MyBB Hacks

Full Version: XThreads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
(05-12-2011 03:55 PM)ZiNgA BuRgA Wrote: [ -> ]
(05-12-2011 01:18 PM)leefish Wrote: [ -> ]Ok, thank you. I will have a go at that, see what I come up with. Will I still be able to use the filters like in the forum display or would that require more files to be included? If so, which ones?
You'd have to manually build the query at this point.  There's no convenient XThreads function to do the job from memory.

Example:

PHP Code:
$query_add = '';
if($mybb->input['filtertf_pfcat']) $query_add .= ' AND tfd.pfcat="'.$db->escape_string($mybb->input['filtertf_pfcat']).'"';

...

// modify the query on portal.php which grabs threads
$db->query('SELECT ... '.$query_add);


Hi again, I have been working on this off and on, and I do have an operating page as far as display goes. I used the 2nd portal with pagination and using the portal_announcements/paging modifications (as in this post) from the Global templates as I was unable to get an image to show building my own query :/

I have added the query add as suggested by Zinga - I am filtering on a custom field - called prefix so I changed the query add to look for "prefix" as so:

PHP Code:
$query_add = '';
if($mybb->input['filtertf_prefix']) $query_add .= ' AND tfd.prefix="'.$db->escape_string($mybb->input['filtertf_prefix']).'"';


The page runs fine and looks good, but when I attempt to filter I get this mysql error:

Code:
MyBB has experienced an internal SQL error and cannot continue.
SQL Error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND tfd.prefix="Sims2"' at line 7
Query:
 SELECT p.pid, p.message, p.tid, tfd.prefix FROM mybb_posts p LEFT JOIN mybb_threads t ON (t.tid=p.tid) LEFT JOIN mybb_threadfields_data tfd ON (tfd.tid = t.tid) WHERE t.fid IN (7,14,22,28,53,55,73,78) AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid ORDER BY t.dateline DESC LIMIT 0, 18 AND tfd.prefix="Sims2"


My page is called browse.php and I have set up the filter as so:

HTML Code
			   	<tr><td class="thead"><strong>Game</strong></td></tr>
				<tr><td class="trow4"><a href="browse.php?"><span><strong>Both</strong></span></a></td></tr>
				<tr><td class="trow4 {$filters_set['prefix']['active']['Sims2']}"><a href="browse.php?&amp;filtertf_prefix=Sims2"><strong>Sims2</strong></a></td></tr>
				<tr><td class="trow4 {$filters_set['prefix']['active']['Sims3']}"><a href="browse.php?&amp;filtertf_prefix=Sims3"><strong>Sims3</strong></a></td></tr>


My custom thread field has two values, Sims2 or Sims3 and has a display formatting like so:

PHP Code:
Sims2{|}<a href="{$forumurl?}filtertf_prefix=Sims2"><span style="color: red;"><img src="http://www.leefish.nl/mybb/images/icons/sims2icon.png" alt="sims2" width="32px" height="32px"/></span></a>
Sims3{|}<img src="http://www.leefish.nl/mybb/images/icons/sims3icon.png" alt="sims3" width="32px" height="32px" />


So where am I going wrong? Live page is here:

http://www.leefish.nl/mybb/browse.php

Could you post the full script of your browse.php file?
Yes, here we go: It's probably full of redundant code, but one step at a time Smile

PHP Code:
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: portal.php 5147 2010-07-30 23:18:16Z RyanGordon $
 */

define("IN_MYBB", 1);
define("IN_PORTAL", 1);
define('THIS_SCRIPT', 'browse.php');

// set the path to your forums directory here (without trailing slash)
$forumdir = "./";

// end editing

$change_dir = "./";

if(!@chdir($forumdir) && !empty($forumdir))
{
	if(@is_dir($forumdir))
	{
		$change_dir = $forumdir;
	}
	else
	{
		die("\$forumdir is invalid!");
	}
}

$templatelist = "portal_announcement,browseportal";
$templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage";

require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;


// Fetch the current URL
$browse_url = get_current_location();

	add_breadcrumb("Downloads", $mybb->settings['bburl']."/browse.php");

$mybb->settings['portal_announcementsfid'] = '7,14,22,28,53,55,73,78';
$mybb->settings['portal_numannouncements'] = '18';
$query_add = '';
if($mybb->input['filtertf_prefix']) $query_add .= ' AND tfd.prefix="'.$db->escape_string($mybb->input['filtertf_prefix']).'"';

$plugins->run_hooks("portal_start");


// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewwhere = " AND fid NOT IN ($unviewable)";
}

// Get latest news announcements
// First validate announcement fids:
$announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']);
if(is_array($announcementsfids))
{
	foreach($announcementsfids as $fid)
	{
		$fid_array[] = intval($fid);
	}
	$announcementsfids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$announcementsfids.")");
while($forumrow = $db->fetch_array($query))
{
    $forum[$forumrow['fid']] = $forumrow;

}
	
$pids = '';
$tids = '';
$comma = '';
$page = intval($mybb->input['page']);
if($page < 1) $page = 1;
$numann = $db->fetch_field($db->simple_select('threads', 'COUNT(*) AS numann', "fid IN (".$mybb->settings['portal_announcementsfid'].") AND visible='1' AND closed NOT LIKE 'moved|%'"), 'numann');
$perpage = intval($mybb->settings['portal_numannouncements']);
$multipage = multipage($numann, $perpage, $page, $_SERVER['PHP_SELF'].'?paged=1');
$query = $db->query("
	SELECT p.pid, p.message, p.tid, tfd.prefix
	FROM ".TABLE_PREFIX."posts p
	LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
	LEFT JOIN ".TABLE_PREFIX."threadfields_data tfd ON (tfd.tid = t.tid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
	ORDER BY t.dateline DESC 
	LIMIT ".(($page-1)*$perpage).", ".$perpage.
$query_add);


while($getid = $db->fetch_array($query))
{
	$pids .= ",'{$getid['pid']}'";
	$tids .= ",'{$getid['tid']}'";
	$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";

if(is_array($forum))
{
	foreach($forum as $fid => $forumrow)
	{
		$forumpermissions[$fid] = forum_permissions($fid);

	}
}

$icon_cache = $cache->read("posticons");

$announcements = '';
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	WHERE fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
	ORDER BY t.dateline DESC
	LIMIT ".(($page-1)*$perpage).", ".$perpage
);
while($announcement = $db->fetch_array($query))
{

	$announcement['pid'] = $posts[$announcement['tid']]['pid'];
	$announcement['threadlink'] = get_thread_link($announcement['tid']);
	
	if($announcement['uid'] == 0)
	{
		$profilelink = htmlspecialchars_uni($announcement['threadusername']);
	}
	else
	{
		$profilelink = build_profile_link($announcement['username'], $announcement['uid']);
	}
	
	if(!$announcement['username'])
	{
		$announcement['username'] = $announcement['threadusername'];
	}
	$announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
	if($announcement['icon'] > 0 && $icon_cache[$announcement['icon']])
	{
		$icon = $icon_cache[$announcement['icon']];
		$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
	}
	else
	{
		$icon = "&nbsp;";
	}

	$anndate = my_date($mybb->settings['dateformat'], $announcement['dateline']);
	$anntime = my_date($mybb->settings['timeformat'], $announcement['dateline']);
	$annname = $announcement['forumname'];
	
	$plugins->run_hooks("portal_announcement");

		
	eval("\$announcements .= \"".$templates->get("portal_announcement")."\";");
	unset($post);
}

$plugins->run_hooks("portal_end");

eval("\$browse = \"".$templates->get("browseportal")."\";");
output_page($browse);

?>

Could you try this?

PHP Code:
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: portal.php 5147 2010-07-30 23:18:16Z RyanGordon $
 */

define("IN_MYBB", 1);
define("IN_PORTAL", 1);
define('THIS_SCRIPT', 'browse.php');

// set the path to your forums directory here (without trailing slash)
$forumdir = "./";

// end editing

$change_dir = "./";

if(!@chdir($forumdir) && !empty($forumdir))
{
	if(@is_dir($forumdir))
	{
		$change_dir = $forumdir;
	}
	else
	{
		die("\$forumdir is invalid!");
	}
}

$templatelist = "portal_announcement,browseportal";
$templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage";

require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;


// Fetch the current URL
$browse_url = get_current_location();

	add_breadcrumb("Downloads", $mybb->settings['bburl']."/browse.php");

$mybb->settings['portal_announcementsfid'] = '7,14,22,28,53,55,73,78';
$mybb->settings['portal_numannouncements'] = '18';
$query_add = '';
if($mybb->input['filtertf_prefix']) $query_add .= ' AND tfd.prefix="'.$db->escape_string($mybb->input['filtertf_prefix']).'"';

$plugins->run_hooks("portal_start");


// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewwhere = " AND fid NOT IN ($unviewable)";
}

