public function __construct() { parent::__construct(); // Если инстанс класса уже существует - просто используем уже существующие переменные if (self::$view_instance) { $this->currency =& self::$view_instance->currency; $this->currencies =& self::$view_instance->currencies; $this->user =& self::$view_instance->user; $this->group =& self::$view_instance->group; $this->page =& self::$view_instance->page; } else { // Сохраняем свой инстанс в статической переменной, // чтобы в следующий раз использовать его self::$view_instance = $this; // Все валюты $this->currencies = $this->money->get_currencies(array('enabled' => 1)); // Выбор текущей валюты if ($currency_id = $this->request->get('currency_id', 'integer')) { $_SESSION['currency_id'] = $currency_id; header("Location: " . $this->request->url(array('currency_id' => null))); } // Берем валюту из сессии if (isset($_SESSION['currency_id'])) { $this->currency = $this->money->get_currency($_SESSION['currency_id']); } else { $this->currency = reset($this->currencies); } // Пользователь, если залогинен if (isset($_SESSION['user_id'])) { $u = $this->users->get_user(intval($_SESSION['user_id'])); if ($u && $u->enabled) { $this->user = $u; $this->group = $this->users->get_group($this->user->group_id); } } // Текущая страница (если есть) $subdir = substr(dirname(dirname(__FILE__)), strlen($_SERVER['DOCUMENT_ROOT'])); $page_url = trim(substr($_SERVER['REQUEST_URI'], strlen($subdir)), "/"); if (strpos($page_url, '?') !== false) { $page_url = substr($page_url, 0, strpos($page_url, '?')); } $this->page = $this->pages->get_page((string) $page_url); $this->design->assign('page', $this->page); // Передаем в дизайн то, что может понадобиться в нем $this->design->assign('currencies', $this->currencies); $this->design->assign('currency', $this->currency); $this->design->assign('user', $this->user); $this->design->assign('group', $this->group); $this->design->assign('config', $this->config); $this->design->assign('settings', $this->settings); // Настраиваем плагины для смарти $this->design->smarty->registerPlugin("function", "get_posts", array($this, 'get_posts_plugin')); $this->design->smarty->registerPlugin("function", "get_brands", array($this, 'get_brands_plugin')); $this->design->smarty->registerPlugin("function", "get_browsed_products", array($this, 'get_browsed_products')); $this->design->smarty->registerPlugin("function", "get_featured_products", array($this, 'get_featured_products_plugin')); $this->design->smarty->registerPlugin("function", "get_new_products", array($this, 'get_new_products_plugin')); $this->design->smarty->registerPlugin("function", "get_discounted_products", array($this, 'get_discounted_products_plugin')); } }
public function __construct() { parent::__construct(); if (!defined('IS_CLIENT')) { define('IS_CLIENT', true); } // Если инстанс класса уже существует - просто используем уже существующие переменные if (self::$view_instance) { $this->currency =& self::$view_instance->currency; $this->currencies =& self::$view_instance->currencies; $this->user =& self::$view_instance->user; $this->group =& self::$view_instance->group; $this->page =& self::$view_instance->page; $this->language =& self::$view_instance->language; $this->lang_link =& self::$view_instance->lang_link; } else { // Сохраняем свой инстанс в статической переменной, // чтобы в следующий раз использовать его self::$view_instance = $this; // Язык $languages = $this->languages->languages(); $lang_link = ''; if (!empty($languages)) { if ($_GET['lang_label']) { $this->language = $this->languages->languages(array('id' => $this->languages->lang_id())); if (!is_object($this->language)) { $_GET['page_url'] = '404'; $_GET['module'] = 'PageView'; } $lang_link = $this->language->label . '/'; } else { $this->language = reset($languages); $this->languages->set_lang_id($this->language->id); } $first_lang = reset($languages); $ruri = $_SERVER['REQUEST_URI']; if (strlen($this->config->subfolder) > 1) { $pos = strpos($_SERVER['REQUEST_URI'], $this->config->subfolder); if ($pos === 1 || $pos === 0) { $sf = $this->config->subfolder; $ruri = preg_replace("~{$sf}~", '', $ruri); } } $ruri = explode('/', $ruri); $as = $first_lang->id !== $this->languages->lang_id() ? 2 : 1; if (is_array($ruri) && $first_lang->id == $this->languages->lang_id() && $ruri[1] == $first_lang->label) { header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $this->config->root_url . '/' . implode('/', array_slice($ruri, 2))); exit; } foreach ($languages as $l) { // основному языку не нужна метка if ($first_lang->id !== $l->id) { $l->url = $l->label . ($ruri ? '/' . implode('/', array_slice($ruri, $as)) : ''); } else { $l->url = $ruri ? implode('/', array_slice($ruri, $as)) : ''; } } } $this->design->assign('lang_link', $lang_link); $this->lang_link = $lang_link; // Все валюты $this->currencies = $this->money->get_currencies(array('enabled' => 1)); // Выбор текущей валюты if ($currency_id = $this->request->get('currency_id', 'integer')) { $_SESSION['currency_id'] = $currency_id; header("Location: " . $this->request->url(array('currency_id' => null))); } // Берем валюту из сессии if (isset($_SESSION['currency_id'])) { $this->currency = $this->money->get_currency($_SESSION['currency_id']); } else { $this->currency = reset($this->currencies); } // Пользователь, если залогинен if (isset($_SESSION['user_id'])) { $u = $this->users->get_user(intval($_SESSION['user_id'])); if ($u && $u->enabled) { $this->user = $u; $this->group = $this->users->get_group($this->user->group_id); } } // Текущая страница (если есть) $subdir = substr(dirname(dirname(__FILE__)), strlen($_SERVER['DOCUMENT_ROOT'])); $page_url = trim(substr($_SERVER['REQUEST_URI'], strlen($subdir)), "/"); if (strpos($page_url, '?') !== false) { $page_url = substr($page_url, 0, strpos($page_url, '?')); } if (!empty($languages) && !empty($first_lang)) { $strlen = $first_lang->id == $this->language->id ? "" : $first_lang->label; $page_url = trim(substr($page_url, strlen($strlen)), "/"); } if (in_array($_GET['page_url'], array('all-products', 'discounted', 'bestsellers'))) { $page_url = $_GET['page_url']; } $this->design->assign('language', $this->language); $this->design->assign('languages', $languages); $this->design->assign('lang', $this->translations); $this->design->assign('translate_id', $this->translations->get_labels_ids()); $this->page = $this->pages->get_page((string) $page_url); $this->design->assign('page', $this->page); // Передаем в дизайн то, что может понадобиться в нем $this->design->assign('currencies', $this->currencies); $this->design->assign('currency', $this->currency); $this->design->assign('user', $this->user); $this->design->assign('group', $this->group); $this->design->assign('config', $this->config); $this->design->assign('settings', $this->settings); // Настраиваем плагины для смарти $this->design->smarty->registerPlugin('modifier', 'printa', array($this, 'printa')); $this->design->smarty->registerPlugin("function", "get_posts", array($this, 'get_posts_plugin')); $this->design->smarty->registerPlugin("function", "get_brands", array($this, 'get_brands_plugin')); $this->design->smarty->registerPlugin("function", "get_browsed_products", array($this, 'get_browsed_products')); $this->design->smarty->registerPlugin("function", "get_featured_products", array($this, 'get_featured_products_plugin')); $this->design->smarty->registerPlugin("function", "get_new_products", array($this, 'get_new_products_plugin')); $this->design->smarty->registerPlugin("function", "get_discounted_products", array($this, 'get_discounted_products_plugin')); $this->design->smarty->registerPlugin("function", "get_categories", array($this, 'get_categories_plugin')); $this->design->smarty->registerPlugin("function", "get_banner", array($this, 'get_banner_plugin')); } }