public function testPathWithDefault()
 {
     $_SERVER['SCRIPT_NAME'] = '/default/index.php';
     $this->Dispatcher = Dispatcher::getInstance();
     $this->Dispatcher->setUrl('mycontroller/myaction/p1/1/p2/2/p3/3');
     $this->assertEqual(UrlComponent::path('default/index'), '/default/index');
 }
Beispiel #2
0
 /**
  * Create a link to a photo
  *
  * @param mixed $photo Photos object (can be an ID supplier, but deprecated)
  * @param string $alias
  * @param int $id_lang
  * @return string
  */
 public static function getPhotosLink($photo, $alias = null, $id_lang = null, $id_shop = null)
 {
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     if ($id_shop === null) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop);
     $dispatcher = Dispatcher::getInstance();
     if (!is_object($photo)) {
         if ($alias !== null && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_title', $id_shop)) {
             return $url . $dispatcher->createUrl('photo_rule', $id_lang, array('id' => (int) $photo, 'rewrite' => (string) $alias), $this->allow, '', $id_shop);
         }
         $photo = new Photos($photo, $id_lang);
     }
     // Set available keywords
     $params = array();
     $params['id'] = $photo->id;
     $params['rewrite'] = !$alias ? $photo->link_rewrite : $alias;
     $params['meta_keywords'] = Tools::str2url($photo->meta_keywords);
     $params['meta_title'] = Tools::str2url($photo->meta_title);
     return $url . $dispatcher->createUrl('photo_rule', $id_lang, $params, $this->allow, '', $id_shop);
 }
Beispiel #3
0
 /**
  * Create a simple link
  *
  * @param string $controller
  * @param string|array $request
  * @param bool $request_url_encode Use URL encode
  *
  * @return string Page link
  */
 public function getPageLink($controller, $request = null, $request_url_encode = false)
 {
     //If $controller contains '&' char, it means that $controller contains request data and must be parsed first
     $p = strpos($controller, '&');
     if ($p !== false) {
         $request = substr($controller, $p + 1);
         $request_url_encode = false;
         $controller = substr($controller, 0, $p);
     }
     $controller = Tools::strReplaceFirst('.php', '', $controller);
     //need to be unset because getModuleLink need those params when rewrite is enable
     if (is_array($request)) {
         if (isset($request['module'])) {
             unset($request['module']);
         }
         if (isset($request['controller'])) {
             unset($request['controller']);
         }
     } else {
         $request = html_entity_decode($request);
         if ($request_url_encode) {
             $request = urlencode($request);
         }
         parse_str($request, $request);
     }
     $uri_path = Dispatcher::getInstance()->createUrl($controller, $request, false, '');
     return $this->getBaseLink() . ltrim($uri_path, '/');
 }
Beispiel #4
0
 static function logException(\Exception $e)
 {
     $requestURI = Dispatcher::getInstance()->getCalledURL();
     $requestURILine = sprintf(static::$messageConfigs['default']['line'], 'Request URI', $requestURI);
     $message = static::computeMessage($e, static::$messageConfigs['default'], array($requestURILine));
     \ManiaLib\Utils\Logger::error($message);
 }
Beispiel #5
0
 protected function _prepareHook($params)
 {
     $languages = Language::getLanguages(true, $this->context->shop->id);
     if (!count($languages)) {
         return false;
     }
     $link = new Link();
     if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
         $default_rewrite = array();
         if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) {
             $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']);
             }
         }
         if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) {
             $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']);
             }
         }
         if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) {
             $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
             foreach ($rewrite_infos as $infos) {
                 $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
                 $default_rewrite[$infos['id_lang']] = $arr_link;
             }
         }
         $this->smarty->assign('lang_rewrite_urls', $default_rewrite);
     }
     return true;
 }
Beispiel #6
0
 public function hookHeader()
 {
     $this->page_name = Dispatcher::getInstance()->getController();
     if ($this->page_name == 'index') {
         $this->_assignMedia();
     }
 }
