-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c3f3e2d
Showing
22 changed files
with
809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* ImageCopyright for Contao Open Source CMS | ||
* | ||
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de> | ||
* @author Daniel Jahnsmüller <tastaturberuf.de> | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Tastaturberuf\ContaoImageCopyrightBundle\ContaoManager; | ||
|
||
|
||
use Contao\CoreBundle\ContaoCoreBundle; | ||
use Contao\ManagerPlugin\Bundle\BundlePluginInterface; | ||
use Contao\ManagerPlugin\Bundle\Config\BundleConfig; | ||
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; | ||
use Tastaturberuf\ContaoImageCopyrightBundle\TastaturberufContaoImageCopyrightBundle; | ||
|
||
|
||
class Plugin implements BundlePluginInterface | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getBundles(ParserInterface $parser) | ||
{ | ||
return [ | ||
BundleConfig::create(TastaturberufContaoImageCopyrightBundle::class) | ||
->setLoadAfter([ContaoCoreBundle::class]) | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
/** | ||
* ImageCopyright for Contao Open Source CMS | ||
* | ||
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de> | ||
* @author Daniel Jahnsmüller <tastaturberuf.de> | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Tastaturberuf\ContaoImageCopyrightBundle\Controller; | ||
|
||
|
||
use Contao\Config; | ||
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; | ||
use Contao\CoreBundle\Image\ImageFactoryInterface; | ||
use Contao\CoreBundle\ServiceAnnotation\FrontendModule; | ||
use Contao\FilesModel; | ||
use Contao\Model\Collection; | ||
use Contao\ModuleModel; | ||
use Contao\StringUtil; | ||
use Contao\Template; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
|
||
/** | ||
* @FrontendModule(category="miscellaneous") | ||
*/ | ||
class ImageCopyrightListController extends AbstractFrontendModuleController | ||
{ | ||
|
||
public const TYPE = 'image_copyright_list'; | ||
|
||
|
||
/** | ||
* @var ImageFactoryInterface | ||
*/ | ||
private $imageFactory; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $rootDir; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $validImageExtensions; | ||
|
||
|
||
public function __construct(ImageFactoryInterface $imageFactory, string $rootDir, array $validImageExtensions) | ||
{ | ||
$this->imageFactory = $imageFactory; | ||
$this->rootDir = $rootDir; | ||
$this->validImageExtensions = $validImageExtensions; | ||
} | ||
|
||
|
||
protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response | ||
{ | ||
if ( null !== $files = $this->getImages() ) | ||
{ | ||
$imgSize = StringUtil::deserialize($model->imgSize); | ||
|
||
foreach ($files as $file) | ||
{ | ||
$image = $this->imageFactory->create($this->rootDir.DIRECTORY_SEPARATOR.$file->path, $imgSize); | ||
|
||
$file->src = $image->getUrl($this->rootDir); | ||
$file->dimensions = $image->getDimensions(); | ||
} | ||
|
||
$template->files = $files; | ||
} | ||
|
||
return $template->getResponse(); | ||
} | ||
|
||
|
||
private function getImages(): ?Collection | ||
{ | ||
// mask all strings to e.g. 'jpeg', 'webp', ... | ||
$extensions = array_map(function (string $extension): string { | ||
return "'$extension'"; | ||
}, $this->validImageExtensions); | ||
|
||
|
||
|
||
$options = | ||
[ | ||
'column' => | ||
[ | ||
// text is set | ||
"ic_copyright != ''", | ||
// type is file | ||
"type = 'file'", | ||
// is not hidden | ||
"ic_hide = ''", | ||
// is valid image type | ||
sprintf("extension IN (%s)", join(',', $extensions)) | ||
] | ||
]; | ||
|
||
return FilesModel::findAll($options); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
DependencyInjection/TastaturberufContaoImageCopyrightExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* ImageCopyright for Contao Open Source CMS | ||
* | ||
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de> | ||
* @author Daniel Jahnsmüller <tastaturberuf.de> | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Tastaturberuf\ContaoImageCopyrightBundle\DependencyInjection; | ||
|
||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
|
||
class TastaturberufContaoImageCopyrightExtension extends Extension | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__.'/../Resources/config') | ||
); | ||
|
||
$loader->load('services.yaml'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/** | ||
* ImageCopyright for Contao Open Source CMS | ||
* | ||
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de> | ||
* @author Daniel Jahnsmüller <tastaturberuf.de> | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Tastaturberuf\ContaoImageCopyrightBundle\EventListener; | ||
|
||
|
||
use Contao\CoreBundle\DataContainer\PaletteManipulator; | ||
use Contao\CoreBundle\ServiceAnnotation\Hook; | ||
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface; | ||
|
||
|
||
class DcaFilesListener implements ServiceAnnotationInterface | ||
{ | ||
|
||
/** | ||
* @Hook("loadDataContainer", priority=1) | ||
*/ | ||
public function onLoadCallback(string $table): void | ||
{ | ||
if ( 'tl_files' !== $table ) | ||
{ | ||
return; | ||
} | ||
|
||
$this->extendPalette($table); | ||
$this->addFields($table); | ||
} | ||
|
||
|
||
private function extendPalette(string $table): void | ||
{ | ||
PaletteManipulator::create() | ||
->addLegend('tastaturberuf_image_copyright_legend', 'meta') | ||
->addField(['ic_copyright', 'ic_href', 'ic_hide'], 'tastaturberuf_image_copyright_legend') | ||
->applyToPalette('default', $table) | ||
; | ||
} | ||
|
||
|
||
private function addFields(string $table): void | ||
{ | ||
$GLOBALS['TL_DCA'][$table]['fields'] = array_replace_recursive($GLOBALS['TL_DCA'][$table]['fields'], | ||
[ | ||
'ic_copyright' => | ||
[ | ||
'exclude' => true, | ||
'inputType' => 'text', | ||
'eval' => | ||
[ | ||
'maxlength' => 128, | ||
'tl_class' => 'w50' | ||
], | ||
'sql' => "varchar(128) NOT NULL default ''" | ||
], | ||
'ic_href' => | ||
[ | ||
'exclude' => true, | ||
'inputType' => 'text', | ||
'eval' => | ||
[ | ||
'rgxp' => 'url', | ||
'maxlength' => 255, | ||
'tl_class' => 'w50' | ||
], | ||
'sql' => "varchar(255) NOT NULL default ''" | ||
], | ||
'ic_hide' => | ||
[ | ||
'exclude' => true, | ||
'inputType' => 'checkbox', | ||
'eval' => | ||
[ | ||
'tl_class' => 'clear m12 w50' | ||
], | ||
'sql' => "char(1) NOT NULL default ''" | ||
], | ||
|
||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* ImageCopyright for Contao Open Source CMS | ||
* | ||
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de> | ||
* @author Daniel Jahnsmüller <tastaturberuf.de> | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Tastaturberuf\ContaoImageCopyrightBundle\EventListener; | ||
|
||
|
||
use Contao\CoreBundle\ServiceAnnotation\Callback; | ||
use Contao\DataContainer; | ||
use Tastaturberuf\ContaoImageCopyrightBundle\Controller\ImageCopyrightListController; | ||
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface; | ||
|
||
|
||
class DcaModuleListener implements ServiceAnnotationInterface | ||
{ | ||
|
||
/** | ||
* @Callback(table="tl_module", target="config.onload") | ||
*/ | ||
public function onLoadCallback(DataContainer $dc): void | ||
{ | ||
$GLOBALS['TL_DCA'][$dc->table]['palettes'][ImageCopyrightListController::TYPE] = | ||
' | ||
{title_legend},name,headline,type; | ||
{config_legend},imgSize; | ||
{template_legend:hide},customTpl; | ||
{protected_legend:hide},protected; | ||
{expert_legend:hide},guests,cssID | ||
'; | ||
} | ||
|
||
} |
Oops, something went wrong.