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 #297 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Mar 15, 2023
2 parents db5487a + 17eba42 commit e01b517
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 229 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.6
* fixed the `connector.minimal.php` file for ElFinder and the `FixElFinderCommand`: the Composer autoload is now
correctly loaded via absolute path;
* removed the default `userbar` and all code related;
* little fixes.

### 2.31.5
* `login` layout changed to `single-column`. This name clarifies that it can be used for various purposes (login, sign
up, but also error views);
Expand Down
16 changes: 9 additions & 7 deletions config/elfinder/connector.minimal.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php
error_reporting(0); //Set E_ALL for debuging
error_reporting(0); //Set E_ALL for debugging

require_once '{{AUTOLOAD_PATH}}';
require_once './autoload.php';

use MeCms\Model\Entity\User;

session_start();

if (!isset($_SESSION['Auth']['User']['id'])) {
if (!isset($_SESSION['Auth']) || !$_SESSION['Auth'] instanceof User || $_SESSION['Auth']->isEmpty('id')) {
header('HTTP/1.0 401 Unauthorized');
echo '{"error": "Login failed."}';
exit;
}

is_readable('./vendor/autoload.php') && require './vendor/autoload.php';
require './autoload.php';

/**
* Control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from '.' (dot)
Expand All @@ -28,7 +30,7 @@ function access($attr, $path, $data, $volume, $isDir, $relpath)
$basename = basename($path);

return $basename[0] === '.' // if file/folder begins with '.' (dot)
&& strlen($relpath) !== 1 // but with out volume root
&& strlen($relpath) !== 1 // but without volume root
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
: null; //else elFinder decide it itself
}
Expand All @@ -53,7 +55,7 @@ function access($attr, $path, $data, $volume, $isDir, $relpath)
'path' => '{{UPLOADS_PATH}}.trash',
'tmbURL' => '{{UPLOADS_URL}}/.trash/.tmb/',
'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
'uploadDeny' => ['all'], // Recomend the same settings as the original volume that uses the trash
'uploadDeny' => ['all'], // Recommend the same settings as the original volume that uses the trash
'uploadAllow' => ['image', 'text/plain'], // Same as above
'uploadOrder' => ['deny', 'allow'], // Same as above
'accessControl' => 'access', // Same as above
Expand Down
3 changes: 0 additions & 3 deletions config/me_cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,5 @@
'reset_password' => true,
//Signup (enabled or disabled)
'signup' => true,
//Displays the userbar. This will have effect only on the frontend; in
// the backend, the userbar will always be visible
'userbar' => true,
],
]];
10 changes: 5 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<code>parent::__construct($name, $data, $dataName)</code>
</InternalMethod>
</file>
<file src="src/Utility/Sitemap/SitemapBuilder.php">
<TooManyTemplateParams occurrences="1">
<code>\Cake\Collection\CollectionInterface&lt;array{class: class-string, name: string}&gt;</code>
</TooManyTemplateParams>
</file>
<file src="templates/Admin/Pages/form.php">
<TooManyTemplateParams occurrences="1">
<code>$this-&gt;extend('MeCms./common/form');</code>
Expand All @@ -51,6 +46,11 @@
<code>$this-&gt;extend('MeCms./common/form');</code>
</TooManyTemplateParams>
</file>
<file src="templates/Posts/view.php">
<TooManyTemplateParams occurrences="1">
<code>$this-&gt;extend('/common/view');</code>
</TooManyTemplateParams>
</file>
<file src="templates/cell/PostsTagsWidgets/popular_as_cloud.php">
<TooManyTemplateParams occurrences="1"/>
</file>
Expand Down
12 changes: 11 additions & 1 deletion src/Command/Install/FixElFinderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ protected function createConnectorMinimal(ConsoleIo $io): void
return;
}

$Filesystem = new Filesystem();
$autoload = $Filesystem->concatenate(APP, 'vendor', 'autoload.php');
$origin = Plugin::path('MeCms', 'config' . DS . 'elfinder' . DS . 'connector.minimal.php');
$content = str_replace(['{{UPLOADS_PATH}}', '{{UPLOADS_URL}}'], [Filesystem::instance()->addSlashTerm(UPLOADED), Router::url('/files', true)], file_get_contents($origin) ?: '');
$content = str_replace([
'{{AUTOLOAD_PATH}}',
'{{UPLOADS_PATH}}',
'{{UPLOADS_URL}}',
], [
is_readable($autoload) ? $autoload : $Filesystem->concatenate(ROOT, 'vendor', 'autoload.php'),
$Filesystem->addSlashTerm(UPLOADED),
Router::url('/files', true),
], file_get_contents($origin) ?: '');
$io->createFile($target, $content);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin/SystemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ protected function clearSitemap(): bool
* Temporary cleaner (assets, cache, logs, sitemap and thumbnails)
* @param string $type Type
* @return \Cake\Http\Response|null
* @throws \Symfony\Component\Filesystem\Exception\IOException
* @throws \Symfony\Component\Finder\Exception\DirectoryNotFoundException
* @throws \Tools\Exception\MethodNotExistsException
* @throws \Tools\Exception\NotReadableException
*/
public function tmpCleaner(string $type): ?Response
{
Expand Down
1 change: 1 addition & 0 deletions src/Model/Table/PostsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PostsTable extends PostsAndPagesTables
* @param \ArrayObject $data Request data
* @return void
* @since 2.15.2
* @noinspection PhpUnusedParameterInspection
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Model/Table/UsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function _initializeSchema(TableSchemaInterface $schema): TableSchemaI
* @param \ArrayObject $options Options
* @return void
* @since 2.16.1
* @noinspection PhpUnusedParameterInspection
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void
{
Expand Down
1 change: 1 addition & 0 deletions src/ORM/PostsAndPagesTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function afterSave(EventInterface $event, EntityInterface $entity): void
* @return void
* @throws \Tools\Exception\NotWritableException
* @since 2.17.0
* @noinspection PhpUnusedParameterInspection
*/
public function beforeSave(EventInterface $event, EntityInterface $entity): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Utility/StaticPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static function getPaths(): array
/**
* Gets all static pages
* @return \Cake\Collection\CollectionInterface Collection of static pages
* @throws \ErrorException
*/
public static function all(): CollectionInterface
{
Expand Down
10 changes: 4 additions & 6 deletions src/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ protected function getTitleForLayout(): string
return $title;
}

//If exists, it adds the title set by the controller, as if it has
// been set via `$this->View->set()`
//If exists, it adds the title set by the controller, as if it has been set via `$this->View->set()`
if ($this->get('title')) {
$title = sprintf('%s - %s', $this->get('title'), $title);
//Else, if exists, it adds the title set by the current view, as if
// it has been set via `$this->View->Blocks->set()`
$title = $this->get('title') . ' - ' . $title;
//Else, if exists, it adds the title set by the current view, as if it has been set via `$this->View->Blocks->set()`
} elseif ($this->fetch('title')) {
$title = sprintf('%s - %s', $this->fetch('title'), $title);
$title = $this->fetch('title') . ' - ' . $title;
}

return $this->titleForLayout = $title;
Expand Down
20 changes: 0 additions & 20 deletions src/View/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
*/
class AppView extends View
{
/**
* Internal property to set the userbar elements
* @var array
*/
protected array $userbar = [];

/**
* Internal method to set some blocks
* @return void
Expand Down Expand Up @@ -86,20 +80,6 @@ public function renderLayout(string $content, ?string $layout = null): string

$this->setBlocks();

//Assign the userbar
$this->assign('userbar', implode(PHP_EOL, array_map(fn($element): string => $this->Html->li($element), $this->userbar)));

return parent::renderLayout($content, $layout);
}

/**
* Adds content to the userbar
* @param string ...$content Contents as string or an array of contents
* @return void
* @since 2.29.5
*/
public function addToUserbar(string ...$content): void
{
$this->userbar = [...$this->userbar, $content];
}
}
26 changes: 4 additions & 22 deletions templates/Pages/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,14 @@
* @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\Model\Entity\Page $page
*/
$this->extend('/common/view');
$this->assign('title', $page->get('title'));

/**
* Userbar
* @var \MeCms\Model\Entity\Page $page
* @var \MeCms\View\View\AppView $this
*/
$class = 'badge badge-warning';
if (!$page->get('active')) {
$this->addToUserbar($this->Html->span(I18N_DRAFT, compact('class')));
}
if ($page->get('created')->isFuture()) {
$this->addToUserbar($this->Html->span(I18N_SCHEDULED, compact('class')));
}
$this->addToUserbar($this->Html->link(
__d('me_cms', 'Edit page'),
['action' => 'edit', $page->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link', 'icon' => 'pencil-alt', 'target' => '_blank']
));
$this->addToUserbar($this->Form->postLink(
__d('me_cms', 'Delete page'),
['action' => 'delete', $page->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link text-danger', 'icon' => 'trash-alt', 'confirm' => I18N_SURE_TO_DELETE, 'target' => '_blank']
));
$this->extend('/common/view');
$this->assign('title', $page->get('title'));

/**
* Breadcrumb
Expand Down
25 changes: 5 additions & 20 deletions templates/PagesCategories/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,22 @@
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
use MeCms\Model\Entity\Page;

/**
* @var \MeCms\Model\Entity\PagesCategory $category
* @var \MeCms\View\View\AppView $this
*/

use MeCms\Model\Entity\Page;

$this->extend('/common/index');
$this->assign('title', $category->get('title'));

/**
* Userbar
*/
$this->addToUserbar($this->Html->link(
__d('me_cms', 'Edit category'),
['action' => 'edit', $category->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link', 'icon' => 'pencil-alt', 'target' => '_blank']
));
$this->addToUserbar($this->Form->postLink(
__d('me_cms', 'Delete category'),
['action' => 'delete', $category->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link text-danger', 'icon' => 'trash-alt', 'confirm' => I18N_SURE_TO_DELETE, 'target' => '_blank']
));

/**
* Breadcrumb
*/
$this->Breadcrumbs->add($category->get('title'), ['_name' => 'pagesCategory', $category->get('title')]);

$pages = collection($category->get('pages'))
->map(fn(Page $page): string => $this->Html->link($page->get('title'), $page->get('url')))
->toList();
$pagesLinks = array_map(fn(Page $page): string => $this->Html->link($page->get('title'), $page->get('url')), $category->get('pages'));

echo $this->Html->ul($pages, ['icon' => 'caret-right']);
echo $this->Html->ul($pagesLinks, ['icon' => 'caret-right']);
35 changes: 7 additions & 28 deletions templates/Posts/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,18 @@
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
*/
use MeCms\Model\Entity\Post;

/**
* @var \MeCms\Model\Entity\Post $post
* @var \Cake\Collection\Collection<\MeCms\Model\Entity\Post> $related
* @var \MeCms\View\View\AppView $this
*/

use MeCms\Model\Entity\Post;

$this->extend('/common/view');
$this->assign('title', $post->get('title'));

/**
* Userbar
*/
$class = 'badge badge-warning';
if (!$post->get('active')) {
$this->addToUserbar($this->Html->span(I18N_DRAFT, compact('class')));
}
if ($post->get('created')->isFuture()) {
$this->addToUserbar($this->Html->span(I18N_SCHEDULED, compact('class')));
}
$this->addToUserbar($this->Html->link(
__d('me_cms', 'Edit post'),
['action' => 'edit', $post->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link', 'icon' => 'pencil-alt', 'target' => '_blank']
));
$this->addToUserbar($this->Form->postLink(
__d('me_cms', 'Delete post'),
['action' => 'delete', $post->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link text-danger', 'icon' => 'trash-alt', 'confirm' => I18N_SURE_TO_DELETE, 'target' => '_blank']
));

/**
* Breadcrumb
*/
Expand Down Expand Up @@ -89,14 +69,13 @@

<?php if (!$related->isEmpty()) : ?>
<?php
$relatedAsArray = collection($related)
->map(fn(Post $post): string => $this->Html->link($post->get('title'), ['_name' => 'post', $post->get('slug')]))
$relatedAsLinks = $related->map(fn(Post $post): string => $this->Html->link($post->get('title'), ['_name' => 'post', $post->get('slug')]))
->toArray();
?>
<div class="related-contents mb-4">
<?= $this->Html->h5(__d('me_cms', 'Related posts')) ?>
<?php if (!getConfig('post.related.images')) : ?>
<?= $this->Html->ul($relatedAsArray, ['icon' => 'caret-right']) ?>
<?= $this->Html->ul($relatedAsLinks, ['icon' => 'caret-right']) ?>
<?php else : ?>
<div class="d-none d-lg-block">
<div class="row">
Expand All @@ -109,7 +88,7 @@
</div>

<div class="d-lg-none">
<?= $this->Html->ul($relatedAsArray, ['icon' => 'caret-right']) ?>
<?= $this->Html->ul($relatedAsLinks, ['icon' => 'caret-right']) ?>
</div>
<?php endif; ?>
</div>
Expand Down
17 changes: 4 additions & 13 deletions templates/PostsCategories/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
$this->extend('/Posts/index');
$this->assign('title', $category->get('title'));

/**
* Userbar
* @var \MeCms\Model\Entity\PostsCategory $category
* @var \MeCms\View\View\AppView $this
*/
$this->addToUserbar($this->Html->link(
__d('me_cms', 'Edit category'),
['action' => 'edit', $category->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link', 'icon' => 'pencil-alt', 'target' => '_blank']
));
$this->addToUserbar($this->Form->postLink(
__d('me_cms', 'Delete category'),
['action' => 'delete', $category->get('id'), 'prefix' => ADMIN_PREFIX],
['class' => 'nav-link text-danger', 'icon' => 'trash-alt', 'confirm' => I18N_SURE_TO_DELETE, 'target' => '_blank']
));
$this->extend('/Posts/index');
$this->assign('title', $category->get('title'));

/**
* Breadcrumb
Expand Down
Loading

0 comments on commit e01b517

Please sign in to comment.