Skip to content

Commit

Permalink
Merge pull request #2 from dappur/v4.x
Browse files Browse the repository at this point in the history
V4.x
  • Loading branch information
edwardteach42 authored Jul 13, 2019
2 parents 453ca99 + 18e0a67 commit 1e32427
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Changelog

## [Unreleased]
### No Changes
- No Changes

## [4.0.1] - 2019-07-12
### Fixed
- Blog post status was not toggling
- Code cleanup

## [4.0.0]
### Notes
Expand Down Expand Up @@ -67,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
Expand Down
75 changes: 40 additions & 35 deletions app/src/Dappurware/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +13,7 @@ class Blog extends Dappurware
protected $videoId;
protected $publishAt;

/** @SuppressWarnings(PHPMD.StaticAccess) */
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -67,14 +61,15 @@ 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;
}

$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();
Expand All @@ -87,14 +82,16 @@ public function addPost()
return false;
}

/** @SuppressWarnings(PHPMD.StaticAccess) */
public function updatePost($postId)
{
$this->blogEdit = true;

$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;
Expand All @@ -115,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'];
Expand All @@ -135,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();
Expand All @@ -153,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()) {
Expand All @@ -165,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;
Expand All @@ -178,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;
Expand All @@ -194,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.'
Expand All @@ -210,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);
}
Expand All @@ -224,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;
Expand All @@ -247,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);
}
Expand All @@ -266,23 +269,24 @@ 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;
}
continue;
}

// 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()) {
Expand All @@ -293,6 +297,7 @@ private function processTags()
}
}

/** @SuppressWarnings(PHPMD.StaticAccess) */
private function processVideo()
{
$requestParams = $this->container->request->getParams();
Expand All @@ -303,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
Expand Down
18 changes: 11 additions & 7 deletions app/src/TwigExtension/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions app/src/TwigExtension/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<img src="' . $url . '"';
foreach ($atts as $key => $val) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/TwigExtension/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1e32427

Please sign in to comment.