| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | class FeedWordPressParsedPostMeta { |
| 3 | 3 | var $s, $ptr, $ptrEOS; |
| 4 | 4 | var $delims, $delimCount, $delimPtr; |
| 5 | 5 | var $paren; |
| 6 | - var $anchor; // I have no idea what it's for, but it's referred from the one-liner methods... (gwyneth 20230920) | |
| 7 | 6 | |
| 8 | 7 | var $parsed = NULL; |
| 9 | 8 | |
| 10 | 9 | function __construct ($s) { |
| @@ -13,13 +12,13 @@ | ||
| 13 | 12 | } |
| 14 | 13 | |
| 15 | 14 | function reset () { |
| 16 | 15 | $this->parsed = NULL; |
| 17 | - | |
| 16 | + | |
| 18 | 17 | $this->ptr = 0; |
| 19 | 18 | $this->paren = 0; |
| 20 | 19 | $this->ptrEOS = strlen($this->s); |
| 21 | - | |
| 20 | + | |
| 22 | 21 | $this->delimCount['CDATA'] = preg_match_all('/\$/', $this->s, $this->delims['CDATA'], PREG_OFFSET_CAPTURE); |
| 23 | 22 | $this->delimPtr['CDATA'] = 0; |
| 24 | 23 | |
| 25 | 24 | $this->delimCount['EXPR'] = preg_match_all('/[()\s]/', $this->s, $this->delims['EXPR'], PREG_OFFSET_CAPTURE); |
| @@ -45,16 +44,16 @@ | ||
| 45 | 44 | $next = $this->ptrEOS; |
| 46 | 45 | endif; |
| 47 | 46 | return $next; |
| 48 | 47 | } |
| 49 | - | |
| 48 | + | |
| 50 | 49 | function substitute_terms ($post, $piece, $values = NULL) { |
| 51 | - $terms = array(); // never used. (gwyneth 20230920) | |
| 50 | + $terms = array(); | |
| 52 | 51 | if ('EXPR'==$piece[0]) : |
| 53 | 52 | // Parameter stored in $piece[1] |
| 54 | 53 | $param = $piece[1]; |
| 55 | 54 | if (is_string($param)) : |
| 56 | - if ( !isset($values[$param])) : | |
| 55 | + if (!isset($values[$param])) : | |
| 57 | 56 | $values[$param] = $post->query($param); |
| 58 | 57 | endif; |
| 59 | 58 | $term = $param; |
| 60 | 59 | $results = $values[$param]; |
| @@ -60,13 +59,13 @@ | ||
| 60 | 59 | $results = $values[$param]; |
| 61 | 60 | else : |
| 62 | 61 | list($results, $term, $values) = $this->substitute_terms($post, $piece[1], $values); |
| 63 | 62 | endif; |
| 64 | - | |
| 63 | + | |
| 65 | 64 | // Filtering function, if any, stored in $piece[2] |
| 66 | 65 | if (isset($piece[2])) : |
| 67 | 66 | $filter = $post->substitution_function(trim(strtolower($piece[2]))); |
| 68 | - if ( !is_null($filter)) : | |
| 67 | + if (!is_null($filter)) : | |
| 69 | 68 | foreach ($results as $key => $result) : |
| 70 | 69 | $results[$key] = $filter($result); |
| 71 | 70 | endforeach; |
| 72 | 71 | else : |
| @@ -74,9 +73,9 @@ | ||
| 74 | 73 | "[[ERR: No such function (".$piece[2].")]]", |
| 75 | 74 | ); |
| 76 | 75 | endif; |
| 77 | 76 | endif; |
| 78 | - | |
| 77 | + | |
| 79 | 78 | elseif ('CDATA'==$piece[0]) : |
| 80 | 79 | // Literal string stored in $piece[1] |
| 81 | 80 | $results = array($piece[1]); |
| 82 | 81 | $term = NULL; |
| @@ -87,23 +86,23 @@ | ||
| 87 | 86 | function do_substitutions ($post, $in = NULL, $scratchpad = NULL) { |
| 88 | 87 | if (is_null($in)) : |
| 89 | 88 | $in = $this->get(); |
| 90 | 89 | endif; |
| 91 | - | |
| 90 | + | |
| 92 | 91 | if (count($in) > 0) : |
| 93 | 92 | $out = array(); |
| 94 | - | |
| 93 | + | |
| 95 | 94 | // Init. results set if not already initialized. |
| 96 | 95 | if (is_null($scratchpad)) : |
| 97 | 96 | $scratchpad = array(array('', array())); |
| 98 | 97 | endif; |
| 99 | - | |
| 98 | + | |
| 100 | 99 | // Grab the first |
| 101 | 100 | $piece = array_shift($in); |
| 102 | 101 | |
| 103 | 102 | foreach ($scratchpad as $key => $scratch) : |
| 104 | 103 | $line = $scratch[0]; |
| 105 | - $element_values = $scratch[1]; | |
| 104 | + $element_values = $scratch[1]; | |
| 106 | 105 | |
| 107 | 106 | switch ($piece[0]) : |
| 108 | 107 | case 'CDATA' : |
| 109 | 108 | $subs = array($piece[1]); |
| @@ -115,18 +114,18 @@ | ||
| 115 | 114 | endswitch; |
| 116 | 115 | |
| 117 | 116 | $constrained_values = $element_values; |
| 118 | 117 | foreach ($subs as $sub) : |
| 119 | - | |
| 118 | + | |
| 120 | 119 | if (isset($term)) : |
| 121 | 120 | $constrained_values[$term] = array($sub); |
| 122 | 121 | endif; |
| 123 | - | |
| 122 | + | |
| 124 | 123 | $out[] = array($line . $sub, $constrained_values); |
| 125 | 124 | endforeach; |
| 126 | - | |
| 125 | + | |
| 127 | 126 | endforeach; |
| 128 | - | |
| 127 | + | |
| 129 | 128 | if (count($in) > 0) : |
| 130 | 129 | $out = $this->do_substitutions($post, $in, $out); |
| 131 | 130 | endif; |
| 132 | 131 | else : |
| @@ -140,25 +139,25 @@ | ||
| 140 | 139 | $out[$idx] = $line[0]; |
| 141 | 140 | endif; |
| 142 | 141 | endforeach; |
| 143 | 142 | endif; |
| 144 | - | |
| 143 | + | |
| 145 | 144 | return $out; |
| 146 | 145 | } |
| 147 | - | |
| 146 | + | |
| 148 | 147 | function get ($idx = NULL) { |
| 149 | 148 | $ret = $this->parse(); |
| 150 | 149 | if ($idx) : $ret = $ret[$idx]; endif; |
| 151 | - | |
| 150 | + | |
| 152 | 151 | return $ret; |
| 153 | 152 | } |
| 154 | - | |
| 153 | + | |
| 155 | 154 | function parse () { |
| 156 | 155 | if (is_null($this->parsed)) : |
| 157 | 156 | $out = array(); |
| 158 | - | |
| 157 | + | |
| 159 | 158 | $this->reset(); |
| 160 | - while ( ! $this->EOS()) : | |
| 159 | + while (!$this->EOS()) : | |
| 161 | 160 | switch ($this->look()) : |
| 162 | 161 | case '$' : |
| 163 | 162 | $this->ptr++; |
| 164 | 163 | $out[] = $this->EXPR(); |
| @@ -166,9 +165,9 @@ | ||
| 166 | 165 | default : |
| 167 | 166 | $out[] = $this->CDATA(); |
| 168 | 167 | endswitch; |
| 169 | 168 | endwhile; |
| 170 | - | |
| 169 | + | |
| 171 | 170 | $this->parsed = $out; |
| 172 | 171 | endif; |
| 173 | 172 | return $this->parsed; |
| 174 | 173 | } |
| @@ -182,13 +181,13 @@ | ||
| 182 | 181 | function EXPR () { |
| 183 | 182 | $ret = array(__FUNCTION__); |
| 184 | 183 | $paren0 = $this->paren; |
| 185 | 184 | $this->drop(); |
| 186 | - | |
| 185 | + | |
| 187 | 186 | $ptr0 = $this->ptr; |
| 188 | 187 | |
| 189 | 188 | $complete = false; |
| 190 | - while ( ! $this->EOS() and ! $complete) : | |
| 189 | + while (!$this->EOS() and !$complete) : | |
| 191 | 190 | $tok = $this->look(); |
| 192 | 191 | switch ($tok) : |
| 193 | 192 | case '(' : |
| 194 | 193 | |
| @@ -198,9 +197,9 @@ | ||
| 198 | 197 | $this->ptr++; |
| 199 | 198 | |
| 200 | 199 | // And indent us one level in. |
| 201 | 200 | $this->paren++; |
| 202 | - | |
| 201 | + | |
| 203 | 202 | $delta = $this->EXPR(); |
| 204 | 203 | if (isset($delta[2])) : |
| 205 | 204 | $ret[1] = $delta; |
| 206 | 205 | else : |
| @@ -239,9 +238,9 @@ | ||
| 239 | 238 | else : |
| 240 | 239 | $this->ptr++; |
| 241 | 240 | endif; |
| 242 | 241 | break; |
| 243 | - | |
| 242 | + | |
| 244 | 243 | case '$' : |
| 245 | 244 | if ($ptr0 == $this->ptr) : |
| 246 | 245 | // This is an escaped literal $ |
| 247 | 246 | $this->ptr++; |
| @@ -262,14 +261,14 @@ | ||
| 262 | 261 | else : |
| 263 | 262 | $next = $this->nextDelim('EXPR'); |
| 264 | 263 | |
| 265 | 264 | // Skip ahead to the next potentially interesting character. |
| 266 | - if ( !is_null($next)) : | |
| 265 | + if (!is_null($next)) : | |
| 267 | 266 | $this->ptr = $next; |
| 268 | 267 | else : |
| 269 | 268 | $this->ptr = $this->ptrEOS; |
| 270 | 269 | endif; |
| 271 | - | |
| 270 | + | |
| 272 | 271 | endif; |
| 273 | 272 | endswitch; |
| 274 | 273 | endwhile; |
| 275 | 274 | |