Implementing translations (still in progress)
This commit is contained in:
@@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -55,7 +56,7 @@ class HttpException extends BaseAction implements EventSubscriberInterface
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
$parser->setTemplate(ConfigQuery::getActiveTemplate());
|
||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
||||
|
||||
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Propel\Runtime\Propel;
|
||||
|
||||
class Product extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
@@ -257,21 +259,37 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
public function setProductTemplate(ProductSetTemplateEvent $event)
|
||||
{
|
||||
$product = $event->getProduct();
|
||||
|
||||
// Delete all product feature relations
|
||||
FeatureProductQuery::create()->filterByProduct($product)->delete();
|
||||
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
|
||||
|
||||
// Delete all product attributes sale elements
|
||||
ProductSaleElementsQuery::create()->filterByProduct($product)->delete();
|
||||
$con->beginTransaction();
|
||||
|
||||
// Update the product template
|
||||
$template_id = $event->getTemplateId();
|
||||
try {
|
||||
|
||||
// Set it to null if it's zero.
|
||||
if ($template_id <= 0) $template_id = NULL;
|
||||
$product = $event->getProduct();
|
||||
|
||||
$product->setTemplateId($template_id)->save();
|
||||
// Delete all product feature relations
|
||||
FeatureProductQuery::create()->filterByProduct($product)->delete($con);
|
||||
|
||||
// Delete all product attributes sale elements
|
||||
ProductSaleElementsQuery::create()->filterByProduct($product)->delete($con);
|
||||
|
||||
// Update the product template
|
||||
$template_id = $event->getTemplateId();
|
||||
|
||||
// Set it to null if it's zero.
|
||||
if ($template_id <= 0) $template_id = NULL;
|
||||
|
||||
$product->setTemplateId($template_id)->save($con);
|
||||
|
||||
// Store all the stuff !
|
||||
$con->commit();
|
||||
} catch (\Exception $ex) {
|
||||
|
||||
$con->rollback();
|
||||
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Message" name="message"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Delivery" name="delivery"/>
|
||||
<loop class="Thelia\Core\Template\Loop\ProductTemplate" name="product-template"/> <!-- This is product templates ;-) -->
|
||||
<loop class="Thelia\Core\Template\Loop\Template" name="template"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Tax" name="tax"/>
|
||||
<loop class="Thelia\Core\Template\Loop\TaxRule" name="tax-rule"/>
|
||||
<loop class="Thelia\Core\Template\Loop\TaxRuleCountry" name="tax-rule-country"/>
|
||||
|
||||
@@ -1040,6 +1040,16 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::deactivateDomainAction</default>
|
||||
</route>
|
||||
|
||||
<!-- translations management -->
|
||||
|
||||
<route id="admin.configuration.translations" path="/admin/configuration/translations">
|
||||
<default key="_controller">Thelia\Controller\Admin\TranslationsController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.translations.update" path="/admin/configuration/translations/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\TranslationsController::updateAction</default>
|
||||
</route>
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
<route id="admin.processTemplate" path="/admin/{template}">
|
||||
|
||||
@@ -43,6 +43,7 @@ use Symfony\Component\Routing\Router;
|
||||
use Thelia\Model\Admin;
|
||||
use Thelia\Core\Security\Token\CookieTokenProvider;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
class BaseAdminController extends BaseController
|
||||
{
|
||||
@@ -199,7 +200,7 @@ class BaseAdminController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
$parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default'));
|
||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ use Thelia\Model\Base\OrderAddressQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
/**
|
||||
* Class OrderController
|
||||
@@ -218,7 +219,7 @@ class OrderController extends BaseAdminController
|
||||
array(
|
||||
'order_id' => $order_id
|
||||
),
|
||||
ConfigQuery::read('pdf_template', 'pdf')
|
||||
TemplateHelper::getInstance()->getActivePdfTemplate()->getPath()
|
||||
);
|
||||
|
||||
$order = OrderQuery::create()->findPk($order_id);
|
||||
|
||||
@@ -66,6 +66,7 @@ use Thelia\Model\Product;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\ProductCombinationGenerationForm;
|
||||
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
|
||||
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
|
||||
194
core/lib/Thelia/Controller/Admin/TranslationsController.php
Normal file
194
core/lib/Thelia/Controller/Admin/TranslationsController.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?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\Controller\Admin;
|
||||
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Form\SystemLogConfigurationForm;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
/**
|
||||
* Class LangController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class TranslationsController extends BaseAdminController
|
||||
{
|
||||
protected function renderTemplate()
|
||||
{
|
||||
|
||||
// Find modules
|
||||
$modules = ModuleQuery::create()->joinI18n($this->getCurrentEditionLocale())->orderByPosition()->find();
|
||||
|
||||
TemplateHelper::getInstance()->getList(TemplateDefinition::BACK_OFFICE);
|
||||
TemplateHelper::getInstance()->getList(TemplateDefinition::PDF);
|
||||
TemplateHelper::getInstance()->getList(TemplateDefinition::FRONT_OFFICE);
|
||||
|
||||
// Get related strings, if all input data are here
|
||||
$item_to_translate = $this->getRequest()->get('item_to_translate');
|
||||
|
||||
$item_id = $this->getRequest()->get('item_id', '');
|
||||
|
||||
$all_strings = $translated_strings = array();
|
||||
|
||||
$template = $directory = $i18n_directory = false;
|
||||
|
||||
if (! empty($item_id)) {
|
||||
|
||||
switch($item_to_translate) {
|
||||
|
||||
case 'mo' :
|
||||
if (null !== $module = ModuleQuery::create()->findPk($item_id)) {
|
||||
$directory = THELIA_MODULE_DIR . $module->getBaseDir();
|
||||
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'fo' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::FRONT_OFFICE);
|
||||
break;
|
||||
|
||||
case 'bo' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::BACK_OFFICE);
|
||||
break;
|
||||
|
||||
case 'pf' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::PDF);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($template) {
|
||||
$directory = THELIA_TEMPLATE_DIR . $template->getPath();
|
||||
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath();
|
||||
}
|
||||
|
||||
if ($directory) {
|
||||
|
||||
// Load strings
|
||||
$this->walkDir($directory, $all_strings);
|
||||
|
||||
// Load translated strings
|
||||
if ($i18n_directory) {
|
||||
$locale = $this->getCurrentEditionLocale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('translations', array(
|
||||
'item_to_translate' => $item_to_translate,
|
||||
'item_id' => $item_id,
|
||||
'all_strings' => $all_strings,
|
||||
'translated_strings' => $translated_strings,
|
||||
'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0)
|
||||
));
|
||||
}
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::TRANSLATIONS, AccessManager::VIEW)) return $response;
|
||||
|
||||
return $this->renderTemplate();
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
|
||||
|
||||
return $this->renderTemplate();
|
||||
}
|
||||
|
||||
protected function normalize_path($path)
|
||||
{
|
||||
$path =
|
||||
str_replace(
|
||||
str_replace('\\', '/', THELIA_ROOT),
|
||||
'',
|
||||
str_replace('\\', '/', realpath($path))
|
||||
);
|
||||
|
||||
if ($path[0] == '/') $path = substr($path, 1);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
protected function walkDir($directory, &$strings) {
|
||||
try {
|
||||
//echo "walking in $directory<br />";
|
||||
|
||||
foreach (new \DirectoryIterator($directory) as $fileInfo) {
|
||||
|
||||
if ($fileInfo->isDot()) continue;
|
||||
|
||||
if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $strings);
|
||||
|
||||
if ($fileInfo->isFile()) {
|
||||
|
||||
$ext = $fileInfo->getExtension();
|
||||
|
||||
if ($ext == 'html' || $ext == 'tpl' || $ext == 'xml') {
|
||||
|
||||
if ($content = file_get_contents($fileInfo->getPathName())) {
|
||||
|
||||
$short_path = $this->normalize_path($fileInfo->getPathName());
|
||||
|
||||
// echo " examining $short_path\n";
|
||||
|
||||
$matches = array();
|
||||
|
||||
if (preg_match_all('/{intl[\s]l=((?<![\\\\])[\'"])((?:.(?!(?<![\\\\])\1))*.?)\1/', $content, $matches)) {
|
||||
|
||||
// print_r($matches[2]);
|
||||
|
||||
foreach($matches[2] as $match) {
|
||||
|
||||
$hash = md5($match);
|
||||
|
||||
if (isset($strings[$hash]))
|
||||
{
|
||||
if (! in_array($short_path, $strings[$hash]['files']))
|
||||
{
|
||||
$strings[$hash]['files'][] = $short_path;
|
||||
}
|
||||
}
|
||||
else
|
||||
$strings[$hash] = array(
|
||||
'files' => array($short_path),
|
||||
'chaine' => $match,
|
||||
'dollar' => strstr($match, '$') !== false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\UnexpectedValueException $ex) {
|
||||
echo $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,26 +67,26 @@ class RegisterRouterPass implements CompilerPassInterface
|
||||
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$moduleCode = ucfirst($module->getCode());
|
||||
if (file_exists(THELIA_MODULE_DIR . "/" . $moduleCode . "/Config/routing.xml")) {
|
||||
$moduleBaseDir = $module->getBaseDir();
|
||||
if (file_exists(THELIA_MODULE_DIR . "/" . $moduleBaseDir . "/Config/routing.xml")) {
|
||||
$definition = new Definition(
|
||||
$container->getParameter("router.class"),
|
||||
array(
|
||||
new Reference("router.module.xmlLoader"),
|
||||
ucfirst($module->getCode()) . "/Config/routing.xml",
|
||||
$moduleBaseDir . "/Config/routing.xml",
|
||||
array(
|
||||
"cache_dir" => $container->getParameter("kernel.cache_dir"),
|
||||
"debug" => $container->getParameter("kernel.debug"),
|
||||
"matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleCode),
|
||||
"generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleCode),
|
||||
"matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleBaseDir),
|
||||
"generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleBaseDir),
|
||||
),
|
||||
new Reference("request.context")
|
||||
)
|
||||
);
|
||||
|
||||
$container->setDefinition("router.".$moduleCode, $definition);
|
||||
$container->setDefinition("router.".$moduleBaseDir, $definition);
|
||||
|
||||
$chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), 150));
|
||||
$chainRouter->addMethodCall("add", array(new Reference("router.".$moduleBaseDir), 150));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,4 +99,6 @@ final class AdminResources
|
||||
const TEMPLATE = "admin.configuration.template";
|
||||
|
||||
const SYSTEM_LOG = "admin.configuration.system-log";
|
||||
|
||||
const TRANSLATIONS = "admin.configuration.translations";
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
@@ -31,29 +32,39 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Base\TemplateQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
use Thelia\Module\BaseModule;
|
||||
use Thelia\Type;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
|
||||
/**
|
||||
*
|
||||
* Template loop
|
||||
* Template loop, to get available back-office or front-office templates.
|
||||
*
|
||||
*
|
||||
* Class Template
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Template extends BaseI18nLoop
|
||||
{
|
||||
public $timestampable = true;
|
||||
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
new Argument(
|
||||
'template_type',
|
||||
new Type\TypeCollection(
|
||||
new Type\EnumListType(array(
|
||||
'front-office',
|
||||
'back-office',
|
||||
'pdf'
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,40 +75,27 @@ class Template extends BaseI18nLoop
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = TemplateQuery::create();
|
||||
$type = $this->getArg(template_type);
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
if ($type == 'front-office')
|
||||
$templateType = TemplateDefinition::FRONT_OFFICE;
|
||||
else if ($type == 'back-office')
|
||||
$templateType = TemplateDefinition::BACK_OFFICE;
|
||||
else if ($type == 'pdf')
|
||||
$templateType = TemplateDefinition::PDF;
|
||||
|
||||
$lang = $this->getLang();
|
||||
$templates = TemplateHelper::getInstance()->getList($templateType);
|
||||
|
||||
/* manage translations */
|
||||
$locale = $this->configureI18nProcessing($search, $columns = array('NAME'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (null !== $id) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (null !== $exclude) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
/* perform search */
|
||||
$templates = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($templates);
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($templates as $template) {
|
||||
$loopResultRow = new LoopResultRow($loopResult, $template, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$loopResultRow = new LoopResultRow($loopResult);
|
||||
|
||||
$loopResultRow
|
||||
->set("ID", $template->getId())
|
||||
->set("IS_TRANSLATED" , $template->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE" , $locale)
|
||||
->set("NAME" , $template->getVirtualColumn('i18n_NAME'))
|
||||
->set("NAME" , $template->getName())
|
||||
->set("RELATIVE_PATH" , $template->getPath())
|
||||
->set("ABSOLUTE_PATH" , THELIA_TEMPLATE_DIR . $template->getPath())
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
@@ -105,4 +103,4 @@ class Template extends BaseI18nLoop
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ use Thelia\Tools\URL;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Model\Config;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
/**
|
||||
* This class implements variour admin template utilities
|
||||
@@ -50,7 +51,7 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
|
||||
$snippet_path = sprintf('%s/%s/%s.html',
|
||||
THELIA_TEMPLATE_DIR,
|
||||
ConfigQuery::read('base-admin-template', 'admin/default'),
|
||||
TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath(),
|
||||
$templateName
|
||||
);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class Module extends AbstractSmartyPlugin
|
||||
|
||||
foreach ($modules as $module) {
|
||||
|
||||
$file = sprintf("%s/%s/AdminIncludes/%s.html", THELIA_MODULE_DIR, ucfirst($module->getCode()), $location);
|
||||
$file = sprintf("%s/%s/AdminIncludes/%s.html", THELIA_MODULE_DIR, $module->getBaseDir(), $location);
|
||||
|
||||
if (file_exists($file)) {
|
||||
$content .= file_get_contents($file);
|
||||
|
||||
@@ -14,6 +14,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -62,7 +63,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
$this->setCompileDir($compile_dir);
|
||||
$this->setCacheDir($cache_dir);
|
||||
|
||||
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
||||
$this->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
||||
|
||||
$this->debugging = $debug;
|
||||
|
||||
|
||||
102
core/lib/Thelia/Core/Template/TemplateDefinition.php
Normal file
102
core/lib/Thelia/Core/Template/TemplateDefinition.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class TemplateDefinition
|
||||
{
|
||||
const FRONT_OFFICE = 1;
|
||||
const BACK_OFFICE = 2;
|
||||
const PDF = 3;
|
||||
|
||||
const BACK_OFFICE_SUBDIR = 'admin/';
|
||||
const PDF_SUBDIR = 'pdf/';
|
||||
|
||||
/**
|
||||
* @var the template directory name (e.g. 'default')
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var the template directory full path
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var the template type (front, back, pdf)
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
|
||||
public function __construct($name, $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
||||
if ($type == self::BACK_OFFICE)
|
||||
$this->path = self::BACK_OFFICE_SUBDIR . $name;
|
||||
else if ($type == self::PDF)
|
||||
$this->path = self::PDF_SUBDIR . $name;
|
||||
else
|
||||
$this->path = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getI18nPath() {
|
||||
return $this->getPath() . DS . 'I18n';
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
96
core/lib/Thelia/Core/Template/TemplateHelper.php
Normal file
96
core/lib/Thelia/Core/Template/TemplateHelper.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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;
|
||||
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class TemplateHelper
|
||||
{
|
||||
/**
|
||||
* This is a singleton
|
||||
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) self::$instance = new TemplateHelper();
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getActivePdfTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-pdf-template', 'default'),
|
||||
TemplateDefinition::PDF
|
||||
);
|
||||
}
|
||||
|
||||
public function getActiveAdminTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-admin-template', 'default'),
|
||||
TemplateDefinition::BACK_OFFICE
|
||||
);
|
||||
}
|
||||
|
||||
public function getActiveFrontTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-admin-template', 'default'),
|
||||
TemplateDefinition::FRONT_OFFICE
|
||||
);
|
||||
}
|
||||
|
||||
public function getList($templateType) {
|
||||
|
||||
$list = $exclude = array();
|
||||
|
||||
if ($templateType == TemplateDefinition::BACK_OFFICE) {
|
||||
$baseDir = THELIA_TEMPLATE_DIR.TemplateDefinition::BACK_OFFICE_SUBDIR;
|
||||
}
|
||||
else if ($templateType == TemplateDefinition::PDF) {
|
||||
$baseDir = THELIA_TEMPLATE_DIR.TemplateDefinition::PDF_SUBDIR;
|
||||
}
|
||||
else {
|
||||
$baseDir = THELIA_TEMPLATE_DIR;
|
||||
|
||||
$exclude = array(TemplateDefinition::BACK_OFFICE_SUBDIR, TemplateDefinition::PDF_SUBDIR);
|
||||
}
|
||||
|
||||
// Every subdir of the basedir is supposed to be a template.
|
||||
$di = new \DirectoryIterator($baseDir);
|
||||
|
||||
foreach ($di as $file) {
|
||||
// Ignore 'dot' elements
|
||||
if ($file->isDot() || ! $file->isDir()) continue;
|
||||
|
||||
// Ignore reserved directory names
|
||||
if (in_array($file->getFilename()."/", $exclude)) continue;
|
||||
|
||||
$list[] = new TemplateDefinition($file->getFilename(), $templateType);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ use Symfony\Component\Config\FileLocator;
|
||||
|
||||
use Propel\Runtime\Propel;
|
||||
use Propel\Runtime\Connection\ConnectionManagerSingle;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
class Thelia extends Kernel
|
||||
{
|
||||
@@ -138,10 +139,10 @@ class Thelia extends Kernel
|
||||
$defintion
|
||||
);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
|
||||
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . $module->getConfigPath()));
|
||||
$loader->load("config.xml");
|
||||
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) {
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . $module->getI18nPath())) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -149,18 +150,22 @@ class Thelia extends Kernel
|
||||
}
|
||||
}
|
||||
|
||||
//Load translation from templates
|
||||
// Load translation from templates
|
||||
//core translation
|
||||
$dirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
|
||||
$dirs[] = THELIA_ROOT . "core/lib/Thelia/Config/I18n";
|
||||
|
||||
//admin template
|
||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
|
||||
// admin template
|
||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveAdminTemplate()->getI18nPath())) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
|
||||
//front template
|
||||
$template = ConfigQuery::getActiveTemplate();
|
||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
|
||||
// front template
|
||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveFrontTemplate()->getI18nPath())) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
|
||||
// PDF template
|
||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActivePdfTemplate()->getI18nPath())) {
|
||||
$dirs[] = $dir;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,12 +82,6 @@ class ConfigQuery extends BaseConfigQuery {
|
||||
return self::read('passed_url_view', 'passed-url');
|
||||
}
|
||||
|
||||
|
||||
public static function getActiveTemplate()
|
||||
{
|
||||
return self::read('active-template', 'default');
|
||||
}
|
||||
|
||||
public static function useTaxFreeAmounts()
|
||||
{
|
||||
return self::read('use_tax_free_amounts', 'default') == 1;
|
||||
|
||||
@@ -166,7 +166,7 @@ class ConfigTableMap extends TableMap
|
||||
// columns
|
||||
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
|
||||
$this->addColumn('NAME', 'Name', 'VARCHAR', true, 255, null);
|
||||
$this->addColumn('VALUE', 'Value', 'VARCHAR', true, 255, null);
|
||||
$this->addColumn('VALUE', 'Value', 'LONGVARCHAR', true, null, null);
|
||||
$this->addColumn('SECURED', 'Secured', 'TINYINT', true, null, 1);
|
||||
$this->addColumn('HIDDEN', 'Hidden', 'TINYINT', true, null, 1);
|
||||
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
|
||||
|
||||
@@ -11,4 +11,25 @@ class Module extends BaseModule {
|
||||
{
|
||||
ModuleQuery::resetActivated();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's base directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getBaseDir() {
|
||||
return ucfirst($this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's config directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getConfigPath() {
|
||||
return $this->getBaseDir() . DS . "Config";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module's i18N directory path, relative to THELIA_MODULE_DIR
|
||||
*/
|
||||
public function getI18nPath() {
|
||||
return $this->getBaseDir() . DS . "I18n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user