MyBB Community Forums

Full Version: [WIP] Post Icons on index plugin - not working right.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im trying to get my plugin to work.


<?php
/**
 * MyBB 1.4 Post Icons on index in lastpost Plugin
 * by ELY M.
 *
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}


$plugins->add_hook("build_forumbits_forum", "posticonsonindex_start");

/*
//Thanks to Demonic for this function
//http://community.mybboard.net/thread-39634.html
function posticonsonindex_uninstalltemplates($title,$find,$replace) {
  global $db;
  $title = $db->escape_string( $title );
  $query = $db->simple_select("templates", "*", "title='$title' AND sid='-2'");
  if( $db->num_rows( $query ) > 0 ) {
    $rows = $db->fetch_array( $query );
    $temp = str_replace($find,$replace, $rows['template']);
    $updatetemp = array("template" => $db->escape_string($temp), "dateline" => TIME_NOW);
    $db->update_query("templates", $updatetemp, "title='$title'");
  }
}
*/
    
function posticonsonindex_info()
{
	
	return array(
		"name" => "Post icons on index in the last post",
		"description" => "Post icons on index in the last post next to thread subject",
		"website" => "",
		"author" => "ELY M.",
		"authorsite" => "",
		"version" => "1.0.1",
		"guid" => "",
		"compatibility" => "14*"
	);
}

/*
function posticonsonindex_activate()
{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
  //find_replace_templatesets("nav_sep", "#/#i", "&raquo;");
  //find_replace_templatesets("nav_sep_active", "#/#i", "<br><img src=images/nav_bit.gif>");
}

function posticonsonindex_deactivate()
{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	//replace_temp_set("nav_sep", "#".preg_quote("&raquo;")."#i", "/");
	//replace_temp_set("nav_sep_active", "#".preg_quote("<br><img src=images/nav_bit.gif>")."#i", "/");

}
*/


function posticonsonindex_start() {

global $fcache, $cache, $moderatorcache, $forumpermissions, $theme, $mybb, $templates, $bgcolor, $collapsed, $lang, $showdepth, $plugins, $parser, $forum_viewers;

// GET THREAD ICON
$lastpost_icon = "";
$thread = get_thread($lastpost_data['lastposttid']);
$icon_cache = $cache->read("posticons");
if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
{
  $icon = $icon_cache[$thread['icon']];
  $lastpost_icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />&nbsp;";
}

}

?>


I already have {$lastpost_icon} in my template forumbit_depth2_forum_lastpost

to test and try to get this plugin to work.
you need to manually add {$lastpost_icon} into forumbit_depth2_forum_lastpost template

any help would be appreciated.

this is original mod that I'm trying to convert to a plugin.
http://community.mybboard.net/thread-32146.html
credit to LeX- for original mod.
Did you add the eval() code so it recognizes the $lastpost_icon?
I don't add eval()
(2009-02-10, 05:54 PM)ELY_M Wrote: [ -> ]I don't add eval()
I'm not sure how to do it, or if it's even neccesary; but I think it is.
Be aware of the scope of your variables. $lastpost_icon in your function only has local scope, thus once your plugin finishes running, $lastpost_icon no longer has any meaning.
A quick fix may be to use the passed $forum variable - you'll need to change your function definition to:
function posticonsonindex_start(&$forum) {
Then use $forum['lastpost_icon'] instead of your variable (and put it in the template).

There's actually a few other issues with your code, but I'll let you figure it out Toungue
why do get_thread dont return anything.
I think the issue is this line

$thread = get_thread($lastpost_data['lastposttid']);


function posticonsonindex_start() {

global $fcache, $cache, $moderatorcache, $forumpermissions, $theme, $mybb, $templates, $bgcolor, $collapsed, $lang, $showdepth, $plugins, $parser, $forum_viewers;
//global $cache;
require_once MYBB_ROOT."/inc/functions.php";

          // GET THREAD ICON
          $lastpost_icon = "no...";
          //$forum['lastpost_icon'] = "null...";

          $thread = get_thread($lastpost_data['lastposttid']);
          //eval("\$thread = get_thread(\$lastpost_data['lastposttid']);");

          $icon_cache = $cache->read("posticons");
          //eval("\$icon_cache = \$cache->read(\"posticons\");");
          
          if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
          {
          $icon = $icon_cache[$thread['icon']];
          //eval("\$icon = \"".$icon_cache[$thread['icon']]."\";");
          $lastpost_icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />&nbsp;";
          //$forum['lastpost_icon'] = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />&nbsp;";

          }



///eval("\$lastpost_icon = \"".$templates->get("forumbit_depth2_forum_lastpost")."\";");

//eval("\$lastpost_icon = \"".$templates->get("forumbit_depth2_forum_lastpost")."\";");
echo "testing: thread: ".$thread." iconcache: ".$icon_cache." icon: ".$icon." lastpost_icon:".$lastpost_icon."forum lastpost_icon: ".$forum['lastpost_icon']."<br>";
echo "get_thread: ".get_thread($lastpost_data['lastposttid']);
echo "<hr>";



}


here is original mod Im trying to convert to a plugin.
http://community.mybboard.net/thread-32146.html
Yes, $lastpost_data has no meaning in your function - for one, it's a local variable in the function build_forumbits which means it's impossible to reference outside of that function, and secondly, it's assigned after the hook is executed.
For this case, try using $forum['lastposttid'], after accepting $forum as a passed argument.
its working now Big Grin

Thanks to Yumi Big Grin
There is issues with seeing subforum post icons.

http://ftmtalk.com/index.php

you cant see post icons from index from thread in subforums.
you would have to click on forums "UFO MotherShip" to see post icon in subforum.
I just tested more and I see that it is picking up posticons from threads that are posted under "UFO MotherShip"
I posted a thread under UFO subforums and go back to index. I see wrong posticon now. I should have alien icon for latest thread instead of the smile with hair.