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