1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | check_status(ACCESS_ADMINISTRATOR); |
---|
5 | |
---|
6 | global $template, $conf, $page, $pwg_loaded_plugins; |
---|
7 | |
---|
8 | load_language('plugin.lang', REGENERATE_WEBSIZE_PATH); |
---|
9 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
10 | prepare_upload_configuration(); |
---|
11 | $upload_form_config = get_upload_form_config(); |
---|
12 | |
---|
13 | $template->set_filename('regenerateWebsize', realpath(REGENERATE_WEBSIZE_PATH.'element_set_global_action.tpl')); |
---|
14 | |
---|
15 | if (isset($_POST['submit']) and $_POST['selectAction'] == 'regenerateWebsize') |
---|
16 | { |
---|
17 | if ($_POST['regenerateWebsizeSuccess'] != '0') |
---|
18 | array_push($page['infos'], sprintf(l10n('%s photos have been regenerated'), $_POST['regenerateWebsizeSuccess'])); |
---|
19 | |
---|
20 | if ($_POST['regenerateWebsizeError'] != '0') |
---|
21 | array_push($page['warnings'], sprintf(l10n('%s photos can not be regenerated'), $_POST['regenerateWebsizeError'])); |
---|
22 | |
---|
23 | // Update configuration |
---|
24 | $fields = array('websize_maxwidth', 'websize_maxheight', 'websize_quality'); |
---|
25 | foreach ($fields as $field) |
---|
26 | { |
---|
27 | if (!isset($upload_form_config[$field])) |
---|
28 | { |
---|
29 | continue; |
---|
30 | } |
---|
31 | $value = null; |
---|
32 | if (!empty($_POST[$field])) |
---|
33 | { |
---|
34 | $value = $_POST[$field]; |
---|
35 | } |
---|
36 | |
---|
37 | $min = $upload_form_config[$field]['min']; |
---|
38 | $max = $upload_form_config[$field]['max']; |
---|
39 | $pattern = $upload_form_config[$field]['pattern']; |
---|
40 | |
---|
41 | if (preg_match($pattern, $value) and $value >= $min and $value <= $max) |
---|
42 | { |
---|
43 | $conf['upload_form_'.$field] = $value; |
---|
44 | $updates[] = array( |
---|
45 | 'param' => 'upload_form_'.$field, |
---|
46 | 'value' => $value |
---|
47 | ); |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | array_push( |
---|
52 | $page['errors'], |
---|
53 | sprintf( |
---|
54 | $upload_form_config[$field]['error_message'], |
---|
55 | $min, |
---|
56 | $max |
---|
57 | ) |
---|
58 | ); |
---|
59 | } |
---|
60 | $form_values[$field] = $value; |
---|
61 | } |
---|
62 | if (count($page['errors']) == 0) |
---|
63 | { |
---|
64 | mass_updates( |
---|
65 | CONFIG_TABLE, |
---|
66 | array( |
---|
67 | 'primary' => array('param'), |
---|
68 | 'update' => array('value') |
---|
69 | ), |
---|
70 | $updates |
---|
71 | ); |
---|
72 | } |
---|
73 | |
---|
74 | $template->delete_compiled_templates(); |
---|
75 | } |
---|
76 | |
---|
77 | foreach ($upload_form_config as $param_shortname => $param) |
---|
78 | { |
---|
79 | $param_name = 'upload_form_'.$param_shortname; |
---|
80 | $form_values[$param_shortname] = $conf[$param_name]; |
---|
81 | } |
---|
82 | |
---|
83 | $template->assign(array( |
---|
84 | 'upload_form_websize_settings' => $form_values, |
---|
85 | 'all_elements' => $page['cat_elements_id'], |
---|
86 | 'redirect_url' => get_root_url().'admin.php?page='.$_GET['page'], |
---|
87 | ) |
---|
88 | ); |
---|
89 | |
---|
90 | $template->append('element_set_global_plugins_actions', array( |
---|
91 | 'ID' => 'regenerateWebsize', |
---|
92 | 'NAME' => l10n('Regenerate Websize Photos'), |
---|
93 | 'CONTENT' => $template->parse('regenerateWebsize', true), |
---|
94 | ) |
---|
95 | ); |
---|
96 | |
---|
97 | ?> |
---|