source: extensions/GDThumb/admin.php @ 31148

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

version 1.0.15 - refer to changelog for more details

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