Changeset 1284

Show
Ignore:
Timestamp:
08/12/08 06:46:32 (4 months ago)
Author:
_ck_
Message:

0.0.3 minor update, additional data checks added based on strange bug reports

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bb-reputation/trunk/bb-reputation.php

    r1072 r1284  
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.0.2 
     8Version: 0.0.3 
    99 
    1010license: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ 
     
    1717*/ 
    1818 
    19 if (strpos($self,"bb-reputation.php")===false) : 
     19if (strpos($self,"bb-reputation.php")===false) :        
    2020 
    2121function bb_reputation_initialize() { global $bb_reputation; 
     
    5858 
    5959$bb_reputation['style']=" 
    60 .bb_reputation {margin:5px 0; line-height:1.1em; font-size:90%;  white-space: nowrap; letter-spacing:-1px;}  
     60.bb_reputation {margin:5px 0; line-height:1.1em; font-size:11px;  white-space: nowrap; letter-spacing:-1px;}  
    6161.bb_reputation a {color:green;} 
    6262.bb_reputation .bb_number {color:black; padding:0 2px;}  
     
    6767 
    6868/*       stop editing here      */ 
     69 
     70$bb_reputation['points_per_post']=intval($bb_reputation['points_per_post']);    // correct config errors 
     71$bb_reputation['points_per_topic']=intval($bb_reputation['points_per_topic']);  // correct config errors 
    6972 
    7073bb_reputation_process_request(); 
     
    8790$user = bb_get_user( $user_id );  
    8891$reputation=intval($user->bb_reputation);                
    89 if (!isset($user->bb_reputation) && $user_id && ($bb_reputation['points_per_post'] || $bb_reputation['points_per_topic'])) { 
     92if ($user_id && !isset($user->bb_reputation) && ($bb_reputation['points_per_post'] || $bb_reputation['points_per_topic'])) { 
    9093        global $bbdb;  
    9194        $topics = $bb_reputation['points_per_topic']*intval($bbdb->get_var("SELECT count(*) FROM $bbdb->topics WHERE topic_poster = $user_id  AND topic_status = 0")); 
    9295        $posts = $bb_reputation['points_per_post']*intval($bbdb->get_var("SELECT count(*) FROM $bbdb->posts WHERE poster_id = $user_id AND post_position != 1 AND post_status = 0"));            
    9396        $reputation = $topics + $posts; 
    94         bb_update_meta( $user_id, "bb_reputation", $reputation, 'user' ); 
     97        bb_update_meta( $user_id, 'bb_reputation', $reputation, 'user' ); 
    9598} 
    9699$link=''; if ($bb_reputation['members_can_award'] && bb_current_user_can($bb_reputation['member_award_role']) && $user_id != bb_get_current_user_info( 'id' )) {$link='<a class="bb_reputation_link" title="'.$bb_reputation['action'].'" href="#post-'.$post_id.'" onClick="bb_reputation('.$post_id.');return false;">+</a>';} 
     
    121124        $deduct=intval($from->bb_reputation)-$points; 
    122125        if ($deduct<0) {return false;}  // can't deduct so don't give points 
    123         bb_update_meta( $from_id, "bb_reputation", $deduct, 'user' ); 
    124 } 
    125 if ($points>0 || bb_current_user_can($bb_reputation['deduct_role'])) { 
    126         $add=intval($user->bb_reputation)+$points;               
    127         bb_update_meta( $user_id, "bb_reputation", $add, 'user' ); 
    128         $history=$user->bb_reputation_history.time()."|$from_id|$post_id|$points|$reason|"
    129         bb_update_meta( $user_id, "bb_reputation_history", $history, 'user' ); 
     126        bb_update_meta( $from_id, 'bb_reputation', $deduct, 'user' ); 
     127} 
     128if ($points>0 || ($points && bb_current_user_can($bb_reputation['deduct_role']))) { 
     129        $add=intval($user->bb_reputation)+$points;                      
     130        bb_update_meta( $user_id, 'bb_reputation', $add, 'user' ); 
     131        $history=(string) $user->bb_reputation_history.(time()."|$from_id|$post_id|$points|$reason|")
     132        bb_update_meta( $user_id, 'bb_reputation_history', $history, 'user' ); 
    130133} 
    131134return $points; 
     
    141144        if ($post->post_position==1) {$points=$bb_reputation['points_per_topic'];} 
    142145        elseif ($post->post_position>1) {$points=$bb_reputation['points_per_post'];}     
    143         bb_update_meta( $user_id, "bb_reputation", $reputation+$points, 'user' ); 
     146        bb_update_meta( $user_id, 'bb_reputation', $reputation+$points, 'user' ); 
    144147}  
    145148} 
     
    174177 
    175178function bb_reputation_process_request() {  
    176         if (isset($_POST['bb_reputation_id']) && isset($_POST['bb_reputation_reason'])) {  
     179        if (isset($_POST) && isset($_POST['bb_reputation_id']) && isset($_POST['bb_reputation_reason'])) {  
    177180                $points=(isset($_POST['bb_reputation_points'])) ? $_POST['bb_reputation_points'] : 0; 
    178181                 bb_reputation_add_points($_POST['bb_reputation_id'],$points,$_POST['bb_reputation_reason']);                            
    179182                // header("HTTP/1.1 307 Temporary redirect"); 
    180                 wp_redirect($GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]);     // I *really* don't like this technique but it's the only way to clear post data? 
     183                wp_redirect($_SERVER["REQUEST_URI"]); // I *really* don't like this technique but it's the only way to clear post data? 
    181184                // exit();  // not sure why but this makes it fail? 
    182185        }        
    183         /* 
    184         if (isset($_GET['delete_poll']) && intval($_GET['delete_poll'])) {       
    185                 bb_polls_delete_poll(); 
    186                 wp_redirect(remove_query_arg(array('start_new_poll','delete_poll')));   // I *really* don't like this technique but it's the only way to clear post data? 
    187         }                                
    188         if (isset($_GET['show_poll_results_ajax'])) { 
    189                 $topic_id=intval($_GET['show_poll_results_ajax']); 
    190                 header("Content-Type: application/x-javascript"); 
    191                 echo 'bb_polls_insert_ajax("'.mysql_escape_string(bb_polls_show_poll_results($topic_id,0)).'")'; 
    192                 exit(); 
    193         } 
    194         */       
    195186}  
    196187 
     
    198189global $bb_reputation;   
    199190$fix=""; if ($bb_reputation['fix_kakumei']) {$fix=".threadauthor  {position:relative; float:left; margin:0 -110px 0 0; right:110px; } .poststuff {clear:both;}";} 
    200 echo '<style type="text/css">'.$bb_reputation['style'].$fix.'</style>'; 
     191if (!empty($bb_reputation['style']) || !empty($fix)) {echo '<style type="text/css">'.$bb_reputation['style'].$fix.'</style>';} 
    201192}  
    202193 
    203194function bb_reputation_profile_key($keys) {     // inserts reputation into profile without hacking 
    204 global $bb_reputation;  
    205 if (!isset($_GET['tab']) && bb_get_location()=="profile-page") { 
    206         $keys=array_merge(array_slice($keys, 0 , 1), array('bb_reputation' => array(0, $bb_reputation['label'])), array_slice($keys,  1)); 
    207 } 
    208 return $keys; 
     195global $bb_reputation, $self; 
     196if (empty($self)==true && isset($_GET['tab'])==false && bb_get_location()=="profile-page") {    
     197        (array) $keys=array_merge(array_slice((array) $keys, 0 , 1), array('bb_reputation' => array(0, $bb_reputation['label'])), array_slice((array) $keys,  1));     
     198} 
     199return (array) $keys; 
    209200 } 
    210201 
     
    221212} 
    222213 
    223 elseif ($bb_reputation['history_profile'])  : 
     214elseif ($bb_reputation['history_profile'])  :          // we're in the profile tab, is it enabled? 
    224215 
    225216bb_get_header(); 
     
    227218<h3 class="bbcrumb"><a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; <a href="<?php echo get_user_profile_link($user->ID ).'">'.__("Profile"); ?></a> &raquo; <?php echo $bb_reputation['label']; ?></h3> 
    228219 
    229 <?php if (($bb_reputation['history_public']) || bb_current_user_can('edit_user', $user->ID)) { // security check ?> 
     220<?php if (($bb_reputation['history_public']) || bb_current_user_can('edit_user', $user->ID)) {  ?> 
    230221<div class="indent"> 
    231222<?php 
     
    239230<h4><?php echo $bb_reputation['label_history']; ?> <small>(<?php printf(__('%s total ').$bb_reputation['unit'], bb_number_format_i18n($user->bb_reputation)); ?>)</small></h4> 
    240231 
    241 <?php $matches=explode("|",$user->bb_reputation_history); if ($matches && is_array($matches)) : ?> 
     232<?php $matches=explode("|",(string) $user->bb_reputation_history); if ($matches && is_array($matches)) : ?> 
    242233<ol> 
    243234<?php $rows=floor(count($matches)/5);           // 5 items per row 
     
    270261} // security check 
    271262bb_get_footer(); 
    272 endif; 
     263endif; // profile tab check 
    273264?>