From f1a9f335ad608cca7253fdf2a655b46a61de2b81 Mon Sep 17 00:00:00 2001 From: "stephen@cubedesigners.com" Date: Wed, 13 May 2020 19:43:35 +0000 Subject: [PATCH] WIP #3641 @9 --- framework/application/Bootstrap.php | 51 ++++++++++++++++++- .../controllers/BlogpostController.php | 32 ++++++++++++ framework/application/forms/CMS/Blog.php | 12 +++++ .../forms/CMS/Element/BlogPosts.php | 11 ++++ .../application/forms/CMS/Sub/Blog/Post.php | 46 +++++++++++++++++ .../application/layouts/scripts/layout.phtml | 1 + framework/application/models/Blog.php | 31 +++++++++++ .../application/views/helpers/BlogIndex.php | 39 ++++++++++++++ .../views/scripts/admin/index.phtml | 2 +- .../views/scripts/blogpost/index.phtml | 4 ++ .../views/scripts/templates/blog.phtml | 7 +++ js/010-admin.js | 1 + 12 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 framework/application/controllers/BlogpostController.php create mode 100644 framework/application/forms/CMS/Blog.php create mode 100644 framework/application/forms/CMS/Element/BlogPosts.php create mode 100644 framework/application/forms/CMS/Sub/Blog/Post.php create mode 100644 framework/application/models/Blog.php create mode 100644 framework/application/views/helpers/BlogIndex.php create mode 100644 framework/application/views/scripts/blogpost/index.phtml create mode 100644 framework/application/views/scripts/templates/blog.phtml diff --git a/framework/application/Bootstrap.php b/framework/application/Bootstrap.php index d032ce7..ebb08cd 100644 --- a/framework/application/Bootstrap.php +++ b/framework/application/Bootstrap.php @@ -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 index 0000000..dcb2f79 --- /dev/null +++ b/framework/application/controllers/BlogpostController.php @@ -0,0 +1,32 @@ +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 index 0000000..8e1ddeb --- /dev/null +++ b/framework/application/forms/CMS/Blog.php @@ -0,0 +1,12 @@ +setLabel('Blog Posts'); + $this->addElement($blog); + + } +} diff --git a/framework/application/forms/CMS/Element/BlogPosts.php b/framework/application/forms/CMS/Element/BlogPosts.php new file mode 100644 index 0000000..73f5178 --- /dev/null +++ b/framework/application/forms/CMS/Element/BlogPosts.php @@ -0,0 +1,11 @@ +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 index 0000000..0fa5f96 --- /dev/null +++ b/framework/application/forms/CMS/Sub/Blog/Post.php @@ -0,0 +1,46 @@ +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']); + + + } +} diff --git a/framework/application/layouts/scripts/layout.phtml b/framework/application/layouts/scripts/layout.phtml index 89de174..f30544b 100644 --- a/framework/application/layouts/scripts/layout.phtml +++ b/framework/application/layouts/scripts/layout.phtml @@ -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 index 0000000..5971fb8 --- /dev/null +++ b/framework/application/models/Blog.php @@ -0,0 +1,31 @@ + 'date', + ]; + + public static function getSchema($schema) { + $table = parent::getSchema($schema); + $table->addColumn('title', 'string', ['length' => 255]); + $table->addColumn('excerpt', 'text'); + $table->addColumn('thumbnail', 'text'); + $table->addColumn('content', 'text'); + $table->addColumn('publish_date', 'datetime'); + $table->addColumn('author_id', 'integer', ['unsigned' => true]); + $table->addColumn('online', 'boolean', ['default' => 1]); + return $table; + } + +} diff --git a/framework/application/views/helpers/BlogIndex.php b/framework/application/views/helpers/BlogIndex.php new file mode 100644 index 0000000..383d64c --- /dev/null +++ b/framework/application/views/helpers/BlogIndex.php @@ -0,0 +1,39 @@ +order('publish_date DESC')->find(); + + $res = ''; + + foreach ($posts as $post) { + $res .= $this->post($post); + } + + return $this->htmlElement($res, 'div', ['class' => 'blog-index']); + } + + protected function post($post) { + + $URL = CubeIT_Navigation_Page::generateAutoUri($post, Bootstrap::getBlogPostURLTemplate()); + + $img = $post->getThumbnail(247, 247, 'blog-featured-image'); + + if (!$img) { + $img = ''; + } + + $res = $this->link($img, $URL); + $res .= $this->dateTime($post->getPublishDate(), CubeIT_Date::DAY . '/' . CubeIT_Date::MONTH . '/' . CubeIT_Date::YEAR); + $res .= $this->link($this->htmlElement($post->getTitle(), 'h2'), $URL, ['class' => 'news-heading-link']); + $res .= '
'; + $res .= $this->markupDotclear($post->getExcerpt()); + $res .= '
'; + $res .= $this->link(__('Lire la suite'), $URL, ['class' => 'read-more']); + return $this->htmlElement($res, 'article'); + } +} diff --git a/framework/application/views/scripts/admin/index.phtml b/framework/application/views/scripts/admin/index.phtml index 99f13da..0422fd7 100644 --- a/framework/application/views/scripts/admin/index.phtml +++ b/framework/application/views/scripts/admin/index.phtml @@ -5,4 +5,4 @@ $this->headLink()->appendStylesheet('/CubeIT/less/admin/common.less', 'all'); $this->headLink()->appendStylesheet('/less/010-admin.less', 'all'); echo '
'; echo $this->form; -echo ''; \ No newline at end of file +echo ''; diff --git a/framework/application/views/scripts/blogpost/index.phtml b/framework/application/views/scripts/blogpost/index.phtml new file mode 100644 index 0000000..4b9cb78 --- /dev/null +++ b/framework/application/views/scripts/blogpost/index.phtml @@ -0,0 +1,4 @@ + +
+    post); ?>
+
diff --git a/framework/application/views/scripts/templates/blog.phtml b/framework/application/views/scripts/templates/blog.phtml new file mode 100644 index 0000000..26853e9 --- /dev/null +++ b/framework/application/views/scripts/templates/blog.phtml @@ -0,0 +1,7 @@ +headScript()->addScriptAndStyle('610-blog'); + +echo $this->introBlock($this->intro, ''); +echo $this->blogIndex(); +echo $this->contactFooter(); diff --git a/js/010-admin.js b/js/010-admin.js index e69de29..c898d29 100644 --- a/js/010-admin.js +++ b/js/010-admin.js @@ -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 -- 2.39.5