MangaD / mybb-thread-preview

A plugin for previewing MyBB forum threads on hovering over the subject.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incompatibility with Endless plugin

Eisteed opened this issue · comments

Hey, really cool plugin works great but is there any way of making this compatible with endless plugin ?
https://community.mybb.com/mods.php?action=view&pid=1439

I'm using it for an infinite scroll in threadlist, this is the SQL error I get when endless try to load the other threads when scrolling (line 100 in threadpreview.php) :

SQL Error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5
Query: SELECT t.tid, t.firstpost, p.message
			FROM mybb_threads t
			LEFT JOIN mybb_posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN()
Back Trace: #0  errorHandler-
Query: SELECT t.tid, t.firstpost, p.message
			FROM mybb_threads t
			LEFT JOIN mybb_posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN(), , 0) called at [public_html/inc/class_error.php:203]
#1  errorHandler-
			FROM mybb_threads t
			LEFT JOIN mybb_posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN())) called at [public_html/inc/db_mysqli.php:601]
#2  DB_MySQLi-
			FROM mybb_threads t
			LEFT JOIN mybb_posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN()) called at [public_html/inc/db_mysqli.php:337]
#3  DB_MySQLi-
			FROM mybb_threads t
			LEFT JOIN mybb_posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN()) called at [public_html/inc/plugins/threadpreview.php:100]
#4  threadpreview_preview() called at [public_html/inc/class_plugins.php:142]

Thanks

Hello, I am not familiar with the endless plugin and have no intention to support it. But as this project is open source, anyone is welcome to contribute.

Alright ;( I don't know much about mybb plugins dev but I will try to find a fix.

Okay easier than I thought, but I don't know if this is a proper way to do it. I added another function to threadpreview

function threadpreview_getPreview($thread)
{
	global $mybb, $db, $tids, $threadcache, $thread, $firstpostcache;
	$query = $db->query("SELECT t.tid, t.firstpost, p.message
			FROM " . TABLE_PREFIX . "threads t
			LEFT JOIN " . TABLE_PREFIX . "posts p
			ON(t.firstpost=p.pid)
			WHERE t.tid IN(" . $thread['tid'] . ")");
	while($data = $db->fetch_array($query))
	{
		$firstpostcache[$data['tid']] = replaceMedia($data['message']);
		//$firstpostcache[$data['tid']] = substr($data['message'], 0, (int)$mybb->settings['threadpreview_maxlength']);
		//$threadcache[$data['tid']]['preview'] = $data['message'];
	}

	// MangaD - parse mycode, smilies...
	global $parser;
	if(!$parser)
	{
		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser;
	}

	$parser_options = array(
		"allow_html" => (int)$mybb->settings['pmsallowhtml'],
		"allow_mycode" => (int)$mybb->settings['pmsallowmycode'],
		"allow_smilies" => (int)$mybb->settings['pmsallowsmilies'],
		"allow_imgcode" => (int)$mybb->settings['pmsallowimgcode'],
		"allow_videocode" => (int)$mybb->settings['pmsallowvideocode'],
		"nofollow_on" => 1,
		"filter_badwords" => 1
	);

	$thread['preview'] = $parser->parse_message($firstpostcache[$thread['tid']], $parser_options);
	$thread['preview'] = truncateHTML((int)$mybb->settings['threadpreview_maxlength'], $thread['preview']);
}

then inside endless I can call threadpreview_getPreview with the current $thread being created as argument.

The only problem I see is that there's a reference to the $thread global variable inside the function, that possibly conflicts with the argument.

Yea I wasn't sure about how to use those but it's working like that ^^
Removing $thread returns an empty $thread['preview']