Facebook  Twitter 

SMFHacks.com

+- +-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 12384
Latest: JamesPrige
New This Month: 3
New This Week: 2
New Today: 2
Stats
Total Posts: 40254
Total Topics: 7090
Most Online Today: 112
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 36
Total: 36

Author Topic: Gallery Random Picture block for TP  (Read 4285 times)

0 Members and 1 Guest are viewing this topic.

Offline Rafferty

  • Full Member
  • ***
  • Posts: 159
    • View Profile
    • Australian Air Defence Artillery Association
Gallery Random Picture block for TP
« on: October 14, 2010, 06:47:10 pm »
Hacks any chance of updating this code for SMF 2.0 RC3? Ive had it since 1.1.11 but no longer displays correctly.

Code: [Select]
////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.8          //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 9/26/2008
// 1.8
//        - added display # of comments option
//
// Used in a TinyPortal phpblock or Article.
// This block displays random/most/least/newest/oldest picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

global $scripturl, $db_prefix, $modSettings, $boardurl, $ID_MEMBER, $user_info, $context;

/*
****************************************
****************************************
***    !! Admin Config Section !!    ***
****************************************
****************************************
*/

//   *****   LAYOUT OPTIONS   *****
// how many pictures do you want to show?  0 = all!
$gal_numpics = 1;

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 0;
// sort :: 0 = Descending, 1 = Ascending
$gal_sort = 0;

// enable profile pics display?
// 0 = disable, 1 = enable --- if enabled, and you are viewing a member profile, show pics from that member only
// other options still apply (showtype, sort order, etc)
$gal_profile = 1;

// only show pics from buddies?
// 0 = disable, 1 = enable --- if enabled, will only show pics posted by members in your buddy list
$gal_buddies = 0;

// use Normal Size Text, or Small Size Text? (0 = Normal Size, 1 = Small Size)
$gal_smalltext = 1;

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns = 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle = 1;
// display membername who posted pic?
$gal_dispMember = 0;
// display posted date?
$gal_dispDate = 0;
// display category the picture is in?
$gal_dispCategory = 1;
// display number of views?
$gal_dispViews = 1;
// display dimensions?
$gal_dispDimensions = 0;
// display filesize?
$gal_dispSize = 0;
// display picture description?
$gal_dispDescription = 1;
// display # comments
$gal_dispNumComments = 0;

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats = "";
// select only from the following cats - leave empty for all - NOTE:($gal_disallowCats overrides)
// example: $gal_allowCats = "1,3,4" - show only categories 1, 3, and 4
$gal_allowCats = "";
// Require the user has allowedTo('smfgallery_view') permission to view random pics thumbnails in block?
$gal_viewPermission = 1;

/*
****************************************
****************************************
***  !! END Admin Config Section !!  ***
****************************************
****************************************
*/

//###############################################
//###############################################
//   You shouldn't change anything below here
//###############################################
//###############################################

if (empty($modSettings['gallery_url'])){
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$gal_textclass = empty($gal_smalltext) ? "normaltext" : "smalltext";

// get this user's buddy list
$gal_buddylist = implode(",", $user_info['buddies']);

// prep for our switch routine
if (empty($gal_showtype))
    $gal_showtype = 0;

// sort text
if (empty($gal_sort)){
    $gal_sort_text = 'DESC';
} else {
    $gal_sort_text = '';
}

// are we viewing a member profile and $gal_profile is enabled?
if (!empty($gal_profile) && strtolower($context['current_action']) == "profile"){
    $gal_member = empty($_GET['u']) ? $ID_MEMBER : $_GET['u'];
}
// allow member to view random pic based on security settings
if (empty($gal_viewPermission) || allowedTo('smfgallery_view')){
    $gal_query = '
            SELECT
                thumbfilename,
                ID_PICTURE,
                ID_MEMBER,
                date,
                title,
                description,
                views,
                filesize,
                height,
                width,
                commenttotal,
                ID_CAT
            FROM '.$db_prefix.'gallery_pic
            WHERE approved = 1
            '.(empty($gal_member) ? (empty($gal_buddies) ? "" : (empty($gal_buddylist) ? "AND ID_MEMBER = NULL " : "AND ID_MEMBER in ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member" ).'
            '.(empty($gal_disallowCats) ? "" : "    AND ID_CAT NOT IN ($gal_disallowCats)").'
            '.(empty($gal_allowCats) ? "" : "    AND ID_CAT IN ($gal_allowCats)").'
            GROUP BY thumbfilename ';

    switch ($gal_showtype){
        // most/least recent
        case 1:
            $gal_query .= '
                    ORDER BY date '.$gal_sort_text;
            break;

        // most/least viewed
        case 2:
            $gal_query .= '
                    ORDER BY views '.$gal_sort_text;
            break;

        // most/least commented
        case 3:
            $gal_query .= '
                    ORDER BY commenttotal '.$gal_sort_text;
            break;

        default:
            $gal_query .= '
                    ORDER BY rand() '.$gal_sort_text;
            break;
    }
    $gal_query .= (empty($_GET['gal_viewall']) && !empty($gal_numpics)) ? ' LIMIT '.$gal_numpics : '';
    $gal_result = mysql_query($gal_query);
    if (!$gal_result){
        // error retrieving information from database
        if (mysql_errno() == 1146){
            echo '<p />Error, no database found!<p />';
        } else {
            echo '<p />MySQL error:'.mysql_error().'<p />';
        }
    } else {
        echo "\n".'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%">'."\n";
   
        $gal_colcnt = 1;
        echo "    <tr>\n";
        while ($row = mysql_fetch_assoc($gal_result)){
            if ($gal_colcnt > $gal_columns){
                // close out the row and start a new row
                echo "    </tr>\n    <tr>\n".'        <td colspan="'.$gal_columns.'"><hr /></td>'."\n    </tr>\n    <tr>\n";
                // reset count to column 1
                $gal_colcnt = 1;
            }
            echo    '        <td class="'.$gal_textclass.'" align="center">'."\n";
            // display title if enabled, make edit link if viewing user is picture poster
            if (!empty($gal_dispTitle)){
                echo "            ".($ID_MEMBER == $row['ID_MEMBER'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>') : $row['title'])."<br />\n";
            }
            // display the picture thumbnail and link it to gallery full picture
            echo    '            <a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'"><img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" /></a><br />'."\n";
            // display poster's name and posted date if enabled
            if (!empty($gal_dispMember) || !empty($gal_dispDate)){
                echo 'Posted';
                if (!empty($gal_dispMember)){
                    // display the membername who posted pic?  need to get name based on ID_MEMBER
                    $gal_tmp = mysql_fetch_assoc(mysql_query("SELECT memberName FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));
                    echo ' by <a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['memberName'].'</a>';
                }
                if (!empty($gal_dispDate)){
                    // display the date it was posted
                    echo ' on '.date("d M Y", $row['date']);
                }
                echo "<br />\n";
            }
            // display category if enabled
            if (!empty($gal_dispCategory)){
                // get category name based on category id
                $gal_tmp = mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
                echo '<br />in<br /><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title']."</a><br /><br />\n";
            }
            // display number of views if enabled
            if (!empty($gal_dispViews)){
                echo "Viewed ".$row['views']." times<br />\n";
            }
            // display dimensions if enabled
            if (!empty($gal_dispDimensions)){
                echo $row['width']."w X ".$row['height']."h<br />\n";
            }
            // display filesize if enabled
            if (!empty($gal_dispSize)){
                echo $row['filesize']." bytes<br />\n";
            }
            // display description if enabled
            if (!empty($gal_dispDescription)){
                echo "<br />".$row['description']."<br />\n";
            }
            // display # of comments if enabled
            if (!empty($gal_dispNumComments)){
                echo '<br /><i><a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'">'.$row['commenttotal']."</a> comment(s)</i><br />\n";
            }
            echo    "        </td>\n";
            $gal_colcnt++;
        }
        mysql_free_result($gal_result);
        echo "    </tr>\n</table>\n";
        if (!empty($gal_member) && empty($_GET['gal_viewall']))
            echo '<br /><a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pics from this member</a>';
        if (!empty($gal_buddies) && empty($_GET['gal_viewall'])){
            // build the link
            $gal_querystring = $context['TPortal']['querystring'];
            $gal_querystring .= empty($gal_querystring) ? 'gal_viewall=1' : ';gal_viewall=1';
            echo '<br /><a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pics of buddies</a>';
        }
    }
} else {
    echo 'Sorry, you do not have permission to view pictures!';
}
Don't Follow Me I Have No Idea What I'm Doing

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15123
    • View Profile
Re: Gallery Random Picture block for TP
« Reply #1 on: October 15, 2010, 03:26:07 pm »
Updated the parts that I can see would not work with SMF 2.0 don't know what changed or was updated in TP though for 2.0

Code: [Select]
<?php

////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.8          //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 9/26/2008
// 1.8
//        - added display # of comments option
//
// Used in a TinyPortal phpblock or Article.
// This block displays random/most/least/newest/oldest picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

global $scripturl$db_prefix$modSettings$boardurl$ID_MEMBER$user_info$context;

/*
****************************************
****************************************
***    !! Admin Config Section !!    ***
****************************************
****************************************
*/

//   *****   LAYOUT OPTIONS   *****
// how many pictures do you want to show?  0 = all!
$gal_numpics 1;

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype 0;
// sort :: 0 = Descending, 1 = Ascending
$gal_sort 0;

// enable profile pics display?
// 0 = disable, 1 = enable --- if enabled, and you are viewing a member profile, show pics from that member only
// other options still apply (showtype, sort order, etc)
$gal_profile 1;

// only show pics from buddies?
// 0 = disable, 1 = enable --- if enabled, will only show pics posted by members in your buddy list
$gal_buddies 0;

// use Normal Size Text, or Small Size Text? (0 = Normal Size, 1 = Small Size)
$gal_smalltext 1;

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle 1;
// display membername who posted pic?
$gal_dispMember 0;
// display posted date?
$gal_dispDate 0;
// display category the picture is in?
$gal_dispCategory 1;
// display number of views?
$gal_dispViews 1;
// display dimensions?
$gal_dispDimensions 0;
// display filesize?
$gal_dispSize 0;
// display picture description?
$gal_dispDescription 1;
// display # comments
$gal_dispNumComments 0;

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats "";
// select only from the following cats - leave empty for all - NOTE:($gal_disallowCats overrides)
// example: $gal_allowCats = "1,3,4" - show only categories 1, 3, and 4
$gal_allowCats "";
// Require the user has allowedTo('smfgallery_view') permission to view random pics thumbnails in block?
$gal_viewPermission 1;

/*
****************************************
****************************************
***  !! END Admin Config Section !!  ***
****************************************
****************************************
*/

//###############################################
//###############################################
//   You shouldn't change anything below here
//###############################################
//###############################################

if (empty($modSettings['gallery_url'])){
    
$modSettings['gallery_url'] = $boardurl '/gallery/';
}

$gal_textclass = empty($gal_smalltext) ? "normaltext" "smalltext";

// get this user's buddy list
$gal_buddylist implode(","$user_info['buddies']);

// prep for our switch routine
if (empty($gal_showtype))
    
$gal_showtype 0;

// sort text
if (empty($gal_sort)){
    
$gal_sort_text 'DESC';
} else {
    
$gal_sort_text '';
}

// are we viewing a member profile and $gal_profile is enabled?
if (!empty($gal_profile) && strtolower($context['current_action']) == "profile"){
    
$gal_member = empty($_GET['u']) ? $user_info['id'] : $_GET['u'];
}
// allow member to view random pic based on security settings
if (empty($gal_viewPermission) || allowedTo('smfgallery_view')){
    
$gal_query '
            SELECT 
                thumbfilename, 
                ID_PICTURE, 
                ID_MEMBER, 
                date, 
                title, 
                description, 
                views, 
                filesize, 
                height, 
                width, 
                commenttotal, 
                ID_CAT 
            FROM '
.$db_prefix.'gallery_pic 
            WHERE approved = 1 
            '
.(empty($gal_member) ? (empty($gal_buddies) ? "" : (empty($gal_buddylist) ? "AND ID_MEMBER = NULL " "AND ID_MEMBER in ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member).'
            '
.(empty($gal_disallowCats) ? "" "    AND ID_CAT NOT IN ($gal_disallowCats)").'
            '
.(empty($gal_allowCats) ? "" "    AND ID_CAT IN ($gal_allowCats)").'
            GROUP BY thumbfilename '
;

    switch (
$gal_showtype){
        
// most/least recent
        
case 1:
            
$gal_query .= '
                    ORDER BY date '
.$gal_sort_text;
            break;

        
// most/least viewed
        
case 2:
            
$gal_query .= '
                    ORDER BY views '
.$gal_sort_text;
            break;

        
// most/least commented
        
case 3:
            
$gal_query .= '
                    ORDER BY commenttotal '
.$gal_sort_text;
            break;

        default:
            
$gal_query .= '
                    ORDER BY rand() '
.$gal_sort_text;
            break;
    }
    
$gal_query .= (empty($_GET['gal_viewall']) && !empty($gal_numpics)) ? ' LIMIT '.$gal_numpics '';
    
$gal_result mysql_query($gal_query);
    if (!
$gal_result){
        
// error retrieving information from database
        
if (mysql_errno() == 1146){
            echo 
'<p />Error, no database found!<p />';
        } else {
            echo 
'<p />MySQL error:'.mysql_error().'<p />';
        }
    } else {
        echo 
"\n".'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%">'."\n";
    
        
$gal_colcnt 1;
        echo 
"    <tr>\n";
        while (
$row mysql_fetch_assoc($gal_result)){
            if (
$gal_colcnt $gal_columns){
                
// close out the row and start a new row
                
echo "    </tr>\n    <tr>\n".'        <td colspan="'.$gal_columns.'"><hr /></td>'."\n    </tr>\n    <tr>\n";
                
// reset count to column 1
                
$gal_colcnt 1;
            }
            echo    
'        <td class="'.$gal_textclass.'" align="center">'."\n";
            
// display title if enabled, make edit link if viewing user is picture poster
            
if (!empty($gal_dispTitle)){
                echo 
"            ".($user_info['id'] == $row['ID_MEMBER'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>') : $row['title'])."<br />\n";
            }
            
// display the picture thumbnail and link it to gallery full picture
            
echo    '            <a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'"><img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" /></a><br />'."\n";
            
// display poster's name and posted date if enabled
            
if (!empty($gal_dispMember) || !empty($gal_dispDate)){
                echo 
'Posted';
                if (!empty(
$gal_dispMember)){
                    
// display the membername who posted pic?  need to get name based on ID_MEMBER
                    
$gal_tmp mysql_fetch_assoc(mysql_query("SELECT real_name FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));
                    echo 
' by <a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['real_name'].'</a>';
                }
                if (!empty(
$gal_dispDate)){
                    
// display the date it was posted
                    
echo ' on '.date("d M Y"$row['date']);
                }
                echo 
"<br />\n";
            }
            
// display category if enabled
            
if (!empty($gal_dispCategory)){
                
// get category name based on category id
                
$gal_tmp mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
                echo 
'<br />in<br /><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title']."</a><br /><br />\n";
            }
            
// display number of views if enabled
            
if (!empty($gal_dispViews)){
                echo 
"Viewed ".$row['views']." times<br />\n";
            }
            
// display dimensions if enabled
            
if (!empty($gal_dispDimensions)){
                echo 
$row['width']."w X ".$row['height']."h<br />\n";
            }
            
// display filesize if enabled
            
if (!empty($gal_dispSize)){
                echo 
$row['filesize']." bytes<br />\n";
            }
            
// display description if enabled
            
if (!empty($gal_dispDescription)){
                echo 
"<br />".$row['description']."<br />\n";
            }
            
// display # of comments if enabled
            
if (!empty($gal_dispNumComments)){
                echo 
'<br /><i><a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'">'.$row['commenttotal']."</a> comment(s)</i><br />\n";
            }
            echo    
"        </td>\n";
            
$gal_colcnt++;
        }
        
mysql_free_result($gal_result);
        echo 
"    </tr>\n</table>\n";
        if (!empty(
$gal_member) && empty($_GET['gal_viewall']))
            echo 
'<br /><a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pics from this member</a>';
        if (!empty(
$gal_buddies) && empty($_GET['gal_viewall'])){
            
// build the link
            
$gal_querystring $context['TPortal']['querystring'];
            
$gal_querystring .= empty($gal_querystring) ? 'gal_viewall=1' ';gal_viewall=1';
            echo 
'<br /><a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pics of buddies</a>';
        }
    }
} else {
    echo 
'Sorry, you do not have permission to view pictures!';
}
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Rafferty

  • Full Member
  • ***
  • Posts: 159
    • View Profile
    • Australian Air Defence Artillery Association
Re: Gallery Random Picture block for TP
« Reply #2 on: October 15, 2010, 04:03:02 pm »
Great Hacks, just had to remove the <?php

Again thanks for your efforts
Don't Follow Me I Have No Idea What I'm Doing

 

Related Topics

  Subject / Started by Replies Last post
112 Replies
127659 Views
Last post March 08, 2009, 11:52:44 am
by Raji
1 Replies
4032 Views
Last post February 18, 2008, 08:03:27 am
by Ken.
4 Replies
3507 Views
Last post June 18, 2010, 09:18:00 am
by dvera
1 Replies
2608 Views
Last post October 16, 2016, 12:12:51 pm
by exit
5 Replies
2913 Views
Last post July 12, 2017, 03:45:34 pm
by donk

+- Recent Topics

Moving pictures to another user personal gallery by Hatshepsut
August 10, 2020, 11:07:26 pm

Rebuild related images time too long by SMFHacks
August 09, 2020, 01:52:57 pm

Call to undefined function mysql_num_rows() by SMFHacks
July 30, 2020, 07:45:29 am

Problem with one videosite embedding by Hatshepsut
July 24, 2020, 01:25:08 am

Download System Lite by Rock Lee
June 03, 2020, 07:34:24 pm

Font question by SMFHacks
May 27, 2020, 08:15:26 am

Error message with latest SMF 2.1 Github build by Hatshepsut
May 25, 2020, 01:43:26 am

smfblog not working on 2.0.17 by tech9
May 20, 2020, 01:44:34 pm

Copyright removal by stbc
May 18, 2020, 01:27:57 am

Mod Verified User i can't square the image by Rock Lee
May 07, 2020, 07:56:10 pm

Powered by EzPortal