From 301fea8684f194bd622994494706b3676fdea299 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 05:51:39 -0400 Subject: [PATCH 01/12] ping.php performance: caching baseurl --- boot.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/boot.php b/boot.php index e49ffbd22..4fefe6f7e 100644 --- a/boot.php +++ b/boot.php @@ -787,27 +787,29 @@ class App { if (!is_object($this)) return(self::$a->get_baseurl($ssl)); - $scheme = $this->scheme; + if (!$this->baseurl) { + $scheme = $this->scheme; - if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) { - if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL)) - $scheme = 'https'; - - // Basically, we have $ssl = true on any links which can only be seen by a logged in user - // (and also the login link). Anything seen by an outsider will have it turned off. - - if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if($ssl) + if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) { + if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL)) $scheme = 'https'; - else - $scheme = 'http'; + + // Basically, we have $ssl = true on any links which can only be seen by a logged in user + // (and also the login link). Anything seen by an outsider will have it turned off. + + if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { + if($ssl) + $scheme = 'https'; + else + $scheme = 'http'; + } } + + if (get_config('config','hostname') != "") + $this->hostname = get_config('config','hostname'); + + $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); } - - if (get_config('config','hostname') != "") - $this->hostname = get_config('config','hostname'); - - $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); return $this->baseurl; } From 63e5342ced5720d1fd55b8d09462edd945474e32 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 05:54:26 -0400 Subject: [PATCH 02/12] ping.php performance: removing datetime_convert --- include/datetime.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/datetime.php b/include/datetime.php index ea98f01fe..626e0b92c 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -328,12 +328,12 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke * @param string $posted_date * @param string $format (optional) Parsed with sprintf() * %1$d %2$s ago, e.g. 22 hours ago, 1 minute ago - * + * * @return string with relative date */ -function relative_date($posted_date,$format = null) { +function relative_date($posted_date, $format = null) { - $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date); + $localtime = $posted_date . ' UTC'; $abs = strtotime($localtime); @@ -347,13 +347,6 @@ function relative_date($posted_date,$format = null) { return t('less than a second ago'); } - /* - $time_append = ''; - if ($etime >= 86400) { - $time_append = ' ('.$localtime.')'; - } - */ - $a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')), 30 * 24 * 60 * 60 => array( t('month'), t('months')), 7 * 24 * 60 * 60 => array( t('week'), t('weeks')), @@ -368,8 +361,9 @@ function relative_date($posted_date,$format = null) { if ($d >= 1) { $r = round($d); // translators - e.g. 22 hours ago, 1 minute ago - if(! $format) + if(! $format) { $format = t('%1$d %2$s ago'); + } return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1])); } From 747f902e21f7ddf9e94ede295fe3c12c3ade2eb1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 05:55:19 -0400 Subject: [PATCH 03/12] ping.php performance: optimizing session_write queries --- include/session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/session.php b/include/session.php index 8f9d64606..4e7befb1b 100644 --- a/include/session.php +++ b/include/session.php @@ -40,12 +40,12 @@ function ref_session_write ($id,$data) { if($session_exists) { $r = q("UPDATE `session` SET `data` = '%s' - WHERE `data` != '%s' AND `sid` = '%s'", + WHERE `sid` = '%s' AND `data` != '%s'", dbesc($data), dbesc($data), dbesc($id)); $r = q("UPDATE `session` SET `expire` = '%s' - WHERE `expire` != '%s' AND `sid` = '%s'", + WHERE `sid` = '%s' AND `expire` != '%s'", dbesc($expire), dbesc($expire), dbesc($id)); } else $r = q("INSERT INTO `session` From f1c855e755aa1a51bba210221a5a2c1850cfec88 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 06:28:16 -0400 Subject: [PATCH 04/12] ping.php performance: Cache notification bbcode - Add two fields to notifiy table to store cached bbcode result - Add bbcode conversion on notif creation - Add postfact caching if cache field is empty on retrieval --- boot.php | 2 +- database.sql | 2 ++ include/dbstructure.php | 2 ++ include/enotify.php | 35 +++++++++++++++++++++++++---- mod/ping.php | 49 +++++++++++++++++++++++------------------ update.php | 2 +- 6 files changed, 65 insertions(+), 27 deletions(-) diff --git a/boot.php b/boot.php index 4fefe6f7e..cb4feef90 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1206 ); +define ( 'DB_UPDATE_VERSION', 1207 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index f12746e7e..c5fd49ba0 100644 --- a/database.sql +++ b/database.sql @@ -655,6 +655,8 @@ CREATE TABLE IF NOT EXISTS `notify` ( `seen` tinyint(1) NOT NULL DEFAULT 0, `verb` varchar(255) NOT NULL DEFAULT '', `otype` varchar(16) NOT NULL DEFAULT '', + `name_cache` tinytext, + `msg_name` mediumtext, PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8mb4; diff --git a/include/dbstructure.php b/include/dbstructure.php index fdf09d90d..8053965e0 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1036,6 +1036,8 @@ function db_definition($charset) { "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""), + "name_cache" => array("type" => "tinytext"), + "msg_cache" => array("type" => "mediumtext") ), "indexes" => array( "PRIMARY" => array("id"), diff --git a/include/enotify.php b/include/enotify.php index 4973bedc2..bcb2ebe7c 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -418,6 +418,7 @@ function notification($params) { $datarray = array(); $datarray['hash'] = $hash; $datarray['name'] = $params['source_name']; + $datarray['name_cache'] = strip_tags(bbcode($params['source_name'])); $datarray['url'] = $params['source_link']; $datarray['photo'] = $params['source_photo']; $datarray['date'] = datetime_convert(); @@ -439,7 +440,7 @@ function notification($params) { // create notification entry in DB - $r = q("INSERT INTO `notify` (`hash`, `name`, `url`, `photo`, `date`, `uid`, `link`, `iid`, `parent`, `type`, `verb`, `otype`) + $r = q("INSERT INTO `notify` (`hash`, `name`, `url`, `photo`, `date`, `uid`, `link`, `iid`, `parent`, `type`, `verb`, `otype`, `name_cache`) values('%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s')", dbesc($datarray['hash']), dbesc($datarray['name']), @@ -452,7 +453,8 @@ function notification($params) { intval($datarray['parent']), intval($datarray['type']), dbesc($datarray['verb']), - dbesc($datarray['otype']) + dbesc($datarray['otype']), + dbesc($datarray["name_cache"]) ); $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' AND `uid` = %d LIMIT 1", @@ -494,8 +496,10 @@ function notification($params) { $itemlink = $a->get_baseurl().'/notify/view/'.$notify_id; $msg = replace_macros($epreamble, array('$itemlink' => $itemlink)); - $r = q("UPDATE `notify` SET `msg` = '%s' WHERE `id` = %d AND `uid` = %d", + $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(bbcode($msg))); + $r = q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($msg), + dbesc($msg_cache), intval($notify_id), intval($params['uid']) ); @@ -778,4 +782,27 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { if (isset($params["type"])) notification($params); } -?> + +/** + * @brief Formats a notification message with the notification author + * + * Replace the name with {0} but ensure to make that only once. The {0} is used + * later and prints the name in bold. + * + * @param string $name + * @param string $message + * @return string Formatted message + */ +function format_notification_message($name, $message) { + if ($name != '') { + $pos = strpos($message, $name); + } else { + $pos = false; + } + + if ($pos !== false) { + $message = substr_replace($message, '{0}', $pos, strlen($name)); + } + + return $message; +} \ No newline at end of file diff --git a/mod/ping.php b/mod/ping.php index 8c28e7474..a90537122 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -344,6 +344,12 @@ function ping_init(&$a) { killme(); } +/** + * @brief Retrieves the notifications array for the given user ID + * + * @param int $uid + * @return array + */ function ping_get_notifications($uid) { $result = array(); @@ -372,46 +378,47 @@ function ping_get_notifications($uid) { $seensql = ""; $order = "DESC"; $offset = 0; - } elseif (!$r) + } elseif (!$r) { $quit = true; - else + } else { $offset += 50; - + } foreach ($r AS $notification) { - if (is_null($notification["visible"])) + if (is_null($notification["visible"])) { $notification["visible"] = true; + } - if (is_null($notification["spam"])) + if (is_null($notification["spam"])) { $notification["spam"] = 0; + } - if (is_null($notification["deleted"])) + if (is_null($notification["deleted"])) { $notification["deleted"] = 0; + } - $notification["message"] = strip_tags(bbcode($notification["msg"])); - $notification["name"] = strip_tags(bbcode($notification["name"])); + if ($notification["msg_cache"]) { + $notification["name"] = $notification["name_cache"]; + $notification["message"] = $notification["msg_cache"]; + } else { + $notification["name"] = strip_tags(bbcode($notification["name"])); + $notification["message"] = format_notification_message($notification["name"], strip_tags(bbcode($notification["msg"]))); - // Replace the name with {0} but ensure to make that only once - // The {0} is used later and prints the name in bold. + q("UPDATE `notify` SET `name_cache` = '%s', `msg_cache` = '%s' WHERE `id` = %d", + dbesc($notification["name"]), + dbesc($notification["message"]), + intval($notification["id"]) + ); + } - if ($notification['name'] != "") - $pos = strpos($notification["message"],$notification['name']); - else - $pos = false; - - if ($pos !== false) - $notification["message"] = substr_replace($notification["message"],"{0}",$pos,strlen($notification["name"])); - - $notification['href'] = $a->get_baseurl() . '/notify/view/' . $notification['id']; + $notification["href"] = $a->get_baseurl() . "/notify/view/" . $notification["id"]; if ($notification["visible"] AND !$notification["spam"] AND !$notification["deleted"] AND !is_array($result[$notification["parent"]])) { $result[$notification["parent"]] = $notification; } } - } while ((count($result) < 50) AND !$quit); - return($result); } diff --git a/update.php b/update.php index 756091113..5eab9c220 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Fri, 28 Oct 2016 06:50:08 -0400 Subject: [PATCH 05/12] ping.php performance: improve baseurl caching - Add cache invalidation on set_baseurl - Add documentation - Fix formatting --- boot.php | 58 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/boot.php b/boot.php index cb4feef90..279a9f292 100644 --- a/boot.php +++ b/boot.php @@ -781,16 +781,25 @@ class App { return($this->scheme); } + /** + * @brief Retrieves the Friendica instance base URL + * + * Caches both SSL and non-SSL version for performance + * + * @param bool $ssl + * @return string + */ function get_baseurl($ssl = false) { // Is the function called statically? - if (!is_object($this)) + if (!is_object($this)) { return(self::$a->get_baseurl($ssl)); + } - if (!$this->baseurl) { + if (!isset($this->baseurl[$ssl ? 'https' : 'http'])) { $scheme = $this->scheme; - if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) { + if((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL)) $scheme = 'https'; @@ -798,45 +807,58 @@ class App { // (and also the login link). Anything seen by an outsider will have it turned off. if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if($ssl) + if($ssl) { $scheme = 'https'; - else + } else { $scheme = 'http'; + } } } - if (get_config('config','hostname') != "") - $this->hostname = get_config('config','hostname'); + if (get_config('config','hostname') != '') { + $this->hostname = get_config('config', 'hostname'); + } - $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); + $this->baseurl[$ssl ? 'https' : 'http'] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); } - return $this->baseurl; + return $this->baseurl[$ssl ? 'https' : 'http']; } + /** + * @brief Initializes the baseurl components + * + * Clears the baseurl cache to prevent inconstistencies + * + * @param string $url + */ function set_baseurl($url) { $parsed = @parse_url($url); - $this->baseurl = $url; + $this->baseurl = []; if($parsed) { $this->scheme = $parsed['scheme']; $hostname = $parsed['host']; - if(x($parsed,'port')) + if (x($parsed, 'port')) { $hostname .= ':' . $parsed['port']; - if(x($parsed,'path')) - $this->path = trim($parsed['path'],'\\/'); + } + if (x($parsed, 'path')) { + $this->path = trim($parsed['path'], '\\/'); + } - if (file_exists(".htpreconfig.php")) + if (file_exists(".htpreconfig.php")) { @include(".htpreconfig.php"); + } - if (get_config('config','hostname') != "") - $this->hostname = get_config('config','hostname'); + if (get_config('config', 'hostname') != '') { + $this->hostname = get_config('config', 'hostname'); + } - if (!isset($this->hostname) OR ($this->hostname == "")) + if (!isset($this->hostname) OR ($this->hostname == '')) { $this->hostname = $hostname; + } } - } function get_hostname() { From cc4363c5c62656512d64025ee25b5c25887303f0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 12:29:55 -0400 Subject: [PATCH 06/12] ping.php performance: fix formatting --- boot.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/boot.php b/boot.php index 279a9f292..895530351 100644 --- a/boot.php +++ b/boot.php @@ -793,21 +793,22 @@ class App { // Is the function called statically? if (!is_object($this)) { - return(self::$a->get_baseurl($ssl)); + return self::$a->get_baseurl($ssl); } if (!isset($this->baseurl[$ssl ? 'https' : 'http'])) { $scheme = $this->scheme; - if((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { - if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL)) + if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { + if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) { $scheme = 'https'; + } // Basically, we have $ssl = true on any links which can only be seen by a logged in user // (and also the login link). Anything seen by an outsider will have it turned off. - if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if($ssl) { + if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { + if ($ssl) { $scheme = 'https'; } else { $scheme = 'http'; @@ -815,7 +816,7 @@ class App { } } - if (get_config('config','hostname') != '') { + if (get_config('config', 'hostname') != '') { $this->hostname = get_config('config', 'hostname'); } From bc407080d2832b2096b0f46e715d4f0fe2b97670 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 22:14:51 -0400 Subject: [PATCH 07/12] ping.php performance: improve documentation and formatting --- doc/database/db_notify.md | 36 +++++++++++++++++++----------------- include/session.php | 25 +++++++++++++++++++------ mod/ping.php | 4 ++-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/doc/database/db_notify.md b/doc/database/db_notify.md index 5ef2aa7eb..b2bae6471 100644 --- a/doc/database/db_notify.md +++ b/doc/database/db_notify.md @@ -1,22 +1,24 @@ Table notify ============ -| Field | Description | Type | Null | Key | Default | Extra | -| ------ | --------------------------------- | ------------ | ---- | --- | ------------------- | --------------- | -| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment | -| hash | | varchar(64) | NO | | | | -| type | | int(11) | NO | | 0 | | -| name | | varchar(255) | NO | | | | -| url | | varchar(255) | NO | | | | -| photo | | varchar(255) | NO | | | | -| date | | datetime | NO | | 0000-00-00 00:00:00 | | -| msg | | mediumtext | NO | | NULL | | -| uid | user.id of the owner of this data | int(11) | NO | MUL | 0 | | -| link | | varchar(255) | NO | | | | -| parent | | int(11) | NO | | 0 | | -| seen | | tinyint(1) | NO | | 0 | | -| verb | | varchar(255) | NO | | | | -| otype | | varchar(16) | NO | | | | -| iid | item.id | int(11) | NO | | 0 | | +| Field | Description | Type | Null | Key | Default | Extra | +| ---------- | --------------------------------- | ------------ | ---- | --- | ------------------- | --------------- | +| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment | +| hash | | varchar(64) | NO | | | | +| type | | int(11) | NO | | 0 | | +| name | | varchar(255) | NO | | | | +| url | | varchar(255) | NO | | | | +| photo | | varchar(255) | NO | | | | +| date | | datetime | NO | | 0000-00-00 00:00:00 | | +| msg | | mediumtext | YES | | NULL | | +| uid | user.id of the owner of this data | int(11) | NO | MUL | 0 | | +| link | | varchar(255) | NO | | | | +| iid | item.id | int(11) | NO | | 0 | | +| parent | | int(11) | NO | | 0 | | +| seen | | tinyint(1) | NO | | 0 | | +| verb | | varchar(255) | NO | | | | +| otype | | varchar(16) | NO | | | | +| name_cache | Cached bbcode parsing of name | tinytext | YES | | NULL | | +| msg_cache | Cached bbcode parsing of msg | mediumtext | YES | | NULL | | Return to [database documentation](help/database) diff --git a/include/session.php b/include/session.php index 4e7befb1b..23066be42 100644 --- a/include/session.php +++ b/include/session.php @@ -26,18 +26,30 @@ function ref_session_read ($id) { return ''; }} -if(! function_exists('ref_session_write')) { -function ref_session_write ($id,$data) { +/** + * @brief Standard PHP session write callback + * + * This callback updates the DB-stored session data and/or the expiration depending + * on the case. Uses the $session_expire global for existing session, 5 minutes + * for newly created session. + * + * @global bool $session_exists Whether a session with the given id already exists + * @global int $session_expire Session expiration delay in seconds + * @param string $id Session ID with format: [a-z0-9]{26} + * @param string $data Serialized session data + * @return boolean Returns false if parameters are missing, true otherwise + */ +function ref_session_write($id, $data) { global $session_exists, $session_expire; - if(! $id || ! $data) { + if (!$id || !$data) { return false; } $expire = time() + $session_expire; $default_expire = time() + 300; - if($session_exists) { + if ($session_exists) { $r = q("UPDATE `session` SET `data` = '%s' WHERE `sid` = '%s' AND `data` != '%s'", @@ -47,13 +59,14 @@ function ref_session_write ($id,$data) { SET `expire` = '%s' WHERE `sid` = '%s' AND `expire` != '%s'", dbesc($expire), dbesc($expire), dbesc($id)); - } else + } else { $r = q("INSERT INTO `session` SET `sid` = '%s', `expire` = '%s', `data` = '%s'", dbesc($id), dbesc($default_expire), dbesc($data)); + } return true; -}} +} if(! function_exists('ref_session_close')) { function ref_session_close() { diff --git a/mod/ping.php b/mod/ping.php index a90537122..0ed7eb3fe 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -347,8 +347,8 @@ function ping_init(&$a) { /** * @brief Retrieves the notifications array for the given user ID * - * @param int $uid - * @return array + * @param int $uid User id + * @return array Associative array of notifications */ function ping_get_notifications($uid) { From 0131656a06ddb7162e687cfa598a9d2aecea0a9d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 22:15:24 -0400 Subject: [PATCH 08/12] ping.php perfomance: reverting useless session write changes --- include/session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/session.php b/include/session.php index 23066be42..5cf4bcc9c 100644 --- a/include/session.php +++ b/include/session.php @@ -52,12 +52,12 @@ function ref_session_write($id, $data) { if ($session_exists) { $r = q("UPDATE `session` SET `data` = '%s' - WHERE `sid` = '%s' AND `data` != '%s'", + WHERE `data` != '%s' AND `sid` = '%s'", dbesc($data), dbesc($data), dbesc($id)); $r = q("UPDATE `session` SET `expire` = '%s' - WHERE `sid` = '%s' AND `expire` != '%s'", + WHERE `expire` != '%s' AND `sid` = '%s'", dbesc($expire), dbesc($expire), dbesc($id)); } else { $r = q("INSERT INTO `session` From cd3f98d27dc6ffaa188cc81f0f50217cd8b3bf1d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 28 Oct 2016 22:27:26 -0400 Subject: [PATCH 09/12] ping.php improvement: db version bump --- boot.php | 2 +- update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index 0be159540..5df6520db 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1207 ); +define ( 'DB_UPDATE_VERSION', 1208 ); /** * @brief Constant with a HTML line break. diff --git a/update.php b/update.php index 5eab9c220..fa03ddd1a 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Mon, 31 Oct 2016 14:27:19 -0400 Subject: [PATCH 10/12] ping.php improvement: using baser cache key --- boot.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index 5df6520db..8dd43101c 100644 --- a/boot.php +++ b/boot.php @@ -800,7 +800,9 @@ class App { return self::$a->get_baseurl($ssl); } - if (!isset($this->baseurl[$ssl ? 'https' : 'http'])) { + $cache_index = $ssl ? 'https' : 'http'; + + if (!isset($this->baseurl[$cache_index])) { $scheme = $this->scheme; if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { @@ -824,9 +826,9 @@ class App { $this->hostname = get_config('config', 'hostname'); } - $this->baseurl[$ssl ? 'https' : 'http'] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); + $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); } - return $this->baseurl[$ssl ? 'https' : 'http']; + return $this->baseurl[$cache_index]; } /** From 5e188a9250d42a82cd6b8e84d65875f3bc6067fb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 1 Nov 2016 02:04:59 -0400 Subject: [PATCH 11/12] ping.php improvement: datetime.php formatting --- include/datetime.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/datetime.php b/include/datetime.php index 626e0b92c..16b134e90 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -325,7 +325,7 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke * Results relative to current timezone. * Limited to range of timestamps. * - * @param string $posted_date + * @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS) * @param string $format (optional) Parsed with sprintf() * %1$d %2$s ago, e.g. 22 hours ago, 1 minute ago * @@ -361,11 +361,11 @@ function relative_date($posted_date, $format = null) { if ($d >= 1) { $r = round($d); // translators - e.g. 22 hours ago, 1 minute ago - if(! $format) { + if (!$format) { $format = t('%1$d %2$s ago'); } - return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1])); + return sprintf($format, $r, (($r == 1) ? $str[0] : $str[1])); } } } From 97c2e99d46efe9f2ff447acebe5d3e7239447d6c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 1 Nov 2016 17:05:23 -0400 Subject: [PATCH 12/12] ping.php improvement: improving get_baseurl - Adding more documentation - Trying hard to make @annando happy --- boot.php | 69 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/boot.php b/boot.php index 8dd43101c..eb91b26ba 100644 --- a/boot.php +++ b/boot.php @@ -788,10 +788,18 @@ class App { /** * @brief Retrieves the Friendica instance base URL * - * Caches both SSL and non-SSL version for performance + * This function assembles the base URL from multiple parts: + * - Protocol is determined either by the request or a combination of + * system.ssl_policy and the $ssl parameter. + * - Host name is determined either by system.hostname or inferred from request + * - Path is inferred from SCRIPT_NAME * - * @param bool $ssl - * @return string + * Caches the result (depending on $ssl value) for performance. + * + * Note: $ssl parameter value doesn't directly correlate with the resulting protocol + * + * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN + * @return string Friendica server base URL */ function get_baseurl($ssl = false) { @@ -800,34 +808,39 @@ class App { return self::$a->get_baseurl($ssl); } + // Arbitrary values, the resulting url protocol can be different $cache_index = $ssl ? 'https' : 'http'; - if (!isset($this->baseurl[$cache_index])) { - $scheme = $this->scheme; - - if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { - if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) { - $scheme = 'https'; - } - - // Basically, we have $ssl = true on any links which can only be seen by a logged in user - // (and also the login link). Anything seen by an outsider will have it turned off. - - if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if ($ssl) { - $scheme = 'https'; - } else { - $scheme = 'http'; - } - } - } - - if (get_config('config', 'hostname') != '') { - $this->hostname = get_config('config', 'hostname'); - } - - $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); + // Cached value found, nothing to process + if (isset($this->baseurl[$cache_index])) { + return $this->baseurl[$cache_index]; } + + $scheme = $this->scheme; + + if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { + if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) { + $scheme = 'https'; + } + + // Basically, we have $ssl = true on any links which can only be seen by a logged in user + // (and also the login link). Anything seen by an outsider will have it turned off. + + if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { + if ($ssl) { + $scheme = 'https'; + } else { + $scheme = 'http'; + } + } + } + + if (get_config('config', 'hostname') != '') { + $this->hostname = get_config('config', 'hostname'); + } + + $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); + return $this->baseurl[$cache_index]; }