function pages_edit_page($page_name, $owner = -1)
{
    global $CFG, $PAGE;
    $PAGE->pages->editing = true;
    if (pages_enabled() && !empty($page_name) && permissions_check('pages::edit', $owner)) {
        if ($owner == -1 && pages_is_frontpage($page_name)) {
            $is_frontpage = true;
        } else {
            $is_frontpage = false;
        }
        if (!($page = get_record('pages', 'uri', $page_name, 'owner', $owner))) {
            // try to edit legacy content
            if ($owner == -1) {
                $page = pages_get_legacy($page_name);
            }
        } else {
            pages_current_page($page);
        }
        $page = pages_input_override($page, $owner, false);
        if (isset($page->ident)) {
            $page->ident = intval($page->ident);
        }
        //if frontpage force some value
        if ($is_frontpage) {
            $page->name = $page_name;
            $page->parent = -1;
            //hidden
            $page->access = 'PUBLIC';
            //force public
        }
        $title_enc = htmlspecialchars($page->title, ENT_QUOTES, 'utf-8');
        //$page->content = htmlspecialchars(stripslashes($page->content), ENT_COMPAT, 'utf-8');
        $page->content = trim($page->content);
        $page->name = htmlspecialchars($page->name, ENT_QUOTES, 'utf-8');
        $input_title = pages_html_wrap('label', __gettext('Title:'), array('for' => 'page-title'));
        $input_title .= pages_html_input('text', array('id' => 'page-title', 'name' => 'page-title', 'value' => $title_enc, 'maxlength' => 127, 'style' => 'width:100%;'));
        $input_content = pages_html_wrap('label', __gettext('Content:'), array('for' => 'page-content'));
        $input_content .= pages_html_wrap('textarea', htmlspecialchars($page->content, ENT_NOQUOTES, 'utf-8'), array('id' => 'page-content', 'name' => 'page-content', 'rows' => 20, 'cols' => '79', 'style' => 'width:100%;'));
        if ($is_frontpage) {
            $input_menu = pages_html_input('hidden', array('name' => 'page-name', 'value' => stripslashes($page->name)));
            $input_default = null;
            $input_parent = pages_html_input('hidden', array('name' => 'menu-parent', 'value' => -1));
            $input_weight = null;
            $input_access = pages_html_input('hidden', array('name' => 'page-access', 'value' => 'PUBLIC'));
        } else {
            $input_menu = pages_html_wrap('label', __gettext('Menu title:'), array('for' => 'page-name'));
            $input_menu .= pages_html_input('text', array('id' => 'page-name', 'name' => 'page-name', 'value' => stripslashes($page->name), 'maxlength' => 127));
            if (!isset($page->ident) && $page_name == __gettext('Main')) {
                $page_default = 'checked';
            } else {
                $page_default = pages_is_default(isset($page->ident) ? $page->ident : 0, $owner) ? 'checked' : 'dummy';
            }
            if ($page_default == 'dummy') {
                $input_default = pages_html_wrap('label', __gettext('Make default:'), array('for' => 'page-default'));
                $input_default .= pages_html_input('checkbox', array('id' => 'page-default', 'name' => 'page-default', $page_default => $page_default));
            } else {
                // hidden checked input
                $input_default = pages_html_input('hidden', array('name' => 'page-default', 'value' => true));
            }
            $input_parent = pages_html_wrap('label', __gettext('Parent element:'), array('for' => 'menu-parent'));
            if (isset($page->ident)) {
                $menu_parents = get_records_select('pages', 'parent=? AND ident<>? AND owner=?', array(0, $page->ident, $owner));
            } else {
                $menu_parents = get_records_select('pages', 'parent=? AND owner=?', array(0, $owner));
            }
            $menu_parents_opts = array();
            $menu_parents_opts[] = (object) array('label' => __gettext('Top menu'), 'value' => 0);
            if (is_array($menu_parents)) {
                foreach ($menu_parents as $m) {
                    $opt = new StdClass();
                    $opt->value = $m->ident;
                    $opt->label = '- ' . $m->name;
                    if ($m->ident == $page->parent) {
                        $opt->selected = true;
                    }
                    $menu_parents_opts[] = $opt;
                }
            }
            $input_parent .= pages_html_select('menu-parent', $menu_parents_opts, array('id' => 'menu-parent'));
            $input_weight = pages_html_wrap('label', __gettext('Weight:'), array('for' => 'menu-weight'));
            $weights = array();
            for ($i = -10; $i <= 10; $i++) {
                $w = (object) array('label' => " {$i}", 'value' => $i);
                if ($page->weight == $i) {
                    $w->selected = true;
                }
                $weights[] = $w;
            }
            $input_weight .= pages_html_select('menu-weight', $weights, array('id' => 'menu-weight'));
            // access level
            $input_access = pages_html_wrap('label', __gettext('Access:'), array('for' => 'page-access'));
            $input_access .= run('display:access_level_select', array('page-access', $page->access));
        }
        // help
        $form_help = __gettext('You can use {{page}} keyword to link to others pages.');
        $form_help .= '<br />&raquo; ';
        $form_help .= __gettext('<em>{{page:About_me}}</em> will link to your page with menu title "About me". e.g. {{page:Main}}');
        $form_help .= '<br />&raquo; ';
        $form_help .= __gettext('<em>{{page:user:Title}}</em> will link to user\'s page "Title". e.g. {{page:news:Main}}');
        $form_help .= '<br />&raquo; ';
        $form_help .= __gettext('<em>{{page:content:Title}}</em> will link to site main pages "Title". e.g. {{page:content:About}}');
        $form_help = pages_html_wrap('p', $form_help);
        $input_buttons = pages_html_input('submit', array('id' => 'page-save', 'name' => 'submit', 'value' => __gettext('Save page')));
        $input_buttons .= pages_html_input('submit', array('id' => 'page-preview', 'name' => 'submit', 'value' => __gettext('Preview')));
        if ($page->name != 'New page' && !$is_frontpage) {
            $input_buttons .= pages_html_input('submit', array('id' => 'page-delete', 'name' => 'submit', 'value' => __gettext('Delete'), 'onclick' => 'return confirm_delete()'));
            $confirm_delete = __gettext('Are you sure that you want to delete this page?');
            $input_buttons .= pages_html_wrap('script', "\n               <!--\n                function confirm_delete() {\n                    return confirm('{$confirm_delete}');\n                }\n                -->\n                ", array('type' => 'text/javascript'));
        }
        // hidden action
        $input_buttons .= pages_html_input('hidden', array('name' => 'action', 'value' => 'pages:edit'));
        $content = pages_html_wrap('div', $input_title, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $input_content, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $form_help, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $input_menu . $input_default, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $input_parent . $input_weight, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $input_access, array('class' => 'form-item'));
        $content .= pages_html_wrap('div', $input_buttons, array('class' => 'form-item form-button'));
        $content = pages_html_wrap('form', $content, array('id' => 'page-form', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI']));
        // check for preview action
        if (optional_param('submit') == __gettext('Preview')) {
            $content = pages_preview_page($page) . $content;
        }
        // override content
        $page->content = $content;
    } else {
        $page = pages_page_denied();
    }
    if (empty($page)) {
        $page = pages_page_not_found();
    }
    return $page;
}
Example #2
0
function pages_html_form($name, $body, $attrs = null)
{
    if (!isset($attrs)) {
        $attrs = array();
    }
    if (!isset($attrs['id'])) {
        $attrs['id'] = $name;
    }
    if (!isset($attrs['name'])) {
        $attrs['name'] = $name;
    }
    if (!isset($attrs['method'])) {
        $attrs['method'] = 'post';
    }
    if (!isset($attrs['action'])) {
        $attrs['action'] = '';
    }
    if (isset($attrs['buttons'])) {
        $buttons = $attrs['buttons'];
    } else {
        $buttons = pages_html_input('submit', array('value' => __gettext('Submit')));
    }
    // add form key
    $buttons .= pages_html_input('hidden', array('name' => 'form_key', 'value' => elggform_key_get($name)));
    $body .= pages_html_wrap('div', $buttons, array('class' => 'form-buttons'));
    return pages_html_wrap('form', $body, $attrs);
}
function elggadmin_config_input($c, $obj)
{
    global $CFG;
    // override with current values
    $value = isset($CFG->{$c}) ? $CFG->{$c} : null;
    $input_name = "config[{$c}]";
    $attrs = array();
    $attrs['name'] = $input_name;
    $attrs['value'] = $value;
    $attrs['class'] = 'input';
    if (isset($obj->noteditable)) {
        $attrs['disabled'] = 'disabled';
        $attrs['class'] .= ' input-disabled';
    }
    if (!isset($obj->type)) {
        $obj->type = null;
    }
    switch ($obj->type) {
        case 'bool':
        case 'boolean':
            $yes = __gettext('Yes');
            $no = __gettext('No');
            $yesattrs = unserialize(serialize($attrs));
            $noattrs = unserialize(serialize($attrs));
            $yesattrs['value'] = 1;
            $noattrs['value'] = 0;
            if ((bool) $value) {
                $yesattrs['checked'] = 'checked';
            } else {
                $noattrs['checked'] = 'checked';
            }
            $result = pages_html_wrap('label', pages_html_input('radio', $yesattrs) . ' ' . $yes);
            $result .= pages_html_wrap('label', pages_html_input('radio', $noattrs) . ' ' . $no);
            $result = pages_html_wrap('div', $result, array('class' => 'input-text'));
            break;
        case 'int':
        case 'integer':
            $attrs['class'] = ' input-numeric';
            $result = pages_html_input('text', $attrs);
            break;
        case 'access':
            unset($attrs['name']);
            unset($attrs['value']);
            $options = array();
            $_opts = array('Private' => 'PRIVATE', 'Logged in' => 'LOGGED_IN', 'Public' => 'PUBLIC');
            foreach ($_opts as $label => $access) {
                $obj = new StdClass();
                $obj->label = $label;
                $obj->value = $access;
                if ($value == $access) {
                    $obj->selected = true;
                }
                $options[] = $obj;
            }
            $result = pages_html_select($input_name, $options, $attrs);
            break;
        case 'debug':
            unset($attrs['name']);
            unset($attrs['value']);
            $_opts = array('Off' => '0', 'Warning' => '7', 'Enabled' => '2047');
            $options = array();
            foreach ($_opts as $label => $access) {
                $obj = new StdClass();
                $obj->label = $label;
                $obj->value = $access;
                if ($value == $access) {
                    $obj->selected = true;
                }
                $options[] = $obj;
            }
            $result = pages_html_select($input_name, $options, $attrs);
            break;
        case 'language':
            if (empty($CFG->languages_installed)) {
                $result = __gettext('No languages installed');
            } else {
                ksort($CFG->languages_installed);
                $options = array();
                foreach ($CFG->languages_installed as $code => $lang) {
                    $obj = new StdClass();
                    $obj->label = $lang;
                    $obj->value = $code;
                    if ($code == $value) {
                        $obj->selected = true;
                    }
                    $options[] = $obj;
                }
            }
            $result = pages_html_select($input_name, $options, $attrs);
            break;
        default:
            $attrs['class'] .= ' input-text';
            $result = pages_html_input('text', $attrs);
            break;
    }
    return $result;
}