core/api/modules/page_edit/ajax.php

77 lines
2.6 KiB
PHP

<?php
ini_set( 'display_errors', 1 );
switch(@$_POST['act']) {
case 'foto_upload':
@mkdir( 'img/' . $_SERVER['SERVER_NAME'] . '/pages', 0700 );
@mkdir( 'img/' . $_SERVER['SERVER_NAME'] . '/pages/' . $_SESSION['page_id'], 0700 );
if ( $_FILES['file']['tmp_name'] ){
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/' . $_SESSION['page_id'] . '/' . $img_name . '.jpg';
copy( $source, $target_original );
$mod_settings2=\core::setSettingsMod('page_edit');
$s_w=$mod_settings2['main-img-w']-100;
$s_h=$mod_settings2['main-img-h']-100;
$prw = 'img/' . $_SERVER['SERVER_NAME'] . '/pages/' . $_SESSION['page_id'] . '/' . $img_name . '_' . $mod_settings2['main-img-w'] . '_' . $mod_settings2['main-img-h'] . '.jpg';
exec ("convert -define jpeg:size=" . $s_w . "x" . $s_h . " " . $target_original . " -thumbnail '" . $mod_settings2['main-img-w'] . "x" . $mod_settings2['main-img-h'] . ">' -background white -gravity center -extent " . $mod_settings2['main-img-w'] . "x" . $mod_settings2['main-img-h'] . " " . $prw);
\DB::add( "INSERT INTO `pages_img` (`filename`, `pages_id`) VALUES (?, ?)", array( $img_name, $_SESSION['page_id'] ) );
}
}
break;
case 'save-settings':
$json=\json::to_j($_POST);
$id=\DB::getValue("SELECT `id` FROM `settings` WHERE `mod`='page_edit' LIMIT 1");
if ($id)
\DB::set("UPDATE `settings` SET `json` =? WHERE `mod`='page_edit' LIMIT 1", $json);
else
\DB::add("INSERT INTO `settings` (`mod`, `json`) VALUES (?, ?)", array('page_edit', $json));
break;
/*
case 'update_settings':
unset($_POST['act']);
$db->update_settings($_POST);
break;
case 'upload_main_img':
//echo 'uploader';
$settings_mod = $db -> get_settings_json($_POST['mod']);
unset($_POST['act']);
$tmp_name = $db -> upload_img( $_FILES, 'pages', 'main_img');
$db -> resize_img($tmp_name, $settings_mod['w'], $settings_mod['h'], 80, false, 'pages');
$db -> resize_img($tmp_name, $settings_mod['p_w'], $settings_mod['p_h'], 80, true, 'pages');
unset($a);
$a['id']=$_POST['id'];
$json=$db->get_val('pages', $a, 'json');
$massiv=$db->from_j($db-> clear_json($json));
$massiv['main_img']=$tmp_name;
$json=$db->to_j($massiv);
$db->free_sql( "UPDATE `pages` SET `json` = '" . $json . "' WHERE `id` = " . $_POST['id'] );
echo $tmp_name;
break;
*/
default:
}
?>