1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: randomquote |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package randomquote |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <https://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xoopsmodules\randomquote; |
26
|
|
|
|
27
|
|
|
//require_once dirname(__DIR__) . '/class/utility.php'; |
28
|
|
|
/** |
29
|
|
|
* @param $options |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
function showRandomquoteQuotes($options) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
// require_once dirname(__DIR__) . '/class/quotes.php'; |
36
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
37
|
|
|
//$myts = \MyTextSanitizer::getInstance(); |
38
|
|
|
|
39
|
|
|
$block = []; |
40
|
|
|
$blockType = $options[0]; |
41
|
|
|
$quotesCount = $options[1]; |
42
|
|
|
//$titleLenght = $options[2]; |
43
|
|
|
|
44
|
|
|
/** @var XoopsObjectHandler $quotesHandler */ |
45
|
|
|
$quotesHandler = new randomquote\QuotesHandler($GLOBALS['xoopsDB']); |
46
|
|
|
$criteria = new CriteriaCompo(); |
47
|
|
|
array_shift($options); |
48
|
|
|
array_shift($options); |
49
|
|
|
array_shift($options); |
50
|
|
|
if ($blockType) { |
51
|
|
|
$criteria->add(new Criteria('id', 0, '!=')); |
52
|
|
|
$criteria->setSort('id'); |
53
|
|
|
$criteria->setOrder('ASC'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$criteria->setLimit($quotesCount); |
57
|
|
|
$quotesArray = $quotesHandler->getAll($criteria); |
58
|
|
|
foreach (array_keys($quotesArray) as $i) { |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $block; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $options |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
function editRandomquoteQuotes($options) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
require_once dirname(__DIR__) . '/class/quotes.php'; |
72
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
73
|
|
|
|
74
|
|
|
$form = MB_RANDOMQUOTE_DISPLAY; |
75
|
|
|
$form .= "<input type='hidden' name='options[0]' value='" . $options[0] . "' />"; |
76
|
|
|
$form .= "<input name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' type='text' /> <br>"; |
77
|
|
|
$form .= MB_RANDOMQUOTE_TITLELENGTH . " : <input name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' type='text' /><br><br>"; |
78
|
|
|
|
79
|
|
|
/** @var XoopsObjectHandler $'. quotes . 'Handler */ |
80
|
|
|
$quotesHandler = new randomquote\QuotesHandler($GLOBALS['xoopsDB']); // xoops_getModuleHandler('quotes', $moduleDirName); |
81
|
|
|
$criteria = new CriteriaCompo(); |
82
|
|
|
array_shift($options); |
83
|
|
|
array_shift($options); |
84
|
|
|
array_shift($options); |
85
|
|
|
$criteria->add(new Criteria('id', 0, '!=')); |
86
|
|
|
$criteria->setSort('id'); |
87
|
|
|
$criteria->setOrder('ASC'); |
88
|
|
|
$quotesArray = $quotesHandler->getAll($criteria); |
89
|
|
|
$form .= MB_RANDOMQUOTE_CATTODISPLAY . "<br><select name='options[]' multiple='multiple' size='5'>"; |
90
|
|
|
$form .= "<option value='0' " . (false === in_array(0, $options) ? '' : "selected='selected'") . '>' . MB_RANDOMQUOTE_ALLCAT . '</option>'; |
91
|
|
|
foreach (array_keys($quotesArray) as $i) { |
92
|
|
|
$id = $quotesArray[$i]->getVar('id'); |
93
|
|
|
$form .= "<option value='" . $id . "' " . (false === in_array($id, $options) ? '' : "selected='selected'") . '>' . $quotesArray[$i]->getVar('quote') . '</option>'; |
94
|
|
|
} |
95
|
|
|
$form .= '</select>'; |
96
|
|
|
|
97
|
|
|
return $form; |
98
|
|
|
} |
99
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.