From 8072f89dfd12b089e87604b27d3b65ea319e33a0 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 7 Jul 2020 14:59:37 -0700 Subject: [PATCH] setup/ - Fix CSS loading on "finished" page. Split out "page.php". The various `finished.*.php` files were outtputting the incorrect URL for `template.css`. The code for outputting `template.css` is duplicated in a few files. This commit fixes by extracting a helper (`renderPage()` / `page.php`) to encapsulate that bit and reuse it for each page-view in the Setup UI. --- setup/res/error.html | 17 -------- setup/res/finished.Backdrop.php | 12 ------ setup/res/finished.Drupal.php | 13 +----- setup/res/installer.tpl.php | 21 +++++++++ setup/res/page.tpl.php | 31 ++++++++++++++ setup/res/template.php | 41 ------------------ setup/src/Setup/UI/SetupController.php | 59 ++++++++++++++++++++------ 7 files changed, 98 insertions(+), 96 deletions(-) delete mode 100644 setup/res/error.html create mode 100644 setup/res/installer.tpl.php create mode 100644 setup/res/page.tpl.php delete mode 100644 setup/res/template.php diff --git a/setup/res/error.html b/setup/res/error.html deleted file mode 100644 index 9bfe8e56de..0000000000 --- a/setup/res/error.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - <?php echo $errorTitle ?> - - /> - - - -
-

- - - -
- - diff --git a/setup/res/finished.Backdrop.php b/setup/res/finished.Backdrop.php index 473cd45573..68ed482e91 100644 --- a/setup/res/finished.Backdrop.php +++ b/setup/res/finished.Backdrop.php @@ -4,17 +4,7 @@ $backdropPermissionsURL = url('admin/config/people/permissions'); $backdropURL = url('civicrm/admin/configtask', [ 'query' => ['reset' => 1], ]); -$registerSiteURL = "https://civicrm.org/register-site"; - ?> - - - - <?php echo ts('CiviCRM Installed'); ?> - - - -

@@ -27,5 +17,3 @@ $registerSiteURL = "https://civicrm.org/register-site";
- - diff --git a/setup/res/finished.Drupal.php b/setup/res/finished.Drupal.php index c7ae2bfafe..2b64ec6bd2 100644 --- a/setup/res/finished.Drupal.php +++ b/setup/res/finished.Drupal.php @@ -1,21 +1,12 @@ array( 'reset' => 1, ), )); -?> - - - <?php echo ts('CiviCRM Installed'); ?> - - - - +?>

