booked-calendar-feeds.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. Plugin Name: Booked Add-On: Calendar Feeds
  4. Plugin URI: https://getbooked.io
  5. Description: Adds a read-only calendar feed to the Booked plugin.
  6. Version: 1.1.5
  7. Author: Boxy Studio
  8. Author URI: https://www.boxystudio.com
  9. */
  10. define('BOOKEDICAL_PLUGIN_DIR', dirname(__FILE__));
  11. $secure_hash = md5( 'booked_ical_feed_' . get_site_url() );
  12. define('BOOKEDICAL_SECURE_HASH',$secure_hash);
  13. // Include the required class for plugin updates.
  14. require_once('updates/plugin-update-checker.php');
  15. $BookedFEA_BoxyUpdateChecker = PucFactory::buildUpdateChecker('http://boxyupdates.com/get/?action=get_metadata&slug=booked-calendar-feeds', __FILE__, 'booked-calendar-feeds');
  16. // Is Booked installed and active?
  17. if( in_array('booked/booked.php',apply_filters('active_plugins',get_option('active_plugins')))) {
  18. if(!class_exists('bookedical_plugin')) {
  19. class bookedical_plugin {
  20. public function __construct() {
  21. $this->booked_screens = array('booked-feeds');
  22. add_action('init', array(&$this, 'booked_ical_feed') );
  23. add_action('admin_enqueue_scripts', array(&$this, 'admin_styles'));
  24. add_action('admin_menu', array(&$this, 'add_feeds_menu'));
  25. }
  26. public function booked_ical_feed(){
  27. if (isset($_GET['booked_ical'])):
  28. include(BOOKEDICAL_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'calendar-feed.php');
  29. exit;
  30. endif;
  31. }
  32. // Add a New Menu Item
  33. public function add_feeds_menu() {
  34. add_submenu_page('booked-appointments', __('Calendar Feeds','booked-calendar-feeds'), __('Calendar Feeds','booked-calendar-feeds'), 'manage_options', 'booked-feeds', array(&$this, 'plugin_feeds_page'));
  35. }
  36. // Booked Feeds Page
  37. public function plugin_feeds_page() {
  38. if(!current_user_can('manage_options')) {
  39. wp_die(__('You do not have sufficient permissions to access this page.', 'booked-calendar-feeds'));
  40. }
  41. include(sprintf("%s/admin/feeds.php", BOOKEDICAL_PLUGIN_DIR));
  42. }
  43. public function admin_styles() {
  44. $current_page = (isset($_GET['page']) ? $_GET['page'] : false);
  45. $screen = get_current_screen();
  46. if (in_array($current_page,$this->booked_screens)):
  47. wp_enqueue_style('booked-icons', BOOKED_PLUGIN_URL . '/assets/css/icons.css', array(), BOOKED_VERSION);
  48. wp_enqueue_style('booked-admin', BOOKED_PLUGIN_URL . '/assets/css/admin-styles.css', array(), BOOKED_VERSION);
  49. endif;
  50. }
  51. }
  52. }
  53. } else {
  54. // Show notice when Booked and/or WooCommerce is not active
  55. add_action('admin_notices', 'bookedical_required_plugins_notice');
  56. }
  57. add_action('plugins_loaded','init_bookedical');
  58. function init_bookedical(){
  59. if(class_exists('bookedical_plugin')) {
  60. // instantiate the plugin class
  61. $bookedical_plugin = new bookedical_plugin();
  62. }
  63. }
  64. function bookedical_required_plugins_notice() {
  65. echo '<div class="update-nag">';
  66. echo sprintf( __('In order to use the %s plugin, you need to have %s installed and active.'), '<strong>Booked Calendar Feed</strong>', '<strong><a href="http://codecanyon.net/item/booked-appointment-booking-for-wordpress/9466968/?ref=boxystudio" target="_blank">Booked</a></strong>' );
  67. echo '</div>';
  68. }