Beispiel #7
0
 public function hookHeader()
 {
     $this->page_name = Dispatcher::getInstance()->getController();
     if ($this->page_name == 'index') {
         $this->context->controller->addJS($this->_path . 'blockfacebook.js');
     }
 }
Beispiel #8
0
    private function ModuleHookExec($moduleName, $hook_name)
    {
        $output = '';
        $moduleInstance = Module::getInstanceByName($moduleName);
        if (Validate::isLoadedObject($moduleInstance) && $moduleInstance->id) {
            $altern = 0;
            $id_hook = Hook::getIdByName($hook_name);
            $retro_hook_name = Hook::getRetroHookName($hook_name);
            $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
            if ($disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($moduleInstance->name, self::$native_module)) {
                return '';
            }
            //check disable module
            $device = (int) $this->context->getDevice();
            if (Db::getInstance()->getValue('
			SELECT COUNT(`id_module`) FROM ' . _DB_PREFIX_ . 'module_shop
			WHERE enable_device & ' . (int) $device . ' AND id_module=' . (int) $moduleInstance->id . Shop::addSqlRestriction()) == 0) {
                return '';
            }
            // Check permissions
            $exceptions = $moduleInstance->getExceptions($id_hook);
            $controller = Dispatcher::getInstance()->getController();
            $controller_obj = Context::getContext()->controller;
            //check if current controller is a module controller
            if (isset($controller_obj->module) && Validate::isLoadedObject($controller_obj->module)) {
                $controller = 'module-' . $controller_obj->module->name . '-' . $controller;
            }
            if (in_array($controller, $exceptions)) {
                return '';
            }
            //retro compat of controller names
            $matching_name = array('authentication' => 'auth', 'productscomparison' => 'compare');
            if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                return '';
            }
            if (Validate::isLoadedObject($this->context->employee) && !$moduleInstance->getPermission('view', $this->context->employee)) {
                return '';
            }
            if (!isset($hook_args['cookie']) or !$hook_args['cookie']) {
                $hook_args['cookie'] = $this->context->cookie;
            }
            if (!isset($hook_args['cart']) or !$hook_args['cart']) {
                $hook_args['cart'] = $this->context->cart;
            }
            $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
            $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
            if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
                $hook_args['altern'] = ++$altern;
                // Call hook method
                if ($hook_callable) {
                    $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
                } elseif ($hook_retro_callable) {
                    $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
                }
                $output .= $display;
            }
        }
        return $output;
    }
 /**
  * get live Edit URL
  */
 public function getLiveEditUrl($live_edit_params)
 {
     $url = $this->context->shop->getBaseURL() . Dispatcher::getInstance()->createUrl('index', (int) $this->context->language->id, $live_edit_params);
     if (Configuration::get('PS_REWRITING_SETTINGS')) {
         $url = str_replace('index.php', '', $url);
     }
     return $url;
 }
 public function hookHeader($params)
 {
     $this->page_name = Dispatcher::getInstance()->getController();
     if ($this->page_name == 'product') {
         $this->context->controller->addCSS($this->_path . 'sendtoafriend.css', 'all');
         $this->context->controller->addJS($this->_path . 'sendtoafriend.js');
     }
 }
Beispiel #11
0
 public function addOneAndEcho($i)
 {
     $i++;
     echo $i . '-' . $this->name . '<br />';
     $instance = Dispatcher::getInstance();
     $instance::publish($this, $i);
     return $i;
 }
Beispiel #12
0
 /**
  * Взаимодействуем с каждым подписанным объектом
  *
  * @param $object
  */
 public static function publish($object)
 {
     $instance = Dispatcher::getInstance();
     $id = spl_object_hash($object);
     $subscribers = $instance->listeners[$id];
     foreach ($subscribers as $subscriber) {
         $subscriber->doSomething();
     }
 }
