* @copyright 2007 Sam Bauers * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v2 * @version 1.0 **/ /** * Container class for Post count titles * * @author Sam Bauers * @version 1.0 **/ class Post_Count_Titles { /** * The current version of the plugin * * @var string **/ public $version = '1.0'; /** * Whether the plugin is enabled * * @var boolean **/ private $enabled; /** * Whether the plugin has enough settings to work * * @var boolean **/ private $active = false; /** * The post count titles in an array * * @var array **/ private $titles; /** * The post count titles in an array, but reversed * * @var array **/ private $titlesReverse; /** * The format of the post count string * * @var string **/ private $format; /** * A cache of users titles * * @var array **/ private $cache = array(); /** * Pulls out database settings * * @return void * @author Sam Bauers **/ public function __construct() { // An integer set to 1 for enabled or 0 for disabled $this->enabled = bb_get_option('post_count_titles_enabled'); $this->titles = bb_get_option('post_count_titles_titles'); $this->titlesReverse = array_reverse($this->titles, true); if ($this->titles) { $this->active = true; } $this->format = bb_get_option('post_count_titles_format'); if (!$this->format) { $this->format = '%ROLE-LINK%
%TITLE%
%POSTS% posts'; } } /** * Returns whether the plugin is active or not * * @return boolean * @author Sam Bauers **/ public function isActive() { if ($this->enabled && $this->active) { return true; } else { return false; } } /** * Adds a string representing the users post count to the given string * * @return string * @author Sam Bauers **/ public function addPostTitleToUserTitle($input) { global $bb_post; global $bbdb; global $bb_table_prefix; // Get the user object $user = bb_get_user(get_post_author_id()); // Return the cached version to speed things up a bit on repeats if (isset($this->cache[$user->ID])) { return $this->cache[$user->ID]; } // Get the live current posts $currentPosts = $bbdb->get_var("SELECT COUNT(post_id) FROM `" . $bbdb->posts . "` WHERE `post_status` = '0' AND `poster_id` = '" . $user->ID . "';"); // Work out the title for this user foreach ($this->titlesReverse as $posts => $title) { if ($currentPosts > $posts) { $currentTitle = $title; break; } } // Get the profile link from the input if (preg_match('@^(]+>)([^<]+)@', $input, $matches)) { $profileLink = $matches[1]; $role = $matches[2]; } else { $role = $input; } // Transform the output based on the format $output = str_replace( array( '%ROLE%', '%ROLE-LINK%', '%TITLE%', '%TITLE-LINK%', '%POSTS%' ), array( $role, $input, $currentTitle, $profileLink . $currentTitle . '', $currentPosts ), $this->format ); // Cache the result $this->cache[$user->ID] = $output; return $output; } } // END class Post_Count_Titles // Initialise the class $post_count_titles = new Post_Count_Titles(); // If active, then add filters via API if ($post_count_titles->isActive()) { add_filter('post_author_title', array($post_count_titles, 'addPostTitleToUserTitle')); } /** * The admin pages below are handled outside of the class due to constraints * in the architecture of the admin menu generation routine in bbPress */ // Add filters for the admin area add_action('bb_admin_menu_generator', 'post_count_titles_admin_page_add'); add_action('bb_admin-header.php','post_count_titles_admin_page_process'); /** * Adds in an item to the $bb_admin_submenu array * * @return void * @author Sam Bauers **/ function post_count_titles_admin_page_add() { if (function_exists('bb_admin_add_submenu')) { // Build 794+ bb_admin_add_submenu(__('Post count titles'), 'use_keys', 'post_count_titles_admin_page'); } else { global $bb_submenu; $submenu = array(__('Post count titles'), 'use_keys', 'post_count_titles_admin_page'); if (isset($bb_submenu['plugins.php'])) { // Build 740-793 $bb_submenu['plugins.php'][] = $submenu; } else { // Build 277-739 $bb_submenu['site.php'][] = $submenu; } } } /** * Writes an admin page for the plugin * * @return string * @author Sam Bauers **/ function post_count_titles_admin_page() { $enabled = bb_get_option('post_count_titles_enabled'); $titles = bb_get_option('post_count_titles_titles'); $format = bb_get_option('post_count_titles_format'); if ($enabled) { $enabled_checked = ' checked="checked"'; } if (!$titles) { $titles = array( '0' => 'French Fry', '10' => 'Junior Burger', '100' => 'Quarter Pounder', '1000' => 'Big Mac' ); } $title_form = array(); foreach ($titles as $posts => $title) { $title_form[] = array( 'posts' => $posts, 'title' => $title ); } if (!$format) { $format = '%ROLE-LINK%
%TITLE%
%POSTS% posts'; } ?>

Post count titles

Enable

/> Enable post count titles
 

Titles

"Posts" refers to the number of posts the user must have made to achieve the given "Title"

Posts Title

Format

The format of the string used in place of the normal users role on posts.