Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * Simpla CMS
- *
- * @copyright 2011 Denis Pikusov
- * @link http://simp.la
- * @author Denis Pikusov
- *
- * Этот класс использует шаблон index.tpl,
- * который содержит всю страницу кроме центрального блока
- * По get-параметру module мы определяем что сожержится в центральном блоке
- *
- */
- require_once('View.php');
- class IndexView extends View
- {
- private $themes_dir = 'design/';
- private $compiled_dir = 'compiled/';
- public $modules_dir = 'view/';
- public function __construct()
- {
- parent::__construct();
- }
- /**
- *
- * Отображение
- *
- */
- function fetch()
- {
- // Содержимое корзины
- $this->design->assign('cart', $this->cart->get_cart());
- // Категории товаров
- $this->design->assign('categories', $this->categories->get_categories_tree());
- // Страницы
- $pages = $this->pages->get_pages(array('visible'=>1));
- $this->design->assign('pages', $pages);
- // Текущий модуль (для отображения центрального блока)
- $module = $this->request->get('module', 'string');
- $module = preg_replace("/[^A-Za-z0-9]+/", "", $module);
- // Если не задан - берем из настроек
- if(empty($module))
- return false;
- //$module = $this->settings->main_module;
- // Создаем соответствующий класс
- if (is_file($this->modules_dir."$module.php"))
- {
- include_once($this->modules_dir."$module.php");
- if (class_exists($module))
- {
- $this->main = new $module($this);
- } else return false;
- } else return false;
- if($this->request->method('post'))
- {
- $this->dir_delete($this->compiled_dir, false);
- $action = $this->request->post('action');
- $action_theme = $this->request->post('theme');
- switch($this->request->post('action'))
- {
- case 'set_main_theme':
- {
- $this->settings->theme = $action_theme;
- break;
- }
- }
- }
- $themes = $this->get_themes();
- $current_theme->name = $this->settings->theme;
- $this->design->assign('theme', $current_theme);
- $this->design->assign('themes', $themes);
- $this->design->assign('themes_dir', $this->themes_dir);
- // Создаем основной блок страницы
- if (!$content = $this->main->fetch())
- {
- return false;
- }
- // Передаем основной блок в шаблон
- $this->design->assign('content', $content);
- // Передаем название модуля в шаблон, это может пригодиться
- $this->design->assign('module', $module);
- // Создаем текущую обертку сайта (обычно index.tpl)
- $wrapper = $this->design->smarty->getTemplateVars('wrapper');
- if(empty($wrapper))
- $wrapper = 'index.tpl';
- $this->body = $this->design->fetch($wrapper);
- return $this->body;
- }
- private function dir_delete($path, $delete_self = true)
- {
- if(!$dh = @opendir($path))
- return;
- while (false !== ($obj = readdir($dh)))
- {
- if($obj == '.' || $obj == '..')
- continue;
- if (!@unlink($path . '/' . $obj))
- $this->dir_delete($path.'/'.$obj, true);
- }
- closedir($dh);
- if($delete_self)
- @rmdir($path);
- return;
- }
- private function get_themes()
- {
- if($handle = opendir($this->themes_dir)) {
- while(false !== ($file = readdir($handle)))
- {
- if(is_dir($this->themes_dir.'/'.$file) && $file[0] != '.')
- {
- unset($theme);
- $theme->name = $file;
- $theme->locked = is_file($this->themes_dir.$file.'/locked');
- $themes[] = $theme;
- }
- }
- closedir($handle);
- sort($themes);
- }
- return $themes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement