MyBB Hacks

Full Version: Use custom thread field in a custom page MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I want to use custom thread field in a custom page MyBB (like tos.php). How to do that?
Bump. Please help.
For example, I'm using this code.

PHP Code:
define('IN_MYBB', 1);
define('THIS_SCRIPT', 'lctq.php');
require "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_forumlist.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;

if ($_GET['view'] == 'phs')
{
	/* --- Initialisation. --- */
	add_breadcrumb($lang->thuquan_phs_name, "lctq.php?view=phs");
	$plugins->run_hooks("forumdisplay_start");
	$tvisibleonly = "AND t.visible='1'";
	
	/* --- Setup pagingation. --- */
	$perpage = 12;
	if(isset($mybb->input['page']) && intval($mybb->input['page']) > 0)
	{
		$page = intval($mybb->input['page']);
		$start = ($page-1) * $perpage;
		$pages = $threadcount / $perpage;
		$pages = ceil($pages);
		if($page > $pages || $page <= 0)
		{
			$start = 0;
			$page = 1;
		}
	}
	else
	{
		$start = 0;
		$page = 1;
	}

	$end = $start + $perpage;
	$lower = $start + 1;
	$upper = $end;

	if($upper > $threadcount)
	{
		$upper = $threadcount;
	}
	
	$query = $db->query("
		SELECT t.*, t.username AS threadusername, u.username
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
		WHERE t.fid='5' $tvisibleonly
		ORDER BY t.sticky DESC
		LIMIT $start, $perpage
	");
	
	/* --- Getting threads. --- */
	while($thread = $db->fetch_array($query))
	{		
		$threadcache[$thread['tid']] = $thread;
	}

	if(!empty($threadcache))
	{
		$count = 0;
		foreach($threadcache as $thread)
		{
			$plugins->run_hooks("forumdisplay_thread");
			$count++;

			$thread['author'] = $thread['uid'];
			if(!$thread['username'])
			{
				$thread['username'] = $thread['threadusername'];
				$thread['profilelink'] = $thread['threadusername'];
			}
			else
			{
				$thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']);
			}

			$thread['subject'] = $parser->parse_badwords($thread['subject']);
			$thread['subject'] = htmlspecialchars_uni($thread['subject']);

			$prefix = '';

			$thread['threadlink'] = get_thread_link($thread['tid']);
			$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");

			$createdate = my_date($mybb->settings['dateformat'], $thread['dateline']);
			$createtime = my_date($mybb->settings['timeformat'], $thread['dateline']);
			$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
			$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
			$lastposter = $thread['lastposter'];
			$lastposteruid = $thread['lastposteruid'];

			// Don't link to guest's profiles (they have no profile).
			if($lastposteruid == 0)
			{
				$lastposterlink = $lastposter;
			}
			else
			{
				$lastposterlink = build_profile_link($lastposter, $lastposteruid);
			}

			$thread['replies'] = my_number_format($thread['replies']);
			$thread['views'] = my_number_format($thread['views']);
			
			if ($count == 4) {
				$count = 0;
			}
			eval("\$lcthreads .= \"".$templates->get("lctg_thuquan_phs_thread")."\";");
		}
	}
	
	eval("\$lclist = \"".$templates->get("lctg_thuquan_phs_list")."\";");
	
	/* --- Output --- */
	$plugins->run_hooks("forumdisplay_end");
	eval("\$lctq_phs = \"".$templates->get("lctg_thuquan_phs")."\";"); 
	output_page($lctq_phs);
}


But in this template lctg_thuquan_phs_thread, I can't use the threadfield variable ($GLOBAL....) What should I do ???

You need to pull the fields data in your query.
I'm assuming you actually understand the code you posted, right?
(07-28-2013 10:41 PM)ZiNgA BuRgA Wrote: [ -> ]You need to pull the fields data in your query.
I'm assuming you actually understand the code you posted, right?

Yes, I do. That's my code.
Well, I need to get the url of upload type field (it's name cover).

As normal, I just need to use this $GLOBALS['threadfields']['cover']['url'] then it will give me the url of the image. But when I check in the database (threadfields_data). The value of 'cover' field is just 0 and 1

What should I do to get that url ?
Maybe you need to look at the xtattachments table.
(07-30-2013 04:11 AM)RateU Wrote: [ -> ]Maybe you need to look at the xtattachments table.

How to build the Url like XThreads?

Eg:

Code:
http://example.com/xt_attach.php/2_1374420223_20e962ae/4d7e787a85a225087b594bdc27358cb5/filename.jpg

Use the function xthreads_get_xta_url()
Pass in the row from the xtattachments table as an array as the first argument.

If you wish to see how XThreads parses all its fields look at the xthreads_sanitize_disp and xthreads_sanitize_disp_set_xta_fields functions.
Thanks you.
Reference URL's