/** * admin_menu function * Display the admin menu items using the add_menu_page WP function. * * @return void */ function admin_menu() { global $ai1ec_settings_controller, $ai1ec_settings_helper, $ai1ec_settings, $ai1ec_themes_controller, $submenu; // ======================= // = Calendar Feeds Page = // ======================= $ai1ec_settings->feeds_page = add_submenu_page(AI1EC_ADMIN_BASE_URL, __('Calendar Feeds', AI1EC_PLUGIN_NAME), __('Calendar Feeds', AI1EC_PLUGIN_NAME), 'manage_ai1ec_feeds', AI1EC_PLUGIN_NAME . '-feeds', array(&$ai1ec_settings_controller, 'view_feeds')); // Allow feeds page to have additional meta boxes added to it. add_action("load-{$ai1ec_settings->feeds_page}", array(&$ai1ec_settings_helper, 'add_feeds_meta_boxes')); // Load our plugin's meta boxes. add_action("load-{$ai1ec_settings->feeds_page}", array(&$ai1ec_settings_controller, 'add_feeds_meta_boxes')); // =============== // = Themes Page = // =============== $themes_page = add_submenu_page(AI1EC_ADMIN_BASE_URL, __('Calendar Themes', AI1EC_PLUGIN_NAME), __('Calendar Themes', AI1EC_PLUGIN_NAME), 'switch_ai1ec_themes', AI1EC_PLUGIN_NAME . '-themes', array(&$ai1ec_themes_controller, 'view')); if (false !== $themes_page) { // Make copy of Themes page at its old location. $submenu['themes.php'][] = array(__('Calendar Themes', AI1EC_PLUGIN_NAME), 'switch_ai1ec_themes', AI1EC_THEME_SELECTION_BASE_URL); } // ====================== // = Theme Options Page = // ====================== // if themes are out of date do not show the page if (!$ai1ec_themes_controller->are_themes_outdated()) { $less_variable_editing_page = Ai1ec_Page_Factory::create_page('less_variable_editing'); $ai1ec_settings->less_variables_page = $less_variable_editing_page->add_page_to_menu(AI1EC_ADMIN_BASE_URL, __('Theme Options', AI1EC_PLUGIN_NAME), __('Theme Options', AI1EC_PLUGIN_NAME), 'manage_ai1ec_options', AI1EC_PLUGIN_NAME . '-edit-css'); if (false !== $ai1ec_settings->less_variables_page) { // Make copy of Theme Options page at its old location. $submenu['themes.php'][] = array(__('Calendar Theme Options', AI1EC_PLUGIN_NAME), 'manage_ai1ec_options', AI1EC_THEME_OPTIONS_BASE_URL); } } // ================= // = Settings Page = // ================= $ai1ec_settings->settings_page = add_submenu_page(AI1EC_ADMIN_BASE_URL, __('Settings', AI1EC_PLUGIN_NAME), __('Settings', AI1EC_PLUGIN_NAME), 'manage_ai1ec_options', AI1EC_PLUGIN_NAME . '-settings', array(&$ai1ec_settings_controller, 'view_settings')); if (false !== $ai1ec_settings->settings_page) { // Make copy of Settings page at its old location. $submenu['options-general.php'][] = array(__('Calendar', AI1EC_PLUGIN_NAME), 'manage_ai1ec_options', AI1EC_SETTINGS_BASE_URL); } // Allow settings page to have additional meta boxes added to it. add_action("load-{$ai1ec_settings->settings_page}", array(&$ai1ec_settings_helper, 'add_settings_meta_boxes')); // Load our plugin's meta boxes. add_action("load-{$ai1ec_settings->settings_page}", array(&$ai1ec_settings_controller, 'add_settings_meta_boxes')); // ======================== // = Calendar Update Page = // ======================== if (Ai1ec_Meta::instance('Option')->is_visible_update()) { add_submenu_page('plugins.php', __('Upgrade Calendar', AI1EC_PLUGIN_NAME), __('Upgrade Calendar', AI1EC_PLUGIN_NAME), 'update_plugins', AI1EC_PLUGIN_NAME . '-upgrade', array($this, 'upgrade')); } }
/** * Get original post . * * @param int $id Optional. Post ID. * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. * @return mixed Post data */ function duplicate_post_get_original($id = 0, $output = OBJECT) { if (!($post =& get_post($id))) { return; } $original_ID = Ai1ec_Meta::instance('Post')->get($post->ID, '_dp_original', '', true); if (empty($original_ID)) { return NULL; } $original_post =& get_post($original_ID[0], $output); return $original_post; }
/** * get_long_time function * * Format a long-length time for use in other views (e.g., single event); * this is also converted to the local timezone. * * @param int $timestamp * @param bool $convert_from_gmt Whether to convert from GMT time to local * * @return string **/ function get_long_time($timestamp, $convert_from_gmt = true) { $meta = Ai1ec_Meta::instance('Option'); $date_format = $meta->get('date_format', NULL, 'l, M j, Y'); $time_format = $meta->get('time_format', NULL, 'g:i a'); if ($convert_from_gmt) { $timestamp = $this->gmt_to_local($timestamp); } return Ai1ec_Time_Utility::date_i18n($date_format, $timestamp, true) . ' @ ' . Ai1ec_Time_Utility::date_i18n($time_format, $timestamp, true); }
/** * Display notices available to super-admin only * * Term super-admin identifies network admin in network * installation, or admin otherwise * * @return void Method does not return */ public function network_admin_notices() { // Premium plugin update available notice. $meta = Ai1ec_Meta::instance('Option'); if (!$meta->is_visible_update()) { return NULL; } global $ai1ec_view_helper; $args = array('label' => __('All-in-One Event Calendar Update', AI1EC_PLUGIN_NAME)); $update_url = AI1EC_UPGRADE_PLUGIN_BASE_URL; $args['msg'] = '<p>' . $meta->get('ai1ec_update_message', NULL, '') . '</p>'; $args['msg'] .= '<p><a class="button" href="' . admin_url($update_url) . '">'; $args['msg'] .= __('Upgrade now', AI1EC_PLUGIN_NAME); $args['msg'] .= '</a></p>'; $ai1ec_view_helper->display_admin('admin_notices.php', $args); }
/** * Checks and sends message to Twitter * * Upon successfully sending message - updates meta to reflect status change * * @return bool Success * * @throws Ai1ec_Oauth_Exception In case of some error */ protected function _send_twitter_message($event) { $format = '[title], [date] @ [venue], [link] [hashtags]'; $oauth = Ai1ec_Oauth_Controller::get_instance(); $status = Ai1ec_Meta::instance('Post')->get($event->post_id, '_ai1ec_post_twitter', array('not_requested')); if (is_array($status)) { $status = (string) current($status); } if ('pending' !== $status) { return false; } $terms = array_merge(wp_get_post_terms($event->post_id, 'events_categories'), wp_get_post_terms($event->post_id, 'events_tags')); $hashtags = array(); foreach ($terms as $term) { $hashtags[] = '#' . implode('_', explode(' ', $term->name)); } $hashtags = implode(' ', array_unique($hashtags)); $link = get_permalink($event->post) . $event->instance_id; $message = str_replace(array('[title]', '[date]', '@ [venue]', '[link]', '[hashtags]'), array($event->post->post_title, $event->get_short_start_date(), $event->venue, $link, $hashtags), $format); $message = trim(preg_replace('/ ,/', ',', preg_replace('/\\s+/', ' ', $message))); $length = strlen($message); $link_length = strlen($link); if ($link_length > 20) { $length += 20 - $link_length; } if ($length > 140) { $message = substr($message, 0, strrpos($message, ' ', 140 - $length)); } $status = $oauth->get_provider('twitter')->send_message($oauth->get_token($event->post->post_author, 'twitter'), $message); if (!$status) { return false; } return update_post_meta($event->post_id, '_ai1ec_post_twitter', array('status' => 'sent', 'twitter_status_id' => $status)); }
/** * admin_notices function * * Notify the user about anything special. * * @return void **/ function admin_notices() { global $ai1ec_view_helper, $ai1ec_settings, $plugin_page, $ai1ec_themes_controller, $ai1ec_importer_plugin_helper; if ('invalid' == $ai1ec_settings->license_warning) { $args = array('label' => __('All-in-One Event Calendar Warning', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Our records indicate that your license for the Pro Calendar has expired.</strong> Without a valid license you will not be able to access Premium Support services or receive software updates.</p><p>Please log into your <a href="%s" target="_blank">Timely Account</a> to renew your Pro license.</p>', AI1EC_PLUGIN_NAME), AI1EC_TIMELY_ACCOUNT_URL), 'button' => (object) array('class' => 'ai1ec-dismiss-license-warning', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME)), 'message_type' => 'error'); $ai1ec_view_helper->display_admin('admin_notices.php', $args); } // Display introductory video notice if not disabled. if ($ai1ec_settings->show_intro_video) { $args = array('label' => __('Welcome to the All-in-One Event Calendar, by Timely', AI1EC_PLUGIN_NAME), 'msg' => sprintf('<div class="timely"><a href="#ai1ec-video-modal" data-toggle="modal" ' . 'class="button-primary pull-left">%s</a>' . '<div class="pull-left"> </div></div>', __('Watch the introductory video ยป', AI1EC_PLUGIN_NAME)), 'button' => (object) array('class' => 'ai1ec-dismiss-intro-video', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME))); $ai1ec_view_helper->display_admin('admin_notices.php', $args); // Find out if CSS for Bootstrap modals has been attached. If not, embed // it inline. if (!wp_style_is('timely-bootstrap')) { $ai1ec_view_helper->display_admin_css('bootstrap.min.css'); } $args = array('title' => __('Introducing the All-in-One Event Calendar, by Timely', AI1EC_PLUGIN_NAME), 'youtube_id' => 'XJ-KHOqBKuQ'); $ai1ec_view_helper->display_admin('video_modal.php', $args); } // No themes available notice. if (!$ai1ec_themes_controller->are_themes_available()) { $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Core Calendar Themes are not installed.</strong></p>' . '<p>Our automated install couldn\'t install the core Calendar Themes automatically. ' . 'You will need to install calendar themes manually by following these steps:</p>' . '<ol><li>Gain access to your WordPress files. Either direct filesystem access or FTP access is fine.</li>' . '<li>Navigate to the <strong>%s</strong> folder.</li>' . '<li>Copy the <strong>%s</strong> folder and all of its contents into the <strong>%s</strong> folder.</li>' . '<li>You should now have a folder named <strong>%s</strong> containing all the same files and sub-folders as <strong>%s</strong> does.</li>' . '<li>Refresh this page and if this notice is gone, the core Calendar Themes are installed.</li></ol>', AI1EC_PLUGIN_NAME), AI1EC_PATH, AI1EC_THEMES_FOLDER, WP_CONTENT_DIR, WP_CONTENT_DIR . '/' . AI1EC_THEMES_FOLDER, AI1EC_PATH . '/' . AI1EC_THEMES_FOLDER)); $ai1ec_view_helper->display_admin('admin_notices.php', $args); } // Outdated themes notice (on all pages except update themes page). if ($plugin_page != AI1EC_PLUGIN_NAME . '-update-themes' && $ai1ec_themes_controller->are_themes_outdated()) { $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Core Calendar Themes are out of date.</strong> ' . 'We have found updates for some of your core Calendar Theme files and you should update them now to ensure proper functioning of your calendar.</p>' . '<p><strong>Warning:</strong> If you have previously modified any <strong>core</strong> Calendar Theme files, ' . 'your changes will be lost during update. Please make a backup of all modifications to core themes before proceeding.</p>' . '<p>Once you are ready, please <a href="%s">update your core Calendar Themes</a>.</p>', AI1EC_PLUGIN_NAME), admin_url(AI1EC_UPDATE_THEMES_BASE_URL))); $ai1ec_view_helper->display_admin('admin_notices.php', $args); } if ($ai1ec_settings->show_data_notification) { $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p>We collect some basic information about how your calendar works in order to deliver a better ' . 'and faster calendar system and one that will help you promote your events even more.</p>' . '<p>You can find more detailed information on our privacy policy by <a href="%s" target="_blank">clicking here</a>.</p>', AI1EC_PLUGIN_NAME), 'http://time.ly/event-search-calendar', admin_url(AI1EC_SETTINGS_BASE_URL)), 'button' => (object) array('class' => 'ai1ec-dismiss-notification', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME))); $ai1ec_view_helper->display_admin('admin_notices.php', $args); } // If calendar page or time zone has not been set, this is a fresh install. // Additionally, if we're not already updating the settings, alert user // appropriately that the calendar is not properly set up. if ((!$ai1ec_settings->calendar_page_id || !Ai1ec_Meta::get_option('timezone_string')) && !isset($_REQUEST['ai1ec_save_settings'])) { $args = array(); $messages = array(); // Display messages for blog admin. if (current_user_can('manage_ai1ec_options')) { // If on the settings page, instruct user as to what to do. if ($plugin_page == AI1EC_PLUGIN_NAME . '-settings') { if (!$ai1ec_settings->calendar_page_id) { $messages[] = __('Select an option in the <strong>Calendar page</strong> dropdown list.', AI1EC_PLUGIN_NAME); } if (!Ai1ec_Meta::get_option('timezone_string')) { $messages[] = __('Select an option in the <strong>Timezone</strong> dropdown list.', AI1EC_PLUGIN_NAME); } $messages[] = __('Click <strong>Update Settings</strong>.', AI1EC_PLUGIN_NAME); } else { $msg = sprintf(__('The plugin is installed, but has not been configured. <a href="%s">Click here to set it up now »</a>', AI1EC_PLUGIN_NAME), admin_url(AI1EC_SETTINGS_BASE_URL)); $messages[] = $msg; } } else { $messages[] = __('The plugin is installed, but has not been configured. Please log in as an Administrator to set it up.', AI1EC_PLUGIN_NAME); } // Format notice message. if (count($messages) > 1) { $args['msg'] = __('<p>To set up the plugin:</p>', AI1EC_PLUGIN_NAME); $args['msg'] .= '<ol><li>'; $args['msg'] .= implode('</li><li>', $messages); $args['msg'] .= '</li></ol>'; } else { $args['msg'] = "<p>{$messages['0']}</p>"; } $args['label'] = __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME); $ai1ec_view_helper->display_admin('admin_notices.php', $args); } // Premium plugin update available notice. $meta = Ai1ec_Meta::instance('Option'); if ($meta->get('ai1ec_update_available', NULL, false) && current_user_can('update_plugins')) { $args = array('label' => __('All-in-One Event Calendar Update', AI1EC_PLUGIN_NAME)); $update_url = AI1EC_UPGRADE_PLUGIN_BASE_URL; $args['msg'] = '<p>' . $meta->get('ai1ec_update_message', NULL, '') . '</p>'; $args['msg'] .= '<p><a class="button" href="' . admin_url($update_url) . '">'; $args['msg'] .= __('Upgrade now', AI1EC_PLUGIN_NAME); $args['msg'] .= '</a></p>'; $ai1ec_view_helper->display_admin('admin_notices.php', $args); } // Let the plugin display their notice. $ai1ec_importer_plugin_helper->display_admin_notices(); }
/** * Return checkbox `checked` status for given event and provider * * @param Ai1ec_Event $event Instance of Ai1ec_Event concerned * @param string $provider Name of provider to check * * @return string Value for `checked` part of checkbox */ protected function _selected_for_posting(Ai1ec_Event $event = NULL, $provider) { if (NULL === $event || !isset($event->post_id) || empty($event->post_id)) { return ''; } $meta = '_ai1ec_post_' . $provider; $status = Ai1ec_Meta::instance('Post')->get($event->post_id, $meta, false); if (false === $status) { return ''; } return 'checked="checked"'; }