149 lines
6.6 KiB
PHP
149 lines
6.6 KiB
PHP
|
<?php
|
|||
|
|
|||
|
/*
|
|||
|
26.05.2017
|
|||
|
Добавлена загрузка обложки
|
|||
|
27.07.2017
|
|||
|
Урезан код за счет удаления открытых SQL-запросов, все перенесено в апи
|
|||
|
20.11.2017
|
|||
|
Работа с ЧПУ - изменение данных
|
|||
|
*/
|
|||
|
unset($a);
|
|||
|
if ( $_SESSION['dostup'] !=='a' && $_SESSION['dostup'] !== 'e' ) header( 'Location: /403/' );
|
|||
|
require MYDIR . '/api/php/genpass.php';
|
|||
|
if( @$_FILES['img1']['tmp_name'] ){
|
|||
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['img1']['name'] ) ) {
|
|||
|
$b = generate_password(10);
|
|||
|
$source = $_FILES['img1']['tmp_name'];
|
|||
|
$target = MYDIR.'/img/pages/' . $b . '.jpg';
|
|||
|
$target2 = MYDIR.'/img/pages/' . $b . '_min.jpg';
|
|||
|
copy( $source, $target );
|
|||
|
$size = getimagesize ( $target );
|
|||
|
if ( $size[0] > 400 ) exec ( 'convert ' . $target . ' -resize 400 -quality 95 ' . $target );
|
|||
|
exec ( 'convert ' . $target . ' -gravity Center -crop 250x250+0 ' . $target2 );
|
|||
|
$_POST['img1'] = $b;
|
|||
|
}
|
|||
|
}
|
|||
|
if( @$_FILES['img2']['tmp_name'] ){
|
|||
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['img2']['name'] ) ) {
|
|||
|
$b = generate_password(10);
|
|||
|
$source = $_FILES['img2']['tmp_name'];
|
|||
|
$target = MYDIR . '/img/pages/' . $b . '.jpg';
|
|||
|
$target2 = MYDIR . '/img/pages/' . $b . '_min.jpg';
|
|||
|
copy($source, $target);
|
|||
|
$size = getimagesize ( $target );
|
|||
|
if ( $size[0] > 400 ) exec ( 'convert ' . $target . ' -resize 400 -quality 95 ' . $target );
|
|||
|
exec ( 'convert ' . $target . ' -gravity Center -crop 250x250+0 ' . $target2 );
|
|||
|
$_POST['img2'] = $b;
|
|||
|
}
|
|||
|
}
|
|||
|
if(@$_FILES['img3']['tmp_name']){
|
|||
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['img3']['name'] ) ) {
|
|||
|
$b=generate_password(10);
|
|||
|
$source = $_FILES['img3']['tmp_name'];
|
|||
|
$target = MYDIR.'/img/pages/' . $b . '.jpg';
|
|||
|
$target2 = MYDIR.'/img/pages/' . $b . '_min.jpg';
|
|||
|
copy($source, $target);
|
|||
|
$size = getimagesize ( $target );
|
|||
|
if ( $size[0] > 400 ) exec ( 'convert ' . $target . ' -resize 400 -quality 95 ' . $target );
|
|||
|
exec ( 'convert ' . $target . ' -gravity Center -crop 250x250+0 ' . $target2 );
|
|||
|
$_POST['img3'] = $b;
|
|||
|
}
|
|||
|
}
|
|||
|
if(@$_FILES['img4']['tmp_name']){
|
|||
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['img4']['name'] ) ) {
|
|||
|
$b=generate_password(10);
|
|||
|
$source = $_FILES['img4']['tmp_name'];
|
|||
|
$target = MYDIR.'/img/pages/' . $b . '.jpg';
|
|||
|
$target2 = MYDIR.'/img/pages/' . $b . '_min.jpg';
|
|||
|
copy($source, $target);
|
|||
|
$size = getimagesize ( $target );
|
|||
|
if ( $size[0] > 400 ) exec ( 'convert ' . $target . ' -resize 400 -quality 95 ' . $target );
|
|||
|
exec ( 'convert ' . $target . ' -gravity Center -crop 250x250+0 ' . $target2 );
|
|||
|
$_POST['img4'] = $b;
|
|||
|
}
|
|||
|
}
|
|||
|
//загружаем обложку
|
|||
|
if (@$_FILES['oblozhka']['tmp_name']){
|
|||
|
$src = $_FILES['oblozhka']['tmp_name'];
|
|||
|
$f1 = generate_password(10);
|
|||
|
$f2 = generate_password(10);
|
|||
|
$img = MYDIR . '/img/pages/' . $f1 . '.jpg';
|
|||
|
$img_big = MYDIR . '/img/pages/' . $f2 . '.jpg';
|
|||
|
//$target700_100 = MYDIR . '/img/pages/' . $f2 . '_700_100.jpg';//Куда загружаем:
|
|||
|
$target770_471 = MYDIR . '/img/pages/' . $f1 . '_770_471.jpg';//Куда загружаем:
|
|||
|
$target370_245 = MYDIR . '/img/pages/' . $f1 . '_370_245.jpg';
|
|||
|
$target770_471c = MYDIR . '/img/pages/' . $f1 . '_770_471c.jpg';//Куда загружаем:
|
|||
|
$target370_245c = MYDIR . '/img/pages/' . $f1 . '_370_245c.jpg';
|
|||
|
$target80_75 = MYDIR . '/img/pages/' . $f1 . '_80_75.jpg';
|
|||
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['oblozhka']['name'] ) ) {
|
|||
|
copy( $src, $img );
|
|||
|
include( MYDIR . '/api/php/img2.php' );
|
|||
|
rimg($img, 770, 471, $target770_471, 90);
|
|||
|
rimg($img, 370, 245, $target370_245, 90);
|
|||
|
rimg($img, 80, 75, $target80_75, 100);
|
|||
|
rimg($img, 770, 471, $target770_471c, 50, 1);
|
|||
|
rimg($img, 370, 245, $target370_245c, 50, 1);
|
|||
|
copy( $src, $img_big );
|
|||
|
unlink( $src );
|
|||
|
//создаем маленькую картинку
|
|||
|
$size = getimagesize ( $img_big );
|
|||
|
if ( $size[0] > 350 ) exec ( 'convert ' . $img_big . ' -resize 350 -quality 100 ' . $img );
|
|||
|
exec ( 'convert ' . $img . ' -gravity Center -crop 190x190+0 ' . $img );
|
|||
|
// Доступ на запись и чтение для владельца, нет доступа для других
|
|||
|
chmod( $img, 0600 );
|
|||
|
//создаем большую картинку
|
|||
|
if ( $size[0] > 700 ) exec ( 'convert ' . $img_big . ' -resize 700 -quality 100 ' . $img_big );
|
|||
|
chmod( $img_big, 0600 );
|
|||
|
unlink( MYDIR . '/img/pages/' . $old_img . '.jpg' );
|
|||
|
unlink( MYDIR . '/img/pages/' . $old_img2 . '.jpg' );
|
|||
|
$_POST['oblozhka'] = $f1;
|
|||
|
$_POST['oblozhka_big'] = $f2;
|
|||
|
}
|
|||
|
}
|
|||
|
$_POST['avtor']=$_SESSION['user_id'];//записываем автора страницы
|
|||
|
include MYDIR . '/api/php/ekr.php';
|
|||
|
//$_POST['txt']=ekr($_POST['txt']);
|
|||
|
if ( ID ){//если задан ИД - пробуем найти, иначе создаем новую страницу
|
|||
|
$tmp['alias'] = ID; //пробуем найти страницу по алиасу
|
|||
|
$db -> get_massiv ( 'pages', $tmp, '', '1' );
|
|||
|
$page = $db -> result;
|
|||
|
if ( !$page[0]['id'] ){//если по алиасу не нашли, ищем по ИД
|
|||
|
unset( $tmp );
|
|||
|
$tmp['id'] = ID;
|
|||
|
$db -> get_massiv ( 'pages', $tmp, '', '1' );
|
|||
|
$page = $db -> result;
|
|||
|
}
|
|||
|
$smarty -> assign( 'page', $page );
|
|||
|
if ( isset ( $_POST['ok'] ) ){
|
|||
|
$_POST['abtime'] = time();
|
|||
|
$_POST['user_id'] = $_SESSION['user_id'];
|
|||
|
$db -> update('pages', $page[0]['id'], $_POST);
|
|||
|
header( 'Location: /page/' . $page[0]['id']);
|
|||
|
}
|
|||
|
}else{
|
|||
|
if ( isset( $_POST['ok'] ) ){
|
|||
|
$_POST['abtime'] = time();
|
|||
|
$_POST['user_id'] = $_SESSION['user_id'];
|
|||
|
$db -> add( 'pages', $_POST );
|
|||
|
$id=$db -> id;
|
|||
|
header( 'Location: /page/' . $id );
|
|||
|
}
|
|||
|
}
|
|||
|
//выбираем редактор:
|
|||
|
switch ( $settings['editor'] ) {
|
|||
|
case 'tinymce':
|
|||
|
$smarty -> assign( 'editor', '<script language="javascript" type="text/javascript" src="/api/soft/tinymce/4.3.12/tinymce.min.js"></script><script language="javascript" type="text/javascript" src="/api/soft/tinymce/4.3.12/load.php"></script>');
|
|||
|
break;
|
|||
|
default:
|
|||
|
$smarty -> assign( 'editor', '<script language="javascript" type="text/javascript" src="/api/soft/tinymce/4.3.12/tinymce.min.js"></script><script language="javascript" type="text/javascript" src="/api/soft/tinymce/4.3.12/load.php"></script>');
|
|||
|
}
|
|||
|
/* выбираем категорию */
|
|||
|
$db -> get_massiv ( 'page_cat', '', 'txt' );
|
|||
|
$smarty -> assign( 'list', $db -> result );
|
|||
|
//загружаем список картинок
|
|||
|
unset($a);
|
|||
|
$a['page_id']=ID;
|
|||
|
$smarty -> assign( 'img', $db -> get_massiv ( 'img', $a) );
|
|||
|
|
|||
|
?>
|