Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications

/mvc/elements/wiki

[return to app]
1
<?php
if (!isset($enableEdit)) {
    $enableEdit = false;
}
if ($enableEdit) {
    $historyLink = $html->link('javascript: document.location=document.location+"?history"', 'history');
    $baseUrl = '/' . mvc::$controller;
    if (mvc::$action != 'index') {
        $baseUrl .= '/' . mvc::$action;
    }
    if (isset(mvc::$params[0]) && mvc::$params[0] != 'index') {
        $baseUrl .= '/' . implode('/', mvc::$params);
    }
}
if (isset($returncode) && $returncode == 404) {
    header('HTTP/1.0 404 Not Found');
    if (!$enableEdit) {
        echo $html->h1('Page does not exist');
    } else {
        echo $html->h1('This "' . get::htmlentities($action) . '" page does not exist');
        if (isset($hasHistory) && $hasHistory) {
            echo $html->h3('This page used to exist but has been deleted: ' . $historyLink);
        }
        echo $html->h2('To create this page enter the content below and click save');
    }
}
if (isset($history) && $enableEdit) {
    if ($history) {
        echo '<ul>';
        foreach ($history as $version => $comments) {
            echo $html->li($html->link($baseUrl . '?version=' . urlencode($version), $version)
                           . ' ' . get::htmlentities($comments));
        }
        echo '</ul>';
    } else {
        echo $html->div('This page has no history');
    }
    echo $html->div($html->link($baseUrl, 'Back to most current version'));
    return;
}
if ($enableEdit) {
    echo $html->jsInline('document.writeln(\'<div id="wikiedit">[' . $html->link('javascript:wikiEdit()', 'edit')
                         . '] [' . (!isset($_GET['version']) ? $historyLink : 'Version: ' . $_GET['version'] . '
 '
. $html->link($baseUrl, 'Back to most current version')) . ']</div>\');'); echo $form->open(array('action' => $baseUrl, 'id' => 'wikieditform')); } if (isset($searchResults)) { $body = $html->h1('Search results for ' . get::htmlentities($_POST['wsearch'])); foreach ($searchResults as $wikiaction => $result) { $body .= $html->h2($html->link($wikiaction, $result['title'])); if ($result['description']) { $body .= $html->p($result['description']); } } if (!$searchResults) { $body .= $html->p('Your search did not match any documents'); } } if (!isset($hideSearch)) { load::element('wikisearch', array('withinExistingForm' => true)); } if (isset($body)) { echo '<div id="wikibody">' . $body . '</div>'; } if ($enableEdit) { $wysiwygTextarea = (!isset($_GET['html']) && file_exists('js/tinymce')); if ($wysiwygTextarea) { echo $form->wysiwygTextareaInit(array('nocache' => true)); } $keywordsArgs = array('name' => 'keywords', 'type' => 'textarea'); if (isset($head['meta']['keywords'])) { $keywordsArgs['value'] = $head['meta']['keywords']; } $descriptionArgs = array('name' => 'description', 'type' => 'textarea'); if (isset($head['meta']['description'])) { $descriptionArgs['value'] = $head['meta']['description']; } $js = $html->jsTools(true) . 'function wikiEdit() { dom("wikiedit").style.display = "none"; var wikibody = dom("wikibody"); var originalContent = wikibody.innerHTML; wikibody.innerHTML = \'' . $html->div($form->input(array('name' => 'title', 'value' => $title, 'id' => 'wikititle'))) . '\'; wikibody.innerHTML += \'<div><textarea name="body" class="wysiwyg" id="wikibodytextarea" style="height:
 400px;">\''
. ' + originalContent.replace(/&(\w{2,6});/gi, "&amp;$1;").replace(/<\/textarea>/gi, "&lt;\/textarea>")' . ' + \'</textarea>\';'; if (!$wysiwygTextarea) { $js .= 'wikibody.innerHTML += \'<div id="wikiwysiwyglabel"><label
 for="wikiwysiwyg">Preview:</label></div>'
. '<div id="wikiwysiwyg"></div></div>\'; '; } $js .= 'wikibody.innerHTML += \'' . $html->div($form->input($keywordsArgs)) . '\'; wikibody.innerHTML += \'' . $html->div($form->input($descriptionArgs)) . '\'; wikibody.innerHTML += \'' . $html->div($form->input(array('label' => 'Comments about changes made
 (optional)'
, 'name' => 'comments', 'id' => 'wikicomments'))) .
 
'\'; wikibody.innerHTML += \'' . $html->div($form->input(array('type' => 'submit', 'value' => 'Save', 'id' => 'wikisave'))) . '\'; wikibody.innerHTML += \'' . $html->div($form->input(array('type' => 'button', 'value' => 'Delete this page', 'id' => 'wikidelete'))) . '\'; if (dom("wikiwysiwyg")) { var updateWysiwyg = function() {dom("wikiwysiwyg").innerHTML = dom("wikibodytextarea").value}; updateWysiwyg(); dom("wikibodytextarea").onkeyup = updateWysiwyg; } var wikiDelete = function() {wikibody.innerHTML = \'' . $form->input(array('type' => 'hidden', 'name' => 'delete')) . '\'; dom("wikieditform").submit();} dom("wikidelete").onclick = function() { if (confirm("Are you sure that you want to delete this page?")) { wikiDelete(); } }'; if ($wysiwygTextarea) { $js .= PHP_EOL . ' tinyMCE.init(vorkInitTinyMce);'; } $js .= PHP_EOL . '}'; if (isset($returncode) && $returncode == 404) { $js .= PHP_EOL . 'wikiEdit();'; } echo $html->jsInline($js); echo $form->close(); }