Beispiel #1
0
 public function set_metatags_and_content($url, $name = 'page', $items_on_page = null)
 {
     $name = mb_strtolower($name);
     $name = ucfirst($name);
     $model = ORM::factory($name)->get_page_by_url($url);
     if (!$model->loaded() || isset($model->md5_url) && $model->md5_url != md5($url)) {
         $this->forward_404();
     }
     $this->_items_on_page = $items_on_page;
     $this->_model = $model;
     $this->template->model = $model;
     $this->_object_name = str_replace('Model_', '', get_class($this->_model));
     $list_columns = $this->_model->list_columns();
     foreach ($list_columns as $column => $params) {
         $this->template->{$column} = $this->_model->{$column};
         switch ($column) {
             case 's_title':
                 $this->template->s_title = $this->set_title();
                 break;
         }
     }
     foreach ($this->_model->has_many() as $column => $params) {
         if ($this->_items_on_page && $column != 'children' && $column != 'filters') {
             $pagination_items = $this->get_pagination_items($column, $params);
             $this->template->{$column} = $pagination_items['items'];
             if ($pagination_items['pagination']) {
                 $this->template->pagination = $pagination_items['pagination'];
             }
         } else {
             if ($column != 'filters') {
                 $this->template->{$column} = $this->_model->{$column}->where('active', '=', 1)->find_all();
             }
         }
     }
     foreach ($this->_model->belongs_to() as $column => $params) {
         if ($params['model'] == 'Brand' || $params['model'] == 'Category') {
             continue;
         }
         $model = ORM::factory($params['model'])->fetchByUrl($this->param($column));
         if ($model->id != $this->_model->{$params['foreign_key']} && $column != 'parent' && $column != 'parent') {
             $this->forward_404();
         }
         foreach ($model->list_columns() as $model_column => $model_params) {
             $this->template->{$column . '_' . $model_column} = $model->{$model_column};
         }
     }
     if (isset($list_columns['more_images'])) {
         $this->template->content = $this->replace_images();
     }
     $device = new Device();
     $this->template->is_mobile = $device->is_mobile();
 }
        }
    }
    if (!empty($_USER['theme'])) {
        if (is_dir($_CONF['path_themes'] . $_USER['theme'])) {
            $_CONF['theme'] = $_USER['theme'];
            $_CONF['path_layout'] = $_CONF['path_themes'] . $_CONF['theme'] . '/';
            $_CONF['layout_url'] = $_CONF['site_url'] . '/layout/' . $_CONF['theme'];
        } else {
            $_USER['theme'] = $_CONF['theme'];
        }
    }
}
// Set template class default template variables option
$TEMPLATE_OPTIONS['default_vars']['layout_url'] = $_CONF['layout_url'];
$TEMPLATE_OPTIONS['default_vars']['anonymous_user'] = COM_isAnonUser();
$TEMPLATE_OPTIONS['default_vars']['device_mobile'] = $_DEVICE->is_mobile();
/**
 * This provides the ability to set css and javascript.
 *
 * @global $_SCRIPTS Scripts
 */
