Function check_badges($color, $uid, $limit = 300, $_DEBUG = true)


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Function check_badges($color, $uid, $limit = 300, $_DEBUG = true)

Here is the first draft PHP function to check badges:


Code:
<?php
function check_badges($color, $uid, $limit = 300, $_DEBUG = true)
{
    /*
     * check_badges()   version 0.1 by Neo  9 Jan 2019
     * $_COOKIE['badgeshash'] is not used in this server-side code
     * but may be used in the browser.  Mostly for debugging.
     * $color is an array of badge colors
     */
    global $vbulletin;
    $now = time();
    $st = 0;
    $output = null;
    if (isset($_COOKIE['badgeshashtime'])) {
        $diff = $now - $_COOKIE['badgeshashtime'];
    } else {
        setcookie("badgeshashtime", $now);
        $diff = $now;
    }
    if ($diff > $limit) {
        $st = 1;
        $badges_serialized = json_encode($color);
        $hash = hash('ripemd160', $badges_serialized);
        $getbadges = "SELECT badges AS badges FROM user where userid =" . $uid;
        $userbadges = $vbulletin->db->query_first($getbadges);
        $badgesDB = json_decode($userbadges['badges'], true);
        $badgeDiff = array_diff_assoc($badgesDB, $color);
        $output = get_diff_string($badgeDiff);
        $countDiff = sizeof($badgeDiff);
        if ($_DEBUG) {
            $diffB = print_r($badgeDiff, true);
            $badgeDiffR = array_diff_assoc($color, $bDiff);
            $diffBR = print_r($badgeDiffR, true);
        }
        if (isset($_COOKIE['badgeshash'])) {
            $cookiehash = $_COOKIE['badgeshash'];
        } else {
            setcookie("badgeshash", $hash);
            setcookie("badgeshashtime", $now);
        }
        $gethash = "SELECT badgeshash AS hash FROM user where userid =" . $uid;
        $userhash = $vbulletin->db->query_first($gethash);
        if ($hash != $userhash['hash']) {
            if ($countDiff > 0 and $_DEBUG) {
                error_log(date(DATE_RFC822) . " User " .
                    $modaluser['username'] . ' Hash ' . $hash .
                    ' Cookie ' . $cookiehash . ' St: 1  Diff(' . $countDiff . ') ' .
                    $diffB . ' Diff String: ' . $output .
                    "\n", 3, '/var/log/apache2/debug/neo_global_uim_hash_diff.log');
            }
            $updatehash = "UPDATE user SET badgeshash ='" . $hash . "' WHERE userid =" . $uid;
            $status = $vbulletin->db->query_write($updatehash);
            $updatebadges = "UPDATE user SET badges ='" . $badges_serialized . "' WHERE userid =" . $uid;
            $status = $vbulletin->db->query_write($updatebadges);
            setcookie("badgestatechange", $st);
            setcookie("badgeshash", $hash);
            setcookie("badgeshashtime", $now);
        }
        if ($_DEBUG) {
            error_log(date(DATE_RFC822) . " GLOBAL Badges for: " .
                $modaluser['username'] . ' Hash ' . $hash . ' Cookie ' .
                $cookiehash . ' State ' . $st .
                "\n", 3, '/var/log/apache2/debug/neo_global_uim_hash.log');
        }
    }
    return $output;
}

function get_diff_string($badgesDiffArray)
{
    $string = '';
    $size = sizeof($badgesDiffArray);
    $i = 0;
    $badges_desc = array(
        "fauser" => "Post Count",
        "faaward" => "First Post",
        "fajediorder" => "100 Posts",
        "faphoenix" => "500 Posts",
        "fajedi" => "1,000 Posts",
        "faatom" => "10,000 Posts",
        "fascale" => "Moderator",
        "facrab" => "Order of the Crab",
        "fawizard" => "Order of the Wizards's Hat",
        "facrow" => "Order of the Raven",
        "fahippo" => "Order of the Hippo",
        "faspider" => "Order of the Spider",
        "fadragon" => "Order of the Dragon",
        "facrow" => "Order of the Raven",
        "fabuilding" => "Administrator",
        "fabishop" => "Forum Advisor",
        "facity" => "Web Dev Ops",
        "faflask" => "Formulator",
        "fathumbsup" => "Thanks Received",
        "fatrophy" => "100 Thanks Received",
        "fachalkboardteacher" => "1,000 Thanks Received",
        "fashieldalt" => "2,000 Thanks Received",
        "fastroopwafel" => "3,000 Thanks Received",
        "fafirstorderalt" => "4,000 Thanks Received",
        "faidbadge" => "Member Profile",
        "faaddressbook" => "Contact Methods",
        "fabtc" => "Bits",
        "fauniversity" => "Bits Banker",
        "fausergraduate" => "Activity",
        "farocket" => "Thanks This Past Month",
        "facomment" => "Post This Past Month",
        "faterminal" => "Discussions Started This Past Month",
        "fabolt" => "Posts Per Day",
        "faknight" => "Discussions Started",
        "fadownload" => "Attachments Uploaded",
        "fatags" => "Tags Added",
        "faeye" => "Discussion Started Max Views",
        "fainfraction" => "Infraction Points",
        "fathanks_given" => "Thanks Given",
        "fapatreon" => "Patreon Sponsor",
        "fajoin_time" => "Time A Member",
        "fahistory" => "Weeks Active In A Row",
    );
    foreach ($badgesDiffArray as $key => $color) {
        if ($i++ < $size -1) {
            $string .= $badges_desc[$key] . ', ';
        } else {
            $string .= $badges_desc[$key];
        }
    }
    return $string;
}

These 2 Users Gave Thanks to Neo For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Internal software error in the tostring function for files greater than 300 MB
script_op2a
Hello, When I run my awk script with input files greater than 300 MB I always get this error: awk: Internal software error in the tostring function on TS1101?05044400?.0085498227?0?.0011041461?.0034752266?.00397045?0?0?0?0?0?0?11/02/10?09/23/10???10?no??0??no?sct_det3_10_20110516_143936.txt ...... Shell Programming and Scripting
0
Shell Programming and Scripting
AWK limit for (length) function?
CKT_newbie88
I am trying to use the following code: awk '{s=$0;if(length(s) < 750){getline; s=s " " $0}printf("%s\n",s)}' filename but an error shows that 'awk' is too long. Is there a limit to the awk length function? and what could be an alternate solution for long fixed width records? The code...... Shell Programming and Scripting
3
Shell Programming and Scripting
how to write a wrapper c code to return uid using getuid() function
pwd
And how to use setuid() ? thanks... Programming
4
Programming
Red Hat Linux

Red Hat, Inc. is a global American software company providing open-source software products to the enterprise community. Red Hat was Founded in 1993, and has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide. On October 28, 2018, IBM announced its intent to acquire Red Hat for $34 billion. Red Hat has focused on Red Hat Enterprise Linux an enterprise operating system. Red Hat also acquired the open-source enterprise middleware vendor JBoss. Red Hat also sells an enterprise virtualization product, Red Hat Virtualization (RHV). Red Hat also provides storage, operating system platforms, middleware, applications, management products, and support, training, and consulting services. Red Hat actively creates, maintains, and contributes to many free and open software projects. Red Hat has acquired several proprietary software products through corporate mergers and acquisitions and has released these software acquisitions under open-source licenses.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.