@@ -18,6 +18,9 @@ discard block |
||
| 18 | 18 | protected $root; |
| 19 | 19 | protected $ignored; |
| 20 | 20 | |
| 21 | + /** |
|
| 22 | + * @param string $folder |
|
| 23 | + */ |
|
| 21 | 24 | function __construct($file, $folder, $ignored=null) { |
| 22 | 25 | $this->zip = new ZipArchive(); |
| 23 | 26 | |
@@ -39,6 +42,9 @@ discard block |
||
| 39 | 42 | $this->zip->close(); |
| 40 | 43 | } |
| 41 | 44 | |
| 45 | + /** |
|
| 46 | + * @param string $folder |
|
| 47 | + */ |
|
| 42 | 48 | function zip($folder, $parent=null) { |
| 43 | 49 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 50 | $zip_path = "$parent$folder"; |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** This file is part of KCFinder project. The class are taken from |
| 4 | - * http://www.php.net/manual/en/function.ziparchive-addemptydir.php |
|
| 5 | - * |
|
| 6 | - * @desc Directory to ZIP file archivator |
|
| 7 | - * @package KCFinder |
|
| 8 | - * @version 2.54 |
|
| 9 | - * @author Pavel Tzonkov <[email protected]> |
|
| 10 | - * @copyright 2010-2014 KCFinder Project |
|
| 11 | - * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 |
|
| 12 | - * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 |
|
| 13 | - * @link http://kcfinder.sunhater.com |
|
| 14 | - */ |
|
| 4 | + * http://www.php.net/manual/en/function.ziparchive-addemptydir.php |
|
| 5 | + * |
|
| 6 | + * @desc Directory to ZIP file archivator |
|
| 7 | + * @package KCFinder |
|
| 8 | + * @version 2.54 |
|
| 9 | + * @author Pavel Tzonkov <[email protected]> |
|
| 10 | + * @copyright 2010-2014 KCFinder Project |
|
| 11 | + * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 |
|
| 12 | + * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 |
|
| 13 | + * @link http://kcfinder.sunhater.com |
|
| 14 | + */ |
|
| 15 | 15 | |
| 16 | 16 | class zipFolder { |
| 17 | 17 | protected $zip; |
@@ -13,12 +13,12 @@ discard block |
||
| 13 | 13 | * @link http://kcfinder.sunhater.com |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -class zipFolder { |
|
| 16 | +class zipFolder{ |
|
| 17 | 17 | protected $zip; |
| 18 | 18 | protected $root; |
| 19 | 19 | protected $ignored; |
| 20 | 20 | |
| 21 | - function __construct($file, $folder, $ignored=null) { |
|
| 21 | + function __construct($file, $folder, $ignored = null){ |
|
| 22 | 22 | $this->zip = new ZipArchive(); |
| 23 | 23 | |
| 24 | 24 | $this->ignored = is_array($ignored) |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $this->zip->close(); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - function zip($folder, $parent=null) { |
|
| 42 | + function zip($folder, $parent = null){ |
|
| 43 | 43 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 44 | $zip_path = "$parent$folder"; |
| 45 | 45 | $this->zip->addEmptyDir($zip_path); |
@@ -13,20 +13,23 @@ discard block |
||
| 13 | 13 | * @link http://kcfinder.sunhater.com |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -class zipFolder { |
|
| 16 | +class zipFolder |
|
| 17 | +{ |
|
| 17 | 18 | protected $zip; |
| 18 | 19 | protected $root; |
| 19 | 20 | protected $ignored; |
| 20 | 21 | |
| 21 | - function __construct($file, $folder, $ignored=null) { |
|
| 22 | + function __construct($file, $folder, $ignored=null) |
|
| 23 | + { |
|
| 22 | 24 | $this->zip = new ZipArchive(); |
| 23 | 25 | |
| 24 | 26 | $this->ignored = is_array($ignored) |
| 25 | 27 | ? $ignored |
| 26 | 28 | : ($ignored ? array($ignored) : array()); |
| 27 | 29 | |
| 28 | - if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) |
|
| 29 | - throw new Exception("cannot open <$file>\n"); |
|
| 30 | + if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) { |
|
| 31 | + throw new Exception("cannot open <$file>\n"); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $folder = rtrim($folder, '/'); |
| 32 | 35 | |
@@ -39,19 +42,22 @@ discard block |
||
| 39 | 42 | $this->zip->close(); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | - function zip($folder, $parent=null) { |
|
| 45 | + function zip($folder, $parent=null) |
|
| 46 | + { |
|
| 43 | 47 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 48 | $zip_path = "$parent$folder"; |
| 45 | 49 | $this->zip->addEmptyDir($zip_path); |
| 46 | 50 | $dir = new DirectoryIterator($full_path); |
| 47 | - foreach ($dir as $file) |
|
| 48 | - if (!$file->isDot()) { |
|
| 51 | + foreach ($dir as $file) { |
|
| 52 | + if (!$file->isDot()) { |
|
| 49 | 53 | $filename = $file->getFilename(); |
| 54 | + } |
|
| 50 | 55 | if (!in_array($filename, $this->ignored)) { |
| 51 | - if ($file->isDir()) |
|
| 52 | - $this->zip($filename, "$zip_path/"); |
|
| 53 | - else |
|
| 54 | - $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 56 | + if ($file->isDir()) { |
|
| 57 | + $this->zip($filename, "$zip_path/"); |
|
| 58 | + } else { |
|
| 59 | + $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 60 | + } |
|
| 55 | 61 | } |
| 56 | 62 | } |
| 57 | 63 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | ? $ignored |
| 26 | 26 | : ($ignored ? array($ignored) : array()); |
| 27 | 27 | |
| 28 | - if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) |
|
| 28 | + if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== true) |
|
| 29 | 29 | throw new Exception("cannot open <$file>\n"); |
| 30 | 30 | |
| 31 | 31 | $folder = rtrim($folder, '/'); |
@@ -102,7 +102,6 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /** Checks if the given file is really writable. The standard PHP function |
| 104 | 104 | * is_writable() does not work properly on Windows servers. |
| 105 | - * @param string $dir |
|
| 106 | 105 | * @return bool */ |
| 107 | 106 | |
| 108 | 107 | static function isWritable($filename) { |
@@ -114,7 +113,6 @@ discard block |
||
| 114 | 113 | } |
| 115 | 114 | |
| 116 | 115 | /** Get the extension from filename |
| 117 | - * @param string $file |
|
| 118 | 116 | * @param bool $toLower |
| 119 | 117 | * @return string */ |
| 120 | 118 | |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** This file is part of KCFinder project |
| 4 | - * |
|
| 5 | - * @desc File helper class |
|
| 6 | - * @package KCFinder |
|
| 7 | - * @version 2.54 |
|
| 8 | - * @author Pavel Tzonkov <[email protected]> |
|
| 9 | - * @copyright 2010-2014 KCFinder Project |
|
| 10 | - * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 |
|
| 11 | - * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 |
|
| 12 | - * @link http://kcfinder.sunhater.com |
|
| 13 | - */ |
|
| 4 | + * |
|
| 5 | + * @desc File helper class |
|
| 6 | + * @package KCFinder |
|
| 7 | + * @version 2.54 |
|
| 8 | + * @author Pavel Tzonkov <[email protected]> |
|
| 9 | + * @copyright 2010-2014 KCFinder Project |
|
| 10 | + * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 |
|
| 11 | + * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 |
|
| 12 | + * @link http://kcfinder.sunhater.com |
|
| 13 | + */ |
|
| 14 | 14 | |
| 15 | 15 | class file { |
| 16 | 16 | |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | 'zip' => 'application/x-zip' |
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | - /** Checks if the given file is really writable. The standard PHP function |
|
| 104 | - * is_writable() does not work properly on Windows servers. |
|
| 105 | - * @param string $dir |
|
| 106 | - * @return bool */ |
|
| 103 | + /** Checks if the given file is really writable. The standard PHP function |
|
| 104 | + * is_writable() does not work properly on Windows servers. |
|
| 105 | + * @param string $dir |
|
| 106 | + * @return bool */ |
|
| 107 | 107 | |
| 108 | 108 | static function isWritable($filename) { |
| 109 | 109 | $filename = path::normalize($filename); |
@@ -113,26 +113,26 @@ discard block |
||
| 113 | 113 | return true; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - /** Get the extension from filename |
|
| 117 | - * @param string $file |
|
| 118 | - * @param bool $toLower |
|
| 119 | - * @return string */ |
|
| 116 | + /** Get the extension from filename |
|
| 117 | + * @param string $file |
|
| 118 | + * @param bool $toLower |
|
| 119 | + * @return string */ |
|
| 120 | 120 | |
| 121 | 121 | static function getExtension($filename, $toLower=true) { |
| 122 | 122 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
| 123 | 123 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - /** Get MIME type of the given filename. If Fileinfo PHP extension is |
|
| 127 | - * available the MIME type will be fetched by the file's content. The |
|
| 128 | - * second parameter is optional and defines the magic file path. If you |
|
| 129 | - * skip it, the default one will be loaded. |
|
| 130 | - * If Fileinfo PHP extension is not available the MIME type will be fetched |
|
| 131 | - * by filename extension regarding $MIME property. If the file extension |
|
| 132 | - * does not exist there, returned type will be application/octet-stream |
|
| 133 | - * @param string $filename |
|
| 134 | - * @param string $magic |
|
| 135 | - * @return string */ |
|
| 126 | + /** Get MIME type of the given filename. If Fileinfo PHP extension is |
|
| 127 | + * available the MIME type will be fetched by the file's content. The |
|
| 128 | + * second parameter is optional and defines the magic file path. If you |
|
| 129 | + * skip it, the default one will be loaded. |
|
| 130 | + * If Fileinfo PHP extension is not available the MIME type will be fetched |
|
| 131 | + * by filename extension regarding $MIME property. If the file extension |
|
| 132 | + * does not exist there, returned type will be application/octet-stream |
|
| 133 | + * @param string $filename |
|
| 134 | + * @param string $magic |
|
| 135 | + * @return string */ |
|
| 136 | 136 | |
| 137 | 137 | static function getMimeType($filename, $magic=null) { |
| 138 | 138 | if (class_exists("finfo")) { |
@@ -149,26 +149,26 @@ discard block |
||
| 149 | 149 | return isset(self::$MIME[$ext]) ? self::$MIME[$ext] : "application/octet-stream"; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** Get inexistant filename based on the given filename. If you skip $dir |
|
| 153 | - * parameter the directory will be fetched from $filename and returned |
|
| 154 | - * value will be full filename path. The third parameter is optional and |
|
| 155 | - * defines the template, the filename will be renamed to. Default template |
|
| 156 | - * is {name}({sufix}){ext}. Examples: |
|
| 157 | - * |
|
| 158 | - * file::getInexistantFilename("/my/directory/myfile.txt"); |
|
| 159 | - * If myfile.txt does not exist - returns the same path to the file |
|
| 160 | - * otherwise returns "/my/directory/myfile(1).txt" |
|
| 161 | - * |
|
| 162 | - * file::getInexistantFilename("myfile.txt", "/my/directory"); |
|
| 163 | - * returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc... |
|
| 164 | - * |
|
| 165 | - * file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}"); |
|
| 166 | - * returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc... |
|
| 167 | - * |
|
| 168 | - * @param string $filename |
|
| 169 | - * @param string $dir |
|
| 170 | - * @param string $tpl |
|
| 171 | - * @return string */ |
|
| 152 | + /** Get inexistant filename based on the given filename. If you skip $dir |
|
| 153 | + * parameter the directory will be fetched from $filename and returned |
|
| 154 | + * value will be full filename path. The third parameter is optional and |
|
| 155 | + * defines the template, the filename will be renamed to. Default template |
|
| 156 | + * is {name}({sufix}){ext}. Examples: |
|
| 157 | + * |
|
| 158 | + * file::getInexistantFilename("/my/directory/myfile.txt"); |
|
| 159 | + * If myfile.txt does not exist - returns the same path to the file |
|
| 160 | + * otherwise returns "/my/directory/myfile(1).txt" |
|
| 161 | + * |
|
| 162 | + * file::getInexistantFilename("myfile.txt", "/my/directory"); |
|
| 163 | + * returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc... |
|
| 164 | + * |
|
| 165 | + * file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}"); |
|
| 166 | + * returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc... |
|
| 167 | + * |
|
| 168 | + * @param string $filename |
|
| 169 | + * @param string $dir |
|
| 170 | + * @param string $tpl |
|
| 171 | + * @return string */ |
|
| 172 | 172 | |
| 173 | 173 | static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
| 174 | 174 | if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class file { |
|
| 15 | +class file{ |
|
| 16 | 16 | |
| 17 | 17 | static $MIME = array( |
| 18 | 18 | 'ai' => 'application/postscript', |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param string $dir |
| 106 | 106 | * @return bool */ |
| 107 | 107 | |
| 108 | - static function isWritable($filename) { |
|
| 108 | + static function isWritable($filename){ |
|
| 109 | 109 | $filename = path::normalize($filename); |
| 110 | 110 | if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
| 111 | 111 | return false; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param bool $toLower |
| 119 | 119 | * @return string */ |
| 120 | 120 | |
| 121 | - static function getExtension($filename, $toLower=true) { |
|
| 121 | + static function getExtension($filename, $toLower = true){ |
|
| 122 | 122 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
| 123 | 123 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
| 124 | 124 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param string $magic |
| 135 | 135 | * @return string */ |
| 136 | 136 | |
| 137 | - static function getMimeType($filename, $magic=null) { |
|
| 137 | + static function getMimeType($filename, $magic = null){ |
|
| 138 | 138 | if (class_exists("finfo")) { |
| 139 | 139 | $finfo = ($magic === null) |
| 140 | 140 | ? new finfo(FILEINFO_MIME) |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param string $tpl |
| 171 | 171 | * @return string */ |
| 172 | 172 | |
| 173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
| 173 | + static function getInexistantFilename($filename, $dir = null, $tpl = null){ |
|
| 174 | 174 | if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
| 175 | 175 | $fullPath = ($dir === null); |
| 176 | 176 | if ($fullPath) |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
| 189 | 189 | $i = 1; $file = "$dir/$filename"; |
| 190 | 190 | while (file_exists($file)) |
| 191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 191 | + $file = "$dir/".str_replace('{sufix}', $i++, $tpl); |
|
| 192 | 192 | |
| 193 | 193 | return $fullPath |
| 194 | 194 | ? $file |
| 195 | 195 | : (strlen($fdir) |
| 196 | - ? "$fdir/" . basename($file) |
|
| 196 | + ? "$fdir/".basename($file) |
|
| 197 | 197 | : basename($file)); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class file { |
|
| 15 | +class file |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | static $MIME = array( |
| 18 | 19 | 'ai' => 'application/postscript', |
@@ -105,10 +106,12 @@ discard block |
||
| 105 | 106 | * @param string $dir |
| 106 | 107 | * @return bool */ |
| 107 | 108 | |
| 108 | - static function isWritable($filename) { |
|
| 109 | + static function isWritable($filename) |
|
| 110 | + { |
|
| 109 | 111 | $filename = path::normalize($filename); |
| 110 | - if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
|
| 111 | - return false; |
|
| 112 | + if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 112 | 115 | fclose($fp); |
| 113 | 116 | return true; |
| 114 | 117 | } |
@@ -118,7 +121,8 @@ discard block |
||
| 118 | 121 | * @param bool $toLower |
| 119 | 122 | * @return string */ |
| 120 | 123 | |
| 121 | - static function getExtension($filename, $toLower=true) { |
|
| 124 | + static function getExtension($filename, $toLower=true) |
|
| 125 | + { |
|
| 122 | 126 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
| 123 | 127 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
| 124 | 128 | } |
@@ -134,7 +138,8 @@ discard block |
||
| 134 | 138 | * @param string $magic |
| 135 | 139 | * @return string */ |
| 136 | 140 | |
| 137 | - static function getMimeType($filename, $magic=null) { |
|
| 141 | + static function getMimeType($filename, $magic=null) |
|
| 142 | + { |
|
| 138 | 143 | if (class_exists("finfo")) { |
| 139 | 144 | $finfo = ($magic === null) |
| 140 | 145 | ? new finfo(FILEINFO_MIME) |
@@ -170,12 +175,15 @@ discard block |
||
| 170 | 175 | * @param string $tpl |
| 171 | 176 | * @return string */ |
| 172 | 177 | |
| 173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
| 174 | - if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
|
| 178 | + static function getInexistantFilename($filename, $dir=null, $tpl=null) |
|
| 179 | + { |
|
| 180 | + if ($tpl === null) { |
|
| 181 | + $tpl = "{name}({sufix}){ext}"; |
|
| 182 | + } |
|
| 175 | 183 | $fullPath = ($dir === null); |
| 176 | - if ($fullPath) |
|
| 177 | - $dir = path::normalize(dirname($filename)); |
|
| 178 | - else { |
|
| 184 | + if ($fullPath) { |
|
| 185 | + $dir = path::normalize(dirname($filename)); |
|
| 186 | + } else { |
|
| 179 | 187 | $fdir = dirname($filename); |
| 180 | 188 | $dir = strlen($fdir) |
| 181 | 189 | ? path::normalize("$dir/$fdir") |
@@ -187,8 +195,9 @@ discard block |
||
| 187 | 195 | $tpl = str_replace('{name}', $name, $tpl); |
| 188 | 196 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
| 189 | 197 | $i = 1; $file = "$dir/$filename"; |
| 190 | - while (file_exists($file)) |
|
| 191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 198 | + while (file_exists($file)) { |
|
| 199 | + $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | return $fullPath |
| 194 | 203 | ? $file |
@@ -616,6 +616,9 @@ discard block |
||
| 616 | 616 | Output: |
| 617 | 617 | \*======================================================================*/ |
| 618 | 618 | |
| 619 | + /** |
|
| 620 | + * @param string $http_method |
|
| 621 | + */ |
|
| 619 | 622 | function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
| 620 | 623 | { |
| 621 | 624 | $cookie_headers = ''; |
@@ -923,6 +926,10 @@ discard block |
||
| 923 | 926 | Output: post body |
| 924 | 927 | \*======================================================================*/ |
| 925 | 928 | |
| 929 | + /** |
|
| 930 | + * @param string $formvars |
|
| 931 | + * @param string $formfiles |
|
| 932 | + */ |
|
| 926 | 933 | function _prepare_post_body($formvars, $formfiles) |
| 927 | 934 | { |
| 928 | 935 | settype($formvars, "array"); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | // using proxy, send entire URI |
| 150 | 150 | $this->_httprequest($URI, $fp, $URI, $this->_httpmethod); |
| 151 | 151 | } else { |
| 152 | - $path = $URI_PARTS["path"] . ($URI_PARTS["query"] ? "?" . $URI_PARTS["query"] : ""); |
|
| 152 | + $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|
| 153 | 153 | // no proxy, send only the path |
| 154 | 154 | $this->_httprequest($path, $fp, $URI, $this->_httpmethod); |
| 155 | 155 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | /* url was redirected, check if we've hit the max depth */ |
| 161 | 161 | if ($this->maxredirs > $this->_redirectdepth) { |
| 162 | 162 | // only follow redirect if it's on this site, or offsiteok is true |
| 163 | - if (preg_match("|^https?://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) { |
|
| 163 | + if (preg_match("|^https?://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) { |
|
| 164 | 164 | /* follow the redirect */ |
| 165 | 165 | $this->_redirectdepth++; |
| 166 | 166 | $this->lastredirectaddr = $this->_redirectaddr; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | break; |
| 189 | 189 | default: |
| 190 | 190 | // not a valid protocol |
| 191 | - $this->error = 'Invalid protocol "' . $URI_PARTS["scheme"] . '"\n'; |
|
| 191 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 192 | 192 | return false; |
| 193 | 193 | break; |
| 194 | 194 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | // using proxy, send entire URI |
| 240 | 240 | $this->_httprequest($URI, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 241 | 241 | } else { |
| 242 | - $path = $URI_PARTS["path"] . ($URI_PARTS["query"] ? "?" . $URI_PARTS["query"] : ""); |
|
| 242 | + $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|
| 243 | 243 | // no proxy, send only the path |
| 244 | 244 | $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 245 | 245 | } |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | if ($this->_redirectaddr) { |
| 250 | 250 | /* url was redirected, check if we've hit the max depth */ |
| 251 | 251 | if ($this->maxredirs > $this->_redirectdepth) { |
| 252 | - if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) |
|
| 253 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]); |
|
| 252 | + if (!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 253 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 254 | 254 | |
| 255 | 255 | // only follow redirect if it's on this site, or offsiteok is true |
| 256 | - if (preg_match("|^https?://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) { |
|
| 256 | + if (preg_match("|^https?://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) { |
|
| 257 | 257 | /* follow the redirect */ |
| 258 | 258 | $this->_redirectdepth++; |
| 259 | 259 | $this->lastredirectaddr = $this->_redirectaddr; |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | break; |
| 286 | 286 | default: |
| 287 | 287 | // not a valid protocol |
| 288 | - $this->error = 'Invalid protocol "' . $URI_PARTS["scheme"] . '"\n'; |
|
| 288 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 289 | 289 | return false; |
| 290 | 290 | break; |
| 291 | 291 | } |
@@ -585,9 +585,9 @@ discard block |
||
| 585 | 585 | $match = preg_replace("|/$|", "", $match); |
| 586 | 586 | $match_part = parse_url($match); |
| 587 | 587 | $match_root = |
| 588 | - $match_part["scheme"] . "://" . $match_part["host"]; |
|
| 588 | + $match_part["scheme"]."://".$match_part["host"]; |
|
| 589 | 589 | |
| 590 | - $search = array("|^http://" . preg_quote($this->host) . "|i", |
|
| 590 | + $search = array("|^http://".preg_quote($this->host)."|i", |
|
| 591 | 591 | "|^(\/)|i", |
| 592 | 592 | "|^(?!http://)(?!mailto:)|i", |
| 593 | 593 | "|/\./|", |
@@ -595,8 +595,8 @@ discard block |
||
| 595 | 595 | ); |
| 596 | 596 | |
| 597 | 597 | $replace = array("", |
| 598 | - $match_root . "/", |
|
| 599 | - $match . "/", |
|
| 598 | + $match_root."/", |
|
| 599 | + $match."/", |
|
| 600 | 600 | "/", |
| 601 | 601 | "/" |
| 602 | 602 | ); |
@@ -625,17 +625,17 @@ discard block |
||
| 625 | 625 | $URI_PARTS = parse_url($URI); |
| 626 | 626 | if (empty($url)) |
| 627 | 627 | $url = "/"; |
| 628 | - $headers = $http_method . " " . $url . " " . $this->_httpversion . "\r\n"; |
|
| 628 | + $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
|
| 629 | 629 | if (!empty($this->host) && !isset($this->rawheaders['Host'])) { |
| 630 | - $headers .= "Host: " . $this->host; |
|
| 630 | + $headers .= "Host: ".$this->host; |
|
| 631 | 631 | if (!empty($this->port) && $this->port != '80') |
| 632 | - $headers .= ":" . $this->port; |
|
| 632 | + $headers .= ":".$this->port; |
|
| 633 | 633 | $headers .= "\r\n"; |
| 634 | 634 | } |
| 635 | 635 | if (!empty($this->agent)) |
| 636 | - $headers .= "User-Agent: " . $this->agent . "\r\n"; |
|
| 636 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
| 637 | 637 | if (!empty($this->accept)) |
| 638 | - $headers .= "Accept: " . $this->accept . "\r\n"; |
|
| 638 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
| 639 | 639 | if ($this->use_gzip) { |
| 640 | 640 | // make sure PHP was built with --with-zlib |
| 641 | 641 | // and we can handle gzipp'ed data |
@@ -643,46 +643,46 @@ discard block |
||
| 643 | 643 | $headers .= "Accept-encoding: gzip\r\n"; |
| 644 | 644 | } else { |
| 645 | 645 | trigger_error( |
| 646 | - "use_gzip is on, but PHP was built without zlib support." . |
|
| 646 | + "use_gzip is on, but PHP was built without zlib support.". |
|
| 647 | 647 | " Requesting file(s) without gzip encoding.", |
| 648 | 648 | E_USER_NOTICE); |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | if (!empty($this->referer)) |
| 652 | - $headers .= "Referer: " . $this->referer . "\r\n"; |
|
| 652 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
| 653 | 653 | if (!empty($this->cookies)) { |
| 654 | 654 | if (!is_array($this->cookies)) |
| 655 | - $this->cookies = (array)$this->cookies; |
|
| 655 | + $this->cookies = (array) $this->cookies; |
|
| 656 | 656 | |
| 657 | 657 | reset($this->cookies); |
| 658 | 658 | if (count($this->cookies) > 0) { |
| 659 | 659 | $cookie_headers .= 'Cookie: '; |
| 660 | 660 | foreach ($this->cookies as $cookieKey => $cookieVal) { |
| 661 | - $cookie_headers .= $cookieKey . "=" . urlencode($cookieVal) . "; "; |
|
| 661 | + $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
|
| 662 | 662 | } |
| 663 | - $headers .= substr($cookie_headers, 0, -2) . "\r\n"; |
|
| 663 | + $headers .= substr($cookie_headers, 0, -2)."\r\n"; |
|
| 664 | 664 | } |
| 665 | 665 | } |
| 666 | 666 | if (!empty($this->rawheaders)) { |
| 667 | 667 | if (!is_array($this->rawheaders)) |
| 668 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 668 | + $this->rawheaders = (array) $this->rawheaders; |
|
| 669 | 669 | while (list($headerKey, $headerVal) = each($this->rawheaders)) |
| 670 | - $headers .= $headerKey . ": " . $headerVal . "\r\n"; |
|
| 670 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
| 671 | 671 | } |
| 672 | 672 | if (!empty($content_type)) { |
| 673 | 673 | $headers .= "Content-type: $content_type"; |
| 674 | 674 | if ($content_type == "multipart/form-data") |
| 675 | - $headers .= "; boundary=" . $this->_mime_boundary; |
|
| 675 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
| 676 | 676 | $headers .= "\r\n"; |
| 677 | 677 | } |
| 678 | 678 | if (!empty($body)) |
| 679 | - $headers .= "Content-length: " . strlen($body) . "\r\n"; |
|
| 679 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
| 680 | 680 | if (!empty($this->user) || !empty($this->pass)) |
| 681 | - $headers .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->pass) . "\r\n"; |
|
| 681 | + $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
| 682 | 682 | |
| 683 | 683 | //add proxy auth headers |
| 684 | 684 | if (!empty($this->proxy_user)) |
| 685 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; |
|
| 685 | + $headers .= 'Proxy-Authorization: '.'Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass)."\r\n"; |
|
| 686 | 686 | |
| 687 | 687 | |
| 688 | 688 | $headers .= "\r\n"; |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | socket_set_timeout($fp, $this->read_timeout); |
| 693 | 693 | $this->timed_out = false; |
| 694 | 694 | |
| 695 | - fwrite($fp, $headers . $body, strlen($headers . $body)); |
|
| 695 | + fwrite($fp, $headers.$body, strlen($headers.$body)); |
|
| 696 | 696 | |
| 697 | 697 | $this->_redirectaddr = false; |
| 698 | 698 | unset($this->headers); |
@@ -716,10 +716,10 @@ discard block |
||
| 716 | 716 | // look for :// in the Location header to see if hostname is included |
| 717 | 717 | if (!preg_match("|\:\/\/|", $matches[2])) { |
| 718 | 718 | // no host in the path, so prepend |
| 719 | - $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port; |
|
| 719 | + $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|
| 720 | 720 | // eliminate double slash |
| 721 | 721 | if (!preg_match("|^/|", $matches[2])) |
| 722 | - $this->_redirectaddr .= "/" . $matches[2]; |
|
| 722 | + $this->_redirectaddr .= "/".$matches[2]; |
|
| 723 | 723 | else |
| 724 | 724 | $this->_redirectaddr .= $matches[2]; |
| 725 | 725 | } else |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) { |
| 772 | 772 | $this->results[] = $results; |
| 773 | 773 | for ($x = 0; $x < count($match[1]); $x++) |
| 774 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); |
|
| 774 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
| 775 | 775 | } // have we already fetched framed content? |
| 776 | 776 | elseif (is_array($this->results)) |
| 777 | 777 | $this->results[] = $results; |
@@ -858,14 +858,14 @@ discard block |
||
| 858 | 858 | $context_opts['ssl']['capath'] = $this->capath; |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - $host = 'ssl://' . $host; |
|
| 861 | + $host = 'ssl://'.$host; |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | $context = stream_context_create($context_opts); |
| 865 | 865 | |
| 866 | 866 | if (version_compare(PHP_VERSION, '5.0.0', '>')) { |
| 867 | - if($this->scheme == 'http') |
|
| 868 | - $host = "tcp://" . $host; |
|
| 867 | + if ($this->scheme == 'http') |
|
| 868 | + $host = "tcp://".$host; |
|
| 869 | 869 | $fp = stream_socket_client( |
| 870 | 870 | "$host:$port", |
| 871 | 871 | $errno, |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | case -5: |
| 898 | 898 | $this->error = "connection refused or timed out (-5)"; |
| 899 | 899 | default: |
| 900 | - $this->error = "connection failed (" . $errno . ")"; |
|
| 900 | + $this->error = "connection failed (".$errno.")"; |
|
| 901 | 901 | } |
| 902 | 902 | return false; |
| 903 | 903 | } |
@@ -938,26 +938,26 @@ discard block |
||
| 938 | 938 | while (list($key, $val) = each($formvars)) { |
| 939 | 939 | if (is_array($val) || is_object($val)) { |
| 940 | 940 | while (list($cur_key, $cur_val) = each($val)) { |
| 941 | - $postdata .= urlencode($key) . "[]=" . urlencode($cur_val) . "&"; |
|
| 941 | + $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
|
| 942 | 942 | } |
| 943 | 943 | } else |
| 944 | - $postdata .= urlencode($key) . "=" . urlencode($val) . "&"; |
|
| 944 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
| 945 | 945 | } |
| 946 | 946 | break; |
| 947 | 947 | |
| 948 | 948 | case "multipart/form-data": |
| 949 | - $this->_mime_boundary = "Snoopy" . md5(uniqid(microtime())); |
|
| 949 | + $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
|
| 950 | 950 | |
| 951 | 951 | reset($formvars); |
| 952 | 952 | while (list($key, $val) = each($formvars)) { |
| 953 | 953 | if (is_array($val) || is_object($val)) { |
| 954 | 954 | while (list($cur_key, $cur_val) = each($val)) { |
| 955 | - $postdata .= "--" . $this->_mime_boundary . "\r\n"; |
|
| 955 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
| 956 | 956 | $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; |
| 957 | 957 | $postdata .= "$cur_val\r\n"; |
| 958 | 958 | } |
| 959 | 959 | } else { |
| 960 | - $postdata .= "--" . $this->_mime_boundary . "\r\n"; |
|
| 960 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
| 961 | 961 | $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n"; |
| 962 | 962 | $postdata .= "$val\r\n"; |
| 963 | 963 | } |
@@ -974,12 +974,12 @@ discard block |
||
| 974 | 974 | fclose($fp); |
| 975 | 975 | $base_name = basename($file_name); |
| 976 | 976 | |
| 977 | - $postdata .= "--" . $this->_mime_boundary . "\r\n"; |
|
| 977 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
| 978 | 978 | $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n"; |
| 979 | 979 | $postdata .= "$file_content\r\n"; |
| 980 | 980 | } |
| 981 | 981 | } |
| 982 | - $postdata .= "--" . $this->_mime_boundary . "--\r\n"; |
|
| 982 | + $postdata .= "--".$this->_mime_boundary."--\r\n"; |
|
| 983 | 983 | break; |
| 984 | 984 | } |
| 985 | 985 | |
@@ -121,14 +121,18 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | |
| 123 | 123 | $URI_PARTS = parse_url($URI); |
| 124 | - if (!empty($URI_PARTS["user"])) |
|
| 125 | - $this->user = $URI_PARTS["user"]; |
|
| 126 | - if (!empty($URI_PARTS["pass"])) |
|
| 127 | - $this->pass = $URI_PARTS["pass"]; |
|
| 128 | - if (empty($URI_PARTS["query"])) |
|
| 129 | - $URI_PARTS["query"] = ''; |
|
| 130 | - if (empty($URI_PARTS["path"])) |
|
| 131 | - $URI_PARTS["path"] = ''; |
|
| 124 | + if (!empty($URI_PARTS["user"])) { |
|
| 125 | + $this->user = $URI_PARTS["user"]; |
|
| 126 | + } |
|
| 127 | + if (!empty($URI_PARTS["pass"])) { |
|
| 128 | + $this->pass = $URI_PARTS["pass"]; |
|
| 129 | + } |
|
| 130 | + if (empty($URI_PARTS["query"])) { |
|
| 131 | + $URI_PARTS["query"] = ''; |
|
| 132 | + } |
|
| 133 | + if (empty($URI_PARTS["path"])) { |
|
| 134 | + $URI_PARTS["path"] = ''; |
|
| 135 | + } |
|
| 132 | 136 | |
| 133 | 137 | $fp = null; |
| 134 | 138 | |
@@ -142,8 +146,9 @@ discard block |
||
| 142 | 146 | case "http": |
| 143 | 147 | $this->scheme = strtolower($URI_PARTS["scheme"]); |
| 144 | 148 | $this->host = $URI_PARTS["host"]; |
| 145 | - if (!empty($URI_PARTS["port"])) |
|
| 146 | - $this->port = $URI_PARTS["port"]; |
|
| 149 | + if (!empty($URI_PARTS["port"])) { |
|
| 150 | + $this->port = $URI_PARTS["port"]; |
|
| 151 | + } |
|
| 147 | 152 | if ($this->_connect($fp)) { |
| 148 | 153 | if ($this->_isproxy) { |
| 149 | 154 | // using proxy, send entire URI |
@@ -177,8 +182,9 @@ discard block |
||
| 177 | 182 | if ($this->_framedepth < $this->maxframes) { |
| 178 | 183 | $this->fetch($frameurl); |
| 179 | 184 | $this->_framedepth++; |
| 180 | - } else |
|
| 181 | - break; |
|
| 185 | + } else { |
|
| 186 | + break; |
|
| 187 | + } |
|
| 182 | 188 | } |
| 183 | 189 | } |
| 184 | 190 | } else { |
@@ -213,14 +219,18 @@ discard block |
||
| 213 | 219 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 214 | 220 | |
| 215 | 221 | $URI_PARTS = parse_url($URI); |
| 216 | - if (!empty($URI_PARTS["user"])) |
|
| 217 | - $this->user = $URI_PARTS["user"]; |
|
| 218 | - if (!empty($URI_PARTS["pass"])) |
|
| 219 | - $this->pass = $URI_PARTS["pass"]; |
|
| 220 | - if (empty($URI_PARTS["query"])) |
|
| 221 | - $URI_PARTS["query"] = ''; |
|
| 222 | - if (empty($URI_PARTS["path"])) |
|
| 223 | - $URI_PARTS["path"] = ''; |
|
| 222 | + if (!empty($URI_PARTS["user"])) { |
|
| 223 | + $this->user = $URI_PARTS["user"]; |
|
| 224 | + } |
|
| 225 | + if (!empty($URI_PARTS["pass"])) { |
|
| 226 | + $this->pass = $URI_PARTS["pass"]; |
|
| 227 | + } |
|
| 228 | + if (empty($URI_PARTS["query"])) { |
|
| 229 | + $URI_PARTS["query"] = ''; |
|
| 230 | + } |
|
| 231 | + if (empty($URI_PARTS["path"])) { |
|
| 232 | + $URI_PARTS["path"] = ''; |
|
| 233 | + } |
|
| 224 | 234 | |
| 225 | 235 | switch (strtolower($URI_PARTS["scheme"])) { |
| 226 | 236 | case "https": |
@@ -232,8 +242,9 @@ discard block |
||
| 232 | 242 | case "http": |
| 233 | 243 | $this->scheme = strtolower($URI_PARTS["scheme"]); |
| 234 | 244 | $this->host = $URI_PARTS["host"]; |
| 235 | - if (!empty($URI_PARTS["port"])) |
|
| 236 | - $this->port = $URI_PARTS["port"]; |
|
| 245 | + if (!empty($URI_PARTS["port"])) { |
|
| 246 | + $this->port = $URI_PARTS["port"]; |
|
| 247 | + } |
|
| 237 | 248 | if ($this->_connect($fp)) { |
| 238 | 249 | if ($this->_isproxy) { |
| 239 | 250 | // using proxy, send entire URI |
@@ -249,18 +260,22 @@ discard block |
||
| 249 | 260 | if ($this->_redirectaddr) { |
| 250 | 261 | /* url was redirected, check if we've hit the max depth */ |
| 251 | 262 | if ($this->maxredirs > $this->_redirectdepth) { |
| 252 | - if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) |
|
| 253 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]); |
|
| 263 | + if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) { |
|
| 264 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]); |
|
| 265 | + } |
|
| 254 | 266 | |
| 255 | 267 | // only follow redirect if it's on this site, or offsiteok is true |
| 256 | 268 | if (preg_match("|^https?://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) { |
| 257 | 269 | /* follow the redirect */ |
| 258 | 270 | $this->_redirectdepth++; |
| 259 | 271 | $this->lastredirectaddr = $this->_redirectaddr; |
| 260 | - if (strpos($this->_redirectaddr, "?") > 0) |
|
| 261 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 262 | - else |
|
| 263 | - $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 272 | + if (strpos($this->_redirectaddr, "?") > 0) { |
|
| 273 | + $this->fetch($this->_redirectaddr); |
|
| 274 | + } |
|
| 275 | + // the redirect has changed the request method from post to get |
|
| 276 | + else { |
|
| 277 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 278 | + } |
|
| 264 | 279 | } |
| 265 | 280 | } |
| 266 | 281 | } |
@@ -273,8 +288,9 @@ discard block |
||
| 273 | 288 | if ($this->_framedepth < $this->maxframes) { |
| 274 | 289 | $this->fetch($frameurl); |
| 275 | 290 | $this->_framedepth++; |
| 276 | - } else |
|
| 277 | - break; |
|
| 291 | + } else { |
|
| 292 | + break; |
|
| 293 | + } |
|
| 278 | 294 | } |
| 279 | 295 | } |
| 280 | 296 | |
@@ -302,19 +318,24 @@ discard block |
||
| 302 | 318 | function fetchlinks($URI) |
| 303 | 319 | { |
| 304 | 320 | if ($this->fetch($URI) !== false) { |
| 305 | - if ($this->lastredirectaddr) |
|
| 306 | - $URI = $this->lastredirectaddr; |
|
| 321 | + if ($this->lastredirectaddr) { |
|
| 322 | + $URI = $this->lastredirectaddr; |
|
| 323 | + } |
|
| 307 | 324 | if (is_array($this->results)) { |
| 308 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 309 | - $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 310 | - } else |
|
| 311 | - $this->results = $this->_striplinks($this->results); |
|
| 325 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 326 | + $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 327 | + } |
|
| 328 | + } else { |
|
| 329 | + $this->results = $this->_striplinks($this->results); |
|
| 330 | + } |
|
| 312 | 331 | |
| 313 | - if ($this->expandlinks) |
|
| 314 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 332 | + if ($this->expandlinks) { |
|
| 333 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 334 | + } |
|
| 315 | 335 | return $this; |
| 316 | - } else |
|
| 317 | - return false; |
|
| 336 | + } else { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 318 | 339 | } |
| 319 | 340 | |
| 320 | 341 | /*======================================================================*\ |
@@ -330,14 +351,17 @@ discard block |
||
| 330 | 351 | if ($this->fetch($URI) !== false) { |
| 331 | 352 | |
| 332 | 353 | if (is_array($this->results)) { |
| 333 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 334 | - $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 335 | - } else |
|
| 336 | - $this->results = $this->_stripform($this->results); |
|
| 354 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 355 | + $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 356 | + } |
|
| 357 | + } else { |
|
| 358 | + $this->results = $this->_stripform($this->results); |
|
| 359 | + } |
|
| 337 | 360 | |
| 338 | 361 | return $this; |
| 339 | - } else |
|
| 340 | - return false; |
|
| 362 | + } else { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 341 | 365 | } |
| 342 | 366 | |
| 343 | 367 | |
@@ -352,13 +376,16 @@ discard block |
||
| 352 | 376 | { |
| 353 | 377 | if ($this->fetch($URI) !== false) { |
| 354 | 378 | if (is_array($this->results)) { |
| 355 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 356 | - $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 357 | - } else |
|
| 358 | - $this->results = $this->_striptext($this->results); |
|
| 379 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 380 | + $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 381 | + } |
|
| 382 | + } else { |
|
| 383 | + $this->results = $this->_striptext($this->results); |
|
| 384 | + } |
|
| 359 | 385 | return $this; |
| 360 | - } else |
|
| 361 | - return false; |
|
| 386 | + } else { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 362 | 389 | } |
| 363 | 390 | |
| 364 | 391 | /*======================================================================*\ |
@@ -371,22 +398,26 @@ discard block |
||
| 371 | 398 | function submitlinks($URI, $formvars = "", $formfiles = "") |
| 372 | 399 | { |
| 373 | 400 | if ($this->submit($URI, $formvars, $formfiles) !== false) { |
| 374 | - if ($this->lastredirectaddr) |
|
| 375 | - $URI = $this->lastredirectaddr; |
|
| 401 | + if ($this->lastredirectaddr) { |
|
| 402 | + $URI = $this->lastredirectaddr; |
|
| 403 | + } |
|
| 376 | 404 | if (is_array($this->results)) { |
| 377 | 405 | for ($x = 0; $x < count($this->results); $x++) { |
| 378 | 406 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 379 | - if ($this->expandlinks) |
|
| 380 | - $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 407 | + if ($this->expandlinks) { |
|
| 408 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 409 | + } |
|
| 381 | 410 | } |
| 382 | 411 | } else { |
| 383 | 412 | $this->results = $this->_striplinks($this->results); |
| 384 | - if ($this->expandlinks) |
|
| 385 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 413 | + if ($this->expandlinks) { |
|
| 414 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 415 | + } |
|
| 386 | 416 | } |
| 387 | 417 | return $this; |
| 388 | - } else |
|
| 389 | - return false; |
|
| 418 | + } else { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 390 | 421 | } |
| 391 | 422 | |
| 392 | 423 | /*======================================================================*\ |
@@ -399,22 +430,26 @@ discard block |
||
| 399 | 430 | function submittext($URI, $formvars = "", $formfiles = "") |
| 400 | 431 | { |
| 401 | 432 | if ($this->submit($URI, $formvars, $formfiles) !== false) { |
| 402 | - if ($this->lastredirectaddr) |
|
| 403 | - $URI = $this->lastredirectaddr; |
|
| 433 | + if ($this->lastredirectaddr) { |
|
| 434 | + $URI = $this->lastredirectaddr; |
|
| 435 | + } |
|
| 404 | 436 | if (is_array($this->results)) { |
| 405 | 437 | for ($x = 0; $x < count($this->results); $x++) { |
| 406 | 438 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 407 | - if ($this->expandlinks) |
|
| 408 | - $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 439 | + if ($this->expandlinks) { |
|
| 440 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 441 | + } |
|
| 409 | 442 | } |
| 410 | 443 | } else { |
| 411 | 444 | $this->results = $this->_striptext($this->results); |
| 412 | - if ($this->expandlinks) |
|
| 413 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 445 | + if ($this->expandlinks) { |
|
| 446 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 447 | + } |
|
| 414 | 448 | } |
| 415 | 449 | return $this; |
| 416 | - } else |
|
| 417 | - return false; |
|
| 450 | + } else { |
|
| 451 | + return false; |
|
| 452 | + } |
|
| 418 | 453 | } |
| 419 | 454 | |
| 420 | 455 | |
@@ -468,13 +503,15 @@ discard block |
||
| 468 | 503 | // catenate the non-empty matches from the conditional subpattern |
| 469 | 504 | |
| 470 | 505 | while (list($key, $val) = each($links[2])) { |
| 471 | - if (!empty($val)) |
|
| 472 | - $match[] = $val; |
|
| 506 | + if (!empty($val)) { |
|
| 507 | + $match[] = $val; |
|
| 508 | + } |
|
| 473 | 509 | } |
| 474 | 510 | |
| 475 | 511 | while (list($key, $val) = each($links[3])) { |
| 476 | - if (!empty($val)) |
|
| 477 | - $match[] = $val; |
|
| 512 | + if (!empty($val)) { |
|
| 513 | + $match[] = $val; |
|
| 514 | + } |
|
| 478 | 515 | } |
| 479 | 516 | |
| 480 | 517 | // return the links |
@@ -619,23 +656,28 @@ discard block |
||
| 619 | 656 | function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
| 620 | 657 | { |
| 621 | 658 | $cookie_headers = ''; |
| 622 | - if ($this->passcookies && $this->_redirectaddr) |
|
| 623 | - $this->setcookies(); |
|
| 659 | + if ($this->passcookies && $this->_redirectaddr) { |
|
| 660 | + $this->setcookies(); |
|
| 661 | + } |
|
| 624 | 662 | |
| 625 | 663 | $URI_PARTS = parse_url($URI); |
| 626 | - if (empty($url)) |
|
| 627 | - $url = "/"; |
|
| 664 | + if (empty($url)) { |
|
| 665 | + $url = "/"; |
|
| 666 | + } |
|
| 628 | 667 | $headers = $http_method . " " . $url . " " . $this->_httpversion . "\r\n"; |
| 629 | 668 | if (!empty($this->host) && !isset($this->rawheaders['Host'])) { |
| 630 | 669 | $headers .= "Host: " . $this->host; |
| 631 | - if (!empty($this->port) && $this->port != '80') |
|
| 632 | - $headers .= ":" . $this->port; |
|
| 670 | + if (!empty($this->port) && $this->port != '80') { |
|
| 671 | + $headers .= ":" . $this->port; |
|
| 672 | + } |
|
| 633 | 673 | $headers .= "\r\n"; |
| 634 | 674 | } |
| 635 | - if (!empty($this->agent)) |
|
| 636 | - $headers .= "User-Agent: " . $this->agent . "\r\n"; |
|
| 637 | - if (!empty($this->accept)) |
|
| 638 | - $headers .= "Accept: " . $this->accept . "\r\n"; |
|
| 675 | + if (!empty($this->agent)) { |
|
| 676 | + $headers .= "User-Agent: " . $this->agent . "\r\n"; |
|
| 677 | + } |
|
| 678 | + if (!empty($this->accept)) { |
|
| 679 | + $headers .= "Accept: " . $this->accept . "\r\n"; |
|
| 680 | + } |
|
| 639 | 681 | if ($this->use_gzip) { |
| 640 | 682 | // make sure PHP was built with --with-zlib |
| 641 | 683 | // and we can handle gzipp'ed data |
@@ -648,11 +690,13 @@ discard block |
||
| 648 | 690 | E_USER_NOTICE); |
| 649 | 691 | } |
| 650 | 692 | } |
| 651 | - if (!empty($this->referer)) |
|
| 652 | - $headers .= "Referer: " . $this->referer . "\r\n"; |
|
| 693 | + if (!empty($this->referer)) { |
|
| 694 | + $headers .= "Referer: " . $this->referer . "\r\n"; |
|
| 695 | + } |
|
| 653 | 696 | if (!empty($this->cookies)) { |
| 654 | - if (!is_array($this->cookies)) |
|
| 655 | - $this->cookies = (array)$this->cookies; |
|
| 697 | + if (!is_array($this->cookies)) { |
|
| 698 | + $this->cookies = (array)$this->cookies; |
|
| 699 | + } |
|
| 656 | 700 | |
| 657 | 701 | reset($this->cookies); |
| 658 | 702 | if (count($this->cookies) > 0) { |
@@ -664,32 +708,39 @@ discard block |
||
| 664 | 708 | } |
| 665 | 709 | } |
| 666 | 710 | if (!empty($this->rawheaders)) { |
| 667 | - if (!is_array($this->rawheaders)) |
|
| 668 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 669 | - while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 670 | - $headers .= $headerKey . ": " . $headerVal . "\r\n"; |
|
| 711 | + if (!is_array($this->rawheaders)) { |
|
| 712 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 713 | + } |
|
| 714 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) { |
|
| 715 | + $headers .= $headerKey . ": " . $headerVal . "\r\n"; |
|
| 716 | + } |
|
| 671 | 717 | } |
| 672 | 718 | if (!empty($content_type)) { |
| 673 | 719 | $headers .= "Content-type: $content_type"; |
| 674 | - if ($content_type == "multipart/form-data") |
|
| 675 | - $headers .= "; boundary=" . $this->_mime_boundary; |
|
| 720 | + if ($content_type == "multipart/form-data") { |
|
| 721 | + $headers .= "; boundary=" . $this->_mime_boundary; |
|
| 722 | + } |
|
| 676 | 723 | $headers .= "\r\n"; |
| 677 | 724 | } |
| 678 | - if (!empty($body)) |
|
| 679 | - $headers .= "Content-length: " . strlen($body) . "\r\n"; |
|
| 680 | - if (!empty($this->user) || !empty($this->pass)) |
|
| 681 | - $headers .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->pass) . "\r\n"; |
|
| 725 | + if (!empty($body)) { |
|
| 726 | + $headers .= "Content-length: " . strlen($body) . "\r\n"; |
|
| 727 | + } |
|
| 728 | + if (!empty($this->user) || !empty($this->pass)) { |
|
| 729 | + $headers .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->pass) . "\r\n"; |
|
| 730 | + } |
|
| 682 | 731 | |
| 683 | 732 | //add proxy auth headers |
| 684 | - if (!empty($this->proxy_user)) |
|
| 685 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; |
|
| 733 | + if (!empty($this->proxy_user)) { |
|
| 734 | + $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; |
|
| 735 | + } |
|
| 686 | 736 | |
| 687 | 737 | |
| 688 | 738 | $headers .= "\r\n"; |
| 689 | 739 | |
| 690 | 740 | // set the read timeout if needed |
| 691 | - if ($this->read_timeout > 0) |
|
| 692 | - socket_set_timeout($fp, $this->read_timeout); |
|
| 741 | + if ($this->read_timeout > 0) { |
|
| 742 | + socket_set_timeout($fp, $this->read_timeout); |
|
| 743 | + } |
|
| 693 | 744 | $this->timed_out = false; |
| 694 | 745 | |
| 695 | 746 | fwrite($fp, $headers . $body, strlen($headers . $body)); |
@@ -706,8 +757,9 @@ discard block |
||
| 706 | 757 | return false; |
| 707 | 758 | } |
| 708 | 759 | |
| 709 | - if ($currentHeader == "\r\n") |
|
| 710 | - break; |
|
| 760 | + if ($currentHeader == "\r\n") { |
|
| 761 | + break; |
|
| 762 | + } |
|
| 711 | 763 | |
| 712 | 764 | // if a header begins with Location: or URI:, set the redirect |
| 713 | 765 | if (preg_match("/^(Location:|URI:)/i", $currentHeader)) { |
@@ -718,12 +770,14 @@ discard block |
||
| 718 | 770 | // no host in the path, so prepend |
| 719 | 771 | $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port; |
| 720 | 772 | // eliminate double slash |
| 721 | - if (!preg_match("|^/|", $matches[2])) |
|
| 722 | - $this->_redirectaddr .= "/" . $matches[2]; |
|
| 723 | - else |
|
| 724 | - $this->_redirectaddr .= $matches[2]; |
|
| 725 | - } else |
|
| 726 | - $this->_redirectaddr = $matches[2]; |
|
| 773 | + if (!preg_match("|^/|", $matches[2])) { |
|
| 774 | + $this->_redirectaddr .= "/" . $matches[2]; |
|
| 775 | + } else { |
|
| 776 | + $this->_redirectaddr .= $matches[2]; |
|
| 777 | + } |
|
| 778 | + } else { |
|
| 779 | + $this->_redirectaddr = $matches[2]; |
|
| 780 | + } |
|
| 727 | 781 | } |
| 728 | 782 | |
| 729 | 783 | if (preg_match("|^HTTP/|", $currentHeader)) { |
@@ -770,14 +824,17 @@ discard block |
||
| 770 | 824 | // have we hit our frame depth and is there frame src to fetch? |
| 771 | 825 | if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) { |
| 772 | 826 | $this->results[] = $results; |
| 773 | - for ($x = 0; $x < count($match[1]); $x++) |
|
| 774 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); |
|
| 827 | + for ($x = 0; $x < count($match[1]); $x++) { |
|
| 828 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); |
|
| 829 | + } |
|
| 775 | 830 | } // have we already fetched framed content? |
| 776 | - elseif (is_array($this->results)) |
|
| 777 | - $this->results[] = $results; |
|
| 831 | + elseif (is_array($this->results)) { |
|
| 832 | + $this->results[] = $results; |
|
| 833 | + } |
|
| 778 | 834 | // no framed content |
| 779 | - else |
|
| 780 | - $this->results = $results; |
|
| 835 | + else { |
|
| 836 | + $this->results = $results; |
|
| 837 | + } |
|
| 781 | 838 | |
| 782 | 839 | return $this; |
| 783 | 840 | } |
@@ -790,8 +847,9 @@ discard block |
||
| 790 | 847 | function setcookies() |
| 791 | 848 | { |
| 792 | 849 | for ($x = 0; $x < count($this->headers); $x++) { |
| 793 | - if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) |
|
| 794 | - $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 850 | + if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) { |
|
| 851 | + $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 852 | + } |
|
| 795 | 853 | } |
| 796 | 854 | return $this; |
| 797 | 855 | } |
@@ -852,10 +910,12 @@ discard block |
||
| 852 | 910 | 'disable_compression' => true, |
| 853 | 911 | ); |
| 854 | 912 | |
| 855 | - if (isset($this->cafile)) |
|
| 856 | - $context_opts['ssl']['cafile'] = $this->cafile; |
|
| 857 | - if (isset($this->capath)) |
|
| 858 | - $context_opts['ssl']['capath'] = $this->capath; |
|
| 913 | + if (isset($this->cafile)) { |
|
| 914 | + $context_opts['ssl']['cafile'] = $this->cafile; |
|
| 915 | + } |
|
| 916 | + if (isset($this->capath)) { |
|
| 917 | + $context_opts['ssl']['capath'] = $this->capath; |
|
| 918 | + } |
|
| 859 | 919 | } |
| 860 | 920 | |
| 861 | 921 | $host = 'ssl://' . $host; |
@@ -864,8 +924,9 @@ discard block |
||
| 864 | 924 | $context = stream_context_create($context_opts); |
| 865 | 925 | |
| 866 | 926 | if (version_compare(PHP_VERSION, '5.0.0', '>')) { |
| 867 | - if($this->scheme == 'http') |
|
| 868 | - $host = "tcp://" . $host; |
|
| 927 | + if($this->scheme == 'http') { |
|
| 928 | + $host = "tcp://" . $host; |
|
| 929 | + } |
|
| 869 | 930 | $fp = stream_socket_client( |
| 870 | 931 | "$host:$port", |
| 871 | 932 | $errno, |
@@ -929,8 +990,9 @@ discard block |
||
| 929 | 990 | settype($formfiles, "array"); |
| 930 | 991 | $postdata = ''; |
| 931 | 992 | |
| 932 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
| 933 | - return; |
|
| 993 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
| 994 | + return; |
|
| 995 | + } |
|
| 934 | 996 | |
| 935 | 997 | switch ($this->_submit_type) { |
| 936 | 998 | case "application/x-www-form-urlencoded": |
@@ -940,8 +1002,9 @@ discard block |
||
| 940 | 1002 | while (list($cur_key, $cur_val) = each($val)) { |
| 941 | 1003 | $postdata .= urlencode($key) . "[]=" . urlencode($cur_val) . "&"; |
| 942 | 1004 | } |
| 943 | - } else |
|
| 944 | - $postdata .= urlencode($key) . "=" . urlencode($val) . "&"; |
|
| 1005 | + } else { |
|
| 1006 | + $postdata .= urlencode($key) . "=" . urlencode($val) . "&"; |
|
| 1007 | + } |
|
| 945 | 1008 | } |
| 946 | 1009 | break; |
| 947 | 1010 | |
@@ -967,7 +1030,9 @@ discard block |
||
| 967 | 1030 | while (list($field_name, $file_names) = each($formfiles)) { |
| 968 | 1031 | settype($file_names, "array"); |
| 969 | 1032 | while (list(, $file_name) = each($file_names)) { |
| 970 | - if (!is_readable($file_name)) continue; |
|
| 1033 | + if (!is_readable($file_name)) { |
|
| 1034 | + continue; |
|
| 1035 | + } |
|
| 971 | 1036 | |
| 972 | 1037 | $fp = fopen($file_name, "r"); |
| 973 | 1038 | $file_content = fread($fp, filesize($file_name)); |
@@ -48,6 +48,9 @@ discard block |
||
| 48 | 48 | Input: url from wich the rss file was fetched |
| 49 | 49 | Output: true on sucess |
| 50 | 50 | \*=======================================================================*/ |
| 51 | + /** |
|
| 52 | + * @param string $url |
|
| 53 | + */ |
|
| 51 | 54 | function set ($url, $rss) { |
| 52 | 55 | $this->ERROR = ""; |
| 53 | 56 | $cache_file = $this->file_name( $url ); |
@@ -74,6 +77,9 @@ discard block |
||
| 74 | 77 | Input: url from wich the rss file was fetched |
| 75 | 78 | Output: cached object on HIT, false on MISS |
| 76 | 79 | \*=======================================================================*/ |
| 80 | + /** |
|
| 81 | + * @param string $url |
|
| 82 | + */ |
|
| 77 | 83 | function get ($url) { |
| 78 | 84 | $this->ERROR = ""; |
| 79 | 85 | $cache_file = $this->file_name( $url ); |
@@ -110,6 +116,9 @@ discard block |
||
| 110 | 116 | Input: url from wich the rss file was fetched |
| 111 | 117 | Output: cached object on HIT, false on MISS |
| 112 | 118 | \*=======================================================================*/ |
| 119 | + /** |
|
| 120 | + * @param string $url |
|
| 121 | + */ |
|
| 113 | 122 | function check_cache ( $url ) { |
| 114 | 123 | $this->ERROR = ""; |
| 115 | 124 | $filename = $this->file_name( $url ); |
@@ -156,6 +165,9 @@ discard block |
||
| 156 | 165 | /*=======================================================================*\ |
| 157 | 166 | Function: unserialize |
| 158 | 167 | \*=======================================================================*/ |
| 168 | + /** |
|
| 169 | + * @param string $data |
|
| 170 | + */ |
|
| 159 | 171 | function unserialize ( $data ) { |
| 160 | 172 | return unserialize( $data ); |
| 161 | 173 | } |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | if ($filesize = filesize($cache_file) ) { |
| 97 | - $data = fread( $fp, filesize($cache_file) ); |
|
| 98 | - $rss = $this->unserialize( $data ); |
|
| 97 | + $data = fread( $fp, filesize($cache_file) ); |
|
| 98 | + $rss = $this->unserialize( $data ); |
|
| 99 | 99 | |
| 100 | - return $rss; |
|
| 101 | - } |
|
| 100 | + return $rss; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return 0; |
|
| 103 | + return 0; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /*=======================================================================*\ |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - function cache_age( $cache_key ) { |
|
| 138 | - $filename = $this->file_name( $url ); |
|
| 139 | - if ( file_exists( $filename ) ) { |
|
| 140 | - $mtime = filemtime( $filename ); |
|
| 137 | + function cache_age( $cache_key ) { |
|
| 138 | + $filename = $this->file_name( $url ); |
|
| 139 | + if ( file_exists( $filename ) ) { |
|
| 140 | + $mtime = filemtime( $filename ); |
|
| 141 | 141 | $age = time() - $mtime; |
| 142 | - return $age; |
|
| 143 | - } |
|
| 144 | - else { |
|
| 145 | - return -1; |
|
| 146 | - } |
|
| 147 | - } |
|
| 142 | + return $age; |
|
| 143 | + } |
|
| 144 | + else { |
|
| 145 | + return -1; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | /*=======================================================================*\ |
| 150 | 150 | Function: serialize |
@@ -16,27 +16,27 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -class RSSCache { |
|
| 20 | - var $BASE_CACHE = './cache'; // where the cache files are stored |
|
| 21 | - var $MAX_AGE = 3600; // when are files stale, default one hour |
|
| 22 | - var $ERROR = ""; // accumulate error messages |
|
| 19 | +class RSSCache{ |
|
| 20 | + var $BASE_CACHE = './cache'; // where the cache files are stored |
|
| 21 | + var $MAX_AGE = 3600; // when are files stale, default one hour |
|
| 22 | + var $ERROR = ""; // accumulate error messages |
|
| 23 | 23 | |
| 24 | - function __construct($base='', $age='') { |
|
| 25 | - if ( $base ) { |
|
| 24 | + function __construct($base = '', $age = ''){ |
|
| 25 | + if ($base) { |
|
| 26 | 26 | $this->BASE_CACHE = $base; |
| 27 | 27 | } |
| 28 | - if ( $age ) { |
|
| 28 | + if ($age) { |
|
| 29 | 29 | $this->MAX_AGE = $age; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // attempt to make the cache directory |
| 33 | - if ( ! file_exists( $this->BASE_CACHE ) ) { |
|
| 34 | - $status = @mkdir( $this->BASE_CACHE, 0755 ); |
|
| 33 | + if (!file_exists($this->BASE_CACHE)) { |
|
| 34 | + $status = @mkdir($this->BASE_CACHE, 0755); |
|
| 35 | 35 | |
| 36 | 36 | // if make failed |
| 37 | - if ( ! $status ) { |
|
| 37 | + if (!$status) { |
|
| 38 | 38 | $this->error( |
| 39 | - "Cache couldn't make dir '" . $this->BASE_CACHE . "'." |
|
| 39 | + "Cache couldn't make dir '".$this->BASE_CACHE."'." |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -48,12 +48,12 @@ discard block |
||
| 48 | 48 | Input: url from wich the rss file was fetched |
| 49 | 49 | Output: true on sucess |
| 50 | 50 | \*=======================================================================*/ |
| 51 | - function set ($url, $rss) { |
|
| 51 | + function set($url, $rss){ |
|
| 52 | 52 | $this->ERROR = ""; |
| 53 | - $cache_file = $this->file_name( $url ); |
|
| 54 | - $fp = @fopen( $cache_file, 'w' ); |
|
| 53 | + $cache_file = $this->file_name($url); |
|
| 54 | + $fp = @fopen($cache_file, 'w'); |
|
| 55 | 55 | |
| 56 | - if ( ! $fp ) { |
|
| 56 | + if (!$fp) { |
|
| 57 | 57 | $this->error( |
| 58 | 58 | "Cache unable to open file for writing: $cache_file" |
| 59 | 59 | ); |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - $data = $this->serialize( $rss ); |
|
| 65 | - fwrite( $fp, $data ); |
|
| 66 | - fclose( $fp ); |
|
| 64 | + $data = $this->serialize($rss); |
|
| 65 | + fwrite($fp, $data); |
|
| 66 | + fclose($fp); |
|
| 67 | 67 | |
| 68 | 68 | return $cache_file; |
| 69 | 69 | } |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | Input: url from wich the rss file was fetched |
| 75 | 75 | Output: cached object on HIT, false on MISS |
| 76 | 76 | \*=======================================================================*/ |
| 77 | - function get ($url) { |
|
| 77 | + function get($url){ |
|
| 78 | 78 | $this->ERROR = ""; |
| 79 | - $cache_file = $this->file_name( $url ); |
|
| 79 | + $cache_file = $this->file_name($url); |
|
| 80 | 80 | |
| 81 | - if ( ! file_exists( $cache_file ) ) { |
|
| 81 | + if (!file_exists($cache_file)) { |
|
| 82 | 82 | $this->debug( |
| 83 | 83 | "Cache doesn't contain: $url (cache file: $cache_file)" |
| 84 | 84 | ); |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $fp = @fopen($cache_file, 'r'); |
| 89 | - if ( ! $fp ) { |
|
| 89 | + if (!$fp) { |
|
| 90 | 90 | $this->error( |
| 91 | 91 | "Failed to open cache file for reading: $cache_file" |
| 92 | 92 | ); |
| 93 | 93 | return 0; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ($filesize = filesize($cache_file) ) { |
|
| 97 | - $data = fread( $fp, filesize($cache_file) ); |
|
| 98 | - $rss = $this->unserialize( $data ); |
|
| 96 | + if ($filesize = filesize($cache_file)) { |
|
| 97 | + $data = fread($fp, filesize($cache_file)); |
|
| 98 | + $rss = $this->unserialize($data); |
|
| 99 | 99 | |
| 100 | 100 | return $rss; |
| 101 | 101 | } |
@@ -110,16 +110,16 @@ discard block |
||
| 110 | 110 | Input: url from wich the rss file was fetched |
| 111 | 111 | Output: cached object on HIT, false on MISS |
| 112 | 112 | \*=======================================================================*/ |
| 113 | - function check_cache ( $url ) { |
|
| 113 | + function check_cache($url){ |
|
| 114 | 114 | $this->ERROR = ""; |
| 115 | - $filename = $this->file_name( $url ); |
|
| 115 | + $filename = $this->file_name($url); |
|
| 116 | 116 | |
| 117 | - if ( file_exists( $filename ) ) { |
|
| 117 | + if (file_exists($filename)) { |
|
| 118 | 118 | // find how long ago the file was added to the cache |
| 119 | 119 | // and whether that is longer then MAX_AGE |
| 120 | - $mtime = filemtime( $filename ); |
|
| 120 | + $mtime = filemtime($filename); |
|
| 121 | 121 | $age = time() - $mtime; |
| 122 | - if ( $this->MAX_AGE > $age ) { |
|
| 122 | + if ($this->MAX_AGE > $age) { |
|
| 123 | 123 | // object exists and is current |
| 124 | 124 | return 'HIT'; |
| 125 | 125 | } |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - function cache_age( $cache_key ) { |
|
| 138 | - $filename = $this->file_name( $url ); |
|
| 139 | - if ( file_exists( $filename ) ) { |
|
| 140 | - $mtime = filemtime( $filename ); |
|
| 137 | + function cache_age($cache_key){ |
|
| 138 | + $filename = $this->file_name($url); |
|
| 139 | + if (file_exists($filename)) { |
|
| 140 | + $mtime = filemtime($filename); |
|
| 141 | 141 | $age = time() - $mtime; |
| 142 | 142 | return $age; |
| 143 | 143 | } |
@@ -149,15 +149,15 @@ discard block |
||
| 149 | 149 | /*=======================================================================*\ |
| 150 | 150 | Function: serialize |
| 151 | 151 | \*=======================================================================*/ |
| 152 | - function serialize ( $rss ) { |
|
| 153 | - return serialize( $rss ); |
|
| 152 | + function serialize($rss){ |
|
| 153 | + return serialize($rss); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /*=======================================================================*\ |
| 157 | 157 | Function: unserialize |
| 158 | 158 | \*=======================================================================*/ |
| 159 | - function unserialize ( $data ) { |
|
| 160 | - return unserialize( $data ); |
|
| 159 | + function unserialize($data){ |
|
| 160 | + return unserialize($data); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /*=======================================================================*\ |
@@ -166,31 +166,31 @@ discard block |
||
| 166 | 166 | Input: url from wich the rss file was fetched |
| 167 | 167 | Output: a file name |
| 168 | 168 | \*=======================================================================*/ |
| 169 | - function file_name ($url) { |
|
| 170 | - $filename = md5( $url ); |
|
| 171 | - return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); |
|
| 169 | + function file_name($url){ |
|
| 170 | + $filename = md5($url); |
|
| 171 | + return join(DIRECTORY_SEPARATOR, array($this->BASE_CACHE, $filename)); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /*=======================================================================*\ |
| 175 | 175 | Function: error |
| 176 | 176 | Purpose: register error |
| 177 | 177 | \*=======================================================================*/ |
| 178 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 178 | + function error($errormsg, $lvl = E_USER_WARNING){ |
|
| 179 | 179 | // append PHP's error message if track_errors enabled |
| 180 | - if ( isset($php_errormsg) ) { |
|
| 180 | + if (isset($php_errormsg)) { |
|
| 181 | 181 | $errormsg .= " ($php_errormsg)"; |
| 182 | 182 | } |
| 183 | 183 | $this->ERROR = $errormsg; |
| 184 | - if ( MAGPIE_DEBUG ) { |
|
| 185 | - trigger_error( $errormsg, $lvl); |
|
| 184 | + if (MAGPIE_DEBUG) { |
|
| 185 | + trigger_error($errormsg, $lvl); |
|
| 186 | 186 | } |
| 187 | 187 | else { |
| 188 | - error_log( $errormsg, 0); |
|
| 188 | + error_log($errormsg, 0); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
| 193 | - if ( MAGPIE_DEBUG ) { |
|
| 192 | + function debug($debugmsg, $lvl = E_USER_NOTICE){ |
|
| 193 | + if (MAGPIE_DEBUG) { |
|
| 194 | 194 | $this->error("MagpieRSS [debug] $debugmsg", $lvl); |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -16,12 +16,14 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -class RSSCache { |
|
| 19 | +class RSSCache |
|
| 20 | +{ |
|
| 20 | 21 | var $BASE_CACHE = './cache'; // where the cache files are stored |
| 21 | 22 | var $MAX_AGE = 3600; // when are files stale, default one hour |
| 22 | 23 | var $ERROR = ""; // accumulate error messages |
| 23 | 24 | |
| 24 | - function __construct($base='', $age='') { |
|
| 25 | + function __construct($base='', $age='') |
|
| 26 | + { |
|
| 25 | 27 | if ( $base ) { |
| 26 | 28 | $this->BASE_CACHE = $base; |
| 27 | 29 | } |
@@ -48,7 +50,8 @@ discard block |
||
| 48 | 50 | Input: url from wich the rss file was fetched |
| 49 | 51 | Output: true on sucess |
| 50 | 52 | \*=======================================================================*/ |
| 51 | - function set ($url, $rss) { |
|
| 53 | + function set ($url, $rss) |
|
| 54 | + { |
|
| 52 | 55 | $this->ERROR = ""; |
| 53 | 56 | $cache_file = $this->file_name( $url ); |
| 54 | 57 | $fp = @fopen( $cache_file, 'w' ); |
@@ -74,7 +77,8 @@ discard block |
||
| 74 | 77 | Input: url from wich the rss file was fetched |
| 75 | 78 | Output: cached object on HIT, false on MISS |
| 76 | 79 | \*=======================================================================*/ |
| 77 | - function get ($url) { |
|
| 80 | + function get ($url) |
|
| 81 | + { |
|
| 78 | 82 | $this->ERROR = ""; |
| 79 | 83 | $cache_file = $this->file_name( $url ); |
| 80 | 84 | |
@@ -110,7 +114,8 @@ discard block |
||
| 110 | 114 | Input: url from wich the rss file was fetched |
| 111 | 115 | Output: cached object on HIT, false on MISS |
| 112 | 116 | \*=======================================================================*/ |
| 113 | - function check_cache ( $url ) { |
|
| 117 | + function check_cache ( $url ) |
|
| 118 | + { |
|
| 114 | 119 | $this->ERROR = ""; |
| 115 | 120 | $filename = $this->file_name( $url ); |
| 116 | 121 | |
@@ -122,26 +127,24 @@ discard block |
||
| 122 | 127 | if ( $this->MAX_AGE > $age ) { |
| 123 | 128 | // object exists and is current |
| 124 | 129 | return 'HIT'; |
| 125 | - } |
|
| 126 | - else { |
|
| 130 | + } else { |
|
| 127 | 131 | // object exists but is old |
| 128 | 132 | return 'STALE'; |
| 129 | 133 | } |
| 130 | - } |
|
| 131 | - else { |
|
| 134 | + } else { |
|
| 132 | 135 | // object does not exist |
| 133 | 136 | return 'MISS'; |
| 134 | 137 | } |
| 135 | 138 | } |
| 136 | 139 | |
| 137 | - function cache_age( $cache_key ) { |
|
| 140 | + function cache_age( $cache_key ) |
|
| 141 | + { |
|
| 138 | 142 | $filename = $this->file_name( $url ); |
| 139 | 143 | if ( file_exists( $filename ) ) { |
| 140 | 144 | $mtime = filemtime( $filename ); |
| 141 | 145 | $age = time() - $mtime; |
| 142 | 146 | return $age; |
| 143 | - } |
|
| 144 | - else { |
|
| 147 | + } else { |
|
| 145 | 148 | return -1; |
| 146 | 149 | } |
| 147 | 150 | } |
@@ -149,14 +152,16 @@ discard block |
||
| 149 | 152 | /*=======================================================================*\ |
| 150 | 153 | Function: serialize |
| 151 | 154 | \*=======================================================================*/ |
| 152 | - function serialize ( $rss ) { |
|
| 155 | + function serialize ( $rss ) |
|
| 156 | + { |
|
| 153 | 157 | return serialize( $rss ); |
| 154 | 158 | } |
| 155 | 159 | |
| 156 | 160 | /*=======================================================================*\ |
| 157 | 161 | Function: unserialize |
| 158 | 162 | \*=======================================================================*/ |
| 159 | - function unserialize ( $data ) { |
|
| 163 | + function unserialize ( $data ) |
|
| 164 | + { |
|
| 160 | 165 | return unserialize( $data ); |
| 161 | 166 | } |
| 162 | 167 | |
@@ -166,7 +171,8 @@ discard block |
||
| 166 | 171 | Input: url from wich the rss file was fetched |
| 167 | 172 | Output: a file name |
| 168 | 173 | \*=======================================================================*/ |
| 169 | - function file_name ($url) { |
|
| 174 | + function file_name ($url) |
|
| 175 | + { |
|
| 170 | 176 | $filename = md5( $url ); |
| 171 | 177 | return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); |
| 172 | 178 | } |
@@ -175,21 +181,22 @@ discard block |
||
| 175 | 181 | Function: error |
| 176 | 182 | Purpose: register error |
| 177 | 183 | \*=======================================================================*/ |
| 178 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 184 | + function error ($errormsg, $lvl=E_USER_WARNING) |
|
| 185 | + { |
|
| 179 | 186 | // append PHP's error message if track_errors enabled |
| 180 | - if ( isset($php_errormsg) ) { |
|
| 187 | + if ( isset($php_errormsg) ) { |
|
| 181 | 188 | $errormsg .= " ($php_errormsg)"; |
| 182 | 189 | } |
| 183 | 190 | $this->ERROR = $errormsg; |
| 184 | 191 | if ( MAGPIE_DEBUG ) { |
| 185 | 192 | trigger_error( $errormsg, $lvl); |
| 186 | - } |
|
| 187 | - else { |
|
| 193 | + } else { |
|
| 188 | 194 | error_log( $errormsg, 0); |
| 189 | 195 | } |
| 190 | 196 | } |
| 191 | 197 | |
| 192 | - function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
| 198 | + function debug ($debugmsg, $lvl=E_USER_NOTICE) |
|
| 199 | + { |
|
| 193 | 200 | if ( MAGPIE_DEBUG ) { |
| 194 | 201 | $this->error("MagpieRSS [debug] $debugmsg", $lvl); |
| 195 | 202 | } |
@@ -243,6 +243,9 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | +/** |
|
| 247 | + * @param integer $lvl |
|
| 248 | + */ |
|
| 246 | 249 | function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
| 247 | 250 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
| 248 | 251 | } |
@@ -289,6 +292,9 @@ discard block |
||
| 289 | 292 | Input: an HTTP response object (see Snoopy) |
| 290 | 293 | Output: parsed RSS object (see rss_parse) |
| 291 | 294 | \*=======================================================================*/ |
| 295 | +/** |
|
| 296 | + * @param Snoopy $resp |
|
| 297 | + */ |
|
| 292 | 298 | function _response_to_rss ($resp) { |
| 293 | 299 | $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
| 294 | 300 | |
@@ -166,7 +166,7 @@ |
||
| 166 | 166 | $resp = _fetch_remote_file( $url, $request_headers ); |
| 167 | 167 | |
| 168 | 168 | if (isset($resp) and $resp) { |
| 169 | - if ($resp->status == '304' ) { |
|
| 169 | + if ($resp->status == '304' ) { |
|
| 170 | 170 | // we have the most current copy |
| 171 | 171 | if ( MAGPIE_DEBUG > 1) { |
| 172 | 172 | debug("Got 304 for $url"); |
@@ -24,19 +24,19 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('MAGPIE_DIR')) { |
| 27 | - define('MAGPIE_DIR', dirname(__FILE__) . DIR_SEP); |
|
| 27 | + define('MAGPIE_DIR', dirname(__FILE__).DIR_SEP); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | if (!defined('MAGPIE_CACHE_DIR')) { |
| 31 | - define('MAGPIE_CACHE_DIR', MODX_BASE_PATH . 'assets/cache/rss'); |
|
| 31 | + define('MAGPIE_CACHE_DIR', MODX_BASE_PATH.'assets/cache/rss'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | -require_once( MAGPIE_DIR . 'rss_parse.inc' ); |
|
| 35 | -require_once( MAGPIE_DIR . 'rss_cache.inc' ); |
|
| 34 | +require_once(MAGPIE_DIR.'rss_parse.inc'); |
|
| 35 | +require_once(MAGPIE_DIR.'rss_cache.inc'); |
|
| 36 | 36 | |
| 37 | 37 | // for including 3rd party libraries |
| 38 | -define('MAGPIE_EXTLIB', MAGPIE_DIR . 'extlib' . DIR_SEP); |
|
| 39 | -require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc'); |
|
| 38 | +define('MAGPIE_EXTLIB', MAGPIE_DIR.'extlib'.DIR_SEP); |
|
| 39 | +require_once(MAGPIE_EXTLIB.'Snoopy.class.inc'); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /* |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $MAGPIE_ERROR = ""; |
| 91 | 91 | |
| 92 | -function fetch_rss ($url) { |
|
| 92 | +function fetch_rss($url){ |
|
| 93 | 93 | // initialize constants |
| 94 | 94 | init(); |
| 95 | 95 | |
| 96 | - if ( !isset($url) ) { |
|
| 96 | + if (!isset($url)) { |
|
| 97 | 97 | error("fetch_rss called without a url"); |
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // if cache is disabled |
| 102 | - if ( !MAGPIE_CACHE_ON ) { |
|
| 102 | + if (!MAGPIE_CACHE_ON) { |
|
| 103 | 103 | // fetch file, and parse it |
| 104 | - $resp = _fetch_remote_file( $url ); |
|
| 105 | - if ( is_success( $resp->status ) ) { |
|
| 106 | - return _response_to_rss( $resp ); |
|
| 104 | + $resp = _fetch_remote_file($url); |
|
| 105 | + if (is_success($resp->status)) { |
|
| 106 | + return _response_to_rss($resp); |
|
| 107 | 107 | } |
| 108 | 108 | else { |
| 109 | 109 | error("Failed to fetch $url and cache is off"); |
@@ -118,34 +118,34 @@ discard block |
||
| 118 | 118 | // 3. if cached obj fails freshness check, fetch remote |
| 119 | 119 | // 4. if remote fails, return stale object, or error |
| 120 | 120 | |
| 121 | - $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); |
|
| 121 | + $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE); |
|
| 122 | 122 | |
| 123 | 123 | if (MAGPIE_DEBUG and $cache->ERROR) { |
| 124 | 124 | debug($cache->ERROR, E_USER_WARNING); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - $cache_status = 0; // response of check_cache |
|
| 128 | + $cache_status = 0; // response of check_cache |
|
| 129 | 129 | $request_headers = array(); // HTTP headers to send with fetch |
| 130 | - $rss = 0; // parsed RSS object |
|
| 131 | - $errormsg = 0; // errors, if any |
|
| 130 | + $rss = 0; // parsed RSS object |
|
| 131 | + $errormsg = 0; // errors, if any |
|
| 132 | 132 | |
| 133 | 133 | // store parsed XML by desired output encoding |
| 134 | 134 | // as character munging happens at parse time |
| 135 | - $cache_key = $url . MAGPIE_OUTPUT_ENCODING; |
|
| 135 | + $cache_key = $url.MAGPIE_OUTPUT_ENCODING; |
|
| 136 | 136 | |
| 137 | 137 | if (!$cache->ERROR) { |
| 138 | 138 | // return cache HIT, MISS, or STALE |
| 139 | - $cache_status = $cache->check_cache( $cache_key); |
|
| 139 | + $cache_status = $cache->check_cache($cache_key); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // if object cached, and cache is fresh, return cached obj |
| 143 | - if ( $cache_status == 'HIT' ) { |
|
| 144 | - $rss = $cache->get( $cache_key ); |
|
| 145 | - if ( isset($rss) and $rss ) { |
|
| 143 | + if ($cache_status == 'HIT') { |
|
| 144 | + $rss = $cache->get($cache_key); |
|
| 145 | + if (isset($rss) and $rss) { |
|
| 146 | 146 | // should be cache age |
| 147 | 147 | $rss->from_cache = 1; |
| 148 | - if ( MAGPIE_DEBUG > 1) { |
|
| 148 | + if (MAGPIE_DEBUG > 1) { |
|
| 149 | 149 | debug("MagpieRSS: Cache HIT", E_USER_NOTICE); |
| 150 | 150 | } |
| 151 | 151 | return $rss; |
@@ -155,50 +155,50 @@ discard block |
||
| 155 | 155 | // else attempt a conditional get |
| 156 | 156 | |
| 157 | 157 | // setup headers |
| 158 | - if ( $cache_status == 'STALE' ) { |
|
| 159 | - $rss = $cache->get( $cache_key ); |
|
| 160 | - if ( $rss and $rss->etag and $rss->last_modified ) { |
|
| 158 | + if ($cache_status == 'STALE') { |
|
| 159 | + $rss = $cache->get($cache_key); |
|
| 160 | + if ($rss and $rss->etag and $rss->last_modified) { |
|
| 161 | 161 | $request_headers['If-None-Match'] = $rss->etag; |
| 162 | 162 | $request_headers['If-Last-Modified'] = $rss->last_modified; |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $resp = _fetch_remote_file( $url, $request_headers ); |
|
| 166 | + $resp = _fetch_remote_file($url, $request_headers); |
|
| 167 | 167 | |
| 168 | 168 | if (isset($resp) and $resp) { |
| 169 | - if ($resp->status == '304' ) { |
|
| 169 | + if ($resp->status == '304') { |
|
| 170 | 170 | // we have the most current copy |
| 171 | - if ( MAGPIE_DEBUG > 1) { |
|
| 171 | + if (MAGPIE_DEBUG > 1) { |
|
| 172 | 172 | debug("Got 304 for $url"); |
| 173 | 173 | } |
| 174 | 174 | // reset cache on 304 (at minutillo insistent prodding) |
| 175 | 175 | $cache->set($cache_key, $rss); |
| 176 | 176 | return $rss; |
| 177 | 177 | } |
| 178 | - elseif ( is_success( $resp->status ) ) { |
|
| 179 | - $rss = _response_to_rss( $resp ); |
|
| 180 | - if ( $rss ) { |
|
| 178 | + elseif (is_success($resp->status)) { |
|
| 179 | + $rss = _response_to_rss($resp); |
|
| 180 | + if ($rss) { |
|
| 181 | 181 | if (MAGPIE_DEBUG > 1) { |
| 182 | 182 | debug("Fetch successful"); |
| 183 | 183 | } |
| 184 | 184 | // add object to cache |
| 185 | - $cache->set( $cache_key, $rss ); |
|
| 185 | + $cache->set($cache_key, $rss); |
|
| 186 | 186 | return $rss; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | else { |
| 190 | 190 | $errormsg = "Failed to fetch $url "; |
| 191 | - if ( $resp->status == '-100' ) { |
|
| 192 | - $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
|
| 191 | + if ($resp->status == '-100') { |
|
| 192 | + $errormsg .= "(Request timed out after ".MAGPIE_FETCH_TIME_OUT." seconds)"; |
|
| 193 | 193 | } |
| 194 | - elseif ( $resp->error ) { |
|
| 194 | + elseif ($resp->error) { |
|
| 195 | 195 | # compensate for Snoopy's annoying habbit to tacking |
| 196 | 196 | # on '\n' |
| 197 | 197 | $http_error = substr($resp->error, 0, -2); |
| 198 | 198 | $errormsg .= "(HTTP Error: $http_error)"; |
| 199 | 199 | } |
| 200 | 200 | else { |
| 201 | - $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
|
| 201 | + $errormsg .= "(HTTP Response: ".$resp->response_code.')'; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -210,14 +210,14 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | // attempt to return cached object |
| 212 | 212 | if ($rss) { |
| 213 | - if ( MAGPIE_DEBUG ) { |
|
| 213 | + if (MAGPIE_DEBUG) { |
|
| 214 | 214 | debug("Returning STALE object for $url"); |
| 215 | 215 | } |
| 216 | 216 | return $rss; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | // else we totally failed |
| 220 | - error( $errormsg ); |
|
| 220 | + error($errormsg); |
|
| 221 | 221 | |
| 222 | 222 | return false; |
| 223 | 223 | |
@@ -229,21 +229,21 @@ discard block |
||
| 229 | 229 | Purpose: set MAGPIE_ERROR, and trigger error |
| 230 | 230 | \*=======================================================================*/ |
| 231 | 231 | |
| 232 | -function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 232 | +function error($errormsg, $lvl = E_USER_WARNING){ |
|
| 233 | 233 | global $MAGPIE_ERROR; |
| 234 | 234 | |
| 235 | 235 | // append PHP's error message if track_errors enabled |
| 236 | - if ( isset($php_errormsg) ) { |
|
| 236 | + if (isset($php_errormsg)) { |
|
| 237 | 237 | $errormsg .= " ($php_errormsg)"; |
| 238 | 238 | } |
| 239 | - if ( $errormsg ) { |
|
| 239 | + if ($errormsg) { |
|
| 240 | 240 | $errormsg = "MagpieRSS: $errormsg"; |
| 241 | 241 | $MAGPIE_ERROR = $errormsg; |
| 242 | - trigger_error( $errormsg, $lvl); |
|
| 242 | + trigger_error($errormsg, $lvl); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | -function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
| 246 | +function debug($debugmsg, $lvl = E_USER_NOTICE){ |
|
| 247 | 247 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
| 248 | 248 | } |
| 249 | 249 | |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | Function: magpie_error |
| 252 | 252 | Purpose: accessor for the magpie error variable |
| 253 | 253 | \*=======================================================================*/ |
| 254 | -function magpie_error ($errormsg="") { |
|
| 254 | +function magpie_error($errormsg = ""){ |
|
| 255 | 255 | global $MAGPIE_ERROR; |
| 256 | 256 | |
| 257 | - if ( isset($errormsg) and $errormsg ) { |
|
| 257 | + if (isset($errormsg) and $errormsg) { |
|
| 258 | 258 | $MAGPIE_ERROR = $errormsg; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -268,13 +268,13 @@ discard block |
||
| 268 | 268 | headers to send along with the request (optional) |
| 269 | 269 | Output: an HTTP response object (see Snoopy.class.inc) |
| 270 | 270 | \*=======================================================================*/ |
| 271 | -function _fetch_remote_file ($url, $headers = "" ) { |
|
| 271 | +function _fetch_remote_file($url, $headers = ""){ |
|
| 272 | 272 | // Snoopy is an HTTP client in PHP |
| 273 | 273 | $client = new Snoopy(); |
| 274 | 274 | $client->agent = MAGPIE_USER_AGENT; |
| 275 | 275 | $client->read_timeout = MAGPIE_FETCH_TIME_OUT; |
| 276 | 276 | $client->use_gzip = MAGPIE_USE_GZIP; |
| 277 | - if (is_array($headers) ) { |
|
| 277 | + if (is_array($headers)) { |
|
| 278 | 278 | $client->rawheaders = $headers; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | Input: an HTTP response object (see Snoopy) |
| 290 | 290 | Output: parsed RSS object (see rss_parse) |
| 291 | 291 | \*=======================================================================*/ |
| 292 | -function _response_to_rss ($resp) { |
|
| 293 | - $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
|
| 292 | +function _response_to_rss($resp){ |
|
| 293 | + $rss = new MagpieRSS($resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING); |
|
| 294 | 294 | |
| 295 | 295 | // if RSS parsed successfully |
| 296 | - if ( $rss and !$rss->ERROR) { |
|
| 296 | + if ($rss and !$rss->ERROR) { |
|
| 297 | 297 | |
| 298 | 298 | // find Etag, and Last-Modified |
| 299 | - foreach($resp->headers as $h) { |
|
| 299 | + foreach ($resp->headers as $h) { |
|
| 300 | 300 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
| 301 | 301 | if (strpos($h, ": ")) { |
| 302 | 302 | list($field, $val) = explode(": ", $h, 2); |
@@ -306,11 +306,11 @@ discard block |
||
| 306 | 306 | $val = ""; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( $field == 'ETag' ) { |
|
| 309 | + if ($field == 'ETag') { |
|
| 310 | 310 | $rss->etag = $val; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if ( $field == 'Last-Modified' ) { |
|
| 313 | + if ($field == 'Last-Modified') { |
|
| 314 | 314 | $rss->last_modified = $val; |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $errormsg = "Failed to parse RSS file."; |
| 322 | 322 | |
| 323 | 323 | if ($rss) { |
| 324 | - $errormsg .= " (" . $rss->ERROR . ")"; |
|
| 324 | + $errormsg .= " (".$rss->ERROR.")"; |
|
| 325 | 325 | } |
| 326 | 326 | error($errormsg); |
| 327 | 327 | |
@@ -334,67 +334,67 @@ discard block |
||
| 334 | 334 | Purpose: setup constants with default values |
| 335 | 335 | check for user overrides |
| 336 | 336 | \*=======================================================================*/ |
| 337 | -function init () { |
|
| 338 | - if ( defined('MAGPIE_INITALIZED') ) { |
|
| 337 | +function init(){ |
|
| 338 | + if (defined('MAGPIE_INITALIZED')) { |
|
| 339 | 339 | return; |
| 340 | 340 | } |
| 341 | 341 | else { |
| 342 | 342 | define('MAGPIE_INITALIZED', true); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if ( !defined('MAGPIE_CACHE_ON') ) { |
|
| 345 | + if (!defined('MAGPIE_CACHE_ON')) { |
|
| 346 | 346 | define('MAGPIE_CACHE_ON', true); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - if ( !defined('MAGPIE_CACHE_DIR') ) { |
|
| 349 | + if (!defined('MAGPIE_CACHE_DIR')) { |
|
| 350 | 350 | define('MAGPIE_CACHE_DIR', './cache'); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( !defined('MAGPIE_CACHE_AGE') ) { |
|
| 354 | - define('MAGPIE_CACHE_AGE', 60*60); // one hour |
|
| 353 | + if (!defined('MAGPIE_CACHE_AGE')) { |
|
| 354 | + define('MAGPIE_CACHE_AGE', 60 * 60); // one hour |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { |
|
| 357 | + if (!defined('MAGPIE_CACHE_FRESH_ONLY')) { |
|
| 358 | 358 | define('MAGPIE_CACHE_FRESH_ONLY', false); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( !defined('MAGPIE_OUTPUT_ENCODING') ) { |
|
| 361 | + if (!defined('MAGPIE_OUTPUT_ENCODING')) { |
|
| 362 | 362 | global $modx_manager_charset; |
| 363 | - if(empty($modx_manager_charset)) $modx_manager_charset = 'ISO-8859-1'; |
|
| 363 | + if (empty($modx_manager_charset)) $modx_manager_charset = 'ISO-8859-1'; |
|
| 364 | 364 | define('MAGPIE_OUTPUT_ENCODING', $modx_manager_charset); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - if ( !defined('MAGPIE_INPUT_ENCODING') ) { |
|
| 367 | + if (!defined('MAGPIE_INPUT_ENCODING')) { |
|
| 368 | 368 | define('MAGPIE_INPUT_ENCODING', null); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if ( !defined('MAGPIE_DETECT_ENCODING') ) { |
|
| 371 | + if (!defined('MAGPIE_DETECT_ENCODING')) { |
|
| 372 | 372 | define('MAGPIE_DETECT_ENCODING', true); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( !defined('MAGPIE_DEBUG') ) { |
|
| 375 | + if (!defined('MAGPIE_DEBUG')) { |
|
| 376 | 376 | define('MAGPIE_DEBUG', 0); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( !defined('MAGPIE_USER_AGENT') ) { |
|
| 380 | - $ua = 'MagpieRSS/'. MAGPIE_VERSION . ' (+http://magpierss.sf.net'; |
|
| 379 | + if (!defined('MAGPIE_USER_AGENT')) { |
|
| 380 | + $ua = 'MagpieRSS/'.MAGPIE_VERSION.' (+http://magpierss.sf.net'; |
|
| 381 | 381 | |
| 382 | - if ( MAGPIE_CACHE_ON ) { |
|
| 383 | - $ua = $ua . ')'; |
|
| 382 | + if (MAGPIE_CACHE_ON) { |
|
| 383 | + $ua = $ua.')'; |
|
| 384 | 384 | } |
| 385 | 385 | else { |
| 386 | - $ua = $ua . '; No cache)'; |
|
| 386 | + $ua = $ua.'; No cache)'; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | define('MAGPIE_USER_AGENT', $ua); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ( !defined('MAGPIE_FETCH_TIME_OUT') ) { |
|
| 392 | + if (!defined('MAGPIE_FETCH_TIME_OUT')) { |
|
| 393 | 393 | define('MAGPIE_FETCH_TIME_OUT', 5); // 5 second timeout |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | // use gzip encoding to fetch rss files if supported? |
| 397 | - if ( !defined('MAGPIE_USE_GZIP') ) { |
|
| 397 | + if (!defined('MAGPIE_USE_GZIP')) { |
|
| 398 | 398 | define('MAGPIE_USE_GZIP', true); |
| 399 | 399 | } |
| 400 | 400 | } |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | Function: is_info |
| 418 | 418 | Purpose: return true if Informational status code |
| 419 | 419 | \*=======================================================================*/ |
| 420 | -function is_info ($sc) { |
|
| 420 | +function is_info($sc){ |
|
| 421 | 421 | return $sc >= 100 && $sc < 200; |
| 422 | 422 | } |
| 423 | 423 | |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | Function: is_success |
| 426 | 426 | Purpose: return true if Successful status code |
| 427 | 427 | \*=======================================================================*/ |
| 428 | -function is_success ($sc) { |
|
| 428 | +function is_success($sc){ |
|
| 429 | 429 | return $sc >= 200 && $sc < 300; |
| 430 | 430 | } |
| 431 | 431 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | Function: is_redirect |
| 434 | 434 | Purpose: return true if Redirection status code |
| 435 | 435 | \*=======================================================================*/ |
| 436 | -function is_redirect ($sc) { |
|
| 436 | +function is_redirect($sc){ |
|
| 437 | 437 | return $sc >= 300 && $sc < 400; |
| 438 | 438 | } |
| 439 | 439 | |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | Function: is_error |
| 442 | 442 | Purpose: return true if Error status code |
| 443 | 443 | \*=======================================================================*/ |
| 444 | -function is_error ($sc) { |
|
| 444 | +function is_error($sc){ |
|
| 445 | 445 | return $sc >= 400 && $sc < 600; |
| 446 | 446 | } |
| 447 | 447 | |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | Function: is_client_error |
| 450 | 450 | Purpose: return true if Error status code, and its a client error |
| 451 | 451 | \*=======================================================================*/ |
| 452 | -function is_client_error ($sc) { |
|
| 452 | +function is_client_error($sc){ |
|
| 453 | 453 | return $sc >= 400 && $sc < 500; |
| 454 | 454 | } |
| 455 | 455 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | Function: is_client_error |
| 458 | 458 | Purpose: return true if Error status code, and its a server error |
| 459 | 459 | \*=======================================================================*/ |
| 460 | -function is_server_error ($sc) { |
|
| 460 | +function is_server_error($sc){ |
|
| 461 | 461 | return $sc >= 500 && $sc < 600; |
| 462 | 462 | } |
| 463 | 463 | ?> |
@@ -89,7 +89,8 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $MAGPIE_ERROR = ""; |
| 91 | 91 | |
| 92 | -function fetch_rss ($url) { |
|
| 92 | +function fetch_rss ($url) |
|
| 93 | +{ |
|
| 93 | 94 | // initialize constants |
| 94 | 95 | init(); |
| 95 | 96 | |
@@ -104,8 +105,7 @@ discard block |
||
| 104 | 105 | $resp = _fetch_remote_file( $url ); |
| 105 | 106 | if ( is_success( $resp->status ) ) { |
| 106 | 107 | return _response_to_rss( $resp ); |
| 107 | - } |
|
| 108 | - else { |
|
| 108 | + } else { |
|
| 109 | 109 | error("Failed to fetch $url and cache is off"); |
| 110 | 110 | return false; |
| 111 | 111 | } |
@@ -174,8 +174,7 @@ discard block |
||
| 174 | 174 | // reset cache on 304 (at minutillo insistent prodding) |
| 175 | 175 | $cache->set($cache_key, $rss); |
| 176 | 176 | return $rss; |
| 177 | - } |
|
| 178 | - elseif ( is_success( $resp->status ) ) { |
|
| 177 | + } elseif ( is_success( $resp->status ) ) { |
|
| 179 | 178 | $rss = _response_to_rss( $resp ); |
| 180 | 179 | if ( $rss ) { |
| 181 | 180 | if (MAGPIE_DEBUG > 1) { |
@@ -185,24 +184,20 @@ discard block |
||
| 185 | 184 | $cache->set( $cache_key, $rss ); |
| 186 | 185 | return $rss; |
| 187 | 186 | } |
| 188 | - } |
|
| 189 | - else { |
|
| 187 | + } else { |
|
| 190 | 188 | $errormsg = "Failed to fetch $url "; |
| 191 | 189 | if ( $resp->status == '-100' ) { |
| 192 | 190 | $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
| 193 | - } |
|
| 194 | - elseif ( $resp->error ) { |
|
| 191 | + } elseif ( $resp->error ) { |
|
| 195 | 192 | # compensate for Snoopy's annoying habbit to tacking |
| 196 | 193 | # on '\n' |
| 197 | 194 | $http_error = substr($resp->error, 0, -2); |
| 198 | 195 | $errormsg .= "(HTTP Error: $http_error)"; |
| 199 | - } |
|
| 200 | - else { |
|
| 196 | + } else { |
|
| 201 | 197 | $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
| 202 | 198 | } |
| 203 | 199 | } |
| 204 | - } |
|
| 205 | - else { |
|
| 200 | + } else { |
|
| 206 | 201 | $errormsg = "Unable to retrieve RSS file for unknown reasons."; |
| 207 | 202 | } |
| 208 | 203 | |
@@ -229,11 +224,12 @@ discard block |
||
| 229 | 224 | Purpose: set MAGPIE_ERROR, and trigger error |
| 230 | 225 | \*=======================================================================*/ |
| 231 | 226 | |
| 232 | -function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 227 | +function error ($errormsg, $lvl=E_USER_WARNING) |
|
| 228 | +{ |
|
| 233 | 229 | global $MAGPIE_ERROR; |
| 234 | 230 | |
| 235 | 231 | // append PHP's error message if track_errors enabled |
| 236 | - if ( isset($php_errormsg) ) { |
|
| 232 | + if ( isset($php_errormsg) ) { |
|
| 237 | 233 | $errormsg .= " ($php_errormsg)"; |
| 238 | 234 | } |
| 239 | 235 | if ( $errormsg ) { |
@@ -243,7 +239,8 @@ discard block |
||
| 243 | 239 | } |
| 244 | 240 | } |
| 245 | 241 | |
| 246 | -function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
| 242 | +function debug ($debugmsg, $lvl=E_USER_NOTICE) |
|
| 243 | +{ |
|
| 247 | 244 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
| 248 | 245 | } |
| 249 | 246 | |
@@ -251,10 +248,11 @@ discard block |
||
| 251 | 248 | Function: magpie_error |
| 252 | 249 | Purpose: accessor for the magpie error variable |
| 253 | 250 | \*=======================================================================*/ |
| 254 | -function magpie_error ($errormsg="") { |
|
| 251 | +function magpie_error ($errormsg="") |
|
| 252 | +{ |
|
| 255 | 253 | global $MAGPIE_ERROR; |
| 256 | 254 | |
| 257 | - if ( isset($errormsg) and $errormsg ) { |
|
| 255 | + if ( isset($errormsg) and $errormsg ) { |
|
| 258 | 256 | $MAGPIE_ERROR = $errormsg; |
| 259 | 257 | } |
| 260 | 258 | |
@@ -268,7 +266,8 @@ discard block |
||
| 268 | 266 | headers to send along with the request (optional) |
| 269 | 267 | Output: an HTTP response object (see Snoopy.class.inc) |
| 270 | 268 | \*=======================================================================*/ |
| 271 | -function _fetch_remote_file ($url, $headers = "" ) { |
|
| 269 | +function _fetch_remote_file ($url, $headers = "" ) |
|
| 270 | +{ |
|
| 272 | 271 | // Snoopy is an HTTP client in PHP |
| 273 | 272 | $client = new Snoopy(); |
| 274 | 273 | $client->agent = MAGPIE_USER_AGENT; |
@@ -289,7 +288,8 @@ discard block |
||
| 289 | 288 | Input: an HTTP response object (see Snoopy) |
| 290 | 289 | Output: parsed RSS object (see rss_parse) |
| 291 | 290 | \*=======================================================================*/ |
| 292 | -function _response_to_rss ($resp) { |
|
| 291 | +function _response_to_rss ($resp) |
|
| 292 | +{ |
|
| 293 | 293 | $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
| 294 | 294 | |
| 295 | 295 | // if RSS parsed successfully |
@@ -300,8 +300,7 @@ discard block |
||
| 300 | 300 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
| 301 | 301 | if (strpos($h, ": ")) { |
| 302 | 302 | list($field, $val) = explode(": ", $h, 2); |
| 303 | - } |
|
| 304 | - else { |
|
| 303 | + } else { |
|
| 305 | 304 | $field = $h; |
| 306 | 305 | $val = ""; |
| 307 | 306 | } |
@@ -334,11 +333,11 @@ discard block |
||
| 334 | 333 | Purpose: setup constants with default values |
| 335 | 334 | check for user overrides |
| 336 | 335 | \*=======================================================================*/ |
| 337 | -function init () { |
|
| 336 | +function init () |
|
| 337 | +{ |
|
| 338 | 338 | if ( defined('MAGPIE_INITALIZED') ) { |
| 339 | 339 | return; |
| 340 | - } |
|
| 341 | - else { |
|
| 340 | + } else { |
|
| 342 | 341 | define('MAGPIE_INITALIZED', true); |
| 343 | 342 | } |
| 344 | 343 | |
@@ -360,7 +359,9 @@ discard block |
||
| 360 | 359 | |
| 361 | 360 | if ( !defined('MAGPIE_OUTPUT_ENCODING') ) { |
| 362 | 361 | global $modx_manager_charset; |
| 363 | - if(empty($modx_manager_charset)) $modx_manager_charset = 'ISO-8859-1'; |
|
| 362 | + if(empty($modx_manager_charset)) { |
|
| 363 | + $modx_manager_charset = 'ISO-8859-1'; |
|
| 364 | + } |
|
| 364 | 365 | define('MAGPIE_OUTPUT_ENCODING', $modx_manager_charset); |
| 365 | 366 | } |
| 366 | 367 | |
@@ -381,8 +382,7 @@ discard block |
||
| 381 | 382 | |
| 382 | 383 | if ( MAGPIE_CACHE_ON ) { |
| 383 | 384 | $ua = $ua . ')'; |
| 384 | - } |
|
| 385 | - else { |
|
| 385 | + } else { |
|
| 386 | 386 | $ua = $ua . '; No cache)'; |
| 387 | 387 | } |
| 388 | 388 | |
@@ -417,7 +417,8 @@ discard block |
||
| 417 | 417 | Function: is_info |
| 418 | 418 | Purpose: return true if Informational status code |
| 419 | 419 | \*=======================================================================*/ |
| 420 | -function is_info ($sc) { |
|
| 420 | +function is_info ($sc) |
|
| 421 | +{ |
|
| 421 | 422 | return $sc >= 100 && $sc < 200; |
| 422 | 423 | } |
| 423 | 424 | |
@@ -425,7 +426,8 @@ discard block |
||
| 425 | 426 | Function: is_success |
| 426 | 427 | Purpose: return true if Successful status code |
| 427 | 428 | \*=======================================================================*/ |
| 428 | -function is_success ($sc) { |
|
| 429 | +function is_success ($sc) |
|
| 430 | +{ |
|
| 429 | 431 | return $sc >= 200 && $sc < 300; |
| 430 | 432 | } |
| 431 | 433 | |
@@ -433,7 +435,8 @@ discard block |
||
| 433 | 435 | Function: is_redirect |
| 434 | 436 | Purpose: return true if Redirection status code |
| 435 | 437 | \*=======================================================================*/ |
| 436 | -function is_redirect ($sc) { |
|
| 438 | +function is_redirect ($sc) |
|
| 439 | +{ |
|
| 437 | 440 | return $sc >= 300 && $sc < 400; |
| 438 | 441 | } |
| 439 | 442 | |
@@ -441,7 +444,8 @@ discard block |
||
| 441 | 444 | Function: is_error |
| 442 | 445 | Purpose: return true if Error status code |
| 443 | 446 | \*=======================================================================*/ |
| 444 | -function is_error ($sc) { |
|
| 447 | +function is_error ($sc) |
|
| 448 | +{ |
|
| 445 | 449 | return $sc >= 400 && $sc < 600; |
| 446 | 450 | } |
| 447 | 451 | |
@@ -449,7 +453,8 @@ discard block |
||
| 449 | 453 | Function: is_client_error |
| 450 | 454 | Purpose: return true if Error status code, and its a client error |
| 451 | 455 | \*=======================================================================*/ |
| 452 | -function is_client_error ($sc) { |
|
| 456 | +function is_client_error ($sc) |
|
| 457 | +{ |
|
| 453 | 458 | return $sc >= 400 && $sc < 500; |
| 454 | 459 | } |
| 455 | 460 | |
@@ -457,7 +462,8 @@ discard block |
||
| 457 | 462 | Function: is_client_error |
| 458 | 463 | Purpose: return true if Error status code, and its a server error |
| 459 | 464 | \*=======================================================================*/ |
| 460 | -function is_server_error ($sc) { |
|
| 465 | +function is_server_error ($sc) |
|
| 466 | +{ |
|
| 461 | 467 | return $sc >= 500 && $sc < 600; |
| 462 | 468 | } |
| 463 | 469 | ?> |
@@ -447,6 +447,10 @@ discard block |
||
| 447 | 447 | /** |
| 448 | 448 | * return XML parser, and possibly re-encoded source |
| 449 | 449 | * |
| 450 | + * @param string $source |
|
| 451 | + * @param string $out_enc |
|
| 452 | + * @param string|null $in_enc |
|
| 453 | + * @param boolean $detect |
|
| 450 | 454 | */ |
| 451 | 455 | function create_parser($source, $out_enc, $in_enc, $detect) { |
| 452 | 456 | if ( substr(phpversion(),0,1) == 5) { |
@@ -556,6 +560,9 @@ discard block |
||
| 556 | 560 | } |
| 557 | 561 | } |
| 558 | 562 | |
| 563 | + /** |
|
| 564 | + * @param integer $lvl |
|
| 565 | + */ |
|
| 559 | 566 | function error ($errormsg, $lvl=E_USER_WARNING) { |
| 560 | 567 | // append PHP's error message if track_errors enabled |
| 561 | 568 | if ( isset($php_errormsg) ) { |
@@ -591,6 +598,9 @@ discard block |
||
| 591 | 598 | define("CASE_LOWER",0); |
| 592 | 599 | |
| 593 | 600 | |
| 601 | + /** |
|
| 602 | + * @param integer $case |
|
| 603 | + */ |
|
| 594 | 604 | function array_change_key_case($array,$case=CASE_LOWER) { |
| 595 | 605 | if ($case=CASE_LOWER) $cmd=strtolower; |
| 596 | 606 | elseif ($case=CASE_UPPER) $cmd=strtoupper; |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | # |
| 99 | 99 | if (!function_exists('xml_parser_create')) { |
| 100 | 100 | $this->error( "Failed to load PHP's XML Extension. " . |
| 101 | - "http://www.php.net/manual/en/ref.xml.php", |
|
| 102 | - E_USER_ERROR ); |
|
| 101 | + "http://www.php.net/manual/en/ref.xml.php", |
|
| 102 | + E_USER_ERROR ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | list($parser, $source) = $this->create_parser($source, |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | if (!is_resource($parser)) { |
| 110 | 110 | $this->error( "Failed to create an instance of PHP's XML parser. " . |
| 111 | - "http://www.php.net/manual/en/ref.xml.php", |
|
| 112 | - E_USER_ERROR ); |
|
| 111 | + "http://www.php.net/manual/en/ref.xml.php", |
|
| 112 | + E_USER_ERROR ); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
| 448 | - * return XML parser, and possibly re-encoded source |
|
| 449 | - * |
|
| 450 | - */ |
|
| 448 | + * return XML parser, and possibly re-encoded source |
|
| 449 | + * |
|
| 450 | + */ |
|
| 451 | 451 | function create_parser($source, $out_enc, $in_enc, $detect) { |
| 452 | 452 | if ( substr(phpversion(),0,1) == 5) { |
| 453 | 453 | $parser = $this->php5_create_parser($in_enc, $detect); |
@@ -464,14 +464,14 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
| 467 | - * Instantiate an XML parser under PHP5 |
|
| 468 | - * |
|
| 469 | - * PHP5 will do a fine job of detecting input encoding |
|
| 470 | - * if passed an empty string as the encoding. |
|
| 471 | - * |
|
| 472 | - * All hail libxml2! |
|
| 473 | - * |
|
| 474 | - */ |
|
| 467 | + * Instantiate an XML parser under PHP5 |
|
| 468 | + * |
|
| 469 | + * PHP5 will do a fine job of detecting input encoding |
|
| 470 | + * if passed an empty string as the encoding. |
|
| 471 | + * |
|
| 472 | + * All hail libxml2! |
|
| 473 | + * |
|
| 474 | + */ |
|
| 475 | 475 | function php5_create_parser($in_enc, $detect) { |
| 476 | 476 | // by default php5 does a fine job of detecting input encodings |
| 477 | 477 | if(!$detect && $in_enc) { |
@@ -483,20 +483,20 @@ discard block |
||
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
| 486 | - * Instaniate an XML parser under PHP4 |
|
| 487 | - * |
|
| 488 | - * Unfortunately PHP4's support for character encodings |
|
| 489 | - * and especially XML and character encodings sucks. As |
|
| 490 | - * long as the documents you parse only contain characters |
|
| 491 | - * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 492 | - * and a subset of UTF-8) you're fine. However once you |
|
| 493 | - * step out of that comfy little world things get mad, bad, |
|
| 494 | - * and dangerous to know. |
|
| 495 | - * |
|
| 496 | - * The following code is based on SJM's work with FoF |
|
| 497 | - * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 498 | - * |
|
| 499 | - */ |
|
| 486 | + * Instaniate an XML parser under PHP4 |
|
| 487 | + * |
|
| 488 | + * Unfortunately PHP4's support for character encodings |
|
| 489 | + * and especially XML and character encodings sucks. As |
|
| 490 | + * long as the documents you parse only contain characters |
|
| 491 | + * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 492 | + * and a subset of UTF-8) you're fine. However once you |
|
| 493 | + * step out of that comfy little world things get mad, bad, |
|
| 494 | + * and dangerous to know. |
|
| 495 | + * |
|
| 496 | + * The following code is based on SJM's work with FoF |
|
| 497 | + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 498 | + * |
|
| 499 | + */ |
|
| 500 | 500 | function php4_create_parser($source, $in_enc, $detect) { |
| 501 | 501 | if ( !$detect ) { |
| 502 | 502 | return array(xml_parser_create($in_enc), $source); |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | // else |
| 542 | 542 | $this->error("Feed is in an unsupported character encoding. ($in_enc) " . |
| 543 | - "You may see strange artifacts, and mangled characters.", |
|
| 544 | - E_USER_NOTICE); |
|
| 543 | + "You may see strange artifacts, and mangled characters.", |
|
| 544 | + E_USER_NOTICE); |
|
| 545 | 545 | |
| 546 | 546 | return array(xml_parser_create(), $source); |
| 547 | 547 | } |
@@ -587,18 +587,18 @@ discard block |
||
| 587 | 587 | // courtesy, Ryan Currie, [email protected] |
| 588 | 588 | |
| 589 | 589 | if (!function_exists('array_change_key_case')) { |
| 590 | - define("CASE_UPPER",1); |
|
| 591 | - define("CASE_LOWER",0); |
|
| 590 | + define("CASE_UPPER",1); |
|
| 591 | + define("CASE_LOWER",0); |
|
| 592 | 592 | |
| 593 | 593 | |
| 594 | - function array_change_key_case($array,$case=CASE_LOWER) { |
|
| 595 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
| 596 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
| 597 | - foreach($array as $key=>$value) { |
|
| 598 | - $output[$cmd($key)]=$value; |
|
| 599 | - } |
|
| 600 | - return $output; |
|
| 601 | - } |
|
| 594 | + function array_change_key_case($array,$case=CASE_LOWER) { |
|
| 595 | + if ($case=CASE_LOWER) $cmd=strtolower; |
|
| 596 | + elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
| 597 | + foreach($array as $key=>$value) { |
|
| 598 | + $output[$cmd($key)]=$value; |
|
| 599 | + } |
|
| 600 | + return $output; |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | 603 | } |
| 604 | 604 | ?> |
| 605 | 605 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | define('RSS', 'RSS'); |
| 24 | 24 | define('ATOM', 'Atom'); |
| 25 | 25 | |
| 26 | -require_once (MAGPIE_DIR . 'rss_utils.inc'); |
|
| 26 | +require_once (MAGPIE_DIR.'rss_utils.inc'); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Hybrid parser, and object, takes RSS as a string and returns a simple object. |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * see: rss_fetch.inc for a simpler interface with integrated caching support |
| 32 | 32 | * |
| 33 | 33 | */ |
| 34 | -class MagpieRSS { |
|
| 34 | +class MagpieRSS{ |
|
| 35 | 35 | var $parser; |
| 36 | 36 | |
| 37 | - var $current_item = array(); // item currently being parsed |
|
| 38 | - var $items = array(); // collection of parsed items |
|
| 39 | - var $channel = array(); // hash of channel fields |
|
| 37 | + var $current_item = array(); // item currently being parsed |
|
| 38 | + var $items = array(); // collection of parsed items |
|
| 39 | + var $channel = array(); // hash of channel fields |
|
| 40 | 40 | var $textinput = array(); |
| 41 | 41 | var $image = array(); |
| 42 | 42 | var $feed_type; |
| 43 | 43 | var $feed_version; |
| 44 | - var $encoding = ''; // output encoding of parsed rss |
|
| 44 | + var $encoding = ''; // output encoding of parsed rss |
|
| 45 | 45 | |
| 46 | - var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 46 | + var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 47 | 47 | |
| 48 | 48 | var $ERROR = ""; |
| 49 | 49 | var $WARNING = ""; |
@@ -91,15 +91,15 @@ discard block |
||
| 91 | 91 | * source encoding. (caveat emptor) |
| 92 | 92 | * |
| 93 | 93 | */ |
| 94 | - function __construct($source, $output_encoding='ISO-8859-1', |
|
| 95 | - $input_encoding=null, $detect_encoding=true) |
|
| 94 | + function __construct($source, $output_encoding = 'ISO-8859-1', |
|
| 95 | + $input_encoding = null, $detect_encoding = true) |
|
| 96 | 96 | { |
| 97 | 97 | # if PHP xml isn't compiled in, die |
| 98 | 98 | # |
| 99 | 99 | if (!function_exists('xml_parser_create')) { |
| 100 | - $this->error( "Failed to load PHP's XML Extension. " . |
|
| 100 | + $this->error("Failed to load PHP's XML Extension. ". |
|
| 101 | 101 | "http://www.php.net/manual/en/ref.xml.php", |
| 102 | - E_USER_ERROR ); |
|
| 102 | + E_USER_ERROR); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | list($parser, $source) = $this->create_parser($source, |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | if (!is_resource($parser)) { |
| 110 | - $this->error( "Failed to create an instance of PHP's XML parser. " . |
|
| 110 | + $this->error("Failed to create an instance of PHP's XML parser. ". |
|
| 111 | 111 | "http://www.php.net/manual/en/ref.xml.php", |
| 112 | - E_USER_ERROR ); |
|
| 112 | + E_USER_ERROR); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -118,57 +118,57 @@ discard block |
||
| 118 | 118 | # pass in parser, and a reference to this object |
| 119 | 119 | # setup handlers |
| 120 | 120 | # |
| 121 | - xml_set_object( $this->parser, $this ); |
|
| 121 | + xml_set_object($this->parser, $this); |
|
| 122 | 122 | xml_set_element_handler($this->parser, |
| 123 | - 'feed_start_element', 'feed_end_element' ); |
|
| 123 | + 'feed_start_element', 'feed_end_element'); |
|
| 124 | 124 | |
| 125 | - xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
| 125 | + xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
| 126 | 126 | |
| 127 | - $status = xml_parse( $this->parser, $source ); |
|
| 127 | + $status = xml_parse($this->parser, $source); |
|
| 128 | 128 | |
| 129 | - if (! $status ) { |
|
| 130 | - $errorcode = xml_get_error_code( $this->parser ); |
|
| 131 | - if ( $errorcode != XML_ERROR_NONE ) { |
|
| 132 | - $xml_error = xml_error_string( $errorcode ); |
|
| 129 | + if (!$status) { |
|
| 130 | + $errorcode = xml_get_error_code($this->parser); |
|
| 131 | + if ($errorcode != XML_ERROR_NONE) { |
|
| 132 | + $xml_error = xml_error_string($errorcode); |
|
| 133 | 133 | $error_line = xml_get_current_line_number($this->parser); |
| 134 | 134 | $error_col = xml_get_current_column_number($this->parser); |
| 135 | 135 | $errormsg = "$xml_error at line $error_line, column $error_col"; |
| 136 | 136 | |
| 137 | - $this->error( $errormsg ); |
|
| 137 | + $this->error($errormsg); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - xml_parser_free( $this->parser ); |
|
| 141 | + xml_parser_free($this->parser); |
|
| 142 | 142 | |
| 143 | 143 | $this->normalize(); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - function feed_start_element($p, $element, &$attrs) { |
|
| 146 | + function feed_start_element($p, $element, &$attrs){ |
|
| 147 | 147 | $el = $element = strtolower($element); |
| 148 | 148 | $attrs = array_change_key_case($attrs, CASE_LOWER); |
| 149 | 149 | |
| 150 | 150 | // check for a namespace, and split if found |
| 151 | 151 | $ns = false; |
| 152 | - if ( strpos( $element, ':' ) ) { |
|
| 153 | - list($ns, $el) = explode( ':', $element, 2); |
|
| 152 | + if (strpos($element, ':')) { |
|
| 153 | + list($ns, $el) = explode(':', $element, 2); |
|
| 154 | 154 | } |
| 155 | - if ( $ns and $ns != 'rdf' ) { |
|
| 155 | + if ($ns and $ns != 'rdf') { |
|
| 156 | 156 | $this->current_namespace = $ns; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | # if feed type isn't set, then this is first element of feed |
| 160 | 160 | # identify feed from root element |
| 161 | 161 | # |
| 162 | - if (!isset($this->feed_type) ) { |
|
| 163 | - if ( $el == 'rdf' ) { |
|
| 162 | + if (!isset($this->feed_type)) { |
|
| 163 | + if ($el == 'rdf') { |
|
| 164 | 164 | $this->feed_type = RSS; |
| 165 | 165 | $this->feed_version = '1.0'; |
| 166 | 166 | } |
| 167 | - elseif ( $el == 'rss' ) { |
|
| 167 | + elseif ($el == 'rss') { |
|
| 168 | 168 | $this->feed_type = RSS; |
| 169 | 169 | $this->feed_version = $attrs['version']; |
| 170 | 170 | } |
| 171 | - elseif ( $el == 'feed' ) { |
|
| 171 | + elseif ($el == 'feed') { |
|
| 172 | 172 | $this->feed_type = ATOM; |
| 173 | 173 | $this->feed_version = $attrs['version']; |
| 174 | 174 | $this->inchannel = true; |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if ( $el == 'channel' ) |
|
| 179 | + if ($el == 'channel') |
|
| 180 | 180 | { |
| 181 | 181 | $this->inchannel = true; |
| 182 | 182 | } |
| 183 | - elseif ($el == 'item' or $el == 'entry' ) |
|
| 183 | + elseif ($el == 'item' or $el == 'entry') |
|
| 184 | 184 | { |
| 185 | 185 | $this->initem = true; |
| 186 | - if ( isset($attrs['rdf:about']) ) { |
|
| 186 | + if (isset($attrs['rdf:about'])) { |
|
| 187 | 187 | $this->current_item['about'] = $attrs['rdf:about']; |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | # handle atom content constructs |
| 210 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 210 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
| 211 | 211 | { |
| 212 | 212 | // avoid clashing w/ RSS mod_content |
| 213 | - if ($el == 'content' ) { |
|
| 213 | + if ($el == 'content') { |
|
| 214 | 214 | $el = 'atom_content'; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -220,31 +220,31 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
| 223 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
| 223 | + elseif ($this->feed_type == ATOM and $this->incontent) |
|
| 224 | 224 | { |
| 225 | 225 | // if tags are inlined, then flatten |
| 226 | 226 | $attrs_str = join(' ', |
| 227 | 227 | array_map('map_attrs', |
| 228 | 228 | array_keys($attrs), |
| 229 | - array_values($attrs) ) ); |
|
| 229 | + array_values($attrs))); |
|
| 230 | 230 | |
| 231 | - $this->append_content( "<$element $attrs_str>" ); |
|
| 231 | + $this->append_content("<$element $attrs_str>"); |
|
| 232 | 232 | |
| 233 | - array_unshift( $this->stack, $el ); |
|
| 233 | + array_unshift($this->stack, $el); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Atom support many links per containging element. |
| 237 | 237 | // Magpie treats link elements of type rel='alternate' |
| 238 | 238 | // as being equivalent to RSS's simple link element. |
| 239 | 239 | // |
| 240 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
| 240 | + elseif ($this->feed_type == ATOM and $el == 'link') |
|
| 241 | 241 | { |
| 242 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
| 242 | + if (isset($attrs['rel']) and $attrs['rel'] == 'alternate') |
|
| 243 | 243 | { |
| 244 | 244 | $link_el = 'link'; |
| 245 | 245 | } |
| 246 | 246 | else { |
| 247 | - $link_el = 'link_' . $attrs['rel']; |
|
| 247 | + $link_el = 'link_'.$attrs['rel']; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $this->append($link_el, $attrs['href']); |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | |
| 259 | 259 | |
| 260 | - function feed_cdata ($p, $text) { |
|
| 260 | + function feed_cdata($p, $text){ |
|
| 261 | 261 | if ($this->feed_type == ATOM and $this->incontent) |
| 262 | 262 | { |
| 263 | - $this->append_content( $text ); |
|
| 263 | + $this->append_content($text); |
|
| 264 | 264 | } |
| 265 | 265 | else { |
| 266 | 266 | $current_el = join('_', array_reverse($this->stack)); |
@@ -268,35 +268,35 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - function feed_end_element ($p, $el) { |
|
| 271 | + function feed_end_element($p, $el){ |
|
| 272 | 272 | $el = strtolower($el); |
| 273 | 273 | |
| 274 | - if ( $el == 'item' or $el == 'entry' ) |
|
| 274 | + if ($el == 'item' or $el == 'entry') |
|
| 275 | 275 | { |
| 276 | 276 | $this->items[] = $this->current_item; |
| 277 | 277 | $this->current_item = array(); |
| 278 | 278 | $this->initem = false; |
| 279 | 279 | } |
| 280 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
| 280 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput') |
|
| 281 | 281 | { |
| 282 | 282 | $this->intextinput = false; |
| 283 | 283 | } |
| 284 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
| 284 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image') |
|
| 285 | 285 | { |
| 286 | 286 | $this->inimage = false; |
| 287 | 287 | } |
| 288 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 288 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
| 289 | 289 | { |
| 290 | 290 | $this->incontent = false; |
| 291 | 291 | } |
| 292 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
| 292 | + elseif ($el == 'channel' or $el == 'feed') |
|
| 293 | 293 | { |
| 294 | 294 | $this->inchannel = false; |
| 295 | 295 | } |
| 296 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
| 296 | + elseif ($this->feed_type == ATOM and $this->incontent) { |
|
| 297 | 297 | // balance tags properly |
| 298 | 298 | // note: i don't think this is actually neccessary |
| 299 | - if ( $this->stack[0] == $el ) |
|
| 299 | + if ($this->stack[0] == $el) |
|
| 300 | 300 | { |
| 301 | 301 | $this->append_content("</$el>"); |
| 302 | 302 | } |
@@ -304,91 +304,91 @@ discard block |
||
| 304 | 304 | $this->append_content("<$el />"); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - array_shift( $this->stack ); |
|
| 307 | + array_shift($this->stack); |
|
| 308 | 308 | } |
| 309 | 309 | else { |
| 310 | - array_shift( $this->stack ); |
|
| 310 | + array_shift($this->stack); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | $this->current_namespace = false; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - function concat (&$str1, $str2="") { |
|
| 317 | - if (!isset($str1) ) { |
|
| 318 | - $str1=""; |
|
| 316 | + function concat(&$str1, $str2 = ""){ |
|
| 317 | + if (!isset($str1)) { |
|
| 318 | + $str1 = ""; |
|
| 319 | 319 | } |
| 320 | 320 | $str1 .= $str2; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | |
| 324 | 324 | |
| 325 | - function append_content($text) { |
|
| 326 | - if ( $this->initem ) { |
|
| 327 | - $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
| 325 | + function append_content($text){ |
|
| 326 | + if ($this->initem) { |
|
| 327 | + $this->concat($this->current_item[$this->incontent], $text); |
|
| 328 | 328 | } |
| 329 | - elseif ( $this->inchannel ) { |
|
| 330 | - $this->concat( $this->channel[ $this->incontent ], $text ); |
|
| 329 | + elseif ($this->inchannel) { |
|
| 330 | + $this->concat($this->channel[$this->incontent], $text); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // smart append - field and namespace aware |
| 335 | - function append($el, $text) { |
|
| 335 | + function append($el, $text){ |
|
| 336 | 336 | if (!$el) { |
| 337 | 337 | return; |
| 338 | 338 | } |
| 339 | - if ( $this->current_namespace ) |
|
| 339 | + if ($this->current_namespace) |
|
| 340 | 340 | { |
| 341 | - if ( $this->initem ) { |
|
| 341 | + if ($this->initem) { |
|
| 342 | 342 | $this->concat( |
| 343 | - $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
| 343 | + $this->current_item[$this->current_namespace][$el], $text); |
|
| 344 | 344 | } |
| 345 | 345 | elseif ($this->inchannel) { |
| 346 | 346 | $this->concat( |
| 347 | - $this->channel[ $this->current_namespace][ $el ], $text ); |
|
| 347 | + $this->channel[$this->current_namespace][$el], $text ); |
|
| 348 | 348 | } |
| 349 | 349 | elseif ($this->intextinput) { |
| 350 | 350 | $this->concat( |
| 351 | - $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
| 351 | + $this->textinput[$this->current_namespace][$el], $text ); |
|
| 352 | 352 | } |
| 353 | 353 | elseif ($this->inimage) { |
| 354 | 354 | $this->concat( |
| 355 | - $this->image[ $this->current_namespace ][ $el ], $text ); |
|
| 355 | + $this->image[$this->current_namespace][$el], $text ); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | else { |
| 359 | - if ( $this->initem ) { |
|
| 359 | + if ($this->initem) { |
|
| 360 | 360 | $this->concat( |
| 361 | - $this->current_item[ $el ], $text); |
|
| 361 | + $this->current_item[$el], $text); |
|
| 362 | 362 | } |
| 363 | 363 | elseif ($this->intextinput) { |
| 364 | 364 | $this->concat( |
| 365 | - $this->textinput[ $el ], $text ); |
|
| 365 | + $this->textinput[$el], $text ); |
|
| 366 | 366 | } |
| 367 | 367 | elseif ($this->inimage) { |
| 368 | 368 | $this->concat( |
| 369 | - $this->image[ $el ], $text ); |
|
| 369 | + $this->image[$el], $text ); |
|
| 370 | 370 | } |
| 371 | 371 | elseif ($this->inchannel) { |
| 372 | 372 | $this->concat( |
| 373 | - $this->channel[ $el ], $text ); |
|
| 373 | + $this->channel[$el], $text ); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - function normalize () { |
|
| 379 | + function normalize(){ |
|
| 380 | 380 | // if atom populate rss fields |
| 381 | - if ( $this->is_atom() ) { |
|
| 381 | + if ($this->is_atom()) { |
|
| 382 | 382 | $this->channel['description'] = $this->channel['tagline']; |
| 383 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
| 383 | + for ($i = 0; $i < count($this->items); $i++) { |
|
| 384 | 384 | $item = $this->items[$i]; |
| 385 | - if ( isset($item['summary']) ) |
|
| 385 | + if (isset($item['summary'])) |
|
| 386 | 386 | $item['description'] = $item['summary']; |
| 387 | - if ( isset($item['atom_content'])) |
|
| 387 | + if (isset($item['atom_content'])) |
|
| 388 | 388 | $item['content']['encoded'] = $item['atom_content']; |
| 389 | 389 | |
| 390 | - $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; |
|
| 391 | - if ( $atom_date ) { |
|
| 390 | + $atom_date = (isset($item['issued'])) ? $item['issued'] : $item['modified']; |
|
| 391 | + if ($atom_date) { |
|
| 392 | 392 | $epoch = @parse_w3cdtf($atom_date); |
| 393 | 393 | if ($epoch and $epoch > 0) { |
| 394 | 394 | $item['date_timestamp'] = $epoch; |
@@ -398,22 +398,22 @@ discard block |
||
| 398 | 398 | $this->items[$i] = $item; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | - elseif ( $this->is_rss() ) { |
|
| 401 | + elseif ($this->is_rss()) { |
|
| 402 | 402 | $this->channel['tagline'] = $this->channel['description']; |
| 403 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
| 403 | + for ($i = 0; $i < count($this->items); $i++) { |
|
| 404 | 404 | $item = $this->items[$i]; |
| 405 | - if ( isset($item['description'])) |
|
| 405 | + if (isset($item['description'])) |
|
| 406 | 406 | $item['summary'] = $item['description']; |
| 407 | - if ( isset($item['content']['encoded'] ) ) |
|
| 407 | + if (isset($item['content']['encoded'])) |
|
| 408 | 408 | $item['atom_content'] = $item['content']['encoded']; |
| 409 | 409 | |
| 410 | - if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
|
| 410 | + if ($this->is_rss() == '1.0' and isset($item['dc']['date'])) { |
|
| 411 | 411 | $epoch = @parse_w3cdtf($item['dc']['date']); |
| 412 | 412 | if ($epoch and $epoch > 0) { |
| 413 | 413 | $item['date_timestamp'] = $epoch; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | - elseif ( isset($item['pubdate']) ) { |
|
| 416 | + elseif (isset($item['pubdate'])) { |
|
| 417 | 417 | $epoch = @strtotime($item['pubdate']); |
| 418 | 418 | if ($epoch > 0) { |
| 419 | 419 | $item['date_timestamp'] = $epoch; |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
| 429 | - function is_rss () { |
|
| 430 | - if ( $this->feed_type == RSS ) { |
|
| 429 | + function is_rss(){ |
|
| 430 | + if ($this->feed_type == RSS) { |
|
| 431 | 431 | return $this->feed_version; |
| 432 | 432 | } |
| 433 | 433 | else { |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - function is_atom() { |
|
| 439 | - if ( $this->feed_type == ATOM ) { |
|
| 438 | + function is_atom(){ |
|
| 439 | + if ($this->feed_type == ATOM) { |
|
| 440 | 440 | return $this->feed_version; |
| 441 | 441 | } |
| 442 | 442 | else { |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | * return XML parser, and possibly re-encoded source |
| 449 | 449 | * |
| 450 | 450 | */ |
| 451 | - function create_parser($source, $out_enc, $in_enc, $detect) { |
|
| 452 | - if ( substr(phpversion(),0,1) == 5) { |
|
| 451 | + function create_parser($source, $out_enc, $in_enc, $detect){ |
|
| 452 | + if (substr(phpversion(), 0, 1) == 5) { |
|
| 453 | 453 | $parser = $this->php5_create_parser($in_enc, $detect); |
| 454 | 454 | } |
| 455 | 455 | else { |
@@ -472,9 +472,9 @@ discard block |
||
| 472 | 472 | * All hail libxml2! |
| 473 | 473 | * |
| 474 | 474 | */ |
| 475 | - function php5_create_parser($in_enc, $detect) { |
|
| 475 | + function php5_create_parser($in_enc, $detect){ |
|
| 476 | 476 | // by default php5 does a fine job of detecting input encodings |
| 477 | - if(!$detect && $in_enc) { |
|
| 477 | + if (!$detect && $in_enc) { |
|
| 478 | 478 | return xml_parser_create($in_enc); |
| 479 | 479 | } |
| 480 | 480 | else { |
@@ -497,8 +497,8 @@ discard block |
||
| 497 | 497 | * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
| 498 | 498 | * |
| 499 | 499 | */ |
| 500 | - function php4_create_parser($source, $in_enc, $detect) { |
|
| 501 | - if ( !$detect ) { |
|
| 500 | + function php4_create_parser($source, $in_enc, $detect){ |
|
| 501 | + if (!$detect) { |
|
| 502 | 502 | return array(xml_parser_create($in_enc), $source); |
| 503 | 503 | } |
| 504 | 504 | |
@@ -522,8 +522,8 @@ discard block |
||
| 522 | 522 | // cast the XML to a known encoding |
| 523 | 523 | // @see http://php.net/iconv |
| 524 | 524 | |
| 525 | - if (function_exists('iconv')) { |
|
| 526 | - $encoded_source = iconv($in_enc,'UTF-8', $source); |
|
| 525 | + if (function_exists('iconv')) { |
|
| 526 | + $encoded_source = iconv($in_enc, 'UTF-8', $source); |
|
| 527 | 527 | if ($encoded_source) { |
| 528 | 528 | return array(xml_parser_create('UTF-8'), $encoded_source); |
| 529 | 529 | } |
@@ -531,24 +531,24 @@ discard block |
||
| 531 | 531 | |
| 532 | 532 | // iconv didn't work, try mb_convert_encoding |
| 533 | 533 | // @see http://php.net/mbstring |
| 534 | - if(function_exists('mb_convert_encoding')) { |
|
| 535 | - $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc ); |
|
| 534 | + if (function_exists('mb_convert_encoding')) { |
|
| 535 | + $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc); |
|
| 536 | 536 | if ($encoded_source) { |
| 537 | 537 | return array(xml_parser_create('UTF-8'), $encoded_source); |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | // else |
| 542 | - $this->error("Feed is in an unsupported character encoding. ($in_enc) " . |
|
| 542 | + $this->error("Feed is in an unsupported character encoding. ($in_enc) ". |
|
| 543 | 543 | "You may see strange artifacts, and mangled characters.", |
| 544 | 544 | E_USER_NOTICE); |
| 545 | 545 | |
| 546 | 546 | return array(xml_parser_create(), $source); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | - function known_encoding($enc) { |
|
| 549 | + function known_encoding($enc){ |
|
| 550 | 550 | $enc = strtoupper($enc); |
| 551 | - if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
|
| 551 | + if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
| 552 | 552 | return $enc; |
| 553 | 553 | } |
| 554 | 554 | else { |
@@ -556,20 +556,20 @@ discard block |
||
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 559 | + function error($errormsg, $lvl = E_USER_WARNING){ |
|
| 560 | 560 | // append PHP's error message if track_errors enabled |
| 561 | - if ( isset($php_errormsg) ) { |
|
| 561 | + if (isset($php_errormsg)) { |
|
| 562 | 562 | $errormsg .= " ($php_errormsg)"; |
| 563 | 563 | } |
| 564 | - if ( MAGPIE_DEBUG ) { |
|
| 565 | - trigger_error( $errormsg, $lvl); |
|
| 564 | + if (MAGPIE_DEBUG) { |
|
| 565 | + trigger_error($errormsg, $lvl); |
|
| 566 | 566 | } |
| 567 | 567 | else { |
| 568 | - error_log( $errormsg, 0); |
|
| 568 | + error_log($errormsg, 0); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - $notices = E_USER_NOTICE|E_NOTICE; |
|
| 572 | - if ( $lvl&$notices ) { |
|
| 571 | + $notices = E_USER_NOTICE | E_NOTICE; |
|
| 572 | + if ($lvl & $notices) { |
|
| 573 | 573 | $this->WARNING = $errormsg; |
| 574 | 574 | } else { |
| 575 | 575 | $this->ERROR = $errormsg; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | } // end class RSS |
| 581 | 581 | |
| 582 | -function map_attrs($k, $v) { |
|
| 582 | +function map_attrs($k, $v){ |
|
| 583 | 583 | return "$k=\"$v\""; |
| 584 | 584 | } |
| 585 | 585 | |
@@ -587,15 +587,15 @@ discard block |
||
| 587 | 587 | // courtesy, Ryan Currie, [email protected] |
| 588 | 588 | |
| 589 | 589 | if (!function_exists('array_change_key_case')) { |
| 590 | - define("CASE_UPPER",1); |
|
| 591 | - define("CASE_LOWER",0); |
|
| 590 | + define("CASE_UPPER", 1); |
|
| 591 | + define("CASE_LOWER", 0); |
|
| 592 | 592 | |
| 593 | 593 | |
| 594 | - function array_change_key_case($array,$case=CASE_LOWER) { |
|
| 595 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
| 596 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
| 597 | - foreach($array as $key=>$value) { |
|
| 598 | - $output[$cmd($key)]=$value; |
|
| 594 | + function array_change_key_case($array, $case = CASE_LOWER){ |
|
| 595 | + if ($case = CASE_LOWER) $cmd = strtolower; |
|
| 596 | + elseif ($case = CASE_UPPER) $cmd = strtoupper; |
|
| 597 | + foreach ($array as $key=>$value) { |
|
| 598 | + $output[$cmd($key)] = $value; |
|
| 599 | 599 | } |
| 600 | 600 | return $output; |
| 601 | 601 | } |
@@ -31,7 +31,8 @@ discard block |
||
| 31 | 31 | * see: rss_fetch.inc for a simpler interface with integrated caching support |
| 32 | 32 | * |
| 33 | 33 | */ |
| 34 | -class MagpieRSS { |
|
| 34 | +class MagpieRSS |
|
| 35 | +{ |
|
| 35 | 36 | var $parser; |
| 36 | 37 | |
| 37 | 38 | var $current_item = array(); // item currently being parsed |
@@ -92,8 +93,8 @@ discard block |
||
| 92 | 93 | * |
| 93 | 94 | */ |
| 94 | 95 | function __construct($source, $output_encoding='ISO-8859-1', |
| 95 | - $input_encoding=null, $detect_encoding=true) |
|
| 96 | - { |
|
| 96 | + $input_encoding=null, $detect_encoding=true) |
|
| 97 | + { |
|
| 97 | 98 | # if PHP xml isn't compiled in, die |
| 98 | 99 | # |
| 99 | 100 | if (!function_exists('xml_parser_create')) { |
@@ -143,7 +144,8 @@ discard block |
||
| 143 | 144 | $this->normalize(); |
| 144 | 145 | } |
| 145 | 146 | |
| 146 | - function feed_start_element($p, $element, &$attrs) { |
|
| 147 | + function feed_start_element($p, $element, &$attrs) |
|
| 148 | + { |
|
| 147 | 149 | $el = $element = strtolower($element); |
| 148 | 150 | $attrs = array_change_key_case($attrs, CASE_LOWER); |
| 149 | 151 | |
@@ -163,12 +165,10 @@ discard block |
||
| 163 | 165 | if ( $el == 'rdf' ) { |
| 164 | 166 | $this->feed_type = RSS; |
| 165 | 167 | $this->feed_version = '1.0'; |
| 166 | - } |
|
| 167 | - elseif ( $el == 'rss' ) { |
|
| 168 | + } elseif ( $el == 'rss' ) { |
|
| 168 | 169 | $this->feed_type = RSS; |
| 169 | 170 | $this->feed_version = $attrs['version']; |
| 170 | - } |
|
| 171 | - elseif ( $el == 'feed' ) { |
|
| 171 | + } elseif ( $el == 'feed' ) { |
|
| 172 | 172 | $this->feed_type = ATOM; |
| 173 | 173 | $this->feed_version = $attrs['version']; |
| 174 | 174 | $this->inchannel = true; |
@@ -176,12 +176,9 @@ discard block |
||
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if ( $el == 'channel' ) |
|
| 180 | - { |
|
| 179 | + if ( $el == 'channel' ) { |
|
| 181 | 180 | $this->inchannel = true; |
| 182 | - } |
|
| 183 | - elseif ($el == 'item' or $el == 'entry' ) |
|
| 184 | - { |
|
| 181 | + } elseif ($el == 'item' or $el == 'entry' ) { |
|
| 185 | 182 | $this->initem = true; |
| 186 | 183 | if ( isset($attrs['rdf:about']) ) { |
| 187 | 184 | $this->current_item['about'] = $attrs['rdf:about']; |
@@ -193,22 +190,17 @@ discard block |
||
| 193 | 190 | elseif ( |
| 194 | 191 | $this->feed_type == RSS and |
| 195 | 192 | $this->current_namespace == '' and |
| 196 | - $el == 'textinput' ) |
|
| 197 | - { |
|
| 193 | + $el == 'textinput' ) { |
|
| 198 | 194 | $this->intextinput = true; |
| 199 | - } |
|
| 200 | - |
|
| 201 | - elseif ( |
|
| 195 | + } elseif ( |
|
| 202 | 196 | $this->feed_type == RSS and |
| 203 | 197 | $this->current_namespace == '' and |
| 204 | - $el == 'image' ) |
|
| 205 | - { |
|
| 198 | + $el == 'image' ) { |
|
| 206 | 199 | $this->inimage = true; |
| 207 | 200 | } |
| 208 | 201 | |
| 209 | 202 | # handle atom content constructs |
| 210 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 211 | - { |
|
| 203 | + elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) { |
|
| 212 | 204 | // avoid clashing w/ RSS mod_content |
| 213 | 205 | if ($el == 'content' ) { |
| 214 | 206 | $el = 'atom_content'; |
@@ -220,8 +212,7 @@ discard block |
||
| 220 | 212 | } |
| 221 | 213 | |
| 222 | 214 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
| 223 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
| 224 | - { |
|
| 215 | + elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
| 225 | 216 | // if tags are inlined, then flatten |
| 226 | 217 | $attrs_str = join(' ', |
| 227 | 218 | array_map('map_attrs', |
@@ -237,13 +228,10 @@ discard block |
||
| 237 | 228 | // Magpie treats link elements of type rel='alternate' |
| 238 | 229 | // as being equivalent to RSS's simple link element. |
| 239 | 230 | // |
| 240 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
| 241 | - { |
|
| 242 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
| 243 | - { |
|
| 231 | + elseif ($this->feed_type == ATOM and $el == 'link' ) { |
|
| 232 | + if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) { |
|
| 244 | 233 | $link_el = 'link'; |
| 245 | - } |
|
| 246 | - else { |
|
| 234 | + } else { |
|
| 247 | 235 | $link_el = 'link_' . $attrs['rel']; |
| 248 | 236 | } |
| 249 | 237 | |
@@ -257,63 +245,51 @@ discard block |
||
| 257 | 245 | |
| 258 | 246 | |
| 259 | 247 | |
| 260 | - function feed_cdata ($p, $text) { |
|
| 261 | - if ($this->feed_type == ATOM and $this->incontent) |
|
| 262 | - { |
|
| 248 | + function feed_cdata ($p, $text) |
|
| 249 | + { |
|
| 250 | + if ($this->feed_type == ATOM and $this->incontent) { |
|
| 263 | 251 | $this->append_content( $text ); |
| 264 | - } |
|
| 265 | - else { |
|
| 252 | + } else { |
|
| 266 | 253 | $current_el = join('_', array_reverse($this->stack)); |
| 267 | 254 | $this->append($current_el, $text); |
| 268 | 255 | } |
| 269 | 256 | } |
| 270 | 257 | |
| 271 | - function feed_end_element ($p, $el) { |
|
| 258 | + function feed_end_element ($p, $el) |
|
| 259 | + { |
|
| 272 | 260 | $el = strtolower($el); |
| 273 | 261 | |
| 274 | - if ( $el == 'item' or $el == 'entry' ) |
|
| 275 | - { |
|
| 262 | + if ( $el == 'item' or $el == 'entry' ) { |
|
| 276 | 263 | $this->items[] = $this->current_item; |
| 277 | 264 | $this->current_item = array(); |
| 278 | 265 | $this->initem = false; |
| 279 | - } |
|
| 280 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
| 281 | - { |
|
| 266 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) { |
|
| 282 | 267 | $this->intextinput = false; |
| 283 | - } |
|
| 284 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
| 285 | - { |
|
| 268 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) { |
|
| 286 | 269 | $this->inimage = false; |
| 287 | - } |
|
| 288 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 289 | - { |
|
| 270 | + } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) { |
|
| 290 | 271 | $this->incontent = false; |
| 291 | - } |
|
| 292 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
| 293 | - { |
|
| 272 | + } elseif ($el == 'channel' or $el == 'feed' ) { |
|
| 294 | 273 | $this->inchannel = false; |
| 295 | - } |
|
| 296 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
| 274 | + } elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
| 297 | 275 | // balance tags properly |
| 298 | 276 | // note: i don't think this is actually neccessary |
| 299 | - if ( $this->stack[0] == $el ) |
|
| 300 | - { |
|
| 277 | + if ( $this->stack[0] == $el ) { |
|
| 301 | 278 | $this->append_content("</$el>"); |
| 302 | - } |
|
| 303 | - else { |
|
| 279 | + } else { |
|
| 304 | 280 | $this->append_content("<$el />"); |
| 305 | 281 | } |
| 306 | 282 | |
| 307 | 283 | array_shift( $this->stack ); |
| 308 | - } |
|
| 309 | - else { |
|
| 284 | + } else { |
|
| 310 | 285 | array_shift( $this->stack ); |
| 311 | 286 | } |
| 312 | 287 | |
| 313 | 288 | $this->current_namespace = false; |
| 314 | 289 | } |
| 315 | 290 | |
| 316 | - function concat (&$str1, $str2="") { |
|
| 291 | + function concat (&$str1, $str2="") |
|
| 292 | + { |
|
| 317 | 293 | if (!isset($str1) ) { |
| 318 | 294 | $str1=""; |
| 319 | 295 | } |
@@ -322,53 +298,46 @@ discard block |
||
| 322 | 298 | |
| 323 | 299 | |
| 324 | 300 | |
| 325 | - function append_content($text) { |
|
| 301 | + function append_content($text) |
|
| 302 | + { |
|
| 326 | 303 | if ( $this->initem ) { |
| 327 | 304 | $this->concat( $this->current_item[ $this->incontent ], $text ); |
| 328 | - } |
|
| 329 | - elseif ( $this->inchannel ) { |
|
| 305 | + } elseif ( $this->inchannel ) { |
|
| 330 | 306 | $this->concat( $this->channel[ $this->incontent ], $text ); |
| 331 | 307 | } |
| 332 | 308 | } |
| 333 | 309 | |
| 334 | 310 | // smart append - field and namespace aware |
| 335 | - function append($el, $text) { |
|
| 311 | + function append($el, $text) |
|
| 312 | + { |
|
| 336 | 313 | if (!$el) { |
| 337 | 314 | return; |
| 338 | 315 | } |
| 339 | - if ( $this->current_namespace ) |
|
| 340 | - { |
|
| 316 | + if ( $this->current_namespace ) { |
|
| 341 | 317 | if ( $this->initem ) { |
| 342 | 318 | $this->concat( |
| 343 | 319 | $this->current_item[ $this->current_namespace ][ $el ], $text); |
| 344 | - } |
|
| 345 | - elseif ($this->inchannel) { |
|
| 320 | + } elseif ($this->inchannel) { |
|
| 346 | 321 | $this->concat( |
| 347 | 322 | $this->channel[ $this->current_namespace][ $el ], $text ); |
| 348 | - } |
|
| 349 | - elseif ($this->intextinput) { |
|
| 323 | + } elseif ($this->intextinput) { |
|
| 350 | 324 | $this->concat( |
| 351 | 325 | $this->textinput[ $this->current_namespace][ $el ], $text ); |
| 352 | - } |
|
| 353 | - elseif ($this->inimage) { |
|
| 326 | + } elseif ($this->inimage) { |
|
| 354 | 327 | $this->concat( |
| 355 | 328 | $this->image[ $this->current_namespace ][ $el ], $text ); |
| 356 | 329 | } |
| 357 | - } |
|
| 358 | - else { |
|
| 330 | + } else { |
|
| 359 | 331 | if ( $this->initem ) { |
| 360 | 332 | $this->concat( |
| 361 | 333 | $this->current_item[ $el ], $text); |
| 362 | - } |
|
| 363 | - elseif ($this->intextinput) { |
|
| 334 | + } elseif ($this->intextinput) { |
|
| 364 | 335 | $this->concat( |
| 365 | 336 | $this->textinput[ $el ], $text ); |
| 366 | - } |
|
| 367 | - elseif ($this->inimage) { |
|
| 337 | + } elseif ($this->inimage) { |
|
| 368 | 338 | $this->concat( |
| 369 | 339 | $this->image[ $el ], $text ); |
| 370 | - } |
|
| 371 | - elseif ($this->inchannel) { |
|
| 340 | + } elseif ($this->inchannel) { |
|
| 372 | 341 | $this->concat( |
| 373 | 342 | $this->channel[ $el ], $text ); |
| 374 | 343 | } |
@@ -376,16 +345,19 @@ discard block |
||
| 376 | 345 | } |
| 377 | 346 | } |
| 378 | 347 | |
| 379 | - function normalize () { |
|
| 348 | + function normalize () |
|
| 349 | + { |
|
| 380 | 350 | // if atom populate rss fields |
| 381 | 351 | if ( $this->is_atom() ) { |
| 382 | 352 | $this->channel['description'] = $this->channel['tagline']; |
| 383 | 353 | for ( $i = 0; $i < count($this->items); $i++) { |
| 384 | 354 | $item = $this->items[$i]; |
| 385 | - if ( isset($item['summary']) ) |
|
| 386 | - $item['description'] = $item['summary']; |
|
| 387 | - if ( isset($item['atom_content'])) |
|
| 388 | - $item['content']['encoded'] = $item['atom_content']; |
|
| 355 | + if ( isset($item['summary']) ) { |
|
| 356 | + $item['description'] = $item['summary']; |
|
| 357 | + } |
|
| 358 | + if ( isset($item['atom_content'])) { |
|
| 359 | + $item['content']['encoded'] = $item['atom_content']; |
|
| 360 | + } |
|
| 389 | 361 | |
| 390 | 362 | $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; |
| 391 | 363 | if ( $atom_date ) { |
@@ -397,23 +369,23 @@ discard block |
||
| 397 | 369 | |
| 398 | 370 | $this->items[$i] = $item; |
| 399 | 371 | } |
| 400 | - } |
|
| 401 | - elseif ( $this->is_rss() ) { |
|
| 372 | + } elseif ( $this->is_rss() ) { |
|
| 402 | 373 | $this->channel['tagline'] = $this->channel['description']; |
| 403 | 374 | for ( $i = 0; $i < count($this->items); $i++) { |
| 404 | 375 | $item = $this->items[$i]; |
| 405 | - if ( isset($item['description'])) |
|
| 406 | - $item['summary'] = $item['description']; |
|
| 407 | - if ( isset($item['content']['encoded'] ) ) |
|
| 408 | - $item['atom_content'] = $item['content']['encoded']; |
|
| 376 | + if ( isset($item['description'])) { |
|
| 377 | + $item['summary'] = $item['description']; |
|
| 378 | + } |
|
| 379 | + if ( isset($item['content']['encoded'] ) ) { |
|
| 380 | + $item['atom_content'] = $item['content']['encoded']; |
|
| 381 | + } |
|
| 409 | 382 | |
| 410 | 383 | if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
| 411 | 384 | $epoch = @parse_w3cdtf($item['dc']['date']); |
| 412 | 385 | if ($epoch and $epoch > 0) { |
| 413 | 386 | $item['date_timestamp'] = $epoch; |
| 414 | 387 | } |
| 415 | - } |
|
| 416 | - elseif ( isset($item['pubdate']) ) { |
|
| 388 | + } elseif ( isset($item['pubdate']) ) { |
|
| 417 | 389 | $epoch = @strtotime($item['pubdate']); |
| 418 | 390 | if ($epoch > 0) { |
| 419 | 391 | $item['date_timestamp'] = $epoch; |
@@ -426,20 +398,20 @@ discard block |
||
| 426 | 398 | } |
| 427 | 399 | |
| 428 | 400 | |
| 429 | - function is_rss () { |
|
| 401 | + function is_rss () |
|
| 402 | + { |
|
| 430 | 403 | if ( $this->feed_type == RSS ) { |
| 431 | 404 | return $this->feed_version; |
| 432 | - } |
|
| 433 | - else { |
|
| 405 | + } else { |
|
| 434 | 406 | return false; |
| 435 | 407 | } |
| 436 | 408 | } |
| 437 | 409 | |
| 438 | - function is_atom() { |
|
| 410 | + function is_atom() |
|
| 411 | + { |
|
| 439 | 412 | if ( $this->feed_type == ATOM ) { |
| 440 | 413 | return $this->feed_version; |
| 441 | - } |
|
| 442 | - else { |
|
| 414 | + } else { |
|
| 443 | 415 | return false; |
| 444 | 416 | } |
| 445 | 417 | } |
@@ -448,11 +420,11 @@ discard block |
||
| 448 | 420 | * return XML parser, and possibly re-encoded source |
| 449 | 421 | * |
| 450 | 422 | */ |
| 451 | - function create_parser($source, $out_enc, $in_enc, $detect) { |
|
| 423 | + function create_parser($source, $out_enc, $in_enc, $detect) |
|
| 424 | + { |
|
| 452 | 425 | if ( substr(phpversion(),0,1) == 5) { |
| 453 | 426 | $parser = $this->php5_create_parser($in_enc, $detect); |
| 454 | - } |
|
| 455 | - else { |
|
| 427 | + } else { |
|
| 456 | 428 | list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
| 457 | 429 | } |
| 458 | 430 | if ($out_enc) { |
@@ -472,12 +444,12 @@ discard block |
||
| 472 | 444 | * All hail libxml2! |
| 473 | 445 | * |
| 474 | 446 | */ |
| 475 | - function php5_create_parser($in_enc, $detect) { |
|
| 447 | + function php5_create_parser($in_enc, $detect) |
|
| 448 | + { |
|
| 476 | 449 | // by default php5 does a fine job of detecting input encodings |
| 477 | 450 | if(!$detect && $in_enc) { |
| 478 | 451 | return xml_parser_create($in_enc); |
| 479 | - } |
|
| 480 | - else { |
|
| 452 | + } else { |
|
| 481 | 453 | return xml_parser_create(''); |
| 482 | 454 | } |
| 483 | 455 | } |
@@ -497,7 +469,8 @@ discard block |
||
| 497 | 469 | * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
| 498 | 470 | * |
| 499 | 471 | */ |
| 500 | - function php4_create_parser($source, $in_enc, $detect) { |
|
| 472 | + function php4_create_parser($source, $in_enc, $detect) |
|
| 473 | + { |
|
| 501 | 474 | if ( !$detect ) { |
| 502 | 475 | return array(xml_parser_create($in_enc), $source); |
| 503 | 476 | } |
@@ -506,8 +479,7 @@ discard block |
||
| 506 | 479 | if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
| 507 | 480 | $in_enc = strtoupper($m[1]); |
| 508 | 481 | $this->source_encoding = $in_enc; |
| 509 | - } |
|
| 510 | - else { |
|
| 482 | + } else { |
|
| 511 | 483 | $in_enc = 'UTF-8'; |
| 512 | 484 | } |
| 513 | 485 | } |
@@ -522,7 +494,7 @@ discard block |
||
| 522 | 494 | // cast the XML to a known encoding |
| 523 | 495 | // @see http://php.net/iconv |
| 524 | 496 | |
| 525 | - if (function_exists('iconv')) { |
|
| 497 | + if (function_exists('iconv')) { |
|
| 526 | 498 | $encoded_source = iconv($in_enc,'UTF-8', $source); |
| 527 | 499 | if ($encoded_source) { |
| 528 | 500 | return array(xml_parser_create('UTF-8'), $encoded_source); |
@@ -546,25 +518,25 @@ discard block |
||
| 546 | 518 | return array(xml_parser_create(), $source); |
| 547 | 519 | } |
| 548 | 520 | |
| 549 | - function known_encoding($enc) { |
|
| 521 | + function known_encoding($enc) |
|
| 522 | + { |
|
| 550 | 523 | $enc = strtoupper($enc); |
| 551 | 524 | if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
| 552 | 525 | return $enc; |
| 553 | - } |
|
| 554 | - else { |
|
| 526 | + } else { |
|
| 555 | 527 | return false; |
| 556 | 528 | } |
| 557 | 529 | } |
| 558 | 530 | |
| 559 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
| 531 | + function error ($errormsg, $lvl=E_USER_WARNING) |
|
| 532 | + { |
|
| 560 | 533 | // append PHP's error message if track_errors enabled |
| 561 | - if ( isset($php_errormsg) ) { |
|
| 534 | + if ( isset($php_errormsg) ) { |
|
| 562 | 535 | $errormsg .= " ($php_errormsg)"; |
| 563 | 536 | } |
| 564 | 537 | if ( MAGPIE_DEBUG ) { |
| 565 | 538 | trigger_error( $errormsg, $lvl); |
| 566 | - } |
|
| 567 | - else { |
|
| 539 | + } else { |
|
| 568 | 540 | error_log( $errormsg, 0); |
| 569 | 541 | } |
| 570 | 542 | |
@@ -579,7 +551,8 @@ discard block |
||
| 579 | 551 | |
| 580 | 552 | } // end class RSS |
| 581 | 553 | |
| 582 | -function map_attrs($k, $v) { |
|
| 554 | +function map_attrs($k, $v) |
|
| 555 | +{ |
|
| 583 | 556 | return "$k=\"$v\""; |
| 584 | 557 | } |
| 585 | 558 | |
@@ -591,9 +564,13 @@ discard block |
||
| 591 | 564 | define("CASE_LOWER",0); |
| 592 | 565 | |
| 593 | 566 | |
| 594 | - function array_change_key_case($array,$case=CASE_LOWER) { |
|
| 595 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
| 596 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
| 567 | + function array_change_key_case($array,$case=CASE_LOWER) |
|
| 568 | + { |
|
| 569 | + if ($case=CASE_LOWER) { |
|
| 570 | + $cmd=strtolower; |
|
| 571 | + } elseif ($case=CASE_UPPER) { |
|
| 572 | + $cmd=strtoupper; |
|
| 573 | + } |
|
| 597 | 574 | foreach($array as $key=>$value) { |
| 598 | 575 | $output[$cmd($key)]=$value; |
| 599 | 576 | } |
@@ -18,11 +18,17 @@ discard block |
||
| 18 | 18 | $this->request_time = $_SERVER['REQUEST_TIME'] + $modx->config['server_offset_time']; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | + /** |
|
| 22 | + * @param string $path |
|
| 23 | + */ |
|
| 21 | 24 | function setCachepath($path) |
| 22 | 25 | { |
| 23 | 26 | $this->cachePath = $path; |
| 24 | 27 | } |
| 25 | 28 | |
| 29 | + /** |
|
| 30 | + * @param boolean $bool |
|
| 31 | + */ |
|
| 26 | 32 | function setReport($bool) |
| 27 | 33 | { |
| 28 | 34 | $this->showReport = $bool; |
@@ -45,6 +51,9 @@ discard block |
||
| 45 | 51 | return str_replace($q1, $q2, $s); |
| 46 | 52 | } |
| 47 | 53 | |
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 48 | 57 | function getParents($id, $path = '') |
| 49 | 58 | { // modx:returns child's parent |
| 50 | 59 | global $modx; |
@@ -148,6 +157,9 @@ discard block |
||
| 148 | 157 | } |
| 149 | 158 | } |
| 150 | 159 | |
| 160 | + /** |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 151 | 163 | public function getCacheRefreshTime() |
| 152 | 164 | { |
| 153 | 165 | global $modx; |
@@ -190,7 +202,7 @@ discard block |
||
| 190 | 202 | /** |
| 191 | 203 | * build siteCache file |
| 192 | 204 | * @param DocumentParser $modx |
| 193 | - * @return boolean success |
|
| 205 | + * @return null|boolean success |
|
| 194 | 206 | */ |
| 195 | 207 | public function buildCache($modx) |
| 196 | 208 | { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | if (isset($this->aliases[$id])) { |
| 62 | 62 | if ($this->aliasVisible[$id] == 1) { |
| 63 | 63 | if ($path != '') { |
| 64 | - $path = $this->aliases[$id] . '/' . $path; |
|
| 64 | + $path = $this->aliases[$id].'/'.$path; |
|
| 65 | 65 | } else { |
| 66 | 66 | $path = $this->aliases[$id]; |
| 67 | 67 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $modx->messageQuit("Cache path not set."); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $files = glob(realpath($this->cachePath) . '/*.pageCache.php'); |
|
| 83 | + $files = glob(realpath($this->cachePath).'/*.pageCache.php'); |
|
| 84 | 84 | $filesincache = count($files); |
| 85 | 85 | $deletedfiles = array(); |
| 86 | 86 | while ($file = array_shift($files)) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if(function_exists('opcache_get_status')) { |
|
| 96 | + if (function_exists('opcache_get_status')) { |
|
| 97 | 97 | $opcache = opcache_get_status(); |
| 98 | 98 | if (!empty($opcache['opcache_enabled'])) { |
| 99 | 99 | opcache_reset(); |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | if (isset($opcache)) { |
| 114 | 114 | echo '<p>Opcache empty.</p>'; |
| 115 | 115 | } |
| 116 | - echo '<p>' . $_lang['cache_files_deleted'] . '</p><ul>'; |
|
| 116 | + echo '<p>'.$_lang['cache_files_deleted'].'</p><ul>'; |
|
| 117 | 117 | foreach ($deletedfiles as $deletedfile) { |
| 118 | - echo '<li>' . $deletedfile . '</li>'; |
|
| 118 | + echo '<li>'.$deletedfile.'</li>'; |
|
| 119 | 119 | } |
| 120 | 120 | echo '</ul>'; |
| 121 | 121 | } |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | // write the file |
| 134 | - $content = '<?php' . "\n"; |
|
| 135 | - $content .= '$recent_update=\'' . $this->request_time . '\';' . "\n"; |
|
| 136 | - $content .= '$cacheRefreshTime=\'' . $cacheRefreshTime . '\';' . "\n"; |
|
| 134 | + $content = '<?php'."\n"; |
|
| 135 | + $content .= '$recent_update=\''.$this->request_time.'\';'."\n"; |
|
| 136 | + $content .= '$cacheRefreshTime=\''.$cacheRefreshTime.'\';'."\n"; |
|
| 137 | 137 | |
| 138 | - $filename = $this->cachePath . '/sitePublishing.idx.php'; |
|
| 138 | + $filename = $this->cachePath.'/sitePublishing.idx.php'; |
|
| 139 | 139 | if (!$handle = fopen($filename, 'w')) { |
| 140 | 140 | exit("Cannot open file ({$filename}"); |
| 141 | 141 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // update publish time file |
| 156 | 156 | $timesArr = array(); |
| 157 | 157 | |
| 158 | - $result = $modx->db->select('MIN(pub_date) AS minpub', '[+prefix+]site_content', 'pub_date>' . $this->request_time); |
|
| 158 | + $result = $modx->db->select('MIN(pub_date) AS minpub', '[+prefix+]site_content', 'pub_date>'.$this->request_time); |
|
| 159 | 159 | if (!$result) { |
| 160 | 160 | echo "Couldn't determine next publish event!"; |
| 161 | 161 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $timesArr[] = $minpub; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $result = $modx->db->select('MIN(unpub_date) AS minunpub', '[+prefix+]site_content', 'unpub_date>' . $this->request_time); |
|
| 168 | + $result = $modx->db->select('MIN(unpub_date) AS minunpub', '[+prefix+]site_content', 'unpub_date>'.$this->request_time); |
|
| 169 | 169 | if (!$result) { |
| 170 | 170 | echo "Couldn't determine next unpublish event!"; |
| 171 | 171 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $config = array(); |
| 204 | 204 | $content .= '$c=&$this->config;'; |
| 205 | 205 | while (list($key, $value) = $modx->db->getRow($rs, 'num')) { |
| 206 | - $content .= '$c[\'' . $key . '\']="' . $this->escapeDoubleQuotes($value) . '";'; |
|
| 206 | + $content .= '$c[\''.$key.'\']="'.$this->escapeDoubleQuotes($value).'";'; |
|
| 207 | 207 | $config[$key] = $value; |
| 208 | 208 | } |
| 209 | 209 | |
@@ -241,23 +241,23 @@ discard block |
||
| 241 | 241 | $docid = $doc['id']; |
| 242 | 242 | if ($use_alias_path) { |
| 243 | 243 | $tmpPath = $this->getParents($doc['parent']); |
| 244 | - $alias = (strlen($tmpPath) > 0 ? "$tmpPath/" : '') . $doc['alias']; |
|
| 244 | + $alias = (strlen($tmpPath) > 0 ? "$tmpPath/" : '').$doc['alias']; |
|
| 245 | 245 | $key = $alias; |
| 246 | 246 | } else { |
| 247 | 247 | $key = $doc['alias']; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $doc['path'] = $tmpPath; |
| 251 | - $content .= '$a[' . $docid . ']=array(\'id\'=>' . $docid . ',\'alias\'=>\'' . $doc['alias'] . '\',\'path\'=>\'' . $doc['path'] . '\',\'parent\'=>' . $doc['parent'] . ',\'isfolder\'=>' . $doc['isfolder'] . ',\'alias_visible\'=>' . $doc['alias_visible'] . ');'; |
|
| 252 | - $content .= '$d[\'' . $key . '\']=' . $docid . ';'; |
|
| 253 | - $content .= '$m[]=array(' . $doc['parent'] . '=>' . $docid . ');'; |
|
| 251 | + $content .= '$a['.$docid.']=array(\'id\'=>'.$docid.',\'alias\'=>\''.$doc['alias'].'\',\'path\'=>\''.$doc['path'].'\',\'parent\'=>'.$doc['parent'].',\'isfolder\'=>'.$doc['isfolder'].',\'alias_visible\'=>'.$doc['alias_visible'].');'; |
|
| 252 | + $content .= '$d[\''.$key.'\']='.$docid.';'; |
|
| 253 | + $content .= '$m[]=array('.$doc['parent'].'=>'.$docid.');'; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // get content types |
| 257 | 257 | $rs = $modx->db->select('id, contentType', '[+prefix+]site_content', "contentType!='text/html'"); |
| 258 | 258 | $content .= '$c=&$this->contentTypes;'; |
| 259 | 259 | while ($doc = $modx->db->getRow($rs)) { |
| 260 | - $content .= '$c[\'' . $doc['id'] . '\']=\'' . $doc['contentType'] . '\';'; |
|
| 260 | + $content .= '$c[\''.$doc['id'].'\']=\''.$doc['contentType'].'\';'; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // WRITE Chunks to cache file |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | if ($modx->config['minifyphp_incache']) { |
| 268 | 268 | $doc['snippet'] = $this->php_strip_whitespace($doc['snippet']); |
| 269 | 269 | } |
| 270 | - $content .= '$c[\'' . $doc['name'] . '\']=\'' . ($doc['disabled'] ? '' : $this->escapeSingleQuotes($doc['snippet'])) . '\';'; |
|
| 270 | + $content .= '$c[\''.$doc['name'].'\']=\''.($doc['disabled'] ? '' : $this->escapeSingleQuotes($doc['snippet'])).'\';'; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // WRITE snippets to cache file |
@@ -278,18 +278,18 @@ discard block |
||
| 278 | 278 | while ($row = $modx->db->getRow($rs)) { |
| 279 | 279 | $key = $row['name']; |
| 280 | 280 | if ($row['disabled']) { |
| 281 | - $content .= '$s[\'' . $key . '\']=\'return false;\';'; |
|
| 281 | + $content .= '$s[\''.$key.'\']=\'return false;\';'; |
|
| 282 | 282 | } else { |
| 283 | 283 | $value = trim($row['snippet']); |
| 284 | 284 | if ($modx->config['minifyphp_incache']) { |
| 285 | 285 | $value = $this->php_strip_whitespace($value); |
| 286 | 286 | } |
| 287 | - $content .= '$s[\'' . $key . '\']=\'' . $this->escapeSingleQuotes($value) . '\';'; |
|
| 287 | + $content .= '$s[\''.$key.'\']=\''.$this->escapeSingleQuotes($value).'\';'; |
|
| 288 | 288 | $properties = $modx->parseProperties($row['properties']); |
| 289 | 289 | $sharedproperties = $modx->parseProperties($row['sharedproperties']); |
| 290 | 290 | $properties = array_merge($sharedproperties, $properties); |
| 291 | 291 | if (0 < count($properties)) { |
| 292 | - $content .= '$s[\'' . $key . 'Props\']=\'' . $this->escapeSingleQuotes(json_encode($properties)) . '\';'; |
|
| 292 | + $content .= '$s[\''.$key.'Props\']=\''.$this->escapeSingleQuotes(json_encode($properties)).'\';'; |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -307,13 +307,13 @@ discard block |
||
| 307 | 307 | if ($modx->config['minifyphp_incache']) { |
| 308 | 308 | $value = $this->php_strip_whitespace($value); |
| 309 | 309 | } |
| 310 | - $content .= '$p[\'' . $key . '\']=\'' . $this->escapeSingleQuotes($value) . '\';'; |
|
| 310 | + $content .= '$p[\''.$key.'\']=\''.$this->escapeSingleQuotes($value).'\';'; |
|
| 311 | 311 | if ($row['properties'] != '' || $row['sharedproperties'] != '') { |
| 312 | 312 | $properties = $modx->parseProperties($row['properties']); |
| 313 | 313 | $sharedproperties = $modx->parseProperties($row['sharedproperties']); |
| 314 | 314 | $properties = array_merge($sharedproperties, $properties); |
| 315 | 315 | if (0 < count($properties)) { |
| 316 | - $content .= '$p[\'' . $key . 'Props\']=\'' . $this->escapeSingleQuotes(json_encode($properties)) . '\';'; |
|
| 316 | + $content .= '$p[\''.$key.'Props\']=\''.$this->escapeSingleQuotes(json_encode($properties)).'\';'; |
|
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | } |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | foreach ($events as $evtname => $pluginnames) { |
| 338 | 338 | $events[$evtname] = $pluginnames; |
| 339 | - $content .= '$e[\'' . $evtname . '\']=array(\'' . implode('\',\'', $this->escapeSingleQuotes($pluginnames)) . '\');'; |
|
| 339 | + $content .= '$e[\''.$evtname.'\']=array(\''.implode('\',\'', $this->escapeSingleQuotes($pluginnames)).'\');'; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | $content .= "\n"; |
| 343 | 343 | |
| 344 | 344 | // close and write the file |
| 345 | - $filename = $this->cachePath . 'siteCache.idx.php'; |
|
| 345 | + $filename = $this->cachePath.'siteCache.idx.php'; |
|
| 346 | 346 | |
| 347 | 347 | // invoke OnBeforeCacheUpdate event |
| 348 | 348 | if ($modx) { |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | exit("Cannot write main MODX cache file! Make sure the assets/cache directory is writable!"); |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if (!is_file($this->cachePath . '/.htaccess')) { |
|
| 357 | - file_put_contents($this->cachePath . '/.htaccess', "order deny,allow\ndeny from all\n"); |
|
| 356 | + if (!is_file($this->cachePath.'/.htaccess')) { |
|
| 357 | + file_put_contents($this->cachePath.'/.htaccess', "order deny,allow\ndeny from all\n"); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // invoke OnCacheUpdate event |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | $source = trim($source); |
| 373 | 373 | if (substr($source, 0, 5) !== '<?php') { |
| 374 | - $source = '<?php ' . $source; |
|
| 374 | + $source = '<?php '.$source; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | $tokens = token_get_all($source); |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | $_ .= $text; |
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | - $source = preg_replace(array('@^<\?php@i', '|\s+|', '|<!--|', '|-->|', '|-->\s+<!--|'), array('', ' ', "\n" . '<!--', '-->' . "\n", '-->' . "\n" . '<!--'), $_); |
|
| 430 | + $source = preg_replace(array('@^<\?php@i', '|\s+|', '|<!--|', '|-->|', '|-->\s+<!--|'), array('', ' ', "\n".'<!--', '-->'."\n", '-->'."\n".'<!--'), $_); |
|
| 431 | 431 | $source = trim($source); |
| 432 | 432 | return $source; |
| 433 | 433 | } |
@@ -46,7 +46,8 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function getParents($id, $path = '') |
| 49 | - { // modx:returns child's parent |
|
| 49 | + { |
|
| 50 | +// modx:returns child's parent |
|
| 50 | 51 | global $modx; |
| 51 | 52 | if (empty($this->aliases)) { |
| 52 | 53 | $f = "id, IF(alias='', id, alias) AS alias, parent, alias_visible"; |
@@ -403,7 +404,8 @@ discard block |
||
| 403 | 404 | $_ = trim($_); |
| 404 | 405 | } |
| 405 | 406 | $lastChar = substr($_, -1); |
| 406 | - if (!in_array($lastChar, $chars)) {// ,320,327,288,284,289 |
|
| 407 | + if (!in_array($lastChar, $chars)) { |
|
| 408 | +// ,320,327,288,284,289 |
|
| 407 | 409 | if (!in_array($prev_token, array(T_FOREACH, T_WHILE, T_FOR, T_BOOLEAN_AND, T_BOOLEAN_OR, T_DOUBLE_ARROW))) { |
| 408 | 410 | $_ .= ' '; |
| 409 | 411 | } |
@@ -170,70 +170,70 @@ |
||
| 170 | 170 | array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
| 171 | 171 | ); |
| 172 | 172 | } |
| 173 | - if (intval($params['shareparams']) || !empty($params['dependencies'])) { |
|
| 174 | - $dependencies = explode(',', $params['dependencies']); |
|
| 175 | - foreach ($dependencies as $dependency) { |
|
| 176 | - $dependency = explode(':', $dependency); |
|
| 177 | - switch (trim($dependency[0])) { |
|
| 178 | - case 'template': |
|
| 179 | - $mdp[] = array( |
|
| 180 | - 'module' => $params['name'], |
|
| 181 | - 'table' => 'templates', |
|
| 182 | - 'column' => 'templatename', |
|
| 183 | - 'type' => 50, |
|
| 184 | - 'name' => trim($dependency[1]) |
|
| 185 | - ); |
|
| 186 | - break; |
|
| 187 | - case 'tv': |
|
| 188 | - case 'tmplvar': |
|
| 189 | - $mdp[] = array( |
|
| 190 | - 'module' => $params['name'], |
|
| 191 | - 'table' => 'tmplvars', |
|
| 192 | - 'column' => 'name', |
|
| 193 | - 'type' => 60, |
|
| 194 | - 'name' => trim($dependency[1]) |
|
| 195 | - ); |
|
| 196 | - break; |
|
| 197 | - case 'chunk': |
|
| 198 | - case 'htmlsnippet': |
|
| 199 | - $mdp[] = array( |
|
| 200 | - 'module' => $params['name'], |
|
| 201 | - 'table' => 'htmlsnippets', |
|
| 202 | - 'column' => 'name', |
|
| 203 | - 'type' => 10, |
|
| 204 | - 'name' => trim($dependency[1]) |
|
| 205 | - ); |
|
| 206 | - break; |
|
| 207 | - case 'snippet': |
|
| 208 | - $mdp[] = array( |
|
| 209 | - 'module' => $params['name'], |
|
| 210 | - 'table' => 'snippets', |
|
| 211 | - 'column' => 'name', |
|
| 212 | - 'type' => 40, |
|
| 213 | - 'name' => trim($dependency[1]) |
|
| 214 | - ); |
|
| 215 | - break; |
|
| 216 | - case 'plugin': |
|
| 217 | - $mdp[] = array( |
|
| 218 | - 'module' => $params['name'], |
|
| 219 | - 'table' => 'plugins', |
|
| 220 | - 'column' => 'name', |
|
| 221 | - 'type' => 30, |
|
| 222 | - 'name' => trim($dependency[1]) |
|
| 223 | - ); |
|
| 224 | - break; |
|
| 225 | - case 'resource': |
|
| 226 | - $mdp[] = array( |
|
| 227 | - 'module' => $params['name'], |
|
| 228 | - 'table' => 'content', |
|
| 229 | - 'column' => 'pagetitle', |
|
| 230 | - 'type' => 20, |
|
| 231 | - 'name' => trim($dependency[1]) |
|
| 232 | - ); |
|
| 233 | - break; |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 173 | + if (intval($params['shareparams']) || !empty($params['dependencies'])) { |
|
| 174 | + $dependencies = explode(',', $params['dependencies']); |
|
| 175 | + foreach ($dependencies as $dependency) { |
|
| 176 | + $dependency = explode(':', $dependency); |
|
| 177 | + switch (trim($dependency[0])) { |
|
| 178 | + case 'template': |
|
| 179 | + $mdp[] = array( |
|
| 180 | + 'module' => $params['name'], |
|
| 181 | + 'table' => 'templates', |
|
| 182 | + 'column' => 'templatename', |
|
| 183 | + 'type' => 50, |
|
| 184 | + 'name' => trim($dependency[1]) |
|
| 185 | + ); |
|
| 186 | + break; |
|
| 187 | + case 'tv': |
|
| 188 | + case 'tmplvar': |
|
| 189 | + $mdp[] = array( |
|
| 190 | + 'module' => $params['name'], |
|
| 191 | + 'table' => 'tmplvars', |
|
| 192 | + 'column' => 'name', |
|
| 193 | + 'type' => 60, |
|
| 194 | + 'name' => trim($dependency[1]) |
|
| 195 | + ); |
|
| 196 | + break; |
|
| 197 | + case 'chunk': |
|
| 198 | + case 'htmlsnippet': |
|
| 199 | + $mdp[] = array( |
|
| 200 | + 'module' => $params['name'], |
|
| 201 | + 'table' => 'htmlsnippets', |
|
| 202 | + 'column' => 'name', |
|
| 203 | + 'type' => 10, |
|
| 204 | + 'name' => trim($dependency[1]) |
|
| 205 | + ); |
|
| 206 | + break; |
|
| 207 | + case 'snippet': |
|
| 208 | + $mdp[] = array( |
|
| 209 | + 'module' => $params['name'], |
|
| 210 | + 'table' => 'snippets', |
|
| 211 | + 'column' => 'name', |
|
| 212 | + 'type' => 40, |
|
| 213 | + 'name' => trim($dependency[1]) |
|
| 214 | + ); |
|
| 215 | + break; |
|
| 216 | + case 'plugin': |
|
| 217 | + $mdp[] = array( |
|
| 218 | + 'module' => $params['name'], |
|
| 219 | + 'table' => 'plugins', |
|
| 220 | + 'column' => 'name', |
|
| 221 | + 'type' => 30, |
|
| 222 | + 'name' => trim($dependency[1]) |
|
| 223 | + ); |
|
| 224 | + break; |
|
| 225 | + case 'resource': |
|
| 226 | + $mdp[] = array( |
|
| 227 | + 'module' => $params['name'], |
|
| 228 | + 'table' => 'content', |
|
| 229 | + 'column' => 'pagetitle', |
|
| 230 | + 'type' => 20, |
|
| 231 | + 'name' => trim($dependency[1]) |
|
| 232 | + ); |
|
| 233 | + break; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | $d->close(); |
| 239 | 239 | } |
@@ -1,33 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //:: EVO Installer Setup file |
| 3 | 3 | //::::::::::::::::::::::::::::::::::::::::: |
| 4 | -if (is_file($base_path . 'assets/cache/siteManager.php')) { |
|
| 5 | - include_once($base_path . 'assets/cache/siteManager.php'); |
|
| 4 | +if (is_file($base_path.'assets/cache/siteManager.php')) { |
|
| 5 | + include_once($base_path.'assets/cache/siteManager.php'); |
|
| 6 | 6 | } |
| 7 | -if(!defined('MGR_DIR')) define('MGR_DIR', 'manager'); |
|
| 7 | +if (!defined('MGR_DIR')) define('MGR_DIR', 'manager'); |
|
| 8 | 8 | |
| 9 | 9 | require_once('../'.MGR_DIR.'/includes/version.inc.php'); |
| 10 | 10 | |
| 11 | -$chunkPath = $base_path .'install/assets/chunks'; |
|
| 12 | -$snippetPath = $base_path .'install/assets/snippets'; |
|
| 13 | -$pluginPath = $base_path .'install/assets/plugins'; |
|
| 14 | -$modulePath = $base_path .'install/assets/modules'; |
|
| 15 | -$templatePath = $base_path .'install/assets/templates'; |
|
| 16 | -$tvPath = $base_path .'install/assets/tvs'; |
|
| 11 | +$chunkPath = $base_path.'install/assets/chunks'; |
|
| 12 | +$snippetPath = $base_path.'install/assets/snippets'; |
|
| 13 | +$pluginPath = $base_path.'install/assets/plugins'; |
|
| 14 | +$modulePath = $base_path.'install/assets/modules'; |
|
| 15 | +$templatePath = $base_path.'install/assets/templates'; |
|
| 16 | +$tvPath = $base_path.'install/assets/tvs'; |
|
| 17 | 17 | |
| 18 | 18 | // setup Template template files - array : name, description, type - 0:file or 1:content, parameters, category |
| 19 | 19 | $mt = &$moduleTemplates; |
| 20 | -if(is_dir($templatePath) && is_readable($templatePath)) { |
|
| 20 | +if (is_dir($templatePath) && is_readable($templatePath)) { |
|
| 21 | 21 | $d = dir($templatePath); |
| 22 | 22 | while (false !== ($tplfile = $d->read())) |
| 23 | 23 | { |
| 24 | - if(substr($tplfile, -4) != '.tpl') continue; |
|
| 24 | + if (substr($tplfile, -4) != '.tpl') continue; |
|
| 25 | 25 | $params = parse_docblock($templatePath, $tplfile); |
| 26 | - if(is_array($params) && (count($params)>0)) |
|
| 26 | + if (is_array($params) && (count($params) > 0)) |
|
| 27 | 27 | { |
| 28 | 28 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 29 | - $mt[] = array |
|
| 30 | - ( |
|
| 29 | + $mt[] = array( |
|
| 31 | 30 | $params['name'], |
| 32 | 31 | $description, |
| 33 | 32 | // Don't think this is gonna be used ... but adding it just in case 'type' |
@@ -45,12 +44,12 @@ discard block |
||
| 45 | 44 | |
| 46 | 45 | // setup Template Variable template files |
| 47 | 46 | $mtv = &$moduleTVs; |
| 48 | -if(is_dir($tvPath) && is_readable($tvPath)) { |
|
| 47 | +if (is_dir($tvPath) && is_readable($tvPath)) { |
|
| 49 | 48 | $d = dir($tvPath); |
| 50 | 49 | while (false !== ($tplfile = $d->read())) { |
| 51 | - if(substr($tplfile, -4) != '.tpl') continue; |
|
| 50 | + if (substr($tplfile, -4) != '.tpl') continue; |
|
| 52 | 51 | $params = parse_docblock($tvPath, $tplfile); |
| 53 | - if(is_array($params) && (count($params)>0)) { |
|
| 52 | + if (is_array($params) && (count($params) > 0)) { |
|
| 54 | 53 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 55 | 54 | $mtv[] = array( |
| 56 | 55 | $params['name'], |
@@ -62,9 +61,9 @@ discard block |
||
| 62 | 61 | $params['output_widget'], |
| 63 | 62 | $params['output_widget_params'], |
| 64 | 63 | "$templatePath/{$params['filename']}", /* not currently used */ |
| 65 | - $params['template_assignments']!="*"?$params['template_assignments']:implode(",",array_map(create_function('$v','return $v[0];'),$mt)), /* comma-separated list of template names */ |
|
| 64 | + $params['template_assignments'] != "*" ? $params['template_assignments'] : implode(",", array_map(create_function('$v', 'return $v[0];'), $mt)), /* comma-separated list of template names */ |
|
| 66 | 65 | $params['modx_category'], |
| 67 | - $params['lock_tv'], /* value should be 1 or 0 */ |
|
| 66 | + $params['lock_tv'], /* value should be 1 or 0 */ |
|
| 68 | 67 | array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
| 69 | 68 | ); |
| 70 | 69 | } |
@@ -74,14 +73,14 @@ discard block |
||
| 74 | 73 | |
| 75 | 74 | // setup chunks template files - array : name, description, type - 0:file or 1:content, file or content |
| 76 | 75 | $mc = &$moduleChunks; |
| 77 | -if(is_dir($chunkPath) && is_readable($chunkPath)) { |
|
| 76 | +if (is_dir($chunkPath) && is_readable($chunkPath)) { |
|
| 78 | 77 | $d = dir($chunkPath); |
| 79 | 78 | while (false !== ($tplfile = $d->read())) { |
| 80 | - if(substr($tplfile, -4) != '.tpl') { |
|
| 79 | + if (substr($tplfile, -4) != '.tpl') { |
|
| 81 | 80 | continue; |
| 82 | 81 | } |
| 83 | 82 | $params = parse_docblock($chunkPath, $tplfile); |
| 84 | - if(is_array($params) && count($params) > 0) { |
|
| 83 | + if (is_array($params) && count($params) > 0) { |
|
| 85 | 84 | $mc[] = array( |
| 86 | 85 | $params['name'], |
| 87 | 86 | $params['description'], |
@@ -97,14 +96,14 @@ discard block |
||
| 97 | 96 | |
| 98 | 97 | // setup snippets template files - array : name, description, type - 0:file or 1:content, file or content,properties |
| 99 | 98 | $ms = &$moduleSnippets; |
| 100 | -if(is_dir($snippetPath) && is_readable($snippetPath)) { |
|
| 99 | +if (is_dir($snippetPath) && is_readable($snippetPath)) { |
|
| 101 | 100 | $d = dir($snippetPath); |
| 102 | 101 | while (false !== ($tplfile = $d->read())) { |
| 103 | - if(substr($tplfile, -4) != '.tpl') { |
|
| 102 | + if (substr($tplfile, -4) != '.tpl') { |
|
| 104 | 103 | continue; |
| 105 | 104 | } |
| 106 | 105 | $params = parse_docblock($snippetPath, $tplfile); |
| 107 | - if(is_array($params) && count($params) > 0) { |
|
| 106 | + if (is_array($params) && count($params) > 0) { |
|
| 108 | 107 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 109 | 108 | $ms[] = array( |
| 110 | 109 | $params['name'], |
@@ -121,14 +120,14 @@ discard block |
||
| 121 | 120 | |
| 122 | 121 | // setup plugins template files - array : name, description, type - 0:file or 1:content, file or content,properties |
| 123 | 122 | $mp = &$modulePlugins; |
| 124 | -if(is_dir($pluginPath) && is_readable($pluginPath)) { |
|
| 123 | +if (is_dir($pluginPath) && is_readable($pluginPath)) { |
|
| 125 | 124 | $d = dir($pluginPath); |
| 126 | 125 | while (false !== ($tplfile = $d->read())) { |
| 127 | - if(substr($tplfile, -4) != '.tpl') { |
|
| 126 | + if (substr($tplfile, -4) != '.tpl') { |
|
| 128 | 127 | continue; |
| 129 | 128 | } |
| 130 | 129 | $params = parse_docblock($pluginPath, $tplfile); |
| 131 | - if(is_array($params) && count($params) > 0) { |
|
| 130 | + if (is_array($params) && count($params) > 0) { |
|
| 132 | 131 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 133 | 132 | $mp[] = array( |
| 134 | 133 | $params['name'], |
@@ -150,14 +149,14 @@ discard block |
||
| 150 | 149 | // setup modules - array : name, description, type - 0:file or 1:content, file or content,properties, guid,enable_sharedparams |
| 151 | 150 | $mm = &$moduleModules; |
| 152 | 151 | $mdp = &$moduleDependencies; |
| 153 | -if(is_dir($modulePath) && is_readable($modulePath)) { |
|
| 152 | +if (is_dir($modulePath) && is_readable($modulePath)) { |
|
| 154 | 153 | $d = dir($modulePath); |
| 155 | 154 | while (false !== ($tplfile = $d->read())) { |
| 156 | - if(substr($tplfile, -4) != '.tpl') { |
|
| 155 | + if (substr($tplfile, -4) != '.tpl') { |
|
| 157 | 156 | continue; |
| 158 | 157 | } |
| 159 | 158 | $params = parse_docblock($modulePath, $tplfile); |
| 160 | - if(is_array($params) && count($params) > 0) { |
|
| 159 | + if (is_array($params) && count($params) > 0) { |
|
| 161 | 160 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 162 | 161 | $mm[] = array( |
| 163 | 162 | $params['name'], |
@@ -241,109 +240,109 @@ discard block |
||
| 241 | 240 | // setup callback function |
| 242 | 241 | $callBackFnc = "clean_up"; |
| 243 | 242 | |
| 244 | -function clean_up($sqlParser) { |
|
| 243 | +function clean_up($sqlParser){ |
|
| 245 | 244 | $ids = array(); |
| 246 | 245 | $mysqlVerOk = -1; |
| 247 | 246 | |
| 248 | - if(function_exists("mysqli_get_server_info")) { |
|
| 249 | - $mysqlVerOk = (version_compare(mysqli_get_server_info($sqlParser->conn),"4.0.2")>=0); |
|
| 247 | + if (function_exists("mysqli_get_server_info")) { |
|
| 248 | + $mysqlVerOk = (version_compare(mysqli_get_server_info($sqlParser->conn), "4.0.2") >= 0); |
|
| 250 | 249 | } |
| 251 | 250 | |
| 252 | 251 | // secure web documents - privateweb |
| 253 | - mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 0 WHERE privateweb = 1"); |
|
| 254 | - $sql = "SELECT DISTINCT sc.id |
|
| 252 | + mysqli_query($sqlParser->conn, "UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 0 WHERE privateweb = 1"); |
|
| 253 | + $sql = "SELECT DISTINCT sc.id |
|
| 255 | 254 | FROM `".$sqlParser->prefix."site_content` sc |
| 256 | 255 | LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id |
| 257 | 256 | LEFT JOIN `".$sqlParser->prefix."webgroup_access` wga ON wga.documentgroup = dg.document_group |
| 258 | 257 | WHERE wga.id>0"; |
| 259 | - $ds = mysqli_query($sqlParser->conn,$sql); |
|
| 260 | - if(!$ds) { |
|
| 258 | + $ds = mysqli_query($sqlParser->conn, $sql); |
|
| 259 | + if (!$ds) { |
|
| 261 | 260 | echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
| 262 | 261 | } |
| 263 | 262 | else { |
| 264 | - while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
| 265 | - if(count($ids)>0) { |
|
| 266 | - mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ",$ids).")"); |
|
| 263 | + while ($r = mysqli_fetch_assoc($ds)) $ids[] = $r["id"]; |
|
| 264 | + if (count($ids) > 0) { |
|
| 265 | + mysqli_query($sqlParser->conn, "UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ", $ids).")"); |
|
| 267 | 266 | unset($ids); |
| 268 | 267 | } |
| 269 | 268 | } |
| 270 | 269 | |
| 271 | 270 | // secure manager documents privatemgr |
| 272 | - mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 0 WHERE privatemgr = 1"); |
|
| 273 | - $sql = "SELECT DISTINCT sc.id |
|
| 271 | + mysqli_query($sqlParser->conn, "UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 0 WHERE privatemgr = 1"); |
|
| 272 | + $sql = "SELECT DISTINCT sc.id |
|
| 274 | 273 | FROM `".$sqlParser->prefix."site_content` sc |
| 275 | 274 | LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id |
| 276 | 275 | LEFT JOIN `".$sqlParser->prefix."membergroup_access` mga ON mga.documentgroup = dg.document_group |
| 277 | 276 | WHERE mga.id>0"; |
| 278 | - $ds = mysqli_query($sqlParser->conn,$sql); |
|
| 279 | - if(!$ds) { |
|
| 277 | + $ds = mysqli_query($sqlParser->conn, $sql); |
|
| 278 | + if (!$ds) { |
|
| 280 | 279 | echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
| 281 | 280 | } |
| 282 | 281 | else { |
| 283 | - while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
| 284 | - if(count($ids)>0) { |
|
| 285 | - mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ",$ids).")"); |
|
| 282 | + while ($r = mysqli_fetch_assoc($ds)) $ids[] = $r["id"]; |
|
| 283 | + if (count($ids) > 0) { |
|
| 284 | + mysqli_query($sqlParser->conn, "UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ", $ids).")"); |
|
| 286 | 285 | unset($ids); |
| 287 | 286 | } |
| 288 | 287 | } |
| 289 | 288 | } |
| 290 | 289 | |
| 291 | -function parse_docblock($element_dir, $filename) { |
|
| 290 | +function parse_docblock($element_dir, $filename){ |
|
| 292 | 291 | $params = array(); |
| 293 | - $fullpath = $element_dir . '/' . $filename; |
|
| 294 | - if(is_readable($fullpath)) { |
|
| 292 | + $fullpath = $element_dir.'/'.$filename; |
|
| 293 | + if (is_readable($fullpath)) { |
|
| 295 | 294 | $tpl = @fopen($fullpath, "r"); |
| 296 | - if($tpl) { |
|
| 295 | + if ($tpl) { |
|
| 297 | 296 | $params['filename'] = $filename; |
| 298 | 297 | $docblock_start_found = false; |
| 299 | 298 | $name_found = false; |
| 300 | 299 | $description_found = false; |
| 301 | 300 | $docblock_end_found = false; |
| 302 | 301 | |
| 303 | - while(!feof($tpl)) { |
|
| 302 | + while (!feof($tpl)) { |
|
| 304 | 303 | $line = fgets($tpl); |
| 305 | - if(!$docblock_start_found) { |
|
| 304 | + if (!$docblock_start_found) { |
|
| 306 | 305 | // find docblock start |
| 307 | - if(strpos($line, '/**') !== false) { |
|
| 306 | + if (strpos($line, '/**') !== false) { |
|
| 308 | 307 | $docblock_start_found = true; |
| 309 | 308 | } |
| 310 | 309 | continue; |
| 311 | - } elseif(!$name_found) { |
|
| 310 | + } elseif (!$name_found) { |
|
| 312 | 311 | // find name |
| 313 | 312 | $ma = null; |
| 314 | - if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
| 313 | + if (preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
| 315 | 314 | $params['name'] = trim($ma[1]); |
| 316 | 315 | $name_found = !empty($params['name']); |
| 317 | 316 | } |
| 318 | 317 | continue; |
| 319 | - } elseif(!$description_found) { |
|
| 318 | + } elseif (!$description_found) { |
|
| 320 | 319 | // find description |
| 321 | 320 | $ma = null; |
| 322 | - if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
| 321 | + if (preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
| 323 | 322 | $params['description'] = trim($ma[1]); |
| 324 | 323 | $description_found = !empty($params['description']); |
| 325 | 324 | } |
| 326 | 325 | continue; |
| 327 | 326 | } else { |
| 328 | 327 | $ma = null; |
| 329 | - if(preg_match("/^\s+\*\s+\@([^\s]+)\s+(.+)/", $line, $ma)) { |
|
| 328 | + if (preg_match("/^\s+\*\s+\@([^\s]+)\s+(.+)/", $line, $ma)) { |
|
| 330 | 329 | $param = trim($ma[1]); |
| 331 | 330 | $val = trim($ma[2]); |
| 332 | - if(!empty($param) && !empty($val)) { |
|
| 333 | - if($param == 'internal') { |
|
| 331 | + if (!empty($param) && !empty($val)) { |
|
| 332 | + if ($param == 'internal') { |
|
| 334 | 333 | $ma = null; |
| 335 | - if(preg_match("/\@([^\s]+)\s+(.+)/", $val, $ma)) { |
|
| 334 | + if (preg_match("/\@([^\s]+)\s+(.+)/", $val, $ma)) { |
|
| 336 | 335 | $param = trim($ma[1]); |
| 337 | 336 | $val = trim($ma[2]); |
| 338 | 337 | } |
| 339 | 338 | //if($val !== '0' && (empty($param) || empty($val))) { |
| 340 | - if(empty($param)) { |
|
| 339 | + if (empty($param)) { |
|
| 341 | 340 | continue; |
| 342 | 341 | } |
| 343 | 342 | } |
| 344 | 343 | $params[$param] = $val; |
| 345 | 344 | } |
| 346 | - } elseif(preg_match("/^\s*\*\/\s*$/", $line)) { |
|
| 345 | + } elseif (preg_match("/^\s*\*\/\s*$/", $line)) { |
|
| 347 | 346 | $docblock_end_found = true; |
| 348 | 347 | break; |
| 349 | 348 | } |
@@ -4,7 +4,9 @@ discard block |
||
| 4 | 4 | if (is_file($base_path . 'assets/cache/siteManager.php')) { |
| 5 | 5 | include_once($base_path . 'assets/cache/siteManager.php'); |
| 6 | 6 | } |
| 7 | -if(!defined('MGR_DIR')) define('MGR_DIR', 'manager'); |
|
| 7 | +if(!defined('MGR_DIR')) { |
|
| 8 | + define('MGR_DIR', 'manager'); |
|
| 9 | +} |
|
| 8 | 10 | |
| 9 | 11 | require_once('../'.MGR_DIR.'/includes/version.inc.php'); |
| 10 | 12 | |
@@ -19,12 +21,12 @@ discard block |
||
| 19 | 21 | $mt = &$moduleTemplates; |
| 20 | 22 | if(is_dir($templatePath) && is_readable($templatePath)) { |
| 21 | 23 | $d = dir($templatePath); |
| 22 | - while (false !== ($tplfile = $d->read())) |
|
| 23 | - { |
|
| 24 | - if(substr($tplfile, -4) != '.tpl') continue; |
|
| 24 | + while (false !== ($tplfile = $d->read())) { |
|
| 25 | + if(substr($tplfile, -4) != '.tpl') { |
|
| 26 | + continue; |
|
| 27 | + } |
|
| 25 | 28 | $params = parse_docblock($templatePath, $tplfile); |
| 26 | - if(is_array($params) && (count($params)>0)) |
|
| 27 | - { |
|
| 29 | + if(is_array($params) && (count($params)>0)) { |
|
| 28 | 30 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
| 29 | 31 | $mt[] = array |
| 30 | 32 | ( |
@@ -48,7 +50,9 @@ discard block |
||
| 48 | 50 | if(is_dir($tvPath) && is_readable($tvPath)) { |
| 49 | 51 | $d = dir($tvPath); |
| 50 | 52 | while (false !== ($tplfile = $d->read())) { |
| 51 | - if(substr($tplfile, -4) != '.tpl') continue; |
|
| 53 | + if(substr($tplfile, -4) != '.tpl') { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 52 | 56 | $params = parse_docblock($tvPath, $tplfile); |
| 53 | 57 | if(is_array($params) && (count($params)>0)) { |
| 54 | 58 | $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
@@ -241,7 +245,8 @@ discard block |
||
| 241 | 245 | // setup callback function |
| 242 | 246 | $callBackFnc = "clean_up"; |
| 243 | 247 | |
| 244 | -function clean_up($sqlParser) { |
|
| 248 | +function clean_up($sqlParser) |
|
| 249 | +{ |
|
| 245 | 250 | $ids = array(); |
| 246 | 251 | $mysqlVerOk = -1; |
| 247 | 252 | |
@@ -259,9 +264,10 @@ discard block |
||
| 259 | 264 | $ds = mysqli_query($sqlParser->conn,$sql); |
| 260 | 265 | if(!$ds) { |
| 261 | 266 | echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
| 262 | - } |
|
| 263 | - else { |
|
| 264 | - while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
| 267 | + } else { |
|
| 268 | + while($r = mysqli_fetch_assoc($ds)) { |
|
| 269 | + $ids[]=$r["id"]; |
|
| 270 | + } |
|
| 265 | 271 | if(count($ids)>0) { |
| 266 | 272 | mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ",$ids).")"); |
| 267 | 273 | unset($ids); |
@@ -278,9 +284,10 @@ discard block |
||
| 278 | 284 | $ds = mysqli_query($sqlParser->conn,$sql); |
| 279 | 285 | if(!$ds) { |
| 280 | 286 | echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
| 281 | - } |
|
| 282 | - else { |
|
| 283 | - while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
| 287 | + } else { |
|
| 288 | + while($r = mysqli_fetch_assoc($ds)) { |
|
| 289 | + $ids[]=$r["id"]; |
|
| 290 | + } |
|
| 284 | 291 | if(count($ids)>0) { |
| 285 | 292 | mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ",$ids).")"); |
| 286 | 293 | unset($ids); |
@@ -288,7 +295,8 @@ discard block |
||
| 288 | 295 | } |
| 289 | 296 | } |
| 290 | 297 | |
| 291 | -function parse_docblock($element_dir, $filename) { |
|
| 298 | +function parse_docblock($element_dir, $filename) |
|
| 299 | +{ |
|
| 292 | 300 | $params = array(); |
| 293 | 301 | $fullpath = $element_dir . '/' . $filename; |
| 294 | 302 | if(is_readable($fullpath)) { |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | $params['modx_category'], |
| 37 | 37 | $params['lock_template'], |
| 38 | 38 | array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false, |
| 39 | - isset($params['save_sql_id_as']) ? $params['save_sql_id_as'] : NULL // Nessecary to fix template-ID for demo-site |
|
| 39 | + isset($params['save_sql_id_as']) ? $params['save_sql_id_as'] : null // Nessecary to fix template-ID for demo-site |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | <form name="install" id="install_form" action="index.php?action=options" method="post"> |
| 21 | 21 | <?php |
| 22 | 22 | if ($errors == 0) { |
| 23 | - // check if install folder is removeable |
|
| 23 | + // check if install folder is removeable |
|
| 24 | 24 | if (is_writable("../install")) { ?> |
| 25 | 25 | <span id="removeinstall" style="float:left;cursor:pointer;color:#505050;line-height:18px;" onclick="var chk=document.install.rminstaller; if(chk) chk.checked=!chk.checked;"><input type="checkbox" name="rminstaller" onclick="event.cancelBubble=true;" <?php echo (empty ($errors) ? 'checked="checked"' : '') ?> style="cursor:default;" /><?php echo $_lang['remove_install_folder_auto'] ?></span> |
| 26 | 26 | <?php |
@@ -43,10 +43,10 @@ |
||
| 43 | 43 | var chk = document.install.rminstaller; |
| 44 | 44 | if(chk && chk.checked) { |
| 45 | 45 | // remove install folder and files |
| 46 | - window.location.href = "../<?php echo MGR_DIR;?>/processors/remove_installer.processor.php?rminstall=1"; |
|
| 46 | + window.location.href = "../<?php echo MGR_DIR; ?>/processors/remove_installer.processor.php?rminstall=1"; |
|
| 47 | 47 | } |
| 48 | 48 | else { |
| 49 | - window.location.href = "../<?php echo MGR_DIR;?>/"; |
|
| 49 | + window.location.href = "../<?php echo MGR_DIR; ?>/"; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | /* ]]> */ |