Пример #1
0
function addpage()
{
    $addtErrMsg = array();
    $catlist = getDetails('cats');
    $newp = new Page();
    $newp->newPageInit();
    $newp->addToCat('sidebar');
    if (isset($_POST[save])) {
        $isFormSubmitted = true;
        $content = stripslashes($_POST[content]);
        $title = stripslashes($_POST[title]);
        $newp->editTitle($title);
        $slug = $newp->slug;
        //	Fixed category adding
        $postVariables = $_POST;
        $selectedCats = array();
        foreach ($postVariables as $catKey => $categoryName) {
            if (strpos($catKey, 'check_') !== false) {
                $selectedCats[] = $categoryName;
            }
        }
        if (count($selectedCats) == 0) {
            $selectedCats[] = 'sidebar';
        }
        $newp->cats = $selectedCats;
        // $newp->commitChanges(); // dont commit yet
        // fix complete
        if ($title != '' and $content != '') {
            $newPageFile = pageDataDir($slug);
            if (!file_exists($newPageFile)) {
                //view all cats
                $newp->commitChanges();
                //debug($newp);
                runTweak('new-page', array('page-obj' => &$newp, 'page-content' => &$content));
                if (put2file($newPageFile, $content)) {
                    savepages();
                }
                $m = lt("The page was created successfully", 'page-create-success') . '<br />';
                $m .= lt("File Created") . " : " . $newPageFile . "<br />";
                $m .= lt("Content") . " : " . substr(strip_tags($content), 0, 100) . (strlen($content) > 100 ? '...' : '') . "<br />";
                MsgBox($m);
                return;
                // success
            } else {
                $addtErrMsg[] = lt("Save Failed");
                if (file_exists($newPageFile)) {
                    $addtErrMsg[] = lt("A page with similar Title already exists!!", 'similar-page-title-exists');
                }
            }
        } else {
            $addtErrMsg[] = lt("Either the title or the content is/are empty!!! Please check your input!!<br />", 'title-or-content-empty');
        }
        //die('f****d');
        //savepages();
    }
    if (count($addtErrMsg) != 0 and isset($title)) {
        //error occured
        $em = '';
        foreach ($addtErrMsg as $msg) {
            $em .= "<li>{$msg}</li>";
        }
        MsgBox(lt("Errors Occured") . " : <ul>{$em}</ul>", 'background:#FFE8E8;border:1px solid #AE0000');
    }
    //debug($addtErrMsg);
    $formAction = "?action=addpage";
    $submitButton = lt('Add Page');
    $chkboxs = checkBoxList(getDetails('cats'), $newp->cats);
    $pageTitleLabel = lt('Page Title');
    $catsLabel = lt('Categories');
    $contentLabel = lt('Content');
    $addnewpageLabel = lt('Add new Page');
    echo $te = <<<TET
\t<form action='{$formAction}' method=post class='pagemod_form'>
\t\t<h2>{$addnewpageLabel}</h2>
\t\t<table width='98%' border='0'>
\t\t  <tr>
\t\t\t<td width='20%'>{$pageTitleLabel}</td>
\t\t\t<td><input type='text' value='{$title}' name='title'></td>
\t\t\t<td align='right'><input type='submit' value='{$submitButton}' name='save'></td>
\t\t  </tr>
\t\t  <tr>
\t\t\t<td>{$catsLabel}</td>
\t\t\t<td colspan=2>{$chkboxs}</td>
\t\t  </tr>
\t\t</table>
\t\t<h2>{$contentLabel}</h2>
\t\t<table width="98%">
\t\t  <tr><td colspan=2>
\t\t\t<textarea name='content' rows=20 cols=70 id='editbox' class='editbox'>{$content}</textarea>
\t\t  </td></tr>
\t\t  <tr><td colspan=2><br /><input type='submit' value='{$submitButton}' name='save'></td></tr>
\t\t</table>
\t</form>
TET;
    runTweak('after-add-form-display');
}
Пример #2
0
function performEditLink($xLinkIn = '')
{
    global $editErrMsg, $razorArray;
    if ($xLinkIn == '') {
        $slab = $_GET['slab'];
    } else {
        $slab = $xLinkIn;
    }
    if (!in_array($slab, $razorArray['slabs'])) {
        MsgBox(lt('Invalid name'), 'redbox');
        return;
    }
    $addtErrMsg = array();
    $catlist = $razorArray['links_cats'];
    // get form signature //
    $random = false;
    if (isset($_POST['random'])) {
        $randomV = htmlspecialchars(stripslashes($_POST['random']), ENT_QUOTES);
        $randomVC = htmlspecialchars(stripslashes($_SESSION['random']), ENT_QUOTES);
        if ($randomV == $randomVC) {
            $random = true;
        }
    }
    // process form data if clicked //
    if (isset($_POST['save']) && $xLinkIn == '' && $random) {
        $newp = new SLAB();
        $newp->loadSlab($slab);
        $oldTitle = $newp->title;
        $oldSlab = $slab;
        $newSlab = cleanSlabTitle($_POST['title'], $newp->slabId);
        $externalLink = stripslashes($_POST['externallink']);
        $title = '';
        if (isset($_POST['title'])) {
            $title = stripslashes($_POST['title']);
        }
        if ($title == '') {
            $addtErrMsg[] = lt('Title cannot be empty');
        } else {
            $newp->catReset();
            foreach ($catlist as $cat => $cc) {
                if (isset($_POST['check_' . $cat])) {
                    $newp->addToCat($cat);
                }
            }
            $renameErr = false;
            // Fix for slab title renaming error (thanks to sguy) //
            if ($newSlab != $oldSlab || $title != $oldTitle) {
                if ($title != $oldTitle && in_array($title, $razorArray['titles'])) {
                    $addtErrMsg[] = lt('Cannot Rename Title, content with similar title already exists');
                    $renameErr = true;
                } else {
                    if ($newSlab != $oldSlab && in_array($newSlab, $razorArray['slabs'])) {
                        $addtErrMsg[] = lt('Cannot Rename Title, content with similar title already exists');
                        $renameErr = true;
                    } else {
                        $slab = $newSlab;
                    }
                }
                if (!$renameErr) {
                    $newp->editTitle($title);
                    unset($razorArray['ext_links'][$oldSlab]);
                }
            }
            // end fix //
            if (!$renameErr) {
                $razorArray['ext_links'][$slab] = $externalLink;
                if (isset($_POST['new-win'])) {
                    if ($_POST['new-win'] == 'show') {
                        $razorArray['ext_link_win'][$slab] = true;
                    } else {
                        if (isset($razorArray['ext_link_win'][$slab])) {
                            unset($razorArray['ext_link_win'][$slab]);
                        }
                    }
                } else {
                    if (isset($razorArray['ext_link_win'][$slab])) {
                        unset($razorArray['ext_link_win'][$slab]);
                    }
                }
            }
        }
    }
    // end //
    // output message if failed or save changes if worked //
    if (count($addtErrMsg) != 0) {
        $em = '';
        foreach ($addtErrMsg as $msg) {
            $em .= "<p>{$msg}</p>";
        }
        MsgBox(lt('Errors Occured') . $em, 'redbox');
    } elseif (isset($newp) && count($addtErrMsg) == 0) {
        BsocketB('admin-xpage-info-input', array($slab));
        $newp->commitChanges();
        saveRazorArray();
        $m = lt('Link Edited Successfully') . '<br />';
        $m .= lt('Title') . " <b>" . $title . '</b><br />';
        $m .= lt('XLink Edited') . " <b>" . $externalLink . "</b><br />";
        MsgBox($m, 'greenbox');
    }
    // end //
    // filter categories //
    $filteredCats = array();
    foreach ($razorArray['links_cats'] as $linksCats => $contents) {
        if ($linksCats != $razorArray['settings']['info-bar-cat']) {
            $filteredCats[$linksCats] = $linksCats;
        }
    }
    // end //
    // set up form data //
    $ep = new SLAB();
    $ep->loadSlab($slab);
    $externalLink = $razorArray['ext_links'][$slab];
    $title = $ep->title;
    $formAction = "?action=editextlink&slab={$slab}";
    $submitButton = lt('Edit Link');
    $pageTitleLabel = lt('External Link Title');
    $externalLinkTitle = lt('External Link');
    $urlLable = lt('URL');
    if (isset($razorArray['ext_link_win'])) {
        if (in_array($slab, $razorArray['ext_link_win'])) {
            if ($razorArray['ext_link_win'][$slab]) {
                $nwchecked = 'checked';
            }
        }
    }
    $newWinLabel = lt('Display in New Window');
    $newWinChkbox = "<input type='checkbox' name='new-win' value='show' {$nwchecked}>";
    $addnewpageLabel = lt('External Link Details');
    $chkboxs = checkBoxList($filteredCats, $ep->cats);
    $catsLabel = lt('Categories');
    $contentManager = lt('Content Manager');
    $editContent = lt('Edit External Link');
    // end //
    // sockets for extra ouput and add function //
    $extraInfo;
    BsocketB('admin-xlink-info-output', array(&$extraInfo));
    $addFunction;
    BsocketB('admin-add-link-function', array(&$addFunction, &$content));
    // end //
    // generate random signature for form //
    $random = rand();
    $_SESSION['random'] = $random;
    // output form for data input //Search...
    $te[1] = <<<TET
            <h1>{$editContent} {$ep->title}</h1>
            <div class='contentwh'>
            <form action='{$formAction}' method=post class='pagemod_form'>
            <input type='hidden' name='random' value='{$random}'>
                <h3>{$addnewpageLabel}</h3>
                {$extraInfo}
                <table class='tableEditItem'>
                    <tr class='tableFooter'><td class='twenty'></td><td class='auto'></td></tr>
                    <tr>
                        <td>{$pageTitleLabel}</td>
                        <td><input type='text' value='{$title}' name='title'></td>
                    </tr>
                    <tr>
                        <td>{$catsLabel}</td>
                        <td>{$chkboxs}</td>
                    </tr>
                    <tr>
                        <td>{$newWinLabel}</td>
                        <td>{$newWinChkbox}</td>
                    </tr>
                    <tr class='tableFooter'><td></td><td></td></tr>
                </table>
                <h3>{$externalLinkTitle}</h3>
                <table class='tableEditItem'>
                    <tr class='tableFooter'><td class='twenty'></td><td></td></tr>
        {$addFunction}
TET;
    $te[2] = "</tr><td>{$urlLable}</td><td>http:// <input type='externallink' value='{$externalLink}' name='externallink'></td></tr>";
    $te[3] = <<<TET
                    <tr class='tableFooter'><td></td><td></td></tr>
                </table>
                <input id='button' type='submit' value='{$submitButton}' name='save'>
            </form>
            </div>
TET;
    $te[4] = $content;
    echo $te[1];
    echo $te[2];
    echo $te[3];
    // end //
}