boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Latest n Comments -- Rev. 0.5.0
Goto page 1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Sat Jan 25, 2003 7:59 pm    Post subject: Latest n Comments -- Rev. 0.5.0 Reply with quote

I have written a function from scratch that will display a number of comments on your template. You can define the number of comments, the length of the contents, which will be replaced by a string you specify, and whether to show the comment date/time or not.

To call this function, use the following syntax:

Code:

<?php latestcomments(5, 20, " said...", "[...]", 1, 1, 0); ?>


The first parameter is the number of comments that will be displayed; second parameter is the length of contents of comments; third parameter is what will appear after the name of the author; fourth parameter is what will be replaced with if the content is longer then you specified; the next two parameters will display the date and/or time if set to 1; and set the last parameter to 1 if you want comments in a popup window when the link is clicked.

If you leave all those parameters, defaults will be used. However, if you do put those parameters, make sure not to mix them up. And if you want to skip a parameter, skip it by leaving it empty but keep the sequence they are passed.

This cannot be used inside the b2 loop.

Save the following function in a separate file and call it from b2template_functions.php, or just copy and paste the function into that file. I recommend putting it in a separate file, preferably "latestcomments.php".

Updates:
---
0.5: A popup option added.

0.4.8: HTML tags are now stripped.

0.4.7: "Time-only" is now supported.

0.4.6: Added a check to see if the author URL is empty or not.

0.4.5: You can now define strings to be excluded from displaying.

0.4.3: Time is now supported.

0.4: A minor bug fixed.
---

You can see it working here.

You can get the code here.

Hope this would be useful to someone. Cool
_________________
Michael P.


Last edited by Cyberian75 on Wed Oct 13, 2004 11:31 pm; edited 23 times in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Sun Jan 26, 2003 6:02 am    Post subject: Reply with quote

wow, nice job
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Sun Jan 26, 2003 7:01 am    Post subject: Reply with quote

Thanks. Smile

I need your help, though. For some reason, if I set the date variable $show_date to 0 and the time variable $show_time to 1, the time won't show. Any ideas why?
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Wed Jan 29, 2003 5:38 pm    Post subject: Reply with quote

Cyberian75 wrote:
Thanks. Smile

I need your help, though. For some reason, if I set the date variable $show_date to 0 and the time variable $show_time to 1, the time won't show. Any ideas why?
hmm, i am not too good in mysql LOL. For me i use DATE_FORMAT(post_date, '%e.%c.%Y @ %H:%i') and print out using array[1] instead of like array["date"]
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Wed Jan 29, 2003 5:51 pm    Post subject: Reply with quote

Well, I'm trying to separate those two--date and time. Even if I use DATE_FORMAT function for the time, it returns a null value for some reason. Sad
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Wed Jan 29, 2003 8:05 pm    Post subject: Reply with quote

I took a different approach and used the following:

Code:

   if ($show_datetime == 1) {
      $joinquery .= ", DATE_FORMAT(comment_date, '%b. %D, %Y') AS commentdatetime ";
   }
   if ($show_datetime == 2) {
      $joinquery .= ", DATE_FORMAT(comment_date, '@ %l:%i %p') AS commentdatetime ";
   }
   if ($show_datetime == 3) {
      $joinquery .= ", DATE_FORMAT(comment_date, '%b. %D, %Y @ %l:%i %p') AS commentdatetime ";
   }


The rest of the function changed accordingly, of course. However, the second and third statements return a null value no matter what I do.

Any ideas?
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
blog17



Joined: 28 Jan 2003
Posts: 144
Location: London, UK

PostPosted: Thu Jan 30, 2003 2:40 am    Post subject: @ ... ? Reply with quote

Quote:
Michael said...
The "latest n comments" hack has been updated
...more >>
on Jan. 29th, 2003 @


Um... can you see the prob there? @ what?

Help? Smile
_________________
Check this out! The ULTIMATE site!
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Thu Jan 30, 2003 3:11 am    Post subject: Reply with quote

It's been fixed. Time now works. Smile

However, the odd behavior is still there; i.e., time-only mode is not working, meaning if you set $show_date to 0 and $show_time to 1, neither of them are displayed.

If you can figure it out, it would be very appreciated. Smile

By the way, the new feature allows you to exclude strings that you define for $excludearray variable. I implemented this to exclude smilie characters from the comments.
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
blog17



Joined: 28 Jan 2003
Posts: 144
Location: London, UK

PostPosted: Thu Jan 30, 2003 2:39 pm    Post subject: Reply with quote

Great job!
_________________
Check this out! The ULTIMATE site!
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Fri Feb 07, 2003 6:24 pm    Post subject: Reply with quote

Updated Smile

Update History:
---
0.4.7: "Time-only" is now supported.

0.4.6: Added a check to see if the author URL is empty or too short.

0.4.5: You can now define strings to be excluded from displaying.

0.4.3: Time is now supported.

0.4: A minor bug fixed.
---
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
blog17



Joined: 28 Jan 2003
Posts: 144
Location: London, UK

PostPosted: Sun Feb 09, 2003 3:56 am    Post subject: Fix Reply with quote

If someone were to put a ' or a "" in the name field... you would get a slash / when it appears in the comments block. It would be great if this were fixed.
_________________
Check this out! The ULTIMATE site!
Back to top
View user's profile Send private message Visit poster's website
bigsimon



Joined: 04 Jan 2003
Posts: 13

PostPosted: Tue Feb 11, 2003 12:39 am    Post subject: Reply with quote

I'm sort of a PHP newb...

How do I "call it from b2template.functions.php"?
_________________
bigSimon
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1063
Location: Oregon

PostPosted: Wed Feb 19, 2003 8:38 pm    Post subject: Reply with quote

Blog17, that's been fixed. You only needed to use the "stripslashes" function where you pull out the data from the database. Look within the while loop. Smile


And Simon, you can "include" a file by putting the following code in the file where you want to include a file in:

Code:

<?php include("filename.php"); ?>


To include something in b2template_functions.php, however, you would put the following just before the closing tag "?>":

Code:

include("filename.php");

_________________
Michael P.


Last edited by Cyberian75 on Sun Oct 26, 2003 10:03 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
bigsimon



Joined: 04 Jan 2003
Posts: 13

PostPosted: Sun Feb 23, 2003 8:29 am    Post subject: Reply with quote

Yeah! Got it working at http://www.bigsimon.com

Thanks, Michael.
_________________
bigSimon
Back to top
View user's profile Send private message
turtelina



Joined: 25 Jan 2002
Posts: 33
Location: Austria

PostPosted: Fri Mar 14, 2003 11:56 am    Post subject: Reply with quote

I love it Michael, it´s brilliant!

me hearts hacks Very Happy
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
Jump to:  
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