[~] Hook::get replaced by Hook::getIdByName

This commit is contained in:
fBrignoli
2011-08-05 14:49:18 +00:00
parent 1816946216
commit d9fa602cc3
6 changed files with 202 additions and 178 deletions
+52 -31
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -29,42 +29,64 @@ class HookCore extends ObjectModel
{
/** @var string Name */
public $name;
protected $fieldsRequired = array('name');
protected $fieldsSize = array('name' => 32);
protected $fieldsValidate = array('name' => 'isHookName');
protected $table = 'hook';
protected $identifier = 'id_hook';
static $preloadModulesFromHooks = null;
public function getFields()
{
parent::validateFields();
parent::validateFields();
$fields['name'] = pSQL($this->name);
return $fields;
}
/**
* Return hook ID from name
*
*
* @param string $hookName Hook name
* @return integer Hook ID
*
* @deprecated since 1.5
*/
static public function get($hookName)
{
Tools::displayAsDeprecated();
if (!Validate::isHookName($hookName))
die(Tools::displayError());
$result = Db::getInstance()->getRow('
SELECT `id_hook`, `name`
FROM `'._DB_PREFIX_.'hook`
FROM `'._DB_PREFIX_.'hook`
WHERE `name` = \''.pSQL($hookName).'\'');
return ($result ? $result['id_hook'] : false);
}
/**
* Return hook ID from name
*
* @param string $hook_name Hook name
* @return integer Hook ID
*/
public static function getIdByName($hook_name)
{
if (!Validate::isHookName($hook_name))
die(Tools::displayError());
$result = Db::getInstance()->getRow('
SELECT `id_hook`, `name`
FROM `'._DB_PREFIX_.'hook`
WHERE `name` = \''.pSQL($hook_name).'\'');
return ($result ? $result['id_hook'] : false);
}
static public function getHooks($position = false)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -105,7 +127,7 @@ class HookCore extends ObjectModel
);
}
}
static public function getModulesFromHook($hookID, $moduleID = null)
{
Hook::preloadModulesFromHooks();
@@ -115,7 +137,7 @@ class HookCore extends ObjectModel
return (isset($list[$moduleID])) ? array($list[$moduleID]) : array();
return $list;
}
static public function newOrder($cart, $order, $customer, $currency, $orderStatus)
{
return Module::hookExec('newOrder', array(
@@ -135,7 +157,7 @@ class HookCore extends ObjectModel
$return = Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return;
return $return;
}
static public function postUpdateOrderStatus($newOrderStatusId, $id_order)
{
$order = new Order((int)($id_order));
@@ -146,7 +168,7 @@ class HookCore extends ObjectModel
/**
* Called when quantity of a product is updated.
*
*
* @param Product
* @param Order
*/
@@ -154,37 +176,37 @@ class HookCore extends ObjectModel
{
return Module::hookExec('updateQuantity', array('product' => $product, 'order' => $order));
}
static public function productFooter($product, $category)
{
return Module::hookExec('productFooter', array('product' => $product, 'category' => $category));
}
static public function productOutOfStock($product)
{
return Module::hookExec('productOutOfStock', array('product' => $product));
}
static public function addProduct($product)
{
return Module::hookExec('addProduct', array('product' => $product));
}
static public function updateProduct($product)
{
return Module::hookExec('updateProduct', array('product' => $product));
}
static public function deleteProduct($product)
{
return Module::hookExec('deleteProduct', array('product' => $product));
}
static public function updateProductAttribute($id_product_attribute)
{
return Module::hookExec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute));
}
static public function orderConfirmation($id_order)
{
if (Validate::isUnsignedId($id_order))
@@ -192,20 +214,20 @@ class HookCore extends ObjectModel
$params = array();
$order = new Order((int)$id_order);
$currency = new Currency((int)$order->id_currency);
if (Validate::isLoadedObject($order))
{
$params['total_to_pay'] = $order->total_paid;
$params['currency'] = $currency->sign;
$params['objOrder'] = $order;
$params['currencyObj'] = $currency;
return Module::hookExec('orderConfirmation', $params);
}
}
return false;
}
static public function paymentReturn($id_order, $id_module)
{
if (Validate::isUnsignedId($id_order) AND Validate::isUnsignedId($id_module))
@@ -213,14 +235,14 @@ class HookCore extends ObjectModel
$params = array();
$order = new Order((int)($id_order));
$currency = new Currency((int)($order->id_currency));
if (Validate::isLoadedObject($order))
{
$params['total_to_pay'] = $order->total_paid;
$params['currency'] = $currency->sign;
$params['objOrder'] = $order;
$params['currencyObj'] = $currency;
return Module::hookExec('paymentReturn', $params, (int)($id_module));
}
}
@@ -233,7 +255,7 @@ class HookCore extends ObjectModel
return false;
return Module::hookExec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order));
}
static public function backBeforePayment($module)
{
$params['module'] = strval($module);
@@ -241,7 +263,7 @@ class HookCore extends ObjectModel
return false;
return Module::hookExec('backBeforePayment', $params);
}
static public function updateCarrier($id_carrier, $carrier)
{
if (!Validate::isUnsignedId($id_carrier) OR !is_object($carrier))
@@ -250,4 +272,3 @@ class HookCore extends ObjectModel
}
}
+25 -26
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -111,8 +111,8 @@ class MoneyBookers extends PaymentModule
public function install()
{
if (!parent::install() OR
!$this->registerHook('payment') OR
if (!parent::install() OR
!$this->registerHook('payment') OR
!$this->registerHook('paymentReturn'))
return false;
Configuration::updateValue('MB_HIDE_LOGIN', 1);
@@ -157,28 +157,28 @@ class MoneyBookers extends PaymentModule
'max_redirects' => 10,
'timeout' => $timeout,
'header' => array(
'Accept-language: en',
'Accept-language: en',
'Cookie: foo=bar')));
if (is_callable('curl_init') && ($ch = curl_init()))
{
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);
}
else
{
// Check availability of the context options
// Check availability of the context options
if (!is_array($contextOptions) || !count($contextOptions))
$contextOptions = $defaultContextOptions;
// Create a stream context
$stream_context = stream_context_create($contextOptions);
if (($fp = @fopen($url, $mode, false, $stream_context)))
{
$content = fgets($fp, 4096);
@@ -187,7 +187,7 @@ class MoneyBookers extends PaymentModule
else if (!($content = @file_get_contents($url, false, $stream_context)))
if (($fp = @fsockopen($url, 80, $errnom, $errstr, $timeout)))
{
preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
$host = $matches[1];
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: ".$host."\r\n";
@@ -218,7 +218,7 @@ class MoneyBookers extends PaymentModule
if (isset($_POST['mb_email_to_validate']) &&
!empty($_POST['mb_email_to_validate']))
{
try
try
{
$url = 'http://moneybookers.prestashop.com/email_check.php?email='.$_POST['mb_email_to_validate'].'&url=http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__;
$content = $this->_fetchWebContent($url);
@@ -237,7 +237,7 @@ class MoneyBookers extends PaymentModule
}
}
catch(Exception $e)
{
{
$errors[] = $this->l('Unable to contact activation server, please try again later.');
}
}
@@ -317,13 +317,13 @@ class MoneyBookers extends PaymentModule
{
foreach(array('leftColumn', 'rightColumn') as $hookName)
if ($this->isRegisteredInHook($hookName))
$this->unregisterHook(Hook::get($hookName));
$this->unregisterHook(Hook::getIdByName($hookName));
if (Tools::getValue('logo_position') == self::LEFT_COLUMN)
$this->registerHook('leftColumn');
else if (Tools::getValue('logo_position') == self::RIGHT_COLUMN)
$this->registerHook('rightColumn');
}
/* Display errors */
if (sizeof($errors))
{
@@ -351,9 +351,9 @@ class MoneyBookers extends PaymentModule
self::DISABLE => $this->l('Disable'),
self::LEFT_COLUMN => $this->l('Left Column'),
self::RIGHT_COLUMN => $this->l('Right Column'));
$currentLogoBlockPosition = ($this->isRegisteredInHook('leftColumn')) ? self::LEFT_COLUMN :
(($this->isRegisteredInHook('rightColumn')) ? self::RIGHT_COLUMN : -1);
$currentLogoBlockPosition = ($this->isRegisteredInHook('leftColumn')) ? self::LEFT_COLUMN :
(($this->isRegisteredInHook('rightColumn')) ? self::RIGHT_COLUMN : -1);
/* Display settings form */
$output .= '
@@ -368,7 +368,7 @@ class MoneyBookers extends PaymentModule
<fieldset class="width2" style="margin: 20px 0; width: 800px;">
<legend><img src="'.__PS_BASE_URI__.'modules/moneybookers/logo.gif" alt="" />'.$this->l('Settings').'</legend>
<div class="margin-form" style="margin:0; padding:0 0 1em 20px">
<b>'.$this->l('Select the logo position').'</b> :
<b>'.$this->l('Select the logo position').'</b> :
<select name="logo_position">';
foreach($blockPositionList as $position => $translation)
{
@@ -380,8 +380,8 @@ class MoneyBookers extends PaymentModule
$iso_code = strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT')));
$landingPage = ($iso_code == 'en' || $iso_code == 'us') ? 'http://www.moneybookers.com/ads/partners/index.html?p=Prestashop' :
'http://www.moneybookers.com/ads/partners/'.$iso_code.'/index.html?p=Prestashop';
$output .= '
</select>
<p>'.$this->l('Change youpr logo position in the Front Office. Works with').'
@@ -424,7 +424,7 @@ class MoneyBookers extends PaymentModule
<tr><td colspan="3" style="border-top: 1px solid black;"><small>'.$this->l('For merchants over €100,000 fees can be negotiated.').' Contact: ecommerce@moneybookers.com</small></td></tr>
</table>
<br />
'.$this->l('To view the last update of the detailed fees').'<a href="'.$landingPage.'"> <b>'.$this->l('Click here').'</b></a>
'.$this->l('To view the last update of the detailed fees').'<a href="'.$landingPage.'"> <b>'.$this->l('Click here').'</b></a>
<p align="left">
** '.$this->l('Moneybookers eWallet').'<br />
@@ -562,7 +562,7 @@ class MoneyBookers extends PaymentModule
$imgPath = __PS_BASE_URI__.'modules/moneybookers/logo-skrill.png';
return '<div style="text-align:center;"><img src="'.$imgPath.'" width=150 /></div>';
}
public function hookRightColumn($params)
{
return $this->_displayLogoBlock(self::RIGHT_COLUMN);
@@ -597,7 +597,7 @@ class MoneyBookers extends PaymentModule
{
$localMethods = Configuration::get('MB_LOCAL_METHODS');
$interMethods = Configuration::get('MB_INTER_METHODS');
$this->context->smarty->assign(array(
'display_mode' => (int)(Configuration::get('MB_DISPLAY_MODE')),
'local' => $localMethods ? explode('|', $localMethods) : array(),
@@ -662,11 +662,11 @@ class MoneyBookers extends PaymentModule
case _PS_OS_OUTOFSTOCK_:
$this->context->smarty->assign('status', 'ok');
break;
case _PS_OS_BANKWIRE_:
$this->context->smarty->assign('status', 'pending');
break;
case _PS_OS_ERROR_:
default:
$this->context->smarty->assign('status', 'failed');
@@ -677,4 +677,3 @@ class MoneyBookers extends PaymentModule
}
}
+41 -38
View File
@@ -268,7 +268,7 @@ class shopimporter extends ImportModule
unset($exportModules[$key]);
$html = '<script type="text/javascript">var globalAjaxShopImporterToken = "'.sha1(_COOKIE_KEY_.'ajaxShopImporter').'";</script>
<script type="text/javascript" src="../modules/shopimporter/shopimporter.js"></script>
<script src="'._PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js"></script>
<script src="'._PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js"></script>
<script type="text/javascript">
var conf = new Array(); ';
$i = 0;
@@ -449,10 +449,10 @@ class shopimporter extends ImportModule
$defaultIdLand = $importModule->getDefaultIdLang();
$defaultLanguageImport = new Language(Language::getIdByIso($languages[$defaultIdLand]['iso_code']));
if ($defaultLanguage->iso_code != $defaultLanguageImport->iso_code)
$errors[] = $this->l('Default language doesn\'t match : ').'<br>'.Configuration::get('PS_SHOP_NAME').' : '.$defaultLanguage->name.' ≠
$errors[] = $this->l('Default language doesn\'t match : ').'<br>'.Configuration::get('PS_SHOP_NAME').' : '.$defaultLanguage->name.' ≠
'.$importModule->displayName.' : '.$defaultLanguageImport->name.'<br>'.$this->l('Please change default language in your configuration');
}
if (Tools::isSubmit('syncCurrency'))
{
$defaultIdCurrency = $importModule->getDefaultIdCurrency();
@@ -461,7 +461,7 @@ class shopimporter extends ImportModule
$defaultCurrencyImport = new Currency((int)Currency::getIdByIsoCode($currencies[$defaultIdCurrency]['iso_code']));
else
$defaultCurrencyImport = new Currency((int)Currency::getIdByIsoCodeNum($currencies[$defaultIdCurrency]['iso_code_num']));
$defaultCurrency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'));
if ($defaultCurrency->iso_code != $defaultCurrencyImport->iso_code)
$errors[] = $this->l('Default currency doesn\'t match : ').'<br>'.Configuration::get('PS_SHOP_NAME').' : '.$defaultCurrency->name.' ≠ '.$importModule->displayName.' : '.$defaultCurrencyImport->name.'<br>'.$this->l('Please change default currency in your configuration');
@@ -472,7 +472,7 @@ class shopimporter extends ImportModule
else
die('{"hasError" : true, "error" : ["FATAL ERROR"], "datas" : []}');
}
foreach($fields as $key => $field)
{
$id = $this->supportedImports[strtolower($className)]['identifier'];
@@ -492,7 +492,7 @@ class shopimporter extends ImportModule
array_unshift($errors[sizeof($errors)-1], $field[$id]);
}
}
if (sizeof($errors) > 0)
if (sizeof($errors) > 0)
{
$json['hasError'] = true;
$json['error'] = $errors;
@@ -528,14 +528,14 @@ class shopimporter extends ImportModule
if ($className == 'Category' AND (sizeof($fields) != (int)Tools::getValue('nbr_import')))
$this->updateCat();
}
if (sizeof($errors) > 0 AND is_array($errors))
if (sizeof($errors) > 0 AND is_array($errors))
{
$json['hasError'] = true;
$json['error'] = $errors;
}
die(Tools::jsonEncode($json));
}
private function saveObject($className, $items)
{
$return = array();
@@ -547,7 +547,7 @@ class shopimporter extends ImportModule
{
$object = new $className;
$id = $item[$this->supportedImports[strtolower($className)]['identifier']];
if (array_key_exists('foreign_key', $this->supportedImports[strtolower($className)]))
if (array_key_exists('foreign_key', $this->supportedImports[strtolower($className)]))
$this->replaceForeignKey($item, $table);
$matchIdLang = $this->getMatchIdLang(1);
foreach($item as $key => $val)
@@ -584,7 +584,7 @@ class shopimporter extends ImportModule
}
return $return;
}
private function saveOrders($items)
{
$this->saveObject('cart', $items);
@@ -637,12 +637,12 @@ class shopimporter extends ImportModule
$item['order_history'][$k][$key] = $foreignKey[$key][$val];
else
$item['order_history'][$k][$key] = 0;
Db::getInstance()->autoExecute(_DB_PREFIX_.'order_history', $item['order_history'][$k],'INSERT');
}
}
}
private function insertAssociation($table, $items)
{
foreach($this->supportedImports[$table]['association'] AS $association)
@@ -675,7 +675,7 @@ class shopimporter extends ImportModule
}
}
}
private function saveMatchId($className, $psId, $matchId)
{
$table = $this->supportedImports[$className]['table'];
@@ -683,7 +683,7 @@ class shopimporter extends ImportModule
$identifier = $this->supportedImports[$className]['identifier'];
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.pSQL($table).' SET `'.pSQL($identifier).'_'.pSQL($moduleName).'` = '.(int)$matchId.' WHERE `'.pSQL($identifier).'` = '.(int)$psId);
}
private function getMatchId($className)
{
$table = $this->supportedImports[$className]['table'];
@@ -695,7 +695,7 @@ class shopimporter extends ImportModule
$match[$return[$identifier.'_'.$moduleName]] = $return[$identifier];
return $match;
}
private function getDefaultId($table)
{
$defaultId = 1;
@@ -703,7 +703,7 @@ class shopimporter extends ImportModule
$defaultId = Configuration::get($this->supportedImports[strtolower($table)]['defaultId']);
return $defaultId;
}
private function copyImg($item, $className)
{
require_once('../../images.inc.php');
@@ -737,7 +737,7 @@ class shopimporter extends ImportModule
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import');
if (@copy($image, $tmpfile))
{
$imagesTypes = ImageType::getImagesTypes($type);
imageResize($tmpfile, $path.(int)$matchId[$item[$identifier]].'.jpg');
if ($className == 'Product')
@@ -767,16 +767,16 @@ class shopimporter extends ImportModule
@unlink($tmpfile);
$cover = 0;
}
}
private function replaceForeignKey(&$item, $table)
{
if ($table == 'product_attribute')
$table2 = 'combination';
else
$table2 = $table;
$foreingKey = $this->supportedImports[$table2]['foreign_key'];
$foreingKeyValue = $this->getForeignKey($table, $foreingKey);
foreach($foreingKey as $key)
@@ -793,7 +793,7 @@ class shopimporter extends ImportModule
$item[$key2] = $this->getDefaultId($table);
}
}
private function alterTable($className)
{
$query ='';
@@ -816,7 +816,7 @@ class shopimporter extends ImportModule
Db::getInstance()->Execute($query);
}
}
private function updateCat()
{
$moduleName = Tools::getValue('moduleName');
@@ -825,7 +825,7 @@ class shopimporter extends ImportModule
INNER JOIN
'._DB_PREFIX_.'category c2
ON
c.id_parent = c2.id_category_'.pSQL($moduleName).'
c.id_parent = c2.id_category_'.pSQL($moduleName).'
SET
c.id_parent = c2.id_category
WHERE c.id_category_'.pSQL($moduleName).' != 0');
@@ -838,7 +838,7 @@ class shopimporter extends ImportModule
$cat->update();
}
}
private function getForeignKey($className, $foreign_key = null)
{
$moduleName = Tools::getValue('moduleName');
@@ -859,7 +859,7 @@ class shopimporter extends ImportModule
$return = Db::getInstance()->ExecuteS('SELECT `'.pSQL($key2).'_'.pSQL($moduleName).'`, `'.pSQL($key2).'` FROM `'._DB_PREFIX_.pSQL($from).'` WHERE `'.pSQL($key2).'_'.pSQL($moduleName).'` != 0');
if (!empty($return))
foreach($return AS $name => $val)
$match[$key][$val[$key2.'_'.$moduleName]] = $val[$key2];
$match[$key][$val[$key2.'_'.$moduleName]] = $val[$key2];
}
return $match;
}
@@ -874,7 +874,7 @@ class shopimporter extends ImportModule
$match[$val[$id.'_'.$moduleName]] = $val[$id];
return $match;
}
private function getMatchIdLang($order = 1)
{
$moduleName = Tools::getValue('moduleName');
@@ -931,7 +931,7 @@ class shopimporter extends ImportModule
}
else
$returnErrors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is invalid');
if ((sizeof($rules['requiredLang']) OR sizeof($rules['sizeLang']) OR sizeof($rules['validateLang'])))
{
$matchIdLang = $this->getMatchIdLang(0);
@@ -1037,7 +1037,7 @@ class shopimporter extends ImportModule
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'lang`
SET `id_lang_'.pSQL($moduleName).'` = '.(int)$language['id_lang'].'
WHERE `id_lang` = '.(int)$newId);
}
}
}
}
@@ -1129,12 +1129,12 @@ class shopimporter extends ImportModule
Product::cleanPositions((int)($categ['id_category']));
}
}
public function getDefaultIdLang()
{
return;
}
private function generateData($size = 1, $type)
{
$type = str_replace('is', '', $type);
@@ -1197,7 +1197,7 @@ class shopimporter extends ImportModule
$return .= substr($str, mt_rand(0, strlen($str)), 1);
break;
case 'StateIsoCode';
break;
case 'Email':
$a = mt_rand(4, 10);
@@ -1218,9 +1218,9 @@ class shopimporter extends ImportModule
$return .= '1970-01-01 00:00:00';
break;
}
return $return;
return $return;
}
private function cartToOrder($items, $foreignKey)
{
$this->alterTable('order');
@@ -1231,13 +1231,13 @@ class shopimporter extends ImportModule
$order->id_customer = (int)$foreignKey['id_customer'][$item['id_customer']];
$order->id_address_invoice = (int)$foreignKey['id_address_invoice'][$item['id_address_invoice']];
$order->id_address_delivery = (int)$foreignKey['id_address_delivery'][$item['id_address_delivery']];
$vat_address = new Address((int)$foreignKey['id_address_delivery'][$item['id_address_delivery']]);
$id_zone = Address::getZoneById((int)$vat_address->id);
$order->id_currency = (int)$item['id_currency'];
$order->id_lang = (int)$item['id_lang'];
$order->id_cart = (int)$foreignKey['id_cart'][$item['id_cart']];
$customer = new Customer((int)$order->id_customer);
$order->secure_key = pSQL($customer->secure_key);
if (!strlen(trim($item['payment'])))
@@ -1246,24 +1246,27 @@ class shopimporter extends ImportModule
$order->payment = utf8_encode(html_entity_decode(strip_tags(Tools::substr($item['payment'], 0, 32))));
if (isset($this->name))
$order->module = $this->name;
$carrier = new Carrier((int)$item['id_carrier']);
$currency = new Currency($order->id_currency);
$order->conversion_rate = $currency->conversion_rate;
$order->total_products = (float)$item['total_products'];
$order->total_products_wt = (float)$item['total_products_wt'];
$order->total_discounts = (float)$item['total_discounts'];
$order->total_shipping = (float)$item['total_shipping'];
$order->carrier_tax_rate = (float)Tax::getCarrierTaxRate((int)$item['id_carrier'], (int)$item[Configuration::get('PS_TAX_ADDRESS_TYPE')]);
$order->carrier_tax_rate = (float)$carrier->getTaxesRate(new Address((int)$item[Configuration::get('PS_TAX_ADDRESS_TYPE')]));
$order->total_wrapping = (float)$item['total_wrapping'];
$order->total_paid = (float)$item['total_paid'];
$order->total_paid_real = (float)$item['total_paid_real'];
$order->invoice_date = '0000-00-00 00:00:00';
$order->delivery_date = '0000-00-00 00:00:00';
$order->save(false, false);
$this->saveMatchId('order', (int)$order->id, (int)$item['id_cart']);
}
}
}
?>
+74 -73
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -41,17 +41,17 @@ class ThemeInstallator extends Module
** index
*/
private $page;
/*
** Config File
*/
private $xml;
public function __construct()
{
set_time_limit(0);
ini_set('memory_limit', '2G');
$this->name = 'themeinstallator';
$this->version = '1.4';
$this->author = 'PrestaShop';
@@ -64,7 +64,7 @@ class ThemeInstallator extends Module
$this->displayName = $this->l('Import/export a theme');
$this->description = $this->l('Export or Install a theme and its modules on your shop.');
}
private function getTheNativeModules()
{
$xml = simplexml_load_string(Tools::file_get_contents('http://www.prestashop.com/xml/modules_list.xml'));
@@ -73,7 +73,7 @@ class ThemeInstallator extends Module
foreach ($xml->modules as $row)
foreach ($row->module as $row2)
$natives[] = (string)$row2['name'];
if (count($natives > 0))
return $natives;
// use this list if we can't contact the prestashop.com server
@@ -90,7 +90,7 @@ class ThemeInstallator extends Module
'trackingfront', 'watermark');
return $natives;
}
private function deleteDirectory($dirname)
{
$files = scandir($dirname);
@@ -104,7 +104,7 @@ class ThemeInstallator extends Module
}
rmdir($dirname);
}
private function recurseCopy($src, $dst)
{
if (!$dir = opendir($src))
@@ -121,7 +121,7 @@ class ThemeInstallator extends Module
}
closedir($dir);
}
/*
** Checks if module is installed
** Returns true if module is active
@@ -145,7 +145,7 @@ class ThemeInstallator extends Module
return true;
return false;
}
private function deleteTmpFiles()
{
if (file_exists(_IMPORT_FOLDER_.'doc'))
@@ -156,26 +156,26 @@ class ThemeInstallator extends Module
self::deleteDirectory(_IMPORT_FOLDER_.'modules');
if (file_exists(_IMPORT_FOLDER_.'themes'))
self::deleteDirectory(_IMPORT_FOLDER_.'themes');
if (file_exists(_EXPORT_FOLDER_.'archive.zip'))
if (file_exists(_EXPORT_FOLDER_.'archive.zip'))
unlink(_EXPORT_FOLDER_.'archive.zip');
}
private function init_defines()
{
global $cookie;
define('_EXPORT_FOLDER_', dirname(__FILE__).'/export/');
define('_IMPORT_FOLDER_', dirname(__FILE__).'/import/');
$this->page = 1;
$this->page = 1;
if (!file_exists(_EXPORT_FOLDER_) OR !is_dir(_EXPORT_FOLDER_))
mkdir(_EXPORT_FOLDER_, 0777);
if (!file_exists(_IMPORT_FOLDER_) OR !is_dir(_IMPORT_FOLDER_))
mkdir(_IMPORT_FOLDER_, 0777);
if (!Tools::isSubmit('cancelExport') AND (Tools::isSubmit('exportTheme') OR Tools::isSubmit('submitExport')))
$this->page = 'exportPage';
$this->_html = '<form action="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::htmlentitiesUTF8(Tools::getValue('token')).'" method="POST" enctype=multipart/form-data>';
if (Tools::isSubmit('modulesToExport') OR Tools::isSubmit('submitModules'))
$this->to_export = Tools::getValue('modulesToExport');
if (Tools::isSubmit('submitThemes'))
@@ -192,7 +192,7 @@ class ThemeInstallator extends Module
define('MAX_COMPATIBILITY_VER', 7);
define('ARCHIVE_NAME', _IMPORT_FOLDER_.'uploaded.zip');
define('XMLFILENAME', 'Config.xml');
$this->_msg = '';
$this->to_enable = false;
$this->to_disable = false;
@@ -205,7 +205,7 @@ class ThemeInstallator extends Module
echo parent::displayError('<b>'.$theme.'</b> is not a valid theme to export');
}
}
private function handleInformations()
{
if (Tools::isSubmit('submitImport1'))
@@ -272,7 +272,7 @@ class ThemeInstallator extends Module
}
self::deleteTmpFiles();
}
private function checkXmlFields()
{
if (!file_exists(_IMPORT_FOLDER_.XMLFILENAME) OR !$xml = simplexml_load_file(_IMPORT_FOLDER_.XMLFILENAME))
@@ -290,7 +290,7 @@ class ThemeInstallator extends Module
return false;
return true;
}
public function getContentExport()
{
$this->theme_list = scandir(_PS_ALL_THEMES_DIR_);
@@ -314,7 +314,7 @@ class ThemeInstallator extends Module
self::VariationInformationForm();
return $this->_html;
}
/*
** Main function
*/
@@ -341,7 +341,7 @@ class ThemeInstallator extends Module
}
return $this->errors.$this->_msg.$this->_html;
}
/*
** Checker si le dossier doc existe : Si oui appeler la fonction !
*/
@@ -349,7 +349,7 @@ class ThemeInstallator extends Module
{
$docname = array();
$docpath = array();
foreach ($this->xml->docs->doc as $row)
{
$docname[] = strval($row['name']);
@@ -372,7 +372,7 @@ class ThemeInstallator extends Module
<p class="clear">&nbsp;</p>';
$this->_html .= $doc;
}
private function getModules()
{
$this->native_modules = self::getTheNativeModules();
@@ -386,7 +386,7 @@ class ThemeInstallator extends Module
$this->to_disable[] = strval($row['name']);
}
}
private function updateImages()
{
foreach ($this->xml->images->image as $row)
@@ -422,7 +422,7 @@ class ThemeInstallator extends Module
}
return true;
}
private function _displayForm4()
{
$xml = simplexml_load_file(_IMPORT_FOLDER_.XMLFILENAME);
@@ -433,7 +433,7 @@ class ThemeInstallator extends Module
$position = array();
$msg = '';
$shopID = $this->context->shop->getID();
foreach ($this->xml->modules->hooks->hook as $row)
{
$hookedModule[] = strval($row['module']);
@@ -465,7 +465,7 @@ class ThemeInstallator extends Module
Db::getInstance()->Execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')');
$msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'hook_module`
DELETE FROM `'._DB_PREFIX_.'hook_module`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop = '.$shopID);
$count = -1;
while (isset($hookedModule[++$count]))
@@ -473,12 +473,12 @@ class ThemeInstallator extends Module
{
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`)
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')');
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::getIdByName($hook[$count]).', '.(int)$position[$count].')');
if ($exceptions[$count])
foreach ($exceptions[$count] as $file_name)
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module_exceptions` (`id_module`, `id_hook`, `file_name`)
VALUES ('.(int)$obj->id.', '.(int)Hook::get($hook[$count]).', "'.pSQL($file_name).'")');
VALUES ('.(int)$obj->id.', '.(int)Hook::getIdByName($hook[$count]).', "'.pSQL($file_name).'")');
}
}
if (($val = (int)(Tools::getValue('nativeModules'))) != 1)
@@ -495,7 +495,7 @@ class ThemeInstallator extends Module
$msg .= '<b>'.$this->l('The following modules have been disabled').' :</b><br />';
$msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'module_shop`
DELETE FROM `'._DB_PREFIX_.'module_shop`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop = '.$shopID);
}
}
@@ -518,7 +518,7 @@ class ThemeInstallator extends Module
$msg .= '<b>'.$this->l('The following modules have been enabled').' :</b><br />';
$msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'hook_module`
DELETE FROM `'._DB_PREFIX_.'hook_module`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop = '.$shopID);
$count = -1;
while (isset($hookedModule[++$count]))
@@ -526,12 +526,12 @@ class ThemeInstallator extends Module
{
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`)
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')');
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::getIdByName($hook[$count]).', '.(int)$position[$count].')');
foreach ($exceptions[$count] as $filename)
if (!empty($filename))
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module_exceptions` (`id_module`, id_shop, `id_hook`, `file_name`)
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', "'.pSQL($filename).'")');
VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::getIdByName($hook[$count]).', "'.pSQL($filename).'")');
}
}
}
@@ -546,9 +546,9 @@ class ThemeInstallator extends Module
<input type="submit" class="button" name="submitThemes" value="'.$this->l('Previous').'" />
<input type="submit" class="button" name="Finish" value="'.$this->l('Finish').'" />
</form>';
}
private function _displayForm3()
{
$xml = simplexml_load_file(_IMPORT_FOLDER_.XMLFILENAME);
@@ -603,7 +603,7 @@ class ThemeInstallator extends Module
<li><input type="radio" name="nativeModules" value="3" id="nativemoduleconfig3" /> <label style="display:bock;float:none" for="nativemoduleconfig3">'.$this->l('Both').'</label>
</ul>
</fieldset>
<p>&nbsp;</p>';
<p>&nbsp;</p>';
$this->_html .= '
<fieldset>
<legend>'.$this->l('Theme images configuration').'</legend>
@@ -620,7 +620,7 @@ class ThemeInstallator extends Module
</fieldset>
</form>';
}
private function _displayForm2()
{
global $cookie;
@@ -680,18 +680,18 @@ class ThemeInstallator extends Module
';
$this->_html .= '</form>';
}
private function _displayForm1()
{
$tmp = scandir(_PS_ALL_THEMES_DIR_);
$themeList = array();
foreach ($tmp as $row)
if (is_dir(_PS_ALL_THEMES_DIR_.$row) AND file_exists(_PS_ALL_THEMES_DIR_.$row.'/index.tpl') AND $row != 'prestashop')
$themeList[] = $row;
if (count($themeList) > 0)
{
$tmp = '';
$tmp = '';
foreach ($themeList as $row)
$tmp .= '<option value="'.$row.'" '.($row == _THEME_NAME_ ? 'selected="selected"' : '').'>'.$row.'</option>';
$this->_html .= '
@@ -756,7 +756,7 @@ class ThemeInstallator extends Module
*/
private function displayInformations()
{
{
$this->_html .= '<input type="hidden" name="mainTheme" value="'.Tools::getValue('mainTheme').'" />';
if ($this->error === false AND class_exists('ZipArchive', false) AND ($zip = new ZipArchive()))
{
@@ -767,7 +767,7 @@ class ThemeInstallator extends Module
$this->_html .= parent::displayConfirmation('Fill this formular to export this theme: <b>'.Tools::getValue('mainTheme').'</b> in a ZIP file');
}
}
private function archiveThisFile($obj, $file, $serverPath, $archivePath)
{
if (is_dir($serverPath.$file))
@@ -780,12 +780,12 @@ class ThemeInstallator extends Module
else if (!$obj->addFile($serverPath.$file, $archivePath.$file))
$this->error = true;
}
/*
** Generate Archive !
*/
private function generateArchive()
{
{
$count = 0;
$zip = new ZipArchive();
$zip_file_name = md5(time()).".zip";
@@ -821,7 +821,7 @@ class ThemeInstallator extends Module
}
$this->_html .= parent::displayError($this->l('An error occurred during the archive generation'));
}
/*
** XML Generation, all vars should be GOOD at this point
*/
@@ -854,7 +854,7 @@ class ThemeInstallator extends Module
$variation->addAttribute('from', $array[2]);
$variation->addAttribute('to', $array[3]);
}
$docs = $theme->addChild('docs');
if (isset($this->user_doc))
foreach ($this->user_doc as $row)
@@ -864,7 +864,7 @@ class ThemeInstallator extends Module
$doc->addAttribute('name', $array[0]);
$doc->addAttribute('path', $array[1]);
}
$modules = $theme->addChild('modules');
if (isset($this->to_export))
foreach ($this->to_export as $row)
@@ -886,7 +886,7 @@ class ThemeInstallator extends Module
$module->addAttribute('action', 'disable');
$module->addAttribute('name', $row);
}
$hooks = $modules->addChild('hooks');
foreach ($this->to_hook as $row)
{
@@ -898,7 +898,7 @@ class ThemeInstallator extends Module
if (!empty($array[3]))
$hook->addAttribute('exceptions', $array[3]);
}
$images = $theme->addChild('images');
foreach ($this->image_list as $row)
{
@@ -920,7 +920,7 @@ class ThemeInstallator extends Module
** Init modules and Hooks
*/
private function _initList()
{
{
$this->native_modules = self::getTheNativeModules();
$this->module_list = Db::getInstance()->ExecuteS('SELECT id_module, name, active FROM `'._DB_PREFIX_.'module`');
$this->hook_list = Db::getInstance()->ExecuteS('
@@ -933,7 +933,7 @@ class ThemeInstallator extends Module
ORDER BY name_module');
foreach ($this->hook_list as &$row)
$row['exceptions'] = trim(preg_replace('/(,,+)/', ',', $row['exceptions']), ',');
}
/*
@@ -951,7 +951,7 @@ class ThemeInstallator extends Module
if ($array['active'] == 1)
$this->to_enable[] = $array['name'];
else
$this->to_disable[] = $array['name'];
$this->to_disable[] = $array['name'];
}
else if ($array['active'] == 1)
$this->to_install[] = $array['name'];
@@ -967,7 +967,7 @@ class ThemeInstallator extends Module
$flag = 1;
break;
}
if ($flag == 0)
if ($flag == 0)
$this->to_disable[] = $str;
}
}
@@ -986,7 +986,7 @@ class ThemeInstallator extends Module
if ($tmp['name_module'] == $string)
$this->to_hook[] = $string.';'.$tmp['name_hook'].';'.$tmp['position'].';'.$tmp['exceptions'];
}
/*
** Fill Image var
*/
@@ -1001,7 +1001,7 @@ class ThemeInstallator extends Module
($row['suppliers'] == 1 ? 'true' : 'false').';'.
($row['scenes'] == 1 ? 'true' : 'false');
}
/*
** Takes current and submited theme's informations
*/
@@ -1022,7 +1022,7 @@ class ThemeInstallator extends Module
$this->variations[] = $name.'¤'.$dir.'¤'.$from.'¤'.$to;
}
}
private function getDocumentation()
{
$count = 0;
@@ -1039,7 +1039,7 @@ class ThemeInstallator extends Module
{
$mail = Tools::getValue('email');
$website = Tools::getValue('website');
if ($mail AND !preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $mail))
$this->_html .= parent::displayError($this->l('There is an error in your e-mail syntax!'));
else if ($website AND (!Validate::isURL($website) OR !Validate::isAbsoluteUrl($website)))
@@ -1050,7 +1050,7 @@ class ThemeInstallator extends Module
return true;
return false;
}
/*
** Checks posted documentation
*/
@@ -1076,7 +1076,7 @@ class ThemeInstallator extends Module
return false;
return true;
}
/*
** Checks theme's and author's name syntax, existence and length
*/
@@ -1085,7 +1085,7 @@ class ThemeInstallator extends Module
$author = Tools::getValue('author_name');
$name = Tools::getValue('theme_name');
$count = 0;
if (!$author OR !Validate::isGenericName($author) OR strlen($author) > MAX_NAME_LENGTH)
$this->_html .= parent::displayError($this->l('Please enter a valid author name'));
else if (!$name OR !Validate::isGenericName($name) OR strlen($name) > MAX_NAME_LENGTH)
@@ -1107,9 +1107,9 @@ class ThemeInstallator extends Module
{
$count = 0;
$exp = "#^[0-9]+[.]+[0-9.]*[0-9]$#";
if (!preg_match("#^[0-9][.][0-9]$#", Tools::getValue('version')) OR
!preg_match($exp, Tools::getValue('compa_from')) OR !preg_match($exp, Tools::getValue('compa_to')) OR
if (!preg_match("#^[0-9][.][0-9]$#", Tools::getValue('version')) OR
!preg_match($exp, Tools::getValue('compa_from')) OR !preg_match($exp, Tools::getValue('compa_to')) OR
version_compare(Tools::getValue('compa_from'), Tools::getValue('compa_to')) == 1)
$this->_html .= parent::displayError($this->l('Syntax error on version field. Only digits and points are allowed and the compatibility should be increasing or equal.'));
while ($this->error === false AND Tools::isSubmit('myvar_'.++$count))
@@ -1125,14 +1125,14 @@ class ThemeInstallator extends Module
return false;
return true;
}
private function ModulesInformationForm()
{
if ($this->to_install AND count($this->to_install))
{
$tmp = '';
foreach ($this->to_install as $key => $val)
$tmp .= '<input type="checkbox" name="modulesToExport[]" value="'.$val.'" id="'.$val.'" '.(in_array($val, $this->to_export) ? 'checked="checked"' : "").'/> <label style="display:bock;float:none" for="'.$val.'">'.$val.'</label><br />';
$tmp .= '<input type="checkbox" name="modulesToExport[]" value="'.$val.'" id="'.$val.'" '.(in_array($val, $this->to_export) ? 'checked="checked"' : "").'/> <label style="display:bock;float:none" for="'.$val.'">'.$val.'</label><br />';
$this->_html .= '
<fieldset>
<legend>'.$this->l('Modules').'</legend>
@@ -1142,7 +1142,7 @@ class ThemeInstallator extends Module
<p class="clear">&nbsp;</p>';
}
}
private function AuthorInformationForm()
{
global $cookie;
@@ -1170,14 +1170,14 @@ class ThemeInstallator extends Module
</fieldset>
<div class="clear">&nbsp;</div>';
}
private function ThemeInformationForm()
{
global $cookie;
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages();
$iso = Language::getIsoById((int)($cookie->id_lang));
$iso = Language::getIsoById((int)($cookie->id_lang));
$divLangName = 'title';
$val = Tools::getValue('theme_name') ? Tools::getValue('theme_name') : Tools::getValue('mainTheme');
@@ -1211,7 +1211,7 @@ class ThemeInstallator extends Module
<p class="clear">'.$this->l('Your theme\'s version').'</p>
</div>';
$val = Tools::getValue('compa_from') ? Tools::getValue('compa_from') : DEFAULT_COMPATIBILITY_FROM;
$val2 = Tools::getValue('compa_to') ? Tools::getValue('compa_to') : DEFAULT_COMPATIBILITY_TO;
$val2 = Tools::getValue('compa_to') ? Tools::getValue('compa_to') : DEFAULT_COMPATIBILITY_TO;
$this->_html .= '
<div style="float: left;">
<label>'.$this->l('Compatible From').'</label>
@@ -1227,7 +1227,7 @@ class ThemeInstallator extends Module
</div>
<p class="clear">&nbsp;</p>';
}
private function DocInformationForm()
{
$val = Tools::htmlentitiesUTF8(Tools::getValue('documentation'));
@@ -1243,7 +1243,7 @@ class ThemeInstallator extends Module
';
$this->_html .= '<p class="clear">&nbsp;</p>';
}
private function VariationInformationForm()
{
$script = _MODULE_DIR_.$this->name.'/script.js';
@@ -1290,3 +1290,4 @@ class ThemeInstallator extends Module
</form>';
}
}
+9 -9
View File
@@ -202,7 +202,7 @@ XML;
$price->addChild('reduction_percent', ($specificPrice AND $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.00);
$price->addChild('reduction_price', ($specificPrice AND $specificPrice['reduction_type'] == 'amount') ? (float)$specificPrice['reduction'] : 0.00);
$price->addChild('display-on-sale', (int)$sqlProduct['on_sale']);
$product->addChild('downloadable', $sqlProduct['id_product_download'] >= 1 ? 1 : 0);
$pack = Db::getInstance()->ExecuteS('
@@ -241,7 +241,7 @@ XML;
{
if (isset($imagesAlreadyDone[$imageSQL['id_image']]))
continue;
$imagesAlreadyDone[(int)$imageSQL['id_image']] = 1;
$image = $product->addChild('image');
@@ -363,7 +363,7 @@ XML;
}
}
if (!empty($group['attributes']))
if (!empty($group['attributes']))
{
foreach ($group['attributes'] AS $id_attribute => $attribute)
{
@@ -408,7 +408,7 @@ XML;
LEFT JOIN '._DB_PREFIX_.'product_attribute_image pi ON (pa.id_product_attribute = pi.id_product_attribute)
WHERE pa.id_product = '.(int)$sqlProduct['id_product']);
if(!empty($productAttributes))
if(!empty($productAttributes))
{
foreach ($productAttributes AS $productAttribute)
{
@@ -427,7 +427,7 @@ XML;
$image->addAttribute('ref-id', $productAttribute['id_image']);
}
if (isset($combinaison[$id_product_attribute]) && !empty($combinaison[$id_product_attribute]))
if (isset($combinaison[$id_product_attribute]) && !empty($combinaison[$id_product_attribute]))
{
foreach ($combinaison[$id_product_attribute] AS $id_group_attribute => $id_attribute)
{
@@ -504,7 +504,7 @@ XML;
}
closedir($dh);
}
$out .= '<div class="clear"></div></div></div>';
return $out;
}
@@ -671,13 +671,13 @@ XML;
if (Tools::getValue('trpd_hook_position') == 0)
{
Configuration::updateValue('TREEPODIA_HOOK', 0);
$this->unregisterHook(Hook::get('productFooter'));
$this->unregisterHook(Hook::getIdByName('productFooter'));
$this->registerHook('extraLeft');
}
else
{
Configuration::updateValue('TREEPODIA_HOOK', 1);
$this->unregisterHook(Hook::get('extraLeft'));
$this->unregisterHook(Hook::getIdByName('extraLeft'));
$this->registerHook('productFooter');
}
@@ -713,7 +713,7 @@ XML;
$result = '';
while (!feof($socket))
$result .= trim(fgets($socket, 1024));
fclose($socket);
}
+1 -1
View File
@@ -91,7 +91,7 @@ class TrustedShops extends Module
break;
}
$return = ($return) ? (parent::install() AND $this->registerHook('orderConfirmation') AND $this->registerHook('newOrder') AND $this->registerHook('rightColumn') AND $this->registerHook('paymentTop') AND $this->registerHook('orderConfirmation')) : $return;
$id_hook = Hook::get('payment');
$id_hook = Hook::getIdByName('payment');
$this->updatePosition($id_hook, 0, 1);
return $return;
}