1
|
|
|
<?php |
2
|
|
|
// |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// This program is free software; you can redistribute it and/or modify // |
5
|
|
|
// it under the terms of the GNU General Public License as published by // |
6
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
7
|
|
|
// (at your option) any later version. // |
8
|
|
|
// // |
9
|
|
|
// You may not change or alter any portion of this comment or credits // |
10
|
|
|
// of supporting developers from this source code or any supporting // |
11
|
|
|
// source code which is considered copyrighted (c) material of the // |
12
|
|
|
// original comment or credit authors. // |
13
|
|
|
// // |
14
|
|
|
// This program is distributed in the hope that it will be useful, // |
15
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
16
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
17
|
|
|
// GNU General Public License for more details. // |
18
|
|
|
// // |
19
|
|
|
// You should have received a copy of the GNU General Public License // |
20
|
|
|
// along with this program; if not, write to the Free Software // |
21
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
22
|
|
|
// ------------------------------------------------------------------------ // |
23
|
|
|
// Author: phppp (D.J., [email protected]) // |
24
|
|
|
// URL: https://xoops.org // |
25
|
|
|
// Project: Article Project // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
use Xmf\Request; |
28
|
|
|
|
29
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$current_path = __FILE__; |
32
|
|
View Code Duplication |
if (DIRECTORY_SEPARATOR !== '/') { |
|
|
|
|
33
|
|
|
$current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
34
|
|
|
} |
35
|
|
|
$url_arr = explode('/', strstr($current_path, '/modules/')); |
36
|
|
|
$GLOBALS['moddirname'] = $url_arr[2]; |
37
|
|
|
|
38
|
|
|
if (!defined('planet_FUNCTIONS')): |
39
|
|
|
define('planet_FUNCTIONS', 1); |
40
|
|
|
|
41
|
|
|
require XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/include/vars.php'; |
42
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
43
|
|
|
require_once XOOPS_ROOT_PATH . '/Frameworks/art/functions.php'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Function to display messages |
47
|
|
|
* |
48
|
|
|
* @var mixed $messages |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
function planetDisplayMessage($message) |
52
|
|
|
{ |
53
|
|
|
return mod_message($message); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Function to parse arguments for a page according to $_SERVER['REQUEST_URI'] |
58
|
|
|
* |
59
|
|
|
* @var array $args_numeric array of numeric variable values |
60
|
|
|
* @var array $args array of indexed variables: name and value |
61
|
|
|
* @var array $args_string array of string variable values |
62
|
|
|
* |
63
|
|
|
* @return bool true on args parsed |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
|
/* known issues: |
67
|
|
|
* - "/" in a string |
68
|
|
|
* - "&" in a string |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
function planetParseArguments(&$args_numeric, &$args, &$args_string) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$args_abb = array( |
73
|
|
|
'a' => 'article', |
74
|
|
|
'b' => 'blog', |
75
|
|
|
'c' => 'category', |
76
|
|
|
'l' => 'list', |
77
|
|
|
'o' => 'sort', |
78
|
|
|
's' => 'start', |
79
|
|
|
'u' => 'uid' |
80
|
|
|
); |
81
|
|
|
$args = array(); |
82
|
|
|
$args_numeric = array(); |
83
|
|
|
$args_string = array(); |
84
|
|
|
if (preg_match("/[^\?]*\.php[\/|\?]([^\?]*)/i", Request::getUrl('REQUEST_URI', '', 'SERVER'), $matches)) { |
85
|
|
|
$vars = preg_split("/[\/|&]/", $matches[1]); |
86
|
|
|
$vars = array_map('trim', $vars); |
87
|
|
|
if (count($vars) > 0) { |
88
|
|
|
foreach ($vars as $var) { |
89
|
|
|
if (is_numeric($var)) { |
90
|
|
|
$args_numeric[] = $var; |
91
|
|
|
} elseif (false === strpos($var, '=')) { |
92
|
|
|
if (is_numeric(substr($var, 1))) { |
93
|
|
|
$args[$args_abb[strtolower($var{0})]] = (int)substr($var, 1); |
94
|
|
|
} else { |
95
|
|
|
$args_string[] = urldecode($var); |
96
|
|
|
} |
97
|
|
|
} else { |
98
|
|
|
parse_str($var, $args); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return (count($args) + count($args_numeric) + count($args_string) == 0) ? null : true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Function to parse class prefix |
109
|
|
|
* |
110
|
|
|
* @var string $class_string string to be parsed |
111
|
|
|
* @var mixed $pattern |
112
|
|
|
* @var mixed $replacement |
113
|
|
|
* |
114
|
|
|
* @return bool true on success |
115
|
|
|
*/ |
116
|
|
View Code Duplication |
function planetParseClass($class_string, $pattern = '', $replacement = '') |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
if (empty($class_string)) { |
119
|
|
|
return; |
120
|
|
|
} |
121
|
|
|
$patterns = array("/\[CLASS_PREFIX\]/"); |
122
|
|
|
$replacements = array(ucfirst(strtolower($GLOBALS['moddirname']))); |
123
|
|
|
if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
124
|
|
|
$pattern = array($pattern); |
125
|
|
|
$replacement = array($replacement); |
126
|
|
|
} |
127
|
|
|
if (is_array($pattern) && count($pattern) > 0) { |
128
|
|
|
$ii = 0; |
129
|
|
|
foreach ($pattern as $pat) { |
130
|
|
|
if (!in_array($pat, $patterns)) { |
131
|
|
|
$patterns[] = $pat; |
132
|
|
|
$replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
133
|
|
|
} |
134
|
|
|
++$ii; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
$class_string = preg_replace($patterns, $replacements, $class_string); |
138
|
|
|
eval($class_string); |
|
|
|
|
139
|
|
|
|
140
|
|
|
return true; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Function to parse function prefix |
145
|
|
|
* |
146
|
|
|
* @var string $function_string string to be parsed |
147
|
|
|
* @var mixed $pattern |
148
|
|
|
* @var mixed $replacement |
149
|
|
|
* |
150
|
|
|
* @return bool true on success |
151
|
|
|
*/ |
152
|
|
View Code Duplication |
function planetParseFunction($function_string, $pattern = '', $replacement = '') |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
if (empty($function_string)) { |
155
|
|
|
return; |
156
|
|
|
} |
157
|
|
|
$patterns = array("/\[DIRNAME\]/", "/\[VAR_PREFIX\]/"); |
158
|
|
|
$replacements = array($GLOBALS['moddirname'], $GLOBALS['VAR_PREFIX']); |
159
|
|
|
if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
160
|
|
|
$pattern = array($pattern); |
161
|
|
|
$replacement = array($replacement); |
162
|
|
|
} |
163
|
|
|
if (is_array($pattern) && count($pattern) > 0) { |
164
|
|
|
$ii = 0; |
165
|
|
|
foreach ($pattern as $pat) { |
166
|
|
|
if (!in_array($pat, $patterns)) { |
167
|
|
|
$patterns[] = $pat; |
168
|
|
|
$replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
169
|
|
|
} |
170
|
|
|
++$ii; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
$function_string = preg_replace($patterns, $replacements, $function_string); |
174
|
|
|
eval($function_string); |
|
|
|
|
175
|
|
|
|
176
|
|
|
return true; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Function to convert UNIX time to formatted time string |
181
|
|
|
* @param $time |
182
|
|
|
* @param string $format |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
function planet_formatTimestamp($time, $format = '') |
186
|
|
|
{ |
187
|
|
|
if (empty($time)) { |
188
|
|
|
return ''; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return formatTimestamp($time, $format); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Function to a list of user names associated with their user IDs |
196
|
|
|
* @param int $userid |
197
|
|
|
* @param int $usereal |
198
|
|
|
* @param bool $linked |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
|
View Code Duplication |
function &planetGetUnameFromId($userid, $usereal = 0, $linked = false) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
if (!is_array($userid)) { |
204
|
|
|
$userid = array($userid); |
205
|
|
|
} |
206
|
|
|
$users =& mod_getUnameFromIds($userid, $usereal, $linked); |
207
|
|
|
|
208
|
|
|
return $users; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Function to parse links, links are delimited by link break, URL and title of a link are delimited by space |
213
|
|
|
* |
214
|
|
|
* @var string $text raw content |
215
|
|
|
* |
216
|
|
|
* @return array associative array of link url and title |
217
|
|
|
*/ |
218
|
|
View Code Duplication |
function &planetParseLinks($text) |
|
|
|
|
219
|
|
|
{ |
220
|
|
|
$myts = MyTextSanitizer::getInstance(); |
221
|
|
|
$link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
222
|
|
|
$links = array(); |
223
|
|
|
if (count($link_array) > 0) { |
224
|
|
|
foreach ($link_array as $link) { |
225
|
|
|
@list($url, $title) = array_map('trim', preg_split('/ /', $link, 2)); |
|
|
|
|
226
|
|
|
if (empty($url)) { |
227
|
|
|
continue; |
228
|
|
|
} |
229
|
|
|
//if(empty($title)) $title = $url; |
|
|
|
|
230
|
|
|
$links[] = array('url' => $url, 'title' => $myts->htmlSpecialChars($title)); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return $links; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param $pagename |
239
|
|
|
* @return string |
240
|
|
|
*/ |
241
|
|
|
function planetGetTemplate($pagename) |
242
|
|
|
{ |
243
|
|
|
return $GLOBALS['VAR_PREFIX'] . '_' . $pagename . '.tpl'; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param int $currentoption |
248
|
|
|
*/ |
249
|
|
|
function planet_adminmenu($currentoption = -1) |
250
|
|
|
{ |
251
|
|
|
loadModuleAdminMenu($currentoption, ''); |
252
|
|
|
|
253
|
|
|
return; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Function to send a trackback |
258
|
|
|
* |
259
|
|
|
* @param $article |
260
|
|
|
* @param $comment |
261
|
|
|
* @return bool |
262
|
|
|
*/ |
263
|
|
View Code Duplication |
function planet_com_trackback(&$article, &$comment) |
|
|
|
|
264
|
|
|
{ |
265
|
|
|
$blogHandler = xoops_getModuleHandler('blog', $GLOBALS['moddirname']); |
266
|
|
|
$blog_obj = $blogHandler->get($article->getVar('blog_id')); |
267
|
|
|
if (!$pattern = $blog_obj->getVar('blog_trackback')) { |
268
|
|
|
return false; |
269
|
|
|
} |
270
|
|
|
@list($pat, $rep) = array_map('trim', preg_split("#[\s]+#", $pattern)); |
|
|
|
|
271
|
|
|
$trackback_url = preg_replace('#' . $pat . '#', $rep, $article_obj->getVar('art_link')); |
|
|
|
|
272
|
|
|
|
273
|
|
|
return planetTrackback($trackback_url, $article); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @param $trackback_url |
278
|
|
|
* @param $article |
279
|
|
|
* @return bool |
280
|
|
|
*/ |
281
|
|
View Code Duplication |
function planetTrackback($trackback_url, $article) |
|
|
|
|
282
|
|
|
{ |
283
|
|
|
global $myts, $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
284
|
|
|
|
285
|
|
|
$title = $article->getVar('art_title'); |
286
|
|
|
$excerpt = $article->getVar('art_content'); |
287
|
|
|
$blog_name = $xoopsConfig['sitename'] . '-' . $xoopsModule->getVar('name'); |
288
|
|
|
$title = xoops_utf8_encode($title); |
289
|
|
|
$excerpt = xoops_utf8_encode($excerpt); |
290
|
|
|
$blog_name = xoops_utf8_encode($blog_name); |
291
|
|
|
$charset = 'utf-8'; |
292
|
|
|
$title1 = urlencode($title); |
293
|
|
|
$excerpt1 = urlencode($excerpt); |
294
|
|
|
$name1 = urlencode($blog_name); |
295
|
|
|
$url = urlencode(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $article->getVar('art_id')); |
296
|
|
|
$query_string = "title=$title1&url=$url&blog_name=$name1&excerpt=$excerpt1&charset=$charset"; |
297
|
|
|
$trackback_url = parse_url($trackback_url); |
298
|
|
|
|
299
|
|
|
$http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?' . $trackback_url['query'] : '') . " HTTP/1.0\r\n"; |
300
|
|
|
$http_request .= 'Host: ' . $trackback_url['host'] . "\r\n"; |
301
|
|
|
$http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . $charset . "\r\n"; |
302
|
|
|
$http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n"; |
303
|
|
|
$http_request .= 'User-Agent: XOOPS Blogs/' . XOOPS_VERSION; |
304
|
|
|
$http_request .= "\r\n\r\n"; |
305
|
|
|
$http_request .= $query_string; |
306
|
|
|
if ('' == $trackback_url['port']) { |
307
|
|
|
$trackback_url['port'] = 80; |
308
|
|
|
} |
309
|
|
|
$fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4); |
310
|
|
|
@fwrite($fs, $http_request); |
|
|
|
|
311
|
|
|
if ($xoopsModuleConfig['do_debug']) { |
312
|
|
|
$debug_file = XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '_trackback.log'; |
313
|
|
|
$fr = "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"; |
314
|
|
|
$fr .= "CHARSET:$charset\n"; |
315
|
|
|
$fr .= "NAME:$blog_name\n"; |
316
|
|
|
$fr .= 'TITLE:' . $title . "\n"; |
317
|
|
|
$fr .= "EXCERPT:$excerpt\n\n"; |
318
|
|
|
while (!@feof($fs)) { |
319
|
|
|
$fr .= @fgets($fs, 4096); |
320
|
|
|
} |
321
|
|
|
$fr .= "\n\n"; |
322
|
|
|
|
323
|
|
|
if ($fp = fopen($debug_file, 'a')) { |
324
|
|
|
fwrite($fp, $fr); |
325
|
|
|
fclose($fp); |
326
|
|
|
} else { |
|
|
|
|
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
@fclose($fs); |
|
|
|
|
330
|
|
|
|
331
|
|
|
return true; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Function to ping servers |
336
|
|
|
* @param $server |
337
|
|
|
* @param $id |
338
|
|
|
*/ |
339
|
|
View Code Duplication |
function planetGetPing($server, $id) |
|
|
|
|
340
|
|
|
{ |
341
|
|
|
if (is_array($server)) { |
342
|
|
|
foreach ($server as $serv) { |
343
|
|
|
planetGetPing($serv, $id); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/class-IXR.php'; |
347
|
|
|
|
348
|
|
|
// using a timeout of 3 seconds should be enough to cover slow servers |
349
|
|
|
$client = new IXR_Client($server, false); |
350
|
|
|
$client->timeout = 3; |
351
|
|
|
$client->useragent .= ' -- XOOPS Article/' . XOOPS_VERSION; |
352
|
|
|
|
353
|
|
|
// when set to true, this outputs debug messages by itself |
354
|
|
|
$client->debug = false; |
355
|
|
|
|
356
|
|
|
$blogname = xoops_utf8_encode($GLOBALS['xoopsModule']->getVar('name')); |
357
|
|
|
$home = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/'; |
358
|
|
|
$rss2_url = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php' . URL_DELIMITER . 'rss2.0/' . $id; |
359
|
|
|
|
360
|
|
|
if (!$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url)) { // then try a normal ping |
361
|
|
|
$client->query('weblogUpdates.ping', $blogname, $home); |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Function to respond to a trackback |
367
|
|
|
* @param int $error |
368
|
|
|
* @param string $error_message |
369
|
|
|
*/ |
370
|
|
View Code Duplication |
function planetRespondToTrackback($error = 0, $error_message = '') |
|
|
|
|
371
|
|
|
{ |
372
|
|
|
$charset = 'utf-8'; |
373
|
|
|
$error_message = xoops_utf8_encode($error_message); |
374
|
|
|
header('Content-Type: text/xml; charset="' . $charset . '"'); |
375
|
|
|
if ($error) { |
376
|
|
|
echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
377
|
|
|
echo "<response>\n"; |
378
|
|
|
echo "<error>1</error>\n"; |
379
|
|
|
echo "<message>$error_message</message>\n"; |
380
|
|
|
echo '</response>'; |
381
|
|
|
die(); |
382
|
|
|
} else { |
383
|
|
|
echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
384
|
|
|
echo "<response>\n"; |
385
|
|
|
echo "<error>0</error>\n"; |
386
|
|
|
echo '</response>'; |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Function to set a cookie with module-specified name |
392
|
|
|
* |
393
|
|
|
* using customized serialization method |
394
|
|
|
* @param $name |
395
|
|
|
* @param string $string |
396
|
|
|
* @param int $expire |
397
|
|
|
*/ |
398
|
|
View Code Duplication |
function planetSetCookie($name, $string = '', $expire = 0) |
|
|
|
|
399
|
|
|
{ |
400
|
|
|
if (is_array($string)) { |
401
|
|
|
$value = array(); |
402
|
|
|
foreach ($string as $key => $val) { |
403
|
|
|
$value[] = $key . '|' . $val; |
404
|
|
|
} |
405
|
|
|
$string = implode(',', $value); |
406
|
|
|
} |
407
|
|
|
setcookie($GLOBALS['VAR_PREFIX'] . $name, $string, (int)$expire, '/'); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @param $name |
412
|
|
|
* @param bool $isArray |
413
|
|
|
* @return array|null |
414
|
|
|
*/ |
415
|
|
View Code Duplication |
function planetGetCookie($name, $isArray = false) |
|
|
|
|
416
|
|
|
{ |
417
|
|
|
$value = isset($_COOKIE[$GLOBALS['VAR_PREFIX'] . $name]) ? $_COOKIE[$GLOBALS['VAR_PREFIX'] . $name] : null; |
418
|
|
|
if ($isArray) { |
419
|
|
|
$_value = $value ? explode(',', $value) : array(); |
420
|
|
|
$value = array(); |
421
|
|
|
if (count($_value) > 0) { |
422
|
|
|
foreach ($_value as $string) { |
423
|
|
|
$key = substr($string, 0, strpos($string, '|')); |
424
|
|
|
$val = substr($string, strpos($string, '|') + 1); |
425
|
|
|
$value[$key] = $val; |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
unset($_value); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
return $value; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Function to filter text |
436
|
|
|
* |
437
|
|
|
* @param $document |
438
|
|
|
* @return string filtered text |
439
|
|
|
*/ |
440
|
|
|
function &planetHtml2text(&$document) |
441
|
|
|
{ |
442
|
|
|
$document = strip_tags($document); |
443
|
|
|
|
444
|
|
|
return $document; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
// Adapted from PMA_getIp() [phpmyadmin project] |
448
|
|
|
/** |
449
|
|
|
* @param bool $asString |
450
|
|
|
* @return mixed |
451
|
|
|
*/ |
452
|
|
|
function planetGetIP($asString = false) |
453
|
|
|
{ |
454
|
|
|
return mod_getIP($asString); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* @param $url |
459
|
|
|
* @return bool|mixed|string |
460
|
|
|
*/ |
461
|
|
|
function planetGetRemoteContent($url) |
462
|
|
|
{ |
463
|
|
|
if ($data = planet_fetch_snoopy($url)) { |
464
|
|
|
return $data; |
465
|
|
|
} |
466
|
|
|
if ($data = planet_fetch_CURL($url)) { |
467
|
|
|
return $data; |
468
|
|
|
} |
469
|
|
|
if ($data = planet_fetch_fopen($url)) { |
470
|
|
|
return $data; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
return false; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @param $url |
478
|
|
|
* @return string |
479
|
|
|
*/ |
480
|
|
View Code Duplication |
function planet_fetch_snoopy($url) |
|
|
|
|
481
|
|
|
{ |
482
|
|
|
require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; |
483
|
|
|
$snoopy = new Snoopy; |
484
|
|
|
$data = ''; |
485
|
|
|
if (@$snoopy->fetch($url)) { |
486
|
|
|
$data = is_array($snoopy->results) ? implode("\n", $snoopy->results) : $snoopy->results; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
return $data; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* @param $url |
494
|
|
|
* @return bool|mixed |
495
|
|
|
*/ |
496
|
|
View Code Duplication |
function planet_fetch_CURL($url) |
|
|
|
|
497
|
|
|
{ |
498
|
|
|
if (!function_exists('curl_init')) { |
499
|
|
|
return false; |
500
|
|
|
} |
501
|
|
|
$ch = curl_init(); // initialize curl handle |
502
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
503
|
|
|
curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
504
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
505
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable |
506
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
507
|
|
|
$data = curl_exec($ch); // run the whole process |
508
|
|
|
curl_close($ch); |
509
|
|
|
|
510
|
|
|
return $data; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* @param $url |
515
|
|
|
* @return bool|string |
516
|
|
|
*/ |
517
|
|
View Code Duplication |
function planet_fetch_fopen($url) |
|
|
|
|
518
|
|
|
{ |
519
|
|
|
if (!$fp = @fopen($url, 'r')) { |
520
|
|
|
return false; |
521
|
|
|
} |
522
|
|
|
$data = ''; |
523
|
|
|
while (!feof($fp)) { |
524
|
|
|
$data .= fgets($fp, 1024); |
525
|
|
|
} |
526
|
|
|
fclose($fp); |
527
|
|
|
|
528
|
|
|
return $data; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* @param $haystack |
533
|
|
|
* @param $needle |
534
|
|
|
* @param int $offset |
535
|
|
|
* @return bool|int |
536
|
|
|
*/ |
537
|
|
View Code Duplication |
function planetStrrPos($haystack, $needle, $offset = 0) |
|
|
|
|
538
|
|
|
{ |
539
|
|
|
if (substr(PHP_VERSION, 0, 1) == 5) { |
540
|
|
|
return strrpos($haystack, $needle, $offset); |
541
|
|
|
} |
542
|
|
|
$index = strpos(strrev($haystack), strrev($needle)); |
543
|
|
|
if ($index === false) { |
544
|
|
|
return false; |
545
|
|
|
} |
546
|
|
|
$index = strlen($haystack) - strlen($needle) - $index; |
547
|
|
|
|
548
|
|
|
return $index; |
549
|
|
|
} |
550
|
|
|
endif; |
551
|
|
|
|
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.