@@ -28,5 +19,3 @@ $drupalURL = url('civicrm/admin/configtask', array(
- - diff --git a/setup/res/installer.tpl.php b/setup/res/installer.tpl.php new file mode 100644 index 0000000000..e335447270 --- /dev/null +++ b/setup/res/installer.tpl.php @@ -0,0 +1,21 @@ + +getErrors()) ? 'has-errors' : '', + count($reqs->getWarnings()) ? 'has-warnings' : '', + (count($reqs->getErrors()) + count($reqs->getWarnings()) > 0) ? 'has-problems' : '', + (count($reqs->getErrors()) + count($reqs->getWarnings()) === 0) ? 'has-no-problems' : '', +); +?> + +
+
+ +
+ + renderBlocks($_tpl_params); ?> + +
+
+
diff --git a/setup/res/page.tpl.php b/setup/res/page.tpl.php new file mode 100644 index 0000000000..3b3281cf67 --- /dev/null +++ b/setup/res/page.tpl.php @@ -0,0 +1,31 @@ + + + + + <?php echo htmlentities($pageTitle); ?> + ", htmlentities($pageAsset['url'])); + break; + + case 'script-code': + printf("", $pageAsset['code']); + break; + + case 'style-url': + printf("", htmlentities($pageAsset['url'])); + break; + + default: + throw new \Exception("Unrecognized page asset: " . $pageAsset['type']); + + } + } ?> + + + + + + + diff --git a/setup/res/template.php b/setup/res/template.php deleted file mode 100644 index 4af55b0d3c..0000000000 --- a/setup/res/template.php +++ /dev/null @@ -1,41 +0,0 @@ - - - - - <?php echo ts('CiviCRM Installer'); ?> - - - /> - getUrl('font-awesome.css') ?> /> -\n"; -} -?> - - - -getErrors()) ? 'has-errors' : '', - count($reqs->getWarnings()) ? 'has-warnings' : '', - (count($reqs->getErrors()) + count($reqs->getWarnings()) > 0) ? 'has-problems' : '', - (count($reqs->getErrors()) + count($reqs->getWarnings()) === 0) ? 'has-no-problems' : '', -); -?> - -
-
- -
- - renderBlocks($_tpl_params); ?> - -
-
-
- - diff --git a/setup/src/Setup/UI/SetupController.php b/setup/src/Setup/UI/SetupController.php index 032582ff99..2431e54e80 100644 --- a/setup/src/Setup/UI/SetupController.php +++ b/setup/src/Setup/UI/SetupController.php @@ -89,19 +89,14 @@ class SetupController implements SetupControllerInterface { */ $model = $this->setup->getModel(); - $tplFile = $this->getResourcePath('template.php'); + $tplFile = $this->getResourcePath('installer.tpl.php'); $tplVars = [ - 'ctrl' => $this, - 'civicrm_version' => \CRM_Utils_System::version(), - 'installURLPath' => $this->urls['res'], - 'short_lang_code' => \CRM_Core_I18n_PseudoConstant::shortForLong($GLOBALS['tsLocale']), - 'text_direction' => (\CRM_Core_I18n::isLanguageRTL($GLOBALS['tsLocale']) ? 'rtl' : 'ltr'), 'model' => $model, 'reqs' => $this->setup->checkRequirements(), ]; // $body = "
" . htmlentities(print_r(['method' => $method, 'urls' => $this->urls, 'data' => $fields], 1)) . "
"; - $body = $this->render($tplFile, $tplVars); + $body = $this->renderPage(ts('CiviCRM Installer'), $this->render($tplFile, $tplVars)); return array(array(), $body); } @@ -181,14 +176,39 @@ class SetupController implements SetupControllerInterface { public function createError($message, $title = 'Error') { return [ [], - $this->render($this->getResourcePath('error.html'), [ - 'errorTitle' => htmlentities($title), - 'errorMsg' => htmlentities($message), - 'installURLPath' => $this->urls['res'], - ]), + $this->renderPage($title, sprintf('

%s

\n%s', htmlentities($title), htmlentities($message))), ]; } + /** + * @param string $title + * @param string $body + * @return string + */ + public function renderPage($title, $body) { + /** @var \Civi\Setup\Model $model */ + $model = $this->setup->getModel(); + + $pageAssets = [ + ['type' => 'script-url', 'url' => $this->getUrl('jquery.js')], + ['type' => 'script-code', 'code' => 'window.csj$ = jQuery.noConflict();'], + ['type' => 'style-url', 'url' => $this->urls['res'] . "template.css"], + ['type' => 'style-url', 'url' => $this->getUrl('font-awesome.css')], + ]; + if (\CRM_Core_I18n::isLanguageRTL($model->lang)) { + $pageAssets[] = ['type' => 'style-url', 'url' => $this->urls['res'] . "template-rtl.css"]; + } + + $pageVars = [ + 'pageAssets' => $pageAssets, + 'pageTitle' => $title, + 'pageBody' => $body, + 'shortLangCode' => \CRM_Core_I18n_PseudoConstant::shortForLong($model->lang), + 'textDirection' => (\CRM_Core_I18n::isLanguageRTL($model->lang) ? 'rtl' : 'ltr'), + ]; + return $this->render($this->getResourcePath('page.tpl.php'), $pageVars); + } + /** * Render a *.php template file. * @@ -199,6 +219,7 @@ class SetupController implements SetupControllerInterface { * @return string */ public function render($_tpl_file, $_tpl_params = array()) { + $_tpl_params = array_merge($this->getCommonTplVars(), $_tpl_params); extract($_tpl_params); ob_start(); require $_tpl_file; @@ -306,12 +327,22 @@ class SetupController implements SetupControllerInterface { $m = $this->setup->getModel(); $tplFile = $this->getResourcePath('finished.' . $m->cms . '.php'); if (file_exists($tplFile)) { - $tplVars = array(); - return array(array(), $this->render($tplFile, $tplVars)); + return [[], $this->renderPage(ts('CiviCRM Installed'), $this->render($tplFile))]; } else { return $this->createError("Installation succeeded. However, the final page ($tplFile) was not available."); } } + /** + * @return array + */ + private function getCommonTplVars() { + return [ + 'ctrl' => $this, + 'civicrm_version' => \CRM_Utils_System::version(), + 'installURLPath' => $this->urls['res'], + ]; + } + } -- 2.25.1