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
UNIX and Linux

Unix (trademarked as the UNIX certification mark) is a very mature family of multitasking, multiuser computer operating systems that evolved from the original AT&T Unix. Unix development starting in the 1970s by legendary Bell Labs programmers Ken Thompson, Dennis Ritchie, and others. Unix was first targeted for the Bell System and AT&T licensed Unix to outside parties. In the 1970s time period, this lead to a variety of for-profit as well as not-for-profit Unix variants.
In the early days, this included the University of California, Berkeley (BSD), Microsoft (Xenix), IBM (AIX), and Sun Microsystems (Solaris). In the early 1990s, AT&T sold their Unix rights to Novell. In 1995 Novell sold their Unix business to the Santa Cruz Operation (SCO). The UNIX trademark was passed to The Open Group, a "neutral" industry consortium. The Open Group promoted the use of the UNIX trademark for certified operating systems that comply with the Single UNIX Specification (SUS). In 2014 Apple's macOS became the Unix version with the largest global install base and macOS remains the largest Unix-user base today.
Linux is a family of open source Unix-like operating systems based on the Linux kernel. The Linux kernel is an operating system kernel first released by Linus Torvalds on 17 September 1991. Linux distributions include the Linux kernel, system software and libraries. Popular free open source Linux distributions include Debian, Fedora, and Ubuntu. Commercial Linux distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Linux may be freely modified and redistributed. Anyone on the planet may create a Linux distribution for any purpose.
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.