core/api/modules/tovar_show/class.php

162 lines
6.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class main extends MySQL{
var $id;
private $settings;
public $user_info;/* Array: Информация о пользователе*/
public $keywords;
public $comments;
private function user_info($id) { /* Получаем инормацию об авторе */
$db=$this->db;
$db -> or_by_desc = 0;
$a['id']=$id;
$this -> user_info = $db->get_massiv('users', $a, '', 1);
return $this -> user_info;
}
/* ------------------------------------------------------------------------------------------------------------------------- */
function gen_keywords($txt){ /* Генератор ключевых слов */
include_once MYDIR . '/api/php/kwg.php';
$keywords=seokeywords($txt, 5, 10);
return explode(",", $keywords);
}
/* ------------------------------------------------------------------------------------------------------------------------- */
private function redirect($page){ /* Редиректы куда надо */
if ( @$page[0]['alias'] && ID != @$page[0]['alias'] ){
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: /' . $page[0]['alias'] . '.html' );
}
if (@$page[0]['rdir']){//редирект на новую страницу
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: ' . $page[0]['rdir'] );
}
}
/* ------------------------------------------------------------------------------------------------------------------------- */
private function set_viewers($id, $reyt){/* меняем количество просмотров */
if (!@$_SESSION['user_id']){
$db=$this->db;
$p['reyt']=$reyt+1;
$db->update('pages', $id, $p);
}
}
function get_breadcrumb($id){
$db=$this->db;
$tmp['id']=$id;
$postrow = $db -> get_massiv ( 'pages_cat', $tmp, '', 1 );
$x=0;
$parent=$postrow[0]['parent'];
while ($parent != 0){
$x++;
unset($tmp);
$tmp['id']=$parent;
$postrow[$x] = $db -> get_massiv ( 'pages_cat', $tmp, '', 1 );
$parent=$postrow[$x]['parent'];
}
return $postrow;
}
/* ------------------------------------------------------------------------------------------------------------------------- */
function get_cat_info($id){
unset($a);
$a['id']=$id;
$a['tip']='category';
}
/* ------------------------------------------------------------------------------------------------------------------------- */
/*
26.12.2021
список категорий + количества статей в них
*/
function get_cat_list( $parent=0 ){
$tmp['tip'] ='category';
$tmp['public']=1;
$tmp['parent']=$parent;
$postrow = $this -> get_massiv ( 'pages', $tmp );
$num = count($postrow);
for($i = 0; $i < $num; $i++){
unset( $tmp );
$tmp['parent']=$postrow[$i]['id'];
$tmp['tip']='page';
$tmp['public']=1;
$postrow[$i]['posts_count'] = $this->count_sql('pages', $tmp);
}
return $postrow;
}
/* ----------------------------------------------------------------------
31.05.2022
Берем рандомный список товаров из этой же категории - с картинками!
Принимает количество и категорию
---------------------------------------------------------------------- */
function get_random_tovar( $kolvo=4, $tovar_cat ){
$sql = 'SELECT `id`, `txt`, `artikul`, `cena` FROM `pages` WHERE `tip`="tovar" AND `id`<> ' . ID . ' AND `public`="1" AND `parent` = "' . $tovar_cat . '" ORDER BY RANDOM() LIMIT ' . $kolvo;
$rndTovar = $this -> free_sql( $sql );
$num = count ( $rndTovar );
for ( $i=0; $i < $num; $i++ ){
unset( $a );
$a['page_id'] = $rndTovar[$i]['id'];
$rndTovar[$i]['img'] = $this -> get_val( 'img', $a, 'fileName' );
}
return $rndTovar;
}
/* ----------------------------------------------------------------------
01.06.2022
Пишем в историю просмотров что смотрели, чтоб навящиво выводить
---------------------------------------------------------------------- */
function to_history(){
$a['session_id'] = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
$a['page_id'] = ID;
$id = $this -> get_val( 'market_history', $a, 'id' );
if ( !$id ) $this -> add( 'market_history', $a );
}
/* ----------------------------------------------------------------------
01.06.2022
Читаем историю просмотров
---------------------------------------------------------------------- */
function from_history( $limit=4 ){
$this -> debug = 1;
$a['session_id'] = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
$this -> or_by_desc = 1;
$history = $this -> get_massiv( 'market_history', $a, 'id', $limit );
$this -> or_by_desc = 0;
$num = count( $history );
for ( $i=0; $i < $num; $i++ ){
$sql = 'SELECT pages.id, pages.txt, pages.artikul, pages.cena, img.fileName FROM pages, img WHERE pages.id= ' . $history[$i]['page_id'] . ' AND img.page_id = ' . $history[$i]['page_id'] . ' LIMIT 1';
$tovar = $this -> free_sql( $sql );
$tovarFromHistory[$i]['id'] = $history[$i]['page_id'];
$tovarFromHistory[$i]['txt'] = $tovar[0]['txt'];
$tovarFromHistory[$i]['artikul'] = $tovar[0]['artikul'];
$tovarFromHistory[$i]['cena'] = $tovar[0]['cena'];
$tovarFromHistory[$i]['fileName'] = $tovar[0]['fileName'];
unset( $tovar );
}
return $tovarFromHistory;
}
/* ----------------------------------------------------------------------
10.06.2022
Получаем характеристики из БД
---------------------------------------------------------------------- */
function get_harakteriskika(){
$a['pages_id']=ID;
$har=$this->get_massiv('har', $a);
$num = count( $har );
for ( $i=0; $i < $num; $i++ ){
unset($a);
$a['id']=$har[$i]['sp_har_id'];
$har[$i]['opt']=$this->get_val('sp_har', $a, 'txt');
}
return $har;
}
/* ------------------------------------------------------------------------------------------------------------------------- */
}
?>