Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 11:44 am EDT

Geeklog Forums

hacking the advanced search to show most viewed


Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
Is there any way to hack the advanced search to return most viewed articles. I know that stats.php has the top 10 but I would love to be able to check the top articles within certain dates...
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
See if this thread does you any good

...it probably wont i think, having just now actually read your question. Leaves me speechless
 Quote

Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
Unless I'm missing something, the thread doesn't help me. I need something to find out what were the 15 most popular stories of the last 10 days and how many views. I thought the easiest way to do this would be the advanced search because you can specify a date range. But it doesn't allow you the option to have the result come back in order of popularity. I was thinking a hack to have that option would work best. But If I could create a static page or block that could do this function that would work as well...

 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
mix the one above with this thread and you should be on your way to a new block. most popular within a date range
 Quote

Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
I hate to be a pain, and I'm sorry to bother you again but I heve no idea how to intergrate them? I know very very basic php.... and looking at the two code posts its very clear I have no idea whats going on...
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
this block gives you the most popular, ordered by hits descending, for the last 30 days. editing the date calculations in the query will, obviously, change your results.

you could call another function from within this one that, perhaps allows you to enter a date range, and then that calculation will be built and inserted into this query. easy as pie.
Text Formatted Code

function phpblock_mostPopularbyDate()
{
    global $_TABLES, $_CONF;
    $result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']}
        WHERE (draft_flag = 0) AND (date <= NOW()) AND (date >= (DATE_SUB(NOW(), INTERVAL 30 DAY)))"
        . COM_getPermSQL ('AND') . " ORDER BY hits desc");
    $nrows  = DB_numRows($result);

    if( $nrows > 0 ){
        $string = '';
        $popular = array();

        for( $i = 0; $i < $nrows; $i++ ){
            $A = DB_fetchArray( $result );
            $string .= $poplist . '<br>';
            $popular[] = '<a href="' . COM_buildUrl( $_CONF['site_url']
                    . '/article.php?story=' . $A['sid'] ) . '">' . $A['title']
                    . '</a> (' . $A['hits'] . ')';
        }
        if( !empty( $popular )){
            $poplist = COM_makeList( $popular, 'list-popular-stories' );
        }
    }
    return $poplist;
}

 
 Quote

Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
This worked great... I thank you very much, you've saved my butt more than once!
 Quote

Status: offline

beewee

Forum User
Full Member
Registered: 08/05/03
Posts: 969
Location:The Netherlands, where else?
Great block, Mach, especially for good SERP's. But I how can I limit it to show max 5 or 10 stories, and change the URL's to:

www.mydomain.com/topic ID/article.php/story ID ??
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
to limit the query, just change this bit of the query, ORDER BY hits desc, to read ORDER BY hits desc LIMIT 5.

You should be able to have that URL the way you've specified if you turn on URL rewrite in your config.php. This function uses COM_buildURL(), which is the wrapper for the rewrite engine, afaics. But don't quote me cuz I've never actually used it.
 Quote

Status: offline

beewee

Forum User
Full Member
Registered: 08/05/03
Posts: 969
Location:The Netherlands, where else?
Great, thanks, but did you have a good look at the URL I mentioned, I'm using URL-Rewrite to put the stories in the topic directories:

URL/topic ID/article.php/story ID

Like on this website.
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
OK, so the difference being the topic ID, right?
so let's just forget rewrite and do it manually like you wanted in the first place I think.
try this version, which includes the topic ID in the query as well as the URL redefined:
Text Formatted Code

function phpblock_mostPopularbyDate()
{
    global $_TABLES, $_CONF;
    $result = DB_query("SELECT sid,tid,title,hits FROM {$_TABLES['stories']}
        WHERE (draft_flag = 0) AND (date <= NOW()) AND (date >= (DATE_SUB(NOW(), INTERVAL 30 DAY)))"
        . COM_getPermSQL ('AND') . " ORDER BY hits desc LIMIT 5");
    $nrows  = DB_numRows($result);

    if( $nrows > 0 ){
        $string = '';
        $popular = array();

        for( $i = 0; $i < $nrows; $i++ ){
            $A = DB_fetchArray( $result );
            $string .= $poplist . '<br>';
            $popular[] = '<a href="' . $_CONF['site_url'] . '/'
                    . $A['tid'] . '/article.php/' . $A['sid'] . '">' . $A['title']
                    . '</a> (' . $A['hits'] . ')';
        }
        if( !empty( $popular )){
            $poplist = COM_makeList( $popular, 'list-popular-stories' );
        }
    }
    return $poplist;
}

 
 Quote

Status: offline

beewee

Forum User
Full Member
Registered: 08/05/03
Posts: 969
Location:The Netherlands, where else?
You made me very happy! I deleted the hits, but it works like a charm, look over here, right block on the top. Thanks, Mach!
Big Celebration Big Celebration
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
 Quote

All times are EDT. The time is now 11:44 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content