| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
@copyright |
|---|
| 6 |
@author will@flourishlib.com |
|---|
| 7 |
@license http://flourishlib.com/license |
|---|
| 8 |
|
|---|
| 9 |
@package |
|---|
| 10 |
@link http://flourishlib.com/fException |
|---|
| 11 |
|
|---|
| 12 |
@version |
|---|
| 13 |
@changes |
|---|
| 14 |
@changes |
|---|
| 15 |
@changes |
|---|
| 16 |
@changes |
|---|
| 17 |
@changes |
|---|
| 18 |
@changes |
|---|
| 19 |
@changes |
|---|
| 20 |
@changes |
|---|
| 21 |
|
|---|
| 22 |
abstract class fException extends Exception |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
@var |
|---|
| 28 |
|
|---|
| 29 |
static private $callbacks = array(); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
@param |
|---|
| 36 |
@param |
|---|
| 37 |
@param |
|---|
| 38 |
@return |
|---|
| 39 |
|
|---|
| 40 |
static protected function compose($message) |
|---|
| 41 |
{ |
|---|
| 42 |
$components = array_slice(func_get_args(), 1); |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
if (sizeof($components) == 1 && is_array($components[0])) { |
|---|
| 46 |
$components = $components[0]; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
if (class_exists('fText', FALSE)) { |
|---|
| 51 |
return call_user_func_array( |
|---|
| 52 |
array('fText', 'compose'), |
|---|
| 53 |
array($message, $components) |
|---|
| 54 |
); |
|---|
| 55 |
|
|---|
| 56 |
} else { |
|---|
| 57 |
return vsprintf($message, $components); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
http://php.net/print_r |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
@param |
|---|
| 75 |
@return |
|---|
| 76 |
|
|---|
| 77 |
static protected function dump($data) |
|---|
| 78 |
{ |
|---|
| 79 |
if (is_bool($data)) { |
|---|
| 80 |
return ($data) ? '{true}' : '{false}'; |
|---|
| 81 |
|
|---|
| 82 |
} elseif (is_null($data)) { |
|---|
| 83 |
return '{null}'; |
|---|
| 84 |
|
|---|
| 85 |
} elseif ($data === '') { |
|---|
| 86 |
return '{empty_string}'; |
|---|
| 87 |
|
|---|
| 88 |
} elseif (is_array($data) || is_object($data)) { |
|---|
| 89 |
|
|---|
| 90 |
ob_start(); |
|---|
| 91 |
var_dump($data); |
|---|
| 92 |
$output = ob_get_contents(); |
|---|
| 93 |
ob_end_clean(); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
$output = preg_replace('#=>\n( )+(?=[a-zA-Z]|&)#m', ' => ', $output); |
|---|
| 97 |
$output = str_replace('string(0) ""', '{empty_string}', $output); |
|---|
| 98 |
$output = preg_replace('#=> (&)?NULL#', '=> \1{null}', $output); |
|---|
| 99 |
$output = preg_replace('#=> (&)?bool\((false|true)\)#', '=> \1{\2}', $output); |
|---|
| 100 |
$output = preg_replace('#string\(\d+\) "#', '', $output); |
|---|
| 101 |
$output = preg_replace('#"(\n( )*)(?=\[|\})#', '\1', $output); |
|---|
| 102 |
$output = preg_replace('#(?:float|int)\((-?\d+(?:.\d+)?)\)#', '\1', $output); |
|---|
| 103 |
$output = preg_replace('#((?: )+)\["(.*?)"\]#', '\1[\2]', $output); |
|---|
| 104 |
$output = preg_replace('#(?:&)?array\(\d+\) \{\n((?: )*)((?: )(?=\[)|(?=\}))#', "Array\n\\1(\n\\1\\2", $output); |
|---|
| 105 |
$output = preg_replace('/object\((\w+)\)#\d+ \(\d+\) {\n((?: )*)((?: )(?=\[)|(?=\}))/', "\\1 Object\n\\2(\n\\2\\3", $output); |
|---|
| 106 |
$output = preg_replace('#^((?: )+)}(?=\n|$)#m', "\\1)\n", $output); |
|---|
| 107 |
$output = substr($output, 0, -2) . ')'; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
$output_lines = explode("\n", $output); |
|---|
| 111 |
$new_output = array(); |
|---|
| 112 |
$stack = 0; |
|---|
| 113 |
foreach ($output_lines as $line) { |
|---|
| 114 |
if (preg_match('#^((?: )*)([^ ])#', $line, $match)) { |
|---|
| 115 |
$spaces = strlen($match[1]); |
|---|
| 116 |
if ($spaces && $match[2] == '(') { |
|---|
| 117 |
$stack += 1; |
|---|
| 118 |
} |
|---|
| 119 |
$new_output[] = str_pad('', ($spaces)+(4*$stack)) . $line; |
|---|
| 120 |
if ($spaces && $match[2] == ')') { |
|---|
| 121 |
$stack -= 1; |
|---|
| 122 |
} |
|---|
| 123 |
} else { |
|---|
| 124 |
$new_output[] = str_pad('', ($spaces)+(4*$stack)) . $line; |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
return join("\n", $new_output); |
|---|
| 129 |
|
|---|
| 130 |
} else { |
|---|
| 131 |
return (string) $data; |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
@param |
|---|
| 144 |
@param |
|---|
| 145 |
@return |
|---|
| 146 |
|
|---|
| 147 |
static public function registerCallback($callback, $exception_type=NULL) |
|---|
| 148 |
{ |
|---|
| 149 |
if ($exception_type === NULL) { |
|---|
| 150 |
$exception_type = 'fException'; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
if (!isset(self::$callbacks[$exception_type])) { |
|---|
| 154 |
self::$callbacks[$exception_type] = array(); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
if (is_string($callback) && strpos($callback, '::') !== FALSE) { |
|---|
| 158 |
$callback = explode('::', $callback); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
self::$callbacks[$exception_type][] = $callback; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
@param |
|---|
| 169 |
@param |
|---|
| 170 |
@return |
|---|
| 171 |
|
|---|
| 172 |
static private function sortMatchingArray($a, $b) |
|---|
| 173 |
{ |
|---|
| 174 |
return -1 * strnatcmp(strlen($a), strlen($b)); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
http://php.net/sprintf |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
@param http://php.net/sprintf |
|---|
| 193 |
@param |
|---|
| 194 |
@param |
|---|
| 195 |
@param |
|---|
| 196 |
@return |
|---|
| 197 |
|
|---|
| 198 |
public function __construct($message='') |
|---|
| 199 |
{ |
|---|
| 200 |
$args = array_slice(func_get_args(), 1); |
|---|
| 201 |
$required_args = preg_match_all( |
|---|
| 202 |
'/ |
|---|
| 203 |
(?<!%) # Ensure this is not an escaped % |
|---|
| 204 |
%( # The leading % |
|---|
| 205 |
(?:\d+\$)? # Position |
|---|
| 206 |
\+? # Sign specifier |
|---|
| 207 |
(?:(?:0|\'.)?-?\d+|-?) # Padding, alignment and width or just alignment |
|---|
| 208 |
(?:\.\d+)? # Precision |
|---|
| 209 |
[bcdeufFosxX] # Type |
|---|
| 210 |
)/x', |
|---|
| 211 |
$message, |
|---|
| 212 |
$matches |
|---|
| 213 |
); |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
$formats = $matches[1]; |
|---|
| 217 |
$delimeters = ($formats) ? array_fill(0, sizeof($formats), '#') : array(); |
|---|
| 218 |
$lookahead = join( |
|---|
| 219 |
'|', |
|---|
| 220 |
array_map( |
|---|
| 221 |
'preg_quote', |
|---|
| 222 |
$formats, |
|---|
| 223 |
$delimeters |
|---|
| 224 |
) |
|---|
| 225 |
); |
|---|
| 226 |
$lookahead = ($lookahead) ? '|' . $lookahead : ''; |
|---|
| 227 |
$message = preg_replace('#(?<!%)%(?!%' . $lookahead . ')#', '%%', $message); |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
$code = NULL; |
|---|
| 231 |
if ($required_args == sizeof($args) - 1) { |
|---|
| 232 |
$code = array_pop($args); |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
if (sizeof($args) != $required_args) { |
|---|
| 236 |
$message = self::compose( |
|---|
| 237 |
'%1$d components were passed to the %2$s constructor, while %3$d were specified in the message', |
|---|
| 238 |
sizeof($args), |
|---|
| 239 |
get_class($this), |
|---|
| 240 |
$required_args |
|---|
| 241 |
); |
|---|
| 242 |
throw new Exception($message); |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
$args = array_map(array('fException', 'dump'), $args); |
|---|
| 246 |
|
|---|
| 247 |
parent::__construct(self::compose($message, $args)); |
|---|
| 248 |
$this->code = $code; |
|---|
| 249 |
|
|---|
| 250 |
foreach (self::$callbacks as $class => $callbacks) { |
|---|
| 251 |
foreach ($callbacks as $callback) { |
|---|
| 252 |
if ($this instanceof $class) { |
|---|
| 253 |
call_user_func($callback, $this); |
|---|
| 254 |
} |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
@internal |
|---|
| 264 |
|
|---|
| 265 |
@param |
|---|
| 266 |
@return |
|---|
| 267 |
|
|---|
| 268 |
public function __get($method) |
|---|
| 269 |
{ |
|---|
| 270 |
return array($this, $method); |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
@return |
|---|
| 278 |
|
|---|
| 279 |
public function formatTrace() |
|---|
| 280 |
{ |
|---|
| 281 |
$doc_root = realpath($_SERVER['DOCUMENT_ROOT']); |
|---|
| 282 |
$doc_root .= (substr($doc_root, -1) != DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : ''; |
|---|
| 283 |
|
|---|
| 284 |
$backtrace = explode("\n", $this->getTraceAsString()); |
|---|
| 285 |
array_unshift($backtrace, $this->file . '(' . $this->line . ')'); |
|---|
| 286 |
$backtrace = preg_replace('/^#\d+\s+/', '', $backtrace); |
|---|
| 287 |
$backtrace = str_replace($doc_root, '{doc_root}' . DIRECTORY_SEPARATOR, $backtrace); |
|---|
| 288 |
$backtrace = array_diff($backtrace, array('{main}')); |
|---|
| 289 |
$backtrace = array_reverse($backtrace); |
|---|
| 290 |
|
|---|
| 291 |
return join("\n", $backtrace); |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
@return |
|---|
| 299 |
|
|---|
| 300 |
protected function getCSSClass() |
|---|
| 301 |
{ |
|---|
| 302 |
$string = preg_replace('#^f#', '', get_class($this)); |
|---|
| 303 |
|
|---|
| 304 |
do { |
|---|
| 305 |
$old_string = $string; |
|---|
| 306 |
$string = preg_replace('/([a-zA-Z])([0-9])/', '\1_\2', $string); |
|---|
| 307 |
$string = preg_replace('/([a-z0-9A-Z])([A-Z])/', '\1_\2', $string); |
|---|
| 308 |
} while ($old_string != $string); |
|---|
| 309 |
|
|---|
| 310 |
return strtolower($string); |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
@return |
|---|
| 318 |
|
|---|
| 319 |
protected function prepare($content) |
|---|
| 320 |
{ |
|---|
| 321 |
|
|---|
| 322 |
static $inline_tags_minus_br = '<a><abbr><acronym><b><big><button><cite><code><del><dfn><em><font><i><img><input><ins><kbd><label><q><s><samp><select><small><span><strike><strong><sub><sup><textarea><tt><u><var>'; |
|---|
| 323 |
$content_with_newlines = (strip_tags($content, $inline_tags_minus_br)) ? $content : nl2br($content); |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
$inline_tags = $inline_tags_minus_br . '<br>'; |
|---|
| 327 |
$no_block_html = strip_tags($content, $inline_tags) == $content; |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
$reg_exp = "/<\s*\/?\s*[\w:]+(?:\s+[\w:]+(?:\s*=\s*(?:\"[^\"]*?\"|'[^']*?'|[^'\">\s]+))?)*\s*\/?\s*>|&(?:#\d+|\w+);|<\!--.*?-->/"; |
|---|
| 331 |
preg_match_all($reg_exp, $content, $html_matches, PREG_SET_ORDER); |
|---|
| 332 |
$text_matches = preg_split($reg_exp, $content_with_newlines); |
|---|
| 333 |
|
|---|
| 334 |
foreach($text_matches as $key => $value) { |
|---|
| 335 |
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
for ($i = 0; $i < sizeof($html_matches); $i++) { |
|---|
| 339 |
$text_matches[$i] .= $html_matches[$i][0]; |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
$content_with_newlines = implode($text_matches); |
|---|
| 343 |
|
|---|
| 344 |
$output = ($no_block_html) ? '<p>' : ''; |
|---|
| 345 |
$output .= $content_with_newlines; |
|---|
| 346 |
$output .= ($no_block_html) ? '</p>' : ''; |
|---|
| 347 |
|
|---|
| 348 |
return $output; |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
@return |
|---|
| 356 |
|
|---|
| 357 |
public function printMessage() |
|---|
| 358 |
{ |
|---|
| 359 |
echo '<div class="exception ' . $this->getCSSClass() . '">'; |
|---|
| 360 |
echo $this->prepare($this->message); |
|---|
| 361 |
echo '</div>'; |
|---|
| 362 |
} |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
@return |
|---|
| 369 |
|
|---|
| 370 |
public function printTrace() |
|---|
| 371 |
{ |
|---|
| 372 |
echo '<pre class="exception ' . $this->getCSSClass() . ' trace">'; |
|---|
| 373 |
echo $this->formatTrace(); |
|---|
| 374 |
echo '</pre>'; |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
@param |
|---|
| 382 |
@param |
|---|
| 383 |
@return |
|---|
| 384 |
|
|---|
| 385 |
public function reorderMessage($match) |
|---|
| 386 |
{ |
|---|
| 387 |
|
|---|
| 388 |
if (!preg_match('#^(.*<(?:ul|ol)[^>]*?>)(.*?)(</(?:ul|ol)>.*)$#isD', $this->message, $message_parts)) { |
|---|
| 389 |
return $this; |
|---|
| 390 |
} |
|---|
| 391 |
|
|---|
| 392 |
$matching_array = func_get_args(); |
|---|
| 393 |
|
|---|
| 394 |
uasort($matching_array, array('self', 'sortMatchingArray')); |
|---|
| 395 |
|
|---|
| 396 |
$beginning = $message_parts[1]; |
|---|
| 397 |
$list_contents = $message_parts[2]; |
|---|
| 398 |
$ending = $message_parts[3]; |
|---|
| 399 |
|
|---|
| 400 |
preg_match_all('#<li(.*?)</li>#i', $list_contents, $list_items, PREG_SET_ORDER); |
|---|
| 401 |
|
|---|
| 402 |
$ordered_items = array_fill(0, sizeof($matching_array), array()); |
|---|
| 403 |
$other_items = array(); |
|---|
| 404 |
|
|---|
| 405 |
foreach ($list_items as $list_item) { |
|---|
| 406 |
foreach ($matching_array as $num => $match_string) { |
|---|
| 407 |
if (strpos($list_item[1], $match_string) !== FALSE) { |
|---|
| 408 |
$ordered_items[$num][] = $list_item[0]; |
|---|
| 409 |
continue 2; |
|---|
| 410 |
} |
|---|
| 411 |
} |
|---|
| 412 |
|
|---|
| 413 |
$other_items[] = $list_item[0]; |
|---|
| 414 |
} |
|---|
| 415 |
|
|---|
| 416 |
$final_list = array(); |
|---|
| 417 |
foreach ($ordered_items as $ordered_item) { |
|---|
| 418 |
$final_list = array_merge($final_list, $ordered_item); |
|---|
| 419 |
} |
|---|
| 420 |
$final_list = array_merge($final_list, $other_items); |
|---|
| 421 |
|
|---|
| 422 |
$this->message = $beginning . join("\n", $final_list) . $ending; |
|---|
| 423 |
|
|---|
| 424 |
return $this; |
|---|
| 425 |
} |
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
@param |
|---|
| 432 |
@return |
|---|
| 433 |
|
|---|
| 434 |
public function setMessage($new_message) |
|---|
| 435 |
{ |
|---|
| 436 |
$this->message = $new_message; |
|---|
| 437 |
} |
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
@param |
|---|
| 513 |
@param |
|---|
| 514 |
@return |
|---|
| 515 |
|
|---|
| 516 |
public function splitMessage($list_item_matches) |
|---|
| 517 |
{ |
|---|
| 518 |
$class = get_class($this); |
|---|
| 519 |
|
|---|
| 520 |
$matching_arrays = func_get_args(); |
|---|
| 521 |
|
|---|
| 522 |
if (!preg_match('#^(.*<(?:ul|ol)[^>]*?>)(.*?)(</(?:ul|ol)>.*)$#isD', $this->message, $matches)) { |
|---|
| 523 |
return array_merge(array($this->message), array_fill(0, sizeof($matching_arrays)-1, '')); |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
$beginning_html = $matches[1]; |
|---|
| 527 |
$list_items_html = $matches[2]; |
|---|
| 528 |
$ending_html = $matches[3]; |
|---|
| 529 |
|
|---|
| 530 |
preg_match_all('#<li(.*?)</li>#i', $list_items_html, $list_items, PREG_SET_ORDER); |
|---|
| 531 |
|
|---|
| 532 |
$output = array(); |
|---|
| 533 |
|
|---|
| 534 |
foreach ($matching_arrays as $matching_array) { |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
uasort($matching_array, array('self', 'sortMatchingArray')); |
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
$matched_list_items = array_fill(0, sizeof($matching_array), array()); |
|---|
| 541 |
$found = FALSE; |
|---|
| 542 |
|
|---|
| 543 |
foreach ($list_items as $list_item) { |
|---|
| 544 |
foreach ($matching_array as $match_num => $matching_string) { |
|---|
| 545 |
if (strpos($list_item[1], $matching_string) !== FALSE) { |
|---|
| 546 |
$matched_list_items[$match_num][] = $list_item[0]; |
|---|
| 547 |
$found = TRUE; |
|---|
| 548 |
continue 2; |
|---|
| 549 |
} |
|---|
| 550 |
} |
|---|
| 551 |
} |
|---|
| 552 |
|
|---|
| 553 |
if (!$found) { |
|---|
| 554 |
$output[] = ''; |
|---|
| 555 |
continue; |
|---|
| 556 |
} |
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
$merged_list_items = array(); |
|---|
| 560 |
foreach ($matched_list_items as $match_num => $matched_items) { |
|---|
| 561 |
$merged_list_items = array_merge($merged_list_items, $matched_items); |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
$output[] = $beginning_html . join("\n", $merged_list_items) . $ending_html; |
|---|
| 565 |
} |
|---|
| 566 |
|
|---|
| 567 |
return $output; |
|---|
| 568 |
} |
|---|
| 569 |
} |
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
will@flourishlib.com |
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|