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/RSS/RSS.php

    r874 r887  
    33class ModuleRSS extends AppModule
    44{
    5   var $RSSChannels;
     5  public array $RSSChannels;
    66
    7   function __construct($System)
     7  function __construct(System $System)
    88  {
    99    parent::__construct($System);
     
    1717  }
    1818
    19   function Start()
     19  function DoStart(): void
    2020  {
    21     $this->System->RegisterPage('rss', 'PageRSS');
     21    $this->System->RegisterPage(['rss'], 'PageRSS');
    2222    $this->System->RegisterPageHeader('RSS', array($this, 'ShowRSSHeader'));
    2323  }
    2424
    25   function RegisterRSS($Channel, $Pos = NULL, $Callback = NULL)
     25  function RegisterRSS(array $Channel, $Pos = NULL, $Callback = NULL): void
    2626  {
    2727    $this->RSSChannels[$Channel['Channel']] = $Channel;
    2828
    2929    if (is_null($Pos)) $this->RSSChannelsPos[] = $Channel['Channel'];
    30     else {
     30    else
     31    {
    3132      array_splice($this->RSSChannelsPos, $Pos, 0, $Channel['Channel']);
    3233    }
    3334  }
    3435
    35   function UnregisterRSS($ChannelName)
     36  function UnregisterRSS($ChannelName): void
    3637  {
    3738    unset($this->RSSChannels[$ChannelName]);
     
    3940  }
    4041
    41   function ShowRSSHeader()
     42  function ShowRSSHeader(): string
    4243  {
    4344    $Output = '';
    4445    foreach ($this->RSSChannels as $Channel)
    4546    {
    46       //if ($this->System->User->Licence($Channel['Permission']))
     47      //if (ModuleUser::Cast($this->System->GetModule('User'))->User->Licence($Channel['Permission']))
    4748        $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.
    4849          $this->System->Link('/rss/?channel='.$Channel['Channel']).'" type="application/rss+xml" />';
     
    5051    return $Output;
    5152  }
     53
     54  static function Cast(AppModule $AppModule): ModuleRSS
     55  {
     56    if ($AppModule instanceof ModuleRSS)
     57    {
     58      return $AppModule;
     59    }
     60    throw new Exception('Expected ModuleRSS type but got '.gettype($AppModule));
     61  }
    5262}
    5363
    5464class PageRSS extends Page
    5565{
    56   function Show()
     66  function Show(): string
    5767  {
    5868    $this->ClearPage = true;
     
    6272    if (array_key_exists('token', $_GET)) $Token = $_GET['token'];
    6373      else $Token = '';
    64     if (array_key_exists($ChannelName, $this->System->ModuleManager->Modules['RSS']->RSSChannels))
     74    if (array_key_exists($ChannelName, ModuleRSS::Cast($this->System->GetModule('RSS'))->RSSChannels))
    6575    {
    66       $Channel = $this->System->ModuleManager->Modules['RSS']->RSSChannels[$ChannelName];
    67       if ($this->System->User->CheckPermission($Channel['Permission']['Module'], $Channel['Permission']['Operation']) or
    68       $this->System->User->CheckToken($Channel['Permission']['Module'], $Channel['Permission']['Operation'], $Token))
     76      $Channel = ModuleRSS::Cast($this->System->GetModule('RSS'))->RSSChannels[$ChannelName];
     77      if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($Channel['Permission']['Module'], $Channel['Permission']['Operation']) or
     78      ModuleUser::Cast($this->System->GetModule('User'))->User->CheckToken($Channel['Permission']['Module'], $Channel['Permission']['Operation'], $Token))
    6979      {
    7080        if (is_string($Channel['Callback'][0]))
Note: See TracChangeset for help on using the changeset viewer.