Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (4 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/News/NewsPage.php

    r878 r887  
    33class PageNews extends Page
    44{
    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í';
    2517    else
    2618    {
     
    3527          else $Author = $Row['Name'];
    3628        $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'])))
    3831        {
    3932          $Output .= '<div class="Action">';
     
    4235          $Output .= '</div>';
    4336        }
    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 />';
    4538        if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    4639        if ($Row['Enclosure'] != '')
     
    5043          foreach ($Enclosures as $Enclosure)
    5144          {
    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>';
    5447          }
    5548        }
     
    6053  }
    6154
    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']))
    6761    {
    6862      $this->System->PageHeaders[] = array($this, 'GetPageHeader');
     
    7569      while ($DbRow = $DbResult->fetch_array())
    7670      {
    77         if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
     71        if ($User->CheckPermission('News', 'Insert', 'Group', $DbRow['Id']))
    7872        {
    7973          if ($DbRow['Id'] == $Category['Id']) $Selected = ' selected="1"';
     
    9690  }
    9791
    98   function ShowAdd2()
    99   {
     92  function ShowAdd2(): string
     93  {
     94    $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
    10095    $Output = '';
    10196    $RemoteAddr = GetRemoteAddress();
    10297    $Category = $this->GetCategory();
    103     if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     98    if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    10499    {
    105100      // Process uploaded file
     
    110105        if (array_key_exists($EnclosureName, $_FILES) and ($_FILES[$EnclosureName]['name'] != ''))
    111106        {
    112           $UploadedFilePath = $this->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
     107          $UploadedFilePath = ModuleNews::Cast($this->System->GetModule('News'))->UploadedFilesFolder.basename($_FILES[$EnclosureName]['name']);
    113108          if (move_uploaded_file($_FILES[$EnclosureName]['tmp_name'], $UploadedFilePath))
    114109          {
     
    124119        $this->Database->insert('News', array('Category' => $Category['Id'], 'Title' => $_POST['title'],
    125120          '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']));
    128123        $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 />';
    129124        $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);
    131126    } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
    132127    return $Output;
    133128  }
    134129
    135   function GetPageHeader()
     130  function GetPageHeader(): string
    136131  {
    137132    return '<script src="'.$this->System->Link('/Packages/TinyMCE/tinymce.min.js').'"></script>'.
     
    152147  }
    153148
    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']))
    159155    {
    160156      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
    161157      $Row = $DbResult->fetch_array();
    162       if (($this->System->User->User['Id'] == $Row['User']))
     158      if (($User->User['Id'] == $Row['User']))
    163159      {
    164160        $this->System->PageHeaders[] = array($this, 'GetPageHeader');
     
    177173  }
    178174
    179   function ShowUpdate()
    180   {
     175  function ShowUpdate(): string
     176  {
     177    $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
    181178    $Output = '';
    182179    $RemoteAddr = GetRemoteAddress();
    183180    $Category = $this->GetCategory();
    184     if ($this->System->User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
     181    if ($User->CheckPermission('News', 'Insert', 'Group', $Category['Id']))
    185182    {
    186183      $_POST['id'] = $_POST['id'] * 1;
     
    189186      {
    190187        $Row = $DbResult->fetch_array();
    191         if ($this->System->User->User['Id'] == $Row['User'])
     188        if ($User->User['Id'] == $Row['User'])
    192189        {
    193190          $this->Database->update('News', 'Id='.$_POST['id'], array('Title' => $_POST['title'],
     
    201198  }
    202199
    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']))
    208206    {
    209207      $DbResult = $this->Database->query('SELECT * FROM `News` WHERE `Id`='.$_GET['id']);
    210208      $Row = $DbResult->fetch_array();
    211       if ($this->System->User->User['Id'] == $Row['User'])
     209      if ($User->User['Id'] == $Row['User'])
    212210      {
    213211        // TODO: Make upload using general File class
     
    218216          foreach ($Enclosures as $Enclosure)
    219217          {
    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);
    221219          }
    222220        }
     
    228226  }
    229227
    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']))
    235234    {
    236235      $PerPage = 20;
     
    250249          else $Author = $Row['Name'];
    251250        $Output .= '<div class="Panel"><div class="Title"><a href="?action=view&amp;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'])))
    253252        {
    254253          $Output .= '<div class="Action">';
     
    257256          $Output .= '</div>';
    258257        }
    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 />';
    260259        if ($Row['Link'] != '') $Output .= '<br/><a href="'.$Row['Link'].'">Odkaz</a>';
    261260        if ($Row['Enclosure'] != '')
     
    265264          foreach ($Enclosures as $Enclosure)
    266265          {
    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>';
    269268          }
    270269        }
     
    277276  }
    278277
    279   function GetCategory()
     278  function GetCategory(): array
    280279  {
    281280    $Category = array('Id' => 1); // Default category
     
    292291  }
    293292
    294   function ShowMain()
     293  function Show(): string
    295294  {
    296295    $Output = '';
     
    306305    return $Output;
    307306  }
    308 
    309   function ShowSubscription()
     307}
     308
     309class 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
     329class 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
    310340  {
    311341    if (array_key_exists('build', $_GET))
     
    333363    return $Output;
    334364  }
    335 
    336   function ShowRSS()
     365}
     366
     367class 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
    337378  {
    338379    $this->ClearPage = true;
     
    409450        foreach ($Enclosures as $Enclosure)
    410451        {
    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>';
    413454        }
    414455      }
     
    432473  }
    433474}
    434 
    435 class PageNewsUpdate extends Page
    436 {
    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.