2022-12-11 13:55:49 +05:00
< ? php
2023-01-14 21:17:46 +05:00
ini_set ( 'display_errors' , 0 );
2023-02-12 15:08:07 +05:00
@ mkdir ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/ava' , 0700 );
/* ----------------------------------------------------------------------
11.02 . 2023
Получаем страницу
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$page = \DB :: getAll ( " SELECT * FROM `pages` WHERE `id`=? OR `alias`=? LIMIT 1 " , array ( $_GET [ 'id' ], $_GET [ 'id' ]));
2023-08-28 22:47:07 +05:00
if ( $page [ 0 ][ 'status' ] == 0 ) header ( 'Location: /403/' );
//Редирект от дублей
if ( $_GET [ 'id' ] == $page [ 0 ][ 'id' ] && $page [ 0 ][ 'alias' ]){
header ( 'HTTP/1.1 301 Moved Permanently' );
header ( 'Location: /' . $page [ 0 ][ 'alias' ] . '.html' );
}
2023-08-14 09:15:58 +05:00
$page [ 0 ][ 'date' ] = ( $page [ 0 ][ 't' ]) ? date ( 'd.m.Y' , $page [ 0 ][ 't' ]) : time ();
2023-04-09 19:52:26 +05:00
2023-08-14 09:15:58 +05:00
$keywords = \DB :: getAll ( " SELECT `txt` FROM `keywords` WHERE `content_type`='page' AND `content_id`=? " , $page [ 0 ][ 'id' ]);
for ( $i = 0 ; $i < count ( $keywords ); $i ++ ) $page [ 0 ][ 'keywords' ] = $page [ 0 ][ 'keywords' ] . ', ' . $keywords [ $i ][ 'txt' ];
//$page[0]['keywords']=implode("," $keywords);
//print_r($keywords);
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
02.04 . 2024
Получаем обложку
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$page [ 0 ][ 'filename' ] = \DB :: getValue ( " SELECT `filename` FROM `img` WHERE `content_id`=? AND `content_type`='pages' LIMIT 1 " , $page [ 0 ][ 'id' ]);
//print_r($page);
2023-04-09 19:52:26 +05:00
2022-12-11 13:55:49 +05:00
$smarty -> assign ( 'page' , $page );
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
02.04 . 2024
Получаем данные о категории
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$category_title = \DB :: getValue ( " SELECT `title` FROM `pages_category` WHERE `id`=? " , $page [ 0 ][ 'category' ]);
$smarty -> assign ( 'category_title' , $category_title );
2023-04-09 19:52:26 +05:00
2023-02-12 15:08:07 +05:00
/* ----------------------------------------------------------------------
11.02 . 2023
Получаем данные о пользователе
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$autor = \DB :: getAll ( " SELECT * FROM `users` WHERE `id`=? LIMIT 1 " , $page [ 0 ][ 'user_id' ]);
if ( $autor [ 0 ][ 'dostup' ] == 'a' )
$autor [ 0 ][ 'dostup' ] = 'Администратор сайта' ;
2023-02-12 15:08:07 +05:00
$smarty -> assign ( 'autor' , $autor );
/* ----------------------------------------------------------------------
11.02 . 2023
Получаем количество статей пользователя
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$pageskolvo = \DB :: getAll ( " SELECT count(*) FROM `pages` WHERE `user_id`=? AND `status`=1 " , $page [ 0 ][ 'user_id' ]);
2023-02-12 15:08:07 +05:00
$smarty -> assign ( 'pageskolvo' , $pageskolvo [ 0 ][ 'count(*)' ]);
2023-02-13 16:05:33 +05:00
/* ----------------------------------------------------------------------
11.02 . 2023
Получаем коментарии
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$comments = \DB :: getAll ( " SELECT * FROM `pages_comments` WHERE `page_id`=? AND `status`=1 ORDER BY `id` DESC " , $page [ 0 ][ 'id' ]);
2023-02-13 16:05:33 +05:00
//Получаем инфу о пользователе - аву и фио
2023-08-14 09:15:58 +05:00
for ( $i = 0 ; $i < count ( $comments ); $i ++ ) {
$user_info = \DB :: getAll ( " SELECT `fio`, `ava` FROM `users` WHERE `id`=? LIMIT 1 " , $comments [ $i ][ 'user_id' ]);
$comments [ $i ][ 'ava' ] = $user_info [ 0 ][ 'ava' ];
$comments [ $i ][ 'fio' ] = $user_info [ 0 ][ 'fio' ];
2023-02-13 16:05:33 +05:00
unset ( $user_info );
}
$smarty -> assign ( 'comments' , $comments );
2023-02-19 21:07:48 +05:00
/* ----------------------------------------------------------------------
14.02 . 2023
Пишем статистику
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$see = \DB :: getValue ( " SELECT `see` FROM `pages` WHERE `id`=? LIMIT 1 " , $page [ 0 ][ 'id' ]);
$user_id = ( $_SESSION [ 'user_id' ]) ? $_SESSION [ 'user_id' ] : session_id ();
$id = \DB :: getValue ( " SELECT `id` FROM `likes` WHERE `content_id`=? AND `user_id`=? AND `tip`='see' LIMIT 1 " , array ( $page [ 0 ][ 'id' ], $user_id ));
if ( ! $id ) {
2023-02-19 21:07:48 +05:00
$see ++ ;
\DB :: set ( " UPDATE `pages` SET `see`=? WHERE `id`=? LIMIT 1 " , array ( $see , $page [ 0 ][ 'id' ]));
\DB :: add ( " INSERT INTO `likes` (`user_id`, `content_id`, `tip`) VALUES(?, ?, ?) " , array ( $user_id , $page [ 0 ][ 'id' ], 'see' ));
}
$smarty -> assign ( 'see' , $see );
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
01.04 . 2023
Получаем спиосок категорий страниц
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$categories = \DB :: getAll ( " SELECT * FROM `pages_category` ORDER BY `title` " );
for ( $i = 0 ; $i < count ( $categories ); $i ++ )
$categories [ $i ][ 'count' ] = \DB :: getAll ( " SELECT COUNT(*) FROM `pages` WHERE `category`=? AND `status`=1 " , $categories [ $i ][ 'id' ])[ 0 ][ 'COUNT(*)' ];
2023-04-09 19:52:26 +05:00
$smarty -> assign ( 'categories' , $categories );
/* ----------------------------------------------------------------------
02.04 . 2023
Получаем самое читабельное
---------------------------------------------------------------------- */
2023-08-28 22:47:07 +05:00
$popular_pages = \DB :: getAll ( " SELECT `title`, `id`, `description`, `t`, `alias`, `user_id`, `status` FROM `pages` WHERE `status`=1 ORDER BY `see` DESC LIMIT 9 " );
2023-08-14 09:15:58 +05:00
for ( $i = 0 ; $i < count ( $popular_pages ); $i ++ ) {
$popular_pages [ $i ][ 'filename' ] = \DB :: getValue ( " SELECT `filename` FROM `img` WHERE `content_type`='pages' AND `content_id`=? LIMIT 1 " , $popular_pages [ $i ][ 'id' ]);
$popular_pages [ $i ][ 'link' ] = ( $popular_pages [ $i ][ 'alias' ]) ? '/' . $popular_pages [ $i ][ 'alias' ] . '.html' : '/page/' . $popular_pages [ $i ][ 'id' ];
}
//for ($i=0; $i<count($popular_pages); $i++)$popular_pages[$i]['img']=\DB::getValue("SELECT `filename` FROM `pages_img` WHERE `pages_id`=? LIMIT 1", $popular_pages[$i]['id']);
2023-04-09 19:52:26 +05:00
//print_r($popular_pages);
$smarty -> assign ( 'popular_pages' , $popular_pages );
2023-08-14 09:15:58 +05:00
//print_r($popular_pages);
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
02.04 . 2023
Получаем вложенные изображения , кроме первого
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
//$page_img=\DB::getAll("SELECT * FROM `pages_img` WHERE `pages_id`=?", $page[0]['id']);
2023-04-09 19:52:26 +05:00
unset ( $page_img [ 0 ]);
$smarty -> assign ( 'page_img' , $page_img );
//print_r($page_img);
/* ----------------------------------------------------------------------
02.04 . 2023
Получаем коменты
---------------------------------------------------------------------- */
2023-08-14 09:15:58 +05:00
$comments = \DB :: getAll ( " SELECT * FROM `pages_comments` WHERE `page_id`=? AND `status`=1 ORDER BY `t` DESC " , $page [ 0 ][ 'id' ]);
for ( $i = 0 ; $i < count ( $comments ); $i ++ )
$comments [ $i ][ 'fio' ] = \DB :: getValue ( " SELECT `fio` FROM `users` WHERE `id`=? " , $comments [ $i ][ 'user_id' ]);
2023-04-09 19:52:26 +05:00
//print_r($comments);
$smarty -> assign ( 'comments' , $comments );
2023-08-14 09:15:58 +05:00
/* ----------------------------------------------------------------------
13.08 . 2023
Заполняем мета - теги
---------------------------------------------------------------------- */
function setKeywords ( $content_id , $host )
{
$token = 'y0_AgAAAAABiU4jAAn8iwAAAADkWpkSbFJu1kVDTGCi5DQIA4h6RaMwKpA' ;
$url = (( ! empty ( $_SERVER [ 'HTTPS' ])) ? 'https' : 'http' ) . '://' . $host . $_SERVER [ 'REQUEST_URI' ]; // . $_SERVER['REQUEST_URI']
//echo $url;
$params = array (
'ids' => '21950635' ,
'metrics' => 'ym:s:visits' ,
'dimensions' => 'ym:s:searchPhrase' ,
'date1' => '365daysAgo' ,
'date2' => 'today' ,
'filters' => " ym:pv:URL==' " . $url . " ' "
);
$ch = curl_init ( 'https://api-metrika.yandex.net/stat/v1/data?' . urldecode ( http_build_query ( $params )));
curl_setopt ( $ch , CURLOPT_HTTPHEADER , array ( 'Authorization: OAuth ' . $token ));
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt ( $ch , CURLOPT_HEADER , false );
$res = curl_exec ( $ch );
curl_close ( $ch );
$res = json_decode ( $res , true );
$words = array ();
foreach ( $res [ 'data' ] as $row ) {
$words [] = $row [ 'dimensions' ][ 0 ][ 'name' ];
}
//print_r($words);
for ( $i = 0 ; $i < count ( $words ); $i ++ ) {
$id = \DB :: getValue ( " SELECT `id` FROM `keywords` WHERE `content_id`=? AND `txt`=? AND `content_type`='page' LIMIT 1 " , array ( $content_id , $words [ $i ]));
if ( ! $id )
\DB :: set ( " INSERT INTO `keywords` (`content_type`, `content_id`, `txt`) VALUES (?, ?, ?) " , array ( 'page' , $content_id , $words [ $i ]));
}
}
function yurecntf ( $text )
{
$old1 = array ( " new.yurecnt.ru " );
$new1 = array ( " yurecnt.ru " );
$text = str_replace ( $old1 , $new1 , $text );
return $text ;
}
setKeywords ( $page [ 0 ][ 'id' ], yurecntf ( $_SERVER [ 'HTTP_HOST' ]));
2022-12-11 13:55:49 +05:00
?>