|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| -* include/search.inc.php - search gwiki pages |
4 |
| -* |
5 |
| -* This file is part of gwiki - geekwright wiki |
6 |
| -* |
7 |
| -* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
8 |
| -* @license gwiki/docs/license.txt GNU General Public License (GPL) |
9 |
| -* @since 1.0 |
10 |
| -* @author Richard Griffith <[email protected]> |
11 |
| -* @package gwiki |
12 |
| -* @version $Id$ |
13 |
| -*/ |
14 |
| -function gwiki_search($queryarray, $andor, $limit, $offset, $userid, $prefix=null) |
| 3 | + * include/search.inc.php - search gwiki pages |
| 4 | + * |
| 5 | + * This file is part of gwiki - geekwright wiki |
| 6 | + * |
| 7 | + * @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
| 8 | + * @license gwiki/docs/license.txt GNU General Public License (GPL) |
| 9 | + * @since 1.0 |
| 10 | + * @author Richard Griffith <[email protected]> |
| 11 | + * @package gwiki |
| 12 | + * @version $Id$ |
| 13 | + * @param $queryarray |
| 14 | + * @param $andor |
| 15 | + * @param $limit |
| 16 | + * @param $offset |
| 17 | + * @param $userid |
| 18 | + * @param null $prefix |
| 19 | + * @return array |
| 20 | + */ |
| 21 | +function gwiki_search($queryarray, $andor, $limit, $offset, $userid, $prefix = null) |
15 | 22 | {
|
16 | 23 | global $xoopsDB;
|
17 | 24 |
|
18 |
| - $dir = basename( dirname ( dirname( __FILE__ ) ) ) ; |
| 25 | + $dir = basename(dirname(__DIR__)); |
19 | 26 |
|
20 |
| - $module_handler = xoops_gethandler('module'); |
| 27 | + $module_handler = &xoops_gethandler('module'); |
21 | 28 | $module = $module_handler->getByDirname($dir);
|
22 |
| - $module_id = $module->getVar('mid'); |
23 |
| - $config_handler = xoops_gethandler('config'); |
| 29 | + $module_id = $module->getVar('mid'); |
| 30 | + $config_handler = &xoops_gethandler('config'); |
24 | 31 | $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
|
25 | 32 |
|
26 | 33 | $baseurl = $moduleConfig['searchlink_template'];
|
27 |
| - $args=implode('+',$queryarray); // template should include '&query=' |
28 | 34 |
|
29 |
| - $pagesetq=''; |
30 |
| - if (substr_compare($queryarray[count($queryarray)-1],'{pageset=', 0, 9)===0) { |
31 |
| - $pageset=array_pop($queryarray); |
32 |
| - $pageset=substr($pageset,9,-1); |
| 35 | + if ($queryarray == '') { |
| 36 | + $args = ''; |
| 37 | + } else { |
| 38 | + $args = implode('+', $queryarray);// template should include '&query=' |
| 39 | + } |
| 40 | + |
| 41 | + $pagesetq = ''; |
| 42 | + if (is_array($queryarray) && (count($queryarray) > 1) && substr_compare($queryarray[count($queryarray) - 1], '{pageset=', 0, 9) === 0) { |
| 43 | + $pageset = array_pop($queryarray); |
| 44 | + $pageset = substr($pageset, 9, -1); |
33 | 45 | trigger_error($pageset);
|
34 |
| - $pagesetq=" AND page_set_home = '{$pageset}' "; |
| 46 | + $pagesetq = " AND page_set_home = '{$pageset}' "; |
35 | 47 | }
|
36 | 48 |
|
37 |
| - $sql = "SELECT DISTINCT * FROM ".$xoopsDB->prefix('gwiki_pages')." WHERE active=1 ".$pagesetq; |
| 49 | + $sql = "SELECT DISTINCT * FROM " . $xoopsDB->prefix('gwiki_pages') . " WHERE active=1 " . $pagesetq; |
38 | 50 | if (is_array($queryarray) && ($count = count($queryarray))) {
|
39 | 51 | $sql .= " AND (title LIKE '%$queryarray[0]%' OR search_body LIKE '%$queryarray[0]%' OR meta_keywords LIKE '%$queryarray[0]%' OR meta_description LIKE '%$queryarray[0]%')";
|
40 |
| - for ($i = 1; $i < $count; $i++) { |
| 52 | + for ($i = 1; $i < $count; ++$i) { |
41 | 53 | $sql .= " $andor (title LIKE '%$queryarray[$i]%' OR search_body LIKE '%$queryarray[$i]%' OR meta_keywords LIKE '%$queryarray[$i]%' OR meta_description LIKE '%$queryarray[$i]%')";
|
42 | 54 | }
|
43 | 55 | } else {
|
44 | 56 | $sql .= " AND uid='$userid'";
|
45 | 57 | }
|
46 | 58 | $sql .= " ORDER BY lastmodified DESC";
|
47 | 59 |
|
48 |
| - $items = array(); |
| 60 | + $items = array(); |
49 | 61 | $result = $xoopsDB->query($sql, $limit, $offset);
|
50 | 62 | while ($myrow = $xoopsDB->fetchArray($result)) {
|
51 | 63 | $items[] = array(
|
52 | 64 | 'title' => $myrow['title'],
|
53 |
| - 'link' => sprintf($baseurl,strtolower($myrow['keyword']),$args), |
54 |
| - 'time' => $myrow['lastmodified'], |
55 |
| - 'uid' => $myrow['uid'], |
56 |
| - 'image' => 'assets/images/search-result-icon.png' |
57 |
| - ); |
| 65 | + 'link' => sprintf($baseurl, strtolower($myrow['keyword']), $args), |
| 66 | + 'time' => $myrow['lastmodified'], |
| 67 | + 'uid' => $myrow['uid'], |
| 68 | + 'image' => 'assets/images/search-result-icon.png'); |
58 | 69 | }
|
59 | 70 |
|
60 | 71 | return $items;
|
|
0 commit comments