Recent Topics

1 Apr 03, 2005 00:03    

I'm trying to make my blog comments highlight - simply by using a different CSS class instead of "bComment" - something like "bCommentAuthor" - to change the colours of the border and background for that comment.

Now, I know what I need to do, what I don't know is how to get the information I need from b2evo.

I'm guessing I need to get the Post's author id using "$User->ID()" and the ID of the comment poster using "$Comment->dget()" - however the link to "Comment Properties" from the User Manual is broken.

I'm expecting the final code to look something like this and sit in _feedback.php :

if ( $Item->Author() == $Comment->get( 'author' ) ) {
   echo '<div class="bCommentAuthor">';
} else {
  echo '<div class="bComment">';
}

However, I just can't figure out what the parameters for the if statement should be to match a Comment's author to the post's author.

Anyone know more about this and able to point me in the right direction?

2 Apr 03, 2005 14:02

if the comment-author is a registered user, his ID is saved in comment_author_ID
you should compare it with $Item->Author->ID() not with $User->ID() because $User is the actual user looking at the website.

3 Apr 03, 2005 14:17

A few tests later, and I've got the Author ID from $Item->Author->ID() - however this is displaying immediately, rather than returning a value for the comparison

 if ( $Item->Author->ID() == 3 ) {
    echo '<div class="bCommentByAuthor">';
 } else {
    echo '<div class="bComment">';
 }

(yes, the "3" is a hack for now... I know that'll just match for every item for which the Item author's ID = 3 (all of them) - rather than the comment author ID)

Currently though the code above is actually outputting "3" to the browser - how to I stop $Item->Author->ID() from echoing "3" to the browser, and get it to return the value instead?

Example page: http://www.a-rush.co.uk/8/blogs/index.php/2005/03/22/driving_to_distraction#comments

4 Apr 03, 2005 15:52

Figured it out - so here's how to do it - the _class_comment.php file doesn't pass the value of authorid for a comment through, so I had to make a small change:

In _class_comment.php, find this block of code in the Comment function:

			$this->author_ip = $db_row['comment_author_IP'];
			$this->date = $db_row['comment_date'];
			$this->content = $db_row['comment_content'];
			$this->karma = $db_row['comment_karma'];

and add the following line to the end:

                        $this->authorid = $author_ID;

Now, in _feedback.php (for your skin) - find the line

<div class="bComment">

and replace it with

<?php
   $Author_is = $Item->Author->get('ID');
   $Comment_is = $Comment->get('authorid');

 if ( $Author_is == $Comment_is) {
    echo '<div class="bCommentByAuthor">';
 } else {
    echo '<div class="bComment">';
 }
?>

Then create a new CSS style for bCommentByAuthor to alter the comment as you want.

The change needed in _lastcomments.php is slightly different, again find the line

<div class="bComment">

but replace this one with

<?php
   $Author_is = $Comment->Item->Author->get('ID');
   $Comment_is = $Comment->get('authorid');

 if ( $Author_is == $Comment_is) {
    echo '<div class="bCommentByAuthor">';
 } else {
    echo '<div class="bComment">';
 }
?>

Phew. Now to go improve the CSS (I used lime green initially to make it obvious it was working!)

5 May 17, 2005 01:51

Thanks for this Tom.

Easily implemented.

6 May 05, 2007 05:32

This hack worked nicely for me in 1.9.3 - but I've been trying to make sure that I keep upgrading easier by making sure that all my changed code is kept in /skins/myskinname.

I tried some various things but I wasn't able to get this to work without making the appropriate changes to the comment class file.

Can anyone suggest a method that would avoid changing any of the core files, or should I just put in a request to have the comment class return the author ID as well?

I was also thinking that this would be nice to make into a plugin as well, like Wordpress has, and I'd be willing to work on it myself, but I don't think a plugin is possible if core files need to be manually modified.

7 May 05, 2007 17:26

Good hack! I was using another, but it was not so clean :)

8 May 07, 2007 22:21

What hack were you using for author highlighting? Can you point me to the code you used?