$_SCRIPTS = new Scripts();
// Include theme functions file which may/may not do anything
if (file_exists($_CONF['path_layout'] . 'functions.php')) {
    require_once $_CONF['path_layout'] . 'functions.php';
}
// Get the configuration values from the theme
$_CONF['theme_default'] = '';
// Default is none
$_CONF['path_layout_default'] = '';
// Default is none
Beispiel #3
0
 public function action_index()
 {
     $page_view = Cookie::get('page_view');
     if (!$page_view) {
         $page_view = 'grid';
     }
     if ($_GET['page_view'] == 'list') {
         $page_view = "list";
         Cookie::set('page_view', 'list', time() + 86400);
     } elseif ($_GET['page_view'] == 'grid') {
         Cookie::set('page_view', 'grid', time() + 86400);
         $page_view = "grid";
     }
     $this->template->page_view = $page_view;
     $page = intval($this->param('page'));
     $brands = Arr::get($_GET, 'brands', array());
     $lines = Arr::get($_GET, 'line');
     $category = ORM::factory('Category')->where('url', '=', $this->param('category'))->find();
     if (!$category->id) {
         $this->forward_404();
     }
     $PDO = ORM::factory('Product')->PDO();
     if ($lines) {
         $url = $_SERVER['REQUEST_URI'];
         $linesArray = $PDO->query("\n\t\t\t\tSELECT l.id, pr.brand_id FROM line l\n\t\t\t\tLEFT JOIN product pr ON pr.line_id = l.id\n\t\t\t\tWHERE l.id IN ('" . join("', '", array_keys($lines)) . "')")->fetchAll(PDO::FETCH_ASSOC);
         $emptyLines = array();
         foreach ($linesArray as $linerow) {
             if (!in_array($linerow['brand_id'], $brands)) {
                 $emptyLines[] = $linerow['id'];
                 $url = str_replace('&line%5B' . $linerow['id'] . '%5D=1', '', $url);
             }
         }
         if ($emptyLines) {
             $this->redirect($url);
         }
     }
     $line_query = "SELECT line.url, line.name, line.id, product.brand_id, count(*) FROM line\n                        LEFT JOIN product ON product.line_id = line.id\n                        WHERE product.category_id = {$category->id}\n                        AND product.active = 1";
     if ($brands) {
         $brandsList = join('", "', $brands);
         $line_query .= ' AND product.brand_id IN ("' . $brandsList . '")';
     } else {
         $line_query .= " AND product.brand_id = 'none'";
     }
     $line_query .= " GROUP BY line.id\n\t\t\t\t\t\tHAVING COUNT(*) > 1\n                        ORDER BY line.name ASC";
     $brands_query = "SELECT brand.url, brand.name, brand.id, count(*) FROM brand\n                            LEFT JOIN product ON product.brand_id = brand.id\n                            WHERE product.category_id = {$category->id}\n                            AND product.active = 1\n                            GROUP BY brand.id\n\t\t\t\t\t\t\tHAVING count(*) > 1\n                            ORDER BY brand.position ASC, brand.name ASC";
     $property = "SELECT properties.id, properties.name FROM product\n                        LEFT JOIN product_properties ON product_properties.product_id = product.id\n                        LEFT JOIN properties ON properties.id = product_properties.property_id\n                        WHERE product.category_id = {$category->id}\n                        AND product.active = 1\n                        GROUP BY properties.id\n                        ORDER BY properties.name ASC";
     $this->template->brand = $PDO->query($brands_query)->fetchAll(PDO::FETCH_ASSOC);
     $this->template->line = $PDO->query($line_query)->fetchAll(PDO::FETCH_ASSOC);
     $this->template->property = $PDO->query($property)->fetchAll(PDO::FETCH_ASSOC);
     $querymaxprice = "SELECT MAX(price) as max, MIN(price) as min FROM product\n\t\t\t\t\tWHERE product.category_id = {$category->id}";
     $maxprice = ORM::factory('Product')->PDO()->query($querymaxprice . " AND product.active = 1 AND product.price > 0")->fetch();
     $max_price = $maxprice['max'];
     $min_price = $maxprice['min'];
     $current_min_price = $min_price;
     $current_max_price = $max_price;
     if (isset($_GET['price']) && preg_match('%,%', $_GET['price'])) {
         list($current_min_price, $current_max_price) = explode(',', $_GET['price']);
     }
     $this->template->max_price = $max_price;
     $this->template->min_price = $min_price;
     $current_url = Arr::get($_SERVER, 'REQUEST_URI');
     $this->template->category = $category;
     $this->template->set_layout('layout/site/global');
     $filters = ORM::factory('Filter')->query('select p.id as property_id, f.property_type, p.name, p.type from filters f' . ' left join properties p on f.property_id = p.id' . ' left join product_properties pp on pp.property_id = p.id' . ' where f.category_id = ' . $category->id . ' group by pp.property_id having count(*) > 1', true, true);
     $filters = Arr::get($filters, 'items', array());
     $property_ids = array();
     $filters_hash = array();
     foreach ($filters as $filter) {
         if ($filter['type'] == 'D') {
             $property_ids[] = $filter['property_id'];
         }
         $filters_hash[$filter['property_id']] = $filter;
     }
     $property_ids = array_unique($property_ids);
     $this->template->filters = $filters;
     $get_filters = Arr::get($_GET, 'filter');
     $query = 'SELECT SQL_CALC_FOUND_ROWS pr.id, pr.name as name, pr.url as url, pr.id as id' . ' , pr.price, pr.main_image, pr.short_content, pr.new_price, pr.article, sum(rw.rating) as reviews,  count(1) as cnt' . ' FROM product pr' . ' LEFT JOIN reviews rw ON rw.prod_id = pr.id';
     if ($get_filters) {
         $query .= ' LEFT JOIN product_properties pp ON pr.id = pp.product_id' . ' LEFT JOIN properties p ON p.id = pp.property_id';
     }
     if ($brands) {
         $query .= ' LEFT JOIN brand br ON br.id = pr.brand_id';
     }
     $query .= ' WHERE pr.parent_product = 0 AND pr.active=1 AND pr.category_id=' . $category->id . ' AND pr.price > 0';
     if ($brands) {
         $brandsList = join('", "', $brands);
         $query .= ' AND br.id IN ("' . $brandsList . '")';
     }
     if ($lines) {
         $linesList = join('", "', array_keys($lines));
         $query .= ' AND pr.line_id IN ("' . $linesList . '")';
     }
     if ($current_max_price && $current_min_price) {
         $query .= ' AND pr.price >= ' . $current_min_price . ' AND pr.price <= ' . $current_max_price;
     }
     $this->template->current_max_price = $current_max_price;
     $this->template->current_min_price = $current_min_price;
     $properties_count = 0;
     $bool_query = '';
     $integer_query = '';
     $select_query = '';
     $bool_count = 0;
     $integer_count = 0;
     foreach ($get_filters as $filter_id => $filter_value) {
         if ($filters_hash[$filter_id]['type'] == 'B' && $filter_value) {
             if (!$bool_count) {
                 $bool_query .= '(';
             }
             if ($bool_count) {
                 $bool_query .= ' OR ';
             }
             $bool_query .= 'pp.property_id=' . $filter_id . ' AND pp.value=1';
             $bool_count++;
             $properties_count++;
         }
     }
     if ($properties_count) {
         $query .= ' AND (';
     }
     if ($bool_count) {
         $bool_query .= ')';
     }
     $query .= $bool_query;
     if ($integer_query) {
         if ($bool_count) {
             $query .= ' OR ';
         }
         $query .= $integer_query;
     }
     if ($select_query) {
         if ($bool_count || $integer_count) {
             $query .= ' OR ';
         }
         $query .= $select_query;
     }
     if ($properties_count) {
         $query .= ')';
     }
     if ($page == 1) {
         $url = str_replace('/' . $page, '', $this->request->url());
         $this->redirect($url, 301);
     }
     if (is_null($this->param('page'))) {
         $page = 1;
     }
     $order = Arr::get($_GET, 'order');
     $dest = Arr::get($_GET, 'dest');
     $order_by_str = '';
     if ($order && $dest && in_array($dest, array('asc', 'desc', 'ASC', 'DESC')) && array_key_exists($order, ORM::factory('Product')->as_array())) {
         $order_by_str = ' ORDER BY ' . 'pr.' . $order . ' ' . $dest;
     }
     $offset = $this->_items_on_page * $page - $this->_items_on_page;
     $query .= ' GROUP BY pr.id HAVING cnt >=' . $properties_count . $order_by_str;
     $query .= ' LIMIT ' . $offset . ',' . $this->_items_on_page;
     $items = ORM::factory('Product')->query($query);
     if ($this->request->is_ajax()) {
         exit(json_encode(array('count' => $items['total_items'])));
     }
     $max_pages = intval(ceil($items['total_items'] / $this->_items_on_page));
     if (!$max_pages) {
         $max_pages = 1;
     }
     if ($page < 1 || $page > $max_pages) {
         $this->forward_404();
     }
     $img_width = 320;
     $img_height = 150;
     $mobile = '';
     $device = new Device();
     if ($device->is_mobile()) {
         $img_width = 700;
         $img_height = 300;
         $mobile = 'mobile';
     }
     $this->template->mobile = $mobile;
     $this->template->img_height = $img_height;
     $this->template->img_width = $img_width;
     $this->template->pagination = Pagination::factory(array('current_page' => array('source' => 'route', 'key' => 'page'), 'total_items' => $items['total_items'], 'items_per_page' => $this->_items_on_page, 'view' => 'site/pagination/pagination'))->render();
     $this->template->product = $items['items'];
     $this->template->s_description = $category->s_description;
     $this->template->s_title = $category->name . ' - купить ' . $category->name . ' в Минске в интернет магазине cosm.by: лучшие цены, большой каталог, отзывы';
 }
