2022-12-11 13:55:49 +05:00
< ? php
2023-08-28 22:47:07 +05:00
ini_set ( 'display_errors' , 0 );
2023-04-09 19:52:26 +05:00
2023-08-28 22:47:07 +05:00
$_GET [ 'id' ] = ( $_GET [ 'id' ]) ? $_GET [ 'id' ] : 0 ;
2023-04-09 19:52:26 +05:00
2023-01-25 14:20:32 +05:00
@ mkdir ( 'img/' . $_SESSION [ 'SERVER_NAME' ] . '/pages_category' , 0700 );
2023-08-28 22:47:07 +05:00
/* ----------------------------------------------------------------------
19.08 . 2023
Сохраняем блог
---------------------------------------------------------------------- */
if ( $_SESSION [ 'user_id' ] && $_POST [ 'ok' ]) {
$page_id = \DB :: add ( " INSERT INTO `pages` (`title`, `txt`, `t`, `user_id`, `status`, `category`) VALUES (?, ?, ?, ?, ?) " , array (
$_POST [ 'title' ], $_POST [ 'txt' ],
time (), $_SESSION [ 'user_id' ],
3 , $_GET [ 'id' ]
)
);
//Загружаем картинку
if ( $_FILES [ 'file' ][ 'tmp_name' ]) {
@ mkdir ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/pages/' . $page_id , 0700 );
if ( preg_match ( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/' , $_FILES [ 'file' ][ 'name' ])) {
$img_name = \core :: genpassword ( 30 );
$source = $_FILES [ 'file' ][ 'tmp_name' ];
$target_original = 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/pages/' . $page_id . '/' . $img_name . '.jpg' ;
copy ( $source , $target_original );
\DB :: add (
" INSERT INTO `img` (`filename`, `content_type`, `content_id`) VALUES (?, ?, ?) " ,
array (
$img_name ,
'pages' ,
$page_id
)
);
}
}
header ( 'Location: /page/' . $page_id );
}
2023-08-14 09:15:58 +05:00
/* ----------------------------------------------------------------------
11.08 . 2023
Получаем информацию о текущей категории
---------------------------------------------------------------------- */
2023-08-28 22:47:07 +05:00
if ( $_GET [ 'id' ] > 0 ) {
$thisCategory = \DB :: getRow ( " SELECT `id`, `title`, `subtitle`, `description`, `keywords` FROM `pages_category` WHERE id=? LIMIT 1 " , $_GET [ 'id' ]);
$thisCategory [ 'filename' ] = \DB :: getValue ( " SELECT `filename` FROM `img` WHERE `content_type`='pages_category' AND `content_id`=? LIMIT 1 " , $_GET [ 'id' ]);
$smarty -> assign ( 'page_info' , $thisCategory );
2023-08-14 09:15:58 +05:00
}
2023-04-09 19:52:26 +05:00
2023-08-14 09:15:58 +05:00
/* ----------------------------------------------------------------------
11.08 . 2023
Получаем подкатегории
---------------------------------------------------------------------- */
2023-08-28 22:47:07 +05:00
$cats = \DB :: getAll ( " SELECT `id`, `title` FROM `pages_category` WHERE `category`=? AND `status`=1 ORDER BY `title` " , $_GET [ 'id' ]);
$smarty -> assign ( 'cats' , $cats );
2023-08-14 09:15:58 +05:00
/* ----------------------------------------------------------------------
11.08 . 2023
Получаем список хлебные крошки
---------------------------------------------------------------------- */
2023-08-28 22:47:07 +05:00
$b = \core :: getBreadcrumb ( 'pages_category' , $_GET [ 'id' ]);
$smarty -> assign ( 'Breadcrumb' , $b );
2023-08-14 09:15:58 +05:00
/* ----------------------------------------------------------------------
11.08 . 2023
Получаем список страниц в категории
---------------------------------------------------------------------- */
2023-04-09 19:52:26 +05:00
2023-08-28 22:47:07 +05:00
$list = \DB :: getAll ( " SELECT `id`, `title`, `alias`, `t`, `reyt`, `see`,`description` FROM `pages` WHERE `category`=? ORDER BY `t` DESC " , $_GET [ 'id' ]);
2023-04-09 19:52:26 +05:00
2023-08-28 22:47:07 +05:00
for ( $i = 0 ; $i < count ( $list ); $i ++ ) {
$list [ $i ][ 'filename' ] = \DB :: getValue ( " SELECT `filename` FROM `img` WHERE `content_type`='pages' AND `content_id`=? LIMIT 1 " , $list [ $i ][ 'id' ]);
$list [ $i ][ 'link' ] = ( $list [ $i ][ 'alias' ]) ? '/' . $list [ $i ][ 'alias' ] . '.html' : '/page/' . $list [ $i ][ 'id' ];
2023-04-09 19:52:26 +05:00
}
//print_r($list);
2023-08-28 22:47:07 +05:00
$smarty -> assign ( 'list' , $list );
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
01.04 . 2023
2023-08-14 09:15:58 +05:00
Получаем список категорий страниц
2023-04-09 19:52:26 +05:00
---------------------------------------------------------------------- */
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(*)'];
//$smarty->assign('categories', $categories);
2023-04-09 19:52:26 +05:00
/* ----------------------------------------------------------------------
02.04 . 2023
Получаем самое читабельное
---------------------------------------------------------------------- */
2023-08-28 22:47:07 +05:00
$popular_pages = \DB :: getAll ( " SELECT `id`, `title`, `description`, `alias` FROM `pages` WHERE `status`=1 ORDER BY `see` DESC LIMIT 15 " );
for ( $i = 0 ; $i < count ( $popular_pages ); $i ++ )
$popular_pages [ $i ][ 'filename' ] = \DB :: getValue ( " SELECT `filename` FROM `img` WHERE `content_id`=? AND `content_type`='pages_category' LIMIT 1 " , $popular_pages [ $i ][ 'id' ]);
2023-04-09 19:52:26 +05:00
$smarty -> assign ( 'popular_pages' , $popular_pages );
2022-12-11 13:55:49 +05:00
?>