Beispiel #13
0
 public function __construct()
 {
     $Dispatcher = Dispatcher::getInstance();
     $Dispatcher->setApp('app');
     $Dispatcher->setControllerName('myController');
     $Dispatcher->setActionName('myAction');
     i18n::setCulture('fr');
     i18n::addDefinitions($this->def);
 }
Beispiel #14
0
 public static function publish($object, $i)
 {
     $instance = Dispatcher::getInstance();
     $id = spl_object_hash($object);
     $subscribers = $instance->listeners[$id];
     foreach ($subscribers as $subscriber) {
         $i = $subscriber->addOneAndEcho($i);
     }
 }
Beispiel #15
0
 public function load()
 {
     $this->assertIsRunning();
     $this->loadConfig();
     $dispatcher = Dispatcher::getInstance();
     $request = new Request($_SERVER['REQUEST_METHOD']);
     $response = new Response();
     $dispatcher->forward($request, $response);
 }
 public function __construct()
 {
     $this->controller_type = 'modulefront';
     $this->module = Module::getInstanceByName(Tools::getValue('module'));
     if (!$this->module->active) {
         Tools::redirect('index');
     }
     $this->page_name = 'module-' . $this->module->name . '-' . Dispatcher::getInstance()->getController();
     parent::__construct();
 }
 public function __construct()
 {
     $this->controller_type = 'modulefront';
     $this->module = Module::getInstanceByName(Tools::getValue('module'));
     if (!$this->module->active) {
         Tools::redirect('index');
     }
     $this->page_name = 'module-' . $this->module->name . '-' . Dispatcher::getInstance()->getController();
     parent::__construct();
     $this->display_column_left = isset($this->page_name) && is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasLeftColumn($this->page_name) : true;
     $this->display_column_right = isset($this->page_name) && is_object(Context::getContext()->theme) ? Context::getContext()->theme->hasRightColumn($this->page_name) : true;
 }
Beispiel #18
0
 public function hookHeader()
 {
     $this->_controller = Dispatcher::getInstance()->getController();
     if (!empty($this->context->controller->php_self)) {
         $this->_controller = $this->context->controller->php_self;
     }
     if ($this->_handleNobots()) {
         // no need to add anything else as robots should ignore this page
         return;
     }
     $out = "\n" . $this->_displayHreflang() . $this->_displayCanonical();
     return $out;
 }
Beispiel #19
0
 public function __construct()
 {
     $config = Dispatcher::getInstance()->get('config');
     if (isset($this->adapter[$config->get('driver')])) {
         return $this->adapter[$config->get('driver')];
     }
     switch ($config->get('driver')) {
         case 'mysql':
         default:
             $this->adapter[$config->get('driver')] = new \mysqli($config->get('host'), $config->get('user'), $config->get('password'), $config->get('db'));
             $this->driver = 'mysql';
             break;
     }
     return $this->adapter[$this->driver];
 }
Beispiel #20
0
 public function __set($name, $value)
 {
     if (FALSE === $this->template) {
         $dispatcher = \Dispatcher::getInstance();
         $this->template = $dispatcher->controller() . '/' . $dispatcher->action();
     }
     if (is_string($this->template)) {
         $this->template = new \View($this->template);
         if (!$this->render) {
             $ref = new \ReflectionMethod($this, 'render');
             $ref->setAccessible(TRUE);
             \Event::register(\Dispatcher::PostDispatch, array($ref, 'invoke'), array($this));
             $this->render = TRUE;
         }
     }
     $this->template->set($name, $value);
 }
Beispiel #21
0
 public function __construct()
 {
     $this->controller_type = 'modulefront';
     $this->module = Module::getInstanceByName(Tools::getValue('module'));
     if (!$this->module->active) {
         Tools::redirect('index');
     }
     $this->page_name = 'module-' . $this->module->name . '-' . Dispatcher::getInstance()->getController();
     parent::__construct();
     header('Content-Type: application/javascript');
     $cookiestring = Tools::getValue('c');
     if ($cookiestring != '') {
         if (isset($this->context->cookie->{$cookiestring})) {
             echo AmzPayments::prepareCookieValueForAmazonPaymentsUse($this->context->cookie->{$cookiestring});
         }
     }
     exit;
 }
