PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/all-in-one-event-calendar/app/helper/class-ai1ec-settings-helper.php

https://gitlab.com/endomorphosis/jeffersonsmithmayor
PHP | 421 lines | 274 code | 25 blank | 122 comment | 27 complexity | 0a678e47bec8b1fec9cd990e3b6d6220 MD5 | raw file
  1. <?php
  2. //
  3. // class-ai1ec-settings-helper.php
  4. // all-in-one-event-calendar
  5. //
  6. // Created by The Seed Studio on 2011-07-13.
  7. //
  8. /**
  9. * Ai1ec_Settings_Helper class
  10. *
  11. * @package Helpers
  12. * @author The Seed Studio
  13. **/
  14. class Ai1ec_Settings_Helper {
  15. /**
  16. * _instance class variable
  17. *
  18. * Class instance
  19. *
  20. * @var null | object
  21. **/
  22. private static $_instance = NULL;
  23. /**
  24. * get_instance function
  25. *
  26. * Return singleton instance
  27. *
  28. * @return object
  29. **/
  30. static function get_instance() {
  31. if( self::$_instance === NULL ) {
  32. self::$_instance = new self();
  33. }
  34. return self::$_instance;
  35. }
  36. /**
  37. * Constructor
  38. *
  39. * Default constructor
  40. **/
  41. private function __construct() { }
  42. /**
  43. * wp_pages_dropdown function
  44. *
  45. * Display drop-down list selector of pages, including an "Auto-Create New Page"
  46. * option which causes the plugin to generate a new page on user's behalf.
  47. *
  48. * @param string $field_name
  49. * @param int $selected_page_id
  50. * @param string $auto_page
  51. * @param bool $include_disabled
  52. *
  53. * @return string
  54. **/
  55. function wp_pages_dropdown( $field_name, $selected_page_id = 0, $auto_page = '', $include_disabled = false ) {
  56. global $wpdb;
  57. ob_start();
  58. $query = "SELECT
  59. *
  60. FROM
  61. {$wpdb->posts}
  62. WHERE
  63. post_status = %s
  64. AND
  65. post_type = %s";
  66. $query = $wpdb->prepare( $query, 'publish', 'page' );
  67. $results = $wpdb->get_results( $query );
  68. $pages = array();
  69. if( $results ) {
  70. $pages = $results;
  71. }
  72. $selected_title = '';
  73. ?>
  74. <select class="inputwidth" name="<?php echo $field_name; ?>"
  75. id="<?php echo $field_name; ?>"
  76. class="wafp-dropdown wafp-pages-dropdown">
  77. <?php if( ! empty( $auto_page ) ) { ?>
  78. <option value="__auto_page:<?php echo $auto_page; ?>">
  79. <?php _e( '- Auto-Create New Page -', AI1EC_PLUGIN_NAME ); ?>
  80. </option>
  81. <?php }
  82. foreach( $pages as $page ) {
  83. if( $selected_page_id == $page->ID ) {
  84. $selected = ' selected="selected"';
  85. $selected_title = $page->post_title;
  86. } else {
  87. $selected = '';
  88. }
  89. ?>
  90. <option value="<?php echo $page->ID ?>" <?php echo $selected; ?>>
  91. <?php echo $page->post_title ?>
  92. </option>
  93. <?php } ?>
  94. </select>
  95. <?php
  96. if( is_numeric( $selected_page_id ) && $selected_page_id > 0 ) {
  97. $permalink = get_permalink( $selected_page_id );
  98. ?>
  99. <br />
  100. <a href="<?php echo $permalink ?>" target="_blank">
  101. <?php printf( __( 'View "%s" ยป', AI1EC_PLUGIN_NAME ), $selected_title ) ?>
  102. </a>
  103. <?php
  104. }
  105. return ob_get_clean();
  106. }
  107. /**
  108. * get_week_dropdown function
  109. *
  110. * Creates the dropdown element for selecting start of the week
  111. *
  112. * @param int $week_start_day Selected start day
  113. *
  114. * @return String dropdown element
  115. **/
  116. function get_week_dropdown( $week_start_day ) {
  117. global $wp_locale;
  118. ob_start();
  119. ?>
  120. <select class="inputwidth" name="week_start_day" id="week_start_day">
  121. <?php
  122. for( $day_index = 0; $day_index <= 6; $day_index++ ) :
  123. $selected = ( $week_start_day == $day_index ) ? 'selected="selected"' : '';
  124. echo "\n\t<option value='" . esc_attr($day_index) . "' $selected>" . $wp_locale->get_weekday($day_index) . '</option>';
  125. endfor;
  126. ?>
  127. </select>
  128. <?php
  129. return ob_get_clean();
  130. }
  131. /**
  132. * get_view_dropdown function
  133. *
  134. * @return void
  135. **/
  136. function get_view_dropdown( $view = null ) {
  137. ob_start();
  138. ?>
  139. <select name="default_calendar_view">
  140. <option value="oneday" <?php echo $view == 'oneday' ? 'selected' : '' ?>>
  141. <?php _e( 'Day', AI1EC_PLUGIN_NAME ) ?>
  142. </option>
  143. <option value="month" <?php echo $view == 'month' ? 'selected' : '' ?>>
  144. <?php _e( 'Month', AI1EC_PLUGIN_NAME ) ?>
  145. </option>
  146. <option value="week" <?php echo $view == 'week' ? 'selected' : '' ?>>
  147. <?php _e( 'Week', AI1EC_PLUGIN_NAME ) ?>
  148. </option>
  149. <option value="agenda" <?php echo $view == 'agenda' ? 'selected' : '' ?>>
  150. <?php _e( 'Agenda', AI1EC_PLUGIN_NAME ) ?>
  151. </option>
  152. </select>
  153. <?php
  154. return ob_get_clean();
  155. }
  156. /**
  157. * get_timezone_dropdown function
  158. *
  159. *
  160. *
  161. * @return void
  162. **/
  163. function get_timezone_dropdown( $timezone = null ) {
  164. $timezone_identifiers = DateTimeZone::listIdentifiers();
  165. ob_start();
  166. ?>
  167. <select id="timezone" name="timezone">
  168. <?php foreach( $timezone_identifiers as $value ) : ?>
  169. <?php if( preg_match( '/^(Africa|America|Antartica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)\//', $value ) ) : ?>
  170. <?php $ex = explode( "/", $value ); //obtain continent,city ?>
  171. <?php if( isset( $continent ) && $continent != $ex[0] ) : ?>
  172. <?php if( ! empty( $continent ) ) : ?>
  173. </optgroup>
  174. <?php endif ?>
  175. <optgroup label="<?php echo $ex[0] ?>">
  176. <?php endif ?>
  177. <?php $city = isset( $ex[2] ) ? $ex[2] : $ex[1]; $continent = $ex[0]; ?>
  178. <option value="<?php echo $value ?>" <?php echo $value == $timezone ? 'selected' : '' ?>><?php echo $city ?></option>
  179. <?php endif ?>
  180. <?php endforeach ?>
  181. </optgroup>
  182. </select>
  183. <?php
  184. return ob_get_clean();
  185. }
  186. /**
  187. * get_date_format_dropdown function
  188. *
  189. * @return string
  190. **/
  191. function get_date_format_dropdown( $view = null ) {
  192. ob_start();
  193. ?>
  194. <select name="input_date_format">
  195. <option value="def" <?php echo $view == 'def' ? 'selected' : '' ?>>
  196. <?php _e( 'Default (d/m/y)', AI1EC_PLUGIN_NAME ) ?>
  197. </option>
  198. <option value="us" <?php echo $view == 'us' ? 'selected' : '' ?>>
  199. <?php _e( 'US (m/d/y)', AI1EC_PLUGIN_NAME ) ?>
  200. </option>
  201. <option value="iso" <?php echo $view == 'iso' ? 'selected' : '' ?>>
  202. <?php _e( 'ISO 8601 (y-m-d)', AI1EC_PLUGIN_NAME ) ?>
  203. </option>
  204. <option value="dot" <?php echo $view == 'dot' ? 'selected' : '' ?>>
  205. <?php _e( 'Dotted (m.d.y)', AI1EC_PLUGIN_NAME ) ?>
  206. </option>
  207. </select>
  208. <?php
  209. return ob_get_clean();
  210. }
  211. /**
  212. * get_cron_freq_dropdown function
  213. *
  214. * @return void
  215. **/
  216. function get_cron_freq_dropdown( $cron_freq = null ) {
  217. ob_start();
  218. ?>
  219. <select name="cron_freq">
  220. <option value="hourly" <?php echo $cron_freq == 'hourly' ? 'selected' : ''; ?>>
  221. <?php _e( 'Hourly', AI1EC_PLUGIN_NAME ) ?>
  222. </option>
  223. <option value="twicedaily" <?php echo $cron_freq == 'twicedaily' ? 'selected' : '' ?>>
  224. <?php _e( 'Twice Daily', AI1EC_PLUGIN_NAME ) ?>
  225. </option>
  226. <option value="daily" <?php echo $cron_freq == 'daily' ? 'selected' : '' ?>>
  227. <?php _e( 'Daily', AI1EC_PLUGIN_NAME ) ?>
  228. </option>
  229. </select>
  230. <?php
  231. return ob_get_clean();
  232. }
  233. /**
  234. * get_feed_rows function
  235. *
  236. * Creates feed rows to display on settings page
  237. *
  238. * @return String feed rows
  239. **/
  240. function get_feed_rows() {
  241. global $wpdb,
  242. $ai1ec_view_helper;
  243. // Select all added feeds
  244. $table_name = $wpdb->prefix . 'ai1ec_event_feeds';
  245. $sql = "SELECT * FROM {$table_name}";
  246. $rows = $wpdb->get_results( $sql );
  247. ob_start();
  248. foreach( $rows as $row ) :
  249. $feed_category = get_term( $row->feed_category, 'events_categories' );
  250. $table_name = $wpdb->prefix . 'ai1ec_events';
  251. $sql = "SELECT COUNT(*) FROM {$table_name} WHERE ical_feed_url = '%s'";
  252. $events = $wpdb->get_var( $wpdb->prepare( $sql, $row->feed_url ) );
  253. $args = array(
  254. 'feed_url' => $row->feed_url,
  255. 'event_category' => $feed_category->name,
  256. 'tags' => stripslashes( $row->feed_tags ),
  257. 'feed_id' => $row->feed_id,
  258. 'events' => $events
  259. );
  260. $ai1ec_view_helper->display( 'feed_row.php', $args );
  261. endforeach;
  262. return ob_get_clean();
  263. }
  264. /**
  265. * get_event_categories_select function
  266. *
  267. * Creates the dropdown element for selecting feed category
  268. *
  269. * @param int|null $selected The selected category or null
  270. *
  271. * @return String dropdown element
  272. **/
  273. function get_event_categories_select( $selected = null) {
  274. ob_start();
  275. ?>
  276. <select name="ai1ec_feed_category" id="ai1ec_feed_category">
  277. <?php
  278. foreach( get_terms( 'events_categories', array( 'hide_empty' => false ) ) as $term ) :
  279. ?>
  280. <option value="<?php echo $term->term_id; ?>" <?php echo ( $selected === $term->term_id ) ? 'selected' : '' ?>>
  281. <?php echo $term->name; ?>
  282. </option>
  283. <?php
  284. endforeach;
  285. ?>
  286. </select>
  287. <?php
  288. return ob_get_clean();
  289. }
  290. /**
  291. * general_settings_meta_box function
  292. *
  293. * Displays the General Settings meta box.
  294. *
  295. * @return void
  296. **/
  297. function general_settings_meta_box( $object, $box ) {
  298. global $ai1ec_view_helper,
  299. $ai1ec_settings_helper,
  300. $ai1ec_settings;
  301. $calendar_page = $ai1ec_settings_helper->wp_pages_dropdown(
  302. 'calendar_page_id',
  303. $ai1ec_settings->calendar_page_id,
  304. __( 'Calendar', AI1EC_PLUGIN_NAME )
  305. );
  306. $calendar_css_selector = $ai1ec_settings->calendar_css_selector;
  307. $week_start_day = $ai1ec_settings_helper->get_week_dropdown( get_option( 'start_of_week' ) );
  308. $agenda_events_per_page = $ai1ec_settings->agenda_events_per_page;
  309. $include_events_in_rss =
  310. '<input type="checkbox" name="include_events_in_rss"
  311. id="include_events_in_rss" value="1"'
  312. . ( $ai1ec_settings->include_events_in_rss ? ' checked="checked"' : '' )
  313. . '/>';
  314. $exclude_from_search = $ai1ec_settings->exclude_from_search ? 'checked=checked' : '';
  315. $show_publish_button = $ai1ec_settings->show_publish_button ? 'checked=checked' : '';
  316. $hide_maps_until_clicked = $ai1ec_settings->hide_maps_until_clicked ? 'checked=checked' : '';
  317. $agenda_events_expanded = $ai1ec_settings->agenda_events_expanded ? 'checked=checked' : '';
  318. $turn_off_subscription_buttons = $ai1ec_settings->turn_off_subscription_buttons ? 'checked=checked' : '';
  319. $show_create_event_button = $ai1ec_settings->show_create_event_button ? 'checked=checked' : '';
  320. $inject_categories = $ai1ec_settings->inject_categories ? 'checked=checked' : '';
  321. $geo_region_biasing = $ai1ec_settings->geo_region_biasing ? 'checked=checked' : '';
  322. $input_date_format = $ai1ec_settings_helper->get_date_format_dropdown( $ai1ec_settings->input_date_format );
  323. $input_24h_time = $ai1ec_settings->input_24h_time ? 'checked=checked' : '';
  324. $default_calendar_view = $ai1ec_settings_helper->get_view_dropdown( $ai1ec_settings->default_calendar_view );
  325. $timezone_control = $ai1ec_settings_helper->get_timezone_dropdown( $ai1ec_settings->timezone );
  326. $allow_statistics = $ai1ec_settings->allow_statistics ? 'checked=checked' : '';
  327. $args = array(
  328. 'calendar_page' => $calendar_page,
  329. 'default_calendar_view' => $default_calendar_view,
  330. 'calendar_css_selector' => $calendar_css_selector,
  331. 'week_start_day' => $week_start_day,
  332. 'agenda_events_per_page' => $agenda_events_per_page,
  333. 'exclude_from_search' => $exclude_from_search,
  334. 'show_publish_button' => $show_publish_button,
  335. 'hide_maps_until_clicked' => $hide_maps_until_clicked,
  336. 'agenda_events_expanded' => $agenda_events_expanded,
  337. 'turn_off_subscription_buttons' => $turn_off_subscription_buttons,
  338. 'show_create_event_button' => $show_create_event_button,
  339. 'inject_categories' => $inject_categories,
  340. 'input_date_format' => $input_date_format,
  341. 'input_24h_time' => $input_24h_time,
  342. 'show_timezone' => ! get_option( 'timezone_string' ),
  343. 'timezone_control' => $timezone_control,
  344. 'geo_region_biasing' => $geo_region_biasing,
  345. 'allow_statistics' => $allow_statistics
  346. );
  347. $ai1ec_view_helper->display( 'box_general_settings.php', $args );
  348. }
  349. /**
  350. * ics_import_settings_meta_box function
  351. *
  352. * Renders view of iCalendar import meta box on the settings page.
  353. *
  354. * @return void
  355. **/
  356. function ics_import_settings_meta_box( $object, $box )
  357. {
  358. global $ai1ec_view_helper,
  359. $ai1ec_settings_helper,
  360. $ai1ec_settings;
  361. $args = array(
  362. 'cron_freq' => $ai1ec_settings_helper->get_cron_freq_dropdown( $ai1ec_settings->cron_freq ),
  363. 'event_categories' => $ai1ec_settings_helper->get_event_categories_select(),
  364. 'feed_rows' => $ai1ec_settings_helper->get_feed_rows()
  365. );
  366. $ai1ec_view_helper->display( 'box_ics_import_settings.php', $args );
  367. }
  368. /**
  369. * the_seed_studio_meta_box function
  370. *
  371. *
  372. *
  373. * @return void
  374. **/
  375. function the_seed_studio_meta_box( $object, $box ) {
  376. global $ai1ec_view_helper;
  377. include_once( ABSPATH . WPINC . '/feed.php' );
  378. // Initialize new feed
  379. $newsItems = array();
  380. $feed = fetch_feed( AI1EC_RSS_FEED );
  381. $newsItems = is_wp_error( $feed ) ? array() : $feed->get_items();
  382. $ai1ec_view_helper->display( 'box_the_seed_studio.php', array( 'news' => $newsItems ) );
  383. }
  384. /**
  385. * add_meta_boxes function
  386. *
  387. *
  388. *
  389. * @return void
  390. **/
  391. function add_meta_boxes(){
  392. global $ai1ec_settings;
  393. do_action( 'add_meta_boxes', $ai1ec_settings->settings_page );
  394. }
  395. }
  396. // END class