MyBB Hacks

Full Version: XThreads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thanks, Yumi Smile
I just got an idea for XThreads. It kind of came about when I was making an extra thread field. I'm not sure if it's already possible or if it might seem like a silly idea but how about thread field-dependent thread fields? Like... thread fields that would appear when certain options from other thread fields are selected. Tongue

Edit (1/1/11 @ 4:11pm est): I forgot to say this but I wish I had known a bit about XThreads sooner. This can do everything I really wanted to do with a forum and then some. Brilliant plug-in.

Edit 2 (4:17pm est): I just got another idea which is sort of based on a vBulletin plugin I used to use for a vB forum. Would it be possible to tag selected threads with thread field options via Inline Moderation?
(01-02-2011 06:41 AM)PK8 Wrote: [ -> ]I just got an idea for XThreads. It kind of came about when I was making an extra thread field. I'm not sure if it's already possible or if it might seem like a silly idea but how about thread field-dependent thread fields? Like... thread fields that would appear when certain options from other thread fields are selected. Tongue...

Nice idea for the main plugin PK8, I agree that feature would be great.
You could also do it now with the "template conditionals/ php in templates" plugin and some if statements.*

*This idea (above) would usually require refreshing the page, when certain option are selected; Dynamic "Ajax thread field-dependent thread fields" would be amazing**

**As long as your users have js enabled.
I have been continuing to work on my XThreads downloads stats, and I have this piece of code working(ish) in the xthreads_attach.php. It gives me the dls on date in a queryable table. I use that table to run queries for graphs using the open graphs API.

On each download click it writes to a table I made in phpmyadmin, and gives me daily stats on those threads where there has been a download on that day. However, I am struggling to put this into xthreads_attach.php as a plugin, rather than editing the core files, and wondered if Zinga (or anyone who knows ) could give me a tip on how to combine this into Xthreads?

At the moment I have my code as so:

PHP Code:
// connect to DB
	define('TABLE_PREFIX', $config['database']['table_prefix']);
	$db->connect($config['database']);
	$db->set_table_prefix(TABLE_PREFIX);
	$db->type = $config['database']['type'];
// Stuff added by me
	$result = mysql_query("SELECT tid , uid FROM mybb_xtattachments WHERE aid=".$aid);
	$attachment = mysql_fetch_assoc($result);
	$threadid = $attachment['tid'];
	$postuserid = $attachment['uid'];
//end of first bit of my stuff
	
	// so we do all the above just to run an update query :P

<-- my query goes here -->
}
	$db->write_query('UPDATE '.$db->table_prefix.'xtattachments SET downloads=downloads+1 WHERE aid='.intval($aid), 1);


	$db->close();
	unset($db, $GLOBALS['mybb']);
}


I would prefer to NOT have to change the XThreads files with core edits like this, but I don't know much about hooks.

Also, I am not sure if its my install, but in the xtattchments table in the db all the user ids are 0?

Hmm, I see this in uploads_php

Code:
// note, $uid is used purely for flood checking; not verification, identification or anything else
function &upload_xtattachment(&$attachment, &$tf, $uid, $update_attachment=0, $tid=0)


So I guess its not my install - I am on version 1.337 though. (Looks hopeful for 1.4)

(01-02-2011 06:41 AM)PK8 Wrote: [ -> ]I just got an idea for XThreads. It kind of came about when I was making an extra thread field. I'm not sure if it's already possible or if it might seem like a silly idea but how about thread field-dependent thread fields? Like... thread fields that would appear when certain options from other thread fields are selected. Tongue
Thanks for the idea - I think it's best to do with conditionals though.
Can put your own logic in templates for Javascript if you want it to work with the editor.

(01-02-2011 06:41 AM)PK8 Wrote: [ -> ]Edit 2 (4:17pm est): I just got another idea which is sort of based on a vBulletin plugin I used to use for a vB forum. Would it be possible to tag selected threads with thread field options via Inline Moderation?
Next version will allow modifying via custom moderator tools, so you could, theoretically, make a tool to do mass editing.  Unfortunately, this requires the admin to create a tool specific for the situation of course.

