Title: Photo Gallery v2.0

Author: Steven Waters, John Briggs

Contributors: Jack Faxon, Stalker, Spike, Bigdumredneck, Elmo

Description:
This mod will provide a photo gallery to your xmb board.

Copyright:  2006 XMBMods.com

Compatability: XMB 1.9.5 Final

Install Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License. A copy is provided with this software.

Author Note:
Please feel free to improve this modification so long as you abide by the GNU GPL license and respect my copyrights.


=======================================================================================================================
=======
Step 1:
=======

Copy all the php files from the Contents folder EXCEPT for gallery_upgrade.php and gallery.function.inc.php to your XMB folder.
Copy the img_templates.xmb file to your XMB folder.

=======================================================================================================================
=======
Step 2:
=======

Copy the contents of the Gallery lang folder to your XMB lang folder.

=======================================================================================================================
=======
Step 3:
=======

Copy gallery.function.inc.php to your Include folder

=======================================================================================================================
=======
Step 4:
=======

Copy the '.gif' files from the images folder to your theme folders

=======================================================================================================================
=======
Step 5:
=======

===================
Edit 'cp.php'
===================

==========
Find Code:
==========

        $avataron = $avataroff = $avatarlist = '';
        if ($SETTINGS['avastatus'] == "on") {
            $avataron = $selHTML;
        } elseif ($avastatus == "list") {
            $avatarlist = $selHTML;
        } else {
            $avataroff = $selHTML;
        }

===============
Add Code Below:
===============
        
        // Photo Gallery Mod Begin
        $photogalleryon = $photogalleryoff = '';
        switch ($SETTINGS['photogallerystatus']) {
            case 'on':
                $photogalleryon = $selHTML;
                break;
            default;
                $photogalleryoff = $selHTML;
                break;
        }
        // Photo Gallery Mod End

==========
Find Code:
==========

        printsetting1($lang['reportpoststatus'], 'reportpostnew', $reportposton, $reportpostoff);

===============
Add Code Below:
===============

        // Photo Gallery Mod Begin
        printsetting1($lang['img_gallerystatus'], 'photogallerystatusnew', $photogalleryon, $photogalleryoff, $langfile);
        // Photo Gallery Mod End

==========
Find Code:
==========

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

===============
Add Code Below:
===============

        // Photo Gallery Mod Begin
        $photogallerystatusnew = ($photogallerystatusnew == 'on') ? 'on' : 'off';
        // Photo Gallery Mod End

==========
Find Code:
==========

        $db->query("UPDATE $table_settings SET langfile='$langfilenew'

=================================
Add Code To End of Statement Before: ");
=================================

, photogallerystatus='$photogallerystatusnew'

===========================================================================================================================

===================
Edit 'header.php'
===================

==========
Find Code:
==========

    require ROOT."lang/$langfile.lang.php";

==========
Add below:
==========

    // Photo Gallery Mod Begin
    if (file_exists(ROOT.'lang/'.$langfile.'.gallery.php')) {
        require_once(ROOT.'lang/'.$langfile.'.gallery.php');
    } else {
        require_once(ROOT.'lang/English.gallery.php');
    }
    // Photo Gallery Mod End

==========
Find Code:
==========

,'forums','logs'

=================
Replace Code With:
=================

,'forums','imgcats','imgsettings','imgimages','imgvotes','imgcomments','imgimagedata','imgthumbnails','logs'

==========
Find Code:
==========

    $links = implode(' &nbsp; ', $links);

==========
Add above:
==========

    // Photo Gallery-link
    if ($SETTINGS['gallerystatus'] == 'on') {
        $links[] = '<img src="'.$imgdir.'/camera.gif" alt="'.$lang['img_textphotogallery'].'" border="0" /> <a href="gallery.php"><font class="navtd">'.$lang['img_textphotogallery'].'</font></a>';
    }

=======================================================================================================================
=======
Step 6:
=======

===================
Edit 'admin.user.inc.php'
===================

==========
Find Code:
==========

        global $table_forums, $table_favorites, $table_buddys, $table_u2u, $table_logs;

==========
Add Below:
==========

        // Photo Gallery Mod Begin
        global $table_imgimages, $table_imgvotes, $table_imgcats;
        // Photo Gallery Mod End


==========
Find Code:
==========

        return (($self['username'] == $userfrom) ? $lang['admin_rename_warn_self'] : '') . $lang['admin_rename_success'];

==========
Add above:
==========

        // Photo Gallery Mod Begin
        // Update the images, albums and votes.
        $db->query("UPDATE $table_imgimages SET author='$userto' WHERE author='$userfrom'");
        $db->query("UPDATE $table_imgcats SET author='$userto' WHERE author='$userfrom'");
        $db->query("UPDATE $table_imgvotes SET username='$userto' WHERE username='$userfrom'");

        // Update the last post in the albums
        $query = $db->query("SELECT cid, lastpost from $table_imgcats WHERE lastpost like '%$userfrom'");
        while ($result = $db->fetch_array($query)) {
            list($posttime, $lastauthor) = explode("|", $result['lastpost']);
            if ($lastauthor == $userfrom) {
                $newlastpost = $posttime.'|'.$userto;
                $db->query("UPDATE $table_imgcats SET lastpost='$newlastpost' WHERE cid='".$result['cid']."'");
            }
        }
        $db->free_result($query);

        // Update the view list for the albums
        $query = $db->query("SELECT view_list, cid FROM $table_imgcats WHERE (view_list REGEXP '(^|(,))( )*$userfrom( )*((,)|$)')");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['view_list']);
            $index = array_search($userfrom, $parts);
            $parts[$index] = $userto;
            $parts = implode(', ', $parts);
            $db->query("UPDATE $table_imgcats SET view_list='".$parts."' WHERE cid='".$list['cid']."'");
        }
        $db->free_result($query);

        // Update the add list for the albums
        $query = $db->query("SELECT add_list, cid FROM $table_imgcats WHERE (view_list REGEXP '(^|(,))( )*$userfrom( )*((,)|$)')");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['add_list']);
            $index = array_search($userfrom, $parts);
            $parts[$index] = $userto;
            $parts = implode(', ', $parts);
            $db->query("UPDATE $table_imgcats SET add_list='".$parts."' WHERE cid='".$list['cid']."'");
        }
        $db->free_result($query);
        // Photo Gallery Mod End

=======================================================================================================================
=======
Step 7:
=======
===================
Edit 'misc.php'
===================

==========
Find Code:
==========

    require "./header.php";

==========
Add Below:
==========

    // Photo Gallery Mod Begin
    require_once(ROOT.'include/gallery.functions.inc.php');
    // Photo Gallery Mod End

==========
Find Code:
==========

    global $db, $table_forums, $table_threads, $lang, $self;
    static $restrict, $rset, $fname, $tsub;

=============
Replace with:
=============

    // Photo Gallery Mod Begin
    global $db, $table_forums, $table_threads, $lang, $self, $table_imgsettings, $table_imgcats, $table_imgimages;
    static $restrict, $rset, $fname, $tsub, $albumname, $imagename;

    $query  = $db->query("SELECT who_view_gallery FROM $table_imgsettings");
    $who_view_gallery = $db->result($query, 0);
    $db->free_result($query);
    // Photo Gallery Mod End

==========
Find Code:
==========

    } else {
        $location = $url;
    }

=============
Replace with:
=============
    // Photo Gallery Mod begin
    } elseif (false !== strpos($url, "gallery")) {
        if (privfcheck($who_view_gallery,'')) {
            if (false !== strpos($url, 'cid')) {
                $temp = explode('?', $url);
                $urls = explode('&', $temp[1]);
                foreach ($urls as $key=>$val) {
                    if (strpos($val, 'cid') !== false) {
                        $cid = (int) substr($val, 4);
                    }
                }
                if (!isset($albumname[$cid])) {
                    $query = $db->query("SELECT name FROM $table_imgcats WHERE cid='$cid'");
                    while ($locate = $db->fetch_array($query)) {
                        $albumname[$cid] = $locate['name'];
                    }
                    $db->free_result($query);
                }
            }
            if (false !== strpos($url, 'iid')) {
                $temp = explode('?', $url);
                $urls = explode('&', $temp[1]);
                foreach ($urls as $key=>$val) {
                    if (strpos($val, 'iid') !== false) {
                        $iid = (int) substr($val, 4);
                    }
                }
                if (!isset($imagename[$iid])) {
                    $query = $db->query("SELECT name FROM $table_imgimages WHERE iid='$iid'");
                    while ($locate = $db->fetch_array($query)) {
                        $imagename[$iid] = $locate['name'];
                    }
                    $db->free_result($query);
                }
            }
            if (false !== strpos($url, '/gallery_admin.php')) {
                $location = $lang['img_onlinecp'];
                if (!X_ADMIN) {
                    $url = 'index.php';
                 }
            } elseif (false !== strpos($url, '/gallery.php')) {
                $location = $lang['img_onlineviewgallery'];
            } elseif (false !== strpos($url, '/gallery_view_album.php')  && gallery_viewalbumperm($cid)) {
                 $location = $lang['img_onlineviewalbum'].' '.$albumname[$cid];
            } elseif (false !== strpos($url, '/gallery_user_album.php') && gallery_viewalbumperm($cid)) {
                if (false !== strpos($url, 'create')) {
                    $location = $lang['img_onlineaddalbum'];
                } elseif (false !== strpos($url, 'edit')) {
                    $location = $lang['img_onlineeditalbum'].' '.$albumname[$cid];
                } elseif (false !== strpos($url, 'delete')) {
                    $location = $lang['img_onlinedeletealbum'].' '.$albumname[$cid];
                }
            } elseif (false !== strpos($url, '/gallery_image.php') && gallery_viewalbumperm($cid)) {
                if (false !== strpos($url, 'add')) {
                    $location = $lang['img_onlineaddimage'].' '.$albumname[$cid];
                } elseif (false !== strpos($url, 'upload')) {
                    $location = $lang['img_onlineuploadimage'].' '.$albumname[$cid];
                } elseif (false !== strpos($url, 'edit')) {
                    $location = $lang['img_onlineeditimage'].' '.$imagename[$iid];
                } elseif (false !== strpos($url, 'delete')) {
                    $location = $lang['img_onlinedeleteimage'].' '.$imagename[$iid];
                }
            } elseif (false !== strpos($url, '/gallery_comments.php') && gallery_viewalbumperm($cid)) {
                if (false !== strpos($url, 'reply')) {
                    $location = $lang['img_onlinereplycomment'].' '.$imagename[$iid];
                } elseif (false !== strpos($url, 'edit')) {
                    $location = $lang['img_onlineeditcomment'].' '.$imagename[$iid];
                }
            } elseif (false !== strpos($url, '/gallery_stats.php')) {
                $location = $lang['img_onlineviewstatus'];
            } elseif (false !== strpos($url, '/gallery_search.php')) {
                $location = $lang['img_onlinesearch'];
            }
        }
    // Photo Gallery Mod end
    } else {
        $location = $url;
    }

=======================================================================================================================
=======
Step 8:
=======

    Run gallery_install.php, and follow the prompts.

    Delete gallery_install.php and img_templates.xmb after installation.

===============================================================================================================