|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits of |
|
4
|
|
|
supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit |
|
6
|
|
|
authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but |
|
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* Module: RandomQuote |
|
14
|
|
|
* |
|
15
|
|
|
* @category Module |
|
16
|
|
|
* @package randomquote |
|
17
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
18
|
|
|
* @author ZySpec <[email protected]> |
|
19
|
|
|
* @copyright {@link https://xoops.org 2001-2016 XOOPS Project} |
|
20
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
21
|
|
|
* @link https://xoops.org XOOPS |
|
22
|
|
|
* @since 2.11 |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
|
26
|
|
|
|
|
27
|
|
|
XoopsLoad::load('XoopsFilterInput'); |
|
28
|
|
|
|
|
29
|
|
|
/** Get item fields: title, content, time, link, uid, tags |
|
30
|
|
|
* |
|
31
|
|
|
* Note that $items is "by reference" so modifying it in this |
|
32
|
|
|
* routine in effect passes it back... |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $items |
|
35
|
|
|
* |
|
36
|
|
|
* @return bool |
|
37
|
|
|
**/ |
|
38
|
|
|
function randomquote_tag_iteminfo(&$items) |
|
39
|
|
|
{ |
|
40
|
|
|
if (empty($items) || !is_array($items)) { |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
45
|
|
|
require_once $GLOBALS['xoops']->path("/modules/{$moduleDirName}/class/constants.php"); |
|
46
|
|
|
|
|
47
|
|
|
$itemsId = array(); |
|
48
|
|
|
$catsId = array(); |
|
49
|
|
|
|
|
50
|
|
|
foreach (array_keys($items) as $catId) { |
|
51
|
|
|
$catsId[] = (int)$catId; |
|
52
|
|
|
foreach (array_keys($items[$catId]) as $itemId) { |
|
53
|
|
|
$itemsId[] = (int)$itemId; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$criteria = new CriteriaCompo(); |
|
58
|
|
|
$criteria->add(new Criteria('id', '(' . implode(',', $itemsId) . ')', 'IN')); |
|
59
|
|
|
$criteria->add(new Criteria('quote_status', RandomquoteConstants::STATUS_ONLINE)); |
|
60
|
|
|
|
|
61
|
|
|
$quoteHandler = xoops_getModuleHandler('quotes', $moduleDirName); |
|
62
|
|
|
$quoteObjs = $quoteHandler->getObjects($criteria, true); |
|
63
|
|
|
|
|
64
|
|
|
foreach ($catsId as $catId) { |
|
65
|
|
|
foreach ($itemsId as $itemId) { |
|
66
|
|
|
$quoteObj = $quoteObjs[$itemId]; |
|
67
|
|
|
$items[$catId][$itemId] = array('title' => $quoteObj, //uses class majic __toString |
|
68
|
|
|
'link' => "index.php?id={$itemId}", |
|
69
|
|
|
'time' => strtotime($quoteObj->getVar('create_date')), |
|
70
|
|
|
'content' => '', |
|
71
|
|
|
// 'tags' => tag_parse_tag($quoteObj->getVar('item_tag', 'n')), // optional |
|
72
|
|
|
// 'uid' => $quoteObj->getVar('uid'), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
unset($quoteObjs); |
|
78
|
|
|
return true; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Remove orphan tag-item links |
|
83
|
|
|
* |
|
84
|
|
|
* @param int $mid module ID |
|
85
|
|
|
*/ |
|
86
|
|
|
function randomquote_tag_synchronization($mid) |
|
87
|
|
|
{ |
|
88
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
89
|
|
|
require_once $GLOBALS['xoops']->path("/modules/{$moduleDirName}/class/constants.php"); |
|
90
|
|
|
|
|
91
|
|
|
$itemHandler = xoops_getModuleHandler('quotes', $moduleDirName); |
|
92
|
|
|
$linkHandler = xoops_getModuleHandler('link', 'tag'); |
|
93
|
|
|
|
|
94
|
|
|
$itemClass = $moduleDirName . 'QuotesHandler'; |
|
95
|
|
|
if ((!$itemHandler instanceof $itemClass) || (!$linkHandler instanceof TagLink)) { |
|
|
|
|
|
|
96
|
|
|
$result = false; |
|
97
|
|
|
} else { |
|
98
|
|
|
$mid = XoopsFilterInput::clean($mid, 'INT'); |
|
99
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
|
|
|
|
|
100
|
|
|
$rqModule = XoopsModule::getByDirname($moduleDirName); |
|
101
|
|
|
|
|
102
|
|
|
// check to make sure module is active and trying to sync randomquote |
|
103
|
|
|
if (($rqModule instanceof XoopsModule) && $rqModule->isactive() && ($rqModule->mid() == $mid)) { |
|
|
|
|
|
|
104
|
|
|
// clear tag-item links |
|
105
|
|
|
$sql = "DELETE FROM {$linkHandler->table}" |
|
106
|
|
|
. " WHERE tag_modid = {$mid}" |
|
107
|
|
|
. ' AND ' |
|
108
|
|
|
. ' (tag_itemid NOT IN ' |
|
109
|
|
|
. " (SELECT DISTINCT {$itemHandler->keyName} " |
|
110
|
|
|
. " FROM {$itemHandler->table} " |
|
111
|
|
|
. " WHERE {$itemHandler->table}.quote_status = " |
|
112
|
|
|
. RandomquoteConstants::STATUS_ONLINE |
|
113
|
|
|
. ' )' |
|
114
|
|
|
. ' )'; |
|
115
|
|
|
$result = $linkHandler->db->queryF($sql); |
|
116
|
|
|
} else { |
|
117
|
|
|
$result = false; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $result ? true : false; |
|
122
|
|
|
} |
|
123
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.