1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Adslight; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* You may not change or alter any portion of this comment or credits |
9
|
|
|
* of supporting developers from this source code or any supporting source code |
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
20
|
|
|
* @author XOOPS Development Team |
21
|
|
|
* @author Pascal Le Boustouller: original author ([email protected]) |
22
|
|
|
* @author Luc Bizet (www.frxoops.org) |
23
|
|
|
* @author jlm69 (www.jlmzone.com) |
24
|
|
|
* @author mamba (www.xoops.org) |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AdslightUtil Class |
29
|
|
|
* |
30
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
31
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
32
|
|
|
* @author XOOPS Development Team |
33
|
|
|
* @package AdsLight |
34
|
|
|
* @since 1.03 |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
use Xmf\Request; |
38
|
|
|
use XoopsModules\Adslight; |
39
|
|
|
use XoopsModules\Adslight\Common; |
40
|
|
|
|
41
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; |
42
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class Utility |
46
|
|
|
*/ |
47
|
|
|
class Utility |
48
|
|
|
{ |
49
|
|
|
use Common\VersionChecks; |
|
|
|
|
50
|
|
|
|
51
|
|
|
//checkVerXoops, checkVerPhp Traits |
52
|
|
|
|
53
|
|
|
use Common\ServerStats; |
54
|
|
|
|
55
|
|
|
// getServerStats Trait |
56
|
|
|
|
57
|
|
|
use Common\FilesManagement; |
58
|
|
|
|
59
|
|
|
// Files Management Trait |
60
|
|
|
|
61
|
|
|
//--------------- Custom module methods ----------------------------- |
62
|
|
|
|
63
|
|
|
public static function expireAd(): void |
64
|
|
|
{ |
65
|
|
|
global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $meta; |
66
|
|
|
|
67
|
|
|
$datenow = \time(); |
68
|
|
|
$message = ''; |
69
|
|
|
|
70
|
|
|
$result5 = $xoopsDB->query('SELECT lid, title, expire, type, desctext, date_created, email, submitter, photo, valid, hits, comments, remind FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes'"); |
71
|
|
|
|
72
|
|
|
while (false !== (list($lids, $title, $expire, $type, $desctext, $dateann, $email, $submitter, $photo, $valid, $hits, $comments, $remind) = $xoopsDB->fetchRow($result5))) { |
73
|
|
|
$title = \htmlspecialchars($title, \ENT_QUOTES | \ENT_HTML5); |
74
|
|
|
$expire = \htmlspecialchars($expire, \ENT_QUOTES | \ENT_HTML5); |
75
|
|
|
$type = \htmlspecialchars($type, \ENT_QUOTES | \ENT_HTML5); |
76
|
|
|
$desctext = &$myts->displayTarea($desctext, 1, 1, 1, 1, 1); |
77
|
|
|
$submitter = \htmlspecialchars($submitter, \ENT_QUOTES | \ENT_HTML5); |
78
|
|
|
$remind = \htmlspecialchars($remind, \ENT_QUOTES | \ENT_HTML5); |
79
|
|
|
$supprdate = $dateann + ($expire * 86400); |
80
|
|
|
$almost = $GLOBALS['xoopsModuleConfig']['adslight_almost']; |
81
|
|
|
|
82
|
|
|
// give warning that add is about to expire |
83
|
|
|
|
84
|
|
|
if ($almost > 0 && ($supprdate - $almost * 86400) < $datenow |
85
|
|
|
&& 'Yes' === $valid |
86
|
|
|
&& 0 == $remind) { |
87
|
|
|
$xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET remind='1' WHERE lid=$lids"); |
88
|
|
|
|
89
|
|
|
if ($email) { |
90
|
|
|
$tags = []; |
91
|
|
|
$subject = '' . \_ADSLIGHT_ALMOST . ''; |
92
|
|
|
$tags['TITLE'] = $title; |
93
|
|
|
$tags['HELLO'] = '' . \_ADSLIGHT_HELLO . ''; |
94
|
|
|
$tags['YOUR_AD_ON'] = '' . \_ADSLIGHT_YOUR_AD_ON . ''; |
95
|
|
|
$tags['VEDIT_AD'] = '' . \_ADSLIGHT_VEDIT_AD . ''; |
96
|
|
|
$tags['YOUR_AD'] = '' . \_ADSLIGHT_YOUR_AD . ''; |
97
|
|
|
$tags['SOON'] = '' . \_ADSLIGHT_SOON . ''; |
98
|
|
|
$tags['VIEWED'] = '' . \_ADSLIGHT_VU . ''; |
99
|
|
|
$tags['TIMES'] = '' . \_ADSLIGHT_TIMES . ''; |
100
|
|
|
$tags['WEBMASTER'] = '' . \_ADSLIGHT_WEBMASTER . ''; |
101
|
|
|
$tags['THANKS'] = '' . \_ADSLIGHT_THANKS . ''; |
102
|
|
|
$tags['TYPE'] = static::getNameType($type); |
103
|
|
|
$tags['DESCTEXT'] = $desctext; |
104
|
|
|
$tags['HITS'] = $hits; |
105
|
|
|
$tags['META_TITLE'] = $meta['title']; |
106
|
|
|
$tags['SUBMITTER'] = $submitter; |
107
|
|
|
$tags['DURATION'] = $expire; |
108
|
|
|
$tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
109
|
|
|
$mail = \getMailer(); |
110
|
|
|
$mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
111
|
|
|
$mail->setTemplate('listing_expires.tpl'); |
112
|
|
|
$mail->useMail(); |
113
|
|
|
$mail->multimailer->isHTML(true); |
114
|
|
|
$mail->setFromName($meta['title']); |
115
|
|
|
$mail->setFromEmail($xoopsConfig['adminmail']); |
116
|
|
|
$mail->setToEmails($email); |
117
|
|
|
$mail->setSubject($subject); |
118
|
|
|
$mail->assign($tags); |
119
|
|
|
$mail->send(); |
120
|
|
|
echo $mail->getErrors(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// expire ad |
125
|
|
|
|
126
|
|
|
if ($supprdate < $datenow) { |
127
|
|
|
if (0 != $photo) { |
128
|
|
|
$result2 = $xoopsDB->query('SELECT url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
129
|
|
|
|
130
|
|
|
while (false !== (list($url) = $xoopsDB->fetchRow($result2))) { |
131
|
|
|
$destination = XOOPS_ROOT_PATH . '/uploads/adslight'; |
132
|
|
|
$destination2 = XOOPS_ROOT_PATH . '/uploads/adslight/thumbs'; |
133
|
|
|
$destination3 = XOOPS_ROOT_PATH . '/uploads/adslight/midsize'; |
134
|
|
|
if (\is_file("$destination/$url")) { |
135
|
|
|
\unlink("$destination/$url"); |
136
|
|
|
} |
137
|
|
|
if (\is_file("$destination2/thumb_$url")) { |
138
|
|
|
\unlink("$destination2/thumb_$url"); |
139
|
|
|
} |
140
|
|
|
if (\is_file("$destination3/resized_$url")) { |
141
|
|
|
\unlink("$destination3/resized_$url"); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lids)); |
147
|
|
|
|
148
|
|
|
// Specification for Japan: |
149
|
|
|
// $message = ""._ADS_HELLO." $submitter,\n\n"._ADS_STOP2."\n $type : $title\n $desctext\n"._ADS_STOP3."\n\n"._ADS_VU." $lu "._ADS_VU2."\n\n"._ADS_OTHER." ".XOOPS_URL."/modules/myAds\n\n"._ADS_THANK."\n\n"._ADS_TEAM." ".$meta['title']."\n".XOOPS_URL.""; |
150
|
|
|
if ($email) { |
151
|
|
|
$tags = []; |
152
|
|
|
$subject = '' . \_ADSLIGHT_STOP . ''; |
153
|
|
|
$tags['TITLE'] = $title; |
154
|
|
|
$tags['HELLO'] = '' . \_ADSLIGHT_HELLO . ''; |
155
|
|
|
$tags['TYPE'] = static::getNameType($type); |
156
|
|
|
$tags['DESCTEXT'] = $desctext; |
157
|
|
|
$tags['HITS'] = $hits; |
158
|
|
|
$tags['META_TITLE'] = $meta['title']; |
159
|
|
|
$tags['SUBMITTER'] = $submitter; |
160
|
|
|
$tags['YOUR_AD_ON'] = '' . \_ADSLIGHT_YOUR_AD_ON . ''; |
161
|
|
|
$tags['EXPIRED'] = '' . \_ADSLIGHT_EXPIRED . ''; |
162
|
|
|
$tags['MESSTEXT'] = \stripslashes($message); |
163
|
|
|
$tags['OTHER'] = '' . \_ADSLIGHT_OTHER . ''; |
164
|
|
|
$tags['WEBMASTER'] = '' . \_ADSLIGHT_WEBMASTER . ''; |
165
|
|
|
$tags['THANKS'] = '' . \_ADSLIGHT_THANKS . ''; |
166
|
|
|
$tags['VIEWED'] = '' . \_ADSLIGHT_VU . ''; |
167
|
|
|
$tags['TIMES'] = '' . \_ADSLIGHT_TIMES . ''; |
168
|
|
|
$tags['TEAM'] = '' . \_ADSLIGHT_TEAM . ''; |
169
|
|
|
$tags['DURATION'] = $expire; |
170
|
|
|
$tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids; |
171
|
|
|
$mail = \getMailer(); |
172
|
|
|
$mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
173
|
|
|
$mail->setTemplate('listing_expired.tpl'); |
174
|
|
|
$mail->useMail(); |
175
|
|
|
$mail->multimailer->isHTML(true); |
176
|
|
|
$mail->setFromName($meta['title']); |
177
|
|
|
$mail->setFromEmail($xoopsConfig['adminmail']); |
178
|
|
|
$mail->setToEmails($email); |
179
|
|
|
$mail->setSubject($subject); |
180
|
|
|
$mail->assign($tags); |
181
|
|
|
$mail->send(); |
182
|
|
|
echo $mail->getErrors(); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
//updates rating data in itemtable for a given user |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param $sel_id |
192
|
|
|
*/ |
193
|
|
|
public static function updateUserRating($sel_id): void |
194
|
|
|
{ |
195
|
|
|
global $xoopsDB; |
196
|
|
|
|
197
|
|
|
$usid = Request::getInt('usid', 0, 'GET'); |
|
|
|
|
198
|
|
|
|
199
|
|
|
$query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_user_votedata') . ' WHERE usid=' . $xoopsDB->escape($sel_id) . ' '; |
200
|
|
|
//echo $query; |
201
|
|
|
$voteresult = $xoopsDB->query($query); |
202
|
|
|
$votesDB = $xoopsDB->getRowsNum($voteresult); |
203
|
|
|
$totalrating = 0; |
204
|
|
|
while (false !== (list($rating) = $xoopsDB->fetchRow($voteresult))) { |
205
|
|
|
$totalrating += $rating; |
206
|
|
|
} |
207
|
|
|
$finalrating = $totalrating / $votesDB; |
208
|
|
|
$finalrating = \number_format($finalrating, 4); |
209
|
|
|
$query = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET user_rating=$finalrating, user_votes=$votesDB WHERE usid=" . $xoopsDB->escape($sel_id) . ''; |
210
|
|
|
//echo $query; |
211
|
|
|
$xoopsDB->query($query) || exit(); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
//updates rating data in itemtable for a given item |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param $sel_id |
218
|
|
|
*/ |
219
|
|
|
public static function updateItemRating($sel_id): void |
220
|
|
|
{ |
221
|
|
|
global $xoopsDB; |
222
|
|
|
|
223
|
|
|
$lid = Request::getInt('lid', 0, 'GET'); |
|
|
|
|
224
|
|
|
|
225
|
|
|
$query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($sel_id) . ' '; |
226
|
|
|
//echo $query; |
227
|
|
|
$voteresult = $xoopsDB->query($query); |
228
|
|
|
$votesDB = $xoopsDB->getRowsNum($voteresult); |
229
|
|
|
$totalrating = 0; |
230
|
|
|
while (false !== (list($rating) = $xoopsDB->fetchRow($voteresult))) { |
231
|
|
|
$totalrating += $rating; |
232
|
|
|
} |
233
|
|
|
$finalrating = $totalrating / $votesDB; |
234
|
|
|
$finalrating = \number_format($finalrating, 4); |
235
|
|
|
$query = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET item_rating=$finalrating, item_votes=$votesDB WHERE lid=" . $xoopsDB->escape($sel_id) . ''; |
236
|
|
|
//echo $query; |
237
|
|
|
$xoopsDB->query($query) || exit(); |
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param $sel_id |
242
|
|
|
* @param string $status |
243
|
|
|
* |
244
|
|
|
* @return int |
245
|
|
|
*/ |
246
|
|
|
public static function getTotalItems($sel_id, $status = ''): int |
|
|
|
|
247
|
|
|
{ |
248
|
|
|
global $xoopsDB, $mytree; |
249
|
|
|
$categories = self::getMyItemIds('adslight_view'); |
250
|
|
|
$count = 0; |
251
|
|
|
$arr = []; |
|
|
|
|
252
|
|
|
if (\in_array($sel_id, $categories)) { |
253
|
|
|
$query = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$sel_id . " AND valid='Yes' AND status!='1'"; |
254
|
|
|
|
255
|
|
|
$result = $xoopsDB->query($query); |
256
|
|
|
[$thing] = $xoopsDB->fetchRow($result); |
257
|
|
|
$count = $thing; |
258
|
|
|
$arr = $mytree->getAllChildId($sel_id); |
259
|
|
|
foreach ($arr as $iValue) { |
260
|
|
|
if (\in_array($iValue, $categories)) { |
261
|
|
|
$query2 = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$iValue . " AND valid='Yes' AND status!='1'"; |
262
|
|
|
|
263
|
|
|
$result2 = $xoopsDB->query($query2); |
264
|
|
|
[$thing] = $xoopsDB->fetchRow($result2); |
265
|
|
|
$count += $thing; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
return (int)$count; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param $permtype |
275
|
|
|
* |
276
|
|
|
* @return mixed |
277
|
|
|
*/ |
278
|
|
|
public static function getMyItemIds($permtype) |
279
|
|
|
{ |
280
|
|
|
static $permissions = []; |
281
|
|
|
if (\is_array($permissions) |
282
|
|
|
&& \array_key_exists($permtype, $permissions)) { |
283
|
|
|
return $permissions[$permtype]; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
287
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
288
|
|
|
$myModule = $moduleHandler->getByDirname('adslight'); |
289
|
|
|
$groups = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
290
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
291
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
292
|
|
|
$categories = $grouppermHandler->getItemIds($permtype, $groups, $myModule->getVar('mid')); |
293
|
|
|
$permissions[$permtype] = $categories; |
294
|
|
|
|
295
|
|
|
return $categories; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Returns a module's option |
300
|
|
|
* @param string $option module option's name |
301
|
|
|
* @param string $repmodule |
302
|
|
|
* |
303
|
|
|
* @return bool|mixed option's value |
304
|
|
|
*/ |
305
|
|
|
public static function getModuleOption($option, $repmodule = 'adslight') |
306
|
|
|
{ |
307
|
|
|
global $xoopsModule; |
308
|
|
|
$helper = \XoopsModules\Adslight\Helper::getInstance(); |
309
|
|
|
static $tbloptions = []; |
310
|
|
|
if (\is_array($tbloptions) && \array_key_exists($option, $tbloptions)) { |
311
|
|
|
return $tbloptions[$option]; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
$retval = false; |
315
|
|
|
if (isset($GLOBALS['xoopsModuleConfig']) |
316
|
|
|
&& (\is_object($xoopsModule) |
317
|
|
|
&& $xoopsModule->getVar('dirname') == $repmodule |
318
|
|
|
&& $xoopsModule->getVar('isactive'))) { |
319
|
|
|
if (isset($GLOBALS['xoopsModuleConfig'][$option])) { |
320
|
|
|
$retval = $GLOBALS['xoopsModuleConfig'][$option]; |
321
|
|
|
} |
322
|
|
|
} else { |
323
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
324
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
325
|
|
|
$module = $moduleHandler->getByDirname($repmodule); |
326
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
327
|
|
|
$configHandler = \xoops_getHandler('config'); |
328
|
|
|
if ($module) { |
329
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $GLOBALS['xoopsModule']->getVar('mid')); |
|
|
|
|
330
|
|
|
if (null !== $helper->getConfig($option)) { |
331
|
|
|
$retval = $helper->getConfig($option); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
$tbloptions[$option] = $retval; |
336
|
|
|
|
337
|
|
|
return $retval; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public static function showImage(): void |
341
|
|
|
{ |
342
|
|
|
echo "<script type=\"text/javascript\">\n"; |
343
|
|
|
echo "<!--\n\n"; |
344
|
|
|
echo "function showimage() {\n"; |
345
|
|
|
echo "if (!document.images)\n"; |
346
|
|
|
echo "return\n"; |
347
|
|
|
echo "document.images.avatar.src=\n"; |
348
|
|
|
echo "'" . XOOPS_URL . "/modules/adslight/assets/images/img_cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n"; |
349
|
|
|
echo "}\n\n"; |
350
|
|
|
echo "//-->\n"; |
351
|
|
|
echo "</script>\n"; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
//Reusable Link Sorting Functions |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @param $orderby |
358
|
|
|
* |
359
|
|
|
* @return string |
360
|
|
|
*/ |
361
|
|
|
public static function convertOrderByIn($orderby): string |
362
|
|
|
{ |
363
|
|
|
switch (\trim($orderby)) { |
364
|
|
|
case 'titleA': |
365
|
|
|
$orderby = 'title ASC'; |
366
|
|
|
break; |
367
|
|
|
case 'dateA': |
368
|
|
|
$orderby = 'date_created ASC'; |
369
|
|
|
break; |
370
|
|
|
case 'hitsA': |
371
|
|
|
$orderby = 'hits ASC'; |
372
|
|
|
break; |
373
|
|
|
case 'priceA': |
374
|
|
|
$orderby = 'price ASC'; |
375
|
|
|
break; |
376
|
|
|
case 'titleD': |
377
|
|
|
$orderby = 'title DESC'; |
378
|
|
|
break; |
379
|
|
|
case 'hitsD': |
380
|
|
|
$orderby = 'hits DESC'; |
381
|
|
|
break; |
382
|
|
|
case 'priceD': |
383
|
|
|
$orderby = 'price DESC'; |
384
|
|
|
break; |
385
|
|
|
case'dateD': |
386
|
|
|
default: |
387
|
|
|
$orderby = 'date_created DESC'; |
388
|
|
|
break; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
return $orderby; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @param $orderby |
396
|
|
|
* |
397
|
|
|
* @return string |
398
|
|
|
*/ |
399
|
|
|
public static function convertOrderByTrans($orderby): string |
400
|
|
|
{ |
401
|
|
|
$orderbyTrans = ''; |
402
|
|
|
if ('hits ASC' === $orderby) { |
403
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_POPULARITYLTOM . ''; |
404
|
|
|
} |
405
|
|
|
if ('hits DESC' === $orderby) { |
406
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_POPULARITYMTOL . ''; |
407
|
|
|
} |
408
|
|
|
if ('title ASC' === $orderby) { |
409
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_TITLEATOZ . ''; |
410
|
|
|
} |
411
|
|
|
if ('title DESC' === $orderby) { |
412
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_TITLEZTOA . ''; |
413
|
|
|
} |
414
|
|
|
if ('date_created ASC' === $orderby) { |
415
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_DATEOLD . ''; |
416
|
|
|
} |
417
|
|
|
if ('date_created DESC' === $orderby) { |
418
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_DATENEW . ''; |
419
|
|
|
} |
420
|
|
|
if ('price ASC' === $orderby) { |
421
|
|
|
$orderbyTrans = \_ADSLIGHT_PRICELTOH; |
422
|
|
|
} |
423
|
|
|
if ('price DESC' === $orderby) { |
424
|
|
|
$orderbyTrans = '' . \_ADSLIGHT_PRICEHTOL . ''; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return $orderbyTrans; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param $orderby |
432
|
|
|
* |
433
|
|
|
* @return string |
434
|
|
|
*/ |
435
|
|
|
public static function convertOrderByOut($orderby): string |
436
|
|
|
{ |
437
|
|
|
if ('title ASC' === $orderby) { |
438
|
|
|
$orderby = 'titleA'; |
439
|
|
|
} |
440
|
|
|
if ('date_created ASC' === $orderby) { |
441
|
|
|
$orderby = 'dateA'; |
442
|
|
|
} |
443
|
|
|
if ('hits ASC' === $orderby) { |
444
|
|
|
$orderby = 'hitsA'; |
445
|
|
|
} |
446
|
|
|
if ('price ASC' === $orderby) { |
447
|
|
|
$orderby = 'priceA'; |
448
|
|
|
} |
449
|
|
|
if ('title DESC' === $orderby) { |
450
|
|
|
$orderby = 'titleD'; |
451
|
|
|
} |
452
|
|
|
if ('date_created DESC' === $orderby) { |
453
|
|
|
$orderby = 'dateD'; |
454
|
|
|
} |
455
|
|
|
if ('hits DESC' === $orderby) { |
456
|
|
|
$orderby = 'hitsD'; |
457
|
|
|
} |
458
|
|
|
if ('price DESC' === $orderby) { |
459
|
|
|
$orderby = 'priceD'; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
return $orderby; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @param $tablename |
468
|
|
|
* |
469
|
|
|
* @return bool |
470
|
|
|
*/ |
471
|
|
|
public static function checkTableExists($tablename): bool |
472
|
|
|
{ |
473
|
|
|
global $xoopsDB; |
474
|
|
|
$result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
475
|
|
|
|
476
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* @param $fieldname |
481
|
|
|
* @param $table |
482
|
|
|
* |
483
|
|
|
* @return bool |
484
|
|
|
*/ |
485
|
|
|
public static function checkFieldExists($fieldname, $table): bool |
486
|
|
|
{ |
487
|
|
|
global $xoopsDB; |
488
|
|
|
$result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
489
|
|
|
|
490
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* @param $cid |
496
|
|
|
* |
497
|
|
|
* @return bool |
498
|
|
|
*/ |
499
|
|
|
public static function getCatNameFromId($cid): bool |
500
|
|
|
{ |
501
|
|
|
global $xoopsDB, $myts; |
502
|
|
|
|
503
|
|
|
$sql = 'SELECT SQL_CACHE title FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid = '$cid'"; |
504
|
|
|
|
505
|
|
|
if (!$result = $xoopsDB->query($sql)) { |
506
|
|
|
return false; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
if (!$arr = $xoopsDB->fetchArray($result)) { |
510
|
|
|
return false; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
$title = $arr['title']; |
514
|
|
|
|
515
|
|
|
return $title; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* @return array |
520
|
|
|
*/ |
521
|
|
|
public static function goCategory(): array |
522
|
|
|
{ |
523
|
|
|
global $xoopsDB; |
524
|
|
|
|
525
|
|
|
$xoopsTree = new \XoopsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
526
|
|
|
$jump = XOOPS_URL . '/modules/adslight/viewcats.php?cid='; |
527
|
|
|
\ob_start(); |
528
|
|
|
$xoopsTree->makeMySelBox('title', 'title', 0, 1, 'pid', 'location="' . $jump . '"+this.options[this.selectedIndex].value'); |
529
|
|
|
$block['selectbox'] = \ob_get_clean(); |
|
|
|
|
530
|
|
|
|
531
|
|
|
return $block; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
// ADSLIGHT Version 2 // |
535
|
|
|
// Fonction rss.php RSS par categories |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* @return array |
539
|
|
|
*/ |
540
|
|
|
public static function returnAllAdsRss(): array |
541
|
|
|
{ |
542
|
|
|
global $xoopsDB; |
543
|
|
|
|
544
|
|
|
$cid = Request::getInt('cid', null, 'GET'); |
545
|
|
|
|
546
|
|
|
$result = []; |
547
|
|
|
|
548
|
|
|
$sql = 'SELECT lid, title, price, date_created, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' AND cid=" . $xoopsDB->escape($cid) . ' ORDER BY date_created DESC'; |
549
|
|
|
|
550
|
|
|
$resultValues = $xoopsDB->query($sql); |
551
|
|
|
while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
552
|
|
|
$result[] = $resultTemp; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
return $result; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
// Fonction fluxrss.php RSS Global |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* @return array |
562
|
|
|
*/ |
563
|
|
|
public static function returnAllAdsFluxRss(): array |
564
|
|
|
{ |
565
|
|
|
global $xoopsDB; |
566
|
|
|
|
567
|
|
|
$result = []; |
568
|
|
|
|
569
|
|
|
$sql = 'SELECT lid, title, price, desctext, date_created, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' ORDER BY date_created DESC LIMIT 0,15"; |
570
|
|
|
|
571
|
|
|
$resultValues = $xoopsDB->query($sql); |
572
|
|
|
while (false !== ($resultTemp = $xoopsDB->fetchBoth($resultValues))) { |
573
|
|
|
$result[] = $resultTemp; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
return $result; |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* @param $type |
581
|
|
|
* |
582
|
|
|
* @return mixed |
583
|
|
|
*/ |
584
|
|
|
public static function getNameType($type) |
585
|
|
|
{ |
586
|
|
|
global $xoopsDB; |
587
|
|
|
$sql = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . " WHERE id_type='" . $xoopsDB->escape($type) . "'"); |
588
|
|
|
[$nom_type] = $xoopsDB->fetchRow($sql); |
589
|
|
|
|
590
|
|
|
return $nom_type; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* Saves permissions for the selected category |
596
|
|
|
* |
597
|
|
|
* saveCategory_Permissions() |
598
|
|
|
* |
599
|
|
|
* @param array $groups : group with granted permission |
600
|
|
|
* @param $categoryId |
601
|
|
|
* @param $permName |
602
|
|
|
* @return bool : TRUE if the no errors occured |
603
|
|
|
*/ |
604
|
|
|
public static function saveCategoryPermissions($groups, $categoryId, $permName): bool |
605
|
|
|
{ |
606
|
|
|
global $xoopsModule; |
607
|
|
|
$helper = \XoopsModules\Adslight\Helper::getInstance(); |
|
|
|
|
608
|
|
|
|
609
|
|
|
$result = true; |
610
|
|
|
// $xoopsModule = sf_getModuleInfo(); |
611
|
|
|
// $moduleId = $helper->getModule()->getVar('mid'); |
612
|
|
|
$moduleId = $xoopsModule->getVar('mid'); |
613
|
|
|
|
614
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
615
|
|
|
// First, if the permissions are already there, delete them |
616
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
617
|
|
|
$grouppermHandler->deleteByModule($moduleId, $permName, $categoryId); |
618
|
|
|
// Save the new permissions |
619
|
|
|
if (\count($groups) > 0) { |
620
|
|
|
foreach ($groups as $groupId) { |
621
|
|
|
$grouppermHandler->addRight($permName, $categoryId, $groupId, $moduleId); |
622
|
|
|
} |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
return $result; |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
|
629
|
|
|
/*********************************************************************** |
630
|
|
|
* $fldVersion : dossier version de fancybox |
631
|
|
|
***********************************************************************/ |
632
|
|
|
public static function load_lib_js(): void |
633
|
|
|
{ |
634
|
|
|
global $xoTheme, $xoopsModuleConfig; |
635
|
|
|
|
636
|
|
|
$fld = XOOPS_URL . '/modules/adslight/' . 'assets/'; |
637
|
|
|
|
638
|
|
|
if (1 == $GLOBALS['xoopsModuleConfig']['adslight_lightbox']) { |
639
|
|
|
// $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/plugins/jquery.lightbox.js'); |
640
|
|
|
// $xoTheme->addStyleSheet(XOOPS_URL . '/browse.php?Frameworks/jquery/plugins/jquery.lightbox.js'); |
641
|
|
|
|
642
|
|
|
$xoTheme->addScript($fld . '/js/lightbox/js/lightbox.js'); |
643
|
|
|
$xoTheme->addStyleSheet($fld . '/js/lightbox/css/lightbox.css'); |
644
|
|
|
} else { |
645
|
|
|
//$xoTheme->addStyleSheet($fld . "/css/galery.css" type="text/css" media="screen"); |
646
|
|
|
|
647
|
|
|
} |
648
|
|
|
/* |
649
|
|
|
if (1 == $GLOBALS['xoopsModuleConfig']['adslight_lightbox']) { |
650
|
|
|
$header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" > |
651
|
|
|
<script type="text/javascript" src="assets/lightbox/js/jquery-1.7.2.min.js"></script> |
652
|
|
|
<script type="text/javascript" src="assets/lightbox/js/jquery-ui-1.8.18.custom.min"></script> |
653
|
|
|
<script type="text/javascript" src="assets/lightbox/js/jquery.smooth-scroll.min.js"></script> |
654
|
|
|
<script type="text/javascript" src="assets/lightbox/js/lightbox.js"></script> |
655
|
|
|
|
656
|
|
|
<link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" > |
657
|
|
|
<link rel="stylesheet" type="text/css" media="screen" href="assets/lightbox/css/lightbox.css"></link>'; |
658
|
|
|
} else { |
659
|
|
|
$header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" > |
660
|
|
|
<link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" >'; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
|
664
|
|
|
$fldVersion = "fancybox_215"; |
665
|
|
|
$fbFolder = XOOPS_URL . "/Frameworks/" . $fldVersion; |
666
|
|
|
//$modFolder = "modules/" . $module_dirname; |
667
|
|
|
$modFolder = "modules/" . 'mediatheque'; |
668
|
|
|
|
669
|
|
|
//$xoTheme->addStyleSheet($fModule . '/css/style.css'); |
670
|
|
|
$xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
671
|
|
|
|
672
|
|
|
//to-do : a remplacer par jquery.mousewheel-3.0.6.pack.js |
673
|
|
|
$xoTheme->addScript($fbFolder . "/jquery.mousewheel-3.0.4.pack.js"); |
674
|
|
|
|
675
|
|
|
$xoTheme->addStyleSheet($fbFolder . "/jquery.fancybox.css?v=2.1.5"); |
676
|
|
|
$xoTheme->addScript($fbFolder . "/jquery.fancybox.js?v=2.1.5"); |
677
|
|
|
|
678
|
|
|
//----------------------------------------- |
679
|
|
|
// OPTIONAL |
680
|
|
|
$xoTheme->addStyleSheet($fbFolder . "/helpers/jquery.fancybox-buttons.css?v=1.0.5"); |
681
|
|
|
$xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-buttons.js?v=1.0.5"); |
682
|
|
|
|
683
|
|
|
$xoTheme->addStyleSheet($fbFolder . "/helpers/jquery.fancybox-thumbs.css?v=1.0.7"); |
684
|
|
|
$xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-thumbs.js?v=1.0.7"); |
685
|
|
|
|
686
|
|
|
$xoTheme->addScript($fbFolder . "/helpers/jquery.fancybox-media.js?v=1.0.6"); |
687
|
|
|
|
688
|
|
|
//----------------------------------------- |
689
|
|
|
|
690
|
|
|
|
691
|
|
|
|
692
|
|
|
$xoTheme->addScript($modFolder . "/js/media.fancybox.js"); |
693
|
|
|
|
694
|
|
|
*/ |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Currency Format |
699
|
|
|
* |
700
|
|
|
* @param float $number |
701
|
|
|
* @param string $currency The 3-letter ISO 4217 currency code indicating the currency to use. |
702
|
|
|
* @param string $localeCode (local language code, e.g. en_US) |
703
|
|
|
* @return string formatted currency value |
704
|
|
|
*/ |
705
|
|
|
public static function formatCurrency($number, $currency = 'USD', $localeCode = ''): ?string |
706
|
|
|
{ |
707
|
|
|
$localeCode ?? \locale_get_default(); |
708
|
|
|
$fmt = new \NumberFormatter($localeCode, \NumberFormatter::CURRENCY); |
709
|
|
|
return $fmt->formatCurrency($number, $currency); |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Currency Format (temporary) |
714
|
|
|
* |
715
|
|
|
* @param float $number |
716
|
|
|
* @param string $currency The 3-letter ISO 4217 currency code indicating the currency to use. |
717
|
|
|
* @param string $currencySymbol |
718
|
|
|
* @param int $currencyPosition |
719
|
|
|
* @return string formatted currency value |
720
|
|
|
*/ |
721
|
|
|
public static function formatCurrencyTemp($number, $currency = 'USD', $currencySymbol = '$', $currencyPosition = 0): string |
|
|
|
|
722
|
|
|
{ |
723
|
|
|
$currentDefault = \locale_get_default(); |
724
|
|
|
$fmt = new \NumberFormatter($currentDefault, \NumberFormatter::DECIMAL); |
725
|
|
|
$formattedNumber = $fmt->format($number); |
726
|
|
|
return 1 === $currencyPosition ? $currencySymbol . $formattedNumber : $formattedNumber . ' ' . $currencySymbol; |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
|