1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Crop Image |
---|
4 | Version: 2.5.c |
---|
5 | Description: Enables to Crop Images already uploaded to the gallery, basic functionality. Tested with v2.5.1, v2.4.6 |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=700 |
---|
7 | Author: Chillexistence |
---|
8 | Author URI: http://piwigo.org |
---|
9 | */ |
---|
10 | |
---|
11 | if( !defined("CROPIMAGE_PATH") ) |
---|
12 | { |
---|
13 | die ("Hacking attempt!"); |
---|
14 | } |
---|
15 | |
---|
16 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
17 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
18 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
19 | include_once(dirname(__FILE__).'/functions.inc.php'); |
---|
20 | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | // | Check Access and exit when user status is not ok | |
---|
23 | // +-----------------------------------------------------------------------+ |
---|
24 | |
---|
25 | check_status(ACCESS_ADMINISTRATOR); |
---|
26 | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | Basic checks | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | |
---|
31 | $_GET['image_id'] = isset($_GET['tab']) ? $_GET['tab'] : ''; |
---|
32 | |
---|
33 | check_input_parameter('image_id', $_GET, false, PATTERN_ID); |
---|
34 | |
---|
35 | $admin_photo_base_url = get_root_url().'admin.php?page=photo-'.$_GET['image_id']; |
---|
36 | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | // | Process form | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | |
---|
41 | // cancel crop |
---|
42 | if (isset($_POST['cancel_crop'])) |
---|
43 | { |
---|
44 | redirect($admin_photo_base_url); |
---|
45 | } |
---|
46 | |
---|
47 | // apply crop and redirect |
---|
48 | else if (isset($_POST['submit_crop'])) |
---|
49 | { |
---|
50 | include_once(dirname(__FILE__).'/crop.class.php'); |
---|
51 | |
---|
52 | $CropImg = get_file_to_crop($_POST['picture_file']); |
---|
53 | $img = new crop_image($CropImg['PATH']); |
---|
54 | list($width, $height) = getimagesize($CropImg['PATH']); |
---|
55 | $img->cropimage_resize( |
---|
56 | $CropImg['PATH'], |
---|
57 | $_POST['x'], |
---|
58 | $_POST['y'], |
---|
59 | $_POST['x2'], |
---|
60 | $_POST['y2'], |
---|
61 | $_POST['w'], |
---|
62 | $_POST['h'] |
---|
63 | ); |
---|
64 | $img->destroy(); |
---|
65 | |
---|
66 | $query=' |
---|
67 | SELECT |
---|
68 | id, |
---|
69 | path, |
---|
70 | representative_ext |
---|
71 | FROM '.IMAGES_TABLE.' |
---|
72 | WHERE id = '.(int)$_POST['image_id'].' |
---|
73 | ;'; |
---|
74 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
75 | if ($row == null) |
---|
76 | { |
---|
77 | return false; |
---|
78 | } |
---|
79 | |
---|
80 | sync_metadata(array($row['id'])); |
---|
81 | |
---|
82 | //list($width, $height) = getimagesize($banner['PATH']); |
---|
83 | //$filesize = floor(filesize($banner['PATH'])/1024); |
---|
84 | |
---|
85 | $query = 'UPDATE '.IMAGES_TABLE .' |
---|
86 | SET coi=NULL |
---|
87 | WHERE id='.$row['id']; |
---|
88 | pwg_query($query); |
---|
89 | |
---|
90 | delete_element_derivatives($row); |
---|
91 | |
---|
92 | $_SESSION['page_infos'][] = l10n('Photo Cropped'); |
---|
93 | redirect($admin_photo_base_url); |
---|
94 | } |
---|
95 | |
---|
96 | // +-----------------------------------------------------------------------+ |
---|
97 | // | Tabs | |
---|
98 | // +-----------------------------------------------------------------------+ |
---|
99 | |
---|
100 | $tabsheet = new tabsheet(); |
---|
101 | $tabsheet->set_id('photo'); |
---|
102 | $tabsheet->select('crop'); |
---|
103 | $tabsheet->assign(); |
---|
104 | |
---|
105 | // +-----------------------------------------------------------------------+ |
---|
106 | // | template init | |
---|
107 | // +-----------------------------------------------------------------------+ |
---|
108 | |
---|
109 | $template->set_filenames( |
---|
110 | array( |
---|
111 | 'plugin_admin_content' => dirname(__FILE__).'/crop_image.tpl' |
---|
112 | ) |
---|
113 | ); |
---|
114 | |
---|
115 | // get picture from gallery |
---|
116 | if (isset($_GET['image_id'])) |
---|
117 | { |
---|
118 | $query = ' |
---|
119 | SELECT |
---|
120 | file, |
---|
121 | path, |
---|
122 | coi, |
---|
123 | width, |
---|
124 | height, |
---|
125 | name |
---|
126 | FROM '.IMAGES_TABLE.' |
---|
127 | WHERE id = '. (int)@$_GET['image_id'] .' |
---|
128 | ;'; |
---|
129 | $result = pwg_query($query); |
---|
130 | |
---|
131 | if (!pwg_db_num_rows($result)) |
---|
132 | { |
---|
133 | array_push($page['errors'], l10n('Unknown Photo ID')); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | $picture = pwg_db_fetch_assoc(pwg_query($query)); |
---|
138 | $picture['filename'] = basename($picture['path']); |
---|
139 | |
---|
140 | $picture['banner_src'] = PHPWG_ROOT_PATH . $picture['path']; |
---|
141 | |
---|
142 | $template->assign(array( |
---|
143 | 'TITLE' => render_element_name($picture), |
---|
144 | 'IN_CROP' => true, |
---|
145 | 'picture' => $picture, |
---|
146 | 'crop' => get_crop_display($picture), |
---|
147 | 'image_id' => (int)@$_GET['image_id'], |
---|
148 | )); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | // +-----------------------------------------------------------------------+ |
---|
153 | // | sending html code | |
---|
154 | // +-----------------------------------------------------------------------+ |
---|
155 | |
---|
156 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
157 | ?> |
---|