@@ -133,7 +133,9 @@ |
||
| 133 | 133 | } |
| 134 | 134 | if (is_string($config)) { |
| 135 | 135 | $ret->loadIni($config); |
| 136 | - } elseif (is_array($config)) $ret->loadArray($config); |
|
| 136 | + } elseif (is_array($config)) { |
|
| 137 | + $ret->loadArray($config); |
|
| 138 | + } |
|
| 137 | 139 | return $ret; |
| 138 | 140 | } |
| 139 | 141 | |
@@ -41,7 +41,10 @@ |
||
| 41 | 41 | $matches = array(); |
| 42 | 42 | $result = preg_match($r_URI, $uri, $matches); |
| 43 | 43 | |
| 44 | - if (!$result) return false; // *really* invalid URI |
|
| 44 | + if (!$result) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + // *really* invalid URI |
|
| 45 | 48 | |
| 46 | 49 | // seperate out parts |
| 47 | 50 | $scheme = !empty($matches[1]) ? $matches[2] : null; |
@@ -42,7 +42,10 @@ discard block |
||
| 42 | 42 | public function addFilter($filter, $config) |
| 43 | 43 | { |
| 44 | 44 | $r = $filter->prepare($config); |
| 45 | - if ($r === false) return; // null is ok, for backwards compat |
|
| 45 | + if ($r === false) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + // null is ok, for backwards compat |
|
| 46 | 49 | if ($filter->post) { |
| 47 | 50 | $this->postFilters[$filter->name] = $filter; |
| 48 | 51 | } else { |
@@ -79,9 +82,13 @@ discard block |
||
| 79 | 82 | $parser = new HTMLPurifier_URIParser(); |
| 80 | 83 | $this->base = $parser->parse($base_uri); |
| 81 | 84 | $this->defaultScheme = $this->base->scheme; |
| 82 | - if (is_null($this->host)) $this->host = $this->base->host; |
|
| 85 | + if (is_null($this->host)) { |
|
| 86 | + $this->host = $this->base->host; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + if (is_null($this->defaultScheme)) { |
|
| 90 | + $this->defaultScheme = $config->get('URI.DefaultScheme'); |
|
| 83 | 91 | } |
| 84 | - if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI.DefaultScheme'); |
|
| 85 | 92 | } |
| 86 | 93 | |
| 87 | 94 | public function getDefaultScheme($config, $context) |
@@ -93,7 +100,9 @@ discard block |
||
| 93 | 100 | { |
| 94 | 101 | foreach ($this->filters as $name => $f) { |
| 95 | 102 | $result = $f->filter($uri, $config, $context); |
| 96 | - if (!$result) return false; |
|
| 103 | + if (!$result) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 97 | 106 | } |
| 98 | 107 | return true; |
| 99 | 108 | } |
@@ -102,7 +111,9 @@ discard block |
||
| 102 | 111 | { |
| 103 | 112 | foreach ($this->postFilters as $name => $f) { |
| 104 | 113 | $result = $f->filter($uri, $config, $context); |
| 105 | - if (!$result) return false; |
|
| 114 | + if (!$result) { |
|
| 115 | + return false; |
|
| 116 | + } |
|
| 106 | 117 | } |
| 107 | 118 | return true; |
| 108 | 119 | } |
@@ -46,7 +46,9 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function toArray($t = NULL) { |
| 48 | 48 | $a = $this->front; |
| 49 | - if ($t !== NULL) $a[] = $t; |
|
| 49 | + if ($t !== NULL) { |
|
| 50 | + $a[] = $t; |
|
| 51 | + } |
|
| 50 | 52 | for ($i = count($this->back)-1; $i >= 0; $i--) { |
| 51 | 53 | $a[] = $this->back[$i]; |
| 52 | 54 | } |
@@ -59,7 +61,9 @@ discard block |
||
| 59 | 61 | * @return Original contents of new hole. |
| 60 | 62 | */ |
| 61 | 63 | public function next($t) { |
| 62 | - if ($t !== NULL) array_push($this->front, $t); |
|
| 64 | + if ($t !== NULL) { |
|
| 65 | + array_push($this->front, $t); |
|
| 66 | + } |
|
| 63 | 67 | return empty($this->back) ? NULL : array_pop($this->back); |
| 64 | 68 | } |
| 65 | 69 | |
@@ -82,7 +86,9 @@ discard block |
||
| 82 | 86 | * @return Original contents of new hole. |
| 83 | 87 | */ |
| 84 | 88 | public function prev($t) { |
| 85 | - if ($t !== NULL) array_push($this->back, $t); |
|
| 89 | + if ($t !== NULL) { |
|
| 90 | + array_push($this->back, $t); |
|
| 91 | + } |
|
| 86 | 92 | return empty($this->front) ? NULL : array_pop($this->front); |
| 87 | 93 | } |
| 88 | 94 | |
@@ -108,7 +114,9 @@ discard block |
||
| 108 | 114 | * @param Element to insert |
| 109 | 115 | */ |
| 110 | 116 | public function insertBefore($t) { |
| 111 | - if ($t !== NULL) array_push($this->front, $t); |
|
| 117 | + if ($t !== NULL) { |
|
| 118 | + array_push($this->front, $t); |
|
| 119 | + } |
|
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | /** |
@@ -116,7 +124,9 @@ discard block |
||
| 116 | 124 | * @param Element to insert |
| 117 | 125 | */ |
| 118 | 126 | public function insertAfter($t) { |
| 119 | - if ($t !== NULL) array_push($this->back, $t); |
|
| 127 | + if ($t !== NULL) { |
|
| 128 | + array_push($this->back, $t); |
|
| 129 | + } |
|
| 120 | 130 | } |
| 121 | 131 | |
| 122 | 132 | /** |
@@ -105,7 +105,9 @@ |
||
| 105 | 105 | break; |
| 106 | 106 | case 'caption': |
| 107 | 107 | // there can only be one caption! |
| 108 | - if ($caption !== false) break; |
|
| 108 | + if ($caption !== false) { |
|
| 109 | + break; |
|
| 110 | + } |
|
| 109 | 111 | $caption = $node; |
| 110 | 112 | $ws_accum =& $after_caption_ws; |
| 111 | 113 | break; |
@@ -327,9 +327,13 @@ |
||
| 327 | 327 | $ret .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; |
| 328 | 328 | // No protection if $html contains a stray </div>! |
| 329 | 329 | $ret .= '</head><body>'; |
| 330 | - if ($use_div) $ret .= '<div>'; |
|
| 330 | + if ($use_div) { |
|
| 331 | + $ret .= '<div>'; |
|
| 332 | + } |
|
| 331 | 333 | $ret .= $html; |
| 332 | - if ($use_div) $ret .= '</div>'; |
|
| 334 | + if ($use_div) { |
|
| 335 | + $ret .= '</div>'; |
|
| 336 | + } |
|
| 333 | 337 | $ret .= '</body></html>'; |
| 334 | 338 | return $ret; |
| 335 | 339 | } |
@@ -56,8 +56,9 @@ discard block |
||
| 56 | 56 | $parser =& $parser_list[$parser_class][$attr]; |
| 57 | 57 | |
| 58 | 58 | # create the parser if not already set |
| 59 | - if (!$parser) |
|
| 60 | - $parser = new $parser_class($attr); |
|
| 59 | + if (!$parser) { |
|
| 60 | + $parser = new $parser_class($attr); |
|
| 61 | + } |
|
| 61 | 62 | |
| 62 | 63 | # Transform text using parser. |
| 63 | 64 | return $parser->transform($text); |
@@ -119,44 +120,31 @@ discard block |
||
| 119 | 120 | # |
| 120 | 121 | if ($attr == "0") { |
| 121 | 122 | $this->do_nothing = 1; |
| 122 | - } |
|
| 123 | - else if ($attr == "1") { |
|
| 123 | + } else if ($attr == "1") { |
|
| 124 | 124 | # Do everything, turn all options on. |
| 125 | 125 | $this->do_quotes = 1; |
| 126 | 126 | $this->do_backticks = 1; |
| 127 | 127 | $this->do_dashes = 1; |
| 128 | 128 | $this->do_ellipses = 1; |
| 129 | - } |
|
| 130 | - else if ($attr == "2") { |
|
| 129 | + } else if ($attr == "2") { |
|
| 131 | 130 | # Do everything, turn all options on, use old school dash shorthand. |
| 132 | 131 | $this->do_quotes = 1; |
| 133 | 132 | $this->do_backticks = 1; |
| 134 | 133 | $this->do_dashes = 2; |
| 135 | 134 | $this->do_ellipses = 1; |
| 136 | - } |
|
| 137 | - else if ($attr == "3") { |
|
| 135 | + } else if ($attr == "3") { |
|
| 138 | 136 | # Do everything, turn all options on, use inverted old school dash shorthand. |
| 139 | 137 | $this->do_quotes = 1; |
| 140 | 138 | $this->do_backticks = 1; |
| 141 | 139 | $this->do_dashes = 3; |
| 142 | 140 | $this->do_ellipses = 1; |
| 143 | - } |
|
| 144 | - else if ($attr == "-1") { |
|
| 141 | + } else if ($attr == "-1") { |
|
| 145 | 142 | # Special "stupefy" mode. |
| 146 | 143 | $this->do_stupefy = 1; |
| 147 | - } |
|
| 148 | - else { |
|
| 144 | + } else { |
|
| 149 | 145 | $chars = preg_split('//', $attr); |
| 150 | 146 | foreach ($chars as $c){ |
| 151 | - if ($c == "q") { $this->do_quotes = 1; } |
|
| 152 | - else if ($c == "b") { $this->do_backticks = 1; } |
|
| 153 | - else if ($c == "B") { $this->do_backticks = 2; } |
|
| 154 | - else if ($c == "d") { $this->do_dashes = 1; } |
|
| 155 | - else if ($c == "D") { $this->do_dashes = 2; } |
|
| 156 | - else if ($c == "i") { $this->do_dashes = 3; } |
|
| 157 | - else if ($c == "e") { $this->do_ellipses = 1; } |
|
| 158 | - else if ($c == "w") { $this->convert_quot = 1; } |
|
| 159 | - else { |
|
| 147 | + if ($c == "q") { $this->do_quotes = 1; } else if ($c == "b") { $this->do_backticks = 1; } else if ($c == "B") { $this->do_backticks = 2; } else if ($c == "d") { $this->do_dashes = 1; } else if ($c == "D") { $this->do_dashes = 2; } else if ($c == "i") { $this->do_dashes = 3; } else if ($c == "e") { $this->do_ellipses = 1; } else if ($c == "w") { $this->convert_quot = 1; } else { |
|
| 160 | 148 | # Unknown attribute option, ignore. |
| 161 | 149 | } |
| 162 | 150 | } |
@@ -234,17 +222,27 @@ discard block |
||
| 234 | 222 | } |
| 235 | 223 | |
| 236 | 224 | if ($this->do_dashes) { |
| 237 | - if ($this->do_dashes == 1) $t = $this->educateDashes($t); |
|
| 238 | - if ($this->do_dashes == 2) $t = $this->educateDashesOldSchool($t); |
|
| 239 | - if ($this->do_dashes == 3) $t = $this->educateDashesOldSchoolInverted($t); |
|
| 225 | + if ($this->do_dashes == 1) { |
|
| 226 | + $t = $this->educateDashes($t); |
|
| 227 | + } |
|
| 228 | + if ($this->do_dashes == 2) { |
|
| 229 | + $t = $this->educateDashesOldSchool($t); |
|
| 230 | + } |
|
| 231 | + if ($this->do_dashes == 3) { |
|
| 232 | + $t = $this->educateDashesOldSchoolInverted($t); |
|
| 233 | + } |
|
| 240 | 234 | } |
| 241 | 235 | |
| 242 | - if ($this->do_ellipses) $t = $this->educateEllipses($t); |
|
| 236 | + if ($this->do_ellipses) { |
|
| 237 | + $t = $this->educateEllipses($t); |
|
| 238 | + } |
|
| 243 | 239 | |
| 244 | 240 | # Note: backticks need to be processed before quotes. |
| 245 | 241 | if ($this->do_backticks) { |
| 246 | 242 | $t = $this->educateBackticks($t); |
| 247 | - if ($this->do_backticks == 2) $t = $this->educateSingleBackticks($t); |
|
| 243 | + if ($this->do_backticks == 2) { |
|
| 244 | + $t = $this->educateSingleBackticks($t); |
|
| 245 | + } |
|
| 248 | 246 | } |
| 249 | 247 | |
| 250 | 248 | if ($this->do_quotes) { |
@@ -252,27 +250,25 @@ discard block |
||
| 252 | 250 | # Special case: single-character ' token |
| 253 | 251 | if (preg_match('/\S/', $prev_token_last_char)) { |
| 254 | 252 | $t = $this->smart_singlequote_close; |
| 255 | - } |
|
| 256 | - else { |
|
| 253 | + } else { |
|
| 257 | 254 | $t = $this->smart_singlequote_open; |
| 258 | 255 | } |
| 259 | - } |
|
| 260 | - else if ($t == '"') { |
|
| 256 | + } else if ($t == '"') { |
|
| 261 | 257 | # Special case: single-character " token |
| 262 | 258 | if (preg_match('/\S/', $prev_token_last_char)) { |
| 263 | 259 | $t = $this->smart_doublequote_close; |
| 264 | - } |
|
| 265 | - else { |
|
| 260 | + } else { |
|
| 266 | 261 | $t = $this->smart_doublequote_open; |
| 267 | 262 | } |
| 268 | - } |
|
| 269 | - else { |
|
| 263 | + } else { |
|
| 270 | 264 | # Normal case: |
| 271 | 265 | $t = $this->educateQuotes($t); |
| 272 | 266 | } |
| 273 | 267 | } |
| 274 | 268 | |
| 275 | - if ($this->do_stupefy) $t = $this->stupefyEntities($t); |
|
| 269 | + if ($this->do_stupefy) { |
|
| 270 | + $t = $this->stupefyEntities($t); |
|
| 271 | + } |
|
| 276 | 272 | |
| 277 | 273 | return $t; |
| 278 | 274 | } |
@@ -549,10 +545,11 @@ discard block |
||
| 549 | 545 | $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 550 | 546 | |
| 551 | 547 | foreach ($parts as $part) { |
| 552 | - if (++$index % 2 && $part != '') |
|
| 553 | - $tokens[] = array('text', $part); |
|
| 554 | - else |
|
| 555 | - $tokens[] = array('tag', $part); |
|
| 548 | + if (++$index % 2 && $part != '') { |
|
| 549 | + $tokens[] = array('text', $part); |
|
| 550 | + } else { |
|
| 551 | + $tokens[] = array('tag', $part); |
|
| 552 | + } |
|
| 556 | 553 | } |
| 557 | 554 | return $tokens; |
| 558 | 555 | } |
@@ -116,34 +116,19 @@ discard block |
||
| 116 | 116 | $this->do_space_frenchquote = 1; |
| 117 | 117 | $this->do_space_thousand = 1; |
| 118 | 118 | $this->do_space_unit = 1; |
| 119 | - } |
|
| 120 | - else if ($attr == "-1") { |
|
| 119 | + } else if ($attr == "-1") { |
|
| 121 | 120 | # Special "stupefy" mode. |
| 122 | 121 | $this->do_stupefy = 1; |
| 123 | - } |
|
| 124 | - else { |
|
| 122 | + } else { |
|
| 125 | 123 | $chars = preg_split('//', $attr); |
| 126 | 124 | foreach ($chars as $c){ |
| 127 | - if ($c == "c") { $current =& $this->do_comma_quotes; } |
|
| 128 | - else if ($c == "g") { $current =& $this->do_guillemets; } |
|
| 129 | - else if ($c == "G") { $current =& $this->do_geresh_gershayim; } |
|
| 130 | - else if ($c == ":") { $current =& $this->do_space_colon; } |
|
| 131 | - else if ($c == ";") { $current =& $this->do_space_semicolon; } |
|
| 132 | - else if ($c == "m") { $current =& $this->do_space_marks; } |
|
| 133 | - else if ($c == "h") { $current =& $this->do_space_emdash; } |
|
| 134 | - else if ($c == "H") { $current =& $this->do_space_endash; } |
|
| 135 | - else if ($c == "f") { $current =& $this->do_space_frenchquote; } |
|
| 136 | - else if ($c == "t") { $current =& $this->do_space_thousand; } |
|
| 137 | - else if ($c == "u") { $current =& $this->do_space_unit; } |
|
| 138 | - else if ($c == "+") { |
|
| 125 | + if ($c == "c") { $current =& $this->do_comma_quotes; } else if ($c == "g") { $current =& $this->do_guillemets; } else if ($c == "G") { $current =& $this->do_geresh_gershayim; } else if ($c == ":") { $current =& $this->do_space_colon; } else if ($c == ";") { $current =& $this->do_space_semicolon; } else if ($c == "m") { $current =& $this->do_space_marks; } else if ($c == "h") { $current =& $this->do_space_emdash; } else if ($c == "H") { $current =& $this->do_space_endash; } else if ($c == "f") { $current =& $this->do_space_frenchquote; } else if ($c == "t") { $current =& $this->do_space_thousand; } else if ($c == "u") { $current =& $this->do_space_unit; } else if ($c == "+") { |
|
| 139 | 126 | $current = 2; |
| 140 | 127 | unset($current); |
| 141 | - } |
|
| 142 | - else if ($c == "-") { |
|
| 128 | + } else if ($c == "-") { |
|
| 143 | 129 | $current = -1; |
| 144 | 130 | unset($current); |
| 145 | - } |
|
| 146 | - else { |
|
| 131 | + } else { |
|
| 147 | 132 | # Unknown attribute option, ignore. |
| 148 | 133 | } |
| 149 | 134 | $current = 1; |
@@ -175,21 +160,43 @@ discard block |
||
| 175 | 160 | |
| 176 | 161 | function educate($t, $prev_token_last_char) { |
| 177 | 162 | # must happen before regular smart quotes |
| 178 | - if ($this->do_geresh_gershayim) $t = $this->educateGereshGershayim($t); |
|
| 163 | + if ($this->do_geresh_gershayim) { |
|
| 164 | + $t = $this->educateGereshGershayim($t); |
|
| 165 | + } |
|
| 179 | 166 | |
| 180 | 167 | $t = parent::educate($t, $prev_token_last_char); |
| 181 | 168 | |
| 182 | - if ($this->do_comma_quotes) $t = $this->educateCommaQuotes($t); |
|
| 183 | - if ($this->do_guillemets) $t = $this->educateGuillemets($t); |
|
| 169 | + if ($this->do_comma_quotes) { |
|
| 170 | + $t = $this->educateCommaQuotes($t); |
|
| 171 | + } |
|
| 172 | + if ($this->do_guillemets) { |
|
| 173 | + $t = $this->educateGuillemets($t); |
|
| 174 | + } |
|
| 184 | 175 | |
| 185 | - if ($this->do_space_emdash) $t = $this->spaceEmDash($t); |
|
| 186 | - if ($this->do_space_endash) $t = $this->spaceEnDash($t); |
|
| 187 | - if ($this->do_space_colon) $t = $this->spaceColon($t); |
|
| 188 | - if ($this->do_space_semicolon) $t = $this->spaceSemicolon($t); |
|
| 189 | - if ($this->do_space_marks) $t = $this->spaceMarks($t); |
|
| 190 | - if ($this->do_space_frenchquote) $t = $this->spaceFrenchQuotes($t); |
|
| 191 | - if ($this->do_space_thousand) $t = $this->spaceThousandSeparator($t); |
|
| 192 | - if ($this->do_space_unit) $t = $this->spaceUnit($t); |
|
| 176 | + if ($this->do_space_emdash) { |
|
| 177 | + $t = $this->spaceEmDash($t); |
|
| 178 | + } |
|
| 179 | + if ($this->do_space_endash) { |
|
| 180 | + $t = $this->spaceEnDash($t); |
|
| 181 | + } |
|
| 182 | + if ($this->do_space_colon) { |
|
| 183 | + $t = $this->spaceColon($t); |
|
| 184 | + } |
|
| 185 | + if ($this->do_space_semicolon) { |
|
| 186 | + $t = $this->spaceSemicolon($t); |
|
| 187 | + } |
|
| 188 | + if ($this->do_space_marks) { |
|
| 189 | + $t = $this->spaceMarks($t); |
|
| 190 | + } |
|
| 191 | + if ($this->do_space_frenchquote) { |
|
| 192 | + $t = $this->spaceFrenchQuotes($t); |
|
| 193 | + } |
|
| 194 | + if ($this->do_space_thousand) { |
|
| 195 | + $t = $this->spaceThousandSeparator($t); |
|
| 196 | + } |
|
| 197 | + if ($this->do_space_unit) { |
|
| 198 | + $t = $this->spaceUnit($t); |
|
| 199 | + } |
|
| 193 | 200 | |
| 194 | 201 | return $t; |
| 195 | 202 | } |
@@ -210,8 +210,7 @@ discard block |
||
| 210 | 210 | if (!$whitespace_preserve) { |
| 211 | 211 | if (trim($node->data) === "") { |
| 212 | 212 | $node->data = $whitespace; |
| 213 | - } |
|
| 214 | - else { |
|
| 213 | + } else { |
|
| 215 | 214 | $node->data = preg_replace('{\s+}', ' ', $node->data); |
| 216 | 215 | } |
| 217 | 216 | } |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | if ($element->firstChild->nodeType == XML_TEXT_NODE) { |
| 225 | 224 | $element->firstChild->data = |
| 226 | 225 | preg_replace('{^\s+}', "\n", $element->firstChild->data); |
| 227 | - } |
|
| 228 | - else { |
|
| 226 | + } else { |
|
| 229 | 227 | $element->insertBefore(new DOMText("\n"), $element->firstChild); |
| 230 | 228 | } |
| 231 | 229 | } |
@@ -233,8 +231,7 @@ discard block |
||
| 233 | 231 | if ($element->lastChild->nodeType == XML_TEXT_NODE) { |
| 234 | 232 | $element->lastChild->data = |
| 235 | 233 | preg_replace('{\s+$}', "\n", $element->lastChild->data); |
| 236 | - } |
|
| 237 | - else { |
|
| 234 | + } else { |
|
| 238 | 235 | $element->insertBefore(new DOMText("\n"), null); |
| 239 | 236 | } |
| 240 | 237 | } |