Advertisement
Guest User

Untitled

a guest
Mar 1st, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.15 KB | None | 0 0
  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. /**
  7. * Filters for page content and if an event replaces it with the relevant event data.
  8. * @param $data
  9. * @return string
  10. */
  11. function em_content($page_content) {
  12. global $post, $wpdb, $wp_query, $EM_Event, $EM_Location, $EM_Category;
  13. if( empty($post) ) return $page_content; //fix for any other plugins calling the_content outside the loop
  14. $events_page_id = get_option ( 'dbem_events_page' );
  15. $locations_page_id = get_option( 'dbem_locations_page' );
  16. $categories_page_id = get_option( 'dbem_categories_page' );
  17. $tags_page_id = get_option( 'dbem_tags_page' );
  18. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  19. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  20. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  21. $my_bookings_page_id = get_option( 'dbem_my_bookings_page' );
  22. //core_changed//polylang
  23. global $polylang;
  24. $translated_events_page_id = pll_get_post($events_page_id,'ru');
  25. $translated_events_page = get_post($translated_events_page_id);
  26. $translated_events_page_content = $translated_events_page->post_content;
  27. $translated_categories_page_id = pll_get_post($categories_page_id,'ru');
  28. $translated_categories_page = get_post($translated_categories_page_id);
  29. $translated_categories_page_content = $translated_categories_page->post_content;
  30. //general defaults
  31. $args = array(
  32. 'owner' => false,
  33. 'pagination' => 1
  34. );
  35. $args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
  36. if( !post_password_required() && in_array($post->ID, array($translated_events_page_id, $translated_categories_page_id, $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, $tags_page_id)) ){ //core_changed//polylang//scan_russian
  37. $content = apply_filters('em_content_pre', '', $page_content);
  38. if( empty($content) ){
  39. ob_start();
  40. if ( ( $post->ID == $events_page_id && $events_page_id != 0 ) || ( $post->ID == $translated_events_page_id && $translated_events_page_id != 0 ) ) { //core_changed//polylang
  41. if ( !empty($_REQUEST['calendar_day']) ) {
  42. //Events for a specific day
  43. $args = EM_Events::get_post_search( array_merge($args, $_REQUEST) );
  44. em_locate_template('templates/calendar-day.php',true, array('args'=>$args));
  45. }elseif ( is_object($EM_Event)) {
  46. em_locate_template('templates/event-single.php',true, array('args'=>$args));
  47. }else{
  48. // Multiple events page
  49. $args['orderby'] = get_option('dbem_events_default_orderby');
  50. $args['order'] = get_option('dbem_events_default_order');
  51. if (get_option ( 'dbem_display_calendar_in_events_page' )){
  52. $args['long_events'] = 1;
  53. em_locate_template('templates/events-calendar.php',true, array('args'=>$args));
  54. }else{
  55. //Intercept search request, if defined
  56. if( !empty($_REQUEST['action']) && ($_REQUEST['action'] == 'search_events' || $_REQUEST['action'] == 'search_events_grouped') ){
  57. $args = EM_Events::get_post_search( array_merge($args, $_REQUEST) );
  58. }
  59. if( empty($args['scope']) ){
  60. $args['scope'] = get_option('dbem_events_page_scope');
  61. }
  62. if( get_option('dbem_events_page_search_form') ){
  63. //load the search form and pass on custom arguments (from settings page)
  64. $search_args = em_get_search_form_defaults();
  65. $search_args['search_action'] = get_option('dbem_event_list_groupby') && !empty($args['ajax']) ? 'search_events_grouped':'search_events';
  66. em_locate_template('templates/events-search.php', true, array('args'=>$search_args));
  67. }
  68. $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit');
  69. if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //AJAX wrapper open
  70. if( get_option('dbem_event_list_groupby') ){
  71. em_locate_template('templates/events-list-grouped.php', true, array('args'=>$args));
  72. }else{
  73. em_locate_template('templates/events-list.php', true, array('args'=>$args));
  74. }
  75. if( !empty($args['ajax']) ) echo "</div>"; //AJAX wrapper close
  76. }
  77. }
  78. }elseif( $post->ID == $locations_page_id && $locations_page_id != 0 ){
  79. $args['orderby'] = get_option('dbem_locations_default_orderby');
  80. $args['order'] = get_option('dbem_locations_default_order');
  81. $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_locations_default_limit');
  82. if( EM_MS_GLOBAL && is_object($EM_Location) ){
  83. em_locate_template('templates/location-single.php',true, array('args'=>$args));
  84. }else{
  85. //Intercept search request, if defined
  86. if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_locations' ){
  87. $args = EM_Locations::get_post_search( array_merge($args, $_REQUEST) );
  88. }
  89. if( get_option('dbem_locations_page_search_form') ){
  90. //load the search form and pass on custom arguments (from settings page)
  91. $search_args = em_get_search_form_defaults();
  92. //remove date and category
  93. $search_args['search_categories'] = $search_args['search_scope'] = false;
  94. em_locate_template('templates/locations-search.php', true, array('args'=>$search_args));
  95. }
  96. if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //AJAX wrapper open
  97. em_locate_template('templates/locations-list.php',true, array('args'=>$args));
  98. if( !empty($args['ajax']) ) echo "</div>"; //AJAX wrapper close
  99. }
  100. }elseif( ($post->ID == $categories_page_id && $categories_page_id != 0) || ($post->ID == $translated_categories_page_id && $translated_categories_page_id != 0) ){ //core_changed//polylang
  101. $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_categories_default_limit');
  102. if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //AJAX wrapper open
  103. em_locate_template('templates/categories-list.php',true, array('args'=>$args));
  104. if( !empty($args['ajax']) ) echo "</div>"; //AJAX wrapper close
  105. }elseif( $post->ID == $tags_page_id && $tags_page_id != 0 ){
  106. $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_tags_default_limit');
  107. if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //AJAX wrapper open
  108. em_locate_template('templates/tags-list.php',true, array('args'=>$args));
  109. if( !empty($args['ajax']) ) echo "</div>"; //AJAX wrapper close
  110. }elseif( $post->ID == $edit_events_page_id && $edit_events_page_id != 0 ){
  111. em_events_admin();
  112. }elseif( $post->ID == $edit_locations_page_id && $edit_locations_page_id != 0 ){
  113. em_locations_admin();
  114. }elseif( $post->ID == $my_bookings_page_id && $my_bookings_page_id != 0 ){
  115. em_my_bookings();
  116. }elseif( $post->ID == $edit_bookings_page_id && $edit_bookings_page_id != 0 ){
  117. em_bookings_admin();
  118. }
  119. $content = ob_get_clean();
  120. //If disable rewrite flag is on, then we need to add a placeholder here
  121. if( get_option('dbem_disable_title_rewrites') == 1 ){
  122. $content = str_replace('#_PAGETITLE', em_content_page_title(''),get_option('dbem_title_html')) . $content;
  123. }
  124. //Now, we either replace CONTENTS or just replace the whole page
  125. if( preg_match('/CONTENTS/', $page_content) ){
  126. $content = str_replace('CONTENTS',$content,$page_content);
  127. }
  128.  
  129. if(get_option('dbem_credits')){
  130. $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>';
  131. }
  132. }
  133. return apply_filters('em_content', '<div id="em-wrapper">'.$content.'</div>');
  134. }
  135. return $page_content;
  136. }
  137. add_filter('the_content', 'em_content');
  138.  
  139. /**
  140. * Filter for titles when on event pages
  141. * @param $data
  142. * @return string
  143. */
  144. function em_content_page_title($original_content, $id = null) {
  145. global $EM_Event, $EM_Location, $EM_Category, $wp_query, $post;
  146. if( empty($post) ) return $original_content; //fix for any other plugins calling the_content outside the loop
  147. if ($id && $id !== $post->ID) return $original_content;
  148.  
  149. $events_page_id = get_option ( 'dbem_events_page' );
  150. $locations_page_id = get_option( 'dbem_locations_page' );
  151. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  152. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  153. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  154. 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))){
  155. //override the titles with this filter if needed, preventing the following code from being run
  156. $content = apply_filters('em_content_page_title_pre', '', $original_content);
  157. if( empty($content) ){
  158. $content = $original_content; //leave untouched by default
  159. if ( $post->ID == $events_page_id ) {
  160. if ( !empty( $_REQUEST['calendar_day'] ) ) {
  161. $events = EM_Events::get(array('limit'=>2,'scope'=>$_REQUEST['calendar_day'],'owner'=>false));
  162. if ( count($events) != 1 || get_option('dbem_display_calendar_day_single') == 1 ) {
  163. //We only support dates for the calendar day list title, so we do a simple filter for the supplied calendar_day
  164. $content = get_option ('dbem_list_date_title');
  165. preg_match_all("/#[A-Za-z0-9]+/", $content, $placeholders);
  166. foreach($placeholders[0] as $placeholder) {
  167. // matches all PHP date and time placeholders
  168. if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $placeholder)) {
  169. $content = str_replace($placeholder, mysql2date(ltrim($placeholder, "#"), $_REQUEST['calendar_day']),$content );
  170. }
  171. }
  172. }else{
  173. $event = array_shift($events);
  174. $content = $event->output( get_option('dbem_event_page_title_format') );
  175. }
  176. }elseif ( EM_MS_GLOBAL && is_object($EM_Event) && !get_option('dbem_ms_global_events_links') ) {
  177. // single event page
  178. $content = $EM_Event->output ( get_option ( 'dbem_event_page_title_format' ) );
  179. }
  180. }elseif( $post->ID == $locations_page_id ){
  181. if( EM_MS_GLOBAL && is_object($EM_Location) && get_option('dbem_ms_global_locations_links') ){
  182. $content = $EM_Location->output(get_option( 'dbem_location_page_title_format' ));
  183. }
  184. }elseif( $post->ID == $edit_events_page_id ){
  185. if( !empty($_REQUEST['action']) && $_REQUEST['action'] = 'edit' ){
  186. if( is_object($EM_Event) && $EM_Event->event_id){
  187. if($EM_Event->is_recurring()){
  188. $content = __( "Reschedule Events", 'dbem' )." '{$EM_Event->event_name}'";
  189. }else{
  190. $content = __( "Edit Event", 'dbem' ) . " '" . $EM_Event->event_name . "'";
  191. }
  192. }else{
  193. $content = __( 'Add Event', 'dbem' );
  194. }
  195. }
  196. }elseif( $post->ID == $edit_locations_page_id ){
  197. if( !empty($_REQUEST['action']) && $_REQUEST['action'] = 'edit' ){
  198. if( empty($EM_Location) || !is_object($EM_Location) ){
  199. $content = __('Add Location', 'dbem');
  200. }else{
  201. $content = __('Edit Location', 'dbem');
  202. }
  203. }
  204. }elseif( $post->ID == $edit_bookings_page_id){
  205. if( is_object($EM_Event) ){
  206. $content = $EM_Event->name .' - '. $original_content;
  207. }
  208. }
  209. return apply_filters('em_content_page_title', $content);
  210. }
  211. }
  212. return $original_content;
  213. }
  214.  
  215. function em_content_wp_title($title, $sep = '', $seplocation = ''){
  216. global $EM_Location, $post;
  217. if( empty($post) ) return $title; //fix for any other plugins calling the_content outside the loop
  218. //single event and location page titles get parsed for formats
  219. if( is_single() && !empty($post->post_type) ){
  220. if( $post->post_type == EM_POST_TYPE_EVENT ){
  221. $EM_Event = em_get_event($post);
  222. return $EM_Event->output($title);
  223. }elseif( $post->post_type == EM_POST_TYPE_LOCATION ){
  224. $EM_Location = em_get_location($post);
  225. return $EM_Location->output($title);
  226. }
  227. }
  228. //we only rewrite titles on events and locations pages since they are 'special'
  229. $pages = array( get_option('dbem_events_page'), get_option( 'dbem_locations_page' ) );
  230. if( !empty($post->ID) && !in_array($post->ID,$pages) ){ return $title; }
  231. // Determines position of the separator and direction of the breadcrumb
  232. $new_title = em_content_page_title($title);
  233. if( $new_title != $title ){
  234. if( $sep == '' ) $sep = ' ';
  235. $title_array = explode( $sep, $title );
  236. foreach($title_array as $title_item_key => $title_item){ if(trim($title_item) == ''){ unset($title_array[$title_item_key]); } } //remove blanks
  237. $title_array[] = $new_title;
  238. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  239. array_unshift($title_array, '');
  240. $title_array = array_reverse( $title_array );
  241. }else{
  242. $title_array[] = '';
  243. }
  244. if( $sep == ' ' ) $sep = '';
  245. $title = implode( " $sep ", $title_array );
  246. }
  247. return $title;
  248. }
  249. add_filter ( 'wp_title', 'em_content_wp_title',100,3 ); //override other plugin SEO due to way EM works.
  250. add_filter( 'wpseo_title', 'em_content_wp_title', 100, 3 ); //WP SEO friendly
  251.  
  252. /**
  253. * 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.
  254. * @param string $data
  255. * @return string
  256. */
  257. function em_wp_the_title($data, $id = null){
  258. global $post, $wp_query, $EM_Location, $EM_Event;
  259. if( empty($post) ) return $data; //fix for any other plugins calling the_content outside the loop
  260. //because we're only editing the main title of the page here, we make sure we're in the main query
  261. if( is_main_query() ){
  262. $events_page_id = get_option ( 'dbem_events_page' );
  263. $locations_page_id = get_option( 'dbem_locations_page' );
  264. $edit_events_page_id = get_option( 'dbem_edit_events_page' );
  265. $edit_locations_page_id = get_option( 'dbem_edit_locations_page' );
  266. $edit_bookings_page_id = get_option( 'dbem_edit_bookings_page' );
  267. 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)) ){
  268. if ( $wp_query->in_the_loop ) {
  269. return apply_filters('em_wp_the_title', em_content_page_title($data, $id)) ;
  270. }
  271. }elseif( is_main_query() && is_single() && !empty($post->post_type) ){
  272. if( $post->post_type == EM_POST_TYPE_EVENT ){
  273. $EM_Event = em_get_event($post);
  274. return apply_filters('em_wp_the_title', $EM_Event->output($data)) ;
  275. }elseif( $post->post_type == EM_POST_TYPE_LOCATION ){
  276. $EM_Location = em_get_location($post);
  277. return apply_filters('em_wp_the_title', $EM_Location->output($data)) ;
  278. }
  279. }
  280. }
  281. return $data;
  282. }
  283. add_filter ( 'the_title', 'em_wp_the_title',10, 2 );
  284.  
  285.  
  286. function em_get_page_type(){
  287. global $EM_Location, $EM_Category, $EM_Event, $wp_query, $post, $em_category_id, $em_tag_id;
  288. $events_page_id = get_option ( 'dbem_events_page' );
  289. $locations_page_id = get_option( 'dbem_locations_page' );
  290. $categories_page_id = get_option( 'dbem_categories_page' );
  291. $has_post = is_object($post);
  292. if ( !empty($events_page_id) && $has_post && $post->ID == $events_page_id ) {
  293. if ( $wp_query->get('calendar_day') ) {
  294. return "calendar_day";
  295. }else{
  296. return is_object($EM_Event) ? "event" : "events";
  297. }
  298. }elseif( empty($events_page_id) ){
  299. if( $wp_query->get('calendar_day') ){
  300. return "calendar_day";
  301. }
  302. }
  303. if( is_single() && $has_post && $post->post_type == EM_POST_TYPE_EVENT ){
  304. return 'event';
  305. }
  306. if( (!empty($locations_page_id) && $has_post && $post->ID == $locations_page_id) || (!is_single() && $wp_query->query_vars['post_type'] == EM_POST_TYPE_LOCATION) ){
  307. return is_object($EM_Location) ? "location":"locations";
  308. }elseif( is_single() && $post->post_type == EM_POST_TYPE_LOCATION ){
  309. return 'location';
  310. }
  311. if( (!empty($categories_page_id) && $has_post && $post->ID == $categories_page_id) ){
  312. return "categories";
  313. }elseif( is_tax(EM_TAXONOMY_CATEGORY) || !empty($wp_query->em_category_id) || ($has_post && $post->ID == get_option('dbem_categories_page') && !empty($em_category_id)) ){
  314. return "category";
  315. }elseif( is_tax(EM_TAXONOMY_TAG) || !empty($wp_query->em_tag_id) || !empty($em_tag_id) ){
  316. return "tag";
  317. }
  318. }
  319. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement