Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
OlSpazzy
Feb 10, 2004

PHP noob alert! Oh god please don't rape me in the rear end :(

The script I'm using for news posting is designed so the comments for each news item are displayed with links like "/news/comments.php?action=list&newsid=1" but I'd like to have the comments displayed below each post, rather than on a separate page. There doesn't seem to be a variable to do this with the templates, so how can I accomplish it? The script is available for download at http://www.utopiasoftware.net/newspro/dl.php?filename=newspro140b.zip&mirror=1

Perhaps there's a better script I should use instead? I don't need a cms script though, just a way to include blog posts on an otherwise static website.

Adbot
ADBOT LOVES YOU

OlSpazzy
Feb 10, 2004

OlSpazzy posted:

PHP noob alert! Oh god please don't rape me in the rear end :(

The script I'm using for news posting is designed so the comments for each news item are displayed with links like "/news/comments.php?action=list&newsid=1" but I'd like to have the comments displayed below each post, rather than on a separate page. There doesn't seem to be a variable to do this with the templates, so how can I accomplish it? The script is available for download at http://www.utopiasoftware.net/newspro/dl.php?filename=newspro140b.zip&mirror=1

Perhaps there's a better script I should use instead? I don't need a cms script though, just a way to include blog posts on an otherwise static website.

Ok well I hacked parted of the news.php script to include sections from comments.php relevant to listing comments. I'm using the $comments_list_commentbit variable in the news_newsbit_commentslink template, but I'm only getting one comment out of 5 in the database showing up, and it's showing on the wrong newsid. Any ideas?

php:
<?
if ($action == '')
{
    define('ISPRINTABLEPAGE', false);
    define('WILLTRUNCATE', true);
    define('ISRSS', false);
    $templatesused = 'news_newsbit,news_newsbit_commentslink,news_avatarbit,news_newsbit_readmorelink,comments_list_commentbit';
    unp_cacheTemplates($templatesused);
    $getnews = $DB->query("SELECT * FROM `unp_news` ORDER BY `date` DESC LIMIT $newslimit");
    while ($news = $DB->fetch_array($getnews))
    {
        $catid = $news['catid'];
        $category = $categorycache["$catid"];
        $newsid = $news['newsid'];
        $subject = $news['subject'];
        $newstext = $news['news'];
        $poster = $news['poster'];
        $posterid = $news['posterid'];
        $date = $news['date'];
        $postdate = unp_date($dateformat, $date);
        $posttime = unp_date($timeformat, $date);
        $avatar = unp_checkAvatar($posterid);
        if (!$avatar)
        {
            $useravatar = '';
        }
        else
        {
            eval('$useravatar = "'.unp_printTemplate('news_avatarbit').'";');
        }
        if ($commentsallowance == '1')
        {
            $comments = $news['comments'];
            eval('$commentsinfo = "'.unp_printTemplate('news_newsbit_commentslink').'";');
        }
        else
        {
            $commentsinfo = '&nbsp;';
        }
        $comments = $news['comments'];
        //$newstext = $n->unp_doNewsTrim($newstext); // Move to unp_doNewsFormat
        $newstext = $n->unp_doNewsFormat($newstext);
        $subject = $n->unp_doSubjectFormat($subject);
        // NewsBit
        eval('$news_newsbit = "'.unp_printTemplate('news_newsbit').'";');
        unp_echoTemplate($news_newsbit);
        // NewsBit
        echo "\n\n";
        $getcomments = $DB->query("SELECT * FROM `unp_comments` WHERE newsid='$newsid'");
            if ($DB->num_rows($getcomments) > 0)
            {
                while ($comments = $DB->fetch_array($getcomments))
                {
                    // grab and fix up comments
                    $c_id = $comments['id'];
                    $c_title = htmlspecialchars(stripslashes($comments['title']));
                    $c_name = htmlspecialchars(stripslashes($comments['name']));
                    $c_email = htmlspecialchars(stripslashes($comments['email']));
                    $c_date = unp_date($dateformat, $comments['date']);
                    $c_time = unp_date($timeformat, $comments['date']);
                    $c_text = nl2br(htmlspecialchars(stripslashes($comments['comments'])));
                    $c_ipaddress = $comments['ipaddress'];
                    $c_proxy = $comments['proxy'];
                    $c_text = $n->unp_doSmilies($c_text);        
                    eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
                }
            }
            else
            {
                $comments_list_commentbit = '';
            }
    }
    unset($news);
}
?>

OlSpazzy
Feb 10, 2004

Does anyone see a reason why the "show news comments" section of this code is only displaying the newest comment for each post?