// Get latest news announcements
// First validate announcement fids:
$announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']);
if(is_array($announcementsfids))
{
	foreach($announcementsfids as $fid)
	{
		$fid_array[] = intval($fid);
	}
	$announcementsfids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$announcementsfids.")");
while($forumrow = $db->fetch_array($query))
{
    $forum[$forumrow['fid']] = $forumrow;

}
	
$pids = '';
$tids = '';
$comma = '';
$page = intval($mybb->input['page']);
if($page < 1) $page = 1;
$numann = $db->fetch_field($db->simple_select('threads', 'COUNT(*) AS numann', "fid IN (".$mybb->settings['portal_announcementsfid'].") AND visible='1' AND closed NOT LIKE 'moved|%'"), 'numann');
$perpage = intval($mybb->settings['portal_numannouncements']);
$multipage = multipage($numann, $perpage, $page, $_SERVER['PHP_SELF'].'?paged=1');
$query = $db->query("
	SELECT p.pid, p.message, p.tid
	FROM ".TABLE_PREFIX."posts p
	LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
	ORDER BY t.dateline DESC 
	LIMIT ".(($page-1)*$perpage).", ".$perpage
);


while($getid = $db->fetch_array($query))
{
	$pids .= ",'{$getid['pid']}'";
	$tids .= ",'{$getid['tid']}'";
	$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";

if(is_array($forum))
{
	foreach($forum as $fid => $forumrow)
	{
		$forumpermissions[$fid] = forum_permissions($fid);

	}
}

$icon_cache = $cache->read("posticons");

$announcements = '';
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'".$query_add."
	ORDER BY t.dateline DESC
	LIMIT ".(($page-1)*$perpage).", ".$perpage
);
while($announcement = $db->fetch_array($query))
{

	$announcement['pid'] = $posts[$announcement['tid']]['pid'];
	$announcement['threadlink'] = get_thread_link($announcement['tid']);
	
	if($announcement['uid'] == 0)
	{
		$profilelink = htmlspecialchars_uni($announcement['threadusername']);
	}
	else
	{
		$profilelink = build_profile_link($announcement['username'], $announcement['uid']);
	}
	
	if(!$announcement['username'])
	{
		$announcement['username'] = $announcement['threadusername'];
	}
	$announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
	if($announcement['icon'] > 0 && $icon_cache[$announcement['icon']])
	{
		$icon = $icon_cache[$announcement['icon']];
		$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
	}
	else
	{
		$icon = "&nbsp;";
	}

	$anndate = my_date($mybb->settings['dateformat'], $announcement['dateline']);
	$anntime = my_date($mybb->settings['timeformat'], $announcement['dateline']);
	$annname = $announcement['forumname'];
	
	$plugins->run_hooks("portal_announcement");

		
	eval("\$announcements .= \"".$templates->get("portal_announcement")."\";");
	unset($post);
}

$plugins->run_hooks("portal_end");

eval("\$browse = \"".$templates->get("browseportal")."\";");
output_page($browse);

?>

Hi RateU, the filter worked, but it exploded the pagination. I will try moving it AFTER the pagination.

EDIT:  ok, the moving after pagination exploded it. I know that Zinga's filter supports paginated results - I just don't know how.

On further clicking the edited query is now only calling the first page of results - filtered or not. I have an alternate version of browse.php which calls my own query (I prefer to use this as I can do more with it) but it has the same issue with the paging.

So, now updating the "problem" to "how can I use the tf_filters with paginated results?"
Try this:

PHP Code:
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: portal.php 5147 2010-07-30 23:18:16Z RyanGordon $
 */

define("IN_MYBB", 1);
define("IN_PORTAL", 1);
define('THIS_SCRIPT', 'browse.php');

// set the path to your forums directory here (without trailing slash)
$forumdir = "./";

// end editing

$change_dir = "./";

if(!@chdir($forumdir) && !empty($forumdir))
{
	if(@is_dir($forumdir))
	{
		$change_dir = $forumdir;
	}
	else
	{
		die("\$forumdir is invalid!");
	}
}

$templatelist = "portal_announcement,browseportal";
$templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage";

require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;


// Fetch the current URL
$browse_url = get_current_location();

	add_breadcrumb("Downloads", $mybb->settings['bburl']."/browse.php");

