fix variable-protocol urls, fix vert spacing on fluid spans, remove moving gradient, switch dev.php to php7, add posts list template

This commit is contained in:
Alex Grintsvayg 2016-08-31 19:14:24 -04:00
parent dad52ad7b4
commit eea5421803
10 changed files with 68 additions and 38 deletions

View file

@ -1,10 +1,5 @@
<?php <?php
/**
* Description of ContentActions
*
* @author jeremy
*/
class ContentActions extends Actions class ContentActions extends Actions
{ {
const RSS_SLUG = 'rss.xml', const RSS_SLUG = 'rss.xml',
@ -13,7 +8,7 @@ class ContentActions extends Actions
VIEW_FOLDER_NEWS = ROOT_DIR . '/posts/news', VIEW_FOLDER_NEWS = ROOT_DIR . '/posts/news',
VIEW_FOLDER_FAQ = ROOT_DIR . '/posts/faq'; VIEW_FOLDER_FAQ = ROOT_DIR . '/posts/faq';
public static function executeHome() public static function executeHome(): array
{ {
return ['page/home', [ return ['page/home', [
'totalUSD' => CreditApi::getTotalDollarSales(), 'totalUSD' => 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); $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); $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC);
return ['content/news', [ 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); $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC);
return ['content/rss', [ return ['content/rss', [
@ -83,7 +78,7 @@ class ContentActions extends Actions
]]; ]];
} }
public static function executeNewsPost($relativeUri) public static function executeNewsPost($relativeUri): array
{ {
try try
{ {
@ -101,7 +96,7 @@ class ContentActions extends Actions
]]; ]];
} }
public static function executeFaqPost($relativeUri) public static function executeFaqPost($relativeUri): array
{ {
try 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'; $zipFileName = 'lbry-press-kit-' . date('Y-m-d') . '.zip';
$zipPath = tempnam('/tmp', $zipFileName); $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']; $person = $vars['person'];
$path = 'bio/' . $person . '.md'; $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']; $post = $vars['post'];
return [ return [
@ -200,4 +195,12 @@ class ContentActions extends Actions
'authorBioHtml' => $post->getAuthorBioHtml() '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)
];
}
} }

2
dev.sh
View file

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
php --server localhost:8000 --docroot web/ web/index.php php7.0 --server localhost:8000 --docroot web/ web/index.php

View file

@ -16,16 +16,16 @@ class View
public static function render($template, array $vars = []) 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) if (!static::exists($template) || substr_count($template, '/') !== 1)
{ {
throw new InvalidArgumentException(sprintf('The template "%s" does not exist or is unreadable.', $template)); 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); list($module, $view) = explode('/', $template);
$isPartial = $view[0] === '_'; $isPartial = $view[0] === '_';
@ -42,23 +42,35 @@ class View
return; 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_start();
ob_implicit_flush(0); ob_implicit_flush(0);
try 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 // need to end output buffering before throwing the exception
ob_end_clean(); ob_end_clean();
throw $e; throw $e;
} }
return static::interpolateTokens(ob_get_clean());
} }
public static function markdownToHtml($path) public static function markdownToHtml($path)
@ -82,6 +94,7 @@ class View
{ {
return $template; return $template;
} }
if (static::isMarkdown($template)) if (static::isMarkdown($template))
{ {
return ROOT_DIR . '/posts/' . $template; return ROOT_DIR . '/posts/' . $template;

View file

@ -0,0 +1,8 @@
<div>
<h3>Latest News</h3>
<ul class="no-style">
<?php foreach($posts as $post): ?>
<li><a href="<?php echo '/'.$post->getRelativeUrl() ?>"><?php echo $post->getTitle() ?></a></li>
<?php endforeach ?>
</ul>
</div>

View file

@ -12,7 +12,7 @@
</div> </div>
<?php echo View::render('nav/_globalItems') ?> <?php echo View::render('nav/_globalItems') ?>
<div class="control-item"> <div class="control-item">
<a href="//en.wikipedia.org/wiki/AACS_encryption_key_controversy" class="footer-img-link"> <a href="https://en.wikipedia.org/wiki/AACS_encryption_key_controversy" class="footer-img-link">
<img src="/img/Free-speech-flag.svg" alt="Free Speech Flag" height="30"/> <img src="/img/Free-speech-flag.svg" alt="Free Speech Flag" height="30"/>
</a> </a>
</div> </div>

View file

@ -8,13 +8,13 @@
</div> </div>
<?php endforeach ?> <?php endforeach ?>
<div class="control-item no-label-desktop"> <div class="control-item no-label-desktop">
<a href="//twitter.com/lbryio"><span class="btn-label">Twitter</span> <span class="icon-fw icon-twitter"></span></a> <a href="https://twitter.com/lbryio"><span class="btn-label">Twitter</span> <span class="icon-fw icon-twitter"></span></a>
</div> </div>
<div class="control-item no-label-desktop"> <div class="control-item no-label-desktop">
<a href="//www.facebook.com/lbryio"><span class="btn-label">Facebook</span> <span class="icon-fw icon-facebook"></span></a> <a href="https://www.facebook.com/lbryio"><span class="btn-label">Facebook</span> <span class="icon-fw icon-facebook"></span></a>
</div> </div>
<div class="control-item no-label-desktop"> <div class="control-item no-label-desktop">
<a href="//reddit.com/r/lbry"><span class="btn-label">Reddit</span> <span class="icon-fw icon-reddit"></span> </a> <a href="https://reddit.com/r/lbry"><span class="btn-label">Reddit</span> <span class="icon-fw icon-reddit"></span> </a>
</div> </div>
<div class="control-item no-label-desktop"> <div class="control-item no-label-desktop">
<a href="http://slack.lbry.io"><span class="btn-label">Slack</span><span class="icon-slack icon-fw"></span></a> <a href="http://slack.lbry.io"><span class="btn-label">Slack</span><span class="icon-slack icon-fw"></span></a>

View file

@ -15,9 +15,9 @@
</table> </table>
<ul> <ul>
<li><a href="/join-list" class="link-primary"><?php echo __('email.subscribe') ?></a>.</li> <li><a href="/join-list" class="link-primary"><?php echo __('email.subscribe') ?></a>.</li>
<li>Join us on <a href="//twitter.com/lbryio" class="link-primary"><span class="btn-label">Twitter</span><span class="icon icon-twitter"></span></a>, <li>Join us on <a href="https://twitter.com/lbryio" class="link-primary"><span class="btn-label">Twitter</span><span class="icon icon-twitter"></span></a>,
<a href="//facebook.com/lbryio" class="link-primary"><span class="btn-label">Facebook</span><span class="icon icon-facebook"></span></a>, <a href="https://facebook.com/lbryio" class="link-primary"><span class="btn-label">Facebook</span><span class="icon icon-facebook"></span></a>,
or <a href="//reddit.com/r/lbry" class="link-primary"><span class="btn-label">Reddit</span><span class="icon icon-reddit"></span></a>.</li> or <a href="https://reddit.com/r/lbry" class="link-primary"><span class="btn-label">Reddit</span><span class="icon icon-reddit"></span></a>.</li>
</ul> </ul>
</div> </div>
<div class="span6"> <div class="span6">

View file

@ -1,9 +1,9 @@
<div class="spacer1"> <div class="spacer1">
<a href="//twitter.com/lbryio" class="link-primary"><span class="icon-twitter icon-fw"></span><span class="btn-label">Twitter</span></a> <a href="https://twitter.com/lbryio" class="link-primary"><span class="icon-twitter icon-fw"></span><span class="btn-label">Twitter</span></a>
</div> </div>
<div class="spacer1"> <div class="spacer1">
<a href="//www.facebook.com/lbryio" class="link-primary"><span class="icon-facebook icon-fw"></span><span class="btn-label">Facebook</span></a> <a href="https://www.facebook.com/lbryio" class="link-primary"><span class="icon-facebook icon-fw"></span><span class="btn-label">Facebook</span></a>
</div> </div>
<div class="spacer1"> <div class="spacer1">
<a href="//reddit.com/r/lbry" class="link-primary"><span class="icon-reddit icon-fw"></span><span class="btn-label">Reddit</span></a> <a href="https://reddit.com/r/lbry" class="link-primary"><span class="icon-reddit icon-fw"></span><span class="btn-label">Reddit</span></a>
</div> </div>

View file

@ -68,11 +68,13 @@
} }
.cover-dark-grad .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 .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 .cover-title, .cover-subtitle

View file

@ -95,5 +95,9 @@ $gutter_fluid: 4;
width: 100% !important; width: 100% !important;
margin-left: 0 !important; margin-left: 0 !important;
display: block !important; display: block !important;
&:not(:last-child)
{
margin-bottom: $spacing-vertical;
}
} }
} }