Merge branch 'master' into loops

Conflicts:
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Loop/FeatureValue.php
	core/lib/Thelia/Core/Template/Loop/Folder.php
	core/lib/Thelia/Core/Template/Loop/Product.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	install/faker.php
This commit is contained in:
Etienne Roudeix
2013-08-21 09:19:56 +02:00
3275 changed files with 929970 additions and 274940 deletions

4
.gitignore vendored
View File

@@ -15,6 +15,10 @@ coverage
.project
.settings/
local/cache/*
local/media/documents/*
local/media/images/*
web/assets/*
web/cache/*
web/.htaccess
phpdoc*.log
php-cs

View File

@@ -11,7 +11,7 @@
"php": ">=5.4",
"ezyang/htmlpurifier": "dev-master",
"ircmaxell/password-compat": "dev-master",
"propel/propel": "dev-master",
"propel/propel": "2.0.0-alpha1",
"psr/log" : "1.0",
"symfony/class-loader": "2.2.*",
"symfony/config" : "2.2.*",
@@ -27,14 +27,16 @@
"symfony-cmf/routing": "1.0.0",
"symfony/form": "2.2.*",
"symfony/validator": "2.3.*",
"symfony/validator": "2.3.*@dev",
"smarty/smarty": "v3.1.14",
"kriswallsmith/assetic": "1.2.*@dev",
"leafo/lessphp": "0.3.*@dev",
"ptachoire/cssembed": "dev-master",
"simplepie/simplepie": "dev-master"
"simplepie/simplepie": "dev-master",
"imagine/imagine": "dev-master"
},
"require-dev" : {
"phpunit/phpunit": "3.7.*",

320
composer.lock generated
View File

@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "b20fbb4995fbf676a7028034f21cfbe0",
"hash": "458aeccc06b7394d7653a9063b6fd981",
"packages": [
{
"name": "ezyang/htmlpurifier",
@@ -49,6 +49,58 @@
],
"time": "2013-07-27 04:54:53"
},
{
"name": "imagine/imagine",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/avalanche123/Imagine.git",
"reference": "v0.5.0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/avalanche123/Imagine/zipball/v0.5.0",
"reference": "v0.5.0",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"sami/sami": "dev-master"
},
"suggest": {
"ext-gd": "to use the GD implementation",
"ext-gmagick": "to use the Gmagick implementation",
"ext-imagick": "to use the Imagick implementation"
},
"type": "library",
"autoload": {
"psr-0": {
"Imagine": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bulat Shakirzyanov",
"email": "mallluhuct@gmail.com",
"homepage": "http://avalanche123.com"
}
],
"description": "Image processing for PHP 5.3",
"homepage": "http://imagine.readthedocs.org/",
"keywords": [
"drawing",
"graphics",
"image manipulation",
"image processing"
],
"time": "2013-07-10 17:25:36"
},
{
"name": "ircmaxell/password-compat",
"version": "dev-master",
@@ -165,12 +217,12 @@
"source": {
"type": "git",
"url": "https://github.com/leafo/lessphp.git",
"reference": "366fb52798d4f120503af0703da11cba4ad06f8d"
"reference": "v0.4.0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/leafo/lessphp/zipball/366fb52798d4f120503af0703da11cba4ad06f8d",
"reference": "366fb52798d4f120503af0703da11cba4ad06f8d",
"url": "https://api.github.com/repos/leafo/lessphp/zipball/v0.4.0",
"reference": "v0.4.0",
"shasum": ""
},
"type": "library",
@@ -198,34 +250,34 @@
],
"description": "lessphp is a compiler for LESS written in PHP.",
"homepage": "http://leafo.net/lessphp/",
"time": "2013-07-09 16:25:09"
"time": "2013-08-09 17:09:19"
},
{
"name": "propel/propel",
"version": "dev-master",
"version": "2.0.0-alpha1",
"source": {
"type": "git",
"url": "https://github.com/propelorm/Propel2.git",
"reference": "4cf5fca150ed93b33dc54206e3d9d943d0712621"
"reference": "2.0.0-alpha1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/4cf5fca150ed93b33dc54206e3d9d943d0712621",
"reference": "4cf5fca150ed93b33dc54206e3d9d943d0712621",
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/2.0.0-alpha1",
"reference": "2.0.0-alpha1",
"shasum": ""
},
"require": {
"php": ">=5.4",
"psr/log": "~1.0",
"symfony/console": "~2.2",
"symfony/filesystem": "~2.2",
"symfony/finder": "~2.2",
"symfony/validator": "~2.2",
"symfony/yaml": "~2.2"
"psr/log": ">=1.0,<2.0",
"symfony/console": ">=2.2,<3.0",
"symfony/filesystem": ">=2.2,<3.0",
"symfony/finder": ">=2.2,<3.0",
"symfony/validator": ">=2.2,<3.0",
"symfony/yaml": ">=2.2,<3.0"
},
"require-dev": {
"behat/behat": "~2.4",
"monolog/monolog": "~1.3",
"behat/behat": ">=2.4,<3.0",
"monolog/monolog": ">=1.3,<2.0",
"phpunit/phpunit": "3.7.*"
},
"suggest": {
@@ -258,7 +310,7 @@
"orm",
"persistence"
],
"time": "2013-07-10 11:32:06"
"time": "2013-06-05 06:46:14"
},
{
"name": "psr/log",
@@ -488,17 +540,17 @@
},
{
"name": "symfony/class-loader",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/ClassLoader",
"source": {
"type": "git",
"url": "https://github.com/symfony/ClassLoader.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/ClassLoader/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/ClassLoader/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -538,17 +590,17 @@
},
{
"name": "symfony/config",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Config",
"source": {
"type": "git",
"url": "https://github.com/symfony/Config.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Config/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Config/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -581,21 +633,21 @@
],
"description": "Symfony Config Component",
"homepage": "http://symfony.com",
"time": "2013-07-10 14:03:01"
"time": "2013-08-06 02:31:28"
},
{
"name": "symfony/console",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Console",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Console/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -632,17 +684,17 @@
},
{
"name": "symfony/dependency-injection",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/DependencyInjection",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -683,21 +735,21 @@
],
"description": "Symfony DependencyInjection Component",
"homepage": "http://symfony.com",
"time": "2013-05-06 08:37:50"
"time": "2013-07-21 09:38:59"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -741,17 +793,17 @@
},
{
"name": "symfony/filesystem",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Filesystem",
"source": {
"type": "git",
"url": "https://github.com/symfony/Filesystem.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Filesystem/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Filesystem/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -788,17 +840,17 @@
},
{
"name": "symfony/finder",
"version": "v2.3.2",
"version": "v2.3.3",
"target-dir": "Symfony/Component/Finder",
"source": {
"type": "git",
"url": "https://github.com/symfony/Finder.git",
"reference": "v2.3.2"
"reference": "v2.3.3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Finder/zipball/v2.3.2",
"reference": "v2.3.2",
"url": "https://api.github.com/repos/symfony/Finder/zipball/v2.3.3",
"reference": "v2.3.3",
"shasum": ""
},
"require": {
@@ -831,21 +883,21 @@
],
"description": "Symfony Finder Component",
"homepage": "http://symfony.com",
"time": "2013-07-01 12:17:23"
"time": "2013-07-21 12:12:18"
},
{
"name": "symfony/form",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Form",
"source": {
"type": "git",
"url": "https://github.com/symfony/Form.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Form/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Form/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -890,21 +942,21 @@
],
"description": "Symfony Form Component",
"homepage": "http://symfony.com",
"time": "2013-06-23 07:35:41"
"time": "2013-08-02 13:12:51"
},
{
"name": "symfony/http-foundation",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/HttpFoundation",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpFoundation.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -940,21 +992,21 @@
],
"description": "Symfony HttpFoundation Component",
"homepage": "http://symfony.com",
"time": "2013-07-15 12:12:07"
"time": "2013-08-07 14:00:53"
},
{
"name": "symfony/http-kernel",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/HttpKernel",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpKernel.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/HttpKernel/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/HttpKernel/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -972,7 +1024,8 @@
"symfony/finder": "~2.0",
"symfony/process": "~2.0",
"symfony/routing": ">=2.2,<2.3-dev",
"symfony/stopwatch": ">=2.2,<2.3-dev"
"symfony/stopwatch": ">=2.2,<2.3-dev",
"symfony/templating": "~2.2"
},
"suggest": {
"symfony/browser-kit": "2.2.*",
@@ -1009,7 +1062,7 @@
],
"description": "Symfony HttpKernel Component",
"homepage": "http://symfony.com",
"time": "2013-07-15 12:28:01"
"time": "2013-08-07 15:57:43"
},
{
"name": "symfony/icu",
@@ -1061,17 +1114,17 @@
},
{
"name": "symfony/intl",
"version": "v2.3.2",
"version": "v2.3.3",
"target-dir": "Symfony/Component/Intl",
"source": {
"type": "git",
"url": "https://github.com/symfony/Intl.git",
"reference": "v2.3.2"
"reference": "v2.3.3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Intl/zipball/v2.3.2",
"reference": "v2.3.2",
"url": "https://api.github.com/repos/symfony/Intl/zipball/v2.3.3",
"reference": "v2.3.3",
"shasum": ""
},
"require": {
@@ -1134,21 +1187,21 @@
"l10n",
"localization"
],
"time": "2013-07-08 13:00:35"
"time": "2013-08-01 12:40:45"
},
{
"name": "symfony/locale",
"version": "v2.3.2",
"version": "v2.3.3",
"target-dir": "Symfony/Component/Locale",
"source": {
"type": "git",
"url": "https://github.com/symfony/Locale.git",
"reference": "v2.3.2"
"reference": "v2.3.3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Locale/zipball/v2.3.2",
"reference": "v2.3.2",
"url": "https://api.github.com/repos/symfony/Locale/zipball/v2.3.3",
"reference": "v2.3.3",
"shasum": ""
},
"require": {
@@ -1186,17 +1239,17 @@
},
{
"name": "symfony/options-resolver",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/OptionsResolver",
"source": {
"type": "git",
"url": "https://github.com/symfony/OptionsResolver.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/OptionsResolver/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/OptionsResolver/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -1238,17 +1291,17 @@
},
{
"name": "symfony/process",
"version": "v2.3.2",
"version": "v2.3.3",
"target-dir": "Symfony/Component/Process",
"source": {
"type": "git",
"url": "https://github.com/symfony/Process.git",
"reference": "v2.3.2"
"reference": "v2.3.3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Process/zipball/v2.3.2",
"reference": "v2.3.2",
"url": "https://api.github.com/repos/symfony/Process/zipball/v2.3.3",
"reference": "v2.3.3",
"shasum": ""
},
"require": {
@@ -1281,21 +1334,21 @@
],
"description": "Symfony Process Component",
"homepage": "http://symfony.com",
"time": "2013-07-01 12:24:43"
"time": "2013-08-02 21:51:01"
},
{
"name": "symfony/property-access",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/PropertyAccess",
"source": {
"type": "git",
"url": "https://github.com/symfony/PropertyAccess.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/PropertyAccess/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/PropertyAccess/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -1339,21 +1392,21 @@
"property path",
"reflection"
],
"time": "2013-04-07 22:02:49"
"time": "2013-07-28 18:26:16"
},
{
"name": "symfony/routing",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Routing",
"source": {
"type": "git",
"url": "https://github.com/symfony/Routing.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Routing/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Routing/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -1397,21 +1450,21 @@
],
"description": "Symfony Routing Component",
"homepage": "http://symfony.com",
"time": "2013-06-23 06:56:04"
"time": "2013-07-30 11:22:46"
},
{
"name": "symfony/translation",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Translation",
"source": {
"type": "git",
"url": "https://github.com/symfony/Translation.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Translation/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Translation/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -1452,21 +1505,21 @@
],
"description": "Symfony Translation Component",
"homepage": "http://symfony.com",
"time": "2013-05-10 16:49:00"
"time": "2013-07-28 18:26:16"
},
{
"name": "symfony/validator",
"version": "v2.3.2",
"version": "2.3.x-dev",
"target-dir": "Symfony/Component/Validator",
"source": {
"type": "git",
"url": "https://github.com/symfony/Validator.git",
"reference": "v2.3.2"
"reference": "55808a75bf373a8edb6400239268d315f0a326c7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Validator/zipball/v2.3.2",
"reference": "v2.3.2",
"url": "https://api.github.com/repos/symfony/Validator/zipball/55808a75bf373a8edb6400239268d315f0a326c7",
"reference": "55808a75bf373a8edb6400239268d315f0a326c7",
"shasum": ""
},
"require": {
@@ -1513,21 +1566,21 @@
],
"description": "Symfony Validator Component",
"homepage": "http://symfony.com",
"time": "2013-07-08 13:36:15"
"time": "2013-08-13 20:18:00"
},
{
"name": "symfony/yaml",
"version": "v2.2.4",
"version": "v2.2.5",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "v2.2.4"
"reference": "v2.2.5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.2.4",
"reference": "v2.2.4",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.2.5",
"reference": "v2.2.5",
"shasum": ""
},
"require": {
@@ -1570,12 +1623,12 @@
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "3613b1466d5e9518b83f87d828f93f962ff0f997"
"reference": "feb6492762a77db946bc13cc44a20a01546be0e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/3613b1466d5e9518b83f87d828f93f962ff0f997",
"reference": "3613b1466d5e9518b83f87d828f93f962ff0f997",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/feb6492762a77db946bc13cc44a20a01546be0e6",
"reference": "feb6492762a77db946bc13cc44a20a01546be0e6",
"shasum": ""
},
"require": {
@@ -1608,7 +1661,7 @@
"faker",
"fixtures"
],
"time": "2013-07-15 16:26:12"
"time": "2013-08-12 10:05:47"
},
{
"name": "phpunit/php-code-coverage",
@@ -1762,16 +1815,16 @@
},
{
"name": "phpunit/php-timer",
"version": "1.0.4",
"version": "1.0.5",
"source": {
"type": "git",
"url": "git://github.com/sebastianbergmann/php-timer.git",
"reference": "1.0.4"
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "1.0.5"
},
"dist": {
"type": "zip",
"url": "https://github.com/sebastianbergmann/php-timer/zipball/1.0.4",
"reference": "1.0.4",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1.0.5",
"reference": "1.0.5",
"shasum": ""
},
"require": {
@@ -1798,24 +1851,24 @@
}
],
"description": "Utility class for timing",
"homepage": "http://www.phpunit.de/",
"homepage": "https://github.com/sebastianbergmann/php-timer/",
"keywords": [
"timer"
],
"time": "2012-10-11 04:45:58"
"time": "2013-08-02 07:42:54"
},
{
"name": "phpunit/php-token-stream",
"version": "1.1.7",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "1.1.7"
"reference": "1.2.0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1.1.7",
"reference": "1.1.7",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1.2.0",
"reference": "1.2.0",
"shasum": ""
},
"require": {
@@ -1823,6 +1876,11 @@
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"autoload": {
"classmap": [
"PHP/"
@@ -1847,20 +1905,20 @@
"keywords": [
"tokenizer"
],
"time": "2013-07-29 14:27:06"
"time": "2013-08-04 05:57:48"
},
{
"name": "phpunit/phpunit",
"version": "3.7.22",
"version": "3.7.24",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "3.7.22"
"reference": "3.7.24"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.22",
"reference": "3.7.22",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.24",
"reference": "3.7.24",
"shasum": ""
},
"require": {
@@ -1872,7 +1930,7 @@
"phpunit/php-code-coverage": "~1.2.1",
"phpunit/php-file-iterator": ">=1.3.1",
"phpunit/php-text-template": ">=1.1.1",
"phpunit/php-timer": "~1.0.2",
"phpunit/php-timer": ">=1.0.4",
"phpunit/phpunit-mock-objects": "~1.2.0",
"symfony/yaml": "~2.0"
},
@@ -1921,7 +1979,7 @@
"testing",
"xunit"
],
"time": "2013-07-06 06:29:15"
"time": "2013-08-09 06:58:24"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -1980,11 +2038,13 @@
"stability-flags": {
"ezyang/htmlpurifier": 20,
"ircmaxell/password-compat": 20,
"propel/propel": 20,
"propel/propel": 15,
"symfony/validator": 20,
"kriswallsmith/assetic": 20,
"leafo/lessphp": 20,
"ptachoire/cssembed": 20,
"simplepie/simplepie": 20,
"imagine/imagine": 20,
"fzaninotto/faker": 20
},
"platform": {

18
core/lib/Thelia/Action/BaseAction.php Normal file → Executable file
View File

@@ -22,24 +22,21 @@
/*************************************************************************************/
namespace Thelia\Action;
use Thelia\Form\BaseForm;
use Thelia\Action\Exception\FormValidationException;
use Thelia\Core\Event\ActionEvent;
use Symfony\Component\Form\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BaseAction
{
/**
* @var The container
*/
protected $container;
public function __construct(ContainerInterface $container) {
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
@@ -60,14 +57,11 @@ class BaseAction
$form->bind($aBaseForm->getRequest());
if ($form->isValid()) {
return $form;
}
else {
} else {
throw new FormValidationException("Missing or invalid data");
}
}
else {
} else {
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
}
}
@@ -79,8 +73,8 @@ class BaseAction
* @param string $error_message an error message that may be displayed to the customer
* @param ActionEvent $event the action event
*/
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event) {
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event)
{
// The form has an error
$aBaseForm->setError(true);
$aBaseForm->setErrorMessage($error_message);

View File

@@ -25,10 +25,8 @@ namespace Thelia\Action;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CartEvent;
use Thelia\Form\CartAdd;
use Thelia\Model\ProductPrice;
@@ -36,7 +34,6 @@ use Thelia\Model\ProductPriceQuery;
use Thelia\Model\CartItem;
use Thelia\Model\CartItemQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Action\Exception\FormValidationException;
/**
*
@@ -52,53 +49,31 @@ class Cart extends BaseAction implements EventSubscriberInterface
* add an article in the current cart
* @param \Thelia\Core\Event\CartEvent $event
*/
public function addArticle(CartEvent $event)
public function addItem(CartEvent $event)
{
$request = $event->getRequest();
$message = null;
try {
$cartAdd = $this->getAddCartForm($request);
$form = $this->validateForm($cartAdd);
$cart = $event->getCart();
$newness = $form->get("newness")->getData();
$append = $form->get("append")->getData();
$quantity = $form->get("quantity")->getData();
$newness = $event->getNewness();
$append = $event->getAppend();
$quantity = $event->getQuantity();
$productSaleElementsId = $form->get("product_sale_elements_id")->getData();
$productId = $form->get("product")->getData();
$productSaleElementsId = $event->getProductSaleElementsId();
$productId = $event->getProduct();
$cartItem = $this->findItem($cart->getId(), $productId, $productSaleElementsId);
if ($cartItem === null || $newness) {
$productPrice = ProductPriceQuery::create()
->filterByProductSaleElementsId($productSaleElementsId)
->findOne()
;
->findOne();
$this->addItem($cart, $productId, $productSaleElementsId, $quantity, $productPrice);
$this->doAddItem($cart, $productId, $productSaleElementsId, $quantity, $productPrice);
}
if ($append && $cartItem !== null) {
$this->updateQuantity($cartItem, $quantity);
}
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
$message = "Failed to add this article to your cart, please try again";
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
if($message) {
// The form has errors, propagate it.
$this->propagateFormError($cartAdd, $message, $event);
}
}
/**
*
@@ -106,20 +81,14 @@ class Cart extends BaseAction implements EventSubscriberInterface
*
* @param \Thelia\Core\Event\CartEvent $event
*/
public function deleteArticle(CartEvent $event)
public function deleteItem(CartEvent $event)
{
$request = $event->getRequest();
if (null !== $cartItemId = $request->get('cartItem')) {
if (null !== $cartItemId = $event->getCartItem()) {
$cart = $event->getCart();
try {
$cartItem = CartItemQuery::create()
->filterByCartId($cart->getId())
->filterById($cartItemId)
->delete();
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during deleting cartItem with message : %s", $e->getMessage()));
}
}
}
@@ -132,14 +101,10 @@ class Cart extends BaseAction implements EventSubscriberInterface
*
* @param \Thelia\Core\Event\CartEvent $event
*/
public function modifyArticle(CartEvent $event)
public function changeItem(CartEvent $event)
{
$request = $event->getRequest();
if (null !== $cartItemId = $request->get("cartItem") && null !== $quantity = $request->get("quantity")) {
try {
$cart = $event->getCart($request);
if ((null !== $cartItemId = $event->getCartItem()) && (null !== $quantity = $event->getQuantity())) {
$cart = $event->getCart();
$cartItem = CartItemQuery::create()
->filterByCartId($cart->getId())
@@ -149,9 +114,6 @@ class Cart extends BaseAction implements EventSubscriberInterface
if ($cartItem) {
$this->updateQuantity($cartItem, $quantity);
}
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during updating cartItem with message : %s", $e->getMessage()));
}
}
}
@@ -178,14 +140,12 @@ class Cart extends BaseAction implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
"action.addArticle" => array("addArticle", 128),
"action.deleteArticle" => array("deleteArticle", 128),
"action.changeArticle" => array("modifyArticle", 128),
"action.addArticle" => array("addItem", 128),
"action.deleteArticle" => array("deleteItem", 128),
"action.changeArticle" => array("changeItem", 128),
);
}
/**
* increase the quantity for an existing cartItem
*
@@ -195,7 +155,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
protected function updateQuantity(CartItem $cartItem, $quantity)
{
$cartItem->setDisptacher($this->getDispatcher());
$cartItem->addQuantity($quantity)
$cartItem->updateQuantity($quantity)
->save();
}
@@ -208,7 +168,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
* @param float $quantity
* @param ProductPrice $productPrice
*/
protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
protected function doAddItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
{
$cartItem = new CartItem();
$cartItem->setDisptacher($this->getDispatcher());
@@ -241,28 +201,4 @@ class Cart extends BaseAction implements EventSubscriberInterface
->findOne();
}
/**
* Find the good way to construct the cart form
*
* @param Request $request
* @return CartAdd
*/
private function getAddCartForm(Request $request)
{
if ($request->isMethod("post")) {
$cartAdd = new CartAdd($request);
} else {
$cartAdd = new CartAdd(
$request,
"form",
array(),
array(
'csrf_protection' => false,
)
);
}
return $cartAdd;
}
}

32
core/lib/Thelia/Action/Category.php Normal file → Executable file
View File

@@ -40,7 +40,6 @@ use Propel\Runtime\Propel;
use Thelia\Model\Map\CategoryTableMap;
use Propel\Runtime\Exception\PropelException;
class Category extends BaseAction implements EventSubscriberInterface
{
public function create(ActionEvent $event)
@@ -237,7 +236,8 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @param ActionEvent $event
*/
public function changePositionUp(ActionEvent $event) {
public function changePositionUp(ActionEvent $event)
{
return $this->exchangePosition($event, 'up');
}
@@ -246,7 +246,8 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @param ActionEvent $event
*/
public function changePositionDown(ActionEvent $event) {
public function changePositionDown(ActionEvent $event)
{
return $this->exchangePosition($event, 'down');
}
@@ -256,8 +257,8 @@ class Category extends BaseAction implements EventSubscriberInterface
* @param ActionEvent $event
* @param string $direction up to move up, down to move down
*/
protected function exchangePosition(ActionEvent $event, $direction) {
protected function exchangePosition(ActionEvent $event, $direction)
{
$this->checkAuth("ADMIN", "admin.category.edit");
$request = $event->getRequest();
@@ -277,17 +278,15 @@ class Category extends BaseAction implements EventSubscriberInterface
if ($direction == 'up') {
// Find the category immediately before me
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
}
else if ($direction == 'down') {
} elseif ($direction == 'down') {
// Find the category immediately after me
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
}
else
} else
return;
$result = $search->findOne();
// If we found the proper category, exchange their positions
if ($result) {
@@ -301,8 +300,7 @@ class Category extends BaseAction implements EventSubscriberInterface
$result->setPosition($my_position)->save();
$cnx->commit();
}
catch(Exception $e) {
} catch (Exception $e) {
$cnx->rollback();
}
}
@@ -314,8 +312,8 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @param ActionEvent $event
*/
public function changePosition(ActionEvent $event) {
public function changePosition(ActionEvent $event)
{
$this->checkAuth("ADMIN", "admin.category.edit");
$request = $event->getRequest();
@@ -340,8 +338,7 @@ class Category extends BaseAction implements EventSubscriberInterface
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position));
$delta = -1;
}
else {
} else {
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
$search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1));
@@ -362,8 +359,7 @@ class Category extends BaseAction implements EventSubscriberInterface
$category->setPosition($new_position)->save($cnx);
$cnx->commit();
}
catch(Exception $e) {
} catch (Exception $e) {
$cnx->rollback();
}
}

