diff --git a/.ecs/batch/check/default.bat b/.ecs/batch/check/default.bat new file mode 100644 index 0000000..06b8375 --- /dev/null +++ b/.ecs/batch/check/default.bat @@ -0,0 +1,10 @@ +:: Run easy-coding-standard (ecs) via this batch file inside your IDE e.g. PhpStorm (Windows only) +:: Install inside PhpStorm the "Batch Script Support" plugin +cd.. +cd.. +cd.. +cd.. +cd.. +cd.. +vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/src --config vendor/markocupic/gallery-creator-bundle/.ecs/config/default.php +cd vendor/markocupic/gallery-creator-bundle/.ecs./batch/check diff --git a/.ecs/batch/check/tests.bat b/.ecs/batch/check/tests.bat new file mode 100644 index 0000000..9625367 --- /dev/null +++ b/.ecs/batch/check/tests.bat @@ -0,0 +1,10 @@ +:: Run easy-coding-standard (ecs) via this batch file inside your IDE e.g. PhpStorm (Windows only) +:: Install inside PhpStorm the "Batch Script Support" plugin +cd.. +cd.. +cd.. +cd.. +cd.. +cd.. +vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/tests --config vendor/markocupic/gallery-creator-bundle/.ecs/config/default.php +cd vendor/markocupic/gallery-creator-bundle/.ecs./batch/check diff --git a/.ecs/batch/fix/default.bat b/.ecs/batch/fix/default.bat new file mode 100644 index 0000000..ec7e638 --- /dev/null +++ b/.ecs/batch/fix/default.bat @@ -0,0 +1,11 @@ +:: Run easy-coding-standard (ecs) via this batch file inside your IDE e.g. PhpStorm (Windows only) +:: Install inside PhpStorm the "Batch Script Support" plugin +cd.. +cd.. +cd.. +cd.. +cd.. +cd.. +vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/src --fix --config vendor/markocupic/gallery-creator-bundle/.ecs/config/default.php + +cd vendor/markocupic/gallery-creator-bundle/.ecs./batch/fix diff --git a/.ecs/batch/fix/tests.bat b/.ecs/batch/fix/tests.bat new file mode 100644 index 0000000..2c01e53 --- /dev/null +++ b/.ecs/batch/fix/tests.bat @@ -0,0 +1,10 @@ +:: Run easy-coding-standard (ecs) via this batch file inside your IDE e.g. PhpStorm (Windows only) +:: Install inside PhpStorm the "Batch Script Support" plugin +cd.. +cd.. +cd.. +cd.. +cd.. +cd.. +vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/tests --fix --config vendor/markocupic/gallery-creator-bundle/.ecs/config/default.php +cd vendor/markocupic/gallery-creator-bundle/.ecs./batch/fix diff --git a/.ecs/config/default.php b/.ecs/config/default.php new file mode 100644 index 0000000..e9a8899 --- /dev/null +++ b/.ecs/config/default.php @@ -0,0 +1,16 @@ +import(__DIR__ . '../../../../../contao/easy-coding-standard/config/contao.php'); + + // Custom + $ECSConfig->import(__DIR__.'/set/header_comment_fixer.php'); + + // Custom + $ECSConfig->import(__DIR__.'/set/skip_configuration.php'); +}; diff --git a/.ecs/config/set/header_comment_fixer.php b/.ecs/config/set/header_comment_fixer.php new file mode 100644 index 0000000..2cff98d --- /dev/null +++ b/.ecs/config/set/header_comment_fixer.php @@ -0,0 +1,18 @@ +services(); + + $services + ->set(HeaderCommentFixer::class) + ->call('configure', [[ + 'header' => "This file is part of Gallery Creator Bundle.\n\n(c) Marko Cupic ".date('Y')." \n@license GPL-3.0-or-later\nFor the full copyright and license information,\nplease view the LICENSE file that was distributed with this source code.\n@link https://github.com/markocupic/gallery-creator-bundle", + ]]) + ; +}; diff --git a/.ecs/config/set/skip_configuration.php b/.ecs/config/set/skip_configuration.php new file mode 100644 index 0000000..2d8a4a4 --- /dev/null +++ b/.ecs/config/set/skip_configuration.php @@ -0,0 +1,19 @@ +parameters(); + + $parameters->set(Option::SKIP, [ + + MethodChainingIndentationFixer::class => [ + '*/DependencyInjection/Configuration.php', + + ], + ]); +}; diff --git a/.editorconfig b/.editorconfig index 4e14bc7..6835bbf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,16 +9,16 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.{php,twig,yaml}] +[*.{php,twig,yml}] indent_style = space indent_size = 4 [*.{html5,svg,min.css,min.js}] insert_final_newline = false -[*/public/**.{css,js,php}] +[*/src/Resources/contao/**.{css,js,php}] indent_style = tab -[*/contao/**.html5] +[*/src/Resources/contao/**.html5] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index bcde59b..bdb0cab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,5 @@ # Auto detect text files and perform LF normalization -* text eol=lf - -#* text=auto +* text=auto # Custom for Visual Studio *.cs diff=csharp diff --git a/README.md b/README.md index ed8ca2b..70e9427 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Marko Cupic](docs/logo.png?raw=true "Marko Cupic") +

# Gallery Creator Bundle @@ -83,19 +83,21 @@ declare(strict_types=1); namespace App\EventListener; -use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; -use Contao\CoreBundle\Twig\FragmentTemplate; +use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\Template; +use Markocupic\GalleryCreatorBundle\Controller\ContentElement\AbstractContentElementController; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; -#[AsHook(GalleryCreatorFrontendTemplateListener::HOOK, priority: 100)] +/** + * @Hook(GalleryCreatorFrontendTemplateListener::HOOK, priority=100) + */ class GalleryCreatorFrontendTemplateListener { public const HOOK = 'galleryCreatorGenerateFrontendTemplate'; - public function __invoke(AbstractContentElementController $contentElement, Fragmenttemplate $template, GalleryCreatorAlbumsModel|null $activeAlbum = null) + public function __invoke(AbstractContentElementController $contentElement, Template $template, ?GalleryCreatorAlbumsModel $activeAlbum = null) { - $template->set('foo', 'bar'); + $template->foo = 'bar'; } } @@ -118,11 +120,13 @@ declare(strict_types=1); namespace App\EventListener; use Contao\BackendUser; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; -#[AsHook(GalleryCreatorImagePostInsertListener::HOOK, priority: 100)] +/** + * @Hook(GalleryCreatorImagePostInsertListener::HOOK, priority=100) + */ class GalleryCreatorImagePostInsertListener { public const HOOK = 'galleryCreatorImagePostInsert'; diff --git a/composer.json b/composer.json index 8b5cf6e..ca66bca 100644 --- a/composer.json +++ b/composer.json @@ -1,54 +1,42 @@ { - "name": "markocupic/gallery-creator-bundle", - "keywords": [ - "Contao", - "gallery", - "album", - "plugin" - ], - "type": "contao-bundle", - "description": "gallery extension for Contao CMS", - "license": "LGPL-3.0+", - "authors": [ - { - "name": "Marko Cupic", - "email": "m.cupic@gmx.ch", - "homepage": "https://github.com/markocupic", - "role": "Developer" - } - ], - "support": { - "issues": "https://github.com/markocupic/gallery-creator-bundle/issues", - "source": "https://github.com/markocupic/gallery-creator-bundle", - "forum": "https://community.contao.org/de/showthread.php?22634-gallery_creator" - }, - "require": { - "contao/core-bundle": "^5.0", - "php": "^8.1", - "jaybizzle/crawler-detect": "^1.2", - "league/commonmark": "^2.3" - }, - "require-dev": { - "contao/easy-coding-standard": "^5.0" - }, - "autoload": { - "psr-4": { - "Markocupic\\GalleryCreatorBundle\\": "src/" - } - }, - "extra": { - "contao-manager-plugin": "Markocupic\\GalleryCreatorBundle\\ContaoManager\\Plugin" - }, - "config": { - "allow-plugins": { - "contao/manager-plugin": false, - "contao-components/installer": false, - "dealerdirect/phpcodesniffer-composer-installer": true - } - }, - "scripts": { - "cs-fixer": "@php tools/ecs/vendor/bin/ecs check config/ contao/ src/ tests/ --config tools/ecs/config.php --fix --ansi", - "unit-tests": "@php tools/phpunit/vendor/bin/phpunit -c tools/phpunit/phpunit.xml.dist", - "phpstan": "@php tools/phpstan/vendor/bin/phpstan analyse src tests" + "name": "markocupic/gallery-creator-bundle", + "keywords": [ + "Contao", + "gallery", + "album", + "plugin" + ], + "type": "contao-bundle", + "description": "gallery extension for Contao CMS", + "license": "LGPL-3.0+", + "authors": [ + { + "name": "Marko Cupic", + "email": "m.cupic@gmx.ch", + "homepage": "https://github.com/markocupic", + "role": "Developer" } + ], + "support": { + "issues": "https://github.com/markocupic/gallery-creator-bundle/issues", + "source": "https://github.com/markocupic/gallery-creator-bundle", + "forum": "https://community.contao.org/de/showthread.php?22634-gallery_creator" + }, + "require": { + "contao/core-bundle": "^4.13 || ^5.0 || > 5.0.0-RC3", + "php": "^7.4 || ^8.0", + "jaybizzle/crawler-detect": "^1.2", + "league/commonmark": "^2.2" + }, + "require-dev": { + "contao/easy-coding-standard": "^5.0" + }, + "autoload": { + "psr-4": { + "Markocupic\\GalleryCreatorBundle\\": "src/" + } + }, + "extra": { + "contao-manager-plugin": "Markocupic\\GalleryCreatorBundle\\ContaoManager\\Plugin" + } } diff --git a/config/routes.yaml b/config/routes.yaml deleted file mode 100644 index e3d6d39..0000000 --- a/config/routes.yaml +++ /dev/null @@ -1,3 +0,0 @@ -markocupic_gallery_creator.controller: - resource: "@MarkocupicGalleryCreatorBundle/src/Controller" - type: annotation diff --git a/contao/templates/_new/.twig-root b/contao/templates/_new/.twig-root deleted file mode 100644 index e69de29..0000000 diff --git a/contao/templates/_new/component/_album.html.twig b/contao/templates/_new/component/_album.html.twig deleted file mode 100644 index f051cd1..0000000 --- a/contao/templates/_new/component/_album.html.twig +++ /dev/null @@ -1,84 +0,0 @@ -{# component/_album.html.twig #} -{% use "@Contao/component/_figure.html.twig" %} - -{% trans_default_domain 'contao_default' %} - -{% block album_component %} - {% if album.href|default %} - {% - set album_href_attributes = attrs(album_href_attributes|default) - .set('href', album.href) - .set('title', album.meta.getTitle()) - .addClass('gc-album-list-link') - %} - {% endif %} - - - {% block album_figure %} - - {% if album_href_attributes|default %} - - {% endif %} - {% if album.figure.build|default %}{% with {figure: album.figure.build} %}{{ block('figure_component') }}{% endwith %}{% endif %} - {% if album_href_attributes|default %} - - {% endif %} - - {% endblock %} - - - {% block album_title %} - {% if album_href_attributes|default %} - - {% endif %} - {% set album_title_tag = album_title_tag|default('h4') %} - <{{ album_title_tag }}{{ attrs(album_name_attributes|default).addClass('gc-album-list-name') }}>{% block album_name %}{{ album.name }}{% endblock %} - {% if album_href_attributes|default %} - - {% endif %} - {% endblock %} - - {% block album_date %} - - {% endblock %} - - {% if album.location|default %} - {% block album_location %} - {{ 'GALLERY_CREATOR.location'|trans }}: {{ album.location }} - {% endblock %} - {% endif %} - - {% if album.photographer|default %} - {% block album_photographer %} - {{ 'GALLERY_CREATOR.photographerName'|trans }}: {{ album.photographer }} - {% endblock %} - {% endif %} - - {% if album.teaser|default %} - {% block album_teaser %} - {{ album.teaser|raw|nl2br }} - {% endblock %} - {% endif %} - - {% if album.pictureCount|default(0) %} - {% block album_picture_count %} - {{ album.pictureCount }} {{ 'GALLERY_CREATOR.pictures'|trans }} - {% endblock %} - {% endif %} - - {% if album.visitors|default(0) %} - {% block album_visitors %} - {{ album.visitors }} {{ 'GALLERY_CREATOR.visitors'|trans }} - {% endblock %} - {% endif %} - - {% if album.hasChildAlbums|default %} - {% block album_child_album_count %} - {{ album.childAlbumCount }} {{ 'GALLERY_CREATOR.childAlbums'|trans }} - {% endblock %} - {% endif %} - - - - -{% endblock %} diff --git a/contao/templates/_new/component/_album_detail_view.html.twig b/contao/templates/_new/component/_album_detail_view.html.twig deleted file mode 100644 index 29cfd58..0000000 --- a/contao/templates/_new/component/_album_detail_view.html.twig +++ /dev/null @@ -1,84 +0,0 @@ -{% use "@Contao/component/_list.html.twig" %} - -{# component/_album_detail_view.html.twig #} -{% trans_default_domain 'contao_default' %} - -{% block album_detail_view %} - {% set album_detail_view_attributes = attrs(album_detail_view_attributes|default).addClass('gc-album-detail-view').set('data-album-level', level) %} - - - - {% block album_detail_article_pre %} - {% if insertArticlePre %} - - {{ insertArticlePre|raw }} - - {% endif %} - {% endblock %} - - {% block album_detail_back_link %} - {% if backLink %} - - {{ 'GALLERY_CREATOR.backLink'|trans }} - - {% endif %} - {% endblock %} - - {% block album_detail_name %} - {% if album.name|default %} - {% set album_detail_name_tag_name = album_detail_name_tag_name|default('h2') %} - <{{ album_detail_name_tag_name }}{{ attrs(album_detail_name_attributes|default).addClass('gc-album-detail-name') }}>{{ album.name }} - {% endif %} - {% endblock %} - - {% block album_detail_date %} - {% if album.dateFormatted|default %} - {{ album.dateFormatted }} - {% endif %} - {% endblock %} - - {% block album_detail_location %} - {% if album.location|default %} - {{ album.location }} - {% endif %} - {% endblock %} - - {% block album_detail_child_albums %} - {% if album.hasChildAlbums %} - {{ album.childAlbumCount }} {{ 'GALLERY_CREATOR.childAlbums'|trans }} - {% endif %} - {% endblock %} - - {% block album_detail_caption %} - {% set album_detail_caption_attributes = attrs(album_detail_caption_attributes|default).addClass('gc-album-detail-caption') %} - {% if album.captionType == 'markdown' and album.markdownCaption|default %} - -

{{ album.markdownCaption|raw }}

- - {% elseif album.caption|default %} - -

{{ album.caption|raw|nl2br }}

