run.php 3.79 KB
<?php
session_start();
require_once("config.class.php");
require_once("router.class.php");
require_once("controller_base.class.php");
require_once("block_base.class.php");
require_once("db.class.php");
require_once("template.class.php");
require_once("blocks.php");
require_once("libs/PHPMailer/class.phpmailer.php");
require_once("libs/resize-class.php");
require_once("libs/HTTP/Download.php");
require_once("function.php");

Config::init();
    spl_autoload_register('__autoload');
    function __autoload($class_name) {
    $dir = 'modules';
    //print strchr($class_name,'Block',true);
   /* if(preg_match("/(.+)Block/i", $class_name, $matches)){
      $filename = 'blocks/' . strtolower($matches[1]) . '.block.class.php';
    }else  */

    $filename = 'model/' . strtolower($class_name) . '.class.php';

   /* if ($dh = opendir($dir)) {
        while (($module = readdir($dh)) !== false) {
           if($module!="." && $module!=".."){   */


    $file = $dir . '/' . router::$modul . '/' . $filename;
    if (file_exists($file) == true)
    {
      include ($file);  return;
    }

           
        /*   }
        }
        closedir($dh);
    }      */


}

Class Run{

 private $tpl;
 private $error = array();
 private $router;
 private $blocks;
 private $model;
 private $url;
 private $this_url;
 private $navig;
 private $meta;
 
 function __construct() {
  $this->tpl = new Template(new Config);
  $this->router = new router();
  $this->router->setPath (Config::get('modules_path'),Config::get('modules_default'),Config::get('modules_controller_path'));
 // $this->router->setStart(Config::get('start'));
  $this->router->setRule(Config::get('rules'));
  $this->router->setLangs(Config::get('langs'),Config::get('lang'));
  $this->blocks = new Blocks();
 }
 
 public function loader(){
  $module = $this->router->loader();
  $this->loaderLang($this->router->lang);
  $this->view_url(Config::get('url'),Config::get('lang'),$this->router->lang);
  $this->setMeta();
  $this->setNavig();

  $this->router->setParams($this->tpl,$this->error,$this->url,$this->this_url,$this->navig,$this->meta);
  $this->router->run();
  
  $this->blocks->setParams($this->tpl,$this->error,$this->router->lang,$this->url,$this->router->getParam,$this->router->postParam);
  $this->blocks->loader($module['path'],$module['controller']);
  $this->view_lang($this->router->lang);
  $this->view_linksLangs(Config::get('url'),Config::get('langs'),Config::get('lang'),$this->router->lang);
  $this->view_meta();
  $this->view_navig();
  $this->layout();
 }
 
 private function setMeta(){
  $this->meta = Config::get('meta');
 }
 
 private function setNavig(){
  $this->navig[] = array('url'=>$this->url,'name'=>Config::get('site'));
 }
 
 private function view_lang($lang){
  $this->tpl->viewLang($lang);
 }
 
 private function view_url($url,$default_lang,$lang){
  $this->url = $url;
  $this->this_url = $this->url . '/' . $_GET['rt'];
  if($default_lang!=$lang)$this->url .= '/' . $lang;
  $this->tpl->viewUrl($this->this_url,$this->url);
 }
 
 private function loaderLang($lang){
  $path = "lang/" . $lang . ".php";
  if( is_readable($path) ){
   include_once $path;
  }
 }
 
 private function view_linksLangs($url,$langs,$default_lang,$lang){// print $_SERVER['REQUEST_URI'];
  $l = array();
  $field = strrchr($url, '/');
  $REQUEST_URI = str_replace($field,'',$_SERVER['REQUEST_URI']);
  $r = explode($lang,$REQUEST_URI);
  foreach($langs as $str_lang){
   $l[$str_lang] = $url . '/';
   if($default_lang!=$str_lang)$l[$str_lang] .= $str_lang . '/';
   $l[$str_lang] .= substr($r[count($r)-1],1);
  }
  $this->tpl->viewLinksLangs($l);
 }
 
 private function view_meta(){
  $this->tpl->viewMeta($this->meta);
 }
 
 private function view_navig(){
  $this->tpl->viewNavig($this->navig);
 }
 
 private function layout(){
  $this->tpl->viewError($this->error);
  $this->tpl->layout();
 }
}
?>