From 022e48e76a04f8dce8d8f2b1db4b8ba2ccdc41f5 Mon Sep 17 00:00:00 2001 From: Edward Teach Date: Fri, 8 Feb 2019 14:51:49 -0800 Subject: [PATCH 1/3] blog not toggling --- CHANGELOG.md | 3 ++- app/src/Dappurware/Blog.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfec17e..be29626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog ## [Unreleased] -### No Changes +### Fixed +- Blog post status was not toggling ## [4.0.0] ### Notes diff --git a/app/src/Dappurware/Blog.php b/app/src/Dappurware/Blog.php index bc55663..e490560 100644 --- a/app/src/Dappurware/Blog.php +++ b/app/src/Dappurware/Blog.php @@ -67,6 +67,7 @@ public function addPost() $newPost->category_id = $this->categoryId; $newPost->user_id = $this->container->auth->check()->id; $newPost->publish_at = $this->publishAt; + $newPost->status = 0; if ($requestParams['status']) { $newPost->status = 1; } From 0ce2de97a8da06f45298c3d98ae800b631f5ab9f Mon Sep 17 00:00:00 2001 From: Jeff Thomas Date: Fri, 12 Jul 2019 14:54:02 -0700 Subject: [PATCH 2/3] code cleanup --- CHANGELOG.md | 1 + app/src/Dappurware/Blog.php | 74 ++++++++++++++++-------------- app/src/TwigExtension/Asset.php | 18 +++++--- app/src/TwigExtension/Gravatar.php | 4 +- app/src/TwigExtension/Menus.php | 4 ++ 5 files changed, 57 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be29626..035e9ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Fixed - Blog post status was not toggling +- Code cleanup ## [4.0.0] ### Notes diff --git a/app/src/Dappurware/Blog.php b/app/src/Dappurware/Blog.php index e490560..e293805 100644 --- a/app/src/Dappurware/Blog.php +++ b/app/src/Dappurware/Blog.php @@ -2,17 +2,8 @@ namespace Dappur\Dappurware; -use Carbon\Carbon; -use Dappur\Dappurware\Utils; -use Dappur\Dappurware\VideoParser as VP; -use Dappur\Model\BlogCategories; -use Dappur\Model\BlogPosts; -use Dappur\Model\BlogPostsTags; -use Dappur\Model\BlogTags; use Interop\Container\ContainerInterface; -use Respect\Validation\Validator as V; -/** @SuppressWarnings(PHPMD.StaticAccess) */ class Blog extends Dappurware { protected $categoryId; @@ -22,6 +13,7 @@ class Blog extends Dappurware protected $videoId; protected $publishAt; + /** @SuppressWarnings(PHPMD.StaticAccess) */ public function __construct(ContainerInterface $container) { parent::__construct($container); @@ -30,9 +22,11 @@ public function __construct(ContainerInterface $container) $this->parsedTags = null; $this->videoProvider = null; $this->videoId = null; - $this->publishAt = Carbon::now(); + $this->publishAt = \Carbon\Carbon::now(); + $this->utils = new Dappur\Dappurware\Utils; } + /** @SuppressWarnings(PHPMD.StaticAccess) */ public function addPost() { $requestParams = $this->container->request->getParams(); @@ -53,10 +47,10 @@ public function addPost() $this->processVideo(); // Process Publish At Date - $this->publishAt = Carbon::parse($requestParams['publish_at']); + $this->publishAt = \Carbon\Carbon::parse($requestParams['publish_at']); if ($this->validator->isValid()) { - $newPost = new BlogPosts; + $newPost = new \Dappur\Model\BlogPosts; $newPost->title = $requestParams['title']; $newPost->description = $requestParams['description']; $newPost->slug = $this->slug; @@ -75,7 +69,7 @@ public function addPost() $newPost->save(); foreach ($this->parsedTags as $tag) { - $addTag = new BlogPostsTags; + $addTag = new \Dappur\Model\BlogPostsTags; $addTag->post_id = $newPost->id; $addTag->tag_id = $tag; $addTag->save(); @@ -88,6 +82,7 @@ public function addPost() return false; } + /** @SuppressWarnings(PHPMD.StaticAccess) */ public function updatePost($postId) { $this->blogEdit = true; @@ -95,7 +90,8 @@ public function updatePost($postId) $requestParams = $this->container->request->getParams(); //Check Post - $post = BlogPosts::find($postId); + $post = new \Dappur\Model\BlogPosts::find($postId); + $post = $post->find($postId); if (!$post) { return false; @@ -116,7 +112,7 @@ public function updatePost($postId) $this->processVideo(); // Process Publish At Date - $this->publishAt = Carbon::parse($requestParams['publish_at']); + $this->publishAt = \Carbon\Carbon::parse($requestParams['publish_at']); if ($this->validator->isValid()) { $post->title = $requestParams['title']; @@ -136,10 +132,10 @@ public function updatePost($postId) $post->save(); //Delete Existing Post Tags - BlogPostsTags::where('post_id', $post->id)->delete(); + \Dappur\Model\BlogPostsTags::where('post_id', $post->id)->delete(); foreach ($this->parsedTags as $tag) { - $addTag = new BlogPostsTags; + $addTag = new \Dappur\Model\BlogPostsTags; $addTag->post_id = $post->id; $addTag->tag_id = $tag; $addTag->save(); @@ -154,7 +150,8 @@ public function updatePost($postId) public function delete() { - $post = BlogPosts::find($this->container->request->getParam('post_id')); + $post = new \Dappur\Model\BlogPosts; + $post = $post->find($this->container->request->getParam('post_id')); if ($post) { if ($post->delete()) { @@ -166,7 +163,8 @@ public function delete() public function publish() { - $post = BlogPosts::find($this->container->request->getParam('post_id')); + $post = new \Dappur\Model\BlogPosts; + $post = $post->find($this->container->request->getParam('post_id')); if ($post) { $post->status = 1; @@ -179,7 +177,8 @@ public function publish() public function unpublish() { - $post = BlogPosts::find($this->container->request->getParam('post_id')); + $post = new \Dappur\Model\BlogPosts; + $post = $post->find($this->container->request->getParam('post_id')); if ($post) { $post->status = 0; @@ -195,14 +194,14 @@ private function validateTitleDesc($postId = null) //Validate Data $validateData = array( 'title' => array( - 'rules' => V::length(6, 255)->alnum('\',.?!@#$%&*()-_"'), + 'rules' => \Respect\Validation\Validator::length(6, 255)->alnum('\',.?!@#$%&*()-_"'), 'messages' => array( 'length' => 'Must be between 6 and 255 characters.', 'alnum' => 'Invalid Characters Only \',.?!@#$%&*()-_" are allowed.' ) ), 'description' => array( - 'rules' => V::length(6, 255)->alnum('\',.?!@#$%&*()-_"'), + 'rules' => \Respect\Validation\Validator::length(6, 255)->alnum('\',.?!@#$%&*()-_"'), 'messages' => array( 'length' => 'Must be between 6 and 255 characters.', 'alnum' => 'Invalid Characters Only \',.?!@#$%&*()-_" are allowed.' @@ -211,7 +210,8 @@ private function validateTitleDesc($postId = null) ); $this->validator->validate($this->container->request, $validateData); - $checkTitle = BlogPosts::where('title', $this->container->request->getParam('title')); + $checkTitle = new \Dappur\Model\BlogPosts; + $checkTitle = $checkTitle->where('title', $this->container->request->getParam('title')); if ($postId) { $checkTitle = $checkTitle->where('id', '!=', $postId); } @@ -225,19 +225,20 @@ private function processCategory() $categoryId = $this->container->request->getParam('category'); // Check if category exists by id - $categoryCheck = BlogCategories::find($categoryId); + $categoryCheck = new \Dappur\Model\BlogCategories; + $categoryCheck = $categoryCheck->find($categoryId); if (!$categoryCheck) { // Check if category exists by name - $checkCat = BlogCategories::where('name', $categoryId)->first(); + $checkCat = \Dappur\Model\BlogCategories::where('name', $categoryId)->first(); if ($checkCat) { $categoryId = $checkCat->category_id; } // Add new category if not exists - $addCategory = new BlogCategories; + $addCategory = new \Dappur\Model\BlogCategories; $addCategory->name = $categoryId; - $addCategory->slug = Utils::slugify($categoryId); + $addCategory->slug = $this->utils->slugify($categoryId); $addCategory->status = 1; $addCategory->save(); $categoryId = $addCategory->id; @@ -248,8 +249,9 @@ private function processCategory() private function processSlug($postId = null) { - $slug = Utils::slugify($this->container->request->getParam('title')); - $checkSlug = BlogPosts::where('slug', $slug); + $slug = $this->utils->slugify($this->container->request->getParam('title')); + $checkSlug = new \Dappur\Model\BlogPosts; + $checkSlug = $checkSlug->where('slug', $slug); if ($postId) { $checkSlug = $checkSlug->where('id', '!=', $postId); } @@ -267,7 +269,8 @@ private function processTags() foreach ($this->container->request->getParam('tags') as $value) { // Check if Already Numeric if (is_numeric($value)) { - $check = BlogTags::find($value); + $check = new \Dappur\Model\BlogTags; + $check = $check->find($value); if ($check) { $this->parsedTags[] = $value; } @@ -275,15 +278,15 @@ private function processTags() } // Check if slug already exists - $slug = Utils::slugify($value); - $slugCheck = BlogTags::where('slug', '=', $slug)->first(); + $slug = $this->utils->slugify($value); + $slugCheck = \Dappur\Model\BlogTags::where('slug', '=', $slug)->first(); if ($slugCheck) { $this->parsedTags[] = $slugCheck->id; continue; } // Add New Tag To Database - $newTag = new BlogTags; + $newTag = new \Dappur\Model\BlogTags; $newTag->name = $value; $newTag->slug = $slug; if ($newTag->save()) { @@ -294,6 +297,7 @@ private function processTags() } } + /** @SuppressWarnings(PHPMD.StaticAccess) */ private function processVideo() { $requestParams = $this->container->request->getParams(); @@ -304,8 +308,8 @@ private function processVideo() $this->videoId = $requestParams['video_id']; } if (!empty($requestParams['video_url'])) { - $this->videoProvider = VP::getVideoId($requestParams['video_url']); - $this->videoId = VP::getVideoId($requestParams['video_url']); + $this->videoProvider = Dappur\Dappurware\VideoParser::getVideoId($requestParams['video_url']); + $this->videoId = Dappur\Dappurware\VideoParser::getVideoId($requestParams['video_url']); } // Check Featured Image diff --git a/app/src/TwigExtension/Asset.php b/app/src/TwigExtension/Asset.php index 3238bbd..5fe6b3a 100644 --- a/app/src/TwigExtension/Asset.php +++ b/app/src/TwigExtension/Asset.php @@ -4,25 +4,29 @@ use Psr\Http\Message\RequestInterface; -class Asset extends \Twig_Extension { - +class Asset extends \Twig_Extension +{ protected $request; - public function __construct(RequestInterface $request) { + public function __construct(RequestInterface $request) + { $this->request = $request; } - public function getName() { + public function getName() + { return 'asset'; } - public function getFunctions() { + public function getFunctions() + { return [ new \Twig_SimpleFunction('asset', [$this, 'asset']) ]; } - public function asset($path) { + public function asset($path) + { return '/asset?path=' . $path; } -} \ No newline at end of file +} diff --git a/app/src/TwigExtension/Gravatar.php b/app/src/TwigExtension/Gravatar.php index acd4991..3027f44 100644 --- a/app/src/TwigExtension/Gravatar.php +++ b/app/src/TwigExtension/Gravatar.php @@ -29,11 +29,11 @@ public function getFunctions() * @return String containing either just a URL or a complete image tag * @source https://gravatar.com/site/implement/images/php/ */ - public function gravatar($email, $s = 160, $d = 'mp', $r = 'g', $img = false, $atts = array()) + public function gravatar($email, $size = 160, $default = 'mp', $rating = 'g', $img = null, $atts = array()) { $url = 'https://www.gravatar.com/avatar/'; $url .= md5(strtolower(trim($email))); - $url .= "?s=$s&d=$d&r=$r"; + $url .= "?s=$size&d=$default&r=$rating"; if ($img) { $url = ' $val) { diff --git a/app/src/TwigExtension/Menus.php b/app/src/TwigExtension/Menus.php index 1248e68..0dbc663 100644 --- a/app/src/TwigExtension/Menus.php +++ b/app/src/TwigExtension/Menus.php @@ -36,6 +36,10 @@ public function getMenu($menuId) return $menu; } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ private function validateMenu($menu) { $user = $this->container->auth->check(); From 18e0a676f606252d54c25f23b23243eec1a0fba5 Mon Sep 17 00:00:00 2001 From: Jeff Thomas Date: Fri, 12 Jul 2019 20:53:26 -0700 Subject: [PATCH 3/3] prepared for release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 035e9ce..263cad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +- No Changes + +## [4.0.1] - 2019-07-12 ### Fixed - Blog post status was not toggling - Code cleanup @@ -69,7 +72,8 @@ I am bumping the version number on on Dappurware for this release to v3.0.0. Th - Separated Dappurware from the framework. -[Unreleased]: https://github.com/dappur/dappurware/compare/v4.0.0...HEAD +[Unreleased]: https://github.com/dappur/dappurware/compare/v4.0.1...HEAD +[4.0.1]: https://github.com/dappur/dappurware/compare/v4.0.0...v4.0.1 [4.0.0]: https://github.com/dappur/dappurware/compare/v3.0.0...v4.0.0 [3.0.0]: https://github.com/dappur/dappurware/compare/v1.1.2...v3.0.0 [1.1.2]: https://github.com/dappur/dappurware/compare/v1.1.1...v1.1.2