@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | $current_path = __FILE__; |
| 31 | 31 | if (DIRECTORY_SEPARATOR !== '/') { |
| 32 | - $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 32 | + $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 33 | 33 | } |
| 34 | 34 | $url_arr = explode('/', strstr($current_path, '/modules/')); |
| 35 | 35 | include XOOPS_ROOT_PATH . '/modules/' . $url_arr[2] . '/include/vars.php'; |
@@ -8,13 +8,13 @@ |
||
| 8 | 8 | |
| 9 | 9 | $current_path = __FILE__; |
| 10 | 10 | if (DIRECTORY_SEPARATOR !== '/') { |
| 11 | - $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 11 | + $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 12 | 12 | } |
| 13 | 13 | $url_arr = explode('/', strstr($current_path, '/modules/')); |
| 14 | 14 | include XOOPS_ROOT_PATH . '/modules/' . $url_arr[2] . '/include/vars.php'; |
| 15 | 15 | |
| 16 | 16 | if (defined($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_MAIN')) { |
| 17 | - return; |
|
| 17 | + return; |
|
| 18 | 18 | } |
| 19 | 19 | define($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_MAIN', 1); |
| 20 | 20 | |
@@ -8,13 +8,13 @@ |
||
| 8 | 8 | |
| 9 | 9 | $current_path = __FILE__; |
| 10 | 10 | if (DIRECTORY_SEPARATOR !== '/') { |
| 11 | - $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 11 | + $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 12 | 12 | } |
| 13 | 13 | $url_arr = explode('/', strstr($current_path, '/modules/')); |
| 14 | 14 | include XOOPS_ROOT_PATH . '/modules/' . $url_arr[2] . '/include/vars.php'; |
| 15 | 15 | |
| 16 | 16 | if (defined($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_ADMIN')) { |
| 17 | - return; |
|
| 17 | + return; |
|
| 18 | 18 | } |
| 19 | 19 | define($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_ADMIN', 1); |
| 20 | 20 | |
@@ -8,13 +8,13 @@ |
||
| 8 | 8 | |
| 9 | 9 | $current_path = __FILE__; |
| 10 | 10 | if (DIRECTORY_SEPARATOR !== '/') { |
| 11 | - $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 11 | + $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 12 | 12 | } |
| 13 | 13 | $url_arr = explode('/', strstr($current_path, '/modules/')); |
| 14 | 14 | include XOOPS_ROOT_PATH . '/modules/' . $url_arr[2] . '/include/vars.php'; |
| 15 | 15 | |
| 16 | 16 | if (defined($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_BLOCKS')) { |
| 17 | - return; |
|
| 17 | + return; |
|
| 18 | 18 | } |
| 19 | 19 | define($GLOBALS['VAR_PREFIXU'] . '_LANG_EN_BLOCKS', 1); |
| 20 | 20 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * IXR_Message constructor. |
| 173 | - * @param $message |
|
| 173 | + * @param string|boolean $message |
|
| 174 | 174 | */ |
| 175 | 175 | public function __construct($message) |
| 176 | 176 | { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | /** |
| 899 | 899 | * IXR_Base64 constructor. |
| 900 | - * @param $data |
|
| 900 | + * @param string $data |
|
| 901 | 901 | */ |
| 902 | 902 | public function __construct($data) |
| 903 | 903 | { |
@@ -939,10 +939,10 @@ discard block |
||
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * @param $method |
|
| 943 | - * @param $callback |
|
| 944 | - * @param $args |
|
| 945 | - * @param $help |
|
| 942 | + * @param string $method |
|
| 943 | + * @param string $callback |
|
| 944 | + * @param string[] $args |
|
| 945 | + * @param string $help |
|
| 946 | 946 | */ |
| 947 | 947 | public function addCallback($method, $callback, $args, $help) |
| 948 | 948 | { |
@@ -14,136 +14,136 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class IXR_Value |
| 16 | 16 | { |
| 17 | - public $data; |
|
| 18 | - public $type; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * IXR_Value constructor. |
|
| 22 | - * @param $data |
|
| 23 | - * @param bool $type |
|
| 24 | - */ |
|
| 25 | - public function __construct($data, $type = false) |
|
| 26 | - { |
|
| 27 | - $this->data = $data; |
|
| 28 | - if (!$type) { |
|
| 29 | - $type = $this->calculateType(); |
|
| 30 | - } |
|
| 31 | - $this->type = $type; |
|
| 32 | - if ('struct' === $type) { |
|
| 33 | - /* Turn all the values in the array in to new IXR_Value objects */ |
|
| 34 | - foreach ($this->data as $key => $value) { |
|
| 35 | - $this->data[$key] = new IXR_Value($value); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - if ('array' === $type) { |
|
| 39 | - for ($i = 0, $j = count($this->data); $i < $j; ++$i) { |
|
| 40 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function calculateType() |
|
| 49 | - { |
|
| 50 | - if (true === $this->data || false === $this->data) { |
|
| 51 | - return 'boolean'; |
|
| 52 | - } |
|
| 53 | - if (is_int($this->data)) { |
|
| 54 | - return 'int'; |
|
| 55 | - } |
|
| 56 | - if (is_float($this->data)) { |
|
| 57 | - return 'double'; |
|
| 58 | - } |
|
| 59 | - // Deal with IXR object types base64 and date |
|
| 60 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 61 | - return 'date'; |
|
| 62 | - } |
|
| 63 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 64 | - return 'base64'; |
|
| 65 | - } |
|
| 66 | - // If it is a normal PHP object convert it in to a struct |
|
| 67 | - if (is_object($this->data)) { |
|
| 68 | - $this->data = get_object_vars($this->data); |
|
| 69 | - |
|
| 70 | - return 'struct'; |
|
| 71 | - } |
|
| 72 | - if (!is_array($this->data)) { |
|
| 73 | - return 'string'; |
|
| 74 | - } |
|
| 75 | - /* We have an array - is it an array or a struct ? */ |
|
| 76 | - if ($this->isStruct($this->data)) { |
|
| 77 | - return 'struct'; |
|
| 78 | - } else { |
|
| 79 | - return 'array'; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return bool|string |
|
| 85 | - */ |
|
| 86 | - public function getXml() |
|
| 87 | - { |
|
| 88 | - /* Return XML for this value */ |
|
| 89 | - switch ($this->type) { |
|
| 90 | - case 'boolean': |
|
| 91 | - return '<boolean>' . ($this->data ? '1' : '0') . '</boolean>'; |
|
| 92 | - break; |
|
| 93 | - case 'int': |
|
| 94 | - return '<int>' . $this->data . '</int>'; |
|
| 95 | - break; |
|
| 96 | - case 'double': |
|
| 97 | - return '<double>' . $this->data . '</double>'; |
|
| 98 | - break; |
|
| 99 | - case 'string': |
|
| 100 | - return '<string>' . htmlspecialchars($this->data, ENT_QUOTES | ENT_HTML5) . '</string>'; |
|
| 101 | - break; |
|
| 102 | - case 'array': |
|
| 103 | - $return = '<array><data>' . "\n"; |
|
| 104 | - foreach ($this->data as $item) { |
|
| 105 | - $return .= ' <value>' . $item->getXml() . "</value>\n"; |
|
| 106 | - } |
|
| 107 | - $return .= '</data></array>'; |
|
| 108 | - |
|
| 109 | - return $return; |
|
| 110 | - break; |
|
| 111 | - case 'struct': |
|
| 112 | - $return = '<struct>' . "\n"; |
|
| 113 | - foreach ($this->data as $name => $value) { |
|
| 114 | - $return .= " <member><name>$name</name><value>"; |
|
| 115 | - $return .= $value->getXml() . "</value></member>\n"; |
|
| 116 | - } |
|
| 117 | - $return .= '</struct>'; |
|
| 118 | - |
|
| 119 | - return $return; |
|
| 120 | - break; |
|
| 121 | - case 'date': |
|
| 122 | - case 'base64': |
|
| 123 | - return $this->data->getXml(); |
|
| 124 | - break; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param $array |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function isStruct($array) |
|
| 135 | - { |
|
| 136 | - /* Nasty function to check if an array is a struct or not */ |
|
| 137 | - $expected = 0; |
|
| 138 | - foreach ($array as $key => $value) { |
|
| 139 | - if ((string)$key != (string)$expected) { |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - ++$expected; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 17 | + public $data; |
|
| 18 | + public $type; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * IXR_Value constructor. |
|
| 22 | + * @param $data |
|
| 23 | + * @param bool $type |
|
| 24 | + */ |
|
| 25 | + public function __construct($data, $type = false) |
|
| 26 | + { |
|
| 27 | + $this->data = $data; |
|
| 28 | + if (!$type) { |
|
| 29 | + $type = $this->calculateType(); |
|
| 30 | + } |
|
| 31 | + $this->type = $type; |
|
| 32 | + if ('struct' === $type) { |
|
| 33 | + /* Turn all the values in the array in to new IXR_Value objects */ |
|
| 34 | + foreach ($this->data as $key => $value) { |
|
| 35 | + $this->data[$key] = new IXR_Value($value); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + if ('array' === $type) { |
|
| 39 | + for ($i = 0, $j = count($this->data); $i < $j; ++$i) { |
|
| 40 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function calculateType() |
|
| 49 | + { |
|
| 50 | + if (true === $this->data || false === $this->data) { |
|
| 51 | + return 'boolean'; |
|
| 52 | + } |
|
| 53 | + if (is_int($this->data)) { |
|
| 54 | + return 'int'; |
|
| 55 | + } |
|
| 56 | + if (is_float($this->data)) { |
|
| 57 | + return 'double'; |
|
| 58 | + } |
|
| 59 | + // Deal with IXR object types base64 and date |
|
| 60 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 61 | + return 'date'; |
|
| 62 | + } |
|
| 63 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 64 | + return 'base64'; |
|
| 65 | + } |
|
| 66 | + // If it is a normal PHP object convert it in to a struct |
|
| 67 | + if (is_object($this->data)) { |
|
| 68 | + $this->data = get_object_vars($this->data); |
|
| 69 | + |
|
| 70 | + return 'struct'; |
|
| 71 | + } |
|
| 72 | + if (!is_array($this->data)) { |
|
| 73 | + return 'string'; |
|
| 74 | + } |
|
| 75 | + /* We have an array - is it an array or a struct ? */ |
|
| 76 | + if ($this->isStruct($this->data)) { |
|
| 77 | + return 'struct'; |
|
| 78 | + } else { |
|
| 79 | + return 'array'; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return bool|string |
|
| 85 | + */ |
|
| 86 | + public function getXml() |
|
| 87 | + { |
|
| 88 | + /* Return XML for this value */ |
|
| 89 | + switch ($this->type) { |
|
| 90 | + case 'boolean': |
|
| 91 | + return '<boolean>' . ($this->data ? '1' : '0') . '</boolean>'; |
|
| 92 | + break; |
|
| 93 | + case 'int': |
|
| 94 | + return '<int>' . $this->data . '</int>'; |
|
| 95 | + break; |
|
| 96 | + case 'double': |
|
| 97 | + return '<double>' . $this->data . '</double>'; |
|
| 98 | + break; |
|
| 99 | + case 'string': |
|
| 100 | + return '<string>' . htmlspecialchars($this->data, ENT_QUOTES | ENT_HTML5) . '</string>'; |
|
| 101 | + break; |
|
| 102 | + case 'array': |
|
| 103 | + $return = '<array><data>' . "\n"; |
|
| 104 | + foreach ($this->data as $item) { |
|
| 105 | + $return .= ' <value>' . $item->getXml() . "</value>\n"; |
|
| 106 | + } |
|
| 107 | + $return .= '</data></array>'; |
|
| 108 | + |
|
| 109 | + return $return; |
|
| 110 | + break; |
|
| 111 | + case 'struct': |
|
| 112 | + $return = '<struct>' . "\n"; |
|
| 113 | + foreach ($this->data as $name => $value) { |
|
| 114 | + $return .= " <member><name>$name</name><value>"; |
|
| 115 | + $return .= $value->getXml() . "</value></member>\n"; |
|
| 116 | + } |
|
| 117 | + $return .= '</struct>'; |
|
| 118 | + |
|
| 119 | + return $return; |
|
| 120 | + break; |
|
| 121 | + case 'date': |
|
| 122 | + case 'base64': |
|
| 123 | + return $this->data->getXml(); |
|
| 124 | + break; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param $array |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function isStruct($array) |
|
| 135 | + { |
|
| 136 | + /* Nasty function to check if an array is a struct or not */ |
|
| 137 | + $expected = 0; |
|
| 138 | + foreach ($array as $key => $value) { |
|
| 139 | + if ((string)$key != (string)$expected) { |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + ++$expected; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -151,189 +151,189 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | class IXR_Message |
| 153 | 153 | { |
| 154 | - public $message; |
|
| 155 | - public $messageType; // methodCall / methodResponse / fault |
|
| 156 | - public $faultCode; |
|
| 157 | - public $faultString; |
|
| 158 | - public $methodName; |
|
| 159 | - public $params; |
|
| 160 | - // Current variable stacks |
|
| 161 | - public $_arraystructs = []; // The stack used to keep track of the current array/struct |
|
| 162 | - public $_arraystructstypes = []; // Stack keeping track of if things are structs or array |
|
| 163 | - public $_currentStructName = []; // A stack as well |
|
| 164 | - public $_param; |
|
| 165 | - public $_value; |
|
| 166 | - public $_currentTag; |
|
| 167 | - public $_currentTagContents; |
|
| 168 | - // The XML parser |
|
| 169 | - public $_parser; |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * IXR_Message constructor. |
|
| 173 | - * @param $message |
|
| 174 | - */ |
|
| 175 | - public function __construct($message) |
|
| 176 | - { |
|
| 177 | - $this->message = $message; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function parse() |
|
| 184 | - { |
|
| 185 | - // first remove the XML declaration |
|
| 186 | - $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); |
|
| 187 | - if ('' == trim($this->message)) { |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - $this->_parser = xml_parser_create(); |
|
| 191 | - // Set XML parser to take the case of tags in to account |
|
| 192 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 193 | - // Set XML parser callback functions |
|
| 194 | - xml_set_object($this->_parser, $this); |
|
| 195 | - xml_set_elementHandler($this->_parser, 'tag_open', 'tag_close'); |
|
| 196 | - xml_set_character_dataHandler($this->_parser, 'cdata'); |
|
| 197 | - if (!xml_parse($this->_parser, $this->message)) { |
|
| 198 | - /* die(sprintf('XML error: %s at line %d', |
|
| 154 | + public $message; |
|
| 155 | + public $messageType; // methodCall / methodResponse / fault |
|
| 156 | + public $faultCode; |
|
| 157 | + public $faultString; |
|
| 158 | + public $methodName; |
|
| 159 | + public $params; |
|
| 160 | + // Current variable stacks |
|
| 161 | + public $_arraystructs = []; // The stack used to keep track of the current array/struct |
|
| 162 | + public $_arraystructstypes = []; // Stack keeping track of if things are structs or array |
|
| 163 | + public $_currentStructName = []; // A stack as well |
|
| 164 | + public $_param; |
|
| 165 | + public $_value; |
|
| 166 | + public $_currentTag; |
|
| 167 | + public $_currentTagContents; |
|
| 168 | + // The XML parser |
|
| 169 | + public $_parser; |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * IXR_Message constructor. |
|
| 173 | + * @param $message |
|
| 174 | + */ |
|
| 175 | + public function __construct($message) |
|
| 176 | + { |
|
| 177 | + $this->message = $message; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function parse() |
|
| 184 | + { |
|
| 185 | + // first remove the XML declaration |
|
| 186 | + $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); |
|
| 187 | + if ('' == trim($this->message)) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + $this->_parser = xml_parser_create(); |
|
| 191 | + // Set XML parser to take the case of tags in to account |
|
| 192 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 193 | + // Set XML parser callback functions |
|
| 194 | + xml_set_object($this->_parser, $this); |
|
| 195 | + xml_set_elementHandler($this->_parser, 'tag_open', 'tag_close'); |
|
| 196 | + xml_set_character_dataHandler($this->_parser, 'cdata'); |
|
| 197 | + if (!xml_parse($this->_parser, $this->message)) { |
|
| 198 | + /* die(sprintf('XML error: %s at line %d', |
|
| 199 | 199 | xml_error_string(xml_get_error_code($this->_parser)), |
| 200 | 200 | xml_get_current_line_number($this->_parser))); */ |
| 201 | 201 | |
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - xml_parser_free($this->_parser); |
|
| 205 | - // Grab the error messages, if any |
|
| 206 | - if ('fault' === $this->messageType) { |
|
| 207 | - $this->faultCode = $this->params[0]['faultCode']; |
|
| 208 | - $this->faultString = $this->params[0]['faultString']; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return true; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param $parser |
|
| 216 | - * @param $tag |
|
| 217 | - * @param $attr |
|
| 218 | - */ |
|
| 219 | - public function tag_open($parser, $tag, $attr) |
|
| 220 | - { |
|
| 221 | - $this->currentTag = $tag; |
|
| 222 | - switch ($tag) { |
|
| 223 | - case 'methodCall': |
|
| 224 | - case 'methodResponse': |
|
| 225 | - case 'fault': |
|
| 226 | - $this->messageType = $tag; |
|
| 227 | - break; |
|
| 228 | - /* Deal with stacks of arrays and structs */ |
|
| 229 | - case 'data': // data is to all intents and puposes more interesting than array |
|
| 230 | - $this->_arraystructstypes[] = 'array'; |
|
| 231 | - $this->_arraystructs[] = []; |
|
| 232 | - break; |
|
| 233 | - case 'struct': |
|
| 234 | - $this->_arraystructstypes[] = 'struct'; |
|
| 235 | - $this->_arraystructs[] = []; |
|
| 236 | - break; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $parser |
|
| 242 | - * @param $cdata |
|
| 243 | - */ |
|
| 244 | - public function cdata($parser, $cdata) |
|
| 245 | - { |
|
| 246 | - $this->_currentTagContents .= $cdata; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param $parser |
|
| 251 | - * @param $tag |
|
| 252 | - */ |
|
| 253 | - public function tag_close($parser, $tag) |
|
| 254 | - { |
|
| 255 | - $valueFlag = false; |
|
| 256 | - switch ($tag) { |
|
| 257 | - case 'int': |
|
| 258 | - case 'i4': |
|
| 259 | - $value = (int)trim($this->_currentTagContents); |
|
| 260 | - $this->_currentTagContents = ''; |
|
| 261 | - $valueFlag = true; |
|
| 262 | - break; |
|
| 263 | - case 'double': |
|
| 264 | - $value = (double)trim($this->_currentTagContents); |
|
| 265 | - $this->_currentTagContents = ''; |
|
| 266 | - $valueFlag = true; |
|
| 267 | - break; |
|
| 268 | - case 'string': |
|
| 269 | - $value = trim($this->_currentTagContents); |
|
| 270 | - $this->_currentTagContents = ''; |
|
| 271 | - $valueFlag = true; |
|
| 272 | - break; |
|
| 273 | - case 'dateTime.iso8601': |
|
| 274 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 275 | - // $value = $iso->getTimestamp(); |
|
| 276 | - $this->_currentTagContents = ''; |
|
| 277 | - $valueFlag = true; |
|
| 278 | - break; |
|
| 279 | - case 'value': |
|
| 280 | - // "If no type is indicated, the type is string." |
|
| 281 | - if ('' != trim($this->_currentTagContents)) { |
|
| 282 | - $value = (string)$this->_currentTagContents; |
|
| 283 | - $this->_currentTagContents = ''; |
|
| 284 | - $valueFlag = true; |
|
| 285 | - } |
|
| 286 | - break; |
|
| 287 | - case 'boolean': |
|
| 288 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 289 | - $this->_currentTagContents = ''; |
|
| 290 | - $valueFlag = true; |
|
| 291 | - break; |
|
| 292 | - case 'base64': |
|
| 293 | - $value = base64_decode(trim($this->_currentTagContents)); |
|
| 294 | - $this->_currentTagContents = ''; |
|
| 295 | - $valueFlag = true; |
|
| 296 | - break; |
|
| 297 | - /* Deal with stacks of arrays and structs */ |
|
| 298 | - case 'data': |
|
| 299 | - case 'struct': |
|
| 300 | - $value = array_pop($this->_arraystructs); |
|
| 301 | - array_pop($this->_arraystructstypes); |
|
| 302 | - $valueFlag = true; |
|
| 303 | - break; |
|
| 304 | - case 'member': |
|
| 305 | - array_pop($this->_currentStructName); |
|
| 306 | - break; |
|
| 307 | - case 'name': |
|
| 308 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 309 | - $this->_currentTagContents = ''; |
|
| 310 | - break; |
|
| 311 | - case 'methodName': |
|
| 312 | - $this->methodName = trim($this->_currentTagContents); |
|
| 313 | - $this->_currentTagContents = ''; |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - if ($valueFlag) { |
|
| 317 | - /* |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + xml_parser_free($this->_parser); |
|
| 205 | + // Grab the error messages, if any |
|
| 206 | + if ('fault' === $this->messageType) { |
|
| 207 | + $this->faultCode = $this->params[0]['faultCode']; |
|
| 208 | + $this->faultString = $this->params[0]['faultString']; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return true; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param $parser |
|
| 216 | + * @param $tag |
|
| 217 | + * @param $attr |
|
| 218 | + */ |
|
| 219 | + public function tag_open($parser, $tag, $attr) |
|
| 220 | + { |
|
| 221 | + $this->currentTag = $tag; |
|
| 222 | + switch ($tag) { |
|
| 223 | + case 'methodCall': |
|
| 224 | + case 'methodResponse': |
|
| 225 | + case 'fault': |
|
| 226 | + $this->messageType = $tag; |
|
| 227 | + break; |
|
| 228 | + /* Deal with stacks of arrays and structs */ |
|
| 229 | + case 'data': // data is to all intents and puposes more interesting than array |
|
| 230 | + $this->_arraystructstypes[] = 'array'; |
|
| 231 | + $this->_arraystructs[] = []; |
|
| 232 | + break; |
|
| 233 | + case 'struct': |
|
| 234 | + $this->_arraystructstypes[] = 'struct'; |
|
| 235 | + $this->_arraystructs[] = []; |
|
| 236 | + break; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $parser |
|
| 242 | + * @param $cdata |
|
| 243 | + */ |
|
| 244 | + public function cdata($parser, $cdata) |
|
| 245 | + { |
|
| 246 | + $this->_currentTagContents .= $cdata; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param $parser |
|
| 251 | + * @param $tag |
|
| 252 | + */ |
|
| 253 | + public function tag_close($parser, $tag) |
|
| 254 | + { |
|
| 255 | + $valueFlag = false; |
|
| 256 | + switch ($tag) { |
|
| 257 | + case 'int': |
|
| 258 | + case 'i4': |
|
| 259 | + $value = (int)trim($this->_currentTagContents); |
|
| 260 | + $this->_currentTagContents = ''; |
|
| 261 | + $valueFlag = true; |
|
| 262 | + break; |
|
| 263 | + case 'double': |
|
| 264 | + $value = (double)trim($this->_currentTagContents); |
|
| 265 | + $this->_currentTagContents = ''; |
|
| 266 | + $valueFlag = true; |
|
| 267 | + break; |
|
| 268 | + case 'string': |
|
| 269 | + $value = trim($this->_currentTagContents); |
|
| 270 | + $this->_currentTagContents = ''; |
|
| 271 | + $valueFlag = true; |
|
| 272 | + break; |
|
| 273 | + case 'dateTime.iso8601': |
|
| 274 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 275 | + // $value = $iso->getTimestamp(); |
|
| 276 | + $this->_currentTagContents = ''; |
|
| 277 | + $valueFlag = true; |
|
| 278 | + break; |
|
| 279 | + case 'value': |
|
| 280 | + // "If no type is indicated, the type is string." |
|
| 281 | + if ('' != trim($this->_currentTagContents)) { |
|
| 282 | + $value = (string)$this->_currentTagContents; |
|
| 283 | + $this->_currentTagContents = ''; |
|
| 284 | + $valueFlag = true; |
|
| 285 | + } |
|
| 286 | + break; |
|
| 287 | + case 'boolean': |
|
| 288 | + $value = (boolean)trim($this->_currentTagContents); |
|
| 289 | + $this->_currentTagContents = ''; |
|
| 290 | + $valueFlag = true; |
|
| 291 | + break; |
|
| 292 | + case 'base64': |
|
| 293 | + $value = base64_decode(trim($this->_currentTagContents)); |
|
| 294 | + $this->_currentTagContents = ''; |
|
| 295 | + $valueFlag = true; |
|
| 296 | + break; |
|
| 297 | + /* Deal with stacks of arrays and structs */ |
|
| 298 | + case 'data': |
|
| 299 | + case 'struct': |
|
| 300 | + $value = array_pop($this->_arraystructs); |
|
| 301 | + array_pop($this->_arraystructstypes); |
|
| 302 | + $valueFlag = true; |
|
| 303 | + break; |
|
| 304 | + case 'member': |
|
| 305 | + array_pop($this->_currentStructName); |
|
| 306 | + break; |
|
| 307 | + case 'name': |
|
| 308 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 309 | + $this->_currentTagContents = ''; |
|
| 310 | + break; |
|
| 311 | + case 'methodName': |
|
| 312 | + $this->methodName = trim($this->_currentTagContents); |
|
| 313 | + $this->_currentTagContents = ''; |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + if ($valueFlag) { |
|
| 317 | + /* |
|
| 318 | 318 | if (!is_array($value) && !is_object($value)) { |
| 319 | 319 | $value = trim($value); |
| 320 | 320 | } |
| 321 | 321 | */ |
| 322 | - if (count($this->_arraystructs) > 0) { |
|
| 323 | - // Add value to struct or array |
|
| 324 | - if ('struct' === $this->_arraystructstypes[count($this->_arraystructstypes) - 1]) { |
|
| 325 | - // Add to struct |
|
| 326 | - $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 327 | - } else { |
|
| 328 | - // Add to array |
|
| 329 | - $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 330 | - } |
|
| 331 | - } else { |
|
| 332 | - // Just add as a paramater |
|
| 333 | - $this->params[] = $value; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 322 | + if (count($this->_arraystructs) > 0) { |
|
| 323 | + // Add value to struct or array |
|
| 324 | + if ('struct' === $this->_arraystructstypes[count($this->_arraystructstypes) - 1]) { |
|
| 325 | + // Add to struct |
|
| 326 | + $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 327 | + } else { |
|
| 328 | + // Add to array |
|
| 329 | + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 330 | + } |
|
| 331 | + } else { |
|
| 332 | + // Just add as a paramater |
|
| 333 | + $this->params[] = $value; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -341,55 +341,55 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | class IXR_Server |
| 343 | 343 | { |
| 344 | - public $data; |
|
| 345 | - public $callbacks = []; |
|
| 346 | - public $message; |
|
| 347 | - public $capabilities; |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * IXR_Server constructor. |
|
| 351 | - * @param bool $callbacks |
|
| 352 | - * @param bool $data |
|
| 353 | - */ |
|
| 354 | - public function __construct($callbacks = false, $data = false) |
|
| 355 | - { |
|
| 356 | - $this->setCapabilities(); |
|
| 357 | - if ($callbacks) { |
|
| 358 | - $this->callbacks = $callbacks; |
|
| 359 | - } |
|
| 360 | - $this->setCallbacks(); |
|
| 361 | - $this->serve($data); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @param bool $data |
|
| 366 | - */ |
|
| 367 | - public function serve($data = false) |
|
| 368 | - { |
|
| 369 | - if (!$data) { |
|
| 370 | - $http_raw_post_data = file_get_contents('php://input'); |
|
| 371 | - if (!$http_raw_post_data) { |
|
| 372 | - die('XML-RPC server accepts POST requests only.'); |
|
| 373 | - } |
|
| 374 | - $data = $http_raw_post_data; |
|
| 375 | - } |
|
| 376 | - $this->message = new IXR_Message($data); |
|
| 377 | - if (!$this->message->parse()) { |
|
| 378 | - $this->error(-32700, 'parse error. not well formed'); |
|
| 379 | - } |
|
| 380 | - if ('methodCall' !== $this->message->messageType) { |
|
| 381 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 382 | - } |
|
| 383 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
| 384 | - // Is the result an error? |
|
| 385 | - if (is_a($result, 'IXR_Error')) { |
|
| 386 | - $this->error($result); |
|
| 387 | - } |
|
| 388 | - // Encode the result |
|
| 389 | - $r = new IXR_Value($result); |
|
| 390 | - $resultxml = $r->getXml(); |
|
| 391 | - // Create the XML |
|
| 392 | - $xml = <<<EOD |
|
| 344 | + public $data; |
|
| 345 | + public $callbacks = []; |
|
| 346 | + public $message; |
|
| 347 | + public $capabilities; |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * IXR_Server constructor. |
|
| 351 | + * @param bool $callbacks |
|
| 352 | + * @param bool $data |
|
| 353 | + */ |
|
| 354 | + public function __construct($callbacks = false, $data = false) |
|
| 355 | + { |
|
| 356 | + $this->setCapabilities(); |
|
| 357 | + if ($callbacks) { |
|
| 358 | + $this->callbacks = $callbacks; |
|
| 359 | + } |
|
| 360 | + $this->setCallbacks(); |
|
| 361 | + $this->serve($data); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @param bool $data |
|
| 366 | + */ |
|
| 367 | + public function serve($data = false) |
|
| 368 | + { |
|
| 369 | + if (!$data) { |
|
| 370 | + $http_raw_post_data = file_get_contents('php://input'); |
|
| 371 | + if (!$http_raw_post_data) { |
|
| 372 | + die('XML-RPC server accepts POST requests only.'); |
|
| 373 | + } |
|
| 374 | + $data = $http_raw_post_data; |
|
| 375 | + } |
|
| 376 | + $this->message = new IXR_Message($data); |
|
| 377 | + if (!$this->message->parse()) { |
|
| 378 | + $this->error(-32700, 'parse error. not well formed'); |
|
| 379 | + } |
|
| 380 | + if ('methodCall' !== $this->message->messageType) { |
|
| 381 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 382 | + } |
|
| 383 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
| 384 | + // Is the result an error? |
|
| 385 | + if (is_a($result, 'IXR_Error')) { |
|
| 386 | + $this->error($result); |
|
| 387 | + } |
|
| 388 | + // Encode the result |
|
| 389 | + $r = new IXR_Value($result); |
|
| 390 | + $resultxml = $r->getXml(); |
|
| 391 | + // Create the XML |
|
| 392 | + $xml = <<<EOD |
|
| 393 | 393 | <methodResponse> |
| 394 | 394 | <params> |
| 395 | 395 | <param> |
@@ -401,162 +401,162 @@ discard block |
||
| 401 | 401 | </methodResponse> |
| 402 | 402 | |
| 403 | 403 | EOD; |
| 404 | - // Send it |
|
| 405 | - $this->output($xml); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @param $methodname |
|
| 410 | - * @param $args |
|
| 411 | - * @return IXR_Error|mixed |
|
| 412 | - */ |
|
| 413 | - public function call($methodname, $args) |
|
| 414 | - { |
|
| 415 | - if (!$this->hasMethod($methodname)) { |
|
| 416 | - return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); |
|
| 417 | - } |
|
| 418 | - $method = $this->callbacks[$methodname]; |
|
| 419 | - // Perform the callback and send the response |
|
| 420 | - if (1 == count($args)) { |
|
| 421 | - // If only one paramater just send that instead of the whole array |
|
| 422 | - $args = $args[0]; |
|
| 423 | - } |
|
| 424 | - // Are we dealing with a function or a method? |
|
| 425 | - if ('this:' === substr($method, 0, 5)) { |
|
| 426 | - // It's a class method - check it exists |
|
| 427 | - $method = substr($method, 5); |
|
| 428 | - if (!method_exists($this, $method)) { |
|
| 429 | - return new IXR_Error(-32601, 'server error. requested class method "' . $method . '" does not exist.'); |
|
| 430 | - } |
|
| 431 | - // Call the method |
|
| 432 | - $result = $this->$method($args); |
|
| 433 | - } else { |
|
| 434 | - // It's a function - does it exist? |
|
| 435 | - if (is_array($method)) { |
|
| 436 | - if (!method_exists($method[0], $method[1])) { |
|
| 437 | - return new IXR_Error(-32601, 'server error. requested object method "' . $method[1] . '" does not exist.'); |
|
| 438 | - } |
|
| 439 | - } elseif (!function_exists($method)) { |
|
| 440 | - return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); |
|
| 441 | - } |
|
| 442 | - // Call the function |
|
| 443 | - $result = call_user_func($method, $args); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $result; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param $error |
|
| 451 | - * @param bool $message |
|
| 452 | - */ |
|
| 453 | - public function error($error, $message = false) |
|
| 454 | - { |
|
| 455 | - // Accepts either an error object or an error code and message |
|
| 456 | - if ($message && !is_object($error)) { |
|
| 457 | - $error = new IXR_Error($error, $message); |
|
| 458 | - } |
|
| 459 | - $this->output($error->getXml()); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @param $xml |
|
| 464 | - */ |
|
| 465 | - public function output($xml) |
|
| 466 | - { |
|
| 467 | - $xml = '<?xml version="1.0"?>' . "\n" . $xml; |
|
| 468 | - $length = strlen($xml); |
|
| 469 | - header('Connection: close'); |
|
| 470 | - header('Content-Length: ' . $length); |
|
| 471 | - header('Content-Type: text/xml'); |
|
| 472 | - header('Date: ' . date('r')); |
|
| 473 | - echo $xml; |
|
| 474 | - exit; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * @param $method |
|
| 479 | - * @return bool |
|
| 480 | - */ |
|
| 481 | - public function hasMethod($method) |
|
| 482 | - { |
|
| 483 | - return in_array($method, array_keys($this->callbacks)); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - public function setCapabilities() |
|
| 487 | - { |
|
| 488 | - // Initialises capabilities array |
|
| 489 | - $this->capabilities = [ |
|
| 490 | - 'xmlrpc' => [ |
|
| 491 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 492 | - 'specVersion' => 1 |
|
| 493 | - ], |
|
| 494 | - 'faults_interop' => [ |
|
| 495 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 496 | - 'specVersion' => 20010516 |
|
| 497 | - ], |
|
| 498 | - 'system.multicall' => [ |
|
| 499 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 500 | - 'specVersion' => 1 |
|
| 501 | - ] |
|
| 502 | - ]; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @param $args |
|
| 507 | - * @return mixed |
|
| 508 | - */ |
|
| 509 | - public function getCapabilities($args) |
|
| 510 | - { |
|
| 511 | - return $this->capabilities; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - public function setCallbacks() |
|
| 515 | - { |
|
| 516 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 517 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 518 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @param $args |
|
| 523 | - * @return array |
|
| 524 | - */ |
|
| 525 | - public function listMethods($args) |
|
| 526 | - { |
|
| 527 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 528 | - // methods are listed before server defined methods |
|
| 529 | - return array_reverse(array_keys($this->callbacks)); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * @param $methodcalls |
|
| 534 | - * @return array |
|
| 535 | - */ |
|
| 536 | - public function multiCall($methodcalls) |
|
| 537 | - { |
|
| 538 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 539 | - $return = []; |
|
| 540 | - foreach ($methodcalls as $call) { |
|
| 541 | - $method = $call['methodName']; |
|
| 542 | - $params = $call['params']; |
|
| 543 | - if ('system.multicall' === $method) { |
|
| 544 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 545 | - } else { |
|
| 546 | - $result = $this->call($method, $params); |
|
| 547 | - } |
|
| 548 | - if (is_a($result, 'IXR_Error')) { |
|
| 549 | - $return[] = [ |
|
| 550 | - 'faultCode' => $result->code, |
|
| 551 | - 'faultString' => $result->message |
|
| 552 | - ]; |
|
| 553 | - } else { |
|
| 554 | - $return[] = [$result]; |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - return $return; |
|
| 559 | - } |
|
| 404 | + // Send it |
|
| 405 | + $this->output($xml); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @param $methodname |
|
| 410 | + * @param $args |
|
| 411 | + * @return IXR_Error|mixed |
|
| 412 | + */ |
|
| 413 | + public function call($methodname, $args) |
|
| 414 | + { |
|
| 415 | + if (!$this->hasMethod($methodname)) { |
|
| 416 | + return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); |
|
| 417 | + } |
|
| 418 | + $method = $this->callbacks[$methodname]; |
|
| 419 | + // Perform the callback and send the response |
|
| 420 | + if (1 == count($args)) { |
|
| 421 | + // If only one paramater just send that instead of the whole array |
|
| 422 | + $args = $args[0]; |
|
| 423 | + } |
|
| 424 | + // Are we dealing with a function or a method? |
|
| 425 | + if ('this:' === substr($method, 0, 5)) { |
|
| 426 | + // It's a class method - check it exists |
|
| 427 | + $method = substr($method, 5); |
|
| 428 | + if (!method_exists($this, $method)) { |
|
| 429 | + return new IXR_Error(-32601, 'server error. requested class method "' . $method . '" does not exist.'); |
|
| 430 | + } |
|
| 431 | + // Call the method |
|
| 432 | + $result = $this->$method($args); |
|
| 433 | + } else { |
|
| 434 | + // It's a function - does it exist? |
|
| 435 | + if (is_array($method)) { |
|
| 436 | + if (!method_exists($method[0], $method[1])) { |
|
| 437 | + return new IXR_Error(-32601, 'server error. requested object method "' . $method[1] . '" does not exist.'); |
|
| 438 | + } |
|
| 439 | + } elseif (!function_exists($method)) { |
|
| 440 | + return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); |
|
| 441 | + } |
|
| 442 | + // Call the function |
|
| 443 | + $result = call_user_func($method, $args); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $result; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param $error |
|
| 451 | + * @param bool $message |
|
| 452 | + */ |
|
| 453 | + public function error($error, $message = false) |
|
| 454 | + { |
|
| 455 | + // Accepts either an error object or an error code and message |
|
| 456 | + if ($message && !is_object($error)) { |
|
| 457 | + $error = new IXR_Error($error, $message); |
|
| 458 | + } |
|
| 459 | + $this->output($error->getXml()); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @param $xml |
|
| 464 | + */ |
|
| 465 | + public function output($xml) |
|
| 466 | + { |
|
| 467 | + $xml = '<?xml version="1.0"?>' . "\n" . $xml; |
|
| 468 | + $length = strlen($xml); |
|
| 469 | + header('Connection: close'); |
|
| 470 | + header('Content-Length: ' . $length); |
|
| 471 | + header('Content-Type: text/xml'); |
|
| 472 | + header('Date: ' . date('r')); |
|
| 473 | + echo $xml; |
|
| 474 | + exit; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * @param $method |
|
| 479 | + * @return bool |
|
| 480 | + */ |
|
| 481 | + public function hasMethod($method) |
|
| 482 | + { |
|
| 483 | + return in_array($method, array_keys($this->callbacks)); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + public function setCapabilities() |
|
| 487 | + { |
|
| 488 | + // Initialises capabilities array |
|
| 489 | + $this->capabilities = [ |
|
| 490 | + 'xmlrpc' => [ |
|
| 491 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 492 | + 'specVersion' => 1 |
|
| 493 | + ], |
|
| 494 | + 'faults_interop' => [ |
|
| 495 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 496 | + 'specVersion' => 20010516 |
|
| 497 | + ], |
|
| 498 | + 'system.multicall' => [ |
|
| 499 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 500 | + 'specVersion' => 1 |
|
| 501 | + ] |
|
| 502 | + ]; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @param $args |
|
| 507 | + * @return mixed |
|
| 508 | + */ |
|
| 509 | + public function getCapabilities($args) |
|
| 510 | + { |
|
| 511 | + return $this->capabilities; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + public function setCallbacks() |
|
| 515 | + { |
|
| 516 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 517 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 518 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @param $args |
|
| 523 | + * @return array |
|
| 524 | + */ |
|
| 525 | + public function listMethods($args) |
|
| 526 | + { |
|
| 527 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 528 | + // methods are listed before server defined methods |
|
| 529 | + return array_reverse(array_keys($this->callbacks)); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * @param $methodcalls |
|
| 534 | + * @return array |
|
| 535 | + */ |
|
| 536 | + public function multiCall($methodcalls) |
|
| 537 | + { |
|
| 538 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 539 | + $return = []; |
|
| 540 | + foreach ($methodcalls as $call) { |
|
| 541 | + $method = $call['methodName']; |
|
| 542 | + $params = $call['params']; |
|
| 543 | + if ('system.multicall' === $method) { |
|
| 544 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 545 | + } else { |
|
| 546 | + $result = $this->call($method, $params); |
|
| 547 | + } |
|
| 548 | + if (is_a($result, 'IXR_Error')) { |
|
| 549 | + $return[] = [ |
|
| 550 | + 'faultCode' => $result->code, |
|
| 551 | + 'faultString' => $result->message |
|
| 552 | + ]; |
|
| 553 | + } else { |
|
| 554 | + $return[] = [$result]; |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + return $return; |
|
| 559 | + } |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /** |
@@ -564,50 +564,50 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | class IXR_Request |
| 566 | 566 | { |
| 567 | - public $method; |
|
| 568 | - public $args; |
|
| 569 | - public $xml; |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * IXR_Request constructor. |
|
| 573 | - * @param $method |
|
| 574 | - * @param $args |
|
| 575 | - */ |
|
| 576 | - public function __construct($method, $args) |
|
| 577 | - { |
|
| 578 | - $this->method = $method; |
|
| 579 | - $this->args = $args; |
|
| 580 | - $this->xml = <<<EOD |
|
| 567 | + public $method; |
|
| 568 | + public $args; |
|
| 569 | + public $xml; |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * IXR_Request constructor. |
|
| 573 | + * @param $method |
|
| 574 | + * @param $args |
|
| 575 | + */ |
|
| 576 | + public function __construct($method, $args) |
|
| 577 | + { |
|
| 578 | + $this->method = $method; |
|
| 579 | + $this->args = $args; |
|
| 580 | + $this->xml = <<<EOD |
|
| 581 | 581 | <?xml version="1.0"?> |
| 582 | 582 | <methodCall> |
| 583 | 583 | <methodName>{$this->method}</methodName> |
| 584 | 584 | <params> |
| 585 | 585 | |
| 586 | 586 | EOD; |
| 587 | - foreach ($this->args as $arg) { |
|
| 588 | - $this->xml .= '<param><value>'; |
|
| 589 | - $v = new IXR_Value($arg); |
|
| 590 | - $this->xml .= $v->getXml(); |
|
| 591 | - $this->xml .= "</value></param>\n"; |
|
| 592 | - } |
|
| 593 | - $this->xml .= '</params></methodCall>'; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @return int |
|
| 598 | - */ |
|
| 599 | - public function getLength() |
|
| 600 | - { |
|
| 601 | - return strlen($this->xml); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @return string |
|
| 606 | - */ |
|
| 607 | - public function getXml() |
|
| 608 | - { |
|
| 609 | - return $this->xml; |
|
| 610 | - } |
|
| 587 | + foreach ($this->args as $arg) { |
|
| 588 | + $this->xml .= '<param><value>'; |
|
| 589 | + $v = new IXR_Value($arg); |
|
| 590 | + $this->xml .= $v->getXml(); |
|
| 591 | + $this->xml .= "</value></param>\n"; |
|
| 592 | + } |
|
| 593 | + $this->xml .= '</params></methodCall>'; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @return int |
|
| 598 | + */ |
|
| 599 | + public function getLength() |
|
| 600 | + { |
|
| 601 | + return strlen($this->xml); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @return string |
|
| 606 | + */ |
|
| 607 | + public function getXml() |
|
| 608 | + { |
|
| 609 | + return $this->xml; |
|
| 610 | + } |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -615,150 +615,150 @@ discard block |
||
| 615 | 615 | */ |
| 616 | 616 | class IXR_Client |
| 617 | 617 | { |
| 618 | - public $server; |
|
| 619 | - public $port; |
|
| 620 | - public $path; |
|
| 621 | - public $useragent; |
|
| 622 | - public $response; |
|
| 623 | - public $timeout; |
|
| 624 | - public $vendor = ''; |
|
| 625 | - public $message = false; |
|
| 626 | - public $debug = false; |
|
| 627 | - // Storage place for an error message |
|
| 628 | - public $error = false; |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * IXR_Client constructor. |
|
| 632 | - * @param $server |
|
| 633 | - * @param bool $path |
|
| 634 | - * @param int $port |
|
| 635 | - * @param int $timeout |
|
| 636 | - * @param string $vendor |
|
| 637 | - */ |
|
| 638 | - public function __construct($server, $path = false, $port = 80, $timeout = 30, $vendor = '') |
|
| 639 | - { |
|
| 640 | - if (!$path) { |
|
| 641 | - // Assume we have been given a URL instead |
|
| 642 | - $bits = parse_url($server); |
|
| 643 | - $this->server = $bits['host']; |
|
| 644 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 645 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 646 | - // Make absolutely sure we have a path |
|
| 647 | - if (!$this->path) { |
|
| 648 | - $this->path = '/'; |
|
| 649 | - } |
|
| 650 | - } else { |
|
| 651 | - $this->server = $server; |
|
| 652 | - $this->path = $path; |
|
| 653 | - $this->port = $port; |
|
| 654 | - $this->timeout = $timeout; |
|
| 655 | - } |
|
| 656 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * @return bool |
|
| 661 | - */ |
|
| 662 | - public function query() |
|
| 663 | - { |
|
| 664 | - $args = func_get_args(); |
|
| 665 | - $method = array_shift($args); |
|
| 666 | - $request = new IXR_Request($method, $args); |
|
| 667 | - $length = $request->getLength(); |
|
| 668 | - $xml = $request->getXml(); |
|
| 669 | - $r = "\r\n"; |
|
| 670 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 671 | - $request .= "Host: {$this->server}$r"; |
|
| 672 | - $request .= "Content-Type: text/xml$r"; |
|
| 673 | - $request .= "User-Agent: {$this->useragent}$r"; |
|
| 674 | - $request .= "Content-length: {$length}$r$r"; |
|
| 675 | - $request .= $xml; |
|
| 676 | - // Now send the request |
|
| 677 | - if ($this->debug) { |
|
| 678 | - echo '<pre>' . htmlspecialchars($request, ENT_QUOTES | ENT_HTML5) . "\n</pre>\n\n"; |
|
| 679 | - } |
|
| 680 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 681 | - if (!$fp) { |
|
| 682 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 683 | - |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - fwrite($fp, $request); |
|
| 687 | - $contents = ''; |
|
| 688 | - $gotFirstLine = false; |
|
| 689 | - $gettingHeaders = true; |
|
| 690 | - while (!feof($fp)) { |
|
| 691 | - $line = fgets($fp, 4096); |
|
| 692 | - if (!$gotFirstLine) { |
|
| 693 | - // Check line for '200' |
|
| 694 | - if (false === strpos($line, '200')) { |
|
| 695 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 696 | - |
|
| 697 | - return false; |
|
| 698 | - } |
|
| 699 | - $gotFirstLine = true; |
|
| 700 | - } |
|
| 701 | - if ('' == trim($line)) { |
|
| 702 | - $gettingHeaders = false; |
|
| 703 | - } |
|
| 704 | - if (!$gettingHeaders) { |
|
| 705 | - $contents .= trim($line) . "\n"; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - if ($this->debug) { |
|
| 709 | - echo '<pre>' . htmlspecialchars($contents, ENT_QUOTES | ENT_HTML5) . "\n</pre>\n\n"; |
|
| 710 | - } |
|
| 711 | - // Now parse what we've got back |
|
| 712 | - $this->message = new IXR_Message($contents); |
|
| 713 | - if (!$this->message->parse()) { |
|
| 714 | - // XML error |
|
| 715 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 716 | - |
|
| 717 | - return false; |
|
| 718 | - } |
|
| 719 | - // Is the message a fault? |
|
| 720 | - if ('fault' === $this->message->messageType) { |
|
| 721 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 722 | - |
|
| 723 | - return false; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - // Message must be OK |
|
| 727 | - return true; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * @return mixed |
|
| 732 | - */ |
|
| 733 | - public function getResponse() |
|
| 734 | - { |
|
| 735 | - // methodResponses can only have one param - return that |
|
| 736 | - return $this->message->params[0]; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * @return bool |
|
| 741 | - */ |
|
| 742 | - public function isError() |
|
| 743 | - { |
|
| 744 | - return is_object($this->error); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * @return mixed |
|
| 749 | - */ |
|
| 750 | - public function getErrorCode() |
|
| 751 | - { |
|
| 752 | - return $this->error->code; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * @return mixed |
|
| 757 | - */ |
|
| 758 | - public function getErrorMessage() |
|
| 759 | - { |
|
| 760 | - return $this->error->message; |
|
| 761 | - } |
|
| 618 | + public $server; |
|
| 619 | + public $port; |
|
| 620 | + public $path; |
|
| 621 | + public $useragent; |
|
| 622 | + public $response; |
|
| 623 | + public $timeout; |
|
| 624 | + public $vendor = ''; |
|
| 625 | + public $message = false; |
|
| 626 | + public $debug = false; |
|
| 627 | + // Storage place for an error message |
|
| 628 | + public $error = false; |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * IXR_Client constructor. |
|
| 632 | + * @param $server |
|
| 633 | + * @param bool $path |
|
| 634 | + * @param int $port |
|
| 635 | + * @param int $timeout |
|
| 636 | + * @param string $vendor |
|
| 637 | + */ |
|
| 638 | + public function __construct($server, $path = false, $port = 80, $timeout = 30, $vendor = '') |
|
| 639 | + { |
|
| 640 | + if (!$path) { |
|
| 641 | + // Assume we have been given a URL instead |
|
| 642 | + $bits = parse_url($server); |
|
| 643 | + $this->server = $bits['host']; |
|
| 644 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 645 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 646 | + // Make absolutely sure we have a path |
|
| 647 | + if (!$this->path) { |
|
| 648 | + $this->path = '/'; |
|
| 649 | + } |
|
| 650 | + } else { |
|
| 651 | + $this->server = $server; |
|
| 652 | + $this->path = $path; |
|
| 653 | + $this->port = $port; |
|
| 654 | + $this->timeout = $timeout; |
|
| 655 | + } |
|
| 656 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * @return bool |
|
| 661 | + */ |
|
| 662 | + public function query() |
|
| 663 | + { |
|
| 664 | + $args = func_get_args(); |
|
| 665 | + $method = array_shift($args); |
|
| 666 | + $request = new IXR_Request($method, $args); |
|
| 667 | + $length = $request->getLength(); |
|
| 668 | + $xml = $request->getXml(); |
|
| 669 | + $r = "\r\n"; |
|
| 670 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 671 | + $request .= "Host: {$this->server}$r"; |
|
| 672 | + $request .= "Content-Type: text/xml$r"; |
|
| 673 | + $request .= "User-Agent: {$this->useragent}$r"; |
|
| 674 | + $request .= "Content-length: {$length}$r$r"; |
|
| 675 | + $request .= $xml; |
|
| 676 | + // Now send the request |
|
| 677 | + if ($this->debug) { |
|
| 678 | + echo '<pre>' . htmlspecialchars($request, ENT_QUOTES | ENT_HTML5) . "\n</pre>\n\n"; |
|
| 679 | + } |
|
| 680 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 681 | + if (!$fp) { |
|
| 682 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 683 | + |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + fwrite($fp, $request); |
|
| 687 | + $contents = ''; |
|
| 688 | + $gotFirstLine = false; |
|
| 689 | + $gettingHeaders = true; |
|
| 690 | + while (!feof($fp)) { |
|
| 691 | + $line = fgets($fp, 4096); |
|
| 692 | + if (!$gotFirstLine) { |
|
| 693 | + // Check line for '200' |
|
| 694 | + if (false === strpos($line, '200')) { |
|
| 695 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 696 | + |
|
| 697 | + return false; |
|
| 698 | + } |
|
| 699 | + $gotFirstLine = true; |
|
| 700 | + } |
|
| 701 | + if ('' == trim($line)) { |
|
| 702 | + $gettingHeaders = false; |
|
| 703 | + } |
|
| 704 | + if (!$gettingHeaders) { |
|
| 705 | + $contents .= trim($line) . "\n"; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + if ($this->debug) { |
|
| 709 | + echo '<pre>' . htmlspecialchars($contents, ENT_QUOTES | ENT_HTML5) . "\n</pre>\n\n"; |
|
| 710 | + } |
|
| 711 | + // Now parse what we've got back |
|
| 712 | + $this->message = new IXR_Message($contents); |
|
| 713 | + if (!$this->message->parse()) { |
|
| 714 | + // XML error |
|
| 715 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 716 | + |
|
| 717 | + return false; |
|
| 718 | + } |
|
| 719 | + // Is the message a fault? |
|
| 720 | + if ('fault' === $this->message->messageType) { |
|
| 721 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 722 | + |
|
| 723 | + return false; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + // Message must be OK |
|
| 727 | + return true; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * @return mixed |
|
| 732 | + */ |
|
| 733 | + public function getResponse() |
|
| 734 | + { |
|
| 735 | + // methodResponses can only have one param - return that |
|
| 736 | + return $this->message->params[0]; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * @return bool |
|
| 741 | + */ |
|
| 742 | + public function isError() |
|
| 743 | + { |
|
| 744 | + return is_object($this->error); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * @return mixed |
|
| 749 | + */ |
|
| 750 | + public function getErrorCode() |
|
| 751 | + { |
|
| 752 | + return $this->error->code; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * @return mixed |
|
| 757 | + */ |
|
| 758 | + public function getErrorMessage() |
|
| 759 | + { |
|
| 760 | + return $this->error->message; |
|
| 761 | + } |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /** |
@@ -766,26 +766,26 @@ discard block |
||
| 766 | 766 | */ |
| 767 | 767 | class IXR_Error |
| 768 | 768 | { |
| 769 | - public $code; |
|
| 770 | - public $message; |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * IXR_Error constructor. |
|
| 774 | - * @param $code |
|
| 775 | - * @param $message |
|
| 776 | - */ |
|
| 777 | - public function __construct($code, $message) |
|
| 778 | - { |
|
| 779 | - $this->code = $code; |
|
| 780 | - $this->message = $message; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * @return string |
|
| 785 | - */ |
|
| 786 | - public function getXml() |
|
| 787 | - { |
|
| 788 | - $xml = <<<EOD |
|
| 769 | + public $code; |
|
| 770 | + public $message; |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * IXR_Error constructor. |
|
| 774 | + * @param $code |
|
| 775 | + * @param $message |
|
| 776 | + */ |
|
| 777 | + public function __construct($code, $message) |
|
| 778 | + { |
|
| 779 | + $this->code = $code; |
|
| 780 | + $this->message = $message; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * @return string |
|
| 785 | + */ |
|
| 786 | + public function getXml() |
|
| 787 | + { |
|
| 788 | + $xml = <<<EOD |
|
| 789 | 789 | <methodResponse> |
| 790 | 790 | <fault> |
| 791 | 791 | <value> |
@@ -805,8 +805,8 @@ discard block |
||
| 805 | 805 | |
| 806 | 806 | EOD; |
| 807 | 807 | |
| 808 | - return $xml; |
|
| 809 | - } |
|
| 808 | + return $xml; |
|
| 809 | + } |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -814,78 +814,78 @@ discard block |
||
| 814 | 814 | */ |
| 815 | 815 | class IXR_Date |
| 816 | 816 | { |
| 817 | - public $year; |
|
| 818 | - public $month; |
|
| 819 | - public $day; |
|
| 820 | - public $hour; |
|
| 821 | - public $minute; |
|
| 822 | - public $second; |
|
| 823 | - public $timezone; |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * IXR_Date constructor. |
|
| 827 | - * @param $time |
|
| 828 | - */ |
|
| 829 | - public function __construct($time) |
|
| 830 | - { |
|
| 831 | - // $time can be a PHP timestamp or an ISO one |
|
| 832 | - if (is_numeric($time)) { |
|
| 833 | - $this->parseTimestamp($time); |
|
| 834 | - } else { |
|
| 835 | - $this->parseIso($time); |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * @param $timestamp |
|
| 841 | - */ |
|
| 842 | - public function parseTimestamp($timestamp) |
|
| 843 | - { |
|
| 844 | - $this->year = date('Y', $timestamp); |
|
| 845 | - $this->month = date('Y', $timestamp); |
|
| 846 | - $this->day = date('Y', $timestamp); |
|
| 847 | - $this->hour = date('H', $timestamp); |
|
| 848 | - $this->minute = date('i', $timestamp); |
|
| 849 | - $this->second = date('s', $timestamp); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * @param $iso |
|
| 854 | - */ |
|
| 855 | - public function parseIso($iso) |
|
| 856 | - { |
|
| 857 | - $this->year = substr($iso, 0, 4); |
|
| 858 | - $this->month = substr($iso, 4, 2); |
|
| 859 | - $this->day = substr($iso, 6, 2); |
|
| 860 | - $this->hour = substr($iso, 9, 2); |
|
| 861 | - $this->minute = substr($iso, 12, 2); |
|
| 862 | - $this->second = substr($iso, 15, 2); |
|
| 863 | - $this->timezone = substr($iso, 17); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * @return string |
|
| 868 | - */ |
|
| 869 | - public function getIso() |
|
| 870 | - { |
|
| 871 | - return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second . $this->timezone; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * @return string |
|
| 876 | - */ |
|
| 877 | - public function getXml() |
|
| 878 | - { |
|
| 879 | - return '<dateTime.iso8601>' . $this->getIso() . '</dateTime.iso8601>'; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * @return int |
|
| 884 | - */ |
|
| 885 | - public function getTimestamp() |
|
| 886 | - { |
|
| 887 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 888 | - } |
|
| 817 | + public $year; |
|
| 818 | + public $month; |
|
| 819 | + public $day; |
|
| 820 | + public $hour; |
|
| 821 | + public $minute; |
|
| 822 | + public $second; |
|
| 823 | + public $timezone; |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * IXR_Date constructor. |
|
| 827 | + * @param $time |
|
| 828 | + */ |
|
| 829 | + public function __construct($time) |
|
| 830 | + { |
|
| 831 | + // $time can be a PHP timestamp or an ISO one |
|
| 832 | + if (is_numeric($time)) { |
|
| 833 | + $this->parseTimestamp($time); |
|
| 834 | + } else { |
|
| 835 | + $this->parseIso($time); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * @param $timestamp |
|
| 841 | + */ |
|
| 842 | + public function parseTimestamp($timestamp) |
|
| 843 | + { |
|
| 844 | + $this->year = date('Y', $timestamp); |
|
| 845 | + $this->month = date('Y', $timestamp); |
|
| 846 | + $this->day = date('Y', $timestamp); |
|
| 847 | + $this->hour = date('H', $timestamp); |
|
| 848 | + $this->minute = date('i', $timestamp); |
|
| 849 | + $this->second = date('s', $timestamp); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * @param $iso |
|
| 854 | + */ |
|
| 855 | + public function parseIso($iso) |
|
| 856 | + { |
|
| 857 | + $this->year = substr($iso, 0, 4); |
|
| 858 | + $this->month = substr($iso, 4, 2); |
|
| 859 | + $this->day = substr($iso, 6, 2); |
|
| 860 | + $this->hour = substr($iso, 9, 2); |
|
| 861 | + $this->minute = substr($iso, 12, 2); |
|
| 862 | + $this->second = substr($iso, 15, 2); |
|
| 863 | + $this->timezone = substr($iso, 17); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * @return string |
|
| 868 | + */ |
|
| 869 | + public function getIso() |
|
| 870 | + { |
|
| 871 | + return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second . $this->timezone; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * @return string |
|
| 876 | + */ |
|
| 877 | + public function getXml() |
|
| 878 | + { |
|
| 879 | + return '<dateTime.iso8601>' . $this->getIso() . '</dateTime.iso8601>'; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * @return int |
|
| 884 | + */ |
|
| 885 | + public function getTimestamp() |
|
| 886 | + { |
|
| 887 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 888 | + } |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | /** |
@@ -893,24 +893,24 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | class IXR_Base64 |
| 895 | 895 | { |
| 896 | - public $data; |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * IXR_Base64 constructor. |
|
| 900 | - * @param $data |
|
| 901 | - */ |
|
| 902 | - public function __construct($data) |
|
| 903 | - { |
|
| 904 | - $this->data = $data; |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * @return string |
|
| 909 | - */ |
|
| 910 | - public function getXml() |
|
| 911 | - { |
|
| 912 | - return '<base64>' . base64_encode($this->data) . '</base64>'; |
|
| 913 | - } |
|
| 896 | + public $data; |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * IXR_Base64 constructor. |
|
| 900 | + * @param $data |
|
| 901 | + */ |
|
| 902 | + public function __construct($data) |
|
| 903 | + { |
|
| 904 | + $this->data = $data; |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * @return string |
|
| 909 | + */ |
|
| 910 | + public function getXml() |
|
| 911 | + { |
|
| 912 | + return '<base64>' . base64_encode($this->data) . '</base64>'; |
|
| 913 | + } |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -918,161 +918,161 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | class IXR_IntrospectionServer extends IXR_Server |
| 920 | 920 | { |
| 921 | - public $signatures; |
|
| 922 | - public $help; |
|
| 923 | - |
|
| 924 | - /** |
|
| 925 | - * IXR_IntrospectionServer constructor. |
|
| 926 | - */ |
|
| 927 | - public function __construct() |
|
| 928 | - { |
|
| 929 | - $this->setCallbacks(); |
|
| 930 | - $this->setCapabilities(); |
|
| 931 | - $this->capabilities['introspection'] = [ |
|
| 932 | - 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 933 | - 'specVersion' => 1 |
|
| 934 | - ]; |
|
| 935 | - $this->addCallback('system.methodSignature', 'this:methodSignature', ['array', 'string'], 'Returns an array describing the return type and required parameters of a method'); |
|
| 936 | - $this->addCallback('system.getCapabilities', 'this:getCapabilities', ['struct'], 'Returns a struct describing the XML-RPC specifications supported by this server'); |
|
| 937 | - $this->addCallback('system.listMethods', 'this:listMethods', ['array'], 'Returns an array of available methods on this server'); |
|
| 938 | - $this->addCallback('system.methodHelp', 'this:methodHelp', ['string', 'string'], 'Returns a documentation string for the specified method'); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - /** |
|
| 942 | - * @param $method |
|
| 943 | - * @param $callback |
|
| 944 | - * @param $args |
|
| 945 | - * @param $help |
|
| 946 | - */ |
|
| 947 | - public function addCallback($method, $callback, $args, $help) |
|
| 948 | - { |
|
| 949 | - $this->callbacks[$method] = $callback; |
|
| 950 | - $this->signatures[$method] = $args; |
|
| 951 | - $this->help[$method] = $help; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * @param $methodname |
|
| 956 | - * @param $args |
|
| 957 | - * @return IXR_Error|mixed |
|
| 958 | - */ |
|
| 959 | - public function call($methodname, $args) |
|
| 960 | - { |
|
| 961 | - // Make sure it's in an array |
|
| 962 | - if ($args && !is_array($args)) { |
|
| 963 | - $args = [$args]; |
|
| 964 | - } |
|
| 965 | - // Over-rides default call method, adds signature check |
|
| 966 | - if (!$this->hasMethod($methodname)) { |
|
| 967 | - return new IXR_Error(-32601, 'server error. requested method "' . $this->message->methodName . '" not specified.'); |
|
| 968 | - } |
|
| 969 | - $method = $this->callbacks[$methodname]; |
|
| 970 | - $signature = $this->signatures[$methodname]; |
|
| 971 | - $returnType = array_shift($signature); |
|
| 972 | - // Check the number of arguments |
|
| 973 | - if (count($args) != count($signature)) { |
|
| 974 | - // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
| 975 | - return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 976 | - } |
|
| 977 | - // Check the argument types |
|
| 978 | - $ok = true; |
|
| 979 | - $argsbackup = $args; |
|
| 980 | - for ($i = 0, $j = count($args); $i < $j; ++$i) { |
|
| 981 | - $arg = array_shift($args); |
|
| 982 | - $type = array_shift($signature); |
|
| 983 | - switch ($type) { |
|
| 984 | - case 'int': |
|
| 985 | - case 'i4': |
|
| 986 | - if (is_array($arg) || !is_int($arg)) { |
|
| 987 | - $ok = false; |
|
| 988 | - } |
|
| 989 | - break; |
|
| 990 | - case 'base64': |
|
| 991 | - case 'string': |
|
| 992 | - if (!is_string($arg)) { |
|
| 993 | - $ok = false; |
|
| 994 | - } |
|
| 995 | - break; |
|
| 996 | - case 'boolean': |
|
| 997 | - if (false !== $arg && true !== $arg) { |
|
| 998 | - $ok = false; |
|
| 999 | - } |
|
| 1000 | - break; |
|
| 1001 | - case 'float': |
|
| 1002 | - case 'double': |
|
| 1003 | - if (!is_float($arg)) { |
|
| 1004 | - $ok = false; |
|
| 1005 | - } |
|
| 1006 | - break; |
|
| 1007 | - case 'date': |
|
| 1008 | - case 'dateTime.iso8601': |
|
| 1009 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 1010 | - $ok = false; |
|
| 1011 | - } |
|
| 1012 | - break; |
|
| 1013 | - } |
|
| 1014 | - if (!$ok) { |
|
| 1015 | - return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - // It passed the test - run the "real" method call |
|
| 1020 | - return parent::call($methodname, $argsbackup); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * @param $method |
|
| 1025 | - * @return array|IXR_Error |
|
| 1026 | - */ |
|
| 1027 | - public function methodSignature($method) |
|
| 1028 | - { |
|
| 1029 | - if (!$this->hasMethod($method)) { |
|
| 1030 | - return new IXR_Error(-32601, 'server error. requested method "' . $method . '" not specified.'); |
|
| 1031 | - } |
|
| 1032 | - // We should be returning an array of types |
|
| 1033 | - $types = $this->signatures[$method]; |
|
| 1034 | - $return = []; |
|
| 1035 | - foreach ($types as $type) { |
|
| 1036 | - switch ($type) { |
|
| 1037 | - case 'string': |
|
| 1038 | - $return[] = 'string'; |
|
| 1039 | - break; |
|
| 1040 | - case 'int': |
|
| 1041 | - case 'i4': |
|
| 1042 | - $return[] = 42; |
|
| 1043 | - break; |
|
| 1044 | - case 'double': |
|
| 1045 | - $return[] = 3.1415; |
|
| 1046 | - break; |
|
| 1047 | - case 'dateTime.iso8601': |
|
| 1048 | - $return[] = new IXR_Date(time()); |
|
| 1049 | - break; |
|
| 1050 | - case 'boolean': |
|
| 1051 | - $return[] = true; |
|
| 1052 | - break; |
|
| 1053 | - case 'base64': |
|
| 1054 | - $return[] = new IXR_Base64('base64'); |
|
| 1055 | - break; |
|
| 1056 | - case 'array': |
|
| 1057 | - $return[] = ['array']; |
|
| 1058 | - break; |
|
| 1059 | - case 'struct': |
|
| 1060 | - $return[] = ['struct' => 'struct']; |
|
| 1061 | - break; |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - return $return; |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - /** |
|
| 1069 | - * @param $method |
|
| 1070 | - * @return mixed |
|
| 1071 | - */ |
|
| 1072 | - public function methodHelp($method) |
|
| 1073 | - { |
|
| 1074 | - return $this->help[$method]; |
|
| 1075 | - } |
|
| 921 | + public $signatures; |
|
| 922 | + public $help; |
|
| 923 | + |
|
| 924 | + /** |
|
| 925 | + * IXR_IntrospectionServer constructor. |
|
| 926 | + */ |
|
| 927 | + public function __construct() |
|
| 928 | + { |
|
| 929 | + $this->setCallbacks(); |
|
| 930 | + $this->setCapabilities(); |
|
| 931 | + $this->capabilities['introspection'] = [ |
|
| 932 | + 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 933 | + 'specVersion' => 1 |
|
| 934 | + ]; |
|
| 935 | + $this->addCallback('system.methodSignature', 'this:methodSignature', ['array', 'string'], 'Returns an array describing the return type and required parameters of a method'); |
|
| 936 | + $this->addCallback('system.getCapabilities', 'this:getCapabilities', ['struct'], 'Returns a struct describing the XML-RPC specifications supported by this server'); |
|
| 937 | + $this->addCallback('system.listMethods', 'this:listMethods', ['array'], 'Returns an array of available methods on this server'); |
|
| 938 | + $this->addCallback('system.methodHelp', 'this:methodHelp', ['string', 'string'], 'Returns a documentation string for the specified method'); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + /** |
|
| 942 | + * @param $method |
|
| 943 | + * @param $callback |
|
| 944 | + * @param $args |
|
| 945 | + * @param $help |
|
| 946 | + */ |
|
| 947 | + public function addCallback($method, $callback, $args, $help) |
|
| 948 | + { |
|
| 949 | + $this->callbacks[$method] = $callback; |
|
| 950 | + $this->signatures[$method] = $args; |
|
| 951 | + $this->help[$method] = $help; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * @param $methodname |
|
| 956 | + * @param $args |
|
| 957 | + * @return IXR_Error|mixed |
|
| 958 | + */ |
|
| 959 | + public function call($methodname, $args) |
|
| 960 | + { |
|
| 961 | + // Make sure it's in an array |
|
| 962 | + if ($args && !is_array($args)) { |
|
| 963 | + $args = [$args]; |
|
| 964 | + } |
|
| 965 | + // Over-rides default call method, adds signature check |
|
| 966 | + if (!$this->hasMethod($methodname)) { |
|
| 967 | + return new IXR_Error(-32601, 'server error. requested method "' . $this->message->methodName . '" not specified.'); |
|
| 968 | + } |
|
| 969 | + $method = $this->callbacks[$methodname]; |
|
| 970 | + $signature = $this->signatures[$methodname]; |
|
| 971 | + $returnType = array_shift($signature); |
|
| 972 | + // Check the number of arguments |
|
| 973 | + if (count($args) != count($signature)) { |
|
| 974 | + // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
| 975 | + return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 976 | + } |
|
| 977 | + // Check the argument types |
|
| 978 | + $ok = true; |
|
| 979 | + $argsbackup = $args; |
|
| 980 | + for ($i = 0, $j = count($args); $i < $j; ++$i) { |
|
| 981 | + $arg = array_shift($args); |
|
| 982 | + $type = array_shift($signature); |
|
| 983 | + switch ($type) { |
|
| 984 | + case 'int': |
|
| 985 | + case 'i4': |
|
| 986 | + if (is_array($arg) || !is_int($arg)) { |
|
| 987 | + $ok = false; |
|
| 988 | + } |
|
| 989 | + break; |
|
| 990 | + case 'base64': |
|
| 991 | + case 'string': |
|
| 992 | + if (!is_string($arg)) { |
|
| 993 | + $ok = false; |
|
| 994 | + } |
|
| 995 | + break; |
|
| 996 | + case 'boolean': |
|
| 997 | + if (false !== $arg && true !== $arg) { |
|
| 998 | + $ok = false; |
|
| 999 | + } |
|
| 1000 | + break; |
|
| 1001 | + case 'float': |
|
| 1002 | + case 'double': |
|
| 1003 | + if (!is_float($arg)) { |
|
| 1004 | + $ok = false; |
|
| 1005 | + } |
|
| 1006 | + break; |
|
| 1007 | + case 'date': |
|
| 1008 | + case 'dateTime.iso8601': |
|
| 1009 | + if (!is_a($arg, 'IXR_Date')) { |
|
| 1010 | + $ok = false; |
|
| 1011 | + } |
|
| 1012 | + break; |
|
| 1013 | + } |
|
| 1014 | + if (!$ok) { |
|
| 1015 | + return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + // It passed the test - run the "real" method call |
|
| 1020 | + return parent::call($methodname, $argsbackup); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * @param $method |
|
| 1025 | + * @return array|IXR_Error |
|
| 1026 | + */ |
|
| 1027 | + public function methodSignature($method) |
|
| 1028 | + { |
|
| 1029 | + if (!$this->hasMethod($method)) { |
|
| 1030 | + return new IXR_Error(-32601, 'server error. requested method "' . $method . '" not specified.'); |
|
| 1031 | + } |
|
| 1032 | + // We should be returning an array of types |
|
| 1033 | + $types = $this->signatures[$method]; |
|
| 1034 | + $return = []; |
|
| 1035 | + foreach ($types as $type) { |
|
| 1036 | + switch ($type) { |
|
| 1037 | + case 'string': |
|
| 1038 | + $return[] = 'string'; |
|
| 1039 | + break; |
|
| 1040 | + case 'int': |
|
| 1041 | + case 'i4': |
|
| 1042 | + $return[] = 42; |
|
| 1043 | + break; |
|
| 1044 | + case 'double': |
|
| 1045 | + $return[] = 3.1415; |
|
| 1046 | + break; |
|
| 1047 | + case 'dateTime.iso8601': |
|
| 1048 | + $return[] = new IXR_Date(time()); |
|
| 1049 | + break; |
|
| 1050 | + case 'boolean': |
|
| 1051 | + $return[] = true; |
|
| 1052 | + break; |
|
| 1053 | + case 'base64': |
|
| 1054 | + $return[] = new IXR_Base64('base64'); |
|
| 1055 | + break; |
|
| 1056 | + case 'array': |
|
| 1057 | + $return[] = ['array']; |
|
| 1058 | + break; |
|
| 1059 | + case 'struct': |
|
| 1060 | + $return[] = ['struct' => 'struct']; |
|
| 1061 | + break; |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + return $return; |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + /** |
|
| 1069 | + * @param $method |
|
| 1070 | + * @return mixed |
|
| 1071 | + */ |
|
| 1072 | + public function methodHelp($method) |
|
| 1073 | + { |
|
| 1074 | + return $this->help[$method]; |
|
| 1075 | + } |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1080,37 +1080,37 @@ discard block |
||
| 1080 | 1080 | */ |
| 1081 | 1081 | class IXR_ClientMulticall extends IXR_Client |
| 1082 | 1082 | { |
| 1083 | - public $calls = []; |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * IXR_ClientMulticall constructor. |
|
| 1087 | - * @param $server |
|
| 1088 | - * @param bool $path |
|
| 1089 | - * @param int $port |
|
| 1090 | - */ |
|
| 1091 | - public function __construct($server, $path = false, $port = 80) |
|
| 1092 | - { |
|
| 1093 | - parent::IXR_Client($server, $path, $port); |
|
| 1094 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - public function addCall() |
|
| 1098 | - { |
|
| 1099 | - $args = func_get_args(); |
|
| 1100 | - $methodName = array_shift($args); |
|
| 1101 | - $struct = [ |
|
| 1102 | - 'methodName' => $methodName, |
|
| 1103 | - 'params' => $args |
|
| 1104 | - ]; |
|
| 1105 | - $this->calls[] = $struct; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * @return bool |
|
| 1110 | - */ |
|
| 1111 | - public function query() |
|
| 1112 | - { |
|
| 1113 | - // Prepare multicall, then call the parent::query() method |
|
| 1114 | - return parent::query('system.multicall', $this->calls); |
|
| 1115 | - } |
|
| 1083 | + public $calls = []; |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * IXR_ClientMulticall constructor. |
|
| 1087 | + * @param $server |
|
| 1088 | + * @param bool $path |
|
| 1089 | + * @param int $port |
|
| 1090 | + */ |
|
| 1091 | + public function __construct($server, $path = false, $port = 80) |
|
| 1092 | + { |
|
| 1093 | + parent::IXR_Client($server, $path, $port); |
|
| 1094 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + public function addCall() |
|
| 1098 | + { |
|
| 1099 | + $args = func_get_args(); |
|
| 1100 | + $methodName = array_shift($args); |
|
| 1101 | + $struct = [ |
|
| 1102 | + 'methodName' => $methodName, |
|
| 1103 | + 'params' => $args |
|
| 1104 | + ]; |
|
| 1105 | + $this->calls[] = $struct; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * @return bool |
|
| 1110 | + */ |
|
| 1111 | + public function query() |
|
| 1112 | + { |
|
| 1113 | + // Prepare multicall, then call the parent::query() method |
|
| 1114 | + return parent::query('system.multicall', $this->calls); |
|
| 1115 | + } |
|
| 1116 | 1116 | } |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | public $_feed; |
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | - * @param $format |
|
| 372 | + * @param string $format |
|
| 373 | 373 | */ |
| 374 | 374 | public function _setFormat($format) |
| 375 | 375 | { |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | /** |
| 567 | 567 | * Adds an FeedItem to the feed. |
| 568 | 568 | * |
| 569 | - * @param $item |
|
| 569 | + * @param FeedItem $item |
|
| 570 | 570 | * @internal param FeedItem $object $item The FeedItem to add to the feed. |
| 571 | 571 | * @access public |
| 572 | 572 | */ |
@@ -585,6 +585,7 @@ discard block |
||
| 585 | 585 | * @static |
| 586 | 586 | * @param string string A string to be truncated. |
| 587 | 587 | * @param int length the maximum length the string should be truncated to |
| 588 | + * @param integer $length |
|
| 588 | 589 | * @return string the truncated string |
| 589 | 590 | */ |
| 590 | 591 | public function iTrunc($string, $length) |
@@ -696,7 +697,7 @@ discard block |
||
| 696 | 697 | /** |
| 697 | 698 | * @since 1.4 |
| 698 | 699 | * @access private |
| 699 | - * @param $filename |
|
| 700 | + * @param string $filename |
|
| 700 | 701 | */ |
| 701 | 702 | public function _redirect($filename) |
| 702 | 703 | { |
@@ -853,7 +854,7 @@ discard block |
||
| 853 | 854 | /** |
| 854 | 855 | * Gets the date stored in this FeedDate as an RFC 822 date. |
| 855 | 856 | * |
| 856 | - * @return a date in RFC 822 format |
|
| 857 | + * @return string date in RFC 822 format |
|
| 857 | 858 | */ |
| 858 | 859 | public function rfc822() |
| 859 | 860 | { |
@@ -869,7 +870,7 @@ discard block |
||
| 869 | 870 | /** |
| 870 | 871 | * Gets the date stored in this FeedDate as an ISO 8601 date. |
| 871 | 872 | * |
| 872 | - * @return a date in ISO 8601 format |
|
| 873 | + * @return string date in ISO 8601 format |
|
| 873 | 874 | */ |
| 874 | 875 | public function iso8601() |
| 875 | 876 | { |
@@ -999,7 +1000,7 @@ discard block |
||
| 999 | 1000 | /** |
| 1000 | 1001 | * Sets this RSS feed's version number. |
| 1001 | 1002 | * @access private |
| 1002 | - * @param $version |
|
| 1003 | + * @param string $version |
|
| 1003 | 1004 | */ |
| 1004 | 1005 | public function _setRSSVersion($version) |
| 1005 | 1006 | { |
@@ -197,52 +197,52 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | class FeedItem extends HtmlDescribable |
| 199 | 199 | { |
| 200 | - /** |
|
| 201 | - * Mandatory attributes of an item. |
|
| 202 | - */ |
|
| 203 | - public $title; |
|
| 204 | - public $description; |
|
| 205 | - public $link; |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Optional attributes of an item. |
|
| 209 | - */ |
|
| 210 | - public $author; |
|
| 211 | - public $authorEmail; |
|
| 212 | - public $image; |
|
| 213 | - public $category; |
|
| 214 | - public $comments; |
|
| 215 | - public $guid; |
|
| 216 | - public $source; |
|
| 217 | - public $creator; |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Publishing date of an item. May be in one of the following formats: |
|
| 221 | - * |
|
| 222 | - * RFC 822: |
|
| 223 | - * "Mon, 20 Jan 03 18:05:41 +0400" |
|
| 224 | - * "20 Jan 03 18:05:41 +0000" |
|
| 225 | - * |
|
| 226 | - * ISO 8601: |
|
| 227 | - * "2003-01-20T18:05:41+04:00" |
|
| 228 | - * |
|
| 229 | - * Unix: |
|
| 230 | - * 1043082341 |
|
| 231 | - */ |
|
| 232 | - public $date; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Any additional elements to include as an assiciated array. All $key => $value pairs |
|
| 236 | - * will be included unencoded in the feed item in the form |
|
| 237 | - * <$key>$value</$key> |
|
| 238 | - * Again: No encoding will be used! This means you can invalidate or enhance the feed |
|
| 239 | - * if $value contains markup. This may be abused to embed tags not implemented by |
|
| 240 | - * the FeedCreator class used. |
|
| 241 | - */ |
|
| 242 | - public $additionalElements = []; |
|
| 243 | - |
|
| 244 | - // on hold |
|
| 245 | - // var $source; |
|
| 200 | + /** |
|
| 201 | + * Mandatory attributes of an item. |
|
| 202 | + */ |
|
| 203 | + public $title; |
|
| 204 | + public $description; |
|
| 205 | + public $link; |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Optional attributes of an item. |
|
| 209 | + */ |
|
| 210 | + public $author; |
|
| 211 | + public $authorEmail; |
|
| 212 | + public $image; |
|
| 213 | + public $category; |
|
| 214 | + public $comments; |
|
| 215 | + public $guid; |
|
| 216 | + public $source; |
|
| 217 | + public $creator; |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Publishing date of an item. May be in one of the following formats: |
|
| 221 | + * |
|
| 222 | + * RFC 822: |
|
| 223 | + * "Mon, 20 Jan 03 18:05:41 +0400" |
|
| 224 | + * "20 Jan 03 18:05:41 +0000" |
|
| 225 | + * |
|
| 226 | + * ISO 8601: |
|
| 227 | + * "2003-01-20T18:05:41+04:00" |
|
| 228 | + * |
|
| 229 | + * Unix: |
|
| 230 | + * 1043082341 |
|
| 231 | + */ |
|
| 232 | + public $date; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Any additional elements to include as an assiciated array. All $key => $value pairs |
|
| 236 | + * will be included unencoded in the feed item in the form |
|
| 237 | + * <$key>$value</$key> |
|
| 238 | + * Again: No encoding will be used! This means you can invalidate or enhance the feed |
|
| 239 | + * if $value contains markup. This may be abused to embed tags not implemented by |
|
| 240 | + * the FeedCreator class used. |
|
| 241 | + */ |
|
| 242 | + public $additionalElements = []; |
|
| 243 | + |
|
| 244 | + // on hold |
|
| 245 | + // var $source; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | class FeedImage extends HtmlDescribable |
| 254 | 254 | { |
| 255 | - /** |
|
| 256 | - * Mandatory attributes of an image. |
|
| 257 | - */ |
|
| 258 | - public $title; |
|
| 259 | - public $url; |
|
| 260 | - public $link; |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Optional attributes of an image. |
|
| 264 | - */ |
|
| 265 | - public $width; |
|
| 266 | - public $height; |
|
| 267 | - public $description; |
|
| 255 | + /** |
|
| 256 | + * Mandatory attributes of an image. |
|
| 257 | + */ |
|
| 258 | + public $title; |
|
| 259 | + public $url; |
|
| 260 | + public $link; |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Optional attributes of an image. |
|
| 264 | + */ |
|
| 265 | + public $width; |
|
| 266 | + public $height; |
|
| 267 | + public $description; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -273,29 +273,29 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | class HtmlDescribable |
| 275 | 275 | { |
| 276 | - /** |
|
| 277 | - * Indicates whether the description field should be rendered in HTML. |
|
| 278 | - */ |
|
| 279 | - public $descriptionHtmlSyndicated; |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Indicates whether and to how many characters a description should be truncated. |
|
| 283 | - */ |
|
| 284 | - public $descriptionTruncSize; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns a formatted description field, depending on descriptionHtmlSyndicated and |
|
| 288 | - * $descriptionTruncSize properties |
|
| 289 | - * @return string the formatted description |
|
| 290 | - */ |
|
| 291 | - public function getDescription() |
|
| 292 | - { |
|
| 293 | - $descriptionField = new FeedHtmlField($this->description); |
|
| 294 | - $descriptionField->syndicateHtml = $this->descriptionHtmlSyndicated; |
|
| 295 | - $descriptionField->truncSize = $this->descriptionTruncSize; |
|
| 296 | - |
|
| 297 | - return $descriptionField->output(); |
|
| 298 | - } |
|
| 276 | + /** |
|
| 277 | + * Indicates whether the description field should be rendered in HTML. |
|
| 278 | + */ |
|
| 279 | + public $descriptionHtmlSyndicated; |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Indicates whether and to how many characters a description should be truncated. |
|
| 283 | + */ |
|
| 284 | + public $descriptionTruncSize; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns a formatted description field, depending on descriptionHtmlSyndicated and |
|
| 288 | + * $descriptionTruncSize properties |
|
| 289 | + * @return string the formatted description |
|
| 290 | + */ |
|
| 291 | + public function getDescription() |
|
| 292 | + { |
|
| 293 | + $descriptionField = new FeedHtmlField($this->description); |
|
| 294 | + $descriptionField->syndicateHtml = $this->descriptionHtmlSyndicated; |
|
| 295 | + $descriptionField->truncSize = $this->descriptionTruncSize; |
|
| 296 | + |
|
| 297 | + return $descriptionField->output(); |
|
| 298 | + } |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,53 +306,53 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | class FeedHtmlField |
| 308 | 308 | { |
| 309 | - /** |
|
| 310 | - * Mandatory attributes of a FeedHtmlField. |
|
| 311 | - */ |
|
| 312 | - public $rawFieldContent; |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Optional attributes of a FeedHtmlField. |
|
| 316 | - * |
|
| 317 | - */ |
|
| 318 | - public $truncSize; |
|
| 319 | - public $syndicateHtml; |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Creates a new instance of FeedHtmlField. |
|
| 323 | - * @param $parFieldContent |
|
| 324 | - * @internal param $string : if given, sets the rawFieldContent property |
|
| 325 | - */ |
|
| 326 | - public function __construct($parFieldContent) |
|
| 327 | - { |
|
| 328 | - if ($parFieldContent) { |
|
| 329 | - $this->rawFieldContent = $parFieldContent; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Creates the right output, depending on $truncSize, $syndicateHtml properties. |
|
| 335 | - * @return string the formatted field |
|
| 336 | - */ |
|
| 337 | - public function output() |
|
| 338 | - { |
|
| 339 | - // when field available and syndicated in html we assume |
|
| 340 | - // - valid html in $rawFieldContent and we enclose in CDATA tags |
|
| 341 | - // - no truncation (truncating risks producing invalid html) |
|
| 342 | - if (!$this->rawFieldContent) { |
|
| 343 | - $result = ''; |
|
| 344 | - } elseif ($this->syndicateHtml) { |
|
| 345 | - $result = '<![CDATA[' . $this->rawFieldContent . ']]>'; |
|
| 346 | - } else { |
|
| 347 | - if ($this->truncSize && is_int($this->truncSize)) { |
|
| 348 | - $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent, ENT_QUOTES | ENT_HTML5), $this->truncSize); |
|
| 349 | - } else { |
|
| 350 | - $result = htmlspecialchars($this->rawFieldContent, ENT_QUOTES | ENT_HTML5); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return $result; |
|
| 355 | - } |
|
| 309 | + /** |
|
| 310 | + * Mandatory attributes of a FeedHtmlField. |
|
| 311 | + */ |
|
| 312 | + public $rawFieldContent; |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Optional attributes of a FeedHtmlField. |
|
| 316 | + * |
|
| 317 | + */ |
|
| 318 | + public $truncSize; |
|
| 319 | + public $syndicateHtml; |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Creates a new instance of FeedHtmlField. |
|
| 323 | + * @param $parFieldContent |
|
| 324 | + * @internal param $string : if given, sets the rawFieldContent property |
|
| 325 | + */ |
|
| 326 | + public function __construct($parFieldContent) |
|
| 327 | + { |
|
| 328 | + if ($parFieldContent) { |
|
| 329 | + $this->rawFieldContent = $parFieldContent; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Creates the right output, depending on $truncSize, $syndicateHtml properties. |
|
| 335 | + * @return string the formatted field |
|
| 336 | + */ |
|
| 337 | + public function output() |
|
| 338 | + { |
|
| 339 | + // when field available and syndicated in html we assume |
|
| 340 | + // - valid html in $rawFieldContent and we enclose in CDATA tags |
|
| 341 | + // - no truncation (truncating risks producing invalid html) |
|
| 342 | + if (!$this->rawFieldContent) { |
|
| 343 | + $result = ''; |
|
| 344 | + } elseif ($this->syndicateHtml) { |
|
| 345 | + $result = '<![CDATA[' . $this->rawFieldContent . ']]>'; |
|
| 346 | + } else { |
|
| 347 | + if ($this->truncSize && is_int($this->truncSize)) { |
|
| 348 | + $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent, ENT_QUOTES | ENT_HTML5), $this->truncSize); |
|
| 349 | + } else { |
|
| 350 | + $result = htmlspecialchars($this->rawFieldContent, ENT_QUOTES | ENT_HTML5); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return $result; |
|
| 355 | + } |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -366,129 +366,129 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | class UniversalFeedCreator extends FeedCreator |
| 368 | 368 | { |
| 369 | - public $_feed; |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param $format |
|
| 373 | - */ |
|
| 374 | - public function _setFormat($format) |
|
| 375 | - { |
|
| 376 | - switch (strtoupper($format)) { |
|
| 377 | - |
|
| 378 | - case '2.0': |
|
| 379 | - // fall through |
|
| 380 | - case 'RSS2.0': |
|
| 381 | - $this->_feed = new RSSCreator20(); |
|
| 382 | - break; |
|
| 383 | - |
|
| 384 | - case '1.0': |
|
| 385 | - // fall through |
|
| 386 | - case 'RSS1.0': |
|
| 387 | - $this->_feed = new RSSCreator10(); |
|
| 388 | - break; |
|
| 389 | - |
|
| 390 | - case '0.91': |
|
| 391 | - // fall through |
|
| 392 | - case 'RSS0.91': |
|
| 393 | - $this->_feed = new RSSCreator091(); |
|
| 394 | - break; |
|
| 395 | - |
|
| 396 | - case 'PIE0.1': |
|
| 397 | - $this->_feed = new PIECreator01(); |
|
| 398 | - break; |
|
| 399 | - |
|
| 400 | - case 'MBOX': |
|
| 401 | - $this->_feed = new MBOXCreator(); |
|
| 402 | - break; |
|
| 403 | - |
|
| 404 | - case 'OPML': |
|
| 405 | - $this->_feed = new OPMLCreator(); |
|
| 406 | - break; |
|
| 407 | - |
|
| 408 | - case 'ATOM': |
|
| 409 | - // fall through: always the latest ATOM version |
|
| 410 | - |
|
| 411 | - case 'ATOM0.3': |
|
| 412 | - $this->_feed = new AtomCreator03(); |
|
| 413 | - break; |
|
| 414 | - |
|
| 415 | - case 'HTML': |
|
| 416 | - $this->_feed = new HTMLCreator(); |
|
| 417 | - break; |
|
| 418 | - |
|
| 419 | - case 'JS': |
|
| 420 | - // fall through |
|
| 421 | - case 'JAVASCRIPT': |
|
| 422 | - $this->_feed = new JSCreator(); |
|
| 423 | - break; |
|
| 424 | - |
|
| 425 | - default: |
|
| 426 | - $this->_feed = new RSSCreator091(); |
|
| 427 | - break; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $vars = get_object_vars($this); |
|
| 431 | - foreach ($vars as $key => $value) { |
|
| 432 | - // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself |
|
| 433 | - //if (!in_array($key, array("_feed", "contentType", "encoding"))) { |
|
| 434 | - $this->_feed->{$key} = $this->{$key}; |
|
| 435 | - //} |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Creates a syndication feed based on the items previously added. |
|
| 441 | - * |
|
| 442 | - * @see FeedCreator::addItem() |
|
| 443 | - * @param string format format the feed should comply to. Valid values are: |
|
| 444 | - * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS" |
|
| 445 | - * @return string the contents of the feed. |
|
| 446 | - */ |
|
| 447 | - public function createFeed($format = 'RSS0.91') |
|
| 448 | - { |
|
| 449 | - $this->_setFormat($format); |
|
| 450 | - |
|
| 451 | - return $this->_feed->createFeed(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect |
|
| 456 | - * header may be sent to redirect the use to the newly created file. |
|
| 457 | - * @since 1.4 |
|
| 458 | - * |
|
| 459 | - * @param string $format |
|
| 460 | - * @param string $filename |
|
| 461 | - * @param bool $displayContents displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. |
|
| 462 | - * @internal param format $string format the feed should comply to. Valid values are: |
|
| 463 | - * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS" |
|
| 464 | - * @internal param filename $string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 465 | - */ |
|
| 466 | - public function saveFeed($format = 'RSS0.91', $filename = '', $displayContents = true) |
|
| 467 | - { |
|
| 468 | - $this->_setFormat($format); |
|
| 469 | - $this->_feed->saveFeed($filename, $displayContents); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Turns on caching and checks if there is a recent version of this feed in the cache. |
|
| 474 | - * If there is, an HTTP redirect header is sent. |
|
| 475 | - * To effectively use caching, you should create the FeedCreator object and call this method |
|
| 476 | - * before anything else, especially before you do the time consuming task to build the feed |
|
| 477 | - * (web fetching, for example). |
|
| 478 | - * |
|
| 479 | - * @param string $format |
|
| 480 | - * @param string $filename |
|
| 481 | - * @param int $timeout |
|
| 482 | - * @internal param format $string format the feed should comply to. Valid values are: |
|
| 483 | - * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". |
|
| 484 | - * @internal param string $filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 485 | - * @internal param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
|
| 486 | - */ |
|
| 487 | - public function useCached($format = 'RSS0.91', $filename = '', $timeout = 3600) |
|
| 488 | - { |
|
| 489 | - $this->_setFormat($format); |
|
| 490 | - $this->_feed->useCached($filename, $timeout); |
|
| 491 | - } |
|
| 369 | + public $_feed; |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param $format |
|
| 373 | + */ |
|
| 374 | + public function _setFormat($format) |
|
| 375 | + { |
|
| 376 | + switch (strtoupper($format)) { |
|
| 377 | + |
|
| 378 | + case '2.0': |
|
| 379 | + // fall through |
|
| 380 | + case 'RSS2.0': |
|
| 381 | + $this->_feed = new RSSCreator20(); |
|
| 382 | + break; |
|
| 383 | + |
|
| 384 | + case '1.0': |
|
| 385 | + // fall through |
|
| 386 | + case 'RSS1.0': |
|
| 387 | + $this->_feed = new RSSCreator10(); |
|
| 388 | + break; |
|
| 389 | + |
|
| 390 | + case '0.91': |
|
| 391 | + // fall through |
|
| 392 | + case 'RSS0.91': |
|
| 393 | + $this->_feed = new RSSCreator091(); |
|
| 394 | + break; |
|
| 395 | + |
|
| 396 | + case 'PIE0.1': |
|
| 397 | + $this->_feed = new PIECreator01(); |
|
| 398 | + break; |
|
| 399 | + |
|
| 400 | + case 'MBOX': |
|
| 401 | + $this->_feed = new MBOXCreator(); |
|
| 402 | + break; |
|
| 403 | + |
|
| 404 | + case 'OPML': |
|
| 405 | + $this->_feed = new OPMLCreator(); |
|
| 406 | + break; |
|
| 407 | + |
|
| 408 | + case 'ATOM': |
|
| 409 | + // fall through: always the latest ATOM version |
|
| 410 | + |
|
| 411 | + case 'ATOM0.3': |
|
| 412 | + $this->_feed = new AtomCreator03(); |
|
| 413 | + break; |
|
| 414 | + |
|
| 415 | + case 'HTML': |
|
| 416 | + $this->_feed = new HTMLCreator(); |
|
| 417 | + break; |
|
| 418 | + |
|
| 419 | + case 'JS': |
|
| 420 | + // fall through |
|
| 421 | + case 'JAVASCRIPT': |
|
| 422 | + $this->_feed = new JSCreator(); |
|
| 423 | + break; |
|
| 424 | + |
|
| 425 | + default: |
|
| 426 | + $this->_feed = new RSSCreator091(); |
|
| 427 | + break; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $vars = get_object_vars($this); |
|
| 431 | + foreach ($vars as $key => $value) { |
|
| 432 | + // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself |
|
| 433 | + //if (!in_array($key, array("_feed", "contentType", "encoding"))) { |
|
| 434 | + $this->_feed->{$key} = $this->{$key}; |
|
| 435 | + //} |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Creates a syndication feed based on the items previously added. |
|
| 441 | + * |
|
| 442 | + * @see FeedCreator::addItem() |
|
| 443 | + * @param string format format the feed should comply to. Valid values are: |
|
| 444 | + * "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS" |
|
| 445 | + * @return string the contents of the feed. |
|
| 446 | + */ |
|
| 447 | + public function createFeed($format = 'RSS0.91') |
|
| 448 | + { |
|
| 449 | + $this->_setFormat($format); |
|
| 450 | + |
|
| 451 | + return $this->_feed->createFeed(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect |
|
| 456 | + * header may be sent to redirect the use to the newly created file. |
|
| 457 | + * @since 1.4 |
|
| 458 | + * |
|
| 459 | + * @param string $format |
|
| 460 | + * @param string $filename |
|
| 461 | + * @param bool $displayContents displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. |
|
| 462 | + * @internal param format $string format the feed should comply to. Valid values are: |
|
| 463 | + * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS" |
|
| 464 | + * @internal param filename $string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 465 | + */ |
|
| 466 | + public function saveFeed($format = 'RSS0.91', $filename = '', $displayContents = true) |
|
| 467 | + { |
|
| 468 | + $this->_setFormat($format); |
|
| 469 | + $this->_feed->saveFeed($filename, $displayContents); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Turns on caching and checks if there is a recent version of this feed in the cache. |
|
| 474 | + * If there is, an HTTP redirect header is sent. |
|
| 475 | + * To effectively use caching, you should create the FeedCreator object and call this method |
|
| 476 | + * before anything else, especially before you do the time consuming task to build the feed |
|
| 477 | + * (web fetching, for example). |
|
| 478 | + * |
|
| 479 | + * @param string $format |
|
| 480 | + * @param string $filename |
|
| 481 | + * @param int $timeout |
|
| 482 | + * @internal param format $string format the feed should comply to. Valid values are: |
|
| 483 | + * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". |
|
| 484 | + * @internal param string $filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 485 | + * @internal param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
|
| 486 | + */ |
|
| 487 | + public function useCached($format = 'RSS0.91', $filename = '', $timeout = 3600) |
|
| 488 | + { |
|
| 489 | + $this->_setFormat($format); |
|
| 490 | + $this->_feed->useCached($filename, $timeout); |
|
| 491 | + } |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -501,271 +501,271 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | class FeedCreator extends HtmlDescribable |
| 503 | 503 | { |
| 504 | - /** |
|
| 505 | - * Mandatory attributes of a feed. |
|
| 506 | - */ |
|
| 507 | - public $title; |
|
| 508 | - public $description; |
|
| 509 | - public $link; |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Optional attributes of a feed. |
|
| 513 | - */ |
|
| 514 | - public $syndicationURL; |
|
| 515 | - public $image; |
|
| 516 | - public $language; |
|
| 517 | - public $copyright; |
|
| 518 | - public $pubDate; |
|
| 519 | - public $lastBuildDate; |
|
| 520 | - public $editor; |
|
| 521 | - public $editorEmail; |
|
| 522 | - public $webmaster; |
|
| 523 | - public $category; |
|
| 524 | - public $docs; |
|
| 525 | - public $ttl; |
|
| 526 | - public $rating; |
|
| 527 | - public $skipHours; |
|
| 528 | - public $skipDays; |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * The url of the external xsl stylesheet used to format the naked rss feed. |
|
| 532 | - * Ignored in the output when empty. |
|
| 533 | - */ |
|
| 534 | - public $xslStyleSheet = ''; |
|
| 535 | - |
|
| 536 | - public $cssStyleSheet = ''; |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @access private |
|
| 540 | - */ |
|
| 541 | - public $items = []; |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * This feed's MIME content type. |
|
| 545 | - * @since 1.4 |
|
| 546 | - * @access private |
|
| 547 | - */ |
|
| 548 | - public $contentType = 'application/xml'; |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * This feed's character encoding. |
|
| 552 | - * @since 1.6.1 |
|
| 553 | - **/ |
|
| 554 | - public $encoding = 'ISO-8859-1'; |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Any additional elements to include as an assiciated array. All $key => $value pairs |
|
| 558 | - * will be included unencoded in the feed in the form |
|
| 559 | - * <$key>$value</$key> |
|
| 560 | - * Again: No encoding will be used! This means you can invalidate or enhance the feed |
|
| 561 | - * if $value contains markup. This may be abused to embed tags not implemented by |
|
| 562 | - * the FeedCreator class used. |
|
| 563 | - */ |
|
| 564 | - public $additionalElements = []; |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Adds an FeedItem to the feed. |
|
| 568 | - * |
|
| 569 | - * @param $item |
|
| 570 | - * @internal param FeedItem $object $item The FeedItem to add to the feed. |
|
| 571 | - * @access public |
|
| 572 | - */ |
|
| 573 | - public function addItem($item) |
|
| 574 | - { |
|
| 575 | - $this->items[] = $item; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Truncates a string to a certain length at the most sensible point. |
|
| 580 | - * First, if there's a '.' character near the end of the string, the string is truncated after this character. |
|
| 581 | - * If there is no '.', the string is truncated after the last ' ' character. |
|
| 582 | - * If the string is truncated, " ..." is appended. |
|
| 583 | - * If the string is already shorter than $length, it is returned unchanged. |
|
| 584 | - * |
|
| 585 | - * @static |
|
| 586 | - * @param string string A string to be truncated. |
|
| 587 | - * @param int length the maximum length the string should be truncated to |
|
| 588 | - * @return string the truncated string |
|
| 589 | - */ |
|
| 590 | - public function iTrunc($string, $length) |
|
| 591 | - { |
|
| 592 | - if (strlen($string) <= $length) { |
|
| 593 | - return $string; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - $pos = strrpos($string, '.'); |
|
| 597 | - if ($pos >= $length - 4) { |
|
| 598 | - $string = substr($string, 0, $length - 4); |
|
| 599 | - $pos = strrpos($string, '.'); |
|
| 600 | - } |
|
| 601 | - if ($pos >= $length * 0.4) { |
|
| 602 | - return substr($string, 0, $pos + 1) . ' ...'; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - $pos = strrpos($string, ' '); |
|
| 606 | - if ($pos >= $length - 4) { |
|
| 607 | - $string = substr($string, 0, $length - 4); |
|
| 608 | - $pos = strrpos($string, ' '); |
|
| 609 | - } |
|
| 610 | - if ($pos >= $length * 0.4) { |
|
| 611 | - return substr($string, 0, $pos) . ' ...'; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - return substr($string, 0, $length - 4) . ' ...'; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Creates a comment indicating the generator of this feed. |
|
| 619 | - * The format of this comment seems to be recognized by |
|
| 620 | - * Syndic8.com. |
|
| 621 | - */ |
|
| 622 | - public function _createGeneratorComment() |
|
| 623 | - { |
|
| 624 | - return '<!-- generator="' . FEEDCREATOR_VERSION . "\" -->\n"; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Creates a string containing all additional elements specified in |
|
| 629 | - * $additionalElements. |
|
| 630 | - * @param array $elements |
|
| 631 | - * @param string $indentString |
|
| 632 | - * @return string the XML tags corresponding to $additionalElements |
|
| 633 | - * @internal param array $elements an associative array containing key => value pairs |
|
| 634 | - * @internal param string $indentString a string that will be inserted before every generated line |
|
| 635 | - */ |
|
| 636 | - public function _createAdditionalElements($elements, $indentString = '') |
|
| 637 | - { |
|
| 638 | - $ae = ''; |
|
| 639 | - if (is_array($elements)) { |
|
| 640 | - foreach ($elements as $key => $value) { |
|
| 641 | - $ae .= $indentString . "<$key>$value</$key>\n"; |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return $ae; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @return string |
|
| 650 | - */ |
|
| 651 | - public function _createStylesheetReferences() |
|
| 652 | - { |
|
| 653 | - $xml = ''; |
|
| 654 | - if ($this->cssStyleSheet) { |
|
| 655 | - $xml .= '<?xml-stylesheet href="' . $this->cssStyleSheet . "\" type=\"text/css\"?>\n"; |
|
| 656 | - } |
|
| 657 | - if ($this->xslStyleSheet) { |
|
| 658 | - $xml .= '<?xml-stylesheet href="' . $this->xslStyleSheet . "\" type=\"text/xsl\"?>\n"; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - return $xml; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Builds the feed's text. |
|
| 666 | - * @abstract |
|
| 667 | - * @return string the feed's complete text |
|
| 668 | - */ |
|
| 669 | - public function createFeed() |
|
| 670 | - { |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml. |
|
| 675 | - * For example: |
|
| 676 | - * |
|
| 677 | - * echo $_SERVER["PHP_SELF"]."\n"; |
|
| 678 | - * echo FeedCreator::_generateFilename(); |
|
| 679 | - * |
|
| 680 | - * would produce: |
|
| 681 | - * |
|
| 682 | - * /rss/latestnews.php |
|
| 683 | - * latestnews.xml |
|
| 684 | - * |
|
| 685 | - * @return string the feed cache filename |
|
| 686 | - * @since 1.4 |
|
| 687 | - * @access private |
|
| 688 | - */ |
|
| 689 | - public function _generateFilename() |
|
| 690 | - { |
|
| 691 | - $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 692 | - |
|
| 693 | - return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.xml'; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * @since 1.4 |
|
| 698 | - * @access private |
|
| 699 | - * @param $filename |
|
| 700 | - */ |
|
| 701 | - public function _redirect($filename) |
|
| 702 | - { |
|
| 703 | - // attention, heavily-commented-out-area |
|
| 704 | - |
|
| 705 | - // maybe use this in addition to file time checking |
|
| 706 | - //Header("Expires: ".date("r",time()+$this->_timeout)); |
|
| 707 | - |
|
| 708 | - /* no caching at all, doesn't seem to work as good: |
|
| 504 | + /** |
|
| 505 | + * Mandatory attributes of a feed. |
|
| 506 | + */ |
|
| 507 | + public $title; |
|
| 508 | + public $description; |
|
| 509 | + public $link; |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Optional attributes of a feed. |
|
| 513 | + */ |
|
| 514 | + public $syndicationURL; |
|
| 515 | + public $image; |
|
| 516 | + public $language; |
|
| 517 | + public $copyright; |
|
| 518 | + public $pubDate; |
|
| 519 | + public $lastBuildDate; |
|
| 520 | + public $editor; |
|
| 521 | + public $editorEmail; |
|
| 522 | + public $webmaster; |
|
| 523 | + public $category; |
|
| 524 | + public $docs; |
|
| 525 | + public $ttl; |
|
| 526 | + public $rating; |
|
| 527 | + public $skipHours; |
|
| 528 | + public $skipDays; |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * The url of the external xsl stylesheet used to format the naked rss feed. |
|
| 532 | + * Ignored in the output when empty. |
|
| 533 | + */ |
|
| 534 | + public $xslStyleSheet = ''; |
|
| 535 | + |
|
| 536 | + public $cssStyleSheet = ''; |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @access private |
|
| 540 | + */ |
|
| 541 | + public $items = []; |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * This feed's MIME content type. |
|
| 545 | + * @since 1.4 |
|
| 546 | + * @access private |
|
| 547 | + */ |
|
| 548 | + public $contentType = 'application/xml'; |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * This feed's character encoding. |
|
| 552 | + * @since 1.6.1 |
|
| 553 | + **/ |
|
| 554 | + public $encoding = 'ISO-8859-1'; |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Any additional elements to include as an assiciated array. All $key => $value pairs |
|
| 558 | + * will be included unencoded in the feed in the form |
|
| 559 | + * <$key>$value</$key> |
|
| 560 | + * Again: No encoding will be used! This means you can invalidate or enhance the feed |
|
| 561 | + * if $value contains markup. This may be abused to embed tags not implemented by |
|
| 562 | + * the FeedCreator class used. |
|
| 563 | + */ |
|
| 564 | + public $additionalElements = []; |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Adds an FeedItem to the feed. |
|
| 568 | + * |
|
| 569 | + * @param $item |
|
| 570 | + * @internal param FeedItem $object $item The FeedItem to add to the feed. |
|
| 571 | + * @access public |
|
| 572 | + */ |
|
| 573 | + public function addItem($item) |
|
| 574 | + { |
|
| 575 | + $this->items[] = $item; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Truncates a string to a certain length at the most sensible point. |
|
| 580 | + * First, if there's a '.' character near the end of the string, the string is truncated after this character. |
|
| 581 | + * If there is no '.', the string is truncated after the last ' ' character. |
|
| 582 | + * If the string is truncated, " ..." is appended. |
|
| 583 | + * If the string is already shorter than $length, it is returned unchanged. |
|
| 584 | + * |
|
| 585 | + * @static |
|
| 586 | + * @param string string A string to be truncated. |
|
| 587 | + * @param int length the maximum length the string should be truncated to |
|
| 588 | + * @return string the truncated string |
|
| 589 | + */ |
|
| 590 | + public function iTrunc($string, $length) |
|
| 591 | + { |
|
| 592 | + if (strlen($string) <= $length) { |
|
| 593 | + return $string; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + $pos = strrpos($string, '.'); |
|
| 597 | + if ($pos >= $length - 4) { |
|
| 598 | + $string = substr($string, 0, $length - 4); |
|
| 599 | + $pos = strrpos($string, '.'); |
|
| 600 | + } |
|
| 601 | + if ($pos >= $length * 0.4) { |
|
| 602 | + return substr($string, 0, $pos + 1) . ' ...'; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + $pos = strrpos($string, ' '); |
|
| 606 | + if ($pos >= $length - 4) { |
|
| 607 | + $string = substr($string, 0, $length - 4); |
|
| 608 | + $pos = strrpos($string, ' '); |
|
| 609 | + } |
|
| 610 | + if ($pos >= $length * 0.4) { |
|
| 611 | + return substr($string, 0, $pos) . ' ...'; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + return substr($string, 0, $length - 4) . ' ...'; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Creates a comment indicating the generator of this feed. |
|
| 619 | + * The format of this comment seems to be recognized by |
|
| 620 | + * Syndic8.com. |
|
| 621 | + */ |
|
| 622 | + public function _createGeneratorComment() |
|
| 623 | + { |
|
| 624 | + return '<!-- generator="' . FEEDCREATOR_VERSION . "\" -->\n"; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Creates a string containing all additional elements specified in |
|
| 629 | + * $additionalElements. |
|
| 630 | + * @param array $elements |
|
| 631 | + * @param string $indentString |
|
| 632 | + * @return string the XML tags corresponding to $additionalElements |
|
| 633 | + * @internal param array $elements an associative array containing key => value pairs |
|
| 634 | + * @internal param string $indentString a string that will be inserted before every generated line |
|
| 635 | + */ |
|
| 636 | + public function _createAdditionalElements($elements, $indentString = '') |
|
| 637 | + { |
|
| 638 | + $ae = ''; |
|
| 639 | + if (is_array($elements)) { |
|
| 640 | + foreach ($elements as $key => $value) { |
|
| 641 | + $ae .= $indentString . "<$key>$value</$key>\n"; |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return $ae; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @return string |
|
| 650 | + */ |
|
| 651 | + public function _createStylesheetReferences() |
|
| 652 | + { |
|
| 653 | + $xml = ''; |
|
| 654 | + if ($this->cssStyleSheet) { |
|
| 655 | + $xml .= '<?xml-stylesheet href="' . $this->cssStyleSheet . "\" type=\"text/css\"?>\n"; |
|
| 656 | + } |
|
| 657 | + if ($this->xslStyleSheet) { |
|
| 658 | + $xml .= '<?xml-stylesheet href="' . $this->xslStyleSheet . "\" type=\"text/xsl\"?>\n"; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + return $xml; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Builds the feed's text. |
|
| 666 | + * @abstract |
|
| 667 | + * @return string the feed's complete text |
|
| 668 | + */ |
|
| 669 | + public function createFeed() |
|
| 670 | + { |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml. |
|
| 675 | + * For example: |
|
| 676 | + * |
|
| 677 | + * echo $_SERVER["PHP_SELF"]."\n"; |
|
| 678 | + * echo FeedCreator::_generateFilename(); |
|
| 679 | + * |
|
| 680 | + * would produce: |
|
| 681 | + * |
|
| 682 | + * /rss/latestnews.php |
|
| 683 | + * latestnews.xml |
|
| 684 | + * |
|
| 685 | + * @return string the feed cache filename |
|
| 686 | + * @since 1.4 |
|
| 687 | + * @access private |
|
| 688 | + */ |
|
| 689 | + public function _generateFilename() |
|
| 690 | + { |
|
| 691 | + $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 692 | + |
|
| 693 | + return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.xml'; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * @since 1.4 |
|
| 698 | + * @access private |
|
| 699 | + * @param $filename |
|
| 700 | + */ |
|
| 701 | + public function _redirect($filename) |
|
| 702 | + { |
|
| 703 | + // attention, heavily-commented-out-area |
|
| 704 | + |
|
| 705 | + // maybe use this in addition to file time checking |
|
| 706 | + //Header("Expires: ".date("r",time()+$this->_timeout)); |
|
| 707 | + |
|
| 708 | + /* no caching at all, doesn't seem to work as good: |
|
| 709 | 709 | Header("Cache-Control: no-cache"); |
| 710 | 710 | Header("Pragma: no-cache"); |
| 711 | 711 | */ |
| 712 | 712 | |
| 713 | - // HTTP redirect, some feed readers' simple HTTP implementations don't follow it |
|
| 714 | - //Header("Location: ".$filename); |
|
| 715 | - |
|
| 716 | - header('Content-Type: ' . $this->contentType . '; charset=' . $this->encoding . '; filename=' . basename($filename)); |
|
| 717 | - header('Content-Disposition: inline; filename=' . basename($filename)); |
|
| 718 | - readfile($filename, 'r'); |
|
| 719 | - die(); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Turns on caching and checks if there is a recent version of this feed in the cache. |
|
| 724 | - * If there is, an HTTP redirect header is sent. |
|
| 725 | - * To effectively use caching, you should create the FeedCreator object and call this method |
|
| 726 | - * before anything else, especially before you do the time consuming task to build the feed |
|
| 727 | - * (web fetching, for example). |
|
| 728 | - * @since 1.4 |
|
| 729 | - * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 730 | - * @param int $timeout |
|
| 731 | - * @internal param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
|
| 732 | - */ |
|
| 733 | - public function useCached($filename = '', $timeout = 3600) |
|
| 734 | - { |
|
| 735 | - $this->_timeout = $timeout; |
|
| 736 | - if ('' == $filename) { |
|
| 737 | - $filename = $this->_generateFilename(); |
|
| 738 | - } |
|
| 739 | - if (file_exists($filename) && (time() - filemtime($filename) < $timeout)) { |
|
| 740 | - $this->_redirect($filename); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * Saves this feed as a file on the local disk. After the file is saved, a redirect |
|
| 746 | - * header may be sent to redirect the user to the newly created file. |
|
| 747 | - * @since 1.4 |
|
| 748 | - * |
|
| 749 | - * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 750 | - * @param bool $displayContents |
|
| 751 | - * @internal param bool $redirect optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. |
|
| 752 | - */ |
|
| 753 | - public function saveFeed($filename = '', $displayContents = true) |
|
| 754 | - { |
|
| 755 | - if ('' == $filename) { |
|
| 756 | - $filename = $this->_generateFilename(); |
|
| 757 | - } |
|
| 758 | - $feedFile = fopen($filename, 'w+'); |
|
| 759 | - if ($feedFile) { |
|
| 760 | - fwrite($feedFile, $this->createFeed()); |
|
| 761 | - fclose($feedFile); |
|
| 762 | - if ($displayContents) { |
|
| 763 | - $this->_redirect($filename); |
|
| 764 | - } |
|
| 765 | - } else { |
|
| 766 | - echo '<br><b>Error creating feed file, please check write permissions.</b><br>'; |
|
| 767 | - } |
|
| 768 | - } |
|
| 713 | + // HTTP redirect, some feed readers' simple HTTP implementations don't follow it |
|
| 714 | + //Header("Location: ".$filename); |
|
| 715 | + |
|
| 716 | + header('Content-Type: ' . $this->contentType . '; charset=' . $this->encoding . '; filename=' . basename($filename)); |
|
| 717 | + header('Content-Disposition: inline; filename=' . basename($filename)); |
|
| 718 | + readfile($filename, 'r'); |
|
| 719 | + die(); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Turns on caching and checks if there is a recent version of this feed in the cache. |
|
| 724 | + * If there is, an HTTP redirect header is sent. |
|
| 725 | + * To effectively use caching, you should create the FeedCreator object and call this method |
|
| 726 | + * before anything else, especially before you do the time consuming task to build the feed |
|
| 727 | + * (web fetching, for example). |
|
| 728 | + * @since 1.4 |
|
| 729 | + * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 730 | + * @param int $timeout |
|
| 731 | + * @internal param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
|
| 732 | + */ |
|
| 733 | + public function useCached($filename = '', $timeout = 3600) |
|
| 734 | + { |
|
| 735 | + $this->_timeout = $timeout; |
|
| 736 | + if ('' == $filename) { |
|
| 737 | + $filename = $this->_generateFilename(); |
|
| 738 | + } |
|
| 739 | + if (file_exists($filename) && (time() - filemtime($filename) < $timeout)) { |
|
| 740 | + $this->_redirect($filename); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * Saves this feed as a file on the local disk. After the file is saved, a redirect |
|
| 746 | + * header may be sent to redirect the user to the newly created file. |
|
| 747 | + * @since 1.4 |
|
| 748 | + * |
|
| 749 | + * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). |
|
| 750 | + * @param bool $displayContents |
|
| 751 | + * @internal param bool $redirect optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. |
|
| 752 | + */ |
|
| 753 | + public function saveFeed($filename = '', $displayContents = true) |
|
| 754 | + { |
|
| 755 | + if ('' == $filename) { |
|
| 756 | + $filename = $this->_generateFilename(); |
|
| 757 | + } |
|
| 758 | + $feedFile = fopen($filename, 'w+'); |
|
| 759 | + if ($feedFile) { |
|
| 760 | + fwrite($feedFile, $this->createFeed()); |
|
| 761 | + fclose($feedFile); |
|
| 762 | + if ($displayContents) { |
|
| 763 | + $this->_redirect($filename); |
|
| 764 | + } |
|
| 765 | + } else { |
|
| 766 | + echo '<br><b>Error creating feed file, please check write permissions.</b><br>'; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -774,123 +774,123 @@ discard block |
||
| 774 | 774 | */ |
| 775 | 775 | class FeedDate |
| 776 | 776 | { |
| 777 | - public $unix; |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Creates a new instance of FeedDate representing a given date. |
|
| 781 | - * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps. |
|
| 782 | - * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used. |
|
| 783 | - */ |
|
| 784 | - public function __construct($dateString = '') |
|
| 785 | - { |
|
| 786 | - $tzOffset = 0; |
|
| 787 | - if ('' == $dateString) { |
|
| 788 | - $dateString = date('r'); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - //if (is_integer($dateString)) { |
|
| 792 | - if (is_numeric($dateString)) { |
|
| 793 | - $this->unix = $dateString; |
|
| 794 | - |
|
| 795 | - return; |
|
| 796 | - } |
|
| 797 | - if (preg_match("~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~", $dateString, $matches)) { |
|
| 798 | - $months = [ |
|
| 799 | - 'Jan' => 1, |
|
| 800 | - 'Feb' => 2, |
|
| 801 | - 'Mar' => 3, |
|
| 802 | - 'Apr' => 4, |
|
| 803 | - 'May' => 5, |
|
| 804 | - 'Jun' => 6, |
|
| 805 | - 'Jul' => 7, |
|
| 806 | - 'Aug' => 8, |
|
| 807 | - 'Sep' => 9, |
|
| 808 | - 'Oct' => 10, |
|
| 809 | - 'Nov' => 11, |
|
| 810 | - 'Dec' => 12 |
|
| 811 | - ]; |
|
| 812 | - $this->unix = mktime($matches[4], $matches[5], $matches[6], $months[$matches[2]], $matches[1], $matches[3]); |
|
| 813 | - if ('+' == substr($matches[7], 0, 1) || '-' == substr($matches[7], 0, 1)) { |
|
| 814 | - $tzOffset = (substr($matches[7], 0, 3) * 60 + substr($matches[7], -2)) * 60; |
|
| 815 | - } else { |
|
| 816 | - if (1 == strlen($matches[7])) { |
|
| 817 | - $oneHour = 3600; |
|
| 818 | - $ord = ord($matches[7]); |
|
| 819 | - if ($ord < ord('M')) { |
|
| 820 | - $tzOffset = (ord('A') - $ord - 1) * $oneHour; |
|
| 821 | - } elseif ($ord >= ord('M') && 'Z' !== $matches[7]) { |
|
| 822 | - $tzOffset = ($ord - ord('M')) * $oneHour; |
|
| 823 | - } elseif ('Z' === $matches[7]) { |
|
| 824 | - $tzOffset = 0; |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - switch ($matches[7]) { |
|
| 828 | - case 'UT': |
|
| 829 | - case 'GMT': |
|
| 830 | - $tzOffset = 0; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - $this->unix += $tzOffset; |
|
| 834 | - |
|
| 835 | - return; |
|
| 836 | - } |
|
| 837 | - if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~", $dateString, $matches)) { |
|
| 838 | - $this->unix = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
|
| 839 | - if ('+' == substr($matches[7], 0, 1) || '-' == substr($matches[7], 0, 1)) { |
|
| 840 | - $tzOffset = (substr($matches[7], 0, 3) * 60 + substr($matches[7], -2)) * 60; |
|
| 841 | - } else { |
|
| 842 | - if ('Z' === $matches[7]) { |
|
| 843 | - $tzOffset = 0; |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - $this->unix += $tzOffset; |
|
| 847 | - |
|
| 848 | - return; |
|
| 849 | - } |
|
| 850 | - $this->unix = 0; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Gets the date stored in this FeedDate as an RFC 822 date. |
|
| 855 | - * |
|
| 856 | - * @return a date in RFC 822 format |
|
| 857 | - */ |
|
| 858 | - public function rfc822() |
|
| 859 | - { |
|
| 860 | - //return gmdate("r",$this->unix); |
|
| 861 | - $date = gmdate('D, d M Y H:i:s', $this->unix); |
|
| 862 | - if (TIME_ZONE != '') { |
|
| 863 | - $date .= ' ' . str_replace(':', '', TIME_ZONE); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - return $date; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * Gets the date stored in this FeedDate as an ISO 8601 date. |
|
| 871 | - * |
|
| 872 | - * @return a date in ISO 8601 format |
|
| 873 | - */ |
|
| 874 | - public function iso8601() |
|
| 875 | - { |
|
| 876 | - $date = gmdate("Y-m-d\TH:i:sO", $this->unix); |
|
| 877 | - $date = substr($date, 0, 22) . ':' . substr($date, -2); |
|
| 878 | - if (TIME_ZONE != '') { |
|
| 879 | - $date = str_replace('+00:00', TIME_ZONE, $date); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - return $date; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * Gets the date stored in this FeedDate as unix time stamp. |
|
| 887 | - * |
|
| 888 | - * @return a date as a unix time stamp |
|
| 889 | - */ |
|
| 890 | - public function unix() |
|
| 891 | - { |
|
| 892 | - return $this->unix; |
|
| 893 | - } |
|
| 777 | + public $unix; |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Creates a new instance of FeedDate representing a given date. |
|
| 781 | + * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps. |
|
| 782 | + * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used. |
|
| 783 | + */ |
|
| 784 | + public function __construct($dateString = '') |
|
| 785 | + { |
|
| 786 | + $tzOffset = 0; |
|
| 787 | + if ('' == $dateString) { |
|
| 788 | + $dateString = date('r'); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + //if (is_integer($dateString)) { |
|
| 792 | + if (is_numeric($dateString)) { |
|
| 793 | + $this->unix = $dateString; |
|
| 794 | + |
|
| 795 | + return; |
|
| 796 | + } |
|
| 797 | + if (preg_match("~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~", $dateString, $matches)) { |
|
| 798 | + $months = [ |
|
| 799 | + 'Jan' => 1, |
|
| 800 | + 'Feb' => 2, |
|
| 801 | + 'Mar' => 3, |
|
| 802 | + 'Apr' => 4, |
|
| 803 | + 'May' => 5, |
|
| 804 | + 'Jun' => 6, |
|
| 805 | + 'Jul' => 7, |
|
| 806 | + 'Aug' => 8, |
|
| 807 | + 'Sep' => 9, |
|
| 808 | + 'Oct' => 10, |
|
| 809 | + 'Nov' => 11, |
|
| 810 | + 'Dec' => 12 |
|
| 811 | + ]; |
|
| 812 | + $this->unix = mktime($matches[4], $matches[5], $matches[6], $months[$matches[2]], $matches[1], $matches[3]); |
|
| 813 | + if ('+' == substr($matches[7], 0, 1) || '-' == substr($matches[7], 0, 1)) { |
|
| 814 | + $tzOffset = (substr($matches[7], 0, 3) * 60 + substr($matches[7], -2)) * 60; |
|
| 815 | + } else { |
|
| 816 | + if (1 == strlen($matches[7])) { |
|
| 817 | + $oneHour = 3600; |
|
| 818 | + $ord = ord($matches[7]); |
|
| 819 | + if ($ord < ord('M')) { |
|
| 820 | + $tzOffset = (ord('A') - $ord - 1) * $oneHour; |
|
| 821 | + } elseif ($ord >= ord('M') && 'Z' !== $matches[7]) { |
|
| 822 | + $tzOffset = ($ord - ord('M')) * $oneHour; |
|
| 823 | + } elseif ('Z' === $matches[7]) { |
|
| 824 | + $tzOffset = 0; |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + switch ($matches[7]) { |
|
| 828 | + case 'UT': |
|
| 829 | + case 'GMT': |
|
| 830 | + $tzOffset = 0; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + $this->unix += $tzOffset; |
|
| 834 | + |
|
| 835 | + return; |
|
| 836 | + } |
|
| 837 | + if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~", $dateString, $matches)) { |
|
| 838 | + $this->unix = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
|
| 839 | + if ('+' == substr($matches[7], 0, 1) || '-' == substr($matches[7], 0, 1)) { |
|
| 840 | + $tzOffset = (substr($matches[7], 0, 3) * 60 + substr($matches[7], -2)) * 60; |
|
| 841 | + } else { |
|
| 842 | + if ('Z' === $matches[7]) { |
|
| 843 | + $tzOffset = 0; |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + $this->unix += $tzOffset; |
|
| 847 | + |
|
| 848 | + return; |
|
| 849 | + } |
|
| 850 | + $this->unix = 0; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Gets the date stored in this FeedDate as an RFC 822 date. |
|
| 855 | + * |
|
| 856 | + * @return a date in RFC 822 format |
|
| 857 | + */ |
|
| 858 | + public function rfc822() |
|
| 859 | + { |
|
| 860 | + //return gmdate("r",$this->unix); |
|
| 861 | + $date = gmdate('D, d M Y H:i:s', $this->unix); |
|
| 862 | + if (TIME_ZONE != '') { |
|
| 863 | + $date .= ' ' . str_replace(':', '', TIME_ZONE); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + return $date; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * Gets the date stored in this FeedDate as an ISO 8601 date. |
|
| 871 | + * |
|
| 872 | + * @return a date in ISO 8601 format |
|
| 873 | + */ |
|
| 874 | + public function iso8601() |
|
| 875 | + { |
|
| 876 | + $date = gmdate("Y-m-d\TH:i:sO", $this->unix); |
|
| 877 | + $date = substr($date, 0, 22) . ':' . substr($date, -2); |
|
| 878 | + if (TIME_ZONE != '') { |
|
| 879 | + $date = str_replace('+00:00', TIME_ZONE, $date); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + return $date; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * Gets the date stored in this FeedDate as unix time stamp. |
|
| 887 | + * |
|
| 888 | + * @return a date as a unix time stamp |
|
| 889 | + */ |
|
| 890 | + public function unix() |
|
| 891 | + { |
|
| 892 | + return $this->unix; |
|
| 893 | + } |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | /** |
@@ -902,74 +902,74 @@ discard block |
||
| 902 | 902 | */ |
| 903 | 903 | class RSSCreator10 extends FeedCreator |
| 904 | 904 | { |
| 905 | - /** |
|
| 906 | - * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. |
|
| 907 | - * The feed will contain all items previously added in the same order. |
|
| 908 | - * @return string the feed's complete text |
|
| 909 | - */ |
|
| 910 | - public function createFeed() |
|
| 911 | - { |
|
| 912 | - $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 913 | - $feed .= $this->_createGeneratorComment(); |
|
| 914 | - if ('' == $this->cssStyleSheet) { |
|
| 915 | - $cssStyleSheet = 'http://www.w3.org/2000/08/w3c-synd/style.css'; |
|
| 916 | - } |
|
| 917 | - $feed .= $this->_createStylesheetReferences(); |
|
| 918 | - $feed .= "<rdf:RDF\n"; |
|
| 919 | - $feed .= " xmlns=\"http://purl.org/rss/1.0/\"\n"; |
|
| 920 | - $feed .= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; |
|
| 921 | - $feed .= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n"; |
|
| 922 | - $feed .= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; |
|
| 923 | - $feed .= ' <channel rdf:about="' . $this->syndicationURL . "\">\n"; |
|
| 924 | - $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 925 | - $feed .= ' <description>' . htmlspecialchars($this->description, ENT_QUOTES | ENT_HTML5) . "</description>\n"; |
|
| 926 | - $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 927 | - if (null != $this->image) { |
|
| 928 | - $feed .= ' <image rdf:resource="' . $this->image->url . "\">\n"; |
|
| 929 | - } |
|
| 930 | - $now = new FeedDate(); |
|
| 931 | - $feed .= ' <dc:date>' . htmlspecialchars($now->iso8601(), ENT_QUOTES | ENT_HTML5) . "</dc:date>\n"; |
|
| 932 | - $feed .= " <items>\n"; |
|
| 933 | - $feed .= " <rdf:Seq>\n"; |
|
| 934 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 935 | - $feed .= ' <rdf:li rdf:resource="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 936 | - } |
|
| 937 | - $feed .= " </rdf:Seq>\n"; |
|
| 938 | - $feed .= " </items>\n"; |
|
| 939 | - $feed .= " </channel>\n"; |
|
| 940 | - if (null != $this->image) { |
|
| 941 | - $feed .= ' <image rdf:about="' . $this->image->url . "\">\n"; |
|
| 942 | - $feed .= ' <title>' . $this->image->title . "</title>\n"; |
|
| 943 | - $feed .= ' <link>' . $this->image->link . "</link>\n"; |
|
| 944 | - $feed .= ' <url>' . $this->image->url . "</url>\n"; |
|
| 945 | - $feed .= " </image>\n"; |
|
| 946 | - } |
|
| 947 | - $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 948 | - |
|
| 949 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 950 | - $feed .= ' <item rdf:about="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 951 | - //$feed.= " <dc:type>Posting</dc:type>\n"; |
|
| 952 | - $feed .= " <dc:format>text/html</dc:format>\n"; |
|
| 953 | - if (null != $this->items[$i]->date) { |
|
| 954 | - $itemDate = new FeedDate($this->items[$i]->date); |
|
| 955 | - $feed .= ' <dc:date>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</dc:date>\n"; |
|
| 956 | - } |
|
| 957 | - if ('' != $this->items[$i]->source) { |
|
| 958 | - $feed .= ' <dc:source>' . htmlspecialchars($this->items[$i]->source, ENT_QUOTES | ENT_HTML5) . "</dc:source>\n"; |
|
| 959 | - } |
|
| 960 | - if ('' != $this->items[$i]->author) { |
|
| 961 | - $feed .= ' <dc:creator>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</dc:creator>\n"; |
|
| 962 | - } |
|
| 963 | - $feed .= ' <title>' . htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", ' ')), ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 964 | - $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 965 | - $feed .= ' <description>' . htmlspecialchars($this->items[$i]->description, ENT_QUOTES | ENT_HTML5) . "</description>\n"; |
|
| 966 | - $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 967 | - $feed .= " </item>\n"; |
|
| 968 | - } |
|
| 969 | - $feed .= "</rdf:RDF>\n"; |
|
| 970 | - |
|
| 971 | - return $feed; |
|
| 972 | - } |
|
| 905 | + /** |
|
| 906 | + * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. |
|
| 907 | + * The feed will contain all items previously added in the same order. |
|
| 908 | + * @return string the feed's complete text |
|
| 909 | + */ |
|
| 910 | + public function createFeed() |
|
| 911 | + { |
|
| 912 | + $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 913 | + $feed .= $this->_createGeneratorComment(); |
|
| 914 | + if ('' == $this->cssStyleSheet) { |
|
| 915 | + $cssStyleSheet = 'http://www.w3.org/2000/08/w3c-synd/style.css'; |
|
| 916 | + } |
|
| 917 | + $feed .= $this->_createStylesheetReferences(); |
|
| 918 | + $feed .= "<rdf:RDF\n"; |
|
| 919 | + $feed .= " xmlns=\"http://purl.org/rss/1.0/\"\n"; |
|
| 920 | + $feed .= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; |
|
| 921 | + $feed .= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n"; |
|
| 922 | + $feed .= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; |
|
| 923 | + $feed .= ' <channel rdf:about="' . $this->syndicationURL . "\">\n"; |
|
| 924 | + $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 925 | + $feed .= ' <description>' . htmlspecialchars($this->description, ENT_QUOTES | ENT_HTML5) . "</description>\n"; |
|
| 926 | + $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 927 | + if (null != $this->image) { |
|
| 928 | + $feed .= ' <image rdf:resource="' . $this->image->url . "\">\n"; |
|
| 929 | + } |
|
| 930 | + $now = new FeedDate(); |
|
| 931 | + $feed .= ' <dc:date>' . htmlspecialchars($now->iso8601(), ENT_QUOTES | ENT_HTML5) . "</dc:date>\n"; |
|
| 932 | + $feed .= " <items>\n"; |
|
| 933 | + $feed .= " <rdf:Seq>\n"; |
|
| 934 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 935 | + $feed .= ' <rdf:li rdf:resource="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 936 | + } |
|
| 937 | + $feed .= " </rdf:Seq>\n"; |
|
| 938 | + $feed .= " </items>\n"; |
|
| 939 | + $feed .= " </channel>\n"; |
|
| 940 | + if (null != $this->image) { |
|
| 941 | + $feed .= ' <image rdf:about="' . $this->image->url . "\">\n"; |
|
| 942 | + $feed .= ' <title>' . $this->image->title . "</title>\n"; |
|
| 943 | + $feed .= ' <link>' . $this->image->link . "</link>\n"; |
|
| 944 | + $feed .= ' <url>' . $this->image->url . "</url>\n"; |
|
| 945 | + $feed .= " </image>\n"; |
|
| 946 | + } |
|
| 947 | + $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 948 | + |
|
| 949 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 950 | + $feed .= ' <item rdf:about="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 951 | + //$feed.= " <dc:type>Posting</dc:type>\n"; |
|
| 952 | + $feed .= " <dc:format>text/html</dc:format>\n"; |
|
| 953 | + if (null != $this->items[$i]->date) { |
|
| 954 | + $itemDate = new FeedDate($this->items[$i]->date); |
|
| 955 | + $feed .= ' <dc:date>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</dc:date>\n"; |
|
| 956 | + } |
|
| 957 | + if ('' != $this->items[$i]->source) { |
|
| 958 | + $feed .= ' <dc:source>' . htmlspecialchars($this->items[$i]->source, ENT_QUOTES | ENT_HTML5) . "</dc:source>\n"; |
|
| 959 | + } |
|
| 960 | + if ('' != $this->items[$i]->author) { |
|
| 961 | + $feed .= ' <dc:creator>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</dc:creator>\n"; |
|
| 962 | + } |
|
| 963 | + $feed .= ' <title>' . htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", ' ')), ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 964 | + $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 965 | + $feed .= ' <description>' . htmlspecialchars($this->items[$i]->description, ENT_QUOTES | ENT_HTML5) . "</description>\n"; |
|
| 966 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 967 | + $feed .= " </item>\n"; |
|
| 968 | + } |
|
| 969 | + $feed .= "</rdf:RDF>\n"; |
|
| 970 | + |
|
| 971 | + return $feed; |
|
| 972 | + } |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
@@ -981,139 +981,139 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | class RSSCreator091 extends FeedCreator |
| 983 | 983 | { |
| 984 | - /** |
|
| 985 | - * Stores this RSS feed's version number. |
|
| 986 | - * @access private |
|
| 987 | - */ |
|
| 988 | - public $RSSVersion; |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * RSSCreator091 constructor. |
|
| 992 | - */ |
|
| 993 | - public function __construct() |
|
| 994 | - { |
|
| 995 | - $this->_setRSSVersion('0.91'); |
|
| 996 | - $this->contentType = 'application/rss+xml'; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * Sets this RSS feed's version number. |
|
| 1001 | - * @access private |
|
| 1002 | - * @param $version |
|
| 1003 | - */ |
|
| 1004 | - public function _setRSSVersion($version) |
|
| 1005 | - { |
|
| 1006 | - $this->RSSVersion = $version; |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - /** |
|
| 1010 | - * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. |
|
| 1011 | - * The feed will contain all items previously added in the same order. |
|
| 1012 | - * @return string the feed's complete text |
|
| 1013 | - */ |
|
| 1014 | - public function createFeed() |
|
| 1015 | - { |
|
| 1016 | - $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1017 | - $feed .= $this->_createGeneratorComment(); |
|
| 1018 | - $feed .= $this->_createStylesheetReferences(); |
|
| 1019 | - $feed .= '<rss version="' . $this->RSSVersion . "\">\n"; |
|
| 1020 | - $feed .= " <channel>\n"; |
|
| 1021 | - $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1022 | - $this->descriptionTruncSize = 500; |
|
| 1023 | - $feed .= ' <description>' . $this->getDescription() . "</description>\n"; |
|
| 1024 | - $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 1025 | - $now = new FeedDate(); |
|
| 1026 | - $feed .= ' <lastBuildDate>' . htmlspecialchars($now->rfc822(), ENT_QUOTES | ENT_HTML5) . "</lastBuildDate>\n"; |
|
| 1027 | - $feed .= ' <generator>' . FEEDCREATOR_VERSION . "</generator>\n"; |
|
| 1028 | - |
|
| 1029 | - if (null != $this->image) { |
|
| 1030 | - $feed .= " <image>\n"; |
|
| 1031 | - $feed .= ' <url>' . $this->image->url . "</url>\n"; |
|
| 1032 | - $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->image->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1033 | - $feed .= ' <link>' . $this->image->link . "</link>\n"; |
|
| 1034 | - if ('' != $this->image->width) { |
|
| 1035 | - $feed .= ' <width>' . $this->image->width . "</width>\n"; |
|
| 1036 | - } |
|
| 1037 | - if ('' != $this->image->height) { |
|
| 1038 | - $feed .= ' <height>' . $this->image->height . "</height>\n"; |
|
| 1039 | - } |
|
| 1040 | - if ('' != $this->image->description) { |
|
| 1041 | - $feed .= ' <description>' . $this->image->getDescription() . "</description>\n"; |
|
| 1042 | - } |
|
| 1043 | - $feed .= " </image>\n"; |
|
| 1044 | - } |
|
| 1045 | - if ('' != $this->language) { |
|
| 1046 | - $feed .= ' <language>' . $this->language . "</language>\n"; |
|
| 1047 | - } |
|
| 1048 | - if ('' != $this->copyright) { |
|
| 1049 | - $feed .= ' <copyright>' . FeedCreator::iTrunc(htmlspecialchars($this->copyright, ENT_QUOTES | ENT_HTML5), 100) . "</copyright>\n"; |
|
| 1050 | - } |
|
| 1051 | - if ('' != $this->editor) { |
|
| 1052 | - $feed .= ' <managingEditor>' . FeedCreator::iTrunc(htmlspecialchars($this->editor, ENT_QUOTES | ENT_HTML5), 100) . "</managingEditor>\n"; |
|
| 1053 | - } |
|
| 1054 | - if ('' != $this->webmaster) { |
|
| 1055 | - $feed .= ' <webMaster>' . FeedCreator::iTrunc(htmlspecialchars($this->webmaster, ENT_QUOTES | ENT_HTML5), 100) . "</webMaster>\n"; |
|
| 1056 | - } |
|
| 1057 | - if ('' != $this->pubDate) { |
|
| 1058 | - $pubDate = new FeedDate($this->pubDate); |
|
| 1059 | - $feed .= ' <pubDate>' . htmlspecialchars($pubDate->rfc822(), ENT_QUOTES | ENT_HTML5) . "</pubDate>\n"; |
|
| 1060 | - } |
|
| 1061 | - if ('' != $this->category) { |
|
| 1062 | - $feed .= ' <category>' . htmlspecialchars($this->category, ENT_QUOTES | ENT_HTML5) . "</category>\n"; |
|
| 1063 | - } |
|
| 1064 | - if ('' != $this->docs) { |
|
| 1065 | - $feed .= ' <docs>' . FeedCreator::iTrunc(htmlspecialchars($this->docs, ENT_QUOTES | ENT_HTML5), 500) . "</docs>\n"; |
|
| 1066 | - } |
|
| 1067 | - if ('' != $this->ttl) { |
|
| 1068 | - $feed .= ' <ttl>' . htmlspecialchars($this->ttl, ENT_QUOTES | ENT_HTML5) . "</ttl>\n"; |
|
| 1069 | - } |
|
| 1070 | - if ('' != $this->rating) { |
|
| 1071 | - $feed .= ' <rating>' . FeedCreator::iTrunc(htmlspecialchars($this->rating, ENT_QUOTES | ENT_HTML5), 500) . "</rating>\n"; |
|
| 1072 | - } |
|
| 1073 | - if ('' != $this->skipHours) { |
|
| 1074 | - $feed .= ' <skipHours>' . htmlspecialchars($this->skipHours, ENT_QUOTES | ENT_HTML5) . "</skipHours>\n"; |
|
| 1075 | - } |
|
| 1076 | - if ('' != $this->skipDays) { |
|
| 1077 | - $feed .= ' <skipDays>' . htmlspecialchars($this->skipDays, ENT_QUOTES | ENT_HTML5) . "</skipDays>\n"; |
|
| 1078 | - } |
|
| 1079 | - $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 1080 | - |
|
| 1081 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1082 | - $feed .= " <item>\n"; |
|
| 1083 | - $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1084 | - $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 1085 | - $feed .= ' <description>' . $this->items[$i]->getDescription() . "</description>\n"; |
|
| 1086 | - |
|
| 1087 | - if ('' != $this->items[$i]->author) { |
|
| 1088 | - $feed .= ' <author>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</author>\n"; |
|
| 1089 | - } |
|
| 1090 | - /* |
|
| 984 | + /** |
|
| 985 | + * Stores this RSS feed's version number. |
|
| 986 | + * @access private |
|
| 987 | + */ |
|
| 988 | + public $RSSVersion; |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * RSSCreator091 constructor. |
|
| 992 | + */ |
|
| 993 | + public function __construct() |
|
| 994 | + { |
|
| 995 | + $this->_setRSSVersion('0.91'); |
|
| 996 | + $this->contentType = 'application/rss+xml'; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * Sets this RSS feed's version number. |
|
| 1001 | + * @access private |
|
| 1002 | + * @param $version |
|
| 1003 | + */ |
|
| 1004 | + public function _setRSSVersion($version) |
|
| 1005 | + { |
|
| 1006 | + $this->RSSVersion = $version; |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + /** |
|
| 1010 | + * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. |
|
| 1011 | + * The feed will contain all items previously added in the same order. |
|
| 1012 | + * @return string the feed's complete text |
|
| 1013 | + */ |
|
| 1014 | + public function createFeed() |
|
| 1015 | + { |
|
| 1016 | + $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1017 | + $feed .= $this->_createGeneratorComment(); |
|
| 1018 | + $feed .= $this->_createStylesheetReferences(); |
|
| 1019 | + $feed .= '<rss version="' . $this->RSSVersion . "\">\n"; |
|
| 1020 | + $feed .= " <channel>\n"; |
|
| 1021 | + $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1022 | + $this->descriptionTruncSize = 500; |
|
| 1023 | + $feed .= ' <description>' . $this->getDescription() . "</description>\n"; |
|
| 1024 | + $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 1025 | + $now = new FeedDate(); |
|
| 1026 | + $feed .= ' <lastBuildDate>' . htmlspecialchars($now->rfc822(), ENT_QUOTES | ENT_HTML5) . "</lastBuildDate>\n"; |
|
| 1027 | + $feed .= ' <generator>' . FEEDCREATOR_VERSION . "</generator>\n"; |
|
| 1028 | + |
|
| 1029 | + if (null != $this->image) { |
|
| 1030 | + $feed .= " <image>\n"; |
|
| 1031 | + $feed .= ' <url>' . $this->image->url . "</url>\n"; |
|
| 1032 | + $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->image->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1033 | + $feed .= ' <link>' . $this->image->link . "</link>\n"; |
|
| 1034 | + if ('' != $this->image->width) { |
|
| 1035 | + $feed .= ' <width>' . $this->image->width . "</width>\n"; |
|
| 1036 | + } |
|
| 1037 | + if ('' != $this->image->height) { |
|
| 1038 | + $feed .= ' <height>' . $this->image->height . "</height>\n"; |
|
| 1039 | + } |
|
| 1040 | + if ('' != $this->image->description) { |
|
| 1041 | + $feed .= ' <description>' . $this->image->getDescription() . "</description>\n"; |
|
| 1042 | + } |
|
| 1043 | + $feed .= " </image>\n"; |
|
| 1044 | + } |
|
| 1045 | + if ('' != $this->language) { |
|
| 1046 | + $feed .= ' <language>' . $this->language . "</language>\n"; |
|
| 1047 | + } |
|
| 1048 | + if ('' != $this->copyright) { |
|
| 1049 | + $feed .= ' <copyright>' . FeedCreator::iTrunc(htmlspecialchars($this->copyright, ENT_QUOTES | ENT_HTML5), 100) . "</copyright>\n"; |
|
| 1050 | + } |
|
| 1051 | + if ('' != $this->editor) { |
|
| 1052 | + $feed .= ' <managingEditor>' . FeedCreator::iTrunc(htmlspecialchars($this->editor, ENT_QUOTES | ENT_HTML5), 100) . "</managingEditor>\n"; |
|
| 1053 | + } |
|
| 1054 | + if ('' != $this->webmaster) { |
|
| 1055 | + $feed .= ' <webMaster>' . FeedCreator::iTrunc(htmlspecialchars($this->webmaster, ENT_QUOTES | ENT_HTML5), 100) . "</webMaster>\n"; |
|
| 1056 | + } |
|
| 1057 | + if ('' != $this->pubDate) { |
|
| 1058 | + $pubDate = new FeedDate($this->pubDate); |
|
| 1059 | + $feed .= ' <pubDate>' . htmlspecialchars($pubDate->rfc822(), ENT_QUOTES | ENT_HTML5) . "</pubDate>\n"; |
|
| 1060 | + } |
|
| 1061 | + if ('' != $this->category) { |
|
| 1062 | + $feed .= ' <category>' . htmlspecialchars($this->category, ENT_QUOTES | ENT_HTML5) . "</category>\n"; |
|
| 1063 | + } |
|
| 1064 | + if ('' != $this->docs) { |
|
| 1065 | + $feed .= ' <docs>' . FeedCreator::iTrunc(htmlspecialchars($this->docs, ENT_QUOTES | ENT_HTML5), 500) . "</docs>\n"; |
|
| 1066 | + } |
|
| 1067 | + if ('' != $this->ttl) { |
|
| 1068 | + $feed .= ' <ttl>' . htmlspecialchars($this->ttl, ENT_QUOTES | ENT_HTML5) . "</ttl>\n"; |
|
| 1069 | + } |
|
| 1070 | + if ('' != $this->rating) { |
|
| 1071 | + $feed .= ' <rating>' . FeedCreator::iTrunc(htmlspecialchars($this->rating, ENT_QUOTES | ENT_HTML5), 500) . "</rating>\n"; |
|
| 1072 | + } |
|
| 1073 | + if ('' != $this->skipHours) { |
|
| 1074 | + $feed .= ' <skipHours>' . htmlspecialchars($this->skipHours, ENT_QUOTES | ENT_HTML5) . "</skipHours>\n"; |
|
| 1075 | + } |
|
| 1076 | + if ('' != $this->skipDays) { |
|
| 1077 | + $feed .= ' <skipDays>' . htmlspecialchars($this->skipDays, ENT_QUOTES | ENT_HTML5) . "</skipDays>\n"; |
|
| 1078 | + } |
|
| 1079 | + $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 1080 | + |
|
| 1081 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1082 | + $feed .= " <item>\n"; |
|
| 1083 | + $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1084 | + $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 1085 | + $feed .= ' <description>' . $this->items[$i]->getDescription() . "</description>\n"; |
|
| 1086 | + |
|
| 1087 | + if ('' != $this->items[$i]->author) { |
|
| 1088 | + $feed .= ' <author>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</author>\n"; |
|
| 1089 | + } |
|
| 1090 | + /* |
|
| 1091 | 1091 | // on hold |
| 1092 | 1092 | if ($this->items[$i]->source!="") { |
| 1093 | 1093 | $feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n"; |
| 1094 | 1094 | } |
| 1095 | 1095 | */ |
| 1096 | - if ('' != $this->items[$i]->category) { |
|
| 1097 | - $feed .= ' <category>' . htmlspecialchars($this->items[$i]->category, ENT_QUOTES | ENT_HTML5) . "</category>\n"; |
|
| 1098 | - } |
|
| 1099 | - if ('' != $this->items[$i]->comments) { |
|
| 1100 | - $feed .= ' <comments>' . htmlspecialchars($this->items[$i]->comments, ENT_QUOTES | ENT_HTML5) . "</comments>\n"; |
|
| 1101 | - } |
|
| 1102 | - if ('' != $this->items[$i]->date) { |
|
| 1103 | - $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1104 | - $feed .= ' <pubDate>' . htmlspecialchars($itemDate->rfc822(), ENT_QUOTES | ENT_HTML5) . "</pubDate>\n"; |
|
| 1105 | - } |
|
| 1106 | - if ('' != $this->items[$i]->guid) { |
|
| 1107 | - $feed .= ' <guid>' . htmlspecialchars($this->items[$i]->guid, ENT_QUOTES | ENT_HTML5) . "</guid>\n"; |
|
| 1108 | - } |
|
| 1109 | - $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 1110 | - $feed .= " </item>\n"; |
|
| 1111 | - } |
|
| 1112 | - $feed .= " </channel>\n"; |
|
| 1113 | - $feed .= "</rss>\n"; |
|
| 1114 | - |
|
| 1115 | - return $feed; |
|
| 1116 | - } |
|
| 1096 | + if ('' != $this->items[$i]->category) { |
|
| 1097 | + $feed .= ' <category>' . htmlspecialchars($this->items[$i]->category, ENT_QUOTES | ENT_HTML5) . "</category>\n"; |
|
| 1098 | + } |
|
| 1099 | + if ('' != $this->items[$i]->comments) { |
|
| 1100 | + $feed .= ' <comments>' . htmlspecialchars($this->items[$i]->comments, ENT_QUOTES | ENT_HTML5) . "</comments>\n"; |
|
| 1101 | + } |
|
| 1102 | + if ('' != $this->items[$i]->date) { |
|
| 1103 | + $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1104 | + $feed .= ' <pubDate>' . htmlspecialchars($itemDate->rfc822(), ENT_QUOTES | ENT_HTML5) . "</pubDate>\n"; |
|
| 1105 | + } |
|
| 1106 | + if ('' != $this->items[$i]->guid) { |
|
| 1107 | + $feed .= ' <guid>' . htmlspecialchars($this->items[$i]->guid, ENT_QUOTES | ENT_HTML5) . "</guid>\n"; |
|
| 1108 | + } |
|
| 1109 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 1110 | + $feed .= " </item>\n"; |
|
| 1111 | + } |
|
| 1112 | + $feed .= " </channel>\n"; |
|
| 1113 | + $feed .= "</rss>\n"; |
|
| 1114 | + |
|
| 1115 | + return $feed; |
|
| 1116 | + } |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
@@ -1125,13 +1125,13 @@ discard block |
||
| 1125 | 1125 | */ |
| 1126 | 1126 | class RSSCreator20 extends RSSCreator091 |
| 1127 | 1127 | { |
| 1128 | - /** |
|
| 1129 | - * RSSCreator20 constructor. |
|
| 1130 | - */ |
|
| 1131 | - public function __construct() |
|
| 1132 | - { |
|
| 1133 | - parent::_setRSSVersion('2.0'); |
|
| 1134 | - } |
|
| 1128 | + /** |
|
| 1129 | + * RSSCreator20 constructor. |
|
| 1130 | + */ |
|
| 1131 | + public function __construct() |
|
| 1132 | + { |
|
| 1133 | + parent::_setRSSVersion('2.0'); |
|
| 1134 | + } |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1144,52 +1144,52 @@ discard block |
||
| 1144 | 1144 | */ |
| 1145 | 1145 | class PIECreator01 extends FeedCreator |
| 1146 | 1146 | { |
| 1147 | - /** |
|
| 1148 | - * PIECreator01 constructor. |
|
| 1149 | - */ |
|
| 1150 | - public function __construct() |
|
| 1151 | - { |
|
| 1152 | - $this->encoding = 'utf-8'; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * @return string |
|
| 1157 | - */ |
|
| 1158 | - public function createFeed() |
|
| 1159 | - { |
|
| 1160 | - $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1161 | - $feed .= $this->_createStylesheetReferences(); |
|
| 1162 | - $feed .= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; |
|
| 1163 | - $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1164 | - $this->truncSize = 500; |
|
| 1165 | - $feed .= ' <subtitle>' . $this->getDescription() . "</subtitle>\n"; |
|
| 1166 | - $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 1167 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1168 | - $feed .= " <entry>\n"; |
|
| 1169 | - $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1170 | - $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 1171 | - $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1172 | - $feed .= ' <created>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</created>\n"; |
|
| 1173 | - $feed .= ' <issued>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</issued>\n"; |
|
| 1174 | - $feed .= ' <modified>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1175 | - $feed .= ' <id>' . htmlspecialchars($this->items[$i]->guid, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1176 | - if ('' != $this->items[$i]->author) { |
|
| 1177 | - $feed .= " <author>\n"; |
|
| 1178 | - $feed .= ' <name>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</name>\n"; |
|
| 1179 | - if ('' != $this->items[$i]->authorEmail) { |
|
| 1180 | - $feed .= ' <email>' . $this->items[$i]->authorEmail . "</email>\n"; |
|
| 1181 | - } |
|
| 1182 | - $feed .= " </author>\n"; |
|
| 1183 | - } |
|
| 1184 | - $feed .= " <content type=\"text/html\" xml:lang=\"en-us\">\n"; |
|
| 1185 | - $feed .= ' <div xmlns="http://www.w3.org/1999/xhtml">' . $this->items[$i]->getDescription() . "</div>\n"; |
|
| 1186 | - $feed .= " </content>\n"; |
|
| 1187 | - $feed .= " </entry>\n"; |
|
| 1188 | - } |
|
| 1189 | - $feed .= "</feed>\n"; |
|
| 1190 | - |
|
| 1191 | - return $feed; |
|
| 1192 | - } |
|
| 1147 | + /** |
|
| 1148 | + * PIECreator01 constructor. |
|
| 1149 | + */ |
|
| 1150 | + public function __construct() |
|
| 1151 | + { |
|
| 1152 | + $this->encoding = 'utf-8'; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * @return string |
|
| 1157 | + */ |
|
| 1158 | + public function createFeed() |
|
| 1159 | + { |
|
| 1160 | + $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1161 | + $feed .= $this->_createStylesheetReferences(); |
|
| 1162 | + $feed .= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; |
|
| 1163 | + $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1164 | + $this->truncSize = 500; |
|
| 1165 | + $feed .= ' <subtitle>' . $this->getDescription() . "</subtitle>\n"; |
|
| 1166 | + $feed .= ' <link>' . $this->link . "</link>\n"; |
|
| 1167 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1168 | + $feed .= " <entry>\n"; |
|
| 1169 | + $feed .= ' <title>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . "</title>\n"; |
|
| 1170 | + $feed .= ' <link>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</link>\n"; |
|
| 1171 | + $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1172 | + $feed .= ' <created>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</created>\n"; |
|
| 1173 | + $feed .= ' <issued>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</issued>\n"; |
|
| 1174 | + $feed .= ' <modified>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1175 | + $feed .= ' <id>' . htmlspecialchars($this->items[$i]->guid, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1176 | + if ('' != $this->items[$i]->author) { |
|
| 1177 | + $feed .= " <author>\n"; |
|
| 1178 | + $feed .= ' <name>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</name>\n"; |
|
| 1179 | + if ('' != $this->items[$i]->authorEmail) { |
|
| 1180 | + $feed .= ' <email>' . $this->items[$i]->authorEmail . "</email>\n"; |
|
| 1181 | + } |
|
| 1182 | + $feed .= " </author>\n"; |
|
| 1183 | + } |
|
| 1184 | + $feed .= " <content type=\"text/html\" xml:lang=\"en-us\">\n"; |
|
| 1185 | + $feed .= ' <div xmlns="http://www.w3.org/1999/xhtml">' . $this->items[$i]->getDescription() . "</div>\n"; |
|
| 1186 | + $feed .= " </content>\n"; |
|
| 1187 | + $feed .= " </entry>\n"; |
|
| 1188 | + } |
|
| 1189 | + $feed .= "</feed>\n"; |
|
| 1190 | + |
|
| 1191 | + return $feed; |
|
| 1192 | + } |
|
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | /** |
@@ -1210,71 +1210,71 @@ discard block |
||
| 1210 | 1210 | */ |
| 1211 | 1211 | class AtomCreator03 extends FeedCreator |
| 1212 | 1212 | { |
| 1213 | - /** |
|
| 1214 | - * AtomCreator03 constructor. |
|
| 1215 | - */ |
|
| 1216 | - public function __construct() |
|
| 1217 | - { |
|
| 1218 | - $this->contentType = 'application/atom+xml'; |
|
| 1219 | - $this->encoding = 'utf-8'; |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * @return string |
|
| 1224 | - */ |
|
| 1225 | - public function createFeed() |
|
| 1226 | - { |
|
| 1227 | - $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1228 | - $feed .= $this->_createGeneratorComment(); |
|
| 1229 | - $feed .= $this->_createStylesheetReferences(); |
|
| 1230 | - $feed .= '<feed version="0.3" xmlns="http://purl.org/atom/ns#"'; |
|
| 1231 | - if ('' != $this->language) { |
|
| 1232 | - $feed .= ' xml:lang="' . $this->language . '"'; |
|
| 1233 | - } |
|
| 1234 | - $feed .= ">\n"; |
|
| 1235 | - $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1236 | - $feed .= ' <tagline>' . htmlspecialchars($this->description, ENT_QUOTES | ENT_HTML5) . "</tagline>\n"; |
|
| 1237 | - $feed .= ' <link rel="alternate" type="text/html" href="' . htmlspecialchars($this->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 1238 | - $feed .= ' <id>' . htmlspecialchars($this->link, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1239 | - $now = new FeedDate(); |
|
| 1240 | - $feed .= ' <modified>' . htmlspecialchars($now->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1241 | - if ('' != $this->editor) { |
|
| 1242 | - $feed .= " <author>\n"; |
|
| 1243 | - $feed .= ' <name>' . $this->editor . "</name>\n"; |
|
| 1244 | - if ('' != $this->editorEmail) { |
|
| 1245 | - $feed .= ' <email>' . $this->editorEmail . "</email>\n"; |
|
| 1246 | - } |
|
| 1247 | - $feed .= " </author>\n"; |
|
| 1248 | - } |
|
| 1249 | - $feed .= ' <generator>' . FEEDCREATOR_VERSION . "</generator>\n"; |
|
| 1250 | - $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 1251 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1252 | - $feed .= " <entry>\n"; |
|
| 1253 | - $feed .= ' <title>' . htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1254 | - $feed .= ' <link rel="alternate" type="text/html" href="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 1255 | - if ('' == $this->items[$i]->date) { |
|
| 1256 | - $this->items[$i]->date = time(); |
|
| 1257 | - } |
|
| 1258 | - $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1259 | - $feed .= ' <created>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</created>\n"; |
|
| 1260 | - $feed .= ' <issued>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</issued>\n"; |
|
| 1261 | - $feed .= ' <modified>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1262 | - $feed .= ' <id>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1263 | - $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 1264 | - if ('' != $this->items[$i]->author) { |
|
| 1265 | - $feed .= " <author>\n"; |
|
| 1266 | - $feed .= ' <name>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</name>\n"; |
|
| 1267 | - $feed .= " </author>\n"; |
|
| 1268 | - } |
|
| 1269 | - if ('' != $this->items[$i]->description) { |
|
| 1270 | - $feed .= ' <summary>' . htmlspecialchars($this->items[$i]->description, ENT_QUOTES | ENT_HTML5) . "</summary>\n"; |
|
| 1271 | - } |
|
| 1272 | - $feed .= " </entry>\n"; |
|
| 1273 | - } |
|
| 1274 | - $feed .= "</feed>\n"; |
|
| 1275 | - |
|
| 1276 | - return $feed; |
|
| 1277 | - } |
|
| 1213 | + /** |
|
| 1214 | + * AtomCreator03 constructor. |
|
| 1215 | + */ |
|
| 1216 | + public function __construct() |
|
| 1217 | + { |
|
| 1218 | + $this->contentType = 'application/atom+xml'; |
|
| 1219 | + $this->encoding = 'utf-8'; |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * @return string |
|
| 1224 | + */ |
|
| 1225 | + public function createFeed() |
|
| 1226 | + { |
|
| 1227 | + $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1228 | + $feed .= $this->_createGeneratorComment(); |
|
| 1229 | + $feed .= $this->_createStylesheetReferences(); |
|
| 1230 | + $feed .= '<feed version="0.3" xmlns="http://purl.org/atom/ns#"'; |
|
| 1231 | + if ('' != $this->language) { |
|
| 1232 | + $feed .= ' xml:lang="' . $this->language . '"'; |
|
| 1233 | + } |
|
| 1234 | + $feed .= ">\n"; |
|
| 1235 | + $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1236 | + $feed .= ' <tagline>' . htmlspecialchars($this->description, ENT_QUOTES | ENT_HTML5) . "</tagline>\n"; |
|
| 1237 | + $feed .= ' <link rel="alternate" type="text/html" href="' . htmlspecialchars($this->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 1238 | + $feed .= ' <id>' . htmlspecialchars($this->link, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1239 | + $now = new FeedDate(); |
|
| 1240 | + $feed .= ' <modified>' . htmlspecialchars($now->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1241 | + if ('' != $this->editor) { |
|
| 1242 | + $feed .= " <author>\n"; |
|
| 1243 | + $feed .= ' <name>' . $this->editor . "</name>\n"; |
|
| 1244 | + if ('' != $this->editorEmail) { |
|
| 1245 | + $feed .= ' <email>' . $this->editorEmail . "</email>\n"; |
|
| 1246 | + } |
|
| 1247 | + $feed .= " </author>\n"; |
|
| 1248 | + } |
|
| 1249 | + $feed .= ' <generator>' . FEEDCREATOR_VERSION . "</generator>\n"; |
|
| 1250 | + $feed .= $this->_createAdditionalElements($this->additionalElements, ' '); |
|
| 1251 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1252 | + $feed .= " <entry>\n"; |
|
| 1253 | + $feed .= ' <title>' . htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1254 | + $feed .= ' <link rel="alternate" type="text/html" href="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "\">\n"; |
|
| 1255 | + if ('' == $this->items[$i]->date) { |
|
| 1256 | + $this->items[$i]->date = time(); |
|
| 1257 | + } |
|
| 1258 | + $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1259 | + $feed .= ' <created>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</created>\n"; |
|
| 1260 | + $feed .= ' <issued>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</issued>\n"; |
|
| 1261 | + $feed .= ' <modified>' . htmlspecialchars($itemDate->iso8601(), ENT_QUOTES | ENT_HTML5) . "</modified>\n"; |
|
| 1262 | + $feed .= ' <id>' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . "</id>\n"; |
|
| 1263 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, ' '); |
|
| 1264 | + if ('' != $this->items[$i]->author) { |
|
| 1265 | + $feed .= " <author>\n"; |
|
| 1266 | + $feed .= ' <name>' . htmlspecialchars($this->items[$i]->author, ENT_QUOTES | ENT_HTML5) . "</name>\n"; |
|
| 1267 | + $feed .= " </author>\n"; |
|
| 1268 | + } |
|
| 1269 | + if ('' != $this->items[$i]->description) { |
|
| 1270 | + $feed .= ' <summary>' . htmlspecialchars($this->items[$i]->description, ENT_QUOTES | ENT_HTML5) . "</summary>\n"; |
|
| 1271 | + } |
|
| 1272 | + $feed .= " </entry>\n"; |
|
| 1273 | + } |
|
| 1274 | + $feed .= "</feed>\n"; |
|
| 1275 | + |
|
| 1276 | + return $feed; |
|
| 1277 | + } |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | /** |
@@ -1286,97 +1286,97 @@ discard block |
||
| 1286 | 1286 | */ |
| 1287 | 1287 | class MBOXCreator extends FeedCreator |
| 1288 | 1288 | { |
| 1289 | - /** |
|
| 1290 | - * MBOXCreator constructor. |
|
| 1291 | - */ |
|
| 1292 | - public function __construct() |
|
| 1293 | - { |
|
| 1294 | - $this->contentType = 'text/plain'; |
|
| 1295 | - $this->encoding = 'ISO-8859-15'; |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * @param string $input |
|
| 1300 | - * @param int $line_max |
|
| 1301 | - * @return string |
|
| 1302 | - */ |
|
| 1303 | - public function qp_enc($input = '', $line_max = 76) |
|
| 1304 | - { |
|
| 1305 | - $hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; |
|
| 1306 | - $lines = preg_split("/(?:\r\n|\r|\n)/", $input); |
|
| 1307 | - $eol = "\r\n"; |
|
| 1308 | - $escape = '='; |
|
| 1309 | - $output = ''; |
|
| 1310 | - // while (list(, $line) = each($lines)) { |
|
| 1311 | - foreach ($lines as $key => $line) { |
|
| 1312 | - //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary |
|
| 1313 | - $linlen = strlen($line); |
|
| 1314 | - $newline = ''; |
|
| 1315 | - for ($i = 0; $i < $linlen; ++$i) { |
|
| 1316 | - $c = substr($line, $i, 1); |
|
| 1317 | - $dec = ord($c); |
|
| 1318 | - if ((32 == $dec) && ($i == ($linlen - 1))) { // convert space at eol only |
|
| 1319 | - $c = '=20'; |
|
| 1320 | - } elseif ((61 == $dec) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required |
|
| 1321 | - $h2 = floor($dec / 16); |
|
| 1322 | - $h1 = floor($dec % 16); |
|
| 1323 | - $c = $escape . $hex[(string)$h2] . $hex[(string)$h1]; |
|
| 1324 | - } |
|
| 1325 | - if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted |
|
| 1326 | - $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay |
|
| 1327 | - $newline = ''; |
|
| 1328 | - } |
|
| 1329 | - $newline .= $c; |
|
| 1330 | - } // end of for |
|
| 1331 | - $output .= $newline . $eol; |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - return trim($output); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * Builds the MBOX contents. |
|
| 1339 | - * @return string the feed's complete text |
|
| 1340 | - */ |
|
| 1341 | - public function createFeed() |
|
| 1342 | - { |
|
| 1343 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1344 | - if ('' != $this->items[$i]->author) { |
|
| 1345 | - $from = $this->items[$i]->author; |
|
| 1346 | - } else { |
|
| 1347 | - $from = $this->title; |
|
| 1348 | - } |
|
| 1349 | - $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1350 | - $feed .= 'From ' . strtr(self::qp_enc($from), ' ', '_') . ' ' . date('D M d H:i:s Y', $itemDate->unix()) . "\n"; |
|
| 1351 | - $feed .= "Content-Type: text/plain;\n"; |
|
| 1352 | - $feed .= ' charset="' . $this->encoding . "\"\n"; |
|
| 1353 | - $feed .= "Content-Transfer-Encoding: quoted-printable\n"; |
|
| 1354 | - $feed .= "Content-Type: text/plain\n"; |
|
| 1355 | - $feed .= 'From: "' . self::qp_enc($from) . "\"\n"; |
|
| 1356 | - $feed .= 'Date: ' . $itemDate->rfc822() . "\n"; |
|
| 1357 | - $feed .= 'Subject: ' . self::qp_enc(FeedCreator::iTrunc($this->items[$i]->title, 100)) . "\n"; |
|
| 1358 | - $feed .= "\n"; |
|
| 1359 | - $body = chunk_split(self::qp_enc($this->items[$i]->description)); |
|
| 1360 | - $feed .= preg_replace("~\nFrom ([^\n]*)(\n?)~", "\n>From $1$2\n", $body); |
|
| 1361 | - $feed .= "\n"; |
|
| 1362 | - $feed .= "\n"; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - return $feed; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. |
|
| 1370 | - * @return string the feed cache filename |
|
| 1371 | - * @since 1.4 |
|
| 1372 | - * @access private |
|
| 1373 | - */ |
|
| 1374 | - public function _generateFilename() |
|
| 1375 | - { |
|
| 1376 | - $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1377 | - |
|
| 1378 | - return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.mbox'; |
|
| 1379 | - } |
|
| 1289 | + /** |
|
| 1290 | + * MBOXCreator constructor. |
|
| 1291 | + */ |
|
| 1292 | + public function __construct() |
|
| 1293 | + { |
|
| 1294 | + $this->contentType = 'text/plain'; |
|
| 1295 | + $this->encoding = 'ISO-8859-15'; |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * @param string $input |
|
| 1300 | + * @param int $line_max |
|
| 1301 | + * @return string |
|
| 1302 | + */ |
|
| 1303 | + public function qp_enc($input = '', $line_max = 76) |
|
| 1304 | + { |
|
| 1305 | + $hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; |
|
| 1306 | + $lines = preg_split("/(?:\r\n|\r|\n)/", $input); |
|
| 1307 | + $eol = "\r\n"; |
|
| 1308 | + $escape = '='; |
|
| 1309 | + $output = ''; |
|
| 1310 | + // while (list(, $line) = each($lines)) { |
|
| 1311 | + foreach ($lines as $key => $line) { |
|
| 1312 | + //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary |
|
| 1313 | + $linlen = strlen($line); |
|
| 1314 | + $newline = ''; |
|
| 1315 | + for ($i = 0; $i < $linlen; ++$i) { |
|
| 1316 | + $c = substr($line, $i, 1); |
|
| 1317 | + $dec = ord($c); |
|
| 1318 | + if ((32 == $dec) && ($i == ($linlen - 1))) { // convert space at eol only |
|
| 1319 | + $c = '=20'; |
|
| 1320 | + } elseif ((61 == $dec) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required |
|
| 1321 | + $h2 = floor($dec / 16); |
|
| 1322 | + $h1 = floor($dec % 16); |
|
| 1323 | + $c = $escape . $hex[(string)$h2] . $hex[(string)$h1]; |
|
| 1324 | + } |
|
| 1325 | + if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted |
|
| 1326 | + $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay |
|
| 1327 | + $newline = ''; |
|
| 1328 | + } |
|
| 1329 | + $newline .= $c; |
|
| 1330 | + } // end of for |
|
| 1331 | + $output .= $newline . $eol; |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + return trim($output); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + /** |
|
| 1338 | + * Builds the MBOX contents. |
|
| 1339 | + * @return string the feed's complete text |
|
| 1340 | + */ |
|
| 1341 | + public function createFeed() |
|
| 1342 | + { |
|
| 1343 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1344 | + if ('' != $this->items[$i]->author) { |
|
| 1345 | + $from = $this->items[$i]->author; |
|
| 1346 | + } else { |
|
| 1347 | + $from = $this->title; |
|
| 1348 | + } |
|
| 1349 | + $itemDate = new FeedDate($this->items[$i]->date); |
|
| 1350 | + $feed .= 'From ' . strtr(self::qp_enc($from), ' ', '_') . ' ' . date('D M d H:i:s Y', $itemDate->unix()) . "\n"; |
|
| 1351 | + $feed .= "Content-Type: text/plain;\n"; |
|
| 1352 | + $feed .= ' charset="' . $this->encoding . "\"\n"; |
|
| 1353 | + $feed .= "Content-Transfer-Encoding: quoted-printable\n"; |
|
| 1354 | + $feed .= "Content-Type: text/plain\n"; |
|
| 1355 | + $feed .= 'From: "' . self::qp_enc($from) . "\"\n"; |
|
| 1356 | + $feed .= 'Date: ' . $itemDate->rfc822() . "\n"; |
|
| 1357 | + $feed .= 'Subject: ' . self::qp_enc(FeedCreator::iTrunc($this->items[$i]->title, 100)) . "\n"; |
|
| 1358 | + $feed .= "\n"; |
|
| 1359 | + $body = chunk_split(self::qp_enc($this->items[$i]->description)); |
|
| 1360 | + $feed .= preg_replace("~\nFrom ([^\n]*)(\n?)~", "\n>From $1$2\n", $body); |
|
| 1361 | + $feed .= "\n"; |
|
| 1362 | + $feed .= "\n"; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + return $feed; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. |
|
| 1370 | + * @return string the feed cache filename |
|
| 1371 | + * @since 1.4 |
|
| 1372 | + * @access private |
|
| 1373 | + */ |
|
| 1374 | + public function _generateFilename() |
|
| 1375 | + { |
|
| 1376 | + $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1377 | + |
|
| 1378 | + return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.mbox'; |
|
| 1379 | + } |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | /** |
@@ -1388,55 +1388,55 @@ discard block |
||
| 1388 | 1388 | */ |
| 1389 | 1389 | class OPMLCreator extends FeedCreator |
| 1390 | 1390 | { |
| 1391 | - /** |
|
| 1392 | - * OPMLCreator constructor. |
|
| 1393 | - */ |
|
| 1394 | - public function __construct() |
|
| 1395 | - { |
|
| 1396 | - $this->encoding = 'utf-8'; |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - /** |
|
| 1400 | - * @return string |
|
| 1401 | - */ |
|
| 1402 | - public function createFeed() |
|
| 1403 | - { |
|
| 1404 | - $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1405 | - $feed .= $this->_createGeneratorComment(); |
|
| 1406 | - $feed .= $this->_createStylesheetReferences(); |
|
| 1407 | - $feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
|
| 1408 | - $feed .= " <head>\n"; |
|
| 1409 | - $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1410 | - if ('' != $this->pubDate) { |
|
| 1411 | - $date = new FeedDate($this->pubDate); |
|
| 1412 | - $feed .= ' <dateCreated>' . $date->rfc822() . "</dateCreated>\n"; |
|
| 1413 | - } |
|
| 1414 | - if ('' != $this->lastBuildDate) { |
|
| 1415 | - $date = new FeedDate($this->lastBuildDate); |
|
| 1416 | - $feed .= ' <dateModified>' . $date->rfc822() . "</dateModified>\n"; |
|
| 1417 | - } |
|
| 1418 | - if ('' != $this->editor) { |
|
| 1419 | - $feed .= ' <ownerName>' . $this->editor . "</ownerName>\n"; |
|
| 1420 | - } |
|
| 1421 | - if ('' != $this->editorEmail) { |
|
| 1422 | - $feed .= ' <ownerEmail>' . $this->editorEmail . "</ownerEmail>\n"; |
|
| 1423 | - } |
|
| 1424 | - $feed .= " </head>\n"; |
|
| 1425 | - $feed .= " <body>\n"; |
|
| 1426 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1427 | - $feed .= ' <outline type="rss" '; |
|
| 1428 | - $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", ' ')), ENT_QUOTES | ENT_HTML5); |
|
| 1429 | - $feed .= ' title="' . $title . '"'; |
|
| 1430 | - $feed .= ' text="' . $title . '"'; |
|
| 1431 | - //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\""; |
|
| 1432 | - $feed .= ' url="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . '"'; |
|
| 1433 | - $feed .= ">\n"; |
|
| 1434 | - } |
|
| 1435 | - $feed .= " </body>\n"; |
|
| 1436 | - $feed .= "</opml>\n"; |
|
| 1437 | - |
|
| 1438 | - return $feed; |
|
| 1439 | - } |
|
| 1391 | + /** |
|
| 1392 | + * OPMLCreator constructor. |
|
| 1393 | + */ |
|
| 1394 | + public function __construct() |
|
| 1395 | + { |
|
| 1396 | + $this->encoding = 'utf-8'; |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * @return string |
|
| 1401 | + */ |
|
| 1402 | + public function createFeed() |
|
| 1403 | + { |
|
| 1404 | + $feed = '<?xml version="1.0" encoding="' . $this->encoding . "\"?>\n"; |
|
| 1405 | + $feed .= $this->_createGeneratorComment(); |
|
| 1406 | + $feed .= $this->_createStylesheetReferences(); |
|
| 1407 | + $feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
|
| 1408 | + $feed .= " <head>\n"; |
|
| 1409 | + $feed .= ' <title>' . htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5) . "</title>\n"; |
|
| 1410 | + if ('' != $this->pubDate) { |
|
| 1411 | + $date = new FeedDate($this->pubDate); |
|
| 1412 | + $feed .= ' <dateCreated>' . $date->rfc822() . "</dateCreated>\n"; |
|
| 1413 | + } |
|
| 1414 | + if ('' != $this->lastBuildDate) { |
|
| 1415 | + $date = new FeedDate($this->lastBuildDate); |
|
| 1416 | + $feed .= ' <dateModified>' . $date->rfc822() . "</dateModified>\n"; |
|
| 1417 | + } |
|
| 1418 | + if ('' != $this->editor) { |
|
| 1419 | + $feed .= ' <ownerName>' . $this->editor . "</ownerName>\n"; |
|
| 1420 | + } |
|
| 1421 | + if ('' != $this->editorEmail) { |
|
| 1422 | + $feed .= ' <ownerEmail>' . $this->editorEmail . "</ownerEmail>\n"; |
|
| 1423 | + } |
|
| 1424 | + $feed .= " </head>\n"; |
|
| 1425 | + $feed .= " <body>\n"; |
|
| 1426 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1427 | + $feed .= ' <outline type="rss" '; |
|
| 1428 | + $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", ' ')), ENT_QUOTES | ENT_HTML5); |
|
| 1429 | + $feed .= ' title="' . $title . '"'; |
|
| 1430 | + $feed .= ' text="' . $title . '"'; |
|
| 1431 | + //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\""; |
|
| 1432 | + $feed .= ' url="' . htmlspecialchars($this->items[$i]->link, ENT_QUOTES | ENT_HTML5) . '"'; |
|
| 1433 | + $feed .= ">\n"; |
|
| 1434 | + } |
|
| 1435 | + $feed .= " </body>\n"; |
|
| 1436 | + $feed .= "</opml>\n"; |
|
| 1437 | + |
|
| 1438 | + return $feed; |
|
| 1439 | + } |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | /** |
@@ -1452,138 +1452,138 @@ discard block |
||
| 1452 | 1452 | */ |
| 1453 | 1453 | class HTMLCreator extends FeedCreator |
| 1454 | 1454 | { |
| 1455 | - // public $contentType = 'text/html'; |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * Contains HTML to be output at the start of the feed's html representation. |
|
| 1459 | - */ |
|
| 1460 | - public $header; |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * Contains HTML to be output at the end of the feed's html representation. |
|
| 1464 | - */ |
|
| 1465 | - public $footer; |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * Contains HTML to be output between entries. A separator is only used in |
|
| 1469 | - * case of multiple entries. |
|
| 1470 | - */ |
|
| 1471 | - public $separator; |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * Used to prefix the stylenames to make sure they are unique |
|
| 1475 | - * and do not clash with stylenames on the users' page. |
|
| 1476 | - */ |
|
| 1477 | - public $stylePrefix; |
|
| 1478 | - |
|
| 1479 | - /** |
|
| 1480 | - * Determines whether the links open in a new window or not. |
|
| 1481 | - */ |
|
| 1482 | - public $openInNewWindow = true; |
|
| 1483 | - |
|
| 1484 | - public $imageAlign = 'right'; |
|
| 1485 | - |
|
| 1486 | - /** |
|
| 1487 | - * In case of very simple output you may want to get rid of the style tags, |
|
| 1488 | - * hence this variable. There's no equivalent on item level, but of course you can |
|
| 1489 | - * add strings to it while iterating over the items ($this->stylelessOutput .= ...) |
|
| 1490 | - * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored |
|
| 1491 | - * in the function createFeed(). |
|
| 1492 | - */ |
|
| 1493 | - public $stylelessOutput = ''; |
|
| 1494 | - |
|
| 1495 | - /** |
|
| 1496 | - * HTMLCreator constructor. |
|
| 1497 | - */ |
|
| 1498 | - public function __construct() |
|
| 1499 | - { |
|
| 1500 | - $this->contentType = 'text/html'; |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Writes the HTML. |
|
| 1505 | - * @return string the scripts's complete text |
|
| 1506 | - */ |
|
| 1507 | - public function createFeed() |
|
| 1508 | - { |
|
| 1509 | - // if there is styleless output, use the content of this variable and ignore the rest |
|
| 1510 | - if ('' != $this->stylelessOutput) { |
|
| 1511 | - return $this->stylelessOutput; |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - //if no stylePrefix is set, generate it yourself depending on the script name |
|
| 1515 | - if ('' == $this->stylePrefix) { |
|
| 1516 | - $this->stylePrefix = str_replace('.', '_', $this->_generateFilename()) . '_'; |
|
| 1517 | - } |
|
| 1518 | - |
|
| 1519 | - //set an openInNewWindow_token_to be inserted or not |
|
| 1520 | - if ($this->openInNewWindow) { |
|
| 1521 | - $targetInsert = " target='_blank'"; |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - // use this array to put the lines in and implode later with "document.write" javascript |
|
| 1525 | - $feedArray = []; |
|
| 1526 | - if (null != $this->image) { |
|
| 1527 | - $imageStr = "<a href='" . $this->image->link . "'" . $targetInsert . '>' . "<img src='" . $this->image->url . "' border='0' alt='" . FeedCreator::iTrunc(htmlspecialchars($this->image->title, ENT_QUOTES | ENT_HTML5), 100) . "' align='" . $this->imageAlign . "' "; |
|
| 1528 | - if ($this->image->width) { |
|
| 1529 | - $imageStr .= " width='" . $this->image->width . "' "; |
|
| 1530 | - } |
|
| 1531 | - if ($this->image->height) { |
|
| 1532 | - $imageStr .= " height='" . $this->image->height . "' "; |
|
| 1533 | - } |
|
| 1534 | - $imageStr .= '></a>'; |
|
| 1535 | - $feedArray[] = $imageStr; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - if ($this->title) { |
|
| 1539 | - $feedArray[] = "<div class='" . $this->stylePrefix . "title'><a href='" . $this->link . "' " . $targetInsert . " class='" . $this->stylePrefix . "title'>" . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . '</a></div>'; |
|
| 1540 | - } |
|
| 1541 | - if ($this->getDescription()) { |
|
| 1542 | - $feedArray[] = "<div class='" . $this->stylePrefix . "description'>" . str_replace(']]>', '', str_replace('<![CDATA[', '', $this->getDescription())) . '</div>'; |
|
| 1543 | - } |
|
| 1544 | - |
|
| 1545 | - if ($this->header) { |
|
| 1546 | - $feedArray[] = "<div class='" . $this->stylePrefix . "header'>" . $this->header . '</div>'; |
|
| 1547 | - } |
|
| 1548 | - |
|
| 1549 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1550 | - if ($this->separator && $i > 0) { |
|
| 1551 | - $feedArray[] = "<div class='" . $this->stylePrefix . "separator'>" . $this->separator . '</div>'; |
|
| 1552 | - } |
|
| 1553 | - |
|
| 1554 | - if ($this->items[$i]->title) { |
|
| 1555 | - if ($this->items[$i]->link) { |
|
| 1556 | - $feedArray[] = "<div class='" . $this->stylePrefix . "item_title'><a href='" . $this->items[$i]->link . "' class='" . $this->stylePrefix . "item_title'" . $targetInsert . '>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . '</a></div>'; |
|
| 1557 | - } else { |
|
| 1558 | - $feedArray[] = "<div class='" . $this->stylePrefix . "item_title'>" . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . '</div>'; |
|
| 1559 | - } |
|
| 1560 | - } |
|
| 1561 | - if ($this->items[$i]->getDescription()) { |
|
| 1562 | - $feedArray[] = "<div class='" . $this->stylePrefix . "item_description'>" . str_replace(']]>', '', str_replace('<![CDATA[', '', $this->items[$i]->getDescription())) . '</div>'; |
|
| 1563 | - } |
|
| 1564 | - } |
|
| 1565 | - if ($this->footer) { |
|
| 1566 | - $feedArray[] = "<div class='" . $this->stylePrefix . "footer'>" . $this->footer . '</div>'; |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - $feed = '' . implode($feedArray, "\r\n"); |
|
| 1570 | - |
|
| 1571 | - return $feed; |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - /** |
|
| 1575 | - * Overrrides parent to produce .html extensions |
|
| 1576 | - * |
|
| 1577 | - * @return string the feed cache filename |
|
| 1578 | - * @since 1.4 |
|
| 1579 | - * @access private |
|
| 1580 | - */ |
|
| 1581 | - public function _generateFilename() |
|
| 1582 | - { |
|
| 1583 | - $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1584 | - |
|
| 1585 | - return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.html'; |
|
| 1586 | - } |
|
| 1455 | + // public $contentType = 'text/html'; |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * Contains HTML to be output at the start of the feed's html representation. |
|
| 1459 | + */ |
|
| 1460 | + public $header; |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * Contains HTML to be output at the end of the feed's html representation. |
|
| 1464 | + */ |
|
| 1465 | + public $footer; |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * Contains HTML to be output between entries. A separator is only used in |
|
| 1469 | + * case of multiple entries. |
|
| 1470 | + */ |
|
| 1471 | + public $separator; |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * Used to prefix the stylenames to make sure they are unique |
|
| 1475 | + * and do not clash with stylenames on the users' page. |
|
| 1476 | + */ |
|
| 1477 | + public $stylePrefix; |
|
| 1478 | + |
|
| 1479 | + /** |
|
| 1480 | + * Determines whether the links open in a new window or not. |
|
| 1481 | + */ |
|
| 1482 | + public $openInNewWindow = true; |
|
| 1483 | + |
|
| 1484 | + public $imageAlign = 'right'; |
|
| 1485 | + |
|
| 1486 | + /** |
|
| 1487 | + * In case of very simple output you may want to get rid of the style tags, |
|
| 1488 | + * hence this variable. There's no equivalent on item level, but of course you can |
|
| 1489 | + * add strings to it while iterating over the items ($this->stylelessOutput .= ...) |
|
| 1490 | + * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored |
|
| 1491 | + * in the function createFeed(). |
|
| 1492 | + */ |
|
| 1493 | + public $stylelessOutput = ''; |
|
| 1494 | + |
|
| 1495 | + /** |
|
| 1496 | + * HTMLCreator constructor. |
|
| 1497 | + */ |
|
| 1498 | + public function __construct() |
|
| 1499 | + { |
|
| 1500 | + $this->contentType = 'text/html'; |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Writes the HTML. |
|
| 1505 | + * @return string the scripts's complete text |
|
| 1506 | + */ |
|
| 1507 | + public function createFeed() |
|
| 1508 | + { |
|
| 1509 | + // if there is styleless output, use the content of this variable and ignore the rest |
|
| 1510 | + if ('' != $this->stylelessOutput) { |
|
| 1511 | + return $this->stylelessOutput; |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + //if no stylePrefix is set, generate it yourself depending on the script name |
|
| 1515 | + if ('' == $this->stylePrefix) { |
|
| 1516 | + $this->stylePrefix = str_replace('.', '_', $this->_generateFilename()) . '_'; |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + //set an openInNewWindow_token_to be inserted or not |
|
| 1520 | + if ($this->openInNewWindow) { |
|
| 1521 | + $targetInsert = " target='_blank'"; |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + // use this array to put the lines in and implode later with "document.write" javascript |
|
| 1525 | + $feedArray = []; |
|
| 1526 | + if (null != $this->image) { |
|
| 1527 | + $imageStr = "<a href='" . $this->image->link . "'" . $targetInsert . '>' . "<img src='" . $this->image->url . "' border='0' alt='" . FeedCreator::iTrunc(htmlspecialchars($this->image->title, ENT_QUOTES | ENT_HTML5), 100) . "' align='" . $this->imageAlign . "' "; |
|
| 1528 | + if ($this->image->width) { |
|
| 1529 | + $imageStr .= " width='" . $this->image->width . "' "; |
|
| 1530 | + } |
|
| 1531 | + if ($this->image->height) { |
|
| 1532 | + $imageStr .= " height='" . $this->image->height . "' "; |
|
| 1533 | + } |
|
| 1534 | + $imageStr .= '></a>'; |
|
| 1535 | + $feedArray[] = $imageStr; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + if ($this->title) { |
|
| 1539 | + $feedArray[] = "<div class='" . $this->stylePrefix . "title'><a href='" . $this->link . "' " . $targetInsert . " class='" . $this->stylePrefix . "title'>" . FeedCreator::iTrunc(htmlspecialchars($this->title, ENT_QUOTES | ENT_HTML5), 100) . '</a></div>'; |
|
| 1540 | + } |
|
| 1541 | + if ($this->getDescription()) { |
|
| 1542 | + $feedArray[] = "<div class='" . $this->stylePrefix . "description'>" . str_replace(']]>', '', str_replace('<![CDATA[', '', $this->getDescription())) . '</div>'; |
|
| 1543 | + } |
|
| 1544 | + |
|
| 1545 | + if ($this->header) { |
|
| 1546 | + $feedArray[] = "<div class='" . $this->stylePrefix . "header'>" . $this->header . '</div>'; |
|
| 1547 | + } |
|
| 1548 | + |
|
| 1549 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 1550 | + if ($this->separator && $i > 0) { |
|
| 1551 | + $feedArray[] = "<div class='" . $this->stylePrefix . "separator'>" . $this->separator . '</div>'; |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + if ($this->items[$i]->title) { |
|
| 1555 | + if ($this->items[$i]->link) { |
|
| 1556 | + $feedArray[] = "<div class='" . $this->stylePrefix . "item_title'><a href='" . $this->items[$i]->link . "' class='" . $this->stylePrefix . "item_title'" . $targetInsert . '>' . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . '</a></div>'; |
|
| 1557 | + } else { |
|
| 1558 | + $feedArray[] = "<div class='" . $this->stylePrefix . "item_title'>" . FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title), ENT_QUOTES | ENT_HTML5), 100) . '</div>'; |
|
| 1559 | + } |
|
| 1560 | + } |
|
| 1561 | + if ($this->items[$i]->getDescription()) { |
|
| 1562 | + $feedArray[] = "<div class='" . $this->stylePrefix . "item_description'>" . str_replace(']]>', '', str_replace('<![CDATA[', '', $this->items[$i]->getDescription())) . '</div>'; |
|
| 1563 | + } |
|
| 1564 | + } |
|
| 1565 | + if ($this->footer) { |
|
| 1566 | + $feedArray[] = "<div class='" . $this->stylePrefix . "footer'>" . $this->footer . '</div>'; |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + $feed = '' . implode($feedArray, "\r\n"); |
|
| 1570 | + |
|
| 1571 | + return $feed; |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + /** |
|
| 1575 | + * Overrrides parent to produce .html extensions |
|
| 1576 | + * |
|
| 1577 | + * @return string the feed cache filename |
|
| 1578 | + * @since 1.4 |
|
| 1579 | + * @access private |
|
| 1580 | + */ |
|
| 1581 | + public function _generateFilename() |
|
| 1582 | + { |
|
| 1583 | + $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1584 | + |
|
| 1585 | + return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.html'; |
|
| 1586 | + } |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | /** |
@@ -1595,44 +1595,44 @@ discard block |
||
| 1595 | 1595 | class JSCreator extends HTMLCreator |
| 1596 | 1596 | { |
| 1597 | 1597 | |
| 1598 | - /** |
|
| 1599 | - * JSCreator constructor. |
|
| 1600 | - */ |
|
| 1601 | - public function __construct() |
|
| 1602 | - { |
|
| 1603 | - $this->contentType = 'text/javascript'; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * writes the javascript |
|
| 1608 | - * @return string the scripts's complete text |
|
| 1609 | - */ |
|
| 1610 | - public function createFeed() |
|
| 1611 | - { |
|
| 1612 | - $feed = parent::createFeed(); |
|
| 1613 | - $feedArray = explode("\n", $feed); |
|
| 1614 | - |
|
| 1615 | - $jsFeed = ''; |
|
| 1616 | - foreach ($feedArray as $value) { |
|
| 1617 | - $jsFeed .= "document.write('" . trim(addslashes($value)) . "');\n"; |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - return $jsFeed; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * Overrrides parent to produce .js extensions |
|
| 1625 | - * |
|
| 1626 | - * @return string the feed cache filename |
|
| 1627 | - * @since 1.4 |
|
| 1628 | - * @access private |
|
| 1629 | - */ |
|
| 1630 | - public function _generateFilename() |
|
| 1631 | - { |
|
| 1632 | - $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1633 | - |
|
| 1634 | - return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.js'; |
|
| 1635 | - } |
|
| 1598 | + /** |
|
| 1599 | + * JSCreator constructor. |
|
| 1600 | + */ |
|
| 1601 | + public function __construct() |
|
| 1602 | + { |
|
| 1603 | + $this->contentType = 'text/javascript'; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * writes the javascript |
|
| 1608 | + * @return string the scripts's complete text |
|
| 1609 | + */ |
|
| 1610 | + public function createFeed() |
|
| 1611 | + { |
|
| 1612 | + $feed = parent::createFeed(); |
|
| 1613 | + $feedArray = explode("\n", $feed); |
|
| 1614 | + |
|
| 1615 | + $jsFeed = ''; |
|
| 1616 | + foreach ($feedArray as $value) { |
|
| 1617 | + $jsFeed .= "document.write('" . trim(addslashes($value)) . "');\n"; |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + return $jsFeed; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * Overrrides parent to produce .js extensions |
|
| 1625 | + * |
|
| 1626 | + * @return string the feed cache filename |
|
| 1627 | + * @since 1.4 |
|
| 1628 | + * @access private |
|
| 1629 | + */ |
|
| 1630 | + public function _generateFilename() |
|
| 1631 | + { |
|
| 1632 | + $fileInfo = pathinfo($_SERVER['PHP_SELF']); |
|
| 1633 | + |
|
| 1634 | + return substr($fileInfo['basename'], 0, -(strlen($fileInfo['extension']) + 1)) . '.js'; |
|
| 1635 | + } |
|
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | /*** TEST SCRIPT ********************************************************* |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | // smart append - field and namespace aware |
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | - * @param $el |
|
| 309 | + * @param string $el |
|
| 310 | 310 | * @param $text |
| 311 | 311 | */ |
| 312 | 312 | public function append($el, $text) |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
| 393 | - * @return bool |
|
| 393 | + * @return string|false |
|
| 394 | 394 | */ |
| 395 | 395 | public function is_rss() |
| 396 | 396 | { |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | - * @return bool |
|
| 405 | + * @return string|false |
|
| 406 | 406 | */ |
| 407 | 407 | public function is_atom() |
| 408 | 408 | { |
@@ -415,10 +415,10 @@ discard block |
||
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | 417 | * return XML parser, and possibly re-encoded source |
| 418 | - * @param $source |
|
| 419 | - * @param $out_enc |
|
| 420 | - * @param $in_enc |
|
| 421 | - * @param $detect |
|
| 418 | + * @param string $source |
|
| 419 | + * @param string $out_enc |
|
| 420 | + * @param string|null $in_enc |
|
| 421 | + * @param boolean $detect |
|
| 422 | 422 | * @return array |
| 423 | 423 | */ |
| 424 | 424 | public function create_parser($source, $out_enc, $in_enc, $detect) |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | 530 | * @param $enc |
| 531 | - * @return bool|string |
|
| 531 | + * @return string|false |
|
| 532 | 532 | */ |
| 533 | 533 | public function known_encoding($enc) |
| 534 | 534 | { |
@@ -33,468 +33,468 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | class MagpieRSS |
| 35 | 35 | { |
| 36 | - public $parser; |
|
| 37 | - |
|
| 38 | - public $current_item = []; // item currently being parsed |
|
| 39 | - public $items = []; // collection of parsed items |
|
| 40 | - public $channel = []; // hash of channel fields |
|
| 41 | - public $textinput = []; |
|
| 42 | - public $image = []; |
|
| 43 | - public $feed_type; |
|
| 44 | - public $feed_version; |
|
| 45 | - public $encoding = ''; // output encoding of parsed rss |
|
| 46 | - |
|
| 47 | - public $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 48 | - |
|
| 49 | - public $ERROR = ''; |
|
| 50 | - public $WARNING = ''; |
|
| 51 | - |
|
| 52 | - // define some constants |
|
| 53 | - |
|
| 54 | - public $_CONTENT_CONSTRUCTS = ['content', 'summary', 'info', 'title', 'tagline', 'copyright']; |
|
| 55 | - public $_KNOWN_ENCODINGS = ['UTF-8', 'US-ASCII', 'ISO-8859-1']; |
|
| 56 | - |
|
| 57 | - // parser variables, useless if you're not a parser, treat as private |
|
| 58 | - public $stack = []; // parser stack |
|
| 59 | - public $inchannel = false; |
|
| 60 | - public $initem = false; |
|
| 61 | - public $incontent = false; // if in Atom <content mode="xml"> field |
|
| 62 | - public $intextinput = false; |
|
| 63 | - public $inimage = false; |
|
| 64 | - public $current_field = ''; |
|
| 65 | - public $current_namespace = false; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Set up XML parser, parse source, and return populated RSS object.. |
|
| 69 | - * |
|
| 70 | - * @param string $source string containing the RSS to be parsed |
|
| 71 | - * |
|
| 72 | - * NOTE: Probably a good idea to leave the encoding options alone unless |
|
| 73 | - * you know what you're doing as PHP's character set support is |
|
| 74 | - * a little weird. |
|
| 75 | - * |
|
| 76 | - * NOTE: A lot of this is unnecessary but harmless with PHP5 |
|
| 77 | - * |
|
| 78 | - * |
|
| 79 | - * @param string $output_encoding output the parsed RSS in this character |
|
| 80 | - * set defaults to ISO-8859-1 as this is PHP's |
|
| 81 | - * default. |
|
| 82 | - * |
|
| 83 | - * NOTE: might be changed to UTF-8 in future |
|
| 84 | - * versions. |
|
| 85 | - * |
|
| 86 | - * @param string $input_encoding the character set of the incoming RSS source. |
|
| 87 | - * Leave blank and Magpie will try to figure it |
|
| 88 | - * out. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param bool $detect_encoding if false Magpie won't attempt to detect |
|
| 92 | - * source encoding. (caveat emptor) |
|
| 93 | - * |
|
| 94 | - */ |
|
| 95 | - public function __construct( |
|
| 96 | - $source, |
|
| 97 | - $output_encoding = 'ISO-8859-1', |
|
| 98 | - $input_encoding = null, |
|
| 99 | - $detect_encoding = true |
|
| 100 | - ) { |
|
| 101 | - # if PHP xml isn't compiled in, die |
|
| 102 | - # |
|
| 103 | - if (!function_exists('xml_parser_create')) { |
|
| 104 | - $this->error("Failed to load PHP's XML Extension. " . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - list($parser, $source) = $this->create_parser($source, $output_encoding, $input_encoding, $detect_encoding); |
|
| 108 | - |
|
| 109 | - if (!is_resource($parser)) { |
|
| 110 | - $this->error("Failed to create an instance of PHP's XML parser. " . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $this->parser = $parser; |
|
| 114 | - |
|
| 115 | - # pass in parser, and a reference to this object |
|
| 116 | - # setup handlers |
|
| 117 | - # |
|
| 118 | - xml_set_object($this->parser, $this); |
|
| 119 | - xml_set_elementHandler($this->parser, 'feed_start_element', 'feed_end_element'); |
|
| 120 | - |
|
| 121 | - xml_set_character_dataHandler($this->parser, 'feed_cdata'); |
|
| 122 | - |
|
| 123 | - $status = @xml_parse($this->parser, $source); |
|
| 124 | - |
|
| 125 | - if (!$status) { |
|
| 126 | - $errorcode = xml_get_error_code($this->parser); |
|
| 127 | - if (XML_ERROR_NONE != $errorcode) { |
|
| 128 | - $xml_error = xml_error_string($errorcode); |
|
| 129 | - $error_line = xml_get_current_line_number($this->parser); |
|
| 130 | - $error_col = xml_get_current_column_number($this->parser); |
|
| 131 | - $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
| 132 | - |
|
| 133 | - $this->error($errormsg); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - xml_parser_free($this->parser); |
|
| 138 | - |
|
| 139 | - $this->normalize(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param $p |
|
| 144 | - * @param $element |
|
| 145 | - * @param $attrs |
|
| 146 | - */ |
|
| 147 | - public function feed_start_element($p, $element, &$attrs) |
|
| 148 | - { |
|
| 149 | - $el = $element = strtolower($element); |
|
| 150 | - $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
| 151 | - |
|
| 152 | - // check for a namespace, and split if found |
|
| 153 | - $ns = false; |
|
| 154 | - if (strpos($element, ':')) { |
|
| 155 | - list($ns, $el) = explode(':', $element, 2); |
|
| 156 | - } |
|
| 157 | - if ($ns && 'rdf' !== $ns) { |
|
| 158 | - $this->current_namespace = $ns; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - # if feed type isn't set, then this is first element of feed |
|
| 162 | - # identify feed from root element |
|
| 163 | - # |
|
| 164 | - if (!isset($this->feed_type)) { |
|
| 165 | - if ('rdf' === $el) { |
|
| 166 | - $this->feed_type = RSS; |
|
| 167 | - $this->feed_version = '1.0'; |
|
| 168 | - } elseif ('rss' === $el) { |
|
| 169 | - $this->feed_type = RSS; |
|
| 170 | - $this->feed_version = $attrs['version']; |
|
| 171 | - } elseif ('feed' === $el) { |
|
| 172 | - $this->feed_type = ATOM; |
|
| 173 | - $this->feed_version = $attrs['version']; |
|
| 174 | - $this->inchannel = true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if ('channel' === $el) { |
|
| 181 | - $this->inchannel = true; |
|
| 182 | - } elseif ('item' === $el || 'entry' === $el) { |
|
| 183 | - $this->initem = true; |
|
| 184 | - if (isset($attrs['rdf:about'])) { |
|
| 185 | - $this->current_item['about'] = $attrs['rdf:about']; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // if we're in the default namespace of an RSS feed, |
|
| 190 | - // record textinput or image fields |
|
| 191 | - elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'textinput' === $el) { |
|
| 192 | - $this->intextinput = true; |
|
| 193 | - } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'image' === $el) { |
|
| 194 | - $this->inimage = true; |
|
| 195 | - } # handle atom content constructs |
|
| 196 | - elseif (ATOM == $this->feed_type && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 197 | - // avoid clashing w/ RSS mod_content |
|
| 198 | - if ('content' === $el) { |
|
| 199 | - $el = 'atom_content'; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $this->incontent = $el; |
|
| 203 | - } // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
| 204 | - elseif (ATOM == $this->feed_type && $this->incontent) { |
|
| 205 | - // if tags are inlined, then flatten |
|
| 206 | - $attrs_str = implode(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs))); |
|
| 207 | - |
|
| 208 | - $this->append_content("<$element $attrs_str>"); |
|
| 209 | - |
|
| 210 | - array_unshift($this->stack, $el); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // Atom support many links per containging element. |
|
| 214 | - // Magpie treats link elements of type rel='alternate' |
|
| 215 | - // as being equivalent to RSS's simple link element. |
|
| 216 | - // |
|
| 217 | - elseif (ATOM == $this->feed_type && 'link' === $el) { |
|
| 218 | - if (isset($attrs['rel']) && 'alternate' === $attrs['rel']) { |
|
| 219 | - $link_el = 'link'; |
|
| 220 | - } else { |
|
| 221 | - $link_el = 'link_' . $attrs['rel']; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $this->append($link_el, $attrs['href']); |
|
| 225 | - } // set stack[0] to current element |
|
| 226 | - else { |
|
| 227 | - array_unshift($this->stack, $el); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param $p |
|
| 233 | - * @param $text |
|
| 234 | - */ |
|
| 235 | - public function feed_cdata($p, $text) |
|
| 236 | - { |
|
| 237 | - if (ATOM == $this->feed_type && $this->incontent) { |
|
| 238 | - $this->append_content($text); |
|
| 239 | - } else { |
|
| 240 | - $current_el = implode('_', array_reverse($this->stack)); |
|
| 241 | - $this->append($current_el, $text); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param $p |
|
| 247 | - * @param $el |
|
| 248 | - */ |
|
| 249 | - public function feed_end_element($p, $el) |
|
| 250 | - { |
|
| 251 | - $el = strtolower($el); |
|
| 252 | - |
|
| 253 | - if ('item' === $el || 'entry' === $el) { |
|
| 254 | - $this->items[] = $this->current_item; |
|
| 255 | - $this->current_item = []; |
|
| 256 | - $this->initem = false; |
|
| 257 | - } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'textinput' === $el) { |
|
| 258 | - $this->intextinput = false; |
|
| 259 | - } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'image' === $el) { |
|
| 260 | - $this->inimage = false; |
|
| 261 | - } elseif (ATOM == $this->feed_type && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 262 | - $this->incontent = false; |
|
| 263 | - } elseif ('channel' === $el || 'feed' === $el) { |
|
| 264 | - $this->inchannel = false; |
|
| 265 | - } elseif (ATOM == $this->feed_type && $this->incontent) { |
|
| 266 | - // balance tags properly |
|
| 267 | - // note: i don't think this is actually neccessary |
|
| 268 | - if ($this->stack[0] == $el) { |
|
| 269 | - $this->append_content("</$el>"); |
|
| 270 | - } else { |
|
| 271 | - $this->append_content("<$el>"); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - array_shift($this->stack); |
|
| 275 | - } else { |
|
| 276 | - array_shift($this->stack); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $this->current_namespace = false; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @param $str1 |
|
| 284 | - * @param string $str2 |
|
| 285 | - */ |
|
| 286 | - public function concat(&$str1, $str2 = '') |
|
| 287 | - { |
|
| 288 | - if (!isset($str1)) { |
|
| 289 | - $str1 = ''; |
|
| 290 | - } |
|
| 291 | - $str1 .= $str2; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param $text |
|
| 296 | - */ |
|
| 297 | - public function append_content($text) |
|
| 298 | - { |
|
| 299 | - if ($this->initem) { |
|
| 300 | - $this->concat($this->current_item[$this->incontent], $text); |
|
| 301 | - } elseif ($this->inchannel) { |
|
| 302 | - $this->concat($this->channel[$this->incontent], $text); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - // smart append - field and namespace aware |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @param $el |
|
| 310 | - * @param $text |
|
| 311 | - */ |
|
| 312 | - public function append($el, $text) |
|
| 313 | - { |
|
| 314 | - if (!$el) { |
|
| 315 | - return; |
|
| 316 | - } |
|
| 317 | - if ($this->current_namespace) { |
|
| 318 | - if ($this->initem) { |
|
| 319 | - $this->concat($this->current_item[$this->current_namespace][$el], $text); |
|
| 320 | - } elseif ($this->inchannel) { |
|
| 321 | - $this->concat($this->channel[$this->current_namespace][$el], $text); |
|
| 322 | - } elseif ($this->intextinput) { |
|
| 323 | - $this->concat($this->textinput[$this->current_namespace][$el], $text); |
|
| 324 | - } elseif ($this->inimage) { |
|
| 325 | - $this->concat($this->image[$this->current_namespace][$el], $text); |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - if ($this->initem) { |
|
| 329 | - $this->concat($this->current_item[$el], $text); |
|
| 330 | - } elseif ($this->intextinput) { |
|
| 331 | - $this->concat($this->textinput[$el], $text); |
|
| 332 | - } elseif ($this->inimage) { |
|
| 333 | - $this->concat($this->image[$el], $text); |
|
| 334 | - } elseif ($this->inchannel) { |
|
| 335 | - $this->concat($this->channel[$el], $text); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - public function normalize() |
|
| 341 | - { |
|
| 342 | - // if atom populate rss fields |
|
| 343 | - if ($this->is_atom()) { |
|
| 344 | - $this->channel['description'] = $this->channel['tagline']; |
|
| 345 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 346 | - $item = $this->items[$i]; |
|
| 347 | - if (isset($item['summary'])) { |
|
| 348 | - $item['description'] = $item['summary']; |
|
| 349 | - } |
|
| 350 | - if (isset($item['atom_content'])) { |
|
| 351 | - $item['content']['encoded'] = $item['atom_content']; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $atom_date = isset($item['issued']) ? $item['issued'] : @$item['modified']; |
|
| 355 | - if ($atom_date) { |
|
| 356 | - $epoch = @parse_w3cdtf($atom_date); |
|
| 357 | - if ($epoch && $epoch > 0) { |
|
| 358 | - $item['date_timestamp'] = $epoch; |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $this->items[$i] = $item; |
|
| 363 | - } |
|
| 364 | - } elseif ($this->is_rss()) { |
|
| 365 | - $this->channel['tagline'] = $this->channel['description']; |
|
| 366 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 367 | - $item = $this->items[$i]; |
|
| 368 | - if (isset($item['description'])) { |
|
| 369 | - $item['summary'] = $item['description']; |
|
| 370 | - } |
|
| 371 | - if (isset($item['content']['encoded'])) { |
|
| 372 | - $item['atom_content'] = $item['content']['encoded']; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ('1.0' === $this->is_rss() && isset($item['dc']['date'])) { |
|
| 376 | - $epoch = @parse_w3cdtf($item['dc']['date']); |
|
| 377 | - if ($epoch && $epoch > 0) { |
|
| 378 | - $item['date_timestamp'] = $epoch; |
|
| 379 | - } |
|
| 380 | - } elseif (isset($item['pubdate'])) { |
|
| 381 | - $epoch = @strtotime($item['pubdate']); |
|
| 382 | - if ($epoch > 0) { |
|
| 383 | - $item['date_timestamp'] = $epoch; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $this->items[$i] = $item; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * @return bool |
|
| 394 | - */ |
|
| 395 | - public function is_rss() |
|
| 396 | - { |
|
| 397 | - if (RSS == $this->feed_type) { |
|
| 398 | - return $this->feed_version; |
|
| 399 | - } else { |
|
| 400 | - return false; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * @return bool |
|
| 406 | - */ |
|
| 407 | - public function is_atom() |
|
| 408 | - { |
|
| 409 | - if (ATOM == $this->feed_type) { |
|
| 410 | - return $this->feed_version; |
|
| 411 | - } else { |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * return XML parser, and possibly re-encoded source |
|
| 418 | - * @param $source |
|
| 419 | - * @param $out_enc |
|
| 420 | - * @param $in_enc |
|
| 421 | - * @param $detect |
|
| 422 | - * @return array |
|
| 423 | - */ |
|
| 424 | - public function create_parser($source, $out_enc, $in_enc, $detect) |
|
| 425 | - { |
|
| 426 | - if (5 == substr(PHP_VERSION, 0, 1)) { |
|
| 427 | - $parser = $this->php5_create_parser($in_enc, $detect); |
|
| 428 | - } else { |
|
| 429 | - list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
| 430 | - } |
|
| 431 | - if ($out_enc) { |
|
| 432 | - $this->encoding = $out_enc; |
|
| 433 | - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return [$parser, $source]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Instantiate an XML parser under PHP5 |
|
| 441 | - * |
|
| 442 | - * PHP5 will do a fine job of detecting input encoding |
|
| 443 | - * if passed an empty string as the encoding. |
|
| 444 | - * |
|
| 445 | - * All hail libxml2! |
|
| 446 | - * @param $in_enc |
|
| 447 | - * @param $detect |
|
| 448 | - * @return resource |
|
| 449 | - */ |
|
| 450 | - public function php5_create_parser($in_enc, $detect) |
|
| 451 | - { |
|
| 452 | - // by default php5 does a fine job of detecting input encodings |
|
| 453 | - if (!$detect && $in_enc) { |
|
| 454 | - return xml_parser_create($in_enc); |
|
| 455 | - } else { |
|
| 456 | - return xml_parser_create(''); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Instaniate an XML parser under PHP4 |
|
| 462 | - * |
|
| 463 | - * Unfortunately PHP4's support for character encodings |
|
| 464 | - * and especially XML and character encodings sucks. As |
|
| 465 | - * long as the documents you parse only contain characters |
|
| 466 | - * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 467 | - * and a subset of UTF-8) you're fine. However once you |
|
| 468 | - * step out of that comfy little world things get mad, bad, |
|
| 469 | - * and dangerous to know. |
|
| 470 | - * |
|
| 471 | - * The following code is based on SJM's work with FoF |
|
| 472 | - * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 473 | - * @param $source |
|
| 474 | - * @param $in_enc |
|
| 475 | - * @param $detect |
|
| 476 | - * @return array |
|
| 477 | - */ |
|
| 478 | - public function php4_create_parser($source, $in_enc, $detect) |
|
| 479 | - { |
|
| 480 | - if (!$detect) { |
|
| 481 | - return [xml_parser_create($in_enc), $source]; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (!$in_enc) { |
|
| 485 | - if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
| 486 | - $in_enc = strtoupper($m[1]); |
|
| 487 | - $this->source_encoding = $in_enc; |
|
| 488 | - } else { |
|
| 489 | - $in_enc = 'UTF-8'; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - if ($this->known_encoding($in_enc)) { |
|
| 494 | - return [xml_parser_create($in_enc), $source]; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /* |
|
| 36 | + public $parser; |
|
| 37 | + |
|
| 38 | + public $current_item = []; // item currently being parsed |
|
| 39 | + public $items = []; // collection of parsed items |
|
| 40 | + public $channel = []; // hash of channel fields |
|
| 41 | + public $textinput = []; |
|
| 42 | + public $image = []; |
|
| 43 | + public $feed_type; |
|
| 44 | + public $feed_version; |
|
| 45 | + public $encoding = ''; // output encoding of parsed rss |
|
| 46 | + |
|
| 47 | + public $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 48 | + |
|
| 49 | + public $ERROR = ''; |
|
| 50 | + public $WARNING = ''; |
|
| 51 | + |
|
| 52 | + // define some constants |
|
| 53 | + |
|
| 54 | + public $_CONTENT_CONSTRUCTS = ['content', 'summary', 'info', 'title', 'tagline', 'copyright']; |
|
| 55 | + public $_KNOWN_ENCODINGS = ['UTF-8', 'US-ASCII', 'ISO-8859-1']; |
|
| 56 | + |
|
| 57 | + // parser variables, useless if you're not a parser, treat as private |
|
| 58 | + public $stack = []; // parser stack |
|
| 59 | + public $inchannel = false; |
|
| 60 | + public $initem = false; |
|
| 61 | + public $incontent = false; // if in Atom <content mode="xml"> field |
|
| 62 | + public $intextinput = false; |
|
| 63 | + public $inimage = false; |
|
| 64 | + public $current_field = ''; |
|
| 65 | + public $current_namespace = false; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Set up XML parser, parse source, and return populated RSS object.. |
|
| 69 | + * |
|
| 70 | + * @param string $source string containing the RSS to be parsed |
|
| 71 | + * |
|
| 72 | + * NOTE: Probably a good idea to leave the encoding options alone unless |
|
| 73 | + * you know what you're doing as PHP's character set support is |
|
| 74 | + * a little weird. |
|
| 75 | + * |
|
| 76 | + * NOTE: A lot of this is unnecessary but harmless with PHP5 |
|
| 77 | + * |
|
| 78 | + * |
|
| 79 | + * @param string $output_encoding output the parsed RSS in this character |
|
| 80 | + * set defaults to ISO-8859-1 as this is PHP's |
|
| 81 | + * default. |
|
| 82 | + * |
|
| 83 | + * NOTE: might be changed to UTF-8 in future |
|
| 84 | + * versions. |
|
| 85 | + * |
|
| 86 | + * @param string $input_encoding the character set of the incoming RSS source. |
|
| 87 | + * Leave blank and Magpie will try to figure it |
|
| 88 | + * out. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param bool $detect_encoding if false Magpie won't attempt to detect |
|
| 92 | + * source encoding. (caveat emptor) |
|
| 93 | + * |
|
| 94 | + */ |
|
| 95 | + public function __construct( |
|
| 96 | + $source, |
|
| 97 | + $output_encoding = 'ISO-8859-1', |
|
| 98 | + $input_encoding = null, |
|
| 99 | + $detect_encoding = true |
|
| 100 | + ) { |
|
| 101 | + # if PHP xml isn't compiled in, die |
|
| 102 | + # |
|
| 103 | + if (!function_exists('xml_parser_create')) { |
|
| 104 | + $this->error("Failed to load PHP's XML Extension. " . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + list($parser, $source) = $this->create_parser($source, $output_encoding, $input_encoding, $detect_encoding); |
|
| 108 | + |
|
| 109 | + if (!is_resource($parser)) { |
|
| 110 | + $this->error("Failed to create an instance of PHP's XML parser. " . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $this->parser = $parser; |
|
| 114 | + |
|
| 115 | + # pass in parser, and a reference to this object |
|
| 116 | + # setup handlers |
|
| 117 | + # |
|
| 118 | + xml_set_object($this->parser, $this); |
|
| 119 | + xml_set_elementHandler($this->parser, 'feed_start_element', 'feed_end_element'); |
|
| 120 | + |
|
| 121 | + xml_set_character_dataHandler($this->parser, 'feed_cdata'); |
|
| 122 | + |
|
| 123 | + $status = @xml_parse($this->parser, $source); |
|
| 124 | + |
|
| 125 | + if (!$status) { |
|
| 126 | + $errorcode = xml_get_error_code($this->parser); |
|
| 127 | + if (XML_ERROR_NONE != $errorcode) { |
|
| 128 | + $xml_error = xml_error_string($errorcode); |
|
| 129 | + $error_line = xml_get_current_line_number($this->parser); |
|
| 130 | + $error_col = xml_get_current_column_number($this->parser); |
|
| 131 | + $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
| 132 | + |
|
| 133 | + $this->error($errormsg); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + xml_parser_free($this->parser); |
|
| 138 | + |
|
| 139 | + $this->normalize(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param $p |
|
| 144 | + * @param $element |
|
| 145 | + * @param $attrs |
|
| 146 | + */ |
|
| 147 | + public function feed_start_element($p, $element, &$attrs) |
|
| 148 | + { |
|
| 149 | + $el = $element = strtolower($element); |
|
| 150 | + $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
| 151 | + |
|
| 152 | + // check for a namespace, and split if found |
|
| 153 | + $ns = false; |
|
| 154 | + if (strpos($element, ':')) { |
|
| 155 | + list($ns, $el) = explode(':', $element, 2); |
|
| 156 | + } |
|
| 157 | + if ($ns && 'rdf' !== $ns) { |
|
| 158 | + $this->current_namespace = $ns; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + # if feed type isn't set, then this is first element of feed |
|
| 162 | + # identify feed from root element |
|
| 163 | + # |
|
| 164 | + if (!isset($this->feed_type)) { |
|
| 165 | + if ('rdf' === $el) { |
|
| 166 | + $this->feed_type = RSS; |
|
| 167 | + $this->feed_version = '1.0'; |
|
| 168 | + } elseif ('rss' === $el) { |
|
| 169 | + $this->feed_type = RSS; |
|
| 170 | + $this->feed_version = $attrs['version']; |
|
| 171 | + } elseif ('feed' === $el) { |
|
| 172 | + $this->feed_type = ATOM; |
|
| 173 | + $this->feed_version = $attrs['version']; |
|
| 174 | + $this->inchannel = true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if ('channel' === $el) { |
|
| 181 | + $this->inchannel = true; |
|
| 182 | + } elseif ('item' === $el || 'entry' === $el) { |
|
| 183 | + $this->initem = true; |
|
| 184 | + if (isset($attrs['rdf:about'])) { |
|
| 185 | + $this->current_item['about'] = $attrs['rdf:about']; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // if we're in the default namespace of an RSS feed, |
|
| 190 | + // record textinput or image fields |
|
| 191 | + elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'textinput' === $el) { |
|
| 192 | + $this->intextinput = true; |
|
| 193 | + } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'image' === $el) { |
|
| 194 | + $this->inimage = true; |
|
| 195 | + } # handle atom content constructs |
|
| 196 | + elseif (ATOM == $this->feed_type && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 197 | + // avoid clashing w/ RSS mod_content |
|
| 198 | + if ('content' === $el) { |
|
| 199 | + $el = 'atom_content'; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $this->incontent = $el; |
|
| 203 | + } // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
| 204 | + elseif (ATOM == $this->feed_type && $this->incontent) { |
|
| 205 | + // if tags are inlined, then flatten |
|
| 206 | + $attrs_str = implode(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs))); |
|
| 207 | + |
|
| 208 | + $this->append_content("<$element $attrs_str>"); |
|
| 209 | + |
|
| 210 | + array_unshift($this->stack, $el); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // Atom support many links per containging element. |
|
| 214 | + // Magpie treats link elements of type rel='alternate' |
|
| 215 | + // as being equivalent to RSS's simple link element. |
|
| 216 | + // |
|
| 217 | + elseif (ATOM == $this->feed_type && 'link' === $el) { |
|
| 218 | + if (isset($attrs['rel']) && 'alternate' === $attrs['rel']) { |
|
| 219 | + $link_el = 'link'; |
|
| 220 | + } else { |
|
| 221 | + $link_el = 'link_' . $attrs['rel']; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $this->append($link_el, $attrs['href']); |
|
| 225 | + } // set stack[0] to current element |
|
| 226 | + else { |
|
| 227 | + array_unshift($this->stack, $el); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param $p |
|
| 233 | + * @param $text |
|
| 234 | + */ |
|
| 235 | + public function feed_cdata($p, $text) |
|
| 236 | + { |
|
| 237 | + if (ATOM == $this->feed_type && $this->incontent) { |
|
| 238 | + $this->append_content($text); |
|
| 239 | + } else { |
|
| 240 | + $current_el = implode('_', array_reverse($this->stack)); |
|
| 241 | + $this->append($current_el, $text); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param $p |
|
| 247 | + * @param $el |
|
| 248 | + */ |
|
| 249 | + public function feed_end_element($p, $el) |
|
| 250 | + { |
|
| 251 | + $el = strtolower($el); |
|
| 252 | + |
|
| 253 | + if ('item' === $el || 'entry' === $el) { |
|
| 254 | + $this->items[] = $this->current_item; |
|
| 255 | + $this->current_item = []; |
|
| 256 | + $this->initem = false; |
|
| 257 | + } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'textinput' === $el) { |
|
| 258 | + $this->intextinput = false; |
|
| 259 | + } elseif (RSS == $this->feed_type && '' === $this->current_namespace && 'image' === $el) { |
|
| 260 | + $this->inimage = false; |
|
| 261 | + } elseif (ATOM == $this->feed_type && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 262 | + $this->incontent = false; |
|
| 263 | + } elseif ('channel' === $el || 'feed' === $el) { |
|
| 264 | + $this->inchannel = false; |
|
| 265 | + } elseif (ATOM == $this->feed_type && $this->incontent) { |
|
| 266 | + // balance tags properly |
|
| 267 | + // note: i don't think this is actually neccessary |
|
| 268 | + if ($this->stack[0] == $el) { |
|
| 269 | + $this->append_content("</$el>"); |
|
| 270 | + } else { |
|
| 271 | + $this->append_content("<$el>"); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + array_shift($this->stack); |
|
| 275 | + } else { |
|
| 276 | + array_shift($this->stack); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $this->current_namespace = false; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @param $str1 |
|
| 284 | + * @param string $str2 |
|
| 285 | + */ |
|
| 286 | + public function concat(&$str1, $str2 = '') |
|
| 287 | + { |
|
| 288 | + if (!isset($str1)) { |
|
| 289 | + $str1 = ''; |
|
| 290 | + } |
|
| 291 | + $str1 .= $str2; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param $text |
|
| 296 | + */ |
|
| 297 | + public function append_content($text) |
|
| 298 | + { |
|
| 299 | + if ($this->initem) { |
|
| 300 | + $this->concat($this->current_item[$this->incontent], $text); |
|
| 301 | + } elseif ($this->inchannel) { |
|
| 302 | + $this->concat($this->channel[$this->incontent], $text); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + // smart append - field and namespace aware |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @param $el |
|
| 310 | + * @param $text |
|
| 311 | + */ |
|
| 312 | + public function append($el, $text) |
|
| 313 | + { |
|
| 314 | + if (!$el) { |
|
| 315 | + return; |
|
| 316 | + } |
|
| 317 | + if ($this->current_namespace) { |
|
| 318 | + if ($this->initem) { |
|
| 319 | + $this->concat($this->current_item[$this->current_namespace][$el], $text); |
|
| 320 | + } elseif ($this->inchannel) { |
|
| 321 | + $this->concat($this->channel[$this->current_namespace][$el], $text); |
|
| 322 | + } elseif ($this->intextinput) { |
|
| 323 | + $this->concat($this->textinput[$this->current_namespace][$el], $text); |
|
| 324 | + } elseif ($this->inimage) { |
|
| 325 | + $this->concat($this->image[$this->current_namespace][$el], $text); |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + if ($this->initem) { |
|
| 329 | + $this->concat($this->current_item[$el], $text); |
|
| 330 | + } elseif ($this->intextinput) { |
|
| 331 | + $this->concat($this->textinput[$el], $text); |
|
| 332 | + } elseif ($this->inimage) { |
|
| 333 | + $this->concat($this->image[$el], $text); |
|
| 334 | + } elseif ($this->inchannel) { |
|
| 335 | + $this->concat($this->channel[$el], $text); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + public function normalize() |
|
| 341 | + { |
|
| 342 | + // if atom populate rss fields |
|
| 343 | + if ($this->is_atom()) { |
|
| 344 | + $this->channel['description'] = $this->channel['tagline']; |
|
| 345 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 346 | + $item = $this->items[$i]; |
|
| 347 | + if (isset($item['summary'])) { |
|
| 348 | + $item['description'] = $item['summary']; |
|
| 349 | + } |
|
| 350 | + if (isset($item['atom_content'])) { |
|
| 351 | + $item['content']['encoded'] = $item['atom_content']; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $atom_date = isset($item['issued']) ? $item['issued'] : @$item['modified']; |
|
| 355 | + if ($atom_date) { |
|
| 356 | + $epoch = @parse_w3cdtf($atom_date); |
|
| 357 | + if ($epoch && $epoch > 0) { |
|
| 358 | + $item['date_timestamp'] = $epoch; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $this->items[$i] = $item; |
|
| 363 | + } |
|
| 364 | + } elseif ($this->is_rss()) { |
|
| 365 | + $this->channel['tagline'] = $this->channel['description']; |
|
| 366 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 367 | + $item = $this->items[$i]; |
|
| 368 | + if (isset($item['description'])) { |
|
| 369 | + $item['summary'] = $item['description']; |
|
| 370 | + } |
|
| 371 | + if (isset($item['content']['encoded'])) { |
|
| 372 | + $item['atom_content'] = $item['content']['encoded']; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ('1.0' === $this->is_rss() && isset($item['dc']['date'])) { |
|
| 376 | + $epoch = @parse_w3cdtf($item['dc']['date']); |
|
| 377 | + if ($epoch && $epoch > 0) { |
|
| 378 | + $item['date_timestamp'] = $epoch; |
|
| 379 | + } |
|
| 380 | + } elseif (isset($item['pubdate'])) { |
|
| 381 | + $epoch = @strtotime($item['pubdate']); |
|
| 382 | + if ($epoch > 0) { |
|
| 383 | + $item['date_timestamp'] = $epoch; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $this->items[$i] = $item; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * @return bool |
|
| 394 | + */ |
|
| 395 | + public function is_rss() |
|
| 396 | + { |
|
| 397 | + if (RSS == $this->feed_type) { |
|
| 398 | + return $this->feed_version; |
|
| 399 | + } else { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * @return bool |
|
| 406 | + */ |
|
| 407 | + public function is_atom() |
|
| 408 | + { |
|
| 409 | + if (ATOM == $this->feed_type) { |
|
| 410 | + return $this->feed_version; |
|
| 411 | + } else { |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * return XML parser, and possibly re-encoded source |
|
| 418 | + * @param $source |
|
| 419 | + * @param $out_enc |
|
| 420 | + * @param $in_enc |
|
| 421 | + * @param $detect |
|
| 422 | + * @return array |
|
| 423 | + */ |
|
| 424 | + public function create_parser($source, $out_enc, $in_enc, $detect) |
|
| 425 | + { |
|
| 426 | + if (5 == substr(PHP_VERSION, 0, 1)) { |
|
| 427 | + $parser = $this->php5_create_parser($in_enc, $detect); |
|
| 428 | + } else { |
|
| 429 | + list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
| 430 | + } |
|
| 431 | + if ($out_enc) { |
|
| 432 | + $this->encoding = $out_enc; |
|
| 433 | + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return [$parser, $source]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Instantiate an XML parser under PHP5 |
|
| 441 | + * |
|
| 442 | + * PHP5 will do a fine job of detecting input encoding |
|
| 443 | + * if passed an empty string as the encoding. |
|
| 444 | + * |
|
| 445 | + * All hail libxml2! |
|
| 446 | + * @param $in_enc |
|
| 447 | + * @param $detect |
|
| 448 | + * @return resource |
|
| 449 | + */ |
|
| 450 | + public function php5_create_parser($in_enc, $detect) |
|
| 451 | + { |
|
| 452 | + // by default php5 does a fine job of detecting input encodings |
|
| 453 | + if (!$detect && $in_enc) { |
|
| 454 | + return xml_parser_create($in_enc); |
|
| 455 | + } else { |
|
| 456 | + return xml_parser_create(''); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Instaniate an XML parser under PHP4 |
|
| 462 | + * |
|
| 463 | + * Unfortunately PHP4's support for character encodings |
|
| 464 | + * and especially XML and character encodings sucks. As |
|
| 465 | + * long as the documents you parse only contain characters |
|
| 466 | + * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 467 | + * and a subset of UTF-8) you're fine. However once you |
|
| 468 | + * step out of that comfy little world things get mad, bad, |
|
| 469 | + * and dangerous to know. |
|
| 470 | + * |
|
| 471 | + * The following code is based on SJM's work with FoF |
|
| 472 | + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 473 | + * @param $source |
|
| 474 | + * @param $in_enc |
|
| 475 | + * @param $detect |
|
| 476 | + * @return array |
|
| 477 | + */ |
|
| 478 | + public function php4_create_parser($source, $in_enc, $detect) |
|
| 479 | + { |
|
| 480 | + if (!$detect) { |
|
| 481 | + return [xml_parser_create($in_enc), $source]; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (!$in_enc) { |
|
| 485 | + if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
| 486 | + $in_enc = strtoupper($m[1]); |
|
| 487 | + $this->source_encoding = $in_enc; |
|
| 488 | + } else { |
|
| 489 | + $in_enc = 'UTF-8'; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + if ($this->known_encoding($in_enc)) { |
|
| 494 | + return [xml_parser_create($in_enc), $source]; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /* |
|
| 498 | 498 | // the dectected encoding is not one of the simple encodings PHP knows |
| 499 | 499 | |
| 500 | 500 | // attempt to use the iconv extension to |
@@ -523,46 +523,46 @@ discard block |
||
| 523 | 523 | E_USER_NOTICE); |
| 524 | 524 | */ |
| 525 | 525 | |
| 526 | - return [xml_parser_create(), $source]; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * @param $enc |
|
| 531 | - * @return bool|string |
|
| 532 | - */ |
|
| 533 | - public function known_encoding($enc) |
|
| 534 | - { |
|
| 535 | - $enc = strtoupper($enc); |
|
| 536 | - if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
| 537 | - return $enc; |
|
| 538 | - } else { |
|
| 539 | - return false; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @param $errormsg |
|
| 545 | - * @param int $lvl |
|
| 546 | - */ |
|
| 547 | - public function error($errormsg, $lvl = E_USER_WARNING) |
|
| 548 | - { |
|
| 549 | - // append PHP's error message if track_errors enabled |
|
| 550 | - if (!empty($php_errormsg)) { |
|
| 551 | - $errormsg .= " ($php_errormsg)"; |
|
| 552 | - } |
|
| 553 | - if (MAGPIE_DEBUG) { |
|
| 554 | - trigger_error($errormsg, $lvl); |
|
| 555 | - } else { |
|
| 556 | - error_log($errormsg, 0); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - $notices = E_USER_NOTICE | E_NOTICE; |
|
| 560 | - if ($lvl & $notices) { |
|
| 561 | - $this->WARNING = $errormsg; |
|
| 562 | - } else { |
|
| 563 | - $this->ERROR = $errormsg; |
|
| 564 | - } |
|
| 565 | - } |
|
| 526 | + return [xml_parser_create(), $source]; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * @param $enc |
|
| 531 | + * @return bool|string |
|
| 532 | + */ |
|
| 533 | + public function known_encoding($enc) |
|
| 534 | + { |
|
| 535 | + $enc = strtoupper($enc); |
|
| 536 | + if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
| 537 | + return $enc; |
|
| 538 | + } else { |
|
| 539 | + return false; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @param $errormsg |
|
| 545 | + * @param int $lvl |
|
| 546 | + */ |
|
| 547 | + public function error($errormsg, $lvl = E_USER_WARNING) |
|
| 548 | + { |
|
| 549 | + // append PHP's error message if track_errors enabled |
|
| 550 | + if (!empty($php_errormsg)) { |
|
| 551 | + $errormsg .= " ($php_errormsg)"; |
|
| 552 | + } |
|
| 553 | + if (MAGPIE_DEBUG) { |
|
| 554 | + trigger_error($errormsg, $lvl); |
|
| 555 | + } else { |
|
| 556 | + error_log($errormsg, 0); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + $notices = E_USER_NOTICE | E_NOTICE; |
|
| 560 | + if ($lvl & $notices) { |
|
| 561 | + $this->WARNING = $errormsg; |
|
| 562 | + } else { |
|
| 563 | + $this->ERROR = $errormsg; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | 566 | } // end class RSS |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | */ |
| 573 | 573 | function map_attrs($k, $v) |
| 574 | 574 | { |
| 575 | - return "$k=\"$v\""; |
|
| 575 | + return "$k=\"$v\""; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -581,50 +581,50 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | function parse_w3cdtf($date_str) |
| 583 | 583 | { |
| 584 | - # regex to match wc3dtf |
|
| 585 | - $pat = "/(\d{4})-(\d{2})-(\d{2})[T]?(\d{2})?[:]?(\d{2})?(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
|
| 586 | - |
|
| 587 | - if (preg_match($pat, $date_str, $match)) { |
|
| 588 | - list($year, $month, $day, $hours, $minutes, $seconds) = [ |
|
| 589 | - $match[1], |
|
| 590 | - $match[2], |
|
| 591 | - $match[3], |
|
| 592 | - $match[4], |
|
| 593 | - $match[5], |
|
| 594 | - $match[6] |
|
| 595 | - ]; |
|
| 596 | - |
|
| 597 | - # calc epoch for current date assuming GMT |
|
| 598 | - $epoch = gmmktime((int)$hours, (int)$minutes, (int)$seconds, (int)$month, (int)$day, (int)$year); |
|
| 599 | - |
|
| 600 | - $offset = 0; |
|
| 601 | - if ('Z' === $match[10]) { |
|
| 602 | - # zulu time, aka GMT |
|
| 603 | - } else { |
|
| 604 | - list($tz_mod, $tz_hour, $tz_min) = [$match[8], $match[9], $match[10]]; |
|
| 605 | - |
|
| 606 | - # zero out the variables |
|
| 607 | - if (!$tz_hour) { |
|
| 608 | - $tz_hour = 0; |
|
| 609 | - } |
|
| 610 | - if (!$tz_min) { |
|
| 611 | - $tz_min = 0; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
| 615 | - |
|
| 616 | - # is timezone ahead of GMT? then subtract offset |
|
| 617 | - # |
|
| 618 | - if ('+' == $tz_mod) { |
|
| 619 | - $offset_secs = $offset_secs * -1; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - $offset = $offset_secs; |
|
| 623 | - } |
|
| 624 | - $epoch = $epoch + $offset; |
|
| 625 | - |
|
| 626 | - return $epoch; |
|
| 627 | - } else { |
|
| 628 | - return -1; |
|
| 629 | - } |
|
| 584 | + # regex to match wc3dtf |
|
| 585 | + $pat = "/(\d{4})-(\d{2})-(\d{2})[T]?(\d{2})?[:]?(\d{2})?(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
|
| 586 | + |
|
| 587 | + if (preg_match($pat, $date_str, $match)) { |
|
| 588 | + list($year, $month, $day, $hours, $minutes, $seconds) = [ |
|
| 589 | + $match[1], |
|
| 590 | + $match[2], |
|
| 591 | + $match[3], |
|
| 592 | + $match[4], |
|
| 593 | + $match[5], |
|
| 594 | + $match[6] |
|
| 595 | + ]; |
|
| 596 | + |
|
| 597 | + # calc epoch for current date assuming GMT |
|
| 598 | + $epoch = gmmktime((int)$hours, (int)$minutes, (int)$seconds, (int)$month, (int)$day, (int)$year); |
|
| 599 | + |
|
| 600 | + $offset = 0; |
|
| 601 | + if ('Z' === $match[10]) { |
|
| 602 | + # zulu time, aka GMT |
|
| 603 | + } else { |
|
| 604 | + list($tz_mod, $tz_hour, $tz_min) = [$match[8], $match[9], $match[10]]; |
|
| 605 | + |
|
| 606 | + # zero out the variables |
|
| 607 | + if (!$tz_hour) { |
|
| 608 | + $tz_hour = 0; |
|
| 609 | + } |
|
| 610 | + if (!$tz_min) { |
|
| 611 | + $tz_min = 0; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
| 615 | + |
|
| 616 | + # is timezone ahead of GMT? then subtract offset |
|
| 617 | + # |
|
| 618 | + if ('+' == $tz_mod) { |
|
| 619 | + $offset_secs = $offset_secs * -1; |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + $offset = $offset_secs; |
|
| 623 | + } |
|
| 624 | + $epoch = $epoch + $offset; |
|
| 625 | + |
|
| 626 | + return $epoch; |
|
| 627 | + } else { |
|
| 628 | + return -1; |
|
| 629 | + } |
|
| 630 | 630 | } |
@@ -84,7 +84,7 @@ |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * @return bool|string |
|
| 87 | + * @return string|false |
|
| 88 | 88 | */ |
| 89 | 89 | public function is_atom() |
| 90 | 90 | { |
@@ -43,171 +43,171 @@ |
||
| 43 | 43 | **/ |
| 44 | 44 | class xmlparser extends MagpieRSS |
| 45 | 45 | { |
| 46 | - public $content; |
|
| 47 | - public $charset_in; |
|
| 48 | - public $charset_out; |
|
| 46 | + public $content; |
|
| 47 | + public $charset_in; |
|
| 48 | + public $charset_out; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Set up XML parser, parse source, and return populated RSS object.. |
|
| 52 | - * |
|
| 53 | - * @param string $content string containing the RSS to be parsed |
|
| 54 | - * |
|
| 55 | - * |
|
| 56 | - * @param string $input_charset |
|
| 57 | - * @param null|string $output_charset |
|
| 58 | - * @param array $tags |
|
| 59 | - * @internal param string $output_encoding output the parsed RSS in this character |
|
| 60 | - * set defaults to ISO-8859-1 as this is PHP's |
|
| 61 | - * default. |
|
| 62 | - * |
|
| 63 | - * @internal param string $input_encoding the character set of the incoming RSS source. |
|
| 64 | - * Leave blank and Magpie will try to figure it |
|
| 65 | - * out. |
|
| 66 | - */ |
|
| 67 | - public function __construct($content, $input_charset, $output_charset = _CHARSET, $tags = []) |
|
| 68 | - { |
|
| 69 | - if (!in_array(strtoupper($input_charset), ['UTF-8', 'US-ASCII', 'ISO-8859-1'])) { |
|
| 70 | - $content = XoopsLocal::convert_encoding($content, 'UTF-8', $input_charset); |
|
| 71 | - $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
|
| 72 | - $input_charset = 'UTF-8'; |
|
| 73 | - } |
|
| 74 | - $this->content = $content; |
|
| 75 | - $this->charset_in = $input_charset; |
|
| 76 | - $this->charset_out = $output_charset; |
|
| 50 | + /** |
|
| 51 | + * Set up XML parser, parse source, and return populated RSS object.. |
|
| 52 | + * |
|
| 53 | + * @param string $content string containing the RSS to be parsed |
|
| 54 | + * |
|
| 55 | + * |
|
| 56 | + * @param string $input_charset |
|
| 57 | + * @param null|string $output_charset |
|
| 58 | + * @param array $tags |
|
| 59 | + * @internal param string $output_encoding output the parsed RSS in this character |
|
| 60 | + * set defaults to ISO-8859-1 as this is PHP's |
|
| 61 | + * default. |
|
| 62 | + * |
|
| 63 | + * @internal param string $input_encoding the character set of the incoming RSS source. |
|
| 64 | + * Leave blank and Magpie will try to figure it |
|
| 65 | + * out. |
|
| 66 | + */ |
|
| 67 | + public function __construct($content, $input_charset, $output_charset = _CHARSET, $tags = []) |
|
| 68 | + { |
|
| 69 | + if (!in_array(strtoupper($input_charset), ['UTF-8', 'US-ASCII', 'ISO-8859-1'])) { |
|
| 70 | + $content = XoopsLocal::convert_encoding($content, 'UTF-8', $input_charset); |
|
| 71 | + $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
|
| 72 | + $input_charset = 'UTF-8'; |
|
| 73 | + } |
|
| 74 | + $this->content = $content; |
|
| 75 | + $this->charset_in = $input_charset; |
|
| 76 | + $this->charset_out = $output_charset; |
|
| 77 | 77 | |
| 78 | - /* TODO: parse specified tags only */ |
|
| 79 | - parent::__construct($content, $input_charset, $input_charset, false); |
|
| 78 | + /* TODO: parse specified tags only */ |
|
| 79 | + parent::__construct($content, $input_charset, $input_charset, false); |
|
| 80 | 80 | |
| 81 | - //xoops_message($this); |
|
| 82 | - unset($this->content); |
|
| 83 | - $this->encoding_convert($tags); |
|
| 84 | - } |
|
| 81 | + //xoops_message($this); |
|
| 82 | + unset($this->content); |
|
| 83 | + $this->encoding_convert($tags); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @return bool|string |
|
| 88 | - */ |
|
| 89 | - public function is_atom() |
|
| 90 | - { |
|
| 91 | - if (ATOM == $this->feed_type) { |
|
| 92 | - $this->feed_version = empty($this->feed_version) ? '0.3' : $this->feed_version; |
|
| 86 | + /** |
|
| 87 | + * @return bool|string |
|
| 88 | + */ |
|
| 89 | + public function is_atom() |
|
| 90 | + { |
|
| 91 | + if (ATOM == $this->feed_type) { |
|
| 92 | + $this->feed_version = empty($this->feed_version) ? '0.3' : $this->feed_version; |
|
| 93 | 93 | |
| 94 | - return $this->feed_version; |
|
| 95 | - } else { |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 98 | - } |
|
| 94 | + return $this->feed_version; |
|
| 95 | + } else { |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function normalize() |
|
| 101 | - { |
|
| 102 | - if ($this->is_atom()): |
|
| 103 | - if (empty($this->channel['tagline'])) { |
|
| 104 | - /* ATOM */ |
|
| 105 | - $this->channel['tagline'] = @$this->channel['subtitle']; |
|
| 106 | - unset($this->channel['subtitle']); |
|
| 107 | - } |
|
| 108 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 109 | - // ATOM time |
|
| 110 | - if ($date = @$this->items[$i]['modified']) { |
|
| 111 | - continue; |
|
| 112 | - } |
|
| 113 | - if (empty($date)) { |
|
| 114 | - $date = @$this->items[$i]['updated']; |
|
| 115 | - } |
|
| 116 | - if (empty($date)) { |
|
| 117 | - $date = @$this->items[$i]['issued']; |
|
| 118 | - } |
|
| 119 | - if (empty($date)) { |
|
| 120 | - $date = @$this->items[$i]['created']; |
|
| 121 | - } |
|
| 122 | - if (empty($date)) { |
|
| 123 | - $date = @$this->items[$i]['created']; |
|
| 124 | - } |
|
| 125 | - $this->items[$i]['modified'] = $date; |
|
| 126 | - } elseif ('1.0' !== $this->is_rss()): |
|
| 127 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 128 | - if ($date = @$this->items[$i]['pubdate']) { |
|
| 129 | - continue; |
|
| 130 | - } |
|
| 131 | - $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
| 132 | - } |
|
| 133 | - endif; |
|
| 134 | - parent::normalize(); |
|
| 135 | - /* ATOM */ |
|
| 136 | - if (empty($this->channel['language']) && !empty($this->channel['dc']['language'])) { |
|
| 137 | - $this->channel['language'] = $this->channel['dc']['language']; |
|
| 138 | - unset($this->channel['dc']['language']); |
|
| 139 | - } |
|
| 140 | - if (empty($this->channel['language']) |
|
| 141 | - && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
| 142 | - $this->channel['language'] = $match[1]; |
|
| 143 | - } |
|
| 144 | - if (empty($this->channel['language']) |
|
| 145 | - && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
| 146 | - $this->channel['language'] = $match[1]; |
|
| 147 | - } |
|
| 148 | - /* remove to avoid redundant encoding conversion */ |
|
| 149 | - if (!empty($this->channel['tagline'])) { |
|
| 150 | - unset($this->channel['tagline']); |
|
| 151 | - } |
|
| 100 | + public function normalize() |
|
| 101 | + { |
|
| 102 | + if ($this->is_atom()): |
|
| 103 | + if (empty($this->channel['tagline'])) { |
|
| 104 | + /* ATOM */ |
|
| 105 | + $this->channel['tagline'] = @$this->channel['subtitle']; |
|
| 106 | + unset($this->channel['subtitle']); |
|
| 107 | + } |
|
| 108 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 109 | + // ATOM time |
|
| 110 | + if ($date = @$this->items[$i]['modified']) { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 113 | + if (empty($date)) { |
|
| 114 | + $date = @$this->items[$i]['updated']; |
|
| 115 | + } |
|
| 116 | + if (empty($date)) { |
|
| 117 | + $date = @$this->items[$i]['issued']; |
|
| 118 | + } |
|
| 119 | + if (empty($date)) { |
|
| 120 | + $date = @$this->items[$i]['created']; |
|
| 121 | + } |
|
| 122 | + if (empty($date)) { |
|
| 123 | + $date = @$this->items[$i]['created']; |
|
| 124 | + } |
|
| 125 | + $this->items[$i]['modified'] = $date; |
|
| 126 | + } elseif ('1.0' !== $this->is_rss()): |
|
| 127 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 128 | + if ($date = @$this->items[$i]['pubdate']) { |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 131 | + $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
| 132 | + } |
|
| 133 | + endif; |
|
| 134 | + parent::normalize(); |
|
| 135 | + /* ATOM */ |
|
| 136 | + if (empty($this->channel['language']) && !empty($this->channel['dc']['language'])) { |
|
| 137 | + $this->channel['language'] = $this->channel['dc']['language']; |
|
| 138 | + unset($this->channel['dc']['language']); |
|
| 139 | + } |
|
| 140 | + if (empty($this->channel['language']) |
|
| 141 | + && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
| 142 | + $this->channel['language'] = $match[1]; |
|
| 143 | + } |
|
| 144 | + if (empty($this->channel['language']) |
|
| 145 | + && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
| 146 | + $this->channel['language'] = $match[1]; |
|
| 147 | + } |
|
| 148 | + /* remove to avoid redundant encoding conversion */ |
|
| 149 | + if (!empty($this->channel['tagline'])) { |
|
| 150 | + unset($this->channel['tagline']); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 154 | - if ($date_timestamp = @$this->items[$i]['date_timestamp']) { |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - if ($date_timestamp = @$this->items[$i]['pubdate']) { |
|
| 158 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 159 | - } elseif ($date_timestamp = @$this->items[$i]['dc']['date']) { |
|
| 160 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 161 | - } else { |
|
| 162 | - $this->items[$i]['date_timestamp'] = time(); |
|
| 163 | - } |
|
| 164 | - if (!is_numeric($this->items[$i]['date_timestamp'])) { |
|
| 165 | - if ($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
| 166 | - $this->items[$i]['date_timestamp'] = $date; |
|
| 167 | - } elseif ($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
| 168 | - $this->items[$i]['date_timestamp'] = $date; |
|
| 169 | - } |
|
| 170 | - } |
|
| 153 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 154 | + if ($date_timestamp = @$this->items[$i]['date_timestamp']) { |
|
| 155 | + continue; |
|
| 156 | + } |
|
| 157 | + if ($date_timestamp = @$this->items[$i]['pubdate']) { |
|
| 158 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 159 | + } elseif ($date_timestamp = @$this->items[$i]['dc']['date']) { |
|
| 160 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 161 | + } else { |
|
| 162 | + $this->items[$i]['date_timestamp'] = time(); |
|
| 163 | + } |
|
| 164 | + if (!is_numeric($this->items[$i]['date_timestamp'])) { |
|
| 165 | + if ($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
| 166 | + $this->items[$i]['date_timestamp'] = $date; |
|
| 167 | + } elseif ($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
| 168 | + $this->items[$i]['date_timestamp'] = $date; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /* remove to avoid redundant encoding conversion */ |
|
| 173 | - if (isset($this->items[$i]['summary'])) { |
|
| 174 | - unset($this->items[$i]['summary']); |
|
| 175 | - } |
|
| 176 | - if (isset($this->items[$i]['atom_content'])) { |
|
| 177 | - unset($this->items[$i]['atom_content']); |
|
| 178 | - } |
|
| 179 | - } |
|
| 172 | + /* remove to avoid redundant encoding conversion */ |
|
| 173 | + if (isset($this->items[$i]['summary'])) { |
|
| 174 | + unset($this->items[$i]['summary']); |
|
| 175 | + } |
|
| 176 | + if (isset($this->items[$i]['atom_content'])) { |
|
| 177 | + unset($this->items[$i]['atom_content']); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - return; |
|
| 182 | - } |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @param array $tags |
|
| 186 | - */ |
|
| 187 | - public function encoding_convert($tags = []) |
|
| 188 | - { |
|
| 189 | - if (empty($tags) || in_array('channel', $tags)) { |
|
| 190 | - $this->channel = $this->_encoding($this->channel); |
|
| 191 | - } |
|
| 192 | - if (empty($tags) || in_array('items', $tags)) { |
|
| 193 | - $this->items = $this->_encoding($this->items); |
|
| 194 | - } |
|
| 195 | - } |
|
| 184 | + /** |
|
| 185 | + * @param array $tags |
|
| 186 | + */ |
|
| 187 | + public function encoding_convert($tags = []) |
|
| 188 | + { |
|
| 189 | + if (empty($tags) || in_array('channel', $tags)) { |
|
| 190 | + $this->channel = $this->_encoding($this->channel); |
|
| 191 | + } |
|
| 192 | + if (empty($tags) || in_array('items', $tags)) { |
|
| 193 | + $this->items = $this->_encoding($this->items); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @param $val |
|
| 199 | - * @return array|mixed|string |
|
| 200 | - */ |
|
| 201 | - public function _encoding($val) |
|
| 202 | - { |
|
| 203 | - if (is_array($val)) { |
|
| 204 | - foreach (array_keys($val) as $key) { |
|
| 205 | - $val[$key] = $this->_encoding($val[$key]); |
|
| 206 | - } |
|
| 207 | - } else { |
|
| 208 | - $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
| 209 | - } |
|
| 197 | + /** |
|
| 198 | + * @param $val |
|
| 199 | + * @return array|mixed|string |
|
| 200 | + */ |
|
| 201 | + public function _encoding($val) |
|
| 202 | + { |
|
| 203 | + if (is_array($val)) { |
|
| 204 | + foreach (array_keys($val) as $key) { |
|
| 205 | + $val[$key] = $this->_encoding($val[$key]); |
|
| 206 | + } |
|
| 207 | + } else { |
|
| 208 | + $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - return $val; |
|
| 212 | - } |
|
| 211 | + return $val; |
|
| 212 | + } |
|
| 213 | 213 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @var mixed $pattern |
| 112 | 112 | * @var mixed $replacement |
| 113 | 113 | * |
| 114 | - * @return bool true on success |
|
| 114 | + * @return null|boolean true on success |
|
| 115 | 115 | */ |
| 116 | 116 | function planetParseClass($class_string, $pattern = '', $replacement = '') |
| 117 | 117 | { |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @var mixed $pattern |
| 148 | 148 | * @var mixed $replacement |
| 149 | 149 | * |
| 150 | - * @return bool true on success |
|
| 150 | + * @return null|boolean true on success |
|
| 151 | 151 | */ |
| 152 | 152 | function planetParseFunction($function_string, $pattern = '', $replacement = '') |
| 153 | 153 | { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | /** |
| 514 | 514 | * @param $url |
| 515 | - * @return bool|string |
|
| 515 | + * @return false|string |
|
| 516 | 516 | */ |
| 517 | 517 | function planet_fetch_fopen($url) |
| 518 | 518 | { |
@@ -33,523 +33,523 @@ |
||
| 33 | 33 | |
| 34 | 34 | $current_path = __FILE__; |
| 35 | 35 | if (DIRECTORY_SEPARATOR !== '/') { |
| 36 | - $current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 36 | + $current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
| 37 | 37 | } |
| 38 | 38 | $url_arr = explode('/', strstr($current_path, '/modules/')); |
| 39 | 39 | $GLOBALS['moddirname'] = $url_arr[2]; |
| 40 | 40 | |
| 41 | 41 | if (!defined('planet_FUNCTIONS')): |
| 42 | - define('planet_FUNCTIONS', 1); |
|
| 43 | - |
|
| 44 | - require XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/include/vars.php'; |
|
| 45 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 46 | - require_once XOOPS_ROOT_PATH . '/Frameworks/art/functions.php'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Function to display messages |
|
| 50 | - * |
|
| 51 | - * @var mixed $messages |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - function planetDisplayMessage($message) |
|
| 55 | - { |
|
| 56 | - return mod_message($message); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Function to parse arguments for a page according to $_SERVER['REQUEST_URI'] |
|
| 61 | - * |
|
| 62 | - * @var array $args_numeric array of numeric variable values |
|
| 63 | - * @var array $args array of indexed variables: name and value |
|
| 64 | - * @var array $args_string array of string variable values |
|
| 65 | - * |
|
| 66 | - * @return bool true on args parsed |
|
| 67 | - */ |
|
| 68 | - |
|
| 69 | - /* known issues: |
|
| 42 | + define('planet_FUNCTIONS', 1); |
|
| 43 | + |
|
| 44 | + require XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/include/vars.php'; |
|
| 45 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 46 | + require_once XOOPS_ROOT_PATH . '/Frameworks/art/functions.php'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Function to display messages |
|
| 50 | + * |
|
| 51 | + * @var mixed $messages |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + function planetDisplayMessage($message) |
|
| 55 | + { |
|
| 56 | + return mod_message($message); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Function to parse arguments for a page according to $_SERVER['REQUEST_URI'] |
|
| 61 | + * |
|
| 62 | + * @var array $args_numeric array of numeric variable values |
|
| 63 | + * @var array $args array of indexed variables: name and value |
|
| 64 | + * @var array $args_string array of string variable values |
|
| 65 | + * |
|
| 66 | + * @return bool true on args parsed |
|
| 67 | + */ |
|
| 68 | + |
|
| 69 | + /* known issues: |
|
| 70 | 70 | * - "/" in a string |
| 71 | 71 | * - "&" in a string |
| 72 | 72 | */ |
| 73 | - function planetParseArguments(&$args_numeric, &$args, &$args_string) |
|
| 74 | - { |
|
| 75 | - $args_abb = [ |
|
| 76 | - 'a' => 'article', |
|
| 77 | - 'b' => 'blog', |
|
| 78 | - 'c' => 'category', |
|
| 79 | - 'l' => 'list', |
|
| 80 | - 'o' => 'sort', |
|
| 81 | - 's' => 'start', |
|
| 82 | - 'u' => 'uid' |
|
| 83 | - ]; |
|
| 84 | - $args = []; |
|
| 85 | - $args_numeric = []; |
|
| 86 | - $args_string = []; |
|
| 87 | - if (preg_match("/[^\?]*\.php[\/|\?]([^\?]*)/i", Request::getUrl('REQUEST_URI', '', 'SERVER'), $matches)) { |
|
| 88 | - $vars = preg_split("/[\/|&]/", $matches[1]); |
|
| 89 | - $vars = array_map('trim', $vars); |
|
| 90 | - if (count($vars) > 0) { |
|
| 91 | - foreach ($vars as $var) { |
|
| 92 | - if (is_numeric($var)) { |
|
| 93 | - $args_numeric[] = $var; |
|
| 94 | - } elseif (false === strpos($var, '=')) { |
|
| 95 | - if (is_numeric(substr($var, 1))) { |
|
| 96 | - $args[$args_abb[strtolower($var{0})]] = (int)substr($var, 1); |
|
| 97 | - } else { |
|
| 98 | - $args_string[] = urldecode($var); |
|
| 99 | - } |
|
| 100 | - } else { |
|
| 101 | - parse_str($var, $args); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return (0 == count($args) + count($args_numeric) + count($args_string)) ? null : true; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Function to parse class prefix |
|
| 112 | - * |
|
| 113 | - * @var string $class_string string to be parsed |
|
| 114 | - * @var mixed $pattern |
|
| 115 | - * @var mixed $replacement |
|
| 116 | - * |
|
| 117 | - * @return bool true on success |
|
| 118 | - */ |
|
| 119 | - function planetParseClass($class_string, $pattern = '', $replacement = '') |
|
| 120 | - { |
|
| 121 | - if (empty($class_string)) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - $patterns = ["/\[CLASS_PREFIX\]/"]; |
|
| 125 | - $replacements = [ucfirst(strtolower($GLOBALS['moddirname']))]; |
|
| 126 | - if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
| 127 | - $pattern = [$pattern]; |
|
| 128 | - $replacement = [$replacement]; |
|
| 129 | - } |
|
| 130 | - if (is_array($pattern) && count($pattern) > 0) { |
|
| 131 | - $ii = 0; |
|
| 132 | - foreach ($pattern as $pat) { |
|
| 133 | - if (!in_array($pat, $patterns)) { |
|
| 134 | - $patterns[] = $pat; |
|
| 135 | - $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
|
| 136 | - } |
|
| 137 | - ++$ii; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - $class_string = preg_replace($patterns, $replacements, $class_string); |
|
| 141 | - eval($class_string); |
|
| 142 | - |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Function to parse function prefix |
|
| 148 | - * |
|
| 149 | - * @var string $function_string string to be parsed |
|
| 150 | - * @var mixed $pattern |
|
| 151 | - * @var mixed $replacement |
|
| 152 | - * |
|
| 153 | - * @return bool true on success |
|
| 154 | - */ |
|
| 155 | - function planetParseFunction($function_string, $pattern = '', $replacement = '') |
|
| 156 | - { |
|
| 157 | - if (empty($function_string)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - $patterns = ["/\[DIRNAME\]/", "/\[VAR_PREFIX\]/"]; |
|
| 161 | - $replacements = [$GLOBALS['moddirname'], $GLOBALS['VAR_PREFIX']]; |
|
| 162 | - if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
| 163 | - $pattern = [$pattern]; |
|
| 164 | - $replacement = [$replacement]; |
|
| 165 | - } |
|
| 166 | - if (is_array($pattern) && count($pattern) > 0) { |
|
| 167 | - $ii = 0; |
|
| 168 | - foreach ($pattern as $pat) { |
|
| 169 | - if (!in_array($pat, $patterns)) { |
|
| 170 | - $patterns[] = $pat; |
|
| 171 | - $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
|
| 172 | - } |
|
| 173 | - ++$ii; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - $function_string = preg_replace($patterns, $replacements, $function_string); |
|
| 177 | - eval($function_string); |
|
| 178 | - |
|
| 179 | - return true; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Function to convert UNIX time to formatted time string |
|
| 184 | - * @param $time |
|
| 185 | - * @param string $format |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - function planet_formatTimestamp($time, $format = '') |
|
| 189 | - { |
|
| 190 | - if (empty($time)) { |
|
| 191 | - return ''; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return formatTimestamp($time, $format); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Function to a list of user names associated with their user IDs |
|
| 199 | - * @param int $userid |
|
| 200 | - * @param int $usereal |
|
| 201 | - * @param bool $linked |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - function &planetGetUnameFromId($userid, $usereal = 0, $linked = false) |
|
| 205 | - { |
|
| 206 | - if (!is_array($userid)) { |
|
| 207 | - $userid = [$userid]; |
|
| 208 | - } |
|
| 209 | - $users =& mod_getUnameFromIds($userid, $usereal, $linked); |
|
| 210 | - |
|
| 211 | - return $users; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Function to parse links, links are delimited by link break, URL and title of a link are delimited by space |
|
| 216 | - * |
|
| 217 | - * @var string $text raw content |
|
| 218 | - * |
|
| 219 | - * @return array associative array of link url and title |
|
| 220 | - */ |
|
| 221 | - function &planetParseLinks($text) |
|
| 222 | - { |
|
| 223 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 224 | - $link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
|
| 225 | - $links = []; |
|
| 226 | - if (count($link_array) > 0) { |
|
| 227 | - foreach ($link_array as $link) { |
|
| 228 | - @list($url, $title) = array_map('trim', preg_split('/ /', $link, 2)); |
|
| 229 | - if (empty($url)) { |
|
| 230 | - continue; |
|
| 231 | - } |
|
| 232 | - //if(empty($title)) $title = $url; |
|
| 233 | - $links[] = ['url' => $url, 'title' => $myts->htmlSpecialChars($title)]; |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return $links; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $pagename |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - function planetGetTemplate($pagename) |
|
| 245 | - { |
|
| 246 | - return $GLOBALS['VAR_PREFIX'] . '_' . $pagename . '.tpl'; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param int $currentoption |
|
| 251 | - */ |
|
| 252 | - function planet_adminmenu($currentoption = -1) |
|
| 253 | - { |
|
| 254 | - loadModuleAdminMenu($currentoption, ''); |
|
| 255 | - |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Function to send a trackback |
|
| 261 | - * |
|
| 262 | - * @param $article |
|
| 263 | - * @param $comment |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - function planet_com_trackback(&$article, &$comment) |
|
| 267 | - { |
|
| 268 | - $blogHandler = xoops_getModuleHandler('blog', $GLOBALS['moddirname']); |
|
| 269 | - $blog_obj = $blogHandler->get($article->getVar('blog_id')); |
|
| 270 | - if (!$pattern = $blog_obj->getVar('blog_trackback')) { |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 273 | - @list($pat, $rep) = array_map('trim', preg_split("#[\s]+#", $pattern)); |
|
| 274 | - $trackback_url = preg_replace('#' . $pat . '#', $rep, $article_obj->getVar('art_link')); |
|
| 275 | - |
|
| 276 | - return planetTrackback($trackback_url, $article); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param $trackback_url |
|
| 281 | - * @param $article |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - function planetTrackback($trackback_url, $article) |
|
| 285 | - { |
|
| 286 | - global $myts, $xoopsConfig, $xoopsModule; |
|
| 287 | - /** @var Planet\Helper $helper */ |
|
| 288 | - $helper = Planet\Helper::getInstance(); |
|
| 289 | - |
|
| 290 | - $title = $article->getVar('art_title'); |
|
| 291 | - $excerpt = $article->getVar('art_content'); |
|
| 292 | - $blog_name = $xoopsConfig['sitename'] . '-' . $xoopsModule->getVar('name'); |
|
| 293 | - $title = xoops_utf8_encode($title); |
|
| 294 | - $excerpt = xoops_utf8_encode($excerpt); |
|
| 295 | - $blog_name = xoops_utf8_encode($blog_name); |
|
| 296 | - $charset = 'utf-8'; |
|
| 297 | - $title1 = urlencode($title); |
|
| 298 | - $excerpt1 = urlencode($excerpt); |
|
| 299 | - $name1 = urlencode($blog_name); |
|
| 300 | - $url = urlencode(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $article->getVar('art_id')); |
|
| 301 | - $query_string = "title=$title1&url=$url&blog_name=$name1&excerpt=$excerpt1&charset=$charset"; |
|
| 302 | - $trackback_url = parse_url($trackback_url); |
|
| 303 | - |
|
| 304 | - $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?' . $trackback_url['query'] : '') . " HTTP/1.0\r\n"; |
|
| 305 | - $http_request .= 'Host: ' . $trackback_url['host'] . "\r\n"; |
|
| 306 | - $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . $charset . "\r\n"; |
|
| 307 | - $http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n"; |
|
| 308 | - $http_request .= 'User-Agent: XOOPS Blogs/' . XOOPS_VERSION; |
|
| 309 | - $http_request .= "\r\n\r\n"; |
|
| 310 | - $http_request .= $query_string; |
|
| 311 | - if ('' == $trackback_url['port']) { |
|
| 312 | - $trackback_url['port'] = 80; |
|
| 313 | - } |
|
| 314 | - $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4); |
|
| 315 | - @fwrite($fs, $http_request); |
|
| 316 | - if ($helper->getConfig('do_debug')) { |
|
| 317 | - $debug_file = XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '_trackback.log'; |
|
| 318 | - $fr = "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"; |
|
| 319 | - $fr .= "CHARSET:$charset\n"; |
|
| 320 | - $fr .= "NAME:$blog_name\n"; |
|
| 321 | - $fr .= 'TITLE:' . $title . "\n"; |
|
| 322 | - $fr .= "EXCERPT:$excerpt\n\n"; |
|
| 323 | - while (!@feof($fs)) { |
|
| 324 | - $fr .= @fgets($fs, 4096); |
|
| 325 | - } |
|
| 326 | - $fr .= "\n\n"; |
|
| 327 | - |
|
| 328 | - if ($fp = fopen($debug_file, 'a')) { |
|
| 329 | - fwrite($fp, $fr); |
|
| 330 | - fclose($fp); |
|
| 331 | - } else { |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - @fclose($fs); |
|
| 335 | - |
|
| 336 | - return true; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Function to ping servers |
|
| 341 | - * @param $server |
|
| 342 | - * @param $id |
|
| 343 | - */ |
|
| 344 | - function planetGetPing($server, $id) |
|
| 345 | - { |
|
| 346 | - if (is_array($server)) { |
|
| 347 | - foreach ($server as $serv) { |
|
| 348 | - planetGetPing($serv, $id); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - require_once XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/class-IXR.php'; |
|
| 352 | - |
|
| 353 | - // using a timeout of 3 seconds should be enough to cover slow servers |
|
| 354 | - $client = new IXR_Client($server, false); |
|
| 355 | - $client->timeout = 3; |
|
| 356 | - $client->useragent .= ' -- XOOPS Article/' . XOOPS_VERSION; |
|
| 357 | - |
|
| 358 | - // when set to true, this outputs debug messages by itself |
|
| 359 | - $client->debug = false; |
|
| 360 | - |
|
| 361 | - $blogname = xoops_utf8_encode($GLOBALS['xoopsModule']->getVar('name')); |
|
| 362 | - $home = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/'; |
|
| 363 | - $rss2_url = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php' . URL_DELIMITER . 'rss2.0/' . $id; |
|
| 364 | - |
|
| 365 | - if (!$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url)) { // then try a normal ping |
|
| 366 | - $client->query('weblogUpdates.ping', $blogname, $home); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Function to respond to a trackback |
|
| 372 | - * @param int $error |
|
| 373 | - * @param string $error_message |
|
| 374 | - */ |
|
| 375 | - function planetRespondToTrackback($error = 0, $error_message = '') |
|
| 376 | - { |
|
| 377 | - $charset = 'utf-8'; |
|
| 378 | - $error_message = xoops_utf8_encode($error_message); |
|
| 379 | - header('Content-Type: text/xml; charset="' . $charset . '"'); |
|
| 380 | - if ($error) { |
|
| 381 | - echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
|
| 382 | - echo "<response>\n"; |
|
| 383 | - echo "<error>1</error>\n"; |
|
| 384 | - echo "<message>$error_message</message>\n"; |
|
| 385 | - echo '</response>'; |
|
| 386 | - die(); |
|
| 387 | - } else { |
|
| 388 | - echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
|
| 389 | - echo "<response>\n"; |
|
| 390 | - echo "<error>0</error>\n"; |
|
| 391 | - echo '</response>'; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Function to set a cookie with module-specified name |
|
| 397 | - * |
|
| 398 | - * using customized serialization method |
|
| 399 | - * @param $name |
|
| 400 | - * @param string $string |
|
| 401 | - * @param int $expire |
|
| 402 | - */ |
|
| 403 | - function planetSetCookie($name, $string = '', $expire = 0) |
|
| 404 | - { |
|
| 405 | - if (is_array($string)) { |
|
| 406 | - $value = []; |
|
| 407 | - foreach ($string as $key => $val) { |
|
| 408 | - $value[] = $key . '|' . $val; |
|
| 409 | - } |
|
| 410 | - $string = implode(',', $value); |
|
| 411 | - } |
|
| 412 | - setcookie($GLOBALS['VAR_PREFIX'] . $name, $string, (int)$expire, '/'); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param $name |
|
| 417 | - * @param bool $isArray |
|
| 418 | - * @return array|null |
|
| 419 | - */ |
|
| 420 | - function planetGetCookie($name, $isArray = false) |
|
| 421 | - { |
|
| 422 | - $value = isset($_COOKIE[$GLOBALS['VAR_PREFIX'] . $name]) ? $_COOKIE[$GLOBALS['VAR_PREFIX'] . $name] : null; |
|
| 423 | - if ($isArray) { |
|
| 424 | - $_value = $value ? explode(',', $value) : []; |
|
| 425 | - $value = []; |
|
| 426 | - if (count($_value) > 0) { |
|
| 427 | - foreach ($_value as $string) { |
|
| 428 | - $key = substr($string, 0, strpos($string, '|')); |
|
| 429 | - $val = substr($string, strpos($string, '|') + 1); |
|
| 430 | - $value[$key] = $val; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - unset($_value); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $value; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Function to filter text |
|
| 441 | - * |
|
| 442 | - * @param $document |
|
| 443 | - * @return string filtered text |
|
| 444 | - */ |
|
| 445 | - function &planetHtml2text(&$document) |
|
| 446 | - { |
|
| 447 | - $document = strip_tags($document); |
|
| 448 | - |
|
| 449 | - return $document; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - // Adapted from PMA_getIp() [phpmyadmin project] |
|
| 453 | - /** |
|
| 454 | - * @param bool $asString |
|
| 455 | - * @return mixed |
|
| 456 | - */ |
|
| 457 | - function planetGetIP($asString = false) |
|
| 458 | - { |
|
| 459 | - return mod_getIP($asString); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @param $url |
|
| 464 | - * @return bool|mixed|string |
|
| 465 | - */ |
|
| 466 | - function planetGetRemoteContent($url) |
|
| 467 | - { |
|
| 468 | - if ($data = planet_fetch_snoopy($url)) { |
|
| 469 | - return $data; |
|
| 470 | - } |
|
| 471 | - if ($data = planet_fetch_CURL($url)) { |
|
| 472 | - return $data; |
|
| 473 | - } |
|
| 474 | - if ($data = planet_fetch_fopen($url)) { |
|
| 475 | - return $data; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - return false; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param $url |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - function planet_fetch_snoopy($url) |
|
| 486 | - { |
|
| 487 | - require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; |
|
| 488 | - $snoopy = new Snoopy; |
|
| 489 | - $data = ''; |
|
| 490 | - if (@$snoopy->fetch($url)) { |
|
| 491 | - $data = is_array($snoopy->results) ? implode("\n", $snoopy->results) : $snoopy->results; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $data; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * @param $url |
|
| 499 | - * @return bool|mixed |
|
| 500 | - */ |
|
| 501 | - function planet_fetch_CURL($url) |
|
| 502 | - { |
|
| 503 | - if (!function_exists('curl_init')) { |
|
| 504 | - return false; |
|
| 505 | - } |
|
| 506 | - $ch = curl_init(); // initialize curl handle |
|
| 507 | - curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
|
| 508 | - curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
|
| 509 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
|
| 510 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable |
|
| 511 | - curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
|
| 512 | - $data = curl_exec($ch); // run the whole process |
|
| 513 | - curl_close($ch); |
|
| 514 | - |
|
| 515 | - return $data; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * @param $url |
|
| 520 | - * @return bool|string |
|
| 521 | - */ |
|
| 522 | - function planet_fetch_fopen($url) |
|
| 523 | - { |
|
| 524 | - if (!$fp = @fopen($url, 'r')) { |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - $data = ''; |
|
| 528 | - while (!feof($fp)) { |
|
| 529 | - $data .= fgets($fp, 1024); |
|
| 530 | - } |
|
| 531 | - fclose($fp); |
|
| 532 | - |
|
| 533 | - return $data; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * @param $haystack |
|
| 538 | - * @param $needle |
|
| 539 | - * @param int $offset |
|
| 540 | - * @return bool|int |
|
| 541 | - */ |
|
| 542 | - function planetStrrPos($haystack, $needle, $offset = 0) |
|
| 543 | - { |
|
| 544 | - if (5 == substr(PHP_VERSION, 0, 1)) { |
|
| 545 | - return strrpos($haystack, $needle, $offset); |
|
| 546 | - } |
|
| 547 | - $index = strpos(strrev($haystack), strrev($needle)); |
|
| 548 | - if (false === $index) { |
|
| 549 | - return false; |
|
| 550 | - } |
|
| 551 | - $index = strlen($haystack) - strlen($needle) - $index; |
|
| 552 | - |
|
| 553 | - return $index; |
|
| 554 | - } |
|
| 73 | + function planetParseArguments(&$args_numeric, &$args, &$args_string) |
|
| 74 | + { |
|
| 75 | + $args_abb = [ |
|
| 76 | + 'a' => 'article', |
|
| 77 | + 'b' => 'blog', |
|
| 78 | + 'c' => 'category', |
|
| 79 | + 'l' => 'list', |
|
| 80 | + 'o' => 'sort', |
|
| 81 | + 's' => 'start', |
|
| 82 | + 'u' => 'uid' |
|
| 83 | + ]; |
|
| 84 | + $args = []; |
|
| 85 | + $args_numeric = []; |
|
| 86 | + $args_string = []; |
|
| 87 | + if (preg_match("/[^\?]*\.php[\/|\?]([^\?]*)/i", Request::getUrl('REQUEST_URI', '', 'SERVER'), $matches)) { |
|
| 88 | + $vars = preg_split("/[\/|&]/", $matches[1]); |
|
| 89 | + $vars = array_map('trim', $vars); |
|
| 90 | + if (count($vars) > 0) { |
|
| 91 | + foreach ($vars as $var) { |
|
| 92 | + if (is_numeric($var)) { |
|
| 93 | + $args_numeric[] = $var; |
|
| 94 | + } elseif (false === strpos($var, '=')) { |
|
| 95 | + if (is_numeric(substr($var, 1))) { |
|
| 96 | + $args[$args_abb[strtolower($var{0})]] = (int)substr($var, 1); |
|
| 97 | + } else { |
|
| 98 | + $args_string[] = urldecode($var); |
|
| 99 | + } |
|
| 100 | + } else { |
|
| 101 | + parse_str($var, $args); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return (0 == count($args) + count($args_numeric) + count($args_string)) ? null : true; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Function to parse class prefix |
|
| 112 | + * |
|
| 113 | + * @var string $class_string string to be parsed |
|
| 114 | + * @var mixed $pattern |
|
| 115 | + * @var mixed $replacement |
|
| 116 | + * |
|
| 117 | + * @return bool true on success |
|
| 118 | + */ |
|
| 119 | + function planetParseClass($class_string, $pattern = '', $replacement = '') |
|
| 120 | + { |
|
| 121 | + if (empty($class_string)) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + $patterns = ["/\[CLASS_PREFIX\]/"]; |
|
| 125 | + $replacements = [ucfirst(strtolower($GLOBALS['moddirname']))]; |
|
| 126 | + if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
| 127 | + $pattern = [$pattern]; |
|
| 128 | + $replacement = [$replacement]; |
|
| 129 | + } |
|
| 130 | + if (is_array($pattern) && count($pattern) > 0) { |
|
| 131 | + $ii = 0; |
|
| 132 | + foreach ($pattern as $pat) { |
|
| 133 | + if (!in_array($pat, $patterns)) { |
|
| 134 | + $patterns[] = $pat; |
|
| 135 | + $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
|
| 136 | + } |
|
| 137 | + ++$ii; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + $class_string = preg_replace($patterns, $replacements, $class_string); |
|
| 141 | + eval($class_string); |
|
| 142 | + |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Function to parse function prefix |
|
| 148 | + * |
|
| 149 | + * @var string $function_string string to be parsed |
|
| 150 | + * @var mixed $pattern |
|
| 151 | + * @var mixed $replacement |
|
| 152 | + * |
|
| 153 | + * @return bool true on success |
|
| 154 | + */ |
|
| 155 | + function planetParseFunction($function_string, $pattern = '', $replacement = '') |
|
| 156 | + { |
|
| 157 | + if (empty($function_string)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + $patterns = ["/\[DIRNAME\]/", "/\[VAR_PREFIX\]/"]; |
|
| 161 | + $replacements = [$GLOBALS['moddirname'], $GLOBALS['VAR_PREFIX']]; |
|
| 162 | + if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
| 163 | + $pattern = [$pattern]; |
|
| 164 | + $replacement = [$replacement]; |
|
| 165 | + } |
|
| 166 | + if (is_array($pattern) && count($pattern) > 0) { |
|
| 167 | + $ii = 0; |
|
| 168 | + foreach ($pattern as $pat) { |
|
| 169 | + if (!in_array($pat, $patterns)) { |
|
| 170 | + $patterns[] = $pat; |
|
| 171 | + $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ''; |
|
| 172 | + } |
|
| 173 | + ++$ii; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + $function_string = preg_replace($patterns, $replacements, $function_string); |
|
| 177 | + eval($function_string); |
|
| 178 | + |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Function to convert UNIX time to formatted time string |
|
| 184 | + * @param $time |
|
| 185 | + * @param string $format |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + function planet_formatTimestamp($time, $format = '') |
|
| 189 | + { |
|
| 190 | + if (empty($time)) { |
|
| 191 | + return ''; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return formatTimestamp($time, $format); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Function to a list of user names associated with their user IDs |
|
| 199 | + * @param int $userid |
|
| 200 | + * @param int $usereal |
|
| 201 | + * @param bool $linked |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + function &planetGetUnameFromId($userid, $usereal = 0, $linked = false) |
|
| 205 | + { |
|
| 206 | + if (!is_array($userid)) { |
|
| 207 | + $userid = [$userid]; |
|
| 208 | + } |
|
| 209 | + $users =& mod_getUnameFromIds($userid, $usereal, $linked); |
|
| 210 | + |
|
| 211 | + return $users; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Function to parse links, links are delimited by link break, URL and title of a link are delimited by space |
|
| 216 | + * |
|
| 217 | + * @var string $text raw content |
|
| 218 | + * |
|
| 219 | + * @return array associative array of link url and title |
|
| 220 | + */ |
|
| 221 | + function &planetParseLinks($text) |
|
| 222 | + { |
|
| 223 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 224 | + $link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
|
| 225 | + $links = []; |
|
| 226 | + if (count($link_array) > 0) { |
|
| 227 | + foreach ($link_array as $link) { |
|
| 228 | + @list($url, $title) = array_map('trim', preg_split('/ /', $link, 2)); |
|
| 229 | + if (empty($url)) { |
|
| 230 | + continue; |
|
| 231 | + } |
|
| 232 | + //if(empty($title)) $title = $url; |
|
| 233 | + $links[] = ['url' => $url, 'title' => $myts->htmlSpecialChars($title)]; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return $links; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $pagename |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + function planetGetTemplate($pagename) |
|
| 245 | + { |
|
| 246 | + return $GLOBALS['VAR_PREFIX'] . '_' . $pagename . '.tpl'; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param int $currentoption |
|
| 251 | + */ |
|
| 252 | + function planet_adminmenu($currentoption = -1) |
|
| 253 | + { |
|
| 254 | + loadModuleAdminMenu($currentoption, ''); |
|
| 255 | + |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Function to send a trackback |
|
| 261 | + * |
|
| 262 | + * @param $article |
|
| 263 | + * @param $comment |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + function planet_com_trackback(&$article, &$comment) |
|
| 267 | + { |
|
| 268 | + $blogHandler = xoops_getModuleHandler('blog', $GLOBALS['moddirname']); |
|
| 269 | + $blog_obj = $blogHandler->get($article->getVar('blog_id')); |
|
| 270 | + if (!$pattern = $blog_obj->getVar('blog_trackback')) { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + @list($pat, $rep) = array_map('trim', preg_split("#[\s]+#", $pattern)); |
|
| 274 | + $trackback_url = preg_replace('#' . $pat . '#', $rep, $article_obj->getVar('art_link')); |
|
| 275 | + |
|
| 276 | + return planetTrackback($trackback_url, $article); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param $trackback_url |
|
| 281 | + * @param $article |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + function planetTrackback($trackback_url, $article) |
|
| 285 | + { |
|
| 286 | + global $myts, $xoopsConfig, $xoopsModule; |
|
| 287 | + /** @var Planet\Helper $helper */ |
|
| 288 | + $helper = Planet\Helper::getInstance(); |
|
| 289 | + |
|
| 290 | + $title = $article->getVar('art_title'); |
|
| 291 | + $excerpt = $article->getVar('art_content'); |
|
| 292 | + $blog_name = $xoopsConfig['sitename'] . '-' . $xoopsModule->getVar('name'); |
|
| 293 | + $title = xoops_utf8_encode($title); |
|
| 294 | + $excerpt = xoops_utf8_encode($excerpt); |
|
| 295 | + $blog_name = xoops_utf8_encode($blog_name); |
|
| 296 | + $charset = 'utf-8'; |
|
| 297 | + $title1 = urlencode($title); |
|
| 298 | + $excerpt1 = urlencode($excerpt); |
|
| 299 | + $name1 = urlencode($blog_name); |
|
| 300 | + $url = urlencode(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $article->getVar('art_id')); |
|
| 301 | + $query_string = "title=$title1&url=$url&blog_name=$name1&excerpt=$excerpt1&charset=$charset"; |
|
| 302 | + $trackback_url = parse_url($trackback_url); |
|
| 303 | + |
|
| 304 | + $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?' . $trackback_url['query'] : '') . " HTTP/1.0\r\n"; |
|
| 305 | + $http_request .= 'Host: ' . $trackback_url['host'] . "\r\n"; |
|
| 306 | + $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . $charset . "\r\n"; |
|
| 307 | + $http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n"; |
|
| 308 | + $http_request .= 'User-Agent: XOOPS Blogs/' . XOOPS_VERSION; |
|
| 309 | + $http_request .= "\r\n\r\n"; |
|
| 310 | + $http_request .= $query_string; |
|
| 311 | + if ('' == $trackback_url['port']) { |
|
| 312 | + $trackback_url['port'] = 80; |
|
| 313 | + } |
|
| 314 | + $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4); |
|
| 315 | + @fwrite($fs, $http_request); |
|
| 316 | + if ($helper->getConfig('do_debug')) { |
|
| 317 | + $debug_file = XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '_trackback.log'; |
|
| 318 | + $fr = "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"; |
|
| 319 | + $fr .= "CHARSET:$charset\n"; |
|
| 320 | + $fr .= "NAME:$blog_name\n"; |
|
| 321 | + $fr .= 'TITLE:' . $title . "\n"; |
|
| 322 | + $fr .= "EXCERPT:$excerpt\n\n"; |
|
| 323 | + while (!@feof($fs)) { |
|
| 324 | + $fr .= @fgets($fs, 4096); |
|
| 325 | + } |
|
| 326 | + $fr .= "\n\n"; |
|
| 327 | + |
|
| 328 | + if ($fp = fopen($debug_file, 'a')) { |
|
| 329 | + fwrite($fp, $fr); |
|
| 330 | + fclose($fp); |
|
| 331 | + } else { |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + @fclose($fs); |
|
| 335 | + |
|
| 336 | + return true; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Function to ping servers |
|
| 341 | + * @param $server |
|
| 342 | + * @param $id |
|
| 343 | + */ |
|
| 344 | + function planetGetPing($server, $id) |
|
| 345 | + { |
|
| 346 | + if (is_array($server)) { |
|
| 347 | + foreach ($server as $serv) { |
|
| 348 | + planetGetPing($serv, $id); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + require_once XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/class-IXR.php'; |
|
| 352 | + |
|
| 353 | + // using a timeout of 3 seconds should be enough to cover slow servers |
|
| 354 | + $client = new IXR_Client($server, false); |
|
| 355 | + $client->timeout = 3; |
|
| 356 | + $client->useragent .= ' -- XOOPS Article/' . XOOPS_VERSION; |
|
| 357 | + |
|
| 358 | + // when set to true, this outputs debug messages by itself |
|
| 359 | + $client->debug = false; |
|
| 360 | + |
|
| 361 | + $blogname = xoops_utf8_encode($GLOBALS['xoopsModule']->getVar('name')); |
|
| 362 | + $home = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/'; |
|
| 363 | + $rss2_url = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php' . URL_DELIMITER . 'rss2.0/' . $id; |
|
| 364 | + |
|
| 365 | + if (!$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url)) { // then try a normal ping |
|
| 366 | + $client->query('weblogUpdates.ping', $blogname, $home); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Function to respond to a trackback |
|
| 372 | + * @param int $error |
|
| 373 | + * @param string $error_message |
|
| 374 | + */ |
|
| 375 | + function planetRespondToTrackback($error = 0, $error_message = '') |
|
| 376 | + { |
|
| 377 | + $charset = 'utf-8'; |
|
| 378 | + $error_message = xoops_utf8_encode($error_message); |
|
| 379 | + header('Content-Type: text/xml; charset="' . $charset . '"'); |
|
| 380 | + if ($error) { |
|
| 381 | + echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
|
| 382 | + echo "<response>\n"; |
|
| 383 | + echo "<error>1</error>\n"; |
|
| 384 | + echo "<message>$error_message</message>\n"; |
|
| 385 | + echo '</response>'; |
|
| 386 | + die(); |
|
| 387 | + } else { |
|
| 388 | + echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; |
|
| 389 | + echo "<response>\n"; |
|
| 390 | + echo "<error>0</error>\n"; |
|
| 391 | + echo '</response>'; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Function to set a cookie with module-specified name |
|
| 397 | + * |
|
| 398 | + * using customized serialization method |
|
| 399 | + * @param $name |
|
| 400 | + * @param string $string |
|
| 401 | + * @param int $expire |
|
| 402 | + */ |
|
| 403 | + function planetSetCookie($name, $string = '', $expire = 0) |
|
| 404 | + { |
|
| 405 | + if (is_array($string)) { |
|
| 406 | + $value = []; |
|
| 407 | + foreach ($string as $key => $val) { |
|
| 408 | + $value[] = $key . '|' . $val; |
|
| 409 | + } |
|
| 410 | + $string = implode(',', $value); |
|
| 411 | + } |
|
| 412 | + setcookie($GLOBALS['VAR_PREFIX'] . $name, $string, (int)$expire, '/'); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param $name |
|
| 417 | + * @param bool $isArray |
|
| 418 | + * @return array|null |
|
| 419 | + */ |
|
| 420 | + function planetGetCookie($name, $isArray = false) |
|
| 421 | + { |
|
| 422 | + $value = isset($_COOKIE[$GLOBALS['VAR_PREFIX'] . $name]) ? $_COOKIE[$GLOBALS['VAR_PREFIX'] . $name] : null; |
|
| 423 | + if ($isArray) { |
|
| 424 | + $_value = $value ? explode(',', $value) : []; |
|
| 425 | + $value = []; |
|
| 426 | + if (count($_value) > 0) { |
|
| 427 | + foreach ($_value as $string) { |
|
| 428 | + $key = substr($string, 0, strpos($string, '|')); |
|
| 429 | + $val = substr($string, strpos($string, '|') + 1); |
|
| 430 | + $value[$key] = $val; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + unset($_value); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $value; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Function to filter text |
|
| 441 | + * |
|
| 442 | + * @param $document |
|
| 443 | + * @return string filtered text |
|
| 444 | + */ |
|
| 445 | + function &planetHtml2text(&$document) |
|
| 446 | + { |
|
| 447 | + $document = strip_tags($document); |
|
| 448 | + |
|
| 449 | + return $document; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + // Adapted from PMA_getIp() [phpmyadmin project] |
|
| 453 | + /** |
|
| 454 | + * @param bool $asString |
|
| 455 | + * @return mixed |
|
| 456 | + */ |
|
| 457 | + function planetGetIP($asString = false) |
|
| 458 | + { |
|
| 459 | + return mod_getIP($asString); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @param $url |
|
| 464 | + * @return bool|mixed|string |
|
| 465 | + */ |
|
| 466 | + function planetGetRemoteContent($url) |
|
| 467 | + { |
|
| 468 | + if ($data = planet_fetch_snoopy($url)) { |
|
| 469 | + return $data; |
|
| 470 | + } |
|
| 471 | + if ($data = planet_fetch_CURL($url)) { |
|
| 472 | + return $data; |
|
| 473 | + } |
|
| 474 | + if ($data = planet_fetch_fopen($url)) { |
|
| 475 | + return $data; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + return false; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param $url |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + function planet_fetch_snoopy($url) |
|
| 486 | + { |
|
| 487 | + require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; |
|
| 488 | + $snoopy = new Snoopy; |
|
| 489 | + $data = ''; |
|
| 490 | + if (@$snoopy->fetch($url)) { |
|
| 491 | + $data = is_array($snoopy->results) ? implode("\n", $snoopy->results) : $snoopy->results; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $data; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * @param $url |
|
| 499 | + * @return bool|mixed |
|
| 500 | + */ |
|
| 501 | + function planet_fetch_CURL($url) |
|
| 502 | + { |
|
| 503 | + if (!function_exists('curl_init')) { |
|
| 504 | + return false; |
|
| 505 | + } |
|
| 506 | + $ch = curl_init(); // initialize curl handle |
|
| 507 | + curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
|
| 508 | + curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
|
| 509 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
|
| 510 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable |
|
| 511 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
|
| 512 | + $data = curl_exec($ch); // run the whole process |
|
| 513 | + curl_close($ch); |
|
| 514 | + |
|
| 515 | + return $data; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * @param $url |
|
| 520 | + * @return bool|string |
|
| 521 | + */ |
|
| 522 | + function planet_fetch_fopen($url) |
|
| 523 | + { |
|
| 524 | + if (!$fp = @fopen($url, 'r')) { |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + $data = ''; |
|
| 528 | + while (!feof($fp)) { |
|
| 529 | + $data .= fgets($fp, 1024); |
|
| 530 | + } |
|
| 531 | + fclose($fp); |
|
| 532 | + |
|
| 533 | + return $data; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * @param $haystack |
|
| 538 | + * @param $needle |
|
| 539 | + * @param int $offset |
|
| 540 | + * @return bool|int |
|
| 541 | + */ |
|
| 542 | + function planetStrrPos($haystack, $needle, $offset = 0) |
|
| 543 | + { |
|
| 544 | + if (5 == substr(PHP_VERSION, 0, 1)) { |
|
| 545 | + return strrpos($haystack, $needle, $offset); |
|
| 546 | + } |
|
| 547 | + $index = strpos(strrev($haystack), strrev($needle)); |
|
| 548 | + if (false === $index) { |
|
| 549 | + return false; |
|
| 550 | + } |
|
| 551 | + $index = strlen($haystack) - strlen($needle) - $index; |
|
| 552 | + |
|
| 553 | + return $index; |
|
| 554 | + } |
|
| 555 | 555 | endif; |