Showing with 13,219 additions and 207 deletions.
  1. +15 −0 CHANGELOG.md
  2. +1 −1 README.md
  3. +4 −3 composer.json
  4. +2 −9 src/Config/Dumper/CombinedFileDumper.php
  5. +99 −19 src/Config/Loader/PhpFileLoader.php
  6. +24 −7 src/Cors/WebsiteRootsConfigProvider.php
  7. +1 −0 src/EventListener/CommandSchedulerListener.php
  8. +2 −0 src/EventListener/PrettyErrorScreenListener.php
  9. +1 −1 src/Image/ImageFactoryInterface.php
  10. +1 −1 src/Resources/contao/classes/DataContainer.php
  11. +2 −2 src/Resources/contao/classes/FrontendTemplate.php
  12. +1 −1 src/Resources/contao/classes/Versions.php
  13. +1 −1 src/Resources/contao/config/constants.php
  14. +15 −4 src/Resources/contao/dca/tl_files.php
  15. +1 −1 src/Resources/contao/dca/tl_module.php
  16. +1 −1 src/Resources/contao/dca/tl_templates.php
  17. +10 −1 src/Resources/contao/drivers/DC_Folder.php
  18. +1 −1 src/Resources/contao/drivers/DC_Table.php
  19. +1 −1 src/Resources/contao/forms/FormTextArea.php
  20. +1,026 −0 src/Resources/contao/languages/sr/countries.xlf
  21. +2,367 −0 src/Resources/contao/languages/sr/default.xlf
  22. +150 −0 src/Resources/contao/languages/sr/exception.xlf
  23. +110 −0 src/Resources/contao/languages/sr/explain.xlf
  24. +1,190 −0 src/Resources/contao/languages/sr/languages.xlf
  25. +382 −0 src/Resources/contao/languages/sr/modules.xlf
  26. +282 −0 src/Resources/contao/languages/sr/tl_article.xlf
  27. +798 −0 src/Resources/contao/languages/sr/tl_content.xlf
  28. +266 −0 src/Resources/contao/languages/sr/tl_files.xlf
  29. +246 −0 src/Resources/contao/languages/sr/tl_form.xlf
  30. +558 −0 src/Resources/contao/languages/sr/tl_form_field.xlf
  31. +170 −0 src/Resources/contao/languages/sr/tl_image_size.xlf
  32. +122 −0 src/Resources/contao/languages/sr/tl_image_size_item.xlf
  33. +574 −0 src/Resources/contao/languages/sr/tl_layout.xlf
  34. +94 −0 src/Resources/contao/languages/sr/tl_log.xlf
  35. +166 −0 src/Resources/contao/languages/sr/tl_maintenance.xlf
  36. +298 −0 src/Resources/contao/languages/sr/tl_member.xlf
  37. +114 −0 src/Resources/contao/languages/sr/tl_member_group.xlf
  38. +758 −0 src/Resources/contao/languages/sr/tl_module.xlf
  39. +575 −0 src/Resources/contao/languages/sr/tl_page.xlf
  40. +405 −0 src/Resources/contao/languages/sr/tl_settings.xlf
  41. +639 −0 src/Resources/contao/languages/sr/tl_style.xlf
  42. +166 −0 src/Resources/contao/languages/sr/tl_style_sheet.xlf
  43. +78 −0 src/Resources/contao/languages/sr/tl_templates.xlf
  44. +216 −0 src/Resources/contao/languages/sr/tl_theme.xlf
  45. +62 −0 src/Resources/contao/languages/sr/tl_undo.xlf
  46. +373 −0 src/Resources/contao/languages/sr/tl_user.xlf
  47. +126 −0 src/Resources/contao/languages/sr/tl_user_group.xlf
  48. +6 −0 src/Resources/contao/library/Contao/Combiner.php
  49. +2 −4 src/Resources/contao/library/Contao/Controller.php
  50. +1 −1 src/Resources/contao/library/Contao/Database.php
  51. +1 −1 src/Resources/contao/library/Contao/Dbafs.php
  52. +6 −0 src/Resources/contao/library/Contao/DcaExtractor.php
  53. +8 −1 src/Resources/contao/library/Contao/Environment.php
  54. +2 −1 src/Resources/contao/library/Contao/File.php
  55. +37 −3 src/Resources/contao/library/Contao/Idna.php
  56. +1 −8 src/Resources/contao/library/Contao/Image.php
  57. +9 −5 src/Resources/contao/library/Contao/Template.php
  58. +0 −2 src/Resources/contao/library/Contao/ZipReader.php
  59. +2 −2 src/Resources/contao/models/PageModel.php
  60. +5 −0 src/Resources/contao/modules/ModuleBooknav.php
  61. +3 −3 src/Resources/contao/modules/ModuleLogin.php
  62. +1 −1 src/Resources/contao/modules/ModuleUser.php
  63. +1 −1 src/Resources/contao/templates/backend/be_alerts.html5
  64. +1 −1 src/Resources/contao/templates/backend/be_confirm.html5
  65. +1 −1 src/Resources/contao/templates/backend/be_diff.html5
  66. +1 −1 src/Resources/contao/templates/backend/be_help.html5
  67. +1 −1 src/Resources/contao/templates/backend/be_login.html5
  68. +1 −1 src/Resources/contao/templates/backend/be_main.html5
  69. +1 −1 src/Resources/contao/templates/backend/be_password.html5
  70. +1 −1 src/Resources/contao/templates/backend/be_picker.html5
  71. +1 −1 src/Resources/contao/templates/backend/be_popup.html5
  72. +1 −1 src/Resources/contao/templates/backend/be_preview.html5
  73. +1 −1 src/Resources/contao/templates/backend/be_switch.html5
  74. +1 −1 src/Resources/contao/themes/flexible/main.css
  75. +0 −1 src/Resources/contao/themes/flexible/src/main.css
  76. +1 −0 src/Resources/public/mootao.js
  77. +1 −1 src/Resources/public/mootao.min.js
  78. +4 −1 src/Util/SymlinkUtil.php
  79. +69 −8 tests/Command/UserPasswordCommandTest.php
  80. +2 −17 tests/Config/Dumper/CombinedFileDumperTest.php
  81. +180 −4 tests/Config/Loader/PhpFileLoaderTest.php
  82. +72 −69 tests/Contao/EnvironmentTest.php
  83. +41 −0 tests/ContaoManager/PluginTest.php
  84. +112 −5 tests/Cors/WebsiteRootsConfigProviderTest.php
  85. +7 −1 tests/EventListener/CommandSchedulerListenerTest.php
  86. +21 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare1.php
  87. +21 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare2.php
  88. +25 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare3.php
  89. +22 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare4.php
  90. +22 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare5.php
  91. +22 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_declare6.php
  92. +7 −0 tests/Fixtures/vendor/contao/test-bundle/Resources/contao/dca/tl_test_with_namespace.php
  93. +0 −2 tests/TestCase.php
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Contao core bundle change log

