$v ) { if ( array_key_exists($k, $array_entry_props) && array_key_exists('replace_chars_re', $array_entry_props[$k]) && array_key_exists('default_value', $array_entry_props[$k]) ) { $array_ini[$k] = sanitize($array_ini, $k, $array_entry_props[$k]['replace_chars_re'], $array_entry_props[$k]['default_value'] ); } else { unset($array_ini[$k]); } } // Set default value for all missing ini entries (if default value exists) foreach ( $array_entry_props as $k => $v ) { if ( !array_key_exists($k, $array_ini) && array_key_exists('default_value', $array_entry_props[$k]) ) { $array_ini[$k] = $array_entry_props[$k]['default_value']; } } } return $array_ini; } function load_ini_site_conf($ini_path) { $sanitize_site_conf = array( 'site_admin_lang' => array( 'replace_chars_re' => RE_LANG_IDENT_CLEANER, 'default_value' => 'C' ), 'site_default_page' => array( 'replace_chars_re' => RE_RELPATH_CLEANER, 'default_value' => 'en/index' ), ); return sanitize_ini($ini_path, $sanitize_site_conf); } function load_ini_page_props($page) { $sanitize_page_props = array( //FIXME : title regex : all but html special chars ? 'page_template' => array( 'replace_chars_re' => RE_IDENTIFIER_CLEANER, 'default_value' => 'default' ), 'page_layout' => array( 'replace_chars_re' => RE_IDENTIFIER_CLEANER, 'default_value' => 'article' ), 'page_title' => array( 'replace_chars_re' => RE_TEXT_LINE_CLEANER, 'default_value' => '(missing)' ), 'page_description' => array( 'replace_chars_re' => RE_TEXT_LINE_CLEANER, 'default_value' => '(missing)' ), 'page_keywords' => array( 'replace_chars_re' => RE_TEXT_LINE_CLEANER, 'default_value' => '(missing)' ), ); $ini_path="content/$page/props.ini"; return sanitize_ini($ini_path, $sanitize_page_props); } function l10n_init($lang) { setlocale(LC_MESSAGES, "$lang.utf8"); $base = bindtextdomain('editablesite', './locale'); $domain = textdomain('editablesite'); bind_textdomain_codeset('editablesite', 'UTF-8'); //echo "
l10n file is '$base/$lang.utf8/LC_MESSAGES/$domain.mo'\n"; } function need_auth() { session_start(); if ( ! array_key_exists('auth_user', $_SESSION) || $_SESSION['auth_user'] !== TRUE ) { $_SESSION['auth_return'] = $_SERVER['REQUEST_URI']; header('Location: auth.php'); exit(); } } function is_ress($kind, $path) { switch ($kind) { case 'page': return is_file($path.'/props.ini'); case 'media': return substr($path, -4)=='.jpg' && is_file($path); default : return FALSE; } } function strcmp_tree($a,$b) { if (is_array($a) || is_array($b) ) return 0; return strnatcasecmp($a,$b); } function find_all($path, $kind) { $result=array(); if ( $handle = opendir($path) ) { while (FALSE !== ($entry = readdir($handle))) { if ( array_search($entry, array('.','..')) !== FALSE ) continue; $childpath=$path.'/'.$entry; if ( is_ress($kind, $childpath) ) $result[] = $entry; else if ( is_dir($childpath) ) $result[$entry]=find_all($childpath,$kind); } closedir($handle); } uasort($result, 'strcmp_tree'); return $result; } function php_array_to_tree($page_tree, $node_cb, $leaf_cb='', $path='', $itemid="item-0") { if ( ! is_array($page_tree) ) return; echo "