Changeset 887 for trunk/Modules/News
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- Location:
- trunk/Modules/News
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/News/Import/Vismo.php
r878 r887 3 3 class NewsSourceVismo extends NewsSource 4 4 { 5 function Import() 5 function Import(): string 6 6 { 7 7 $Output = parent::Import(); -
trunk/Modules/News/ImportKinoVatra.php
r873 r887 1 1 <?php 2 2 3 include_once(dirname(__FILE__).'/../../Application/ System.php');4 $System = new System();3 include_once(dirname(__FILE__).'/../../Application/Core.php'); 4 $System = new Core(); 5 5 $System->ShowPage = false; 6 6 $System->Run(); -
trunk/Modules/News/ImportTvBeskyd.php
r873 r887 1 1 <?php 2 2 3 include_once(dirname(__FILE__).'/../../Application/ System.php');3 include_once(dirname(__FILE__).'/../../Application/Core.php'); 4 4 $System = new Core(); 5 5 $System->ShowPage = false; -
trunk/Modules/News/News.php
r878 r887 13 13 class ModuleNews extends AppModule 14 14 { 15 var$NewsCountPerCategory = 3;16 var$UploadedFilesFolder = 'files/news/';17 18 function __construct( $System)15 public int $NewsCountPerCategory = 3; 16 public string $UploadedFilesFolder = 'files/news/'; 17 18 function __construct(System $System) 19 19 { 20 20 parent::__construct($System); … … 28 28 } 29 29 30 function DoInstall() 31 { 32 } 33 34 function DoUnInstall() 35 { 36 } 37 38 function DoStart() 39 { 40 $this->System->RegisterPage('aktuality', 'PageNews'); 41 $this->System->RegisterPage(array('aktuality', 'aktualizace'), 'PageNewsUpdate'); 30 function DoInstall(): void 31 { 32 } 33 34 function DoUnInstall(): void 35 { 36 } 37 38 function DoStart(): void 39 { 40 $this->System->RegisterPage(['aktuality'], 'PageNews'); 41 $this->System->RegisterPage(['aktuality', 'subscription'], 'PageNewsSubscription'); 42 $this->System->RegisterPage(['aktuality', 'rss'], 'PageNewsRss'); 43 $this->System->RegisterPage(['aktuality', 'aktualizace'], 'PageNewsUpdate'); 42 44 $this->System->FormManager->RegisterClass('News', array( 43 45 'Title' => 'Aktualita', … … 86 88 if ($this->System->ModuleManager->ModulePresent('Search')) 87 89 { 88 $this->System->ModuleManager->Modules['Search']->RegisterSearch('Novinky', 'News', array('Title', 'Content'));89 } 90 } 91 92 function ShowNews( $Category, $ItemCount, $DaysAgo)90 ModuleSearch::Cast($this->System->GetModule('Search'))->RegisterSearch('Novinky', 'News', array('Title', 'Content')); 91 } 92 } 93 94 function ShowNews(string $Category, int $ItemCount, int $DaysAgo): string 93 95 { 94 96 $ItemCount = abs($ItemCount); … … 98 100 $Output = '<div class="NewsPanel"><div class="Title">'.$Row['Caption']; 99 101 $Output .= '<div class="Action"><a href="aktuality/?category='.$Category.'">Zobrazit</a>'; 100 if ( $this->System->User->CheckPermission('News', 'Insert', 'Group', $Category))102 if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('News', 'Insert', 'Group', $Category)) 101 103 $Output .= ' <a href="aktuality/?action=add&category='.$Category.'">Přidat</a>'; 102 104 $Output .= '</div></div><div class="Content">'; … … 139 141 } 140 142 141 function LoadSettingsFromCookies() 143 function LoadSettingsFromCookies(): void 142 144 { 143 145 // Initialize default news setting … … 163 165 } 164 166 165 function Show() 167 function Show(): string 166 168 { 167 169 $Output = ''; … … 197 199 } 198 200 199 function ShowCustomizeMenu() 201 function ShowCustomizeMenu(): string 200 202 { 201 203 $Output = '<form action="?Action=CustomizeNewsSave" method="post">'; … … 220 222 } 221 223 222 function CustomizeSave() 224 function CustomizeSave(): void 223 225 { 224 226 $Checkbox = array('' => 0, 'on' => 1); … … 245 247 } 246 248 247 function ModifyContent( $Content)249 function ModifyContent(string $Content): string 248 250 { 249 251 $Result = ''; … … 254 256 { 255 257 $I = strpos($Content, 'http://'); 256 if (($I > 0) and ($Content {$I - 1}!= '"'))258 if (($I > 0) and ($Content[$I - 1] != '"')) 257 259 { 258 260 $Result .= substr($Content, 0, $I); … … 272 274 return $Result; 273 275 } 276 277 static function Cast(AppModule $AppModule): ModuleNews 278 { 279 if ($AppModule instanceof ModuleNews) 280 { 281 return $AppModule; 282 } 283 throw new Exception('Expected ModuleNews type but got '.gettype($AppModule)); 284 } 274 285 } -
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 -
trunk/Modules/News/NewsSource.php
r878 r887 1 1 <?php 2 2 3 function GetTextBetween( &$Text, $Start, $End)3 function GetTextBetween(string &$Text, string $Start, string $End): string 4 4 { 5 5 $Result = ''; … … 34 34 } 35 35 36 function HumanDateTimeToTime( $DateTime)36 function HumanDateTimeToTime(string $DateTime): int 37 37 { 38 38 if ($DateTime == '') return NULL; … … 49 49 } 50 50 51 function HumanDateToTime( $Date)51 function HumanDateToTime(string $Date): int 52 52 { 53 53 if ($Date == '') return NULL; … … 55 55 } 56 56 57 function GetUrlBase( $Url)57 function GetUrlBase(string $Url): string 58 58 { 59 59 $Result = parse_url($Url); … … 63 63 class NewsSources 64 64 { 65 public $Database;65 public Database $Database; 66 66 67 67 function Parse($Id = null) … … 94 94 class NewsSource 95 95 { 96 public $Name;97 public $URL;96 public string $Name; 97 public string $URL; 98 98 public $Method; 99 public $Id;100 public $Database;101 public $NewsItems;102 public $AddedCount;99 public int $Id; 100 public Database $Database; 101 public array $NewsItems; 102 public int $AddedCount; 103 103 public $Category; 104 104 … … 109 109 } 110 110 111 function Import() 111 function Import(): string 112 112 { 113 113 return ''; 114 114 } 115 115 116 function DoImport() 116 function DoImport(): string 117 117 { 118 118 $this->NewsItems = array(); … … 133 133 class NewsItem 134 134 { 135 var$Database;136 var$Title = '';137 var$Content = '';138 var $Date = '';139 var$Link = '';140 var$Category = '';141 var$Author = '';142 var$IP = '';143 var$Enclosure = '';135 public Database $Database; 136 public string $Title = ''; 137 public string $Content = ''; 138 public int $Date = 0; 139 public string $Link = ''; 140 public string $Category = ''; 141 public string $Author = ''; 142 public string $IP = ''; 143 public string $Enclosure = ''; 144 144 145 function AddIfNotExist() 145 function AddIfNotExist(): int 146 146 { 147 147 $Where = '(`Title` = "'.$this->Database->real_escape_string($this->Title).'") AND '.
Note:
See TracChangeset
for help on using the changeset viewer.