source: extensions/regenerateThumbnails/element_set_global_action.php @ 10102

Last change on this file since 10102 was 9950, checked in by patdenice, 14 years ago

Avoid notices on first upload use.

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