From f65df2f2ae40367756b6930c9f12ecc6c36d3a8b Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 30 Sep 2011 13:50:55 +0000 Subject: [PATCH] // Norm on controllers --- classes/Controller.php | 20 +++-- classes/FrontController.php | 8 +- controllers/front/AuthController.php | 2 +- controllers/front/BestSalesController.php | 2 +- .../front/ChangeCurrencyController.php | 4 +- controllers/front/CmsController.php | 5 +- controllers/front/CompareController.php | 4 +- controllers/front/ContactController.php | 8 +- controllers/front/DiscountController.php | 4 +- controllers/front/GetFileController.php | 14 ++- controllers/front/GuestTrackingController.php | 17 ++-- controllers/front/HistoryController.php | 4 +- controllers/front/IdentityController.php | 10 +-- controllers/front/IndexController.php | 4 +- controllers/front/ManufacturerController.php | 10 +-- controllers/front/ModuleController.php | 4 +- controllers/front/MyAccountController.php | 4 +- controllers/front/NewProductsController.php | 4 +- .../front/OrderConfirmationController.php | 4 +- controllers/front/OrderController.php | 79 +++++++++-------- controllers/front/OrderDetailController.php | 20 +---- controllers/front/OrderFollowController.php | 6 +- controllers/front/OrderOpcController.php | 16 +--- controllers/front/OrderReturnController.php | 19 +--- controllers/front/OrderSlipController.php | 6 +- controllers/front/PageNotFoundController.php | 4 +- controllers/front/PasswordController.php | 6 +- controllers/front/PdfInvoiceController.php | 19 ++-- .../front/PdfOrderReturnController.php | 15 ++-- controllers/front/PdfOrderSlipController.php | 21 +++-- controllers/front/PricesDropController.php | 4 +- controllers/front/ProductController.php | 30 +++---- controllers/front/SearchController.php | 4 +- controllers/front/SitemapController.php | 4 +- controllers/front/StatisticsController.php | 87 ++++++++++++------- controllers/front/StoresController.php | 40 ++++----- controllers/front/SupplierController.php | 8 +- override/classes/_FrontController.php | 4 +- 38 files changed, 252 insertions(+), 272 deletions(-) diff --git a/classes/Controller.php b/classes/Controller.php index 46ce1f431..5431e197c 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -48,7 +48,7 @@ abstract class ControllerCore /** * @var bool check if header will be displayed */ - protected $displayHeader = false; + protected $display_header; /** * @var string template name for page content @@ -58,7 +58,7 @@ abstract class ControllerCore /** * @var string check if footer will be displayed */ - protected $displayFooter = false; + protected $display_footer; /** * @var bool If ajax parameter is detected in request, set this flag to true @@ -99,8 +99,12 @@ abstract class ControllerCore public function __construct() { - $this->displayHeader(true); - $this->displayFooter(true); + if (is_null($this->display_header)) + $this->display_header = true; + + if (is_null($this->display_footer)) + $this->display_footer = true; + $this->context = Context::getContext(); $this->ajax = Tools::getValue('ajax') || Tools::isSubmit('ajax'); } @@ -117,14 +121,14 @@ abstract class ControllerCore else $this->postProcess(); - if ($this->displayHeader) + if ($this->display_header) { $this->setMedia(); $this->initHeader(); } $this->initContent(); - if ($this->displayFooter) + if ($this->display_footer) $this->initFooter(); if ($this->ajax && method_exists($this, 'displayAjax')) @@ -135,12 +139,12 @@ abstract class ControllerCore public function displayHeader($display = true) { - $this->displayHeader = $display; + $this->display_header = $display; } public function displayFooter($display = true) { - $this->displayFooter = $display; + $this->display_footer = $display; } public function setTemplate($template) diff --git a/classes/FrontController.php b/classes/FrontController.php index 072340e1e..919115204 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -89,8 +89,8 @@ class FrontControllerCore extends Controller if ($this->ajax) { - $this->displayHeader(false); - $this->displayFooter(false); + $this->display_header = false; + $this->display_footer = false; } ob_start(); @@ -375,13 +375,13 @@ class FrontControllerCore extends Controller Tools::safePostVars(); $this->context->smarty->assign('errors', $this->errors); - if ($this->displayHeader) + if ($this->display_header) $this->context->smarty->display(_PS_THEME_DIR_.'header.tpl'); if ($this->template) $this->context->smarty->display($this->template); - if ($this->displayFooter) + if ($this->display_footer) $this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl'); // live edit diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 656d064e2..324a22e20 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -362,7 +362,7 @@ class AuthControllerCore extends FrontController $this->addJS(_THEME_JS_DIR_.'tools/statesManagement.js'); } - public function process() + public function initContent() { parent::process(); diff --git a/controllers/front/BestSalesController.php b/controllers/front/BestSalesController.php index 33c186a79..f9c720e92 100644 --- a/controllers/front/BestSalesController.php +++ b/controllers/front/BestSalesController.php @@ -29,7 +29,7 @@ class BestSalesControllerCore extends FrontController { public $php_self = 'best-sales'; - public function process() + public function initContent() { $this->productSort(); $nbProducts = (int)ProductSale::getNbSales(); diff --git a/controllers/front/ChangeCurrencyController.php b/controllers/front/ChangeCurrencyController.php index 1496a2b51..83f7a9bd5 100644 --- a/controllers/front/ChangeCurrencyController.php +++ b/controllers/front/ChangeCurrencyController.php @@ -29,9 +29,9 @@ class ChangeCurrencyControllerCore extends FrontController { /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $currency = new Currency((int)Tools::getValue('id_currency')); if (Validate::isLoadedObject($currency) && !$currency->deleted) diff --git a/controllers/front/CmsController.php b/controllers/front/CmsController.php index 87f6da2de..b35d77b48 100644 --- a/controllers/front/CmsController.php +++ b/controllers/front/CmsController.php @@ -76,11 +76,10 @@ class CmsControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - parent::process(); $parent_cat = new CMSCategory(1, $this->context->language->id); $this->context->smarty->assign('id_current_lang', $this->context->language->id); $this->context->smarty->assign('home_title', $parent_cat->name); diff --git a/controllers/front/CompareController.php b/controllers/front/CompareController.php index 2fc5c40d5..a4a52eda0 100644 --- a/controllers/front/CompareController.php +++ b/controllers/front/CompareController.php @@ -81,9 +81,9 @@ class CompareControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { //Clean compare product table CompareProduct::cleanCompareProducts('week'); diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index a3d290859..be7a69020 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -193,12 +193,12 @@ class ContactControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->assignOrderList(); - + $email = Tools::safeOutput(Tools::getValue('from', ((isset($this->context->cookie) && isset($this->context->cookie->email) && Validate::isEmail($this->context->cookie->email)) ? $this->context->cookie->email : ''))); $this->context->smarty->assign(array( @@ -221,7 +221,7 @@ class ContactControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl'); } - + /** * Assign template vars related to order list and product list ordered by the customer */ diff --git a/controllers/front/DiscountController.php b/controllers/front/DiscountController.php index 17e28f3f0..e9acfa7fc 100644 --- a/controllers/front/DiscountController.php +++ b/controllers/front/DiscountController.php @@ -34,9 +34,9 @@ class DiscountControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $discounts = Discount::getCustomerDiscounts($this->context->language->id, $this->context->customer->id, true, false); $nbDiscounts = 0; diff --git a/controllers/front/GetFileController.php b/controllers/front/GetFileController.php index a473e8b37..63dabdbe7 100644 --- a/controllers/front/GetFileController.php +++ b/controllers/front/GetFileController.php @@ -27,18 +27,14 @@ class GetFileControllerCore extends FrontController { - /** - * Assign template vars related to page content - * @see FrontController::process() - */ - public function process() - { - $this->displayHeader(false); - $this->displayFooter(false); + protected $display_header = false; + protected $display_footer = false; + public function postProcess() + { if (isset($this->context->employee) && $this->context->employee->isLoggedBack() && Tools::getValue('file')) { - /* Admin can directly access to file */ + // Admin can directly access to file $filename = Tools::getValue('file'); if (!Validate::isSha1($filename)) die(Tools::displayError()); diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 368fc8d09..80b44b99f 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -39,7 +39,7 @@ class GuestTrackingControllerCore extends FrontController if ($this->context->customer->isLogged()) Tools::redirect('history.php'); } - + /** * Start forms process * @see FrontController::postProcess() @@ -51,7 +51,7 @@ class GuestTrackingControllerCore extends FrontController $id_order = (int)Tools::getValue('id_order'); $email = Tools::getValue('email'); $order = new Order((int)$id_order); - + if (empty($id_order)) $this->errors[] = Tools::displayError('Please provide your Order ID'); else if (empty($email)) @@ -92,20 +92,21 @@ class GuestTrackingControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - parent::process(); - /* Handle brute force attacks */ if (count($this->errors)) sleep(1); - $this->context->smarty->assign(array('action' => $this->context->link->getPageLink('guest-tracking.php'), 'errors' => $this->errors)); + $this->context->smarty->assign(array( + 'action' => $this->context->link->getPageLink('guest-tracking.php'), + 'errors' => $this->errors, + )); $this->setTemplate(_PS_THEME_DIR_.'guest-tracking.tpl'); } - + /** * Assign template vars related to order tracking informations */ diff --git a/controllers/front/HistoryController.php b/controllers/front/HistoryController.php index bf5f704ff..9b5d4921f 100644 --- a/controllers/front/HistoryController.php +++ b/controllers/front/HistoryController.php @@ -46,9 +46,9 @@ class HistoryControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if ($orders = Order::getCustomerOrders($this->context->customer->id)) foreach ($orders as &$order) diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 7fd698fc1..fc3ecedbf 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -31,13 +31,13 @@ class IdentityControllerCore extends FrontController public $php_self = 'identity'; public $authRedirection = 'identity'; public $ssl = true; - + public function init() { parent::init(); $this->customer = $this->context->customer; } - + /** * Start forms process * @see FrontController::postProcess() @@ -94,14 +94,14 @@ class IdentityControllerCore extends FrontController } else $_POST = array_map('stripslashes', $this->customer->getFields()); - + return $this->customer; } /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if ($this->customer->birthday) $birthday = explode('-', $this->customer->birthday); diff --git a/controllers/front/IndexController.php b/controllers/front/IndexController.php index 0e228c11e..0f1ef81dc 100644 --- a/controllers/front/IndexController.php +++ b/controllers/front/IndexController.php @@ -31,9 +31,9 @@ class IndexControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->context->smarty->assign('HOOK_HOME', Module::hookExec('home')); $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); diff --git a/controllers/front/ManufacturerController.php b/controllers/front/ManufacturerController.php index 67dc151a2..7298a7f57 100644 --- a/controllers/front/ManufacturerController.php +++ b/controllers/front/ManufacturerController.php @@ -41,7 +41,7 @@ class ManufacturerControllerCore extends FrontController if (Validate::isLoadedObject($this->manufacturer)) parent::canonicalRedirection($this->context->link->getManufacturerLink($this->manufacturer)); } - + /** * Initialize manufaturer controller * @see FrontController::init() @@ -66,9 +66,9 @@ class ManufacturerControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if (Validate::isLoadedObject($this->manufacturer) && $this->manufacturer->active && $this->manufacturer->isAssociatedToGroupShop()) { @@ -82,7 +82,7 @@ class ManufacturerControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'manufacturer-list.tpl'); } } - + /** * Assign template vars if displaying one manufacturer */ @@ -96,7 +96,7 @@ class ManufacturerControllerCore extends FrontController 'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''), 'manufacturer' => $this->manufacturer)); } - + /** * Assign template vars if displaying the manufacturer list */ diff --git a/controllers/front/ModuleController.php b/controllers/front/ModuleController.php index 578d76b1c..0cfaf77d0 100644 --- a/controllers/front/ModuleController.php +++ b/controllers/front/ModuleController.php @@ -35,9 +35,9 @@ class ModuleControllerCore extends FrontController { /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { // Check module existence $name = Tools::getValue('module'); diff --git a/controllers/front/MyAccountController.php b/controllers/front/MyAccountController.php index d9dedfb09..e6a69984d 100644 --- a/controllers/front/MyAccountController.php +++ b/controllers/front/MyAccountController.php @@ -40,9 +40,9 @@ class MyAccountControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->context->smarty->assign(array( 'voucherAllowed' => (int)(Configuration::get('PS_VOUCHERS')), diff --git a/controllers/front/NewProductsController.php b/controllers/front/NewProductsController.php index 3694b017e..35ac0dffe 100644 --- a/controllers/front/NewProductsController.php +++ b/controllers/front/NewProductsController.php @@ -37,9 +37,9 @@ class NewProductsControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->productSort(); diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index 7f7f0492c..9ce74a292 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -66,9 +66,9 @@ class OrderConfirmationControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->context->smarty->assign(array( 'is_guest' => $this->context->customer->is_guest, diff --git a/controllers/front/OrderController.php b/controllers/front/OrderController.php index 6b2a70b7b..9be768f82 100644 --- a/controllers/front/OrderController.php +++ b/controllers/front/OrderController.php @@ -43,45 +43,41 @@ class OrderControllerCore extends ParentOrderController if (!$this->nbProducts) $this->step = -1; - /* If some products have disappear */ + // If some products have disappear if (!$this->context->cart->checkQuantities()) { $this->step = 0; $this->errors[] = Tools::displayError('An item in your cart is no longer available for this quantity, you cannot proceed with your order.'); } - /* Check minimal amount */ + // Check minimal amount $currency = Currency::getCurrency((int)$this->context->cart->id_currency); $orderTotal = $this->context->cart->getOrderTotal(); - $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency); - if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimalPurchase && $this->step != -1) + $minimal_purchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency); + if ($this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS) < $minimal_purchase && $this->step != -1) { $this->step = 0; - $this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency). + $this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimal_purchase, $currency). ' '.Tools::displayError('is required in order to validate your order.'); } if (!$this->context->customer->isLogged(true) && in_array($this->step, array(1, 2, 3))) Tools::redirect('index.php?controller=authentication&back='.urlencode('order.php&step='.$this->step)); - - if ($this->nbProducts) - $this->context->smarty->assign('virtual_cart', $isVirtualCart); - } - - public function displayHeader($display = true) - { - if (!Tools::getValue('ajax')) - parent::displayHeader(); } /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - /* 4 steps to the order */ + global $isVirtualCart; + + if ($this->nbProducts) + $this->context->smarty->assign('virtual_cart', $isVirtualCart); + + // 4 steps to the order switch ((int)$this->step) { case -1; @@ -104,7 +100,7 @@ class OrderControllerCore extends ParentOrderController break; case 3: - //Test that the conditions (so active) were accepted by the customer + // Test that the conditions (so active) were accepted by the customer $cgv = Tools::getValue('cgv'); if (Configuration::get('PS_CONDITIONS') && (!Validate::isBool($cgv))) Tools::redirect('index.php?controller=order&step=2'); @@ -112,7 +108,8 @@ class OrderControllerCore extends ParentOrderController if (Tools::isSubmit('processCarrier')) $this->processCarrier(); $this->autoStep(); - /* Bypass payment step if total is 0 */ + + // Bypass payment step if total is 0 if (($id_order = $this->_checkFreeOrder()) && $id_order) { if ($this->context->customer->is_guest) @@ -146,8 +143,8 @@ class OrderControllerCore extends ParentOrderController private function processAddressFormat() { - $addressDelivery = new Address((int)($this->context->cart->id_address_delivery)); - $addressInvoice = new Address((int)($this->context->cart->id_address_invoice)); + $addressDelivery = new Address((int)$this->context->cart->id_address_delivery); + $addressInvoice = new Address((int)$this->context->cart->id_address_invoice); $invoiceAddressFields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country, false, true); $deliveryAddressFields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country, false, true); @@ -157,21 +154,17 @@ class OrderControllerCore extends ParentOrderController 'dlv_adr_fields' => $deliveryAddressFields)); } - public function displayFooter($display = true) - { - if (!Tools::getValue('ajax')) - parent::displayFooter(); - } - - /* Order process controller */ + /** + * Order process controller + */ public function autoStep() { global $isVirtualCart; if ($this->step >= 2 && (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice)) Tools::redirect('index.php?controller=order&step=1'); - $delivery = new Address((int)($this->context->cart->id_address_delivery)); - $invoice = new Address((int)($this->context->cart->id_address_invoice)); + $delivery = new Address((int)$this->context->cart->id_address_delivery); + $invoice = new Address((int)$this->context->cart->id_address_invoice); if ($delivery->deleted || $invoice->deleted) { @@ -194,25 +187,29 @@ class OrderControllerCore extends ParentOrderController $this->errors[] = Tools::displayError('This address is not in a valid area.'); else { - $this->context->cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); - $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); + $this->context->cart->id_address_delivery = (int)Tools::getValue('id_address_delivery'); + $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int)Tools::getValue('id_address_invoice'); if (!$this->context->cart->update()) $this->errors[] = Tools::displayError('An error occurred while updating your cart.'); if (Tools::isSubmit('message')) $this->_updateMessage(Tools::getValue('message')); } - if (count($this->errors)) + + if ($this->errors) { if (Tools::getValue('ajax')) die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}'); $this->step = 1; } - if (Tools::getValue('ajax')) + + if ($this->ajax) die(true); } - /* Carrier step */ + /** + * Carrier step + */ protected function processCarrier() { global $orderTotal; @@ -231,7 +228,9 @@ class OrderControllerCore extends ParentOrderController $orderTotal = $this->context->cart->getOrderTotal(); } - /* Address step */ + /** + * Address step + */ protected function _assignAddress() { parent::_assignAddress(); @@ -241,7 +240,9 @@ class OrderControllerCore extends ParentOrderController Tools::redirect('index.php?controller=order&step=2'); } - /* Carrier step */ + /** + * Carrier step + */ protected function _assignCarrier() { if (!isset($this->context->customer->id)) @@ -254,7 +255,9 @@ class OrderControllerCore extends ParentOrderController $this->context->smarty->assign('is_guest', (isset($this->context->customer->is_guest) ? $this->context->customer->is_guest : 0)); } - /* Payment step */ + /** + * Payment step + */ protected function _assignPayment() { global $orderTotal; diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 54b21bd3e..213a1d6b0 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -41,7 +41,7 @@ class OrderDetailControllerCore extends FrontController header('Cache-Control: no-cache, must-revalidate'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); } - + /** * Start forms process * @see FrontController::postProcess() @@ -118,12 +118,12 @@ class OrderDetailControllerCore extends FrontController } } } - + /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if (!$id_order = (int)(Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) $this->errors[] = Tools::displayError('Order ID required'); @@ -204,16 +204,4 @@ class OrderDetailControllerCore extends FrontController $this->addCSS(_THEME_CSS_DIR_.'addresses.css'); } } - - public function displayHeader($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayHeader(); - } - - public function displayFooter($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayFooter(); - } } diff --git a/controllers/front/OrderFollowController.php b/controllers/front/OrderFollowController.php index 496c21a43..0e5f511d0 100644 --- a/controllers/front/OrderFollowController.php +++ b/controllers/front/OrderFollowController.php @@ -71,12 +71,12 @@ class OrderFollowControllerCore extends FrontController Tools::redirect('index.php?controller=order-follow'); } } - + /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $ordersReturn = OrderReturn::getOrdersReturn($this->context->customer->id); if (Tools::isSubmit('errorQuantity')) diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 085a5706c..c0f87eff1 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -227,9 +227,9 @@ class OrderOpcControllerCore extends ParentOrderController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { // SHOPPING CART $this->_assignSummaryInformations(); @@ -286,18 +286,6 @@ class OrderOpcControllerCore extends ParentOrderController $this->setTemplate(_PS_THEME_DIR_.'order-opc.tpl'); } - public function displayHeader($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayHeader(); - } - - public function displayFooter($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayFooter(); - } - protected function _getGuestInformations() { $customer = $this->context->customer; diff --git a/controllers/front/OrderReturnController.php b/controllers/front/OrderReturnController.php index 7b912e265..9108cf3bc 100644 --- a/controllers/front/OrderReturnController.php +++ b/controllers/front/OrderReturnController.php @@ -71,31 +71,18 @@ class OrderReturnControllerCore extends FrontController $this->errors[] = Tools::displayError('Cannot find this order return'); } } - + /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - parent::process(); $this->context->smarty->assign(array( 'errors' => $this->errors, 'nbdaysreturn' => (int)(Configuration::get('PS_ORDER_RETURN_NB_DAYS')) )); $this->setTemplate(_PS_THEME_DIR_.'order-return.tpl'); } - - public function displayHeader($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayHeader(); - } - - public function displayFooter($display = true) - { - if (Tools::getValue('ajax') != 'true') - parent::displayFooter(); - } } diff --git a/controllers/front/OrderSlipController.php b/controllers/front/OrderSlipController.php index bd69e0397..854f54254 100644 --- a/controllers/front/OrderSlipController.php +++ b/controllers/front/OrderSlipController.php @@ -43,11 +43,11 @@ class OrderSlipControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - $this->context->smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int)($this->context->cookie->id_customer))); + $this->context->smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int)$this->context->cookie->id_customer)); $this->setTemplate(_PS_THEME_DIR_.'order-slip.tpl'); } } diff --git a/controllers/front/PageNotFoundController.php b/controllers/front/PageNotFoundController.php index 2f7efc10c..f126ccc06 100644 --- a/controllers/front/PageNotFoundController.php +++ b/controllers/front/PageNotFoundController.php @@ -31,9 +31,9 @@ class PageNotFoundControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); } diff --git a/controllers/front/PasswordController.php b/controllers/front/PasswordController.php index c1a2c4793..f5549e5c9 100644 --- a/controllers/front/PasswordController.php +++ b/controllers/front/PasswordController.php @@ -105,12 +105,12 @@ class PasswordControllerCore extends FrontController else if (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); } - + /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->setTemplate(_PS_THEME_DIR_.'password.tpl'); } diff --git a/controllers/front/PdfInvoiceController.php b/controllers/front/PdfInvoiceController.php index b80e32323..f941b5b09 100644 --- a/controllers/front/PdfInvoiceController.php +++ b/controllers/front/PdfInvoiceController.php @@ -27,21 +27,20 @@ class PdfInvoiceControllerCore extends FrontController { - /** - * Assign template vars related to page content - * @see FrontController::process() - */ - public function process() - { - $this->displayHeader(false); - $this->displayFooter(false); + protected $display_header = false; + protected $display_footer = false; + public function postProcess() + { if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key')) Tools::redirect('index.php?controller=authentication&back=pdf-invoice'); - if (!(int)(Configuration::get('PS_INVOICE'))) + + if (!(int)Configuration::get('PS_INVOICE')) die(Tools::displayError('Invoices are disabled in this shop.')); + if (isset($_GET['id_order']) && Validate::isUnsignedId($_GET['id_order'])) - $order = new Order((int)($_GET['id_order'])); + $order = new Order($_GET['id_order']); + if (!isset($order) || !Validate::isLoadedObject($order)) die(Tools::displayError('Invoice not found')); else if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key'))) diff --git a/controllers/front/PdfOrderReturnController.php b/controllers/front/PdfOrderReturnController.php index b7e942e3b..58537936f 100644 --- a/controllers/front/PdfOrderReturnController.php +++ b/controllers/front/PdfOrderReturnController.php @@ -27,20 +27,17 @@ class PdfOrderReturnControllerCore extends FrontController { - /** - * Assign template vars related to page content - * @see FrontController::process() - */ - public function process() - { - $this->displayHeader(false); - $this->displayFooter(false); + protected $display_header = false; + protected $display_footer = false; + public function postProcess() + { if (!$this->context->customer->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow'); if (isset($_GET['id_order_return']) && Validate::isUnsignedId($_GET['id_order_return'])) - $orderReturn = new OrderReturn((int)($_GET['id_order_return'])); + $orderReturn = new OrderReturn($_GET['id_order_return']); + if (!isset($orderReturn) || !Validate::isLoadedObject($orderReturn)) die(Tools::displayError('Order return not found')); else if ($orderReturn->id_customer != $this->context->customer->id) diff --git a/controllers/front/PdfOrderSlipController.php b/controllers/front/PdfOrderSlipController.php index dc8b4fd86..6efd57d6c 100644 --- a/controllers/front/PdfOrderSlipController.php +++ b/controllers/front/PdfOrderSlipController.php @@ -27,28 +27,27 @@ class PdfOrderSlipControllerCore extends FrontController { - /** - * Assign template vars related to page content - * @see FrontController::process() - */ - public function process() - { - $this->displayHeader(false); - $this->displayFooter(false); + protected $display_header = false; + protected $display_footer = false; + public function postProcess() + { if (!$this->context->customer->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow'); if (isset($_GET['id_order_slip']) && Validate::isUnsignedId($_GET['id_order_slip'])) - $orderSlip = new OrderSlip((int)($_GET['id_order_slip'])); + $orderSlip = new OrderSlip($_GET['id_order_slip']); + if (!isset($orderSlip) || !Validate::isLoadedObject($orderSlip)) die(Tools::displayError('Order return not found')); else if ($orderSlip->id_customer != $this->context->customer->id) die(Tools::displayError('Order return not found')); - $order = new Order((int)($orderSlip->id_order)); + + $order = new Order($orderSlip->id_order); if (!Validate::isLoadedObject($order)) die(Tools::displayError('Order not found')); - $order->products = OrderSlip::getOrdersSlipProducts((int)($orderSlip->id), $order); + + $order->products = OrderSlip::getOrdersSlipProducts((int)$orderSlip->id, $order); $ref = null; PDF::invoice($order, 'D', false, $ref, $orderSlip); } diff --git a/controllers/front/PricesDropController.php b/controllers/front/PricesDropController.php index e0d520a9b..27d9b1276 100644 --- a/controllers/front/PricesDropController.php +++ b/controllers/front/PricesDropController.php @@ -37,9 +37,9 @@ class PricesDropControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->productSort(); $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 3fd07c865..977f84dda 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -74,7 +74,7 @@ class ProductControllerCore extends FrontController if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id)) $this->product->quantity = 0; - + $this->product->description = $this->transformDescriptionWithImg($this->product->description); if (!Validate::isLoadedObject($this->product)) @@ -101,13 +101,11 @@ class ProductControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { - parent::process(); - - if (!count($this->errors)) + if (!$this->errors) { // Assign to the tempate the id of the virtuale product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)($this->product->id))); @@ -153,7 +151,7 @@ class ProductControllerCore extends FrontController $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); - + // Assign template vars related to the images $this->assignImages(); @@ -197,7 +195,7 @@ class ProductControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'product.tpl'); } - + /** * Assign price and tax to the template */ @@ -223,9 +221,9 @@ class ProductControllerCore extends FrontController $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); $quantityDiscounts = SpecificPrice::getQuantityDiscounts((int)$this->product->id, $this->context->shop->getID(true), (int)$this->context->cookie->id_currency, $id_country, $id_group); - + $productPrice = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false); - + $this->context->smarty->assign(array( 'quantity_discounts' => $this->formatQuantityDiscounts($quantityDiscounts, $productPrice, (float)$tax), 'ecotax_tax_inc' => $ecotaxTaxAmount, @@ -238,7 +236,7 @@ class ProductControllerCore extends FrontController 'tax_enabled' => Configuration::get('PS_TAX') )); } - + /** * Assign template vars related to images */ @@ -271,7 +269,7 @@ class ProductControllerCore extends FrontController if (count($productImages)) $this->context->smarty->assign('images', $productImages); } - + /** * Assign template vars related to attribute groups and colors */ @@ -301,7 +299,7 @@ class ProductControllerCore extends FrontController 'group_type' => $row['group_type'], 'default' => -1, ); - + $groups = array(); $combinationImages = $this->product->getCombinationImages($this->context->language->id); foreach ($attributesGroups AS $k => $row) @@ -388,7 +386,7 @@ class ProductControllerCore extends FrontController $availableDate = Tools::displayDate($row['available_date'], $this->context->language->id); else $availableDate = $row['available_date']; - + $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int)($row['id_attribute']); $combinations[$row['id_product_attribute']]['price'] = (float)($row['price']); @@ -433,7 +431,7 @@ class ProductControllerCore extends FrontController 'combinationImages' => $combinationImages)); } } - + /** * Assign template vars related to category */ @@ -474,7 +472,7 @@ class ProductControllerCore extends FrontController } else $this->context->smarty->assign('path', Tools::getPath((int)$this->product->id_category_default, $this->product->name)); - + $this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id)); $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category))); } diff --git a/controllers/front/SearchController.php b/controllers/front/SearchController.php index 8eda95bc6..c7b308cee 100644 --- a/controllers/front/SearchController.php +++ b/controllers/front/SearchController.php @@ -45,9 +45,9 @@ class SearchControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $query = urldecode(Tools::getValue('q')); if ($this->ajax_search) diff --git a/controllers/front/SitemapController.php b/controllers/front/SitemapController.php index aac26735a..23b8e7fb9 100644 --- a/controllers/front/SitemapController.php +++ b/controllers/front/SitemapController.php @@ -38,9 +38,9 @@ class SitemapControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); diff --git a/controllers/front/StatisticsController.php b/controllers/front/StatisticsController.php index 133c6a31d..9aa925810 100644 --- a/controllers/front/StatisticsController.php +++ b/controllers/front/StatisticsController.php @@ -27,43 +27,64 @@ class StatisticsControllerCore extends FrontController { - /** - * Assign template vars related to page content - * @see FrontController::process() - */ - public function process() - { - $this->displayHeader(false); - $this->displayFooter(false); + public $display_header = false; + public $display_footer = false; - if (!isset($_POST['token']) || !isset($_POST['type'])) + protected $param_token; + + public function postProcess() + { + $this->param_token = Tools::getValue('token'); + if (!$this->param_token) die; if ($_POST['type'] == 'navinfo') - { - if (sha1($_POST['id_guest']._COOKIE_KEY_) != $_POST['token']) - die; - - $guest = new Guest((int)$_POST['id_guest']); - $guest->javascript = true; - $guest->screen_resolution_x = (int)($_POST['screen_resolution_x']); - $guest->screen_resolution_y = (int)($_POST['screen_resolution_y']); - $guest->screen_color = (int)($_POST['screen_color']); - $guest->sun_java = (int)($_POST['sun_java']); - $guest->adobe_flash = (int)($_POST['adobe_flash']); - $guest->adobe_director = (int)($_POST['adobe_director']); - $guest->apple_quicktime = (int)($_POST['apple_quicktime']); - $guest->real_player = (int)($_POST['real_player']); - $guest->windows_media = (int)($_POST['windows_media']); - $guest->update(); - } + $this->processNavigationStats(); else if ($_POST['type'] == 'pagetime') - { - if (sha1($_POST['id_connections'].$_POST['id_page'].$_POST['time_start']._COOKIE_KEY_) != $_POST['token']) - die; - if (!Validate::isInt($_POST['time']) || $_POST['time'] <= 0) - die; - Connection::setPageTime((int)$_POST['id_connections'], (int)$_POST['id_page'], substr($_POST['time_start'], 0, 19), intval($_POST['time'])); - } + $this->processPageTime(); + else + exit; + } + + /** + * Log statistics on navigation (resolution, plugins, etc.) + */ + protected function processNavigationStats() + { + $id_guest = (int)Tools::getValue('id_guest'); + if (sha1($id_guest._COOKIE_KEY_) != $this->param_token) + die; + + $guest = new Guest($id_guest); + $guest->javascript = true; + $guest->screen_resolution_x = (int)Tools::getValue('screen_resolution_x'); + $guest->screen_resolution_y = (int)Tools::getValue('screen_resolution_y'); + $guest->screen_color = (int)Tools::getValue('screen_color'); + $guest->sun_java = (int)Tools::getValue('sun_java'); + $guest->adobe_flash = (int)Tools::getValue('adobe_flash'); + $guest->adobe_director = (int)Tools::getValue('adobe_director'); + $guest->apple_quicktime = (int)Tools::getValue('apple_quicktime'); + $guest->real_player = (int)Tools::getValue('real_player'); + $guest->windows_media = (int)Tools::getValue('windows_media'); + $guest->update(); + } + + /** + * Log statistics on time spend on pages + */ + protected function processPageTime() + { + $id_connection = (int)Tools::getValue('id_connections'); + $time = (int)Tools::getValue('time'); + $time_start = Tools::getValue('time_start'); + $id_page = (int)Tools::getValue('id_page'); + + if (sha1($id_connection.$id_page.$time_start._COOKIE_KEY_) != $this->param_token) + die; + + if ($time <= 0) + die; + + Connection::setPageTime($id_connection, $id_page, substr($time_start, 0, 19), $time); } } \ No newline at end of file diff --git a/controllers/front/StoresController.php b/controllers/front/StoresController.php index e6f403651..37f8a4cbf 100644 --- a/controllers/front/StoresController.php +++ b/controllers/front/StoresController.php @@ -99,20 +99,20 @@ class StoresControllerCore extends FrontController foreach ($stores as &$store) $store['has_picture'] = file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg'); - + $this->context->smarty->assign(array( 'simplifiedStoresDiplay' => true, 'stores' => $stores )); } - + public function getStores() { $distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); if (!in_array($distanceUnit, array('km', 'mi'))) $distanceUnit = 'km'; - + if (Tools::getValue('all') == 1) { $stores = Db::getInstance()->ExecuteS(' @@ -149,10 +149,10 @@ class StoresControllerCore extends FrontController ORDER BY distance ASC LIMIT 0,20'); } - + return $stores; } - + /** * Assign template vars for classical stores */ @@ -163,25 +163,25 @@ class StoresControllerCore extends FrontController $distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); if (!in_array($distanceUnit, array('km', 'mi'))) $distanceUnit = 'km'; - + $this->context->smarty->assign(array( 'distance_unit' => $distanceUnit, 'simplifiedStoresDiplay' => false, 'stores' => $this->getStores() )); } - + /** * Display the Xml for showing the nodes in the google map */ protected function displayAjax() { $stores = $this->getStores(); - + $dom = new DOMDocument('1.0'); $node = $dom->createElement('markers'); $parnode = $dom->appendChild($node); - + $days[1] = 'Monday'; $days[2] = 'Tuesday'; $days[3] = 'Wednesday'; @@ -189,7 +189,7 @@ class StoresControllerCore extends FrontController $days[5] = 'Friday'; $days[6] = 'Saturday'; $days[7] = 'Sunday'; - + foreach ($stores as $store) { $days_datas = array(); @@ -197,12 +197,12 @@ class StoresControllerCore extends FrontController $newnode = $parnode->appendChild($node); $newnode->setAttribute('name', $store['name']); $address = $this->processStoreAddress($store); - + $other = ''; if (!empty($store['hours'])) { $hours = unserialize($store['hours']); - + for ($i = 1; $i < 8; $i++) { $hours_datas = array(); @@ -212,10 +212,10 @@ class StoresControllerCore extends FrontController } $this->context->smarty->assign('days_datas', $days_datas); $this->context->smarty->assign('id_country', $store['id_country']); - + $other .= $this->context->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); } - + $newnode->setAttribute('addressNoHtml', strip_tags(str_replace('
', ' ', $address))); $newnode->setAttribute('address', $address); $newnode->setAttribute('other', $other); @@ -224,20 +224,20 @@ class StoresControllerCore extends FrontController $newnode->setAttribute('has_store_picture', file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg')); $newnode->setAttribute('lat', (float)($store['latitude'])); $newnode->setAttribute('lng', (float)($store['longitude'])); - + if (isset($store['distance'])) $newnode->setAttribute('distance', (int)($store['distance'])); } - + header('Content-type: text/xml'); die($dom->saveXML()); } - + /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if (Configuration::get('PS_STORES_SIMPLIFIED')) $stores = $this->assignStoresSimplified(); @@ -250,7 +250,7 @@ class StoresControllerCore extends FrontController 'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'), 'searchUrl' => $this->context->link->getPageLink('stores') )); - + $this->setTemplate(_PS_THEME_DIR_.'stores.tpl'); } diff --git a/controllers/front/SupplierController.php b/controllers/front/SupplierController.php index 8e1df5951..789a51da2 100644 --- a/controllers/front/SupplierController.php +++ b/controllers/front/SupplierController.php @@ -68,9 +68,9 @@ class SupplierControllerCore extends FrontController /** * Assign template vars related to page content - * @see FrontController::process() + * @see FrontController::initContent() */ - public function process() + public function initContent() { if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToGroupShop()) { @@ -84,7 +84,7 @@ class SupplierControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'supplier-list.tpl'); } } - + /** * Assign template vars if displaying one supplier */ @@ -99,7 +99,7 @@ class SupplierControllerCore extends FrontController 'supplier' => $this->supplier, )); } - + /** * Assign template vars if displaying the supplier list */ diff --git a/override/classes/_FrontController.php b/override/classes/_FrontController.php index d05e59f6e..759031c8e 100755 --- a/override/classes/_FrontController.php +++ b/override/classes/_FrontController.php @@ -192,7 +192,7 @@ class FrontController extends FrontControllerCore $this->_memory[2] = memory_get_usage(); $this->_time[2] = microtime(true); - if ($this->displayHeader) + if ($this->display_header) { $this->setMedia(); $this->initHeader(); @@ -205,7 +205,7 @@ class FrontController extends FrontControllerCore $this->_memory[4] = memory_get_usage(); $this->_time[4] = microtime(true); - if ($this->displayFooter) + if ($this->display_footer) $this->initFooter(); $this->_memory[5] = memory_get_usage();