Exemple #1
0
function elggadmin_pagesetup()
{
    // first login?
    global $CFG;
    if (user_flag_get('admin', $_SESSION['userid']) && !isset($CFG->elggadmin_installed)) {
        $CFG->elggadmin_installed = true;
        set_config('elggadmin_installed', true);
        header_redirect(get_url(null, 'elggadmin::config'), __gettext('Welcome to the Elgg configuration manager!'));
    }
    if (context() == 'admin') {
        if (!plugin_is_loaded('pages')) {
            elgg_messages_add(__gettext('Error: <code>elggadmin</code> plugin needs <code>pages</code> plugin to run'));
        } else {
            pages_submenu_add('elggadmin', __gettext('Site administration'), get_url(null, 'elggadmin::'), 10);
        }
    } elseif (context() == 'elggadmin') {
        if (!plugin_is_loaded('pages')) {
            elgg_messages_add(__gettext('Error: <code>elggadmin</code> plugin needs <code>pages</code> plugin to run'));
            header_redirect(get_url(null, 'admin::'));
        }
        // submenu options
        pages_submenu_add('elggadmin', __gettext('Configuration manager'), get_url(null, 'elggadmin::'));
        pages_submenu_add('elggadmin:theme', __gettext('Default theme editor'), get_url(null, 'elggadmin::theme'));
        pages_submenu_add('elggadmin:frontpage', __gettext('Frontpage template editor'), get_url(null, 'elggadmin::frontpage'));
        pages_submenu_add('elggadmin:logs', __gettext('Error log'), get_url(null, 'elggadmin::logs'));
        sidebar_add(50, 'sidebar-' . elggadmin_currentpage(), elggadmin_sidebar());
        // clear sidebar
        $clear_sidebar[] = 'sidebar-profile';
        $clear_sidebar[] = 'sidebar-' . elggadmin_currentpage();
        sidebar_remove($clear_sidebar, true);
        if (elggadmin_is_404()) {
            header('HTTP/1.0 404 Not Found');
        }
    }
}
//FIXME: workaround for walledgarden
if (isset($_GET['owner']) && $_GET['owner'] == -1) {
    define('context', 'external');
    define('pages_external', true);
}
include dirname(dirname(dirname(__FILE__))) . '/includes.php';
require dirname(__FILE__) . '/lib/pages.inc.php';
if (page_owner() > 0) {
    define('context', 'pages');
}
// pages init
pages_actions();
templates_page_setup();
if (page_owner() < 1) {
    // remove all but pages block
    sidebar_remove(array('pages_sidebar'), true);
}
$page_id = optional_param('page');
$do_action = optional_param('do');
if (!pages_enabled()) {
    $page = new StdClass();
    $page->title = __gettext('Plugin disabled for users');
    $page->content = __gettext('This plugin is currently disabled by site administrator');
} else {
    if ($do_action == 'edit') {
        $page = pages_edit_page($page_id, page_owner());
    } else {
        $page = pages_get_page($page_id, page_owner());
    }
}
if (!empty($page->ident)) {
Exemple #3
0
/**
 * Removes a block or blocks from sidebar
 *
 * @param mixed $id block identificator to remove, string or array of id's
 * @param bool $overrideall if all blocks will be removed except provided $id
 */
function sidebar_remove($id, $overrideall = false)
{
    global $PAGE;
    if (empty($id)) {
        trigger_error(__FUNCTION__ . ": invalid argument (id: empty)", E_USER_ERROR);
    }
    if ($overrideall) {
        // clear sidebar
        $block = array();
        if (!is_array($id)) {
            $id = array($id);
        }
        // exists?
        foreach ($PAGE->sidebar as $w => $v) {
            foreach ($v as $e) {
                // found
                if (in_array($e['id'], $id)) {
                    while (isset($block[$w])) {
                        $w++;
                    }
                    $block[$w] = $e;
                }
            }
        }
        if (!empty($block)) {
            unset($PAGE->sidebar);
            foreach ($block as $w => $b) {
                sidebar_add($w, $b['id'], $b['body'], $b['userdetails'], $b['label'], $b['class']);
            }
        }
        $PAGE->sidebar_locked = $id;
        // end
        return;
    }
    if (!isset($PAGE->sidebar_blacklist)) {
        $PAGE->sidebar_blacklist = array();
    }
    if (is_array($id)) {
        foreach ($id as $e) {
            sidebar_remove($e);
        }
    } elseif (!in_array($id, $PAGE->sidebar_blacklist)) {
        $PAGE->sidebar_blacklist[] = $id;
        // prevent further inclusions
        if (!empty($PAGE->sidebar) && is_array($PAGE->sidebar)) {
            // remove block if exists
            $sidebar = array();
            foreach ($PAGE->sidebar as $w => $blocks) {
                if (!isset($sidebar[$w])) {
                    $sidebar[$w] = array();
                }
                foreach ($blocks as $block) {
                    if ($block['id'] == $id) {
                        continue;
                    } else {
                        $sidebar[$w][] = $block;
                    }
                }
            }
            // override sidebar
            $PAGE->sidebar = $sidebar;
            if (isset($PAGE->sidebar_locked)) {
                // unlock
                unset($PAGE->sidebar_locked);
            }
        }
    }
}