/mvc/components/wiki
[return to app]1
<?php
2 /**
3 * Powers the Wiki functions when accessed within a controller
4 */
5 class wikiComponent {
6 /**
7 * Bootstrap function that controls the whole Wiki system
8 *
9 * @param boolean $enableEdit Optional, true if ommitted
10 * @return array
11 */
12 public function getWiki($enableEdit = true) {
13 if (!isset($_POST['wsearch']) && isset($_GET['wsearch'])) {
14 $_POST['wsearch'] = $_GET['wsearch'];
15 }
16 if (isset($_POST['wsearch'])) {
17 $_POST['wsearch'] = trim($_POST['wsearch']);
18 if ($_POST['wsearch']) {
19 $return['enableEdit'] = false;
20 $return['searchResults'] = get::model('wiki')->search($_POST['wsearch']);
21 return $return;
22 }
23 }
24
25 $return['enableEdit'] = $enableEdit;
26 if (!isset(mvc::$params[0])) {
27 mvc::$params[0] = 'index';
28 }
29 if ($enableEdit) {
30 $return['action'] = mvc::$params[0];
31 if (isset($_GET['history'])) {
32 $return['history'] = get::model('wiki')->getHistory();
33 return $return;
34 }
35 if (isset($_POST['body'])) {
36 $_POST['body'] = get::component('filter')->cleanHtml($_POST['body']);
37 get::model('wiki')->update($_POST);
38 } else if (isset($_POST['delete'])) {
39 get::model('wiki')->delete();
40 }
41 $html = get::helper('html');
42 $html->vorkHead['cssInline'][] = '#wikibody #wikititle, #wikibody #wikicomments {width: 630px;} '
43 . '#wikibody textarea {width: 630px; height: 50px;} '
44 . '#wikibody #wikiwysiwyg {border: 2px solid; margin-bottom: 20px; padding: 5px;} '
45 . '#wikibody #wikiwysiwyglabel {margin-top: 10px;} #wikibody #wikisave {font-weight: bold;} '
46 . '#wikibody #wikidelete {margin-top: 30px; margin-left: 650px; color: red;}';
47 }
48 $version = (isset($_GET['version']) && $enableEdit ? $_GET['version'] : null);
49 $return = array_merge(get::model('wiki')->select($version), $return);
50 return $return;
51 }
52
53 /**
54 * Simplified Wiki - just add to the end of your controller method:
55 * return get::component('wiki')->wiki();
56 *
57 * @param boolean $enableEdit Optional, true if ommitted
58 * @return array
59 */
60 public function wiki($enableEdit = true) {
61 mvc::$view = '#wiki';
62 return $this->getWiki($enableEdit);
63 }
64 }