View File

@@ -25,8 +25,8 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\BaseForm;
use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerModification;
use Thelia\Model\Customer as CustomerModel;
@@ -34,105 +34,57 @@ use Thelia\Log\Tlog;
use Thelia\Model\CustomerQuery;
use Thelia\Form\CustomerLogin;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\SecurityContext;
use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Propel\Runtime\Exception\PropelException;
use Thelia\Action\Exception\FormValidationException;
class Customer extends BaseAction implements EventSubscriberInterface
{
public function create(ActionEvent $event)
public function create(CustomerCreateOrUpdateEvent $event)
{
$request = $event->getRequest();
try {
$customerCreationForm = new CustomerCreation($request);
$form = $this->validateForm($customerCreationForm, "POST");
$data = $form->getData();
$customer = new CustomerModel();
$customer->setDispatcher($event->getDispatcher());
$customer->setDispatcher($this->getDispatcher());
$customer->createOrUpdate(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["country"],
$data["email"],
$data["password"],
$request->getSession()->getLang()
);
$this->createOrUpdateCustomer($customer, $event);
$event->customer = $customer;
} catch (PropelException $e) {
Tlog::getInstance()->error(sprintf('error during creating customer on action/createCustomer with message "%s"', $e->getMessage()));
$message = "Failed to create your account, please try again.";
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// The form has errors, propagate it.
$this->propagateFormError($customerCreationForm, $message, $event);
}
public function modify(ActionEvent $event)
public function modify(CustomerCreateOrUpdateEvent $event)
{
$request = $event->getRequest();
try {
$customerModification = new CustomerModification($request);
$customer = $event->getCustomer();
$customer->setDispatcher($this->getDispatcher());
$form = $this->validateForm($customerModification, "POST");
$this->createOrUpdateCustomer($customer, $event);
$data = $form->getData();
$customer = CustomerQuery::create()->findPk(1);
$data = $form->getData();
$customer->createOrUpdate(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["country"]
);
// Update the logged-in user, and redirect to the success URL (exits)
// We don-t send the login event, as the customer si already logged.
$this->processSuccessfullLogin($event, $customer, $customerModification);
} catch (PropelException $e) {
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
$message = "Failed to change your account, please try again.";
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// The form has errors, propagate it.
$this->propagateFormError($customerModification, $message, $event);
private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event)
{
$customer->createOrUpdate(
$event->getTitle(),
$event->getFirstname(),
$event->getLastname(),
$event->getAddress1(),
$event->getAddress2(),
$event->getAddress3(),
$event->getPhone(),
$event->getCellphone(),
$event->getZipcode(),
$event->getCity(),
$event->getCountry(),
$event->getEmail(),
$event->getPassword(),
$event->getLang(),
$event->getReseller(),
$event->getSponsor(),
$event->getDiscount()
);
$event->setCustomer($customer);
}
/**
@@ -144,51 +96,9 @@ class Customer extends BaseAction implements EventSubscriberInterface
{
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
$this->getFrontSecurityContext()->clear();
}
/**
* Perform user login. On a successful login, the user is redirected to the URL
* found in the success_url form parameter, or / if none was found.
*
* If login is not successfull, the same view is dispolyed again.
*
* @param ActionEvent $event
*/
public function login(ActionEvent $event)
{
$request = $event->getRequest();
$customerLoginForm = new CustomerLogin($request);
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
try {
$user = $authenticator->getAuthentifiedUser();
$event->customer = $customer;
} catch (ValidatorException $ex) {
$message = "Missing or invalid information. Please check your input.";
} catch (UsernameNotFoundException $ex) {
$message = "This email address was not found.";
} catch (AuthenticationException $ex) {
$message = "Login failed. Please check your username and password.";
} catch (\Exception $ex) {
$message = sprintf("Unable to process your request. Please try again (%s in %s).", $ex->getMessage(), $ex->getFile());
}
// The for has an error
$customerLoginForm->setError(true);
$customerLoginForm->setErrorMessage($message);
// Dispatch the errored form
$event->setErrorForm($customerLoginForm);
// A this point, the same view is displayed again.
}
public function changePassword(ActionEvent $event)
{
// TODO
@@ -219,8 +129,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
return array(
"action.createCustomer" => array("create", 128),
"action.modifyCustomer" => array("modify", 128),
"action.loginCustomer" => array("login", 128),
"action.logoutCustomer" => array("logout", 128),
);
}
}

497
core/lib/Thelia/Action/Image.php Executable file
View File

@@ -0,0 +1,497 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\ImageEvent;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
use Imagine\Image\ImagineInterface;
use Imagine\Image\ImageInterface;
use Imagine\Image\Box;
use Imagine\Image\Color;
use Imagine\Image\Point;
use Thelia\Exception\ImageException;
use Thelia\Core\Event\TheliaEvents;
/**
*
* Image management actions. This class handles image processing an caching.
*
* Basically, images are stored outside the web space (by default in local/media/images),
* and cached in the web space (by default in web/local/images).
*
* In the images caches directory, a subdirectory for images categories (eg. product, category, folder, etc.) is
* automatically created, and the cached image is created here. Plugin may use their own subdirectory as required.
*
* The cached image name contains a hash of the processing options, and the original (normalized) name of the image.
*
* A copy (or symbolic link, by default) of the original image is always created in the cache, so that the full
* resolution image is always available.
*
* Various image processing options are available :
*
* - resizing, with border, crop, or by keeping image aspect ratio
* - rotation, in degrees, positive or negative
* - background color, applyed to empty background when creating borders or rotating
* - effects. The effects are applied in the specified order. The following effects are available:
* - gamma:value : change the image Gamma to the specified value. Example: gamma:0.7
* - grayscale or greyscale: switch image to grayscale
* - colorize:color : apply a color mask to the image. Exemple: colorize:#ff2244
* - negative : transform the image in its negative equivalent
* - vflip or vertical_flip : vertical flip
* - hflip or horizontal_flip : horizontal flip
*
* If a problem occurs, an ImageException may be thrown.
*
* @package Thelia\Action
* @author Franck Allimant <franck@cqfdev.fr>
*
*/
class Image extends BaseAction implements EventSubscriberInterface
{
// Resize mode constants
const EXACT_RATIO_WITH_BORDERS = 1;
const EXACT_RATIO_WITH_CROP = 2;
const KEEP_IMAGE_RATIO = 3;
/**
* Clear the image cache. Is a subdirectory is specified, only this directory is cleared.
* If no directory is specified, the whole cache is cleared.
* Only files are deleted, directories will remain.
*
* @param ImageEvent $event
*/
public function clearCache(ImageEvent $event) {
$path = $this->getCachePath($event->getCacheSubdirectory(), false);
$this->clearDirectory($path);
}
/**
* Recursively clears the specified directory.
*
* @param string $path the directory path
*/
protected function clearDirectory($path) {
$iterator = new \DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isDot()) continue;
if ($fileinfo->isFile() || $fileinfo->isLink()) {
@unlink($fileinfo->getPathname());
}
else if ($fileinfo->isDir()) {
$this->clearDirectory($fileinfo->getPathname());
}
}
}
/**
* Process image and write the result in the image cache.
*
* If the image already exists in cache, the cache file is immediately returned, without any processing
* If the original (full resolution) image is required, create either a symbolic link with the
* original image in the cache dir, or copy it in the cache dir.
*
* This method updates the cache_file_path and file_url attributes of the event
*
* @param ImageEvent $event
* @throws \InvalidArgumentException, ImageException
*/
public function processImage(ImageEvent $event)
{
$subdir = $event->getCacheSubdirectory();
$source_file = $event->getSourceFilepath();
if (null == $subdir || null == $source_file) {
throw new \InvalidArgumentException("Cache sub-directory and source file path cannot be null");
}
// echo basename($source_file).": ";
// Find cached file path
$cacheFilePath = $this->getCacheFilePath($subdir, $source_file, $event);
$originalImagePathInCache = $this->getCacheFilePath($subdir, $source_file, $event, true);
if (! file_exists($cacheFilePath)) {
if (! file_exists($source_file)) {
throw new ImageException(sprintf("Source image file %s does not exists.", $source_file));
}
// Create a chached version of the original image in the web space, if not exists
if (! file_exists($originalImagePathInCache)) {
$mode = ConfigQuery::read('original_image_delivery_mode', 'symlink');
if ($mode == 'symlink') {
if (false == symlink($source_file, $originalImagePathInCache)) {
throw new ImageException(sprintf("Failed to create symbolic link for %s in %s image cache directory", basename($source_file), $subdir));
}
}
else {// mode = 'copy'
if (false == @copy($source_file, $originalImagePathInCache)) {
throw new ImageException(sprintf("Failed to copy %s in %s image cache directory", basename($source_file), $subdir));
}
}
}
// Process image only if we have some transformations to do.
if (! $event->isOriginalImage()) {
// We have to process the image.
$imagine = $this->createImagineInstance();
$image = $imagine->open($source_file);
if ($image) {
$background_color = $event->getBackgroundColor();
if ($background_color != null) {
$bg_color = new Color($background_color);
}
else
$bg_color = null;
// Apply resize
$image = $this->applyResize($imagine, $image, $event->getWidth(), $event->getHeight(), $event->getResizeMode(), $bg_color);
// Rotate if required
$rotation = intval($event->getRotation());
if ($rotation != 0)
$image->rotate($rotation, $bg_color);
// Flip
// Process each effects
foreach ($event->getEffects() as $effect) {
$effect = trim(strtolower($effect));
$params = explode(':', $effect);
switch ($params[0]) {
case 'greyscale':
case 'grayscale':
$image->effects()->grayscale();
break;
case 'negative':
$image->effects()->negative();
break;
case 'horizontal_flip':
case 'hflip':
$image->flipHorizontally();
break;
case 'vertical_flip':
case 'vflip':
$image-> flipVertically();
break;
case 'gamma':
// Syntax: gamma:value. Exemple: gamma:0.7
if (isset($params[1])) {
$gamma = floatval($params[1]);
$image->effects()->gamma($gamma);
}
break;
case 'colorize':
// Syntax: colorize:couleur. Exemple: colorize:#ff00cc
if (isset($params[1])) {
$the_color = new Color($params[1]);
$image->effects()->colorize($the_color);
}
break;
}
}
$quality = $event->getQuality();
if (is_null($quality)) $quality = ConfigQuery::read('default_image_quality_percent', 75);
$image->save(
$cacheFilePath,
array('quality' => $quality)
);
}
else {
throw new ImageException(sprintf("Source file %s cannot be opened.", basename($source_file)));
}
}
}
// Compute the image URL
$processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath));
// compute the full resulution image path in cache
$original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache));
// Update the event with file path and file URL
$event->setCacheFilepath($cacheFilePath);
$event->setCacheOriginalFilepath($originalImagePathInCache);
$event->setFileUrl(URL::absoluteUrl($processed_image_url, null, URL::PATH_TO_FILE));
$event->setOriginalFileUrl(URL::absoluteUrl($original_image_url, null, URL::PATH_TO_FILE));
}
/**
* Process image resizing, with borders or cropping. If $dest_width and $dest_height
* are both null, no resize is performed.
*
* @param ImagineInterface $imagine the Imagine instance
* @param ImageInterface $image the image to process
* @param int $dest_width the required width
* @param int $dest_height the required height
* @param int $resize_mode the resize mode (crop / bands / keep image ratio)p
* @param string $bg_color the bg_color used for bands
* @return ImageInterface the resized image.
*/
protected function applyResize(ImagineInterface $imagine, ImageInterface $image, $dest_width, $dest_height, $resize_mode, $bg_color)
{
if (! (is_null($dest_width) && is_null($dest_height))) {
$width_orig = $image->getSize()->getWidth();
$height_orig = $image->getSize()->getHeight();
if (is_null($dest_width))
$dest_width = $width_orig;
if (is_null($dest_height))
$dest_height = $height_orig;
if (is_null($resize_mode))
$resize_mode = self::KEEP_IMAGE_RATIO;
$width_diff = $dest_width / $width_orig;
$height_diff = $dest_height / $height_orig;
$delta_x = $delta_y = $border_width = $border_height = 0;
if ($width_diff > 1 AND $height_diff > 1) {
$next_width = $width_orig;
$next_height = $height_orig;
$dest_width = ($resize_mode == self::EXACT_RATIO_WITH_BORDERS ? $dest_width : $next_width);
$dest_height = ($resize_mode == self::EXACT_RATIO_WITH_BORDERS ? $dest_height : $next_height);
}
else if ($width_diff > $height_diff) {
// Image height > image width
$next_height = $dest_height;
$next_width = intval(($width_orig * $next_height) / $height_orig);
if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
$next_width = $dest_width;
$next_height = intval($height_orig * $dest_width / $width_orig);
$delta_y = ($next_height - $dest_height) / 2;
}
else if ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
$dest_width = $next_width;
}
}
else {
// Image width > image height
$next_width = $dest_width;
$next_height = intval($height_orig * $dest_width / $width_orig);
if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
$next_height = $dest_height;
$next_width = intval(($width_orig * $next_height) / $height_orig);
$delta_x = ($next_width - $dest_width) / 2;
}
else if ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
$dest_height = $next_height;
}
}
$image->resize(new Box($next_width, $next_height));
// echo "w=$dest_width, h=$dest_height, nw=$next_width, nh=$next_height, dx=$delta_x, dy=$delta_y, bw=$border_width, bh=$border_height\n";
if ($resize_mode == self::EXACT_RATIO_WITH_BORDERS) {
$border_width = intval(($dest_width - $next_width) / 2);
$border_height = intval(($dest_height - $next_height) / 2);
$canvas = new Box($dest_width, $dest_height);
return $imagine->create($canvas, $bg_color)
->paste($image, new Point($border_width, $border_height));
}
else if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
$image->crop(
new Point($delta_x, $delta_y),
new Box($dest_width, $dest_height)
);
}
}
return $image;
}
/**
* Return the absolute URL to the cached image
*
* @param string $subdir the subdirectory related to cache base
* @param string $filename the safe filename, as returned by getCacheFilePath()
* @return string the absolute URL to the cached image
*/
protected function getCacheFileURL($subdir, $safe_filename)
{
$path = $this->getCachePathFromWebRoot($subdir);
return URL::absoluteUrl(sprintf("%s/%s", $path, $safe_filename), null, URL::PATH_TO_FILE);
}
/**
* Return the full path of the cached file
*
* @param string $subdir the subdirectory related to cache base
* @param string $filename the filename
* @param boolean $forceOriginalImage if true, the origiunal image path in the cache dir is returned.
* @return string the cache directory path relative to Web Root
*/
protected function getCacheFilePath($subdir, $filename, ImageEvent $event, $forceOriginalImage = false)
{
$path = $this->getCachePath($subdir);
$safe_filename = preg_replace("[^:alnum:\-\._]", "-", strtolower(basename($filename)));
// Keep original safe name if no tranformations are applied
if ($forceOriginalImage || $event->isOriginalImage())
return sprintf("%s/%s", $path, $safe_filename);
else
return sprintf("%s/%s-%s", $path, $event->getOptionsHash(), $safe_filename);
}
/**
* Return the cache directory path relative to Web Root
*
* @param string $subdir the subdirectory related to cache base, or null to get the cache directory only.
* @return string the cache directory path relative to Web Root
*/
protected function getCachePathFromWebRoot($subdir = null)
{
$cache_dir_from_web_root = ConfigQuery::read('image_cache_dir_from_web_root', 'cache');
if ($subdir != null) {
$safe_subdir = basename($subdir);
$path = sprintf("%s/%s", $cache_dir_from_web_root, $safe_subdir);
}
else
$path = $cache_dir_from_web_root;
// Check if path is valid, e.g. in the cache dir
return $path;
}
/**
* Return the absolute cache directory path
*
* @param string $subdir the subdirectory related to cache base, or null to get the cache base directory.
* @throws \RuntimeException if cache directory cannot be created
* @return string the absolute cache directory path
*/
protected function getCachePath($subdir = null, $create_if_not_exists = true)
{
$cache_base = $this->getCachePathFromWebRoot($subdir);
$web_root = rtrim(THELIA_WEB_DIR, '/');
$path = sprintf("%s/%s", $web_root, $cache_base);
// Create directory (recursively) if it does not exists.
if ($create_if_not_exists && !is_dir($path)) {
if (!@mkdir($path, 0777, true)) {
throw new ImageException(sprintf("Failed to create %s/%s image cache directory", $cache_base));
}
}
// Check if path is valid, e.g. in the cache dir
$cache_base = realpath(sprintf("%s/%s", $web_root, $this->getCachePathFromWebRoot()));
if (strpos(realpath($path), $cache_base) !== 0) {
throw new \InvalidArgumentException(sprintf("Invalid cache path %s, with subdirectory %s", $path, $subdir));
}
return $path;
}
/**
* Create a new Imagine object using current driver configuration
*
* @return \Imagine\ImagineInterface
*/
protected function createImagineInstance()
{
$driver = ConfigQuery::read("imagine_graphic_driver", "gd");
switch ($driver) {
case 'imagik':
$image = new \Imagine\Imagick\Imagine();
break;
case 'gmagick':
$image = new \Imagine\Gmagick\Imagine();
break;
case 'gd':
default:
$image = new \Imagine\Gd\Imagine();
}
return $image;
}
public static function getSubscribedEvents()
{
return array(
TheliaEvents::IMAGE_PROCESS => array("processImage", 128),
TheliaEvents::IMAGE_CLEAR_CACHE => array("clearCache", 128),
);
}
}

