PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/events-manager/em-events.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 274 lines | 236 code | 6 blank | 32 comment | 113 complexity | 9076a3d2b673071dc02ea9dec6febe20 MD5 | raw file
  1. <?php
  2. /*
  3. * This file contains the event related hooks in the front end, as well as some event template tags
  4. */
  5. /**
  6. * Filters for page content and if an event replaces it with the relevant event data.
  7. * @param $data
  8. * @return string
  9. */
  10. function em_content($page_content) {
  11. global $post, $wpdb, $wp_query, $EM_Event, $EM_Location, $EM_Category;
  12. if( empty($post) ) return $page_content; //fix for any other plugins calling the_content outside the loop
  13. $events_page_id = get_option ( 'dbem_events_page' );
  14. $locations_page_id = get_option( 'dbem_locations_page' );
  15. $categories_page_id = get_option( 'dbem_categories_page' );
  16. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  17. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  18. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  19. $my_bookings_page_id = get_option( 'dbem_my_bookings_page' );
  20. //general defaults
  21. $args = array(
  22. 'owner' => false,
  23. 'pagination' => 1
  24. );
  25. if( in_array($post->ID, array($events_page_id, $locations_page_id, $categories_page_id, $edit_bookings_page_id, $edit_events_page_id, $edit_locations_page_id, $my_bookings_page_id)) ){
  26. $content = apply_filters('em_content_pre', '', $page_content);
  27. if( empty($content) ){
  28. ob_start();
  29. if ( $post->ID == $events_page_id && $events_page_id != 0 ) {
  30. if ( !empty($_REQUEST['calendar_day']) ) {
  31. //Events for a specific day
  32. $args = EM_Events::get_post_search( array_merge($args, $_REQUEST) );
  33. em_locate_template('templates/calendar-day.php',true, array('args'=>$args));
  34. }elseif ( $wp_query->get('bookings_page') && empty($my_bookings_page_id)) {
  35. //Bookings Page
  36. em_locate_template('templates/my-bookings.php',true);
  37. }elseif ( is_object($EM_Event)) {
  38. em_locate_template('templates/event-single.php',true, array('args'=>$args));
  39. }else{
  40. // Multiple events page
  41. $args['orderby'] = get_option('dbem_events_default_orderby');
  42. $args['order'] = get_option('dbem_events_default_order');
  43. if (get_option ( 'dbem_display_calendar_in_events_page' )){
  44. $args['long_events'] = 1;
  45. em_locate_template('templates/events-calendar.php',true, array('args'=>$args));
  46. }else{
  47. //Intercept search request, if defined
  48. $args['scope'] = get_option('dbem_events_page_scope');
  49. if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_events' ){
  50. $args = EM_Events::get_post_search( array_merge($args, $_REQUEST) );
  51. }
  52. em_locate_template('templates/events-list.php', true, array('args'=>$args));
  53. }
  54. }
  55. }elseif( $post->ID == $locations_page_id && $locations_page_id != 0 ){
  56. $args['orderby'] = get_option('dbem_locations_default_orderby');
  57. $args['order'] = get_option('dbem_locations_default_order');
  58. if( EM_MS_GLOBAL && is_object($EM_Location) ){
  59. em_locate_template('templates/location-single.php',true, array('args'=>$args));
  60. }else{
  61. em_locate_template('templates/locations-list.php',true, array('args'=>$args));
  62. }
  63. }elseif( $post->ID == $categories_page_id && $categories_page_id != 0 ){
  64. $args['orderby'] = get_option('dbem_categories_default_orderby');
  65. $args['order'] = get_option('dbem_categories_default_order');
  66. em_locate_template('templates/categories-list.php',true, array('args'=>$args));
  67. }elseif( $post->ID == $edit_events_page_id && $edit_events_page_id != 0 ){
  68. em_events_admin();
  69. }elseif( $post->ID == $edit_locations_page_id && $edit_locations_page_id != 0 ){
  70. em_locations_admin();
  71. }elseif( $post->ID == $edit_bookings_page_id && $edit_bookings_page_id != 0 ){
  72. em_bookings_admin();
  73. }elseif( $post->ID == $my_bookings_page_id && $my_bookings_page_id != 0 ){
  74. em_my_bookings();
  75. }
  76. $content = ob_get_clean();
  77. //If disable rewrite flag is on, then we need to add a placeholder here
  78. if( get_option('dbem_disable_title_rewrites') == 1 ){
  79. $content = str_replace('#_PAGETITLE', em_content_page_title(''),get_option('dbem_title_html')) . $content;
  80. }
  81. //Now, we either replace CONTENTS or just replace the whole page
  82. if( preg_match('/CONTENTS/', $page_content) ){
  83. $content = str_replace('CONTENTS',$content,$page_content);
  84. }
  85. if(get_option('dbem_credits')){
  86. $content .= '<p style="color:#999; font-size:11px;">Powered by <a href="http://wp-events-plugin.com" style="color:#999;" target="_blank">Events Manager</a></p>';
  87. }
  88. }
  89. return apply_filters('em_content', '<div id="em-wrapper">'.$content.'</div>');
  90. }
  91. return $page_content;
  92. }
  93. add_filter('the_content', 'em_content');
  94. /**
  95. * Filter for titles when on event pages
  96. * @param $data
  97. * @return string
  98. */
  99. function em_content_page_title($original_content) {
  100. global $EM_Event, $EM_Location, $EM_Category, $wp_query, $post;
  101. if( empty($post) ) return $original_content; //fix for any other plugins calling the_content outside the loop
  102. $events_page_id = get_option ( 'dbem_events_page' );
  103. $locations_page_id = get_option( 'dbem_locations_page' );
  104. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  105. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  106. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  107. if( !empty($post->ID) && in_array($post->ID, array($events_page_id, $locations_page_id, $edit_events_page_id, $edit_locations_page_id, $edit_bookings_page_id))){
  108. $content = apply_filters('em_content_page_title_pre', '', $original_content);
  109. if( empty($content) ){
  110. if ( $post->ID == $events_page_id ) {
  111. if ( !empty( $_REQUEST['calendar_day'] ) ) {
  112. $events = EM_Events::get(array('limit'=>2,'scope'=>$_REQUEST['calendar_day'],'owner'=>false));
  113. if ( count($events) != 1 || get_option('dbem_display_calendar_day_single') == 1 ) {
  114. //We only support dates for the calendar day list title, so we do a simple filter for the supplied calendar_day
  115. $content = get_option ('dbem_list_date_title');
  116. preg_match_all("/#[A-Za-z0-9]+/", $content, $placeholders);
  117. foreach($placeholders[0] as $placeholder) {
  118. // matches all PHP date and time placeholders
  119. if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $placeholder)) {
  120. $content = str_replace($placeholder, mysql2date(ltrim($placeholder, "#"), $_REQUEST['calendar_day']),$content );
  121. }
  122. }
  123. }else{
  124. $event = array_shift($events);
  125. $content = $event->output( get_option('dbem_event_page_title_format') );
  126. }
  127. }elseif ( $wp_query->get('bookings_page') ) {
  128. //Bookings Page
  129. $content = sprintf(__('My %s','dbem'),__('Bookings','dbem'));
  130. }elseif ( is_object($EM_Event) && EM_MS_GLOBAL ) {
  131. // single event page
  132. if( $EM_Event->status == 1 ){
  133. $content = $EM_Event->output ( get_option ( 'dbem_event_page_title_format' ) );
  134. }else{
  135. $content = get_option('dbem_events_page_title');
  136. }
  137. }else{
  138. // Multiple events page, leave untouched
  139. $content = $original_content;
  140. }
  141. }elseif( $post->ID == $locations_page_id ){
  142. if( EM_MS_GLOBAL && is_object($EM_Location) ){
  143. $content = $EM_Location->output(get_option( 'dbem_location_page_title_format' ));
  144. }else{
  145. $content = $original_content;
  146. }
  147. }elseif( $post->ID == $edit_events_page_id ){
  148. if( !empty($_REQUEST['action']) && $_REQUEST['action'] = 'edit' ){
  149. if( is_object($EM_Event) ){
  150. if($EM_Event->is_recurring()){
  151. $content = __( "Reschedule Events", 'dbem' )." '{$EM_Event->event_name}'";
  152. }else{
  153. $content = __( "Edit Event", 'dbem' ) . " '" . $EM_Event->event_name . "'";
  154. }
  155. }else{
  156. $content = __( 'Add Event', 'dbem' );
  157. }
  158. }else{
  159. $content = $original_content;
  160. }
  161. }elseif( $post->ID == $edit_locations_page_id ){
  162. if( !empty($_REQUEST['action']) && $_REQUEST['action'] = 'edit' ){
  163. if( empty($EM_Location) || !is_object($EM_Location) ){
  164. $content = __('Add Location', 'dbem');
  165. }else{
  166. $content = __('Edit Location', 'dbem');
  167. }
  168. }else{
  169. $content = $original_content;
  170. }
  171. }elseif( $post->ID == $edit_bookings_page_id){
  172. if( is_object($EM_Event) ){
  173. $content = $EM_Event->name .' - '. $original_content;
  174. }else{
  175. $content = $original_content;
  176. }
  177. }
  178. return apply_filters('em_content_page_title', $content);
  179. }
  180. }
  181. return $original_content;
  182. }
  183. function em_content_wp_title($title, $sep = '', $seplocation = ''){
  184. global $EM_Location, $post;
  185. if( empty($post) ) return $title; //fix for any other plugins calling the_content outside the loop
  186. $events_page_id = get_option ( 'dbem_events_page' );
  187. $locations_page_id = get_option( 'dbem_locations_page' );
  188. if( !empty($post->ID) && $post->ID != $events_page_id && !in_array($post->ID, array($events_page_id, $locations_page_id)) ){ return $title; }
  189. // Determines position of the separator and direction of the breadcrumb
  190. $new_title = em_content_page_title($title);
  191. if( $new_title != $title ){
  192. if( $sep == '' ) $sep = ' ';
  193. $title_array = explode( $sep, $title );
  194. foreach($title_array as $title_item_key => $title_item){ if(trim($title_item) == ''){ unset($title_array[$title_item_key]); } } //remove blanks
  195. $title_array[] = $new_title;
  196. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  197. array_unshift($title_array, '');
  198. $title_array = array_reverse( $title_array );
  199. }else{
  200. $title_array[] = '';
  201. }
  202. if( $sep == ' ' ) $sep = '';
  203. $title = implode( " $sep ", $title_array );
  204. }
  205. return $title;
  206. }
  207. add_filter ( 'wp_title', 'em_content_wp_title',100,3 ); //override other plugin SEO due to way EM works.
  208. /**
  209. * Makes sure we're in "THE Loop", which is determinied by a flag set when the_post() (start) is first called, and when have_posts() (end) returns false.
  210. * @param string $data
  211. * @return string
  212. */
  213. function em_wp_the_title($data){
  214. global $post, $wp_query, $EM_Location;
  215. if( empty($post) ) return $data; //fix for any other plugins calling the_content outside the loop
  216. //because we're only editing the main title of the page here, we make sure we're in the main query
  217. if( is_main_query() ){
  218. $events_page_id = get_option ( 'dbem_events_page' );
  219. $locations_page_id = get_option( 'dbem_locations_page' );
  220. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  221. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  222. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  223. if( is_main_query() && !empty($post->ID) && in_array($post->ID, array($events_page_id, $locations_page_id, $edit_events_page_id, $edit_locations_page_id, $edit_bookings_page_id)) ){
  224. if ( $wp_query->in_the_loop ) {
  225. return apply_filters('em_wp_the_title', em_content_page_title($data)) ;
  226. }
  227. }
  228. }
  229. return $data;
  230. }
  231. add_filter ( 'the_title', 'em_wp_the_title',10,1 );
  232. function em_get_page_type(){
  233. global $EM_Location, $EM_Category, $EM_Event, $wp_query, $post, $em_category_id, $em_tag_id;
  234. $events_page_id = get_option ( 'dbem_events_page' );
  235. $locations_page_id = get_option( 'dbem_locations_page' );
  236. $categories_page_id = get_option( 'dbem_categories_page' );
  237. if ( !empty($events_page_id) && $post->ID == $events_page_id ) {
  238. if ( $wp_query->get('calendar_day') ) {
  239. return "calendar_day";
  240. }elseif ( $wp_query->get('bookings_page') ) {
  241. return "my_bookings";
  242. }else{
  243. return is_object($EM_Event) ? "event" : "events";
  244. }
  245. }elseif( empty($events_page_id) ){
  246. if( $wp_query->get('calendar_day') ){
  247. return "calendar_day";
  248. }elseif ( $wp_query->get('bookings_page') ) {
  249. return "my_bookings";
  250. }
  251. }
  252. if( is_single() && $post->post_type == EM_POST_TYPE_EVENT ){
  253. return 'event';
  254. }
  255. if( (!empty($locations_page_id) && $post->ID == $locations_page_id) || (!is_single() && $wp_query->query_vars['post_type'] == EM_POST_TYPE_LOCATION) ){
  256. return is_object($EM_Location) ? "location":"locations";
  257. }elseif( is_single() && $post->post_type == EM_POST_TYPE_LOCATION ){
  258. return 'location';
  259. }
  260. if( (!empty($categories_page_id) && $post->ID == $categories_page_id) ){
  261. return "categories";
  262. }elseif( is_tax(EM_TAXONOMY_CATEGORY) || !empty($wp_query->em_category_id) || ($post->ID == get_option('dbem_categories_page') && !empty($em_category_id)) ){
  263. return "category";
  264. }elseif( is_tax(EM_TAXONOMY_TAG) || !empty($wp_query->em_tag_id) || !empty($em_tag_id) ){
  265. return "tag";
  266. }
  267. }
  268. ?>