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

Last change on this file since 31134 was 31134, checked in by SergeD, 9 years ago

version 1.0.17 - refer to changelog for more details

File size: 5.5 KB
Line 
1<?php
2/*
3Plugin Name: gdThumb
4Version: 1.0.17
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
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.17');
22define('GDTHUMB_ID',      basename(dirname(__FILE__)));
23define('GDTHUMB_PATH' ,   PHPWG_PLUGINS_PATH . GDTHUMB_ID . '/');
24if (!defined('GDTHEME_PATH')):
25  define('GDTHEME_PATH' ,   PHPWG_THEMES_PATH . 'greydragon/');
26endif;
27
28if (!isset($conf['gdThumb'])):
29  include(dirname(__FILE__).'/config_default.inc.php');
30
31  $query = '
32INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
33VALUES ("gdThumb" , "'.addslashes(serialize($config_default)).'" , "GDThumb plugin parameters");';
34  pwg_query($query);
35  load_conf_from_db();
36endif;
37
38$conf['gdThumb'] = unserialize($conf['gdThumb']);
39
40// RV Thumbnails Scroller
41if (isset($_GET['rvts'])):
42  $conf['gdThumb']['big_thumb'] = false;
43  add_event_handler('loc_end_index_thumbnails', 'GDThumb_process_thumb', 50, 2);
44endif;
45
46add_event_handler('init', 'GDThumb_init');
47add_event_handler('loc_begin_index', 'GDThumb_index', 60);
48add_event_handler('loc_end_index_category_thumbnails', 'GDThumb_process_category', 50, 2);
49add_event_handler('get_admin_plugin_menu_links', 'GDThumb_admin_menu');
50add_event_handler('loc_end_index', 'GDThumb_remove_thumb_size');
51
52function GDThumb_init() {
53  global $conf, $user, $page, $stripped;
54
55  $confTemp = $conf['gdThumb'];
56  $user['nb_image_page']    = $confTemp['nb_image_page'];
57  $page['nb_image_page']    = $confTemp['nb_image_page'];
58  $stripped['maxThumb']     = $confTemp['nb_image_page'];
59}
60
61function GDThumb_index() {
62  global $template;
63
64  $template->smarty->registerPlugin("function", "media_type", "GDThumb_media_type");
65  $template->set_prefilter('index', 'GDThumb_prefilter');
66
67  add_event_handler('loc_end_index_thumbnails', 'GDThumb_process_thumb', 50, 2);
68}
69                                                 
70function GDThumb_endsWith($needles, $haystack) {
71  if(empty($needles) || empty($haystack)):
72    return false;
73  else:
74    $arr_needles = explode(',', $needles);
75   
76    foreach ((array) $arr_needles as $needle) { 
77      if ((string) $needle === substr($haystack, -strlen($needle))) return true; 
78    } 
79    return false; 
80  endif;
81}
82
83function GDThumb_media_type($params, $smarty) {
84  if(empty($params["file"]))
85    return "image";
86
87  $file = $params["file"];
88  if (GDThumb_endsWith("webm,webmv,ogv,m4v,flv,mp4", $file))
89    return "video";
90  if (GDThumb_endsWith("mp3,ogg,oga,m4a,webma,fla,wav", $file))
91    return "music";
92  if (GDThumb_endsWith("pdf", $file))
93    return "pdf";
94  if (GDThumb_endsWith("doc,docx,odt", $file))
95    return "doc";
96  if (GDThumb_endsWith("xls,xlsx,ods", $file))
97    return "xls";
98  if (GDThumb_endsWith("ppt,pptx,odp", $file))
99    return "ppt";
100
101  return "image";
102}
103
104function GDThumb_process_thumb($tpl_vars, $pictures) {
105  global $template, $conf;
106  $confTemp = $conf['gdThumb'];
107  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
108  $confTemp['big_thumb_noinpw'] = (isset($confTemp['big_thumb_noinpw']) && ($confTemp['big_thumb_noinpw']))? 1 : 0;
109  if ($confTemp['normalize_title'] == "1"):
110    $confTemp['normalize_title'] = "on";
111  endif;   
112
113  $template->set_filename( 'index_thumbnails', dirname(__FILE__) . '/template/gdthumb_thumb.tpl');
114  $template->assign('GDThumb', $confTemp);
115  $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
116
117  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
118    $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
119    $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
120  endif;
121
122  return $tpl_vars;
123}
124
125function GDThumb_process_category($tpl_vars) {
126
127  global $template, $conf;
128  $confTemp = $conf['gdThumb'];
129  $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
130  $confTemp['big_thumb_noinpw'] = isset($confTemp['big_thumb_noinpw'])? 1 : 0;
131
132  $template->set_filename( 'index_category_thumbnails', dirname(__FILE__) . '/template/gdthumb_cat.tpl');
133  $template->assign('GDThumb', $confTemp);
134  $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
135
136  if ($confTemp['big_thumb'] and !empty($tpl_vars[0])):
137    $id = $tpl_vars[0]["representative_picture_id"];
138    if (($id) && ($rep = $tpl_vars[0]["representative"])):
139      $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
140      $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $rep['src_image']));
141    endif;
142  endif;
143
144  return $tpl_vars;
145}
146
147function GDThumb_prefilter($content, $smarty) {
148  $pattern = '#\<div.*?id\="thumbnails".*?\>\{\$THUMBNAILS\}\</div\>#';
149  $replacement = '<ul id="thumbnails">{$THUMBNAILS}</ul>';
150
151  return preg_replace($pattern, $replacement, $content);
152}
153
154function GDThumb_admin_menu($menu) {
155  array_push($menu,
156    array(
157      'NAME' => 'gdThumb',
158      'URL' => get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)),
159    )
160  );
161  return $menu;
162}
163
164function GDThumb_remove_thumb_size() {
165  global $template;
166  $template->clear_assign('image_derivatives');
167}
168
169?>
Note: See TracBrowser for help on using the repository browser.