SimpleCalendarEventsEvent

The Event.

Defined (1)

The class is defined in the following location(s).

/includes/events/event.php  
  1. class Event { 
  2.  
  3. /** 
  4. * Event type. 
  5. * @access public 
  6. * @var string 
  7. */ 
  8. public $type = ''; 
  9.  
  10. /** 
  11. * Event source. 
  12. * @access public 
  13. * @var string 
  14. */ 
  15. public $source = ''; 
  16.  
  17. /** 
  18. * Event title. 
  19. * @access public 
  20. * @var string 
  21. */ 
  22. public $title = ''; 
  23.  
  24. /** 
  25. * Event description. 
  26. * @access public 
  27. * @var string 
  28. */ 
  29. public $description = ''; 
  30.  
  31. /** 
  32. * Event visibility. 
  33. * @access public 
  34. * @var string 
  35. */ 
  36. public $visibility = ''; 
  37.  
  38. /** 
  39. * Event privacy. 
  40. * @access public 
  41. * @var bool 
  42. */ 
  43. public $public = false; 
  44.  
  45. /** 
  46. * Event link URL. 
  47. * @access public 
  48. * @var 
  49. */ 
  50. public $link = ''; 
  51.  
  52. /** 
  53. * Event unique identifier. 
  54. * @access public 
  55. * @var string 
  56. */ 
  57. public $uid = ''; 
  58.  
  59. /** 
  60. * Event iCal ID 
  61. */ 
  62. public $ical_id = ''; 
  63.  
  64. /** 
  65. * Event parent calendar id. 
  66. * @access public 
  67. * @var int 
  68. */ 
  69. public $calendar = 0; 
  70.  
  71. /** 
  72. * Event parent calendar timezone. 
  73. * @access public 
  74. * @var string 
  75. */ 
  76. public $timezone = 'UTC'; 
  77.  
  78. /** 
  79. * Event start time. 
  80. * @access public 
  81. * @var int 
  82. */ 
  83. public $start = 0; 
  84.  
  85. /** 
  86. * Event start time in GMT. 
  87. * @access public 
  88. * @var int 
  89. */ 
  90. public $start_utc = 0; 
  91.  
  92. /** 
  93. * Event start datetime object. 
  94. * @access public 
  95. * @var Carbon 
  96. */ 
  97. public $start_dt = null; 
  98.  
  99. /** 
  100. * Event start time timezone. 
  101. * @access public 
  102. * @var string 
  103. */ 
  104. public $start_timezone = 'UTC'; 
  105.  
  106. /** 
  107. * Event location at event start. 
  108. * @access public 
  109. * @var array 
  110. */ 
  111. public $start_location = false; 
  112.  
  113. /** 
  114. * Event end time. 
  115. * @access public 
  116. * @var false|int 
  117. */ 
  118. public $end = false; 
  119.  
  120. /** 
  121. * Event end time in GMT. 
  122. * @access public 
  123. * @var false|int 
  124. */ 
  125. public $end_utc = false; 
  126.  
  127. /** 
  128. * Event end datetime object. 
  129. * @access public 
  130. * @var null|Carbon 
  131. */ 
  132. public $end_dt = null; 
  133.  
  134. /** 
  135. * Event end time timezone. 
  136. * @access public 
  137. * @var string 
  138. */ 
  139. public $end_timezone = 'UTC'; 
  140.  
  141. /** 
  142. * Event location at event end. 
  143. * @access public 
  144. * @var array 
  145. */ 
  146. public $end_location = false; 
  147.  
  148. /** 
  149. * Event has location. 
  150. * @access public 
  151. * @var bool 
  152. */ 
  153. public $venue = false; 
  154.  
  155. /** 
  156. * Whole day event. 
  157. * @access public 
  158. * @var bool 
  159. */ 
  160. public $whole_day = false; 
  161.  
  162. /** 
  163. * Multiple days span. 
  164. * @access public 
  165. * @var bool|int 
  166. */ 
  167. public $multiple_days = false; 
  168.  
  169. /** 
  170. * Recurring event. 
  171. * @access public 
  172. * @var false|array 
  173. */ 
  174. public $recurrence = false; 
  175.  
  176. /** 
  177. * Event meta. 
  178. * @access public 
  179. * @var array 
  180. */ 
  181. public $meta = array(); 
  182.  
  183. /** 
  184. * Event default template. 
  185. * @access public 
  186. * @var string 
  187. */ 
  188. public $template = ''; 
  189.  
  190. /** 
  191. * Event constructor. 
  192. * @since 3.0.0 
  193. * @param array $event 
  194. */ 
  195. public function __construct( array $event ) { 
  196.  
  197. /** ================= * 
  198. * Event Identifiers * 
  199. * ================= */ 
  200.  
  201. // Event unique id. 
  202. if ( ! empty( $event['uid'] ) ) { 
  203. $this->uid = esc_attr( $event['uid'] ); 
  204.  
  205. // iCal ID 
  206. if ( ! empty( $event['ical_id'] ) ) { 
  207. $this->ical_id = esc_attr( $event['ical_id'] ); 
  208.  
  209. // Event source. 
  210. if ( ! empty( $event['source'] ) ) { 
  211. $this->source = esc_attr( $event['source'] ); 
  212.  
  213. // Event parent calendar id. 
  214. if ( ! empty( $event['calendar'] ) ) { 
  215. $this->calendar = max( intval( $event['calendar'] ), 0 ); 
  216.  
  217. // Event parent calendar timezone. 
  218. if ( ! empty( $event['timezone'] ) ) { 
  219. $this->timezone = esc_attr( $event['timezone'] ); 
  220.  
  221. /** ============= * 
  222. * Event Content * 
  223. * ============= */ 
  224.  
  225. // Event title. 
  226. if ( ! empty( $event['title'] ) ) { 
  227. $this->title = esc_html( $event['title'] ); 
  228.  
  229. // Event description. 
  230. if ( ! empty( $event['description'] ) ) { 
  231. $this->description = wp_kses_post( $event['description'] ); 
  232.  
  233. // Event link URL. 
  234. if ( ! empty( $event['link'] ) ) { 
  235. $this->link = esc_url_raw( $event['link'] ); 
  236.  
  237. // Event visibility. 
  238. if ( ! empty( $event['visibility'] ) ) { 
  239. $this->visibility = esc_attr( $event['visibility'] ); 
  240. $this->public = $this->visibility == 'public' ? true : false; 
  241.  
  242. /** =========== * 
  243. * Event Start * 
  244. * =========== */ 
  245.  
  246. if ( ! empty( $event['start'] ) ) { 
  247. $this->start = is_numeric( $event['start'] ) ? intval( $event['start'] ) : 0; 
  248. if ( ! empty( $event['start_utc'] ) ) { 
  249. $this->start_utc = is_numeric( $event['start_utc'] ) ? intval( $event['start_utc'] ) : 0; 
  250. if ( ! empty( $event['start_timezone'] ) ) { 
  251. $this->start_timezone = esc_attr( $event['start_timezone'] ); 
  252. $this->start_dt = Carbon::createFromTimestamp( $this->start, $this->start_timezone ); 
  253. $start_location = isset( $event['start_location'] ) ? $event['start_location'] : ''; 
  254. $this->start_location = $this->esc_location( $start_location ); 
  255.  
  256. /** ========= * 
  257. * Event End * 
  258. * ========= */ 
  259.  
  260. if ( ! empty( $event['end'] ) ) { 
  261. $this->end = is_numeric( $event['end'] ) ? intval( $event['end'] ): false; 
  262. if ( ! empty( $event['end_utc'] ) ) { 
  263. $this->end_utc = is_numeric( $event['end_utc'] ) ? intval( $event['end_utc'] ) : false; 
  264. if ( ! empty( $event['end_timezone'] ) ) { 
  265. $this->end_timezone = esc_attr( $event['end_timezone'] ); 
  266. $this->end_dt = Carbon::createFromTimestamp( $this->end, $this->end_timezone ); 
  267. $end_location = isset( $event['end_location'] ) ? $event['end_location'] : ''; 
  268. $this->end_location = $this->esc_location( $end_location ); 
  269.  
  270. /** ================== * 
  271. * Event Distribution * 
  272. * ================== */ 
  273.  
  274. // Whole day event. 
  275. if ( ! empty( $event['whole_day'] ) ) { 
  276. $this->whole_day = true === $event['whole_day'] ? true: false; 
  277.  
  278. // Multi day event. 
  279. if ( ! empty( $event['multiple_days'] ) ) { 
  280. $this->multiple_days = max( absint( $event['multiple_days'] ), 1 ); 
  281.  
  282. // Event recurrence. 
  283. if ( isset( $event['recurrence'] ) ) { 
  284. $this->recurrence = ! empty( $event['recurrence'] ) ? $event['recurrence'] : false; 
  285.  
  286. /** ========== * 
  287. * Event Meta * 
  288. * ========== */ 
  289.  
  290. // Event has venue(s). 
  291. if ( $this->start_location['venue'] || $this->end_location['venue'] ) { 
  292. $this->venue = true; 
  293.  
  294. // Event meta. 
  295. if ( ! empty( $event['meta'] ) ) { 
  296. $this->meta = is_array( $event['meta'] ) ? $event['meta'] : array(); 
  297.  
  298. // Event template. 
  299. if ( ! empty( $event['template'] ) ) { 
  300. $this->template = wp_kses_post( $event['template'] ); 
  301.  
  302.  
  303. /** 
  304. * Escape location. 
  305. * @since 3.0.0 
  306. * @access private 
  307. * @param string|array $var 
  308. * @return array 
  309. */ 
  310. private function esc_location( $var = '' ) { 
  311.  
  312. $location = array(); 
  313.  
  314. if ( is_string( $var ) ) { 
  315. $var = array( 
  316. 'name' => $var,  
  317. 'address' => $var,  
  318. ); 
  319. } elseif ( is_bool( $var ) || is_null( $var ) ) { 
  320. $var = array(); 
  321. } else { 
  322. $var = (array) $var; 
  323.  
  324. $location['name'] = isset( $var['name'] ) ? esc_attr( strip_tags( $var['name'] ) ) : ''; 
  325. $location['address'] = isset( $var['address'] ) ? esc_attr( strip_tags( $var['address'] ) ) : ''; 
  326. $location['lat'] = isset( $var['lat'] ) ? $this->esc_coordinate( $var['lat'] ) : 0; 
  327. $location['lng'] = isset( $var['lng'] ) ? $this->esc_coordinate( $var['lng'] ) : 0; 
  328.  
  329. if ( ! empty( $location['name'] ) || ! empty( $location['address'] ) ) { 
  330. $location['venue'] = true; 
  331. } else { 
  332. $location['venue'] = false; 
  333.  
  334. return $location; 
  335.  
  336. /** 
  337. * Escape coordinate. 
  338. * @since 3.0.0 
  339. * @access private 
  340. * @param int|float $latlng 
  341. * @return int|float 
  342. */ 
  343. private function esc_coordinate( $latlng = 0 ) { 
  344. return is_numeric( $latlng ) ? floatval( $latlng ) : 0; 
  345.  
  346. /** 
  347. * Set timezone. 
  348. * @since 3.0.0 
  349. * @access private 
  350. * @param string $tz Timezone. 
  351. * @return bool 
  352. */ 
  353. public function set_timezone( $tz ) { 
  354. if ( in_array( $tz, timezone_identifiers_list() ) ) { 
  355. $this->timezone = $tz; 
  356. return true; 
  357. return false; 
  358.  
  359. /** 
  360. * Starts or ends today. 
  361. * @since 3.0.0 
  362. * @return bool 
  363. */ 
  364. public function is_today() { 
  365. return $this->starts_today() || $this->ends_today(); 
  366.  
  367. /** 
  368. * Starts today. 
  369. * @since 3.0.0 
  370. * @return bool 
  371. */ 
  372. public function starts_today() { 
  373. return $this->start_dt->setTimezone( $this->timezone )->isToday(); 
  374.  
  375. /** 
  376. * Ends today. 
  377. * @since 3.0.0 
  378. * @return bool 
  379. */ 
  380. public function ends_today() { 
  381. return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isToday() : true; 
  382.  
  383. /** 
  384. * Starts tomorrow 
  385. * @since 3.0.0 
  386. * @return bool 
  387. */ 
  388. public function starts_tomorrow() { 
  389. return $this->start_dt->setTimezone( $this->timezone )->isTomorrow(); 
  390.  
  391. /** 
  392. * Ends tomorrow. 
  393. * @since 3.0.0 
  394. * @return bool 
  395. */ 
  396. public function ends_tomorrow() { 
  397. return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isTomorrow() : false; 
  398.  
  399. /** 
  400. * Started yesterday. 
  401. * @since 3.0.0 
  402. * @return bool 
  403. */ 
  404. public function started_yesterday() { 
  405. return $this->start_dt->setTimezone( $this->timezone )->isYesterday(); 
  406.  
  407. /** 
  408. * Ended yesterday. 
  409. * @since 3.0.0 
  410. * @return bool 
  411. */ 
  412. public function ended_yesterday() { 
  413. return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isYesterday() : false; 
  414.  
  415. /** 
  416. * Starts in the future. 
  417. * @since 3.0.0 
  418. * @return bool 
  419. */ 
  420. public function starts_future() { 
  421. return $this->start_dt->setTimezone( $this->timezone )->isFuture(); 
  422.  
  423. /** 
  424. * Ends in the future. 
  425. * @since 3.0.0 
  426. * @return bool 
  427. */ 
  428. public function ends_future() { 
  429. return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isFuture() : false; 
  430.  
  431. /** 
  432. * Started in the past. 
  433. * @since 3.0.0 
  434. * @return bool 
  435. */ 
  436. public function started_past() { 
  437. return $this->start_dt->setTimezone( $this->timezone )->isPast(); 
  438.  
  439. /** 
  440. * Ended in the past. 
  441. * @since 3.0.0 
  442. * @return bool 
  443. */ 
  444. public function ended_past() { 
  445. return ! is_null( $this->end_dt ) ? $this->end_dt->setTimezone( $this->timezone )->isPast() : false; 
  446.  
  447. /** 
  448. * Get color. 
  449. * @since 3.0.0 
  450. * @param string $default 
  451. * @return string 
  452. */ 
  453. public function get_color( $default = '' ) { 
  454. if ( isset( $this->meta['color'] ) ) { 
  455. return ! empty( $this->meta['color'] ) ? esc_attr( $this->meta['color'] ) : $default; 
  456. return $default; 
  457.  
  458. /** 
  459. * Get attachments. 
  460. * @since 3.0.0 
  461. * @return array 
  462. */ 
  463. public function get_attachments() { 
  464. return isset( $this->meta['attachments'] ) ? $this->meta['attachments'] : array(); 
  465.  
  466. /** 
  467. * Get attendees. 
  468. * @since 3.0.0 
  469. * @return array 
  470. */ 
  471. public function get_attendees() { 
  472. return isset( $this->meta['attendees'] ) ? $this->meta['attendees'] : array(); 
  473.  
  474. /** 
  475. * Get organizer. 
  476. * @since 3.0.0 
  477. * @return array 
  478. */ 
  479. public function get_organizer() { 
  480. return isset( $this->meta['organizer'] ) ? $this->meta['organizer'] : array(); 
  481.