Log in

View Full Version : adding replys (0) to custom script


msimonds
01-20-2004, 05:51 PM
I received this script from Turcic.com and I am modifing it to meet my needs for a new home page that I am working on!

you can see it in action here:

http://www.sportsrant.com/indexpost.php


I actually have it working great but I want to add one small feature!! the replies/comments that are posted to it in the forum that I am pulling this from: the "full story" works fine and goes to the forum post. I was wondering if someone could help me add the replies to it: here is the code:

<?php
// +-------------------------------------------------------------+
// | Turcic.com Website index.htm
// | Copyright ?2003 Alexander Turcic
// | Date: 2003/09/29 00:00:00 - Revision: 4.00
// +-------------------------------------------------------------+
error_reporting(E_ALL);
chdir('upgrade/vb');
require_once('./global.php');
include("./glob/css.php");
csssite($pvlayer=0);

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

// ################### VB: 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();

// ######################### VB: REQUIRE BACK-END ############################
//chdir('upgrade/vb');
require_once('./global.php');
require_once('./includes/functions_bbcodeparse.php');
//require_once('./includes/functions_external.php'); // seems not to be needed here
chdir('..');

// ################################################## ##########################
// Get Header template
$page_title = 'Welcome to Turcic.com!';
//include_once('./templates/header.php');

// ################################################## ##########################
// connnect to custom database (not used so far)
// dbconnect();
// $result = dbquery("SELECT id, time, source, title, url, langid FROM links ORDER BY time DESC;") or die("MySQL Error: " . mysql_error());

// Here comes specific Page Content
?>

<?php
// set announcement forum id
global $index,$fontcolor1,$fontcolor2,$fontcolor3,$fontco lor4,$bgcolor1,$bgcolor2,$bgcolor3,$bgcolor4, $title;
$announceforums = "14";
$forumchoice = array();
$forumids = explode(',', $announceforums);
foreach ($forumids AS $forumid)
{
$forumid = intval($forumid);
if (isset($forumcache["$forumid"]))
{
$forumchoice[] = $forumid;
}
}
if (!empty($forumchoice))
{
$forumchoice = 'AND thread.forumid IN(' . implode(',', $forumchoice) . ')';
}
else
{
$forumchoice = '';
}

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

// get visible forums for this user
$forumids = array();
foreach (array_keys($forumcache) AS $forumid)
{
$fp = &$bbuserinfo['forumpermissions']["$forumid"];
if ($fp & CANVIEW AND $fp & CANVIEWOTHERS)
{
$forumids[] = $forumid;
}
}

$previewfield = "post.pagetext AS preview,";
$previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.firstpostid)";

// query last 15 threads from visible / chosen forums
$threads = $DB_site->query("
SELECT $previewfield
thread.threadid, thread.title, thread.lastposter, thread.lastpost, thread.postusername, thread.dateline, forum.forumid, forum.title AS forumtitle
FROM " . TABLE_PREFIX . "thread AS thread
$previewjoin
INNER JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON (deletionlog.primaryid = thread.threadid AND deletionlog.type = 'thread')
WHERE thread.forumid IN(" . implode(',', $forumids) . ") $forumchoice
AND thread.visible = 1
AND deletionlog.primaryid IS NULL
ORDER BY thread.dateline DESC
LIMIT 5
");

$threadcache = array();
while ($thread = $DB_site->fetch_array($threads))
{ // fetch the threads
$threadcache[] = $thread;
}

if (!empty($threadcache))
{
foreach ($threadcache AS $thread)
{


$thread['preview'] = strip_quotes($thread['preview']);
//$thread['preview'] = htmlspecialchars_uni(fetch_trimmed_title(strip_bbc ode($thread['preview'], true, true),1500));
$thread['preview'] = fetch_trimmed_title(strip_bbcode($thread['preview'], true, true),1500);
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td class=\"title\" align=\"center\">$thread[title]<br></font></td></tr>\n";
echo "<tr>";
echo "<td class=\"title\" align=\"right\">" . vbdate('M d, Y', $thread['dateline']) . " </font></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td class=\"content\">$thread[preview]</td></tr>";
echo "<tr>";
echo "<td class=\"content\"><a target=\"_blank\" href=\"upgrade/vb/showthread.php?t=$thread[threadid]\"><br>(Full Story</a>, Comments )<br><br><br><hr></td>";
echo " </tr></table>";
}
}

?>

this is the actual line that shows the "full Story" link

echo "<td class=\"content\"><a target=\"_blank\" href=\"upgrade/vb/showthread.php?t=$thread[threadid]\"><br>(Full Story</a>, Comments )<br><br><br><hr></td>";
AND the actual data coming from the database.....
$threads = $DB_site->query("
SELECT $previewfield
thread.threadid, thread.title, thread.lastposter, thread.lastpost, thread.postusername, thread.dateline, forum.forumid, forum.title AS forumtitle
FROM " . TABLE_PREFIX . "thread AS thread
$previewjoin
INNER JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON (deletionlog.primaryid = thread.threadid AND deletionlog.type = 'thread')
WHERE thread.forumid IN(" . implode(',', $forumids) . ") $forumchoice
AND thread.visible = 1
AND deletionlog.primaryid IS NULL
ORDER BY thread.dateline DESC
LIMIT 5


ANYONE!!!!!!

Andreas
01-20-2004, 06:04 PM
I am not sure what you want exactly ...
Do you 1) want to show the whole thread at this page or 2) do you want to have reply-functionality?
For 2)

