source: extensions/header_manager/admin/add.php @ 15958

Last change on this file since 15958 was 15958, checked in by mistic100, 12 years ago

generate a uniq name for upload banners, instead of keeping original name

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