Location: PHPKode > projects > XennoBB > xennobb/admin/blocks.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('blocks'))
    BB_Functions::Message($lang['No permission']);
$cms_install_block = (isset($_GET['install']) && file_exists($cms_blocks->path . $_GET['install'] . '/install/install.php')) ? $_GET['install'] : '';
$cms_uninstall_block = (isset($_GET['uninstall']) && file_exists($cms_blocks->path . $_GET['uninstall'] . '/install/uninstall.php')) ? $_GET['uninstall'] : '';
$cms_enable_block = (isset($_GET['enable']) && in_array($_GET['enable'], $cms_blocks->All_Elements())) ? $_GET['enable'] : '';
$cms_disable_block = (isset($_GET['disable']) && in_array($_GET['disable'], $cms_blocks->All_Elements())) ? $_GET['disable'] : '';
$cms_delete_block = (isset($_GET['delete']) && in_array($_GET['delete'], $cms_blocks->All_Elements())) ? $_GET['delete'] : '';
$cms_pack_block = (isset($_GET['pack']) && in_array($_GET['pack'], $cms_blocks->All_Elements())) ? $_GET['pack'] : '';
$cms_info_block = (isset($_GET['info']) && in_array($_GET['info'], $cms_blocks->All_Elements())) ? $_GET['info'] : '';
$cms_custom_title_page = $lang['Admin'] . $lang['manage_blocks'];
if (is_file(FORUM_ROOT . 'include/templates/' . $forum_user['template'] . '/forum_admin.tpl'))
    $cms_main_template = FORUM_ROOT . 'include/templates/' . $forum_user['template'] . '/forum_admin.tpl';
else
    $cms_main_template = FORUM_ROOT . 'include/templates/Default/forum_admin.tpl';
