]> _ Git - fluidbook-v3.git/commitdiff
WIP #3641 @10
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 26 May 2020 17:58:03 +0000 (17:58 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 26 May 2020 17:58:03 +0000 (17:58 +0000)
framework/application/controllers/BlogpostController.php
framework/application/forms/CMS/Sub/Blog/Post.php
framework/application/models/Blog.php
framework/application/views/helpers/BackgroundBlock.php
framework/application/views/helpers/BlogBody.php [new file with mode: 0644]
framework/application/views/helpers/BlogIndex.php
framework/application/views/helpers/BlogIntro.php [new file with mode: 0644]
framework/application/views/helpers/ContactFooter.php
framework/application/views/helpers/HomeLayer.php
framework/application/views/scripts/blogpost/index.phtml
less/610-blog.less [new file with mode: 0644]

index cd32ce2dc06382c685b115de8bc8e13748c352b9..33c34a48b174576af49f252ba025e35a4d824ad7 100644 (file)
@@ -4,7 +4,7 @@ class BlogpostController extends CubeIT_Controller_PageController {
 
     public function indexAction() {
 
-        $this->view->headScript()->addScriptAndStyle('blog-post');
+        $this->view->headScript()->addScriptAndStyle('610-blog');
 
         //$parent = $this->view->currentPage->getParent();
         //$parent_data = $this->getBootstrap()->getCMSDatasOfNavigationPage($parent);
@@ -13,8 +13,14 @@ class BlogpostController extends CubeIT_Controller_PageController {
 
         $model = Fluidbook_Model_Blog::factory()
             ->order('publish_date DESC')
-            ->where('id = ?', $this->getRequest()
-                ->getParam('post_id'));
+            ->where('id = ?', $this->getRequest()->getParam('post_id'));
+
+        // Non-admin users can't see offline or future posts
+        if (!$this->isAllowed('edition')) {
+            $model->where('online = ?', 1);
+            $model->where('publish_date <= NOW()');
+        }
+
         $post = $model->find();
 
         if (count($post) < 1) {
@@ -24,6 +30,7 @@ class BlogpostController extends CubeIT_Controller_PageController {
 
         // Get the first and only array item
         $post = reset($post);
+        $post = $post->unserialize();
 
         $this->view->post = $post->unserialize();
         $this->view->headTitle($post->getTitle(), 'SET');
index db334594543d2ba2be37b1abd2245abf84744b50..b86e46d7ad3f7ae210649c89b4f1f7d867345171 100644 (file)
@@ -35,13 +35,13 @@ class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model
         $intro_image->setMaxItems(1);
         $this->addElement($intro_image);
 
-        $intro_text_color = new Zend_Form_Element_Select('intro_text_color');
-        $intro_text_color->setLabel('Intro Text Colour')
+        $intro_style = new Zend_Form_Element_Select('intro_style');
+        $intro_style->setLabel('Intro Block Style')
             ->setMultiOptions([
                 'light' => 'Light',
                 'dark' => 'Dark',
             ]);
-        $this->addElement($intro_text_color);
+        $this->addElement($intro_style);
 
         $intro_gradient_start = new CubeIT_Form_Element_Color('intro_gradient_start');
         $intro_gradient_start->setLabel('Intro Gradient Start')
index 72771b6c13c2454d49cf2ec86a509e5ce0954433..746128f9f1bd388648b68033dd3173a20b8031f1 100644 (file)
@@ -9,7 +9,7 @@ class Fluidbook_Model_Blog extends CubeIT_Model_Data_Table
     protected $intro_image;\r
     protected $intro_gradient_start;\r
     protected $intro_gradient_end;\r
-    protected $intro_text_color;\r
+    protected $intro_style;\r
     protected $content;\r
     protected $publish_date;\r
     protected $author_id;\r
@@ -26,7 +26,7 @@ class Fluidbook_Model_Blog extends CubeIT_Model_Data_Table
         $table->addColumn('intro_image', 'text');\r
         $table->addColumn('intro_gradient_start', 'string', ['length' => 7]); // Hex code\r
         $table->addColumn('intro_gradient_end', 'string', ['length' => 7]); // Hex code\r
-        $table->addColumn('intro_text_color', 'string', ['length' => 7]); // light|dark\r
+        $table->addColumn('intro_style', 'string', ['length' => 5, 'default' => 'light']); // light|dark (used for setting text colour + header style)\r
         $table->addColumn('content', 'text');\r
         $table->addColumn('publish_date', 'datetime');\r
         $table->addColumn('author_id', 'integer', ['unsigned' => true]);\r
index 3be23e454ec1373f4976ee733ffe80db67d23c87..f6060f8361004edf120acf8db84a01a09c781df4 100644 (file)
@@ -5,10 +5,15 @@ class Fluidbook_View_Helper_BackgroundBlock extends CubeIT_View_Helper_Abstract
     /**\r
      * @return string\r
      */\r
-    public function backgroundBlock($content, $data, $class = array('content-wrapper', 'no-shrink'))\r
+    public function backgroundBlock($content, $data, $attributes = [])\r
     {\r
-        $style = '';\r
-        $attributes = array('class' => $class);\r
+        if (!isset($attributes['style'])) {\r
+            $attributes['style'] = '';\r
+        }\r
+\r
+        if (!isset($attributes['class'])) {\r
+            $attributes['class'] = ['content-wrapper', 'no-shrink'];\r
+        }\r
 \r
         if (isset($data['backgroundimage']) && !isset($data['bg_image'])) {\r
             $data['bg_image'] = $data['backgroundimage'];\r
@@ -54,11 +59,9 @@ class Fluidbook_View_Helper_BackgroundBlock extends CubeIT_View_Helper_Abstract
                             $target_height = $mobile_max_width * $image_ratio;\r
                             $mobile = $this->imageProcess()->imageProcessGetURL($mobile_path, '', $mobile_max_width, $target_height, array(), 'C', 'R', 'M');\r
                         } else {\r
-                            $attributes['data-bg-ratio'] = $attributes['data-bg-ratio'];\r
                             $mobile = $this->imageProcess()->imageProcessGetURL($image_path, '', $mobile_max_width, $target_height, array(), 'C', 'R', 'M');\r
                         }\r
                     } else {\r
-                        $attributes['data-bg-ratio'] = $attributes['data-bg-ratio'];\r
                         $mobile = $this->imageProcess()->imageProcessGetURL($image_path, '', $mobile_max_width, $target_height, array(), 'C', 'R', 'M');\r
                     }\r
 \r
@@ -85,9 +88,8 @@ class Fluidbook_View_Helper_BackgroundBlock extends CubeIT_View_Helper_Abstract
         }\r
 \r
         if (isset($data['bg_color'])) {\r
-            $style .= "background-color:" . $data['bg_color'] . ";";\r
+            $attributes['style'] .= "background-color: {$data['bg_color']};";\r
         }\r
-        $attributes['style'] = $style;\r
 \r
         return $this->htmlElement($content, 'div', $attributes);\r
     }\r
diff --git a/framework/application/views/helpers/BlogBody.php b/framework/application/views/helpers/BlogBody.php
new file mode 100644 (file)
index 0000000..b58f30c
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+class Fluidbook_View_Helper_BlogBody extends CubeIT_View_Helper_Abstract {
+
+    public function blogBody(Fluidbook_Model_Blog $post) {
+
+        $res  = '<div class="content-wrapper grid">';
+        $res .= '<div class="blog-post-body">';
+
+        foreach ($post->getContent() as $content) {
+
+            $res .= '<div class="block-'. $content->content_type .'">';
+
+            switch($content->content_type) {
+                case 'text':
+                    $res .= $this->_text($content);
+                    break;
+
+                case 'image':
+                    $res .= $this->_image($content);
+                    break;
+            }
+
+            $res .= '</div>'; // .block-$content->content_type
+        }
+
+        $res .= '</div>'; // .blog-post-body
+        $res .= '</div>'; // .content-wrapper
+
+        return $res;
+    }
+
+    protected function _text($content) {
+        return $this->markupDotclear($content->text);
+    }
+
+    protected function _image($content) {
+
+        $class = (!empty($content->image_style)) ? 'image-'.$content->image_style : '';
+
+        $res = '<figure class="image '. $class .'">';
+
+        if (!empty($content->image)) {
+            $res .= $this->imageCms($content->image, $content->image_caption);
+        }
+
+        if (!empty($content->image_caption)) {
+            $res .= '<figcaption>'. $content->image_caption .'</figcaption>';
+        }
+
+        $res .= '</figure>';
+
+        return $res;
+    }
+
+}
index 4366e460b41f36d75ef492f5d5f16d7c807a5710..e876ebee15cf55eec52dad9c74c0615ad3c713bb 100644 (file)
@@ -6,32 +6,23 @@ class Fluidbook_View_Helper_BlogIndex extends CubeIT_View_Helper_Abstract {
      */\r
     public function blogIndex() {\r
 \r
-        $posts = Fluidbook_Model_Blog::factory()->order('publish_date DESC')->find();\r
+        $model = Fluidbook_Model_Blog::factory()->order('publish_date DESC');\r
+\r
+        // Don't show offline or future posts to non-admins\r
+        if (!$this->acl()->isAllowed('edition')) {\r
+            $model->where('online = ?', 1);\r
+            $model->where('publish_date <= NOW()');\r
+        }\r
+\r
+        $posts = $model->find();\r
 \r
         $res = '';\r
 \r
         foreach ($posts as $post) {\r
             /* @var $post Fluidbook_Model_Blog */\r
-            $res .= $this->post($post->unserialize());\r
+            $res .= $this->blogIntro($post, false);\r
         }\r
 \r
         return $this->htmlElement($res, 'div', ['class' => 'blog-index']);\r
     }\r
-\r
-    protected function post($post) {\r
-\r
-        $URL = CubeIT_Navigation_Page::generateAutoUri($post, Bootstrap::getBlogPostURLTemplate());\r
-\r
-        $img = $this->view->imageCms($post->getIntroImage(), $post->getTitle(), null, null, ['class' => 'blog-hero-image']);\r
-\r
-        $res  = $this->link($img, $URL);\r
-        $res .= '<br/>';\r
-        $res .= $this->dateTime($post->getPublishDate(), CubeIT_Date::DAY .' '. CubeIT_Date::MONTH_NAME .' '. CubeIT_Date::YEAR);\r
-        $res .= $this->link($this->htmlElement($post->getTitle(), 'h2'), $URL, ['class' => 'news-heading-link']);\r
-        $res .= '<div class="acc">';\r
-        $res .= $this->markupDotclear($post->getExcerpt());\r
-        $res .= '</div>';\r
-        $res .= $this->link(__('Lire la suite'), $URL, ['class' => 'read-more']);\r
-        return $this->htmlElement($res, 'article');\r
-    }\r
 }\r
diff --git a/framework/application/views/helpers/BlogIntro.php b/framework/application/views/helpers/BlogIntro.php
new file mode 100644 (file)
index 0000000..0bd8f9a
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+class Fluidbook_View_Helper_BlogIntro extends CubeIT_View_Helper_Abstract {
+
+    public function blogIntro($post, $is_single = true) {
+
+        $post = $post->unserialize();
+
+        $URL = CubeIT_Navigation_Page::generateAutoUri($post, Bootstrap::getBlogPostURLTemplate());
+
+        // This helper is used in two contexts: the blog index and on the single blog post
+        // In the blog index, the title should be a H2 and have a link on it
+        // In the single post view, the title is a H1 without a link
+        if ($is_single) {
+            $title = $post->getTitle();
+            $title_tag = 'h1';
+        } else {
+            $title = $this->link($post->getTitle(), $URL);
+            $title_tag = 'h2';
+        }
+
+        // Blog intro content structure
+        $res  = '<div class="grid">';
+        $res .= '<div class="blog-intro-content">';
+        $res .= $this->dateTime(
+            $post->getPublishDate(),
+            CubeIT_Date::DAY .' '. CubeIT_Date::MONTH_NAME .' '. CubeIT_Date::YEAR,
+            ['class' => 'blog-intro-date']
+        );
+        $res .= $this->title($title, $title_tag, ['class' => 'blog-intro-title']);
+        $res .= $this->markupDotclear($post->getExcerpt(), [], ['class' => 'blog-intro-excerpt']);
+        $res .= '</div>'; // .col-2
+        $res .= '</div>'; // .grid
+
+        // Prepare data and attributes for use in the backgroundBlock helper
+        $data = [
+            'title' => $post->getTitle(),
+        ];
+
+        $attributes = [
+            'class' => ['content-wrapper', 'blog-intro', $post->getIntroStyle()],
+            'style' => "background-image:linear-gradient(135deg, {$post->getIntroGradientStart()}, {$post->getIntroGradientEnd()});",
+        ];
+
+        if ($post->getIntroImage()) {
+            $data['bg_image'] = $post->getIntroImage();
+        }
+
+        return $this->backgroundBlock($res, $data, $attributes);
+    }
+
+}
index 43315da3e11112a053c53fd14453c3c8d6b0769c..40bce096dd25c5900171caddfcfd816118290536 100644 (file)
@@ -23,11 +23,11 @@ class Fluidbook_View_Helper_ContactFooter extends CubeIT_View_Helper_Abstract {
 \r
                $res = $this->htmlElement($res, 'div', array('class' => 'col-2'));\r
                $res = $this->htmlElement($res, 'div', array('class' => 'grid'));\r
-               $res = $this->backgroundBlock($res, $cf, array('content-wrapper'));\r
+               $res = $this->backgroundBlock($res, $cf, ['class' => ['content-wrapper']]);\r
 \r
                return $this->htmlElement($res, 'section', array(\r
                        'class' => 'contactFooter section',\r
                        'data-themecolor' => '#8aab41', // Todo: possibly set this via the admin?\r
                        'data-section-name' => 'contact', 'data-puce' => __('Contact')));\r
        }\r
-}
\ No newline at end of file
+}\r
index 2add350f9fecb033e31bc08d0fdfd85e2f7a8d97..1fb2727d05bab4f90e1f1fa7aaf09974f96cac68 100644 (file)
@@ -20,7 +20,7 @@ class Fluidbook_View_Helper_HomeLayer extends CubeIT_View_Helper_Abstract
 \r
         $content = $this->htmlElement($content, 'div', array('class' => 'content-inner'));\r
         $content .= $outerContent;\r
-        $content = $this->backgroundBlock($content, $this->data, array('content-wrapper', 'no-shrink', 'fullheight'));\r
+        $content = $this->backgroundBlock($content, $this->data, ['class' => ['content-wrapper', 'no-shrink', 'fullheight']]);\r
 \r
         return $this->htmlElement($content, 'section', $attributes);\r
     }\r
index f6c5470c28eb4d76c48b35f5ba0d276c5e03ec92..bc694b429a92dcba8d30e03236ed1ed526064c76 100644 (file)
@@ -1,4 +1,11 @@
-<?php // TODO: blog post detail view ?>
-<pre style="margin-top: 200px;">
-    <?php print_r($this->post); ?>
-</pre>
+<?php
+
+$attributes = [
+        'class' => 'blog-post-single',
+        'data-header-theme' => $this->post->getIntroStyle(),
+];
+
+echo $this->htmlElement($this->blogIntro($this->post), 'section', $attributes);
+echo $this->blogBody($this->post);
+echo $this->contactFooter();
+
diff --git a/less/610-blog.less b/less/610-blog.less
new file mode 100644 (file)
index 0000000..43e1f2c
--- /dev/null
@@ -0,0 +1,88 @@
+@import "000-imports";
+
+.blog-index {
+  padding: 144px 0;
+
+  @media @m1280 {
+    padding: 86px 0;
+  }
+  @media @m900 {
+    padding: 96px 0;
+  }
+  @media @m768 {
+    padding: 68px 0;
+  }
+
+}
+
+
+.blog-intro {
+  display: flex;
+  align-items: center;
+  padding: 0 !important;
+
+  &.light {
+    color: #fff;
+  }
+
+  &.dark {
+    color: @color-text;
+  }
+
+  &-content {
+    flex-basis: 40%;
+  }
+
+  &-date {
+    display: block;
+    margin-bottom: 0.5em;
+  }
+
+  &-title {
+    color: currentColor !important;
+    font-size: 60px !important;
+
+    &:after {
+      background-color: currentColor !important;
+    }
+
+    a {
+      color: currentColor;
+      text-decoration: none;
+
+      &:hover {
+        color: currentColor;
+      }
+    }
+  }
+
+  &-excerpt {
+    font-size: 15px;
+    line-height: 1.7;
+  }
+
+  .picture {
+    @media @m1024 {
+      display: none;
+    }
+  }
+
+}
+
+
+.blog-post-body {
+  max-width: 1008px;
+  margin: 0 auto;
+  font-size: 24px;
+  line-height: 1.67;
+
+  > * + * {
+    margin-top: 1.5em;
+  }
+
+  img {
+    max-width: 100%;
+    height: auto;
+  }
+
+}