add_moderator_role(); // If we're requesting ajax stuff we'll hand over control to spec ajax then die. if ( isset( $_REQUEST[ '_spec_ajax' ] ) ) { new spectacula_ajax( ); } $this->comment_moderation_calls(); add_filter( 'body_class', array( $this, 'get_agent_body_class' ) ); add_action( 'wp_head', array( $this, 'css' ) ); add_action( 'wp', array( $this, 'before_headers' ) ); add_action( 'comment_form', array( $this, 'our_credit' ) ); add_filter( 'comments_template', array( $this, 'comment_template_hijack' ) ); // The live comment toggle metabox. Lets you toggle live comments on // a post by post basis. add_action( 'admin_init', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_metabox_toggle_status' ), 100, 2 ); add_filter( 'comments_array', array( $this, 'comment_query_hijack')); // Make sure the stylesheet has the correct schema add_filter( 'spec_comment_css', array( $this, 'set_stylesheet_schema' ), 1000 ); } /** * Make sure the stylesheet is called with the correct schema. * * @param string $stylesheet The URL * * @return string The corrected URL. */ public function set_stylesheet_schema( $stylesheet = '' ) { return set_url_scheme( $stylesheet, is_ssl() ? 'https' : 'http' ); } function add_moderator_role(){ $result = add_role('spec_comment_moderator', 'Comment Moderator', array( 'read' => true, // True allows that capability 'moderate_comments' => true )); } /* This should execute before headers are sent but after WP has set up the post data allowing us to check to see if we're on a page that would require comments. This will simply add the JavaScript and JS localisations to the header if we're on a post that needs them. @uses apply_filters( ) Calls 'spec_comment_js' hook on the path to the commenting jQuery js file. @uses apply_filters( ) Calls 'spec_comment_local_js' hook on the array of the localisation data. Allows you to change/add more text if you choose to roll your own JS file. @return null; */ function before_headers() { global $post; // Quick check that this post_type supports comments. $post_type_supports = function_exists( 'post_type_supports' ) && is_object( $post ) ? post_type_supports( $post->post_type, 'comments' ) : true; if( function_exists( 'wp_list_comments' ) && is_singular( ) && $post_type_supports && comments_open( $post->ID ) ) { $prefix = ! defined( 'SCRIPT_DEBUG' ) || ( defined( 'SCRIPT_DEBUG' ) && ! SCRIPT_DEBUG ) ? '.min' : ''; wp_register_script( 'json2', SPEC_COMMENT_URL . "/js/json2.js", array( ), '20090817', true ); wp_register_script( 'autogrow', SPEC_COMMENT_URL . "/js/jquery.autogrow-textarea$prefix.js", array( 'jquery' ), 1.04, true ); wp_register_script( 'scrollto', SPEC_COMMENT_URL . "/js/jquery.scrollTo-master/jquery.scrollTo.min.js", array( 'jquery' ), '1.4.11', true ); wp_deregister_script( 'comment-reply' ); // dealt with by the included jQuery global $post; $time = current_time( 'mysql', false ); $localisation = array( 'tb_show' => __( 'Show trackbacks', SPEC_COMMENT_DOM ), 'tb_hide' => __( 'Hide trackbacks', SPEC_COMMENT_DOM ), 'rpl_hide_2' => __( "Hide %count% replies to %name%'s comment", SPEC_COMMENT_DOM ), 'rpl_show_2' => __( "View %count% replies to %name%'s comment", SPEC_COMMENT_DOM ), 'rpl_hide_1' => __( "Hide the reply to %name%'s comment", SPEC_COMMENT_DOM ), 'rpl_show_1' => __( "View the reply to %name%'s comment", SPEC_COMMENT_DOM ), 'tb_from' => __( 'Trackback from: %s', SPEC_COMMENT_DOM ), 'err_txt_mis' => __( 'Missing some fields', SPEC_COMMENT_DOM ), 'unknown' => __( 'Unknown commenter', SPEC_COMMENT_DOM ), 'order' => get_option( 'comment_order' ), 'polling' => spec_comment_option( 'polling' ), 'update' => $this->check_live( $post->ID ) && comments_open( $post->ID ) ? 1 : 0, 'time' => $time, 'post_id' => $post->ID, 'ajax_url' => trailingslashit( home_url( ) ), 'nest_depth' => spec_comment_option( 'comments_nest_depth' ), 'max_depth' => get_option( 'thread_comments_depth' ), 'scroll_off' => spec_comment_option( 'tc_scroll_offset', 0 ) ); if ( spec_comment_option( 'quote_button' ) || spec_comment_option( 'quote_select' ) ) { wp_enqueue_script( 'spec_quote_button', SPEC_COMMENT_URL . "/js/quote$prefix.js", array( 'jquery' ), '1.0.3', true ); $quote_options = array( 'button_text' => __( 'Quote', SPEC_COMMENT_DOM ), 'quote_button' => spec_comment_option( 'quote_button' ), 'quote_select' => spec_comment_option( 'quote_select' ), 'quote_target' => spec_comment_option( 'quote_target' ) ); wp_localize_script( 'spec_quote_button', 'specQuoteLn', $quote_options ); } wp_enqueue_script( 'commenting', apply_filters( 'spec_comment_js', SPEC_COMMENT_URL . "/js/commenting$prefix.js" ), array( 'jquery', 'autogrow', 'jquery-form', 'json2', 'scrollto' ), '1.0.3', true ); wp_localize_script( 'commenting', 'commentingL10n', apply_filters( 'spec_comment_local_js', $localisation ) ); } } /* Change the path to the comments.php to point to our new comments.php file. @param string $passed passed in by comments_template apply_filters call and would normally contain the path to the theme's comments.php @return string the new comments.php if it exists otherwise just return the one we were given before. */ function comment_template_hijack( $passed ){ if ( file_exists( SPEC_COMMENT_TMP ) ) return SPEC_COMMENT_TMP; else return $passed; } /** * Hijack the comments and redo it if the current user can moderate comments so they can see them all **/ function comment_query_hijack($comments){ if(current_user_can('moderate_comments')){ global $post; $comments = get_comments( array('post_id' => $post->ID, 'status' => '', 'order' => 'ASC') ); } return $comments; } function comment_moderation_calls(){ if(current_user_can('moderate_comments')){ if(isset($_GET['p']) && ( isset($_GET['approvecomment']) || isset($_GET['spamcomment']) || isset($_GET['deletecomment']) )){ $post_id = $_GET['p']; if(isset($_GET['approvecomment'])){ $comment_id = $_GET['approvecomment']; spec_comment_approve_comment($comment_id); } else if(isset($_GET['spamcomment'])){ $comment_id = $_GET['spamcomment']; spec_comment_spam_comment($comment_id); } else if(isset($_GET['deletecomment'])){ $comment_id = $_GET['deletecomment']; spec_comment_delete_comment($comment_id); } } } } /* Add the comments.css file to the head of pages that'll need comments. @uses apply_filters( ) Calls 'spec_comment_css' hook on the the path to the stylesheet so that you can roll your own should you need/want to. @return null; */ function css( ){ if ( is_singular( ) && strtolower( spec_comment_option( 'stylesheet' ) ) != 'disabled' ) { ?> = 9 && $version < 10 ) { $class[ ] = 'ie'; $class[ ] = 'ie9'; // Look forward to the day when this is the standard IE, shouldn't need this anymore then. :D } elseif ( ! in_array( 'ie8', $class ) && $version >= 8 && $version < 9 ) { $class[ ] = 'ie'; $class[ ] = 'ie8'; } elseif ( ! in_array( 'ie7', $class ) && $version >= 7 && $version < 8 ) { $class[ ] = 'ie'; $class[ ] = 'ie7'; } elseif ( ! in_array( 'ie6', $class ) && $version >= 6 && $version < 7 ) { $class[ ] = 'ie'; $class[ ] = 'ie6'; } elseif ( ! in_array( 'ie55', $class ) && $version >= 5.5 && $version < 6 ) { $class[ ] = 'ie'; $class[ ] = 'ie55'; } elseif ( ! in_array( 'ie5', $class ) && $version >= 5 && $version < 5.5 ) { $class[ ] = 'ie'; $class[ ] = 'ie5'; } elseif ( ! in_array( 'ie-old', $class ) && $version < 5 ) { $class[ ] = 'ie'; $class[ ] = 'ie-old'; } else { // Unknown IE. $class[ ] = 'ie'; $class[ ] = 'iexx'; } } return $class; } /* This is attached to the comment_form action and just echos out our credit link. If you don't want to give us credit for this :( then you can hide the link from the admin page. */ function our_credit( ){ if ( spec_comment_option( 'credit' ) ) { echo '