$comments_list_commentbit is being called from within the template for "news_newsbit_commentslink". Note that some classes and variables may not appear to be defined as this is only a portion of the script.

php:
<?
if ($action == '')
{
    define('ISPRINTABLEPAGE', false);
    define('WILLTRUNCATE', true);
    define('ISRSS', false);
    $templatesused = 'news_newsbit, news_newsbit_commentslink, news_avatarbit, news_newsbit_readmorelink, comments_list_commentbit, comments_list_commentbit_removecomment';
    unp_cacheTemplates($templatesused);
    $getnews = $DB->query("SELECT * FROM `unp_news` ORDER BY `date` DESC LIMIT $newslimit");
    while ($news = $DB->fetch_array($getnews))
    {
        $catid = $news['catid'];
        $category = $categorycache["$catid"];
        $newsid = $news['newsid'];
        $subject = $news['subject'];
        $newstext = $news['news'];
        $poster = $news['poster'];
        $posterid = $news['posterid'];
        $date = $news['date'];
        $postdate = unp_date($dateformat, $date);
        $posttime = unp_date($timeformat, $date);
        $avatar = unp_checkAvatar($posterid);
        // begin Show News Comments
        $getcomments = $DB->query("SELECT * FROM `unp_comments` WHERE newsid='$newsid'");
        if ($DB->num_rows($getcomments) > 0)
        {
            while ($comments = $DB->fetch_array($getcomments))
            {
                // grab and fix up comments
                $c_id = $comments['id'];
                $c_title = htmlspecialchars(stripslashes($comments['title']));
                $c_name = htmlspecialchars(stripslashes($comments['name']));
                $c_email = htmlspecialchars(stripslashes($comments['email']));
                $c_date = unp_date($dateformat, $comments['date']);
                $c_time = unp_date($timeformat, $comments['date']);
                $c_text = nl2br(htmlspecialchars(stripslashes($comments['comments'])));
                $c_ipaddress = $comments['ipaddress'];
                $c_proxy = $comments['proxy'];
                $c_text = $n->unp_doSmilies($c_text);
                if ($isloggedin == 1)
                {
                    eval('$removecommentlink = "'.unp_printTemplate('comments_list_commentbit_removecomment').'";');
                }
                else
                {
                    $removecommentlink = '';
                }
                eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
            }
        }
        else
        {
            $comments_list_commentbit = '';
        }
        // end Show News Comments
        if (!$avatar)
        {
            $useravatar = '';
        }
        else
        {
            eval('$useravatar = "'.unp_printTemplate('news_avatarbit').'";');
        }
        if ($commentsallowance == '1')
        {
            $comments = $news['comments'];
            eval('$commentsinfo = "'.unp_printTemplate('news_newsbit_commentslink').'";');
        }
        else
        {
            $commentsinfo = '&nbsp;';
        }
        $comments = $news['comments'];
        //$newstext = $n->unp_doNewsTrim($newstext); // Move to unp_doNewsFormat
        $newstext = $n->unp_doNewsFormat($newstext);
        $subject = $n->unp_doSubjectFormat($subject);
        // NewsBit
        eval('$news_newsbit = "'.unp_printTemplate('news_newsbit').'";');
        unp_echoTemplate($news_newsbit);
                
        // NewsBit
        echo "\n\n";
    }
    unset($news);
}?>

OlSpazzy
Feb 10, 2004

bt_escm posted:

I looks like you are assigning $comments_list_commentbit each time. I think you want to use .= instead of =

Also I see no reason to use eval here or anywhere else in your code and it's really just a style and readability thing, but never use select * from table, even when you want to select everything from the table. List out the columns. It will save your sanity in the future.

I actually did try .= instead and somehow that causes each post to display all of it's comments AND the comments of the post above it. Posts with zero comments don't display anything. It also causes this notice only once at the top of code execution:

code:
Notice: Undefined variable: comments_list_commentbit in /home/x/y/z.com/news/news.php(149) : eval()'d code on line 8
Also, the evals are necessary, without them unp_printTemplate('comments_list_commentbit') returns, for example:

{$c_name}{$c_date} at {$c_time} {$removecommentlink}
{$c_text}

So it's needed to get the variables within the templates to actually parse. Thanks for the suggestion on table selections.

OlSpazzy
Feb 10, 2004

I've given up trying to fix my comments problem from previous posts. I just don't understand php well enough to do the job myself.

Does anyone know of a php news publishing script that can be integrated into an existing site (not a cms script) that includes the comments inside the news posts at all times?

In other words, you don't have to view the full story or load a new page to view comments as they are already displayed on the initial post, along with the comment submission form.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply