Changeset 545 for trunk/includes


Ignore:
Timestamp:
Jun 18, 2013, 6:07:52 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Prvotní podpora pro modulární systém.
  • Přidáno: Podpora pro používání pěkných URL.
  • Upraveno: Vstupní stránka se generuje z modulu FrontPage.
  • Upraveno: Stránka banners převedena na modul Referrer.
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        55.project
        66.buildpath
         7Query.log
  • trunk/includes/Page.php

    r542 r545  
    11<?php
    2 
    3 function ShowShoutbox()
    4 {
    5   global $System, $Config, $User, $System;
    6  
    7   $Output = '<strong><a href="'.$System->Link('/action.php?action=ShoutBoxView').'">Kecátko:</a></strong>';
    8   if($User->Licence(LICENCE_USER))
    9     $Output .= ' <a href="'.$System->Link('/action.php?action=shoutbox').'">Vložit</a>';
    10   $Output .= '<div class="box"><table>';
    11   $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
    12   while($Line = $DbResult->fetch_assoc())
    13     $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>';
    14   $Output .= '</table></div>';
    15   return($Output);
    16 }
    172
    183function ShowTopBar()
     
    340325}
    341326
     327class Page
     328{
     329  var $System;
     330  var $Database;
     331 
     332  function __construct($System)
     333  {
     334    $this->System = &$System;
     335    $this->Database = &$System->Database;   
     336  }
     337       
     338        function Show()
     339        {
     340                return('');
     341  }
     342 
     343  function GetOutput()
     344  {
     345        $Output = $this->Show();
     346        $Output = ShowPage($Output);     
     347        return($Output);
     348  }
     349}
     350
    342351?>
  • trunk/includes/Version.php

    r543 r545  
    11<?php
    22
    3 $Revision = 543; // Subversion revision
     3$Revision = 545; // Subversion revision
    44$DatabaseRevision = 543; // Database structure revision
    5 $ReleaseTime = '2013-06-17';
     5$ReleaseTime = '2013-06-18';
    66
    77?>
  • trunk/includes/global.php

    r538 r545  
    1111  include_once(dirname(__FILE__).'/config.php');
    1212include_once(dirname(__FILE__).'/Version.php');
     13include_once(dirname(__FILE__).'/AppModule.php');
     14
     15// Include application modules
     16// TODO: Make modules configurable
     17include_once(dirname(__FILE__).'/../Modules/AoWoW/AoWoW.php');
     18include_once(dirname(__FILE__).'/../Modules/Referrer/Referrer.php');
     19include_once(dirname(__FILE__).'/../Modules/FrontPage/FrontPage.php');
    1320
    1421GlobalInit();
     
    5259  // TODO: Global initialized variable should be removed
    5360  $TranslationTree = GetTranslationTree();
    54 
    55   LogReferrer();
     61 
     62  // Initialize application modules
     63  $System->ModuleManager->RegisterModule(new AoWoW($System));
     64  $System->ModuleManager->RegisterModule(new Referrer($System));
     65  $System->ModuleManager->Modules['Referrer']->Excluded[] = $System->Config['Web']['Host'];
     66  $System->ModuleManager->RegisterModule(new FrontPage($System));
     67  $System->ModuleManager->StartAll();
    5668}
    5769
     
    633645  if($Session) $_SESSION[$Name] = $Result;
    634646  return($Result);
    635 }
    636 
    637 function LogReferrer()
    638 {
    639   global $System;
    640 
    641   if(array_key_exists('HTTP_REFERER', $_SERVER))
    642   {
    643     $Referrer = addslashes($_SERVER['HTTP_REFERER']);
    644     $HostName = substr($Referrer, strpos($Referrer, '/') + 2);
    645     $HostName = substr($HostName, 0, strpos($HostName, '/'));
    646     if($HostName != $System->Config['Web']['Host'])
    647     {
    648       $DbResult = $System->Database->query('SELECT `Id` FROM `Referrer` WHERE `Web` = "'.$HostName.'"');
    649       if($DbResult->num_rows > 0)
    650       {
    651         $DbRow = $DbResult->fetch_assoc();
    652         $System->Database->query('UPDATE `Referrer` SET `Hits` = `Hits` + 1, `DateLast` = NOW(), `LastURL` = "'.addslashes($Referrer).'" WHERE `Id` = '.$DbRow['Id']);
    653       } else $System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`) VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1)');
    654     }
    655   }
    656647}
    657648
     
    744735}
    745736
     737function ProcessURL()
     738{
     739        if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     740                $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
     741        else $PathString = '';
     742        if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
     743        $PathItems = explode('/', $PathString);
     744        if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
     745                $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
     746        else $_SERVER['QUERY_STRING'] = '';
     747        parse_str($_SERVER['QUERY_STRING'], $_GET);
     748        return($PathItems);
     749}
     750
    746751?>
  • trunk/includes/system.php

    r542 r545  
    2121  var $Database;
    2222  var $Config;
     23  var $ModuleManager;
     24  var $PathItems;
    2325 
    2426  function __construct()
     
    4042    $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
    4143    $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];
     44    $this->ModuleManager = new AppModuleManager();
    4245  }
    4346 
     
    5053  function Link($Target)
    5154  {
    52     global $Config;
    53    
    54     return($Config['Web']['BaseURL'].$Target);
     55    return($this->Config['Web']['BaseURL'].$Target);
    5556  }
     57 
     58  function RegisterPage($Path, $Handler)
     59  {
     60    if(is_array($Path))
     61    {
     62      $Page = &$this->Pages;
     63      $LastKey = array_pop($Path);
     64      foreach($Path as $PathItem)
     65      {
     66        $Page = &$Page[$PathItem];       
     67      }
     68      if(!is_array($Page)) $Page = array('' => $Page);
     69      $Page[$LastKey] = $Handler;
     70    } else $this->Pages[$Path] = $Handler;
     71  }
     72 
     73  function SearchPage($PathItems, $Pages)
     74  {
     75    if(count($PathItems) > 0) $PathItem = $PathItems[0];
     76      else $PathItem = '';
     77    if(array_key_exists($PathItem, $Pages))
     78    {
     79      if(is_array($Pages[$PathItem]))
     80      {
     81        array_shift($PathItems);
     82        return($this->SearchPage($PathItems, $Pages[$PathItem]));
     83      } else return($Pages[$PathItem]);
     84    } else return('');
     85  }
     86 
     87  function PageNotFound()
     88  {
     89    return('Page '.implode('/', $this->PathItems).' not found.');
     90  }
     91 
     92  function ShowPage()
     93  {
     94    /* @var $Page Page */
     95    $ClassName = $this->SearchPage($this->PathItems, $this->Pages);     
     96    if($ClassName != '')
     97    {
     98      $Page = new $ClassName($this);
     99      $Page->GetOutput();
     100    } else echo($this->PageNotFound());
     101  }
    56102}
    57 
    58 ?>
Note: See TracChangeset for help on using the changeset viewer.