1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/ModuleWiki.php');
|
---|
4 |
|
---|
5 | class PageWiki extends Page
|
---|
6 | {
|
---|
7 | function Show(): string
|
---|
8 | {
|
---|
9 | if (array_key_exists('Action', $_GET))
|
---|
10 | {
|
---|
11 | if ($_GET['Action'] == 'Edit') $Output = $this->EditContent();
|
---|
12 | else if ($_GET['Action'] == 'EditSave') $Output = $this->SaveContent();
|
---|
13 | else if ($_GET['Action'] == 'History') $Output = $this->ShowHistory();
|
---|
14 | else $Output = $this->ShowContent();
|
---|
15 | } else $Output = $this->ShowContent();
|
---|
16 | return $Output;
|
---|
17 | }
|
---|
18 |
|
---|
19 | function ShowContent()
|
---|
20 | {
|
---|
21 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
22 | $PageName = Core::Cast($this->System)->PathItems[count(Core::Cast($this->System)->PathItems) - 1];
|
---|
23 | $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');
|
---|
24 | if ($DbResult->num_rows > 0)
|
---|
25 | {
|
---|
26 | $DbRow = $DbResult->fetch_assoc();
|
---|
27 | if (array_key_exists('ver', $_GET))
|
---|
28 | {
|
---|
29 | $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' AND Id='.$_GET['ver']*1);
|
---|
30 | if ($DbResult2->num_rows > 0)
|
---|
31 | {
|
---|
32 | $DbRow2 = $DbResult2->fetch_assoc();
|
---|
33 | $Output = '<h3>Archív stránky '.$DbRow['Name'].' ('.HumanDateTime($DbRow2['Time']).')</h3>';
|
---|
34 | $Output .= $DbRow2['Content'];
|
---|
35 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
36 | $Output .= '<div><a href="?Action=Edit">Upravit nejnovější</a> <a href="?Action=History">Historie</a></div>';
|
---|
37 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
38 | } else
|
---|
39 | {
|
---|
40 | $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1');
|
---|
41 | if ($DbResult2->num_rows > 0)
|
---|
42 | {
|
---|
43 | $DbRow2 = $DbResult2->fetch_assoc();
|
---|
44 | $Output = '<h3>'.$DbRow['Name'].'</h3>';
|
---|
45 | $Output .= $DbRow2['Content'];
|
---|
46 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
47 | $Output .= '<hr><div><a href="?Action=Edit">Upravit</a> <a href="?Action=History">Historie</a></div>';
|
---|
48 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
49 | }
|
---|
50 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
51 | return $Output;
|
---|
52 | }
|
---|
53 |
|
---|
54 | function EditContent()
|
---|
55 | {
|
---|
56 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
57 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
58 | {
|
---|
59 | $PageName = Core::Cast($this->System)->PathItems[count(Core::Cast($this->System)->PathItems) - 1];
|
---|
60 | $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');
|
---|
61 | if ($DbResult->num_rows > 0)
|
---|
62 | {
|
---|
63 | $DbRow = $DbResult->fetch_assoc();
|
---|
64 | $Output = '<h3>Úprava '.$DbRow['Name'].'</h3>';
|
---|
65 | $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1');
|
---|
66 | if ($DbResult2->num_rows > 0)
|
---|
67 | {
|
---|
68 | $DbRow2 = $DbResult2->fetch_assoc();
|
---|
69 | $Output .= '<form action="?Action=EditSave" method="post">'.
|
---|
70 | '<textarea name="content" rows="8" cols="80" onkeydown="ResizeTextArea(this)" class="textedit">'.$DbRow2['Content'].'</textarea><br/>'.
|
---|
71 | '<input type="submit" name="save" value="Uložit"/> '.
|
---|
72 | '<input type="button" name="cancel" value="Zrušit" onclick="location.href=\'?\'"/>'.
|
---|
73 | '</form>';
|
---|
74 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
75 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
76 | } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
77 | return $Output;
|
---|
78 | }
|
---|
79 |
|
---|
80 | function SaveContent()
|
---|
81 | {
|
---|
82 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
83 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
84 | {
|
---|
85 | $PageName = Core::Cast($this->System)->PathItems[count(Core::Cast($this->System)->PathItems) - 1];
|
---|
86 | $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');
|
---|
87 | if ($DbResult->num_rows > 0)
|
---|
88 | {
|
---|
89 | $DbRow = $DbResult->fetch_assoc();
|
---|
90 | if (array_key_exists('content', $_POST) and array_key_exists('save', $_POST))
|
---|
91 | {
|
---|
92 | $DbResult2 = $this->Database->insert('WikiPageContent', array('Content' => stripslashes($_POST['content']),
|
---|
93 | 'User' => $User->Id, 'Time' => 'NOW()', 'Page' => $DbRow['Id']));
|
---|
94 | $Output = ShowMessage('Wiki stránka uložena', MESSAGE_INFORMATION);
|
---|
95 | } else $Output = ShowMessage('Nezadána platná data', MESSAGE_CRITICAL);
|
---|
96 | $Output .= $this->ShowContent();
|
---|
97 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
98 | } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
99 | return $Output;
|
---|
100 | }
|
---|
101 |
|
---|
102 | function ShowHistory()
|
---|
103 | {
|
---|
104 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
105 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
106 | {
|
---|
107 | $PageName = Core::Cast($this->System)->PathItems[count(Core::Cast($this->System)->PathItems) - 1];
|
---|
108 | $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');
|
---|
109 | if ($DbResult->num_rows > 0)
|
---|
110 | {
|
---|
111 | $DbRow = $DbResult->fetch_assoc();
|
---|
112 |
|
---|
113 | $Output = '<h3>Historie stránky '.$DbRow['Name'].'</h3>';
|
---|
114 | $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM `WikiPageContent` WHERE Page='.$DbRow['Id']);
|
---|
115 | $DbRow2 = $DbResult2->fetch_row();
|
---|
116 | $PageList = GetPageList($DbRow2[0]);
|
---|
117 |
|
---|
118 | $Output .= $PageList['Output'];
|
---|
119 | $Output .= '<table class="BaseTable">';
|
---|
120 |
|
---|
121 | $TableColumns = array(
|
---|
122 | array('Name' => 'Time', 'Title' => 'Čas'),
|
---|
123 | array('Name' => 'User', 'Title' => 'Uživatel'),
|
---|
124 | array('Name' => 'Action', 'Title' => 'Akce'),
|
---|
125 | );
|
---|
126 |
|
---|
127 | $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
|
---|
128 | $Output .= $Order['Output'];
|
---|
129 |
|
---|
130 | $DbResult2 = $this->Database->query('SELECT *, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`WikiPageContent`.`User`) AS `UserName` '.
|
---|
131 | ' FROM `WikiPageContent` WHERE Page='.
|
---|
132 | $DbRow['Id'].' '.$Order['SQL'].$PageList['SQLLimit']);
|
---|
133 | while ($PageContent = $DbResult2->fetch_assoc())
|
---|
134 | {
|
---|
135 | $Output .= '<tr>'.
|
---|
136 | '<td>'.HumanDateTime($PageContent['Time']).'</td>'.
|
---|
137 | '<td><a href="'.$this->System->Link('/user/?user='.$PageContent['User']).'">'.$PageContent['UserName'].'</a></td>'.
|
---|
138 | '<td><a href="?id='.$PageContent['Id'].'&ver='.$PageContent['Id'].'">Zobrazit</a></td>';
|
---|
139 | $Output .= '</tr>';
|
---|
140 | }
|
---|
141 |
|
---|
142 | $Output .= '</table>'.
|
---|
143 | $PageList['Output'];
|
---|
144 | } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);
|
---|
145 | } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
146 | return $Output;
|
---|
147 | }
|
---|
148 |
|
---|
149 | function ToHtml($text)
|
---|
150 | {
|
---|
151 | $text = preg_replace('/<source lang="(.*?)">(.*?)<\/source>/', '<pre lang="$1">$2</pre>', $text);
|
---|
152 | $text = preg_replace('/======(.*?)======/', '<h5>$1</h5>', $text);
|
---|
153 | $text = preg_replace('/=====(.*?)=====/', '<h4>$1</h4>', $text);
|
---|
154 | $text = preg_replace('/====(.*?)====/', '<h3>$1</h3>', $text);
|
---|
155 | $text = preg_replace('/===(.*?)===/', '<h2>$1</h2>', $text);
|
---|
156 | $text = preg_replace('/==(.*?)==/', '<h1>$1</h1>', $text);
|
---|
157 | $text = preg_replace("/'''(.*?)'''/", '<strong>$1</strong>', $text);
|
---|
158 | $text = preg_replace("/''(.*?)''/", '<em>$1</em>', $text);
|
---|
159 | $text = preg_replace('/<s>(.*?)<\/s>/', '<strike>$1</strike>', $text);
|
---|
160 | $text = preg_replace('/\[\[Image:(.*?)\|(.*?)\]\]/', '<img src="$1" alt="$2" title="$2" />', $text);
|
---|
161 | $text = preg_replace('/\[(.*?) (.*?)\]/', '<a href="$1" title="$2">$2</a>', $text);
|
---|
162 | $text = preg_replace('/>(.*?)\n/', '<blockquote>$1</blockquote>', $text);
|
---|
163 |
|
---|
164 | $text = preg_replace('/\* (.*?)\n/', '<ul><li>$1</li></ul>', $text);
|
---|
165 | $text = preg_replace('/<\/ul><ul>/', '', $text);
|
---|
166 |
|
---|
167 | $text = preg_replace('/# (.*?)\n/', '<ol><li>$1</li></ol>', $text);
|
---|
168 | $text = preg_replace('/<\/ol><ol>/', '', $text);
|
---|
169 |
|
---|
170 | $text = str_replace("\r\n\r\n", '</p><p>', $text);
|
---|
171 | $text = str_replace("\r\n", '<br/>', $text);
|
---|
172 | $text = '<p>'.$text.'</p>';
|
---|
173 | return $text;
|
---|
174 | }
|
---|
175 | }
|
---|