source: extensions/GThumb/admin.php @ 12733

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

Thumbnails can be generated in admin pannel.

File size: 2.9 KB
RevLine 
[12678]1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
[12733]5global $template, $conf, $page;
[12678]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
[12691]12// Delete cache
13if (isset($_GET['deletecache']))
14{
[12696]15  check_pwg_token();                             
[12691]16  gtdeltree(GTHUMB_CACHE_DIR);
17  redirect('admin.php?page=plugin-GThumb');
18}
19
[12733]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
[12678]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 (empty($page['errors']))
73  {
74    $query = '
75  UPDATE ' . CONFIG_TABLE . '
76    SET value="' . addslashes(serialize($params)) . '"
77    WHERE param="GThumb"
78    LIMIT 1';
79    pwg_query($query);
80   
81    array_push($page['infos'], l10n('Information data registered in database'));
82  }
83}
84
85// Configuration du template
86$template->assign(
87  array(
88    'HEIGHT'          => $params['height'],
89    'MARGIN'          => $params['margin'],
90    'NB_IMAGE_PAGE'   => $params['nb_image_page'],
91    'BIG_THUMB'       => $params['big_thumb'],
92    'CACHE_BIG_THUMB' => $params['cache_big_thumb'],
93    'METHOD'          => $params['method'],
94  )
95);
96
[12691]97// Informations
98$data = gtdirsize(GTHUMB_CACHE_DIR);
99
100$template->assign(
101  array(
[12733]102    'NB_FILES' => $data['nb_files'],
103    'CACHE_SIZE' => $data['size'],
[12691]104    'PWG_TOKEN' => get_pwg_token(),
105  )
106);
107
[12678]108$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl'));
109$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
110
111?>
Note: See TracBrowser for help on using the repository browser.