00001 <?php
00002
00003
00013 define('CACHE_PERMANENT', 0);
00014
00018 define('CACHE_TEMPORARY', -1);
00019
00023 define('CACHE_DISABLED', 0);
00024
00028 define('CACHE_NORMAL', 1);
00029
00035 define('CACHE_AGGRESSIVE', 2);
00036
00043 define('WATCHDOG_EMERG', 0);
00044
00051 define('WATCHDOG_ALERT', 1);
00052
00059 define('WATCHDOG_CRITICAL', 2);
00060
00067 define('WATCHDOG_ERROR', 3);
00068
00075 define('WATCHDOG_WARNING', 4);
00076
00083 define('WATCHDOG_NOTICE', 5);
00084
00091 define('WATCHDOG_INFO', 6);
00092
00099 define('WATCHDOG_DEBUG', 7);
00100
00104 define('DRUPAL_BOOTSTRAP_CONFIGURATION', 0);
00105
00110 define('DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE', 1);
00111
00115 define('DRUPAL_BOOTSTRAP_DATABASE', 2);
00116
00120 define('DRUPAL_BOOTSTRAP_ACCESS', 3);
00121
00125 define('DRUPAL_BOOTSTRAP_SESSION', 4);
00126
00131 define('DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE', 5);
00132
00136 define('DRUPAL_BOOTSTRAP_LANGUAGE', 6);
00137
00141 define('DRUPAL_BOOTSTRAP_PATH', 7);
00142
00147 define('DRUPAL_BOOTSTRAP_FULL', 8);
00148
00152 define('DRUPAL_ANONYMOUS_RID', 1);
00153
00157 define('DRUPAL_AUTHENTICATED_RID', 2);
00158
00162 define('LANGUAGE_NEGOTIATION_NONE', 0);
00163
00168 define('LANGUAGE_NEGOTIATION_PATH_DEFAULT', 1);
00169
00175 define('LANGUAGE_NEGOTIATION_PATH', 2);
00176
00181 define('LANGUAGE_NEGOTIATION_DOMAIN', 3);
00182
00191 function timer_start($name) {
00192 global $timers;
00193
00194 list($usec, $sec) = explode(' ', microtime());
00195 $timers[$name]['start'] = (float)$usec + (float)$sec;
00196 $timers[$name]['count'] = isset($timers[$name]['count']) ? ++$timers[$name]['count'] : 1;
00197 }
00198
00207 function timer_read($name) {
00208 global $timers;
00209
00210 if (isset($timers[$name]['start'])) {
00211 list($usec, $sec) = explode(' ', microtime());
00212 $stop = (float)$usec + (float)$sec;
00213 $diff = round(($stop - $timers[$name]['start']) * 1000, 2);
00214
00215 if (isset($timers[$name]['time'])) {
00216 $diff += $timers[$name]['time'];
00217 }
00218 return $diff;
00219 }
00220 }
00221
00232 function timer_stop($name) {
00233 global $timers;
00234
00235 $timers[$name]['time'] = timer_read($name);
00236 unset($timers[$name]['start']);
00237
00238 return $timers[$name];
00239 }
00240
00281 function conf_path($require_settings = TRUE, $reset = FALSE) {
00282 static $conf = '';
00283
00284 if ($conf && !$reset) {
00285 return $conf;
00286 }
00287
00288 $confdir = 'sites';
00289 $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']);
00290 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
00291 for ($i = count($uri) - 1; $i > 0; $i--) {
00292 for ($j = count($server); $j > 0; $j--) {
00293 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
00294 if (file_exists("$confdir/$dir/settings.php") || (!$require_settings && file_exists("$confdir/$dir"))) {
00295 $conf = "$confdir/$dir";
00296 return $conf;
00297 }
00298 }
00299 }
00300 $conf = "$confdir/default";
00301 return $conf;
00302 }
00303
00307 function drupal_unset_globals() {
00308 if (ini_get('register_globals')) {
00309 $allowed = array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1);
00310 foreach ($GLOBALS as $key => $value) {
00311 if (!isset($allowed[$key])) {
00312 unset($GLOBALS[$key]);
00313 }
00314 }
00315 }
00316 }
00317
00322 function conf_init() {
00323 global $base_url, $base_path, $base_root;
00324
00325
00326 global $db_url, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access;
00327 $conf = array();
00328
00329 if (file_exists('./' . conf_path() . '/settings.php')) {
00330 include_once './' . conf_path() . '/settings.php';
00331 }
00332
00333 if (isset($base_url)) {
00334
00335 $parts = parse_url($base_url);
00336 if (!isset($parts['path'])) {
00337 $parts['path'] = '';
00338 }
00339 $base_path = $parts['path'] . '/';
00340
00341 $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
00342 }
00343 else {
00344
00345 $base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
00346
00347
00348
00349 $base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
00350
00351
00352
00353 if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
00354 $base_path = "/$dir";
00355 $base_url .= $base_path;
00356 $base_path .= '/';
00357 }
00358 else {
00359 $base_path = '/';
00360 }
00361 }
00362
00363 if ($cookie_domain) {
00364
00365 $session_name = $cookie_domain;
00366 }
00367 else {
00368
00369
00370 list( , $session_name) = explode('://', $base_url, 2);
00371
00372 if (!empty($_SERVER['HTTP_HOST'])) {
00373 $cookie_domain = check_plain($_SERVER['HTTP_HOST']);
00374 }
00375 }
00376
00377 $cookie_domain = ltrim($cookie_domain, '.');
00378 if (strpos($cookie_domain, 'www.') === 0) {
00379 $cookie_domain = substr($cookie_domain, 4);
00380 }
00381 $cookie_domain = explode(':', $cookie_domain);
00382 $cookie_domain = '.' . $cookie_domain[0];
00383
00384
00385 if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
00386 ini_set('session.cookie_domain', $cookie_domain);
00387 }
00388 session_name('SESS' . md5($session_name));
00389 }
00390
00419 function drupal_get_filename($type, $name, $filename = NULL) {
00420 static $files = array();
00421
00422 if (!isset($files[$type])) {
00423 $files[$type] = array();
00424 }
00425
00426 if (!empty($filename) && file_exists($filename)) {
00427 $files[$type][$name] = $filename;
00428 }
00429 elseif (isset($files[$type][$name])) {
00430
00431 }
00432
00433
00434
00435
00436 elseif (db_is_active() && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
00437 $files[$type][$name] = $file;
00438 }
00439 else {
00440
00441
00442 $config = conf_path();
00443 $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
00444 $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");
00445
00446 foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
00447 if (file_exists($file)) {
00448 $files[$type][$name] = $file;
00449 break;
00450 }
00451 }
00452 }
00453
00454 if (isset($files[$type][$name])) {
00455 return $files[$type][$name];
00456 }
00457 }
00458
00466 function variable_init($conf = array()) {
00467
00468 if ($cached = cache_get('variables', 'cache')) {
00469 $variables = $cached->data;
00470 }
00471 else {
00472 $result = db_query('SELECT * FROM {variable}');
00473 while ($variable = db_fetch_object($result)) {
00474 $variables[$variable->name] = unserialize($variable->value);
00475 }
00476 cache_set('variables', $variables);
00477 }
00478
00479 foreach ($conf as $name => $value) {
00480 $variables[$name] = $value;
00481 }
00482
00483 return $variables;
00484 }
00485
00496 function variable_get($name, $default) {
00497 global $conf;
00498
00499 return isset($conf[$name]) ? $conf[$name] : $default;
00500 }
00501
00511 function variable_set($name, $value) {
00512 global $conf;
00513
00514 $serialized_value = serialize($value);
00515 db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $name);
00516 if (!db_affected_rows()) {
00517 @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value);
00518 }
00519
00520 cache_clear_all('variables', 'cache');
00521
00522 $conf[$name] = $value;
00523 }
00524
00531 function variable_del($name) {
00532 global $conf;
00533
00534 db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
00535 cache_clear_all('variables', 'cache');
00536
00537 unset($conf[$name]);
00538 }
00539
00540
00547 function page_get_cache() {
00548 global $user, $base_root;
00549
00550 $cache = NULL;
00551
00552 if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_set_message()) == 0) {
00553 $cache = cache_get($base_root . request_uri(), 'cache_page');
00554
00555 if (empty($cache)) {
00556 ob_start();
00557 }
00558 }
00559
00560 return $cache;
00561 }
00562
00569 function bootstrap_invoke_all($hook) {
00570 foreach (module_list(TRUE, TRUE) as $module) {
00571 module_invoke($module, $hook);
00572 }
00573 }
00574
00587 function drupal_load($type, $name) {
00588 static $files = array();
00589
00590 if (isset($files[$type][$name])) {
00591 return TRUE;
00592 }
00593
00594 $filename = drupal_get_filename($type, $name);
00595
00596 if ($filename) {
00597 include_once "./$filename";
00598 $files[$type][$name] = TRUE;
00599
00600 return TRUE;
00601 }
00602
00603 return FALSE;
00604 }
00605
00615 function drupal_page_header() {
00616 header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
00617 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00618 header("Cache-Control: store, no-cache, must-revalidate");
00619 header("Cache-Control: post-check=0, pre-check=0", FALSE);
00620 }
00621
00631 function drupal_page_cache_header($cache) {
00632
00633 $last_modified = gmdate('D, d M Y H:i:s', $cache->created) . ' GMT';
00634 $etag = '"' . md5($last_modified) . '"';
00635
00636
00637 $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
00638 $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
00639
00640 if ($if_modified_since && $if_none_match
00641 && $if_none_match == $etag
00642 && $if_modified_since == $last_modified) {
00643 header('HTTP/1.1 304 Not Modified');
00644
00645 header("Etag: $etag");
00646 exit();
00647 }
00648
00649
00650 header("Last-Modified: $last_modified");
00651 header("ETag: $etag");
00652
00653
00654 header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
00655 header("Cache-Control: must-revalidate");
00656
00657 if (variable_get('page_compression', TRUE)) {
00658
00659 if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE && function_exists('gzencode')) {
00660
00661 $cache->data = gzinflate(substr(substr($cache->data, 10), 0, -8));
00662 }
00663 elseif (function_exists('gzencode')) {
00664 header('Content-Encoding: gzip');
00665 }
00666 }
00667
00668
00669
00670
00671 $headers = explode("\n", $cache->headers);
00672 foreach ($headers as $header) {
00673 header($header);
00674 }
00675
00676 print $cache->data;
00677 }
00678
00682 function bootstrap_hooks() {
00683 return array('boot', 'exit');
00684 }
00685
00694 function drupal_unpack($obj, $field = 'data') {
00695 if ($obj->$field && $data = unserialize($obj->$field)) {
00696 foreach ($data as $key => $value) {
00697 if (!isset($obj->$key)) {
00698 $obj->$key = $value;
00699 }
00700 }
00701 }
00702 return $obj;
00703 }
00704
00708 function referer_uri() {
00709 if (isset($_SERVER['HTTP_REFERER'])) {
00710 return $_SERVER['HTTP_REFERER'];
00711 }
00712 }
00713
00720 function check_plain($text) {
00721 return drupal_validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : '';
00722 }
00723
00753 function drupal_validate_utf8($text) {
00754 if (strlen($text) == 0) {
00755 return TRUE;
00756 }
00757 return (preg_match('/^./us', $text) == 1);
00758 }
00759
00764 function request_uri() {
00765
00766 if (isset($_SERVER['REQUEST_URI'])) {
00767 $uri = $_SERVER['REQUEST_URI'];
00768 }
00769 else {
00770 if (isset($_SERVER['argv'])) {
00771 $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
00772 }
00773 elseif (isset($_SERVER['QUERY_STRING'])) {
00774 $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
00775 }
00776 else {
00777 $uri = $_SERVER['SCRIPT_NAME'];
00778 }
00779 }
00780
00781 return $uri;
00782 }
00783
00804 function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
00805 global $user, $base_root;
00806
00807
00808 $log_message = array(
00809 'type' => $type,
00810 'message' => $message,
00811 'variables' => $variables,
00812 'severity' => $severity,
00813 'link' => $link,
00814 'user' => $user,
00815 'request_uri' => $base_root . request_uri(),
00816 'referer' => referer_uri(),
00817 'ip' => ip_address(),
00818 'timestamp' => time(),
00819 );
00820
00821
00822 foreach (module_implements('watchdog', TRUE) as $module) {
00823 module_invoke($module, 'watchdog', $log_message);
00824 }
00825 }
00826
00845 function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) {
00846 if ($message) {
00847 if (!isset($_SESSION['messages'])) {
00848 $_SESSION['messages'] = array();
00849 }
00850
00851 if (!isset($_SESSION['messages'][$type])) {
00852 $_SESSION['messages'][$type] = array();
00853 }
00854
00855 if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
00856 $_SESSION['messages'][$type][] = $message;
00857 }
00858 }
00859
00860
00861 return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL;
00862 }
00863
00877 function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
00878 if ($messages = drupal_set_message()) {
00879 if ($type) {
00880 if ($clear_queue) {
00881 unset($_SESSION['messages'][$type]);
00882 }
00883 if (isset($messages[$type])) {
00884 return array($type => $messages[$type]);
00885 }
00886 }
00887 else {
00888 if ($clear_queue) {
00889 unset($_SESSION['messages']);
00890 }
00891 return $messages;
00892 }
00893 }
00894 return array();
00895 }
00896
00910 function drupal_is_denied($ip) {
00911
00912
00913
00914 $blocked_ips = variable_get('blocked_ips', NULL);
00915 if (isset($blocked_ips) && is_array($blocked_ips)) {
00916 return in_array($ip, $blocked_ips);
00917 }
00918 else {
00919 $sql = "SELECT 1 FROM {blocked_ips} WHERE ip = '%s'";
00920 return (bool) db_result(db_query($sql, $ip));
00921 }
00922 }
00923
00929 function drupal_anonymous_user($session = '') {
00930 $user = new stdClass();
00931 $user->uid = 0;
00932 $user->hostname = ip_address();
00933 $user->roles = array();
00934 $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
00935 $user->session = $session;
00936 $user->cache = 0;
00937 return $user;
00938 }
00939
00960 function drupal_bootstrap($phase) {
00961 static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0;
00962
00963 while ($phase >= $phase_index && isset($phases[$phase_index])) {
00964 $current_phase = $phases[$phase_index];
00965 unset($phases[$phase_index++]);
00966 _drupal_bootstrap($current_phase);
00967 }
00968 }
00969
00970 function _drupal_bootstrap($phase) {
00971 global $conf;
00972
00973 switch ($phase) {
00974
00975 case DRUPAL_BOOTSTRAP_CONFIGURATION:
00976 drupal_unset_globals();
00977
00978 timer_start('page');
00979
00980 conf_init();
00981 break;
00982
00983 case DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:
00984
00985
00986 require_once variable_get('cache_inc', './includes/cache.inc');
00987
00988
00989
00990
00991 if (variable_get('page_cache_fastpath', FALSE) && page_cache_fastpath()) {
00992 exit;
00993 }
00994 break;
00995
00996 case DRUPAL_BOOTSTRAP_DATABASE:
00997
00998 require_once './includes/database.inc';
00999 db_set_active();
01000
01001 spl_autoload_register('drupal_autoload_class');
01002 spl_autoload_register('drupal_autoload_interface');
01003 break;
01004
01005 case DRUPAL_BOOTSTRAP_ACCESS:
01006
01007 if (drupal_is_denied(ip_address())) {
01008 header('HTTP/1.1 403 Forbidden');
01009 print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';
01010 exit();
01011 }
01012 break;
01013
01014 case DRUPAL_BOOTSTRAP_SESSION:
01015 require_once variable_get('session_inc', './includes/session.inc');
01016 session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc');
01017 session_start();
01018 break;
01019
01020 case DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
01021
01022 $conf = variable_init(isset($conf) ? $conf : array());
01023
01024 require_once './includes/module.inc';
01025 $cache_mode = variable_get('cache', CACHE_DISABLED);
01026
01027 $cache = $cache_mode == CACHE_DISABLED ? '' : page_get_cache();
01028
01029 if ($cache_mode != CACHE_AGGRESSIVE) {
01030 bootstrap_invoke_all('boot');
01031 }
01032
01033 if ($cache) {
01034 drupal_page_cache_header($cache);
01035
01036 if ($cache_mode != CACHE_AGGRESSIVE) {
01037 bootstrap_invoke_all('exit');
01038 }
01039
01040 exit;
01041 }
01042
01043 drupal_page_header();
01044 break;
01045
01046 case DRUPAL_BOOTSTRAP_LANGUAGE:
01047 drupal_init_language();
01048 break;
01049
01050 case DRUPAL_BOOTSTRAP_PATH:
01051 require_once './includes/path.inc';
01052
01053 drupal_init_path();
01054 break;
01055
01056 case DRUPAL_BOOTSTRAP_FULL:
01057 require_once './includes/common.inc';
01058 _drupal_bootstrap_full();
01059 break;
01060 }
01061 }
01062
01071 function drupal_maintenance_theme() {
01072 require_once './includes/theme.maintenance.inc';
01073 _drupal_maintenance_theme();
01074 }
01075
01080 function get_t() {
01081 static $t;
01082 if (is_null($t)) {
01083 $t = function_exists('install_main') ? 'st' : 't';
01084 }
01085 return $t;
01086 }
01087
01091 function drupal_init_language() {
01092 global $language, $user;
01093
01094
01095
01096 if (variable_get('language_count', 1) == 1) {
01097 $language = language_default();
01098 }
01099 else {
01100 include_once './includes/language.inc';
01101 $language = language_initialize();
01102 }
01103 }
01104
01111 function language_list($field = 'language', $reset = FALSE) {
01112 static $languages = NULL;
01113
01114
01115 if ($reset) {
01116 $languages = NULL;
01117 }
01118
01119
01120 if (!isset($languages)) {
01121 if (variable_get('language_count', 1) > 1 || module_exists('locale')) {
01122 $result = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC');
01123 while ($row = db_fetch_object($result)) {
01124 $languages['language'][$row->language] = $row;
01125 }
01126 }
01127 else {
01128
01129 $default = language_default();
01130 $languages['language'][$default->language] = $default;
01131 }
01132 }
01133
01134
01135 if (!isset($languages[$field])) {
01136 $languages[$field] = array();
01137 foreach ($languages['language'] as $lang) {
01138
01139 if (in_array($field, array('enabled', 'weight'))) {
01140 $languages[$field][$lang->$field][$lang->language] = $lang;
01141 }
01142 else {
01143 $languages[$field][$lang->$field] = $lang;
01144 }
01145 }
01146 }
01147 return $languages[$field];
01148 }
01149
01156 function language_default($property = NULL) {
01157 $language = variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''));
01158 return $property ? $language->$property : $language;
01159 }
01160
01169 function ip_address() {
01170 static $ip_address = NULL;
01171
01172 if (!isset($ip_address)) {
01173 $ip_address = $_SERVER['REMOTE_ADDR'];
01174 if (variable_get('reverse_proxy', 0) && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
01175
01176
01177 $reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array());
01178 if (!empty($reverse_proxy_addresses) && in_array($ip_address, $reverse_proxy_addresses, TRUE)) {
01179
01180
01181 $ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
01182 }
01183 }
01184 }
01185
01186 return $ip_address;
01187 }
01188
01207 function drupal_function_exists($function) {
01208 static $checked = array();
01209
01210 if (defined('MAINTENANCE_MODE')) {
01211 return function_exists($function);
01212 }
01213
01214 if (isset($checked[$function])) {
01215 return $checked[$function];
01216 }
01217 $checked[$function] = FALSE;
01218
01219 if (function_exists($function)) {
01220 registry_mark_code('function', $function);
01221 $checked[$function] = TRUE;
01222 return TRUE;
01223 }
01224
01225 $file = db_result(db_query("SELECT filename FROM {registry} WHERE name = '%s' AND type = '%s'", $function, 'function'));
01226 if ($file) {
01227 require_once($file);
01228 $checked[$function] = function_exists($function);
01229 if ($checked[$function]) {
01230 registry_mark_code('function', $function);
01231 }
01232 }
01233
01234 return $checked[$function];
01235 }
01236
01249 function drupal_autoload_interface($interface) {
01250 return _registry_check_code('interface', $interface);
01251 }
01252
01265 function drupal_autoload_class($class) {
01266 return _registry_check_code('class', $class);
01267 }
01268
01272 function _registry_check_code($type, $name) {
01273 $file = db_result(db_query("SELECT filename FROM {registry} WHERE name = '%s' AND type = '%s'", $name, $type));
01274 if ($file) {
01275 require_once($file);
01276 registry_mark_code($type, $name);
01277 return TRUE;
01278 }
01279 }
01280
01291 function registry_mark_code($type, $name, $return = FALSE) {
01292 static $resources = array();
01293
01294 if ($type && $name) {
01295 if (!isset($resources[$type])) {
01296 $resources[$type] = array();
01297 }
01298 if (!in_array($name, $resources[$type])) {
01299 $resources[$type][] = $name;
01300 }
01301 }
01302
01303 if ($return) {
01304 return $resources;
01305 }
01306 }
01307
01314 function drupal_rebuild_code_registry() {
01315 require_once './includes/registry.inc';
01316 _drupal_rebuild_code_registry();
01317 }
01318
01327 function registry_cache_hook_implementations($hook, $write_to_persistent_cache = FALSE) {
01328 static $implementations;
01329
01330 if ($hook) {
01331
01332 $implementations[$hook['hook']] = $hook['modules'];
01333 }
01334
01335 if ($write_to_persistent_cache === TRUE) {
01336
01337
01338 if ($implementations != registry_get_hook_implementations_cache()) {
01339 cache_set('hooks', $implementations, 'cache_registry');
01340 }
01341 }
01342 }
01343
01347 function registry_cache_path_files() {
01348 if ($used_code = registry_mark_code(NULL, NULL, TRUE)) {
01349 $files = array();
01350 $type_sql = array();
01351 $params = array();
01352 foreach ($used_code as $type => $names) {
01353 $type_sql[] = "(name IN (" . db_placeholders($names, 'varchar') . ") AND type = '%s')";
01354 $params = array_merge($params, $names);
01355 $params[] = $type;
01356 }
01357 $res = db_query("SELECT DISTINCT filename FROM {registry} WHERE " . implode(' OR ', $type_sql), $params);
01358 while ($row = db_fetch_object($res)) {
01359 $files[] = $row->filename;
01360 }
01361 if ($files) {
01362 sort($files);
01363
01364
01365 if ($files != registry_load_path_files(TRUE)) {
01366 $menu = menu_get_item();
01367 cache_set('registry:' . $menu['path'], implode(';', $files), 'cache_registry');
01368 }
01369 }
01370 }
01371 }
01372
01376 function registry_load_path_files($return = FALSE) {
01377 static $file_cache_data = array();
01378 if ($return) {
01379 sort($file_cache_data);
01380 return $file_cache_data;
01381 }
01382 $menu = menu_get_item();
01383 $cache = cache_get('registry:' . $menu['path'], 'cache_registry');
01384 if (!empty($cache->data)) {
01385 foreach(explode(';', $cache->data) as $file) {
01386 require_once($file);
01387 $file_cache_data[] = $file;
01388 }
01389 }
01390 }
01391
01395 function registry_get_hook_implementations_cache() {
01396 static $implementations;
01397 if ($implementations === NULL) {
01398 if ($cache = cache_get('hooks', 'cache_registry')) {
01399 $implementations = $cache->data;
01400 }
01401 else {
01402 $implementations = array();
01403 }
01404 }
01405 return $implementations;
01406 }
01407