Ignore:
Timestamp:
Sep 11, 2009, 8:18:38 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Zrušeny samostatné include soubory a správně vloženy přímé závislosti pomocí include_once do všech souborů. Takto se budou načítat jen ty třídy, které jsou skutenčě potřeba.
  • Upraveno: Aplikace se nyní inicializuje přes soubor Application.php, kde je vložena třída odvozená z třídy System. Hlavní soubor index.php se pak odkazuje na soubor aplikace.
  • Objekty Database, Config a Translation jsou nyní lokální v rámci třídy System.
  • Přidáno: Třída pro odesílání pošty. Použita v třídě User.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/Base/System.php

    r76 r78  
    11<?php
     2
     3include_once(dirname(__FILE__).'/Database.php');
     4include_once(dirname(__FILE__).'/Form.php');
     5include_once(dirname(__FILE__).'/Table.php');
     6include_once(dirname(__FILE__).'/Error.php');
    27
    38$PrefixMultipliers = array
     
    7984  var $Database;
    8085  var $Config;
     86  var $TimeStart;
     87  var $Translation;
     88 
     89  function __construct()
     90  {
     91    // Change current directory to script location
     92    $BaseDir = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
     93    if($BaseDir != '') chdir($BaseDir);
     94
     95    if(array_key_exists('argv', $_SERVER))
     96      $_GET = array_merge($_GET, ParseCommandLineArgs($_SERVER['argv']));
     97
     98    // SQL injection hack protection
     99    foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
     100    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
     101
     102    if(isset($_SERVER['REMOTE_ADDR'])) session_start();
     103     
     104    $FileName = dirname(__FILE__).'/../Application/Config/Config.php';
     105    if(file_exists($FileName)) include_once($FileName);
     106      else die('Nenalezen soubor '.$FileName.'. Vytvořte jej kopií ze souboru ConfigSample.php umístěném ve stejné složce.');
     107    $this->Config = $Config;
     108   
     109    $FileName = dirname(__FILE__).'/../Application/Localization/'.$Config['Web']['Locale'].'.php';
     110    if(file_exists($FileName)) include_once($FileName);
     111      else die('Nenalezen soubor '.$FileName.'. Buď máte špatně nastaven jazyk nebo vám chybí jazykový soubor.');
     112    $this->Translation = $Translation;
     113
     114    $this->TimeStart = $this->GetMicrotime();
     115    $this->Database = new Database($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']);
     116    $this->Database->Prefix = $this->Config['Database']['Prefix'];
     117    $this->Database->charset($this->Config['Database']['Charset']);   
     118  }
     119 
     120  function Run()
     121  {
     122    if(array_key_exists('Module', $_GET)) $Module = $_GET['Module'];
     123      else $Module = 'HomePage';
     124
     125    $ControllerName = $Module.'Controller';
     126    $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
     127    if(!file_exists($FileName))
     128      echo('Soubor '.$FileName.' nenalezen.');
     129      else include($FileName);
     130    if(class_exists($ControllerName))
     131    {
     132      $Controller = new $ControllerName($this);
     133      echo($Controller->Process());
     134    } else echo('Modul '.$ControllerName.' nenalezen.');
     135  }
    81136
    82137  function ModulePresent($Name)
     
    85140  }
    86141
    87   function AddModule($Module)
    88   {
    89     global $Database;
    90 
    91     //echo('Přidávám modul '.get_class($Module).'<br />');
    92     $this->Modules[get_class($Module)] = $Module;
    93   }
    94  
    95   function AddEmailToQueue($Address, $Subject, $Content, $Headers = '')
    96   {
    97     $this->Database->insert('EmailQueue', array('Address' => $Address, 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()', 'Headers' => $Headers));
    98   }
    99  
    100   function MailUTF8($To, $Subject = '(No subject)', $Message = '', $Header = '')
    101   {
    102     $Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n".$Header;
    103     mail($To, '=?UTF-8?B?'.base64_encode($Subject).'?=', $Message, $Header);
    104     //echo('mail('.$To.', =?UTF-8?B?'.base64_encode($Subject).'?=, '.$Message.', '.$Header.')<br/>');
    105   }
    106 
    107   function ProcessEmailQueue()
    108   {
    109     $Output = '';
    110     $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
    111     while($DbRow = $DbResult->fetch_assoc())
    112     {     
    113       $this->MailUTF8($DbRow['Address'], $DbRow['Subject'], $DbRow['Content'], $DbRow['Headers']);
    114       //echo('mail('.$DbRow['Address'].', '.$DbRow['Subject'].', '.$DbRow['Content'].', FromUTF8('.$DbRow['Headers'].', \'iso2\'));');
    115       $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));
    116       $this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
    117       $Output .= 'To: '.$DbRow['Address'].'  Subject: '.$DbRow['Subject'].'<br />';
    118     }   
    119     return($Output);
     142  function AddModule($Name)
     143  {
     144    $this->Modules[$Name] = new $Name($this);
    120145  }
    121146 
     
    189214  function Translate($Text)
    190215  {
    191     global $Translation;
    192 
    193     if(array_key_exists($Text, $Translation)) return($Translation[$Text]);
     216    if(array_key_exists($Text, $this->Translation)) return($this->Translation[$Text]);
    194217      else return('#'.$Text);
    195218  }
     219 
     220  function GetRemoteAddress()
     221  {
     222    if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ;
     223    else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
     224    else $IP = '0.0.0.0';
     225    return($IP);
     226  } 
    196227}
    197228
Note: See TracChangeset for help on using the changeset viewer.