// Rename Module->smartyAssign to Module->templateAssign

[+] Front: Add module controller + url dispatch for modules
This commit is contained in:
rMalie committed 2011-09-23 13:50:33 +00:00
1 parent 3c215168ac
commit dc957d3d3a
21 files changed
+190 -120

No files matched your search

+15 -14
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -59,7 +59,7 @@ class AdminMeta extends AdminTab
'fields' => array(), 'fields' => array(),
), ),
); );
// Display route options only if friendly URL is activated // Display route options only if friendly URL is activated
if (Configuration::get('PS_REWRITING_SETTINGS')) if (Configuration::get('PS_REWRITING_SETTINGS'))
{ {
@@ -69,9 +69,10 @@ class AdminMeta extends AdminTab
$this->addFieldRoute('manufacturer_rule', $this->l('Route to manufacturer')); $this->addFieldRoute('manufacturer_rule', $this->l('Route to manufacturer'));
$this->addFieldRoute('cms_rule', $this->l('Route to CMS page')); $this->addFieldRoute('cms_rule', $this->l('Route to CMS page'));
$this->addFieldRoute('cms_category_rule', $this->l('Route to CMS category')); $this->addFieldRoute('cms_category_rule', $this->l('Route to CMS category'));
$this->addFieldRoute('module', $this->l('Route to modules'));
} }
} }
public function addFieldRoute($routeID, $title) public function addFieldRoute($routeID, $title)
{ {
$keywords = array(); $keywords = array();
@@ -91,7 +92,7 @@ class AdminMeta extends AdminTab
public function displayForm($isMainTab = true) public function displayForm($isMainTab = true)
{ {
parent::displayForm(); parent::displayForm();
if (!($meta = $this->loadObject(true))) if (!($meta = $this->loadObject(true)))
return; return;
$files = Meta::getPages(true, ($meta->page ? $meta->page : false)); $files = Meta::getPages(true, ($meta->page ? $meta->page : false));
@@ -174,7 +175,7 @@ class AdminMeta extends AdminTab
</fieldset> </fieldset>
</form>'; </form>';
} }
public function postProcess() public function postProcess()
{ {
if (Tools::isSubmit('submitAddmeta')) if (Tools::isSubmit('submitAddmeta'))
@@ -210,18 +211,18 @@ class AdminMeta extends AdminTab
} }
Module::hookExec('afterSaveAdminMeta'); Module::hookExec('afterSaveAdminMeta');
} }
return parent::postProcess(); return parent::postProcess();
} }
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false)
{ {
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID(true)); parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID(true));
} }
/** /**
* Validate route syntax and save it in configuration * Validate route syntax and save it in configuration
* *
* @param string $routeID * @param string $routeID
*/ */
public function checkAndUpdateRoute($routeID) public function checkAndUpdateRoute($routeID)
@@ -229,7 +230,7 @@ class AdminMeta extends AdminTab
$default_routes = Dispatcher::getInstance()->default_routes; $default_routes = Dispatcher::getInstance()->default_routes;
if (!isset($default_routes[$routeID])) if (!isset($default_routes[$routeID]))
return ; return ;
$rule = Tools::getValue('PS_ROUTE_'.$routeID); $rule = Tools::getValue('PS_ROUTE_'.$routeID);
if (!$rule || $rule == $default_routes[$routeID]['rule']) if (!$rule || $rule == $default_routes[$routeID]['rule'])
{ {
@@ -256,22 +257,22 @@ class AdminMeta extends AdminTab
{ {
$this->checkAndUpdateRoute('category_rule'); $this->checkAndUpdateRoute('category_rule');
} }
public function updateOptionPsRouteSupplierRule() public function updateOptionPsRouteSupplierRule()
{ {
$this->checkAndUpdateRoute('supplier_rule'); $this->checkAndUpdateRoute('supplier_rule');
} }
public function updateOptionPsRouteManufacturerRule() public function updateOptionPsRouteManufacturerRule()
{ {
$this->checkAndUpdateRoute('manufacturer_rule'); $this->checkAndUpdateRoute('manufacturer_rule');
} }
public function updateOptionPsRouteCmsRule() public function updateOptionPsRouteCmsRule()
{ {
$this->checkAndUpdateRoute('cms_rule'); $this->checkAndUpdateRoute('cms_rule');
} }
public function updateOptionPsRouteCmsCategoryRule() public function updateOptionPsRouteCmsCategoryRule()
{ {
$this->checkAndUpdateRoute('cms_category_rule'); $this->checkAndUpdateRoute('cms_category_rule');
+2
View File
@@ -315,6 +315,8 @@
'IndexController' => 'override/controllers/front/IndexController.php', 'IndexController' => 'override/controllers/front/IndexController.php',
'ManufacturerControllerCore' => 'controllers/front/ManufacturerController.php', 'ManufacturerControllerCore' => 'controllers/front/ManufacturerController.php',
'ManufacturerController' => 'override/controllers/front/ManufacturerController.php', 'ManufacturerController' => 'override/controllers/front/ManufacturerController.php',
'ModuleControllerCore' => 'controllers/front/ModuleController.php',
'ModuleController' => 'override/controllers/front/ModuleController.php',
'MyAccountControllerCore' => 'controllers/front/MyAccountController.php', 'MyAccountControllerCore' => 'controllers/front/MyAccountController.php',
'MyAccountController' => 'override/controllers/front/MyAccountController.php', 'MyAccountController' => 'override/controllers/front/MyAccountController.php',
'NewProductsControllerCore' => 'controllers/front/NewProductsController.php', 'NewProductsControllerCore' => 'controllers/front/NewProductsController.php',
+8
View File
@@ -108,6 +108,14 @@ class DispatcherCore
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'), 'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
), ),
), ),
'module' => array(
'controller' => 'module',
'rule' => 'module/{name}/{action}',
'keywords' => array(
'name' => array('regexp' => '[a-zA-Z0-9_-]+', 'param' => 'module'),
'action' => array('regexp' => '[a-zA-Z0-9_-]+', 'param' => 'action'),
),
),
); );
/** /**
+1 -1
View File
@@ -25,7 +25,7 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
class FrontControllerCore extends ControllerCore class FrontControllerCore extends Controller
{ {
public $errors = array(); public $errors = array();
+45 -21
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -31,7 +31,7 @@ class LinkCore
protected $allow; protected $allow;
protected $url; protected $url;
public static $cache = array('page' => array()); public static $cache = array('page' => array());
public $protocol_link; public $protocol_link;
public $protocol_content; public $protocol_content;
@@ -74,7 +74,7 @@ class LinkCore
{ {
$dispatcher = Dispatcher::getInstance(); $dispatcher = Dispatcher::getInstance();
$url = _PS_BASE_URL_.__PS_BASE_URI__; $url = _PS_BASE_URL_.__PS_BASE_URI__;
if (!$id_lang) if (!$id_lang)
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
@@ -97,10 +97,10 @@ class LinkCore
if ($dispatcher->hasKeyword('product_rule', 'manufacturer')) if ($dispatcher->hasKeyword('product_rule', 'manufacturer'))
$params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer)); $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
if ($dispatcher->hasKeyword('product_rule', 'supplier')) if ($dispatcher->hasKeyword('product_rule', 'supplier'))
$params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier)); $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
if ($dispatcher->hasKeyword('product_rule', 'price')) if ($dispatcher->hasKeyword('product_rule', 'price'))
$params['supplier'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $product->specificPrice); $params['supplier'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $product->specificPrice);
@@ -118,7 +118,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getCategoryLink($category, $alias = NULL, $id_lang = NULL) public function getCategoryLink($category, $alias = null, $id_lang = null)
{ {
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -145,7 +145,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getCMSCategoryLink($category, $alias = NULL, $id_lang = NULL) public function getCMSCategoryLink($category, $alias = null, $id_lang = null)
{ {
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -173,7 +173,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL) public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null)
{ {
$base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true)); $base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
@@ -201,7 +201,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getSupplierLink($supplier, $alias = NULL, $id_lang = NULL) public function getSupplierLink($supplier, $alias = null, $id_lang = null)
{ {
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -228,7 +228,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getManufacturerLink($manufacturer, $alias = NULL, $id_lang = NULL) public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null)
{ {
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -247,18 +247,42 @@ class LinkCore
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $params, $this->allow); return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $params, $this->allow);
} }
/**
* Create a link to a supplier
*
* @since 1.5.0
* @param string $name Module name
* @param string $action Action name
* @param int $id_lang
* @return string
*/
public function getModuleLink($name, $action, $ssl = false, $id_lang = null)
{
$base = (($ssl && Configuration::get('PS_SSL_ENABLED')) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_);
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
// Set available keywords
$params = array();
$params['name'] = $name;
$params['action'] = $action;
return $url.Dispatcher::getInstance()->createUrl('module', $params, $this->allow);
}
/** /**
* Returns a link to a product image for display * Returns a link to a product image for display
* Note: the new image filesystem stores product images in subdirectories of img/p/ * Note: the new image filesystem stores product images in subdirectories of img/p/
* *
* @param string $name rewrite link of the image * @param string $name rewrite link of the image
* @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new) * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
* @param string $type * @param string $type
*/ */
public function getImageLink($name, $ids, $type = NULL) public function getImageLink($name, $ids, $type = null)
{ {
// legacy mode or default image // legacy mode or default image
if ((Configuration::get('PS_LEGACY_IMAGES') if ((Configuration::get('PS_LEGACY_IMAGES')
&& (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'.jpg'))) && (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'.jpg')))
|| strpos($ids, 'default') !== false) || strpos($ids, 'default') !== false)
{ {
@@ -271,13 +295,13 @@ class LinkCore
// if ids if of the form id_product-id_image, we want to extract the id_image part // if ids if of the form id_product-id_image, we want to extract the id_image part
$split_ids = explode('-', $ids); $split_ids = explode('-', $ids);
$id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]); $id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
if ($this->allow == 1) if ($this->allow == 1)
$uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').'/'.$name.'.jpg'; $uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').'/'.$name.'.jpg';
else else
$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg'; $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg';
} }
return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path; return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
} }
@@ -288,7 +312,7 @@ class LinkCore
/** /**
* Create a simple link * Create a simple link
* *
* @param string $controller * @param string $controller
* @param bool $ssl * @param bool $ssl
* @param int $id_lang * @param int $id_lang
@@ -344,7 +368,7 @@ class LinkCore
parse_str($_SERVER['QUERY_STRING'], $queryTab); parse_str($_SERVER['QUERY_STRING'], $queryTab);
unset($queryTab['isolang'], $queryTab['controller']); unset($queryTab['isolang'], $queryTab['controller']);
if (!$this->allow) if (!$this->allow)
$queryTab['id_lang'] = $id_lang; $queryTab['id_lang'] = $id_lang;
@@ -377,11 +401,11 @@ class LinkCore
{ {
if (Configuration::get('PS_REWRITING_SETTINGS') AND ($k == 'isolang' OR $k == 'id_lang')) if (Configuration::get('PS_REWRITING_SETTINGS') AND ($k == 'isolang' OR $k == 'id_lang'))
continue; continue;
$ifNb = (!$nb OR ($nb AND !in_array($k, $varsNb))); $ifNb = (!$nb || ($nb AND !in_array($k, $varsNb)));
$ifSort = (!$sort OR ($sort AND !in_array($k, $varsSort))); $ifSort = (!$sort OR ($sort AND !in_array($k, $varsSort)));
$ifPagination = (!$pagination OR ($pagination AND !in_array($k, $varsPagination))); $ifPagination = (!$pagination || ($pagination && !in_array($k, $varsPagination)));
if ($ifNb AND $ifSort AND $ifPagination AND !is_array($value)) if ($ifNb && $ifSort && $ifPagination AND !is_array($value))
!$array ? ($vars .= ((!$n++ AND ($this->allow == 1 OR $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value)); !$array ? ($vars .= ((!$n++ && ($this->allow == 1 || $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value));
} }
if (!$array) if (!$array)
return $url.$vars; return $url.$vars;
+17 -2
View File
@@ -515,7 +515,7 @@ abstract class ModuleCore
* Return an instance of the specified module * Return an instance of the specified module
* *
* @param string $moduleName Module name * @param string $moduleName Module name
* @return Module instance * @return Module
*/ */
public static function getInstanceByName($moduleName) public static function getInstanceByName($moduleName)
{ {
@@ -1158,6 +1158,21 @@ abstract class ModuleCore
return $result; return $result;
} }
/**
* Get realpath of a template of current module (check if template is overriden too)
*
* @since 1.5.0
* @param string $template
* @return string
*/
public function getTemplatePath($template)
{
$overloaded = $this->_isTemplateOverloaded($template);
if (is_null($overloaded))
return null;
return ($overloaded ? _PS_THEME_DIR_.'modules/'.$this->name : _PS_MODULE_DIR_.$this->name).'/'.$template;
}
/** /**
* Assign a smarty vars (same syntax as smarty->assign) but prefix all keys with module name * Assign a smarty vars (same syntax as smarty->assign) but prefix all keys with module name
* *
@@ -1165,7 +1180,7 @@ abstract class ModuleCore
* @param string $key Variable key (can be an array) * @param string $key Variable key (can be an array)
* @param mixed $value Variable value * @param mixed $value Variable value
*/ */
public function smartyAssign($key, $value = null) public function templateAssign($key, $value = null)
{ {
if (is_array($key)) if (is_array($key))
{ {
+8 -3
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -25,5 +25,10 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
$controller = new FrontController(); if (isset(Context::getContext()->controller))
$controller->init(); $controller = Context::getContext()->controller;
else
{
$controller = new FrontController();
$controller->init();
}
+36 -36
View File
@@ -44,7 +44,7 @@ abstract class Module
/** @var string author of the module */ /** @var string author of the module */
public $author; public $author;
/** @var int need_instance */ /** @var int need_instance */
public $need_instance = 1; public $need_instance = 1;
@@ -84,11 +84,11 @@ abstract class Module
*/ */
protected static $modulesCache; protected static $modulesCache;
protected static $_hookModulesCache; protected static $_hookModulesCache;
protected static $_INSTANCE = array(); protected static $_INSTANCE = array();
protected static $_generateConfigXmlMode = false; protected static $_generateConfigXmlMode = false;
protected static $l_cache = array(); protected static $l_cache = array();
/** /**
@@ -168,14 +168,14 @@ abstract class Module
} }
/** /**
* This function enable module $name. If an $name is an array, * This function enable module $name. If an $name is an array,
* this will enable all of them * this will enable all of them
* *
* @param array|string $name * @param array|string $name
* @return true if succeed * @return true if succeed
* @since 1.4.1 * @since 1.4.1
*/ */
public static function enableByName($name) public static function enableByName($name)
{ {
if (!is_array($name)) if (!is_array($name))
$name = array($name); $name = array($name);
@@ -198,16 +198,16 @@ abstract class Module
SET `active`= 1 SET `active`= 1
WHERE `name` = \''.pSQL($this->name).'\''); WHERE `name` = \''.pSQL($this->name).'\'');
} }
/** /**
* This function disable module $name. If an $name is an array, * This function disable module $name. If an $name is an array,
* this will disable all of them * this will disable all of them
* *
* @param array|string $name * @param array|string $name
* @return true if succeed * @return true if succeed
* @since 1.4.1 * @since 1.4.1
*/ */
public static function disableByName($name) public static function disableByName($name)
{ {
if (!is_array($name)) if (!is_array($name))
$name = array($name); $name = array($name);
@@ -220,11 +220,11 @@ abstract class Module
SET `active`= 0 SET `active`= 0
WHERE `name` IN ('.implode(',',$name).')'); WHERE `name` IN ('.implode(',',$name).')');
} }
/** /**
* Called when module is set to deactive * Called when module is set to deactive
*/ */
public function disable() public function disable()
{ {
return Module::disableByName($this->name); return Module::disableByName($this->name);
} }
@@ -369,11 +369,11 @@ abstract class Module
/** /**
* This function is used to determine the module name * This function is used to determine the module name
* of an AdminTab which belongs to a module, in order to keep translation * of an AdminTab which belongs to a module, in order to keep translation
* related to a module in its directory (instead of $_LANGADM) * related to a module in its directory (instead of $_LANGADM)
* *
* @param mixed $currentClass the * @param mixed $currentClass the
* @return boolean|string if the class belongs to a module, will return the module name. Otherwise, return false. * @return boolean|string if the class belongs to a module, will return the module name. Otherwise, return false.
*/ */
public static function getModuleNameFromClass($currentClass) public static function getModuleNameFromClass($currentClass)
@@ -396,7 +396,7 @@ abstract class Module
if (Tools::file_exists_cache($file) AND include_once($file)) if (Tools::file_exists_cache($file) AND include_once($file))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
} }
else else
self::$classInModule[$currentClass] = false; self::$classInModule[$currentClass] = false;
} }
// return name of the module, or false // return name of the module, or false
@@ -434,7 +434,7 @@ abstract class Module
if(!isset($preloadedModuleNameFromId)) { if(!isset($preloadedModuleNameFromId)) {
$preloadedModuleNameFromId = array(); $preloadedModuleNameFromId = array();
} }
if(is_array($ids)) if(is_array($ids))
{ {
foreach($ids as $id) foreach($ids as $id)
@@ -458,12 +458,12 @@ abstract class Module
else else
$preloadedModuleNameFromId[$ids] = false; $preloadedModuleNameFromId[$ids] = false;
} }
if(is_array($ids)) { if(is_array($ids)) {
return $preloadedModuleNameFromId; return $preloadedModuleNameFromId;
} else { } else {
if(!isset($preloadedModuleNameFromId[$ids])) if(!isset($preloadedModuleNameFromId[$ids]))
return false; return false;
return $preloadedModuleNameFromId[$ids]; return $preloadedModuleNameFromId[$ids];
} }
@@ -674,7 +674,7 @@ abstract class Module
AND m.`active` = 1 AND m.`active` = 1
ORDER BY hm.`position`', false); ORDER BY hm.`position`', false);
self::$_hookModulesCache = array(); self::$_hookModulesCache = array();
if ($result) if ($result)
while ($row = $db->nextRow()) while ($row = $db->nextRow())
{ {
@@ -711,7 +711,7 @@ abstract class Module
{ {
$live_edit = true; $live_edit = true;
$output .= '<script type="text/javascript"> modules_list.push(\''.$moduleInstance->name.'\');</script> $output .= '<script type="text/javascript"> modules_list.push(\''.$moduleInstance->name.'\');</script>
<div id="hook_'.$array['id_hook'].'_module_'.$moduleInstance->id.'_moduleName_'.$moduleInstance->name.'" <div id="hook_'.$array['id_hook'].'_module_'.$moduleInstance->id.'_moduleName_'.$moduleInstance->name.'"
class="dndModule" style="border: 1px dotted red;'.(!strlen($display) ? 'height:50px;' : '').'"> class="dndModule" style="border: 1px dotted red;'.(!strlen($display) ? 'height:50px;' : '').'">
<span><img src="'.$moduleInstance->_path.'/logo.gif">' <span><img src="'.$moduleInstance->_path.'/logo.gif">'
.$moduleInstance->displayName.'<span style="float:right"> .$moduleInstance->displayName.'<span style="float:right">
@@ -760,7 +760,7 @@ abstract class Module
/** /**
* find translation from $_MODULES and put it in self::$l_cache if not already exist * find translation from $_MODULES and put it in self::$l_cache if not already exist
* and return it. * and return it.
* *
* @param string $name name of the module * @param string $name name of the module
* @param string $string term to find * @param string $string term to find
* @param string $source additional param for building translation key * @param string $source additional param for building translation key
@@ -769,9 +769,9 @@ abstract class Module
public static function findTranslation($name, $string, $source) public static function findTranslation($name, $string, $source)
{ {
global $_MODULES; global $_MODULES;
$cache_key = $name . '|' . $string . '|' . $source; $cache_key = $name . '|' . $string . '|' . $source;
if (!isset(self::$l_cache[$cache_key])) if (!isset(self::$l_cache[$cache_key]))
{ {
if (!is_array($_MODULES)) if (!is_array($_MODULES))
@@ -780,7 +780,7 @@ abstract class Module
$_MODULES = array_change_key_case($_MODULES); $_MODULES = array_change_key_case($_MODULES);
$currentKey = '<{'.strtolower($name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($source).'_'.md5($string); $currentKey = '<{'.strtolower($name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($source).'_'.md5($string);
$defaultKey = '<{'.strtolower($name).'}prestashop>'.strtolower($source).'_'.md5($string); $defaultKey = '<{'.strtolower($name).'}prestashop>'.strtolower($source).'_'.md5($string);
if (isset($_MODULES[$currentKey])) if (isset($_MODULES[$currentKey]))
$ret = stripslashes($_MODULES[$currentKey]); $ret = stripslashes($_MODULES[$currentKey]);
elseif (isset($_MODULES[Tools::strtolower($currentKey)])) elseif (isset($_MODULES[Tools::strtolower($currentKey)]))
@@ -791,16 +791,16 @@ abstract class Module
$ret = stripslashes($_MODULES[Tools::strtolower($defaultKey)]); $ret = stripslashes($_MODULES[Tools::strtolower($defaultKey)]);
else else
$ret = stripslashes($string); $ret = stripslashes($string);
self::$l_cache[$cache_key] = str_replace('"', '&quot;', $ret); self::$l_cache[$cache_key] = str_replace('"', '&quot;', $ret);
} }
return self::$l_cache[$cache_key]; return self::$l_cache[$cache_key];
} }
/** /**
* Get translation for a given module text * Get translation for a given module text
* *
* Note: $specific parameter is mandatory for library files. * Note: $specific parameter is mandatory for library files.
* Otherwise, translation key will not match for Module library * Otherwise, translation key will not match for Module library
* when module is loaded with eval() Module::getModulesOnDisk() * when module is loaded with eval() Module::getModulesOnDisk()
* *
* @param string $string String to translate * @param string $string String to translate
@@ -811,14 +811,14 @@ abstract class Module
{ {
if (self::$_generateConfigXmlMode) if (self::$_generateConfigXmlMode)
return $string; return $string;
global $_MODULES, $_MODULE, $cookie; global $_MODULES, $_MODULE, $cookie;
$id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang); $id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang);
$file = _PS_MODULE_DIR_.$this->name.'/'.Language::getIsoById($id_lang).'.php'; $file = _PS_MODULE_DIR_.$this->name.'/'.Language::getIsoById($id_lang).'.php';
if (Tools::file_exists_cache($file) AND include_once($file)) if (Tools::file_exists_cache($file) AND include_once($file))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
$source = $specific ? $specific : $this->name; $source = $specific ? $specific : $this->name;
$string = str_replace('\'', '\\\'', $string); $string = str_replace('\'', '\\\'', $string);
$ret = $this->findTranslation($this->name, $string, $source); $ret = $this->findTranslation($this->name, $string, $source);
@@ -897,7 +897,7 @@ abstract class Module
*/ */
public function getPosition($id_hook) public function getPosition($id_hook)
{ {
if(isset(Hook::$preloadModulesFromHooks)) if(isset(Hook::$preloadModulesFromHooks))
if(isset(Hook::$preloadModulesFromHooks[$id_hook])) if(isset(Hook::$preloadModulesFromHooks[$id_hook]))
if(isset(Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id])) if(isset(Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id]))
return Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id]; return Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id];
@@ -1027,7 +1027,7 @@ abstract class Module
return $smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId); return $smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
} }
protected function _generateConfigXml() protected function _generateConfigXml()
{ {
$xml = '<?xml version="1.0" encoding="UTF-8" ?> $xml = '<?xml version="1.0" encoding="UTF-8" ?>
@@ -1044,7 +1044,7 @@ abstract class Module
if (is_writable(_PS_MODULE_DIR_.$this->name.'/')) if (is_writable(_PS_MODULE_DIR_.$this->name.'/'))
file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', utf8_encode($xml)); file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', utf8_encode($xml));
} }
/** /**
* @param string $hook_name * @param string $hook_name
* @return bool if module can be transplanted on hook * @return bool if module can be transplanted on hook
+5 -5
View File
@@ -77,10 +77,10 @@ class BlockCart extends Module
if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1) if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1)
{ {
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
$this->smartyAssign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); $this->templateAssign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
} }
$this->smartyAssign(array( $this->templateAssign(array(
'products' => $products, 'products' => $products,
'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)),
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
@@ -98,9 +98,9 @@ class BlockCart extends Module
'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false
)); ));
if (sizeof($errors)) if (sizeof($errors))
$this->smartyAssign('errors', $errors); $this->templateAssign('errors', $errors);
if(isset($this->context->cookie->ajax_blockcart_display)) if(isset($this->context->cookie->ajax_blockcart_display))
$this->smartyAssign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); $this->templateAssign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display);
} }
public function getContent() public function getContent()
@@ -160,7 +160,7 @@ class BlockCart extends Module
return; return;
// @todo this variable seems not used // @todo this variable seems not used
$this->smartyAssign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false); $this->templateAssign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false);
$this->assignContentVars($params); $this->assignContentVars($params);
return $this->display(__FILE__, 'blockcart.tpl'); return $this->display(__FILE__, 'blockcart.tpl');
} }
+2 -2
View File
@@ -773,7 +773,7 @@ class BlockCms extends Module
public function displayBlockCMS($column) public function displayBlockCMS($column)
{ {
$cms_titles = self::getCMStitles($column); $cms_titles = self::getCMStitles($column);
$this->smartyAssign(array( $this->templateAssign(array(
'block' => 1, 'block' => 1,
'cms_titles' => $cms_titles, 'cms_titles' => $cms_titles,
)); ));
@@ -796,7 +796,7 @@ class BlockCms extends Module
if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))
{ {
$cms_titles = self::getCMStitlesFooter(); $cms_titles = self::getCMStitlesFooter();
$this->smartyAssign(array( $this->templateAssign(array(
'block' => 0, 'block' => 0,
'cmslinks' => $cms_titles, 'cmslinks' => $cms_titles,
'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), 'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'),
+1 -1
View File
@@ -92,7 +92,7 @@ class BlockLanguages extends Module
} }
} }
if (count($default_rewrite)) if (count($default_rewrite))
$this->smartyAssign('lang_rewrite_urls', $default_rewrite); $this->templateAssign('lang_rewrite_urls', $default_rewrite);
} }
return $this->display(__FILE__, 'blocklanguages.tpl'); return $this->display(__FILE__, 'blocklanguages.tpl');
@@ -54,8 +54,7 @@ class BlockManufacturer extends Module
function hookLeftColumn($params) function hookLeftColumn($params)
{ {
$this->templateAssign(array(
$this->smartyAssign(array(
'manufacturers' => Manufacturer::getManufacturers(), 'manufacturers' => Manufacturer::getManufacturers(),
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'), 'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'), 'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
+1 -1
View File
@@ -61,7 +61,7 @@ class BlockMyAccount extends Module
if (!$this->context->customer->isLogged()) if (!$this->context->customer->isLogged())
return false; return false;
$this->smartyAssign(array( $this->templateAssign(array(
'voucherAllowed' => (int)Configuration::get('PS_VOUCHERS'), 'voucherAllowed' => (int)Configuration::get('PS_VOUCHERS'),
'returnAllowed' => (int)Configuration::get('PS_ORDER_RETURN'), 'returnAllowed' => (int)Configuration::get('PS_ORDER_RETURN'),
'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock'), 'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock'),
@@ -100,7 +100,7 @@ class BlockNewProducts extends Module
if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'new_products' => $newProducts, 'new_products' => $newProducts,
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
)); ));
+1 -1
View File
@@ -90,7 +90,7 @@ class BlockSpecials extends Module
if (!$special = Product::getRandomSpecial((int)$params['cookie']->id_lang) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) if (!$special = Product::getRandomSpecial((int)$params['cookie']->id_lang) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'special' => $special, 'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
+1 -1
View File
@@ -60,7 +60,7 @@ class BlockUserInfo extends Module
if (!$this->active) if (!$this->active)
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'cart' => $this->context->cart, 'cart' => $this->context->cart,
'cart_qties' => $this->context->cart->nbProducts(), 'cart_qties' => $this->context->cart->nbProducts(),
'logged' => $this->context->customer->isLogged(), 'logged' => $this->context->customer->isLogged(),
+1 -1
View File
@@ -166,7 +166,7 @@ class BlockViewed extends Module
if (!sizeof($productsViewedObj)) if (!sizeof($productsViewedObj))
return ; return ;
$this->smartyAssign(array( $this->templateAssign(array(
'productsViewedObj' => $productsViewedObj, 'productsViewedObj' => $productsViewedObj,
'mediumSize' => Image::getSize('medium'))); 'mediumSize' => Image::getSize('medium')));
+34 -25
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -42,7 +42,7 @@ class Cheque extends PaymentModule
$this->tab = 'payments_gateways'; $this->tab = 'payments_gateways';
$this->version = '2.3'; $this->version = '2.3';
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->currencies = true; $this->currencies = true;
$this->currencies_mode = 'checkbox'; $this->currencies_mode = 'checkbox';
@@ -51,13 +51,13 @@ class Cheque extends PaymentModule
$this->chequeName = $config['CHEQUE_NAME']; $this->chequeName = $config['CHEQUE_NAME'];
if (isset($config['CHEQUE_ADDRESS'])) if (isset($config['CHEQUE_ADDRESS']))
$this->address = $config['CHEQUE_ADDRESS']; $this->address = $config['CHEQUE_ADDRESS'];
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Check'); $this->displayName = $this->l('Check');
$this->description = $this->l('Module for accepting payments by check.'); $this->description = $this->l('Module for accepting payments by check.');
$this->confirmUninstall = $this->l('Are you sure you want to delete your details ?'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
if (!isset($this->chequeName) OR !isset($this->address)) if (!isset($this->chequeName) OR !isset($this->address))
$this->warning = $this->l('\'To the order of\' and address must be configured in order to use this module correctly.'); $this->warning = $this->l('\'To the order of\' and address must be configured in order to use this module correctly.');
if (!sizeof(Currency::checkPaymentCurrencies($this->id))) if (!sizeof(Currency::checkPaymentCurrencies($this->id)))
@@ -149,26 +149,7 @@ class Cheque extends PaymentModule
public function execPayment($cart) public function execPayment($cart)
{ {
if (!$this->active) return $this->actionPayment(true);
return ;
if (!$this->_checkCurrency($cart))
Tools::redirect('index.php?controller=order');
$this->context->smarty->assign(array(
'nbProducts' => $cart->nbProducts(),
'cust_currency' => $cart->id_currency,
'currencies' => $this->getCurrency((int)$cart->id_currency),
'total' => $cart->getOrderTotal(true, Cart::BOTH),
'isoCode' => $this->context->language->iso_code,
'chequeName' => $this->chequeName,
'chequeAddress' => Tools::nl2br($this->address),
'this_path' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment_execution.tpl');
} }
public function hookPayment($params) public function hookPayment($params)
@@ -203,7 +184,7 @@ class Cheque extends PaymentModule
$this->context->smarty->assign('status', 'failed'); $this->context->smarty->assign('status', 'failed');
return $this->display(__FILE__, 'payment_return.tpl'); return $this->display(__FILE__, 'payment_return.tpl');
} }
private function _checkCurrency($cart) private function _checkCurrency($cart)
{ {
$currency_order = new Currency((int)($cart->id_currency)); $currency_order = new Currency((int)($cart->id_currency));
@@ -215,4 +196,32 @@ class Cheque extends PaymentModule
return true; return true;
return false; return false;
} }
public function actionPayment($direct_call = false)
{
if (!$this->active)
return ;
$cart = $this->context->cart;
if (!$this->_checkCurrency($cart))
Tools::redirect('index.php?controller=order');
$this->context->smarty->assign(array(
'nbProducts' => $cart->nbProducts(),
'cust_currency' => $cart->id_currency,
'currencies' => $this->getCurrency((int)$cart->id_currency),
'total' => $cart->getOrderTotal(true, Cart::BOTH),
'isoCode' => $this->context->language->iso_code,
'chequeName' => $this->chequeName,
'chequeAddress' => Tools::nl2br($this->address),
'this_path' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
if (!$direct_call)
return $this->getTemplatePath('payment_execution.tpl');
else
// For retrocompatibility
return $this->display(__FILE__, 'payment_execution.tpl');
}
} }
+2 -2
View File
@@ -1,5 +1,5 @@
{* {*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -25,7 +25,7 @@
*} *}
<p class="payment_module"> <p class="payment_module">
<a href="{$this_path_ssl}payment.php" title="{l s='Pay by cheque' mod='cheque'}"> <a href="{$link->getModuleLink('cheque', 'payment')}" title="{l s='Pay by cheque' mod='cheque'}">
<img src="{$this_path}cheque.jpg" alt="{l s='Pay by cheque' mod='cheque'}" width="86" height="49" /> <img src="{$this_path}cheque.jpg" alt="{l s='Pay by cheque' mod='cheque'}" width="86" height="49" />
{l s='Pay by cheque (order process will be longer)' mod='cheque'} {l s='Pay by cheque (order process will be longer)' mod='cheque'}
</a> </a>
+1 -1
View File
@@ -96,7 +96,7 @@ class HomeFeatured extends Module
$nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
$products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10));
$this->smartyAssign(array( $this->templateAssign(array(
'products' => $products, 'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home'), 'homeSize' => Image::getSize('home'),
@@ -0,0 +1,7 @@
<?php
class ModuleController extends ModuleControllerCore
{
}