From 01e71254d95882e8568bf69cdefe2c332e8c0fb2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 May 2019 16:15:38 -0400 Subject: [PATCH 1/6] Replace defaults() calls on $_SESSION by Core\Session calls - Replace direct calls to $_SESSION by Core\Session calls in Module\Login --- include/conversation.php | 3 ++- mod/network.php | 3 ++- mod/settings.php | 5 +++-- src/App.php | 13 +++++++------ src/Content/Nav.php | 5 +++-- src/Core/Session.php | 8 +------- src/Module/Login.php | 27 +++++++++------------------ src/Module/Profile.php | 8 ++++++-- src/Object/Post.php | 3 ++- view/theme/frio/theme.php | 5 ++--- 10 files changed, 37 insertions(+), 43 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 85938ca0f0..3b3c7a4c18 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -15,6 +15,7 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -528,7 +529,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
' . "\r\n" - . ""; } } elseif ($mode === 'community') { diff --git a/mod/network.php b/mod/network.php index 30e31cea3c..cbd3071ece 100644 --- a/mod/network.php +++ b/mod/network.php @@ -19,6 +19,7 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -854,7 +855,7 @@ function networkThreadedView(App $a, $update, $parent) ((time() - $_SESSION['network_last_date_timestamp']) < ($browser_update * 10))) { $bottom_limit = $_SESSION['network_last_date']; } - $_SESSION['network_last_date'] = defaults($_SESSION, 'network_last_top_limit', $top_limit); + $_SESSION['network_last_date'] = Session::get('network_last_top_limit', $top_limit); $_SESSION['network_last_date_timestamp'] = time(); if ($last_date > $top_limit) { diff --git a/mod/settings.php b/mod/settings.php index 45f11cdb6c..efb601f4d2 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -14,6 +14,7 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Core\Worker; @@ -910,8 +911,8 @@ function settings_content(App $a) } } - $theme_selected = defaults($_SESSION, 'theme' , $default_theme); - $mobile_theme_selected = defaults($_SESSION, 'mobile-theme', $default_mobile_theme); + $theme_selected = Session::get('theme', $default_theme); + $mobile_theme_selected = Session::get('mobile-theme', $default_mobile_theme); $nowarn_insecure = intval(PConfig::get(local_user(), 'system', 'nowarn_insecure')); diff --git a/src/App.php b/src/App.php index 2e357f8651..7ef4e49195 100644 --- a/src/App.php +++ b/src/App.php @@ -1038,10 +1038,11 @@ class App // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") && strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) { - if (defaults($_SESSION, "visitor_home", "") != $_GET["zrl"]) { - $_SESSION['my_url'] = $_GET['zrl']; - $_SESSION['authenticated'] = 0; + if (Core\Session::get('visitor_home') != $_GET["zrl"]) { + Core\Session::set('my_url', $_GET['zrl']); + Core\Session::set('authenticated', 0); } + Model\Profile::zrlInit($this); } else { // Someone came with an invalid parameter, maybe as a DDoS attempt @@ -1066,9 +1067,9 @@ class App header('X-Account-Management-Status: none'); } - $_SESSION['sysmsg'] = defaults($_SESSION, 'sysmsg' , []); - $_SESSION['sysmsg_info'] = defaults($_SESSION, 'sysmsg_info' , []); - $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []); + $_SESSION['sysmsg'] = Core\Session::get('sysmsg', []); + $_SESSION['sysmsg_info'] = Core\Session::get('sysmsg_info', []); + $_SESSION['last_updated'] = Core\Session::get('last_updated', []); /* * check_config() is responsible for running update scripts. These automatically diff --git a/src/Content/Nav.php b/src/Content/Nav.php index a63244e856..cb4564115a 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -9,6 +9,7 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Profile; @@ -172,7 +173,7 @@ class Nav // "Home" should also take you home from an authenticated remote profile connection $homelink = Profile::getMyURL(); if (! $homelink) { - $homelink = defaults($_SESSION, 'visitor_home', ''); + $homelink = Session::get('visitor_home', ''); } if (($a->module != 'home') && (! (local_user()))) { @@ -241,7 +242,7 @@ class Nav $nav['home'] = ['profile/' . $a->user['nickname'], L10n::t('Home'), '', L10n::t('Your posts and conversations')]; // Don't show notifications for public communities - if (defaults($_SESSION, 'page_flags', '') != User::PAGE_FLAGS_COMMUNITY) { + if (Session::get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) { $nav['introductions'] = ['notifications/intros', L10n::t('Introductions'), '', L10n::t('Friend Requests')]; $nav['notifications'] = ['notifications', L10n::t('Notifications'), '', L10n::t('Notifications')]; $nav['notifications']['all'] = ['notifications/system', L10n::t('See all notifications'), '', '']; diff --git a/src/Core/Session.php b/src/Core/Session.php index 8b6c26bc57..e54c0e49b9 100644 --- a/src/Core/Session.php +++ b/src/Core/Session.php @@ -62,13 +62,7 @@ class Session */ public static function get($name, $defaults = null) { - if (isset($_SESSION)) { - $return = defaults($_SESSION, $name, $defaults); - } else { - $return = $defaults; - } - - return $return; + return $_SESSION[$name] ?? $defaults; } /** diff --git a/src/Module/Login.php b/src/Module/Login.php index 7a3b6ae457..a8cb838517 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -32,26 +32,21 @@ class Login extends BaseModule { $a = self::getApp(); - if (!empty($_SESSION['theme'])) { - unset($_SESSION['theme']); - } - - if (!empty($_SESSION['mobile-theme'])) { - unset($_SESSION['mobile-theme']); - } + Session::remove('theme'); + Session::remove('mobile-theme'); if (local_user()) { $a->internalRedirect(); } - return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED); + return self::form(Session::get('return_path'), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED); } public static function post() { - $return_path = defaults($_SESSION, 'return_path', ''); + $return_path = Session::get('return_path'); session_unset(); - $_SESSION['return_path'] = $return_path; + Session::set('return_path', $return_path); // OpenId Login if ( @@ -159,17 +154,13 @@ class Login extends BaseModule } // if we haven't failed up this point, log them in. - $_SESSION['remember'] = $remember; - $_SESSION['last_login_date'] = DateTimeFormat::utcNow(); + Session::set('remember', $remember); + Session::set('last_login_date', DateTimeFormat::utcNow()); Session::setAuthenticatedForUser($a, $record, true, true); - if (!empty($_SESSION['return_path'])) { - $return_path = $_SESSION['return_path']; - unset($_SESSION['return_path']); - } else { - $return_path = ''; - } + $return_path = Session::get('return_path', ''); + Session::remove('return_path'); $a->internalRedirect($return_path); } diff --git a/src/Module/Profile.php b/src/Module/Profile.php index fceea726b4..36b3ba1a82 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -11,6 +11,7 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact as ContactModel; @@ -226,8 +227,10 @@ class Profile extends BaseModule $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups, $remote_cid); $sql_extra2 = ''; + $last_updated_array = Session::get('last_updated', []); + if ($update) { - $last_updated = (defaults($_SESSION['last_updated'], $last_updated_key, 0)); + $last_updated = $last_updated_array[$last_updated_key] ?? 0; // If the page user is the owner of the page we should query for unseen // items. Otherwise use a timestamp of the last succesful update request. @@ -334,7 +337,8 @@ class Profile extends BaseModule // Set a time stamp for this page. We will make use of it when we // search for new items (update routine) - $_SESSION['last_updated'][$last_updated_key] = time(); + $last_updated_array[$last_updated_key] = time(); + Session::set('last_updated', $last_updated_array); if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) { $o .= ProfileModel::getBirthdays(); diff --git a/src/Object/Post.php b/src/Object/Post.php index a8577dd8be..173b1e53af 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -15,6 +15,7 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Item; @@ -400,7 +401,7 @@ class Post extends BaseObject 'location' => $location_e, 'indent' => $indent, 'shiny' => $shiny, - 'owner_self' => $item['author-link'] == defaults($_SESSION, 'my_url', null), + 'owner_self' => $item['author-link'] == Session::get('my_url'), 'owner_url' => $this->getOwnerUrl(), 'owner_photo' => $a->removeBaseURL(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)), 'owner_name' => $owner_name_e, diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 9434b340d2..e7c2510783 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -14,9 +14,8 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\PConfig; use Friendica\Core\Renderer; -use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model; use Friendica\Module; @@ -201,7 +200,7 @@ function frio_remote_nav($a, &$nav) // get the homelink from $_XSESSION $homelink = Model\Profile::getMyURL(); if (!$homelink) { - $homelink = defaults($_SESSION, 'visitor_home', ''); + $homelink = Session::get('visitor_home', ''); } // split up the url in it's parts (protocol,domain/directory, /profile/, nickname From c8dd290f18ceb12e6a3df3550309911b3e936b35 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 May 2019 21:28:34 -0400 Subject: [PATCH 2/6] Deprecate defaults() function in favor of native coalesce operator --- boot.php | 1 + 1 file changed, 1 insertion(+) diff --git a/boot.php b/boot.php index dfedcdbbbe..9076331290 100644 --- a/boot.php +++ b/boot.php @@ -334,6 +334,7 @@ function get_app() * @param array $args * @brief Returns a defaut value if the provided variable or array key is falsy * @return mixed + * @deprecated since version 2019.06, use native coalesce operator (??) instead */ function defaults(...$args) { From 596b5b0982029f1633315271d56b818d02bfd3b0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 May 2019 12:01:48 -0400 Subject: [PATCH 3/6] Simplify HTML::toPlaintext - Keep new lines in plain text output --- src/Content/Text/HTML.php | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 47463bdd09..4be217b3e4 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -567,7 +567,13 @@ class HTML return $urls; } - public static function toPlaintext($html, $wraplength = 75, $compact = false) + /** + * @param string $html + * @param int $wraplength Ensures individual lines aren't longer than this many characters. Doesn't break words. + * @param bool $compact True: Completely strips image tags; False: Keeps image URLs + * @return string + */ + public static function toPlaintext(string $html, $wraplength = 75, $compact = false) { $message = str_replace("\r", "", $html); @@ -578,15 +584,9 @@ class HTML @$doc->loadHTML($message); - $xpath = new DOMXPath($doc); - $list = $xpath->query("//pre"); - foreach ($list as $node) { - $node->nodeValue = str_replace("\n", "\r", $node->nodeValue); - } - $message = $doc->saveHTML(); - $message = str_replace(["\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"], ["<", ">", "
", " ", ""], $message); - $message = preg_replace('= [\s]*=i', " ", $message); + // Remove eventual UTF-8 BOM + $message = str_replace("\xC3\x82\xC2\xA0", "", $message); // Collecting all links $urls = self::collectURLs($message); @@ -596,18 +596,6 @@ class HTML self::tagToBBCode($doc, 'html', [], '', ''); self::tagToBBCode($doc, 'body', [], '', ''); - // MyBB-Auszeichnungen - /* - self::node2BBCode($doc, 'span', array('style'=>'text-decoration: underline;'), '_', '_'); - self::node2BBCode($doc, 'span', array('style'=>'font-style: italic;'), '/', '/'); - self::node2BBCode($doc, 'span', array('style'=>'font-weight: bold;'), '*', '*'); - - self::node2BBCode($doc, 'strong', array(), '*', '*'); - self::node2BBCode($doc, 'b', array(), '*', '*'); - self::node2BBCode($doc, 'i', array(), '/', '/'); - self::node2BBCode($doc, 'u', array(), '_', '_'); - */ - if ($compact) { self::tagToBBCode($doc, 'blockquote', [], "»", "«"); } else { @@ -621,8 +609,6 @@ class HTML self::tagToBBCode($doc, 'div', [], "\r", "\r"); self::tagToBBCode($doc, 'p', [], "\n", "\n"); - //self::node2BBCode($doc, 'ul', array(), "\n[list]", "[/list]\n"); - //self::node2BBCode($doc, 'ol', array(), "\n[list=1]", "[/list]\n"); self::tagToBBCode($doc, 'li', [], "\n* ", "\n"); self::tagToBBCode($doc, 'hr', [], "\n" . str_repeat("-", 70) . "\n", ""); @@ -637,12 +623,6 @@ class HTML self::tagToBBCode($doc, 'h5', [], "\n\n*", "*\n"); self::tagToBBCode($doc, 'h6', [], "\n\n*", "*\n"); - // Problem: there is no reliable way to detect if it is a link to a tag or profile - //self::node2BBCode($doc, 'a', array('href'=>'/(.+)/'), ' $1 ', ' ', true); - //self::node2BBCode($doc, 'a', array('href'=>'/(.+)/', 'rel'=>'oembed'), ' $1 ', '', true); - //self::node2BBCode($doc, 'img', array('alt'=>'/(.+)/'), '$1', ''); - //self::node2BBCode($doc, 'img', array('title'=>'/(.+)/'), '$1', ''); - //self::node2BBCode($doc, 'img', array(), '', ''); if (!$compact) { self::tagToBBCode($doc, 'img', ['src' => '/(.+)/'], ' [img]$1', '[/img] '); } else { From 5f9fb1f14f47b666f8716ca0b2e095fa6242886e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 May 2019 12:02:12 -0400 Subject: [PATCH 4/6] Simplify BBCode::toPlaintext - Keep white spaces after tags --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index e417b38a46..c4735b9e93 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -355,7 +355,7 @@ class BBCode extends BaseObject */ public static function toPlaintext($text, $keep_urls = true) { - $naked_text = preg_replace('/\[(.+?)\]\s*/','', $text); + $naked_text = preg_replace('/\[.+?\]/','', $text); if (!$keep_urls) { $naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text); } From 5d2bf735178ae0fcea8ba6b5831e65ef698cec6d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 May 2019 12:02:28 -0400 Subject: [PATCH 5/6] Add Babel result screen for compact HTML::toPlaintext --- src/Module/Debug/Babel.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Module/Debug/Babel.php b/src/Module/Debug/Babel.php index 1ce1ac4c6e..be10da7ea4 100644 --- a/src/Module/Debug/Babel.php +++ b/src/Module/Debug/Babel.php @@ -159,6 +159,12 @@ class Babel extends BaseModule 'title' => L10n::t('HTML::toPlaintext'), 'content' => '
' . $text . '
' ]; + + $text = Text\HTML::toPlaintext($html, 0, true); + $results[] = [ + 'title' => L10n::t('HTML::toPlaintext'), + 'content' => '
' . $text . '
' + ]; } } From 5e4ace271b1a425f7a883b5072f9136058f04b28 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 23 Jun 2019 17:52:05 -0400 Subject: [PATCH 6/6] Welcome 2019.09-dev! --- CHANGELOG | 2 ++ VERSION | 2 +- boot.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1fa98ee870..df15f41ebf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +Version 2019.09-dev (UNRELEASED) + Version 2019.06 (2019-06-23) Friendica Core: Update to the tranlation (CS, DE, EN-GB, EN-US, ET, FR, IT, PL, PT-BR, SV) [translation teams] diff --git a/VERSION b/VERSION index 4eda9a567d..bb3511a1d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2019.06 +2019.09-dev diff --git a/boot.php b/boot.php index 24e013fa11..086e74d2f4 100644 --- a/boot.php +++ b/boot.php @@ -31,7 +31,7 @@ use Friendica\Util\DateTimeFormat; define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_CODENAME', 'Dalmatian Bellflower'); -define('FRIENDICA_VERSION', '2019.06'); +define('FRIENDICA_VERSION', '2019.09-dev'); define('DFRN_PROTOCOL_VERSION', '2.23'); define('NEW_UPDATE_ROUTINE_VERSION', 1170);