12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076 |
- <?php
- use Drupal\Component\Utility\Crypt;
- use Drupal\Component\Utility\Html;
- use Drupal\Component\Utility\SafeMarkup;
- use Drupal\Component\Utility\Unicode;
- use Drupal\Core\Config\BootstrapConfigStorageFactory;
- use Drupal\Core\Logger\RfcLogLevel;
- use Drupal\Core\Test\TestDatabase;
- use Drupal\Core\Session\AccountInterface;
- use Drupal\Core\Site\Settings;
- use Drupal\Core\Utility\Error;
- use Drupal\Core\StringTranslation\TranslatableMarkup;
- const DRUPAL_MINIMUM_PHP = '5.5.9';
- const DRUPAL_RECOMMENDED_PHP = '7.1';
- const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M';
- const ERROR_REPORTING_HIDE = 'hide';
- const ERROR_REPORTING_DISPLAY_SOME = 'some';
- const ERROR_REPORTING_DISPLAY_ALL = 'all';
- const ERROR_REPORTING_DISPLAY_VERBOSE = 'verbose';
- const DRUPAL_ANONYMOUS_RID = AccountInterface::ANONYMOUS_ROLE;
- const DRUPAL_AUTHENTICATED_RID = AccountInterface::AUTHENTICATED_ROLE;
- const DRUPAL_EXTENSION_NAME_MAX_LENGTH = 50;
- define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
- const DRUPAL_PHP_FUNCTION_PATTERN = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
- const CONFIG_ACTIVE_DIRECTORY = 'active';
- const CONFIG_SYNC_DIRECTORY = 'sync';
- const CONFIG_STAGING_DIRECTORY = 'staging';
- define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
- function config_get_config_directory($type) {
- global $config_directories;
-
- if ($type == CONFIG_SYNC_DIRECTORY && !isset($config_directories[CONFIG_SYNC_DIRECTORY]) && isset($config_directories[CONFIG_STAGING_DIRECTORY])) {
- $type = CONFIG_STAGING_DIRECTORY;
- }
- if (!empty($config_directories[$type])) {
- return $config_directories[$type];
- }
-
- throw new \Exception("The configuration directory type '$type' does not exist");
- }
- function drupal_get_filename($type, $name, $filename = NULL) {
-
-
- static $files = [];
-
-
-
-
- if ($type === 'core') {
- return 'core/core.info.yml';
- }
-
-
- if ($type == 'profile') {
- $type = 'module';
- }
- if (!isset($files[$type])) {
- $files[$type] = [];
- }
- if (isset($filename)) {
- $files[$type][$name] = $filename;
- }
- elseif (!isset($files[$type][$name])) {
-
-
-
-
- if ($type == 'module' && \Drupal::hasService('module_handler')) {
- foreach (\Drupal::moduleHandler()->getModuleList() as $module_name => $module) {
- $files[$type][$module_name] = $module->getPathname();
- }
- }
-
-
-
- if (!isset($files[$type][$name]) && \Drupal::hasService('state')) {
- $files[$type] += \Drupal::state()->get('system.' . $type . '.files', []);
- }
-
- if (!isset($files[$type][$name])) {
- trigger_error(SafeMarkup::format('The following @type is missing from the file system: @name', ['@type' => $type, '@name' => $name]), E_USER_WARNING);
- }
- }
- if (isset($files[$type][$name])) {
- return $files[$type][$name];
- }
- }
- function drupal_get_path($type, $name) {
- return dirname(drupal_get_filename($type, $name));
- }
- function t($string, array $args = [], array $options = []) {
- return new TranslatableMarkup($string, $args, $options);
- }
- function format_string($string, array $args) {
- return SafeMarkup::format($string, $args);
- }
- function drupal_validate_utf8($text) {
- return Unicode::validateUtf8($text);
- }
- function watchdog_exception($type, Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) {
-
- if (empty($message)) {
- $message = '%type: @message in %function (line %line of %file).';
- }
- if ($link) {
- $variables['link'] = $link;
- }
- $variables += Error::decodeException($exception);
- \Drupal::logger($type)->log($severity, $message, $variables);
- }
- function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
- @trigger_error('drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
- $messenger = \Drupal::messenger();
- if (isset($message)) {
- $messenger->addMessage($message, $type, $repeat);
- }
- return $messenger->all();
- }
- function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
- @trigger_error('drupal_get_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::all() or \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
- $messenger = \Drupal::messenger();
- if ($messages = $messenger->all()) {
- if ($type) {
- if ($clear_queue) {
- $messenger->deleteByType($type);
- }
- if (isset($messages[$type])) {
- return [$type => $messages[$type]];
- }
- }
- else {
- if ($clear_queue) {
- $messenger->deleteAll();
- }
- return $messages;
- }
- }
- return [];
- }
- function drupal_get_user_timezone() {
- $user = \Drupal::currentUser();
- $config = \Drupal::config('system.date');
- if ($user && $config->get('timezone.user.configurable') && $user->isAuthenticated() && $user->getTimezone()) {
- return $user->getTimezone();
- }
- else {
-
-
- $config_data_default_timezone = $config->get('timezone.default');
- return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get();
- }
- }
- function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
- require_once __DIR__ . '/errors.inc';
- _drupal_error_handler_real($error_level, $message, $filename, $line, $context);
- }
- function _drupal_exception_handler($exception) {
- require_once __DIR__ . '/errors.inc';
- try {
-
- _drupal_log_error(Error::decodeException($exception), TRUE);
- }
-
-
- catch (\Throwable $error) {
- _drupal_exception_handler_additional($exception, $error);
- }
-
- catch (\Exception $exception2) {
- _drupal_exception_handler_additional($exception, $exception2);
- }
- }
- function _drupal_exception_handler_additional($exception, $exception2) {
-
-
-
- if (error_displayable()) {
- print '<h1>Additional uncaught exception thrown while handling exception.</h1>';
- print '<h2>Original</h2><p>' . Error::renderExceptionSafe($exception) . '</p>';
- print '<h2>Additional</h2><p>' . Error::renderExceptionSafe($exception2) . '</p><hr />';
- }
- }
- function drupal_valid_test_ua($new_prefix = NULL) {
- static $test_prefix;
- if (isset($new_prefix)) {
- $test_prefix = $new_prefix;
- }
- if (isset($test_prefix)) {
- return $test_prefix;
- }
-
-
- $test_prefix = FALSE;
-
-
-
- $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL;
- $user_agent = isset($_COOKIE['SIMPLETEST_USER_AGENT']) ? $_COOKIE['SIMPLETEST_USER_AGENT'] : $http_user_agent;
- if (isset($user_agent) && preg_match("/^simple(\w+\d+):(.+):(.+):(.+)$/", $user_agent, $matches)) {
- list(, $prefix, $time, $salt, $hmac) = $matches;
- $check_string = $prefix . ':' . $time . ':' . $salt;
-
-
-
-
-
- $test_db = new TestDatabase($prefix);
- $key_file = DRUPAL_ROOT . '/' . $test_db->getTestSitePath() . '/.htkey';
- if (!is_readable($key_file)) {
- header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
- exit;
- }
- $private_key = file_get_contents($key_file);
-
- $key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
- $time_diff = REQUEST_TIME - $time;
- $test_hmac = Crypt::hmacBase64($check_string, $key);
-
-
- if ($time_diff >= 0 && $time_diff <= 600 && $hmac === $test_hmac) {
- $test_prefix = $prefix;
- }
- else {
- header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden (SIMPLETEST_USER_AGENT invalid)');
- exit;
- }
- }
- return $test_prefix;
- }
- function drupal_generate_test_ua($prefix) {
- static $key, $last_prefix;
- if (!isset($key) || $last_prefix != $prefix) {
- $last_prefix = $prefix;
- $test_db = new TestDatabase($prefix);
- $key_file = DRUPAL_ROOT . '/' . $test_db->getTestSitePath() . '/.htkey';
-
-
-
-
-
- if (DRUPAL_TEST_IN_CHILD_SITE && $parent_prefix = drupal_valid_test_ua()) {
- if ($parent_prefix != $prefix) {
- throw new \RuntimeException("Malformed User-Agent: Expected '$parent_prefix' but got '$prefix'.");
- }
-
- $private_key = file_get_contents($key_file);
- }
- else {
-
-
- $private_key = Crypt::randomBytesBase64(55);
- file_put_contents($key_file, $private_key);
- }
-
- $key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
- }
-
- $salt = uniqid('', TRUE);
- $check_string = $prefix . ':' . time() . ':' . $salt;
- return 'simple' . $check_string . ':' . Crypt::hmacBase64($check_string, $key);
- }
- function drupal_maintenance_theme() {
- require_once __DIR__ . '/theme.maintenance.inc';
- _drupal_maintenance_theme();
- }
- function drupal_installation_attempted() {
-
-
-
-
-
- return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']);
- }
- function drupal_get_profile() {
- global $install_state;
- if (drupal_installation_attempted()) {
-
- if (isset($install_state['parameters']['profile'])) {
- $profile = $install_state['parameters']['profile'];
- }
- else {
- $profile = NULL;
- }
- }
- else {
- if (\Drupal::hasContainer()) {
- $profile = \Drupal::installProfile();
- }
- else {
- $profile = BootstrapConfigStorageFactory::getDatabaseStorage()->read('core.extension')['profile'];
- }
-
-
- if (empty($profile)) {
- $profile = Settings::get('install_profile');
- }
- }
- return $profile;
- }
- function drupal_classloader_register($name, $path) {
- $loader = \Drupal::service('class_loader');
- $loader->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
- }
- function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
- static $data = [], $default = [];
-
- if (isset($data[$name]) || array_key_exists($name, $data)) {
-
- if ($reset) {
-
- $data[$name] = $default[$name];
- }
- return $data[$name];
- }
-
- if (isset($name)) {
- if ($reset) {
-
-
- return $data;
- }
-
- $default[$name] = $data[$name] = $default_value;
- return $data[$name];
- }
-
-
-
- foreach ($default as $name => $value) {
- $data[$name] = $value;
- }
-
-
- return $data;
- }
- function drupal_static_reset($name = NULL) {
- drupal_static($name, NULL, TRUE);
- }
- function drupal_placeholder($text) {
- return '<em class="placeholder">' . Html::escape($text) . '</em>';
- }
- function &drupal_register_shutdown_function($callback = NULL) {
-
-
- static $callbacks = [];
- if (isset($callback)) {
-
- if (empty($callbacks)) {
- register_shutdown_function('_drupal_shutdown_function');
- }
- $args = func_get_args();
-
- unset($args[0]);
-
- $callbacks[] = ['callback' => $callback, 'arguments' => $args];
- }
- return $callbacks;
- }
- function _drupal_shutdown_function() {
- $callbacks = &drupal_register_shutdown_function();
-
-
- chdir(DRUPAL_ROOT);
- try {
- foreach ($callbacks as &$callback) {
- call_user_func_array($callback['callback'], $callback['arguments']);
- }
- }
-
-
- catch (\Throwable $error) {
- _drupal_shutdown_function_handle_exception($error);
- }
-
- catch (\Exception $exception) {
- _drupal_shutdown_function_handle_exception($exception);
- }
- }
- function _drupal_shutdown_function_handle_exception($exception) {
-
-
- if (!function_exists('fastcgi_finish_request')) {
-
-
- require_once __DIR__ . '/errors.inc';
- if (error_displayable()) {
- print '<h1>Uncaught exception thrown in shutdown function.</h1>';
- print '<p>' . Error::renderExceptionSafe($exception) . '</p><hr />';
- }
- }
- error_log($exception);
- }
|