/** * 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); }
/** * 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); }