1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* Marquee - MODULE FOR XOOPS |
5
|
|
|
* Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com) |
6
|
|
|
* |
7
|
|
|
* You may not change or alter any portion of this comment or credits |
8
|
|
|
* of supporting developers from this source code or any supporting source code |
9
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
* |
14
|
|
|
* @copyright Hervé Thouzard (https://www.herve-thouzard.com) |
15
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
16
|
|
|
* @author Hervé Thouzard (https://www.herve-thouzard.com) |
17
|
|
|
* |
18
|
|
|
* Version : |
19
|
|
|
* **************************************************************************** |
20
|
|
|
* |
21
|
|
|
* @param $limit |
22
|
|
|
* @param $dateFormat |
23
|
|
|
* @param $itemsSize |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use XoopsModules\Marquee\{ |
29
|
|
|
Utility |
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
// Script to list recent partners from the xoopspartners module (tested with version 1.1) |
33
|
|
|
function b_marquee_xoopspartners($limit, $dateFormat, $itemsSize) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$block = []; |
36
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
37
|
|
|
$arrayIds = []; |
|
|
|
|
38
|
|
|
$arrayIds = xoopspartners_random($limit); |
39
|
|
|
global $xoopsDB; |
40
|
|
|
foreach ($arrayIds as $id) { |
41
|
|
|
$sql = 'SELECT id, url, image, title FROM ' . $xoopsDB->prefix('partners') . " WHERE id=$id"; |
42
|
|
|
$result = Utility::queryAndCheck($xoopsDB, $sql); |
43
|
|
|
[$id, $url, $image, $title] = $xoopsDB->fetchRow($result); |
44
|
|
|
$origtitle = $title; |
45
|
|
|
$title = htmlspecialchars($title, ENT_QUOTES | ENT_HTML5); |
|
|
|
|
46
|
|
|
if ($itemsSize > 0) { |
47
|
|
|
$title = htmlspecialchars(mb_substr($origtitle, 0, 19), ENT_QUOTES | ENT_HTML5); |
48
|
|
|
} else { |
49
|
|
|
$title = htmlspecialchars($origtitle, ENT_QUOTES | ENT_HTML5); |
50
|
|
|
} |
51
|
|
|
$block[] = [ |
52
|
|
|
'date' => '', |
53
|
|
|
'category' => '', |
54
|
|
|
'author' => '', |
55
|
|
|
'title' => $title, |
56
|
|
|
'link' => "<a href='" . XOOPS_URL . '/modules/xoopspartners/vpartner.php?id=' . $id . "'>" . $title . '</a>', |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $block; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $numberPartners |
65
|
|
|
* @param bool $random |
66
|
|
|
* @param string $orden |
67
|
|
|
* @param string $desc |
68
|
|
|
* |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
function xoopspartners_random($numberPartners, $random = true, $orden = '', $desc = '') |
72
|
|
|
{ |
73
|
|
|
global $xoopsDB; |
74
|
|
|
$PartnersId = []; |
75
|
|
|
$ArrayReturn = []; |
76
|
|
|
$numrows = 0; |
77
|
|
|
if ($random) { |
78
|
|
|
$sql = 'SELECT id FROM ' . $xoopsDB->prefix('partners') . ' WHERE status = 1'; |
79
|
|
|
$result = Utility::queryAndCheck($xoopsDB, $sql); |
80
|
|
|
$numrows = $xoopsDB->getRowsNum($result); |
81
|
|
|
} else { |
82
|
|
|
$result = $xoopsDB->query('SELECT id FROM ' . $xoopsDB->prefix('partners') . ' WHERE status = 1 ORDER BY ' . $orden . ' ' . $desc, $numberPartners); |
83
|
|
|
} |
84
|
|
|
while (false !== ($ret = $xoopsDB->fetchArray($result))) { |
85
|
|
|
$PartnersId[] = $ret['id']; |
86
|
|
|
} |
87
|
|
|
if (($numrows <= $numberPartners) || (!$random)) { |
88
|
|
|
return $PartnersId; |
89
|
|
|
} |
90
|
|
|
$numberTotal = 0; |
91
|
|
|
$totalPartner = count($PartnersId) - 1; |
92
|
|
|
while ($numberPartners > $numberTotal) { |
93
|
|
|
$RandomPart = random_int(0, $totalPartner); |
94
|
|
|
if (!in_array($PartnersId[$RandomPart], $ArrayReturn, true)) { |
95
|
|
|
$ArrayReturn[] = $PartnersId[$RandomPart]; |
96
|
|
|
++$numberTotal; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $ArrayReturn; |
101
|
|
|
} |
102
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.