/[drupal]/contributions/modules/flashnode/flashnode.admin.inc
ViewVC logotype

Contents of /contributions/modules/flashnode/flashnode.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sun Aug 17 22:30:15 2008 UTC (15 months, 1 week ago) by stuartgreenfield
Branch: MAIN
CVS Tags: DRUPAL-6--2-2, DRUPAL-6--2-1, DRUPAL-6--2-0, DRUPAL-6--3-0, DRUPAL-6--3-1, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3
Changes since 1.8: +2 -2 lines
File MIME type: text/x-php
Fix error in configuration page that prevents it loading.
1 <?php
2 // $Id: flashnode.admin.inc,v 1.8 2008/08/07 22:43:28 stuartgreenfield Exp $
3
4 /**
5 * @file
6 * Callback for settings page
7 */
8 function flashnode_admin_settings() {
9
10 // Check for flash directory and create if necessary
11 _flashnode_check_settings();
12
13 // Reset the cache to ensure any pages using filters are updated
14 // Necessary to ensure macro content regenerated in case the user modifies max_height or max_width settings
15 cache_clear_all('*', 'cache_filter', TRUE);
16
17 $form['flashnode_updated'] = array(
18 '#type' => 'hidden',
19 '#value' => time(),
20 );
21
22 $form['display_settings'] = array(
23 '#type' => 'fieldset',
24 '#title' => t('Display settings'),
25 '#collapsible' => TRUE,
26 '#collapsed' => TRUE,
27 );
28
29 $form['display_settings']['flashnode_default_display'] = array(
30 '#type' => 'radios',
31 '#title' => t('Default display setting'),
32 '#default_value' => variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
33 '#description' => t('The default display setting that will be used when a new flash node is created.'),
34 '#options' => array(
35 FLASHNODE_TEASER_AND_BODY => t('Teaser and body'),
36 FLASHNODE_TEASER_ONLY => t('Teaser only'),
37 FLASHNODE_BODY_ONLY => t('Body only'),
38 FLASHNODE_DO_NOT_DISPLAY => t('Do not display'),
39 ),
40 );
41
42 $form['display_settings']['flashnode_max_width'] = array(
43 '#type' => 'textfield',
44 '#title' => t('Maximum displayed width'),
45 '#default_value' => variable_get('flashnode_max_width', 0),
46 '#description' => t('The maximum displayed width of a flash movie can be limited by entering a non-zero value here. If the movie width is greater than this width then the movie will be scaled down when it is displayed. A value of zero means that no scaling will occur. This setting can be useful to ensure that the page layout is not disrupted by a large flash movie.'),
47 );
48
49 $form['display_settings']['flashnode_max_height'] = array(
50 '#type' => 'textfield',
51 '#title' => t('Maximum displayed height'),
52 '#default_value' => variable_get('flashnode_max_height', 0),
53 '#description' => t('The maximum displayed height of a flash movie can be limited by entering a non-zero value here. If the movie height is greater than this height then the movie will be scaled down when it is displayed. A value of zero means that no scaling will occur. This setting can be useful to ensure that the page layout is not disrupted by a large flash movie.'),
54 );
55
56 $form['display_settings']['flashnode_teaser_scale'] = array(
57 '#type' => 'textfield',
58 '#title' => t('Scale factor to apply to teasers'),
59 '#default_value' => variable_get('flashnode_teaser_scale', 1),
60 '#description' => t('Use this setting to specify a scale factor to apply to flash content when it is displayed in teaser view. For example, enter <em>0.25</em> to display teaser content at 25% of its normal size.'),
61 );
62
63 $form['display_settings']['flashnode_max_teaser_width'] = array(
64 '#type' => 'textfield',
65 '#title' => t('Maximum displayed width for teasers'),
66 '#default_value' => variable_get('flashnode_max_teaser_width', 0),
67 '#description' => t('The maximum displayed width of a flash movie when in the teaser view can be limited by entering a non-zero value here. The teaser scaling factor defined above will be applied first, but if the resulting movie width is greater than this width then the movie will be scaled down further when it is displayed. A value of zero means that no additional scaling will occur. This setting can be useful to ensure that the page layout is not disrupted by a large flash movie.'),
68 );
69
70 $form['display_settings']['flashnode_max_teaser_height'] = array(
71 '#type' => 'textfield',
72 '#title' => t('Maximum displayed height for teasers'),
73 '#default_value' => variable_get('flashnode_max_teaser_height', 0),
74 '#description' => t('The maximum displayed height of a flash movie when in the teaser view can be limited by entering a non-zero value here. The teaser scaling factor defined above will be applied first, but if the resulting movie height is greater than this height then the movie will be scaled down further when it is displayed. A value of zero means that no additional scaling will occur. This setting can be useful to ensure that the page layout is not disrupted by a large flash movie.'),
75 );
76
77 $form['display_settings']['flashnode_weight'] = array(
78 '#type' => 'textfield',
79 '#title' => t('Weight of Flash content'),
80 '#default_value' => variable_get('flashnode_weight', FLASHNODE_DEFAULT_WEIGHT),
81 '#description' => t('Adjusting the weight of the Flash content will control where it appears relative to other parts of the node, such as the body. A negative value means it will float, a positive value means it will sink.'),
82 );
83
84 $form['general_settings'] = array(
85 '#type' => 'fieldset',
86 '#title' => t('General settings'),
87 '#collapsible' => TRUE,
88 '#collapsed' => TRUE,
89 );
90
91 $form['general_settings']['flashnode_default_html_alt'] = array(
92 '#type' => 'textarea',
93 '#rows' => 5,
94 '#title' => t('Default substitution content'),
95 '#default_value' => variable_get('flashnode_default_html_alt', FLASHNODE_DEFAULT_HTML_ALT),
96 '#description' => t('If you are using a javascript method to embed flash then this is the content that users will see if they are unable to, or choose not to, display the flash content. Use this content in a node by entering %default in the substitution field when creating a flash node. Note that this content is NOT filtered when it is displayed in a node so you may use mark-up that would not otherwise be allowed.', array('%default' => '!default')),
97 );
98
99 $form['general_settings']['flashnode_default_base'] = array(
100 '#type' => 'textfield',
101 '#title' => t('Default base parameter'),
102 '#default_value' => variable_get('flashnode_default_base', ''),
103 '#description' => t('If you use the ActionScript command %loadmovie then the <code>base</code> setting tells the Flash player where to find supporting movies that are not identified with a fully qualified file path. If you leave this setting blank then flash node will generate a default setting of %base that points to the file directory. This setting can be over-ridden in any node when the node is created.', array('%base' => file_create_url(''))),
104 );
105
106 $form['general_settings']['flashnode_default_import_status'] = array(
107 '#type' => 'radios',
108 '#title' => t('Publish status for imported nodes'),
109 '#default_value' => variable_get('flashnode_default_import_status', FLASHNODE_DEFAULT_IMPORT_STATUS),
110 '#description' => t('Specifies whether nodes created by import are published or not when they are created.'),
111 '#options' => array(
112 0 => t('Not published'),
113 1 => t('Published'),
114 ),
115 );
116
117 $form['file_settings'] = array(
118 '#type' => 'fieldset',
119 '#title' => t('File settings'),
120 '#collapsible' => TRUE,
121 '#collapsed' => TRUE,
122 );
123
124 $form['file_settings']['flashnode_default_path'] = array(
125 '#type' => 'textfield',
126 '#title' => t('Default flash path'),
127 '#default_value' => variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH),
128 '#description' => t('Subdirectory in the directory "%dir" where Flash files will be stored. Do not include a leading or trailing slash.', array('%dir' => variable_get('file_directory_path', 'files'))),
129 );
130
131 // Set some default options for files
132 $flashnode_default_extensions = variable_get('flashnode_default_extensions', FLASHNODE_DEFAULT_EXTENSIONS);
133 $upload_uploadsize_default = variable_get('upload_uploadsize_default', 1);
134 $upload_usersize_default = variable_get('upload_usersize_default', 1);
135
136 $form['file_settings']['flashnode_default_extensions'] = array(
137 '#type' => 'textfield',
138 '#title' => t('Default permitted file extensions'),
139 '#default_value' => $flashnode_default_extensions,
140 '#maxlength' => 255,
141 '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
142 );
143
144 $form['file_settings']['upload_uploadsize_default'] = array(
145 '#type' => 'textfield',
146 '#title' => t('Default maximum file size per upload'),
147 '#default_value' => $upload_uploadsize_default,
148 '#size' => 5,
149 '#maxlength' => 5,
150 '#description' => t('The default maximum file size a user can upload. This setting is shared with the upload module.'),
151 '#field_suffix' => t('MB'),
152 );
153
154 $form['file_settings']['upload_usersize_default'] = array(
155 '#type' => 'textfield',
156 '#title' => t('Default total file size per user'),
157 '#default_value' => $upload_usersize_default,
158 '#size' => 5,
159 '#maxlength' => 5,
160 '#description' => t('The default maximum size of all files a user can have on the site. This setting is shared with the upload module.'),
161 '#field_suffix' => t('MB'),
162 );
163
164 $form['file_settings']['upload_max_size'] = array('#value' => '<p>'. t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) .'</p>');
165
166 // Retrieve array of roles who can create flash nodes
167 $roles = user_roles(0, 'create flash nodes');
168 $form['roles'] = array('#type' => 'value', '#value' => $roles);
169
170 foreach ($roles as $rid => $role) {
171 $form['settings_role_'. $rid] = array(
172 '#type' => 'fieldset',
173 '#title' => t('Settings for @role', array('@role' => $role)),
174 '#collapsible' => TRUE,
175 '#collapsed' => TRUE,
176 );
177
178 $form['settings_role_'. $rid]['flashnode_extensions_'. $rid] = array(
179 '#type' => 'textfield',
180 '#title' => t('Permitted file extensions'),
181 '#default_value' => variable_get('flashnode_extensions_'. $rid, $flashnode_default_extensions),
182 '#maxlength' => 255,
183 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'),
184 );
185
186 $form['settings_role_'. $rid]['upload_uploadsize_'. $rid] = array(
187 '#type' => 'textfield',
188 '#title' => t('Maximum file size per upload'),
189 '#default_value' => variable_get('upload_uploadsize_'. $rid, $upload_uploadsize_default),
190 '#size' => 5,
191 '#maxlength' => 5,
192 '#description' => t('The maximum size of a file a user can upload. This setting is shared with the upload module.'),
193 '#field_suffix' => t('MB'),
194 );
195
196 $form['settings_role_'. $rid]['upload_usersize_'. $rid] = array(
197 '#type' => 'textfield',
198 '#title' => t('Total file size per user'),
199 '#default_value' => variable_get('upload_usersize_'. $rid, $upload_usersize_default),
200 '#size' => 5,
201 '#maxlength' => 5,
202 '#description' => t('The maximum size of all files a user can have on the site. This setting is shared with the upload module.'),
203 '#field_suffix' => t('MB'),
204 );
205
206 }
207
208 $form['#validate'] = array('flashnode_admin_settings_validate');
209
210 return system_settings_form($form);
211 }
212
213
214 /**
215 * Validate flashnode_admin_settings to ensure that flashnode_max_width and
216 * flashnode_max_height are valid (numeric and zero or positive)
217 */
218 function flashnode_admin_settings_validate($form, &$form_state) {
219
220 // Check max width - must be numeric and not negative
221 if (!is_numeric($form_state['values']['flashnode_max_width']) || $form_state['values']['flashnode_max_width'] < 0) {
222 form_set_error('flashnode_max_width', t('The maximum displayed width must be zero or a positive number.'));
223 }
224
225 // Check max height - must be numeric and not negative
226 if (!is_numeric($form_state['values']['flashnode_max_height']) || $form_state['values']['flashnode_max_height'] < 0) {
227 form_set_error('flashnode_max_height', t('The maximum displayed height must be zero or a positive number.'));
228 }
229
230 // Check teaser scale - must be numeric and not negative
231 if (!is_numeric($form_state['values']['flashnode_teaser_scale']) || $form_state['values']['flashnode_teaser_scale'] < 0) {
232 form_set_error('flashnode_teaser_scale', t('The teaser scaling factor must be zero or a positive number.'));
233 }
234
235 // Check max teaser width - must be numeric and not negative
236 if (!is_numeric($form_state['values']['flashnode_max_teaser_width']) || $form_state['values']['flashnode_max_teaser_width'] < 0) {
237 form_set_error('flashnode_max_teaser_width', t('The maximum displayed teaser width must be zero or a positive number.'));
238 }
239
240 // Check max teaser height - must be numeric and not negative
241 if (!is_numeric($form_state['values']['flashnode_max_teaser_height']) || $form_state['values']['flashnode_max_teaser_height'] < 0) {
242 form_set_error('flashnode_max_teaser_height', t('The maximum displayed teaser height must be zero or a positive number.'));
243 }
244
245
246 // Check weight - must be numeric
247 if (!is_numeric($form_state['values']['flashnode_weight'])) {
248 form_set_error('flashnode_weight', t('The weight must be number.'));
249 }
250
251 // Check upload size settings
252 $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
253 $default_usersize = $form_state['values']['upload_usersize_default'];
254
255 $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) .'<br/>';
256 $more_info = t("Depending on your server environment, these settings may be changed in the system-wide php.ini file, a php.ini file in your Drupal root directory, in your Drupal site's settings.php file, or in the .htaccess file in your Drupal root directory.");
257
258 if (!is_numeric($default_uploadsize) || ($default_uploadsize <= 0)) {
259 form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
260 }
261 if (!is_numeric($default_usersize) || ($default_usersize <= 0)) {
262 form_set_error('upload_usersize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
263 }
264 if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
265 form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
266 $more_info = '';
267 }
268 if ($default_uploadsize > $default_usersize) {
269 form_set_error('upload_uploadsize_default', t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => t('default'))));
270 }
271
272 foreach ($form_state['values']['roles'] as $rid => $role) {
273 $uploadsize = $form_state['values']['upload_uploadsize_'. $rid];
274 $usersize = $form_state['values']['upload_usersize_'. $rid];
275
276 if (!is_numeric($uploadsize) || ($uploadsize <= 0)) {
277 form_set_error('upload_uploadsize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
278 }
279 if (!is_numeric($usersize) || ($usersize <= 0)) {
280 form_set_error('upload_usersize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
281 }
282 if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
283 form_set_error('upload_uploadsize_'. $rid, $exceed_max_msg . $more_info);
284 $more_info = '';
285 }
286 if ($uploadsize > $usersize) {
287 form_set_error('upload_uploadsize_'. $rid, t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => $role)));
288 }
289 }
290 }

  ViewVC Help
Powered by ViewVC 1.1.2