Configuration: Options » DoFollow. Author: Kimmo Suominen Version: 4.1 Author URI: http://kimmo.suominen.com/ */ if (is_plugin_page()): if (isset($wppDoFollow)) { $wppDoFollow->options_page(); } else { ?>

init_options(); add_filter('comment_text', array(&$this, 'nofollow_del'), 16); add_filter('get_comment_author_link', array(&$this, 'nofollow_del'), 16); remove_filter('pre_comment_content', 'wp_rel_nofollow', 15); if ($this->timeout) add_filter('pre_comment_content', array(&$this, 'nofollow_ins'), 15); add_action('admin_menu', array(&$this, 'admin_menu')); // Broken in WordPress 1.5 //add_action('options_page_dofollow', array(&$this, 'options_page')); } function admin_menu() { add_options_page( __('DoFollow Options'), __('DoFollow'), 5, basename(__FILE__)); } function init_options() { if ($this->timeout = intval(get_option('dofollow_timeout'))) { $this->ldate = time() - ($this->timeout * 86400); } else { // Make it tomorrow, so we don't have to worry about time zones $this->ldate = time() + 86400; } $this->registered = get_option('dofollow_registered'); switch ($this->registered) { case DOFOLLOW_NORMAL: case DOFOLLOW_REGONLY: case DOFOLLOW_REGOK: case DOFOLLOW_OFF: break; default: $this->registered = DOFOLLOW_NORMAL; break; } $this->excludetypes = get_option('dofollow_excludetypes'); if (is_array($this->excludetypes)) { foreach ($this->excludetypes as $type => $val) { switch ($val) { case 0: case 1: break; default: $this->excludetypes[$type] = 0; break; } } } else { $this->excludetypes = array(); } } function options_page() { global $wpdb; if (isset($_POST['Submit'])): update_option('dofollow_registered', intval($_POST['dofollow_registered'])); update_option('dofollow_timeout', intval($_POST['dofollow_timeout'])); switch (isset($_POST['dofollow_excludetypes'])) { case true: update_option('dofollow_excludetypes', $_POST['dofollow_excludetypes']); break; default: delete_option('dofollow_excludetypes'); break; } // use the new values $this->init_options(); ?>
timeout = intval(get_option('dofollow_timeout'))) { $this->ldate = time() - ($this->timeout * 86400); } $alldb = $wpdb->get_col("SELECT DISTINCT comment_type FROM {$wpdb->comments}"); foreach ($alldb as $type) { switch ($type) { case '': // regular comments break; default: $alltypes[$type] = true; break; } } $alltypes['pingback'] = true; $alltypes['trackback'] = true; ksort($alltypes); if (empty($this->excludetypes)) { $elist = ''; } else { if (count($this->excludetypes) > 1) { $elist = array_keys($this->excludetypes); $last = array_pop($elist); $elist = implode(', ', $elist) . __(' or ') . $last; } else { $elist = implode('', array_keys($this->excludetypes)); } } if ($this->timeout) { $opmode = sprintf(__('Timeout is set to %s days.'), $this->timeout); if ($this->registered == DOFOLLOW_REGONLY) { $opmode .= ' ' . sprintf(__('Nofollow will be removed from comments posted by registered users before %s.'), date('r (T)', $this->ldate)); $opmode .= ' ' . __('Nofollow will not be removed from pingbacks, trackbacks or other special comment types.'); } elseif ($this->registered == DOFOLLOW_OFF) { if (empty($elist)) { $opmode .= ' ' . sprintf(__('Nofollow will be removed from pingbacks, trackbacks and other special comment types posted before %s.'), date('r (T)', $this->ldate)); } else { $opmode .= ' ' . sprintf(__('Nofollow will be removed from comments posted before %s except from regular comments or comments of type %s.'), date('r (T)', $this->ldate), $elist); } } else { if (empty($elist)) { $opmode .= ' ' . sprintf(__('Nofollow will be removed from all comments posted before %s.'), date('r (T)', $this->ldate)); } else { $opmode .= ' ' . sprintf(__('Nofollow will be removed from comments posted before %s except from comments of type %s.'), date('r (T)', $this->ldate), $elist); } if ($this->registered == DOFOLLOW_REGOK) { $opmode .= ' ' . __('However, nofollow will be removed immediately from comments posted by registered users.'); } } } else { $opmode = __('No timeout is set.'); if ($this->registered == DOFOLLOW_REGONLY) { $opmode .= ' ' . __('Nofollow will be removed immediately from comments posted by registered users.'); $opmode .= ' ' . __('Nofollow will not be removed from pingbacks, trackbacks or other special comment types.'); } elseif ($this->registered == DOFOLLOW_OFF) { if (empty($elist)) { $opmode .= ' ' . __('Nofollow will be removed immediately from pingbacks, trackbacks and other special comment types.'); } else { $opmode .= ' ' . sprintf(__('Nofollow will be removed immediately except from regular comments or comments of type %s.'), $elist); } } else { if (empty($elist)) { $opmode .= ' ' . __('Nofollow will be removed immediately from all comments.'); } else { $opmode .= ' ' . sprintf(__('Nofollow will be removed immediately except from comments of type %s.'), $elist); } } } ?>

timeout . '" size="3" align="right" />'); ?>
registered == DOFOLLOW_NORMAL) echo ' checked'; ?> />
registered == DOFOLLOW_REGONLY) echo ' checked'; ?> />
registered == DOFOLLOW_REGOK) echo ' checked'; ?> />
registered == DOFOLLOW_OFF) echo ' checked'; ?> />
excludetypes['pingback'])) echo ' checked'; ?>" />
excludetypes['trackback'])) echo ' checked'; ?>" />
$v) { switch ($type) { case 'pingback': case 'trackback': break; default: ?> excludetypes[$type])) echo ' checked'; ?>" />

comment_date) > $this->ldate) { if ($this->registered == DOFOLLOW_REGOK) { if (empty($comment->user_id)) { return $text; } } else { return $text; } } if ($this->registered == DOFOLLOW_REGONLY) { if (empty($comment->user_id)) { return $text; } } if ($this->registered == DOFOLLOW_OFF) { if (empty($comment->comment_type)) { return $text; } } if (isset($this->excludetypes[$comment->comment_type])) { return $text; } $text = preg_replace('||i', '', $text); $text = preg_replace('||i', '', $text); $text = preg_replace('||i', '', $text); $text = preg_replace('||i', '', $text); return $text; } function nofollow_ins($text) { global $comment; if (mysql2date('U', $comment->comment_date) > $this->ldate) { if ($this->registered == DOFOLLOW_REGOK) { if (empty($comment->user_id)) { return wp_rel_nofollow($text); } } else { return wp_rel_nofollow($text); } } if ($this->registered == DOFOLLOW_REGONLY) { if (empty($comment->user_id)) { return wp_rel_nofollow($text); } } if ($this->registered == DOFOLLOW_OFF) { if (empty($comment->comment_type)) { return wp_rel_nofollow($text); } } if (isset($this->excludetypes[$comment->comment_type])) { return wp_rel_nofollow($text); } return $text; } } $wppDoFollow = new DoFollow; endif; // is_plugin_page() ?>