Wednesday, September 30, 2009

So, today I decided to try to figure out how to turn ‘recently popular’ into ‘latest news’. After much searching on the Pligg forum, I worked out that the order of the default front page was set in index.php. When I had a look at the code, it actually appeared to be ordering it already by date based on the variable link_published_date DESC; and no other variable.
I went to the live site and started adding comments and voting for older stories and this seemed to hold true – the order didn’t change.

I also looked at the code for the ‘Live’ section (which we have deactivated). This lists everything in order from latest to oldest using the same code. In live2.php noticed it set the order of the list, but ordered it by the more general variable link_date desc;. couldn’t work out what some of the code meant, so I started tracking bits down, to see if they had impact on the display. I didn’t know what ‘index_url_today’ did, so I tracked it down with a grep search and found it also appeared in smartyvariables.php. Looking at the line of code it appeared in there, it was linked with ‘index_sort’ which led me to html1.php. I then realised that this all was just responsible for setting the URL for any page you were on based on the sort category the user had selected. A dead end re the article feed, but good to know, none the less.

Looking at the code behind sorting the news by ‘top today’ I could see it was calling on the links database again, but filtering by ‘today’ and ordering by link_votes. So I went to the database and looked at the table ‘Links’. I could see that both link_comments and link_votes were set to be integers, so I figure we should be able to construct a way to display most commented using similar code.

I went back to index.php and looked at the function that was calling all of this to happen. it was called $setmek. So I grep searched it and found the original function details in search.php.
In the function do_setmek(), "if ($setmek == ‘today’)", it filters the results by time frame ‘today’ and orders it by ‘link_votes DESC’, so it makes sense to me that be should be able to create a similar command to sort highest commented today y::
"if ($setmek =='commented') {
$this->filterToTimeFrame = 'today';
$this->orderBy = "link_comments";"

Which will display only the stories submitted today, ordered by the number of comments (which is taken from the database table 'links' field 'link_comments').

So that’s a side matter solved, but back to the main problem. There was a bunch of code at the top of the setmek function code that I didn’t understand, but looked like it was determining order shown based on a variable $ords. I couldn’t work it out, how to change it or if it affected what we were trying to do, so I flicked back to the live Strine site and paged through the news feed.

As I was doing this, I realised that each page had a consistent number of articles on it – but they weren’t necessarily divided equally between the two columns. In the ‘recently popular’ news sort, it picked the latest 8 stories, whether they appeared in news or opinion categories. In the ‘top today’ it picked the 8 highest rated stories from today – with no distinction between their categories. So THIS was why the columns were appearing unequally! The current code configuration was treating it all as one lot of news (just displayed in different columns depending on category) not two sets of news. I’ve bounced this one back to Matt, so he can check out his to column feed set up.

SO: Recently popular IS latest to oldest news and is the default.
Top today, yesterday etc is ordered by votes and limited to chosen time frame

Need to set up a similar top today etc ordered by comments

No comments:

Post a Comment