PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 248 lines | 154 code | 17 blank | 77 comment | 37 complexity | 14ebf4fdc672a6ceee93a20e250f8deb MD5 | raw file
  1. <?php
  2. //TODO add a shortcode to link for a specific event, e.g. [event id=x]text[/event]
  3. /**
  4. * Returns the html of an events calendar with events that match given query attributes. Accepts any event query attribute.
  5. * @param array $atts
  6. * @return string
  7. */
  8. function em_get_calendar_shortcode($atts) {
  9. $atts = (array) $atts;
  10. return EM_Calendar::output($atts);
  11. }
  12. add_shortcode('events_calendar', 'em_get_calendar_shortcode');
  13. function em_get_gcal_shortcode($atts){
  14. $img_url = is_ssl() ? 'https://www.google.com/calendar/images/ext/gc_button6.gif':'http://www.google.com/calendar/images/ext/gc_button6.gif';
  15. $atts = shortcode_atts(array('img'=>$img_url, 'button'=>6), $atts);
  16. if( $img_url == $atts['img'] && $atts['button'] != 6 ){
  17. $img_url = str_replace('gc_button6.gif', 'gc_button'.$atts['button'].'.gif', $img_url);
  18. }
  19. $url = '<a href="http://www.google.com/calendar/render?cid='.urlencode(trailingslashit(get_home_url()).'events.ics').'" target="_blank"><img src="'.$img_url.'" alt="0" border="0"></a>';
  20. return $url;
  21. }
  22. add_shortcode('events_gcal', 'em_get_gcal_shortcode');
  23. /**
  24. * Generates a map of locations that match given query attributes. Accepts any location query attributes.
  25. * @param array $args
  26. * @return string
  27. */
  28. function em_get_locations_map_shortcode($args){
  29. $args['width'] = ( !empty($args['width']) ) ? $args['width']:450;
  30. $args['height'] = ( !empty($args['height']) ) ? $args['height']:300;
  31. ob_start();
  32. em_locate_template('templates/map-global.php',true, array('args'=>$args));
  33. return ob_get_clean();
  34. }
  35. add_shortcode('locations_map', 'em_get_locations_map_shortcode');
  36. add_shortcode('locations-map', 'em_get_locations_map_shortcode'); //Depreciate this... confusing for WordPress
  37. /**
  38. * Shows a list of events according to given specifications. Accepts any event query attribute.
  39. * @param array $atts
  40. * @return string
  41. */
  42. function em_get_events_list_shortcode($atts, $format='') {
  43. $atts = (array) $atts;
  44. $atts['format'] = ($format != '' || empty($atts['format'])) ? $format : $atts['format'];
  45. $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html
  46. $atts['page'] = ( !empty($atts['page']) && is_numeric($atts['page']) )? $atts['page'] : 1;
  47. $atts['page'] = ( !empty($_GET['pno']) && is_numeric($_GET['pno']) )? $_GET['pno'] : $atts['page'];
  48. return EM_Events::output( $atts );
  49. }
  50. add_shortcode ( 'events_list', 'em_get_events_list_shortcode' );
  51. /**
  52. * Shows a list of events according to given specifications. Accepts any event query attribute.
  53. * @param array $atts
  54. * @return string
  55. */
  56. function em_get_event_shortcode($atts, $format='') {
  57. global $EM_Event, $post;
  58. $the_event = is_object($EM_Event) ? clone($EM_Event):null; //save global temporarily
  59. $atts = (array) $atts;
  60. $atts['format'] = ($format != '' || empty($atts['format'])) ? $format : $atts['format'];
  61. $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html
  62. if( !empty($atts['event']) && is_numeric($atts['event']) ){
  63. $EM_Event = em_get_event($atts['event']);
  64. $return = ( !empty($atts['format']) ) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
  65. }elseif( !empty($atts['post_id']) && is_numeric($atts['post_id']) ){
  66. $EM_Event = em_get_event($atts['post_id'], 'post_id');
  67. $return = ( !empty($atts['format']) ) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
  68. }
  69. //no specific event or post id supplied, check globals
  70. if( !empty($EM_Event) ){
  71. $return = ( !empty($atts['format']) ) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
  72. }elseif( $post->post_type == EM_POST_TYPE_EVENT ){
  73. $EM_Event = em_get_event($post->ID, 'post_id');
  74. $return = ( !empty($atts['format']) ) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
  75. }
  76. $EM_Event = is_object($the_event) ? $the_event:$EM_Event; //reset global
  77. return $return;
  78. }
  79. add_shortcode ( 'event', 'em_get_event_shortcode' );
  80. /**
  81. * Returns list of locations according to given specifications. Accepts any location query attribute.
  82. */
  83. function em_get_locations_list_shortcode( $atts, $format='' ) {
  84. $atts = (array) $atts;
  85. $atts['format'] = ($format != '' || empty($atts['format'])) ? $format : $atts['format'];
  86. $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html
  87. $atts['page'] = ( !empty($atts['page']) && is_numeric($atts['page']) )? $atts['page'] : 1;
  88. $atts['page'] = ( !empty($_GET['pno']) && is_numeric($_GET['pno']) )? $_GET['pno'] : $atts['page'];
  89. $args['orderby'] = !empty($args['orderby']) ? $args['orderby'] : get_option('dbem_locations_default_orderby');
  90. $args['order'] = !empty($args['order']) ? $args['order'] : get_option('dbem_locations_default_order');
  91. return EM_Locations::output( $atts );
  92. }
  93. add_shortcode('locations_list', 'em_get_locations_list_shortcode');
  94. /**
  95. * Shows a single location according to given specifications. Accepts any event query attribute.
  96. * @param array $atts
  97. * @return string
  98. */
  99. function em_get_location_shortcode($atts, $format='') {
  100. $atts = (array) $atts;
  101. $atts['format'] = ($format != '' || empty($atts['format'])) ? $format : $atts['format'];
  102. $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html
  103. if( !empty($atts['location']) && is_numeric($atts['location']) ){
  104. $EM_Location = em_get_location($atts['location']);
  105. return ( !empty($atts['format']) ) ? $EM_Location->output($atts['format']) : $EM_Location->output_single();
  106. }elseif( !empty($atts['post_id']) && is_numeric($atts['post_id']) ){
  107. $EM_Location = em_get_location($atts['post_id'],'post_id');
  108. return ( !empty($atts['format']) ) ? $EM_Location->output($atts['format']) : $EM_Location->output_single();
  109. }
  110. //no specific location or post id supplied, check globals
  111. global $EM_Location, $post;
  112. if( !empty($EM_Location) ){
  113. return ( !empty($atts['format']) ) ? $EM_Location->output($atts['format']) : $EM_Location->output_single();
  114. }elseif( $post->post_type == EM_POST_TYPE_LOCATION ){
  115. $EM_Location = em_get_location($post->ID,'post_id');
  116. return ( !empty($atts['format']) ) ? $EM_Location->output($atts['format']) : $EM_Location->output_single();
  117. }
  118. }
  119. add_shortcode ( 'location', 'em_get_location_shortcode' );
  120. function em_get_categories_shortcode($args, $format=''){
  121. $args = (array) $args;
  122. $args['format'] = ($format != '' || empty($args['format'])) ? $format : $args['format'];
  123. $args['format'] = html_entity_decode($args['format']); //shorcode doesn't accept html
  124. $args['orderby'] = !empty($args['orderby']) ? $args['orderby'] : get_option('dbem_categories_default_orderby');
  125. $args['order'] = !empty($args['order']) ? $args['order'] : get_option('dbem_categories_default_order');
  126. return EM_Categories::output($args);
  127. }
  128. add_shortcode ( 'categories_list', 'em_get_categories_shortcode' );
  129. /**
  130. * Shows a single location according to given specifications. Accepts any event query attribute.
  131. * @param array $atts
  132. * @return string
  133. */
  134. function em_get_event_category_shortcode($atts, $format='') {
  135. $atts = (array) $atts;
  136. $atts['format'] = ($format != '' || empty($atts['format'])) ? $format : $atts['format'];
  137. $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html
  138. if( !empty($atts['category']) && is_numeric($atts['category']) ){
  139. $EM_Category = new EM_Category($atts['category']);
  140. return ( !empty($atts['format']) ) ? $EM_Category->output($atts['format']) : $EM_Category->output_single();
  141. }elseif( !empty($atts['post_id']) && is_numeric($atts['post_id']) ){
  142. $EM_Category = new EM_Category($atts['post_id'],'post_id');
  143. return ( !empty($atts['format']) ) ? $EM_Category->output($atts['format']) : $EM_Category->output_single();
  144. }
  145. }
  146. add_shortcode ( 'event_category', 'em_get_event_category_shortcode' );
  147. /**
  148. * DO NOT DOCUMENT! This should be replaced with shortcodes events-link and events_uri
  149. * @param array $atts
  150. * @return string
  151. */
  152. function em_get_events_page_shortcode($atts) {
  153. $atts = shortcode_atts ( array ('justurl' => 0, 'text' => '' ), $atts );
  154. if($atts['justurl']){
  155. return EM_URI;
  156. }else{
  157. return em_get_link($atts['text']);
  158. }
  159. }
  160. add_shortcode ( 'events_page', 'em_get_events_page_shortcode' );
  161. /**
  162. * Shortcode for a link to events page. Default will show events page title in link text, if you use [events_link]text[/events_link] 'text' will be the link text
  163. * @param array $atts
  164. * @param string $text
  165. * @return string
  166. */
  167. function em_get_link_shortcode($atts, $text='') {
  168. return em_get_link($text);
  169. }
  170. add_shortcode ( 'events_link', 'em_get_link_shortcode');
  171. /**
  172. * Returns the uri of the events page only
  173. * @return string
  174. */
  175. function em_get_url_shortcode(){
  176. return EM_URI;
  177. }
  178. add_shortcode ( 'events_url', 'em_get_url_shortcode');
  179. /**
  180. * CHANGE DOCUMENTATION! if you just want the url you should use shortcode events_rss_uri
  181. * @param array $atts
  182. * @return string
  183. */
  184. function em_get_rss_link_shortcode($atts) {
  185. $atts = shortcode_atts ( array ('justurl' => 0, 'text' => 'RSS' ), $atts );
  186. if($atts['justurl']){
  187. return EM_RSS_URI;
  188. }else{
  189. return em_get_rss_link($atts['text']);
  190. }
  191. }
  192. add_shortcode ( 'events_rss_link', 'em_get_rss_link_shortcode' );
  193. /**
  194. * Returns the uri of the events rss page only, takes no attributes.
  195. * @return string
  196. */
  197. function em_get_rss_url_shortcode(){
  198. return EM_RSS_URI;
  199. }
  200. add_shortcode ( 'events_rss_url', 'em_get_rss_url_shortcode');
  201. /**
  202. * Creates a form to submit events with
  203. * @param array $atts
  204. * @return string
  205. */
  206. function em_get_event_form_shortcode( $args = array() ){
  207. return em_get_event_form( $args );
  208. }
  209. add_shortcode ( 'event_form', 'em_get_event_form_shortcode');
  210. /**
  211. * Creates a form to search events with
  212. * @param array $atts
  213. * @return string
  214. */
  215. function em_get_event_search_form_shortcode( $args = array() ){
  216. return em_get_event_search_form( $args );
  217. }
  218. add_shortcode ( 'event_search_form', 'em_get_event_search_form_shortcode');
  219. /**
  220. * Creates a grouped list of events by year, month, week or day
  221. * @since 4.213
  222. * @param array $args
  223. * @param string $format
  224. * @return string
  225. */
  226. function em_get_events_list_grouped_shortcode($args = array(), $format = ''){
  227. $args['format'] = ($format != '' || empty($args['format'])) ? $format : $args['format'];
  228. $args['format'] = html_entity_decode($args['format']); //shorcode doesn't accept html
  229. return em_get_events_list_grouped($args);
  230. }
  231. add_shortcode ( 'events_list_grouped', 'em_get_events_list_grouped_shortcode' );