Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add inline comments for liveblog comments

Comments have liveblog comment persisted with some hackery as otherwise
WordPress sets the comment_parent to 0 since it is not a recognized status.

Still needing to render the comments under the liveblog comment parents.
  • Loading branch information...
commit 94958de51f786e4eed6389cc0c3124fcdb8c5c29 1 parent 298d8f5
@westonruter westonruter authored
View
7 classes/class-wpcom-liveblog-entry.php
@@ -83,6 +83,7 @@ public function get_fields_for_render() {
'entry_time' => get_comment_date( get_option('time_format'), $entry_id ),
'timestamp' => $this->get_timestamp(),
'is_liveblog_editable' => WPCOM_Liveblog::is_liveblog_editable(),
+ 'is_liveblog_commenting_open' => self::is_commenting_enabled( $post_id )
);
return $entry;
@@ -98,7 +99,6 @@ public function render() {
return $output;
$entry = $this->get_fields_for_render();
-
$entry = apply_filters( 'liveblog_entry_template_variables', $entry );
return WPCOM_Liveblog::get_template_part( 'liveblog-single-entry.php', $entry );
@@ -192,6 +192,11 @@ public static function delete( $args ) {
return $entry;
}
+ public static function is_commenting_enabled( $post = null ) {
+ $post = get_post( $post );
+ return apply_filters( 'liveblog_commenting_enabled', comments_open( $post ) );
+ }
+
private static function insert_comment( $args ) {
$valid_args = self::validate_args( $args );
if ( is_wp_error( $valid_args ) ) {
View
3  css/liveblog.css
@@ -177,6 +177,9 @@ a.liveblog-form-entry::-webkit-input-placeholder {
.liveblog-actions .liveblog-submit-wrapper .liveblog-entry-delete {
float: right;
}
+.liveblog-actions .liveblog-submit-wrapper .liveblog-entry-reply {
+ display: none;
+}
/* Remove the dotted border on :focus and the extra padding in Firefox */
#liveblog-container .button-secondary::-moz-focus-inner {
border-width: 1px 0;
View
2  js/liveblog-publisher.js
@@ -69,6 +69,7 @@
e.preventDefault();
this.$entry_text.show();
this.$entry.find('.liveblog-entry-edit').show();
+ this.$entry.find('.liveblog-entry-reply').show();
this.$entry.find('.liveblog-entry-actions .liveblog-entry-delete').show();
this.remove();
},
@@ -232,6 +233,7 @@
}
form.render();
entry.find( '.liveblog-entry-edit' ).hide();
+ entry.find( '.liveblog-entry-reply' ).hide();
entry.find('.liveblog-entry-actions .liveblog-entry-delete').hide();
};
View
16 js/liveblog.js
@@ -135,9 +135,25 @@ window.liveblog = {};
liveblog.set_initial_timestamps();
liveblog.start_human_time_diff_timer();
+ if ( liveblog_settings.commenting_enabled ) {
+ liveblog.init_commenting();
+ }
liveblog.$events.trigger( 'after-init' );
};
+ liveblog.init_commenting = function () {
+ liveblog.entriesContainer.$el.on('click', '.comment-reply-link', function (e) {
+ var $reply_link = $(this);
+ addComment.moveForm(
+ $reply_link.data('commentElementId'),
+ $reply_link.data('commentId'),
+ $reply_link.data('respondElementId'),
+ $reply_link.data('postId')
+ );
+ e.preventDefault();
+ });
+ };
+
liveblog.init_moment_js = function() {
momentLang.relativeTime = _.extend(moment().lang().relativeTime, momentLang.relativeTime);
moment.lang(momentLang.locale, momentLang);
View
47 liveblog.php
@@ -118,6 +118,7 @@ private static function add_actions() {
add_action( 'init', array( __CLASS__, 'flush_rewrite_rules' ), 1000 );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) );
+ add_action( 'comment_post', array( __CLASS__, 'fixup_comment_parent' ), 10, 2 );
add_action( 'wp_ajax_set_liveblog_state_for_post', array( __CLASS__, 'admin_ajax_set_liveblog_state_for_post' ) );
}
@@ -127,8 +128,9 @@ private static function add_actions() {
* @uses add_filter()
*/
private static function add_filters() {
- add_filter( 'template_redirect', array( __CLASS__, 'handle_request' ) );
- add_filter( 'comment_class', array( __CLASS__, 'add_comment_class' ), 10, 3 );
+ add_filter( 'template_redirect', array( __CLASS__, 'handle_request' ) );
+ add_filter( 'comment_class', array( __CLASS__, 'add_comment_class' ), 10, 3 );
+ add_filter( 'preprocess_comment', array( __CLASS__, 'save_original_comment_parent_for_fixup' ) );
}
/**
@@ -453,6 +455,43 @@ public static function add_comment_class( $classes, $class, $comment_id ) {
return $classes;
}
+ private static $_original_comment_parent_at_preprocess;
+
+ /**
+ * Save the original comment_parent since we can't filter it
+ * @see wp_new_comment()
+ * @filter preprocess_comment
+ */
+ public static function save_original_comment_parent_for_fixup( $commentdata ) {
+ if ( self::is_liveblog_post( $commentdata['comment_post_ID'] ) ) {
+ self::$_original_comment_parent_at_preprocess = $commentdata['comment_parent'];
+ }
+ return $commentdata;
+ }
+
+ /**
+ * Aggravatingly, the wp_filter_comment() function does not provide a pre_comment_parent filter,
+ * and neither does wp_insert_comment() provide a way to filter the comment_parent field.
+ * So we have to fixup the comment_parent right after the comment is posted.
+ * @see wp_new_comment()
+ * @action comment_post
+ */
+ public static function fixup_comment_parent( $comment_ID, $comment_approved ) {
+ $comment = (array) get_comment( $comment_ID );
+ $should_fixup = (
+ self::is_liveblog_post( $comment['comment_post_ID'] )
+ &&
+ ! empty( self::$_original_comment_parent_at_preprocess )
+ &&
+ WPCOM_Liveblog_Entry::is_commenting_enabled( $comment['comment_post_ID'] )
+ );
+ if ( $should_fixup ) {
+ $comment['comment_parent'] = self::$_original_comment_parent_at_preprocess;
+ wp_update_comment( $comment );
+ }
+ self::$_original_comment_parent_at_preprocess = null;
+ }
+
public static function admin_enqueue_scripts() {
wp_enqueue_style( self::key, plugins_url( 'css/liveblog-admin.css', __FILE__ ) );
wp_enqueue_script( 'liveblog-admin', plugins_url( 'js/liveblog-admin.js', __FILE__ ) );
@@ -502,6 +541,9 @@ public static function enqueue_scripts() {
wp_enqueue_script( 'liveblog-plupload', plugins_url( 'js/plupload.js', __FILE__ ), array( self::key, 'wp-plupload', 'jquery' ) );
self::add_default_plupload_settings();
}
+ if ( WPCOM_Liveblog_Entry::is_commenting_enabled() ) {
+ wp_enqueue_script( 'comment-reply' );
+ }
if ( wp_script_is( 'jquery.spin', 'registered' ) ) {
wp_enqueue_script( 'jquery.spin' );
@@ -515,6 +557,7 @@ public static function enqueue_scripts() {
'permalink' => get_permalink(),
'post_id' => get_the_ID(),
'state' => self::get_liveblog_state(),
+ 'commenting_enabled' => WPCOM_Liveblog_Entry::is_commenting_enabled(),
'key' => self::key,
'nonce_key' => self::nonce_key,
View
24 templates/liveblog-single-entry.php
@@ -1,4 +1,5 @@
-<div id="liveblog-entry-<?php echo $entry_id; ?>" <?php echo $css_classes; ?> data-timestamp="<?php echo $timestamp; ?>">
+<?php $div_id = "liveblog-entry-$entry_id" ?>
+<div id="<?php echo esc_attr( $div_id ); ?>" <?php echo $css_classes; ?> data-timestamp="<?php echo $timestamp; ?>">
<header class="liveblog-meta">
<span class="liveblog-author-avatar"><?php echo $avatar_img; ?></span>
<span class="liveblog-author-name"><?php echo $author_link; ?></span>
@@ -7,9 +8,26 @@
<div class="liveblog-entry-text" data-original-content="<?php echo esc_attr( $original_content ); ?>">
<?php echo $content; ?>
</div>
-<?php if ( $is_liveblog_editable ): ?>
+<?php if ( $is_liveblog_editable || $is_liveblog_commenting_open ): ?>
<ul class="liveblog-entry-actions">
- <li><button class="liveblog-entry-edit button-secondary"><?php _e( 'Edit', 'liveblog' ); ?></button><button class="liveblog-entry-delete button-secondary"><?php _e( 'Delete', 'liveblog' ); ?></button></li>
+ <li>
+ <?php if ( $is_liveblog_editable ): ?>
+ <button class="liveblog-entry-edit button-secondary"><?php _e( 'Edit', 'liveblog' ); ?></button>
+ <?php endif; ?>
+ <?php if ( $is_liveblog_commenting_open ): ?>
+ <a
+ class="comment-reply-link"
+ href="<?php echo esc_url( add_query_arg( 'replytocom', $entry_id ) . '#respond' ) ?>"
+ data-comment-id="<?php echo esc_attr( $entry_id ) ?>"
+ data-comment-element-id="<?php echo esc_attr( $div_id ) ?>"
+ data-respond-element-id="<?php echo esc_attr( 'respond' ) ?>"
+ data-post-id="<?php echo esc_attr( get_the_ID() ) ?>"
+ ><?php _e( 'Reply', 'liveblog' ); ?></a>
+ <?php endif; ?>
+ <?php if ( $is_liveblog_editable ): ?>
+ <button class="liveblog-entry-delete button-secondary"><?php _e( 'Delete', 'liveblog' ); ?></button>
+ <?php endif; ?>
+ </li>
</ul>
<?php endif; ?>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.