Merge branch 'master' into frontend
Conflicts: core/lib/Thelia/Controller/Admin/OrderController.php
This commit is contained in:
@@ -31,7 +31,7 @@ use Thelia\Model\Customer;
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerCreateOrUpdateEvent extends ActionEvent
|
||||
class CustomerCreateOrUpdateEvent extends CustomerEvent
|
||||
{
|
||||
//base parameters for creating new customer
|
||||
protected $title;
|
||||
@@ -53,11 +53,6 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
|
||||
protected $discount;
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* @var \Thelia\Model\Customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @param int $title the title customer id
|
||||
* @param string $firstname
|
||||
@@ -242,21 +237,4 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
return $this->sponsor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,13 +28,23 @@ use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class CustomerEvent extends ActionEvent
|
||||
{
|
||||
public $customer;
|
||||
public $customer = null;
|
||||
|
||||
public function __construct(Customer $customer)
|
||||
public function __construct(Customer $customer = null)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Customer
|
||||
*/
|
||||
@@ -43,4 +53,12 @@ class CustomerEvent extends ActionEvent
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCustomer()
|
||||
{
|
||||
return $this->customer != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,17 +26,7 @@ namespace Thelia\Core\Event\Customer;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
class CustomerLoginEvent extends ActionEvent
|
||||
class CustomerLoginEvent extends CustomerEvent
|
||||
{
|
||||
protected $customer;
|
||||
|
||||
public function __construct(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
// Nothing specific :)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class SecurityContext
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
final public function isGranted(array $roles, array $resources, array $accesses)
|
||||
final public function isGranted(array $roles, array $resources, array $modules, array $accesses)
|
||||
{
|
||||
// Find a user which matches the required roles.
|
||||
$user = $this->getCustomerUser();
|
||||
@@ -140,7 +140,7 @@ class SecurityContext
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($resources) || empty($accesses)) {
|
||||
if ((empty($resources) && empty($modules)) || empty($accesses)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,6 +172,28 @@ class SecurityContext
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if ($module === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!array_key_exists('module', $userPermissions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$module = strtolower($module);
|
||||
|
||||
if (!array_key_exists($module, $userPermissions['module'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($accesses as $access) {
|
||||
if (!$userPermissions['module'][$module]->can($access)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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\Assets;
|
||||
|
||||
interface AssetManagerInterface {
|
||||
/**
|
||||
* Prepare an asset directory.
|
||||
*
|
||||
* @param string $source_assets_directory the full path to the source asstes directory
|
||||
* @param string $web_assets_directory_base the base directory of the web based asset directory
|
||||
* @throws \RuntimeException if something goes wrong.
|
||||
*/
|
||||
public function prepareAssets($source_assets_directory, $web_assets_directory_base);
|
||||
|
||||
/**
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection, e.g. *.less)
|
||||
*
|
||||
* @param string $web_assets_directory_base the full disk path to the base assets output directory in the web space
|
||||
* @param string $output_url the URL to the base assets output directory in the web space
|
||||
*
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
*
|
||||
* @param boolean $debug the debug mode, true or false
|
||||
*
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug);
|
||||
}
|
||||
350
core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php
Executable file
350
core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php
Executable file
@@ -0,0 +1,350 @@
|
||||
<?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\Assets;
|
||||
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\FilterManager;
|
||||
use Assetic\Filter;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\AssetWriter;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Log\Tlog;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
|
||||
/**
|
||||
* This class is a simple helper for generating assets using Assetic.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class AsseticAssetManager implements AssetManagerInterface
|
||||
{
|
||||
protected $developmentMode;
|
||||
|
||||
protected $source_file_extensions = array('less', 'js', 'coffee', 'html', 'tpl', 'htm', 'xml');
|
||||
|
||||
public function __construct($developmentMode)
|
||||
{
|
||||
$this->developmentMode = $developmentMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a stamp form the modification time of the content of the given directory and all of its subdirectories
|
||||
*
|
||||
* @param string $directory ther directory name
|
||||
* @return string the stamp of this directory
|
||||
*/
|
||||
protected function getStamp($directory)
|
||||
{
|
||||
$stamp = '';
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
$stamp .= $file->getMTime();
|
||||
}
|
||||
|
||||
return md5($stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file is a source asset file
|
||||
*
|
||||
* @param \DirectoryIterator $fileInfo
|
||||
*/
|
||||
protected function isSourceFile(\SplFileInfo $fileInfo) {
|
||||
return in_array($fileInfo->getExtension(), $this->source_file_extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively copy assets from the source directory to the destination
|
||||
* directory in the web space, ommiting source files.
|
||||
*
|
||||
* @param string $from_directory the source
|
||||
* @param string $to_directory the destination
|
||||
* @throws \RuntimeException if a problem occurs.
|
||||
*/
|
||||
protected function copyAssets(Filesystem $fs, $from_directory, $to_directory)
|
||||
{
|
||||
Tlog::getInstance()->addDebug("Copying assets from ", $from_directory, " to ", $to_directory);
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($from_directory, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
foreach ($iterator as $item) {
|
||||
if ($item->isDir()) {
|
||||
$dest_dir = $to_directory . DS . $iterator->getSubPathName();
|
||||
|
||||
if (! is_dir($dest_dir)) {
|
||||
if ($fs->exists($dest_dir)) {
|
||||
$fs->remove($dest_dir);
|
||||
}
|
||||
|
||||
$fs->mkdir($dest_dir, 0777);
|
||||
}
|
||||
}
|
||||
// We don't copy source files
|
||||
else if (! $this->isSourceFile($item)) {
|
||||
|
||||
$dest_file = $to_directory . DS . $iterator->getSubPathName();
|
||||
|
||||
if ($fs->exists($dest_file)) {
|
||||
$fs->remove($dest_file);
|
||||
}
|
||||
|
||||
$fs->copy($item, $dest_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compite the assets path relative to the base template directory
|
||||
*
|
||||
* @param string $source_assets_directory the source directory
|
||||
* @param string $web_assets_directory_base base directory of the web assets
|
||||
* @return the full path of the destination directory
|
||||
*/
|
||||
protected function getRelativeDirectoryPath($source_assets_directory, $web_assets_directory_base)
|
||||
{
|
||||
$source_assets_directory = realpath($source_assets_directory);
|
||||
|
||||
// Remove base path from asset source path to get a path relative to the template base
|
||||
// and use it to create the destination path.
|
||||
return str_replace(
|
||||
realpath(THELIA_ROOT),
|
||||
'',
|
||||
$source_assets_directory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the destination directory path, from the source directory and the
|
||||
* base directory of the web assets
|
||||
*
|
||||
* @param string $source_assets_directory the source directory
|
||||
* @param string $web_assets_directory_base base directory of the web assets
|
||||
* @return the full path of the destination directory
|
||||
*/
|
||||
protected function getDestinationDirectory($source_assets_directory, $web_assets_directory_base)
|
||||
{
|
||||
// Compute the absolute path of the output directory
|
||||
return $web_assets_directory_base . $this->getRelativeDirectoryPath($source_assets_directory, $web_assets_directory_base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an asset directory by checking that no changes occured in
|
||||
* the source directory. If any change is detected, the whole asset directory
|
||||
* is copied in the web space.
|
||||
*
|
||||
* @param string $source_assets_directory the full path to the source asstes directory
|
||||
* @param string $web_assets_directory_base the base directory of the web based asset directory
|
||||
* @throws \RuntimeException if something goes wrong.
|
||||
*/
|
||||
public function prepareAssets($source_assets_directory, $web_assets_directory_base) {
|
||||
|
||||
// Compute the absolute path of the output directory
|
||||
$to_directory = $this->getDestinationDirectory($source_assets_directory, $web_assets_directory_base);
|
||||
|
||||
// Get a path to the stamp file
|
||||
$stamp_file_path = $to_directory . DS . '.source-stamp';
|
||||
|
||||
// Get the last stamp of source assets directory
|
||||
$prev_stamp = @file_get_contents($stamp_file_path);
|
||||
|
||||
// Get the current stamp of the source directory
|
||||
$curr_stamp = $this->getStamp($source_assets_directory);
|
||||
|
||||
if ($prev_stamp !== $curr_stamp) {
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
// FIXME: locking or not locking ?
|
||||
/*
|
||||
$lock_file = "$web_assets_directory_base/assets-".md5($source_assets_directory)."-generation-lock.txt";
|
||||
|
||||
if (! $fp = fopen($lock_file, "w")) {
|
||||
throw new IOException(sprintf('Failed to open lock file %s', $lock_file));
|
||||
}
|
||||
|
||||
if (flock($fp, LOCK_EX|LOCK_NB)) { // do an exclusive lock
|
||||
*/
|
||||
$tmp_dir = "$to_directory.tmp";
|
||||
|
||||
$fs->remove($tmp_dir);
|
||||
|
||||
// Copy the whole source dir in a temp directory
|
||||
$this->copyAssets($fs, $source_assets_directory, $tmp_dir);
|
||||
|
||||
// Remove existing directory
|
||||
if ($fs->exists($to_directory)) $fs->remove($to_directory);
|
||||
|
||||
// Put in place the new directory
|
||||
$fs->rename($tmp_dir, $to_directory);
|
||||
/*
|
||||
// Release the lock
|
||||
flock($fp, LOCK_UN);
|
||||
|
||||
// Remove the lock file
|
||||
@fclose($fp);
|
||||
|
||||
$fs->remove($lock_file);
|
||||
*/
|
||||
if (false === @file_put_contents($stamp_file_path, $curr_stamp)) {
|
||||
throw new \RuntimeException(
|
||||
"Failed to create asset stamp file $stamp_file_path. Please check that your web server has the proper access rights to do that.");
|
||||
}
|
||||
/* }
|
||||
else {
|
||||
@fclose($fp);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the filters names, and initialize the Assetic FilterManager
|
||||
*
|
||||
* @param FilterManager $filterManager the Assetic filter manager
|
||||
* @param string $filters a comma separated list of filter names
|
||||
* @throws \InvalidArgumentException if a wrong filter is passed
|
||||
* @return an array of filter names
|
||||
*/
|
||||
protected function decodeAsseticFilters(FilterManager $filterManager, $filters) {
|
||||
|
||||
if (!empty($filters)) {
|
||||
|
||||
$filter_list = explode(',', $filters);
|
||||
|
||||
foreach ($filter_list as $filter_name) {
|
||||
|
||||
$filter_name = trim($filter_name);
|
||||
|
||||
switch ($filter_name) {
|
||||
case 'less':
|
||||
$filterManager->set('less', new Filter\LessphpFilter());
|
||||
break;
|
||||
|
||||
case 'sass':
|
||||
$filterManager->set('sass', new Filter\Sass\SassFilter());
|
||||
break;
|
||||
|
||||
case 'cssembed':
|
||||
$filterManager->set('cssembed', new Filter\PhpCssEmbedFilter());
|
||||
break;
|
||||
|
||||
case 'cssrewrite':
|
||||
$filterManager->set('cssrewrite', new Filter\CssRewriteFilter());
|
||||
break;
|
||||
|
||||
case 'cssimport':
|
||||
$filterManager->set('cssimport', new Filter\CssImportFilter());
|
||||
break;
|
||||
|
||||
case 'compass':
|
||||
$filterManager->set('compass', new Filter\CompassFilter());
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException("Unsupported Assetic filter: '$filter_name'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filter_list = array();
|
||||
}
|
||||
|
||||
return $filter_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection, e.g. *.less)
|
||||
*
|
||||
* @param string $web_assets_directory_base the full disk path to the base assets output directory in the web space
|
||||
* @param string $output_url the URL to the base assets output directory in the web space
|
||||
*
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
*
|
||||
* @param boolean $debug true / false
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug)
|
||||
{
|
||||
$asset_name = basename($asset_path);
|
||||
$input_directory = realpath(dirname($asset_path));
|
||||
|
||||
$am = new AssetManager();
|
||||
$fm = new FilterManager();
|
||||
|
||||
// Get the filter list
|
||||
$filter_list = $this->decodeAsseticFilters($fm, $filters);
|
||||
|
||||
// Factory setup
|
||||
$factory = new AssetFactory($input_directory);
|
||||
|
||||
$factory->setAssetManager($am);
|
||||
$factory->setFilterManager($fm);
|
||||
|
||||
$factory->setDefaultOutput('*' . (!empty($asset_type) ? '.' : '') . $asset_type);
|
||||
|
||||
$factory->setDebug($debug);
|
||||
|
||||
$asset = $factory->createAsset($asset_name, $filter_list);
|
||||
|
||||
$input_directory = realpath(dirname($asset_path));
|
||||
|
||||
$output_directory = $this->getDestinationDirectory($input_directory, $web_assets_directory_base);
|
||||
|
||||
// Get the URL part from the relative path
|
||||
$output_relative_path = $this->getRelativeDirectoryPath($input_directory, $web_assets_directory_base);
|
||||
|
||||
$output_relative_web_path = rtrim(str_replace('\\', '/', $output_relative_path), '/') . '/';
|
||||
|
||||
$asset_target_filename = $asset->getTargetPath();
|
||||
|
||||
// This is the final name of the generated asset
|
||||
$asset_destination_path = $output_directory . DS . $asset_target_filename;
|
||||
|
||||
Tlog::getInstance()->addDebug("Asset destination name: ", $asset_destination_path);
|
||||
|
||||
// We generate an asset only if it does not exists, or if the asset processing is forced in development mode
|
||||
if (! file_exists($asset_destination_path) || ($this->developmentMode && ConfigQuery::read('process_assets', true)) ) {
|
||||
|
||||
$writer = new AssetWriter($output_directory);
|
||||
|
||||
Tlog::getInstance()->addDebug("Writing asset to $output_directory");
|
||||
|
||||
$writer->writeAsset($asset);
|
||||
}
|
||||
|
||||
return rtrim($output_url, '/') . '/' . $output_relative_web_path . $asset_target_filename;
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
<?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\Assets;
|
||||
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\FilterManager;
|
||||
use Assetic\Filter;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Factory\Worker\CacheBustingWorker;
|
||||
use Assetic\AssetWriter;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* This class is a simple helper for generating assets using Assetic.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class AsseticHelper
|
||||
{
|
||||
/**
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection)
|
||||
* @param string $output_path the full disk path to the output directory (shoud be visible to web server)
|
||||
* @param string $output_url the URL to the generated asset directory
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
* @param boolean $debug true / false
|
||||
* @param boolean $dev_mode true / false. If true, assets are not cached and always compiled.
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function asseticize($asset_path, $output_path, $output_url, $asset_type, $filters, $debug, $dev_mode = false)
|
||||
{
|
||||
$asset_name = basename($asset_path);
|
||||
$asset_dir = dirname($asset_path);
|
||||
|
||||
$am = new AssetManager();
|
||||
$fm = new FilterManager();
|
||||
|
||||
if (! empty($filters)) {
|
||||
$filter_list = explode(',', $filters);
|
||||
|
||||
foreach ($filter_list as $filter_name) {
|
||||
|
||||
$filter_name = trim($filter_name);
|
||||
|
||||
switch ($filter_name) {
|
||||
case 'less' :
|
||||
$fm->set('less', new Filter\LessphpFilter());
|
||||
break;
|
||||
|
||||
case 'sass' :
|
||||
$fm->set('sass', new Filter\Sass\SassFilter());
|
||||
break;
|
||||
|
||||
case 'cssembed' :
|
||||
$fm->set('cssembed', new Filter\PhpCssEmbedFilter());
|
||||
break;
|
||||
|
||||
case 'cssrewrite':
|
||||
$fm->set('cssrewrite', new Filter\CssRewriteFilter());
|
||||
break;
|
||||
|
||||
case 'cssimport':
|
||||
$fm->set('cssimport', new Filter\CssImportFilter());
|
||||
break;
|
||||
|
||||
case 'compass':
|
||||
$fm->set('compass', new Filter\CompassFilter());
|
||||
break;
|
||||
|
||||
default :
|
||||
throw new \InvalidArgumentException("Unsupported Assetic filter: '$filter_name'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$filter_list = array();
|
||||
}
|
||||
|
||||
// Factory setup
|
||||
$factory = new AssetFactory($asset_dir);
|
||||
|
||||
$factory->setAssetManager($am);
|
||||
$factory->setFilterManager($fm);
|
||||
|
||||
$factory->setDefaultOutput('*'.(! empty($asset_type) ? '.' : '').$asset_type);
|
||||
|
||||
$factory->setDebug($debug);
|
||||
|
||||
$factory->addWorker(new CacheBustingWorker('-'));
|
||||
|
||||
// We do not pass the filter list here, juste to get the asset file name
|
||||
$asset = $factory->createAsset($asset_name);
|
||||
|
||||
$asset_target_path = $asset->getTargetPath();
|
||||
|
||||
$target_file = sprintf("%s/%s", $output_path, $asset_target_path);
|
||||
|
||||
// As it seems that assetic cannot handle a real file cache, let's do the job ourselves.
|
||||
// It works only if the CacheBustingWorker is used, as a new file name is generated for each version.
|
||||
//
|
||||
// the previous version of the file is deleted, by getting the first part of the ouput file name
|
||||
// (the one before '-'), and delete aby file beginning with the same string. Example:
|
||||
// old name: 3bc974a-dfacc1f.css
|
||||
// new name: 3bc974a-ad3ef47.css
|
||||
//
|
||||
// before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files.
|
||||
//
|
||||
if ($dev_mode == true || ! file_exists($target_file)) {
|
||||
|
||||
if (ConfigQuery::read('process_assets', true)) {
|
||||
|
||||
// Delete previous version of the file
|
||||
list($commonPart, $dummy) = explode('-', $asset_target_path);
|
||||
|
||||
foreach (glob("$output_path/$commonPart-*") as $filename) {
|
||||
@unlink($filename);
|
||||
}
|
||||
|
||||
// Apply filters now
|
||||
foreach ($filter_list as $filter) {
|
||||
if ('?' != $filter[0]) {
|
||||
$asset->ensureFilter($fm->get($filter));
|
||||
} elseif (!$debug) {
|
||||
$asset->ensureFilter($fm->get(substr($filter, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
$writer = new AssetWriter($output_path);
|
||||
|
||||
$writer->writeAsset($asset);
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($output_url, '/').'/'.$asset_target_path;
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,12 @@ class Auth extends BaseLoop implements ArraySearchLoopInterface
|
||||
new AlphaNumStringListType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'module',
|
||||
new TypeCollection(
|
||||
new AlphaNumStringListType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'access',
|
||||
new TypeCollection(
|
||||
@@ -79,10 +85,20 @@ class Auth extends BaseLoop implements ArraySearchLoopInterface
|
||||
{
|
||||
$roles = $this->getRole();
|
||||
$resource = $this->getResource();
|
||||
$module = $this->getModule();
|
||||
$access = $this->getAccess();
|
||||
|
||||
if(null !== $module) {
|
||||
$in = true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (true === $this->securityContext->isGranted($roles, $resource === null ? array() : $resource, $access === null ? array() : $access)) {
|
||||
if (true === $this->securityContext->isGranted(
|
||||
$roles,
|
||||
$resource === null ? array() : $resource,
|
||||
$module === null ? array() : $module,
|
||||
$access === null ? array() : $access)
|
||||
) {
|
||||
|
||||
// Create an empty row: loop is no longer empty :)
|
||||
$loopResult->addRow(new LoopResultRow());
|
||||
|
||||
@@ -36,6 +36,9 @@ use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\Map\OrderAddressTableMap;
|
||||
use Thelia\Model\Map\OrderTableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -65,7 +68,22 @@ class Customer extends BaseLoop implements SearchLoopInterface, PropelSearchLoop
|
||||
)
|
||||
),
|
||||
Argument::createBooleanTypeArgument('reseller'),
|
||||
Argument::createIntTypeArgument('sponsor')
|
||||
Argument::createIntTypeArgument('sponsor'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array(
|
||||
'id', 'id_reverse',
|
||||
'reference', 'reference_reverse',
|
||||
'firstname', 'firstname_reverse',
|
||||
'lastname', 'lastname_reverse',
|
||||
'last_order', 'last_order_reverse',
|
||||
'order_amount', 'order_amount_reverse',
|
||||
'registration_date', 'registration_date_reverse'
|
||||
))
|
||||
),
|
||||
'lastname'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -151,6 +169,49 @@ class Customer extends BaseLoop implements SearchLoopInterface, PropelSearchLoop
|
||||
$search->filterBySponsor($sponsor, Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case 'id':
|
||||
$search->orderById(Criteria::ASC);
|
||||
break;
|
||||
case 'id_reverse':
|
||||
$search->orderById(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'reference':
|
||||
$search->orderByRef(Criteria::ASC);
|
||||
break;
|
||||
case 'reference_reverse':
|
||||
$search->orderByRef(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'lastname':
|
||||
$search->orderByLastname(Criteria::ASC);
|
||||
break;
|
||||
case 'lastname_reverse':
|
||||
$search->orderByLastname(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'firstname':
|
||||
$search->orderByFirstname(Criteria::ASC);
|
||||
break;
|
||||
case 'firstname_reverse':
|
||||
$search->orderByFirstname(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'registration_date':
|
||||
$search->orderByCreatedAt(Criteria::ASC);
|
||||
break;
|
||||
case 'registration_date_reverse':
|
||||
$search->orderByCreatedAt(Criteria::DESC);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $search;
|
||||
|
||||
}
|
||||
@@ -158,16 +219,24 @@ class Customer extends BaseLoop implements SearchLoopInterface, PropelSearchLoop
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
foreach ($loopResult->getResultDataCollection() as $customer) {
|
||||
|
||||
$loopResultRow = new LoopResultRow($customer);
|
||||
$loopResultRow->set("ID", $customer->getId());
|
||||
$loopResultRow->set("REF", $customer->getRef());
|
||||
$loopResultRow->set("TITLE", $customer->getTitleId());
|
||||
$loopResultRow->set("FIRSTNAME", $customer->getFirstname());
|
||||
$loopResultRow->set("LASTNAME", $customer->getLastname());
|
||||
$loopResultRow->set("EMAIL", $customer->getEmail());
|
||||
$loopResultRow->set("RESELLER", $customer->getReseller());
|
||||
$loopResultRow->set("SPONSOR", $customer->getSponsor());
|
||||
$loopResultRow->set("DISCOUNT", $customer->getDiscount());
|
||||
|
||||
$loopResultRow
|
||||
->set("ID" , $customer->getId())
|
||||
->set("REF" , $customer->getRef())
|
||||
->set("TITLE" , $customer->getTitleId())
|
||||
->set("FIRSTNAME" , $customer->getFirstname())
|
||||
->set("LASTNAME" , $customer->getLastname())
|
||||
->set("EMAIL" , $customer->getEmail())
|
||||
->set("RESELLER" , $customer->getReseller())
|
||||
->set("SPONSOR" , $customer->getSponsor())
|
||||
->set("DISCOUNT" , $customer->getDiscount())
|
||||
|
||||
->set("LAST_ORDER_DATE" , $lastOrder != null ? $lastOrder->getCreatedAt() : '')
|
||||
->set("LAST_ORDER_AMOUNT" , $lastOrder != null ? $lastOrder->getCreatedAt() : '')
|
||||
->set("LAST_ORDER_CURRENCY" , $lastOrder != null ? $lastOrder->getCreatedAt() : '')
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -25,32 +25,44 @@ namespace Thelia\Core\Template\Smarty\Assets;
|
||||
|
||||
use Thelia\Core\Template\Assets\AsseticHelper;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Template\Assets\AssetManagerInterface;
|
||||
|
||||
class SmartyAssetsManager
|
||||
{
|
||||
const ASSET_TYPE_AUTO = '';
|
||||
|
||||
private $assetic_manager;
|
||||
private $assetsManager;
|
||||
|
||||
private $web_root;
|
||||
private $path_relative_to_web_root;
|
||||
private $developmentMode;
|
||||
|
||||
/**
|
||||
* Creates a new SmartyAssetsManager instance
|
||||
*
|
||||
* @param string $web_root the disk path to the web root
|
||||
* @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated
|
||||
* @param boolean $developmentMode true / false. If true, assets are not cached, and always generated.
|
||||
* @param AssetManagerInterface $assetsManager an asset manager instance
|
||||
* @param string $web_root the disk path to the web root (with final /)
|
||||
* @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated
|
||||
*/
|
||||
public function __construct($web_root, $path_relative_to_web_root, $developmentMode)
|
||||
public function __construct(AssetManagerInterface $assetsManager, $web_root, $path_relative_to_web_root)
|
||||
{
|
||||
$this->web_root = $web_root;
|
||||
$this->path_relative_to_web_root = $path_relative_to_web_root;
|
||||
|
||||
$this->developmentMode = $developmentMode;
|
||||
$this->assetsManager = $assetsManager;
|
||||
}
|
||||
|
||||
$this->assetic_manager = new AsseticHelper();
|
||||
public function prepareAssets($assets_directory, \Smarty_Internal_Template $template) {
|
||||
|
||||
$tpl_dir = dirname($template->source->filepath);
|
||||
|
||||
$asset_dir_absolute_path = realpath($tpl_dir . DS . $assets_directory);
|
||||
|
||||
if ($asset_dir_absolute_path === false) throw new \Exception("Failed to get real path of '".$tpl_dir . DS . $assets_directory."'");
|
||||
|
||||
$this->assetsManager->prepareAssets(
|
||||
$asset_dir_absolute_path,
|
||||
$this->web_root . $this->path_relative_to_web_root
|
||||
);
|
||||
}
|
||||
|
||||
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template)
|
||||
@@ -66,19 +78,18 @@ class SmartyAssetsManager
|
||||
$tpl_dir = dirname($tpl_path);
|
||||
|
||||
// Create absolute dir path
|
||||
$asset_dir = realpath($tpl_dir.'/'.dirname($file));
|
||||
$asset_dir = realpath($tpl_dir) . DS . dirname($file);
|
||||
$asset_file = basename($file);
|
||||
|
||||
if ($asset_dir === false) throw new \Exception("Failed to get real path of '".$tpl_dir.'/'.dirname($file)."'");
|
||||
|
||||
$url = $this->assetic_manager->asseticize(
|
||||
$asset_dir.'/'.$asset_file,
|
||||
$this->web_root."/".$this->path_relative_to_web_root,
|
||||
$url = $this->assetsManager->processAsset(
|
||||
$asset_dir . DS . $asset_file,
|
||||
$this->web_root . $this->path_relative_to_web_root,
|
||||
URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
|
||||
$assetType,
|
||||
$filters,
|
||||
$debug,
|
||||
$this->developmentMode
|
||||
$debug
|
||||
);
|
||||
|
||||
return $url;
|
||||
|
||||
@@ -69,6 +69,7 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
{
|
||||
// The required permissions
|
||||
$resource = $this->getParam($params, 'resource');
|
||||
$module = $this->getParam($params, 'module');
|
||||
$access = $this->getParam($params, 'access');
|
||||
|
||||
// The base position change path
|
||||
@@ -92,7 +93,12 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
<a href="{url path='/admin/configuration/currencies/positionDown' currency_id=$ID}"><i class="icon-arrow-down"></i></a>
|
||||
*/
|
||||
|
||||
if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($resource), array($access))) {
|
||||
if ($permissions == null || $this->securityContext->isGranted(
|
||||
"ADMIN",
|
||||
$resource === null ? array() : array($resource),
|
||||
$module === null ? array() : array($module),
|
||||
array($access))
|
||||
) {
|
||||
|
||||
return $this->fetch_snippet($smarty, 'includes/admin-utilities-position-block', array(
|
||||
'admin_utilities_go_up_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)),
|
||||
|
||||
@@ -27,18 +27,29 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\Assets\AssetManagerInterface;
|
||||
|
||||
class Assetic extends AbstractSmartyPlugin
|
||||
class Assets extends AbstractSmartyPlugin
|
||||
{
|
||||
public $assetManager;
|
||||
|
||||
public function __construct($developmentMode)
|
||||
public function __construct(AssetManagerInterface $assetsManager)
|
||||
{
|
||||
$web_root = THELIA_WEB_DIR;
|
||||
$asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets');
|
||||
|
||||
$asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets/');
|
||||
$this->assetManager = new SmartyAssetsManager($assetsManager, THELIA_WEB_DIR, $asset_dir_from_web_root);
|
||||
}
|
||||
|
||||
$this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root, $developmentMode == 'dev');
|
||||
public function declareAssets($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
if (false !== $asset_dir = $this->getParam($params, 'directory', false)) {
|
||||
|
||||
$this->assetManager->prepareAssets($asset_dir, $template);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('declare_assets: parameter "directory" is required');
|
||||
}
|
||||
|
||||
public function blockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
@@ -79,10 +90,11 @@ class Assetic extends AbstractSmartyPlugin
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('block' , 'stylesheets', $this, 'blockStylesheets'),
|
||||
new SmartyPluginDescriptor('block' , 'javascripts', $this, 'blockJavascripts'),
|
||||
new SmartyPluginDescriptor('block' , 'images' , $this, 'blockImages'),
|
||||
new SmartyPluginDescriptor('function', 'image' , $this, 'functionImage')
|
||||
new SmartyPluginDescriptor('block' , 'stylesheets' , $this, 'blockStylesheets'),
|
||||
new SmartyPluginDescriptor('block' , 'javascripts' , $this, 'blockJavascripts'),
|
||||
new SmartyPluginDescriptor('block' , 'images' , $this, 'blockImages'),
|
||||
new SmartyPluginDescriptor('function', 'image' , $this, 'functionImage'),
|
||||
new SmartyPluginDescriptor('function', 'declare_assets' , $this, 'declareAssets')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,10 @@ class Security extends AbstractSmartyPlugin
|
||||
{
|
||||
$roles = $this->_explode($this->getParam($params, 'role'));
|
||||
$resources = $this->_explode($this->getParam($params, 'resource'));
|
||||
$modules = $this->_explode($this->getParam($params, 'module'));
|
||||
$accesses = $this->_explode($this->getParam($params, 'access'));
|
||||
|
||||
if (! $this->securityContext->isGranted($roles, $resources, $accesses)) {
|
||||
if (! $this->securityContext->isGranted($roles, $resources, $modules, $accesses)) {
|
||||
|
||||
$ex = new AuthenticationException(
|
||||
sprintf("User not granted for roles '%s', to access resources '%s' with %s in context '%s'.",
|
||||
|
||||
Reference in New Issue
Block a user