Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2014, 08:59 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Mentor for Plugins - And Cron Help

Hey everyone!

I have recently done some neat little features for my community which may benefit others. I have currently done all the hard coding myself and have done certain features how I want them. I was wondering if anyone could point me towards an article on making a plugin or maybe walk me through it? I'd love to give back to the community in some way! Thanks!

--------------- Added [DATE]1417220241[/DATE] at [TIME]1417220241[/TIME] ---------------

In addition to the above request, I have an issue with a CRON task I am trying to do. It isn't being logged, and I'm not even sure that it is actually doing the process each night. Any help would be great!

PHP Code:
<?php

// Created by DrMath AKA James Will
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db)) {
    exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
// $nextrun is the time difference between runs. Should be sent over from cron.php!!
// We only check the users that have been active since the lastrun to save a bit of cpu time.

$thisrun TIMENOW;
$lastrun $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun $thisrun);

// Define Basic Membergroups
$membergroups = array(235515253);
$leadergroups = array(5617182438505455565862);

// Define Usergroup Levels
$grouplevels = array();
// Group ID, Required Points, Rank Image Source
$grouplevels[] = array(353"<img src='images/ranks/v9/mem_stea.png' alt='Steadfast Member' />""Steadfast Member");
$grouplevels[] = array(518"<img src='images/ranks/v9/mem_seni.png' alt='Senior Member' />""Senior Member");
$grouplevels[] = array(5215"<img src='images/ranks/v9/mem_reno.png' alt='Renowned Member' />""Renowned Member");
$grouplevels[] = array(5325"<img src='images/ranks/v9/mem_visi.png' alt='Visionary Member' />""Visionary Member");

