PDA

View Full Version : Miscellaneous Hacks - Adding subforums option for external.php


DarkSoroush
11-11-2010, 10:00 PM
Very quick and easy modification to add an option for including sub-forums in external.php
It is very odd why there isn't any trick in internet about this and no Mod.

Automatic Install:
Using xml file and try to Install Product.

Manual Install:
Go to plug-ins section. Click to add new plug-in. Then Select "external_start" as hook location, enter a name like "External Subforums Addon" or something, Then copy below code to "PHP Plug-in Code" and select Yes from "Enable Plug-In" then click Save.

function GetSubs($fid){
global $db;
$fidsq = $db->query_read_slave("SELECT childlist
FROM " . TABLE_PREFIX . "forum
WHERE forumid = ".$db->escape_string($fid)."
");
if ($fids = $db->fetch_array($fidsq)){
$fids = str_replace(',-1','',$fids['childlist']);
return $fids;
}else{
return $fid;
}
}

if ($_REQUEST['subforums'] && $_REQUEST['subforums']==1){
if ($_REQUEST['forumids']){
foreach (explode(',',$_REQUEST['forumids']) as $fid){
$_REQUEST['forumids'] = trim(GetSubs($fid).','.$_REQUEST['forumids'],',');
}
}elseif($_REQUEST['forumid']){
$_REQUEST['forumids'] = GetSubs($_REQUEST['forumid']);
}
}

if ($_REQUEST['forumids']){
// quick way of getting the first value
$_REQUEST['forumid'] = intval($_REQUEST['forumids']);
}

How to use?
Only add subforums=1 at end of external.php address. For example:

mysite.com/forum/external.php?type=RSS2&forumids=115,67&subforums=1
Or:
mysite.com/forum/external.php?type=RSS2&forumid=16&lastpost=1&subforums=1
Or:
mysite.com/forum/external.php?type=RSS&forumid=67&subforums=1
Or:
mysite.com/forum/external.php?type=XML&forumids=115&lastpost=1&subforums=1
etc ...

Advantages:
1. Comparing to manual adding of forum ids to address, It help users from missing new topics or posts when you make an other sub-forum but bookmarks of users are old.
2. And make better address for rss of course.
3. Also, You don't need any change of forums code to add updated rss links to your forum list. You can use a simple mod like "https://vborg.vbsupport.ru/showthread.php?t=211957". No need to install complete solution like this one: "https://vborg.vbsupport.ru/showthread.php?t=203358".