/**
  * Called by WPCOM_Liveblog::load(),
  * it attaches the new command.
  */
 public static function load()
 {
     add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));
     add_filter('liveblog_before_insert_entry', array(__CLASS__, 'strip_input'), 1);
     add_filter('liveblog_before_update_entry', array(__CLASS__, 'strip_input'), 1);
     // Allow the features to be seperated in multiple ways: via spaces,
     // pipes or commas. This line explodes via spaces and pipes then
     // proceeds to explode it via commas. This allows for the tidy:
     // feature_one, feature_two, feature_three
     self::$features = explode(',', preg_replace('~[ |]+~', ',', self::$features));
     self::$features = array_filter(self::$features, 'strlen');
     // We pass these features into a filter to allow other plugins,
     // themes, etc. to enable or disable any of the features.
     self::$features = apply_filters('liveblog_features', self::$features);
     // This is the autocomplete prefix regex.
     $regex_prefix = '~(?:(?<!\\S)|>?)((?:';
     // This is the autocomplete postfix regex.
     $regex_postfix = '){1}([0-9_\\-\\p{L}]*[_\\-\\p{L}][0-9_\\-\\p{L}]*))(?:<)?~um';
     // We loop every feature and set them up individually.
     foreach (self::$features as $name) {
         // Grab the class from what we expect the classname to be.
         // WPCOM_Liveblog_Entry_Extend_Feature_{{ $name }}
         $class = __CLASS__ . '_Feature_' . ucfirst($name);
         $feature = new $class();
         // Add all the basic (common) feature filters.
         add_filter('liveblog_extend_autocomplete', array($feature, 'get_config'), 10);
         add_filter('liveblog_before_insert_entry', array($feature, 'filter'), 10);
         add_filter('liveblog_before_update_entry', array($feature, 'filter'), 10);
         add_filter('liveblog_before_preview_entry', array($feature, 'filter'), 10);
         add_filter('liveblog_before_edit_entry', array($feature, 'revert'), 10);
         // Set the prefixes to the filtered prefixes.
         // This allows themes, plugins, etc. to change prefixes.
         $feature->set_prefixes(apply_filters('liveblog_' . $name . '_prefixes', $feature->get_prefixes()));
         // We apply the prefixes to the regex so we can match them
         // during the autocomplete and matching process.
         $regex = $regex_prefix . implode('|', $feature->get_prefixes()) . $regex_postfix;
         $feature->set_regex(apply_filters('liveblog_' . $name . '_regex', $regex));
         // Finally, simply load the feature as it may have it's
         // own setup that it is required to complete.
         $feature->load();
     }
     // Allow external sources to build the autocomplete config that is
     // used by the frontend javascript for autocomplete matching.
     self::$autocomplete = apply_filters('liveblog_extend_autocomplete', self::$autocomplete);
 }
Beispiel #2
0
 /**
  * Enqueue the necessary CSS and JS that liveblog needs to function.
  *
  * @return If not a liveblog post
  */
 public static function enqueue_scripts()
 {
     if (!self::is_viewing_liveblog_post()) {
         return;
     }
     wp_enqueue_style(self::key, plugins_url('css/liveblog.css', __FILE__));
     wp_register_script('jquery-throttle', plugins_url('js/jquery.ba-throttle-debounce.min.js', __FILE__));
     wp_register_script('moment', plugins_url('js/moment.min.js', __FILE__), array(), '1.7.2');
     wp_localize_script('moment', 'momentLang', array('locale' => get_locale(), 'relativeTime' => array('past' => __('%s ago', 'liveblog'), 's' => __('a few seconds', 'liveblog'), 'm' => __('a minute', 'liveblog'), 'mm' => __('%d minutes', 'liveblog'), 'h' => __('an hour', 'liveblog'), 'hh' => __('%d hours', 'liveblog'), 'd' => __('a day', 'liveblog'), 'dd' => __('%d days', 'liveblog'), 'M' => __('a month', 'liveblog'), 'MM' => __('%d months', 'liveblog'), 'y' => __('a year', 'liveblog'), 'yy' => __('%d years', 'liveblog'))));
     wp_enqueue_script(self::key, plugins_url('js/liveblog.js', __FILE__), array('jquery', 'jquery-color', 'backbone', 'jquery-throttle', 'moment'), self::version, true);
     if (self::is_liveblog_editable()) {
         if (apply_filters('liveblog_rich_text_editing_allowed', true)) {
             wp_enqueue_script('editor');
         }
         wp_enqueue_script('liveblog-publisher', plugins_url('js/liveblog-publisher.js', __FILE__), array(self::key), self::version, true);
         wp_enqueue_script('liveblog-plupload', plugins_url('js/plupload.js', __FILE__), array(self::key, 'wp-plupload', 'jquery'));
         self::add_default_plupload_settings();
     }
     if (wp_script_is('jquery.spin', 'registered')) {
         wp_enqueue_script('jquery.spin');
     } else {
         wp_enqueue_script('spin', plugins_url('js/spin.js', __FILE__), false, '1.3');
         wp_enqueue_script('jquery.spin', plugins_url('js/jquery.spin.js', __FILE__), array('jquery', 'spin'), '1.3');
     }
     wp_localize_script(self::key, 'liveblog_settings', apply_filters('liveblog_settings', array('permalink' => get_permalink(), 'post_id' => get_the_ID(), 'state' => self::get_liveblog_state(), 'key' => self::key, 'nonce_key' => self::nonce_key, 'nonce' => wp_create_nonce(self::nonce_key), 'latest_entry_timestamp' => self::$entry_query->get_latest_timestamp(), 'refresh_interval' => WP_DEBUG ? self::debug_refresh_interval : self::refresh_interval, 'max_consecutive_retries' => self::max_consecutive_retries, 'delay_threshold' => self::delay_threshold, 'delay_multiplier' => self::delay_multiplier, 'fade_out_duration' => self::fade_out_duration, 'endpoint_url' => self::get_entries_endpoint_url(), 'features' => WPCOM_Liveblog_Entry_Extend::get_enabled_features(), 'autocomplete' => WPCOM_Liveblog_Entry_Extend::get_autocomplete(), 'command_class' => apply_filters('liveblog_command_class', WPCOM_Liveblog_Entry_Extend_Feature_Commands::$class_prefix), 'delete_confirmation' => __('Do you really want to delete this entry? There is no way back.', 'liveblog'), 'delete_key_confirm' => __('Do you want to delete this key entry?', 'liveblog'), 'error_message_template' => __('Error {error-code}: {error-message}', 'liveblog'), 'short_error_message_template' => __('Error: {error-message}', 'liveblog'), 'new_update' => __('Liveblog: {number} new update', 'liveblog'), 'new_updates' => __('Liveblog: {number} new updates', 'liveblog'), 'create_link_prompt' => __('Provide URL for link:', 'liveblog'), 'class_term_prefix' => __('term-', 'liveblog'), 'class_alert' => __('type-alert', 'liveblog'), 'class_key' => __('type-key', 'liveblog'))));
     wp_localize_script('liveblog-publisher', 'liveblog_publisher_settings', array('loading_preview' => __('Loading preview…', 'liveblog'), 'new_entry_tab_label' => __('New Entry', 'liveblog'), 'new_entry_submit_label' => __('Publish Update', 'liveblog'), 'edit_entry_tab_label' => __('Edit Entry', 'liveblog'), 'edit_entry_submit_label' => __('Update', 'liveblog')));
 }