-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
59 lines (55 loc) · 2.03 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @package Joomla.Site
* @subpackage mod_bpromo
*
* @copyright Copyright (C) 2015 Yair Lahav, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined("_JEXEC") or die("Restricted access");
class ModBpromoHelper
{
/**
* Get the item
*
* @return object The item.
*/
static function getVisitorData ($dataType, $visitorInfo) {
switch ($dataType) {
case "country":
return $visitorInfo['countryCode'];
case "continent":
return $visitorInfo['continentCode'];
case "currency":
return $visitorInfo['currencyCode'];
}
return $visitorInfo->countryCode;
}
public static function getItem($params, $visitorInfo)
{
$imagesDir = $params['defaultrule']->image;
$images = glob(JPATH_ROOT . "/images/" . $imagesDir . "/*.{jpg,png,gif}", GLOB_BRACE);
$jdx = rand(0, count($images) - 1);
$item['image'] = JURI::base() . "images/" . $imagesDir . "/" . basename($images[$jdx]);
$item['url'] = $params['defaultrule']->url;
/* check rules... */
$rulesEncoded = $params['list_rules'];
$rules = json_decode($rulesEncoded);
if (!empty( $rules )) {
for( $idx = 0; $idx < count( $rules->ruleType ); $idx++ ) {
if (!empty($rules->ruleType[$idx]) && !empty($visitorInfo)) {
$visitorData = ModBpromoHelper::getVisitorData( $rules->ruleType[$idx], $visitorInfo );
if (in_array( $visitorData, explode(",", $rules->reulevals[$idx]) )) {
$imagesDir = $rules->image[$idx];
$images = glob(JPATH_ROOT . "/images/" . $imagesDir . "/*.{jpg,png,gif}", GLOB_BRACE);
$jdx = rand(0, count($images) - 1);
$item['image'] = JURI::base() . "images/" . $imagesDir . "/" . basename($images[$jdx]);
$item['url'] = $rules->url[$idx];
break;
}
}
}
}
return $item;
}
}