Exemple #1
0
function getWeblogForm3($weblogname)
{
    global $PIVOTX;
    $form = new Form("weblog3", "", __("Save"));
    // No border and no 'submit' for this form:
    // TODO: Think about accessibility / non-js users!
    $form->html['start'] = <<<EOM
<form  enctype='multipart/form-data'  name='%name%' id='%name%' action="%action%" method='post'>
<table border='0' cellspacing='0' cellpadding='4' class='formclass' style="border-width: 0px !important;">
EOM;
    $form->html['submit'] = "";
    $weblog = $PIVOTX['weblogs']->getWeblog($weblogname);
    $subweblogs = $PIVOTX['weblogs']->getSubweblogs($weblogname);
    $allcats = $PIVOTX['categories']->getCategories();
    // Make an array where the keys are the same as the values
    foreach ($allcats as $cat) {
        $catoptions[$cat['name']] = sprintf("%s (%s)", $cat['display'], $cat['name']);
    }
    $templates = templateList();
    $templateoptions = templateOptions($templates, '_sub', array('_aux_', 'frontpage', 'entrypage', 'archivepage', 'searchpage'));
    // We use a counter to add lines between the subweblogs.
    $counter = 0;
    foreach ($subweblogs as $key) {
        $key = trim($key);
        if ($counter > 0) {
            $form->add(array('type' => 'custom', 'text' => "<tr><td colspan='3'><hr noshade='noshade' size='1' /></td></tr>"));
        }
        $counter++;
        $form->add(array('type' => 'custom', 'text' => "<tr><td colspan='2'><h3>" . sprintf(__("Subweblog %s"), $key) . '</h3></td></tr>'));
        $form->add(array('type' => 'text', 'name' => "{$key}#num_entries", 'label' => __('Number of Entries'), 'value' => 0 + $weblog['sub_weblog'][$key]['num_entries'], 'error' => __('Error'), 'size' => 10, 'isrequired' => 1, 'validation' => 'integer|min=0', 'text' => makeJtip(__('Number of Entries'), __('The Number of entries in this subweblog that will be shown on the frontpage.'))));
        $form->add(array('type' => 'text', 'name' => "{$key}#offset", 'label' => __('Offset'), 'value' => 0 + $weblog['sub_weblog'][$key]['offset'], 'error' => __('Error'), 'size' => 10, 'isrequired' => 1, 'validation' => 'integer|min=0|max=200', 'text' => makeJtip(__('Offset'), __('If Offset is set to a number, that amount of entries will be skipped when generating the page. You can use this to make a "Previous entries" list, for example.'))));
        $form->add(array('type' => 'select', 'name' => "{$key}#categories", 'label' => __('Categories'), 'value' => $weblog['sub_weblog'][$key]['categories'], 'options' => $catoptions, 'multiple' => true, 'text' => makeJtip(__('Categories'), __('Publish these categories')), 'size' => 10));
    }
    $form->use_javascript(true);
    return $form;
}
Exemple #2
0
/**
 * Edit a page in the mobile interface.
 */
