Posted on: 10/15/02 07:57pm
By: MLimburg
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
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 ...
$tpl->set_var( 'toptenstoriesbyview', phpblock_toptenstoriesbyview() );
... will give you the ability to place that info pretty much anywhere!
Happy Hacking.
Re: Top Ten Stories by View
Posted on: 07/25/07 12:57pm
By: linker
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[*1]
Re: Top Ten Stories by View
Posted on: 07/25/07 01:50pm
By: Dirk
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
Re: Top Ten Stories by View
Posted on: 07/25/07 01:53pm
By: jmucchiello
Quote by: MLimburg
Text 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.
Text 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" );
Re: Top Ten Stories by View
Posted on: 07/25/07 02:04pm
By: linker
I keep getting this error: Fatal error: "Call to a member function on a non-object"
Re: Top Ten Stories by View
Posted on: 07/25/07 03:59pm
By: jmucchiello
stories should be in single quotes: $_TABLES['stories']
Re: Top Ten Stories by View
Posted on: 07/26/07 01:25pm
By: Anonymous (linker)
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[*2]
// 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('$','$',$A['title']));
$A['sid'] = "<a href=\"" . COM_buildUrl ($_CONF['site_url']
. "/article.php?story={$A['sid']}"
. "\">{$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