[22939] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Crop Image |
---|
| 4 | Version: 2.5.d |
---|
| 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 | load_language('plugin.lang', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 41 | |
---|
| 42 | // cancel crop |
---|
| 43 | if (isset($_POST['cancel_crop'])) |
---|
| 44 | { |
---|
| 45 | redirect($admin_photo_base_url); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // apply crop and redirect |
---|
| 49 | else if (isset($_POST['submit_crop'])) |
---|
| 50 | { |
---|
| 51 | include_once(dirname(__FILE__).'/crop.class.php'); |
---|
| 52 | |
---|
| 53 | $CropImg = get_file_to_crop($_POST['picture_file']); |
---|
| 54 | $img = new crop_image($CropImg['PATH']); |
---|
| 55 | list($width, $height) = getimagesize($CropImg['PATH']); |
---|
| 56 | $img->cropimage_resize( |
---|
| 57 | $CropImg['PATH'], |
---|
| 58 | $_POST['x'], |
---|
| 59 | $_POST['y'], |
---|
| 60 | $_POST['x2'], |
---|
| 61 | $_POST['y2'], |
---|
| 62 | $_POST['w'], |
---|
| 63 | $_POST['h'] |
---|
| 64 | ); |
---|
| 65 | $img->destroy(); |
---|
| 66 | |
---|
| 67 | $query=' |
---|
| 68 | SELECT |
---|
| 69 | id, |
---|
| 70 | path, |
---|
| 71 | representative_ext |
---|
| 72 | FROM '.IMAGES_TABLE.' |
---|
| 73 | WHERE id = '.(int)$_POST['image_id'].' |
---|
| 74 | ;'; |
---|
| 75 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 76 | if ($row == null) |
---|
| 77 | { |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | sync_metadata(array($row['id'])); |
---|
| 82 | |
---|
| 83 | $query = 'UPDATE '.IMAGES_TABLE .' |
---|
| 84 | SET coi=NULL |
---|
| 85 | WHERE id='.$row['id']; |
---|
| 86 | pwg_query($query); |
---|
| 87 | |
---|
| 88 | delete_element_derivatives($row); |
---|
| 89 | |
---|
[22941] | 90 | $_SESSION['page_infos'][] = l10n('Photo Cropped'); |
---|
[22939] | 91 | redirect($admin_photo_base_url); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // +-----------------------------------------------------------------------+ |
---|
| 95 | // | Tabs | |
---|
| 96 | // +-----------------------------------------------------------------------+ |
---|
| 97 | |
---|
| 98 | $tabsheet = new tabsheet(); |
---|
| 99 | $tabsheet->set_id('photo'); |
---|
| 100 | $tabsheet->select('crop'); |
---|
| 101 | $tabsheet->assign(); |
---|
| 102 | |
---|
| 103 | // +-----------------------------------------------------------------------+ |
---|
| 104 | // | template init | |
---|
| 105 | // +-----------------------------------------------------------------------+ |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | $template->set_filenames( |
---|
| 109 | array( |
---|
| 110 | 'plugin_admin_content' => dirname(__FILE__).'/crop_image.tpl' |
---|
| 111 | ) |
---|
| 112 | ); |
---|
| 113 | |
---|
| 114 | // get picture from gallery |
---|
| 115 | if (isset($_GET['image_id'])) |
---|
| 116 | { |
---|
| 117 | $query = ' |
---|
| 118 | SELECT |
---|
| 119 | file, |
---|
| 120 | path, |
---|
| 121 | coi, |
---|
| 122 | width, |
---|
| 123 | height, |
---|
| 124 | name |
---|
| 125 | FROM '.IMAGES_TABLE.' |
---|
| 126 | WHERE id = '. (int)@$_GET['image_id'] .' |
---|
| 127 | ;'; |
---|
| 128 | $result = pwg_query($query); |
---|
| 129 | |
---|
| 130 | if (!pwg_db_num_rows($result)) |
---|
| 131 | { |
---|
[22941] | 132 | array_push($page['errors'], l10n('Unknown Photo ID')); |
---|
[22939] | 133 | } |
---|
| 134 | else |
---|
| 135 | { |
---|
| 136 | $picture = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 137 | $picture['filename'] = basename($picture['path']); |
---|
| 138 | |
---|
| 139 | $picture['banner_src'] = PHPWG_ROOT_PATH . $picture['path']; |
---|
| 140 | |
---|
[24055] | 141 | list($RatioWidth, $RatioHeight) = getimagesize($picture['path']); |
---|
| 142 | |
---|
[22939] | 143 | $template->assign(array( |
---|
| 144 | 'TITLE' => render_element_name($picture), |
---|
| 145 | 'IN_CROP' => true, |
---|
| 146 | 'picture' => $picture, |
---|
| 147 | 'crop' => get_crop_display($picture), |
---|
| 148 | 'image_id' => (int)@$_GET['image_id'], |
---|
[24055] | 149 | 'image_ratio' => $RatioWidth/$RatioHeight, |
---|
[22939] | 150 | )); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // +-----------------------------------------------------------------------+ |
---|
| 155 | // | sending html code | |
---|
| 156 | // +-----------------------------------------------------------------------+ |
---|
| 157 | |
---|
| 158 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 159 | ?> |
---|