Ejemplo n.º 1
0
    #error_log("Avatar: $avatar");
    #var_dump($user);
}
//Get user Language
$user_tmp = lhg_get_userdata_guid($guid);
$user = $user_tmp[0];
# Check if user has .de account -> add flag
if ($user->wpuid != 0) {
    $user_language_txt = lhg_get_locale_from_id($public_user_ID);
}
if ($user->wpuid != 0) {
    $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
}
# Check if user has .de account -> add flag
if ($user->wpuid_de != 0) {
    $user_language_flag .= " " . lhg_show_flag_by_lang("de") . " ";
}
//get user registration date
$regdate = date("d. M Y", strtotime(get_userdata($public_user_ID)->user_registered));
//get number of contributed hardware articles
$num_art = count_user_posts($public_user_ID);
//get number of comments
global $wpdb;
$where = 'WHERE comment_approved = 1 AND user_id = ' . $public_user_ID;
$num_com = $wpdb->get_var("SELECT COUNT( * ) AS total\n\t    FROM {$wpdb->comments}\n\t    {$where}");
//first steps to implement karma
//$karma = $num_com * 3 + $num_art * 50;
#if (function_exists('cp_getPoints'))
#$karma = cp_getPoints( $public_user_ID ); //$num_com * 3 + $num_art * 50;
$subscriptions = $wp_subscribe_reloaded->get_subscriptions('email', 'equals', $email, 'dt', 'DESC');
#echo 'Username: '******'<br />';
Ejemplo n.º 2
0
function lhg_donation_history($attr)
{
    global $lang;
    global $donation;
    $start = $attr['start'];
    $end = $attr['end'];
    list($endyear, $endmonth) = explode("-", $end);
    $enddate = "1-" . (intval($endmonth) + 1) . "-" . $endyear;
    $start_timestamp = strtotime($start);
    $end_timestamp = strtotime($enddate);
    #
    $total_points = 0;
    # collects all points collected in this time frame
    $donation_points = array();
    # collects all points per donation target in this time frame
    #
    # donation points by hardware scans
    #
    # donations to distribution was introduced after 09-2016
    # skip output otherwise
    if ($end_timestamp > strtotime("1-10-2016")) {
        $points_scan = lhg_points_from_hwscans($start_timestamp, $end_timestamp);
        foreach ($points_scan as $key => $points) {
            #error_log("Pts: $points -> $key");
            $total_points += $points;
            $donation_points[$key] += $points;
        }
    }
    # sort by points
    arsort($points_scan);
    $distri = lhg_get_distribution_array();
    $logo = $distri[$distri_name]["logo"];
    foreach ($points_scan as $key => $points) {
        $distri_name = lhg_get_distri_name($donation[$key]["Name"]);
        $logo = $distri[$distri_name]["logo"];
        $scan_output .= '<div class="donations-short-user-list">
                        		<div class="donations-short-user-list-avatar">' . "<img src=\"" . $logo . "\" width=45px>\n                                        </div>\n\n                                        " . '<div class="donations-short-user-list-text">
                                        	<center>' . $donation[$key]["Name"] . "<br><b>" . round($points / $total_points * 100) . "%</b> ({$points} points)\n                                        \t</center>\n                                        </div>\n\n                                </div>";
    }
    #
    # donation points collected by users
    list($list_guid, $list_points_guid) = cp_getAllQuarterlyPoints_transverse($start_timestamp, $end_timestamp);
    #print_r("LGUID:   $list_guid");
    $i = 0;
    if (sizeof($list_guid) > 0) {
        foreach ($list_guid as $guid) {
            $user_tmp = lhg_get_userdata_guid($guid);
            $user = $user_tmp[0];
            if ($user !== false) {
                #var_dump($user);
                #print sizeof($uid)."<p>";
                $user_nicename = $user->user_nicename;
                $points = $list_points_guid[$i];
                # get user's avatar
                $avatar = $user->avatar;
                # repair URL if linking to .de avatar on .com server
                if (strpos($avatar, "src='/avatars/") > 0) {
                    $avatar = str_replace("src='/avatars/", "src='http://www.linux-hardware-guide.de/avatars/", $avatar);
                }
                $wpuid_de = $user->wpuid_de;
                $wpuid_com = $user->wpuid;
                $user_language_txt = $user->language;
                $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                $total_karma = $user->karma_com + $user->karma_de;
                //$num_com * 3 + $num_art * 50;
                if ($lang == "de") {
                    $uid = $user->wpuid_de;
                }
                if ($lang == "com") {
                    $uid = $user->wpuid;
                }
                //registration date
                #$regdate = date("d. M Y", strtotime(get_userdata( $uid ) -> user_registered ) );
                //donates to
                # TODO:
                # to be updated, because we need the donation target at the end of the given time frame
                $donation_target = lhg_get_donation_target_by_date($guid, $end_timestamp);
                $total_points += $points;
                $donation_points[$donation_target] += $points;
                #$output .="User: $user_nicename -> Points: $points -> $donation_target <br>";
                ## show user info
                ##
                $user_list .= '<div class="donations-short-user-list">
                        		<div class="donations-short-user-list-avatar">';
                # TODO: localized hardware profile should be linked. Not US version
                # linked avatar to user page if on local server
                # link avatar to guser page, if user present on other servers
                if ($lang == "de") {
                    if ($user->wpuid_de != 0) {
                        $user_list .= '<a href="/hardware-profile/user' . $user->wpuid_de . '" class="recent-comments">';
                        $close0 = 1;
                        # remember that link has to be closed
                    } else {
                        $user_list .= '<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">';
                        $close0 = 1;
                    }
                }
                if ($lang != "de") {
                    if ($user->wpuid != 0) {
                        $user_list .= '<a href="/hardware-profile/user' . $user->wpuid . '" class="recent-comments">';
                        $close0 = 1;
                        # remember that link has to be closed
                    } else {
                        $user_list .= '<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">';
                        $close0 = 1;
                        # remember that link has to be closed
                    }
                }
                $user_list .= '    <div class="userlist-avatar">' . $avatar . '
			    </div> ';
                if ($close0 == 1) {
                    $user_list .= '</a></div>';
                }
                $user_list .= '<div class="donations-short-user-list-text"><center>';
                # show link to user page if on local server
                # link to guser page, if user present on other servers
                if ($lang == "de") {
                    if ($user->wpuid_de != 0) {
                        $user_list .= '		<a href="/hardware-profile/user' . $user->wpuid_de . '" class="recent-comments">';
                        $close1 = 1;
                        # remember that link has to be closed
                    } else {
                        $user_list .= '		<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">';
                        $close1 = 1;
                    }
                }
                if ($lang != "de") {
                    if ($user->wpuid != 0) {
                        $user_list .= '		<a href="/hardware-profile/user' . $user->wpuid . '" class="recent-comments">';
                        $close1 = 1;
                    } else {
                        $user_list .= '		<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">';
                        $close1 = 1;
                    }
                }
                $user_list .= "" . $user_nicename . "";
                if ($close1 == 1) {
                    $user_list .= '</a>';
                }
                $user_list .= "<br>{$points} Points\n                         to<br>" . $donation[$donation_target]["Name"] . "\n\n                        </center> </div>";
                $user_list .= "</div>";
            }
            $i++;
        }
    }
    #print "Scan results:";
    #var_dump($scans_donation_target);
    #$iendmonth= (int)$endmonth;
    $output .= "<h2>Donations from " . date("d M Y", $start_timestamp) . " to " . date("d M Y", $end_timestamp) . ":</h2>\n                        Collected Points: <b>{$total_points}</b><br>\n                        ";
    foreach ($donation_points as $key => $donation_point) {
        if ($donation_point > 0) {
            $output .= "Donations to " . $donation[$key]["Name"] . ": <b>" . round($donation_point / $total_points * 100) . "%</b> ({$donation_point} points)<br>";
        }
    }
    $output .= "<br>Users that collected and donated points:<br>\n        " . $user_list . "";
    # donations to distribution was introduced after 09-2016
    # skip output otherwise
    if ($end_timestamp > strtotime("1-10-2016")) {
        $output .= '<br clear=all>Hardware scan results:<br>' . $scan_output . "<br clear=all>";
    }
    return $output;
}
function lhg_update_karma_values($type)
{
    global $lang;
    global $lhg_price_db;
    list($list_uid, $list_points) = cp_getAllQuarterlyPoints();
    $i = 0;
    if (sizeof($list_uid) > 0) {
        foreach ($list_uid as $uid) {
            #error_log("CP UID return: $uid");
            $user = get_userdata($uid);
            if ($user !== false) {
                if ($uid != 12378) {
                    $name = $user->nickname;
                    #$user->first_name." ".$user->last_name;
                    $username = $user->user_login;
                    $points = $list_points[$i];
                    $avatar = get_avatar($uid, 40);
                    $user_language_txt = lhg_get_locale_from_id($uid);
                    $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                    $total_karma = cp_getPoints($uid);
                    //$num_com * 3 + $num_art * 50;
                    $donation_target = get_user_meta($uid, 'user_donation_target', true);
                    if ($lang != "de") {
                        $user_language = get_user_meta($uid, 'user_language', true);
                    }
                    error_log("User {$username} -> quarterly_karma: {$points}");
                    # check if user exists
                    if ($lang != "de") {
                        $sql = "SELECT id, karma_com, karma_quarterly_com, donation_target_com, user_nicename, language, username_com, emails FROM `lhgtransverse_users` WHERE emails = \"" . $user->user_email . "\" ";
                    } else {
                        $sql = "SELECT id, karma_de, karma_quarterly_de, donation_target_de, user_nicename, username_de, emails  FROM `lhgtransverse_users` WHERE emails = \"" . $user->user_email . "\" ";
                    }
                    $result = $lhg_price_db->get_results($sql);
                    #error_log( "UID: $uid");
                    #error_log("GUID: ".$result[0] ->id);
                    #var_dump($result);
                    #print "<br>";
                    if ($result[0]->id == "") {
                        # user not yet in priceDB, add
                        $guid = lhg_add_user_to_pricedb($uid);
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("karma_com", $guid, $total_karma);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("karma_quarterly_com", $guid, $points);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("donation_target_com", $guid, $donation_target);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("language", $guid, $user_language);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("username_com", $guid, $username);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("karma_de", $guid, $total_karma);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("karma_quarterly_de", $guid, $points);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("donation_target_de", $guid, $donation_target);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("username_de", $guid, $username);
                        }
                        #error_log("A: $uid - $guid - ".$result->id);
                        lhg_update_userdb_by_guid("user_nicename", $guid, $name);
                        lhg_update_userdb_by_guid("avatar", $guid, $avatar);
                    } else {
                        # user in priceDB, check if update necessary
                        if ($lang != "de" && $total_karma != $result[0]->karma_com) {
                            lhg_update_userdb_by_guid("karma_com", $result[0]->id, $total_karma);
                        }
                        if ($lang != "de" && $points != $result[0]->karma_quarterly_com) {
                            lhg_update_userdb_by_guid("karma_quarterly_com", $result[0]->id, $points);
                        }
                        if ($lang != "de" && $donation_target != $result[0]->donation_target_com) {
                            lhg_update_userdb_by_guid("donation_target_com", $result[0]->id, $donation_target);
                        }
                        if ($lang != "de" && $user_language != $result[0]->language) {
                            lhg_update_userdb_by_guid("language", $result[0]->id, $user_language);
                        }
                        if ($lang != "de" && $username != $result[0]->username_com) {
                            lhg_update_userdb_by_guid("username_com", $result[0]->id, $username);
                        }
                        if ($lang == "de" && $total_karma != $result[0]->karma_de) {
                            lhg_update_userdb_by_guid("karma_de", $result[0]->id, $total_karma);
                        }
                        if ($lang == "de" && $points != $result[0]->karma_quarterly_de) {
                            lhg_update_userdb_by_guid("karma_quarterly_de", $result[0]->id, $points);
                        }
                        if ($lang == "de" && $donation_target != $result[0]->donation_target_de) {
                            lhg_update_userdb_by_guid("donation_target_de", $result[0]->id, $donation_target);
                        }
                        if ($lang == "de" && $username != $result[0]->username_com) {
                            lhg_update_userdb_by_guid("username_de", $result[0]->id, $username);
                        }
                        if ($name != $result[0]->user_nicename) {
                            lhg_update_userdb_by_guid("user_nicename", $result[0]->id, $name);
                        }
                        if ($avatar != $result[0]->avatar) {
                            lhg_update_userdb_by_guid("avatar", $result[0]->id, $avatar);
                        }
                        if ($user->user_email != $result[0]->emails) {
                            lhg_update_userdb_by_guid("emails", $result[0]->id, $user->user_email);
                        }
                        # check if user was already set for other language
                        if ($lang == "de" && $uid != $result[0]->wpuid_de) {
                            lhg_update_userdb_by_guid("wpuid_de", $result[0]->id, $uid);
                        }
                        if ($lang != "de" && $uid != $result[0]->wpuid) {
                            lhg_update_userdb_by_guid("wpuid", $result[0]->id, $uid);
                        }
                        #error_log("NAME: $name");
                        #error_log("B Points: $points vs. ".$result[0]->karma_quarterly_com);
                    }
                }
            }
            $i++;
            // points array counter
        }
    }
}
Ejemplo n.º 4
0
    function widget($args, $instance)
    {
        global $region;
        global $top_users;
        global $donation;
        global $txt_cp_title;
        global $txt_cp_karma;
        global $txt_cp_points;
        global $txt_cp_donates_to;
        global $txt_cp_longtext;
        global $txt_cp_language;
        # How many users to show for ongoing quarter
        $max_users_to_show = 5;
        $langurl = lhg_get_lang_url_from_region($region);
        extract($args, EXTR_SKIP);
        echo $before_widget;
        //$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
        $title = '<i class="icon-trophy menucolor"></i>&nbsp;' . $txt_cp_title;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        //set default values
        if ($instance['num'] == '' || $instance['num'] == 0) {
            $instance['num'] = 1;
        }
        if ($instance['text'] == '') {
            $instance['text'] = '%user% (%points%)';
        }
        # Show table of top users of ongoing Quarter
        list($list_uid, $list_points) = cp_getAllQuarterlyPoints();
        #print "<br>Users:";
        #var_dump($list_uid);
        $i = 0;
        if (sizeof($list_uid) > 0) {
            print '<table id="quarterly-points-table">
                <tr id="quarterly-points-header-row">
                  <td class="qrtly-1" id="quarterly-points-1">Quarterly Points</td>
                  <td class="qrtly-2" id="quarterly-points-2"></td>
                  <td class="qrtly-3" id="quarterly-points-3">Username</td>
                  <td class="qrtly-4" id="quarterly-points-3">Details</td>
                  <td class="qrtly-5" id="quarterly-points-3">Total Points</td>
                </tr>
                ';
        }
        if (sizeof($list_uid) > 0) {
            foreach ($list_uid as $uid) {
                $user = get_userdata($uid);
                $name = $user->first_name . " " . $user->last_name;
                $points = $list_points[$i];
                $avatar = get_avatar($uid, 40);
                $user_language_txt = lhg_get_locale_from_id($uid);
                $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                $total_karma = cp_getPoints($uid);
                //$num_com * 3 + $num_art * 50;
                //registration date
                $regdate = date("d. M Y", strtotime(get_userdata($uid)->user_registered));
                //donates to
                $donation_target = get_user_meta($uid, 'user_donation_target', true);
                if ($donation_target == "") {
                    $donation_target = 1;
                }
                //print_r($y);
                //if ($langurl != "") $langurl = "/".$langurl;
                #print "Name: ".$user->user_nicename." ($uid) - $points<br>";
                echo '<tr>

<td class="qrtly-1" >
	    <div class="userlist-place-quarter">' . $points . ' ' . $txt_cp_points . '
    	    </div>
</td>


<td class="quartery-points-avatar qrtly-2">
<a href="./hardware-profile/user' . $uid . '" class="recent-comments">
    <div class="userlist-avatar">' . $avatar . '
    </div>
</a>
</td>


<td class="qrtly-3">
          <div class="userlist-displayname">
		<a href="./hardware-profile/user' . $uid . '" class="recent-comments">';
                echo $user->user_nicename . '
                </a>

          </div>
</td>


<td class="qrtly-4">
    <div class="quarterly-points-userlist-details">
      ' . $txt_cp_donates_to . ': ' . $donation[$donation_target]["Name"] . '<br>
      ' . $txt_cp_language . ': ' . $user_language_flag . '
    </div>
</td>

<td class="qrtly-5">
          <div class="quartly-points-totalpoints">
	      ' . $txt_cp_karma . ': ' . $total_karma . ' ' . $txt_cp_points . '<br>
          </div>
</td>

';
                print "</tr>";
                $i++;
                if ($i > $max_users_to_show - 1) {
                    break;
                }
            }
        }
        if (sizeof($list_uid) > 0) {
            print "</table>";
        }
        /*
        
        		$top = cp_getAllPoints($instance['num'],get_option('cp_topfilter'));
        		do_action('cp_topUsersWidget_before');
        		echo apply_filters('cp_topUsersWidget_before','<div class="userlist-all"><ul class="bwp-rc-ulist">');
        		$line = str_replace('%style%', $instance['style'], $line);
        		foreach($top as $x=>$y){
                                $i++;
                                $uid = $y['id'];
        			$user = get_userdata($y['id']);
                                $name = $user->first_name." ".$user->last_name;
        			$string = str_replace('%string%', '', $instance['text']);
        			$string = str_replace('%string%',$string,$line);
        			$string = apply_filters('cp_displayUserInfo',$string,$y,$x+1);
        
                                //Flag
        		        $user_language_txt = lhg_get_locale_from_id ( $uid );
                		$user_language_flag= lhg_show_flag_by_lang ( $user_language_txt );
        
                                //registration date
                                $regdate = date("d. M Y", strtotime(get_userdata( $uid ) -> user_registered ) );
        
                                //donates to
        			$donation_target = get_user_meta($uid,'user_donation_target',true);
                                if ($donation_target == "") $donation_target = 1;
        
                                $avatar = get_avatar($uid, 40);
                                //print_r($y);
                                //if ($langurl != "") $langurl = "/".$langurl;
        
        global $txt_cp_karma;
        global $txt_cp_points;
        global $txt_cp_donates_to;
        global $txt_cp_longtext;
        global $txt_cp_language;
        
                                echo '
        <a href="./hardware-profile/user'.$uid.'" class="recent-comments">
          <div class="comment-box">
        
            <div class="userlist-avatar">'.
              $avatar.'
            </div>
        
            <div class="userlist-name">
                  <div class="userlist-place">'.
                    $i.'.
                  </div>
                  <div class="userlist-displayname">';
                    //if ($name == " ") {
                    	echo $y['display_name'];
                    //}else{
                    //    echo $name;
                    //};
                    echo '
                  </div>
        
                <!-- div class="userlist-flag">'.
                  $user_language_flag.'
                </div -->
        
            </div>
        
        
            <div class="userlist-details">
              '.$txt_cp_karma.': '.$y['points'].' '.$txt_cp_points.'<br>
              '.$txt_cp_donates_to.': '.$donation[$donation_target]["Name"].'<br>
              '.$txt_cp_language.': '.$user_language_flag.'
            </div>
        
          </div>
        </a>';
        //      Registered since: '.$regdate.'<br>
        
        
        
        
                        $top_users[$i]["ID"]=$uid;
                        $top_users[$i]["Karma"]=$y['points'];
        	        $top_users[$i]["DisplayName"]=$y['display_name'];
        
                                // echo $string;
        		}
        		echo apply_filters('cp_topUsersWidget_after','</ul></div>');
        
        $topvotes = lhg_voted_donation();
        $most_voted = lhg_most_voted ($topvotes);
        $most_voted_percent = lhg_most_voted_percent ($topvotes);
        
        //$most_voted = 2;
        
                // echo "TV: $topvotes";
        */
        global $donation_total;
        /*
        Former donation code
        echo '
        
        <div class="userlist-chart">'.$txt_cp_longtext.': <b>'. $donation_total.' &euro;</b>
          '.do_shortcode('[highchart-quarterly]
        ');
        */
        echo 'Donations:<br>' . do_shortcode('[highchart_quarterly]');
        $startQrt = cp_StartOfQuarter();
        $endQrt = cp_EndOfQuarter();
        #print "Range: ".date('jS \of F Y h:i:s A',$startQrt)." to ".date('jS \of F Y h:i:s A',$endQrt);
        //   Currently, '.$most_voted_percent.'% of all users vote for "'.$donation[$most_voted]["Name"].'".
        //$topvo
        // echo '</div>';
        //end of userlist all
        do_action('cp_topUsersWidget_after');
        echo $after_widget;
    }