├── README.md └── conv_fnames.php /README.md: -------------------------------------------------------------------------------- 1 | # codecharge_php7fix 2 | script to transform code charge studio output to php 7.4 3 | ---------------------------------------------------------------------- 4 | I've developed a script to transform CCS php files to work with PHP7.4. includes changing function and constructor names, 5 | each iterations etc. I don't take any responsibility, but I am using this regularly. 6 | 7 | Usage from command line: 8 | 9 | php conv_fnames.php 10 | 11 | Notice: 12 | 13 | Run this after each publish. 14 | It is set to ignore directory CCS if its located inside your publish directory so not to touch the original. 15 | And set to ignore node_modules - if you are using node for any reason. 16 | 17 | It assumes you haven't touched the CodeCharge library files such as classes.php etc - 18 | which can always be regenerated from scratch. 19 | -------------------------------------------------------------------------------- /conv_fnames.php: -------------------------------------------------------------------------------- 1 | $match ) 56 | { 57 | $offsets[$match[1]] = $n; 58 | } 59 | ksort($offsets); 60 | reset($offsets); 61 | return current($offsets); 62 | // var_dump($offsets); 63 | 64 | // return $offsets[0]; 65 | } 66 | 67 | 68 | 69 | function fix_fnames($path) 70 | { 71 | $str_result = ""; 72 | // if(!preg_match('/export_data.php$/i', $path )) 73 | // return; 74 | 75 | $str = file_get_contents($path); 76 | $str_len = strlen($str); 77 | $offset = 0; 78 | $offset_prev = 0; 79 | $offset1 = 0; 80 | $offset2 = 0; 81 | $change_made = false; 82 | $replaced_content = ""; 83 | $count = 0; 84 | $pattern = "/(class[\s\r\n]+[a-z_0-9]+[\n\r\s]+extends[\s\r\n]+[a-z_0-9]+[\s\r\n]*{|class[\s\r\n]+[a-z_0-9]+[\s\r\n]*{)/i"; 85 | // echo "\n".$path; 86 | $kkk =false; 87 | while(preg_match( $pattern , $str , $matches , PREG_OFFSET_CAPTURE, $offset) && $offset < $str_len ) 88 | { 89 | $kkk = true; 90 | // echo "\n".$path." - ".$offset."\n";; 91 | 92 | // default replacment content is from current offset to end of input 93 | 94 | // get class name 95 | $res = select_min_match($matches); 96 | $temp = $matches[$res][0]; 97 | 98 | //echo __FILE__; 99 | //var_dump($matches[$res]); 100 | 101 | 102 | 103 | $temp = str_replace(array("\r","\n","{")," ",$temp ); 104 | $temp = str_replace(" "," ",$temp ); 105 | $tokens = explode(" ",$temp ); 106 | $class_name = $tokens[1]; 107 | 108 | $parent_class_name = ""; 109 | if( $tokens[2] == "extends" ) 110 | { 111 | $parent_class_name = $tokens[3]; 112 | 113 | } 114 | 115 | //echo $class_name."\n"; 116 | $new_offset = $matches[$res][1]; // reset offset to start of matching string 117 | $offset1 = $new_offset + 1; 118 | if(strlen($str_result) == 0 ) 119 | { 120 | $str_result = substr($str, 0,$new_offset); 121 | } 122 | 123 | 124 | //get next class position 125 | if(preg_match( $pattern , $str , $matches1 , PREG_OFFSET_CAPTURE, $offset1) ) 126 | { 127 | /// location of next match 128 | $res1 = select_min_match($matches1); 129 | $next_offset = $matches1[$res1][1]; 130 | 131 | $string_to_process = substr($str ,$new_offset , $next_offset - $new_offset ); 132 | } 133 | else 134 | { 135 | // there isn't another class definition - use rest of input string 136 | $string_to_process = substr($str ,$new_offset ); 137 | $next_offset = $str_len; 138 | } 139 | 140 | 141 | 142 | /// replace here 143 | if( preg_match('/function[ ]+'.$class_name.'[(]/i' , $string_to_process ) ) 144 | { 145 | $change_made = true; 146 | $string_to_process = preg_replace('/function[ ]+'.$class_name.'[(]/i', "function __construct(", $string_to_process ); 147 | if( $string_to_process == NULL ) 148 | { 149 | echo "
error in".$path; 150 | return; 151 | } 152 | } 153 | 154 | /// replace parent constructor 155 | if( preg_match('/parent::'.$parent_class_name.'[(]/i' , $string_to_process ) ) 156 | { 157 | $string_to_process = preg_replace('/parent::'.$parent_class_name.'[(]/i', "parent::__construct(", $string_to_process); 158 | 159 | $change_made = true; 160 | if( $string_to_process == NULL ) 161 | { 162 | echo "
error in".$path; 163 | return; 164 | } 165 | } 166 | 167 | $offset = $next_offset; 168 | 169 | // echo "
"; 170 | $str_result .= $string_to_process; 171 | } 172 | if( !$kkk ) 173 | $str_result = $str; 174 | //var_dump($str_result); 175 | 176 | $cnnt = 0; 177 | $str_result = preg_replace('/([\r\n]+[\s]*)(\$CCSEvents[\s]*);/i', '$1$2 = array();', $str_result,-1,$cnn); 178 | $cnnt += $cnn; 179 | $str_result = preg_replace('/(public[\s]+\$CCSEvents[\s]*[;])/i', 'public \$CCSEvents = array();', $str_result,-1,$cnn); 180 | $cnnt += $cnn; 181 | $str_result = preg_replace('/(public[\s]+\$CCSEvents[\s]*=[\s]*""[\s]*[;])/i', 'public \$CCSEvents = array();', $str_result,-1,$cnn); 182 | $cnnt += $cnn; 183 | 184 | $str_result= preg_replace('/([\r\n]+)(\$CCSEvents[\s]*=[\s]*""[\s]*;)/i', '$1\$CCSEvents = array();', $str_result,-1,$cnn); 185 | 186 | $cnnt += $cnn; 187 | $str_result=preg_replace('/(var[\s]+\$CCSEvents[\s]*=[\s]*""[\s]*[;])/i', 'var \$CCSEvents = array();', $str_result,-1,$cnn); 188 | $cnnt += $cnn; 189 | $str_result=preg_replace('/(\$this->CCSEvents[\s]*=[\s]*""[\s]*;)/i', '\$this->CCSEvents = array();', $str_result,-1,$cnn); 190 | $cnnt += $cnn; 191 | 192 | /// replace each expressions 193 | $each1_pattern = preg_quote('while (list($key,) = each($searching_array))','/'); 194 | if(preg_match('/Template.php$/i', $path ) && 195 | preg_match( '/'.$each1_pattern.'/i' , $str_result) ) 196 | { 197 | $str_result=preg_replace('/'.$each1_pattern.'/i', 'foreach( $searching_array as $key=>$dontcare)', $str_result,1,$cnn); 198 | $cnnt += $cnn; 199 | } 200 | 201 | $each2_pattern = preg_quote('while(list($key, $value) = each($this->blocks[$block_name]))','/'); 202 | if(preg_match('/Template.php$/i', $path ) && 203 | preg_match( '/'.$each2_pattern.'/i' , $str_result) ) 204 | { 205 | $str_result=preg_replace('/'.$each2_pattern.'/i', 'foreach( $this->blocks[$block_name] as $key=>$value)', $str_result,1,$cnn); 206 | $cnnt += $cnn; 207 | } 208 | 209 | $each3_pattern = preg_quote('while(list($key, $value) = each($this->globals))','/'); 210 | if(preg_match('/Template.php$/i', $path ) && 211 | preg_match( '/'.$each3_pattern.'/i' , $str_result) ) 212 | { 213 | $str_result=preg_replace('/'.$each3_pattern.'/i', 'foreach( $this->globals as $key=>$value)', $str_result,1,$cnn); 214 | $cnnt += $cnn; 215 | } 216 | 217 | //// replace each in Classes.php 218 | $each4_pattern = preg_quote('while ($blnResult && list ($key, $Parameter) = each ($this->Parameters)) 219 | {','/'); 220 | if(preg_match('/Classes.php$/i', $path ) && 221 | preg_match( '/'.$each4_pattern.'/i' , $str_result) ) 222 | { 223 | $str_result=preg_replace('/'.$each4_pattern.'/i', 'foreach( $this->Parameters as $key=>$Parameter) { 224 | if(!$blnResult) 225 | continue;', $str_result,1,$cnn); 226 | $cnnt += $cnn; 227 | } 228 | 229 | 230 | //// fix casting to int in DB_Adapter::PageCount() 231 | $each5_pattern = preg_quote('return $this->PageSize && $this->RecordsCount != "CCS not counted" ? ceil($this->RecordsCount','/'); 232 | 233 | if(preg_match('/db_adapter.php$/i', $path ) && 234 | preg_match( '/'.$each5_pattern.'/i' , $str_result) ) 235 | { 236 | $str_result=preg_replace('/'.$each5_pattern.'/i', 'return $this->PageSize && $this->RecordsCount != "CCS not counted" ? ceil((int)$this->RecordsCount', $str_result,1,$cnn); 237 | $cnnt += $cnn; 238 | } 239 | 240 | 241 | if(preg_match('/(common.php|commonserv.php)$/i', $path ) ) 242 | { 243 | $str222 = 'function CCGetListValues(&$db, $sql, $where = "", $order_by = "", $bound_column = "", $text_column = "", $dbformat = "", $datatype = "", $errorclass = "", $fieldname = "", $DSType = dsSQL) 244 | { 245 | $errors = new clsErrors(); 246 | $values = '; 247 | //"";'; 248 | $str222_pattern = preg_quote( $str222 , '/' ); 249 | if( preg_match('/'.$str222_pattern.'("")'.'/i',$str_result )) 250 | { 251 | $str_result = preg_replace( '/'.$str222_pattern.'("")'.'/i' , $str222 . "array()", $str_result,1,$cnn ); 252 | $cnnt += $cnn; 253 | } 254 | 255 | } 256 | 257 | /// replace depracated get_magic_quotes_gpc() function with false constant 258 | $str_result = str_replace("get_magic_quotes_gpc()","false",$str_result, $cnn); 259 | $cnnt += $cnn; 260 | 261 | if( $cnnt> 0 ) 262 | $change_made = true; 263 | 264 | if( strlen($str_result ) > 0 && $change_made) 265 | { 266 | file_put_contents($path , $str_result); 267 | } 268 | 269 | } 270 | 271 | 272 | 273 | if( $argc == 2 ) 274 | { 275 | $file_name = $argv[1]; 276 | if( is_dir($argv[1] ) ) 277 | { 278 | // $d = str_replace("\\","/", dirname(realpath( $argv[1]))); 279 | // echo $d; 280 | rec_scandir(str_replace("\\","/", $argv[1])); 281 | } 282 | // rec_scandir(str_replace("\\","/", dirname(realpath( $argv[1])))); 283 | } 284 | 285 | 286 | 287 | 288 | ?> 289 | --------------------------------------------------------------------------------