Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #292 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
added `MeCms.default.other_css` and `MeCms.default.other_js` configur…
  • Loading branch information
mirko-pagliai authored Feb 28, 2023
2 parents e664108 + 48ee9e0 commit ad2516d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 114 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 2.x branch
## 2.31 branch
### 2.31.4
* removed the `cookies_policy` template element, the `SystemsController::acceptCookies()` method and all code related to
privacy for cookies (you need to integrate your privacy cookie);
* added `MeCms.default.other_css` and `MeCms.default.other_js` configuration values. These are used directly by the
`default` layout, to allow you to easily load css and js files from the application.

### 2.31.3
* fixed a small bug for css files that contain relative paths (and therefore shouldn't be used with `AssetHelper`);
* fixed Roboto fonts.
Expand Down
6 changes: 4 additions & 2 deletions config/me_cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
],
//Default layout
'default' => [
//Displays the alert for the cookie policy
'cookies_policy' => true,
//"Contact us" form (enabled or disabled)
'contact_us' => true,
//Facebook app ID or `false`
Expand All @@ -21,6 +19,10 @@
'offline' => false,
//Text to display when the site is offline or `false`
'offline_text' => false,
//Other application css files to load automatically (default `contents` and `layout`)
'other_css' => ['contents', 'layout'],
//Other application script files to load automatically (default empty)
'other_js' => [],
//Number of records to show per page
'records' => 10,
//Number of records to show on RSS
Expand Down
9 changes: 0 additions & 9 deletions config/routes/systems.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@

/** @var \Cake\Routing\RouteBuilder $routes */

//Accept cookies
if (!$routes->nameExists('acceptCookies')) {
$routes->connect(
'/accept/cookies',
['controller' => 'Systems', 'action' => 'acceptCookies'],
['_name' => 'acceptCookies']
);
}

//"Contact us" form
if (!$routes->nameExists('contactUs')) {
$routes->connect(
Expand Down
15 changes: 0 additions & 15 deletions src/Controller/SystemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace MeCms\Controller;

use Cake\Http\Cookie\Cookie;
use Cake\Http\Response;
use Cake\I18n\FrozenTime;
use MeCms\Form\ContactUsForm;
Expand Down Expand Up @@ -45,20 +44,6 @@ public function initialize(): void
$this->ContactUsForm ??= new ContactUsForm();
}

/**
* Accept cookies policy.
* It sets the cookie to remember the user accepted the cookie policy and
* redirects
* @return \Cake\Http\Response|null
*/
public function acceptCookies(): ?Response
{
$cookie = (new Cookie('cookies-policy', '1'))->withNeverExpire();
$this->setResponse($this->getResponse()->withCookie($cookie));

return $this->redirect($this->referer(['_name' => 'homepage']));
}

/**
* "Contact us" form
* @return \Cake\Http\Response|null|void
Expand Down
36 changes: 0 additions & 36 deletions templates/element/cookies_policy.php

This file was deleted.

15 changes: 7 additions & 8 deletions templates/layout/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \MeCms\View\View\AppView $this
*/

use Cake\Core\Configure;
use Cake\I18n\I18n;

/**
* @var \MeCms\View\View\AppView $this
*/
$sidebar = $this->fetch('sidebar') . $this->Widget->all();
?>
<!DOCTYPE html>
Expand All @@ -34,35 +34,34 @@
'/vendor/font-awesome/css/all.min',
'MeCms.fonts',
], ['block' => true]);
//Default css and css files from the application (`layout.css` and `contents.css`)
$css = array_filter(['layout', 'contents'], fn(string $name): bool => is_readable(Configure::read('App.wwwRoot') . Configure::read('App.cssBaseUrl') . $name . '.css'));
//Default css and application css files to load automatically (default `contents` and `layout`)
echo $this->Asset->css([
'/vendor/bootstrap/css/bootstrap.min',
'MeTools.default',
'MeTools.forms',
'MeCms.cookies',
'MeCms.layout',
'MeCms.contents',
...$css,
...(array)getConfig('default.other_css'),
], ['block' => true]);

//Other css files
echo $this->Asset->css('MeCms.print', ['block' => true, 'media' => 'print']);
echo $this->fetch('css');

//Default script and application script files to load automatically (default empty)
echo $this->Asset->script([
'/vendor/jquery/jquery.min',
'/vendor/bootstrap/js/bootstrap.bundle.min',
'MeCms.js.cookie.min',
'MeTools.default',
'MeCms.layout',
...(array)getConfig('default.other_js'),
], ['block' => true]);
echo $this->fetch('script');
?>
</head>
<body class="d-flex flex-column min-vh-100">
<?= $this->element('MeCms.userbar') ?>
<?= $this->element('MeCms.cookies_policy') ?>
<header>
<?php
$logo = $this->Html->h1(getConfigOrFail('main.title'));
Expand Down
15 changes: 0 additions & 15 deletions tests/TestCase/Controller/SystemsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
namespace MeCms\Test\TestCase\Controller;

use Cake\Cache\Cache;
use Cake\Chronos\Chronos;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\EventInterface;
use Cake\I18n\FrozenTime;
use MeCms\Form\ContactUsForm;
use MeCms\TestSuite\ControllerTestCase;
use StopSpam\SpamDetector;
Expand Down Expand Up @@ -57,19 +55,6 @@ public function controllerSpy(EventInterface $event, ?Controller $controller = n
$this->_controller->viewBuilder()->setLayout('with_flash');
}

/**
* @uses \MeCms\Controller\SystemsController::acceptCookies()
* @test
*/
public function testAcceptCookies(): void
{
$this->get(['_name' => 'acceptCookies']);
$this->assertRedirect(['_name' => 'homepage']);
$expires = FrozenTime::createFromTimestamp($this->_response->getCookie('cookies-policy')['expires']);
$this->assertCookie('1', 'cookies-policy');
$this->assertTrue($expires->isWithinNext((string)Chronos::createFromDate(2038, 1, 1)));
}

/**
* @uses \MeCms\Controller\SystemsController::contactUs()
* @test
Expand Down
2 changes: 0 additions & 2 deletions tests/test_app/TestApp/config/me_cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
],
//Default layout
'default' => [
//Displays the alert for the cookie policy
'cookies_policy' => true,
//"Contact us" form (enabled or disabled)
'contact_us' => true,
//Facebook app ID or `false`
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.31.3
2.31.4
26 changes: 0 additions & 26 deletions webroot/js/layout.js

This file was deleted.

0 comments on commit ad2516d

Please sign in to comment.