/includes/admin/metaboxes/settings.php

  1. <?php 
  2. /** 
  3. * Calendar Feed Settings Meta Box 
  4. * 
  5. * @package SimpleCalendar/Admin 
  6. */ 
  7. namespace SimpleCalendar\Admin\Metaboxes; 
  8.  
  9. use SimpleCalendar\Abstracts\Meta_Box; 
  10. use SimpleCalendar\Abstracts\Calendar; 
  11. use SimpleCalendar\Abstracts\Feed; 
  12. use SimpleCalendar\Abstracts\Field; 
  13.  
  14. if ( ! defined( 'ABSPATH' ) ) { 
  15. exit; 
  16.  
  17. /** 
  18. * Calendar feed settings. 
  19. * 
  20. * Meta box for handling an individual feed settings. 
  21. * 
  22. * @since 3.0.0 
  23. */ 
  24. class Settings implements Meta_Box { 
  25.  
  26. /** 
  27. * Output the meta box markup. 
  28. * 
  29. * @since 3.0.0 
  30. * 
  31. * @param \WP_Post $post 
  32. */ 
  33. public static function html( $post ) { 
  34.  
  35. // @see Meta_Boxes::save_meta_boxes() 
  36. wp_nonce_field( 'simcal_save_data', 'simcal_meta_nonce' ); 
  37.  
  38. ?> 
  39. <div class="simcal-panels-wrap"> 
  40.  
  41. <span class="simcal-box-handle"> 
  42. <?php self::settings_handle( $post ); ?> 
  43. </span> 
  44.  
  45. <ul class="simcal-tabs"> 
  46. <?php self::settings_tabs( $post ); ?> 
  47. <?php do_action( 'simcal_settings_meta_tabs' ); ?> 
  48. </ul> 
  49.  
  50. <div class="simcal-panels"> 
  51. <div id="events-settings-panel" class="simcal-panel"> 
  52. <?php self::events_settings_panel( $post ); ?> 
  53. <?php do_action( 'simcal_settings_meta_events_panel', $post->ID ); ?> 
  54. </div> 
  55. <div id="calendar-settings-panel" class="simcal-panel"> 
  56. <?php do_action( 'simcal_settings_meta_calendar_panel', $post->ID ); ?> 
  57. <?php self::calendar_settings_panel( $post ); ?> 
  58. </div> 
  59. <?php 
  60. // Hook for additional settings panels. 
  61. do_action( 'simcal_settings_meta_panels', $post->ID ); 
  62. // Thus advanced panel is always the last one: 
  63. ?> 
  64. <div id="advanced-settings-panel" class="simcal-panel"> 
  65. <?php self::advanced_settings_panel( $post ) ?> 
  66. <?php do_action( 'simcal_settings_meta_advanced_panel', $post->ID ); ?> 
  67. </div> 
  68. </div> 
  69.  
  70. <div class="clear"> 
  71. </div> 
  72.  
  73. </div> 
  74. <?php 
  75.  
  76.  
  77. /** 
  78. * Print the meta box settings handle. 
  79. * 
  80. * @since 3.0.0 
  81. * @access private 
  82. * 
  83. * @param \WP_Post $post 
  84. */ 
  85. private static function settings_handle( $post ) { 
  86.  
  87. $feed_options = $calendar_options = $calendar_views = array(); 
  88.  
  89. $feed_types = simcal_get_feed_types(); 
  90. foreach ( $feed_types as $feed_type ) { 
  91.  
  92. $feed = simcal_get_feed( $feed_type ); 
  93.  
  94. if ( $feed instanceof Feed ) { 
  95. $feed_options[ $feed_type ] = $feed->name; 
  96.  
  97. $calendar_types = simcal_get_calendar_types(); 
  98. foreach ( $calendar_types as $calendar_type => $views ) { 
  99.  
  100. $calendar = simcal_get_calendar( $calendar_type ); 
  101.  
  102. if ( $calendar instanceof Calendar ) { 
  103. $calendar_options[ $calendar_type ] = $calendar->name; 
  104. $calendar_views[ $calendar_type ] = $calendar->views; 
  105.  
  106. if ( $feed_options ) { 
  107.  
  108. if ( $feed_types = wp_get_object_terms( $post->ID, 'calendar_feed' ) ) { 
  109. $feed_type = sanitize_title( current( $feed_types )->name ); 
  110. } else { 
  111. $feed_type = apply_filters( 'simcal_default_feed_type', 'google' ); 
  112.  
  113. ?> 
  114. <label for="_feed_type"><span><?php _e( 'Event Source', 'google-calendar-events' ); ?></span> 
  115. <select name="_feed_type" id="_feed_type"> 
  116. <optgroup label="<?php _ex( 'Get events from', 'From which calendar source to load events from', 'google-calendar-events' ) ?>"> 
  117. <?php foreach ( $feed_options as $feed => $name ) { ?> 
  118. <option value="<?php echo $feed; ?>" <?php selected( $feed, $feed_type, true ); ?>><?php echo $name; ?></option> 
  119. <?php } ?> 
  120. </optgroup> 
  121. </select> 
  122. </label> 
  123. <?php 
  124.  
  125.  
  126. if ( $calendar_options ) { 
  127.  
  128. if ( $calendar_types = wp_get_object_terms( $post->ID, 'calendar_type' ) ) { 
  129. $calendar_type = sanitize_title( current( $calendar_types )->name ); 
  130. } else { 
  131. $calendar_type = apply_filters( 'simcal_default_calendar_type', 'default-calendar' ); 
  132.  
  133. ?> 
  134. <label for="_calendar_type"><span><?php _e( 'Calendar Type', 'google-calendar-events' ); ?></span> 
  135. <select name="_calendar_type" id="_calendar_type"> 
  136. <optgroup label="<?php _e( 'Calendar to use', 'google-calendar-events' ); ?>"> 
  137. <?php foreach ( $calendar_options as $calendar => $name ) { ?> 
  138. <option value="<?php echo $calendar; ?>" <?php selected( $calendar, $calendar_type, true ); ?>><?php echo $name; ?></option> 
  139. <?php } ?> 
  140. </optgroup> 
  141. </select> 
  142. </label> 
  143. <?php 
  144.  
  145. if ( $calendar_views ) { 
  146.  
  147. $calendar_view = get_post_meta( $post->ID, '_calendar_view', true ); 
  148.  
  149. foreach ( $calendar_views as $calendar => $views ) { 
  150.  
  151. $calendar_type_view = isset( $calendar_view[ $calendar ] ) ? $calendar_view[ $calendar ] : ''; 
  152.  
  153. ?> 
  154. <label for="_calendar_view_<?php echo $calendar; ?>"><span><?php _e( 'View', 'google-calendar-events' ); ?></span> 
  155. <select name="_calendar_view[<?php echo $calendar; ?>]" id="_calendar_view_<?php echo $calendar; ?>"> 
  156. <optgroup label="<?php _e( 'View to display', 'google-calendar-events' ); ?>"> 
  157. <?php foreach ( $views as $view => $name ) { ?> 
  158. <option value="<?php echo $view; ?>" <?php selected( $view, $calendar_type_view, true ); ?>><?php echo $name; ?></option> 
  159. <?php } ?> 
  160. </optgroup> 
  161. </select> 
  162. </label> 
  163. <?php 
  164.  
  165.  
  166. /** 
  167. * Print settings tabs. 
  168. * 
  169. * @since 3.0.0 
  170. * @access private 
  171. * 
  172. * @param \WP_Post $post 
  173. */ 
  174. private static function settings_tabs( $post ) { 
  175.  
  176. // Hook to add more tabs. 
  177. $tabs = apply_filters( 'simcal_settings_meta_tabs_li', array( 
  178. 'events' => array( 
  179. 'label' => __( 'Events', 'google-calendar-events' ),  
  180. 'target' => 'events-settings-panel',  
  181. 'class' => array( 'active' ),  
  182. 'icon' => 'simcal-icon-event',  
  183. ),  
  184. 'calendar' => array( 
  185. 'label' => __( 'Appearance', 'google-calendar-events' ),  
  186. 'target' => 'calendar-settings-panel',  
  187. 'class' => array(),  
  188. 'icon' => 'simcal-icon-calendar',  
  189. ),  
  190. ), $post->ID ); 
  191.  
  192. // Always keep advanced tab as the last one. 
  193. $tabs['advanced'] = array( 
  194. 'label' => __( 'Advanced', 'google-calendar-events' ),  
  195. 'target' => 'advanced-settings-panel',  
  196. 'class' => array(),  
  197. 'icon' => 'simcal-icon-settings',  
  198. ); 
  199.  
  200. // Output the tabs as list items. 
  201. foreach ( $tabs as $key => $tab ) { 
  202.  
  203. if ( isset( $tab['target'] ) && isset( $tab['label'] ) ) { 
  204.  
  205. $icon = $tab['icon'] ? $tab['icon'] : 'simcal-icon-panel'; 
  206. $class = $tab['class'] ? $tab['class'] : array(); 
  207.  
  208. echo '<li class="' . $key . '-settings ' . $key . '-tab ' . implode( ' ', $class ) . '" data-tab="' . $key . '">'; 
  209. echo '<a href="#' . $tab['target'] . '"><i class="' . $icon . '" ></i> <span>' . esc_html( $tab['label'] ) . '</span></a>'; 
  210. echo '</li>'; 
  211.  
  212. /** 
  213. * Print events settings panel. 
  214. * 
  215. * @since 3.0.0 
  216. * @access private 
  217. * 
  218. * @param \WP_Post $post 
  219. */ 
  220. private static function events_settings_panel( $post ) { 
  221.  
  222. ?> 
  223. <table> 
  224. <thead> 
  225. <tr><th colspan="2"><?php _e( 'Event Settings', 'google-calendar-events' ); ?></th></tr> 
  226. </thead> 
  227. <tbody class="simcal-panel-section simcal-panel-section-events-range"> 
  228. <tr class="simcal-panel-field"> 
  229. <th><label for="_calendar_begins"><?php _e( 'Calendar Start', 'google-calendar-events' ); ?></label></th> 
  230. <td> 
  231. <?php 
  232.  
  233. $calendar_begins = esc_attr( get_post_meta( $post->ID, '_calendar_begins', true ) ); 
  234. $calendar_begins_nth = max( absint( get_post_meta( $post->ID, '_calendar_begins_nth', true ) ), 1 ); 
  235. $calendar_begins_nth_show = in_array( $calendar_begins, array( 
  236. 'days_before',  
  237. 'days_after',  
  238. 'weeks_before',  
  239. 'weeks_after',  
  240. 'months_before',  
  241. 'months_after',  
  242. 'years_before',  
  243. 'years_after',  
  244. ) ); 
  245.  
  246. simcal_print_field( array( 
  247. 'type' => 'standard',  
  248. 'subtype' => 'number',  
  249. 'name' => '_calendar_begins_nth',  
  250. 'id' => '_calendar_begins_nth',  
  251. 'value' => strval( $calendar_begins_nth ),  
  252. 'attributes' => array( 
  253. 'min' => '1',  
  254. ),  
  255. 'class' => array( 
  256. 'simcal-field-inline',  
  257. 'simcal-field-tiny',  
  258. ),  
  259. 'style' => ! $calendar_begins_nth_show ? array( 'display' => 'none' ) : '',  
  260. ) ); 
  261.  
  262. ?> 
  263. <select name="_calendar_begins" 
  264. id="_calendar_begins" 
  265. class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> 
  266. <optgroup label="<?php _e( 'Days', 'google-calendar-events' ); ?>"> 
  267. <option value="today" 
  268. data-hide-fields="_calendar_begins_custom_date, _calendar_begins_nth" 
  269. <?php selected( 'today', $calendar_begins, true ); ?>><?php _e( 'Today', 'google-calendar-events' ); ?></option> 
  270. <option value="now" 
  271. data-hide-fields="_calendar_begins_custom_date, _calendar_begins_nth" 
  272. <?php selected( 'now', $calendar_begins, true ); ?>><?php _e( 'Now', 'google-calendar-events' ); ?></option> 
  273. <option value="days_before" 
  274. data-hide-field="_calendar_begins_custom_date" 
  275. data-show-field="_calendar_begins_nth" <?php selected( 'days_before', $calendar_begins, true ); ?>><?php _e( 'Day(s) before today', 'google-calendar-events' ); ?></option> 
  276. <option value="days_after" 
  277. data-hide-field="_calendar_begins_custom_date" 
  278. data-show-field="_calendar_begins_nth" <?php selected( 'days_after', $calendar_begins, true ); ?>><?php _e( 'Day(s) after today', 'google-calendar-events' ); ?></option> 
  279. </optgroup> 
  280. <optgroup label="<?php _e( 'Weeks', 'google-calendar-events' ); ?>"> 
  281. <option value="this_week" 
  282. data-hide-fields="_calendar_begins_custom_date, _calendar_begins_nth" 
  283. <?php selected( 'this_week', $calendar_begins, true ); ?>><?php _e( 'This week', 'google-calendar-events' ); ?></option> 
  284. <option value="weeks_before" 
  285. data-hide-field="_calendar_begins_custom_date" 
  286. data-show-field="_calendar_begins_nth" <?php selected( 'weeks_before', $calendar_begins, true ); ?>><?php _e( 'Week(s) before current', 'google-calendar-events' ); ?></option> 
  287. <option value="weeks_after" 
  288. data-hide-field="_calendar_begins_custom_date" 
  289. data-show-field="_calendar_begins_nth" <?php selected( 'weeks_after', $calendar_begins, true ); ?>><?php _e( 'Week(s) after current', 'google-calendar-events' ); ?></option> 
  290. </optgroup> 
  291. <optgroup label="<?php _e( 'Months', 'google-calendar-events' ); ?>"> 
  292. <option value="this_month" 
  293. data-hide-fields="_calendar_begins_custom_date, _calendar_begins_nth" 
  294. <?php selected( 'this_month', $calendar_begins, true ); ?>><?php _e( 'This month', 'google-calendar-events' ); ?></option> 
  295. <option value="months_before" 
  296. data-hide-field="_calendar_begins_custom_date" 
  297. data-show-field="_calendar_begins_nth" <?php selected( 'months_before', $calendar_begins, true ); ?>><?php _e( 'Month(s) before current', 'google-calendar-events' ); ?></option> 
  298. <option value="months_after" 
  299. data-hide-field="_calendar_begins_custom_date" 
  300. data-show-field="_calendar_begins_nth" <?php selected( 'months_after', $calendar_begins, true ); ?>><?php _e( 'Month(s) after current', 'google-calendar-events' ); ?></option> 
  301. </optgroup> 
  302. <optgroup label="<?php _e( 'Years', 'google-calendar-events' ); ?>"> 
  303. <option value="this_year" 
  304. data-hide-fields="_calendar_begins_custom_date, _calendar_begins_nth" 
  305. <?php selected( 'this_year', $calendar_begins, true ); ?>><?php _e( 'This year', 'google-calendar-events' ); ?></option> 
  306. <option value="years_before" 
  307. data-show-field="_calendar_begins_nth" <?php selected( 'years_before', $calendar_begins, true ); ?>><?php _e( 'Year(s) before current', 'google-calendar-events' ); ?></option> 
  308. <option value="years_after" 
  309. data-hide-field="_calendar_begins_custom_date" 
  310. data-show-field="_calendar_begins_nth" <?php selected( 'years_after', $calendar_begins, true ); ?>><?php _e( 'Year(s) after current', 'google-calendar-events' ); ?></option> 
  311. </optgroup> 
  312. <optgroup label="<?php _e( 'Other', 'google-calendar-events' ); ?>"> 
  313. <option value="custom_date" 
  314. data-hide-field="_calendar_begins_nth" 
  315. data-show-field="_calendar_begins_custom_date" <?php selected( 'custom_date', $calendar_begins, true ); ?>><?php _e( 'Specific date', 'google-calendar-events' ); ?></option> 
  316. </optgroup> 
  317. </select> 
  318. <?php 
  319.  
  320. simcal_print_field( array( 
  321. 'type' => 'date-picker',  
  322. 'name' => '_calendar_begins_custom_date',  
  323. 'id' => '_calendar_begins_custom_date',  
  324. 'value' => get_post_meta( $post->ID, '_calendar_begins_custom_date', true ),  
  325. 'class' => array( 
  326. 'simcal-field-inline',  
  327. ),  
  328. 'style' => 'custom_date' != $calendar_begins ? array( 'display' => 'none' ) : '',  
  329. ) ); 
  330.  
  331. ?> 
  332. <i class="simcal-icon-help simcal-help-tip" 
  333. data-tip="<?php _e( 'The calendar default opening date. It will automatically adapt based on the chosen calendar type.', 'google-calendar-events' ); ?>"></i> 
  334. </td> 
  335. </tr> 
  336. <tr class="simcal-panel-field"> 
  337. <th><label for="_feed_earliest_event_date"><?php _e( 'Earliest Event', 'google-calendar-events' ); ?></label></th> 
  338. <td> 
  339. <?php 
  340.  
  341. $earliest_event_saved = get_post_meta( $post->ID, '_feed_earliest_event_date', true ); 
  342. $earliest_event = false == $earliest_event_saved ? 'months_before' : esc_attr( $earliest_event_saved ); 
  343.  
  344. simcal_print_field( array( 
  345. 'type' => 'standard',  
  346. 'subtype' => 'number',  
  347. 'name' => '_feed_earliest_event_date_range',  
  348. 'id' => '_feed_earliest_event_date_range',  
  349. 'value' => strval( max( absint( get_post_meta( $post->ID, '_feed_earliest_event_date_range', true ) ), 1 ) ),  
  350. 'attributes' => array( 
  351. 'min' => '1',  
  352. ),  
  353. 'class' => array( 
  354. 'simcal-field-inline',  
  355. 'simcal-field-tiny',  
  356. ),  
  357. 'style' => ( 'now' != $earliest_event ) && ( 'today' != $earliest_event ) ? array( 'display' => 'none' ) : '',  
  358. ) ); 
  359.  
  360. ?> 
  361. <select name="_feed_earliest_event_date" 
  362. id="_feed_earliest_event_date" 
  363. class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> 
  364. <option value="calendar_start" data-hide-field="_feed_earliest_event_date_range" <?php selected( 'calendar_start', $earliest_event, true ); ?>><?php _e( 'Same as start date', 'google-calendar-events' ); ?></option> 
  365. <option value="days_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'days_before', $earliest_event, true ); ?>><?php _e( 'Day(s) before start date', 'google-calendar-events' ); ?></option> 
  366. <option value="weeks_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'weeks_before', $earliest_event, true ); ?>><?php _e( 'Week(s) before start date', 'google-calendar-events' ); ?></option> 
  367. <option value="months_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'months_before', $earliest_event, true ); ?>><?php _e( 'Month(s) before start date', 'google-calendar-events' ); ?></option> 
  368. <option value="years_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'years_before', $earliest_event, true ); ?>><?php _e( 'Year(s) before start date', 'google-calendar-events' ); ?></option> 
  369. </select> 
  370. <i class="simcal-icon-help simcal-help-tip" 
  371. data-tip="<?php _e( 'Set the date for the earliest possible event to show in calendar. There will not be events before this date.', 'google-calendar-events' ); ?>"></i> 
  372. </td> 
  373. </tr> 
  374. <tr class="simcal-panel-field"> 
  375. <th><label for="_feed_latest_event_date"><?php _e( 'Latest Event', 'google-calendar-events' ); ?></label></th> 
  376. <td> 
  377. <?php 
  378.  
  379. $latest_event_saved = get_post_meta( $post->ID, '_feed_latest_event_date', true ); 
  380. $latest_event = false == $latest_event_saved ? 'years_after' : esc_attr( $latest_event_saved ); 
  381.  
  382. simcal_print_field( array( 
  383. 'type' => 'standard',  
  384. 'subtype' => 'number',  
  385. 'name' => '_feed_latest_event_date_range',  
  386. 'id' => '_feed_latest_event_date_range',  
  387. 'value' => strval( max( absint( get_post_meta( $post->ID, '_feed_latest_event_date_range', true ) ), 1 ) ),  
  388. 'attributes' => array( 
  389. 'min' => '1',  
  390. ),  
  391. 'class' => array( 
  392. 'simcal-field-inline',  
  393. 'simcal-field-tiny',  
  394. ),  
  395. 'style' => 'indefinite' != $latest_event ? array( 'display' => 'none' ) : '',  
  396. ) ); 
  397.  
  398. ?> 
  399. <select name="_feed_latest_event_date" 
  400. id="_feed_latest_event_date" 
  401. class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> 
  402. <option value="calendar_start" data-hide-field="_feed_latest_event_date_range" <?php selected( 'calendar_start', $earliest_event, true ); ?>><?php _e( 'Day end of start date', 'google-calendar-events' ); ?></option> 
  403. <option value="days_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'days_after', $latest_event, true ); ?>><?php _e( 'Day(s) after start date', 'google-calendar-events' ); ?></option> 
  404. <option value="weeks_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'weeks_after', $latest_event, true ); ?>><?php _e( 'Weeks(s) after start date', 'google-calendar-events' ); ?></option> 
  405. <option value="months_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'months_after', $latest_event, true ); ?>><?php _e( 'Month(s) after start date', 'google-calendar-events' ); ?></option> 
  406. <option value="years_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'years_after', $latest_event, true ); ?>><?php _e( 'Year(s) after start date', 'google-calendar-events' ); ?></option> 
  407. </select> 
  408. <i class="simcal-icon-help simcal-help-tip" 
  409. data-tip="<?php _e( 'Set the date for the latest possible event to show on calendar. There will not be events after this date.', 'google-calendar-events' ); ?>"></i> 
  410. </td> 
  411. </tr> 
  412. </tbody> 
  413. </table> 
  414. <?php 
  415.  
  416.  
  417. /** 
  418. * Print the calendar settings panel. 
  419. * 
  420. * @since 3.0.0 
  421. * @access private 
  422. * 
  423. * @param \WP_Post $post 
  424. */ 
  425. private static function calendar_settings_panel( $post ) { 
  426.  
  427. ?> 
  428. <table> 
  429. <thead> 
  430. <tr><th colspan="2"><?php _e( 'Miscellaneous', 'google-calendar-events' ); ?></th></tr> 
  431. </thead> 
  432. <tbody class="simcal-panel-section"> 
  433. <tr class="simcal-panel-field"> 
  434. <th><label for="_calendar_is_static"><?php _e( 'Static Calendar', 'google-calendar-events' ); ?></label></th> 
  435. <td> 
  436. <?php 
  437.  
  438. $fixed = get_post_meta( $post->ID, '_calendar_is_static', true ); 
  439.  
  440. simcal_print_field( array( 
  441. 'type' => 'checkbox',  
  442. 'name' => '_calendar_is_static',  
  443. 'id' => '_calendar_is_static',  
  444. 'tooltip' => __( 'Remove the navigation arrows and fix the calendar view to its initial state.', 'google-calendar-events' ),  
  445. 'value' => 'yes' == $fixed ? 'yes' : 'no',  
  446. 'text' => __( 'Yes (hide navigation arrows)', 'google-calendar-events' ),  
  447. ) ); 
  448.  
  449. ?> 
  450. </td> 
  451. </tr> 
  452. <tr class="simcal-panel-field"> 
  453. <th><label for="_no_events_message"><?php _e( 'No Events Message', 'google-calendar-events' ); ?></label></th> 
  454. <td> 
  455. <?php 
  456.  
  457. simcal_print_field( array( 
  458. 'type' => 'textarea',  
  459. 'name' => '_no_events_message',  
  460. 'id' => '_no_events_message',  
  461. 'tooltip' => __( 'Some calendars may display a message when no events are found. You can change the default message here.', 'google-calendar-events' ),  
  462. 'value' => get_post_meta( $post->ID, '_no_events_message', true ),  
  463. 'placeholder' => __( 'There are no upcoming events.', 'google-calendar-events' ),  
  464. ) ); 
  465.  
  466. ?> 
  467. </td> 
  468. </tr> 
  469. <tr class="simcal-panel-field"> 
  470. <th><label for="_event_formatting"><?php _e( 'Event Formatting', 'google-calendar-events' ); ?></label></th> 
  471. <td> 
  472. <?php 
  473.  
  474. $event_formatting = get_post_meta( $post->ID, '_event_formatting', true ); 
  475.  
  476. simcal_print_field( array( 
  477. 'type' => 'select',  
  478. 'name' => '_event_formatting',  
  479. 'id' => '_event_formatting',  
  480. 'tooltip' => __( 'How to preserve line breaks and paragraphs in the event template builder.', 'google-calendar-events' ),  
  481. 'value' => $event_formatting,  
  482. 'default' => 'preserve_linebreaks',  
  483. 'options' => array( 
  484. 'preserve_linebreaks' => __( 'Preserve line breaks, auto paragraphs (default)', 'google-calendar-events' ),  
  485. 'no_linebreaks' => __( 'No line breaks, auto paragraphs', 'google-calendar-events' ),  
  486. 'none' => __( 'No line breaks, no auto paragraphs', 'google-calendar-events' ),  
  487. ),  
  488. ) ); 
  489.  
  490. ?> 
  491. </td> 
  492. </tr> 
  493. <tr class="simcal-panel-field"> 
  494. <th><label for="_poweredby"><?php _e( 'Powered By', 'google-calendar-events' ); ?></label></th> 
  495. <td> 
  496. <?php 
  497.  
  498. $poweredby = get_post_meta( $post->ID, '_poweredby', true ); 
  499.  
  500. simcal_print_field( array( 
  501. 'type' => 'checkbox',  
  502. 'name' => '_poweredby',  
  503. 'id' => '_poweredby',  
  504. 'value' => 'yes' == $poweredby ? 'yes' : 'no',  
  505. 'text' => __( 'Yes, Simple Calendar rocks! Show some love with a little link below this calendar.', 'google-calendar-events' ),  
  506. ) ); 
  507.  
  508. ?> 
  509. </td> 
  510. </tr> 
  511. </tbody> 
  512. </table> 
  513. <?php 
  514.  
  515.  
  516. /** 
  517. * Print the advanced settings panel. 
  518. * 
  519. * @since 3.0.0 
  520. * @access private 
  521. * 
  522. * @param \WP_Post $post 
  523. */ 
  524. private static function advanced_settings_panel( $post ) { 
  525.  
  526. ?> 
  527. <table> 
  528. <thead> 
  529. <tr><th colspan="2"><?php _e( 'Date and Time', 'google-calendar-events' ); ?></th></tr> 
  530. </thead> 
  531. <tbody class="simcal-panel-section simcal-panel-datetime-formatting"> 
  532. <tr class="simcal-panel-field"> 
  533. <th><label for="_calendar_timezone_setting"><?php _e( 'Timezone', 'google-calendar-events' ); ?></label></th> 
  534. <td> 
  535. <?php 
  536.  
  537. $timezone_wordpress = simcal_get_wp_timezone(); 
  538. $timezone_default = $timezone_wordpress ? $timezone_wordpress : 'UTC'; 
  539. $timezone_setting = esc_attr( get_post_meta( $post->ID, '_feed_timezone_setting', true ) ); 
  540. $timezone = esc_attr( get_post_meta( $post->ID, '_feed_timezone', true ) ); 
  541. $timezone = $timezone ? $timezone : $timezone_default; 
  542. $show_use_calendar = isset( simcal_get_feed( $post )->type ); 
  543.  
  544. if ( $show_use_calendar ) { 
  545. $show_use_calendar = ( simcal_get_feed( $post )->type !== 'grouped-calendars' ? 1 : 0 ); 
  546. } else { 
  547. $show_use_calendar = true; 
  548.  
  549. ?> 
  550. <select name="_feed_timezone_setting" 
  551. id="_feed_timezone_setting" 
  552. class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" 
  553. data-show-field-on-choice="true"> 
  554. <option value="use_site" <?php selected( 'use_site', $timezone_setting, true ); ?>><?php printf( _x( 'Site default', 'Use this site default setting', 'google-calendar-events' ) . ' (%s)', $timezone_default ); ?></option> 
  555. <?php if ( $show_use_calendar ) { ?> 
  556. <option id="use_calendar" value="use_calendar" data-show-field="_use_calendar_warning" <?php selected( 'use_calendar', $timezone_setting, true ); ?>><?php _ex( 'Event source default', 'Use the calendar default setting', 'google-calendar-events' ); ?></option> 
  557. <?php } ?> 
  558. <option value="use_custom" data-show-field="_feed_timezone" <?php selected( 'use_custom', $timezone_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> 
  559. </select> 
  560. <select name="_feed_timezone" 
  561. id="_feed_timezone" 
  562. class="simcal-field simcal-field-select simcal-field-inline" 
  563. <?php echo 'use_custom' != $timezone_setting ? 'style="display: none;"' : ''; ?>> 
  564. <?php echo wp_timezone_choice( $timezone ); ?> 
  565. </select> 
  566. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Using a different timezone may alter the date and time display of your calendar events. We recommended using the site default timezone.', 'google-calendar-events' ); ?>"></i> 
  567. <p id="_use_calendar_warning" style="display: none;" class="simcal-field"> 
  568. <span class="attention"><?php _e( 'Warning', 'google-calendar-events' ); ?>:</span> 
  569. <?php _e( 'Setting this to <code>Event source default</code> can at times cause unexpected results. Please test thoroughly.', 'google-calendar-events' ); ?> 
  570. <a href="http://docs.simplecalendar.io/timezone-settings/" target="_blank"><?php _e( 'See details.', 'google-calendar-events' ); ?></a> 
  571. </p> 
  572. </td> 
  573. </tr> 
  574. <tr class="simcal-panel-field"> 
  575. <th><label for="_calendar_date_format_setting"><?php _e( 'Date Format', 'google-calendar-events' ); ?></label></th> 
  576. <td> 
  577. <?php 
  578.  
  579. $date_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_setting', true ) ); 
  580. $date_format_default = esc_attr( get_option( 'date_format' ) ); 
  581. $date_format = esc_attr( get_post_meta( $post->ID, '_calendar_date_format', true ) ); 
  582. $date_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_php', true ) ); 
  583. $date_format_php = $date_format_php ? $date_format_php : $date_format_default; 
  584.  
  585. ?> 
  586. <select name="_calendar_date_format_setting" 
  587. id="_calendar_date_format_setting" 
  588. class="simcal-field simcal-field-select simcal-field-show-other"> 
  589. <option value="use_site" data-show-field="_calendar_date_format_default" <?php selected( 'use_site', $date_format_setting, true ); ?>><?php _ex( 'Site default', 'Use this site default setting', 'google-calendar-events' ); ?></option> 
  590. <option value="use_custom" data-show-field="_calendar_date_format" <?php selected( 'use_custom', $date_format_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> 
  591. <option value="use_custom_php" data-show-field="_calendar_date_format_php_field" <?php selected( 'use_custom_php', $date_format_setting, true ); ?>><?php _e( 'Custom (PHP format)', 'google-calendar-events' ); ?></option> 
  592. </select> 
  593. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'This option sets how calendars display event dates. It is recommended to keep your site default setting.', 'google-calendar-events' ); ?>"></i> 
  594. <p id="_calendar_date_format_default" style="<?php echo $date_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> 
  595. <em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em>   
  596. <code><?php echo date_i18n( $date_format_default, time() ); ?></code> 
  597. </p> 
  598. <?php simcal_print_field( array( 
  599. 'type' => 'datetime-format',  
  600. 'subtype' => 'date',  
  601. 'name' => '_calendar_date_format',  
  602. 'id' => '_calendar_date_format',  
  603. 'value' => $date_format,  
  604. 'style' => $date_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '',  
  605. ) ); ?> 
  606. <div class="simcal-field-datetime-format-php" id="_calendar_date_format_php_field" style="<?php echo $date_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> 
  607. <br> 
  608. <label for="_calendar_date_format_php"> 
  609. <input type="text" 
  610. name="_calendar_date_format_php" 
  611. id="_calendar_date_format_php" 
  612. class="simcal-field simcal-field-text simcal-field-small" 
  613. value="<?php echo $date_format_php; ?>" /> 
  614. <?php printf( __( 'Enter a date format using %s values.', 'google-calendar-events' ), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>' ); ?> 
  615. </label> 
  616. <p> 
  617. <em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em>   
  618. <code><?php echo date_i18n( $date_format_php, time() ); ?></code> 
  619. </p> 
  620. </div> 
  621. </td> 
  622. </tr> 
  623. <tr class="simcal-panel-field"> 
  624. <th><label for="_calendar_datetime_separator"><?php _e( 'Separator', 'google-calendar-events' ); ?></label></th> 
  625. <td> 
  626. <?php 
  627.  
  628. $separator = get_post_meta( $post->ID, '_calendar_datetime_separator', true ); 
  629. $separator = false == $separator ? '@' : $separator; 
  630.  
  631. simcal_print_field( array( 
  632. 'type' => 'standard',  
  633. 'subtype' => 'text',  
  634. 'name' => '_calendar_datetime_separator',  
  635. 'id' => '_calendar_datetime_separator',  
  636. 'value' => $separator,  
  637. 'tooltip' => __( 'Used to divide date and time when both are shown.', 'google-calendar-events' ),  
  638. 'class' => array( 
  639. 'simcal-field-tiny',  
  640. ),  
  641. ) ); 
  642.  
  643. ?> 
  644. </td> 
  645. </tr> 
  646. <tr class="simcal-panel-field"> 
  647. <th><label for="_calendar_time_format_setting"><?php _e( 'Time Format', 'google-calendar-events' ); ?></label></th> 
  648. <td> 
  649. <?php 
  650.  
  651. $time_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_setting', true ) ); 
  652. $time_format_default = esc_attr( get_option( 'time_format' ) ); 
  653. $time_format = esc_attr( get_post_meta( $post->ID, '_calendar_time_format', true ) ); 
  654. $time_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_php', true ) ); 
  655. $time_format_php = $time_format_php ? $time_format_php : $time_format_default; 
  656.  
  657. ?> 
  658. <select name="_calendar_time_format_setting" 
  659. id="_calendar_time_format_setting" 
  660. class="simcal-field simcal-field-select simcal-field-show-other"> 
  661. <option value="use_site" data-show-field="_calendar_time_format_default" <?php selected( 'use_site', $time_format_setting, true ); ?>><?php _ex( 'Site default', 'Use this site default setting', 'google-calendar-events' ); ?></option> 
  662. <option value="use_custom" data-show-field="_calendar_time_format" <?php selected( 'use_custom', $time_format_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> 
  663. <option value="use_custom_php" data-show-field="_calendar_time_format_php_field" <?php selected( 'use_custom_php', $time_format_setting, true ); ?>><?php _e( 'Custom (PHP format)', 'google-calendar-events' ); ?></option> 
  664. </select> 
  665. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'This option sets how calendars display event times. It is recommended to keep your site default setting.', 'google-calendar-events' ); ?>"></i> 
  666. <p id="_calendar_time_format_default" style="<?php echo $time_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> 
  667. <em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em>   
  668. <code><?php echo date_i18n( $time_format_default, time() ); ?></code> 
  669. </p> 
  670. <?php simcal_print_field( array( 
  671. 'type' => 'datetime-format',  
  672. 'subtype' => 'time',  
  673. 'name' => '_calendar_time_format',  
  674. 'id' => '_calendar_time_format',  
  675. 'value' => $time_format,  
  676. 'style' => $time_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '',  
  677. ) ); ?> 
  678. <div class="simcal-field-datetime-format-php" id="_calendar_time_format_php_field" style="<?php echo $time_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> 
  679. <br> 
  680. <label for="_calendar_date_format_php"> 
  681. <input type="text" 
  682. name="_calendar_time_format_php" 
  683. id="_calendar_time_format_php" 
  684. class="simcal-field simcal-field-text simcal-field-small" 
  685. value="<?php echo $time_format_php; ?>"/> 
  686. <?php printf( __( 'Enter a time format using %s values.', 'google-calendar-events' ), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>' ); ?> 
  687. </label> 
  688. <p> 
  689. <em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em>   
  690. <code><?php echo date_i18n( $time_format_php, time() ); ?></code> 
  691. </p> 
  692. </div> 
  693. </td> 
  694. </tr> 
  695. <tr class="simcal-panel-field"> 
  696. <th><label for="_calendar_week_starts_on_setting"><?php _e( 'Week Starts On', 'google-calendar-events' ); ?></label></th> 
  697. <td> 
  698. <?php 
  699.  
  700. $week_starts_setting = esc_attr( get_post_meta( $post->ID, '_calendar_week_starts_on_setting', true ) ); 
  701. $week_starts_default = esc_attr( get_option( 'start_of_week' ) ); 
  702. $week_starts = intval( get_post_meta( $post->ID, '_calendar_week_starts_on', true ) ); 
  703. $week_starts = is_numeric( $week_starts ) ? strval( $week_starts ) : $week_starts_default; 
  704.  
  705. ?> 
  706. <select 
  707. name="_calendar_week_starts_on_setting" 
  708. id="_calendar_week_starts_on_setting" 
  709. class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-next" 
  710. data-show-next-if-value="use_custom"> 
  711. <option value="use_site" <?php selected( 'use_site', $week_starts_setting, true ); ?>><?php printf( _x( 'Site default', 'Use this site default setting', 'google-calendar-events' ) . ' (%s)', date_i18n( 'l', strtotime( "Sunday + $week_starts_default Days" ) ) ); ?></option> 
  712. <option value="use_custom" <?php selected( 'use_custom', $week_starts_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> 
  713. </select> 
  714. <select 
  715. name="_calendar_week_starts_on" 
  716. id="_calendar_week_starts_on" 
  717. class="simcal-field simcal-field-select simcal-field-inline" 
  718. <?php echo 'use_custom' != $week_starts_setting ? 'style="display: none;"' : ''; ?>> 
  719. <?php $day_names = simcal_get_calendar_names_i18n( 'day', 'full' ); ?> 
  720. <?php for ( $i = 0; $i <= 6; $i++ ) : ?> 
  721. <option value="<?php echo $i; ?>" <?php selected( $i, $week_starts, true ); ?>><?php echo $day_names[ $i ]; ?></option> 
  722. <?php endfor; ?> 
  723. </select> 
  724. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Some calendars may use this setting to display the start of the week. It is recommended to keep the site default setting.', 'google-calendar-events' ); ?>"></i> 
  725. </td> 
  726. </tr> 
  727. </tbody> 
  728. </table> 
  729. <table> 
  730. <thead> 
  731. <tr><th colspan="2"><?php _e( 'Cache', 'google-calendar-events' ); ?></th></tr> 
  732. </thead> 
  733. <tbody class="simcal-panel-section simcal-panel-section-cache"> 
  734. <?php 
  735.  
  736. $cache_freq = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_amount', true ) ); 
  737. $cache_unit = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_unit', true ) ); 
  738.  
  739. $cache_freq = intval( $cache_freq ) && $cache_freq >= 0 ? $cache_freq : 2; 
  740. $cache_unit = $cache_unit ? $cache_unit : '3600'; 
  741.  
  742. ?> 
  743. <tr class="simcal-panel-field"> 
  744. <th><label for="_feed_cache_user_amount"><?php _ex( 'Refresh Interval', 'Cache maximum interval', 'google-calendar-events' ); ?></label></th> 
  745. <td> 
  746. <input type="number" 
  747. name="_feed_cache_user_amount" 
  748. id="_feed_cache_user_amount" 
  749. class="simcal-field simcal-field-number simcal-field-tiny simcal-field-inline" 
  750. value="<?php echo $cache_freq; ?>" 
  751. min="0" /> 
  752. <select name="_feed_cache_user_unit" 
  753. id="_feed_cache_user_unit" 
  754. class="simcal-field simcalfield-select simcal-field-inline"> 
  755. <option value="60" <?php selected( '60', $cache_unit, true ); ?>><?php _e( 'Minute(s)', 'google-calendar-events' ); ?></option> 
  756. <option value="3600" <?php selected( '3600', $cache_unit, true ); ?>><?php _e( 'Hour(s)', 'google-calendar-events' ); ?></option> 
  757. <option value="86400" <?php selected( '86400', $cache_unit, true ); ?>><?php _e( 'Day(s)', 'google-calendar-events' ); ?></option> 
  758. <option value="604800" <?php selected( '604800', $cache_unit, true ); ?>><?php _e( 'Week(s)', 'google-calendar-events' ); ?></option> 
  759. </select> 
  760. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'If you add, edit or remove events in your calendar very often, you can set a lower interval to refresh the events displayed. Set a higher interval for best performance.', 'google-calendar-events' ); ?>"></i> 
  761. </td> 
  762. </tr> 
  763. </tbody> 
  764. </table> 
  765. <?php 
  766.  
  767.  
  768. /** 
  769. * Print fields in a panel. 
  770. * 
  771. * @since 3.0.0 
  772. * 
  773. * @param array $array 
  774. * @param int $post_id 
  775. * 
  776. * @return void 
  777. */ 
  778. public static function print_panel_fields( $array, $post_id ) { 
  779.  
  780. foreach ( $array as $section => $fields ) : 
  781.  
  782. if ( $fields && is_array( $fields ) ) : 
  783.  
  784. ?> 
  785. <tbody class="simcal-panel-section simcal-panel-section-<?php echo esc_attr( $section ); ?>"> 
  786. <?php foreach ( $fields as $key => $field ) : 
  787.  
  788. $value = get_post_meta( $post_id, $key, true ); 
  789. $field['value'] = $value ? $value : ( isset( $field['default'] ) ? $field['default'] : '' ); 
  790. $the_field = simcal_get_field( $field ); ?> 
  791.  
  792. <?php if ( $the_field instanceof Field ) : ?> 
  793. <tr class="simcal-panel-field"> 
  794. <th><label for="<?php echo $the_field->id ?>"><?php echo $the_field->title; ?></label></th> 
  795. <td><?php $the_field->html(); ?></td> 
  796. </tr> 
  797. <?php endif; ?> 
  798.  
  799. <?php endforeach; ?> 
  800. </tbody> 
  801. <?php 
  802.  
  803. endif; 
  804.  
  805. endforeach; 
  806.  
  807.  
  808. /** 
  809. * Validate and save the meta box fields. 
  810. * 
  811. * @since 3.0.0 
  812. * 
  813. * @param int $post_id 
  814. * @param \WP_Post $post 
  815. * 
  816. * @return void 
  817. */ 
  818. public static function save( $post_id, $post ) { 
  819.  
  820. /** ====================== * 
  821. * Calendar type and view * 
  822. * ====================== */ 
  823.  
  824. // Unlink existing terms for feed type and calendar type. 
  825. wp_delete_object_term_relationships( $post_id, array( 
  826. 'calendar_feed',  
  827. 'calendar_type',  
  828. ) ); 
  829.  
  830. // Set the feed type as term. 
  831. $feed_type = isset( $_POST['_feed_type'] ) ? sanitize_title( stripslashes( $_POST['_feed_type'] ) ) : apply_filters( 'simcal_default_feed_type', 'google' ); 
  832. wp_set_object_terms( $post_id, $feed_type, 'calendar_feed' ); 
  833.  
  834. // Set the calendar type as a term. 
  835. $calendar_type = isset( $_POST['_calendar_type'] ) ? sanitize_title( stripslashes( $_POST['_calendar_type'] ) ) : apply_filters( 'simcal_default_calendar_type', 'default-calendar' ); 
  836. wp_set_object_terms( $post_id, $calendar_type, 'calendar_type' ); 
  837. // Set the calendar type view as post meta. 
  838. $calendar_view = isset( $_POST['_calendar_view'] ) ? $_POST['_calendar_view'] : ''; 
  839. if ( $calendar_view && is_array( $calendar_view ) ) { 
  840. $views = array_map( 'sanitize_title', $calendar_view ); 
  841. update_post_meta( $post_id, '_calendar_view', $views ); 
  842.  
  843. /** ===================== * 
  844. * Events settings panel * 
  845. * ===================== */ 
  846.  
  847. // Calendar opening. 
  848. $calendar_begins = isset( $_POST['_calendar_begins'] ) ? sanitize_key( $_POST['_calendar_begins'] ) : 'this_month'; 
  849. update_post_meta( $post_id, '_calendar_begins', $calendar_begins ); 
  850. $calendar_begins_nth = isset( $_POST['_calendar_begins_nth'] ) ? absint( $_POST['_calendar_begins_nth'] ) : 2; 
  851. update_post_meta( $post_id, '_calendar_begins_nth', $calendar_begins_nth ); 
  852. $calendar_begins_custom_date = isset( $_POST['_calendar_begins_custom_date'] ) ? sanitize_title( $_POST['_calendar_begins_custom_date'] ) : ''; 
  853. update_post_meta( $post_id, '_calendar_begins_custom_date', $calendar_begins_custom_date ); 
  854.  
  855. // Feed earliest events date. 
  856. $earliest_events = isset( $_POST['_feed_earliest_event_date'] ) ? sanitize_key( $_POST['_feed_earliest_event_date'] ) : ''; 
  857. update_post_meta( $post_id, '_feed_earliest_event_date', $earliest_events ); 
  858. $earliest_events_range = isset( $_POST['_feed_earliest_event_date_range'] ) ? max( absint( $_POST['_feed_earliest_event_date_range'] ), 1 ) : 1; 
  859. update_post_meta( $post_id, '_feed_earliest_event_date_range', $earliest_events_range ); 
  860.  
  861. // Feed latest events date. 
  862. $latest_events = isset( $_POST['_feed_latest_event_date'] ) ? sanitize_key( $_POST['_feed_latest_event_date'] ) : ''; 
  863. update_post_meta( $post_id, '_feed_latest_event_date', $latest_events ); 
  864. $latest_events_range = isset( $_POST['_feed_latest_event_date_range'] ) ? max( absint( $_POST['_feed_latest_event_date_range'] ), 1 ) : 1; 
  865. update_post_meta( $post_id, '_feed_latest_event_date_range', $latest_events_range ); 
  866.  
  867. /** ======================= * 
  868. * Calendar settings panel * 
  869. * ======================= */ 
  870.  
  871. // Static calendar. 
  872. $static = isset( $_POST['_calendar_is_static'] ) ? 'yes' : 'no'; 
  873. update_post_meta( $post_id, '_calendar_is_static', $static ); 
  874.  
  875. // No events message. 
  876. $message = isset( $_POST['_no_events_message'] ) ? wp_kses_post( $_POST['_no_events_message'] ) : ''; 
  877. update_post_meta( $post_id, '_no_events_message', $message ); 
  878.  
  879. // _event_formatting 
  880. $event_formatting = isset( $_POST['_event_formatting'] ) ? sanitize_key( $_POST['_event_formatting'] ) : 'preserve_linebreaks'; 
  881. update_post_meta( $post_id, '_event_formatting', $event_formatting ); 
  882.  
  883. // Powered by option 
  884. $poweredby = isset( $_POST['_poweredby'] ) ? 'yes' : 'no'; 
  885. update_post_meta( $post_id, '_poweredby', $poweredby ); 
  886.  
  887. /** ======================= * 
  888. * Advanced settings panel * 
  889. * ======================= */ 
  890.  
  891. // Timezone. 
  892. $feed_timezone_setting = isset( $_POST['_feed_timezone_setting'] ) ? sanitize_key( $_POST['_feed_timezone_setting'] ) : 'use_calendar'; 
  893. update_post_meta( $post_id, '_feed_timezone_setting', $feed_timezone_setting ); 
  894. $default_timezone = simcal_get_wp_timezone(); 
  895. $feed_timezone = $default_timezone ? $default_timezone : 'UTC'; 
  896. $feed_timezone = isset( $_POST['_feed_timezone'] ) ? sanitize_text_field( $_POST['_feed_timezone'] ) : $feed_timezone; 
  897. update_post_meta( $post_id, '_feed_timezone', $feed_timezone ); 
  898.  
  899. // Date format. 
  900. $date_format_setting = isset( $_POST['_calendar_date_format_setting'] ) ? sanitize_key( $_POST['_calendar_date_format_setting'] ) : 'use_site'; 
  901. update_post_meta( $post_id, '_calendar_date_format_setting', $date_format_setting ); 
  902. $date_format = isset( $_POST['_calendar_date_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format'] ) ) : get_option( 'date_format' ); 
  903. update_post_meta( $post_id, '_calendar_date_format', $date_format ); 
  904. $date_format_php = isset( $_POST['_calendar_date_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format_php'] ) ) : get_option( 'date_format' ); 
  905. update_post_meta( $post_id, '_calendar_date_format_php', $date_format_php ); 
  906.  
  907. // Time format. 
  908. $time_format_setting = isset( $_POST['_calendar_time_format_setting'] ) ? sanitize_key( $_POST['_calendar_time_format_setting'] ) : 'use_site'; 
  909. update_post_meta( $post_id, '_calendar_time_format_setting', $time_format_setting ); 
  910. $time_format = isset( $_POST['_calendar_time_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format'] ) ) : get_option( 'time_format' ); 
  911. update_post_meta( $post_id, '_calendar_time_format', $time_format ); 
  912. $time_format_php = isset( $_POST['_calendar_time_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format_php'] ) ) : get_option( 'time_format' ); 
  913. update_post_meta( $post_id, '_calendar_time_format_php', $time_format_php ); 
  914.  
  915. // Date-time separator. 
  916. $datetime_separator = isset( $_POST['_calendar_datetime_separator'] ) ? sanitize_text_field( $_POST['_calendar_datetime_separator'] ) : ' '; 
  917. update_post_meta( $post_id, '_calendar_datetime_separator', $datetime_separator ); 
  918.  
  919. // Week start. 
  920. $week_start_setting = isset( $_POST['_calendar_week_starts_on_setting'] ) ? sanitize_key( $_POST['_calendar_week_starts_on_setting'] ) : 'use_site'; 
  921. update_post_meta( $post_id, '_calendar_week_starts_on_setting', $week_start_setting ); 
  922. $week_start = isset( $_POST['_calendar_week_starts_on'] ) ? intval( $_POST['_calendar_week_starts_on'] ) : get_option( 'start_of_week' ); 
  923. update_post_meta( $post_id, '_calendar_week_starts_on', $week_start ); 
  924.  
  925. // Cache interval. 
  926. $cache = 7200; 
  927. if ( isset( $_POST['_feed_cache_user_amount'] ) && isset( $_POST['_feed_cache_user_unit'] ) ) { 
  928. $amount = is_numeric( $_POST['_feed_cache_user_amount'] ) || $_POST['_feed_cache_user_amount'] == 0 ? absint( $_POST['_feed_cache_user_amount'] ) : 1; 
  929. $unit = is_numeric( $_POST['_feed_cache_user_unit'] ) ? absint( $_POST['_feed_cache_user_unit'] ) : 3600; 
  930. update_post_meta( $post_id, '_feed_cache_user_amount', $amount ); 
  931. update_post_meta( $post_id, '_feed_cache_user_unit', $unit ); 
  932. $cache = ( ( $amount * $unit ) > 0 ) ? $amount * $unit : 1; 
  933. update_post_meta( $post_id, '_feed_cache', $cache ); 
  934.  
  935. /** ============= * 
  936. * Miscellaneous * 
  937. * ============= */ 
  938.  
  939. // Update version. 
  940. update_post_meta( $post_id, '_calendar_version', SIMPLE_CALENDAR_VERSION ); 
  941.  
  942. // Action hook. 
  943. do_action( 'simcal_process_settings_meta', $post_id ); 
  944.  
  945. // Clear cache. 
  946. simcal_delete_feed_transients( $post_id ); 
  947.  
.