Mercurial > defr > drupal > core
comparison modules/system/system.module @ 1:c1f4ac30525a 6.0
Drupal 6.0
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:28:28 +0100 |
parents | |
children | 165d43f946a8 |
comparison
equal
deleted
inserted
replaced
0:5a113a1c4740 | 1:c1f4ac30525a |
---|---|
1 <?php | |
2 // $Id: system.module,v 1.585.2.6 2008/02/13 14:25:42 goba Exp $ | |
3 | |
4 /** | |
5 * @file | |
6 * Configuration system that lets administrators modify the workings of the site. | |
7 */ | |
8 | |
9 /** | |
10 * The current system version. | |
11 */ | |
12 define('VERSION', '6.0'); | |
13 | |
14 /** | |
15 * Core API compatibility. | |
16 */ | |
17 define('DRUPAL_CORE_COMPATIBILITY', '6.x'); | |
18 | |
19 /** | |
20 * Minimum supported version of PHP. | |
21 */ | |
22 define('DRUPAL_MINIMUM_PHP', '4.3.5'); | |
23 | |
24 /** | |
25 * Minimum recommended value of PHP memory_limit. | |
26 */ | |
27 define('DRUPAL_MINIMUM_PHP_MEMORY_LIMIT', '16M'); | |
28 | |
29 /** | |
30 * Minimum supported version of MySQL, if it is used. | |
31 */ | |
32 define('DRUPAL_MINIMUM_MYSQL', '4.1.1'); | |
33 | |
34 /** | |
35 * Minimum supported version of PostgreSQL, if it is used. | |
36 */ | |
37 define('DRUPAL_MINIMUM_PGSQL', '7.4'); | |
38 | |
39 /** | |
40 * Maximum age of temporary files in seconds. | |
41 */ | |
42 define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440); | |
43 | |
44 /** | |
45 * Implementation of hook_help(). | |
46 */ | |
47 function system_help($path, $arg) { | |
48 global $base_url; | |
49 | |
50 switch ($path) { | |
51 case 'admin/help#system': | |
52 $output = '<p>'. t('The system module is at the foundation of your Drupal website, and provides basic but extensible functionality for use by other modules and themes. Some integral elements of Drupal are contained in and managed by the system module, including caching, enabling or disabling of modules and themes, preparing and displaying the administrative page, and configuring fundamental site settings. A number of key system maintenance operations are also part of the system module.') .'</p>'; | |
53 $output .= '<p>'. t('The system module provides:') .'</p>'; | |
54 $output .= '<ul><li>'. t('support for enabling and disabling <a href="@modules">modules</a>. Drupal comes packaged with a number of core modules; each module provides a discrete set of features and may be enabled depending on the needs of your site. A wide array of additional modules contributed by members of the Drupal community are available for download at the <a href="@drupal-modules">Drupal.org module page</a>.', array('@modules' => url('admin/build/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) .'</li>'; | |
55 $output .= '<li>'. t('support for enabling and disabling <a href="@themes">themes</a>, which determine the design and presentation of your site. Drupal comes packaged with several core themes and additional contributed themes are available at the <a href="@drupal-themes">Drupal.org theme page</a>.', array('@themes' => url('admin/build/themes'), '@drupal-themes' => 'http://drupal.org/project/themes')) .'</li>'; | |
56 $output .= '<li>'. t('a robust <a href="@cache-settings">caching system</a> that allows the efficient re-use of previously-constructed web pages and web page components. Drupal stores the pages requested by anonymous users in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, Drupal\'s caching system may significantly increase the speed of your site.', array('@cache-settings' => url('admin/settings/performance'))) .'</li>'; | |
57 $output .= '<li>'. t('a set of routine administrative operations that rely on a correctly-configured <a href="@cron">cron maintenance task</a> to run automatically. A number of other modules, including the feed aggregator, ping module and search also rely on <a href="@cron">cron maintenance tasks</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>.', array('@cron' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron')) .'</li>'; | |
58 $output .= '<li>'. t('basic configuration options for your site, including <a href="@date-settings">date and time settings</a>, <a href="@file-system">file system settings</a>, <a href="@clean-url">clean URL support</a>, <a href="@site-info">site name and other information</a>, and a <a href="@site-maintenance">site maintenance</a> function for taking your site temporarily off-line.', array('@date-settings' => url('admin/settings/date-time'), '@file-system' => url('admin/settings/file-system'), '@clean-url' => url('admin/settings/clean-urls'), '@site-info' => url('admin/settings/site-information'), '@site-maintenance' => url('admin/settings/site-maintenance'))) .'</li></ul>'; | |
59 $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/handbook/modules/system/')) .'</p>'; | |
60 return $output; | |
61 case 'admin': | |
62 return '<p>'. t('Welcome to the administration section. Here you may control how your site functions.') .'</p>'; | |
63 case 'admin/by-module': | |
64 return '<p>'. t('This page shows you all available administration tasks for each module.') .'</p>'; | |
65 case 'admin/build/themes': | |
66 $output = '<p>'. t('Select which themes are available to your users and specify the default theme. To configure site-wide display settings, click the "configure" task above. Alternatively, to override these settings in a specific theme, click the "configure" link for that theme. Note that different themes may have different regions available for displaying content; for consistency in presentation, you may wish to enable only one theme.') .'</p>'; | |
67 $output .= '<p>'. t('To change the appearance of your site, a number of <a href="@themes">contributed themes</a> are available.', array('@themes' => 'http://drupal.org/project/themes')) .'</p>'; | |
68 return $output; | |
69 case 'admin/build/themes/settings/'. $arg[4]: | |
70 $reference = explode('.', $arg[4], 2); | |
71 $theme = array_pop($reference); | |
72 return '<p>'. t('These options control the display settings for the <code>%template</code> theme. When your site is displayed using this theme, these settings will be used. By clicking "Reset to defaults," you can choose to use the <a href="@global">global settings</a> for this theme.', array('%template' => $theme, '@global' => url('admin/build/themes/settings'))) .'</p>'; | |
73 case 'admin/build/themes/settings': | |
74 return '<p>'. t('These options control the default display settings for your entire site, across all themes. Unless they have been overridden by a specific theme, these settings will be used.') .'</p>'; | |
75 case 'admin/build/modules': | |
76 $output = '<p>'. t('Modules are plugins that extend Drupal\'s core functionality. Enable modules by selecting the <em>Enabled</em> checkboxes below and clicking the <em>Save configuration</em> button. Once a module is enabled, new <a href="@permissions">permissions</a> may be available. To reduce server load, modules with their <em>Throttle</em> checkbox selected are temporarily disabled when your site becomes extremely busy. (Note that the <em>Throttle</em> checkbox is only available if the Throttle module is enabled.)', array('@permissions' => url('admin/user/permissions'))); | |
77 if (module_exists('throttle')) { | |
78 $output .= ' '. t('The auto-throttle functionality must be enabled on the <a href="@throttle">throttle configuration page</a> after having enabled the throttle module.', array('@throttle' => url('admin/settings/throttle'))); | |
79 } | |
80 $output .= '</p>'; | |
81 $output .= '<p>'. t('It is important that <a href="@update-php">update.php</a> is run every time a module is updated to a newer version.', array('@update-php' => $base_url .'/update.php')) .'</p>'; | |
82 $output .= '<p>'. t('You can find all administration tasks belonging to a particular module on the <a href="@by-module">administration by module page</a>.', array('@by-module' => url('admin/by-module'))) .'</p>'; | |
83 $output .= '<p>'. t('To extend the functionality of your site, a number of <a href="@modules">contributed modules</a> are available.', array('@modules' => 'http://drupal.org/project/modules')) .'</p>'; | |
84 return $output; | |
85 case 'admin/build/modules/uninstall': | |
86 return '<p>'. t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it. Not all modules support this feature.') .'</p>'; | |
87 case 'admin/build/block/configure': | |
88 if ($arg[4] == 'system' && $arg[5] == 0) { | |
89 return '<p>'. t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') .'</p>'; | |
90 } | |
91 break; | |
92 case 'admin/settings/actions': | |
93 case 'admin/settings/actions/manage': | |
94 $output = '<p>'. t('Actions are individual tasks that the system can do, such as unpublishing a piece of content or banning a user. Modules, such as the trigger module, can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions.') .'</p>'; | |
95 $output .= '<p>'. t('There are two types of actions: simple and advanced. Simple actions do not require any additional configuration, and are listed here automatically. Advanced actions can do more than simple actions; for example, send an e-mail to a specified address, or check for certain words within a piece of content. These actions need to be created and configured first before they may be used. To create an advanced action, select the action from the drop-down below and click the <em>Create</em> button.') .'</p>'; | |
96 if (module_exists('trigger')) { | |
97 $output .= '<p>'. t('You may proceed to the <a href="@url">Triggers</a> page to assign these actions to system events.', array('@url' => url('admin/build/trigger'))) .'</p>'; | |
98 } | |
99 return $output; | |
100 case 'admin/settings/actions/configure': | |
101 return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended, in order to better identify the precise action taking place. This description will be displayed in modules such as the trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Send e-mail to Moderation Team" rather than simply "Send e-mail").'); | |
102 case 'admin/reports/status': | |
103 return '<p>'. t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues.") .'</p>'; | |
104 } | |
105 } | |
106 | |
107 /** | |
108 * Implementation of hook_theme(). | |
109 */ | |
110 function system_theme() { | |
111 return array_merge(drupal_common_theme(), array( | |
112 'system_theme_select_form' => array( | |
113 'arguments' => array('form' => NULL), | |
114 'file' => 'system.admin.inc', | |
115 ), | |
116 'system_themes_form' => array( | |
117 'arguments' => array('form' => NULL), | |
118 'file' => 'system.admin.inc', | |
119 ), | |
120 'system_modules' => array( | |
121 'arguments' => array('form' => NULL), | |
122 'file' => 'system.admin.inc', | |
123 ), | |
124 'system_modules_uninstall' => array( | |
125 'arguments' => array('form' => NULL), | |
126 'file' => 'system.admin.inc', | |
127 ), | |
128 'status_report' => array( | |
129 'arguments' => array('requirements' => NULL), | |
130 'file' => 'system.admin.inc', | |
131 ), | |
132 'admin_page' => array( | |
133 'arguments' => array('blocks' => NULL), | |
134 'file' => 'system.admin.inc', | |
135 ), | |
136 'admin_block' => array( | |
137 'arguments' => array('block' => NULL), | |
138 'file' => 'system.admin.inc', | |
139 ), | |
140 'admin_block_content' => array( | |
141 'arguments' => array('content' => NULL), | |
142 'file' => 'system.admin.inc', | |
143 ), | |
144 'system_admin_by_module' => array( | |
145 'arguments' => array('menu_items' => NULL), | |
146 'file' => 'system.admin.inc', | |
147 ), | |
148 'system_powered_by' => array( | |
149 'arguments' => array('image_path' => NULL), | |
150 ), | |
151 )); | |
152 } | |
153 | |
154 /** | |
155 * Implementation of hook_perm(). | |
156 */ | |
157 function system_perm() { | |
158 return array('administer site configuration', 'access administration pages', 'administer actions', 'access site reports', 'select different theme', 'administer files'); | |
159 } | |
160 | |
161 /** | |
162 * Implementation of hook_elements(). | |
163 */ | |
164 function system_elements() { | |
165 // Top level form | |
166 $type['form'] = array('#method' => 'post', '#action' => request_uri()); | |
167 | |
168 // Inputs | |
169 $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah')); | |
170 $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, '#process' => array('form_expand_ahah')); | |
171 $type['image_button'] = array('#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL); | |
172 $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_expand_ahah')); | |
173 $type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#process' => array('form_expand_ahah')); | |
174 $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm')); | |
175 $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, '#process' => array('form_expand_ahah')); | |
176 $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios')); | |
177 $type['radio'] = array('#input' => TRUE, '#default_value' => NULL, '#process' => array('form_expand_ahah')); | |
178 $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes'), '#tree' => TRUE); | |
179 $type['checkbox'] = array('#input' => TRUE, '#return_value' => 1, '#process' => array('form_expand_ahah')); | |
180 $type['select'] = array('#input' => TRUE, '#size' => 0, '#multiple' => FALSE, '#process' => array('form_expand_ahah')); | |
181 $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight', 'form_expand_ahah')); | |
182 $type['date'] = array('#input' => TRUE, '#process' => array('expand_date'), '#element_validate' => array('date_validate')); | |
183 $type['file'] = array('#input' => TRUE, '#size' => 60); | |
184 | |
185 // Form structure | |
186 $type['item'] = array('#value' => ''); | |
187 $type['hidden'] = array('#input' => TRUE, '#process' => array('form_expand_ahah')); | |
188 $type['value'] = array('#input' => TRUE); | |
189 $type['markup'] = array('#prefix' => '', '#suffix' => ''); | |
190 $type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL, '#process' => array('form_expand_ahah')); | |
191 $type['token'] = array('#input' => TRUE); | |
192 return $type; | |
193 } | |
194 | |
195 /** | |
196 * Implementation of hook_menu(). | |
197 */ | |
198 function system_menu() { | |
199 $items['system/files'] = array( | |
200 'title' => 'File download', | |
201 'page callback' => 'file_download', | |
202 'access callback' => TRUE, | |
203 'type' => MENU_CALLBACK, | |
204 ); | |
205 $items['admin'] = array( | |
206 'title' => 'Administer', | |
207 'access arguments' => array('access administration pages'), | |
208 'page callback' => 'system_main_admin_page', | |
209 'weight' => 9, | |
210 'file' => 'system.admin.inc', | |
211 ); | |
212 $items['admin/compact'] = array( | |
213 'title' => 'Compact mode', | |
214 'page callback' => 'system_admin_compact_page', | |
215 'type' => MENU_CALLBACK, | |
216 'file' => 'system.admin.inc', | |
217 ); | |
218 $items['admin/by-task'] = array( | |
219 'title' => 'By task', | |
220 'page callback' => 'system_main_admin_page', | |
221 'file' => 'system.admin.inc', | |
222 'type' => MENU_DEFAULT_LOCAL_TASK, | |
223 ); | |
224 $items['admin/by-module'] = array( | |
225 'title' => 'By module', | |
226 'page callback' => 'system_admin_by_module', | |
227 'file' => 'system.admin.inc', | |
228 'type' => MENU_LOCAL_TASK, | |
229 'weight' => 2, | |
230 ); | |
231 $items['admin/content'] = array( | |
232 'title' => 'Content management', | |
233 'description' => "Manage your site's content.", | |
234 'position' => 'left', | |
235 'weight' => -10, | |
236 'page callback' => 'system_admin_menu_block_page', | |
237 'file' => 'system.admin.inc', | |
238 ); | |
239 | |
240 // menu items that are basically just menu blocks | |
241 $items['admin/settings'] = array( | |
242 'title' => 'Site configuration', | |
243 'description' => 'Adjust basic site configuration options.', | |
244 'position' => 'right', | |
245 'weight' => -5, | |
246 'page callback' => 'system_settings_overview', | |
247 'file' => 'system.admin.inc', | |
248 ); | |
249 $items['admin/build'] = array( | |
250 'title' => 'Site building', | |
251 'description' => 'Control how your site looks and feels.', | |
252 'position' => 'right', | |
253 'weight' => -10, | |
254 'page callback' => 'system_admin_menu_block_page', | |
255 'file' => 'system.admin.inc', | |
256 ); | |
257 $items['admin/settings/admin'] = array( | |
258 'title' => 'Administration theme', | |
259 'description' => 'Settings for how your administrative pages should look.', | |
260 'position' => 'left', | |
261 'page callback' => 'drupal_get_form', | |
262 'page arguments' => array('system_admin_theme_settings'), | |
263 'access arguments' => array('administer site configuration'), | |
264 'block callback' => 'system_admin_theme_settings', | |
265 'file' => 'system.admin.inc', | |
266 ); | |
267 // Themes: | |
268 $items['admin/build/themes'] = array( | |
269 'title' => 'Themes', | |
270 'description' => 'Change which theme your site uses or allows users to set.', | |
271 'page callback' => 'drupal_get_form', | |
272 'page arguments' => array('system_themes_form', NULL), | |
273 'access arguments' => array('administer site configuration'), | |
274 'file' => 'system.admin.inc', | |
275 ); | |
276 $items['admin/build/themes/select'] = array( | |
277 'title' => 'List', | |
278 'description' => 'Select the default theme.', | |
279 'type' => MENU_DEFAULT_LOCAL_TASK, | |
280 'weight' => -1, | |
281 ); | |
282 $items['admin/build/themes/settings'] = array( | |
283 'title' => 'Configure', | |
284 'page arguments' => array('system_theme_settings'), | |
285 'type' => MENU_LOCAL_TASK, | |
286 ); | |
287 // Theme configuration subtabs | |
288 $items['admin/build/themes/settings/global'] = array( | |
289 'title' => 'Global settings', | |
290 'type' => MENU_DEFAULT_LOCAL_TASK, | |
291 'weight' => -1, | |
292 ); | |
293 | |
294 foreach (list_themes() as $theme) { | |
295 $items['admin/build/themes/settings/'. $theme->name] = array( | |
296 'title' => $theme->info['name'], | |
297 'page arguments' => array('system_theme_settings', $theme->name), | |
298 'type' => MENU_LOCAL_TASK, | |
299 'access callback' => '_system_themes_access', | |
300 'access arguments' => array($theme), | |
301 ); | |
302 } | |
303 | |
304 // Modules: | |
305 $items['admin/build/modules'] = array( | |
306 'title' => 'Modules', | |
307 'description' => 'Enable or disable add-on modules for your site.', | |
308 'page callback' => 'drupal_get_form', | |
309 'page arguments' => array('system_modules'), | |
310 'access arguments' => array('administer site configuration'), | |
311 'file' => 'system.admin.inc', | |
312 ); | |
313 $items['admin/build/modules/list'] = array( | |
314 'title' => 'List', | |
315 'type' => MENU_DEFAULT_LOCAL_TASK, | |
316 ); | |
317 $items['admin/build/modules/list/confirm'] = array( | |
318 'title' => 'List', | |
319 'type' => MENU_CALLBACK, | |
320 ); | |
321 $items['admin/build/modules/uninstall'] = array( | |
322 'title' => 'Uninstall', | |
323 'page arguments' => array('system_modules_uninstall'), | |
324 'type' => MENU_LOCAL_TASK, | |
325 ); | |
326 $items['admin/build/modules/uninstall/confirm'] = array( | |
327 'title' => 'Uninstall', | |
328 'type' => MENU_CALLBACK, | |
329 ); | |
330 | |
331 // Actions: | |
332 $items['admin/settings/actions'] = array( | |
333 'title' => 'Actions', | |
334 'description' => 'Manage the actions defined for your site.', | |
335 'access arguments' => array('administer actions'), | |
336 'page callback' => 'system_actions_manage' | |
337 ); | |
338 $items['admin/settings/actions/manage'] = array( | |
339 'title' => 'Manage actions', | |
340 'description' => 'Manage the actions defined for your site.', | |
341 'page callback' => 'system_actions_manage', | |
342 'type' => MENU_DEFAULT_LOCAL_TASK, | |
343 'weight' => -2, | |
344 ); | |
345 $items['admin/settings/actions/configure'] = array( | |
346 'title' => 'Configure an advanced action', | |
347 'page callback' => 'drupal_get_form', | |
348 'page arguments' => array('system_actions_configure'), | |
349 'type' => MENU_CALLBACK, | |
350 ); | |
351 $items['admin/settings/actions/delete/%actions'] = array( | |
352 'title' => 'Delete action', | |
353 'description' => 'Delete an action.', | |
354 'page callback' => 'drupal_get_form', | |
355 'page arguments' => array('system_actions_delete_form', 4), | |
356 'type' => MENU_CALLBACK, | |
357 ); | |
358 $items['admin/settings/actions/orphan'] = array( | |
359 'title' => 'Remove orphans', | |
360 'page callback' => 'system_actions_remove_orphans', | |
361 'type' => MENU_CALLBACK, | |
362 ); | |
363 | |
364 // Settings: | |
365 $items['admin/settings/site-information'] = array( | |
366 'title' => 'Site information', | |
367 'description' => 'Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.', | |
368 'page callback' => 'drupal_get_form', | |
369 'page arguments' => array('system_site_information_settings'), | |
370 'access arguments' => array('administer site configuration'), | |
371 'file' => 'system.admin.inc', | |
372 ); | |
373 $items['admin/settings/error-reporting'] = array( | |
374 'title' => 'Error reporting', | |
375 'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.', | |
376 'page callback' => 'drupal_get_form', | |
377 'page arguments' => array('system_error_reporting_settings'), | |
378 'access arguments' => array('administer site configuration'), | |
379 'file' => 'system.admin.inc', | |
380 ); | |
381 $items['admin/settings/logging'] = array( | |
382 'title' => 'Logging and alerts', | |
383 'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.", | |
384 'page callback' => 'system_logging_overview', | |
385 'access arguments' => array('administer site configuration'), | |
386 'file' => 'system.admin.inc', | |
387 ); | |
388 $items['admin/settings/performance'] = array( | |
389 'title' => 'Performance', | |
390 'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.', | |
391 'page callback' => 'drupal_get_form', | |
392 'page arguments' => array('system_performance_settings'), | |
393 'access arguments' => array('administer site configuration'), | |
394 'file' => 'system.admin.inc', | |
395 ); | |
396 $items['admin/settings/file-system'] = array( | |
397 'title' => 'File system', | |
398 'description' => 'Tell Drupal where to store uploaded files and how they are accessed.', | |
399 'page callback' => 'drupal_get_form', | |
400 'page arguments' => array('system_file_system_settings'), | |
401 'access arguments' => array('administer site configuration'), | |
402 'file' => 'system.admin.inc', | |
403 ); | |
404 $items['admin/settings/image-toolkit'] = array( | |
405 'title' => 'Image toolkit', | |
406 'description' => 'Choose which image toolkit to use if you have installed optional toolkits.', | |
407 'page callback' => 'drupal_get_form', | |
408 'page arguments' => array('system_image_toolkit_settings'), | |
409 'access arguments' => array('administer site configuration'), | |
410 'file' => 'system.admin.inc', | |
411 ); | |
412 $items['admin/content/rss-publishing'] = array( | |
413 'title' => 'RSS publishing', | |
414 'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.', | |
415 'page callback' => 'drupal_get_form', | |
416 'page arguments' => array('system_rss_feeds_settings'), | |
417 'access arguments' => array('administer site configuration'), | |
418 'file' => 'system.admin.inc', | |
419 ); | |
420 $items['admin/settings/date-time'] = array( | |
421 'title' => 'Date and time', | |
422 'description' => "Settings for how Drupal displays date and time, as well as the system's default timezone.", | |
423 'page callback' => 'drupal_get_form', | |
424 'page arguments' => array('system_date_time_settings'), | |
425 'access arguments' => array('administer site configuration'), | |
426 'file' => 'system.admin.inc', | |
427 ); | |
428 $items['admin/settings/date-time/lookup'] = array( | |
429 'title' => 'Date and time lookup', | |
430 'type' => MENU_CALLBACK, | |
431 'page callback' => 'system_date_time_lookup', | |
432 'file' => 'system.admin.inc', | |
433 ); | |
434 $items['admin/settings/site-maintenance'] = array( | |
435 'title' => 'Site maintenance', | |
436 'description' => 'Take the site off-line for maintenance or bring it back online.', | |
437 'page callback' => 'drupal_get_form', | |
438 'page arguments' => array('system_site_maintenance_settings'), | |
439 'access arguments' => array('administer site configuration'), | |
440 'file' => 'system.admin.inc', | |
441 ); | |
442 $items['admin/settings/clean-urls'] = array( | |
443 'title' => 'Clean URLs', | |
444 'description' => 'Enable or disable clean URLs for your site.', | |
445 'page callback' => 'drupal_get_form', | |
446 'page arguments' => array('system_clean_url_settings'), | |
447 'access arguments' => array('administer site configuration'), | |
448 'file' => 'system.admin.inc', | |
449 ); | |
450 $items['admin/settings/clean-urls/check'] = array( | |
451 'title' => 'Clean URL check', | |
452 'page callback' => 'drupal_json', | |
453 'page arguments' => array(array('status' => TRUE)), | |
454 'access callback' => TRUE, | |
455 'type' => MENU_CALLBACK, | |
456 ); | |
457 // Menu handler to test that drupal_http_request() works locally. | |
458 // @see system_check_http_request() | |
459 $items['admin/reports/request-test'] = array( | |
460 'title' => 'Request test', | |
461 'page callback' => 'printf', | |
462 'page arguments' => array('request test'), | |
463 'access callback' => TRUE, | |
464 'type' => MENU_CALLBACK, | |
465 ); | |
466 | |
467 // Reports: | |
468 $items['admin/reports'] = array( | |
469 'title' => 'Reports', | |
470 'description' => 'View reports from system logs and other status information.', | |
471 'page callback' => 'system_admin_menu_block_page', | |
472 'access arguments' => array('access site reports'), | |
473 'weight' => 5, | |
474 'position' => 'left', | |
475 'file' => 'system.admin.inc', | |
476 ); | |
477 $items['admin/reports/status'] = array( | |
478 'title' => 'Status report', | |
479 'description' => "Get a status report about your site's operation and any detected problems.", | |
480 'page callback' => 'system_status', | |
481 'weight' => 10, | |
482 'access arguments' => array('administer site configuration'), | |
483 'file' => 'system.admin.inc', | |
484 ); | |
485 $items['admin/reports/status/run-cron'] = array( | |
486 'title' => 'Run cron', | |
487 'page callback' => 'system_run_cron', | |
488 'type' => MENU_CALLBACK, | |
489 'file' => 'system.admin.inc', | |
490 ); | |
491 $items['admin/reports/status/php'] = array( | |
492 'title' => 'PHP', | |
493 'page callback' => 'system_php', | |
494 'type' => MENU_CALLBACK, | |
495 'file' => 'system.admin.inc', | |
496 ); | |
497 $items['admin/reports/status/sql'] = array( | |
498 'title' => 'SQL', | |
499 'page callback' => 'system_sql', | |
500 'type' => MENU_CALLBACK, | |
501 'file' => 'system.admin.inc', | |
502 ); | |
503 // Default page for batch operations | |
504 $items['batch'] = array( | |
505 'page callback' => 'system_batch_page', | |
506 'access callback' => TRUE, | |
507 'type' => MENU_CALLBACK, | |
508 'file' => 'system.admin.inc', | |
509 ); | |
510 return $items; | |
511 } | |
512 | |
513 /** | |
514 * Menu item access callback - only admin or enabled themes can be accessed. | |
515 */ | |
516 function _system_themes_access($theme) { | |
517 return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', '0')); | |
518 } | |
519 | |
520 /** | |
521 * Implementation of hook_init(). | |
522 */ | |
523 function system_init() { | |
524 // Use the administrative theme if the user is looking at a page in the admin/* path. | |
525 if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) { | |
526 global $custom_theme; | |
527 $custom_theme = variable_get('admin_theme', '0'); | |
528 drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module'); | |
529 } | |
530 | |
531 // Add the CSS for this module. | |
532 drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module'); | |
533 drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module'); | |
534 drupal_add_css(drupal_get_path('module', 'system') .'/system-menus.css', 'module'); | |
535 } | |
536 | |
537 /** | |
538 * Implementation of hook_user(). | |
539 * | |
540 * Allows users to individually set their theme and time zone. | |
541 */ | |
542 function system_user($type, $edit, &$user, $category = NULL) { | |
543 if ($type == 'form' && $category == 'account') { | |
544 $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), isset($edit['theme']) ? $edit['theme'] : NULL, 2); | |
545 | |
546 if (variable_get('configurable_timezones', 1)) { | |
547 $zones = _system_zonelist(); | |
548 $form['timezone'] = array( | |
549 '#type' => 'fieldset', | |
550 '#title' => t('Locale settings'), | |
551 '#weight' => 6, | |
552 '#collapsible' => TRUE, | |
553 ); | |
554 $form['timezone']['timezone'] = array( | |
555 '#type' => 'select', | |
556 '#title' => t('Time zone'), | |
557 '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0), | |
558 '#options' => $zones, | |
559 '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'), | |
560 ); | |
561 } | |
562 | |
563 return $form; | |
564 } | |
565 } | |
566 | |
567 /** | |
568 * Implementation of hook_block(). | |
569 * | |
570 * Generate a block with a promotional link to Drupal.org. | |
571 */ | |
572 function system_block($op = 'list', $delta = 0, $edit = NULL) { | |
573 switch ($op) { | |
574 case 'list': | |
575 $blocks[0] = array( | |
576 'info' => t('Powered by Drupal'), | |
577 'weight' => '10', | |
578 // Not worth caching. | |
579 'cache' => BLOCK_NO_CACHE, | |
580 ); | |
581 return $blocks; | |
582 case 'configure': | |
583 // Compile a list of fields to show | |
584 $form['wrapper']['color'] = array( | |
585 '#type' => 'select', | |
586 '#title' => t('Badge color'), | |
587 '#default_value' => variable_get('drupal_badge_color', 'powered-blue'), | |
588 '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')), | |
589 ); | |
590 $form['wrapper']['size'] = array( | |
591 '#type' => 'select', | |
592 '#title' => t('Badge size'), | |
593 '#default_value' => variable_get('drupal_badge_size', '80x15'), | |
594 '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')), | |
595 ); | |
596 return $form; | |
597 case 'save': | |
598 variable_set('drupal_badge_color', $edit['color']); | |
599 variable_set('drupal_badge_size', $edit['size']); | |
600 break; | |
601 case 'view': | |
602 $image_path = 'misc/'. variable_get('drupal_badge_color', 'powered-blue') .'-'. variable_get('drupal_badge_size', '80x15') .'.png'; | |
603 $block['subject'] = NULL; // Don't display a title | |
604 $block['content'] = theme('system_powered_by', $image_path); | |
605 return $block; | |
606 } | |
607 } | |
608 | |
609 /** | |
610 * Provide a single block on the administration overview page. | |
611 * | |
612 * @param $item | |
613 * The menu item to be displayed. | |
614 */ | |
615 function system_admin_menu_block($item) { | |
616 $content = array(); | |
617 if (!isset($item['mlid'])) { | |
618 $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path'])); | |
619 } | |
620 $result = db_query(" | |
621 SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* | |
622 FROM {menu_links} ml | |
623 LEFT JOIN {menu_router} m ON ml.router_path = m.path | |
624 WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']); | |
625 while ($item = db_fetch_array($result)) { | |
626 _menu_link_translate($item); | |
627 if (!$item['access']) { | |
628 continue; | |
629 } | |
630 // The link 'description' either derived from the hook_menu 'description' or | |
631 // entered by the user via menu module is saved as the title attribute. | |
632 if (!empty($item['localized_options']['attributes']['title'])) { | |
633 $item['description'] = $item['localized_options']['attributes']['title']; | |
634 } | |
635 // Prepare for sorting as in function _menu_tree_check_access(). | |
636 // The weight is offset so it is always positive, with a uniform 5-digits. | |
637 $content[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $item; | |
638 } | |
639 ksort($content); | |
640 return $content; | |
641 } | |
642 | |
643 /** | |
644 * Process admin theme form submissions. | |
645 */ | |
646 function system_admin_theme_submit($form, &$form_state) { | |
647 // If we're changing themes, make sure the theme has its blocks initialized. | |
648 if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) { | |
649 $result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $form_state['values']['admin_theme'])); | |
650 if (!$result) { | |
651 system_initialize_theme_blocks($form_state['values']['admin_theme']); | |
652 } | |
653 } | |
654 } | |
655 | |
656 /** | |
657 * Returns a fieldset containing the theme select form. | |
658 * | |
659 * @param $description | |
660 * description of the fieldset | |
661 * @param $default_value | |
662 * default value of theme radios | |
663 * @param $weight | |
664 * weight of the fieldset | |
665 * @return | |
666 * a form array | |
667 */ | |
668 function system_theme_select_form($description = '', $default_value = '', $weight = 0) { | |
669 if (user_access('select different theme')) { | |
670 $enabled = array(); | |
671 $themes = list_themes(); | |
672 | |
673 foreach ($themes as $theme) { | |
674 if ($theme->status) { | |
675 $enabled[] = $theme; | |
676 } | |
677 } | |
678 | |
679 if (count($enabled) > 1) { | |
680 ksort($enabled); | |
681 | |
682 $form['themes'] = array( | |
683 '#type' => 'fieldset', | |
684 '#title' => t('Theme configuration'), | |
685 '#description' => $description, | |
686 '#collapsible' => TRUE, | |
687 '#theme' => 'system_theme_select_form' | |
688 ); | |
689 | |
690 foreach ($enabled as $info) { | |
691 // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. | |
692 $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name; | |
693 | |
694 $screenshot = NULL; | |
695 $theme_key = $info->name; | |
696 while ($theme_key) { | |
697 if (file_exists($themes[$theme_key]->info['screenshot'])) { | |
698 $screenshot = $themes[$theme_key]->info['screenshot']; | |
699 break; | |
700 } | |
701 $theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL; | |
702 } | |
703 | |
704 $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot'); | |
705 | |
706 $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot); | |
707 $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'garland') ? '<br /> <em>'. t('(site default theme)') .'</em>' : '')); | |
708 $options[$info->key] = ''; | |
709 } | |
710 | |
711 $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : ''); | |
712 $form['#weight'] = $weight; | |
713 return $form; | |
714 } | |
715 } | |
716 } | |
717 | |
718 /** | |
719 * Checks the existence of the directory specified in $form_element. This | |
720 * function is called from the system_settings form to check both the | |
721 * file_directory_path and file_directory_temp directories. If validation | |
722 * fails, the form element is flagged with an error from within the | |
723 * file_check_directory function. | |
724 * | |
725 * @param $form_element | |
726 * The form element containing the name of the directory to check. | |
727 */ | |
728 function system_check_directory($form_element) { | |
729 file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]); | |
730 return $form_element; | |
731 } | |
732 | |
733 /** | |
734 * Retrieves the current status of an array of files in the system table. | |
735 * | |
736 * @param $files | |
737 * An array of files to check. | |
738 * @param $type | |
739 * The type of the files. | |
740 */ | |
741 function system_get_files_database(&$files, $type) { | |
742 // Extract current files from database. | |
743 $result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type); | |
744 while ($file = db_fetch_object($result)) { | |
745 if (isset($files[$file->name]) && is_object($files[$file->name])) { | |
746 $file->old_filename = $file->filename; | |
747 foreach ($file as $key => $value) { | |
748 if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) { | |
749 $files[$file->name]->$key = $value; | |
750 } | |
751 } | |
752 } | |
753 } | |
754 } | |
755 | |
756 /** | |
757 * Prepare defaults for themes. | |
758 * | |
759 * @return | |
760 * An array of default themes settings. | |
761 */ | |
762 function system_theme_default() { | |
763 return array( | |
764 'regions' => array( | |
765 'left' => 'Left sidebar', | |
766 'right' => 'Right sidebar', | |
767 'content' => 'Content', | |
768 'header' => 'Header', | |
769 'footer' => 'Footer', | |
770 ), | |
771 'description' => '', | |
772 'features' => array( | |
773 'comment_user_picture', | |
774 'favicon', | |
775 'mission', | |
776 'logo', | |
777 'name', | |
778 'node_user_picture', | |
779 'search', | |
780 'slogan', | |
781 'primary_links', | |
782 'secondary_links', | |
783 ), | |
784 'stylesheets' => array( | |
785 'all' => array('style.css') | |
786 ), | |
787 'scripts' => array('script.js'), | |
788 'screenshot' => 'screenshot.png', | |
789 'php' => DRUPAL_MINIMUM_PHP, | |
790 ); | |
791 } | |
792 | |
793 /** | |
794 * Collect data about all currently available themes. | |
795 * | |
796 * @return | |
797 * Array of all available themes and their data. | |
798 */ | |
799 function system_theme_data() { | |
800 // Scan the installation theme .info files and their engines. | |
801 $themes = _system_theme_data(); | |
802 | |
803 // Extract current files from database. | |
804 system_get_files_database($themes, 'theme'); | |
805 | |
806 db_query("DELETE FROM {system} WHERE type = 'theme'"); | |
807 | |
808 foreach ($themes as $theme) { | |
809 if (!isset($theme->owner)) { | |
810 $theme->owner = ''; | |
811 } | |
812 | |
813 db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, isset($theme->status) ? $theme->status : 0, 0, 0); | |
814 } | |
815 | |
816 return $themes; | |
817 } | |
818 | |
819 /** | |
820 * Helper function to scan and collect theme .info data and their engines. | |
821 * | |
822 * @return | |
823 * An associative array of themes information. | |
824 */ | |
825 function _system_theme_data() { | |
826 static $themes_info = array(); | |
827 | |
828 if (empty($theme_info)) { | |
829 // Find themes | |
830 $themes = drupal_system_listing('\.info$', 'themes'); | |
831 // Find theme engines | |
832 $engines = drupal_system_listing('\.engine$', 'themes/engines'); | |
833 | |
834 $defaults = system_theme_default(); | |
835 | |
836 $sub_themes = array(); | |
837 // Read info files for each theme | |
838 foreach ($themes as $key => $theme) { | |
839 $themes[$key]->info = drupal_parse_info_file($theme->filename) + $defaults; | |
840 | |
841 // Invoke hook_system_info_alter() to give installed modules a chance to | |
842 // modify the data in the .info files if necessary. | |
843 drupal_alter('system_info', $themes[$key]->info, $themes[$key]); | |
844 | |
845 if (!empty($themes[$key]->info['base theme'])) { | |
846 $sub_themes[] = $key; | |
847 } | |
848 if (empty($themes[$key]->info['engine'])) { | |
849 $filename = dirname($themes[$key]->filename) .'/'. $themes[$key]->name .'.theme'; | |
850 if (file_exists($filename)) { | |
851 $themes[$key]->owner = $filename; | |
852 $themes[$key]->prefix = $key; | |
853 } | |
854 } | |
855 else { | |
856 $engine = $themes[$key]->info['engine']; | |
857 if (isset($engines[$engine])) { | |
858 $themes[$key]->owner = $engines[$engine]->filename; | |
859 $themes[$key]->prefix = $engines[$engine]->name; | |
860 $themes[$key]->template = TRUE; | |
861 } | |
862 } | |
863 | |
864 // Give the stylesheets proper path information. | |
865 $pathed_stylesheets = array(); | |
866 foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) { | |
867 foreach ($stylesheets as $stylesheet) { | |
868 $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filename) .'/'. $stylesheet; | |
869 } | |
870 } | |
871 $themes[$key]->info['stylesheets'] = $pathed_stylesheets; | |
872 | |
873 // Give the scripts proper path information. | |
874 $scripts = array(); | |
875 foreach ($themes[$key]->info['scripts'] as $script) { | |
876 $scripts[$script] = dirname($themes[$key]->filename) .'/'. $script; | |
877 } | |
878 $themes[$key]->info['scripts'] = $scripts; | |
879 // Give the screenshot proper path information. | |
880 if (!empty($themes[$key]->info['screenshot'])) { | |
881 $themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['screenshot']; | |
882 } | |
883 } | |
884 | |
885 // Now that we've established all our master themes, go back and fill in | |
886 // data for subthemes. | |
887 foreach ($sub_themes as $key) { | |
888 $base_key = system_find_base_theme($themes, $key); | |
889 if (!$base_key) { | |
890 continue; | |
891 } | |
892 // Copy the 'owner' and 'engine' over if the top level theme uses a | |
893 // theme engine. | |
894 if (isset($themes[$base_key]->owner)) { | |
895 if (isset($themes[$base_key]->info['engine'])) { | |
896 $themes[$key]->info['engine'] = $themes[$base_key]->info['engine']; | |
897 $themes[$key]->owner = $themes[$base_key]->owner; | |
898 $themes[$key]->prefix = $themes[$base_key]->prefix; | |
899 } | |
900 else { | |
901 $themes[$key]->prefix = $key; | |
902 } | |
903 } | |
904 } | |
905 | |
906 $themes_info = $themes; | |
907 } | |
908 | |
909 return $themes_info; | |
910 } | |
911 | |
912 /** | |
913 * Recursive function to find the top level base theme. Themes can inherit | |
914 * templates and function implementations from earlier themes. | |
915 * | |
916 * @param $themes | |
917 * An array of available themes. | |
918 * @param $key | |
919 * The name of the theme whose base we are looking for. | |
920 * @param $used_keys | |
921 * A recursion parameter preventing endless loops. | |
922 * @return | |
923 * Returns the top level parent that has no ancestor or returns NULL if there isn't a valid parent. | |
924 */ | |
925 function system_find_base_theme($themes, $key, $used_keys = array()) { | |
926 $base_key = $themes[$key]->info['base theme']; | |
927 // Does the base theme exist? | |
928 if (!isset($themes[$base_key])) { | |
929 return NULL; | |
930 } | |
931 | |
932 // Is the base theme itself a child of another theme? | |
933 if (isset($themes[$base_key]->info['base theme'])) { | |
934 // Prevent loops. | |
935 if (!empty($used_keys[$base_key])) { | |
936 return NULL; | |
937 } | |
938 $used_keys[$base_key] = TRUE; | |
939 return system_find_base_theme($themes, $base_key, $used_keys); | |
940 } | |
941 // If we get here, then this is our parent theme. | |
942 return $base_key; | |
943 } | |
944 | |
945 /** | |
946 * Get a list of available regions from a specified theme. | |
947 * | |
948 * @param $theme_key | |
949 * The name of a theme. | |
950 * @return | |
951 * An array of regions in the form $region['name'] = 'description'. | |
952 */ | |
953 function system_region_list($theme_key) { | |
954 static $list = array(); | |
955 | |
956 if (!array_key_exists($theme_key, $list)) { | |
957 $info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key))); | |
958 $list[$theme_key] = array_map('t', $info['regions']); | |
959 } | |
960 | |
961 return $list[$theme_key]; | |
962 } | |
963 | |
964 /** | |
965 * Get the name of the default region for a given theme. | |
966 * | |
967 * @param $theme | |
968 * The name of a theme. | |
969 * @return | |
970 * A string that is the region name. | |
971 */ | |
972 function system_default_region($theme) { | |
973 $regions = array_keys(system_region_list($theme)); | |
974 return isset($regions[0]) ? $regions[0] : ''; | |
975 } | |
976 | |
977 /** | |
978 * Assign an initial, default set of blocks for a theme. | |
979 * | |
980 * This function is called the first time a new theme is enabled. The new theme | |
981 * gets a copy of the default theme's blocks, with the difference that if a | |
982 * particular region isn't available in the new theme, the block is assigned | |
983 * to the new theme's default region. | |
984 * | |
985 * @param $theme | |
986 * The name of a theme. | |
987 */ | |
988 function system_initialize_theme_blocks($theme) { | |
989 // Initialize theme's blocks if none already registered. | |
990 if (!(db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $theme)))) { | |
991 $default_theme = variable_get('theme_default', 'garland'); | |
992 $regions = system_region_list($theme); | |
993 $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme); | |
994 while ($block = db_fetch_array($result)) { | |
995 // If the region isn't supported by the theme, assign the block to the theme's default region. | |
996 if (!array_key_exists($block['region'], $regions)) { | |
997 $block['region'] = system_default_region($theme); | |
998 } | |
999 db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, %d)", | |
1000 $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['cache']); | |
1001 } | |
1002 } | |
1003 } | |
1004 | |
1005 /** | |
1006 * Add default buttons to a form and set its prefix. | |
1007 * | |
1008 * @ingroup forms | |
1009 * @see system_settings_form_submit() | |
1010 * @param $form | |
1011 * An associative array containing the structure of the form. | |
1012 * @return | |
1013 * The form structure. | |
1014 */ | |
1015 function system_settings_form($form) { | |
1016 $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); | |
1017 $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); | |
1018 | |
1019 if (!empty($_POST) && form_get_errors()) { | |
1020 drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); | |
1021 } | |
1022 $form['#submit'][] = 'system_settings_form_submit'; | |
1023 $form['#theme'] = 'system_settings_form'; | |
1024 return $form; | |
1025 } | |
1026 | |
1027 /** | |
1028 * Execute the system_settings_form. | |
1029 * | |
1030 * If you want node type configure style handling of your checkboxes, | |
1031 * add an array_filter value to your form. | |
1032 */ | |
1033 function system_settings_form_submit($form, &$form_state) { | |
1034 $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; | |
1035 | |
1036 // Exclude unnecessary elements. | |
1037 unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']); | |
1038 | |
1039 foreach ($form_state['values'] as $key => $value) { | |
1040 if ($op == t('Reset to defaults')) { | |
1041 variable_del($key); | |
1042 } | |
1043 else { | |
1044 if (is_array($value) && isset($form_state['values']['array_filter'])) { | |
1045 $value = array_keys(array_filter($value)); | |
1046 } | |
1047 variable_set($key, $value); | |
1048 } | |
1049 } | |
1050 if ($op == t('Reset to defaults')) { | |
1051 drupal_set_message(t('The configuration options have been reset to their default values.')); | |
1052 } | |
1053 else { | |
1054 drupal_set_message(t('The configuration options have been saved.')); | |
1055 } | |
1056 | |
1057 cache_clear_all(); | |
1058 drupal_rebuild_theme_registry(); | |
1059 } | |
1060 | |
1061 /** | |
1062 * Helper function to sort requirements. | |
1063 */ | |
1064 function _system_sort_requirements($a, $b) { | |
1065 if (!isset($a['weight'])) { | |
1066 if (!isset($b['weight'])) { | |
1067 return strcmp($a['title'], $b['title']); | |
1068 } | |
1069 return -$b['weight']; | |
1070 } | |
1071 return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight']; | |
1072 } | |
1073 | |
1074 /** | |
1075 * Implementation of hook_node_type(). | |
1076 * | |
1077 * Updates theme settings after a node type change. | |
1078 */ | |
1079 function system_node_type($op, $info) { | |
1080 if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { | |
1081 $old = 'toggle_node_info_'. $info->old_type; | |
1082 $new = 'toggle_node_info_'. $info->type; | |
1083 | |
1084 $theme_settings = variable_get('theme_settings', array()); | |
1085 if (isset($theme_settings[$old])) { | |
1086 $theme_settings[$new] = $theme_settings[$old]; | |
1087 unset($theme_settings[$old]); | |
1088 variable_set('theme_settings', $theme_settings); | |
1089 } | |
1090 } | |
1091 } | |
1092 | |
1093 /** | |
1094 * Output a confirmation form | |
1095 * | |
1096 * This function returns a complete form for confirming an action. A link is | |
1097 * offered to go back to the item that is being changed in case the user changes | |
1098 * his/her mind. | |
1099 * | |
1100 * If the submit handler for this form is invoked, the user successfully | |
1101 * confirmed the action. You should never directly inspect $_POST to see if an | |
1102 * action was confirmed. | |
1103 * | |
1104 * @ingroup forms | |
1105 * @param $form | |
1106 * Additional elements to inject into the form, for example hidden elements. | |
1107 * @param $question | |
1108 * The question to ask the user (e.g. "Are you sure you want to delete the | |
1109 * block <em>foo</em>?"). | |
1110 * @param $path | |
1111 * The page to go to if the user denies the action. | |
1112 * Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'. | |
1113 * @param $description | |
1114 * Additional text to display (defaults to "This action cannot be undone."). | |
1115 * @param $yes | |
1116 * A caption for the button which confirms the action (e.g. "Delete", | |
1117 * "Replace", ...). | |
1118 * @param $no | |
1119 * A caption for the link which denies the action (e.g. "Cancel"). | |
1120 * @param $name | |
1121 * The internal name used to refer to the confirmation item. | |
1122 * @return | |
1123 * The form. | |
1124 */ | |
1125 function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') { | |
1126 $description = isset($description) ? $description : t('This action cannot be undone.'); | |
1127 | |
1128 // Prepare cancel link | |
1129 $query = $fragment = NULL; | |
1130 if (is_array($path)) { | |
1131 $query = isset($path['query']) ? $path['query'] : NULL; | |
1132 $fragment = isset($path['fragment']) ? $path['fragment'] : NULL; | |
1133 $path = isset($path['path']) ? $path['path'] : NULL; | |
1134 } | |
1135 $cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment)); | |
1136 | |
1137 drupal_set_title($question); | |
1138 | |
1139 // Confirm form fails duplication check, as the form values rarely change -- so skip it. | |
1140 $form['#skip_duplicate_check'] = TRUE; | |
1141 | |
1142 $form['#attributes'] = array('class' => 'confirmation'); | |
1143 $form['description'] = array('#value' => $description); | |
1144 $form[$name] = array('#type' => 'hidden', '#value' => 1); | |
1145 | |
1146 $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>'); | |
1147 $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm')); | |
1148 $form['actions']['cancel'] = array('#value' => $cancel); | |
1149 $form['#theme'] = 'confirm_form'; | |
1150 return $form; | |
1151 } | |
1152 | |
1153 /** | |
1154 * Determine if a user is in compact mode. | |
1155 */ | |
1156 function system_admin_compact_mode() { | |
1157 global $user; | |
1158 return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE); | |
1159 } | |
1160 | |
1161 /** | |
1162 * Generate a list of tasks offered by a specified module. | |
1163 * | |
1164 * @param $module | |
1165 * Module name. | |
1166 * @return | |
1167 * An array of task links. | |
1168 */ | |
1169 function system_get_module_admin_tasks($module) { | |
1170 static $items; | |
1171 | |
1172 $admin_access = user_access('administer permissions'); | |
1173 $admin_tasks = array(); | |
1174 | |
1175 if (!isset($items)) { | |
1176 $result = db_query(" | |
1177 SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.* | |
1178 FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.link_path LIKE 'admin/%' AND hidden >= 0 AND module = 'system' AND m.number_parts > 2"); | |
1179 $items = array(); | |
1180 while ($item = db_fetch_array($result)) { | |
1181 _menu_link_translate($item); | |
1182 if ($item['access']) { | |
1183 $items[$item['router_path']] = $item; | |
1184 } | |
1185 } | |
1186 } | |
1187 $admin_tasks = array(); | |
1188 $admin_task_count = 0; | |
1189 // Check for permissions. | |
1190 if (module_hook($module, 'perm') && $admin_access) { | |
1191 $admin_tasks[-1] = l(t('Configure permissions'), 'admin/user/permissions', array('fragment' => 'module-'. $module)); | |
1192 } | |
1193 | |
1194 // Check for menu items that are admin links. | |
1195 if ($menu = module_invoke($module, 'menu')) { | |
1196 foreach (array_keys($menu) as $path) { | |
1197 if (isset($items[$path])) { | |
1198 $admin_tasks[$items[$path]['title'] . $admin_task_count ++] = l($items[$path]['title'], $path); | |
1199 } | |
1200 } | |
1201 } | |
1202 | |
1203 return $admin_tasks; | |
1204 } | |
1205 | |
1206 /** | |
1207 * Implementation of hook_cron(). | |
1208 * | |
1209 * Remove older rows from flood and batch table. Remove old temporary files. | |
1210 */ | |
1211 function system_cron() { | |
1212 // Cleanup the flood. | |
1213 db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600); | |
1214 // Cleanup the batch table. | |
1215 db_query('DELETE FROM {batch} WHERE timestamp < %d', time() - 864000); | |
1216 | |
1217 // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. | |
1218 $result = db_query('SELECT * FROM {files} WHERE status = %d and timestamp < %d', FILE_STATUS_TEMPORARY, time() - DRUPAL_MAXIMUM_TEMP_FILE_AGE); | |
1219 while ($file = db_fetch_object($result)) { | |
1220 if (file_exists($file->filepath)) { | |
1221 // If files that exist cannot be deleted, continue so the database remains | |
1222 // consistent. | |
1223 if (!file_delete($file->filepath)) { | |
1224 watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->filepath), 'error'); | |
1225 continue; | |
1226 } | |
1227 } | |
1228 db_query('DELETE FROM {files} WHERE fid = %d', $file->fid); | |
1229 } | |
1230 } | |
1231 | |
1232 /** | |
1233 * Implementation of hook_hook_info(). | |
1234 */ | |
1235 function system_hook_info() { | |
1236 return array( | |
1237 'system' => array( | |
1238 'cron' => array( | |
1239 'run' => array( | |
1240 'runs when' => t('When cron runs'), | |
1241 ), | |
1242 ), | |
1243 ), | |
1244 ); | |
1245 } | |
1246 | |
1247 /** | |
1248 * Implementation of hook_action_info(). | |
1249 */ | |
1250 function system_action_info() { | |
1251 return array( | |
1252 'system_message_action' => array( | |
1253 'type' => 'system', | |
1254 'description' => t('Display a message to the user'), | |
1255 'configurable' => TRUE, | |
1256 'hooks' => array( | |
1257 'nodeapi' => array('view', 'insert', 'update', 'delete'), | |
1258 'comment' => array('view', 'insert', 'update', 'delete'), | |
1259 'user' => array('view', 'insert', 'update', 'delete', 'login'), | |
1260 'taxonomy' => array('insert', 'update', 'delete'), | |
1261 ), | |
1262 ), | |
1263 'system_send_email_action' => array( | |
1264 'description' => t('Send e-mail'), | |
1265 'type' => 'system', | |
1266 'configurable' => TRUE, | |
1267 'hooks' => array( | |
1268 'nodeapi' => array('view', 'insert', 'update', 'delete'), | |
1269 'comment' => array('view', 'insert', 'update', 'delete'), | |
1270 'user' => array('view', 'insert', 'update', 'delete', 'login'), | |
1271 'taxonomy' => array('insert', 'update', 'delete'), | |
1272 ) | |
1273 ), | |
1274 'system_goto_action' => array( | |
1275 'description' => t('Redirect to URL'), | |
1276 'type' => 'system', | |
1277 'configurable' => TRUE, | |
1278 'hooks' => array( | |
1279 'nodeapi' => array('view', 'insert', 'update', 'delete'), | |
1280 'comment' => array('view', 'insert', 'update', 'delete'), | |
1281 'user' => array('view', 'insert', 'update', 'delete', 'login'), | |
1282 ) | |
1283 ) | |
1284 ); | |
1285 } | |
1286 | |
1287 /** | |
1288 * Menu callback. Display an overview of available and configured actions. | |
1289 */ | |
1290 function system_actions_manage() { | |
1291 $output = ''; | |
1292 $actions = actions_list(); | |
1293 actions_synchronize($actions); | |
1294 $actions_map = actions_actions_map($actions); | |
1295 $options = array(t('Choose an advanced action')); | |
1296 $unconfigurable = array(); | |
1297 | |
1298 foreach ($actions_map as $key => $array) { | |
1299 if ($array['configurable']) { | |
1300 $options[$key] = $array['description'] .'...'; | |
1301 } | |
1302 else { | |
1303 $unconfigurable[] = $array; | |
1304 } | |
1305 } | |
1306 | |
1307 $row = array(); | |
1308 $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters != ''")); | |
1309 $header = array( | |
1310 array('data' => t('Action type'), 'field' => 'type'), | |
1311 array('data' => t('Description'), 'field' => 'description'), | |
1312 array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2') | |
1313 ); | |
1314 $sql = 'SELECT * FROM {actions}'; | |
1315 $result = pager_query($sql . tablesort_sql($header), 50); | |
1316 while ($action = db_fetch_object($result)) { | |
1317 $row[] = array( | |
1318 array('data' => $action->type), | |
1319 array('data' => $action->description), | |
1320 array('data' => $action->parameters ? l(t('configure'), "admin/settings/actions/configure/$action->aid") : ''), | |
1321 array('data' => $action->parameters ? l(t('delete'), "admin/settings/actions/delete/$action->aid") : '') | |
1322 ); | |
1323 } | |
1324 | |
1325 if ($row) { | |
1326 $pager = theme('pager', NULL, 50, 0); | |
1327 if (!empty($pager)) { | |
1328 $row[] = array(array('data' => $pager, 'colspan' => '3')); | |
1329 } | |
1330 $output .= '<h3>'. t('Actions available to Drupal:') .'</h3>'; | |
1331 $output .= theme('table', $header, $row); | |
1332 } | |
1333 | |
1334 if ($actions_map) { | |
1335 $output .= drupal_get_form('system_actions_manage_form', $options); | |
1336 } | |
1337 | |
1338 return $output; | |
1339 } | |
1340 | |
1341 /** | |
1342 * Define the form for the actions overview page. | |
1343 * | |
1344 * @see system_actions_manage_form_submit() | |
1345 * @ingroup forms | |
1346 * @param $form_state | |
1347 * An associative array containing the current state of the form; not used. | |
1348 * @param $options | |
1349 * An array of configurable actions. | |
1350 * @return | |
1351 * Form definition. | |
1352 */ | |
1353 function system_actions_manage_form($form_state, $options = array()) { | |
1354 $form['parent'] = array( | |
1355 '#type' => 'fieldset', | |
1356 '#title' => t('Make a new advanced action available'), | |
1357 '#prefix' => '<div class="container-inline">', | |
1358 '#suffix' => '</div>', | |
1359 ); | |
1360 $form['parent']['action'] = array( | |
1361 '#type' => 'select', | |
1362 '#default_value' => '', | |
1363 '#options' => $options, | |
1364 '#description' => '', | |
1365 ); | |
1366 $form['parent']['buttons']['submit'] = array( | |
1367 '#type' => 'submit', | |
1368 '#value' => t('Create'), | |
1369 ); | |
1370 return $form; | |
1371 } | |
1372 | |
1373 /** | |
1374 * Process system_actions_manage form submissions. | |
1375 */ | |
1376 function system_actions_manage_form_submit($form, &$form_state) { | |
1377 if ($form_state['values']['action']) { | |
1378 $form_state['redirect'] = 'admin/settings/actions/configure/'. $form_state['values']['action']; | |
1379 } | |
1380 } | |
1381 | |
1382 /** | |
1383 * Menu callback. Create the form for configuration of a single action. | |
1384 * | |
1385 * We provide the "Description" field. The rest of the form | |
1386 * is provided by the action. We then provide the Save button. | |
1387 * Because we are combining unknown form elements with the action | |
1388 * configuration form, we use actions_ prefix on our elements. | |
1389 * | |
1390 * @see system_actions_configure_validate() | |
1391 * @see system_actions_configure_submit() | |
1392 * @param $action | |
1393 * md5 hash of action ID or an integer. If it's an md5 hash, we | |
1394 * are creating a new instance. If it's an integer, we're editing | |
1395 * an existing instance. | |
1396 * @return | |
1397 * Form definition. | |
1398 */ | |
1399 function system_actions_configure($form_state, $action = NULL) { | |
1400 if ($action === NULL) { | |
1401 drupal_goto('admin/settings/actions'); | |
1402 } | |
1403 | |
1404 $actions_map = actions_actions_map(actions_list()); | |
1405 $edit = array(); | |
1406 | |
1407 // Numeric action denotes saved instance of a configurable action; | |
1408 // else we are creating a new action instance. | |
1409 if (is_numeric($action)) { | |
1410 $aid = $action; | |
1411 // Load stored parameter values from database. | |
1412 $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", intval($aid))); | |
1413 $edit['actions_description'] = $data->description; | |
1414 $edit['actions_type'] = $data->type; | |
1415 $function = $data->callback; | |
1416 $action = md5($data->callback); | |
1417 $params = unserialize($data->parameters); | |
1418 if ($params) { | |
1419 foreach ($params as $name => $val) { | |
1420 $edit[$name] = $val; | |
1421 } | |
1422 } | |
1423 } | |
1424 else { | |
1425 $function = $actions_map[$action]['callback']; | |
1426 $edit['actions_description'] = $actions_map[$action]['description']; | |
1427 $edit['actions_type'] = $actions_map[$action]['type']; | |
1428 } | |
1429 | |
1430 $form['actions_description'] = array( | |
1431 '#type' => 'textfield', | |
1432 '#title' => t('Description'), | |
1433 '#default_value' => $edit['actions_description'], | |
1434 '#maxlength' => '255', | |
1435 '#description' => t('A unique description for this advanced action. This description will be displayed in the interface of modules that integrate with actions, such as Trigger module.'), | |
1436 '#weight' => -10 | |
1437 ); | |
1438 $action_form = $function .'_form'; | |
1439 $form = array_merge($form, $action_form($edit)); | |
1440 $form['actions_type'] = array( | |
1441 '#type' => 'value', | |
1442 '#value' => $edit['actions_type'], | |
1443 ); | |
1444 $form['actions_action'] = array( | |
1445 '#type' => 'hidden', | |
1446 '#value' => $action, | |
1447 ); | |
1448 // $aid is set when configuring an existing action instance. | |
1449 if (isset($aid)) { | |
1450 $form['actions_aid'] = array( | |
1451 '#type' => 'hidden', | |
1452 '#value' => $aid, | |
1453 ); | |
1454 } | |
1455 $form['actions_configured'] = array( | |
1456 '#type' => 'hidden', | |
1457 '#value' => '1', | |
1458 ); | |
1459 $form['buttons']['submit'] = array( | |
1460 '#type' => 'submit', | |
1461 '#value' => t('Save'), | |
1462 '#weight' => 13 | |
1463 ); | |
1464 | |
1465 return $form; | |
1466 } | |
1467 | |
1468 /** | |
1469 * Validate system_actions_configure form submissions. | |
1470 */ | |
1471 function system_actions_configure_validate($form, $form_state) { | |
1472 $function = actions_function_lookup($form_state['values']['actions_action']) .'_validate'; | |
1473 // Hand off validation to the action. | |
1474 if (function_exists($function)) { | |
1475 $function($form, $form_state); | |
1476 } | |
1477 } | |
1478 | |
1479 /** | |
1480 * Process system_actions_configure form submissions. | |
1481 */ | |
1482 function system_actions_configure_submit($form, &$form_state) { | |
1483 $function = actions_function_lookup($form_state['values']['actions_action']); | |
1484 $submit_function = $function .'_submit'; | |
1485 | |
1486 // Action will return keyed array of values to store. | |
1487 $params = $submit_function($form, $form_state); | |
1488 $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL; | |
1489 | |
1490 actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid); | |
1491 drupal_set_message(t('The action has been successfully saved.')); | |
1492 | |
1493 $form_state['redirect'] = 'admin/settings/actions/manage'; | |
1494 } | |
1495 | |
1496 /** | |
1497 * Create the form for confirmation of deleting an action. | |
1498 * | |
1499 * @ingroup forms | |
1500 * @see system_actions_delete_form_submit() | |
1501 */ | |
1502 function system_actions_delete_form($form_state, $action) { | |
1503 | |
1504 $form['aid'] = array( | |
1505 '#type' => 'hidden', | |
1506 '#value' => $action->aid, | |
1507 ); | |
1508 return confirm_form($form, | |
1509 t('Are you sure you want to delete the action %action?', array('%action' => $action->description)), | |
1510 'admin/settings/actions/manage', | |
1511 t('This cannot be undone.'), | |
1512 t('Delete'), t('Cancel') | |
1513 ); | |
1514 } | |
1515 | |
1516 /** | |
1517 * Process system_actions_delete form submissions. | |
1518 * | |
1519 * Post-deletion operations for action deletion. | |
1520 */ | |
1521 function system_actions_delete_form_submit($form, &$form_state) { | |
1522 $aid = $form_state['values']['aid']; | |
1523 $action = actions_load($aid); | |
1524 actions_delete($aid); | |
1525 $description = check_plain($action->description); | |
1526 watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $description)); | |
1527 drupal_set_message(t('Action %action was deleted', array('%action' => $description))); | |
1528 $form_state['redirect'] = 'admin/settings/actions/manage'; | |
1529 } | |
1530 | |
1531 /** | |
1532 * Post-deletion operations for deleting action orphans. | |
1533 * | |
1534 * @param $orphaned | |
1535 * An array of orphaned actions. | |
1536 */ | |
1537 function system_action_delete_orphans_post($orphaned) { | |
1538 foreach ($orphaned as $callback) { | |
1539 drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback))); | |
1540 } | |
1541 } | |
1542 | |
1543 /** | |
1544 * Remove actions that are in the database but not supported by any enabled module. | |
1545 */ | |
1546 function system_actions_remove_orphans() { | |
1547 actions_synchronize(actions_list(), TRUE); | |
1548 drupal_goto('admin/settings/actions/manage'); | |
1549 } | |
1550 | |
1551 /** | |
1552 * Return a form definition so the Send email action can be configured. | |
1553 * | |
1554 * @see system_send_email_action_validate() | |
1555 * @see system_send_email_action_submit() | |
1556 * @param $context | |
1557 * Default values (if we are editing an existing action instance). | |
1558 * @return | |
1559 * Form definition. | |
1560 */ | |
1561 function system_send_email_action_form($context) { | |
1562 // Set default values for form. | |
1563 if (!isset($context['recipient'])) { | |
1564 $context['recipient'] = ''; | |
1565 } | |
1566 if (!isset($context['subject'])) { | |
1567 $context['subject'] = ''; | |
1568 } | |
1569 if (!isset($context['message'])) { | |
1570 $context['message'] = ''; | |
1571 } | |
1572 | |
1573 $form['recipient'] = array( | |
1574 '#type' => 'textfield', | |
1575 '#title' => t('Recipient'), | |
1576 '#default_value' => $context['recipient'], | |
1577 '#maxlength' => '254', | |
1578 '#description' => t('The email address to which the message should be sent OR enter %author if you would like to send an e-mail to the author of the original post.', array('%author' => '%author')), | |
1579 ); | |
1580 $form['subject'] = array( | |
1581 '#type' => 'textfield', | |
1582 '#title' => t('Subject'), | |
1583 '#default_value' => $context['subject'], | |
1584 '#maxlength' => '254', | |
1585 '#description' => t('The subject of the message.'), | |
1586 ); | |
1587 $form['message'] = array( | |
1588 '#type' => 'textarea', | |
1589 '#title' => t('Message'), | |
1590 '#default_value' => $context['message'], | |
1591 '#cols' => '80', | |
1592 '#rows' => '20', | |
1593 '#description' => t('The message that should be sent. You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body. Not all variables will be available in all contexts.'), | |
1594 ); | |
1595 return $form; | |
1596 } | |
1597 | |
1598 /** | |
1599 * Validate system_send_email_action form submissions. | |
1600 */ | |
1601 function system_send_email_action_validate($form, $form_state) { | |
1602 $form_values = $form_state['values']; | |
1603 // Validate the configuration form. | |
1604 if (!valid_email_address($form_values['recipient']) && $form_values['recipient'] != '%author') { | |
1605 // We want the literal %author placeholder to be emphasized in the error message. | |
1606 form_set_error('recipient', t('Please enter a valid email address or %author.', array('%author' => '%author'))); | |
1607 } | |
1608 } | |
1609 | |
1610 /** | |
1611 * Process system_send_email_action form submissions. | |
1612 */ | |
1613 function system_send_email_action_submit($form, $form_state) { | |
1614 $form_values = $form_state['values']; | |
1615 // Process the HTML form to store configuration. The keyed array that | |
1616 // we return will be serialized to the database. | |
1617 $params = array( | |
1618 'recipient' => $form_values['recipient'], | |
1619 'subject' => $form_values['subject'], | |
1620 'message' => $form_values['message'], | |
1621 ); | |
1622 return $params; | |
1623 } | |
1624 | |
1625 /** | |
1626 * Implementation of a configurable Drupal action. Sends an email. | |
1627 */ | |
1628 function system_send_email_action($object, $context) { | |
1629 global $user; | |
1630 | |
1631 switch ($context['hook']) { | |
1632 case 'nodeapi': | |
1633 // Because this is not an action of type 'node' the node | |
1634 // will not be passed as $object, but it will still be available | |
1635 // in $context. | |
1636 $node = $context['node']; | |
1637 break; | |
1638 // The comment hook provides nid, in $context. | |
1639 case 'comment': | |
1640 $comment = $context['comment']; | |
1641 $node = node_load($comment->nid); | |
1642 break; | |
1643 case 'user': | |
1644 // Because this is not an action of type 'user' the user | |
1645 // object is not passed as $object, but it will still be available | |
1646 // in $context. | |
1647 $account = $context['account']; | |
1648 if (isset($context['node'])) { | |
1649 $node = $context['node']; | |
1650 } | |
1651 elseif ($context['recipient'] == '%author') { | |
1652 // If we don't have a node, we don't have a node author. | |
1653 watchdog('error', 'Cannot use %author token in this context.'); | |
1654 return; | |
1655 } | |
1656 break; | |
1657 default: | |
1658 // We are being called directly. | |
1659 $node = $object; | |
1660 } | |
1661 | |
1662 $recipient = $context['recipient']; | |
1663 | |
1664 if (isset($node)) { | |
1665 if (!isset($account)) { | |
1666 $account = user_load(array('uid' => $node->uid)); | |
1667 } | |
1668 if ($recipient == '%author') { | |
1669 $recipient = $account->mail; | |
1670 } | |
1671 } | |
1672 | |
1673 if (!isset($account)) { | |
1674 $account = $user; | |
1675 | |
1676 } | |
1677 $language = user_preferred_language($account); | |
1678 $params = array('account' => $account, 'object' => $object, 'context' => $context); | |
1679 if (isset($node)) { | |
1680 $params['node'] = $node; | |
1681 } | |
1682 | |
1683 if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) { | |
1684 watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient)); | |
1685 } | |
1686 else { | |
1687 watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient)); | |
1688 } | |
1689 } | |
1690 | |
1691 /** | |
1692 * Implementation of hook_mail(). | |
1693 */ | |
1694 function system_mail($key, &$message, $params) { | |
1695 $account = $params['account']; | |
1696 $context = $params['context']; | |
1697 $variables = array( | |
1698 '%site_name' => variable_get('site_name', 'Drupal'), | |
1699 '%username' => $account->name, | |
1700 ); | |
1701 if ($context['hook'] == 'taxonomy') { | |
1702 $object = $params['object']; | |
1703 $vocabulary = taxonomy_vocabulary_load($object->vid); | |
1704 $variables += array( | |
1705 '%term_name' => $object->name, | |
1706 '%term_description' => $object->description, | |
1707 '%term_id' => $object->tid, | |
1708 '%vocabulary_name' => $vocabulary->name, | |
1709 '%vocabulary_description' => $vocabulary->description, | |
1710 '%vocabulary_id' => $vocabulary->vid, | |
1711 ); | |
1712 } | |
1713 | |
1714 // Node-based variable translation is only available if we have a node. | |
1715 if (isset($params['node'])) { | |
1716 $node = $params['node']; | |
1717 $variables += array( | |
1718 '%uid' => $node->uid, | |
1719 '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)), | |
1720 '%node_type' => node_get_types('name', $node), | |
1721 '%title' => $node->title, | |
1722 '%teaser' => $node->teaser, | |
1723 '%body' => $node->body, | |
1724 ); | |
1725 } | |
1726 $subject = strtr($context['subject'], $variables); | |
1727 $body = strtr($context['message'], $variables); | |
1728 $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); | |
1729 $message['body'][] = drupal_html_to_text($body); | |
1730 } | |
1731 | |
1732 function system_message_action_form($context) { | |
1733 $form['message'] = array( | |
1734 '#type' => 'textarea', | |
1735 '#title' => t('Message'), | |
1736 '#default_value' => isset($context['message']) ? $context['message'] : '', | |
1737 '#required' => TRUE, | |
1738 '#rows' => '8', | |
1739 '#description' => t('The message to be displayed to the current user. You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body. Not all variables will be available in all contexts.'), | |
1740 ); | |
1741 return $form; | |
1742 } | |
1743 | |
1744 function system_message_action_submit($form, $form_state) { | |
1745 return array('message' => $form_state['values']['message']); | |
1746 } | |
1747 | |
1748 /** | |
1749 * A configurable Drupal action. Sends a message to the current user's screen. | |
1750 */ | |
1751 function system_message_action(&$object, $context = array()) { | |
1752 global $user; | |
1753 $variables = array( | |
1754 '%site_name' => variable_get('site_name', 'Drupal'), | |
1755 '%username' => $user->name ? $user->name : variable_get('anonymous', t('Anonymous')), | |
1756 ); | |
1757 | |
1758 // This action can be called in any context, but if placeholders | |
1759 // are used a node object must be present to be the source | |
1760 // of substituted text. | |
1761 switch ($context['hook']) { | |
1762 case 'nodeapi': | |
1763 // Because this is not an action of type 'node' the node | |
1764 // will not be passed as $object, but it will still be available | |
1765 // in $context. | |
1766 $node = $context['node']; | |
1767 break; | |
1768 // The comment hook also provides the node, in context. | |
1769 case 'comment': | |
1770 $comment = $context['comment']; | |
1771 $node = node_load($comment->nid); | |
1772 break; | |
1773 case 'taxonomy': | |
1774 $vocabulary = taxonomy_vocabulary_load($object->vid); | |
1775 $variables = array_merge($variables, array( | |
1776 '%term_name' => $object->name, | |
1777 '%term_description' => $object->description, | |
1778 '%term_id' => $object->tid, | |
1779 '%vocabulary_name' => $vocabulary->name, | |
1780 '%vocabulary_description' => $vocabulary->description, | |
1781 '%vocabulary_id' => $vocabulary->vid, | |
1782 ) | |
1783 ); | |
1784 break; | |
1785 default: | |
1786 // We are being called directly. | |
1787 $node = $object; | |
1788 } | |
1789 | |
1790 if (isset($node) && is_object($node)) { | |
1791 $variables = array_merge($variables, array( | |
1792 '%uid' => $node->uid, | |
1793 '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)), | |
1794 '%node_type' => check_plain(node_get_types('name', $node)), | |
1795 '%title' => filter_xss($node->title), | |
1796 '%teaser' => filter_xss($node->teaser), | |
1797 '%body' => filter_xss($node->body), | |
1798 ) | |
1799 ); | |
1800 } | |
1801 $context['message'] = strtr($context['message'], $variables); | |
1802 drupal_set_message($context['message']); | |
1803 } | |
1804 | |
1805 /** | |
1806 * Implementation of a configurable Drupal action. Redirect user to a URL. | |
1807 */ | |
1808 function system_goto_action_form($context) { | |
1809 $form['url'] = array( | |
1810 '#type' => 'textfield', | |
1811 '#title' => t('URL'), | |
1812 '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like http://drupal.org.'), | |
1813 '#default_value' => isset($context['url']) ? $context['url'] : '', | |
1814 '#required' => TRUE, | |
1815 ); | |
1816 return $form; | |
1817 } | |
1818 | |
1819 function system_goto_action_submit($form, $form_state) { | |
1820 return array( | |
1821 'url' => $form_state['values']['url'] | |
1822 ); | |
1823 } | |
1824 | |
1825 function system_goto_action($object, $context) { | |
1826 drupal_goto($context['url']); | |
1827 } | |
1828 | |
1829 /** | |
1830 * Generate an array of time zones and their local time&date. | |
1831 */ | |
1832 function _system_zonelist() { | |
1833 $timestamp = time(); | |
1834 $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 14); | |
1835 $zones = array(); | |
1836 foreach ($zonelist as $offset) { | |
1837 $zone = $offset * 3600; | |
1838 $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') .' O', $zone); | |
1839 } | |
1840 return $zones; | |
1841 } | |
1842 | |
1843 /** | |
1844 * Checks whether the server is capable of issuing HTTP requests. | |
1845 * | |
1846 * The function sets the drupal_http_request_fail system variable to TRUE if | |
1847 * drupal_http_request() does not work and then the system status report page | |
1848 * will contain an error. | |
1849 * | |
1850 * @return | |
1851 * Whether the admin/reports/request-test page can be requested via HTTP | |
1852 * and contains the same output as if called via the menu system. | |
1853 */ | |
1854 function system_check_http_request() { | |
1855 // Check whether we can do any request at all. First get the results for | |
1856 // a very simple page which has access TRUE set via the menu system. Then, | |
1857 // try to drupal_http_request() the same page and compare. | |
1858 ob_start(); | |
1859 $path = 'admin/reports/request-test'; | |
1860 menu_execute_active_handler($path); | |
1861 $nothing = ob_get_contents(); | |
1862 ob_end_clean(); | |
1863 $result = drupal_http_request(url($path, array('absolute' => TRUE))); | |
1864 $works = isset($result->data) && $result->data == $nothing; | |
1865 variable_set('drupal_http_request_fails', !$works); | |
1866 return $works; | |
1867 } | |
1868 | |
1869 /** | |
1870 * Format the Powered by Drupal text. | |
1871 * | |
1872 * @ingroup themeable | |
1873 */ | |
1874 function theme_system_powered_by($image_path) { | |
1875 $image = theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system')); | |
1876 return l($image, 'http://drupal.org', array('html' => TRUE, 'absolute' => TRUE, 'external' => TRUE)); | |
1877 } |