Skip to content

Commit

Permalink
Merge pull request #2117 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
LuckyCyborg authored Dec 26, 2018
2 parents f05e8d8 + 9a8bd69 commit b569c34
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 72 deletions.
4 changes: 2 additions & 2 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
/**
* The Website URL.
*/
'url' => 'http://www.novaframework.dev/',
'url' => 'http://www.novaframework.local/',

/**
* The Administrator's E-mail Address.
*/
'email' => 'admin@novaframework.dev',
'email' => 'admin@novaframework.local',

/**
* The Website Path.
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/

'from' => array(
'address' => 'admin@novaframework.dev',
'address' => 'admin@novaframework.local',
'name' => 'The Nova Staff',
),

Expand Down
4 changes: 2 additions & 2 deletions app/Config/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'author' => array(
'name' => 'John Doe',
'email' => 'john.doe@novaframework.dev',
'homepage' => 'http://novaframework.dev',
'email' => 'john.doe@novaframework.local',
'homepage' => 'http://novaframework.local',
),

//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '4.0.94');
define('VERSION', '4.0.95');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
2 changes: 1 addition & 1 deletion modules/Contacts/Database/Seeds/ContactsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function run()
$contact = Contact::create(array(
'id' => 1,
'name' => 'Site Contact',
'email' => 'admin@novaframework.dev',
'email' => 'admin@novaframework.local',
'path' => 'content/contact-us',
'description' => 'The default site-wide Contact',

Expand Down
2 changes: 1 addition & 1 deletion modules/Content/Controllers/Admin/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function itemsOrder(Request $request, $id)
);

// Invalidate the cached menu data.
Cache::forget('content.menus.main_menu');
Cache::forget('content.menus.' .$taxonomy->slug);

return Redirect::back()->with('success', __d('content', 'The Menu Items order was successfully updated.'));
}
Expand Down
4 changes: 2 additions & 2 deletions modules/Content/Database/Seeds/CommentsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function run()
'id' => 1,
'post_id' => $post->id,
'author' => 'A Nova Commenter',
'author_email' => 'rookie@novaframework.dev',
'author_url' => 'https://novaframework.dev',
'author_email' => 'rookie@novaframework.local',
'author_url' => 'https://novaframework.local',
'author_ip' => '',
'content' => 'Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Expand Down
125 changes: 68 additions & 57 deletions modules/Platform/Support/EventedMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getItems($name, UserInterface $user, $url, array $payload = arra

$pattern = preg_quote($itemUrl, '#');

if (($itemUrl == $url) || (preg_match('#^' .$pattern .'/page/[0-9]+$#', $url) === 1)) {
if (($itemUrl === $url) || (preg_match('#^' .$pattern .'/page/[0-9]+$#', $url) === 1)) {
$path = $item['path'];
}
}
Expand All @@ -101,11 +101,53 @@ public function getItems($name, UserInterface $user, $url, array $payload = arra
return $this->prepareItems($items, $path, $url);
}

/**
* Prepare the given menu items.
*
* @param array $items
* @param string $path
* @param string $url
* @param string $pageName
* @return array
*/
protected function prepareItems(array $items, $path, $url)
{
foreach ($items as &$item) {
$pattern = preg_quote($itemUrl = $item['url'], '#');

if (($itemUrl === $url) || Str::startsWith($path, $item['path'])) {
$active = true;
} else if (preg_match('#^' .$pattern .'/page/[0-9]+$#', $url) === 1) {
$active = true;
} else {
$active = false;
}

$item['active'] = $active;

if (! empty($children = $item['children'])) {
$item['children'] = $this->prepareItems($children, $path, $url);
}
}

// Sort the menu items by their weight and title.
usort($items, function ($a, $b)
{
if ($a['weight'] === $b['weight']) {
return strcmp($a['title'], $b['title']);
}

return ($a['weight'] < $b['weight']) ? -1 : 1;
});

return $items;
}

/**
* Determine if the menu item usage is allowed by the specified User Roles.
*
* @param array $item
* @param mixed $user
* @param \Nova\Auth\UserInterface $user
* @param \Nova\Auth\Access\GateInterface $gate
* @return boolean
*/
Expand All @@ -130,29 +172,8 @@ protected function userIsAllowed(array $item, UserInterface $user, GateInterface
$abilities = explode('|', $abilities);
}

