@@ -109,7 +109,6 @@ |
||
109 | 109 | /** |
110 | 110 | * get summary of the article |
111 | 111 | * |
112 | - * @param bool $actionOnEmpty flag for truncating content if summary is empty |
|
113 | 112 | * @return string |
114 | 113 | */ |
115 | 114 | function &getSummary($length = 0) |
@@ -48,73 +48,73 @@ discard block |
||
48 | 48 | |
49 | 49 | class Barticle extends ArtObject |
50 | 50 | { |
51 | - /** |
|
52 | - * Constructor |
|
53 | - * |
|
54 | - * @param int $id ID of the article |
|
55 | - */ |
|
56 | - function Barticle($id = null) |
|
57 | - { |
|
58 | - $this->ArtObject(); |
|
59 | - $this->table = planet_DB_prefix("article"); |
|
60 | - $this->initVar("art_id", XOBJ_DTYPE_INT, null, false); |
|
61 | - $this->initVar("blog_id", XOBJ_DTYPE_INT, 0, true); |
|
51 | + /** |
|
52 | + * Constructor |
|
53 | + * |
|
54 | + * @param int $id ID of the article |
|
55 | + */ |
|
56 | + function Barticle($id = null) |
|
57 | + { |
|
58 | + $this->ArtObject(); |
|
59 | + $this->table = planet_DB_prefix("article"); |
|
60 | + $this->initVar("art_id", XOBJ_DTYPE_INT, null, false); |
|
61 | + $this->initVar("blog_id", XOBJ_DTYPE_INT, 0, true); |
|
62 | 62 | |
63 | - $this->initVar("art_title", XOBJ_DTYPE_TXTBOX, ""); |
|
64 | - $this->initVar("art_content", XOBJ_DTYPE_TXTAREA, ""); |
|
65 | - $this->initVar("art_link", XOBJ_DTYPE_TXTBOX, ""); |
|
66 | - $this->initVar("art_time", XOBJ_DTYPE_INT, 0); |
|
67 | - $this->initVar("art_author", XOBJ_DTYPE_TXTBOX, ""); |
|
63 | + $this->initVar("art_title", XOBJ_DTYPE_TXTBOX, ""); |
|
64 | + $this->initVar("art_content", XOBJ_DTYPE_TXTAREA, ""); |
|
65 | + $this->initVar("art_link", XOBJ_DTYPE_TXTBOX, ""); |
|
66 | + $this->initVar("art_time", XOBJ_DTYPE_INT, 0); |
|
67 | + $this->initVar("art_author", XOBJ_DTYPE_TXTBOX, ""); |
|
68 | 68 | |
69 | - $this->initVar("art_views", XOBJ_DTYPE_INT, 0); |
|
70 | - $this->initVar("art_rating", XOBJ_DTYPE_INT, 0); |
|
71 | - $this->initVar("art_rates", XOBJ_DTYPE_INT, 0); |
|
72 | - $this->initVar("art_comments", XOBJ_DTYPE_INT, 0); |
|
69 | + $this->initVar("art_views", XOBJ_DTYPE_INT, 0); |
|
70 | + $this->initVar("art_rating", XOBJ_DTYPE_INT, 0); |
|
71 | + $this->initVar("art_rates", XOBJ_DTYPE_INT, 0); |
|
72 | + $this->initVar("art_comments", XOBJ_DTYPE_INT, 0); |
|
73 | 73 | |
74 | - $this->initVar("dohtml", XOBJ_DTYPE_INT, 1); |
|
75 | - $this->initVar("dosmiley", XOBJ_DTYPE_INT, 1); |
|
76 | - $this->initVar("doxcode", XOBJ_DTYPE_INT, 1); |
|
77 | - $this->initVar("doimage", XOBJ_DTYPE_INT, 1); |
|
78 | - $this->initVar("dobr", XOBJ_DTYPE_INT, 1); |
|
79 | - } |
|
74 | + $this->initVar("dohtml", XOBJ_DTYPE_INT, 1); |
|
75 | + $this->initVar("dosmiley", XOBJ_DTYPE_INT, 1); |
|
76 | + $this->initVar("doxcode", XOBJ_DTYPE_INT, 1); |
|
77 | + $this->initVar("doimage", XOBJ_DTYPE_INT, 1); |
|
78 | + $this->initVar("dobr", XOBJ_DTYPE_INT, 1); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * get title of the article |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - function getTitle() |
|
87 | - { |
|
88 | - $title = $this->getVar("art_title"); |
|
81 | + /** |
|
82 | + * get title of the article |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + function getTitle() |
|
87 | + { |
|
88 | + $title = $this->getVar("art_title"); |
|
89 | 89 | return $title; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * get formatted publish time of the article |
|
94 | - * |
|
95 | - * {@link Config} |
|
96 | - * |
|
97 | - * @param string $format format of time |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - function getTime($format = "c") |
|
101 | - { |
|
102 | - $time = $this->getVar("art_time"); |
|
103 | - if(empty($time)) $time = time(); |
|
104 | - $time = planet_formatTimestamp($time, $format); |
|
92 | + /** |
|
93 | + * get formatted publish time of the article |
|
94 | + * |
|
95 | + * {@link Config} |
|
96 | + * |
|
97 | + * @param string $format format of time |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + function getTime($format = "c") |
|
101 | + { |
|
102 | + $time = $this->getVar("art_time"); |
|
103 | + if(empty($time)) $time = time(); |
|
104 | + $time = planet_formatTimestamp($time, $format); |
|
105 | 105 | return $time; |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * get summary of the article |
|
111 | - * |
|
112 | - * @param bool $actionOnEmpty flag for truncating content if summary is empty |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - function &getSummary($length = 0) |
|
116 | - { |
|
117 | - $content = $this->getVar("art_content"); |
|
109 | + /** |
|
110 | + * get summary of the article |
|
111 | + * |
|
112 | + * @param bool $actionOnEmpty flag for truncating content if summary is empty |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + function &getSummary($length = 0) |
|
116 | + { |
|
117 | + $content = $this->getVar("art_content"); |
|
118 | 118 | $summary = planet_html2text($content); |
119 | 119 | if(empty($length)){ |
120 | 120 | $length = $GLOBALS["xoopsModuleConfig"]["display_summary"]; |
@@ -122,29 +122,29 @@ discard block |
||
122 | 122 | if(!empty($length)){ |
123 | 123 | $summary = xoops_substr($summary, 0, $length); |
124 | 124 | } |
125 | - return $summary; |
|
126 | - } |
|
125 | + return $summary; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * get rating average of the article |
|
131 | - * |
|
132 | - * @param int $decimals decimal length |
|
133 | - * @return numeric |
|
134 | - */ |
|
135 | - function getRatingAverage($decimals = 1) |
|
136 | - { |
|
137 | - $ave=3; |
|
138 | - if($this->getVar("art_rates")){ |
|
139 | - $ave = number_format($this->getVar("art_rating")/$this->getVar("art_rates"),$decimals); |
|
140 | - } |
|
141 | - return $ave; |
|
142 | - } |
|
129 | + /** |
|
130 | + * get rating average of the article |
|
131 | + * |
|
132 | + * @param int $decimals decimal length |
|
133 | + * @return numeric |
|
134 | + */ |
|
135 | + function getRatingAverage($decimals = 1) |
|
136 | + { |
|
137 | + $ave=3; |
|
138 | + if($this->getVar("art_rates")){ |
|
139 | + $ave = number_format($this->getVar("art_rating")/$this->getVar("art_rates"),$decimals); |
|
140 | + } |
|
141 | + return $ave; |
|
142 | + } |
|
143 | 143 | |
144 | - function getStar() |
|
145 | - { |
|
146 | - return $this->getRatingAverage(0); |
|
147 | - } |
|
144 | + function getStar() |
|
145 | + { |
|
146 | + return $this->getRatingAverage(0); |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | endif; |
150 | 150 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * {@link XoopsObject} |
46 | 46 | **/ |
47 | -if(!class_exists("Barticle")): |
|
47 | +if (!class_exists("Barticle")): |
|
48 | 48 | |
49 | 49 | class Barticle extends ArtObject |
50 | 50 | { |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | function getTime($format = "c") |
101 | 101 | { |
102 | 102 | $time = $this->getVar("art_time"); |
103 | - if(empty($time)) $time = time(); |
|
103 | + if (empty($time)) $time = time(); |
|
104 | 104 | $time = planet_formatTimestamp($time, $format); |
105 | 105 | return $time; |
106 | 106 | } |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | { |
117 | 117 | $content = $this->getVar("art_content"); |
118 | 118 | $summary = planet_html2text($content); |
119 | - if(empty($length)){ |
|
119 | + if (empty($length)) { |
|
120 | 120 | $length = $GLOBALS["xoopsModuleConfig"]["display_summary"]; |
121 | 121 | } |
122 | - if(!empty($length)){ |
|
122 | + if (!empty($length)) { |
|
123 | 123 | $summary = xoops_substr($summary, 0, $length); |
124 | 124 | } |
125 | 125 | return $summary; |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | function getRatingAverage($decimals = 1) |
136 | 136 | { |
137 | - $ave=3; |
|
138 | - if($this->getVar("art_rates")){ |
|
139 | - $ave = number_format($this->getVar("art_rating")/$this->getVar("art_rates"),$decimals); |
|
137 | + $ave = 3; |
|
138 | + if ($this->getVar("art_rates")) { |
|
139 | + $ave = number_format($this->getVar("art_rating")/$this->getVar("art_rates"), $decimals); |
|
140 | 140 | } |
141 | 141 | return $ave; |
142 | 142 | } |
@@ -100,7 +100,9 @@ |
||
100 | 100 | function getTime($format = "c") |
101 | 101 | { |
102 | 102 | $time = $this->getVar("art_time"); |
103 | - if(empty($time)) $time = time(); |
|
103 | + if(empty($time)) { |
|
104 | + $time = time(); |
|
105 | + } |
|
104 | 106 | $time = planet_formatTimestamp($time, $format); |
105 | 107 | return $time; |
106 | 108 | } |
@@ -650,6 +650,10 @@ discard block |
||
650 | 650 | |
651 | 651 | class IXR_Base64 { |
652 | 652 | var $data; |
653 | + |
|
654 | + /** |
|
655 | + * @param string $data |
|
656 | + */ |
|
653 | 657 | function IXR_Base64($data) { |
654 | 658 | $this->data = $data; |
655 | 659 | } |
@@ -694,6 +698,13 @@ discard block |
||
694 | 698 | 'Returns a documentation string for the specified method' |
695 | 699 | ); |
696 | 700 | } |
701 | + |
|
702 | + /** |
|
703 | + * @param string $method |
|
704 | + * @param string $callback |
|
705 | + * @param string[] $args |
|
706 | + * @param string $help |
|
707 | + */ |
|
697 | 708 | function addCallback($method, $callback, $args, $help) { |
698 | 709 | $this->callbacks[$method] = $callback; |
699 | 710 | $this->signatures[$method] = $args; |
@@ -11,305 +11,305 @@ discard block |
||
11 | 11 | |
12 | 12 | |
13 | 13 | class IXR_Value { |
14 | - var $data; |
|
15 | - var $type; |
|
16 | - function IXR_Value ($data, $type = false) { |
|
17 | - $this->data = $data; |
|
18 | - if (!$type) { |
|
19 | - $type = $this->calculateType(); |
|
20 | - } |
|
21 | - $this->type = $type; |
|
22 | - if ($type == 'struct') { |
|
23 | - /* Turn all the values in the array in to new IXR_Value objects */ |
|
24 | - foreach ($this->data as $key => $value) { |
|
25 | - $this->data[$key] = new IXR_Value($value); |
|
26 | - } |
|
27 | - } |
|
28 | - if ($type == 'array') { |
|
29 | - for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
30 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
31 | - } |
|
32 | - } |
|
33 | - } |
|
34 | - function calculateType() { |
|
35 | - if ($this->data === true || $this->data === false) { |
|
36 | - return 'boolean'; |
|
37 | - } |
|
38 | - if (is_integer($this->data)) { |
|
39 | - return 'int'; |
|
40 | - } |
|
41 | - if (is_double($this->data)) { |
|
42 | - return 'double'; |
|
43 | - } |
|
44 | - // Deal with IXR object types base64 and date |
|
45 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
46 | - return 'date'; |
|
47 | - } |
|
48 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
49 | - return 'base64'; |
|
50 | - } |
|
51 | - // If it is a normal PHP object convert it in to a struct |
|
52 | - if (is_object($this->data)) { |
|
14 | + var $data; |
|
15 | + var $type; |
|
16 | + function IXR_Value ($data, $type = false) { |
|
17 | + $this->data = $data; |
|
18 | + if (!$type) { |
|
19 | + $type = $this->calculateType(); |
|
20 | + } |
|
21 | + $this->type = $type; |
|
22 | + if ($type == 'struct') { |
|
23 | + /* Turn all the values in the array in to new IXR_Value objects */ |
|
24 | + foreach ($this->data as $key => $value) { |
|
25 | + $this->data[$key] = new IXR_Value($value); |
|
26 | + } |
|
27 | + } |
|
28 | + if ($type == 'array') { |
|
29 | + for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
30 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
31 | + } |
|
32 | + } |
|
33 | + } |
|
34 | + function calculateType() { |
|
35 | + if ($this->data === true || $this->data === false) { |
|
36 | + return 'boolean'; |
|
37 | + } |
|
38 | + if (is_integer($this->data)) { |
|
39 | + return 'int'; |
|
40 | + } |
|
41 | + if (is_double($this->data)) { |
|
42 | + return 'double'; |
|
43 | + } |
|
44 | + // Deal with IXR object types base64 and date |
|
45 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
46 | + return 'date'; |
|
47 | + } |
|
48 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
49 | + return 'base64'; |
|
50 | + } |
|
51 | + // If it is a normal PHP object convert it in to a struct |
|
52 | + if (is_object($this->data)) { |
|
53 | 53 | |
54 | - $this->data = get_object_vars($this->data); |
|
55 | - return 'struct'; |
|
56 | - } |
|
57 | - if (!is_array($this->data)) { |
|
58 | - return 'string'; |
|
59 | - } |
|
60 | - /* We have an array - is it an array or a struct ? */ |
|
61 | - if ($this->isStruct($this->data)) { |
|
62 | - return 'struct'; |
|
63 | - } else { |
|
64 | - return 'array'; |
|
65 | - } |
|
66 | - } |
|
67 | - function getXml() { |
|
68 | - /* Return XML for this value */ |
|
69 | - switch ($this->type) { |
|
70 | - case 'boolean': |
|
71 | - return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
72 | - break; |
|
73 | - case 'int': |
|
74 | - return '<int>'.$this->data.'</int>'; |
|
75 | - break; |
|
76 | - case 'double': |
|
77 | - return '<double>'.$this->data.'</double>'; |
|
78 | - break; |
|
79 | - case 'string': |
|
80 | - return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
81 | - break; |
|
82 | - case 'array': |
|
83 | - $return = '<array><data>'."\n"; |
|
84 | - foreach ($this->data as $item) { |
|
85 | - $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
86 | - } |
|
87 | - $return .= '</data></array>'; |
|
88 | - return $return; |
|
89 | - break; |
|
90 | - case 'struct': |
|
91 | - $return = '<struct>'."\n"; |
|
92 | - foreach ($this->data as $name => $value) { |
|
93 | - $return .= " <member><name>$name</name><value>"; |
|
94 | - $return .= $value->getXml()."</value></member>\n"; |
|
95 | - } |
|
96 | - $return .= '</struct>'; |
|
97 | - return $return; |
|
98 | - break; |
|
99 | - case 'date': |
|
100 | - case 'base64': |
|
101 | - return $this->data->getXml(); |
|
102 | - break; |
|
103 | - } |
|
104 | - return false; |
|
105 | - } |
|
106 | - function isStruct($array) { |
|
107 | - /* Nasty function to check if an array is a struct or not */ |
|
108 | - $expected = 0; |
|
109 | - foreach ($array as $key => $value) { |
|
110 | - if ((string)$key != (string)$expected) { |
|
111 | - return true; |
|
112 | - } |
|
113 | - $expected++; |
|
114 | - } |
|
115 | - return false; |
|
116 | - } |
|
54 | + $this->data = get_object_vars($this->data); |
|
55 | + return 'struct'; |
|
56 | + } |
|
57 | + if (!is_array($this->data)) { |
|
58 | + return 'string'; |
|
59 | + } |
|
60 | + /* We have an array - is it an array or a struct ? */ |
|
61 | + if ($this->isStruct($this->data)) { |
|
62 | + return 'struct'; |
|
63 | + } else { |
|
64 | + return 'array'; |
|
65 | + } |
|
66 | + } |
|
67 | + function getXml() { |
|
68 | + /* Return XML for this value */ |
|
69 | + switch ($this->type) { |
|
70 | + case 'boolean': |
|
71 | + return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
72 | + break; |
|
73 | + case 'int': |
|
74 | + return '<int>'.$this->data.'</int>'; |
|
75 | + break; |
|
76 | + case 'double': |
|
77 | + return '<double>'.$this->data.'</double>'; |
|
78 | + break; |
|
79 | + case 'string': |
|
80 | + return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
81 | + break; |
|
82 | + case 'array': |
|
83 | + $return = '<array><data>'."\n"; |
|
84 | + foreach ($this->data as $item) { |
|
85 | + $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
86 | + } |
|
87 | + $return .= '</data></array>'; |
|
88 | + return $return; |
|
89 | + break; |
|
90 | + case 'struct': |
|
91 | + $return = '<struct>'."\n"; |
|
92 | + foreach ($this->data as $name => $value) { |
|
93 | + $return .= " <member><name>$name</name><value>"; |
|
94 | + $return .= $value->getXml()."</value></member>\n"; |
|
95 | + } |
|
96 | + $return .= '</struct>'; |
|
97 | + return $return; |
|
98 | + break; |
|
99 | + case 'date': |
|
100 | + case 'base64': |
|
101 | + return $this->data->getXml(); |
|
102 | + break; |
|
103 | + } |
|
104 | + return false; |
|
105 | + } |
|
106 | + function isStruct($array) { |
|
107 | + /* Nasty function to check if an array is a struct or not */ |
|
108 | + $expected = 0; |
|
109 | + foreach ($array as $key => $value) { |
|
110 | + if ((string)$key != (string)$expected) { |
|
111 | + return true; |
|
112 | + } |
|
113 | + $expected++; |
|
114 | + } |
|
115 | + return false; |
|
116 | + } |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
120 | 120 | class IXR_Message { |
121 | - var $message; |
|
122 | - var $messageType; // methodCall / methodResponse / fault |
|
123 | - var $faultCode; |
|
124 | - var $faultString; |
|
125 | - var $methodName; |
|
126 | - var $params; |
|
127 | - // Current variable stacks |
|
128 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
129 | - var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
130 | - var $_currentStructName = array(); // A stack as well |
|
131 | - var $_param; |
|
132 | - var $_value; |
|
133 | - var $_currentTag; |
|
134 | - var $_currentTagContents; |
|
135 | - // The XML parser |
|
136 | - var $_parser; |
|
137 | - function IXR_Message ($message) { |
|
138 | - $this->message = $message; |
|
139 | - } |
|
140 | - function parse() { |
|
141 | - // first remove the XML declaration |
|
142 | - $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); |
|
143 | - if (trim($this->message) == '') { |
|
144 | - return false; |
|
145 | - } |
|
146 | - $this->_parser = xml_parser_create(); |
|
147 | - // Set XML parser to take the case of tags in to account |
|
148 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
149 | - // Set XML parser callback functions |
|
150 | - xml_set_object($this->_parser, $this); |
|
151 | - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
152 | - xml_set_character_data_handler($this->_parser, 'cdata'); |
|
153 | - if (!xml_parse($this->_parser, $this->message)) { |
|
154 | - /* die(sprintf('XML error: %s at line %d', |
|
121 | + var $message; |
|
122 | + var $messageType; // methodCall / methodResponse / fault |
|
123 | + var $faultCode; |
|
124 | + var $faultString; |
|
125 | + var $methodName; |
|
126 | + var $params; |
|
127 | + // Current variable stacks |
|
128 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
129 | + var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
130 | + var $_currentStructName = array(); // A stack as well |
|
131 | + var $_param; |
|
132 | + var $_value; |
|
133 | + var $_currentTag; |
|
134 | + var $_currentTagContents; |
|
135 | + // The XML parser |
|
136 | + var $_parser; |
|
137 | + function IXR_Message ($message) { |
|
138 | + $this->message = $message; |
|
139 | + } |
|
140 | + function parse() { |
|
141 | + // first remove the XML declaration |
|
142 | + $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); |
|
143 | + if (trim($this->message) == '') { |
|
144 | + return false; |
|
145 | + } |
|
146 | + $this->_parser = xml_parser_create(); |
|
147 | + // Set XML parser to take the case of tags in to account |
|
148 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
149 | + // Set XML parser callback functions |
|
150 | + xml_set_object($this->_parser, $this); |
|
151 | + xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
152 | + xml_set_character_data_handler($this->_parser, 'cdata'); |
|
153 | + if (!xml_parse($this->_parser, $this->message)) { |
|
154 | + /* die(sprintf('XML error: %s at line %d', |
|
155 | 155 | xml_error_string(xml_get_error_code($this->_parser)), |
156 | 156 | xml_get_current_line_number($this->_parser))); */ |
157 | - return false; |
|
158 | - } |
|
159 | - xml_parser_free($this->_parser); |
|
160 | - // Grab the error messages, if any |
|
161 | - if ($this->messageType == 'fault') { |
|
162 | - $this->faultCode = $this->params[0]['faultCode']; |
|
163 | - $this->faultString = $this->params[0]['faultString']; |
|
164 | - } |
|
165 | - return true; |
|
166 | - } |
|
167 | - function tag_open($parser, $tag, $attr) { |
|
168 | - $this->currentTag = $tag; |
|
169 | - switch($tag) { |
|
170 | - case 'methodCall': |
|
171 | - case 'methodResponse': |
|
172 | - case 'fault': |
|
173 | - $this->messageType = $tag; |
|
174 | - break; |
|
175 | - /* Deal with stacks of arrays and structs */ |
|
176 | - case 'data': // data is to all intents and puposes more interesting than array |
|
177 | - $this->_arraystructstypes[] = 'array'; |
|
178 | - $this->_arraystructs[] = array(); |
|
179 | - break; |
|
180 | - case 'struct': |
|
181 | - $this->_arraystructstypes[] = 'struct'; |
|
182 | - $this->_arraystructs[] = array(); |
|
183 | - break; |
|
184 | - } |
|
185 | - } |
|
186 | - function cdata($parser, $cdata) { |
|
187 | - $this->_currentTagContents .= $cdata; |
|
188 | - } |
|
189 | - function tag_close($parser, $tag) { |
|
190 | - $valueFlag = false; |
|
191 | - switch($tag) { |
|
192 | - case 'int': |
|
193 | - case 'i4': |
|
194 | - $value = (int)trim($this->_currentTagContents); |
|
195 | - $this->_currentTagContents = ''; |
|
196 | - $valueFlag = true; |
|
197 | - break; |
|
198 | - case 'double': |
|
199 | - $value = (double)trim($this->_currentTagContents); |
|
200 | - $this->_currentTagContents = ''; |
|
201 | - $valueFlag = true; |
|
202 | - break; |
|
203 | - case 'string': |
|
204 | - $value = (string)trim($this->_currentTagContents); |
|
205 | - $this->_currentTagContents = ''; |
|
206 | - $valueFlag = true; |
|
207 | - break; |
|
208 | - case 'dateTime.iso8601': |
|
209 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
210 | - // $value = $iso->getTimestamp(); |
|
211 | - $this->_currentTagContents = ''; |
|
212 | - $valueFlag = true; |
|
213 | - break; |
|
214 | - case 'value': |
|
215 | - // "If no type is indicated, the type is string." |
|
216 | - if (trim($this->_currentTagContents) != '') { |
|
217 | - $value = (string)$this->_currentTagContents; |
|
218 | - $this->_currentTagContents = ''; |
|
219 | - $valueFlag = true; |
|
220 | - } |
|
221 | - break; |
|
222 | - case 'boolean': |
|
223 | - $value = (boolean)trim($this->_currentTagContents); |
|
224 | - $this->_currentTagContents = ''; |
|
225 | - $valueFlag = true; |
|
226 | - break; |
|
227 | - case 'base64': |
|
228 | - $value = base64_decode( trim($this->_currentTagContents) ); |
|
229 | - $this->_currentTagContents = ''; |
|
230 | - $valueFlag = true; |
|
231 | - break; |
|
232 | - /* Deal with stacks of arrays and structs */ |
|
233 | - case 'data': |
|
234 | - case 'struct': |
|
235 | - $value = array_pop($this->_arraystructs); |
|
236 | - array_pop($this->_arraystructstypes); |
|
237 | - $valueFlag = true; |
|
238 | - break; |
|
239 | - case 'member': |
|
240 | - array_pop($this->_currentStructName); |
|
241 | - break; |
|
242 | - case 'name': |
|
243 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
244 | - $this->_currentTagContents = ''; |
|
245 | - break; |
|
246 | - case 'methodName': |
|
247 | - $this->methodName = trim($this->_currentTagContents); |
|
248 | - $this->_currentTagContents = ''; |
|
249 | - break; |
|
250 | - } |
|
251 | - if ($valueFlag) { |
|
252 | - /* |
|
157 | + return false; |
|
158 | + } |
|
159 | + xml_parser_free($this->_parser); |
|
160 | + // Grab the error messages, if any |
|
161 | + if ($this->messageType == 'fault') { |
|
162 | + $this->faultCode = $this->params[0]['faultCode']; |
|
163 | + $this->faultString = $this->params[0]['faultString']; |
|
164 | + } |
|
165 | + return true; |
|
166 | + } |
|
167 | + function tag_open($parser, $tag, $attr) { |
|
168 | + $this->currentTag = $tag; |
|
169 | + switch($tag) { |
|
170 | + case 'methodCall': |
|
171 | + case 'methodResponse': |
|
172 | + case 'fault': |
|
173 | + $this->messageType = $tag; |
|
174 | + break; |
|
175 | + /* Deal with stacks of arrays and structs */ |
|
176 | + case 'data': // data is to all intents and puposes more interesting than array |
|
177 | + $this->_arraystructstypes[] = 'array'; |
|
178 | + $this->_arraystructs[] = array(); |
|
179 | + break; |
|
180 | + case 'struct': |
|
181 | + $this->_arraystructstypes[] = 'struct'; |
|
182 | + $this->_arraystructs[] = array(); |
|
183 | + break; |
|
184 | + } |
|
185 | + } |
|
186 | + function cdata($parser, $cdata) { |
|
187 | + $this->_currentTagContents .= $cdata; |
|
188 | + } |
|
189 | + function tag_close($parser, $tag) { |
|
190 | + $valueFlag = false; |
|
191 | + switch($tag) { |
|
192 | + case 'int': |
|
193 | + case 'i4': |
|
194 | + $value = (int)trim($this->_currentTagContents); |
|
195 | + $this->_currentTagContents = ''; |
|
196 | + $valueFlag = true; |
|
197 | + break; |
|
198 | + case 'double': |
|
199 | + $value = (double)trim($this->_currentTagContents); |
|
200 | + $this->_currentTagContents = ''; |
|
201 | + $valueFlag = true; |
|
202 | + break; |
|
203 | + case 'string': |
|
204 | + $value = (string)trim($this->_currentTagContents); |
|
205 | + $this->_currentTagContents = ''; |
|
206 | + $valueFlag = true; |
|
207 | + break; |
|
208 | + case 'dateTime.iso8601': |
|
209 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
210 | + // $value = $iso->getTimestamp(); |
|
211 | + $this->_currentTagContents = ''; |
|
212 | + $valueFlag = true; |
|
213 | + break; |
|
214 | + case 'value': |
|
215 | + // "If no type is indicated, the type is string." |
|
216 | + if (trim($this->_currentTagContents) != '') { |
|
217 | + $value = (string)$this->_currentTagContents; |
|
218 | + $this->_currentTagContents = ''; |
|
219 | + $valueFlag = true; |
|
220 | + } |
|
221 | + break; |
|
222 | + case 'boolean': |
|
223 | + $value = (boolean)trim($this->_currentTagContents); |
|
224 | + $this->_currentTagContents = ''; |
|
225 | + $valueFlag = true; |
|
226 | + break; |
|
227 | + case 'base64': |
|
228 | + $value = base64_decode( trim($this->_currentTagContents) ); |
|
229 | + $this->_currentTagContents = ''; |
|
230 | + $valueFlag = true; |
|
231 | + break; |
|
232 | + /* Deal with stacks of arrays and structs */ |
|
233 | + case 'data': |
|
234 | + case 'struct': |
|
235 | + $value = array_pop($this->_arraystructs); |
|
236 | + array_pop($this->_arraystructstypes); |
|
237 | + $valueFlag = true; |
|
238 | + break; |
|
239 | + case 'member': |
|
240 | + array_pop($this->_currentStructName); |
|
241 | + break; |
|
242 | + case 'name': |
|
243 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
244 | + $this->_currentTagContents = ''; |
|
245 | + break; |
|
246 | + case 'methodName': |
|
247 | + $this->methodName = trim($this->_currentTagContents); |
|
248 | + $this->_currentTagContents = ''; |
|
249 | + break; |
|
250 | + } |
|
251 | + if ($valueFlag) { |
|
252 | + /* |
|
253 | 253 | if (!is_array($value) && !is_object($value)) { |
254 | 254 | $value = trim($value); |
255 | 255 | } |
256 | 256 | */ |
257 | - if (count($this->_arraystructs) > 0) { |
|
258 | - // Add value to struct or array |
|
259 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
260 | - // Add to struct |
|
261 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
262 | - } else { |
|
263 | - // Add to array |
|
264 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
265 | - } |
|
266 | - } else { |
|
267 | - // Just add as a paramater |
|
268 | - $this->params[] = $value; |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
257 | + if (count($this->_arraystructs) > 0) { |
|
258 | + // Add value to struct or array |
|
259 | + if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
260 | + // Add to struct |
|
261 | + $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
262 | + } else { |
|
263 | + // Add to array |
|
264 | + $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
265 | + } |
|
266 | + } else { |
|
267 | + // Just add as a paramater |
|
268 | + $this->params[] = $value; |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | |
275 | 275 | class IXR_Server { |
276 | - var $data; |
|
277 | - var $callbacks = array(); |
|
278 | - var $message; |
|
279 | - var $capabilities; |
|
280 | - function IXR_Server($callbacks = false, $data = false) { |
|
281 | - $this->setCapabilities(); |
|
282 | - if ($callbacks) { |
|
283 | - $this->callbacks = $callbacks; |
|
284 | - } |
|
285 | - $this->setCallbacks(); |
|
286 | - $this->serve($data); |
|
287 | - } |
|
288 | - function serve($data = false) { |
|
289 | - if (!$data) { |
|
290 | - global $HTTP_RAW_POST_DATA; |
|
291 | - if (!$HTTP_RAW_POST_DATA) { |
|
292 | - die('XML-RPC server accepts POST requests only.'); |
|
293 | - } |
|
294 | - $data = $HTTP_RAW_POST_DATA; |
|
295 | - } |
|
296 | - $this->message = new IXR_Message($data); |
|
297 | - if (!$this->message->parse()) { |
|
298 | - $this->error(-32700, 'parse error. not well formed'); |
|
299 | - } |
|
300 | - if ($this->message->messageType != 'methodCall') { |
|
301 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
302 | - } |
|
303 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
304 | - // Is the result an error? |
|
305 | - if (is_a($result, 'IXR_Error')) { |
|
306 | - $this->error($result); |
|
307 | - } |
|
308 | - // Encode the result |
|
309 | - $r = new IXR_Value($result); |
|
310 | - $resultxml = $r->getXml(); |
|
311 | - // Create the XML |
|
312 | - $xml = <<<EOD |
|
276 | + var $data; |
|
277 | + var $callbacks = array(); |
|
278 | + var $message; |
|
279 | + var $capabilities; |
|
280 | + function IXR_Server($callbacks = false, $data = false) { |
|
281 | + $this->setCapabilities(); |
|
282 | + if ($callbacks) { |
|
283 | + $this->callbacks = $callbacks; |
|
284 | + } |
|
285 | + $this->setCallbacks(); |
|
286 | + $this->serve($data); |
|
287 | + } |
|
288 | + function serve($data = false) { |
|
289 | + if (!$data) { |
|
290 | + global $HTTP_RAW_POST_DATA; |
|
291 | + if (!$HTTP_RAW_POST_DATA) { |
|
292 | + die('XML-RPC server accepts POST requests only.'); |
|
293 | + } |
|
294 | + $data = $HTTP_RAW_POST_DATA; |
|
295 | + } |
|
296 | + $this->message = new IXR_Message($data); |
|
297 | + if (!$this->message->parse()) { |
|
298 | + $this->error(-32700, 'parse error. not well formed'); |
|
299 | + } |
|
300 | + if ($this->message->messageType != 'methodCall') { |
|
301 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
302 | + } |
|
303 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
304 | + // Is the result an error? |
|
305 | + if (is_a($result, 'IXR_Error')) { |
|
306 | + $this->error($result); |
|
307 | + } |
|
308 | + // Encode the result |
|
309 | + $r = new IXR_Value($result); |
|
310 | + $resultxml = $r->getXml(); |
|
311 | + // Create the XML |
|
312 | + $xml = <<<EOD |
|
313 | 313 | <methodResponse> |
314 | 314 | <params> |
315 | 315 | <param> |
@@ -321,265 +321,265 @@ discard block |
||
321 | 321 | </methodResponse> |
322 | 322 | |
323 | 323 | EOD; |
324 | - // Send it |
|
325 | - $this->output($xml); |
|
326 | - } |
|
327 | - function call($methodname, $args) { |
|
328 | - if (!$this->hasMethod($methodname)) { |
|
329 | - return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
330 | - } |
|
331 | - $method = $this->callbacks[$methodname]; |
|
332 | - // Perform the callback and send the response |
|
333 | - if (count($args) == 1) { |
|
334 | - // If only one paramater just send that instead of the whole array |
|
335 | - $args = $args[0]; |
|
336 | - } |
|
337 | - // Are we dealing with a function or a method? |
|
338 | - if (substr($method, 0, 5) == 'this:') { |
|
339 | - // It's a class method - check it exists |
|
340 | - $method = substr($method, 5); |
|
341 | - if (!method_exists($this, $method)) { |
|
342 | - return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
343 | - } |
|
344 | - // Call the method |
|
345 | - $result = $this->$method($args); |
|
346 | - } else { |
|
347 | - // It's a function - does it exist? |
|
348 | - if (is_array($method)) { |
|
349 | - if (!method_exists($method[0], $method[1])) { |
|
350 | - return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
351 | - } |
|
352 | - } else if (!function_exists($method)) { |
|
353 | - return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
354 | - } |
|
355 | - // Call the function |
|
356 | - $result = call_user_func($method, $args); |
|
357 | - } |
|
358 | - return $result; |
|
359 | - } |
|
324 | + // Send it |
|
325 | + $this->output($xml); |
|
326 | + } |
|
327 | + function call($methodname, $args) { |
|
328 | + if (!$this->hasMethod($methodname)) { |
|
329 | + return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
330 | + } |
|
331 | + $method = $this->callbacks[$methodname]; |
|
332 | + // Perform the callback and send the response |
|
333 | + if (count($args) == 1) { |
|
334 | + // If only one paramater just send that instead of the whole array |
|
335 | + $args = $args[0]; |
|
336 | + } |
|
337 | + // Are we dealing with a function or a method? |
|
338 | + if (substr($method, 0, 5) == 'this:') { |
|
339 | + // It's a class method - check it exists |
|
340 | + $method = substr($method, 5); |
|
341 | + if (!method_exists($this, $method)) { |
|
342 | + return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
343 | + } |
|
344 | + // Call the method |
|
345 | + $result = $this->$method($args); |
|
346 | + } else { |
|
347 | + // It's a function - does it exist? |
|
348 | + if (is_array($method)) { |
|
349 | + if (!method_exists($method[0], $method[1])) { |
|
350 | + return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
351 | + } |
|
352 | + } else if (!function_exists($method)) { |
|
353 | + return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
354 | + } |
|
355 | + // Call the function |
|
356 | + $result = call_user_func($method, $args); |
|
357 | + } |
|
358 | + return $result; |
|
359 | + } |
|
360 | 360 | |
361 | - function error($error, $message = false) { |
|
362 | - // Accepts either an error object or an error code and message |
|
363 | - if ($message && !is_object($error)) { |
|
364 | - $error = new IXR_Error($error, $message); |
|
365 | - } |
|
366 | - $this->output($error->getXml()); |
|
367 | - } |
|
368 | - function output($xml) { |
|
369 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
370 | - $length = strlen($xml); |
|
371 | - header('Connection: close'); |
|
372 | - header('Content-Length: '.$length); |
|
373 | - header('Content-Type: text/xml'); |
|
374 | - header('Date: '.date('r')); |
|
375 | - echo $xml; |
|
376 | - exit; |
|
377 | - } |
|
378 | - function hasMethod($method) { |
|
379 | - return in_array($method, array_keys($this->callbacks)); |
|
380 | - } |
|
381 | - function setCapabilities() { |
|
382 | - // Initialises capabilities array |
|
383 | - $this->capabilities = array( |
|
384 | - 'xmlrpc' => array( |
|
385 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
386 | - 'specVersion' => 1 |
|
387 | - ), |
|
388 | - 'faults_interop' => array( |
|
389 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
390 | - 'specVersion' => 20010516 |
|
391 | - ), |
|
392 | - 'system.multicall' => array( |
|
393 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
394 | - 'specVersion' => 1 |
|
395 | - ), |
|
396 | - ); |
|
397 | - } |
|
398 | - function getCapabilities($args) { |
|
399 | - return $this->capabilities; |
|
400 | - } |
|
401 | - function setCallbacks() { |
|
402 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
403 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
404 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
405 | - } |
|
406 | - function listMethods($args) { |
|
407 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
408 | - // methods are listed before server defined methods |
|
409 | - return array_reverse(array_keys($this->callbacks)); |
|
410 | - } |
|
411 | - function multiCall($methodcalls) { |
|
412 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
413 | - $return = array(); |
|
414 | - foreach ($methodcalls as $call) { |
|
415 | - $method = $call['methodName']; |
|
416 | - $params = $call['params']; |
|
417 | - if ($method == 'system.multicall') { |
|
418 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
419 | - } else { |
|
420 | - $result = $this->call($method, $params); |
|
421 | - } |
|
422 | - if (is_a($result, 'IXR_Error')) { |
|
423 | - $return[] = array( |
|
424 | - 'faultCode' => $result->code, |
|
425 | - 'faultString' => $result->message |
|
426 | - ); |
|
427 | - } else { |
|
428 | - $return[] = array($result); |
|
429 | - } |
|
430 | - } |
|
431 | - return $return; |
|
432 | - } |
|
361 | + function error($error, $message = false) { |
|
362 | + // Accepts either an error object or an error code and message |
|
363 | + if ($message && !is_object($error)) { |
|
364 | + $error = new IXR_Error($error, $message); |
|
365 | + } |
|
366 | + $this->output($error->getXml()); |
|
367 | + } |
|
368 | + function output($xml) { |
|
369 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
370 | + $length = strlen($xml); |
|
371 | + header('Connection: close'); |
|
372 | + header('Content-Length: '.$length); |
|
373 | + header('Content-Type: text/xml'); |
|
374 | + header('Date: '.date('r')); |
|
375 | + echo $xml; |
|
376 | + exit; |
|
377 | + } |
|
378 | + function hasMethod($method) { |
|
379 | + return in_array($method, array_keys($this->callbacks)); |
|
380 | + } |
|
381 | + function setCapabilities() { |
|
382 | + // Initialises capabilities array |
|
383 | + $this->capabilities = array( |
|
384 | + 'xmlrpc' => array( |
|
385 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
386 | + 'specVersion' => 1 |
|
387 | + ), |
|
388 | + 'faults_interop' => array( |
|
389 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
390 | + 'specVersion' => 20010516 |
|
391 | + ), |
|
392 | + 'system.multicall' => array( |
|
393 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
394 | + 'specVersion' => 1 |
|
395 | + ), |
|
396 | + ); |
|
397 | + } |
|
398 | + function getCapabilities($args) { |
|
399 | + return $this->capabilities; |
|
400 | + } |
|
401 | + function setCallbacks() { |
|
402 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
403 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
404 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
405 | + } |
|
406 | + function listMethods($args) { |
|
407 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
408 | + // methods are listed before server defined methods |
|
409 | + return array_reverse(array_keys($this->callbacks)); |
|
410 | + } |
|
411 | + function multiCall($methodcalls) { |
|
412 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
413 | + $return = array(); |
|
414 | + foreach ($methodcalls as $call) { |
|
415 | + $method = $call['methodName']; |
|
416 | + $params = $call['params']; |
|
417 | + if ($method == 'system.multicall') { |
|
418 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
419 | + } else { |
|
420 | + $result = $this->call($method, $params); |
|
421 | + } |
|
422 | + if (is_a($result, 'IXR_Error')) { |
|
423 | + $return[] = array( |
|
424 | + 'faultCode' => $result->code, |
|
425 | + 'faultString' => $result->message |
|
426 | + ); |
|
427 | + } else { |
|
428 | + $return[] = array($result); |
|
429 | + } |
|
430 | + } |
|
431 | + return $return; |
|
432 | + } |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | class IXR_Request { |
436 | - var $method; |
|
437 | - var $args; |
|
438 | - var $xml; |
|
439 | - function IXR_Request($method, $args) { |
|
440 | - $this->method = $method; |
|
441 | - $this->args = $args; |
|
442 | - $this->xml = <<<EOD |
|
436 | + var $method; |
|
437 | + var $args; |
|
438 | + var $xml; |
|
439 | + function IXR_Request($method, $args) { |
|
440 | + $this->method = $method; |
|
441 | + $this->args = $args; |
|
442 | + $this->xml = <<<EOD |
|
443 | 443 | <?xml version="1.0"?> |
444 | 444 | <methodCall> |
445 | 445 | <methodName>{$this->method}</methodName> |
446 | 446 | <params> |
447 | 447 | |
448 | 448 | EOD; |
449 | - foreach ($this->args as $arg) { |
|
450 | - $this->xml .= '<param><value>'; |
|
451 | - $v = new IXR_Value($arg); |
|
452 | - $this->xml .= $v->getXml(); |
|
453 | - $this->xml .= "</value></param>\n"; |
|
454 | - } |
|
455 | - $this->xml .= '</params></methodCall>'; |
|
456 | - } |
|
457 | - function getLength() { |
|
458 | - return strlen($this->xml); |
|
459 | - } |
|
460 | - function getXml() { |
|
461 | - return $this->xml; |
|
462 | - } |
|
449 | + foreach ($this->args as $arg) { |
|
450 | + $this->xml .= '<param><value>'; |
|
451 | + $v = new IXR_Value($arg); |
|
452 | + $this->xml .= $v->getXml(); |
|
453 | + $this->xml .= "</value></param>\n"; |
|
454 | + } |
|
455 | + $this->xml .= '</params></methodCall>'; |
|
456 | + } |
|
457 | + function getLength() { |
|
458 | + return strlen($this->xml); |
|
459 | + } |
|
460 | + function getXml() { |
|
461 | + return $this->xml; |
|
462 | + } |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | |
466 | 466 | class IXR_Client { |
467 | - var $server; |
|
468 | - var $port; |
|
469 | - var $path; |
|
470 | - var $useragent; |
|
471 | - var $response; |
|
472 | - var $timeout; |
|
473 | - var $vendor = ''; |
|
474 | - var $message = false; |
|
475 | - var $debug = false; |
|
476 | - // Storage place for an error message |
|
477 | - var $error = false; |
|
478 | - function IXR_Client($server, $path = false, $port = 80, $timeout = 30, $vendor = '') { |
|
479 | - if (!$path) { |
|
480 | - // Assume we have been given a URL instead |
|
481 | - $bits = parse_url($server); |
|
482 | - $this->server = $bits['host']; |
|
483 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
484 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
485 | - // Make absolutely sure we have a path |
|
486 | - if (!$this->path) { |
|
487 | - $this->path = '/'; |
|
488 | - } |
|
489 | - } else { |
|
490 | - $this->server = $server; |
|
491 | - $this->path = $path; |
|
492 | - $this->port = $port; |
|
493 | - $this->timeout = $timeout; |
|
494 | - } |
|
495 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
496 | - } |
|
497 | - function query() { |
|
498 | - $args = func_get_args(); |
|
499 | - $method = array_shift($args); |
|
500 | - $request = new IXR_Request($method, $args); |
|
501 | - $length = $request->getLength(); |
|
502 | - $xml = $request->getXml(); |
|
503 | - $r = "\r\n"; |
|
504 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
505 | - $request .= "Host: {$this->server}$r"; |
|
506 | - $request .= "Content-Type: text/xml$r"; |
|
507 | - $request .= "User-Agent: {$this->useragent}$r"; |
|
508 | - $request .= "Content-length: {$length}$r$r"; |
|
509 | - $request .= $xml; |
|
510 | - // Now send the request |
|
511 | - if ($this->debug) { |
|
512 | - echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
513 | - } |
|
514 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
515 | - if (!$fp) { |
|
516 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
517 | - return false; |
|
518 | - } |
|
519 | - fputs($fp, $request); |
|
520 | - $contents = ''; |
|
521 | - $gotFirstLine = false; |
|
522 | - $gettingHeaders = true; |
|
523 | - while (!feof($fp)) { |
|
524 | - $line = fgets($fp, 4096); |
|
525 | - if (!$gotFirstLine) { |
|
526 | - // Check line for '200' |
|
527 | - if (strstr($line, '200') === false) { |
|
528 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
529 | - return false; |
|
530 | - } |
|
531 | - $gotFirstLine = true; |
|
532 | - } |
|
533 | - if (trim($line) == '') { |
|
534 | - $gettingHeaders = false; |
|
535 | - } |
|
536 | - if (!$gettingHeaders) { |
|
537 | - $contents .= trim($line)."\n"; |
|
538 | - } |
|
539 | - } |
|
540 | - if ($this->debug) { |
|
541 | - echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n"; |
|
542 | - } |
|
543 | - // Now parse what we've got back |
|
544 | - $this->message = new IXR_Message($contents); |
|
545 | - if (!$this->message->parse()) { |
|
546 | - // XML error |
|
547 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
548 | - return false; |
|
549 | - } |
|
550 | - // Is the message a fault? |
|
551 | - if ($this->message->messageType == 'fault') { |
|
552 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
553 | - return false; |
|
554 | - } |
|
555 | - // Message must be OK |
|
556 | - return true; |
|
557 | - } |
|
558 | - function getResponse() { |
|
559 | - // methodResponses can only have one param - return that |
|
560 | - return $this->message->params[0]; |
|
561 | - } |
|
562 | - function isError() { |
|
563 | - return (is_object($this->error)); |
|
564 | - } |
|
565 | - function getErrorCode() { |
|
566 | - return $this->error->code; |
|
567 | - } |
|
568 | - function getErrorMessage() { |
|
569 | - return $this->error->message; |
|
570 | - } |
|
467 | + var $server; |
|
468 | + var $port; |
|
469 | + var $path; |
|
470 | + var $useragent; |
|
471 | + var $response; |
|
472 | + var $timeout; |
|
473 | + var $vendor = ''; |
|
474 | + var $message = false; |
|
475 | + var $debug = false; |
|
476 | + // Storage place for an error message |
|
477 | + var $error = false; |
|
478 | + function IXR_Client($server, $path = false, $port = 80, $timeout = 30, $vendor = '') { |
|
479 | + if (!$path) { |
|
480 | + // Assume we have been given a URL instead |
|
481 | + $bits = parse_url($server); |
|
482 | + $this->server = $bits['host']; |
|
483 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
484 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
485 | + // Make absolutely sure we have a path |
|
486 | + if (!$this->path) { |
|
487 | + $this->path = '/'; |
|
488 | + } |
|
489 | + } else { |
|
490 | + $this->server = $server; |
|
491 | + $this->path = $path; |
|
492 | + $this->port = $port; |
|
493 | + $this->timeout = $timeout; |
|
494 | + } |
|
495 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
496 | + } |
|
497 | + function query() { |
|
498 | + $args = func_get_args(); |
|
499 | + $method = array_shift($args); |
|
500 | + $request = new IXR_Request($method, $args); |
|
501 | + $length = $request->getLength(); |
|
502 | + $xml = $request->getXml(); |
|
503 | + $r = "\r\n"; |
|
504 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
505 | + $request .= "Host: {$this->server}$r"; |
|
506 | + $request .= "Content-Type: text/xml$r"; |
|
507 | + $request .= "User-Agent: {$this->useragent}$r"; |
|
508 | + $request .= "Content-length: {$length}$r$r"; |
|
509 | + $request .= $xml; |
|
510 | + // Now send the request |
|
511 | + if ($this->debug) { |
|
512 | + echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
513 | + } |
|
514 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
515 | + if (!$fp) { |
|
516 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
517 | + return false; |
|
518 | + } |
|
519 | + fputs($fp, $request); |
|
520 | + $contents = ''; |
|
521 | + $gotFirstLine = false; |
|
522 | + $gettingHeaders = true; |
|
523 | + while (!feof($fp)) { |
|
524 | + $line = fgets($fp, 4096); |
|
525 | + if (!$gotFirstLine) { |
|
526 | + // Check line for '200' |
|
527 | + if (strstr($line, '200') === false) { |
|
528 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
529 | + return false; |
|
530 | + } |
|
531 | + $gotFirstLine = true; |
|
532 | + } |
|
533 | + if (trim($line) == '') { |
|
534 | + $gettingHeaders = false; |
|
535 | + } |
|
536 | + if (!$gettingHeaders) { |
|
537 | + $contents .= trim($line)."\n"; |
|
538 | + } |
|
539 | + } |
|
540 | + if ($this->debug) { |
|
541 | + echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n"; |
|
542 | + } |
|
543 | + // Now parse what we've got back |
|
544 | + $this->message = new IXR_Message($contents); |
|
545 | + if (!$this->message->parse()) { |
|
546 | + // XML error |
|
547 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
548 | + return false; |
|
549 | + } |
|
550 | + // Is the message a fault? |
|
551 | + if ($this->message->messageType == 'fault') { |
|
552 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
553 | + return false; |
|
554 | + } |
|
555 | + // Message must be OK |
|
556 | + return true; |
|
557 | + } |
|
558 | + function getResponse() { |
|
559 | + // methodResponses can only have one param - return that |
|
560 | + return $this->message->params[0]; |
|
561 | + } |
|
562 | + function isError() { |
|
563 | + return (is_object($this->error)); |
|
564 | + } |
|
565 | + function getErrorCode() { |
|
566 | + return $this->error->code; |
|
567 | + } |
|
568 | + function getErrorMessage() { |
|
569 | + return $this->error->message; |
|
570 | + } |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | |
574 | 574 | class IXR_Error { |
575 | - var $code; |
|
576 | - var $message; |
|
577 | - function IXR_Error($code, $message) { |
|
578 | - $this->code = $code; |
|
579 | - $this->message = $message; |
|
580 | - } |
|
581 | - function getXml() { |
|
582 | - $xml = <<<EOD |
|
575 | + var $code; |
|
576 | + var $message; |
|
577 | + function IXR_Error($code, $message) { |
|
578 | + $this->code = $code; |
|
579 | + $this->message = $message; |
|
580 | + } |
|
581 | + function getXml() { |
|
582 | + $xml = <<<EOD |
|
583 | 583 | <methodResponse> |
584 | 584 | <fault> |
585 | 585 | <value> |
@@ -598,231 +598,231 @@ discard block |
||
598 | 598 | </methodResponse> |
599 | 599 | |
600 | 600 | EOD; |
601 | - return $xml; |
|
602 | - } |
|
601 | + return $xml; |
|
602 | + } |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | |
606 | 606 | class IXR_Date { |
607 | - var $year; |
|
608 | - var $month; |
|
609 | - var $day; |
|
610 | - var $hour; |
|
611 | - var $minute; |
|
612 | - var $second; |
|
613 | - var $timezone; |
|
614 | - function IXR_Date($time) { |
|
615 | - // $time can be a PHP timestamp or an ISO one |
|
616 | - if (is_numeric($time)) { |
|
617 | - $this->parseTimestamp($time); |
|
618 | - } else { |
|
619 | - $this->parseIso($time); |
|
620 | - } |
|
621 | - } |
|
622 | - function parseTimestamp($timestamp) { |
|
623 | - $this->year = date('Y', $timestamp); |
|
624 | - $this->month = date('Y', $timestamp); |
|
625 | - $this->day = date('Y', $timestamp); |
|
626 | - $this->hour = date('H', $timestamp); |
|
627 | - $this->minute = date('i', $timestamp); |
|
628 | - $this->second = date('s', $timestamp); |
|
629 | - } |
|
630 | - function parseIso($iso) { |
|
631 | - $this->year = substr($iso, 0, 4); |
|
632 | - $this->month = substr($iso, 4, 2); |
|
633 | - $this->day = substr($iso, 6, 2); |
|
634 | - $this->hour = substr($iso, 9, 2); |
|
635 | - $this->minute = substr($iso, 12, 2); |
|
636 | - $this->second = substr($iso, 15, 2); |
|
637 | - $this->timezone = substr($iso, 17); |
|
638 | - } |
|
639 | - function getIso() { |
|
640 | - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
641 | - } |
|
642 | - function getXml() { |
|
643 | - return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
644 | - } |
|
645 | - function getTimestamp() { |
|
646 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
647 | - } |
|
607 | + var $year; |
|
608 | + var $month; |
|
609 | + var $day; |
|
610 | + var $hour; |
|
611 | + var $minute; |
|
612 | + var $second; |
|
613 | + var $timezone; |
|
614 | + function IXR_Date($time) { |
|
615 | + // $time can be a PHP timestamp or an ISO one |
|
616 | + if (is_numeric($time)) { |
|
617 | + $this->parseTimestamp($time); |
|
618 | + } else { |
|
619 | + $this->parseIso($time); |
|
620 | + } |
|
621 | + } |
|
622 | + function parseTimestamp($timestamp) { |
|
623 | + $this->year = date('Y', $timestamp); |
|
624 | + $this->month = date('Y', $timestamp); |
|
625 | + $this->day = date('Y', $timestamp); |
|
626 | + $this->hour = date('H', $timestamp); |
|
627 | + $this->minute = date('i', $timestamp); |
|
628 | + $this->second = date('s', $timestamp); |
|
629 | + } |
|
630 | + function parseIso($iso) { |
|
631 | + $this->year = substr($iso, 0, 4); |
|
632 | + $this->month = substr($iso, 4, 2); |
|
633 | + $this->day = substr($iso, 6, 2); |
|
634 | + $this->hour = substr($iso, 9, 2); |
|
635 | + $this->minute = substr($iso, 12, 2); |
|
636 | + $this->second = substr($iso, 15, 2); |
|
637 | + $this->timezone = substr($iso, 17); |
|
638 | + } |
|
639 | + function getIso() { |
|
640 | + return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
641 | + } |
|
642 | + function getXml() { |
|
643 | + return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
644 | + } |
|
645 | + function getTimestamp() { |
|
646 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
647 | + } |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | |
651 | 651 | class IXR_Base64 { |
652 | - var $data; |
|
653 | - function IXR_Base64($data) { |
|
654 | - $this->data = $data; |
|
655 | - } |
|
656 | - function getXml() { |
|
657 | - return '<base64>'.base64_encode($this->data).'</base64>'; |
|
658 | - } |
|
652 | + var $data; |
|
653 | + function IXR_Base64($data) { |
|
654 | + $this->data = $data; |
|
655 | + } |
|
656 | + function getXml() { |
|
657 | + return '<base64>'.base64_encode($this->data).'</base64>'; |
|
658 | + } |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | |
662 | 662 | class IXR_IntrospectionServer extends IXR_Server { |
663 | - var $signatures; |
|
664 | - var $help; |
|
665 | - function IXR_IntrospectionServer() { |
|
666 | - $this->setCallbacks(); |
|
667 | - $this->setCapabilities(); |
|
668 | - $this->capabilities['introspection'] = array( |
|
669 | - 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
670 | - 'specVersion' => 1 |
|
671 | - ); |
|
672 | - $this->addCallback( |
|
673 | - 'system.methodSignature', |
|
674 | - 'this:methodSignature', |
|
675 | - array('array', 'string'), |
|
676 | - 'Returns an array describing the return type and required parameters of a method' |
|
677 | - ); |
|
678 | - $this->addCallback( |
|
679 | - 'system.getCapabilities', |
|
680 | - 'this:getCapabilities', |
|
681 | - array('struct'), |
|
682 | - 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
683 | - ); |
|
684 | - $this->addCallback( |
|
685 | - 'system.listMethods', |
|
686 | - 'this:listMethods', |
|
687 | - array('array'), |
|
688 | - 'Returns an array of available methods on this server' |
|
689 | - ); |
|
690 | - $this->addCallback( |
|
691 | - 'system.methodHelp', |
|
692 | - 'this:methodHelp', |
|
693 | - array('string', 'string'), |
|
694 | - 'Returns a documentation string for the specified method' |
|
695 | - ); |
|
696 | - } |
|
697 | - function addCallback($method, $callback, $args, $help) { |
|
698 | - $this->callbacks[$method] = $callback; |
|
699 | - $this->signatures[$method] = $args; |
|
700 | - $this->help[$method] = $help; |
|
701 | - } |
|
702 | - function call($methodname, $args) { |
|
703 | - // Make sure it's in an array |
|
704 | - if ($args && !is_array($args)) { |
|
705 | - $args = array($args); |
|
706 | - } |
|
707 | - // Over-rides default call method, adds signature check |
|
708 | - if (!$this->hasMethod($methodname)) { |
|
709 | - return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
710 | - } |
|
711 | - $method = $this->callbacks[$methodname]; |
|
712 | - $signature = $this->signatures[$methodname]; |
|
713 | - $returnType = array_shift($signature); |
|
714 | - // Check the number of arguments |
|
715 | - if (count($args) != count($signature)) { |
|
716 | - // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
717 | - return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
718 | - } |
|
719 | - // Check the argument types |
|
720 | - $ok = true; |
|
721 | - $argsbackup = $args; |
|
722 | - for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
723 | - $arg = array_shift($args); |
|
724 | - $type = array_shift($signature); |
|
725 | - switch ($type) { |
|
726 | - case 'int': |
|
727 | - case 'i4': |
|
728 | - if (is_array($arg) || !is_int($arg)) { |
|
729 | - $ok = false; |
|
730 | - } |
|
731 | - break; |
|
732 | - case 'base64': |
|
733 | - case 'string': |
|
734 | - if (!is_string($arg)) { |
|
735 | - $ok = false; |
|
736 | - } |
|
737 | - break; |
|
738 | - case 'boolean': |
|
739 | - if ($arg !== false && $arg !== true) { |
|
740 | - $ok = false; |
|
741 | - } |
|
742 | - break; |
|
743 | - case 'float': |
|
744 | - case 'double': |
|
745 | - if (!is_float($arg)) { |
|
746 | - $ok = false; |
|
747 | - } |
|
748 | - break; |
|
749 | - case 'date': |
|
750 | - case 'dateTime.iso8601': |
|
751 | - if (!is_a($arg, 'IXR_Date')) { |
|
752 | - $ok = false; |
|
753 | - } |
|
754 | - break; |
|
755 | - } |
|
756 | - if (!$ok) { |
|
757 | - return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
758 | - } |
|
759 | - } |
|
760 | - // It passed the test - run the "real" method call |
|
761 | - return parent::call($methodname, $argsbackup); |
|
762 | - } |
|
763 | - function methodSignature($method) { |
|
764 | - if (!$this->hasMethod($method)) { |
|
765 | - return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
766 | - } |
|
767 | - // We should be returning an array of types |
|
768 | - $types = $this->signatures[$method]; |
|
769 | - $return = array(); |
|
770 | - foreach ($types as $type) { |
|
771 | - switch ($type) { |
|
772 | - case 'string': |
|
773 | - $return[] = 'string'; |
|
774 | - break; |
|
775 | - case 'int': |
|
776 | - case 'i4': |
|
777 | - $return[] = 42; |
|
778 | - break; |
|
779 | - case 'double': |
|
780 | - $return[] = 3.1415; |
|
781 | - break; |
|
782 | - case 'dateTime.iso8601': |
|
783 | - $return[] = new IXR_Date(time()); |
|
784 | - break; |
|
785 | - case 'boolean': |
|
786 | - $return[] = true; |
|
787 | - break; |
|
788 | - case 'base64': |
|
789 | - $return[] = new IXR_Base64('base64'); |
|
790 | - break; |
|
791 | - case 'array': |
|
792 | - $return[] = array('array'); |
|
793 | - break; |
|
794 | - case 'struct': |
|
795 | - $return[] = array('struct' => 'struct'); |
|
796 | - break; |
|
797 | - } |
|
798 | - } |
|
799 | - return $return; |
|
800 | - } |
|
801 | - function methodHelp($method) { |
|
802 | - return $this->help[$method]; |
|
803 | - } |
|
663 | + var $signatures; |
|
664 | + var $help; |
|
665 | + function IXR_IntrospectionServer() { |
|
666 | + $this->setCallbacks(); |
|
667 | + $this->setCapabilities(); |
|
668 | + $this->capabilities['introspection'] = array( |
|
669 | + 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
670 | + 'specVersion' => 1 |
|
671 | + ); |
|
672 | + $this->addCallback( |
|
673 | + 'system.methodSignature', |
|
674 | + 'this:methodSignature', |
|
675 | + array('array', 'string'), |
|
676 | + 'Returns an array describing the return type and required parameters of a method' |
|
677 | + ); |
|
678 | + $this->addCallback( |
|
679 | + 'system.getCapabilities', |
|
680 | + 'this:getCapabilities', |
|
681 | + array('struct'), |
|
682 | + 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
683 | + ); |
|
684 | + $this->addCallback( |
|
685 | + 'system.listMethods', |
|
686 | + 'this:listMethods', |
|
687 | + array('array'), |
|
688 | + 'Returns an array of available methods on this server' |
|
689 | + ); |
|
690 | + $this->addCallback( |
|
691 | + 'system.methodHelp', |
|
692 | + 'this:methodHelp', |
|
693 | + array('string', 'string'), |
|
694 | + 'Returns a documentation string for the specified method' |
|
695 | + ); |
|
696 | + } |
|
697 | + function addCallback($method, $callback, $args, $help) { |
|
698 | + $this->callbacks[$method] = $callback; |
|
699 | + $this->signatures[$method] = $args; |
|
700 | + $this->help[$method] = $help; |
|
701 | + } |
|
702 | + function call($methodname, $args) { |
|
703 | + // Make sure it's in an array |
|
704 | + if ($args && !is_array($args)) { |
|
705 | + $args = array($args); |
|
706 | + } |
|
707 | + // Over-rides default call method, adds signature check |
|
708 | + if (!$this->hasMethod($methodname)) { |
|
709 | + return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
710 | + } |
|
711 | + $method = $this->callbacks[$methodname]; |
|
712 | + $signature = $this->signatures[$methodname]; |
|
713 | + $returnType = array_shift($signature); |
|
714 | + // Check the number of arguments |
|
715 | + if (count($args) != count($signature)) { |
|
716 | + // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
717 | + return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
718 | + } |
|
719 | + // Check the argument types |
|
720 | + $ok = true; |
|
721 | + $argsbackup = $args; |
|
722 | + for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
723 | + $arg = array_shift($args); |
|
724 | + $type = array_shift($signature); |
|
725 | + switch ($type) { |
|
726 | + case 'int': |
|
727 | + case 'i4': |
|
728 | + if (is_array($arg) || !is_int($arg)) { |
|
729 | + $ok = false; |
|
730 | + } |
|
731 | + break; |
|
732 | + case 'base64': |
|
733 | + case 'string': |
|
734 | + if (!is_string($arg)) { |
|
735 | + $ok = false; |
|
736 | + } |
|
737 | + break; |
|
738 | + case 'boolean': |
|
739 | + if ($arg !== false && $arg !== true) { |
|
740 | + $ok = false; |
|
741 | + } |
|
742 | + break; |
|
743 | + case 'float': |
|
744 | + case 'double': |
|
745 | + if (!is_float($arg)) { |
|
746 | + $ok = false; |
|
747 | + } |
|
748 | + break; |
|
749 | + case 'date': |
|
750 | + case 'dateTime.iso8601': |
|
751 | + if (!is_a($arg, 'IXR_Date')) { |
|
752 | + $ok = false; |
|
753 | + } |
|
754 | + break; |
|
755 | + } |
|
756 | + if (!$ok) { |
|
757 | + return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
758 | + } |
|
759 | + } |
|
760 | + // It passed the test - run the "real" method call |
|
761 | + return parent::call($methodname, $argsbackup); |
|
762 | + } |
|
763 | + function methodSignature($method) { |
|
764 | + if (!$this->hasMethod($method)) { |
|
765 | + return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
766 | + } |
|
767 | + // We should be returning an array of types |
|
768 | + $types = $this->signatures[$method]; |
|
769 | + $return = array(); |
|
770 | + foreach ($types as $type) { |
|
771 | + switch ($type) { |
|
772 | + case 'string': |
|
773 | + $return[] = 'string'; |
|
774 | + break; |
|
775 | + case 'int': |
|
776 | + case 'i4': |
|
777 | + $return[] = 42; |
|
778 | + break; |
|
779 | + case 'double': |
|
780 | + $return[] = 3.1415; |
|
781 | + break; |
|
782 | + case 'dateTime.iso8601': |
|
783 | + $return[] = new IXR_Date(time()); |
|
784 | + break; |
|
785 | + case 'boolean': |
|
786 | + $return[] = true; |
|
787 | + break; |
|
788 | + case 'base64': |
|
789 | + $return[] = new IXR_Base64('base64'); |
|
790 | + break; |
|
791 | + case 'array': |
|
792 | + $return[] = array('array'); |
|
793 | + break; |
|
794 | + case 'struct': |
|
795 | + $return[] = array('struct' => 'struct'); |
|
796 | + break; |
|
797 | + } |
|
798 | + } |
|
799 | + return $return; |
|
800 | + } |
|
801 | + function methodHelp($method) { |
|
802 | + return $this->help[$method]; |
|
803 | + } |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | |
807 | 807 | class IXR_ClientMulticall extends IXR_Client { |
808 | - var $calls = array(); |
|
809 | - function IXR_ClientMulticall($server, $path = false, $port = 80) { |
|
810 | - parent::IXR_Client($server, $path, $port); |
|
811 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
812 | - } |
|
813 | - function addCall() { |
|
814 | - $args = func_get_args(); |
|
815 | - $methodName = array_shift($args); |
|
816 | - $struct = array( |
|
817 | - 'methodName' => $methodName, |
|
818 | - 'params' => $args |
|
819 | - ); |
|
820 | - $this->calls[] = $struct; |
|
821 | - } |
|
822 | - function query() { |
|
823 | - // Prepare multicall, then call the parent::query() method |
|
824 | - return parent::query('system.multicall', $this->calls); |
|
825 | - } |
|
808 | + var $calls = array(); |
|
809 | + function IXR_ClientMulticall($server, $path = false, $port = 80) { |
|
810 | + parent::IXR_Client($server, $path, $port); |
|
811 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
812 | + } |
|
813 | + function addCall() { |
|
814 | + $args = func_get_args(); |
|
815 | + $methodName = array_shift($args); |
|
816 | + $struct = array( |
|
817 | + 'methodName' => $methodName, |
|
818 | + 'params' => $args |
|
819 | + ); |
|
820 | + $this->calls[] = $struct; |
|
821 | + } |
|
822 | + function query() { |
|
823 | + // Prepare multicall, then call the parent::query() method |
|
824 | + return parent::query('system.multicall', $this->calls); |
|
825 | + } |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | ?> |
829 | 829 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | class IXR_Value { |
14 | 14 | var $data; |
15 | 15 | var $type; |
16 | - function IXR_Value ($data, $type = false) { |
|
16 | + function IXR_Value($data, $type = false) { |
|
17 | 17 | $this->data = $data; |
18 | 18 | if (!$type) { |
19 | 19 | $type = $this->calculateType(); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | if ($type == 'array') { |
29 | - for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
29 | + for ($i = 0, $j = count($this->data); $i<$j; $i++) { |
|
30 | 30 | $this->data[$i] = new IXR_Value($this->data[$i]); |
31 | 31 | } |
32 | 32 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /* We have an array - is it an array or a struct ? */ |
61 | 61 | if ($this->isStruct($this->data)) { |
62 | 62 | return 'struct'; |
63 | - } else { |
|
63 | + }else { |
|
64 | 64 | return 'array'; |
65 | 65 | } |
66 | 66 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | /* Nasty function to check if an array is a struct or not */ |
108 | 108 | $expected = 0; |
109 | 109 | foreach ($array as $key => $value) { |
110 | - if ((string)$key != (string)$expected) { |
|
110 | + if ((string) $key != (string) $expected) { |
|
111 | 111 | return true; |
112 | 112 | } |
113 | 113 | $expected++; |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | |
120 | 120 | class IXR_Message { |
121 | 121 | var $message; |
122 | - var $messageType; // methodCall / methodResponse / fault |
|
122 | + var $messageType; // methodCall / methodResponse / fault |
|
123 | 123 | var $faultCode; |
124 | 124 | var $faultString; |
125 | 125 | var $methodName; |
126 | 126 | var $params; |
127 | 127 | // Current variable stacks |
128 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
128 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
129 | 129 | var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
130 | - var $_currentStructName = array(); // A stack as well |
|
130 | + var $_currentStructName = array(); // A stack as well |
|
131 | 131 | var $_param; |
132 | 132 | var $_value; |
133 | 133 | var $_currentTag; |
134 | 134 | var $_currentTagContents; |
135 | 135 | // The XML parser |
136 | 136 | var $_parser; |
137 | - function IXR_Message ($message) { |
|
137 | + function IXR_Message($message) { |
|
138 | 138 | $this->message = $message; |
139 | 139 | } |
140 | 140 | function parse() { |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | } |
167 | 167 | function tag_open($parser, $tag, $attr) { |
168 | 168 | $this->currentTag = $tag; |
169 | - switch($tag) { |
|
169 | + switch ($tag) { |
|
170 | 170 | case 'methodCall': |
171 | 171 | case 'methodResponse': |
172 | 172 | case 'fault': |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | } |
189 | 189 | function tag_close($parser, $tag) { |
190 | 190 | $valueFlag = false; |
191 | - switch($tag) { |
|
191 | + switch ($tag) { |
|
192 | 192 | case 'int': |
193 | 193 | case 'i4': |
194 | - $value = (int)trim($this->_currentTagContents); |
|
194 | + $value = (int) trim($this->_currentTagContents); |
|
195 | 195 | $this->_currentTagContents = ''; |
196 | 196 | $valueFlag = true; |
197 | 197 | break; |
198 | 198 | case 'double': |
199 | - $value = (double)trim($this->_currentTagContents); |
|
199 | + $value = (double) trim($this->_currentTagContents); |
|
200 | 200 | $this->_currentTagContents = ''; |
201 | 201 | $valueFlag = true; |
202 | 202 | break; |
203 | 203 | case 'string': |
204 | - $value = (string)trim($this->_currentTagContents); |
|
204 | + $value = (string) trim($this->_currentTagContents); |
|
205 | 205 | $this->_currentTagContents = ''; |
206 | 206 | $valueFlag = true; |
207 | 207 | break; |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | case 'value': |
215 | 215 | // "If no type is indicated, the type is string." |
216 | 216 | if (trim($this->_currentTagContents) != '') { |
217 | - $value = (string)$this->_currentTagContents; |
|
217 | + $value = (string) $this->_currentTagContents; |
|
218 | 218 | $this->_currentTagContents = ''; |
219 | 219 | $valueFlag = true; |
220 | 220 | } |
221 | 221 | break; |
222 | 222 | case 'boolean': |
223 | - $value = (boolean)trim($this->_currentTagContents); |
|
223 | + $value = (boolean) trim($this->_currentTagContents); |
|
224 | 224 | $this->_currentTagContents = ''; |
225 | 225 | $valueFlag = true; |
226 | 226 | break; |
227 | 227 | case 'base64': |
228 | - $value = base64_decode( trim($this->_currentTagContents) ); |
|
228 | + $value = base64_decode(trim($this->_currentTagContents)); |
|
229 | 229 | $this->_currentTagContents = ''; |
230 | 230 | $valueFlag = true; |
231 | 231 | break; |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | $value = trim($value); |
255 | 255 | } |
256 | 256 | */ |
257 | - if (count($this->_arraystructs) > 0) { |
|
257 | + if (count($this->_arraystructs)>0) { |
|
258 | 258 | // Add value to struct or array |
259 | 259 | if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
260 | 260 | // Add to struct |
261 | 261 | $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
262 | - } else { |
|
262 | + }else { |
|
263 | 263 | // Add to array |
264 | 264 | $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
265 | 265 | } |
266 | - } else { |
|
266 | + }else { |
|
267 | 267 | // Just add as a paramater |
268 | 268 | $this->params[] = $value; |
269 | 269 | } |
@@ -343,13 +343,13 @@ discard block |
||
343 | 343 | } |
344 | 344 | // Call the method |
345 | 345 | $result = $this->$method($args); |
346 | - } else { |
|
346 | + }else { |
|
347 | 347 | // It's a function - does it exist? |
348 | 348 | if (is_array($method)) { |
349 | 349 | if (!method_exists($method[0], $method[1])) { |
350 | 350 | return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
351 | 351 | } |
352 | - } else if (!function_exists($method)) { |
|
352 | + }else if (!function_exists($method)) { |
|
353 | 353 | return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
354 | 354 | } |
355 | 355 | // Call the function |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $params = $call['params']; |
417 | 417 | if ($method == 'system.multicall') { |
418 | 418 | $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
419 | - } else { |
|
419 | + }else { |
|
420 | 420 | $result = $this->call($method, $params); |
421 | 421 | } |
422 | 422 | if (is_a($result, 'IXR_Error')) { |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | 'faultCode' => $result->code, |
425 | 425 | 'faultString' => $result->message |
426 | 426 | ); |
427 | - } else { |
|
427 | + }else { |
|
428 | 428 | $return[] = array($result); |
429 | 429 | } |
430 | 430 | } |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | if (!$this->path) { |
487 | 487 | $this->path = '/'; |
488 | 488 | } |
489 | - } else { |
|
489 | + }else { |
|
490 | 490 | $this->server = $server; |
491 | 491 | $this->path = $path; |
492 | 492 | $this->port = $port; |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | // $time can be a PHP timestamp or an ISO one |
616 | 616 | if (is_numeric($time)) { |
617 | 617 | $this->parseTimestamp($time); |
618 | - } else { |
|
618 | + }else { |
|
619 | 619 | $this->parseIso($time); |
620 | 620 | } |
621 | 621 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | // Check the argument types |
720 | 720 | $ok = true; |
721 | 721 | $argsbackup = $args; |
722 | - for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
722 | + for ($i = 0, $j = count($args); $i<$j; $i++) { |
|
723 | 723 | $arg = array_shift($args); |
724 | 724 | $type = array_shift($signature); |
725 | 725 | switch ($type) { |
@@ -359,6 +359,9 @@ discard block |
||
359 | 359 | class UniversalFeedCreator extends FeedCreator { |
360 | 360 | var $_feed; |
361 | 361 | |
362 | + /** |
|
363 | + * @param string $format |
|
364 | + */ |
|
362 | 365 | function _setFormat($format) { |
363 | 366 | switch (strtoupper($format)) { |
364 | 367 | |
@@ -540,6 +543,7 @@ discard block |
||
540 | 543 | * Adds an FeedItem to the feed. |
541 | 544 | * |
542 | 545 | * @param object FeedItem $item The FeedItem to add to the feed. |
546 | + * @param FeedItem $item |
|
543 | 547 | * @access public |
544 | 548 | */ |
545 | 549 | function addItem($item) { |
@@ -557,6 +561,7 @@ discard block |
||
557 | 561 | * @static |
558 | 562 | * @param string string A string to be truncated. |
559 | 563 | * @param int length the maximum length the string should be truncated to |
564 | + * @param integer $length |
|
560 | 565 | * @return string the truncated string |
561 | 566 | */ |
562 | 567 | function iTrunc($string, $length) { |
@@ -655,6 +660,7 @@ discard block |
||
655 | 660 | /** |
656 | 661 | * @since 1.4 |
657 | 662 | * @access private |
663 | + * @param string $filename |
|
658 | 664 | */ |
659 | 665 | function _redirect($filename) { |
660 | 666 | // attention, heavily-commented-out-area |
@@ -788,7 +794,7 @@ discard block |
||
788 | 794 | /** |
789 | 795 | * Gets the date stored in this FeedDate as an RFC 822 date. |
790 | 796 | * |
791 | - * @return a date in RFC 822 format |
|
797 | + * @return string date in RFC 822 format |
|
792 | 798 | */ |
793 | 799 | function rfc822() { |
794 | 800 | //return gmdate("r",$this->unix); |
@@ -800,7 +806,7 @@ discard block |
||
800 | 806 | /** |
801 | 807 | * Gets the date stored in this FeedDate as an ISO 8601 date. |
802 | 808 | * |
803 | - * @return a date in ISO 8601 format |
|
809 | + * @return string date in ISO 8601 format |
|
804 | 810 | */ |
805 | 811 | function iso8601() { |
806 | 812 | $date = gmdate("Y-m-d\TH:i:sO",$this->unix); |
@@ -922,6 +928,7 @@ discard block |
||
922 | 928 | /** |
923 | 929 | * Sets this RSS feed's version number. |
924 | 930 | * @access private |
931 | + * @param string $version |
|
925 | 932 | */ |
926 | 933 | function _setRSSVersion($version) { |
927 | 934 | $this->RSSVersion = $version; |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
468 | 468 | */ |
469 | 469 | function useCached($format="RSS0.91", $filename="", $timeout=3600) { |
470 | - $this->_setFormat($format); |
|
471 | - $this->_feed->useCached($filename, $timeout); |
|
470 | + $this->_setFormat($format); |
|
471 | + $this->_feed->useCached($filename, $timeout); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | } |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | var $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays; |
497 | 497 | |
498 | 498 | /** |
499 | - * The url of the external xsl stylesheet used to format the naked rss feed. |
|
500 | - * Ignored in the output when empty. |
|
501 | - */ |
|
499 | + * The url of the external xsl stylesheet used to format the naked rss feed. |
|
500 | + * Ignored in the output when empty. |
|
501 | + */ |
|
502 | 502 | var $xslStyleSheet = ""; |
503 | 503 | |
504 | 504 | var $cssStyleSheet = ""; |
@@ -1046,9 +1046,9 @@ discard block |
||
1046 | 1046 | */ |
1047 | 1047 | class RSSCreator20 extends RSSCreator091 { |
1048 | 1048 | |
1049 | - function RSSCreator20() { |
|
1050 | - parent::_setRSSVersion("2.0"); |
|
1051 | - } |
|
1049 | + function RSSCreator20() { |
|
1050 | + parent::_setRSSVersion("2.0"); |
|
1051 | + } |
|
1052 | 1052 | |
1053 | 1053 | } |
1054 | 1054 |
@@ -333,10 +333,10 @@ discard block |
||
333 | 333 | $result = ""; |
334 | 334 | } elseif ($this->syndicateHtml) { |
335 | 335 | $result = "<![CDATA[".$this->rawFieldContent."]]>"; |
336 | - } else { |
|
336 | + }else { |
|
337 | 337 | if ($this->truncSize and is_int($this->truncSize)) { |
338 | - $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize); |
|
339 | - } else { |
|
338 | + $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent), $this->truncSize); |
|
339 | + }else { |
|
340 | 340 | $result = htmlspecialchars($this->rawFieldContent); |
341 | 341 | } |
342 | 342 | } |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @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()). |
449 | 449 | * @param boolean displayContents optional send the content of the file or not. If true, the file will be sent in the body of the response. |
450 | 450 | */ |
451 | - function saveFeed($format="RSS0.91", $filename="", $displayContents=true) { |
|
451 | + function saveFeed($format = "RSS0.91", $filename = "", $displayContents = true) { |
|
452 | 452 | $this->_setFormat($format); |
453 | 453 | $this->_feed->saveFeed($filename, $displayContents); |
454 | 454 | } |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * @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()). |
467 | 467 | * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
468 | 468 | */ |
469 | - function useCached($format="RSS0.91", $filename="", $timeout=3600) { |
|
469 | + function useCached($format = "RSS0.91", $filename = "", $timeout = 3600) { |
|
470 | 470 | $this->_setFormat($format); |
471 | 471 | $this->_feed->useCached($filename, $timeout); |
472 | 472 | } |
@@ -564,25 +564,25 @@ discard block |
||
564 | 564 | return $string; |
565 | 565 | } |
566 | 566 | |
567 | - $pos = strrpos($string,"."); |
|
567 | + $pos = strrpos($string, "."); |
|
568 | 568 | if ($pos>=$length-4) { |
569 | - $string = substr($string,0,$length-4); |
|
570 | - $pos = strrpos($string,"."); |
|
569 | + $string = substr($string, 0, $length-4); |
|
570 | + $pos = strrpos($string, "."); |
|
571 | 571 | } |
572 | 572 | if ($pos>=$length*0.4) { |
573 | - return substr($string,0,$pos+1)." ..."; |
|
573 | + return substr($string, 0, $pos+1)." ..."; |
|
574 | 574 | } |
575 | 575 | |
576 | - $pos = strrpos($string," "); |
|
576 | + $pos = strrpos($string, " "); |
|
577 | 577 | if ($pos>=$length-4) { |
578 | - $string = substr($string,0,$length-4); |
|
579 | - $pos = strrpos($string," "); |
|
578 | + $string = substr($string, 0, $length-4); |
|
579 | + $pos = strrpos($string, " "); |
|
580 | 580 | } |
581 | 581 | if ($pos>=$length*0.4) { |
582 | - return substr($string,0,$pos)." ..."; |
|
582 | + return substr($string, 0, $pos)." ..."; |
|
583 | 583 | } |
584 | 584 | |
585 | - return substr($string,0,$length-4)." ..."; |
|
585 | + return substr($string, 0, $length-4)." ..."; |
|
586 | 586 | |
587 | 587 | } |
588 | 588 | |
@@ -604,11 +604,11 @@ discard block |
||
604 | 604 | * @param indentString string a string that will be inserted before every generated line |
605 | 605 | * @return string the XML tags corresponding to $additionalElements |
606 | 606 | */ |
607 | - function _createAdditionalElements($elements, $indentString="") { |
|
607 | + function _createAdditionalElements($elements, $indentString = "") { |
|
608 | 608 | $ae = ""; |
609 | 609 | if (is_array($elements)) { |
610 | - foreach($elements AS $key => $value) { |
|
611 | - $ae.= $indentString."<$key>$value</$key>\n"; |
|
610 | + foreach ($elements AS $key => $value) { |
|
611 | + $ae .= $indentString."<$key>$value</$key>\n"; |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | return $ae; |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function _generateFilename() { |
650 | 650 | $fileInfo = pathinfo($_SERVER["PHP_SELF"]); |
651 | - return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml"; |
|
651 | + return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"])+1)).".xml"; |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | |
@@ -686,12 +686,12 @@ discard block |
||
686 | 686 | * @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()). |
687 | 687 | * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) |
688 | 688 | */ |
689 | - function useCached($filename="", $timeout=3600) { |
|
689 | + function useCached($filename = "", $timeout = 3600) { |
|
690 | 690 | $this->_timeout = $timeout; |
691 | - if ($filename=="") { |
|
691 | + if ($filename == "") { |
|
692 | 692 | $filename = $this->_generateFilename(); |
693 | 693 | } |
694 | - if (file_exists($filename) AND (time()-filemtime($filename) < $timeout)) { |
|
694 | + if (file_exists($filename) AND (time()-filemtime($filename)<$timeout)) { |
|
695 | 695 | $this->_redirect($filename); |
696 | 696 | } |
697 | 697 | } |
@@ -705,18 +705,18 @@ discard block |
||
705 | 705 | * @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()). |
706 | 706 | * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. |
707 | 707 | */ |
708 | - function saveFeed($filename="", $displayContents=true) { |
|
709 | - if ($filename=="") { |
|
708 | + function saveFeed($filename = "", $displayContents = true) { |
|
709 | + if ($filename == "") { |
|
710 | 710 | $filename = $this->_generateFilename(); |
711 | 711 | } |
712 | 712 | $feedFile = fopen($filename, "w+"); |
713 | 713 | if ($feedFile) { |
714 | - fputs($feedFile,$this->createFeed()); |
|
714 | + fputs($feedFile, $this->createFeed()); |
|
715 | 715 | fclose($feedFile); |
716 | 716 | if ($displayContents) { |
717 | 717 | $this->_redirect($filename); |
718 | 718 | } |
719 | - } else { |
|
719 | + }else { |
|
720 | 720 | echo "<br /><b>Error creating feed file, please check write permissions.</b><br />"; |
721 | 721 | } |
722 | 722 | } |
@@ -736,29 +736,29 @@ discard block |
||
736 | 736 | * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps. |
737 | 737 | * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and time is used. |
738 | 738 | */ |
739 | - function FeedDate($dateString="") { |
|
739 | + function FeedDate($dateString = "") { |
|
740 | 740 | $tzOffset = 0; |
741 | - if ($dateString=="") $dateString = date("r"); |
|
741 | + if ($dateString == "") $dateString = date("r"); |
|
742 | 742 | |
743 | 743 | //if (is_integer($dateString)) { |
744 | 744 | if (is_numeric($dateString)) { |
745 | 745 | $this->unix = $dateString; |
746 | 746 | return; |
747 | 747 | } |
748 | - 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)) { |
|
749 | - $months = Array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12); |
|
750 | - $this->unix = mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]); |
|
751 | - if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') { |
|
752 | - $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60; |
|
753 | - } else { |
|
754 | - if (strlen($matches[7])==1) { |
|
748 | + 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)) { |
|
749 | + $months = Array("Jan"=>1, "Feb"=>2, "Mar"=>3, "Apr"=>4, "May"=>5, "Jun"=>6, "Jul"=>7, "Aug"=>8, "Sep"=>9, "Oct"=>10, "Nov"=>11, "Dec"=>12); |
|
750 | + $this->unix = mktime($matches[4], $matches[5], $matches[6], $months[$matches[2]], $matches[1], $matches[3]); |
|
751 | + if (substr($matches[7], 0, 1) == '+' OR substr($matches[7], 0, 1) == '-') { |
|
752 | + $tzOffset = (substr($matches[7], 0, 3)*60+substr($matches[7], -2))*60; |
|
753 | + }else { |
|
754 | + if (strlen($matches[7]) == 1) { |
|
755 | 755 | $oneHour = 3600; |
756 | 756 | $ord = ord($matches[7]); |
757 | - if ($ord < ord("M")) { |
|
758 | - $tzOffset = (ord("A") - $ord - 1) * $oneHour; |
|
759 | - } elseif ($ord >= ord("M") AND $matches[7]!="Z") { |
|
760 | - $tzOffset = ($ord - ord("M")) * $oneHour; |
|
761 | - } elseif ($matches[7]=="Z") { |
|
757 | + if ($ord<ord("M")) { |
|
758 | + $tzOffset = (ord("A")-$ord-1)*$oneHour; |
|
759 | + } elseif ($ord>=ord("M") AND $matches[7] != "Z") { |
|
760 | + $tzOffset = ($ord-ord("M"))*$oneHour; |
|
761 | + } elseif ($matches[7] == "Z") { |
|
762 | 762 | $tzOffset = 0; |
763 | 763 | } |
764 | 764 | } |
@@ -770,12 +770,12 @@ discard block |
||
770 | 770 | $this->unix += $tzOffset; |
771 | 771 | return; |
772 | 772 | } |
773 | - if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~",$dateString,$matches)) { |
|
774 | - $this->unix = mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]); |
|
775 | - if (substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-') { |
|
776 | - $tzOffset = (substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60; |
|
777 | - } else { |
|
778 | - if ($matches[7]=="Z") { |
|
773 | + if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~", $dateString, $matches)) { |
|
774 | + $this->unix = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
|
775 | + if (substr($matches[7], 0, 1) == '+' OR substr($matches[7], 0, 1) == '-') { |
|
776 | + $tzOffset = (substr($matches[7], 0, 3)*60+substr($matches[7], -2))*60; |
|
777 | + }else { |
|
778 | + if ($matches[7] == "Z") { |
|
779 | 779 | $tzOffset = 0; |
780 | 780 | } |
781 | 781 | } |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | function rfc822() { |
794 | 794 | //return gmdate("r",$this->unix); |
795 | 795 | $date = gmdate("D, d M Y H:i:s", $this->unix); |
796 | - if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE); |
|
796 | + if (TIME_ZONE != "") $date .= " ".str_replace(":", "", TIME_ZONE); |
|
797 | 797 | return $date; |
798 | 798 | } |
799 | 799 | |
@@ -803,9 +803,9 @@ discard block |
||
803 | 803 | * @return a date in ISO 8601 format |
804 | 804 | */ |
805 | 805 | function iso8601() { |
806 | - $date = gmdate("Y-m-d\TH:i:sO",$this->unix); |
|
807 | - $date = substr($date,0,22) . ':' . substr($date,-2); |
|
808 | - if (TIME_ZONE!="") $date = str_replace("+00:00",TIME_ZONE,$date); |
|
806 | + $date = gmdate("Y-m-d\TH:i:sO", $this->unix); |
|
807 | + $date = substr($date, 0, 22).':'.substr($date, -2); |
|
808 | + if (TIME_ZONE != "") $date = str_replace("+00:00", TIME_ZONE, $date); |
|
809 | 809 | return $date; |
810 | 810 | } |
811 | 811 | |
@@ -836,63 +836,63 @@ discard block |
||
836 | 836 | */ |
837 | 837 | function createFeed() { |
838 | 838 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
839 | - $feed.= $this->_createGeneratorComment(); |
|
840 | - if ($this->cssStyleSheet=="") { |
|
839 | + $feed .= $this->_createGeneratorComment(); |
|
840 | + if ($this->cssStyleSheet == "") { |
|
841 | 841 | $cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css"; |
842 | 842 | } |
843 | - $feed.= $this->_createStylesheetReferences(); |
|
844 | - $feed.= "<rdf:RDF\n"; |
|
845 | - $feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n"; |
|
846 | - $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; |
|
847 | - $feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n"; |
|
848 | - $feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; |
|
849 | - $feed.= " <channel rdf:about=\"".$this->syndicationURL."\">\n"; |
|
850 | - $feed.= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
851 | - $feed.= " <description>".htmlspecialchars($this->description)."</description>\n"; |
|
852 | - $feed.= " <link>".$this->link."</link>\n"; |
|
853 | - if ($this->image!=null) { |
|
854 | - $feed.= " <image rdf:resource=\"".$this->image->url."\" />\n"; |
|
843 | + $feed .= $this->_createStylesheetReferences(); |
|
844 | + $feed .= "<rdf:RDF\n"; |
|
845 | + $feed .= " xmlns=\"http://purl.org/rss/1.0/\"\n"; |
|
846 | + $feed .= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; |
|
847 | + $feed .= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n"; |
|
848 | + $feed .= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; |
|
849 | + $feed .= " <channel rdf:about=\"".$this->syndicationURL."\">\n"; |
|
850 | + $feed .= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
851 | + $feed .= " <description>".htmlspecialchars($this->description)."</description>\n"; |
|
852 | + $feed .= " <link>".$this->link."</link>\n"; |
|
853 | + if ($this->image != null) { |
|
854 | + $feed .= " <image rdf:resource=\"".$this->image->url."\" />\n"; |
|
855 | 855 | } |
856 | 856 | $now = new FeedDate(); |
857 | - $feed.= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n"; |
|
858 | - $feed.= " <items>\n"; |
|
859 | - $feed.= " <rdf:Seq>\n"; |
|
860 | - for ($i=0;$i<count($this->items);$i++) { |
|
861 | - $feed.= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; |
|
857 | + $feed .= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n"; |
|
858 | + $feed .= " <items>\n"; |
|
859 | + $feed .= " <rdf:Seq>\n"; |
|
860 | + for ($i = 0; $i<count($this->items); $i++) { |
|
861 | + $feed .= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; |
|
862 | 862 | } |
863 | - $feed.= " </rdf:Seq>\n"; |
|
864 | - $feed.= " </items>\n"; |
|
865 | - $feed.= " </channel>\n"; |
|
866 | - if ($this->image!=null) { |
|
867 | - $feed.= " <image rdf:about=\"".$this->image->url."\">\n"; |
|
868 | - $feed.= " <title>".$this->image->title."</title>\n"; |
|
869 | - $feed.= " <link>".$this->image->link."</link>\n"; |
|
870 | - $feed.= " <url>".$this->image->url."</url>\n"; |
|
871 | - $feed.= " </image>\n"; |
|
863 | + $feed .= " </rdf:Seq>\n"; |
|
864 | + $feed .= " </items>\n"; |
|
865 | + $feed .= " </channel>\n"; |
|
866 | + if ($this->image != null) { |
|
867 | + $feed .= " <image rdf:about=\"".$this->image->url."\">\n"; |
|
868 | + $feed .= " <title>".$this->image->title."</title>\n"; |
|
869 | + $feed .= " <link>".$this->image->link."</link>\n"; |
|
870 | + $feed .= " <url>".$this->image->url."</url>\n"; |
|
871 | + $feed .= " </image>\n"; |
|
872 | 872 | } |
873 | - $feed.= $this->_createAdditionalElements($this->additionalElements, " "); |
|
873 | + $feed .= $this->_createAdditionalElements($this->additionalElements, " "); |
|
874 | 874 | |
875 | - for ($i=0;$i<count($this->items);$i++) { |
|
876 | - $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n"; |
|
875 | + for ($i = 0; $i<count($this->items); $i++) { |
|
876 | + $feed .= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n"; |
|
877 | 877 | //$feed.= " <dc:type>Posting</dc:type>\n"; |
878 | - $feed.= " <dc:format>text/html</dc:format>\n"; |
|
879 | - if ($this->items[$i]->date!=null) { |
|
878 | + $feed .= " <dc:format>text/html</dc:format>\n"; |
|
879 | + if ($this->items[$i]->date != null) { |
|
880 | 880 | $itemDate = new FeedDate($this->items[$i]->date); |
881 | - $feed.= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n"; |
|
881 | + $feed .= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n"; |
|
882 | 882 | } |
883 | - if ($this->items[$i]->source!="") { |
|
884 | - $feed.= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n"; |
|
883 | + if ($this->items[$i]->source != "") { |
|
884 | + $feed .= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n"; |
|
885 | 885 | } |
886 | - if ($this->items[$i]->author!="") { |
|
887 | - $feed.= " <dc:creator>".htmlspecialchars($this->items[$i]->author)."</dc:creator>\n"; |
|
886 | + if ($this->items[$i]->author != "") { |
|
887 | + $feed .= " <dc:creator>".htmlspecialchars($this->items[$i]->author)."</dc:creator>\n"; |
|
888 | 888 | } |
889 | - $feed.= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," ")))."</title>\n"; |
|
890 | - $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
891 | - $feed.= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n"; |
|
892 | - $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
893 | - $feed.= " </item>\n"; |
|
889 | + $feed .= " <title>".htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", " ")))."</title>\n"; |
|
890 | + $feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
891 | + $feed .= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n"; |
|
892 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
893 | + $feed .= " </item>\n"; |
|
894 | 894 | } |
895 | - $feed.= "</rdf:RDF>\n"; |
|
895 | + $feed .= "</rdf:RDF>\n"; |
|
896 | 896 | return $feed; |
897 | 897 | } |
898 | 898 | } |
@@ -934,78 +934,78 @@ discard block |
||
934 | 934 | */ |
935 | 935 | function createFeed() { |
936 | 936 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
937 | - $feed.= $this->_createGeneratorComment(); |
|
938 | - $feed.= $this->_createStylesheetReferences(); |
|
939 | - $feed.= "<rss version=\"".$this->RSSVersion."\">\n"; |
|
940 | - $feed.= " <channel>\n"; |
|
941 | - $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n"; |
|
937 | + $feed .= $this->_createGeneratorComment(); |
|
938 | + $feed .= $this->_createStylesheetReferences(); |
|
939 | + $feed .= "<rss version=\"".$this->RSSVersion."\">\n"; |
|
940 | + $feed .= " <channel>\n"; |
|
941 | + $feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</title>\n"; |
|
942 | 942 | $this->descriptionTruncSize = 500; |
943 | - $feed.= " <description>".$this->getDescription()."</description>\n"; |
|
944 | - $feed.= " <link>".$this->link."</link>\n"; |
|
943 | + $feed .= " <description>".$this->getDescription()."</description>\n"; |
|
944 | + $feed .= " <link>".$this->link."</link>\n"; |
|
945 | 945 | $now = new FeedDate(); |
946 | - $feed.= " <lastBuildDate>".htmlspecialchars($now->rfc822())."</lastBuildDate>\n"; |
|
947 | - $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; |
|
948 | - |
|
949 | - if ($this->image!=null) { |
|
950 | - $feed.= " <image>\n"; |
|
951 | - $feed.= " <url>".$this->image->url."</url>\n"; |
|
952 | - $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n"; |
|
953 | - $feed.= " <link>".$this->image->link."</link>\n"; |
|
954 | - if ($this->image->width!="") { |
|
955 | - $feed.= " <width>".$this->image->width."</width>\n"; |
|
946 | + $feed .= " <lastBuildDate>".htmlspecialchars($now->rfc822())."</lastBuildDate>\n"; |
|
947 | + $feed .= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; |
|
948 | + |
|
949 | + if ($this->image != null) { |
|
950 | + $feed .= " <image>\n"; |
|
951 | + $feed .= " <url>".$this->image->url."</url>\n"; |
|
952 | + $feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title), 100)."</title>\n"; |
|
953 | + $feed .= " <link>".$this->image->link."</link>\n"; |
|
954 | + if ($this->image->width != "") { |
|
955 | + $feed .= " <width>".$this->image->width."</width>\n"; |
|
956 | 956 | } |
957 | - if ($this->image->height!="") { |
|
958 | - $feed.= " <height>".$this->image->height."</height>\n"; |
|
957 | + if ($this->image->height != "") { |
|
958 | + $feed .= " <height>".$this->image->height."</height>\n"; |
|
959 | 959 | } |
960 | - if ($this->image->description!="") { |
|
961 | - $feed.= " <description>".$this->image->getDescription()."</description>\n"; |
|
960 | + if ($this->image->description != "") { |
|
961 | + $feed .= " <description>".$this->image->getDescription()."</description>\n"; |
|
962 | 962 | } |
963 | - $feed.= " </image>\n"; |
|
963 | + $feed .= " </image>\n"; |
|
964 | 964 | } |
965 | - if ($this->language!="") { |
|
966 | - $feed.= " <language>".$this->language."</language>\n"; |
|
965 | + if ($this->language != "") { |
|
966 | + $feed .= " <language>".$this->language."</language>\n"; |
|
967 | 967 | } |
968 | - if ($this->copyright!="") { |
|
969 | - $feed.= " <copyright>".FeedCreator::iTrunc(htmlspecialchars($this->copyright),100)."</copyright>\n"; |
|
968 | + if ($this->copyright != "") { |
|
969 | + $feed .= " <copyright>".FeedCreator::iTrunc(htmlspecialchars($this->copyright), 100)."</copyright>\n"; |
|
970 | 970 | } |
971 | - if ($this->editor!="") { |
|
972 | - $feed.= " <managingEditor>".FeedCreator::iTrunc(htmlspecialchars($this->editor),100)."</managingEditor>\n"; |
|
971 | + if ($this->editor != "") { |
|
972 | + $feed .= " <managingEditor>".FeedCreator::iTrunc(htmlspecialchars($this->editor), 100)."</managingEditor>\n"; |
|
973 | 973 | } |
974 | - if ($this->webmaster!="") { |
|
975 | - $feed.= " <webMaster>".FeedCreator::iTrunc(htmlspecialchars($this->webmaster),100)."</webMaster>\n"; |
|
974 | + if ($this->webmaster != "") { |
|
975 | + $feed .= " <webMaster>".FeedCreator::iTrunc(htmlspecialchars($this->webmaster), 100)."</webMaster>\n"; |
|
976 | 976 | } |
977 | - if ($this->pubDate!="") { |
|
977 | + if ($this->pubDate != "") { |
|
978 | 978 | $pubDate = new FeedDate($this->pubDate); |
979 | - $feed.= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n"; |
|
979 | + $feed .= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n"; |
|
980 | 980 | } |
981 | - if ($this->category!="") { |
|
982 | - $feed.= " <category>".htmlspecialchars($this->category)."</category>\n"; |
|
981 | + if ($this->category != "") { |
|
982 | + $feed .= " <category>".htmlspecialchars($this->category)."</category>\n"; |
|
983 | 983 | } |
984 | - if ($this->docs!="") { |
|
985 | - $feed.= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs),500)."</docs>\n"; |
|
984 | + if ($this->docs != "") { |
|
985 | + $feed .= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs), 500)."</docs>\n"; |
|
986 | 986 | } |
987 | - if ($this->ttl!="") { |
|
988 | - $feed.= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n"; |
|
987 | + if ($this->ttl != "") { |
|
988 | + $feed .= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n"; |
|
989 | 989 | } |
990 | - if ($this->rating!="") { |
|
991 | - $feed.= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating),500)."</rating>\n"; |
|
990 | + if ($this->rating != "") { |
|
991 | + $feed .= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating), 500)."</rating>\n"; |
|
992 | 992 | } |
993 | - if ($this->skipHours!="") { |
|
994 | - $feed.= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n"; |
|
993 | + if ($this->skipHours != "") { |
|
994 | + $feed .= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n"; |
|
995 | 995 | } |
996 | - if ($this->skipDays!="") { |
|
997 | - $feed.= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n"; |
|
996 | + if ($this->skipDays != "") { |
|
997 | + $feed .= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n"; |
|
998 | 998 | } |
999 | - $feed.= $this->_createAdditionalElements($this->additionalElements, " "); |
|
999 | + $feed .= $this->_createAdditionalElements($this->additionalElements, " "); |
|
1000 | 1000 | |
1001 | - for ($i=0;$i<count($this->items);$i++) { |
|
1002 | - $feed.= " <item>\n"; |
|
1003 | - $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n"; |
|
1004 | - $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
1005 | - $feed.= " <description>".$this->items[$i]->getDescription()."</description>\n"; |
|
1001 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1002 | + $feed .= " <item>\n"; |
|
1003 | + $feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</title>\n"; |
|
1004 | + $feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
1005 | + $feed .= " <description>".$this->items[$i]->getDescription()."</description>\n"; |
|
1006 | 1006 | |
1007 | - if ($this->items[$i]->author!="") { |
|
1008 | - $feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n"; |
|
1007 | + if ($this->items[$i]->author != "") { |
|
1008 | + $feed .= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n"; |
|
1009 | 1009 | } |
1010 | 1010 | /* |
1011 | 1011 | // on hold |
@@ -1013,24 +1013,24 @@ discard block |
||
1013 | 1013 | $feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n"; |
1014 | 1014 | } |
1015 | 1015 | */ |
1016 | - if ($this->items[$i]->category!="") { |
|
1017 | - $feed.= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n"; |
|
1016 | + if ($this->items[$i]->category != "") { |
|
1017 | + $feed .= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n"; |
|
1018 | 1018 | } |
1019 | - if ($this->items[$i]->comments!="") { |
|
1020 | - $feed.= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n"; |
|
1019 | + if ($this->items[$i]->comments != "") { |
|
1020 | + $feed .= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n"; |
|
1021 | 1021 | } |
1022 | - if ($this->items[$i]->date!="") { |
|
1022 | + if ($this->items[$i]->date != "") { |
|
1023 | 1023 | $itemDate = new FeedDate($this->items[$i]->date); |
1024 | - $feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n"; |
|
1024 | + $feed .= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n"; |
|
1025 | 1025 | } |
1026 | - if ($this->items[$i]->guid!="") { |
|
1027 | - $feed.= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n"; |
|
1026 | + if ($this->items[$i]->guid != "") { |
|
1027 | + $feed .= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n"; |
|
1028 | 1028 | } |
1029 | - $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
1030 | - $feed.= " </item>\n"; |
|
1029 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
1030 | + $feed .= " </item>\n"; |
|
1031 | 1031 | } |
1032 | - $feed.= " </channel>\n"; |
|
1033 | - $feed.= "</rss>\n"; |
|
1032 | + $feed .= " </channel>\n"; |
|
1033 | + $feed .= "</rss>\n"; |
|
1034 | 1034 | return $feed; |
1035 | 1035 | } |
1036 | 1036 | } |
@@ -1069,35 +1069,35 @@ discard block |
||
1069 | 1069 | |
1070 | 1070 | function createFeed() { |
1071 | 1071 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
1072 | - $feed.= $this->_createStylesheetReferences(); |
|
1073 | - $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; |
|
1074 | - $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n"; |
|
1072 | + $feed .= $this->_createStylesheetReferences(); |
|
1073 | + $feed .= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; |
|
1074 | + $feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</title>\n"; |
|
1075 | 1075 | $this->truncSize = 500; |
1076 | - $feed.= " <subtitle>".$this->getDescription()."</subtitle>\n"; |
|
1077 | - $feed.= " <link>".$this->link."</link>\n"; |
|
1078 | - for ($i=0;$i<count($this->items);$i++) { |
|
1079 | - $feed.= " <entry>\n"; |
|
1080 | - $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n"; |
|
1081 | - $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
1076 | + $feed .= " <subtitle>".$this->getDescription()."</subtitle>\n"; |
|
1077 | + $feed .= " <link>".$this->link."</link>\n"; |
|
1078 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1079 | + $feed .= " <entry>\n"; |
|
1080 | + $feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</title>\n"; |
|
1081 | + $feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; |
|
1082 | 1082 | $itemDate = new FeedDate($this->items[$i]->date); |
1083 | - $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n"; |
|
1084 | - $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n"; |
|
1085 | - $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n"; |
|
1086 | - $feed.= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n"; |
|
1087 | - if ($this->items[$i]->author!="") { |
|
1088 | - $feed.= " <author>\n"; |
|
1089 | - $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; |
|
1090 | - if ($this->items[$i]->authorEmail!="") { |
|
1091 | - $feed.= " <email>".$this->items[$i]->authorEmail."</email>\n"; |
|
1083 | + $feed .= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n"; |
|
1084 | + $feed .= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n"; |
|
1085 | + $feed .= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n"; |
|
1086 | + $feed .= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n"; |
|
1087 | + if ($this->items[$i]->author != "") { |
|
1088 | + $feed .= " <author>\n"; |
|
1089 | + $feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; |
|
1090 | + if ($this->items[$i]->authorEmail != "") { |
|
1091 | + $feed .= " <email>".$this->items[$i]->authorEmail."</email>\n"; |
|
1092 | 1092 | } |
1093 | - $feed.=" </author>\n"; |
|
1093 | + $feed .= " </author>\n"; |
|
1094 | 1094 | } |
1095 | - $feed.= " <content type=\"text/html\" xml:lang=\"en-us\">\n"; |
|
1096 | - $feed.= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription()."</div>\n"; |
|
1097 | - $feed.= " </content>\n"; |
|
1098 | - $feed.= " </entry>\n"; |
|
1095 | + $feed .= " <content type=\"text/html\" xml:lang=\"en-us\">\n"; |
|
1096 | + $feed .= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription()."</div>\n"; |
|
1097 | + $feed .= " </content>\n"; |
|
1098 | + $feed .= " </entry>\n"; |
|
1099 | 1099 | } |
1100 | - $feed.= "</feed>\n"; |
|
1100 | + $feed .= "</feed>\n"; |
|
1101 | 1101 | return $feed; |
1102 | 1102 | } |
1103 | 1103 | } |
@@ -1128,53 +1128,53 @@ discard block |
||
1128 | 1128 | |
1129 | 1129 | function createFeed() { |
1130 | 1130 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
1131 | - $feed.= $this->_createGeneratorComment(); |
|
1132 | - $feed.= $this->_createStylesheetReferences(); |
|
1133 | - $feed.= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\""; |
|
1134 | - if ($this->language!="") { |
|
1135 | - $feed.= " xml:lang=\"".$this->language."\""; |
|
1131 | + $feed .= $this->_createGeneratorComment(); |
|
1132 | + $feed .= $this->_createStylesheetReferences(); |
|
1133 | + $feed .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\""; |
|
1134 | + if ($this->language != "") { |
|
1135 | + $feed .= " xml:lang=\"".$this->language."\""; |
|
1136 | 1136 | } |
1137 | - $feed.= ">\n"; |
|
1138 | - $feed.= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
1139 | - $feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n"; |
|
1140 | - $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n"; |
|
1141 | - $feed.= " <id>".htmlspecialchars($this->link)."</id>\n"; |
|
1137 | + $feed .= ">\n"; |
|
1138 | + $feed .= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
1139 | + $feed .= " <tagline>".htmlspecialchars($this->description)."</tagline>\n"; |
|
1140 | + $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n"; |
|
1141 | + $feed .= " <id>".htmlspecialchars($this->link)."</id>\n"; |
|
1142 | 1142 | $now = new FeedDate(); |
1143 | - $feed.= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n"; |
|
1144 | - if ($this->editor!="") { |
|
1145 | - $feed.= " <author>\n"; |
|
1146 | - $feed.= " <name>".$this->editor."</name>\n"; |
|
1147 | - if ($this->editorEmail!="") { |
|
1148 | - $feed.= " <email>".$this->editorEmail."</email>\n"; |
|
1143 | + $feed .= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n"; |
|
1144 | + if ($this->editor != "") { |
|
1145 | + $feed .= " <author>\n"; |
|
1146 | + $feed .= " <name>".$this->editor."</name>\n"; |
|
1147 | + if ($this->editorEmail != "") { |
|
1148 | + $feed .= " <email>".$this->editorEmail."</email>\n"; |
|
1149 | 1149 | } |
1150 | - $feed.= " </author>\n"; |
|
1150 | + $feed .= " </author>\n"; |
|
1151 | 1151 | } |
1152 | - $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; |
|
1153 | - $feed.= $this->_createAdditionalElements($this->additionalElements, " "); |
|
1154 | - for ($i=0;$i<count($this->items);$i++) { |
|
1155 | - $feed.= " <entry>\n"; |
|
1156 | - $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; |
|
1157 | - $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; |
|
1158 | - if ($this->items[$i]->date=="") { |
|
1152 | + $feed .= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; |
|
1153 | + $feed .= $this->_createAdditionalElements($this->additionalElements, " "); |
|
1154 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1155 | + $feed .= " <entry>\n"; |
|
1156 | + $feed .= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; |
|
1157 | + $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; |
|
1158 | + if ($this->items[$i]->date == "") { |
|
1159 | 1159 | $this->items[$i]->date = time(); |
1160 | 1160 | } |
1161 | 1161 | $itemDate = new FeedDate($this->items[$i]->date); |
1162 | - $feed.= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n"; |
|
1163 | - $feed.= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n"; |
|
1164 | - $feed.= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n"; |
|
1165 | - $feed.= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n"; |
|
1166 | - $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
1167 | - if ($this->items[$i]->author!="") { |
|
1168 | - $feed.= " <author>\n"; |
|
1169 | - $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; |
|
1170 | - $feed.= " </author>\n"; |
|
1162 | + $feed .= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n"; |
|
1163 | + $feed .= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n"; |
|
1164 | + $feed .= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n"; |
|
1165 | + $feed .= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n"; |
|
1166 | + $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|
1167 | + if ($this->items[$i]->author != "") { |
|
1168 | + $feed .= " <author>\n"; |
|
1169 | + $feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; |
|
1170 | + $feed .= " </author>\n"; |
|
1171 | 1171 | } |
1172 | - if ($this->items[$i]->description!="") { |
|
1173 | - $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n"; |
|
1172 | + if ($this->items[$i]->description != "") { |
|
1173 | + $feed .= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n"; |
|
1174 | 1174 | } |
1175 | - $feed.= " </entry>\n"; |
|
1175 | + $feed .= " </entry>\n"; |
|
1176 | 1176 | } |
1177 | - $feed.= "</feed>\n"; |
|
1177 | + $feed .= "</feed>\n"; |
|
1178 | 1178 | return $feed; |
1179 | 1179 | } |
1180 | 1180 | } |
@@ -1195,25 +1195,25 @@ discard block |
||
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | function qp_enc($input = "", $line_max = 76) { |
1198 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
1198 | + $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
1199 | 1199 | $lines = preg_split("/(?:\r\n|\r|\n)/", $input); |
1200 | 1200 | $eol = "\r\n"; |
1201 | 1201 | $escape = "="; |
1202 | 1202 | $output = ""; |
1203 | - while( list(, $line) = each($lines) ) { |
|
1203 | + while (list(, $line) = each($lines)) { |
|
1204 | 1204 | //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary |
1205 | 1205 | $linlen = strlen($line); |
1206 | 1206 | $newline = ""; |
1207 | - for($i = 0; $i < $linlen; $i++) { |
|
1207 | + for ($i = 0; $i<$linlen; $i++) { |
|
1208 | 1208 | $c = substr($line, $i, 1); |
1209 | 1209 | $dec = ord($c); |
1210 | - if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only |
|
1210 | + if (($dec == 32) && ($i == ($linlen-1))) { // convert space at eol only |
|
1211 | 1211 | $c = "=20"; |
1212 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
1212 | + } elseif (($dec == 61) || ($dec<32) || ($dec>126)) { // always encode "\t", which is *not* required |
|
1213 | 1213 | $h2 = floor($dec/16); $h1 = floor($dec%16); |
1214 | 1214 | $c = $escape.$hex["$h2"].$hex["$h1"]; |
1215 | 1215 | } |
1216 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
1216 | + if ((strlen($newline)+strlen($c))>=$line_max) { // CRLF is not counted |
|
1217 | 1217 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
1218 | 1218 | $newline = ""; |
1219 | 1219 | } |
@@ -1230,26 +1230,26 @@ discard block |
||
1230 | 1230 | * @return string the feed's complete text |
1231 | 1231 | */ |
1232 | 1232 | function createFeed() { |
1233 | - for ($i=0;$i<count($this->items);$i++) { |
|
1234 | - if ($this->items[$i]->author!="") { |
|
1233 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1234 | + if ($this->items[$i]->author != "") { |
|
1235 | 1235 | $from = $this->items[$i]->author; |
1236 | - } else { |
|
1236 | + }else { |
|
1237 | 1237 | $from = $this->title; |
1238 | 1238 | } |
1239 | 1239 | $itemDate = new FeedDate($this->items[$i]->date); |
1240 | - $feed.= "From ".strtr(MBOXCreator::qp_enc($from)," ","_")." ".date("D M d H:i:s Y",$itemDate->unix())."\n"; |
|
1241 | - $feed.= "Content-Type: text/plain;\n"; |
|
1242 | - $feed.= " charset=\"".$this->encoding."\"\n"; |
|
1243 | - $feed.= "Content-Transfer-Encoding: quoted-printable\n"; |
|
1244 | - $feed.= "Content-Type: text/plain\n"; |
|
1245 | - $feed.= "From: \"".MBOXCreator::qp_enc($from)."\"\n"; |
|
1246 | - $feed.= "Date: ".$itemDate->rfc822()."\n"; |
|
1247 | - $feed.= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title,100))."\n"; |
|
1248 | - $feed.= "\n"; |
|
1240 | + $feed .= "From ".strtr(MBOXCreator::qp_enc($from), " ", "_")." ".date("D M d H:i:s Y", $itemDate->unix())."\n"; |
|
1241 | + $feed .= "Content-Type: text/plain;\n"; |
|
1242 | + $feed .= " charset=\"".$this->encoding."\"\n"; |
|
1243 | + $feed .= "Content-Transfer-Encoding: quoted-printable\n"; |
|
1244 | + $feed .= "Content-Type: text/plain\n"; |
|
1245 | + $feed .= "From: \"".MBOXCreator::qp_enc($from)."\"\n"; |
|
1246 | + $feed .= "Date: ".$itemDate->rfc822()."\n"; |
|
1247 | + $feed .= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title, 100))."\n"; |
|
1248 | + $feed .= "\n"; |
|
1249 | 1249 | $body = chunk_split(MBOXCreator::qp_enc($this->items[$i]->description)); |
1250 | - $feed.= preg_replace("~\nFrom ([^\n]*)(\n?)~","\n>From $1$2\n",$body); |
|
1251 | - $feed.= "\n"; |
|
1252 | - $feed.= "\n"; |
|
1250 | + $feed .= preg_replace("~\nFrom ([^\n]*)(\n?)~", "\n>From $1$2\n", $body); |
|
1251 | + $feed .= "\n"; |
|
1252 | + $feed .= "\n"; |
|
1253 | 1253 | } |
1254 | 1254 | return $feed; |
1255 | 1255 | } |
@@ -1262,7 +1262,7 @@ discard block |
||
1262 | 1262 | */ |
1263 | 1263 | function _generateFilename() { |
1264 | 1264 | $fileInfo = pathinfo($_SERVER["PHP_SELF"]); |
1265 | - return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".mbox"; |
|
1265 | + return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"])+1)).".mbox"; |
|
1266 | 1266 | } |
1267 | 1267 | } |
1268 | 1268 | |
@@ -1282,38 +1282,38 @@ discard block |
||
1282 | 1282 | |
1283 | 1283 | function createFeed() { |
1284 | 1284 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
1285 | - $feed.= $this->_createGeneratorComment(); |
|
1286 | - $feed.= $this->_createStylesheetReferences(); |
|
1287 | - $feed.= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
|
1288 | - $feed.= " <head>\n"; |
|
1289 | - $feed.= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
1290 | - if ($this->pubDate!="") { |
|
1285 | + $feed .= $this->_createGeneratorComment(); |
|
1286 | + $feed .= $this->_createStylesheetReferences(); |
|
1287 | + $feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
|
1288 | + $feed .= " <head>\n"; |
|
1289 | + $feed .= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|
1290 | + if ($this->pubDate != "") { |
|
1291 | 1291 | $date = new FeedDate($this->pubDate); |
1292 | - $feed.= " <dateCreated>".$date->rfc822()."</dateCreated>\n"; |
|
1292 | + $feed .= " <dateCreated>".$date->rfc822()."</dateCreated>\n"; |
|
1293 | 1293 | } |
1294 | - if ($this->lastBuildDate!="") { |
|
1294 | + if ($this->lastBuildDate != "") { |
|
1295 | 1295 | $date = new FeedDate($this->lastBuildDate); |
1296 | - $feed.= " <dateModified>".$date->rfc822()."</dateModified>\n"; |
|
1296 | + $feed .= " <dateModified>".$date->rfc822()."</dateModified>\n"; |
|
1297 | 1297 | } |
1298 | - if ($this->editor!="") { |
|
1299 | - $feed.= " <ownerName>".$this->editor."</ownerName>\n"; |
|
1298 | + if ($this->editor != "") { |
|
1299 | + $feed .= " <ownerName>".$this->editor."</ownerName>\n"; |
|
1300 | 1300 | } |
1301 | - if ($this->editorEmail!="") { |
|
1302 | - $feed.= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n"; |
|
1301 | + if ($this->editorEmail != "") { |
|
1302 | + $feed .= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n"; |
|
1303 | 1303 | } |
1304 | - $feed.= " </head>\n"; |
|
1305 | - $feed.= " <body>\n"; |
|
1306 | - for ($i=0;$i<count($this->items);$i++) { |
|
1307 | - $feed.= " <outline type=\"rss\" "; |
|
1308 | - $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," "))); |
|
1309 | - $feed.= " title=\"".$title."\""; |
|
1310 | - $feed.= " text=\"".$title."\""; |
|
1304 | + $feed .= " </head>\n"; |
|
1305 | + $feed .= " <body>\n"; |
|
1306 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1307 | + $feed .= " <outline type=\"rss\" "; |
|
1308 | + $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", " "))); |
|
1309 | + $feed .= " title=\"".$title."\""; |
|
1310 | + $feed .= " text=\"".$title."\""; |
|
1311 | 1311 | //$feed.= " description=\"".htmlspecialchars($this->items[$i]->description)."\""; |
1312 | - $feed.= " url=\"".htmlspecialchars($this->items[$i]->link)."\""; |
|
1313 | - $feed.= "/>\n"; |
|
1312 | + $feed .= " url=\"".htmlspecialchars($this->items[$i]->link)."\""; |
|
1313 | + $feed .= "/>\n"; |
|
1314 | 1314 | } |
1315 | - $feed.= " </body>\n"; |
|
1316 | - $feed.= "</opml>\n"; |
|
1315 | + $feed .= " </body>\n"; |
|
1316 | + $feed .= "</opml>\n"; |
|
1317 | 1317 | return $feed; |
1318 | 1318 | } |
1319 | 1319 | } |
@@ -1343,7 +1343,7 @@ discard block |
||
1343 | 1343 | /** |
1344 | 1344 | * Contains HTML to be output at the end of the feed's html representation. |
1345 | 1345 | */ |
1346 | - var $footer ; |
|
1346 | + var $footer; |
|
1347 | 1347 | |
1348 | 1348 | /** |
1349 | 1349 | * Contains HTML to be output between entries. A separator is only used in |
@@ -1362,7 +1362,7 @@ discard block |
||
1362 | 1362 | */ |
1363 | 1363 | var $openInNewWindow = true; |
1364 | 1364 | |
1365 | - var $imageAlign ="right"; |
|
1365 | + var $imageAlign = "right"; |
|
1366 | 1366 | |
1367 | 1367 | /** |
1368 | 1368 | * In case of very simple output you may want to get rid of the style tags, |
@@ -1371,7 +1371,7 @@ discard block |
||
1371 | 1371 | * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored |
1372 | 1372 | * in the function createFeed(). |
1373 | 1373 | */ |
1374 | - var $stylelessOutput =""; |
|
1374 | + var $stylelessOutput = ""; |
|
1375 | 1375 | |
1376 | 1376 | /** |
1377 | 1377 | * Writes the HTML. |
@@ -1379,12 +1379,12 @@ discard block |
||
1379 | 1379 | */ |
1380 | 1380 | function createFeed() { |
1381 | 1381 | // if there is styleless output, use the content of this variable and ignore the rest |
1382 | - if ($this->stylelessOutput!="") { |
|
1382 | + if ($this->stylelessOutput != "") { |
|
1383 | 1383 | return $this->stylelessOutput; |
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | //if no stylePrefix is set, generate it yourself depending on the script name |
1387 | - if ($this->stylePrefix=="") { |
|
1387 | + if ($this->stylePrefix == "") { |
|
1388 | 1388 | $this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_"; |
1389 | 1389 | } |
1390 | 1390 | |
@@ -1395,24 +1395,24 @@ discard block |
||
1395 | 1395 | |
1396 | 1396 | // use this array to put the lines in and implode later with "document.write" javascript |
1397 | 1397 | $feedArray = array(); |
1398 | - if ($this->image!=null) { |
|
1398 | + if ($this->image != null) { |
|
1399 | 1399 | $imageStr = "<a href='".$this->image->link."'".$targetInsert.">". |
1400 | 1400 | "<img src='".$this->image->url."' border='0' alt='". |
1401 | - FeedCreator::iTrunc(htmlspecialchars($this->image->title),100). |
|
1401 | + FeedCreator::iTrunc(htmlspecialchars($this->image->title), 100). |
|
1402 | 1402 | "' align='".$this->imageAlign."' "; |
1403 | 1403 | if ($this->image->width) { |
1404 | - $imageStr .=" width='".$this->image->width. "' "; |
|
1404 | + $imageStr .= " width='".$this->image->width."' "; |
|
1405 | 1405 | } |
1406 | 1406 | if ($this->image->height) { |
1407 | - $imageStr .=" height='".$this->image->height."' "; |
|
1407 | + $imageStr .= " height='".$this->image->height."' "; |
|
1408 | 1408 | } |
1409 | - $imageStr .="/></a>"; |
|
1409 | + $imageStr .= "/></a>"; |
|
1410 | 1410 | $feedArray[] = $imageStr; |
1411 | 1411 | } |
1412 | 1412 | |
1413 | 1413 | if ($this->title) { |
1414 | 1414 | $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>". |
1415 | - FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</a></div>"; |
|
1415 | + FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</a></div>"; |
|
1416 | 1416 | } |
1417 | 1417 | if ($this->getDescription()) { |
1418 | 1418 | $feedArray[] = "<div class='".$this->stylePrefix."description'>". |
@@ -1424,8 +1424,8 @@ discard block |
||
1424 | 1424 | $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>"; |
1425 | 1425 | } |
1426 | 1426 | |
1427 | - for ($i=0;$i<count($this->items);$i++) { |
|
1428 | - if ($this->separator and $i > 0) { |
|
1427 | + for ($i = 0; $i<count($this->items); $i++) { |
|
1428 | + if ($this->separator and $i>0) { |
|
1429 | 1429 | $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>"; |
1430 | 1430 | } |
1431 | 1431 | |
@@ -1433,12 +1433,12 @@ discard block |
||
1433 | 1433 | if ($this->items[$i]->link) { |
1434 | 1434 | $feedArray[] = |
1435 | 1435 | "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix. |
1436 | - "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100). |
|
1436 | + "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100). |
|
1437 | 1437 | "</a></div>"; |
1438 | - } else { |
|
1438 | + }else { |
|
1439 | 1439 | $feedArray[] = |
1440 | 1440 | "<div class='".$this->stylePrefix."item_title'>". |
1441 | - FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100). |
|
1441 | + FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100). |
|
1442 | 1442 | "</div>"; |
1443 | 1443 | } |
1444 | 1444 | } |
@@ -1453,7 +1453,7 @@ discard block |
||
1453 | 1453 | $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>"; |
1454 | 1454 | } |
1455 | 1455 | |
1456 | - $feed= "".join($feedArray, "\r\n"); |
|
1456 | + $feed = "".join($feedArray, "\r\n"); |
|
1457 | 1457 | return $feed; |
1458 | 1458 | } |
1459 | 1459 | |
@@ -1466,7 +1466,7 @@ discard block |
||
1466 | 1466 | */ |
1467 | 1467 | function _generateFilename() { |
1468 | 1468 | $fileInfo = pathinfo($_SERVER["PHP_SELF"]); |
1469 | - return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html"; |
|
1469 | + return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"])+1)).".html"; |
|
1470 | 1470 | } |
1471 | 1471 | } |
1472 | 1472 | |
@@ -1487,7 +1487,7 @@ discard block |
||
1487 | 1487 | function createFeed() |
1488 | 1488 | { |
1489 | 1489 | $feed = parent::createFeed(); |
1490 | - $feedArray = explode("\n",$feed); |
|
1490 | + $feedArray = explode("\n", $feed); |
|
1491 | 1491 | |
1492 | 1492 | $jsFeed = ""; |
1493 | 1493 | foreach ($feedArray as $value) { |
@@ -1505,7 +1505,7 @@ discard block |
||
1505 | 1505 | */ |
1506 | 1506 | function _generateFilename() { |
1507 | 1507 | $fileInfo = pathinfo($_SERVER["PHP_SELF"]); |
1508 | - return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js"; |
|
1508 | + return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"])+1)).".js"; |
|
1509 | 1509 | } |
1510 | 1510 | |
1511 | 1511 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | // - no truncation (truncating risks producing invalid html) |
332 | 332 | if (!$this->rawFieldContent) { |
333 | 333 | $result = ""; |
334 | - } elseif ($this->syndicateHtml) { |
|
334 | + } elseif ($this->syndicateHtml) { |
|
335 | 335 | $result = "<![CDATA[".$this->rawFieldContent."]]>"; |
336 | 336 | } else { |
337 | 337 | if ($this->truncSize and is_int($this->truncSize)) { |
@@ -616,8 +616,12 @@ discard block |
||
616 | 616 | |
617 | 617 | function _createStylesheetReferences() { |
618 | 618 | $xml = ""; |
619 | - if ($this->cssStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n"; |
|
620 | - if ($this->xslStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n"; |
|
619 | + if ($this->cssStyleSheet) { |
|
620 | + $xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n"; |
|
621 | + } |
|
622 | + if ($this->xslStyleSheet) { |
|
623 | + $xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n"; |
|
624 | + } |
|
621 | 625 | return $xml; |
622 | 626 | } |
623 | 627 | |
@@ -738,7 +742,9 @@ discard block |
||
738 | 742 | */ |
739 | 743 | function FeedDate($dateString="") { |
740 | 744 | $tzOffset = 0; |
741 | - if ($dateString=="") $dateString = date("r"); |
|
745 | + if ($dateString=="") { |
|
746 | + $dateString = date("r"); |
|
747 | + } |
|
742 | 748 | |
743 | 749 | //if (is_integer($dateString)) { |
744 | 750 | if (is_numeric($dateString)) { |
@@ -793,7 +799,9 @@ discard block |
||
793 | 799 | function rfc822() { |
794 | 800 | //return gmdate("r",$this->unix); |
795 | 801 | $date = gmdate("D, d M Y H:i:s", $this->unix); |
796 | - if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE); |
|
802 | + if (TIME_ZONE!="") { |
|
803 | + $date .= " ".str_replace(":","",TIME_ZONE); |
|
804 | + } |
|
797 | 805 | return $date; |
798 | 806 | } |
799 | 807 | |
@@ -805,7 +813,9 @@ discard block |
||
805 | 813 | function iso8601() { |
806 | 814 | $date = gmdate("Y-m-d\TH:i:sO",$this->unix); |
807 | 815 | $date = substr($date,0,22) . ':' . substr($date,-2); |
808 | - if (TIME_ZONE!="") $date = str_replace("+00:00",TIME_ZONE,$date); |
|
816 | + if (TIME_ZONE!="") { |
|
817 | + $date = str_replace("+00:00",TIME_ZONE,$date); |
|
818 | + } |
|
809 | 819 | return $date; |
810 | 820 | } |
811 | 821 |
@@ -450,6 +450,10 @@ discard block |
||
450 | 450 | /** |
451 | 451 | * return XML parser, and possibly re-encoded source |
452 | 452 | * |
453 | + * @param string $source |
|
454 | + * @param string $out_enc |
|
455 | + * @param string|null $in_enc |
|
456 | + * @param boolean $detect |
|
453 | 457 | */ |
454 | 458 | function create_parser($source, $out_enc, $in_enc, $detect) { |
455 | 459 | if ( substr(phpversion(),0,1) == 5) { |
@@ -561,6 +565,9 @@ discard block |
||
561 | 565 | } |
562 | 566 | } |
563 | 567 | |
568 | + /** |
|
569 | + * @param integer $lvl |
|
570 | + */ |
|
564 | 571 | function error ($errormsg, $lvl=E_USER_WARNING) { |
565 | 572 | // append PHP's error message if track_errors enabled |
566 | 573 | if ( !empty($php_errormsg) ) { |
@@ -32,492 +32,492 @@ discard block |
||
32 | 32 | * |
33 | 33 | */ |
34 | 34 | class MagpieRSS { |
35 | - var $parser; |
|
36 | - |
|
37 | - var $current_item = array(); // item currently being parsed |
|
38 | - var $items = array(); // collection of parsed items |
|
39 | - var $channel = array(); // hash of channel fields |
|
40 | - var $textinput = array(); |
|
41 | - var $image = array(); |
|
42 | - var $feed_type; |
|
43 | - var $feed_version; |
|
44 | - var $encoding = ''; // output encoding of parsed rss |
|
45 | - |
|
46 | - var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
47 | - |
|
48 | - var $ERROR = ""; |
|
49 | - var $WARNING = ""; |
|
50 | - |
|
51 | - // define some constants |
|
52 | - |
|
53 | - var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
|
54 | - var $_KNOWN_ENCODINGS = array('UTF-8', 'US-ASCII', 'ISO-8859-1'); |
|
55 | - |
|
56 | - // parser variables, useless if you're not a parser, treat as private |
|
57 | - var $stack = array(); // parser stack |
|
58 | - var $inchannel = false; |
|
59 | - var $initem = false; |
|
60 | - var $incontent = false; // if in Atom <content mode="xml"> field |
|
61 | - var $intextinput = false; |
|
62 | - var $inimage = false; |
|
63 | - var $current_field = ''; |
|
64 | - var $current_namespace = false; |
|
65 | - |
|
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 | - function MagpieRSS ($source, $output_encoding='ISO-8859-1', |
|
96 | - $input_encoding=null, $detect_encoding=true) |
|
97 | - { |
|
98 | - # if PHP xml isn't compiled in, die |
|
99 | - # |
|
100 | - if (!function_exists('xml_parser_create')) { |
|
101 | - $this->error( "Failed to load PHP's XML Extension. " . |
|
102 | - "http://www.php.net/manual/en/ref.xml.php", |
|
103 | - E_USER_ERROR ); |
|
104 | - } |
|
35 | + var $parser; |
|
36 | + |
|
37 | + var $current_item = array(); // item currently being parsed |
|
38 | + var $items = array(); // collection of parsed items |
|
39 | + var $channel = array(); // hash of channel fields |
|
40 | + var $textinput = array(); |
|
41 | + var $image = array(); |
|
42 | + var $feed_type; |
|
43 | + var $feed_version; |
|
44 | + var $encoding = ''; // output encoding of parsed rss |
|
45 | + |
|
46 | + var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
47 | + |
|
48 | + var $ERROR = ""; |
|
49 | + var $WARNING = ""; |
|
50 | + |
|
51 | + // define some constants |
|
52 | + |
|
53 | + var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
|
54 | + var $_KNOWN_ENCODINGS = array('UTF-8', 'US-ASCII', 'ISO-8859-1'); |
|
55 | + |
|
56 | + // parser variables, useless if you're not a parser, treat as private |
|
57 | + var $stack = array(); // parser stack |
|
58 | + var $inchannel = false; |
|
59 | + var $initem = false; |
|
60 | + var $incontent = false; // if in Atom <content mode="xml"> field |
|
61 | + var $intextinput = false; |
|
62 | + var $inimage = false; |
|
63 | + var $current_field = ''; |
|
64 | + var $current_namespace = false; |
|
65 | + |
|
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 | + function MagpieRSS ($source, $output_encoding='ISO-8859-1', |
|
96 | + $input_encoding=null, $detect_encoding=true) |
|
97 | + { |
|
98 | + # if PHP xml isn't compiled in, die |
|
99 | + # |
|
100 | + if (!function_exists('xml_parser_create')) { |
|
101 | + $this->error( "Failed to load PHP's XML Extension. " . |
|
102 | + "http://www.php.net/manual/en/ref.xml.php", |
|
103 | + E_USER_ERROR ); |
|
104 | + } |
|
105 | 105 | |
106 | - list($parser, $source) = $this->create_parser($source, |
|
107 | - $output_encoding, $input_encoding, $detect_encoding); |
|
106 | + list($parser, $source) = $this->create_parser($source, |
|
107 | + $output_encoding, $input_encoding, $detect_encoding); |
|
108 | 108 | |
109 | 109 | |
110 | - if (!is_resource($parser)) { |
|
111 | - $this->error( "Failed to create an instance of PHP's XML parser. " . |
|
112 | - "http://www.php.net/manual/en/ref.xml.php", |
|
113 | - E_USER_ERROR ); |
|
114 | - } |
|
110 | + if (!is_resource($parser)) { |
|
111 | + $this->error( "Failed to create an instance of PHP's XML parser. " . |
|
112 | + "http://www.php.net/manual/en/ref.xml.php", |
|
113 | + E_USER_ERROR ); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | - $this->parser = $parser; |
|
117 | + $this->parser = $parser; |
|
118 | 118 | |
119 | - # pass in parser, and a reference to this object |
|
120 | - # setup handlers |
|
121 | - # |
|
122 | - xml_set_object( $this->parser, $this ); |
|
123 | - xml_set_element_handler($this->parser, |
|
124 | - 'feed_start_element', 'feed_end_element' ); |
|
119 | + # pass in parser, and a reference to this object |
|
120 | + # setup handlers |
|
121 | + # |
|
122 | + xml_set_object( $this->parser, $this ); |
|
123 | + xml_set_element_handler($this->parser, |
|
124 | + 'feed_start_element', 'feed_end_element' ); |
|
125 | 125 | |
126 | - xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
126 | + xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
127 | 127 | |
128 | - $status = @xml_parse( $this->parser, $source ); |
|
128 | + $status = @xml_parse( $this->parser, $source ); |
|
129 | 129 | |
130 | - if (! $status ) { |
|
131 | - $errorcode = xml_get_error_code( $this->parser ); |
|
132 | - if ( $errorcode != XML_ERROR_NONE ) { |
|
133 | - $xml_error = xml_error_string( $errorcode ); |
|
134 | - $error_line = xml_get_current_line_number($this->parser); |
|
135 | - $error_col = xml_get_current_column_number($this->parser); |
|
136 | - $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
130 | + if (! $status ) { |
|
131 | + $errorcode = xml_get_error_code( $this->parser ); |
|
132 | + if ( $errorcode != XML_ERROR_NONE ) { |
|
133 | + $xml_error = xml_error_string( $errorcode ); |
|
134 | + $error_line = xml_get_current_line_number($this->parser); |
|
135 | + $error_col = xml_get_current_column_number($this->parser); |
|
136 | + $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
137 | 137 | |
138 | - $this->error( $errormsg ); |
|
139 | - } |
|
140 | - } |
|
138 | + $this->error( $errormsg ); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | - xml_parser_free( $this->parser ); |
|
142 | + xml_parser_free( $this->parser ); |
|
143 | 143 | |
144 | - $this->normalize(); |
|
144 | + $this->normalize(); |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - function feed_start_element($p, $element, &$attrs) { |
|
149 | - $el = $element = strtolower($element); |
|
150 | - $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
148 | + function feed_start_element($p, $element, &$attrs) { |
|
149 | + $el = $element = strtolower($element); |
|
150 | + $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
151 | 151 | |
152 | - // check for a namespace, and split if found |
|
153 | - $ns = false; |
|
154 | - if ( strpos( $element, ':' ) ) { |
|
155 | - list($ns, $el) = split( ':', $element, 2); |
|
156 | - } |
|
157 | - if ( $ns and $ns != 'rdf' ) { |
|
158 | - $this->current_namespace = $ns; |
|
159 | - } |
|
152 | + // check for a namespace, and split if found |
|
153 | + $ns = false; |
|
154 | + if ( strpos( $element, ':' ) ) { |
|
155 | + list($ns, $el) = split( ':', $element, 2); |
|
156 | + } |
|
157 | + if ( $ns and $ns != 'rdf' ) { |
|
158 | + $this->current_namespace = $ns; |
|
159 | + } |
|
160 | 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 ( $el == 'rdf' ) { |
|
166 | - $this->feed_type = RSS; |
|
167 | - $this->feed_version = '1.0'; |
|
168 | - } |
|
169 | - elseif ( $el == 'rss' ) { |
|
170 | - $this->feed_type = RSS; |
|
171 | - $this->feed_version = $attrs['version']; |
|
172 | - } |
|
173 | - elseif ( $el == 'feed' ) { |
|
174 | - $this->feed_type = ATOM; |
|
175 | - $this->feed_version = $attrs['version']; |
|
176 | - $this->inchannel = true; |
|
177 | - } |
|
178 | - return; |
|
179 | - } |
|
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 ( $el == 'rdf' ) { |
|
166 | + $this->feed_type = RSS; |
|
167 | + $this->feed_version = '1.0'; |
|
168 | + } |
|
169 | + elseif ( $el == 'rss' ) { |
|
170 | + $this->feed_type = RSS; |
|
171 | + $this->feed_version = $attrs['version']; |
|
172 | + } |
|
173 | + elseif ( $el == 'feed' ) { |
|
174 | + $this->feed_type = ATOM; |
|
175 | + $this->feed_version = $attrs['version']; |
|
176 | + $this->inchannel = true; |
|
177 | + } |
|
178 | + return; |
|
179 | + } |
|
180 | 180 | |
181 | - if ( $el == 'channel' ) |
|
182 | - { |
|
183 | - $this->inchannel = true; |
|
184 | - } |
|
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
186 | - { |
|
187 | - $this->initem = true; |
|
188 | - if ( isset($attrs['rdf:about']) ) { |
|
189 | - $this->current_item['about'] = $attrs['rdf:about']; |
|
190 | - } |
|
191 | - } |
|
181 | + if ( $el == 'channel' ) |
|
182 | + { |
|
183 | + $this->inchannel = true; |
|
184 | + } |
|
185 | + elseif ($el == 'item' or $el == 'entry' ) |
|
186 | + { |
|
187 | + $this->initem = true; |
|
188 | + if ( isset($attrs['rdf:about']) ) { |
|
189 | + $this->current_item['about'] = $attrs['rdf:about']; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - // if we're in the default namespace of an RSS feed, |
|
194 | - // record textinput or image fields |
|
195 | - elseif ( |
|
196 | - $this->feed_type == RSS and |
|
197 | - $this->current_namespace == '' and |
|
198 | - $el == 'textinput' ) |
|
199 | - { |
|
200 | - $this->intextinput = true; |
|
201 | - } |
|
193 | + // if we're in the default namespace of an RSS feed, |
|
194 | + // record textinput or image fields |
|
195 | + elseif ( |
|
196 | + $this->feed_type == RSS and |
|
197 | + $this->current_namespace == '' and |
|
198 | + $el == 'textinput' ) |
|
199 | + { |
|
200 | + $this->intextinput = true; |
|
201 | + } |
|
202 | 202 | |
203 | - elseif ( |
|
204 | - $this->feed_type == RSS and |
|
205 | - $this->current_namespace == '' and |
|
206 | - $el == 'image' ) |
|
207 | - { |
|
208 | - $this->inimage = true; |
|
209 | - } |
|
203 | + elseif ( |
|
204 | + $this->feed_type == RSS and |
|
205 | + $this->current_namespace == '' and |
|
206 | + $el == 'image' ) |
|
207 | + { |
|
208 | + $this->inimage = true; |
|
209 | + } |
|
210 | 210 | |
211 | - # handle atom content constructs |
|
212 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
213 | - { |
|
214 | - // avoid clashing w/ RSS mod_content |
|
215 | - if ($el == 'content' ) { |
|
216 | - $el = 'atom_content'; |
|
217 | - } |
|
211 | + # handle atom content constructs |
|
212 | + elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
213 | + { |
|
214 | + // avoid clashing w/ RSS mod_content |
|
215 | + if ($el == 'content' ) { |
|
216 | + $el = 'atom_content'; |
|
217 | + } |
|
218 | 218 | |
219 | - $this->incontent = $el; |
|
219 | + $this->incontent = $el; |
|
220 | 220 | |
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
225 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
226 | - { |
|
227 | - // if tags are inlined, then flatten |
|
228 | - $attrs_str = join(' ', |
|
229 | - array_map('map_attrs', |
|
230 | - array_keys($attrs), |
|
231 | - array_values($attrs) ) ); |
|
224 | + // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
225 | + elseif ($this->feed_type == ATOM and $this->incontent ) |
|
226 | + { |
|
227 | + // if tags are inlined, then flatten |
|
228 | + $attrs_str = join(' ', |
|
229 | + array_map('map_attrs', |
|
230 | + array_keys($attrs), |
|
231 | + array_values($attrs) ) ); |
|
232 | 232 | |
233 | - $this->append_content( "<$element $attrs_str>" ); |
|
233 | + $this->append_content( "<$element $attrs_str>" ); |
|
234 | 234 | |
235 | - array_unshift( $this->stack, $el ); |
|
236 | - } |
|
235 | + array_unshift( $this->stack, $el ); |
|
236 | + } |
|
237 | 237 | |
238 | - // Atom support many links per containging element. |
|
239 | - // Magpie treats link elements of type rel='alternate' |
|
240 | - // as being equivalent to RSS's simple link element. |
|
241 | - // |
|
242 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
243 | - { |
|
244 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
245 | - { |
|
246 | - $link_el = 'link'; |
|
247 | - } |
|
248 | - else { |
|
249 | - $link_el = 'link_' . $attrs['rel']; |
|
250 | - } |
|
238 | + // Atom support many links per containging element. |
|
239 | + // Magpie treats link elements of type rel='alternate' |
|
240 | + // as being equivalent to RSS's simple link element. |
|
241 | + // |
|
242 | + elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
243 | + { |
|
244 | + if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
245 | + { |
|
246 | + $link_el = 'link'; |
|
247 | + } |
|
248 | + else { |
|
249 | + $link_el = 'link_' . $attrs['rel']; |
|
250 | + } |
|
251 | 251 | |
252 | - $this->append($link_el, $attrs['href']); |
|
253 | - } |
|
254 | - // set stack[0] to current element |
|
255 | - else { |
|
256 | - array_unshift($this->stack, $el); |
|
257 | - } |
|
258 | - } |
|
252 | + $this->append($link_el, $attrs['href']); |
|
253 | + } |
|
254 | + // set stack[0] to current element |
|
255 | + else { |
|
256 | + array_unshift($this->stack, $el); |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - function feed_cdata ($p, $text) { |
|
262 | + function feed_cdata ($p, $text) { |
|
263 | 263 | |
264 | - if ($this->feed_type == ATOM and $this->incontent) |
|
265 | - { |
|
266 | - $this->append_content( $text ); |
|
267 | - } |
|
268 | - else { |
|
269 | - $current_el = join('_', array_reverse($this->stack)); |
|
270 | - $this->append($current_el, $text); |
|
271 | - } |
|
272 | - } |
|
264 | + if ($this->feed_type == ATOM and $this->incontent) |
|
265 | + { |
|
266 | + $this->append_content( $text ); |
|
267 | + } |
|
268 | + else { |
|
269 | + $current_el = join('_', array_reverse($this->stack)); |
|
270 | + $this->append($current_el, $text); |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - function feed_end_element ($p, $el) { |
|
275 | - $el = strtolower($el); |
|
274 | + function feed_end_element ($p, $el) { |
|
275 | + $el = strtolower($el); |
|
276 | 276 | |
277 | - if ( $el == 'item' or $el == 'entry' ) |
|
278 | - { |
|
279 | - $this->items[] = $this->current_item; |
|
280 | - $this->current_item = array(); |
|
281 | - $this->initem = false; |
|
282 | - } |
|
283 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
284 | - { |
|
285 | - $this->intextinput = false; |
|
286 | - } |
|
287 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
288 | - { |
|
289 | - $this->inimage = false; |
|
290 | - } |
|
291 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
292 | - { |
|
293 | - $this->incontent = false; |
|
294 | - } |
|
295 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
296 | - { |
|
297 | - $this->inchannel = false; |
|
298 | - } |
|
299 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
300 | - // balance tags properly |
|
301 | - // note: i don't think this is actually neccessary |
|
302 | - if ( $this->stack[0] == $el ) |
|
303 | - { |
|
304 | - $this->append_content("</$el>"); |
|
305 | - } |
|
306 | - else { |
|
307 | - $this->append_content("<$el />"); |
|
308 | - } |
|
277 | + if ( $el == 'item' or $el == 'entry' ) |
|
278 | + { |
|
279 | + $this->items[] = $this->current_item; |
|
280 | + $this->current_item = array(); |
|
281 | + $this->initem = false; |
|
282 | + } |
|
283 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
284 | + { |
|
285 | + $this->intextinput = false; |
|
286 | + } |
|
287 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
288 | + { |
|
289 | + $this->inimage = false; |
|
290 | + } |
|
291 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
292 | + { |
|
293 | + $this->incontent = false; |
|
294 | + } |
|
295 | + elseif ($el == 'channel' or $el == 'feed' ) |
|
296 | + { |
|
297 | + $this->inchannel = false; |
|
298 | + } |
|
299 | + elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
300 | + // balance tags properly |
|
301 | + // note: i don't think this is actually neccessary |
|
302 | + if ( $this->stack[0] == $el ) |
|
303 | + { |
|
304 | + $this->append_content("</$el>"); |
|
305 | + } |
|
306 | + else { |
|
307 | + $this->append_content("<$el />"); |
|
308 | + } |
|
309 | 309 | |
310 | - array_shift( $this->stack ); |
|
311 | - } |
|
312 | - else { |
|
313 | - array_shift( $this->stack ); |
|
314 | - } |
|
310 | + array_shift( $this->stack ); |
|
311 | + } |
|
312 | + else { |
|
313 | + array_shift( $this->stack ); |
|
314 | + } |
|
315 | 315 | |
316 | - $this->current_namespace = false; |
|
317 | - } |
|
316 | + $this->current_namespace = false; |
|
317 | + } |
|
318 | 318 | |
319 | - function concat (&$str1, $str2="") { |
|
320 | - if (!isset($str1) ) { |
|
321 | - $str1=""; |
|
322 | - } |
|
323 | - $str1 .= $str2; |
|
324 | - } |
|
319 | + function concat (&$str1, $str2="") { |
|
320 | + if (!isset($str1) ) { |
|
321 | + $str1=""; |
|
322 | + } |
|
323 | + $str1 .= $str2; |
|
324 | + } |
|
325 | 325 | |
326 | 326 | |
327 | 327 | |
328 | - function append_content($text) { |
|
329 | - if ( $this->initem ) { |
|
330 | - $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
331 | - } |
|
332 | - elseif ( $this->inchannel ) { |
|
333 | - $this->concat( $this->channel[ $this->incontent ], $text ); |
|
334 | - } |
|
335 | - } |
|
328 | + function append_content($text) { |
|
329 | + if ( $this->initem ) { |
|
330 | + $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
331 | + } |
|
332 | + elseif ( $this->inchannel ) { |
|
333 | + $this->concat( $this->channel[ $this->incontent ], $text ); |
|
334 | + } |
|
335 | + } |
|
336 | 336 | |
337 | - // smart append - field and namespace aware |
|
338 | - function append($el, $text) { |
|
339 | - if (!$el) { |
|
340 | - return; |
|
341 | - } |
|
342 | - if ( $this->current_namespace ) |
|
343 | - { |
|
344 | - if ( $this->initem ) { |
|
345 | - $this->concat( |
|
346 | - $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
347 | - } |
|
348 | - elseif ($this->inchannel) { |
|
349 | - $this->concat( |
|
350 | - $this->channel[ $this->current_namespace][ $el ], $text ); |
|
351 | - } |
|
352 | - elseif ($this->intextinput) { |
|
353 | - $this->concat( |
|
354 | - $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
355 | - } |
|
356 | - elseif ($this->inimage) { |
|
357 | - $this->concat( |
|
358 | - $this->image[ $this->current_namespace ][ $el ], $text ); |
|
359 | - } |
|
360 | - } |
|
361 | - else { |
|
362 | - if ( $this->initem ) { |
|
363 | - $this->concat( |
|
364 | - $this->current_item[ $el ], $text); |
|
365 | - } |
|
366 | - elseif ($this->intextinput) { |
|
367 | - $this->concat( |
|
368 | - $this->textinput[ $el ], $text ); |
|
369 | - } |
|
370 | - elseif ($this->inimage) { |
|
371 | - $this->concat( |
|
372 | - $this->image[ $el ], $text ); |
|
373 | - } |
|
374 | - elseif ($this->inchannel) { |
|
375 | - $this->concat( |
|
376 | - $this->channel[ $el ], $text ); |
|
377 | - } |
|
337 | + // smart append - field and namespace aware |
|
338 | + function append($el, $text) { |
|
339 | + if (!$el) { |
|
340 | + return; |
|
341 | + } |
|
342 | + if ( $this->current_namespace ) |
|
343 | + { |
|
344 | + if ( $this->initem ) { |
|
345 | + $this->concat( |
|
346 | + $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
347 | + } |
|
348 | + elseif ($this->inchannel) { |
|
349 | + $this->concat( |
|
350 | + $this->channel[ $this->current_namespace][ $el ], $text ); |
|
351 | + } |
|
352 | + elseif ($this->intextinput) { |
|
353 | + $this->concat( |
|
354 | + $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
355 | + } |
|
356 | + elseif ($this->inimage) { |
|
357 | + $this->concat( |
|
358 | + $this->image[ $this->current_namespace ][ $el ], $text ); |
|
359 | + } |
|
360 | + } |
|
361 | + else { |
|
362 | + if ( $this->initem ) { |
|
363 | + $this->concat( |
|
364 | + $this->current_item[ $el ], $text); |
|
365 | + } |
|
366 | + elseif ($this->intextinput) { |
|
367 | + $this->concat( |
|
368 | + $this->textinput[ $el ], $text ); |
|
369 | + } |
|
370 | + elseif ($this->inimage) { |
|
371 | + $this->concat( |
|
372 | + $this->image[ $el ], $text ); |
|
373 | + } |
|
374 | + elseif ($this->inchannel) { |
|
375 | + $this->concat( |
|
376 | + $this->channel[ $el ], $text ); |
|
377 | + } |
|
378 | 378 | |
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - function normalize () { |
|
383 | - // if atom populate rss fields |
|
384 | - if ( $this->is_atom() ) { |
|
385 | - $this->channel['description'] = $this->channel['tagline']; |
|
386 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
387 | - $item = $this->items[$i]; |
|
388 | - if ( isset($item['summary']) ) |
|
389 | - $item['description'] = $item['summary']; |
|
390 | - if ( isset($item['atom_content'])) |
|
391 | - $item['content']['encoded'] = $item['atom_content']; |
|
392 | - |
|
393 | - $atom_date = (isset($item['issued']) ) ? $item['issued'] : @$item['modified']; |
|
394 | - if ( $atom_date ) { |
|
395 | - $epoch = @parse_w3cdtf($atom_date); |
|
396 | - if ($epoch and $epoch > 0) { |
|
397 | - $item['date_timestamp'] = $epoch; |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - $this->items[$i] = $item; |
|
402 | - } |
|
403 | - } |
|
404 | - elseif ( $this->is_rss() ) { |
|
405 | - $this->channel['tagline'] = $this->channel['description']; |
|
406 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
407 | - $item = $this->items[$i]; |
|
408 | - if ( isset($item['description'])) |
|
409 | - $item['summary'] = $item['description']; |
|
410 | - if ( isset($item['content']['encoded'] ) ) |
|
411 | - $item['atom_content'] = $item['content']['encoded']; |
|
412 | - |
|
413 | - if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
|
414 | - $epoch = @parse_w3cdtf($item['dc']['date']); |
|
415 | - if ($epoch and $epoch > 0) { |
|
416 | - $item['date_timestamp'] = $epoch; |
|
417 | - } |
|
418 | - } |
|
419 | - elseif ( isset($item['pubdate']) ) { |
|
420 | - $epoch = @strtotime($item['pubdate']); |
|
421 | - if ($epoch > 0) { |
|
422 | - $item['date_timestamp'] = $epoch; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - $this->items[$i] = $item; |
|
427 | - } |
|
428 | - } |
|
429 | - } |
|
379 | + } |
|
380 | + } |
|
430 | 381 | |
382 | + function normalize () { |
|
383 | + // if atom populate rss fields |
|
384 | + if ( $this->is_atom() ) { |
|
385 | + $this->channel['description'] = $this->channel['tagline']; |
|
386 | + for ( $i = 0; $i < count($this->items); $i++) { |
|
387 | + $item = $this->items[$i]; |
|
388 | + if ( isset($item['summary']) ) |
|
389 | + $item['description'] = $item['summary']; |
|
390 | + if ( isset($item['atom_content'])) |
|
391 | + $item['content']['encoded'] = $item['atom_content']; |
|
392 | + |
|
393 | + $atom_date = (isset($item['issued']) ) ? $item['issued'] : @$item['modified']; |
|
394 | + if ( $atom_date ) { |
|
395 | + $epoch = @parse_w3cdtf($atom_date); |
|
396 | + if ($epoch and $epoch > 0) { |
|
397 | + $item['date_timestamp'] = $epoch; |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + $this->items[$i] = $item; |
|
402 | + } |
|
403 | + } |
|
404 | + elseif ( $this->is_rss() ) { |
|
405 | + $this->channel['tagline'] = $this->channel['description']; |
|
406 | + for ( $i = 0; $i < count($this->items); $i++) { |
|
407 | + $item = $this->items[$i]; |
|
408 | + if ( isset($item['description'])) |
|
409 | + $item['summary'] = $item['description']; |
|
410 | + if ( isset($item['content']['encoded'] ) ) |
|
411 | + $item['atom_content'] = $item['content']['encoded']; |
|
412 | + |
|
413 | + if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
|
414 | + $epoch = @parse_w3cdtf($item['dc']['date']); |
|
415 | + if ($epoch and $epoch > 0) { |
|
416 | + $item['date_timestamp'] = $epoch; |
|
417 | + } |
|
418 | + } |
|
419 | + elseif ( isset($item['pubdate']) ) { |
|
420 | + $epoch = @strtotime($item['pubdate']); |
|
421 | + if ($epoch > 0) { |
|
422 | + $item['date_timestamp'] = $epoch; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + $this->items[$i] = $item; |
|
427 | + } |
|
428 | + } |
|
429 | + } |
|
431 | 430 | |
432 | - function is_rss () { |
|
433 | - if ( $this->feed_type == RSS ) { |
|
434 | - return $this->feed_version; |
|
435 | - } |
|
436 | - else { |
|
437 | - return false; |
|
438 | - } |
|
439 | - } |
|
440 | 431 | |
441 | - function is_atom() { |
|
442 | - if ( $this->feed_type == ATOM ) { |
|
443 | - return $this->feed_version; |
|
444 | - } |
|
445 | - else { |
|
446 | - return false; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * return XML parser, and possibly re-encoded source |
|
452 | - * |
|
453 | - */ |
|
454 | - function create_parser($source, $out_enc, $in_enc, $detect) { |
|
455 | - if ( substr(phpversion(),0,1) == 5) { |
|
456 | - $parser = $this->php5_create_parser($in_enc, $detect); |
|
457 | - } |
|
458 | - else { |
|
459 | - list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
460 | - } |
|
461 | - if ($out_enc) { |
|
462 | - $this->encoding = $out_enc; |
|
463 | - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
464 | - } |
|
432 | + function is_rss () { |
|
433 | + if ( $this->feed_type == RSS ) { |
|
434 | + return $this->feed_version; |
|
435 | + } |
|
436 | + else { |
|
437 | + return false; |
|
438 | + } |
|
439 | + } |
|
465 | 440 | |
466 | - return array($parser, $source); |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Instantiate an XML parser under PHP5 |
|
471 | - * |
|
472 | - * PHP5 will do a fine job of detecting input encoding |
|
473 | - * if passed an empty string as the encoding. |
|
474 | - * |
|
475 | - * All hail libxml2! |
|
476 | - * |
|
477 | - */ |
|
478 | - function php5_create_parser($in_enc, $detect) { |
|
479 | - // by default php5 does a fine job of detecting input encodings |
|
480 | - if(!$detect && $in_enc) { |
|
481 | - return xml_parser_create($in_enc); |
|
482 | - } |
|
483 | - else { |
|
484 | - return xml_parser_create(''); |
|
485 | - } |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Instaniate an XML parser under PHP4 |
|
490 | - * |
|
491 | - * Unfortunately PHP4's support for character encodings |
|
492 | - * and especially XML and character encodings sucks. As |
|
493 | - * long as the documents you parse only contain characters |
|
494 | - * from the ISO-8859-1 character set (a superset of ASCII, |
|
495 | - * and a subset of UTF-8) you're fine. However once you |
|
496 | - * step out of that comfy little world things get mad, bad, |
|
497 | - * and dangerous to know. |
|
498 | - * |
|
499 | - * The following code is based on SJM's work with FoF |
|
500 | - * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
501 | - * |
|
502 | - */ |
|
503 | - function php4_create_parser($source, $in_enc, $detect) { |
|
504 | - if ( !$detect ) { |
|
505 | - return array(xml_parser_create($in_enc), $source); |
|
506 | - } |
|
441 | + function is_atom() { |
|
442 | + if ( $this->feed_type == ATOM ) { |
|
443 | + return $this->feed_version; |
|
444 | + } |
|
445 | + else { |
|
446 | + return false; |
|
447 | + } |
|
448 | + } |
|
507 | 449 | |
508 | - if (!$in_enc) { |
|
509 | - if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
510 | - $in_enc = strtoupper($m[1]); |
|
511 | - $this->source_encoding = $in_enc; |
|
512 | - } |
|
513 | - else { |
|
514 | - $in_enc = 'UTF-8'; |
|
515 | - } |
|
516 | - } |
|
450 | + /** |
|
451 | + * return XML parser, and possibly re-encoded source |
|
452 | + * |
|
453 | + */ |
|
454 | + function create_parser($source, $out_enc, $in_enc, $detect) { |
|
455 | + if ( substr(phpversion(),0,1) == 5) { |
|
456 | + $parser = $this->php5_create_parser($in_enc, $detect); |
|
457 | + } |
|
458 | + else { |
|
459 | + list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
460 | + } |
|
461 | + if ($out_enc) { |
|
462 | + $this->encoding = $out_enc; |
|
463 | + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
464 | + } |
|
517 | 465 | |
518 | - if ($this->known_encoding($in_enc)) { |
|
519 | - return array(xml_parser_create($in_enc), $source); |
|
520 | - } |
|
466 | + return array($parser, $source); |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Instantiate an XML parser under PHP5 |
|
471 | + * |
|
472 | + * PHP5 will do a fine job of detecting input encoding |
|
473 | + * if passed an empty string as the encoding. |
|
474 | + * |
|
475 | + * All hail libxml2! |
|
476 | + * |
|
477 | + */ |
|
478 | + function php5_create_parser($in_enc, $detect) { |
|
479 | + // by default php5 does a fine job of detecting input encodings |
|
480 | + if(!$detect && $in_enc) { |
|
481 | + return xml_parser_create($in_enc); |
|
482 | + } |
|
483 | + else { |
|
484 | + return xml_parser_create(''); |
|
485 | + } |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Instaniate an XML parser under PHP4 |
|
490 | + * |
|
491 | + * Unfortunately PHP4's support for character encodings |
|
492 | + * and especially XML and character encodings sucks. As |
|
493 | + * long as the documents you parse only contain characters |
|
494 | + * from the ISO-8859-1 character set (a superset of ASCII, |
|
495 | + * and a subset of UTF-8) you're fine. However once you |
|
496 | + * step out of that comfy little world things get mad, bad, |
|
497 | + * and dangerous to know. |
|
498 | + * |
|
499 | + * The following code is based on SJM's work with FoF |
|
500 | + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
501 | + * |
|
502 | + */ |
|
503 | + function php4_create_parser($source, $in_enc, $detect) { |
|
504 | + if ( !$detect ) { |
|
505 | + return array(xml_parser_create($in_enc), $source); |
|
506 | + } |
|
507 | + |
|
508 | + if (!$in_enc) { |
|
509 | + if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
510 | + $in_enc = strtoupper($m[1]); |
|
511 | + $this->source_encoding = $in_enc; |
|
512 | + } |
|
513 | + else { |
|
514 | + $in_enc = 'UTF-8'; |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + if ($this->known_encoding($in_enc)) { |
|
519 | + return array(xml_parser_create($in_enc), $source); |
|
520 | + } |
|
521 | 521 | |
522 | 522 | /* |
523 | 523 | // the dectected encoding is not one of the simple encodings PHP knows |
@@ -548,44 +548,44 @@ discard block |
||
548 | 548 | E_USER_NOTICE); |
549 | 549 | */ |
550 | 550 | |
551 | - return array(xml_parser_create(), $source); |
|
552 | - } |
|
551 | + return array(xml_parser_create(), $source); |
|
552 | + } |
|
553 | 553 | |
554 | - function known_encoding($enc) { |
|
555 | - $enc = strtoupper($enc); |
|
556 | - if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
|
557 | - return $enc; |
|
558 | - } |
|
559 | - else { |
|
560 | - return false; |
|
561 | - } |
|
562 | - } |
|
554 | + function known_encoding($enc) { |
|
555 | + $enc = strtoupper($enc); |
|
556 | + if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
|
557 | + return $enc; |
|
558 | + } |
|
559 | + else { |
|
560 | + return false; |
|
561 | + } |
|
562 | + } |
|
563 | 563 | |
564 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
565 | - // append PHP's error message if track_errors enabled |
|
566 | - if ( !empty($php_errormsg) ) { |
|
567 | - $errormsg .= " ($php_errormsg)"; |
|
568 | - } |
|
569 | - if ( MAGPIE_DEBUG ) { |
|
570 | - trigger_error( $errormsg, $lvl); |
|
571 | - } |
|
572 | - else { |
|
573 | - error_log( $errormsg, 0); |
|
574 | - } |
|
564 | + function error ($errormsg, $lvl=E_USER_WARNING) { |
|
565 | + // append PHP's error message if track_errors enabled |
|
566 | + if ( !empty($php_errormsg) ) { |
|
567 | + $errormsg .= " ($php_errormsg)"; |
|
568 | + } |
|
569 | + if ( MAGPIE_DEBUG ) { |
|
570 | + trigger_error( $errormsg, $lvl); |
|
571 | + } |
|
572 | + else { |
|
573 | + error_log( $errormsg, 0); |
|
574 | + } |
|
575 | 575 | |
576 | - $notices = E_USER_NOTICE|E_NOTICE; |
|
577 | - if ( $lvl&$notices ) { |
|
578 | - $this->WARNING = $errormsg; |
|
579 | - } else { |
|
580 | - $this->ERROR = $errormsg; |
|
581 | - } |
|
582 | - } |
|
576 | + $notices = E_USER_NOTICE|E_NOTICE; |
|
577 | + if ( $lvl&$notices ) { |
|
578 | + $this->WARNING = $errormsg; |
|
579 | + } else { |
|
580 | + $this->ERROR = $errormsg; |
|
581 | + } |
|
582 | + } |
|
583 | 583 | |
584 | 584 | |
585 | 585 | } // end class RSS |
586 | 586 | |
587 | 587 | function map_attrs($k, $v) { |
588 | - return "$k=\"$v\""; |
|
588 | + return "$k=\"$v\""; |
|
589 | 589 | } |
590 | 590 | |
591 | 591 |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | class MagpieRSS { |
35 | 35 | var $parser; |
36 | 36 | |
37 | - var $current_item = array(); // item currently being parsed |
|
38 | - var $items = array(); // collection of parsed items |
|
39 | - var $channel = array(); // hash of channel fields |
|
37 | + var $current_item = array(); // item currently being parsed |
|
38 | + var $items = array(); // collection of parsed items |
|
39 | + var $channel = array(); // hash of channel fields |
|
40 | 40 | var $textinput = array(); |
41 | 41 | var $image = array(); |
42 | 42 | var $feed_type; |
43 | 43 | var $feed_version; |
44 | - var $encoding = ''; // output encoding of parsed rss |
|
44 | + var $encoding = ''; // output encoding of parsed rss |
|
45 | 45 | |
46 | - var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
46 | + var $_source_encoding = ''; // only set if we have to parse xml prolog |
|
47 | 47 | |
48 | 48 | var $ERROR = ""; |
49 | 49 | var $WARNING = ""; |
@@ -92,15 +92,15 @@ discard block |
||
92 | 92 | * source encoding. (caveat emptor) |
93 | 93 | * |
94 | 94 | */ |
95 | - function MagpieRSS ($source, $output_encoding='ISO-8859-1', |
|
96 | - $input_encoding=null, $detect_encoding=true) |
|
95 | + function MagpieRSS($source, $output_encoding = 'ISO-8859-1', |
|
96 | + $input_encoding = null, $detect_encoding = true) |
|
97 | 97 | { |
98 | 98 | # if PHP xml isn't compiled in, die |
99 | 99 | # |
100 | 100 | if (!function_exists('xml_parser_create')) { |
101 | - $this->error( "Failed to load PHP's XML Extension. " . |
|
101 | + $this->error("Failed to load PHP's XML Extension. ". |
|
102 | 102 | "http://www.php.net/manual/en/ref.xml.php", |
103 | - E_USER_ERROR ); |
|
103 | + E_USER_ERROR); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | list($parser, $source) = $this->create_parser($source, |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | |
109 | 109 | |
110 | 110 | if (!is_resource($parser)) { |
111 | - $this->error( "Failed to create an instance of PHP's XML parser. " . |
|
111 | + $this->error("Failed to create an instance of PHP's XML parser. ". |
|
112 | 112 | "http://www.php.net/manual/en/ref.xml.php", |
113 | - E_USER_ERROR ); |
|
113 | + E_USER_ERROR); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -119,27 +119,27 @@ discard block |
||
119 | 119 | # pass in parser, and a reference to this object |
120 | 120 | # setup handlers |
121 | 121 | # |
122 | - xml_set_object( $this->parser, $this ); |
|
122 | + xml_set_object($this->parser, $this); |
|
123 | 123 | xml_set_element_handler($this->parser, |
124 | - 'feed_start_element', 'feed_end_element' ); |
|
124 | + 'feed_start_element', 'feed_end_element'); |
|
125 | 125 | |
126 | - xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
126 | + xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
127 | 127 | |
128 | - $status = @xml_parse( $this->parser, $source ); |
|
128 | + $status = @xml_parse($this->parser, $source); |
|
129 | 129 | |
130 | - if (! $status ) { |
|
131 | - $errorcode = xml_get_error_code( $this->parser ); |
|
132 | - if ( $errorcode != XML_ERROR_NONE ) { |
|
133 | - $xml_error = xml_error_string( $errorcode ); |
|
130 | + if (!$status) { |
|
131 | + $errorcode = xml_get_error_code($this->parser); |
|
132 | + if ($errorcode != XML_ERROR_NONE) { |
|
133 | + $xml_error = xml_error_string($errorcode); |
|
134 | 134 | $error_line = xml_get_current_line_number($this->parser); |
135 | 135 | $error_col = xml_get_current_column_number($this->parser); |
136 | 136 | $errormsg = "$xml_error at line $error_line, column $error_col"; |
137 | 137 | |
138 | - $this->error( $errormsg ); |
|
138 | + $this->error($errormsg); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - xml_parser_free( $this->parser ); |
|
142 | + xml_parser_free($this->parser); |
|
143 | 143 | |
144 | 144 | $this->normalize(); |
145 | 145 | |
@@ -151,26 +151,26 @@ discard block |
||
151 | 151 | |
152 | 152 | // check for a namespace, and split if found |
153 | 153 | $ns = false; |
154 | - if ( strpos( $element, ':' ) ) { |
|
155 | - list($ns, $el) = split( ':', $element, 2); |
|
154 | + if (strpos($element, ':')) { |
|
155 | + list($ns, $el) = split(':', $element, 2); |
|
156 | 156 | } |
157 | - if ( $ns and $ns != 'rdf' ) { |
|
157 | + if ($ns and $ns != 'rdf') { |
|
158 | 158 | $this->current_namespace = $ns; |
159 | 159 | } |
160 | 160 | |
161 | 161 | # if feed type isn't set, then this is first element of feed |
162 | 162 | # identify feed from root element |
163 | 163 | # |
164 | - if (!isset($this->feed_type) ) { |
|
165 | - if ( $el == 'rdf' ) { |
|
164 | + if (!isset($this->feed_type)) { |
|
165 | + if ($el == 'rdf') { |
|
166 | 166 | $this->feed_type = RSS; |
167 | 167 | $this->feed_version = '1.0'; |
168 | 168 | } |
169 | - elseif ( $el == 'rss' ) { |
|
169 | + elseif ($el == 'rss') { |
|
170 | 170 | $this->feed_type = RSS; |
171 | 171 | $this->feed_version = $attrs['version']; |
172 | 172 | } |
173 | - elseif ( $el == 'feed' ) { |
|
173 | + elseif ($el == 'feed') { |
|
174 | 174 | $this->feed_type = ATOM; |
175 | 175 | $this->feed_version = $attrs['version']; |
176 | 176 | $this->inchannel = true; |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | return; |
179 | 179 | } |
180 | 180 | |
181 | - if ( $el == 'channel' ) |
|
181 | + if ($el == 'channel') |
|
182 | 182 | { |
183 | 183 | $this->inchannel = true; |
184 | 184 | } |
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
185 | + elseif ($el == 'item' or $el == 'entry') |
|
186 | 186 | { |
187 | 187 | $this->initem = true; |
188 | - if ( isset($attrs['rdf:about']) ) { |
|
188 | + if (isset($attrs['rdf:about'])) { |
|
189 | 189 | $this->current_item['about'] = $attrs['rdf:about']; |
190 | 190 | } |
191 | 191 | } |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | # handle atom content constructs |
212 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
212 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
213 | 213 | { |
214 | 214 | // avoid clashing w/ RSS mod_content |
215 | - if ($el == 'content' ) { |
|
215 | + if ($el == 'content') { |
|
216 | 216 | $el = 'atom_content'; |
217 | 217 | } |
218 | 218 | |
@@ -222,31 +222,31 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
225 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
225 | + elseif ($this->feed_type == ATOM and $this->incontent) |
|
226 | 226 | { |
227 | 227 | // if tags are inlined, then flatten |
228 | 228 | $attrs_str = join(' ', |
229 | 229 | array_map('map_attrs', |
230 | 230 | array_keys($attrs), |
231 | - array_values($attrs) ) ); |
|
231 | + array_values($attrs))); |
|
232 | 232 | |
233 | - $this->append_content( "<$element $attrs_str>" ); |
|
233 | + $this->append_content("<$element $attrs_str>"); |
|
234 | 234 | |
235 | - array_unshift( $this->stack, $el ); |
|
235 | + array_unshift($this->stack, $el); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | // Atom support many links per containging element. |
239 | 239 | // Magpie treats link elements of type rel='alternate' |
240 | 240 | // as being equivalent to RSS's simple link element. |
241 | 241 | // |
242 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
242 | + elseif ($this->feed_type == ATOM and $el == 'link') |
|
243 | 243 | { |
244 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
244 | + if (isset($attrs['rel']) and $attrs['rel'] == 'alternate') |
|
245 | 245 | { |
246 | 246 | $link_el = 'link'; |
247 | 247 | } |
248 | 248 | else { |
249 | - $link_el = 'link_' . $attrs['rel']; |
|
249 | + $link_el = 'link_'.$attrs['rel']; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | $this->append($link_el, $attrs['href']); |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - function feed_cdata ($p, $text) { |
|
262 | + function feed_cdata($p, $text) { |
|
263 | 263 | |
264 | 264 | if ($this->feed_type == ATOM and $this->incontent) |
265 | 265 | { |
266 | - $this->append_content( $text ); |
|
266 | + $this->append_content($text); |
|
267 | 267 | } |
268 | 268 | else { |
269 | 269 | $current_el = join('_', array_reverse($this->stack)); |
@@ -271,35 +271,35 @@ discard block |
||
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - function feed_end_element ($p, $el) { |
|
274 | + function feed_end_element($p, $el) { |
|
275 | 275 | $el = strtolower($el); |
276 | 276 | |
277 | - if ( $el == 'item' or $el == 'entry' ) |
|
277 | + if ($el == 'item' or $el == 'entry') |
|
278 | 278 | { |
279 | 279 | $this->items[] = $this->current_item; |
280 | 280 | $this->current_item = array(); |
281 | 281 | $this->initem = false; |
282 | 282 | } |
283 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
283 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput') |
|
284 | 284 | { |
285 | 285 | $this->intextinput = false; |
286 | 286 | } |
287 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
287 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image') |
|
288 | 288 | { |
289 | 289 | $this->inimage = false; |
290 | 290 | } |
291 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
291 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
292 | 292 | { |
293 | 293 | $this->incontent = false; |
294 | 294 | } |
295 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
295 | + elseif ($el == 'channel' or $el == 'feed') |
|
296 | 296 | { |
297 | 297 | $this->inchannel = false; |
298 | 298 | } |
299 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
299 | + elseif ($this->feed_type == ATOM and $this->incontent) { |
|
300 | 300 | // balance tags properly |
301 | 301 | // note: i don't think this is actually neccessary |
302 | - if ( $this->stack[0] == $el ) |
|
302 | + if ($this->stack[0] == $el) |
|
303 | 303 | { |
304 | 304 | $this->append_content("</$el>"); |
305 | 305 | } |
@@ -307,18 +307,18 @@ discard block |
||
307 | 307 | $this->append_content("<$el />"); |
308 | 308 | } |
309 | 309 | |
310 | - array_shift( $this->stack ); |
|
310 | + array_shift($this->stack); |
|
311 | 311 | } |
312 | 312 | else { |
313 | - array_shift( $this->stack ); |
|
313 | + array_shift($this->stack); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->current_namespace = false; |
317 | 317 | } |
318 | 318 | |
319 | - function concat (&$str1, $str2="") { |
|
320 | - if (!isset($str1) ) { |
|
321 | - $str1=""; |
|
319 | + function concat(&$str1, $str2 = "") { |
|
320 | + if (!isset($str1)) { |
|
321 | + $str1 = ""; |
|
322 | 322 | } |
323 | 323 | $str1 .= $str2; |
324 | 324 | } |
@@ -326,11 +326,11 @@ discard block |
||
326 | 326 | |
327 | 327 | |
328 | 328 | function append_content($text) { |
329 | - if ( $this->initem ) { |
|
330 | - $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
329 | + if ($this->initem) { |
|
330 | + $this->concat($this->current_item[$this->incontent], $text); |
|
331 | 331 | } |
332 | - elseif ( $this->inchannel ) { |
|
333 | - $this->concat( $this->channel[ $this->incontent ], $text ); |
|
332 | + elseif ($this->inchannel) { |
|
333 | + $this->concat($this->channel[$this->incontent], $text); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -339,61 +339,61 @@ discard block |
||
339 | 339 | if (!$el) { |
340 | 340 | return; |
341 | 341 | } |
342 | - if ( $this->current_namespace ) |
|
342 | + if ($this->current_namespace) |
|
343 | 343 | { |
344 | - if ( $this->initem ) { |
|
344 | + if ($this->initem) { |
|
345 | 345 | $this->concat( |
346 | - $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
346 | + $this->current_item[$this->current_namespace][$el], $text); |
|
347 | 347 | } |
348 | 348 | elseif ($this->inchannel) { |
349 | 349 | $this->concat( |
350 | - $this->channel[ $this->current_namespace][ $el ], $text ); |
|
350 | + $this->channel[$this->current_namespace][$el], $text ); |
|
351 | 351 | } |
352 | 352 | elseif ($this->intextinput) { |
353 | 353 | $this->concat( |
354 | - $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
354 | + $this->textinput[$this->current_namespace][$el], $text ); |
|
355 | 355 | } |
356 | 356 | elseif ($this->inimage) { |
357 | 357 | $this->concat( |
358 | - $this->image[ $this->current_namespace ][ $el ], $text ); |
|
358 | + $this->image[$this->current_namespace][$el], $text ); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | else { |
362 | - if ( $this->initem ) { |
|
362 | + if ($this->initem) { |
|
363 | 363 | $this->concat( |
364 | - $this->current_item[ $el ], $text); |
|
364 | + $this->current_item[$el], $text); |
|
365 | 365 | } |
366 | 366 | elseif ($this->intextinput) { |
367 | 367 | $this->concat( |
368 | - $this->textinput[ $el ], $text ); |
|
368 | + $this->textinput[$el], $text ); |
|
369 | 369 | } |
370 | 370 | elseif ($this->inimage) { |
371 | 371 | $this->concat( |
372 | - $this->image[ $el ], $text ); |
|
372 | + $this->image[$el], $text ); |
|
373 | 373 | } |
374 | 374 | elseif ($this->inchannel) { |
375 | 375 | $this->concat( |
376 | - $this->channel[ $el ], $text ); |
|
376 | + $this->channel[$el], $text ); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - function normalize () { |
|
382 | + function normalize() { |
|
383 | 383 | // if atom populate rss fields |
384 | - if ( $this->is_atom() ) { |
|
384 | + if ($this->is_atom()) { |
|
385 | 385 | $this->channel['description'] = $this->channel['tagline']; |
386 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
386 | + for ($i = 0; $i<count($this->items); $i++) { |
|
387 | 387 | $item = $this->items[$i]; |
388 | - if ( isset($item['summary']) ) |
|
388 | + if (isset($item['summary'])) |
|
389 | 389 | $item['description'] = $item['summary']; |
390 | - if ( isset($item['atom_content'])) |
|
390 | + if (isset($item['atom_content'])) |
|
391 | 391 | $item['content']['encoded'] = $item['atom_content']; |
392 | 392 | |
393 | - $atom_date = (isset($item['issued']) ) ? $item['issued'] : @$item['modified']; |
|
394 | - if ( $atom_date ) { |
|
393 | + $atom_date = (isset($item['issued'])) ? $item['issued'] : @$item['modified']; |
|
394 | + if ($atom_date) { |
|
395 | 395 | $epoch = @parse_w3cdtf($atom_date); |
396 | - if ($epoch and $epoch > 0) { |
|
396 | + if ($epoch and $epoch>0) { |
|
397 | 397 | $item['date_timestamp'] = $epoch; |
398 | 398 | } |
399 | 399 | } |
@@ -401,24 +401,24 @@ discard block |
||
401 | 401 | $this->items[$i] = $item; |
402 | 402 | } |
403 | 403 | } |
404 | - elseif ( $this->is_rss() ) { |
|
404 | + elseif ($this->is_rss()) { |
|
405 | 405 | $this->channel['tagline'] = $this->channel['description']; |
406 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
406 | + for ($i = 0; $i<count($this->items); $i++) { |
|
407 | 407 | $item = $this->items[$i]; |
408 | - if ( isset($item['description'])) |
|
408 | + if (isset($item['description'])) |
|
409 | 409 | $item['summary'] = $item['description']; |
410 | - if ( isset($item['content']['encoded'] ) ) |
|
410 | + if (isset($item['content']['encoded'])) |
|
411 | 411 | $item['atom_content'] = $item['content']['encoded']; |
412 | 412 | |
413 | - if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
|
413 | + if ($this->is_rss() == '1.0' and isset($item['dc']['date'])) { |
|
414 | 414 | $epoch = @parse_w3cdtf($item['dc']['date']); |
415 | - if ($epoch and $epoch > 0) { |
|
415 | + if ($epoch and $epoch>0) { |
|
416 | 416 | $item['date_timestamp'] = $epoch; |
417 | 417 | } |
418 | 418 | } |
419 | - elseif ( isset($item['pubdate']) ) { |
|
419 | + elseif (isset($item['pubdate'])) { |
|
420 | 420 | $epoch = @strtotime($item['pubdate']); |
421 | - if ($epoch > 0) { |
|
421 | + if ($epoch>0) { |
|
422 | 422 | $item['date_timestamp'] = $epoch; |
423 | 423 | } |
424 | 424 | } |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | |
432 | - function is_rss () { |
|
433 | - if ( $this->feed_type == RSS ) { |
|
432 | + function is_rss() { |
|
433 | + if ($this->feed_type == RSS) { |
|
434 | 434 | return $this->feed_version; |
435 | 435 | } |
436 | 436 | else { |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | |
441 | 441 | function is_atom() { |
442 | - if ( $this->feed_type == ATOM ) { |
|
442 | + if ($this->feed_type == ATOM) { |
|
443 | 443 | return $this->feed_version; |
444 | 444 | } |
445 | 445 | else { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | * |
453 | 453 | */ |
454 | 454 | function create_parser($source, $out_enc, $in_enc, $detect) { |
455 | - if ( substr(phpversion(),0,1) == 5) { |
|
455 | + if (substr(phpversion(), 0, 1) == 5) { |
|
456 | 456 | $parser = $this->php5_create_parser($in_enc, $detect); |
457 | 457 | } |
458 | 458 | else { |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | */ |
478 | 478 | function php5_create_parser($in_enc, $detect) { |
479 | 479 | // by default php5 does a fine job of detecting input encodings |
480 | - if(!$detect && $in_enc) { |
|
480 | + if (!$detect && $in_enc) { |
|
481 | 481 | return xml_parser_create($in_enc); |
482 | 482 | } |
483 | 483 | else { |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | * |
502 | 502 | */ |
503 | 503 | function php4_create_parser($source, $in_enc, $detect) { |
504 | - if ( !$detect ) { |
|
504 | + if (!$detect) { |
|
505 | 505 | return array(xml_parser_create($in_enc), $source); |
506 | 506 | } |
507 | 507 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | |
554 | 554 | function known_encoding($enc) { |
555 | 555 | $enc = strtoupper($enc); |
556 | - if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
|
556 | + if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
557 | 557 | return $enc; |
558 | 558 | } |
559 | 559 | else { |
@@ -561,22 +561,22 @@ discard block |
||
561 | 561 | } |
562 | 562 | } |
563 | 563 | |
564 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
564 | + function error($errormsg, $lvl = E_USER_WARNING) { |
|
565 | 565 | // append PHP's error message if track_errors enabled |
566 | - if ( !empty($php_errormsg) ) { |
|
566 | + if (!empty($php_errormsg)) { |
|
567 | 567 | $errormsg .= " ($php_errormsg)"; |
568 | 568 | } |
569 | - if ( MAGPIE_DEBUG ) { |
|
570 | - trigger_error( $errormsg, $lvl); |
|
569 | + if (MAGPIE_DEBUG) { |
|
570 | + trigger_error($errormsg, $lvl); |
|
571 | 571 | } |
572 | 572 | else { |
573 | - error_log( $errormsg, 0); |
|
573 | + error_log($errormsg, 0); |
|
574 | 574 | } |
575 | 575 | |
576 | - $notices = E_USER_NOTICE|E_NOTICE; |
|
577 | - if ( $lvl&$notices ) { |
|
576 | + $notices = E_USER_NOTICE | E_NOTICE; |
|
577 | + if ($lvl & $notices) { |
|
578 | 578 | $this->WARNING = $errormsg; |
579 | - } else { |
|
579 | + }else { |
|
580 | 580 | $this->ERROR = $errormsg; |
581 | 581 | } |
582 | 582 | } |
@@ -589,41 +589,41 @@ discard block |
||
589 | 589 | } |
590 | 590 | |
591 | 591 | |
592 | -function parse_w3cdtf ( $date_str ) { |
|
592 | +function parse_w3cdtf($date_str) { |
|
593 | 593 | |
594 | 594 | # regex to match wc3dtf |
595 | 595 | $pat = "/(\d{4})-(\d{2})-(\d{2})[T]?(\d{2})?[:]?(\d{2})?(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
596 | 596 | |
597 | - if ( preg_match( $pat, $date_str, $match ) ) { |
|
598 | - list( $year, $month, $day, $hours, $minutes, $seconds) = |
|
599 | - array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
597 | + if (preg_match($pat, $date_str, $match)) { |
|
598 | + list($year, $month, $day, $hours, $minutes, $seconds) = |
|
599 | + array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
600 | 600 | |
601 | 601 | # calc epoch for current date assuming GMT |
602 | - $epoch = gmmktime( intval($hours), intval($minutes), intval($seconds), intval($month), intval($day), intval($year)); |
|
602 | + $epoch = gmmktime(intval($hours), intval($minutes), intval($seconds), intval($month), intval($day), intval($year)); |
|
603 | 603 | |
604 | 604 | $offset = 0; |
605 | - if ( $match[10] == 'Z' ) { |
|
605 | + if ($match[10] == 'Z') { |
|
606 | 606 | # zulu time, aka GMT |
607 | 607 | } |
608 | 608 | else { |
609 | - list( $tz_mod, $tz_hour, $tz_min ) = |
|
610 | - array( $match[8], $match[9], $match[10]); |
|
609 | + list($tz_mod, $tz_hour, $tz_min) = |
|
610 | + array($match[8], $match[9], $match[10]); |
|
611 | 611 | |
612 | 612 | # zero out the variables |
613 | - if ( ! $tz_hour ) { $tz_hour = 0; } |
|
614 | - if ( ! $tz_min ) { $tz_min = 0; } |
|
613 | + if (!$tz_hour) { $tz_hour = 0; } |
|
614 | + if (!$tz_min) { $tz_min = 0; } |
|
615 | 615 | |
616 | 616 | $offset_secs = (($tz_hour*60)+$tz_min)*60; |
617 | 617 | |
618 | 618 | # is timezone ahead of GMT? then subtract offset |
619 | 619 | # |
620 | - if ( $tz_mod == '+' ) { |
|
621 | - $offset_secs = $offset_secs * -1; |
|
620 | + if ($tz_mod == '+') { |
|
621 | + $offset_secs = $offset_secs*-1; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | $offset = $offset_secs; |
625 | 625 | } |
626 | - $epoch = $epoch + $offset; |
|
626 | + $epoch = $epoch+$offset; |
|
627 | 627 | return $epoch; |
628 | 628 | } |
629 | 629 | else { |
@@ -165,12 +165,10 @@ discard block |
||
165 | 165 | if ( $el == 'rdf' ) { |
166 | 166 | $this->feed_type = RSS; |
167 | 167 | $this->feed_version = '1.0'; |
168 | - } |
|
169 | - elseif ( $el == 'rss' ) { |
|
168 | + } elseif ( $el == 'rss' ) { |
|
170 | 169 | $this->feed_type = RSS; |
171 | 170 | $this->feed_version = $attrs['version']; |
172 | - } |
|
173 | - elseif ( $el == 'feed' ) { |
|
171 | + } elseif ( $el == 'feed' ) { |
|
174 | 172 | $this->feed_type = ATOM; |
175 | 173 | $this->feed_version = $attrs['version']; |
176 | 174 | $this->inchannel = true; |
@@ -181,8 +179,7 @@ discard block |
||
181 | 179 | if ( $el == 'channel' ) |
182 | 180 | { |
183 | 181 | $this->inchannel = true; |
184 | - } |
|
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
182 | + } elseif ($el == 'item' or $el == 'entry' ) |
|
186 | 183 | { |
187 | 184 | $this->initem = true; |
188 | 185 | if ( isset($attrs['rdf:about']) ) { |
@@ -198,9 +195,7 @@ discard block |
||
198 | 195 | $el == 'textinput' ) |
199 | 196 | { |
200 | 197 | $this->intextinput = true; |
201 | - } |
|
202 | - |
|
203 | - elseif ( |
|
198 | + } elseif ( |
|
204 | 199 | $this->feed_type == RSS and |
205 | 200 | $this->current_namespace == '' and |
206 | 201 | $el == 'image' ) |
@@ -244,8 +239,7 @@ discard block |
||
244 | 239 | if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
245 | 240 | { |
246 | 241 | $link_el = 'link'; |
247 | - } |
|
248 | - else { |
|
242 | + } else { |
|
249 | 243 | $link_el = 'link_' . $attrs['rel']; |
250 | 244 | } |
251 | 245 | |
@@ -264,8 +258,7 @@ discard block |
||
264 | 258 | if ($this->feed_type == ATOM and $this->incontent) |
265 | 259 | { |
266 | 260 | $this->append_content( $text ); |
267 | - } |
|
268 | - else { |
|
261 | + } else { |
|
269 | 262 | $current_el = join('_', array_reverse($this->stack)); |
270 | 263 | $this->append($current_el, $text); |
271 | 264 | } |
@@ -279,37 +272,30 @@ discard block |
||
279 | 272 | $this->items[] = $this->current_item; |
280 | 273 | $this->current_item = array(); |
281 | 274 | $this->initem = false; |
282 | - } |
|
283 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
275 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
284 | 276 | { |
285 | 277 | $this->intextinput = false; |
286 | - } |
|
287 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
278 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
288 | 279 | { |
289 | 280 | $this->inimage = false; |
290 | - } |
|
291 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
281 | + } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
292 | 282 | { |
293 | 283 | $this->incontent = false; |
294 | - } |
|
295 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
284 | + } elseif ($el == 'channel' or $el == 'feed' ) |
|
296 | 285 | { |
297 | 286 | $this->inchannel = false; |
298 | - } |
|
299 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
287 | + } elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
300 | 288 | // balance tags properly |
301 | 289 | // note: i don't think this is actually neccessary |
302 | 290 | if ( $this->stack[0] == $el ) |
303 | 291 | { |
304 | 292 | $this->append_content("</$el>"); |
305 | - } |
|
306 | - else { |
|
293 | + } else { |
|
307 | 294 | $this->append_content("<$el />"); |
308 | 295 | } |
309 | 296 | |
310 | 297 | array_shift( $this->stack ); |
311 | - } |
|
312 | - else { |
|
298 | + } else { |
|
313 | 299 | array_shift( $this->stack ); |
314 | 300 | } |
315 | 301 | |
@@ -328,8 +314,7 @@ discard block |
||
328 | 314 | function append_content($text) { |
329 | 315 | if ( $this->initem ) { |
330 | 316 | $this->concat( $this->current_item[ $this->incontent ], $text ); |
331 | - } |
|
332 | - elseif ( $this->inchannel ) { |
|
317 | + } elseif ( $this->inchannel ) { |
|
333 | 318 | $this->concat( $this->channel[ $this->incontent ], $text ); |
334 | 319 | } |
335 | 320 | } |
@@ -344,34 +329,27 @@ discard block |
||
344 | 329 | if ( $this->initem ) { |
345 | 330 | $this->concat( |
346 | 331 | $this->current_item[ $this->current_namespace ][ $el ], $text); |
347 | - } |
|
348 | - elseif ($this->inchannel) { |
|
332 | + } elseif ($this->inchannel) { |
|
349 | 333 | $this->concat( |
350 | 334 | $this->channel[ $this->current_namespace][ $el ], $text ); |
351 | - } |
|
352 | - elseif ($this->intextinput) { |
|
335 | + } elseif ($this->intextinput) { |
|
353 | 336 | $this->concat( |
354 | 337 | $this->textinput[ $this->current_namespace][ $el ], $text ); |
355 | - } |
|
356 | - elseif ($this->inimage) { |
|
338 | + } elseif ($this->inimage) { |
|
357 | 339 | $this->concat( |
358 | 340 | $this->image[ $this->current_namespace ][ $el ], $text ); |
359 | 341 | } |
360 | - } |
|
361 | - else { |
|
342 | + } else { |
|
362 | 343 | if ( $this->initem ) { |
363 | 344 | $this->concat( |
364 | 345 | $this->current_item[ $el ], $text); |
365 | - } |
|
366 | - elseif ($this->intextinput) { |
|
346 | + } elseif ($this->intextinput) { |
|
367 | 347 | $this->concat( |
368 | 348 | $this->textinput[ $el ], $text ); |
369 | - } |
|
370 | - elseif ($this->inimage) { |
|
349 | + } elseif ($this->inimage) { |
|
371 | 350 | $this->concat( |
372 | 351 | $this->image[ $el ], $text ); |
373 | - } |
|
374 | - elseif ($this->inchannel) { |
|
352 | + } elseif ($this->inchannel) { |
|
375 | 353 | $this->concat( |
376 | 354 | $this->channel[ $el ], $text ); |
377 | 355 | } |
@@ -385,10 +363,12 @@ discard block |
||
385 | 363 | $this->channel['description'] = $this->channel['tagline']; |
386 | 364 | for ( $i = 0; $i < count($this->items); $i++) { |
387 | 365 | $item = $this->items[$i]; |
388 | - if ( isset($item['summary']) ) |
|
389 | - $item['description'] = $item['summary']; |
|
390 | - if ( isset($item['atom_content'])) |
|
391 | - $item['content']['encoded'] = $item['atom_content']; |
|
366 | + if ( isset($item['summary']) ) { |
|
367 | + $item['description'] = $item['summary']; |
|
368 | + } |
|
369 | + if ( isset($item['atom_content'])) { |
|
370 | + $item['content']['encoded'] = $item['atom_content']; |
|
371 | + } |
|
392 | 372 | |
393 | 373 | $atom_date = (isset($item['issued']) ) ? $item['issued'] : @$item['modified']; |
394 | 374 | if ( $atom_date ) { |
@@ -400,23 +380,23 @@ discard block |
||
400 | 380 | |
401 | 381 | $this->items[$i] = $item; |
402 | 382 | } |
403 | - } |
|
404 | - elseif ( $this->is_rss() ) { |
|
383 | + } elseif ( $this->is_rss() ) { |
|
405 | 384 | $this->channel['tagline'] = $this->channel['description']; |
406 | 385 | for ( $i = 0; $i < count($this->items); $i++) { |
407 | 386 | $item = $this->items[$i]; |
408 | - if ( isset($item['description'])) |
|
409 | - $item['summary'] = $item['description']; |
|
410 | - if ( isset($item['content']['encoded'] ) ) |
|
411 | - $item['atom_content'] = $item['content']['encoded']; |
|
387 | + if ( isset($item['description'])) { |
|
388 | + $item['summary'] = $item['description']; |
|
389 | + } |
|
390 | + if ( isset($item['content']['encoded'] ) ) { |
|
391 | + $item['atom_content'] = $item['content']['encoded']; |
|
392 | + } |
|
412 | 393 | |
413 | 394 | if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
414 | 395 | $epoch = @parse_w3cdtf($item['dc']['date']); |
415 | 396 | if ($epoch and $epoch > 0) { |
416 | 397 | $item['date_timestamp'] = $epoch; |
417 | 398 | } |
418 | - } |
|
419 | - elseif ( isset($item['pubdate']) ) { |
|
399 | + } elseif ( isset($item['pubdate']) ) { |
|
420 | 400 | $epoch = @strtotime($item['pubdate']); |
421 | 401 | if ($epoch > 0) { |
422 | 402 | $item['date_timestamp'] = $epoch; |
@@ -432,8 +412,7 @@ discard block |
||
432 | 412 | function is_rss () { |
433 | 413 | if ( $this->feed_type == RSS ) { |
434 | 414 | return $this->feed_version; |
435 | - } |
|
436 | - else { |
|
415 | + } else { |
|
437 | 416 | return false; |
438 | 417 | } |
439 | 418 | } |
@@ -441,8 +420,7 @@ discard block |
||
441 | 420 | function is_atom() { |
442 | 421 | if ( $this->feed_type == ATOM ) { |
443 | 422 | return $this->feed_version; |
444 | - } |
|
445 | - else { |
|
423 | + } else { |
|
446 | 424 | return false; |
447 | 425 | } |
448 | 426 | } |
@@ -454,8 +432,7 @@ discard block |
||
454 | 432 | function create_parser($source, $out_enc, $in_enc, $detect) { |
455 | 433 | if ( substr(phpversion(),0,1) == 5) { |
456 | 434 | $parser = $this->php5_create_parser($in_enc, $detect); |
457 | - } |
|
458 | - else { |
|
435 | + } else { |
|
459 | 436 | list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
460 | 437 | } |
461 | 438 | if ($out_enc) { |
@@ -479,8 +456,7 @@ discard block |
||
479 | 456 | // by default php5 does a fine job of detecting input encodings |
480 | 457 | if(!$detect && $in_enc) { |
481 | 458 | return xml_parser_create($in_enc); |
482 | - } |
|
483 | - else { |
|
459 | + } else { |
|
484 | 460 | return xml_parser_create(''); |
485 | 461 | } |
486 | 462 | } |
@@ -509,8 +485,7 @@ discard block |
||
509 | 485 | if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
510 | 486 | $in_enc = strtoupper($m[1]); |
511 | 487 | $this->source_encoding = $in_enc; |
512 | - } |
|
513 | - else { |
|
488 | + } else { |
|
514 | 489 | $in_enc = 'UTF-8'; |
515 | 490 | } |
516 | 491 | } |
@@ -555,8 +530,7 @@ discard block |
||
555 | 530 | $enc = strtoupper($enc); |
556 | 531 | if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
557 | 532 | return $enc; |
558 | - } |
|
559 | - else { |
|
533 | + } else { |
|
560 | 534 | return false; |
561 | 535 | } |
562 | 536 | } |
@@ -568,8 +542,7 @@ discard block |
||
568 | 542 | } |
569 | 543 | if ( MAGPIE_DEBUG ) { |
570 | 544 | trigger_error( $errormsg, $lvl); |
571 | - } |
|
572 | - else { |
|
545 | + } else { |
|
573 | 546 | error_log( $errormsg, 0); |
574 | 547 | } |
575 | 548 | |
@@ -604,8 +577,7 @@ discard block |
||
604 | 577 | $offset = 0; |
605 | 578 | if ( $match[10] == 'Z' ) { |
606 | 579 | # zulu time, aka GMT |
607 | - } |
|
608 | - else { |
|
580 | + } else { |
|
609 | 581 | list( $tz_mod, $tz_hour, $tz_min ) = |
610 | 582 | array( $match[8], $match[9], $match[10]); |
611 | 583 | |
@@ -625,8 +597,7 @@ discard block |
||
625 | 597 | } |
626 | 598 | $epoch = $epoch + $offset; |
627 | 599 | return $epoch; |
628 | - } |
|
629 | - else { |
|
600 | + } else { |
|
630 | 601 | return -1; |
631 | 602 | } |
632 | 603 | } |
@@ -93,6 +93,10 @@ |
||
93 | 93 | $this->version = $version; |
94 | 94 | } |
95 | 95 | |
96 | + /** |
|
97 | + * @param string $var |
|
98 | + * @param FeedImage $val |
|
99 | + */ |
|
96 | 100 | function setVar($var, $val, $encoding = false) |
97 | 101 | { |
98 | 102 | if(!empty($encoding)) $val = $this->convert_encoding($val); |
@@ -84,63 +84,63 @@ |
||
84 | 84 | if(!class_exists("Xmlfeed")){ |
85 | 85 | class Bxmlfeed extends UniversalFeedCreator |
86 | 86 | { |
87 | - var $version; |
|
88 | - var $filename= ""; |
|
89 | - |
|
90 | - function Bxmlfeed($version) |
|
91 | - { |
|
92 | - $this->filename= XOOPS_CACHE_PATH."/feed.xml"; |
|
93 | - $this->version = $version; |
|
94 | - } |
|
95 | - |
|
96 | - function setVar($var, $val, $encoding = false) |
|
97 | - { |
|
98 | - if(!empty($encoding)) $val = $this->convert_encoding($val); |
|
99 | - $this->$var = $val; |
|
100 | - } |
|
87 | + var $version; |
|
88 | + var $filename= ""; |
|
89 | + |
|
90 | + function Bxmlfeed($version) |
|
91 | + { |
|
92 | + $this->filename= XOOPS_CACHE_PATH."/feed.xml"; |
|
93 | + $this->version = $version; |
|
94 | + } |
|
95 | + |
|
96 | + function setVar($var, $val, $encoding = false) |
|
97 | + { |
|
98 | + if(!empty($encoding)) $val = $this->convert_encoding($val); |
|
99 | + $this->$var = $val; |
|
100 | + } |
|
101 | 101 | |
102 | - function convert_encoding($val) |
|
103 | - { |
|
104 | - if(is_array($val)){ |
|
105 | - foreach(array_keys($val) as $key){ |
|
106 | - $val[$key] = $this->convert_encoding($val[$key]); |
|
107 | - } |
|
108 | - }else{ |
|
109 | - $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
|
110 | - } |
|
111 | - return $val; |
|
112 | - } |
|
113 | - |
|
114 | - function getVar($var) |
|
115 | - { |
|
116 | - return $this->$var; |
|
117 | - } |
|
118 | - |
|
119 | - function setImage(&$img) |
|
120 | - { |
|
121 | - $image = new FeedImage(); |
|
122 | - foreach($img as $key=>$val){ |
|
123 | - $image->$key = $this->convert_encoding($val); |
|
124 | - } |
|
125 | - $this->setVar("image", $image); |
|
126 | - } |
|
127 | - |
|
128 | - function _addItem(&$itm) |
|
129 | - { |
|
130 | - $item = new FeedItem(); |
|
131 | - foreach($itm as $key=>$val){ |
|
132 | - $item->$key = $this->convert_encoding($val); |
|
133 | - } |
|
134 | - $this->addItem($item); |
|
135 | - } |
|
136 | - |
|
137 | - function addItems(&$items) |
|
138 | - { |
|
139 | - if(!is_array($items) || count($items)==0) return; |
|
140 | - foreach($items as $item){ |
|
141 | - $this->_addItem($item); |
|
142 | - } |
|
143 | - } |
|
102 | + function convert_encoding($val) |
|
103 | + { |
|
104 | + if(is_array($val)){ |
|
105 | + foreach(array_keys($val) as $key){ |
|
106 | + $val[$key] = $this->convert_encoding($val[$key]); |
|
107 | + } |
|
108 | + }else{ |
|
109 | + $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
|
110 | + } |
|
111 | + return $val; |
|
112 | + } |
|
113 | + |
|
114 | + function getVar($var) |
|
115 | + { |
|
116 | + return $this->$var; |
|
117 | + } |
|
118 | + |
|
119 | + function setImage(&$img) |
|
120 | + { |
|
121 | + $image = new FeedImage(); |
|
122 | + foreach($img as $key=>$val){ |
|
123 | + $image->$key = $this->convert_encoding($val); |
|
124 | + } |
|
125 | + $this->setVar("image", $image); |
|
126 | + } |
|
127 | + |
|
128 | + function _addItem(&$itm) |
|
129 | + { |
|
130 | + $item = new FeedItem(); |
|
131 | + foreach($itm as $key=>$val){ |
|
132 | + $item->$key = $this->convert_encoding($val); |
|
133 | + } |
|
134 | + $this->addItem($item); |
|
135 | + } |
|
136 | + |
|
137 | + function addItems(&$items) |
|
138 | + { |
|
139 | + if(!is_array($items) || count($items)==0) return; |
|
140 | + foreach($items as $item){ |
|
141 | + $this->_addItem($item); |
|
142 | + } |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | // Project: Article Project // |
26 | 26 | // ------------------------------------------------------------------------ // |
27 | 27 | |
28 | -if (!defined('XOOPS_ROOT_PATH')){ exit(); } |
|
28 | +if (!defined('XOOPS_ROOT_PATH')) { exit(); } |
|
29 | 29 | include_once dirname(dirname(__FILE__))."/include/vars.php"; |
30 | 30 | mod_loadFunctions("", $GLOBALS["moddirname"]); |
31 | 31 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | |
67 | 67 | // your local timezone, set to "" to disable or for GMT |
68 | 68 | $server_TZ = abs(intval($GLOBALS['xoopsConfig']['server_TZ']*3600.0)); |
69 | -$prefix = ($GLOBALS['xoopsConfig']['server_TZ']<0)?"-":"+"; |
|
70 | -$TIME_ZONE = $prefix.date("H:i",$server_TZ); |
|
69 | +$prefix = ($GLOBALS['xoopsConfig']['server_TZ']<0) ? "-" : "+"; |
|
70 | +$TIME_ZONE = $prefix.date("H:i", $server_TZ); |
|
71 | 71 | define("TIME_ZONE", $TIME_ZONE); |
72 | 72 | // Version string. |
73 | 73 | define("FEEDCREATOR_VERSION", "ARTICLE @ XOOPS powered by FeedCreator"); |
@@ -81,31 +81,31 @@ discard block |
||
81 | 81 | * @return type description |
82 | 82 | * @link |
83 | 83 | */ |
84 | -if(!class_exists("Xmlfeed")){ |
|
84 | +if (!class_exists("Xmlfeed")) { |
|
85 | 85 | class Bxmlfeed extends UniversalFeedCreator |
86 | 86 | { |
87 | 87 | var $version; |
88 | - var $filename= ""; |
|
88 | + var $filename = ""; |
|
89 | 89 | |
90 | 90 | function Bxmlfeed($version) |
91 | 91 | { |
92 | - $this->filename= XOOPS_CACHE_PATH."/feed.xml"; |
|
92 | + $this->filename = XOOPS_CACHE_PATH."/feed.xml"; |
|
93 | 93 | $this->version = $version; |
94 | 94 | } |
95 | 95 | |
96 | 96 | function setVar($var, $val, $encoding = false) |
97 | 97 | { |
98 | - if(!empty($encoding)) $val = $this->convert_encoding($val); |
|
98 | + if (!empty($encoding)) $val = $this->convert_encoding($val); |
|
99 | 99 | $this->$var = $val; |
100 | 100 | } |
101 | 101 | |
102 | 102 | function convert_encoding($val) |
103 | 103 | { |
104 | - if(is_array($val)){ |
|
105 | - foreach(array_keys($val) as $key){ |
|
104 | + if (is_array($val)) { |
|
105 | + foreach (array_keys($val) as $key) { |
|
106 | 106 | $val[$key] = $this->convert_encoding($val[$key]); |
107 | 107 | } |
108 | - }else{ |
|
108 | + }else { |
|
109 | 109 | $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
110 | 110 | } |
111 | 111 | return $val; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function setImage(&$img) |
120 | 120 | { |
121 | 121 | $image = new FeedImage(); |
122 | - foreach($img as $key=>$val){ |
|
122 | + foreach ($img as $key=>$val) { |
|
123 | 123 | $image->$key = $this->convert_encoding($val); |
124 | 124 | } |
125 | 125 | $this->setVar("image", $image); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | function _addItem(&$itm) |
129 | 129 | { |
130 | 130 | $item = new FeedItem(); |
131 | - foreach($itm as $key=>$val){ |
|
131 | + foreach ($itm as $key=>$val) { |
|
132 | 132 | $item->$key = $this->convert_encoding($val); |
133 | 133 | } |
134 | 134 | $this->addItem($item); |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | |
137 | 137 | function addItems(&$items) |
138 | 138 | { |
139 | - if(!is_array($items) || count($items)==0) return; |
|
140 | - foreach($items as $item){ |
|
139 | + if (!is_array($items) || count($items) == 0) return; |
|
140 | + foreach ($items as $item) { |
|
141 | 141 | $this->_addItem($item); |
142 | 142 | } |
143 | 143 | } |
@@ -95,7 +95,9 @@ discard block |
||
95 | 95 | |
96 | 96 | function setVar($var, $val, $encoding = false) |
97 | 97 | { |
98 | - if(!empty($encoding)) $val = $this->convert_encoding($val); |
|
98 | + if(!empty($encoding)) { |
|
99 | + $val = $this->convert_encoding($val); |
|
100 | + } |
|
99 | 101 | $this->$var = $val; |
100 | 102 | } |
101 | 103 | |
@@ -105,7 +107,7 @@ discard block |
||
105 | 107 | foreach(array_keys($val) as $key){ |
106 | 108 | $val[$key] = $this->convert_encoding($val[$key]); |
107 | 109 | } |
108 | - }else{ |
|
110 | + } else{ |
|
109 | 111 | $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
110 | 112 | } |
111 | 113 | return $val; |
@@ -136,7 +138,9 @@ discard block |
||
136 | 138 | |
137 | 139 | function addItems(&$items) |
138 | 140 | { |
139 | - if(!is_array($items) || count($items)==0) return; |
|
141 | + if(!is_array($items) || count($items)==0) { |
|
142 | + return; |
|
143 | + } |
|
140 | 144 | foreach($items as $item){ |
141 | 145 | $this->_addItem($item); |
142 | 146 | } |
@@ -53,13 +53,6 @@ |
||
53 | 53 | * @param string $content string containing the RSS to be parsed |
54 | 54 | * |
55 | 55 | * |
56 | - * @param string $output_encoding output the parsed RSS in this character |
|
57 | - * set defaults to ISO-8859-1 as this is PHP's |
|
58 | - * default. |
|
59 | - * |
|
60 | - * @param string $input_encoding the character set of the incoming RSS source. |
|
61 | - * Leave blank and Magpie will try to figure it |
|
62 | - * out. |
|
63 | 56 | * |
64 | 57 | */ |
65 | 58 | function XmlParser ($content, $input_charset, $output_charset = _CHARSET, $tags = array()) |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | var $charset_in; |
48 | 48 | var $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 $output_encoding output the parsed RSS in this character |
|
57 | - * set defaults to ISO-8859-1 as this is PHP's |
|
58 | - * default. |
|
59 | - * |
|
60 | - * @param string $input_encoding the character set of the incoming RSS source. |
|
61 | - * Leave blank and Magpie will try to figure it |
|
62 | - * out. |
|
63 | - * |
|
64 | - */ |
|
65 | - function XmlParser ($content, $input_charset, $output_charset = _CHARSET, $tags = array()) |
|
66 | - { |
|
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 $output_encoding output the parsed RSS in this character |
|
57 | + * set defaults to ISO-8859-1 as this is PHP's |
|
58 | + * default. |
|
59 | + * |
|
60 | + * @param string $input_encoding the character set of the incoming RSS source. |
|
61 | + * Leave blank and Magpie will try to figure it |
|
62 | + * out. |
|
63 | + * |
|
64 | + */ |
|
65 | + function XmlParser ($content, $input_charset, $output_charset = _CHARSET, $tags = array()) |
|
66 | + { |
|
67 | 67 | if(!in_array(strtoupper($input_charset), array("UTF-8", "US-ASCII", "ISO-8859-1"))) { |
68 | 68 | $content = XoopsLocal::convert_encoding($content, "UTF-8", $input_charset); |
69 | 69 | $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
@@ -79,109 +79,109 @@ discard block |
||
79 | 79 | //xoops_message($this); |
80 | 80 | unset($this->content); |
81 | 81 | $this->encoding_convert($tags); |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - function is_atom() { |
|
85 | - if ( $this->feed_type == ATOM ) { |
|
86 | - $this->feed_version = empty($this->feed_version)?"0.3":$this->feed_version; |
|
87 | - return $this->feed_version; |
|
88 | - } |
|
89 | - else { |
|
90 | - return false; |
|
91 | - } |
|
92 | - } |
|
84 | + function is_atom() { |
|
85 | + if ( $this->feed_type == ATOM ) { |
|
86 | + $this->feed_version = empty($this->feed_version)?"0.3":$this->feed_version; |
|
87 | + return $this->feed_version; |
|
88 | + } |
|
89 | + else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - function normalize () { |
|
95 | - if ( $this->is_atom() ): |
|
96 | - if(empty($this->channel["tagline"])){ |
|
97 | - /* ATOM */ |
|
98 | - $this->channel["tagline"] = @$this->channel["subtitle"]; |
|
99 | - unset($this->channel["subtitle"]); |
|
100 | - } |
|
101 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
102 | - // ATOM time |
|
103 | - if($date = @$this->items[$i]['modified']) continue; |
|
104 | - if(empty($date)){ |
|
105 | - $date = @$this->items[$i]['updated']; |
|
106 | - } |
|
107 | - if(empty($date)){ |
|
108 | - $date = @$this->items[$i]['issued']; |
|
109 | - } |
|
110 | - if(empty($date)){ |
|
111 | - $date = @$this->items[$i]['created']; |
|
112 | - } |
|
113 | - if(empty($date)){ |
|
114 | - $date = @$this->items[$i]['created']; |
|
115 | - } |
|
116 | - $this->items[$i]['modified'] = $date; |
|
117 | - } |
|
118 | - elseif($this->is_rss() != '1.0'): |
|
119 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
120 | - if($date = @$this->items[$i]['pubdate']) continue; |
|
121 | - $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
122 | - } |
|
123 | - endif; |
|
124 | - parent::normalize(); |
|
125 | - /* ATOM */ |
|
126 | - if(empty($this->channel["language"]) && !empty($this->channel["dc"]["language"]) ) { |
|
94 | + function normalize () { |
|
95 | + if ( $this->is_atom() ): |
|
96 | + if(empty($this->channel["tagline"])){ |
|
97 | + /* ATOM */ |
|
98 | + $this->channel["tagline"] = @$this->channel["subtitle"]; |
|
99 | + unset($this->channel["subtitle"]); |
|
100 | + } |
|
101 | + for ( $i = 0; $i < count($this->items); $i++) { |
|
102 | + // ATOM time |
|
103 | + if($date = @$this->items[$i]['modified']) continue; |
|
104 | + if(empty($date)){ |
|
105 | + $date = @$this->items[$i]['updated']; |
|
106 | + } |
|
107 | + if(empty($date)){ |
|
108 | + $date = @$this->items[$i]['issued']; |
|
109 | + } |
|
110 | + if(empty($date)){ |
|
111 | + $date = @$this->items[$i]['created']; |
|
112 | + } |
|
113 | + if(empty($date)){ |
|
114 | + $date = @$this->items[$i]['created']; |
|
115 | + } |
|
116 | + $this->items[$i]['modified'] = $date; |
|
117 | + } |
|
118 | + elseif($this->is_rss() != '1.0'): |
|
119 | + for ( $i = 0; $i < count($this->items); $i++) { |
|
120 | + if($date = @$this->items[$i]['pubdate']) continue; |
|
121 | + $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
122 | + } |
|
123 | + endif; |
|
124 | + parent::normalize(); |
|
125 | + /* ATOM */ |
|
126 | + if(empty($this->channel["language"]) && !empty($this->channel["dc"]["language"]) ) { |
|
127 | 127 | $this->channel["language"] = $this->channel["dc"]["language"]; |
128 | 128 | unset($this->channel["dc"]["language"]); |
129 | 129 | } |
130 | - if(empty($this->channel["language"]) && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
130 | + if(empty($this->channel["language"]) && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
131 | 131 | $this->channel["language"] = $match[1]; |
132 | 132 | } |
133 | - if(empty($this->channel["language"]) && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
133 | + if(empty($this->channel["language"]) && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
134 | 134 | $this->channel["language"] = $match[1]; |
135 | 135 | } |
136 | 136 | /* remove to avoid redundant encoding conversion */ |
137 | - if(!empty($this->channel["tagline"])){ |
|
138 | - unset($this->channel["tagline"]); |
|
139 | - } |
|
137 | + if(!empty($this->channel["tagline"])){ |
|
138 | + unset($this->channel["tagline"]); |
|
139 | + } |
|
140 | 140 | |
141 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
142 | - if($date_timestamp = @$this->items[$i]['date_timestamp']) continue; |
|
143 | - if($date_timestamp = @$this->items[$i]['pubdate']){ |
|
144 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
145 | - }elseif($date_timestamp = @$this->items[$i]['dc']['date']){ |
|
146 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
147 | - }else{ |
|
148 | - $this->items[$i]['date_timestamp'] = time(); |
|
149 | - } |
|
150 | - if(!is_numeric($this->items[$i]['date_timestamp'])){ |
|
151 | - if($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
152 | - $this->items[$i]['date_timestamp'] = $date; |
|
153 | - }elseif($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
154 | - $this->items[$i]['date_timestamp'] = $date; |
|
155 | - } |
|
156 | - } |
|
141 | + for ( $i = 0; $i < count($this->items); $i++) { |
|
142 | + if($date_timestamp = @$this->items[$i]['date_timestamp']) continue; |
|
143 | + if($date_timestamp = @$this->items[$i]['pubdate']){ |
|
144 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
145 | + }elseif($date_timestamp = @$this->items[$i]['dc']['date']){ |
|
146 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
147 | + }else{ |
|
148 | + $this->items[$i]['date_timestamp'] = time(); |
|
149 | + } |
|
150 | + if(!is_numeric($this->items[$i]['date_timestamp'])){ |
|
151 | + if($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
152 | + $this->items[$i]['date_timestamp'] = $date; |
|
153 | + }elseif($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
154 | + $this->items[$i]['date_timestamp'] = $date; |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | /* remove to avoid redundant encoding conversion */ |
159 | - if ( isset($this->items[$i]['summary']) ) |
|
160 | - unset($this->items[$i]['summary']); |
|
161 | - if ( isset($this->items[$i]['atom_content'])) |
|
162 | - unset($this->items[$i]['atom_content']); |
|
163 | - } |
|
164 | - return; |
|
165 | - } |
|
159 | + if ( isset($this->items[$i]['summary']) ) |
|
160 | + unset($this->items[$i]['summary']); |
|
161 | + if ( isset($this->items[$i]['atom_content'])) |
|
162 | + unset($this->items[$i]['atom_content']); |
|
163 | + } |
|
164 | + return; |
|
165 | + } |
|
166 | 166 | |
167 | - function encoding_convert($tags = array()){ |
|
168 | - if(empty($tags) || in_array("channel", $tags)){ |
|
169 | - $this->channel = $this->_encoding($this->channel); |
|
170 | - } |
|
171 | - if(empty($tags) || in_array("items", $tags)){ |
|
172 | - $this->items = $this->_encoding($this->items); |
|
173 | - } |
|
174 | - } |
|
167 | + function encoding_convert($tags = array()){ |
|
168 | + if(empty($tags) || in_array("channel", $tags)){ |
|
169 | + $this->channel = $this->_encoding($this->channel); |
|
170 | + } |
|
171 | + if(empty($tags) || in_array("items", $tags)){ |
|
172 | + $this->items = $this->_encoding($this->items); |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - function _encoding($val){ |
|
177 | - if(is_array($val)){ |
|
178 | - foreach(array_keys($val) as $key){ |
|
179 | - $val[$key] = $this->_encoding($val[$key]); |
|
180 | - } |
|
181 | - }else{ |
|
182 | - $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
183 | - } |
|
184 | - return $val; |
|
185 | - } |
|
176 | + function _encoding($val){ |
|
177 | + if(is_array($val)){ |
|
178 | + foreach(array_keys($val) as $key){ |
|
179 | + $val[$key] = $this->_encoding($val[$key]); |
|
180 | + } |
|
181 | + }else{ |
|
182 | + $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
183 | + } |
|
184 | + return $val; |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | ?> |
188 | 188 | \ No newline at end of file |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * out. |
63 | 63 | * |
64 | 64 | */ |
65 | - function XmlParser ($content, $input_charset, $output_charset = _CHARSET, $tags = array()) |
|
65 | + function XmlParser($content, $input_charset, $output_charset = _CHARSET, $tags = array()) |
|
66 | 66 | { |
67 | - if(!in_array(strtoupper($input_charset), array("UTF-8", "US-ASCII", "ISO-8859-1"))) { |
|
67 | + if (!in_array(strtoupper($input_charset), array("UTF-8", "US-ASCII", "ISO-8859-1"))) { |
|
68 | 68 | $content = XoopsLocal::convert_encoding($content, "UTF-8", $input_charset); |
69 | 69 | $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
70 | 70 | $input_charset = "UTF-8"; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $this->charset_out = $output_charset; |
75 | 75 | |
76 | 76 | /* TODO: parse specified tags only */ |
77 | - $this->MagpieRSS( $content, $input_charset, $input_charset, false ); |
|
77 | + $this->MagpieRSS($content, $input_charset, $input_charset, false); |
|
78 | 78 | |
79 | 79 | //xoops_message($this); |
80 | 80 | unset($this->content); |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | function is_atom() { |
85 | - if ( $this->feed_type == ATOM ) { |
|
86 | - $this->feed_version = empty($this->feed_version)?"0.3":$this->feed_version; |
|
85 | + if ($this->feed_type == ATOM) { |
|
86 | + $this->feed_version = empty($this->feed_version) ? "0.3" : $this->feed_version; |
|
87 | 87 | return $this->feed_version; |
88 | 88 | } |
89 | 89 | else { |
@@ -91,94 +91,94 @@ discard block |
||
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - function normalize () { |
|
95 | - if ( $this->is_atom() ): |
|
96 | - if(empty($this->channel["tagline"])){ |
|
94 | + function normalize() { |
|
95 | + if ($this->is_atom()): |
|
96 | + if (empty($this->channel["tagline"])) { |
|
97 | 97 | /* ATOM */ |
98 | 98 | $this->channel["tagline"] = @$this->channel["subtitle"]; |
99 | 99 | unset($this->channel["subtitle"]); |
100 | 100 | } |
101 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
101 | + for ($i = 0; $i<count($this->items); $i++) { |
|
102 | 102 | // ATOM time |
103 | - if($date = @$this->items[$i]['modified']) continue; |
|
104 | - if(empty($date)){ |
|
103 | + if ($date = @$this->items[$i]['modified']) continue; |
|
104 | + if (empty($date)) { |
|
105 | 105 | $date = @$this->items[$i]['updated']; |
106 | 106 | } |
107 | - if(empty($date)){ |
|
107 | + if (empty($date)) { |
|
108 | 108 | $date = @$this->items[$i]['issued']; |
109 | 109 | } |
110 | - if(empty($date)){ |
|
110 | + if (empty($date)) { |
|
111 | 111 | $date = @$this->items[$i]['created']; |
112 | 112 | } |
113 | - if(empty($date)){ |
|
113 | + if (empty($date)) { |
|
114 | 114 | $date = @$this->items[$i]['created']; |
115 | 115 | } |
116 | 116 | $this->items[$i]['modified'] = $date; |
117 | 117 | } |
118 | - elseif($this->is_rss() != '1.0'): |
|
119 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
120 | - if($date = @$this->items[$i]['pubdate']) continue; |
|
118 | + elseif ($this->is_rss() != '1.0'): |
|
119 | + for ($i = 0; $i<count($this->items); $i++) { |
|
120 | + if ($date = @$this->items[$i]['pubdate']) continue; |
|
121 | 121 | $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
122 | 122 | } |
123 | 123 | endif; |
124 | 124 | parent::normalize(); |
125 | 125 | /* ATOM */ |
126 | - if(empty($this->channel["language"]) && !empty($this->channel["dc"]["language"]) ) { |
|
126 | + if (empty($this->channel["language"]) && !empty($this->channel["dc"]["language"])) { |
|
127 | 127 | $this->channel["language"] = $this->channel["dc"]["language"]; |
128 | 128 | unset($this->channel["dc"]["language"]); |
129 | 129 | } |
130 | - if(empty($this->channel["language"]) && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
130 | + if (empty($this->channel["language"]) && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
131 | 131 | $this->channel["language"] = $match[1]; |
132 | 132 | } |
133 | - if(empty($this->channel["language"]) && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) ) { |
|
133 | + if (empty($this->channel["language"]) && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match)) { |
|
134 | 134 | $this->channel["language"] = $match[1]; |
135 | 135 | } |
136 | 136 | /* remove to avoid redundant encoding conversion */ |
137 | - if(!empty($this->channel["tagline"])){ |
|
137 | + if (!empty($this->channel["tagline"])) { |
|
138 | 138 | unset($this->channel["tagline"]); |
139 | 139 | } |
140 | 140 | |
141 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
142 | - if($date_timestamp = @$this->items[$i]['date_timestamp']) continue; |
|
143 | - if($date_timestamp = @$this->items[$i]['pubdate']){ |
|
141 | + for ($i = 0; $i<count($this->items); $i++) { |
|
142 | + if ($date_timestamp = @$this->items[$i]['date_timestamp']) continue; |
|
143 | + if ($date_timestamp = @$this->items[$i]['pubdate']) { |
|
144 | 144 | $this->items[$i]['date_timestamp'] = $date_timestamp; |
145 | - }elseif($date_timestamp = @$this->items[$i]['dc']['date']){ |
|
145 | + }elseif ($date_timestamp = @$this->items[$i]['dc']['date']) { |
|
146 | 146 | $this->items[$i]['date_timestamp'] = $date_timestamp; |
147 | - }else{ |
|
147 | + }else { |
|
148 | 148 | $this->items[$i]['date_timestamp'] = time(); |
149 | 149 | } |
150 | - if(!is_numeric($this->items[$i]['date_timestamp'])){ |
|
151 | - if($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
150 | + if (!is_numeric($this->items[$i]['date_timestamp'])) { |
|
151 | + if ($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
152 | 152 | $this->items[$i]['date_timestamp'] = $date; |
153 | - }elseif($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
153 | + }elseif ($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
154 | 154 | $this->items[$i]['date_timestamp'] = $date; |
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | 158 | /* remove to avoid redundant encoding conversion */ |
159 | - if ( isset($this->items[$i]['summary']) ) |
|
159 | + if (isset($this->items[$i]['summary'])) |
|
160 | 160 | unset($this->items[$i]['summary']); |
161 | - if ( isset($this->items[$i]['atom_content'])) |
|
161 | + if (isset($this->items[$i]['atom_content'])) |
|
162 | 162 | unset($this->items[$i]['atom_content']); |
163 | 163 | } |
164 | 164 | return; |
165 | 165 | } |
166 | 166 | |
167 | - function encoding_convert($tags = array()){ |
|
168 | - if(empty($tags) || in_array("channel", $tags)){ |
|
167 | + function encoding_convert($tags = array()) { |
|
168 | + if (empty($tags) || in_array("channel", $tags)) { |
|
169 | 169 | $this->channel = $this->_encoding($this->channel); |
170 | 170 | } |
171 | - if(empty($tags) || in_array("items", $tags)){ |
|
171 | + if (empty($tags) || in_array("items", $tags)) { |
|
172 | 172 | $this->items = $this->_encoding($this->items); |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - function _encoding($val){ |
|
177 | - if(is_array($val)){ |
|
178 | - foreach(array_keys($val) as $key){ |
|
176 | + function _encoding($val) { |
|
177 | + if (is_array($val)) { |
|
178 | + foreach (array_keys($val) as $key) { |
|
179 | 179 | $val[$key] = $this->_encoding($val[$key]); |
180 | 180 | } |
181 | - }else{ |
|
181 | + }else { |
|
182 | 182 | $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
183 | 183 | } |
184 | 184 | return $val; |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | if ( $this->feed_type == ATOM ) { |
86 | 86 | $this->feed_version = empty($this->feed_version)?"0.3":$this->feed_version; |
87 | 87 | return $this->feed_version; |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | return false; |
91 | 90 | } |
92 | 91 | } |
@@ -100,7 +99,9 @@ discard block |
||
100 | 99 | } |
101 | 100 | for ( $i = 0; $i < count($this->items); $i++) { |
102 | 101 | // ATOM time |
103 | - if($date = @$this->items[$i]['modified']) continue; |
|
102 | + if($date = @$this->items[$i]['modified']) { |
|
103 | + continue; |
|
104 | + } |
|
104 | 105 | if(empty($date)){ |
105 | 106 | $date = @$this->items[$i]['updated']; |
106 | 107 | } |
@@ -114,10 +115,11 @@ discard block |
||
114 | 115 | $date = @$this->items[$i]['created']; |
115 | 116 | } |
116 | 117 | $this->items[$i]['modified'] = $date; |
117 | - } |
|
118 | - elseif($this->is_rss() != '1.0'): |
|
118 | + } elseif($this->is_rss() != '1.0'): |
|
119 | 119 | for ( $i = 0; $i < count($this->items); $i++) { |
120 | - if($date = @$this->items[$i]['pubdate']) continue; |
|
120 | + if($date = @$this->items[$i]['pubdate']) { |
|
121 | + continue; |
|
122 | + } |
|
121 | 123 | $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
122 | 124 | } |
123 | 125 | endif; |
@@ -139,27 +141,31 @@ discard block |
||
139 | 141 | } |
140 | 142 | |
141 | 143 | for ( $i = 0; $i < count($this->items); $i++) { |
142 | - if($date_timestamp = @$this->items[$i]['date_timestamp']) continue; |
|
144 | + if($date_timestamp = @$this->items[$i]['date_timestamp']) { |
|
145 | + continue; |
|
146 | + } |
|
143 | 147 | if($date_timestamp = @$this->items[$i]['pubdate']){ |
144 | 148 | $this->items[$i]['date_timestamp'] = $date_timestamp; |
145 | - }elseif($date_timestamp = @$this->items[$i]['dc']['date']){ |
|
149 | + } elseif($date_timestamp = @$this->items[$i]['dc']['date']){ |
|
146 | 150 | $this->items[$i]['date_timestamp'] = $date_timestamp; |
147 | - }else{ |
|
151 | + } else{ |
|
148 | 152 | $this->items[$i]['date_timestamp'] = time(); |
149 | 153 | } |
150 | 154 | if(!is_numeric($this->items[$i]['date_timestamp'])){ |
151 | 155 | if($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
152 | 156 | $this->items[$i]['date_timestamp'] = $date; |
153 | - }elseif($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
157 | + } elseif($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
154 | 158 | $this->items[$i]['date_timestamp'] = $date; |
155 | 159 | } |
156 | 160 | } |
157 | 161 | |
158 | 162 | /* remove to avoid redundant encoding conversion */ |
159 | - if ( isset($this->items[$i]['summary']) ) |
|
160 | - unset($this->items[$i]['summary']); |
|
161 | - if ( isset($this->items[$i]['atom_content'])) |
|
162 | - unset($this->items[$i]['atom_content']); |
|
163 | + if ( isset($this->items[$i]['summary']) ) { |
|
164 | + unset($this->items[$i]['summary']); |
|
165 | + } |
|
166 | + if ( isset($this->items[$i]['atom_content'])) { |
|
167 | + unset($this->items[$i]['atom_content']); |
|
168 | + } |
|
163 | 169 | } |
164 | 170 | return; |
165 | 171 | } |
@@ -178,7 +184,7 @@ discard block |
||
178 | 184 | foreach(array_keys($val) as $key){ |
179 | 185 | $val[$key] = $this->_encoding($val[$key]); |
180 | 186 | } |
181 | - }else{ |
|
187 | + } else{ |
|
182 | 188 | $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
183 | 189 | } |
184 | 190 | return $val; |
@@ -37,11 +37,17 @@ |
||
37 | 37 | if(!defined("PLANET_FUNCTIONS_INI")): |
38 | 38 | define("PLANET_FUNCTIONS_INI",1); |
39 | 39 | |
40 | +/** |
|
41 | + * @param string $name |
|
42 | + */ |
|
40 | 43 | function planet_constant($name) |
41 | 44 | { |
42 | 45 | return mod_constant($name); |
43 | 46 | } |
44 | 47 | |
48 | +/** |
|
49 | + * @param string $name |
|
50 | + */ |
|
45 | 51 | function planet_DB_prefix($name, $isRel = false) |
46 | 52 | { |
47 | 53 | return mod_DB_prefix($name, $isRel); |
@@ -59,24 +59,24 @@ |
||
59 | 59 | return $moduleConfig; |
60 | 60 | } |
61 | 61 | |
62 | - if(is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == $GLOBALS["moddirname"]){ |
|
63 | - $moduleConfig =& $GLOBALS["xoopsModuleConfig"]; |
|
64 | - }else{ |
|
62 | + if(is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == $GLOBALS["moddirname"]){ |
|
63 | + $moduleConfig =& $GLOBALS["xoopsModuleConfig"]; |
|
64 | + }else{ |
|
65 | 65 | $module_handler = &xoops_gethandler('module'); |
66 | 66 | $module = $module_handler->getByDirname($GLOBALS["moddirname"]); |
67 | 67 | |
68 | - $config_handler = &xoops_gethandler('config'); |
|
69 | - $criteria = new CriteriaCompo(new Criteria('conf_modid', $module->getVar('mid'))); |
|
70 | - $configs =& $config_handler->getConfigs($criteria); |
|
71 | - foreach(array_keys($configs) as $i){ |
|
72 | - $moduleConfig[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput(); |
|
73 | - } |
|
74 | - unset($configs); |
|
75 | - } |
|
68 | + $config_handler = &xoops_gethandler('config'); |
|
69 | + $criteria = new CriteriaCompo(new Criteria('conf_modid', $module->getVar('mid'))); |
|
70 | + $configs =& $config_handler->getConfigs($criteria); |
|
71 | + foreach(array_keys($configs) as $i){ |
|
72 | + $moduleConfig[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput(); |
|
73 | + } |
|
74 | + unset($configs); |
|
75 | + } |
|
76 | 76 | if($customConfig = @include(XOOPS_ROOT_PATH."/modules/".$GLOBALS["moddirname"]."/include/plugin.php")){ |
77 | 77 | $moduleConfig = array_merge($moduleConfig, $customConfig); |
78 | 78 | } |
79 | - return $moduleConfig; |
|
79 | + return $moduleConfig; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | function planet_define_url_delimiter() |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | The functions loaded on initializtion |
31 | 31 | */ |
32 | 32 | |
33 | -if (!defined('XOOPS_ROOT_PATH')){ exit(); } |
|
34 | -if (!defined('PLANET_INI')){ exit(); } |
|
33 | +if (!defined('XOOPS_ROOT_PATH')) { exit(); } |
|
34 | +if (!defined('PLANET_INI')) { exit(); } |
|
35 | 35 | |
36 | 36 | |
37 | -if(!defined("PLANET_FUNCTIONS_INI")): |
|
38 | -define("PLANET_FUNCTIONS_INI",1); |
|
37 | +if (!defined("PLANET_FUNCTIONS_INI")): |
|
38 | +define("PLANET_FUNCTIONS_INI", 1); |
|
39 | 39 | |
40 | 40 | function planet_constant($name) |
41 | 41 | { |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | function planet_load_config() |
56 | 56 | { |
57 | 57 | static $moduleConfig; |
58 | - if(isset($moduleConfig)){ |
|
58 | + if (isset($moduleConfig)) { |
|
59 | 59 | return $moduleConfig; |
60 | 60 | } |
61 | 61 | |
62 | - if(is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == $GLOBALS["moddirname"]){ |
|
63 | - $moduleConfig =& $GLOBALS["xoopsModuleConfig"]; |
|
64 | - }else{ |
|
62 | + if (is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == $GLOBALS["moddirname"]) { |
|
63 | + $moduleConfig = & $GLOBALS["xoopsModuleConfig"]; |
|
64 | + }else { |
|
65 | 65 | $module_handler = &xoops_gethandler('module'); |
66 | 66 | $module = $module_handler->getByDirname($GLOBALS["moddirname"]); |
67 | 67 | |
68 | 68 | $config_handler = &xoops_gethandler('config'); |
69 | 69 | $criteria = new CriteriaCompo(new Criteria('conf_modid', $module->getVar('mid'))); |
70 | - $configs =& $config_handler->getConfigs($criteria); |
|
71 | - foreach(array_keys($configs) as $i){ |
|
70 | + $configs = & $config_handler->getConfigs($criteria); |
|
71 | + foreach (array_keys($configs) as $i) { |
|
72 | 72 | $moduleConfig[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput(); |
73 | 73 | } |
74 | 74 | unset($configs); |
75 | 75 | } |
76 | - if($customConfig = @include(XOOPS_ROOT_PATH."/modules/".$GLOBALS["moddirname"]."/include/plugin.php")){ |
|
76 | + if ($customConfig = @include(XOOPS_ROOT_PATH."/modules/".$GLOBALS["moddirname"]."/include/plugin.php")) { |
|
77 | 77 | $moduleConfig = array_merge($moduleConfig, $customConfig); |
78 | 78 | } |
79 | 79 | return $moduleConfig; |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | |
82 | 82 | function planet_define_url_delimiter() |
83 | 83 | { |
84 | - if(defined("URL_DELIMITER")){ |
|
85 | - if(!in_array(URL_DELIMITER, array("?","/"))) die("Exit on security"); |
|
86 | - }else{ |
|
84 | + if (defined("URL_DELIMITER")) { |
|
85 | + if (!in_array(URL_DELIMITER, array("?", "/"))) die("Exit on security"); |
|
86 | + }else { |
|
87 | 87 | $moduleConfig = planet_load_config(); |
88 | - if(empty($moduleConfig["do_urw"])){ |
|
88 | + if (empty($moduleConfig["do_urw"])) { |
|
89 | 89 | define("URL_DELIMITER", "?"); |
90 | - }else{ |
|
90 | + }else { |
|
91 | 91 | define("URL_DELIMITER", "/"); |
92 | 92 | } |
93 | 93 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | |
62 | 62 | if(is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == $GLOBALS["moddirname"]){ |
63 | 63 | $moduleConfig =& $GLOBALS["xoopsModuleConfig"]; |
64 | - }else{ |
|
64 | + } else{ |
|
65 | 65 | $module_handler = &xoops_gethandler('module'); |
66 | 66 | $module = $module_handler->getByDirname($GLOBALS["moddirname"]); |
67 | 67 | |
@@ -82,12 +82,14 @@ discard block |
||
82 | 82 | function planet_define_url_delimiter() |
83 | 83 | { |
84 | 84 | if(defined("URL_DELIMITER")){ |
85 | - if(!in_array(URL_DELIMITER, array("?","/"))) die("Exit on security"); |
|
86 | - }else{ |
|
85 | + if(!in_array(URL_DELIMITER, array("?","/"))) { |
|
86 | + die("Exit on security"); |
|
87 | + } |
|
88 | + } else{ |
|
87 | 89 | $moduleConfig = planet_load_config(); |
88 | 90 | if(empty($moduleConfig["do_urw"])){ |
89 | 91 | define("URL_DELIMITER", "?"); |
90 | - }else{ |
|
92 | + } else{ |
|
91 | 93 | define("URL_DELIMITER", "/"); |
92 | 94 | } |
93 | 95 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @var mixed $pattern |
99 | 99 | * @var mixed $replacement |
100 | 100 | * |
101 | - * @return bool true on success |
|
101 | + * @return null|boolean true on success |
|
102 | 102 | */ |
103 | 103 | function planet_parse_class($class_string, $pattern="", $replacement="") |
104 | 104 | { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @var mixed $pattern |
132 | 132 | * @var mixed $replacement |
133 | 133 | * |
134 | - * @return bool true on success |
|
134 | + * @return null|boolean true on success |
|
135 | 135 | */ |
136 | 136 | function planet_parse_function($function_string, $pattern="", $replacement="") |
137 | 137 | { |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | if(!is_array($userid)) $userid = array($userid); |
176 | 176 | $users = mod_getUnameFromIds($userid, $usereal, $linked); |
177 | 177 | |
178 | - return $users; |
|
178 | + return $users; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | { |
191 | 191 | $myts =& MyTextSanitizer::getInstance(); |
192 | 192 | $link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
193 | - $links = array(); |
|
194 | - if(count($link_array)>0) foreach($link_array as $link){ |
|
195 | - @list($url, $title) = array_map("trim",preg_split("/ /", $link, 2)); |
|
196 | - if(empty($url)) continue; |
|
197 | - //if(empty($title)) $title = $url; |
|
198 | - $links[] = array("url"=>$url, "title"=>$myts->htmlSpecialChars($title)); |
|
199 | - } |
|
200 | - return $links; |
|
193 | + $links = array(); |
|
194 | + if(count($link_array)>0) foreach($link_array as $link){ |
|
195 | + @list($url, $title) = array_map("trim",preg_split("/ /", $link, 2)); |
|
196 | + if(empty($url)) continue; |
|
197 | + //if(empty($title)) $title = $url; |
|
198 | + $links[] = array("url"=>$url, "title"=>$myts->htmlSpecialChars($title)); |
|
199 | + } |
|
200 | + return $links; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | function planet_getTemplate($pagename) |
@@ -379,9 +379,9 @@ discard block |
||
379 | 379 | |
380 | 380 | function planet_remote_content($url) |
381 | 381 | { |
382 | - if($data = planet_fetch_snoopy($url)) return $data; |
|
383 | - if($data = planet_fetch_CURL($url)) return $data; |
|
384 | - if($data = planet_fetch_fopen($url)) return $data; |
|
382 | + if($data = planet_fetch_snoopy($url)) return $data; |
|
383 | + if($data = planet_fetch_CURL($url)) return $data; |
|
384 | + if($data = planet_fetch_fopen($url)) return $data; |
|
385 | 385 | return false; |
386 | 386 | } |
387 | 387 | |
@@ -391,33 +391,33 @@ discard block |
||
391 | 391 | $snoopy = new Snoopy; |
392 | 392 | $data = ""; |
393 | 393 | if (@$snoopy->fetch($url)){ |
394 | - $data = (is_array($snoopy->results))?implode("\n",$snoopy->results):$snoopy->results; |
|
394 | + $data = (is_array($snoopy->results))?implode("\n",$snoopy->results):$snoopy->results; |
|
395 | 395 | } |
396 | 396 | return $data; |
397 | 397 | } |
398 | 398 | |
399 | 399 | function planet_fetch_CURL($url) |
400 | 400 | { |
401 | - if (!function_exists('curl_init') ) return false; |
|
402 | - $ch = curl_init(); // initialize curl handle |
|
403 | - curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
|
404 | - curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
|
405 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
|
406 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable |
|
407 | - curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
|
408 | - $data = curl_exec($ch); // run the whole process |
|
409 | - curl_close($ch); |
|
410 | - return $data; |
|
401 | + if (!function_exists('curl_init') ) return false; |
|
402 | + $ch = curl_init(); // initialize curl handle |
|
403 | + curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
|
404 | + curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
|
405 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
|
406 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable |
|
407 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
|
408 | + $data = curl_exec($ch); // run the whole process |
|
409 | + curl_close($ch); |
|
410 | + return $data; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | function planet_fetch_fopen($url) |
414 | 414 | { |
415 | 415 | if(!$fp = @fopen ($url, 'r')) return false; |
416 | - $data = ""; |
|
417 | - while (!feof($fp)) { |
|
418 | - $data .= fgets ($fp, 1024); |
|
419 | - } |
|
420 | - fclose($fp); |
|
416 | + $data = ""; |
|
417 | + while (!feof($fp)) { |
|
418 | + $data .= fgets ($fp, 1024); |
|
419 | + } |
|
420 | + fclose($fp); |
|
421 | 421 | return $data; |
422 | 422 | } |
423 | 423 |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | // Project: Article Project // |
26 | 26 | // ------------------------------------------------------------------------ // |
27 | 27 | |
28 | -if (!defined('XOOPS_ROOT_PATH')){ exit(); } |
|
28 | +if (!defined('XOOPS_ROOT_PATH')) { exit(); } |
|
29 | 29 | |
30 | 30 | $current_path = __FILE__; |
31 | -if ( DIRECTORY_SEPARATOR != '/' ) $current_path = str_replace( strpos( $current_path, '\\\\', 2 ) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
32 | -$url_arr = explode('/',strstr($current_path,'/modules/')); |
|
31 | +if (DIRECTORY_SEPARATOR != '/') $current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
32 | +$url_arr = explode('/', strstr($current_path, '/modules/')); |
|
33 | 33 | $GLOBALS["moddirname"] = $url_arr[2]; |
34 | 34 | |
35 | -if(!defined("planet_FUNCTIONS")): |
|
36 | -define("planet_FUNCTIONS",1); |
|
35 | +if (!defined("planet_FUNCTIONS")): |
|
36 | +define("planet_FUNCTIONS", 1); |
|
37 | 37 | |
38 | 38 | require XOOPS_ROOT_PATH."/modules/".$GLOBALS["moddirname"]."/include/vars.php"; |
39 | 39 | include_once(XOOPS_ROOT_PATH."/class/xoopslists.php"); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @var mixed $messages |
46 | 46 | */ |
47 | -function planet_message( $message ) |
|
47 | +function planet_message($message) |
|
48 | 48 | { |
49 | - return mod_message( $message ); |
|
49 | + return mod_message($message); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -65,30 +65,30 @@ discard block |
||
65 | 65 | */ |
66 | 66 | function planet_parse_args(&$args_numeric, &$args, &$args_string) |
67 | 67 | { |
68 | - $args_abb=array("a"=>"article", "b"=>"blog", "c"=>"category", "l"=>"list", "o"=>"sort", "s"=>"start", "u"=>"uid"); |
|
68 | + $args_abb = array("a"=>"article", "b"=>"blog", "c"=>"category", "l"=>"list", "o"=>"sort", "s"=>"start", "u"=>"uid"); |
|
69 | 69 | $args = array(); |
70 | 70 | $args_numeric = array(); |
71 | 71 | $args_string = array(); |
72 | - if(preg_match("/[^\?]*\.php[\/|\?]([^\?]*)/i", $_SERVER['REQUEST_URI'], $matches)){ |
|
72 | + if (preg_match("/[^\?]*\.php[\/|\?]([^\?]*)/i", $_SERVER['REQUEST_URI'], $matches)) { |
|
73 | 73 | $vars = preg_split("/[\/|&]/", $matches[1]); |
74 | 74 | $vars = array_map("trim", $vars); |
75 | - if(count($vars)>0) { |
|
76 | - foreach($vars as $var){ |
|
77 | - if(is_numeric($var)){ |
|
75 | + if (count($vars)>0) { |
|
76 | + foreach ($vars as $var) { |
|
77 | + if (is_numeric($var)) { |
|
78 | 78 | $args_numeric[] = $var; |
79 | - }elseif(false === strpos($var, "=")){ |
|
80 | - if(is_numeric(substr($var, 1))){ |
|
79 | + }elseif (false === strpos($var, "=")) { |
|
80 | + if (is_numeric(substr($var, 1))) { |
|
81 | 81 | $args[$args_abb[strtolower($var{0})]] = intval(substr($var, 1)); |
82 | - }else{ |
|
82 | + }else { |
|
83 | 83 | $args_string[] = urldecode($var); |
84 | 84 | } |
85 | - }else{ |
|
85 | + }else { |
|
86 | 86 | parse_str($var, $args); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | - return (count($args)+count($args_numeric)+count($args_string) == 0)?null:true; |
|
91 | + return (count($args)+count($args_numeric)+count($args_string) == 0) ? null : true; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return bool true on success |
102 | 102 | */ |
103 | -function planet_parse_class($class_string, $pattern="", $replacement="") |
|
103 | +function planet_parse_class($class_string, $pattern = "", $replacement = "") |
|
104 | 104 | { |
105 | - if(empty($class_string)) return; |
|
105 | + if (empty($class_string)) return; |
|
106 | 106 | $patterns = array("/\[CLASS_PREFIX\]/"); |
107 | 107 | $replacements = array(ucfirst(strtolower($GLOBALS["moddirname"]))); |
108 | - if(!empty($pattern) && !is_array($pattern) && !is_array($replacement)){ |
|
108 | + if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
109 | 109 | $pattern = array($pattern); |
110 | 110 | $replacement = array($replacement); |
111 | 111 | } |
112 | - if(is_array($pattern) && count($pattern)>0){ |
|
112 | + if (is_array($pattern) && count($pattern)>0) { |
|
113 | 113 | $ii = 0; |
114 | - foreach($pattern as $pat){ |
|
115 | - if(!in_array($pat, $patterns)){ |
|
114 | + foreach ($pattern as $pat) { |
|
115 | + if (!in_array($pat, $patterns)) { |
|
116 | 116 | $patterns[] = $pat; |
117 | - $replacements[] = isset($replacement[$ii])?$replacement[$ii]:""; |
|
117 | + $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ""; |
|
118 | 118 | } |
119 | 119 | $ii++; |
120 | 120 | } |
@@ -133,21 +133,21 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return bool true on success |
135 | 135 | */ |
136 | -function planet_parse_function($function_string, $pattern="", $replacement="") |
|
136 | +function planet_parse_function($function_string, $pattern = "", $replacement = "") |
|
137 | 137 | { |
138 | - if(empty($function_string)) return; |
|
138 | + if (empty($function_string)) return; |
|
139 | 139 | $patterns = array("/\[DIRNAME\]/", "/\[VAR_PREFIX\]/"); |
140 | 140 | $replacements = array($GLOBALS["moddirname"], $GLOBALS["VAR_PREFIX"]); |
141 | - if(!empty($pattern) && !is_array($pattern) && !is_array($replacement)){ |
|
141 | + if (!empty($pattern) && !is_array($pattern) && !is_array($replacement)) { |
|
142 | 142 | $pattern = array($pattern); |
143 | 143 | $replacement = array($replacement); |
144 | 144 | } |
145 | - if(is_array($pattern) && count($pattern)>0){ |
|
145 | + if (is_array($pattern) && count($pattern)>0) { |
|
146 | 146 | $ii = 0; |
147 | - foreach($pattern as $pat){ |
|
148 | - if(!in_array($pat, $patterns)){ |
|
147 | + foreach ($pattern as $pat) { |
|
148 | + if (!in_array($pat, $patterns)) { |
|
149 | 149 | $patterns[] = $pat; |
150 | - $replacements[] = isset($replacement[$ii])?$replacement[$ii]:""; |
|
150 | + $replacements[] = isset($replacement[$ii]) ? $replacement[$ii] : ""; |
|
151 | 151 | } |
152 | 152 | $ii++; |
153 | 153 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | function planet_formatTimestamp($time, $format = "") |
164 | 164 | { |
165 | - if(empty($time)) return ""; |
|
165 | + if (empty($time)) return ""; |
|
166 | 166 | return formatTimestamp($time, $format); |
167 | 167 | } |
168 | 168 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * Function to a list of user names associated with their user IDs |
171 | 171 | * |
172 | 172 | */ |
173 | -function &planet_getUnameFromId( $userid, $usereal = 0, $linked = false ) |
|
173 | +function &planet_getUnameFromId($userid, $usereal = 0, $linked = false) |
|
174 | 174 | { |
175 | - if(!is_array($userid)) $userid = array($userid); |
|
175 | + if (!is_array($userid)) $userid = array($userid); |
|
176 | 176 | $users = mod_getUnameFromIds($userid, $usereal, $linked); |
177 | 177 | |
178 | 178 | return $users; |
@@ -188,12 +188,12 @@ discard block |
||
188 | 188 | */ |
189 | 189 | function &planet_parseLinks($text) |
190 | 190 | { |
191 | - $myts =& MyTextSanitizer::getInstance(); |
|
191 | + $myts = & MyTextSanitizer::getInstance(); |
|
192 | 192 | $link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
193 | 193 | $links = array(); |
194 | - if(count($link_array)>0) foreach($link_array as $link){ |
|
195 | - @list($url, $title) = array_map("trim",preg_split("/ /", $link, 2)); |
|
196 | - if(empty($url)) continue; |
|
194 | + if (count($link_array)>0) foreach ($link_array as $link) { |
|
195 | + @list($url, $title) = array_map("trim", preg_split("/ /", $link, 2)); |
|
196 | + if (empty($url)) continue; |
|
197 | 197 | //if(empty($title)) $title = $url; |
198 | 198 | $links[] = array("url"=>$url, "title"=>$myts->htmlSpecialChars($title)); |
199 | 199 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | return $GLOBALS["VAR_PREFIX"]."_".$pagename.".html"; |
206 | 206 | } |
207 | 207 | |
208 | -function planet_adminmenu ($currentoption = -1) |
|
208 | +function planet_adminmenu($currentoption = -1) |
|
209 | 209 | { |
210 | 210 | loadModuleAdminMenu($currentoption, ""); |
211 | 211 | return; |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | */ |
219 | 219 | function planet_com_trackback(&$article, &$comment) |
220 | 220 | { |
221 | - $blog_handler =& xoops_getmodulehandler("blog", $GLOBALS["moddirname"]); |
|
222 | - $blog_obj =& $blog_handler->get($article->getVar("blog_id")); |
|
223 | - if(!$pattern = $blog_obj->getVar("blog_trackback")) return false; |
|
224 | - @list($pat, $rep) = array_map("trim",preg_split("#[\s]+#", $pattern)); |
|
221 | + $blog_handler = & xoops_getmodulehandler("blog", $GLOBALS["moddirname"]); |
|
222 | + $blog_obj = & $blog_handler->get($article->getVar("blog_id")); |
|
223 | + if (!$pattern = $blog_obj->getVar("blog_trackback")) return false; |
|
224 | + @list($pat, $rep) = array_map("trim", preg_split("#[\s]+#", $pattern)); |
|
225 | 225 | $trackback_url = preg_replace("#".$pat."#", $rep, $article_obj->getVar("art_link")); |
226 | 226 | return planet_trackback($trackback_url, $article); |
227 | 227 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $title = xoops_utf8_encode($title); |
237 | 237 | $excerpt = xoops_utf8_encode($excerpt); |
238 | 238 | $blog_name = xoops_utf8_encode($blog_name); |
239 | - $charset="utf-8"; |
|
239 | + $charset = "utf-8"; |
|
240 | 240 | $title1 = urlencode($title); |
241 | 241 | $excerpt1 = urlencode($excerpt); |
242 | 242 | $name1 = urlencode($blog_name); |
@@ -244,34 +244,34 @@ discard block |
||
244 | 244 | $query_string = "title=$title1&url=$url&blog_name=$name1&excerpt=$excerpt1&charset=$charset"; |
245 | 245 | $trackback_url = parse_url($trackback_url); |
246 | 246 | |
247 | - $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n"; |
|
247 | + $http_request = 'POST '.$trackback_url['path'].($trackback_url['query'] ? '?'.$trackback_url['query'] : '')." HTTP/1.0\r\n"; |
|
248 | 248 | $http_request .= "Host: ".$trackback_url["host"]."\r\n"; |
249 | 249 | $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=".$charset."\r\n"; |
250 | 250 | $http_request .= "Content-Length: ".strlen($query_string)."\r\n"; |
251 | - $http_request .= "User-Agent: XOOPS Blogs/" . XOOPS_VERSION; |
|
251 | + $http_request .= "User-Agent: XOOPS Blogs/".XOOPS_VERSION; |
|
252 | 252 | $http_request .= "\r\n\r\n"; |
253 | 253 | $http_request .= $query_string; |
254 | - if ( '' == $trackback_url['port'] ){ |
|
254 | + if ('' == $trackback_url['port']) { |
|
255 | 255 | $trackback_url['port'] = 80; |
256 | 256 | } |
257 | 257 | $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4); |
258 | 258 | @fputs($fs, $http_request); |
259 | - if($xoopsModuleConfig["do_debug"]) { |
|
259 | + if ($xoopsModuleConfig["do_debug"]) { |
|
260 | 260 | $debug_file = XOOPS_CACHE_PATH."/".$GLOBALS["moddirname"]."_trackback.log"; |
261 | 261 | $fr = "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"; |
262 | 262 | $fr .= "CHARSET:$charset\n"; |
263 | 263 | $fr .= "NAME:$blog_name\n"; |
264 | 264 | $fr .= "TITLE:".$title."\n"; |
265 | 265 | $fr .= "EXCERPT:$excerpt\n\n"; |
266 | - while(!@feof($fs)) { |
|
266 | + while (!@feof($fs)) { |
|
267 | 267 | $fr .= @fgets($fs, 4096); |
268 | 268 | } |
269 | 269 | $fr .= "\n\n"; |
270 | 270 | |
271 | - if($fp = fopen($debug_file, "a")){ |
|
271 | + if ($fp = fopen($debug_file, "a")) { |
|
272 | 272 | fwrite($fp, $fr); |
273 | 273 | fclose($fp); |
274 | - }else{ |
|
274 | + }else { |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | @fclose($fs); |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * Function to ping servers |
283 | 283 | */ |
284 | 284 | function planet_ping($server, $id) { |
285 | - if(is_array($server)){ |
|
286 | - foreach($server as $serv){ |
|
285 | + if (is_array($server)) { |
|
286 | + foreach ($server as $serv) { |
|
287 | 287 | planet_ping($serv, $id); |
288 | 288 | } |
289 | 289 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $home = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/"; |
302 | 302 | $rss2_url = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/xml.php".URL_DELIMITER."rss2.0/".$id; |
303 | 303 | |
304 | - if ( !$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url ) ) // then try a normal ping |
|
304 | + if (!$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url)) // then try a normal ping |
|
305 | 305 | $client->query('weblogUpdates.ping', $blogname, $home); |
306 | 306 | } |
307 | 307 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | echo "<message>$error_message</message>\n"; |
320 | 320 | echo "</response>"; |
321 | 321 | die(); |
322 | - } else { |
|
322 | + }else { |
|
323 | 323 | echo '<?xml version="1.0" encoding="'.$charset.'"?'.">\n"; |
324 | 324 | echo "<response>\n"; |
325 | 325 | echo "<error>0</error>\n"; |
@@ -334,10 +334,10 @@ discard block |
||
334 | 334 | */ |
335 | 335 | function planet_setcookie($name, $string = '', $expire = 0) |
336 | 336 | { |
337 | - if(is_array($string)) { |
|
337 | + if (is_array($string)) { |
|
338 | 338 | $value = array(); |
339 | - foreach ($string as $key => $val){ |
|
340 | - $value[]=$key."|".$val; |
|
339 | + foreach ($string as $key => $val) { |
|
340 | + $value[] = $key."|".$val; |
|
341 | 341 | } |
342 | 342 | $string = implode(",", $value); |
343 | 343 | } |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | function planet_getcookie($name, $isArray = false) |
348 | 348 | { |
349 | 349 | $value = isset($_COOKIE[$GLOBALS["VAR_PREFIX"].$name]) ? $_COOKIE[$GLOBALS["VAR_PREFIX"].$name] : null; |
350 | - if($isArray) { |
|
351 | - $_value = ($value)?explode(",", $value):array(); |
|
350 | + if ($isArray) { |
|
351 | + $_value = ($value) ? explode(",", $value) : array(); |
|
352 | 352 | $value = array(); |
353 | - if(count($_value)>0) foreach($_value as $string){ |
|
354 | - $key = substr($string, 0, strpos($string,"|")); |
|
355 | - $val = substr($string, (strpos($string,"|")+1)); |
|
353 | + if (count($_value)>0) foreach ($_value as $string) { |
|
354 | + $key = substr($string, 0, strpos($string, "|")); |
|
355 | + $val = substr($string, (strpos($string, "|")+1)); |
|
356 | 356 | $value[$key] = $val; |
357 | 357 | } |
358 | 358 | unset($_value); |
@@ -379,9 +379,9 @@ discard block |
||
379 | 379 | |
380 | 380 | function planet_remote_content($url) |
381 | 381 | { |
382 | - if($data = planet_fetch_snoopy($url)) return $data; |
|
383 | - if($data = planet_fetch_CURL($url)) return $data; |
|
384 | - if($data = planet_fetch_fopen($url)) return $data; |
|
382 | + if ($data = planet_fetch_snoopy($url)) return $data; |
|
383 | + if ($data = planet_fetch_CURL($url)) return $data; |
|
384 | + if ($data = planet_fetch_fopen($url)) return $data; |
|
385 | 385 | return false; |
386 | 386 | } |
387 | 387 | |
@@ -390,20 +390,20 @@ discard block |
||
390 | 390 | require_once(XOOPS_ROOT_PATH."/class/snoopy.php"); |
391 | 391 | $snoopy = new Snoopy; |
392 | 392 | $data = ""; |
393 | - if (@$snoopy->fetch($url)){ |
|
394 | - $data = (is_array($snoopy->results))?implode("\n",$snoopy->results):$snoopy->results; |
|
393 | + if (@$snoopy->fetch($url)) { |
|
394 | + $data = (is_array($snoopy->results)) ? implode("\n", $snoopy->results) : $snoopy->results; |
|
395 | 395 | } |
396 | 396 | return $data; |
397 | 397 | } |
398 | 398 | |
399 | 399 | function planet_fetch_CURL($url) |
400 | 400 | { |
401 | - if (!function_exists('curl_init') ) return false; |
|
402 | - $ch = curl_init(); // initialize curl handle |
|
401 | + if (!function_exists('curl_init')) return false; |
|
402 | + $ch = curl_init(); // initialize curl handle |
|
403 | 403 | curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
404 | 404 | curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
405 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects |
|
406 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable |
|
405 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects |
|
406 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable |
|
407 | 407 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s |
408 | 408 | $data = curl_exec($ch); // run the whole process |
409 | 409 | curl_close($ch); |
@@ -412,25 +412,25 @@ discard block |
||
412 | 412 | |
413 | 413 | function planet_fetch_fopen($url) |
414 | 414 | { |
415 | - if(!$fp = @fopen ($url, 'r')) return false; |
|
415 | + if (!$fp = @fopen($url, 'r')) return false; |
|
416 | 416 | $data = ""; |
417 | 417 | while (!feof($fp)) { |
418 | - $data .= fgets ($fp, 1024); |
|
418 | + $data .= fgets($fp, 1024); |
|
419 | 419 | } |
420 | 420 | fclose($fp); |
421 | 421 | return $data; |
422 | 422 | } |
423 | 423 | |
424 | -function planet_strrpos($haystack, $needle, $offset = 0 ) |
|
424 | +function planet_strrpos($haystack, $needle, $offset = 0) |
|
425 | 425 | { |
426 | - if( substr(phpversion(),0,1) == 5 ){ |
|
426 | + if (substr(phpversion(), 0, 1) == 5) { |
|
427 | 427 | return strrpos($haystack, $needle, $offset); |
428 | 428 | } |
429 | 429 | $index = strpos(strrev($haystack), strrev($needle)); |
430 | - if($index === false) { |
|
430 | + if ($index === false) { |
|
431 | 431 | return false; |
432 | 432 | } |
433 | - $index = strlen($haystack) - strlen($needle) - $index; |
|
433 | + $index = strlen($haystack)-strlen($needle)-$index; |
|
434 | 434 | return $index; |
435 | 435 | } |
436 | 436 | endif; |
@@ -28,7 +28,9 @@ discard block |
||
28 | 28 | if (!defined('XOOPS_ROOT_PATH')){ exit(); } |
29 | 29 | |
30 | 30 | $current_path = __FILE__; |
31 | -if ( DIRECTORY_SEPARATOR != '/' ) $current_path = str_replace( strpos( $current_path, '\\\\', 2 ) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
31 | +if ( DIRECTORY_SEPARATOR != '/' ) { |
|
32 | + $current_path = str_replace( strpos( $current_path, '\\\\', 2 ) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); |
|
33 | +} |
|
32 | 34 | $url_arr = explode('/',strstr($current_path,'/modules/')); |
33 | 35 | $GLOBALS["moddirname"] = $url_arr[2]; |
34 | 36 | |
@@ -76,13 +78,13 @@ discard block |
||
76 | 78 | foreach($vars as $var){ |
77 | 79 | if(is_numeric($var)){ |
78 | 80 | $args_numeric[] = $var; |
79 | - }elseif(false === strpos($var, "=")){ |
|
81 | + } elseif(false === strpos($var, "=")){ |
|
80 | 82 | if(is_numeric(substr($var, 1))){ |
81 | 83 | $args[$args_abb[strtolower($var{0})]] = intval(substr($var, 1)); |
82 | - }else{ |
|
84 | + } else{ |
|
83 | 85 | $args_string[] = urldecode($var); |
84 | 86 | } |
85 | - }else{ |
|
87 | + } else{ |
|
86 | 88 | parse_str($var, $args); |
87 | 89 | } |
88 | 90 | } |
@@ -102,7 +104,9 @@ discard block |
||
102 | 104 | */ |
103 | 105 | function planet_parse_class($class_string, $pattern="", $replacement="") |
104 | 106 | { |
105 | - if(empty($class_string)) return; |
|
107 | + if(empty($class_string)) { |
|
108 | + return; |
|
109 | + } |
|
106 | 110 | $patterns = array("/\[CLASS_PREFIX\]/"); |
107 | 111 | $replacements = array(ucfirst(strtolower($GLOBALS["moddirname"]))); |
108 | 112 | if(!empty($pattern) && !is_array($pattern) && !is_array($replacement)){ |
@@ -135,7 +139,9 @@ discard block |
||
135 | 139 | */ |
136 | 140 | function planet_parse_function($function_string, $pattern="", $replacement="") |
137 | 141 | { |
138 | - if(empty($function_string)) return; |
|
142 | + if(empty($function_string)) { |
|
143 | + return; |
|
144 | + } |
|
139 | 145 | $patterns = array("/\[DIRNAME\]/", "/\[VAR_PREFIX\]/"); |
140 | 146 | $replacements = array($GLOBALS["moddirname"], $GLOBALS["VAR_PREFIX"]); |
141 | 147 | if(!empty($pattern) && !is_array($pattern) && !is_array($replacement)){ |
@@ -162,7 +168,9 @@ discard block |
||
162 | 168 | */ |
163 | 169 | function planet_formatTimestamp($time, $format = "") |
164 | 170 | { |
165 | - if(empty($time)) return ""; |
|
171 | + if(empty($time)) { |
|
172 | + return ""; |
|
173 | + } |
|
166 | 174 | return formatTimestamp($time, $format); |
167 | 175 | } |
168 | 176 | |
@@ -172,7 +180,9 @@ discard block |
||
172 | 180 | */ |
173 | 181 | function &planet_getUnameFromId( $userid, $usereal = 0, $linked = false ) |
174 | 182 | { |
175 | - if(!is_array($userid)) $userid = array($userid); |
|
183 | + if(!is_array($userid)) { |
|
184 | + $userid = array($userid); |
|
185 | + } |
|
176 | 186 | $users = mod_getUnameFromIds($userid, $usereal, $linked); |
177 | 187 | |
178 | 188 | return $users; |
@@ -191,9 +201,13 @@ discard block |
||
191 | 201 | $myts =& MyTextSanitizer::getInstance(); |
192 | 202 | $link_array = preg_split("/(\r\n|\r|\n)( *)/", $text); |
193 | 203 | $links = array(); |
194 | - if(count($link_array)>0) foreach($link_array as $link){ |
|
204 | + if(count($link_array)>0) { |
|
205 | + foreach($link_array as $link){ |
|
195 | 206 | @list($url, $title) = array_map("trim",preg_split("/ /", $link, 2)); |
196 | - if(empty($url)) continue; |
|
207 | + } |
|
208 | + if(empty($url)) { |
|
209 | + continue; |
|
210 | + } |
|
197 | 211 | //if(empty($title)) $title = $url; |
198 | 212 | $links[] = array("url"=>$url, "title"=>$myts->htmlSpecialChars($title)); |
199 | 213 | } |
@@ -220,7 +234,9 @@ discard block |
||
220 | 234 | { |
221 | 235 | $blog_handler =& xoops_getmodulehandler("blog", $GLOBALS["moddirname"]); |
222 | 236 | $blog_obj =& $blog_handler->get($article->getVar("blog_id")); |
223 | - if(!$pattern = $blog_obj->getVar("blog_trackback")) return false; |
|
237 | + if(!$pattern = $blog_obj->getVar("blog_trackback")) { |
|
238 | + return false; |
|
239 | + } |
|
224 | 240 | @list($pat, $rep) = array_map("trim",preg_split("#[\s]+#", $pattern)); |
225 | 241 | $trackback_url = preg_replace("#".$pat."#", $rep, $article_obj->getVar("art_link")); |
226 | 242 | return planet_trackback($trackback_url, $article); |
@@ -271,7 +287,7 @@ discard block |
||
271 | 287 | if($fp = fopen($debug_file, "a")){ |
272 | 288 | fwrite($fp, $fr); |
273 | 289 | fclose($fp); |
274 | - }else{ |
|
290 | + } else{ |
|
275 | 291 | } |
276 | 292 | } |
277 | 293 | @fclose($fs); |
@@ -301,9 +317,11 @@ discard block |
||
301 | 317 | $home = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/"; |
302 | 318 | $rss2_url = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/xml.php".URL_DELIMITER."rss2.0/".$id; |
303 | 319 | |
304 | - if ( !$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url ) ) // then try a normal ping |
|
320 | + if ( !$client->query('weblogUpdates.extendedPing', $blogname, $home, $rss2_url ) ) { |
|
321 | + // then try a normal ping |
|
305 | 322 | $client->query('weblogUpdates.ping', $blogname, $home); |
306 | -} |
|
323 | + } |
|
324 | + } |
|
307 | 325 | |
308 | 326 | /** |
309 | 327 | * Function to respond to a trackback |
@@ -350,8 +368,10 @@ discard block |
||
350 | 368 | if($isArray) { |
351 | 369 | $_value = ($value)?explode(",", $value):array(); |
352 | 370 | $value = array(); |
353 | - if(count($_value)>0) foreach($_value as $string){ |
|
371 | + if(count($_value)>0) { |
|
372 | + foreach($_value as $string){ |
|
354 | 373 | $key = substr($string, 0, strpos($string,"|")); |
374 | + } |
|
355 | 375 | $val = substr($string, (strpos($string,"|")+1)); |
356 | 376 | $value[$key] = $val; |
357 | 377 | } |
@@ -379,9 +399,15 @@ discard block |
||
379 | 399 | |
380 | 400 | function planet_remote_content($url) |
381 | 401 | { |
382 | - if($data = planet_fetch_snoopy($url)) return $data; |
|
383 | - if($data = planet_fetch_CURL($url)) return $data; |
|
384 | - if($data = planet_fetch_fopen($url)) return $data; |
|
402 | + if($data = planet_fetch_snoopy($url)) { |
|
403 | + return $data; |
|
404 | + } |
|
405 | + if($data = planet_fetch_CURL($url)) { |
|
406 | + return $data; |
|
407 | + } |
|
408 | + if($data = planet_fetch_fopen($url)) { |
|
409 | + return $data; |
|
410 | + } |
|
385 | 411 | return false; |
386 | 412 | } |
387 | 413 | |
@@ -398,7 +424,9 @@ discard block |
||
398 | 424 | |
399 | 425 | function planet_fetch_CURL($url) |
400 | 426 | { |
401 | - if (!function_exists('curl_init') ) return false; |
|
427 | + if (!function_exists('curl_init') ) { |
|
428 | + return false; |
|
429 | + } |
|
402 | 430 | $ch = curl_init(); // initialize curl handle |
403 | 431 | curl_setopt($ch, CURLOPT_URL, $url); // set url to post to |
404 | 432 | curl_setopt($ch, CURLOPT_FAILONERROR, 1); |
@@ -412,7 +440,9 @@ discard block |
||
412 | 440 | |
413 | 441 | function planet_fetch_fopen($url) |
414 | 442 | { |
415 | - if(!$fp = @fopen ($url, 'r')) return false; |
|
443 | + if(!$fp = @fopen ($url, 'r')) { |
|
444 | + return false; |
|
445 | + } |
|
416 | 446 | $data = ""; |
417 | 447 | while (!feof($fp)) { |
418 | 448 | $data .= fgets ($fp, 1024); |
@@ -165,18 +165,18 @@ |
||
165 | 165 | |
166 | 166 | $tags = empty($list)?"":array($article_prefix."art_title", $article_prefix."blog_id", $article_prefix."art_time"); |
167 | 167 | switch($query_type){ |
168 | -case "category": |
|
169 | - $articles_obj =& $article_handler->getByCategory($criteria, $tags); |
|
170 | - $count_article = $article_handler->getCountByCategory($criteria); |
|
171 | - break; |
|
172 | -case "bookmark": |
|
173 | - $articles_obj =& $article_handler->getByBookmark($criteria, $tags); |
|
174 | - $count_article = $article_handler->getCountByBookmark($criteria); |
|
175 | - break; |
|
176 | -default: |
|
177 | - $articles_obj =& $article_handler->getAll($criteria, $tags); |
|
178 | - $count_article = $article_handler->getCount($criteria); |
|
179 | - break; |
|
168 | + case "category": |
|
169 | + $articles_obj =& $article_handler->getByCategory($criteria, $tags); |
|
170 | + $count_article = $article_handler->getCountByCategory($criteria); |
|
171 | + break; |
|
172 | + case "bookmark": |
|
173 | + $articles_obj =& $article_handler->getByBookmark($criteria, $tags); |
|
174 | + $count_article = $article_handler->getCountByBookmark($criteria); |
|
175 | + break; |
|
176 | + default: |
|
177 | + $articles_obj =& $article_handler->getAll($criteria, $tags); |
|
178 | + $count_article = $article_handler->getCount($criteria); |
|
179 | + break; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | if(!empty($blog_data)){ |
@@ -26,46 +26,46 @@ discard block |
||
26 | 26 | // ------------------------------------------------------------------------ // |
27 | 27 | include "header.php"; |
28 | 28 | |
29 | -if(preg_match("/\/notification_update\.php/i", $_SERVER['REQUEST_URI'], $matches)){ |
|
29 | +if (preg_match("/\/notification_update\.php/i", $_SERVER['REQUEST_URI'], $matches)) { |
|
30 | 30 | include XOOPS_ROOT_PATH.'/include/notification_update.php'; |
31 | 31 | exit(); |
32 | 32 | } |
33 | 33 | |
34 | -if($REQUEST_URI_parsed = planet_parse_args($args_num, $args, $args_str)){ |
|
34 | +if ($REQUEST_URI_parsed = planet_parse_args($args_num, $args, $args_str)) { |
|
35 | 35 | $args["start"] = @$args_num[0]; |
36 | 36 | $args["sort"] = @$args_str[0]; |
37 | 37 | } |
38 | 38 | |
39 | 39 | /* Start */ |
40 | -$start = intval( empty($_GET["start"])?@$args["start"]:$_GET["start"] ); |
|
40 | +$start = intval(empty($_GET["start"]) ? @$args["start"] : $_GET["start"]); |
|
41 | 41 | /* Specified Category */ |
42 | -$category_id = intval( empty($_GET["category"])?@$args["category"]:$_GET["category"] ); |
|
42 | +$category_id = intval(empty($_GET["category"]) ? @$args["category"] : $_GET["category"]); |
|
43 | 43 | /* Specified Blog */ |
44 | -$blog_id = intval( empty($_GET["blog"])?@$args["blog"]:$_GET["blog"] ); |
|
44 | +$blog_id = intval(empty($_GET["blog"]) ? @$args["blog"] : $_GET["blog"]); |
|
45 | 45 | /* Specified Bookmar(Favorite) UID */ |
46 | -$uid = intval( empty($_GET["uid"])?@$args["uid"]:$_GET["uid"] ); |
|
46 | +$uid = intval(empty($_GET["uid"]) ? @$args["uid"] : $_GET["uid"]); |
|
47 | 47 | /* Sort by term */ |
48 | -$sort = empty($_GET["sort"])?@$args["sort"]:$_GET["sort"]; |
|
48 | +$sort = empty($_GET["sort"]) ? @$args["sort"] : $_GET["sort"]; |
|
49 | 49 | /* Display as list */ |
50 | -$list = intval( empty($_GET["list"])?@$args["list"]:$_GET["list"] ); |
|
50 | +$list = intval(empty($_GET["list"]) ? @$args["list"] : $_GET["list"]); |
|
51 | 51 | |
52 | 52 | // restore $_SERVER['REQUEST_URI'] |
53 | -if(!empty($REQUEST_URI_parsed)){ |
|
53 | +if (!empty($REQUEST_URI_parsed)) { |
|
54 | 54 | $args_REQUEST_URI = array(); |
55 | - $_args =array("start", "sort", "uid", "list"); |
|
56 | - foreach($_args as $arg){ |
|
57 | - if(!empty(${$arg})){ |
|
58 | - $args_REQUEST_URI[] = $arg ."=". ${$arg}; |
|
55 | + $_args = array("start", "sort", "uid", "list"); |
|
56 | + foreach ($_args as $arg) { |
|
57 | + if (!empty(${$arg})) { |
|
58 | + $args_REQUEST_URI[] = $arg."=".${$arg}; |
|
59 | 59 | } |
60 | 60 | } |
61 | - if(!empty($blog_id)){ |
|
62 | - $args_REQUEST_URI[] = "blog=". $blog_id; |
|
61 | + if (!empty($blog_id)) { |
|
62 | + $args_REQUEST_URI[] = "blog=".$blog_id; |
|
63 | 63 | } |
64 | - if(!empty($category_id)){ |
|
65 | - $args_REQUEST_URI[] = "category=". $category_id; |
|
64 | + if (!empty($category_id)) { |
|
65 | + $args_REQUEST_URI[] = "category=".$category_id; |
|
66 | 66 | } |
67 | 67 | $_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php". |
68 | - (empty($args_REQUEST_URI)?"":"?".implode("&",$args_REQUEST_URI)); |
|
68 | + (empty($args_REQUEST_URI) ? "" : "?".implode("&", $args_REQUEST_URI)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $xoopsOption["template_main"] = planet_getTemplate("index"); |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | '; |
77 | 77 | |
78 | 78 | $xoopsOption["xoops_module_header"] = $xoops_module_header; |
79 | -include_once( XOOPS_ROOT_PATH . "/header.php" ); |
|
79 | +include_once(XOOPS_ROOT_PATH."/header.php"); |
|
80 | 80 | include XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/include/vars.php"; |
81 | 81 | |
82 | 82 | // Following part will not be executed after cache |
83 | -$category_handler =& xoops_getmodulehandler("category", $GLOBALS["moddirname"]); |
|
84 | -$blog_handler =& xoops_getmodulehandler("blog", $GLOBALS["moddirname"]); |
|
85 | -$article_handler =& xoops_getmodulehandler("article", $GLOBALS["moddirname"]); |
|
83 | +$category_handler = & xoops_getmodulehandler("category", $GLOBALS["moddirname"]); |
|
84 | +$blog_handler = & xoops_getmodulehandler("blog", $GLOBALS["moddirname"]); |
|
85 | +$article_handler = & xoops_getmodulehandler("article", $GLOBALS["moddirname"]); |
|
86 | 86 | |
87 | -$limit = empty($list)? $xoopsModuleConfig["articles_perpage"] : $xoopsModuleConfig["list_perpage"]; |
|
87 | +$limit = empty($list) ? $xoopsModuleConfig["articles_perpage"] : $xoopsModuleConfig["list_perpage"]; |
|
88 | 88 | $query_type = ""; |
89 | 89 | $criteria = new CriteriaCompo(); |
90 | 90 | $article_prefix = ""; |
91 | 91 | /* Specific category */ |
92 | -if($category_id >0){ |
|
92 | +if ($category_id>0) { |
|
93 | 93 | $category_obj = $category_handler->get($category_id); |
94 | 94 | $criteria->add(new Criteria("bc.cat_id", $category_id)); |
95 | 95 | $uid = 0; |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | $article_prefix = "a."; |
100 | 100 | } |
101 | 101 | /* Specific blog */ |
102 | -if($blog_id>0){ |
|
103 | - $blog_obj =& $blog_handler->get($blog_id); |
|
104 | - if($blog_obj->getVar("blog_status") || |
|
105 | - (is_object($xoopsUser) && $xoopsUser->getVar("uid")== $blog_obj->getVar("blog_submitter")) |
|
106 | - ){ |
|
102 | +if ($blog_id>0) { |
|
103 | + $blog_obj = & $blog_handler->get($blog_id); |
|
104 | + if ($blog_obj->getVar("blog_status") || |
|
105 | + (is_object($xoopsUser) && $xoopsUser->getVar("uid") == $blog_obj->getVar("blog_submitter")) |
|
106 | + ) { |
|
107 | 107 | $criteria->add(new Criteria("blog_id", $blog_id)); |
108 | 108 | $category_id = 0; |
109 | 109 | $uid = 0; |
110 | - $bookmark_handler =& xoops_getmodulehandler("bookmark", $GLOBALS["moddirname"]); |
|
110 | + $bookmark_handler = & xoops_getmodulehandler("bookmark", $GLOBALS["moddirname"]); |
|
111 | 111 | $blog_data = array( |
112 | 112 | "id"=>$blog_id, |
113 | 113 | "title"=>$blog_obj->getVar("blog_title"), |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | $article_prefix = ""; |
127 | 127 | } |
128 | 128 | /* User bookmarks(favorites) */ |
129 | -if($uid >0){ |
|
129 | +if ($uid>0) { |
|
130 | 130 | $criteria->add(new Criteria("bm.bm_uid", $uid)); |
131 | 131 | $category_id = 0; |
132 | 132 | $blog_id = 0; |
133 | - $bookmark_handler =& xoops_getmodulehandler("bookmark", $GLOBALS["moddirname"]); |
|
133 | + $bookmark_handler = & xoops_getmodulehandler("bookmark", $GLOBALS["moddirname"]); |
|
134 | 134 | $user_data = array( |
135 | 135 | "uid"=>$uid, |
136 | 136 | "name"=>XoopsUser::getUnameFromID($uid), |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | /* Sort */ |
144 | 144 | $order = "DESC"; |
145 | -$sort = empty($sort)?"time":$sort; |
|
146 | -switch($sort){ |
|
145 | +$sort = empty($sort) ? "time" : $sort; |
|
146 | +switch ($sort) { |
|
147 | 147 | case "views": |
148 | 148 | $sortby = $article_prefix."art_views"; |
149 | 149 | break; |
@@ -163,25 +163,25 @@ discard block |
||
163 | 163 | $criteria->setStart($start); |
164 | 164 | $criteria->setLimit($limit); |
165 | 165 | |
166 | -$tags = empty($list)?"":array($article_prefix."art_title", $article_prefix."blog_id", $article_prefix."art_time"); |
|
167 | -switch($query_type){ |
|
166 | +$tags = empty($list) ? "" : array($article_prefix."art_title", $article_prefix."blog_id", $article_prefix."art_time"); |
|
167 | +switch ($query_type) { |
|
168 | 168 | case "category": |
169 | - $articles_obj =& $article_handler->getByCategory($criteria, $tags); |
|
169 | + $articles_obj = & $article_handler->getByCategory($criteria, $tags); |
|
170 | 170 | $count_article = $article_handler->getCountByCategory($criteria); |
171 | 171 | break; |
172 | 172 | case "bookmark": |
173 | - $articles_obj =& $article_handler->getByBookmark($criteria, $tags); |
|
173 | + $articles_obj = & $article_handler->getByBookmark($criteria, $tags); |
|
174 | 174 | $count_article = $article_handler->getCountByBookmark($criteria); |
175 | 175 | break; |
176 | 176 | default: |
177 | - $articles_obj =& $article_handler->getAll($criteria, $tags); |
|
177 | + $articles_obj = & $article_handler->getAll($criteria, $tags); |
|
178 | 178 | $count_article = $article_handler->getCount($criteria); |
179 | 179 | break; |
180 | 180 | } |
181 | 181 | |
182 | -if(!empty($blog_data)){ |
|
182 | +if (!empty($blog_data)) { |
|
183 | 183 | $blogs[$blog_data["id"]] = $blog_data["title"]; |
184 | -}else{ |
|
184 | +}else { |
|
185 | 185 | $blog_array = array(); |
186 | 186 | foreach (array_keys($articles_obj) as $id) { |
187 | 187 | $blog_array[$articles_obj[$id]->getVar("blog_id")] = 1; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | "time" => $articles_obj[$id]->getTime(), |
200 | 200 | "blog"=> array("id"=>$articles_obj[$id]->getVar("blog_id"), "title"=>$blogs[$articles_obj[$id]->getVar("blog_id")]) |
201 | 201 | ); |
202 | - if(empty($list)){ |
|
202 | + if (empty($list)) { |
|
203 | 203 | $_article = array_merge($_article, array( |
204 | 204 | "author" => $articles_obj[$id]->getVar("art_author"), |
205 | 205 | "views"=> $articles_obj[$id]->getVar("art_views"), |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | "rates"=> $articles_obj[$id]->getVar("art_rates") |
209 | 209 | ) |
210 | 210 | ); |
211 | - if(!empty($xoopsModuleConfig["display_summary"])){ |
|
211 | + if (!empty($xoopsModuleConfig["display_summary"])) { |
|
212 | 212 | $_article["content"] = $articles_obj[$id]->getSummary(); |
213 | - }else{ |
|
213 | + }else { |
|
214 | 214 | $_article["content"] = $articles_obj[$id]->getVar("art_content"); |
215 | 215 | } |
216 | 216 | } |
@@ -219,46 +219,46 @@ discard block |
||
219 | 219 | } |
220 | 220 | unset($articles_obj); |
221 | 221 | |
222 | -if ( $count_article > $limit) { |
|
222 | +if ($count_article>$limit) { |
|
223 | 223 | include(XOOPS_ROOT_PATH."/class/pagenav.php"); |
224 | 224 | $start_link = array(); |
225 | - if($sort) $start_link[] = "sort=".$sort; |
|
226 | - if($category_id) $start_link[] = "category=".$category_id; |
|
227 | - if($blog_id) $start_link[] = "blog=".$blog_id; |
|
228 | - if($list) $start_link[] = "list=".$list; |
|
225 | + if ($sort) $start_link[] = "sort=".$sort; |
|
226 | + if ($category_id) $start_link[] = "category=".$category_id; |
|
227 | + if ($blog_id) $start_link[] = "blog=".$blog_id; |
|
228 | + if ($list) $start_link[] = "list=".$list; |
|
229 | 229 | $nav = new XoopsPageNav($count_article, $limit, $start, "start", implode("&", $start_link)); |
230 | 230 | $pagenav = $nav->renderNav(4); |
231 | -} else { |
|
231 | +}else { |
|
232 | 232 | $pagenav = ""; |
233 | 233 | } |
234 | 234 | |
235 | -$xoopsTpl -> assign("xoops_module_header", $xoops_module_header ); |
|
236 | -$xoopsTpl -> assign("dirname", $GLOBALS["moddirname"] ); |
|
235 | +$xoopsTpl -> assign("xoops_module_header", $xoops_module_header); |
|
236 | +$xoopsTpl -> assign("dirname", $GLOBALS["moddirname"]); |
|
237 | 237 | |
238 | -if($category_id || $blog_id || $uid){ |
|
238 | +if ($category_id || $blog_id || $uid) { |
|
239 | 239 | $xoopsTpl -> assign("link_index", "<a href=\"".XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php\" title=\"".planet_constant("MD_INDEX")."\" target=\"_self\">".planet_constant("MD_INDEX")."</a>"); |
240 | 240 | } |
241 | 241 | |
242 | 242 | $link_switch = "<a href=\"".XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php". |
243 | - (empty($category_id)?"":"/c".$category_id). |
|
244 | - (empty($uid)?"":"/u".$uid). |
|
245 | - (empty($blog_id)?"":"/b".$blog_id). |
|
246 | - (empty($list)?"/l1":""). |
|
247 | - "\" title=\"".(empty($list)?planet_constant("MD_LISTVIEW"):planet_constant("MD_FULLVIEW"))."\">".(empty($list)?planet_constant("MD_LISTVIEW"):planet_constant("MD_FULLVIEW"))."</a>"; |
|
243 | + (empty($category_id) ? "" : "/c".$category_id). |
|
244 | + (empty($uid) ? "" : "/u".$uid). |
|
245 | + (empty($blog_id) ? "" : "/b".$blog_id). |
|
246 | + (empty($list) ? "/l1" : ""). |
|
247 | + "\" title=\"".(empty($list) ? planet_constant("MD_LISTVIEW") : planet_constant("MD_FULLVIEW"))."\">".(empty($list) ? planet_constant("MD_LISTVIEW") : planet_constant("MD_FULLVIEW"))."</a>"; |
|
248 | 248 | $xoopsTpl -> assign("link_switch", $link_switch); |
249 | 249 | |
250 | 250 | $link_blogs = "<a href=\"".XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/view.blogs.php". |
251 | - (empty($category_id)?"":"/c".$category_id). |
|
252 | - (empty($uid)?"":"/u".$uid). |
|
251 | + (empty($category_id) ? "" : "/c".$category_id). |
|
252 | + (empty($uid) ? "" : "/u".$uid). |
|
253 | 253 | "\" title=\"".planet_constant("MD_BLOGS")."\">".planet_constant("MD_BLOGS"). |
254 | 254 | "</a>"; |
255 | 255 | $xoopsTpl -> assign("link_blogs", $link_blogs); |
256 | 256 | |
257 | -if(empty($uid) && is_object($xoopsUser)){ |
|
257 | +if (empty($uid) && is_object($xoopsUser)) { |
|
258 | 258 | $xoopsTpl -> assign("link_bookmark", "<a href=\"".XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php".URL_DELIMITER."u".$xoopsUser->getVar("uid")."\" title=\"".planet_constant("MD_BOOKMARKS")."\" target=\"_self\">".planet_constant("MD_BOOKMARKS")."</a>"); |
259 | 259 | } |
260 | 260 | |
261 | -if($xoopsModuleConfig["newblog_submit"]==1 || is_object($xoopsUser)){ |
|
261 | +if ($xoopsModuleConfig["newblog_submit"] == 1 || is_object($xoopsUser)) { |
|
262 | 262 | $xoopsTpl -> assign("link_submit", "<a href=\"".XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/action.blog.php\" title=\""._SUBMIT."\" target=\"_blank\">"._SUBMIT."</a>"); |
263 | 263 | } |
264 | 264 | |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | $xoopsTpl -> assign("pagenav", $pagenav); |
271 | 271 | $xoopsTpl -> assign("is_list", !empty($list)); |
272 | 272 | |
273 | -$xoopsTpl -> assign("user_level", !is_object($xoopsUser)?0:($xoopsUser->isAdmin()?2:1)); |
|
274 | -if(empty($xoopsModuleConfig["anonymous_rate"]) && !is_object($xoopsUser)){ |
|
275 | -}elseif($blog_id>0){ |
|
273 | +$xoopsTpl -> assign("user_level", !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1)); |
|
274 | +if (empty($xoopsModuleConfig["anonymous_rate"]) && !is_object($xoopsUser)) { |
|
275 | +}elseif ($blog_id>0) { |
|
276 | 276 | $xoopsTpl -> assign("canrate", 1); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $sort_link = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php". |
280 | - (empty($category_id)?"":"/c".$category_id). |
|
281 | - (empty($uid)?"":"/u".$uid). |
|
282 | - (empty($blog_id)?"":"/b".$blog_id). |
|
283 | - (empty($list)?"":"/l1"); |
|
280 | + (empty($category_id) ? "" : "/c".$category_id). |
|
281 | + (empty($uid) ? "" : "/u".$uid). |
|
282 | + (empty($blog_id) ? "" : "/b".$blog_id). |
|
283 | + (empty($list) ? "" : "/l1"); |
|
284 | 284 | $valid_sorts = array("views"=>planet_constant("MD_VIEWS"), "rating"=>planet_constant("MD_RATING"), "time"=>planet_constant("MD_TIME"), "default"=>planet_constant("MD_DEFAULT")); |
285 | 285 | $sortlinks = array(); |
286 | -foreach($valid_sorts as $val=>$name){ |
|
287 | - if($val == $sort) continue; |
|
286 | +foreach ($valid_sorts as $val=>$name) { |
|
287 | + if ($val == $sort) continue; |
|
288 | 288 | $sortlinks[] = "<a href=\"".$sort_link."/".$val."\">".$name."</a>"; |
289 | 289 | } |
290 | 290 | $xoopsTpl -> assign("link_sort", implode(" | ", $sortlinks)); |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | $xoopsTpl->assign('do_pseudocron', $xoopsModuleConfig["do_pseudocron"]); |
294 | 294 | |
295 | 295 | // for notification |
296 | -if(!empty($blog_id)){ |
|
296 | +if (!empty($blog_id)) { |
|
297 | 297 | //$_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php"; |
298 | 298 | $_GET["blog"] = $blog_id; |
299 | 299 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | |
182 | 182 | if(!empty($blog_data)){ |
183 | 183 | $blogs[$blog_data["id"]] = $blog_data["title"]; |
184 | -}else{ |
|
184 | +} else{ |
|
185 | 185 | $blog_array = array(); |
186 | 186 | foreach (array_keys($articles_obj) as $id) { |
187 | 187 | $blog_array[$articles_obj[$id]->getVar("blog_id")] = 1; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | ); |
211 | 211 | if(!empty($xoopsModuleConfig["display_summary"])){ |
212 | 212 | $_article["content"] = $articles_obj[$id]->getSummary(); |
213 | - }else{ |
|
213 | + } else{ |
|
214 | 214 | $_article["content"] = $articles_obj[$id]->getVar("art_content"); |
215 | 215 | } |
216 | 216 | } |
@@ -222,10 +222,18 @@ discard block |
||
222 | 222 | if ( $count_article > $limit) { |
223 | 223 | include(XOOPS_ROOT_PATH."/class/pagenav.php"); |
224 | 224 | $start_link = array(); |
225 | - if($sort) $start_link[] = "sort=".$sort; |
|
226 | - if($category_id) $start_link[] = "category=".$category_id; |
|
227 | - if($blog_id) $start_link[] = "blog=".$blog_id; |
|
228 | - if($list) $start_link[] = "list=".$list; |
|
225 | + if($sort) { |
|
226 | + $start_link[] = "sort=".$sort; |
|
227 | + } |
|
228 | + if($category_id) { |
|
229 | + $start_link[] = "category=".$category_id; |
|
230 | + } |
|
231 | + if($blog_id) { |
|
232 | + $start_link[] = "blog=".$blog_id; |
|
233 | + } |
|
234 | + if($list) { |
|
235 | + $start_link[] = "list=".$list; |
|
236 | + } |
|
229 | 237 | $nav = new XoopsPageNav($count_article, $limit, $start, "start", implode("&", $start_link)); |
230 | 238 | $pagenav = $nav->renderNav(4); |
231 | 239 | } else { |
@@ -272,7 +280,7 @@ discard block |
||
272 | 280 | |
273 | 281 | $xoopsTpl -> assign("user_level", !is_object($xoopsUser)?0:($xoopsUser->isAdmin()?2:1)); |
274 | 282 | if(empty($xoopsModuleConfig["anonymous_rate"]) && !is_object($xoopsUser)){ |
275 | -}elseif($blog_id>0){ |
|
283 | +} elseif($blog_id>0){ |
|
276 | 284 | $xoopsTpl -> assign("canrate", 1); |
277 | 285 | } |
278 | 286 | |
@@ -284,7 +292,9 @@ discard block |
||
284 | 292 | $valid_sorts = array("views"=>planet_constant("MD_VIEWS"), "rating"=>planet_constant("MD_RATING"), "time"=>planet_constant("MD_TIME"), "default"=>planet_constant("MD_DEFAULT")); |
285 | 293 | $sortlinks = array(); |
286 | 294 | foreach($valid_sorts as $val=>$name){ |
287 | - if($val == $sort) continue; |
|
295 | + if($val == $sort) { |
|
296 | + continue; |
|
297 | + } |
|
288 | 298 | $sortlinks[] = "<a href=\"".$sort_link."/".$val."\">".$name."</a>"; |
289 | 299 | } |
290 | 300 | $xoopsTpl -> assign("link_sort", implode(" | ", $sortlinks)); |