/mvc/elements/wiki
[return to app]1
<?php
2 if (!isset($enableEdit)) {
3 $enableEdit = false;
4 }
5 if ($enableEdit) {
6 $historyLink = $html->link('javascript: document.location=document.location+"?history"', 'history');
7 $baseUrl = '/' . mvc::$controller;
8 if (mvc::$action != 'index') {
9 $baseUrl .= '/' . mvc::$action;
10 }
11 if (isset(mvc::$params[0]) && mvc::$params[0] != 'index') {
12 $baseUrl .= '/' . implode('/', mvc::$params);
13 }
14 }
15 if (isset($returncode) && $returncode == 404) {
16 header('HTTP/1.0 404 Not Found');
17 if (!$enableEdit) {
18 echo $html->h1('Page does not exist');
19 } else {
20 echo $html->h1('This "' . get::htmlentities($action) . '" page does not exist');
21 if (isset($hasHistory) && $hasHistory) {
22 echo $html->h3('This page used to exist but has been deleted: ' . $historyLink);
23 }
24 echo $html->h2('To create this page enter the content below and click save');
25 }
26 }
27 if (isset($history) && $enableEdit) {
28 if ($history) {
29 echo '<ul>';
30 foreach ($history as $version => $comments) {
31 echo $html->li($html->link($baseUrl . '?version=' . urlencode($version), $version)
32 . ' ' . get::htmlentities($comments));
33 }
34 echo '</ul>';
35 } else {
36 echo $html->div('This page has no history');
37 }
38 echo $html->div($html->link($baseUrl, 'Back to most current version'));
39 return;
40 }
41 if ($enableEdit) {
42 echo $html->jsInline('document.writeln(\'<div id="wikiedit">[' . $html->link('javascript:wikiEdit()', 'edit')
43 . '] [' . (!isset($_GET['version']) ? $historyLink : 'Version: ' . $_GET['version'] . '
'
44 . $html->link($baseUrl, 'Back to most current version')) . ']</div>\');');
45 echo $form->open(array('action' => $baseUrl, 'id' => 'wikieditform'));
46 }
47 if (isset($searchResults)) {
48 $body = $html->h1('Search results for ' . get::htmlentities($_POST['wsearch']));
49 foreach ($searchResults as $wikiaction => $result) {
50 $body .= $html->h2($html->link($wikiaction, $result['title']));
51 if ($result['description']) {
52 $body .= $html->p($result['description']);
53 }
54 }
55 if (!$searchResults) {
56 $body .= $html->p('Your search did not match any documents');
57 }
58 }
59
60 if (!isset($hideSearch)) {
61 load::element('wikisearch', array('withinExistingForm' => true));
62 }
63 if (isset($body)) {
64 echo '<div id="wikibody">' . $body . '</div>';
65 }
66 if ($enableEdit) {
67 $wysiwygTextarea = (!isset($_GET['html']) && file_exists('js/tinymce'));
68 if ($wysiwygTextarea) {
69 echo $form->wysiwygTextareaInit(array('nocache' => true));
70 }
71 $keywordsArgs = array('name' => 'keywords', 'type' => 'textarea');
72 if (isset($head['meta']['keywords'])) {
73 $keywordsArgs['value'] = $head['meta']['keywords'];
74 }
75 $descriptionArgs = array('name' => 'description', 'type' => 'textarea');
76 if (isset($head['meta']['description'])) {
77 $descriptionArgs['value'] = $head['meta']['description'];
78 }
79
80 $js = $html->jsTools(true) . 'function wikiEdit() {
81 dom("wikiedit").style.display = "none";
82 var wikibody = dom("wikibody");
83 var originalContent = wikibody.innerHTML;
84 wikibody.innerHTML = \'' . $html->div($form->input(array('name' => 'title',
85 'value' => $title, 'id' => 'wikititle'))) . '\';
86 wikibody.innerHTML += \'<div><textarea name="body" class="wysiwyg" id="wikibodytextarea" style="height:
400px;">\''
87 . ' + originalContent.replace(/&(\w{2,6});/gi, "&$1;").replace(/<\/textarea>/gi, "<\/textarea>")'
88 . ' + \'</textarea>\';';
89 if (!$wysiwygTextarea) {
90 $js .= 'wikibody.innerHTML += \'<div id="wikiwysiwyglabel"><label
for="wikiwysiwyg">Preview:</label></div>'
91 . '<div id="wikiwysiwyg"></div></div>\';
92 ';
93 }
94 $js .= 'wikibody.innerHTML += \'' . $html->div($form->input($keywordsArgs)) . '\';
95 wikibody.innerHTML += \'' . $html->div($form->input($descriptionArgs)) . '\';
96 wikibody.innerHTML += \'' . $html->div($form->input(array('label' => 'Comments about changes made
(optional)',
97 'name' => 'comments', 'id' => 'wikicomments'))) .
'\';
98 wikibody.innerHTML += \'' . $html->div($form->input(array('type' => 'submit', 'value' => 'Save',
99 'id' => 'wikisave'))) . '\';
100
101 wikibody.innerHTML += \'' . $html->div($form->input(array('type' => 'button', 'value' => 'Delete this page',
102 'id' => 'wikidelete'))) . '\';
103 if (dom("wikiwysiwyg")) {
104 var updateWysiwyg = function() {dom("wikiwysiwyg").innerHTML = dom("wikibodytextarea").value};
105 updateWysiwyg();
106 dom("wikibodytextarea").onkeyup = updateWysiwyg;
107 }
108 var wikiDelete = function() {wikibody.innerHTML = \''
109 . $form->input(array('type' => 'hidden', 'name' => 'delete')) . '\'; dom("wikieditform").submit();}
110 dom("wikidelete").onclick = function() {
111 if (confirm("Are you sure that you want to delete this page?")) {
112 wikiDelete();
113 }
114 }';
115 if ($wysiwygTextarea) {
116 $js .= PHP_EOL . ' tinyMCE.init(vorkInitTinyMce);';
117 }
118 $js .= PHP_EOL . '}';
119 if (isset($returncode) && $returncode == 404) {
120 $js .= PHP_EOL . 'wikiEdit();';
121 }
122 echo $html->jsInline($js);
123 echo $form->close();
124 }