示例#1
0
 public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disableMuliviews = false)
 {
     $tab = array('ErrorDocument' => array(), 'RewriteEngine' => array(), 'RewriteRule' => array());
     $multilang = Language::countActiveLanguages() > 1;
     // ErrorDocument
     $tab['ErrorDocument']['comment'] = '# Catch 404 errors';
     $tab['ErrorDocument']['content'] = '404 ' . __PS_BASE_URI__ . '404.php';
     // RewriteEngine
     $tab['RewriteEngine']['comment'] = '# URL rewriting module activation';
     // RewriteRules
     $tab['RewriteRule']['comment'] = '# URL rewriting rules';
     // Compatibility with the old image filesystem
     if (Configuration::get('PS_LEGACY_IMAGES')) {
         $tab['RewriteRule']['content']['^([a-z0-9]+)\\-([a-z0-9]+)(\\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1-$2$3.jpg [L]';
         $tab['RewriteRule']['content']['^([0-9]+)\\-([0-9]+)/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1-$2.jpg [L]';
     }
     // Rewriting for product image id < 100 millions
     $tab['RewriteRule']['content']['^([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$1$2.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$1$2$3.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$1$2$3$4.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$4/$1$2$3$4$5.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\\.jpg$'] = _PS_PROD_IMG_ . '$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]';
     $tab['RewriteRule']['content']['^c/([0-9]+)(\\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\\.jpg$'] = 'img/c/$1$2.jpg [L]';
     $tab['RewriteRule']['content']['^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\\.jpg$'] = 'img/c/$1.jpg [L]';
     if ($multilang) {
         $tab['RewriteRule']['content']['^([a-z]{2})/[a-zA-Z0-9-]*/([0-9]+)\\-[a-zA-Z0-9-]*\\.html'] = 'product.php?id_product=$2&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\\-[a-zA-Z0-9-]*\\.html'] = 'product.php?id_product=$2&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$2&isolang=$1&noredirect=1 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$2&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/content/([0-9]+)\\-[a-zA-Z0-9-]*'] = 'cms.php?isolang=$1&id_cms=$2 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/content/category/([0-9]+)\\-[a-zA-Z0-9-]*'] = 'cms.php?isolang=$1&id_cms_category=$2 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)__[a-zA-Z0-9-]*'] = 'supplier.php?isolang=$1&id_supplier=$2 [QSA,L]';
         $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)_[a-zA-Z0-9-]*'] = 'manufacturer.php?isolang=$1&id_manufacturer=$2 [QSA,L]';
     }
     // PS BASE URI automaticaly prepend the string, do not use PS defines for the image directories
     $tab['RewriteRule']['content']['^([0-9]+)(\\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\\.jpg$'] = 'img/c/$1$2.jpg [L]';
     $tab['RewriteRule']['content']['^([0-9]+)\\-[a-zA-Z0-9-]*\\.html'] = 'product.php?id_product=$1 [QSA,L]';
     $tab['RewriteRule']['content']['^[a-zA-Z0-9-]*/([0-9]+)\\-[a-zA-Z0-9-]*\\.html'] = 'product.php?id_product=$1 [QSA,L]';
     // Notice : the id_category rule has to be after product rules.
     // If not, category with number in their name will result a bug
     $tab['RewriteRule']['content']['^([0-9]+)\\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$1&noredirect=1 [QSA,L]';
     $tab['RewriteRule']['content']['^([0-9]+)\\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$1 [QSA,L]';
     $tab['RewriteRule']['content']['^([0-9]+)__([a-zA-Z0-9-]*)'] = 'supplier.php?id_supplier=$1 [QSA,L]';
     $tab['RewriteRule']['content']['^([0-9]+)_([a-zA-Z0-9-]*)'] = 'manufacturer.php?id_manufacturer=$1 [QSA,L]';
     $tab['RewriteRule']['content']['^content/([0-9]+)\\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms=$1 [QSA,L]';
     $tab['RewriteRule']['content']['^content/category/([0-9]+)\\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms_category=$1 [QSA,L]';
     // Compatibility with the old URLs
     if (!Configuration::get('PS_INSTALL_VERSION') or version_compare(Configuration::get('PS_INSTALL_VERSION'), '1.4.0.7') == -1) {
         // This is a nasty copy/paste of the previous links, but with "lang-en" instead of "en"
         // Do not update it when you add something in the one at the top, it's only for the old links
         $tab['RewriteRule']['content']['^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\\-([a-zA-Z0-9-]*)\\.html'] = 'product.php?id_product=$3&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^lang-([a-z]{2})/([0-9]+)\\-([a-zA-Z0-9-]*)\\.html'] = 'product.php?id_product=$2&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^lang-([a-z]{2})/([0-9]+)\\-([a-zA-Z0-9-]*)'] = 'category.php?id_category=$2&isolang=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^content/([0-9]+)\\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms=$1 [QSA,L]';
         $tab['RewriteRule']['content']['^content/category/([0-9]+)\\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms_category=$1 [QSA,L]';
     }
     Language::loadLanguages();
     $default_meta = Meta::getMetasByIdLang((int) Configuration::get('PS_LANG_DEFAULT'));
     if ($multilang) {
         foreach (Language::getLanguages() as $language) {
             foreach (Meta::getMetasByIdLang($language['id_lang']) as $key => $meta) {
                 if (!empty($meta['url_rewrite']) and Validate::isLinkRewrite($meta['url_rewrite'])) {
                     $tab['RewriteRule']['content']['^' . $language['iso_code'] . '/' . $meta['url_rewrite'] . '$'] = $meta['page'] . '.php?isolang=' . $language['iso_code'] . ' [QSA,L]';
                 } elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '') {
                     $tab['RewriteRule']['content']['^' . $language['iso_code'] . '/' . $default_meta[$key]['url_rewrite'] . '$'] = $default_meta[$key]['page'] . '.php?isolang=' . $language['iso_code'] . ' [QSA,L]';
                 }
             }
             $tab['RewriteRule']['content']['^' . $language['iso_code'] . '$'] = $language['iso_code'] . '/ [QSA,L]';
             $tab['RewriteRule']['content']['^' . $language['iso_code'] . '/([^?&]*)$'] = '$1?isolang=' . $language['iso_code'] . ' [QSA,L]';
         }
     } else {
         foreach ($default_meta as $key => $meta) {
             if (!empty($meta['url_rewrite'])) {
                 $tab['RewriteRule']['content']['^' . $meta['url_rewrite'] . '$'] = $meta['page'] . '.php [QSA,L]';
             } elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '') {
                 $tab['RewriteRule']['content']['^' . $default_meta[$key]['url_rewrite'] . '$'] = $default_meta[$key]['page'] . '.php [QSA,L]';
             }
         }
     }
     if (!($writeFd = @fopen($path, 'w'))) {
         return false;
     }
     // PS Comments
     fwrite($writeFd, "# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution\n");
     fwrite($writeFd, "# WARNING: PLEASE DO NOT MODIFY THIS FILE MANUALLY. IF NECESSARY, ADD YOUR SPECIFIC CONFIGURATION WITH THE HTACCESS GENERATOR IN BACK OFFICE\n");
     fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n");
     if (!empty($specific)) {
         fwrite($writeFd, $specific);
     }
     // RewriteEngine
     fwrite($writeFd, "\n<IfModule mod_rewrite.c>\n");
     if ($disableMuliviews) {
         fwrite($writeFd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
     }
     fwrite($writeFd, $tab['RewriteEngine']['comment'] . "\nRewriteEngine on\n\n");
     fwrite($writeFd, $tab['RewriteRule']['comment'] . "\n");
     // Webservice
     fwrite($writeFd, 'RewriteRule ^api/?(.*)$ ' . __PS_BASE_URI__ . "webservice/dispatcher.php?url=\$1 [QSA,L]\n");
     // Classic URL rewriting
     if ($rewrite_settings) {
         foreach ($tab['RewriteRule']['content'] as $rule => $url) {
             fwrite($writeFd, 'RewriteRule ' . $rule . ' ' . __PS_BASE_URI__ . $url . "\n");
         }
     }
     fwrite($writeFd, "</IfModule>\n\n");
     // ErrorDocument
     fwrite($writeFd, $tab['ErrorDocument']['comment'] . "\nErrorDocument " . $tab['ErrorDocument']['content'] . "\n");
     // Cache control
     if ($cache_control) {
         $cacheControl = "\n<IfModule mod_expires.c>\n\tExpiresActive On\n\tExpiresByType image/gif \"access plus 1 month\"\n\tExpiresByType image/jpeg \"access plus 1 month\"\n\tExpiresByType image/png \"access plus 1 month\"\n\tExpiresByType text/css \"access plus 1 week\"\n\tExpiresByType text/javascript \"access plus 1 week\"\n\tExpiresByType application/javascript \"access plus 1 week\"\n\tExpiresByType application/x-javascript \"access plus 1 week\"\n\tExpiresByType image/x-icon \"access plus 1 year\"\n</IfModule>\n\nFileETag INode MTime Size\n<IfModule mod_deflate.c>\n\tAddOutputFilterByType DEFLATE text/html\n\tAddOutputFilterByType DEFLATE text/css\n\tAddOutputFilterByType DEFLATE text/javascript\n\tAddOutputFilterByType DEFLATE application/javascript\n\tAddOutputFilterByType DEFLATE application/x-javascript\n</IfModule>\n\t\t\t\t";
         fwrite($writeFd, $cacheControl);
     }
     fclose($writeFd);
     Module::hookExec('afterCreateHtaccess');
     return true;
 }
    public function displayAjaxGetKpi()
    {
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        switch (Tools::getValue('kpi')) {
            case 'conversion_rate':
                $visitors = AdminStatsController::getVisits(true, date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')), false);
                $orders = AdminStatsController::getOrders(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')), false);
                // $data = array();
                // $from = strtotime(date('Y-m-d 00:00:00', strtotime('-31 day')));
                // $to = strtotime(date('Y-m-d 23:59:59', strtotime('-1 day')));
                // for ($date = $from; $date <= $to; $date = strtotime('+1 day', $date))
                // if (isset($visitors[$date]) && $visitors[$date])
                // $data[$date] = round(100 * ((isset($orders[$date]) && $orders[$date]) ? $orders[$date] : 0) / $visitors[$date], 2);
                // else
                // $data[$date] = 0;
                $visits_sum = $visitors;
                //array_sum($visitors);
                $orders_sum = $orders;
                //array_sum($orders);
                if ($visits_sum) {
                    $value = round(100 * $orders_sum / $visits_sum, 2);
                } elseif ($orders_sum) {
                    $value = '&infin;';
                } else {
                    $value = 0;
                }
                $value .= '%';
                // ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', Tools::jsonEncode($data));
                ConfigurationKPI::updateValue('CONVERSION_RATE', $value);
                ConfigurationKPI::updateValue('CONVERSION_RATE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))));
                break;
            case 'abandoned_cart':
                $value = AdminStatsController::getAbandonedCarts(date('Y-m-d H:i:s', strtotime('-2 day')), date('Y-m-d H:i:s', strtotime('-1 day')));
                ConfigurationKPI::updateValue('ABANDONED_CARTS', $value);
                ConfigurationKPI::updateValue('ABANDONED_CARTS_EXPIRE', strtotime('+1 hour'));
                break;
            case 'installed_modules':
                $value = AdminStatsController::getInstalledModules();
                ConfigurationKPI::updateValue('INSTALLED_MODULES', $value);
                ConfigurationKPI::updateValue('INSTALLED_MODULES_EXPIRE', strtotime('+2 min'));
                break;
            case 'disabled_modules':
                $value = AdminStatsController::getDisabledModules();
                ConfigurationKPI::updateValue('DISABLED_MODULES', $value);
                ConfigurationKPI::updateValue('DISABLED_MODULES_EXPIRE', strtotime('+2 min'));
                break;
            case 'update_modules':
                $value = AdminStatsController::getModulesToUpdate();
                ConfigurationKPI::updateValue('UPDATE_MODULES', $value);
                ConfigurationKPI::updateValue('UPDATE_MODULES_EXPIRE', strtotime('+2 min'));
                break;
            case 'percent_product_stock':
                $value = AdminStatsController::getPercentProductStock();
                ConfigurationKPI::updateValue('PERCENT_PRODUCT_STOCK', $value);
                ConfigurationKPI::updateValue('PERCENT_PRODUCT_STOCK_EXPIRE', strtotime('+4 hour'));
                break;
            case 'product_avg_gross_margin':
                $value = AdminStatsController::getProductAverageGrossMargin();
                ConfigurationKPI::updateValue('PRODUCT_AVG_GROSS_MARGIN', $value);
                ConfigurationKPI::updateValue('PRODUCT_AVG_GROSS_MARGIN_EXPIRE', strtotime('+6 hour'));
                break;
            case 'disabled_categories':
                $value = AdminStatsController::getDisabledCategories();
                ConfigurationKPI::updateValue('DISABLED_CATEGORIES', $value);
                ConfigurationKPI::updateValue('DISABLED_CATEGORIES_EXPIRE', strtotime('+2 hour'));
                break;
            case 'disabled_products':
                $value = AdminStatsController::getDisabledProducts();
                ConfigurationKPI::updateValue('DISABLED_PRODUCTS', $value);
                ConfigurationKPI::updateValue('DISABLED_PRODUCTS_EXPIRE', strtotime('+2 hour'));
                break;
            case '8020_sales_catalog':
                $value = AdminStatsController::get8020SalesCatalog(date('Y-m-d', strtotime('-1 month')), date('Y-m-d'));
                $value = sprintf($this->l('%d%% of your Catalog'), $value);
                ConfigurationKPI::updateValue('8020_SALES_CATALOG', $value);
                ConfigurationKPI::updateValue('8020_SALES_CATALOG_EXPIRE', strtotime('+12 hour'));
                break;
            case 'empty_categories':
                $value = AdminStatsController::getEmptyCategories();
                ConfigurationKPI::updateValue('EMPTY_CATEGORIES', $value);
                ConfigurationKPI::updateValue('EMPTY_CATEGORIES_EXPIRE', strtotime('+2 hour'));
                break;
            case 'customer_main_gender':
                $value = AdminStatsController::getCustomerMainGender();
                if ($value === false) {
                    $value = $this->l('No customers', null, null, false);
                } elseif ($value['type'] == 'female') {
                    $value = sprintf($this->l('%d%% Women Customers', null, null, false), $value['value']);
                } elseif ($value['type'] == 'male') {
                    $value = sprintf($this->l('%d%% Men Customers', null, null, false), $value['value']);
                } else {
                    $value = sprintf($this->l('%d%% Neutral Customers', null, null, false), $value['value']);
                }
                ConfigurationKPI::updateValue('CUSTOMER_MAIN_GENDER', array($this->context->language->id => $value));
                ConfigurationKPI::updateValue('CUSTOMER_MAIN_GENDER_EXPIRE', array($this->context->language->id => strtotime('+1 day')));
                break;
            case 'avg_customer_age':
                $value = sprintf($this->l('%d years', null, null, false), AdminStatsController::getAverageCustomerAge(), 1);
                ConfigurationKPI::updateValue('AVG_CUSTOMER_AGE', $value);
                ConfigurationKPI::updateValue('AVG_CUSTOMER_AGE_EXPIRE', strtotime('+1 day'));
                break;
            case 'pending_messages':
                $value = (int) AdminStatsController::getPendingMessages();
                ConfigurationKPI::updateValue('PENDING_MESSAGES', $value);
                ConfigurationKPI::updateValue('PENDING_MESSAGES_EXPIRE', strtotime('+5 min'));
                break;
            case 'avg_msg_response_time':
                $value = sprintf($this->l('%.1f hours', null, null, false), AdminStatsController::getAverageMessageResponseTime(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day'))));
                ConfigurationKPI::updateValue('AVG_MSG_RESPONSE_TIME', $value);
                ConfigurationKPI::updateValue('AVG_MSG_RESPONSE_TIME_EXPIRE', strtotime('+4 hour'));
                break;
            case 'messages_per_thread':
                $value = round(AdminStatsController::getMessagesPerThread(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day'))), 1);
                ConfigurationKPI::updateValue('MESSAGES_PER_THREAD', $value);
                ConfigurationKPI::updateValue('MESSAGES_PER_THREAD_EXPIRE', strtotime('+12 hour'));
                break;
            case 'newsletter_registrations':
                $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
				SELECT COUNT(*)
				FROM `' . _DB_PREFIX_ . 'customer`
				WHERE newsletter = 1
				' . Shop::addSqlRestriction(Shop::SHARE_ORDER));
                if (Module::isInstalled('blocknewsletter')) {
                    $value += Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
					SELECT COUNT(*)
					FROM `' . _DB_PREFIX_ . 'newsletter`
					WHERE active = 1
					' . Shop::addSqlRestriction(Shop::SHARE_ORDER));
                }
                ConfigurationKPI::updateValue('NEWSLETTER_REGISTRATIONS', $value);
                ConfigurationKPI::updateValue('NEWSLETTER_REGISTRATIONS_EXPIRE', strtotime('+6 hour'));
                break;
            case 'enabled_languages':
                $value = Language::countActiveLanguages();
                ConfigurationKPI::updateValue('ENABLED_LANGUAGES', $value);
                ConfigurationKPI::updateValue('ENABLED_LANGUAGES_EXPIRE', strtotime('+1 min'));
                break;
            case 'frontoffice_translations':
                $themes = Theme::getThemes();
                $languages = Language::getLanguages();
                $total = $translated = 0;
                foreach ($themes as $theme) {
                    foreach ($languages as $language) {
                        $kpi_key = substr(strtoupper($theme->name . '_' . $language['iso_code']), 0, 16);
                        $total += ConfigurationKPI::get('TRANSLATE_TOTAL_' . $kpi_key);
                        $translated += ConfigurationKPI::get('TRANSLATE_DONE_' . $kpi_key);
                    }
                }
                $value = 0;
                if ($translated) {
                    $value = round(100 * $translated / $total, 1);
                }
                $value .= '%';
                ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS', $value);
                ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS_EXPIRE', strtotime('+2 min'));
                break;
            case 'main_country':
                if (!($row = AdminStatsController::getMainCountry(date('Y-m-d', strtotime('-30 day')), date('Y-m-d')))) {
                    $value = $this->l('No orders', null, null, false);
                } else {
                    $country = new Country($row['id_country'], $this->context->language->id);
                    $value = sprintf($this->l('%d%% %s', null, null, false), $row['orders'], $country->name);
                }
                ConfigurationKPI::updateValue('MAIN_COUNTRY', array($this->context->language->id => $value));
                ConfigurationKPI::updateValue('MAIN_COUNTRY_EXPIRE', array($this->context->language->id => strtotime('+1 day')));
                break;
            case 'orders_per_customer':
                $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
				SELECT COUNT(*)
				FROM `' . _DB_PREFIX_ . 'customer` c
				WHERE active = 1
				' . Shop::addSqlRestriction());
                if ($value) {
                    $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
					SELECT COUNT(*)
					FROM `' . _DB_PREFIX_ . 'orders` o
					WHERE valid = 1
					' . Shop::addSqlRestriction());
                    $value = round($orders / $value, 2);
                }
                ConfigurationKPI::updateValue('ORDERS_PER_CUSTOMER', $value);
                ConfigurationKPI::updateValue('ORDERS_PER_CUSTOMER_EXPIRE', strtotime('+1 day'));
                break;
            case 'average_order_value':
                $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
				SELECT
					COUNT(`id_order`) as orders,
					SUM(`total_paid_tax_excl` / `conversion_rate`) as total_paid_tax_excl
				FROM `' . _DB_PREFIX_ . 'orders`
				WHERE `invoice_date` BETWEEN "' . pSQL(date('Y-m-d', strtotime('-31 day'))) . ' 00:00:00" AND "' . pSQL(date('Y-m-d', strtotime('-1 day'))) . ' 23:59:59"
				' . Shop::addSqlRestriction());
                $value = Tools::displayPrice($row['orders'] ? $row['total_paid_tax_excl'] / $row['orders'] : 0, $currency);
                ConfigurationKPI::updateValue('AVG_ORDER_VALUE', $value);
                ConfigurationKPI::updateValue('AVG_ORDER_VALUE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))));
                break;
            case 'netprofit_visitor':
                $date_from = date('Y-m-d', strtotime('-31 day'));
                $date_to = date('Y-m-d', strtotime('-1 day'));
                $total_visitors = AdminStatsController::getVisits(true, $date_from, $date_to);
                $net_profits = AdminStatsController::getTotalSales($date_from, $date_to);
                $net_profits -= AdminStatsController::getExpenses($date_from, $date_to);
                $net_profits -= AdminStatsController::getPurchases($date_from, $date_to);
                if ($total_visitors) {
                    $value = Tools::displayPrice($net_profits / $total_visitors, $currency);
                } elseif ($net_profits) {
                    $value = '&infin;';
                } else {
                    $value = Tools::displayPrice(0, $currency);
                }
                ConfigurationKPI::updateValue('NETPROFIT_VISITOR', $value);
                ConfigurationKPI::updateValue('NETPROFIT_VISITOR_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))));
                break;
            case 'products_per_category':
                $products = AdminStatsController::getTotalProducts();
                $categories = AdminStatsController::getTotalCategories();
                $value = round($products / $categories);
                ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY', $value);
                ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY_EXPIRE', strtotime('+1 hour'));
                break;
            case 'top_category':
                if (!($id_category = AdminStatsController::getBestCategory(date('Y-m-d', strtotime('-1 month')), date('Y-m-d')))) {
                    $value = $this->l('No category', null, null, false);
                } else {
                    $category = new Category($id_category, $this->context->language->id);
                    $value = $category->name;
                }
                ConfigurationKPI::updateValue('TOP_CATEGORY', array($this->context->language->id => $value));
                ConfigurationKPI::updateValue('TOP_CATEGORY_EXPIRE', array($this->context->language->id => strtotime('+1 day')));
                break;
            default:
                $value = false;
        }
        if ($value !== false) {
            $array = array('value' => $value);
            if (isset($data)) {
                $array['data'] = $data;
            }
            die(Tools::jsonEncode($array));
        }
        die(Tools::jsonEncode(array('has_errors' => true)));
    }
示例#3
0
 /**
  * Check if more on than one language is activated
  *
  * @since 1.5.0
  * @return bool
  */
 public static function isMultiLanguageActivated()
 {
     return Language::countActiveLanguages() > 1;
 }
 /**
  * Check if more on than one language is activated
  *
  * @since 1.5.0
  * @return bool
  */
 public static function isMultiLanguageActivated($id_shop = null)
 {
     return Language::countActiveLanguages($id_shop) > 1;
 }
示例#5
0
    public static function getSeoPageUrlByKeys($seoKeys, $idLang)
    {
        $seoPageListTmp = Db::getInstance()->ExecuteS('
			SELECT s.`seo_key`, s.`id_seo`, sl.`seo_url`
			FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_seo` s
			JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_seo_lang` sl ON (s.`id_seo`=sl.`id_seo` AND sl.`id_lang`=' . (int) $idLang . ')
			WHERE s.`seo_key` IN ("' . implode('","', $seoKeys) . '")
			AND s.`deleted`=0');
        $seoPageList = array();
        if (is_array($seoPageListTmp)) {
            if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) {
                $baseUri = Context::getContext()->shop->getBaseURL() . (Language::countActiveLanguages() > 1 ? Language::getIsoById($idLang) . '/' : '');
            } else {
                $baseUri = Tools::getShopDomain(true) . __PS_BASE_URI__ . (Language::countActiveLanguages() > 1 ? Language::getIsoById($idLang) . '/' : '');
            }
            foreach ($seoPageListTmp as $seoPage) {
                $seoPageList[$seoPage['seo_key']] = array('id_seo' => (int) $seoPage['id_seo'], 'seo_page_url' => $baseUri . 's/' . $seoPage['id_seo'] . '/' . $seoPage['seo_url']);
            }
        }
        return $seoPageList;
    }
示例#6
0
 protected function getLangLink($id_lang = NULL)
 {
     if (!$this->allow or Language::countActiveLanguages() <= 1) {
         return '';
     }
     global $cookie;
     if (!$id_lang) {
         $id_lang = (int) $cookie->id_lang;
     }
     return Language::getIsoById((int) $id_lang) . '/';
 }
 public function getLinkOutputValue($row, $type, $withExtra = true, $haveSub = false, $first_level = false)
 {
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         $link = $this->_context->link;
     } else {
         global $link;
     }
     $return = false;
     $name = false;
     $icone = false;
     $url = false;
     $linkNotClickable = false;
     if (trim($row['link']) == '#') {
         $linkNotClickable = true;
     }
     //CMS
     if ($row['type'] == 1) {
         if (trim($row['name'])) {
             $name .= htmlentities($row['name'], ENT_COMPAT, 'UTF-8');
         } else {
             $name .= htmlentities($row['meta_title'], ENT_COMPAT, 'UTF-8');
         }
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         $url .= $link->getCMSLink(intval($row['id_cms']), $row['link_rewrite']);
     } elseif ($row['type'] == 2) {
         if (trim($row['name'])) {
             $name .= htmlentities($row['name'], ENT_COMPAT, 'UTF-8');
         }
         //else $name .= $this->l('No label');
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         if (trim($row['link'])) {
             $url .= htmlentities($row['link'], ENT_COMPAT, 'UTF-8');
         } else {
             $linkNotClickable = true;
         }
     } elseif ($row['type'] == 3) {
         if (trim($row['name'])) {
             $name .= htmlentities($row['name'], ENT_COMPAT, 'UTF-8');
         } else {
             $name .= htmlentities($row['category_name'], ENT_COMPAT, 'UTF-8');
         }
         if (version_compare(_PS_VERSION_, '1.4.0.0', '<')) {
             $name = self::hideCategoryPosition($name);
         }
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         $url .= $link->getCategoryLink(intval($row['id_category']), $row['category_link_rewrite']);
     } elseif ($row['type'] == 4) {
         if (trim($row['name'])) {
             $name .= htmlentities($row['name'], ENT_COMPAT, 'UTF-8');
         } else {
             $name .= htmlentities($row['manufacturer_name'], ENT_COMPAT, 'UTF-8') . '';
         }
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         $url .= $link->getManufacturerLink(intval($row['id_manufacturer']), version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Tools::link_rewrite($row['manufacturer_name']) : Tools::link_rewrite($row['manufacturer_name'], false));
     } elseif ($row['type'] == 5) {
         if (trim($row['name'])) {
             $name .= htmlentities($row['name'], ENT_COMPAT, 'UTF-8');
         } else {
             $name .= htmlentities($row['supplier_name'], ENT_COMPAT, 'UTF-8') . '';
         }
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         $url .= $link->getSupplierLink(intval($row['id_supplier']), version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Tools::link_rewrite($row['supplier_name']) : Tools::link_rewrite($row['supplier_name'], false));
     } elseif ($row['type'] == 6) {
         $this->_smarty->assign(array('atm_form_action_link' => version_compare(_PS_VERSION_, '1.4.0.0', '<') ? __PS_BASE_URI__ . 'search.php' : $link->getPageLink('search.php'), 'atm_search_id' => 'search_query_atm_' . $type . '_' . $row['id_' . $type], 'atm_have_icon' => trim($row['have_icon']), 'atm_withExtra' => $withExtra, 'atm_icon_image_source' => $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg'), 'atm_search_value' => trim(htmlentities($row['name'], ENT_COMPAT, 'UTF-8')), 'atm_is_autocomplete_search' => Configuration::get('ATM_AUTOCOMPLET_SEARCH'), 'atm_cookie_id_lang' => $this->_cookie->id_lang, 'atm_pagelink_search' => version_compare(_PS_VERSION_, '1.4.0.0', '<') ? __PS_BASE_URI__ . 'search.php' : $link->getPageLink('search.php')));
         return $this->display(__FILE__, 'pm_advancedtopmenu_search.tpl');
     } elseif ($row['type'] == 7) {
         $name = '';
         if ($withExtra && trim($row['have_icon'])) {
             $icone .= $this->_path . $type . '_icons/' . $row['id_' . $type] . '.' . ($row['image_type'] ? $row['image_type'] : 'jpg');
         }
         if (trim($row['link'])) {
             $url .= htmlentities($row['link'], ENT_COMPAT, 'UTF-8');
         } else {
             $linkNotClickable = true;
         }
     }
     $urlIsActive = false;
     if (!$this->activeAllreadySet && Configuration::get('ATM_MENU_GLOBAL_ACTIF')) {
         if ($id_product = Tools::getValue('id_product')) {
             //Check if url be cached
             if (!$this->current_category_product_url) {
                 //Get product default category URL
                 $product = new Product($id_product, false, $this->_cookie->id_lang);
                 //Put on cache
                 if (isset($product->category) && !empty($product->category)) {
                     $this->current_category_product_url = $link->getCategoryLink($product->id_category_default, $product->category);
                 }
             }
             $curUrl = $this->current_category_product_url;
         }
         if (!isset($curUrl) || !$curUrl) {
             $curUrl = explode('?', $_SERVER['REQUEST_URI']);
             $curUrl = $curUrl[0] . $this->getKeepVar();
         }
         $destUrl = explode('?', $url);
         $destUrl = $destUrl[0] . (isset($destUrl[1]) ? $this->getKeepVar($destUrl[1]) : '');
         //Url de destination
         $destUrl = preg_replace('#https?://' . preg_quote($_SERVER['HTTP_HOST'], '#') . '#i', '', $destUrl);
         //If PS_CANONICAL_REDIRECT add _iso_lang
         if (version_compare(_PS_VERSION_, '1.4.0.0', '>=') && $destUrl == __PS_BASE_URI__ && Configuration::get('PS_REWRITING_SETTINGS') && Configuration::get('PS_CANONICAL_REDIRECT') && Language::countActiveLanguages() > 1) {
             $destUrl .= Language::getIsoById($this->_cookie->id_lang) . '/';
         }
         //Url courante
         $curUrl = preg_replace('#https?://' . preg_quote($_SERVER['HTTP_HOST'], '#') . '#i', '', $curUrl);
         $pregCurUrl = preg_quote($curUrl, '#');
         $pregDestUrl = preg_quote($destUrl, '#');
         $urlIsActive = strlen($curUrl) <= strlen($destUrl) ? preg_match('#' . $pregDestUrl . '#i', $curUrl) : false;
     }
     ///prestashop_1\.4\.1\.0/cms\.php\?id_cms\=1
     ///prestashop_1\.4\.1\.0/cms\.php\?id_cms\=1
     if ($url && $urlIsActive) {
         $idActif = 'advtm_menu_actif_' . uniqid();
     }
     $return .= '<a href="' . ($linkNotClickable ? '#' : $url) . '" title="' . $name . '" ' . ($row['target'] ? 'target="' . htmlentities($row['target'], ENT_COMPAT, 'UTF-8') . '"' : '') . ' class="' . ($linkNotClickable ? 'adtm_unclickable' : '') . (strpos($name, "\n") !== false ? ' a-multiline' : '') . ($first_level ? ' a-niveau1' : '') . ($url && $urlIsActive ? ' advtm_menu_actif ' . $idActif : '') . '">';
     if ($type == 'menu') {
         $return .= '<span class="advtm_menu_span advtm_menu_span_' . intval($row['id_menu']) . '">';
     }
     if ($icone) {
         $return .= '<img src="' . $icone . '" alt="' . $name . '" title="' . $name . '" class="adtm_menu_icon" />';
     }
     $return .= nl2br($name);
     if ($type == 'menu') {
         $return .= '</span>';
     }
     if ($haveSub) {
         $return .= '<!--[if gte IE 7]><!-->';
     }
     $return .= '</a>';
     if ($url && $urlIsActive) {
         $return .= '<script type="text/javascript">activateParentMenu(".' . $idActif . '","' . $type . '");</script>';
         $this->activeAllreadySet = true;
     }
     return $return;
 }
示例#8
0
 public function hookHeader($params)
 {
     // Better way to check which file / controller name is loaded
     if (!($file = basename(Tools::getValue('controller')))) {
         $file = str_replace(array('.php', '-'), '', basename($_SERVER['SCRIPT_NAME']));
     }
     // Otherwise, create Google Analytics stats
     $ganalytics_id = Configuration::get('GANALYTICS_ID');
     $multilang = method_exists('Language', 'isMultiLanguageActivated') ? Language::isMultiLanguageActivated() : Language::countActiveLanguages() > 1;
     $defaultMetaOrder = Meta::getMetaByPage('order', $this->context->language->id);
     $order = ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite'];
     $pageTrack = preg_match('#(^' . __PS_BASE_URI__ . 'order.php)|(^' . __PS_BASE_URI__ . ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite'] . '[^-])#', $_SERVER['REQUEST_URI']) ? '/order/step' . (int) Tools::getValue('step') . '.html' : $file;
     $this->context->smarty->assign('ganalytics_id', $ganalytics_id);
     $this->context->smarty->assign('pageTrack', $pageTrack);
     $this->context->smarty->assign('isOrder', false);
     return $this->display(__FILE__, 'header.tpl');
 }
 function hookHeader($params)
 {
     if (method_exists('Language', 'isMultiLanguageActivated') && Language::isMultiLanguageActivated() || Language::countActiveLanguages() > 1) {
         $multilang = (string) Tools::getValue('isolang') . '/';
     } else {
         $multilang = '';
     }
     $defaultMetaOrder = Meta::getMetaByPage('order', $this->context->language->id);
     if (strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . 'order.php') === 0 || strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . $multilang . $defaultMetaOrder['url_rewrite']) === 0) {
         $this->context->smarty->assign('pageTrack', '/order/step' . (int) Tools::getValue('step') . '.html');
     }
     $this->context->smarty->assign('ganalytics_id', Configuration::get('GANALYTICS_ID'));
     $this->context->smarty->assign('isOrder', false);
     return $this->display(__FILE__, 'header.tpl');
 }
示例#10
0
 public function process()
 {
     $seo_url = Tools::getValue('seo_url', false);
     if ($seo_url == 'products-comparison') {
         ob_end_clean();
         header("Status: 301 Moved Permanently", false, 301);
         Tools::redirect('products-comparison.php?ajax=' . (int) Tools::getValue('ajax') . '&action=' . Tools::getValue('action') . '&id_product=' . (int) Tools::getValue('id_product'));
         die;
     }
     if ($seo_url && $this->id_seo && !Tools::getValue('getShareBlock')) {
         $resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int) $this->id_seo, (int) $this->context->cookie->id_lang);
         if (!$resultSeoUrl) {
             Tools::redirect('404.php');
             die;
         }
         if ($resultSeoUrl[0]['deleted']) {
             header("Status: 301 Moved Permanently", false, 301);
             Tools::redirect('index.php');
             die;
         }
         $currentUri = explode('?', $_SERVER['REQUEST_URI']);
         $currentUri = $currentUri[0];
         $this->realURI = __PS_BASE_URI__ . (Language::countActiveLanguages() > 1 ? Language::getIsoById($this->context->cookie->id_lang) . '/' : '') . 's/' . $resultSeoUrl[0]['id_seo'] . '/' . $resultSeoUrl[0]['seo_url'];
         if (!preg_match('#([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*)#', $_SERVER['REQUEST_URI'])) {
             header("Status: 301 Moved Permanently", false, 301);
             header("Location: " . $this->realURI . ((int) Tools::getValue('p') > 1 ? '?p=' . (int) Tools::getValue('p') : ''));
             die;
         }
         if (!Tools::getValue('id_seo_id_search') && ($resultSeoUrl[0]['seo_url'] != $seo_url || $currentUri != $this->realURI)) {
             header("Status: 301 Moved Permanently", false, 301);
             header("Location: " . $this->realURI);
             die;
         }
         $this->id_search = $resultSeoUrl[0]['id_search'];
         $AdvancedSearchClass = new AdvancedSearchClass((int) $this->id_search, (int) $this->context->cookie->id_lang);
         if (!$AdvancedSearchClass->active) {
             header("Status: 302 Moved Temporarily", false, 302);
             Tools::redirect('index.php');
             die;
         }
         $criteria = unserialize($resultSeoUrl[0]['criteria']);
         if (is_array($criteria) && sizeof($criteria)) {
             $this->criterions = PM_AdvancedSearch4::getArrayCriteriaFromSeoArrayCriteria($criteria);
         }
         $_GET['id_seo_id_search'] = (int) $this->id_search;
         $_GET['as4c'] = $this->criterions;
         $this->hookName = AdvancedSearchClass::getHookName($AdvancedSearchClass->id_hook);
         $hasPriceCriterionGroup = false;
         if (is_array($this->criterions) && sizeof($this->criterions)) {
             $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay((int) $this->id_search, array_keys($this->criterions));
             if (is_array($selected_criteria_groups_type) && sizeof($selected_criteria_groups_type)) {
                 foreach ($selected_criteria_groups_type as $criterionGroup) {
                     if ($criterionGroup['criterion_group_type'] == 'price') {
                         $hasPriceCriterionGroup = true;
                         break;
                     }
                 }
             }
         }
         if ($hasPriceCriterionGroup && $resultSeoUrl[0]['id_currency'] && $this->context->cookie->id_currency != (int) $resultSeoUrl[0]['id_currency']) {
             $this->context->cookie->id_currency = $resultSeoUrl[0]['id_currency'];
             header('Refresh: 1; URL=' . $_SERVER['REQUEST_URI']);
             die;
         }
         $this->context->smarty->assign('as_cross_links', AdvancedSearchSeoClass::getCrossLinksSeo($this->context->cookie->id_lang, $resultSeoUrl[0]['id_seo']));
     } else {
         if (Tools::getValue('setCollapseGroup')) {
             ob_end_clean();
             $this->id_search = (int) Tools::getValue('id_search');
             $id_criterion_group = (int) Tools::getValue('id_criterion_group');
             $state = (int) Tools::getValue('state');
             $id_criterion_group = $this->id_search . '_' . $id_criterion_group;
             $criterion_state = array($id_criterion_group => $state);
             $previous_criterion = array();
             if (isset($this->context->cookie->criterion_group_state)) {
                 $previous_criterion = unserialize($this->context->cookie->criterion_group_state);
                 if (is_array($previous_criterion) && sizeof($previous_criterion)) {
                     foreach ($previous_criterion as $k => $v) {
                         if ($k == $id_criterion_group) {
                             $criterion_state[$k] = (int) $state;
                         } else {
                             $criterion_state[$k] = (int) $v;
                         }
                     }
                     $this->context->cookie->criterion_group_state = serialize($criterion_state);
                     die;
                 } else {
                     $this->context->cookie->criterion_group_state = serialize($criterion_state);
                 }
                 die;
             } else {
                 $this->context->cookie->criterion_group_state = serialize($criterion_state);
             }
             die;
         } elseif (Tools::getValue('setHideCriterionStatus')) {
             ob_end_clean();
             $this->id_search = (int) Tools::getValue('id_search');
             $state = (int) Tools::getValue('state');
             if (isset($this->context->cookie->hidden_criteria_state)) {
                 $hidden_criteria_state = unserialize($this->context->cookie->hidden_criteria_state);
                 if (is_array($hidden_criteria_state)) {
                     $hidden_criteria_state[$this->id_search] = $state;
                 } else {
                     $hidden_criteria_state = array();
                 }
                 $this->context->cookie->hidden_criteria_state = serialize($hidden_criteria_state);
             } else {
                 $this->context->cookie->hidden_criteria_state = serialize(array($this->id_search => $state));
             }
             die;
         } elseif (Tools::getValue('getShareBlock')) {
             ob_end_clean();
             echo Module::getInstanceByName('pm_advancedsearch4')->getShareBlock(Tools::safeOutput(Tools::getValue('ASSearchTitle')), Tools::safeOutput(Tools::getValue('ASSearchUrl')));
             die;
         } else {
             if (Tools::getValue('resetSearchSelection')) {
                 ob_end_clean();
                 $this->id_search = (int) Tools::getValue('id_search');
                 Module::getInstanceByName('pm_advancedsearch4')->resetSearchSelection($this->id_search);
                 die('1');
             }
         }
         $this->criterions = Tools::getValue('as4c', array());
         if (is_array($this->criterions)) {
             $this->criterions = AdvancedSearchClass::cleanArrayCriterion($this->criterions);
         } else {
             $this->criterions = array();
         }
         $this->criterions_hidden = Tools::getValue('as4c_hidden', array());
         if (is_array($this->criterions_hidden)) {
             $this->criterions_hidden = AdvancedSearchClass::cleanArrayCriterion($this->criterions_hidden);
         } else {
             $this->criterions_hidden = array();
         }
         $this->next_id_criterion_group = (int) Tools::getValue('next_id_criterion_group', false);
         $this->reset = (int) Tools::getValue('reset', false);
         $this->reset_group = (int) Tools::getValue('reset_group', false);
         if ($this->reset) {
             $this->criterions = array();
         }
         if ($this->reset_group && isset($this->criterions[$this->reset_group])) {
             unset($this->criterions[$this->reset_group]);
         }
         $this->hookName = Tools::getValue('hookName');
         if (!Validate::isHookName($this->hookName)) {
             die('Invalid hook name');
         }
         $this->id_search = (int) Tools::getValue('id_search');
         $this->context->cookie->{'next_id_criterion_group_' . (int) $this->id_search} = $this->next_id_criterion_group;
     }
 }
示例#11
0
 function hookHeader($params)
 {
     // Better way to check which file / controller name is loaded
     if (!($file = basename(Tools::getValue('controller')))) {
         $file = str_replace(array('.php', '-'), '', basename($_SERVER['SCRIPT_NAME']));
     }
     #PNM-30 - Order confirmation wasn't tracked
     // If other controller / file name need to be done, add it to the array
     // if (in_array(v, array('orderconfirmation')))
     // return '';
     // Otherwise, create Google Analytics stats
     $ganalytics_id = Configuration::get('GANALYTICS_ID');
     $multilang = method_exists('Language', 'isMultiLanguageActivated') ? Language::isMultiLanguageActivated() : Language::countActiveLanguages() > 1;
     $defaultMetaOrder = Meta::getMetaByPage('order', $this->context->language->id);
     $order = ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite'];
     $pageTrack = strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . 'order.php') === 0 || strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite']) === 0 ? '/order/step' . (int) Tools::getValue('step') . '.html' : $file;
     $this->context->smarty->assign('ganalytics_id', $ganalytics_id);
     $this->context->smarty->assign('pageTrack', $pageTrack);
     $this->context->smarty->assign('isOrder', false);
     return $this->display(__FILE__, 'header.tpl');
 }
示例#12
0
 function hookHeader($params)
 {
     global $smarty, $cookie;
     // hookOrderConfirmation() already send the sats bypass this step
     if (strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . 'order-confirmation.php') === 0) {
         return '';
     }
     // Otherwise, create Google Analytics stats
     $ganalytics_id = Configuration::get('GANALYTICS_ID');
     $multilang = Language::countActiveLanguages() > 1;
     $defaultMetaOrder = Meta::getMetaByPage('order', (int) $cookie->id_lang);
     $order = ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite'];
     $pageTrack = strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . 'order.php') === 0 || strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__ . ($multilang ? (string) Tools::getValue('isolang') . '/' : '') . $defaultMetaOrder['url_rewrite']) === 0 ? '/order/step' . (int) Tools::getValue('step') . '.html' : '';
     $smarty->assign('ganalytics_id', $ganalytics_id);
     $smarty->assign('pageTrack', $pageTrack);
     $smarty->assign('isOrder', false);
     return $this->display(__FILE__, 'header.tpl');
 }
示例#13
0
 public static function countActiveLanguages()
 {
     if (!self::$countActiveLanguages) {
         self::$countActiveLanguages = Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'Language` WHERE `Active` = 1');
     }
     return self::$countActiveLanguages;
 }
示例#14
0
 /**
  * Returns the current shop's url from the context and language.
  *
  * @param Context $context the context.
  * @param Language $language the language.
  * @return string the absolute url.
  */
 protected function getContextShopUrl($context, $language)
 {
     $shop = $context->shop;
     $ssl = Configuration::get('PS_SSL_ENABLED');
     $rewrite = (int) Configuration::get('PS_REWRITING_SETTINGS', null, null, $shop->id);
     $multi_lang = Language::countActiveLanguages($shop->id) > 1;
     // Backward compatibility
     if (_PS_VERSION_ < '1.5') {
         $base = ($ssl ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__;
     } else {
         $base = ($ssl ? 'https://' . $shop->domain_ssl : 'http://' . $shop->domain) . $shop->getBaseURI();
     }
     $lang = '';
     if ($multi_lang) {
         if ($rewrite) {
             $lang = $language->iso_code . '/';
         } else {
             $lang = '?id_lang=' . $language->id;
         }
     }
     return $base . $lang;
 }
示例#15
0
 protected function displaySeoUrlList()
 {
     $id_search = Tools::getValue('id_search');
     $this->_startForm(array('id' => 'SEOURLListForm'));
     $this->_displayTitle($this->l('SEO URL list'));
     $this->_showInfo($this->l('You will find here the list of all the SEO URLs pages you have created for this search engine. You have to add them in your menu, slideshow, footer, blocks, or anywhere you want in your website for Google crawling'));
     $seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($this->_cookie->id_lang, false, $id_search);
     if ($seoSearchs && self::_isFilledArray($seoSearchs)) {
         $new_SeoSearch = array();
         foreach ($seoSearchs as $row) {
             $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, unserialize($row['criteria']), $row['id_currency']);
             $ObjAdvancedSearchSeoClass = new AdvancedSearchSeoClass($row['id_seo'], null);
             if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) {
                 $shopUrl = new Shop($this->_context->shop->id);
                 $base_url = $shopUrl->getBaseURL();
             } else {
                 $base_url = Tools::getShopDomain(true) . __PS_BASE_URI__;
             }
             if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) {
                 $base_url = 'https://' . ltrim($base_url, 'http://');
             }
             foreach ($this->_languages as $language) {
                 $url = $base_url . (Language::countActiveLanguages() > 1 ? $language['iso_code'] . '/' : '') . 's/' . (int) $ObjAdvancedSearchSeoClass->id . '/' . $ObjAdvancedSearchSeoClass->seo_url[$language['id_lang']];
                 $title = htmlentities($ObjAdvancedSearchSeoClass->title[$language['id_lang']], ENT_COMPAT, 'UTF-8');
                 $new_SeoSearch[$language['id_lang']][$ObjAdvancedSearchSeoClass->id]['url'] = $url;
                 $new_SeoSearch[$language['id_lang']][$ObjAdvancedSearchSeoClass->id]['title'] = $title;
             }
         }
         $seoSearchs = $new_SeoSearch;
         unset($new_SeoSearch);
         if ($seoSearchs && self::_isFilledArray($seoSearchs)) {
             $this->_html .= '<p>' . $this->l('Please select the language :') . '<p>';
             $this->displayPMFlags();
             $this->_html .= '<div class="clear"></div>';
             foreach ($seoSearchs as $id_lang => $seo_urls) {
                 $this->_html .= '<div id="langseo_url_' . $id_lang . '" class="pmFlag pmFlagLang_' . $id_lang . '" style="display: ' . ($id_lang == $this->_default_language ? 'block' : 'none') . '; float: left;">';
                 $this->_html .= '<h3>' . $this->l('HTML version:') . '</h3>';
                 $this->_html .= '<textarea cols="110" rows="10">';
                 $this->_html .= htmlentities('<ul>', ENT_COMPAT, 'UTF-8') . "\n";
                 foreach ($seo_urls as $seo_url) {
                     $this->_html .= htmlentities('<li><a href="' . $seo_url['url'] . '" title="' . $seo_url['title'] . '">' . $seo_url['title'] . '</a></li>', ENT_COMPAT, 'UTF-8') . "\n";
                 }
                 $this->_html .= htmlentities('</ul>', ENT_COMPAT, 'UTF-8') . "\n";
                 $this->_html .= '</textarea>';
                 $this->_html .= '<h3>' . $this->l('CSV version:') . '</h3>';
                 $this->_html .= '<textarea cols="110" rows="10">';
                 foreach ($seo_urls as $seo_url) {
                     $this->_html .= '"' . $seo_url['title'] . '";"' . $seo_url['url'] . '"' . "\n";
                 }
                 $this->_html .= '</textarea>';
                 $this->_html .= '</div>';
             }
         }
     } else {
         $this->_showInfo($this->l('No seo page at this time please add one'));
     }
     $this->_endForm(array('id' => 'SEOURLListForm'));
 }