Changeset 63 for trunk/index.php


Ignore:
Timestamp:
Aug 3, 2021, 11:20:41 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Used explicit types where possible for better error reporting.
  • Modified: Updated Common packaged to newer version.
  • Modified: Simplified pages title.
  • Added: Simple keyword based spam filter for meet items.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1 nbproject
        2 Config.php
        31.settings
        42.project
        53.buildpath
         4.htaccess
  • trunk/index.php

    r61 r63  
    55require_once('Packages/Common/Common.php');
    66require_once('View.php');
    7 
    87
    98require_once('Modules/Meet/Meet.php');
     
    1817if (isset($_SERVER['REMOTE_ADDR'])) session_start();
    1918
    20 class ApplicationTanec extends Application
    21 {
    22   var $Config;
    23   var $Title;
    24   var $Pages;
    25   var $PathItems;
    26   var $ShowPage;
    27   var $MainMenu;
    28   var $PageHeaders;
    29   var $Bars;
     19class Core extends System
     20{
     21  public array $Config;
     22  public array $PathItems;
     23  public bool $ShowPage;
     24  public array $MainMenu;
     25  public array $PageHeaders;
     26  public array $Bars;
    3027
    3128  function __construct()
     
    3835  }
    3936
    40   function IsAdmin()
     37  function IsAdmin(): bool
    4138  {
    4239    return array_key_exists('IsAdmin', $_SESSION) and ($_SESSION['IsAdmin'] == 1);
    4340  }
    4441
    45   function Link($URL)
     42  function Link(string $URL): string
    4643  {
    4744    return $this->Config['BaseURL'].$URL;
    4845  }
    4946
    50   function AbsoluteLink($URL)
     47  function AbsoluteLink(string $URL): string
    5148  {
    5249    return $this->Config['HostName'].$this->Config['BaseURL'].$URL;
    5350  }
    5451
    55   function ShowMenu()
     52  function ShowMenu(): string
    5653  {
    5754    $Output = '<div>';
     
    6461  }
    6562
    66   function ProcessURL()
     63  function ProcessURL(): array
    6764  {
    6865    if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     
    7875  }
    7976
    80   function RegisterPage($Path, $Handler)
     77  function RegisterPage($Path, $Handler): void
    8178  {
    8279    if (is_array($Path))
     
    9390  }
    9491
    95   function RegisterMenuItem($Link, $Title)
     92  function RegisterMenuItem(string $Link, string $Title): void
    9693  {
    9794     $this->MainMenu[] = array('Link' => $Link, 'Title' => $Title);
    9895  }
    9996
    100   function RegisterPageHeader($Name, $Callback)
     97  function RegisterPageHeader(string $Name, array $Callback): void
    10198  {
    10299    $this->PageHeaders[$Name] = $Callback;
    103100  }
    104101
    105   function RegisterPageBar($Name)
     102  function RegisterPageBar(string $Name): void
    106103  {
    107104    $this->Bars[$Name] = array();
    108105  }
    109106
    110   function UnregisterPageBar($Name)
     107  function UnregisterPageBar(string $Name): void
    111108  {
    112109    unset($this->Bars[$Name]);
    113110  }
    114111
    115   function SearchPage($PathItems, $Pages)
     112  function SearchPage(array $PathItems, array $Pages): ?string
    116113  {
    117114    if (count($PathItems) > 0) $PathItem = $PathItems[0];
     
    127124  }
    128125
    129   function PageNotFound()
     126  function PageNotFound(): string
    130127  {
    131128    return 'Page '.implode('/', $this->PathItems).' not found.';
    132129  }
    133130
    134   function ShowPage()
     131  function ShowPage(): void
    135132  {
    136133    $this->BaseView = new BaseView($this);
    137134
    138     /* @var $Page Page */
    139135    $ClassName = $this->SearchPage($this->PathItems, $this->Pages);
    140136    if ($ClassName != '')
    141137    {
    142138      $Page = new $ClassName($this);
    143     } else {
     139    } else
     140    {
    144141      $Page = new PageMissing($this);
    145142    }
     
    147144  }
    148145
    149   function Run()
     146  function Run(): void
    150147  {
    151148    $this->RunCommon();
     
    157154  }
    158155
    159   function RunCommon()
     156  function RunCommon(): void
    160157  {
    161158    global $Config;
     
    172169
    173170    $this->RegisterPageBar('Top');
    174     $this->Title = 'Tanec';
    175     $Output = '';
     171    $this->Name = 'Tanec';
     172  }
     173
     174  static function Cast(System $System): Core
     175  {
     176    if ($System instanceof Core)
     177    {
     178      return $System;
     179    }
     180    throw new Exception('Expected Core type but '.gettype($System));
    176181  }
    177182}
     
    179184class PageMissing extends Page
    180185{
    181   var $FullTitle = 'Stránka nenalezena';
    182   var $ShortTitle = 'Stránka nenalezena';
    183 
    184186  function __construct($System)
    185187  {
    186188    parent::__construct($System);
     189    $this->Title = 'Stránka nenalezena';
    187190    $this->ParentClass = 'PagePortal';
    188191  }
    189192
    190   function Show()
     193  function Show(): string
    191194  {
    192195    Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
     
    202205  }
    203206
    204   function Show()
     207  function Show(): string
    205208  {
    206209    $this->RawPage = true;
     
    214217class PageSiteMap extends Page
    215218{
    216   function Show()
     219  function Show(): string
    217220  {
    218221    $this->RawPage = true;
     
    265268class PageLogin extends Page
    266269{
    267   function Show()
     270  function __construct($System)
     271  {
     272    parent::__construct($System);
     273    $this->Title = 'Přihlášení';
     274    $this->ParentClass = 'PagePortal';
     275  }
     276
     277  function Show(): string
    268278  {
    269279    global $Config;
     
    296306      $Output .= $this->ShowLoginForm();
    297307    }
    298     if ($this->System->IsAdmin()) $Output .= '<div>Jsi přihlášen jako správce. <a href="?logoff">Odhlásit</a></div>';
     308    if(Core::Cast($this->System)->IsAdmin()) $Output .= '<div>Jsi přihlášen jako správce. <a href="?logoff">Odhlásit</a></div>';
    299309    return $Output;
    300310  }
    301311
    302   function ShowLoginForm()
     312  function ShowLoginForm(): string
    303313  {
    304314    return '<form method="post" action="?login">'.
    305         'Heslo: <input type="password" name="password" value=""/><br/>'.
    306         '<input type="submit" value="Přihlásit"/>'.
    307         '</form>';
    308   }
    309 }
    310 
    311 $Revision = 51; // Subversion revision
     315      'Heslo: <input type="password" name="password" value=""/><br/>'.
     316      '<input type="submit" value="Přihlásit"/>'.
     317      '</form>';
     318  }
     319}
     320
     321$Revision = 63; // Subversion revision
    312322$DatabaseRevision = 51; // SQL structure revision
    313 $ReleaseTime = strtotime('2020-01-01');
    314 
    315 $Application = new ApplicationTanec();
     323$ReleaseTime = strtotime('2021-08-03');
     324
     325$Application = new Core();
    316326$Application->ModuleManager->LoadModulesFromDir(dirname(__FILE__).'/Modules');
    317327$Application->Modules = $Application->ModuleManager->Modules;
    318328$Application->ModuleManager->InstallAll();
    319329$Application->ModuleManager->StartAll();
    320 $Application->RegisterPage('', 'PageDanceList');
    321 $Application->RegisterPage('robots.txt', 'PageRobots');
    322 $Application->RegisterPage('sitemap.xml', 'PageSiteMap');
    323 $Application->RegisterPage('admin', 'PageLogin');
     330$Application->RegisterPage([''], 'PageDanceList');
     331$Application->RegisterPage(['robots.txt'], 'PageRobots');
     332$Application->RegisterPage(['sitemap.xml'], 'PageSiteMap');
     333$Application->RegisterPage(['admin'], 'PageLogin');
    324334$Application->Run();
Note: See TracChangeset for help on using the changeset viewer.