Changeset 1317

Show
Ignore:
Timestamp:
08/31/08 16:12:13 (3 months ago)
Author:
_ck_
Message:

1.1.6 bbPress 1.0 compatibility, externalize admin functions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • post-count-plus/trunk/post-count-plus.php

    r1218 r1317  
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 1.1.5 
     8Version: 1.1.6 
    99 
    1010License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ 
     
    168168function post_count_plus_profile_key($keys) {   // inserts post_count into profile without hacking 
    169169global $post_count_plus, $self;  
    170 if (!$self && !isset($_GET['tab']) && bb_get_location()=="profile-page") { 
    171         $keys=array_merge(array_slice($keys, 0 , 1), array('post_count' => array(0, __('Posts'))), array_slice($keys,  1)); 
    172 } 
    173 return $keys; 
    174 
     170if (empty($self)==true && isset($_GET['tab'])==false && bb_get_location()=="profile-page") { 
     171        (array) $keys=array_merge(array_slice((array) $keys, 0 , 1), array('post_count' => array(0, __('Posts'))), array_slice((array) $keys,  1));     
     172} 
     173return (array) $keys; 
     174
    175175 
    176176function post_count_plus_add_css() { global $post_count_plus;  echo '<style type="text/css">'.$post_count_plus['style'].'</style>';} // inject css 
     
    237237        // } 
    238238        if ($post_count_plus['profile_insert']) {add_filter( 'get_profile_info_keys','post_count_plus_profile_key',200);} 
    239         if ($post_count_plus['activate']) {add_filter( 'post_author_title', 'post_count_plus_filter');
     239        if ($post_count_plus['activate']) {add_filter( 'post_author_title', 'post_count_plus_filter'); add_filter( 'post_author_title_link', 'post_count_plus_filter');
    240240        if ($post_count_plus['style']) {add_action('bb_head', 'post_count_plus_add_css');}       
    241241        if ($post_count_plus['user_color']) { 
     
    260260} 
    261261 
    262 function post_count_plus_add_admin_page() {bb_admin_add_submenu(__('Post Count Plus'), 'administrate', 'post_count_plus_admin_page');} 
    263 add_action( 'bb_admin_menu_generator', 'post_count_plus_add_admin_page' ); 
    264  
    265 function post_count_plus_admin_page() { 
    266         global $post_count_plus, $post_count_plus_type, $post_count_plus_label;                  
    267         ?> 
    268                 <div style="text-align:right;margin-bottom:-1.5em;"> 
    269                         [ <a title="recommended occasionally to speed up page loads or re-sync counts" href="<?php echo add_query_arg('post_count_plus_recount','1',remove_query_arg('post_count_plus_reset')); ?>">Rebuild Post Count For All Users</a> ] 
    270                         &nbsp;&nbsp;&nbsp;&nbsp; 
    271                         [ <a href="<?php echo add_query_arg('post_count_plus_reset','1',remove_query_arg('post_count_plus_recount')); ?>">Reset All Settings To Defaults</a> ]                   
    272                 </div> 
    273                  
    274                 <h2>Post Count Plus</h2> 
    275                  
    276                 <form method="post" name="post_count_plus_form" id="post_count_plus_form" action="<?php echo remove_query_arg(array('post_count_plus_reset','post_count_plus_recount')); ?>"> 
    277                 <input type=hidden name="post_count_plus" value="1"> 
    278                         <table class="widefat"> 
    279                                 <thead> 
    280                                         <tr> <th width="33%">Option</th>        <th>Setting</th> </tr> 
    281                                 </thead> 
    282                                 <tbody> 
    283                                         <?php 
    284                                          
    285                                         $post_count_plus['custom_titles'][0]=__("New Title");     
    286                                         $post_count_plus['custom_titles'][1]=__("Minimum Posts"); 
    287                                         $post_count_plus['custom_titles'][2]=__("Minimum Days"); 
    288                                         $post_count_plus['custom_titles'][3]=__("Minimum Role"); 
    289                                         $post_count_plus['custom_titles'][4]=__("Color"); 
    290                                          
    291                                         foreach(array_keys( $post_count_plus_type) as $key) { 
    292                                         $post_count_plus[$key]=stripslashes_deep($post_count_plus[$key]);                                        
    293                                         $colspan= (substr($post_count_plus_type[$key],0,strpos($post_count_plus_type[$key].",",","))=="array") ? "2" : "1"; 
    294                                                 ?> 
    295                                                 <tr> 
    296                                                         <td nowrap colspan=<?php echo $colspan; ?>> 
    297                                                         <label for="post_count_plus_<?php echo $key; ?>"> 
    298                                                         <b><?php  if ($post_count_plus_label[$key])  {echo $post_count_plus_label[$key];} else {echo ucwords(str_replace("_"," ",$key));} ?></b> 
    299                                                         </label> 
    300                                                         <?php 
    301                                                         if ($colspan<2) {echo "</td><td>";} else {echo "<br />";} 
    302                                                         switch (substr($post_count_plus_type[$key],0,strpos($post_count_plus_type[$key].",",","))) : 
    303                                                         case 'binary' : 
    304                                                                 ?><input type=radio name="<?php echo $key;  ?>" value="1" <?php echo ($post_count_plus[$key]==true ? 'checked="checked"' : ''); ?> >Yes 
    305                                                                      <input type=radio name="<?php echo $key;  ?>" value="0" <?php echo ($post_count_plus[$key]==false ? 'checked="checked"' : ''); ?> >No <?php 
    306                                                         break; 
    307                                                         case 'numeric' : 
    308                                                                 ?><input type=text maxlength=3 name="<?php echo $key;  ?>" value="<?php echo $post_count_plus[$key]; ?>"> <?php  
    309                                                         break; 
    310                                                         case 'textarea' :                                                                
    311                                                                 ?><textarea style="width:98%" name="<?php echo $key;  ?>"><?php echo $post_count_plus[$key]; ?></textarea><?php                                                          
    312                                                         break; 
    313                                                         case 'array' : 
    314                                                                 $elements=explode(",",$post_count_plus_type[$key]); 
    315                                                                 echo "<table border=0 align='center' width='80%'>"; 
    316                                                                 for ($row=0; $row<$elements[2]; $row++) { echo "<tr>"; 
    317                                                                 for ($column=0; $column<$elements[1]; $column++) { 
    318                                                                 if ($row==0) {echo "<th width='".intval(100/$elements[1])."%'>".$post_count_plus[$key][$column]."</th>";} 
    319                                                                 else { 
    320                                                                 $position=($row*$elements[1])+$column;  
    321                                                                 echo "<td width='".intval(100/$elements[1])."%'>"; 
    322                                                                 ?><input type=text style="width:99%" name="<?php echo $key."[$position]";  ?>" value="<?php echo $post_count_plus[$key][$position]; ?>"> 
    323                                                                 <?php  echo "</td>";    }                                                                        
    324                                                                         } echo "</tr>"; 
    325                                                                 } echo "</table>";                                                               
    326                                                         break; 
    327                                                         default :  // type "input" and everything else we forgot 
    328                                                                 $values=explode(",",$post_count_plus_type[$key]); 
    329                                                                 if (count($values)>2) { 
    330                                                                 echo '<select name="'.$key.'">'; 
    331                                                                 foreach ($values as $value) {echo '<option '; echo ($post_count_plus[$key]== $value ? 'selected' : ''); echo '>'.$value.'</option>'; } 
    332                                                                 echo '</select>'; 
    333                                                                 } else {                                                                                                                 
    334                                                                 ?><input type=text style="width:98%" name="<?php echo $key;  ?>" value="<?php echo $post_count_plus[$key]; ?>"> <?php  
    335                                                                 } 
    336                                                         endswitch;                                                       
    337                                                         ?> 
    338                                                         </td> 
    339                                                 </tr> 
    340                                                 <?php 
    341                                         } 
    342                                         ?> 
    343                                 </tbody> 
    344                         </table> 
    345                         <p class="submit"><input type="submit" name="submit" value="Save Post Count Plus Settings"></p> 
    346                  
    347                 </form> 
    348                 <?php 
    349 
    350  
    351 function post_count_plus_process_post() { 
    352 global $post_count_plus; 
    353         if (bb_current_user_can('administrate')) { 
    354                 if (isset($_REQUEST['post_count_plus_reset'])) { 
    355                         unset($post_count_plus);                 
    356                         bb_delete_option('post_count_plus'); 
    357                         post_count_plus_initialize();                    
    358                         bb_update_option('post_count_plus',$post_count_plus); 
    359                         bb_admin_notice('<b>Post Count Plus: '.__('All Settings Reset To Defaults.').'</b>');   // , 'error'                     
    360                         wp_redirect(remove_query_arg(array('post_count_plus_reset','post_count_plus_recount')));        // bug workaround, page doesn't show reset settings 
    361                 } 
    362                 elseif (isset($_REQUEST['post_count_plus_recount'])) {post_count_plus_recount();} 
    363                 elseif (isset($_POST['submit']) && isset($_POST['post_count_plus'])) { 
    364                                                          
    365                         foreach(array_keys( $post_count_plus) as $key) { 
    366                                 if (isset($_POST[$key])) {$post_count_plus[$key]=$_POST[$key];} 
    367                         } 
    368                         $found=0; $width=5; $rows=floor(count($post_count_plus['custom_titles'])/$width); 
    369                         for ($i=1; $i<$rows; $i++) {    // filter typed in settings here for correctness         
    370                         if ($post_count_plus['custom_titles'][$i*$width+3]) { // strip down roles to lowercase no spaces - could actually try to match real role names? 
    371                                 $post_count_plus['custom_titles'][$i*$width+3]=str_replace(" ","",strtolower($post_count_plus['custom_titles'][$i*$width+3])); 
    372                         }}  
    373                         bb_update_option('post_count_plus',$post_count_plus); 
    374                         bb_admin_notice('<b>Post Count Plus: '.__('All Settings Saved.').'</b>'); 
    375                         // unset($GLOBALS['post_count_plus']); $post_count_plus = bb_get_option('post_count_plus'); 
    376                 } 
    377         } 
    378 
    379 add_action( 'bb_admin-header.php','post_count_plus_process_post'); 
    380  
    381 function post_count_plus_recount() {    // count function to re-sync all user post counts and keep extra queries low 
    382          global $bbdb;   
    383         // echo "<html><body><h1>Post Count Plus</h1><h2>counting posts for all users...</h2><pre>"; 
    384         $status1=$bbdb->query("DELETE FROM $bbdb->usermeta  WHERE meta_key = 'post_count'"); 
    385         $status2=$bbdb->query("INSERT INTO  $bbdb->usermeta  (user_id, meta_key, meta_value) ". 
    386         "SELECT poster_id as user_id,'post_count',count(*) as meta_value FROM $bbdb->posts WHERE post_status = 0 GROUP BY poster_id"); 
    387         // echo "<h3>".mysql_affected_rows(). " users counted and inserted.</h3></pre>"; 
    388         // echo "<b><a href='".remove_query_arg('post_count_plus_recount')."'>return to forum</a></b>"; 
    389         // echo "<scr"."ipt>setTimeout(".'"'."window.location='".remove_query_arg('post_count_plus_recount')."'".'"'.",3000);</scr"."ipt>"; exit();      
    390         bb_admin_notice('<b>Post Count Plus: '.__('All users and posts recounted.').' '.mysql_affected_rows().' '.__('users counted and inserted.').'</b> ('.__('status: ').$status1.':'.$status2.')');         // , 'error'  
    391 }  
    392  
    393 function post_count_plus_recount_list(){ 
    394 global $recount_list; 
    395 $recount_list[123] = array('post_count_plus_recount', __('Rebuild Post Count For All Users')); 
    396 }        
    397 add_action('bb_recount_list','post_count_plus_recount_list',200); 
     262if ((defined('BB_IS_ADMIN') && BB_IS_ADMIN) || !(strpos($_SERVER['REQUEST_URI'],"/bb-admin/")===false)) { // "stub" only load functions if in admin  
     263        function post_count_plus_add_admin_page() {bb_admin_add_submenu(__('Post Count Plus'), 'administrate', 'post_count_plus_admin');} 
     264        add_action( 'bb_admin_menu_generator', 'post_count_plus_add_admin_page' );       
     265        if (isset($_GET['plugin']) && $_GET['plugin']=="post_count_plus_admin") {require_once("post-count-plus-admin.php");} // load entire core only when needed 
     266
    398267?> 
  • post-count-plus/trunk/readme.txt

    r1016 r1317  
    33Contributors: _ck_ 
    44Requires at least: 0.8.2 
    5 Tested up to: trunk alpha 1075 
     5Tested up to: 0.9.0.2 
    66Stable tag: trunk 
    77Donate link: http://amazon.com/paypage/P2FBORKDEFQIVM 
     
    2222* A demo can be seen at any topic on http://bbShowcase.org/forums/ 
    2323good example: http://bbshowcase.org/forums/topic/new-bbpress-theme-futurekind 
     24 
     25= Why does the user's info repeat twice in their posts? = 
     26 
     27* This is a bug in an early version of bbPress 1.0 alpha. Please upgrade your bbPress to the newest 1.0 
    2428 
    2529== Installation == 
     
    6569* don't activate if inside a feed  
    6670 
     71= Version 1.1.6 (2008-08-31) = 
     72 
     73* admin function externalized to reduce code size for most users 
     74* bug fix for automatic post count inserted into profile 
     75* now compatible with 1.0 
     76 
    6777== To Do == 
    6878