Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2006, 03:41 PM
djwins djwins is offline
 
Join Date: Jan 2005
Posts: 167
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Please convert this 3.0.7 external.php hack to 3.5.4! - latest forum posts

I recently upgraded to 3.5.4 and I was hoping someone could help me convert this 3.0.7 external.php hack to 3.5.4

I was using javascript to pull the info onto the front page of my site
The following hack would pull latest active forum threads in this format:
thread title (# of replies)
last poster name

Clicking the thread title would take you to the first post in the thread and the last poster name would take you to the last post


FWIW, someone else made this 3.0.7 hack for me.
Hopefully there is a way to add this as a hook.
I can share my javascript code for those who are interested in using this on their sites.
Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.0.7 - Licence Number L77155ed
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000?2005 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('SESSION_BYPASS', 1);
define('LOCATION_BYPASS', 1);
define('DIE_QUIETLY', 1);
define('THIS_SCRIPT', 'external');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array(
	'userstats',
	'birthdays',
	'maxloggedin'
);

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_external.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

// set us up as a very limited privileges user
$vboptions['hourdiff'] = (date('Z', TIMENOW) / 3600 - intval($_REQUEST['timeoffset'])) * 3600;
$bbuserinfo = array('usergroupid' => 1);
$usergroupcache = array();
$permissions = cache_permissions($bbuserinfo);

// check to see if there is a forum preference
if ($_REQUEST['forumids'] != '')
{
	$forumchoice = array();
	$forumids = explode(',', $_REQUEST['forumids']);
	foreach ($forumids AS $forumid)
	{
			$forumchoice[] = $forumid;
	}

	$number_of_forums = sizeof($forumchoice);
	if ($number_of_forums == 1)
	{
		$title = $forumcache["$forumchoice[0]"]['title'];
	}
	else if ($number_of_forums > 1)
	{
		$title = implode(',', $forumchoice);
	}
	else
	{
		$title = '';
	}

	if (!empty($forumchoice))
	{
		$forumchoice = 'AND thread.forumid IN(' . implode(',', $forumchoice) . ')';
	}
	else
	{
		$forumchoice = '';
	}
}
else
{
	foreach (array_keys($forumcache) AS $forumid)
	{
		$fp = &$bbuserinfo['forumpermissions']["$forumid"];
		if (($fp & CANVIEW) AND ($fp & CANVIEWOTHERS) AND verify_forum_password($forumid, $forumcache["$forumid"]['password'], false))
		{
			$forumchoice[] = $forumid;
		}
	}
	if (!empty($forumchoice))
	{
		$forumchoice = 'AND thread.forumid IN(' . implode(',', $forumchoice) . ')';
	}
	else
	{
		$forumchoice = '';
	}
}

if ($forumchoice != '')
{
	// query last 5 threads from visible / chosen forums
	$threads = $DB_site->query("
		SELECT thread.threadid, thread.title, thread.lastposter, thread.lastpost, thread.postusername, thread.lastpost, thread.replycount, forum.forumid, forum.title AS forumtitle, post.pagetext AS preview
		FROM " . TABLE_PREFIX . "thread AS thread
		INNER JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
		LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)
		LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON (deletionlog.primaryid = thread.threadid AND deletionlog.type = 'thread')
		WHERE 1=1
			$forumchoice
			AND open <> 10
			AND deletionlog.primaryid IS NULL
		ORDER BY thread.lastpost DESC
		LIMIT 5
	");
}

$threadcache = array();
while ($thread = $DB_site->fetch_array($threads))
{ // fetch the threads
	$threadcache[] = $thread;
}
$_REQUEST['type'] = strtoupper($_REQUEST['type']);
switch ($_REQUEST['type'])
{
	case 'JS':
	case 'XML':
	case 'RSS2':
		break;
	default:
		$_REQUEST['type'] = 'RSS';
}

if ($_REQUEST['type'] == 'JS' AND $vboptions['externaljs'])
{ // javascript output

	?>
	function thread(threadid, title, poster, threaddate, threadtime, replycount)
	{
		this.threadid = threadid;
		this.title = title;
		this.poster = poster;
		this.threaddate = threaddate;
		this.threadtime = threadtime;
		this.replycount = replycount;
	}
	<?php
	echo "var threads = new Array(" . sizeof ($threadcache) . ");\r\n";
	if (!empty($threadcache))
	{
		foreach ($threadcache AS $threadnum => $thread)
		{
			$thread['title'] = addslashes_js($thread['title']) . ' (' . $thread['replycount'] . ')';
			$thread['poster'] = addslashes_js($thread['lastposter']);
			echo "\tthreads[$threadnum] = new thread($thread[threadid], '$thread[title]', '$thread[poster]', '" . vbdate($vboptions['dateformat'], $thread['lastpost']) . "', '" . vbdate($vboptions['timeformat'], $thread['lastpost']) . "');\r\n";
		}
	}

}
else if ($_REQUEST['type'] == 'XML' AND $vboptions['externalxml'])
{ // XML output

	// set XML type and nocache headers
	header('Content-Type: text/xml');
	header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Pragma: public');

	// print out the page header
	echo '<?xml version="1.0" encoding="' . $stylevar['charset'] . '"?>' . "\r\n";
	echo "<source>\r\n\r\n";
	echo "\t<url>$vboptions[bburl]</url>\r\n\r\n";

	// list returned threads
	if (!empty($threadcache))
	{
		foreach ($threadcache AS $thread)
		{
			echo "\t<thread id=\"$thread[threadid]\">\r\n";
			echo "\t\t<title><![CDATA[$thread[title]]]></title>\r\n";
			echo "\t\t<author><![CDATA[$thread[postusername]]]></author>\r\n";
			echo "\t\t<date>" . vbdate($vboptions['dateformat'], $thread['lastpost']) . "</date>\r\n";
			echo "\t\t<time>" . vbdate($vboptions['timeformat'], $thread['lastpost']) . "</time>\r\n";
			echo "\t</thread>\r\n";
		}
	}
	echo "\r\n</source>";
}
else if (($_REQUEST['type'] == 'RSS' OR $_REQUEST['type'] == 'RSS2') AND $vboptions['externalrss'])
{ // RSS output
	// setup the board title
	if (empty($title))
	{ // just show board title
		$rss_title = htmlspecialchars_uni($vboptions['bbtitle']);
	}
	else
	{ // show board title plus selection
		$rss_title = htmlspecialchars_uni($vboptions['bbtitle'] . " - $title");
	}
	if ($_REQUEST['type'] == 'RSS2')
	{
		$v = 2;
	}
	else
	{
		$v = 1;
	}
	// set XML type and nocache headers
	header('Content-Type: text/xml');
	header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Pragma: public');

	echo '<?xml version="1.0" encoding="' . $stylevar['charset'] . '"?>' . "\r\n";
	if ($v == 2)
	{
		echo "<rss version=\"2.0\"
\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"
\txmlns:syn=\"http://purl.org/rss/1.0/modules/syndication/\"
\txmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\r\n\r\n";
	}
	else
	{
		echo '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\r\n";
		echo '<rss version="0.91">' . "\r\n";
	}
	echo "<channel>\r\n";
	echo "\t<title>" . $rss_title . "</title>\r\n";
	echo "\t<link>$vboptions[bburl]</link>\r\n";
	echo "\t<description>" . htmlspecialchars_uni($vboptions['description']) . "</description>\r\n";

	if ($v == 2)
	{
	echo "\t<syn:updatePeriod>hourly</syn:updatePeriod>\r\n";
	echo "\t<syn:updateFrequency>1</syn:updateFrequency>\r\n";
	echo "\t<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase>\r\n";
	echo "\t<dc:language>$stylevar[languagecode]</dc:language>\r\n";
	echo "\t<dc:creator>vBulletin</dc:creator>\r\n";
	$tz = vbdate('O', TIMENOW);
	if ($tz == '+0000')
	{
		$tz = 'Z';
	}
	else
	{
		$tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);
	}
	echo "\t<dc:date>" . vbdate('Y-m-d\TH:i:s', TIMENOW) . "$tz</dc:date>\r\n";
	}

	#	<image>
	#		<title>< ?php echo $vboptions['bbtitle']; ? ></title>
	#		<url>http://www.domain.com/images/image.gif</url>
	#		<link>< ?php echo $vboptions['bburl']; ? ></link>
	#	</image>

	$i = 0;

	// list returned threads
	if (!empty($threadcache))
	{
		foreach ($threadcache AS $thread)
		{
			$fp = &$bbuserinfo['forumpermissions']["$forumid"];

			echo "\t<item>\r\n";
			echo "\t\t<title>$thread[title]</title>\r\n";
			echo "\t\t<link>$vboptions[bburl]/showthread.php?t=$thread[threadid]&amp;goto=newpost</link>\r\n";
			if ($v == 1)
			{
				echo "\t\t<description><![CDATA[$vbphrase[forum]: " . htmlspecialchars_uni($thread['forumtitle']) . "\r\n$vbphrase[posted_by]: $thread[postusername]\r\n" .
					construct_phrase($vbphrase['post_time_x_at_y'], vbdate($vboptions['dateformat'], $thread['lastpost']), vbdate($vboptions['timeformat'], $thread['lastpost'])) .
					"]]></description>\r\n";
			}
			else
			{ // RSS v2 allows more data
				echo "\t\t<content:encoded><![CDATA[". htmlspecialchars_uni(fetch_trimmed_title(strip_bbcode($thread['preview'], false, true), $vboptions['threadpreview'])) ."]]></content:encoded>\r\n";
				echo "\t\t<guid isPermaLink=\"false\">$vboptions[bburl]/showthread.php?t=$thread[threadid]</guid>\r\n";
				// cant use the $tz value for TIMENOW as DST could have been in effect when this post was made.
				$tz = vbdate('O', $thread['lastpost']);
				if ($tz == '+0000')
				{
					$tz = 'Z';
				}
				else
				{
					$tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);
				}
				echo "\t\t<dc:date>" . vbdate('Y-m-d\TH:i:s', $thread['lastpost']) . "$tz</dc:date>\r\n";
				echo "\t\t<dc:creator>$thread[postusername]</dc:creator>\r\n";
			}
			echo "\t</item>\r\n";
		}
	}
	echo "</channel>\r\n";
	echo "</rss>";

}

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 23:45, Wed Mar 23rd 2005
|| # CVS: $RCSfile: external.php,v $ - $Revision: 1.53.2.1 $
|| ####################################################################
\*======================================================================*/
?>
Thanks in advance!
Reply With Quote
  #2  
Old 02-26-2006, 10:27 PM
djwins djwins is offline
 
Join Date: Jan 2005
Posts: 167
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone? Maybe a tip or two on what has changed in the external.php file from 3.0.8 to 3.5.4?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03465 seconds
  • Memory Usage 2,217KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete