Welcome to Geeklog Monday, October 23 2017 @ 06:39 pm EDT


Status: offline

MLimburg

Forum User
Chatty
Registered: 17/12/2001
Posts: 35
Location:Adelaide, AU
Howdy. Here's another one. Moved the Top Ten Stories by View as a block.Open lib-custom.php and insert the following:

PHP Code

PHP Formatted Code
function phpblock_toptenstoriesbyview()
{
    global $_CONF, $_TABLES, $LANG10;

    $result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits desc LIMIT 10" );
    $nrows = DB_numRows( $result );

    $stat_templates = new Template( $_CONF['path_layout'] . 'stats' );
    $stat_templates->set_file( array(
        'itemstats'=>'itemstatistics.thtml',
        'statrow'=>'singlestat.thtml'
        ));
       
    if( $nrows > 0 )
    {
        $stat_templates->set_var( 'item_label', $LANG10[8] );
        $stat_templates->set_var( 'stat_name', $LANG10[9] );
       
        for ($i = 0; $i < $nrows; $i++)
        {
            $A = DB_fetchArray($result);

            $stat_templates->set_var( 'item_url', 'article.php?story=' . $A['sid'] );
            $stat_templates->set_var( 'item_text', stripslashes( str_replace( '$', '$', $A['title'] )));
            $stat_templates->set_var( 'item_stat', $A['hits'] );

            $stat_templates->parse( 'stat_row', 'statrow', true );
        }

        $stat_templates->parse( 'output', 'itemstats' );
        $retval = $stat_templates->finish($stat_templates->get_var('output'));
    }     else
    {
        $retval = $LANG10[10];
    }

    return $retval;
}
 

This will allow you to call phpblock_toptenstoriesbyview as a block. In addition (and indeed, the reason it was written in the first place), you can code a template placemarker to get this info. Something like ...

PHP Formatted Code
    $tpl->set_var( 'toptenstoriesbyview', phpblock_toptenstoriesbyview() );

... will give you the ability to place that info pretty much anywhere!

Happy Hacking.


Friends help you move. Real friends help you move bodies.

Status: offline

linker

Forum User
Newbie
Registered: 03/03/2007
Posts: 7
I followed the instructions and place the code: $tpl->set_var( 'toptenstoriesbyview', phpblock_toptenstoriesbyview() ); in search.php in order to get my top ten directories showing up in search and nothing happens. Please help. my website is http://www.alabamafest.com

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/2002
Posts: 13073
Location:Stuttgart, Germany
Assuming that code still works (haven't tested it): It defines a new variable {toptenstoriesbyview} that you will have to add to the search templates.

bye, Dirk

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
Quote by: MLimburg
PHP Formatted Code
    $result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits desc LIMIT 10" );
 


At a minimum you need to add COM_getPermSQL() to that. You should also add COM_getTopicSQL() to fully follow GL's security setup. You might also want to check that the date of release has passed. Stories can be saved for future release.

PHP Formatted Code
    $result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 " . COM_getPermSQL('AND') . COM_getTopicSQL('AND') . " ORDER BY Hits desc LIMIT 10" );
 

Status: offline

linker

Forum User
Newbie
Registered: 03/03/2007
Posts: 7
I keep getting this error: Fatal error: "Call to a member function on a non-object"

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
stories should be in single quotes: $_TABLES['stories']

linker

Anonymous
Thanks guys. I was unsuccessful, so i settled for add this code to search.php which work great, except i would like to change topic heading from Top Ten Viewed Stories to Top fifty Viewed Stories. http://www.accentaccounting.net/search.php // Detailed story statistics $result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . $topicsql . " ORDER BY hits DESC LIMIT 50"); $nrows = DB_numRows($result); if ($nrows > 0) { $header_arr = array( array('text' => $LANG10[8], 'field' => 'sid'), array('text' => $LANG10[9], 'field' => 'hits'), ); $data_arr = array(); $text_arr = array('has_menu' => false, 'title' => $LANG10[7], ); for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); $A['title'] = stripslashes(str_replace('$','&#36;',$A['title'])); $A['sid'] = "<a href=\"" . COM_buildUrl ($_CONF['site_url'] . "/article.php?story={$A['sid']}"Wink. "\">{$A['title']}"; $A['hits'] = COM_NumberFormat ($A['hits']); $data_arr[$i] = $A; } $display .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr); } else { $display .= COM_startBlock($LANG10[7]); $display .= $LANG10[10]; $display .= COM_endBlock(); } // CLOSE TOP 10 STORIES

All times are EDT. The time is now 06:39 pm.

  • 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