Recent Topics

1 Jun 27, 2006 11:14    

Hi!

I want to alter this DB-Request:

   
$CommentList = & new CommentList( $blog, "'comment'", $show_statuses, '',   '',   'DESC',   '',   5 );

so that is does not show any comments which has the word "academy" in the title of the article it belongs to. I changed the commentteaser plugin this way but I think it is much easier to change the DB-Request.

Here is my try but doing this with the DB-Request would be much nicer. Any idea?

<?php

if (!ereg("Academy", $Comment->Item->title)){

echo "<li class=\"commentteaser\">\n";
echo "<a title=\"Kommentar geschrieben am";?> <?php $Comment->date() ?> <? echo "um";?> <?php $Comment->time( 'H:i' ) ?><? echo "\" href=\""; ?><?php $Comment->Item->permalink() ?><? echo "#c"; ?><? $Comment->ID() ?><? echo "\">"; ?>

    <?php $Comment->Item->title( '', '', false ) ?>
	<? echo "</a><br /><span class=\"dimmed\">" ?><?php $Comment->author( '', '', '', '', 'htmlbody', false) ?><? echo "</span>"; ?>
<? echo "</li>"; ?>
<?
}
?>

2 Jun 27, 2006 11:19

And can someone give me a hint how to do the same with this SQL-Statement:

	$sql = "SELECT ID , post_title, post_urltitle ,
ROUND(COUNT(ID) / COUNT(DISTINCT postcat_cat_ID)) AS count
FROM evo_comments , evo_posts
INNER JOIN evo_postcats ON ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE evo_posts.ID = evo_comments.comment_post_ID
AND (cat_blog_ID = ".$params['blog'].")
GROUP BY ID
ORDER BY `count` DESC
LIMIT ".$params['limit2'];

I don't want any comments in it with the word "academy" in the title.

UPDATE:

Ok, I found the main problem: How can I read the title of the article that belongs to the specific comment? Can I use the comment_post_ID and then check the title there? It seems difficult. =(
If the comment has the word in it would be easier. Any Idea?

3 Jun 27, 2006 11:45

Try this :-

 $sql = "SELECT ID , post_title, post_urltitle ,
ROUND(COUNT(ID) / COUNT(DISTINCT postcat_cat_ID)) AS count
FROM evo_comments , evo_posts
INNER JOIN evo_postcats ON ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE evo_posts.ID = evo_comments.comment_post_ID
AND (cat_blog_ID = ".$params['blog'].")
AND not( post_title like '%academy%' )
GROUP BY ID
ORDER BY `count` DESC
LIMIT ".$params['limit2'];

¥

4 Jun 27, 2006 20:30

ok, thank you. I am not able to try it out at the moment but thanx for your help. Do you have also an idea for the first problem in my first post?

5 Jun 28, 2006 10:30

Ok, I'm not sure that this one will work, but crack open b2evocore/_class_commentlist.php and change this bit :-

	function CommentList( 
		$blog = 1, 
		$comment_types = "'comment'",
		$show_statuses = array(),							// Not used yet					
		$p = '',															// Restrict to specific post
		$author = '',													// Not used yet
		$order = 'DESC',											// ASC or DESC
		$orderby = '',												// list of fields to order by
		$posts = '', 													// # of comments to display on the page
		$paged = '',													// Not used yet
		$poststart = '',											// Not used yet
		$postend = '',												// Not used yet
		$s = '',															// Not used yet
		$sentence = '',												// Not used yet
		$exact = '',													// Not used yet
		$default_posts_per_page = '', 
		$init_what_to_show = '' ,
 $restrict = ''
		)
	{
		global $DB;
		global $tablecomments, $tableposts, $tablecategories, $tableblogs, $tablepostcats;
		global $cache_categories;
		global $cat_array; // communication with recursive callback funcs
		global $pagenow;		// Bleh !
		
		// Call parent constructor:
		parent::DataObjectList( $tablecomments, 'comment_', 'comment_ID' );

		$this->blog = $blog;
		
		if( !empty($posts) )
			$this->posts_per_page = $posts;
		else $this->posts_per_page = $default_posts_per_page;

		$this->request = "SELECT DISTINCT $tablecomments.*
											FROM (($tablecomments INNER JOIN $tableposts ON comment_post_ID = ID) ";
				
		if( !empty( $p ) )
		{	// Restrict to comments on selected post
			$this->request .= ") WHERE comment_post_ID = $p AND ";
		}
		elseif( $blog > 1 )
		{	// Restrict to viewable posts/cats on current blog
			$this->request .= "INNER JOIN $tablepostcats ON ID = postcat_post_ID) INNER JOIN $tablecategories othercats ON postcat_cat_ID = othercats.cat_ID WHERE othercats.cat_blog_ID = $blog AND ";
		}
		else
		{	// This is blog 1, we don't care, we can include all comments:
			$this->request .= ') WHERE ';
		}
		
		$this->request .= "comment_type IN ($comment_types) ";

if ( $restrict ) $this->request .= ' and not( post_title like \'%'.$restrict.'%\' )';


and then change your call to :-

$CommentList = & new CommentList( $blog, "'comment'", $show_statuses, '',   '',   'DESC',   '',   5, '', '', '', '', '', '', '', '', 'academy' );

¥

6 Jun 28, 2006 10:33

I just want to hack the comment-teaser plugin and not the whole b2evolution-core. I think if change that line in the code it will have an impact and the global comment stuff?!

7 Jun 28, 2006 10:42

It's a tad tough to answer that one without knowing which one of the many comment plugins you are using, but I'm guessing it's not possible to just alter the request.

The above change shouldn't have any effect on the rest of the comment stuff as I added a new parameter to the end of the list which needs to be set specifically.

¥

8 Jun 28, 2006 17:50

I am using this one:

<?php

   if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );


   $CommentList = & new CommentList( $blog, "'comment'", $show_statuses, '',   '',   'DESC',   '',   5 );

   $CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );
   echo "<ul>";
   while( $Comment = $CommentList->get_next() )
   {   // Loop through comments:   ?>

<?php
//LOOP START
//if (!ereg("Academy", $Comment->Item->title)){
echo "<!-- comment start -->\n";
echo "<li class=\"commentteaser\">\n";
echo "<a title=\"Kommentar geschrieben am";?> <?php $Comment->date() ?> <? echo "um";?> <?php $Comment->time( 'H:i' ) ?><? echo "\" href=\""; ?><?php $Comment->Item->permalink() ?><? echo "#c"; ?><? $Comment->ID() ?><? echo "\">"; ?><?php $Comment->Item->title( '', '', false ) ?><? echo "</a>\n<br />\n<span class=\"dimmed\">" ?><?php $Comment->author( '', '', '', '', 'htmlbody', false) ?><? echo "</span>"; ?>
<? echo "\n</li>\n"; echo "<!-- comment end -->\n"; ?>
<?
// LOOP END!
//}
?>

      <?php
   }   // End of comment loop.
?>
<li><a href="http://www.marctv.de/index.php?disp=comments">mehr...</a></li>
</ul>

9 Jun 29, 2006 09:39

Ok, without making the core hack I suggested you're pretty much limited to doing it the way you are now.

¥


Form is loading...