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