PageRenderTime 76ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/phpical/functions/init.inc.php

https://gitlab.com/endomorphosis/fusenews
PHP | 196 lines | 121 code | 25 blank | 50 comment | 44 complexity | 06e14a801bfc16d94579a001e9fe20ac MD5 | raw file
  1. <?php
  2. # require php 5
  3. $php_started = getmicrotime();
  4. # define BASE
  5. if (!defined('BASE')) define('BASE', './');
  6. if (phpversion() < '5.1'){
  7. die (phpversion()." detected. php 5.1 or higher required for this version.\n\n" );
  8. }
  9. include_once(BASE.'functions/init/sanitize.php');
  10. include_once(BASE.'functions/init/set_error_reporting.php');
  11. include_once(BASE.'functions/init/configs.php');
  12. include_once(BASE.'functions/init/cpaths.php');
  13. include_once(BASE.'functions/init/date_range.php');
  14. include_once(BASE.'error.php');
  15. include_once(BASE.'functions/calendar_functions.php');
  16. include_once(BASE.'functions/userauth_functions.php');
  17. // Grab the action (login or logout).
  18. $action = '';
  19. if (isset($_GET['action'])) $action = $_GET['action'];
  20. else if (isset($_POST['action'])) $action = $_POST['action'];
  21. // Login and/or logout.
  22. list($username, $password, $invalid_login) = user_login();
  23. if ($action != 'login') $invalid_login = false;
  24. if ($action == 'logout' || $invalid_login) {
  25. list($username, $password) = user_logout();
  26. }
  27. if (ini_get('max_execution_time') < 60) {
  28. @ini_set('max_execution_time', '60');
  29. }
  30. // Pull the calendars off the GET line if provided. The $cal_filename
  31. // is always an array, because this makes it easier to deal with below.
  32. $cal_filenames = array();
  33. if (isset($_GET['cal']) && $_GET['cal'] !='') {
  34. // If the cal value is not an array, split it into an array on
  35. // commas.
  36. if (!is_array($_GET['cal']))
  37. $_GET['cal'] = explode(',', $_GET['cal']);
  38. // Grab the calendar filenames off the cal value array.
  39. $cal_filenames = $_GET['cal'];
  40. } elseif ($phpiCal_config->default_cal != '') {
  41. $cal_filenames = explode(',',$phpiCal_config->default_cal);
  42. } else {
  43. $cal_filenames[0] = $phpiCal_config->ALL_CALENDARS_COMBINED;
  44. }
  45. //load cal_filenames if $ALL_CALENDARS_COMBINED
  46. if ($cal_filenames[0] == $phpiCal_config->ALL_CALENDARS_COMBINED){
  47. $cal_filenames = availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED);
  48. }
  49. // Separate the calendar identifiers into web calendars and local
  50. // calendars.
  51. $web_cals = array();
  52. $local_cals = array();
  53. foreach ($cal_filenames as $cal_filename) {
  54. # substitute for md5-obscured list_webcals
  55. foreach ($list_webcals as $tmp_cal){
  56. if($cal_filename == md5($phpiCal_config->salt.$tmp_cal)) $cal_filename = $tmp_cal;
  57. }
  58. // If the calendar identifier begins with a web protocol, this is a web
  59. // calendar.
  60. $cal_filename = urldecode($cal_filename); #need to decode for substr statements to identify webcals
  61. $cal_filename = str_replace(' ','%20', $cal_filename); #need to reencode blank spaces for matching with $list_webcals
  62. if (substr($cal_filename, 0, 7) == 'http://' ||
  63. substr($cal_filename, 0, 8) == 'https://' ||
  64. substr($cal_filename, 0, 9) == 'webcal://')
  65. {
  66. #jump sends cal url without .ics extension. Add it if needed.
  67. # if (substr($cal_filename, -4) != ".ics") $cal_filename .= ".ics";
  68. $web_cals[] = $cal_filename;
  69. }
  70. // Otherwise it is a local calendar.
  71. else {
  72. // Check blacklisted.
  73. if (in_array($cal_filename, $blacklisted_cals) && $cal_filename !='') {
  74. exit(error($lang['l_error_restrictedcal'], $cal_filename));
  75. }
  76. $local_cals[] = urldecode(str_replace(".ics", '', basename($cal_filename)));
  77. }
  78. }
  79. // We will build the calendar display name as we go. The final display
  80. // name will get constructed at the end.
  81. $cal_displaynames = array();
  82. // This is our list of final calendars.
  83. $cal_filelist = array();
  84. // This is our list of URL encoded calendars.
  85. $cals = array();
  86. // Process the web calendars.
  87. foreach ($web_cals as $web_cal) {
  88. // Make some protocol alternatives, and set our real identifier to the
  89. // HTTP protocol.
  90. $cal_webcalPrefix = str_replace('http://','webcal://',$web_cal);
  91. $cal_httpPrefix = str_replace('webcal://','http://',$web_cal);
  92. $cal_httpsPrefix = str_replace('webcal://','https://',$web_cal);
  93. $cal_httpsPrefix = str_replace('http://','https://',$web_cal);
  94. // We can only include this web calendar if we allow all web calendars
  95. // (as defined by $allow_webcals) or if the web calendar shows up in the
  96. // list of web calendars defined in config.inc.php.
  97. if ($phpiCal_config->allow_webcals != 'yes' &&
  98. !in_array($cal_webcalPrefix, $list_webcals) &&
  99. !in_array($cal_httpPrefix, $list_webcals) &&
  100. !in_array($cal_httpsPrefix, $list_webcals))
  101. {
  102. exit(error($lang['l_error_remotecal'], $web_cal));
  103. }
  104. // Pull the display name off the URL.
  105. # $cal_displaynames[] = substr(str_replace('32', ' ', basename($web_cal)), 0, -4);
  106. $cal_displaynames[] = substr(basename($web_cal), 0, -4);
  107. if(in_array($web_cal, $list_webcals)){
  108. $web_cal = md5($phpiCal_config->salt.$web_cal);
  109. }
  110. $cals[] = urlencode($web_cal);
  111. //$filename = $cal_filename;
  112. $subscribe_path = $cal_webcalPrefix;
  113. // Add the webcal to the available calendars.
  114. $web_cal = $cal_httpPrefix;
  115. $cal_filelist[] = $web_cal;
  116. }
  117. // Process the local calendars.
  118. if (count($local_cals) > 0) {
  119. $local_cals = availableCalendars($username, $password, $local_cals);
  120. foreach ($local_cals as $local_cal) {
  121. $cal_displaynames[] = str_replace('32', ' ', getCalendarName($local_cal));
  122. }
  123. $cal_filelist = array_merge($cal_filelist, $local_cals);
  124. $cals = array_merge($cals, array_map("urlencode", array_map("getCalendarName", $local_cals)));
  125. // Set the download and subscribe paths from the config, if there is
  126. // only one calendar being displayed and those paths are defined.
  127. if (count($local_cals) == 1) {
  128. $filename = $local_cals[0];
  129. $add_cpath = '';
  130. if (isset($cpath) && $cpath !='') $add_cpath = "$cpath/";
  131. if (($phpiCal_config->download_uri == '') && (preg_match('/(^\/|\.\.\/)/', $filename) == 0)) {
  132. $subscribe_path = 'webcal://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'.$filename;
  133. $download_filename = $filename;
  134. } elseif ($phpiCal_config->download_uri != '') {
  135. $newurl = eregi_replace("^(http://)", "", $phpiCal_config->download_uri);
  136. $subscribe_path = 'webcal://'.$newurl.'/'.$add_cpath.basename($filename);
  137. $download_filename = $phpiCal_config->download_uri.'/'.$add_cpath.basename($filename);
  138. } else {
  139. $subscribe_path = $add_cpath;
  140. $download_filename = $add_cpath;
  141. }
  142. }
  143. }
  144. // We should only allow a download filename and subscribe path if there is
  145. // only one calendar being displayed.
  146. if (count($cal_filelist) > 1) {
  147. $subscribe_path = '';
  148. $download_filename = '';
  149. }
  150. // Build the final cal list. This is a comma separated list of the
  151. // url-encoded calendar names and web calendar URLs.
  152. $cal = implode(',', $cals);
  153. // Build the final display name used for template substitution.
  154. asort($cal_displaynames);
  155. $cal_displayname = implode(', ', $cal_displaynames);
  156. $rss_powered = ($phpiCal_config->enable_rss == 'yes') ? 'yes' : '';
  157. function getmicrotime() {
  158. list($usec, $sec) = explode(' ',microtime());
  159. return ((float)$usec + (float)$sec);
  160. }
  161. $uid_list = array();
  162. #uncomment for diagnostics
  163. #echo "after init.inc.ics<pre>";
  164. #echo "cals";print_r($cals);echo"\n\n";
  165. #echo "cal_filenames";print_r($cal_filenames);echo"\n\n";
  166. #echo "web_cals";print_r($web_cals);echo"\n\n";
  167. #echo "local_cals";print_r($local_cals);echo"\n\n";
  168. #echo "cal_filelist";print_r($cal_filelist);
  169. #echo "cal_displaynames";print_r($cal_displaynames);
  170. #echo "</pre><hr>";
  171. ?>