source: extensions/Crop_Image/main.inc.php @ 31930

Last change on this file since 31930 was 22977, checked in by Chillexistence, 11 years ago

Removed get_root_url() from $sheets URL since this was there twice, and changed version to auto.

File size: 3.3 KB
Line 
1<?php
2/*
3Plugin Name: Crop Image
4Version: auto
5Description: Enables to Crop Images already uploaded to the gallery, basic functionality.  Tested with v2.5.1, v2.4.6
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=700
7Author: Chillexistence
8Author URI: http://piwigo.org
9*/
10if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
11define('CROPIMAGE_PATH',    PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)));
12defined('CROPIMAGE_ID') or define('CROPIMAGE_ID', basename(dirname(__FILE__)));
13define('CROPIMAGE_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . CROPIMAGE_ID);
14
15
16add_event_handler('init', 'cropImage_init' );
17add_event_handler('tabsheet_before_select','crop_image_add_tab', 50, 2);
18
19function crop_image_add_tab($sheets, $id)
20{ 
21        global $lang;
22        load_language('plugin.lang', dirname(__FILE__).'/');
23         
24        $image_id = isset($_GET['image_id'])? $_GET['image_id'] : '';
25 
26        if ($id == 'photo')
27  {
28    $sheets['crop'] = array(
29      'caption' => l10n('Crop'),
30      'url' => CROPIMAGE_ADMIN.'-'.$image_id,
31      );
32  }
33 
34  return $sheets;
35}
36               
37function cropImage_init()
38{
39  global $conf, $pwg_loaded_plugins;           
40  if (!defined('PWG_HELP') and !defined('IN_ADMIN') and is_admin())
41  {
42                // Add an event handler for a prefilter on picture.php pages
43                add_event_handler('loc_begin_picture', 'cropImage_set_prefilter_add_to_pic_info', 55 );
44        }
45}       
46       
47////////////////////////////////////////////////////////////////////////////////
48// Add the prefilter for the Crop Link on the template on picture.php
49////////////////////////////////////////////////////////////////////////////////
50function cropImage_set_prefilter_add_to_pic_info()
51{
52        global $template, $conf, $user, $page, $lang;
53        load_language('plugin.lang', dirname(__FILE__).'/');
54       
55        $url_admin =
56    CROPIMAGE_ADMIN.'-'.$page['image_id']
57    .(isset($page['category']) ? '&amp;cat_id='.$page['category']['id'] : '')
58    ;
59        $template->set_prefilter('picture', 'cropImage_add_button');
60       
61        $template->func_combine_css(array('path' => CROPIMAGE_PATH.'/css/cropimage_toolbar_buttons.css'));
62       
63        //Get the Theme to display the correct icon style
64        if ( in_array($user['theme'], array('Sylvia','sylvia')) )
65        {
66                 $ButtonTheme = "sylvia";
67        }
68        elseif ( in_array($user['theme'], array('elegant')) )
69        {
70                 $ButtonTheme = "elegant";
71        }
72        elseif ( in_array($user['theme'], array('clear')) )
73        {
74                 $ButtonTheme = "clear";
75        }
76        elseif ( in_array($user['theme'], array('dark')) )
77        {
78                 $ButtonTheme = "dark";
79        }
80        else
81        {
82                 $ButtonTheme = "clear";
83        }
84       
85        $template->assign(
86    array(
87      'U_CROPIMAGE' => $url_admin,
88                        'U_CROPIMAGE_THEME' => $ButtonTheme,
89      )
90    );
91}       
92////////////////////////////////////////////////////////////////////////////////
93// Insert the template for the Crop Link on picture.php
94////////////////////////////////////////////////////////////////////////////////
95function cropImage_add_button($content)
96{
97        // Add the information after imageInfoTable so before everything else like author and date.
98        $search = '{strip}{if isset($U_CADDIE)}{*caddie management BEGIN*}';
99       
100        $replacement = '
101        <a class="pwg-state-default pwg-button" href="{$U_CROPIMAGE}" title="{\'Crop Photo\'|@translate}" rel="nofollow">
102         <span class="ci-icon ci-icon-cropimage-{$U_CROPIMAGE_THEME}"> </span><span class="pwg-button-text">{\'Crop Photo\'|@translate}</span>
103  </a>
104        ' . $search;
105
106        return str_replace($search, $replacement, $content);
107}
108       
109?>
Note: See TracBrowser for help on using the repository browser.