9 May 08, 2007 10:55

<div class="bComment<?php echo ( isset( $Comment->author_user_ID ) && $Comment->author_user_ID == $Item->creator_user_ID ? 'Author' : '' ); ?>">

¥

10 May 11, 2007 21:30

What version are you using this with? Could it work only with 1.9.x ?

I tried with 1.8.6 and did not get the effect. Becasue of a comment line I added I know the updated _feedback.php is being used.

Also, I did NOT find a _class_comment.php file. What I had in my install was _comment.class.php in /inc/MODEL/comments/

11 May 11, 2007 21:58

I use it in a 1.8.6 installation
just altering my _feedback.php

12 May 12, 2007 14:26

wow, I'll try to add this to my v1.10 b2e... good job!

13 May 19, 2007 06:31

Yabba has the proper solution... but I can't say for sure if it'll work on versions earlier than 1.9.x - I haven't worked as much with the older versions.

Now I've gotta dig in and figure out how to turn this into a plugin... it should be easy enough for my first one.

14 May 19, 2007 11:15

design guy wrote:

Yabba has the proper solution... but I can't say for sure if it'll work on versions earlier than 1.9.x - I haven't worked as much with the older versions.

LIke I said : it works on a 1.8.6 installation.
Since that is the prefered installation from the 'oldies'..

Don't try it ona 0.9.x.. installation.. that is for sure;.. because they don't work with plugins

15 Aug 04, 2007 22:28

Hmmm... for me this in currently not really working. I would like have a solution not fer everyone but only for user = 1, so for myself ;)

So far I have:

<?php
/**
 * This is the template that displays the links to the last comments for a blog
 *
 * This file is not meant to be called directly.
 * It is meant to be called by an include in the _main.php template.
 * To display a feedback, you should call a stub AND pass the right parameters
 * For example: /blogs/index.php?disp=comments
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package evoskins
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

$CommentList = & new CommentList( $blog, "'comment','trackback','pingback'", array('published'), '',	'',	'DESC',	'',	5 );
$CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );

while( $Comment = & $CommentList->get_next() )
{ // Loop through comments:
	// Load comment's Item object:
	$Comment->get_Item();
	?>
	<!-- ========== START of a COMMENT ========== -->
	<?php $Comment->anchor() ?>
	<?php if( $Item->author_user_ID == 1 ) { ?>
	<div class="bCommentByAuthor">
	<?php $Comment->author('von ', '', 'von ', '', 'raw', true) ?>
	<?php echo "als Antwort auf "; ?>
	<?php $Comment->Item->permanent_link( '#title#' ) ?>
	<?php echo ":<br>"; ?>
	<?php $Comment->content() ?>
	<?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
	<?php $Comment->date() ?> @ <?php $Comment->time( 'H:i' ) ?>
	<?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
	<?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?>
	</div>
	<?php } else { ?>
	<div class="bComment">
	<?php $Comment->author('von ', '', 'von ', '', 'raw', true) ?>
	<?php echo "als Antwort auf "; ?>
	<?php $Comment->Item->permanent_link( '#title#' ) ?>
	<?php echo ":<br>"; ?>
	<?php $Comment->content() ?>
	<?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
	<?php $Comment->date() ?> @ <?php $Comment->time( 'H:i' ) ?>
	<?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
	<?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?>
	</div>
	<?php } ?>
	<!-- ========== END of a COMMENT ========== -->
	<?php
}	// End of comment loop.


/*
 nolog */
?>

and the "else"-stuff is working... but not the <?php if( $Item->author_user_ID == 1 ) { ?> line... it produces the error message: "Notice: Trying to get property of non-object in /home/www/web5600/html/blog/skins/custom/_lastcomments.php on line 28".

Any Idea how I have to modify line 28 to highlight the comments which were made by myself, the author of every post, the user no. 1 ;)

Any ideas?

Thanks very much in advance for your help!
Daniel

16 Aug 05, 2007 08:49

Change this :

