XThreads
Author Message
My Spiel
XThreads is one of my larger plugins which I have been working on for a while.  Originally planned to release it inline with MyBB 1.6, but who knows when that'll be out.  It perhaps doesn't include everything I wanted it to, but does have most of the things (plus I want to move onto other projects).

What does it do?
Take a look at RateU's forum for some nice ideas of what it can do.  I also have some more basic examples here of what can be done with XThreads.  I'm pretty sure there are many other applications of this plugin, but those examples just give you some simple ideas.

The basic idea is giving you the ability to define custom fields for your threads, and providing methods to give you a lot of flexibility with customising forums.

Warning: I'm not going to bother with "beta" labels and so on.  I've done some testing on this myself, but it's by no means extensive.  Use this at your own risk.

Installation Instructions: standard installation procedures apply - you can find them in the announcement here.
You may need to CHMOD the uploads/xthreads_ul/ folder to 0777 after uploading the files (probably won't though).

Upgrade Instructions: unless stated otherwise, the general procedure for upgrades is to simply upload the new files, then visit your AdminCP.  In there, you'll be presented with a notice to run the upgrade - just follow what it says from there on.

Usage Instructions: this is a complex plugin, and unfortunately, you're probably going to have to figure this out yourself, depending on what you want to achieve with this plugin.  HTML and CSS knowledge is strongly recommended; you should also be familiar with MyBB's template system.  Some demonstrations can be found here - hopefully these will give you a good idea of how things work.  I suggest looking at the thread descriptions example, as this is fairly easy to understand (IMO).  If you can understand how everything works, there, perhaps try out the gallery example.

Known conflicting plugins
- MyPlaza Turbo -
If you are using MyPlaza Turbo, note that the author decided to use a particularly odd method to implement certain functionality, practically destroying compatibility with any plugin which hooks into the forum add/edit routines.  I've included a patch to address this issue - you need to replace inc/myplaza/myplaza_admin_plugin.php with the following file (it's unlikely that this will be committed as the author has decided to discontinue development)

.php  myplaza_admin_plugin.php (Size: 56.27 KB / Downloads: 2312)

- PL9 Forum Icons -
Affects certain functionality.  See here for a solution.

- PHP in Templates, v1.4 or older -
Similar to PL9 Forum Icons - solution is just to update to the latest version.

- MyAdvertisements - (update: older versions only, later versions may not conflict)
Affects some thread functionality, see here for a solution.

- Group Post CSS -
See here http://mybbhacks.zingaburga.com/showthre...http://mybbhacks.zingaburga.com/showthread.php?tid=378&pid=59

All bug reports, suggestions, criticisms are appreciated (though I may not always implement suggestions) so please feel free to post them.
If you find this plugin useful, I would be grateful if you could give some token of appreciation for the work that has gone into this, and perhaps post some example usages you've come up with in the XThreads forum to help others get an idea of what can be achieve with this plugin (and for my own interest's sake Tongue).


Github: https://github.com/zingaburga/XThreads-MyBB-Plugin
Note: do NOT use the Github version, unless you know what you're doing
Changelogs: v1.10, v1.20, v1.21, v1.22, v1.23, v1.24, v1.25, v1.26, v1.27, v1.30, v1.31, v1.32, v1.337, v1.40, v1.41, v1.42, v1.43, v1.44, v1.45, v1.46, v1.47, v1.50, v1.51, v1.52, v1.53, v1.60, v1.61, v1.62, v1.63, v1.64, v1.65, v1.66, v1.67, v1.68
(This post was last modified: 12-25-2015 12:46 PM by ZiNgA BuRgA.)
Find all posts by this user
Quote this message in a reply
Download: xthreads-1.68.7z (114.53 KB)
Plugin Version: 1.68
Last Updated: 12-25-2015, 12:46 PM

Downloads: 8,337
MyBB Compatibility: 1.4.x, 1.6.x, 1.8.x
Plugin License: GPLv3
Uploader: ZiNgA BuRgA
Torengo Offline
Junior Member
**
Posts: 1
Joined: Mar 2011
Post: #331
RE: XThreads
Thanks you much for X-Threads! Top quality plugin!
03-17-2011 01:43 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #332
RE: XThreads
(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?

03-18-2011 04:29 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #333
RE: XThreads
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 />
(This post was last modified: 03-20-2011 01:36 AM by Pirata Nervo.)
03-19-2011 10:33 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #334
RE: XThreads
(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.

My Blog
03-20-2011 08:54 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #335
RE: XThreads
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:
1
2
3
4
5
6
7
		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;

03-24-2011 02:35 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #336
RE: XThreads
aid is the primary key of the table, in other words, guaranteed to be unique, so it won't overwrite.

My Blog
03-24-2011 08:45 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #337
RE: XThreads
(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.
03-24-2011 08:55 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #338
RE: XThreads
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?

My Blog
(This post was last modified: 03-24-2011 09:37 AM by ZiNgA BuRgA.)
03-24-2011 09:34 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #339
RE: XThreads
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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.

03-25-2011 09:21 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #340
RE: XThreads
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);


My Blog
03-25-2011 02:17 PM
Find all posts by this user Quote this message in a reply


Forum Jump: