Advertisement
Guest User

Simpla Addon

a guest
Jul 18th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?PHP
  2.  
  3. /**
  4.  * Simpla CMS
  5.  *
  6.  * @copyright   2011 Denis Pikusov
  7.  * @link        http://simp.la
  8.  * @author      Denis Pikusov
  9.  *
  10.  * Этот класс использует шаблон index.tpl,
  11.  * который содержит всю страницу кроме центрального блока
  12.  * По get-параметру module мы определяем что сожержится в центральном блоке
  13.  *
  14.  */
  15.  
  16. require_once('View.php');
  17.  
  18. class IndexView extends View
  19. {  
  20.  
  21.     private $themes_dir = 'design/';
  22.     private $compiled_dir = 'compiled/';
  23.  
  24.     public $modules_dir = 'view/';
  25.  
  26.     public function __construct()
  27.     {
  28.         parent::__construct();
  29.     }
  30.  
  31.        
  32.     /**
  33.      *
  34.      * Отображение
  35.      *
  36.      */
  37.     function fetch()
  38.     {
  39.         // Содержимое корзины
  40.         $this->design->assign('cart',       $this->cart->get_cart());
  41.    
  42.         // Категории товаров
  43.         $this->design->assign('categories', $this->categories->get_categories_tree());
  44.        
  45.         // Страницы
  46.         $pages = $this->pages->get_pages(array('visible'=>1));     
  47.         $this->design->assign('pages', $pages);
  48.                            
  49.         // Текущий модуль (для отображения центрального блока)
  50.         $module = $this->request->get('module', 'string');
  51.         $module = preg_replace("/[^A-Za-z0-9]+/", "", $module);
  52.  
  53.         // Если не задан - берем из настроек
  54.         if(empty($module))
  55.             return false;
  56.         //$module = $this->settings->main_module;
  57.  
  58.         // Создаем соответствующий класс
  59.         if (is_file($this->modules_dir."$module.php"))
  60.         {
  61.                 include_once($this->modules_dir."$module.php");
  62.                 if (class_exists($module))
  63.                 {
  64.                     $this->main = new $module($this);
  65.                 } else return false;
  66.         } else return false;
  67.  
  68.        
  69.        
  70.        
  71.         if($this->request->method('post'))
  72.         {
  73.             $this->dir_delete($this->compiled_dir, false);
  74.  
  75.             $action = $this->request->post('action');
  76.             $action_theme  = $this->request->post('theme');
  77.            
  78.             switch($this->request->post('action'))
  79.             {
  80.                 case 'set_main_theme':
  81.                 {
  82.                     $this->settings->theme = $action_theme;      
  83.                     break;
  84.                 }      
  85.             }
  86.         }
  87.    
  88.         $themes = $this->get_themes();
  89.        
  90.         $current_theme->name = $this->settings->theme;
  91.         $this->design->assign('theme', $current_theme);
  92.         $this->design->assign('themes', $themes);
  93.         $this->design->assign('themes_dir', $this->themes_dir);
  94.  
  95.        
  96.        
  97.         // Создаем основной блок страницы
  98.         if (!$content = $this->main->fetch())
  99.         {
  100.             return false;
  101.         }      
  102.  
  103.         // Передаем основной блок в шаблон
  104.         $this->design->assign('content', $content);    
  105.        
  106.         // Передаем название модуля в шаблон, это может пригодиться
  107.         $this->design->assign('module', $module);
  108.                
  109.         // Создаем текущую обертку сайта (обычно index.tpl)
  110.         $wrapper = $this->design->smarty->getTemplateVars('wrapper');
  111.         if(empty($wrapper))
  112.             $wrapper = 'index.tpl';
  113.            
  114.         $this->body = $this->design->fetch($wrapper);
  115.         return $this->body;
  116.     }
  117.    
  118.         private function dir_delete($path, $delete_self = true)
  119.     {
  120.         if(!$dh = @opendir($path))
  121.             return;
  122.         while (false !== ($obj = readdir($dh)))
  123.         {
  124.             if($obj == '.' || $obj == '..')
  125.                 continue;
  126.    
  127.             if (!@unlink($path . '/' . $obj))
  128.                 $this->dir_delete($path.'/'.$obj, true);
  129.         }
  130.         closedir($dh);
  131.         if($delete_self)
  132.             @rmdir($path);
  133.         return;
  134.     }
  135.    
  136.     private function get_themes()
  137.     {
  138.         if($handle = opendir($this->themes_dir)) {
  139.             while(false !== ($file = readdir($handle)))
  140.             {
  141.                 if(is_dir($this->themes_dir.'/'.$file) && $file[0] != '.')
  142.                 {
  143.                     unset($theme);
  144.                     $theme->name = $file;
  145.                     $theme->locked = is_file($this->themes_dir.$file.'/locked');
  146.                     $themes[] = $theme;
  147.                 }
  148.             }
  149.             closedir($handle);
  150.             sort($themes);
  151.         }
  152.         return $themes;
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement