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

Last change on this file since 26298 was 26298, checked in by mistic100, 10 years ago

update for 2.6 + better calculation + option to force ratio
TODO: issue with PNG (unable to generate thumbnail with IM)

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