MyBB Community Forums

Full Version: Where do I tell my skins to read variable in the header template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So I've edited a plugin I have and am having trouble getting the variable to display. * The PHP file is correct. I duplicated from another plugin I have running so everything is EXACTLY the same except for the variable name.


The original plugin inserts {$thing} into the index template.
I've edited it to insert {$thing} into the header template.

This worked before, but there was an additional step - something where I had to find another file and tell my skins or something to read the variable since it was no longer in the index template...

Any help?
in the plugin file there should be some hook code to get it work on the index
$plugins->add_hook("index_start", "abcdef_ghij");
that needs to be changed so that plugin works globally (on the header of every page)
$plugins->add_hook("global_start", "abcdef_ghij");

see plugin hooks documentation
Thanks so much. That worked!

... This is from the same plugin. I'm trying to get it to display according to the newest post but I can't remember the field name for the latest-post date. Any help/suggest? Here's the code part I'm working with below.

       //Run the query to get the most recent posts along with their posters, time and forums
		
	   $query = $db->query("
	   SELECT t.tid, t.fid, t.subject, t.lastpost, 
	   t.lastposter, t.lastposteruid, f.name,
	   u.usergroup, u.displaygroup, p.message, p.tid
	   FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
	   ON (f.fid = t.fid)
       INNER JOIN ".TABLE_PREFIX. "posts as p
	   ON (t.tid = p.tid)
	   LEFT JOIN " . TABLE_PREFIX . "users AS u 
	   ON (t.lastposteruid = u.uid)
	   {$fids}
	   AND t.visible = '1'
	   GROUP BY t.tid
	   ORDER BY t.tid DESC 
	   LIMIT " . $mybb->settings['limit_posts_nr']);
^ latest post date comes from t.lastpost from the above query
That's a lot!

It didn't seem to have the desired affect though (my fault though). I'm trying to get it to display the newest post but for some reason it keeps displaying the first post in the thread. I tried switching "DESC" for "ASC" with no luck...
^ have you tried changing ORDER BY t.tid DESC with ORDER BY t.lastpost DESC
Yes. Smile That's why I needed the name for t.lastpost.
^ you can remove GROUP BY t.tid and check the result
No luck... Here's the entire code (fairly short)... It's a recentposts code but I've modified it to make an announcement system on my forum (because I want announcements that mods can use without accessing the admin panel)...

<?php

//Latest Posts Board Index Mod by Borbole

//Trying to access directly the file, are we :D

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

//Hooking into index_start with our function
$plugins->add_hook("global_start", "recentposts_box");


//Show some info about our mod
function recentpostsindex_info()
{
	return array(
		"name"			=> "Recent Posts Forum Index",
		"description"	=> "It shows the recent posts on your board index.",
		"website"		=> "http://www.forumservices.eu/mybb",
		"version"		=> "1.0",
		"author"		=> "borbole",
		"authorsite"	=> "http://www.forumservices.eu/mybb",
		"compatibility"  => "16*",
		'guid'        => 'f8cd8d11a353a4f58a29fbc0d72ec9c3'
	);
}

//Activate it
function recentpostsindex_activate()
{
	global $db;
	
	//Insert the mod settings in the forumhome settinggroup. It looks beter there :D
	
	$query = $db->simple_select("settinggroups", "gid", "name='forumhome'");
	$gid = $db->fetch_field($query, "gid");
	
	
	$setting = array(
		'name' => 'enable',
		'title' => 'Recent Posts Forum Index',
		'description' => 'Would you like to display the Recent Posts Box at your board index?',
		'optionscode' => 'yesno',
		'value' => '1',
		'disporder' => '90',
		'gid' => intval($gid)
	);
	$db->insert_query('settings',$setting);
	
	$setting = array(
		"name" => "limit_posts_nr",
		"title" => "Recent Posts!",
		"description" => "2",
		"optionscode" => "text",
		"value" => "1",
		"disporder" => "91",
		"gid" => intval($gid),
		);
	$db->insert_query("settings", $setting);	
	
	rebuild_settings();
	
   //Add our custom var in the header template to display the latest posts box
   require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

   find_replace_templatesets("header", "#".preg_quote('{$welcomeblock}') . "#i", '{$welcomeblock}' . "\n" . '{$recentposts}');

}


//Don't want to use it anymore? Let 's deactivate it then and drop the settings and the custom var as well

function recentpostsindex_deactivate()
{
	global $db;
	
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='enable'");	
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='limit_posts_nr'");

rebuild_settings();	
	
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

find_replace_templatesets("header", "#".preg_quote('{$welcomeblock}' . "\n" . '{$recentposts}') . "#i", '{$welcomeblock}',0);

}


//Insert our function 
function recentposts_box()
{
	global $db, $mybb, $lang, $theme, $recentposts;
	
	//Enable it
    if($mybb->settings['enable'] == 1 )
	{
	    //Load the language files and set up the table for the recent posts box
	    $lang->load('recentpostsindex');

	    $recentposts .= '
	
    
           ';

	    //Get threads from specific forum
		
		$fids = "";
        $unviewablefids = get_unviewable_forums();
		
        if($unviewablefids)
        {
            $fids = "WHERE t.fid = 40 AND t.tid = 49";
        }
        
		//Get threads from specific forum
		
		$inactivefids = get_inactive_forums();
	    if ($inactivefids)
		{
		    $fids .= " WHERE t.fid = 40 AND t.tid = 49)";
	    }		
		
		
        //Run the query to get the most recent posts along with their posters, time and forums
		
	   $query = $db->query("
	   SELECT t.tid, t.fid, t.subject, t.lastpost, 
	   t.lastposter, t.lastposteruid, f.name,
	   u.usergroup, u.displaygroup, p.message, p.tid
	   FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
	   ON (f.fid = t.fid)
       INNER JOIN ".TABLE_PREFIX. "posts as p
	   ON (t.tid = p.tid)
	   LEFT JOIN " . TABLE_PREFIX . "users AS u 
	   ON (t.lastposteruid = u.uid)
	   {$fids}
	   AND t.visible = '1'
	   ORDER BY t.lastpost ASC
	   LIMIT " . $mybb->settings['limit_posts_nr']);
	
	    while($row = $db->fetch_array($query))
	    {
		   $recentposts .= '
		   ';
		   
		   //Trim the thread titles if they are over 49 characters
		   
		   $subject = htmlspecialchars_uni($row['subject']);
		   
		   if (strlen($subject) > 49)
		   {
	          $subject = substr($subject, 0, 49) . "..."; 
		   }
		   
		   //Trim the usernames if they are over 12 characters
		   
		   if (strlen($row['lastposter']) > 12)
		   {
	          $row['lastposter'] = substr($row['lastposter'], 0, 12) . "..."; 
		   }
		   
		    //Trim the forum names if they are over 19 characters so everything will be in porpotion
		   if (strlen($row['name']) > 19)
		   {
	          $row['name'] = substr($row['name'], 0, 19) . "..."; 
		   }
		   
		   //Get the date and time of the most recent posts
		   
		   $lastpostdate = my_date($mybb->settings['dateformat'], $row['lastpost']);
		   $lastposttime = my_date($mybb->settings['timeformat'], $row['lastpost']);
		   
		   //Get the usernames and make them pretty too with the group styling
		   
		   $username = build_profile_link(format_name($row['lastposter'],$row['usergroup'],$row['displaygroup']), $row['lastposteruid']);
		   
		   //Display them all trimmed up and pretty :D
		   
		   $recentposts .= '
		   
		      <div class=announce><a href="showthread.php?tid=' . $row['tid'] . '&amp;action=lastpost">' . $subject .'</a></div><br>
 ' . $row['message'] . '


		



';
	    }
          
		  //End of mod. I hope you enjoy it as much as I did coding it :)
		  
          $recentposts .= "";

   }

}

?>
^ ORDER BY t.lastpost DESC is working for me
Pages: 1 2