|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
|
|
4
|
|
|
------------------------------------------------------------------------ |
|
5
|
|
|
XOOPS - PHP Content Management System |
|
6
|
|
|
Copyright (c) 2000 XOOPS.org |
|
7
|
|
|
<http://www.xoops.org/> |
|
8
|
|
|
------------------------------------------------------------------------ |
|
9
|
|
|
This program is free software; you can redistribute it and/or modify |
|
10
|
|
|
it under the terms of the GNU General Public License as published by |
|
11
|
|
|
the Free Software Foundation; either version 2 of the License, or |
|
12
|
|
|
(at your option) any later version. |
|
13
|
|
|
|
|
14
|
|
|
You may not change or alter any portion of this comment or credits |
|
15
|
|
|
of supporting developers from this source code or any supporting |
|
16
|
|
|
source code which is considered copyrighted (c) material of the |
|
17
|
|
|
original comment or credit authors. |
|
18
|
|
|
|
|
19
|
|
|
This program is distributed in the hope that it will be useful, |
|
20
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
GNU General Public License for more details. |
|
23
|
|
|
|
|
24
|
|
|
You should have received a copy of the GNU General Public License |
|
25
|
|
|
along with this program; if not, write to the Free Software |
|
26
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
27
|
|
|
------------------------------------------------------------------------ |
|
28
|
|
|
Author: Raul Recio (AKA UNFOR) |
|
29
|
|
|
Project: The XOOPS Project |
|
30
|
|
|
------------------------------------------------------------------------- |
|
31
|
|
|
*/ |
|
32
|
|
|
/** |
|
33
|
|
|
* Module: XoopsPartners - a partner affiliation links module |
|
34
|
|
|
* |
|
35
|
|
|
* @category Module |
|
36
|
|
|
* @package xoopspartners |
|
37
|
|
|
* @subpackage admin |
|
38
|
|
|
* @author :: Raul Recio (aka UNFOR) |
|
39
|
|
|
* @author XOOPS Module Development Team |
|
40
|
|
|
* @copyright {@link http://xoops.org 2001-2016 XOOPS Project} |
|
41
|
|
|
* @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
|
42
|
|
|
* @link http://xoops.org XOOPS |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* Show partners in block |
|
48
|
|
|
* @param array $options from block preferences |
|
49
|
|
|
* |
|
50
|
|
|
* $options: 0 - Put spaces between partners |
|
51
|
|
|
* 1 - Fade partners in/out |
|
52
|
|
|
* 2 - Randomize which partners to display in block |
|
53
|
|
|
* 3 - Number of partners to display |
|
54
|
|
|
* 4 - show images|text|both |
|
55
|
|
|
* 5 - display order id|hits|title|weight |
|
56
|
|
|
* 6 - order ASC|DESC |
|
57
|
|
|
* 7 - max title length (0 for unlimited) |
|
58
|
|
|
* |
|
59
|
|
|
* @return array block settings |
|
60
|
|
|
*/ |
|
61
|
|
|
function b_xoopspartners_show($options) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$block = array(); |
|
66
|
|
|
$moduleDirname = basename(dirname(__DIR__)); |
|
67
|
|
|
$block['xpDir'] = $moduleDirname; |
|
68
|
|
|
|
|
69
|
|
|
$partnerHandler = xoops_getModuleHandler('partners', $moduleDirname); |
|
70
|
|
|
$pFields = array('id', 'url', 'image', 'title', 'description'); |
|
71
|
|
|
$criteria = new CriteriaCompo(); |
|
72
|
|
|
$criteria->setLimit($options[3]); |
|
73
|
|
|
if ($options[2]) { |
|
74
|
|
|
$criteria->setSort('RAND()'); |
|
75
|
|
|
} else { |
|
76
|
|
|
$criteria->setSort($options[5]); |
|
77
|
|
|
$criteria->setOrder($options[6]); |
|
78
|
|
|
} |
|
79
|
|
|
$pObjs = $partnerHandler->getAll($criteria, $pFields); |
|
80
|
|
|
foreach ($pObjs as $pObj) { |
|
81
|
|
|
$url = $pObj->getVar('url'); |
|
82
|
|
|
$origtitle = $pObj->getVar('title'); |
|
83
|
|
|
$title = $origtitle; |
|
84
|
|
|
$description = $pObj->getVar('description'); |
|
85
|
|
|
$image = $pObj->getVar('image'); |
|
86
|
|
|
//@TODO: make display string length a config option |
|
87
|
|
|
if (!empty($options[7])) { |
|
88
|
|
|
$title = xoops_substr($origtitle, 0, (int)$options[7]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
// $title = (mb_strlen($origtitle) > 19) ? xoops_substr($title, 0, 19) : $title; |
|
|
|
|
|
|
92
|
|
|
$partners['id'] = $pObj->getVar('id'); |
|
|
|
|
|
|
93
|
|
|
$partners['url'] = $url; |
|
94
|
|
|
$partners['description'] = $description; |
|
95
|
|
|
if (!empty($image) && (1 == $options[4] || 3 == $options[4])) { |
|
96
|
|
|
$partners['image'] = $image; |
|
97
|
|
|
} |
|
98
|
|
|
if (empty($image) || (2 == $options[4]) || (3 == $options[4])) { |
|
99
|
|
|
$partners['title'] = $title; |
|
100
|
|
|
} else { |
|
101
|
|
|
$partners['title'] = ''; |
|
102
|
|
|
} |
|
103
|
|
|
$block['partners'][] = $partners; |
|
104
|
|
|
} |
|
105
|
|
|
$block['insertBr'] = (1 == $options[0]); |
|
106
|
|
|
$block['fadeImage'] = (1 == $options[1]) ; |
|
107
|
|
|
|
|
108
|
|
|
//now load the stylesheet |
|
109
|
|
|
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . "/modules/{$moduleDirname}/assets/css/style.css"); |
|
110
|
|
|
|
|
111
|
|
|
return $block; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* |
|
116
|
|
|
* Edit Random Partners block preferences |
|
117
|
|
|
* |
|
118
|
|
|
* @param array $options from block preferences |
|
119
|
|
|
* |
|
120
|
|
|
* @return string HTML to display for edit form |
|
121
|
|
|
*/ |
|
122
|
|
|
function b_xoopspartners_edit($options) |
|
123
|
|
|
{ |
|
124
|
|
|
if (0 == $options[0]) { //put spaces between partners |
|
125
|
|
|
$chk0no = " checked='checked'"; |
|
126
|
|
|
$chk0yes = ''; |
|
127
|
|
|
} else { |
|
128
|
|
|
$chk0no = ''; |
|
129
|
|
|
$chk0yes = " checked='checked'"; |
|
130
|
|
|
} |
|
131
|
|
|
if (0 == $options[1]) { //fade partners in/out |
|
132
|
|
|
$chk1no = " checked='checked'"; |
|
133
|
|
|
$chk1yes = ''; |
|
134
|
|
|
} else { |
|
135
|
|
|
$chk1no = ''; |
|
136
|
|
|
$chk1yes = " checked='checked'"; |
|
137
|
|
|
} |
|
138
|
|
|
if (0 == $options[2]) { //randomize partners in block |
|
139
|
|
|
$chk2no = " checked='checked'"; |
|
140
|
|
|
$chk2yes = ''; |
|
141
|
|
|
} else { |
|
142
|
|
|
$chk2no = ''; |
|
143
|
|
|
$chk2yes = " checked='checked'"; |
|
144
|
|
|
} |
|
145
|
|
|
$form = |
|
146
|
|
|
"<table style='border-width: 0px;'>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_PSPACE . "</td>\n" . ' <td>' . "<input type='radio' name='options[0]' value='0'{$chk0no}>" . _NO . '' . "<input type='radio' name='options[0]' value='1'{$chk0yes}>" . _YES . '' . " </td>\n" . " </tr>\n" |
|
147
|
|
|
. " <tr>\n" . ' <td>' . _MB_XPARTNERS_FADE . "</td>\n" . ' <td>' . "<input type='radio' name='options[1]' value='0'{$chk1no}>" . _NO . '' . "<input type='radio' name='options[1]' value='1'{$chk1yes}>" . _YES . "</td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BRAND |
|
148
|
|
|
. "</td>\n" . ' <td>' . "<input type='radio' name='options[2]' value='0'{$chk2no}>" . _NO . '' . "<input type='radio' name='options[2]' value='1'{$chk2yes}>" . _YES . "</td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BLIMIT . "</td>\n" |
|
149
|
|
|
. " <td><input class='txtright' type='number' name='options[3]' size='5' value='{$options[3]}' min='0'></td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BSHOW . "</td>\n" . " <td>\n" . " <select size='1' name='options[4]'>\n"; |
|
150
|
|
|
$sel = (1 == $options[4]) ? " selected='selected'" : ''; |
|
151
|
|
|
$form .= " <option value='1'{$sel}>" . _MB_XPARTNERS_IMAGES . "</option>\n"; |
|
152
|
|
|
|
|
153
|
|
|
$sel = (2 == $options[4]) ? " selected='selected'" : ''; |
|
154
|
|
|
$form .= " <option value='2'{$sel}>" . _MB_XPARTNERS_TEXT . "</option>\n"; |
|
155
|
|
|
|
|
156
|
|
|
$sel = (3 == $options[4]) ? " selected='selected'" : ''; |
|
157
|
|
|
$form .= " <option value='3'{$sel}>" . _MB_XPARTNERS_BOTH . "</option>\n" . " </select>\n" . " </td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BSORT . "</td>\n" . " <td>\n" . " <select size='1' name='options[5]'>"; |
|
158
|
|
|
$sel = ('id' === $options[5]) ? " selected='selected'" : ''; |
|
159
|
|
|
$form .= " <option value='id'{$sel}>" . _MB_XPARTNERS_ID . "</option>\n"; |
|
160
|
|
|
|
|
161
|
|
|
$sel = ('hits' === $options[5]) ? " selected='selected'" : ''; |
|
162
|
|
|
$form .= " <option value='hits'{$sel}>" . _MB_XPARTNERS_HITS . "</option>\n"; |
|
163
|
|
|
|
|
164
|
|
|
$sel = ('title' === $options[5]) ? " selected='selected'" : ''; |
|
165
|
|
|
$form .= " <option value='title'{$sel}>" . _MB_XPARTNERS_TITLE . "</option>\n"; |
|
166
|
|
|
|
|
167
|
|
|
$sel = ('weight' === $options[5]) ? " selected='selected'" : ''; |
|
168
|
|
|
$form .= " <option value='weight'{$sel}>" . _MB_XPARTNERS_WEIGHT . "</option>\n" . " </select>\n" . " <select size='1' name='options[6]'>\n"; |
|
169
|
|
|
|
|
170
|
|
|
$sel = ('ASC' === $options[6]) ? " selected='selected'" : ''; |
|
171
|
|
|
$form .= " <option value='ASC'{$sel}>" . _MB_XPARTNERS_ASC . "</option>\n"; |
|
172
|
|
|
|
|
173
|
|
|
$sel = ('DESC' === $options[6]) ? " selected='selected'" : ''; |
|
174
|
|
|
$form .= " <option value='DESC'{$sel}>" . _MB_XPARTNERS_DESC . "</option>\n" . " </select>\n" . " </td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_TTL_LENGTH . "</td>\n" |
|
175
|
|
|
. " <td><input type='number' class='txtright' name='options[7]' size='5' value='{$options[7]}' min='0'></td>\n" . " </tr>\n" . " <tr>\n" . "</table>\n"; |
|
176
|
|
|
return $form; |
|
177
|
|
|
} |
|
178
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: