This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // disallow direct access to file if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) { die('Sorry, but you cannot access this page directly.'); } if (version_compare(PHP_VERSION, '5', '<')) { $out = "
"; print $out; } define('AEC_MENU_POSITION', null); //previously 30 define('AEC_VERSION', '1.0.4'); define('AEC_FILE', basename(__FILE__)); define('AEC_NAME', str_replace('.php', '', AEC_FILE)); define('AEC_PATH', plugin_dir_path(__FILE__)); define('AEC_URL', plugin_dir_url(__FILE__)); define('AEC_EVENT_TABLE', 'aec_event'); define('AEC_CATEGORY_TABLE', 'aec_event_category'); define('AEC_HOMEPAGE', 'http://wordpress.org/extend/plugins/' . AEC_NAME . '/'); define('AEC_WP_DATE_FORMAT', get_option('date_format')); define('AEC_WP_TIME_FORMAT', get_option('time_format')); define('AEC_DB_DATETIME_FORMAT', 'Y-m-d H:i:s'); define('AEC_LOCALE', substr(get_locale(), 0, 2)); // for javascript localization scripts // if uncommented, overrides the location of the WP error log to the AEC plugin root // @ini_set('error_log', AEC_PATH . 'aec_debug.log'); if (!class_exists('ajax_event_calendar')) { class ajax_event_calendar { private $required_fields = array(); private $shortcode_params = array(); private $admin_messages = array(); private $plugin_defaults = array( 'filter_label' => 'Show Type', 'limit' => '0', 'show_weekends' => '1', 'show_map_link' => '1', 'menu' => '1', 'make_links' => '0', 'popup_links' => '1', 'step_interval' => '30', 'addy_format' => '0', 'scroll' => '1', 'title' => '2', 'venue' => '1', 'address' => '2', 'city' => '2', 'state' => '2', 'zip' => '2', 'country' => '1', 'link' => '1', 'description' => '2', 'contact' => '2', 'contact_info' => '2', 'accessible' => '0', 'rsvp' => '0', 'reset' => '0' ); function __construct() { add_action('plugins_loaded', array($this, 'version_patches')); add_action('init', array($this, 'localize_plugin')); add_action('admin_menu', array($this, 'render_admin_menu')); add_action('admin_init', array($this, 'admin_options_initialize')); add_action('wp_print_styles', array($this, 'calendar_styles')); add_action('wp_print_scripts', array($this, 'frontend_calendar_scripts')); add_action('delete_user', array($this, 'delete_events_by_user')); add_action('admin_notices', array(&$this, 'admin_alert')); // ajax hooks add_action('wp_ajax_nopriv_get_events', array($this, 'render_calendar_events')); add_action('wp_ajax_get_events', array($this, 'render_calendar_events')); add_action('wp_ajax_nopriv_get_event', array($this, 'render_frontend_modal')); add_action('wp_ajax_get_event', array($this, 'render_frontend_modal')); add_action('wp_ajax_admin_event', array($this, 'render_admin_modal')); add_action('wp_ajax_add_event', array($this, 'add_event')); add_action('wp_ajax_copy_event', array($this, 'copy_event')); add_action('wp_ajax_update_event', array($this, 'update_event')); add_action('wp_ajax_delete_event', array($this, 'delete_event')); add_action('wp_ajax_move_event', array($this, 'move_event')); add_action('wp_ajax_add_category', array($this, 'add_category')); add_action('wp_ajax_update_filter_label', array($this, 'update_filter_label')); add_action('wp_ajax_update_category', array($this, 'update_category')); add_action('wp_ajax_delete_category', array($this, 'confirm_delete_category')); add_action('wp_ajax_reassign_category', array($this, 'reassign_category')); // wordpress overrides add_filter('manage_users_columns', array($this, 'add_events_column')); add_filter('manage_users_custom_column', array($this, 'add_events_column_data'), 10, 3); add_filter('plugin_action_links', array($this, 'settings_link'), 10, 2); add_filter('option_page_capability_aec_plugin_options', array($this, 'set_option_page_capability')); add_shortcode('calendar', array($this, 'render_shortcode_calendar')); add_shortcode('eventlist', array($this, 'render_shortcode_eventlist')); // activate shortcode in text widgets add_filter('widget_text', 'shortcode_unautop'); add_filter('widget_text', 'do_shortcode'); } function install() { require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; if ($wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . AEC_EVENT_TABLE . '"') != $wpdb->prefix . AEC_EVENT_TABLE) { $sql = 'CREATE TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' ( id BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, user_id INT(10) UNSIGNED NOT NULL, title VARCHAR(100) NOT NULL, start DATETIME NOT NULL, end DATETIME NOT NULL, repeat_freq TINYINT(4) UNSIGNED DEFAULT 0, repeat_int TINYINT(4) UNSIGNED DEFAULT 0, repeat_end DATE, allDay TINYINT(1) UNSIGNED DEFAULT 0, category_id TINYINT(4) UNSIGNED NOT NULL, description VARCHAR(2500), link VARCHAR(2000), venue VARCHAR(100), address VARCHAR(100), city VARCHAR(50), state VARCHAR(50), zip VARCHAR(10), country VARCHAR(50), contact VARCHAR(50), contact_info VARCHAR(50), access TINYINT(1) UNSIGNED DEFAULT 0, rsvp TINYINT(1) UNSIGNED DEFAULT 0) CHARSET=utf8;'; dbDelta($sql); } if ($wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . AEC_CATEGORY_TABLE . '"') != $wpdb->prefix . AEC_CATEGORY_TABLE) { $sql = 'CREATE TABLE ' . $wpdb->prefix . AEC_CATEGORY_TABLE . ' ( id TINYINT(4) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, category VARCHAR(25) NOT NULL, bgcolor CHAR(6) NOT NULL, fgcolor CHAR(6) NOT NULL ) CHARSET=utf8; ## DEFAULT CATEGORIES INSERT INTO ' . $wpdb->prefix . AEC_CATEGORY_TABLE . ' (id, category, bgcolor, fgcolor) VALUES (NULL, "Event", "517ed6", "FFFFFF"), (NULL, "Deadline", "e3686c", "FFFFFF"), (NULL, "Volunteer", "8fc9b0", "FFFFFF");'; dbDelta($sql); } // add new role add_role('calendar_contributor', 'Calendar Contributor', array( 'read' => 1, 'aec_add_events' => 1 )); // add calendar capabilities to administrator $role = get_role('administrator'); $role->add_cap('aec_add_events'); $role->add_cap('aec_manage_events'); $role->add_cap('aec_manage_calendar'); } function version_patches() { $plugin_updated = false; $options = get_option('aec_options'); $current = get_option('aec_version'); // initial and manual option initialization if (!is_array($options) || !isset($options['reset']) || $options['reset'] == '1') { update_option('aec_options', $this->plugin_defaults); } if (version_compare($current, AEC_VERSION, '==')) { return; } // set version for new plugin installations if ($current === false) { update_option('aec_version', AEC_VERSION); $current = get_option('aec_version'); $plugin_updated = true; } // < 0.9.6 if (version_compare($current, '0.9.6', '<')) { // set title as a required field $options = $this->insert_option('title', 2); // update database fields in event table require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; $sql = 'ALTER TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' ' . 'modify venue VARCHAR(100),' . 'modify city VARCHAR(50),' . 'modify state CHAR(2),' . 'modify zip VARCHAR(10),' . 'modify contact VARCHAR(50),' . 'modify contact_info VARCHAR(50);'; $wpdb->query($sql); $plugin_updated = true; } // < 0.9.8.1 if (version_compare($current, '0.9.8.1', '<')) { // add calendar weekend toggle, and event detail map link toggle $options = $this->insert_option('show_weekends', 1); $options = $this->insert_option('show_map_link', 1); $plugin_updated = true; } // < 0.9.8.5 if (version_compare($current, '0.9.8.5', '<')) { // update tables to UTF8 and modify category table require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; $sqla = 'ALTER TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' CONVERT TO CHARACTER SET utf8;'; $wpdb->query($sqla); $sqlb = 'ALTER TABLE ' . $wpdb->prefix . AEC_CATEGORY_TABLE . ' CONVERT TO CHARACTER SET utf8;'; $wpdb->query($sqlb); $sqlc = 'ALTER TABLE ' . $wpdb->prefix . AEC_CATEGORY_TABLE . ' ' . 'modify category VARCHAR(100) NOT NULL;'; $wpdb->query($sqlc); // remove sidebar option $this->decommission_options(array('sidebar')); // remove retired administrator capability $role = get_role('administrator'); $role->remove_cap('aec_run_reports'); // remove retired role remove_role('blog_calendar_contributor'); // remove outdated widget option delete_option('widget_upcoming_events'); delete_option('widget_contributor_list'); $plugin_updated = true; } // < 0.9.9.1 if (version_compare($current, '0.9.9.1', '<')) { // update table to support Aussi state length require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; $sql = 'ALTER TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' MODIFY state CHAR(3);'; $wpdb->query($sql); // add filter label, description link options and address format options $options = $this->insert_option('filter_label', 'Show Type'); $options = $this->insert_option('make_links', 0); $options = $this->insert_option('popup_links', 1); $options = $this->insert_option('addy_format', 0); $plugin_updated = true; } // < 1.0 if (version_compare($current, '1.0', '<')) { // update table with repeating event fields, country, larger description, and larger state/province require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; $sql = 'ALTER TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' MODIFY description VARCHAR(2500),' . ' MODIFY state VARCHAR(50),' . ' ADD country VARCHAR(50),' . ' ADD repeat_freq TINYINT(4) UNSIGNED DEFAULT 0,' . ' ADD repeat_int TINYINT(4) UNSIGNED DEFAULT 0,' . ' ADD repeat_end DATE;'; $wpdb->query($sql); // add mousescroll control, country field, and step d options $options = $this->insert_option('scroll', 1); $options = $this->insert_option('country', 0); $options = $this->insert_option('step_interval', 30); $plugin_updated = true; } // < 1.0.1 if (version_compare($current, '1.0.1', '<')) { // update to accomodate long urls require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); global $wpdb; $sql = 'ALTER TABLE ' . $wpdb->prefix . AEC_EVENT_TABLE . ' MODIFY link VARCHAR(2000);'; $wpdb->query($sql); $plugin_updated = true; } // update routines completed if ($plugin_updated) { // update plugin version update_option('aec_version', AEC_VERSION); // add sample event $_POST['event']['user_id'] = 0; // system id $_POST['event']['title'] = "Ajax Event Calendar [v" . AEC_VERSION . "] successfully installed!"; $_POST['event']['start_date'] = date('Y-m-d'); $_POST['event']['start_time'] = '00:00:00'; $_POST['event']['end_date'] = date('Y-m-d'); $_POST['event']['end_time'] = '00:00:00'; $_POST['event']['allDay'] = 1; $_POST['event']['repeat_freq'] = 0; $_POST['event']['repeat_int'] = 0; $_POST['event']['repeat_end'] = null; $_POST['event']['category_id'] = 1; $_POST['event']['description'] = "Ajax Event Calendar WordPress Plugin is a fully localized (including RTL language support) community calendar that allows authorized users to add, edit, copy, move, resize and delete events into custom categories. Highly customized calendars can be added to pages, posts or text widgets using the [calendar] shortcode. Similarly, a list view of events can be added using the [eventlist] shortcode. Click on the event link to learn about available the shortcode options."; $_POST['event']['link'] = AEC_HOMEPAGE; $_POST['event']['venue'] = 'Cloud Gate "The Bean"'; $_POST['event']['address'] = '201 East Randolph Street'; $_POST['event']['city'] = 'Chicago'; $_POST['event']['state'] = 'Illinois'; $_POST['event']['zip'] = '60601-6530'; $_POST['event']['country'] = 'United States'; $_POST['event']['contact'] = 'Eran Miller'; $_POST['event']['contact_info'] = '123-123-1234'; $_POST['event']['access'] = 1; $_POST['event']['rsvp'] = 0; // removes previously created release events and creates a new one $_POST['user_id'] = $_POST['event']['user_id']; $this->delete_events_by_user(); $this->db_insert_event($this->cleanse_event_input($_POST['event']), false); } } function set_admin_alert($message) { array_push($this->admin_messages, print_r($message, true)); } // display admin alerts function admin_alert() { $alerts = $this->admin_messages; if (count($alerts)) { foreach ($alerts as $alert) { printf('Ajax Event Calendar %s.
%s... %s.
%s %s
%s %s. %s
", "
"); $add .= "\n"; $aec_options = get_option('aec_options'); $add .= $this->add_wrap(__('Category filter label', AEC_NAME), "", "
"); $add .= $this->add_wrap("", "", ""); $add .= $this->add_wrap(__('Update', AEC_NAME), "
"); $add .= $this->add_wrap(__('Category IDs are displayed in color bubbles at the beginning of each row.' , AEC_NAME), "", "
");
$add .= $this->add_wrap(__('To change category color, click the color swatch or edit the hex color value and click Update.', AEC_NAME), "", "
{$row->cnt} "; $out .= $this->render_i18n_data($row->category); $out .= " " . _n('Event', 'Events', $row->cnt, AEC_NAME); $out .= "
\n"; } $out .= $this->add_wrap(__('NOTE: Each repeating event is counted once.', AEC_NAME), "", "
"); } else { $out .= $this->add_wrap(__('No events this month.', AEC_NAME), "", "
"); } $out = $this->add_panel(__('Number of events scheduled for the current month, by category:', AEC_NAME), $out); $top = "\n"; $top .= $this->add_wrap(__('Activity Report', AEC_NAME), "