 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
Doc.Fusion
Joined: 19 May 2003 Posts: 25
|
Posted: Sun Aug 03, 2003 4:16 pm Post subject: [HACK] Last n comments only in Admin Control Panel |
|
|
First of all, I want to apologize Cyberian75 for this hack which mine is based on.
This hack let you see the latest comments, with the abilities of editing or deleting them.
This screen should explain you more than my poor english :
OK, let's see how to get that !
--------------------------------------------------------------------------------------
First, in your "b2-include" folder, find b2menutop.php.
In this file, find :
Code: | <a href="b2edit.php" class="menutop" style="-font-weight: bold;">Post / Edit</a><?php echo $sep ?><a href="javascript:profile(<?php echo $user_ID ?>)" class="menutop">My Profile</a><?php echo $sep ?><a href="b2team.php" class="menutop">Team</a><?php | (it was line 28 for me).
Replace this line with this one :
Code: | <a href="b2edit.php" class="menutop" style="-font-weight: bold;">Post / Edit</a><?php echo $sep ?><a href="javascript:profile(<?php echo $user_ID ?>)" class="menutop">My Profile</a><?php echo $sep ?><a href="b2lastcomments.php" class="menutop">Last comments</a><?php echo $sep ?><a href="b2team.php" class="menutop">Team</a><?php |
--------------------------------------------------------------------------------------
In the same folder, find b2functions.php.
At the and of this file, add this new function :
Code: | function latestcomments($number = 10, $commentlength = 20, $authorstr = ' said...', $replacestr = '[...]', $show_date = 1, $show_time = 1) {
global $tableposts, $tablecomments, $siteurl, $querycount;
global $querystring_start, $querystring_equal, $querystring_separator;
$commentlength=50000;
//strings you wish to exclude... to add more, use $excludeaway[] = "string";
$excludearray[] = ":cool:";
$excludearray[] = ":mad:";
$excludearray[] = ":oops:";
$excludearray[] = ":evil:";
$excludearray[] = ":twisted:";
$excludearray[] = ":roll:";
$excludearray[] = ":wink:";
$excludearray[] = ":idea:";
$excludearray[] = ":arrow:";
$excludearray[] = ":cry:";
$excludearray[] = ":razz:";
$excludearray[] = ":neutral:";
$excludearray[] = ":mrgreen:";
$excludearray[] = ":shock:";
$excludearray[] = ":eek:";
$excludearray[] = ":lol:";
$excludearray[] = ":grin:";
$excludearray[] = ":sad:";
$excludearray[] = ":smile:";
$joinquery = "SELECT ID, comment_post_ID, comment_ID, comment_author, comment_author_url, comment_content, post_title, comment_author_email, comment_author_IP";
//for date/time formatting, see www.mysql.com/doc/en/Date_and_time_functions.html
if ($show_date == 1) {
$joinquery .= ", DATE_FORMAT(comment_date, '%m/%d/%Y ') AS date";
}
if ($show_time == 1) {
$joinquery .= ", TIME_FORMAT(comment_date, '%H:%i ') AS time";
}
$joinquery .= " FROM $tableposts LEFT JOIN $tablecomments ON ID = comment_post_ID " .
" WHERE comment_content NOT LIKE '%<trackback />%' AND comment_content NOT LIKE '%<pingback />%' " .
" AND comment_content != '' " .
" ORDER BY comment_date DESC LIMIT $number";
// " ORDER BY comment_post_ID DESC, comment_date DESC LIMIT $number";
// try the second line if you want all comments sorted by post
$joinresult = mysql_query($joinquery) or die(mysql_error());
$querycount++;
$posttitle="";
while ($rows = mysql_fetch_array($joinresult)) {
$postID = $rows["ID"];
$commentID = $rows["comment_ID"];
$commentauthor = stripslashes($rows["comment_author"]);
$commentauthorurl = $rows["comment_author_url"];
$commentcontent = strip_tags(stripslashes($rows["comment_content"]));
$commentauthoremail = $rows["comment_author_email"];
$commentauthorip = $rows["comment_author_IP"];
$commentpostid = $rows["comment_post_ID"];
if($posttitle != stripslashes($rows["post_title"])){
$displaytitle=1;
$posttitle = stripslashes($rows["post_title"]);
}
else{
$displaytitle=0;
}
if (!empty($excludearray)) {
foreach ($excludearray AS $exclude) {
$commentcontent = str_replace($exclude, '', $commentcontent);
}
}
if ($show_date == 1) {
$commentdatetime = $rows["date"];
}
if ($show_time == 1) {
if ($show_date == 1) {
$commentdatetime .= ' @ ';
}
else {
$commentdatetime = '@ ';
}
$commentdatetime .= $rows["time"];
}
if($displaytitle==1) echo "<b>".$posttitle."</b><br />";
// if (strlen($commentcontent) > $commentlength) {
// $link = ' <a href="'.$siteurl.'/'.$querystring_start.'p'.$querystring_equal.$postID.$querystring_separator.'c'.$querystring_equal.'1'.$querystring_separator.'more'.$querystring_equal.'1#c'.$commentID.'">'.$replacestr.'</a>';
// $commentcontent = substr_replace($commentcontent, $link, $commentlength);
// }
// else {
// $link = ' <a href="'.$siteurl.'/'.$querystring_start.'p'.$querystring_equal.$postID.$querystring_separator.'c'.$querystring_equal.'1'.$querystring_separator.'more'.$querystring_equal.'1">[Post]</a>';
// $commentcontent .= $link;
// }
if (empty($commentauthorurl) || strlen($commentauthorurl) < 12) {
echo $commentauthor.$authorstr;
}
else {
echo '<a href="'.$commentauthorurl.'" target="_blank">'.$commentauthor.'</a>'.$authorstr;
}
echo "<b>( <a href=mailto:".$commentauthoremail.">".$commentauthoremail."</a> / <a href=".$commentauthorurl." target=_blank>".$commentauthorurl."</a> )</b> (IP: ".$commentauthorip.")";
echo "<br>\n";
echo $commentcontent."<br>\n";
if ($show_date == 1 || $show_time == 1) {
echo $commentdatetime."<br>";
}
else {
echo "<br>\n";
}
echo "[ <a href=".$siteurl."/b2edit.php".$querystring_start."action".$querystring_equal."editcomment".$querystring_separator."comment".$querystring_equal.$commentID.">Edit</a> - <a href=".$siteurl."/b2edit.php".$querystring_start."action".$querystring_equal."deletecomment".$querystring_separator."p".$querystring_equal.$postID.$querystring_separator."comment".$querystring_equal.$commentID.">Delete</a> ]<br>";
echo "<br>\n\n";
}
}
|
--------------------------------------------------------------------------------------
OK, it's almost finish.
Make a new page called b2lastcomments.php.
Paste this code into :
Code: | <?php
$title = "Last comments";
/* <Last comments> */
function add_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}
if (!get_magic_quotes_gpc()) {
$HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
$HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
}
$b2varstoreset = array('action','standalone','cat');
for ($i=0; $i<count($b2varstoreset); $i += 1) {
$b2var = $b2varstoreset[$i];
if (!isset($$b2var)) {
if (empty($HTTP_POST_VARS["$b2var"])) {
if (empty($HTTP_GET_VARS["$b2var"])) {
$$b2var = '';
} else {
$$b2var = $HTTP_GET_VARS["$b2var"];
}
} else {
$$b2var = $HTTP_POST_VARS["$b2var"];
}
}
}
$standalone=0;
require_once ("./b2header.php");
if ($user_level < 3) {
die("You have no right to see the last comments for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
}
?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<?php if(empty($number)) $number=10; ?>
<table width="" cellpadding="5" cellspacing="0">
<form></form>
<tr>
<td><form name="addcat" action="b2lastcomments.php" method="post"><b>Show</b> last
<!-- <input type="hidden" name="action" value="addcat" />
--> <input type="text" name="number" size="3" value="<?php echo $number ?>" /> comments
<input type="submit" name="submit" value="Show them !" class="search" /></form><br />
<?php latestcomments($number, 500, " a dit...", "(...)", 1, 1); ?>
</td></tr></table>
<?php echo $tablebottom ?>
<br />
<?php echo $tabletop ?>
<b>Note:</b><br />
This is a beta hack.
<?php echo $tablebottom ?>
<?php
/* </Last comments> */
include($b2inc."/b2footer.php"); ?> |
Then upload this file into your b2 directory.
That's over !
I hope you'll like it !
 |
|
Back to top |
|
 |
epolady
Joined: 30 Jul 2002 Posts: 800 Location: Texas
|
Posted: Sun Aug 03, 2003 7:28 pm Post subject: great job |
|
|
Hi there, great hack! However, when I made and uploaded b2lastcomments.php and I try to access it, it's very slow when it loads. Even when I have it set to show only the last comment. Any ideas? It can't be my server because I can browse other b2 pages without any lag.
Thank you.  |
|
Back to top |
|
 |
Doc.Fusion
Joined: 19 May 2003 Posts: 25
|
Posted: Sun Aug 03, 2003 10:24 pm Post subject: |
|
|
That's very strange.
In fact, I'm hosted by a server which is everything but not fast (www.free.fr), and the hack works fine.
There is only one SQL query.
Very sorry, yet, I can't figure out where is your trouble...
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1007 Location: Washington
|
Posted: Thu Feb 05, 2004 8:47 pm Post subject: |
|
|
Uhhh, you'd have simply changed the parameter "$commentlength = 20" to "$commentlength = 500000" instead of defining it again on the 4th line of the latestcomments function. I'd recommend doing a query instead of using this function, though. It's an inefficient way of doing queries for such a hack. _________________ Michael P. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2 © 2001, 2002 phpBB Group
|