Ejemplo n.º 1
0
 public function render($template = 'liveblog-single-entry.php')
 {
     $output = apply_filters('liveblog_pre_entry_output', '', $this);
     if (!empty($output)) {
         return $output;
     }
     if (empty($this->comment->comment_content)) {
         return $output;
     }
     $entry = $this->get_fields_for_render();
     $entry = apply_filters('liveblog_entry_template_variables', $entry);
     return WPCOM_Liveblog::get_template_part($template, $entry);
 }
Ejemplo n.º 2
0
 /**
  * Look for any new Liveblog entries, and return them via JSON
  */
 public static function ajax_entries_between()
 {
     // Set some defaults
     $latest_timestamp = 0;
     $entries_for_json = array();
     // Look for entry boundaries
     list($start_timestamp, $end_timestamp) = self::get_timestamps_from_query();
     // Bail if there is no end timestamp
     if (empty($end_timestamp)) {
         self::send_user_error(__('A timestamp is missing. Correct URL: <permalink>/liveblog/<from>/</to>/', 'liveblog'));
     }
     // Do not cache if it's too soon
     if ($end_timestamp > time()) {
         self::$do_not_cache_response = true;
     }
     // Get liveblog entries within the start and end boundaries
     $entries = self::$entry_query->get_between_timestamps($start_timestamp, $end_timestamp);
     if (empty($entries)) {
         do_action('liveblog_entry_request_empty');
         self::json_return(array('entries' => array(), 'latest_timestamp' => null));
     }
     /**
      * Loop through each liveblog entry, set the most recent timestamp, and
      * put the JSON data for each entry into a neat little array.
      */
     foreach ($entries as $entry) {
         $latest_timestamp = max($latest_timestamp, $entry->get_timestamp());
         $entries_for_json[] = $entry->for_json();
     }
     // Setup our data to return via JSON
     $result_for_json = array('entries' => $entries_for_json, 'latest_timestamp' => $latest_timestamp);
     do_action('liveblog_entry_request', $result_for_json);
     self::json_return($result_for_json);
 }
 /**
  * Enqueues the lazyloader script file.
  *
  * @wp-hook wp_enqueue_scripts
  *
  * @return void
  */
 public static function enqueue_script()
 {
     if (!WPCOM_Liveblog::is_viewing_liveblog_post()) {
         return;
     }
     $handle = 'liveblog-lazyloader';
     $path = 'js/liveblog-lazyloader.js';
     $plugin_path = dirname(__FILE__);
     $temp = plugin_dir_path($plugin_path) . $path;
     wp_enqueue_script($handle, plugins_url($path, $plugin_path), array('liveblog'), filemtime($temp), true);
     wp_localize_script($handle, 'liveblogLazyloaderSettings', array('loadMoreText' => esc_html__('Load more entries&hellip;', 'liveblog')));
 }
 /**
  * Loads in the scripts and styles for autocomplete
  */
 public static function enqueue_scripts()
 {
     if (WPCOM_Liveblog::is_liveblog_editable()) {
         $path = dirname(__FILE__);
         wp_enqueue_style('textcomplete-css', plugins_url('/css/jquery.textcomplete.css', $path));
         wp_enqueue_script('textcomplete-script', plugins_url('/js/jquery.textcomplete.min.js', $path), false, true);
     }
 }
 /**
  * Builds the box to display key entries
  *
  * @param $atts
  * @return mixed
  */
 public static function shortcode($atts)
 {
     global $post;
     if (!is_single()) {
         return;
     }
     // Define the default shortcode attributes.
     $atts = shortcode_atts(array('title' => 'Key Events'), $atts);
     // The args to pass into the entry query.
     $args = array('meta_key' => self::meta_key, 'meta_value' => self::meta_value);
     $limit = get_post_meta($post->ID, self::meta_key_limit, true);
     if (isset($limit)) {
         $args['number'] = $limit;
     }
     // Build the entry query.
     $entry_query = new WPCOM_Liveblog_Entry_Query($post->ID, WPCOM_Liveblog::key);
     // Execute the entry query with the previously defined args.
     $entries = (array) $entry_query->get_all($args);
     // Grab the template to use.
     $template = self::get_current_template($post->ID);
     // Only run the shortcode on an archived or enabled post.
     if (WPCOM_Liveblog::get_liveblog_state($post->ID)) {
         // Render the actual template.
         return WPCOM_Liveblog::get_template_part('liveblog-key-events.php', array('entries' => $entries, 'title' => $atts['title'], 'template' => $template[0], 'wrap' => $template[1], 'class' => $template[2]));
     }
 }
Ejemplo n.º 6
0
 function test_headers_should_skip_null_bytes()
 {
     $this->assertEquals('baba', WPCOM_Liveblog::sanitize_http_header('ba' . chr(0) . 'ba'));
 }
	<a class="link" href="#liveblog-entry-<?php 
echo esc_attr($entry_id);
?>
" data-entry-id="<?php 
echo esc_attr($entry_id);
?>
">
		<span class="date liveblog-time-update"><?php 
echo esc_html($entry_date);
?>
 - <?php 
echo esc_html($entry_time);
?>
</span>
		<span class="title"><?php 
echo WPCOM_Liveblog_Entry_Key_Events::get_formatted_content($content, $post_id);
?>
</span>
	</a>
	<?php 
if (WPCOM_Liveblog::current_user_can_edit_liveblog()) {
    ?>
		<span class="dashicons dashicons-no liveblog-key-event-delete" data-entry-id="<?php 
    echo $entry_id;
    ?>
"></span>
	<?php 
}
?>
</li>
Ejemplo n.º 8
0
 /**
  * Fetches all Liveblog entries that are to be lazyloaded, and returns them via JSON.
  */
 public static function ajax_lazyload_entries()
 {
     // The URL is of the form "lazyload/optional_max_timestamp/optional_min_timestamp".
     $fragments = explode('/', get_query_var(self::url_endpoint));
     // Get all Liveblog entries that are to be lazyloaded.
     $entries = self::$entry_query->get_for_lazyloading(isset($fragments[1]) ? (int) $fragments[1] : 0, isset($fragments[2]) ? (int) $fragments[2] : 0);
     if (!$entries) {
         do_action('liveblog_entry_request_empty');
         self::json_return(array('entries' => array(), 'index' => (int) filter_input(INPUT_GET, 'index')));
     }
     $entries = array_slice($entries, 0, WPCOM_Liveblog_Lazyloader::get_number_of_entries());
     $entries_for_json = array();
     // Set up an array containing the JSON data for all Liveblog entries.
     foreach ($entries as $entry) {
         $entries_for_json[] = $entry->for_json();
     }
     // Set up the data to be returned via JSON.
     $result_for_json = array('entries' => $entries_for_json, 'index' => (int) filter_input(INPUT_GET, 'index'));
     do_action('liveblog_entry_request', $result_for_json);
     self::$do_not_cache_response = true;
     self::json_return($result_for_json);
 }