Changeset 887 for trunk/Modules/News/NewsPage.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/NewsPage.php
r878 r887 3 3 class PageNews extends Page 4 4 { 5 var $FullTitle = 'Aktualní informace'; 6 var $ShortTitle = 'Aktuality'; 7 var $ParentClass = 'PagePortal'; 8 var $UploadedFilesFolder; 9 10 function Show() 11 { 12 $this->UploadedFilesFolder = $this->System->ModuleManager->Modules['News']->UploadedFilesFolder; 13 if (count($this->System->PathItems) > 1) 14 { 15 if ($this->System->PathItems[1] == 'subscription') return $this->ShowSubscription(); 16 else if ($this->System->PathItems[1] == 'rss') return $this->ShowRSS(); 17 else return PAGE_NOT_FOUND; 18 } else return $this->ShowMain(); 19 } 20 21 function ShowView() 22 { 23 $Output = ''; 24 if (!$this->System->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění'; 5 function __construct(System $System) 6 { 7 parent::__construct($System); 8 $this->FullTitle = 'Aktualní informace'; 9 $this->ShortTitle = 'Aktuality'; 10 $this->ParentClass = 'PagePortal'; 11 } 12 13 function ShowView(): string 14 { 15 $Output = ''; 16 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Display', 'Item')) $Output .= 'Nemáte oprávnění'; 25 17 else 26 18 { … … 35 27 else $Author = $Row['Name']; 36 28 $Output .= '<div class="Panel"><div class="Title">'.$Row['Title'].' ('.HumanDate($Row['Date']).', '.$Author.')'; 37 if (($this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) 29 if ((ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'] == $Row['User']) and 30 (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) 38 31 { 39 32 $Output .= '<div class="Action">'; … … 42 35 $Output .= '</div>'; 43 36 } 44 $Output .= '</div><div class="Content">'. $this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';37 $Output .= '</div><div class="Content">'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'<br />'; 45 38 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>'; 46 39 if ($Row['Enclosure'] != '') … … 50 43 foreach ($Enclosures as $Enclosure) 51 44 { 52 if (file_exists( $this->UploadedFilesFolder.$Enclosure))53 $Output .= ' <a href="'.$this->System->Link('/'. $this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';45 if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) 46 $Output .= ' <a href="'.$this->System->Link('/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 54 47 } 55 48 } … … 60 53 } 61 54 62 function ShowAdd() 63 { 64 $Output = ''; 65 $Category = $this->GetCategory(); 66 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 55 function ShowAdd(): string 56 { 57 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 58 $Output = ''; 59 $Category = $this->GetCategory(); 60 if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 67 61 { 68 62 $this->System->PageHeaders[] = array($this, 'GetPageHeader'); … … 75 69 while ($DbRow = $DbResult->fetch_array()) 76 70 { 77 if ($ this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))71 if ($User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id'])) 78 72 { 79 73 if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"'; … … 96 90 } 97 91 98 function ShowAdd2() 99 { 92 function ShowAdd2(): string 93 { 94 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 100 95 $Output = ''; 101 96 $RemoteAddr = GetRemoteAddress(); 102 97 $Category = $this->GetCategory(); 103 if ($ this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))98 if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 104 99 { 105 100 // Process uploaded file … … 110 105 if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != '')) 111 106 { 112 $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);107 $UploadedFilePath = ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']); 113 108 if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath)) 114 109 { … … 124 119 $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'], 125 120 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr, 126 'Enclosure' => $Enclosures, 'Author' => $ this->System->User->User['Name'],127 'User' => $ this->System->User->User['Id'], 'Link' => $_POST['link']));121 'Enclosure' => $Enclosures, 'Author' => $User->User['Name'], 122 'User' => $User->User['Id'], 'Link' => $_POST['link'])); 128 123 $Output .= 'Aktualita přidána!<br />Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.<br /><br />'; 129 124 $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>'; 130 $this->System->ModuleManager->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);125 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id); 131 126 } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!'; 132 127 return $Output; 133 128 } 134 129 135 function GetPageHeader() 130 function GetPageHeader(): string 136 131 { 137 132 return '<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'. … … 152 147 } 153 148 154 function ShowEdit() 155 { 156 $Output = ''; 157 $Category = $this->GetCategory(); 158 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 149 function ShowEdit(): string 150 { 151 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 152 $Output = ''; 153 $Category = $this->GetCategory(); 154 if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 159 155 { 160 156 $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']); 161 157 $Row = $DbResult->fetch_array(); 162 if (($ this->System->User->User['Id'] == $Row['User']))158 if (($User->User['Id'] == $Row['User'])) 163 159 { 164 160 $this->System->PageHeaders[] = array($this, 'GetPageHeader'); … … 177 173 } 178 174 179 function ShowUpdate() 180 { 175 function ShowUpdate(): string 176 { 177 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 181 178 $Output = ''; 182 179 $RemoteAddr = GetRemoteAddress(); 183 180 $Category = $this->GetCategory(); 184 if ($ this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))181 if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 185 182 { 186 183 $_POST['id'] = $_POST['id'] * 1; … … 189 186 { 190 187 $Row = $DbResult->fetch_array(); 191 if ($ this->System->User->User['Id'] == $Row['User'])188 if ($User->User['Id'] == $Row['User']) 192 189 { 193 190 $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'], … … 201 198 } 202 199 203 function ShowDelete() 204 { 205 $Output = ''; 206 $Category = $this->GetCategory(); 207 if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 200 function ShowDelete(): string 201 { 202 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 203 $Output = ''; 204 $Category = $this->GetCategory(); 205 if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])) 208 206 { 209 207 $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']); 210 208 $Row = $DbResult->fetch_array(); 211 if ($ this->System->User->User['Id'] == $Row['User'])209 if ($User->User['Id'] == $Row['User']) 212 210 { 213 211 // TODO: Make upload using general File class … … 218 216 foreach ($Enclosures as $Enclosure) 219 217 { 220 if (file_exists( $this->UploadedFilesFolder.$Enclosure)) unlink($this->UploadedFilesFolder.$Enclosure);218 if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) unlink(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure); 221 219 } 222 220 } … … 228 226 } 229 227 230 function ShowList() 231 { 232 $Output = ''; 233 $Category = $this->GetCategory(); 234 if ($this->System->User->CheckPermission('News', 'Display', 'Group', $Category['Id'])) 228 function ShowList(): string 229 { 230 $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; 231 $Output = ''; 232 $Category = $this->GetCategory(); 233 if ($User->CheckPermission('News', 'Display', 'Group', $Category['Id'])) 235 234 { 236 235 $PerPage = 20; … … 250 249 else $Author = $Row['Name']; 251 250 $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&id='.$Row['Id'].'">'.$Row['Title'].'</a> ('.HumanDate($Row['Date']).', '.$Author.')'; 252 if (($ this->System->User->User['Id'] == $Row['User']) and ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id'])))251 if (($User->User['Id'] == $Row['User']) and ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))) 253 252 { 254 253 $Output .= '<div class="Action">'; … … 257 256 $Output .= '</div>'; 258 257 } 259 $Output .= '</div><div class="Content">'. $this->System->ModuleManager->Modules['News']->ModifyContent($Row['Content']).'<br />';258 $Output .= '</div><div class="Content">'.ModuleNews::Cast($this->System->GetModule('News'))->ModifyContent($Row['Content']).'<br />'; 260 259 if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>'; 261 260 if ($Row['Enclosure'] != '') … … 265 264 foreach ($Enclosures as $Enclosure) 266 265 { 267 if (file_exists( $this->UploadedFilesFolder.$Enclosure))268 $Output .= ' <a href="'.$this->System->Link('/'. $this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';266 if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) 267 $Output .= ' <a href="'.$this->System->Link('/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 269 268 } 270 269 } … … 277 276 } 278 277 279 function GetCategory() 278 function GetCategory(): array 280 279 { 281 280 $Category = array('Id' => 1); // Default category … … 292 291 } 293 292 294 function Show Main()293 function Show(): string 295 294 { 296 295 $Output = ''; … … 306 305 return $Output; 307 306 } 308 309 function ShowSubscription() 307 } 308 309 class PageNewsUpdate extends Page 310 { 311 function __construct(System $System) 312 { 313 parent::__construct($System); 314 $this->FullTitle = 'Aktualizace aktualit'; 315 $this->ShortTitle = 'Aktualizace aktualit'; 316 $this->ParentClass = 'PageNews'; 317 } 318 319 function Show(): string 320 { 321 $NewsSources = new NewsSources(); 322 $NewsSources->Database = $this->Database; 323 if (array_key_exists('i', $_GET)) $Output = $NewsSources->Parse($_GET['i']); 324 else $Output = $NewsSources->Parse(); 325 return $Output; 326 } 327 } 328 329 class PageNewsSubscription extends Page 330 { 331 function __construct(System $System) 332 { 333 parent::__construct($System); 334 $this->FullTitle = 'Odběry aktualit'; 335 $this->ShortTitle = 'Odběry aktualit'; 336 $this->ParentClass = 'PageNews'; 337 } 338 339 function Show(): string 310 340 { 311 341 if (array_key_exists('build', $_GET)) … … 333 363 return $Output; 334 364 } 335 336 function ShowRSS() 365 } 366 367 class PageNewsRss extends Page 368 { 369 function __construct(System $System) 370 { 371 parent::__construct($System); 372 $this->FullTitle = 'RSS kanál aktualit'; 373 $this->ShortTitle = 'Aktuality RSS'; 374 $this->ParentClass = 'PageNews'; 375 } 376 377 function Show(): string 337 378 { 338 379 $this->ClearPage = true; … … 409 450 foreach ($Enclosures as $Enclosure) 410 451 { 411 if (file_exists( $this->UploadedFilesFolder.$Enclosure))412 $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'. $this->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>';452 if (file_exists(ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure)) 453 $EnclosuresText .= ' <a href="'.$this->System->Link('/aktuality/'.ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.$Enclosure).'">'.$Enclosure.'</a>'; 413 454 } 414 455 } … … 432 473 } 433 474 } 434 435 class PageNewsUpdate extends Page436 {437 function __construct($System)438 {439 parent::__construct($System);440 $this->FullTitle = 'Aktualizace aktualit';441 $this->ShortTitle = 'Aktualizace aktualit';442 $this->ParentClass = 'PageNews';443 }444 445 function Show()446 {447 $NewsSources = new NewsSources();448 $NewsSources->Database = $this->Database;449 if (array_key_exists('i', $_GET)) $Output = $NewsSources->Parse($_GET['i']);450 else $Output = $NewsSources->Parse();451 return $Output;452 }453 }454
Note:
See TracChangeset
for help on using the changeset viewer.