Changeset 816 for trunk/Modules/Wiki/Wiki.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Wiki/Wiki.php
r609 r816 13 13 $this->Dependencies = array(); 14 14 } 15 15 16 16 function Install() 17 17 { … … 22 22 { 23 23 parent::UnInstall(); 24 } 25 24 } 25 26 26 function Start() 27 27 { … … 29 29 $this->LoadPages(); 30 30 } 31 31 32 32 function Stop() 33 33 { 34 35 } 36 34 parent::Stop(); 35 } 36 37 37 function LoadPages() 38 38 { 39 40 41 42 43 44 45 46 47 48 49 50 39 $DbResult = $this->Database->select('WikiPage', '*', 'VisibleInMenu=1'); 40 while($DbRow = $DbResult->fetch_assoc()) 41 { 42 $this->System->RegisterPage($DbRow['NormalizedName'], 'PageWiki'); 43 $this->System->RegisterMenuItem(array( 44 'Title' => $DbRow['Name'], 45 'Hint' => '', 46 'Link' => $this->System->Link('/'.$DbRow['NormalizedName'].'/'), 47 'Permission' => LICENCE_ANONYMOUS, 48 'Icon' => '', 49 ), 6); 50 } 51 51 } 52 52 } … … 54 54 class PageWiki extends Page 55 55 { 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 } else 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 $Output = ShowMessage('Wiki stránka uložena', MESSAGE_INFORMATION); 141 142 143 144 145 146 147 148 149 { 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 '<td><a href="'.$this->System->Link('/user.php?user='.$PageContent['User']).'">'.$PageContent['UserName'].'</a></td>'.183 184 185 } 186 187 188 189 190 191 192 193 194 56 function Show() 57 { 58 if(array_key_exists('Action', $_GET)) 59 { 60 if($_GET['Action'] == 'Edit') $Output = $this->EditContent(); 61 else if($_GET['Action'] == 'EditSave') $Output = $this->SaveContent(); 62 else if($_GET['Action'] == 'History') $Output = $this->ShowHistory(); 63 else $Output = $this->ShowContent(); 64 } else $Output = $this->ShowContent(); 65 return($Output); 66 } 67 68 function ShowContent() 69 { 70 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 71 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 72 if($DbResult->num_rows > 0) 73 { 74 $DbRow = $DbResult->fetch_assoc(); 75 if(array_key_exists('ver', $_GET)) 76 { 77 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' AND Id='.$_GET['ver']*1); 78 if($DbResult2->num_rows > 0) 79 { 80 $DbRow2 = $DbResult2->fetch_assoc(); 81 $Output = '<h3>Archív stránky '.$DbRow['Name'].' ('.HumanDateTime($DbRow2['Time']).')</h3>'; 82 $Output .= $DbRow2['Content']; 83 if($this->System->User->Licence(LICENCE_MODERATOR)) 84 $Output .= '<div><a href="?Action=Edit">Upravit nejnovější</a> <a href="?Action=History">Historie</a></div>'; 85 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 86 } else 87 { 88 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1'); 89 if($DbResult2->num_rows > 0) 90 { 91 $DbRow2 = $DbResult2->fetch_assoc(); 92 $Output = '<h3>'.$DbRow['Name'].'</h3>'; 93 $Output .= $DbRow2['Content']; 94 if($this->System->User->Licence(LICENCE_MODERATOR)) 95 $Output .= '<hr><div><a href="?Action=Edit">Upravit</a> <a href="?Action=History">Historie</a></div>'; 96 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 97 } 98 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 99 return($Output); 100 } 101 102 function EditContent() 103 { 104 if($this->System->User->Licence(LICENCE_MODERATOR)) 105 { 106 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 107 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 108 if($DbResult->num_rows > 0) 109 { 110 $DbRow = $DbResult->fetch_assoc(); 111 $Output = '<h3>Úprava '.$DbRow['Name'].'</h3>'; 112 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1'); 113 if($DbResult2->num_rows > 0) 114 { 115 $DbRow2 = $DbResult2->fetch_assoc(); 116 $Output .= '<form action="?Action=EditSave" method="post">'. 117 '<textarea name="content" rows="8" cols="80" onkeydown="ResizeTextArea(this)" class="textedit">'.$DbRow2['Content'].'</textarea><br/>'. 118 '<input type="submit" name="save" value="Uložit"/> '. 119 '<input type="button" name="cancel" value="Zrušit" onclick="location.href=\'?\'"/>'. 120 '</form>'; 121 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 122 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 123 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 124 return($Output); 125 } 126 127 function SaveContent() 128 { 129 if($this->System->User->Licence(LICENCE_MODERATOR)) 130 { 131 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 132 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 133 if($DbResult->num_rows > 0) 134 { 135 $DbRow = $DbResult->fetch_assoc(); 136 if(array_key_exists('content', $_POST) and array_key_exists('save', $_POST)) 137 { 138 $DbResult2 = $this->Database->insert('WikiPageContent', array('Content' => stripslashes($_POST['content']), 139 'User' => $this->System->User->Id, 'Time' => 'NOW()', 'Page' => $DbRow['Id'])); 140 $Output = ShowMessage('Wiki stránka uložena', MESSAGE_INFORMATION); 141 } else $Output = ShowMessage('Nezadána platná data', MESSAGE_CRITICAL); 142 $Output .= $this->ShowContent(); 143 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 144 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 145 return($Output); 146 } 147 148 function ShowHistory() 149 { 150 if($this->System->User->Licence(LICENCE_MODERATOR)) 151 { 152 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 153 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 154 if($DbResult->num_rows > 0) 155 { 156 $DbRow = $DbResult->fetch_assoc(); 157 158 $Output = '<h3>Historie stránky '.$DbRow['Name'].'</h3>'; 159 $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM `WikiPageContent` WHERE Page='.$DbRow['Id']); 160 $DbRow2 = $DbResult2->fetch_row(); 161 $PageList = GetPageList($DbRow2[0]); 162 163 $Output .= $PageList['Output']; 164 $Output .= '<table class="BaseTable">'; 165 166 $TableColumns = array( 167 array('Name' => 'Time', 'Title' => 'Čas'), 168 array('Name' => 'User', 'Title' => 'Uživatel'), 169 array('Name' => 'Action', 'Title' => 'Akce'), 170 ); 171 172 $Order = GetOrderTableHeader($TableColumns, 'Time', 1); 173 $Output .= $Order['Output']; 174 175 $DbResult2 = $this->Database->query('SELECT *, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`WikiPageContent`.`User`) AS `UserName` '. 176 ' FROM `WikiPageContent` WHERE Page='. 177 $DbRow['Id'].' '.$Order['SQL'].$PageList['SQLLimit']); 178 while($PageContent = $DbResult2->fetch_assoc()) 179 { 180 $Output .= '<tr>'. 181 '<td>'.HumanDateTime($PageContent['Time']).'</td>'. 182 '<td><a href="'.$this->System->Link('/user.php?user='.$PageContent['User']).'">'.$PageContent['UserName'].'</a></td>'. 183 '<td><a href="?id='.$PageContent['Id'].'&ver='.$PageContent['Id'].'">Zobrazit</a></td>'; 184 $Output .= '</tr>'; 185 } 186 187 $Output .= '</table>'. 188 $PageList['Output']; 189 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 190 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 191 return($Output); 192 } 193 194 function ToHtml($text) 195 195 { 196 196 $text = preg_replace('/<source lang="(.*?)">(.*?)<\/source>/', '<pre lang="$1">$2</pre>', $text);
Note:
See TracChangeset
for help on using the changeset viewer.