lib/base.php

Go to the documentation of this file.
00001 <?php
00011 class Config {
00012   private static $instance_;
00016   public static function instance() {
00017     if (!isset(self::$instance_))
00018       self::$instance_ = new Config;
00019     return self::$instance_;
00020   }
00021   
00022   private $documentRoot_;
00028   public function documentRoot() {
00029     return $this->documentRoot_;
00030   }
00036   public function setDocumentRoot($documentRoot) {
00037     $this->documentRoot_ = $documentRoot;
00038   }
00039   
00040   private $webName_ = '';
00045   public function webName() {
00046     return $this->webName_;
00047   }
00052   public function setWebName($webName) {
00053     $this->webName_ = $webName;
00054   }
00055   
00056   private $webMasterMail_ = '';
00061   public function webMasterMail() {
00062     return $this->webMasterMail_;
00063   }
00068   public function setWebMasterMail($webMasterMail) {
00069     $this->webMasterMail_ = $webMasterMail;
00070   }
00071   
00072   private $webRoot_ = '';
00077   public function webRoot() {
00078     return $this->webRoot_;
00079   }
00084   public function setWebRoot($webRoot) {
00085     $this->webRoot_ = $webRoot;
00086   }
00087   
00088   private $classDir_ = '';
00093   public function classDir() {
00094     return $this->classDir_;
00095   }
00100   public function setClassDir($classDir) {
00101     $this->classDir_ = $classDir;
00102   }
00103   
00104   private $smartyDir_ = '';
00110   public function smartyDir() {
00111     return $this->smartyDir_;
00112   }
00118   public function setSmartyDir($smartyDir) {
00119     $this->smartyDir_ = $smartyDir;
00120   }
00121   
00126   public $smartyConf = Array();
00127   
00128   private $scriptDir_ = '';
00133   public function scriptDir() {
00134     return $this->scriptDir_;
00135   }
00140   public function setScriptDir($scriptDir) {
00141     $this->scriptDir_ = $scriptDir;
00142   }
00143   
00144   private $cacheDir_ = '';
00150   public function cacheDir() {
00151     return $this->cacheDir_;
00152   }
00158   public function setCacheDir($cacheDir) {
00159     $this->cacheDir_ = $cacheDir;
00160   }
00161   
00162   private $styleDir_ = '';
00167   public function styleDir() {
00168     return $this->styleDir_;
00169   }
00174   public function setStyleDir($styleDir) {
00175     $this->styleDir_ = $styleDir;
00176   }
00177   
00178   private $imgDir_ = '';
00185   public function imgDir() {
00186     return $this->imgDir_;
00187   }
00194   public function setImgDir($imgDir) {
00195     $this->imgDir_ = $imgDir;
00196   }
00197   
00198   private $pageDir_ = '';
00203   public function pageDir() {
00204     return $this->pageDir_;
00205   }
00210   public function setPageDir($pageDir) {
00211     $this->pageDir_ = $pageDir;
00212   }
00213   
00214   private $geshiDir_ = '';
00219   public function geshiDir() {
00220     return $this->geshiDir_;
00221   }
00226   public function setGeshiDir($geshiDir) {
00227     $this->geshiDir_ = $geshiDir;
00228   }
00229   
00230   private $filesDir_ = '';
00235   public function filesDir() {
00236     return $this->filesDir_;
00237   }
00242   public function setFilesDir($filesDir) {
00243     $this->filesDir_ = $filesDir;
00244   }
00245   
00246   private $htmlDir_ = '';
00251   public function htmlDir() {
00252     return $this->htmlDir_;
00253   }
00258   public function setHtmlDir($htmlDir) {
00259     $this->htmlDir_ = $htmlDir;
00260   }
00261   
00262   private $execPhpDir_ = '';
00267   public function execPhpDir() {
00268     return $this->execPhpDir_;
00269   }
00274   public function setExecPhpDir($execPhpDir) {
00275     $this->execPhpDir_ = $execPhpDir;
00276   }
00277   
00278   private $tmpDir_ = '';
00284   public function tmpDir() {
00285     return $this->tmpDir_;
00286   }
00292   public function setTmpDir($tmpDir) {
00293     $this->tmpDir_ = $tmpDir;
00294   }
00295   
00296   private function __construct() {
00297     $this->documentRoot_ = $_SERVER['DOCUMENT_ROOT'];
00298   }
00299 };
00300 
00306 class ClassFactory {
00311   public static function importClass($className) {
00312     $config = Config::instance();
00313     $docRoot = $config->documentRoot();
00314     $classDir = $config->classDir();
00315     require_once($docRoot.$config->classDir().'/'.$className.'.class.php');
00316   }
00317 };
00318 
00323 class JSOnloadList {
00324   private static $instance_;
00328   public static function instance() {
00329     if (!isset(self::$instance_))
00330       self::$instance_ = new JSOnloadList;
00331     return self::$instance_;
00332   }
00333   private $onloadList = Array();
00339   public function addFunction($fnName) {
00340     $this->onloadList []= $fnName;
00341   }
00346   public function generate() {
00347     if (0== count($this->onloadList))
00348       return;
00349     ?>  <script type="text/javascript">
00350 window.onload = function() {
00351 <?php
00352     foreach($this->onloadList as $fn)
00353       echo '  '.$fn."();\n";
00354     ?>}
00355   </script>
00356 <?php
00357   }
00358   private function __construct() { }
00359 }
00360 
00367 class Indentor {
00371   public static function singleton()
00372   {
00373     if (!isset(self::$instance)) {
00374       $c = __CLASS__;
00375       self::$instance = new $c;
00376     }
00377     return self::$instance;
00378   }
00379   
00384   const INDENT_STRING= "  ";
00385   
00389   public function enter() { $this->iLevel ++; }
00393   public function leave() { $this->iLevel --; }
00397   public function level() { return $this->iLevel; }
00401   public function indent()
00402   {
00403     return str_repeat (self::INDENT_STRING, $this->level());
00404   }
00408   public function indentDirect() { echo $this->indent(); }
00413   public function puts($szText)
00414   {
00415     echo $this->indent().$szText."\n";
00416   }
00417   
00418   // Prevent users to clone the instance
00419   public function __clone()
00420   {
00421     trigger_error('Clone is not allowed.', E_USER_ERROR);
00422   }
00423 
00424   private static $instance;
00425   private $iLevel;
00426   private function __construct() 
00427   {
00428     $this->iLevel= 0;
00429   }
00430 };
00431 
00439 class LangSelect {
00440 
00445   public static function singleton ()
00446   {
00447     if (!isset (self::$_instance)) {
00448       $c= __CLASS__;
00449       self::$_instance= new $c;
00450     }
00451 
00452     return self::$_instance;
00453   }
00454 
00460   public function handleLangSelect ()
00461   {
00462     if (isset ($_REQUEST ["lang"]))
00463       // User request for different language
00464       $_SESSION["lang"]= $_REQUEST["lang"];
00465 
00466     if (!isset($_SESSION["lang"]) || !ereg("(^en$)|(^cz$)",$_SESSION["lang"])) {
00467       // Read user-prefered languege from http_header
00468       if (ereg("(^cs)|(^cz)",$_SERVER["HTTP_ACCEPT_LANGUAGE"]))
00469         $_SESSION["lang"]="cz";
00470       else
00471         $_SESSION["lang"]="en";
00472     }
00473   }
00474 
00478   public function getLang ()
00479   {
00480     return $_SESSION["lang"];
00481   }
00482 
00487   public function isLangCz ()
00488   {
00489     return ($this->getLang() == "cz");
00490   }
00491 
00492   private static $_instance;
00493 
00494   private function __construct ()
00495   {
00496     session_start ();
00497     session_register ("lang");
00498   }
00499 
00500   private function __clone ()
00501   {
00502     // TODO - exception??
00503   }
00504 }
00505 
00510 class L10n {
00511   private $langMap = Array();
00518   public function setTranslation($lang, $msgid, $msgstr) {
00519     if (!array_key_exists($lang, $this->langMap))
00520       $this->langMap[$lang] = Array();
00521     $this->langMap[$lang][$msgid] = $msgstr;
00522     if (!array_key_exists($msgid, $this->langMap['en']))
00523       $this->langMap['en'][$msgid] = $msgid;
00524   }
00531   public function trMap($lang=null) {
00532     if (!isset($lang))
00533       $lang = LangSelect::singleton()->getLang();
00534     return $this->langMap[$lang];
00535   }
00544   public function tr($msgid, $lang=null) {
00545     if (!isset($lang))
00546       $lang = LangSelect::singleton()->getLang();
00547     $msg = $msgid;
00548     if (array_key_exists($lang, $this->langMap)) {
00549       $lm = $this->langMap[$lang];
00550       if (array_key_exists($msgid, $lm))
00551         $msg = $lm[$msgid];
00552     }
00553     return $msg;
00554   }
00555   public function __construct() {
00556     $this->langMap['en'] = Array();
00557   }
00558 };
00559 
00564 class ExceptionNotFound extends Exception {
00568   public function __construct($msg=null) {
00569     parent::__construct($msg);
00570   }
00571 };
00572 
00573 ?>

Generated on Sat Mar 8 10:26:43 2008 for Dudka.cz by  doxygen 1.5.4