These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * |
||
4 | * Module: Lexikon - glossary module |
||
5 | * Version: v 1.00 |
||
6 | * Release Date: 8 May 2004 |
||
7 | * Author: hsalazar |
||
8 | * Licence: GNU |
||
9 | */ |
||
10 | |||
11 | include __DIR__ . '/header.php'; |
||
12 | $GLOBALS['xoopsOption']['template_main'] = 'lx_entry.tpl'; |
||
13 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
14 | global $xoTheme, $xoopsUser, $lexikon_module_header; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
15 | $myts = MyTextSanitizer::getInstance(); |
||
16 | xoops_load('XoopsUserUtility'); |
||
17 | |||
18 | include_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php'; |
||
19 | $highlight = LexikonUtility::getModuleOption('config_highlighter'); |
||
20 | if ($highlight) { |
||
21 | include_once XOOPS_ROOT_PATH . '/modules/lexikon/class/keyhighlighter.class.php'; |
||
22 | } |
||
23 | |||
24 | $entryID = isset($_GET['entryID']) ? (int)$_GET['entryID'] : 0; |
||
25 | if (empty($entryID)) { |
||
26 | redirect_header(XOOPS_URL . '/modules/lexikon/index.php', 3, _MD_LEXIKON_UNKNOWNERROR); |
||
27 | } |
||
28 | $entrytype = 1; |
||
29 | // permissions |
||
30 | $gpermHandler = xoops_getHandler('groupperm'); |
||
31 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
32 | $module_id = $xoopsModule->getVar('mid'); |
||
33 | $allowed_cats = $gpermHandler->getItemIds('lexikon_view', $groups, $module_id); |
||
34 | $catids = implode(',', $allowed_cats); |
||
35 | $catperms = " AND categoryID IN ($catids) "; |
||
36 | |||
37 | // If there's no entries yet in the system... |
||
38 | $publishedwords = LexikonUtility::countWords(); |
||
39 | $xoopsTpl->assign('publishedwords', $publishedwords); |
||
40 | if ($publishedwords == 0) { |
||
41 | $xoopsTpl->assign('empty', '1'); |
||
42 | $xoopsTpl->assign('stillnothing', _MD_LEXIKON_STILLNOTHINGHERE); |
||
43 | } |
||
44 | |||
45 | // To display the linked letter list |
||
46 | $alpha = LexikonUtility::getAlphaArray(); |
||
47 | $xoopsTpl->assign('alpha', $alpha); |
||
48 | |||
49 | // list($howmanyother) = $xoopsDB -> fetchRow($xoopsDB->query("SELECT COUNT(*) FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '#' AND offline ='0' ".$catperms."" )); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% 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. ![]() |
|||
50 | list($howmanyother) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(entryID) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' ')); |
||
51 | $xoopsTpl->assign('totalother', $howmanyother); |
||
52 | |||
53 | $xoopsTpl->assign('multicats', (int)$xoopsModuleConfig['multicats']); |
||
54 | // To display the list of categories |
||
55 | View Code Duplication | if ($xoopsModuleConfig['multicats'] == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
56 | $xoopsTpl->assign('block0', LexikonUtility::getCategoryArray()); |
||
57 | $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN); |
||
58 | if ($xoopsModuleConfig['useshots'] == 1) { |
||
59 | $xoopsTpl->assign('show_screenshot', true); |
||
60 | $xoopsTpl->assign('logo_maximgwidth', $xoopsModuleConfig['logo_maximgwidth']); |
||
61 | $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS); |
||
62 | } else { |
||
63 | $xoopsTpl->assign('show_screenshot', false); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | if (!$entryID) { |
||
68 | redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR); |
||
69 | } else { |
||
70 | if ($entryID <= 0) { |
||
71 | redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR); |
||
72 | } |
||
73 | if (!$xoopsUser || ($xoopsUser->isAdmin($xoopsModule->mid()) && $xoopsModuleConfig['adminhits'] == 1) |
||
74 | || ($xoopsUser |
||
75 | && !$xoopsUser->isAdmin($xoopsModule->mid())) |
||
76 | ) { |
||
77 | $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('lxentries') . " SET counter = counter+1 WHERE entryID = $entryID "); |
||
78 | } |
||
79 | |||
80 | $result = $xoopsDB->query('SELECT entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, counter, html, smiley, xcodes, breaks, block, offline, notifypub |
||
81 | FROM ' . $xoopsDB->prefix('lxentries') . " |
||
82 | WHERE entryID = $entryID"); |
||
83 | // verify result |
||
84 | if ($xoopsDB->getRowsNum($result) <= 0) { |
||
85 | redirect_header(XOOPS_URL.'/modules/lexikon/index.php', 2, _MD_LEXIKON_UNKNOWNERROR); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | while (list($entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline) = $xoopsDB->fetchRow($result)) { |
||
90 | $catID = (int)$categoryID; |
||
91 | if (!$gpermHandler->checkRight('lexikon_view', (int)$categoryID, $groups, $module_id)) { |
||
92 | redirect_header('index.php', 3, _NOPERM); |
||
93 | } |
||
94 | |||
95 | $thisterm = array(); |
||
96 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
97 | $thisterm['id'] = (int)$entryID; |
||
98 | $thisterm['offline'] = (int)$offline; |
||
99 | // exit if offline - except admin |
||
100 | if ($thisterm['offline'] == 1 && !$xoopsUserIsAdmin) { |
||
101 | redirect_header('javascript:history.go(-1)', 3, _MD_LEXIKON_ENTRYISOFF); |
||
102 | } |
||
103 | View Code Duplication | if ($xoopsModuleConfig['multicats'] == 1) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
104 | $thisterm['categoryID'] = (int)$categoryID; |
||
105 | $catname = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID "); |
||
106 | while (list($name) = $xoopsDB->fetchRow($catname)) { |
||
107 | $thisterm['catname'] = $myts->htmlSpecialChars($name); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | $glossaryterm = $myts->htmlSpecialChars($term); |
||
112 | $thisterm['term'] = ucfirst($myts->htmlSpecialChars($term)); |
||
113 | if ($init === '#') { |
||
114 | $thisterm['init'] = _MD_LEXIKON_OTHER; |
||
115 | } else { |
||
116 | $thisterm['init'] = ucfirst($init); |
||
117 | } |
||
118 | $thisterm['offline'] = (int)$offline; |
||
119 | |||
120 | if ($xoopsModuleConfig['linkterms'] != 1 && $xoopsModuleConfig['linkterms'] != 2) { |
||
121 | LexikonUtility::getModuleHeader(); |
||
122 | $xoopsTpl->assign('xoops_module_header', $lexikon_module_header); |
||
123 | } else { |
||
124 | $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />'); |
||
125 | } |
||
126 | |||
127 | if ($xoopsModuleConfig['linkterms'] != 1) { |
||
128 | // Code to make links out of glossary terms |
||
129 | $parts = explode('>', $definition); |
||
130 | |||
131 | // First, retrieve all terms from the glossary... |
||
132 | $allterms = $xoopsDB->query('SELECT entryID, term, definition FROM ' . $xoopsDB->prefix('lxentries') . " WHERE offline ='0' " . $catperms . ' '); |
||
133 | |||
134 | while (list($entryID, $term, $definition) = $xoopsDB->fetchrow($allterms)) { |
||
135 | foreach ($parts as $key => $part) { |
||
136 | if ($term != $glossaryterm) { |
||
137 | $term_q = preg_quote($term, '/'); |
||
138 | $search_term = "/\b$term_q\b/SsUi"; |
||
139 | //static link |
||
140 | $staticURL = '' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID=' . ucfirst($entryID) . ''; |
||
141 | switch ($xoopsModuleConfig['linkterms']) { |
||
142 | default: |
||
143 | $replace_term = '<span><b><a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="' . $staticURL . '" >' . $term . '</a></b></span>'; |
||
144 | break; |
||
145 | View Code Duplication | case 3: //tooltip |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
146 | $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150)); |
||
147 | $replace_term = '<a class="parser" href="' . $staticURL . '" onMouseover="ddrivetip(\'' . $tooltipdef . '\', 300)"; onMouseout=\'hideddrivetip()\'>' . $term . '</a>'; |
||
148 | break; |
||
149 | case 4://simple popup |
||
150 | $replace_term = '<a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="#" onClick=\'popup("popup.php?entryID=' |
||
151 | . $entryID |
||
152 | . '","details", 420, 350); return false\'>' |
||
153 | . $term |
||
154 | . '</a>'; |
||
155 | break; |
||
156 | View Code Duplication | case 5:// balloon tooltip |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
157 | $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150)); |
||
158 | $replace_term = '<a class="parser" href="' |
||
159 | . $staticURL |
||
160 | . '" onMouseover="showToolTip(event,\'' |
||
161 | . $tooltipdef |
||
162 | . '\');return false"; onMouseout=\'hideToolTip()\'>' |
||
163 | . $term |
||
164 | . '</a>'; |
||
165 | break; |
||
166 | View Code Duplication | case 6:// shadow tooltip |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
167 | $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150)); |
||
168 | $replace_term = '<a class="parser" href="' . $staticURL . '" onmouseout="hideTooltip()" onmouseover="showTooltip(event,\'' . $tooltipdef . '\')"; >' . $term . '</a>'; |
||
169 | break; |
||
170 | } |
||
171 | $parts[$key] = preg_replace($search_term, $replace_term, $parts[$key]); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | $definition = implode('>', $parts); |
||
176 | } |
||
177 | $thisterm['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks); |
||
178 | $thisterm['ref'] = $myts->displayTarea($ref, $html, $smiley, $xcodes, 1, $breaks); |
||
179 | $thisterm['url'] = $myts->makeClickable($url, $allowimage = 0); |
||
180 | //$thisterm['submitter'] = XoopsUserUtility::getUnameFromId ( $uid ); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
53% 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. ![]() |
|||
181 | if ($xoopsModuleConfig['showsubmitter'] == 1) { |
||
182 | $xoopsTpl->assign('showsubmitter', true); |
||
183 | if ($xoopsModuleConfig['authorprofile'] == 1) { |
||
184 | $thisterm['submitter'] = LexikonUtility::getLinkedProfileFromId($uid); |
||
185 | } else { |
||
186 | $thisterm['submitter'] = XoopsUserUtility::getUnameFromId($uid); |
||
187 | } |
||
188 | } else { |
||
189 | $xoopsTpl->assign('showsubmitter', false); |
||
190 | } |
||
191 | $thisterm['submit'] = (int)$submit; |
||
192 | $thisterm['datesub'] = formatTimestamp($datesub, $xoopsModuleConfig['dateformat']); |
||
193 | $thisterm['counter'] = (int)$counter; |
||
194 | $thisterm['block'] = (int)$block; |
||
195 | $thisterm['dir'] = $xoopsModule->dirname(); |
||
196 | if ($highlight && isset($_GET['keywords'])) { |
||
197 | $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
||
198 | $h = new lx_keyhighlighter($keywords, true, 'lx_myhighlighter'); |
||
199 | $thisterm['definition'] = $h->highlight($thisterm['definition']); |
||
200 | $thisterm['ref'] = $h->highlight($thisterm['ref']); |
||
201 | } |
||
202 | } |
||
203 | //smartry strings |
||
204 | $xoopsTpl->assign('thisterm', $thisterm); |
||
205 | $microlinks = LexikonUtility::getServiceLinks($thisterm); |
||
206 | $microlinksnew = LexikonUtility::getServiceLinksNew($thisterm); |
||
207 | $xoopsTpl->assign('microlinks', $microlinks); |
||
208 | $xoopsTpl->assign('microlinksnew', $microlinksnew); |
||
209 | $xoopsTpl->assign('lang_modulename', $xoopsModule->name()); |
||
210 | $xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname')); |
||
211 | $xoopsTpl->assign('entryID', $entryID); |
||
212 | $xoopsTpl->assign('submittedon', sprintf(_MD_LEXIKON_SUBMITTEDON, $thisterm['datesub'])); |
||
213 | if ($xoopsModuleConfig['showsubmitter'] == 1) { |
||
214 | $xoopsTpl->assign('submitter', sprintf(_MD_LEXIKON_SUBMITTEDBY, $thisterm['submitter'])); |
||
215 | } |
||
216 | $xoopsTpl->assign('counter', sprintf(_MD_LEXIKON_COUNT, $thisterm['counter'])); |
||
217 | $xoopsTpl->assign('entrytype', '1'); |
||
218 | |||
219 | // --- keywordshighligher --- |
||
220 | /** |
||
221 | * @param $matches |
||
222 | * @return string |
||
223 | */ |
||
224 | function lx_myhighlighter($matches) |
||
225 | { |
||
226 | return '<span style="font-weight: bolder; background-color: #FFFF80;">' . $matches[0] . '</span>'; |
||
227 | } |
||
228 | |||
229 | //--- Display tags of this term |
||
230 | #$itemid = $entryID; |
||
231 | /** @var XoopsModuleHandler $moduleHandler */ |
||
232 | $moduleHandler = xoops_getHandler('module'); |
||
233 | $tagsModule = $moduleHandler->getByDirname('tag'); |
||
234 | if (is_object($tagsModule)) { |
||
235 | include_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php'; |
||
236 | |||
237 | $itemid = isset($_GET['entryID']) ? (int)$_GET['entryID'] : 0; |
||
238 | $catid = 0; |
||
239 | //$xoopsTpl->assign('tagbar', tagBar($itemid, $catid = 0)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% 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. ![]() |
|||
240 | $tagbar = tagBar($itemid, $catid); |
||
241 | if ($tagbar) { |
||
242 | $xoopsTpl->assign('tagbar', $tagbar); |
||
243 | $tagsmeta = implode(' ', $tagbar['tags']); |
||
244 | } else { |
||
245 | $tagsmeta = ''; |
||
246 | } |
||
247 | } else { |
||
248 | $xoopsTpl->assign('tagbar', false); |
||
249 | $tagsmeta = ''; |
||
250 | } |
||
251 | |||
252 | //--- linkterms assigns |
||
253 | // Balloontips |
||
254 | if ($xoopsModuleConfig['linkterms'] == 5) { |
||
255 | $xoopsTpl->assign('balloontips', true); |
||
256 | } else { |
||
257 | $xoopsTpl->assign('balloontips', false); |
||
258 | } |
||
259 | |||
260 | // Show Bookmark icons ? |
||
261 | switch ($xoopsModuleConfig['bookmarkme']) { |
||
262 | case '0': |
||
263 | default: |
||
264 | $xoopsTpl->assign('bookmarkme', false); |
||
265 | break; |
||
266 | case '1': |
||
267 | $xoopsTpl->assign('bookmarkme', 1); |
||
268 | $xoopsTpl->assign('encoded_title', rawurlencode($thisterm['term'])); |
||
269 | break; |
||
270 | case '2': |
||
271 | $xoopsTpl->assign('bookmarkme', 2); |
||
272 | break; |
||
273 | case '3': |
||
274 | $xoopsTpl->assign('bookmarkme', 3); |
||
275 | break; |
||
276 | } |
||
277 | // Meta data |
||
278 | $meta_description = xoops_substr(LexikonUtility::convertHtml2text($thisterm['definition']), 0, 150); |
||
279 | if ($xoopsModuleConfig['multicats'] == 1) { |
||
280 | LexikonUtility::createPageTitle($thisterm['term'] . ' - ' . $thisterm['catname']); |
||
281 | LexikonUtility::extractKeywords($myts->htmlSpecialChars($xoopsModule->name()) . ' ,' . $thisterm['term'] . ' ,' . $thisterm['catname'] . ', ' . $meta_description . ', ' . $tagsmeta); |
||
282 | LexikonUtility::getMetaDescription($myts->htmlSpecialChars($xoopsModule->name()) . ' ' . $thisterm['catname'] . ' ' . $thisterm['term'] . ' ' . $meta_description); |
||
283 | } else { |
||
284 | LexikonUtility::createPageTitle($thisterm['term']); |
||
285 | LexikonUtility::extractKeywords($myts->htmlSpecialChars($xoopsModule->name()) . ' ,' . $thisterm['term'] . ', ' . $meta_description . ', ' . $tagsmeta); |
||
286 | LexikonUtility::getMetaDescription($myts->htmlSpecialChars($xoopsModule->name()) . ' ' . $thisterm['term'] . ' ' . $meta_description); |
||
287 | } |
||
288 | //Mondarse |
||
289 | include XOOPS_ROOT_PATH . '/include/comment_view.php'; |
||
290 | //Mondarse |
||
291 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
292 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.