/** Will parse all subfoders of the plugin folder to find config.php config files They are merged with the main config file */ function parsePhpPluginFolder($folder = '/plugin/') { $complete_config = array(); require_once 'php_parser.class.php'; $parser = new php_parser(); $folder = ROOT . $folder; // test if folder is found if (file_exists($folder)) { $ressource = opendir($folder); // find files in this folder while (($file = readdir($ressource)) !== false) { $plugin_folder = $folder . '/' . $file; if (is_dir($plugin_folder)) { $plugin_config_file = $plugin_folder . '/config.php'; if (file_exists($plugin_config_file)) { $config = $parser->load($plugin_config_file); if ($config) { array_merge_2($complete_config, $config); } } if (!isset($config)) { //trigger_error("we have a parsing error with $file"); } } } } return $complete_config; }
function parsePhpFolder($folder) { //die($folder); $complete_config = array(); require_once 'php_parser.class.php'; $parser = new php_parser(); // test if folder is found if (file_exists($folder)) { $ressource = opendir($folder); // find files in this folder while (($file = readdir($ressource)) !== false) { // debug($file, 'xml_parser::parse_folder files'); if (is_file($folder . '/' . $file)) { $path_parts = pathinfo($file); // if it's an yaml file, parse it and store thge results in an array if ($path_parts['extension'] == 'php') { $we_have_config_files = true; $config = $parser->load($folder . '/' . $file); if (!$config) { trigger_error("we have a parsing error with {$file}"); } if (is_array($config)) { /* echo '<pre>Complete config'; echo '<hr>'; print_r ($complete_config); */ //$complete_config = array_merge($complete_config, $config); array_merge_2($complete_config, $config); /* echo '<pre>Complete config after'; echo '<hr>'; print_r ($complete_config); */ } } } } if (isset($we_have_config_files)) { //echo '<pre>'; //print_r($complete_config); return $complete_config; } else { trigger_error("thinkedit::parsePhpFolder() no config files found - aborting"); die; return false; } } else { trigger_error("thinkedit::parsePhpFolder() : {$folder} is not found - aborting"); die; return false; } }
<?php require_once '../thinkedit.init.php'; require_once ROOT . '/class/php_parser.class.php'; $parser = new php_parser(); echo '<pre>'; //echo $parser->save('config.php', $thinkedit->config); //echo $parser->toPhpHumanFriendly($thinkedit->config); $parser->save('config.php', $thinkedit->config); die; echo '<hr>'; $test = $parser->load('config.php'); print_r($test); die; $config = $thinkedit->config; function toPhp($data, $path = false) { if (is_array($data)) { foreach ($data as $key => $value) { if (is_array($value)) { $path[] = $key; //echo $key . ' : <br/>'; toPhp($value, $path); } else { echo '$config'; foreach ($path as $item) { echo "['" . $item . "']"; } echo ' = ' . $value . '<br>'; } }