Permalink
Browse files

Load initial entries server-side rather than via AJAX for SEO benefit

  • Loading branch information...
1 parent 8ff4206 commit cb778e4361fd03737d8ae90678465f995a362ef5 @mjangda mjangda committed Jun 6, 2012
Showing with 17 additions and 7 deletions.
  1. +4 −2 js/liveblog.js
  2. +13 −5 liveblog.php
View
@@ -3,6 +3,8 @@ var liveblog = {};
( function( $ ) {
liveblog.init = function() {
+ liveblog.set_timestamp( liveblog_settings.last_timestamp );
+
liveblog.$container = $( '#liveblog-entries' );
// Damn you wp_localize_script
@@ -11,7 +13,7 @@ var liveblog = {};
liveblog_settings.delay_threshold = parseInt( liveblog_settings.delay_threshold );
liveblog_settings.delay_multiplier = parseFloat( liveblog_settings.delay_multiplier );
- liveblog.get_recent_entries();
+ liveblog.reset_timer();
}
liveblog.kill_timer = function() {
@@ -151,7 +153,7 @@ var liveblog = {};
// If the entry is already there, update it
var $entry = $( '#liveblog-entry-' + entry.ID );
if ( $entry.length ) {
- $entry.html( entry.content )
+ $entry.replaceWith( entry.content )
.addClass( 'liveblog-updated' )
.one( 'mouseover', function() {
$( this ).removeClass( 'liveblog-updated' );
View
@@ -14,7 +14,6 @@
TODO (future):
-- Manual refresh button
-- Allow marking of liveblog as ended
--- SEO consideration (output entries server-side on initial load)
-- Allow comment modifications; need to store modified date as comment_meta
-- Drag-and-drop image uploading support
@@ -134,7 +133,7 @@ function ajax_get_recent_entries( $timestamp = 0 ) {
foreach( $entries as $entry ) {
$filtered_entry = new stdClass;
$filtered_entry->ID = $entry->comment_ID;
- $filtered_entry->content = self::entry_output( $entry, array(), false );
+ $filtered_entry->content = self::entry_output( $entry, false );
array_push( $filtered_entries, $filtered_entry );
}
@@ -144,7 +143,7 @@ function ajax_get_recent_entries( $timestamp = 0 ) {
self::json_return( true, '', array( 'entries' => $filtered_entries, 'timestamp' => $last_timestamp ) );
}
- function entry_output( $entry, $args = array(), $echo = true ) {
+ function entry_output( $entry, $echo = true ) {
$entry_id = $entry->comment_ID;
$post_id = $entry->comment_post_ID;
$output = '';
@@ -154,7 +153,7 @@ function entry_output( $entry, $args = array(), $echo = true ) {
if ( $output )
return $output;
- $args = wp_parse_args( $args, array(
+ $args = apply_filters( 'liveblog_entry_output_args', array(
'avatar_size' => 30,
) );
@@ -232,6 +231,7 @@ function enqueue_scripts() {
'nonce_key' => self::nonce_key,
'permalink' => get_permalink(),
'post_id' => get_the_ID(),
+ 'last_timestamp' => self::get_last_entry_timestamp(),
'refresh_interval' => self::refresh_interval,
'max_retries' => self::max_retries,
@@ -249,9 +249,17 @@ function enqueue_scripts() {
}
function add_liveblog_to_content( $content ) {
+ $post_id = get_the_ID();
+ $entries = self::get_entries_since( $post_id );
+
$liveblog_output = '';
$liveblog_output .= self::get_entry_editor_output();
- $liveblog_output .= '<div id="liveblog-entries" class="liveblog-container"></div>';
+ $liveblog_output .= '<div id="liveblog-entries" class="liveblog-container">';
+ foreach ( (array) $entries as $entry ) {
+ $liveblog_output .= self::entry_output( $entry, false );
+ }
+
+ $liveblog_output .= '</div>';
return $content . $liveblog_output;
}

0 comments on commit cb778e4

Please sign in to comment.