From eea54218038082bd9dc8329c09b76a668af80d3a Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 31 Aug 2016 19:14:24 -0400 Subject: [PATCH] fix variable-protocol urls, fix vert spacing on fluid spans, remove moving gradient, switch dev.php to php7, add posts list template --- controller/action/ContentActions.class.php | 31 ++++++++++--------- dev.sh | 2 +- view/View.class.php | 35 +++++++++++++++------- view/template/content/_postList.php | 8 +++++ view/template/nav/_footer.php | 2 +- view/template/nav/_globalItems.php | 6 ++-- view/template/nav/_learnFooter.php | 6 ++-- view/template/social/_list.php | 6 ++-- web/scss/_cover.scss | 6 ++-- web/scss/_grid.scss | 4 +++ 10 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 view/template/content/_postList.php diff --git a/controller/action/ContentActions.class.php b/controller/action/ContentActions.class.php index 5e8faf84..783c11c0 100644 --- a/controller/action/ContentActions.class.php +++ b/controller/action/ContentActions.class.php @@ -1,10 +1,5 @@ CreditApi::getTotalDollarSales(), @@ -21,7 +16,7 @@ class ContentActions extends Actions ]]; } - public static function executeFaq() + public static function executeFaq(): array { $allPosts = Post::find(static::VIEW_FOLDER_FAQ); @@ -60,7 +55,7 @@ class ContentActions extends Actions ]]; } - public static function executeNews() + public static function executeNews(): array { $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC); return ['content/news', [ @@ -72,7 +67,7 @@ class ContentActions extends Actions } - public static function executeRss() + public static function executeRss(): array { $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC); return ['content/rss', [ @@ -83,7 +78,7 @@ class ContentActions extends Actions ]]; } - public static function executeNewsPost($relativeUri) + public static function executeNewsPost($relativeUri): array { try { @@ -101,7 +96,7 @@ class ContentActions extends Actions ]]; } - public static function executeFaqPost($relativeUri) + public static function executeFaqPost($relativeUri): array { try { @@ -116,7 +111,7 @@ class ContentActions extends Actions ]]; } - public static function executePressKit() + public static function executePressKit(): array { $zipFileName = 'lbry-press-kit-' . date('Y-m-d') . '.zip'; $zipPath = tempnam('/tmp', $zipFileName); @@ -177,7 +172,7 @@ class ContentActions extends Actions ]]; } - public static function prepareBioPartial(array $vars) + public static function prepareBioPartial(array $vars): array { $person = $vars['person']; $path = 'bio/' . $person . '.md'; @@ -191,7 +186,7 @@ class ContentActions extends Actions ]; } - public static function preparePostAuthorPartial(array $vars) + public static function preparePostAuthorPartial(array $vars): array { $post = $vars['post']; return [ @@ -200,4 +195,12 @@ class ContentActions extends Actions 'authorBioHtml' => $post->getAuthorBioHtml() ]; } + + public static function preparePostListPartial(array $vars): array + { + $count = isset($vars['count']) ? $vars['count'] : 3; + return [ + 'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count) + ]; + } } diff --git a/dev.sh b/dev.sh index 415ebe73..318acd8a 100755 --- a/dev.sh +++ b/dev.sh @@ -1,3 +1,3 @@ #!/bin/bash -php --server localhost:8000 --docroot web/ web/index.php \ No newline at end of file +php7.0 --server localhost:8000 --docroot web/ web/index.php diff --git a/view/View.class.php b/view/View.class.php index 8d4efbcf..a6c39a80 100644 --- a/view/View.class.php +++ b/view/View.class.php @@ -16,16 +16,16 @@ class View public static function render($template, array $vars = []) { - if (static::isMarkdown($template)) - { - return static::markdownToHtml(static::getFullPath($template)); - } - if (!static::exists($template) || substr_count($template, '/') !== 1) { throw new InvalidArgumentException(sprintf('The template "%s" does not exist or is unreadable.', $template)); } + if (static::isMarkdown($template)) + { + return static::markdownToHtml(static::getFullPath($template)); + } + list($module, $view) = explode('/', $template); $isPartial = $view[0] === '_'; @@ -42,23 +42,35 @@ class View return; } - extract($vars); + return static::interpolateTokens(static::getTemplateSafely($template, $vars)); + } + + /** + * This is its own function because we don't want in-scope variables to leak into the template + * + * @param string $___template + * @param array $___vars + * + * @return string + * @throws Throwable + */ + protected static function getTemplateSafely(string $___template, array $___vars): string + { + extract($___vars); ob_start(); ob_implicit_flush(0); try { - require(static::getFullPath($template)); + require(static::getFullPath($___template)); + return ob_get_clean(); } - catch (Exception $e) + catch (Throwable $e) { // need to end output buffering before throwing the exception ob_end_clean(); throw $e; } - - - return static::interpolateTokens(ob_get_clean()); } public static function markdownToHtml($path) @@ -82,6 +94,7 @@ class View { return $template; } + if (static::isMarkdown($template)) { return ROOT_DIR . '/posts/' . $template; diff --git a/view/template/content/_postList.php b/view/template/content/_postList.php new file mode 100644 index 00000000..a0ec09ab --- /dev/null +++ b/view/template/content/_postList.php @@ -0,0 +1,8 @@ +
+

Latest News

+ +
diff --git a/view/template/nav/_footer.php b/view/template/nav/_footer.php index 0a88f89f..dc7c5027 100644 --- a/view/template/nav/_footer.php +++ b/view/template/nav/_footer.php @@ -12,7 +12,7 @@
- + Free Speech Flag
diff --git a/view/template/nav/_globalItems.php b/view/template/nav/_globalItems.php index d5b8f855..b98fa7aa 100644 --- a/view/template/nav/_globalItems.php +++ b/view/template/nav/_globalItems.php @@ -8,13 +8,13 @@
- Twitter + Twitter
- Facebook + Facebook
- Reddit + Reddit
Slack diff --git a/view/template/nav/_learnFooter.php b/view/template/nav/_learnFooter.php index 115677ce..48b848fd 100644 --- a/view/template/nav/_learnFooter.php +++ b/view/template/nav/_learnFooter.php @@ -15,9 +15,9 @@
diff --git a/view/template/social/_list.php b/view/template/social/_list.php index c395587a..e48d0ebd 100644 --- a/view/template/social/_list.php +++ b/view/template/social/_list.php @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/web/scss/_cover.scss b/web/scss/_cover.scss index 7ee3f17f..369d6c49 100644 --- a/web/scss/_cover.scss +++ b/web/scss/_cover.scss @@ -68,11 +68,13 @@ } .cover-dark-grad { - @include linear-gradient(darken($color-primary, 5), lighten($color-primary, 5)); + //@include linear-gradient(darken($color-primary, 5), lighten($color-primary, 5)); + background-color: $color-primary; } .cover-light-alt-grad { - @include linear-gradient(darken($color-light-alt, 5), lighten($color-light-alt, 5)); + //@include linear-gradient(darken($color-light-alt, 5), lighten($color-light-alt, 5)); + background-color: $color-light-alt; } .cover-title, .cover-subtitle diff --git a/web/scss/_grid.scss b/web/scss/_grid.scss index 37766d19..1dc8b7f0 100644 --- a/web/scss/_grid.scss +++ b/web/scss/_grid.scss @@ -95,5 +95,9 @@ $gutter_fluid: 4; width: 100% !important; margin-left: 0 !important; display: block !important; + &:not(:last-child) + { + margin-bottom: $spacing-vertical; + } } } \ No newline at end of file