PageRenderTime 32ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/event-espresso.3.1.23.P/includes/functions/ical.php

https://bitbucket.org/anneivycat/ebcookhouse
PHP | 133 lines | 124 code | 5 blank | 4 comment | 6 complexity | ad894e2563f653d84a5ca7a24ef6408a MD5 | raw file
  1. <?php
  2. function espresso_ical() {
  3. $name = $_REQUEST['event_summary'] . ".ics";
  4. $output = "BEGIN:VCALENDAR\n" .
  5. "PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN\n" .
  6. "VERSION:2.0\n" .
  7. "BEGIN:VEVENT\n" .
  8. "DTSTAMP:" . $_REQUEST['currentyear'] . $_REQUEST['currentmonth'] . $_REQUEST['currentday'] . "T" . $_REQUEST['currenttime'] . "\n" .
  9. "UID:" . $_REQUEST['attendee_id'] . "@" . $_REQUEST['event_id'] . "\n" .
  10. "ORGANIZER:MAILTO:" . $_REQUEST['contact'] . "\n" .
  11. "DTSTART:" . $_REQUEST['startyear'] . $_REQUEST['startmonth'] . $_REQUEST['startday'] . "T" . $_REQUEST['starttime'] . "\n" .
  12. "DTEND:" . $_REQUEST['endyear'] . $_REQUEST['endmonth'] . $_REQUEST['endday'] . "T" . $_REQUEST['endtime'] . "\n" .
  13. "STATUS:CONFIRMED\n" .
  14. "CATEGORIES:" . $_REQUEST['event_categories'] . "\n" .
  15. "SUMMARY:" . $_REQUEST['event_summary'] . "\n" .
  16. "DESCRIPTION:" . $_REQUEST['event_description'] . "\n" .
  17. "END:VEVENT\n" .
  18. "END:VCALENDAR";
  19. if (ob_get_length())
  20. echo('Some data has already been output, can\'t send iCal file');
  21. header('Content-Type: application/x-download');
  22. if (headers_sent())
  23. echo('Some data has already been output, can\'t send iCal file');
  24. header('Content-Length: ' . strlen($output));
  25. header('Content-Disposition: attachment; filename="' . $name . '"');
  26. header('Cache-Control: private, max-age=0, must-revalidate');
  27. header('Pragma: public');
  28. header('Content-Type: application/octet-stream');
  29. header('Content-Type: application/force-download');
  30. header('Content-type: application/pdf');
  31. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  32. header("Content-Transfer-Encoding: binary");
  33. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  34. ini_set('zlib.output_compression', '0');
  35. echo $output;
  36. die();
  37. }
  38. function espresso_ical_prepare_by_attendee_id($attendee_id) {
  39. global $org_options, $wpdb;
  40. do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
  41. $sql = "SELECT ea.event_id, ed.alt_email, ed.start_date, ed.end_date, ed.event_name, ed.event_desc, ea.event_time, ea.end_time FROM " . EVENTS_ATTENDEE_TABLE . " ea";
  42. $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ea.event_id = ed.id";
  43. $sql .= " WHERE ea.id = '" . $attendee_id . "'";
  44. $data = $wpdb->get_row($sql, OBJECT);
  45. $contact = ($data->alt_email == '') ? $org_options['contact_email'] : $data->alt_email . ',' . $org_options['contact_email'];
  46. if (empty($data->event_time)) $data->event_time = '09:00';
  47. if (empty($data->end_time)) $data->end_time = '17:00';
  48. $start_date = strtotime($data->start_date . ' ' . $data->event_time);
  49. $end_date = strtotime($data->end_date . ' ' . $data->end_time);
  50. $sql = "SELECT ec.category_name FROM " . EVENTS_CATEGORY_TABLE . " ec ";
  51. $sql .= "JOIN " . EVENTS_CATEGORY_REL_TABLE . " ecr ON ec.id = ecr.cat_id ";
  52. $sql .= "WHERE ecr.event_id = '" . $data->event_id . "'";
  53. $cats = $wpdb->get_col($sql);
  54. $categories = '';
  55. foreach ($cats as $cat) {
  56. $categories .= $cat . ',';
  57. }
  58. $categories = rtrim($categories, ',');
  59. $action = strpbrk($_SERVER['REQUEST_URI'], '?') ? $_SERVER['REQUEST_URI'] . "&iCal=true" : $_SERVER['REQUEST_URI'] . "?iCal=true";
  60. $output = "<form id='view_form' action='" . $action . "' method='post' >";
  61. $output .= "<input name='currentyear' type='hidden' value='" . date('Y') . "' >";
  62. $output .= "<input name='currentmonth' type='hidden' value='" . date('m') . "' >";
  63. $output .= "<input name='currentday' type='hidden' value='" . date('d') . "' >";
  64. $output .= "<input name='currenttime' type='hidden' value='" . date('His') . "' >";
  65. $output .= "<input name='attendee_id' type='hidden' value='" . $attendee_id . "' >";
  66. $output .= "<input name='event_id' type='hidden' value='" . $data->event_id . "' >";
  67. $output .= "<input name='contact' type='hidden' value='" . $contact . "' >";
  68. $output .= "<input name='startyear' type='hidden' value='" . date('Y', $start_date) . "' >";
  69. $output .= "<input name='startmonth' type='hidden' value='" . date('m', $start_date) . "' >";
  70. $output .= "<input name='startday' type='hidden' value='" . date('d', $start_date) . "' >";
  71. $output .= "<input name='starttime' type='hidden' value='" . date('His', $start_date) . "' >";
  72. $output .= "<input name='endyear' type='hidden' value='" . date('Y', $end_date) . "' >";
  73. $output .= "<input name='endmonth' type='hidden' value='" . date('m', $end_date) . "' >";
  74. $output .= "<input name='endday' type='hidden' value='" . date('d', $end_date) . "' >";
  75. $output .= "<input name='endtime' type='hidden' value='" . date('His', $end_date) . "' >";
  76. $output .= "<input name='event_categories' type='hidden' value='" . $categories . "' >";
  77. $output .= "<input name='event_summary' type='hidden' value='" . $data->event_name . "' >";
  78. $output .= "<input name='event_description' type='hidden' value='" . $data->event_desc . "' >";
  79. $output .= "<input id='view_button' type='submit' class='btn_event_form_submit ui-priority-primary ui-state-default ui-corner-all' value='Add to Calendar' >";
  80. $output .= "</form>";
  81. // commenting out this line to close cb #653 for 3.1.16.P ~c
  82. //return $output;
  83. }
  84. add_filter('filter_hook_espresso_display_add_to_calendar_by_attendee_id', 'espresso_ical_prepare_by_attendee_id');
  85. function espresso_ical_prepare_by_event_id($event_id) {
  86. global $org_options, $wpdb;
  87. do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
  88. $sql = "SELECT ed.alt_email, ed.start_date, ed.end_date, ed.event_name, ed.event_desc FROM " . EVENTS_DETAIL_TABLE . " ed";
  89. $sql .= " WHERE ed.id = '" . $event_id . "'";
  90. $data = $wpdb->get_row($sql, OBJECT);
  91. $contact = ($data->alt_email == '') ? $org_options['contact_email'] : $data->alt_email . ',' . $org_options['contact_email'];
  92. $start_date = strtotime($data->start_date . ' 09:00');
  93. $end_date = strtotime($data->end_date . ' 17:00');
  94. $sql = "SELECT ec.category_name FROM " . EVENTS_CATEGORY_TABLE . " ec ";
  95. $sql .= "JOIN " . EVENTS_CATEGORY_REL_TABLE . " ecr ON ec.id = ecr.cat_id ";
  96. $sql .= "WHERE ecr.event_id = '" . $event_id . "'";
  97. $cats = $wpdb->get_col($sql);
  98. $categories = '';
  99. foreach ($cats as $cat) {
  100. $categories .= $cat . ',';
  101. }
  102. $categories = rtrim($categories, ',');
  103. $action = strpbrk($_SERVER['REQUEST_URI'], '?') ? $_SERVER['REQUEST_URI'] . "&iCal=true" : $_SERVER['REQUEST_URI'] . "?iCal=true";
  104. $output = "<form id='view_form' action='" . $action . "' method='post' >";
  105. $output .= "<input name='currentyear' type='hidden' value='" . date('Y') . "' >";
  106. $output .= "<input name='currentmonth' type='hidden' value='" . date('m') . "' >";
  107. $output .= "<input name='currentday' type='hidden' value='" . date('d') . "' >";
  108. $output .= "<input name='currenttime' type='hidden' value='" . date('His') . "' >";
  109. $output .= "<input name='attendee_id' type='hidden' value='" . $event_id . "' >";
  110. $output .= "<input name='event_id' type='hidden' value='" . $event_id . "' >";
  111. $output .= "<input name='contact' type='hidden' value='" . $contact . "' >";
  112. $output .= "<input name='startyear' type='hidden' value='" . date('Y', $start_date) . "' >";
  113. $output .= "<input name='startmonth' type='hidden' value='" . date('m', $start_date) . "' >";
  114. $output .= "<input name='startday' type='hidden' value='" . date('d', $start_date) . "' >";
  115. $output .= "<input name='starttime' type='hidden' value='" . date('His', $start_date) . "' >";
  116. $output .= "<input name='endyear' type='hidden' value='" . date('Y', $end_date) . "' >";
  117. $output .= "<input name='endmonth' type='hidden' value='" . date('m', $end_date) . "' >";
  118. $output .= "<input name='endday' type='hidden' value='" . date('d', $end_date) . "' >";
  119. $output .= "<input name='endtime' type='hidden' value='" . date('His', $end_date) . "' >";
  120. $output .= "<input name='event_categories' type='hidden' value='" . $categories . "' >";
  121. $output .= "<input name='event_summary' type='hidden' value='" . $data->event_name . "' >";
  122. $output .= "<input name='event_description' type='hidden' value='" . $data->event_desc . "' >";
  123. $output .= "<input id='view_button' type='submit' class='btn_event_form_submit ui-priority-primary ui-state-default ui-corner-all' value='Add to Calendar' >";
  124. $output .= "</form>";
  125. // commenting out this line to close cb #653 for 3.1.16.P ~c
  126. //return $output;
  127. }
  128. add_filter('filter_hook_espresso_display_add_to_calendar_by_event_id', 'espresso_ical_prepare_by_event_id');