source: extensions/GThumb/admin.php @ 12857

Last change on this file since 12857 was 12758, checked in by patdenice, 12 years ago

Delete cache automaticaly if height or margin has changed

File size: 3.1 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf, $page;
6
7load_language('plugin.lang', GTHUMB_PATH);
8include_once(GTHUMB_PATH.'functions.inc.php');
9include(dirname(__FILE__).'/config_default.inc.php');
10$params = $conf['GThumb'];
11
12// Delete cache
13if (isset($_GET['deletecache']))
14{
15  check_pwg_token();                             
16  gtdeltree(GTHUMB_CACHE_DIR);
17  redirect('admin.php?page=plugin-GThumb');
18}
19
20// Generate cache
21if (isset($_GET['generatecache']))
22{
23  if ($_GET['generatecache'] == 'complete')
24  {
25    array_push($page['infos'], l10n('Cache have been generated'));
26  }
27  else
28  {
29    $query = 'SELECT id, path, md5sum, tn_ext FROM '.IMAGES_TABLE.';';
30    $result = pwg_query($query);
31    $cache_dir = GTHUMB_CACHE_DIR.'/'.$conf['GThumb']['height'].'/';
32    $missing = array();
33
34    while ($row = pwg_db_fetch_assoc($result))
35    {
36      if (!is_file($cache_dir.md5($row['path'].(!empty($row['md5sum']) ? $row['md5sum'] : '')).'.'.$row['tn_ext'])
37        and in_array(get_extension($row['path']), $conf['picture_ext']))
38      {
39        array_push($missing, $row['id']);
40      }
41    }
42    echo json_encode($missing);
43    exit();
44  }
45}
46
47// Save configuration
48if (isset($_POST['submit']))
49{
50  $params  = array(
51    'height'          => $_POST['height'],
52    'margin'          => $_POST['margin'],
53    'nb_image_page'   => $_POST['nb_image_page'],
54    'big_thumb'       => !empty($_POST['big_thumb']),
55    'cache_big_thumb' => !empty($_POST['cache_big_thumb']),
56    'method'          => $_POST['method'],
57  );
58
59  if (!is_numeric($params['height']))
60  {
61    array_push($page['errors'], 'Thumbnails max height must be an integer.');
62  }
63  if (!is_numeric($params['margin']))
64  {
65    array_push($page['errors'], 'Margin between thumbnails must be an integer.');
66  }
67  if (!is_numeric($params['nb_image_page']))
68  {
69    array_push($page['errors'], 'Number of photos per page must be an integer.');
70  }
71
72  if ($params['height'] != $conf['GThumb']['height'])
73  {
74    gtdeltree(GTHUMB_CACHE_DIR);
75  }
76  elseif ($params['margin'] != $conf['GThumb']['margin'])
77  {
78    gtdeltree(GTHUMB_CACHE_DIR.'/'.($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']));
79  }
80
81  if (empty($page['errors']))
82  {
83    $query = '
84  UPDATE ' . CONFIG_TABLE . '
85    SET value="' . addslashes(serialize($params)) . '"
86    WHERE param="GThumb"
87    LIMIT 1';
88    pwg_query($query);
89   
90    array_push($page['infos'], l10n('Information data registered in database'));
91  }
92}
93
94// Configuration du template
95$template->assign(
96  array(
97    'HEIGHT'          => $params['height'],
98    'MARGIN'          => $params['margin'],
99    'NB_IMAGE_PAGE'   => $params['nb_image_page'],
100    'BIG_THUMB'       => $params['big_thumb'],
101    'CACHE_BIG_THUMB' => $params['cache_big_thumb'],
102    'METHOD'          => $params['method'],
103  )
104);
105
106// Informations
107$data = gtdirsize(GTHUMB_CACHE_DIR);
108
109$template->assign(
110  array(
111    'NB_FILES' => $data['nb_files'],
112    'CACHE_SIZE' => $data['size'],
113    'PWG_TOKEN' => get_pwg_token(),
114  )
115);
116
117$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl'));
118$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
119
120?>
Note: See TracBrowser for help on using the repository browser.