1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: gdThumb |
---|
4 | Version: 1.0.17 |
---|
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.17'); |
---|
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 | |
---|
31 | $query = ' |
---|
32 | INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) |
---|
33 | VALUES ("gdThumb" , "'.addslashes(serialize($config_default)).'" , "GDThumb plugin parameters");'; |
---|
34 | pwg_query($query); |
---|
35 | load_conf_from_db(); |
---|
36 | endif; |
---|
37 | |
---|
38 | $conf['gdThumb'] = unserialize($conf['gdThumb']); |
---|
39 | |
---|
40 | // RV Thumbnails Scroller |
---|
41 | if (isset($_GET['rvts'])): |
---|
42 | $conf['gdThumb']['big_thumb'] = false; |
---|
43 | add_event_handler('loc_end_index_thumbnails', 'GDThumb_process_thumb', 50, 2); |
---|
44 | endif; |
---|
45 | |
---|
46 | add_event_handler('init', 'GDThumb_init'); |
---|
47 | add_event_handler('loc_begin_index', 'GDThumb_index', 60); |
---|
48 | add_event_handler('loc_end_index_category_thumbnails', 'GDThumb_process_category', 50, 2); |
---|
49 | add_event_handler('get_admin_plugin_menu_links', 'GDThumb_admin_menu'); |
---|
50 | add_event_handler('loc_end_index', 'GDThumb_remove_thumb_size'); |
---|
51 | |
---|
52 | function 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 | |
---|
61 | function 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 | |
---|
70 | function 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 | |
---|
83 | function 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 | |
---|
104 | function 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 | |
---|
125 | function 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 | |
---|
147 | function 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 | |
---|
154 | function 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 | |
---|
164 | function GDThumb_remove_thumb_size() { |
---|
165 | global $template; |
---|
166 | $template->clear_assign('image_derivatives'); |
---|
167 | } |
---|
168 | |
---|
169 | ?> |
---|