These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?PHP |
||
2 | /** |
||
3 | * $Id: search.php v 1.0 8 May 2004 hsalazar Exp $ |
||
4 | * Module: Lexikon - glossary module |
||
5 | * Version: v 1.00 |
||
6 | * Release Date: 18 Dec 2011 |
||
7 | * Author: hsalazar |
||
8 | * Licence: GNU |
||
9 | */ |
||
10 | #$xoopsOption['pagetype'] = "search"; |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | include("header.php"); |
||
13 | $xoopsOption['template_main'] = 'lx_search.html'; |
||
14 | include XOOPS_ROOT_PATH."/header.php"; |
||
15 | |||
16 | global $xoTheme, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $searchtype; |
||
17 | $myts =& MyTextSanitizer::getInstance(); |
||
18 | // -- options |
||
19 | include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php'; |
||
20 | $highlight = false; |
||
21 | $highlight = ( $xoopsModuleConfig['config_highlighter'] = 1 ) ? 1:0; |
||
22 | //$highlight = lx_getmoduleoption('config_highlighter'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
23 | $hightlight_key = ''; |
||
24 | |||
25 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
26 | |||
27 | // Check if search is enabled site-wide |
||
28 | $config_handler =& xoops_gethandler('config'); |
||
29 | $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||
30 | if ($xoopsConfigSearch['enable_search'] != 1) { |
||
31 | header('location: '.XOOPS_URL.'/modules/' .$xoopsModule->dirname(). '/index.php'); |
||
32 | exit(); |
||
33 | } |
||
34 | |||
35 | // permissions |
||
36 | $gperm_handler =& xoops_gethandler('groupperm'); |
||
37 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
38 | $module_id = $xoopsModule->getVar('mid'); |
||
39 | $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id); |
||
40 | $catids = implode(',', $allowed_cats); |
||
41 | |||
42 | extract($_GET); |
||
43 | extract($_POST, EXTR_OVERWRITE); |
||
44 | |||
45 | $action = isset($action) ? trim($action) : "search"; |
||
46 | $query = isset($term) ? trim($term) : ""; |
||
47 | $start = isset($start) ? intval($start) : 0; |
||
48 | $categoryID = isset($categoryID) ? intval($categoryID) : 0; |
||
49 | $type = isset($type) ? intval($type) : 3; |
||
50 | $queries = array(); |
||
51 | |||
52 | if ($xoopsModuleConfig['multicats'] == 1) { |
||
53 | $xoopsTpl->assign('multicats', 1); |
||
54 | $totalcats = lx_countCats(); |
||
55 | $xoopsTpl->assign('totalcats', $totalcats); |
||
56 | } else { |
||
57 | $xoopsTpl->assign('multicats', 0); |
||
58 | } |
||
59 | |||
60 | // Configure search parameters according to selector |
||
61 | $query = stripslashes($query); |
||
62 | if ($type == "1") { $searchtype = "( w.term LIKE '%$query%' )"; } |
||
63 | if ($type == "2") { $searchtype = "( definition LIKE '%$query%' )"; } |
||
64 | if ($type == "3") { $searchtype = "(( term LIKE '%$query%' OR definition LIKE '%$query%' OR ref LIKE '%$query%' ))"; } |
||
65 | |||
66 | View Code Duplication | if ($xoopsModuleConfig['multicats'] == 1) { |
|
67 | // If the search is in a particular category |
||
68 | if ($categoryID > 0 ) { |
||
69 | $andcatid = "AND categoryID = '$categoryID' "; |
||
70 | } else { |
||
71 | $andcatid = ""; |
||
72 | } |
||
73 | } else { |
||
74 | $andcatid = ""; |
||
75 | } |
||
76 | |||
77 | // Counter |
||
78 | $publishedwords = lx_countWords(); |
||
79 | $xoopsTpl->assign('publishedwords', $publishedwords); |
||
80 | |||
81 | // If there's no term here (calling directly search page) |
||
82 | if (!$query) { |
||
83 | // Display message saying there's no term and explaining how to search |
||
84 | $xoopsTpl -> assign ('intro', _MD_LEXIKON_NOSEARCHTERM ); |
||
85 | // Display search form |
||
86 | $searchform = lx_showSearchForm(); |
||
87 | $xoopsTpl->assign('searchform', $searchform); |
||
88 | } else { |
||
89 | // IF results, count number |
||
90 | $catrestrict = " categoryID IN ($catids) "; |
||
91 | $searchquery = $xoopsDB -> query ("SELECT COUNT(*) as nrows FROM ".$xoopsDB->prefix ("lxentries")." w WHERE offline='0' AND ".$catrestrict." ".$andcatid." AND $searchtype ORDER BY term DESC"); |
||
92 | list($results) = $xoopsDB->fetchRow($searchquery); |
||
93 | |||
94 | if ($results == 0) { |
||
95 | // There's been no correspondences with the searched terms |
||
96 | $xoopsTpl -> assign ('intro', _MD_LEXIKON_NORESULTS ); |
||
97 | |||
98 | // Display search form |
||
99 | $searchform = lx_showSearchForm(); |
||
100 | $xoopsTpl->assign('searchform', $searchform); |
||
101 | // $results > 0 -> there were search results |
||
102 | } else { |
||
103 | // Show paginated list of results |
||
104 | // We'll put the results in an array |
||
105 | $resultset = array(); |
||
106 | |||
107 | // -- highlighter |
||
108 | if ( is_array( $resultset ) ) { |
||
109 | if ($highlight) { |
||
110 | $xoopsTpl -> assign ('highlight', true); |
||
111 | $hightlight_key = "&keywords=" . urlencode(trim($query)); |
||
112 | //$hightlight_key = '&keywords='.urlencode(trim(implode(' ',$query))); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
64% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
113 | } else { |
||
114 | $xoopsTpl -> assign ('highlight', false); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | // How many results will we show in this page? |
||
119 | View Code Duplication | if ($xoopsModuleConfig['multicats'] == 1) { |
|
120 | // If the search is in a particular category |
||
121 | if ($categoryID > 0 ) { |
||
122 | $andcatid2 = "AND w.categoryID = '$categoryID' "; |
||
123 | } else { |
||
124 | $andcatid2 = ""; |
||
125 | } |
||
126 | } else { |
||
127 | $andcatid2 = ""; |
||
128 | } |
||
129 | $catsallow = " w.categoryID IN ($catids) "; |
||
130 | $queryA = "SELECT w.entryID, w.categoryID, w.term, w.init, w.definition, w.datesub, w.ref, c.name AS catname FROM ".$xoopsDB -> prefix( 'lxentries' )." w LEFT JOIN ".$xoopsDB -> prefix( 'lxcategories' )." c ON w.categoryID = c.categoryID WHERE w.offline = '0' AND ".$catsallow." ".$andcatid2." AND ".$searchtype." "; |
||
131 | $queryA .= " ORDER BY w.term ASC"; |
||
132 | $resultA = $xoopsDB -> query ($queryA, $xoopsModuleConfig['indexperpage'], $start ); |
||
133 | |||
134 | while (list( $entryID, $categoryID, $term, $init, $definition, $datesub, $ref, $catname ) = $xoopsDB->fetchRow($resultA)) { |
||
135 | $eachresult = array(); |
||
136 | $xoopsModule = XoopsModule::getByDirname("lexikon"); |
||
137 | $eachresult['dir'] = $xoopsModule->dirname(); |
||
138 | $eachresult['id'] = $entryID; |
||
139 | $eachresult['categoryID'] = $categoryID; |
||
140 | $eachresult['term'] = ucfirst($myts -> htmlSpecialChars( $term )); |
||
141 | $eachresult['date'] = formatTimestamp($datesub,$xoopsModuleConfig['dateformat']); |
||
142 | $eachresult['ref'] = lx_getHTMLHighlight($query,$myts -> htmlSpecialChars( $ref ), '<b style="background-color: #FFFF80; ">', '</b>' ); |
||
143 | $eachresult['catname'] = $myts -> htmlSpecialChars( $catname ); |
||
144 | $tempdef = $myts -> displayTarea ( $definition, 1, 1, 1, 1, 1); |
||
145 | $eachresult['definition'] = lx_getHTMLHighlight( $query, $tempdef, '<b style="background-color: #FFFF80; ">', '</b>' ); |
||
146 | if ($highlight) { |
||
147 | $eachresult['keywords'] = $hightlight_key; |
||
148 | } |
||
149 | // Functional links |
||
150 | $microlinks = lx_serviceLinks ( $eachresult ); |
||
151 | $eachresult['microlinks'] = $microlinks; |
||
152 | $resultset['match'][] = $eachresult; |
||
153 | } |
||
154 | |||
155 | // Msg: there's # results |
||
156 | $xoopsTpl -> assign ('intro', sprintf( _MD_LEXIKON_THEREWERE, $results, $query ) ); |
||
157 | |||
158 | $linkstring = "term=".$query."&start"; |
||
159 | $pagenav = new XoopsPageNav( $results, $xoopsModuleConfig['indexperpage'], $start, $linkstring ); |
||
160 | $resultset['navbar'] = '<div style="text-align:right;">' . $pagenav -> renderNav(6) . '</div>'; |
||
161 | |||
162 | $xoopsTpl -> assign ('resultset', $resultset); |
||
163 | |||
164 | // Display search form |
||
165 | $searchform = lx_showSearchForm(); |
||
166 | $xoopsTpl->assign('searchform', $searchform); |
||
167 | } |
||
168 | } |
||
169 | // Assign variables and close |
||
170 | $xoopsTpl -> assign ( 'lang_modulename', $xoopsModule->name() ); |
||
171 | $xoopsTpl -> assign ( 'lang_moduledirname', $xoopsModule->getVar('dirname') ); |
||
172 | |||
173 | $xoopsTpl->assign("xoops_module_header", '<link rel="stylesheet" type="text/css" href="style.css" />'); |
||
174 | $xoopsTpl->assign('xoops_pagetitle', _MD_LEXIKON_SEARCHENTRY . ' - ' . $myts->htmlSpecialChars($xoopsModule->name())); |
||
175 | |||
176 | // Meta data |
||
177 | $meta_description = _MD_LEXIKON_SEARCHENTRY. ' - ' .$myts->htmlSpecialChars($xoopsModule->name()); |
||
178 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
179 | $xoTheme->addMeta( 'meta', 'description', $meta_description); |
||
180 | } else { |
||
181 | $xoopsTpl->assign('xoops_meta_description', $meta_description); |
||
182 | } |
||
183 | |||
184 | include(XOOPS_ROOT_PATH."/footer.php"); |
||
185 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.