source: extensions/GDThumb/main.inc.php @ 30319

Last change on this file since 30319 was 30225, checked in by SergeD, 10 years ago

GDThumb 1.0.12

File size: 4.3 KB
Line 
1<?php
2/*
3Plugin Name: gdThumb
4Version: 1.0.12
5Description: Display thumbnails as patchwork
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=771
7Author: Serge Dosyukov
8Author URI: http://blog.dragonsoft.us
9*/
10// Original work by P@t - GTHumb+
11
12global $conf;
13
14if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
15
16if (mobile_theme()) return;
17
18// +-----------------------------------------------------------------------+
19// | Plugin constants                                               |
20// +-----------------------------------------------------------------------+
21define('GDTHUMB_VERSION', '1.0.12');
22define('GDTHUMB_ID',      basename(dirname(__FILE__)));
23define('GDTHEME_PATH' ,   PHPWG_THEMES_PATH . 'greydragon/');
24define('GDTHUMB_PATH' ,   PHPWG_PLUGINS_PATH . GDTHUMB_ID . '/');
25
26if (!isset($conf['gdThumb'])):
27  include(dirname(__FILE__).'/config_default.inc.php');
28
29  $query = '
30INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
31VALUES ("gdThumb" , "'.addslashes(serialize($config_default)).'" , "GDThumb plugin parameters");';
32  pwg_query($query);
33  load_conf_from_db();
34endif;
35
36$conf['gdThumb'] = unserialize($conf['gdThumb']);
37
38// RV Thumbnails Scroller
39if (isset($_GET['rvts'])):
40  $conf['gdThumb']['big_thumb'] = false;
41  add_event_handler('loc_end_index_thumbnails', 'process_GDThumb', 50, 2);
42endif;
43
44add_event_handler('init', 'GDThumb_init');
45add_event_handler('loc_begin_index', 'GDThumb_index', 60);
46add_event_handler('loc_end_index_category_thumbnails', 'GDThumb_process_category', 50, 2);
47add_event_handler('get_admin_plugin_menu_links', 'GDThumb_admin_menu');
48add_event_handler('loc_end_index', 'GDThumb_remove_thumb_size');
49
50function GDThumb_init() {
51  global $conf, $user, $page, $stripped;
52
53  $confTemp = $conf['gdThumb'];
54  $user['nb_image_page']    = $confTemp['nb_image_page'];
55  $page['nb_image_page']    = $confTemp['nb_image_page'];
56  $stripped['maxThumb']     = $confTemp['nb_image_page'];
57}
58
59function GDThumb_index() {
60  global $template;
61 
62  $template->set_prefilter('index', 'GDThumb_prefilter');
63
64  add_event_handler('loc_end_index_thumbnails', 'GDThumb_process_thumb', 50, 2);
65}
66
67function GDThumb_process_thumb($tpl_vars, $pictures) {
68  global $template, $conf;
69  $confTemp = $conf['gdThumb'];
70  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
71  $confTemp['big_thumb_noinpw'] = (isset($confTemp['big_thumb_noinpw']) && ($confTemp['big_thumb_noinpw']))? 1 : 0;
72
73  $template->set_filename( 'index_thumbnails', dirname(__FILE__) . '/template/gdthumb_thumb.tpl');
74  $template->assign('GDThumb', $confTemp);
75  $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
76
77  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
78    $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
79    $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
80  endif;
81
82  return $tpl_vars;
83}
84
85function GDThumb_process_category($tpl_vars) {
86
87  global $template, $conf;
88  $confTemp = $conf['gdThumb'];
89  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
90  $confTemp['big_thumb_noinpw'] = isset($confTemp['big_thumb_noinpw'])? 1 : 0;
91
92  $template->set_filename( 'index_category_thumbnails', dirname(__FILE__) . '/template/gdthumb_cat.tpl');
93  $template->assign('GDThumb', $confTemp);
94  $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
95
96  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
97    $id = $tpl_vars[0]["representative_picture_id"];
98    if (($id) && ($rep = $tpl_vars[0]["representative"])):
99      $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
100      $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $rep['src_image']));
101    endif;
102  endif;
103
104  return $tpl_vars;
105}
106
107function GDThumb_prefilter($content, $smarty) {
108  $pattern = '#\<div.*?id\="thumbnails".*?\>\{\$THUMBNAILS\}\</div\>#';
109  $replacement = '<ul id="thumbnails">{$THUMBNAILS}</ul>';
110
111  return preg_replace($pattern, $replacement, $content);
112}
113
114function GDThumb_admin_menu($menu) {
115  array_push($menu,
116    array(
117      'NAME' => 'gdThumb',
118      'URL' => get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)),
119    )
120  );
121  return $menu;
122}
123
124function GDThumb_remove_thumb_size() {
125  global $template;
126  $template->clear_assign('image_derivatives');
127}
128
129?>
Note: See TracBrowser for help on using the repository browser.