Sponsored Content
Top Forums Web Development Notes with Ravinder on Badging System Development Part II Post 303028164 by Neo on Tuesday 1st of January 2019 04:31:05 AM
Old 01-01-2019
Notes with Ravinder on Badging System Development Part II

Part II: Current PHP file Beta 73 Not Optimized:

Code:
<?php
$version = 73;
$query = "SELECT * FROM " . TABLE_PREFIX . "user WHERE userid='" . $uid . "'";
$usertable = $db->query_read_slave($query);
$modaluser = $db->fetch_array($usertable);
$modaluser['joindate_formatted'] = gmdate("d F Y", $modaluser['joindate']);
$modaluser['checking_formatted'] = number_format($modaluser['credits']);
$modaluser['savings_formatted'] = number_format($modaluser['credits_saved']);
$total_bits = $modaluser['credits'] + $modaluser['credits_saved'];
$modaluser['total_bits_formatted'] = number_format($total_bits);
$modaluser['total_thanks_formatted'] = number_format($modaluser['post_thanks_thanked_times']);
$modaluser['total_thanks_given_formatted'] = number_format($modaluser['post_thanks_user_amount']);
$modaluser['total_thanked_posts_formatted'] = number_format($modaluser['post_thanks_thanked_posts']);
$f_query = "SELECT * FROM " . TABLE_PREFIX . "userfield WHERE userid='" . $uid . "'";
$userfields = $db->query_read_slave($f_query);
$modaluserfields = $db->fetch_array($userfields);

$query_csa = "SELECT * FROM " . TABLE_PREFIX . "neo_csa_session_manager WHERE user_id='" . $uid . "'";
$user_csa_row = $db->query_read_slave($query_csa);
$usercsa = $db->fetch_array($user_csa_row);

if ($usercsa['country'] == '') {
    if ($modaluser['country_iso2'] != '') {
        $usercsa['country'] = $modaluser['country_iso2'] . " (Legacy)";
    } else {
        $usercsa['country'] = 'TBD - Waiting for Update';
    }
}
if ($usercsa['ip_address'] == '') {
    if ($modaluser['ipaddress'] != '') {
        $usercsa['ip_address'] = $modaluser['ipaddress'] . " (Legacy)";
    } else {
        $usercsa['ip_address'] = 'TBD - Waiting for Update';
    }
}

if ($usercsa['user_agent'] == '') {
    $usercsa['user_agent'] = 'TBD - Waiting for Update';
}

if ($usercsa[riskscore] == '') {
    $usercsa[riskscore] = 'TBD';
}

if ($usercsa[hitcount] == '') {
    $usercsa[hitcount] = 'TBD';
}

$a_query = "SELECT SUM(visible) AS totalpics FROM album WHERE userid='" . $uid . "'";
$pics = $db->query_read_slave($a_query);
$userpics = $db->fetch_array($pics);

$at_query = "SELECT COUNT(attachmentid) AS totalattachments FROM attachment WHERE userid='" . $uid . "'";
$attachs = $db->query_read_slave($at_query);
$userattachments = $db->fetch_array($attachs);

$pm_query = 'SELECT COUNT(pmtextid) AS count ' .
    'FROM ' . pm .
    ' WHERE userid = "' . $uid . '"';
$userpm = $vbulletin->db->query_first($pm_query);

$sub_query = 'SELECT COUNT(threadid) AS count ' .
    'FROM ' . subscribethread .
    ' WHERE userid = "' . $uid . '"';
$usersubs = $vbulletin->db->query_first($sub_query);
$color = array();
$mbclass = array();

if ($modaluser['posts'] > 1000) {
    $color['fauser'] = 'black';
} elseif ($modaluser['posts'] > 500) {
    $color['fauser'] = 'indigo';
} elseif ($modaluser['posts'] > 100) {
    $color['fauser'] = 'blue';
} elseif ($modaluser['posts'] > 10) {
    $color['fauser'] = 'limegreen';
} else {
    $color['fauser'] = 'lightgray';
}

