1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: gdThumb |
---|
4 | Version: 1.0.12 |
---|
5 | Description: Display thumbnails as patchwork |
---|
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.12'); |
---|
22 | define('GDTHUMB_ID', basename(dirname(__FILE__))); |
---|
23 | define('GDTHEME_PATH' , PHPWG_THEMES_PATH . 'greydragon/'); |
---|
24 | define('GDTHUMB_PATH' , PHPWG_PLUGINS_PATH . GDTHUMB_ID . '/'); |
---|
25 | |
---|
26 | if (!isset($conf['gdThumb'])): |
---|
27 | include(dirname(__FILE__).'/config_default.inc.php'); |
---|
28 | |
---|
29 | $query = ' |
---|
30 | INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) |
---|
31 | VALUES ("gdThumb" , "'.addslashes(serialize($config_default)).'" , "GDThumb plugin parameters");'; |
---|
32 | pwg_query($query); |
---|
33 | load_conf_from_db(); |
---|
34 | endif; |
---|
35 | |
---|
36 | $conf['gdThumb'] = unserialize($conf['gdThumb']); |
---|
37 | |
---|
38 | // RV Thumbnails Scroller |
---|
39 | if (isset($_GET['rvts'])): |
---|
40 | $conf['gdThumb']['big_thumb'] = false; |
---|
41 | add_event_handler('loc_end_index_thumbnails', 'process_GDThumb', 50, 2); |
---|
42 | endif; |
---|
43 | |
---|
44 | add_event_handler('init', 'GDThumb_init'); |
---|
45 | add_event_handler('loc_begin_index', 'GDThumb_index', 60); |
---|
46 | add_event_handler('loc_end_index_category_thumbnails', 'GDThumb_process_category', 50, 2); |
---|
47 | add_event_handler('get_admin_plugin_menu_links', 'GDThumb_admin_menu'); |
---|
48 | add_event_handler('loc_end_index', 'GDThumb_remove_thumb_size'); |
---|
49 | |
---|
50 | function 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 | |
---|
59 | function 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 | |
---|
67 | function 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 | |
---|
85 | function 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 | |
---|
107 | function 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 | |
---|
114 | function 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 | |
---|
124 | function GDThumb_remove_thumb_size() { |
---|
125 | global $template; |
---|
126 | $template->clear_assign('image_derivatives'); |
---|
127 | } |
---|
128 | |
---|
129 | ?> |
---|