[22856] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Crop Image |
---|
[22977] | 4 | Version: auto |
---|
[22856] | 5 | Description: Enables to Crop Images already uploaded to the gallery, basic functionality. Tested with v2.5.1, v2.4.6 |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=700 |
---|
| 7 | Author: Chillexistence |
---|
| 8 | Author URI: http://piwigo.org |
---|
| 9 | */ |
---|
| 10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 11 | define('CROPIMAGE_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__))); |
---|
| 12 | defined('CROPIMAGE_ID') or define('CROPIMAGE_ID', basename(dirname(__FILE__))); |
---|
| 13 | define('CROPIMAGE_ADMIN', get_root_url() . 'admin.php?page=plugin-' . CROPIMAGE_ID); |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | add_event_handler('init', 'cropImage_init' ); |
---|
| 17 | add_event_handler('tabsheet_before_select','crop_image_add_tab', 50, 2); |
---|
| 18 | |
---|
| 19 | function crop_image_add_tab($sheets, $id) |
---|
| 20 | { |
---|
[22939] | 21 | global $lang; |
---|
| 22 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 23 | |
---|
[22856] | 24 | $image_id = isset($_GET['image_id'])? $_GET['image_id'] : ''; |
---|
| 25 | |
---|
| 26 | if ($id == 'photo') |
---|
| 27 | { |
---|
| 28 | $sheets['crop'] = array( |
---|
| 29 | 'caption' => l10n('Crop'), |
---|
[22977] | 30 | 'url' => CROPIMAGE_ADMIN.'-'.$image_id, |
---|
[22856] | 31 | ); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | return $sheets; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | function 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 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 50 | function cropImage_set_prefilter_add_to_pic_info() |
---|
| 51 | { |
---|
[22939] | 52 | global $template, $conf, $user, $page, $lang; |
---|
| 53 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
[22856] | 54 | |
---|
| 55 | $url_admin = |
---|
| 56 | CROPIMAGE_ADMIN.'-'.$page['image_id'] |
---|
| 57 | .(isset($page['category']) ? '&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 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 95 | function 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 = ' |
---|
[22941] | 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> |
---|
[22856] | 103 | </a> |
---|
| 104 | ' . $search; |
---|
| 105 | |
---|
| 106 | return str_replace($search, $replacement, $content); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | ?> |
---|