Beispiel #22
0
 public function hookHeader()
 {
     $this->page_name = Dispatcher::getInstance()->getController();
     if ($this->page_name == 'contact') {
         $default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'));
         $this->context->controller->addCSS($this->_path . 'customcontactpage.css', 'all');
         if (Configuration::get('customcontactpage_show')) {
             if (Configuration::get('PS_SSL_ENABLED')) {
                 $apiUrl = 'https://maps-api-ssl.google.com/maps/api/js?sensor=true&amp;region=' . substr($default_country->iso_code, 0, 2);
             } else {
                 $apiUrl = 'http://maps.google.com/maps/api/js?sensor=true&amp;region=' . substr($default_country->iso_code, 0, 2);
             }
             $this->smarty->assign(array('apiurl' => $apiUrl));
             $this->context->controller->addJS($this->_path . 'customcontactpage.js');
             return $this->display(__FILE__, 'apiurl.tpl');
         }
     }
 }
Beispiel #23
0
 static function orderBy($field, $label)
 {
     $Dispatcher = Dispatcher::getInstance();
     $params = $Dispatcher->getParams();
     $orderby = $field;
     $dir = 'asc';
     $reverse = 'desc';
     $class = '';
     $filter = Config::get('pagination.filter');
     $path = UrlComponent::whitelist(array_remove($filter, array('orderby', 'dir')));
     if (isset($params['orderby']) && $params['orderby'] == $field) {
         $orderby = $params['orderby'];
         if (isset($params['dir']) && $params['dir'] == 'asc') {
             $class = 'class="order-asc"';
             $reverse = 'desc';
         } else {
             $class = 'class="order-desc"';
             $reverse = 'asc';
         }
     }
     return '<a href="' . $path . '/orderby/' . $orderby . '/dir/' . $reverse . '" ' . $class . '>' . $label . '</a>';
 }
Beispiel #24
0
 public function __construct($config, $env = null)
 {
     $app = self::app();
     if (!is_null($app)) {
         throw new Exception\StartupError('Only one application can be initialized');
     }
     $this->_environ = $env;
     $config = $this->_loadConfig($config);
     if ($config == null || !$config instanceof Config_Abstract || $this->parseOptions($config->toArray()) != true) {
         throw new Exception\StartupError('Initialization of application config failed');
     }
     //$this->parseOptions($config->toArray());
     $this->_config = $config;
     //request initialization
     $request = new Request\Http();
     if ($request == null) {
         throw new Exception\StartupError('Initialization of request failed');
     }
     //dispatcher
     $this->_dispatcher = Dispatcher::getInstance();
     if ($this->_dispatcher == null || !$this->_dispatcher instanceof Dispatcher) {
         throw new Exception\StartupError('Instantiation of dispatcher failed');
     }
     $this->_dispatcher->setRequest($request);
     //loader initialization
     $loader = Loader::getInstance(isset($this->_options['local_library']) ? $this->_options['local_library'] : '', G::iniGet('yaf.library'));
     if ($loader == null || !$loader instanceof Loader) {
         throw new Exception\StartupError('Initialization of application auto loader failed');
     }
     if (isset($this->_options['local_namespace']) && $this->_options['local_namespace'] != '') {
         $namespace = str_replace(array(',', ' '), array(':', ':'), $this->_options['local_namespace']);
         $loader->registerLocalNamespace($namespace);
     }
     self::$_app = $this;
     if (G::get('throwException') == false) {
         set_exception_handler(array($this, 'exceptionHandler'));
     }
 }
