From 7dd6fb3b3c65ffee02e37419b2feed044d52e5aa Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 19 Sep 2018 22:51:51 -0400 Subject: [PATCH 01/12] Rewrite JS hooks - Use event listeners instead of homebrew hooks - Remove view/js/addon-hooks.js and its references - Update Addon docs --- doc/Addons.md | 16 +++--------- view/js/addon-hooks.js | 41 ------------------------------ view/js/main.js | 8 +++--- view/templates/head.tpl | 1 - view/theme/frio/templates/head.tpl | 1 - 5 files changed, 8 insertions(+), 59 deletions(-) delete mode 100644 view/js/addon-hooks.js diff --git a/doc/Addons.md b/doc/Addons.md index 2465db730..ec413c6ac 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -103,19 +103,11 @@ function _template_vars($a, &$arr) Register your addon hooks in file `addon/*addon_name*/*addon_name*.js`. ```js -Addon_registerHook(type, hookfnstr); +document.addEventListener(name, callback); ``` -*type* is the name of the hook and corresponds to a known Friendica JavaScript hook. -*hookfnstr* is the name of your JavaScript function to execute. - -No arguments are provided to your JavaScript callback function. Example: - -```javascript -function myhook_function() { - -} -``` +*name* is the name of the hook and corresponds to a known Friendica JavaScript hook. +*callback* is a JavaScript function to execute. ## Modules @@ -704,4 +696,4 @@ Here is a complete list of all hook callbacks with file locations (as of 01-Apr- ### view/js/main.js - callAddonHooks("postprocess_liveupdate"); + document.dispatchEvent(new Event('postprocess_liveupdate')); diff --git a/view/js/addon-hooks.js b/view/js/addon-hooks.js deleted file mode 100644 index 3e1cb4849..000000000 --- a/view/js/addon-hooks.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file addon-hooks.js - * @brief Provide a way for add-ons to register a JavaScript hook - */ - -var addon_hooks = {}; - -/** - * @brief Register a JavaScript hook to be called from other Javascript files - * @pre the .js file from which the hook will be called is included in the document response - * @param type which type of hook i.e. where should it be called along with other hooks of the same type - * @param hookfnstr name of the JavaScript function name that needs to be called - */ -function Addon_registerHook(type, hookfnstr) -{ - if (!addon_hooks.hasOwnProperty(type)) { - addon_hooks[type] = []; - } - - addon_hooks[type].push(hookfnstr); -} - -/** - * @brief Call all registered hooks of a certain type, i.e. at the same point of the JavaScript code execution - * @param typeOfHook string indicating which type of hooks to be called among the registered hooks - */ -function callAddonHooks(typeOfHook) -{ - if (typeof addon_hooks !== 'undefined') { - var myTypeOfHooks = addon_hooks[typeOfHook]; - if (typeof myTypeOfHooks !== 'undefined') { - for (addon_hook_idx = 0; addon_hook_idx < myTypeOfHooks.length; addon_hook_idx++) { - var hookfnstr = myTypeOfHooks[addon_hook_idx]; - var hookfn = window[hookfnstr]; - if (typeof hookfn === "function") { - hookfn(); - } - } - } - } -} diff --git a/view/js/main.js b/view/js/main.js index 4788d90a8..ae9cb23d8 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -478,14 +478,12 @@ function liveUpdate(src) { $('.wall-item-body', data).imagesLoaded(function() { updateConvItems(data); + document.dispatchEvent(new Event('postprocess_liveupdate')); + // Update the scroll position. $(window).scrollTop($(window).scrollTop() + $("section").height() - orgHeight); }); - - callAddonHooks("postprocess_liveupdate"); - }); - } function imgbright(node) { @@ -735,6 +733,8 @@ function loadScrollContent() { } else { $("#scroll-end").fadeIn('normal'); } + + document.dispatchEvent(new Event('postprocess_liveupdate')); }); } diff --git a/view/templates/head.tpl b/view/templates/head.tpl index aadbfcd8e..eef985bc6 100644 --- a/view/templates/head.tpl +++ b/view/templates/head.tpl @@ -45,7 +45,6 @@ - {{if is_array($addon_hooks)}} {{foreach $addon_hooks as $addon_hook}} diff --git a/view/theme/frio/templates/head.tpl b/view/theme/frio/templates/head.tpl index 7d6cadea9..0cc5bf4af 100644 --- a/view/theme/frio/templates/head.tpl +++ b/view/theme/frio/templates/head.tpl @@ -69,7 +69,6 @@ - {{if is_array($addon_hooks)}} {{foreach $addon_hooks as $addon_hook}} From 55f1d7b90e180b4609a4473399ea1b23912dfcfa Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:01:05 -0400 Subject: [PATCH 02/12] Add new footer hook - Add new App->footerScripts array - Add footer.tpl template - Add documentation - Rework App->init_page_end to App->initFooter --- doc/Addons.md | 6 +++++ index.php | 38 +--------------------------- src/App.php | 53 +++++++++++++++++++++++++++++++++------ view/templates/footer.tpl | 3 +++ 4 files changed, 56 insertions(+), 44 deletions(-) create mode 100644 view/templates/footer.tpl diff --git a/doc/Addons.md b/doc/Addons.md index ec413c6ac..b126fedc4 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -286,6 +286,11 @@ No hook data. Called after HTML content functions have completed. `$b` is (string) HTML of content div. +### footer +Called after HTML content functions have completed. +`$b` is (string) HTML of footer div/element. +Used to load deferred Javascript files. + ### avatar_lookup Called when looking up the avatar. `$b` is an array: @@ -563,6 +568,7 @@ Here is a complete list of all hook callbacks with file locations (as of 01-Apr- ### src/App.php Addon::callHooks('load_config'); + Addon::callHooks('footer'); ### src/Model/Item.php diff --git a/index.php b/index.php index 8b0bd4725..aa7704930 100644 --- a/index.php +++ b/index.php @@ -153,10 +153,6 @@ if (! x($_SESSION, 'authenticated')) { header('X-Account-Management-Status: none'); } -/* set up page['htmlhead'] and page['end'] for the modules to use */ -$a->page['htmlhead'] = ''; -$a->page['end'] = ''; - $_SESSION['sysmsg'] = defaults($_SESSION, 'sysmsg' , []); $_SESSION['sysmsg_info'] = defaults($_SESSION, 'sysmsg_info' , []); $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []); @@ -326,10 +322,6 @@ if (file_exists($theme_info_file)) { /* initialise content region */ -if (! x($a->page, 'content')) { - $a->page['content'] = ''; -} - if ($a->mode == App::MODE_NORMAL) { Addon::callHooks('page_content_top', $a->page['content']); } @@ -411,18 +403,7 @@ $a->init_pagehead(); * Build the page ending -- this is stuff that goes right before * the closing tag */ -$a->init_page_end(); - -// If you're just visiting, let javascript take you home -if (x($_SESSION, 'visitor_home')) { - $homebase = $_SESSION['visitor_home']; -} elseif (local_user()) { - $homebase = 'profile/' . $a->user['nickname']; -} - -if (isset($homebase)) { - $a->page['content'] .= ''; -} +$a->initFooter(); /* * now that we've been through the module content, see if the page reported @@ -444,23 +425,6 @@ if ($a->module != 'install' && $a->module != 'maintenance') { Nav::build($a); } -/* - * Add a "toggle mobile" link if we're using a mobile device - */ -if ($a->is_mobile || $a->is_tablet) { - if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { - $link = 'toggle_mobile?address=' . curPageURL(); - } else { - $link = 'toggle_mobile?off=1&address=' . curPageURL(); - } - $a->page['footer'] = replace_macros( - get_markup_template("toggle_mobile_footer.tpl"), - [ - '$toggle_link' => $link, - '$toggle_text' => L10n::t('toggle mobile')] - ); -} - /** * Build the page - now that we have all the components */ diff --git a/src/App.php b/src/App.php index 2a5fba854..1a26dd650 100644 --- a/src/App.php +++ b/src/App.php @@ -96,6 +96,15 @@ class App public $force_max_items = 0; public $theme_events_in_profile = true; + public $footerScripts = []; + + public function registerFooterScript($path) + { + $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path); + + $this->footerScripts[] = $this->get_baseurl() . '/' . trim($url, '/'); + } + /** * @brief An array for all theme-controllable parameters * @@ -802,15 +811,45 @@ class App ]) . $this->page['htmlhead']; } - public function init_page_end() + public function initFooter() { - if (!isset($this->page['end'])) { - $this->page['end'] = ''; + if (!isset($this->page['footer'])) { + $this->page['footer'] = ''; } - $tpl = get_markup_template('end.tpl'); - $this->page['end'] = replace_macros($tpl, [ - '$baseurl' => $this->get_baseurl() - ]) . $this->page['end']; + + // If you're just visiting, let javascript take you home + if (!empty($_SESSION['visitor_home'])) { + $homebase = $_SESSION['visitor_home']; + } elseif (local_user()) { + $homebase = 'profile/' . $a->user['nickname']; + } + + if (isset($homebase)) { + $this->page['footer'] .= '' . "\n"; + } + + /* + * Add a "toggle mobile" link if we're using a mobile device + */ + if ($this->is_mobile || $this->is_tablet) { + if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { + $link = 'toggle_mobile?address=' . curPageURL(); + } else { + $link = 'toggle_mobile?off=1&address=' . curPageURL(); + } + $this->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), [ + '$toggle_link' => $link, + '$toggle_text' => Core\L10n::t('toggle mobile') + ]); + } + + Core\Addon::callHooks('footer', $this->page['footer']); + + $tpl = get_markup_template('footer.tpl'); + $this->page['footer'] .= replace_macros($tpl, [ + '$baseurl' => $this->get_baseurl(), + '$footerScripts' => $this->footerScripts, + ]); } public function set_curl_code($code) diff --git a/view/templates/footer.tpl b/view/templates/footer.tpl new file mode 100644 index 000000000..1b9d70002 --- /dev/null +++ b/view/templates/footer.tpl @@ -0,0 +1,3 @@ +{{foreach $footerScripts as $scriptUrl}} + +{{/foreach}} From 1eaa523e611abb7ba0217da77a70837ea9547812 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:02:28 -0400 Subject: [PATCH 03/12] Remove unused App->page['end'] - Remove unused empty templates --- include/conversation.php | 15 --------------- include/text.php | 3 --- mod/cal.php | 5 ----- mod/contacts.php | 9 --------- mod/editpost.php | 9 --------- mod/events.php | 5 ----- mod/message.php | 20 -------------------- mod/profile_photo.php | 1 - mod/profiles.php | 3 --- mod/settings.php | 5 ----- mod/videos.php | 6 ------ mod/wallmessage.php | 7 ------- src/App.php | 1 - view/templates/contact_end.tpl | 1 - view/templates/contacts-end.tpl | 1 - view/templates/cropend.tpl | 1 - view/templates/end.tpl | 1 - view/templates/event_end.tpl | 1 - view/templates/jot-end.tpl | 1 - view/templates/message-end.tpl | 1 - view/templates/msg-end.tpl | 1 - view/templates/profed_end.tpl | 1 - view/templates/videos_end.tpl | 0 view/templates/wallmsg-end.tpl | 1 - 24 files changed, 99 deletions(-) delete mode 100644 view/templates/contact_end.tpl delete mode 100644 view/templates/contacts-end.tpl delete mode 100644 view/templates/cropend.tpl delete mode 100644 view/templates/end.tpl delete mode 100644 view/templates/event_end.tpl delete mode 100644 view/templates/jot-end.tpl delete mode 100644 view/templates/message-end.tpl delete mode 100644 view/templates/msg-end.tpl delete mode 100644 view/templates/profed_end.tpl delete mode 100644 view/templates/videos_end.tpl delete mode 100644 view/templates/wallmsg-end.tpl diff --git a/include/conversation.php b/include/conversation.php index ca01997f6..d791fa414 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1091,21 +1091,6 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) '$delitems' => L10n::t("Delete item\x28s\x29?") ]); - $tpl = get_markup_template('jot-end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$newpost' => 'true', - '$baseurl' => System::baseUrl(true), - '$geotag' => $geotag, - '$nickname' => $x['nickname'], - '$ispublic' => L10n::t('Visible to everybody'), - '$linkurl' => L10n::t('Please enter a link URL:'), - '$vidurl' => L10n::t("Please enter a video link/URL:"), - '$audurl' => L10n::t("Please enter an audio link/URL:"), - '$term' => L10n::t('Tag term:'), - '$fileas' => L10n::t('Save to Folder:'), - '$whereareu' => L10n::t('Where are you right now?') - ]); - $jotplugins = ''; Addon::callHooks('jot_tool', $jotplugins); diff --git a/include/text.php b/include/text.php index d251824e2..53b806122 100644 --- a/include/text.php +++ b/include/text.php @@ -1191,9 +1191,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [ '$baseurl' => System::baseUrl(), ]); - $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [ - '$baseurl' => System::baseUrl(), - ]); } $url_parts = explode('/', $the_url); diff --git a/mod/cal.php b/mod/cal.php index bdedaaacf..ae1060c47 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -94,11 +94,6 @@ function cal_content(App $a) '$i18n' => $i18n, ]); - $etpl = get_markup_template('event_end.tpl'); - $a->page['end'] .= replace_macros($etpl, [ - '$baseurl' => System::baseUrl(), - ]); - $mode = 'view'; $y = 0; $m = 0; diff --git a/mod/contacts.php b/mod/contacts.php index 4e8769717..86d7e2ac6 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -112,12 +112,6 @@ function contacts_init(App $a) '$baseurl' => System::baseUrl(true), '$base' => $base ]); - - $tpl = get_markup_template("contacts-end.tpl"); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(true), - '$base' => $base - ]); } function contacts_batch_actions(App $a) @@ -503,9 +497,6 @@ function contacts_content(App $a, $update = 0) $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [ '$baseurl' => System::baseUrl(true), ]); - $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), [ - '$baseurl' => System::baseUrl(true), - ]); $contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user()); $contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user()); diff --git a/mod/editpost.php b/mod/editpost.php index 258585ef1..b8ccff470 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -51,15 +51,6 @@ function editpost_content(App $a) '$nickname' => $a->user['nickname'] ]); - $tpl = get_markup_template('jot-end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(), - '$ispublic' => ' ', // L10n::t('Visible to everybody'), - '$geotag' => $geotag, - '$nickname' => $a->user['nickname'] - ]); - - $tpl = get_markup_template("jot.tpl"); if (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { diff --git a/mod/events.php b/mod/events.php index 91474022f..fd658a9ce 100644 --- a/mod/events.php +++ b/mod/events.php @@ -229,11 +229,6 @@ function events_content(App $a) { '$i18n' => $i18n, ]); - $etpl = get_markup_template('event_end.tpl'); - $a->page['end'] .= replace_macros($etpl, [ - '$baseurl' => System::baseUrl(), - ]); - $o = ''; $tabs = ''; // tabs diff --git a/mod/message.php b/mod/message.php index 8c9aa657d..23d528a8a 100644 --- a/mod/message.php +++ b/mod/message.php @@ -46,12 +46,6 @@ function message_init(App $a) '$baseurl' => System::baseUrl(true), '$base' => $base ]); - - $end_tpl = get_markup_template('message-end.tpl'); - $a->page['end'] .= replace_macros($end_tpl, [ - '$baseurl' => System::baseUrl(true), - '$base' => $base - ]); } function message_post(App $a) @@ -199,13 +193,6 @@ function message_content(App $a) '$linkurl' => L10n::t('Please enter a link URL:') ]); - $tpl = get_markup_template('msg-end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(true), - '$nickname' => $a->user['nickname'], - '$linkurl' => L10n::t('Please enter a link URL:') - ]); - $preselect = isset($a->argv[2]) ? [$a->argv[2]] : []; $prename = $preurl = $preid = ''; @@ -344,13 +331,6 @@ function message_content(App $a) '$linkurl' => L10n::t('Please enter a link URL:') ]); - $tpl = get_markup_template('msg-end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(true), - '$nickname' => $a->user['nickname'], - '$linkurl' => L10n::t('Please enter a link URL:') - ]); - $mails = []; $seen = 0; $unknown = false; diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 567a7f3a2..984ebfed6 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -317,7 +317,6 @@ function profile_photo_crop_ui_head(App $a, Image $image) } $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), []); - $a->page['end'] .= replace_macros(get_markup_template("cropend.tpl"), []); $imagecrop = [ 'hash' => $hash, diff --git a/mod/profiles.php b/mod/profiles.php index d951a470d..76491c553 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -527,9 +527,6 @@ function profiles_content(App $a) { $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), [ '$baseurl' => System::baseUrl(true), ]); - $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), [ - '$baseurl' => System::baseUrl(true), - ]); $opt_tpl = get_markup_template("profile-hide-friends.tpl"); $hide_friends = replace_macros($opt_tpl,[ diff --git a/mod/settings.php b/mod/settings.php index 84bc230e3..78fa446ce 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -982,11 +982,6 @@ function settings_content(App $a) '$theme_config' => $theme_config, ]); - $tpl = get_markup_template('settings/display_end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$theme' => ['theme', L10n::t('Display Theme:'), $theme_selected, '', $themes] - ]); - return $o; } diff --git a/mod/videos.php b/mod/videos.php index e622e17f0..4bd0ab4f3 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -105,12 +105,6 @@ function videos_init(App $a) $a->page['htmlhead'] .= replace_macros($tpl,[ '$baseurl' => System::baseUrl(), ]); - - $tpl = get_markup_template("videos_end.tpl"); - $a->page['end'] .= replace_macros($tpl,[ - '$baseurl' => System::baseUrl(), - ]); - } return; diff --git a/mod/wallmessage.php b/mod/wallmessage.php index 5606b6fee..5e08420ec 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -120,13 +120,6 @@ function wallmessage_content(App $a) { '$linkurl' => L10n::t('Please enter a link URL:') ]); - $tpl = get_markup_template('wallmsg-end.tpl'); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(true), - '$nickname' => $user['nickname'], - '$linkurl' => L10n::t('Please enter a link URL:') - ]); - $tpl = get_markup_template('wallmessage.tpl'); $o = replace_macros($tpl, [ '$header' => L10n::t('Send Private Message'), diff --git a/src/App.php b/src/App.php index 1a26dd650..26bc7362f 100644 --- a/src/App.php +++ b/src/App.php @@ -318,7 +318,6 @@ class App 'aside' => '', 'bottom' => '', 'content' => '', - 'end' => '', 'footer' => '', 'htmlhead' => '', 'nav' => '', diff --git a/view/templates/contact_end.tpl b/view/templates/contact_end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/contact_end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/contacts-end.tpl b/view/templates/contacts-end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/contacts-end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/cropend.tpl b/view/templates/cropend.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/cropend.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/end.tpl b/view/templates/end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/event_end.tpl b/view/templates/event_end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/event_end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/jot-end.tpl b/view/templates/jot-end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/jot-end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/message-end.tpl b/view/templates/message-end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/message-end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/msg-end.tpl b/view/templates/msg-end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/msg-end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/profed_end.tpl b/view/templates/profed_end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/profed_end.tpl +++ /dev/null @@ -1 +0,0 @@ - diff --git a/view/templates/videos_end.tpl b/view/templates/videos_end.tpl deleted file mode 100644 index e69de29bb..000000000 diff --git a/view/templates/wallmsg-end.tpl b/view/templates/wallmsg-end.tpl deleted file mode 100644 index 8b1378917..000000000 --- a/view/templates/wallmsg-end.tpl +++ /dev/null @@ -1 +0,0 @@ - From 73c1ebc6fd522be5ae712c058a02e105592c0f95 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:02:55 -0400 Subject: [PATCH 04/12] [frio] Move relevant code to new footer.tpl --- view/theme/frio/php/default.php | 22 +--------------------- view/theme/frio/templates/footer.tpl | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 view/theme/frio/templates/footer.tpl diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index cb6832853..d9ecb7cf0 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -138,27 +138,7 @@ if (!isset($minimal)) {
- - - - - -
- +
diff --git a/view/theme/frio/templates/footer.tpl b/view/theme/frio/templates/footer.tpl new file mode 100644 index 000000000..4d58ff888 --- /dev/null +++ b/view/theme/frio/templates/footer.tpl @@ -0,0 +1,23 @@ + + + + +
+ +{{foreach $footerScripts as $scriptUrl}} + +{{/foreach}} From cc73aec3baf16ed54b2a8465f16ceb968e2375d1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:03:23 -0400 Subject: [PATCH 05/12] Add postprocess_liveupdate JS event dispatch on post preview --- view/js/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/view/js/main.js b/view/js/main.js index ae9cb23d8..b41750b6a 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -667,6 +667,7 @@ function preview_post() { if (data.preview) { $("#jot-preview-content").html(data.preview); $("#jot-preview-content" + " a").click(function() {return false;}); + document.dispatchEvent(new Event('postprocess_liveupdate')); } }, "json" From 30f8fb82b632f1685b3508fe089c17e2d21bfb9b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:05:23 -0400 Subject: [PATCH 06/12] Cleanup index.php - Removed deprecated killme() calls - Removed deprecated x() calls --- index.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index aa7704930..1adfe4ad1 100644 --- a/index.php +++ b/index.php @@ -91,7 +91,7 @@ if (!$a->is_backend()) { * Language was set earlier, but we can over-ride it in the session. * We have to do it here because the session was just now opened. */ -if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) { +if (!empty($_SESSION['authenticated']) && empty($_SESSION['language'])) { $_SESSION['language'] = $lang; // we haven't loaded user data yet, but we need user language if (!empty($_SESSION['uid'])) { @@ -102,7 +102,7 @@ if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) { } } -if (x($_SESSION, 'language') && ($_SESSION['language'] !== $lang)) { +if (!empty($_SESSION['language']) && $_SESSION['language'] !== $lang) { $lang = $_SESSION['language']; L10n::loadTranslationTable($lang); } @@ -125,12 +125,12 @@ if (!empty($_GET['zrl']) && $a->mode == App::MODE_NORMAL) { logger("Invalid ZRL parameter " . $_GET['zrl'], LOGGER_DEBUG); header('HTTP/1.1 403 Forbidden'); echo "

403 Forbidden

"; - killme(); + exit(); } } } -if ((x($_GET,'owt')) && $a->mode == App::MODE_NORMAL) { +if (!empty($_GET['owt']) && $a->mode == App::MODE_NORMAL) { $token = $_GET['owt']; $a->query_string = Profile::stripQueryParam($a->query_string, 'owt'); Profile::openWebAuthInit($token); @@ -149,7 +149,7 @@ if ((x($_GET,'owt')) && $a->mode == App::MODE_NORMAL) { Login::sessionAuth(); -if (! x($_SESSION, 'authenticated')) { +if (empty($_SESSION['authenticated'])) { header('X-Account-Management-Status: none'); } @@ -291,11 +291,11 @@ if (strlen($a->module)) { if (! $a->module_loaded) { // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. - if ((x($_SERVER, 'QUERY_STRING')) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) { + if (!empty($_SERVER['QUERY_STRING']) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) { killme(); } - if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { + if (!empty($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']); goaway(System::baseUrl() . $_SERVER['REQUEST_URI']); } @@ -303,11 +303,9 @@ if (strlen($a->module)) { logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found')); $tpl = get_markup_template("404.tpl"); - $a->page['content'] = replace_macros( - $tpl, - [ - '$message' => L10n::t('Page not found.')] - ); + $a->page['content'] = replace_macros($tpl, [ + '$message' => L10n::t('Page not found.') + ]); } } @@ -466,7 +464,7 @@ if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) { echo substr($target->saveHTML(), 6, -8); - killme(); + exit(); } $page = $a->page; @@ -504,5 +502,3 @@ if (empty($template)) { /// @TODO Looks unsafe (remote-inclusion), is maybe not but Theme::getPathForFile() uses file_exists() but does not escape anything require_once $template; - -killme(); From 2ae6556b3293f20647edeea36b793fda8f65691f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:30:51 -0400 Subject: [PATCH 07/12] Add new 'head' hook - Add new App->registerStylesheet method - Reworked App->init_pagehead into App->initHead --- doc/Addons.md | 8 +++++++- index.php | 2 +- src/App.php | 26 +++++++++++++++++--------- view/templates/head.tpl | 4 ++++ view/theme/frio/templates/head.tpl | 4 ++++ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/doc/Addons.md b/doc/Addons.md index b126fedc4..b8364d935 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -252,6 +252,11 @@ Called after conversion of bbcode to HTML. Called after tag conversion of HTML to bbcode (e.g. remote message posting) `$b` is a string converted text +### head +Called when building the `` sections. +Stylesheets should be registered using this hook. +`$b` is an HTML string of the `` tag. + ### page_header Called after building the page navigation section. `$b` is a string HTML of nav region. @@ -288,8 +293,8 @@ Called after HTML content functions have completed. ### footer Called after HTML content functions have completed. +Deferred Javascript files should be registered using this hook. `$b` is (string) HTML of footer div/element. -Used to load deferred Javascript files. ### avatar_lookup Called when looking up the avatar. `$b` is an array: @@ -568,6 +573,7 @@ Here is a complete list of all hook callbacks with file locations (as of 01-Apr- ### src/App.php Addon::callHooks('load_config'); + Addon::callHooks('head'); Addon::callHooks('footer'); ### src/Model/Item.php diff --git a/index.php b/index.php index 1adfe4ad1..359be7dcb 100644 --- a/index.php +++ b/index.php @@ -395,7 +395,7 @@ if ($a->module_loaded) { * theme choices made by the modules can take effect. */ -$a->init_pagehead(); +$a->initHead(); /* * Build the page ending -- this is stuff that goes right before diff --git a/src/App.php b/src/App.php index 26bc7362f..479813703 100644 --- a/src/App.php +++ b/src/App.php @@ -96,13 +96,21 @@ class App public $force_max_items = 0; public $theme_events_in_profile = true; + public $stylesheets = []; public $footerScripts = []; + public function registerStylesheet($path) + { + $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path); + + $this->stylesheets[] = trim($url, '/'); + } + public function registerFooterScript($path) { $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path); - $this->footerScripts[] = $this->get_baseurl() . '/' . trim($url, '/'); + $this->footerScripts[] = trim($url, '/'); } /** @@ -741,7 +749,7 @@ class App $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; } - public function init_pagehead() + public function initHead() { $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000); @@ -766,9 +774,6 @@ class App * since the code added by the modules frequently depends on it * being first */ - if (!isset($this->page['htmlhead'])) { - $this->page['htmlhead'] = ''; - } // If we're using Smarty, then doing replace_macros() will replace // any unrecognized variables with a blank string. Since we delay @@ -791,7 +796,9 @@ class App } // get data wich is needed for infinite scroll on the network page - $invinite_scroll = infinite_scroll_data($this->module); + $infinite_scroll = infinite_scroll_data($this->module); + + Core\Addon::callHooks('head', $this->page['htmlhead']); $tpl = get_markup_template('head.tpl'); $this->page['htmlhead'] = replace_macros($tpl, [ @@ -805,8 +812,9 @@ class App '$shortcut_icon' => $shortcut_icon, '$touch_icon' => $touch_icon, '$stylesheet' => $stylesheet, - '$infinite_scroll' => $invinite_scroll, + '$infinite_scroll' => $infinite_scroll, '$block_public' => intval(Config::get('system', 'block_public')), + '$stylesheets' => $this->stylesheets, ]) . $this->page['htmlhead']; } @@ -845,10 +853,10 @@ class App Core\Addon::callHooks('footer', $this->page['footer']); $tpl = get_markup_template('footer.tpl'); - $this->page['footer'] .= replace_macros($tpl, [ + $this->page['footer'] = replace_macros($tpl, [ '$baseurl' => $this->get_baseurl(), '$footerScripts' => $this->footerScripts, - ]); + ]) . $this->page['footer']; } public function set_curl_code($code) diff --git a/view/templates/head.tpl b/view/templates/head.tpl index eef985bc6..46b7283ac 100644 --- a/view/templates/head.tpl +++ b/view/templates/head.tpl @@ -11,6 +11,10 @@ +{{foreach $stylesheets as $stylesheetUrl}} + +{{/foreach}} + diff --git a/view/theme/frio/templates/head.tpl b/view/theme/frio/templates/head.tpl index 109127cce..e7c3a4de8 100644 --- a/view/theme/frio/templates/head.tpl +++ b/view/theme/frio/templates/head.tpl @@ -26,21 +26,14 @@ -{{* The own style.css *}} - +{{foreach $stylesheets as $stylesheetUrl}} + +{{/foreach}} {{* own css files *}} -{{foreach $stylesheets as $stylesheetUrl}} - -{{/foreach}} - - From 489d5f41d26f6cecdfcb2b9fbffedd715351b07b Mon Sep 17 00:00:00 2001 From: Benjamin Lorteau Date: Fri, 21 Sep 2018 09:54:40 -0400 Subject: [PATCH 09/12] Add Doxygen headers for multiple function in App --- src/App.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/App.php b/src/App.php index 3f67dbada..c00f898f3 100644 --- a/src/App.php +++ b/src/App.php @@ -99,6 +99,15 @@ class App public $stylesheets = []; public $footerScripts = []; + /** + * Register a stylesheet file path to be included in the tag of every page. + * Inclusion is done in App->initHead(). + * The path can be absolute or relative to the Friendica installation base folder. + * + * @see App->initHead() + * + * @param string $path + */ public function registerStylesheet($path) { $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path); @@ -106,6 +115,15 @@ class App $this->stylesheets[] = trim($url, '/'); } + /** + * Register a javascript file path to be included in the