/******************************* REFERENCE ONLY NOT USED  CAN  DELETE
if ($modaluser['posts'] > 1000) {
    $mbclass['fauser'] = 'mb-4';
} elseif ($modaluser['posts'] > 500) {
    $mbclass['fauser'] = 'mb-3';
} elseif ($modaluser['posts'] > 100) {
    $mbclass['fauser'] = 'mb-3';
} elseif ($modaluser['posts'] > 10) {
    $mbclass['fauser'] = 'mb-1';
} else {
    $mbclass['fauser'] = 'mb-0';
}
*****************************/


$color['faaward'] = 'lightgray';
if ($modaluser['posts'] > 0) {
    $color['faaward'] = 'limegreen';
}

$color['fajediorder'] = 'lightgray';
if ($modaluser['posts'] > 99) {
    $color['fajediorder'] = 'blue';
}

$color['faphoenix'] = 'lightgray';
if ($modaluser['posts'] > 499) {
    $color['faphoenix'] = 'indigo';
}

$color['fajedi'] = 'lightgray';
if ($modaluser['posts'] > 999) {
    $color['fajedi'] = 'black';
}

$color['faatom'] = 'lightgray';
if ($modaluser['posts'] > 9999) {
    $color['faatom'] = 'black';
}

$mods = array('6', '10');
$banned = '11';
$color['fascale'] = 'lightgray';
if (in_array($modaluser['usergroupid'], $mods)) {
    $color['fascale'] = 'black';
} elseif ($modaluser['usergroupid'] == $banned) {
    $color['fascale'] = 'red';
} else {
    $color['fascale'] = 'lightgray';
}

$orderofthecrab = '37898';

if ($uid == $orderofthecrab) {
    $color['facrab'] = 'black';
} else {
    $color['facrab'] = 'lightgray';
}

$orderofthewizard = array('43551', '302136317');

if (in_array($uid, $orderofthewizard)) {
    $color['fawizard'] = 'black';
} else {
    $color['fawizard'] = 'lightgray';
}

$admins = array('1');
$color['fabuilding'] = 'lightgray';
if (in_array($modaluser['userid'], $admins)) {
    $color['fabuilding'] = 'black';
}

$ug = array('6', '10', '13');
$color['fabishop'] = 'lightgray';
if (in_array($modaluser['usergroupid'], $ug)) {
    $color['fabishop'] = 'black';
}

$devops = array('1', '39016', '302063521');
$color['facity'] = 'lightgray';
if (in_array($modaluser['userid'], $devops)) {
    $color['facity'] = 'black';
}

$forumideas = array('1', '39016', '302063521', '302148617');
$color['faflask'] = 'lightgray';
if (in_array($modaluser['userid'], $forumideas)) {
    $color['faflask'] = 'black';
}

$color['fathumbsup'] = 'lightgray';
$color['fatrophy'] = 'lightgray';
$color['fachalkboardteacher'] = 'lightgray';
$color['fashieldalt'] = 'lightgray';
$color['fastroopwafel'] = 'lightgray';
$color['fafirstorderalt'] = 'lightgray';

if ($modaluser['post_thanks_thanked_times'] > 0) {
    $color['fathumbsup'] = 'limegreen';
}

if ($modaluser['post_thanks_thanked_times'] > 99) {
    $color['fathumbsup'] = 'blue';
    $color['fatrophy'] = 'black';
}

if ($modaluser['post_thanks_thanked_times'] > 999) {
    $color['fathumbsup'] = 'indigo';
    $color['fachalkboardteacher'] = 'black';
}

if ($modaluser['post_thanks_thanked_times'] > 1999) {
    $color['fathumbsup'] = 'black';
    $color['fashieldalt'] = 'black';
}

if ($modaluser['post_thanks_thanked_times'] > 2999) {
    $color['fastroopwafel'] = 'black';
}

if ($modaluser['post_thanks_thanked_times'] > 3999) {
    $color['fafirstorderalt'] = 'black';
}

$idfields = 0;
if ($modaluserfields['field1']) {
    $idfields++;
}
if ($modaluserfields['field2']) {
    $idfields++;
}
if ($modaluserfields['field3']) {
    $idfields++;
}
if ($modaluserfields['field4']) {
    $idfields++;
}

