Recent Topics

1 Feb 20, 2008 13:53    

I want to write a widget to emulate the "Hot Topics" hack I currently have at www.everythingulster.com

I'm going to base it on the Comments List and hopefully with a tiny bit of tinkering get it to do what I want (that is, display a list of posts that have been recently commented on - but no matter how many times they've been commented on recently, only list each post once).

The problem is I can't quite get started. I created a copy of the _coll_comment_list.widget.php called _coll_hot_topics.widget.php but it didn't appear anywhere for me to install.

I gather from searching here that I need to develop a plugin to act as a wrapper for the Widget. Can anyone point me in the direction of an introduction or tutorial that explains how to do this?

Thanks.

2 Feb 20, 2008 14:01

I know of no tutorial for it, but I used Afwas' "random photo" plugin to learn how to make a widget with a plugin to create my "countdown" plugin. Both are reasonably light-weight plugins, so perhaps between them you'll figure out which bits are appropriate for a bit of plugin-generated widgetry?

3 Feb 20, 2008 14:36

Thanks for the hint Ed. I had a look but it seems a bit confusing.

I've decided to just hack the existing comments list widget instead.

I've changed the end of the display function from:


    /**
		 * @var Comment
		 */
		while( $Comment = & $CommentList->get_next() )
		{ // Loop through comments:
			// Load comment's Item object:
			$Comment->get_Item();
			echo $this->disp_params[ 'item_start' ];
			$Comment->author( '', ' ', '', ' ', 'htmlbody', $this->disp_params[ 'author_links' ] );
			echo T_( 'on ' );
			$Comment->permanent_link( array(
				'text'        => $Comment->Item->title,
				'title'       => $this->disp_params[ 'hover_text' ],
				) );
			echo $this->disp_params[ 'item_end' ];
		}	// End of comment loop.}
		echo $this->disp_params[ 'list_end' ];
		echo $this->disp_params[ 'block_end' ];

		return true;

to:


    /**
		 * @var Comment
		 */
		 $list = array();
		while( $Comment = & $CommentList->get_next() )
		{ // Loop through comments:
			// Load comment's Item object:
			$Comment->get_Item();
			
  			if (! in_array($Comment->Item->ID, $list)  ) 
        {
          $list[] = $Comment->Item->ID;
    			echo $this->disp_params[ 'item_start' ];
    			$Comment->permanent_link( array(
    				'text'        => $Comment->Item->title,
    				'title'       => $this->disp_params[ 'hover_text' ],
    				) );
    			$Comment->author( '<br /><span class="sfLastCommenter">last comment by ', '</span> ', '<br /><span class="sfLastCommenter">last comment by ', '</span> ', 'htmlbody', $this->disp_params[ 'author_links' ] );
    			
    			echo $this->disp_params[ 'item_end' ];
  			}
  		}	// End of comment loop.}
  		echo $this->disp_params[ 'list_end' ];
  		echo $this->disp_params[ 'block_end' ];
  
		return true;

Is there some way to attach a file to a forum post or put it somewhere to share this back if anyone wants it?

4 Feb 20, 2008 14:42

beano wrote:

... Is there some way to attach a file to a forum post or put it somewhere to share this back if anyone wants it?

I think you just shared it, but afaik file uploading is not an option. You could however copy the file and rename it so that whatever.php becomes whatever.php.txt, then upload the .txt version and provide a link to that. People will see the .txt file and be able to copy/paste it if they want.

I have too much on my plate, but will watch this topic and see about making a plugin out of it - unless someone else beats me to it.

5 Feb 20, 2008 15:59

OK another new update.

The previous one output a list in the form:

POST NAME
last comment by AUTHOR NAME

Where POST NAME linked to the comment and AUTHOR NAME linked to the Author's URL (if they entered one).

This new version has POST NAME linking to the post itself and AUTHOR NAME linking to the comment.

It's maybe a little hacky, but nothing horrendous IMHO.


    /**
		 * @var Comment
		 */
		 $list = array();
		while( $Comment = & $CommentList->get_next() )
		{ // Loop through comments:
			// Load comment's Item object:
			$Comment->get_Item();
			
  			if (! in_array($Comment->Item->ID, $list)  ) 
        {
          $list[] = $Comment->Item->ID;
    			echo $this->disp_params[ 'item_start' ];   			
    			
    			
    			echo $Comment->Item->get_permanent_link( '#title#', $this->disp_params[ 'hover_text' ]);
    			// $Comment->author( '<br /><span class="sfLastCommenter">last comment by ', '</span> ', '<br /><span class="sfLastCommenter">last comment by ', '</span> ', 'htmlbody', $this->disp_params[ 'author_links' ] );
    			
    			if ($Comment->get_author_User() ) $author = $Comment->author_User->get_preferred_name();
    			else $author = $Comment->dget( 'author', 'htmlbody' );
    			
    			$Comment->permanent_link( array(
    			'before'      => '<br /><span class="sfLastCommenter">last comment: ',
    			'after'       => '</span>',
				  'text'        => $author,
				  'title'       => $this->disp_params[ 'hover_text' ],
				  ) );
    			
    			echo $this->disp_params[ 'item_end' ];
  			}
  		}	// End of comment loop.}
  		echo $this->disp_params[ 'list_end' ];
  		echo $this->disp_params[ 'block_end' ];
  
		return true;

