diff options
author | lpouzenc <lpouzenc@gmail.com> | 2013-11-28 13:11:58 +0100 |
---|---|---|
committer | lpouzenc <lpouzenc@gmail.com> | 2013-11-28 13:11:58 +0100 |
commit | a77d63fd3ce1e93a554b62e6f63646f1fb568ecb (patch) | |
tree | baf11cfbae3efa6c2773667565f01e08902ce90d /internal/utils.php | |
download | plaintextcms-a77d63fd3ce1e93a554b62e6f63646f1fb568ecb.tar.gz plaintextcms-a77d63fd3ce1e93a554b62e6f63646f1fb568ecb.tar.bz2 plaintextcms-a77d63fd3ce1e93a554b62e6f63646f1fb568ecb.zip |
Diffstat (limited to 'internal/utils.php')
-rw-r--r-- | internal/utils.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/utils.php b/internal/utils.php new file mode 100644 index 0000000..c9f8320 --- /dev/null +++ b/internal/utils.php @@ -0,0 +1,39 @@ +<?php + function sanitize($arg_array, $arg_key, $replace_chars_re, $default_value) { + if ( ! array_key_exists($arg_key, $arg_array) ) return $default_value; + return preg_replace($replace_chars_re, '_', $arg_array[$arg_key]); + } + + function sanitize_ini($ini_path, $array_entry_props) { + $arr = parse_ini_file("$ini_path"); + if ( is_array($arr) ) { + foreach ( $arr as $k => $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]) + ) { + $arr[$k] = sanitize($arr, $k, + $array_entry_props[$k]['replace_chars_re'], + $array_entry_props[$k]['default_value'] ); + } else { + unset($arr[$k]); + } + } + } + return $arr; + } + + define('SANITIZE_SITE_CONF', array( + 'default_page' => array( 'replace_chars_re' => '/[^a-z0-9\/]+/', 'default_value' => 'en/index' ), + ) + ); + + define('SANITIZE_PAGE_PROPS', array( + 'title' => array( 'replace_chars_re' => '/[^.]+/', 'default_value' => '(missing title in props.ini)' ), + 'template' => array( 'replace_chars_re' => '/[^a-z0-9]+/', 'default_value' => 'default' ), + 'layout' => array( 'replace_chars_re' => '/[^a-z0-9]+/', 'default_value' => 'article' ), + ) + ); + +?> + |