// Get list of userids
$userid_q $vbulletin->db->query_read("SELECT userid FROM " TABLE_PREFIX "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
while (
$row mysql_fetch_array($userid_qMYSQL_ASSOC)) {
    
$userids[] = $row["userid"];
}
// Gather the Info
//$totalpromos = 0;

foreach ($userids as $userid) {

    
// Query DB for Post Content //
    
$threads_q $vbulletin->db->query_read("SELECT COUNT(*) FROM " TABLE_PREFIX "thread WHERE postuserid = $userid AND forumid NOT IN (13, 19, 28, 43, 47, 49, 71, 86, 126, 141,162, 167, 168, 178, 180, 181, 219, 222, 233, 237, 238, 239, 243, 254, 255, 256, 259, 267, 284, 285, 287, 301, 304, 306, 307, 312, 313, 314, 316, 319, 337, 338, 345, 346, 375, 381, 384, 385, 391, 396, 402)");
    
$recruits_q $vbulletin->db->query_read("SELECT COUNT(*) FROM " TABLE_PREFIX "user WHERE referrerid = $userid");
    
$awards_q $vbulletin->db->query_read("SELECT COUNT(*) FROM " TABLE_PREFIX "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20, 23)");
    
$info_q $vbulletin->db->query_read("SELECT user.username, user.posts, user.joindate, user.usergroupid, user.membergroupids, userfield.field49, userfield.field50 FROM " TABLE_PREFIX "user as user LEFT JOIN " TABLE_PREFIX "userfield as userfield ON (userfield.userid=user.userid) WHERE user.userid = $userid");


    
// Transfer to Arrays
    
$u_threads $vbulletin->db->fetch_array($threads_q);
    
$u_recruits $vbulletin->db->fetch_array($recruits_q);
    
$u_awards $vbulletin->db->fetch_array($awards_q);
    
$u_info $vbulletin->db->fetch_array($info_q);

    
$posts $u_info[1];
    
$joindate = new DateTime(date("Y-m-d"$u_info[2]));
    
$currentdate = new DateTime();
    
$displaydate vbdate($vbulletin->options['dateformat'], $u_info[2], true);
    
//date
    
$datediff $currentdate->diff($joindate);
    
$datediffm $datediff->format('%m');
    
$datediffy $datediff->format('%y');
    
$datediff $datediffm + (12 $datediffy);
    
//end date
    
$usergroup $u_info[3];
    
$othergroups $u_info[4];
    
$staffyesno $u_info[5];
    
$adminyesno $u_info[6];
    
$threads $u_threads[0];
    
$recruits $u_recruits[0];
    
$awards $u_awards[0];
    
$totalpoints 0;

    
// Post Points

    
if ($posts >= 10) {
        
$totalpoints += 1;
    }
    if (
$posts >= 25) {
        
$totalpoints += 1;
    }
    if (
$posts >= 50) {
        
$totalpoints += 1;
    }
    if (
$posts >= 100) {
        
$totalpoints += 1;
    }
    if (
$posts >= 300) {
        
$totalpoints += 5;
    }
    if (
$posts >= 500) {
        
$ppoints floor($posts 500);
        
$totalpoints += $ppoints;
    }

    
// Thread Points

    
if ($threads >= 10) {
        
$totalpoints += 1;
    }
    if (
$threads >= 20) {
        
$totalpoints += 1;
    }
    if (
$threads >= 50) {
        
$totalpoints += 2;
    }
    if (
$threads >= 100) {
        
$tpoints floor($threads 100);
        
$totalpoints += $tpoints;
    }

    
// Recruited Member Points

    
if ($recruits >= && $recruits <= 4) {
        
$totalpoints += $recruits;
    } elseif (
$recruits >= 5) {
        
$r5points floor($recruits 5);
        
$totalpoints += ($r5points);
    }

    
// Membership Length Points

    
if ($datediff >= 1) {
        
$totalpoints += 1;
    }
    if (
$datediff >= 3) {
        
$totalpoints += 1;
    }
    if (
$datediff >= 6) {
        
$totalpoints += 2;
    }
    if (
$datediff >= 12) {
        
$totalpoints += 5;
    }
    if (
$datediff >= 18) {
        
$m6ppoints floor(($datediff 12) / 6);
        
$totalpoints += $m6ppoints;
    }

    
// Award Points

    
if ($awards 0) {
        
$apoints $awards;
        
$totalpoints += $apoints;
    }

    
// Points for Positions

    
if ($staffyesno == "Yes") {
        
$staffpts $totalpoints += 2;
    }
    if (
$adminyesno == "Yes") {
        
$adminpts $totalpoints += 5;
    }

    
// Begin Promotions
    
$newgroup $newrank $newranktitle "";

    
// If they are not in leadership
    
if (in_array($usergroup$membergroups)) {
        
// Go Through Each Rank and Check if They Can Achieve It
        
foreach ($grouplevels as $level) {
            
$groupid $level[0];
            
$reqpoints $level[1];
            
$rankcode $level[2];
            
$ranktitle $level[3];

            
// If they have points to rank up
            
if ($totalpoints >= $reqpoints && $usergroup $groupid) {
                
$newgroup $groupid;
                
$newrank $rankcode;
                
$newranktitle $ranktitle;
            }

            
// Update Chron Log
            
$log = array($newgroup'*'$newranktitle);
            
// the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action(serialize($log), $nextitem1);
        }

        
// If they earned a new usergroup, change it
        
if ($newgroup != null) {
            
$userinfo fetch_userinfo($userid);
            
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('usergroupid'$newgroup);
            
$userdata->setr('usertitle'$newrank);
            
$userdata->save();
            
//$totalpromos ++;
        
}
    }
    
    
// If they are in leadership, check additional groups
    
if (in_array($usergroup$leadergroups)) {
        
        
// If no additional usergroup, set apprentice
        
if ($othergroups == null) {
            
$othergroups "2";
        }

        foreach (
$membergroups as $gid) {
            
$group = (string) $gid;
            if (
in_array($groupexplode(",",$othergroups)) !== false) {
                
$secgroup $group;
                
$secgroupid $gid;
                break;
            }
        }

        
// Go Through Each Rank and Check if They Can Achieve It
        
foreach ($grouplevels as $level) {
            
$groupid $level[0];
            
$reqpoints $level[1];
            
$ranktitle $level[3];

            
// If they have points to rank up
            
if ($totalpoints >= $reqpoints && $secgroupid $groupid) {
                
$newgroup = (string) $groupid;
                
$newranktitle $ranktitle;
            }

            
$log = array($newgroup'*'$newranktitle);
            
// the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action(serialize($log), $nextitem1);
        }

        
$othergroups str_replace($secgroup$newgroup$othergroups);

        
// If they earned a new usergroup, change it
        
if ($newgroup != null) {
            
$userinfo fetch_userinfo($userid);
            
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('membergroupids'$othergroups);
            
$userdata->save();
            
//$totalpromos ++;
        
}
    }
}

$vbulletin->crondata['promos_lastrun'] = $thisrun;
build_datastore('crondata'serialize($vbulletin->crondata), 1);


if (
$vbulletin->debug AND VB_AREA == 'AdminCP') {
    
#echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
}


/* ======================================================================*\
  || ####################################################################
  || # Updated, July 26, 2014
  || ####################################################################
  \*====================================================================== */
?>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:49 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08685 seconds
  • Memory Usage 2,379KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete