-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.php
100 lines (90 loc) · 2.94 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
*
* @category modules
* @package minigallery v2.5
* @author Dev4me / Ruud Eisinga
* @link http://www.allwww.nl/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WebsiteBaker 2.8.x
* @requirements PHP 5.6 and higher
* @version 2.5.1
* @lastmodified March 28, 2018
*
*/
require('../../config.php');
require(dirname(__FILE__).'/info.php');
require(dirname(__FILE__).'/functions.php') ;
require_once(WB_PATH.'/framework/class.admin.php');
$admin = new admin('Modules', 'module_view', false, false);
if (!($admin->is_authenticated() || !$admin->get_permission("minigal2", 'module'))) {
die("Go away");
}
$basedir = WB_PATH.MEDIA_DIRECTORY.'/'.$image_path.'/';
$baseurl = WB_URL.MEDIA_DIRECTORY.'/'.$image_path.'/';
if(isset($_POST['section_id']) && is_numeric($_POST['section_id'])) {
$section_id = (int)$_POST['section_id'];
$curdir = $section_id."/";
$pathToFolder = $basedir.$section_id.'/';
$thumbFolder = $pathToFolder.'thumbs/';
make_dir($basedir);
make_dir($pathToFolder);
make_dir($thumbFolder);
$overwrite = true;
} else {
die();
}
if(isAjax()) {
if(isset($_POST['function'])) {
$f = $_POST['function'];
if($f == 'upload') {
$get_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_minigal2 WHERE section_id = '$section_id'");
$settings = $get_settings->fetchRow();
$maxsize = $settings['maxsize'];
$maxheight = $settings['maxheight'];
$thumbsize = $settings['thumbsize'];
$ratio = $settings['ratio'];
$thumbheight = $thumbsize;
if(!$ratio) {
$thumbsize = 100000; // set width to high value, we want only the height
}
$message = "";
minigallery_save_upload ( 'file', $maxsize , $maxheight, $thumbsize, $thumbheight, $ratio, $pathToFolder, $thumbFolder, $overwrite, $message ) ;
die ($message);
}
if($f == 'reload') {
$i = getMiniGalleryImageList($basedir,$curdir,$baseurl,$section_id);
die($i);
}
if($f == 'delete') {
$filename = $_POST['file'];
if(file_exists($pathToFolder.$filename)) unlink($pathToFolder.$filename);
if(file_exists($thumbFolder.$filename)) unlink($thumbFolder.$filename);
die("ok");
}
if($f == 'deleteall') {
make_dir($basedir);
rm_full_dir($thumbFolder);
rm_full_dir($pathToFolder);
make_dir($pathToFolder);
make_dir($thumbFolder);
die("");
}
if($f == 'caption' ) {
$filename = $database->escapeString($_POST['file']);
$caption = $database->escapeString($_POST['caption']);
minigallery_save_caption ( $section_id, $filename , $caption );
$i = getMiniGalleryImageList($basedir,$curdir,$baseurl,$section_id);
die($i);
}
if($f == 'sort' ) {
$sorting = $database->escapeString(implode('|',$_POST['arr']));
minigallery_save_sorting ( $section_id, $sorting );
die();
}
}
}
function isAjax() {
$isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
return $isAjax;
}