source: extensions/GThumb/admin.php @ 14059

Last change on this file since 14059 was 13652, checked in by patdenice, 13 years ago

Compatible with Piwigo 2.4

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