echo "<td class=\"content\"><a target=\"_blank\" href=\"upgrade/vb/showthread.php?t=$thread[threadid]\"><br>(Full Story</a>, Comments [<a href=href=\"upgrade/vb/newreply.php?do=newreply&noquote=1&t=$thread[threadid]\">Comment this</a>])<br><br><br><hr></td>";


instead of the original one might do the trick (if your users are allowed to post replies in the forum(s) the thread(s) come from.

Or do you want smth. completely different?

msimonds
01-20-2004, 06:13 PM
I want to have that ability and right next to that show the number of replies in (3) [example]. is that something that can be done

Andreas
01-20-2004, 06:23 PM
Replace


$threads = $DB_site->query("
SELECT $previewfield
thread.threadid, thread.title, thread.lastposter, thread.lastpost, thread.postusername, thread.dateline, forum.forumid, forum.title AS forumtitle


With

$threads = $DB_site->query("
SELECT $previewfield
thread.replycount, thread.threadid, thread.title, thread.lastposter, thread.lastpost, thread.postusername, thread.dateline, forum.forumid, forum.title AS forumtitle


Replace

echo "<td class=\"content\"><a target=\"_blank\" href=\"upgrade/vb/showthread.php?t=$thread[threadid]\"><br>(Full Story</a>, Comments )<br><br><br><hr></td>";


With

echo "<td class=\"content\"><a target=\"_blank\" href=\"upgrade/vb/showthread.php?t=$thread[threadid]\"><br>(Full Story</a>, $thread[replycount] Comments [<a href=href=\"upgrade/vb/newreply.php?do=newreply&noquote=1&t=$thread[threadid]\">Comment this</a>])<br><br><br><hr></td>";


This should give you an output like

(Full story, 3 Comments [Comment this])

msimonds
01-20-2004, 06:36 PM
i added your code and I am getting this in the bottom!

(Full Story, Array{replycount] Comments [Comment this])

any ideas!!!

msimonds
01-20-2004, 06:37 PM
nevermind, it was "{" and should be "[", thanks so much

msimonds
01-20-2004, 06:44 PM
man thanks so much, that is great. I really appreciate the help, I just could not figure it out

Andreas
01-20-2004, 06:57 PM
nevermind, it was "{" and should be "[", thanks so much Argh, was just a typo ;)

msimonds
01-20-2004, 07:10 PM
no problem man, I do it more than anyone

msimonds
01-20-2004, 07:29 PM
Hey man I am going to ask one more favor........ What about adding one more call to the DB to see who actually posted the article...... Like:

story....................

Written By: (username)
(Full Story...., Comments (2))

Andreas
01-20-2004, 07:40 PM
You don't need another query, just output $thread[postusername]

msimonds
01-20-2004, 07:41 PM
okay I will try that thanks

msimonds
01-20-2004, 07:53 PM
would this be correct to show a link to the username also:

echo "<td class=\"title\">Written By:<a target=\"_blank\" href=\"upgrade/vb/member.php?=$thread[postusername]>$thread[postusername]</a></td></tr>";

for some reason it is not working

Andreas
01-20-2004, 08:00 PM
You must use the postuserid for member.php:


echo "<td class=\"title\">Written By:<a target=\"_blank\" href=\"upgrade/vb/member.php?u=$thread[postuserid]>$thread[postusername]</a></td></tr>";


And you must also add thread.postuserid to the SELECT (IIRC it is not being selected currently).

msimonds
01-20-2004, 08:07 PM
Thanks again man. I had to add the thread.postuserid to the DB call but that took care of this. You are really a class A help......

Mike