Skip to content

Commit

Permalink
Channel Blog (#563)
Browse files Browse the repository at this point in the history
* change channel call banner header to layout and not index html

* add Channel Types constants

* add blog routes for channel

* redirect to channel if relation does not exist

* improve handling of redirects in channel blog post action

* fixes based on review and change in header for channel blog post
  • Loading branch information
davidbeig authored Oct 20, 2023
1 parent 48f3cc9 commit 46175a2
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 41 deletions.
33 changes: 33 additions & 0 deletions Resources/templates/responsive/channel/call/blog/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

$image = $this->channel->logo ? $this->channel->logo->getLink(700, 700, false, true) : $this->asset('img/blog/header_default.png') ;

$this->layout('channel/call/layout', [
'bodyClass' => 'blog channel-call',
'title' => $this->post->title,
'meta_description' => $this->post->subtitle ?: $this->post->title,
'tw_image' => $image,
'og_image' => $image
]);
?>

<?php
$this->section('header');
$this->replace();
?>


<?php
$this->section('channel-content');
?>

<header class="banner-header">
<?= $this->insert('channel/call/partials/navbar') ?>
</header>

<?= $this->insert('blog/partials/blog_header') ?>
<?= $this->insert('blog/partials/content') ?>
<?= $this->insert('blog/partials/tags') ?>
<?= $this->insert('blog/partials/related_posts') ?>

<?php $this->replace() ?>
6 changes: 2 additions & 4 deletions Resources/templates/responsive/channel/call/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
]);

$this->section('head');

?>

<link rel="stylesheet" type="text/css" href="<?= SRC_URL ?>/assets/vendor/slick-carousel/slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="<?= SRC_URL ?>/assets/vendor/slick-carousel/slick/slick-theme.css"/>

<?php
$this->append();
?>

<?php
$this->section('header');
?>

<?php $this->insert('channel/call/partials/banner_header'); ?>

<?php
$this->replace();

Expand All @@ -33,7 +32,6 @@

<?php $this->section('footer') ?>


<?= $this->insert('channel/call/partials/footer') ?>

<?= $this->insert('partials/footer/javascript') ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

<?= $this->insert('channel/call/partials/projects') ?>

<?php $this->replace() ?>
<?php $this->replace() ?>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php $channel=$this->channel; ?>
<?php
$channel=$this->channel;
$colors = $this->a($this->colors);
?>

<div class="section banner-header">

<!-- Navbar header -->
<?= $this->insert('channel/call/partials/navbar') ?>

<div class="image">
Expand All @@ -12,9 +13,9 @@
<?php $header_image_xs=$this->channel->getBannerHeaderImageXs(); ?>

<picture>
<source srcset="<?= $header_image->getLink(1920, 600, true) ?>" media="(min-width:1400px)">
<source srcset="<?= $header_image_md->getLink(1400, 600, true) ?>" media="(min-width:1051px)">
<source srcset="<?= $header_image_sm->getLink(1051, 600, true) ?>" media="(min-width:550px)">
<source srcset="<?= $header_image->getLink(1920, 600, true) ?>" media="(min-width:1400px)">
<source srcset="<?= $header_image_md->getLink(1400, 600, true) ?>" media="(min-width:1051px)">
<source srcset="<?= $header_image_sm->getLink(1051, 600, true) ?>" media="(min-width:550px)">
<img src="<?= $header_image_xs->getLink(550, 600, true) ?>">
</picture>
</div>
Expand All @@ -24,14 +25,14 @@
<div class="row">
<div class="col-lg-6 col-md-7 col-sm-8 col-xs-12">
<div>
<span class="title" style="<?= $this->colors['header'] ? "color:".$this->colors['header'].";" : '' ?> <?= $this->colors['header_shadow'] ? "text-shadow:none" : '' ?>" >
<?= $this->channel->subtitle ?>
<span class="title" style="<?= $colors['header'] ? 'color:'.$colors['header'].';' : '' ?> <?= $colors['header_shadow'] ? 'text-shadow:none' : '' ?>" >
<?= $this->channel->subtitle ?>
</span>
</div>
<div class="description" style="<?= $this->colors['header'] ? "color:".$this->colors['header'].";" : '' ?> <?= $this->colors['header_shadow'] ? "text-shadow:none" : '' ?>" >
<div class="description" style="<?= $colors['header'] ? 'color:'.$colors['header'].';' : '' ?> <?= $colors['header_shadow'] ? 'text-shadow:none' : '' ?>" >
<?= $this->channel->description ?>
</div>
<a href="<?= $this->channel->banner_button_url ?>" class="btn btn-yellow scroller"><i class="icon icon-plus icon-2x">
<a href="<?= $this->channel->banner_button_url ?>" class="btn btn-yellow scroller"><i class="icon icon-plus icon-2x">
</i><?= $this->text('landing-more-info') ?>
</a>
</div>
Expand All @@ -45,7 +46,7 @@
<div class="info">
<div class="container">
<div class="row">
<div class="col-md-6 subtitle" style="<?= $this->colors['secondary'] ? "color:".$this->colors['secondary'] : '' ?>">
<div class="col-md-6 subtitle" style="<?= $colors['secondary'] ? 'color:'.$colors['secondary'] : '' ?>">
<?= $this->text('channel-call-main-info-subtitle') ?>
</div>
</div>
Expand Down Expand Up @@ -83,4 +84,4 @@

