|
Include comments in post
|
| Author |
Message |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
Include comments in post
Rather than link to a separate page to view and post comments, I'd like to have comments included with each news post. How can I do this?
|
|
| 03-25-2008 02:53 PM |
|
 |
Brian
Administrator
      
Posts: 122
Group: Administrators
Joined: Jan 2006
Status:
Offline
Reputation: 0
|
RE: Include comments in post
This isn't included functionality, though it could be added by importing most of the code from comments.php under $action == 'list' and adding it to news.php. Doing so will also probably include a lot of template editing. If you're up to this, I should be able to guide you.
Brian Earley
Utopia Software
utopiasupport@gmail.com
http://www.utopiasoftware.net
Software: Utopia News Pro
|
|
| 03-26-2008 03:46 AM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
I'm definitely up for it. How should I begin?
Edit: I've gone ahead and done some hacking. Here's what I've got so far:
news.php
// +------------------------------------------------------------------+ // | Process News - Standard | // +------------------------------------------------------------------+ 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 = ' '; } $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); }
I've removed all header/footer references as I do not use them. I also took out IP and remove comment features since I don't really care about them either. My comments_list_commentbit template is set to default for now. I'm pulling it with news_newsbit_commentslink, which is set to:
<a href="javascript:void(0)" class="slide_trigger">{$comments} comments</a> | <a onclick='open("{$unpurl}/comments.php?action=post&newsid={$newsid}","Post","width=550, height=580, top=20,left=20,scrollbars=yes, status=no, toolbar=no, menubar=no")' href="javascript:void(0)">Leave a comment</a>
<div class="slide">{$comments_list_commentbit}</div>
I'm using Mootools Fx.Slide to toggle the comments on and off when "{$comments} comments" is clicked. Eventually I'd also like to include the comment submission form as part of the slide out, rather than a popup or separate page. Alright so now the debugging part:
My hacking has managed to pull and include one comment out of 5 in the database, and it's displaying that one comment on the wrong newsid. Any ideas? Thanks!
This post was last modified: 03-26-2008 07:09 AM by spaz.
|
|
| 03-26-2008 05:46 AM |
|
 |
Brian
Administrator
      
Posts: 122
Group: Administrators
Joined: Jan 2006
Status:
Offline
Reputation: 0
|
RE: Include comments in post
Can I see a link to the page this is being used on? I don't currently see an obvious reason the comments are appearing under the wrong newsid, though it's fairly amusing. :p
Brian Earley
Utopia Software
utopiasupport@gmail.com
http://www.utopiasoftware.net
Software: Utopia News Pro
|
|
| 03-26-2008 01:29 PM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
Can I see a link to the page this is being used on? I don't currently see an obvious reason the comments are appearing under the wrong newsid, though it's fairly amusing. :p
Yeah, page is here http://drdoobious.com/index.php
I went ahead and customized comments_list_commentbit to fit the design, but that shouldn't have affected anything. The first "post" on the page is actually just static html to test the design. Everything below it is actually part of the database.
I also PMed you the login info to the UNP control panel in case you need it.
Edit: I want to be a little more clear. There are 5 comments in the database. Only one of them is actually showing up. It appears on the post at the bottom of the page, but it should be part of the post above it.
This post was last modified: 03-26-2008 05:57 PM by spaz.
|
|
| 03-26-2008 02:49 PM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
I don't know if this will help, but I was messing around some more and found that adding
unp_echoTemplate($comments_list_commentbit);
under
eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
Would actually output all the comments. For some reason using the $comments_list_commentbit variable doesn't work right, but I need it to work in order to pull the comments from within a template.
Edit: I've discovered that only the most recent comment is the one getting displayed, so somehow $comments_list_commentbit is only pulling the newest comment in the database.
This post was last modified: 03-27-2008 05:41 AM by spaz.
|
|
| 03-26-2008 06:19 PM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
This just keeps getting stranger...
I posted a comment on the newest post and it's showing up on the 2nd newest post instead.
So now there's two comments out of 8 that are getting displayed, both on the wrong post.
|
|
| 03-27-2008 06:24 PM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
Ok I'm getting closer. I am now successfully pulling the comments into their respective newsids, however I'm only getting the most recent comment on each newsid to display. Here's my code:
// +------------------------------------------------------------------+ // | Process News - Standard | // +------------------------------------------------------------------+ 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 = ' '; } $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); }
And here's comments_list_commentbit:
<!-- begin comment id: {$c_id} -->
<div class="c-top"></div>
<div class="c-bottom">
<div class="c-auth"><a href="http://{$c_email}">{$c_name}</a></div>
<div class="c-date">{$c_date} at {$c_time} {$removecommentlink}</div>
<div class="c-body">{$c_text}</div>
</div>
<!-- end comment id: {$c_id} -->
And finally here's news_newsbit_commentslink:
<a href="javascript:void(0)" class="slide_trigger">View/Add comments ({$comments})</a>
</div>
<div class="c-box">
<div class="slide">
<div class="b-space"></div>
<div class="cf-add">
<form action="comments.php" method="post">
<div class="cf-namefield"><input name="author" type="text" onfocus="clearText(this);" value="Name" size="30" /></div>
<div class="cf-websitefield"><input name="website" type="text" onfocus="clearText(this);" value="Website (optional)" size="30" /></div>
<div class="cf-comment"><textarea name="comment" cols="90" rows="5" onfocus="clearText(this);">Comment</textarea></div>
<div class="cf-submit"><input name="submit" type="submit" value="Add comment" /></div>
</form>
</div>
{$comments_list_commentbit}
</div>
</div>
Using
echo $comments_list_commentbit;
directly after
eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";');
correctly echos all the comments in the array, but when $comments_list_commentbit is used outside of the
while ($comments = $DB->fetch_array($getcomments))
loop (such as inside the template for news_newsbit_commentslink), it only displays the newest comment for each newsid.
Any thoughts?
|
|
| 03-31-2008 12:57 AM |
|
 |
Brian
Administrator
      
Posts: 122
Group: Administrators
Joined: Jan 2006
Status:
Offline
Reputation: 0
|
RE: Include comments in post
The actual comments.php file does use unp_echoTemplate($comments_list_commentbit) right after the eval() line. Is there a reason it can't be used here, too?
If so, perhaps it would be best as like this, noting the period:
eval('$comments_list_commentbit .= "'.unp_printTemplate('comments_list_commentbit').'";');
Brian Earley
Utopia Software
utopiasupport@gmail.com
http://www.utopiasoftware.net
Software: Utopia News Pro
This post was last modified: 04-04-2008 05:37 AM by Brian.
|
|
| 04-04-2008 05:37 AM |
|
 |
spaz
Junior Member
 
Posts: 14
Group: Registered
Joined: Mar 2008
Status:
Offline
Reputation: 0
|
RE: Include comments in post
It can't be used here because the comments need to be echoed as part of the news_newsbit_commentslink template, not outside it, or the comments display outside of the news posts.
However, I tried adding the period and something strange is happening. I get this notification only once, at the very top of the script output, and only if the first (newest) post has 1 or more comments:
Notice: Undefined variable: comments_list_commentbit in /home/.reveca/drdoobious/drdoobious.com/news/news.php(149) : eval()'d code on line 8
As for the comment output, it works -- to a degree. Posts are now showing all the comments, PLUS the comments of the newer post above it! If the post above has 0 comments, nothing is added, and on the post with 0 comments itself nothing is added even if the post above does have comments.
Very odd! So what next?
|
|
| 04-04-2008 07:21 PM |
|
 |
|
|