From e5ec8ae011fb667450d6ed6f78507921f3f66ed7 Mon Sep 17 00:00:00 2001 From: Derrick Miller Date: Sat, 24 Nov 2018 22:09:15 +0000 Subject: [PATCH 1/2] Pass current page data to plugins per documentation --- app/Respond/Libraries/Publish.php | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Respond/Libraries/Publish.php b/app/Respond/Libraries/Publish.php index 1b49ea6b..7f0f3e1b 100644 --- a/app/Respond/Libraries/Publish.php +++ b/app/Respond/Libraries/Publish.php @@ -839,7 +839,7 @@ public static function publishPluginsForPage($page, $user, $site, $pages = null) $html = file_get_contents($location); - // setup current page + // setup meta info $meta = array( 'url' => $page->url, 'firstName' => $page->firstName, @@ -849,7 +849,7 @@ public static function publishPluginsForPage($page, $user, $site, $pages = null) ); // inject plugin HTML to the page - $dom = Publish::injectPluginHTML($html, $user, $site, $meta, $pages); + $dom = Publish::injectPluginHTML($html, $user, $site, $meta, $pages, $page); // put html back file_put_contents($location, $dom); @@ -870,7 +870,7 @@ public static function publishPluginsForPage($page, $user, $site, $pages = null) * @param {User} $user * @param {Site} $site */ - public static function injectPluginHTML($html, $user, $site, $meta, $pages = null) { + public static function injectPluginHTML($html, $user, $site, $meta, $pages = null, $page = null) { // caches the values of these variables across the request to improve performance static $forms = array(); @@ -924,6 +924,30 @@ public static function injectPluginHTML($html, $user, $site, $meta, $pages = nul 'timeZone' => $site->timeZone, ); + // If page data is provided + if($page) { + + // setup current page + $current_page = array( + 'title' => $page->title, + 'description' => $page->description, + 'keywords' => $page->keywords, + 'callout' => $page->callout, + 'url' => $page->url, + 'photo' => $page->photo, + 'thumb' => $page->thumb, + 'language' => $page->language, + 'direction' => $page->direction, + 'firstName' => $page->firstName, + 'lastName' => $page->lastName, + 'lastModifiedBy' => $page->lastModifiedBy, + 'lastModifiedDate' => $page->lastModifiedDate + ); + + } else { + $current_page = array(); + } + // get plugins for the site $dir = app()->basePath().'/public/sites/'.$site->id.'/plugins'; $exts = array('html', 'php'); @@ -940,7 +964,7 @@ public static function injectPluginHTML($html, $user, $site, $meta, $pages = nul if(file_exists($path)) { // $html = file_get_contents($path); - $id = basename($path); + $id = basename($path);not $id = str_replace('.html', '', $id); $id = str_replace('.php', '', $id); @@ -985,7 +1009,7 @@ public static function injectPluginHTML($html, $user, $site, $meta, $pages = nul if(array_search($el->type, $plugins) !== FALSE) { // render array - $render_arr = array('page' => $meta, + $render_arr = array('page' => $current_page, 'meta' => $meta, 'site' => $current_site, 'pages' => $pages, From 10a4b689883eb6df5d08fc49e6b6832a9f486daf Mon Sep 17 00:00:00 2001 From: Derrick Miller Date: Sat, 24 Nov 2018 22:12:23 +0000 Subject: [PATCH 2/2] Remove typo introduced by code editor --- app/Respond/Libraries/Publish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Respond/Libraries/Publish.php b/app/Respond/Libraries/Publish.php index 7f0f3e1b..58c69ea4 100644 --- a/app/Respond/Libraries/Publish.php +++ b/app/Respond/Libraries/Publish.php @@ -964,7 +964,7 @@ public static function injectPluginHTML($html, $user, $site, $meta, $pages = nul if(file_exists($path)) { // $html = file_get_contents($path); - $id = basename($path);not + $id = basename($path); $id = str_replace('.html', '', $id); $id = str_replace('.php', '', $id);