Topics

User Functions

Events

There are no upcoming events

What's New

Stories

No new stories

Comments last 2 weeks

No new comments

Trackbacks last 2 weeks

No new trackback comments

Links last 2 weeks

No recent new links

NEW FILES last 14 days

No new files

Welcome to Geeklog Monday, May 20 2013 @ 12:28 AM EDT


 Forum Index > Extensions > PHP Blocks New Topic Post Reply
 Top download block for filemgmt plugin
   
::Ben
 07/04/11 09:13AM (Read 504 times)  
+++++
Full Member

Status: offline


Registered: 01/14/05
Posts: 1359
I updated the top download block for filemgmt plugin. This block now check rights for category access.

PHP Formatted Code
function phpblock_topdl()
{
    //For filemgmt plugin >= 1.5
    global $_DB_table_prefix, $_USER;
       
    $poplist = '';
       
    $_FM_TABLES['filemgmt_cat']             = $_DB_table_prefix . 'filemgmt_category';
    $_FM_TABLES['filemgmt_filedetail']      = $_DB_table_prefix . 'filemgmt_filedetail';
       
    $query  = "SELECT f.* FROM {$_FM_TABLES['filemgmt_filedetail']} AS f
                LEFT JOIN {$_FM_TABLES['filemgmt_cat']} AS c
                ON c.cid = f.cid
                                "
;
                               
    if (isset($_USER['uid']) AND $_USER['uid'] > 1) {
        $uid = $_USER['uid'];
    } else {
        $uid = 1;
    }

    $_GROUPS = SEC_getUserGroups($uid);

    $groupsql = '';

    if (count($_GROUPS) == 1) {
        $groupsql .= " WHERE c.grp_access = '" . current($_GROUPS) ."'";
    } else {
        $groupsql .= " WHERE c.grp_access IN (" . implode(',',array_values($_GROUPS)) .")";
    }
       
    $query  .= $groupsql;

    //Files limit is 5. Change it if you need
    $query .= " ORDER BY hits DESC LIMIT 0 , 5";
                               
    $result = mysql_query($query);

    $nrows  = DB_numRows($result);

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

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

Ben

We speak french on http://geeklog.fr
 
Profile Email Website
 Quote
Roccivic
 07/05/11 06:04AM  
MMMMM
Moderator

Status: offline


Registered: 05/19/10
Posts: 136
Are you sure about this?

PHP Formatted Code
    $result = mysql_query($query);

 
Profile Email
 Quote
::Ben
 07/05/11 01:18PM  
+++++
Full Member

Status: offline


Registered: 01/14/05
Posts: 1359
Yes you're right, this might be
PHP Formatted Code
$result = DB_query($query);


New version

PHP Formatted Code

function phpblock_topdl()
{
    //For filemgmt plugin >= 1.5
    global $_DB_table_prefix, $_USER;
       
    $poplist = '';
       
    $_FM_TABLES['filemgmt_cat']             = $_DB_table_prefix . 'filemgmt_category';
    $_FM_TABLES['filemgmt_filedetail']      = $_DB_table_prefix . 'filemgmt_filedetail';
       
    $query  = "SELECT f.* FROM {$_FM_TABLES['filemgmt_filedetail']} AS f
                LEFT JOIN {$_FM_TABLES['filemgmt_cat']} AS c
                ON c.cid = f.cid
                                "
;
                               
    if (isset($_USER['uid']) AND $_USER['uid'] > 1) {
        $uid = $_USER['uid'];
    } else {
        $uid = 1;
    }

    $_GROUPS = SEC_getUserGroups($uid);

    $groupsql = '';

    if (count($_GROUPS) == 1) {
        $groupsql .= " WHERE c.grp_access = '" . current($_GROUPS) ."'";
    } else {
        $groupsql .= " WHERE c.grp_access IN (" . implode(',',array_values($_GROUPS)) .")";
    }
       
    $query  .= $groupsql;

    //Files limit is 5. Change it if you need
    $query .= " ORDER BY hits DESC LIMIT 0 , 5";
                               
    $result = DB_query($query);

    $nrows  = DB_numRows($result);

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

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


Thanks,

Ben

We speak french on http://geeklog.fr
 
Profile Email Website
 Quote
Content generated in: 0.92 seconds
New Topic Post Reply

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