1, 'load_css' => 1, 'load_js' => 1, 'load_dark' => 0, 'credit' => 1); /* PHP4 constructor. Adds the css, js, config menu and the template hijack filters/actions to Wordpress. It also checks that we've not been here already and assigns some variables to the class. @return null; */ function spec_commenting () { // This class was included with some spectacu.la themes // this will stop it running twice and causing confusion. if (defined('SPEC_COMMENT_DON')) return false; else define('SPEC_COMMENT_DON', true); // Load the translation stuff $abs_rel_path = trim(trim(str_replace(trim(ABSPATH, '/'), '', dirname(__FILE__)), '/'), '\\') . '/lang/'; load_plugin_textdomain(SPEC_COMMENT_DOM, $abs_rel_path); // Merge the defalts with those chosen. $this->options = array_merge($this->default_options, (array)get_option(SPEC_COMMENT_OPT)); // Add the actions and filters. if ($this->options['load_css']) { add_filter('body_class', array(&$this, 'get_agent_body_class')); add_action('wp_head', array(&$this, 'css')); if ($this->options['load_dark']) { add_filter('spec_comment_css', array(&$this, 'dark_css')); } } if ($this->options['load_js']) { add_action('wp', array(&$this, 'before_headers')); } add_action('comment_form', array(&$this, 'our_credit')); add_action('admin_menu', array(&$this, 'add_options_page')); add_filter('comments_template', array(&$this, 'comment_template_hijack')); } /* 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(){ wp_deregister_script( 'comment-reply' ); // dealt with by the included jQuery if(function_exists('wp_list_comments') && is_singular()) { $localisation = array( 'trackbackShowText' => __('Show trackbacks', SPEC_COMMENT_DOM), 'trackbackHideText' => __('Hide trackbacks', SPEC_COMMENT_DOM), 'replyHideMany' => __('Hide %count% replies to %name% comment', SPEC_COMMENT_DOM), 'replyShowMany' => __('View %count% replies to %name% comment', SPEC_COMMENT_DOM), 'replyHideOne' => __('Hide the reply to %name% comment', SPEC_COMMENT_DOM), 'replyShowOne' => __('View the reply to %name% comment', SPEC_COMMENT_DOM), ); $localisation = array_merge((array)apply_filters('spec_comment_local_js', $localisation), array('nestDepth' => $this->options['comments_nest_depth'])); wp_enqueue_script('commenting', apply_filters('spec_comment_js', SPEC_COMMENT_URL . '/js/commenting.min.js'), array('jquery'), '1.0.3', true ); wp_localize_script('commenting', 'commentingL10n', $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 themes 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; } /* 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()) { ?>= 9 ) { $class[] = 'ie'; $class[] = 'ienew'; } 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('ieold', $class) && $version < 5) { $class[] = 'ie'; $class[] = 'ieold'; } else { // Unknown IE. $class[] = 'ie'; $class[] = 'iexx'; } } return $class; } /* Add the option page to wordpress' theme menu and register the settings @return null; */ function add_options_page() { register_setting(SPEC_COMMENT_OPT, SPEC_COMMENT_OPT, array(&$this, 'validate_option')); add_theme_page(__('Comments', SPEC_COMMENT_DOM), __('Comments', SPEC_COMMENT_DOM), 'manage_options', SPEC_COMMENT_DOM, array(&$this, 'options_page')); } /* The the processed return from the form page is checked here before returning the cleaned up version to WP for saving to our options var. @return array The parameters to save to our options. */ function validate_option($options) { $outgoing['comments_nest_depth'] = intval($options['comments_nest_depth']) > 0 || intval($options['comments_nest_depth']) < 11 ? intval($options['comments_nest_depth']) : 1; $outgoing['load_dark'] = $options['load_dark'] == 1 ? 1 : 0; $outgoing['load_js'] = $options['load_js'] == 1 ? 1 : 0; $outgoing['load_css'] = $options['load_css'] == 1 ? 1 : 0; $outgoing['credit'] = $options['credit'] == 1 ? 1 : 0; return $outgoing; } /* The options page. @return null; */ function options_page() {?>

options; ?>

/>

/>


/>
Disabling javaScript will cause problems for ie6 as jQuery is used to add classes to items that would otherwise be inaccessible to the CSS.


/>
:(
Spectacu.la

options['credit']) { echo '

Threaded commenting powered by Spectacu.la code.

'; } 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"; } } } /* Check that Wordpress is of sufficient newness to run this. */ if (version_compare($wp_version, SPEC_COMMENT_VER, 'ge')) add_action('init', create_function('', 'return new spec_commenting();'), 5); }?>