require FORUM_ROOT . 'include/header.php';
if (is_writable(FORUM_ROOT . 'include/blocks') && !empty($_GET['block_url']))
{
    $block_url = BB_Input::Trim($_GET['block_url']);
    $parsed_url = parse_url($block_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_blocks->Install($block_url)) !== true)
            BB_Functions::Message($err);
        else
        {
            BB_Admin_Functions::Log_Action('Import block from ' . $block_url, 3);
            BB_Functions::Redirect('blocks.php', $lang['import_block_ok']);
        }
    }
}
if ($cms_install_block != '')
{
    $cms_constant_block = 'bb_block_' . $cms_install_block;
    if (!defined($cms_constant_block))
    {
        if (isset($_POST['install_ok']))
        {
            require $cms_blocks->path . $cms_install_block . '/install/install.php';
            $cms_install_block_status = BB_Install_Block();
            if ($cms_install_block_status === true && BB_Cache::Add_Language($cms_install_block, 'block'))
            {
                BB_Admin_Functions::Log_Action('Install block ' . $cms_install_block, 2);
                ?>
                <div class="blockform">
                    <h2><span><?php echo $lang['install_block_ok']; ?></span></h2>
                    <div class="fakeform">
                        <div class="inform">
                            <div class="infldset file" style="padding:10px">
                                <p><?php echo $lang['install_block_finish']; ?></p>
                                <pre>&lt;cms_block_<?php echo $cms_install_block; ?>&gt;</pre>
                                <p><?php echo $lang['install_block_place']; ?></p>
                            </div>
                        </div>
                        <div><input type="button" class="b1" onclick="javascript:window.location.href='blocks.php';" value="<?php echo $lang['Go back']; ?>" /></div>
                    </div>
                </div>
                <?php
            }
            elseif ($cms_install_block_status === false)
                BB_Functions::Message($lang['unable_install_block']);
            else
                BB_Functions::Message($cms_install_block_status);
        }
        else
        {
            ?>
            <div class="blockform">
                <h2><span><?php printf($lang['install_block'], $cms_install_block); ?></span></h2>
                <form method="post" action="blocks.php?install=<?php echo $cms_install_block; ?>">
                    <input type="hidden" name="install_ok" value="1" />
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php printf($lang['install_block_ready_to'], $cms_install_block); ?></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['Install']; ?>" /></div>
                </form>
            </div>
            <?php
        }
    }
    else
    {
        ?>
        <div class="blockform">
            <h2><span><?php printf($lang['install_block'], $cms_install_block); ?></span></h2>
            <div class="fakeform">
                <div class="inform">
                    <div class="infldset file" style="padding:10px">
                        <p><?php echo $lang['block_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_block != '')
{
    $cms_constant_block = 'bb_block_' . $cms_uninstall_block;

    if (defined($cms_constant_block))
    {
        if (isset($_POST['uninstall_ok']))
        {
            require $cms_blocks->path . $cms_uninstall_block . '/install/uninstall.php';
            $cms_uninstall_block_status = BB_Uninstall_Block();
            if ($cms_uninstall_block_status === true && BB_Cache::Remove_Language($cms_uninstall_block, 'block'))
            {
                BB_Admin_Functions::Log_Action('Uninstall block ' . $cms_uninstall_block, 2);
                ?>
                <div class="blockform">
                    <h2><span><?php echo $lang['uninstall_block_ok']; ?></span></h2>
                    <div class="fakeform">
                        <div class="inform">
                            <div class="infldset file" style="padding:10px">
                                <p><?php echo $lang['uninstall_block_finish']; ?></p>
                                <pre>&lt;cms_block_<?php echo $cms_uninstall_block; ?>&gt;</pre>
                            </div>
                        </div>
                        <div><input type="button" class="b1" onclick="javascript:window.location.href='blocks.php';" value="<?php echo $lang['Go back']; ?>" /></div>
                    </div>
                </div>
                <?php
            }
            elseif ($cms_uninstall_block_status === false)
                BB_Functions::Message($lang['unable_uninstall_block']);
            else
                BB_Functions::Message($cms_uninstall_block_status);
        }
        else
        {
            ?>
            <div class="blockform">
                <h2><span><?php printf($lang['uninstall_block'], $cms_uninstall_block); ?></span></h2>
                <form method="post" action="blocks.php?uninstall=<?php echo $cms_uninstall_block; ?>">
                    <input type="hidden" name="uninstall_ok" value="1" />
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php printf($lang['uninstall_block_ready_to'], $cms_uninstall_block); ?></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_block'], $cms_uninstall_block); ?></span></h2>
            <div class="fakeform">
                <div class="inform">
                    <div class="infldset file" style="padding:10px">
                        <p><?php echo $lang['block_seem_not_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_enable_block != '')
{
    $namespace = 'block_' . $cms_enable_block;
    $config_name = 'bb_block_' . $cms_enable_block;
    $cms_settings->Set_Namespace($namespace);
    $res = $cms_settings->Save($config_name, 1);
    $cms_settings->Set_Namespace('');
    if ($res)
    {
        BB_Admin_Functions::Log_Action("Enable block " . $cms_enable_block, 1);
        header('location: blocks.php');
        exit;
    }
    else
        BB_Functions::Message($lang['unable_update_config']);
}
elseif ($cms_pack_block != '')
{
    $info_extension = array();
    if (file_exists($cms_blocks->path . $cms_pack_block . '/install/info.php'))
        require $cms_blocks->path . $cms_pack_block . '/install/info.php';
    else
        $info_extension['version'] = '';
    $fname = 'block-' . $cms_pack_block . '-' . $info_extension['version'];
    $cms_block_root = FORUM_ROOT . 'include/blocks';
    if (($res = BB_Files::Make_Package($cms_pack_block, $cms_block_root . '/' . $cms_pack_block, $cms_block_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 block ' . $cms_pack_block, 0);
            BB_Functions::Redirect('blocks.php', $lang['export_ok']);
        }
        else
            BB_Functions::Message($lang['export_error']);
    }
    else
        BB_Functions::Message($lang['export_error']);
}
elseif ($cms_disable_block != '')
{
    $namespace = 'block_' . $cms_disable_block;
    $config_name = 'bb_block_' . $cms_disable_block;
    $cms_settings->Set_Namespace($namespace);
    $res = $cms_settings->Save($config_name, 0);
    $cms_settings->Set_Namespace('');
    if ($res)
    {
        BB_Admin_Functions::Log_Action("Disable block " . $cms_disable_block, 1);
        header('location: blocks.php');
        exit;
    }
    else
        BB_Functions::Message($lang['unable_update_config']);
}
elseif ($cms_delete_block != '' && is_writable($cms_blocks->path))
{
    BB_Files::Delete_Tree($cms_blocks->path . $cms_delete_block);
    BB_Admin_Functions::Log_Action('Delete block ' . $cms_delete_block, 3);
    BB_Functions::Redirect('blocks.php', $lang['config_updated']);
}
elseif ($cms_info_block != '')
{
    if (file_exists($cms_blocks->path . $cms_info_block . '/install/info.php'))
    {
        $info_extension = array();
        require $cms_blocks->path . $cms_info_block . '/install/info.php';
        ?>
        <div class="blockform">
            <h2><span><?php echo $lang['info_block']; ?></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_block, 'block'); ?></strong></td>
                            </tr>
                            <tr>
                                <th scope="row"><?php echo $lang['identifier']; ?></th>
                                <td><?php echo $cms_info_block; ?></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_block_' . $cms_info_block;
        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>
        <div class="box">
            <form action="blocks.php" method="get">
                <div class="inform">
                    <label><?php echo $lang['give_url_block']; ?> :<br />
                        <input class="textbox" size="50" name="block_url" id="block_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>
    <div class="blockform">
        <h2><span><?php echo $lang['manage_blocks']; ?></span></h2>
        <div class="box">
            <div class="fakeform">
                <div class="infldset file" style="padding:15px">
                    <table cellspacing="0" >
    <?php
    foreach ($cms_blocks->All_Elements() as $b)
    {
        $curent_block_name = BB_Admin_Functions::Get_Name($b, 'block');
        echo '<tr>' . "\n" . '<th style="width:150px" scope="row">' . $curent_block_name . '</th>' . "\n";
        echo BB_Admin_Functions::Check_Extension($b, $curent_block_name, 'block') . '</tr>';
    }
    ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <?php
}
require FORUM_ROOT . 'include/footer.php';
?>
Return current item: XennoBB