[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* Database import function for E107 website system 3 Use: See separate documentation. 4 5 11.06.06 - zeronull handling added 6 */ 7 8 function createQuery($convertArray, $dataArray, $table, $maptable = null) 9 { 10 global $tp; 11 12 $columns = "("; 13 $values = "("; 14 15 16 foreach($convertArray as $convert) 17 { // Possible types: STRING, INT 18 if (array_key_exists("value", $convert)) 19 { 20 $newvalue = $convert['value']; 21 } 22 elseif (array_key_exists($convert['srcdata'],$dataArray)) 23 { // Real value read from database here - need to check it 24 if($convert['type'] == "STRING") 25 { 26 $newvalue = $tp -> toDB($dataArray[$convert['srcdata']]); 27 // $newvalue = $dataArray[$convert['srcdata']]; // USE IN PLACE OF PREVIOUS LINE FOR STANDALONE TEST 28 if (array_key_exists('sproc',$convert)) 29 { 30 if (strpos($convert['sproc'],"usebb") !== FALSE) $newvalue = proc_bb($newvalue,$convert['sproc'], $maptable); 31 if (strpos($convert['sproc'],"stripbb") !== FALSE) $newvalue = preg_replace("#\[.*\]#", "",$newvalue); 32 } 33 } 34 else 35 if ($convert['type'] == "INT") 36 { 37 $newvalue = intval($dataArray[$convert['srcdata']]); // intval added 25.05.06 38 if (($newvalue == 0) && ((array_key_exists('sproc',$convert)) && (strpos($convert['sproc'],"zeronull") !== FALSE))) $newvalue = ''; 39 } 40 else 41 echo "Invalid field type: ".$convert['type']; 42 } 43 else 44 { // blank (undefined) value 45 if (array_key_exists('default', $convert)) 46 { 47 $newvalue = $convert['default']; 48 } 49 else 50 { 51 if (($convert['type'] == "INT") && ((array_key_exists('sproc',$convert)) && (strpos($convert['sproc'],"zeronull") === FALSE))) 52 $newvalue = "0"; // Should help mySQL5 53 else 54 $newvalue = ''; 55 } 56 } 57 58 $columns .= $convert['e107'].","; 59 $values .= "'".$newvalue."',"; 60 } 61 62 // Knock off last comma of each line 63 $columns = substr($columns, 0, -1).")"; 64 $values = substr($values, 0, -1).")"; 65 66 return "INSERT INTO $table $columns VALUES $values"; 67 68 } 69 70 // Process all bbcodes in the passed value; return the processed string. 71 // Works recursively 72 // Start by assembling matched pairs. Then map and otherwise process as required. 73 // Divide the value into five bits: 74 // Preamble - up to the identified bbcode (won't contain bbcode) 75 // BBCode start code 76 // Inner - text between the two bbcodes (may contain another bbcode) 77 // BBCode end code 78 // Trailer - remaining unprocessed text (may contain more bbcodes) 79 // (Note: preg_split might seem obvious, but doesn't pick out the actual codes 80 // Tested with various strings (see testdata.txt; also mapping table to see what is going on. 81 82 function proc_bb($value, $options = "", $maptable = null) 83 { 84 $nextchar = 0; 85 $loopcount = 0; 86 // echo "<br />starting match<br />"; 87 88 while ($nextchar < strlen($value)) : 89 $firstbit = ''; 90 $middlebit = ''; 91 $lastbit = ''; 92 $loopcount++; 93 if ($loopcount > 10) return 'Max depth exceeded'; 94 unset($bbword); 95 $firstcode = strpos($value,'[',$nextchar); 96 if ($firstcode === FALSE) return $value; // Done if no square brackets 97 $firstend = strpos($value,']',$firstcode); 98 if ($firstend === FALSE) return $value; // Done if no closing bracket 99 $bbword = substr($value,$firstcode+1,$firstend - $firstcode - 1); // May need to process this more if parameter follows 100 $bbparam = ''; 101 $temp = strpos($bbword,'='); 102 if ($temp !== FALSE) 103 { 104 $bbparam = substr($bbword,$temp); 105 $bbword = substr($bbword,0,-strlen($bbparam)); 106 } 107 // echo $bbword."<<||>>".$bbparam; 108 if (($bbword) && ($bbword == trim($bbword))) 109 { 110 $laststart = strpos($value,'[/'.$bbword,$firstend); // Find matching end 111 $lastend = strpos($value,']',$laststart); 112 if (($laststart === FALSE) || ($lastend === FALSE)) 113 { // No matching end character 114 $nextchar = $firstend; // Just move scan pointer along 115 // echo " - no match<br />"; 116 } 117 else 118 { // Got a valid bbcode pair here 119 $firstbit = ''; 120 if ($firstcode > 0) $firstbit = substr($value,0,$firstcode); 121 $middlebit = substr($value,$firstend+1,$laststart - $firstend-1); 122 $lastbit = substr($value,$lastend+1,strlen($value) - $lastend); 123 // echo " - match||".$firstbit."||".$middlebit."||".$lastbit."<br />"; 124 // Process bbcodes here 125 if (strpos($options,'bblower') !== FALSE) $bbword = strtolower($bbword); 126 if ((strpos($options,'phpbb') !== FALSE) && (strpos($bbword,':') !== FALSE)) $bbword = substr($bbword,0,strpos($bbword,':')); 127 if ($maptable) 128 { // Do mapping 129 if (array_key_exists($bbword,$maptable)) $bbword = $maptable[$bbword]; 130 } 131 $bbbegin = '['.$bbword.$bbparam.']'; 132 $bbend = '[/'.$bbword.']'; 133 return $firstbit.$bbbegin.proc_bb($middlebit,$options,$maptable).$bbend.proc_bb($lastbit,$options,$maptable); 134 } 135 } 136 else 137 { 138 $nextchar = $firstend+1; 139 } 140 // echo " -->".$firstcode.", ".$firstend.", ".$laststart.", ".$lastend."<br />"; 141 // echo "<br />"; 142 endwhile; 143 144 } 145 146 147 148 149 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |