1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* Module: SmartPartner |
6
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
7
|
|
|
* Licence: GNU |
8
|
|
|
* @param $options |
9
|
|
|
* @return array |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
function b_random_partner_show($options) |
13
|
|
|
{ |
14
|
|
|
include_once(XOOPS_ROOT_PATH . '/modules/smartpartner/include/common.php'); |
15
|
|
|
|
16
|
|
|
// Creating the partner handler object |
17
|
|
|
$partnerHandler = smartpartner_gethandler('partner'); |
18
|
|
|
|
19
|
|
|
// Randomize |
20
|
|
|
$partnersObj =& $partnerHandler->getPartners(0, 0, _SPARTNER_STATUS_ACTIVE); |
21
|
|
|
if (count($partnersObj) > 0) { |
22
|
|
|
$key_arr = array_keys($partnersObj); |
23
|
|
|
$key_rand = array_rand($key_arr, 1); |
24
|
|
|
$partnerObj = $partnersObj[$key_rand]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$block = array(); |
28
|
|
|
if ($partnerObj) { |
29
|
|
|
$partner['id'] = $partnerObj->id(); |
|
|
|
|
30
|
|
|
$partner['urllink'] = $partnerObj->getUrlLink('block'); |
31
|
|
|
if ($partnerObj->image() && (($options[1] == 1) || ($options[1] == 3))) { |
32
|
|
|
$partner['image'] = $partnerObj->getImageUrl(); |
33
|
|
|
} |
34
|
|
|
if ($partnerObj->image() && (($options[1] == 2) || ($options[1] == 3))) { |
35
|
|
|
$partner['title'] = $partnerObj->title(); |
36
|
|
|
} else { |
37
|
|
|
$partner['title'] = ''; |
38
|
|
|
} |
39
|
|
|
$smartConfig = smartpartner_getModuleConfig(); |
40
|
|
|
$image_info = smartpartner_imageResize($partnerObj->getImagePath(), $smartConfig['img_max_width'], $smartConfig['img_max_height']); |
41
|
|
|
$partner['img_attr'] = $image_info[3]; |
42
|
|
|
$partner['extendedInfo'] = $partnerObj->extentedInfo(); |
43
|
|
|
|
44
|
|
|
if ($options[0] == 1) { |
45
|
|
|
$block['fadeImage'] = 'style="filter:alpha(opacity=20);" onmouseover="nereidFade(this,100,30,5)" onmouseout="nereidFade(this,50,30,5)"'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$block['see_all'] = $options[2]; |
49
|
|
|
$block['lang_see_all'] = _MB_SPARTNER_LANG_SEE_ALL; |
50
|
|
|
$block['smartpartner_url'] = SMARTPARTNER_URL; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $block; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param $options |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
function b_random_partner_edit($options) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$form = "<table border='0'>"; |
63
|
|
|
/*$form .= "<tr><td>"._MB_SPARTNER_PARTNERS_PSPACE."</td><td>"; |
|
|
|
|
64
|
|
|
$chk = ""; |
65
|
|
|
if ($options[0] == 0) { |
66
|
|
|
$chk = " checked='checked'"; |
67
|
|
|
} |
68
|
|
|
$form .= "<input type='radio' name='options[0]' value='0'".$chk." />"._NO.""; |
69
|
|
|
$chk = ""; |
70
|
|
|
if ($options[0] == 1) { |
71
|
|
|
$chk = " checked='checked'"; |
72
|
|
|
} |
73
|
|
|
$form .= "<input type='radio' name='options[0]' value='1'".$chk." />"._YES."</td></tr>";*/ |
74
|
|
|
$form .= '<tr><td>' . _MB_SPARTNER_FADE . '</td><td>'; |
75
|
|
|
$chk = ''; |
76
|
|
|
if ($options[0] == 0) { |
77
|
|
|
$chk = " checked='checked'"; |
78
|
|
|
} |
79
|
|
|
$form .= "<input type='radio' name='options[1]' value='0'" . $chk . ' />' . _NO . ''; |
80
|
|
|
$chk = ''; |
81
|
|
|
if ($options[0] == 1) { |
82
|
|
|
$chk = " checked='checked'"; |
83
|
|
|
} |
84
|
|
|
$form .= "<input type='radio' name='options[1]' value='1'" . $chk . ' />' . _YES . '</td></tr>'; |
85
|
|
|
/*$form .= "<tr><td>"._MB_SPARTNER_BRAND."</td><td>"; |
|
|
|
|
86
|
|
|
$chk = ""; |
87
|
|
|
if ($options[2] == 0) { |
88
|
|
|
$chk = " checked='checked'"; |
89
|
|
|
} |
90
|
|
|
$form .= "<input type='radio' name='options[2]' value='0'".$chk." />"._NO.""; |
91
|
|
|
$chk = ""; |
92
|
|
|
if ($options[2] == 1) { |
93
|
|
|
$chk = " checked='checked'"; |
94
|
|
|
} |
95
|
|
|
$form .= "<input type='radio' name='options[2]' value='1'".$chk." />"._YES."</td></tr>"; |
96
|
|
|
$form .= "<tr><td>"._MB_SPARTNER_BLIMIT."</td><td>"; |
97
|
|
|
$form .= "<input type='text' name='options[3]' size='16' value='".$options[3]."' /></td></tr>";*/ |
98
|
|
|
$form .= '<tr><td>' . _MB_SPARTNER_BSHOW . '</td><td>'; |
99
|
|
|
$form .= "<select size='1' name='options[1]'>"; |
100
|
|
|
$sel = ''; |
101
|
|
|
if ($options[1] == 1) { |
102
|
|
|
$sel = " selected='selected'"; |
103
|
|
|
} |
104
|
|
|
$form .= "<option value='1' " . $sel . '>' . _MB_SPARTNER_IMAGES . '</option>'; |
105
|
|
|
$sel = ''; |
106
|
|
|
if ($options[1] == 2) { |
107
|
|
|
$sel = " selected='selected'"; |
108
|
|
|
} |
109
|
|
|
$form .= "<option value='2' " . $sel . '>' . _MB_SPARTNER_TEXT . '</option>'; |
110
|
|
|
$sel = ''; |
111
|
|
|
if ($options[1] == 3) { |
112
|
|
|
$sel = " selected='selected'"; |
113
|
|
|
} |
114
|
|
|
$form .= "<option value='3' " . $sel . '>' . _MB_SPARTNER_BOTH . '</option>'; |
115
|
|
|
$form .= '</select></td></tr>'; |
116
|
|
|
/*$form .= "<tr><td>"._MB_SPARTNER_BORDER."</td><td>"; |
|
|
|
|
117
|
|
|
$form .= "<select size='1' name='options[5]'>"; |
118
|
|
|
$sel = ""; |
119
|
|
|
if ($options[5] == "id") { |
120
|
|
|
$sel = " selected='selected'"; |
121
|
|
|
} |
122
|
|
|
$form .= "<option value='id' ".$sel.">"._MB_SPARTNER_ID."</option>"; |
123
|
|
|
$sel = ""; |
124
|
|
|
if ($options[5] == "hits") { |
125
|
|
|
$sel = " selected='selected'"; |
126
|
|
|
} |
127
|
|
|
$form .= "<option value='hits' ".$sel.">"._MB_SPARTNER_HITS."</option>"; |
128
|
|
|
$sel = ""; |
129
|
|
|
if ($options[5] == "title") { |
130
|
|
|
$sel = " selected='selected'"; |
131
|
|
|
} |
132
|
|
|
$form .= "<option value='title' ".$sel.">"._MB_SPARTNER_TITLE."</option>"; |
133
|
|
|
if ($options[5] == "weight") { |
134
|
|
|
$sel = " selected='selected'"; |
135
|
|
|
} |
136
|
|
|
$form .= "<option value='weight' ".$sel.">"._MB_SPARTNER_WEIGHT."</option>"; |
137
|
|
|
$form .= "</select> "; |
138
|
|
|
$form .= "<select size='1' name='options[6]'>"; |
139
|
|
|
$sel = ""; |
140
|
|
|
if ($options[6] == "ASC") { |
141
|
|
|
$sel = " selected='selected'"; |
142
|
|
|
} |
143
|
|
|
$form .= "<option value='ASC' ".$sel.">"._MB_SPARTNER_ASC."</option>"; |
144
|
|
|
$sel = ""; |
145
|
|
|
if ($options[6] == "DESC") { |
146
|
|
|
$sel = " selected='selected'"; |
147
|
|
|
} |
148
|
|
|
$form .= "<option value='DESC' ".$sel.">"._MB_SPARTNER_DESC."</option>"; |
149
|
|
|
$form .= "</select></td></tr>"; |
150
|
|
|
*/ |
151
|
|
|
$form .= '<tr><td>' . _MB_SPARTNER_SEE_ALL . '</td><td>'; |
152
|
|
|
$chk = ''; |
153
|
|
|
if ($options[2] == 0) { |
154
|
|
|
$chk = " checked='checked'"; |
155
|
|
|
} |
156
|
|
|
$form .= "<input type='radio' name='options[2]' value='0'" . $chk . ' />' . _NO . ''; |
157
|
|
|
$chk = ''; |
158
|
|
|
if ($options[7] == 1) { |
159
|
|
|
$chk = " checked='checked'"; |
160
|
|
|
} |
161
|
|
|
$form .= "<input type='radio' name='options[2]' value='1'" . $chk . ' />' . _YES . '</td></tr>'; |
162
|
|
|
|
163
|
|
|
$form .= '</table>'; |
164
|
|
|
|
165
|
|
|
return $form; |
166
|
|
|
} |
167
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.