MyBB Community Forums

Full Version: Prefix filter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
When there is no "prefix" available in the forum, the filter should be invisible.
(2021-02-05, 07:37 PM)Eldenroot Wrote: [ -> ]When there is no "prefix" available in the forum, the filter should be invisible.
thank you , Applies in the next version

-Template Added
- not display If not exist Prefix in forum Added
Are the templates cached? Also you should try version system for easier updating (notification). Thank you!

OK, it is not working - filter is displayed even when there are no prefixes in the forum...

And one more thing - you should display "prefix name" on mouse hover in title...
Dear Mostafa, if you're still in stage of developing and improvement of your plugin, please let me leave another inprovement to you for further updates...

Your current code runs SQL queries for threads in a while loop for each prefix. Depending on the count of prefixes, this may cause a lot of SQL statements.
When possible, prevent using SQL in loops. So please consider my suggestion to enhance your plugin in terms of performance and try this single SQL to query all prefixes in a threadlist:
SELECT p.pid AS p_pid, p.prefix AS p_prefix, p.displaystyle AS p_style
FROM ".TABLE_PREFIX."_threads t
INNER JOIN ".TABLE_PREFIX."_threadprefixes p ON p.pid = t.prefix
WHERE t.fid = {$fid} AND t.prefix != 0
GROUP BY t.prefix;

Cheers!
[ExiTuS]
There is no column named fid in the threadprefixes table .

(2021-02-06, 07:47 PM)Eldenroot Wrote: [ -> ]Are the templates cached? Also you should try version system for easier updating (notification). Thank you!

OK, it is not working - filter is displayed even when there are no prefixes in the forum...

And one more thing - you should display "prefix name" on mouse hover in title...

Plugin Updated and Release.
Better way it is get  prefises from cache

plugin generates a lot of queries
You dont need query to threads
use templace "cache"

$prefix_cache = build_prefixes();
$prefixes = array();

if(!empty($prefix_cache))
{
	foreach($prefix_cache as $prefix)
	{
		if($prefix['forums'] != "-1")
		{
			$forums = explode(",", $prefix['forums']);

			if(!in_array($fid, $forums))
			{
				continue;
			}
		}
		
		$prefixes[$prefix['pid']] = $prefix;
	}
}

if(!empty($prefixes))
{
	foreach($prefixes as $prefix)
	{
		// do what you need
	}	
}


edit

I looked deeper and I think fetching prefixes from the cache is not needed

Use only
build_prefixes();
yes ,I forgot to use it, thank you
I will wait for another release then Smile Thx!
Ready working very optimal code for you

$plugins->add_hook('forumdisplay_threadlist', 'PrefixFilter_forumdisplay_threadlist');
$plugins->add_hook('forumdisplay_thread_end', 'PrefixFilter_forumdisplay_thread_end');
$plugins->add_hook('global_start', 'PrefixFilter_global_start');
	
function PrefixFilter_forumdisplay_thread_end()
{
	global $threadprefix, $pr;
	
	if(!empty($threadprefix))
	{
		
		if(empty($pr[$threadprefix['pid']]))
		{
			$pr[$threadprefix['pid']] = array(
				"pid"					=> $threadprefix['pid'],
				"displaystyle"			=> $threadprefix['displaystyle'],
			);	
		}			
	}
}
	
function PrefixFilter_forumdisplay_threadlist()
{
	global $mybb, $fid, $prefixfilter, $pr, $templates;
	
	if(!empty($pr))
	{
		foreach($pr as $p)
		{
			$prefixes .="<a style=\"margin: 0 3px 0 4px;text-decoration: aliceblue;\" href=\"{$mybb->settings['bburl']}/forumdisplay.php?fid={$fid}&prefix={$p['pid']}\">{$p['displaystyle']}</a>";
		}
		
		if(!empty($prefixes))
		{
			eval("\$prefixfilter = \"".$templates->get("PrefixFilter")."\";");
		}
	}
}

function PrefixFilter_global_start()
{
	global $templatelist;
	
	if(in_array(THIS_SCRIPT, explode("," ,"forumdisplay.php")))
	{			
		if(isset($templatelist))
		{
			$templatelist .= ",";
		}
		
		$templatelist .= "PrefixFilter";
	}
}
(2021-02-07, 04:25 PM)Eldenroot Wrote: [ -> ]I will wait for another release then Smile Thx!

Read From build_prefixes function added.
Pages: 1 2 3 4