foreach ($abilities as $value) {
if (! is_array($value)) {
list ($ability, $parameters) = array_pad(explode(':', $value, 2), 2, array());

if (is_string($parameters)) {
$parameters = explode(',', $parameters);
}

// The information is given as an array.
} else if (! is_null($ability = Arr::get($value, 'ability'))) {
$parameters = Arr::get($value, 'arguments', array());

if (! is_array($parameters)) {
$parameters = array($parameters);
}
}

// Invalid ability format specified.
else {
throw new LogicException('Invalid user ability.');
}

if (call_user_func(array($gate, 'allows'), $ability, $parameters)) {
foreach ($abilities as $ability) {
if ($this->userHasAbility($ability, $user, $gate)) {
return true;
}
}
Expand All @@ -161,47 +182,37 @@ protected function userIsAllowed(array $item, UserInterface $user, GateInterface
}

/**
* Prepare the given menu items.
* Determine if the User has a specific Access Ability.
*
* @param array $items
* @param string $path
* @param string $url
* @param string $pageName
* @return array
* @param array|string $data
* @param \Nova\Auth\UserInterface $user
* @param \Nova\Auth\Access\GateInterface $gate
* @return boolean
* @throws \LogicException
*/
protected function prepareItems(array $items, $path, $url)
protected function userHasAbility($data, UserInterface $user, GateInterface $gate)
{
foreach ($items as &$item) {
$itemUrl = $item['url'];
if (! is_array($data)) {
list ($ability, $parameters) = array_pad(explode(':', $data, 2), 2, array());

//
$pattern = preg_quote($itemUrl, '#');

if (($itemUrl == $url) || Str::startsWith($path, $item['path'])) {
$active = true;
} else if (($itemUrl !== '#') && (preg_match('#^' .$pattern .'/page/[0-9]+$#', $url) === 1)) {
$active = true;
} else {
$active = false;
if (is_string($parameters)) {
$parameters = explode(',', $parameters);
}

$item['active'] = $active;

if (! empty($children = $item['children'])) {
$item['children'] = $this->prepareItems($children, $path, $url);
// The data is not a string.
} else if (is_null($ability = Arr::get($data, 'ability'))) {
throw new LogicException('Invalid format of the user ability.');
} else {
if (! is_null($model = Arr::get($data, 'model'))) {
$parameters = array($model);
}
}

// Sort the menu items by their weight and title.
usort($items, function ($a, $b)
{
if ($a['weight'] === $b['weight']) {
return strcmp($a['title'], $b['title']);
// The 'arguments' field must be an array.
else if (! is_array($parameters = Arr::get($data, 'arguments', array()))) {
throw new LogicException('Invalid format of the user ability.');
}
}

return ($a['weight'] < $b['weight']) ? -1 : 1;
});

return $items;
return call_user_func(array($gate, 'allows'), $ability, $parameters);
}
}
10 changes: 5 additions & 5 deletions modules/Users/Database/Seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function run()
'id' => 1,
'username' => 'admin',
'password' => Hash::make('admin'),
'email' => 'admin@novaframework.dev',
'email' => 'admin@novaframework.local',
'realname' => 'Site Administrator',
'image' => null,
'remember_token' => '',
Expand All @@ -45,7 +45,7 @@ public function run()
'id' => 2,
'username' => 'marcus',
'password' => Hash::make('marcus'),
'email' => 'marcus@novaframework.dev',
'email' => 'marcus@novaframework.local',
'realname' => 'Marcus Spears',
'image' => null,
'remember_token' => '',
Expand All @@ -60,7 +60,7 @@ public function run()
'id' => 3,
'username' => 'michael',
'password' => Hash::make('michael'),
'email' => 'michael@novaframework.dev',
'email' => 'michael@novaframework.local',
'realname' => 'Michael White',
'image' => null,
'remember_token' => '',
Expand All @@ -75,7 +75,7 @@ public function run()
'id' => 4,
'username' => 'john',
'password' => Hash::make('john'),
'email' => 'john@novaframework.dev',
'email' => 'john@novaframework.local',
'realname' => 'John Kennedy',
'image' => null,
'remember_token' => '',
Expand All @@ -90,7 +90,7 @@ public function run()
'id' => 5,
'username' => 'mark',
'password' => Hash::make('mark'),
'email' => 'mark@novaframework.dev',
'email' => 'mark@novaframework.local',
'realname' => 'Mark Black',
'image' => null,
'remember_token' => '',
Expand Down

0 comments on commit b569c34

Please sign in to comment.