diff options
| author | 2019-10-31 18:15:47 +0100 | |
|---|---|---|
| committer | 2019-10-31 18:15:47 +0100 | |
| commit | 3aa66f317b496ccd9a2df914bbc747c52081a7ad (patch) | |
| tree | 6a3f3f74899801abdca00546e213dfdc141c53cf /lib/lib_rss.php | |
| parent | 82611c9622ed23b0e9fcf5f9f651ddffa1fd7706 (diff) | |
| parent | fcae48f313d399050cb15f37a8a73ae52fc67796 (diff) | |
Merge pull request #2599 from FreshRSS/dev1.15.0
FreshRSS 1.15
Diffstat (limited to 'lib/lib_rss.php')
| -rw-r--r-- | lib/lib_rss.php | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php index c0ea23989..f4b5c68e6 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -1,26 +1,8 @@ <?php -if (version_compare(PHP_VERSION, '5.3.8', '<')) { - die('FreshRSS error: FreshRSS requires PHP 5.3.8+!'); +if (version_compare(PHP_VERSION, '5.6.0', '<')) { + die('FreshRSS error: FreshRSS requires PHP 5.6.0+!'); } -if (!function_exists('json_decode')) { - require_once(__DIR__ . '/JSON.php'); - function json_decode($var, $assoc = false) { - $JSON = new Services_JSON($assoc ? SERVICES_JSON_LOOSE_TYPE : 0); - return $JSON->decode($var); - } -} - -if (!function_exists('json_encode')) { - require_once(__DIR__ . '/JSON.php'); - function json_encode($var) { - $JSON = new Services_JSON(); - return $JSON->encodeUnsafe($var); - } -} - -defined('JSON_UNESCAPED_UNICODE') or define('JSON_UNESCAPED_UNICODE', 256); //PHP 5.3 - if (!function_exists('mb_strcut')) { function mb_strcut($str, $start, $length = null, $encoding = 'UTF-8') { return substr($str, $start, $length); @@ -57,6 +39,8 @@ function classAutoloader($class) { include(LIB_PATH . '/' . str_replace('_', '/', $class) . '.php'); } elseif (strpos($class, 'SimplePie') === 0) { include(LIB_PATH . '/SimplePie/' . str_replace('_', '/', $class) . '.php'); + } elseif (strpos($class, 'PHPMailer') === 0) { + include(LIB_PATH . '/' . str_replace('\\', '/', $class) . '.php'); } } @@ -68,12 +52,7 @@ function idn_to_puny($url) { $parts = parse_url($url); if (!empty($parts['host'])) { $idn = $parts['host']; - // INTL_IDNA_VARIANT_UTS46 is defined starting in PHP 5.4 - if (defined('INTL_IDNA_VARIANT_UTS46')) { - $puny = idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46); - } else { - $puny = idn_to_ascii($idn); - } + $puny = idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46); $pos = strpos($url, $idn); if ($pos !== false) { return substr_replace($url, $puny, $pos, strlen($idn)); @@ -187,17 +166,10 @@ function timestamptodate ($t, $hour = true) { function html_only_entity_decode($text) { static $htmlEntitiesOnly = null; if ($htmlEntitiesOnly === null) { - if (version_compare(PHP_VERSION, '5.3.4') >= 0) { - $htmlEntitiesOnly = array_flip(array_diff( - get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities - get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities - )); - } else { - $htmlEntitiesOnly = array_map('utf8_encode', array_flip(array_diff( - get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES), //Decode HTML entities - get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES) //Preserve XML entities - ))); - } + $htmlEntitiesOnly = array_flip(array_diff( + get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities + get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities + )); } return strtr($text, $htmlEntitiesOnly); } @@ -292,6 +264,20 @@ function sanitizeHTML($data, $base = '') { } /** + * Validate an email address, supports internationalized addresses. + * + * @param string $email The address to validate + * + * @return bool true if email is valid, else false + */ +function validateEmailAddress($email) { + $mailer = new PHPMailer\PHPMailer\PHPMailer(); + $mailer->Charset = 'utf-8'; + $punyemail = $mailer->punyencodeAddress($email); + return PHPMailer\PHPMailer\PHPMailer::validateAddress($punyemail, 'html5'); +} + +/** * Add support of image lazy loading * Move content from src attribute to data-original * @param content is the text we want to parse @@ -314,7 +300,11 @@ function invalidateHttpCache($username = '') { Minz_Session::_param('touch', uTimeString()); $username = Minz_Session::param('currentUser', '_'); } - return touch(join_path(DATA_PATH, 'users', $username, 'log.txt')); + $ok = @touch(DATA_PATH . '/users/' . $username . '/log.txt'); + //if (!$ok) { + //TODO: Display notification error on front-end + //} + return $ok; } function listUsers() { @@ -428,7 +418,7 @@ function check_install_php() { $pdo_pgsql = extension_loaded('pdo_pgsql'); $pdo_sqlite = extension_loaded('pdo_sqlite'); return array( - 'php' => version_compare(PHP_VERSION, '5.3.8') >= 0, + 'php' => version_compare(PHP_VERSION, '5.5.0') >= 0, 'minz' => file_exists(LIB_PATH . '/Minz'), 'curl' => extension_loaded('curl'), 'pdo' => $pdo_mysql || $pdo_sqlite || $pdo_pgsql, @@ -549,17 +539,16 @@ function _i($icon, $url_only = false) { } -$SHORTCUT_KEYS = array( //No const for < PHP 5.6 compatibility +const SHORTCUT_KEYS = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'Backspace', 'Delete', 'End', 'Enter', 'Escape', 'Home', 'Insert', 'PageDown', 'PageUp', 'Space', 'Tab', - ); + ]; function validateShortcutList($shortcuts) { - global $SHORTCUT_KEYS; $legacy = array( 'down' => 'ArrowDown', 'left' => 'ArrowLeft', 'page_down' => 'PageDown', 'page_up' => 'PageUp', 'right' => 'ArrowRight', 'up' => 'ArrowUp', @@ -568,17 +557,17 @@ function validateShortcutList($shortcuts) { $shortcuts_ok = array(); foreach ($shortcuts as $key => $value) { - if (in_array($value, $SHORTCUT_KEYS)) { + if (in_array($value, SHORTCUT_KEYS)) { $shortcuts_ok[$key] = $value; } elseif (isset($legacy[$value])) { $shortcuts_ok[$key] = $legacy[$value]; } else { //Case-insensitive search if ($upper === null) { - $upper = array_map('strtoupper', $SHORTCUT_KEYS); + $upper = array_map('strtoupper', SHORTCUT_KEYS); } $i = array_search(strtoupper($value), $upper); if ($i !== false) { - $shortcuts_ok[$key] = $SHORTCUT_KEYS[$i]; + $shortcuts_ok[$key] = SHORTCUT_KEYS[$i]; } } } |
