Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 01:52 am EST
Geeklog Forums
Top Ten Links
Status: offline
MLimburg
Forum User
Chatty
Registered: 12/17/01
Posts: 35
Location:Adelaide, AU
I'm hacking away at the code for a bunch of addons that knuckles wants .. so I thought I'd add a few of them in here for us all to use. The following is a function for lib-custom.php which allows you to shop the top ten links in a block. Open lib-custom.php and insert the following:
{
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT lid,url,title,hits from {$_TABLES['links']} WHERE 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[19] );
$stat_templates->set_var( 'stat_name', $LANG10[20] );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result );
$stat_templates->set_var( 'item_url', $_CONF['site_url'] . '/portal.php?url=' . $A['url'] . '&what=link&item=' . $A['lid'] );
$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[21];
}
return $retval;
}
Friends help you move. Real friends help you move bodies.
PHP Code
Text Formatted Code
function phpblock_toptenlinks(){
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT lid,url,title,hits from {$_TABLES['links']} WHERE 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[19] );
$stat_templates->set_var( 'stat_name', $LANG10[20] );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result );
$stat_templates->set_var( 'item_url', $_CONF['site_url'] . '/portal.php?url=' . $A['url'] . '&what=link&item=' . $A['lid'] );
$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[21];
}
return $retval;
}
This will allow you to call phpblock_toptenlinks 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 ...
Text Formatted Code
$tpl->set_var( 'toptenlinks', phpblock_toptenlinks() );... will give you the ability to place that info pretty much anywhere!
Happy Hacking.
Friends help you move. Real friends help you move bodies.
11
12
Quote
Status: offline
ScurvyDawg
Forum User
Full Member
Registered: 11/06/02
Posts: 523
Anyone have an up to date version of this block?
10
13
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
try this:
function phpblock_topTenLinks(){
global $_TABLES, $_CONF;
$result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$retval = '<ul>' . LB;
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray ($result);
$retval .= '<li><a href="'
. COM_buildUrl ($_CONF['site_url']
. '/portal.php?what=link&item=' . $A['lid'])
. '" title="' . $A['url'] . '">'
. stripslashes($A['title']) . '</a>'
. ' (' . $A['hits'] . ')</li>' . LB;
}
$retval .= '</ul>' . LB;
}
return $retval;
}
I left out the description for the sake of space as well as the "edit" link just because.
Text Formatted Code
function phpblock_topTenLinks(){
global $_TABLES, $_CONF;
$result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$retval = '<ul>' . LB;
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray ($result);
$retval .= '<li><a href="'
. COM_buildUrl ($_CONF['site_url']
. '/portal.php?what=link&item=' . $A['lid'])
. '" title="' . $A['url'] . '">'
. stripslashes($A['title']) . '</a>'
. ' (' . $A['hits'] . ')</li>' . LB;
}
$retval .= '</ul>' . LB;
}
return $retval;
}
12
10
Quote
Status: offline
ScurvyDawg
Forum User
Full Member
Registered: 11/06/02
Posts: 523
Thanks
I was actually asking for Redneck as we were discussing this over IM.
I appreciate your quick response Machinari
I was actually asking for Redneck as we were discussing this over IM.
I appreciate your quick response Machinari
15
12
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
modified version here:
function phpblock_topTenLinks(){
global $_TABLES, $_CONF;
$result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$retval = '<ul>' . LB;
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray ($result);
$retval .= '<li><a href="'
. COM_buildUrl ($_CONF['site_url']
. '/portal.php?what=link&item=' . $A['lid'])
. '" title="' . $A['url'] . '">'
. stripslashes($A['title']) . '</a>'
//. ' (' . $A['hits'] . ')'
. '</li>' . LB;
}
$retval .= '</ul>' . LB;
}
return $retval;
}
just uncomment the obvious line to reintroduce "hits" if ever you want to do so.
Text Formatted Code
function phpblock_topTenLinks(){
global $_TABLES, $_CONF;
$result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$retval = '<ul>' . LB;
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray ($result);
$retval .= '<li><a href="'
. COM_buildUrl ($_CONF['site_url']
. '/portal.php?what=link&item=' . $A['lid'])
. '" title="' . $A['url'] . '">'
. stripslashes($A['title']) . '</a>'
//. ' (' . $A['hits'] . ')'
. '</li>' . LB;
}
$retval .= '</ul>' . LB;
}
return $retval;
}
16
14
Quote
mach
Anonymous
add style to your <li>, setting padding and margin to "0", for example: <li style="padding-left: 0; margin-left: 0;">
17
11
Quote
All times are EST. The time is now 01:52 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