' . sprintf( __( 'Threaded commenting powered by %s code.', SPEC_COMMENT_DOM ), 'interconnect/it' ) . '

'; } else { // If you've unticked the show our credit link we'll just have it as an HTML comment instead. // Nothing to stop you removing this line too. But please don't. echo "\n\n"; } } /* Add the metaboxes to all post_types available or post and pages for WordPress 2.9 and older. */ function add_meta_boxes( ) { global $wp_version; if ( version_compare( $wp_version, '3.0', 'ge' ) ) { // WordPress 3.0 and above. foreach( ( array ) get_post_types( array( 'show_ui' => 1 ) ) as $post_type ) { if( post_type_supports( $post_type, 'comments' ) ) add_meta_box( 'spec_live_toggle', __( 'Live Discussion', SPEC_COMMENT_DOM ), array( $this, 'metabox_live_toggle' ), $post_type, 'advanced', 'default' ); } } else { // Add to post and page for older versions of WordPress. add_meta_box( 'spec_live_toggle', __( 'Live Discussion', SPEC_COMMENT_DOM ), array( $this, 'metabox_live_toggle' ), 'post', 'advanced', 'default' ); add_meta_box( 'spec_live_toggle', __( 'Live Discussion', SPEC_COMMENT_DOM ), array( $this, 'metabox_live_toggle' ), 'page', 'advanced', 'default' ); } } /* This is the metabox that'll let you toggle the default status of live commenting on a post by post basis. @param obj $post The post object as passed in by add_meta_box. */ function metabox_live_toggle( $post = '' ) { if ( ! is_object( $post ) ) return false; ?>