$mybb->settings['portal_announcementsfid'] = '7,14,22,28,53,55,73,78';
$mybb->settings['portal_numannouncements'] = '18';
$query_add = '';
if($mybb->input['filtertf_prefix']){
	$query_add .= ' AND tfd.prefix="'.$db->escape_string($mybb->input['filtertf_prefix']).'"';
	$qry = ' LEFT JOIN '.TABLE_PREFIX.'threadfields_data tfd ON (tfd.tid=t.tid)';
	$brl = '&amp;filtertf_prefix='.htmlspecialchars_uni($mybb->input['filtertf_prefix']).'';
}

$plugins->run_hooks("portal_start");


// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewwhere = " AND fid NOT IN ($unviewable)";
}

// Get latest news announcements
// First validate announcement fids:
$announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']);
if(is_array($announcementsfids))
{
	foreach($announcementsfids as $fid)
	{
		$fid_array[] = intval($fid);
	}
	$announcementsfids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$announcementsfids.")");
while($forumrow = $db->fetch_array($query))
{
    $forum[$forumrow['fid']] = $forumrow;

}
	
$pids = '';
$tids = '';
$comma = '';
$page = intval($mybb->input['page']);
if($page < 1) $page = 1;
$numann = $db->fetch_field($db->query("SELECT COUNT(*) AS numann FROM ".TABLE_PREFIX."threads t".$qry." WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%'".$query_add.""), 'numann');
$perpage = intval($mybb->settings['portal_numannouncements']);
$multipage = multipage($numann, $perpage, $page, $_SERVER['PHP_SELF'].'?paged=1'.$brl);

$query = $db->query("
	SELECT p.pid, p.message, p.tid
	FROM ".TABLE_PREFIX."posts p
	LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
	LEFT JOIN ".TABLE_PREFIX."threadfields_data tfd ON (tfd.tid = t.tid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid".$query_add."
	ORDER BY t.dateline DESC 
	LIMIT ".(($page-1)*$perpage).", ".$perpage
);


while($getid = $db->fetch_array($query))
{
	$pids .= ",'{$getid['pid']}'";
	$tids .= ",'{$getid['tid']}'";
	$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";

if(is_array($forum))
{
	foreach($forum as $fid => $forumrow)
	{
		$forumpermissions[$fid] = forum_permissions($fid);

	}
}

$icon_cache = $cache->read("posticons");

$announcements = '';
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'".$query_add."
	ORDER BY t.dateline DESC
	LIMIT 0, ".intval($mybb->settings['portal_numannouncements'])
);
while($announcement = $db->fetch_array($query))
{

	$announcement['pid'] = $posts[$announcement['tid']]['pid'];
	$announcement['threadlink'] = get_thread_link($announcement['tid']);
	
	if($announcement['uid'] == 0)
	{
		$profilelink = htmlspecialchars_uni($announcement['threadusername']);
	}
	else
	{
		$profilelink = build_profile_link($announcement['username'], $announcement['uid']);
	}
	
	if(!$announcement['username'])
	{
		$announcement['username'] = $announcement['threadusername'];
	}
	$announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
	if($announcement['icon'] > 0 && $icon_cache[$announcement['icon']])
	{
		$icon = $icon_cache[$announcement['icon']];
		$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
	}
	else
	{
		$icon = "&nbsp;";
	}

	$anndate = my_date($mybb->settings['dateformat'], $announcement['dateline']);
	$anntime = my_date($mybb->settings['timeformat'], $announcement['dateline']);
	$annname = $announcement['forumname'];
	
	$plugins->run_hooks("portal_announcement");

		
	eval("\$announcements .= \"".$templates->get("portal_announcement")."\";");
	unset($post);
}

$plugins->run_hooks("portal_end");

eval("\$browse = \"".$templates->get("browseportal")."\";");
output_page($browse);

?>

Excellent - it works Smile

I shall write it up as an Xthreads layout for those who may want it. Most forum owners whose focus is not mybb/php (myself included) who want such things really don't have time to create this kind of thing - they are busy building their forum. So this should be a help (I hope)
Hey xthreaders:

Receiving this error after a server move and re-installation of Xthreads....rather an upgrade.

Code:
MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
    1060 - Duplicate column name 'viewable_gids'
Query:
    ALTER TABLE `mybb_threadfields` ADD COLUMN ( `viewable_gids` varchar(255) not null default "", `unviewableval` text not null ) 


Anyone got any ideas?
Thanx

Did you remove your cache/xthreads.php file?  Ensure you've moved that over, otherwise the upgrader won't know your previous version.
Shit....i deleted my old site. All i had was an old .sql file backup Frown
Reference URL's