1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* You may not change or alter any portion of this comment or credits |
4
|
|
|
* of supporting developers from this source code or any supporting source code |
5
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
* This program is distributed in the hope that it will be useful, |
7
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9
|
|
|
* |
10
|
|
|
*----------------------------------- |
11
|
|
|
* Author: Raul Recio (AKA UNFOR) |
12
|
|
|
* Project: The XOOPS Project |
13
|
|
|
*----------------------------------- |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Module: XoopsPartners - a partner affiliation links module |
18
|
|
|
* |
19
|
|
|
* @param mixed $options |
20
|
|
|
* @author Raul Recio (aka UNFOR) |
21
|
|
|
* @author XOOPS Module Development Team |
22
|
|
|
* @copyright {@link https://xoops.org 2001-2016 XOOPS Project} |
23
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
24
|
|
|
* @link https://xoops.org XOOPS |
25
|
|
|
* @package module\Xoopspartners\blocks |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use XoopsModules\Xoopspartners\Helper; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Show partners in block |
32
|
|
|
* @param array $options from block preferences |
33
|
|
|
* |
34
|
|
|
* $options: 0 - Put spaces between partners |
35
|
|
|
* 1 - Fade partners in/out |
36
|
|
|
* 2 - Randomize which partners to display in block |
37
|
|
|
* 3 - Number of partners to display |
38
|
|
|
* 4 - show images|text|both |
39
|
|
|
* 5 - display order id|hits|title|weight |
40
|
|
|
* 6 - order ASC|DESC |
41
|
|
|
* 7 - max title length (0 for unlimited) |
42
|
|
|
* |
43
|
|
|
* @return array block settings |
44
|
|
|
*/ |
45
|
|
|
function b_xoopspartners_show($options) |
46
|
|
|
{ |
47
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
50
|
|
|
/** @var \XoopsModules\Xoopspartners\Helper $helper */ |
51
|
|
|
$helper = Helper::getInstance(); |
52
|
|
|
$partnersHandler = $helper->getHandler('Partners'); |
53
|
|
|
|
54
|
|
|
$block = ['xpDir' => $moduleDirName]; |
55
|
|
|
|
56
|
|
|
$pFields = ['id', 'url', 'image', 'title', 'description']; |
57
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('status', 1, '=')); |
58
|
|
|
$criteria->setLimit($options[3]); |
59
|
|
|
if ($options[2]) { |
60
|
|
|
$criteria->setSort('RAND()'); |
61
|
|
|
} else { |
62
|
|
|
$criteria->setSort($options[5]); |
63
|
|
|
$criteria->setOrder($options[6]); |
64
|
|
|
} |
65
|
|
|
$pObjs = $partnersHandler->getAll($criteria, $pFields); |
66
|
|
|
foreach ($pObjs as $pObj) { |
67
|
|
|
$partners = []; |
68
|
|
|
$url = $pObj->getVar('url'); |
69
|
|
|
$origtitle = $pObj->getVar('title'); |
70
|
|
|
$title = $origtitle; |
71
|
|
|
$description = $pObj->getVar('description'); |
72
|
|
|
$image = $pObj->getVar('image'); |
73
|
|
|
//@TODO: make display string length a config option |
74
|
|
|
if (!empty($options[7])) { |
75
|
|
|
$title = xoops_substr($origtitle, 0, (int)$options[7]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// $title = (mb_strlen($origtitle) > 19) ? xoops_substr($title, 0, 19) : $title; |
79
|
|
|
$partners['id'] = $pObj->getVar('id'); |
80
|
|
|
$partners['url'] = $url; |
81
|
|
|
$partners['description'] = $description; |
82
|
|
|
|
83
|
|
|
if (!empty($image) && (1 == $options[4] || 3 == $options[4])) { |
84
|
|
|
$partners['image'] = $image; |
85
|
|
|
$partners['image_ttl'] = $title; |
86
|
|
|
} |
87
|
|
|
if (empty($image) || (2 == $options[4]) || (3 == $options[4])) { |
88
|
|
|
$partners['title'] = $title; |
89
|
|
|
} else { |
90
|
|
|
$partners['title'] = ''; |
91
|
|
|
} |
92
|
|
|
$block['partners'][] = $partners; |
93
|
|
|
} |
94
|
|
|
$block['insertBr'] = (1 == $options[0]); |
95
|
|
|
$block['fadeImage'] = (1 == $options[1]); |
96
|
|
|
|
97
|
|
|
//now load the stylesheet & jquery |
98
|
|
|
$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/style.css')); |
99
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js'); |
100
|
|
|
$GLOBALS['xoTheme']->renderMetas(null, true); |
101
|
|
|
|
102
|
|
|
return $block; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Edit Random Partners block preferences |
107
|
|
|
* |
108
|
|
|
* @param array $options from block preferences |
109
|
|
|
* |
110
|
|
|
* @return string HTML to display for edit form |
111
|
|
|
*/ |
112
|
|
|
function b_xoopspartners_edit($options) |
113
|
|
|
{ |
114
|
|
|
if (0 == $options[0]) { //put spaces between partners |
115
|
|
|
$chk0no = ' checked'; |
116
|
|
|
$chk0yes = ''; |
117
|
|
|
} else { |
118
|
|
|
$chk0no = ''; |
119
|
|
|
$chk0yes = ' checked'; |
120
|
|
|
} |
121
|
|
|
if (0 == $options[1]) { //fade partners in/out |
122
|
|
|
$chk1no = ' checked'; |
123
|
|
|
$chk1yes = ''; |
124
|
|
|
} else { |
125
|
|
|
$chk1no = ''; |
126
|
|
|
$chk1yes = ' checked'; |
127
|
|
|
} |
128
|
|
|
if (0 == $options[2]) { //randomize partners in block |
129
|
|
|
$chk2no = ' checked'; |
130
|
|
|
$chk2yes = ''; |
131
|
|
|
} else { |
132
|
|
|
$chk2no = ''; |
133
|
|
|
$chk2yes = ' checked'; |
134
|
|
|
} |
135
|
|
|
$form = "<table class='bnone'>\n" |
136
|
|
|
. " <tr>\n" |
137
|
|
|
. ' <td>' |
138
|
|
|
. _MB_XOOPSPARTNERS_PSPACE |
139
|
|
|
. "</td>\n" |
140
|
|
|
. ' <td>' |
141
|
|
|
. "<input type='radio' name='options[0]' id ='options0_0' value='0'{$chk0no}>" |
142
|
|
|
. "<label for='options0_0'>" |
143
|
|
|
. _NO |
144
|
|
|
. '</label> ' |
145
|
|
|
. "<input type='radio' name='options[0]' id ='options0_1' value='1'{$chk0yes}>" |
146
|
|
|
. "<label for='options0_1'>" |
147
|
|
|
. _YES |
148
|
|
|
. '</label>' |
149
|
|
|
. "</td>\n" |
150
|
|
|
. " </tr>\n" |
151
|
|
|
. " <tr>\n" |
152
|
|
|
. ' <td>' |
153
|
|
|
. _MB_XOOPSPARTNERS_FADE |
154
|
|
|
. "</td>\n" |
155
|
|
|
. ' <td>' |
156
|
|
|
. "<input type='radio' name='options[1]' id='options1_0' value='0'{$chk1no}>" |
157
|
|
|
. _NO |
158
|
|
|
. "<label for='options1_0'>" |
159
|
|
|
. _NO |
160
|
|
|
. '</label> ' |
161
|
|
|
. "<input type='radio' name='options[1]' id='options1_1' value='1'{$chk1yes}>" |
162
|
|
|
. _YES |
163
|
|
|
. "<label for='options1_1'>" |
164
|
|
|
. _YES |
165
|
|
|
. '</label>' |
166
|
|
|
. "</td>\n" |
167
|
|
|
. " </tr>\n" |
168
|
|
|
. " <tr>\n" |
169
|
|
|
. ' <td>' |
170
|
|
|
. _MB_XOOPSPARTNERS_BRAND |
171
|
|
|
. "</td>\n" |
172
|
|
|
. ' <td>' |
173
|
|
|
. "<input type='radio' name='options[2]' id='option2_0' value='0'{$chk2no}>" |
174
|
|
|
. _NO |
175
|
|
|
. "<label for='options2_0'>" |
176
|
|
|
. _NO |
177
|
|
|
. '</label>' |
178
|
|
|
. "<input type='radio' name='options[2]' id='options2_1' value='1'{$chk2yes}>" |
179
|
|
|
. _YES |
180
|
|
|
. "<label for='options2_1'>" |
181
|
|
|
. _YES |
182
|
|
|
. '</label>' |
183
|
|
|
. "</td>\n" |
184
|
|
|
. " </tr>\n" |
185
|
|
|
. " <tr>\n" |
186
|
|
|
. ' <td>' |
187
|
|
|
. _MB_XOOPSPARTNERS_BLIMIT |
188
|
|
|
. "</td>\n" |
189
|
|
|
. " <td><input class='right' type='number' name='options[3]' size='5' value='{$options[3]}' min='0'></td>\n" |
190
|
|
|
. " </tr>\n" |
191
|
|
|
. " <tr>\n" |
192
|
|
|
. ' <td>' |
193
|
|
|
. _MB_XOOPSPARTNERS_BSHOW |
194
|
|
|
. "</td>\n" |
195
|
|
|
. " <td>\n" |
196
|
|
|
. " <select size='1' name='options[4]'>\n"; |
197
|
|
|
$sel = (1 == $options[4]) ? ' selected' : ''; |
198
|
|
|
$form .= " <option value='1'{$sel}>" . _MB_XOOPSPARTNERS_IMAGES . "</option>\n"; |
199
|
|
|
|
200
|
|
|
$sel = (2 == $options[4]) ? ' selected' : ''; |
201
|
|
|
$form .= " <option value='2'{$sel}>" . _MB_XOOPSPARTNERS_TEXT . "</option>\n"; |
202
|
|
|
|
203
|
|
|
$sel = (3 == $options[4]) ? ' selected' : ''; |
204
|
|
|
$form .= " <option value='3'{$sel}>" . _MB_XOOPSPARTNERS_BOTH . "</option>\n" . " </select>\n" . " </td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XOOPSPARTNERS_BSORT . "</td>\n" . " <td>\n" . " <select size='1' name='options[5]'>\n"; |
205
|
|
|
|
206
|
|
|
$sel = ('id' === $options[5]) ? ' selected' : ''; |
207
|
|
|
$form .= " <option value='id'{$sel}>" . _MB_XOOPSPARTNERS_ID . "</option>\n"; |
208
|
|
|
|
209
|
|
|
$sel = ('hits' === $options[5]) ? ' selected' : ''; |
210
|
|
|
$form .= " <option value='hits'{$sel}>" . _MB_XOOPSPARTNERS_HITS . "</option>\n"; |
211
|
|
|
|
212
|
|
|
$sel = ('title' === $options[5]) ? ' selected' : ''; |
213
|
|
|
$form .= " <option value='title'{$sel}>" . _MB_XOOPSPARTNERS_TITLE . "</option>\n"; |
214
|
|
|
|
215
|
|
|
$sel = ('weight' === $options[5]) ? ' selected' : ''; |
216
|
|
|
$form .= " <option value='weight'{$sel}>" . _MB_XOOPSPARTNERS_WEIGHT . "</option>\n" . " </select>\n" . " <select size='1' name='options[6]'>\n"; |
217
|
|
|
|
218
|
|
|
$sel = ('ASC' === $options[6]) ? ' selected' : ''; |
219
|
|
|
$form .= " <option value='ASC'{$sel}>" . _MB_XOOPSPARTNERS_ASC . "</option>\n"; |
220
|
|
|
|
221
|
|
|
$sel = ('DESC' === $options[6]) ? ' selected' : ''; |
222
|
|
|
$form .= " <option value='DESC'{$sel}>" |
223
|
|
|
. _MB_XOOPSPARTNERS_DESC |
224
|
|
|
. "</option>\n" |
225
|
|
|
. " </select>\n" |
226
|
|
|
. " </td>\n" |
227
|
|
|
. " </tr>\n" |
228
|
|
|
. " <tr>\n" |
229
|
|
|
. ' <td>' |
230
|
|
|
. _MB_XOOPSPARTNERS_TTL_LENGTH |
231
|
|
|
. "</td>\n" |
232
|
|
|
. ' <td>' |
233
|
|
|
. "<input type='number' class='right' name='options[7]' size='5' value='{$options[7]}' min='0'>" |
234
|
|
|
. "</td>\n" |
235
|
|
|
. " </tr>\n" |
236
|
|
|
. " <tr>\n" |
237
|
|
|
. "</table>\n"; |
238
|
|
|
|
239
|
|
|
return $form; |
240
|
|
|
} |
241
|
|
|
|