657 lines
26 KiB
PHP
657 lines
26 KiB
PHP
|
|
<?PHP
|
|||
|
|
|
|||
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/modal-form/cp.php';
|
|||
|
|
|
|||
|
|
|
|||
|
|
function changeIframe($m){
|
|||
|
|
$x = '<iframe width="100%" style="border:0;margin-bottom:15px;" ' . $m[2] . '</iframe>';
|
|||
|
|
return str_replace('frameborder="0"', '', $x);
|
|||
|
|
}
|
|||
|
|
/**
|
|||
|
|
* Simpla CMS
|
|||
|
|
*
|
|||
|
|
* @copyright 2011 Denis Pikusov
|
|||
|
|
* @link http://simplacms.ru
|
|||
|
|
* @author Denis Pikusov
|
|||
|
|
*
|
|||
|
|
* Этот класс использует шаблон products.tpl
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
require_once('View.php');
|
|||
|
|
|
|||
|
|
class ArticlesView extends View
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
*
|
|||
|
|
* Отображение списка товаров
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
public $servicesTree = array();
|
|||
|
|
|
|||
|
|
function fetch()
|
|||
|
|
{
|
|||
|
|
$url = $this->request->get('url', 'string');
|
|||
|
|
|
|||
|
|
|
|||
|
|
if($this->request->get('filter')) $this->design->assign('service_filter', $this->request->get('filter'));
|
|||
|
|
|
|||
|
|
if(empty($url)) return $this->fetch_articles();
|
|||
|
|
|
|||
|
|
$res = $this->checkMarkaModel();
|
|||
|
|
if($res) return $res;
|
|||
|
|
|
|||
|
|
|
|||
|
|
$article = $this->articles->get_article($url);
|
|||
|
|
|
|||
|
|
if(!$article) return $this->fetch_articles();
|
|||
|
|
|
|||
|
|
if($article && (!$article->visible && empty($_SESSION['admin']))) return false;
|
|||
|
|
|
|||
|
|
return $this->fetch_article($url);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function checkMarkaModel(){
|
|||
|
|
$url = $this->request->get('url', 'string');
|
|||
|
|
$model = $this->request->get('model', 'string');
|
|||
|
|
|
|||
|
|
if(!$url && !$model) return;
|
|||
|
|
|
|||
|
|
if(!$marka = $this->marka->get_brand($url)) return;
|
|||
|
|
|
|||
|
|
if(!$model) return $this->fetch_marka($marka);
|
|||
|
|
|
|||
|
|
|
|||
|
|
$model = $this->model->get_model($model);
|
|||
|
|
|
|||
|
|
if($model) return $this->fetch_model($model);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function fetch_model($model){ //print_r($model);die;
|
|||
|
|
|
|||
|
|
$res = $this->db->query("SELECT * FROM __article_models WHERE model_id=" . $model->id);
|
|||
|
|
$rows = $this->db->results();
|
|||
|
|
if(!$rows) return;
|
|||
|
|
|
|||
|
|
$articleIds = array();
|
|||
|
|
foreach($rows as $row) $articleIds[$row->article_id] = $row->article_id;
|
|||
|
|
|
|||
|
|
$filter = array('id' => $articleIds);
|
|||
|
|
|
|||
|
|
$this->design->assign('services', $this->getServices($filter));
|
|||
|
|
$filter = $this->sortByService($filter);
|
|||
|
|
|
|||
|
|
$articles = $this->articles->get_articles($filter);
|
|||
|
|
|
|||
|
|
$this->design->assign('articles', $articles);
|
|||
|
|
|
|||
|
|
$filterService = $this->getFilterService();
|
|||
|
|
|
|||
|
|
$h1 = 'Наши проекты с ' . $model->marka->name .' '.$model->name;
|
|||
|
|
|
|||
|
|
|
|||
|
|
if(!$filterService){
|
|||
|
|
if(!$model->meta_title) $model->meta_title = 'Тюнинг ' . $model->marka->name . ' ' . $model->name . ' в Санкт-Петербурге - Atomic Garage';
|
|||
|
|
if(!$model->meta_description) $model->meta_description = 'Тюнинг ' . $model->marka->name . ' ' . $model->name . ' в Санкт-Петербурге - примеры работ центра Atomic Garage: тюнинг, ремонт, установка автомобильной оптики, восстановление и улучшение качества света, комплексное обслуживание автомобиля.';
|
|||
|
|
if(!$model->meta_keywords) $model->meta_keywords = $model->marka->name . ', ' . $model->name . ', тюнинг, центр, санкт-петербург, авто, автомобиль, фары, оптика, линзы, примеры работ, проекты, установка, замена, ремонт';
|
|||
|
|
|
|||
|
|
}else{
|
|||
|
|
$model->meta_title = $filterService->name .' ' . $model->marka->name . ' ' . $model->name . ' в Санкт-Петербурге';
|
|||
|
|
$model->meta_description = $filterService->name . ' ' . $model->marka->name . ' ' . $model->name . ' в Санкт-Петербурге - примеры работ центра Atomic Garage: тюнинг и ремонт фар любой сложности, восстановление и улучшение качества света, комплексное обслуживание автомобиля.';
|
|||
|
|
$model->meta_keywords = 'наши работы, проекты, ' . $filterService->name .', ' . $model->marka->name . ', ' . $model->name . ', тюнинг центр, авто, автомобиль, санкт-петербург, установка, замена, ремонт';
|
|||
|
|
$h1 = 'Наши проекты с ' . $model->marka->name . ' ' .$model->name . ' - ' . $filterService->name;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$this->design->assign('meta_title', $model->meta_title);
|
|||
|
|
$this->design->assign('meta_keywords', $model->meta_keywords);
|
|||
|
|
$this->design->assign('meta_description', $model->meta_description);
|
|||
|
|
|
|||
|
|
$this->design->assign('model', $model);
|
|||
|
|
$this->design->assign('h1', $h1);
|
|||
|
|
|
|||
|
|
return $this->design->fetch('model.tpl');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function fetch_marka($marka){
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$res = $this->db->query("SELECT * FROM __article_models WHERE marka_id=" . $marka->id);
|
|||
|
|
$rows = $this->db->results();
|
|||
|
|
if(!$rows) return;
|
|||
|
|
|
|||
|
|
$modelIds = $articleIds = array();
|
|||
|
|
foreach($rows as $row){
|
|||
|
|
if($row->model_id) $modelIds[$row->model_id] = $row->model_id;
|
|||
|
|
$articleIds[$row->article_id] = $row->article_id;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if($modelIds){
|
|||
|
|
$this->db->query("SELECT * FROM __model WHERE visible=1 AND id IN(".implode(',', $modelIds).")");
|
|||
|
|
$models = $this->db->results();
|
|||
|
|
$this->design->assign('models', $models);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$filter = array('id' => $articleIds);
|
|||
|
|
|
|||
|
|
$this->design->assign('services', $this->getServices($filter));
|
|||
|
|
$filter = $this->sortByService($filter);
|
|||
|
|
|
|||
|
|
$articles = $this->articles->get_articles($filter);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$this->design->assign('articles', $articles);
|
|||
|
|
|
|||
|
|
$filterService = $this->getFilterService();
|
|||
|
|
|
|||
|
|
$h1 = 'Наши проекты с ' . $marka->name;
|
|||
|
|
|
|||
|
|
|
|||
|
|
if(!$filterService){
|
|||
|
|
if(!$marka->meta_title) $marka->meta_title = 'Тюнинг ' . $marka->name . ' в Санкт-Петербурге - Atomic Garage';
|
|||
|
|
if(!$marka->meta_description) $marka->meta_description = 'Тюнинг ' . $marka->name . ' в Санкт-Петербурге - примеры работ центра Atomic Garage: тюнинг, ремонт, установка автомобильной оптики, восстановление и улучшение качества света, комплексное обслуживание автомобиля.';
|
|||
|
|
if(!$marka->meta_keywords) $marka->meta_keywords = $marka->name . ', тюнинг, центр, санкт-петербург, авто, автомобиль, фары, оптика, линзы, примеры работ, проекты, установка, замена, ремонт';
|
|||
|
|
}else{
|
|||
|
|
$marka->meta_title = 'Примеры работ: ' .$filterService->name .' ' . $marka->name . ' в Санкт-Петербурге';
|
|||
|
|
$marka->meta_description = $filterService->name . ' ' . $marka->name . ' в Санкт-Петербурге - примеры работ центра Atomic Garage: тюнинг и ремонт фар любой сложности, восстановление и улучшение качества света, комплексное обслуживание автомобиля.';
|
|||
|
|
$marka->meta_keywords = 'наши работы, проекты, ' . $filterService->name .', ' . $marka->name . ', тюнинг центр, авто, автомобиль, санкт-петербург, установка, замена, ремонт';
|
|||
|
|
$h1 = 'Наши проекты с ' . $marka->name . ' - ' . $filterService->name;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$this->design->assign('meta_title', $marka->meta_title);
|
|||
|
|
$this->design->assign('meta_keywords', $marka->meta_keywords);
|
|||
|
|
$this->design->assign('meta_description', $marka->meta_description);
|
|||
|
|
|
|||
|
|
$this->design->assign('marka', $marka);
|
|||
|
|
|
|||
|
|
$this->design->assign('h1', $h1);
|
|||
|
|
|
|||
|
|
return $this->design->fetch('marka.tpl');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
function fetch_article($url)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// Выбираем пост из базы
|
|||
|
|
$article = $this->articles->get_article($url);
|
|||
|
|
$article->visited++;
|
|||
|
|
$update_visited->visited = $article->visited;
|
|||
|
|
$this->articles->update_article($article->id, $update_visited);
|
|||
|
|
|
|||
|
|
// Если не найден - ошибка
|
|||
|
|
if(!$article || (!$article->visible && empty($_SESSION['admin']))) return false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Автозаполнение имени для формы комментария
|
|||
|
|
if(!empty($this->user))
|
|||
|
|
$this->design->assign('comment_name', $this->user->name);
|
|||
|
|
|
|||
|
|
// Принимаем комментарий
|
|||
|
|
if ($this->request->method('post') && $this->request->post('comment'))
|
|||
|
|
{
|
|||
|
|
$comment->name = $this->request->post('name');
|
|||
|
|
$comment->text = $this->request->post('text');
|
|||
|
|
|
|||
|
|
// Передадим комментарий обратно в шаблон - при ошибке нужно будет заполнить форму
|
|||
|
|
$this->design->assign('comment_text', $comment->text);
|
|||
|
|
$this->design->assign('comment_name', $comment->name);
|
|||
|
|
|
|||
|
|
$cp = new ReCaptcha('6LegdywdAAAAAJaQLxIlHnITncRtuHQu-HHxeAYG');
|
|||
|
|
$cpResult = $cp->verifyResponse($_SERVER['REMOTE_ADDR'], $this->request->post('recaptcha_response'));
|
|||
|
|
if (!$cpResult->success) {
|
|||
|
|
$this->design->assign('error', 'captcha');
|
|||
|
|
}
|
|||
|
|
elseif (empty($comment->name))
|
|||
|
|
{
|
|||
|
|
$this->design->assign('error', 'empty_name');
|
|||
|
|
}
|
|||
|
|
elseif (empty($comment->text))
|
|||
|
|
{
|
|||
|
|
$this->design->assign('error', 'empty_comment');
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// Создаем комментарий
|
|||
|
|
$comment->object_id = $article->id;
|
|||
|
|
$comment->type = 'article';
|
|||
|
|
$comment->ip = $_SERVER['REMOTE_ADDR'];
|
|||
|
|
|
|||
|
|
// Если были одобренные комментарии от текущего ip, одобряем сразу
|
|||
|
|
$this->db->query("SELECT 1 FROM __comments WHERE approved=1 AND ip=? LIMIT 1", $comment->ip);
|
|||
|
|
if($this->db->num_rows()>0)
|
|||
|
|
$comment->approved = 1;
|
|||
|
|
|
|||
|
|
// Добавляем комментарий в базу
|
|||
|
|
if($this->request->post('email') == '')
|
|||
|
|
$comment_id = $this->comments->add_comment($comment);
|
|||
|
|
|
|||
|
|
// Отправляем email
|
|||
|
|
$this->notify->email_comment_admin($comment_id);
|
|||
|
|
|
|||
|
|
header('location: '.$_SERVER['REQUEST_URI'].'#comment_'.$comment_id);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Комментарии к посту
|
|||
|
|
$comments = $this->comments->get_comments(array('type'=>'article', 'object_id'=>$article->id, 'approved'=>1, 'ip'=>$_SERVER['REMOTE_ADDR']));
|
|||
|
|
$this->design->assign('comments', $comments);
|
|||
|
|
|
|||
|
|
$article->text = preg_replace_callback('~<iframe width="(.*)"([^<]+)<\/iframe>~Uis', 'changeIframe', $article->text);
|
|||
|
|
|
|||
|
|
$this->design->assign('article', $article);
|
|||
|
|
|
|||
|
|
// Соседние записи
|
|||
|
|
$this->design->assign('next_article', $this->articles->get_next_article($article->id));
|
|||
|
|
$this->design->assign('prev_article', $this->articles->get_prev_article($article->id));
|
|||
|
|
|
|||
|
|
// Связанные объекты
|
|||
|
|
$related_objects = $this->articles->get_related_objects(array('id'=>$article->id));
|
|||
|
|
if(!empty($related_objects))
|
|||
|
|
{
|
|||
|
|
$r_products = array();
|
|||
|
|
$r_articles = array();
|
|||
|
|
|
|||
|
|
foreach($related_objects as &$r_p)
|
|||
|
|
if($r_p->type == 'product') $r_products[$r_p->object_id] = &$r_p;
|
|||
|
|
elseif($r_p->type == 'article') $r_articles[$r_p->object_id] = &$r_p;
|
|||
|
|
|
|||
|
|
if(!empty($r_products)) {
|
|||
|
|
|
|||
|
|
//echo '<!-- @@@1'; print_r($r_products); echo '-->';
|
|||
|
|
|
|||
|
|
// foreach($this->products->get_products(array('id'=>array_keys($r_products), 'in_stock'=>1, 'visible'=>1)) as $p)
|
|||
|
|
foreach($this->products->get_products(array('id'=>array_keys($r_products), 'visible'=>1)) as $p)
|
|||
|
|
$r_products[$p->id] = $p;
|
|||
|
|
|
|||
|
|
//echo '<!-- @@@2'; print_r($r_products); echo '-->';
|
|||
|
|
|
|||
|
|
$r_products_images = $this->products->get_images(array('product_id'=>array_keys($r_products)));
|
|||
|
|
foreach($r_products_images as $related_product_image)
|
|||
|
|
if(isset($r_products[$related_product_image->product_id]))
|
|||
|
|
$r_products[$related_product_image->product_id]->images[] = $related_product_image;
|
|||
|
|
|
|||
|
|
$r_products_variants = $this->variants->get_variants(array('product_id'=>array_keys($r_products), 'instock'=>true));
|
|||
|
|
foreach($r_products_variants as $related_product_variant)
|
|||
|
|
{
|
|||
|
|
if(isset($r_products[$related_product_variant->product_id]))
|
|||
|
|
{
|
|||
|
|
$r_products[$related_product_variant->product_id]->variants[] = $related_product_variant;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach($r_products as $id=>$r)
|
|||
|
|
{
|
|||
|
|
if(is_object($r))
|
|||
|
|
{
|
|||
|
|
$r->image = &$r->images[0];
|
|||
|
|
$r->variant = &$r->variants[0];
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
unset($r_products[$id]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(!empty($r_articles)) {
|
|||
|
|
$temp_articles = $this->articles->get_articles(array('id'=>array_keys($r_articles)));
|
|||
|
|
foreach($temp_articles as $temp_article)
|
|||
|
|
$r_articles[$temp_article->id] = $temp_article;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//echo '<!-- @@@3'; print_r($r_products); echo '-->';
|
|||
|
|
|
|||
|
|
$this->design->assign('related_products', $r_products);
|
|||
|
|
$this->design->assign('related_articles', $r_articles);
|
|||
|
|
}
|
|||
|
|
// Отзывы о товаре
|
|||
|
|
$comments = $this->comments->get_comments(array('type'=>'articles', 'object_id'=>$article->id, 'approved'=>1, 'ip'=>$_SERVER['REMOTE_ADDR']));
|
|||
|
|
|
|||
|
|
// Мета-теги
|
|||
|
|
$page = $this->request->get('page', 'int');
|
|||
|
|
$p = ($page > 1) ? ' страница №'.$page : '';
|
|||
|
|
$p2 = ($page > 1) ? ', страница №'.$page : '';
|
|||
|
|
|
|||
|
|
// echo '<!--'; var_dump($article); echo '-->';
|
|||
|
|
|
|||
|
|
if(!$article->meta_title) $article->meta_title = $article->name . ' в Санкт-Петербурге';
|
|||
|
|
if(!$article->meta_description) $article->meta_description = 'Наши работы: ' . $article->name . ' в Санкт-Петербурге - центр Atomic Garage: тюнинг и ремонт фар любой сложности, восстановление и улучшение качества света, комплексное обслуживание автомобиля.';
|
|||
|
|
if(!$article->meta_keywords) $article->meta_keywords = 'наши, работы, проекты, примеры, ' . $article->name . ', тюнинг центр, авто, автомобиль, санкт-петербург, установка, замена, ремонт';
|
|||
|
|
|
|||
|
|
$this->design->assign('meta_title', ($article->meta_title).$p);
|
|||
|
|
$this->design->assign('meta_keywords', ($article->meta_keywords).$p2);
|
|||
|
|
$this->design->assign('meta_description', ($article->meta_description).$p);
|
|||
|
|
|
|||
|
|
//require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Img.php';
|
|||
|
|
$this->db->query("SELECT * FROM __article_photo WHERE article_id='" . $article->id . "' ORDER BY position, id DESC");
|
|||
|
|
$photos = $this->db->results();
|
|||
|
|
foreach($photos as $ph){
|
|||
|
|
$ph->image = Img::get('/files/article_photo/' . $ph->img, array('width'=>400));
|
|||
|
|
$ph->bigImage = Img::get('/files/article_photo/' . $ph->img, array('width'=>1200));
|
|||
|
|
}
|
|||
|
|
$this->design->assign('article_photos', $photos);
|
|||
|
|
|
|||
|
|
return $this->design->fetch('article.tpl');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function fetch_articles()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$name_style = $img_style= '';
|
|||
|
|
// GET-Параметры
|
|||
|
|
//$category_url = $this->request->get('category', 'string');
|
|||
|
|
$category_url = $this->request->get('url', 'string');
|
|||
|
|
|
|||
|
|
if(isset($_GET['page']) && $_GET['page'] == 1){
|
|||
|
|
Header( "HTTP/1.1 301 Moved Permanently" );
|
|||
|
|
Header( "Location: /articles/" . $category_url . '/' );
|
|||
|
|
exit;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$filter = array();
|
|||
|
|
$filter['visible'] = 1;
|
|||
|
|
|
|||
|
|
// Выберем текущую категорию
|
|||
|
|
if (!empty($category_url))
|
|||
|
|
{
|
|||
|
|
$category = $this->articles->get_category((string)$category_url);
|
|||
|
|
if (empty($category) || (!$category->visible && empty($_SESSION['admin']))) return false;
|
|||
|
|
$this->design->assign('article_category', $category); //echo '<!--';var_dump($category->subcategories); echo '-->';
|
|||
|
|
// $a = array();
|
|||
|
|
// foreach($category->subcategories as $k=>$v){
|
|||
|
|
// if($v->visible == 0) unset($category->subcategories[$k]);
|
|||
|
|
// }
|
|||
|
|
//echo '<!--';print_r($_SESSION); echo '-->';
|
|||
|
|
$filter['category_id'] = $category->children;
|
|||
|
|
}else{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Если задано ключевое слово
|
|||
|
|
$keyword = $this->request->get('keyword', 'string');
|
|||
|
|
if (!empty($keyword))
|
|||
|
|
{
|
|||
|
|
$this->design->assign('keyword', $keyword);
|
|||
|
|
$filter['keyword'] = $keyword;
|
|||
|
|
}
|
|||
|
|
//print_r($_SERVER);
|
|||
|
|
// Постраничная навигация
|
|||
|
|
$items_per_page = $this->settings->products_num;
|
|||
|
|
// Текущая страница в постраничном выводе
|
|||
|
|
$current_page = $this->request->get('page', 'int');
|
|||
|
|
// Если не задана, то равна 1
|
|||
|
|
$current_page = max(1, $current_page);
|
|||
|
|
$this->design->assign('current_page_num', $current_page);
|
|||
|
|
// Вычисляем количество страниц
|
|||
|
|
|
|||
|
|
$filter['page'] = $current_page;
|
|||
|
|
$filter['limit'] = $items_per_page;
|
|||
|
|
$filter = $this->sortByService($filter);
|
|||
|
|
|
|||
|
|
$articles_count = $this->articles->count_articles($filter);
|
|||
|
|
$pages_num = ceil($articles_count/$items_per_page);
|
|||
|
|
$this->design->assign('total_pages_num', $pages_num);
|
|||
|
|
|
|||
|
|
if($pages_num && $current_page > $pages_num){
|
|||
|
|
return $this->force404();
|
|||
|
|
/*header("HTTP/1.0 404 Not Found");
|
|||
|
|
header("Status: 404 Not Found");
|
|||
|
|
Header( "Location: /404/" );
|
|||
|
|
die;*/
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(strpos($_SERVER['REQUEST_URI'], '?page=') !== false){
|
|||
|
|
Header( "HTTP/1.1 301 Moved Permanently" );
|
|||
|
|
$url = $_GET['page'] != 1 ? 'page-' . $_GET['page'] . '/' : '';
|
|||
|
|
$u = explode('?', $_SERVER['REQUEST_URI']);
|
|||
|
|
Header( "Location: " . $u[0]. $url );
|
|||
|
|
die;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//$filter['page'] = $current_page;
|
|||
|
|
//$filter['limit'] = $items_per_page;
|
|||
|
|
///////////////////////////////////////////////
|
|||
|
|
// Постраничная навигация END
|
|||
|
|
///////////////////////////////////////////////
|
|||
|
|
$this->design->assign('services', $this->getServices($filter, 0));
|
|||
|
|
//$filter = $this->sortByService($filter);
|
|||
|
|
// Статьи
|
|||
|
|
$articles = array();
|
|||
|
|
foreach($this->articles->get_articles($filter) as $a)
|
|||
|
|
$articles[$a->id] = $a;
|
|||
|
|
|
|||
|
|
//echo '<!--';var_dump($articles); echo '-->';
|
|||
|
|
// Если искали товар и найден ровно один - перенаправляем на него
|
|||
|
|
if(!empty($keyword) && $products_count == 1)
|
|||
|
|
header('Location: '.$this->config->root_url.'/article/'.$a->url);
|
|||
|
|
|
|||
|
|
// Устанавливаем мета-теги в зависимости от запроса
|
|||
|
|
$page = $this->request->get('page', 'int');
|
|||
|
|
//echo '<pre>'; print_r($this->page); die;
|
|||
|
|
|
|||
|
|
$filterService = $this->getFilterService();
|
|||
|
|
|
|||
|
|
if($filterService){
|
|||
|
|
|
|||
|
|
$this->design->assign('meta_title', 'Наши работы - ' . $filterService->name .' в тюнинг центре Atomic Garage');
|
|||
|
|
$this->design->assign('meta_keywords', 'наши работы, проекты, ' . $filterService->name .', тюнинг центр, авто, автомобиль, санкт-петербург, установка, замена, ремонт');
|
|||
|
|
$this->design->assign('meta_description', 'Примеры работ в тюнинг центре Atomic Garage: ' . $filterService->name . ' в Санкт-Петербурге.');
|
|||
|
|
|
|||
|
|
if($category) $category->name .= ' - ' . $filterService->name;
|
|||
|
|
|
|||
|
|
}else{
|
|||
|
|
|
|||
|
|
|
|||
|
|
if($this->page && !isset($category))
|
|||
|
|
{
|
|||
|
|
$this->design->assign('meta_title', $this->page->meta_title);
|
|||
|
|
$this->design->assign('meta_keywords', $this->page->meta_keywords);
|
|||
|
|
$this->design->assign('meta_description', $this->page->meta_description);
|
|||
|
|
}
|
|||
|
|
elseif(isset($category))
|
|||
|
|
{ //echo '<pre>'; print_r($category); die;
|
|||
|
|
|
|||
|
|
if($category->id == 40){
|
|||
|
|
$name_style = 'height:46px;';
|
|||
|
|
}
|
|||
|
|
$sx = explode(' ', $category->name);
|
|||
|
|
$this->design->assign('maybeBrand', array_pop($sx));
|
|||
|
|
|
|||
|
|
if(isset($_GET['page'])) $category->name .= ' - страница '.$_GET['page'];
|
|||
|
|
|
|||
|
|
$title = $category->meta_title;
|
|||
|
|
$desc = $category->meta_description;
|
|||
|
|
$keys = $category->meta_keywords;
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
|
|||
|
|
if($category->id == 5 && isset($_GET['page'])) $title .= ' в';
|
|||
|
|
|
|||
|
|
if(isset($category->path[0]) && $category->path[1]->id && $category->path[0]->id == 5){
|
|||
|
|
$title = $category->name.' - тюнинг в';
|
|||
|
|
$desc = $category->name.' - визуальный тюнинг автомобильной оптики по выгодным ценам в Санкт-Петербурге от установочного центра CarHeart.';
|
|||
|
|
$keys = 'примеры работ, '.$category->name.', тюнинг, установка, автомобиль, цена, спб, визуальный, стайлинг, световая оптика, фары, линзы';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(isset($category->parent_id) && $category->parent_id == 3){
|
|||
|
|
$title = 'Установочный центр '.$category->name.' в';
|
|||
|
|
$desc = 'Фотографии и примеры работ, выполненных в нашем установочном центре '.$category->name;
|
|||
|
|
$keys = $category->name.', установочный центр, примеры работ, фотографии';
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
//$title = $category->name;
|
|||
|
|
//$desc = $category->name;
|
|||
|
|
// $keys = $category->name;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//echo $category->path[0]->id; echo '.'.$category->path[1]->id; echo '.'.$category->path[2]->id; echo $category->name;
|
|||
|
|
|
|||
|
|
$this->design->assign('meta_title', $title);
|
|||
|
|
$this->design->assign('meta_keywords', $keys);
|
|||
|
|
$this->design->assign('meta_description', $desc);
|
|||
|
|
}
|
|||
|
|
elseif(!empty($keyword))
|
|||
|
|
{
|
|||
|
|
$this->design->assign('meta_title', $keyword);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
$this->design->assign('meta_title', 'Полезные статьи');
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
if($this->request->get('filter', 'int')){
|
|||
|
|
$serviceId = $this->request->get('filter', 'int');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$this->design->assign('articles', $articles);
|
|||
|
|
|
|||
|
|
$categories = $this->articles->get_categories_tree();
|
|||
|
|
$this->design->assign('article_categories', $categories);
|
|||
|
|
$this->design->assign('name_style', $name_style);
|
|||
|
|
|
|||
|
|
$res = $this->db->query("SELECT * FROM __article_models GROUP BY marka_id");
|
|||
|
|
$rows = $this->db->results();
|
|||
|
|
|
|||
|
|
if($rows){
|
|||
|
|
$ids = array();
|
|||
|
|
foreach($rows as $row) $ids[] = $row->marka_id;
|
|||
|
|
|
|||
|
|
$this->db->query("SELECT * FROM __marka WHERE visible=1 AND id IN(".implode(',', $ids).") ORDER BY name");
|
|||
|
|
$markas = $this->db->results();
|
|||
|
|
$this->design->assign('markas', $markas);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
$this->body = $this->design->fetch('articles.tpl');
|
|||
|
|
return $this->body;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function sortByService($filter){
|
|||
|
|
$serviceUrl = $this->request->get('filter', 'string');
|
|||
|
|
if(!$serviceUrl) return $filter;
|
|||
|
|
|
|||
|
|
$this->db->query("SELECT id FROM __pages WHERE url = '".$serviceUrl."' LIMIT 1 ");
|
|||
|
|
$item = $this->db->result();
|
|||
|
|
if(!$item) return $filter;
|
|||
|
|
|
|||
|
|
|
|||
|
|
$ids = array($item->id);
|
|||
|
|
|
|||
|
|
$origFilter = $filter;
|
|||
|
|
$filter['id'] = array();
|
|||
|
|
|
|||
|
|
$services = $this->getChildServices($item->id);
|
|||
|
|
|
|||
|
|
foreach($services as $id => $name) $ids[] = $id;
|
|||
|
|
|
|||
|
|
$this->db->query("SELECT * FROM __article_pages WHERE page_id IN(".implode(',', $ids).")");
|
|||
|
|
|
|||
|
|
foreach($this->db->results() as $row){
|
|||
|
|
if(!empty($origFilter['id']) && in_array($row->article_id, $origFilter['id'])) $filter['id'][] = $row->article_id;
|
|||
|
|
if( empty($origFilter['id']) ) $filter['id'][] = $row->article_id;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $filter;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getFilterService(){
|
|||
|
|
$serviceUrl = $this->request->get('filter', 'string');
|
|||
|
|
if(!$serviceUrl) return;
|
|||
|
|
|
|||
|
|
$this->db->query("SELECT * FROM __pages WHERE url = '".$serviceUrl."' LIMIT 1 ");
|
|||
|
|
return $this->db->result();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function getServices($filter = array(), $skipArticles = true){ ///return $this->getChildServices(28);
|
|||
|
|
|
|||
|
|
unset($filter['page']);
|
|||
|
|
unset($filter['limit']);
|
|||
|
|
|
|||
|
|
if(!$skipArticles && isset($filter['id'])) unset($filter['id']);
|
|||
|
|
|
|||
|
|
$articles = $this->articles->get_articles($filter);
|
|||
|
|
|
|||
|
|
$ids = array();
|
|||
|
|
|
|||
|
|
foreach($articles as $row) $ids[] = $row->id;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$this->db->query("SELECT * FROM __article_pages WHERE article_id IN(".implode(',', $ids).") GROUP BY page_id");
|
|||
|
|
|
|||
|
|
if(!$articlePages = $this->db->results()) return array();
|
|||
|
|
|
|||
|
|
$_pageIds = $pageIds = $_services = array();
|
|||
|
|
|
|||
|
|
$services = $this->getChildServices(28);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
foreach($articlePages as $row){
|
|||
|
|
$_pageIds = array_merge($this->getAllParents($row->page_id, $services), $_pageIds);
|
|||
|
|
}
|
|||
|
|
foreach($_pageIds as $id) $pageIds[$id] = $id;
|
|||
|
|
|
|||
|
|
|
|||
|
|
foreach($services as $id=>$row){
|
|||
|
|
if(isset($pageIds[$id])) $_services[$id] = $row;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
return $_services;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function getAllParents($id, $services, $items = array()){
|
|||
|
|
foreach($services as $row){
|
|||
|
|
if($row->id == $id){
|
|||
|
|
$items[$row->id] = $row->id;
|
|||
|
|
$items = $this->getAllParents($row->parent, $services, $items);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $items;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getChildServices($parentId, $services = array(), $prefix = ''){
|
|||
|
|
$this->db->query("SELECT id,name,url,parent FROM __pages WHERE parent=" . $parentId);
|
|||
|
|
$rows = $this->db->results();
|
|||
|
|
if(!$rows) return $services;
|
|||
|
|
|
|||
|
|
foreach($rows as $row){
|
|||
|
|
$row->name = $prefix . $row->name;
|
|||
|
|
$services[$row->id] = $row;
|
|||
|
|
if(!isset($this->servicesTree[$row->parent])) $this->servicesTree[$row->parent] = array();
|
|||
|
|
$this->servicesTree[$row->parent][$row->id] = $row;
|
|||
|
|
$services = $this->getChildServices($row->id, $services, $prefix . ' ');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $services;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|