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

Last change on this file since 33105 was 32865, checked in by SergeD, 20 months ago

version 1.0.26 - see changelog for details

File size: 6.2 KB
Line 
1<?php
2/*
3Plugin Name: gdThumb
4Version: 1.0.26
5Description: Apply Masonry style to album or image thumbs
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=771
7Author: Serge Dosyukov
8Author URI: http://blog.dragonsoft.us
9Has Settings: true
10*/
11// Original work by P@t - GTHumb+
12
13global $conf;
14
15if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
16
17if (mobile_theme()) return;
18
19// +-----------------------------------------------------------------------+
20// | Plugin constants                                               |
21// +-----------------------------------------------------------------------+
22define('GDTHUMB_VERSION', '1.0.26');
23define('GDTHUMB_ID',      basename(dirname(__FILE__)));
24define('GDTHUMB_PATH' ,   PHPWG_PLUGINS_PATH . GDTHUMB_ID . '/');
25if (!defined('GDTHEME_PATH')):
26  define('GDTHEME_PATH' ,   PHPWG_THEMES_PATH . 'greydragon/');
27endif;
28
29if (!isset($conf['gdThumb'])):
30  include(dirname(__FILE__).'/config_default.inc.php');
31  conf_update_param('gdThumb', $config_default);
32  load_conf_from_db();
33endif;
34
35$conf['gdThumb'] = unserialize($conf['gdThumb']);
36
37// RV Thumbnails Scroller
38if (isset($_GET['rvts'])):
39  $conf['gdThumb']['big_thumb'] = false;
40  add_event_handler('loc_end_index_thumbnails', 'GDThumb_process_thumb', 50, 2);
41endif;
42
43add_event_handler('init', 'GDThumb_init');
44add_event_handler('loc_begin_index', 'GDThumb_index', 60);
45add_event_handler('loc_end_index_category_thumbnails', 'GDThumb_process_category', 50, 2);
46add_event_handler('get_admin_plugin_menu_links', 'GDThumb_admin_menu');
47add_event_handler('loc_end_index', 'GDThumb_remove_thumb_size');
48
49function GDThumb_init() {
50  global $conf, $user, $page, $stripped;
51
52  $confTemp = $conf['gdThumb'];
53  $user['nb_image_page']    = $confTemp['nb_image_page'];
54  $page['nb_image_page']    = $confTemp['nb_image_page'];
55  $stripped['maxThumb']     = $confTemp['nb_image_page'];
56}
57
58function GDThumb_index() {
59  global $template;
60
61  $template->smarty->registerPlugin("function", "media_type", "GDThumb_media_type");
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_endsWith($needles, $haystack) {
68  if(empty($needles) || empty($haystack)):
69    return false;
70  else:
71    $arr_needles = explode(',', $needles);
72   
73    foreach ((array) $arr_needles as $needle) { 
74      if ((string) $needle === substr($haystack, -strlen($needle))) return true; 
75    } 
76    return false; 
77  endif;
78}
79
80function GDThumb_media_type($params, $smarty) {
81  if(empty($params["file"]))
82    return "image";
83
84  $file = $params["file"];
85  if (GDThumb_endsWith("webm,webmv,ogv,m4v,flv,mp4", $file))
86    return "video";
87  if (GDThumb_endsWith("mp3,ogg,oga,m4a,webma,fla,wav", $file))
88    return "music";
89  if (GDThumb_endsWith("pdf", $file))
90    return "pdf";
91  if (GDThumb_endsWith("doc,docx,odt", $file))
92    return "doc";
93  if (GDThumb_endsWith("xls,xlsx,ods", $file))
94    return "xls";
95  if (GDThumb_endsWith("ppt,pptx,odp", $file))
96    return "ppt";
97
98  return "image";
99}
100
101function GDThumb_process_thumb($tpl_vars, $pictures) {
102  global $template, $conf;
103  $confTemp = $conf['gdThumb'];
104  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
105  $confTemp['big_thumb_noinpw'] = (isset($confTemp['big_thumb_noinpw']) && ($confTemp['big_thumb_noinpw']))? 1 : 0;
106  if ($confTemp['normalize_title'] == "1"):
107    $confTemp['normalize_title'] = "on";
108  endif;   
109
110  $template->set_filename( 'index_thumbnails', dirname(__FILE__) . '/template/gdthumb_thumb.tpl');
111  $template->assign('GDThumb', $confTemp);
112  if (($confTemp['method'] == "slide") || ($confTemp['method'] == "square")):
113    $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom($confTemp['height'], 9999));
114  else:
115    $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
116  endif;
117
118  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
119    if (($confTemp['method'] == "slide") || ($confTemp['method'] == "square")):
120      $derivative_params = ImageStdParams::get_custom(2 * $confTemp['height'] + $confTemp['margin'], 9999);
121    else:
122      $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
123    endif;
124    $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
125  endif;
126
127  return $tpl_vars;
128}
129
130function GDThumb_process_category($tpl_vars) {
131
132  global $template, $conf;
133  $confTemp = $conf['gdThumb'];
134  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
135  $confTemp['big_thumb_noinpw'] = isset($confTemp['big_thumb_noinpw'])? 1 : 0;
136
137  $template->set_filename( 'index_category_thumbnails', dirname(__FILE__) . '/template/gdthumb_cat.tpl');
138  $template->assign('GDThumb', $confTemp);
139  if (($confTemp['method'] == "slide") || ($confTemp['method'] == "square")):
140    $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom($confTemp['height'], 9999));
141  else:
142    $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
143  endif;
144
145  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
146    $id = $tpl_vars[0]["representative_picture_id"];
147    if (($id) && ($rep = $tpl_vars[0]["representative"])):
148      if (($confTemp['method'] == "slide") || ($confTemp['method'] == "square")):
149        $derivative_params = ImageStdParams::get_custom(2 * $confTemp['height'] + $confTemp['margin'], 9999);
150      else:
151        $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
152      endif;
153      $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $rep['src_image']));
154    endif;
155  endif;
156
157  return $tpl_vars;
158}
159
160function GDThumb_prefilter($content) {
161  $pattern = '#\<div.*?id\="thumbnails".*?\>\{\$THUMBNAILS\}\</div\>#';
162  $replacement = '<ul id="thumbnails">{$THUMBNAILS}</ul>';
163
164  return preg_replace($pattern, $replacement, $content);
165}
166
167function GDThumb_admin_menu($menu) {
168  array_push($menu,
169    array(
170      'NAME' => 'gdThumb',
171      'URL' => get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)),
172    )
173  );
174  return $menu;
175}
176
177function GDThumb_remove_thumb_size() {
178  global $template;
179  $template->clear_assign('image_derivatives');
180}
181
182?>
Note: See TracBrowser for help on using the repository browser.