============================================================================================================================
Modification Title: Download Center

Version: 1.0

Author: John Briggs

Back-ported for XMB 1.9.5 Nexus by: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

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

Copyright:  2010 John Briggs. All Rights Reserved.

Compatibility: XMB 1.9.5 SP1

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 package.

Author Note: This modification is developed and released for use with XMB 1.9.5 SP1 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, 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:
==========

require_once(ROOT.'lang/'.$langfile.'.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.'/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.user.inc.php
===========================
==========
Find Code:
==========

         global $table_forums, $table_favorites, $table_buddys, $table_u2u, $table_logs;
         
===============
Add Code Below:
===============

         // Download Center Mod Begin
         global $table_files, $table_files_comments;
         // Download Center Mod End

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

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

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

        // Download Center Mod Begin
        $db->query("UPDATE $table_files_comments SET author='$userto' WHERE author='$userfrom'");
        $db->query("UPDATE $table_files_comments SET updatedby='$userto' WHERE updatedby='$userfrom'");
        $db->query("UPDATE $table_files SET creator='$userto' WHERE creator='$userfrom'");
        $db->query("UPDATE $table_files SET submitby='$userto' WHERE submitby='$userfrom'");
        // Download Center Mod End

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

        $query = $db->query("SELECT fid, lastpost FROM $table_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 $table_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 $table_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 $table_files_categories SET viewlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, ratelist FROM $table_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 $table_files_categories SET ratelist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, commentlist FROM $table_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 $table_files_categories SET commentlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, downloadlist FROM $table_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 $table_files_categories SET downloadlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, submitlist FROM $table_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 $table_files_categories SET submitlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, uploadlist FROM $table_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 $table_files_categories SET uploadlist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, emaillist FROM $table_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 $table_files_categories SET emaillist='".$parts."' WHERE id='".$list['id']."'");
        }
        $db->free_result($query);

        $query = $db->query("SELECT id, downloadlist FROM $table_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 $table_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: misc.php
===============
==========
Find Code:
==========

require_once('header.php');

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

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

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

    } elseif (false !== strpos($url, 'fid')  && false === strpos($url, "/post.php")) {

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

    // Download Center Mod Begin
    } elseif (false !== strpos($url, '/files.php')) {
        $catarray = files_category_array();
        $catlist = "'".implode("', '", $catarray)."'";
        $query = $db->query("SELECT id, name FROM $table_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);
                } elseif (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 $table_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';
            }
        } elseif (false !== strpos($url, '/files_stats.php')) {
            $location = $lang['viewingstats'];
        } elseif (false !== strpos($url, '/files_faq.php')) {
            $location = $lang['viewingfaqs'];
        } elseif (false !== strpos($url, '/files.php')) {
            if (false !== strpos($url, 'category') && in_array($id, $catarray)) {
                $location = $lang['viewingcat'].' '.$catname[$id];
            } elseif (false !== strpos($url, 'submit') && in_array($id, $catarray)) {
                $location = $lang['submittingfile'].' '.$catname[$id];
            } elseif (false !== strpos($url, 'action=file')) {
                $location = $lang['viewingfile'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'action=email')) {
                $location = $lang['emailingfile'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'action=report')) {
                $location = $lang['reportingfile'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'action=license')) {
                $location = $lang['viewinglicense'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'action=download')) {
                $location = $lang['downloadingfile'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'action=search')) {
                $location = $lang['searchdownload'];
            } elseif (false !== strpos($url, 'action=viewall')) {
                $location = $lang['viewalldownload'];
            } elseif (false !== strpos($url, 'action=rate')) {
                $location = $lang['rateingfile'];
            } else {
                $location = $lang['downloadsonline'];
            }
        } elseif (false !== strpos($url, '/files_comments.php')) {
            if (false !== strpos($url, 'new')) {
                $location = $lang['commentsonline'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'edit')) {
                $location = $lang['editcommentsonline'].' '.$filename[$id];
            } elseif (false !== strpos($url, 'report')) {
                $location = $lang['reportcommentsonline'].' '.$filename[$id];
            } else {
                $location = $lang['downloadsonline'];
            }
        }
    // 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!