Example #1
0
function pages_permissions_check($type, $ident)
{
    $result = false;
    if (isadmin()) {
        return true;
    }
    switch ($type) {
        case 'pages::edit':
            if (pages_enabled() && $ident > 0) {
                $result = run('permissions:check', 'profile');
            } else {
                $result = false;
            }
            break;
        case 'pages::access':
            $access = get_field('pages', 'access', 'ident', $ident);
            $result = run('users:access_level_check', $access);
            break;
    }
    return $result;
}
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 #3
0
}
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)) {
    // link title
    $title = pages_html_a(get_url($page_id, 'pages::page', page_owner()), $page->title);
} else {
    $title = $page->title;