em-integration.class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. */
  7. if( !defined( 'ABSPATH') ) exit();
  8. class RevSliderEventsManager {
  9. const DEFAULT_FILTER = "none";
  10. /**
  11. *
  12. * check if events class exists
  13. */
  14. public static function isEventsExists(){
  15. if(defined("EM_VERSION") && defined("EM_PRO_MIN_VERSION"))
  16. return(true);
  17. return(false);
  18. }
  19. /**
  20. *
  21. * get sort by list
  22. */
  23. public static function getArrFilterTypes(){
  24. $arrEventsSort = array("none" => __("All Events",'revslider'),
  25. "today" => __("Today",'revslider'),
  26. "tomorrow"=>__("Tomorrow",'revslider'),
  27. "future"=>__("Future",'revslider'),
  28. "past"=>__("Past",'revslider'),
  29. "month"=>__("This Month",'revslider'),
  30. "nextmonth"=>__("Next Month",'revslider')
  31. );
  32. return($arrEventsSort);
  33. }
  34. /**
  35. *
  36. * get meta query
  37. */
  38. public static function getWPQuery($filterType, $sortBy){
  39. $response = array();
  40. $dayMs = 60*60*24;
  41. $time = current_time('timestamp');
  42. $todayStart = strtotime(date('Y-m-d', $time));
  43. $todayEnd = $todayStart + $dayMs-1;
  44. $tomorrowStart = $todayEnd+1;
  45. $tomorrowEnd = $tomorrowStart + $dayMs-1;
  46. $start_month = strtotime(date('Y-m-1',$time));
  47. $end_month = strtotime(date('Y-m-t',$time)) + 86399;
  48. $next_month_middle = strtotime('+1 month', $time); //get the end of this month + 1 day
  49. $start_next_month = strtotime(date('Y-m-1',$next_month_middle));
  50. $end_next_month = strtotime(date('Y-m-t',$next_month_middle)) + 86399;
  51. $query = array();
  52. switch($filterType){
  53. case self::DEFAULT_FILTER: //none
  54. break;
  55. case "today":
  56. $query[] = array( 'key' => '_start_ts', 'value' => $todayEnd, 'compare' => '<=' );
  57. $query[] = array( 'key' => '_end_ts', 'value' => $todayStart, 'compare' => '>=' );
  58. break;
  59. case "future":
  60. $query[] = array( 'key' => '_start_ts', 'value' => $time, 'compare' => '>' );
  61. break;
  62. case "tomorrow":
  63. $query[] = array( 'key' => '_start_ts', 'value' => $tomorrowEnd, 'compare' => '<=' );
  64. $query[] = array( 'key' => '_end_ts', 'value' => $todayStart, 'compare' => '>=' );
  65. break;
  66. case "past":
  67. $query[] = array( 'key' => '_end_ts', 'value' => $todayStart, 'compare' => '<' );
  68. break;
  69. case "month":
  70. $query[] = array( 'key' => '_start_ts', 'value' => $end_month, 'compare' => '<=' );
  71. $query[] = array( 'key' => '_end_ts', 'value' => $start_month, 'compare' => '>=' );
  72. break;
  73. case "nextmonth":
  74. $query[] = array( 'key' => '_start_ts', 'value' => $end_next_month, 'compare' => '<=' );
  75. $query[] = array( 'key' => '_end_ts', 'value' => $start_next_month, 'compare' => '>=' );
  76. break;
  77. default:
  78. RevSliderFunctions::throwError("Wrong event filter");
  79. break;
  80. }
  81. if(!empty($query))
  82. $response["meta_query"] = $query;
  83. //convert sortby
  84. switch($sortBy){
  85. case "event_start_date":
  86. $response["orderby"] = "meta_value_num";
  87. $response["meta_key"] = "_start_ts";
  88. break;
  89. case "event_end_date":
  90. $response["orderby"] = "meta_value_num";
  91. $response["meta_key"] = "_end_ts";
  92. break;
  93. }
  94. return($response);
  95. }
  96. /**
  97. *
  98. * get event post data in array.
  99. * if the post is not event, return empty array
  100. */
  101. public static function getEventPostData($postID){
  102. if(self::isEventsExists() == false)
  103. return(array());
  104. $postType = get_post_type($postID);
  105. if($postType != EM_POST_TYPE_EVENT)
  106. return(array());
  107. $event = new EM_Event($postID, 'post_id');
  108. $location = $event->get_location();
  109. $arrEvent = $event->to_array();
  110. $arrLocation = $location->to_array();
  111. $date_format = get_option('date_format');
  112. $time_format = get_option('time_format');
  113. $arrEvent["event_start_date"] = date_format(date_create_from_format('Y-m-d', $arrEvent["event_start_date"]), $date_format);
  114. $arrEvent["event_end_date"] = date_format(date_create_from_format('Y-m-d', $arrEvent["event_end_date"]), $date_format);
  115. $arrEvent["event_start_time"] = date_format(date_create_from_format('H:i:s', $arrEvent["event_start_time"]), $time_format);
  116. $arrEvent["event_end_time"] = date_format(date_create_from_format('H:i:s', $arrEvent["event_end_time"]), $time_format);
  117. $response = array();
  118. $response["start_date"] = $arrEvent["event_start_date"];
  119. $response["end_date"] = $arrEvent["event_end_date"];
  120. $response["start_time"] = $arrEvent["event_start_time"];
  121. $response["end_time"] = $arrEvent["event_end_time"];
  122. $response["id"] = $arrEvent["event_id"];
  123. $response["location_name"] = $arrLocation["location_name"];
  124. $response["location_address"] = $arrLocation["location_address"];
  125. $response["location_slug"] = $arrLocation["location_slug"];
  126. $response["location_town"] = $arrLocation["location_town"];
  127. $response["location_state"] = $arrLocation["location_state"];
  128. $response["location_postcode"] = $arrLocation["location_postcode"];
  129. $response["location_region"] = $arrLocation["location_region"];
  130. $response["location_country"] = $arrLocation["location_country"];
  131. $response["location_latitude"] = $arrLocation["location_latitude"];
  132. $response["location_longitude"] = $arrLocation["location_longitude"];
  133. return($response);
  134. }
  135. /**
  136. *
  137. * get events sort by array
  138. */
  139. public static function getArrSortBy(){
  140. $arrSortBy = array();
  141. $arrSortBy["event_start_date"] = __("Event Start Date",'revslider');
  142. $arrSortBy["event_end_date"] = __("Event End Date",'revslider');
  143. return($arrSortBy);
  144. }
  145. }
  146. /**
  147. * old classname extends new one (old classnames will be obsolete soon)
  148. * @since: 5.0
  149. **/
  150. class UniteEmRev extends RevSliderEventsManager {}
  151. ?>