function getMeta($group, $subgroup = null, $leaf = null, $withleafvalue = false) { $c =& pfcGlobalConfig::Instance(); // read data from metadata file $ret = array(); $ret["timestamp"] = array(); $ret["value"] = array(); $dir_base = $c->container_cfg_server_dir; $dir = $dir_base . '/' . $group; if ($subgroup == NULL) { if (is_dir($dir)) { $dh = opendir($dir); while (false !== ($file = readdir($dh))) { if ($file == "." || $file == "..") { continue; } // skip . and .. generic files $ret["timestamp"][] = filemtime($dir . '/' . $file); $ret["value"][] = $file; } closedir($dh); } return $ret; } $dir .= '/' . $subgroup; if ($leaf == NULL) { if (is_dir($dir)) { $dh = opendir($dir); while (false !== ($file = readdir($dh))) { if ($file == "." || $file == "..") { continue; } // skip . and .. generic files $ret["timestamp"][] = filemtime($dir . '/' . $file); $ret["value"][] = $file; } closedir($dh); } return $ret; } $leaffilename = $dir . "/" . $leaf; if (!file_exists($leaffilename)) { return $ret; } if ($withleafvalue) { $ret["value"][] = file_get_contents_flock($leaffilename); } else { $ret["value"][] = NULL; } $ret["timestamp"][] = filemtime($leaffilename); return $ret; }
/** * Parse the source-code and update the i18n ressources files */ function UpdateMessageRessources() { // first of all, update the GetAcceptedLanguage list $i18n_basepath = dirname(__FILE__) . '/../i18n'; $i18n_accepted_lang = array(); $dh = opendir($i18n_basepath); while (false !== ($file = readdir($dh))) { // skip . and .. generic files, skip also .svn directory if ($file == "." || $file == ".." || strpos($file, ".") === 0) { continue; } if (file_exists($i18n_basepath . '/' . $file . '/main.php')) { $i18n_accepted_lang[] = $file; } } closedir($dh); $i18n_accepted_lang_str = "array('" . implode("','", $i18n_accepted_lang) . "');"; $data = file_get_contents_flock(__FILE__); $data = preg_replace("/(\\/\\*<GetAcceptedLanguage>\\*\\/)(.*)(\\/\\*<\\/GetAcceptedLanguage>\\*\\/)/", "\$1" . $i18n_accepted_lang_str . "\$3", $data); file_put_contents(__FILE__, $data, LOCK_EX); // Now scan the source code in order to find "_pfc" patterns $files = array(); $files = array_merge($files, glob(dirname(__FILE__) . "/*.php")); $files = array_merge($files, glob(dirname(__FILE__) . "/commands/*.php")); $files = array_merge($files, glob(dirname(__FILE__) . "/containers/*.php")); $files = array_merge($files, glob(dirname(__FILE__) . "/proxies/*.php")); $files = array_merge($files, glob(dirname(__FILE__) . "/client/*.php")); $files = array_merge($files, glob(dirname(__FILE__) . "/../themes/default/*.php")); $res = array(); foreach ($files as $src_filename) { $lines = file($src_filename); $line_nb = 1; foreach ($lines as $l) { // the labels server side if (preg_match_all('/_pfc\\("([^\\"]+)"/', $l, $matches)) { foreach ($matches[1] as $label) { echo "line: " . $line_nb . "\t- " . $label . "\n"; $res[$label] = "// line " . $line_nb . " in " . basename($src_filename); } } // the labels client side (JS) if (preg_match_all('/"([^"]*)",\\s\\/\\/\\s_pfc/', $l, $matches)) { echo "line: " . $line_nb . "\t- " . $matches[1][0] . "\n"; $res[$matches[1][0]] = "// line " . $line_nb . " in " . basename($src_filename); } $line_nb++; } } $dst_filenames = array(); foreach ($i18n_accepted_lang as $lg) { $dst_filenames[] = dirname(__FILE__) . "/../i18n/" . $lg . "/main.php"; } foreach ($dst_filenames as $dst_filename) { // filter lines to keep, line to add $old_content = file_get_contents_flock($dst_filename); // remove php tags to keep only real content $old_content = preg_replace("/^\\<\\?php/", "", $old_content); $old_content = preg_replace("/\\?\\>\$/", "", $old_content); // save into the file $new_content = ""; foreach ($res as $str => $com) { //echo "com=".$com."\n"; //echo "str=".$str."\n"; if (preg_match("/" . preg_quote($str, '/') . "/", $old_content) == 0) { $new_content .= $com . "\n\$GLOBALS[\"i18n\"][\"" . $str . "\"] = \"\";\n\n"; } } $content = "<?php" . $old_content . $new_content . "?>"; //echo $content; file_put_contents($dst_filename, $content, LOCK_EX); } }