- - {% endif %} - {% endblock %} - - {% if images|default %} - {% block album_detail_picture_list %} - {# !!! The gallery is rendered here!!! #} - {% with {items: images } %}{{ block('list_component') }}{% endwith %} - {% endblock %} - {% endif %} - {% block album_detail_article_post %} - {% if insertArticlePost %} - - {{ insertArticlePost|raw }} - - {% endif %} - {% endblock %} - - - - {% block album_detail_script %} - {# Add your javascript here. #} - {% endblock %} -{% endblock %} diff --git a/contao/templates/_new/component/_album_list_view.html.twig b/contao/templates/_new/component/_album_list_view.html.twig deleted file mode 100644 index 56cecd2..0000000 --- a/contao/templates/_new/component/_album_list_view.html.twig +++ /dev/null @@ -1,41 +0,0 @@ -{# component/_album_list_view.html.twig #} -{% use "@Contao_MarkocupicGalleryCreatorBundle/component/_album.html.twig" %} - -{% block album_list_view %} - - - {% block album_list_pagination %} - {{ listPagination|raw }} - {% endblock %} - - {% block album_list %} - {% set album_list_tag = album_list_tag|default('ul') %} - <{{ album_list_tag }}{{ attrs(album_list_attributes|default).addClass('gc-album-list') }}> - {% for album in albums %} - {% set album_list_item_tag = album_list_item_tag|default('li') %} - {% set album_list_item_attributes = attrs(album_list_item_attributes|default) - .addClass('gc-album-list-item') - .set('data-id', album.id) %} - - {% if album.cssClass|default %} - {% set album_list_item_attributes = attrs(album_list_item_attributes|default).addClass(album.cssClass) %} - {% endif %} - - <{{ album_list_item_tag }}{{ album_list_item_attributes }}> - {% with {album: album} %} - {# - Here comes the album component 'component/_album.html.twig' - Do your modifications just below! - #} - {{ block('album_component') }} - {% endwith %} - - {% endfor %} - - {% endblock %} - - {% block album_list_script %} - {# Add your javascript here. #} - {% endblock %} - -{% endblock %} diff --git a/contao/templates/_new/content_element/gallery_creator.html.twig b/contao/templates/_new/content_element/gallery_creator.html.twig deleted file mode 100644 index 7664790..0000000 --- a/contao/templates/_new/content_element/gallery_creator.html.twig +++ /dev/null @@ -1,52 +0,0 @@ -{# content_element/gallery_creator.html.twig #} - -{% extends "@Contao/content_element/_base.html.twig" %} -{% use '@Contao_MarkocupicGalleryCreatorBundle/component/_album_list_view.html.twig' %} -{% use '@Contao_MarkocupicGalleryCreatorBundle/component/_album_detail_view.html.twig' %} -{% use "@Contao_MarkocupicGalleryCreatorBundle/component/_album.html.twig" %} -{% use "@Contao/component/_figure.html.twig" %} - -{% block content %} - - {% if hasBreadcrumb and showAlbumDetail %} - - {% endif %} - - {% if showAlbumDetail %} - {% block album_detail_view %} - {# Do your template modification (e.g. add css classes, replace tag names, etc.) below here: #} - - {{ parent() }} - {% endblock %} - {% endif %} - - {% if showAlbumListing %} - {% block album_list_view %} - {# Do your template modification (e.g. add css classes, replace tag names, etc.) below here: #} - - {{ parent() }} - {% endblock %} - {% endif %} - -{% endblock %} - -{% block list_item %} - {% if showAlbumDetail and item.figure.build|default %} - {% with {figure: item.figure.build} %}{{ block('figure_component') }}{% endwith %} - {% endif %} -{% endblock %} - -{% block list %} - {% if showAlbumDetail %} - {% set list = list|merge({'list_attributes': attrs(list.list_attributes|default) - .removeClass("content-#{type}") - .addClass('gc-album-detail-picture-list')}) %} - - {% set list = list|merge({'item_attributes': attrs(list.item_attributes|default) - .addClass('gc-album-detail-picture-list-item')}) %} - {% endif %} - - {{ parent() }} -{% endblock %} diff --git a/contao/templates/_new/content_element/gallery_creator_news.html.twig b/contao/templates/_new/content_element/gallery_creator_news.html.twig deleted file mode 100644 index 9fab728..0000000 --- a/contao/templates/_new/content_element/gallery_creator_news.html.twig +++ /dev/null @@ -1,34 +0,0 @@ -{# content_elemnt/gallery_creator_news.html.twig #} - -{% extends '@Contao/block_searchable' %} -{% use '@Contao_MarkocupicGalleryCreatorBundle/component/_album_detail_view.html.twig' %} -{% use "@Contao/component/_figure.html.twig" %} - -{% block content %} - - {% block album_detail_view %} - {# Do your template modification (e.g. add css classes, replace tag names, etc.) below here: #} - - {{ parent() }} - {% endblock %} - -{% endblock %} - -{% block list_item %} - {% if showAlbumDetail %} - {% with {figure: item.figure} %}{{ block('figure_component') }}{% endwith %} - {% endif %} -{% endblock %} - -{% block list %} - {% if showAlbumDetail %} - {% set list = list|merge({'list_attributes': attrs(list.list_attributes|default) - .removeClass("content-#{type}") - .addClass('gc-album-detail-picture-list')}) %} - - {% set list = list|merge({'item_attributes': attrs(list.item_attributes|default) - .addClass('gc-album-detail-picture-list-item')}) %} - {% endif %} - - {{ parent() }} -{% endblock %} diff --git a/docs/chmod.png b/docs/chmod.png index e404285..2cf0e8d 100644 Binary files a/docs/chmod.png and b/docs/chmod.png differ diff --git a/docs/logo.png b/docs/logo.png index ffa6560..30905cc 100644 Binary files a/docs/logo.png and b/docs/logo.png differ diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index f31b5fd..4e0de3c 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -44,8 +44,8 @@ public function getBundles(ParserInterface $parser): array public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): RouteCollection { return $resolver - ->resolve(__DIR__.'/../../config/routes.yaml') - ->load(__DIR__.'/../../config/routes.yaml') + ->resolve(__DIR__.'/../Resources/config/routes.yml') + ->load(__DIR__.'/../Resources/config/routes.yml') ; } } diff --git a/src/Controller/Ajax/GalleryCreatorAjax.php b/src/Controller/Ajax/GalleryCreatorAjax.php index 094365c..731d6a6 100644 --- a/src/Controller/Ajax/GalleryCreatorAjax.php +++ b/src/Controller/Ajax/GalleryCreatorAjax.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -19,6 +19,8 @@ use Contao\FilesModel; use Contao\StringUtil; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; +use Doctrine\DBAL\Exception as DoctrineDBALException; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; use Markocupic\GalleryCreatorBundle\Util\AlbumUtil; @@ -30,19 +32,29 @@ class GalleryCreatorAjax { - public function __construct( - private readonly ContaoFramework $framework, - private readonly Connection $connection, - private readonly SecurityUtil $securityUtil, - private readonly AlbumUtil $albumUtil, - private readonly PictureUtil $pictureUtil, - ) { + private ContaoFramework $framework; + private Connection $connection; + private SecurityUtil $securityUtil; + private AlbumUtil $albumUtil; + private PictureUtil $pictureUtil; + + public function __construct(ContaoFramework $framework, Connection $connection, SecurityUtil $securityUtil, AlbumUtil $albumUtil, PictureUtil $pictureUtil) + { + $this->framework = $framework; + $this->connection = $connection; + $this->securityUtil = $securityUtil; + $this->albumUtil = $albumUtil; + $this->pictureUtil = $pictureUtil; } - #[Route('/_gallery_creator/get_image/{pictureId}/{contentId}', name: self::class.'\getImage', defaults: ['scope' => 'frontend'])] + /** + * @throws \Exception + * + * @Route("/_gallery_creator/get_image/{pictureId}/{contentId}", name="GalleryCreatorAjax::class\getImage", defaults={"_scope" = "frontend"}) + */ public function getImage(int $pictureId, int $contentId): Response { - $this->framework->initialize(); + $this->framework->initialize(true); $arrPicture = []; $pictureModel = GalleryCreatorPicturesModel::findByPk($pictureId); @@ -55,10 +67,15 @@ public function getImage(int $pictureId, int $contentId): Response return new JsonResponse($arrPicture); } - #[Route('/_gallery_creator/get_images_by_pid/{pid}/{contentId}', name: self::class.'\getImagesByPid', defaults: ['scope' => 'frontend'])] + /** + * @throws DoctrineDBALDriverException + * @throws DoctrineDBALException + * + * @Route("/_gallery_creator/get_images_by_pid/{pid}/{contentId}", name="GalleryCreatorAjax::class\getImagesByPid", defaults={"_scope" = "frontend"}) + */ public function getImagesByPid(int $pid, int $contentId): Response { - $this->framework->initialize(); + $this->framework->initialize(true); // Do not send data if album is protected and the user has no access $albumModel = GalleryCreatorAlbumsModel::findByPk($pid); @@ -116,4 +133,11 @@ public function getImagesByPid(int $pid, int $contentId): Response return new JsonResponse($json); } + + public function setFramework(ContaoFramework $framework): self + { + $this->framework = $framework; + + return $this; + } } diff --git a/src/Controller/ContentElement/AbstractGalleryCreatorController.php b/src/Controller/ContentElement/AbstractGalleryCreatorController.php index 8bbb328..a543a6c 100644 --- a/src/Controller/ContentElement/AbstractGalleryCreatorController.php +++ b/src/Controller/ContentElement/AbstractGalleryCreatorController.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -16,61 +16,58 @@ use Contao\Config; use Contao\ContentModel; +use Contao\Controller; use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; +use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\CoreBundle\File\Metadata; -use Contao\CoreBundle\Image\Studio\Studio; use Contao\CoreBundle\InsertTag\InsertTagParser; use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag; use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor; use Contao\CoreBundle\Routing\ScopeMatcher; use Contao\CoreBundle\String\HtmlDecoder; -use Contao\CoreBundle\Twig\FragmentTemplate; use Contao\Date; +use Contao\Environment; use Contao\FilesModel; +use Contao\Input; use Contao\PageModel; use Contao\StringUtil; use Contao\System; +use Contao\Template; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception as DoctrineDBALException; +use Contao\Pagination; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; use Markocupic\GalleryCreatorBundle\Util\AlbumUtil; use Markocupic\GalleryCreatorBundle\Util\MarkdownUtil; use Markocupic\GalleryCreatorBundle\Util\PictureUtil; use Markocupic\GalleryCreatorBundle\Util\SecurityUtil; -use Symfony\Component\HttpFoundation\RequestStack; abstract class AbstractGalleryCreatorController extends AbstractContentElementController { protected AlbumUtil $albumUtil; - protected Connection $connection; - protected HtmlDecoder $htmlDecoder; - protected InsertTagParser $insertTagParser; protected MarkdownUtil $markdownUtil; + protected Connection $connection; protected PictureUtil $pictureUtil; - protected RequestStack $requestStack; - protected ResponseContextAccessor $responseContextAccessor; - protected ScopeMatcher $scopeMatcher; protected SecurityUtil $securityUtil; - protected Studio $studio; - protected string $projectDir; + protected ScopeMatcher $scopeMatcher; + protected ResponseContextAccessor $responseContextAccessor; + protected InsertTagParser $insertTagParser; + protected HtmlDecoder $htmlDecoder; public function __construct(DependencyAggregate $dependencyAggregate) { $this->albumUtil = $dependencyAggregate->albumUtil; - $this->connection = $dependencyAggregate->connection; - $this->htmlDecoder = $dependencyAggregate->htmlDecoder; - $this->insertTagParser = $dependencyAggregate->insertTagParser; $this->markdownUtil = $dependencyAggregate->markdownUtil; + $this->connection = $dependencyAggregate->connection; $this->pictureUtil = $dependencyAggregate->pictureUtil; - $this->projectDir = $dependencyAggregate->projectDir; - $this->requestStack = $dependencyAggregate->requestStack; - $this->responseContextAccessor = $dependencyAggregate->responseContextAccessor; - $this->scopeMatcher = $dependencyAggregate->scopeMatcher; $this->securityUtil = $dependencyAggregate->securityUtil; - $this->studio = $dependencyAggregate->studio; + $this->scopeMatcher = $dependencyAggregate->scopeMatcher; + $this->responseContextAccessor = $dependencyAggregate->responseContextAccessor; + $this->insertTagParser = $dependencyAggregate->insertTagParser; + $this->htmlDecoder = $dependencyAggregate->htmlDecoder; } public function overridePageMetaData(GalleryCreatorAlbumsModel $objAlbum): void @@ -100,160 +97,147 @@ public function overridePageMetaData(GalleryCreatorAlbumsModel $objAlbum): void } } - public function getAlbumData(GalleryCreatorAlbumsModel $album, ContentModel $content): array + /** + * @throws DoctrineDBALDriverException + * @throws Exception + */ + public function getAlbumData(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentElementModel): array { - /** @var PageModel $page */ - $page = $this->requestStack->getCurrentRequest()->attributes->get('pageModel'); + global $objPage; // Count images - $pictureCount = $this->connection + $countPictures = $this->connection ->fetchOne( - 'SELECT COUNT(id) AS pictureCount FROM tl_gallery_creator_pictures WHERE pid = ? AND published = ?', - [$album->id, '1'], + 'SELECT COUNT(id) AS countPictures FROM tl_gallery_creator_pictures WHERE pid = ? AND published = ?', + [$albumModel->id, '1'], ) ; // Image size - $size = StringUtil::deserialize($content->gcSizeAlbumListing); + $size = StringUtil::deserialize($contentElementModel->gcSizeAlbumListing); $arrSize = !empty($size) && \is_array($size) ? $size : null; - $params = '/'.$album->alias; - $href = StringUtil::ampersand($page->getFrontendUrl($params)); + $params = '/' . $albumModel->alias; + $href = StringUtil::ampersand($objPage->getFrontendUrl($params)); /** @var FilesModel $previewImage */ - $previewImage = $this->getAlbumPreviewThumb($album); + $previewImage = $this->getAlbumPreviewThumb($albumModel); $arrCssClasses = []; - $arrCssClasses[] = 'gc-level-'.$this->albumUtil->getAlbumLevelFromPid((int) $album->pid); - $arrCssClasses[] = GalleryCreatorAlbumsModel::hasChildAlbums((int) $album->id) ? 'gc-has-child-album' : null; - $arrCssClasses[] = !$pictureCount ? 'gc-empty-album' : null; + $arrCssClasses[] = 'gc-level-'.$this->albumUtil->getAlbumLevelFromPid((int) $albumModel->pid); + $arrCssClasses[] = GalleryCreatorAlbumsModel::hasChildAlbums((int) $albumModel->id) ? 'gc-has-child-album' : null; + $arrCssClasses[] = !$countPictures ? 'gc-empty-album' : null; // Do not show child albums, in news elements - if (GalleryCreatorNewsController::TYPE === $content->type) { + if (GalleryCreatorNewsController::TYPE === $contentElementModel->type) { $childAlbums = null; } else { - $childAlbums = $this->getChildAlbums($album, $content, true); + $childAlbums = $this->getChildAlbums($albumModel, $contentElementModel, true); } $childAlbumCount = null !== $childAlbums ? \count($childAlbums) : 0; - $strTeaser = $this->insertTagParser->replaceInline(nl2br((string) $album->teaser)); - $strCaption = $this->insertTagParser->replaceInline(nl2br((string) $album->caption)); - $strMarkdown = 'markdown' === $album->captionType && $album->markdownCaption ? $this->markdownUtil->parse($album->markdownCaption) : null; + $teaser = $this->insertTagParser->replaceInline(nl2br((string) $albumModel->teaser)); + $caption = $this->insertTagParser->replaceInline(nl2br((string) $albumModel->caption)); + $markdown = 'markdown' === $albumModel->captionType && $albumModel->markdownCaption ? $this->markdownUtil->parse($albumModel->markdownCaption) : null; // Meta $arrMeta = []; - $arrMeta['alt'] = StringUtil::specialchars($album->name); - $arrMeta['caption'] = $strTeaser; - $arrMeta['title'] = StringUtil::specialchars($album->name); - - // Compile list of images - if ($previewImage) { - $figure = $this->studio - ->createFigureBuilder() - ->setSize($arrSize) - ->enableLightbox(false) - ->setOverwriteMetadata(new Metadata($arrMeta)) - ->fromUuid($previewImage->uuid) - ->setMetadata(new Metadata($arrMeta)) - ; - } - - $arrAlbum = $album->row(); - $arrAlbum['teaser'] = $strTeaser; - $arrAlbum['caption'] = $strCaption; - $arrAlbum['markdownCaption'] = $strMarkdown ?: false; - $arrAlbum['dateFormatted'] = Date::parse(Config::get('dateFormat'), $album->date); - $arrAlbum['datimFormatted'] = Date::parse(Config::get('datimFormat'), $album->date); + $arrMeta['alt'] = StringUtil::specialchars($albumModel->name); + $arrMeta['caption'] = $teaser; + $arrMeta['title'] = StringUtil::specialchars($albumModel->name); + + $arrAlbum = $albumModel->row(); + $arrAlbum['teaser'] = $teaser; + $arrAlbum['caption'] = $caption; + $arrAlbum['markdownCaption'] = $markdown ?: false; + $arrAlbum['dateFormatted'] = Date::parse(Config::get('dateFormat'), $albumModel->date); $arrAlbum['meta'] = new Metadata($arrMeta); $arrAlbum['href'] = $href; - $arrAlbum['pictureCount'] = $pictureCount; + $arrAlbum['countPictures'] = $countPictures; + $arrAlbum['cssClass'] = !(empty(implode(' ', array_filter($arrCssClasses)))) ? implode(' ', array_filter($arrCssClasses)) : false; + $arrAlbum['figureUuid'] = $previewImage ? $previewImage->uuid : null; + $arrAlbum['figureSize'] = !empty($arrSize) ? $arrSize : null; + $arrAlbum['figureOptions'] = [ + 'metadata' => new Metadata($arrMeta), + 'linkHref' => $href, + ]; + $arrAlbum['hasChildAlbums'] = (bool) $childAlbumCount; - $arrAlbum['childAlbumCount'] = $childAlbums ? \count($childAlbums) : 0; + $arrAlbum['countChildAlbums'] = $childAlbums ? \count($childAlbums) : 0; $arrAlbum['childAlbums'] = $childAlbums; - $arrAlbum['figure'] = [ - 'build' => isset($figure) ? $figure->build() : null, - 'uuid' => isset($figure) ? $previewImage->uuid : null, - 'size' => $arrSize, - 'enable_lightbox' => false, - 'meta_data' => new Metadata($arrMeta), - ]; return $arrAlbum; } - public function getAlbumPreviewThumb(GalleryCreatorAlbumsModel $album): FilesModel|null + public function getAlbumPreviewThumb(GalleryCreatorAlbumsModel $albumModel): ?FilesModel { - $picture = GalleryCreatorPicturesModel::findOneById($album->thumb); - - if (null === $picture || !$picture->published) { - return null; + if (null === ($pictureModel = GalleryCreatorPicturesModel::findByPk($albumModel->thumb))) { + $pictureModel = GalleryCreatorPicturesModel::findOneByPid($albumModel->id); } - $files = FilesModel::findByUuid($picture->uuid); - - if (null === $files || !is_file($this->projectDir.'/'.$files->path)) { - return null; + if (null !== $pictureModel && $pictureModel->published && null !== ($filesModel = FilesModel::findByUuid($pictureModel->uuid))) { + return $filesModel; } - return $files; + return null; } /** * @throws Exception * @throws DoctrineDBALDriverException */ - public function getChildAlbums(GalleryCreatorAlbumsModel $album, ContentModel $content, bool $blnOnlyAllowed = false): array|null + public function getChildAlbums(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentElementModel, bool $blnOnlyAllowed = false): ?array { - $strSorting = $content->gcSorting.' '.$content->gcSortingDirection; + $strSorting = $contentElementModel->gcSorting.' '.$contentElementModel->gcSortingDirection; $stmt = $this->connection->executeQuery( - "SELECT * FROM tl_gallery_creator_albums WHERE pid = ? AND published = ? ORDER BY $strSorting", - [$album->id, '1'] + 'SELECT * FROM tl_gallery_creator_albums WHERE pid = ? AND published = ? ORDER BY '.$strSorting, + [$albumModel->id, '1'] ); - $arrChildren = []; + $arrChildAlbums = []; - while (false !== ($arrChild = $stmt->fetchAssociative())) { - $objChild = GalleryCreatorAlbumsModel::findByPk($arrChild['id']); + while (false !== ($objChildAlbums = $stmt->fetchAssociative())) { + $objChildAlbum = GalleryCreatorAlbumsModel::findByPk($objChildAlbums['id']); if ($blnOnlyAllowed) { - if ($content->gcShowAlbumSelection) { - $arrAllowed = StringUtil::deserialize($content->gcAlbumSelection, true); + if ($contentElementModel->gcShowAlbumSelection) { + $arrAllowed = StringUtil::deserialize($contentElementModel->gcAlbumSelection, true); - if (!\in_array($objChild->id, $arrAllowed, false)) { + if (!\in_array($objChildAlbum->id, $arrAllowed, false)) { continue; } - if (!$this->securityUtil->isAuthorized($objChild)) { + if (!$this->securityUtil->isAuthorized($objChildAlbum)) { continue; } } } - if (null !== $objChild) { - $arrChildren[] = $this->getAlbumData($objChild, $content); + if (null !== $objChildAlbum) { + $arrChildAlbums[] = $this->getAlbumData($objChildAlbum, $contentElementModel); } } - return !empty($arrChildren) ? $arrChildren : null; + return !empty($arrChildAlbums) ? $arrChildAlbums : null; } /** * Add meta tags to the page header. */ - protected function addMetaTagsToPage(PageModel $pageModel, GalleryCreatorAlbumsModel $album): void + protected function addMetaTagsToPage(PageModel $pageModel, GalleryCreatorAlbumsModel $albumModel): void { - $pageModel->description = '' !== $album->description ? StringUtil::specialchars($album->description) : StringUtil::specialchars($pageModel->description); + $pageModel->description = '' !== $albumModel->description ? StringUtil::specialchars($albumModel->description) : StringUtil::specialchars($this->pageModel->description); } - protected function triggerGenerateFrontendTemplateHook(FragmentTemplate $template, GalleryCreatorAlbumsModel $album = null): void + protected function triggerGenerateFrontendTemplateHook(Template $template, GalleryCreatorAlbumsModel $albumModel = null): void { // Trigger the galleryCreatorGenerateFrontendTemplate - HOOK if (isset($GLOBALS['TL_HOOKS']['galleryCreatorGenerateFrontendTemplate']) && \is_array($GLOBALS['TL_HOOKS']['galleryCreatorGenerateFrontendTemplate'])) { foreach ($GLOBALS['TL_HOOKS']['galleryCreatorGenerateFrontendTemplate'] as $callback) { - System::importStatic($callback[0])->{$callback[1]}($this, $template, $album); + System::importStatic($callback[0])->{$callback[1]}($this, $template, $albumModel); } } } @@ -263,9 +247,9 @@ protected function triggerGenerateFrontendTemplateHook(FragmentTemplate $templat * * @throws DoctrineDBALException */ - protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $album, ContentModel $contentModel, FragmentTemplate $template, PageModel $pageModel): void + protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, Template $template, PageModel $pageModel): void { - $template->set('album', $this->getAlbumData($album, $contentModel)); + $template->album = $this->getAlbumData($albumModel, $contentModel); } /** @@ -274,26 +258,59 @@ protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $album, ContentM * @throws DoctrineDBALDriverException * @throws DoctrineDBALException */ - protected function addAlbumPicturesToTemplate(GalleryCreatorAlbumsModel $album, ContentModel $contentModel, FragmentTemplate $template, PageModel $pageModel): void + protected function addAlbumPicturesToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, $template, PageModel $pageModel): void { + + + $template->detailPagination = ''; + // Picture sorting $arrSorting = empty($contentModel->gcPictureSorting) || empty($contentModel->gcPictureSortingDirection) ? ['sorting', 'ASC'] : [$contentModel->gcPictureSorting, $contentModel->gcPictureSortingDirection]; // Sort by name will be done below. $arrSorting[0] = str_replace('name', 'id', $arrSorting[0]); - $stmt = $this->connection->createQueryBuilder() + $qb = $this->connection->createQueryBuilder() ->select('*') ->from('tl_gallery_creator_pictures', 't') ->where('t.pid = :pid') ->andWhere('t.published = :published') ->orderBy(...$arrSorting) ->setParameter('published', '1') - ->setParameter('pid', $album->id) - ->executeQuery() + ->setParameter('pid', $albumModel->id) ; - $images = []; + $perPage = (int) $contentModel->gcThumbsPerPage; + + if ($perPage > 0) + { + $id = 'page_d' . $contentModel->id; + $page = Input::get($id) ?? 1; + $total = $this->connection->fetchOne( + 'SELECT COUNT(id) AS itemsTotal FROM tl_gallery_creator_pictures WHERE published = ? AND pid = ?', + ['1', $albumModel->id] + ); + + + // Do not index or cache the page if the page number is outside the range + if ($page < 1 || $page > max(ceil($total/$perPage), 1)) + { + throw new PageNotFoundException('Page not found/Out of pagination range exception: '.Environment::get('uri')); + } + + $offset = ($page - 1) * $perPage; + $limit = min($perPage + $offset, $total); + + $objPagination = new Pagination($total, $perPage, Config::get('maxPaginationLinks'), $id); + $template->detailPagination = $objPagination->generate("\n "); + + $qb->setFirstResult($pagination->getOffset()); + $qb->setMaxResults($pagination->getLimit()); + } + + $arrPictures = []; + + $stmt = $qb->executeQuery(); while (false !== ($rowPicture = $stmt->fetchAssociative())) { $filesModel = FilesModel::findByUuid($rowPicture['uuid']); @@ -303,24 +320,22 @@ protected function addAlbumPicturesToTemplate(GalleryCreatorAlbumsModel $album, $basename = $filesModel->name; } - if (null !== ($picture = GalleryCreatorPicturesModel::findByPk($rowPicture['id']))) { - if ($picture->uuid && $this->pictureUtil->pictureExists($picture)) { - // Prevent overriding items with same basename - $images[$basename.'-id-'.$rowPicture['id']] = $this->pictureUtil->getPictureData($picture, $contentModel); - } + if (null !== ($picturesModel = GalleryCreatorPicturesModel::findByPk($rowPicture['id']))) { + // Prevent overriding items with same basename + $arrPictures[$basename.'-id-'.$rowPicture['id']] = $this->pictureUtil->getPictureData($picturesModel, $contentModel); } } // Sort by name if ('name' === $contentModel->gcPictureSorting) { if ('ASC' === $contentModel->gcPictureSortingDirection) { - uksort($images, static fn ($a, $b): int => strnatcasecmp(basename($a), basename($b))); + uksort($arrPictures, static fn ($a, $b): int => strnatcasecmp(basename($a), basename($b))); } else { - uksort($images, static fn ($a, $b): int => -strnatcasecmp(basename($a), basename($b))); + uksort($arrPictures, static fn ($a, $b): int => -strnatcasecmp(basename($a), basename($b))); } } // Add pictures to the template. - $template->set('images', array_values($images)); + $template->arrPictures = array_values($arrPictures); } } diff --git a/src/Controller/ContentElement/DependencyAggregate.php b/src/Controller/ContentElement/DependencyAggregate.php index 56d21d5..6c716a0 100644 --- a/src/Controller/ContentElement/DependencyAggregate.php +++ b/src/Controller/ContentElement/DependencyAggregate.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -14,7 +14,6 @@ namespace Markocupic\GalleryCreatorBundle\Controller\ContentElement; -use Contao\CoreBundle\Image\Studio\Studio; use Contao\CoreBundle\InsertTag\InsertTagParser; use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor; use Contao\CoreBundle\Routing\ScopeMatcher; @@ -24,23 +23,29 @@ use Markocupic\GalleryCreatorBundle\Util\MarkdownUtil; use Markocupic\GalleryCreatorBundle\Util\PictureUtil; use Markocupic\GalleryCreatorBundle\Util\SecurityUtil; -use Symfony\Component\HttpFoundation\RequestStack; final class DependencyAggregate { - public function __construct( - public readonly AlbumUtil $albumUtil, - public readonly Connection $connection, - public readonly HtmlDecoder $htmlDecoder, - public readonly InsertTagParser $insertTagParser, - public readonly MarkdownUtil $markdownUtil, - public readonly PictureUtil $pictureUtil, - public readonly RequestStack $requestStack, - public readonly ResponseContextAccessor $responseContextAccessor, - public readonly ScopeMatcher $scopeMatcher, - public readonly SecurityUtil $securityUtil, - public readonly Studio $studio, - public readonly string $projectDir, - ) { + public AlbumUtil $albumUtil; + public Connection $connection; + public MarkdownUtil $markdownUtil; + public PictureUtil $pictureUtil; + public SecurityUtil $securityUtil; + public ScopeMatcher $scopeMatcher; + public ResponseContextAccessor $responseContextAccessor; + public InsertTagParser $insertTagParser; + public HtmlDecoder $htmlDecoder; + + public function __construct(AlbumUtil $albumUtil, Connection $connection, MarkdownUtil $markdownUtil, PictureUtil $pictureUtil, SecurityUtil $securityUtil, ScopeMatcher $scopeMatcher, ResponseContextAccessor $responseContextAccessor, InsertTagParser $insertTagParser, HtmlDecoder $htmlDecoder) + { + $this->albumUtil = $albumUtil; + $this->connection = $connection; + $this->markdownUtil = $markdownUtil; + $this->pictureUtil = $pictureUtil; + $this->securityUtil = $securityUtil; + $this->scopeMatcher = $scopeMatcher; + $this->responseContextAccessor = $responseContextAccessor; + $this->insertTagParser = $insertTagParser; + $this->htmlDecoder = $htmlDecoder; } } diff --git a/src/Controller/ContentElement/GalleryCreatorController.php b/src/Controller/ContentElement/GalleryCreatorController.php index 7c84b54..acff938 100644 --- a/src/Controller/ContentElement/GalleryCreatorController.php +++ b/src/Controller/ContentElement/GalleryCreatorController.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -16,18 +16,18 @@ use Contao\Config; use Contao\ContentModel; -use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\CoreBundle\Framework\Adapter; use Contao\CoreBundle\Framework\ContaoFramework; +use Contao\CoreBundle\ServiceAnnotation\ContentElement; use Contao\CoreBundle\String\HtmlDecoder; -use Contao\CoreBundle\Twig\FragmentTemplate; use Contao\Environment; use Contao\FrontendTemplate; use Contao\Input; use Contao\PageModel; use Contao\Pagination; use Contao\StringUtil; +use Contao\Template; use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; use Doctrine\DBAL\Exception as DoctrineDBALException; use FOS\HttpCacheBundle\Http\SymfonyResponseTagger; @@ -39,16 +39,22 @@ use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; -#[AsContentElement(category: 'gallery_creator_elements')] +/** + * @ContentElement(GalleryCreatorController::TYPE, category="gallery_creator_elements") + */ class GalleryCreatorController extends AbstractGalleryCreatorController { public const TYPE = 'gallery_creator'; - protected string|null $viewMode = null; - protected GalleryCreatorAlbumsModel|null $activeAlbum = null; + protected ContaoFramework $framework; + protected TwigEnvironment $twig; + protected HtmlDecoder $htmlDecoder; + protected ?SymfonyResponseTagger $responseTagger; + protected ?string $viewMode = null; + protected ?GalleryCreatorAlbumsModel $activeAlbum = null; protected array $arrAlbumListing = []; - protected ContentModel|null $model; - protected PageModel|null $pageModel; + protected ?ContentModel $model; + protected ?PageModel $pageModel; // Adapters protected Adapter $config; @@ -60,14 +66,13 @@ class GalleryCreatorController extends AbstractGalleryCreatorController private bool $showAlbumDetail = false; private bool $showAlbumListing = false; - public function __construct( - DependencyAggregate $dependencyAggregate, - private readonly ContaoFramework $framework, - private readonly TwigEnvironment $twig, - protected HtmlDecoder $htmlDecoder, - private readonly SymfonyResponseTagger|null $responseTagger, - ) { + public function __construct(DependencyAggregate $dependencyAggregate, ContaoFramework $framework, TwigEnvironment $twig, HtmlDecoder $htmlDecoder, ?SymfonyResponseTagger $responseTagger) + { parent::__construct($dependencyAggregate); + $this->framework = $framework; + $this->twig = $twig; + $this->htmlDecoder = $htmlDecoder; + $this->responseTagger = $responseTagger; // Adapters $this->config = $this->framework->getAdapter(Config::class); @@ -110,7 +115,7 @@ public function __invoke(Request $request, ContentModel $model, string $section, $arrIds = $this->stringUtil->deserialize($model->gcAlbumSelection, true); if (!empty($arrIds)) { - $pid = $this->connection->fetchOne('SELECT pid FROM tl_gallery_creator_albums WHERE id IN('.implode(',', array_map('intval', $arrIds)).') ORDER BY pid'); + $pid = $this->connection->fetchOne('SELECT pid FROM tl_gallery_creator_albums WHERE id IN('.implode(',', $arrIds).') ORDER BY pid'); $this->arrAlbumListing = $this->getAlbumsByPid($pid); } else { return new Response('', Response::HTTP_NO_CONTENT); @@ -159,22 +164,21 @@ public function __invoke(Request $request, ContentModel $model, string $section, * @throws DoctrineDBALDriverException * @throws DoctrineDBALException */ - protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response + protected function getResponse(Template $template, ContentModel $model, Request $request): Response { // Set defaults - $template->set('showAlbumDetail', false); - $template->set('showAlbumListing', false); - $template->set('hasBreadcrumb', false); - $template->set('items_per_page', $model->gcThumbsPerPage); + $template->showAlbumDetail = false; + $template->showAlbumListing = false; + $template->hasBreadcrumb = false; if ($this->model->gcAddBreadcrumb) { - $template->set('hasBreadcrumb', true); - $template->set('breadcrumb', $this->generateBreadcrumb()); + $template->hasBreadcrumb = true; + $template->breadcrumb = $this->generateBreadcrumb(); } if ($this->showAlbumListing) { - $template->set('showAlbumListing', true); - $template->set('listPagination', ''); + $template->showAlbumListing = true; + $template->listPagination = ''; // Add a CSS class to the body tag $this->pageModel->loadDetails()->cssClass = $this->pageModel->loadDetails()->cssClass.' gc-listing-view'; @@ -197,26 +201,26 @@ protected function getResponse(FragmentTemplate $template, ContentModel $model, $limit = min($perPage + $offset, $total); $objPagination = new Pagination($total, $perPage, $this->config->get('maxPaginationLinks'), $id); - $template->set('listPagination', $objPagination->generate("\n ")); + $template->listPagination = $objPagination->generate("\n "); // Paginate the result $arrItems = \array_slice($arrItems, $offset, $limit); } - $template->set('albums', array_map( + $template->albums = array_map( function ($id) { $albumModel = $this->galleryCreatorAlbumsModel->findByPk($id); return null !== $albumModel ? $this->getAlbumData($albumModel, $this->model) : []; }, $arrItems - )); + ); - $template->set('content', $this->model->row()); + $template->content = $this->model->row(); } if ($this->showAlbumDetail) { - $template->set('showAlbumDetail', true); + $template->showAlbumDetail = true; // Add a CSS class to the body tag $this->pageModel->loadDetails()->cssClass = $this->pageModel->loadDetails()->cssClass.' gc-detail-view'; @@ -233,10 +237,10 @@ function ($id) { $this->albumUtil->countAlbumViews($this->activeAlbum); // Add content model to template. - $template->set('content', $model->row()); + $template->content = $model->row(); // Get the album level - $template->set('level', $this->albumUtil->getAlbumLevelFromPid((int) $this->activeAlbum->pid)); + $template->level = $this->albumUtil->getAlbumLevelFromPid((int) $this->activeAlbum->pid); // Add meta tags to the page header. $this->addMetaTagsToPage($this->pageModel, $this->activeAlbum); @@ -324,23 +328,20 @@ protected function isInSelection(GalleryCreatorAlbumsModel $albumModel): bool * * @throws DoctrineDBALException */ - protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, FragmentTemplate $template, PageModel $pageModel): void + protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, Template $template, PageModel $pageModel): void { parent::addAlbumToTemplate($albumModel, $contentModel, $template, $pageModel); // Back link - $template->set('backLink', $this->generateBackLink($albumModel) ?: false); + $template->backLink = $this->generateBackLink($albumModel) ?: false; // In the detail view, an article can optionally be added in front of the album - $template->set('insertArticlePre', $albumModel->insertArticlePre ? sprintf('{{insert_article::%s}}', $albumModel->insertArticlePre) : false); + $template->insertArticlePre = $albumModel->insertArticlePre ? sprintf('{{insert_article::%s}}', $albumModel->insertArticlePre) : false; // In the detail view, an article can optionally be added right after the album - $template->set('insertArticlePost', $albumModel->insertArticlePost ? sprintf('{{insert_article::%s}}', $albumModel->insertArticlePost) : false); + $template->insertArticlePost = $albumModel->insertArticlePost ? sprintf('{{insert_article::%s}}', $albumModel->insertArticlePost) : false; } - /** - * @throws \Exception - */ protected function generateBreadcrumb(): string { $items = []; diff --git a/src/Controller/ContentElement/GalleryCreatorNewsController.php b/src/Controller/ContentElement/GalleryCreatorNewsController.php index 3c68811..47a4948 100644 --- a/src/Controller/ContentElement/GalleryCreatorNewsController.php +++ b/src/Controller/ContentElement/GalleryCreatorNewsController.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -15,9 +15,9 @@ namespace Markocupic\GalleryCreatorBundle\Controller\ContentElement; use Contao\ContentModel; -use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; -use Contao\CoreBundle\Twig\FragmentTemplate; +use Contao\CoreBundle\ServiceAnnotation\ContentElement; use Contao\PageModel; +use Contao\Template; use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; use Doctrine\DBAL\Exception as DoctrineDBALException; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; @@ -25,19 +25,22 @@ use Symfony\Component\HttpFoundation\Response; use Twig\Environment as TwigEnvironment; -#[AsContentElement(category: 'gallery_creator_elements')] +/** + * @ContentElement(GalleryCreatorNewsController::TYPE, category="gallery_creator_elements") + */ class GalleryCreatorNewsController extends AbstractGalleryCreatorController { public const TYPE = 'gallery_creator_news'; - protected GalleryCreatorAlbumsModel|null $activeAlbum = null; - protected ContentModel|null $model = null; - protected PageModel|null $pageModel = null; + protected TwigEnvironment $twig; + protected ?GalleryCreatorAlbumsModel $activeAlbum = null; + protected ?ContentModel $model = null; + protected ?PageModel $pageModel = null; + + public function __construct(DependencyAggregate $dependencyAggregate, TwigEnvironment $twig) + { + $this->twig = $twig; - public function __construct( - DependencyAggregate $dependencyAggregate, - private readonly TwigEnvironment $twig, - ) { parent::__construct($dependencyAggregate); } @@ -81,7 +84,7 @@ public function __invoke(Request $request, ContentModel $model, string $section, * * @return Response|null */ - protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response + protected function getResponse(Template $template, ContentModel $model, Request $request): Response { // Add the picture collection and the pagination to the template. $this->addAlbumPicturesToTemplate($this->activeAlbum, $this->model, $template, $this->pageModel); @@ -93,7 +96,7 @@ protected function getResponse(FragmentTemplate $template, ContentModel $model, $this->albumUtil->countAlbumViews($this->activeAlbum); // Add content model to template. - $template->set('content', $model->row()); + $template->content = $model->row(); // Add meta tags to the page header. $this->addMetaTagsToPage($this->pageModel, $this->activeAlbum); @@ -107,7 +110,7 @@ protected function getResponse(FragmentTemplate $template, ContentModel $model, /** * Augment template with some more properties of the active album. */ - protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, FragmentTemplate $template, PageModel $pageModel): void + protected function addAlbumToTemplate(GalleryCreatorAlbumsModel $albumModel, ContentModel $contentModel, Template $template, PageModel $pageModel): void { parent::addAlbumToTemplate($albumModel, $contentModel, $template, $pageModel); } diff --git a/src/DataContainer/Content.php b/src/DataContainer/Content.php index c057e08..865af3a 100644 --- a/src/DataContainer/Content.php +++ b/src/DataContainer/Content.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -14,22 +14,37 @@ namespace Markocupic\GalleryCreatorBundle\DataContainer; -use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; +use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\DataContainer; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\Exception; +use Markocupic\GalleryCreatorBundle\Util\AlbumUtil; +use Symfony\Component\HttpFoundation\RequestStack; +use Twig\Environment as TwigEnvironment; class Content { - public function __construct( - private readonly Connection $connection, - ) { + private AlbumUtil $albumUtil; + private Connection $connection; + private RequestStack $requestStack; + private TwigEnvironment $twig; + + public function __construct(AlbumUtil $albumUtil, Connection $connection, RequestStack $requestStack, TwigEnvironment $twig) + { + $this->albumUtil = $albumUtil; + $this->connection = $connection; + $this->requestStack = $requestStack; + $this->twig = $twig; } /** + * Options callback. + * + * @Callback(table="tl_content", target="fields.gcPublishSingleAlbum.options") + * * @throws Exception + * @throws \Doctrine\DBAL\Exception */ - #[AsCallback(table: 'tl_content', target: 'fields.gcPublishSingleAlbum.options', priority: 100)] public function optionsCbGcPublishSingleAlbum(DataContainer $dc): array { $arrOpt = []; diff --git a/src/DataContainer/GalleryCreatorAlbums.php b/src/DataContainer/GalleryCreatorAlbums.php index 13f477a..952114d 100644 --- a/src/DataContainer/GalleryCreatorAlbums.php +++ b/src/DataContainer/GalleryCreatorAlbums.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -20,13 +20,13 @@ use Contao\Config; use Contao\Controller; use Contao\CoreBundle\DataContainer\PaletteManipulator; -use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; use Contao\CoreBundle\Exception\RedirectResponseException; use Contao\CoreBundle\Exception\ResponseException; use Contao\CoreBundle\Framework\Adapter; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Image\ImageFactory; use Contao\CoreBundle\Security\ContaoCorePermissions; +use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\DataContainer; use Contao\Dbafs; use Contao\File; @@ -37,7 +37,6 @@ use Contao\Message; use Contao\StringUtil; use Contao\System; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Exception as DoctrineDBALException; @@ -47,59 +46,70 @@ use Markocupic\GalleryCreatorBundle\Revise\ReviseAlbumDatabase; use Markocupic\GalleryCreatorBundle\Security\GalleryCreatorAlbumPermissions; use Markocupic\GalleryCreatorBundle\Util\FileUtil; -use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment as TwigEnvironment; -use Twig\Error\LoaderError; -use Twig\Error\RuntimeError; -use Twig\Error\SyntaxError; class GalleryCreatorAlbums { + protected CacheManager $cacheManager; + private ContaoFramework $framework; + private RequestStack $requestStack; + private FileUtil $fileUtil; + private Connection $connection; + private Security $security; + private TranslatorInterface $translator; + private ImageFactory $imageFactory; + private TwigEnvironment $twig; + private ReviseAlbumDatabase $reviseAlbumDatabase; + private string $projectDir; + private string $galleryCreatorUploadPath; + private array $galleryCreatorValidExtensions; + // Adapters private Adapter $albums; private Adapter $backend; + private Adapter $config; private Adapter $controller; private Adapter $image; private Adapter $message; private Adapter $pictures; private Adapter $stringUtil; private Adapter $system; - private Adapter $config; /** * @throws DoctrineDBALException - * @throws Exception */ - public function __construct( - private readonly ContaoFramework $framework, - private readonly RequestStack $requestStack, - private readonly FileUtil $fileUtil, - private readonly Connection $connection, - private readonly Security $security, - private readonly TranslatorInterface $translator, - private readonly ImageFactory $imageFactory, - private readonly TwigEnvironment $twig, - private readonly ReviseAlbumDatabase $reviseAlbumDatabase, - private readonly CacheManager $cacheManager, - private readonly string $projectDir, - private readonly string $galleryCreatorUploadPath, - private readonly array $galleryCreatorValidExtensions, - ) { + public function __construct(ContaoFramework $framework, RequestStack $requestStack, FileUtil $fileUtil, Connection $connection, Security $security, TranslatorInterface $translator, ImageFactory $imageFactory, TwigEnvironment $twig, ReviseAlbumDatabase $reviseAlbumDatabase, CacheManager $cacheManager, string $projectDir, string $galleryCreatorUploadPath, array $galleryCreatorValidExtensions) + { + $this->framework = $framework; + $this->requestStack = $requestStack; + $this->fileUtil = $fileUtil; + $this->connection = $connection; + $this->security = $security; + $this->translator = $translator; + $this->imageFactory = $imageFactory; + $this->twig = $twig; + $this->reviseAlbumDatabase = $reviseAlbumDatabase; + $this->cacheManager = $cacheManager; + $this->projectDir = $projectDir; + $this->galleryCreatorUploadPath = $galleryCreatorUploadPath; + $this->galleryCreatorValidExtensions = $galleryCreatorValidExtensions; + // Adapters $this->albums = $this->framework->getAdapter(GalleryCreatorAlbumsModel::class); $this->backend = $this->framework->getAdapter(Backend::class); + $this->config = $this->framework->getAdapter(Config::class); $this->controller = $this->framework->getAdapter(Controller::class); $this->image = $this->framework->getAdapter(Image::class); $this->message = $this->framework->getAdapter(Message::class); $this->pictures = $this->framework->getAdapter(GalleryCreatorPicturesModel::class); $this->stringUtil = $this->framework->getAdapter(StringUtil::class); $this->system = $this->framework->getAdapter(System::class); - $this->config = $this->framework->getAdapter(Config::class); $request = $this->requestStack->getCurrentRequest(); @@ -108,9 +118,17 @@ public function __construct( } } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function checkPermissions(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload", priority=110) + */ + public function onloadCallbackCheckPermissions(DataContainer $dc): void { + if (!$dc) { + return; + } + $user = $this->security->getUser(); $request = $this->requestStack->getCurrentRequest(); @@ -210,9 +228,29 @@ public function checkPermissions(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function setPalettes(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload", priority="120") + */ + public function checkHasDefaultChmod(DataContainer $dc): void + { + if (!$this->config->gcDefaultChmod) { + //$this->message->addInfo($this->translator->trans) + } + } + + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload") + */ + public function onloadCallbackSetPalettes(DataContainer $dc): void { + if (!$dc) { + return; + } + $user = $this->security->getUser(); $request = $this->requestStack->getCurrentRequest(); @@ -234,7 +272,7 @@ public function setPalettes(DataContainer $dc): void $dca = &$GLOBALS['TL_DCA']['tl_gallery_creator_albums']; - // Allow database revise to admins only + // Permit revise database to admins only if (!$user->admin) { unset( $dca['list']['global_operations']['reviseDatabase'] @@ -268,10 +306,14 @@ public function setPalettes(DataContainer $dc): void } /** + * Onload callback. * Handle image sorting ajax requests. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload") + * + * @throws DoctrineDBALException */ - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function sortPictures(): void + public function onloadCallbackSortPictures(): void { $request = $this->requestStack->getCurrentRequest(); @@ -280,8 +322,6 @@ public function sortPictures(): void if ($request->query->has('pictureSorting')) { $count = 0; - $picturesModel = null; - foreach ($this->stringUtil->trimsplit(',', $request->query->get('pictureSorting')) as $pictureId) { $picturesModel = $this->pictures->findByPk($pictureId); @@ -305,10 +345,61 @@ public function sortPictures(): void } } + /** + * Revise tables. + * This method is called by self::__construct();. + * + * @throws DoctrineDBALException + */ + public function reviseTables(): void + { + $user = $this->security->getUser(); + $request = $this->requestStack->getCurrentRequest(); + $session = $request->getSession(); + + if ($request->query->has('isAjaxRequest')) { + // Revise table in the backend + if ($request->query->has('checkTables')) { + if ($request->query->has('getAlbumIDS')) { + $arrIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_gallery_creator_albums ORDER BY RAND()'); + + throw new ResponseException(new JsonResponse(['ids' => $arrIds])); + } + + if ($request->query->has('albumId')) { + $albumsModel = $this->albums->findByPk($request->query->get('albumId', 0)); + + if (null !== $albumsModel) { + if ($request->query->has('checkTables') || $request->query->has('reviseTables')) { + // Delete damaged data records + $blnCleanDb = $user->admin && $request->query->has('reviseTables'); + + $this->reviseAlbumDatabase->run($albumsModel, $blnCleanDb); + + if ($session->has('gc_error') && \is_array($session->get('gc_error'))) { + if (!empty($session->get('gc_error'))) { + $arrErrors = $session->get('gc_error'); + + if (!empty($arrErrors)) { + throw new ResponseException(new JsonResponse(['errors' => $arrErrors])); + } + } + } + } + } + $session->remove('gc_error'); + } + } + + throw new ResponseException(new Response('', Response::HTTP_NO_CONTENT)); + } + } + /** * Return the "toggle visibility" button. + * + * @Callback(table="tl_gallery_creator_albums", target="list.operations.toggle.button") */ - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.operations.toggle.button', priority: 100)] public function toggleVisibility(array $row, string $href, string $label, string $title, string $icon, string $attributes): string { // Check permissions AFTER checking the tid, so hacking attempts are logged @@ -327,32 +418,33 @@ public function toggleVisibility(array $row, string $href, string $label, string $icon = preg_replace('/\.svg$/i', '_.svg', $icon); // see #8126 } - return $this->image->getHtml($icon).' '; + return Image::getHtml($icon).' '; } - return ''.$this->image->getHtml($icon, $label, 'data-icon="'.$this->image->getPath('visible.svg').'" data-icon-disabled="'.$this->image->getPath('invisible.svg').'" data-state="'.($row['published'] ? 1 : 0).'"').' '; + return ''.Image::getHtml($icon, $label, 'data-icon="'.Image::getPath('visible.svg').'" data-icon-disabled="'.Image::getPath('invisible.svg').'" data-state="'.($row['published'] ? 1 : 0).'"').' '; } /** * Button callback. + * + * @Callback(table="tl_gallery_creator_albums", target="list.operations.editheader.button") + * @Callback(table="tl_gallery_creator_albums", target="list.operations.delete.button") + * @Callback(table="tl_gallery_creator_albums", target="list.operations.uploadImages.button") + * @Callback(table="tl_gallery_creator_albums", target="list.operations.importImagesFromFilesystem.button") */ - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.operations.editheader.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.operations.delete.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.operations.uploadImages.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.operations.importImagesFromFilesystem.button', priority: 100)] - public function buttonCallback(array $row, string|null $href, string $label, string $title, string|null $icon, string $attributes): string + public function buttonCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string { $href .= '&id='.$row['id']; $blnGranted = false; - if (str_contains($href, 'act=edit') && str_contains($href, 'key=fileUpload')) { + if (false !== strpos($href, 'act=edit') && false !== strpos($href, 'key=fileUpload')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_ADD_AND_EDIT_IMAGES, $row['id']); - } elseif (str_contains($href, 'act=edit') && str_contains($href, 'key=importImagesFromFilesystem')) { + } elseif (false !== strpos($href, 'act=edit') && false !== strpos($href, 'key=importImagesFromFilesystem')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_ADD_AND_EDIT_IMAGES, $row['id']); - } elseif (str_contains($href, 'act=edit')) { + } elseif (false !== strpos($href, 'act=edit')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_EDIT_ALBUM, $row['id']); - } elseif (str_contains($href, 'act=delete')) { + } elseif (false !== strpos($href, 'act=delete')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_EDIT_ALBUM, $row['id']); } @@ -369,8 +461,12 @@ public function buttonCallback(array $row, string|null $href, string $label, str return $this->image->getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' '; } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.reviseDatabase.input_field', priority: 100)] - public function getReviseDatabaseWidget(): string + /** + * Input field callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.reviseDatabase.input_field") + */ + public function inputFieldCallbackReviseDatabase(): string { $translator = $this->system->getContainer()->get('translator'); @@ -389,8 +485,12 @@ public function getReviseDatabaseWidget(): string ))->getContent(); } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.fileUpload.input_field', priority: 100)] - public function getFileUploadWidget(): string + /** + * Input field callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.fileUpload.input_field") + */ + public function inputFieldCallbackFileUpload(): string { // Create the template object $objTemplate = new BackendTemplate('be_gc_uploader'); @@ -410,7 +510,13 @@ public function getFileUploadWidget(): string return $objTemplate->parse(); } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'list.label.label', priority: 100)] + /** + * Label callback. + * + * @Callback(table="tl_gallery_creator_albums", target="list.label.label") + * + * @throws DoctrineDBALException + */ public function labelCallback(array $row, string $label): string { $countImages = $this->connection->fetchOne('SELECT count(id) as countImg FROM tl_gallery_creator_pictures WHERE pid = ?', [$row['id']]); @@ -423,41 +529,65 @@ public function labelCallback(array $row, string $label): string $label = str_replace('#icon#', $icon, $label); $label = str_replace('#count_pics#', (string) $countImages, $label); - return str_replace('#datum#', date($this->config->get('dateFormat'), (int) $row['date']), $label); + $config = $this->framework->getAdapter(Config::class); + + return str_replace('#datum#', date($config->get('dateFormat'), (int) $row['date']), $label); } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'edit.buttons', priority: 100)] - public function setFormSubmitButtons(array $arrButtons, DataContainer $dc): array + /** + * Load callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.imageResolution.load") + */ + public function loadCallbackImageResolution(): string + { + $user = $this->security->getUser(); + + return $user->gcImageResolution; + } + + /** + * Buttons callback. + * + * @Callback(table="tl_gallery_creator_albums", target="edit.buttons") + */ + public function editButtonsCallback(array $arrButtons, DataContainer $dc): array { $request = $this->requestStack->getCurrentRequest(); if ('reviseDatabase' === $request->query->get('key')) { - // Remove useless buttons + // Remove buttons unset($arrButtons['saveNcreate'], $arrButtons['saveNclose']); - // Replace the save button with the revise table button. - $arrButtons['save'] = sprintf( - '', - $this->translator->trans('tl_gallery_creator_albums.reviseTablesBtn', [], 'contao_default'), - ); + $arrButtons['save'] = ''; } if ('fileUpload' === $request->query->get('key')) { - // Remove useless buttons + // Remove buttons unset($arrButtons['save'], $arrButtons['saveNclose'], $arrButtons['saveNcreate']); } if ('importImagesFromFilesystem' === $request->query->get('key')) { - // Remove useless buttons + // Remove buttons unset($arrButtons['saveNclose'], $arrButtons['saveNcreate'], $arrButtons['uploadNback']); } return $arrButtons; } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.ondelete', priority: 100)] + /** + * Ondelete callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.ondelete") + * + * @throws DoctrineDBALException + */ public function ondeleteCallback(DataContainer $dc, int $undoId): void { + if (!$dc) { + return; + } + // Also delete child albums $arrDeletedAlbums = $this->albums->getChildAlbumsIds((int) $dc->id); $arrDeletedAlbums = array_merge([$dc->id], $arrDeletedAlbums ?? []); @@ -487,8 +617,8 @@ public function ondeleteCallback(DataContainer $dc, int $undoId): void $fileUuid = $picturesModel->uuid; // Delete the picture from the filesystem if it is not used by another album - if (null !== $this->pictures->findOneByUuid($fileUuid)) { - $filesModel = $files->findOneByUuid($fileUuid); + if (null !== $this->pictures->findByUuid($fileUuid)) { + $filesModel = $files->findByUuid($fileUuid); if (null !== $filesModel) { $file = new File($filesModel->path); @@ -498,7 +628,7 @@ public function ondeleteCallback(DataContainer $dc, int $undoId): void } } - $filesModel = $files->findOneByUuid($albumsModel->assignedDir); + $filesModel = $files->findByUuid($albumsModel->assignedDir); if (null !== $filesModel) { $finder = new Finder(); @@ -515,8 +645,12 @@ public function ondeleteCallback(DataContainer $dc, int $undoId): void } } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function checkAlbumFolder(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload") + */ + public function onloadCallbackCheckFolderSettings(DataContainer $dc): void { // Create the upload directory if it doesn't already exist $objFolder = new Folder($this->galleryCreatorUploadPath); @@ -533,12 +667,16 @@ public function checkAlbumFolder(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function uploadFile(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload") + */ + public function onloadCallbackFileUpload(DataContainer $dc): void { $request = $this->requestStack->getCurrentRequest(); - if ('fileUpload' !== $request->query->get('key')) { + if (!$dc || 'fileUpload' !== $request->query->get('key')) { return; } @@ -551,7 +689,7 @@ public function uploadFile(DataContainer $dc): void // Load language file $this->controller->loadLanguageFile('tl_files'); - // Store uploaded files under $_FILES['file'] + // Store uploaded files to $_FILES['file'] $strName = 'file'; // Return if there is no album @@ -563,8 +701,8 @@ public function uploadFile(DataContainer $dc): void $files = $this->framework->getAdapter(FilesModel::class); - // Return if the album directory does not exist. - $objUploadDir = $files->findOneByUuid($albumsModel->assignedDir); + // Return if there is no album directory + $objUploadDir = $files->findByUuid($albumsModel->assignedDir); if (null === $objUploadDir || !is_dir($this->projectDir.'/'.$objUploadDir->path)) { $this->message->addError('No upload directory defined in the album settings!'); @@ -602,9 +740,17 @@ public function uploadFile(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onload', priority: 100)] - public function importFromFilesystem(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_albums", target="config.onload") + */ + public function onloadCallbackImportFromFilesystem(DataContainer $dc): void { + if (!$dc) { + return; + } + $request = $this->requestStack->getCurrentRequest(); if ('importImagesFromFilesystem' !== $request->query->get('key')) { @@ -644,9 +790,15 @@ public function importFromFilesystem(DataContainer $dc): void throw new RedirectResponseException('contao?do=gallery_creator'); } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'config.onsubmit', priority: 100)] - public function invalidateCacheOnAlbumUpdate(DataContainer $dc): void + /** + * @Callback(table="tl_gallery_creator_albums", target="config.onsubmit") + */ + public function onSubmitInvalidateCache(DataContainer $dc): void { + if (!$dc) { + return; + } + // Invalidate cache tags. $arrTags = [ 'contao.db.tl_gallery_creator_albums.'.$dc->id, @@ -660,13 +812,12 @@ public function invalidateCacheOnAlbumUpdate(DataContainer $dc): void * * List all images of the album (and child albums). * + * @Callback(table="tl_gallery_creator_albums", target="fields.thumb.input_field") + * * @throws DoctrineDBALException - * @throws LoaderError - * @throws RuntimeError - * @throws SyntaxError + * @throws Exception */ - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.thumb.input_field', priority: 100)] - public function getAlbumThumbsWidget(): string + public function inputFieldCallbackThumb(): string { $request = $this->requestStack->getCurrentRequest(); @@ -705,7 +856,7 @@ public function getAlbumThumbsWidget(): string $stmt = $this->connection->executeQuery( 'SELECT * FROM tl_gallery_creator_pictures WHERE pid IN (?) ORDER BY id', [$arrChildAlbums], - [ArrayParameterType::INTEGER] + [Connection::PARAM_INT_ARRAY] ); while (false !== ($arrPicture = $stmt->fetchAssociative())) { @@ -725,7 +876,7 @@ public function getAlbumThumbsWidget(): string foreach ($arrData as $ii => $arrItem) { $files = $this->framework->getAdapter(FilesModel::class); - $filesModel = $files->findOneByUuid($arrItem['uuid']); + $filesModel = $files->findByUuid($arrItem['uuid']); if (null !== $filesModel) { if (file_exists($filesModel->getAbsolutePath())) { @@ -737,7 +888,9 @@ public function getAlbumThumbsWidget(): string $src = $file->path; - if ($file->height <= $this->config->get('gdMaxImgHeight') && $file->width <= $this->config->get('gdMaxImgWidth')) { + $config = $this->framework->getAdapter(Config::class); + + if ($file->height <= $config->get('gdMaxImgHeight') && $file->width <= $config->get('gdMaxImgWidth')) { $image = $this->imageFactory->create( $this->projectDir.'/'.$src, [80, 60, 'center_center'] @@ -776,8 +929,12 @@ public function getAlbumThumbsWidget(): string ))->getContent(); } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.filePrefix.save', priority: 100)] - public function validateFilePrefix(string $strPrefix, DataContainer $dc): string + /** + * Save callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.filePrefix.save") + */ + public function saveCallbackValidateFilePrefix(string $strPrefix, DataContainer $dc): string { $i = 0; @@ -826,8 +983,12 @@ public function validateFilePrefix(string $strPrefix, DataContainer $dc): string return ''; } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.sortBy.save', priority: 100)] - public function sortAlbumEntities(string $varValue, DataContainer $dc): string + /** + * Save callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.sortBy.save") + */ + public function saveCallbackSortBy(string $varValue, DataContainer $dc): string { if ('----' === $varValue) { return $varValue; @@ -845,7 +1006,7 @@ public function sortAlbumEntities(string $varValue, DataContainer $dc): string while ($picturesModels->next()) { $files = $this->framework->getAdapter(FilesModel::class); - $filesModel = $files->findOneByUuid($picturesModels->uuid); + $filesModel = $files->findByUuid($picturesModels->uuid); $file = new File($filesModel->path); $arrFiles[$filesModel->path] = [ @@ -897,9 +1058,10 @@ public function sortAlbumEntities(string $varValue, DataContainer $dc): string * Generate a unique album alias based on the album name * and create a directory with the same name * + * @Callback(table="tl_gallery_creator_albums", target="fields.alias.save") + * * @throws DoctrineDBALException */ - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.alias.save', priority: 100)] public function saveCallbackSetAliasAndUploadFolder(string $strAlias, DataContainer $dc): string { $request = $this->requestStack->getCurrentRequest(); @@ -956,67 +1118,17 @@ public function saveCallbackSetAliasAndUploadFolder(string $strAlias, DataContai return $strAlias; } - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.imageResolution.load', priority: 100)] - public function getImageResolution(): string - { - $user = $this->security->getUser(); - - return $user->gcImageResolution; - } - - #[AsCallback(table: 'tl_gallery_creator_albums', target: 'fields.imageResolution.save', priority: 100)] - public function setImageResolution(string $value): void - { - $user = $this->security->getUser(); - - $this->connection->update('tl_user', ['gcImageResolution' => $value], ['id' => $user->id]); - } - /** + * Save callback. + * + * @Callback(table="tl_gallery_creator_albums", target="fields.imageResolution.save") + * * @throws DoctrineDBALException - * @throws Exception */ - private function reviseTables(): void + public function saveCallbackImageResolution(string $value): void { $user = $this->security->getUser(); - $request = $this->requestStack->getCurrentRequest(); - $session = $request->getSession(); - if ($request->query->has('isAjaxRequest')) { - // Revise table in the backend - if ($request->query->has('checkTables')) { - if ($request->query->has('getAlbumIDS')) { - $arrIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_gallery_creator_albums ORDER BY RAND()'); - - throw new ResponseException(new JsonResponse(['ids' => $arrIds])); - } - - if ($request->query->has('albumId')) { - $albumsModel = $this->albums->findByPk($request->query->get('albumId', 0)); - - if (null !== $albumsModel) { - if ($request->query->has('checkTables') || $request->query->has('reviseTables')) { - // Delete damaged data records - $blnCleanDb = $user->admin && $request->query->has('reviseTables'); - - $this->reviseAlbumDatabase->run($albumsModel, $blnCleanDb); - - if ($session->has('gc_error') && \is_array($session->get('gc_error'))) { - if (!empty($session->get('gc_error'))) { - $arrErrors = $session->get('gc_error'); - - if (!empty($arrErrors)) { - throw new ResponseException(new JsonResponse(['errors' => $arrErrors])); - } - } - } - } - } - $session->remove('gc_error'); - } - } - - throw new ResponseException(new Response('', Response::HTTP_NO_CONTENT)); - } + $this->connection->update('tl_user', ['gcImageResolution' => $value], ['id' => $user->id]); } } diff --git a/src/DataContainer/GalleryCreatorPictures.php b/src/DataContainer/GalleryCreatorPictures.php index a52c349..43edff6 100644 --- a/src/DataContainer/GalleryCreatorPictures.php +++ b/src/DataContainer/GalleryCreatorPictures.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -17,11 +17,10 @@ use Contao\Backend; use Contao\Config; use Contao\Controller; -use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; -use Contao\CoreBundle\Framework\Adapter; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Image\ImageFactory; use Contao\CoreBundle\Security\ContaoCorePermissions; +use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\DataContainer; use Contao\Dbafs; use Contao\File; @@ -38,36 +37,41 @@ use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; use Markocupic\GalleryCreatorBundle\Security\GalleryCreatorAlbumPermissions; use Markocupic\GalleryCreatorBundle\Util\FileUtil; -use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment as TwigEnvironment; class GalleryCreatorPictures { - private Adapter $backend; - private Adapter $controller; - private Adapter $image; - private Adapter $stringUtil; - private Adapter $message; - private Adapter $system; - private Adapter $albums; - private Adapter $pictures; - - public function __construct( - private readonly ContaoFramework $framework, - private readonly RequestStack $requestStack, - private readonly Connection $connection, - private readonly FileUtil $fileUtil, - private readonly Security $security, - private readonly TranslatorInterface $translator, - private readonly ImageFactory $imageFactory, - private readonly TwigEnvironment $twig, - private readonly CacheManager $cacheManager, - private readonly string $projectDir, - private readonly string $galleryCreatorUploadPath, - ) { + private ContaoFramework $framework; + private RequestStack $requestStack; + private Connection $connection; + private FileUtil $fileUtil; + private Security $security; + private TranslatorInterface $translator; + private ImageFactory $imageFactory; + private TwigEnvironment $twig; + private CacheManager $cacheManager; + + private string $projectDir; + private string $galleryCreatorUploadPath; + + public function __construct(ContaoFramework $framework, RequestStack $requestStack, Connection $connection, FileUtil $fileUtil, Security $security, TranslatorInterface $translator, ImageFactory $imageFactory, TwigEnvironment $twig, CacheManager $cacheManager, string $projectDir, string $galleryCreatorUploadPath) + { + $this->framework = $framework; + $this->requestStack = $requestStack; + $this->connection = $connection; + $this->fileUtil = $fileUtil; + $this->security = $security; + $this->translator = $translator; + $this->imageFactory = $imageFactory; + $this->twig = $twig; + $this->cacheManager = $cacheManager; + $this->projectDir = $projectDir; + $this->galleryCreatorUploadPath = $galleryCreatorUploadPath; + // Adapters $this->backend = $this->framework->getAdapter(Backend::class); $this->controller = $this->framework->getAdapter(Controller::class); @@ -79,9 +83,17 @@ public function __construct( $this->pictures = $this->framework->getAdapter(GalleryCreatorPicturesModel::class); } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.onload', priority: 110)] - public function checkPermissions(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="config.onload", priority=110) + */ + public function onloadCallbackCheckPermissions(DataContainer $dc): void { + if (!$dc) { + return; + } + $user = $this->security->getUser(); $request = $this->requestStack->getCurrentRequest(); @@ -181,11 +193,16 @@ public function checkPermissions(DataContainer $dc): void } // Check if user is allowed to move pictures inside the source album - } - - if (!$this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_MOVE_IMAGES, $sourceAlbumId)) { - $this->message->addInfo($this->translator->trans('MSC.notAllowedMovePictures', [$sourceAlbumId], 'contao_default')); - $this->controller->redirect($this->system->getReferer()); + if (!$this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_MOVE_IMAGES, $sourceAlbumId)) { + $this->message->addInfo($this->translator->trans('MSC.notAllowedMovePictures', [$sourceAlbumId], 'contao_default')); + $this->controller->redirect($this->system->getReferer()); + } + } else { + // Check if user is allowed to move pictures inside the source album + if (!$this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_MOVE_IMAGES, $sourceAlbumId)) { + $this->message->addInfo($this->translator->trans('MSC.notAllowedMovePictures', [$sourceAlbumId], 'contao_default')); + $this->controller->redirect($this->system->getReferer()); + } } } @@ -241,10 +258,14 @@ public function checkPermissions(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.onload', priority: 100)] - public function setCorrectReferer(DataContainer $dc): void + /** + * Onload callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="config.onload", priority=100) + */ + public function onloadCallbackSetCorrectReferer(DataContainer $dc): void { - if (empty($dc->id)) { + if (!$dc) { return; } @@ -260,11 +281,21 @@ public function setCorrectReferer(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.onload', priority: 90)] - public function rotateImage(DataContainer $dc): void + /** + * Onload callback. + * + * @throws \Exception + * + * @Callback(table="tl_gallery_creator_pictures", target="config.onload", priority=90) + */ + public function onloadCallbackRotateImage(DataContainer $dc): void { $request = $this->requestStack->getCurrentRequest(); + if (!$dc) { + return; + } + if ('imagerotate' === $request->query->get('key')) { $picturesModel = $this->pictures->findByPk($dc->id); $files = $this->framework->getAdapter(FilesModel::class); @@ -297,9 +328,15 @@ public function rotateImage(DataContainer $dc): void } } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.onsubmit', priority: 100)] - public function invalidateCacheOnSubmit(DataContainer $dc): void + /** + * @Callback(table="tl_gallery_creator_pictures", target="config.onsubmit") + */ + public function onSubmitInvalidateCache(DataContainer $dc): void { + if (!$dc) { + return; + } + $pid = $this->connection->fetchOne('SELECT pid FROM tl_gallery_creator_pictures WHERE id = ?', [$dc->id]); if (!$pid) { @@ -314,7 +351,11 @@ public function invalidateCacheOnSubmit(DataContainer $dc): void $this->cacheManager->invalidateTags($arrTags); } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.operations.toggle.button', priority: 100)] + /** + * Return the "toggle visibility" button. + * + * @Callback(table="tl_gallery_creator_pictures", target="list.operations.toggle.button") + */ public function toggleVisibility(array $row, string $href, string $label, string $title, string $icon, string $attributes): string { // Check permissions AFTER checking the tid, so hacking attempts are logged @@ -339,23 +380,27 @@ public function toggleVisibility(array $row, string $href, string $label, string return ''.Image::getHtml($icon, $label, 'data-icon="'.Image::getPath('visible.svg').'" data-icon-disabled="'.Image::getPath('invisible.svg').'" data-state="'.($row['published'] ? 1 : 0).'"').' '; } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.operations.edit.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.operations.delete.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.operations.cut.button', priority: 100)] - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.operations.imagerotate.button', priority: 100)] - public function buttonCallback(array $row, string|null $href, string|null $label, string|null $title, string|null $icon, string|null $attributes): string + /** + * Button callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="list.operations.edit.button", priority=100) + * @Callback(table="tl_gallery_creator_pictures", target="list.operations.delete.button", priority=100) + * @Callback(table="tl_gallery_creator_pictures", target="list.operations.cut.button", priority=100) + * @Callback(table="tl_gallery_creator_pictures", target="list.operations.imagerotate.button", priority=100) + */ + public function buttonCallback(array $row, ?string $href, ?string $label, ?string $title, ?string $icon, ?string $attributes): string { $href .= '&id='.$row['id']; $blnGranted = false; - if (str_contains($href, 'key=imagerotate')) { + if (false !== strpos($href, 'key=imagerotate')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_ADD_AND_EDIT_IMAGES, $row['pid']); - } elseif (str_contains($href, 'act=delete')) { + } elseif (false !== strpos($href, 'act=delete')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_DELETE_IMAGES, $row['pid']); - } elseif (str_contains($href, 'act=edit')) { + } elseif (false !== strpos($href, 'act=edit')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_ADD_AND_EDIT_IMAGES, $row['pid']); - } elseif (str_contains($href, 'act=paste')) { + } elseif (false !== strpos($href, 'act=paste')) { $blnGranted = $this->security->isGranted(GalleryCreatorAlbumPermissions::USER_CAN_MOVE_IMAGES, $row['pid']); } @@ -372,7 +417,11 @@ public function buttonCallback(array $row, string|null $href, string|null $label return $this->image->getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' '; } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'list.sorting.child_record', priority: 100)] + /** + * Child record callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="list.sorting.child_record", priority=100) + */ public function childRecordCallback(array $arrRow): string { $request = $this->requestStack->getCurrentRequest(); @@ -412,7 +461,7 @@ public function childRecordCallback(array $arrRow): string $type = empty(trim((string) $arrRow['localMediaSRC'])) ? $this->translator->trans('GALLERY_CREATOR.localMedia', [], 'contao_default') : $this->translator->trans('GALLERY_CREATOR.socialMedia', [], 'contao_default'); $iconSrc = 'bundles/markocupicgallerycreator/images/movie.svg'; $hasMovie = sprintf( - '
has local media %s: %s
', + '
%s: %s
', $iconSrc, $type, $src, @@ -438,23 +487,10 @@ public function childRecordCallback(array $arrRow): string $src = $image->getUrl($this->projectDir); } - $return = sprintf( - '
%s - %s [%s x %s px, %s]
', - $key, - $arrRow['headline'] ?? '', - basename($filesModel->path), - $file->width, - $file->height, - $this->backend->getReadableSize($file->filesize), - ); - + $return = sprintf('
%s - %s [%s x %s px, %s]
', $key, $arrRow['headline'] ?? '', basename($filesModel->path), $file->width, $file->height, $this->backend->getReadableSize($file->filesize)); $return .= $hasMovie; - $return .= $blnShowThumb ? '
has movie
' : null; - $return .= sprintf( - '
%s
', - ($config->get('thumbnails') ? ' h64' : ''), - $this->stringUtil->specialchars($arrRow['caption']), - ); + $return .= $blnShowThumb ? '
' : null; + $return .= sprintf('
%s
', ($config->get('thumbnails') ? ' h64' : ''), $this->stringUtil->specialchars($arrRow['caption'])); return $return; } @@ -462,8 +498,9 @@ public function childRecordCallback(array $arrRow): string /** * Move file to the correct directory, when cutting & pasting images * from one album into another. + * + * @Callback(table="tl_gallery_creator_pictures", target="config.oncut", priority=100) */ - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.oncut', priority: 100)] public function oncutCallback(DataContainer $dc): void { $picture = $this->pictures->findByPk($dc->id); @@ -480,7 +517,7 @@ public function oncutCallback(DataContainer $dc): void } // Return if it is an external file - if (!str_contains($sourcePath, $this->galleryCreatorUploadPath)) { + if (false === strpos($sourcePath, $this->galleryCreatorUploadPath)) { return; } @@ -489,8 +526,12 @@ public function oncutCallback(DataContainer $dc): void $file->renameTo($targetPath); } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'fields.picture.input_field', priority: 100)] - public function getPreviewPicture(DataContainer $dc): string + /** + * Input field callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="fields.picture.input_field") + */ + public function inputFieldCallbackPicture(DataContainer $dc): string { $objImg = $this->pictures->findByPk($dc->id); @@ -509,7 +550,6 @@ public function getPreviewPicture(DataContainer $dc): string $this->twig->render( '@MarkocupicGalleryCreator/Backend/picture.html.twig', [ - 'css_class' => $GLOBALS['TL_DCA']['tl_gallery_creator_pictures']['fields']['picture']['eval']['tl_class'] ?? null, 'basename' => basename($filesModel->path), 'img_src' => $src, ] @@ -520,8 +560,12 @@ public function getPreviewPicture(DataContainer $dc): string return ''; } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'fields.imageInfo.input_field', priority: 100)] - public function getImageInformationTable(DataContainer $dc): string + /** + * Input field callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="fields.imageInfo.input_field") + */ + public function inputFieldCallbackImageInfo(DataContainer $dc): string { $picturesModel = $this->pictures->findByPk($dc->id); @@ -548,7 +592,6 @@ public function getImageInformationTable(DataContainer $dc): string '@MarkocupicGalleryCreator/Backend/image_information.html.twig', [ 'model' => $picturesModel->row(), - 'css_class' => $GLOBALS['TL_DCA']['tl_gallery_creator_pictures']['fields']['imageInfo']['eval']['tl_class'] ?? null, 'trans' => [ 'picture_id' => $translator->trans('tl_gallery_creator_pictures.id.0', [], 'contao_default'), 'picture_info' => $translator->trans('tl_gallery_creator_pictures.imageInfo.0', [], 'contao_default'), @@ -565,15 +608,23 @@ public function getImageInformationTable(DataContainer $dc): string ))->getContent(); } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'edit.buttons', priority: 100)] - public function setSubmitButtons(array $buttons, DataContainer $dc): array + /** + * Edit buttons callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="edit.buttons") + */ + public function editButtonsCallback(array $buttons, DataContainer $dc): array { unset($buttons['saveNcreate'], $buttons['copy']); return $buttons; } - #[AsCallback(table: 'tl_gallery_creator_pictures', target: 'config.ondelete', priority: 100)] + /** + * Ondelete callback. + * + * @Callback(table="tl_gallery_creator_pictures", target="config.ondelete", priority=100) + */ public function ondeleteCallback(DataContainer $dc, int $undoInt): void { if (!$dc->id) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3879478..d6defaa 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/src/DependencyInjection/MarkocupicGalleryCreatorExtension.php b/src/DependencyInjection/MarkocupicGalleryCreatorExtension.php index 101b3db..ee5a37d 100644 --- a/src/DependencyInjection/MarkocupicGalleryCreatorExtension.php +++ b/src/DependencyInjection/MarkocupicGalleryCreatorExtension.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -31,10 +31,10 @@ public function load(array $configs, ContainerBuilder $container): void $loader = new YamlFileLoader( $container, - new FileLocator(__DIR__.'/../../config') + new FileLocator(__DIR__.'/../Resources/config') ); - $loader->load('services.yaml'); + $loader->load('services.yml'); // Configuration $container->setParameter('markocupic_gallery_creator.upload_path', $config['upload_path']); diff --git a/src/EventSubscriber/AddBackendAssetsSubscriber.php b/src/EventSubscriber/AddBackendAssetsSubscriber.php index 0ff889c..5b50e40 100644 --- a/src/EventSubscriber/AddBackendAssetsSubscriber.php +++ b/src/EventSubscriber/AddBackendAssetsSubscriber.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -21,9 +21,11 @@ class AddBackendAssetsSubscriber implements EventSubscriberInterface { - public function __construct( - private readonly ScopeMatcher $scopeMatcher, - ) { + protected ScopeMatcher $scopeMatcher; + + public function __construct(ScopeMatcher $scopeMatcher) + { + $this->scopeMatcher = $scopeMatcher; } public static function getSubscribedEvents(): array diff --git a/src/EventListener/ContaoHook/GalleryCreatorFrontendTemplateListener.php b/src/Listener/ContaoHook/GalleryCreatorFrontendTemplateListener.php similarity index 62% rename from src/EventListener/ContaoHook/GalleryCreatorFrontendTemplateListener.php rename to src/Listener/ContaoHook/GalleryCreatorFrontendTemplateListener.php index 0a9a4ae..f47ce8a 100644 --- a/src/EventListener/ContaoHook/GalleryCreatorFrontendTemplateListener.php +++ b/src/Listener/ContaoHook/GalleryCreatorFrontendTemplateListener.php @@ -5,30 +5,31 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. * @link https://github.com/markocupic/gallery-creator-bundle */ -namespace Markocupic\GalleryCreatorBundle\EventListener\ContaoHook; +namespace Markocupic\GalleryCreatorBundle\Listener\ContaoHook; use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; -use Contao\CoreBundle\Twig\FragmentTemplate; +use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\Template; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; /** * This is a demo class! + * + * @Hook(GalleryCreatorFrontendTemplateListener::HOOK, priority=100) */ -#[AsHook(GalleryCreatorFrontendTemplateListener::HOOK, priority: 100)] class GalleryCreatorFrontendTemplateListener { public const HOOK = 'galleryCreatorGenerateFrontendTemplate'; - public function __invoke(AbstractContentElementController $contentElement, FragmentTemplate $template, GalleryCreatorAlbumsModel $albumsModel = null): void + public function __invoke(AbstractContentElementController $contentElement, Template $template, GalleryCreatorAlbumsModel $albumsModel = null): void { - //$template->set('foo, 'bar'); + //$template->hallo = 'Lorem ipsum'; } } diff --git a/src/EventListener/ContaoHook/GalleryCreatorImagePostInsertListener.php b/src/Listener/ContaoHook/GalleryCreatorImagePostInsertListener.php similarity index 79% rename from src/EventListener/ContaoHook/GalleryCreatorImagePostInsertListener.php rename to src/Listener/ContaoHook/GalleryCreatorImagePostInsertListener.php index 00958c6..d36b330 100644 --- a/src/EventListener/ContaoHook/GalleryCreatorImagePostInsertListener.php +++ b/src/Listener/ContaoHook/GalleryCreatorImagePostInsertListener.php @@ -5,23 +5,24 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. * @link https://github.com/markocupic/gallery-creator-bundle */ -namespace Markocupic\GalleryCreatorBundle\EventListener\ContaoHook; +namespace Markocupic\GalleryCreatorBundle\Listener\ContaoHook; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; /** * This is a demo class! + * + * @Hook(GalleryCreatorImagePostInsertListener::HOOK, priority=100) */ -#[AsHook(GalleryCreatorImagePostInsertListener::HOOK, priority: 100)] class GalleryCreatorImagePostInsertListener { public const HOOK = 'galleryCreatorImagePostInsert'; diff --git a/src/EventListener/ContaoHook/InitializeSystemListener.php b/src/Listener/ContaoHook/InitializeSystemListener.php similarity index 86% rename from src/EventListener/ContaoHook/InitializeSystemListener.php rename to src/Listener/ContaoHook/InitializeSystemListener.php index 48bee5f..6ca6fbc 100644 --- a/src/EventListener/ContaoHook/InitializeSystemListener.php +++ b/src/Listener/ContaoHook/InitializeSystemListener.php @@ -5,24 +5,25 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. * @link https://github.com/markocupic/gallery-creator-bundle */ -namespace Markocupic\GalleryCreatorBundle\EventListener\ContaoHook; +namespace Markocupic\GalleryCreatorBundle\Listener\ContaoHook; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Routing\ScopeMatcher; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Input; use Symfony\Component\HttpFoundation\RequestStack; /** * @todo Handle this issue in a more proper way + * + * @Hook(InitializeSystemListener::HOOK) */ -#[AsHook(InitializeSystemListener::HOOK, priority: 100)] class InitializeSystemListener { public const HOOK = 'initializeSystem'; diff --git a/src/EventListener/ContaoHook/ParseBackendTemplate.php b/src/Listener/ContaoHook/ParseBackendTemplate.php similarity index 66% rename from src/EventListener/ContaoHook/ParseBackendTemplate.php rename to src/Listener/ContaoHook/ParseBackendTemplate.php index 397c39e..7abe4e0 100644 --- a/src/EventListener/ContaoHook/ParseBackendTemplate.php +++ b/src/Listener/ContaoHook/ParseBackendTemplate.php @@ -5,32 +5,37 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. * @link https://github.com/markocupic/gallery-creator-bundle */ -namespace Markocupic\GalleryCreatorBundle\EventListener\ContaoHook; +namespace Markocupic\GalleryCreatorBundle\Listener\ContaoHook; -use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Routing\ScopeMatcher; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Symfony\Component\HttpFoundation\RequestStack; -#[AsHook(ParseBackendTemplate::HOOK, priority: 100)] +/** + * @Hook(ParseBackendTemplate::HOOK) + */ class ParseBackendTemplate { public const HOOK = 'parseBackendTemplate'; - public function __construct( - private readonly RequestStack $requestStack, - private readonly ScopeMatcher $scopeMatcher, - ) { + private RequestStack $requestStack; + private ScopeMatcher $scopeMatcher; + + public function __construct(RequestStack $requestStack, ScopeMatcher $scopeMatcher) + { + $this->requestStack = $requestStack; + $this->scopeMatcher = $scopeMatcher; } /** - * Adjust the form encoding for the image uploader in the contao backend. + * Adapt the form encoding for the image uploader in the contao backend. */ public function __invoke(string $strContent): string { diff --git a/src/MarkocupicGalleryCreatorBundle.php b/src/MarkocupicGalleryCreatorBundle.php index eac7b78..0a86be7 100644 --- a/src/MarkocupicGalleryCreatorBundle.php +++ b/src/MarkocupicGalleryCreatorBundle.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -18,8 +18,4 @@ class MarkocupicGalleryCreatorBundle extends Bundle { - public function getPath(): string - { - return \dirname(__DIR__); - } } diff --git a/src/Migration/Version200/AddDefaultChmodMigration.php b/src/Migration/Version200/AddDefaultChmodMigration.php index 48ff1c9..ccec843 100644 --- a/src/Migration/Version200/AddDefaultChmodMigration.php +++ b/src/Migration/Version200/AddDefaultChmodMigration.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -23,10 +23,13 @@ class AddDefaultChmodMigration extends AbstractMigration { - public function __construct( - private readonly ContaoFramework $framework, - private readonly Connection $connection, - ) { + private ContaoFramework $framework; + private Connection $connection; + + public function __construct(ContaoFramework $framework, Connection $connection) + { + $this->framework = $framework; + $this->connection = $connection; } public function getName(): string diff --git a/src/Migration/Version200/RenameColumnsMigration.php b/src/Migration/Version200/RenameColumnsMigration.php index ac17718..cdf4fab 100644 --- a/src/Migration/Version200/RenameColumnsMigration.php +++ b/src/Migration/Version200/RenameColumnsMigration.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -23,9 +23,11 @@ class RenameColumnsMigration extends AbstractMigration { private const ALTERATION_TYPE_RENAME_COLUMN = 'alteration_type_rename_column'; - public function __construct( - private readonly Connection $connection, - ) { + private Connection $connection; + + public function __construct(Connection $connection) + { + $this->connection = $connection; } public function getName(): string diff --git a/src/Model/GalleryCreatorAlbumsModel.php b/src/Model/GalleryCreatorAlbumsModel.php index 79eb9c1..f7ddccc 100644 --- a/src/Model/GalleryCreatorAlbumsModel.php +++ b/src/Model/GalleryCreatorAlbumsModel.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -29,12 +29,19 @@ class GalleryCreatorAlbumsModel extends Model */ protected static $strTable = 'tl_gallery_creator_albums'; - public static function getParentAlbum(self $albumsModel): self|null + /** + * @param GalleryCreatorAlbumsModel $albumsModel + * + * @throws \Exception + * + * @return static|null + */ + public static function getParentAlbum(self $albumsModel): ?self { return $albumsModel->getRelated('pid'); } - public static function getChildAlbumsIds(int $parentId, string $strSorting = '', int $iterationDepth = null): array|null + public static function getChildAlbumsIds(int $parentId, string $strSorting = '', int $iterationDepth = null): ?array { $arrChildAlbumsIds = []; diff --git a/src/Model/GalleryCreatorPicturesModel.php b/src/Model/GalleryCreatorPicturesModel.php index 9de9192..df596fc 100644 --- a/src/Model/GalleryCreatorPicturesModel.php +++ b/src/Model/GalleryCreatorPicturesModel.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/src/Resources/config/routes.yml b/src/Resources/config/routes.yml new file mode 100644 index 0000000..e675dcf --- /dev/null +++ b/src/Resources/config/routes.yml @@ -0,0 +1,4 @@ +markocupic_gallery_creator.controller: + resource: "@MarkocupicGalleryCreatorBundle/Controller" + type: annotation + diff --git a/config/services.yaml b/src/Resources/config/services.yml similarity index 80% rename from config/services.yaml rename to src/Resources/config/services.yml index e3da41c..fe88398 100644 --- a/config/services.yaml +++ b/src/Resources/config/services.yml @@ -11,11 +11,15 @@ services: $galleryCreatorValidExtensions: '%markocupic_gallery_creator.valid_extensions%' $imageFactory: '@contao.image.factory' $insertTagParser: '@contao.insert_tag.parser' - $filesStorage: '@contao.filesystem.virtual.files' + + _instanceof: + Symfony\Bundle\FrameworkBundle\Controller\AbstractController: + calls: + - [ setContainer, [ '@service_container' ] ] Markocupic\GalleryCreatorBundle\: - resource: ../src/ - exclude: ../src/{DependencyInjection,Model} + resource: ../../ + exclude: ../../{DependencyInjection,Resources,Model} Markocupic\GalleryCreatorBundle\Controller\ContentElement\GalleryCreatorController: tags: diff --git a/contao/config/config.php b/src/Resources/contao/config/config.php similarity index 96% rename from contao/config/config.php rename to src/Resources/contao/config/config.php index 15e003f..96e391c 100644 --- a/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_content.php b/src/Resources/contao/dca/tl_content.php similarity index 99% rename from contao/dca/tl_content.php rename to src/Resources/contao/dca/tl_content.php index 2270fe0..45c6898 100644 --- a/contao/dca/tl_content.php +++ b/src/Resources/contao/dca/tl_content.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_gallery_creator_albums.php b/src/Resources/contao/dca/tl_gallery_creator_albums.php similarity index 91% rename from contao/dca/tl_gallery_creator_albums.php rename to src/Resources/contao/dca/tl_gallery_creator_albums.php index f1b1531..93ceef1 100644 --- a/contao/dca/tl_gallery_creator_albums.php +++ b/src/Resources/contao/dca/tl_gallery_creator_albums.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -61,12 +61,12 @@ 'editheader' => [ 'attributes' => 'data-icon="gc-op-icon"', 'href' => 'act=edit', - 'icon' => 'edit.svg', + 'icon' => 'header.svg', ], 'edit' => [ 'attributes' => 'data-icon="gc-op-icon"', 'href' => 'table=tl_gallery_creator_pictures', - 'icon' => 'children.svg', + 'icon' => 'bundles/markocupicgallerycreator/images/list.svg', ], 'delete' => [ 'attributes' => 'onclick="if(!confirm(\''.($GLOBALS['TL_LANG']['MSC']['deleteConfirm'] ?? null).'\'))return false;Backend.getScrollOffset()"', @@ -101,21 +101,8 @@ ], 'palettes' => [ '__selector__' => ['protected', 'includeChmod'], - 'default' => ' - {title_legend},name,alias; - {meta_legend},pageTitle,robots,description,serpPreview; - {details_legend},date,location,photographer,visitors,teaser; - {caption_legend},captionType,caption,markdownCaption; - {album_preview_thumb_legend},sortBy,filePrefix,thumb; - {gallery_creator_chmod_legend:hide},includeChmod; - {insert_article_legend},insertArticlePre,insertArticlePost; - {uploadDir_legend},assignedDir; - {protection_legend:hide},protected - ', - 'fileUpload' => ' - {upload_settings_legend},preserveFilename,imageResolution; - {uploader_legend},fileUpload - ', + 'default' => '{title_legend},name,alias;{meta_legend},pageTitle,robots,description,serpPreview;{details_legend},date,location,teaser,photographer,visitors;{caption_legend},captionType,caption,markdownCaption;{album_preview_thumb_legend},sortBy,filePrefix,thumb;{gallery_creator_chmod_legend:hide},includeChmod;{insert_article_legend},insertArticlePre,insertArticlePost;{uploadDir_legend},assignedDir;{protection_legend:hide},protected', + 'fileUpload' => '{upload_settings_legend},preserveFilename,imageResolution;{uploader_legend},fileUpload', 'importImagesFromFilesystem' => '{upload_settings_legend},preserveFilename,multiSRC', 'reviseDatabase' => '{maintenance},reviseDatabase', ], @@ -163,7 +150,7 @@ 'exclude' => true, 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'decodeEntities' => true, 'tl_class' => 'w33'], + 'eval' => ['maxlength' => 255, 'decodeEntities' => true, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], 'robots' => [ @@ -171,20 +158,20 @@ 'search' => true, 'inputType' => 'select', 'options' => ['index,follow', 'index,nofollow', 'noindex,follow', 'noindex,nofollow'], - 'eval' => ['tl_class' => 'w33', 'includeBlankOption' => true], + 'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true], 'sql' => "varchar(32) NOT NULL default ''", ], 'description' => [ 'exclude' => true, 'search' => true, 'inputType' => 'textarea', - 'eval' => ['decodeEntities' => true, 'tl_class' => 'w33'], + 'eval' => ['style' => 'height:60px', 'decodeEntities' => true, 'tl_class' => 'clr'], 'sql' => 'text NULL', ], 'date' => [ 'sorting' => true, 'default' => time(), - 'eval' => ['mandatory' => true, 'datepicker' => true, 'rgxp' => 'date', 'tl_class' => 'w25 wizard', 'submitOnChange' => false], + 'eval' => ['mandatory' => true, 'datepicker' => true, 'rgxp' => 'date', 'tl_class' => 'w50 wizard', 'submitOnChange' => false], 'inputType' => 'text', 'sql' => "int(10) unsigned NOT NULL default '0'", ], @@ -192,35 +179,41 @@ 'filter' => true, 'search' => true, 'sorting' => true, - 'eval' => ['mandatory' => false, 'tl_class' => 'w25', 'submitOnChange' => false], + 'eval' => ['mandatory' => false, 'tl_class' => 'w50', 'submitOnChange' => false], 'exclude' => true, 'inputType' => 'text', 'sql' => "varchar(255) NOT NULL default ''", ], + 'teaser' => [ + 'exclude' => true, + 'search' => true, + 'inputType' => 'textarea', + 'eval' => ['style' => 'height:60px', 'tl_class' => 'clr long', 'allowHtml' => false, 'wrap' => 'soft'], + 'sql' => 'text NULL', + ], 'photographer' => [ 'filter' => true, 'search' => true, 'sorting' => true, - 'eval' => ['mandatory' => false, 'tl_class' => 'w25', 'submitOnChange' => false], + 'eval' => ['mandatory' => false, 'tl_class' => 'w50', 'submitOnChange' => false], 'exclude' => true, 'inputType' => 'text', 'sql' => "varchar(255) NOT NULL default ''", ], + 'assignedDir' => [ + 'eval' => ['mandatory' => false, 'fieldType' => 'radio', 'tl_class' => 'clr'], + 'exclude' => true, + 'inputType' => 'fileTree', + 'sql' => 'blob NULL', + ], 'visitors' => [ - 'eval' => ['maxlength' => 10, 'tl_class' => 'w25', 'rgxp' => 'digit'], + 'eval' => ['maxlength' => 10, 'tl_class' => 'w50', 'rgxp' => 'digit'], 'inputType' => 'text', 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'visitorsDetails' => [ 'sql' => 'blob NULL', ], - 'teaser' => [ - 'exclude' => true, - 'search' => true, - 'inputType' => 'textarea', - 'eval' => ['style' => 'height:60px', 'tl_class' => 'clr long', 'allowHtml' => false, 'wrap' => 'soft'], - 'sql' => 'text NULL', - ], 'captionType' => [ 'filter' => true, 'eval' => ['submitOnChange' => true, 'tl_class' => 'clr'], @@ -345,11 +338,5 @@ 'reviseDatabase' => [ 'eval' => ['doNotShow' => true], ], - 'assignedDir' => [ - 'eval' => ['mandatory' => false, 'fieldType' => 'radio', 'tl_class' => 'clr'], - 'exclude' => true, - 'inputType' => 'fileTree', - 'sql' => 'blob NULL', - ], ], ]; diff --git a/contao/dca/tl_gallery_creator_pictures.php b/src/Resources/contao/dca/tl_gallery_creator_pictures.php similarity index 87% rename from contao/dca/tl_gallery_creator_pictures.php rename to src/Resources/contao/dca/tl_gallery_creator_pictures.php index ea42e45..485a8d3 100644 --- a/contao/dca/tl_gallery_creator_pictures.php +++ b/src/Resources/contao/dca/tl_gallery_creator_pictures.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -15,7 +15,6 @@ use Contao\BackendUser; use Contao\DC_Table; use Contao\System; -use Contao\DataContainer; $GLOBALS['TL_DCA']['tl_gallery_creator_pictures'] = [ 'config' => [ @@ -36,7 +35,7 @@ 'sorting' => [ 'fields' => ['sorting'], 'headerFields' => ['date', 'name'], - 'mode' => DataContainer::MODE_PARENT, + 'mode' => 4, 'panelLayout' => 'filter;sorting,search,limit', ], 'global_operations' => [ @@ -84,12 +83,7 @@ ], 'palettes' => [ '__selector__' => ['addCustomThumb'], - 'default' => ' - {picture_info_legend},picture,imageInfo; - {title_legend},title,caption,cuser,date; - {thumb_legend},addCustomThumb; - {media_integration:hide},socialMediaSRC,localMediaSRC - ', + 'default' => 'picture,cuser,date,imageInfo,addCustomThumb,title,caption;{media_integration:hide},socialMediaSRC,localMediaSRC', ], 'subpalettes' => [ 'addCustomThumb' => 'customThumb', @@ -112,51 +106,47 @@ 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'published' => [ - 'eval' => ['doNotCopy' => true], + 'toggle' => true, 'filter' => true, 'inputType' => 'checkbox', + 'eval' => ['doNotCopy' => true], 'sql' => "char(1) NOT NULL default '1'", - 'toggle' => true, - ], - 'picture' => [ - 'eval' => ['tl_class' => 'w50'], ], 'imageInfo' => [ - 'eval' => ['tl_class' => 'w50'], + 'eval' => ['tl_class' => 'clr'], ], 'title' => [ - 'eval' => ['allowHtml' => false, 'decodeEntities' => true, 'rgxp' => 'alnum', 'tl_class' => 'w50'], + 'eval' => ['allowHtml' => false, 'decodeEntities' => true, 'rgxp' => 'alnum'], 'exclude' => true, 'search' => true, 'inputType' => 'text', 'sql' => "varchar(255) NOT NULL default ''", ], + 'externalFile' => [ + 'eval' => ['isBoolean' => true], + 'sql' => "char(1) NOT NULL default ''", + ], 'caption' => [ 'cols' => 20, - 'eval' => ['style' => 'height:60px', 'decodeEntities' => true, 'tl_class' => 'w50', 'allowHtml' => false, 'wrap' => 'soft'], + 'eval' => ['style' => 'height:60px', 'decodeEntities' => true, 'tl_class' => 'clr long', 'allowHtml' => false, 'wrap' => 'soft'], 'exclude' => true, 'inputType' => 'textarea', 'rows' => 5, 'search' => true, 'sql' => 'text NULL', ], + 'picture' => [ + 'eval' => ['tl_class' => 'clr'], + ], 'date' => [ - 'default' => time(), // A new uploaded image inherits the date of its parent album. - 'eval' => ['mandatory' => true, 'datepicker' => true, 'rgxp' => 'date', 'tl_class' => 'w50 wizard ', 'submitOnChange' => false], - 'filter' => true, 'inputType' => 'text', + // A new uploaded image inherits the date of the parent album. + 'default' => time(), + 'filter' => true, 'sorting' => true, + 'eval' => ['mandatory' => true, 'datepicker' => true, 'rgxp' => 'date', 'tl_class' => 'clr wizard ', 'submitOnChange' => false], 'sql' => "int(10) unsigned NOT NULL default '0'", ], - 'cuser' => [ - 'default' => System::getContainer()->get('security.helper')->getUser() instanceof BackendUser ? System::getContainer()->get('security.helper')->getUser()->id : 0, - 'eval' => ['includeBlankOption' => true, 'blankOptionLabel' => 'noName', 'nospace' => true, 'tl_class' => 'clr w50'], - 'filter' => true, - 'foreignKey' => 'tl_user.name', - 'inputType' => 'select', - 'relation' => ['type' => 'hasOne', 'load' => 'lazy'], - 'sql' => 'int(10) NOT NULL default 0', - ], 'addCustomThumb' => [ 'eval' => ['submitOnChange' => true, 'isBoolean' => true], 'exclude' => true, @@ -171,6 +161,15 @@ 'inputType' => 'fileTree', 'sql' => 'blob NULL', ], + 'cuser' => [ + 'default' => BackendUser::getInstance()->id, + 'eval' => ['includeBlankOption' => true, 'blankOptionLabel' => 'noName', 'nospace' => true, 'tl_class' => 'clr w50'], + 'filter' => true, + 'foreignKey' => 'tl_user.name', + 'inputType' => 'select', + 'relation' => ['type' => 'hasOne', 'load' => 'lazy'], + 'sql' => 'int(10) NOT NULL default 0', + ], 'socialMediaSRC' => [ 'eval' => ['tl_class' => 'clr'], 'exclude' => true, @@ -185,9 +184,5 @@ 'inputType' => 'fileTree', 'sql' => 'binary(16) NULL', ], - 'externalFile' => [ - 'eval' => ['isBoolean' => true], - 'sql' => "char(1) NOT NULL default ''", - ], ], ]; diff --git a/contao/dca/tl_settings.php b/src/Resources/contao/dca/tl_settings.php similarity index 97% rename from contao/dca/tl_settings.php rename to src/Resources/contao/dca/tl_settings.php index 7607646..1c0b1f0 100644 --- a/contao/dca/tl_settings.php +++ b/src/Resources/contao/dca/tl_settings.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_user.php b/src/Resources/contao/dca/tl_user.php similarity index 93% rename from contao/dca/tl_user.php rename to src/Resources/contao/dca/tl_user.php index 48bcab2..1610211 100644 --- a/contao/dca/tl_user.php +++ b/src/Resources/contao/dca/tl_user.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/de/default.xlf b/src/Resources/contao/languages/de/default.xlf similarity index 100% rename from contao/languages/de/default.xlf rename to src/Resources/contao/languages/de/default.xlf diff --git a/contao/languages/de/modules.xlf b/src/Resources/contao/languages/de/modules.xlf similarity index 88% rename from contao/languages/de/modules.xlf rename to src/Resources/contao/languages/de/modules.xlf index cbb1f9d..597907c 100644 --- a/contao/languages/de/modules.xlf +++ b/src/Resources/contao/languages/de/modules.xlf @@ -19,8 +19,8 @@ Gallery-Creator - Include a Gallery Creator content element. - Fügt ein Gallery Creator Inhaltselement ein. + Include a Gallery Creator content element to your article. + Fügen Sie dem Artikel eine Gallery Creator Inhaltselement hinzu. Gallery Creator News diff --git a/contao/languages/de/tl_comment.xlf b/src/Resources/contao/languages/de/tl_comment.xlf similarity index 100% rename from contao/languages/de/tl_comment.xlf rename to src/Resources/contao/languages/de/tl_comment.xlf diff --git a/contao/languages/de/tl_content.xlf b/src/Resources/contao/languages/de/tl_content.xlf similarity index 100% rename from contao/languages/de/tl_content.xlf rename to src/Resources/contao/languages/de/tl_content.xlf diff --git a/contao/languages/de/tl_gallery_creator_albums.xlf b/src/Resources/contao/languages/de/tl_gallery_creator_albums.xlf similarity index 100% rename from contao/languages/de/tl_gallery_creator_albums.xlf rename to src/Resources/contao/languages/de/tl_gallery_creator_albums.xlf diff --git a/contao/languages/de/tl_gallery_creator_pictures.xlf b/src/Resources/contao/languages/de/tl_gallery_creator_pictures.xlf similarity index 92% rename from contao/languages/de/tl_gallery_creator_pictures.xlf rename to src/Resources/contao/languages/de/tl_gallery_creator_pictures.xlf index 63d205c..760cff6 100644 --- a/contao/languages/de/tl_gallery_creator_pictures.xlf +++ b/src/Resources/contao/languages/de/tl_gallery_creator_pictures.xlf @@ -2,18 +2,6 @@ - - picture info - Bildinfo - - - title legend - Titel Einstellungen - - - thumbnail legend - Thumbnail Einstellungen - Embed a movie or a sound Video- oder Soundintegration @@ -135,7 +123,7 @@ Alternativ zum Grossbild einen Film oder einen Sound von einer Social-Media-Plattform wiedergeben - Add the full embed path to the source: https://www.youtube.com/embed/VOJyrQa_WR4?rel=0&amp;wmode=transparent + Add the full embed path to the source: https://www.youtube.com/embed/VOJyrQa_WR4?rel=0&amp;wmode=transparent Geben Sie den vollen Pfad zum Medium an: https://www.youtube.com/embed/VOJyrQa_WR4?rel=0&amp;wmode=transparent diff --git a/contao/languages/de/tl_settings.xlf b/src/Resources/contao/languages/de/tl_settings.xlf similarity index 100% rename from contao/languages/de/tl_settings.xlf rename to src/Resources/contao/languages/de/tl_settings.xlf diff --git a/contao/languages/en/default.php b/src/Resources/contao/languages/en/default.php similarity index 99% rename from contao/languages/en/default.php rename to src/Resources/contao/languages/en/default.php index 82e4140..0762a17 100644 --- a/contao/languages/en/default.php +++ b/src/Resources/contao/languages/en/default.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/default.xlf b/src/Resources/contao/languages/en/default.xlf similarity index 100% rename from contao/languages/en/default.xlf rename to src/Resources/contao/languages/en/default.xlf diff --git a/contao/languages/en/modules.php b/src/Resources/contao/languages/en/modules.php similarity index 88% rename from contao/languages/en/modules.php rename to src/Resources/contao/languages/en/modules.php index bd6feff..38d00dc 100644 --- a/contao/languages/en/modules.php +++ b/src/Resources/contao/languages/en/modules.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -24,5 +24,5 @@ * Front end content elements */ $GLOBALS['TL_LANG']['CTE']['gallery_creator_elements'] = 'Gallery Creator'; -$GLOBALS['TL_LANG']['CTE'][GalleryCreatorController::TYPE] = ['Gallery Creator', 'Include a Gallery Creator content element.']; +$GLOBALS['TL_LANG']['CTE'][GalleryCreatorController::TYPE] = ['Gallery Creator', 'Include a Gallery Creator content element to your article.']; $GLOBALS['TL_LANG']['CTE'][GalleryCreatorNewsController::TYPE] = ['Gallery Creator News', 'Include a gallery creator album.']; diff --git a/contao/languages/en/modules.xlf b/src/Resources/contao/languages/en/modules.xlf similarity index 92% rename from contao/languages/en/modules.xlf rename to src/Resources/contao/languages/en/modules.xlf index 14a477b..549e211 100644 --- a/contao/languages/en/modules.xlf +++ b/src/Resources/contao/languages/en/modules.xlf @@ -15,7 +15,7 @@ Gallery Creator - Include a Gallery Creator content element. + Include a Gallery Creator content element to your article. Gallery Creator News diff --git a/contao/languages/en/tl_comment.php b/src/Resources/contao/languages/en/tl_comment.php similarity index 91% rename from contao/languages/en/tl_comment.php rename to src/Resources/contao/languages/en/tl_comment.php index e028bf9..d1c5d88 100644 --- a/contao/languages/en/tl_comment.php +++ b/src/Resources/contao/languages/en/tl_comment.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_comment.xlf b/src/Resources/contao/languages/en/tl_comment.xlf similarity index 100% rename from contao/languages/en/tl_comment.xlf rename to src/Resources/contao/languages/en/tl_comment.xlf diff --git a/contao/languages/en/tl_content.php b/src/Resources/contao/languages/en/tl_content.php similarity index 98% rename from contao/languages/en/tl_content.php rename to src/Resources/contao/languages/en/tl_content.php index b23431a..11bfdc0 100644 --- a/contao/languages/en/tl_content.php +++ b/src/Resources/contao/languages/en/tl_content.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_content.xlf b/src/Resources/contao/languages/en/tl_content.xlf similarity index 100% rename from contao/languages/en/tl_content.xlf rename to src/Resources/contao/languages/en/tl_content.xlf diff --git a/contao/languages/en/tl_gallery_creator_albums.php b/src/Resources/contao/languages/en/tl_gallery_creator_albums.php similarity index 99% rename from contao/languages/en/tl_gallery_creator_albums.php rename to src/Resources/contao/languages/en/tl_gallery_creator_albums.php index 5d23b31..bee1b01 100644 --- a/contao/languages/en/tl_gallery_creator_albums.php +++ b/src/Resources/contao/languages/en/tl_gallery_creator_albums.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_gallery_creator_albums.xlf b/src/Resources/contao/languages/en/tl_gallery_creator_albums.xlf similarity index 100% rename from contao/languages/en/tl_gallery_creator_albums.xlf rename to src/Resources/contao/languages/en/tl_gallery_creator_albums.xlf diff --git a/contao/languages/en/tl_gallery_creator_pictures.php b/src/Resources/contao/languages/en/tl_gallery_creator_pictures.php similarity index 91% rename from contao/languages/en/tl_gallery_creator_pictures.php rename to src/Resources/contao/languages/en/tl_gallery_creator_pictures.php index 81d7812..d23ccbb 100644 --- a/contao/languages/en/tl_gallery_creator_pictures.php +++ b/src/Resources/contao/languages/en/tl_gallery_creator_pictures.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -15,9 +15,6 @@ /* * Legends */ -$GLOBALS['TL_LANG']['tl_gallery_creator_pictures']['picture_info_legend'] = 'picture info'; -$GLOBALS['TL_LANG']['tl_gallery_creator_pictures']['title_legend'] = 'title legend'; -$GLOBALS['TL_LANG']['tl_gallery_creator_pictures']['thumb_legend'] = 'thumbnail legend'; $GLOBALS['TL_LANG']['tl_gallery_creator_pictures']['media_integration'] = 'Embed a movie or a sound'; $GLOBALS['TL_LANG']['tl_gallery_creator_pictures']['expert_legend'] = 'Expert Settings'; diff --git a/contao/languages/en/tl_gallery_creator_pictures.xlf b/src/Resources/contao/languages/en/tl_gallery_creator_pictures.xlf similarity index 94% rename from contao/languages/en/tl_gallery_creator_pictures.xlf rename to src/Resources/contao/languages/en/tl_gallery_creator_pictures.xlf index e93f042..ba42840 100644 --- a/contao/languages/en/tl_gallery_creator_pictures.xlf +++ b/src/Resources/contao/languages/en/tl_gallery_creator_pictures.xlf @@ -2,15 +2,6 @@ - - picture info - - - title legend - - - thumbnail legend - Embed a movie or a sound diff --git a/contao/languages/en/tl_settings.php b/src/Resources/contao/languages/en/tl_settings.php similarity index 96% rename from contao/languages/en/tl_settings.php rename to src/Resources/contao/languages/en/tl_settings.php index b8261a0..6f66bd1 100644 --- a/contao/languages/en/tl_settings.php +++ b/src/Resources/contao/languages/en/tl_settings.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_settings.xlf b/src/Resources/contao/languages/en/tl_settings.xlf similarity index 100% rename from contao/languages/en/tl_settings.xlf rename to src/Resources/contao/languages/en/tl_settings.xlf diff --git a/contao/languages/it/default.xlf b/src/Resources/contao/languages/it/default.xlf similarity index 100% rename from contao/languages/it/default.xlf rename to src/Resources/contao/languages/it/default.xlf diff --git a/contao/languages/it/modules.xlf b/src/Resources/contao/languages/it/modules.xlf similarity index 100% rename from contao/languages/it/modules.xlf rename to src/Resources/contao/languages/it/modules.xlf diff --git a/contao/languages/it/tl_comment.xlf b/src/Resources/contao/languages/it/tl_comment.xlf similarity index 100% rename from contao/languages/it/tl_comment.xlf rename to src/Resources/contao/languages/it/tl_comment.xlf diff --git a/contao/languages/it/tl_content.xlf b/src/Resources/contao/languages/it/tl_content.xlf similarity index 100% rename from contao/languages/it/tl_content.xlf rename to src/Resources/contao/languages/it/tl_content.xlf diff --git a/contao/languages/it/tl_gallery_creator_albums.xlf b/src/Resources/contao/languages/it/tl_gallery_creator_albums.xlf similarity index 100% rename from contao/languages/it/tl_gallery_creator_albums.xlf rename to src/Resources/contao/languages/it/tl_gallery_creator_albums.xlf diff --git a/contao/languages/it/tl_gallery_creator_pictures.xlf b/src/Resources/contao/languages/it/tl_gallery_creator_pictures.xlf similarity index 100% rename from contao/languages/it/tl_gallery_creator_pictures.xlf rename to src/Resources/contao/languages/it/tl_gallery_creator_pictures.xlf diff --git a/contao/languages/nl/default.xlf b/src/Resources/contao/languages/nl/default.xlf similarity index 100% rename from contao/languages/nl/default.xlf rename to src/Resources/contao/languages/nl/default.xlf diff --git a/contao/languages/nl/modules.xlf b/src/Resources/contao/languages/nl/modules.xlf similarity index 100% rename from contao/languages/nl/modules.xlf rename to src/Resources/contao/languages/nl/modules.xlf diff --git a/contao/languages/nl/tl_comment.xlf b/src/Resources/contao/languages/nl/tl_comment.xlf similarity index 100% rename from contao/languages/nl/tl_comment.xlf rename to src/Resources/contao/languages/nl/tl_comment.xlf diff --git a/contao/languages/nl/tl_content.xlf b/src/Resources/contao/languages/nl/tl_content.xlf similarity index 100% rename from contao/languages/nl/tl_content.xlf rename to src/Resources/contao/languages/nl/tl_content.xlf diff --git a/contao/languages/nl/tl_gallery_creator_albums.xlf b/src/Resources/contao/languages/nl/tl_gallery_creator_albums.xlf similarity index 100% rename from contao/languages/nl/tl_gallery_creator_albums.xlf rename to src/Resources/contao/languages/nl/tl_gallery_creator_albums.xlf diff --git a/contao/languages/nl/tl_gallery_creator_pictures.xlf b/src/Resources/contao/languages/nl/tl_gallery_creator_pictures.xlf similarity index 100% rename from contao/languages/nl/tl_gallery_creator_pictures.xlf rename to src/Resources/contao/languages/nl/tl_gallery_creator_pictures.xlf diff --git a/contao/templates/be_gc_uploader.html5 b/src/Resources/contao/templates/be_gc_uploader.html5 similarity index 100% rename from contao/templates/be_gc_uploader.html5 rename to src/Resources/contao/templates/be_gc_uploader.html5 diff --git a/src/Resources/contao/templates/ce_gallery_creator.html.twig b/src/Resources/contao/templates/ce_gallery_creator.html.twig new file mode 100644 index 0000000..f4f73d1 --- /dev/null +++ b/src/Resources/contao/templates/ce_gallery_creator.html.twig @@ -0,0 +1,21 @@ +{# ce_gallery_creator.html.twig #} + +{% extends '@Contao/block_searchable' %} + +{% block content %} + + {% if hasBreadcrumb and showAlbumDetail %} + + {% endif %} + + {% if showAlbumDetail %} + {% include '@Contao/gallery_creator_album_detail_view' with _context %} + {% endif %} + + {% if showAlbumListing %} + {% include '@Contao/gallery_creator_album_list_view' with _context %} + {% endif %} + +{% endblock %} diff --git a/src/Resources/contao/templates/ce_gallery_creator_news.html.twig b/src/Resources/contao/templates/ce_gallery_creator_news.html.twig new file mode 100644 index 0000000..16d0ba6 --- /dev/null +++ b/src/Resources/contao/templates/ce_gallery_creator_news.html.twig @@ -0,0 +1,9 @@ +{# ce_gallery_creator_news.html.twig #} + +{% extends '@Contao/block_searchable' %} + +{% block content %} + +{% include '@Contao/gallery_creator_album_detail_view' with _context %} + +{% endblock %} diff --git a/src/Resources/contao/templates/partials/album/gallery_creator_album.html.twig b/src/Resources/contao/templates/partials/album/gallery_creator_album.html.twig new file mode 100644 index 0000000..257ca84 --- /dev/null +++ b/src/Resources/contao/templates/partials/album/gallery_creator_album.html.twig @@ -0,0 +1,41 @@ +{# gallery_creator_album.html.twig #} + +
+
+ {{ contao_figure(album.figureUuid, album.figureSize, album.figureOptions) }} +
+ +
+ {% if album.href %} + + {% endif %} +

