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

Last change on this file since 31810 was 26925, checked in by plg, 10 years ago

compatibility with Piwigo 2.6 (jQuery 1.10)

bug fixed: correctly load language for "Rotate" photo edition tab

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;
19
20  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
21
22  $angles = array (
23    array('value' => 270, 'name' => l10n('90° right')),
24    array('value' =>  90, 'name' => l10n('90° left')),
25    array('value' => 180, 'name' => l10n('180°'))
26  );
27 
28  $template->assign(array(
29    'RI_PWG_TOKEN' => get_pwg_token(),
30    'angles' => $angles,
31    'angle_value' => 90,
32    'library' => pwg_image::get_library()
33  ));
34  $template->set_filename('rotate_image', realpath(dirname(__FILE__).'/rotate_image.tpl'));
35  $template->append('element_set_global_plugins_actions', array(
36    'ID' => 'rotateImg',
37    'NAME' => l10n('Rotate images'),
38    'CONTENT' => $template->parse('rotate_image', true))
39  );
40}
41
42add_event_handler('element_set_global_action', 'rotate_image_element_action', 50, 2);
43function rotate_image_element_action($action, $collection) {
44  if ($action == 'rotateImg') {
45    add_event_handler('get_derivative_url', 'rotate_image_force_refresh', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
46  }
47}
48
49function rotate_image_force_refresh($root_url, $params, $src_image, $rel_url)
50{
51  global $collection;
52
53  if (in_array($src_image->id, $collection))
54  {
55    if (strpos($root_url, '?') === false)
56    {
57      $root_url.= '?';
58    }
59    else
60    {
61      $root_url.= '&amp;';
62    }
63
64    $root_url.= 'rand='.md5(uniqid(rand(), true));
65  }
66
67  return $root_url;
68}
69
70add_event_handler('tabsheet_before_select','rotate_image_add_tab', 50, 2);
71function rotate_image_add_tab($sheets, $id)
72{
73  load_language('plugin.lang', dirname(__FILE__).'/');
74 
75  if ($id == 'photo')
76  {
77    $sheets['rotate'] = array(
78      'caption' => l10n('Rotate'),
79      'url' => get_root_url().'admin.php?page=plugin-rotateImage-'.$_GET['image_id'],
80      );
81  }
82 
83  return $sheets;
84}
85?>
Note: See TracBrowser for help on using the repository browser.