From f6092ebebb8d84fbaed57e8fd500328d7022c0f3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 20:48:29 -0500 Subject: [PATCH 1/5] Add App->mobileDetect property --- src/App.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/App.php b/src/App.php index 1045c413dc..ac513b531a 100644 --- a/src/App.php +++ b/src/App.php @@ -101,6 +101,11 @@ class App */ private $isAjax; + /** + * @var MobileDetect + */ + public $mobileDetect; + /** * Register a stylesheet file path to be included in the tag of every page. * Inclusion is done in App->initHead(). @@ -268,6 +273,9 @@ class App // Detect mobile devices $mobile_detect = new MobileDetect(); + + $this->mobileDetect = $mobile_detect; + $this->is_mobile = $mobile_detect->isMobile(); $this->is_tablet = $mobile_detect->isTablet(); From 6d1bc974a0a94e56304348c38d7949dc6ef71cdc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 20:49:16 -0500 Subject: [PATCH 2/5] Add time parameter for iOS Safari to stylesheet URL --- src/Core/Theme.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 91511b4d5f..6696917490 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -6,6 +6,7 @@ namespace Friendica\Core; +use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\System; @@ -191,11 +192,22 @@ class Theme */ public static function getStylesheetPath($theme) { - $a = get_app(); + $a = BaseObject::getApp(); + + $query_params = []; + + // Workaround for iOS Safari not initially sending the cookie for static files + if ($a->mobileDetect->isIos() && $a->mobileDetect->isSafari()) { + $query_params['t'] = time(); + } + + if ($a->profile_uid) { + $query_params['puid'] = $a->profile_uid; + } + - $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : ''); if (file_exists('view/theme/' . $theme . '/style.php')) { - return 'view/theme/' . $theme . '/style.pcss' . $opts; + return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); } return 'view/theme/' . $theme . '/style.css'; From 1bdb3c916a8809225fca39630e0b7c39dee424e8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 12 Jan 2019 02:21:12 -0500 Subject: [PATCH 3/5] Make style.php require query parameter puid for specific stylesheets --- view/theme/duepuntozero/style.php | 2 +- view/theme/frio/style.php | 2 +- view/theme/quattro/style.php | 2 +- view/theme/vier/style.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/view/theme/duepuntozero/style.php b/view/theme/duepuntozero/style.php index 6d102350cc..a5810f2dc1 100644 --- a/view/theme/duepuntozero/style.php +++ b/view/theme/duepuntozero/style.php @@ -10,7 +10,7 @@ if (file_exists("$THEMEPATH/style.css")) { echo file_get_contents("$THEMEPATH/style.css"); } -$uid = Profile::getThemeUid(); +$uid = defaults($_REQUEST, 'puid', 0); $s_colorset = Config::get('duepuntozero', 'colorset'); $colorset = PConfig::get($uid, 'duepuntozero', 'colorset'); diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index 7570ae0e57..d8bffa9c64 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -14,7 +14,7 @@ $scheme_modified = 0; if ($a->module !== 'install') { // Get the UID of the profile owner. - $uid = Profile::getThemeUid(); + $uid = defaults($_REQUEST, 'puid', 0); if ($uid) { PConfig::load($uid, 'frio'); diff --git a/view/theme/quattro/style.php b/view/theme/quattro/style.php index 8158468327..08756ec4aa 100644 --- a/view/theme/quattro/style.php +++ b/view/theme/quattro/style.php @@ -6,7 +6,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Model\Profile; -$uid = Profile::getThemeUid(); +$uid = defaults($_REQUEST, 'puid', 0); $color = false; $quattro_align = false; diff --git a/view/theme/vier/style.php b/view/theme/vier/style.php index 196d377656..4dfbe4e268 100644 --- a/view/theme/vier/style.php +++ b/view/theme/vier/style.php @@ -7,7 +7,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Model\Profile; -$uid = Profile::getThemeUid(); +$uid = defaults($_REQUEST, 'puid', 0); $style = PConfig::get($uid, 'vier', 'style'); From abf20368b051f76a751b4dfbd69a49c1172cdef1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 12 Jan 2019 02:23:01 -0500 Subject: [PATCH 4/5] Rework Profile::getThemeUid to ignore query parameter and include $a->profile_uid - Use new version in frio default.php file - Use new version in Theme::getStylesheetPath --- src/Core/Theme.php | 12 ++++-------- src/Model/Profile.php | 13 ++++++------- view/theme/frio/php/default.php | 5 +---- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 6696917490..2202780376 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -9,6 +9,7 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\Model\Profile; /** * Some functions to handle themes @@ -196,16 +197,11 @@ class Theme $query_params = []; - // Workaround for iOS Safari not initially sending the cookie for static files - if ($a->mobileDetect->isIos() && $a->mobileDetect->isSafari()) { - $query_params['t'] = time(); + $puid = Profile::getThemeUid($a); + if ($puid) { + $query_params['puid'] = $puid; } - if ($a->profile_uid) { - $query_params['puid'] = $a->profile_uid; - } - - if (file_exists('view/theme/' . $theme . '/style.php')) { return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 49fb868e3a..41e992aa49 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -1176,7 +1176,7 @@ class Profile * Get the user ID of the page owner. * * Used from within PCSS themes to set theme parameters. If there's a - * puid request variable, that is the "page owner" and normally their theme + * profile_uid variable set in App, that is the "page owner" and normally their theme * settings take precedence; unless a local user sets the "always_my_theme" * system pconfig, which means they don't want to see anybody else's theme * settings except their own while on this site. @@ -1184,13 +1184,12 @@ class Profile * @brief Get the user ID of the page owner * @return int user ID * - * @note Returns local_user instead of user ID if "always_my_theme" - * is set to true + * @note Returns local_user instead of user ID if "always_my_theme" is set to true */ - public static function getThemeUid() + public static function getThemeUid(App $a) { - $uid = (!empty($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0); - if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) { + $uid = !empty($a->profile_uid) ? intval($a->profile_uid) : 0; + if (local_user() && (PConfig::get(local_user(), 'system', 'always_my_theme') || !$uid)) { return local_user(); } @@ -1198,7 +1197,7 @@ class Profile } /** - * Stip zrl parameter from a string. + * Strip zrl parameter from a string. * * @param string $s The input string. * @return string The zrl. diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index ce7fd4d777..b9600cc22e 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -42,10 +42,7 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; // Add the theme color meta // It makes mobile Chrome UI match Frio's top bar color. - $uid = $a->profile_uid; - if (is_null($uid)) { - $uid = Profile::getThemeUid(); - } + $uid = Profile::getThemeUid($a); $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema')); if ($scheme && ($scheme != '---')) { if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) { From a9b8eb4d56fbce6750f777a9b829263a5cfb22cf Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 12 Jan 2019 02:26:16 -0500 Subject: [PATCH 5/5] Refactor Theme::getStylesheetPath to return faster if theme style.php doesn't exist --- src/Core/Theme.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 2202780376..de8cd496a4 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -193,6 +193,10 @@ class Theme */ public static function getStylesheetPath($theme) { + if (!file_exists('view/theme/' . $theme . '/style.php')) { + return 'view/theme/' . $theme . '/style.css'; + } + $a = BaseObject::getApp(); $query_params = []; @@ -202,10 +206,6 @@ class Theme $query_params['puid'] = $puid; } - if (file_exists('view/theme/' . $theme . '/style.php')) { - return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); - } - - return 'view/theme/' . $theme . '/style.css'; + return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); } }