Beispiel #25
0
    /**
     * @return int Current page ID
     */
    public static function getCurrentId()
    {
        $controller = Dispatcher::getInstance()->getController();
        $page_type_id = Page::getPageTypeByName($controller);
        // Some pages must be distinguished in order to record exactly what is being seen
        // @todo dispatcher module
        $special_array = array('product' => 'id_product', 'category' => 'id_category', 'order' => 'step', 'manufacturer' => 'id_manufacturer');
        $where = '';
        $insert_data = array('id_page_type' => $page_type_id);
        if (array_key_exists($controller, $special_array)) {
            $object_id = Tools::getValue($special_array[$controller], null);
            $where = ' AND `id_object` = ' . (int) $object_id;
            $insert_data['id_object'] = (int) $object_id;
        }
        $sql = 'SELECT `id_page`
				FROM `' . _DB_PREFIX_ . 'page`
				WHERE `id_page_type` = ' . (int) $page_type_id . $where;
        $result = Db::getInstance()->getRow($sql);
        if ($result['id_page']) {
            return $result['id_page'];
        }
        Db::getInstance()->insert('page', $insert_data, true);
        return Db::getInstance()->Insert_ID();
    }
 public function init()
 {
     /*
      * Globals are DEPRECATED as of version 1.5.
      * Use the Context to access objects instead.
      * Example: $this->context->cart
      */
     global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     parent::init();
     // If current URL use SSL, set it true (used a lot for module redirect)
     if (Tools::usingSecureMode()) {
         $useSSL = true;
     }
     // For compatibility with globals, DEPRECATED as of version 1.5
     $css_files = $this->css_files;
     $js_files = $this->js_files;
     // If we call a SSL controller without SSL or a non SSL controller with SSL, we redirect with the right protocol
     if (Configuration::get('PS_SSL_ENABLED') && $_SERVER['REQUEST_METHOD'] != 'POST' && $this->ssl != Tools::usingSecureMode()) {
         header('HTTP/1.1 301 Moved Permanently');
         header('Cache-Control: no-cache');
         if ($this->ssl) {
             header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
         } else {
             header('Location: ' . Tools::getShopDomain(true) . $_SERVER['REQUEST_URI']);
         }
         exit;
     }
     if ($this->ajax) {
         $this->display_header = false;
         $this->display_footer = false;
     }
     // if account created with the 2 steps register process, remove 'accoun_created' from cookie
     if (isset($this->context->cookie->account_created)) {
         $this->context->smarty->assign('account_created', 1);
         unset($this->context->cookie->account_created);
     }
     ob_start();
     // Init cookie language
     // @TODO This method must be moved into switchLanguage
     Tools::setCookieLanguage($this->context->cookie);
     $protocol_link = Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? 'https://' : 'http://';
     $useSSL = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $link = new Link($protocol_link, $protocol_content);
     $this->context->link = $link;
     if ($id_cart = (int) $this->recoverCart()) {
         $this->context->cookie->id_cart = (int) $id_cart;
     }
     if ($this->auth && !$this->context->customer->isLogged($this->guestAllowed)) {
         Tools::redirect('index.php?controller=authentication' . ($this->authRedirection ? '&back=' . $this->authRedirection : ''));
     }
     /* Theme is missing */
     if (!is_dir(_PS_THEME_DIR_)) {
         throw new PrestaShopException(sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\'))));
     }
     if (Configuration::get('PS_GEOLOCATION_ENABLED')) {
         if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault)) {
             $this->context->country = $newDefault;
         }
     }
     $currency = Tools::setCurrency($this->context->cookie);
     if (isset($_GET['logout']) || $this->context->customer->logged && Customer::isBanned($this->context->customer->id)) {
         $this->context->customer->logout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     } elseif (isset($_GET['mylogout'])) {
         $this->context->customer->mylogout();
         Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     }
     /* Cart already exists */
     if ((int) $this->context->cookie->id_cart) {
         $cart = new Cart($this->context->cookie->id_cart);
         if ($cart->OrderExists()) {
             unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
             $this->context->cookie->check_cgv = false;
         } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 && !FrontController::isInWhitelistForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
             unset($this->context->cookie->id_cart, $cart);
         } elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency) {
             if ($this->context->cookie->id_customer) {
                 $cart->id_customer = (int) $this->context->cookie->id_customer;
             }
             $cart->id_lang = (int) $this->context->cookie->id_lang;
             $cart->id_currency = (int) $currency->id;
             $cart->update();
         }
         /* Select an address if not set */
         if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer) {
             $to_update = false;
             if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
                 $to_update = true;
                 $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
                 $to_update = true;
                 $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             }
             if ($to_update) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || !$cart->id) {
         $cart = new Cart();
         $cart->id_lang = (int) $this->context->cookie->id_lang;
         $cart->id_currency = (int) $this->context->cookie->id_currency;
         $cart->id_guest = (int) $this->context->cookie->id_guest;
         $cart->id_shop_group = (int) $this->context->shop->id_shop_group;
         $cart->id_shop = $this->context->shop->id;
         if ($this->context->cookie->id_customer) {
             $cart->id_customer = (int) $this->context->cookie->id_customer;
             $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
             $cart->id_address_invoice = $cart->id_address_delivery;
         } else {
             $cart->id_address_delivery = 0;
             $cart->id_address_invoice = 0;
         }
         // Needed if the merchant want to give a free product to every visitors
         $this->context->cart = $cart;
         CartRule::autoAddToCart($this->context);
     } else {
         $this->context->cart = $cart;
     }
     /* get page name to display it in body id */
     // Are we in a payment module
     $module_name = '';
     if (Validate::isModuleName(Tools::getValue('module'))) {
         $module_name = Tools::getValue('module');
     }
     if (!empty($this->page_name)) {
         $page_name = $this->page_name;
     } elseif (!empty($this->php_self)) {
         $page_name = $this->php_self;
     } elseif (Tools::getValue('fc') == 'module' && $module_name != '' && Module::getInstanceByName($module_name) instanceof PaymentModule) {
         $page_name = 'module-payment-submit';
     } elseif (preg_match('#^' . preg_quote($this->context->shop->physical_uri, '#') . 'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
         $page_name = 'module-' . $m[1] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[2]);
     } else {
         $page_name = Dispatcher::getInstance()->getController();
         $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
     }
     $this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
     $this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
     /* Breadcrumb */
     $navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
     $this->context->smarty->assign('navigationPipe', $navigationPipe);
     // Automatically redirect to the canonical URL if needed
     if (!empty($this->php_self) && !Tools::getValue('ajax')) {
         $this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
     }
     Product::initPricesComputation();
     $display_tax_label = $this->context->country->display_tax_label;
     if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
         $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $country = new Country((int) $infos['id_country']);
         $this->context->country = $country;
         if (Validate::isLoadedObject($country)) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $languages = Language::getLanguages(true, $this->context->shop->id);
     $meta_language = array();
     foreach ($languages as $lang) {
         $meta_language[] = $lang['iso_code'];
     }
     $compared_products = array();
     if (Configuration::get('PS_COMPARATOR_MAX_ITEM') && isset($this->context->cookie->id_compare)) {
         $compared_products = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
     }
     $this->context->smarty->assign(array('mobile_device' => $this->context->getMobileDevice(), 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $this->context->cookie, 'page_name' => $page_name, 'hide_left_column' => !$this->display_column_left, 'hide_right_column' => !$this->display_column_right, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__, 'base_uri' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__ . (!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''), 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $this->context->language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => $languages, 'meta_language' => implode(',', $meta_language), 'priceDisplay' => Product::getTaxCalculationMethod((int) $this->context->cookie->id_customer), 'is_logged' => (bool) $this->context->customer->isLogged(), 'is_guest' => (bool) $this->context->customer->isGuest(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'show_taxes' => (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX')), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE') || !(bool) Group::getCurrent()->show_prices, 'b2b_enable' => (bool) Configuration::get('PS_B2B_ENABLE'), 'request' => $link->getPaginationLink(false, false, false, true), 'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'), 'quick_view' => (bool) Configuration::get('PS_QUICK_VIEW'), 'shop_phone' => Configuration::get('PS_SHOP_PHONE'), 'compared_products' => is_array($compared_products) ? $compared_products : array(), 'comparator_max_item' => (int) Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     // Add the tpl files directory for mobile
     if ($this->useMobileTheme()) {
         $this->context->smarty->assign(array('tpl_mobile_uri' => _PS_THEME_MOBILE_DIR_));
     }
     // Deprecated
     $this->context->smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $this->context->customer->isLogged(), 'customerName' => $this->context->customer->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : false));
     $assign_array = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     // Add the images directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['img_mobile_dir'] = _THEME_MOBILE_IMG_DIR_;
     }
     // Add the CSS directory for mobile
     if ($this->useMobileTheme()) {
         $assign_array['css_mobile_dir'] = _THEME_MOBILE_CSS_DIR_;
     }
     foreach ($assign_array as $assign_key => $assign_value) {
         if (substr($assign_value, 0, 1) == '/' || $protocol_content == 'https://') {
             $this->context->smarty->assign($assign_key, $protocol_content . Tools::getMediaServer($assign_value) . $assign_value);
         } else {
             $this->context->smarty->assign($assign_key, $assign_value);
         }
     }
     /*
      * These shortcuts are DEPRECATED as of version 1.5.
      * Use the Context to access objects instead.
      * Example: $this->context->cart
      */
     self::$cookie = $this->context->cookie;
     self::$cart = $cart;
     self::$smarty = $this->context->smarty;
     self::$link = $link;
     $defaultCountry = $this->context->country;
     $this->displayMaintenancePage();
     if ($this->restrictedCountry) {
         $this->displayRestrictedCountryPage();
     }
     if (Tools::isSubmit('live_edit') && !$this->checkLiveEditAccess()) {
         Tools::redirect('index.php?controller=404');
     }
     $this->iso = $iso;
     $this->context->cart = $cart;
     $this->context->currency = $currency;
 }
