Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('GlobalController.php');
- class IndexController extends GlobalController {
- public $modules_dir = 'controllers/';
- public $ext_modules_dir = 'modules/';
- public function __construct() {
- parent::__construct();
- }
- private function recursive_categories_tree(&$tree, $steps) {
- if ($steps <= 0) return;
- foreach($tree as &$tree_item) {
- $tree_item['subcategories'] = $this->categories->get_categories_lazy_load_filter(array('parent_id'=>$tree_item['id'], 'visible'=>1));
- $this->recursive_categories_tree($tree_item['subcategories'], $steps-1);
- }
- }
- private function check_visible_menu_items(&$items) {
- $result = false;
- if (!$items) return $result;
- foreach($items as $item) {
- $item->show_item = false;
- if ($item->visible && in_array($item->module_name, $this->global_group_permissions)){
- $item->show_item = true;
- $result = true;
- } else if ($item->visible && !empty($item->subitems)) {
- if ($this->check_visible_menu_items($item->subitems)) {
- $item->show_item = true;
- $result = true;
- }
- }
- }
- return $result;
- }
- private function make_url_menu_items(&$items) {
- $result = "";
- if (!$items) return $result;
- foreach($items as $item) {
- $item->active_url = "";
- if (in_array($item->module_name, $this->global_group_permissions)) {
- if (!empty($item->url)) $item->active_url = $item->url;
- else if (!empty($item->sub_url)) $item->active_url = $item->sub_url;
- if (empty($result)) $result = $item->active_url;
- } else if ($item->visible && !empty($item->subitems)) {
- $item->active_url = $this->make_url_menu_items($item->subitems);
- if (empty($result)) $result = $item->active_url;
- }
- if ($item->active_url == "/") $item->active_url = "";
- }
- if ($result == "/") $result = "";
- return $result;
- }
- function fetch() {
- $url = $_SERVER['REQUEST_URI'];
- $test_301_url = trim($url, '/ ');
- if ($this->settings->seo_use_url_old && !empty($test_301_url)) {
- $this->db->query("SELECT url FROM __categories WHERE url_old=?", $test_301_url);
- $tmp_category = $this->db->result();
- if (!empty($tmp_category)) {
- $products_module = $this->furl->get_module_by_name('ProductsController');
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".$this->config->root_url . $products_module->url . $tmp_category->url . $this->settings->postfix_category_url);
- exit();
- }
- $this->db->query("SELECT url FROM __products WHERE url_old=?", $test_301_url);
- $tmp_product = $this->db->result();
- if (!empty($tmp_product)) {
- $product_module = $this->furl->get_module_by_name('ProductController');
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".$this->config->root_url . $product_module->url . $tmp_product->url . $this->settings->postfix_product_url);
- exit();
- }
- $this->db->query("SELECT url FROM __brands WHERE url_old=?", $test_301_url);
- $tmp_brand = $this->db->result();
- if (!empty($tmp_brand)) {
- $brand_module = $this->furl->get_module_by_name('BrandController');
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".$this->config->root_url . $brand_module->url . $tmp_brand->url . $this->settings->postfix_brand_url);
- exit();
- }
- $this->db->query("SELECT url FROM __materials WHERE url_old=?", $test_301_url);
- $tmp_material = $this->db->result();
- if (!empty($tmp_material)) {
- $pages_module = $this->furl->get_module_by_name('PagesController');
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".$this->config->root_url . $pages_module->url . $tmp_material->url . '.html');
- exit();
- }
- }
- $module = $this->furl->get_module($url);
- if ($module === false) return false;
- $url = mb_substr($url, mb_strlen($module->url, 'utf-8'), mb_strlen($url, 'utf-8'), 'utf-8');
- if (array_key_exists('show_success_registration', $_SESSION) && $_SESSION['show_success_registration']) {
- $this->design->assign('show_success_registration', true);
- unset($_SESSION['show_success_registration']);
- }
- if (is_file($this->config->root_dir.$this->modules_dir.$module->branch.'/'.$module->module.".php")) {
- if ($module->branch == 'admin' && !in_array($module->module, $this->global_group_permissions)) {
- if(!$this->request->check_session()) {
- unset($_POST);
- die('Session expired');
- }
- $this->db->query("SELECT * FROM __system_furl WHERE branch=? and module in (?@) ORDER BY url LIMIT 0,1", $module->branch, $this->global_group_permissions);
- $module = $this->db->result();
- if ($module === false || !in_array($module->module, $this->global_group_permissions)) return false;
- if ($module->module == "LoginControllerAdmin" && ($_SERVER['REQUEST_URI'] != $module->url)) header("Location: " . $this->config->root_url . $module->url . $this->design->url_modifier(array('add'=>array('return_url' => base64_encode($this->config->root_url . $_SERVER['REQUEST_URI'])))) );
- }
- include_once($this->modules_dir.$module->branch.'/'.$module->module.".php");
- if (class_exists($module->module)) {
- $this->main = new $module->module($this);
- $this->main->set_params($url, (array)json_decode($module->options));
- } else {
- return $this->page404();
- }
- } else if ($module->is_external) {
- $this->db->query("SELECT * FROM __external_modules WHERE controller=?", $module->module);
- $ext_module = $this->db->result();
- if (!$ext_module || !$ext_module->enabled) return false;
- if (!is_file($this->ext_modules_dir.$ext_module->path.'/controller/'.$ext_module->filename)) return false;
- include_once($this->ext_modules_dir.$ext_module->path.'/controller/'.$ext_module->filename);
- if (class_exists($module->module)) {
- $this->main = new $module->module($this);
- $this->main->set_params($url, (array)json_decode($module->options));
- } else {
- return $this->page404();
- }
- } else {
- return $this->page404();
- }
- $this->design->assign('module', $module);
- if ($module->branch == 'admin') {
- $menu_tree = $this->menu->get_menu_tree(0);
- $this->check_visible_menu_items($menu_tree->subitems);
- $this->make_url_menu_items($menu_tree->subitems);
- $menu_tree_up = $this->menu->get_menu_tree(1);
- if ($module->is_external)
- $active_menu_item = $this->menu->get_selected_menu_item('ModulesControllerAdmin');
- else
- $active_menu_item = $this->menu->get_selected_menu_item($module->module);
- if (!$active_menu_item)
- $active_menu_item = reset($menu_tree->subitems)->id;
- $active_menu = $this->menu->get_item($active_menu_item);
- $this->design->assign('menu_tree', $menu_tree);
- $this->design->assign('menu_tree_up', $menu_tree_up);
- $this->design->assign('active_menu_item', $active_menu_item);
- $this->design->assign('active_menu', $active_menu);
- }
- if ($module->branch == 'frontend') {
- $this->design->assign('main_module', $this->furl->get_module_by_name('MainController'));
- $this->design->assign('brand_module', $this->furl->get_module_by_name('BrandController'));
- $this->design->assign('brand_module_admin', $this->furl->get_module_by_name('BrandControllerAdmin'));
- $this->design->assign('product_module', $this->furl->get_module_by_name('ProductController'));
- $this->design->assign('product_module_admin', $this->furl->get_module_by_name('ProductControllerAdmin'));
- $this->design->assign('category_module_admin', $this->furl->get_module_by_name('CategoryControllerAdmin'));
- $this->design->assign('material_module_admin', $this->furl->get_module_by_name('MaterialControllerAdmin'));
- $this->design->assign('products_module', $this->furl->get_module_by_name('ProductsController'));
- $this->design->assign('pages_module', $this->furl->get_module_by_name('PagesController'));
- $this->design->assign('reviews_module', $this->furl->get_module_by_name('ReviewsController'));
- $this->design->assign('cart_module', $this->furl->get_module_by_name('CartController'));
- $compare_module = $this->furl->get_module_by_name('CompareController');
- $this->design->assign('compare_module', $compare_module);
- $this->design->assign('register_module', $this->furl->get_module_by_name('RegisterController'));
- $this->design->assign('account_module', $this->furl->get_module_by_name('AccountController'));
- $this->design->assign('order_module', $this->furl->get_module_by_name('OrderController'));
- $this->design->assign('login_module', $this->furl->get_module_by_name('LoginController'));
- $this->design->assign('cart', $this->cart->get_cart());
- if (!empty($this->user))
- $this->design->assign('favorites_products_count', $this->products->count_favorites_products($this->user->id));
- $categories_frontend = $this->categories->get_categories_lazy_load_filter(array('parent_id'=>0, 'visible'=>1));
- $this->recursive_categories_tree($categories_frontend, $this->settings->catalog_count_opened_level);
- $this->design->assign('categories_frontend', $categories_frontend);
- $this->design->assign('categories_frontend_all', $this->categories->get_categories_tree());
- $brands_popular = $this->brands->get_brands(array('visible'=>1, 'is_popular'=>1, 'sort'=>'name'));
- $brands_all = $this->brands->get_brands(array('visible'=>1, 'sort'=>'name'));
- foreach($brands_popular as $index=>$brand)
- $brands_popular[$index]->products_count = $this->products->count_products(array('brand_id'=>$brand->id, 'visible'=>1));
- foreach($brands_all as $index=>$brand)
- $brands_all[$index]->products_count = $this->products->count_products(array('brand_id'=>$brand->id, 'visible'=>1));
- $this->design->assign('brands_popular', $brands_popular);
- $this->design->assign('brands_all', $brands_all);
- $sort_methods = array();
- $sort_methods_name = array();
- $sort_methods_biger = array();
- $sort_methods_lower = array();
- $sort_methods_icon_asc = array();
- $sort_methods_icon_desc = array();
- $sort_methods_direction = array();
- if ($this->settings->settings_sort_position) {
- $sort_methods[] = 'position';
- $sort_methods_name[] = 'РџРѕСЂСЏРґРєСѓ';
- $sort_methods_biger[] = '';
- $sort_methods_lower[] = '';
- $sort_methods_icon_asc[] = '';
- $sort_methods_icon_desc[] = '';
- $sort_methods_direction[] = 'asc';
- }
- if ($this->settings->settings_sort_price) {
- $sort_methods[] = 'price';
- $sort_methods_name[] = 'Цене';
- $sort_methods_biger[] = 'Сначала дорогие';
- $sort_methods_lower[] = 'Сначала дешевые';
- $sort_methods_icon_asc[] = 'fa fa-sort-amount-asc';
- $sort_methods_icon_desc[] = 'fa fa-sort-amount-desc';
- $sort_methods_direction[] = 'asc';
- }
- if ($this->settings->settings_sort_popular) {
- $sort_methods[] = 'popular';
- $sort_methods_name[] = 'Популярности';
- $sort_methods_biger[] = 'Сначала не популярные';
- $sort_methods_lower[] = 'Сначала популярные';
- $sort_methods_icon_asc[] = 'fa fa-sort-amount-asc';
- $sort_methods_icon_desc[] = 'fa fa-sort-amount-desc';
- $sort_methods_direction[] = 'asc';
- }
- if ($this->settings->settings_sort_newest) {
- $sort_methods[] = 'newest';
- $sort_methods_name[] = 'РќРѕРІРёР·РЅРµ';
- $sort_methods_biger[] = 'Сначала новые';
- $sort_methods_lower[] = 'Сначала старые';
- $sort_methods_icon_asc[] = 'fa fa-sort-numeric-asc';
- $sort_methods_icon_desc[] = 'fa fa-sort-numeric-desc';
- $sort_methods_direction[] = 'desc';
- }
- if ($this->settings->settings_sort_name) {
- $sort_methods[] = 'name';
- $sort_methods_name[] = 'Алфавиту';
- $sort_methods_biger[] = '';
- $sort_methods_lower[] = '';
- $sort_methods_icon_asc[] = 'fa fa-sort-alpha-asc';
- $sort_methods_icon_desc[] = 'fa fa-sort-alpha-desc';
- $sort_methods_direction[] = 'asc';
- }
- $this->design->assign('sort_methods', $sort_methods);
- $this->design->assign('sort_methods_name', $sort_methods_name);
- $this->design->assign('sort_methods_biger', $sort_methods_biger);
- $this->design->assign('sort_methods_lower', $sort_methods_lower);
- $this->design->assign('sort_methods_icon_asc', $sort_methods_icon_asc);
- $this->design->assign('sort_methods_icon_desc', $sort_methods_icon_desc);
- $this->design->assign('sort_methods_direction', $sort_methods_direction);
- $history_products = array();
- if(!empty($_COOKIE['history_products'])) {
- $history_products_ids = explode(',', $_COOKIE['history_products']);
- $history_products_ids = array_reverse($history_products_ids);
- foreach($history_products_ids as $history_id) {
- $tmp_product = $this->products->get_product($history_id);
- if ($tmp_product && $tmp_product->visible)
- $history_products[] = $tmp_product;
- }
- foreach($history_products as &$history_product) {
- $history_product->images = $this->image->get_images('products', $history_product->id);
- $history_product->image = reset($history_product->images);
- $history_product->variants = $this->variants->get_variants(array('product_id'=>$history_product->id, 'visible'=>1, 'sort'=>'abs(stock)', 'sort_type'=>'desc'));
- $history_product->variant = reset($history_product->variants);
- }
- }
- $this->design->assign('history_products', $history_products);
- $compare_items = $this->compare->get_compare();
- $ids_str = join(",", $compare_items);
- $compare_href = $this->config->root_url . $compare_module->url . (empty($ids_str) ? "" : "?id=".$ids_str);
- $this->design->assign('compare_items', $compare_items);
- $this->design->assign('compare_href', $compare_href);
- $this->design->assign('compare_href_show', !empty($ids_str));
- }
- $new_order_status = $this->orders->get_status('Новые');
- if ($new_order_status) {
- $count_new_orders = $this->orders->count_orders(array('status_id'=>$new_order_status->id, 'moderated'=>0));
- $this->design->assign('count_new_orders', $count_new_orders);
- }
- $count_new_reviews = $this->reviews->count_reviews(array('moderated'=>0));
- $this->design->assign('count_new_reviews', $count_new_reviews);
- $count_shop_new_reviews = $this->reviews->count_shop_reviews(array('moderated'=>0));
- $this->design->assign('count_shop_new_reviews', $count_shop_new_reviews);
- $reviews_filter = array('limit' => 3, 'sort' => 'date', 'sort_type' => 'desc', 'visible' => 1);
- if ($this->settings->reviews_shop_premoderate)
- $reviews_filter['moderated'] = 1;
- $last_shop_reviews = $this->reviews->get_shop_reviews($reviews_filter);
- $this->design->assign('last_shop_reviews', $last_shop_reviews);
- $count_all_shop_reviews_filter = array('visible'=>1);
- if ($this->settings->reviews_shop_premoderate)
- $count_all_shop_reviews_filter['moderated'] = 1;
- $count_all_shop_reviews = $this->reviews->count_shop_reviews($count_all_shop_reviews_filter);
- $this->design->assign('count_all_shop_reviews', $count_all_shop_reviews);
- $callbacks_count = $this->callbacks->count_callbacks(array('moderated'=>0));
- $this->design->assign('count_callbacks', $callbacks_count);
- if (!$content = $this->main->fetch())
- return false;
- $this->design->assign('content', $content);
- $wrapper = $this->design->smarty->getTemplateVars('wrapper');
- if(!isset($wrapper))
- $wrapper = $this->design->getTemplateDir($module->branch).'index.tpl';
- $this->body = $this->design->fetch($wrapper);
- if ($module->branch == 'frontend') {
- $whitelist = array( '127.0.0.1', '::1' );
- if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist) && ((intval(base64_decode($this->settings->last_check_rc)) < 1) || (strval(base64_decode($this->settings->last_check_rh)) != $_SERVER['SERVER_NAME']))) {
- $this->body .= '<div style="background: #c20000; color: #FFF; padding: 12px; position: absolute; top: 0px; text-align: center; width: 100%;"><strong>Ваша лицензия недействительна!</strong> Приобрести лицензию вы можете на сайте <a href="http://minicart.ru" style="color: #FFF; font-weight:500;" target="_blank">minicart.ru</a></div>';
- }
- }
- return $this->body;
- }
- }
Add Comment
Please, Sign In to add comment