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