1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | function int_delete_gdthumb_cache($pattern) { |
---|
6 | if ($contents = @opendir(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR)): |
---|
7 | while (($node = readdir($contents)) !== false): |
---|
8 | if ($node != '.' |
---|
9 | and $node != '..' |
---|
10 | and is_dir(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $node)): |
---|
11 | clear_derivative_cache_rec(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $node, $pattern); |
---|
12 | endif; |
---|
13 | endwhile; |
---|
14 | closedir($contents); |
---|
15 | endif; |
---|
16 | } |
---|
17 | |
---|
18 | function delete_gdthumb_cache($height) { |
---|
19 | int_delete_gdthumb_cache('#.*-cu_s9999x' . $height . '\.[a-zA-Z0-9]{3,4}$#'); |
---|
20 | int_delete_gdthumb_cache('#.*-cu_s' . $height . 'x9999\.[a-zA-Z0-9]{3,4}$#'); |
---|
21 | } |
---|
22 | |
---|
23 | global $template, $conf, $page; |
---|
24 | |
---|
25 | load_language('plugin.lang', GDTHUMB_PATH); |
---|
26 | include(dirname(__FILE__).'/config_default.inc.php'); |
---|
27 | $params = $conf['gdThumb']; |
---|
28 | |
---|
29 | if (isset($_GET['getMissingDerivative'])) { |
---|
30 | list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) ); |
---|
31 | $start_id = intval($_POST['prev_page']); |
---|
32 | $max_urls = intval($_POST['max_urls']); |
---|
33 | if ($start_id<=0) { |
---|
34 | $start_id = $max_id; |
---|
35 | } |
---|
36 | |
---|
37 | $uid = '&b='.time(); |
---|
38 | global $conf; |
---|
39 | $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; |
---|
40 | $conf['derivative_url_style']=2; //script |
---|
41 | |
---|
42 | $qlimit = min(5000, ceil(max($image_count/500, $max_urls))); |
---|
43 | |
---|
44 | $query_model = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id < start_id ORDER BY id DESC LIMIT ' . $qlimit; |
---|
45 | |
---|
46 | $urls=array(); |
---|
47 | do { |
---|
48 | $result = pwg_query( str_replace('start_id', $start_id, $query_model)); |
---|
49 | $is_last = pwg_db_num_rows($result) < $qlimit; |
---|
50 | while ($row=pwg_db_fetch_assoc($result)) { |
---|
51 | $start_id = $row['id']; |
---|
52 | $src_image = new SrcImage($row); |
---|
53 | if ($src_image->is_mimetype()) |
---|
54 | continue; |
---|
55 | if (($params['method'] == "slide") || ($params['method'] == "square")): |
---|
56 | $derivative = new DerivativeImage(ImageStdParams::get_custom($params['height'], 9999), $src_image); |
---|
57 | else: |
---|
58 | $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $params['height']), $src_image); |
---|
59 | endif; |
---|
60 | if (@filemtime($derivative->get_path())===false) { |
---|
61 | $urls[] = $derivative->get_url().$uid; |
---|
62 | } |
---|
63 | if (count($urls)>=$max_urls && !$is_last) |
---|
64 | break; |
---|
65 | } |
---|
66 | if ($is_last) { |
---|
67 | $start_id = 0; |
---|
68 | } |
---|
69 | }while (count($urls)<$max_urls && $start_id); |
---|
70 | |
---|
71 | $ret = array(); |
---|
72 | if ($start_id) { |
---|
73 | $ret['next_page']=$start_id; |
---|
74 | } |
---|
75 | $ret['urls']=$urls; |
---|
76 | echo json_encode($ret); |
---|
77 | exit(); |
---|
78 | } |
---|
79 | |
---|
80 | // Delete cache |
---|
81 | if (isset($_POST['cachedelete'])) { |
---|
82 | check_pwg_token(); |
---|
83 | delete_gdthumb_cache($params['height']); |
---|
84 | delete_gdthumb_cache($params['height'] * 2 + $params['margin']); |
---|
85 | redirect('admin.php?page=plugin-GDThumb'); |
---|
86 | } |
---|
87 | |
---|
88 | // Save configuration |
---|
89 | if (isset($_POST['submit'])) { |
---|
90 | |
---|
91 | if (empty($_POST['method'])): |
---|
92 | $method = "resize"; |
---|
93 | else: |
---|
94 | $method = $_POST['method']; |
---|
95 | endif; |
---|
96 | if (empty($_POST['normalize_title'])): |
---|
97 | $normalize = "off"; |
---|
98 | else: |
---|
99 | $normalize = $_POST['normalize_title']; |
---|
100 | endif; |
---|
101 | |
---|
102 | $big_thumb = !empty($_POST['big_thumb']); |
---|
103 | $big_thumb_noinpw = !empty($_POST['big_thumb_noinpw']); |
---|
104 | $thumb_animate = !empty($_POST['thumb_animate']); |
---|
105 | $thumb_mode_album = $_POST['thumb_mode_album']; |
---|
106 | $thumb_mode_photo = $_POST['thumb_mode_photo']; |
---|
107 | |
---|
108 | if ($method == "slide"): |
---|
109 | if ($big_thumb): |
---|
110 | $big_thumb = false; |
---|
111 | array_push($page['warnings'], l10n('Big thumb cannot be used in Slide mode. Disabled')); |
---|
112 | endif; |
---|
113 | if ($thumb_animate): |
---|
114 | $thumb_animate = false; |
---|
115 | array_push($page['warnings'], l10n('Thumb animation cannot be used in Slide mode. Disabled')); |
---|
116 | endif; |
---|
117 | |
---|
118 | if (($thumb_mode_album == "overlay-ex") || ($thumb_mode_album == "overlay") || ($thumb_mode_album == "top") || ($thumb_mode_album == "bottom")): |
---|
119 | $thumb_mode_album = "bottom_static"; |
---|
120 | array_push($page['warnings'], l10n('This Thumb mode cannot be used in Slide mode. Changed to default')); |
---|
121 | endif; |
---|
122 | |
---|
123 | if (($thumb_mode_photo == "overlay-ex") || ($thumb_mode_photo == "overlay") || ($thumb_mode_photo == "top") || ($thumb_mode_photo == "bottom")): |
---|
124 | $thumb_mode_photo = "bottom_static"; |
---|
125 | array_push($page['warnings'], l10n('This Thumb mode cannot be used in Slide mode. Changed to default')); |
---|
126 | endif; |
---|
127 | endif; |
---|
128 | |
---|
129 | if (($big_thumb_noinpw) && (!$big_thumb)): |
---|
130 | $big_thumb_noinpw = false; |
---|
131 | endif; |
---|
132 | |
---|
133 | $params = array( |
---|
134 | 'height' => $_POST['height'] |
---|
135 | , 'margin' => $_POST['margin'] |
---|
136 | , 'nb_image_page' => $_POST['nb_image_page'] |
---|
137 | , 'big_thumb' => $big_thumb |
---|
138 | , 'big_thumb_noinpw'=> $big_thumb_noinpw |
---|
139 | , 'cache_big_thumb' => !empty($_POST['cache_big_thumb']) |
---|
140 | , 'normalize_title' => $normalize |
---|
141 | , 'method' => $method |
---|
142 | , 'thumb_mode_album'=> $thumb_mode_album |
---|
143 | , 'thumb_mode_photo'=> $thumb_mode_photo |
---|
144 | , 'thumb_metamode' => $_POST['thumb_metamode'] |
---|
145 | , 'no_wordwrap' => !empty($_POST['no_wordwrap']) |
---|
146 | , 'thumb_animate' => $thumb_animate |
---|
147 | ); |
---|
148 | |
---|
149 | if (!is_numeric($params['height'])) { |
---|
150 | array_push($page['errors'], l10n('Thumbnails max height must be an integer')); |
---|
151 | } |
---|
152 | if (!is_numeric($params['margin'])) { |
---|
153 | array_push($page['errors'], l10n('Margin between thumbnails must be an integer')); |
---|
154 | } |
---|
155 | if (!is_numeric($params['nb_image_page'])) { |
---|
156 | array_push($page['errors'], l10n('Number of photos per page must be an integer')); |
---|
157 | } |
---|
158 | |
---|
159 | if ($params['height'] != $conf['gdThumb']['height']) { |
---|
160 | delete_gdthumb_cache($conf['gdThumb']['height']); |
---|
161 | } |
---|
162 | elseif ($params['margin'] != $conf['gdThumb']['margin']) { |
---|
163 | delete_gdthumb_cache($conf['gdThumb']['height'] * 2 + $conf['gdThumb']['margin']); |
---|
164 | } |
---|
165 | |
---|
166 | if (empty($page['errors'])) { |
---|
167 | conf_update_param('gdThumb', $params); |
---|
168 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | // Try to find GreyDragon Theme and use Theme's styles for admin area |
---|
173 | $css_file = str_replace('/./', '/', dirname(dirname(dirname(__FILE__))) . '/' . GDTHEME_PATH . "admin/css/styles.css"); |
---|
174 | if (@file_exists($css_file)): |
---|
175 | $custom_css = "yes"; |
---|
176 | else: |
---|
177 | $custom_css = "no"; |
---|
178 | endif; |
---|
179 | |
---|
180 | if (!isset($params['normalize_title'])): |
---|
181 | $params['normalize_title'] = "off"; |
---|
182 | elseif ($params['normalize_title'] == "1"): |
---|
183 | $params['normalize_title'] = "on"; |
---|
184 | endif; |
---|
185 | |
---|
186 | // Configuration du template |
---|
187 | $template->assign( |
---|
188 | array( |
---|
189 | 'GDTHUMB_PATH' => 'plugins/' . GDTHUMB_ID, |
---|
190 | 'GDTHEME_PATH' => GDTHEME_PATH, |
---|
191 | 'GDTHUMB_VERSION' => GDTHUMB_VERSION, |
---|
192 | 'PHPWG_ROOT_PATH' => PHPWG_ROOT_PATH, |
---|
193 | |
---|
194 | 'HEIGHT' => $params['height'], |
---|
195 | 'MARGIN' => $params['margin'], |
---|
196 | 'NB_IMAGE_PAGE' => $params['nb_image_page'], |
---|
197 | 'BIG_THUMB' => $params['big_thumb'], |
---|
198 | 'BIG_THUMB_NOINPW' => isset($params['big_thumb_noinpw']) && $params['big_thumb_noinpw'], |
---|
199 | 'CACHE_BIG_THUMB' => $params['cache_big_thumb'], |
---|
200 | 'NORMALIZE_TITLE' => $params['normalize_title'], |
---|
201 | 'METHOD' => $params['method'], |
---|
202 | 'THUMB_MODE_ALBUM' => $params['thumb_mode_album'], |
---|
203 | 'THUMB_MODE_PHOTO' => $params['thumb_mode_photo'], |
---|
204 | 'THUMB_METAMODE' => $params['thumb_metamode'], |
---|
205 | 'NO_WORDWRAP' => isset($params['no_wordwrap']) && $params['no_wordwrap'], |
---|
206 | 'THUMB_ANIMATE' => isset($params['thumb_animate']) && $params['thumb_animate'], |
---|
207 | |
---|
208 | 'PWG_TOKEN' => get_pwg_token(), |
---|
209 | 'CUSTOM_CSS' => $custom_css |
---|
210 | ) |
---|
211 | ); |
---|
212 | |
---|
213 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); |
---|
214 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
215 | |
---|
216 | ?> |
---|