Changeset 693 for trunk/phpbms/include
- Timestamp:
- 12/31/09 13:36:45 (2 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/include/common_functions.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/include/common_functions.php
r675 r693 549 549 /** 550 550 * function makeDelimeterString 551 * 551 * 552 552 * Creates a string with the same length as $string, with a delimeter where 553 553 * the corresponding part of the string is on or within that delimeter, and … … 565 565 */ 566 566 function makeDelimeterString($string, $delimeters, $escapeCharacter = "\\"){ 567 567 568 568 if(!$escapeCharacter) 569 569 $escapeCharacter = NULL; 570 570 571 571 if(strlen($escapeCharacter) > 1) 572 572 return false; 573 573 574 574 $returnString = ""; 575 575 $stringArray = str_split($string); … … 577 577 $prevChar = ""; 578 578 foreach($stringArray as $char){ 579 579 580 580 if(!$inside){ 581 581 if(in_array($char, $delimeters) && $prevChar != $escapeCharacter){ … … 586 586 $returnString .= "0"; 587 587 }else{ 588 588 589 589 if($char == $delimeter && $prevChar != $escapeCharacter){ 590 590 $inside = false; … … 592 592 }else 593 593 $returnString .= $delimeter; 594 594 595 595 }//end if 596 596 597 597 $prevChar = $char; 598 598 599 599 }//end foreach 600 600 601 601 return $returnString; 602 602 603 603 }//end function 604 604 605 605 606 /* … … 607 608 * Returns the part of $querystatement from the general FROM to its ORDER BY or 608 609 * the end of the querystatement if no ORDER BY exists. 609 * 610 * 610 611 * @param $querystatement 611 612 * @return string The part of $querystatement from the general FROM to its 612 613 * ORDER BY. 613 614 */ 614 615 615 function getSearchFrom($querystatement) { 616 616 617 617 $modstatement = $querystatement; 618 618 $insideString = makeDelimeterString($querystatement, array("'", "\"", "`")); 619 619 $insideArray = str_split($insideString); 620 621 620 621 622 622 /** 623 623 * Check for SELECTs that are not inside quotes or tics. … … 628 628 $offset = 0; 629 629 do{ 630 630 631 631 $pos = stripos($querystatement, "select", $offset); 632 632 633 633 if($pos !== false) 634 634 if(!$insideArray[$pos]) 635 635 $selectArray[] = $pos; 636 636 $offset = $pos+1; 637 637 638 638 }while($pos !== false); 639 639 640 640 /** 641 641 * Check for FROMSs that are not inside quotes or tics. … … 646 646 $offset = 0; 647 647 do{ 648 648 649 649 $pos = stripos($querystatement, "from", $offset); 650 650 651 651 if($pos !== false) 652 652 if(!$insideArray[$pos]) 653 653 $fromArray[] = $pos; 654 654 $offset = $pos+1; 655 655 656 656 }while($pos !== false); 657 657 658 658 /** 659 659 * Check for ORDER BYs that are not inside quotes or tics. … … 664 664 $offset = 0; 665 665 do{ 666 666 667 667 $pos = stripos($querystatement, "order by", $offset); 668 668 669 669 if($pos !== false) 670 670 if(!$insideArray[$pos]) 671 671 $orderArray[] = $pos; 672 672 $offset = $pos+1; 673 673 674 674 }while($pos !== false); 675 676 675 676 677 677 /** 678 * Pair the SELECTs with their appropriate FROMs 678 * Pair the SELECTs with their appropriate FROMs 679 679 */ 680 680 $godArray = array(); … … 682 682 $j = 0; 683 683 foreach($fromArray as $fromPos){ 684 684 685 685 $closest = 0; 686 686 $index = 0; … … 690 690 $index = $i; 691 691 }//end if 692 692 693 693 unset($tempSelectArray[$index]); 694 694 $godArray[$j]["select"] = $closest; 695 695 $godArray[$j]["from"] = $fromPos; 696 696 $j++; 697 697 698 698 }//end foreach 699 700 699 700 701 701 /** 702 702 * Pair the ORDER BYs with their approriate FROMs (and thus their … … 706 706 $j = 0; 707 707 foreach($orderArray as $orderPos){ 708 708 709 709 $closest = 0; 710 710 $index = 0; … … 714 714 $index = $i; 715 715 }//end if 716 716 717 717 unset($tempFromArray[$index]); 718 718 for($k=0; $k < count($godArray); $k++) 719 719 if($godArray[$k]["from"] == $closest) 720 720 $godArray[$k]["order"] = $orderPos; 721 721 722 722 $j++; 723 723 724 724 }//end foreach 725 726 725 726 727 727 /** 728 728 * The last entry in the $godArray should be the outermost / first … … 732 732 if(!isset($godArray[$l]["order"])) 733 733 $godArray[$l]["order"] = strlen($querystatement); 734 734 735 735 if(!($godArray[$l]["order"])) 736 736 $godArray[$l]["order"] = strlen($querystatement); 737 737 738 738 return substr($querystatement, $godArray[$l]["from"], $godArray[$l]["order"] - $godArray[$l]["from"]); 739 739 740 740 }//end function 741 741 … … 1125 1125 1126 1126 /* 1127 * function cleanFilename 1127 * function cleanFilename 1128 1128 * @param $string 1129 1129 * @return string $string with only alpha-numeric characters, periods (.), … … 1132 1132 1133 1133 function cleanFilename($string) { 1134 1134 1135 1135 $pattern = "/[^\w\d\.\-\_]/"; 1136 1136 $string = preg_replace($pattern, "", $string); 1137 1137 1138 1138 return $string; 1139 1139 1140 1140 }//end function --cleanFilename-- 1141 1141 … … 1246 1246 1247 1247 1248 /** 1249 * function debug 1250 * 1251 * essentially provides a formatted var_dump with extra info for development purposes 1252 */ 1253 function debug($variable, $exit = false){ 1254 1255 echo "<pre>"; 1256 var_dump($variable); 1257 echo "</pre>"; 1258 1259 $backtrace = debug_backtrace(); 1260 1261 if(count($backtrace) > 1) 1262 array_shift($backtrace); 1263 1264 foreach($backtrace as $trace){ 1265 1266 echo "* "; 1267 1268 if(isset($trace["class"])) 1269 echo $trace["class"]."-> "; 1270 1271 if(isset($trace["function"])) 1272 echo $trace["function"]." "; 1273 1274 echo "in ".$trace["file"]." "; 1275 echo "on line ".$trace["line"]."<br />"; 1276 1277 }//endforeach 1278 1279 if($exit) 1280 exit(); 1281 1282 }//endif 1283 1248 1284 //for windows servers, we have no define time constants and nl_langinfo function 1249 1285 //in a limited fashion; some windows servers still show that the function