Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
RCold committed Oct 16, 2016
1 parent a553d95 commit 3e4dc52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
22 changes: 8 additions & 14 deletions .htaccess
Expand Up @@ -31,28 +31,22 @@ DirectoryIndex index.php

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
# PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
# not set.
php_value always_populate_raw_post_data -1
php_flag mbstring.encoding_translation off
</IfModule>

# PHP 7, Apache 1 and 2.
<IfModule mod_php7.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
# PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
# not set.
php_value always_populate_raw_post_data -1
php_flag mbstring.encoding_translation off
</IfModule>

# Requires mod_expires to be enabled.
Expand Down
32 changes: 18 additions & 14 deletions includes/unicode.inc
Expand Up @@ -134,8 +134,8 @@ function drupal_xml_parser_create(&$data) {
}

// Check for an encoding declaration in the XML prolog if no BOM was found.
if (!$bom && preg_match('/^<\?xml[^>]+encoding="([^"]+)"/', $data, $match)) {
$encoding = $match[1];
if (!$bom && preg_match('/^<\?xml[^>]+encoding="([^"]+)"/', $data, $matches) > 0) {
$encoding = $matches[1];
}

// Unsupported encodings are converted here into UTF-8.
Expand Down Expand Up @@ -334,21 +334,25 @@ function _mime_header_decode($matches) {
* The input $text, with all HTML entities decoded once.
*/
function decode_entities($text, $exclude = array()) {
static $html_entities;
if (!isset($html_entities)) {
include_once './includes/unicode.entities.inc';
}

// Flip the exclude list so that we can do quick lookups later.
$exclude = array_flip($exclude);

// Use a regexp to select all entities in one pass, to avoid decoding
// double-escaped entities twice. The PREG_REPLACE_EVAL modifier 'e' is
// being used to allow for a callback (see
// http://php.net/manual/en/reference.pcre.pattern.modifiers).
return preg_replace_callback('/&(#x?)?([A-Za-z0-9]+);/', function ($matches) use ($html_entities, $exclude) {
_decode_entities($matches[1], $matches[2], $matches[0], $html_entities, $exclude);
}, $text);
// Use a regexp to select all entities in one pass, to avoid decoding
// double-escaped entities twice.
_decode_entities_callback(NULL, $exclude);
return preg_replace_callback('/&(#x?)?([A-Za-z0-9]+);/', '_decode_entities_callback', $text);
}

function _decode_entities_callback($matches, $init = NULL) {
static $html_entities, $exclude;
if (!isset($html_entities)) {
include_once './includes/unicode.entities.inc';
}
if (isset($init)) {
$exclude = $init;
return NULL;
}
return _decode_entities($matches[1], $matches[2], $matches[0], $html_entities, $exclude);
}

/**
Expand Down

0 comments on commit 3e4dc52

Please sign in to comment.