1 | <?php |
---|
2 | defined('HEADER_MANAGER_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | // cancel crop |
---|
5 | if (isset($_POST['cancel_crop'])) |
---|
6 | { |
---|
7 | $banner = get_banner($_POST['picture_file']); |
---|
8 | @unlink($banner['PATH']); |
---|
9 | @unlink($banner['THUMB']); |
---|
10 | } |
---|
11 | // apply crop and redirect |
---|
12 | else if (isset($_POST['submit_crop'])) |
---|
13 | { |
---|
14 | include_once(HEADER_MANAGER_PATH . 'include/banner.class.php'); |
---|
15 | |
---|
16 | $conf['header_manager']['keep_ratio'] = isset($_POST['keep_ratio']); |
---|
17 | conf_update_param('header_manager', serialize($conf['header_manager'])); |
---|
18 | |
---|
19 | $banner = get_banner($_POST['picture_file']); |
---|
20 | |
---|
21 | $img = new banner_image($banner['PATH']); |
---|
22 | $img->banner_resize( |
---|
23 | $banner['PATH'], |
---|
24 | $_POST |
---|
25 | ); |
---|
26 | $img->destroy(); |
---|
27 | |
---|
28 | $img = new pwg_image($banner['PATH']); |
---|
29 | $img->pwg_resize( |
---|
30 | $banner['THUMB'], |
---|
31 | 230, 70, 80, |
---|
32 | false, true, true, false |
---|
33 | ); |
---|
34 | $img->destroy(); |
---|
35 | |
---|
36 | $_SESSION['page_infos'][] = l10n('Banner added'); |
---|
37 | pwg_set_session_var('added_banner', $_POST['picture_file']); |
---|
38 | |
---|
39 | if (!empty($_GET['redirect'])) |
---|
40 | { |
---|
41 | redirect($_GET['redirect']); |
---|
42 | } |
---|
43 | else |
---|
44 | { |
---|
45 | redirect(HEADER_MANAGER_ADMIN); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | // copy picture from gallery |
---|
50 | if (isset($_POST['upload_gallery_image'])) |
---|
51 | { |
---|
52 | $query = ' |
---|
53 | SELECT |
---|
54 | file, |
---|
55 | path, |
---|
56 | coi, |
---|
57 | width, |
---|
58 | height |
---|
59 | FROM '.IMAGES_TABLE.' |
---|
60 | WHERE id = '. (int)@$_POST['picture_id'] .' |
---|
61 | ;'; |
---|
62 | $result = pwg_query($query); |
---|
63 | |
---|
64 | if (!pwg_db_num_rows($result)) |
---|
65 | { |
---|
66 | $page['errors'][] = l10n('Unknown picture id'); |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | $picture = pwg_db_fetch_assoc($result); |
---|
71 | $picture['filename'] = basename($picture['path']); |
---|
72 | |
---|
73 | copy(PHPWG_ROOT_PATH . $picture['path'], HEADER_MANAGER_DIR . $picture['filename']); |
---|
74 | |
---|
75 | define('IN_CROP', true); |
---|
76 | } |
---|
77 | } |
---|
78 | // upload new picture |
---|
79 | else if (isset($_POST['upload_new_image'])) |
---|
80 | { |
---|
81 | $file = $_FILES['new_image']; |
---|
82 | |
---|
83 | if ($file['error'] > 0) |
---|
84 | { |
---|
85 | $page['errors'][] = l10n('Unknown upload error'); |
---|
86 | } |
---|
87 | else if (!in_array($file['type'], array('image/jpeg','image/png','image/gif'))) |
---|
88 | { |
---|
89 | $page['errors'][] = l10n('Incorrect file type,').' '.l10n('Allowed file types: %s.', 'jpg, png, gif'); |
---|
90 | } |
---|
91 | |
---|
92 | if (count($page['errors']) == 0) |
---|
93 | { |
---|
94 | $file['filename'] = date('Ymd').'-'.uniqid().'.'.get_extension($file['name']); |
---|
95 | move_uploaded_file($file['tmp_name'], HEADER_MANAGER_DIR . $file['filename']); |
---|
96 | |
---|
97 | list($width, $height) = getimagesize(HEADER_MANAGER_DIR . $file['filename']); |
---|
98 | $picture = array( |
---|
99 | 'file' => $file['name'], |
---|
100 | 'filename' => $file['filename'], |
---|
101 | 'width' => $width, |
---|
102 | 'height' => $height, |
---|
103 | ); |
---|
104 | |
---|
105 | define('IN_CROP', true); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | // croping template |
---|
110 | if (defined('IN_CROP')) |
---|
111 | { |
---|
112 | // save default size configuration |
---|
113 | $conf['header_manager']['width'] = intval($_POST['width']); |
---|
114 | $conf['header_manager']['height'] = intval($_POST['height']); |
---|
115 | conf_update_param('header_manager', serialize($conf['header_manager'])); |
---|
116 | |
---|
117 | $picture['banner_src'] = HEADER_MANAGER_DIR . $picture['filename']; |
---|
118 | |
---|
119 | $template->assign(array( |
---|
120 | 'IN_CROP' => true, |
---|
121 | 'picture' => $picture, |
---|
122 | 'crop' => hm_get_crop_display($picture), |
---|
123 | 'keep_ratio' => $conf['header_manager']['keep_ratio'], |
---|
124 | )); |
---|
125 | } |
---|
126 | // upload form |
---|
127 | else |
---|
128 | { |
---|
129 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
130 | |
---|
131 | $upload_max_filesize = min( |
---|
132 | get_ini_size('upload_max_filesize'), |
---|
133 | get_ini_size('post_max_size') |
---|
134 | ); |
---|
135 | |
---|
136 | $upload_max_filesize_shorthand = |
---|
137 | ($upload_max_filesize == get_ini_size('upload_max_filesize')) ? |
---|
138 | get_ini_size('upload_max_filesize', false) : |
---|
139 | get_ini_size('post_max_filesize', false); |
---|
140 | |
---|
141 | $template->assign(array( |
---|
142 | 'upload_max_filesize' => $upload_max_filesize, |
---|
143 | 'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand, |
---|
144 | 'BANNER_WIDTH' => $conf['header_manager']['width'], |
---|
145 | 'BANNER_HEIGHT' => $conf['header_manager']['height'], |
---|
146 | )); |
---|
147 | } |
---|
148 | |
---|
149 | $template->assign('F_ACTION', HEADER_MANAGER_ADMIN . '-add' . |
---|
150 | (!empty($_GET['redirect']) ? '&redirect='.urlencode($_GET['redirect']) : '')); |
---|
151 | |
---|
152 | $template->set_filename('header_manager', realpath(HEADER_MANAGER_PATH . 'admin/template/add.tpl')); |
---|