MyBB Community Forums

Full Version: Hi i have problem with some variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i trying to make a few changes to daily post goal plugin.

This is the default plugin
 [Image: OBdlcWk.png]


and im trying to make this

[Image: RQkXfnQ.png]


The code of the plugins is this:

<?php

defined('IN_MYBB') or die('Denied.');

function postgoal_info()
{
	return array(
		'name'          => 'Daily Post Goal',
		'description'   => 'Set a daily post goal the forum should achieve daily.',
		'website'       => 'https://community.mybb.com/user-83692.html',
		'author'        => 'Sazze',
		'authorsite'    => 'https://community.mybb.com/user-83692.html',
		'version'       => '0.1',
		'codename' 		=> 'postgoal',
		'compatibility' => '18*'
	);
}

function postgoal_activate()
{
	global $db;

	$disporder_query = $db->simple_select('settinggroups', 'COUNT(*) AS disp');
	$disporder = (int)$db->fetch_field($disporder_query, 'disp');

	$settings_group = array(
		'name'        => 'postgoal',
		'title'       => 'Post Goal Settings',
		'description' => 'Edit the settings of the Post Goal plugin.',
		'disporder'   => ((int)$disporder + 1)
	);

    $gid = $db->insert_query('settinggroups', $settings_group);

    $setting[] = array(
    	'name'        => 'postgoal_goal',
    	'title'       => $db->escape_string('What\'s the goal?'),
    	'description' => 'The amount of posts the forum should achieve daily.',
    	'optionscode' => 'numeric',
    	'disporder'   => 1,
    	'value'       => 100,
    	'gid'         => (int)$gid
    );

    $setting[] = array(
    	'name'        => 'postgoal_goal_reached',
    	'title'       => 'Custom Reached text',
    	'description' => 'What message should display once goal has been reached?',
    	'optionscode' => 'text',
    	'disporder'   => 2,
    	'value'       => 'Reached',
    	'gid'         => (int)$gid
    );

    $setting[] = array(
    	'name'        => 'postgoal_goal_not_reached',
    	'title'       => 'Custom Not Reached text',
    	'description' => 'What message should it say if the goal is not reached?',
    	'optionscode' => 'text',
    	'disporder'   => 3,
    	'value'       => 'Not Reached',
    	'gid'         => (int)$gid
    );


    $db->insert_query_multiple('settings', $setting);
    rebuild_settings();

    $template = '
    <table border="0" cellspacing="0" cellpadding="5" class="tborder" style="width: 24%; float: right;">
    <tr>
    <td class="thead" colspan="5">
    <strong><a href="forumdisplay.php?fid=1">Daily Post Goal</a></strong>
    </td>
    </tr>

    <tr>
    <td class="trow1" width="50%">Goal:</td>
    <td class="trow1" width="50%">{$fetch}/{$postgoal}</td>
    </tr>

    <tr>
    <td class="trow1" width="50%">Status:</td>
    <td class="trow1" width="50%">{$postgoal_status}</td>
    </tr>
    </table>';

    $insert_template = array(
    	'title'    => 'postgoal',
    	'template' => $db->escape_string($template),
    	'sid'      => '-1',
    	'version'  => '',
    	'dateline' => TIME_NOW
    );

    $db->insert_query('templates', $insert_template);

    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", '#'.preg_quote('{$boardstats}').'#', '{$boardstats}{$postgoal_show}');
    find_replace_templatesets("index", '#'.preg_quote('{$forums}{$boardstats}').'#', '<div style="width: 76%; float: left;">{$forums}{$boardstats}</div>');
}

function postgoal_deactivate()
{
	global $db;

	$db->delete_query('templates', 'title = \'postgoal\'');
	$db->delete_query('settinggroups', 'name = \'postgoal\'');
	$db->delete_query('settings', 'name LIKE \'%postgoal_%\'');
	rebuild_settings();

	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	find_replace_templatesets("index", '#'.preg_quote('{$postgoal_show}').'#', '');
	find_replace_templatesets("index", '#'.preg_quote('<div style="width: 76%; float: left;">{$forums}{$boardstats}</div>').'#', '{$forums}{$boardstats}');
}

$plugins->add_hook('index_start', 'postgoal_index');
function postgoal_index()
{
	global $mybb, $db, $templates, $postgoal_status, $postgoal_show;

	$start = strtotime('00:00:00');
	$end = strtotime('+1 day', $start);
	$postgoal = my_number_format($mybb->settings['postgoal_goal']);

	$query = $db->simple_select('posts', '*', "dateline >= {$start} AND dateline <= {$end}");
	$fetch = my_number_format($db->num_rows($query));

	if ($fetch >= $postgoal)
		$postgoal_status = htmlspecialchars_uni($mybb->settings['postgoal_goal_reached']);
	else
		$postgoal_status = htmlspecialchars_uni($mybb->settings['postgoal_goal_not_reached']);

	/* Show progress. */
	eval('$postgoal_show  = "' . $templates->get('postgoal') . '";');
}


the template is this:
<tr>
    <td class="thead" colspan="5">
    <strong><a href="forumdisplay.php?fid=1">Daily Post Goal</a></strong>
    </td>
    </tr>

    <tr>
    <td class="trow1" width="50%">Goal:</td>
    <td class="trow1" width="50%">{$fetch}/{$postgoal}</td>
    </tr>

    <tr>
    <td class="trow1" width="50%">Status:</td>
    <td class="trow1" width="50%">{$postgoal_status}</td>
</tr>

And the change that im trying to do is:

<td class="thead" align="left">Daily Post Goal</td></tr>
<tr>
 <td class="trow1"> 
<span style="color:#9DAAAA">Posts:</span><span style="float:right;color: #9DAAAA;"> {$fetch}/{$postgoal}</span>
</td>
</tr>
<tr>
 <td class="trow1"> 
<span style="color:#9DAAAA">Status:</span>
	 <if $newposts >= $mybb->settings['postgoal'] then><span style="color: #00BF00;float:right;">Reached</span><else> <span style="color: #e03131;float:right;">Not Reached</span></if>
	 
</td>
</tr>
<tr>
 <td class="trow1">
 <div id="prog-color" class="prog-bar-haxzz">
    <span id="prog-count" style="width: 0%"></span>
    <p id="prog-percent">0%</p>
</div>
</td> </tr> </td>
<script>
function setProgress(i){
	var y = Math.round( i );
	$('#prog-percent').html(y+'%');
	var red = 0, green = 0;
	if (i >= 80) {
        red = 255 - Math.round(((i - 80) / 20) * 255);
        green = 255;
    } else if (i >= 60) {
        red = 255;
        green = Math.round(((i - 60) /20) * 255);
    } else {
        red = 255;
        green = 0;
    }
	$('#prog-count').css('background', "rgb(" + red + "," + green + ",0)");
	if (i > 70){
		$('#prog-percent').css('color', '#000');
	} else {
		$('#prog-percent').css('color', '#fff');
	}
	$('#prog-count').width(i+'%');
}
(function() {
	var i = 0;
	var n = "{$newposts}";
	var o = parseInt(n.replace(',', ''));
	var p = {$mybb->settings['postgoal']};
	i = (o/p)*100;
	if (i > 100) i = 100;
	if (i < 0) i = 0;
	setProgress(i);
})();
	</script>


The goal looks fine but the status and progress bar do not work.

[Image: SoXdw6H.png]

if you see in the images the status says reached but the goal has not completed and the progress bar still on 0%


Any ideas that can help me? My page is https://downfull.net

Somebody can help me please?