8
core/lib/Thelia/Cart/CartTrait.php Normal file → Executable file
View File

@@ -22,10 +22,6 @@
/*************************************************************************************/
namespace Thelia\Cart;
use Thelia\Model\ProductPrice;
use Thelia\Model\ProductPriceQuery;
use Thelia\Model\CartItem;
use Thelia\Model\CartItemQuery;
use Thelia\Model\CartQuery;
use Thelia\Model\Cart as CartModel;
use Thelia\Model\ConfigQuery;
@@ -35,7 +31,8 @@ use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Core\Event\Internal\CartEvent;
use Thelia\Core\Event\TheliaEvents;
trait CartTrait {
trait CartTrait
{
/**
*
* search if cart already exists in session. If not try to create a new one or duplicate an old one.
@@ -103,7 +100,6 @@ trait CartTrait {
return $cart;
}
/**
* try to duplicate existing Cart. Customer is here to determine if this cart belong to him.
*

9
core/lib/Thelia/Command/BaseModuleGenerate.php Normal file → Executable file
View File

@@ -22,12 +22,8 @@
/*************************************************************************************/
namespace Thelia\Command;
use Propel\Runtime\Propel;
use Symfony\Component\Console\Application;
abstract class BaseModuleGenerate extends ContainerAwareCommand {
abstract class BaseModuleGenerate extends ContainerAwareCommand
{
protected $module;
protected $moduleDirectory;
@@ -53,6 +49,7 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand {
if (in_array(strtolower($name), $this->reservedKeyWords)) {
throw new \RuntimeException(sprintf("%s module name is a reserved keyword", $name));
}
return ucfirst($name);
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

View File

@@ -0,0 +1,70 @@
<?php
use Thelia\Core\Event\TheliaEvents;
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Command;
use Thelia\Command\ContainerAwareCommand;
use Thelia\Core\Event\TheliaEvents;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Thelia\Core\Event\ImageEvent;
use Thelia\Core\HttpFoundation\Request;
use Symfony\Component\Console\Input\InputArgument;
class ClearImageCache extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName("image-cache:clear")
->setDescription("Empty part or whole web space image cache")
->addArgument("subdir", InputArgument::OPTIONAL, "Clear only the specified subdirectory")
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$dispatcher = $this->getContainer()->get('event_dispatcher');
$request = new Request();
try {
$event = new ImageEvent($request);
$subdir = $input->getArgument('subdir');
if (! is_null($subdir)) $event->setCacheSubdirectory($subdir);
$dispatcher->dispatch(TheliaEvents::IMAGE_CLEAR_CACHE, $event);
$output->writeln(sprintf('%s image cache successfully cleared.', is_null($subdir) ? 'Entire' : ucfirst($subdir)));
}
catch(\Exception $ex) {
$output->writeln(sprintf("Failed to clear image cache: %s", $ex->getMessage()));
}
}
}

View File

@@ -32,7 +32,8 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ContainerAwareCommand extends Command implements ContainerAwareInterface {
class ContainerAwareCommand extends Command implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*/

View File

@@ -29,7 +29,6 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Command\ContainerAwareCommand;
class Install extends ContainerAwareCommand
{
/**
@@ -80,7 +79,6 @@ class Install extends ContainerAwareCommand
$this->checkPermission($output);
$connectionInfo = array(
"host" => $input->getOption("db_host"),
"dbName" => $input->getOption("db_name"),
@@ -88,8 +86,6 @@ class Install extends ContainerAwareCommand
"password" => $input->getOption("db_password")
);
while (false === $connection = $this->tryConnection($connectionInfo, $output)) {
$connectionInfo = $this->getConnectionInfo($input, $output);
}
@@ -164,8 +160,6 @@ class Install extends ContainerAwareCommand
exit;
}
}
/**
@@ -180,7 +174,6 @@ class Install extends ContainerAwareCommand
$sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
$configFile = THELIA_ROOT . "/local/config/database.yml";
$fs->copy($sampleConfigFile, $configFile, true);
$configContent = file_get_contents($configFile);
@@ -196,11 +189,11 @@ class Install extends ContainerAwareCommand
file_put_contents($configFile, $configContent);
$fs->remove($sampleConfigFile);
// FA - no, as no further install will be possible
// $fs->remove($sampleConfigFile);
$fs->remove($this->getContainer()->getParameter("kernel.cache_dir"));
}
/**
@@ -288,11 +281,10 @@ class Install extends ContainerAwareCommand
$output->writeln(array(
"<error>Wrong connection information</error>"
));
return false;
}
return $connection;
}

9
core/lib/Thelia/Command/ModuleGenerateCommand.php Normal file → Executable file
View File

@@ -22,16 +22,13 @@
/*************************************************************************************/
namespace Thelia\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
class ModuleGenerateCommand extends BaseModuleGenerate {
class ModuleGenerateCommand extends BaseModuleGenerate
{
protected function configure()
{
$this
@@ -99,6 +96,4 @@ class ModuleGenerateCommand extends BaseModuleGenerate {
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
}
}

7
core/lib/Thelia/Command/ModuleGenerateModelCommand.php Normal file → Executable file
View File

@@ -23,18 +23,16 @@
namespace Thelia\Command;
use Propel\Generator\Command\ModelBuildCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Filesystem\Filesystem;
class ModuleGenerateModelCommand extends BaseModuleGenerate {
class ModuleGenerateModelCommand extends BaseModuleGenerate
{
protected function configure()
{
$this
@@ -124,7 +122,6 @@ class ModuleGenerateModelCommand extends BaseModuleGenerate {
}
}
}
}

6
core/lib/Thelia/Command/ModuleGenerateSqlCommand.php Normal file → Executable file
View File

@@ -23,17 +23,15 @@
namespace Thelia\Command;
use Propel\Generator\Command\SqlBuildCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Filesystem\Filesystem;
class ModuleGenerateSqlCommand extends BaseModuleGenerate {
class ModuleGenerateSqlCommand extends BaseModuleGenerate
{
public function configure()
{
$this

5
core/lib/Thelia/Command/Output/TheliaConsoleOutput.php Normal file → Executable file
View File

@@ -23,11 +23,10 @@
namespace Thelia\Command\Output;
use Symfony\Component\Console\Output\ConsoleOutput;
class TheliaConsoleOutput extends ConsoleOutput{
class TheliaConsoleOutput extends ConsoleOutput
{
public function renderBlock(array $messages, $style = "info")
{
$strlen = function ($string) {

3
core/lib/Thelia/Command/Skeleton/Module/Class.php Normal file → Executable file
View File

@@ -21,12 +21,11 @@
/* */
/*************************************************************************************/
namespace %%NAMESPACE%%;
use Thelia\Module\BaseModule;
class %%CLASSNAME%% extends BaseModule
class Class extends BaseModule
{
/**
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class

0
core/lib/Thelia/Command/Skeleton/Module/config.xml Normal file → Executable file
View File

0
core/lib/Thelia/Command/Skeleton/Module/plugin.xml Normal file → Executable file
View File

0
core/lib/Thelia/Command/Skeleton/Module/schema.xml Normal file → Executable file
View File

View File

@@ -26,9 +26,8 @@ namespace Thelia\Config;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class DefinePropel {
class DefinePropel
{
private $processorConfig;
public function __construct(ConfigurationInterface $configuration, array $propelConf)
@@ -40,6 +39,7 @@ class DefinePropel {
public function getConfig()
{
$connection = $this->processorConfig["connection"];
return $conf = array(
"dsn" => $connection["dsn"],
"user" => $connection["user"],

View File

@@ -27,6 +27,11 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.category" class="Thelia\Action\Image">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>

View File

@@ -28,6 +28,7 @@
<loop class="Thelia\Core\Template\Loop\Lang" name="lang"/>
<loop class="Thelia\Core\Template\Loop\CategoryTree" name="category-tree"/>
<loop class="Thelia\Core\Template\Loop\Cart" name="cart"/>
<loop class="Thelia\Core\Template\Loop\Image" name="image"/>
</loops>
<forms>
@@ -45,6 +46,7 @@
<commands>
<command class="Thelia\Command\ClearImageCache"/>
<command class="Thelia\Command\CacheClear"/>
<command class="Thelia\Command\Install"/>
<command class="Thelia\Command\ModuleGenerateCommand"/>

View File

@@ -10,6 +10,7 @@
<parameter key="router.dynamicRouter.class">Symfony\Cmf\Component\Routing\DynamicRouter</parameter>
<parameter key="router.chainRouter.class">Symfony\Cmf\Component\Routing\ChainRouter</parameter>
<parameter key="router.class">Symfony\Component\Routing\Router</parameter>
<parameter key="router.xmlFileName">routing.xml</parameter>
</parameters>
<services>
@@ -24,26 +25,24 @@
<argument type="service" id="thelia.parser"/>
</service>
<service id="matcher.default" class="Thelia\Routing\Matcher\DefaultMatcher">
<argument type="service" id="controller.default"/>
</service>
<service id="request.context" class="%router.request_context.class%" />
<service id="router.null_generator" class="%router.null_generator.class%"/>
<service id="router.default_route" class="%router.dynamicRouter.class%">
<argument type="service" id="request.context"/>
<argument type="service" id="matcher.default"/>
<argument type="service" id="router.null_generator"/>
</service>
<service id="router.admin.fileLocator" class="Symfony\Component\Config\FileLocator">
<service id="router.fileLocator" class="Symfony\Component\Config\FileLocator">
<argument>%thelia.core_dir%/Config/Resources/routing</argument>
</service>
<service id="router.xmlLoader" class="Symfony\Component\Routing\Loader\XmlFileLoader">
<argument type="service" id="router.admin.fileLocator"/>
<argument type="service" id="router.fileLocator"/>
</service>
<service id="router.module.fileLocator" class="Symfony\Component\Config\FileLocator">
<argument>%thelia.module_dir%</argument>
</service>
<service id="router.module.xmlLoader" class="Symfony\Component\Routing\Loader\XmlFileLoader">
<argument type="service" id="router.module.fileLocator"/>
</service>
<service id="router.admin" class="%router.class%">
@@ -54,6 +53,7 @@
<argument key="debug">%kernel.debug%</argument>
</argument>
<argument type="service" id="request.context"/>
<tag name="router.register" priority="0"/>
</service>
<service id="router.front" class="%router.class%">
@@ -64,25 +64,13 @@
<argument key="debug">%kernel.debug%</argument>
</argument>
<argument type="service" id="request.context"/>
<tag name="router.register" priority="255"/>
</service>
<service id="router.chainRequest" class="%router.chainRouter.class%">
<call method="setContext">
<argument type="service" id="request.context"/>
</call>
<call method="add">
<argument type="service" id="router.default_route"/>
<argument>-255</argument>
</call>
<call method="add">
<argument type="service" id="router.admin"/>
<argument>0</argument>
</call>
<call method="add">
<argument type="service" id="router.front"/>
<argument>255</argument>
</call>
</service>
<service id="listener.router" class="Symfony\Component\HttpKernel\EventListener\RouterListener">

29
core/lib/Thelia/Config/Resources/routing/front.xml Normal file → Executable file
View File

@@ -4,21 +4,36 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="home" path="/" >
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">index</default>
</route>
<route id="customer.create.process" path="/customer/create" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
<default key="_view">connexion</default>
</route>
<route id="customer.create" path="/customer/create" methods="get">
<default key="_controller">Thelia\Controller\Front\CustomerController::displayCreateAction</default>
<default key="_view">connexion</default>
<route id="customer.update.process" path="/customer/update" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::updateAction</default>
</route>
<route id="cart.add.process" path="/cart/add" methods="post">
<default key="_controller">Thelia\Controller\Front\CartController::addArticle</default>
<route id="customler.login.process" path="/customer/login" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
</route>
<route id="cart.change.process" path="/cart/change" methods="post">
<default key="_controller">Thelia\Controller\Front\CartController::addArticle</default>
<route id="cart.add.process" path="/cart/add">
<default key="_controller">Thelia\Controller\Front\CartController::addItem</default>
<default key="_view">cart</default>
</route>
<route id="cart.change.process" path="/cart/delete/{cart_item}">
<default key="_controller">Thelia\Controller\Front\CartController::deleteItem</default>
<default key="_view">cart</default>
</route>
<route id="cart.update.quantity" path="/cart/update">
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
<default key="_view">cart</default>
</route>
</routes>

View File

@@ -21,10 +21,10 @@
/* */
/*************************************************************************************/
namespace Thelia\Admin\Controller;
class AdminController extends BaseAdminController {
namespace Thelia\Controller\Admin;
class AdminController extends BaseAdminController
{
public function indexAction()
{
return $this->render("home");

141
core/lib/Thelia/Controller/Admin/BaseAdminController.php Normal file → Executable file
View File

@@ -20,11 +20,146 @@
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Admin\Controller;
namespace Thelia\Controller\Admin;
use Thelia\Controller\BaseController;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Core\Security\Exception\AuthorizationException;
use Thelia\Model\ConfigQuery;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Tools\URL;
use Thelia\Tools\Redirect;
class BaseAdminController extends BaseController {
class BaseAdminController extends BaseController
{
const TEMPLATE_404 = "404";
public function processTemplateAction($template)
{
try {
if (! empty($template)) {
// If we have a view in the URL, render this view
return $this->render($template);
} elseif (null != $view = $this->getRequest()->get('view')) {
return $this->render($view);
}
} catch (\Exception $ex) {
// Nothing special
}
return $this->pageNotFound();
}
/**
* Return a 404 error
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function pageNotFound()
{
return new Response($this->renderRaw(self::TEMPLATE_404), 404);
}
/**
* Return a general error page
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function errorPage($message)
{
return $this->render('general_error', array(
"error_message" => $message)
);
}
/**
* Check current admin user authorisations. An ADMIN role is assumed.
*
* @param unknown $permissions a single permission or an array of permissions.
*
* @throws AuthenticationException if permissions are not granted ti the current user.
*/
protected function checkAuth($permissions)
{
if (! $this->getSecurityContext()->isGranted(array("ADMIN"), is_array($permissions) ? $permissions : array($permissions))) {
throw new AuthorizationException("Sorry, you're not allowed to perform this action");
}
}
/**
* @return a ParserInterfac instance parser
*/
protected function getParser()
{
$parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used
$parser->setTemplate(ConfigQuery::read('base_admin_template', 'admin/default'));
return $parser;
}
/**
* Forwards the request to another controller.
*
* @param string $controller The controller name (a string like BlogBundle:Post:index)
* @param array $path An array of path parameters
* @param array $query An array of query parameters
*
* @return Response A Response instance
*/
protected function forward($controller, array $path = array(), array $query = array())
{
$path['_controller'] = $controller;
$subRequest = $this->container->get('request')->duplicate($query, null, $path);
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
/**
* Render the given template, and returns the result as an Http Response.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function render($templateName, $args = array())
{
$response = new Response();
return $response->setContent($this->renderRaw($templateName, $args));
}
/**
* Render the given template, and returns the result as a string.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderRaw($templateName, $args = array())
{
// Add the template standard extension
$templateName .= '.html';
$session = $this->getSession();
$args = array_merge($args, array(
'locale' => $session->getLocale(),
'lang' => $session->getLang()
));
try {
$data = $this->getParser()->render($templateName, $args);
return $data;
} catch (AuthenticationException $ex) {
// User is not authenticated, and templates requires authentication -> redirect to login page
// We user login_tpl as a path, not a template.
Redirect::exec(URL::absoluteUrl($ex->getLoginTemplate()));
}
}
}

47
core/lib/Thelia/Controller/Admin/CategoryController.php Normal file → Executable file
View File

@@ -21,61 +21,66 @@
/* */
/*************************************************************************************/
namespace Thelia\Admin\Controller;
namespace Thelia\Controller\Admin;
use Thelia\Model\CategoryQuery;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\AuthorizationException;
class CategoryController extends BaseAdminController {
protected function createNewCategory($args) {
class CategoryController extends BaseAdminController
{
protected function createNewCategory($args)
{
$this->dispatchEvent("createCategory");
// At this point, the form has error, and should be redisplayed.
return $this->render('categories', $args);
}
protected function editCategory($args) {
protected function editCategory($args)
{
$this->checkAuth("ADMIN", "admin.category.edit");
return $this->render('edit_category', $args);
}
protected function deleteCategory($args) {
protected function deleteCategory($args)
{
$this->dispatchEvent("deleteCategory");
// Something was wrong, category was not deleted. Display parent category list
return $this->render('categories', $args);
}
protected function browseCategory($args) {
protected function browseCategory($args)
{
$this->checkAuth("AMIN", "admin.catalog.view");
return $this->render('categories', $args);
}
protected function visibilityToggle($args) {
protected function visibilityToggle($args)
{
$this->dispatchEvent("toggleCategoryVisibility");
return $this->nullResponse();
}
protected function changePosition($args) {
protected function changePosition($args)
{
$this->dispatchEvent("changeCategoryPosition");
return $this->render('categories', $args);
}
protected function positionDown($args) {
protected function positionDown($args)
{
$this->dispatchEvent("changeCategoryPositionDown");
return $this->render('categories', $args);
}
protected function positionUp($args) {
protected function positionUp($args)
{
$this->dispatchEvent("changeCategoryPositionUp");
return $this->render('categories', $args);
@@ -102,34 +107,40 @@ class CategoryController extends BaseAdminController {
try {
switch ($action) {
case 'browse' : // Browse categories
return $this->browseCategory($args);
case 'create' : // Create a new category
return $this->createNewCategory($args);
case 'edit' : // Edit an existing category
return $this->editCategory($args);
case 'delete' : // Delete an existing category
return $this->deleteCategory($args);
case 'visibilityToggle' : // Toggle visibility
return $this->visibilityToggle($id);
case 'changePosition' : // Change position
return $this->changePosition($args);
case 'positionUp' : // Move up category
return $this->positionUp($args);
case 'positionDown' : // Move down category
return $this->positionDown($args);
}
}
catch(AuthorizationException $ex) {
} catch (AuthorizationException $ex) {
return $this->errorPage($ex->getMessage());
}
catch(AuthenticationException $ex) {
} catch (AuthenticationException $ex) {
return $this->errorPage($ex->getMessage());
}

View File

@@ -21,9 +21,8 @@
/* */
/*************************************************************************************/
namespace Thelia\Admin\Controller;
namespace Thelia\Controller\Admin;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Form\AdminLogin;
use Thelia\Core\Security\Authentication\AdminUsernamePasswordFormAuthenticator;
use Thelia\Model\AdminLog;
@@ -33,8 +32,8 @@ use Thelia\Tools\URL;
use Thelia\Tools\Redirect;
use Thelia\Core\Event\TheliaEvents;
class SessionController extends BaseAdminController {
class SessionController extends BaseAdminController
{
public function showLoginAction()
{
return $this->render("login");
@@ -71,20 +70,17 @@ class SessionController extends BaseAdminController {
// Redirect to the success URL
return Redirect::exec($adminLoginForm->getSuccessUrl());
}
catch (ValidatorException $ex) {
} catch (ValidatorException $ex) {
// Validation problem
$message = "Missing or invalid information. Please check your input.";
}
catch (AuthenticationException $ex) {
} catch (AuthenticationException $ex) {
// Log authentication failure
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
$message = "Login failed. Please check your username and password.";
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Log authentication failure
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);

View File

@@ -22,17 +22,9 @@
/*************************************************************************************/
namespace Thelia\Controller;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerAware;
use Thelia\Form\BaseForm;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\SecurityContext;
use Thelia\Tools\URL;
use Thelia\Tools\Redirect;
@@ -40,7 +32,8 @@ use Thelia\Core\Template\ParserContext;
use Thelia\Core\Event\ActionEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Thelia\Core\Factory\ActionEventFactory;
use Thelia\Core\Security\Exception\AuthorizationException;
use Thelia\Form\BaseForm;
use Thelia\Form\Exception\FormValidationException;
/**
*
@@ -53,59 +46,6 @@ use Thelia\Core\Security\Exception\AuthorizationException;
class BaseController extends ContainerAware
{
const TEMPLATE_404 = "404";
public function processTemplateAction($template)
{
try {
if (! empty($template)) {
// If we have a view in the URL, render this view
return $this->render($template);
}
else if (null != $view = $this->getRequest()->get('view')) {
return $this->render($view);
}
}
catch (\Exception $ex) {
// Nothing special
}
return $this->pageNotFound();
}
/**
* Return a 404 error
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function pageNotFound() {
return new Response($this->renderRaw(self::TEMPLATE_404), 404);
}
/**
* Return a general error page
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function errorPage($message) {
return $this->render('general_error', array(
"error_message" => $message)
);
}
/**
* Check current admin user authorisations. An ADMIN role is assumed.
*
* @param unknown $permissions a single permission or an array of permissions.
*
* @throws AuthenticationException if permissions are not granted ti the current user.
*/
protected function checkAuth($permissions) {
if (! $this->getSecurityContext()->isGranted(array("ADMIN"), is_array($permissions) ? $permissions : array($permissions))) {
throw new AuthorizationException("Sorry, you're not allowed to perform this action");
}
}
/**
* Return an empty response (after an ajax request, for example)
@@ -116,55 +56,9 @@ class BaseController extends ContainerAware
}
/**
* Render the given template, and returns the result as an Http Response.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function render($templateName, $args = array())
{
$response = new Response();
return $response->setContent($this->renderRaw($templateName, $args));
}
/**
* Render the given template, and returns the result as a string.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderRaw($templateName, $args = array())
{
// Add the template standard extension
$templateName .= '.html';
$session = $this->getSession();
$args = array_merge($args, array(
'locale' => $session->getLocale(),
'lang' => $session->getLang()
));
try {
$data = $this->getParser()->render($templateName, $args);
return $data;
}
catch (AuthenticationException $ex) {
// User is not authenticated, and templates requires authentication -> redirect to login page
// We user login_tpl as a path, not a template.
Redirect::exec(URL::absoluteUrl($ex->getLoginTemplate()));
}
}
/**
* Create an action event,
* Create an action event
*
* @param string $action
* @return EventDispatcher
*/
protected function dispatchEvent($action)
@@ -189,15 +83,15 @@ class BaseController extends ContainerAware
* @param string $eventName a TheliaEvent name, as defined in TheliaEvents class
* @param ActionEvent $event the event
*/
protected function dispatch($eventName, ActionEvent $event = null) {
protected function dispatch($eventName, ActionEvent $event = null)
{
$this->getDispatcher()->dispatch($eventName, $event);
}
/**
* Return the event dispatcher,
*
* @return EventDispatcherInterface
* @return \Symfony\Component\EventDispatcher\EventDispatcher
*/
public function getDispatcher()
{
@@ -217,7 +111,7 @@ class BaseController extends ContainerAware
/**
* Return the security context, by default in admin mode.
*
* @return Thelia\Core\Security\SecurityContext
* @return \Thelia\Core\Security\SecurityContext
*/
protected function getSecurityContext($context = false)
{
@@ -241,40 +135,56 @@ class BaseController extends ContainerAware
*
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
*/
protected function getSession() {
protected function getSession()
{
$request = $this->getRequest();
return $request->getSession();
}
/**
* @return a ParserInterfac instance parser
* Validate a BaseForm
*
* @param BaseForm $aBaseForm the form
* @param string $expectedMethod the expected method, POST or GET, or null for any of them
* @throws FormValidationException is the form contains error, or the method is not the right one
* @return \Symfony\Component\Form\Form Form the symfony form object
*/
protected function getParser()
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
{
$parser = $this->container->get("thelia.parser");
$form = $aBaseForm->getForm();
// Define the template thant shoud be used
$parser->setTemplate(ConfigQuery::read('base_admin_template', 'admin/default'));
if ($expectedMethod == null || $aBaseForm->getRequest()->isMethod($expectedMethod)) {
return $parser;
$form->bind($aBaseForm->getRequest());
if ($form->isValid()) {
return $form;
} else {
throw new FormValidationException("Missing or invalid data");
}
} else {
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
}
}
/**
* Forwards the request to another controller.
*
* @param string $controller The controller name (a string like BlogBundle:Post:index)
* @param array $path An array of path parameters
* @param array $query An array of query parameters
*
* @return Response A Response instance
* redirect request to specify url
* @param string $url
*/
protected function forward($controller, array $path = array(), array $query = array())
public function redirect($url)
{
$path['_controller'] = $controller;
$subRequest = $this->container->get('request')->duplicate($query, null, $path);
Redirect::exec($url);
}
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
/**
* If success_url param is present in request, follow this link.
*/
protected function redirectSuccess()
{
if (null !== $url = $this->getRequest()->get("success_url")) {
$this->redirect($url);
}
}
}

View File

@@ -22,9 +22,8 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Thelia\Controller\BaseController;
class BaseFrontController extends BaseController {
class BaseFrontController extends BaseController
{
}

121
core/lib/Thelia/Controller/Front/CartController.php Normal file → Executable file
View File

@@ -22,33 +22,118 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Event\CartEvent;
use Thelia\Core\Event\TheliaEvents;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Form\CartAdd;
class CartController extends BaseFrontController
{
use \Thelia\Cart\CartTrait;
public function addArticle()
{
$cartEvent = $this->getCartEvent();
$this->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
}
public function modifyArticle()
{
$cartEvent = $this->getCartEvent();
$this->dispatch(TheliaEvents::CART_CHANGEARTICLE, $cartEvent);
}
protected function getCartEvent()
public function addItem()
{
$request = $this->getRequest();
$cart = $this->getCart($request);
return new CartEvent($request, $cart);
$cartAdd = $this->getAddCartForm($request);
$message = null;
try {
$form = $this->validateForm($cartAdd);
$cartEvent = $this->getCartEvent();
$cartEvent->setNewness($form->get("newness")->getData());
$cartEvent->setAppend($form->get("append")->getData());
$cartEvent->setQuantity($form->get("quantity")->getData());
$cartEvent->setProductSaleElementsId($form->get("product_sale_elements_id")->getData());
$cartEvent->setProduct($form->get("product")->getData());
$this->getDispatcher()->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
$this->redirectSuccess();
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
$message = "Failed to add this article to your cart, please try again";
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
if ($message) {
$cartAdd->setErrorMessage($message);
$this->getParserContext()->setErrorForm($cartAdd);
}
}
public function changeItem()
{
$cartEvent = $this->getCartEvent();
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
$cartEvent->setQuantity($this->getRequest()->get("quantity"));
try {
$this->getDispatcher()->dispatch(TheliaEvents::CART_CHANGEITEM, $cartEvent);
$this->redirectSuccess();
} catch(PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
public function deleteItem()
{
$cartEvent = $this->getCartEvent();
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
try {
$this->getDispatcher()->dispatch(TheliaEvents::CART_DELETEITEM, $cartEvent);
$this->redirectSuccess();
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during deleting cartItem with message : %s", $e->getMessage()));
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
/**
* use Thelia\Cart\CartTrait for searching current cart or create a new one
*
* @return CartEvent
*/
protected function getCartEvent()
{
$cart = $this->getCart($this->getRequest());
return new CartEvent($cart);
}
/**
* Find the good way to construct the cart form
*
* @param Request $request
* @return CartAdd
*/
private function getAddCartForm(Request $request)
{
if ($request->isMethod("post")) {
$cartAdd = new CartAdd($request);
} else {
$cartAdd = new CartAdd(
$request,
"form",
array(),
array(
'csrf_protection' => false,
)
);
}
return $cartAdd;
}
}

134
core/lib/Thelia/Controller/Front/CustomerController.php Normal file → Executable file
View File

@@ -22,44 +22,150 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Thelia\Controller\BaseController;
use Symfony\Component\DependencyInjection\ContainerAware;
use Thelia\Core\Event\CustomerEvent;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerLoginEvent;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Thelia\Core\Security\SecurityContext;
use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerModification;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer;
use Thelia\Core\Event\TheliaEvents;
class CustomerController extends BaseFrontController {
class CustomerController extends BaseFrontController
{
/**
* create a new Customer. Retrieve data in form and dispatch a action.createCustomer event
*
* if error occurs, message is set in the parserContext
*/
public function createAction()
{
$request = $this->getRequest();
$customerCreation = new CustomerCreation($request);
try {
$form = $this->validateForm($customerCreation, "post");
$event = $this->dispatchEvent("createCustomer");
if(null !== $customer = $event->customer) {
$this->processLogin($event->customer);
$customerCreateEvent = $this->createEventInstance($form->getData());
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
$this->processLogin($customerCreateEvent->getCustomer());
$this->redirectSuccess();
} catch (FormValidationException $e) {
$customerCreation->setErrorMessage($e->getMessage());
$this->getParserContext()->setErrorForm($customerCreation);
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during customer creation process in front context with message : %s", $e->getMessage()));
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
public function displayCreateAction()
public function updateAction()
{
$request = $this->getRequest();
$customerModification = new CustomerModification($request);
try {
$customer = $this->getSecurityContext(SecurityContext::CONTEXT_FRONT_OFFICE)->getUser();
$form = $this->validateForm($customerModification, "post");
$customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer);
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
$this->processLogin($customerChangeEvent->getCustomer());
$this->redirectSuccess();
} catch (FormValidationException $e) {
$customerModification->setErrorMessage($e->getMessage());
$this->getParserContext()->setErrorForm($customerModification);
} catch (PropelException $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during updating customer in front context with message : %s", $e->getMessage()));
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
/**
* Perform user login. On a successful login, the user is redirected to the URL
* found in the success_url form parameter, or / if none was found.
*
* If login is not successfull, the same view is dispolyed again.
*
*/
public function loginAction()
{
$event = $this->dispatchEvent("loginCustomer");
$request = $this->getRequest();
$customerEvent = new CustomerEvent($event->getCustomer());
$customerLoginForm = new CustomerLogin($request);
$this->processLogin($event->getCustomer(), $customerEvent, true);
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
try {
$customer = $authenticator->getAuthentifiedUser();
$customerLoginEvent = new CustomerLoginEvent($customer);
$this->processLogin($customer, $customerLoginEvent);
$this->redirectSuccess();
} catch (ValidatorException $e) {
} catch(UsernameNotFoundException $e) {
} catch(AuthenticationException $e) {
} catch (\Exception $e) {
}
}
public function processLogin(Customer $customer,$event = null, $sendLogin = false)
public function processLogin(Customer $customer,$event = null)
{
$this->getSecurityContext(SecurityContext::CONTEXT_FRONT_OFFICE)->setUser($customer);
if($sendLogin) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
if($event) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
}
/**
* @param $data
* @return CustomerCreateOrUpdateEvent
*/
private function createEventInstance($data)
{
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["city"],
$data["country"],
isset($data["email"])?$data["email"]:null,
isset($data["password"]) ? $data["password"]:null,
$this->getRequest()->getSession()->getLang(),
isset($data["reseller"])?$data["reseller"]:null,
isset($data["sponsor"])?$data["sponsor"]:null,
isset($data["discount"])?$data["discount"]:nullsch
);
return $customerCreateEvent;
}
}

View File

@@ -20,9 +20,8 @@
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller;
namespace Thelia\Controller\Front;
use Thelia\Controller\NullControllerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -32,7 +31,7 @@ use Symfony\Component\HttpFoundation\Request;
* @author Manuel Raynaud <mraynadu@openstudio.fr>
*/
class DefaultController implements NullControllerInterface
class DefaultController extends BaseFrontController
{
/**
*

View File

@@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\Scope;
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
/**
* First Bundle use in Thelia
@@ -55,7 +56,11 @@ class TheliaBundle extends Bundle
$container->addScope(new Scope('request'));
$container->addCompilerPass(new RegisterListenersPass());
$container->addCompilerPass(new RegisterParserPluginPass());
$container
->addCompilerPass(new RegisterListenersPass())
->addCompilerPass(new RegisterParserPluginPass())
->addCompilerPass(new RegisterRouterPass())
;
}
}

4
core/lib/Thelia/Core/Context.php Normal file → Executable file
View File

@@ -23,7 +23,6 @@
namespace Thelia\Core;
class Context
{
const CONTEXT_FRONT_OFFICE = 'front';
@@ -43,8 +42,7 @@ class Context
public function setContext($context)
{
if($this->isValidContext($context))
{
if ($this->isValidContext($context)) {
$this->currentContext = $context;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
class RegisterRouterPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process(ContainerBuilder $container)
{
try {
$chainRouter = $container->getDefinition("router.chainRequest");
} catch (InvalidArgumentException $e) {
return;
}
foreach ($container->findTaggedServiceIds("router.register") as $id => $attributes) {
$priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0;
$router = $container->getDefinition($id);
$router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher".$id)));
$chainRouter->addMethodCall("add", array(new Reference($id), $priority));
}
if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated();
foreach ($modules as $module) {
$moduleCode = ucfirst($module->getCode());
if (file_exists(THELIA_MODULE_DIR . "/" . $moduleCode . "/Config/routing.xml")) {
$definition = new Definition(
$container->getParameter("router.class"),
array(
new Reference("router.module.xmlLoader"),
ucfirst($module->getCode()) . "/Config/routing.xml",
array(
"cache_dir" => $container->getParameter("kernel.cache_dir"),
"debug" => $container->getParameter("kernel.debug"),
"matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleCode)
),
new Reference("request.context")
)
);
$container->setDefinition("router.".$moduleCode, $definition);
$chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), -1));
}
}
}
}
}

View File

@@ -16,6 +16,7 @@
<xsd:element name="parameters" type="parameters"/>
<xsd:element name="commands" type="commands"/>
<xsd:element name="forms" type="forms" />
<xsd:element name="routing" type="routing" />
</xsd:choice>
</xsd:complexType>
@@ -54,6 +55,16 @@
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="routing">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="file" type="file"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="file">
<xsd:attribute name="path" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="loops">
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
<xsd:element name="loop" type="loop"/>

View File

@@ -26,7 +26,6 @@ namespace Thelia\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Form\BaseForm;
use Thelia\Core\Security\SecurityContext;
/**
*
* Class thrown on Thelia.action event
@@ -43,7 +42,6 @@ abstract class ActionEvent extends Event
*/
protected $request;
protected $errorForm = null;
protected $parameters = array();
@@ -58,7 +56,6 @@ abstract class ActionEvent extends Event
$this->request = $request;
}
public function __set($name, $value)
{
$this->parameters[$name] = $value;
@@ -82,17 +79,20 @@ abstract class ActionEvent extends Event
return $this->request;
}
public function setErrorForm(BaseForm $form) {
public function setErrorForm(BaseForm $form)
{
$this->errorForm = $form;
if ($form != null) $this->stopPropagation();
}
public function getErrorForm() {
public function getErrorForm()
{
return $this->errorForm;
}
public function hasErrorForm() {
public function hasErrorForm()
{
return $this->errorForm != null ? true : false;
}
}

120
core/lib/Thelia/Core/Event/CartEvent.php Normal file → Executable file
View File

@@ -23,21 +23,127 @@
namespace Thelia\Core\Event;
use Thelia\Core\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Cart;
class CartEvent extends ActionEvent {
protected $cart;
public function __construct(Request $request, Cart $cart)
class CartEvent extends Event
{
protected $cart;
protected $quantity;
protected $append;
protected $newness;
protected $productSaleElementsId;
protected $product;
protected $cartItem;
public function __construct(Cart $cart)
{
parent::__construct($request);
$this->cart = $cart;
}
/**
* @param mixed $append
*/
public function setAppend($append)
{
$this->append = $append;
}
/**
* @return mixed
*/
public function getAppend()
{
return $this->append;
}
/**
* @param mixed $cartItem
*/
public function setCartItem($cartItem)
{
$this->cartItem = $cartItem;
}
/**
* @return mixed
*/
public function getCartItem()
{
return $this->cartItem;
}
/**
* @param mixed $newness
*/
public function setNewness($newness)
{
$this->newness = $newness;
}
/**
* @return mixed
*/
public function getNewness()
{
return $this->newness;
}
/**
* @param mixed $product
*/
public function setProduct($product)
{
$this->product = $product;
}
/**
* @return mixed
*/
public function getProduct()
{
return $this->product;
}
/**
* @param mixed $productSaleElementsId
*/
public function setProductSaleElementsId($productSaleElementsId)
{
$this->productSaleElementsId = $productSaleElementsId;
}
/**
* @return mixed
*/
public function getProductSaleElementsId()
{
return $this->productSaleElementsId;
}
/**
* @param mixed $quantity
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
/**
* @return mixed
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @return \Thelia\Model\Cart
*/
public function getCart()
{
return $this->cart;
}
}

5
core/lib/Thelia/Core/Event/CartItemEvent.php Normal file → Executable file
View File

@@ -23,11 +23,10 @@
namespace Thelia\Core\Event;
use Thelia\Model\CartItem;
class CartItemEvent extends InternalEvent {
class CartItemEvent extends InternalEvent
{
protected $cartItem;
public function __construct(CartItem $cartItem)

5
core/lib/Thelia/Core/Event/CategoryEvent.php Normal file → Executable file
View File

@@ -23,11 +23,10 @@
namespace Thelia\Core\Event;
use Thelia\Model\Category;
class CategoryEvent extends InternalEvent {
class CategoryEvent extends InternalEvent
{
public $category;
public function __construct(Category $category)

View File

@@ -0,0 +1,237 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: manu
* Date: 16/08/13
* Time: 10:24
* To change this template use File | Settings | File Templates.
*/
namespace Thelia\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Customer;
class CustomerCreateOrUpdateEvent extends Event {
//base parameters for creating new customer
protected $title;
protected $firstname;
protected $lastname;
protected $address1;
protected $address2;
protected $address3;
protected $phone;
protected $cellphone;
protected $zipcode;
protected $city;
protected $country;
protected $email;
protected $password;
protected $lang;
protected $reseller;
protected $sponsor;
protected $discount;
/**
* @var \Thelia\Model\Customer
*/
protected $customer;
/**
* @param int $title the title customer id
* @param string $firstname
* @param string $lastname
* @param string $address1
* @param string $address2
* @param string $address3
* @param string $phone
* @param string $cellphone
* @param string $zipcode
* @param string $city
* @param int $country the country id
* @param string $email
* @param string $password plain password, don't put hash password, it will hashes again
* @param $lang
* @param int $reseller if customer is a reseller
* @param int $sponsor customer's id sponsor
* @param float $discount
*/
function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount)
{
$this->address1 = $address1;
$this->address2 = $address2;
$this->address3 = $address3;
$this->country = $country;
$this->email = $email;
$this->firstname = $firstname;
$this->lang = $lang;
$this->lastname = $lastname;
$this->password = $password;
$this->phone = $phone;
$this->cellphone = $cellphone;
$this->title = $title;
$this->zipcode = $zipcode;
$this->reseller = $reseller;
$this->sponsor = $sponsor;
$this->discount = $discount;
}
/**
* @return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* @return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* @return string
*/
public function getAddress3()
{
return $this->address3;
}
/**
* @return int
*/
public function getCountry()
{
return $this->country;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* @return mixed
*/
public function getLang()
{
return $this->lang;
}
/**
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/**
* @return int
*/
public function getTitle()
{
return $this->title;
}
/**
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @return int
*/
public function getReseller()
{
return $this->reseller;
}
/**
* @return int
*/
public function getSponsor()
{
return $this->sponsor;
}
/**
* @param Customer $customer
*/
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
}
/**
* @return Customer
*/
public function getCustomer()
{
return $this->customer;
}
}

View File

@@ -21,33 +21,22 @@
/* */
/*************************************************************************************/
namespace Thelia\Core\DependencyInjection;
namespace Thelia\Core\Event;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\Context;
use Thelia\Model\Customer;
class ContainerAwareAdmin implements ContainerAwareInterface {
class CustomerLoginEvent {
/**
* @var ContainerInterface
*
* @api
*/
protected $container;
protected $customer;
/**
* Sets the Container.
*
* @param ContainerInterface|null $container A ContainerInterface instance or null
*
* @api
*/
public function setContainer(ContainerInterface $container = null)
public function __construct(Customer $customer)
{
$container->get('thelia.envContext')->setContext(Context::CONTEXT_BACK_OFFICE);
$this->container = $container;
$this->customer = $customer;
}
public function getCustomer()
{
return $this->customer;
}
}

View File

@@ -0,0 +1,257 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Model\Cart;
class ImageEvent extends ActionEvent
{
/**
* @var string The complete file name (with path) of the source image
*/
protected $source_filepath = null;
/**
* @var string The target subdirectory in the image cache
*/
protected $cache_subdirectory = null;
/**
* @var string The absolute URL of the cached image (in the web space)
*/
protected $file_url = null;
/**
* @var string The absolute path of the cached image file
*/
protected $cache_filepath = null;
/**
* @var string The absolute URL of the cached version of the original image (in the web space)
*/
protected $original_file_url = null;
/**
* @var string The absolute path of the cached version of the original image file
*/
protected $cache_original_filepath = null;
/**
* @var string The image category (i.e. the subdirectory in image cache)
*/
protected $category = null;
/**
* @var integer the required image width
*/
protected $width = null;
/**
* @var int the required image height
*/
protected $height = null;
/**
* @var string the resize mode, either crop, bands, none
*/
protected $resize_mode = null;
/**
* @var string the background color in RGB format (eg. #ff8000)
*/
protected $background_color = null;
/**
* @var array a list of effects (grayscale, negative, mirror...), applied in the specified order.
*/
protected $effects = array();
/**
* @var int the rotation angle in degrees, none if zero or null
*/
protected $rotation = null;
/**
* @var int the quality of the result image, from 0 (!) to 100
*/
protected $quality = null;
/**
* @return boolean true if the required image is the original image (resize_mode and background_color are not significant)
*/
public function isOriginalImage()
{
return empty($this->width) && empty($this->height) /* && empty($this->resize_mode) && empty($this->background_color) not significant */
&& empty($this->effects) && empty($this->rotation) && empty($this->quality);
}
/**
* @return string a hash identifiying the processing options
*/
public function getOptionsHash()
{
return md5(
$this->width . $this->height . $this->resize_mode . $this->background_color . implode(',', $this->effects)
. $this->rotation);
}
public function getCategory()
{
return $this->category;
}
public function setCategory($category)
{
$this->category = $category;
}
public function getWidth()
{
return $this->width;
}
public function setWidth($width)
{
$this->width = $width;
}
public function getHeight()
{
return $this->height;
}
public function setHeight($height)
{
$this->height = $height;
}
public function getResizeMode()
{
return $this->resize_mode;
}
public function setResizeMode($resize_mode)
{
$this->resize_mode = $resize_mode;
}
public function getBackgroundColor()
{
return $this->background_color;
}
public function setBackgroundColor($background_color)
{
$this->background_color = $background_color;
}
public function getEffects()
{
return $this->effects;
}
public function setEffects(array $effects)
{
$this->effects = $effects;
}
public function getRotation()
{
return $this->rotation;
}
public function setRotation($rotation)
{
$this->rotation = $rotation;
}
public function getFileUrl()
{
return $this->file_url;
}
public function setFileUrl($file_url)
{
$this->file_url = $file_url;
}
public function getCacheFilepath()
{
return $this->cache_filepath;
}
public function setCacheFilepath($cache_filepath)
{
$this->cache_filepath = $cache_filepath;
}
public function getSourceFilepath()
{
return $this->source_filepath;
}
public function setSourceFilepath($source_filepath)
{
$this->source_filepath = $source_filepath;
}
public function getCacheSubdirectory()
{
return $this->cache_subdirectory;
}
public function setCacheSubdirectory($cache_subdirectory)
{
$this->cache_subdirectory = $cache_subdirectory;
}
public function getQuality()
{
return $this->quality;
}
public function setQuality($quality)
{
$this->quality = $quality;
}
public function getOriginalFileUrl()
{
return $this->original_file_url;
}
public function setOriginalFileUrl($original_file_url)
{
$this->original_file_url = $original_file_url;
}
public function getCacheOriginalFilepath()
{
return $this->cache_original_filepath;
}
public function setCacheOriginalFilepath($cache_original_filepath)
{
$this->cache_original_filepath = $cache_original_filepath;
}
}

8
core/lib/Thelia/Core/Event/Internal/CartEvent.php Normal file → Executable file
View File

@@ -21,14 +21,12 @@
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Internal;
use Thelia\Model\Cart;
class CartEvent extends InternalEvent {
class CartEvent extends InternalEvent
{
public $cart;
public function __construct(Cart $cart)
@@ -36,6 +34,4 @@ class CartEvent extends InternalEvent {
$this->cart = $cart;
}
}

14
core/lib/Thelia/Core/Event/Internal/CustomerEvent.php Normal file → Executable file
View File

@@ -23,11 +23,10 @@
namespace Thelia\Core\Event\Internal;
use Thelia\Model\Customer;
class CustomerEvent extends InternalEvent {
class CustomerEvent extends InternalEvent
{
public $customer;
public function __construct(Customer $customer)
@@ -35,4 +34,13 @@ class CustomerEvent extends InternalEvent {
$this->customer = $customer;
}
/**
* @return \Thelia\Model\Customer
*/
public function getCustomer()
{
return $this->customer;
}
}

5
core/lib/Thelia/Core/Event/Internal/InternalEvent.php Normal file → Executable file
View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Internal;
use Symfony\Component\EventDispatcher\Event;
/**
@@ -32,6 +31,6 @@ use Symfony\Component\EventDispatcher\Event;
* Class InternalEvent
* @package Thelia\Core\Event
*/
abstract class InternalEvent extends Event {
abstract class InternalEvent extends Event
{
}

View File

@@ -56,6 +56,16 @@ final class TheliaEvents
*/
const CUSTOMER_LOGIN = "action.customer_login";
/**
* sent on customer account creation
*/
const CUSTOMER_CREATEACCOUNT = "action.createCustomer";
/**
* sent on customer account update
*/
const CUSTOMER_UPDATEACCOUNT = "action.modifyCustomer";
/**
* Sent before the logout of the administrator.
*/
@@ -65,8 +75,6 @@ final class TheliaEvents
*/
const ADMIN_LOGIN = "action.admin_login";
/**
* Sent once the customer creation form has been successfully validated, and before customer insertion in the database.
*/
@@ -86,8 +94,6 @@ final class TheliaEvents
*/
const AFTER_CHANGECUSTOMER = "action.after_changecustomer";
/**
* Sent once the category creation form has been successfully validated, and before category insertion in the database.
*/
@@ -112,7 +118,6 @@ final class TheliaEvents
*/
const AFTER_CHANGECATEGORY = "action.after_changecategory";
/**
* sent when a new existing cat id duplicated. This append when current customer is different from current cart
*/
@@ -121,7 +126,7 @@ final class TheliaEvents
/**
* sent when a new item is added to current cart
*/
const AFTER_CARTADDITEM = "cart.addItem";
const AFTER_CARTADDITEM = "cart.after.addItem";
/**
* sent when a cart item is modify
@@ -136,5 +141,18 @@ final class TheliaEvents
/**
* sent on modify article action
*/
const CART_CHANGEARTICLE = "action.changeArticle";
const CART_CHANGEITEM = "action.changeArticle";
const CART_DELETEITEM = "action.deleteArticle";
/**
* Sent on image processing
*/
const IMAGE_PROCESS = "action.processImage";
/**
* Sent on cimage cache clear request
*/
const IMAGE_CLEAR_CACHE = "action.clearImageCache";
}

View File

@@ -44,7 +44,8 @@ class ControllerListener implements EventSubscriberInterface
*/
protected $parserContext;
public function __construct(ParserContext $parserContext) {
public function __construct(ParserContext $parserContext)
{
$this->parserContext = $parserContext;
}

View File

@@ -81,11 +81,9 @@ class ViewListener implements EventSubscriberInterface
} else {
$event->setResponse(new Response($content, $parser->getStatus() ?: 200));
}
}
catch (ResourceNotFoundException $e) {
} catch (ResourceNotFoundException $e) {
$event->setResponse(new Response($e->getMessage(), 404));
}
catch (AuthenticationException $ex) {
} catch (AuthenticationException $ex) {
// Redirect to the login template
$event->setResponse(Redirect::exec(URL::viewUrl($ex->getLoginTemplate())));

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\HttpFoundation;
use Symfony\Component\HttpFoundation\Request as BaseRequest;
use Thelia\Core\Context;
class Request extends BaseRequest
{
@@ -46,6 +45,7 @@ class Request extends BaseRequest
if ('' == $this->getQueryString()) {
$additionalQs = '?'. ltrim($additionalQs, '&');
}
return $uri . $additionalQs;
}
}

View File

@@ -31,9 +31,10 @@ use Thelia\Core\Security\UserProvider\AdminUserProvider;
use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator;
use Thelia\Form\AdminLogin;
class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator {
public function __construct(Request $request, AdminLogin $loginForm) {
class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator
{
public function __construct(Request $request, AdminLogin $loginForm)
{
parent::__construct(
$request,
$loginForm,

View File

@@ -23,8 +23,8 @@
namespace Thelia\Core\Security\Authentication;
interface AuthenticatorInterface {
interface AuthenticatorInterface
{
/**
* Returns a UserInterface instance, authentified using the authenticator specific method
*/

View File

@@ -29,9 +29,10 @@ use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator;
use Thelia\Form\CustomerLogin;
use Thelia\Core\Security\UserProvider\CustomerUserProvider;
class CustomerUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator {
public function __construct(Request $request, CustomerLogin $loginForm) {
class CustomerUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator
{
public function __construct(Request $request, CustomerLogin $loginForm)
{
parent::__construct(
$request,
$loginForm,

View File

@@ -32,8 +32,8 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Form\BaseForm;
class UsernamePasswordFormAuthenticator implements AuthenticatorInterface {
class UsernamePasswordFormAuthenticator implements AuthenticatorInterface
{
protected $request;
protected $loginForm;
protected $userProvider;
@@ -41,7 +41,8 @@ class UsernamePasswordFormAuthenticator implements AuthenticatorInterface {
protected $baseLoginForm;
public function __construct(Request $request, BaseForm $loginForm, UserProviderInterface $userProvider, array $options = array()) {
public function __construct(Request $request, BaseForm $loginForm, UserProviderInterface $userProvider, array $options = array())
{
$this->request = $request;
$this->baseLoginForm = $loginForm;
$this->loginForm = $this->baseLoginForm->getForm();
@@ -61,15 +62,16 @@ class UsernamePasswordFormAuthenticator implements AuthenticatorInterface {
/**
* @return string the username value
*/
public function getUsername() {
public function getUsername()
{
return $this->loginForm->get($this->options['username_field_name'])->getData();
}
/**
* @see \Thelia\Core\Security\Authentication\AuthenticatorInterface::getAuthentifiedUser()
*/
public function getAuthentifiedUser() {
public function getAuthentifiedUser()
{
if ($this->request->isMethod($this->options['required_method'])) {
if (! $this->loginForm->isValid()) throw new ValidatorException("Form is not valid.");
@@ -86,7 +88,6 @@ class UsernamePasswordFormAuthenticator implements AuthenticatorInterface {
$authOk = $user->checkPassword($password) === true;
if ($authOk !== true) throw new WrongPasswordException(sprintf("Wrong password for user '%s'.", $username));
return $user;
}

View File

@@ -33,7 +33,8 @@ class AuthenticationException extends \Exception
/**
* @return string the login template name
*/
public function getLoginTemplate() {
public function getLoginTemplate()
{
return $this->loginTemplate;
}
@@ -42,7 +43,8 @@ class AuthenticationException extends \Exception
*
* @param string $loginPath the login template name
*/
public function setLoginTemplate($loginTemplate) {
public function setLoginTemplate($loginTemplate)
{
$this->loginTemplate = $loginTemplate;
}
}

View File

View File

View File

View File

@@ -39,7 +39,8 @@ class Role implements RoleInterface
return $this->role;
}
public function __toString() {
public function __toString()
{
return $this->role;
}
}

View File

@@ -23,9 +23,6 @@
namespace Thelia\Core\Security;
use Thelia\Core\Security\Authentication\AuthenticationProviderInterface;
use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
use Thelia\Core\Security\Token\TokenInterface;
use Thelia\Core\Security\User\UserInterface;
use Thelia\Core\HttpFoundation\Request;
@@ -34,22 +31,23 @@ use Thelia\Core\HttpFoundation\Request;
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class SecurityContext {
class SecurityContext
{
const CONTEXT_FRONT_OFFICE = 'front';
const CONTEXT_BACK_OFFICE = 'admin';
private $request;
private $context;
public function __construct(Request $request) {
public function __construct(Request $request)
{
$this->request = $request;
$this->context = null;
}
public function setContext($context) {
public function setContext($context)
{
if ($context !== self::CONTEXT_FRONT_OFFICE && $context !== self::CONTEXT_BACK_OFFICE) {
throw new \InvalidArgumentException(sprintf("Invalid or empty context identifier '%s'", $context));
}
@@ -59,14 +57,16 @@ class SecurityContext {
return $this;
}
public function getContext($exception_if_context_undefined = false) {
public function getContext($exception_if_context_undefined = false)
{
if (null === $this->context && $exception_if_context_undefined === true)
throw new \LogicException("No context defined. Please use setContext() first.");
return $this->context;
}
private function getSession() {
private function getSession()
{
$session = $this->request->getSession();
if ($session === null)
@@ -80,7 +80,8 @@ class SecurityContext {
*
* @return UserInterface|null A UserInterface instance or null if no user is available
*/
public function getUser() {
public function getUser()
{
$context = $this->getContext(true);
if ($context === self::CONTEXT_FRONT_OFFICE)
@@ -181,7 +182,8 @@ class SecurityContext {
/**
* Clear the user from the security context
*/
public function clear() {
public function clear()
{
$context = $this->getContext(true);
if ($context === self::CONTEXT_FRONT_OFFICE)

View File

@@ -8,8 +8,8 @@ namespace Thelia\Core\Security\User;
* @author Franck Allimant <franck@cqfdev.fr>
*
*/
interface UserInterface {
interface UserInterface
{
/**
* Return the user unique name
*/

View File

@@ -4,10 +4,10 @@ namespace Thelia\Core\Security\UserProvider;
use Thelia\Model\Admin;
use Thelia\Model\AdminQuery;
class AdminUserProvider implements UserProviderInterface {
public function getUser($key) {
class AdminUserProvider implements UserProviderInterface
{
public function getUser($key)
{
$admin = AdminQuery::create()
->filterByLogin($key)
->findOne();

View File

@@ -1,13 +1,12 @@
<?php
namespace Thelia\Core\Security\UserProvider;
use Thelia\Action\Customer;
use Thelia\Model\CustomerQuery;
class CustomerUserProvider implements UserProviderInterface {
public function getUser($key) {
class CustomerUserProvider implements UserProviderInterface
{
public function getUser($key)
{
$customer = CustomerQuery::create()
->filterByEmail($key)
->findOne();

View File

@@ -2,7 +2,8 @@
namespace Thelia\Core\Security\UserProvider;
interface UserProviderInterface {
interface UserProviderInterface
{
/**
* Returns a UserInterface instance
*
@@ -11,4 +12,3 @@ interface UserProviderInterface {
*/
public function getUser($key);
}
?>

View File

@@ -51,7 +51,6 @@ abstract class BaseLoop
*/
protected $securityContext;
protected $args;
/**
@@ -93,8 +92,8 @@ abstract class BaseLoop
* @return null
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
*/
public function __call($name, $arguments) {
public function __call($name, $arguments)
{
if (substr($name, 0, 3) == 'get') {
// camelCase to underscore: getNotEmpty -> not_empty
@@ -113,8 +112,8 @@ abstract class BaseLoop
*
* @throws \InvalidArgumentException if somùe argument values are missing, or invalid
*/
public function initializeArgs(array $nameValuePairs) {
public function initializeArgs(array $nameValuePairs)
{
$faultActor = array();
$faultDetails = array();
@@ -130,18 +129,15 @@ abstract class BaseLoop
if ($value === null && $argument->mandatory) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter is missing in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else if($value === '' && !$argument->empty) {
} else if ($value === '' && !$argument->empty) {
/* check if empty */
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter cannot be empty in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else if($value !== null && !$argument->type->isValid($value)) {
} elseif ($value !== null && !$argument->type->isValid($value)) {
/* check type */
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('Invalid value for "%s" argument in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else {
} else {
/* set default */
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
if ($value === null) {
@@ -167,8 +163,8 @@ abstract class BaseLoop
* @throws \InvalidArgumentException if argument is not found in loop argument list
* @return Argument the loop argument.
*/
public function getArg($argumentName) {
protected function getArg($argumentName)
{
$arg = $this->args->get($argumentName);
if ($arg === null)
@@ -185,8 +181,8 @@ abstract class BaseLoop
* @throws \InvalidArgumentException if argument is not found in loop argument list
* @return Argument the loop argument.
*/
public function getArgValue($argumentName) {
protected function getArgValue($argumentName)
{
return $this->getArg($argumentName)->getValue();
}
@@ -196,7 +192,7 @@ abstract class BaseLoop
*
* @return array|mixed|\PropelModelPager|\PropelObjectCollection
*/
public function search(ModelCriteria $search, &$pagination = null)
protected function search(ModelCriteria $search, &$pagination = null)
{
if ($this->getArgValue('page') !== null) {
return $this->searchWithPagination($search, $pagination);
@@ -210,7 +206,7 @@ abstract class BaseLoop
*
* @return array|mixed|\PropelObjectCollection
*/
public function searchWithOffset(ModelCriteria $search)
protected function searchWithOffset(ModelCriteria $search)
{
if ($this->getArgValue('limit') >= 0) {
$search->limit($this->getArgValue('limit'));
@@ -226,7 +222,7 @@ abstract class BaseLoop
*
* @return array|\PropelModelPager
*/
public function searchWithPagination(ModelCriteria $search, &$pagination)
protected function searchWithPagination(ModelCriteria $search, &$pagination)
{
$pagination = $search->paginate($this->getArgValue('page'), $this->getArgValue('limit'));

View File

@@ -26,19 +26,12 @@ namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Loop\Product;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\AccessoryQuery;
use Thelia\Model\ProductQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**

View File

@@ -30,10 +30,8 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;

View File

@@ -51,11 +51,13 @@ class Argument
$this->setValue($value);
}
public function getValue() {
public function getValue()
{
return $this->type->getFormattedValue($this->value);
}
public function setValue($value) {
public function setValue($value)
{
$this->value = $value === null ? null : (string) $value;
}

View File

@@ -37,11 +37,13 @@ class ArgumentCollection implements \Iterator
$this->addArguments(func_get_args(), true);
}
public function hasKey($key) {
public function hasKey($key)
{
return isset($this->arguments[$key]);
}
public function get($key) {
public function get($key)
{
return $this->hasKey($key) ? $this->arguments[$key] : null;
}

View File

@@ -30,11 +30,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* @package Thelia\Core\Template\Loop
@@ -87,8 +82,7 @@ class Auth extends BaseLoop
// Create an empty row: loop is no longer empty :)
$loopResult->addRow(new LoopResultRow());
}
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Not granted, loop is empty
}

6
core/lib/Thelia/Core/Template/Loop/Cart.php Normal file → Executable file
View File

@@ -9,13 +9,13 @@
namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
class Cart extends BaseLoop {
class Cart extends BaseLoop
{
use \Thelia\Cart\CartTrait;
/**
*
@@ -78,7 +78,6 @@ class Cart extends BaseLoop {
return $result;
}
$cartItems = $cart->getCartItems();
foreach ($cartItems as $cartItem) {
@@ -99,5 +98,4 @@ class Cart extends BaseLoop {
return $result;
}
}

7
core/lib/Thelia/Core/Template/Loop/CategoryPath.php Normal file → Executable file
View File

@@ -23,18 +23,14 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
@@ -122,8 +118,7 @@ class CategoryPath extends BaseLoop
if ($visible == true) $search->filterByVisible($visible);
}
}
}
while ($category != null && $parent > 0);
} while ($category != null && $parent > 0);
// Reverse list and build the final result
$results = array_reverse($results);

7
core/lib/Thelia/Core/Template/Loop/CategoryTree.php Normal file → Executable file
View File

@@ -30,11 +30,8 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
@@ -65,8 +62,8 @@ class CategoryTree extends BaseLoop
}
// changement de rubrique
protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult) {
protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult)
{
if ($level > $max_level) return;
$search = CategoryQuery::create();

View File

@@ -24,16 +24,13 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\Base\FeatureContentQuery;
use Thelia\Model\FolderQuery;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\ContentFolderQuery;
@@ -69,7 +66,7 @@ class Content extends BaseLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'random', 'given_id'))
new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse', 'random', 'given_id'))
),
'alpha'
),
@@ -158,7 +155,7 @@ class Content extends BaseLoop
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
break;
case "alpha_reverse":
case "alpha-reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
break;
case "manual":

View File

@@ -30,12 +30,9 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CountryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*

View File

@@ -30,10 +30,8 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CustomerQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;

View File

@@ -24,14 +24,12 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\Base\CategoryQuery;
use Thelia\Model\Base\ProductCategoryQuery;
@@ -67,7 +65,7 @@ class Feature extends BaseLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse'))
),
'manual'
)
@@ -126,7 +124,7 @@ class Feature extends BaseLoop
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
break;
case "alpha_reverse":
case "alpha-reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
break;
case "manual":

View File

@@ -24,14 +24,12 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\Base\FeatureAvQuery;
use Thelia\Model\ConfigQuery;
@@ -60,7 +58,7 @@ class FeatureAvailability extends BaseLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse'))
),
'manual'
)
@@ -101,7 +99,7 @@ class FeatureAvailability extends BaseLoop
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
break;
case "alpha_reverse":
case "alpha-reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
break;
case "manual":

View File

@@ -30,9 +30,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*
* @package Thelia\Core\Template\Loop

View File

@@ -0,0 +1,336 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Event\ImageEvent;
use Thelia\Model\CategoryImageQuery;
use Thelia\Model\ProductImageQuery;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Type\TypeCollection;
use Thelia\Type\EnumListType;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Type\EnumType;
use Thelia\Log\Tlog;
/**
* The image loop
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class Image extends BaseLoop
{
/**
* @var array Possible image sources
*/
protected $possible_sources = array('category', 'product', 'folder', 'content');
/**
* Dynamically create the search query, and set the proper filter and order
*
* @param string $source a valid source identifier (@see $possible_sources)
* @param int $object_id the source object ID
* @return ModelCriteria the propel Query object
*/
protected function createSearchQuery($source, $object_id) {
$object = ucfirst($source);
$queryClass = sprintf("\Thelia\Model\%sImageQuery", $object);
$filterMethod = sprintf("filterBy%sId", $object);
$mapClass = sprintf("\Thelia\Model\Map\%sI18nTableMap", $object);
// xxxImageQuery::create()
$method = new \ReflectionMethod($queryClass, 'create');
$search = $method->invoke(null); // Static !
// $query->filterByXXX(id)
$method = new \ReflectionMethod($queryClass, $filterMethod);
$method->invoke($search, $object_id);
$map = new \ReflectionClass($mapClass);
$title_map = $map->getConstant('TITLE');
$orders = $this->getOrder();
// Results ordering
foreach ($orders as $order) {
switch ($order) {
case "alpha":
$search->addAscendingOrderByColumn($title_map);
break;
case "alpha-reverse":
$search->addDescendingOrderByColumn($title_map);
break;
case "manual-reverse":
$search->orderByPosition(Criteria::DESC);
break;
case "manual":
$search->orderByPosition(Criteria::ASC);
break;
case "random":
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
break(2);
break;
}
}
return $search;
}
/**
* Dynamically create the search query, and set the proper filter and order
*
* @param string $object_type (returned) the a valid source identifier (@see $possible_sources)
* @param string $object_id (returned) the ID of the source object
* @return ModelCriteria the propel Query object
*/
protected function getSearchQuery(&$object_type, &$object_id) {
$search = null;
// Check form source="product" source_id="123" style arguments
$source = $this->getSource();
if (! is_null($source)) {
$source_id = $this->getSourceId();
// echo "source = ".$this->getSource().", id=".$id."<br />";
if (is_null($source_id)) {
throw new \InvalidArgumentException("'source_id' argument cannot be null if 'source' argument is specified.");
}
$search = $this->createSearchQuery($source, $source_id);
$object_type = $source;
$object_id = $source_id;
}
else {
// Check for product="id" folder="id", etc. style arguments
foreach($this->possible_sources as $source) {
$argValue = intval($this->getArgValue($source));
if ($argValue > 0) {
$search = $this->createSearchQuery($source, $argValue);
$object_type = $source;
$object_id = $argValue;
break;
}
}
}
if ($search == null)
throw new \InvalidArgumentException(sprintf("Unable to find image source. Valid sources are %s", implode(',', $this->possible_sources)));
return $search;
}
/**
* @param unknown $pagination
*/
public function exec(&$pagination)
{
// Select the proper query to use, and get the object type
$object_type = $object_id = null;
$search = $this->getSearchQuery($object_type, $object_id);
$id = $this->getId();
if (! is_null($id)) {
$search->filterById($id, Criteria::IN);
}
$exclude = $this->getExclude();
if (!is_null($exclude))
$search->filterById($exclude, Criteria::NOT_IN);
// Create image processing event
$event = new ImageEvent($this->request);
// Prepare tranformations
$width = $this->getWidth();
$height = $this->getHeight();
$rotation = $this->getRotation();
$background_color = $this->getBackgroundColor();
$quality = $this->getQuality();
$effects = $this->getEffects();
$effects = $this->getEffects();
if (! is_null($effects)) {
$effects = explode(',', $effects);
}
switch($this->getResizeMode()) {
case 'crop' :
$resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
break;
case 'borders' :
$resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
break;
case 'none' :
default:
$resize_mode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
}
/**
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
*
* @todo : verify here if we want results for row without translations.
*/
$search->joinWithI18n(
$this->request->getSession()->getLocale(),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);
$results = $this->search($search, $pagination);
$loopResult = new LoopResult();
foreach ($results as $result) {
// Create image processing event
$event = new ImageEvent($this->request);
// Setup required transformations
if (! is_null($width)) $event->setWidth($width);
if (! is_null($height)) $event->setHeight($height);
$event->setResizeMode($resize_mode);
if (! is_null($rotation)) $event->setRotation($rotation);
if (! is_null($background_color)) $event->setBackgroundColor($background_color);
if (! is_null($quality)) $event->setQuality($quality);
if (! is_null($effects)) $event->setEffects($effects);
// Put source image file path
$source_filepath = sprintf("%s%s/%s/%s",
THELIA_ROOT,
ConfigQuery::read('documents_library_path', 'local/media/images'),
$object_type,
$result->getFile()
);
$event->setSourceFilepath($source_filepath);
$event->setCacheSubdirectory($object_type);
try {
// Dispatch image processing event
$this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
$loopResultRow = new LoopResultRow();
$loopResultRow
->set("ID", $result->getId())
->set("IMAGE_URL", $event->getFileUrl())
->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())
->set("IMAGE_PATH", $event->getCacheFilepath())
->set("ORIGINAL_IMAGE_PATH", $source_filepath)
->set("TITLE", $result->getTitle())
->set("CHAPO", $result->getChapo())
->set("DESCRIPTION", $result->getDescription())
->set("POSTSCRIPTUM", $result->getPostscriptum())
->set("POSITION", $result->getPosition())
->set("OBJECT_TYPE", $object_type)
->set("OBJECT_ID", $object_id)
;
$loopResult->addRow($loopResultRow);
}
catch (\Exception $ex) {
// Ignore the result and log an error
Tlog::getInstance()->addError("Failed to process image in image loop: ", $this->args);
}
}
return $loopResult;
}
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
$collection = new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'),
new Argument(
'order',
new TypeCollection(
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
),
'manual'
),
Argument::createIntTypeArgument('width'),
Argument::createIntTypeArgument('height'),
Argument::createIntTypeArgument('rotation', 0),
Argument::createAnyTypeArgument('background_color'),
Argument::createIntTypeArgument('quality'),
new Argument(
'resize_mode',
new TypeCollection(
new EnumType(array('crop', 'borders', 'none'))
),
'none'
),
Argument::createAnyTypeArgument('effects'),
Argument::createIntTypeArgument('category'),
Argument::createIntTypeArgument('product'),
Argument::createIntTypeArgument('folder'),
Argument::createIntTypeArgument('content'),
new Argument(
'source',
new TypeCollection(
new EnumType($this->possible_sources)
)
),
Argument::createIntTypeArgument('source_id'),
Argument::createIntListTypeArgument('lang')
);
// Add possible image sources
foreach($this->possible_sources as $source) {
$collection->addArgument(Argument::createIntTypeArgument($source));
}
return $collection;
}
}

2
core/lib/Thelia/Core/Template/Loop/Lang.php Normal file → Executable file
View File

@@ -30,8 +30,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Model\LangQuery;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;

4
core/lib/Thelia/Core/Template/Loop/Order.php Normal file → Executable file
View File

@@ -25,14 +25,10 @@ namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*
* @package Thelia\Core\Template\Loop

4
core/lib/Thelia/Core/Template/Loop/OrderStatus.php Normal file → Executable file
View File

@@ -25,14 +25,10 @@ namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*
* @package Thelia\Core\Template\Loop

View File

@@ -30,12 +30,9 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CustomerTitleQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*

9
core/lib/Thelia/Core/Template/ParserContext.php Normal file → Executable file
View File

@@ -37,8 +37,8 @@ class ParserContext implements \IteratorAggregate
{
private $store = array();
public function __construct(Request $request) {
public function __construct(Request $request)
{
// Setup basic variables
$this
->set('BASE_URL' , ConfigQuery::read('base_url', '/'))
@@ -58,6 +58,11 @@ class ParserContext implements \IteratorAggregate
$this->set('error_form', $form);
}
public function setGeneralError($error)
{
$this->set('general_error', $error);
}
public function getErrorForm()
{
return $this->get('error_form', null);

View File

@@ -65,7 +65,6 @@ abstract class AbstractSmartyPlugin
$value = $this->getParam($params, $name, $default);
if (is_string($value)) $value = strtolower(trim($value));
return $value;
}
@@ -85,8 +84,7 @@ abstract class AbstractSmartyPlugin
return $params[$test];
}
}
}
else if (isset($params[$name])) {
} elseif (isset($params[$name])) {
return $params[$name];
}
@@ -96,5 +94,5 @@ abstract class AbstractSmartyPlugin
/**
* @return an array of SmartyPluginDescriptor
*/
public abstract function getPluginDescriptors();
abstract public function getPluginDescriptors();
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Template\Smarty\Assets;
use Thelia\Core\Template\Assets\AsseticHelper;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
class SmartyAssetsManager
@@ -50,7 +49,8 @@ class SmartyAssetsManager
$this->assetic_manager = new AsseticHelper();
}
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template) {
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template)
{
$file = $params['file'];
$filters = isset($params['filters']) ? $params['filters'] : '';
$debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
@@ -70,7 +70,7 @@ class SmartyAssetsManager
$url = $this->assetic_manager->asseticize(
$asset_dir.'/'.$asset_file,
$this->web_root."/".$this->path_relative_to_web_root,
URL::absoluteUrl($this->path_relative_to_web_root, array(), true /* path only */),
URL::absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
$assetType,
$filters,
$debug

View File

@@ -67,7 +67,6 @@ class DataAccessFunctions extends AbstractSmartyPlugin
return $this->userDataAccess("Customer User", SecurityContext::CONTEXT_FRONT_OFFICE, $params);
}
/**
* Provides access to user attributes using the accessors.
*

View File

@@ -28,7 +28,6 @@ use Thelia\Core\Template\Element\Exception\ElementNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Log\Tlog;
use Thelia\Core\Template\ParserContext;
/**
@@ -111,8 +110,7 @@ class Form extends AbstractSmartyPlugin
$template->assign("form_error", $instance->hasError() ? true : false);
$template->assign("form_error_message", $instance->getErrorMessage());
}
else {
} else {
return $content;
}
}
@@ -145,8 +143,7 @@ class Form extends AbstractSmartyPlugin
$template->assign("attr", implode(" ", $attr));
$formFieldView->setRendered();
}
else {
} else {
return $content;
}
}
@@ -193,8 +190,7 @@ class Form extends AbstractSmartyPlugin
if ($repeat) {
$this->assignFieldErrorVars($template, $errors);
}
else {
} else {
return $content;
}
}
@@ -212,7 +208,8 @@ class Form extends AbstractSmartyPlugin
return array_search("hidden", $formView->vars["block_prefixes"]);
}
protected function getFormFieldView($params) {
protected function getFormFieldView($params)
{
$instance = $this->getInstanceFromParams($params);
$fieldName = $this->getParam($params, 'field');
@@ -227,8 +224,8 @@ class Form extends AbstractSmartyPlugin
return $instance->getView()[$fieldName];
}
protected function getInstanceFromParams($params) {
protected function getInstanceFromParams($params)
{
$instance = $this->getParam($params, 'form');
if (null == $instance) {

View File

@@ -25,7 +25,6 @@ namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
use Thelia\Core\Security\SecurityContext;
use Thelia\Core\Security\Exception\AuthenticationException;

View File

@@ -275,105 +275,6 @@ class TheliaLoop extends AbstractSmartyPlugin
}
}
/**
* Process {unionloop name="loop name" type="loop type" ... } ... {/unionloop} block
*
* @param $params
* @param $content
* @param $template
* @param $repeat
*
* @return string
* @throws \InvalidArgumentException
*/
public function theliaUnion($params, $content, $template, &$repeat)
{
return;
$name = $this->getParam($params, 'name');
if (null == $name)
throw new \InvalidArgumentException("Missing 'name' parameter in unionloop arguments");
$type = $this->getParam($params, 'type');
if (null == $type)
throw new \InvalidArgumentException("Missing 'type' parameter in unionloop arguments");
if ($content === null) {
// Check if a loop with the same name exists in the current scope, and abort if it's the case.
if (array_key_exists($name, $this->varstack)) {
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
}
$loop = $this->createLoopInstance($params);
self::$pagination[$name] = null;
$loopResults = $loop->exec(self::$pagination[$name]);
$this->loopstack[$name] = $loopResults;
// Pas de résultat ? la boucle est terminée, ne pas évaluer le contenu.
if ($loopResults->isEmpty()) $repeat = false;
} else {
$loopResults = $this->loopstack[$name];
$loopResults->next();
}
if ($loopResults->valid()) {
$loopResultRow = $loopResults->current();
// On first iteration, save variables that may be overwritten by this loop
if (! isset($this->varstack[$name])) {
$saved_vars = array();
$varlist = $loopResultRow->getVars();
$varlist[] = 'LOOP_COUNT';
$varlist[] = 'LOOP_TOTAL';
foreach($varlist as $var) {
$saved_vars[$var] = $template->getTemplateVars($var);
}
$this->varstack[$name] = $saved_vars;
}
foreach($loopResultRow->getVarVal() as $var => $val) {
$template->assign($var, $val);
}
$repeat = true;
}
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
// Loop is terminated. Cleanup.
if (! $repeat) {
// Restore previous variables values before terminating
if (isset($this->varstack[$name])) {
foreach($this->varstack[$name] as $var => $value) {
$template->assign($var, $value);
}
unset($this->varstack[$name]);
}
}
if ($content !== null) {
if ($loopResults->isEmpty()) {
$content = "";
}
return $content;
}
}
/**
* Check if a loop has returned results. The loop shoud have been executed before, or an
* InvalidArgumentException is thrown
@@ -474,7 +375,6 @@ class TheliaLoop extends AbstractSmartyPlugin
new SmartyPluginDescriptor('block' , 'elseloop' , $this, 'theliaElseloop'),
new SmartyPluginDescriptor('block' , 'ifloop' , $this, 'theliaIfLoop'),
new SmartyPluginDescriptor('block' , 'pageloop' , $this, 'theliaPageLoop'),
new SmartyPluginDescriptor('block' , 'union', $this, 'theliaUnion'),
);
}
}

View File

@@ -31,7 +31,8 @@ class Translation extends AbstractSmartyPlugin
{
protected $translator;
public function __construct(TranslatorInterface $translator) {
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

View File

@@ -54,7 +54,6 @@ class UrlGenerator extends AbstractSmartyPlugin
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
if ($target != null) $url .= '#'.$target;
return $url;
}
@@ -93,7 +92,6 @@ class UrlGenerator extends AbstractSmartyPlugin
$args = $this->getArgsFromParam($params, array('view', 'action', 'target'));
if (! empty($action)) $args['action'] = $action;
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
}
@@ -103,8 +101,8 @@ class UrlGenerator extends AbstractSmartyPlugin
* @param array $params Smarty function params
* @return array the parameters array (either emply, of valued)
*/
private function getArgsFromParam($params, $exclude = array()) {
private function getArgsFromParam($params, $exclude = array())
{
$pairs = array();
foreach ($params as $name => $value) {

View File

@@ -138,8 +138,7 @@ class SmartyParser extends Smarty implements ParserInterface
{
try {
$templateFile = $this->getTemplateFilePath();
}
catch(\RuntimeException $e) {
} catch (\RuntimeException $e) {
return new Response($e->getMessage(), "404");
}

View File

@@ -196,6 +196,7 @@ class Thelia extends Kernel
$parameters["thelia.root_dir"] = THELIA_ROOT;
$parameters["thelia.core_dir"] = THELIA_ROOT . "core/lib/Thelia";
$parameters["thelia.module_dir"] = THELIA_MODULE_DIR;
return $parameters;
}

4
core/lib/Thelia/Core/Translation/Translator.php Normal file → Executable file
View File

@@ -3,8 +3,8 @@ namespace Thelia\Core\Translation;
use Symfony\Component\Translation\Translator as BaseTranslator;
class Translator extends BaseTranslator {
class Translator extends BaseTranslator
{
/**
* {@inheritdoc}
*

Some files were not shown because too many files have changed in this diff Show More