]> _ Git - fluidbook-v3.git/commitdiff
WIP #3641 @9
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 13 May 2020 19:43:35 +0000 (19:43 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 13 May 2020 19:43:35 +0000 (19:43 +0000)
12 files changed:
framework/application/Bootstrap.php
framework/application/controllers/BlogpostController.php [new file with mode: 0644]
framework/application/forms/CMS/Blog.php [new file with mode: 0644]
framework/application/forms/CMS/Element/BlogPosts.php [new file with mode: 0644]
framework/application/forms/CMS/Sub/Blog/Post.php [new file with mode: 0644]
framework/application/layouts/scripts/layout.phtml
framework/application/models/Blog.php [new file with mode: 0644]
framework/application/views/helpers/BlogIndex.php [new file with mode: 0644]
framework/application/views/scripts/admin/index.phtml
framework/application/views/scripts/blogpost/index.phtml [new file with mode: 0644]
framework/application/views/scripts/templates/blog.phtml [new file with mode: 0644]
js/010-admin.js

index d032ce75c7fe9f2aa7c5a61f17fde71566e50ad9..ebb08cdee98c03a6f197b3e85b59c616dd5f9b91 100644 (file)
@@ -23,11 +23,60 @@ class Bootstrap extends CubeIT_Bootstrap {
                $templates['landingcampaign'] = 'Landing Campagne (Intro + formulaire)';
                $templates['agences'] = 'Agences';
                $templates['faq'] = 'FAQ';
+               $templates['blog'] = 'Blog';
                $templates = array_merge($templates, parent::getCMSTemplates());
                return $templates;
        }
 
-       public function _initRouter($initCms = true, $standard = true) {
+    protected function _makeNavigationOnePage(&$navigation, $r, $t, $isAdmin, $locale = false) {
+        $page = parent::_makeNavigationOnePage($navigation, $r, $t, $isAdmin, $locale);
+
+        if (!$page) return;
+
+        if ($page->getTemplate() === 'blog') {
+            $this->addBlogPages($page, $locale, $isAdmin);
+        }
+    }
+
+    // URL template used for blog pages
+    public static function getBlogPostURLTemplate() {
+        return '/blog/%title%'; // Important: must have leading slash or pages will show as not found!
+    }
+
+    /* @param CubeIT_Navigation_Page_Locale $page */
+    protected function addBlogPages($page, $locale, $isAdmin) {
+        //$datas = $this->getCMSDatasOfNavigationPage($page);
+
+        // How the URLs should be formed for the news articles
+        $URL_template = self::getBlogPostURLTemplate();
+
+        $db = Zend_Db_Table::getDefaultAdapter();
+        $s = $db->select()->from('blog')
+            ->order('id ASC');
+        $q = $s->query();
+
+        while ($r = $q->fetch()) {
+
+            $online = true;
+            $pageTitle = $r->title;
+
+            $p = new CubeIT_Navigation_Page_Locale();
+            $p->setController('Blogpost');
+            $p->setId('blog/' . $r->id);
+            $p->setAutoUri($r, $URL_template);
+            $p->setSitemap($online);
+            $p->setTitle($pageTitle);
+            $p->setEditable(false);
+            $p->setParams(['post_id' => $r->id]);
+            $p->setOnline($online);
+            $p->setDomain($page->getDomain());
+            $p->setLabel($pageTitle);
+            $page->addPage($p);
+        }
+    }
+
+
+    public function _initRouter($initCms = true, $standard = true) {
                profile(__FILE__, __LINE__, 'Init Router');
                $router = parent::_initRouter($initCms, $standard);
                $router->addStaticRoute('15000', 'landing', 'quinzemille');
diff --git a/framework/application/controllers/BlogpostController.php b/framework/application/controllers/BlogpostController.php
new file mode 100644 (file)
index 0000000..dcb2f79
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+class BlogpostController extends CubeIT_Controller_PageController {
+
+    public function indexAction() {
+
+        $this->view->headScript()->addScriptAndStyle('blog-post');
+
+        //$parent = $this->view->currentPage->getParent();
+        //$parent_data = $this->getBootstrap()->getCMSDatasOfNavigationPage($parent);
+        //$this->view->datas = $parent_data;
+
+
+        $model = Fluidbook_Model_Blog::factory()
+            ->order('publish_date DESC')
+            ->where('id = ?', $this->getRequest()
+                ->getParam('post_id'));
+        $post = $model->find();
+
+        if (count($post) < 1) {
+            $this->_404();
+            return;
+        }
+
+        // Get the first and only array item
+        $post = reset($post);
+
+        $this->view->post = $post;
+        $this->view->headTitle($post->getTitle(), 'SET');
+    }
+
+}
diff --git a/framework/application/forms/CMS/Blog.php b/framework/application/forms/CMS/Blog.php
new file mode 100644 (file)
index 0000000..8e1ddeb
--- /dev/null
@@ -0,0 +1,12 @@
+<?php\r
+\r
+class Fluidbook_Form_CMS_Blog extends Fluidbook_Form_CMS_Base {\r
+       public function init() {\r
+               parent::init();\r
+\r
+               $blog = new Fluidbook_Form_CMS_Element_BlogPosts('blog_posts');\r
+               $blog->setLabel('Blog Posts');\r
+               $this->addElement($blog);\r
+\r
+       }\r
+}\r
diff --git a/framework/application/forms/CMS/Element/BlogPosts.php b/framework/application/forms/CMS/Element/BlogPosts.php
new file mode 100644 (file)
index 0000000..73f5178
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+class Fluidbook_Form_CMS_Element_BlogPosts extends CubeIT_Form_Element_List {
+    public function init() {
+        parent::init();
+
+        $this->setBaseForm(new Fluidbook_Form_CMS_Sub_Blog_Post());
+        $this->clearDecorators();
+    }
+
+}
diff --git a/framework/application/forms/CMS/Sub/Blog/Post.php b/framework/application/forms/CMS/Sub/Blog/Post.php
new file mode 100644 (file)
index 0000000..0fa5f96
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model
+{
+
+    public function init() {
+        parent::init();
+
+        $id = new CubeIT_Form_Element_Id();
+        $this->addElement($id);
+
+        $online = new Zend_Form_Element_Checkbox('online');
+        $online->setLabel(__('Published?'));
+        $this->addElement($online);
+
+        $date = new CubeIT_Form_Element_Date('publish_date');
+        $date->setPrecision(Zend_Date::MINUTE);
+        $date->setMinYear('-5');
+        $date->setMaxYear('+1');
+        $date->setLabel(__('Publish Date'));
+        $this->addElement($date);
+
+        $title = new CubeIT_Form_Element_Text('title');
+        $title->setLabel(__('Post Title'));
+        $this->addElement($title);
+
+        $excerpt = new CubeIT_Form_Element_Markitup('excerpt');
+        $excerpt->setLabel(__('Excerpt'));
+        $this->addElement($excerpt);
+
+        $thumbnail = new CubeIT_Form_Element_File_Image('thumbnail');
+        $thumbnail->setLabel(__('Post Thumbnail'));
+        $this->addElement($thumbnail);
+
+        // TODO add content blocks (text + images) based on Cubedesigners case studies content. Also add author reference.
+
+        $this->setListTitle(__('Blog Posts'));
+        $this->setNewTitle(__('New Post'));
+        $this->setEditTitle(__('Edition du post « $title »'));
+        $this->setModel('Fluidbook_Model_Blog');
+        $this->setTitleColumn('title');
+        $this->setAdditionnalColumns(['publish_date', 'online']);
+
+
+    }
+}
index 89de1743ae6cb24ac9f920da75d99aa5977eb310..f30544b8b2a15eed50f5792871e334849c74e055 100644 (file)
@@ -2,6 +2,7 @@
 
 if ($this->acl()->isAllowed('edition')) {
        $this->headScript()->addCommonsAdmin();
+       $this->headScript()->addScriptAndStyle('010-admin');
 }
 
 $this->headMeta()->setViewport('device-width');
diff --git a/framework/application/models/Blog.php b/framework/application/models/Blog.php
new file mode 100644 (file)
index 0000000..5971fb8
--- /dev/null
@@ -0,0 +1,31 @@
+<?php\r
+\r
+class Fluidbook_Model_Blog extends CubeIT_Model_Data_Table\r
+{\r
+    protected static $_table = 'blog';\r
+\r
+    protected $title;\r
+    protected $excerpt;\r
+    protected $thumbnail;\r
+    protected $content;\r
+    protected $publish_date;\r
+    protected $author_id;\r
+    protected $online;\r
+\r
+    protected $_types = [\r
+        'publish_date' => 'date',\r
+    ];\r
+\r
+    public static function getSchema($schema) {\r
+        $table = parent::getSchema($schema);\r
+        $table->addColumn('title', 'string', ['length' => 255]);\r
+        $table->addColumn('excerpt', 'text');\r
+        $table->addColumn('thumbnail', 'text');\r
+        $table->addColumn('content', 'text');\r
+        $table->addColumn('publish_date', 'datetime');\r
+        $table->addColumn('author_id', 'integer', ['unsigned' => true]);\r
+        $table->addColumn('online', 'boolean', ['default' => 1]);\r
+        return $table;\r
+    }\r
+\r
+}\r
diff --git a/framework/application/views/helpers/BlogIndex.php b/framework/application/views/helpers/BlogIndex.php
new file mode 100644 (file)
index 0000000..383d64c
--- /dev/null
@@ -0,0 +1,39 @@
+<?php\r
+\r
+class Fluidbook_View_Helper_BlogIndex extends CubeIT_View_Helper_Abstract {\r
+    /**\r
+     * @return string\r
+     */\r
+    public function blogIndex() {\r
+\r
+        $posts = Fluidbook_Model_Blog::factory()->order('publish_date DESC')->find();\r
+\r
+        $res = '';\r
+\r
+        foreach ($posts as $post) {\r
+            $res .= $this->post($post);\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 = $post->getThumbnail(247, 247, 'blog-featured-image');\r
+\r
+        if (!$img) {\r
+            $img = '<div class="blog-featured-image blog-featured-image-empty"></div>';\r
+        }\r
+\r
+        $res  = $this->link($img, $URL);\r
+        $res .= $this->dateTime($post->getPublishDate(), CubeIT_Date::DAY . '/' . CubeIT_Date::MONTH . '/' . 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
index 99f13dabe59eb687bd92c7e4a469769382ad6bf7..0422fd76240bc36393e9adf80facb10bc31accc6 100644 (file)
@@ -5,4 +5,4 @@ $this->headLink()->appendStylesheet('/CubeIT/less/admin/common.less', 'all');
 $this->headLink()->appendStylesheet('/less/010-admin.less', 'all');\r
 echo '<div id="message"></div>';\r
 echo $this->form;\r
-echo '</div>';
\ No newline at end of file
+echo '</div>';\r
diff --git a/framework/application/views/scripts/blogpost/index.phtml b/framework/application/views/scripts/blogpost/index.phtml
new file mode 100644 (file)
index 0000000..4b9cb78
--- /dev/null
@@ -0,0 +1,4 @@
+<?php // TODO: blog post detail view ?>
+<pre>
+    <?php print_r($this->post); ?>
+</pre>
diff --git a/framework/application/views/scripts/templates/blog.phtml b/framework/application/views/scripts/templates/blog.phtml
new file mode 100644 (file)
index 0000000..26853e9
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+$this->headScript()->addScriptAndStyle('610-blog');
+
+echo $this->introBlock($this->intro, '');
+echo $this->blogIndex();
+echo $this->contactFooter();
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c898d2938b0d4710790654c910f4744995535e3c 100644 (file)
@@ -0,0 +1 @@
+// Todo: adapt code from cubedesigners-v6/js/admin.js to have the custom multi-subform with different fields shown / hidden depending on the option selected