Beispiel #27
0
 public function hookdisplayCategorySlider($params)
 {
     $module_name = '';
     if (Validate::isModuleName(Tools::getValue('module'))) {
         $module_name = Tools::getValue('module');
     }
     //if (!$this->isCached('categoryslider.tpl', $this->getCacheId()))
     if (!empty($this->context->controller->php_self)) {
         $page_name = $this->context->controller->php_self;
     } elseif (Tools::getValue('fc') == 'module' && $module_name != '' && Module::getInstanceByName($module_name) instanceof PaymentModule) {
         $page_name = 'module-payment-submit';
     } elseif (preg_match('#^' . preg_quote($this->context->shop->physical_uri, '#') . 'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
         $page_name = 'module-' . $m[1] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[2]);
     } else {
         $page_name = Dispatcher::getInstance()->getController();
         $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
     }
     if (strlen($page_name) <= 0) {
         return '';
     }
     if ($page_name == 'category') {
         $id_category = (int) Tools::getValue('id_category');
     } elseif ($page_name == 'product') {
         $id_product = (int) Tools::getValue('id_product');
         $product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
         $id_category = $product->id_category_default;
     } else {
         return '';
     }
     $slider = array('width' => Configuration::get('CATESLIDER_WIDTH'), 'height' => Configuration::get('CATESLIDER_HEIGHT'), 'speed' => Configuration::get('CATESLIDER_SPEED'), 'pause' => Configuration::get('CATESLIDER_PAUSE'), 'loop' => Configuration::get('CATESLIDER_LOOP'));
     if (isset($id_category) && $id_category && Validate::isUnsignedId($id_category)) {
         $slides = $this->getSlides(true, $id_category);
     } else {
         return '';
     }
     $check_slide = true;
     if (!$slides && count($slides) < 1) {
         $check_slide = false;
     }
     $this->smarty->assign('categoryslider_slides', $slides);
     $this->smarty->assign('categoryslider', $slider);
     if (!$check_slide) {
         return '';
     }
     // Check if not a mobile theme
     if ($this->context->getMobileDevice() != false) {
         return false;
     }
     return $this->display(__FILE__, 'categoryslider.tpl');
 }
 public function hookDisplayTop($param)
 {
     $this->user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $this->page_name = Dispatcher::getInstance()->getController();
     if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId())) {
         if (Tools::isEmpty($this->_menu)) {
             $this->makeMenu();
         }
         $shop_id = (int) $this->context->shop->id;
         $shop_group_id = Shop::getGroupFromShop($shop_id);
         $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id));
         $this->smarty->assign('MENU', $this->_menu);
         $this->smarty->assign('this_path', $this->_path);
     }
     $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId());
     return $html;
 }
