1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* $Id: functions.php v 1.0 8 May 2004 hsalazar Exp $ |
4
|
|
|
* Module: Lexikon |
5
|
|
|
* Author: hsalazar |
6
|
|
|
* Additions and Modifications: Yerres |
7
|
|
|
* Licence: GNU |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* lx_getLinkedUnameFromId() |
14
|
|
|
* |
15
|
|
|
* @param integer $userid Userid of author etc |
16
|
|
|
* @param integer $name: 0 Use Usenamer 1 Use realname |
|
|
|
|
17
|
|
|
* @return |
18
|
|
|
**/ |
19
|
|
View Code Duplication |
function lx_getLinkedUnameFromId($userid = 0, $name= 0) { |
|
|
|
|
20
|
|
|
if (!is_numeric($userid)) { |
21
|
|
|
return $userid; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$userid = intval($userid); |
25
|
|
|
if ($userid > 0) { |
26
|
|
|
$member_handler = xoops_gethandler('member'); |
27
|
|
|
$user = $member_handler->getUser($userid); |
28
|
|
|
|
29
|
|
|
if (is_object($user)) { |
30
|
|
|
$ts = MyTextSanitizer::getInstance(); |
31
|
|
|
$username = $user->getVar('uname'); |
32
|
|
|
$usernameu = $user->getVar('name'); |
33
|
|
|
|
34
|
|
|
if ( ($name) && !empty($usernameu)) { |
35
|
|
|
$username = $user->getVar('name'); |
36
|
|
|
} |
37
|
|
|
if ( !empty($usernameu)) { |
38
|
|
|
$linkeduser = "$usernameu [<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". $ts->htmlSpecialChars($username) ."</a>]"; |
39
|
|
|
} else { |
40
|
|
|
$linkeduser = "<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". ucfirst($ts->htmlSpecialChars($username)) ."</a>"; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $linkeduser; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $GLOBALS['xoopsConfig']['anonymous']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
function lx_getuserForm($user) { |
|
|
|
|
51
|
|
|
global $xoopsDB, $xoopsConfig; |
|
|
|
|
52
|
|
|
|
53
|
|
|
echo "<select name='author'>"; |
54
|
|
|
echo "<option value='-1'>------</option>"; |
55
|
|
|
$result = $xoopsDB->query("SELECT uid, uname FROM ".$xoopsDB->prefix("users")." ORDER BY uname"); |
56
|
|
|
|
57
|
|
|
while (list($uid, $uname) = $xoopsDB->fetchRow($result)) { |
58
|
|
|
if ( $uid == $user ) { |
59
|
|
|
$opt_selected = "selected='selected'"; |
60
|
|
|
} else { |
61
|
|
|
$opt_selected = ""; |
62
|
|
|
} |
63
|
|
|
echo "<option value='".$uid."' $opt_selected>".$uname."</option>"; |
64
|
|
|
} |
65
|
|
|
echo "</select></div>"; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
function lx_calculateTotals() { |
|
|
|
|
69
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule; |
|
|
|
|
70
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
71
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
72
|
|
|
|
73
|
|
|
$result01 = $xoopsDB -> query( "SELECT categoryID, total FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " ); |
74
|
|
|
list ( $totalcategories ) = $xoopsDB -> getRowsNum( $result01 ); |
|
|
|
|
75
|
|
|
while (list ( $categoryID, $total ) = $xoopsDB -> fetchRow ( $result01 )) { |
|
|
|
|
76
|
|
|
if ($gperm_handler->checkRight('lexikon_view', $categoryID, $groups, $xoopsModule->getVar('mid'))) { |
77
|
|
|
$newcount = lx_countByCategory ( $categoryID ); |
78
|
|
|
$xoopsDB -> queryF( "UPDATE " . $xoopsDB -> prefix( "lxcategories" ) . " SET total = '$newcount' WHERE categoryID = '$categoryID'"); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
function lx_countByCategory( $c ) { |
|
|
|
|
84
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule; |
|
|
|
|
85
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
|
|
|
86
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
|
|
|
|
87
|
|
|
$count = 0; |
88
|
|
|
$sql = $xoopsDB -> query( "SELECT entryID FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE offline = '0' AND categoryID = '$c'" ); |
89
|
|
|
while ( $myrow = $xoopsDB -> fetchArray( $sql ) ) { |
|
|
|
|
90
|
|
|
//if ($gperm_handler->checkRight('lexikon_view', $c, $groups, $xoopsModule->getVar('mid'))) { |
|
|
|
|
91
|
|
|
$count++; |
92
|
|
|
//} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $count; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
View Code Duplication |
function lx_countCats () { |
|
|
|
|
99
|
|
|
global $xoopsUser, $xoopsModule; |
|
|
|
|
100
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
101
|
|
|
$groups = (is_object($xoopsUser)) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS; |
102
|
|
|
$totalcats = $gperm_handler->getItemIds("lexikon_view", $groups, $xoopsModule->getVar('mid')); |
103
|
|
|
|
104
|
|
|
return count($totalcats); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
View Code Duplication |
function lx_countWords () { |
|
|
|
|
108
|
|
|
global $xoopsUser, $xoopsDB; |
|
|
|
|
109
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
110
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
111
|
|
|
$module_handler = xoops_gethandler('module'); |
112
|
|
|
$module = $module_handler->getByDirname('lexikon'); |
113
|
|
|
$module_id = $module->getVar('mid'); |
114
|
|
|
$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id); |
115
|
|
|
$catids = implode(',', $allowed_cats); |
116
|
|
|
$catperms = " AND categoryID IN ($catids) "; |
117
|
|
|
|
118
|
|
|
$pubwords = $xoopsDB -> query( "SELECT * FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE submit = '0' AND offline ='0' AND request = '0' ".$catperms." " ); |
119
|
|
|
$publishedwords = $xoopsDB -> getRowsNum ( $pubwords ); |
120
|
|
|
|
121
|
|
|
return $publishedwords; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// To display the list of categories |
125
|
|
|
function lx_CatsArray(){ |
126
|
|
|
global $xoopsDB, $xoopsModuleConfig,$xoopsUser,$xoopsModule; |
|
|
|
|
127
|
|
|
$myts = MyTextSanitizer::getInstance(); |
128
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
129
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
130
|
|
|
$block0 = []; |
131
|
|
|
$count = 1; |
132
|
|
|
$resultcat = $xoopsDB -> query ( "SELECT categoryID, name, total, logourl FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY weight ASC" ); |
133
|
|
|
while (list( $catID, $name, $total, $logourl) = $xoopsDB->fetchRow($resultcat)) { |
134
|
|
|
if ($gperm_handler->checkRight('lexikon_view', $catID, $groups, $xoopsModule->getVar('mid'))) { |
135
|
|
|
$catlinks = []; |
136
|
|
|
$count++; |
137
|
|
|
if ($logourl && $logourl != "http://") { |
138
|
|
|
$logourl = $myts->htmlSpecialChars($logourl); |
139
|
|
|
} else { |
140
|
|
|
$logourl = ''; |
141
|
|
|
} |
142
|
|
|
$xoopsModule = XoopsModule::getByDirname("lexikon"); |
143
|
|
|
$catlinks['id'] = intval($catID); |
144
|
|
|
$catlinks['total'] = intval($total); |
145
|
|
|
$catlinks['linktext'] = $myts -> htmlSpecialChars( $name ); |
146
|
|
|
$catlinks['image'] = $logourl; |
147
|
|
|
$catlinks['count'] = intval($count); |
148
|
|
|
|
149
|
|
|
$block0['categories'][] = $catlinks; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $block0; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
function lx_alphaArray () { |
157
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule; |
|
|
|
|
158
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
159
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
160
|
|
|
$module_handler = xoops_gethandler('module'); |
161
|
|
|
$module = $module_handler->getByDirname('lexikon'); |
162
|
|
|
$module_id = $module->getVar('mid'); |
163
|
|
|
$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id); |
164
|
|
|
$catids = implode(',', $allowed_cats); |
165
|
|
|
$catperms = " AND categoryID IN ($catids) "; |
166
|
|
|
$alpha = []; |
167
|
|
View Code Duplication |
for ($a = 65; $a < (65+26); $a++ ) { |
|
|
|
|
168
|
|
|
$letterlinks = []; |
169
|
|
|
$initial = chr($a); |
170
|
|
|
$sql = $xoopsDB -> query ( "SELECT entryID FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' ".$catperms.""); |
171
|
|
|
$howmany = $xoopsDB -> getRowsNum( $sql ); |
172
|
|
|
$letterlinks['total'] = $howmany; |
173
|
|
|
$letterlinks['id'] = chr($a); |
174
|
|
|
$letterlinks['linktext'] = chr($a); |
175
|
|
|
|
176
|
|
|
$alpha['initial'][] = $letterlinks; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return $alpha; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* chr() with unicode support |
184
|
|
|
* I found this on this site http://en.php.net/chr |
185
|
|
|
* don't take credit for this. |
186
|
|
|
* |
187
|
|
|
*/ |
188
|
|
View Code Duplication |
function lx_uchr ($initials) { |
|
|
|
|
189
|
|
|
if (is_scalar($initials)) $initials= func_get_args(); |
190
|
|
|
$str= ''; |
191
|
|
|
foreach ($initials as $init) $str.= html_entity_decode('&#'.$init.';',ENT_NOQUOTES,'UTF-8'); |
192
|
|
|
|
193
|
|
|
return $str; |
194
|
|
|
} |
195
|
|
|
/* sample */ |
196
|
|
|
/* |
|
|
|
|
197
|
|
|
echo lx_uchr(23383); echo '<br/>'; |
198
|
|
|
echo lx_uchr(23383,215,23383); echo '<br/>'; |
199
|
|
|
echo lx_uchr(array(23383,215,23383,215,23383)); echo '<br/>'; |
200
|
|
|
*/ |
201
|
|
|
|
202
|
|
|
// Functional links |
203
|
|
View Code Duplication |
function lx_serviceLinks ( $variable ) { |
|
|
|
|
204
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig, $entrytype; |
|
|
|
|
205
|
|
|
|
206
|
|
|
$module_handler = xoops_gethandler('module'); |
207
|
|
|
$moduleInfo = $module_handler->get($xoopsModule->getVar('mid')); |
|
|
|
|
208
|
|
|
$pathIcon16 = $xoopsModule->getInfo('icons16'); |
209
|
|
|
|
210
|
|
|
$srvlinks = ""; |
211
|
|
|
if ( $xoopsUser ) { |
212
|
|
|
if ( $xoopsUser->isAdmin() ) { |
213
|
|
|
$srvlinks .= "<a title=\"" |
214
|
|
|
. _EDIT |
215
|
|
|
. "\" href=\"admin/entry.php?op=mod&entryID=" |
216
|
|
|
. $variable['id'] |
217
|
|
|
. "\" target=\"_blank\"><img src=\"" |
218
|
|
|
. $pathIcon16 |
219
|
|
|
. "/edit.png\" alt=\"" |
220
|
|
|
. _MD_LEXIKON_EDITTERM |
221
|
|
|
. "\" style=\"width:16px; height:16px;\"></a> <a TITLE=\"" |
222
|
|
|
. _DELETE |
223
|
|
|
. "\" href=\"admin/entry.php?op=del&entryID=" |
224
|
|
|
. $variable['id'] |
225
|
|
|
. "\" target=\"_self\"><img src=\"" |
226
|
|
|
. $pathIcon16 |
227
|
|
|
. "/delete.png\" alt=\"" |
228
|
|
|
. _MD_LEXIKON_DELTERM |
229
|
|
|
. "\" style=\"width:16px; height:16px;\"></a> "; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
if ( $entrytype != "1" ) { |
233
|
|
|
$srvlinks .= "<a title=\"" |
234
|
|
|
. _MD_LEXIKON_PRINTTERM |
235
|
|
|
. "\" href=\"print.php?entryID=" |
236
|
|
|
. $variable['id'] |
237
|
|
|
. "\" target=\"_blank\"><img src=\"" |
238
|
|
|
. $pathIcon16 |
239
|
|
|
. "/printer.png\" alt=\"" |
240
|
|
|
. _MD_LEXIKON_PRINTTERM |
241
|
|
|
. "\" style=\"width:16px; height:16px;\"></a> <a TITLE=\"" |
242
|
|
|
. _MD_LEXIKON_SENDTOFRIEND |
243
|
|
|
. "\" href=\"mailto:?subject=" |
244
|
|
|
. sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"]) |
245
|
|
|
. "&body=" |
246
|
|
|
. sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename']) |
247
|
|
|
. ": " |
248
|
|
|
. XOOPS_URL |
249
|
|
|
. "/modules/".$xoopsModule->dirname() |
250
|
|
|
. "/entry.php?entryID=" |
251
|
|
|
. $variable['id'] |
252
|
|
|
. " \" target=\"_blank\"><img src=\"" |
253
|
|
|
. $pathIcon16 |
254
|
|
|
. "/mail_replay.png\" alt=\"" |
255
|
|
|
. _MD_LEXIKON_SENDTOFRIEND |
256
|
|
|
. "\" style=\"width:16px; height:16px;\"></a> "; |
257
|
|
|
if (( $xoopsModuleConfig['com_rule'] != 0 ) && (!empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser))) { |
258
|
|
|
$srvlinks .= "<a title=\"" |
259
|
|
|
. _COMMENTS |
260
|
|
|
. "?\" href=\"comment_new.php?com_itemid=" |
261
|
|
|
. $variable['id'] |
262
|
|
|
. "\" target=\"_parent\"><img src=\"images/comments.gif\" alt=\"" |
263
|
|
|
. _COMMENTS |
264
|
|
|
. "?\" style=\"width:16px; height:16px;\"></a> "; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
return $srvlinks; |
269
|
|
|
} |
270
|
|
|
// entry footer |
271
|
|
View Code Duplication |
function lx_serviceLinksnew ( $variable ) { |
|
|
|
|
272
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig, $myts; |
|
|
|
|
273
|
|
|
$srvlinks2 = "<a title=\"" |
274
|
|
|
. _MD_LEXIKON_PRINTTERM |
275
|
|
|
. "\" href=\"print.php?entryID=" |
276
|
|
|
. $variable['id'] |
277
|
|
|
. "\" target=\"_blank\"><img src=\"images/print.gif\" alt=\"" |
278
|
|
|
. _MD_LEXIKON_PRINTTERM |
279
|
|
|
. "\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> " |
280
|
|
|
. _MD_LEXIKON_PRINTTERM2 |
281
|
|
|
. "</a> <a title=\"" |
282
|
|
|
. _MD_LEXIKON_SENDTOFRIEND |
283
|
|
|
. "\" href=\"mailto:?subject=" |
284
|
|
|
. sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"]) |
285
|
|
|
. "&body=" |
286
|
|
|
. sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename']) |
287
|
|
|
. ": ".$variable['term'] |
288
|
|
|
. " " |
289
|
|
|
. XOOPS_URL |
290
|
|
|
. "/modules/" |
291
|
|
|
. $xoopsModule->dirname() |
292
|
|
|
. "/entry.php?entryID=" |
293
|
|
|
. $variable['id'] |
294
|
|
|
. " \" target=\"_blank\"><img src=\"images/friend.gif\" alt=\"" |
295
|
|
|
. _MD_LEXIKON_SENDTOFRIEND |
296
|
|
|
. "\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> " |
297
|
|
|
. _MD_LEXIKON_SENDTOFRIEND2 |
298
|
|
|
. "</a> "; |
299
|
|
|
|
300
|
|
|
return $srvlinks2; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
View Code Duplication |
function lx_showSearchForm() { |
|
|
|
|
304
|
|
|
global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
|
|
|
|
305
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
306
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
307
|
|
|
|
308
|
|
|
$searchform = "<table style=\"width:100%;\">"; |
309
|
|
|
$searchform .= "<form name=\"op\" id=\"op\" action=\"search.php\" method=\"post\">"; |
310
|
|
|
$searchform .= "<tr><td style=\"text-align: right; line-height: 200%; width:150px;\">"; |
311
|
|
|
$searchform .= _MD_LEXIKON_LOOKON."</td><td style=\"width:10px;\"> </td><td style=\"text-align: left;\">"; |
312
|
|
|
$searchform .= "<select name=\"type\"><option value=\"1\">"._MD_LEXIKON_TERMS."</option><option value=\"2\">"._MD_LEXIKON_DEFINS."</option>"; |
313
|
|
|
$searchform .= "<option SELECTED value=\"3\">"._MD_LEXIKON_TERMSDEFS."</option></select></td></tr>"; |
314
|
|
|
|
315
|
|
|
if ($xoopsModuleConfig['multicats'] == 1) { |
316
|
|
|
$searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">"._MD_LEXIKON_CATEGORY."</td>"; |
317
|
|
|
$searchform .= "<td> </td><td style=\"text-align: left;\">"; |
318
|
|
|
$resultcat = $xoopsDB -> query ( "SELECT categoryID, name FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY categoryID" ); |
319
|
|
|
$searchform .= "<select name=\"categoryID\">"; |
320
|
|
|
$searchform .= "<option value=\"0\">"._MD_LEXIKON_ALLOFTHEM."</option>"; |
321
|
|
|
|
322
|
|
|
while (list( $categoryID, $name) = $xoopsDB->fetchRow($resultcat)) { |
323
|
|
|
if ($gperm_handler->checkRight('lexikon_view', intval($categoryID), $groups, $xoopsModule->getVar('mid'))) { |
324
|
|
|
$searchform .= "<option value=\"$categoryID\">$categoryID : $name</option>"; |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
$searchform .= "</select></td></tr>"; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
$searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">"; |
331
|
|
|
$searchform .= _MD_LEXIKON_TERM."</td><td> </td><td style=\"text-align: left;\">"; |
332
|
|
|
$searchform .= "<input type=\"text\" name=\"term\" class=\"searchBox\" /></td></tr><tr>"; |
333
|
|
|
$searchform .= "<td> </td><td> </td><td><input type=\"submit\" class=\"btnDefault\" value=\""._MD_LEXIKON_SEARCH."\" />"; |
334
|
|
|
$searchform .= "</td></tr></form></table>"; |
335
|
|
|
|
336
|
|
|
return $searchform; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
View Code Duplication |
function lx_getHTMLHighlight($needle, $haystack, $hlS, $hlE) { |
|
|
|
|
340
|
|
|
$parts = explode(">", $haystack); |
341
|
|
|
foreach($parts as $key=>$part) { |
342
|
|
|
$pL = ""; |
343
|
|
|
$pR = ""; |
344
|
|
|
|
345
|
|
|
if (($pos = strpos($part, "<")) === false) |
346
|
|
|
$pL = $part; |
347
|
|
|
elseif($pos > 0) { |
348
|
|
|
$pL = substr($part, 0, $pos); |
349
|
|
|
$pR = substr($part, $pos, strlen($part)); |
350
|
|
|
} |
351
|
|
|
if ($pL != "") |
352
|
|
|
$parts[$key] = preg_replace('|('.quotemeta($needle).')|iU', $hlS.'\\1'.$hlE, $pL) . $pR; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return(implode(">", $parts)); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/* ******************************************************************************* |
359
|
|
|
* Most of the following functions are modified functions from Herve's News Module |
360
|
|
|
* other functions are from AMS by Novasmart/Mithrandir |
361
|
|
|
* others from Red Mexico Soft Rmdp |
362
|
|
|
* others from Xhelp 0.78 thanks to ackbarr and eric_juden |
363
|
|
|
* ******************************************************************************* |
364
|
|
|
*/ |
365
|
|
|
|
366
|
|
|
// Create the meta keywords based on content |
367
|
|
View Code Duplication |
function lx_extract_keywords($content) { |
|
|
|
|
368
|
|
|
global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig; |
|
|
|
|
369
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php'; |
370
|
|
|
$keywords_count = $xoopsModuleConfig['metakeywordsnum']; |
371
|
|
|
$tmp=array(); |
372
|
|
|
if (isset($_SESSION['xoops_keywords_limit'])) { // Search the "Minimum keyword length" |
373
|
|
|
$limit = $_SESSION['xoops_keywords_limit']; |
374
|
|
|
} else { |
375
|
|
|
$config_handler = xoops_gethandler('config'); |
376
|
|
|
$xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
377
|
|
|
$limit=$xoopsConfigSearch['keyword_min']; |
378
|
|
|
$_SESSION['xoops_keywords_limit']=$limit; |
379
|
|
|
} |
380
|
|
|
$myts = MyTextSanitizer::getInstance(); |
381
|
|
|
$content = str_replace ("<br />", " ", $content); |
382
|
|
|
$content= $myts->undoHtmlSpecialChars($content); |
383
|
|
|
$content= strip_tags($content); |
384
|
|
|
$content=strtolower($content); |
385
|
|
|
$search_pattern=[ |
386
|
|
|
" ", |
387
|
|
|
"\t", |
388
|
|
|
"\r\n", |
389
|
|
|
"\r", |
390
|
|
|
"\n", |
391
|
|
|
",", |
392
|
|
|
".", |
393
|
|
|
"'", |
394
|
|
|
";", |
395
|
|
|
":", |
396
|
|
|
")", |
397
|
|
|
"(", |
398
|
|
|
'"', |
399
|
|
|
'?', |
400
|
|
|
'!', |
401
|
|
|
'{', |
402
|
|
|
'}', |
403
|
|
|
'[', |
404
|
|
|
']', |
405
|
|
|
'<', |
406
|
|
|
'>', |
407
|
|
|
'/', |
408
|
|
|
'+', |
409
|
|
|
'-', |
410
|
|
|
'_', |
411
|
|
|
'\\', |
412
|
|
|
'*' |
413
|
|
|
]; |
414
|
|
|
$replace_pattern=[ |
415
|
|
|
' ', |
416
|
|
|
' ', |
417
|
|
|
' ', |
418
|
|
|
' ', |
419
|
|
|
' ', |
420
|
|
|
' ', |
421
|
|
|
' ', |
422
|
|
|
' ', |
423
|
|
|
'', |
424
|
|
|
'', |
425
|
|
|
'', |
426
|
|
|
'', |
427
|
|
|
'', |
428
|
|
|
'', |
429
|
|
|
'', |
430
|
|
|
'', |
431
|
|
|
'', |
432
|
|
|
'', |
433
|
|
|
'', |
434
|
|
|
'', |
435
|
|
|
'', |
436
|
|
|
'', |
437
|
|
|
'', |
438
|
|
|
'', |
439
|
|
|
'', |
440
|
|
|
'', |
441
|
|
|
'' |
442
|
|
|
]; |
443
|
|
|
$content = str_replace($search_pattern, $replace_pattern, $content); |
444
|
|
|
$keywords=explode(' ',$content); |
445
|
|
|
switch (META_KEYWORDS_ORDER) { |
446
|
|
|
case 1: // Returns keywords in the same order that they were created in the text |
447
|
|
|
$keywords=array_unique($keywords); |
448
|
|
|
break; |
449
|
|
|
|
450
|
|
|
case 2: // the keywords order is made according to the reverse keywords frequency (so the less frequent words appear in first in the list) |
451
|
|
|
$keywords=array_count_values($keywords); |
452
|
|
|
asort($keywords); |
453
|
|
|
$keywords=array_keys($keywords); |
454
|
|
|
break; |
455
|
|
|
|
456
|
|
|
case 3: // Same as previous, the only difference is that the most frequent words will appear in first in the list |
457
|
|
|
$keywords=array_count_values($keywords); |
458
|
|
|
arsort($keywords); |
459
|
|
|
$keywords=array_keys($keywords); |
460
|
|
|
break; |
461
|
|
|
} |
462
|
|
|
foreach($keywords as $keyword) { |
463
|
|
|
if (strlen($keyword)>=$limit && !is_numeric($keyword)) { |
464
|
|
|
$tmp[]=$keyword; |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
$tmp=array_slice($tmp,0,$keywords_count); |
468
|
|
|
if (count($tmp)>0) { |
469
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
470
|
|
|
$xoTheme->addMeta( 'meta', 'keywords', implode(',',$tmp)); |
471
|
|
|
} else { // Compatibility for old Xoops versions |
472
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', implode(',',$tmp)); |
473
|
|
|
} |
474
|
|
|
} else { |
475
|
|
|
if (!isset($config_handler) || !is_object($config_handler)) { |
476
|
|
|
$config_handler = xoops_gethandler('config'); |
477
|
|
|
} |
478
|
|
|
$xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
479
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
480
|
|
|
$xoTheme->addMeta( 'meta', 'keywords', $xoopsConfigMetaFooter['meta_keywords']); |
481
|
|
|
} else { // Compatibility for old Xoops versions |
482
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']); |
483
|
|
|
} |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
// Create meta description based on content |
488
|
|
View Code Duplication |
function lx_get_metadescription($content) { |
|
|
|
|
489
|
|
|
global $xoopsTpl, $xoTheme; |
|
|
|
|
490
|
|
|
$myts = MyTextSanitizer::getInstance(); |
491
|
|
|
$content= $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
492
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
493
|
|
|
$xoTheme->addMeta( 'meta', 'description', strip_tags($content)); |
494
|
|
|
} else { // Compatibility for old Xoops versions |
495
|
|
|
$xoopsTpl->assign('xoops_meta_description', strip_tags($content)); |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
// Create pagetitles |
500
|
|
View Code Duplication |
function lx_create_pagetitle($article='', $topic='') { |
|
|
|
|
501
|
|
|
global $xoopsModule, $xoopsTpl; |
|
|
|
|
502
|
|
|
$myts = MyTextSanitizer::getInstance(); |
503
|
|
|
$content=''; |
504
|
|
|
if (!empty($article)) $content .= strip_tags($myts->displayTarea($article)); |
505
|
|
|
if (!empty($topic)) { |
506
|
|
|
if (xoops_trim($content)!='') { |
507
|
|
|
$content .= ' - '.strip_tags($myts->displayTarea($topic)); |
508
|
|
|
} else { |
509
|
|
|
$content .= strip_tags($myts->displayTarea($topic)); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
if (is_object($xoopsModule) && xoops_trim($xoopsModule->name())!='') { |
513
|
|
|
if (xoops_trim($content)!='') { |
514
|
|
|
$content.=' - '.strip_tags($myts->displayTarea($xoopsModule->name())); |
515
|
|
|
} else { |
516
|
|
|
$content.=strip_tags($myts->displayTarea($xoopsModule->name())); |
517
|
|
|
} |
518
|
|
|
} |
519
|
|
|
if ($content!='') { |
520
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $content); |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
// clear descriptions |
525
|
|
View Code Duplication |
function lx_html2text($document) { |
|
|
|
|
526
|
|
|
// PHP Manual:: function preg_replace $document should contain an HTML document. |
527
|
|
|
// This will remove HTML tags, javascript sections and white space. It will also |
528
|
|
|
// convert some common HTML entities to their text equivalent. |
529
|
|
|
|
530
|
|
|
$search = ["'<script[^>]*?>.*?</script>'si", // Strip out javascript |
531
|
|
|
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
532
|
|
|
"'([\r\n])[\s]+'", // Strip out white space |
533
|
|
|
"'&(quot|#34);'i", // Replace HTML entities |
534
|
|
|
"'&(amp|#38);'i", |
535
|
|
|
"'&(lt|#60);'i", |
536
|
|
|
"'&(gt|#62);'i", |
537
|
|
|
"'&(nbsp|#160);'i", |
538
|
|
|
"'&(iexcl|#161);'i", |
539
|
|
|
"'&(cent|#162);'i", |
540
|
|
|
"'&(pound|#163);'i", |
541
|
|
|
"'&(copy|#169);'i"]; |
542
|
|
|
|
543
|
|
|
$replace = ["", |
544
|
|
|
"", |
545
|
|
|
"\\1", |
546
|
|
|
"\"", |
547
|
|
|
"&", |
548
|
|
|
"<", |
549
|
|
|
">", |
550
|
|
|
" ", |
551
|
|
|
chr(161), |
552
|
|
|
chr(162), |
553
|
|
|
chr(163), |
554
|
|
|
chr(169)]; |
555
|
|
|
|
556
|
|
|
$text = preg_replace($search, $replace, $document); |
557
|
|
|
|
558
|
|
|
$text = preg_replace_callback("&#(\d+)&", create_function('$matches',"return chr(\$matches[1]);"),$text); |
|
|
|
|
559
|
|
|
|
560
|
|
|
return $text; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
//Retrieve moduleoptions equivalent to $Xoopsmoduleconfig |
564
|
|
View Code Duplication |
function lx_getmoduleoption($option, $repmodule='lexikon') { |
|
|
|
|
565
|
|
|
global $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
566
|
|
|
static $tbloptions= []; |
567
|
|
|
if (is_array($tbloptions) && array_key_exists($option,$tbloptions)) { |
568
|
|
|
return $tbloptions[$option]; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
$retval=false; |
572
|
|
|
if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
573
|
|
|
if (isset($xoopsModuleConfig[$option])) { |
574
|
|
|
$retval= $xoopsModuleConfig[$option]; |
575
|
|
|
} |
576
|
|
|
} else { |
577
|
|
|
$module_handler = xoops_gethandler('module'); |
578
|
|
|
$module = $module_handler->getByDirname($repmodule); |
579
|
|
|
$config_handler = xoops_gethandler('config'); |
580
|
|
|
if ($module) { |
581
|
|
|
$moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
582
|
|
|
if (isset($moduleConfig[$option])) { |
583
|
|
|
$retval= $moduleConfig[$option]; |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
} |
587
|
|
|
$tbloptions[$option]=$retval; |
588
|
|
|
|
589
|
|
|
return $retval; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Is Xoops 2.3.x ? |
594
|
|
|
* |
595
|
|
|
* @return boolean need to say it ? |
596
|
|
|
*/ |
597
|
|
View Code Duplication |
function lx_isX23() |
|
|
|
|
598
|
|
|
{ |
599
|
|
|
$x23 = false; |
600
|
|
|
$xv = str_replace('XOOPS ','',XOOPS_VERSION); |
601
|
|
|
if(substr($xv,2,1) >= '3') { |
602
|
|
|
$x23 = true; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
return $x23; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* Retreive an editor according to the module's option "form_options" |
610
|
|
|
* following function is from News modified by trabis |
611
|
|
|
*/ |
612
|
|
View Code Duplication |
function &lx_getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental='') |
|
|
|
|
613
|
|
|
{ |
614
|
|
|
$editor_option = strtolower(lx_getmoduleoption('form_options')); |
615
|
|
|
$editor = false; |
616
|
|
|
$editor_configs = []; |
617
|
|
|
$editor_configs['name'] = $name; |
618
|
|
|
$editor_configs['value'] = $value; |
619
|
|
|
$editor_configs['rows'] = 35; |
620
|
|
|
$editor_configs['cols'] = 60; |
621
|
|
|
$editor_configs['width'] = '100%'; |
622
|
|
|
$editor_configs['height'] = '350px'; |
623
|
|
|
$editor_configs['editor'] = $editor_option; |
624
|
|
|
|
625
|
|
|
if(lx_isX23()) { |
626
|
|
|
$editor = new XoopsFormEditor($caption, $name, $editor_configs); |
627
|
|
|
|
628
|
|
|
return $editor; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
// Only for Xoops 2.0.x |
632
|
|
|
switch($editor_option) { |
633
|
|
|
case 'fckeditor': |
634
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
635
|
|
|
require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'); |
636
|
|
|
$editor = new XoopsFormFckeditor($caption, $name, $value); |
637
|
|
|
} |
638
|
|
|
break; |
639
|
|
|
|
640
|
|
|
case 'htmlarea': |
641
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
642
|
|
|
require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
643
|
|
|
$editor = new XoopsFormHtmlarea($caption, $name, $value); |
644
|
|
|
} |
645
|
|
|
break; |
646
|
|
|
|
647
|
|
|
case 'dhtmltextarea': |
648
|
|
|
case 'dhtml': |
649
|
|
|
$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
650
|
|
|
break; |
651
|
|
|
|
652
|
|
|
case 'textarea': |
653
|
|
|
$editor = new XoopsFormTextArea($caption, $name, $value); |
654
|
|
|
break; |
655
|
|
|
|
656
|
|
|
case 'tinyeditor': |
657
|
|
|
case 'tinymce': |
658
|
|
|
if ( is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
659
|
|
|
require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
660
|
|
|
$editor = new XoopsFormTinyeditorTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'400px')); |
661
|
|
|
} |
662
|
|
|
break; |
663
|
|
|
|
664
|
|
|
case 'koivi': |
665
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
666
|
|
|
require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
667
|
|
|
$editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
668
|
|
|
} |
669
|
|
|
break; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
return $editor; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* linkterms: assign module header |
677
|
|
|
* |
678
|
|
|
* tooltips (c) dhtmlgoodies |
679
|
|
|
*/ |
680
|
|
View Code Duplication |
function lx_module_header() { |
|
|
|
|
681
|
|
|
global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig, $lexikon_module_header; |
|
|
|
|
682
|
|
|
if(isset($xoTheme) && is_object($xoTheme)) { |
683
|
|
|
$xoTheme -> addStylesheet( 'modules/lexikon/assets/css/style.css' ); |
684
|
|
|
if ($xoopsModuleConfig['linkterms'] == 3) { |
685
|
|
|
$xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' ); |
686
|
|
|
$xoTheme->addScript( '/modules/lexikon/assets/js/tooltipscript2.js', array( 'type' => 'text/javascript' ) ); |
687
|
|
|
} |
688
|
|
|
if ($xoopsModuleConfig['linkterms'] == 4) { |
689
|
|
|
$xoTheme->addScript( '/modules/lexikon/assets/js/popup.js', array( 'type' => 'text/javascript' ) ); |
690
|
|
|
} |
691
|
|
|
if ($xoopsModuleConfig['linkterms'] == 5) { |
692
|
|
|
$xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' ); |
693
|
|
|
$xoTheme->addScript( '/modules/lexikon/assets/js/balloontooltip.js', array( 'type' => 'text/javascript' ) ); |
694
|
|
|
} |
695
|
|
|
if ($xoopsModuleConfig['linkterms'] == 6) { |
696
|
|
|
$xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' ); |
697
|
|
|
$xoTheme->addScript( '/modules/lexikon/assets/js/shadowtooltip.js', array( 'type' => 'text/javascript' ) ); |
698
|
|
|
} |
699
|
|
|
} else { |
700
|
|
|
$lexikon_url = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname'); |
701
|
|
|
if ($xoopsModuleConfig['linkterms'] == 3) { |
702
|
|
|
$lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" /> |
703
|
|
|
<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" /> |
704
|
|
|
<script src="'.$lexikon_url.'/assets/js/tooltipscript2.js" type="text/javascript"></script>'; |
705
|
|
|
} |
706
|
|
|
if ($xoopsModuleConfig['linkterms'] == 4) { |
707
|
|
|
$lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" /> |
708
|
|
|
<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" /> |
709
|
|
|
<script src="'.$lexikon_url.'/assets/js/popup.js" type="text/javascript"></script>'; |
710
|
|
|
} |
711
|
|
|
if ($xoopsModuleConfig['linkterms'] == 5) { |
712
|
|
|
$lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" /> |
713
|
|
|
<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" /> |
714
|
|
|
<script src="'.$lexikon_url.'/assets/js/balloontooltip.js" type="text/javascript"></script>'; |
715
|
|
|
} |
716
|
|
|
if ($xoopsModuleConfig['linkterms'] == 6) { |
717
|
|
|
$lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" /> |
718
|
|
|
<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" /> |
719
|
|
|
<script src="'.$lexikon_url.'/assets/js/shadowtooltip.js" type="text/javascript"></script>'; |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* Validate userid |
726
|
|
|
*/ |
727
|
|
View Code Duplication |
function lx_val_user_data($uids) { |
|
|
|
|
728
|
|
|
global $xoopsDB,$xoopsUser, $xoopsUserIsAdmin; |
|
|
|
|
729
|
|
|
|
730
|
|
|
if ($uids<=0) { |
731
|
|
|
return false; |
732
|
|
|
} |
733
|
|
|
if ($uids > 0) { |
734
|
|
|
$member_handler = xoops_gethandler('member'); |
735
|
|
|
$user = $member_handler->getUser($uids); |
736
|
|
|
if (!is_object($user)) { |
737
|
|
|
return false; |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
$result = $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("users")." WHERE uid='$uids'"); |
741
|
|
|
if ($xoopsDB->getRowsNum($result)<=0) { |
742
|
|
|
return false; |
743
|
|
|
} |
744
|
|
|
$row = $xoopsDB->fetchArray($result); |
745
|
|
|
|
746
|
|
|
return $row; |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
// Get all terms published by an author |
750
|
|
|
function lx_AuthorProfile($uid ) { |
|
|
|
|
751
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
752
|
|
|
global $authortermstotal, $xoopsTpl, $xoopsDB, $xoopsUser, $xoopsModuleConfig; |
|
|
|
|
753
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
|
|
|
754
|
|
|
//permissions |
755
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
756
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
757
|
|
|
$module_handler = xoops_gethandler('module'); |
758
|
|
|
$module = $module_handler->getByDirname('lexikon'); |
759
|
|
|
$module_id = $module->getVar('mid'); |
760
|
|
|
$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id); |
761
|
|
|
$catids = implode(',', $allowed_cats); |
762
|
|
|
$catperms = " AND categoryID IN ($catids) "; |
763
|
|
|
|
764
|
|
|
$start = isset( $_GET['start'] ) ? intval( $_GET['start'] ) : 0; |
765
|
|
|
$limit = $xoopsModuleConfig['indexperpage']; |
766
|
|
|
|
767
|
|
|
$sql = $xoopsDB -> query( "SELECT * |
768
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
769
|
|
|
WHERE uid='".intval($uid)."' AND offline = '0' AND submit = '0' AND request = '0' ".$catperms." |
770
|
|
|
ORDER BY term |
771
|
|
|
LIMIT $start,$limit"); |
772
|
|
|
|
773
|
|
View Code Duplication |
while ($row=$xoopsDB->fetchArray($sql)) { |
|
|
|
|
774
|
|
|
$xoopsTpl->append('entries', array('id'=>$row['entryID'],'name'=>$row['term'],'date'=>date($xoopsModuleConfig['dateformat'], $row['datesub']),'counter'=>$row['counter'])); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
$navstring = ''; |
778
|
|
|
$navstring .= "uid=".$uid."&start"; |
779
|
|
|
$pagenav = new XoopsPageNav( $authortermstotal , $xoopsModuleConfig['indexperpage'], $start, $navstring); |
780
|
|
|
$authortermsarr['navbar'] = '<span style="text-align:right;">' . $pagenav -> renderNav(6) . '</span>'; |
|
|
|
|
781
|
|
|
$xoopsTpl -> assign( 'authortermsarr', $authortermsarr); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
// Returns the author's IDs for authorslist |
785
|
|
View Code Duplication |
function lx_getAuthors($limit=0, $start=0) { |
|
|
|
|
786
|
|
|
global $xoopsDB ; |
|
|
|
|
787
|
|
|
|
788
|
|
|
$ret = []; |
789
|
|
|
$sql = 'SELECT distinct(uid) as uid FROM '.$xoopsDB->prefix('lxentries').' WHERE offline = 0 '; |
790
|
|
|
$sql .= " ORDER BY uid"; |
791
|
|
|
$result = $xoopsDB->query($sql); |
792
|
|
|
while ( $myrow = $xoopsDB->fetchArray($result) ) { |
793
|
|
|
$ret[] = $myrow['uid']; |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
return $ret; |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
// link to userprofile |
800
|
|
View Code Duplication |
function lx_getLinkedProfileFromId($userid) { |
|
|
|
|
801
|
|
|
global $uid, $xoopsModule; |
|
|
|
|
802
|
|
|
$userid = intval($uid); |
803
|
|
|
if ($userid > 0) { |
804
|
|
|
$member_handler = xoops_gethandler('member'); |
805
|
|
|
$user = $member_handler->getUser($userid); |
806
|
|
|
if (is_object($user)) { |
807
|
|
|
$linkeduser = '<a title="'._MD_LEXIKON_AUTHORPROFILETEXT.'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->dirname().'/profile.php?uid='.$uid.'">'. $user->getVar('uname').'</a>'; |
808
|
|
|
//$linkeduser = XoopsUserUtility::getUnameFromId ( $uid ); |
|
|
|
|
809
|
|
|
//$linkeduser .= '<div style=\'position:relative; right: 4px; top: 2px;\'><a title="'._MD_LEXIKON_AUTHORPROFILETEXT.'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->dirname().'/profile.php?uid='.$uid.'">'._MD_LEXIKON_AUTHORPROFILETEXT.'</a></div>'; |
|
|
|
|
810
|
|
|
return $linkeduser; |
811
|
|
|
} |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
return $GLOBALS['xoopsConfig']['anonymous']; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
// functionset to assign terms with accentuated or umlaut initials to the adequate initial |
818
|
|
View Code Duplication |
function lx_removeAccents($string) { |
|
|
|
|
819
|
|
|
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) |
|
|
|
|
820
|
|
|
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) |
821
|
|
|
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) |
822
|
|
|
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) |
823
|
|
|
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) |
824
|
|
|
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) |
825
|
|
|
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) |
826
|
|
|
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) |
827
|
|
|
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) |
828
|
|
|
.chr(252).chr(253).chr(255); |
829
|
|
|
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; |
830
|
|
|
if (lx_seemsUtf8($string)) { |
831
|
|
|
$invalid_latin_chars = [ |
832
|
|
|
chr(197).chr(146) => 'OE', |
833
|
|
|
chr(197).chr(147) => 'oe', |
834
|
|
|
chr(197).chr(160) => 'S', |
835
|
|
|
chr(197).chr(189) => 'Z', |
836
|
|
|
chr(197).chr(161) => 's', |
837
|
|
|
chr(197).chr(190) => 'z', |
838
|
|
|
chr(226).chr(130).chr(172) => 'E' |
839
|
|
|
]; |
840
|
|
|
$string = utf8_decode(strtr($string, $invalid_latin_chars)); |
841
|
|
|
} |
842
|
|
|
$string = strtr($string, $chars['in'], $chars['out']); |
843
|
|
|
$double_chars['in'] = [ |
|
|
|
|
844
|
|
|
chr(140), |
845
|
|
|
chr(156), |
846
|
|
|
chr(198), |
847
|
|
|
chr(208), |
848
|
|
|
chr(222), |
849
|
|
|
chr(223), |
850
|
|
|
chr(230), |
851
|
|
|
chr(240), |
852
|
|
|
chr(254) |
853
|
|
|
]; |
854
|
|
|
$double_chars['out'] = [ |
855
|
|
|
'OE', |
856
|
|
|
'oe', |
857
|
|
|
'AE', |
858
|
|
|
'DH', |
859
|
|
|
'TH', |
860
|
|
|
'ss', |
861
|
|
|
'ae', |
862
|
|
|
'dh', |
863
|
|
|
'th' |
864
|
|
|
]; |
865
|
|
|
$string = str_replace($double_chars['in'], $double_chars['out'], $string); |
866
|
|
|
|
867
|
|
|
return $string; |
868
|
|
|
} |
869
|
|
|
|
870
|
|
|
function lx_seemsUtf8($Str) { # by bmorel at ssi dot fr |
871
|
|
|
for ($i=0; $i<strlen($Str); $i++) { |
872
|
|
View Code Duplication |
if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb |
|
|
|
|
873
|
|
|
elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb |
874
|
|
|
elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb |
875
|
|
|
elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb |
876
|
|
|
elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb |
877
|
|
|
elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b |
878
|
|
|
else return false; # Does not match any model |
879
|
|
View Code Duplication |
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
|
|
|
880
|
|
|
if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) |
881
|
|
|
return false; |
882
|
|
|
} |
883
|
|
|
} |
884
|
|
|
|
885
|
|
|
return true; |
886
|
|
|
} |
887
|
|
|
|
888
|
|
View Code Duplication |
function lx_sanitizeFieldName($field) { |
|
|
|
|
889
|
|
|
$field = lx_removeAccents($field); |
890
|
|
|
$field = strtolower($field); |
891
|
|
|
$field = preg_replace('/&.+?;/', '', $field); // kill entities |
892
|
|
|
$field = preg_replace('/[^a-z0-9 _-]/', '', $field); |
893
|
|
|
$field = preg_replace('/\s+/', ' ', $field); |
894
|
|
|
$field = str_replace(' ', '-', $field); |
895
|
|
|
$field = preg_replace('|-+|', '-', $field); |
896
|
|
|
$field = trim($field, '-'); |
897
|
|
|
|
898
|
|
|
return $field; |
899
|
|
|
} |
900
|
|
|
|
901
|
|
|
// Verify that a term does not exist for submissions and requests (both user frontend and admin backend) |
902
|
|
View Code Duplication |
function lx_TermExists($term, $table) { |
|
|
|
|
903
|
|
|
global $xoopsDB; |
|
|
|
|
904
|
|
|
$sql = sprintf('SELECT COUNT(*) FROM %s WHERE term = %s', $table, $xoopsDB->quoteString(addslashes($term))); |
905
|
|
|
$result = $xoopsDB->query($sql); |
906
|
|
|
list($count) = $xoopsDB->fetchRow($result); |
907
|
|
|
|
908
|
|
|
return($count); |
909
|
|
|
} |
910
|
|
|
|
911
|
|
|
// Static method to get author data block authors - from AMS |
912
|
|
|
function lexikon_block_getAuthors($limit = 5, $sort = "count", $name = 'uname', $compute_method = "average") { |
913
|
|
|
$limit = intval($limit); |
914
|
|
|
if ($name != "uname") |
915
|
|
|
$name = "name"; //making sure that there is not invalid information in field value |
916
|
|
|
$ret = []; |
917
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
918
|
|
|
if ($sort == "count") { |
919
|
|
|
$sql = "SELECT u.".$name." AS name, u.uid , count( n.entryID ) AS count |
920
|
|
|
FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n |
921
|
|
|
WHERE u.uid = n.uid |
922
|
|
|
AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0 |
923
|
|
|
GROUP BY u.uid ORDER BY count DESC"; |
924
|
|
View Code Duplication |
} elseif ($sort == "read") { |
|
|
|
|
925
|
|
|
if ($compute_method == "average") { |
926
|
|
|
$compute = "sum( n.counter ) / count( n.entryID )"; |
927
|
|
|
} else { |
928
|
|
|
$compute = "sum( n.counter )"; |
929
|
|
|
} |
930
|
|
|
$sql = "SELECT u.".$name." AS name, u.uid , $compute AS count |
931
|
|
|
FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n |
932
|
|
|
WHERE u.uid = n.uid |
933
|
|
|
AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0 |
934
|
|
|
GROUP BY u.uid ORDER BY count DESC"; |
935
|
|
|
} |
936
|
|
|
if (!$result = $db->query($sql, $limit)) |
|
|
|
|
937
|
|
|
return false; |
938
|
|
|
|
939
|
|
View Code Duplication |
while ($row = $db->fetchArray($result)) { |
|
|
|
|
940
|
|
|
if ($name == "name" && $row['name'] == '') |
941
|
|
|
$row['name'] = XoopsUser::getUnameFromId($row['uid']); |
942
|
|
|
$row['count'] = round($row['count'], 0); |
943
|
|
|
$ret[] = $row; |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
return $ret; |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
/** |
950
|
|
|
* close all unclosed xhtml tags *Test* |
951
|
|
|
* |
952
|
|
|
* @param string $html |
953
|
|
|
* @return string |
954
|
|
|
* @author Milian Wolff <mail -at- milianw.de> |
955
|
|
|
*/ |
956
|
|
View Code Duplication |
function lx_closetags2($html){ |
|
|
|
|
957
|
|
|
// put all opened tags into an array |
958
|
|
|
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result); |
959
|
|
|
$openedtags=$result[1]; |
960
|
|
|
|
961
|
|
|
// put all closed tags into an array |
962
|
|
|
preg_match_all("#</([a-z]+)>#iU",$html,$result); |
963
|
|
|
$closedtags=$result[1]; |
964
|
|
|
$len_opened = count($openedtags); |
965
|
|
|
// all tags are closed |
966
|
|
|
if(count($closedtags) == $len_opened){ |
967
|
|
|
return $html; |
968
|
|
|
} |
969
|
|
|
|
970
|
|
|
$openedtags = array_reverse($openedtags); |
971
|
|
|
// close tags |
972
|
|
|
for($i=0;$i < $len_opened;$i++) { |
973
|
|
|
if (!in_array($openedtags[$i],$closedtags)){ |
974
|
|
|
$html .= '</'.$openedtags[$i].'>'; |
975
|
|
|
} else { |
976
|
|
|
unset($closedtags[array_search($openedtags[$i],$closedtags)]); |
977
|
|
|
} |
978
|
|
|
} |
979
|
|
|
|
980
|
|
|
return $html; |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
985
|
|
|
* <amos dot robinson at gmail dot com> |
986
|
|
|
*/ |
987
|
|
View Code Duplication |
function lx_close_tags($string) { |
|
|
|
|
988
|
|
|
// match opened tags |
989
|
|
|
if(preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
990
|
|
|
$start_tags = $start_tags[1]; |
991
|
|
|
// match closed tags |
992
|
|
|
if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
993
|
|
|
$complete_tags = array(); |
994
|
|
|
$end_tags = $end_tags[1]; |
995
|
|
|
|
996
|
|
|
foreach($start_tags as $key => $val) { |
997
|
|
|
$posb = array_search($val, $end_tags); |
998
|
|
|
if(is_integer($posb)) { |
999
|
|
|
unset($end_tags[$posb]); |
1000
|
|
|
} else { |
1001
|
|
|
$complete_tags[] = $val; |
1002
|
|
|
} |
1003
|
|
|
} |
1004
|
|
|
} else { |
1005
|
|
|
$complete_tags = $start_tags; |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
$complete_tags = array_reverse($complete_tags); |
1009
|
|
|
for($i = 0; $i < count($complete_tags); $i++) { |
|
|
|
|
1010
|
|
|
$string .= '</' . $complete_tags[$i] . '>'; |
1011
|
|
|
} |
1012
|
|
|
} |
1013
|
|
|
|
1014
|
|
|
return $string; |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
|
/** |
1018
|
|
|
* Smarty plugin |
1019
|
|
|
* @package Smarty |
1020
|
|
|
* @subpackage plugins |
1021
|
|
|
*/ |
1022
|
|
|
/** |
1023
|
|
|
* Smarty truncate_tagsafe modifier plugin |
1024
|
|
|
* |
1025
|
|
|
* Type: modifier<br> |
1026
|
|
|
* Name: truncate_tagsafe<br> |
1027
|
|
|
* Purpose: Truncate a string to a certain length if necessary, |
1028
|
|
|
* optionally splitting in the middle of a word, and |
1029
|
|
|
* appending the $etc string or inserting $etc into the middle. |
1030
|
|
|
* Makes sure no tags are left half-open or half-closed (e.g. "Banana in a <a...") |
1031
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
1032
|
|
|
* <amos dot robinson at gmail dot com> |
1033
|
|
|
* used in Block entries_scrolling.php |
1034
|
|
|
*/ |
1035
|
|
View Code Duplication |
function lx_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) { |
|
|
|
|
1036
|
|
|
if ($length == 0) return ''; |
1037
|
|
|
if (strlen($string) > $length) { |
1038
|
|
|
$length -= strlen($etc); |
1039
|
|
|
if (!$break_words) { |
1040
|
|
|
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); |
1041
|
|
|
$string = preg_replace('/<[^>]*$/', '', $string); |
1042
|
|
|
$string = lx_close_tags($string); |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
|
return $string . $etc; |
1046
|
|
|
} else { |
1047
|
|
|
return $string; |
1048
|
|
|
} |
1049
|
|
|
} |
1050
|
|
|
|
1051
|
|
|
function lexikon_summary() { |
1052
|
|
|
global $xoopsDB; |
|
|
|
|
1053
|
|
|
|
1054
|
|
|
$summary = []; |
1055
|
|
|
|
1056
|
|
|
$result01 = $xoopsDB -> query( "SELECT COUNT(*) |
1057
|
|
|
FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " ); |
1058
|
|
|
list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 ); |
1059
|
|
|
|
1060
|
|
|
$result02 = $xoopsDB -> query( "SELECT COUNT(*) |
1061
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
1062
|
|
|
WHERE submit = 0" ); |
1063
|
|
|
list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 ); |
1064
|
|
|
|
1065
|
|
|
$result03 = $xoopsDB -> query( "SELECT COUNT(*) |
1066
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
1067
|
|
|
WHERE submit = '1' AND request = '0' " ); |
1068
|
|
|
list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 ); |
1069
|
|
|
|
1070
|
|
|
$result04 = $xoopsDB -> query( "SELECT COUNT(*) |
1071
|
|
|
FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
1072
|
|
|
WHERE submit = '1' AND request = '1' " ); |
1073
|
|
|
list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 ); |
1074
|
|
|
|
1075
|
|
|
// Recuperer les valeurs dans la base de donnees |
1076
|
|
|
|
1077
|
|
|
$summary['publishedEntries'] = $totalpublished ? $totalpublished : '0'; |
1078
|
|
|
$summary['availableCategories'] = $totalcategories ? $totalcategories : '0'; |
1079
|
|
|
$summary['submittedEntries'] = $totalsubmitted ? $totalsubmitted : '0'; |
1080
|
|
|
$summary['requestedEntries'] = $totalrequested ? $totalrequested : '0'; |
1081
|
|
|
|
1082
|
|
|
//print_r($summary); |
1083
|
|
|
return $summary; |
1084
|
|
|
|
1085
|
|
|
} // end function |
1086
|
|
|
|
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.