| @@ 210-225 (lines=16) @@ | ||
| 207 | /** |
|
| 208 | * @brief Replaces BBCode urls. |
|
| 209 | */ |
|
| 210 | protected function replaceUrls() |
|
| 211 | { |
|
| 212 | ||
| 213 | $this->text = preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu', |
|
| 214 | ||
| 215 | function ($matches) { |
|
| 216 | if ( isset($matches[1]) && isset($matches[2]) ) |
|
| 217 | return "[" . $matches[2] . "](" . $matches[1] . ")"; |
|
| 218 | else |
|
| 219 | throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id)); |
|
| 220 | }, |
|
| 221 | ||
| 222 | $this->text |
|
| 223 | ); |
|
| 224 | ||
| 225 | } |
|
| 226 | ||
| 227 | ||
| 228 | /** |
|
| @@ 231-245 (lines=15) @@ | ||
| 228 | /** |
|
| 229 | * @brief Replaces BBCode urls without a description. |
|
| 230 | */ |
|
| 231 | protected function replaceUndescribedUrls() |
|
| 232 | { |
|
| 233 | $this->text = preg_replace_callback('%\[url\]([\W\D\w\s]*?)\[/url\]%iu', |
|
| 234 | ||
| 235 | function ($matches) { |
|
| 236 | if ( isset($matches[1]) ) |
|
| 237 | return "[" . $matches[1] . "](" . $matches[1] . ")"; |
|
| 238 | else |
|
| 239 | throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id)); |
|
| 240 | }, |
|
| 241 | ||
| 242 | $this->text |
|
| 243 | ); |
|
| 244 | ||
| 245 | } |
|
| 246 | ||
| 247 | ||
| 248 | /** |
|