home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / calendar-2010-08-23.tar.gz / calendar-2010-08-23.tar / calendar / functions / init.inc.php < prev    next >
PHP Script  |  2003-10-12  |  5KB  |  151 lines

  1. <?php 
  2. // jared-2002.10.30, I want to make sure my published calendars are world-read/writeable
  3. // so I have this making sure they all are. This should be commented out/deleted
  4. // for shipping versions. This is a convenience so when I commit, changes are made and
  5. // I don't get errors.
  6. //chmod(BASE.'calendars/School.ics',0666);
  7.  
  8. // uncomment when developing, comment for shipping version
  9. //error_reporting (E_ALL);
  10.  
  11. $ALL_CALENDARS_COMBINED = 'all_calendars_combined971';
  12. if (!defined('BASE')) define('BASE', './');
  13. include(BASE.'config.inc.php');
  14. include(BASE.'functions/error.php');
  15. if (isset($HTTP_COOKIE_VARS['phpicalendar'])) {
  16.     $phpicalendar = unserialize(stripslashes($HTTP_COOKIE_VARS['phpicalendar']));
  17.     if (isset($phpicalendar['cookie_language']))     $language             = $phpicalendar['cookie_language'];
  18.     if (isset($phpicalendar['cookie_calendar']))     $default_cal_check    = $phpicalendar['cookie_calendar'];
  19.     if (isset($phpicalendar['cookie_view']))         $default_view         = $phpicalendar['cookie_view'];
  20.     if (isset($phpicalendar['cookie_style']))         $style_sheet         = $phpicalendar['cookie_style'];
  21.     if (isset($phpicalendar['cookie_startday']))     $week_start_day        = $phpicalendar['cookie_startday'];
  22.     if (isset($phpicalendar['cookie_time']))        $day_start            = $phpicalendar['cookie_time'];
  23. }
  24.  
  25. // language support
  26. $language = strtolower($language);
  27. $lang_file = BASE.'/languages/'.$language.'.inc.php';
  28.  
  29. if (file_exists($lang_file)) {
  30.     include($lang_file);
  31. } else {
  32.     exit(error('The requested language "'.$language.'" is not a supported language. Please use the configuration file to choose a supported language.'));
  33. }
  34.  
  35. if (!isset($getdate)) {
  36.     if (isset($HTTP_GET_VARS['getdate']) && ($HTTP_GET_VARS['getdate'] !== '')) {
  37.         $getdate = $HTTP_GET_VARS['getdate'];
  38.     } else {
  39.         $getdate = date('Ymd', strtotime("now + $second_offset seconds"));
  40.     }
  41. }
  42.  
  43. if (ini_get('max_execution_time') < 60) {
  44.     ini_set('max_execution_time', '60');
  45. }
  46.  
  47. if ($calendar_path == '') {
  48.     $calendar_path = 'calendars';
  49.     $calendar_path_orig = $calendar_path;
  50.     $calendar_path = BASE.$calendar_path;
  51. }
  52.  
  53. $is_webcal = FALSE;
  54. if (isset($HTTP_GET_VARS['cal']) && $HTTP_GET_VARS['cal'] != '') {
  55.     $cal_filename = urldecode($HTTP_GET_VARS['cal']);
  56. } else {
  57.     if (isset($default_cal_check)) {
  58.         if ($default_cal_check != $ALL_CALENDARS_COMBINED) {
  59.             $calcheck = $calendar_path.'/'.$default_cal_check.'.ics';
  60.             $calcheckopen = @fopen($calcheck, "r");
  61.             if ($calcheckopen == FALSE) {
  62.                 $cal_filename = $default_cal;
  63.             } else {
  64.                 $cal_filename = $default_cal_check;
  65.             }
  66.         } else {
  67.             $cal_filename = $ALL_CALENDARS_COMBINED;
  68.         }
  69.     } else {
  70.         $cal_filename = $default_cal;
  71.     }
  72. }
  73.  
  74. if (substr($cal_filename, 0, 7) == 'http://' || substr($cal_filename, 0, 9) == 'webcal://') {
  75.     $is_webcal = TRUE;
  76.     $cal_webcalPrefix = str_replace('http://','webcal://',$cal_filename);
  77.     $cal_httpPrefix = str_replace('webcal://','http://',$cal_filename);
  78.     $cal_filename = $cal_httpPrefix;
  79. }
  80.  
  81. if ($is_webcal) {
  82.     if ($allow_webcals == 'yes' || in_array($cal_webcalPrefix, $list_webcals) || in_array($cal_httpPrefix, $list_webcals)) {
  83.         $cal_displayname = substr(str_replace('32', ' ', basename($cal_filename)), 0, -4);
  84.         $cal = urlencode($cal_filename);
  85.         $filename = $cal_filename;
  86.         $subscribe_path = $cal_webcalPrefix;
  87.         // empty the filelist array
  88.         $cal_filelist = array();
  89.         array_push($cal_filelist,$filename);
  90.     } else {
  91.         exit(error($error_remotecal_lang, $HTTP_GET_VARS['cal']));
  92.     }
  93. } else {
  94.     $cal_displayname = str_replace('32', ' ', $cal_filename);
  95.     $cal = urlencode($cal_filename);
  96.     if (in_array($cal_filename, $blacklisted_cals)) {
  97.         exit(error($error_restrictedcal_lang, $cal_filename));
  98.     } else {
  99.         if (!isset($filename)) {
  100.             // empty the filelist array
  101.             $cal_filelist = array();
  102.             if ($cal == $ALL_CALENDARS_COMBINED) { // Create an array with the paths to all files to be combined
  103.                 // Note: code here is similar to code in list_icals.php
  104.                 // open directory
  105.                 $dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename));
  106.     
  107.                 // build the array
  108.                 while (false != ($file = readdir($dir_handle))) {
  109.                     if (preg_match("/^[^.].+\.ics$/", $file) &&
  110.                         !in_array(substr($file, 0, -4), $blacklisted_cals)) {
  111.                             $file = $calendar_path.'/'.$file;
  112.                             array_push($cal_filelist, $file);
  113.                     }
  114.                 }
  115.                 // add webcals
  116.                 foreach ($list_webcals as $file) {
  117.                     if (preg_match("/^[^.].+\.ics$/", $file)) {
  118.                         array_push($cal_filelist, $file);
  119.                     }
  120.                 }
  121.                 natcasesort($cal_filelist);
  122.             } else { // Handle a single file
  123.                 $filename = $calendar_path.'/'.$cal_filename.'.ics';
  124.                 if (true == false) {
  125.                     $dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename));
  126.                     while ($file = readdir($dir_handle)) {
  127.                         if (substr($file, -4) == '.ics') {
  128.                             $cal = urlencode(substr($file, 0, -4));
  129.                             $filename = $calendar_path.'/'.$file;
  130.                             break;
  131.                         }
  132.                     }
  133.                 }
  134.                 array_push($cal_filelist, $filename);
  135.             }
  136.         }
  137.         
  138.         // Sets the download and subscribe paths from the config if present.
  139.         if ($download_uri == '') {
  140.             $subscribe_path = 'webcal://'.$HTTP_SERVER_VARS['SERVER_NAME'].dirname($HTTP_SERVER_VARS['PHP_SELF']).'/'.$filename;
  141.             $download_filename = $filename;
  142.         } else {
  143.             $newurl = eregi_replace("^(http://)", "", $download_uri); 
  144.             $subscribe_path = 'webcal://'.$newurl.'/'.$cal_filename.'.ics';
  145.             $download_filename = $download_uri.'/'.$cal_filename.'.ics';
  146.         }
  147.         
  148.     }
  149. }
  150. ?>
  151.