====An action to edit a php array taken from a php file such as in wikka.config.php==== To use the function you need to call it like { {editphparray folder/file.php} } The script assumes that the array is one "variable,value" per line with possibly one comment before them. The characteristics of the script are: - get the first array in the file and preserves rest of the file even after saving - creates editable form with all the array "variable,value" pairs - preserves the contents of the rest of the file whether they are comments or instructions - it will give a blank entry at the end, for adding extra "comment,variable,value" trio (comment is optional) - can erase a variable, value pair by simply emptying the variable input box and saving - can erase a comment by simply emptying the comment input box and saving - the input box of the value grows according to the data it holds - checks whether user has admin rights - can see a file in a folder simply by specifying folder/file path Disadvantages: - not conventional way to pass the file parameter to the script has been followed - possibly other conventions are not followed Well here is the script save it in action/editphparray.php %%(php) IsAdmin($this->GetUser())) { //usage //{{editphparray wikka.config.php}} foreach ($vars as $param => $value) { list($file_to_process)=explode(";",$value); } /* function magic_quotes_strip($mixed) { if(is_array($mixed)) return array_map('magic_quotes_strip', $mixed); return stripslashes($mixed); } */ // Is magic quotes on? //if(get_magic_quotes_gpc() ) { // $_POST = magic_quotes_strip($_POST); //} //for testing //echo "
".print_r($_POST).""; //will rewrite only version of file grabbed function write_file($filename,$newdata,$mtime) { //echo $mtime ." == ".filemtime($filename); clearstatcache(); if ($mtime == filemtime($filename)) // check if it was modified ever since it was grabbed by client { $f=fopen($filename,"w"); fwrite($f,$newdata); fclose($f); return 1; } else { return 0; } } function read_file_and_info($filename) { clearstatcache(); $data["mtime"]=filemtime($filename); $f=fopen($filename,"r"); $data["contents"]=fread($f,filesize($filename)); fclose($f); return $data; } if (isset($_POST['submit']) && isset($_POST['filename']) ) { $variables = $_POST["variable"]; $values = $_POST["value"]; $end = ","; $array_count = sizeof($variables); if (empty($variables[$array_count - 2])) //did the user fill in the last comment and variable $array_count -= 2 ; for($i=0; $i< $array_count; $i++) { if ( $i == $array_count -1 ) //last array value $end = ""; if (empty($variables[$i])) continue; else if ( $values[$i] == "//" ) $array_lines .= "//".$variables[$i] ."\n" ; else $array_lines .= "\t\"".$variables[$i] ."\" => \"". $values[$i] ."\"".$end."\n" ; } $file_contents = $_POST["file_start"]."\n".$array_lines.$_POST["file_end"]; //for testing purposes // echo "
"; } else { $variable = trim($variable); $variable = trim($variable,"\""); $value = trim($value); $value = trim($value,"\",);"); echo " | = | "; $len = strlen($value); if ($len<50) echo ""; else echo " | "; } echo " | |||
= |