(01-02-2011 10:44 AM)leefish Wrote: [ -> ]I would prefer to NOT have to change the XThreads files with core edits like this, but I don't know much about hooks.
Unfortunately xthreads_attach.php doesn't have any hooks.  I might provide an option to enable them when I make a better plugin API for XThreads, but otherwise, xthreads_attach.php was designed to be as lightweight as possible, so it tries to avoid loading unnecessary stuff (including plugins).

So your only option is to stick with the code edit.  That section of code is unlikely going to change, so if you like using GNU diff/patch, that'll work too (if not, don't worry about it).

(01-02-2011 10:44 AM)leefish Wrote: [ -> ]Also, I am not sure if its my install, but in the xtattchments table in the db all the user ids are 0?
It's a known bug, which won't be there in v1.40.
If you want to patch it, just apply this one change to inc/xt_upload.php https://github.com/zingaburga/XThreads-M...https://github.com/zingaburga/XThreads-MyBB-Plugin/commit/90317bec0c0b8ad531603a668982a97cfde77
It doesn't actually really affect XThreads behavior much, but it might for other plugins that decide to rely on it.
You can try fixing existing data with the following query:

SQL Code
UPDATE mybb_xtattachments a INNER JOIN mybb_threads t ON a.tid=t.tid SET a.uid=t.uid WHERE a.uid=0 AND a.tid!=0

(01-04-2011 06:02 PM)ZiNgA BuRgA Wrote: [ -> ]
(01-02-2011 10:44 AM)leefish Wrote: [ -> ]I would prefer to NOT have to change the XThreads files with core edits like this, but I don't know much about hooks.
Unfortunately xthreads_attach.php doesn't have any hooks.  I might provide an option to enable them when I make a better plugin API for XThreads, but otherwise, xthreads_attach.php was designed to be as lightweight as possible, so it tries to avoid loading unnecessary stuff (including plugins).

So your only option is to stick with the code edit.  That section of code is unlikely going to change, so if you like using GNU diff/patch, that'll work too (if not, don't worry about it).

OK, I will keep the original on file, and when we get an upgrade swap it over, upgrade, and drop my code back in. Good to hear its not likely to change as I have spent a long time on this Smile

(01-04-2011 06:02 PM)ZiNgA BuRgA Wrote: [ -> ]
(01-02-2011 10:44 AM)leefish Wrote: [ -> ]Also, I am not sure if its my install, but in the xtattchments table in the db all the user ids are 0?
It's a known bug, which won't be there in v1.40.
If you want to patch it, just apply this one change to inc/xt_upload.php https://github.com/zingaburga/XThreads-M...https://github.com/zingaburga/XThreads-MyBB-Plugin/commit/90317bec0c0b8ad531603a668982a97cfde77
It doesn't actually really affect XThreads behavior much, but it might for other plugins that decide to rely on it.
You can try fixing existing data with the following query:

SQL Code
UPDATE mybb_xtattachments a INNER JOIN mybb_threads t ON a.tid=t.tid SET a.uid=t.uid WHERE a.uid=0 AND a.tid!=0


EXCELLENT. That worked perfectly, thank you Smile
I deployed the patch described above, but can you explain where to run the query?  I've run queries on my IPB software from inside the ACP, but I'm not sure how to do it on MyBB.  (I'm using cPanel if that matters)
Hi Rocketfoot, hopefully you have access to phpmyadmin. Go to the database in phpmyadmin, go to the xtattachments table. Export a copy of the table just in case...then, go to the SQL tab, clear any data in the tab and paste in the code from ZingaBurga. Hit go.
Thanks!  That seems to have done the trick!  I just never ran a query on My BB yet!  LOL...now I know! Biggrin
I don't why, but any changes that apply using Xthreads doesn't work on the selected forum. I reinstalled, reactivated plugin and it's same.
Reference URL's