Beispiel #29
0
 public static function GetSmartBlogLink($rewrite = 'smartblog', $params = null, $id_shop = null, $id_lang = null)
 {
     $url = smartblog::GetSmartBlogUrl();
     $dispatcher = Dispatcher::getInstance();
     $id_lang = (int) Context::getContext()->language->id;
     $force_routes = (bool) Configuration::get('PS_REWRITING_SETTINGS');
     if ($params != null) {
         return $url . $dispatcher->createUrl($rewrite, $id_lang, $params, $force_routes);
     } else {
         $params = array();
         return $url . $dispatcher->createUrl($rewrite, $id_lang, $params, $force_routes);
     }
 }
 public function hookDisplayNavigationBar($param)
 {
     $this->_itemClass = isset($param['itemClass']) ? $param['itemClass'] : '';
     $this->_itemHead = isset($param['itemHead']) ? $param['itemHead'] : '';
     $this->_itemTail = isset($param['itemTail']) ? $param['itemTail'] : '';
     $this->_subMenuHead = isset($param['submenuHead']) ? $param['submenuHead'] : '';
     $this->_subMenuTail = isset($param['submenuTail']) ? $param['submenuTail'] : '';
     $this->_subMenuClass = isset($param['submenuClass']) ? $param['submenuClass'] : '';
     $this->_subItemClass = isset($param['subitemClass']) ? $param['subitemClass'] : '';
     $this->_subItemHead = isset($param['subitemHead']) ? $param['subitemHead'] : '';
     $this->_subItemtail = isset($param['subitemTail']) ? $param['subitemTail'] : '';
     $this->_showAll = isset($param['showAll']) ? $param['showAll'] : '';
     $this->_showAllResponsive = isset($param['showAllResponsive']) ? $param['showAllResponsive'] : '';
     $this->user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $this->page_name = Dispatcher::getInstance()->getController();
     $smarty_cache_id = 'blocktopmenu_mod-' . $this->page_name . '-' . (int) $this->context->shop->id . '-' . implode(', ', $this->user_groups) . '-' . (int) $this->context->language->id . '-' . (int) Tools::getValue('id_category') . '-' . (int) Tools::getValue('id_manufacturer') . '-' . (int) Tools::getValue('id_supplier') . '-' . (int) Tools::getValue('id_cms') . '-' . (int) Tools::getValue('id_product');
     $this->context->smarty->cache_lifetime = 31536000;
     Tools::enableCache();
     if (!$this->isCached('blocktopmenu_mod.tpl', $smarty_cache_id)) {
         $menu = $this->makeMenu();
         $this->smarty->assign('MENU_HOME', Configuration::get('MOD_BLOCKTOPMENU_HOME'));
         $this->smarty->assign('MENU', $menu);
         $this->smarty->assign('this_path', $this->_path);
         $this->smarty->assign('subMenuClass', $this->_subMenuClass);
         $this->smarty->assign('menuItemClass', $this->_itemClass);
         $this->smarty->assign('submenuItemClassName', $this->_subItemClass);
     }
     $html = $this->display(__FILE__, 'blocktopmenu_mod.tpl', $smarty_cache_id);
     Tools::restoreCacheSettings();
     return $html;
 }