Location: PHPKode > projects > XennoBB > xennobb/admin/modules.php
<?php
/*

  Copyright (C) 2005-2011 UserDot
  Visit XennoBB at www.userdot.net/projects/xennobb
  Originally based on PunBB www.punbb.org

  XennoBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  XennoBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301 USA

 */
define('IN_FORUM_ADMIN', 1);
require dirname(__FILE__) . '/../include/init.php';
if (!BB_Admin_Functions::Check_Permissions('modules'))
    BB_Functions::Message($lang['No permission']);
$cms_install_module = (isset($_GET['install']) && file_exists($cms_modules->path . $_GET['install'] . '/install/install.php')) ? $_GET['install'] : '';
$cms_uninstall_module = (isset($_GET['uninstall']) && file_exists($cms_modules->path . $_GET['uninstall'] . '/install/uninstall.php')) ? $_GET['uninstall'] : '';
$cms_enable_module = (isset($_GET['enable']) && in_array($_GET['enable'], $cms_modules->All_Elements())) ? $_GET['enable'] : '';
$cms_disable_module = (isset($_GET['disable']) && in_array($_GET['disable'], $cms_modules->All_Elements())) ? $_GET['disable'] : '';
$cms_delete_module = (isset($_GET['delete']) && in_array($_GET['delete'], $cms_modules->All_Elements())) ? $_GET['delete'] : '';
$cms_pack_module = (isset($_GET['pack']) && in_array($_GET['pack'], $cms_modules->All_Elements())) ? $_GET['pack'] : '';
$cms_info_module = (isset($_GET['info']) && in_array($_GET['info'], $cms_modules->All_Elements())) ? $_GET['info'] : '';
$cms_custom_title_page = $lang['Admin'] . $lang['manage_modules'];
$cms_main_template = BB_Template::Get_Template_Path('forum_admin');
require FORUM_ROOT . 'admin/header.php';
if (is_writable(FORUM_ROOT . 'include/modules') && !empty($_GET['module_url']))
{
    $module_url = BB_Input::Trim($_GET['module_url']);
    $parsed_url = parse_url($module_url);
    if (empty($parsed_url['scheme']) || !preg_match('/^http|ftp$/', $parsed_url['scheme']) || empty($parsed_url['host']) || empty($parsed_url['path']))
        BB_Functions::Message($lang['import_url_wrong']);
    else
    {
        if (($err = $cms_modules->install($module_url)) !== true)
            BB_Functions::Message($err);
        else
        {
            BB_Admin_Functions::Log_Action("Import module from " . $module_url, 3);
            BB_Functions::Redirect('modules.php', $lang['import_module_ok']);
        }
    }
}
if ($cms_install_module != '')
{
    $cms_constant_module = 'bb_module_' . $cms_install_module;
    if (!defined($cms_constant_module))
    {
        if (isset($_POST['install_module_ok']))
        {
            require $cms_modules->path . $cms_install_module . '/install/install.php';
            $cms_install_module_status = BB_Install_Module();
            if ($cms_install_module_status === true && BB_Cache::Add_Language($cms_install_module, 'module'))
            {
                BB_Admin_Functions::Log_Action('Install module ' . $cms_install_module, 2);
                ?>
                <div class="blockform">
                    <h2><span><?php echo $lang['install_module_ok']; ?></span></h2>
                    <div class="fakeform">
                        <div class="inform">
                            <div class="infldset file" style="padding:10px">
                                <p><?php echo $lang['install_module_finish']; ?></p>
                            </div>
                        </div>
                        <div><input type="button" class="b1" onclick="javascript:window.location.href='modules.php';" value="<?php echo $lang['Go back']; ?>" /></div>
                    </div>
                </div>
                <?php
            }
            elseif ($cms_install_module_status === false)
                BB_Functions::Message($lang['unable_install_module']);
            else
                BB_Functions::Message($cms_install_module_status);
        }
        else
        {
            ?>
            <div class="blockform">
                <h2><span><?php printf($lang['install_module'], $cms_install_module); ?></span></h2>
                <form method="post" action="modules.php?install=<?php echo $cms_install_module; ?>">
                    <input type="hidden" name="install_module_ok" value="1" />
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php printf($lang['install_module_ready_to'], $cms_install_module); ?></p><br />
                        </div>
                    </div>
                    <div><input type="button" class="b1" onclick="javascript:history.go(-1);" value="<?php echo $lang['Go back']; ?>" />&nbsp;&nbsp;&nbsp;<input class="b1" type="submit" value="<?php echo $lang['Install']; ?>" /></div>
                </form>
            </div>
            <?php
        }
    }
    else
    {
        ?>
        <div class="blockform">
            <h2><span><?php printf($lang['install_module'], $cms_install_module); ?></span></h2>
            <div class="fakeform">
                <div class="inform">
                    <div class="infldset file" style="padding:10px">
                        <p><?php echo $lang['module_seem_install']; ?></p><br />
                    </div>
                </div>
                <div><input type="button" class="b1" onclick="javascript:history.go(-1);" value="<?php echo $lang['Go back']; ?>" /></div>
            </div>
        </div>
        <?php
    }
}
elseif ($cms_uninstall_module != '')
{
    $cms_constant_module = 'bb_module_' . $cms_uninstall_module;
    if (defined($cms_constant_module))
    {
        if (isset($_POST['uninstall_module_downloads_ok']))
        {
            require $cms_modules->path . $cms_uninstall_module . '/install/uninstall.php';
            $cms_uninstall_module_status = BB_Uninstall_Module();
            if ($cms_uninstall_module_status === true && BB_Cache::Remove_Language($cms_uninstall_module, 'module'))
            {
                BB_Admin_Functions::Log_Action('Uninstall module ' . $cms_uninstall_module, 2);
                ?>
                <div class="blockform">
                    <h2><span><?php echo $lang['uninstall_module_ok']; ?></span></h2>
                    <div class="fakeform">
                        <div class="inform">
                            <div class="infldset file" style="padding:10px">
                                <p><?php echo $lang['uninstall_module_finish']; ?></p>
                            </div>
                        </div>
                        <div><input type="button" class="b1" onclick="javascript:window.location.href='modules.php';" value="<?php echo $lang['Go back']; ?>" /></div>
                    </div>
                </div>
                <?php
            }
            elseif ($cms_uninstall_module_status === false)
                BB_Functions::Message($lang['unable_install_module']);
            else
                BB_Functions::Message($cms_uninstall_module_status);
        }
        else
        {
            ?>
            <div class="blockform">
                <h2><span><?php printf($lang['uninstall_module'], $cms_uninstall_module); ?></span></h2>
                <form method="post" action="modules.php?uninstall=<?php echo $cms_uninstall_module; ?>">
                    <input type="hidden" name="uninstall_module_downloads_ok" value="1" />
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php printf($lang['uninstall_module_ready_to'], $cms_uninstall_module); ?></p><br />
                        </div>
                    </div>
                    <div><input type="button" class="b1" onclick="javascript:history.go(-1);" value="<?php echo $lang['Go back']; ?>" />&nbsp;&nbsp;&nbsp;<input type="submit" class="b1" value="<?php echo $lang['Uninstall']; ?>" /></div>
                </form>
            </div>
            <?php
        }
    }
    else
    {
        ?>
        <div class="blockform">
            <h2><span><?php printf($lang['uninstall_module'], $cms_uninstall_module); ?></span></h2>
            <div class="fakeform">
                <div class="inform">
                    <div class="infldset file" style="padding:10px">
                        <p><?php echo $lang['module_seem_not_install']; ?></p>
                    </div>
                </div>
                <div><input type="button" class="b1" onclick="javascript:history.go(-1);" value="<?php echo $lang['Go back']; ?>" /></div>
            </div>
        </div>
        <?php
    }
}
elseif ($cms_enable_module != '')
{
    $namespace = 'module_' . $cms_enable_module;
    $config_name = 'bb_module_' . $cms_enable_module;
    $cms_settings->Set_Namespace($namespace);
    $res = $cms_settings->Save($config_name, 1);
    $cms_settings->Set_Namespace('');
    if ($res)
    {
        BB_Admin_Functions::Log_Action("Enable module " . $cms_enable_module, 1);
        header('location: modules.php');
        exit;
    }
    else
        BB_Functions::Message($lang['unable_update_config']);
}
elseif ($cms_pack_module != '')
{
    $info_extension = array();
    if (file_exists($cms_modules->path . $cms_pack_module . '/install/info.php'))
        require $cms_modules->path . $cms_pack_module . '/install/info.php';
    else
        $info_extension['version'] = '';
    $fname = 'module-' . $cms_pack_module . '-' . $info_extension['version'];
    $cms_module_root = FORUM_ROOT . 'include/modules';
    if (($res = BB_Files::Make_Package($cms_pack_module, $cms_module_root . '/' . $cms_pack_module, $cms_module_root . '/', 1)) !== false)
    {
        if (($fp = fopen(FORUM_ROOT . 'var/export/' . $fname . '.pkg.gz', 'w')) !== false)
        {
            fwrite($fp, $res, BB_Input::Strlen($res));
            fclose($fp);
            BB_Admin_Functions::Log_Action('Export module ' . $cms_pack_module, 0);
            BB_Functions::Redirect('modules.php', $lang['export_ok']);
        }
        else
            BB_Functions::Message($lang['export_error']);
    }
    else
        BB_Functions::Message($lang['export_error']);
}
elseif ($cms_disable_module != '')
{
    $namespace = 'module_' . $cms_disable_module;
    $config_name = 'bb_module_' . $cms_disable_module;
    $cms_settings->Set_Namespace($namespace);
    $res = $cms_settings->Save($config_name, 0);
    $cms_settings->Set_Namespace('');
    if ($res)
    {
        BB_Admin_Functions::Log_Action("Disable module " . $cms_disable_module, 1);
        header('location: modules.php');
        exit;
    }
    else
        BB_Functions::Message($lang['unable_update_config']);
}
elseif ($cms_delete_module != '' && is_writable($cms_modules->path))
{
    BB_Files::Delete_Tree($cms_modules->path . $cms_delete_module);
    BB_Admin_Functions::Log_Action('Delete module ' . $cms_delete_module, 3);
    BB_Functions::Redirect('modules.php', $lang['config_updated']);
}
elseif ($cms_info_module != '')
{
    if (file_exists($cms_modules->path . $cms_info_module . '/install/info.php'))
    {
        $info_extension = array();
        require $cms_modules->path . $cms_info_module . '/install/info.php';
        ?>
        <div class="blockform">
            <h2><span><?php echo $lang['info_module']; ?></span></h2>
            <div class="fakeform">
                <div class="inform">
                    <div class="infldset file" style="padding:10px">
                        <table cellspacing="0" >
                            <tr>
                                <th style="width:150px" scope="row"><?php echo $lang['Name']; ?></th>
                                <td><strong><?php echo BB_Admin_Functions::Get_Name($cms_info_module); ?></strong></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['identifier']; ?></th>
                                <td><?php echo $cms_info_module; ?></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['Version']; ?></th>
                                <td><?php echo $info_extension['version']; ?></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['Author']; ?></th>
                                <td><strong><?php echo $info_extension['author']; ?></strong></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['E-Mail']; ?></th>
                                <td><a href="mailto:<?php echo $info_extension['email']; ?>"><?php echo $info_extension['email']; ?></a></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['Website']; ?></th>
                                <td><a href="<?php echo $info_extension['website']; ?>"><?php echo $info_extension['website']; ?></a></td>
                            </tr>
        <?php
        $cms_tmp_var = 'lang_cms_main_module_' . $cms_info_module;
        if (isset($GLOBALS[$cms_tmp_var]['desc']))
        {
            ?>
                                <tr>
                                    <th scope="row"><?php echo $lang['desc']; ?></th>
                                    <td><?php echo $GLOBALS[$cms_tmp_var]['desc']; ?></td>
                                </tr>
            <?php
        }
        ?>
                        </table>
                    </div>
                </div>
                <div><input type="button" class="b1" onclick="javascript:history.go(-1)" value="<?php echo $lang['Go back']; ?>"></div>
            </div>
        </div>
        <?php
    }
    else
        BB_Functions::Message($lang['no_info_file']);
}
else
{
    ?>
    <div class="blockform">
        <h2><span><?php echo $lang['Install']; ?></span></h2>
        <form action="modules.php" method="get">
            <div class="inform">
                <label><?php echo $lang['give_url_module']; ?> :<br />
                    <input class="textbox" size="50" name="module_url" id="module_url" type="text" />
                    <input type="submit" class="b1" value="<?php echo $lang['import']; ?>" /></label>
                <input type="hidden" name="p" value="toolsmng" />
            </div>
        </form>
    </div>
    <div class="blockform">
        <h2><span><?php echo $lang['manage_modules']; ?></span></h2>
        <div class="fakeform">
            <div class="infldset file" style="padding:10px">
                <table cellspacing="0" >
    <?php
    foreach ($cms_modules->All_Elements() as $m)
    {
        $curent_module_name = BB_Admin_Functions::Get_Name($m);
        if (bb_rewrite_urls == 1)
            echo '<tr>' . "\n" . '<th style="width:150px" scope="row"><a href="' . bb_website_url . '/' . strtolower($curent_module_name) . '">' . $curent_module_name . '</a></th>' . "\n";
        else
            echo '<tr>' . "\n" . '<th style="width:150px" scope="row"><a href="' . bb_website_url . '/index.php?/' . strtolower($curent_module_name) . '">' . $curent_module_name . '</a></th>' . "\n";
        echo BB_Admin_Functions::Check_Extension($m, $curent_module_name, 'module') . '</tr>';
    }
    ?>
                </table>
            </div>
        </div>
    </div>
    <?php
}
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB