[12409] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | $service = &$arr[0]; |
---|
| 7 | $service->addMethod('pwg.image.rotate', 'ws_image_rotate', |
---|
| 8 | array( |
---|
| 9 | 'image_id'=>array(), |
---|
| 10 | 'angle'=>array('default'=>"90"), |
---|
[12417] | 11 | 'pwg_token' => array(), |
---|
| 12 | 'rotate_hd' => array('default'=>0) |
---|
[12409] | 13 | ), |
---|
| 14 | 'Rotates a given image' |
---|
| 15 | ); |
---|
| 16 | |
---|
| 17 | function ws_image_rotate($params, &$service) |
---|
| 18 | { |
---|
| 19 | if (!is_admin()) |
---|
| 20 | { |
---|
| 21 | return new PwgError(401, 'Access denied'); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | if (empty($params['image_id'])) |
---|
| 25 | { |
---|
| 26 | return new PwgError(403, "image_id or image_path is missing"); |
---|
| 27 | } |
---|
| 28 | |
---|
[12417] | 29 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
---|
| 30 | { |
---|
| 31 | return new PwgError(403, 'Invalid security token'); |
---|
| 32 | } |
---|
| 33 | |
---|
[12409] | 34 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
| 35 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
| 36 | $image_id=(int)$params['image_id']; |
---|
| 37 | $angle=(int)$params['angle']; |
---|
[12417] | 38 | $rotate_hd = (int) $params['rotate_hd']; |
---|
[12409] | 39 | $query=' |
---|
| 40 | SELECT id, path, tn_ext, has_high |
---|
| 41 | FROM '.IMAGES_TABLE.' |
---|
| 42 | WHERE id = '.$image_id.' |
---|
| 43 | ;'; |
---|
| 44 | $image = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 45 | if ($image == null) |
---|
| 46 | { |
---|
| 47 | return new PwgError(403, "image_id not found"); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | $image_path = $image['path']; |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | $thumb_path = get_thumbnail_path($image); |
---|
| 54 | |
---|
| 55 | $img = new pwg_image($image_path); |
---|
| 56 | $img->rotate($angle); |
---|
| 57 | $img->write($image_path); |
---|
| 58 | update_metadata(array($image_id=>$image_path)); |
---|
[12417] | 59 | if ($rotate_hd) { |
---|
| 60 | $sizes = array('thumb','high'); |
---|
| 61 | } else { |
---|
| 62 | $sizes = array('thumb'); |
---|
| 63 | } |
---|
[12409] | 64 | |
---|
[12417] | 65 | foreach ($sizes as $size) { |
---|
[12409] | 66 | $resized_path = file_path_for_type($image_path,$size); |
---|
| 67 | if (file_exists($resized_path)) { |
---|
| 68 | $resized = new pwg_image($resized_path); |
---|
| 69 | $resized->rotate($angle); |
---|
| 70 | $resized->write($resized_path); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | return true; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | ?> |
---|