function pagem_editpage()
{
    global $PIVOTX;
    $PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL);
    if ($_GET['uid'] == "") {
        $PIVOTX['template']->assign('title', __('Write a new Page'));
    } else {
        $PIVOTX['template']->assign('title', __('Edit Page'));
    }
    $currentuser = $PIVOTX['users']->getUser($PIVOTX['session']->currentUsername());
    if (!empty($_GET['uid'])) {
        // Editing a page.. Get it from the DB..
        $page = $PIVOTX['pages']->getPage($_GET['uid']);
        $PIVOTX['events']->add('edit_entry', intval($_GET['uid']), $entry['title']);
        if (!$PIVOTX['users']->allowEdit('page', $page['user'])) {
            $PIVOTX['template']->assign('heading', __("PivotX encountered an error"));
            $PIVOTX['template']->assign('html', "<p>" . __("You are not allowed to edit this entry.") . "</p>");
            renderTemplate('mobile/generic.tpl');
            return;
        }
        // Make sure we tweak the </textarea> in the intro or body text (since
        // that would break our own textarea, if we didn't)..
        $page['introduction'] = str_replace("<textarea", "&lt;textarea", $page['introduction']);
        $page['introduction'] = str_replace("</textarea", "&lt;/textarea", $page['introduction']);
        $page['body'] = str_replace("<textarea", "&lt;textarea", $page['body']);
        $page['body'] = str_replace("</textarea", "&lt;/textarea", $page['body']);
        // If the entry was written in  'markdown', and is now
        // being edited in the mobile editor, we must convert it.
        if ($page['convert_lb'] == "3") {
            $page['introduction'] = parse_intro_or_body($page['introduction'], false, $page['convert_lb'], true);
            $page['body'] = parse_intro_or_body($page['body'], false, $page['convert_lb'], true);
        }
        // Otherwise, if the entry was written in 'Plain XHTML' or 'WYSIWYG', and is now
        // being edited, there is not much more we
        // can do than strip out the <p> and <br/> tags to replace with linebreaks.
        if ($page['convert_lb'] == "0" || $page['convert_lb'] == "5") {
            $page['introduction'] = unparse_intro_or_body($page['introduction']);
            $page['body'] = unparse_intro_or_body($page['body']);
        }
        list($page['link'], $page['link_end']) = explode($page['uri'], $page['link']);
    } else {
        // Make a new entry.
        $page = array();
        if ($_GET['chapter'] != "") {
            $page['chapter'] = intval($_GET['chapter']);
        }
        $user = $PIVOTX['session']->currentUser();
        $page['user'] = $user['username'];
        $page['sortorder'] = 10;
        if ($PIVOTX['config']->get('default_post_status') != "") {
            $page['status'] = $PIVOTX['config']->get('default_post_status');
        }
        $page['link'] = makePagelink("xxx");
        list($page['link'], $page['link_end']) = explode('xxx', $page['link']);
    }
    $templates = templateOptions(templateList(), 'page', array('_sub_', '_aux_'));
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        // Show the screen..
        // Show the screen..
        $PIVOTX['template']->assign('templates', $templates);
        $PIVOTX['template']->assign('page', $page);
        $PIVOTX['template']->assign('chapters', $PIVOTX['pages']->getIndex());
        $PIVOTX['template']->assign('pivotxsession', $PIVOTX['session']->getCSRF());
        $PIVOTX['template']->assign('users', $PIVOTX['users']->getUsers());
        $PIVOTX['template']->assign('pageuser', $PIVOTX['users']->getUser($entry['user']));
        $PIVOTX['template']->assign("active", "pages");
        renderTemplate('mobile/editpage.tpl');
    } else {
        if ($_POST['code'] != $_GET['uid']) {
            $PIVOTX['events']->add('fatal_error', intval($_GET['uid']), "Tried to fake editing an entry");
            echo "Code is wrong! B0rk!";
            die;
        }
        // Make sure the current user is properly logged in, and that the request is legitimate
        $PIVOTX['session']->checkCSRF($_POST['pivotxsession']);
        // Sanitize the $_POST into an entry we can store
        $page = sanitizePostedPage($page);
        $page['convert_lb'] = "2";
        // Make sure it's processed as 'Textile'
        $PIVOTX['extensions']->executeHook('page_edit_beforesave', $page);
        $new_id = $PIVOTX['pages']->savePage($page);
        $PIVOTX['extensions']->executeHook('page_edit_aftersave', $page);
        $PIVOTX['messages']->addMessage(sprintf(__('Your page "%s" was successfully saved.'), '<em>' . trimText($page['title'], 25) . '</em>'));
        // Remove the frontpages and entrypages from the cache.
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->clear_cache();
        }
        // Update the search index for this page, but only if we're using flat files.
        if ($PIVOTX['db']->db_type == "flat") {
            $page['code'] = $page['uid'] = $new_id;
            updateSearchIndex($page, 'p');
        }
        pagem_Pages();
    }
}