@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use Carbon\Carbon; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @param array $e Events. |
| 46 | 46 | * @param string|\DateTimeZone $tz Timezone. |
| 47 | 47 | */ |
| 48 | - public function __construct( $e = array(), $tz = 'UTC' ) { |
|
| 49 | - $this->set_events( $e ); |
|
| 50 | - $this->set_timezone( $tz ); |
|
| 48 | + public function __construct($e = array(), $tz = 'UTC') { |
|
| 49 | + $this->set_events($e); |
|
| 50 | + $this->set_timezone($tz); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return array |
| 61 | 61 | */ |
| 62 | - public function get_events( $n = '' ) { |
|
| 63 | - if ( ! empty( $n ) && ! empty( $this->events ) ) { |
|
| 64 | - $length = absint( $n ); |
|
| 65 | - return array_slice( $this->events, 0, $length, true ); |
|
| 62 | + public function get_events($n = '') { |
|
| 63 | + if ( ! empty($n) && ! empty($this->events)) { |
|
| 64 | + $length = absint($n); |
|
| 65 | + return array_slice($this->events, 0, $length, true); |
|
| 66 | 66 | } |
| 67 | 67 | return $this->events; |
| 68 | 68 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @param array $ev Events. |
| 76 | 76 | */ |
| 77 | - public function set_events( array $ev ) { |
|
| 77 | + public function set_events(array $ev) { |
|
| 78 | 78 | $this->events = $ev; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @return Events |
| 89 | 89 | */ |
| 90 | - public function set_timezone( $tz ) { |
|
| 91 | - if ( $tz instanceof \DateTimeZone ) { |
|
| 90 | + public function set_timezone($tz) { |
|
| 91 | + if ($tz instanceof \DateTimeZone) { |
|
| 92 | 92 | $tz = $tz->getName(); |
| 93 | 93 | } |
| 94 | - $this->timezone = simcal_esc_timezone( $tz, $this->timezone ); |
|
| 94 | + $this->timezone = simcal_esc_timezone($tz, $this->timezone); |
|
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return Events |
| 106 | 106 | */ |
| 107 | - public function shift( $n ) { |
|
| 108 | - if ( ! empty( $this->events ) ) { |
|
| 109 | - $offset = intval( $n ); |
|
| 110 | - $length = count( $this->events ); |
|
| 111 | - $this->set_events( array_slice( $this->events, $offset, $length, true ) ); |
|
| 107 | + public function shift($n) { |
|
| 108 | + if ( ! empty($this->events)) { |
|
| 109 | + $offset = intval($n); |
|
| 110 | + $length = count($this->events); |
|
| 111 | + $this->set_events(array_slice($this->events, $offset, $length, true)); |
|
| 112 | 112 | } |
| 113 | 113 | return $this; |
| 114 | 114 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return Events |
| 122 | 122 | */ |
| 123 | 123 | public function private_only() { |
| 124 | - $this->set_events( $this->filter_property( 'public', 'hide' ) ); |
|
| 124 | + $this->set_events($this->filter_property('public', 'hide')); |
|
| 125 | 125 | return $this; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return Events |
| 134 | 134 | */ |
| 135 | 135 | public function public_only() { |
| 136 | - $this->set_events( $this->filter_property( 'public', 'show' ) ); |
|
| 136 | + $this->set_events($this->filter_property('public', 'show')); |
|
| 137 | 137 | return $this; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return Events |
| 146 | 146 | */ |
| 147 | 147 | public function recurring() { |
| 148 | - $this->set_events( $this->filter_property( 'recurrence', 'show' ) ); |
|
| 148 | + $this->set_events($this->filter_property('recurrence', 'show')); |
|
| 149 | 149 | return $this; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @return Events |
| 158 | 158 | */ |
| 159 | 159 | public function not_recurring() { |
| 160 | - $this->set_events( $this->filter_property( 'recurrence', 'hide' ) ); |
|
| 160 | + $this->set_events($this->filter_property('recurrence', 'hide')); |
|
| 161 | 161 | return $this; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @return Events |
| 170 | 170 | */ |
| 171 | 171 | public function whole_day() { |
| 172 | - $this->set_events( $this->filter_property( 'whole_day', 'show' ) ); |
|
| 172 | + $this->set_events($this->filter_property('whole_day', 'show')); |
|
| 173 | 173 | return $this; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @return Events |
| 182 | 182 | */ |
| 183 | 183 | public function not_whole_day() { |
| 184 | - $this->set_events( $this->filter_property( 'whole_day', 'hide' ) ); |
|
| 184 | + $this->set_events($this->filter_property('whole_day', 'hide')); |
|
| 185 | 185 | return $this; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return Events |
| 194 | 194 | */ |
| 195 | 195 | public function multi_day() { |
| 196 | - $this->set_events( $this->filter_property( 'multiple_days', 'show' ) ); |
|
| 196 | + $this->set_events($this->filter_property('multiple_days', 'show')); |
|
| 197 | 197 | return $this; |
| 198 | 198 | } |
| 199 | 199 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @return Events |
| 206 | 206 | */ |
| 207 | 207 | public function single_day() { |
| 208 | - $this->set_events( $this->filter_property( 'multiple_days', 'hide' ) ); |
|
| 208 | + $this->set_events($this->filter_property('multiple_days', 'hide')); |
|
| 209 | 209 | return $this; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return Events |
| 218 | 218 | */ |
| 219 | 219 | public function with_location() { |
| 220 | - $this->set_events( $this->filter_property( 'venue', 'show' ) ); |
|
| 220 | + $this->set_events($this->filter_property('venue', 'show')); |
|
| 221 | 221 | return $this; |
| 222 | 222 | } |
| 223 | 223 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @return Events |
| 230 | 230 | */ |
| 231 | 231 | public function without_location() { |
| 232 | - $this->set_events( $this->filter_property( 'venue', 'hide' ) ); |
|
| 232 | + $this->set_events($this->filter_property('venue', 'hide')); |
|
| 233 | 233 | return $this; |
| 234 | 234 | } |
| 235 | 235 | |
@@ -244,18 +244,18 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return array |
| 246 | 246 | */ |
| 247 | - private function filter_property( $property, $toggle ) { |
|
| 247 | + private function filter_property($property, $toggle) { |
|
| 248 | 248 | $filtered = array(); |
| 249 | - if ( ! empty( $this->events ) ) { |
|
| 250 | - foreach ( $this->events as $ts => $events ) { |
|
| 251 | - foreach ( $events as $event ) { |
|
| 252 | - if ( 'hide' == $toggle ) { |
|
| 253 | - if ( ! $event->$property ) { |
|
| 254 | - $filtered[ $ts ][] = $event; |
|
| 249 | + if ( ! empty($this->events)) { |
|
| 250 | + foreach ($this->events as $ts => $events) { |
|
| 251 | + foreach ($events as $event) { |
|
| 252 | + if ('hide' == $toggle) { |
|
| 253 | + if ( ! $event->$property) { |
|
| 254 | + $filtered[$ts][] = $event; |
|
| 255 | 255 | } |
| 256 | - } elseif ( 'show' == $toggle ) { |
|
| 257 | - if ( $event->$property ) { |
|
| 258 | - $filtered[ $ts ][] = $event; |
|
| 256 | + } elseif ('show' == $toggle) { |
|
| 257 | + if ($event->$property) { |
|
| 258 | + $filtered[$ts][] = $event; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -273,14 +273,14 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return Events |
| 275 | 275 | */ |
| 276 | - public function future( $present = '' ) { |
|
| 276 | + public function future($present = '') { |
|
| 277 | 277 | $last = $this->get_last(); |
| 278 | 278 | $to = $last instanceof Event ? $last->start_utc : false; |
| 279 | - if ( $to ) { |
|
| 280 | - if ( empty( $present ) ) { |
|
| 281 | - $present = Carbon::now( $this->timezone )->getTimestamp(); |
|
| 279 | + if ($to) { |
|
| 280 | + if (empty($present)) { |
|
| 281 | + $present = Carbon::now($this->timezone)->getTimestamp(); |
|
| 282 | 282 | } |
| 283 | - $this->set_events( $this->filter_events( intval( $present ), $to ) ); |
|
| 283 | + $this->set_events($this->filter_events(intval($present), $to)); |
|
| 284 | 284 | } |
| 285 | 285 | return $this; |
| 286 | 286 | } |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * |
| 295 | 295 | * @return Events |
| 296 | 296 | */ |
| 297 | - public function past( $present = '' ) { |
|
| 297 | + public function past($present = '') { |
|
| 298 | 298 | $first = $this->get_last(); |
| 299 | 299 | $from = $first instanceof Event ? $first->start_utc : false; |
| 300 | - if ( $from ) { |
|
| 301 | - if ( empty( $present ) ) { |
|
| 302 | - $present = Carbon::now( $this->timezone )->getTimestamp(); |
|
| 300 | + if ($from) { |
|
| 301 | + if (empty($present)) { |
|
| 302 | + $present = Carbon::now($this->timezone)->getTimestamp(); |
|
| 303 | 303 | } |
| 304 | - $this->set_events( $this->filter_events( $from, intval( $present ) ) ); |
|
| 304 | + $this->set_events($this->filter_events($from, intval($present))); |
|
| 305 | 305 | } |
| 306 | 306 | return $this; |
| 307 | 307 | } |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | * |
| 316 | 316 | * @return Events |
| 317 | 317 | */ |
| 318 | - public function after( $time ) { |
|
| 319 | - $dt = $this->parse( $time ); |
|
| 320 | - return ! is_null( $dt ) ? $this->future( $dt->getTimestamp() ) : $this; |
|
| 318 | + public function after($time) { |
|
| 319 | + $dt = $this->parse($time); |
|
| 320 | + return ! is_null($dt) ? $this->future($dt->getTimestamp()) : $this; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return Events |
| 331 | 331 | */ |
| 332 | - public function before( $time ) { |
|
| 333 | - $dt = $this->parse( $time ); |
|
| 334 | - return ! is_null( $dt ) ? $this->past( $dt->getTimestamp() ) : $this; |
|
| 332 | + public function before($time) { |
|
| 333 | + $dt = $this->parse($time); |
|
| 334 | + return ! is_null($dt) ? $this->past($dt->getTimestamp()) : $this; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | * |
| 344 | 344 | * @return Events |
| 345 | 345 | */ |
| 346 | - public function from( $time ) { |
|
| 347 | - $last = $this->parse( $time ); |
|
| 348 | - if ( ! is_null( $last ) ) { |
|
| 349 | - $this->set_events( $this->filter_events( $time, $last->getTimestamp() ) ); |
|
| 346 | + public function from($time) { |
|
| 347 | + $last = $this->parse($time); |
|
| 348 | + if ( ! is_null($last)) { |
|
| 349 | + $this->set_events($this->filter_events($time, $last->getTimestamp())); |
|
| 350 | 350 | } |
| 351 | 351 | return $this; |
| 352 | 352 | } |
@@ -360,10 +360,10 @@ discard block |
||
| 360 | 360 | * |
| 361 | 361 | * @return Events |
| 362 | 362 | */ |
| 363 | - public function to( $time ) { |
|
| 364 | - $first = $this->parse( $time ); |
|
| 365 | - if ( ! is_null( $first ) ) { |
|
| 366 | - $this->set_events( $this->filter_events( $first->getTimestamp(), $time ) ); |
|
| 363 | + public function to($time) { |
|
| 364 | + $first = $this->parse($time); |
|
| 365 | + if ( ! is_null($first)) { |
|
| 366 | + $this->set_events($this->filter_events($first->getTimestamp(), $time)); |
|
| 367 | 367 | } |
| 368 | 368 | return $this; |
| 369 | 369 | } |
@@ -377,15 +377,15 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return null|Carbon |
| 379 | 379 | */ |
| 380 | - private function parse( $time ) { |
|
| 381 | - if ( is_int( $time ) ) { |
|
| 382 | - return Carbon::createFromTimestamp( $time, $this->timezone ); |
|
| 383 | - } elseif ( is_string( $time ) && ! empty( $time ) ) { |
|
| 384 | - return Carbon::parse( $time, $this->timezone ); |
|
| 385 | - } elseif ( $time instanceof Carbon ) { |
|
| 386 | - return $time->setTimezone( $this->timezone ); |
|
| 387 | - } elseif ( $time instanceof \DateTime ) { |
|
| 388 | - return Carbon::instance( $time )->setTimezone( $this->timezone ); |
|
| 380 | + private function parse($time) { |
|
| 381 | + if (is_int($time)) { |
|
| 382 | + return Carbon::createFromTimestamp($time, $this->timezone); |
|
| 383 | + } elseif (is_string($time) && ! empty($time)) { |
|
| 384 | + return Carbon::parse($time, $this->timezone); |
|
| 385 | + } elseif ($time instanceof Carbon) { |
|
| 386 | + return $time->setTimezone($this->timezone); |
|
| 387 | + } elseif ($time instanceof \DateTime) { |
|
| 388 | + return Carbon::instance($time)->setTimezone($this->timezone); |
|
| 389 | 389 | } |
| 390 | 390 | return null; |
| 391 | 391 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @return null|Event |
| 399 | 399 | */ |
| 400 | 400 | public function get_first() { |
| 401 | - return array_shift( $this->events ); |
|
| 401 | + return array_shift($this->events); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | * @return null|Event |
| 410 | 410 | */ |
| 411 | 411 | public function get_last() { |
| 412 | - return array_pop( $this->events ); |
|
| 412 | + return array_pop($this->events); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return null|Event |
| 421 | 421 | */ |
| 422 | 422 | public function get_upcoming() { |
| 423 | - return $this->get_closest( 'future' ); |
|
| 423 | + return $this->get_closest('future'); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @return null|Event |
| 432 | 432 | */ |
| 433 | 433 | public function get_latest() { |
| 434 | - return $this->get_closest( 'past' ); |
|
| 434 | + return $this->get_closest('past'); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -444,11 +444,11 @@ discard block |
||
| 444 | 444 | * |
| 445 | 445 | * @return null|Event |
| 446 | 446 | */ |
| 447 | - private function get_closest( $dir ) { |
|
| 448 | - if ( 'future' == $dir ) { |
|
| 449 | - return array_shift( $this->future()->get_events() ); |
|
| 450 | - } elseif ( 'past' == $dir ) { |
|
| 451 | - return array_shift( $this->past()->get_events() ); |
|
| 447 | + private function get_closest($dir) { |
|
| 448 | + if ('future' == $dir) { |
|
| 449 | + return array_shift($this->future()->get_events()); |
|
| 450 | + } elseif ('past' == $dir) { |
|
| 451 | + return array_shift($this->past()->get_events()); |
|
| 452 | 452 | } |
| 453 | 453 | return null; |
| 454 | 454 | } |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * |
| 463 | 463 | * @return array Multidimensional array with month number, week number and Event objects for each weekday. |
| 464 | 464 | */ |
| 465 | - public function get_year( $year ) { |
|
| 466 | - $y = intval( $year ); |
|
| 465 | + public function get_year($year) { |
|
| 466 | + $y = intval($year); |
|
| 467 | 467 | $months = array(); |
| 468 | - for ( $m = 1; $m <= 12; $m++ ) { |
|
| 469 | - $months[ strval( $m ) ] = $this->get_month( $y, $m ); |
|
| 468 | + for ($m = 1; $m <= 12; $m++) { |
|
| 469 | + $months[strval($m)] = $this->get_month($y, $m); |
|
| 470 | 470 | } |
| 471 | 471 | return $months; |
| 472 | 472 | } |
@@ -481,16 +481,16 @@ discard block |
||
| 481 | 481 | * |
| 482 | 482 | * @return array Multidimensional array with week number, day of the week and array of Event objects for each week day. |
| 483 | 483 | */ |
| 484 | - public function get_month( $year, $month ) { |
|
| 485 | - $y = intval( $year ); |
|
| 486 | - $m = min( max( 1, absint( $month ) ), 12 ); |
|
| 487 | - $days = Carbon::createFromDate( $y, $m, 2, $this->timezone )->startOfMonth()->daysInMonth; |
|
| 484 | + public function get_month($year, $month) { |
|
| 485 | + $y = intval($year); |
|
| 486 | + $m = min(max(1, absint($month)), 12); |
|
| 487 | + $days = Carbon::createFromDate($y, $m, 2, $this->timezone)->startOfMonth()->daysInMonth; |
|
| 488 | 488 | $weeks = array(); |
| 489 | - for ( $d = 1; $d < $days; $d++ ) { |
|
| 490 | - $current = Carbon::createFromDate( $y, $m, $d ); |
|
| 489 | + for ($d = 1; $d < $days; $d++) { |
|
| 490 | + $current = Carbon::createFromDate($y, $m, $d); |
|
| 491 | 491 | $week = $current->weekOfYear; |
| 492 | 492 | $day = $current->dayOfWeek; |
| 493 | - $weeks[ strval( $week ) ][ strval( $day ) ] = $this->get_day( $y, $m, $d ); |
|
| 493 | + $weeks[strval($week)][strval($day)] = $this->get_day($y, $m, $d); |
|
| 494 | 494 | } |
| 495 | 495 | return $weeks; |
| 496 | 496 | } |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | * @return array Associative array with day of the week for key and array of Event objects for value. |
| 507 | 507 | */ |
| 508 | - public function get_week( $year, $week ) { |
|
| 509 | - $y = intval( $year ); |
|
| 510 | - $w = absint( $week ); |
|
| 511 | - $m = date( 'n', strtotime( strval( $y ) . '-W' . strval( $w ) ) ); |
|
| 512 | - $month_dt = Carbon::createFromDate( $y, $m, 2, $this->timezone ); |
|
| 508 | + public function get_week($year, $week) { |
|
| 509 | + $y = intval($year); |
|
| 510 | + $w = absint($week); |
|
| 511 | + $m = date('n', strtotime(strval($y).'-W'.strval($w))); |
|
| 512 | + $month_dt = Carbon::createFromDate($y, $m, 2, $this->timezone); |
|
| 513 | 513 | $days = array(); |
| 514 | - for ( $d = 1; $d < $month_dt->daysInMonth; $d++ ) { |
|
| 515 | - $current = Carbon::createFromDate( $y, $m, $d ); |
|
| 516 | - if ( $w == $current->weekOfYear ) { |
|
| 517 | - $days[ strval( $current->dayOfWeek ) ] = $this->get_day( $y, $m, $d ); |
|
| 514 | + for ($d = 1; $d < $month_dt->daysInMonth; $d++) { |
|
| 515 | + $current = Carbon::createFromDate($y, $m, $d); |
|
| 516 | + if ($w == $current->weekOfYear) { |
|
| 517 | + $days[strval($current->dayOfWeek)] = $this->get_day($y, $m, $d); |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | return $days; |
@@ -531,13 +531,13 @@ discard block |
||
| 531 | 531 | * |
| 532 | 532 | * @return array Event objects for the day. |
| 533 | 533 | */ |
| 534 | - public function get_day( $year, $month, $day ) { |
|
| 535 | - $y = intval( $year ); |
|
| 536 | - $m = min( max( 1, absint( $month ) ), 12 ); |
|
| 537 | - $d = min( absint( $day ), 31 ); |
|
| 538 | - $from = Carbon::createFromDate( $y, $m, $d, $this->timezone )->startOfDay()->getTimestamp(); |
|
| 539 | - $to = Carbon::createFromDate( $y, $m, $d, $this->timezone )->endOfDay()->getTimestamp(); |
|
| 540 | - return $this->filter_events( $from, $to ); |
|
| 534 | + public function get_day($year, $month, $day) { |
|
| 535 | + $y = intval($year); |
|
| 536 | + $m = min(max(1, absint($month)), 12); |
|
| 537 | + $d = min(absint($day), 31); |
|
| 538 | + $from = Carbon::createFromDate($y, $m, $d, $this->timezone)->startOfDay()->getTimestamp(); |
|
| 539 | + $to = Carbon::createFromDate($y, $m, $d, $this->timezone)->endOfDay()->getTimestamp(); |
|
| 540 | + return $this->filter_events($from, $to); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -548,9 +548,9 @@ discard block |
||
| 548 | 548 | * @return array Event objects for today. |
| 549 | 549 | */ |
| 550 | 550 | public function get_today() { |
| 551 | - $start = Carbon::today( $this->timezone )->startOfDay()->getTimestamp(); |
|
| 552 | - $end = Carbon::today( $this->timezone )->endOfDay()->getTimestamp(); |
|
| 553 | - return $this->filter_events( $start, $end ); |
|
| 551 | + $start = Carbon::today($this->timezone)->startOfDay()->getTimestamp(); |
|
| 552 | + $end = Carbon::today($this->timezone)->endOfDay()->getTimestamp(); |
|
| 553 | + return $this->filter_events($start, $end); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -561,9 +561,9 @@ discard block |
||
| 561 | 561 | * @return array Event objects for tomorrow. |
| 562 | 562 | */ |
| 563 | 563 | public function get_tomorrow() { |
| 564 | - $start = Carbon::tomorrow( $this->timezone )->startOfDay()->getTimestamp(); |
|
| 565 | - $end = Carbon::tomorrow( $this->timezone )->endOfDay()->getTimestamp(); |
|
| 566 | - return $this->filter_events( $start, $end ); |
|
| 564 | + $start = Carbon::tomorrow($this->timezone)->startOfDay()->getTimestamp(); |
|
| 565 | + $end = Carbon::tomorrow($this->timezone)->endOfDay()->getTimestamp(); |
|
| 566 | + return $this->filter_events($start, $end); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | * @return array Event objects for yesterday. |
| 575 | 575 | */ |
| 576 | 576 | public function get_yesterday() { |
| 577 | - $start = Carbon::yesterday( $this->timezone )->startOfDay()->getTimestamp(); |
|
| 578 | - $end = Carbon::yesterday( $this->timezone )->endOfDay()->getTimestamp(); |
|
| 579 | - return $this->filter_events( $start, $end ); |
|
| 577 | + $start = Carbon::yesterday($this->timezone)->startOfDay()->getTimestamp(); |
|
| 578 | + $end = Carbon::yesterday($this->timezone)->endOfDay()->getTimestamp(); |
|
| 579 | + return $this->filter_events($start, $end); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -590,16 +590,16 @@ discard block |
||
| 590 | 590 | * |
| 591 | 591 | * @return array Filtered array of Event objects. |
| 592 | 592 | */ |
| 593 | - private function filter_events( $from, $to ) { |
|
| 594 | - $timestamps = array_keys( $this->events ); |
|
| 595 | - $lower_bound = array_filter( $timestamps, function( $ts ) use( $from ) { |
|
| 596 | - return intval( $ts ) > intval( $from ); |
|
| 593 | + private function filter_events($from, $to) { |
|
| 594 | + $timestamps = array_keys($this->events); |
|
| 595 | + $lower_bound = array_filter($timestamps, function($ts) use($from) { |
|
| 596 | + return intval($ts) > intval($from); |
|
| 597 | 597 | } ); |
| 598 | - $higher_bound = array_filter( $lower_bound, function( $ts ) use( $to ) { |
|
| 599 | - return intval( $ts ) > intval( $to ); |
|
| 598 | + $higher_bound = array_filter($lower_bound, function($ts) use($to) { |
|
| 599 | + return intval($ts) > intval($to); |
|
| 600 | 600 | } ); |
| 601 | - $filtered = array_combine( $higher_bound, $higher_bound ); |
|
| 602 | - return array_intersect_key( $this->events, $filtered ); |
|
| 601 | + $filtered = array_combine($higher_bound, $higher_bound); |
|
| 602 | + return array_intersect_key($this->events, $filtered); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | use SimpleCalendar\Admin\Notice; |
| 11 | 11 | use SimpleCalendar\Feeds\Google; |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param string $google_api_key |
| 55 | 55 | * @param string $google_calendar_id |
| 56 | 56 | */ |
| 57 | - public function __construct( Google $feed, $google_api_key, $google_calendar_id ) { |
|
| 57 | + public function __construct(Google $feed, $google_api_key, $google_calendar_id) { |
|
| 58 | 58 | |
| 59 | 59 | $this->feed = $feed; |
| 60 | 60 | $this->google_api_key = $google_api_key; |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $screen = simcal_is_admin_screen(); |
| 64 | 64 | |
| 65 | - if ( 'calendar' == $screen ) { |
|
| 66 | - $this->test_api_key_connection( $this->google_calendar_id ); |
|
| 67 | - add_filter( 'simcal_settings_meta_tabs_li', array( $this, 'add_settings_meta_tab_li' ), 10, 1 ); |
|
| 68 | - add_action( 'simcal_settings_meta_panels', array( $this, 'add_settings_meta_panel' ), 10, 1 ); |
|
| 65 | + if ('calendar' == $screen) { |
|
| 66 | + $this->test_api_key_connection($this->google_calendar_id); |
|
| 67 | + add_filter('simcal_settings_meta_tabs_li', array($this, 'add_settings_meta_tab_li'), 10, 1); |
|
| 68 | + add_action('simcal_settings_meta_panels', array($this, 'add_settings_meta_panel'), 10, 1); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - add_action( 'simcal_process_settings_meta', array( $this, 'process_meta' ), 10, 1 ); |
|
| 71 | + add_action('simcal_process_settings_meta', array($this, 'process_meta'), 10, 1); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -81,20 +81,20 @@ discard block |
||
| 81 | 81 | public function settings_fields() { |
| 82 | 82 | return array( |
| 83 | 83 | 'name' => $this->feed->name, |
| 84 | - 'description' => __( "To read events from your public Google Calendars you'll need create a Google API key and save it here.", 'google-calendar-events' ) . |
|
| 85 | - '<br/><br/>' . |
|
| 86 | - '<em style="font-size: 14px;">' . |
|
| 87 | - sprintf( __( '<strong>Note:</strong> A Google API key is not needed for calendars configured to use the <strong><a href="%s" target="_blank">Google Calendar Pro add-on</a></strong>.', 'google-calendar-events' ), |
|
| 88 | - simcal_ga_campaign_url( simcal_get_url( 'gcal-pro' ), 'core-plugin', 'settings-link' ) |
|
| 89 | - ) . |
|
| 84 | + 'description' => __("To read events from your public Google Calendars you'll need create a Google API key and save it here.", 'google-calendar-events'). |
|
| 85 | + '<br/><br/>'. |
|
| 86 | + '<em style="font-size: 14px;">'. |
|
| 87 | + sprintf(__('<strong>Note:</strong> A Google API key is not needed for calendars configured to use the <strong><a href="%s" target="_blank">Google Calendar Pro add-on</a></strong>.', 'google-calendar-events'), |
|
| 88 | + simcal_ga_campaign_url(simcal_get_url('gcal-pro'), 'core-plugin', 'settings-link') |
|
| 89 | + ). |
|
| 90 | 90 | '</em>', |
| 91 | 91 | 'fields' => array( |
| 92 | 92 | 'api_key' => array( |
| 93 | 93 | 'type' => 'standard', |
| 94 | 94 | 'subtype' => 'text', |
| 95 | - 'class' => array( 'simcal-wide-text regular-text', 'ltr' ), |
|
| 96 | - 'title' => __( 'Google API Key', 'google-calendar-events' ), |
|
| 97 | - 'validation' => array( $this, 'check_google_api_key' ), |
|
| 95 | + 'class' => array('simcal-wide-text regular-text', 'ltr'), |
|
| 96 | + 'title' => __('Google API Key', 'google-calendar-events'), |
|
| 97 | + 'validation' => array($this, 'check_google_api_key'), |
|
| 98 | 98 | ), |
| 99 | 99 | ), |
| 100 | 100 | ); |
@@ -113,27 +113,27 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return true|string |
| 115 | 115 | */ |
| 116 | - public function check_google_api_key( $api_key = '' ) { |
|
| 116 | + public function check_google_api_key($api_key = '') { |
|
| 117 | 117 | |
| 118 | 118 | $message = ''; |
| 119 | 119 | $has_errors = false; |
| 120 | 120 | |
| 121 | - if ( empty( $api_key ) ){ |
|
| 121 | + if (empty($api_key)) { |
|
| 122 | 122 | $api_key = $this->google_api_key; |
| 123 | - if ( empty( $api_key ) ) { |
|
| 124 | - $settings = get_option( 'simple-calendar_settings_feeds' ); |
|
| 125 | - $api_key = isset( $settings['google']['api_key'] ) ? esc_attr( $settings['google']['api_key'] ) : ''; |
|
| 123 | + if (empty($api_key)) { |
|
| 124 | + $settings = get_option('simple-calendar_settings_feeds'); |
|
| 125 | + $api_key = isset($settings['google']['api_key']) ? esc_attr($settings['google']['api_key']) : ''; |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $message = '<p class="description">' . |
|
| 130 | - sprintf( __( '<a href="%s" target="_blank">Step-by-step instructions</a> ', 'google-calendar-events' ), |
|
| 131 | - simcal_ga_campaign_url( simcal_get_url( 'docs' ) . '/google-api-key/', 'core-plugin', 'settings-link' ) |
|
| 132 | - ) . |
|
| 133 | - '<br/>' . |
|
| 134 | - sprintf( __( '<a href="%s" target="_blank">Google Developers Console</a> ', 'google-calendar-events' ), |
|
| 135 | - simcal_get_url( 'gdev-console' ) |
|
| 136 | - ) . |
|
| 129 | + $message = '<p class="description">'. |
|
| 130 | + sprintf(__('<a href="%s" target="_blank">Step-by-step instructions</a> ', 'google-calendar-events'), |
|
| 131 | + simcal_ga_campaign_url(simcal_get_url('docs').'/google-api-key/', 'core-plugin', 'settings-link') |
|
| 132 | + ). |
|
| 133 | + '<br/>'. |
|
| 134 | + sprintf(__('<a href="%s" target="_blank">Google Developers Console</a> ', 'google-calendar-events'), |
|
| 135 | + simcal_get_url('gdev-console') |
|
| 136 | + ). |
|
| 137 | 137 | '</p>'; |
| 138 | 138 | |
| 139 | 139 | return $message; |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - public function add_settings_meta_tab_li( $tabs ) { |
|
| 152 | - return array_merge( $tabs, array( |
|
| 151 | + public function add_settings_meta_tab_li($tabs) { |
|
| 152 | + return array_merge($tabs, array( |
|
| 153 | 153 | 'google' => array( |
| 154 | 154 | 'label' => $this->feed->name, |
| 155 | 155 | 'target' => 'google-settings-panel', |
| 156 | - 'class' => array( 'simcal-feed-type', 'simcal-feed-type-google' ), |
|
| 156 | + 'class' => array('simcal-feed-type', 'simcal-feed-type-google'), |
|
| 157 | 157 | 'icon' => 'simcal-icon-google', |
| 158 | 158 | ), |
| 159 | - ) ); |
|
| 159 | + )); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @param int $post_id |
| 168 | 168 | */ |
| 169 | - public function add_settings_meta_panel( $post_id ) { |
|
| 169 | + public function add_settings_meta_panel($post_id) { |
|
| 170 | 170 | |
| 171 | 171 | $inputs = array( |
| 172 | 172 | $this->feed->type => array( |
@@ -175,30 +175,30 @@ discard block |
||
| 175 | 175 | 'subtype' => 'text', |
| 176 | 176 | 'name' => '_google_calendar_id', |
| 177 | 177 | 'id' => '_google_calendar_id', |
| 178 | - 'title' => __( 'Calendar ID', 'google-calendar-events' ), |
|
| 179 | - 'tooltip' => __( 'Visit your Google Calendar account, copy your public calendar ID, then paste it here.', 'google-calendar-events' ), |
|
| 180 | - 'placeholder' => __( 'Enter a valid Google Calendar ID from a public calendar', 'google-calendar-events' ), |
|
| 181 | - 'escaping' => array( $this->feed, 'esc_google_calendar_id' ), |
|
| 182 | - 'validation' => array( $this, 'test_api_key_connection' ), |
|
| 178 | + 'title' => __('Calendar ID', 'google-calendar-events'), |
|
| 179 | + 'tooltip' => __('Visit your Google Calendar account, copy your public calendar ID, then paste it here.', 'google-calendar-events'), |
|
| 180 | + 'placeholder' => __('Enter a valid Google Calendar ID from a public calendar', 'google-calendar-events'), |
|
| 181 | + 'escaping' => array($this->feed, 'esc_google_calendar_id'), |
|
| 182 | + 'validation' => array($this, 'test_api_key_connection'), |
|
| 183 | 183 | ), |
| 184 | 184 | '_google_events_search_query' => array( |
| 185 | 185 | 'type' => 'standard', |
| 186 | 186 | 'subtype' => 'text', |
| 187 | 187 | 'name' => '_google_events_search_query', |
| 188 | 188 | 'id' => '_google_events_search_query', |
| 189 | - 'title' => __( 'Search query', 'google-calendar-events' ), |
|
| 190 | - 'tooltip' => __( 'Type in keywords if you only want display events that match these terms. You can use basic boolean search operators too.', 'google-calendar-events' ), |
|
| 191 | - 'placeholder' => __( 'Filter events to display by search terms...', 'google-calendar-events' ), |
|
| 189 | + 'title' => __('Search query', 'google-calendar-events'), |
|
| 190 | + 'tooltip' => __('Type in keywords if you only want display events that match these terms. You can use basic boolean search operators too.', 'google-calendar-events'), |
|
| 191 | + 'placeholder' => __('Filter events to display by search terms...', 'google-calendar-events'), |
|
| 192 | 192 | ), |
| 193 | 193 | '_google_events_recurring' => array( |
| 194 | 194 | 'type' => 'select', |
| 195 | 195 | 'name' => '_google_events_recurring', |
| 196 | 196 | 'id' => '_google_events_recurring', |
| 197 | - 'title' => __( 'Recurring events', 'google-calendar-events' ), |
|
| 198 | - 'tooltip' => __( 'Events that are programmed to repeat themselves periodically.', 'google-calendar-events' ), |
|
| 197 | + 'title' => __('Recurring events', 'google-calendar-events'), |
|
| 198 | + 'tooltip' => __('Events that are programmed to repeat themselves periodically.', 'google-calendar-events'), |
|
| 199 | 199 | 'options' => array( |
| 200 | - 'show' => __( 'Show all', 'google-calendar-events' ), |
|
| 201 | - 'first-only' => __( 'Only show first occurrence', 'google-calendar-events' ), |
|
| 200 | + 'show' => __('Show all', 'google-calendar-events'), |
|
| 201 | + 'first-only' => __('Only show first occurrence', 'google-calendar-events'), |
|
| 202 | 202 | ), |
| 203 | 203 | ), |
| 204 | 204 | '_google_events_max_results' => array( |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | 'subtype' => 'number', |
| 207 | 207 | 'name' => '_google_events_max_results', |
| 208 | 208 | 'id' => '_google_events_max_results', |
| 209 | - 'title' => __( 'Maximum Events', 'google-calendar-events' ), |
|
| 210 | - 'tooltip' => __( 'Google Calendar only allows to query for a maximum amount of 2500 events from a calendar each time.', 'google-calendar-events' ), |
|
| 209 | + 'title' => __('Maximum Events', 'google-calendar-events'), |
|
| 210 | + 'tooltip' => __('Google Calendar only allows to query for a maximum amount of 2500 events from a calendar each time.', 'google-calendar-events'), |
|
| 211 | 211 | 'class' => array( |
| 212 | 212 | 'simcal-field-small', |
| 213 | 213 | ), |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | <div id="google-settings-panel" class="simcal-panel"> |
| 225 | 225 | <table> |
| 226 | 226 | <thead> |
| 227 | - <tr><th colspan="2"><?php _e( 'Google Calendar settings', 'google-calendar-events' ); ?></th></tr> |
|
| 227 | + <tr><th colspan="2"><?php _e('Google Calendar settings', 'google-calendar-events'); ?></th></tr> |
|
| 228 | 228 | </thead> |
| 229 | - <?php Settings::print_panel_fields( $inputs, $post_id ); ?> |
|
| 229 | + <?php Settings::print_panel_fields($inputs, $post_id); ?> |
|
| 230 | 230 | </table> |
| 231 | 231 | </div> |
| 232 | 232 | <?php |
@@ -242,47 +242,47 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @return true|string |
| 244 | 244 | */ |
| 245 | - public function test_api_key_connection( $google_calendar_id ) { |
|
| 245 | + public function test_api_key_connection($google_calendar_id) { |
|
| 246 | 246 | |
| 247 | 247 | global $post; |
| 248 | 248 | |
| 249 | - $post_id = isset( $post->ID ) ? $post->ID : 0; |
|
| 249 | + $post_id = isset($post->ID) ? $post->ID : 0; |
|
| 250 | 250 | $feed = null; |
| 251 | - if ( $feed_type = wp_get_object_terms( $post_id, 'calendar_feed' ) ) { |
|
| 252 | - $feed = sanitize_title( current( $feed_type )->name ); |
|
| 251 | + if ($feed_type = wp_get_object_terms($post_id, 'calendar_feed')) { |
|
| 252 | + $feed = sanitize_title(current($feed_type)->name); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $message = ''; |
| 256 | 256 | $error = ''; |
| 257 | 257 | $has_errors = false; |
| 258 | 258 | |
| 259 | - $message .= '<p class="description">' . |
|
| 259 | + $message .= '<p class="description">'. |
|
| 260 | 260 | sprintf( |
| 261 | - __( 'Step 1: Set the Google Calendar you want to use as <strong>"public."</strong> <a href="%1s" target="_blank">Detailed instructions</a>', 'google-calendar-events' ) . '<br />' . |
|
| 262 | - __( 'Step 2: Copy and paste your Google Calendar ID here. <a href="%2s" target="_blank">Detailed instructions</a>', 'google-calendar-events' ), |
|
| 263 | - simcal_ga_campaign_url( simcal_get_url( 'docs' ) . '/make-google-calendar-public/', 'core-plugin', 'settings-link' ), |
|
| 264 | - simcal_ga_campaign_url( simcal_get_url( 'docs' ) . '/find-google-calendar-id/', 'core-plugin', 'settings-link' ) |
|
| 265 | - ) . '</p>'; |
|
| 261 | + __('Step 1: Set the Google Calendar you want to use as <strong>"public."</strong> <a href="%1s" target="_blank">Detailed instructions</a>', 'google-calendar-events').'<br />'. |
|
| 262 | + __('Step 2: Copy and paste your Google Calendar ID here. <a href="%2s" target="_blank">Detailed instructions</a>', 'google-calendar-events'), |
|
| 263 | + simcal_ga_campaign_url(simcal_get_url('docs').'/make-google-calendar-public/', 'core-plugin', 'settings-link'), |
|
| 264 | + simcal_ga_campaign_url(simcal_get_url('docs').'/find-google-calendar-id/', 'core-plugin', 'settings-link') |
|
| 265 | + ).'</p>'; |
|
| 266 | 266 | |
| 267 | - if ( $post_id > 0 && ! is_null( $feed ) && ! empty( $this->feed->type ) ) { |
|
| 267 | + if ($post_id > 0 && ! is_null($feed) && ! empty($this->feed->type)) { |
|
| 268 | 268 | |
| 269 | - $no_key_notice = new Notice( array( |
|
| 270 | - 'id' => array( 'calendar_' . $post_id => 'google-no-api-key' ), |
|
| 269 | + $no_key_notice = new Notice(array( |
|
| 270 | + 'id' => array('calendar_'.$post_id => 'google-no-api-key'), |
|
| 271 | 271 | 'type' => 'error', |
| 272 | 272 | 'screen' => 'calendar', |
| 273 | 273 | 'post' => $post_id, |
| 274 | 274 | 'dismissable' => false, |
| 275 | - 'content' => '<p>' . |
|
| 276 | - '<i class="simcal-icon-warning"></i> ' . |
|
| 275 | + 'content' => '<p>'. |
|
| 276 | + '<i class="simcal-icon-warning"></i> '. |
|
| 277 | 277 | sprintf( |
| 278 | - __( 'Your Google Calendar events will not show up until you <a href="%s">create and save a Google API key</a>.', 'google-calendar-events' ), |
|
| 279 | - admin_url( 'edit.php?post_type=calendar&page=simple-calendar_settings&tab=feeds' ) |
|
| 280 | - ) . |
|
| 278 | + __('Your Google Calendar events will not show up until you <a href="%s">create and save a Google API key</a>.', 'google-calendar-events'), |
|
| 279 | + admin_url('edit.php?post_type=calendar&page=simple-calendar_settings&tab=feeds') |
|
| 280 | + ). |
|
| 281 | 281 | '</p>', |
| 282 | 282 | ) |
| 283 | 283 | ); |
| 284 | 284 | |
| 285 | - if ( empty( $this->google_api_key ) && ( $feed == $this->feed->type ) ) { |
|
| 285 | + if (empty($this->google_api_key) && ($feed == $this->feed->type)) { |
|
| 286 | 286 | |
| 287 | 287 | $has_errors = true; |
| 288 | 288 | $no_key_notice->add(); |
@@ -292,28 +292,28 @@ discard block |
||
| 292 | 292 | $no_key_notice->remove(); |
| 293 | 293 | |
| 294 | 294 | try { |
| 295 | - $this->feed->make_request( $google_calendar_id ); |
|
| 296 | - } catch ( \Exception $e ) { |
|
| 295 | + $this->feed->make_request($google_calendar_id); |
|
| 296 | + } catch (\Exception $e) { |
|
| 297 | 297 | $error = $e->getMessage(); |
| 298 | - $message = ! empty( $error ) ? '<blockquote>' . $error . '</blockquote>' : ''; |
|
| 298 | + $message = ! empty($error) ? '<blockquote>'.$error.'</blockquote>' : ''; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $error_notice = new Notice( array( |
|
| 302 | - 'id' => array( 'calendar_' . $post_id => 'google-error-response' ), |
|
| 301 | + $error_notice = new Notice(array( |
|
| 302 | + 'id' => array('calendar_'.$post_id => 'google-error-response'), |
|
| 303 | 303 | 'type' => 'error', |
| 304 | 304 | 'screen' => 'calendar', |
| 305 | 305 | 'post' => $post_id, |
| 306 | 306 | 'dismissable' => false, |
| 307 | - 'content' => '<p>' . |
|
| 308 | - '<i class="simcal-icon-warning"></i> ' . |
|
| 309 | - __( 'While trying to retrieve events, Google returned an error:', 'google-calendar-events' ) . |
|
| 310 | - '<br>' . $message . '<br>' . |
|
| 311 | - __( 'Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events' ) . |
|
| 307 | + 'content' => '<p>'. |
|
| 308 | + '<i class="simcal-icon-warning"></i> '. |
|
| 309 | + __('While trying to retrieve events, Google returned an error:', 'google-calendar-events'). |
|
| 310 | + '<br>'.$message.'<br>'. |
|
| 311 | + __('Please ensure that both your Google Calendar ID and API Key are valid and that the Google Calendar you want to display is public.', 'google-calendar-events'). |
|
| 312 | 312 | '</p>', |
| 313 | 313 | ) |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - if ( ! empty( $error ) && ( $feed == $this->feed->type ) ) { |
|
| 316 | + if ( ! empty($error) && ($feed == $this->feed->type)) { |
|
| 317 | 317 | $error_notice->add(); |
| 318 | 318 | $has_errors = true; |
| 319 | 319 | } else { |
@@ -335,21 +335,21 @@ discard block |
||
| 335 | 335 | * |
| 336 | 336 | * @param int $post_id |
| 337 | 337 | */ |
| 338 | - public function process_meta( $post_id ) { |
|
| 338 | + public function process_meta($post_id) { |
|
| 339 | 339 | |
| 340 | - $calendar_id = isset( $_POST['_google_calendar_id'] ) ? base64_encode( trim( $_POST['_google_calendar_id'] ) ): ''; |
|
| 341 | - update_post_meta( $post_id, '_google_calendar_id', $calendar_id ); |
|
| 340 | + $calendar_id = isset($_POST['_google_calendar_id']) ? base64_encode(trim($_POST['_google_calendar_id'])) : ''; |
|
| 341 | + update_post_meta($post_id, '_google_calendar_id', $calendar_id); |
|
| 342 | 342 | |
| 343 | - $search_query = isset( $_POST['_google_events_search_query'] ) ? sanitize_text_field( $_POST['_google_events_search_query'] ) : ''; |
|
| 344 | - update_post_meta( $post_id, '_google_events_search_query', $search_query ); |
|
| 343 | + $search_query = isset($_POST['_google_events_search_query']) ? sanitize_text_field($_POST['_google_events_search_query']) : ''; |
|
| 344 | + update_post_meta($post_id, '_google_events_search_query', $search_query); |
|
| 345 | 345 | |
| 346 | - $recurring = isset( $_POST['_google_events_recurring'] ) ? sanitize_key( $_POST['_google_events_recurring'] ) : 'show'; |
|
| 347 | - update_post_meta( $post_id, '_google_events_recurring', $recurring ); |
|
| 346 | + $recurring = isset($_POST['_google_events_recurring']) ? sanitize_key($_POST['_google_events_recurring']) : 'show'; |
|
| 347 | + update_post_meta($post_id, '_google_events_recurring', $recurring); |
|
| 348 | 348 | |
| 349 | - $max_results = isset( $_POST['_google_events_max_results'] ) ? absint( $_POST['_google_events_max_results'] ) : '2500'; |
|
| 350 | - update_post_meta( $post_id, '_google_events_max_results', $max_results ); |
|
| 349 | + $max_results = isset($_POST['_google_events_max_results']) ? absint($_POST['_google_events_max_results']) : '2500'; |
|
| 350 | + update_post_meta($post_id, '_google_events_max_results', $max_results); |
|
| 351 | 351 | |
| 352 | - $this->test_api_key_connection( $calendar_id ); |
|
| 352 | + $this->test_api_key_connection($calendar_id); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use SimpleCalendar\Feeds\Grouped_Calendars; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -34,15 +34,15 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param Grouped_Calendars $feed |
| 36 | 36 | */ |
| 37 | - public function __construct( Grouped_Calendars $feed ) { |
|
| 37 | + public function __construct(Grouped_Calendars $feed) { |
|
| 38 | 38 | |
| 39 | 39 | $this->feed = $feed; |
| 40 | 40 | |
| 41 | - if ( 'calendar' == simcal_is_admin_screen() ) { |
|
| 42 | - add_filter( 'simcal_settings_meta_tabs_li', array( $this, 'add_settings_meta_tab_li' ), 10, 1 ); |
|
| 43 | - add_action( 'simcal_settings_meta_panels', array( $this, 'add_settings_meta_panel' ), 10, 1 ); |
|
| 41 | + if ('calendar' == simcal_is_admin_screen()) { |
|
| 42 | + add_filter('simcal_settings_meta_tabs_li', array($this, 'add_settings_meta_tab_li'), 10, 1); |
|
| 43 | + add_action('simcal_settings_meta_panels', array($this, 'add_settings_meta_panel'), 10, 1); |
|
| 44 | 44 | } |
| 45 | - add_action( 'simcal_process_settings_meta', array( $this, 'process_meta' ), 10, 1 ); |
|
| 45 | + add_action('simcal_process_settings_meta', array($this, 'process_meta'), 10, 1); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - public function add_settings_meta_tab_li( $tabs ) { |
|
| 58 | - return array_merge( $tabs, array( |
|
| 57 | + public function add_settings_meta_tab_li($tabs) { |
|
| 58 | + return array_merge($tabs, array( |
|
| 59 | 59 | 'grouped-calendars' => array( |
| 60 | 60 | 'label' => $this->feed->name, |
| 61 | 61 | 'target' => 'grouped-calendars-settings-panel', |
@@ -75,40 +75,40 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @param int $post_id |
| 77 | 77 | */ |
| 78 | - public function add_settings_meta_panel( $post_id ) { |
|
| 78 | + public function add_settings_meta_panel($post_id) { |
|
| 79 | 79 | |
| 80 | 80 | ?> |
| 81 | 81 | <div id="grouped-calendars-settings-panel" class="simcal-panel"> |
| 82 | 82 | <table> |
| 83 | 83 | <thead> |
| 84 | - <tr><th colspan="2"><?php _e( 'Grouped Calendar settings', 'google-calendar-events' ); ?></th></tr> |
|
| 84 | + <tr><th colspan="2"><?php _e('Grouped Calendar settings', 'google-calendar-events'); ?></th></tr> |
|
| 85 | 85 | </thead> |
| 86 | 86 | <tbody class="simcal-panel-section"> |
| 87 | 87 | <tr class="simcal-panel-field"> |
| 88 | - <th><label for="_grouped_calendars_source"><?php _e( 'Get calendars from', 'google-calendar-events' ); ?></label></th> |
|
| 88 | + <th><label for="_grouped_calendars_source"><?php _e('Get calendars from', 'google-calendar-events'); ?></label></th> |
|
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | 91 | |
| 92 | - $source = esc_attr( get_post_meta( $post_id, '_grouped_calendars_source', true ) ); |
|
| 93 | - $source = empty( $source ) ? 'ids' : $source; |
|
| 92 | + $source = esc_attr(get_post_meta($post_id, '_grouped_calendars_source', true)); |
|
| 93 | + $source = empty($source) ? 'ids' : $source; |
|
| 94 | 94 | |
| 95 | 95 | ?> |
| 96 | 96 | <select name="_grouped_calendars_source" |
| 97 | 97 | id="_grouped_calendars_source" |
| 98 | 98 | class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" |
| 99 | 99 | data-show-field-on-choice="true"> |
| 100 | - <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected( 'ids', $source, true ); ?>><?php _e( 'Manual selection', 'google-calendar-events' ); ?></option> |
|
| 101 | - <option value="category" data-show-field="_grouped_calendars_category" <?php selected( 'category', $source, true ); ?>><?php _e( 'Category', 'google-calendar-events' ); ?></option> |
|
| 100 | + <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected('ids', $source, true); ?>><?php _e('Manual selection', 'google-calendar-events'); ?></option> |
|
| 101 | + <option value="category" data-show-field="_grouped_calendars_category" <?php selected('category', $source, true); ?>><?php _e('Category', 'google-calendar-events'); ?></option> |
|
| 102 | 102 | </select> |
| 103 | - <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events' ); ?>"></i> |
|
| 103 | + <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e('Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events'); ?>"></i> |
|
| 104 | 104 | <br><br> |
| 105 | 105 | <?php |
| 106 | 106 | |
| 107 | - $cals = simcal_get_calendars( $post_id ); |
|
| 108 | - $meta = get_post_meta( $post_id, '_grouped_calendars_ids', true ); |
|
| 109 | - $ids = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ) : absint( $meta ); |
|
| 107 | + $cals = simcal_get_calendars($post_id); |
|
| 108 | + $meta = get_post_meta($post_id, '_grouped_calendars_ids', true); |
|
| 109 | + $ids = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : absint($meta); |
|
| 110 | 110 | |
| 111 | - simcal_print_field( array( |
|
| 111 | + simcal_print_field(array( |
|
| 112 | 112 | 'type' => 'select', |
| 113 | 113 | 'multiselect' => 'multiselect', |
| 114 | 114 | 'name' => '_grouped_calendars_ids', |
@@ -116,25 +116,25 @@ discard block |
||
| 116 | 116 | 'value' => $ids !== 0 ? $ids : '', |
| 117 | 117 | 'options' => $cals, |
| 118 | 118 | 'enhanced' => 'enhanced', |
| 119 | - 'style' => 'ids' == $source ? '' : array( 'display' => 'none' ), |
|
| 119 | + 'style' => 'ids' == $source ? '' : array('display' => 'none'), |
|
| 120 | 120 | 'attributes' => array( |
| 121 | - 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
|
| 121 | + 'data-noresults' => __('No results found.', 'google-calendar-events'), |
|
| 122 | 122 | ), |
| 123 | 123 | )); |
| 124 | 124 | |
| 125 | - $meta = get_post_meta( $post_id, '_grouped_calendars_category', true ); |
|
| 126 | - $category = $meta && is_array( $meta ) ? implode( ',', array_map( 'absint', $meta ) ): ''; |
|
| 125 | + $meta = get_post_meta($post_id, '_grouped_calendars_category', true); |
|
| 126 | + $category = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : ''; |
|
| 127 | 127 | |
| 128 | - $terms = get_terms( 'calendar_category' ); |
|
| 128 | + $terms = get_terms('calendar_category'); |
|
| 129 | 129 | |
| 130 | - if ( ! empty( $terms ) ) { |
|
| 130 | + if ( ! empty($terms)) { |
|
| 131 | 131 | |
| 132 | 132 | $categories = array(); |
| 133 | - foreach ( $terms as $term ) { |
|
| 134 | - $categories[ $term->term_id ] = $term->name; |
|
| 133 | + foreach ($terms as $term) { |
|
| 134 | + $categories[$term->term_id] = $term->name; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - simcal_print_field( array( |
|
| 137 | + simcal_print_field(array( |
|
| 138 | 138 | 'type' => 'select', |
| 139 | 139 | 'multiselect' => 'multiselect', |
| 140 | 140 | 'name' => '_grouped_calendars_category', |
@@ -142,17 +142,17 @@ discard block |
||
| 142 | 142 | 'value' => $category, |
| 143 | 143 | 'options' => $categories, |
| 144 | 144 | 'enhanced' => 'enhanced', |
| 145 | - 'style' => 'category' == $source ? '' : array( 'display' => 'none' ), |
|
| 145 | + 'style' => 'category' == $source ? '' : array('display' => 'none'), |
|
| 146 | 146 | 'attributes' => array( |
| 147 | - 'data-noresults' => __( 'No results found.', 'google-calendar-events' ), |
|
| 147 | + 'data-noresults' => __('No results found.', 'google-calendar-events'), |
|
| 148 | 148 | ), |
| 149 | - ) ); |
|
| 149 | + )); |
|
| 150 | 150 | |
| 151 | 151 | } else { |
| 152 | 152 | |
| 153 | 153 | $style = 'category' == $source ? '' : 'display: none;'; |
| 154 | 154 | $style .= ' width: 100%; max-width: 500px'; |
| 155 | - echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="' . $style . '" placeholder="' . __( 'There are no calendar categories yet.', 'google-calendar-events' ) . '" />'; |
|
| 155 | + echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="'.$style.'" placeholder="'.__('There are no calendar categories yet.', 'google-calendar-events').'" />'; |
|
| 156 | 156 | |
| 157 | 157 | } |
| 158 | 158 | |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param int $post_id |
| 175 | 175 | */ |
| 176 | - public function process_meta( $post_id ) { |
|
| 176 | + public function process_meta($post_id) { |
|
| 177 | 177 | |
| 178 | - $source = isset( $_POST['_grouped_calendars_source'] ) ? sanitize_key( $_POST['_grouped_calendars_source'] ) : 'ids'; |
|
| 179 | - update_post_meta( $post_id, '_grouped_calendars_source', $source ); |
|
| 178 | + $source = isset($_POST['_grouped_calendars_source']) ? sanitize_key($_POST['_grouped_calendars_source']) : 'ids'; |
|
| 179 | + update_post_meta($post_id, '_grouped_calendars_source', $source); |
|
| 180 | 180 | |
| 181 | - $ids = isset( $_POST['_grouped_calendars_ids'] ) ? array_map( 'absint', $_POST['_grouped_calendars_ids'] ) : ''; |
|
| 182 | - update_post_meta( $post_id, '_grouped_calendars_ids', $ids ); |
|
| 181 | + $ids = isset($_POST['_grouped_calendars_ids']) ? array_map('absint', $_POST['_grouped_calendars_ids']) : ''; |
|
| 182 | + update_post_meta($post_id, '_grouped_calendars_ids', $ids); |
|
| 183 | 183 | |
| 184 | - $category = isset( $_POST['_grouped_calendars_category'] ) ? array_map( 'absint', $_POST['_grouped_calendars_category'] ) : ''; |
|
| 185 | - update_post_meta( $post_id, '_grouped_calendars_category', $category ); |
|
| 184 | + $category = isset($_POST['_grouped_calendars_category']) ? array_map('absint', $_POST['_grouped_calendars_category']) : ''; |
|
| 185 | + update_post_meta($post_id, '_grouped_calendars_category', $category); |
|
| 186 | 186 | |
| 187 | 187 | } |
| 188 | 188 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @package SimpleCalendar/Admin/Functions |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if ( ! defined('ABSPATH')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return null|\SimpleCalendar\Abstracts\Admin_Page |
| 34 | 34 | */ |
| 35 | -function simcal_get_admin_page( $page ) { |
|
| 35 | +function simcal_get_admin_page($page) { |
|
| 36 | 36 | $objects = \SimpleCalendar\plugin()->objects; |
| 37 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_admin_page( $page ) : null; |
|
| 37 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_admin_page($page) : null; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return null|\SimpleCalendar\Abstracts\Field |
| 49 | 49 | */ |
| 50 | -function simcal_get_field( $args, $name = '' ) { |
|
| 50 | +function simcal_get_field($args, $name = '') { |
|
| 51 | 51 | $objects = \SimpleCalendar\plugin()->objects; |
| 52 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_field( $args, $name ) : null; |
|
| 52 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_field($args, $name) : null; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | -function simcal_print_field( $args, $name = '' ) { |
|
| 65 | +function simcal_print_field($args, $name = '') { |
|
| 66 | 66 | |
| 67 | - $field = simcal_get_field( $args, $name ); |
|
| 67 | + $field = simcal_get_field($args, $name); |
|
| 68 | 68 | |
| 69 | - if ( $field instanceof \SimpleCalendar\Abstracts\Field ) { |
|
| 69 | + if ($field instanceof \SimpleCalendar\Abstracts\Field) { |
|
| 70 | 70 | $field->html(); |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -80,50 +80,50 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return bool |
| 82 | 82 | */ |
| 83 | -function simcal_delete_feed_transients( $id = '' ) { |
|
| 83 | +function simcal_delete_feed_transients($id = '') { |
|
| 84 | 84 | |
| 85 | - if ( is_numeric( $id ) ) { |
|
| 86 | - $id = intval( $id ) > 0 ? absint( $id ) : simcal_get_calendars(); |
|
| 87 | - } elseif ( $id instanceof WP_Post ) { |
|
| 85 | + if (is_numeric($id)) { |
|
| 86 | + $id = intval($id) > 0 ? absint($id) : simcal_get_calendars(); |
|
| 87 | + } elseif ($id instanceof WP_Post) { |
|
| 88 | 88 | $id = $id->ID; |
| 89 | - } elseif ( is_array( $id ) ) { |
|
| 90 | - $id = array_map( 'absint', $id ); |
|
| 89 | + } elseif (is_array($id)) { |
|
| 90 | + $id = array_map('absint', $id); |
|
| 91 | 91 | } else { |
| 92 | - $id = simcal_get_calendars( '', true ); |
|
| 92 | + $id = simcal_get_calendars('', true); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $feed_types = simcal_get_feed_types(); |
| 96 | 96 | |
| 97 | - if ( is_array( $id ) ) { |
|
| 97 | + if (is_array($id)) { |
|
| 98 | 98 | |
| 99 | - $posts = get_posts( array( |
|
| 99 | + $posts = get_posts(array( |
|
| 100 | 100 | 'post_type' => 'calendar', |
| 101 | 101 | 'fields' => 'ids', |
| 102 | 102 | 'post__in' => $id, |
| 103 | 103 | 'nopaging' => true, |
| 104 | - ) ); |
|
| 104 | + )); |
|
| 105 | 105 | |
| 106 | - foreach ( $posts as $post ) { |
|
| 107 | - $calendar = simcal_get_calendar( $post ); |
|
| 108 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
| 109 | - foreach ( $feed_types as $feed_type ) { |
|
| 110 | - delete_transient( '_simple-calendar_feed_id_' . strval( $calendar->id ) . '_' . $feed_type ); |
|
| 106 | + foreach ($posts as $post) { |
|
| 107 | + $calendar = simcal_get_calendar($post); |
|
| 108 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
| 109 | + foreach ($feed_types as $feed_type) { |
|
| 110 | + delete_transient('_simple-calendar_feed_id_'.strval($calendar->id).'_'.$feed_type); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | } else { |
| 116 | 116 | |
| 117 | - $post = get_post( $id ); |
|
| 118 | - $calendar = simcal_get_calendar( $post ); |
|
| 119 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
| 120 | - foreach ( $feed_types as $feed_type ) { |
|
| 121 | - delete_transient( '_simple-calendar_feed_id_' . strval( $calendar->id ) . '_' . $feed_type ); |
|
| 117 | + $post = get_post($id); |
|
| 118 | + $calendar = simcal_get_calendar($post); |
|
| 119 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
| 120 | + foreach ($feed_types as $feed_type) { |
|
| 121 | + delete_transient('_simple-calendar_feed_id_'.strval($calendar->id).'_'.$feed_type); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return delete_transient( '_simple-calendar_feed_ids' ); |
|
| 126 | + return delete_transient('_simple-calendar_feed_ids'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -139,33 +139,33 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return array|string Sanitized variable |
| 141 | 141 | */ |
| 142 | -function simcal_sanitize_input( $var, $func = 'sanitize_text_field' ) { |
|
| 142 | +function simcal_sanitize_input($var, $func = 'sanitize_text_field') { |
|
| 143 | 143 | |
| 144 | - if ( is_null( $var ) ) { |
|
| 144 | + if (is_null($var)) { |
|
| 145 | 145 | return ''; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if ( is_bool( $var ) ) { |
|
| 149 | - if ( $var === true ) { |
|
| 148 | + if (is_bool($var)) { |
|
| 149 | + if ($var === true) { |
|
| 150 | 150 | return 'yes'; |
| 151 | 151 | } else { |
| 152 | 152 | return 'no'; |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( is_string( $var ) || is_numeric( $var ) ) { |
|
| 157 | - $func = is_string( $func ) && function_exists( $func ) ? $func : 'sanitize_text_field'; |
|
| 158 | - return call_user_func( $func, trim( strval( $var ) ) ); |
|
| 156 | + if (is_string($var) || is_numeric($var)) { |
|
| 157 | + $func = is_string($func) && function_exists($func) ? $func : 'sanitize_text_field'; |
|
| 158 | + return call_user_func($func, trim(strval($var))); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if ( is_object( $var ) ) { |
|
| 161 | + if (is_object($var)) { |
|
| 162 | 162 | $var = (array) $var; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ( is_array( $var ) ) { |
|
| 165 | + if (is_array($var)) { |
|
| 166 | 166 | $array = array(); |
| 167 | - foreach ( $var as $k => $v ) { |
|
| 168 | - $array[ $k ] = simcal_sanitize_input( $v ); |
|
| 167 | + foreach ($var as $k => $v) { |
|
| 168 | + $array[$k] = simcal_sanitize_input($v); |
|
| 169 | 169 | } |
| 170 | 170 | return $array; |
| 171 | 171 | } |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | function simcal_is_admin_screen() { |
| 185 | 185 | |
| 186 | - $view = function_exists( 'get_current_screen' ) ? get_current_screen() : false; |
|
| 186 | + $view = function_exists('get_current_screen') ? get_current_screen() : false; |
|
| 187 | 187 | |
| 188 | - if ( $view instanceof WP_Screen ) { |
|
| 188 | + if ($view instanceof WP_Screen) { |
|
| 189 | 189 | |
| 190 | 190 | // Screens used by this plugin. |
| 191 | 191 | $screens = array( |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | 'dashboard_page_simple-calendar_credits', |
| 201 | 201 | 'dashboard_page_simple-calendar_translators', |
| 202 | 202 | ); |
| 203 | - if ( in_array( $view->id, $screens ) ) { |
|
| 203 | + if (in_array($view->id, $screens)) { |
|
| 204 | 204 | return $view->id; |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @return \SimpleCalendar\Admin\Updater |
| 221 | 221 | */ |
| 222 | -function simcal_addon_updater( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 223 | - return new \SimpleCalendar\Admin\Updater( $_api_url, $_plugin_file, $_api_data ); |
|
| 222 | +function simcal_addon_updater($_api_url, $_plugin_file, $_api_data = null) { |
|
| 223 | + return new \SimpleCalendar\Admin\Updater($_api_url, $_plugin_file, $_api_data); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return null|string |
| 234 | 234 | */ |
| 235 | -function simcal_get_license_key( $addon ) { |
|
| 236 | - $licenses = get_option( 'simple-calendar_settings_licenses', array() ); |
|
| 237 | - if ( isset( $licenses['keys'][ $addon ] ) ) { |
|
| 238 | - return empty( $licenses['keys'][ $addon ] ) ? null : $licenses['keys'][ $addon ]; |
|
| 235 | +function simcal_get_license_key($addon) { |
|
| 236 | + $licenses = get_option('simple-calendar_settings_licenses', array()); |
|
| 237 | + if (isset($licenses['keys'][$addon])) { |
|
| 238 | + return empty($licenses['keys'][$addon]) ? null : $licenses['keys'][$addon]; |
|
| 239 | 239 | } |
| 240 | 240 | return null; |
| 241 | 241 | } |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return array|string |
| 253 | 253 | */ |
| 254 | -function simcal_get_license_status( $addon = null ) { |
|
| 255 | - $licenses = get_option( 'simple-calendar_licenses_status', array() ); |
|
| 256 | - return isset( $licenses[ $addon ] ) ? $licenses[ $addon ] : $licenses; |
|
| 254 | +function simcal_get_license_status($addon = null) { |
|
| 255 | + $licenses = get_option('simple-calendar_licenses_status', array()); |
|
| 256 | + return isset($licenses[$addon]) ? $licenses[$addon] : $licenses; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @since 3.0.0 |
| 275 | 275 | */ |
| 276 | 276 | function simcal_delete_admin_notices() { |
| 277 | - delete_option( 'simple-calendar_admin_notices' ); |
|
| 277 | + delete_option('simple-calendar_admin_notices'); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -286,22 +286,22 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @return void |
| 288 | 288 | */ |
| 289 | -function simcal_print_shortcode_tip( $post_id ) { |
|
| 289 | +function simcal_print_shortcode_tip($post_id) { |
|
| 290 | 290 | |
| 291 | 291 | $browser = new \Browser(); |
| 292 | - if ( $browser::PLATFORM_APPLE == $browser->getPlatform() ) { |
|
| 292 | + if ($browser::PLATFORM_APPLE == $browser->getPlatform()) { |
|
| 293 | 293 | $cmd = '⌘+C'; |
| 294 | 294 | } else { |
| 295 | 295 | $cmd = 'Ctrl+C'; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - $shortcut = sprintf( __( 'Press %s to copy.', 'google-calendar-events' ), $cmd ); |
|
| 299 | - $shortcode = sprintf( '[calendar id="%s"]', $post_id ); |
|
| 298 | + $shortcut = sprintf(__('Press %s to copy.', 'google-calendar-events'), $cmd); |
|
| 299 | + $shortcode = sprintf('[calendar id="%s"]', $post_id); |
|
| 300 | 300 | |
| 301 | - echo "<input readonly='readonly' " . |
|
| 302 | - "class='simcal-shortcode simcal-calendar-shortcode simcal-shortcode-tip' " . |
|
| 303 | - "title='" . $shortcut . "' " . |
|
| 304 | - "onclick='this.select();' value='" . $shortcode . "' />"; |
|
| 301 | + echo "<input readonly='readonly' ". |
|
| 302 | + "class='simcal-shortcode simcal-calendar-shortcode simcal-shortcode-tip' ". |
|
| 303 | + "title='".$shortcut."' ". |
|
| 304 | + "onclick='this.select();' value='".$shortcode."' />"; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -316,20 +316,20 @@ discard block |
||
| 316 | 316 | * |
| 317 | 317 | * @return string $url Full Google Analytics campaign URL |
| 318 | 318 | */ |
| 319 | -function simcal_ga_campaign_url( $base_url, $campaign, $content, $raw = false ) { |
|
| 319 | +function simcal_ga_campaign_url($base_url, $campaign, $content, $raw = false) { |
|
| 320 | 320 | |
| 321 | - $url = add_query_arg( array( |
|
| 321 | + $url = add_query_arg(array( |
|
| 322 | 322 | 'utm_source' => 'inside-plugin', |
| 323 | 323 | 'utm_medium' => 'link', |
| 324 | 324 | 'utm_campaign' => $campaign, // i.e. 'core-plugin', 'gcal-pro' |
| 325 | 325 | 'utm_content' => $content // i.e. 'sidebar-link', 'settings-link' |
| 326 | - ), $base_url ); |
|
| 326 | + ), $base_url); |
|
| 327 | 327 | |
| 328 | - if ( $raw ) { |
|
| 329 | - return esc_url_raw( $url ); |
|
| 328 | + if ($raw) { |
|
| 329 | + return esc_url_raw($url); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - return esc_url( $url ); |
|
| 332 | + return esc_url($url); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | function simcal_newsletter_signup() { |
| 343 | 343 | |
| 344 | - if ( $screen = simcal_is_admin_screen() ) { |
|
| 344 | + if ($screen = simcal_is_admin_screen()) { |
|
| 345 | 345 | |
| 346 | 346 | global $current_user; |
| 347 | 347 | get_currentuserinfo(); |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | <div id="simcal-drip" class="<?php echo $screen; ?>"> |
| 353 | 353 | <div class="signup"> |
| 354 | 354 | <p> |
| 355 | - <?php _e( "Enter your name and email and we'll send you a coupon code for 20% off our Google Calendar Pro add-on.", 'google-calendar-events' ); ?> |
|
| 355 | + <?php _e("Enter your name and email and we'll send you a coupon code for 20% off our Google Calendar Pro add-on.", 'google-calendar-events'); ?> |
|
| 356 | 356 | </p> |
| 357 | 357 | |
| 358 | 358 | <p> |
| 359 | - <label for="simcal-drip-field-email"><?php _e( 'Your Email', 'google-calendar-events' ); ?></label><br /> |
|
| 359 | + <label for="simcal-drip-field-email"><?php _e('Your Email', 'google-calendar-events'); ?></label><br /> |
|
| 360 | 360 | <input type="email" |
| 361 | 361 | id="simcal-drip-field-email" |
| 362 | 362 | name="fields[email]" |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | </p> |
| 365 | 365 | |
| 366 | 366 | <p> |
| 367 | - <label for="simcal-drip-field-first_name"><?php _e( 'First Name', 'google-calendar-events' ); ?></label><br /> |
|
| 367 | + <label for="simcal-drip-field-first_name"><?php _e('First Name', 'google-calendar-events'); ?></label><br /> |
|
| 368 | 368 | <input type="text" |
| 369 | 369 | id="simcal-drip-field-first_name" |
| 370 | 370 | name="fields[first_name]" |
@@ -373,15 +373,15 @@ discard block |
||
| 373 | 373 | <p class="textright"> |
| 374 | 374 | <a href="#" |
| 375 | 375 | id="simcal-drip-signup" |
| 376 | - class="button button-primary"><?php _e( 'Send me the coupon', 'google-calendar-events' ); ?></a> |
|
| 376 | + class="button button-primary"><?php _e('Send me the coupon', 'google-calendar-events'); ?></a> |
|
| 377 | 377 | </p> |
| 378 | 378 | <div class="textright"> |
| 379 | - <a href="<?php echo simcal_ga_campaign_url( simcal_get_url( 'gcal-pro' ), 'core-plugin', 'sidebar-link' ); ?>" |
|
| 380 | - target="_blank"><?php _e( 'Just take me to GCal Pro', 'google-calendar-events' ); ?></a> |
|
| 379 | + <a href="<?php echo simcal_ga_campaign_url(simcal_get_url('gcal-pro'), 'core-plugin', 'sidebar-link'); ?>" |
|
| 380 | + target="_blank"><?php _e('Just take me to GCal Pro', 'google-calendar-events'); ?></a> |
|
| 381 | 381 | </div> |
| 382 | 382 | </div> |
| 383 | 383 | <div class="thank-you" style="display: none;"> |
| 384 | - <?php _e( 'Thank you!', 'google-calendar-events' ); ?> |
|
| 384 | + <?php _e('Thank you!', 'google-calendar-events'); ?> |
|
| 385 | 385 | </div> |
| 386 | 386 | <div class="clear"> |
| 387 | 387 | </div> |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | -if ( ! function_exists( 'mb_detect_encoding' ) ) { |
|
| 395 | +if ( ! function_exists('mb_detect_encoding')) { |
|
| 396 | 396 | |
| 397 | 397 | /** |
| 398 | 398 | * Fallback function for `mb_detect_encoding()`, |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * |
| 407 | 407 | * @return bool |
| 408 | 408 | */ |
| 409 | - function mb_detect_encoding( $string, $enc = null, $ret = null ) { |
|
| 409 | + function mb_detect_encoding($string, $enc = null, $ret = null) { |
|
| 410 | 410 | |
| 411 | 411 | static $enclist = array( |
| 412 | 412 | 'UTF-8', |
@@ -432,10 +432,10 @@ discard block |
||
| 432 | 432 | |
| 433 | 433 | $result = false; |
| 434 | 434 | |
| 435 | - foreach ( $enclist as $item ) { |
|
| 436 | - $sample = iconv( $item, $item, $string ); |
|
| 437 | - if ( md5( $sample ) == md5( $string ) ) { |
|
| 438 | - if ( $ret === null ) { |
|
| 435 | + foreach ($enclist as $item) { |
|
| 436 | + $sample = iconv($item, $item, $string); |
|
| 437 | + if (md5($sample) == md5($string)) { |
|
| 438 | + if ($ret === null) { |
|
| 439 | 439 | $result = $item; |
| 440 | 440 | } else { |
| 441 | 441 | $result = true; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @deprecated |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -16,18 +16,18 @@ discard block |
||
| 16 | 16 | * Print a calendar. |
| 17 | 17 | * @deprecated Use simcal_print_calendar() |
| 18 | 18 | */ |
| 19 | -function gce_print_calendar( $feed_ids, $display, $args ) { |
|
| 19 | +function gce_print_calendar($feed_ids, $display, $args) { |
|
| 20 | 20 | |
| 21 | 21 | $id = 0; |
| 22 | 22 | |
| 23 | - if ( is_numeric( $feed_ids ) ) { |
|
| 24 | - $id = intval( $feed_ids ); |
|
| 25 | - } elseif ( is_array( $feed_ids ) ) { |
|
| 26 | - $id = isset( $feed_ids[0] ) ? intval( $feed_ids[0] ) : ''; |
|
| 23 | + if (is_numeric($feed_ids)) { |
|
| 24 | + $id = intval($feed_ids); |
|
| 25 | + } elseif (is_array($feed_ids)) { |
|
| 26 | + $id = isset($feed_ids[0]) ? intval($feed_ids[0]) : ''; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ( $id > 0 ) { |
|
| 30 | - simcal_print_calendar( $id ); |
|
| 29 | + if ($id > 0) { |
|
| 30 | + simcal_print_calendar($id); |
|
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | * Convert date from mm/dd/yyyy to unix timestamp. |
| 36 | 36 | * @deprecated Assumes a US-only time format. |
| 37 | 37 | */ |
| 38 | -function gce_date_unix( $date = '' ) { |
|
| 39 | - if ( empty( $date ) ) { |
|
| 40 | - $current_time = current_time( 'timestamp' ); |
|
| 41 | - $timestamp = mktime( 0, 0, 0, date( 'm', $current_time ), date( 'd', $current_time ), date( 'Y', $current_time ) ); |
|
| 38 | +function gce_date_unix($date = '') { |
|
| 39 | + if (empty($date)) { |
|
| 40 | + $current_time = current_time('timestamp'); |
|
| 41 | + $timestamp = mktime(0, 0, 0, date('m', $current_time), date('d', $current_time), date('Y', $current_time)); |
|
| 42 | 42 | } else { |
| 43 | - $date = explode( '/', $date ); |
|
| 43 | + $date = explode('/', $date); |
|
| 44 | 44 | $month = $date[0]; |
| 45 | 45 | $day = $date[1]; |
| 46 | 46 | $year = $date[2]; |
| 47 | - $timestamp = mktime( 0, 0, 0, $month, $day, $year ); |
|
| 47 | + $timestamp = mktime(0, 0, 0, $month, $day, $year); |
|
| 48 | 48 | } |
| 49 | 49 | return $timestamp; |
| 50 | 50 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @package SimpleCalendar/Functions |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if ( ! defined('ABSPATH')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -20,17 +20,17 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function is_simple_calendar() { |
| 22 | 22 | |
| 23 | - if ( is_singular() ) { |
|
| 23 | + if (is_singular()) { |
|
| 24 | 24 | |
| 25 | 25 | global $post, $post_type; |
| 26 | 26 | |
| 27 | - if ( 'calendar' == $post_type ) { |
|
| 27 | + if ('calendar' == $post_type) { |
|
| 28 | 28 | return true; |
| 29 | 29 | } else { |
| 30 | - if ( false !== get_post_meta( $post->ID, '_simcal_attach_calendar_id', true ) ) { |
|
| 30 | + if (false !== get_post_meta($post->ID, '_simcal_attach_calendar_id', true)) { |
|
| 31 | 31 | return true; |
| 32 | 32 | } |
| 33 | - if ( has_shortcode( $post->post_content, 'calendar' ) ) { |
|
| 33 | + if (has_shortcode($post->post_content, 'calendar')) { |
|
| 34 | 34 | return true; |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | -function simcal_get_url( $url ) { |
|
| 50 | - return \SimpleCalendar\plugin()->get_url( $url ); |
|
| 49 | +function simcal_get_url($url) { |
|
| 50 | + return \SimpleCalendar\plugin()->get_url($url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return null|\SimpleCalendar\Abstracts\Feed |
| 73 | 73 | */ |
| 74 | -function simcal_get_feed( $object ) { |
|
| 74 | +function simcal_get_feed($object) { |
|
| 75 | 75 | $objects = \SimpleCalendar\plugin()->objects; |
| 76 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_feed( $object ) : null; |
|
| 76 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_feed($object) : null; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return null|\SimpleCalendar\Abstracts\Calendar |
| 99 | 99 | */ |
| 100 | -function simcal_get_calendar( $object ) { |
|
| 100 | +function simcal_get_calendar($object) { |
|
| 101 | 101 | $objects = \SimpleCalendar\plugin()->objects; |
| 102 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar( $object ) : null; |
|
| 102 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar($object) : null; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return mixed |
| 114 | 114 | */ |
| 115 | -function simcal_get_calendar_view( $id = 0, $name = '' ) { |
|
| 115 | +function simcal_get_calendar_view($id = 0, $name = '') { |
|
| 116 | 116 | $objects = \SimpleCalendar\plugin()->objects; |
| 117 | - return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar_view( $id, $name ) : false; |
|
| 117 | + return $objects instanceof \SimpleCalendar\Objects ? $objects->get_calendar_view($id, $name) : false; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | -function simcal_print_calendar( $object ) { |
|
| 129 | +function simcal_print_calendar($object) { |
|
| 130 | 130 | |
| 131 | - $calendar = simcal_get_calendar( $object ); |
|
| 131 | + $calendar = simcal_get_calendar($object); |
|
| 132 | 132 | |
| 133 | - if ( $calendar instanceof \SimpleCalendar\Abstracts\Calendar ) { |
|
| 133 | + if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { |
|
| 134 | 134 | $calendar->html(); |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -148,21 +148,21 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $vars = array( |
| 150 | 150 | 'ajax_url' => \SimpleCalendar\plugin()->ajax_url(), |
| 151 | - 'nonce' => wp_create_nonce( 'simcal' ), |
|
| 151 | + 'nonce' => wp_create_nonce('simcal'), |
|
| 152 | 152 | 'locale' => \SimpleCalendar\plugin()->locale, |
| 153 | 153 | 'text_dir' => is_rtl() ? 'rtl' : 'ltr', |
| 154 | 154 | 'months' => array( |
| 155 | - 'full' => simcal_get_calendar_names_i18n( 'month', 'full' ), |
|
| 156 | - 'short' => simcal_get_calendar_names_i18n( 'month', 'short' ), |
|
| 155 | + 'full' => simcal_get_calendar_names_i18n('month', 'full'), |
|
| 156 | + 'short' => simcal_get_calendar_names_i18n('month', 'short'), |
|
| 157 | 157 | ), |
| 158 | 158 | 'days' => array( |
| 159 | - 'full' => simcal_get_calendar_names_i18n( 'day', 'full' ), |
|
| 160 | - 'short' => simcal_get_calendar_names_i18n( 'day', 'short' ), |
|
| 159 | + 'full' => simcal_get_calendar_names_i18n('day', 'full'), |
|
| 160 | + 'short' => simcal_get_calendar_names_i18n('day', 'short'), |
|
| 161 | 161 | ), |
| 162 | - 'meridiem' => simcal_get_calendar_names_i18n( 'meridiem' ), |
|
| 162 | + 'meridiem' => simcal_get_calendar_names_i18n('meridiem'), |
|
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - return array_merge( $vars, apply_filters( 'simcal_common_scripts_variables', array() ) ); |
|
| 165 | + return array_merge($vars, apply_filters('simcal_common_scripts_variables', array())); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -175,31 +175,31 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return array Associative array with ids as keys and feed titles as values. |
| 177 | 177 | */ |
| 178 | -function simcal_get_calendars( $exclude = '', $cached = true ) { |
|
| 178 | +function simcal_get_calendars($exclude = '', $cached = true) { |
|
| 179 | 179 | |
| 180 | - $calendars = get_transient( '_simple-calendar_feed_ids' ); |
|
| 180 | + $calendars = get_transient('_simple-calendar_feed_ids'); |
|
| 181 | 181 | |
| 182 | - if ( ! $calendars || $cached === false ) { |
|
| 182 | + if ( ! $calendars || $cached === false) { |
|
| 183 | 183 | |
| 184 | - $posts = get_posts( array( |
|
| 184 | + $posts = get_posts(array( |
|
| 185 | 185 | 'post_type' => 'calendar', |
| 186 | 186 | 'nopaging' => true, |
| 187 | - ) ); |
|
| 187 | + )); |
|
| 188 | 188 | |
| 189 | 189 | $calendars = array(); |
| 190 | - foreach ( $posts as $post ) { |
|
| 191 | - $calendars[ $post->ID ] = $post->post_title; |
|
| 190 | + foreach ($posts as $post) { |
|
| 191 | + $calendars[$post->ID] = $post->post_title; |
|
| 192 | 192 | } |
| 193 | - asort( $calendars ); |
|
| 193 | + asort($calendars); |
|
| 194 | 194 | |
| 195 | - set_transient( '_simple-calendar_feed_ids', $calendars, 604800 ); |
|
| 195 | + set_transient('_simple-calendar_feed_ids', $calendars, 604800); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if ( ! empty( $exclude ) ) { |
|
| 199 | - if ( is_numeric( $exclude ) ) { |
|
| 200 | - unset( $calendars[ intval( $exclude ) ] ); |
|
| 201 | - } elseif ( is_array( $exclude ) ) { |
|
| 202 | - array_diff_key( $calendars, array_map( 'intval', array_keys( $exclude ) ) ); |
|
| 198 | + if ( ! empty($exclude)) { |
|
| 199 | + if (is_numeric($exclude)) { |
|
| 200 | + unset($calendars[intval($exclude)]); |
|
| 201 | + } elseif (is_array($exclude)) { |
|
| 202 | + array_diff_key($calendars, array_map('intval', array_keys($exclude))); |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
@@ -218,45 +218,45 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return array |
| 220 | 220 | */ |
| 221 | -function simcal_get_calendar_names_i18n( $group, $style = 'full' ) { |
|
| 221 | +function simcal_get_calendar_names_i18n($group, $style = 'full') { |
|
| 222 | 222 | |
| 223 | 223 | $names = array(); |
| 224 | 224 | |
| 225 | - if ( in_array( $group, array( 'month', 'day', 'meridiem' ) ) ) { |
|
| 225 | + if (in_array($group, array('month', 'day', 'meridiem'))) { |
|
| 226 | 226 | |
| 227 | 227 | $format = ''; |
| 228 | 228 | $length = 0; |
| 229 | 229 | |
| 230 | 230 | $date = Carbon\Carbon::now(); |
| 231 | 231 | |
| 232 | - if ( 'month' == $group ) { |
|
| 233 | - $date->month( 0 )->startOfMonth(); |
|
| 232 | + if ('month' == $group) { |
|
| 233 | + $date->month(0)->startOfMonth(); |
|
| 234 | 234 | $format = 'short' == $style ? 'M' : 'F'; |
| 235 | 235 | $length = 11; |
| 236 | - } elseif ( 'day' == $group ) { |
|
| 237 | - $date->next( 6 ); |
|
| 236 | + } elseif ('day' == $group) { |
|
| 237 | + $date->next(6); |
|
| 238 | 238 | $format = 'short' == $style ? 'D' : 'l'; |
| 239 | 239 | $length = 6; |
| 240 | - } elseif ( 'meridiem' == $group ) { |
|
| 240 | + } elseif ('meridiem' == $group) { |
|
| 241 | 241 | $date->startOfDay(); |
| 242 | - $am = $date->addHour( 1 )->getTimestamp(); |
|
| 243 | - $pm = $date->addHours( 13 )->getTimestamp(); |
|
| 242 | + $am = $date->addHour(1)->getTimestamp(); |
|
| 243 | + $pm = $date->addHours(13)->getTimestamp(); |
|
| 244 | 244 | return array( |
| 245 | - 'AM' => date_i18n( 'A', $am ), |
|
| 246 | - 'am' => date_i18n( 'a', $am ), |
|
| 247 | - 'PM' => date_i18n( 'A', $pm ), |
|
| 248 | - 'pm' => date_i18n( 'a', $pm ), |
|
| 245 | + 'AM' => date_i18n('A', $am), |
|
| 246 | + 'am' => date_i18n('a', $am), |
|
| 247 | + 'PM' => date_i18n('A', $pm), |
|
| 248 | + 'pm' => date_i18n('a', $pm), |
|
| 249 | 249 | ); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $i = 0; |
| 253 | - while ( $i <= $length ) { |
|
| 254 | - if ( 'month' == $group ) { |
|
| 255 | - $date->addMonths( 1 ); |
|
| 253 | + while ($i <= $length) { |
|
| 254 | + if ('month' == $group) { |
|
| 255 | + $date->addMonths(1); |
|
| 256 | 256 | } else { |
| 257 | - $date->addDays( 1 ); |
|
| 257 | + $date->addDays(1); |
|
| 258 | 258 | } |
| 259 | - $names[ strval( $i ) ] = date_i18n( $format, $date->getTimestamp() ); |
|
| 259 | + $names[strval($i)] = date_i18n($format, $date->getTimestamp()); |
|
| 260 | 260 | $i++; |
| 261 | 261 | } |
| 262 | 262 | |
@@ -274,15 +274,15 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | function simcal_default_event_template() { |
| 276 | 276 | |
| 277 | - $content = '<strong>' . '[title]' . '</strong>'; |
|
| 277 | + $content = '<strong>'.'[title]'.'</strong>'; |
|
| 278 | 278 | $content .= '<p>'; |
| 279 | - $content .= '[when]' . "\n"; |
|
| 279 | + $content .= '[when]'."\n"; |
|
| 280 | 280 | $content .= '[location]'; |
| 281 | 281 | $content .= '</p>'; |
| 282 | - $content .= '<div>' . '[description]' . '</div>'; |
|
| 283 | - $content .= '<p>' . '[link newwindow="yes"]' . __( 'See more details', 'google-calendar-events' ) . '[/link]' . '</p>'; |
|
| 282 | + $content .= '<div>'.'[description]'.'</div>'; |
|
| 283 | + $content .= '<p>'.'[link newwindow="yes"]'.__('See more details', 'google-calendar-events').'[/link]'.'</p>'; |
|
| 284 | 284 | |
| 285 | - return apply_filters( 'simcal_default_event_template', $content ); |
|
| 285 | + return apply_filters('simcal_default_event_template', $content); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -297,21 +297,21 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | * @return array |
| 299 | 299 | */ |
| 300 | -function simcal_get_date_format_order( $date_format ) { |
|
| 300 | +function simcal_get_date_format_order($date_format) { |
|
| 301 | 301 | |
| 302 | 302 | $pos = array( |
| 303 | - 'd' => strpos( $date_format, strpbrk( $date_format, 'Dj' ) ), |
|
| 304 | - 'm' => strpos( $date_format, strpbrk( $date_format, 'FMmn' ) ), |
|
| 305 | - 'y' => strpos( $date_format, strpbrk( $date_format, 'Yy' ) ), |
|
| 303 | + 'd' => strpos($date_format, strpbrk($date_format, 'Dj')), |
|
| 304 | + 'm' => strpos($date_format, strpbrk($date_format, 'FMmn')), |
|
| 305 | + 'y' => strpos($date_format, strpbrk($date_format, 'Yy')), |
|
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | 308 | // @TODO When one date piece is not found, perhaps fallback to ISO standard position. |
| 309 | 309 | |
| 310 | 310 | $order = array(); |
| 311 | - foreach ( $pos as $k => $v ) { |
|
| 312 | - $order[ $k ] = $v; |
|
| 311 | + foreach ($pos as $k => $v) { |
|
| 312 | + $order[$k] = $v; |
|
| 313 | 313 | } |
| 314 | - ksort( $order ); |
|
| 314 | + ksort($order); |
|
| 315 | 315 | |
| 316 | 316 | return $order; |
| 317 | 317 | } |
@@ -327,11 +327,11 @@ discard block |
||
| 327 | 327 | */ |
| 328 | 328 | function simcal_get_wp_timezone() { |
| 329 | 329 | |
| 330 | - $timezone = get_option( 'timezone_string' ); |
|
| 330 | + $timezone = get_option('timezone_string'); |
|
| 331 | 331 | |
| 332 | - if ( empty( $timezone ) ) { |
|
| 333 | - $gmt = get_option( 'gmt_offset' ); |
|
| 334 | - $timezone = simcal_get_timezone_from_gmt_offset( $gmt ); |
|
| 332 | + if (empty($timezone)) { |
|
| 333 | + $gmt = get_option('gmt_offset'); |
|
| 334 | + $timezone = simcal_get_timezone_from_gmt_offset($gmt); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | return $timezone; |
@@ -348,26 +348,26 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | * @return null|string |
| 350 | 350 | */ |
| 351 | -function simcal_get_timezone_from_gmt_offset( $offset ) { |
|
| 351 | +function simcal_get_timezone_from_gmt_offset($offset) { |
|
| 352 | 352 | |
| 353 | - if ( is_numeric( $offset ) ) { |
|
| 353 | + if (is_numeric($offset)) { |
|
| 354 | 354 | |
| 355 | - if ( 0 === intval( $offset ) ) { |
|
| 355 | + if (0 === intval($offset)) { |
|
| 356 | 356 | return 'UTC'; |
| 357 | 357 | } else { |
| 358 | - $offset = floatval( $offset ) * 3600; |
|
| 358 | + $offset = floatval($offset) * 3600; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - $timezone = timezone_name_from_abbr( null, $offset, true ); |
|
| 361 | + $timezone = timezone_name_from_abbr(null, $offset, true); |
|
| 362 | 362 | // This is buggy and might return false: |
| 363 | 363 | // @see http://php.net/manual/en/function.timezone-name-from-abbr.php#86928 |
| 364 | 364 | // Therefore: |
| 365 | - if ( false == $timezone ) { |
|
| 365 | + if (false == $timezone) { |
|
| 366 | 366 | |
| 367 | 367 | $list = timezone_abbreviations_list(); |
| 368 | - foreach ( $list as $abbr ) { |
|
| 369 | - foreach ( $abbr as $city ) { |
|
| 370 | - if ( $offset == $city['offset'] ) { |
|
| 368 | + foreach ($list as $abbr) { |
|
| 369 | + foreach ($abbr as $city) { |
|
| 370 | + if ($offset == $city['offset']) { |
|
| 371 | 371 | return $city['timezone_id']; |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @return int Unix time offset |
| 392 | 392 | */ |
| 393 | -function simcal_get_timezone_offset( $timezone ) { |
|
| 394 | - return \Carbon\Carbon::now( $timezone )->offset; |
|
| 393 | +function simcal_get_timezone_offset($timezone) { |
|
| 394 | + return \Carbon\Carbon::now($timezone)->offset; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -404,6 +404,6 @@ discard block |
||
| 404 | 404 | * |
| 405 | 405 | * @return mixed|string |
| 406 | 406 | */ |
| 407 | -function simcal_esc_timezone( $tz, $default = 'UTC' ) { |
|
| 408 | - return in_array( $tz, timezone_identifiers_list() ) ? $tz : $default; |
|
| 407 | +function simcal_esc_timezone($tz, $default = 'UTC') { |
|
| 408 | + return in_array($tz, timezone_identifiers_list()) ? $tz : $default; |
|
| 409 | 409 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use SimpleCalendar\Admin\Pages; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | self::create_terms(); |
| 35 | 35 | self::create_options(); |
| 36 | 36 | |
| 37 | - do_action( 'simcal_activated' ); |
|
| 37 | + do_action('simcal_activated'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | flush_rewrite_rules(); |
| 48 | 48 | |
| 49 | - do_action( 'simcal_deactivated' ); |
|
| 49 | + do_action('simcal_deactivated'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | ) |
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | - foreach ( $taxonomies as $taxonomy => $terms ) { |
|
| 70 | - foreach ( $terms as $term ) { |
|
| 71 | - if ( ! get_term_by( 'slug', sanitize_title( $term ), $taxonomy ) ) { |
|
| 72 | - wp_insert_term( $term, $taxonomy ); |
|
| 69 | + foreach ($taxonomies as $taxonomy => $terms) { |
|
| 70 | + foreach ($terms as $term) { |
|
| 71 | + if ( ! get_term_by('slug', sanitize_title($term), $taxonomy)) { |
|
| 72 | + wp_insert_term($term, $taxonomy); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -85,33 +85,33 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | $default = ''; |
| 87 | 87 | $page = 'settings'; |
| 88 | - $settings_pages = new Pages( $page ); |
|
| 88 | + $settings_pages = new Pages($page); |
|
| 89 | 89 | $plugin_settings = $settings_pages->get_settings(); |
| 90 | 90 | |
| 91 | - if ( $plugin_settings && is_array( $plugin_settings ) ) { |
|
| 91 | + if ($plugin_settings && is_array($plugin_settings)) { |
|
| 92 | 92 | |
| 93 | - foreach ( $plugin_settings as $id => $settings ) { |
|
| 93 | + foreach ($plugin_settings as $id => $settings) { |
|
| 94 | 94 | |
| 95 | - $group = 'simple-calendar_' . $page . '_' . $id; |
|
| 95 | + $group = 'simple-calendar_'.$page.'_'.$id; |
|
| 96 | 96 | |
| 97 | - if ( isset( $settings['sections'] ) ) { |
|
| 97 | + if (isset($settings['sections'])) { |
|
| 98 | 98 | |
| 99 | - if ( $settings['sections'] && is_array( $settings['sections'] ) ) { |
|
| 99 | + if ($settings['sections'] && is_array($settings['sections'])) { |
|
| 100 | 100 | |
| 101 | - foreach ( $settings['sections'] as $section_id => $section ) { |
|
| 101 | + foreach ($settings['sections'] as $section_id => $section) { |
|
| 102 | 102 | |
| 103 | - if ( isset( $section['fields'] ) ) { |
|
| 103 | + if (isset($section['fields'])) { |
|
| 104 | 104 | |
| 105 | - if ( $section['fields'] && is_array( $section['fields'] ) ) { |
|
| 105 | + if ($section['fields'] && is_array($section['fields'])) { |
|
| 106 | 106 | |
| 107 | - foreach ( $section['fields'] as $key => $field ) { |
|
| 107 | + foreach ($section['fields'] as $key => $field) { |
|
| 108 | 108 | |
| 109 | - if ( isset ( $field['type'] ) ) { |
|
| 109 | + if (isset ($field['type'])) { |
|
| 110 | 110 | // Maybe an associative array. |
| 111 | - if ( is_int( $key ) ) { |
|
| 112 | - $default[ $section_id ] = self::get_field_default_value( $field ); |
|
| 111 | + if (is_int($key)) { |
|
| 112 | + $default[$section_id] = self::get_field_default_value($field); |
|
| 113 | 113 | } else { |
| 114 | - $default[ $section_id ][ $key ] = self::get_field_default_value( $field ); |
|
| 114 | + $default[$section_id][$key] = self::get_field_default_value($field); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | } // Are there sections? |
| 129 | 129 | |
| 130 | - add_option( $group, $default, '', true ); |
|
| 130 | + add_option($group, $default, '', true); |
|
| 131 | 131 | |
| 132 | 132 | // Reset before looping next settings page. |
| 133 | 133 | $default = ''; |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return mixed |
| 149 | 149 | */ |
| 150 | - private static function get_field_default_value( $field ) { |
|
| 150 | + private static function get_field_default_value($field) { |
|
| 151 | 151 | |
| 152 | - $saved_value = isset( $field['value'] ) ? $field['value'] : ''; |
|
| 153 | - $default_value = isset( $field['default'] ) ? $field['default'] : ''; |
|
| 152 | + $saved_value = isset($field['value']) ? $field['value'] : ''; |
|
| 153 | + $default_value = isset($field['default']) ? $field['default'] : ''; |
|
| 154 | 154 | |
| 155 | - return ! empty( $saved_value ) ? $saved_value : $default_value; |
|
| 155 | + return ! empty($saved_value) ? $saved_value : $default_value; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use SimpleCalendar\Admin\License_Manager; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @return Plugin |
| 72 | 72 | */ |
| 73 | 73 | public static function get_instance() { |
| 74 | - if ( is_null( self::$_instance ) ) { |
|
| 74 | + if (is_null(self::$_instance)) { |
|
| 75 | 75 | self::$_instance = new self(); |
| 76 | 76 | } |
| 77 | 77 | return self::$_instance; |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * Cloning is forbidden. |
| 82 | 82 | */ |
| 83 | 83 | public function __clone() { |
| 84 | - _doing_it_wrong( __FUNCTION__, 'Cloning the main instance of this plugin is forbidden.', '1.0.0' ); |
|
| 84 | + _doing_it_wrong(__FUNCTION__, 'Cloning the main instance of this plugin is forbidden.', '1.0.0'); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Unserializing instances of this class is forbidden. |
| 89 | 89 | */ |
| 90 | 90 | public function __wakeup() { |
| 91 | - _doing_it_wrong( __FUNCTION__, 'Unserializing instances of this plugin is forbidden.', '1.0.0' ); |
|
| 91 | + _doing_it_wrong(__FUNCTION__, 'Unserializing instances of this plugin is forbidden.', '1.0.0'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,22 +100,22 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | // Load plugin. |
| 102 | 102 | require_once 'autoload.php'; |
| 103 | - $this->locale = apply_filters( 'plugin_locale', get_locale(), 'google-calendar-events' ); |
|
| 103 | + $this->locale = apply_filters('plugin_locale', get_locale(), 'google-calendar-events'); |
|
| 104 | 104 | $this->load(); |
| 105 | 105 | |
| 106 | 106 | // Installation hooks. |
| 107 | - register_activation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'activate' ) ); |
|
| 108 | - register_deactivation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'deactivate' ) ); |
|
| 107 | + register_activation_hook(SIMPLE_CALENDAR_MAIN_FILE, array('SimpleCalendar\Installation', 'activate')); |
|
| 108 | + register_deactivation_hook(SIMPLE_CALENDAR_MAIN_FILE, array('SimpleCalendar\Installation', 'deactivate')); |
|
| 109 | 109 | |
| 110 | 110 | // Do update call here. |
| 111 | - add_action( 'admin_init', array( $this, 'update' ), 999 ); |
|
| 111 | + add_action('admin_init', array($this, 'update'), 999); |
|
| 112 | 112 | |
| 113 | 113 | // Init hooks. |
| 114 | - add_action( 'init', array( $this, 'init' ), 5 ); |
|
| 115 | - add_action( 'admin_init', array( $this, 'register_settings' ), 5 ); |
|
| 114 | + add_action('init', array($this, 'init'), 5); |
|
| 115 | + add_action('admin_init', array($this, 'register_settings'), 5); |
|
| 116 | 116 | |
| 117 | 117 | // Upon plugin loaded action hook. |
| 118 | - do_action( 'simcal_loaded' ); |
|
| 118 | + do_action('simcal_loaded'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | new Post_Types(); |
| 133 | 133 | |
| 134 | 134 | // Load back end. |
| 135 | - if ( is_admin() ) { |
|
| 135 | + if (is_admin()) { |
|
| 136 | 136 | $this->load_admin(); |
| 137 | 137 | } else { |
| 138 | 138 | // Load front end scripts and styles. |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | // Init menus and settings. |
| 175 | 175 | new Admin\Menus(); |
| 176 | 176 | |
| 177 | - if ( defined( 'DOING_AJAX' ) ) { |
|
| 177 | + if (defined('DOING_AJAX')) { |
|
| 178 | 178 | // Admin ajax callbacks. |
| 179 | 179 | new Admin\Ajax(); |
| 180 | 180 | } |
@@ -188,16 +188,16 @@ discard block |
||
| 188 | 188 | public function init() { |
| 189 | 189 | |
| 190 | 190 | // Before init action hook. |
| 191 | - do_action( 'before_simcal_init' ); |
|
| 191 | + do_action('before_simcal_init'); |
|
| 192 | 192 | |
| 193 | 193 | // Set up localization. |
| 194 | - load_plugin_textdomain( 'google-calendar-events', false, dirname( plugin_basename( SIMPLE_CALENDAR_MAIN_FILE ) ) . '/languages/' ); |
|
| 194 | + load_plugin_textdomain('google-calendar-events', false, dirname(plugin_basename(SIMPLE_CALENDAR_MAIN_FILE)).'/languages/'); |
|
| 195 | 195 | |
| 196 | 196 | // Init objects factory. |
| 197 | 197 | $this->objects = new Objects(); |
| 198 | 198 | |
| 199 | 199 | // Upon init action hook. |
| 200 | - do_action( 'simcal_init' ); |
|
| 200 | + do_action('simcal_init'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @since 3.0.0 |
| 207 | 207 | */ |
| 208 | 208 | public function register_settings() { |
| 209 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 209 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
| 210 | 210 | $settings = new Admin\Pages(); |
| 211 | - $settings->register_settings( $settings->get_settings() ); |
|
| 211 | + $settings->register_settings($settings->get_settings()); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | public function ajax_url() { |
| 223 | - return admin_url( 'admin-ajax.php', 'relative' ); |
|
| 223 | + return admin_url('admin-ajax.php', 'relative'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return string |
| 234 | 234 | */ |
| 235 | - public function get_url( $case ) { |
|
| 236 | - switch ( $case ) { |
|
| 235 | + public function get_url($case) { |
|
| 236 | + switch ($case) { |
|
| 237 | 237 | case 'codex' : |
| 238 | 238 | case 'apidocs' : |
| 239 | 239 | return 'http://codex.simplecalendar.io'; |
| 240 | 240 | case 'add-ons' : |
| 241 | - return self::$homepage . '/addons/'; |
|
| 241 | + return self::$homepage.'/addons/'; |
|
| 242 | 242 | case 'gcal-pro' : |
| 243 | - return self::$homepage . '/addons/google-calendar-pro/'; |
|
| 243 | + return self::$homepage.'/addons/google-calendar-pro/'; |
|
| 244 | 244 | case 'docs' : |
| 245 | 245 | return 'http://docs.simplecalendar.io'; |
| 246 | 246 | case 'github' : |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @since 3.0.0 |
| 261 | 261 | */ |
| 262 | 262 | public static function update() { |
| 263 | - $update = new Update( SIMPLE_CALENDAR_VERSION ); |
|
| 263 | + $update = new Update(SIMPLE_CALENDAR_VERSION); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | use SimpleCalendar\Abstracts as Object; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if ( ! defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -31,27 +31,27 @@ discard block |
||
| 31 | 31 | public function __construct() { |
| 32 | 32 | |
| 33 | 33 | // Add default feed type. |
| 34 | - add_filter( 'simcal_get_feed_types', function( $feed_types ) { |
|
| 35 | - return array_merge( $feed_types, array( |
|
| 34 | + add_filter('simcal_get_feed_types', function($feed_types) { |
|
| 35 | + return array_merge($feed_types, array( |
|
| 36 | 36 | 'google', |
| 37 | 37 | 'grouped-calendars', |
| 38 | - ) ); |
|
| 39 | - }, 10, 1 ); |
|
| 38 | + )); |
|
| 39 | + }, 10, 1); |
|
| 40 | 40 | |
| 41 | 41 | // Add default calendar type. |
| 42 | - add_filter( 'simcal_get_calendar_types', function( $calendar_types ) { |
|
| 43 | - return array_merge( $calendar_types, array( |
|
| 42 | + add_filter('simcal_get_calendar_types', function($calendar_types) { |
|
| 43 | + return array_merge($calendar_types, array( |
|
| 44 | 44 | 'default-calendar' => array( |
| 45 | 45 | 'grid', |
| 46 | 46 | 'list', |
| 47 | 47 | ), |
| 48 | - ) ); |
|
| 49 | - }, 10, 1 ); |
|
| 48 | + )); |
|
| 49 | + }, 10, 1); |
|
| 50 | 50 | |
| 51 | 51 | // Add default admin objects. |
| 52 | - if ( $is_admin = is_admin() ) { |
|
| 53 | - add_filter( 'simcal_get_admin_pages', function( $admin_pages ) { |
|
| 54 | - return array_merge( $admin_pages, array( |
|
| 52 | + if ($is_admin = is_admin()) { |
|
| 53 | + add_filter('simcal_get_admin_pages', function($admin_pages) { |
|
| 54 | + return array_merge($admin_pages, array( |
|
| 55 | 55 | 'add-ons' => array( |
| 56 | 56 | 'add-ons', |
| 57 | 57 | ), |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | 'tools' => array( |
| 64 | 64 | 'system-status', |
| 65 | 65 | ), |
| 66 | - ) ); |
|
| 67 | - }, 10, 1 ); |
|
| 66 | + )); |
|
| 67 | + }, 10, 1); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - do_action( 'simcal_load_objects', $is_admin ); |
|
| 70 | + do_action('simcal_load_objects', $is_admin); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | public function get_feed_types() { |
| 81 | - $array = apply_filters( 'simcal_get_feed_types', array() ); |
|
| 82 | - ksort( $array ); |
|
| 81 | + $array = apply_filters('simcal_get_feed_types', array()); |
|
| 82 | + ksort($array); |
|
| 83 | 83 | return $array; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | 93 | public function get_calendar_types() { |
| 94 | - $array = apply_filters( 'simcal_get_calendar_types', array() ); |
|
| 95 | - ksort( $array ); |
|
| 94 | + $array = apply_filters('simcal_get_calendar_types', array()); |
|
| 95 | + ksort($array); |
|
| 96 | 96 | return $array; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | 106 | public function get_admin_pages() { |
| 107 | - return apply_filters( 'simcal_get_admin_pages', array() ); |
|
| 107 | + return apply_filters('simcal_get_admin_pages', array()); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -118,30 +118,30 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return null|Object\Calendar |
| 120 | 120 | */ |
| 121 | - public function get_calendar( $object ) { |
|
| 121 | + public function get_calendar($object) { |
|
| 122 | 122 | |
| 123 | - if ( is_string( $object ) ) { |
|
| 124 | - return ! empty( $object ) ? $this->get_object( $object, 'calendar', '' ) : null; |
|
| 123 | + if (is_string($object)) { |
|
| 124 | + return ! empty($object) ? $this->get_object($object, 'calendar', '') : null; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ( is_object( $object ) ) { |
|
| 128 | - if ( $object instanceof Object\Calendar ) { |
|
| 129 | - return $this->get_object( $object->type, 'feed', $object ); |
|
| 130 | - } elseif ( $object instanceof \WP_Post ) { |
|
| 131 | - if ( $type = wp_get_object_terms( $object->ID, 'calendar_type' ) ) { |
|
| 132 | - $name = sanitize_title( current( $type )->name ); |
|
| 133 | - return $this->get_object( $name, 'calendar', $object ); |
|
| 127 | + if (is_object($object)) { |
|
| 128 | + if ($object instanceof Object\Calendar) { |
|
| 129 | + return $this->get_object($object->type, 'feed', $object); |
|
| 130 | + } elseif ($object instanceof \WP_Post) { |
|
| 131 | + if ($type = wp_get_object_terms($object->ID, 'calendar_type')) { |
|
| 132 | + $name = sanitize_title(current($type)->name); |
|
| 133 | + return $this->get_object($name, 'calendar', $object); |
|
| 134 | 134 | } |
| 135 | - } elseif ( isset( $object->type ) && isset( $object->id ) ) { |
|
| 136 | - return $this->get_object( $object->type, 'calendar', $object->id ); |
|
| 135 | + } elseif (isset($object->type) && isset($object->id)) { |
|
| 136 | + return $this->get_object($object->type, 'calendar', $object->id); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( is_int( $object ) ) { |
|
| 141 | - $post = get_post( $object ); |
|
| 142 | - if ( $post && ( $type = wp_get_object_terms( $post->ID, 'calendar_type' ) ) ) { |
|
| 143 | - $name = sanitize_title( current( $type )->name ); |
|
| 144 | - return $this->get_object( $name, 'calendar', $post ); |
|
| 140 | + if (is_int($object)) { |
|
| 141 | + $post = get_post($object); |
|
| 142 | + if ($post && ($type = wp_get_object_terms($post->ID, 'calendar_type'))) { |
|
| 143 | + $name = sanitize_title(current($type)->name); |
|
| 144 | + return $this->get_object($name, 'calendar', $post); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return null|Object\Calendar_View |
| 160 | 160 | */ |
| 161 | - public function get_calendar_view( $id = 0, $name = '' ) { |
|
| 161 | + public function get_calendar_view($id = 0, $name = '') { |
|
| 162 | 162 | |
| 163 | - if ( ! $name && $id > 0 ) { |
|
| 163 | + if ( ! $name && $id > 0) { |
|
| 164 | 164 | |
| 165 | - $calendar_view = get_post_meta( $id, '_calendar_view', true ); |
|
| 165 | + $calendar_view = get_post_meta($id, '_calendar_view', true); |
|
| 166 | 166 | |
| 167 | - if ( $terms = wp_get_object_terms( $id, 'calendar_type' ) ) { |
|
| 168 | - $calendar_type = sanitize_title( current( $terms )->name ); |
|
| 169 | - $name = isset( $calendar_view[ $calendar_type ] ) ? $calendar_type . '-' . $calendar_view[ $calendar_type ] : ''; |
|
| 167 | + if ($terms = wp_get_object_terms($id, 'calendar_type')) { |
|
| 168 | + $calendar_type = sanitize_title(current($terms)->name); |
|
| 169 | + $name = isset($calendar_view[$calendar_type]) ? $calendar_type.'-'.$calendar_view[$calendar_type] : ''; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - return $name ? $this->get_object( $name, 'calendar-view', '' ) : null; |
|
| 174 | + return $name ? $this->get_object($name, 'calendar-view', '') : null; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -185,34 +185,34 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return null|Object\Feed |
| 187 | 187 | */ |
| 188 | - public function get_feed( $object ) { |
|
| 188 | + public function get_feed($object) { |
|
| 189 | 189 | |
| 190 | - if ( is_string( $object ) ) { |
|
| 191 | - return ! empty( $object ) ? $this->get_object( $object, 'feed', '' ) : null; |
|
| 190 | + if (is_string($object)) { |
|
| 191 | + return ! empty($object) ? $this->get_object($object, 'feed', '') : null; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( is_object( $object ) ) { |
|
| 195 | - if ( $object instanceof Object\Calendar ) { |
|
| 194 | + if (is_object($object)) { |
|
| 195 | + if ($object instanceof Object\Calendar) { |
|
| 196 | 196 | $feed_name = ''; |
| 197 | - if ( empty( $object->feed ) ) { |
|
| 198 | - if ( $feed_type = wp_get_object_terms( $object->id, 'feed_type' ) ) { |
|
| 199 | - $feed_name = sanitize_title( current( $feed_type )->name ); |
|
| 197 | + if (empty($object->feed)) { |
|
| 198 | + if ($feed_type = wp_get_object_terms($object->id, 'feed_type')) { |
|
| 199 | + $feed_name = sanitize_title(current($feed_type)->name); |
|
| 200 | 200 | } |
| 201 | 201 | } else { |
| 202 | 202 | $feed_name = $object->feed; |
| 203 | 203 | } |
| 204 | - return $this->get_object( $feed_name, 'feed', $object ); |
|
| 205 | - } elseif ( $object instanceof \WP_Post ) { |
|
| 206 | - $calendar = $this->get_calendar( $object ); |
|
| 207 | - return $this->get_object( $calendar->feed, 'feed', $calendar ); |
|
| 208 | - } elseif ( isset( $object->feed ) && isset( $object->id ) ) { |
|
| 209 | - return $this->get_object( $object->feed, 'feed', $object ); |
|
| 204 | + return $this->get_object($feed_name, 'feed', $object); |
|
| 205 | + } elseif ($object instanceof \WP_Post) { |
|
| 206 | + $calendar = $this->get_calendar($object); |
|
| 207 | + return $this->get_object($calendar->feed, 'feed', $calendar); |
|
| 208 | + } elseif (isset($object->feed) && isset($object->id)) { |
|
| 209 | + return $this->get_object($object->feed, 'feed', $object); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( is_int( $object ) ) { |
|
| 214 | - $calendar = $this->get_calendar( $object ); |
|
| 215 | - return isset( $calendar->feed ) ? $this->get_object( $calendar->feed, 'feed', $calendar ) : null; |
|
| 213 | + if (is_int($object)) { |
|
| 214 | + $calendar = $this->get_calendar($object); |
|
| 215 | + return isset($calendar->feed) ? $this->get_object($calendar->feed, 'feed', $calendar) : null; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | return null; |
@@ -228,13 +228,13 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @return null|Object\Field |
| 230 | 230 | */ |
| 231 | - public function get_field( $args, $name = '' ) { |
|
| 231 | + public function get_field($args, $name = '') { |
|
| 232 | 232 | |
| 233 | - if ( empty( $name ) ) { |
|
| 234 | - $name = isset( $args['type'] ) ? $args['type'] : false; |
|
| 233 | + if (empty($name)) { |
|
| 234 | + $name = isset($args['type']) ? $args['type'] : false; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return $name ? $this->get_object( $name, 'field', $args ) : null; |
|
| 237 | + return $name ? $this->get_object($name, 'field', $args) : null; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * @return null|Object\Admin_Page |
| 248 | 248 | */ |
| 249 | - public function get_admin_page( $name ) { |
|
| 250 | - return $name ? $this->get_object( $name, 'admin-page' ) : null; |
|
| 249 | + public function get_admin_page($name) { |
|
| 250 | + return $name ? $this->get_object($name, 'admin-page') : null; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @return null|Object |
| 264 | 264 | */ |
| 265 | - private function get_object( $name, $type, $args = '' ) { |
|
| 265 | + private function get_object($name, $type, $args = '') { |
|
| 266 | 266 | |
| 267 | 267 | $types = array( |
| 268 | 268 | 'admin-page', |
@@ -272,11 +272,11 @@ discard block |
||
| 272 | 272 | 'field', |
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | - if ( in_array( $type, $types ) ) { |
|
| 275 | + if (in_array($type, $types)) { |
|
| 276 | 276 | |
| 277 | - $class_name = $this->make_class_name( $name, $type ); |
|
| 278 | - $parent = '\\' . __NAMESPACE__ . '\Abstracts\\' . implode( '_', array_map( 'ucfirst', explode( '-', $type ) ) ); |
|
| 279 | - $class = class_exists( $class_name ) ? new $class_name( $args ) : false; |
|
| 277 | + $class_name = $this->make_class_name($name, $type); |
|
| 278 | + $parent = '\\'.__NAMESPACE__.'\Abstracts\\'.implode('_', array_map('ucfirst', explode('-', $type))); |
|
| 279 | + $class = class_exists($class_name) ? new $class_name($args) : false; |
|
| 280 | 280 | |
| 281 | 281 | return $class instanceof $parent ? $class : null; |
| 282 | 282 | } |
@@ -298,25 +298,25 @@ discard block |
||
| 298 | 298 | * |
| 299 | 299 | * @return string The class name complete with its full namespace. |
| 300 | 300 | */ |
| 301 | - private function make_class_name( $name, $type ) { |
|
| 302 | - |
|
| 303 | - if ( 'calendar' == $type ) { |
|
| 304 | - $namespace = '\\' . __NAMESPACE__ . '\Calendars\\'; |
|
| 305 | - } elseif ( 'calendar-view' == $type ) { |
|
| 306 | - $namespace = '\\' . __NAMESPACE__ . '\Calendars\Views\\'; |
|
| 307 | - } elseif ( 'feed' == $type ) { |
|
| 308 | - $namespace = '\\' . __NAMESPACE__ . '\Feeds\\'; |
|
| 309 | - } elseif ( 'field' == $type ) { |
|
| 310 | - $namespace = '\\' . __NAMESPACE__ . '\Admin\Fields\\'; |
|
| 311 | - } elseif ( 'admin-page' == $type ) { |
|
| 312 | - $namespace = '\\' . __NAMESPACE__ . '\Admin\Pages\\'; |
|
| 301 | + private function make_class_name($name, $type) { |
|
| 302 | + |
|
| 303 | + if ('calendar' == $type) { |
|
| 304 | + $namespace = '\\'.__NAMESPACE__.'\Calendars\\'; |
|
| 305 | + } elseif ('calendar-view' == $type) { |
|
| 306 | + $namespace = '\\'.__NAMESPACE__.'\Calendars\Views\\'; |
|
| 307 | + } elseif ('feed' == $type) { |
|
| 308 | + $namespace = '\\'.__NAMESPACE__.'\Feeds\\'; |
|
| 309 | + } elseif ('field' == $type) { |
|
| 310 | + $namespace = '\\'.__NAMESPACE__.'\Admin\Fields\\'; |
|
| 311 | + } elseif ('admin-page' == $type) { |
|
| 312 | + $namespace = '\\'.__NAMESPACE__.'\Admin\Pages\\'; |
|
| 313 | 313 | } else { |
| 314 | 314 | return ''; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $class_name = implode( '_', array_map( 'ucfirst', explode( '-', $name ) ) ); |
|
| 317 | + $class_name = implode('_', array_map('ucfirst', explode('-', $name))); |
|
| 318 | 318 | |
| 319 | - return $namespace . $class_name; |
|
| 319 | + return $namespace.$class_name; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | } |