source: extensions/thumbCropper/main.inc.php @ 21584

Last change on this file since 21584 was 12501, checked in by Dsls, 13 years ago

Thumb Cropper v0.4 commit

File size: 2.0 KB
RevLine 
[12501]1<?php
2/*
3Plugin Name: Thumb Cropper
4Version: 0.4
5Description: enables to customize image thumbnails
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=581
7*/
8if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
9include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
10include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
11
12add_event_handler('ws_add_methods', 'add_tc_method');
13add_event_handler('loc_begin_admin', 'tc_init_prefilter', 50); 
14
15function add_tc_method($arr) {
16  include_once('ws_functions.inc.php');
17}
18
19function tc_init_prefilter() {
20  global $template;
21  global $row,$conf;
22 
23  if (script_basename() != 'admin')
24    return;
25  if (isset($_GET['image_id'])) {
26    $query = '
27    SELECT *
28      FROM '.IMAGES_TABLE.'
29      WHERE id = '.$_GET['image_id'].'
30    ;';
31    $row = pwg_db_fetch_assoc(pwg_query($query));
32    $thumb_data = array(
33      'x1' => 0,
34      'y1' => 0,
35      'x2' => $row['width'],
36      'y2' => $row['height'],
37      'width' => $conf['upload_form_thumb_maxwidth'],
38      'height' => $conf['upload_form_thumb_maxheight'],
39    );
40   
41    $template->assign(array(
42      'IMG_SRC' => get_image_url($row),
43      'IMG_WIDTH' => $row['width'],
44      'IMG_HEIGHT' => $row['height'],
45      'IMG_ID' => $_GET['image_id'],
46      'thumb_data' => $thumb_data,
47      'TC_PWG_TOKEN' => get_pwg_token()
48    ));
49    $template->set_prefilter('picture_modify','tc_prefilter');
50    load_language('plugin.lang', dirname(__FILE__).'/');
51  }
52}
53
54function tc_prefilter($content,&$smarty) {
55
56  $pattern = '#(<ul class="categoryActions">.*?)</ul>#s';
57
58  $replacement = '$1'.
59    '<li><a href="#thumbcropper" class="cbinline" title="{\'Edit thumbnail\'|@translate}">'.
60    '<img src="plugins/thumbCropper/thumbcropper.png" alt="{\'Edit thumbnail\'|@translate}">'.
61    '</a></li></ul>'.
62    '{include file="'.str_replace("\\","/",(dirname(__FILE__))).'/thumbcropper.tpl"}';
63   
64  return preg_replace($pattern, $replacement, $content);
65}
66
67?>
Note: See TracBrowser for help on using the repository browser.