{{ album.name }}

+ {% if album.href %} +
+ {% endif %} + +

{{ album.date|date('Y-m-d') }}

+ + {% if album.location is defined and not album.location is empty %} +

{{ 'GALLERY_CREATOR.location'|trans({}, 'contao_default') }}: {{ album.location }}

+ {% endif %} + + {% if album.photographer is defined and not album.photographer is empty %} +

{{ 'GALLERY_CREATOR.photographerName'|trans({}, 'contao_default') }}: {{ album.photographer }}

+ {% endif %} + + {% if album.teaser is defined and not album.teaser is empty %} +

{{ album.teaser|raw|nl2br }}

+ {% endif %} + +

{{ album.countPictures }} {{ 'GALLERY_CREATOR.pictures'|trans({}, 'contao_default') }}

+ +

{{ album.visitors }} {{ 'GALLERY_CREATOR.visitors'|trans({}, 'contao_default') }}

+ + {% if album.hasChildAlbums %} +

{{ album.countChildAlbums }} {{ 'GALLERY_CREATOR.childAlbums'|trans({}, 'contao_default') }}

+ {% endif %} + +
+
+ diff --git a/src/Resources/contao/templates/partials/gallery_creator_album_detail_view.html.twig b/src/Resources/contao/templates/partials/gallery_creator_album_detail_view.html.twig new file mode 100644 index 0000000..26b29cc --- /dev/null +++ b/src/Resources/contao/templates/partials/gallery_creator_album_detail_view.html.twig @@ -0,0 +1,58 @@ +{# gallery_creator_album_detail_view.html.twig #} + +
+
+ + {% if insertArticlePre %} +
+ {{ insertArticlePre|raw }} +
+ {% endif %} + + {% if backLink %} + + {% endif %} + + {% if album.name is defined and not album.name is empty %} +

{{ album.name }}

+ {% endif %} + + {% if album.dateFormatted is defined and not album.dateFormatted is empty %} +

{{ album.dateFormatted }}

+ {% endif %} + + {% if album.location is defined and not album.location is empty %} +

{{ album.location }}

+ {% endif %} + + {% if album.hasChildAlbums %} +

{{ album.countChildAlbums }} {{ 'GALLERY_CREATOR.childAlbums'|trans({}, 'contao_default') }}

+ {% endif %} + + {% if album.captionType == 'markdown' and album.markdownCaption %} +
{{ album.markdownCaption|raw }}
+ {% elseif album.caption %} +
{{ album.caption|raw|nl2br }}
+ {% endif %} + + {{ detailPagination|raw }} + + {% if arrPictures %} +
    + {% for picture in arrPictures %} +
  • + {{ contao_figure(picture.figureUuid, picture.figureSize, picture.figureOptions) }} +
  • + {% endfor %} +
+ {% endif %} + + {% if insertArticlePost %} +
+ {{ insertArticlePost|raw }} +
+ {% endif %} +
+
diff --git a/src/Resources/contao/templates/partials/gallery_creator_album_list_view.html.twig b/src/Resources/contao/templates/partials/gallery_creator_album_list_view.html.twig new file mode 100644 index 0000000..2cd7f2d --- /dev/null +++ b/src/Resources/contao/templates/partials/gallery_creator_album_list_view.html.twig @@ -0,0 +1,17 @@ +{# gallery_creator_album_list_view.html.twig #} + + +
+ {{ listPagination|raw }} + +
    + {% for album in albums %} +
  • + {{ include ('@Contao/gallery_creator_album', {content: content, album: album}) }} +
  • + {% endfor %} +
+
+ + + diff --git a/public/css/gallery_creator_be.css b/src/Resources/public/css/gallery_creator_be.css similarity index 89% rename from public/css/gallery_creator_be.css rename to src/Resources/public/css/gallery_creator_be.css index f1e2e7e..16edde3 100644 --- a/public/css/gallery_creator_be.css +++ b/src/Resources/public/css/gallery_creator_be.css @@ -6,16 +6,13 @@ } /** - * Album- % picture info table + * Album detail */ -.gc-album-info-table td, .gc-image-info-table td { +.gc-album-info-table td { padding: 0.5rem; } -.gc-album-info-table tr:nth-child(even) td, .gc-image-info-table tr:nth-child(even) td { - background-color: #ffffff; -} -.gc-album-info-table tr:nth-child(odd) td, .gc-image-info-table tr:nth-child(odd) td { - background: #f3f3f5; +.gc-album-info-table tr.odd > td { + background-color: #f3f3f5; } div.gc-readonly input { @@ -138,7 +135,6 @@ div.gc-readonly input { } .tl_gc_album_tree_widget .gc-item-picker ul { padding-left: 15px; - list-style: none; } .tl_gc_album_tree_widget .gc-item-picker ul li { padding-bottom: 6px; @@ -162,3 +158,5 @@ div.gc-readonly input { .tl_gc_album_tree_widget .gc-item-picker > ul { padding-left: 0; } + +/*# sourceMappingURL=gallery_creator_be.css.map */ diff --git a/public/css/gallery_creator_be.css.map b/src/Resources/public/css/gallery_creator_be.css.map similarity index 100% rename from public/css/gallery_creator_be.css.map rename to src/Resources/public/css/gallery_creator_be.css.map diff --git a/public/css/gallery_creator_be.scss b/src/Resources/public/css/gallery_creator_be.scss similarity index 92% rename from public/css/gallery_creator_be.scss rename to src/Resources/public/css/gallery_creator_be.scss index 10f4404..21cda8d 100644 --- a/public/css/gallery_creator_be.scss +++ b/src/Resources/public/css/gallery_creator_be.scss @@ -6,20 +6,18 @@ } /** - * Album- % picture info table + * Album detail */ -.gc-album-info-table, .gc-image-info-table { +.gc-album-info-table { + td { padding: .5rem; } - tr:nth-child(even) td { - background-color: #ffffff; + tr.odd > td { + background-color: #f3f3f5; } - tr:nth-child(odd) td { - background: #f3f3f5 - } } div.gc-readonly input { @@ -156,7 +154,6 @@ div.gc-readonly input { ul { padding-left: 15px; - list-style: none; li { diff --git a/public/images/.info b/src/Resources/public/images/.info similarity index 100% rename from public/images/.info rename to src/Resources/public/images/.info diff --git a/public/images/_album.svg b/src/Resources/public/images/_album.svg similarity index 100% rename from public/images/_album.svg rename to src/Resources/public/images/_album.svg diff --git a/public/images/add_image.svg b/src/Resources/public/images/add_image.svg similarity index 100% rename from public/images/add_image.svg rename to src/Resources/public/images/add_image.svg diff --git a/public/images/add_image_.svg b/src/Resources/public/images/add_image_.svg similarity index 100% rename from public/images/add_image_.svg rename to src/Resources/public/images/add_image_.svg diff --git a/public/images/album.svg b/src/Resources/public/images/album.svg similarity index 100% rename from public/images/album.svg rename to src/Resources/public/images/album.svg diff --git a/public/images/be_content_element_logo.svg b/src/Resources/public/images/be_content_element_logo.svg similarity index 100% rename from public/images/be_content_element_logo.svg rename to src/Resources/public/images/be_content_element_logo.svg diff --git a/public/images/import_from_filesystem.svg b/src/Resources/public/images/import_from_filesystem.svg similarity index 100% rename from public/images/import_from_filesystem.svg rename to src/Resources/public/images/import_from_filesystem.svg diff --git a/public/images/import_from_filesystem_.svg b/src/Resources/public/images/import_from_filesystem_.svg similarity index 100% rename from public/images/import_from_filesystem_.svg rename to src/Resources/public/images/import_from_filesystem_.svg diff --git a/src/Resources/public/images/import_from_filesystem__.svg b/src/Resources/public/images/import_from_filesystem__.svg new file mode 100644 index 0000000..2057bb5 --- /dev/null +++ b/src/Resources/public/images/import_from_filesystem__.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resources/public/images/list.svg b/src/Resources/public/images/list.svg new file mode 100644 index 0000000..bf5a62d --- /dev/null +++ b/src/Resources/public/images/list.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/public/images/list_.svg b/src/Resources/public/images/list_.svg new file mode 100644 index 0000000..6887d32 --- /dev/null +++ b/src/Resources/public/images/list_.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/images/movie.svg b/src/Resources/public/images/movie.svg similarity index 100% rename from public/images/movie.svg rename to src/Resources/public/images/movie.svg diff --git a/public/images/placeholder.png b/src/Resources/public/images/placeholder.png similarity index 99% rename from public/images/placeholder.png rename to src/Resources/public/images/placeholder.png index 396b8ad..aed27d4 100644 Binary files a/public/images/placeholder.png and b/src/Resources/public/images/placeholder.png differ diff --git a/public/images/revise_database.svg b/src/Resources/public/images/revise_database.svg similarity index 100% rename from public/images/revise_database.svg rename to src/Resources/public/images/revise_database.svg diff --git a/public/images/rotate.svg b/src/Resources/public/images/rotate.svg similarity index 100% rename from public/images/rotate.svg rename to src/Resources/public/images/rotate.svg diff --git a/public/images/rotate_.svg b/src/Resources/public/images/rotate_.svg similarity index 100% rename from public/images/rotate_.svg rename to src/Resources/public/images/rotate_.svg diff --git a/public/js/gallery_creator_be.js b/src/Resources/public/js/gallery_creator_be.js similarity index 96% rename from public/js/gallery_creator_be.js rename to src/Resources/public/js/gallery_creator_be.js index 3a2267b..72dd1ef 100644 --- a/public/js/gallery_creator_be.js +++ b/src/Resources/public/js/gallery_creator_be.js @@ -1,7 +1,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2021 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/public/js/gallery_creator_be.min.js b/src/Resources/public/js/gallery_creator_be.min.js similarity index 100% rename from public/js/gallery_creator_be.min.js rename to src/Resources/public/js/gallery_creator_be.min.js diff --git a/public/js/gallery_creator_be_check_tables.js b/src/Resources/public/js/gallery_creator_be_check_tables.js similarity index 98% rename from public/js/gallery_creator_be_check_tables.js rename to src/Resources/public/js/gallery_creator_be_check_tables.js index 87c0dbf..ece879e 100644 --- a/public/js/gallery_creator_be_check_tables.js +++ b/src/Resources/public/js/gallery_creator_be_check_tables.js @@ -1,7 +1,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2021 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -178,7 +178,7 @@ setTimeout(function () { let statusBox = new Element('p#statusBoxChecksCompleted', { 'class': 'gc-check-tables-status-box', - text: 'All checks successfully completed.', + text: 'All checks completed.', }); statusBox.inject($$('.tl_folder_top')[0]); }, 2000); diff --git a/public/js/gallery_creator_be_check_tables.min.js b/src/Resources/public/js/gallery_creator_be_check_tables.min.js similarity index 90% rename from public/js/gallery_creator_be_check_tables.min.js rename to src/Resources/public/js/gallery_creator_be_check_tables.min.js index d378146..8ad9aca 100644 --- a/public/js/gallery_creator_be_check_tables.min.js +++ b/src/Resources/public/js/gallery_creator_be_check_tables.min.js @@ -1 +1 @@ -(function($){window.addEvent("domready",function(){let objGalleryCreator=new GalleryCreatorBeCheckTables;objGalleryCreator.start()});const GalleryCreatorBeCheckTables=new Class({albumIDS:null,countTests:0,initialize:function(){document.id("main").addClass("gc-check-tables")},start:function(){let self=this;let now=Math.floor((new Date).getTime()/1e3);let doCheck=true;let intervall=3600;let objCookie=null;if(Cookie.read("contao_gallery_creator_be")){objCookie=JSON.decode(atob(Cookie.read("contao_gallery_creator_be")));if(objCookie.tableCheck.lastCheck){if(now-objCookie.tableCheck.lastCheck + * (c) Marko Cupic 2021 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/public/js/gallery_creator_be_revise_tables.min.js b/src/Resources/public/js/gallery_creator_be_revise_tables.min.js similarity index 100% rename from public/js/gallery_creator_be_revise_tables.min.js rename to src/Resources/public/js/gallery_creator_be_revise_tables.min.js diff --git a/templates/Backend/album_information.html.twig b/src/Resources/views/Backend/album_information.html.twig similarity index 84% rename from templates/Backend/album_information.html.twig rename to src/Resources/views/Backend/album_information.html.twig index e276277..acd10c3 100644 --- a/templates/Backend/album_information.html.twig +++ b/src/Resources/views/Backend/album_information.html.twig @@ -1,27 +1,27 @@

 

- + - + - + - + - + - + diff --git a/templates/Backend/album_thumbnail_list.html.twig b/src/Resources/views/Backend/album_thumbnail_list.html.twig similarity index 100% rename from templates/Backend/album_thumbnail_list.html.twig rename to src/Resources/views/Backend/album_thumbnail_list.html.twig diff --git a/templates/Backend/backend_element_view.html.twig b/src/Resources/views/Backend/backend_element_view.html.twig similarity index 100% rename from templates/Backend/backend_element_view.html.twig rename to src/Resources/views/Backend/backend_element_view.html.twig diff --git a/templates/Backend/be_ff_album_tree_field.html.twig b/src/Resources/views/Backend/be_ff_album_tree_field.html.twig similarity index 100% rename from templates/Backend/be_ff_album_tree_field.html.twig rename to src/Resources/views/Backend/be_ff_album_tree_field.html.twig diff --git a/templates/Backend/image_information.html.twig b/src/Resources/views/Backend/image_information.html.twig similarity index 79% rename from templates/Backend/image_information.html.twig rename to src/Resources/views/Backend/image_information.html.twig index c39ec82..c52783d 100644 --- a/templates/Backend/image_information.html.twig +++ b/src/Resources/views/Backend/image_information.html.twig @@ -1,38 +1,38 @@ -
+

-
{{ trans.album_id }}: {{ album_id }}
{{ trans.album_date }}: {{ album_date_formatted }}
{{ trans.album_owners_name }}: {{ album_owners_name }}
{{ trans.album_name }}: {{ album_name }}
{{ trans.album_caption }}: {{ album_caption|raw }}
{{ trans.album_thumb }}: {{ album_thumb }}
- +
+ - + - + - + - + - + {% if model.socialMediaSRC %} - + {% endif %} {% if model.localMediaSRC %} - + diff --git a/templates/Backend/picture.html.twig b/src/Resources/views/Backend/picture.html.twig similarity index 63% rename from templates/Backend/picture.html.twig rename to src/Resources/views/Backend/picture.html.twig index d46f2f5..b3cd9bc 100644 --- a/templates/Backend/picture.html.twig +++ b/src/Resources/views/Backend/picture.html.twig @@ -1,4 +1,4 @@ -
+

{{ basename }}
diff --git a/templates/Backend/revise_database.html.twig b/src/Resources/views/Backend/revise_database.html.twig similarity index 100% rename from templates/Backend/revise_database.html.twig rename to src/Resources/views/Backend/revise_database.html.twig diff --git a/src/Revise/ReviseAlbumDatabase.php b/src/Revise/ReviseAlbumDatabase.php index 9f7f637..0f022e2 100644 --- a/src/Revise/ReviseAlbumDatabase.php +++ b/src/Revise/ReviseAlbumDatabase.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -20,18 +20,26 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Exception as DoctrineDBALException; +use FOS\HttpCacheBundle\CacheManager; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; use Symfony\Component\HttpFoundation\RequestStack; class ReviseAlbumDatabase { - public function __construct( - private readonly RequestStack $requestStack, - private readonly Connection $connection, - private readonly string $projectDir, - private readonly string $galleryCreatorUploadPath, - ) { + private RequestStack $requestStack; + private Connection $connection; + private CacheManager $cacheManager; + private string $projectDir; + private string $galleryCreatorUploadPath; + + public function __construct(RequestStack $requestStack, Connection $connection, CacheManager $cacheManager, string $projectDir, string $galleryCreatorUploadPath) + { + $this->requestStack = $requestStack; + $this->connection = $connection; + $this->cacheManager = $cacheManager; + $this->projectDir = $projectDir; + $this->galleryCreatorUploadPath = $galleryCreatorUploadPath; } /** diff --git a/src/Security/GalleryCreatorAlbumPermissions.php b/src/Security/GalleryCreatorAlbumPermissions.php index de35256..4bbeb10 100644 --- a/src/Security/GalleryCreatorAlbumPermissions.php +++ b/src/Security/GalleryCreatorAlbumPermissions.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/src/Security/Voter/AlbumVoter.php b/src/Security/Voter/AlbumVoter.php index 5658a02..aff9a02 100644 --- a/src/Security/Voter/AlbumVoter.php +++ b/src/Security/Voter/AlbumVoter.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -34,9 +34,11 @@ class AlbumVoter extends Voter 'can_move_images' => 7, ]; - public function __construct( - private readonly ContaoFramework $framework, - ) { + private ContaoFramework $framework; + + public function __construct(ContaoFramework $framework) + { + $this->framework = $framework; } /** diff --git a/src/Util/AlbumUtil.php b/src/Util/AlbumUtil.php index 84d5db5..7337b03 100644 --- a/src/Util/AlbumUtil.php +++ b/src/Util/AlbumUtil.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -22,10 +22,13 @@ class AlbumUtil { - public function __construct( - private readonly ScopeMatcher $scopeMatcher, - private readonly RequestStack $requestStack, - ) { + private ScopeMatcher $scopeMatcher; + private RequestStack $requestStack; + + public function __construct(ScopeMatcher $scopeMatcher, RequestStack $requestStack) + { + $this->scopeMatcher = $scopeMatcher; + $this->requestStack = $requestStack; } public function countAlbumViews(GalleryCreatorAlbumsModel $albumModel): void diff --git a/src/Util/FileUtil.php b/src/Util/FileUtil.php index e19b0fb..82eccd5 100644 --- a/src/Util/FileUtil.php +++ b/src/Util/FileUtil.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -39,15 +39,23 @@ class FileUtil { - public function __construct( - private readonly RequestStack $requestStack, - private readonly Connection $connection, - private readonly TranslatorInterface $translator, - private readonly string $projectDir, - private readonly bool $galleryCreatorCopyImagesOnImport, - private readonly array $galleryCreatorValidExtensions, - private readonly LoggerInterface|null $logger = null, - ) { + private RequestStack $requestStack; + private Connection $connection; + private TranslatorInterface $translator; + private string $projectDir; + private bool $galleryCreatorCopyImagesOnImport; + private array $galleryCreatorValidExtensions; + private ?LoggerInterface $logger; + + public function __construct(RequestStack $requestStack, Connection $connection, TranslatorInterface $translator, string $projectDir, bool $galleryCreatorCopyImagesOnImport, array $galleryCreatorValidExtensions, LoggerInterface $logger = null) + { + $this->requestStack = $requestStack; + $this->connection = $connection; + $this->translator = $translator; + $this->projectDir = $projectDir; + $this->galleryCreatorCopyImagesOnImport = $galleryCreatorCopyImagesOnImport; + $this->galleryCreatorValidExtensions = $galleryCreatorValidExtensions; + $this->logger = $logger; } /** diff --git a/src/Util/MarkdownUtil.php b/src/Util/MarkdownUtil.php index 765e65b..6153426 100644 --- a/src/Util/MarkdownUtil.php +++ b/src/Util/MarkdownUtil.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -16,13 +16,9 @@ use Contao\Config; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\InsertTag\CommonMarkExtension; -use Contao\CoreBundle\InsertTag\InsertTagParser; use Contao\Input; -use League\CommonMark\ConverterInterface; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\Autolink\AutolinkExtension; -use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension; use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use League\CommonMark\Extension\Table\TableExtension; @@ -33,43 +29,33 @@ class MarkdownUtil { - public function __construct( - private readonly ContaoFramework $framework, - private readonly RequestStack $requestStack, - private readonly InsertTagParser $insertTagParser, - ) { + private ContaoFramework $framework; + private RequestStack $requestStack; + + public function __construct(ContaoFramework $framework, RequestStack $requestStack) + { + $this->framework = $framework; + $this->requestStack = $requestStack; } - public function parse(string $markdown): string + public function parse(string $strMarkdown): string { $request = $this->requestStack->getCurrentRequest(); + /** @var Config $config */ $config = $this->framework->getAdapter(Config::class); + + /** @var Input $input */ $input = $this->framework->getAdapter(Input::class); - $html = $this->createConverter($request)->convert($markdown); + + $html = $this->createConverter($request)->convertToHtml($strMarkdown); return $input->stripTags($html, $config->get('allowedTags'), $config->get('allowedAttributes')); } - /** - * Hint: This is protected on purpose, so you can override it for your app specific requirements. - * If you want to provide an extension with additional logic, consider providing your own special - * content element for that. - */ - protected function createConverter(Request $request): ConverterInterface + private function createConverter(Request $request): MarkdownConverter { - $environment = new Environment([ - 'external_link' => [ - 'internal_hosts' => $request->getHost(), - 'open_in_new_window' => true, - 'html_class' => 'external-link', - 'noopener' => 'external', - 'noreferrer' => 'external', - ], - ]); - - $environment->addExtension(new CommonMarkExtension($this->insertTagParser)); - $environment->addExtension(new CommonMarkCoreExtension()); + $environment = Environment::createCommonMarkEnvironment(); // Support GitHub flavoured Markdown (using the individual extensions because we don't want the // DisallowedRawHtmlExtension which is included by default) @@ -81,6 +67,16 @@ protected function createConverter(Request $request): ConverterInterface // Automatically mark external links as such if we have a request $environment->addExtension(new ExternalLinkExtension()); + $environment->mergeConfig([ + 'external_link' => [ + 'internal_hosts' => $request->getHost(), + 'open_in_new_window' => true, + 'html_class' => 'external-link', + 'noopener' => 'external', + 'noreferrer' => 'external', + ], + ]); + return new MarkdownConverter($environment); } } diff --git a/src/Util/PictureUtil.php b/src/Util/PictureUtil.php index c6e6cc9..25f63eb 100644 --- a/src/Util/PictureUtil.php +++ b/src/Util/PictureUtil.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -14,14 +14,15 @@ namespace Markocupic\GalleryCreatorBundle\Util; +use Contao\Config; use Contao\ContentModel; use Contao\CoreBundle\File\Metadata; -use Contao\CoreBundle\Filesystem\FilesystemUtil; -use Contao\CoreBundle\Filesystem\VirtualFilesystem; -use Contao\CoreBundle\Image\Studio\Studio; use Contao\CoreBundle\Routing\ScopeMatcher; use Contao\File; use Contao\FilesModel; +use Contao\Frontend; +use Contao\Input; +use Contao\StringUtil; use Contao\System; use Contao\UserModel; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel; @@ -29,96 +30,96 @@ class PictureUtil { - public function __construct( - private readonly RequestStack $requestStack, - private readonly ScopeMatcher $scopeMatcher, - private readonly Studio $studio, - private readonly VirtualFilesystem $filesStorage, - private readonly bool $galleryCreatorReadExifMetaData, - private readonly string $projectDir, - ) { + private ScopeMatcher $scopeMatcher; + private RequestStack $requestStack; + private bool $galleryCreatorReadExifMetaData; + private string $projectDir; + + public function __construct(ScopeMatcher $scopeMatcher, RequestStack $requestStack, bool $galleryCreatorReadExifMetaData, string $projectDir) + { + $this->scopeMatcher = $scopeMatcher; + $this->requestStack = $requestStack; + $this->galleryCreatorReadExifMetaData = $galleryCreatorReadExifMetaData; + $this->projectDir = $projectDir; } /** * @throws \Exception */ - public function getPictureData(GalleryCreatorPicturesModel $pictureModel, ContentModel $contentElementModel): array|null + public function getPictureData(GalleryCreatorPicturesModel $pictureModel, ContentModel $contentElementModel): ?array { - $staticUrl = System::getContainer()->get('contao.assets.files_context')->getStaticUrl(); + global $objPage; - $request = $this->requestStack->getCurrentRequest(); + $tlFilesUrl = System::getContainer()->get('contao.assets.files_context')->getStaticUrl(); - $filesystemIterator = FilesystemUtil::listContentsFromSerialized($this->filesStorage, $pictureModel->uuid); - $fileSystemItem = $filesystemIterator->first(); + $request = $this->requestStack->getCurrentRequest(); - if (null === $fileSystemItem || !$fileSystemItem->isFile()) { + if (null === ($filesModel = FilesModel::findByUuid($pictureModel->uuid))) { return null; } - if (null === ($filesModel = FilesModel::findByUuid($pictureModel->uuid))) { + if (!is_file($filesModel->getAbsolutePath())) { return null; } - // Get file meta data - $arrMeta = $this->filesStorage->getExtraMetadata($fileSystemItem->getUuid()); + // Meta + $arrMeta = Frontend::getMetaData($filesModel->meta, $objPage->language); if (!isset($arrMeta['title'])) { $arrMeta['title'] = ''; } - // Override file meta title with the picture caption $arrMeta['title'] = $pictureModel->caption ?? $arrMeta['title']; - $customHref = ''; + // Get thumb dimensions + $arrSize = StringUtil::deserialize($contentElementModel->gcSizeDetailView); + + $href = null; $localMediaSrc = null; $socialMediaSrc = null; if ($request && $this->scopeMatcher->isFrontendRequest($request)) { // e.g. youtube or vimeo - $customHref = $pictureModel->socialMediaSRC ?: null; + $href = $pictureModel->socialMediaSRC ?: null; $socialMediaSrc = $pictureModel->socialMediaSRC ?: null; // Local media if (null !== ($objMovieFile = FilesModel::findByUuid($pictureModel->localMediaSRC))) { - $customHref = $objMovieFile->path; - $localMediaSrc = $staticUrl.$objMovieFile->path; + $href = $objMovieFile->path; + $localMediaSrc = $tlFilesUrl.$objMovieFile->path; + } + + // Use the image path as default + if (null === $href && $contentElementModel->gcFullSize) { + $href = $filesModel->path; } - $customHref = $customHref ? $staticUrl.$customHref : null; + $href = $href ? $tlFilesUrl.$href : null; } $ownerModel = UserModel::findByPk($pictureModel->cuser); - // Compile list of images - $figure = $this->studio - ->createFigureBuilder() - ->setSize($contentElementModel->gcSizeDetailView) - ->setLightboxGroupIdentifier('lb'.$contentElementModel->id) - ->enableLightbox((bool) $contentElementModel->gcFullSize) - ->setOverwriteMetadata(new Metadata($arrMeta)) - ->fromUuid($filesModel->uuid) - ->setMetadata(new Metadata($arrMeta)) - ; - - if ($customHref) { - $figure->setLinkHref($customHref); - } - // Build the array return [ - 'row_owner' => $ownerModel ? $ownerModel->row() : [], - 'row_files' => $filesModel->row(), - 'row_picture' => $pictureModel->row(), - 'row_album' => $pictureModel->getRelated('pid')->row(), - 'local_media_src' => $localMediaSrc, - 'social_media_src' => $socialMediaSrc, - 'exif_data' => $this->galleryCreatorReadExifMetaData ? $this->getExif(new File($filesModel->path)) : [], - 'figure' => [ - 'build' => $figure->build(), - 'uuid' => $filesModel->uuid, - 'size' => $contentElementModel->gcSizeDetailView, - 'enable_lightbox' => (bool) $contentElementModel->gcFullSize, - 'meta_data' => new Metadata($arrMeta), + 'ownerRow' => $ownerModel ? $ownerModel->row() : [], + 'filesRow' => $filesModel->row(), + 'pictureRow' => $pictureModel->row, + 'albumRow' => $pictureModel->getRelated('pid')->row(), + 'meta' => $arrMeta, + 'href' => $href, + 'localMediaSrc' => $localMediaSrc, + 'socialMediaSrc' => $socialMediaSrc, + 'exif' => $this->galleryCreatorReadExifMetaData ? $this->getExif(new File($filesModel->path)) : [], + 'singleImageUrl' => StringUtil::ampersand($objPage->getFrontendUrl((Config::get('useAutoItem') ? '/' : '/items/').Input::get('items').'/img/'.$filesModel->name, $objPage->language)), + 'figureUuid' => $pictureModel->addCustomThumb ? $pictureModel->customThumb : $filesModel->uuid, + 'figureSize' => !empty($arrSize) ? $arrSize : null, + 'figureHref' => $href, + 'figureOptions' => [ + 'metadata' => new Metadata($arrMeta), + 'enableLightbox' => (bool) $contentElementModel->gcFullSize, + 'lightboxGroupIdentifier' => sprintf('data-lightbox="lb%s"', $pictureModel->pid), + //'lightboxSize' => '_big_size', + 'linkHref' => $href, ], ]; } @@ -137,16 +138,4 @@ public function getExif(File $file): array return $exif; } - - public function pictureExists(GalleryCreatorPicturesModel $picturesModel): bool - { - $filesystemIterator = FilesystemUtil::listContentsFromSerialized($this->filesStorage, $picturesModel->uuid); - $fileSystemItem = $filesystemIterator->first(); - - if (null === $fileSystemItem || !$fileSystemItem->isFile()) { - return false; - } - - return true; - } } diff --git a/src/Util/SecurityUtil.php b/src/Util/SecurityUtil.php index 9a06a5b..ccb856d 100644 --- a/src/Util/SecurityUtil.php +++ b/src/Util/SecurityUtil.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -14,22 +14,24 @@ namespace Markocupic\GalleryCreatorBundle\Util; -use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Routing\ScopeMatcher; use Contao\FrontendUser; use Contao\StringUtil; use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel; -use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Security\Core\Security; class SecurityUtil { - public function __construct( - private readonly ContaoFramework $framework, - private readonly RequestStack $requestStack, - private readonly ScopeMatcher $scopeMatcher, - private readonly Security $security, - ) { + private Security $security; + private ScopeMatcher $scopeMatcher; + private RequestStack $requestStack; + + public function __construct(Security $security, ScopeMatcher $scopeMatcher, RequestStack $requestStack) + { + $this->security = $security; + $this->scopeMatcher = $scopeMatcher; + $this->requestStack = $requestStack; } /** @@ -40,15 +42,14 @@ public function isAuthorized(GalleryCreatorAlbumsModel $albumsModel): bool { $user = $this->security->getUser(); $request = $this->requestStack->getCurrentRequest(); - $stringUtil = $this->framework->getAdapter(StringUtil::class); if (!$albumsModel->protected) { return true; } if ($request && $this->scopeMatcher->isFrontendRequest($request) && $user instanceof FrontendUser) { - $allowedGroups = $stringUtil->deserialize($albumsModel->groups, true); - $userGroups = $stringUtil->deserialize($user->groups, true); + $allowedGroups = StringUtil::deserialize($albumsModel->groups, true); + $userGroups = StringUtil::deserialize($user->groups, true); if (!empty(array_intersect($allowedGroups, $userGroups))) { return true; diff --git a/src/Widget/Backend/AlbumTreeWidget.php b/src/Widget/Backend/AlbumTreeWidget.php index 0ff848d..f131ef3 100644 --- a/src/Widget/Backend/AlbumTreeWidget.php +++ b/src/Widget/Backend/AlbumTreeWidget.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -32,7 +32,7 @@ class AlbumTreeWidget extends Widget protected $blnSubmitInput = true; protected $blnForAttribute = true; protected $strTemplate = 'be_widget'; - protected MenuItem|null $picker; + protected ?MenuItem $picker; public function __construct($arrAttributes = null) { diff --git a/src/Widget/Backend/ChmodTable.php b/src/Widget/Backend/ChmodTable.php index 2441a0e..f4b57d3 100644 --- a/src/Widget/Backend/ChmodTable.php +++ b/src/Widget/Backend/ChmodTable.php @@ -5,7 +5,7 @@ /* * This file is part of Gallery Creator Bundle. * - * (c) Marko Cupic 2023 + * (c) Marko Cupic 2022 * @license GPL-3.0-or-later * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php deleted file mode 100644 index 7c00828..0000000 --- a/tests/ContaoManager/PluginTest.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @license GPL-3.0-or-later - * For the full copyright and license information, - * please view the LICENSE file that was distributed with this source code. - * @link https://github.com/markocupic/gallery-creator-bundle - */ - -namespace Markocupic\GalleryCreatorBundle\Tests\ContaoManager; - -use Contao\CoreBundle\ContaoCoreBundle; -use Contao\ManagerPlugin\Bundle\Config\BundleConfig; -use Contao\ManagerPlugin\Bundle\Parser\DelegatingParser; -use Contao\TestCase\ContaoTestCase; -use Markocupic\GalleryCreatorBundle\ContaoManager\Plugin; - -class PluginTest extends ContaoTestCase -{ - public function testInstantiation(): void - { - $this->assertInstanceOf(Plugin::class, new Plugin()); - } - - public function testGetBundles(): void - { - $plugin = new Plugin(); - - /** @var array $bundles */ - $bundles = $plugin->getBundles(new DelegatingParser()); - - $this->assertCount(1, $bundles); - $this->assertInstanceOf(BundleConfig::class, $bundles[0]); - $this->assertSame( - [ - ContaoCoreBundle::class, - ], - $bundles[0]->getLoadAfter() - ); - } -} diff --git a/tools/ecs/batch/ecs_fixer.bat b/tools/ecs/batch/ecs_fixer.bat deleted file mode 100644 index c0223e4..0000000 --- a/tools/ecs/batch/ecs_fixer.bat +++ /dev/null @@ -1,15 +0,0 @@ -:: Run easy-coding-standard (ecs) via this batch file inside your IDE e.g. PhpStorm (Windows only) -:: Install inside PhpStorm the "Batch Script Support" plugin -cd.. -cd.. -cd.. -cd.. -cd.. -cd.. -php vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/src --fix --config vendor/markocupic/gallery-creator-bundle/tools/ecs/config.php -php vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/contao --fix --config vendor/markocupic/gallery-creator-bundle/tools/ecs/config.php -php vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/config --fix --config vendor/markocupic/gallery-creator-bundle/tools/ecs/config.php -:: php vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/templates --fix --config vendor/markocupic/gallery-creator-bundle/tools/ecs/config.php -php vendor\bin\ecs check vendor/markocupic/gallery-creator-bundle/tests --fix --config vendor/markocupic/gallery-creator-bundle/tools/ecs/config.php - - diff --git a/tools/ecs/composer.json b/tools/ecs/composer.json deleted file mode 100644 index a4dab8b..0000000 --- a/tools/ecs/composer.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "require": { - "contao/easy-coding-standard": "^5.4" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tools/ecs/config.php b/tools/ecs/config.php deleted file mode 100644 index 2578951..0000000 --- a/tools/ecs/config.php +++ /dev/null @@ -1,41 +0,0 @@ -sets([__DIR__.'/vendor/contao/easy-coding-standard/config/contao.php']); - } else { - // local development - $ecsConfig->sets([__DIR__.'/../../../../../vendor/contao/easy-coding-standard/config/contao.php']); - } - - $services = $ecsConfig->services(); - $services - ->set(HeaderCommentFixer::class) - ->call('configure', [ - [ - 'header' => "This file is part of Gallery Creator Bundle.\n\n(c) Marko Cupic ".date('Y')." \n@license GPL-3.0-or-later\nFor the full copyright and license information,\nplease view the LICENSE file that was distributed with this source code.\n@link https://github.com/markocupic/gallery-creator-bundle", - ], - ]); - - $ecsConfig->skip([ - '*/contao/dca*', - MethodChainingIndentationFixer::class => [ - 'DependencyInjection/Configuration.php', - ], - ]); - - $ecsConfig->parallel(); - $ecsConfig->lineEnding("\n"); - - $parameters = $ecsConfig->parameters(); - $parameters->set(Option::CACHE_DIRECTORY, sys_get_temp_dir().'/ecs_default_cache'); -}; diff --git a/tools/phpstan/batch/phpstan.bat b/tools/phpstan/batch/phpstan.bat deleted file mode 100644 index df4d4b6..0000000 --- a/tools/phpstan/batch/phpstan.bat +++ /dev/null @@ -1,9 +0,0 @@ -:: Run phpstan inside your IDE e.g. PhpStorm (Windows only) -:: Install inside PhpStorm the "Batch Script Support" plugin -cd.. -cd.. -cd.. -cd.. -cd.. -cd.. -php -d memory_limit=-1 vendor/bin/phpstan analyse vendor/markocupic/gallery-creator-bundle/src vendor/markocupic/gallery-creator-bundle/tests diff --git a/tools/phpstan/composer.json b/tools/phpstan/composer.json deleted file mode 100644 index dc74375..0000000 --- a/tools/phpstan/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "require": { - "phpstan/phpstan": "^1.10", - "contao/test-case": "^4.13", - "contao/core-bundle": "^5.1", - "contao/manager-bundle": "^5.1" - }, - "config": { - "allow-plugins": { - "contao-components/installer": true, - "contao/manager-plugin": true, - "contao-community-alliance/composer-plugin": true, - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tools/phpunit/.phpunit.result.cache b/tools/phpunit/.phpunit.result.cache deleted file mode 100644 index 0e1c013..0000000 --- a/tools/phpunit/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":{"Markocupic\\GalleryCreatorBundle\\Tests\\ContaoManager\\PluginTest::testInstantiation":0.004,"Markocupic\\GalleryCreatorBundle\\Tests\\ContaoManager\\PluginTest::testGetBundles":0.001}} \ No newline at end of file diff --git a/tools/phpunit/composer.json b/tools/phpunit/composer.json deleted file mode 100644 index fc43079..0000000 --- a/tools/phpunit/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "require": { - "contao/core-bundle": "^5.1", - "contao/manager-bundle": "^5.1", - "phpunit/phpunit": "^9.5", - "contao/test-case": "^5.0" - }, - "config": { - "allow-plugins": { - "contao/manager-plugin": true, - "contao-components/installer": true, - "contao-community-alliance/composer-plugin": true, - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tools/phpunit/phpunit.xml.dist b/tools/phpunit/phpunit.xml.dist deleted file mode 100644 index d105cd9..0000000 --- a/tools/phpunit/phpunit.xml.dist +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - ../../tests - - - \ No newline at end of file
{{ trans.picture_id }}: {{ model.id }}
{{ trans.picture_path }}: {{ model.path }}
{{ trans.picture_filename }}: {{ model.filename }}
{{ trans.picture_date }}: {{ model.date_formatted }}
{{ trans.picture_owner }}: {{ model.owner_name }}
{{ trans.picture_title }}: {{ model.title }}
{{ trans.picture_video_href_social }}: {{ model.video_href_social }}
{{ trans.picture_video_href_local }}: {{ model.video_href_local }}