<?php if( $Item->author_user_ID == 1 ) { ?>

to this :

<?php if( isset( $Comment->author_user_ID ) && $Comment->author_user_ID == 1 ) { ?>

¥

17 Aug 05, 2007 09:14

Ok... have done it so... and now I have no error messages any more... but now there are not 5 comments shown in my sidebar but only 3, my own comments are nowhere to be seen...

_lastcomments.php

<?php
/**
 * ...
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

$CommentList = & new CommentList( $blog, "'comment','trackback','pingback'", array('published'), '',	'',	'DESC',	'',	5 );
$CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );

while( $Comment = & $CommentList->get_next() )
{ // Loop through comments:
	// Load comment's Item object:
	$Comment->get_Item();
	?>
	<!-- ========== START of a COMMENT ========== -->
	<?php $Comment->anchor() ?>
	<?php if( isset( $Comment->author_user_ID ) && $Comment->author_user_ID == 1 ) { ?>
	<div class="bCommentByAuthor">
	<?php $Comment->author('von ', '', 'von ', '', 'raw', true) ?>
	<?php echo "als Antwort auf "; ?>
	<?php $Comment->Item->permanent_link( '#title#' ) ?>
	<?php echo ":<br>"; ?>
	<?php $Comment->content() ?>
	<?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
	<?php $Comment->date() ?> @ <?php $Comment->time( 'H:i' ) ?>
	<?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
	<?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?>
	</div>
	<?php } else { ?>
	<div class="bComment">
	<?php $Comment->author('von ', '', 'von ', '', 'raw', true) ?>
	<?php echo "als Antwort auf "; ?>
	<?php $Comment->Item->permanent_link( '#title#' ) ?>
	<?php echo ":<br>"; ?>
	<?php $Comment->content() ?>
	<?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
	<?php $Comment->date() ?> @ <?php $Comment->time( 'H:i' ) ?>
	<?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
	<?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?>
	</div>
	<?php } ?>
	<!-- ========== END of a COMMENT ========== -->
	<?php
}	// End of comment loop.


/*
 nolog */
?>

custom.css

div.bComment, /* Entire comment block */
form.bComment /* New comment form */
{
	margin: 1ex 0;
	padding: 0 0.5ex;
	border: 1px dotted #999;
}
div.bCommentByAuthor
{
	margin: 1ex 0;
	padding: 0 0.5ex;
	border: 1px dotted #0000A0;
}

I simply want to have another colored border around my own comments... nothing more... hmmm...

18 Aug 05, 2007 09:19

Tad wierd, try changing your php to this :

 <?php
/**
 * ...
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

$CommentList = & new CommentList( $blog, "'comment','trackback','pingback'", array('published'), '',    '',    'DESC',    '',    5 );
$CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );

while( $Comment = & $CommentList->get_next() )
{ // Loop through comments:
    // Load comment's Item object:
    $Comment->get_Item();
    ?>
    <!-- ========== START of a COMMENT ========== -->
    <?php $Comment->anchor() ?>
    <div class="bComment<?php echo ( isset( $Comment->author_user_ID ) && $Comment->author_user_ID == 1 ? ' bCommentByAuthor' : '' ); ?>">
    <?php $Comment->author('von ', '', 'von ', '', 'raw', true) ?>
    <?php echo "als Antwort auf "; ?>
    <?php $Comment->Item->permanent_link( '#title#' ) ?>
    <?php echo ":<br>"; ?>
    <?php $Comment->content() ?>
    <?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
    <?php $Comment->date() ?> @ <?php $Comment->time( 'H:i' ) ?>
    <?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
    <?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?>
    </div>
    <!-- ========== END of a COMMENT ========== -->
    <?php
}    // End of comment loop.


/*
 nolog */
?>

And then change your css to this :

div.bComment, /* Entire comment block */
form.bComment /* New comment form */
{
    margin: 1ex 0;
    padding: 0 0.5ex;
    border: 1px dotted #999;
}

div.bCommentByAuthor
{
    border-color:#0000A0;
}

¥

19 Aug 05, 2007 09:47

Ok, this works now properly! GREAT! I only have to think of a better color because you nearly couldn´t see the difference ;-)

So, PROBLEM SOLVED!

20 Aug 06, 2007 09:05

Ok, one additional question:

how can I display (when logged in) only the icons for "edit", "delete" and "permalink"? Currently a text linkd and an icon is displayed. I could change it in text only... but I would like to modify it in icon only... and I would like to choose another icon than the standard one.

Would this be possible? When displaying the last comments in the sidebar, this method woul spare some space...

How I have to modify these lines?

    <?php $Comment->permanent_link( '#', '#', 'permalink_right' ); ?>
    <?php $Comment->edit_link( ' &middot; ' ) // Link to backoffice for editing ?>
    <?php $Comment->delete_link( ' &middot; ' ); // Link to backoffice for deleting ?> 

21 Aug 06, 2007 09:46

This is how my links are coded, replace the get_icon() bit with your own image tag if you want to use custom images :

$Comment->edit_link( '&nbsp;&middot;&nbsp;', '', get_icon( 'edit', 'imgtag' ), '#', 'permalink_right' ); /* Link to backoffice for editing */
$Comment->delete_link( '&nbsp;&middot;&nbsp;', '', get_icon( 'delete', 'imgtag' ), '#', 'permalink_right' ); /* Link to backoffice for deleting */

¥

22 Aug 06, 2007 10:53

Ok, this works quite well... but between the icons is IMO too much space... what can I do so that they are nearer together?

	<?php 
	   ...
	   $Comment->permanent_link('<img src="'.$rsc_url.'icons/chain_link.gif">', '#', 'permalink_right');
	   $Comment->edit_link( '', '', get_icon( 'edit', 'imgtag' ), '#', 'permalink_right' );
	   $Comment->delete_link( '', '', get_icon( 'delete', 'imgtag' ), '#', 'permalink_right' );
	   $Comment->content();
	   ...
	?>

Ah... and by using

$Comment->author('von ', '', 'von ', '', 'raw', true);

how can I manage the problem, that the visitor's URL shall open in a new tab / window?

23 Aug 06, 2007 11:20

We're digressing further and further from the topic of this post, if you have any more new problems could you start a new post for them?

1) When I change my code to match yours the icons are touching so you've probably got some css margins on them.

