Mercurial > defr > drupal > core
comparison includes/common.inc @ 7:fff6d4c8c043 6.3
Drupal 6.3
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:30:28 +0100 |
parents | 2427550111ae |
children | acef7ccb09b5 |
comparison
equal
deleted
inserted
replaced
6:2cfdc3c92142 | 7:fff6d4c8c043 |
---|---|
1 <?php | 1 <?php |
2 // $Id: common.inc,v 1.756.2.9 2008/04/09 21:11:44 goba Exp $ | 2 // $Id: common.inc,v 1.756.2.20 2008/07/09 21:48:27 goba Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * Common functions that many Drupal modules will need to reference. | 6 * Common functions that many Drupal modules will need to reference. |
7 * | 7 * |
258 * This issues an on-site HTTP redirect. The function makes sure the redirected | 258 * This issues an on-site HTTP redirect. The function makes sure the redirected |
259 * URL is formatted correctly. | 259 * URL is formatted correctly. |
260 * | 260 * |
261 * Usually the redirected URL is constructed from this function's input | 261 * Usually the redirected URL is constructed from this function's input |
262 * parameters. However you may override that behavior by setting a | 262 * parameters. However you may override that behavior by setting a |
263 * <em>destination</em> in either the $_REQUEST-array (i.e. by using | 263 * destination in either the $_REQUEST-array (i.e. by using |
264 * the query string of an URI) or the $_REQUEST['edit']-array (i.e. by | 264 * the query string of an URI) or the $_REQUEST['edit']-array (i.e. by |
265 * using a hidden form field). This is used to direct the user back to | 265 * using a hidden form field). This is used to direct the user back to |
266 * the proper page after completing a form. For example, after editing | 266 * the proper page after completing a form. For example, after editing |
267 * a post on the 'admin/content/node'-page or after having logged on using the | 267 * a post on the 'admin/content/node'-page or after having logged on using the |
268 * 'user login'-block in a sidebar. The function drupal_get_destination() | 268 * 'user login'-block in a sidebar. The function drupal_get_destination() |
569 * Error levels: | 569 * Error levels: |
570 * - 0 = Log errors to database. | 570 * - 0 = Log errors to database. |
571 * - 1 = Log errors to database and to screen. | 571 * - 1 = Log errors to database and to screen. |
572 */ | 572 */ |
573 function drupal_error_handler($errno, $message, $filename, $line, $context) { | 573 function drupal_error_handler($errno, $message, $filename, $line, $context) { |
574 // If the @ error suppression operator was used, error_reporting is | 574 // If the @ error suppression operator was used, error_reporting will have |
575 // temporarily set to 0. | 575 // been temporarily set to 0. |
576 if (error_reporting() == 0) { | 576 if (error_reporting() == 0) { |
577 return; | 577 return; |
578 } | 578 } |
579 | 579 |
580 if ($errno & (E_ALL ^ E_NOTICE)) { | 580 if ($errno & (E_ALL ^ E_NOTICE)) { |
1223 * The Drupal path being linked to, such as "admin/content/node", or an | 1223 * The Drupal path being linked to, such as "admin/content/node", or an |
1224 * existing URL like "http://drupal.org/". The special path | 1224 * existing URL like "http://drupal.org/". The special path |
1225 * '<front>' may also be given and will generate the site's base URL. | 1225 * '<front>' may also be given and will generate the site's base URL. |
1226 * @param $options | 1226 * @param $options |
1227 * An associative array of additional options, with the following keys: | 1227 * An associative array of additional options, with the following keys: |
1228 * 'query' | 1228 * - 'query' |
1229 * A query string to append to the link, or an array of query key/value | 1229 * A query string to append to the link, or an array of query key/value |
1230 * properties. | 1230 * properties. |
1231 * 'fragment' | 1231 * - 'fragment' |
1232 * A fragment identifier (or named anchor) to append to the link. | 1232 * A fragment identifier (or named anchor) to append to the link. |
1233 * Do not include the '#' character. | 1233 * Do not include the '#' character. |
1234 * 'absolute' (default FALSE) | 1234 * - 'absolute' (default FALSE) |
1235 * Whether to force the output to be an absolute link (beginning with | 1235 * Whether to force the output to be an absolute link (beginning with |
1236 * http:). Useful for links that will be displayed outside the site, such | 1236 * http:). Useful for links that will be displayed outside the site, such |
1237 * as in an RSS feed. | 1237 * as in an RSS feed. |
1238 * 'alias' (default FALSE) | 1238 * - 'alias' (default FALSE) |
1239 * Whether the given path is an alias already. | 1239 * Whether the given path is an alias already. |
1240 * 'external' | 1240 * - 'external' |
1241 * Whether the given path is an external URL. | 1241 * Whether the given path is an external URL. |
1242 * 'language' | 1242 * - 'language' |
1243 * An optional language object. Used to build the URL to link to and | 1243 * An optional language object. Used to build the URL to link to and |
1244 * look up the proper alias for the link. | 1244 * look up the proper alias for the link. |
1245 * 'base_url' | 1245 * - 'base_url' |
1246 * Only used internally, to modify the base URL when a language dependent | 1246 * Only used internally, to modify the base URL when a language dependent |
1247 * URL requires so. | 1247 * URL requires so. |
1248 * 'prefix' | 1248 * - 'prefix' |
1249 * Only used internally, to modify the path when a language dependent URL | 1249 * Only used internally, to modify the path when a language dependent URL |
1250 * requires so. | 1250 * requires so. |
1251 * @return | 1251 * @return |
1252 * A string containing a URL to the given path. | 1252 * A string containing a URL to the given path. |
1253 * | 1253 * |
1404 * base URL (again via the url() function). | 1404 * base URL (again via the url() function). |
1405 * - If you provide a path, and 'alias' is set to TRUE (see below), it is | 1405 * - If you provide a path, and 'alias' is set to TRUE (see below), it is |
1406 * used as is. | 1406 * used as is. |
1407 * @param $options | 1407 * @param $options |
1408 * An associative array of additional options, with the following keys: | 1408 * An associative array of additional options, with the following keys: |
1409 * 'attributes' | 1409 * - 'attributes' |
1410 * An associative array of HTML attributes to apply to the anchor tag. | 1410 * An associative array of HTML attributes to apply to the anchor tag. |
1411 * 'query' | 1411 * - 'query' |
1412 * A query string to append to the link, or an array of query key/value | 1412 * A query string to append to the link, or an array of query key/value |
1413 * properties. | 1413 * properties. |
1414 * 'fragment' | 1414 * - 'fragment' |
1415 * A fragment identifier (named anchor) to append to the link. | 1415 * A fragment identifier (named anchor) to append to the link. |
1416 * Do not include the '#' character. | 1416 * Do not include the '#' character. |
1417 * 'absolute' (default FALSE) | 1417 * - 'absolute' (default FALSE) |
1418 * Whether to force the output to be an absolute link (beginning with | 1418 * Whether to force the output to be an absolute link (beginning with |
1419 * http:). Useful for links that will be displayed outside the site, such | 1419 * http:). Useful for links that will be displayed outside the site, such |
1420 * as in an RSS feed. | 1420 * as in an RSS feed. |
1421 * 'html' (default FALSE) | 1421 * - 'html' (default FALSE) |
1422 * Whether the title is HTML, or just plain-text. For example for making | 1422 * Whether the title is HTML, or just plain-text. For example for making |
1423 * an image a link, this must be set to TRUE, or else you will see the | 1423 * an image a link, this must be set to TRUE, or else you will see the |
1424 * escaped HTML. | 1424 * escaped HTML. |
1425 * 'alias' (default FALSE) | 1425 * - 'alias' (default FALSE) |
1426 * Whether the given path is an alias already. | 1426 * Whether the given path is an alias already. |
1427 * @return | 1427 * @return |
1428 * an HTML string containing a link to the given path. | 1428 * an HTML string containing a link to the given path. |
1429 */ | 1429 */ |
1430 function l($text, $path, $options = array()) { | 1430 function l($text, $path, $options = array()) { |
1710 } | 1710 } |
1711 foreach ($types[$type] as $file => $preprocess) { | 1711 foreach ($types[$type] as $file => $preprocess) { |
1712 // If the theme supplies its own style using the name of the module style, skip its inclusion. | 1712 // If the theme supplies its own style using the name of the module style, skip its inclusion. |
1713 // This includes any RTL styles associated with its main LTR counterpart. | 1713 // This includes any RTL styles associated with its main LTR counterpart. |
1714 if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) { | 1714 if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) { |
1715 // Unset the file to prevent its inclusion when CSS aggregation is enabled. | |
1716 unset($types[$type][$file]); | |
1715 continue; | 1717 continue; |
1716 } | 1718 } |
1717 if (!$preprocess || !($is_writable && $preprocess_css)) { | 1719 // Only include the stylesheet if it exists. |
1718 // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*, | 1720 if (file_exists($file)) { |
1719 // regardless of whether preprocessing is on or off. | 1721 if (!$preprocess || !($is_writable && $preprocess_css)) { |
1720 if (!$preprocess && $type == 'module') { | 1722 // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*, |
1721 $no_module_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; | 1723 // regardless of whether preprocessing is on or off. |
1722 } | 1724 if (!$preprocess && $type == 'module') { |
1723 // If a CSS file is not to be preprocessed and it's a theme CSS file, it needs to *always* appear at the *bottom*, | 1725 $no_module_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; |
1724 // regardless of whether preprocessing is on or off. | 1726 } |
1725 else if (!$preprocess && $type == 'theme') { | 1727 // If a CSS file is not to be preprocessed and it's a theme CSS file, it needs to *always* appear at the *bottom*, |
1726 $no_theme_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; | 1728 // regardless of whether preprocessing is on or off. |
1727 } | 1729 else if (!$preprocess && $type == 'theme') { |
1728 else { | 1730 $no_theme_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; |
1729 $output .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; | 1731 } |
1732 else { | |
1733 $output .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; | |
1734 } | |
1730 } | 1735 } |
1731 } | 1736 } |
1732 } | 1737 } |
1733 } | 1738 } |
1734 | 1739 |
2006 * References to JavaScript files are placed in a certain order: first, all | 2011 * References to JavaScript files are placed in a certain order: first, all |
2007 * 'core' files, then all 'module' and finally all 'theme' JavaScript files | 2012 * 'core' files, then all 'module' and finally all 'theme' JavaScript files |
2008 * are added to the page. Then, all settings are output, followed by 'inline' | 2013 * are added to the page. Then, all settings are output, followed by 'inline' |
2009 * JavaScript code. If running update.php, all preprocessing is disabled. | 2014 * JavaScript code. If running update.php, all preprocessing is disabled. |
2010 * | 2015 * |
2011 * @parameter $scope | 2016 * @param $scope |
2012 * (optional) The scope for which the JavaScript rules should be returned. | 2017 * (optional) The scope for which the JavaScript rules should be returned. |
2013 * Defaults to 'header'. | 2018 * Defaults to 'header'. |
2014 * @parameter $javascript | 2019 * @param $javascript |
2015 * (optional) An array with all JavaScript code. Defaults to the default | 2020 * (optional) An array with all JavaScript code. Defaults to the default |
2016 * JavaScript array for the given scope. | 2021 * JavaScript array for the given scope. |
2017 * @return | 2022 * @return |
2018 * All JavaScript code segments and includes for the scope as HTML tags. | 2023 * All JavaScript code segments and includes for the scope as HTML tags. |
2019 */ | 2024 */ |
2710 uasort($elements, "element_sort"); | 2715 uasort($elements, "element_sort"); |
2711 } | 2716 } |
2712 $elements += array('#title' => NULL, '#description' => NULL); | 2717 $elements += array('#title' => NULL, '#description' => NULL); |
2713 if (!isset($elements['#children'])) { | 2718 if (!isset($elements['#children'])) { |
2714 $children = element_children($elements); | 2719 $children = element_children($elements); |
2715 /* Render all the children that use a theme function */ | 2720 // Render all the children that use a theme function. |
2716 if (isset($elements['#theme']) && empty($elements['#theme_used'])) { | 2721 if (isset($elements['#theme']) && empty($elements['#theme_used'])) { |
2717 $elements['#theme_used'] = TRUE; | 2722 $elements['#theme_used'] = TRUE; |
2718 | 2723 |
2719 $previous = array(); | 2724 $previous = array(); |
2720 foreach (array('#value', '#type', '#prefix', '#suffix') as $key) { | 2725 foreach (array('#value', '#type', '#prefix', '#suffix') as $key) { |
2734 | 2739 |
2735 foreach (array('#value', '#type', '#prefix', '#suffix') as $key) { | 2740 foreach (array('#value', '#type', '#prefix', '#suffix') as $key) { |
2736 $elements[$key] = isset($previous[$key]) ? $previous[$key] : NULL; | 2741 $elements[$key] = isset($previous[$key]) ? $previous[$key] : NULL; |
2737 } | 2742 } |
2738 } | 2743 } |
2739 /* render each of the children using drupal_render and concatenate them */ | 2744 // Render each of the children using drupal_render and concatenate them. |
2740 if (!isset($content) || $content === '') { | 2745 if (!isset($content) || $content === '') { |
2741 foreach ($children as $key) { | 2746 foreach ($children as $key) { |
2742 $content .= drupal_render($elements[$key]); | 2747 $content .= drupal_render($elements[$key]); |
2743 } | 2748 } |
2744 } | 2749 } |
3072 * | 3077 * |
3073 * @param $module | 3078 * @param $module |
3074 * The module for which the tables will be created. | 3079 * The module for which the tables will be created. |
3075 * @return | 3080 * @return |
3076 * An array of arrays with the following key/value pairs: | 3081 * An array of arrays with the following key/value pairs: |
3077 * success: a boolean indicating whether the query succeeded | 3082 * - success: a boolean indicating whether the query succeeded. |
3078 * query: the SQL query(s) executed, passed through check_plain() | 3083 * - query: the SQL query(s) executed, passed through check_plain(). |
3079 */ | 3084 */ |
3080 function drupal_install_schema($module) { | 3085 function drupal_install_schema($module) { |
3081 $schema = drupal_get_schema_unprocessed($module); | 3086 $schema = drupal_get_schema_unprocessed($module); |
3082 _drupal_initialize_schema($module, $schema); | 3087 _drupal_initialize_schema($module, $schema); |
3083 | 3088 |
3097 * | 3102 * |
3098 * @param $module | 3103 * @param $module |
3099 * The module for which the tables will be removed. | 3104 * The module for which the tables will be removed. |
3100 * @return | 3105 * @return |
3101 * An array of arrays with the following key/value pairs: | 3106 * An array of arrays with the following key/value pairs: |
3102 * success: a boolean indicating whether the query succeeded | 3107 * - success: a boolean indicating whether the query succeeded. |
3103 * query: the SQL query(s) executed, passed through check_plain() | 3108 * - query: the SQL query(s) executed, passed through check_plain(). |
3104 */ | 3109 */ |
3105 function drupal_uninstall_schema($module) { | 3110 function drupal_uninstall_schema($module) { |
3106 $schema = drupal_get_schema_unprocessed($module); | 3111 $schema = drupal_get_schema_unprocessed($module); |
3107 _drupal_initialize_schema($module, $schema); | 3112 _drupal_initialize_schema($module, $schema); |
3108 | 3113 |
3223 // Standardize $update to an array. | 3228 // Standardize $update to an array. |
3224 if (is_string($update)) { | 3229 if (is_string($update)) { |
3225 $update = array($update); | 3230 $update = array($update); |
3226 } | 3231 } |
3227 | 3232 |
3233 $schema = drupal_get_schema($table); | |
3234 if (empty($schema)) { | |
3235 return FALSE; | |
3236 } | |
3237 | |
3228 // Convert to an object if needed. | 3238 // Convert to an object if needed. |
3229 if (is_array($object)) { | 3239 if (is_array($object)) { |
3230 $object = (object) $object; | 3240 $object = (object) $object; |
3231 $array = TRUE; | 3241 $array = TRUE; |
3232 } | 3242 } |
3233 else { | 3243 else { |
3234 $array = FALSE; | 3244 $array = FALSE; |
3235 } | |
3236 | |
3237 $schema = drupal_get_schema($table); | |
3238 if (empty($schema)) { | |
3239 return FALSE; | |
3240 } | 3245 } |
3241 | 3246 |
3242 $fields = $defs = $values = $serials = $placeholders = array(); | 3247 $fields = $defs = $values = $serials = $placeholders = array(); |
3243 | 3248 |
3244 // Go through our schema, build SQL, and when inserting, fill in defaults for | 3249 // Go through our schema, build SQL, and when inserting, fill in defaults for |
3305 // Get last insert ids and fill them in. | 3310 // Get last insert ids and fill them in. |
3306 foreach ($serials as $field) { | 3311 foreach ($serials as $field) { |
3307 $object->$field = db_last_insert_id($table, $field); | 3312 $object->$field = db_last_insert_id($table, $field); |
3308 } | 3313 } |
3309 } | 3314 } |
3310 | 3315 } |
3311 // If we began with an array, convert back so we don't surprise the caller. | 3316 else { |
3312 if ($array) { | 3317 $return = FALSE; |
3313 $object = (array) $object; | 3318 } |
3314 } | 3319 |
3315 | 3320 // If we began with an array, convert back so we don't surprise the caller. |
3316 return $return; | 3321 if ($array) { |
3317 } | 3322 $object = (array) $object; |
3318 | 3323 } |
3319 return FALSE; | 3324 |
3325 return $return; | |
3320 } | 3326 } |
3321 | 3327 |
3322 /** | 3328 /** |
3323 * @} End of "ingroup schemaapi". | 3329 * @} End of "ingroup schemaapi". |
3324 */ | 3330 */ |
3505 | 3511 |
3506 /** | 3512 /** |
3507 * Flush all cached data on the site. | 3513 * Flush all cached data on the site. |
3508 * | 3514 * |
3509 * Empties cache tables, rebuilds the menu cache and theme registries, and | 3515 * Empties cache tables, rebuilds the menu cache and theme registries, and |
3510 * exposes a hook for other modules to clear their own cache data as well. | 3516 * invokes a hook so that other modules' cache data can be cleared as well. |
3511 */ | 3517 */ |
3512 function drupal_flush_all_caches() { | 3518 function drupal_flush_all_caches() { |
3513 // Change query-strings on css/js files to enforce reload for all users. | 3519 // Change query-strings on css/js files to enforce reload for all users. |
3514 _drupal_flush_css_js(); | 3520 _drupal_flush_css_js(); |
3515 | 3521 |
3516 drupal_clear_css_cache(); | 3522 drupal_clear_css_cache(); |
3517 drupal_clear_js_cache(); | 3523 drupal_clear_js_cache(); |
3524 system_theme_data(); | |
3518 drupal_rebuild_theme_registry(); | 3525 drupal_rebuild_theme_registry(); |
3519 menu_rebuild(); | 3526 menu_rebuild(); |
3520 node_types_rebuild(); | 3527 node_types_rebuild(); |
3521 // Don't clear cache_form - in-progress form submissions may break. | 3528 // Don't clear cache_form - in-progress form submissions may break. |
3522 // Ordered so clearing the page cache will always be the last action. | 3529 // Ordered so clearing the page cache will always be the last action. |