Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (3 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/News.php

    r878 r887  
    1313class ModuleNews extends AppModule
    1414{
    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)
    1919  {
    2020    parent::__construct($System);
     
    2828  }
    2929
    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');
    4244    $this->System->FormManager->RegisterClass('News', array(
    4345      'Title' => 'Aktualita',
     
    8688    if ($this->System->ModuleManager->ModulePresent('Search'))
    8789    {
    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
    9395  {
    9496    $ItemCount = abs($ItemCount);
     
    98100    $Output = '<div class="NewsPanel"><div class="Title">'.$Row['Caption'];
    99101    $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))
    101103      $Output .= ' <a href="aktuality/?action=add&amp;category='.$Category.'">Přidat</a>';
    102104    $Output .= '</div></div><div class="Content">';
     
    139141  }
    140142
    141   function LoadSettingsFromCookies()
     143  function LoadSettingsFromCookies(): void
    142144  {
    143145    // Initialize default news setting
     
    163165  }
    164166
    165   function Show()
     167  function Show(): string
    166168  {
    167169    $Output = '';
     
    197199  }
    198200
    199   function ShowCustomizeMenu()
     201  function ShowCustomizeMenu(): string
    200202  {
    201203    $Output = '<form action="?Action=CustomizeNewsSave" method="post">';
     
    220222  }
    221223
    222   function CustomizeSave()
     224  function CustomizeSave(): void
    223225  {
    224226    $Checkbox = array('' => 0, 'on' => 1);
     
    245247  }
    246248
    247   function ModifyContent($Content)
     249  function ModifyContent(string $Content): string
    248250  {
    249251    $Result = '';
     
    254256    {
    255257      $I = strpos($Content, 'http://');
    256       if (($I > 0) and ($Content{$I - 1} != '"'))
     258      if (($I > 0) and ($Content[$I - 1] != '"'))
    257259      {
    258260        $Result .= substr($Content, 0, $I);
     
    272274    return $Result;
    273275  }
     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  }
    274285}
Note: See TracChangeset for help on using the changeset viewer.