1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// $Id: functions.php,v 1.5 2004/09/02 17:04:08 hthouzard Exp $ |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
6
|
|
|
// <http://www.xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
28
|
|
|
die('XOOPS root path not defined'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns a module's option |
33
|
|
|
* |
34
|
|
|
* Return's a module's option (for the news module) |
35
|
|
|
* |
36
|
|
|
* @package News |
37
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
38
|
|
|
* @copyright (c) Instant Zero |
39
|
|
|
* @param string $option module option's name |
40
|
|
|
*/ |
41
|
|
|
function news_getmoduleoption($option, $repmodule='news') |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
global $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
44
|
|
|
static $tbloptions= Array(); |
45
|
|
|
if(is_array($tbloptions) && array_key_exists($option,$tbloptions)) { |
46
|
|
|
return $tbloptions[$option]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$retval = false; |
50
|
|
|
if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
51
|
|
|
if(isset($xoopsModuleConfig[$option])) { |
52
|
|
|
$retval= $xoopsModuleConfig[$option]; |
53
|
|
|
} |
54
|
|
|
} else { |
55
|
|
|
$module_handler =& xoops_gethandler('module'); |
56
|
|
|
$module =& $module_handler->getByDirname($repmodule); |
57
|
|
|
$config_handler =& xoops_gethandler('config'); |
58
|
|
|
if ($module) { |
59
|
|
|
$moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
60
|
|
|
if(isset($moduleConfig[$option])) { |
61
|
|
|
$retval= $moduleConfig[$option]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
$tbloptions[$option]=$retval; |
66
|
|
|
return $retval; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Updates rating data in item table for a given item |
72
|
|
|
* |
73
|
|
|
* @package News |
74
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
75
|
|
|
* @copyright (c) Instant Zero |
76
|
|
|
*/ |
77
|
|
|
function news_updaterating($storyid) |
78
|
|
|
{ |
79
|
|
|
global $xoopsDB; |
|
|
|
|
80
|
|
|
$query = 'SELECT rating FROM '.$xoopsDB->prefix('stories_votedata').' WHERE storyid = '.$storyid; |
81
|
|
|
$voteresult = $xoopsDB->query($query); |
82
|
|
|
$votesDB = $xoopsDB->getRowsNum($voteresult); |
83
|
|
|
$totalrating = 0; |
84
|
|
|
while(list($rating)=$xoopsDB->fetchRow($voteresult)){ |
85
|
|
|
$totalrating += $rating; |
86
|
|
|
} |
87
|
|
|
$finalrating = $totalrating/$votesDB; |
88
|
|
|
$finalrating = number_format($finalrating, 4); |
89
|
|
|
$sql = sprintf("UPDATE %s SET rating = %u, votes = %u WHERE storyid = %u", $xoopsDB->prefix('stories'), $finalrating, $votesDB, $storyid); |
90
|
|
|
$xoopsDB->queryF($sql); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Internal function for permissions |
97
|
|
|
* |
98
|
|
|
* Returns a list of all the permitted topics Ids for the current user |
99
|
|
|
* |
100
|
|
|
* @return array $topics Permitted topics Ids |
101
|
|
|
* |
102
|
|
|
* @package News |
103
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
104
|
|
|
* @copyright (c) Instant Zero |
105
|
|
|
*/ |
106
|
|
|
function news_MygetItemIds($permtype='news_view') |
107
|
|
|
{ |
108
|
|
|
global $xoopsUser; |
|
|
|
|
109
|
|
|
static $tblperms = array(); |
110
|
|
|
if(is_array($tblperms) && array_key_exists($permtype,$tblperms)) { |
111
|
|
|
return $tblperms[$permtype]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$module_handler =& xoops_gethandler('module'); |
115
|
|
|
$newsModule =& $module_handler->getByDirname('news'); |
116
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
117
|
|
|
$gperm_handler =& xoops_gethandler('groupperm'); |
118
|
|
|
$topics = $gperm_handler->getItemIds($permtype, $groups, $newsModule->getVar('mid')); |
119
|
|
|
$tblperms[$permtype] = $topics; |
120
|
|
|
return $topics; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function news_html2text($document) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
// PHP Manual:: function preg_replace |
126
|
|
|
// $document should contain an HTML document. |
127
|
|
|
// This will remove HTML tags, javascript sections |
128
|
|
|
// and white space. It will also convert some |
129
|
|
|
// common HTML entities to their text equivalent. |
130
|
|
|
|
131
|
|
|
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript |
132
|
|
|
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
133
|
|
|
"'([\r\n])[\s]+'", // Strip out white space |
134
|
|
|
"'&(quot|#34);'i", // Replace HTML entities |
135
|
|
|
"'&(amp|#38);'i", |
136
|
|
|
"'&(lt|#60);'i", |
137
|
|
|
"'&(gt|#62);'i", |
138
|
|
|
"'&(nbsp|#160);'i", |
139
|
|
|
"'&(iexcl|#161);'i", |
140
|
|
|
"'&(cent|#162);'i", |
141
|
|
|
"'&(pound|#163);'i", |
142
|
|
|
"'&(copy|#169);'i", |
143
|
|
|
"'&#(\d+);'e"); // evaluate as php |
144
|
|
|
|
145
|
|
|
$replace = array ("", |
146
|
|
|
"", |
147
|
|
|
"\\1", |
148
|
|
|
"\"", |
149
|
|
|
"&", |
150
|
|
|
"<", |
151
|
|
|
">", |
152
|
|
|
" ", |
153
|
|
|
chr(161), |
154
|
|
|
chr(162), |
155
|
|
|
chr(163), |
156
|
|
|
chr(169), |
157
|
|
|
"chr(\\1)"); |
158
|
|
|
|
159
|
|
|
$text = preg_replace($search, $replace, $document); |
160
|
|
|
return $text; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Retreive an editor according to the module's option "form_options" |
166
|
|
|
*/ |
167
|
|
|
function &news_getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental='') |
168
|
|
|
{ |
169
|
|
|
$editor = false; |
170
|
|
|
$x22=false; |
171
|
|
|
$xv=str_replace('XOOPS ','',XOOPS_VERSION); |
172
|
|
|
if(substr($xv,2,1)=='2') { |
173
|
|
|
$x22=true; |
174
|
|
|
} |
175
|
|
|
$editor_configs=array(); |
176
|
|
|
$editor_configs['name'] =$name; |
177
|
|
|
$editor_configs['value'] = $value; |
178
|
|
|
$editor_configs['rows'] = 35; |
179
|
|
|
$editor_configs['cols'] = 60; |
180
|
|
|
$editor_configs['width'] = '100%'; |
181
|
|
|
$editor_configs['height'] = '400px'; |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
switch(strtolower(news_getmoduleoption('form_options'))) { |
185
|
|
View Code Duplication |
case 'spaw': |
|
|
|
|
186
|
|
|
if(!$x22) { |
187
|
|
|
if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/spaw/formspaw.php')) { |
188
|
|
|
include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/spaw/formspaw.php'); |
189
|
|
|
$editor = new XoopsFormSpaw($caption, $name, $value); |
190
|
|
|
} |
191
|
|
|
} else { |
192
|
|
|
$editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
193
|
|
|
} |
194
|
|
|
break; |
195
|
|
|
|
196
|
|
View Code Duplication |
case 'fck': |
|
|
|
|
197
|
|
|
if(!$x22) { |
198
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/FCKeditor/formfckeditor.php')) { |
199
|
|
|
include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/FCKeditor/formfckeditor.php'); |
200
|
|
|
$editor = new XoopsFormFckeditor($caption, $name, $value); |
201
|
|
|
} |
202
|
|
|
} else { |
203
|
|
|
$editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
204
|
|
|
} |
205
|
|
|
break; |
206
|
|
|
|
207
|
|
View Code Duplication |
case 'htmlarea': |
|
|
|
|
208
|
|
|
if(!$x22) { |
209
|
|
|
// if ( is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/htmlarea/formhtmlarea.php')) { |
210
|
|
|
// include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/htmlarea/formhtmlarea.php'); |
211
|
|
|
// $editor = new XoopsFormHtmlarea($caption, $name, $value); |
212
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/xinha/formxinha.php')) { |
213
|
|
|
include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/xinha/formxinha.php'); |
214
|
|
|
$editor = new XoopsFormXinha($caption, $name, $value); |
215
|
|
|
} |
216
|
|
|
} else { |
217
|
|
|
$editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
218
|
|
|
} |
219
|
|
|
break; |
220
|
|
|
|
221
|
|
|
case 'dhtml': |
222
|
|
|
if(!$x22) { |
223
|
|
|
$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
224
|
|
|
} else { |
225
|
|
|
$editor = new XoopsFormEditor($caption, 'dhtmltextarea', $editor_configs); |
226
|
|
|
} |
227
|
|
|
break; |
228
|
|
|
|
229
|
|
|
case 'textarea': |
230
|
|
|
$editor = new XoopsFormTextArea($caption, $name, $value); |
231
|
|
|
break; |
232
|
|
|
|
233
|
|
|
case 'tinyeditor': |
234
|
|
|
// if ( is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
235
|
|
|
// include_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
236
|
|
|
// $editor = new XoopsFormTinyeditorTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'400px')); |
237
|
|
|
if ( is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinymce/formtinymce.php')) { |
238
|
|
|
include_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinymce/formtinymce.php'; |
239
|
|
|
$editor = new XoopsFormTinymce(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'400px')); |
240
|
|
|
} |
241
|
|
|
break; |
242
|
|
|
|
243
|
|
View Code Duplication |
case 'koivi': |
|
|
|
|
244
|
|
|
if(!$x22) { |
245
|
|
|
if ( is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formwysiwygtextarea.php')) { |
246
|
|
|
include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formwysiwygtextarea.php'); |
247
|
|
|
$editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '450px', ''); |
248
|
|
|
} |
249
|
|
|
} else { |
250
|
|
|
$editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
251
|
|
|
} |
252
|
|
|
break; |
253
|
|
|
} |
254
|
|
|
return $editor; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Internal function |
259
|
|
|
* |
260
|
|
|
* @package News |
261
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
262
|
|
|
* @copyright (c) Instant Zero |
263
|
|
|
*/ |
264
|
|
|
function DublinQuotes($text) { |
|
|
|
|
265
|
|
|
return str_replace("\"", ' ',$text); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Creates all the meta datas : |
271
|
|
|
* - For Mozilla/Netscape and Opera the site navigation's bar |
272
|
|
|
* - The Dublin's Core Metadata |
273
|
|
|
* - The link for Firefox 2 micro summaries |
274
|
|
|
* - The meta keywords |
275
|
|
|
* - The meta description |
276
|
|
|
* |
277
|
|
|
* @package News |
278
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
279
|
|
|
* @copyright (c) Instant Zero |
280
|
|
|
*/ |
281
|
|
|
function news_CreateMetaDatas($story = null) |
282
|
|
|
{ |
283
|
|
|
global $xoopsConfig, $xoTheme, $xoopsTpl; |
|
|
|
|
284
|
|
|
$content = ''; |
285
|
|
|
$myts = MyTextSanitizer::getInstance(); |
286
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newstopic.php'; |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Firefox and Opera Navigation's Bar |
290
|
|
|
*/ |
291
|
|
|
if(news_getmoduleoption('sitenavbar')) { |
292
|
|
|
$content .= sprintf("<link rel=\"Home\" title=\"%s\" href=\"%s/\" />\n",$xoopsConfig['sitename'],XOOPS_URL); |
293
|
|
|
$content .= sprintf("<link rel=\"Contents\" href=\"%s\" />\n",XOOPS_URL.'/modules/news/index.php'); |
294
|
|
|
$content .= sprintf("<link rel=\"Search\" href=\"%s\" />\n",XOOPS_URL.'/search.php'); |
295
|
|
|
$content .= sprintf("<link rel=\"Glossary\" href=\"%s\" />\n",XOOPS_URL.'/modules/news/archive.php'); |
296
|
|
|
$content .= sprintf("<link rel=\"%s\" href=\"%s\" />\n",$myts->htmlSpecialChars(_NW_SUBMITNEWS),XOOPS_URL.'/modules/news/submit.php'); |
297
|
|
|
$content .= sprintf("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"%s\" href=\"%s/\" />\n",$xoopsConfig['sitename'],XOOPS_URL.'/backend.php'); |
298
|
|
|
|
299
|
|
|
// Create chapters |
300
|
|
|
include_once XOOPS_ROOT_PATH.'/class/tree.php'; |
301
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newstopic.php'; |
302
|
|
|
$xt = new NewsTopic(); |
303
|
|
|
$allTopics = $xt->getAllTopics(news_getmoduleoption('restrictindex')); |
304
|
|
|
$topic_tree = new XoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); |
305
|
|
|
$topics_arr = $topic_tree->getAllChild(0); |
306
|
|
|
foreach ($topics_arr as $onetopic) { |
307
|
|
|
$content .= sprintf("<link rel=\"Chapter\" title=\"%s\" href=\"%s\" />\n",$onetopic->topic_title(),XOOPS_URL.'/modules/news/index.php?storytopic='.$onetopic->topic_id()); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Meta Keywords and Description |
313
|
|
|
* If you have set this module's option to 'yes' and if the information was entered, then they are rendered in the page else they are computed |
314
|
|
|
*/ |
315
|
|
|
$meta_keywords = ''; |
316
|
|
|
if(isset($story) && is_object($story)) { |
317
|
|
|
if(xoops_trim($story->keywords()) != '') { |
318
|
|
|
$meta_keywords = $story->keywords(); |
319
|
|
|
} else { |
320
|
|
|
$meta_keywords = news_createmeta_keywords($story->hometext().' '.$story->bodytext()); |
321
|
|
|
} |
322
|
|
|
if(xoops_trim($story->description())!='') { |
323
|
|
|
$meta_description = $story->description(); |
324
|
|
|
} else { |
325
|
|
|
$meta_description = strip_tags($story->title()); |
326
|
|
|
} |
327
|
|
|
if(isset($xoTheme) && is_object($xoTheme)) { |
328
|
|
|
$xoTheme->addMeta( 'meta', 'keywords', $meta_keywords); |
329
|
|
|
$xoTheme->addMeta( 'meta', 'description', $meta_description); |
330
|
|
|
} elseif(isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
331
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', $meta_keywords); |
332
|
|
|
$xoopsTpl->assign('xoops_meta_description', $meta_description); |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Dublin Core's meta datas |
338
|
|
|
*/ |
339
|
|
|
if(news_getmoduleoption('dublincore') && isset($story) && is_object($story)) { |
340
|
|
|
$config_handler =& xoops_gethandler('config'); |
341
|
|
|
$xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
342
|
|
|
$content .= '<meta name="DC.Title" content="'.DublinQuotes($story->title())."\" />\n"; |
343
|
|
|
$content .= '<meta name="DC.Creator" content="'.DublinQuotes($story->uname())."\" />\n"; |
344
|
|
|
$content .= '<meta name="DC.Subject" content="'.DublinQuotes($meta_keywords)."\" />\n"; |
345
|
|
|
$content .= '<meta name="DC.Description" content="'.DublinQuotes($story->title())."\" />\n"; |
346
|
|
|
$content .= '<meta name="DC.Publisher" content="'.DublinQuotes($xoopsConfig['sitename'])."\" />\n"; |
347
|
|
|
$content .= '<meta name="DC.Date.created" scheme="W3CDTF" content="'.date('Y-m-d',$story->created)."\" />\n"; |
348
|
|
|
$content .= '<meta name="DC.Date.issued" scheme="W3CDTF" content="'.date('Y-m-d',$story->published)."\" />\n"; |
349
|
|
|
$content .= '<meta name="DC.Identifier" content="'.XOOPS_URL.'/modules/news/article.php?storyid='.$story->storyid()."\" />\n"; |
350
|
|
|
$content .= '<meta name="DC.Source" content="'.XOOPS_URL."\" />\n"; |
351
|
|
|
$content .= '<meta name="DC.Language" content="'._LANGCODE."\" />\n"; |
352
|
|
|
$content .= '<meta name="DC.Relation.isReferencedBy" content="'.XOOPS_URL.'/modules/news/index.php?storytopic='.$story->topicid()."\" />\n"; |
353
|
|
|
if(isset($xoopsConfigMetaFooter['meta_copyright'])) { |
354
|
|
|
$content .= '<meta name="DC.Rights" content="'.DublinQuotes($xoopsConfigMetaFooter['meta_copyright'])."\" />\n"; |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Firefox 2 micro summaries |
360
|
|
|
*/ |
361
|
|
|
if(news_getmoduleoption('firefox_microsummaries')) { |
362
|
|
|
$content .= sprintf("<link rel=\"microsummary\" href=\"%s\" />\n",XOOPS_URL.'/modules/news/micro_summary.php'); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
if(isset($xoopsTpl) && is_object($xoopsTpl)) { |
366
|
|
|
$xoopsTpl->assign('xoops_module_header', $content); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
|
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Create the meta keywords based on the content |
374
|
|
|
* |
375
|
|
|
* @package News |
376
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
377
|
|
|
* @copyright (c) Instant Zero |
378
|
|
|
*/ |
379
|
|
|
function news_createmeta_keywords($content) |
|
|
|
|
380
|
|
|
{ |
381
|
|
|
include XOOPS_ROOT_PATH.'/modules/news/config.php'; |
382
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/news/class/blacklist.php'; |
383
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/news/class/registryfile.php'; |
384
|
|
|
|
385
|
|
|
if(!$cfg['meta_keywords_auto_generate']) { |
|
|
|
|
386
|
|
|
return ''; |
387
|
|
|
} |
388
|
|
|
$registry = new news_registryfile('news_metagen_options.txt'); |
389
|
|
|
$tcontent = ''; |
|
|
|
|
390
|
|
|
$tcontent = $registry->getfile(); |
391
|
|
|
if(xoops_trim($tcontent) != '') { |
392
|
|
|
list($keywordscount, $keywordsorder) = explode(',',$tcontent); |
393
|
|
|
} else { |
394
|
|
|
$keywordscount = $cfg['meta_keywords_count']; |
395
|
|
|
$keywordsorder = $cfg['meta_keywords_order']; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$tmp = array(); |
399
|
|
|
// Search for the "Minimum keyword length" |
400
|
|
|
if(isset($_SESSION['news_keywords_limit'])) { |
401
|
|
|
$limit = $_SESSION['news_keywords_limit']; |
402
|
|
|
} else { |
403
|
|
|
$config_handler =& xoops_gethandler('config'); |
404
|
|
|
$xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
405
|
|
|
$limit = $xoopsConfigSearch['keyword_min']; |
406
|
|
|
$_SESSION['news_keywords_limit'] = $limit; |
407
|
|
|
} |
408
|
|
|
$myts = MyTextSanitizer::getInstance(); |
409
|
|
|
$content = str_replace ("<br />", " ", $content); |
410
|
|
|
$content= $myts->undoHtmlSpecialChars($content); |
411
|
|
|
$content= strip_tags($content); |
412
|
|
|
$content=strtolower($content); |
413
|
|
|
$search_pattern=array(" ","\t","\r\n","\r","\n",",",".","'",";",":",")","(",'"','?','!','{','}','[',']','<','>','/','+','-','_','\\','*'); |
414
|
|
|
$replace_pattern=array(' ',' ',' ',' ',' ',' ',' ',' ','','','','','','','','','','','','','','','','','','',''); |
415
|
|
|
$content = str_replace($search_pattern, $replace_pattern, $content); |
416
|
|
|
$keywords = explode(' ',$content); |
417
|
|
|
switch($keywordsorder) { |
418
|
|
|
case 0: // Ordre d'apparition dans le texte |
419
|
|
|
$keywords = array_unique($keywords); |
420
|
|
|
break; |
421
|
|
|
case 1: // Ordre de fr�quence des mots |
422
|
|
|
$keywords = array_count_values($keywords); |
423
|
|
|
asort($keywords); |
424
|
|
|
$keywords = array_keys($keywords); |
425
|
|
|
break; |
426
|
|
|
case 2: // Ordre inverse de la fr�quence des mots |
427
|
|
|
$keywords = array_count_values($keywords); |
428
|
|
|
arsort($keywords); |
429
|
|
|
$keywords = array_keys($keywords); |
430
|
|
|
break; |
431
|
|
|
} |
432
|
|
|
// Remove black listed words |
433
|
|
|
$metablack = new news_blacklist(); |
434
|
|
|
$words = $metablack->getAllKeywords(); |
|
|
|
|
435
|
|
|
$keywords = $metablack->remove_blacklisted($keywords); |
436
|
|
|
|
437
|
|
|
foreach($keywords as $keyword) { |
438
|
|
|
if(strlen($keyword)>=$limit && !is_numeric($keyword)) { |
439
|
|
|
$tmp[] = $keyword; |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
$tmp = array_slice($tmp, 0, $keywordscount); |
443
|
|
|
if(count($tmp) > 0) { |
444
|
|
|
return implode(',',$tmp); |
445
|
|
|
} else { |
446
|
|
|
if(!isset($config_handler) || !is_object($config_handler)) { |
447
|
|
|
$config_handler =& xoops_gethandler('config'); |
448
|
|
|
} |
449
|
|
|
$xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
450
|
|
|
if(isset($xoopsConfigMetaFooter['meta_keywords'])) { |
451
|
|
|
return $xoopsConfigMetaFooter['meta_keywords']; |
452
|
|
|
} else { |
453
|
|
|
return ''; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Remove module's cache |
461
|
|
|
* |
462
|
|
|
* @package News |
463
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
464
|
|
|
* @copyright (c) Instant Zero |
465
|
|
|
*/ |
466
|
|
|
function news_updateCache() { |
467
|
|
|
global $xoopsModule; |
|
|
|
|
468
|
|
|
$folder = $xoopsModule->getVar('dirname'); |
469
|
|
|
$tpllist = array(); |
|
|
|
|
470
|
|
|
include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php'; |
471
|
|
|
include_once XOOPS_ROOT_PATH.'/class/template.php'; |
472
|
|
|
$tplfile_handler =& xoops_gethandler('tplfile'); |
473
|
|
|
$tpllist = $tplfile_handler->find(null, null, null, $folder); |
474
|
|
|
$xoopsTpl = new XoopsTpl(); |
|
|
|
|
475
|
|
|
xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
476
|
|
|
|
477
|
|
|
// Remove cache for each page. |
478
|
|
|
foreach ($tpllist as $onetemplate) { |
479
|
|
|
if( $onetemplate->getVar('tpl_type') == 'module' ) { |
480
|
|
|
// Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
481
|
|
|
$files_del = array(); |
|
|
|
|
482
|
|
|
$files_del = glob(XOOPS_CACHE_PATH.'/*'.$onetemplate->getVar('tpl_file').'*'); |
483
|
|
|
if(count($files_del) >0) { |
484
|
|
|
foreach($files_del as $one_file) { |
485
|
|
|
unlink($one_file); |
486
|
|
|
} |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* Verify that a mysql table exists |
494
|
|
|
* |
495
|
|
|
* @package News |
496
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
497
|
|
|
* @copyright (c) Instant Zero |
498
|
|
|
*/ |
499
|
|
|
function news_TableExists($tablename) |
500
|
|
|
{ |
501
|
|
|
global $xoopsDB; |
|
|
|
|
502
|
|
|
$result=$xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
503
|
|
|
return($xoopsDB->getRowsNum($result) > 0); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Verify that a field exists inside a mysql table |
508
|
|
|
* |
509
|
|
|
* @package News |
510
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
511
|
|
|
* @copyright (c) Instant Zero |
512
|
|
|
*/ |
513
|
|
|
function news_FieldExists($fieldname,$table) |
514
|
|
|
{ |
515
|
|
|
global $xoopsDB; |
|
|
|
|
516
|
|
|
$result=$xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
517
|
|
|
return($xoopsDB->getRowsNum($result) > 0); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Add a field to a mysql table |
522
|
|
|
* |
523
|
|
|
* @package News |
524
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
525
|
|
|
* @copyright (c) Instant Zero |
526
|
|
|
*/ |
527
|
|
|
function news_AddField($field, $table) |
|
|
|
|
528
|
|
|
{ |
529
|
|
|
global $xoopsDB; |
|
|
|
|
530
|
|
|
$result=$xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;"); |
531
|
|
|
return $result; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Verify that the current user is a member of the Admin group |
536
|
|
|
*/ |
537
|
|
|
function news_is_admin_group() |
538
|
|
|
{ |
539
|
|
|
global $xoopsUser, $xoopsModule; |
|
|
|
|
540
|
|
|
if(is_object($xoopsUser)) { |
541
|
|
|
if(in_array('1',$xoopsUser->getGroups())) { |
542
|
|
|
return true; |
543
|
|
|
} else { |
544
|
|
|
if($xoopsUser->isAdmin($xoopsModule->mid())) { |
545
|
|
|
return true; |
546
|
|
|
} else { |
547
|
|
|
return false; |
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
} else { |
551
|
|
|
return false; |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Verify if the current "user" is a bot or not |
558
|
|
|
* |
559
|
|
|
* If you have a problem with this function, insert the folowing code just before the line if(isset($_SESSION['news_cache_bot'])) { : |
560
|
|
|
* return false; |
561
|
|
|
* |
562
|
|
|
* @package News |
563
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
564
|
|
|
* @copyright (c) Instant Zero |
565
|
|
|
*/ |
566
|
|
|
function news_isbot() |
|
|
|
|
567
|
|
|
{ |
568
|
|
|
if(isset($_SESSION['news_cache_bot'])) { |
569
|
|
|
return $_SESSION['news_cache_bot']; |
570
|
|
|
} else { |
571
|
|
|
// Add here every bot you know separated by a pipe | (not matter with the upper or lower cases) |
572
|
|
|
// If you want to see the result for yourself, add your navigator's user agent at the end (mozilla for example) |
573
|
|
|
$botlist='AbachoBOT|Arachnoidea|ASPSeek|Atomz|cosmos|crawl25-public.alexa.com|CrawlerBoy Pinpoint.com|Crawler|DeepIndex|EchO!|exabot|Excalibur Internet Spider|FAST-WebCrawler|Fluffy the spider|GAIS Robot/1.0B2|GaisLab data gatherer|Google|Googlebot-Image|googlebot|Gulliver|ia_archiver|Infoseek|Links2Go|Lycos_Spider_(modspider)|Lycos_Spider_(T-Rex)|MantraAgent|Mata Hari|Mercator|MicrosoftPrototypeCrawler|[email protected]|MSNBOT|NEC Research Agent|NetMechanic|Nokia-WAPToolkit|nttdirectory_robot|Openfind|Oracle Ultra Search|PicoSearch|Pompos|Scooter|Slider_Search_v1-de|Slurp|Slurp.so|SlySearch|Spider|Spinne|SurferF3|Surfnomore Spider|suzuran|teomaagent1|TurnitinBot|Ultraseek|VoilaBot|vspider|W3C_Validator|Web Link Validator|WebTrends|WebZIP|whatUseek_winona|WISEbot|Xenu Link Sleuth|ZyBorg'; |
574
|
|
|
$botlist=strtoupper($botlist); |
575
|
|
|
$currentagent=strtoupper(xoops_getenv('HTTP_USER_AGENT')); |
576
|
|
|
$retval=false; |
577
|
|
|
$botarray=explode('|',$botlist); |
578
|
|
|
foreach($botarray as $onebot) { |
579
|
|
|
if(strstr($currentagent,$onebot)) { |
580
|
|
|
$retval=true; |
581
|
|
|
break; |
582
|
|
|
} |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
$_SESSION['news_cache_bot']=$retval; |
586
|
|
|
return $retval; |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Create an infotip |
592
|
|
|
* |
593
|
|
|
* @package News |
594
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
595
|
|
|
* @copyright (c) Instant Zero |
596
|
|
|
*/ |
597
|
|
|
function news_make_infotips($text) |
|
|
|
|
598
|
|
|
{ |
599
|
|
|
$infotips = news_getmoduleoption('infotips'); |
600
|
|
|
if($infotips>0) { |
601
|
|
|
$myts = MyTextSanitizer::getInstance(); |
602
|
|
|
return $myts->htmlSpecialChars(xoops_substr(strip_tags($text),0,$infotips)); |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
?> |
|
|
|
|
606
|
|
|
|
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.