Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/unlock-phpstan-level-5
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 16, 2020
2 parents e3b80e0 + 735f1a9 commit f18f3e5
Show file tree
Hide file tree
Showing 163 changed files with 8,101 additions and 1,877 deletions.
18 changes: 10 additions & 8 deletions calendar-bundle/src/Resources/contao/dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,17 +1199,19 @@ public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null)
throw new AccessDeniedException('Not enough permissions to publish/unpublish event ID ' . $intId . '.');
}

$objRow = $this->Database->prepare("SELECT * FROM tl_calendar_events WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows < 1)
{
throw new AccessDeniedException('Invalid event ID ' . $intId . '.');
}

// Set the current record
if ($dc)
{
$objRow = $this->Database->prepare("SELECT * FROM tl_calendar_events WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows)
{
$dc->activeRecord = $objRow;
}
$dc->activeRecord = $objRow;
}

$objVersions = new Versions('tl_calendar_events', $intId);
Expand Down
150 changes: 0 additions & 150 deletions calendar-bundle/src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@
use Contao\BackendUser;
use Contao\Calendar;
use Contao\CoreBundle\Exception\AccessDeniedException;
use Contao\DataContainer;
use Contao\Image;
use Contao\Input;
use Contao\StringUtil;
use Contao\System;
use Contao\Versions;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

// Dynamically add the permission check and other callbacks
if (Input::get('do') == 'calendar')
{
array_unshift($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'], array('tl_content_calendar', 'checkPermission'));
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_calendar', 'generateFeed');
$GLOBALS['TL_DCA']['tl_content']['list']['operations']['toggle']['button_callback'] = array('tl_content_calendar', 'toggleIcon');
}

/**
Expand Down Expand Up @@ -177,149 +172,4 @@ public function generateFeed()

$objSession->set('calendar_feed_updater', null);
}

/**
* Return the "toggle visibility" button
*
* @param array $row
* @param string $href
* @param string $label
* @param string $title
* @param string $icon
* @param string $attributes
*
* @return string
*/
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
if (Input::get('cid'))
{
$this->toggleVisibility(Input::get('cid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null));
$this->redirect($this->getReferer());
}

// Check permissions AFTER checking the cid, so hacking attempts are logged
if (!$this->User->hasAccess('tl_content::invisible', 'alexf'))
{
return '';
}

$href .= '&amp;id=' . Input::get('id') . '&amp;cid=' . $row['id'] . '&amp;state=' . $row['invisible'];

if ($row['invisible'])
{
$icon = 'invisible.svg';
}

return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '" data-tid="cid"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['invisible'] ? 0 : 1) . '"') . '</a> ';
}

/**
* Toggle the visibility of an element
*
* @param integer $intId
* @param boolean $blnVisible
* @param DataContainer $dc
*/
public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null)
{
// Set the ID and action
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');

if ($dc)
{
$dc->id = $intId; // see #8043
}

// Trigger the onload_callback
if (is_array($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($dc);
}
elseif (is_callable($callback))
{
$callback($dc);
}
}
}

// Check the field access
if (!$this->User->hasAccess('tl_content::invisible', 'alexf'))
{
throw new AccessDeniedException('Not enough permissions to publish/unpublish content element ID ' . $intId . '.');
}

// Set the current record
if ($dc)
{
$objRow = $this->Database->prepare("SELECT * FROM tl_content WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows)
{
$dc->activeRecord = $objRow;
}
}

$objVersions = new Versions('tl_content', $intId);
$objVersions->initialize();

// Reverse the logic (elements have invisible=1)
$blnVisible = !$blnVisible;

// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc);
}
elseif (is_callable($callback))
{
$blnVisible = $callback($blnVisible, $dc);
}
}
}

$time = time();

// Update the database
$this->Database->prepare("UPDATE tl_content SET tstamp=$time, invisible='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
->execute($intId);

if ($dc)
{
$dc->activeRecord->tstamp = $time;
$dc->activeRecord->invisible = ($blnVisible ? '1' : '');
}

// Trigger the onsubmit_callback
if (is_array($GLOBALS['TL_DCA']['tl_content']['config']['onsubmit_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_content']['config']['onsubmit_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($dc);
}
elseif (is_callable($callback))
{
$callback($dc);
}
}
}

$objVersions->create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<source>Require login to comment</source>
</trans-unit>
<trans-unit id="tl_calendar.requireLogin.1">
<source>Allow only authenticated users to create comments.</source>
<source>Allow only authenticated members to create comments.</source>
</trans-unit>
<trans-unit id="tl_calendar.disableCaptcha.0">
<source>Disable spam protection</source>
Expand Down
16 changes: 14 additions & 2 deletions calendar-bundle/src/Resources/contao/modules/ModuleEventlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,19 @@ protected function compile()
}
}