switch ($idfields) {
    case 0:
        $color['faidbadge'] = 'lightgray';
        break;
    case 1:
        $color['faidbadge'] = 'limegreen';
        break;
    case 2:
        $color['faidbadge'] = 'blue';
        break;
    case 3:
        $color['faidbadge'] = 'indigo';
        break;
    case 4:
        $color['faidbadge'] = 'black';
        break;
}

$contacts = 0;
if ($show['pm']) {
    $contacts++;
}
if ($show['email']) {
    $contacts++;
}

if ($modaluser[homepage]) {
    $contacts++;
}

switch ($contacts) {
    case 0:
        $color['faaddressbook'] = 'lightgray';
        break;
    case 1:
        $color['faaddressbook'] = 'limegreen';
        break;
    case 2:
        $color['faaddressbook'] = 'blue';
        break;
    case 3:
        $color['faaddressbook'] = 'black';
        break;
    default:
        $color['faaddressbook'] = 'lightgray';
}

$color['fabtc'] = 'lightgray';
$color['fauniversity'] = 'lightgray';

if ($total_bits < -20000) {
    $color['fabtc'] = 'red';
} elseif ($total_bits < 0) {
    $color['fabtc'] = 'dark orange';
}

if ($total_bits > 0) {
    $color['fabtc'] = 'limegreen';
}

if ($total_bits > 100000) {
    $color['fabtc'] = 'blue';
}

if ($total_bits > 1000000) {
    $color['fabtc'] = 'indigo';
}

if ($total_bits > 10000000) {
    $color['fabtc'] = 'black';
    $color['fauniversity'] = 'blue';
}

if ($total_bits > 100000000) {
    $color['fauniversity'] = 'black';
}

$color['fausergraduate'] = 'lightgray';
$time_inactive = time() - $modaluser['lastactivity'];
$week = 7 * 24 * 60 * 60;
$month = 4 * $week;
$quarter = $week * (52 / 4);
$halfyear = $week * (52 / 2);
$year = $week * 52;
$twoyears = 2 * $year;
$threeyears = 3 * $year;

if ($time_inactive < $week) {
    $color['fausergraduate'] = 'black';
} elseif ($time_inactive < $month) {
    $color['fausergraduate'] = 'indigo';
} elseif ($time_inactive < $quarter) {
    $color['fausergraduate'] = 'blue';
} elseif ($time_inactive < $halfyear) {
    $color['fausergraduate'] = 'limegreen';
} elseif ($time_inactive < $year) {
    $color['fausergraduate'] = 'lightgray';
} elseif ($time_inactive < $twoyears) {
    $color['fausergraduate'] = 'darkorange';
} elseif ($time_inactive < $threeyears) {
    $color['fausergraduate'] = 'red';
}

$color['fabolt'] = 'lightgray';
$activity = floatval($prepared['postsperday']);
if ($activity < 0.02) {
    $color['fabolt'] = 'red';
} elseif ($activity < 0.1) {
    $color['fabolt'] = 'darkorange';
} elseif ($activity < 0.5) {
    $color['fabolt'] = 'limegreen';
} elseif ($activity < 1.0) {
    $color['fabolt'] = 'blue';
} elseif ($activity < 2.0) {
    $color['fabolt'] = 'indigo';
} else {
    $color['fabolt'] = 'black';
}

$queryc = "SELECT COUNT(threadid) AS threadcount FROM thread WHERE postuserid='" . $uid . "'";
$resultsc = $db->query_first_slave($queryc);
if ($resultsc['threadcount'] > 500) {
    $color['faknight'] = 'black';
} elseif ($resultsc['threadcount'] > 250) {
    $color['faknight'] = 'indigo';
} elseif ($resultsc['threadcount'] > 100) {
    $color['faknight'] = 'blue';
} elseif ($resultsc['threadcount'] > 1) {
    $color['faknight'] = 'limegreen';
} else {
    $color['faknight'] = 'lightgray';
}

if ($userattachments['totalattachments'] > 500) {
    $color['fadownload'] = 'black';
} elseif ($userattachments['totalattachments'] > 100) {
    $color['fadownload'] = 'indigo';
} elseif ($userattachments['totalattachments'] > 10) {
    $color['fadownload'] = 'blue';
} elseif ($userattachments['totalattachments'] > 1) {
    $color['fadownload'] = 'limegreen';
} else {
    $color['fadownload'] = 'lightgray';
}

