source: extensions/regenerateThumbnails/element_set_global_action.php @ 21584

Last change on this file since 21584 was 11649, checked in by patdenice, 13 years ago

Avoid cache conflict

File size: 3.5 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4check_status(ACCESS_ADMINISTRATOR);
5
6function regenerate_prefilter($content, $smarty)
7{
8  return str_replace('{$thumbnail.TN_SRC}', '{$thumbnail.TN_SRC}?rand='.md5(uniqid(rand(), true)), $content);
9}
10
11global $template, $conf, $page, $pwg_loaded_plugins, $user;
12
13// User cache must not be updated during ajax requests
14if ((!isset($user['need_update']) or !$user['need_update']) and !isset($_POST['submit']))
15  getuserdata($user['id'], true);
16
17load_language('plugin.lang', REGENERATE_THUMBNAILS_PATH);
18include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
19prepare_upload_configuration();
20$upload_form_config = get_upload_form_config();
21
22$template->set_filename('regenerateThumbnails', realpath(REGENERATE_THUMBNAILS_PATH.'element_set_global_action.tpl'));
23
24if (isset($_POST['submit']) and $_POST['selectAction'] == 'regenerateThumbnails')
25{
26  if ($_POST['regenerateThumbnailsSuccess'] != '0')
27    array_push($page['infos'], sprintf(l10n('%s thumbnails have been regenerated'), $_POST['regenerateThumbnailsSuccess']));
28
29  if ($_POST['regenerateThumbnailsError'] != '0')
30    array_push($page['warnings'], sprintf(l10n('%s thumbnails can not be regenerated'), $_POST['regenerateThumbnailsError']));
31
32  // Update configuration
33  $fields = array('thumb_maxwidth', 'thumb_maxheight', 'thumb_quality');
34  foreach ($fields as $field)
35  {
36    if (!isset($upload_form_config[$field]))
37    {
38      continue;
39    }
40    $value = null;
41    if (!empty($_POST[$field]))
42    {
43      $value = $_POST[$field];
44    }
45
46    $min = $upload_form_config[$field]['min'];
47    $max = $upload_form_config[$field]['max'];
48    $pattern = $upload_form_config[$field]['pattern'];
49
50    if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
51    {
52      $conf['upload_form_'.$field] = $value;
53       $updates[] = array(
54        'param' => 'upload_form_'.$field,
55        'value' => $value
56        );
57    }
58    else
59    {
60      array_push(
61        $page['errors'],
62        sprintf(
63          $upload_form_config[$field]['error_message'],
64          $min,
65          $max
66          )
67        );
68    }
69    $form_values[$field] = $value;
70  }
71  if (count($page['errors']) == 0)
72  {
73    mass_updates(
74      CONFIG_TABLE,
75      array(
76        'primary' => array('param'),
77        'update' => array('value')
78        ),
79      $updates
80      );
81  }
82
83  if (isset($pwg_loaded_plugins['square_thumbnails']))
84  {
85    $conf['upload_form_thumb_square'] = isset($_POST['square']);
86    conf_update_param('upload_form_thumb_square', $conf['upload_form_thumb_square']);
87  }
88
89  $template->delete_compiled_templates();
90}
91
92foreach ($upload_form_config as $param_shortname => $param)
93{
94  $param_name = 'upload_form_'.$param_shortname;
95  $form_values[$param_shortname] = $conf[$param_name];
96}
97
98if (isset($pwg_loaded_plugins['square_thumbnails']))
99{
100  load_language('plugin.lang', SQUARE_THUMB_PATH);
101  $template->assign(array('SQUARE' => @$conf['upload_form_thumb_square']));
102}
103
104$redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
105if ($_GET['page'] == 'plugin')
106  $redirect_url .= '-regenerateThumbnails';
107
108$template->assign(array(
109  'upload_form_settings' => $form_values,
110  'all_elements' => $page['cat_elements_id'],
111  'redirect_url' => $redirect_url,
112  )
113);
114
115$template->append('element_set_global_plugins_actions', array(
116  'ID' => 'regenerateThumbnails',
117  'NAME' => l10n('Regenerate Thumbnails'),
118  'CONTENT' => $template->parse('regenerateThumbnails', true),
119  )
120);
121
122$template->set_prefilter('batch_manager_global', 'regenerate_prefilter');
123
124?>
Note: See TracBrowser for help on using the repository browser.