PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/all-in-one-event-calendar/app/controller/class-ai1ec-events-controller.php

https://github.com/jdickie/mithpressbeta
PHP | 805 lines | 449 code | 90 blank | 266 comment | 35 complexity | 1f2d31ec553668960cd2df88926a3663 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. //
  3. // class-ai1ec-events-controller.php
  4. // all-in-one-event-calendar
  5. //
  6. // Created by The Seed Studio on 2011-07-13.
  7. //
  8. /**
  9. * Ai1ec_Events_Controller class
  10. *
  11. * @package Controllers
  12. * @author The Seed Studio
  13. **/
  14. class Ai1ec_Events_Controller {
  15. /**
  16. * _instance class variable
  17. *
  18. * Class instance
  19. *
  20. * @var null | object
  21. **/
  22. private static $_instance = NULL;
  23. /**
  24. * get_instance function
  25. *
  26. * Return singleton instance
  27. *
  28. * @return object
  29. **/
  30. static function get_instance() {
  31. if( self::$_instance === NULL ) {
  32. self::$_instance = new self();
  33. }
  34. return self::$_instance;
  35. }
  36. /**
  37. * Constructor
  38. *
  39. **/
  40. private function __construct() { }
  41. /**
  42. * delete_hook function
  43. *
  44. * If the deleted post is an event
  45. * then all entries that match the post_id are
  46. * removed from ai1ec_events and ai1ec_event_instances tables
  47. *
  48. * @param int $pid Post ID
  49. *
  50. * @return bool | int
  51. **/
  52. function delete_post( $pid ) {
  53. global $wpdb;
  54. $sql = "SELECT
  55. ID
  56. FROM
  57. $wpdb->posts
  58. WHERE
  59. ID = %d AND
  60. post_type = '" . AI1EC_POST_TYPE . "'";
  61. // is this post an event?
  62. if( $wpdb->get_var( $wpdb->prepare( $sql, $pid ) ) ) {
  63. $table_name = $wpdb->prefix . 'ai1ec_events';
  64. $sql = "DELETE FROM
  65. $table_name
  66. WHERE
  67. post_id = %d";
  68. // delete from ai1ec_events
  69. $wpdb->query( $wpdb->prepare( $sql, $pid ) );
  70. $table_name = $wpdb->prefix . 'ai1ec_event_instances';
  71. $sql = "DELETE FROM
  72. $table_name
  73. WHERE
  74. post_id = %d";
  75. // delete from ai1ec_event_instances
  76. return $wpdb->query( $wpdb->prepare( $sql, $pid ) );
  77. }
  78. return true;
  79. }
  80. /**
  81. * init function
  82. *
  83. * This function is executed when admin_head hook is called.
  84. * Adds CSS and JS files.
  85. *
  86. * @return void
  87. **/
  88. function init()
  89. {
  90. global $ai1ec_events_helper, $ai1ec_settings;
  91. // Initialize dashboard view
  92. if( is_admin() ) {
  93. // ======
  94. // = JS =
  95. // ======
  96. // Include timespan helper functions
  97. wp_enqueue_script( 'jquery.calendrical', AI1EC_JS_URL . '/jquery.calendrical.js', array( 'jquery' ) );
  98. // Include timespan plugin
  99. wp_enqueue_script( 'jquery.timespan', AI1EC_JS_URL . '/jquery.timespan.js', array( 'jquery', 'jquery.calendrical' ) );
  100. // Include timespan plugin
  101. wp_enqueue_script( 'jquery.inputdate', AI1EC_JS_URL . '/jquery.inputdate.js', array( 'jquery', 'jquery.calendrical' ) );
  102. // Include Google Maps API
  103. wp_enqueue_script( 'gmap_api', 'http://maps.google.com/maps/api/js?sensor=false' );
  104. // Include autocomplete_geomod plugin
  105. wp_enqueue_script( 'autocomplete_geomod', AI1EC_JS_URL . '/jquery.autocomplete_geomod.js', array( 'jquery' ) );
  106. // Include geo_autocomplete plugin
  107. wp_enqueue_script( 'geo_autocomplete', AI1EC_JS_URL . '/geo_autocomplete.js', array( 'jquery', 'autocomplete_geomod' ) );
  108. // Include element selector function
  109. wp_enqueue_script( 'ai1ec-element-selector', AI1EC_JS_URL . '/element-selector.js', array( 'jquery' ) );
  110. // Include jQuery Tools form elements
  111. wp_enqueue_script( 'jquery.tools-form', 'http://cdn.jquerytools.org/1.2.5/form/jquery.tools.min.js', array( 'jquery' ), '1.2.5' );
  112. // Include add new event script
  113. wp_enqueue_script( 'ai1ec-add_new_event', AI1EC_JS_URL . '/add_new_event.js', array( 'jquery', 'jquery.timespan', 'ai1ec-element-selector', 'jquery.tools-form' ) );
  114. wp_enqueue_script( 'ai1ec-color-picker', AI1EC_JS_URL . '/colorpicker.js', array( 'jquery' ) );
  115. // Supply custom value to JavaScript from PHP
  116. wp_localize_script( 'ai1ec-add_new_event', 'ai1ec_add_new_event', array(
  117. // Current time, used for date/time pickers
  118. 'now' => $ai1ec_events_helper->gmt_to_local( time() ),
  119. // US input format for date pickers
  120. 'us_format' => $ai1ec_settings->input_us_format,
  121. // 24h time format for time pickers
  122. 'twentyfour_hour' => $ai1ec_settings->input_24h_time,
  123. // ICS feed error messages
  124. 'duplicate_feed_message' => esc_html__( 'This feed is already being imported.', AI1EC_PLUGIN_NAME ),
  125. 'invalid_url_message' => esc_html__( 'Please enter a valid iCalendar URL.', AI1EC_PLUGIN_NAME ),
  126. ) );
  127. // =======
  128. // = CSS =
  129. // =======
  130. // include autocomplete style
  131. wp_enqueue_style( 'autocomplete', AI1EC_CSS_URL . '/jquery.autocomplete.css' );
  132. // include colorpicker style
  133. wp_enqueue_style( 'colorpicker', AI1EC_CSS_URL . '/colorpicker.css' );
  134. // include add new event style
  135. wp_enqueue_style( 'ai1ec_add_new_event', AI1EC_CSS_URL . '/add_new_event.css' );
  136. }
  137. // Initialize front-end view
  138. else
  139. {
  140. // ======
  141. // = JS =
  142. // ======
  143. wp_enqueue_script( 'ai1ec-event', AI1EC_JS_URL . '/event.js', array( 'jquery' ), 1 );
  144. // =======
  145. // = CSS =
  146. // =======
  147. wp_enqueue_style( 'ai1ec-general', AI1EC_CSS_URL . '/general.css', array(), 1 );
  148. wp_enqueue_style( 'ai1ec-event', AI1EC_CSS_URL . '/event.css', array(), 1 );
  149. }
  150. }
  151. /**
  152. * meta_box_view function
  153. *
  154. * Add Events Calculator box to the Add New Event page
  155. *
  156. * @return void
  157. **/
  158. function meta_box_view() {
  159. global $ai1ec_view_helper,
  160. $ai1ec_events_helper,
  161. $post,
  162. $wpdb,
  163. $ai1ec_settings;
  164. try
  165. {
  166. $event = new Ai1ec_Event( $post->ID );
  167. // Existing event was found. Initialize form values with values from
  168. // event object.
  169. $all_day_event = $event->allday ? 'checked="checked"' : '';
  170. $start_timestamp = $ai1ec_events_helper->gmt_to_local( $event->start );
  171. $end_timestamp = $ai1ec_events_helper->gmt_to_local( $event->end );
  172. $show_map = $event->show_map;
  173. $google_map = $show_map ? 'checked="checked"' : '';
  174. $venue = $event->venue;
  175. $country = $event->country;
  176. $address = $event->address;
  177. $city = $event->city;
  178. $province = $event->province;
  179. $postal_code = $event->postal_code;
  180. $contact_name = $event->contact_name;
  181. $contact_phone = $event->contact_phone;
  182. $contact_email = $event->contact_email;
  183. $cost = $event->cost;
  184. }
  185. catch( Ai1ec_Event_Not_Found $e ) {
  186. // Event does not exist.
  187. // Leave form fields undefined (= zero-length strings)
  188. $event = null;
  189. }
  190. // Recurrence fields
  191. $recurrence = $ai1ec_events_helper->parse_recurrence_rules( $event );
  192. extract( $recurrence );
  193. // Time zone
  194. $timezone = get_option( 'gmt_offset' );
  195. $timezone = sprintf( '(GMT%+d:%02d)', intval( $timezone ), ( abs( $timezone ) * 60 ) % 60 );
  196. // ===============================
  197. // = Display event time and date =
  198. // ===============================
  199. if( is_null( $until ) ) $until = gmmktime();
  200. $repeating_event = is_null( $repeat ) ? false : true;
  201. $args = array(
  202. 'all_day_event' => $all_day_event,
  203. 'start_timestamp' => $start_timestamp,
  204. 'end_timestamp' => $end_timestamp,
  205. 'repeat' => $ai1ec_events_helper->create_repeat_dropdown( $repeat ),
  206. 'count' => $ai1ec_events_helper->create_count_input( $count ),
  207. 'end' => $ai1ec_events_helper->create_end_dropdown( $end ),
  208. 'until' => $until,
  209. 'repeating_event' => $repeating_event,
  210. 'timezone' => $timezone,
  211. 'ending' => $end
  212. );
  213. $ai1ec_view_helper->display( 'box_time_and_date.php', $args );
  214. // =================================================
  215. // = Display event location details and Google map =
  216. // =================================================
  217. $args = array(
  218. 'venue' => $venue,
  219. 'country' => $country,
  220. 'address' => $address,
  221. 'city' => $city,
  222. 'province' => $province,
  223. 'postal_code' => $postal_code,
  224. 'google_map' => $google_map,
  225. 'show_map' => $show_map,
  226. );
  227. $ai1ec_view_helper->display( 'box_event_location.php', $args );
  228. // ======================
  229. // = Display event cost =
  230. // ======================
  231. $args = array(
  232. 'cost' => $cost
  233. );
  234. $ai1ec_view_helper->display( 'box_event_cost.php', $args );
  235. // =========================================
  236. // = Display organizer contact information =
  237. // =========================================
  238. $args = array(
  239. 'contact_name' => $contact_name,
  240. 'contact_phone' => $contact_phone,
  241. 'contact_email' => $contact_email,
  242. );
  243. $ai1ec_view_helper->display( 'box_event_contact.php', $args );
  244. if( $ai1ec_settings->show_publish_button ) {
  245. $args = array();
  246. $post_type = $post->post_type;
  247. $post_type_object = get_post_type_object( $post_type );
  248. if( current_user_can( $post_type_object->cap->publish_posts ) )
  249. $args["button_value"] = is_null( $event ) ? __( 'Publish', AI1EC_PLUGIN_NAME ) : __( 'Update', AI1EC_PLUGIN_NAME );
  250. else
  251. $args["button_value"] = __( 'Submit for Review', AI1EC_PLUGIN_NAME );
  252. $ai1ec_view_helper->display( 'box_publish_button.php', $args );
  253. }
  254. /*
  255. TODO Display Eventbrite ticketing
  256. $ai1ec_view_helper->display( 'box_eventbrite.php' );
  257. */
  258. }
  259. /**
  260. * save_post function
  261. *
  262. * Saves meta post data
  263. *
  264. * @param int $post_id Post ID
  265. *
  266. * @return void
  267. **/
  268. function save_post( $post_id ) {
  269. global $wpdb, $ai1ec_events_helper;
  270. // verify if this is not an auto save routine.
  271. if( ! defined( 'DOING_AUTOSAVE' ) && ! DOING_AUTOSAVE ) {
  272. // verify this came from the our screen and with proper authorization,
  273. // because save_post can be triggered at other times
  274. if ( ! wp_verify_nonce( $_POST[AI1EC_POST_TYPE], 'ai1ec' ) ) {
  275. return;
  276. }
  277. }
  278. // verify if this is not inline-editing
  279. if( $_REQUEST['action'] == 'inline-save' ) {
  280. return;
  281. }
  282. // verify that the post_type is that of an event
  283. if( $_POST['post_type'] != AI1EC_POST_TYPE ) {
  284. return;
  285. }
  286. $all_day = isset( $_POST['ai1ec_all_day_event'] ) ? 1 : 0;
  287. $start_time = isset( $_POST['ai1ec_start_time'] ) ? $_POST['ai1ec_start_time'] : '';
  288. $end_time = isset( $_POST['ai1ec_end_time'] ) ? $_POST['ai1ec_end_time'] : '';
  289. $venue = isset( $_POST['ai1ec_venue'] ) ? stripslashes( $_POST['ai1ec_venue'] ) : '';
  290. $address = isset( $_POST['ai1ec_address'] ) ? stripslashes( $_POST['ai1ec_address'] ) : '';
  291. $city = isset( $_POST['ai1ec_city'] ) ? stripslashes( $_POST['ai1ec_city'] ) : '';
  292. $province = isset( $_POST['ai1ec_province'] ) ? stripslashes( $_POST['ai1ec_province'] ) : '';
  293. $postal_code = isset( $_POST['ai1ec_postal_code'] ) ? stripslashes( $_POST['ai1ec_postal_code'] ) : '';
  294. $country = isset( $_POST['ai1ec_country'] ) ? stripslashes( $_POST['ai1ec_country'] ) : '';
  295. $google_map = isset( $_POST['ai1ec_google_map'] ) ? 1 : 0;
  296. $cost = isset( $_POST['ai1ec_cost'] ) ? stripslashes( $_POST['ai1ec_cost'] ) : '';
  297. $contact_name = isset( $_POST['ai1ec_contact_name'] ) ? stripslashes( $_POST['ai1ec_contact_name'] ) : '';
  298. $contact_phone = isset( $_POST['ai1ec_contact_phone'] ) ? stripslashes( $_POST['ai1ec_contact_phone'] ) : '';
  299. $contact_email = isset( $_POST['ai1ec_contact_email'] ) ? stripslashes( $_POST['ai1ec_contact_email'] ) : '';
  300. $rrule = null;
  301. if( isset( $_POST['ai1ec_repeat'] ) && ! empty( $_POST['ai1ec_repeat'] ) && $_POST['ai1ec_repeat'] != ' ' ) {
  302. // ================================
  303. // = Repeating event, build rrule =
  304. // ================================
  305. $end = (int) $_POST['ai1ec_end'];
  306. switch( $end ) {
  307. // Never
  308. case 0:
  309. $end = '';
  310. break;
  311. // After
  312. case 1:
  313. $end = ';COUNT=' . (int) $_POST['ai1ec_count'];
  314. break;
  315. // On date
  316. case 2:
  317. $until = $_POST['ai1ec_until_time'];
  318. $until = gmdate( 'Ymd', $until );
  319. $end = ';UNTIL=' . $until;
  320. break;
  321. }
  322. switch( $_POST['ai1ec_repeat'] ) {
  323. // Daily
  324. case 'DAILY':
  325. $rrule = 'FREQ=DAILY';
  326. break;
  327. // Mondays
  328. case 'MO':
  329. $rrule = 'FREQ=DAILY;BYDAY=MO';
  330. break;
  331. // Tuesdays
  332. case 'TU':
  333. $rrule = 'FREQ=DAILY;BYDAY=TU';
  334. break;
  335. // Wednesdays
  336. case 'WE':
  337. $rrule = 'FREQ=DAILY;BYDAY=WE';
  338. break;
  339. // Thursdays
  340. case 'TH':
  341. $rrule = 'FREQ=DAILY;BYDAY=TH';
  342. break;
  343. // Fridays
  344. case 'FR':
  345. $rrule = 'FREQ=DAILY;BYDAY=FR';
  346. break;
  347. // Tuesdays and Thursdays
  348. case 'TU+TH':
  349. $rrule = 'FREQ=DAILY;BYDAY=TU,TH';
  350. break;
  351. // Mondays Wednesdays Fridays
  352. case 'MO+WE+FR':
  353. $rrule = 'FREQ=DAILY;BYDAY=MO,WE,FR';
  354. break;
  355. // Weekends
  356. case 'WEEKDAYS':
  357. $rrule = 'FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR';
  358. break;
  359. // Saturdays
  360. case 'SA':
  361. $rrule = 'FREQ=DAILY;BYDAY=SA';
  362. break;
  363. // Sundays
  364. case 'SU':
  365. $rrule = 'FREQ=DAILY;BYDAY=SU';
  366. break;
  367. // Weekends
  368. case 'WEEKENDS':
  369. $rrule = 'FREQ=DAILY;BYDAY=SA+SU';
  370. break;
  371. // Weekly
  372. case 'WEEKLY':
  373. $rrule = 'FREQ=WEEKLY';
  374. break;
  375. // Monthly
  376. case 'MONTHLY':
  377. $rrule = 'FREQ=MONTHLY';
  378. break;
  379. // Yearly
  380. case 'YEARLY':
  381. $rrule = 'FREQ=YEARLY';
  382. break;
  383. }
  384. $rrule .= $end;
  385. }
  386. $is_new = false;
  387. $event = null;
  388. try {
  389. $event = new Ai1ec_Event( $post_id ? $post_id : null );
  390. } catch( Ai1ec_Event_Not_Found $e ) {
  391. // Post exists, but event data hasn't been saved yet. Create new event
  392. // object.
  393. $is_new = true;
  394. $event = new Ai1ec_Event();
  395. $event->post_id = $post_id;
  396. }
  397. $event->start = $ai1ec_events_helper->local_to_gmt( $start_time );
  398. $event->end = $ai1ec_events_helper->local_to_gmt( $end_time );
  399. $event->allday = $all_day;
  400. $event->venue = $venue;
  401. $event->address = $address;
  402. $event->city = $city;
  403. $event->province = $province;
  404. $event->postal_code = $postal_code;
  405. $event->country = $country;
  406. $event->show_map = $google_map;
  407. $event->cost = $cost;
  408. $event->contact_name = $contact_name;
  409. $event->contact_phone = $contact_phone;
  410. $event->contact_email = $contact_email;
  411. $event->recurrence_rules = $rrule;
  412. $event->save( ! $is_new );
  413. $ai1ec_events_helper->delete_event_cache( $post_id );
  414. $ai1ec_events_helper->cache_event( $event );
  415. return;
  416. }
  417. /**
  418. * post_updated_messages function
  419. *
  420. * Filter success messages returned by WordPress when an event post is
  421. * updated/saved.
  422. */
  423. function post_updated_messages( $messages )
  424. {
  425. global $post, $post_ID;
  426. $messages[AI1EC_POST_TYPE] = array(
  427. 0 => '', // Unused. Messages start at index 1.
  428. 1 => sprintf( __( 'Event updated. <a href="%s">View event</a>', AI1EC_PLUGIN_NAME ), esc_url( get_permalink( $post_ID ) ) ),
  429. 2 => __( 'Custom field updated.', AI1EC_PLUGIN_NAME ),
  430. 3 => __( 'Custom field deleted.', AI1EC_PLUGIN_NAME ),
  431. 4 => __( 'Event updated.', AI1EC_PLUGIN_NAME ),
  432. /* translators: %s: date and time of the revision */
  433. 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Event restored to revision from %s', AI1EC_PLUGIN_NAME ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
  434. 6 => sprintf( __( 'Event published. <a href="%s">View event</a>', AI1EC_PLUGIN_NAME ), esc_url( get_permalink($post_ID) ) ),
  435. 7 => __( 'Event saved.' ),
  436. 8 => sprintf( __( 'Event submitted. <a target="_blank" href="%s">Preview event</a>', AI1EC_PLUGIN_NAME ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
  437. 9 => sprintf( __( 'Event scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview event</a>', AI1EC_PLUGIN_NAME ),
  438. // translators: Publish box date format, see http://php.net/date
  439. date_i18n( __( 'M j, Y @ G:i', AI1EC_PLUGIN_NAME ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
  440. 10 => sprintf( __( 'Event draft updated. <a target="_blank" href="%s">Preview event</a>', AI1EC_PLUGIN_NAME ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
  441. );
  442. return $messages;
  443. }
  444. /**
  445. * event_content function
  446. *
  447. * Filter event post content by inserting relevant details of the event
  448. * alongside the regular post content.
  449. *
  450. * @param string $content Post/Page content
  451. *
  452. * @return string Post/Page content
  453. **/
  454. function event_content( $content )
  455. {
  456. global $ai1ec_events_helper;
  457. if( get_post_type() == AI1EC_POST_TYPE ) {
  458. $event = $ai1ec_events_helper->get_event( get_the_ID() );
  459. $content = $this->get_view( $event, $content );
  460. }
  461. return $content;
  462. }
  463. /**
  464. * event_excerpt function
  465. *
  466. * Overrides what wp_trim_excerpt() returned if the post is an event,
  467. * and outputs better rich-text (but not too rich) excerpt instead.
  468. *
  469. * @return void
  470. **/
  471. function event_excerpt( $text )
  472. {
  473. global $ai1ec_view_helper,
  474. $ai1ec_events_helper;
  475. if( get_post_type() != AI1EC_POST_TYPE )
  476. return $text;
  477. $event = new Ai1ec_Event( get_the_ID() );
  478. ob_start();
  479. $this->excerpt_view( $event );
  480. // Re-apply any filters to the post content that normally would have been
  481. // applied if it weren't for our interference (below).
  482. echo
  483. shortcode_unautop( wpautop(
  484. $ai1ec_events_helper->trim_excerpt( $event->post->post_content )
  485. ) );
  486. $page_content = ob_get_contents();
  487. ob_end_clean();
  488. return $page_content;
  489. }
  490. /**
  491. * event_excerpt_noautop function
  492. *
  493. * Conditionally apply wpautop() filter to content, only if it is not an
  494. * event.
  495. *
  496. * @return void
  497. **/
  498. function event_excerpt_noautop( $content )
  499. {
  500. if( get_post_type() != AI1EC_POST_TYPE )
  501. return wpautop( $content );
  502. return $content;
  503. }
  504. /**
  505. * get_view function
  506. *
  507. * Returns the appropriate output to prepend to an event post, depending on
  508. * WP loop context.
  509. *
  510. * @param Ai1ec_Event $event The event post being displayed
  511. * @param string $content The post's original content
  512. *
  513. * @return string The event data markup to prepend to the post content
  514. **/
  515. function get_view( &$event, &$content )
  516. {
  517. global $ai1ec_view_helper;
  518. ob_start();
  519. if( is_single() ) {
  520. $this->single_view( $event );
  521. } else {
  522. $this->multi_view( $event );
  523. }
  524. echo $content;
  525. if( is_single() )
  526. $this->single_event_footer( $event );
  527. $page_content = ob_get_contents();
  528. ob_end_clean();
  529. return $page_content;
  530. }
  531. /**
  532. * single_view function
  533. *
  534. * Outputs event-specific details as HTML to be prepended to post content
  535. * when displayed as a single page.
  536. *
  537. * @param Ai1ec_Event $event The event being displayed
  538. *
  539. * @return void
  540. **/
  541. function single_view( &$event )
  542. {
  543. global $ai1ec_view_helper,
  544. $ai1ec_calendar_helper,
  545. $ai1ec_settings;
  546. $subscribe_url = AI1EC_EXPORT_URL . "&ai1ec_post_ids=$event->post_id";
  547. $subscribe_url = str_replace( 'webcal://', 'http://', $subscribe_url );
  548. $args = array(
  549. 'event' => &$event,
  550. 'recurrence' => $event->recurrence_html,
  551. 'categories' => $event->categories_html,
  552. 'tags' => $event->tags_html,
  553. 'location' => nl2br( $event->location ),
  554. 'map' => $this->get_map_view( $event ),
  555. 'contact' => $event->contact_html,
  556. 'calendar_url' => $ai1ec_calendar_helper->get_calendar_url( $event ),
  557. 'subscribe_url' => $subscribe_url,
  558. 'google_url' => 'http://www.google.com/calendar/render?cid=' . urlencode( $subscribe_url ),
  559. 'show_subscribe_buttons' => ! $ai1ec_settings->turn_off_subscription_buttons
  560. );
  561. $ai1ec_view_helper->display( 'event-single.php', $args );
  562. }
  563. /**
  564. * multi_view function
  565. *
  566. * Outputs event-specific details as HTML to be prepended to post content
  567. * when displayed in a loop alongside other posts.
  568. *
  569. * @param Ai1ec_Event $event The event being displayed
  570. *
  571. * @return void
  572. **/
  573. function multi_view( &$event )
  574. {
  575. global $ai1ec_view_helper,
  576. $ai1ec_calendar_helper;
  577. $location = str_replace( "\n", ', ', rtrim( $event->location ) );
  578. $args = array(
  579. 'event' => &$event,
  580. 'recurrence' => $event->recurrence_html,
  581. 'categories' => $event->categories_html,
  582. 'tags' => $event->tags_html,
  583. 'location' => $location,
  584. 'contact' => $event->contact_html,
  585. 'calendar_url' => $ai1ec_calendar_helper->get_calendar_url( $event ),
  586. );
  587. $ai1ec_view_helper->display( 'event-multi.php', $args );
  588. }
  589. /**
  590. * excerpt_view function
  591. *
  592. * Outputs event-specific details as HTML to be prepended to post content
  593. * when displayed in an excerpt format.
  594. *
  595. * @param Ai1ec_Event $event The event being displayed
  596. *
  597. * @return void
  598. **/
  599. function excerpt_view( &$event )
  600. {
  601. global $ai1ec_view_helper,
  602. $ai1ec_calendar_helper;
  603. $location = str_replace( "\n", ', ', rtrim( $event->location ) );
  604. $args = array(
  605. 'event' => &$event,
  606. 'location' => $location,
  607. );
  608. $ai1ec_view_helper->display( 'event-excerpt.php', $args );
  609. }
  610. /**
  611. * get_map_view function
  612. *
  613. * Returns HTML markup displaying a Google map of the given event, if the event
  614. * has show_map set to true. Returns a zero-length string otherwise.
  615. *
  616. * @return void
  617. **/
  618. function get_map_view( &$event )
  619. {
  620. global $ai1ec_view_helper, $ai1ec_events_helper, $ai1ec_settings;
  621. if( ! $event->show_map )
  622. return '';
  623. $args = array(
  624. 'address' => $event->address,
  625. 'gmap_url_link' => $ai1ec_events_helper->get_gmap_url( $event, false ),
  626. 'hide_maps_until_clicked' => $ai1ec_settings->hide_maps_until_clicked
  627. );
  628. return $ai1ec_view_helper->get_view( 'event-map.php', $args );
  629. }
  630. /**
  631. * single_event_footer function
  632. *
  633. * Outputs any markup that should appear below the post's content on the
  634. * single post page for this event.
  635. *
  636. * @return void
  637. **/
  638. function single_event_footer( &$event )
  639. {
  640. global $ai1ec_view_helper;
  641. $args = array(
  642. 'event' => &$event,
  643. );
  644. return $ai1ec_view_helper->display( 'event-single-footer.php', $args );
  645. }
  646. /**
  647. * events_categories_add_form_fields function
  648. *
  649. *
  650. *
  651. * @return void
  652. **/
  653. function events_categories_add_form_fields() {
  654. global $ai1ec_view_helper;
  655. $args = array();
  656. $ai1ec_view_helper->display( 'event_categories-color_picker.php' );
  657. }
  658. /**
  659. * events_categories_edit_form_fields function
  660. *
  661. *
  662. *
  663. * @return void
  664. **/
  665. function events_categories_edit_form_fields( $term ) {
  666. global $ai1ec_view_helper, $wpdb;
  667. $table_name = $wpdb->prefix . 'ai1ec_event_category_colors';
  668. $color = $wpdb->get_var( "SELECT term_color FROM {$table_name} WHERE term_id = {$term->term_id}" );
  669. $style = '';
  670. $clr = '';
  671. if( ! is_null( $color ) && ! empty( $color ) ) {
  672. $style = 'style="background-color: ' . $color . '"';
  673. $clr = $color;
  674. }
  675. $args = array(
  676. 'style' => $style,
  677. 'color' => $clr,
  678. 'edit' => true,
  679. );
  680. $ai1ec_view_helper->display( 'event_categories-color_picker.php', $args );
  681. }
  682. /**
  683. * edited_events_categories function
  684. *
  685. *
  686. *
  687. * @return void
  688. **/
  689. function created_events_categories( $term_id ) {
  690. global $wpdb;
  691. $tag_color_value = '';
  692. if( isset( $_POST["tag-color-value"] ) && ! empty( $_POST["tag-color-value"] ) ) {
  693. $tag_color_value = $_POST["tag-color-value"];
  694. }
  695. $table_name = $wpdb->prefix . 'ai1ec_event_category_colors';
  696. $wpdb->insert( $table_name, array( 'term_id' => $term_id, 'term_color' => $tag_color_value ), array( '%d', '%s' ) );
  697. }
  698. function edited_events_categories( $term_id ) {
  699. global $wpdb;
  700. $tag_color_value = '';
  701. if( isset( $_POST["tag-color-value"] ) && ! empty( $_POST["tag-color-value"] ) ) {
  702. $tag_color_value = $_POST["tag-color-value"];
  703. }
  704. $table_name = $wpdb->prefix . 'ai1ec_event_category_colors';
  705. $term = $wpdb->get_var( "SELECT term_id FROM {$table_name} WHERE term_id = {$term_id}" );
  706. if( is_null( $term ) ) {
  707. // term doesn't exist, create it
  708. $wpdb->insert( $table_name, array( 'term_id' => $term_id, 'term_color' => $tag_color_value ), array( '%d', '%s' ) );
  709. } else {
  710. // term exist, update it
  711. $wpdb->update( $table_name, array( 'term_color' => $tag_color_value ), array( 'term_id' => $term_id ), array( '%s' ), array( '%d' ) );
  712. }
  713. }
  714. }
  715. // END class