Changeset 738 for trunk/Modules/Wiki
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/Modules/Wiki/Wiki.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Wiki/Wiki.php
r586 r738 14 14 $this->Revision = 1; 15 15 } 16 16 17 17 function DoInstall() 18 18 { 19 19 parent::Install(); 20 20 $this->Database->Query("'CREATE TABLE IF NOT EXISTS `WikiPage` ( 21 `Id` int(11) NOT NULL AUTO_INCREMENT,22 `Name` varchar(255) NOT NULL,23 `NormalizedName` varchar(255) NOT NULL,24 `VisibleInMenu` int(11) NOT NULL,25 PRIMARY KEY (`Id`),26 UNIQUE KEY `Name` (`Name`),27 KEY `VisibleInMenu` (`VisibleInMenu`)21 `Id` int(11) NOT NULL AUTO_INCREMENT, 22 `Name` varchar(255) NOT NULL, 23 `NormalizedName` varchar(255) NOT NULL, 24 `VisibleInMenu` int(11) NOT NULL, 25 PRIMARY KEY (`Id`), 26 UNIQUE KEY `Name` (`Name`), 27 KEY `VisibleInMenu` (`VisibleInMenu`) 28 28 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 29 29 CREATE TABLE IF NOT EXISTS `WikiPageContent` ( 30 `Id` int(11) NOT NULL AUTO_INCREMENT,31 `Page` int(11) NOT NULL,32 `Time` datetime NOT NULL,33 `Content` text NOT NULL,34 `User` int(11) NOT NULL,35 PRIMARY KEY (`Id`),36 KEY `User` (`User`),37 KEY `Page` (`Page`)30 `Id` int(11) NOT NULL AUTO_INCREMENT, 31 `Page` int(11) NOT NULL, 32 `Time` datetime NOT NULL, 33 `Content` text NOT NULL, 34 `User` int(11) NOT NULL, 35 PRIMARY KEY (`Id`), 36 KEY `User` (`User`), 37 KEY `Page` (`Page`) 38 38 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 39 39 ALTER TABLE `WikiPageContent` … … 47 47 'DELETE TABLE `WikiPage`;"); 48 48 parent::UnInstall(); 49 } 50 49 } 50 51 51 function DoStart() 52 52 { 53 53 $this->LoadPages(); 54 54 } 55 55 56 56 function DoStop() 57 57 { 58 58 } 59 59 60 60 function LoadPages() 61 61 { 62 $DbResult = $this->Database->select('WikiPage', '*', 'VisibleInMenu=1');63 while($DbRow = $DbResult->fetch_assoc())64 {65 $this->System->RegisterPage($DbRow['NormalizedName'], 'PageWiki');66 $this->System->RegisterMenuItem(array(67 'Title' => $DbRow['Name'],68 'Hint' => '',69 'Link' => $this->System->Link('/'.$DbRow['NormalizedName'].'/'),70 'Permission' => LICENCE_ANONYMOUS,71 'Icon' => '',72 ), 2);73 }62 $DbResult = $this->Database->select('WikiPage', '*', 'VisibleInMenu=1'); 63 while($DbRow = $DbResult->fetch_assoc()) 64 { 65 $this->System->RegisterPage($DbRow['NormalizedName'], 'PageWiki'); 66 $this->System->RegisterMenuItem(array( 67 'Title' => $DbRow['Name'], 68 'Hint' => '', 69 'Link' => $this->System->Link('/'.$DbRow['NormalizedName'].'/'), 70 'Permission' => LICENCE_ANONYMOUS, 71 'Icon' => '', 72 ), 2); 73 } 74 74 } 75 75 } … … 80 80 var $ShortTitle = 'Wiki'; 81 81 var $ParentClass = 'PagePortal'; 82 82 83 83 function Show() 84 {85 if(array_key_exists('Action', $_GET))86 {87 if($_GET['Action'] == 'Edit') $Output = $this->EditContent();88 else if($_GET['Action'] == 'EditSave') $Output = $this->SaveContent();89 else if($_GET['Action'] == 'History') $Output = $this->ShowHistory();90 else $Output = $this->ShowContent();91 } else $Output = $this->ShowContent();92 return($Output);93 }94 95 function ShowContent()96 {97 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1];98 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');99 if($DbResult->num_rows > 0)100 {101 $DbRow = $DbResult->fetch_assoc();102 if(array_key_exists('ver', $_GET))103 {104 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' AND Id='.$_GET['ver']*1);105 if($DbResult2->num_rows > 0)106 {107 $DbRow2 = $DbResult2->fetch_assoc();108 $Output = '<h3>Archív stránky '.$DbRow['Name'].' ('.HumanDateTime($DbRow2['Time']).')</h3>';109 $Output .= $DbRow2['Content'];110 if($this->System->User->Licence(LICENCE_MODERATOR))111 $Output .= '<div><a href="?Action=Edit">Upravit nejnovější</a> <a href="?Action=History">Historie</a></div>';112 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);113 } else 114 {115 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1');116 if($DbResult2->num_rows > 0)117 {118 $DbRow2 = $DbResult2->fetch_assoc();119 $Output = '<h3>'.$DbRow['Name'].'</h3>';120 $Output .= $DbRow2['Content'];121 if($this->System->User->Licence(LICENCE_MODERATOR))122 $Output .= '<div><a href="?Action=Edit">Upravit</a> <a href="?Action=History">Historie</a></div>';123 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);124 }125 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);126 return($Output);127 }128 129 function EditContent()130 {131 if($this->System->User->Licence(LICENCE_MODERATOR))132 {133 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1];134 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');135 if($DbResult->num_rows > 0)136 {137 $DbRow = $DbResult->fetch_assoc();138 $Output = '<h3>Úprava '.$DbRow['Name'].'</h3>';139 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1');140 if($DbResult2->num_rows > 0)141 {142 $DbRow2 = $DbResult2->fetch_assoc();143 $Output .= '<form action="?Action=EditSave" method="post">'.144 '<textarea name="content" rows="8" cols="80" onkeydown="ResizeTextArea(this)" class="textedit">'.$DbRow2['Content'].'</textarea><br/>'.145 '<input type="submit" name="save" value="Uložit"/> '.146 '<input type="button" name="cancel" value="Zrušit" onclick="location.href=\'?\'"/>'.147 '</form>';148 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);149 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);150 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL);151 return($Output);152 }153 154 function SaveContent()155 {156 if($this->System->User->Licence(LICENCE_MODERATOR))157 {158 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1];159 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');160 if($DbResult->num_rows > 0)161 {162 $DbRow = $DbResult->fetch_assoc();163 if(array_key_exists('content', $_POST) and array_key_exists('save', $_POST))164 {165 $DbResult2 = $this->Database->insert('WikiPageContent', array('Content' => stripslashes($_POST['content']),166 'User' => $this->System->User->Id, 'Time' => 'NOW()', 'Page' => $DbRow['Id']));167 $Output = ShowMessage('Wiki stránka uložena', MESSAGE_INFORMATION); 168 } else $Output = ShowMessage('Nezadána platná data', MESSAGE_CRITICAL);169 $Output .= $this->ShowContent();170 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);171 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL);172 return($Output);173 }174 175 function ShowHistory()176 { 177 if($this->System->User->Licence(LICENCE_MODERATOR))178 {179 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1];180 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"');181 if($DbResult->num_rows > 0)182 {183 $DbRow = $DbResult->fetch_assoc();184 185 $Output = '<h3>Historie stránky '.$DbRow['Name'].'</h3>';186 $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM `WikiPageContent` WHERE Page='.$DbRow['Id']);187 $DbRow2 = $DbResult2->fetch_row();188 $PageList = GetPageList($DbRow2[0]);189 190 $Output .= $PageList['Output'];191 $Output .= '<table class="BaseTable">';192 193 $TableColumns = array(194 array('Name' => 'Time', 'Title' => 'Čas'),195 array('Name' => 'User', 'Title' => 'Uživatel'),196 array('Name' => 'Action', 'Title' => 'Akce'),197 );198 199 $Order = GetOrderTableHeader($TableColumns, 'Time', 1);200 $Output .= $Order['Output'];201 202 $DbResult2 = $this->Database->query('SELECT *, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`WikiPageContent`.`User`) AS `UserName` '.203 ' FROM `WikiPageContent` WHERE Page='.204 $DbRow['Id'].' '.$Order['SQL'].$PageList['SQLLimit']);205 while($PageContent = $DbResult2->fetch_assoc())206 {207 $Output .= '<tr>'.208 '<td>'.HumanDateTime($PageContent['Time']).'</td>'.209 '<td><a href="'.$this->System->Link('/user.php?user='.$PageContent['User']).'">'.$PageContent['UserName'].'</a></td>'.210 '<td><a href="?id='.$PageContent['Id'].'&ver='.$PageContent['Id'].'">Zobrazit</a></td>';211 $Output .= '</tr>';212 } 213 214 $Output .= '</table>'.215 $PageList['Output'];216 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL);217 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL);218 return($Output);219 } 220 84 { 85 if(array_key_exists('Action', $_GET)) 86 { 87 if($_GET['Action'] == 'Edit') $Output = $this->EditContent(); 88 else if($_GET['Action'] == 'EditSave') $Output = $this->SaveContent(); 89 else if($_GET['Action'] == 'History') $Output = $this->ShowHistory(); 90 else $Output = $this->ShowContent(); 91 } else $Output = $this->ShowContent(); 92 return($Output); 93 } 94 95 function ShowContent() 96 { 97 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 98 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 99 if($DbResult->num_rows > 0) 100 { 101 $DbRow = $DbResult->fetch_assoc(); 102 if(array_key_exists('ver', $_GET)) 103 { 104 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' AND Id='.$_GET['ver']*1); 105 if($DbResult2->num_rows > 0) 106 { 107 $DbRow2 = $DbResult2->fetch_assoc(); 108 $Output = '<h3>Archív stránky '.$DbRow['Name'].' ('.HumanDateTime($DbRow2['Time']).')</h3>'; 109 $Output .= $DbRow2['Content']; 110 if($this->System->User->Licence(LICENCE_MODERATOR)) 111 $Output .= '<div><a href="?Action=Edit">Upravit nejnovější</a> <a href="?Action=History">Historie</a></div>'; 112 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 113 } else 114 { 115 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1'); 116 if($DbResult2->num_rows > 0) 117 { 118 $DbRow2 = $DbResult2->fetch_assoc(); 119 $Output = '<h3>'.$DbRow['Name'].'</h3>'; 120 $Output .= $DbRow2['Content']; 121 if($this->System->User->Licence(LICENCE_MODERATOR)) 122 $Output .= '<div><a href="?Action=Edit">Upravit</a> <a href="?Action=History">Historie</a></div>'; 123 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 124 } 125 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 126 return($Output); 127 } 128 129 function EditContent() 130 { 131 if($this->System->User->Licence(LICENCE_MODERATOR)) 132 { 133 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 134 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 135 if($DbResult->num_rows > 0) 136 { 137 $DbRow = $DbResult->fetch_assoc(); 138 $Output = '<h3>Úprava '.$DbRow['Name'].'</h3>'; 139 $DbResult2 = $this->Database->select('WikiPageContent', '*', 'Page='.$DbRow['Id'].' ORDER BY Time DESC LIMIT 1'); 140 if($DbResult2->num_rows > 0) 141 { 142 $DbRow2 = $DbResult2->fetch_assoc(); 143 $Output .= '<form action="?Action=EditSave" method="post">'. 144 '<textarea name="content" rows="8" cols="80" onkeydown="ResizeTextArea(this)" class="textedit">'.$DbRow2['Content'].'</textarea><br/>'. 145 '<input type="submit" name="save" value="Uložit"/> '. 146 '<input type="button" name="cancel" value="Zrušit" onclick="location.href=\'?\'"/>'. 147 '</form>'; 148 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 149 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 150 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL); 151 return($Output); 152 } 153 154 function SaveContent() 155 { 156 if($this->System->User->Licence(LICENCE_MODERATOR)) 157 { 158 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 159 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 160 if($DbResult->num_rows > 0) 161 { 162 $DbRow = $DbResult->fetch_assoc(); 163 if(array_key_exists('content', $_POST) and array_key_exists('save', $_POST)) 164 { 165 $DbResult2 = $this->Database->insert('WikiPageContent', array('Content' => stripslashes($_POST['content']), 166 'User' => $this->System->User->Id, 'Time' => 'NOW()', 'Page' => $DbRow['Id'])); 167 $Output = ShowMessage('Wiki stránka uložena', MESSAGE_INFORMATION); 168 } else $Output = ShowMessage('Nezadána platná data', MESSAGE_CRITICAL); 169 $Output .= $this->ShowContent(); 170 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 171 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL); 172 return($Output); 173 } 174 175 function ShowHistory() 176 { 177 if($this->System->User->Licence(LICENCE_MODERATOR)) 178 { 179 $PageName = $this->System->PathItems[count($this->System->PathItems) - 1]; 180 $DbResult = $this->Database->select('WikiPage', 'Name, Id', 'NormalizedName="'.$PageName.'"'); 181 if($DbResult->num_rows > 0) 182 { 183 $DbRow = $DbResult->fetch_assoc(); 184 185 $Output = '<h3>Historie stránky '.$DbRow['Name'].'</h3>'; 186 $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM `WikiPageContent` WHERE Page='.$DbRow['Id']); 187 $DbRow2 = $DbResult2->fetch_row(); 188 $PageList = GetPageList($DbRow2[0]); 189 190 $Output .= $PageList['Output']; 191 $Output .= '<table class="BaseTable">'; 192 193 $TableColumns = array( 194 array('Name' => 'Time', 'Title' => 'Čas'), 195 array('Name' => 'User', 'Title' => 'Uživatel'), 196 array('Name' => 'Action', 'Title' => 'Akce'), 197 ); 198 199 $Order = GetOrderTableHeader($TableColumns, 'Time', 1); 200 $Output .= $Order['Output']; 201 202 $DbResult2 = $this->Database->query('SELECT *, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`WikiPageContent`.`User`) AS `UserName` '. 203 ' FROM `WikiPageContent` WHERE Page='. 204 $DbRow['Id'].' '.$Order['SQL'].$PageList['SQLLimit']); 205 while($PageContent = $DbResult2->fetch_assoc()) 206 { 207 $Output .= '<tr>'. 208 '<td>'.HumanDateTime($PageContent['Time']).'</td>'. 209 '<td><a href="'.$this->System->Link('/user.php?user='.$PageContent['User']).'">'.$PageContent['UserName'].'</a></td>'. 210 '<td><a href="?id='.$PageContent['Id'].'&ver='.$PageContent['Id'].'">Zobrazit</a></td>'; 211 $Output .= '</tr>'; 212 } 213 214 $Output .= '</table>'. 215 $PageList['Output']; 216 } else $Output = ShowMessage('Wiki stránka nenalezena', MESSAGE_CRITICAL); 217 } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL); 218 return($Output); 219 } 220 221 221 function ToHtml($text) 222 222 {
Note:
See TracChangeset
for help on using the changeset viewer.
