PDA

View Full Version : Posts Per Day Variable in Plugin


Chris.08i
12-11-2015, 12:30 PM
Hello,

I'm trying to create an if dependent on posts per day - however I'm unable to implement it within the PHP.

I'm fairly new to coding, so I maybe missing the mark completely.

I've tried:
$vbphrase[posts_per_day]
$post[postsperday]
$postsperday
$vbulletin->userinfo['postsperday']

None of these seem to work.

I am trying to implement it into the vBShop plugin in the newpost_complete.php hook.

The code is as follows:
<?php

if ($vbulletin->userinfo['userid'] AND $vbulletin->options['dbtech_vbshop_enablepoints'])
{
foreach ((array)VBSHOP::$cache['currency'] as $currencyid => $currency)
{
// Shorthand
$var = 'per' . $type;


if (!$currency[$var])
{
continue;
}



// Update the points table
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . $currency['pointstable'] . "
SET " . $currency['pointscolumn'] . " = " . $currency['pointscolumn'] . " + '" . doubleval($currency[$var]) . "'
WHERE userid = " . $vbulletin->db->sql_prepare($vbulletin->userinfo['userid'])
);

$info = array(
'currencyid' => $currencyid,
'amount' => doubleval($currency[$var]),
);

switch ($var)
{
case 'perthread':
$info['threadid'] = $threadinfo['threadid'];
break;

case 'perreply':
$info['postid'] = $post['postid'];
break;
}

// init data manager
$dm =& VBSHOP::initDataManager('Transactionlog', $vbulletin, ERRTYPE_ARRAY);
$dm->set('userid', $vbulletin->userinfo['userid']);
$dm->set('recipient', $vbulletin->userinfo['userid']);
$dm->set('ipaddress', IPADDRESS);
$dm->set('action', $var);
$dm->set('info', $info);
$dm->save();
unset($dm);
}
}
?>

Any help would be appreciated.

Cheers,
Chris

MarkFL
12-11-2015, 03:24 PM
You could use something like:

$postsperday = $vbulletin->userinfo['posts']/((TIMENOW - $vbulletin->userinfo['joindate'])/86400);

Chris.08i
12-11-2015, 08:02 PM
I thought posts per day is an already calculated variable somewhere?

MarkFL
12-11-2015, 10:09 PM
It is calculated specifically for the profile page, but it is not available as a ready-made element of the $userinfo array, however the post count and join date are, and that's all you need to calculate the ratio. :D

Chris.08i
12-14-2015, 05:01 AM
Thank you Mark!