| 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 | | |
|---|
| 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); |
|---|
| | 262 | if ((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 | } |
|---|