<?php endif; ?>

</div>
</div>
13 changes: 8 additions & 5 deletions Resources/templates/responsive/channel/call/partials/navbar.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
$colors = $this->a($this->colors);
?>
<div class="custom-header">
<div class="pull-left">
<a href="<?= '/channel/'.$this->channel->id . $this->lang_url_query($this->lang_current())?> ">
<img src="<?= $this->channel->logo ? $this->channel->logo->getlink(0,40) : '' ?>" height="40px">
</a>
</div>
<div class="pull-right hidden-xs">
<span style="<?= $this->colors['header'] ? "color:".$this->colors['header'] : '' ?> ">
<?= $this->text('call-header-powered-by') ?>
<span style="<?= $colors['header'] ? 'color:'.$colors['header'] : '' ?> ">
<?= $this->text('call-header-powered-by') ?>
</span>
<a href="<?= $this->get_config('url.main') ?>">
<?php if($this->colors['header_logo']=="blue"): ?>
<?php if($colors['header_logo']=='blue'): ?>
<img height="30" src="<?= '/assets/img/goteo-blue-green.svg' ?>" >
<?php else: ?>
<img height="30" src="<?= '/assets/img/goteo-white-green.png' ?>" >
Expand All @@ -18,7 +21,7 @@
</div>
<div id="navbar" class="navbar languages">
<div class="active">
<span style="<?= $this->colors['header'] ? "color:".$this->colors['header'] : '' ?> "><?= $this->lang_name($this->lang_current()) ?></span>
<span style="<?= $colors['header'] ? 'color:'.$colors['header'] : '' ?> "><?= $this->lang_name($this->lang_current()) ?></span>
<span class="glyphicon glyphicon glyphicon-menu-down" aria-hidden="true"></span>
</div>
<ul class="languages-list list-unstyled">
Expand All @@ -32,4 +35,4 @@
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?= date_formater($this->post->date) ?>
</div>
<div class="title">
<a href="<?= '/blog/' . $this->post->getSlug() . $this->lang_url_query($this->lang_current()) ?>">
<a href="<?= '/channel/' . $this->channel->id. '/blog/' . $this->post->getSlug() . $this->lang_url_query($this->lang_current()) ?>">
<?= $this->text_truncate($this->post->title, 20) ?>
</a>
</div>
Expand All @@ -26,7 +26,7 @@
<div class="author">
<?= $author->name ?>
</div>
<a class="arrow" href="<?= '/blog/' . $this->post->getSlug() . $this->lang_url_query($this->lang_current()) ?>">
<a class="arrow" href="<?= '/channel/' . $this->channel->id. '/blog/' . $this->post->getSlug() . $this->lang_url_query($this->lang_current()) ?>">
<span class="icon icon-arrow icon-2x"></span>
</a>
</div>
Expand Down
20 changes: 20 additions & 0 deletions public/assets/sass/layouts/_channel_call.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@

body.channel-call {

header.banner-header {
div.custom-header{
width: 95%;
margin-left: 2.5%;
border-bottom: 1px solid $color-white;
padding: 20px 0 0px 0;
color: $color-white;
font-weight: bold;
z-index: 100;
img{
margin-left: 5px;
vertical-align: sub;
}

.navbar-toggle {
background-color: unset;
}
}
}

div.languages{
text-transform: uppercase;
float:right;
Expand Down
11 changes: 9 additions & 2 deletions src/Goteo/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Goteo\Library\Text;
use Goteo\Model\Blog\Post;
use Goteo\Model\Blog\Post\Tag;
use Goteo\Model\Node\NodePost;
use Symfony\Component\HttpFoundation\Request;

class BlogController extends Controller {
Expand Down Expand Up @@ -47,7 +48,8 @@ public function indexAction(Request $request, $section='', $tag='') {

}, $slider_posts);

$init = $request->query->get('pag') ? $request->query->get('pag')*$limit : 0;
$page = $request->query->getDigits('pag', 0);
$init = $page * $limit;

$list_posts = Post::getList(['section' => $section, 'tag' => $tag], true, $init, $limit);
$total = Post::getList(['section' => $section, 'tag' => $tag], true, 0, 0, true);
Expand All @@ -65,7 +67,7 @@ public function indexAction(Request $request, $section='', $tag='') {
]);
}