if (true) {
    $queryt = "SELECT COUNT(tagid) AS tagcount FROM tagthread WHERE userid =" . $uid;
    $resultst = $db->query_first_slave($queryt);
    if ($resultst['tagcount'] > 10000) {
        $color['fatags'] = 'black';
    } elseif ($resultst['tagcount'] > 1000) {
        $color['fatags'] = 'indigo';
    } elseif ($resultst['tagcount'] > 100) {
        $color['fatags'] = 'blue';
    } elseif ($resultst['tagcount'] > 1) {
        $color['fatags'] = 'limegreen';
    } else {
        $color['fatags'] = 'lightgray';
    }
}

$query = "SELECT views AS threadhits FROM thread WHERE postuserid=" . $uid . " ORDER BY views DESC  LIMIT 1";
$results = $db->query_first_slave($query);
if ($results['threadhits'] > 100000) {
    $color['faeye'] = 'black';
} elseif ($results['threadhits'] > 50000) {
    $color['faeye'] = 'indigo';
} elseif ($results['threadhits'] > 10000) {
    $color['faeye'] = 'blue';
} elseif ($results['threadhits'] > 1000) {
    $color['faeye'] = 'limegreen';
} else {
    $color['faeye'] = 'lightgray';
}

$queryi = "SELECT ipoints AS infractions FROM user WHERE userid =" . $uid;
$resultsi = $db->query_first_slave($queryi);
if ($resultsi['infractions'] >= 30 || $modaluser['usergroupid'] == 11) {
    $color['fainfraction'] = 'red';
} elseif ($resultsi['infractions'] < 30 && $results['infractions'] >= 10) {
    $color['fainfraction'] = 'orangered';
} elseif ($resultsi['infractions'] < 10 && $results['infractions'] >= 7) {
    $color['fainfraction'] = 'limegreen';
} elseif ($resultsi['infractions'] < 7 && $results['infractions'] >= 5) {
    $color['fainfraction'] = 'blue';
} elseif ($resultsi['infractions'] < 5 && $results['infractions'] > 0) {
    $color['fainfraction'] = 'indigo';
} else {
    $color['fainfraction'] = 'black';
}

if (true) {
    $queryTG = "SELECT post_thanks_user_amount AS thanks_given FROM user WHERE userid =" . $uid;
    $resultsTG = $db->query_first_slave($queryTG);
    if ($resultsTG['thanks_given'] > 0 && $resultsTG['thanks_given'] < 50) {
        $color['fathanks_given'] = 'limegreen';
    } elseif ($resultsTG['thanks_given'] < 500 && $resultsTG['thanks_given'] >= 50) {
        $color['fathanks_given'] = 'blue';
    } elseif ($resultsTG['thanks_given'] < 1000 && $resultsTG['thanks_given'] >= 500) {
        $color['fathanks_given'] = 'indigo';
    } elseif ($resultsTG['thanks_given'] > 1000) {
        $color['fathanks_given'] = 'black';
    } else {
        $color['fathanks_given'] = 'red';
    }
}

