2019-08-12, 12:21 AM
(This post was last modified: 2019-08-12, 12:23 AM by GodLess101. Edited 1 time in total.)
Okay so I'm currently finishing up a pretty shabby plugin... The last is to create a displayable text for the postbit based on the users leechstatus.
The reason why I'm not doing template conditionals is because we' have pretty much of that already, as such I'm in need of some help.
I have in db a row named leechstatus, I'm effectively able to grasp and use that in template by doing {$post['leechstatus']}
And although the above is declared first in my function and this is the hook:
I'm unable to use either leechamount or leechtext variables in template, I've tried the following:
<?php echo $leechamount; echo $leechtext; echo $post['leechtext']; echo $post['leechamount']; ?>
and the corresponding {$leechtext} {$leechamount} {$post['leechamount']} {$post['leechamount']}
I'm not sure what I'm doing wrong, I'm making sure it's initialized, but I'm not adding it to an array of data or anything like that, is there something I'm missing?
Also another reason why I want to do it like this is because I'm very eager to learn how to implement and develop plugins, but as this is my first actual plugin it feels a bit hard to comprehend for me :3
It should also be said the reason I'm not catching on is because of the fact that I've succesfully edited a smaller plugin where declaring a variable as global was enough to make me use it on index_start hook. But now I'm just failing at this xD
The reason why I'm not doing template conditionals is because we' have pretty much of that already, as such I'm in need of some help.
I have in db a row named leechstatus, I'm effectively able to grasp and use that in template by doing {$post['leechstatus']}
global $db, $mybb, $post, $leechamount, $leechtext;
And although the above is declared first in my function and this is the hook:
$plugins->add_hook("postbit", "advancedleech_post");
I'm unable to use either leechamount or leechtext variables in template, I've tried the following:
<?php echo $leechamount; echo $leechtext; echo $post['leechtext']; echo $post['leechamount']; ?>
and the corresponding {$leechtext} {$leechamount} {$post['leechamount']} {$post['leechamount']}
I'm not sure what I'm doing wrong, I'm making sure it's initialized, but I'm not adding it to an array of data or anything like that, is there something I'm missing?
function advancedleech_post(&$post)
{
global $db, $mybb, $post, $leechamount, $leechtext;
require_once "inc/functions_post.php";
$query = $db->query("SELECT leechstatus FROM ".TABLE_PREFIX."users WHERE uid ='".$post['uid']."'");
$leechamount = '0';
while($result = $db->fetch_array($query))
{
$leechamount = $result['leechstatus'];
}
$highbounds = $mybb->settings['high_bounds'];
$lowbounds = $mybb->settings['low_bounds'];
$verylowbounds = $mybb->settings['verylow_bounds'];
$leechtexticon = $mybb->settings['leechtext_icon'];
if ((int)$leechamount >= (int)$highbounds) {
// GREAT leechstatus
$leechtext = '<div class="post-row-s">
<div class="post-row">
<div class="post-icon">'.$leechtexticon.'</div>
<div class="post-row-inner">Leech:<span class="ml-auto" color="green">GREAT</span></div>
</div>
</div>';
} elseif ((int)$leechamount > (int)$lowbounds) {
// GOOD leechstatus
$leechtext = '<div class="post-row-s">
<div class="post-row">
<div class="post-icon">'.$leechtexticon.'</div>
<div class="post-row-inner">Leech:<span class="ml-auto" color="green">GOOD</span></div>
</div>
</div>';
} elseif ((int)$leechamount < (int)$lowbounds) {
// BAD status
$leechtext = '<div class="post-row-s">
<div class="post-row">
<div class="post-icon">'.$leechtexticon.'</div>
<div class="post-row-inner">Leech:<span class="ml-auto" color="orange">BAD</span></div>
</div>
</div>';
} elseif ((int)$leechamount < (int)$verylowbounds) {
// LEECHER status
$leechtext = '<div class="post-row-s">
<div class="post-row">
<div class="post-icon">'.$leechtexticon.'</div>
<div class="post-row-inner">Leech:<span class="ml-auto" color="red">LEECHER</span></div>
</div>
</div>';
}
}
Also another reason why I want to do it like this is because I'm very eager to learn how to implement and develop plugins, but as this is my first actual plugin it feels a bit hard to comprehend for me :3
It should also be said the reason I'm not catching on is because of the fact that I've succesfully edited a smaller plugin where declaring a variable as global was enough to make me use it on index_start hook. But now I'm just failing at this xD