$rootDir = System::getContainer()->getParameter('kernel.project_dir');
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
$uuids = array();

for ($i=$offset; $i<$limit; $i++)
{
if ($arrEvents[$i]['addImage'] && $arrEvents[$i]['singleSRC'] != '')
{
$uuids[] = $arrEvents[$i]['singleSRC'];
}
}

// Preload all images in one query so they are loaded into the model registry
FilesModel::findMultipleByUuids($uuids);

// Parse events
for ($i=$offset; $i<$limit; $i++)
Expand Down Expand Up @@ -340,7 +352,7 @@ protected function compile()
{
$objModel = FilesModel::findByUuid($event['singleSRC']);

if ($objModel !== null && is_file($rootDir . '/' . $objModel->path))
if ($objModel !== null && is_file($projectDir . '/' . $objModel->path))
{
if ($imgSize)
{
Expand Down
24 changes: 24 additions & 0 deletions calendar-bundle/src/Security/ContaoCalendarPermissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CalendarBundle\Security;

final class ContaoCalendarPermissions
{
public const USER_CAN_EDIT_CALENDAR = 'contao_user.calendars';
public const USER_CAN_CREATE_CALENDARS = 'contao_user.calendarp.create';
public const USER_CAN_DELETE_CALENDARS = 'contao_user.calendarp.delete';

public const USER_CAN_EDIT_FEED = 'contao_user.calendarfeeds';
public const USER_CAN_CREATE_FEEDS = 'contao_user.calendarfeedp.create';
public const USER_CAN_DELETE_FEEDS = 'contao_user.calendarfeedp.delete';
}
18 changes: 10 additions & 8 deletions comments-bundle/src/Resources/contao/dca/tl_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,19 @@ public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null)
throw new AccessDeniedException('Not enough permissions to publish/unpublish comment ID ' . $intId . '.');
}

$objRow = $this->Database->prepare("SELECT * FROM tl_comments WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows < 1)
{
throw new AccessDeniedException('Invalid comment ID ' . $intId . '.');
}

// Set the current record
if ($dc)
{
$objRow = $this->Database->prepare("SELECT * FROM tl_comments WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows)
{
$dc->activeRecord = $objRow;
}
$dc->activeRecord = $objRow;
}

$objVersions = new Versions('tl_comments', $intId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<source>Require login to comment</source>
</trans-unit>
<trans-unit id="tl_content.com_requireLogin.1">
<source>Allow only authenticated users to create comments.</source>
<source>Allow only authenticated members to create comments.</source>
</trans-unit>
<trans-unit id="tl_content.com_disableCaptcha.0">
<source>Disable spam protection</source>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"contao-components/tinymce4": "^4.7",
"contao/image": "^1.0",
"contao/imagine-svg": "^0.2.3 || ^1.0",
"contao/maintenance-bundle-deprecated": "^2.1.5",
"contao/manager-plugin": "^2.6.2",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
Expand All @@ -60,7 +61,6 @@
"lcobucci/jwt": "^3.2",
"league/uri-components": "^1.8",
"league/uri-schemes": "^1.2",
"lexik/maintenance-bundle": "^2.1.5",
"matthiasmullie/minify": "^1.3",
"michelf/php-markdown": "^1.4",
"nelmio/cors-bundle": "^1.5.3 || ^2.0.1",
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@
"require-dev": {
"ext-fileinfo": "*",
"composer/composer": "^1.0",
"contao/maintenance-bundle-deprecated": "^2.1.5",
"contao/manager-plugin": "^2.3.1",
"contao/test-case": "^4.2",
"doctrine/event-manager": "^1.0",
"lexik/maintenance-bundle": "^2.1.5",
"monolog/monolog": "^1.24",
"phpunit/phpunit": "^8.4",
"psr/event-dispatcher": "^1.0",
"symfony/browser-kit": "4.4.*",
"symfony/http-client": "4.4.*",
"symfony/monolog-bundle": "^3.1",
"symfony/phpunit-bridge": "4.4.*"
},
"suggest": {
"contao/tcpdf-bundle": "To export articles as PDF files",
"lexik/maintenance-bundle": "To put the application into maintenance mode"
"contao/tcpdf-bundle": "To export articles as PDF files"
},
"extra": {
"branch-alias": {
Expand Down
10 changes: 5 additions & 5 deletions core-bundle/src/Cache/ContaoCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ContaoCacheWarmer implements CacheWarmerInterface
/**
* @var string
*/
private $rootDir;
private $projectDir;

/**
* @var Connection
Expand All @@ -68,12 +68,12 @@ class ContaoCacheWarmer implements CacheWarmerInterface
/**
* @internal Do not inherit from this class; decorate the "contao.cache.warm_internal" service instead
*/
public function __construct(Filesystem $filesystem, ResourceFinderInterface $finder, FileLocator $locator, string $rootDir, Connection $connection, ContaoFramework $framework, array $locales)
public function __construct(Filesystem $filesystem, ResourceFinderInterface $finder, FileLocator $locator, string $projectDir, Connection $connection, ContaoFramework $framework, array $locales)
{
$this->filesystem = $filesystem;
$this->finder = $finder;
$this->locator = $locator;
$this->rootDir = $rootDir;
$this->projectDir = $projectDir;
$this->connection = $connection;
$this->framework = $framework;
$this->locales = $locales;
Expand Down Expand Up @@ -140,7 +140,7 @@ private function generateLanguageCache(string $cacheDir): void
{
$dumper = new CombinedFileDumper(
$this->filesystem,
new DelegatingLoader(new LoaderResolver([new PhpFileLoader(), new XliffFileLoader($this->rootDir)])),
new DelegatingLoader(new LoaderResolver([new PhpFileLoader(), new XliffFileLoader($this->projectDir)])),
Path::join($cacheDir, 'contao')
);

Expand Down Expand Up @@ -223,7 +223,7 @@ private function generateTemplateMapper(string $cacheDir): void
$mapper = [];

foreach ($files as $file) {
$mapper[$file->getBasename('.html5')] = Path::makeRelative($file->getPath(), $this->rootDir);
$mapper[$file->getBasename('.html5')] = Path::makeRelative($file->getPath(), $this->projectDir);
}

$this->filesystem->dumpFile(
Expand Down
3 changes: 2 additions & 1 deletion core-bundle/src/Command/AutomatorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
class AutomatorCommand extends Command
{
protected static $defaultName = 'contao:automator';

/**
* @var array
*/
Expand All @@ -48,7 +50,6 @@ public function __construct(ContaoFramework $framework)
protected function configure(): void
{
$this
->setName('contao:automator')
->addArgument('task', InputArgument::OPTIONAL, "The name of the task:\n - ".implode("\n - ", $this->getCommands()))
->setDescription('Runs automator tasks on the command line.')
;
Expand Down

0 comments on commit f18f3e5

Please sign in to comment.