From b1aaa3b6ca8894ac0422fb3aeadded29c2b83972 Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Thu, 11 Dec 2008 23:48:39 +0000 Subject: add new files --- functions/init/configs.php | 60 ++++++++++++++++++++ functions/init/cpaths.php | 24 ++++++++ functions/init/date_range.php | 39 +++++++++++++ functions/init/sanitize.php | 101 +++++++++++++++++++++++++++++++++ functions/init/set_error_reporting.php | 9 +++ 5 files changed, 233 insertions(+) create mode 100644 functions/init/configs.php create mode 100644 functions/init/cpaths.php create mode 100644 functions/init/date_range.php create mode 100644 functions/init/sanitize.php create mode 100644 functions/init/set_error_reporting.php (limited to 'functions/init') diff --git a/functions/init/configs.php b/functions/init/configs.php new file mode 100644 index 0000000..9cea67b --- /dev/null +++ b/functions/init/configs.php @@ -0,0 +1,60 @@ +$value) $phpiCal_config->setProperty($key, $value); +} +// Set the cookie URI. +if ($phpiCal_config->cookie_uri == '') { + $phpiCal_config->setProperty('cookie_uri', $_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['PHP_SELF'], '/') ).'phpicalendar' ); +} + +if (isset($_COOKIE[$phpiCal_config->cookie_uri]) && !isset($_POST['unset'])) { + $phpicalendar = unserialize(stripslashes($_COOKIE[$cookie_name])); + if (isset($phpicalendar['cookie_language'])) $phpiCal_config->setProperty('language', $phpicalendar['cookie_language']); + if (isset($phpicalendar['cookie_calendar'])) $phpiCal_config->setProperty('default_cal_check', $phpicalendar['cookie_calendar']); + if (isset($phpicalendar['cookie_cpath'])) $phpiCal_config->setProperty('default_cpath_check', $phpicalendar['cookie_cpath']); + if (isset($phpicalendar['cookie_view'])) $phpiCal_config->setProperty('default_view', $phpicalendar['cookie_view']); + if (isset($phpicalendar['cookie_style']) && is_dir(BASE.'templates/'.$phpicalendar['cookie_style'].'/')){ + $phpiCal_config->setProperty('template', $phpicalendar['cookie_style']); + } + if (isset($phpicalendar['cookie_startday'])) $phpiCal_config->setProperty('week_start_day', $phpicalendar['cookie_startday']); + if (isset($phpicalendar['cookie_time'])) $phpiCal_config->setProperty('day_start', $phpicalendar['cookie_time']); +} + +# language support +# default to english and overwrite other strings as available +unset($lang); +include_once(BASE.'languages/english.inc.php'); +$language = strtolower($phpiCal_config->language); +$lang_file = BASE.'languages/'.$language.'.inc.php'; +if (is_file($lang_file)) { + include_once($lang_file); +} + +$template = $phpiCal_config->template; + +$fillTime = $phpiCal_config->day_start; +$day_array = array (); +while ($fillTime < $phpiCal_config->day_end) { + array_push ($day_array, $fillTime); + preg_match ('/([0-9]{2})([0-9]{2})/', $fillTime, $dTime); + $fill_h = $dTime[1]; + $fill_min = $dTime[2]; + $fill_min = sprintf('%02d', $fill_min + $phpiCal_config->gridLength); + if ($fill_min == 60) { + $fill_h = sprintf('%02d', ($fill_h + 1)); + $fill_min = '00'; + } + $fillTime = $fill_h . $fill_min; +} + + +/* +echo "
xx";
+print_r($configs);
+print_r($phpiCal_config);
+echo "
"; +#die; +*/ \ No newline at end of file diff --git a/functions/init/cpaths.php b/functions/init/cpaths.php new file mode 100644 index 0000000..fafc0ec --- /dev/null +++ b/functions/init/cpaths.php @@ -0,0 +1,24 @@ +calendar_path == '') { + $calendar_path = BASE.'calendars'; +}else $calendar_path = $phpiCal_config->calendar_path; +$cpath = ''; #initialize cpath to prevent later undef warnings. +if(isset($_REQUEST['cpath'])&& $_REQUEST['cpath'] !=''){ + $cpath = str_replace('..','',$_REQUEST['cpath']); + $calendar_path .= "/$cpath"; +# $tmp_dir .= "/$cpath"; +}elseif(isset($phpiCal_config->default_cpath_check) && $phpiCal_config->default_cpath_check !='' ){ + $cpath = str_replace('..','',$default_cpath_check); + $calendar_path .= "/$cpath"; +# $tmp_dir .= "/$cpath"; +} +#these need cpath to be set +#set up specific template folder for a particular cpath +if (isset($user_template["$cpath"])){ + $template = $user_template["$cpath"]; +} +#set up specific webcals for a particular cpath +if (isset($phpiCal_config->more_webcals) && is_array($phpiCal_config->more_webcals[$cpath])){ + $list_webcals = array_merge($phpiCal_config->list_webcals, $phpiCal_config->more_webcals["$cpath"]); +} diff --git a/functions/init/date_range.php b/functions/init/date_range.php new file mode 100644 index 0000000..565d0d1 --- /dev/null +++ b/functions/init/date_range.php @@ -0,0 +1,39 @@ + + * @param mixed $value Value to be sanitized + * @return mixed + */ +function recursiveSanitize($value) { + if (is_array($value)) { + $valmod = array(); + foreach ($value as $key => $subval) { + if (is_array($subval)) { + $subval = recursiveSanitize($subval); + } else { + $subval = strip_tags($subval); + } + $valmod[$key] = $subval; + } + $value = $valmod; + } else { + $value = strip_tags($value); + } + + return $value; +} + +if (!isset($_SERVER) && isset($HTTP_SERVER_VARS)) { + $_SERVER = &$HTTP_SERVER_VARS; +} + +foreach ($_REQUEST as $key=>$val){ + switch ($key){ + case 'event_data': + # modify this to allow or disallow different HTML tags in event popups + $allowed = "



    1. "; + $val = strip_tags($val,$allowed); + break; + default: + # cpath + $val = recursiveSanitize($val); + } + + $_REQUEST[$key] = $val; +} +foreach ($_POST as $key=>$val){ + switch ($key){ + case 'action': + $actions = array('login','logout','addupdate','delete'); + if (!in_array($val,$actions)) $val = ''; + break; + case 'date': + case 'time': + if (!is_numeric($val)) $val = ''; + break; + default: + $val = recursiveSanitize($val); + } + $_POST[$key] = $val; + +} +foreach ($_GET as $key=>$val){ + switch ($key){ + case 'cal': + if (!is_array($val)){ + $val = strip_tags($val); + $_GET['cal'] = strip_tags($val); + }else{ + unset ($_GET['cal']); + foreach($val as $cal){ + $_GET['cal'][]= strip_tags($cal); + } + } + break; + case 'getdate': + if (!is_numeric($val)) $val = ''; + break; + default: + $val = recursiveSanitize($val); + } + if ($key != 'cal') $_GET[$key] = $val; + +} +foreach ($_COOKIE as $key=>$val){ + switch ($key){ + case 'time': + if (!is_numeric($val)) $val = ''; + break; + default: + $val = recursiveSanitize($val); + } + $_COOKIE[$key] = $val; +} +?> \ No newline at end of file diff --git a/functions/init/set_error_reporting.php b/functions/init/set_error_reporting.php new file mode 100644 index 0000000..91e491d --- /dev/null +++ b/functions/init/set_error_reporting.php @@ -0,0 +1,9 @@ +