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