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

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

Fix Path to Plugin due to the directory name Piwigo assigned it.

File size: 3.2 KB
Line 
1<?php
2/*
3Plugin Name: Crop Image
4Version: 2.5.c
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        $image_id = isset($_GET['image_id'])? $_GET['image_id'] : '';
22 
23        if ($id == 'photo')
24  {
25    $sheets['crop'] = array(
26      'caption' => l10n('Crop'),
27      'url' => get_root_url().CROPIMAGE_ADMIN.'-'.$image_id,
28      );
29  }
30 
31  return $sheets;
32}
33               
34function cropImage_init()
35{
36  global $conf, $pwg_loaded_plugins;           
37  if (!defined('PWG_HELP') and !defined('IN_ADMIN') and is_admin())
38  {
39                // Add an event handler for a prefilter on picture.php pages
40                add_event_handler('loc_begin_picture', 'cropImage_set_prefilter_add_to_pic_info', 55 );
41        }
42}       
43       
44////////////////////////////////////////////////////////////////////////////////
45// Add the prefilter for the Crop Link on the template on picture.php
46////////////////////////////////////////////////////////////////////////////////
47function cropImage_set_prefilter_add_to_pic_info()
48{
49        global $template, $conf, $user, $page;
50       
51        $url_admin =
52    CROPIMAGE_ADMIN.'-'.$page['image_id']
53    .(isset($page['category']) ? '&amp;cat_id='.$page['category']['id'] : '')
54    ;
55        $template->set_prefilter('picture', 'cropImage_add_button');
56       
57        $template->func_combine_css(array('path' => CROPIMAGE_PATH.'/css/cropimage_toolbar_buttons.css'));
58       
59        //Get the Theme to display the correct icon style
60        if ( in_array($user['theme'], array('Sylvia','sylvia')) )
61        {
62                 $ButtonTheme = "sylvia";
63        }
64        elseif ( in_array($user['theme'], array('elegant')) )
65        {
66                 $ButtonTheme = "elegant";
67        }
68        elseif ( in_array($user['theme'], array('clear')) )
69        {
70                 $ButtonTheme = "clear";
71        }
72        elseif ( in_array($user['theme'], array('dark')) )
73        {
74                 $ButtonTheme = "dark";
75        }
76        else
77        {
78                 $ButtonTheme = "clear";
79        }
80       
81        $template->assign(
82    array(
83      'U_CROPIMAGE' => $url_admin,
84                        'U_CROPIMAGE_THEME' => $ButtonTheme,
85      )
86    );
87}       
88////////////////////////////////////////////////////////////////////////////////
89// Insert the template for the Crop Link on picture.php
90////////////////////////////////////////////////////////////////////////////////
91function cropImage_add_button($content)
92{
93        // Add the information after imageInfoTable so before everything else like author and date.
94        $search = '{strip}{if isset($U_CADDIE)}{*caddie management BEGIN*}';
95       
96        $replacement = '
97        <a class="pwg-state-default pwg-button" href="{$U_CROPIMAGE}" title="Crop Image" rel="nofollow">
98         <span class="ci-icon ci-icon-cropimage-{$U_CROPIMAGE_THEME}"> </span><span class="pwg-button-text">Crop Image</span>
99  </a>
100        ' . $search;
101
102        return str_replace($search, $replacement, $content);
103}
104       
105?>
Note: See TracBrowser for help on using the repository browser.