MyBB Hacks

Full Version: XThreads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thanks you much for X-Threads! Top quality plugin!
(03-17-2011 11:21 AM)jim7777 Wrote: [ -> ]but i dunno why but when a new thread reply is added, the sort options is being disregarded.. as seen on my forum where 3-08-11 comes first before 3-12-11 then 2-24-11 .. the first date (3-08-11) contains a new reply

it is arrange on how the new replies are posted Frown is that a bug?

What is the setting in the [Default Sort By:] setting for that forum?
I've got one question regarding text areas. (multi line text boxes)
Does \r\n or \r get replaced with \n anywhere before the value is stored in the database?
Edit:
Nevermind, after looking closely at XThreads, it seems that all fields get sanitized using xthreads_sanitize_disp(...) which will call xthreads_sanitize_disp_field(...) and then xthreads_sanitize_disp_string(...) which calls the parser which will convert new lines to <br />
(03-19-2011 10:33 PM)Pirata Nervo Wrote: [ -> ]I've got one question regarding text areas. (multi line text boxes)
Does \r\n or \r get replaced with \n anywhere before the value is stored in the database?
From memory, not for the multiline textbox, but for some things, it will strip out \r's.
inc/plugins/xthreads.php

Function xthreads_get_xta_cache(&$tf, &$tids, $posthash='')

What's the point in accepting a list of tids if (when more than one are provided) it just puts the last one in the array, overriding the others?

PHP Code:
		if($posthash)
			$where = 'posthash="'.$db->escape_string($posthash).'"';
		else
			$where = 'tid IN ('.$tids.')';
		$query = $db->simple_select('xtattachments', '*', $where);
		while($xta = $db->fetch_array($query))
			$xta_cache[$xta['aid']] = $xta;

aid is the primary key of the table, in other words, guaranteed to be unique, so it won't overwrite.
(03-24-2011 08:45 AM)ZiNgA BuRgA Wrote: [ -> ]aid is the primary key of the table, in other words, guaranteed to be unique, so it won't overwrite.

The problem, it's overriding. I can assure you the three thread id's provided in $tids as 1,5,7 are unique (they're 1,5,7..).

I'm kinda lost because it's only getting one attachment when the three threads have different attachments.
And what is returned when you query the DB directly?  Do you get 3 rows if you do a "tid IN (1,5,7)"?
EDIT: are you modifying the $xta_cache yourself, at all?
Two rows are displayed when I run:

Code:
SELECT * FROM d1_xtattachments WHERE tid IN (6,7)

6 and 7 are the real thread IDs.

In case you want to look at my code, here it is: (the following function hooks into showthread_start, after XThreads is run)

PHP Code:
function lookssystem_showthread()
{
	global $db, $fid, $mybb, $thread;
	
	$fid = (int)$fid;
	
	if ($fid != $mybb->settings['mydefined_fid'])
		return;
	
	// Get latest looks by us, we're actually getting the latest threads in this forum.
	$latest_looks = '<table border="0">';
	
	$ts = array();
	$q = $db->simple_select('threads', 'tid', 'fid='.$fid.' AND uid='.$thread['uid'], array('order_by' => 'dateline,tid', 'order_dir' => 'desc', 'limit' => '4'));
	while ($t = $db->fetch_field($q, 'tid'))
		$ts[] = $t;
		
	if (empty($ts))
	{
		$latest_looks .= '<tr><td>{$lang->lookssystem_no_looks}</td></tr>';
	}
	else {
	
		global $threadfield_cache;
		
		// Based on XThread's show thread code
		$threadfields = array();
		
		if(!isset($threadfield_cache))
			$threadfield_cache = xthreads_gettfcache($fid);
		
		if(!empty($threadfield_cache))
		{
			// just do an extra query to grab the threadfields
			$threadfields = $db->fetch_array($db->simple_select('threadfields_data', '`'.implode('`,`', array_keys($threadfield_cache)).'`', 'tid IN (\''.implode('\',\'', $ts).'\')'));
			if(!isset($threadfields)) $threadfields = array();
		}
		
		$threadids = $db->escape_string(implode(',', $ts));
		
		//die($threadids); // if uncommented it displays 6,7 as I mentioned above
		
		$threads = array();
		
		if (!empty($threadfield_cache))
		{
			foreach($threadfield_cache as $k => &$v) {
				xthreads_get_xta_cache($v, $threadids);
				global $xta_cache;
				//die(print_r($xta_cache)." ".$threadids." ".print_r($v)); // if uncommented, it displays the array containing one element only, the latest one (from tid = 7, the one from tid 6 does not appear here)
				
				xthreads_sanitize_disp($threadfields[$k], $v, $thread['username']);
				
				$str .= "<br />".$GLOBALS['threadfields']['looks_image']['url'];
				
				$threads[] = $threadfields[$k];
			}
			
			//die($str); // if uncommented, only one attachment is displayed here - which is the latest one, from tid 7 and not the one from tid 6
		}
		else
			$latest_looks .= '<tr><td>{$lang->lookssystem_no_looks}</td></tr>';
	}
	
	$latest_looks .= '</table>';
}


I think I'm doing it correctly, but probably not.

A little unrelated perhaps, but some things about your code:

PHP Code:
			$threadfields = $db->fetch_array($db->simple_select('threadfields_data', '`'.implode('`,`', array_keys($threadfield_cache)).'`', 'tid IN (\''.implode('\',\'', $ts).'\')'));
			if(!isset($threadfields)) $threadfields = array();

This will only grab one thread's thread fields.  The code I used for showthread_start hook assumes one result, since there's only one thread being displayed.  You cannot make the same assumption here.

PHP Code:
$threadids = $db->escape_string(implode(',', $ts));

I don't know why you're using escape string here.

PHP Code:
				xthreads_sanitize_disp($threadfields[$k], $v, $thread['username']);
				
				$str .= "<br />".$GLOBALS['threadfields']['looks_image']['url'];

$threadfields isn't global'd - the second line won't get anything.

As for your issue, I'm guessing that xthreads_get_xta_cache has already run before your function does.  Note that xthreads_get_xta_cache forces a one-call-per-page policy (see the static $done_attach_dl_count variable in the function), so if it already has been called by xthreads_showthread, it will ignore your code.
You'll need to either get your function to be called before xthreads_showthread is called (and hope that it doesn't affect xthreads_showthread in any way) or manually pull the attachments across.
I'll admit that it isn't a tidy function, but then again, it isn't really meant to be used by others.  I only made it to save myself some typing with various checks etc.  Manually pulling xtattachment info isn't very difficult.

PHP Code:
$query = $db->simple_select('xtattachments', '*', 'tid IN (1 to a million)');
while($xta = $db->fetch_array($query))
	$xta_cache[$xta['aid']] = $xta;
$db->free_result($query);

Reference URL's