|
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 XOOPS Module Development Team |
|
18
|
|
|
* @copyright {@link http://xoops.org 2001-2016 XOOPS Project} |
|
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @link http://xoops.org XOOPS |
|
21
|
|
|
* @since 2.00 |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
function randomquote_search($queryarray, $andor, $limit, $offset, $userid) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$ret = array(); |
|
27
|
|
|
if (0 != (int)$userid) { |
|
28
|
|
|
return $ret; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
32
|
|
|
include_once $GLOBALS['xoops']->path("/modules/{$moduleDirName}/class/constants.php"); |
|
33
|
|
|
|
|
34
|
|
|
$quoteHandler = xoops_getmodulehandler('quotes', 'randomquote'); |
|
35
|
|
|
$entryFields = array('id', 'quote', 'author', 'create_date'); |
|
36
|
|
|
$criteria = new CriteriaCompo(); |
|
37
|
|
|
$criteria->add(new Criteria('quote_status', RandomquoteConstants::STATUS_ONLINE)); |
|
38
|
|
|
$criteria->setSort('create_date'); |
|
39
|
|
|
$criteria->setOrder('DESC'); |
|
40
|
|
|
$criteria->setLimit((int) $limit); |
|
41
|
|
|
$criteria->setStart((int) $offset); |
|
42
|
|
|
|
|
43
|
|
|
if ((is_array($queryarray)) && !empty($queryarray)) { |
|
44
|
|
|
$criteria->add(new Criteria('quote', "%{$queryarray[0]}%", 'LIKE')); |
|
45
|
|
|
$criteria->add(new Criteria('author', "%{$queryarray[0]}%", 'LIKE'), 'OR'); |
|
46
|
|
|
array_shift($queryarray); //get rid of first element |
|
47
|
|
|
|
|
48
|
|
|
foreach ($queryarray as $query) { |
|
49
|
|
|
$criteria->add(new Criteria('quote', "%{$query}%", 'LIKE'), $andor); |
|
50
|
|
|
$criteria->add(new Criteria('author', "%{$query}%", 'LIKE'), 'OR'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
$quoteObjs = $quoteHandler->getAll($criteria, $entryFields); |
|
54
|
|
|
foreach ($quoteObjs as $thisQuote) { |
|
55
|
|
|
$ttl = xoops_substr(strip_tags((string) $thisQuote), 0, 60, $trimmarker = '...'); |
|
56
|
|
|
$ret[] = array ( |
|
57
|
|
|
'image' => 'assets/images/icons/quote.png', |
|
58
|
|
|
'link' => "index.php?id=" . $thisQuote->getVar('id'), |
|
59
|
|
|
'title' => $ttl, |
|
60
|
|
|
'time' => strtotime($thisQuote->getVar('create_date')), |
|
61
|
|
|
// 'uid' => $entry['uid'] |
|
|
|
|
|
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
unset($quoteObjs); |
|
67
|
|
|
return $ret; |
|
68
|
|
|
} |
|
69
|
|
|
|
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: