Title: Download Center

Version: 1.0

Author: John Briggs

Description: This modification will add a download section to your board with full administration controls.

Copyright:  2009 John Briggs. All rights reserved.

Compatibility: XMB 1.9.8 SP4

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

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

Author Note: This modification is developed and released for use with XMB 1.9.8 SP4 which is provided by XMBGarage.com.

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

Please upload the following files to your forum 'root' directory.

files_comments.php, files.php, files_faq.php, files_admin.php, files_stats.php, files_upload.php, install.php, files.xmb

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

Please upload the following file to your 'lang' directory.

English.files.php

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

Please upload the following file to your 'include' directory.

files.inc.php

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

Please upload the following files to your 'theme' directories.

comment.gif, download.gif, error.gif, confirm.gif, top_files.gif, files_admin.gif, files_stats.gif, files_faq.gif, files_search.gif

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

Please upload the following folder named 'downloads' to your forum 'root' directory and CHMOD it to 777.

'downloads'

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

=================
Edit File: header.php
=================
==========
Find Code:
==========

    'forums',

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

    'files',
    'files_categories',
    'files_comments',
    'files_custom',
    'files_custom_data',
    'files_licenses',
    'files_votes',
    'forums',

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

if (file_exists(ROOT.'lang/'.$langfile.'.lang.php')) {
    require ROOT.'lang/'.$langfile.'.lang.php';
} else {
    require ROOT.'lang/English.lang.php';
}

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

// Download Center Mod Begin
if (file_exists(ROOT.'lang/'.$langfile.'.files.php')) {
    require_once(ROOT.'lang/'.$langfile.'.files.php');
} else {
    require_once(ROOT.'lang/English.files.php');
}
// Download Center Mod End

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

if ($SETTINGS['stats'] == 'on') {
    $links[] = '<img src="'.$imgdir.'/top_stats.gif" alt="'.$lang['altstats'].'" border="0" /> <a href="stats.php"><font class="navtd">'.$lang['navstats'].'</font></a>';
}

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

// Download Center Mod Begin
if ($SETTINGS['files_status'] == 'on') {
    $links[] = '<img src="'.$imgdir.'/top_files.gif" alt="'.$lang['downloadcenter'].'" border="0" /> <a href="files.php"><font class="navtd">'.$lang['downloadcenter'].'</font></a>';
}
// Download Center Mod End

=======================================================================================================================================
=======
Step 7:
=======

=======================
Edit File: include/admin.inc.php
=======================
==========
Find Code:
==========

        $db->query("UPDATE ".X_PREFIX."whosonline SET username='$userto' WHERE username='$userfrom'");

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

        // Download Center Mod Begin

        $db->query("UPDATE ".X_PREFIX."files_comments SET author='$userto' WHERE author='$userfrom'");
        $db->query("UPDATE ".X_PREFIX."files_comments SET updatedby='$userto' WHERE updatedby='$userfrom'");
        $db->query("UPDATE ".X_PREFIX."files SET creator='$userto' WHERE creator='$userfrom'");
        $db->query("UPDATE ".X_PREFIX."files SET submitby='$userto' WHERE submitby='$userfrom'");
        // Download Center Mod End

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

        $query = $db->query("SELECT fid, lastpost FROM ".X_PREFIX."forums WHERE lastpost LIKE '%$userfrom'");
        while($result = $db->fetch_array($query)) {
            list($posttime, $lastauthor, $lastpid) = explode("|", $result['lastpost']);
            if ($lastauthor == $userfrom) {
                $newlastpost = $posttime . '|' . $userto.'|'.$lastpid;
                $db->query("UPDATE ".X_PREFIX."forums SET lastpost='$newlastpost' WHERE fid='".$result['fid']."'");
            }
        }
        $db->free_result($query);

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

        // Download Center Mod Begin
        $query = $db->query("SELECT id, viewlist FROM ".X_PREFIX."files_categories WHERE viewlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['viewlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET viewlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, ratelist FROM ".X_PREFIX."files_categories WHERE ratelist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['ratelist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET ratelist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, commentlist FROM ".X_PREFIX."files_categories WHERE commentlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['commentlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET commentlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, downloadlist FROM ".X_PREFIX."files_categories WHERE downloadlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['downloadlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET downloadlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, submitlist FROM ".X_PREFIX."files_categories WHERE submitlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['submitlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET submitlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, uploadlist FROM ".X_PREFIX."files_categories WHERE uploadlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['uploadlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET uploadlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, emaillist FROM ".X_PREFIX."files_categories WHERE emaillist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['emaillist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files_categories SET emaillist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, downloadlist FROM ".X_PREFIX."files WHERE downloadlist LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['downloadlist']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."files SET downloadlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);
        // Download Center Mod End

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

    &raquo;&nbsp;<a href="cp2.php?action=themes"><?php echo $lang['themes']?></a><br />

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

    <!-- Download Center Mod Begin -->
    &raquo;&nbsp;<a href="files_admin.php"><?php echo $lang['downloadsadmin']?></a><br />
    <!-- Download Center Mod End -->

=======================================================================================================================================
=======
Step 8:
=======
==================
Edit File: online.inc.php
==================
==========
Find Code:
==========

    static $restrict,

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

    static $restrict, $filename, $catname,

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

    } else if (false !== strpos($url, '/post.php')) {

===============
Add Code Above:
===============

    // Download Center Mod Begin
    } else if (false !== strpos($url, '/files.php')) {
        $catarray = files_category_array();
        $catlist = "'".implode("', '", $catarray)."'";
        $query = $db->query("SELECT id, name FROM ".X_PREFIX."files_categories WHERE id IN ($catlist)");
        while($locate = $db->fetch_array($query)) {
            $catname[$locate['id']] = $locate['name'];
        }
        $db->free_result($query);

        if (false !== strpos($url, 'id')) {
            $temp = explode('?', $url);
            $urls = explode('&', $temp[1]);
            foreach($urls as $key=>$val) {
                if (strpos($val, 'fid') !== false) {
                    $id = (int) substr($val, 4);
                } else if (strpos($val, 'id') !== false && strpos($val, 'cid') === false) {
                    $id = (int) substr($val, 3);
                }
            }

            if (!isset($catname[$id])) {
                $catname[$id] = $lang['viewingunknown'];
            }

            if (!isset($filename[$id])) {
                $query = $db->query("SELECT name FROM ".X_PREFIX."files WHERE id='$id' AND catid IN ($catlist)");
                if ($db->num_rows($query) == 0) {
                    $filename[$id] = $lang['viewingunknown'];
                } else {
                    while($locate = $db->fetch_array($query)) {
                        $filename[$id] = $locate['name'];
                    }

                }
                $db->free_result($query);
            }
        }

        if (false !== strpos($url, '/files_admin.php') || false !== strpos($url, '/files_upload.php')) {
            $location = $lang['onlinecp'];
            if (!X_ADMIN) {
                $url = 'index.php';
            }
        } else if (false !== strpos($url, '/files_stats.php')) {
            $location = $lang['viewingstats'];
        } else if (false !== strpos($url, '/files_faq.php')) {
            $location = $lang['viewingfaqs'];
        } else if (false !== strpos($url, '/files.php')) {
            if (false !== strpos($url, 'category') && in_array($id, $catarray)) {
                $location = $lang['viewingcat'].' '.$catname[$id];
            } else if (false !== strpos($url, 'submit') && in_array($id, $catarray)) {
                $location = $lang['submittingfile'].' '.$catname[$id];
            } else if (false !== strpos($url, 'action=file')) {
                $location = $lang['viewingfile'].' '.$filename[$id];
            } else if (false !== strpos($url, 'action=email')) {
                $location = $lang['emailingfile'].' '.$filename[$id];
            } else if (false !== strpos($url, 'action=report')) {
                $location = $lang['reportingfile'].' '.$filename[$id];
            } else if (false !== strpos($url, 'action=license')) {
                $location = $lang['viewinglicense'].' '.$filename[$id];
            } else if (false !== strpos($url, 'action=download')) {
                $location = $lang['downloadingfile'].' '.$filename[$id];
            } else if (false !== strpos($url, 'action=search')) {
                $location = $lang['searchdownload'];
            } else if (false !== strpos($url, 'action=viewall')) {
                $location = $lang['viewalldownload'];
            } else if (false !== strpos($url, 'action=rate')) {
                $location = $lang['rateingfile'];
            } else {
                $location = $lang['downloadsonline'];
            }
        } else if (false !== strpos($url, '/files_comments.php')) {
            if (false !== strpos($url, 'new')) {
                $location = $lang['commentsonline'].' '.$filename[$id];
            } else if (false !== strpos($url, 'edit')) {
                $location = $lang['editcommentsonline'].' '.$filename[$id];
            } else if (false !== strpos($url, 'report')) {
                $location = $lang['reportcommentsonline'].' '.$filename[$id];
            } else {
                $location = $lang['downloadsonline'];
            }
        }
    // Download Center Mod End

=======================================================================================================================================
=======
Step 9:
=======
===============
Edit File: misc.php
===============
==========
Find Code:
==========

require ROOT.'include/online.inc.php';

===============
Add Code Above:
===============

// Download Center Mod Begin
require ROOT.'include/files.inc.php';
// Download Center Mod End

=======================================================================================================================================
========
Step 10:
========

Please run install.php from your forum 'root' directory.

=======================================================================================================================================
========
Step 11:
========

Please delete the following files from your forum 'root' directory.

install.php, files.xmb

=======================================================================================================================================
Enjoy!