6 Feb 20, 2008 16:03

If you take your code for function Display() and slap it into a plugin, and rename the function to SkinTag() you won't need to re-hack the core when you next upgrade ;)

¥

7 Feb 21, 2008 11:23

Thanks Yabba, I might do that at a later date. That's not enough for it to appear as a widget though, sure it's not?

8 Feb 21, 2008 19:28

Pretty much all.

If it's a cool plugin/widget then it'll probably have shedloads of settings that can be overridden by admin/user/skin, but that's about it.

If EdB doesn't beat me I'll slap it into a widget for you so you can see what I mean .... I'll even try and remember to leave mostly helpful comments in the code ..... mind you, you may prefer to wait for EdB's version, his comments tend to be marginally less obtuse and a smidge more entertaining ........ depending on the hour of day they're written ;)

¥

9 Feb 29, 2008 03:19

So what does this thing actually do? I mean: what makes a topic a hot topic?

I decided to play with my watched topics, and this is one of them. Kinda curious how simple a plugin can be because if I can make a plugin out of this when I don't even really know what it's doing then I can make TRYTsIYSB next. So what makes a topic be "hot"?

Tentative name: "Beano's Hot Topics". Catchy?

EDIT: duh - you explained it in the first post.

10 Feb 29, 2008 04:07

Okay that wasn't so bad. At first using Yabba's "just slap it in a SkinTag" I got like a million "hot topics" listed so I figure that wasn't right. I then changed "$this->init_display( $params );" to "$params = $this->init_display($params);" and all instances of "$this->disp_params" to "$params". THAT screwed things up in a major sort of way because now all the params it needed were even worse than whatever they were before. So I added the params it needed as widget-configurable settings and it sort of works.

What I have unhappiness with is when I tell it "gimme 5" it gives me 3 because, apparently, 2 of the most recent comments are on posts already seen by the other 3 comments. So "limit" gets me five results but "list" only spits out three items. I think that is very workable but it is what it is so there ya go.

Now I feel confident I can make a groovy little plugin for TRYTsIYSB, which everyone needs but no one knows it yet. Oh wait: I can't because I have no idea how to build a pair of arrays with a plugin. Oh well!

I wonder if I should try to clean up this "5 got me 3" thing or just let it go as-is?

11 Feb 29, 2008 04:18

What the heck that wasn't so bad and it'll still display less if any particular post is really REALLY hot.

I now limit the number of comments in the query to "twice the limit" value, then count how many items get displayed and stop adding new ones once "limit" is hit. So if you set a limit of 10 and a single post happens to have gotten the last 20 comments then it'll only show the one post. But if there are actually 10 different posts covered by the last 20 comments then you'll see those 10 posts. If the last 20 comments are scattered across 20 posts then you will only see the 10 most recent because limit is what it is.

I wonder if this should be some sort of soft fuzzy weird math setting for "how hot is hot?" type of thing? Like a 0 to 100 scale where a bigger number means keep the list really hot, which translates to not doubling the list of comments prior to counting how many posts got displayed.

Yeah that'd be cool!

12 Feb 29, 2008 18:24

Sounds really good Ed. There always was a problem in my implementations with the "limit" value (although it's more obvious now that it's configurable from the admin interface) - that just told it how many comments to fetch from the DB and often had no baring on how many topics or posts actually ended up being listed.

There's probably a way to "fix" that but it would involve meddling with the SQL (SELECT DISTINCT something) and I don't even know if that's practical.

EDIT: Just saw your name for it. I like it but somehow I don't think I should get credit since you seem to be doing most of the work. I would love to do it myself but TBH I don't understand quite how plugins and widgets fit in to the architecture.

EDIT2: BTW I got the idea for this from [url=http://www.sluggerotoole.com]Slugger O'Toole[/url]'s "Latest Comments" section, where they list the post name and the number of comments it has received.

EDIT3: What's TRYTsIYSB ?


Form is loading...

Social CMS – This forum is powered by b2evolution CMS, a complete engine for your website.