summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2018-05-09 21:42:32 +0100
committerGreg Roach <fisharebest@webtrees.net>2018-05-09 22:02:19 +0100
commit66e00285d0963270b29fbba077d6f48ddafafc00 (patch)
tree6aff55f253d02c48204ff5099b38a0235c561d48
parent487f2019da9d3adae7232a0f657f82c08e0a0af0 (diff)
downloadwebtrees-66e00285d0963270b29fbba077d6f48ddafafc00.tar.gz
webtrees-66e00285d0963270b29fbba077d6f48ddafafc00.tar.bz2
webtrees-66e00285d0963270b29fbba077d6f48ddafafc00.zip
Converting themes to views
-rw-r--r--app/Theme/AbstractTheme.php388
-rw-r--r--app/Theme/ThemeInterface.php82
-rw-r--r--resources/views/layouts/default.php68
3 files changed, 65 insertions, 473 deletions
diff --git a/app/Theme/AbstractTheme.php b/app/Theme/AbstractTheme.php
index 85cafbfd72..b8c665f70b 100644
--- a/app/Theme/AbstractTheme.php
+++ b/app/Theme/AbstractTheme.php
@@ -296,26 +296,6 @@ abstract class AbstractTheme {
}
/**
- * Create the top of the <body>.
- *
- * @return string
- */
- public function bodyHeader() {
- return
- '<body class="wt-global">' .
- '<header class="wt-header-wrapper d-print-none">' .
- '<div class="container wt-header-container">' .
- '<div class="row wt-header-content">' .
- $this->headerContent() .
- '</div>' .
- '</div>' .
- '</header>' .
- '<main id="content" class="wt-main-wrapper">' .
- '<div class="container wt-main-container">' .
- $this->flashMessagesContainer(FlashMessages::getMessages());
- }
-
- /**
* Create a contact link for a user.
*
* @param User $user
@@ -419,87 +399,6 @@ abstract class AbstractTheme {
}
/**
- * Create the <DOCTYPE> tag.
- *
- * @return string
- */
- public function doctype() {
- return '<!DOCTYPE html>';
- }
-
- /**
- * HTML link to a "favorites icon".
- *
- * @return string
- */
- public function favicon() {
- return
- '<link rel="icon" href="' . self::ASSET_DIR . 'favicon.png" type="image/png">' .
- '<link rel="icon" type="image/png" href="' . self::ASSET_DIR . 'favicon192.png" sizes="192x192">' .
- '<link rel="apple-touch-icon" sizes="180x180" href="' . self::ASSET_DIR . 'favicon180.png">';
- }
-
- /**
- * Add markup to a flash message.
- *
- * @param stdClass $message
- *
- * @return string
- */
- public function flashMessageContainer(stdClass $message) {
- return $this->htmlAlert($message->text, $message->status, true);
- }
-
- /**
- * Create a container for messages that are "flashed" to the session
- * on one request, and displayed on another. If there are many messages,
- * the container may need a max-height and scroll-bar.
- *
- * @param stdClass[] $messages
- *
- * @return string
- */
- public function flashMessagesContainer(array $messages) {
- $html = '';
- foreach ($messages as $message) {
- $html .= $this->flashMessageContainer($message);
- }
-
- if ($html) {
- return '<div class="flash-messages">' . $html . '</div>';
- } else {
- return '';
- }
- }
-
- /**
- * Close the main content and create the <footer> tag.
- *
- * @return string
- */
- public function footerContainer() {
- return
- '</div>' .
- '</main>' .
- '<footer class="wt-footer-container">' .
- '<div class="wt-footer-content container d-print-none">' . $this->footerContent() . '</div>' .
- '</footer>';
- }
-
- /**
- * Create the contents of the <footer> tag.
- *
- * @return string
- */
- public function footerContent() {
- return
- $this->formatContactLinks() .
- $this->logoPoweredBy() .
- $this->formatPageViews($this->page_views) .
- $this->cookieWarning();
- }
-
- /**
* Add markup to the contact links.
*
* @return string
@@ -545,55 +444,6 @@ abstract class AbstractTheme {
}
/**
- * Create a quick search form for the header.
- *
- * @return string
- */
- public function formQuickSearch() {
- if ($this->tree) {
- return
- '<div class="col wt-header-search">' .
- '<form class="wt-header-search-form" role="search">' .
- '<input type="hidden" name="route" value="search-quick">' .
- '<input type="hidden" name="ged" value="' . e($this->tree->getName()) . '">' .
- $this->formQuickSearchFields() .
- '</form>' .
- '</div>';
- } else {
- return '';
- }
- }
-
- /**
- * Create a search field and submit button for the quick search form in the header.
- *
- * @return string
- */
- public function formQuickSearchFields() {
- return
- '<div class="input-group">' .
- '<label class="sr-only" for="quick-search">' . I18N::translate('Search') . '</label>' .
- '<input type="search" class="form-control wt-header-search-field" id="quick-search" name="query" size="15" placeholder="' . I18N::translate('Search') . '">' .
- '<span class="input-group-btn">' .
- '<button type="submit" class="btn btn-primary wt-header-search-button"><i class="fas fa-search"></i></button>' .
- '</span>' .
- '</div>';
- }
-
- /**
- * Add markup to the tree title.
- *
- * @return string
- */
- public function formatTreeTitle() {
- if ($this->tree) {
- return '<h1 class="col wt-site-title">' . e($this->tree->getTitle()) . '</h1>';
- } else {
- return '';
- }
- }
-
- /**
* Add markup to the secondary menu.
*
* @return string
@@ -619,78 +469,7 @@ abstract class AbstractTheme {
}
/**
- * Create the <head> tag.
- *
- * @param PageController $controller The current controller
- *
- * @return string
- */
- public function head(PageController $controller) {
- // Record this now. By the time we render the footer, $controller no longer exists.
- $this->page_views = $this->pageViews($controller);
-
- return
- '<head>' .
- $this->headContents($controller) .
- $this->hookHeaderExtraContent() .
- $this->analytics() .
- '</head>';
- }
-
- /**
- * Create the contents of the <head> tag.
- *
- * @param PageController $controller The current controller
- *
- * @return string
- */
- public function headContents(PageController $controller) {
- // The title often includes the names of records, which may include HTML markup.
- $title = strip_tags($controller->getPageTitle());
-
- // If an extra (site) title is specified, append it.
- if ($this->tree && $this->tree->getPreference('META_TITLE')) {
- $title .= ' – ' . $this->tree->getPreference('META_TITLE');
- }
-
- $html = $this->metaCharset() .
- $this->metaCsrf() .
- $this->title($title) .
- $this->favicon() .
- $this->metaViewport() .
- $this->metaRobots($controller->getMetaRobots()) .
- $this->metaGenerator(WT_WEBTREES . ' ' . WT_VERSION . ' - ' . WT_WEBTREES_URL);
-
- if ($this->tree) {
- $html .= $this->metaDescription($this->tree->getPreference('META_DESCRIPTION'));
- }
-
- // CSS files
- foreach ($this->stylesheets() as $css) {
- $html .= '<link rel="stylesheet" type="text/css" href="' . $css . '">';
- }
-
- return $html;
- }
-
- /**
- * Create the contents of the <header> tag.
- *
- * @return string
- */
- public function headerContent() {
- return
- $this->accessibilityLinks() .
- $this->logoHeader() .
- $this->formatTreeTitle() .
- $this->formQuickSearch() .
- $this->secondaryMenuContainer($this->secondaryMenu()) .
- $this->primaryMenuContainer($this->primaryMenu());
- }
-
- /**
- * Allow themes to do things after initialization (since they cannot use
- * the constructor).
+ * Create resources for the colors theme.
*/
public function hookAfterInit() {
}
@@ -705,51 +484,6 @@ abstract class AbstractTheme {
}
/**
- * Allow themes to add extra content to the page header.
- * Typically this will be additional CSS.
- *
- * @return string
- */
- public function hookHeaderExtraContent() {
- return '';
- }
-
- /**
- * Create the <html> tag.
- *
- * @return string
- */
- public function html() {
- return '<html ' . I18N::htmlAttributes() . '>';
- }
-
- /**
- * Add HTML markup to create an alert
- *
- * @param string $html The content of the alert
- * @param string $level One of 'success', 'info', 'warning', 'danger'
- * @param bool $dismissible If true, add a close button.
- *
- * @return string
- */
- public function htmlAlert($html, $level, $dismissible) {
- if ($dismissible) {
- return
- '<div class="alert alert-' . $level . ' alert-dismissible" role="alert">' .
- '<button type="button" class="close" data-dismiss="alert" aria-label="' . I18N::translate('close') . '">' .
- '<span aria-hidden="true">&times;</span>' .
- '</button>' .
- $html .
- '</div>';
- } else {
- return
- '<div class="alert alert-' . $level . '" role="alert">' .
- $html .
- '</div>';
- }
- }
-
- /**
* Display an icon for this fact.
*
* @param Fact $fact
@@ -1104,15 +838,6 @@ abstract class AbstractTheme {
}
/**
- * A large webtrees logo, for the header.
- *
- * @return string
- */
- public function logoHeader() {
- return '<div class="col wt-site-logo"></div>';
- }
-
- /**
* A small "powered by webtrees" logo for the footer.
*
* @return string
@@ -1866,78 +1591,6 @@ abstract class AbstractTheme {
}
/**
- * Create the <meta charset=""> tag.
- *
- * @return string
- */
- public function metaCharset() {
- return '<meta charset="UTF-8">';
- }
-
- /**
- * Make the CSRF token available to Javascript.
- *
- * @return string
- */
- public function metaCsrf() {
- return '<meta name="csrf" content="' . e(Filter::getCsrfToken()) . '">';
- }
-
- /**
- * Create the <meta name="description"> tag.
- *
- * @param string $description
- *
- * @return string
- */
- public function metaDescription($description) {
- if ($description) {
- return '<meta name="description" content="' . $description . '">';
- } else {
- return '';
- }
- }
-
- /**
- * Create the <meta name="generator"> tag.
- *
- * @param string $generator
- *
- * @return string
- */
- public function metaGenerator($generator) {
- if ($generator) {
- return '<meta name="generator" content="' . $generator . '">';
- } else {
- return '';
- }
- }
-
- /**
- * Create the <meta name="robots"> tag.
- *
- * @param string $robots
- *
- * @return string
- */
- public function metaRobots($robots) {
- if ($robots) {
- return '<meta name="robots" content="' . $robots . '">';
- } else {
- return '';
- }
- }
-
- /**
- * Create the <meta name="viewport" content="width=device-width, initial-scale=1"> tag.
- *
- * @return string
- */
- public function metaViewport() {
- return '<meta name="viewport" content="width=device-width, initial-scale=1">';
- }
-
- /**
* How many times has the current page been shown?
*
* @param PageController $controller
@@ -2063,17 +1716,6 @@ abstract class AbstractTheme {
}
/**
- * Add markup to the primary menu.
- *
- * @param Menu[] $menus
- *
- * @return string
- */
- public function primaryMenuContainer(array $menus) {
- return '<nav class="col wt-primary-navigation"><ul class="nav wt-primary-menu">' . $this->primaryMenuContent($menus) . '</ul></nav>';
- }
-
- /**
* Create the primary menu.
*
* @param Menu[] $menus
@@ -2104,17 +1746,6 @@ abstract class AbstractTheme {
}
/**
- * Add markup to the secondary menu.
- *
- * @param Menu[] $menus
- *
- * @return string
- */
- public function secondaryMenuContainer(array $menus) {
- return '<div class="col wt-secondary-navigation"><ul class="nav wt-secondary-menu">' . $this->secondaryMenuContent($menus) . '</ul></div>';
- }
-
- /**
* Format the secondary menu.
*
* @param Menu[] $menus
@@ -2128,13 +1759,6 @@ abstract class AbstractTheme {
}
/**
- * Send any HTTP headers.
- */
- public function sendHeaders() {
- header('Content-Type: text/html; charset=UTF-8');
- }
-
- /**
* A list of CSS files to include for this page.
*
* @return string[]
@@ -2172,14 +1796,4 @@ abstract class AbstractTheme {
*/
abstract public function themeName();
- /**
- * Create the <title> tag.
- *
- * @param string $title
- *
- * @return string
- */
- public function title($title) {
- return '<title>' . e($title) . '</title>';
- }
}
diff --git a/app/Theme/ThemeInterface.php b/app/Theme/ThemeInterface.php
index 8d51223798..0848993f9c 100644
--- a/app/Theme/ThemeInterface.php
+++ b/app/Theme/ThemeInterface.php
@@ -27,14 +27,6 @@ use Fisharebest\Webtrees\User;
*/
interface ThemeInterface {
/**
- * Create the top of the <body>.
- *
- * @return string
- */
- public function bodyHeader();
-
-
- /**
* Create a contact link for a user.
*
* @param User $user
@@ -44,68 +36,6 @@ interface ThemeInterface {
public function contactLink(User $user);
/**
- * Create the <DOCTYPE> tag.
- *
- * @return string
- */
- public function doctype();
-
- /**
- * Close the main content and create the <footer> tag.
- *
- * @return string
- */
- public function footerContainer();
-
- /**
- * Create the <head> tag.
- *
- * @param PageController $controller The current controller
- *
- * @return string
- */
- public function head(PageController $controller);
-
- /**
- * Allow themes to do things after initialization (since they cannot use
- * the constructor).
- */
- public function hookAfterInit();
-
- /**
- * Allow themes to add extra scripts to the page footer.
- *
- * @return string
- */
- public function hookFooterExtraJavascript();
-
- /**
- * Allow themes to add extra content to the page header.
- * Typically this will be additional CSS.
- *
- * @return string
- */
- public function hookHeaderExtraContent();
-
- /**
- * Create the <html> tag.
- *
- * @return string
- */
- public function html();
-
- /**
- * Add HTML markup to create an alert
- *
- * @param string $html The content of the alert
- * @param string $level One of 'success', 'info', 'warning', 'danger'
- * @param bool $dismissible If true, add a close button.
- *
- * @return string
- */
- public function htmlAlert($html, $level, $dismissible);
-
- /**
* Display an icon for this fact.
*
* @param Fact $fact
@@ -173,13 +103,6 @@ interface ThemeInterface {
public function individualBoxMenu(Individual $individual);
/**
- * Themes menu.
- *
- * @return Menu|null
- */
- public function menuThemes();
-
- /**
* Misecellaneous dimensions, fonts, styles, etc.
*
* @param string $parameter_name
@@ -189,11 +112,6 @@ interface ThemeInterface {
public function parameter($parameter_name);
/**
- * Send any HTTP headers.
- */
- public function sendHeaders();
-
- /**
* A fixed string to identify this theme, in settings, etc.
*
* @return string
diff --git a/resources/views/layouts/default.php b/resources/views/layouts/default.php
index 5c269ff801..d1f6d316b0 100644
--- a/resources/views/layouts/default.php
+++ b/resources/views/layouts/default.php
@@ -42,14 +42,64 @@
<header class="wt-header-wrapper d-print-none">
<div class="container wt-header-container">
<div class="row wt-header-content">
- <?= Theme::theme()->headerContent() ?>
+ <div class="wt-accessibility-links">
+ <a class="sr-only sr-only-focusable btn btn-info btn-sm" href="#content">
+ <?= /* I18N: Skip over the headers and menus, to the main content of the page */ I18N::translate('Skip to content') ?>
+ </a>
+ </div>
+ <div class="col wt-site-logo"></div>
+
+ <?php if ($tree !== null): ?>
+ <h1 class="col wt-site-title"><?= e($tree->getTitle()) ?></h1>
+
+ <div class="col wt-header-search">
+ <form class="wt-header-search-form" role="search">
+ <input type="hidden" name="route" value="search-quick">
+ <input type="hidden" name="ged" value="<?= e($tree->getName()) ?>">
+ <div class="input-group">
+ <label class="sr-only" for="quick-search"><?= I18N::translate('Search') ?></label>
+ <input type="search" class="form-control wt-header-search-field" id="quick-search" name="query" size="15" placeholder="<?= I18N::translate('Search') ?>">
+ <span class="input-group-btn">
+ <button type="submit" class="btn btn-primary wt-header-search-button">
+ <i class="fas fa-search"></i>
+ </button>
+ </span>
+ </div>
+ </form>
+ </div>
+ <?php endif ?>
+
+ <div class="col wt-secondary-navigation">
+ <ul class="nav wt-secondary-menu">
+ <?php foreach (Theme::theme()->secondaryMenu() as $menu): ?>
+ <?= $menu->bootstrap4() ?>
+ <?php endforeach ?>
+ </ul>
+ </div>
+
+ <nav class="col wt-primary-navigation">
+ <ul class="nav wt-primary-menu">
+ <?php foreach (Theme::theme()->primaryMenu() as $menu): ?>
+ <?= $menu->bootstrap4() ?>
+ <?php endforeach ?>
+ </ul>
+ </nav>
</div>
</div>
</header>
<main id="content" class="wt-main-wrapper">
<div class="container wt-main-container">
- <?= Theme::theme()->flashMessagesContainer(FlashMessages::getMessages()) ?>
+ <div class="flash-messages">
+ <?php foreach (FlashMessages::getMessages() as $message): ?>
+ <div class="alert alert-<?= e($message->status) ?> alert-dismissible" role="alert">
+ <button type="button" class="close" data-dismiss="alert" aria-label="<?= I18N::translate('close') ?>">
+ <span aria-hidden="true">&times;</span>
+ </button>
+ <?= $message->text ?>
+ </div>
+ <?php endforeach ?>
+ </div>
<?= $content ?>
</div>
@@ -67,9 +117,19 @@
<script src="<?= e(WT_ASSETS_URL . 'js/vendor.js') ?>"></script>
<script src="<?= e(WT_ASSETS_URL . 'js/webtrees.js') ?>"></script>
- <?= View::stack('javascript') ?>
+ <script>
+ activate_colorbox();
+ jQuery.extend(jQuery.colorbox.settings, {
+ width: "85%",
+ height: "85%",
+ transition: "none",
+ slideshowStart: "<?= I18N::translate('Play') ?>"
+ slideshowStop: "<?= I18N::translate('Stop') ?>",
+ title: function() { return this.dataset.title; }
+ });
+ </script>
- <?= Theme::theme()->hookFooterExtraJavascript() ?>
+ <?= View::stack('javascript') ?>
<?= DebugBar::render() ?>
</body>