source: extensions/GDThumb/admin.php @ 30344

Last change on this file since 30344 was 30225, checked in by SergeD, 10 years ago

GDThumb 1.0.12

File size: 5.6 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
89  $big_thumb = !empty($_POST['big_thumb']);
90  $params  = array(
91    'height'          => $_POST['height'],
92    'margin'          => $_POST['margin'],
93    'nb_image_page'   => $_POST['nb_image_page'],
94    'big_thumb'       => $big_thumb,
95    'big_thumb_noinpw'=> !empty($_POST['big_thumb_noinpw']),
96    'cache_big_thumb' => !empty($_POST['cache_big_thumb']),
97    'normalize_title' => !empty($_POST['normalize_title']),
98    'method'          => $method,
99    'thumb_mode_album'=> $_POST['thumb_mode_album'],
100    'thumb_mode_photo'=> $_POST['thumb_mode_photo'],
101    'thumb_metamode'  => $_POST['thumb_metamode'],
102    'no_wordwrap'     => !empty($_POST['no_wordwrap'])
103  );
104
105  if (!is_numeric($params['height'])) {
106    array_push($page['errors'], 'Thumbnails max height must be an integer.');
107  }
108  if (!is_numeric($params['margin'])) {
109    array_push($page['errors'], 'Margin between thumbnails must be an integer.');
110  }
111  if (!is_numeric($params['nb_image_page'])) {
112    array_push($page['errors'], 'Number of photos per page must be an integer.');
113  }
114
115  if ($params['height'] != $conf['gdThumb']['height']) {
116    delete_gdthumb_cache($conf['gdThumb']['height']);
117  }
118  elseif ($params['margin'] != $conf['gdThumb']['margin']) {
119    delete_gdthumb_cache($conf['gdThumb']['height'] * 2 + $conf['gdThumb']['margin']);
120  }
121
122  if (empty($page['errors'])) {
123    $query = '
124  UPDATE ' . CONFIG_TABLE . '
125    SET value="' . addslashes(serialize($params)) . '"
126    WHERE param="gdThumb"
127    LIMIT 1';
128    pwg_query($query);
129   
130    array_push($page['infos'], l10n('Information data registered in database'));
131  }
132}
133
134// Try to find GreyDragon Theme and use Theme's styles for admin area
135$css_file = str_replace('/./', '/', dirname(dirname(dirname(__FILE__))) . '/' . GDTHEME_PATH . "admin/css/styles.css");
136if (@file_exists($css_file)):
137  $custom_css = "yes";
138else:
139  $custom_css = "no";
140endif;
141
142if (!isset($params['normalize_title'])):
143  $params['normalize_title'] = "off";
144endif;
145
146// Configuration du template
147$template->assign(
148  array(
149    'GDTHUMB_PATH'     => 'plugins/' . GDTHUMB_ID,
150    'GDTHEME_PATH'     => GDTHEME_PATH,
151    'GDTHUMB_VERSION'  => GDTHUMB_VERSION,
152    'PHPWG_ROOT_PATH'  => PHPWG_ROOT_PATH,
153    'HEIGHT'           => $params['height'],
154    'MARGIN'           => $params['margin'],
155    'NB_IMAGE_PAGE'    => $params['nb_image_page'],
156    'BIG_THUMB'        => $params['big_thumb'],
157    'BIG_THUMB_NOINPW' => isset($params['big_thumb_noinpw']) && $params['big_thumb_noinpw'],
158    'CACHE_BIG_THUMB'  => $params['cache_big_thumb'],
159    'NORMALIZE_TITLE'  => $params['normalize_title'],
160    'METHOD'           => $params['method'],
161    'THUMB_MODE_ALBUM' => $params['thumb_mode_album'],
162    'THUMB_MODE_PHOTO' => $params['thumb_mode_photo'],
163    'THUMB_METAMODE'   => $params['thumb_metamode'],
164    'NO_WORDWRAP'      => isset($params['no_wordwrap']) && $params['no_wordwrap'],
165    'PWG_TOKEN'        => get_pwg_token(),
166    'CUSTOM_CSS'       => $custom_css
167  )
168);
169
170$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl'));
171$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
172
173?>
Note: See TracBrowser for help on using the repository browser.