### 4.3.8 (2017-04-24)

* Inline small images in protected folders in the file manager (see #636).
* Correctly encode the URL in the DataContainer::switchToEdit() method (see #762).
* Fix the parent view drag and drop in Firefox (see #666).
* Correctly display the search results in the extended tree view (see #739).
* Update the Punycode library to version 2 (see #748).
* Fix the "delete file" button for non-admin users (see #764).
* Prevent endless loops in the book navigation module (see contao/core#8665).
* Limit the maximum size of dimensionless SVGs in the back end (see contao/core#8684).
* Correctly support 64 character template names everywhere (see contao/core#6819).
* Remove the UTF-8 BOM when combining files (see contao/core#8689).
* Correctly move folders with an "@" in their name (see contao/core#8674).
* Correctly redirect to the last page visited upon login (see contao/core#8632).

### 4.3.7 (2017-03-23)

* Check the database connection in the WebsiteRootsConfigProvider class.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ContaoCoreBundle:
resource: "@ContaoCoreBundle/Resources/config/routing.yml"
```

Add the following entries to your `app/config/security.yml` file:
Replace the content of your `app/config/security.yml` file with the following:

```yml
imports:
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"oyejorge/less.php": "^1.7",
"patchwork/utf8": "^1.2",
"phpspec/php-diff": "^1.0",
"phpunit/php-token-stream": "^1.4",
"psr/log": "^1.0",
"simplepie/simplepie": "^1.3",
"swiftmailer/swiftmailer": "^5.4.5",
"tecnickcom/tcpdf": "^6.0",
"true/punycode": "^1.0",
"true/punycode": "^2.0",
"twig/twig": "^1.20",
"contao/image": "^0.3.1",
"contao/imagine-svg": "^0.1.2",
Expand Down Expand Up @@ -86,7 +86,8 @@
"contao/core": "*",
"contao/manager-plugin": "<2.0 || >=3.0",
"doctrine/orm": "<2.4",
"doctrine/doctrine-migrations-bundle": "<1.1"
"doctrine/doctrine-migrations-bundle": "<1.1",
"swiftmailer/swiftmailer": "<5.4.5"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 2 additions & 9 deletions src/Config/Dumper/CombinedFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Contao\CoreBundle\Config\Dumper;

use Contao\CoreBundle\Config\Loader\PhpFileLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -83,19 +84,11 @@ public function setHeader($header)
*/
public function dump($files, $cacheFile, array $options = [])
{
$type = isset($options['type']) ? $options['type'] : null;
$buffer = $this->header;
$type = $this->addNamespace ? PhpFileLoader::NAMESPACED : null;

foreach ((array) $files as $file) {
if ($this->addNamespace) {
$buffer .= "\nnamespace {";
}

$buffer .= $this->loader->load($file, $type);

if ($this->addNamespace) {
$buffer .= "\n}\n";
}
}

$this->filesystem->dumpFile($this->cacheDir.'/'.$cacheFile, $buffer);
Expand Down
118 changes: 99 additions & 19 deletions src/Config/Loader/PhpFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*
* @author Andreas Schempp <https://github.com/aschempp>
* @author Leo Feyer <https://github.com/leofeyer>
* @author Yanick Witschi <https://github.com/Toflar>
*/
class PhpFileLoader extends Loader
{
const NAMESPACED = 'namespaced';

/**
* Reads the contents of a PHP file stripping the opening and closing PHP tags.
*
Expand All @@ -30,29 +33,15 @@ class PhpFileLoader extends Loader
*/
public function load($file, $type = null)
{
$code = rtrim(file_get_contents($file));
list($code, $namespace) = $this->parseFile($file);

// Opening tag
if (0 === strncmp($code, '<?php', 5)) {
$code = substr($code, 5);
}
$code = $this->stripLegacyCheck($code);

// Access check
$code = str_replace(
[
" if (!defined('TL_ROOT')) die('You cannot access this file directly!');",
" if (!defined('TL_ROOT')) die('You can not access this file directly!');",
],
'',
$code
);

// Closing tag
if (substr($code, -2) === '?>') {
$code = substr($code, 0, -2);
if (false !== $namespace && self::NAMESPACED === $type) {
$code = sprintf("\nnamespace %s {%s}\n", $namespace, $code);
}

return rtrim($code)."\n";
return $code;
}

/**
Expand All @@ -62,4 +51,95 @@ public function supports($resource, $type = null)
{
return 'php' === pathinfo($resource, PATHINFO_EXTENSION);
}

/**
* Parses a file and returns the code and namespace.
*
* @param string $file
*
* @return array
*/
private function parseFile($file)
{
$code = '';
$namespace = '';
$buffer = false;
$stream = new \PHP_Token_Stream($file);

foreach ($stream as $token) {
switch (true) {
case $token instanceof \PHP_Token_OPEN_TAG:
case $token instanceof \PHP_Token_CLOSE_TAG:
// remove
break;

case false !== $buffer:
$buffer .= $token;

if (';' === (string) $token) {
$code .= $this->handleDeclare($buffer);
$buffer = false;
}
break;

case $token instanceof \PHP_Token_NAMESPACE:
if ('{' === $token->getName()) {
$namespace = false;
$code .= $token;
} else {
$namespace = $token->getName();
$stream->seek($token->getEndTokenId());
}
break;

case $token instanceof \PHP_Token_DECLARE:
$buffer = (string) $token;
break;

default:
$code .= $token;
}
}

return [$code, $namespace];
}

/**
* Handles the declare() statement.
*
* @param string $code
*
* @return string
*/
private function handleDeclare($code)
{
$code = preg_replace('/(,\s*)?strict_types\s*=\s*1(\s*,)?/', '', $code);

if (preg_match('/declare\(\s*\)/', $code)) {
return '';
}

return str_replace(' ', '', $code);
}

/**
* Strips the legacy check from the code.
*
* @param string $code
*
* @return string
*/
private function stripLegacyCheck($code)
{
$code = str_replace(
[
"if (!defined('TL_ROOT')) die('You cannot access this file directly!');",
"if (!defined('TL_ROOT')) die('You can not access this file directly!');",
],
'',
$code
);

return "\n".trim($code)."\n";
}
}
31 changes: 24 additions & 7 deletions src/Cors/WebsiteRootsConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ public function __construct(Connection $connection)
*/
public function getOptions(Request $request)
{
if (!$request->headers->has('Origin')
|| '' === $request->headers->get('Origin')
|| !$this->connection->isConnected()
|| !$this->connection->getSchemaManager()->tablesExist(['tl_page'])
) {
if (!$this->hasOrigin($request) || !$this->canRunDbQuery()) {
return [];
}

$stmt = $this->connection->prepare('SELECT id FROM tl_page WHERE type=:type AND dns=:dns');
$stmt->bindValue('type', 'root');
$stmt = $this->connection->prepare("SELECT id FROM tl_page WHERE type='root' AND dns=:dns");
$stmt->bindValue('dns', preg_replace('@^https?://@', '', $request->headers->get('origin')));
$stmt->execute();

Expand All @@ -64,4 +59,26 @@ public function getOptions(Request $request)
'allow_headers' => ['x-requested-with'],
];
}

/**
* Checks if the request has an Origin header.
*
* @param Request $request
*
* @return bool
*/
private function hasOrigin(Request $request)
{
return $request->headers->has('Origin') && '' !== $request->headers->get('Origin');
}

/**
* Checks if the database connection and the table exist.
*
* @return bool
*/
private function canRunDbQuery()
{
return $this->connection->isConnected() && $this->connection->getSchemaManager()->tablesExist(['tl_page']);
}
}
1 change: 1 addition & 0 deletions src/EventListener/CommandSchedulerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private function canRunController()

return $config->isComplete()
&& !$config->get('disableCron')
&& $this->connection->isConnected()
&& $this->connection->getSchemaManager()->tablesExist(['tl_cron'])
;
}
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/PrettyErrorScreenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ private function renderErrorScreenByType($type, GetResponseForExceptionEvent $ev
*/
private function getResponseFromPageHandler($type)
{
$this->framework->initialize();

$type = 'error_'.$type;

if (!isset($GLOBALS['TL_PTY'][$type]) || !class_exists($GLOBALS['TL_PTY'][$type])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Image/ImageFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ImageFactoryInterface
/**
* Creates an Image object.
*
* @param string|ImageInterface $path The path to the source image or an Image object
* @param string|ImageInterface $path The absolute path to the source image or an Image object
* @param int|array|ResizeConfigurationInterface|null $size An image size ID, an array with width, height and
* resize mode or a ResizeConfiguration object
* @param string|null $targetPath
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/classes/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ protected function switchToEdit($id)

$strUrl = TL_SCRIPT . '?' . implode('&', $arrKeys);

return $strUrl . (!empty($arrKeys) ? '&' : '') . (\Input::get('table') ? 'table='.\Input::get('table').'&amp;' : '').'act=edit&amp;id='.$id;
return $strUrl . (!empty($arrKeys) ? '&' : '') . (\Input::get('table') ? 'table='.\Input::get('table').'&amp;' : '').'act=edit&amp;id='.rawurlencode($id);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/classes/FrontendTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function section($key, $template=null)
if ($template === null)
{
$template = 'block_section';

foreach ($this->positions as $position)
{
if (isset($position[$key]['template']))
Expand Down Expand Up @@ -366,7 +366,7 @@ private function setCacheHeaders(Response $response)
/** @var $objPage \PageModel */
global $objPage;

if ($objPage->cache === false && $objPage->clientCache === false)
if (($objPage->cache === false || $objPage->cache === 0) && ($objPage->clientCache === false || $objPage->clientCache === 0))
{
return $response->setPrivate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/classes/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function create()
}
elseif (!empty($objRecord->headline))
{
$chunks = deserialize($objRecord->headline);
$chunks = \StringUtil::deserialize($objRecord->headline);

if (is_array($chunks) && isset($chunks['value']))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Core version
define('VERSION', '4.3');
define('BUILD', '7');
define('BUILD', '8');
define('LONG_TERM_SUPPORT', false);

// Link constants
Expand Down
19 changes: 15 additions & 4 deletions src/Resources/contao/dca/tl_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,12 @@ public function checkPermission()

case 'delete':
$strFile = Input::get('id', true);

if (is_dir(TL_ROOT . '/' . $strFile))
{
$files = scan(TL_ROOT . '/' . $strFile);
if (!empty($files) && !$canDeleteRecursive)
$finder = Symfony\Component\Finder\Finder::create()->in(TL_ROOT . '/' . $strFile);

if ($finder->count() > 0 && !$canDeleteRecursive)
{
throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete folder "' . $strFile . '" recursively.');
}
Expand Down Expand Up @@ -567,9 +569,18 @@ public function cutFile($row, $href, $label, $title, $icon, $attributes)
*/
public function deleteFile($row, $href, $label, $title, $icon, $attributes)
{
if (is_dir(TL_ROOT . '/' . $row['id']) && count(scan(TL_ROOT . '/' . $row['id'])) > 0)
if (is_dir(TL_ROOT . '/' . $row['id']))
{
return $this->User->hasAccess('f4', 'fop') ? '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' ';
$finder = Symfony\Component\Finder\Finder::create()->in(TL_ROOT . '/' . $row['id']);

if ($finder->count() > 0)
{
return $this->User->hasAccess('f4', 'fop') ? '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' ';
}
else
{
return $this->User->hasAccess('f3', 'fop') ? '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' ';
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@
'inputType' => 'select',
'options_callback' => array('tl_module', 'getRssTemplates'),
'eval' => array('tl_class'=>'w50'),
'sql' => "varchar(32) NOT NULL default ''"
'sql' => "varchar(64) NOT NULL default ''"
),
'numberOfItems' => array
(
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
(
array('tl_templates', 'addFileLocation')
),
'eval' => array('mandatory'=>true, 'maxlength'=>32, 'spaceToUnderscore'=>true)
'eval' => array('mandatory'=>true, 'maxlength'=>64, 'spaceToUnderscore'=>true)
)
)
);
Expand Down
Loading