$badgejs = '<script>';
$badgejs .= 'var badge = [];';
$badgejs .= 'badge["posts"] = "' . $color[fauser] . '";';
$badgejs .= 'badge["firstpost"] = "' . $color[faaward] . '";';
$badgejs .= 'badge["100posts"] = "' . $color[fajediorder] . '";';
$badgejs .= 'badge["500posts"] = "' . $color[faphoenix] . '";';
$badgejs .= 'badge["1000posts"] = "' . $color[fajedi] . '";';
$badgejs .= 'badge["10000posts"] = "' . $color[faatom] . '";';
$badgejs .= 'badge["mod"] = "' . $color[fascale] . '";';
$badgejs .= 'badge["admin"] = "' . $color[fabuilding] . '";';
$badgejs .= 'badge["ug"] = "' . $color[fabishop] . '";';
$badgejs .= 'badge["devops"] = "' . $color[facity] . '";';
$badgejs .= 'badge["formulator"] = "' . $color[faflask] . '";';
$badgejs .= 'badge["totalposts"] = "' . number_format($modaluser[posts]) . '";';
$badgejs .= 'badge["thanked"] = "' . $color['fathumbsup'] . '";';
$badgejs .= 'badge["100thanked"] = "' . $color['fatrophy'] . '";';
$badgejs .= 'badge["1000thanked"] = "' . $color['fachalkboardteacher'] . '";';
$badgejs .= 'badge["2000thanked"] = "' . $color['fashieldalt'] . '";';
$badgejs .= 'badge["3000thanked"] = "' . $color['fastroopwafel'] . '";';
$badgejs .= 'badge["4000thanked"] = "' . $color['fafirstorderalt'] . '";';
$badgejs .= 'badge["profile"] = "' . $color['faidbadge'] . '";';
$badgejs .= 'badge["contact"] = "' . $color['faaddressbook'] . '";';
$badgejs .= 'badge["contacttotal"] = "' . $contacts . '";';
$badgejs .= 'badge["profilenumber"] = "' . $idfields . '";';
$badgejs .= 'badge["fabtc"] = "' . $color['fabtc'] . '";';
$badgejs .= 'badge["fauniversity"] = "' . $color['fauniversity'] . '";';
$badgejs .= 'badge["bits"] = "' . number_format($total_bits) . '";';
$badgejs .= 'badge["activity"] = "' . $color['fausergraduate'] . '";';
$badgejs .= 'badge["ppd"] = "' . $color['fabolt'] . '";';
$badgejs .= 'badge["ppdval"] = "' . $activity . '";';
$badgejs .= 'badge["starter"] = "' . $color['faknight'] . '";';
$badgejs .= 'badge["starterval"] = "' . $resultsc['threadcount'] . '";';
$badgejs .= 'badge["fadownload"] = "' . $color['fadownload'] . '";';
$badgejs .= 'badge["fadownloadval"] = "' . $userattachments['totalattachments'] . '";';
$badgejs .= 'badge["fatags"] = "' . $color['fatags'] . '";';
$badgejs .= 'badge["fatagsval"] = "' . number_format($resultst['tagcount']) . '";';
$badgejs .= 'badge["faeye"] = "' . $color['faeye'] . '";';
$badgejs .= 'badge["faeyeval"] = "' . number_format($results['threadhits']) . '";';
$badgejs .= 'badge["facrab"] = "' . $color['facrab'] . '";';
$badgejs .= 'badge["fawizard"] = "' . $color['fawizard'] . '";';
$badgejs .= 'badge["fainfraction"] = "' . $color['fainfraction'] . '";';
$badgejs .= 'badge["fainfractionval"] = "' . number_format($resultsi['infractions']) . '";';
$badgejs .= 'badge["fathanks_given"] = "' . $color['fathanks_given'] . '";';
$badgejs .= 'badge["fathanks_givenval"] = "' . number_format($resultsTG['thanks_given']) . '";';
$badgejs .= '</script>';

This User Gave Thanks to Neo For This Post:
 

3 More Discussions You Might Find Interesting

1. What is on Your Mind?

New Badging System - Badges Prototype Beta 1 (Badges Only)

Today I mapped out the new badging system using FA icons, Beta 1 in no particular order except a 6 x 8 grid: https://www.unix.com/members/1-albums215-picture991.png The prototype HTML code for this layout: <style> .fa-badge-grid { font-size: 1.5em; } .row { ... (38 Replies)
Discussion started by: Neo
38 Replies

2. What is on Your Mind?

Status of Badging System - Beta 1

Dear All, Here is the current status of the badging system: The Beta 1 phase of the new badging system is close to completion. 42 prototype badges have been "allocated" 6 prototype badge slots are held in reserve The "alert you have new badges" prototype is running and is currently... (4 Replies)
Discussion started by: Neo
4 Replies

3. What is on Your Mind?

Badging System: UNIX.COM Bug Hunter Badge (New)

I have moved the bug badge out of reserve and into the main stream. Basically, I will assign a color level like the others, based on who has made a good actionable bug report for UNIX.COM. "Good" means screenshots, links, and even details from web dev tools our the HTML source code. So far,... (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 01:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy