clickable post icons - trying to get custom template to work.
#1
I am working on plugin for clickable post icons.   I  have icons in both places.  
the plugin make custom template.     

I am trying to have plugin use custom template instead of the default one.     

I copied the get_post_icons() function from functions.php
and changed the template to my custom one. 

look here:

http://elymbmx.com/mybb/newthread.php?fid=2


My plugin code here:   

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


/**
 * Clickable Post Icons like Smilies
 */

// 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.");
}

// Neat trick for caching our custom template(s)
if(defined('THIS_SCRIPT'))
{

	if(THIS_SCRIPT == 'newthread.php')
	{
		global $templatelist;
		if(isset($templatelist))
		{
			$templatelist .= ',';
		}
		$templatelist .= 'clickableposticons';
	}
	
	if(THIS_SCRIPT == 'newreply.php')
	{
		global $templatelist;
		if(isset($templatelist))
		{
			$templatelist .= ',';
		}
		$templatelist .= 'clickableposticons';
	}
	
	if(THIS_SCRIPT == 'editpost.php')
	{
		global $templatelist;
		if(isset($templatelist))
		{
			$templatelist .= ',';
		}
		$templatelist .= 'clickableposticons';
	}

	if(THIS_SCRIPT == 'private.php')
	{
		global $templatelist;
		if(isset($templatelist))
		{
			$templatelist .= ',';
		}
		$templatelist .= 'clickableposticons';
	}

}


$plugins->add_hook("admin_config_post_icons_add_multiple", "clickableposticons_lowercase");
//$plugins->add_hook("pre_output_page", "clickableposticons_get");
$plugins->add_hook('editpost_action_start', 'clickableposticons_run');
$plugins->add_hook('newreply_start', 'clickableposticons_run');
$plugins->add_hook('newthread_start', 'clickableposticons_run');
$plugins->add_hook('private_send_start', 'clickableposticons_run');


function clickableposticons_info()
{
	return array(
		"name"				=> "Clickable Post Icons like Smilies",
		"description"		=> "Clickable Post Icons like Smilies",
		"website"			=> "",
		"author"			=> "ELY M.",
		"authorsite"		=> "",
		"version"			=> "1.0.4",
		"compatibility" => "*"
		);
}

function clickableposticons_activate()
{
	

	global $db;
	
	$insert_array = array(
		'title'		=> 'clickableposticons',
		'template'	=> $db->escape_string('<label class="posticons_label"><input type="radio" name="icon" value="{$dbicon[\'iid\']}"{$checked} /> <img src="{$dbicon[\'path\']}" alt="{$dbicon[\'name\']}" title="{$dbicon[\'name\']}" class="smilie smilie_{$dbicon[\'iid\']}{$extra_class}" onclick="MyBBEditor.insertText(\'{$dbicon[\'name\']}\');" /></label>'),
		'sid'		=> '-1',
		'version'	=> '',
		'dateline'	=> TIME_NOW
	);
	$db->insert_query("templates", $insert_array);	



/*
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets(
    'posticons_icon',
    '/(.*)$/',
    '<label class="posticons_label"><input type="radio" name="icon" value="{$dbicon[\'iid\']}"{$checked} /> <img src="{$dbicon[\'path\']}" alt="{$dbicon[\'name\']}" title="{$dbicon[\'name\']}" class="smilie smilie_{$dbicon[\'iid\']}{$extra_class}" onclick="MyBBEditor.insertText(\'{$dbicon[\'name\']}\');" /></label>'
);
*/
	
}


function clickableposticons_deactivate()
{
	
	global $db;
	$db->delete_query("templates", "title IN('clickableposticons')");
	///require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	
	

}


function clickableposticons_lowercase() {

require_once MYBB_ROOT."/inc/class_datacache.php";
require_once MYBB_ROOT."/inc/class_plugins.php";
global $mybb, $lang, $db, $config, $cache, $plugins, $page, $form_container, $form, $icon;


	if($mybb->request_method == "post")
	{
		if($mybb->input['step'] == 1)
		{
			if(!trim($mybb->input['pathfolder']))
			{
				$errors[] = $lang->error_missing_path_multiple;
			}

			$path = $mybb->input['pathfolder'];
			$dir = @opendir(MYBB_ROOT.$path);
			if(!$dir)
			{
				$errors[] = $lang->error_invalid_path;
			}

			if(substr($path, -1, 1) !== "/")
			{
				$path .= "/";
			}

			$query = $db->simple_select("icons");
			while($icon = $db->fetch_array($query))
			{
				$aicons[$icon['path']] = 1;
			}

			while($file = readdir($dir))
			{
				if($file != ".." && $file != ".")
				{
					$ext = get_extension($file);
					if($ext == "gif" || $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "bmp")
					{
						if(!$aicons[$path.$file])
						{
							$icons[] = $file;
						}
					}
				}
			}
			closedir($dir);

			if(count($icons) == 0)
			{
				$errors[] = $lang->error_no_images;
			}

			if(!$errors)
			{
				// We have no errors so let's proceed!
				$page->add_breadcrumb_item($lang->add_multiple_post_icons);
				$page->output_header($lang->post_icons." - ".$lang->add_multiple_post_icons);

				$sub_tabs['manage_icons'] = array(
					'title'	=> $lang->manage_post_icons,
					'link' => "index.php?module=config-post_icons"
				);

				$sub_tabs['add_icon'] = array(
					'title'	=> $lang->add_post_icon,
					'link' => "index.php?module=config-post_icons&amp;action=add"
				);

				$sub_tabs['add_multiple'] = array(
					'title' => $lang->add_multiple_post_icons,
					'link' => "index.php?module=config-post_icons&amp;action=add_multiple",
					'description' => $lang->add_multiple_post_icons_desc
				);

				$page->output_nav_tabs($sub_tabs, 'add_multiple');

				$form = new Form("index.php?module=config-post_icons&amp;action=add_multiple", "post", "add_multiple");
				echo $form->generate_hidden_field("step", "2");
				echo $form->generate_hidden_field("pathfolder", $path);

				$form_container = new FormContainer($lang->add_multiple_post_icons);
				$form_container->output_row_header($lang->image, array("class" => "align_center", 'width' => '10%'));
				$form_container->output_row_header($lang->name);
				$form_container->output_row_header($lang->add, array("class" => "align_center", 'width' => '5%'));

				foreach($icons as $key => $file)
				{
					$ext = get_extension($file);
					$find = str_replace(".".$ext, "", $file);
					$name = ":".$find.":";  //add : around filename for clickable post icons :)

					$form_container->output_cell("<img src=\"../".$path.$file."\" alt=\"\" /><br /><small>{$file}</small>", array("class" => "align_center", "width" => 1));
					$form_container->output_cell($form->generate_text_box("name[{$file}]", $name, array('id' => 'name', 'style' => 'width: 98%')));
					$form_container->output_cell($form->generate_check_box("include[{$file}]", 1, "", array('checked' => 1)), array("class" => "align_center"));
					$form_container->construct_row();
				}

				if($form_container->num_rows() == 0)
				{
					flash_message($lang->error_no_images, 'error');
					admin_redirect("index.php?module=config-post_icons&action=add_multiple");
				}

				$form_container->end();

				$buttons[] = $form->generate_submit_button($lang->save_post_icons);
				$form->output_submit_wrapper($buttons);

				$form->end();

				$page->output_footer();
				exit;
			}
		}
		else
		{
			$path = $mybb->input['pathfolder'];
			reset($mybb->input['include']);
			$name = $mybb->input['name'];

			if(empty($mybb->input['include']))
			{
				flash_message($lang->error_none_included, 'error');
				admin_redirect("index.php?module=config-post_icons&action=add_multiple");
			}

			foreach($mybb->input['include'] as $image => $insert)
			{
				if($insert)
				{
					$new_icon = array(
						'name' => $db->escape_string($name[$image]),
						'path' => $db->escape_string($path.$image)
					);

					$db->insert_query("icons", $new_icon);
				}
			}

			$cache->update_posticons();

			$plugins->run_hooks("admin_config_post_icons_add_multiple_commit");

			// Log admin action
			log_admin_action();

			flash_message($lang->success_post_icons_added, 'success');
			admin_redirect("index.php?module=config-post_icons");
		}
	}



}

                     

function clickableposticons_run()
{
	//global $mybb, $cache, $icon, $theme, $templates, $lang, $posticons;
	
	//global $templates, $posticons;
	//$posticons = clickableposticons_get();

	//global $mybb, $cache, $icon, $theme, $templates, $lang;
	global $mybb, $cache, $icon, $theme, $templates, $lang, $icon, $iconlist, $dbicon, $no_icons_checked, $checked, $posticons_cache, $posticon, $posticons;
	
    
	//eval("\$posticons = \"".$templates->get("clickableposticons")."\";");
	
	
	//eval("\$posticons = \"".$templates->get('clickableposticons')."\";");
	
	
	//eval("\$posticons = \"".$templates->get("clickableposticons")."\";");
	
	echo "<font size=20>TEST!!!!!!!!!!</font>";
	
	
	///$posticons = "<font size=20>FUCK!!!!!!!!!!</font>";
	
	///clickableposticons_get();


	
	
	$posticons = clickableposticons_get();
	

	
	
	
}





function clickableposticons_get()
{
	
	global $mybb, $cache, $icon, $theme, $templates, $lang;
	///global $mybb, $cache, $icon, $theme, $templates, $lang, $icon, $iconlist, $dbicon, $no_icons_checked, $checked, $posticons_cache, $posticon, $posticons;
	
	
	require_once MYBB_ROOT."/inc/functions.php";
	
	echo "<font size=20>RAN!!!!!!!!!!</font>";


	if(isset($mybb->input['icon']))
	{
		$icon = $mybb->get_input('icon');
	}

	$iconlist = '';
	$no_icons_checked = " checked=\"checked\"";
	// read post icons from cache, and sort them accordingly
	$posticons_cache = (array)$cache->read("posticons");
	$posticons = array();
	foreach($posticons_cache as $posticon)
	{
		$posticons[$posticon['name']] = $posticon;
	}
	krsort($posticons);

	foreach($posticons as $dbicon)
	{
		$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
		$dbicon['path'] = htmlspecialchars_uni($mybb->get_asset_url($dbicon['path']));
		$dbicon['name'] = htmlspecialchars_uni($dbicon['name']);

		if($icon == $dbicon['iid'])
		{
			$checked = " checked=\"checked\"";
			$no_icons_checked = '';
		}
		else
		{
			$checked = '';
		}

		eval("\$iconlist .= \"".$templates->get("posticons_icon")."\";");
	}

	if(!empty($iconlist))
	{
		eval("\$posticons = \"".$templates->get("clickableposticons")."\";");
	}
	else
	{
		$posticons = '';
	}

	return $posticons;

}




?>

I fixed the newthread so you do not have to register on my forums.

I got it working!!!! Thank you for reading this....

the mistake was swapped templates. now i have it working Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)