Beispiel #4
0
    switch ($_CONF['doctype']) {
        case 'xhtml10transitional':
        case 'xhtml10strict':
        case 'xhtml5':
            define('XHTML', ' /');
            break;
        default:
            define('XHTML', '');
            break;
    }
}
// Set template class default template variables option
/**
 * @global $TEMPLATE_OPTIONS array
 */
$TEMPLATE_OPTIONS = array('path_cache' => $_CONF['path_data'] . 'layout_cache/', 'path_prefixes' => array($_CONF['path_themes'], $_CONF['path'], '/'), 'incl_phpself_header' => true, 'cache_by_language' => true, 'cache_for_mobile' => $_CONF['cache_mobile'], 'default_vars' => array('xhtml' => XHTML, 'site_url' => $_CONF['site_url'], 'site_admin_url' => $_CONF['site_admin_url'], 'layout_url' => $_CONF['layout_url'], 'anonymous_user' => COM_isAnonUser(), 'device_mobile' => $_DEVICE->is_mobile()), 'hook' => array('set_root' => 'CTL_setTemplateRoot'));
\Geeklog\Autoload::load('template');
// Template library contains helper functions for template class
require_once $_CONF['path_system'] . 'lib-template.php';
// Set language
if (isset($_COOKIE[$_CONF['cookie_language']]) && empty($_USER['language'])) {
    $language = COM_sanitizeFilename($_COOKIE[$_CONF['cookie_language']]);
    if (is_file($_CONF['path_language'] . $language . '.php') && $_CONF['allow_user_language'] == 1) {
        $_USER['language'] = $language;
        $_CONF['language'] = $language;
    }
} elseif (!empty($_USER['language'])) {
    if (is_file($_CONF['path_language'] . $_USER['language'] . '.php') && $_CONF['allow_user_language'] == 1) {
        $_CONF['language'] = $_USER['language'];
    }
} elseif (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) {