2) You'd need to grab the output from the function and add target="_blank" to the link

ob_start();
$Comment->author('von ', '', 'von ', '', 'raw', true); 
$fred = ob_get_clean();
echo preg_replace( '#(<a[^>]+?)>#', '$1 target="_blank">', $fred );

¥

24 Aug 06, 2007 11:29

Ok, concerning the digressing of the original topic you´re right - sorry!

No.2 is now working perfectly well.

Concerning No. 1 please allow me one last question - I think for this, it´s not necessary to open a new post: you are probably right concerning the css margins as well... but it´s something I did not intentionally... so at the moment I don´t know, which css I have to modify. Would it be possible to add a new css to these lines? For me it would be the easiest way to assign the margins I would like... but how to add a new style in the above lines?

25 Aug 06, 2007 11:34

No worries, it just helps people that follow if a post is about a single subject ;)

Without actually being able to see the icons it's a smidge difficult to help, but the easiest way is to wrap them in a div and target them that way :

    <?php 
       ...
       echo '<div class="foo">';
       $Comment->permanent_link('<img src="'.$rsc_url.'icons/chain_link.gif">', '#', 'permalink_right');
       $Comment->edit_link( '', '', get_icon( 'edit', 'imgtag' ), '#', 'permalink_right' );
       $Comment->delete_link( '', '', get_icon( 'delete', 'imgtag' ), '#', 'permalink_right' );
       $Comment->content();
       echo '</div>';
       ...
    ?>

<style type="text/css">
.foo a,
.foo a img{
margin:0;
padding:0;
}
</style>

¥

26 Aug 06, 2007 12:29

Perfect! Thank you very much...


Form is loading...