public function postAction($slug)
public function postAction(Request $request, $slug)
{
// Get related posts
$post = Post::getBySlug($slug, Lang::current());
Expand All @@ -75,6 +77,11 @@ public function postAction($slug)
throw new ModelNotFoundException("Post [$slug] not found!");
}

$channelPosts = NodePost::getList(['post' => $post->id]);
if (!empty($channelPosts)) {
return $this->redirect("/channel/{$channelPosts[0]->node_id}/blog/{$slug}");
}

$user = Session::getUser();
if (!$post->publish) {
if($user && $user->hasPerm('admin-module-blog')) {
Expand Down
39 changes: 35 additions & 4 deletions src/Goteo/Controller/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use Goteo\Core\Controller;
use Goteo\Library\Forms\FormModelException;
use Goteo\Library\Forms\Model\QuestionnaireForm;
use Goteo\Model\Blog\Post;
use Goteo\Model\Footprint;
use Goteo\Model\Node\NodePost;
use Goteo\Model\Node\NodeSections;
use Goteo\Model\Sdg;
use Goteo\Repository\DataSetRepository;
Expand Down Expand Up @@ -80,12 +82,11 @@ private function setChannelContext($id)

$config = $channel->getConfig();

if($config['google_analytics']) {
Config::set('analytics.google', array_merge(Config::get('analytics.google'), [$config['google_analytics']]));
}
if($config['google_analytics'])
Config::set('analytics.google', array_merge(Config::get('analytics.google'), [$config['google_analytics']]));

// get custom colors from config field
$colors=$config['colors'] ? $config['colors'] : [];
$colors=$config['colors'] ?: [];

//check if there are elements to show by type
foreach($types as $key => $type)
Expand Down Expand Up @@ -557,4 +558,34 @@ private function addValuesContext(Node $channel, array $values = []) {

}

public function blogPostAction(Request $request, string $id, string $slug): Response
{
try {
$channel = Node::get($id);
} catch (ModelNotFoundException $e) {
Message::error($e->getMessage());
return $this->redirect('/');
}

$post = Post::get($slug);

if (!$post instanceof Post) {
return $this->redirect('/channel/' . $id);
}

$channelPost = NodePost::getNodePost($channel->id, $post->id);
if (!$channelPost) {
$this->redirect('/channel/' . $id);
}

$relatedPosts = Post::getList(['node' => $id, 'excluded' => $post->id], 0, 3);

return $this->viewResponse('/channel/call/blog/post',[
'post' => $post,
'channel' => $channel,
'related_posts' => $relatedPosts
]);

}

}
21 changes: 17 additions & 4 deletions src/Goteo/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Goteo\Model;

use Goteo\Application\Exception\ModelNotFoundException;
use Goteo\Application\Lang;
use Goteo\Application\Config;
use Goteo\Model\Image;
Expand All @@ -33,6 +34,9 @@ class Node extends \Goteo\Core\Model {
use ImpactDataRelationsTrait;
use DataSetRelationsTrait;

const TYPE_CALL = 'call';
const TYPE_NORMAL = 'normal';

public
$id = null,
$name,
Expand Down Expand Up @@ -104,9 +108,10 @@ public static function getLangFields() {
}

/**
* Obtener datos de un nodo
* @param type mixed $id Identificador
* @return type object Objeto
* @param string $id
* @param string $lang
* @throws ModelNotFoundException
* @return Node
*/
static public function get ($id, $lang = null) {

Expand Down Expand Up @@ -162,7 +167,7 @@ static public function get ($id, $lang = null) {
$item = $query->fetchObject(__CLASS__);

if (!$item instanceof Node) {
throw new Exception\ModelNotFoundException(Text::get('fatal-error-node'));
throw new ModelNotFoundException(Text::get('fatal-error-node'));
}

return $item;
Expand Down Expand Up @@ -1262,5 +1267,13 @@ public function findProject($pid)
return self::query($sql, $values)->fetchAll(\PDO::FETCH_CLASS. __CLASS__);
}

public function isTypeNormal(): bool
{
return self::TYPE_NORMAL === $this->type;
}

public function isTypeCall(): bool
{
return self::TYPE_CALL === $this->type;
}
}
Loading

0 comments on commit 46175a2

Please sign in to comment.