source: extensions/rotateImage/main.inc.php @ 26466

Last change on this file since 26466 was 16981, checked in by plg, 12 years ago

Insert a new tab "Rotate" on the photo administration screen (requires Piwigo 2.4.2)

File size: 2.2 KB
Line 
1<?php
2/*
3Plugin Name: Rotate Image
4Version: auto
5Description: enables to rotate images in batch processing
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=578
7*/
8if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
9
10add_event_handler('ws_add_methods', 'add_image_rotate_method');
11function add_image_rotate_method($arr)
12{
13 include_once('ws_functions.inc.php');
14}
15
16add_event_handler('loc_begin_element_set_global', 'rotate_image_set_template_data');
17function rotate_image_set_template_data() {
18  global $template,$lang;
19  load_language('plugin.lang', dirname(__FILE__).'/');
20
21  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
22
23  $angles = array (
24    array('value' => 270, 'name' => l10n('90° right')),
25    array('value' =>  90, 'name' => l10n('90° left')),
26    array('value' => 180, 'name' => l10n('180°'))
27  );
28 
29  $template->assign(array(
30    'RI_PWG_TOKEN' => get_pwg_token(),
31    'angles' => $angles,
32    'angle_value' => 90,
33    'library' => pwg_image::get_library()
34  ));
35  $template->set_filename('rotate_image', realpath(dirname(__FILE__).'/rotate_image.tpl'));
36  $template->append('element_set_global_plugins_actions', array(
37    'ID' => 'rotateImg',
38    'NAME' => l10n('Rotate images'),
39    'CONTENT' => $template->parse('rotate_image', true))
40  );
41}
42
43add_event_handler('element_set_global_action', 'rotate_image_element_action', 50, 2);
44function rotate_image_element_action($action, $collection) {
45  if ($action == 'rotateImg') {
46    add_event_handler('get_derivative_url', 'rotate_image_force_refresh', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
47  }
48}
49
50function rotate_image_force_refresh($root_url, $params, $src_image, $rel_url)
51{
52  global $collection;
53
54  if (in_array($src_image->id, $collection))
55  {
56    if (strpos($root_url, '?') === false)
57    {
58      $root_url.= '?';
59    }
60    else
61    {
62      $root_url.= '&amp;';
63    }
64
65    $root_url.= 'rand='.md5(uniqid(rand(), true));
66  }
67
68  return $root_url;
69}
70
71add_event_handler('tabsheet_before_select','rotate_image_add_tab', 50, 2);
72function rotate_image_add_tab($sheets, $id)
73{ 
74  if ($id == 'photo')
75  {
76    $sheets['rotate'] = array(
77      'caption' => l10n('Rotate'),
78      'url' => get_root_url().'admin.php?page=plugin-rotateImage-'.$_GET['image_id'],
79      );
80  }
81 
82  return $sheets;
83}
84?>
Note: See TracBrowser for help on using the repository browser.