PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Websites/remote/wp-content/plugins/amr-ical-events-list/amr-ical-config.php

https://bitbucket.org/perchten/open-platform
PHP | 859 lines | 710 code | 72 blank | 77 comment | 57 complexity | 77b79e435c63afa49decf4e29e19789f MD5 | raw file
  1. <?php
  2. /* This is the amr-ical config section file */
  3. global $amr_options;
  4. global $amr_general;
  5. global $amr_components;
  6. global $amr_calprop;
  7. global $amr_colheading;
  8. global $amr_compprop;
  9. global $amr_groupings;
  10. global $amr_limits;
  11. global $amr_formats;
  12. global $amr_csize;
  13. global $amr_validrepeatablecomponents;
  14. global $amr_validrepeatableproperties;
  15. global $amr_wkst;
  16. global $amrdf;
  17. global $amrtf;
  18. global $amr_globaltz;
  19. global $utczobj;
  20. $utczobj = timezone_open('UTC');
  21. if (isset($_REQUEST["debug"]) ) { /* for debug and support - calendar data is public anyway, so no danger*/
  22. define('ICAL_EVENTS_DEBUG', true);
  23. /* define('WP_DEBUG', true); /* when testing only */
  24. // echo '<h1>Debug Mode</h1>';
  25. }
  26. else define('ICAL_EVENTS_DEBUG', false);
  27. $amr_wkst = ical_get_weekstart();
  28. /* set to empty string for concise code */
  29. if (!defined('AMR_NL')) define('AMR_NL',"\n" );
  30. if (!defined('AMR_TB')) define('AMR_TB',"\t" );
  31. define('AMR_EVENTS_CACHE_TTL', 60 * 20); // 20 mins
  32. define('ICAL_EVENTS_CACHE_TTL', 24 * 60 * 60); // 1 day
  33. define('AMR_MAX_REPEATS', 1000); /* if someone wants to repeat something very frequently from some time way in the past, then may need to increase this */
  34. define('TIMEZONEIMAGE','timezone.png');
  35. define('MAPIMAGE','map.png');
  36. define('CALENDARIMAGE','calendar.png');
  37. define('CALENDARADDTOIMAGE','calendar_add.png');
  38. define('ADDTOGOOGLEIMAGE','addtogoogle.png');
  39. define('REFRESHIMAGE','refresh.png');
  40. if ( ! defined( 'WP_PLUGIN_URL' ) )
  41. define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins/' );
  42. if ( ! defined( 'WP_PLUGIN_DIR' ) )
  43. define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins/' );
  44. if ( !defined('WP_SITEURL') )
  45. define( 'WP_SITEURL', get_option('siteurl') );
  46. $x = str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
  47. if (stripos($x,'amr-events') === false) {
  48. $url = WP_PLUGIN_URL.'/amr-ical-events-list/';
  49. $dir = WP_PLUGIN_DIR.'/amr-ical-events-list/';
  50. }
  51. else {
  52. $url = WP_PLUGIN_URL.'/amr-events/listfiles/';
  53. $dir = WP_PLUGIN_DIR.'/amr-events/listfiles/';
  54. }
  55. define('ICALLISTPLUGINURL', $url);
  56. define('ICALLISTPLUGINDIR', $dir);
  57. define('ICALSTYLEURL', $url.'css/icallist.css');
  58. define('ICALSTYLEFILE', $dir.'css/icallist.css');
  59. define('ICAL_EDITSTYLEFILE', $dir.'css/a-yours.css');
  60. define('ICALSTYLEPRINTURL', $url.'css/icalprint.css');
  61. define('AMRICAL_ABSPATH', $url);
  62. define('IMAGES_LOCATION', AMRICAL_ABSPATH.'images/');
  63. $uploads = wp_upload_dir();
  64. //define('ICAL_EVENTS_CACHE_LOCATION',path_join( ABSPATH, get_option('upload_path'))); /* do what wordpress does otherwise weird behaviour here - some folks already seem to have the abs path there. */
  65. define('ICAL_EVENTS_CACHE_LOCATION',$uploads['basedir']);
  66. define('ICAL_EVENTS_CSS_DIR',ICAL_EVENTS_CACHE_LOCATION.'/css/'); /* where to store custom css so does not get overwritten */
  67. define('ICAL_EVENTS_CSS_URL',$uploads['baseurl'].'/css/'); /* where to store custom css so does not get overwritten */
  68. define('ICAL_EVENTS_CACHE_DEFAULT_EXTENSION','ics');
  69. $amr_validrepeatablecomponents = array ('VEVENT', 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VTIMEZONE');
  70. $amr_validrepeatableproperties = array (
  71. 'ATTACH', 'ATTENDEE',
  72. 'CATEGORIES','COMMENT','CONTACT','CLASS' ,
  73. 'DESCRIPTION', 'DAYLIGHT',
  74. 'EXDATE','EXRULE',
  75. 'FREEBUSY',
  76. 'RDATE', 'RSTATUS','RELATED','RESOURCES','RRULE','RECURID',
  77. 'SEQ', 'SUMMARY', 'STATUS', 'STANDARD',
  78. 'TZOFFSETTO','TZOFFSETFROM',
  79. 'URL',
  80. 'XPARAM', 'X-PROP');
  81. /* used for admin field sizes */
  82. $amr_csize = array('Column' => '2', 'Order' => '2', 'Before' => '10', 'After' => '10', 'ColHeading' => '10');
  83. /* the default setup shows what the default display option is */
  84. $amr_formats = array (
  85. 'Time' => str_replace(' ', '',get_option('time_format')),
  86. 'Day' => 'D, '.get_option('date_format'),
  87. // 'Time' => '%I:%M %p',
  88. // 'Day' => '%a, %d %b %Y',
  89. // 'Month' => '%b, %Y', /* %B is the full month name */
  90. 'Month' => 'F,Y',
  91. 'Year' => 'Y',
  92. 'Week' => '\W\e\e\k W',
  93. // 'Timezone' => 'T', /* Not accurate enough, leave at default */
  94. 'DateTime' => get_option('date_format').' '.get_option('time_format')
  95. // 'DateTime' => '%d-%b-%Y %I:%M %p' /* use if displaying date and time together eg the original fields, */
  96. );
  97. function amr_getTimeZone($offset) {
  98. $timezones = array(
  99. '-12'=>'Pacific/Kwajalein',
  100. '-11'=>'Pacific/Samoa',
  101. '-10'=>'Pacific/Honolulu',
  102. '-9.5'=>'Pacific/Marquesas',
  103. '-9'=>'America/Juneau',
  104. '-8'=>'America/Los_Angeles',
  105. '-7'=>'America/Denver',
  106. '-6'=>'America/Mexico_City',
  107. '-5'=>'America/New_York',
  108. '-4.5'=>'America/Caracas',
  109. '-4'=>'America/Manaus',
  110. '-3.5'=>'America/St_Johns',
  111. '-3'=>'America/Argentina/Buenos_Aires',
  112. '-2'=>'Brazil/DeNoronha',
  113. '-1'=>'Atlantic/Azores',
  114. '0'=>'Europe/London',
  115. '1'=>'Europe/Paris',
  116. '2'=>'Europe/Helsinki',
  117. '3'=>'Europe/Moscow',
  118. '3.5'=>'Asia/Tehran',
  119. '4'=>'Asia/Baku',
  120. '4.5'=>'Asia/Kabul',
  121. '5'=>'Asia/Karachi',
  122. '5.5'=>'Asia/Calcutta',
  123. '5.75'=>'Asia/Katmandu',
  124. '6'=>'Asia/Colombo',
  125. '6.5'=>'Asia/Rangoon',
  126. '7'=>'Asia/Bangkok',
  127. '8'=>'Asia/Singapore',
  128. '9'=>'Asia/Tokyo',
  129. '9.5'=>'Australia/Darwin',
  130. '10'=>'Pacific/Guam',
  131. '11'=>'Australia/Sydney',
  132. '11.5'=>'Pacific/Norfolk',
  133. '12'=>'Asia/Kamchatka',
  134. '13'=>'Pacific/Enderbury',
  135. '14'=>'Pacific/Kiritimati'
  136. );
  137. $intoffset = intval($offset); /* to cope with +01.00 */
  138. $stroffset = strval($intoffset);
  139. if (isset($timezones[$stroffset])) return ($timezones[$stroffset]);
  140. else return false;
  141. }
  142. /* ---------------------------------------------------------------------------*/
  143. function amr_set_defaults() {
  144. global $amr_calprop;
  145. global $amr_colheading;
  146. global $amr_compprop;
  147. global $amr_groupings;
  148. global $amr_components;
  149. global $amr_limits;
  150. global $amr_formats;
  151. global $amr_general;
  152. global $amr_globaltz;
  153. global $ical_timezone;
  154. global $eventtaxonomies;
  155. If (ICAL_EVENTS_DEBUG) {
  156. echo '<br />Plugin Version is: '.AMR_ICAL_LIST_VERSION;
  157. echo '<br />Php Version is: '.PHP_VERSION;
  158. }
  159. if (function_exists ('get_option')) {
  160. // if ($d = get_option ('date_format')) $amr_formats['Day'] = $d;
  161. // if ($d = get_option ('time_format')) $amr_formats['Time'] = $d;
  162. if (($a_tz = get_option ('timezone_string') ) and (!empty($a_tz))) {
  163. $amr_globaltz = timezone_open($a_tz);
  164. date_default_timezone_set($a_tz);
  165. If (ICAL_EVENTS_DEBUG or isset($_REQUEST['tzdebug'])) { echo '<br />Found tz string:'.$a_tz;}
  166. }
  167. else {
  168. If (ICAL_EVENTS_DEBUG or isset($_REQUEST['tzdebug'])) { echo '<h2>No timezone string found.</h2>'; }
  169. if (($gmt_offset = get_option ('gmt_offset')) and (!(is_null($gmt_offset))) and (is_numeric($gmt_offset))) {
  170. $a_tz = amr_getTimeZone($gmt_offset);
  171. $amr_globaltz = timezone_open($a_tz);
  172. date_default_timezone_set($a_tz);
  173. If (ICAL_EVENTS_DEBUG or isset($_REQUEST['tzdebug'])) { echo '<h2>Found gmt offset in wordpress options:'.$gmt_offset.'</h2>';}
  174. }
  175. else {
  176. $amr_globaltz = timezone_open(date_default_timezone_get());
  177. }
  178. }
  179. }
  180. else $amr_globaltz = timezone_open(date_default_timezone_get());
  181. $ical_timezone = $amr_globaltz;
  182. If (ICAL_EVENTS_DEBUG or isset($_REQUEST['tzdebug'])) echo '<br />The default php timezone is set to:'.date_default_timezone_get().'<br />';
  183. $amr_general = array (
  184. 'name' => 'Default',
  185. 'Description' => 'A default calendar list. This one set to tables with lists in the cells. Usually needs the css file enabled. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ',
  186. "Default Event URL" => '',
  187. 'ListHTMLStyle' => 'table'
  188. );
  189. $amr_limits = array (
  190. "events" => 30,
  191. "days" => 90,
  192. "cache" => 24, /* hours */
  193. "eventscache" => 0.5);
  194. $amr_components = array (
  195. "VEVENT" => true,
  196. "VTODO" => true,
  197. "VJOURNAL" => false,
  198. "VFREEBUSY" => true
  199. // "VTIMEZONE" => false /* special handling required if we want to process this - for now we are going to use the php definitions rather */
  200. );
  201. $fakeforautolangtranslation = array (
  202. __("Year",'amr_ical_list_lang'),
  203. __("Quarter",'amr_ical_list_lang'),
  204. __("Astronomical Season",'amr_ical_list_lang') ,
  205. __("Traditional Season",'amr_ical_list_lang'),
  206. __("Western Zodiac",'amr_ical_list_lang'),
  207. __("Month",'amr_ical_list_lang'),
  208. __("Week",'amr_ical_list_lang') ,
  209. __("Day",'amr_ical_list_lang')
  210. );
  211. $amr_groupings = array (
  212. "Year" => false,
  213. "Quarter" => false,
  214. "Astronomical Season" => false,
  215. "Traditional Season" => false,
  216. "Western Zodiac" => false,
  217. "Month" => true,
  218. "Week" => false,
  219. "Day"=> false
  220. );
  221. $amr_colheading = array (
  222. '1' => __('When','amr_ical_list_lang'),
  223. '2' => __('What', 'amr_ical_list_lang'),
  224. '3' => __('Where', 'amr_ical_list_lang')
  225. );
  226. $dfalse = array('Column' => 0, 'Order' => 1, 'Before' => '', 'After' => '');
  227. $dtrue = array('Column' => 1, 'Order' => 1, 'Before' => '', 'After' => '');
  228. $dtrue2 = array('Column' => 2, 'Order' => 1, 'Before' => '', 'After' => '');
  229. // check if we have any taxonomies that we may wish to assign an event to
  230. $taxonomies=get_taxonomies();
  231. $excluded = array ('category','nav_menu','link_category') ;
  232. foreach ($taxonomies as $i=>$tax) {
  233. if (in_array($tax, $excluded)) unset ($taxonomies[$i]);
  234. }
  235. $eventtaxonomies = $taxonomies;
  236. foreach ($taxonomies as $i=>$tax) {
  237. $eventtaxonomiesprop[$tax] = $dfalse;
  238. }
  239. //var_dump($taxonomies);
  240. $amr_calprop = array (
  241. 'X-WR-CALNAME' => array('Column' => 1, 'Order' => 1, 'Before' => '', 'After' => ''),
  242. 'X-WR-CALDESC' => $dfalse,
  243. 'X-WR-TIMEZONE' => array('Column' => 2, 'Order' => 2, 'Before' => '', 'After' => ''),
  244. 'icsurl' => array('Column' => 2, 'Order' => 2, 'Before' => '', 'After' => ''),
  245. 'addtogoogle' => array('Column' => 2, 'Order' => 5, 'Before' => '', 'After' => ''),
  246. 'icalrefresh' => array('Column' => 2, 'Order' => 9, 'Before' => '', 'After' => ''),
  247. /* for linking to the ics file, not intended as a display field really unless you want a separate link to it, intended to sit behind name, with desc as title */
  248. 'LAST-MODIFIED' => $dtrue
  249. // 'CALSCALE'=> $dfalse,
  250. // 'METHOD'=> $dfalse,
  251. // 'PRODID'=> $dfalse,
  252. // 'VERSION'=> $dfalse,
  253. // 'X-WR-RELCALID'=> $dfalse
  254. );
  255. /* NB need to switch some field s on for initial plugin view. This will be common default for all, then some are customised separately */
  256. $amr_compprop = array
  257. (
  258. 'Descriptive' =>
  259. array_merge (
  260. array (
  261. 'SUMMARY'=> array('Column' => 2, 'Order' => 10, 'Before' => '<b>', 'After' => '</b>'),
  262. 'DESCRIPTION'=> array('Column' => 2, 'Order' => 20, 'Before' => '<br />', 'After' => ''),
  263. 'EXCERPT'=> array('Column' => 0, 'Order' => 30, 'Before' => '<br />', 'After' => ''),
  264. 'POSTTHUMBNAIL'=> array('Column' => 0, 'Order' => 35, 'Before' => '<br />', 'After' => ''),
  265. 'LOCATION'=> array('Column' => 2, 'Order' => 41, 'Before' => '', 'After' => ''),
  266. 'map'=> array('Column' => 2, 'Order' => 40, 'Before' => '', 'After' => ''),
  267. 'addevent' => array('Column' => 2, 'Order' => 145, 'Before' => '', 'After' => ''),
  268. 'subscribeevent' => array('Column' => 2, 'Order' => 148, 'Before' => '', 'After' => ''),
  269. 'GEO'=> $dfalse,
  270. 'ATTACH'=> $dfalse,
  271. 'CATEGORIES'=> $dfalse,
  272. 'CLASS'=> $dfalse,
  273. 'COMMENT'=> $dfalse,
  274. 'PERCENT-COMPLETE'=> $dfalse,
  275. 'PRIORITY'=> $dfalse,
  276. 'RESOURCES'=> $dfalse,
  277. 'STATUS'=> $dfalse
  278. ),
  279. $eventtaxonomiesprop),
  280. 'Date and Time' => array (
  281. 'EventDate' => array ('Column' => 1, 'Order' => 1, 'Before' => '', 'After' => ''), /* the instnace of a repeating date */
  282. 'StartTime' => array('Column' => 1, 'Order' => 2, 'Before' => '<br />', 'After' => ' '),
  283. 'EndDate' => array('Column' => 1, 'Order' => 3, 'Before' => ' until ', 'After' => ''),
  284. 'EndTime' => array('Column' => 1, 'Order' => 4, 'Before' => ' ', 'After' => ''),
  285. 'DTSTART'=> $dfalse,
  286. // 'age'=> $dfalse,
  287. 'DTEND'=> $dfalse,
  288. 'DUE'=> $dfalse,
  289. 'DURATION'=> $dfalse,
  290. 'ALLDAY' => $dfalse,
  291. 'COMPLETED'=> $dfalse,
  292. 'FREEBUSY'=> $dfalse,
  293. 'TRANSP'=> $dfalse),
  294. // 'Time Zone' => array (
  295. // 'TZID'=> $dtrue, /* but only show if different from calendar TZ */
  296. // 'TZNAME'=> $dfalse,
  297. // 'TZOFFSETFROM'=> $dfalse,
  298. // 'TZOFFSETTO'=> $dfalse,
  299. // 'TZURL'=> $dfalse),
  300. 'Relationship' => array (
  301. 'ATTENDEE'=> $dfalse,
  302. // 'attending_event' => $dfalse,
  303. 'CONTACT'=> $dtrue,
  304. 'ORGANIZER'=> array('Column' => 0, 'Order' => 30, 'Before' => '', 'After' => ''),
  305. 'RECURRENCE-ID'=> $dfalse,
  306. 'RELATED-TO'=> $dfalse,
  307. 'URL'=> array('Column' => 0, 'Order' => 10, 'Before' => '', 'After' => ''),
  308. 'UID'=> $dfalse
  309. ),
  310. 'Recurrence' => array ( /* in case one wants for someone reason to show the "repeating" data, need to create a format rule for it then*/
  311. 'EXDATE'=> $dfalse,
  312. 'EXRULE'=> $dfalse,
  313. 'RDATE'=> $dfalse,
  314. 'RRULE'=> $dfalse
  315. ),
  316. 'Alarm' => array (
  317. 'ACTION'=> $dfalse,
  318. 'REPEAT'=> $dfalse,
  319. 'TRIGGER'=> $dfalse),
  320. 'Change Management' => array ( /* optional and/or for debug purposes */
  321. 'CREATED'=> $dfalse,
  322. 'DTSTAMP'=> $dfalse,
  323. 'SEQUENCE'=> $dfalse,
  324. 'LAST-MODIFIED' => $dfalse
  325. )
  326. );
  327. }
  328. /* -------------------------------------------------------------------------------------------------------------*/
  329. function amr_ical_showmap ($text) { /* the address text */
  330. global $amr_options;
  331. $t1 = __('Show in Google map','amr_ical_list_lang');
  332. if (isset ($amr_options['no_images']) and $amr_options['no_images']) $t3 = $t1;
  333. else $t3 = '<img src="'.IMAGES_LOCATION.MAPIMAGE.'" alt="'. $t1 .'" class="amr-bling" />';
  334. /* this is used to determine what should be done if a map is desired - a link to google behind the text ? or some thing else */
  335. return('<a href="http://maps.google.com/maps?q='
  336. .str_replace(' ','%20',($text)).'" target="_BLANK"' //google wants unencoded
  337. .' title="'.__('Show location in Google Maps','amr_ical_list_lang').'" >'.$t3.'</a>');
  338. }
  339. /* -------------------------------------------------------------------------------------------------------------*/
  340. /* This is used to tailor the multiple default listing options offered. A new listtype first gets the common default */
  341. function customise_listtype($i) { /* sets up some variations of the default list type*/
  342. global $amr_options;
  343. switch ($i) {
  344. case 2:
  345. $amr_options[$i]['general']['name']='On Tour';
  346. $amr_options[$i]['general']['Description']='Default setting uses the original table with lists in the cells. It is grouped by month. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  347. $amr_options[$i]['general']['ListHTMLStyle']='table';
  348. $amr_options[$i]['compprop']['Descriptive']['LOCATION']['Column'] = 2;
  349. $amr_options[$i]['compprop']['Descriptive']['DESCRIPTION']['Column'] = 3;
  350. $amr_options[$i]['compprop']['Descriptive']['SUMMARY']['Column'] = 3;
  351. $amr_options[$i]['compprop']['Descriptive']['addevent']['Column'] = 3;
  352. $amr_options[$i]['heading']['2'] = __('Venue','amr_ical_list_lang');
  353. $amr_options[$i]['heading']['3'] = __('Description','amr_ical_list_lang');
  354. break;
  355. case 3:
  356. $amr_options[$i]['general']['name']='Timetable';
  357. $amr_options[$i]['general']['Description']='Default setting uses the original table with lists in the cells. It is grouped by day. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  358. $amr_options[$i]['general']['ListHTMLStyle']='table';
  359. foreach ($amr_options[$i]['grouping'] as $g=>$v) {$amr_options[$i]['grouping'][$g] = false;}
  360. $amr_options[$i]['grouping']['Day'] = true;
  361. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 0;
  362. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 0;
  363. $amr_options[$i]['compprop']['Descriptive']['LOCATION']['Column'] = 3;
  364. $amr_options[$i]['compprop']['Descriptive']['map']['Column'] = 0;
  365. $amr_options[$i]['compprop']['Descriptive']['addevent']['Column'] = 4;
  366. $amr_options[$i]['compprop']['Descriptive']['subscribeevent']['Column'] = 4;
  367. $amr_options[$i]['heading']['2'] = __('Date','amr_ical_list_lang');
  368. $amr_options[$i]['heading']['2'] = __('Class','amr_ical_list_lang');
  369. $amr_options[$i]['heading']['3'] = __('Room','amr_ical_list_lang');
  370. $amr_options[$i]['format']['Day']='l, jS M';
  371. break;
  372. case 4:
  373. $amr_options[$i]['general']['name']='Widget'; /* No groupings, minimal */
  374. $amr_options[$i]['general']['Description']='The new default setting for widgets uses lists for the table rows. Good for themes that cannot cope with tables in the sidebar. No grouping. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  375. $amr_options[$i]['general']['ListHTMLStyle']='list';
  376. $amr_options[$i]['format']['Day']='M j';
  377. $amr_options[$i]['limit'] = array ( "events" => 10, "days" => 90,"cache" => 24); /* hours */
  378. foreach ($amr_options[$i]['grouping'] as $g => $v) {$amr_options[$i]['grouping'][$g] = false;}
  379. /* No calendar properties for widget - keep it minimal */
  380. foreach ($amr_options[$i]['calprop'] as $g => $v)
  381. {$amr_options[$i]['calprop'][$g]['Column'] = 0;}
  382. foreach ($amr_options[$i]['compprop'] as $g => $v)
  383. foreach ($v as $g2 => $v2) {$amr_options[$i]['compprop'][$g][$g2]['Column'] = 0;}
  384. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 1;
  385. $amr_options[$i]['compprop']['Date and Time']['StartTime']['Column'] = 1;
  386. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 1;
  387. $amr_options[$i]['compprop']['Date and Time']['EndTime']['Column'] = 1;
  388. $amr_options[$i]['compprop']['Descriptive']['SUMMARY'] = array('Column' => 1, 'Order' => 10, 'Before' => '<br />', 'After' => '');
  389. $amr_options[$i]['compprop']['Descriptive']['DESCRIPTION'] = array('Column' => 0, 'Order' => 20, 'Before' => '<br />', 'After' => '');
  390. $amr_options[$i]['heading']['1'] = $amr_options[$i]['heading']['2'] = $amr_options[$i]['heading']['3'] = '';
  391. break;
  392. case 5:
  393. $amr_options[$i]['general']['name']='Alternative';
  394. $amr_options[$i]['general']['Description']='Default setting uses the new table style, with cells separated by breaks and fields by spaces. It is a wacky grouping. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  395. $amr_options[$i]['general']['ListHTMLStyle']='table';
  396. $amr_options[$i]['format']['Day']='j M';
  397. $amr_options[$i]['grouping']['Western Zodiac'] = true;
  398. $amr_options[$i]['grouping']['Month'] = false;
  399. $amr_options[$i]['heading']['1'] = __('Description','amr_ical_list_lang');
  400. $amr_options[$i]['heading']['2'] = __('Timing','amr_ical_list_lang');
  401. $amr_options[$i]['heading']['3'] = '';
  402. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 2;
  403. $amr_options[$i]['compprop']['Date and Time']['StartTime']['Column'] = 2;
  404. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 2;
  405. $amr_options[$i]['compprop']['Date and Time']['EndTime']['Column'] = 2;
  406. $amr_options[$i]['compprop']['Descriptive']['SUMMARY']['Column'] = 1;
  407. $amr_options[$i]['compprop']['Descriptive']['DESCRIPTION']['Column'] = 1;
  408. $amr_options[$i]['compprop']['Descriptive']['LOCATION']= array('Column' => 1, 'Order' => 20, 'Before' => '', 'After' => '');
  409. $amr_options[$i]['compprop']['Descriptive']['addevent']['Column'] = 0;
  410. $amr_options[$i]['compprop']['Descriptive']['map']['Column'] = 0;
  411. $amr_options[$i]['compprop']['Descriptive']['SUMMARY'] = array('Column' => 1, 'Order' => 10, 'Before' => '', 'After' => '');
  412. break;
  413. case 6:
  414. $amr_options[$i]['general']['name']='Testing';
  415. $amr_options[$i]['general']['Description']='A test option with lots of fields switched on. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  416. $amr_options[$i]['general']['ListHTMLStyle']='breaks';
  417. foreach ($amr_options[$i]['grouping'] as $g => $v) {
  418. $amr_options[$i]['grouping'][$g] = false;}
  419. foreach ($amr_options[$i]['compprop'] as $g => $v)
  420. foreach ($v as $g2 => $v2)
  421. { $amr_options[$i]['compprop'][$g][$g2]['After'] = '<br />';
  422. $amr_options[$i]['compprop'][$g][$g2]['Before'] = '';
  423. if ($v2['Column'] === 0) {
  424. $amr_options[$i]['compprop'][$g][$g2]
  425. = array('Column' => 2, 'Order' => 99, 'Before' => "<em>".$g2.': ', 'After' => "</em><br />");}
  426. }
  427. foreach ($amr_options[$i]['calprop'] as $g => $v)
  428. {$amr_options[$i]['calprop'][$g] = array('Column' => 3, 'Order' => 1, 'Before' => '', 'After' => '');}
  429. $amr_options[$i]['calprop']['X-WR-CALNAME']['Column'] = 1;
  430. $amr_options[$i]['calprop']['X-WR-CALDESC']['Column'] = 1;
  431. $amr_options[$i]['calprop']['X-WR-CALDESC']['Before'] = ' ';
  432. foreach ($amr_options[$i]['component'] as $g=>$v) {
  433. $amr_options[$i]['component'][$g] = true;}
  434. $amr_options[$i]['heading']['1'] = '';
  435. $amr_options[$i]['heading']['2'] = '';
  436. $amr_options[$i]['heading']['3'] = '';
  437. $amr_options[$i]['format']['Day'] = 'D, F j, Y';
  438. break;
  439. case 7:
  440. $amr_options[$i]['general']['name']='EventInfo'; /* No groupings, minimal */
  441. $amr_options[$i]['general']['Description']='For displaying additional event info on posts created as events. The summary and description are switched off as these are the post title and the post content. Calendar properties and groupings are also not relevant. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  442. $amr_options[$i]['limit'] = array ( "events" => 10, "days" => 366,"cache" => 24); /* hours */
  443. $amr_options[$i]['general']['ListHTMLStyle']='list';
  444. $amr_options[$i]['format']['Day']='l, j F Y';
  445. $amr_options[$i]['component']['VTODO'] = false;
  446. $amr_options[$i]['component']['VFREEBUSY'] = false;
  447. foreach ($amr_options[$i]['grouping'] as $g => $v) {$amr_options[$i]['grouping'][$g] = false;}
  448. /* No calendar properties for widget - keep it minimal */
  449. foreach ($amr_options[$i]['calprop'] as $g => $v)
  450. {$amr_options[$i]['calprop'][$g]['Column'] = 0;}
  451. foreach ($amr_options[$i]['compprop'] as $g => $v)
  452. foreach ($v as $g2 => $v2) {$amr_options[$i]['compprop'][$g][$g2]['Column'] = 0;}
  453. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 1;
  454. $amr_options[$i]['compprop']['Date and Time']['StartTime']['Column'] = 0;
  455. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Order'] = 10;
  456. $amr_options[$i]['compprop']['Date and Time']['StartTime']['Order'] = 0;
  457. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 0;
  458. $amr_options[$i]['compprop']['Date and Time']['EndTime']['Column'] = 0;
  459. $amr_options[$i]['compprop']['Descriptive']['LOCATION']['Order'] = 0;
  460. $amr_options[$i]['compprop']['Descriptive']['map']['Order'] = 0;
  461. $amr_options[$i]['compprop']['Descriptive']['SUMMARY']['Column'] = 0;
  462. $amr_options[$i]['compprop']['Descriptive']['addevent']['Column'] = 1;
  463. $amr_options[$i]['compprop']['Descriptive']['addevent']['Order'] = 1;
  464. $amr_options[$i]['heading']['1'] = $amr_options[$i]['heading']['2'] = $amr_options[$i]['heading']['3'] = '';
  465. break;
  466. case 8:
  467. $amr_options[$i]['general']['name']='Small-Calendar'; /* No groupings, minimal */
  468. $amr_options[$i]['general']['Description']='The new default setting for calendar widgets. No grouping, No headings. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is. ';
  469. $amr_options[$i]['general']['ListHTMLStyle']='smallcalendar';
  470. $amr_options[$i]['format']['Day']='j';
  471. $amr_options[$i]['format']['Week']='D'; // 3 letter day of week
  472. $amr_options[$i]['format']['Month']='M Y';
  473. $amr_options[$i]['limit'] = array ( "events" => 200, "days" => 31,"cache" => 24 ); /* hours */
  474. foreach ($amr_options[$i]['grouping'] as $g => $v) {$amr_options[$i]['grouping'][$g] = false;}
  475. /* No calendar properties for widget - keep it minimal */
  476. foreach ($amr_options[$i]['calprop'] as $g => $v)
  477. {$amr_options[$i]['calprop'][$g]['Column'] = 0;}
  478. foreach ($amr_options[$i]['compprop'] as $g => $v)
  479. foreach ($v as $g2 => $v2) {$amr_options[$i]['compprop'][$g][$g2]['Column'] = 0;}
  480. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 0;
  481. $amr_options[$i]['compprop']['Date and Time']['StartTime']['Column'] = 1;
  482. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 0;
  483. $amr_options[$i]['compprop']['Date and Time']['EndTime']['Column'] = 1;
  484. $amr_options[$i]['compprop']['Descriptive']['SUMMARY'] = array('Column' => 1, 'Order' => 10, 'Before' => '', 'After' => '');
  485. $amr_options[$i]['compprop']['Descriptive']['DESCRIPTION']['Column'] = 0;
  486. $amr_options[$i]['heading']['1'] = $amr_options[$i]['heading']['2'] = $amr_options[$i]['heading']['3'] = '';
  487. break;
  488. case 9:
  489. $amr_options[$i]['general']['name']='Large-Calendar'; /* No groupings, minimal */
  490. $amr_options[$i]['general']['Description']= __('The new default setting for a large monthly calendar. No grouping, No headings. If you configure it, I suggest changing this description to aid your memory of how/why it is configured the way that it is.','amr_ical', 'amr_ical_list_lang');
  491. $amr_options[$i]['general']['ListHTMLStyle']='largecalendar';
  492. $amr_options[$i]['format']['Day']='M j';
  493. $amr_options[$i]['format']['Time']='G:i';
  494. $amr_options[$i]['format']['Month']='F Y';
  495. $amr_options[$i]['format']['Week']='l'; // lowercase l = full text date
  496. $amr_options[$i]['limit'] = array ( "events" => 200, "days" => 31,"cache" => 24 ); /* hours */
  497. foreach ($amr_options[$i]['grouping'] as $g => $v) {$amr_options[$i]['grouping'][$g] = false;}
  498. /* No calendar properties for widget - keep it minimal */
  499. // foreach ($amr_options[$i]['calprop'] as $g => $v)
  500. // {$amr_options[$i]['calprop'][$g]['Column'] = 0;}
  501. foreach ($amr_options[$i]['compprop'] as $g => $v)
  502. foreach ($v as $g2 => $v2) {$amr_options[$i]['compprop'][$g][$g2]['Column'] = 0;}
  503. $amr_options[$i]['compprop']['Date and Time']['EventDate']['Column'] = 0;
  504. $amr_options[$i]['compprop']['Date and Time']['StartTime'] = array('Column' => 1, 'Order' => 5, 'Before' => '<br />', 'After' => '');
  505. $amr_options[$i]['compprop']['Date and Time']['EndDate']['Column'] = 0;
  506. $amr_options[$i]['compprop']['Date and Time']['EndTime'] = array('Column' => 1, 'Order' => 6, 'Before' => '-', 'After' => '');
  507. $amr_options[$i]['compprop']['Descriptive']['SUMMARY'] = array('Column' => 1, 'Order' => 1, 'Before' => '', 'After' => '');
  508. $amr_options[$i]['compprop']['Descriptive']['DESCRIPTION']
  509. = array('Column' => 2, 'Order' => 1, 'Before' => '<div class="details">', 'After' => '</div>');
  510. $amr_options[$i]['heading']['1'] = $amr_options[$i]['heading']['2'] = $amr_options[$i]['heading']['3'] = '';
  511. break;
  512. }
  513. return ( $amr_options[$i]);
  514. }
  515. /* ---------------------------------------------------------------------*/
  516. function new_listtype() {
  517. global $amr_calprop;
  518. global $amr_colheading;
  519. global $amr_compprop;
  520. global $amr_groupings;
  521. global $amr_components;
  522. global $amr_limits;
  523. global $amr_formats;
  524. global $amr_general;
  525. $amr_newlisttype = (array
  526. (
  527. 'general' => $amr_general,
  528. 'format' => $amr_formats,
  529. 'heading' => $amr_colheading,
  530. 'calprop' => $amr_calprop,
  531. 'component' => $amr_components,
  532. 'grouping' => $amr_groupings,
  533. 'compprop' => $amr_compprop,
  534. 'limit' => $amr_limits
  535. )
  536. );
  537. return $amr_newlisttype;
  538. }
  539. /* ---------------------------------------------------------------------*/
  540. function array_merge_recursive_distinct ( array &$array1, array &$array2 ) { /* array 2 will replace array 1*/
  541. $merged = $array1;
  542. foreach ( $array2 as $key => &$value ) {
  543. if ( is_array ( $value ) && isset ( $merged [$key] ) && is_array ( $merged [$key] ) ) {
  544. $merged [$key] = array_merge_recursive_distinct ( $merged [$key], $value );
  545. }
  546. else {
  547. $merged [$key] = $value;
  548. }
  549. }
  550. return $merged;
  551. }
  552. /* ---------------------------------------------------------------------*/
  553. function amr_checkfornewoptions ($i) /* not required - ussing array recursive merge instead*/
  554. { /* check if an option has been added, butdoes not exist in the DB - ie we have upgraded. Do not overwrite!! */
  555. global $amr_calprop;
  556. global $amr_colheading;
  557. global $amr_compprop;
  558. global $amr_groupings;
  559. global $amr_components;
  560. global $amr_limits;
  561. global $amr_formats;
  562. global $amr_general;
  563. global $amr_options;
  564. if (isset ($amr_options[$i]['limit']['Events'])) { /* changed in about 2.4 I think*/
  565. $amr_options[$i]['limit']['events'] = $o['limit']['Events'];
  566. unset ($amr_options[$i]['limit']['Events']);
  567. }
  568. if (isset ($amr_options[$i]['limit']['Days'])) {
  569. $amr_options[$i]['limit']['days'] = $o['limit']['Days'];
  570. unset ($amr_options[$i]['limit']['Days']);
  571. }
  572. if (!(isset($amr_options[$i]['heading']))) { /* added in version 2, so may not exist */
  573. $amr_options[$i]['heading'] = $amr_colheading;
  574. }
  575. if (!(isset($amr_options[$i]['general']['Default Event URL']))) { /* added, so may not exist */
  576. $amr_options[$i]['general']['Default Event URL'] = '' ;
  577. }
  578. if (!(isset($amr_options[$i]['general']['name']))) { /* added, so may not exist */
  579. $amr_options[$i]['general']['name'] = 'Default' ;
  580. }
  581. if (!(isset($amr_options[$i]['general']['ListHTMLStyle']))) { /* added, so may not exist */
  582. $amr_options[$i]['general']['ListHTMLStyle'] = 'tableoriginal' ;
  583. }
  584. foreach ($amr_general as $key => $value) {
  585. if (!isset($amr_options[i]['general'][$key])) {$amr_options[i]['general'][$key] = $value; }
  586. }
  587. foreach ($amr_formats as $key => $value) {
  588. if (!isset($amr_options[i]['format'][$key])) {$amr_options[i] ['format'][$key] = $value; }
  589. }
  590. foreach ($amr_calprop as $key => $value) {
  591. if (!isset($amr_options[i] ['calprop'][$key])) {$amr_options[i] ['calprop'][$key] = $value; }
  592. }
  593. foreach ($amr_colheading as $key => $value) {
  594. if (!isset($amr_options[i]['heading'][$key])) {$amr_options[i] ['heading'][$key] = $value; }
  595. }
  596. foreach ($amr_components as $key => $value) {
  597. if (!isset($amr_options[i]['component'][$key])) {$amr_options[i] ['component'][$key] = $value;}
  598. }
  599. foreach ($amr_groupings as $key => $value) {
  600. if (!isset($amr_options[i]['grouping'][$key])) {$amr_options[i]['grouping'][$key] = $value;}
  601. }
  602. foreach ($amr_compprop as $key => $value) {
  603. if (!isset($amr_options[i] ['compprop'][$key])) {$amr_options[i]['compprop'][$key] = $value;}
  604. }
  605. foreach ($amr_limits as $key => $value) {
  606. if (!isset($amr_options[i]['limit'][$key])) {$amr_options[i]['limit'][$key] = $value;}
  607. }
  608. return(true);
  609. }
  610. function Quarter ($D)
  611. { /* Quarters can be complicated. There are Tax and fiscal quarters, and many times the tax and fiscal year is different from the calendar year */
  612. /* We could have used the function commented out for calendar quarters. However to allow for easier variation of the quarter definition. we used the limits concept instead */
  613. /* $D->format('Y').__(' Q ').(ceil($D->format('n')/3)); */
  614. return date_season('Quarter', $D);
  615. }
  616. function Meteorological ($D)
  617. {return date_season('Meteorological', $D); }
  618. function Astronomical_Season ($D)
  619. {return date_season('Astronomical', $D); }
  620. function Traditional_Season ($D)
  621. {return date_season('Traditional', $D); }
  622. function Western_Zodiac ($D){
  623. return date_season('Zodiac', $D); }
  624. function date_season ($type='Meteorological',$D)
  625. { /* Receives ($Dateobject and returns a string with the Meterological season by default*/
  626. /* Note that the limits must be defined on backwards order with a seemingly repeated entry at the end to catch all */
  627. if (!(isset($D))) $D = date_create();
  628. $Y = amr_format_date('Y',$D);
  629. $limits ['Quarter']=array(
  630. /* for different quarters ( fiscal, tax, etc,) change the date ranges and the output here */
  631. '/12/31'=> $Y.' Q1',
  632. '/09/31'=> $Y.' Q4',
  633. '/06/30'=> $Y.' Q3',
  634. '/03/31'=> $Y.' Q2',
  635. '/01/00'=> $Y.' Q1',
  636. );
  637. $limits ['Meteorological']=array(
  638. '/12/01'=>'N. Winter, S. Summer',
  639. '/09/01'=>'N. Fall, S. Spring',
  640. '/06/01'=>'N. Summer, S. Winter',
  641. '/03/01'=>'N. Spring, S. Autumn',
  642. '/01/00'=>'N. Winter, S. Summer'
  643. );
  644. $limits ['Astronomical']=array(
  645. '/12/21'=>'N. Winter, S. Summer',
  646. '/09/23'=>'N. Fall, S. Spring',
  647. '/06/21'=>'N. Summer, S. Winter',
  648. '/03/21'=>'N. Spring, S. Autumn',
  649. '/01/00'=>'N. Winter, S. Summer'
  650. );
  651. $limits ['Traditional']=array(
  652. /* actual dates vary , so this is an approximation */
  653. '/11/08'=>'N. Winter, S. Summer',
  654. '/08/06'=>'N. Fall, S. Spring',
  655. '/06/05'=>'N. Summer, S. Winter',
  656. '/02/05'=>'N. Spring, S. Autumn',
  657. '/01/00'=>'N. Winter, S. Summer'
  658. );
  659. $limits ['Zodiac']=array(
  660. /* actual dates vary , so this is an approximation */
  661. '/12/22'=>'Capricorn',
  662. '/11/22'=>'Sagittarius',
  663. '/10/23'=>'Scorpio',
  664. '/09/23'=>'Libra',
  665. '/08/23'=>'Virgo',
  666. '/07/23'=>'Leo',
  667. '/06/21'=>'Cancer',
  668. '/05/21'=>'Gemini',
  669. '/04/20'=>'Taurus',
  670. '/03/21'=>'Aries',
  671. '/02/19'=>'Pisces',
  672. '/01/20'=>'Aquarius',
  673. '/01/00'=>'Capricon',
  674. );
  675. /* get the current year */
  676. foreach ($limits[$type] AS $key => $value)
  677. {
  678. /* add the current year to the limit */
  679. $limit = $key;
  680. $input = amr_format_date ('/m/d', $D);
  681. /* if date is later than limit, then return the current value, else continue to check the next limit */
  682. if ($input > $limit) {
  683. return $value;
  684. }
  685. }
  686. }
  687. /* -----------------------------------------------------------------------------------------------------*/
  688. function ical_get_weekstart() {
  689. $wkst = get_option('start_of_week'); /* Somewhat annoyingly, wp has sunday as 0 and sat as 6 !! */
  690. if (!$wkst) $wkst = 0; /* only becuase this is wp default */
  691. $ical_day_of_week = array ( /* translate from wp day of week to ical day of week */
  692. '1' => 'MO',
  693. '2' => 'TU',
  694. '3' => 'WE',
  695. '4' => 'TH',
  696. '5' => 'FR',
  697. '6' => 'SA',
  698. '0' => 'SU');
  699. $wkst = $ical_day_of_week[$wkst];
  700. return ($wkst);
  701. }
  702. /*----------------------------------------------------------------------------------------*/
  703. global $gnu_freq_conv;
  704. $gnu_freq_conv = array (
  705. /* used to convert from ical FREQ to gnu relative items for date strings useed by php datetime to do maths */
  706. 'DAILY' => 'day',
  707. 'MONTHLY' => 'month',
  708. 'YEARLY' => 'year',
  709. 'WEEKLY' => 'week',
  710. 'HOURLY' => 'hour',
  711. 'MINUTELY' => 'minute',
  712. 'SECONDLY' => 'second'
  713. );
  714. function amr_ngiyabonga() {
  715. /* The credit text styling is designed to be as subtle as possible (small font size with leight weight text, and right aligned, and at the bottom) and fit in within your theme as much as possible by not styling colours etc */
  716. /* You may however style it more gently, and/or subtly to fit in within your theme. It is good manners to donate if you remove it */
  717. global $amr_options;
  718. if (!$amr_options['ngiyabonga'])
  719. return (
  720. // '<span class="amrical_credit" style="float:right;font-size:x-small;font-weight:lighter;font-style:italic;" >'
  721. // .'<a title="Ical Upcoming Events List version '.AMR_ICAL_LIST_VERSION.'" '
  722. // .'href="http://icalevents.anmari.com/">'
  723. //// .'<img src= "http://icalevents.anmari.com/images/plugin-ical1.png" alt ="'
  724. // .__('Events plugin by anmari','amr_ical_list_lang')
  725. //// .'"</img>'
  726. // .'</a></span>'
  727. '');
  728. }
  729. /* ------------------------------------------------------------------------------------------------------ */
  730. function amr_getset_options ($reset=false) {
  731. /* get the options from wordpress if in wordpress
  732. if no options, then set defaults */
  733. global $locale, $amr_options; /* has the initial default configuration */
  734. /* set up some global config initially */
  735. amr_set_defaults();
  736. $amr_options = array (
  737. 'no_types' => 9,
  738. 'ngiyabonga' => false,
  739. 'own_css' => false,
  740. 'feed_css' => true,
  741. 'cssfile' => ICALSTYLEURL,//'icallist.css',
  742. 'date_localise' => 'amr',
  743. 'noeventsmessage' => __('No events found within criteria','amr_ical_list_lang')
  744. );
  745. if (defined('AMR_ICAL_VERSION')) $amr_options['ngiyabonga'] = true; //do not show credit link
  746. $alreadyhave = false;
  747. if ($locale === 'en_US' ) $method = 'none';
  748. else $method = 'amr';
  749. for ($i = 1; $i <= $amr_options['no_types']; $i++) { /* setup some list type defaults if we have empty list type arrays */
  750. $amr_options[$i] = new_listtype();
  751. $amr_options[$i] = customise_listtype( $i); /* then tweak from the one */
  752. }
  753. /* we are requested to reset the options, so delete and update with default */
  754. if ($reset) {
  755. _e('Resetting options...', 'amr_ical_list_lang');
  756. if (($d = delete_option('AmRiCalEventList')) or ($d = delete_option('amr-ical-events-list')))
  757. _e('Options Deleted...','amr_ical_list_lang');
  758. else _e('Option was not saved before or error deleting option...','amr_ical_list_lang');
  759. // if (update_option('amr-ical-events-list', $amr_options)) _e('Options updated with defaults...','amr_ical_list_lang');
  760. }
  761. else {/* *First setup the default config */
  762. /* general config */
  763. if ($alreadyhave = get_option('amr-ical-events-list')) {}
  764. else
  765. if ($alreadyhave = get_option('AmRiCalEventList')) {
  766. delete_option('AmRiCalEventList');
  767. add_option('amr-ical-events-list', $alreadyhave);
  768. _e(' Converting option key to lowercase','amr_ical_list_lang');
  769. }
  770. }
  771. if ($alreadyhave ) { /* will be false if there were none, want to check for older versions */
  772. $amr_options = array_merge_recursive_distinct( $amr_options, $alreadyhave );
  773. // for ($i = 1; $i <= $amr_options['no_types']; $i++) {
  774. // foreach ($amr_options[$i]['Descriptive']['Days']
  775. // }
  776. if (isset ($amr_options[$i]['limit']['Events'])) { /* changed in about 2.4 I think*/
  777. $amr_options[$i]['limit']['events'] = $o['limit']['Events'];
  778. unset ($amr_options[$i]['limit']['Events']);
  779. }
  780. if (isset ($amr_options[$i]['limit']['Days'])) {
  781. $amr_options[$i]['limit']['days'] = $o['limit']['Days'];
  782. unset ($amr_options[$i]['limit']['Days']);
  783. }
  784. }
  785. return ($amr_options);
  786. }
  787. ?>