Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /* if (!defined('_JEXEC')) { register_shutdown_function('gkd_fatal_handler'); ..

Decoded Output download

<?php 
/* 
if (!defined('_JEXEC')) { 
  register_shutdown_function('gkd_fatal_handler'); 
  set_error_handler('var_dump', 0); 
} 
 
function gkd_fatal_handler() { 
  $error = error_get_last(); 
   
  if (!empty($error['type']) && $error['type'] == '1') { 
    ob_end_clean(); 
    if ($error !== NULL) { 
      echo 'Error: ' . $error['message'] . ' in ' . $error['file'] . ' on line '  . $error['line']; 
    } else { 
      echo 'Unknown fatal error'; 
    } 
     
    if (!empty($_SESSION['seopackage_lastItem'])) { 
      echo "\n".'Last item id: '.$_SESSION['seopackage_lastItem']; 
    } 
  } 
} 
*/ 
 
#custom_code# 
class ControllerModuleCompleteSeo extends Controller { 
  const MODULE = 'complete_seo'; 
  const PREFIX = 'mlseo'; 
  const MOD_FILE = 'seo_package'; 
  const LINK = 'module/complete_seo'; 
  const EXT_PATH = 'extension/complete_seo/'; 
  const OCID = 9486; 
   
  static $EXT_PATH = ''; 
  static $MODEL_PATH = 'model_'; 
  static $LINK = 'module/complete_seo'; 
  static $LINK_SEP = 'module/complete_seo/'; 
  static $ASSET_PATH = 'view/seo_package/'; 
   
  private $error = array(); 
  private $OC_VERSION; 
  private $OC_V2; 
  private $OC_V21X; 
  private $OC_V22X; 
  private $OC_V23X; 
  private $EXT_23X = ''; 
  private $OC_V151; 
  private $ml_mode = false; 
  private $multistore_mode = false; 
  private $start; 
  private $limit = 500; 
  private $start_time; 
  private $token; 
  private $url_alias; 
  private $front_url; 
  private $total_items; 
  private $store; 
  private $edit_action = 'edit'; 
   
  public function __construct($registry) { 
    ini_set('memory_limit', -1); 
      $this->OC_VERSION = (int) str_replace('.', '', substr(VERSION, 0, 5)); 
      $this->OC_V2 = version_compare(VERSION, '2', '>='); 
      $this->OC_V151 = (substr(VERSION, 0, 5) == '1.5.1'); 
      $this->OC_V21X = version_compare(VERSION, '2.1', '>='); 
      $this->OC_V22X = version_compare(VERSION, '2.2', '>='); 
      $this->OC_V23X = version_compare(VERSION, '2.3', '>='); 
       
      if ($this->OC_V23X) { 
        $this->EXT_23X = 'extension/'; 
      } 
       
      if (!version_compare(VERSION, '2', '>=')) { 
        $this->edit_action = 'update'; 
      } 
       
    parent::__construct($registry); 
     
      if (!defined('SEO_PACKAGE_CLI')) { 
        $this->token = isset($this->session->data['user_token']) ? 'user_token='.$this->session->data['user_token'] : 'token='.$this->session->data['token']; 
      } 
       
      if (version_compare(VERSION, '3', '>=')) { 
        $this->url_alias = 'seo_url'; 
      } else { 
        $this->url_alias = 'url_alias'; 
      } 
     
    if ($this->config->get('mlseo_ml_mode')) { 
      $this->ml_mode = true; 
    } 
     
    if ($this->config->get('mlseo_multistore')) { 
      $this->multistore_mode = true; 
    } 
     
    // front url handler 
    if (version_compare(VERSION, '4', '>=')) { 
      $this->front_url = new \Opencart\System\Library\Url($this->config->get('site_url')); 
       
      defined('HTTP_CATALOG') ?: define('HTTP_CATALOG', $this->config->get('site_url')); 
      defined('HTTPS_CATALOG') ?: define('HTTPS_CATALOG', $this->config->get('site_url')); 
       
      self::$LINK = self::EXT_PATH.self::$LINK; 
      self::$LINK_SEP = self::$LINK . (version_compare(VERSION, '4', '<') ? '/' : '|'); 
      self::$EXT_PATH = 'extension/'.self::MODULE.'/'; 
      self::$MODEL_PATH = 'model_extension_'.self::MODULE.'_'; 
      self::$ASSET_PATH = '../extension/'.self::MODULE.'/admin/'.self::$ASSET_PATH; 
    } else { 
      $this->front_url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG); 
    } 
     
    if ($this->config->get('config_seo_url')) { 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $seourl_file = DIR_SYSTEM.'../catalog/controller/startup/seo_url.php'; 
      } else { 
        $seourl_file = DIR_SYSTEM.'../catalog/controller/common/seo_url.php'; 
      } 
       
      if (isset($vqmod)) { 
        require_once($vqmod->modCheck($seourl_file)); 
      } else if (class_exists('VQMod') && function_exists('modification')) { 
        require_once(VQMod::modCheck(modification($seourl_file), $seourl_file)); 
      } else if (function_exists('modification')) { 
        require_once(modification($seourl_file)); 
      } else if (class_exists('VQMod')) { 
        require_once(\VQMod::modCheck($seourl_file)); 
      } else { 
        require_once($seourl_file); 
      } 
       
      if (version_compare(VERSION, '4', '>=')) { 
        $rewriter = new \Opencart\Catalog\Controller\Startup\SeoUrl($this->registry); 
      } else if (version_compare(VERSION, '2.2', '>=')) { 
        $rewriter = new ControllerStartupSeoUrl($this->registry); 
      } else { 
        $rewriter = new ControllerCommonSeoUrl($this->registry); 
      } 
       
      $this->front_url->addRewrite($rewriter); 
    } 
     
    if (version_compare(VERSION, '3', '>=') && version_compare(VERSION, '4', '<')) { 
      $this->load->language('extension/'.self::$LINK); 
    } else { 
      $this->load->language(self::$LINK); 
    } 
  } 
 
  public function save() { 
    $isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); 
     
		$json = []; 
 
		if (!$this->user->hasPermission('modify', self::$LINK)) { 
			$json['error']['warning'] = $this->language->get('error_permission'); 
		} 
 
		if (!$json) { 
			$this->load->model('setting/setting'); 
			 
      $this->load->model('localisation/language'); 
      $languages = $this->model_localisation_language->getLanguages(); 
       
      $current_lang_codes = array(); 
      $current_code2id = array(); 
     
      foreach ($languages as $k => $language) { 
        if ($language['status']) { 
          $current_lang_codes[$language['language_id']] = $language['code']; 
          $langaugeCodeToId[$language['code']] = $language['language_id']; 
        } 
      } 
     
      // define multilingual handler 
      $this->load->model('setting/store'); 
     
      $data['stores'] = array(); 
      $data['stores'][] = array( 
        'store_id' => 0, 
        'name'     => $this->config->get('config_name') 
      ); 
 
      $stores = $this->model_setting_store->getStores(); 
 
      foreach ($stores as $store) { 
        $action = array(); 
 
        $data['stores'][] = array( 
          'store_id' => $store['store_id'], 
          'name'     => $store['name'] 
        ); 
      } 
       
      $store_id = 0; 
       
      if (isset($this->request->get['store_id']) && $this->request->get['store_id']) { 
        $data['store_id'] = $store_id = (int) $this->request->get['store_id']; 
      } 
       
      $redirect_store = ''; 
     
      if ($store_id) { 
        $redirect_store = '&store_id=' . $store_id; 
      } 
       
      $lang_to_store = array(); 
     
      foreach ($data['stores'] as $store) { 
        $store_info = $this->model_setting_setting->getSetting('config', $store['store_id']); 
         
        if (!empty($store_info['config_language'])) { 
          $lang_to_store[$store_info['config_language']] = array( 
            'config_url' => !empty($store_info['config_url']) ? rtrim($store_info['config_url'], '/') : rtrim(HTTP_CATALOG, '/'), 
            'config_ssl' => !empty($store_info['config_ssl']) ? rtrim($store_info['config_ssl'], '/') : rtrim(HTTPS_CATALOG, '/'), 
          ); 
        } 
      } 
       
      if (version_compare(VERSION, '4', '>=')) { 
        foreach ($this->request->post['mlseo_flag_custom'] as $langTag => $langVal) { 
          $langQuery = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'language' AND `value` = '" . $this->db->escape($langTag) . "'")->row; 
           
          // reset to empty if not tag mode 
          if ($this->request->post['mlseo_flag_mode'] != 'tag') { 
            $langVal = ''; 
          } 
           
          // update tag 
          if (!empty($langQuery['seo_url_id'])) { 
            $this->db->query("UPDATE `" . DB_PREFIX . "seo_url` SET `keyword` = '" . $this->db->escape($langVal) . "', `sort_order` = '".($langVal ? '-10' : '')."' WHERE `seo_url_id` = '" . (int)$langQuery['seo_url_id'] . "'"); 
          } else { 
            $this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$langaugeCodeToId[$langTag] . "', `key` = 'language', `value` = '" . $this->db->escape($langTag) . "', `keyword` = '" . $this->db->escape($langVal) . "', `sort_order` = '".($langVal ? '-10' : '')."'"); 
          } 
        } 
      } 
       
      $this->request->post['mlseo_ml_mode'] = (count($languages) > 1); 
      $this->request->post['mlseo_lang_codes'] = $current_lang_codes; 
       
      // save store bindings 
      $this->request->post['mlseo_lang_to_store'] = $lang_to_store; 
       
      unset($this->request->post['langs'], $this->request->post['simulate'], $this->request->post['empty_only'], $this->request->post['redirect_mode']); 
       
      // urls management 
      foreach($languages as $lang) { 
        if (isset($this->request->post['mlseo_urls_'.$lang['code']])) { 
          $this->request->post['mlseo_urls_'.$lang['code']] = array_combine($this->request->post['mlseo_urls_'.$lang['code']]['keys'], $this->request->post['mlseo_urls_'.$lang['code']]['values']); 
        } 
      } 
       
      // $this->request->post['mlseo_default_lang'] = (!empty($this->request->post['mlseo_flag_short'])) ? substr($this->config->get('config_language'), 0, 2) : $this->config->get('config_language'); // do not use short code here ! 
      // $this->request->post['mlseo_default_lang'] = $this->config->get('config_language'); 
			$this->model_setting_setting->editSetting('module_'.self::MODULE, array('module_'.self::MODULE.'_status' => !empty($this->request->post['mlseo_enabled'])));				 
			$this->model_setting_setting->editSetting('mlseo', $this->request->post, $store_id); 
       
      if (defined('DIR_EXTENSION') && !empty($this->request->post['mlseo_enabled']) && is_file(DIR_EXTENSION.self::MODULE.'/seo_package.xml_')) { 
        rename(DIR_EXTENSION.self::MODULE.'/seo_package.xml_', DIR_EXTENSION.self::MODULE.'/seo_package.xml'); 
        @unlink(DIR_OPENCART.'vqmod/checked.cache'); 
        @unlink(DIR_OPENCART.'vqmod/mods.cache'); 
        array_map('unlink', glob(DIR_OPENCART.'vqmod/vqcache/*.*')); 
      } else if (defined('DIR_EXTENSION') && empty($this->request->post['mlseo_enabled']) && is_file(DIR_EXTENSION.self::MODULE.'/seo_package.xml')) { 
        rename(DIR_EXTENSION.self::MODULE.'/seo_package.xml', DIR_EXTENSION.self::MODULE.'/seo_package.xml_'); 
        @unlink(DIR_OPENCART.'vqmod/checked.cache'); 
        @unlink(DIR_OPENCART.'vqmod/mods.cache'); 
        array_map('unlink', glob(DIR_OPENCART.'vqmod/vqcache/*.*')); 
      } 
       
			$json['success'] = $this->language->get('text_success'); 
		} 
 
    if ($isAjax) { 
      $this->response->addHeader('Content-Type: application/json'); 
      $this->response->setOutput(json_encode($json)); 
    } else { 
      if (!empty($json['error']['warning'])) { 
        $this->session->data['error'] = $this->language->get($json['error']['warning']); 
        return $this->index(); 
      } 
       
      $this->session->data['success'] = $this->language->get('text_success'); 
      $this->response->redirect($this->url->link(self::$LINK, $this->token.$redirect_store, 'SSL')); 
    } 
  } 
   
  public function index() { goto eWyOX; YRdi_: Tktvl: goto mtyne; R8z5h: if ($data["module_type"] == "vqmod") { goto O7NDK; } goto Vqef4; Hr76T: if (!version_compare(VERSION, 4, ">=")) { goto FyqtB; } goto OggeH; qk9bq: wd3Pl: goto xIxNI; YHqKR: $data["_language"] =& $this->language; goto lUF20; wdSih: goto Ht6v5; goto iORLQ; Vqef4: $this->session->data["error"] = "Module modification are not applied<br/>No modification file have been found, there should be the file either in /system/" . self::MOD_FILE . ".ocmod.xml for ocmod version, or in /vqmod/xml/" . self::MOD_FILE . ".xml for vqmod version, please upload the file from module package if it is not yet."; goto FTFlW; esOab: goto kD8OF; goto Aohj5; lUF20: $data["_config"] =& $this->config; goto vXKlM; nXB0A: curl_close($KwAQS); goto QId3n; rMUKg: goto CVK2s; goto FosLe; DK53K: $this->session->data["error"] = "Warning : PHP extension <b>mbstring</b> not loaded, make sure to enable this extension in order to use correctly the module."; goto b0YVg; ykXHy: $this->config->set("template_engine", "template"); goto JTxgL; iM354: R0QNh: goto CS45X; MuDeD: $this->template = "module/complete_seo.tpl"; goto OluKb; QilHN: $data["error"] = $this->session->data["error"]; goto MJYm8; SEMOu: $data["categories"] = $this->model_catalog_category->getCategories(array()); goto zGN33; quyMm: aGIYP: goto vttEu; zUTPC: U2sOE: goto jS86b; BD_gn: goto u8lxy; goto vMXBJ; vFOOZ: goto h0wsN; goto Q06kI; uS0Fa: $data["breadcrumbs"][] = array("text" => strip_tags($this->language->get("heading_title")), "href" => $this->url->link(self::$LINK, $this->token, "SSL"), "separator" => " :: "); goto gIfYu; OGj1E: s7sn6: goto QSEbR; O5U2r: goto zmXyh; goto aMeRt; MJYm8: unset($this->session->data["error"]); goto Z0TZ1; NoZi0: lCiyA: goto gZmGp; N1uZF: H2x6X: goto LhgYO; kyjMK: goto OKEPI; goto trIFh; XfoSD: $this->load->model("catalog/category"); goto SEMOu; K0dTV: $E5bYQ = 0; goto YNjue; p0wtn: goto sJqH6; goto NMXkQ; nZh12: $data["breadcrumbs"][] = array("text" => $this->language->get("text_home"), "href" => $this->url->link("common/home", $this->token, "SSL"), "separator" => false); goto TeR3y; x5daT: $this->session->data["success"] = $MGEsw["success"]; goto Dhg41; moaNm: pC9VL: goto F2_W4; b8qT0: $data["customer_groups"] = $this->model_customer_customer_group->getCustomerGroups(); goto UxJOm; GjvtR: if ($this->config->get("mlseo_enabled")) { goto stq6R; } goto Qsxvl; zko0O: $this->load->model("customer/customer_group"); goto b8qT0; K2REs: Xh0m8: goto bWoTI; vo1Jj: wi60I: goto b11yH; Hn7bi: $this->response->redirect($this->url->link(self::$LINK, $this->token, "SSL")); goto beXVm; p1wVd: qhash: goto wHNV4; lT1AV: $dfq9k = "mlseo_fpp_"; goto us_B6; xFzTm: if (!version_compare(VERSION, "2", ">=")) { goto EV71N; } goto EWp3H; TeSIv: curl_setopt($KwAQS, CURLOPT_SSL_VERIFYPEER, 0); goto PB5BL; wGce8: curl_setopt($KwAQS, CURLOPT_URL, "https://geekodev.com/license.php"); goto WyOJ6; J4pt1: goto CZYvf; goto AQU4I; iaKGW: if (!($this->config->get("mlseo_absolute") && ($this->config->get("mlseo_fpp_directcat") || !$this->config->get("mlseo_fpp_cat_canonical")))) { goto BIjJS; } goto O5i_E; tOuMH: if (version_compare(VERSION, 4, "<") && !is_file(DIR_TEMPLATE . "tool/gkd_license.tpl")) { goto MHxBE; } goto cjql4; VLnRc: if (!(!$this->config->get("mlseo_ml_mode") && count($XktyI) > 1)) { goto BojEF; } goto c7zrD; NTfTf: $data["currentTab"] = "tab-dashboard"; goto wsd2l; VFZHb: $KntYp = curl_exec($KwAQS); goto IslHb; WNUFz: goto BUV62; goto sAHQ6; lFax7: goto YaG9G; goto PXOa5; NYzmT: Ob4ey: goto nXB0A; LPzjN: DScjT: goto pBDPh; INNuR: $Kcjpq = file_get_contents(DIR_CATALOG . "../index.php"); goto t5ibL; e8jjZ: if (!$UEbbE) { goto Hd5Bt; } goto DIcKV; jY13w: kbLt2: goto Ep3Ui; Cqs3q: if (version_compare(VERSION, "3", ">=")) { goto SjV1f; } goto H6f5u; hI4rY: if (!file_exists(DIR_APPLICATION . "controller/feed/seopackage_sitemap.php")) { goto kbLt2; } goto B583F; ZbNuc: goto yaZqM; goto Pa0M5; SSaO8: $this->session->data["error"] = "Upgrade from old version, please edit your htaccess file like this :<br/>Remove the entire line: <b>RewriteRule ^(?:(?:(\w{2})(?:/|\z))?(?:/|\z)?)?(?:([^?]*))? index.php?_route_=$2&site_language=$1 [L,QSA]</b><br/>Remove the # before the line: <b>#RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]</b>"; goto Kqx03; o_lbF: DHfbB: goto qnJiu; CYOUI: I6EA8: goto pAjfd; cdi4M: q3mXM: goto IZ0gZ; kOXGI: $this->session->data["error"] = "You have enabled redirect to canonical, you should enable the option Path manager > "Rewrite product path in categories" in order to have the product urls to be always the canonical ones, else it will generate a redirection on each product clicked in categories"; goto zDIk0; euUqp: fXTLL: goto KJohC; G7pct: tciec: goto Pu4Ts; VldMs: $data["action"] = $this->url->link(self::$LINK_SEP . "save", $this->token . $yygZ5, "SSL"); goto H4UTK; LdWEy: $glDMO[] = $dfq9k . "categories"; goto JaxZF; cH8zE: xLS8o: goto WDebS; w1IeK: goto itW6K; goto rELE7; WbRIF: if (!(false && $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row)) { goto KXU3q; } goto xNRKz; uWVfm: $data["stores"] = array(); goto Q3qRW; H_dH5: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "style.css")); goto qFgpB; hBOhW: $XktyI = $this->model_localisation_language->getLanguages(); goto wYOzp; HiMyM: $glDMO[] = $dfq9k . "bypasscat"; goto MDq5K; PdqKe: F7leC: goto E2vYj; EGnhv: if (!(isset($this->request->get["store_id"]) && $this->request->get["store_id"])) { goto R2RVC; } goto uBN7d; jS86b: $zOm7L = new \Opencart\System\Library\Template("template"); goto Yy91z; RlWHr: goto Dkal0; goto uXWkf; lqT18: goto WXj4H; goto nhT2L; utpoH: if (empty($Wy0d3) || $RKWTW) { goto eYHvH; } goto gKPjE; Q2AFX: gy0UK: goto Yt22v; s_YlN: goto hthaO; goto GIM7l; Y7l9u: curl_setopt($KwAQS, CURLOPT_POSTFIELDS, http_build_query(array("sn" => $this->request->post["lic_number"], "tw" => !empty($this->request->post["lic_test"]), "ip" => isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : '', "md" => self::MODULE, "ws" => HTTP_SERVER, "rf" => $RKWTW))); goto WObrm; Ao33z: hthaO: goto t2BW1; omtVV: goto f1Ckh; goto mLjNJ; wHgkQ: $VslUq = $this->model_setting_extension->getInstalled("feed"); goto qsOyZ; zICuH: goto uslt2; goto LPzjN; wlB1E: tsHPw: goto U_jdY; Mf_XZ: $this->load->model("setting/extension"); goto Y58Ab; Cg1qQ: $this->load->model(self::$EXT_PATH . "setting/friendlyurls"); goto W25mR; kTrX5: $this->db_tables(); goto IsFNd; ChJua: if (empty($YLVI9[$this->url_alias . "_id"])) { goto hxfHh; } goto ezHYS; r7L3h: FaUJ5: goto VldMs; J8wkT: goto ahhud; goto Q2AFX; VuO5b: $data["cli_log"] = sprintf($this->language->get("text_cli_log_too_big"), round(substr($ieocD, 0, strpos($ieocD, ".") + 4), 2) . $lVHlh[$E5bYQ]); goto lDBSc; xUops: $this->response->redirect($this->url->link(self::$LINK, $this->token, "SSL")); goto vmGvA; lPkC_: Co1Sr: goto QQdRC; UONwS: $this->model_setting_setting->deleteSetting(md5(HTTP_SERVER . self::MODULE)); goto jOEsE; yeW1l: $data["button_save"] = $this->language->get("button_save"); goto DHIOl; GeFVP: oiSlh: goto FKmlZ; WnSX6: MGEfU: goto FGSgv; msqEd: E6fTe: goto pLtEi; a8cMo: $this->data =& $data; goto MuDeD; KnPBS: goto JGZJm; goto zuteY; AmwvT: $ieocD = $ieocD / 1024; goto yWZ4t; bI3eO: goto NKbsH; goto xAD3r; maKBr: ZYRX8: goto kk_ZF; ScKfj: ne10O: goto mUhRA; ThQsH: $data["cli_log_link"] = $this->url->link("module/complete_seo/save_cli_log", $this->token, "SSL"); goto kVpaN; Ur7Ka: goto xkLM6; goto if_dy; CPwSA: $data["module"] = self::MODULE; goto vDrU9; xruWw: if (!empty($data["license_info"]["website"]) && strpos($_SERVER["HTTP_HOST"], $data["license_info"]["website"]) !== false) { goto PL_Zz; } goto a2nQh; ndmsU: xkLM6: goto SvBDS; HxAVF: R6pkt: goto aYJEu; xgqUR: goto WQ00i; goto L2fHK; JTJze: goto XYe2v; goto uGsgR; vWvCp: goto ONRO2; goto a6xyT; bAzPF: $pulAQ = @file_get_contents(DIR_CATALOG . "../.htaccess"); goto neBSO; Yxu0v: $data["OCID"] = self::OCID; goto CPwSA; bKbNt: $data["error"] = ''; goto WlOFJ; w7frK: if (version_compare(VERSION, "2.1", ">=")) { goto WTMfi; } goto w_9Wl; D31ta: ZLzv3: goto w7frK; IybqL: goto Y2ip6; goto HRNE5; Lhp1O: $data["error"] = $this->error["error"]; goto D31ta; wLhPW: goto wig5K; goto TA7CL; WQj4T: $this->document->setTitle(strip_tags($this->language->get("heading_title"))); goto iADIk; i3I5p: curl_setopt($KwAQS, CURLOPT_RETURNTRANSFER, 1); goto TJj2s; ow405: $this->session->data["error"] = "On ocStore you must select Default SEO Url engine in System > Settings > Server in order to Complete SEO to work"; goto e2cjG; uXWkf: UTZ41: goto x5daT; oNhYG: uslt2: goto G_V7g; GIM7l: xoWwu: goto Rfk38; pBDPh: $this->config->set("template_engine", "template"); goto zfaum; KjdIP: $this->document->addScript(self::$ASSET_PATH . "prettyCheckable.js"); goto KYeIU; TQzxx: $this->response->setOutput(str_replace(array("view/javascript/jquery/jquery-1.6.1.min.js", "view/javascript/jquery/jquery-1.7.1.min.js", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"), self::$ASSET_PATH . "jquery.min.js", $this->render())); goto L8fGO; Ulp7q: P6cpl: goto suDbr; l4OHH: ax3DL: goto tWtSO; fo1pS: A4f_w: goto Y7l9u; ZKJy8: f1Ckh: goto zICuH; uQh4b: $data["info"] = "Demonstration mode is read only, no change will be saved."; goto OGj1E; Kqx03: goto Mplkr; goto iirF7; IsFNd: goto KuxKD; goto o_lbF; IslHb: goto Ob4ey; goto IgEJP; XXcfx: ZUHkM: goto OCJBF; If0Ss: itW6K: goto rcqeH; S6ZkA: yaZqM: goto Hn7bi; mUhRA: if (!$I2PwC) { goto xILuV; } goto BiuZ8; clzOL: if (version_compare(VERSION, "2", "<")) { goto GE2Uo; } goto Jz83I; JMXKA: if (isset($this->error["warning"])) { goto JBmfK; } goto uVVFY; zKet3: goto tp2Me; goto euUqp; XUT7n: $this->document->addScript(self::$ASSET_PATH . "bootstrap.min.js"); goto AHi1S; SQv18: eYHvH: goto Brz2W; J9Jnl: goto bM7hS; goto XGAmu; jwRaD: goto XHdVY; goto Vmnw3; QId3n: goto H2x6X; goto cGwju; VKeAO: foreach ($XktyI as $rhdWd => $Kl4xZ) { goto bW5HR; OWbD0: $XktyI[$rhdWd]["image"] = "language/" . $Kl4xZ["code"] . "/" . $Kl4xZ["code"] . ".png"; goto oVZe5; e5JBX: goto cWziR; goto dkCCW; m18TG: meL09: goto tY4jP; iX0VR: $XktyI[$rhdWd]["image"] = "view/image/flags/" . $Kl4xZ["image"]; goto e5JBX; bW5HR: if (version_compare(VERSION, "2.2", ">=")) { goto GH_N7; } goto iX0VR; dkCCW: GH_N7: goto OWbD0; Yh_50: $Sc3w7[$Kl4xZ["language_id"]] = $Kl4xZ["code"]; goto m18TG; IOnk8: if (!$Kl4xZ["status"]) { goto meL09; } goto Yh_50; oVZe5: cWziR: goto IOnk8; tY4jP: FLAs7: goto qTNk2; qTNk2: } goto tCK94; icFdC: b8dg4: goto PhKSX; L2fHK: grxUj: goto f4Igy; sAHQ6: peZwj: goto YhKhr; KxyoD: goto QLh9g; goto zUTPC; ENoc_: $data["heading_title"] = $this->language->get("module_title"); goto yeW1l; kk_ZF: if (empty(self::$LINK)) { goto S20PO; } goto J9Jnl; EWp3H: goto hSw6K; goto S0K_R; S8wnQ: if (!(in_array($_SERVER["REMOTE_ADDR"], array("127.0.0.1", "::1", "192.168.0.1")) || !$this->user->hasPermission("modify", self::$LINK))) { goto y368o; } goto bI3eO; eWyOX: if (!(!empty($this->request->get["clear_cli_logs"]) && file_exists(DIR_LOGS . "seo_package_cli.log"))) { goto wd3Pl; } goto U_9Cd; dzJNP: if (version_compare(VERSION, "4", "<")) { goto RFbg9; } goto sidLB; cbK7_: goto DScjT; goto oNhYG; W1B6n: if (version_compare(VERSION, "2.3", ">=")) { goto LYm80; } goto LOPWb; XCQlC: if (version_compare(VERSION, "2.3", ">=")) { goto xLS8o; } goto JC4xA; imPT5: JDDUE: goto OocR0; mM6ky: sEW2r: goto o9zAR; BiuZ8: goto kCCw5; goto OCJh7; mLjNJ: zTbAp: goto esOab; ncI1j: $TqFxN = array(); goto W9hnQ; BojNg: HVcvU: goto KnPBS; C432k: zNNHP: goto MiDw4; PsJt2: goto UTZ41; goto YRdi_; WDebS: $data["link_sitemap"] = $this->url->link("extension/extension", "type=feed&" . $this->token, "SSL"); goto ciQUe; pAjfd: if (version_compare(VERSION, "2", ">=")) { goto wyoN7; } goto V0hKi; TA7CL: c2zDh: goto E1RKb; TXsHI: $this->document->addStyle(self::$ASSET_PATH . "select2.min.css"); goto cJK6i; xAD3r: y368o: goto y6LDy; hgqJ9: goto aGIYP; goto mHOEY; U_9Cd: unlink(DIR_LOGS . "seo_package_cli.log"); goto LmAbP; aO_YX: $data["currentTab"] = $this->session->data["currentTab"]; goto qR9VH; jX1Lx: NxDW4: goto YLLsl; lxsWx: goto Tktvl; goto XXcfx; KPTLK: V31PC: goto HA0uW; JC4xA: $data["link_sitemap"] = $this->url->link("feed/advanced_sitemap", $this->token, "SSL"); goto wR4q_; GzJat: goto KL7t0; goto mXY76; vewEb: $glDMO[] = $dfq9k . "noprodbreadcrumb"; goto R4BDR; aMeRt: y0Ge3: goto UONwS; oNgZO: $data["lang_to_store"] = $sXCGV; goto fa7Qr; kxiD6: goto GFZxm; goto DHaCG; NZJPD: $this->response->redirect($this->url->link(self::LINK, $this->token, "SSL")); goto Tnpwx; NvK5r: $data["OC_VERSION"] = $this->OC_VERSION; goto a4_ke; rehCP: vJjOA: goto x7UB0; d3my7: unset($this->session->data["success"]); goto zSoaW; vttEu: goto Taqnj; goto ndmsU; gIfYu: if (version_compare(VERSION, "4", ">=")) { goto D1q0_; } goto WzRGv; E355q: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "jquery-editable.css")); goto DngBZ; TZE_h: $this->response->setOutput($this->load->view("extension/" . self::MODULE . "/tool/gkd_license", $data)); goto ijHHG; IUuyZ: SjV1f: goto ykXHy; WlOFJ: goto ZLzv3; goto NDt27; jGTQ1: Gxopa: goto WbRIF; q8InA: $data["error_warning"] = $this->error["warning"]; goto QL01I; Qsxvl: $this->session->data["error"] = $this->language->get("error_module_disabled"); goto tbF5r; W25mR: $data["friendly_urls_langs"] = $this->{self::$MODEL_PATH . "setting_friendlyurls"}->getAvailableLangs(); goto zNLR0; JaxZF: $glDMO[] = $dfq9k . "slash"; goto iRAtT; WObrm: goto cVgmm; goto wlB1E; fVgkt: $glDMO[] = $dfq9k . "breadcrumbs"; goto vewEb; GnCao: goto ZwQfm; goto WkcRT; Pcqen: wll4p: goto PsJt2; pBHnY: KfFJp: goto q505M; EFzR6: pHXIa: goto ev2xs; CS45X: if (!isset($MGEsw["error"])) { goto ylCKb; } goto vFOOZ; S_Jna: $yygZ5 = ''; goto e8jjZ; iRAtT: foreach ($XktyI as $Kl4xZ) { goto JTDh9; u2jMa: $glDMO[] = $Qtmx4 . "pagination_" . $Kl4xZ["language_id"]; goto cOiFo; ifmCu: $glDMO[] = $Qtmx4 . "limit_" . $Kl4xZ["language_id"]; goto wW5b3; leP4x: $glDMO[] = $Qtmx4 . "sortname_" . $Kl4xZ["language_id"]; goto WJBW9; cOiFo: $glDMO[] = $Qtmx4 . "sort_" . $Kl4xZ["language_id"]; goto ifmCu; JTDh9: $glDMO[] = $Qtmx4 . "remove_" . $Kl4xZ["language_id"]; goto MHhWN; wW5b3: $glDMO[] = $Qtmx4 . "order_" . $Kl4xZ["language_id"]; goto leP4x; WJBW9: $glDMO[] = $Qtmx4 . "pagination_name_" . $Kl4xZ["language_id"]; goto WVEOF; MHhWN: $glDMO[] = $Qtmx4 . "replace_" . $Kl4xZ["language_id"]; goto u2jMa; bgVg5: $glDMO[] = $dfq9k . "search_" . $Kl4xZ["language_id"]; goto wfCdl; WVEOF: $glDMO[] = $dfq9k . "tag_" . $Kl4xZ["language_id"]; goto bgVg5; wfCdl: rb140: goto zhmLg; zhmLg: } goto RpPy1; cGwju: lTibQ: goto JrFNH; E2vYj: $this->response->setOutput($this->render()); goto ni9lW; Uiaii: $this->load->model("setting/setting"); goto k_VYk; nH1dO: BIjJS: goto GjvtR; sidLB: $this->session->data["error"] .= "<br/><br/>Also make sureto install this package: <a href="https://geekodev.com/easy-vqmod-installer">https://geekodev.com/easy-vqmod-installer</a>"; goto EFbfg; gDexH: ZR7YW: goto coaeH; guuTc: goto aGIYP; goto F9gv7; rrX0r: if (version_compare(VERSION, "3", ">=")) { goto sRfJY; } goto XCQlC; O5i_E: $this->session->data["error"] = "You have enabled <b>Absolute category path</b>, in this configuration it is necessary to set <b>Category path mode</b> and <b>Category canonical</b> to <b>Full path</b> else it will not be possible to find the corresponding category.<br/>It is also recommended to have <b>Product path mode</b> to <b>Largest path.</b>"; goto nH1dO; YhKhr: msLwd: goto lfYCB; W5rAL: $glDMO[] = $dfq9k . "remove_search"; goto SYFFf; fuAYw: goto JJqsH; goto O5U2r; M61Dd: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "jquery-editable.css")); goto l7AAM; QHYRE: if (!(version_compare(VERSION, "2", "<") && is_dir(DIR_APPLICATION . "controller/extension/module"))) { goto lCiyA; } goto S6Arn; ZiUIY: XHdVY: goto xruWw; Gdrq9: BGpcI: goto ZKJy8; Rqqf0: rPngW: goto q_0kd; Q3qRW: $data["stores"][] = array("store_id" => 0, "name" => $this->config->get("config_name")); goto sJMa_; IgEJP: Taqnj: goto utpoH; c0pmh: kcNa1: goto XMws7; Q1Oe1: $data["column_left"] = $this->load->controller("common/column_left"); goto WNUFz; QIOmi: R2RVC: goto YvgXT; UFMse: goto sb6ug; goto vhURE; nR3Mh: $data["stock_statuses"] = $this->model_localisation_stock_status->getStockStatuses(); goto ncI1j; wHNV4: Rs78v: goto v7x0d; XsvF9: $data["breadcrumbs"][] = array("text" => $this->language->get("text_module"), "href" => $xfz3p, "separator" => " :: "); goto uS0Fa; wjKCN: t0jZR: goto Ex9bo; GG3fW: goto rR44w; goto gDexH; tzsqg: $data["store_id"] = $UEbbE = 0; goto EGnhv; vgn10: goto bA44i; goto g_Sed; In2Oa: vRceA: goto quyMm; lhSZ1: goto StTmw; goto CeiZ4; vhURE: P8Pym: goto xUops; vXHvH: wqsBC: goto S_Jna; YvgXT: $y46IY = $this->config->get("config_gkdMSLang"); goto WCdOI; L5lWL: goto bYxCK; goto GsSYr; Xqus9: goto AQi4L; goto uqpTl; P5fG4: if (!($ieocD / 1024 > 1)) { goto GY8B0; } goto AmwvT; lQu4F: goto imG3F; goto ykNSo; WIpHD: Pn6S8: goto tKA_4; JrFNH: $this->response->setOutput($this->load->view("tool/gkd_license", $data)); goto hH51K; HBKMd: goto Owqly; goto Ao33z; rELE7: shMeG: goto HH007; jqU2e: CZYvf: goto dx1GT; zSoaW: ZwQfm: goto f0j2a; lrKJ1: if (in_array("advanced_sitemap", $VslUq)) { goto KfFJp; } goto rrX0r; bWoTI: goto Ss6pf; goto N1uZF; RR6jr: KL7t0: goto keH4r; PEpus: OKEPI: goto If0Ss; hH51K: goto tsHPw; goto jX1Lx; ZzYvI: if (!version_compare(VERSION, 3, ">=")) { goto S_BIf; } goto PZbpL; Q7KP3: $uPYqh = count($TqFxN); goto w76Fe; wR4q_: goto XBA11; goto cH8zE; LLTF5: iLU_Q: goto fJt6f; SHjnZ: $this->document->addStyle(self::$ASSET_PATH . "awesome/css/font-awesome.min.css"); goto LuUW3; wIySS: yNxiU: goto BlDHP; FTFlW: goto hw3sc; goto EMUv7; Q_QQI: ry9Wx: goto y55aT; Glohr: $VslUq = $this->model_setting_extension->getInstalled("feed"); goto okULr; Z0TZ1: goto ZLzv3; goto ejMIN; SJQpW: goto lxn9M; goto CPizL; LKN6F: foreach ($ih4Ag as $hYkcD) { goto sytbi; VIVFD: i02DG: goto uzt0h; sytbi: $Tt9wx = array(); goto YPead; YPead: $data["stores"][] = array("store_id" => $hYkcD["store_id"], "name" => $hYkcD["name"]); goto VIVFD; uzt0h: } goto cqbWx; U_jdY: n624J: goto lvAAz; OCJBF: $this->redirect($this->url->link(self::LINK, $this->token, "SSL")); goto phmJ1; ilTFm: goto RpLVC; goto WR4Xn; MuPU6: goto jC3yu; goto Tn8fF; N3sr0: goto e_T_g; goto Tgpxq; P1aAT: $data["error"] = "Error during activation process, please contact support"; goto HoQ4U; mz7Q1: tFz1_: goto QIOmi; sR2Ri: $this->load->model("setting/store"); goto uWVfm; BlDHP: $data["error"] = "License number format is incorrect"; goto kyjMK; Iz0DW: if (!empty($this->error["error"])) { goto ZPtf_; } goto bKbNt; h76bJ: $data["cli_log"] = file_get_contents($mMubI); goto IBw26; bIyMx: if (!(version_compare(VERSION, "2", "<") && is_dir(DIR_APPLICATION . "controller/extension/module"))) { goto rmC9B; } goto QHYRE; vJq4g: goto E6fTe; goto PpgDC; Q_pOR: goto sKWVG; goto iLhLV; PZbpL: goto dIeod; goto eDWVu; WfgVc: $this->document->addStyle(self::$ASSET_PATH . "style.css"); goto H3f9b; nKNVw: goto HVcvU; goto J4pt1; uvLDV: GFZxm: goto lFax7; Q06kI: ylCKb: goto aT7yy; xqdhG: frHiO: goto Q1Oe1; A1Vgu: goto ZR7YW; goto S5w_X; LOPWb: $xfz3p = $this->url->link("extension/module", $this->token, "SSL"); goto kxiD6; jYGjx: curl_setopt($KwAQS, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"); goto RlWHr; S0K_R: EV71N: goto dZdJm; ev2xs: $Qtmx4 = "mlseo_"; goto EX6T8; keH4r: if (empty($MGEsw["success"])) { goto Pn6S8; } goto OFqy0; uBN7d: $data["store_id"] = $UEbbE = (int) $this->request->get["store_id"]; goto Dj2Yc; y_ntd: KuxKD: goto KubLq; MDq5K: $glDMO[] = $dfq9k . "directcat"; goto jA1Xy; mHOEY: goto c2zDh; goto CeRSL; idG3M: $mMubI = DIR_LOGS . "seo_package_cli.log"; goto L8cYb; wMAQb: pF5Dh: goto D0wuj; fSzr6: $data["breadcrumbs"] = array(); goto nZh12; tKA_4: goto R0QNh; goto tuQzZ; dhVoH: if (!$RKWTW) { goto oiSlh; } goto AwOur; uVVFY: $data["error_warning"] = ''; goto wqK_m; lfYCB: goto g1OmK; goto tY2Ki; OocR0: $this->load->model("extension/extension"); goto UzcxS; JTxgL: $this->response->setOutput($this->load->view("module/complete_seo", $data)); goto qHFsN; w76Fe: $data["seo_score"] = round(count(array_filter($TqFxN)) * 100 / $uPYqh); goto ENoc_; AQU4I: PKvjB: goto aPFvN; EK28l: $this->session->data["error"] = "Module modification are not applied<br/>You have installed <b>ocmod</b> version, go to extensions > <a href="" . $this->url->link("extension/modification", $this->token) . "">modifications</a> and push refresh button"; goto aonE0; YRMW1: hSw6K: goto dbOze; uJ4jU: $data["column_left"] = $this->load->controller("common/column_left"); goto eZ0QL; MiDw4: goto PKvjB; goto szAlc; szAlc: oIAE9: goto UNzEb; jr8au: $this->session->data["error"] .= "<br/><br/>If you have opencart v2.x or 3.x and don't know what is vqmod or ocmod, then install ocmod version"; goto yLWsk; dbIwA: $this->load->model("localisation/language"); goto hBOhW; u8QAY: goto otT6f; goto eU1sh; ciQUe: XBA11: goto vJq4g; obHup: $data["journal2_active"] = is_dir(DIR_APPLICATION . "model/journal2"); goto Uhf1y; k_VYk: goto y0Ge3; goto KHPb9; akfOF: $this->session->data["error"] = "It seems you have modified your languages configuration, please save module options to activate multilingual handling"; goto jGTQ1; EU5mi: goto NSF3Y; goto LLTF5; Tnpwx: goto fOHi8; goto gcwSx; iORLQ: egvC5: goto hrM_J; hud_m: goto WEwMY; goto QwGii; D8y6l: goto vRceA; goto IERSE; OluKb: $this->children = array("common/header", "common/footer"); goto TQzxx; NDt27: lnFgc: goto QilHN; i09It: goto BGpcI; goto xqdhG; x7UB0: goto EsHWq; goto UmvVT; tCK94: lUWNq: goto I9SsE; Ex9bo: curl_setopt($KwAQS, CURLOPT_POST, 1); goto LhssX; phmJ1: goto vaALZ; goto fo1pS; yb2NI: goto QVHjQ; goto wMAQb; a4_ke: $data["OC_V2"] = version_compare(VERSION, "2", ">="); goto JQMDc; CeiZ4: Hm25k: goto JTJze; eKCXq: foreach ($glDMO as $yEvqp) { goto z1p_g; ecnkd: XUny_: goto dThQz; kXPch: $data[$yEvqp] = is_null($this->config->get($yEvqp)) ? '' : $this->config->get($yEvqp); goto ITHoA; tvHXX: Clvfo: goto elTcX; z1p_g: if (!($yEvqp && !isset($Wy0d3))) { goto XUny_; } goto A7Igl; ITHoA: goto iqCqq; goto tvHXX; elTcX: $data[$yEvqp] = $this->request->post[$yEvqp]; goto PN88Q; dThQz: if (isset($this->request->post[$yEvqp])) { goto Clvfo; } goto kXPch; A7Igl: return; goto ecnkd; PN88Q: iqCqq: goto pR0aV; pR0aV: nn7Sb: goto IYdCY; IYdCY: } goto CYOUI; U18oJ: if (empty($this->request->get["tab"])) { goto Wydk5; } goto h6zMB; DBaZ0: if (!($this->config->get("mlseo_redirect_canonical") > 1 && !$this->config->get("mlseo_fpp_bypasscat"))) { goto Zxs01; } goto kOXGI; zGN33: usort($data["categories"], array($this, "sortByName")); goto eKCXq; Dw04C: goto RicnI; goto F87gY; pDNL0: wyoN7: goto yubq2; PsQks: if (is_writable(DIR_CATALOG . "../.htaccess")) { goto QzCfQ; } goto SSaO8; cJK6i: $data["style_radial_meter"] = file_get_contents(self::$ASSET_PATH . "radial-meter.css"); goto mN7_K; zfaum: goto lTibQ; goto In2Oa; jaMn4: if (version_compare(VERSION, "2.3", ">=") && !$this->config->has("mlseo_default_lang")) { goto DHfbB; } goto kTrX5; YnzO_: v7fM5: goto MpvzY; Pu4Ts: if (!function_exists("mb_strtolower")) { $this->error["warning"] = "The php extension mb_string is not installed, the module can work without it but you may experience some incorrect values when generating seo values, it is recommended to enable this extension in php.ini"; } goto Sb0jx; pLtEi: goto FaUJ5; goto pBHnY; V0hKi: $data["column_left"] = ''; goto a8cMo; yWZ4t: $E5bYQ++; goto rMUKg; E1RKb: kCCw5: goto bAq23; iLGGN: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "style.css")); goto QjXPJ; LzoWL: $data["link_sitemap"] = $this->url->link("marketplace/extension", "type=feed&" . $this->token, "SSL"); goto msqEd; HH007: goto yNxiU; goto xOnEt; zpdTS: goto qt199; goto IUuyZ; AwOur: goto M1PSK; goto GeFVP; wYOzp: $Sc3w7 = array(); goto VKeAO; uGsgR: HWj91: goto mcRfn; Es1dX: goto NxDW4; goto SW5tH; P6Ej8: KXU3q: goto s6sxA; sJMa_: $ih4Ag = $this->model_setting_store->getStores(); goto LKN6F; AlNw7: goto A4f_w; goto QLNdn; A7wcY: $this->document->addScript(self::$ASSET_PATH . "select2.min.js"); goto jVu8q; y55aT: NKbsH: goto HBKMd; S5w_X: g1OmK: goto Hn1An; coaeH: $this->request->server["REQUEST_METHOD"] = "POST"; goto tInOR; Ep3Ui: if (!($Sc3w7 !== $this->config->get("mlseo_lang_codes"))) { goto Gxopa; } goto akfOF; HRNE5: fOHi8: goto oU6mg; rFOE8: $Wy0d3 = 1; goto N3sr0; GsSYr: JGZJm: goto K2REs; lvAAz: goto JvUeH; goto cdi4M; qR9VH: O6sXa: goto sR2Ri; HthF8: $this->response->setOutput($zOm7L->render("extension/complete_seo/module/complete_seo", $data)); goto dyVYp; OCJh7: xILuV: goto CSPmV; ufvZQ: foreach ($data["stores"] as $hYkcD) { goto D0hx6; D0hx6: $lKV_k = $this->model_setting_setting->getSetting("config", $hYkcD["store_id"]); goto TXpMv; qsfNg: VY7p3: goto iWPYP; AkPJV: $sXCGV[$lKV_k["config_language"]] = array("config_url" => !empty($lKV_k["config_url"]) ? rtrim($lKV_k["config_url"], "/") : rtrim(HTTP_CATALOG, "/"), "config_ssl" => !empty($lKV_k["config_ssl"]) ? rtrim($lKV_k["config_ssl"], "/") : rtrim(HTTPS_CATALOG, "/")); goto qsfNg; TXpMv: if (empty($lKV_k["config_language"])) { goto VY7p3; } goto AkPJV; iWPYP: b4BnW: goto gzqJL; gzqJL: } goto YwXeI; gdsgA: vaALZ: goto FwIVx; TwPcP: RpLVC: goto nKNVw; wTwXj: ZUw1_: goto lqT18; HyeUX: GE2Uo: goto o2mDb; EHBTQ: $glDMO[] = $dfq9k . "bc_mode"; goto HiMyM; iRPTY: $data["cancel"] = $xfz3p; goto JeCNV; BsgaD: $this->document->addStyle(self::$ASSET_PATH . "prettyCheckable.css"); goto KjdIP; L8cYb: if (!file_exists($mMubI)) { goto pHXIa; } goto ThQsH; mcRfn: h0wsN: goto SJQpW; g_Jkz: e_T_g: goto hgqJ9; cjql4: goto QDqYA; goto iB7ST; DngBZ: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "gkd-theme.css")); goto H_dH5; H_kGT: dIeod: goto cbK7_; wsd2l: if (empty($this->session->data["currentTab"])) { goto O6sXa; } goto aO_YX; zdGY3: $data["footer"] = $this->load->controller("common/footer"); goto yb2NI; CSPmV: goto x0s8t; goto KAChM; XMws7: $lVHlh = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); goto K0dTV; SQ6kE: $glDMO[] = $dfq9k . "brand_parent"; goto W5rAL; QjXPJ: $this->document->addScript(self::$ASSET_PATH . "bootstrap.min.js"); goto KPTLK; t2BW1: die; goto Xqus9; jOEsE: goto oIAE9; goto Ulp7q; DfZc3: i9Mfn: goto GQKzO; Hn1An: if ($this->request->server["REQUEST_METHOD"] == "POST" && isset($this->request->post["lic_number"])) { goto zTbAp; } goto omtVV; O0gtf: $data["asset_path"] = self::$ASSET_PATH; goto BsgaD; dLqaS: JBmfK: goto q8InA; Pa0M5: cVgmm: goto VFZHb; ZlxUE: $this->children = array("common/header", "common/footer"); goto YuWnB; JcBKM: $this->document->addStyle(self::$ASSET_PATH . "gkd-theme.css"); goto WfgVc; FGSgv: $KwAQS = curl_init(); goto Dw04C; JCIe_: $this->session->data["error"] = "Module modification are not applied<br/>You have installed <b>vqmod</b> version, make sure vqmod is correctly installed and working.\xa          <br/><br/>If vqmod is correctly installed, please try the following:\xa          <br/>- delete all files into <b>/vqmod/vqcache/</b> folder
          <br/>- delete the files <b>checked.cache</b> and <b>mods.cache</b> in <b>/vqmod/</b> folder
          <br/>- reload this page"; goto dzJNP; QwGii: XSgis: goto BojNg; MpvzY: goto n624J; goto GG3fW; OggeH: goto ZUw1_; goto wShAW; LuUW3: $data["style_scoped"] = file_get_contents(self::$ASSET_PATH . "bootstrap.min.css"); goto M61Dd; H3f9b: goto V31PC; goto HyeUX; mWhRd: $RKWTW = isset($this->request->get["refresh"]) ? 1 : rand(1, 12) == 2; goto D8y6l; PhKSX: $data["style_scoped"] = file_get_contents(self::$ASSET_PATH . "bootstrap.min.css"); goto E355q; QgNI2: sNy7f: goto Cg1qQ; Q7mrS: $sXCGV = array(); goto ufvZQ; bAq23: goto tYa6i; goto iM354; j4a6M: tp2Me: goto pQ1H2; neBSO: if (!(strpos($pulAQ, "index.php?_route_=$2&site_language=$1") !== false)) { goto i9Mfn; } goto PsQks; KJohC: StTmw: goto EU5mi; gZmGp: rmC9B: goto Q7mrS; fa7Qr: $data["journal_active"] = is_dir(DIR_APPLICATION . "model/journal2") || is_dir(DIR_APPLICATION . "model/journal3"); goto obHup; FwIVx: goto z8p_W; goto lQu4F; Sb0jx: if ($this->OC_V22X) { goto Rs78v; } goto INNuR; UmvVT: NSF3Y: goto mr51M; KAChM: pbejP: goto fuAYw; dbOze: goto jmPSq; goto FV9fK; QLNdn: QVHjQ: goto Hr76T; XteGL: O1PDs: goto CrCl3; wShAW: FyqtB: goto YE3MU; Jz83I: $this->document->addStyle(self::$ASSET_PATH . "jquery-editable.css"); goto JcBKM; L8fGO: goto HeLGV; goto pDNL0; KHPb9: XYe2v: goto tOuMH; PJGjp: $this->error["warning"] = "Warning : both vqmod and ocmod version are installed<br/>- delete /vqmod/xml/" . self::MOD_FILE . ".xml if you want to use ocmod version<br/>- or delete /system/" . self::MOD_FILE . ".ocmod.xml if you want to use vqmod version"; goto moaNm; IBw26: goto IKppR; goto c0pmh; kVpaN: $ieocD = filesize($mMubI); goto GsjWO; fzl30: $xfz3p = $this->url->link("marketplace/extension", "type=module&" . $this->token, "SSL"); goto C2tp2; LhgYO: $MGEsw = (array) @json_decode($KntYp); goto GzJat; NVtaz: goto R6pkt; goto wIySS; JeCNV: $data["cli_log"] = $data["cli_log_link"] = ''; goto idG3M; vDrU9: $data["module_route"] = self::$LINK; goto DBvGq; desbV: wig5K: goto T0M9X; trIFh: Dkal0: goto QTXtG; F47tw: goto fXTLL; goto Ja3I6; JQMDc: $data["OC_V151"] = $this->OC_V151; goto Yxu0v; o2mDb: $this->document->addScript(self::$ASSET_PATH . "jquery-migrate.js"); goto SHjnZ; UxJOm: ONRO2: goto xs5Zo; nZZKl: if ($data["module_type"] == "ocmod") { goto PMOm6; } goto R8z5h; TJj2s: goto TlGrc; goto OpATk; Bcexg: goto sEW2r; goto l4OHH; WkcRT: AyyjU: goto hxO1g; ip5J_: $glDMO[] = $dfq9k . "depth"; goto fVgkt; B583F: @rename(DIR_APPLICATION . "controller/feed/seopackage_sitemap.php", DIR_APPLICATION . "controller/feed/seopackage_sitemap.php_disabled"); goto jY13w; IERSE: JvUeH: goto Q_pOR; PXOa5: wqPkW: goto fzl30; UsPKO: bYxCK: goto cfaS1; vlqAp: goto peZwj; goto TwPcP; pSla1: goto W9O5y; goto PEpus; b11yH: if (!(is_file(DIR_SYSTEM . "../vqmod/xml/" . self::MOD_FILE . ".xml") && is_file(DIR_SYSTEM . "../system/" . self::MOD_FILE . ".ocmod.xml"))) { goto pC9VL; } goto PJGjp; fJt6f: JJqsH: goto L5lWL; uqpTl: bA44i: goto AmDxN; w_9Wl: $this->load->model("sale/customer_group"); goto zJQI8; KubLq: if (extension_loaded("mbstring")) { goto dVewr; } goto DK53K; cqbWx: IZnGn: goto tzsqg; PpgDC: sRfJY: goto LzoWL; YuWnB: goto F7leC; goto PdqKe; iLhLV: goto ugQJ2; goto desbV; Dhg41: goto ZYRX8; goto maKBr; Iz5Kz: iwNr8: goto jYGjx; HoQ4U: goto xoWwu; goto VUeh0; WVkwz: NF0sK: goto ErqUl; CrCl3: if (!is_file(DIR_CATALOG . "../vqmod/xml/multilingual_seo.xml")) { goto tciec; } goto BGpyO; WR4Xn: TlGrc: goto TeSIv; dZdJm: goto ZUHkM; goto WnSX6; KYeIU: $this->document->addScript(self::$ASSET_PATH . "itoggle.js"); goto Lx0Fy; l7AAM: $data["style_scoped"] .= str_replace("img/", self::$ASSET_PATH . "img/", file_get_contents(self::$ASSET_PATH . "gkd-theme.css")); goto iLGGN; us_B6: $glDMO[] = $dfq9k . "mode"; goto ip5J_; XGAmu: S20PO: goto hud_m; aPFvN: $this->load->model("setting/setting"); goto BTV3I; YE3MU: goto xlb1G; goto NYzmT; beXVm: goto XSgis; goto YnzO_; SYFFf: $glDMO[] = $dfq9k . "remove_tag"; goto LdWEy; F87gY: Ozol2: goto dhVoH; oU6mg: z8p_W: goto ilTFm; XWhny: HeLGV: goto RXXZt; FV9fK: zmXyh: goto gCUf2; TeR3y: if (version_compare(VERSION, "3", ">=")) { goto wqPkW; } goto W1B6n; EFbfg: goto FMzvq; goto yeyGu; vXKlM: $data["_url"] =& $this->url; goto NvK5r; mtyne: goto WaDVC; goto xbTMV; xbTMV: goto HWj91; goto j4a6M; cNZqa: PL_Zz: goto VXjSA; vSET7: $this->document->addStyle(self::$ASSET_PATH . "jquery.dataTables.min.css"); goto TXsHI; Yt22v: $this->request->server["REQUEST_METHOD"] = "GET"; goto xH49a; eZ0QL: $data["footer"] = $this->load->controller("common/footer"); goto mVUk2; v2529: foreach ($Lw2AU as $tV0zs) { $VslUq[] = $tV0zs["code"]; Gpf7f: } goto Rqqf0; SC202: if (!$RKWTW || isset($this->request->get["refresh"])) { goto wll4p; } goto AP4pm; MXPSm: kD8OF: goto Zozj3; g_Sed: WEwMY: goto xFzTm; xs5Zo: $this->load->model("localisation/stock_status"); goto nR3Mh; tF1pd: $data["column_left"] = ''; goto Ur7Ka; G_V7g: if (empty($MGEsw["success"])) { goto Hm25k; } goto lhSZ1; vmGvA: sb6ug: goto qk9bq; lDBSc: IKppR: goto EFzR6; AP4pm: goto Xh0m8; goto Pcqen; tuQzZ: ugQJ2: goto wTwXj; f0j2a: if (isset($this->session->data["error"])) { goto lnFgc; } goto Iz0DW; RpPy1: OhI8w: goto XfoSD; T0M9X: if (!version_compare(VERSION, "2", ">=")) { goto il4__; } goto p0wtn; eDWVu: S_BIf: goto Bcexg; rcqeH: goto pF5Dh; goto jqU2e; Jd09w: foreach ($XktyI as $rhdWd => $Zu00a) { goto OAZxg; OAZxg: if (empty($y46IY[$Zu00a["code"]])) { goto gPVpD; } goto YDDj3; YDDj3: unset($XktyI[$rhdWd]); goto PzU1e; PzU1e: gPVpD: goto D9OqA; D9OqA: aei_d: goto crSu9; crSu9: } goto AlV64; OFqy0: goto zNNHP; goto WIpHD; Nxcx_: ahhud: goto BO2J2; o9zAR: $this->response->setOutput($this->load->view("tool/gkd_license.tpl", $data)); goto iqjDY; hxO1g: $data["success"] = $this->session->data["success"]; goto d3my7; UNzEb: $data["error"] = $MGEsw["error"]; goto zKet3; OpATk: jmPSq: goto NZJPD; QSEbR: if (!(strpos(strtolower($_SERVER["SERVER_SOFTWARE"]), "apache") !== false && !is_file(DIR_CATALOG . "../.htaccess"))) { goto O1PDs; } goto bTwB0; Dj2Yc: $R7oWZ = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . $UEbbE . "'"); goto T93KV; dTky9: Mplkr: goto DfZc3; tbF5r: stq6R: goto QgNI2; TrsBr: $data["button_remove"] = $this->language->get("button_remove"); goto JMXKA; DIcKV: $yygZ5 = "&store_id=" . $UEbbE; goto CXr_n; Gttr5: tlHjw: goto gh32N; T93KV: foreach ($R7oWZ->rows as $ZoaKJ) { goto mWOZ9; w515t: A98WX: goto Nzl5u; u8bRx: if ($this->OC_V21X) { goto A98WX; } goto Ke92J; Nzl5u: $this->config->set($ZoaKJ["key"], json_decode($ZoaKJ["value"], true)); goto nwN4D; XfH9V: goto R2SoO; goto w515t; T84p6: G1a9E: goto QDqe9; va7WV: $this->config->set($ZoaKJ["key"], $ZoaKJ["value"]); goto zwJyA; Ke92J: $this->config->set($ZoaKJ["key"], unserialize($ZoaKJ["value"])); goto XfH9V; i4sFo: goto iDEL2; goto KoBN7; zwJyA: iDEL2: goto T84p6; nwN4D: R2SoO: goto i4sFo; KoBN7: aROFm: goto va7WV; mWOZ9: if (!$ZoaKJ["serialized"]) { goto aROFm; } goto u8bRx; QDqe9: } goto mz7Q1; v7x0d: if (!($this->config->get("mlseo_flag") || isset($this->request->post["mlseo_flag"]) && $this->request->post["mlseo_flag"])) { goto piCNG; } goto bAzPF; Y58Ab: $Lw2AU = $this->model_setting_extension->getInstalls(); goto v2529; kVydk: fsJHu: goto i09It; zDIk0: Zxs01: goto iaKGW; NbOsx: $data["header"] = $this->load->controller("common/header"); goto zOEPj; gCUf2: sJqH6: goto BD_gn; y0sVb: goto SDUK9; goto MXPSm; WCdOI: if (empty($y46IY)) { goto wqsBC; } goto Jd09w; e2cjG: OJDud: goto VLnRc; gtREI: PMOm6: goto EK28l; ijHHG: goto P6cpl; goto WVkwz; Uhf1y: $data["journal3_active"] = is_dir(DIR_APPLICATION . "model/journal3"); goto qtj2r; M1Wlq: hw3sc: goto J3YX1; a6xyT: WTMfi: goto zko0O; Brz2W: goto grxUj; goto RR6jr; OBwxw: file_put_contents(DIR_CATALOG . "../.htaccess", $pulAQ); goto dTky9; Aohj5: otT6f: goto S8wnQ; zJQI8: $data["customer_groups"] = $this->model_sale_customer_group->getCustomerGroups(); goto vWvCp; VUeh0: xlb1G: goto ZzYvI; EMUv7: O7NDK: goto JCIe_; eU1sh: wWOde: goto C432k; zNLR0: foreach (array(self::MOD_FILE, "a_" . self::MOD_FILE, "z_" . self::MOD_FILE) as $lJFer) { goto AHWQa; Cz9_2: qo1VS: goto Up1o5; RJu2S: goto qNdtv; goto WthvM; n1DP2: goto UhoiE; goto edfmN; XgwkT: if (is_file(DIR_SYSTEM . "../system/" . $lJFer . ".ocmod.xml")) { goto MXPQF; } goto QXQR9; uChVE: $data["module_version"] = @simplexml_load_file(DIR_SYSTEM . "../system/" . $lJFer . ".ocmod.xml")->version; goto nyqNT; NDTJ7: qNdtv: goto d3KO9; AM_UF: $data["module_type"] = ''; goto RJu2S; d3KO9: goto GNRkP; goto Cz9_2; UR6HU: goto Co1Sr; goto NDTJ7; edfmN: HgDeF: goto IMQhG; b2VG4: GNRkP: goto n1DP2; QXQR9: $data["module_version"] = "not found"; goto AM_UF; xcPoz: $data["module_type"] = "vqmod"; goto b2e_H; CEGXW: goto Co1Sr; goto b2VG4; qWiLb: $data["module_type"] = "vqmod"; goto CEGXW; HGE6h: UhoiE: goto nMrIq; WthvM: MXPQF: goto uChVE; nyqNT: $data["module_type"] = "ocmod"; goto UR6HU; nMrIq: Wq2Ij: goto RA3QJ; Up1o5: $data["module_version"] = @simplexml_load_file(DIR_SYSTEM . "../vqmod/xml/" . $lJFer . ".xml")->version; goto qWiLb; b2e_H: goto Co1Sr; goto HGE6h; AHWQa: if (defined("DIR_EXTENSION") && is_file(DIR_EXTENSION . self::MODULE . "/" . $lJFer . ".xml")) { goto HgDeF; } goto gmHBC; IMQhG: $data["module_version"] = @simplexml_load_file(DIR_EXTENSION . self::MODULE . "/" . $lJFer . ".xml")->version; goto xcPoz; gmHBC: if (is_file(DIR_SYSTEM . "../vqmod/xml/" . $lJFer . ".xml")) { goto qo1VS; } goto XgwkT; RA3QJ: } goto lPkC_; Ja3I6: Y2ip6: goto ZlxUE; DHIOl: $data["button_cancel"] = $this->language->get("button_cancel"); goto GjPR2; s6sxA: if (!($this->config->get("config_seo_url_type") == "seo_pro")) { goto OJDud; } goto ow405; aT7yy: goto Ozol2; goto S6ZkA; UO8jK: if ($UEbbE) { goto sNy7f; } goto hI4rY; YNjue: CVK2s: goto P5fG4; VXjSA: goto c6SyB; goto zcnON; RDFxE: p1Ixd: goto wdSih; LmAbP: if (version_compare(VERSION, "2", ">=")) { goto P8Pym; } goto Tl5r5; qHFsN: qt199: goto KxyoD; NtiSD: Wydk5: goto NTfTf; DBvGq: $data["route_sep"] = version_compare(VERSION, "4", "<") ? "/" : "|"; goto V8KtV; gh32N: goto MGEfU; goto Q_QQI; xIxNI: $data["token"] = $this->token; goto YHqKR; CPizL: c6SyB: goto tJ7JO; NMXkQ: il4__: goto xgqUR; IibAM: goto SCmO8; goto Iz5Kz; tWtSO: $this->model_setting_setting->editSetting(md5(HTTP_SERVER . self::MODULE), array(md5(HTTP_SERVER . self::MODULE) => $MGEsw["info"])); goto rYqOJ; IZ0gZ: $this->request->post = array("lic_number" => $data["license_info"]["license"]); goto vlqAp; LhssX: goto iwNr8; goto UsPKO; Tgpxq: EsHWq: goto kVydk; ck01b: pOwY1: goto A1Vgu; Zozj3: if (!$this->request->post["lic_number"] || strlen(trim($this->request->post["lic_number"])) != 17) { goto shMeG; } goto w1IeK; QTXtG: curl_setopt($KwAQS, CURLOPT_BINARYTRANSFER, true); goto AlNw7; J3YX1: goto cOQlJ; goto gtREI; qFgpB: $this->document->addStyle(self::$ASSET_PATH . "awesome/css/font-awesome.min.css"); goto XUT7n; CeRSL: BUV62: goto zdGY3; SW5tH: tYa6i: goto Axs9T; WyOJ6: goto NF0sK; goto gdsgA; yLWsk: FMzvq: goto M1Wlq; D0wuj: if (empty($data["error"])) { goto tlHjw; } goto iFhcR; tInOR: goto q3mXM; goto yXFi9; yXFi9: SDUK9: goto g7YSI; AmDxN: $RKWTW = false; goto u8QAY; dNIQq: hxfHh: goto P6Ej8; AHi1S: VmM3E: goto WQj4T; ni9lW: goto pbejP; goto XuGlZ; rsY0V: $data["success"] = ''; goto GnCao; HA0uW: goto VmM3E; goto icFdC; TuUk8: BojEF: goto DBaZ0; rUqv1: $this->session->data["error"] = "Install not complete : multilingual_seo class declaration not found in index.php, maybe the file was not writeable, manual procedure : <br/>- open index.php<br />- find the text (without outter quotes): $languages = array();<br/>- add just below the previous line this text: $multilingual = new multilingual_seo($registry); $multilingual->detect();"; goto p1wVd; iFhcR: goto fsJHu; goto Gttr5; FosLe: GY8B0: goto VuO5b; mN7_K: if (version_compare(VERSION, "4", ">")) { goto b8dg4; } goto clzOL; C2tp2: YaG9G: goto XsvF9; zuteY: CClwY: goto P1aAT; W9hnQ: $TqFxN[] = $this->config->get("mlseo_enabled"); goto Q7KP3; h6zMB: $this->session->data["currentTab"] = $this->request->get["tab"]; goto NtiSD; UzcxS: $VslUq = $this->model_extension_extension->getInstalled("feed"); goto RDFxE; xH49a: goto JnJRz; goto g_Jkz; Axs9T: $data["license_info"] = json_decode(base64_decode($I2PwC), 1); goto jwRaD; iADIk: $this->load->model("setting/setting"); goto dbIwA; qnJiu: $this->install("redir"); goto y_ntd; a2nQh: goto v5VXr; goto cNZqa; BO2J2: $I2PwC = $this->config->get(md5(HTTP_SERVER . self::MODULE)); goto vgn10; ipkjI: goto wWOde; goto Gdrq9; I9SsE: $data["languages"] = $XktyI; goto U18oJ; SvBDS: $this->data =& $data; goto Es1dX; Ny7f1: W9O5y: goto mWhRd; Yy91z: $zOm7L->addPath("extension/complete_seo", DIR_EXTENSION . "complete_seo/admin/view/template/"); goto HthF8; V8KtV: $data["module_route_sep"] = self::$LINK . $data["route_sep"]; goto O0gtf; f9N1E: QDqYA: goto wLhPW; jA1Xy: $glDMO[] = $dfq9k . "homelink"; goto SQ6kE; aonE0: cOQlJ: goto vo1Jj; c7zrD: $this->session->data["error"] = "It seems you have installed another language, please save module options to activate multilingual handling"; goto TuUk8; b0YVg: dVewr: goto UO8jK; i1OZF: $pulAQ = str_replace("RewriteRule ^(?:(?:(\w{2})(?:/|\z))?(?:/|\z)?)?(?:([^?]*))? index.php?_route_=$2&site_language=$1 [L,QSA]", '', $pulAQ); goto OBwxw; mr51M: KuVBd: goto jaMn4; f4Igy: if ($RKWTW) { goto pOwY1; } goto uJV1m; jVu8q: $this->document->addScript(self::$ASSET_PATH . "toggler.js"); goto X9K4Y; if_dy: WXj4H: goto TZE_h; q_0kd: jC3yu: goto lrKJ1; y6LDy: goto ne10O; goto mM6ky; YwXeI: Oxzmp: goto oNgZO; uJV1m: goto msLwd; goto ck01b; nhT2L: WQ00i: goto tF1pd; DHaCG: LYm80: goto p6bdu; iB7ST: MHxBE: goto s_YlN; Waydq: u8lxy: goto NbOsx; S6Arn: $this->session->data["error"] = "OC v1.5 - Please delete the folder " . DIR_APPLICATION . "controller/extension/module"; goto NoZi0; ezHYS: $this->session->data["error"] = "There is some urls which have incorrect language assignation, please go in Mass Update and do a "Clean up""; goto dNIQq; H4UTK: $data["upgrade_url"] = $this->url->link(self::$LINK_SEP . "upgrade", $this->token, "SSL"); goto iRPTY; zcnON: imG3F: goto YRMW1; pQ1H2: WaDVC: goto NVtaz; Tn8fF: D1q0_: goto JZ75x; yeyGu: RFbg9: goto jr8au; JZ75x: $a_wta = []; goto Mf_XZ; Th9Qb: goto iLU_Q; goto Nxcx_; q505M: $data["link_sitemap"] = $this->url->link("feed/advanced_sitemap", $this->token, "SSL"); goto r7L3h; YLLsl: $this->template = "tool/gkd_license.tpl"; goto IybqL; zOEPj: goto frHiO; goto Ny7f1; QQdRC: $modification_active = false; goto FxsyT; t5ibL: if (!(strpos($Kcjpq, "new multilingual_seo") === false)) { goto qhash; } goto rUqv1; okULr: goto p1Ixd; goto imPT5; p6bdu: $xfz3p = $this->url->link("extension/extension", "type=module&" . $this->token, "SSL"); goto uvLDV; ykNSo: AQi4L: goto f9N1E; vMXBJ: Owqly: goto rFOE8; GQKzO: piCNG: goto J8wkT; Rfk38: M1PSK: goto lxsWx; HAxdm: if (version_compare(VERSION, "2", ">=")) { goto JDDUE; } goto CPKH1; xOnEt: Ss6pf: goto rehCP; WzRGv: if (version_compare(VERSION, "3", ">=")) { goto egvC5; } goto HAxdm; s0yf2: $pulAQ = str_replace("#RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]", "RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]", $pulAQ); goto i1OZF; ErqUl: curl_setopt($KwAQS, CURLOPT_REFERER, "http://{$_SERVER["HTTP_HOST"]}{$_SERVER["REQUEST_URI"]}"); goto IibAM; iirF7: QzCfQ: goto s0yf2; EX6T8: $glDMO = array("mlseo_enabled", "mlseo_url_absolute", "mlseo_friendly", "mlseo_multistore", "mlseo_backup", "mlseo_404", "mlseo_redirect", "mlseo_autolink", "mlseo_absolute", "mlseo_redirect_dynamic", "mlseo_redirect_http", "mlseo_redirect_canonical", "mlseo_cat_slash", "mlseo_redir_reviews", "mlseo_cache", "mlseo_preload", "mlseo_banners", "mlseo_special_group", "mlseo_format_tag", "mlseo_fix_search", "mlseo_fix_cart", "mlseo_editor", "mlseo_shortcut", "mlseo_headings", "mlseo_404_log", "mlseo_404_filter", "mlseo_404_filter_ext", "mlseo_404_redir", "mlseo_flag_mode", "mlseo_store_mode", "mlseo_flag", "mlseo_flag_detect", "mlseo_flag_short", "mlseo_flag_upper", "mlseo_flag_default", "mlseo_flag_custom", "mlseo_tag", "mlseo_sort", "mlseo_search", "mlseo_pagination", "mlseo_pagination_fix", "mlseo_pagination_canonical", "mlseo_disable_other_store_links", "mlseo_reviews", "mlseo_canonical", "mlseo_hreflang", "mlseo_hreflang_mode", "mlseo_hreflang_xdefault", "mlseo_robots", "mlseo_meta_robots", "mlseo_store", "mlseo_title_prefix", "mlseo_title_suffix", "mlseo_header_lm_product", "mlseo_header_lm_category", "mlseo_header_lm_information", "mlseo_header_lm_manufacturer", "mlseo_whitespace", "mlseo_extension", "mlseo_extension_mode", "mlseo_safe_url", "mlseo_lowercase", "mlseo_duplicate", "mlseo_insertautotitle", "mlseo_editautotitle", "mlseo_update_description", "mlseo_insertautourl", "mlseo_editautourl", "mlseo_insertautoseotitle", "mlseo_editautoseotitle", "mlseo_insertautometakeyword", "mlseo_editautometakeyword", "mlseo_insertautometadesc", "mlseo_editautometadesc", "mlseo_insertautodesc", "mlseo_editautodesc", "mlseo_insertautoh1", "mlseo_editautoh1", "mlseo_insertautoh2", "mlseo_editautoh2", "mlseo_insertautoh3", "mlseo_editautoh3", "mlseo_insertautoimgtitle", "mlseo_editautoimgtitle", "mlseo_insertautoimgalt", "mlseo_editautoimgalt", "mlseo_insertautoimgname", "mlseo_editautoimgname", "mlseo_insertautotags", "mlseo_editautotags", "mlseo_insertautorelated", "mlseo_editautorelated", "mlseo_product_url_pattern", "mlseo_product_title_pattern", "mlseo_product_h1_pattern", "mlseo_product_h2_pattern", "mlseo_product_h3_pattern", "mlseo_product_keyword_pattern", "mlseo_product_description_pattern", "mlseo_product_full_desc_pattern", "mlseo_product_image_name_pattern", "mlseo_product_image_alt_pattern", "mlseo_product_image_title_pattern", "mlseo_product_tag_pattern", "mlseo_product_related_no", "mlseo_product_related_relevance", "mlseo_product_related_samecat", "mlseo_category_url_pattern", "mlseo_category_h1_pattern", "mlseo_category_h2_pattern", "mlseo_category_h3_pattern", "mlseo_category_title_pattern", "mlseo_category_keyword_pattern", "mlseo_category_description_pattern", "mlseo_category_full_desc_pattern", "mlseo_information_url_pattern", "mlseo_information_h1_pattern", "mlseo_information_h2_pattern", "mlseo_information_h3_pattern", "mlseo_information_title_pattern", "mlseo_information_keyword_pattern", "mlseo_information_description_pattern", "mlseo_information_full_desc_pattern", "mlseo_manufacturer_url_pattern", "mlseo_manufacturer_h1_pattern", "mlseo_manufacturer_h2_pattern", "mlseo_manufacturer_h3_pattern", "mlseo_manufacturer_title_pattern", "mlseo_manufacturer_keyword_pattern", "mlseo_manufacturer_description_pattern", "mlseo_manufacturer_full_desc_pattern", "mlseo_microdata", "mlseo_microdata_data", "mlseo_opengraph", "mlseo_opengraph_data", "mlseo_fb_pixel", "mlseo_tcard", "mlseo_tcard_data", "mlseo_gpublisher", "mlseo_gpublisher_data", "mlseo_cron", "mlseo_cron_log"); goto lT1AV; F9gv7: goto ry9Wx; goto ZiUIY; rYqOJ: goto gy0UK; goto f8UqU; bTwB0: $this->session->data["error"] = "htaccess file not found : Please rename <b>.htaccess.txt</b> to <b>.htaccess</b> in order to enable url rewriting"; goto XteGL; BTV3I: goto ax3DL; goto wjKCN; ejMIN: ZPtf_: goto Lhp1O; FxsyT: if ($modification_active) { goto wi60I; } goto nZZKl; Vmnw3: RicnI: goto wGce8; BGpyO: $this->session->data["error"] = "Old version of the module detected, please remove this file :<b>/vqmod/xml/multilingual_seo.xml</b>"; goto G7pct; iqjDY: goto v7fM5; goto ScKfj; R4BDR: $glDMO[] = $dfq9k . "cat_canonical"; goto EHBTQ; gcwSx: x0s8t: goto guuTc; tJ7JO: $Wy0d3 = 1; goto y0sVb; GjPR2: $data["button_add_module"] = $this->language->get("button_add_module"); goto TrsBr; CXr_n: Hd5Bt: goto bIyMx; FKmlZ: goto CClwY; goto HxAVF; dyVYp: QLh9g: goto XWhny; dx1GT: bM7hS: goto ZbNuc; H6f5u: $this->response->setOutput($this->load->view("module/complete_seo.tpl", $data)); goto zpdTS; qsOyZ: Ht6v5: goto MuPU6; wqK_m: goto CCkUp; goto dLqaS; hrM_J: $this->load->model("setting/extension"); goto wHgkQ; QL01I: CCkUp: goto fSzr6; suDbr: sKWVG: goto Th9Qb; XuGlZ: rR44w: goto H_kGT; F2_W4: if (isset($this->session->data["success"])) { goto AyyjU; } goto rsY0V; CPKH1: $this->load->model("setting/extension"); goto Glohr; tY2Ki: JnJRz: goto SC202; cfaS1: return 0; goto F47tw; Lx0Fy: $this->document->addScript(self::$ASSET_PATH . "jquery-editable.min.js"); goto A7wcY; Tl5r5: $this->redirect($this->url->link(self::$LINK, $this->token, "SSL")); goto UFMse; PB5BL: goto t0jZR; goto Waydq; aYJEu: goto vJjOA; goto ipkjI; xNRKz: $YLVI9 = $this->db->query("SELECT " . $this->url_alias . "_id FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0 LIMIT 1")->row; goto ChJua; GsjWO: if ($ieocD >= 5242880) { goto kcNa1; } goto h76bJ; gKPjE: goto KuVBd; goto SQv18; g7YSI: v5VXr: goto pSla1; AlV64: PoTnz: goto vXHvH; f8UqU: lxn9M: goto Uiaii; mXY76: SCmO8: goto i3I5p; qtj2r: if ($this->user->hasPermission("modify", self::$LINK)) { goto s7sn6; } goto uQh4b; mVUk2: if (version_compare(VERSION, "4", ">=")) { goto U2sOE; } goto Cqs3q; X9K4Y: $this->document->addScript(self::$ASSET_PATH . "jquery.dataTables.min.js"); goto vSET7; yubq2: $data["header"] = $this->load->controller("common/header"); goto uJ4jU; RXXZt: }  
   
  public function save_cli_log() { 
    $file = DIR_LOGS.'seo_package_cli.log'; 
    header('Content-Description: File Transfer'); 
    header('Content-Disposition: attachment; filename=seo_package_cron.log'); 
    header('Content-Type: text/plain'); 
    header('Cache-Control: must-revalidate'); 
    header('Content-Length: ' . filesize($file)); 
    readfile($file); 
    exit; 
  } 
   
  public function generator_related_product($mode, $simulate, $empty_only, $redirect) { 
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
     
    if (!defined('SEO_PACKAGE_CLI')) { 
      $this->limit = 50; // limit more to not cause timeout 
    } 
     
    $values = $data = array(); 
    $data['langs'][0]['lang_img'] = ''; 
       
    if (isset($this->request->post['mlseo_product_related_samecat'])) { 
      $same_cat = $this->request->post['mlseo_product_related_samecat']; 
    } else if ($this->config->get('mlseo_product_related_samecat')) { 
      $same_cat = $this->config->get('mlseo_product_related_samecat'); 
    } else { 
      $same_cat = false; 
    } 
     
    $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=".$this->config->get('config_language_id')." ORDER BY pd.product_id,pd.language_id")->row; 
    $this->total_items = $total['total']; 
       
    if ($same_cat) { 
      $rows = $this->db->query("SELECT pd.*, p.*, (SELECT cp.category_id FROM " . DB_PREFIX . "product_to_category pc LEFT JOIN " . DB_PREFIX . "category_path cp on cp.category_id = pc.category_id WHERE pc.product_id = pd.product_id ORDER BY cp.level DESC LIMIT 1) as category_id FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=" . $this->config->get('config_language_id') . " ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
    } else { 
      $rows = $this->db->query("SELECT pd.*, p.* FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=" . $this->config->get('config_language_id') . " GROUP BY pd.product_id ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
      //$rows = $this->db->query("SELECT pd.*, p.*, pc.category_id FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id LEFT JOIN " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id WHERE language_id=" . $this->config->get('config_language_id') . " GROUP BY pd.product_id ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
    } 
     
    foreach ($rows as $row) { 
      $this->session->data['seopackage_processed']++; 
       
      if (empty($row['product_id'])) continue; 
       
      //$rel_count = $this->db->query("SELECT COUNT(*) AS count FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $row['product_id'] . "'")->row; 
       
      $related = $this->db->query("SELECT pr.related_id, pd.name FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product_description pd ON (pd.product_id = pr.related_id AND pd.language_id='" . (int) $this->config->get('config_language_id')."') WHERE pr.product_id='" . (int) $row['product_id'] . "'")->rows; 
       
      $old_related = array(); 
      foreach ($related as $rel) { 
        $old_related[] = '- ' . $rel['name']; 
      } 
       
      if ($empty_only) { 
        if (count($related)) { 
          continue; 
        } 
      } else { 
        if (!$simulate) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $row['product_id'] . "'" ); 
        } 
      } 
       
      $prod_name = str_replace(array('%', '#', "'", '"'), '', $row['name']); 
      $prod_tag = str_replace(array('%', '#', "'", '"'), '', $row['tag']); 
      $prod_desc = str_replace(array('\n', '\r', '%', '#', "'", '"'), '', $row['description']); 
      $prod_cat = ''; 
       
      if ($same_cat && !empty($row['category_id'])) { 
        $prod_cat = " AND pc.category_id = '" .$row['category_id'] . "' "; 
      } 
       
      if (!empty($this->request->post['mlseo_product_related_relevance'])) { 
        $relevance = $this->request->post['mlseo_product_related_relevance']; 
      } else if ($this->config->get('mlseo_product_related_relevance')) { 
        $relevance = $this->config->get('mlseo_product_related_relevance'); 
      } else { 
        $relevance = 2; 
      } 
       
      if (!empty($this->request->post['mlseo_product_related_no'])) { 
        $max_items = $this->request->post['mlseo_product_related_no']; 
      } else if ($this->config->get('mlseo_product_related_no')) { 
        $max_items = $this->config->get('mlseo_product_related_no'); 
      } else { 
        $max_items = 5; 
      } 
       
      if (empty($row['category_id'])) { 
        $row['category_id'] = 0; 
      } 
       
      if (true) { // related generator method 
        $results = $this->db->query("SELECT DISTINCT p.product_id, pd.name, 
          ROUND(MATCH (pd.name, pd.description) AGAINST ('" . $prod_name . " " . $prod_tag . " " . $prod_desc . "'), 0) / 5 as relevance 
          FROM " . DB_PREFIX . "product_description pd 
          LEFT JOIN " . DB_PREFIX . "product p on pd.product_id = p.product_id 
          INNER JOIN " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id 
          WHERE 
            p.product_id <> " . $row['product_id'] . $prod_cat . " 
            AND p.status = 1 
            AND p.quantity > 0 
          GROUP BY p.product_id 
            HAVING relevance >= " . (int) $relevance . " 
          ORDER BY relevance DESC 
          LIMIT 0, " . (int) $max_items)->rows; 
      } else { // method 2 
        $results = $this->db->query("SELECT DISTINCT p.product_id, pd.name,  
          MAX(2 / (CASE p.price >= ". $this->db->escape($row['price']) ." WHEN 0 THEN (". $this->db->escape($row['price']) ." / p.price) ELSE (p.price / ". $this->db->escape($row['price']) .") END) *  
          (CASE category_id WHEN ". (int) $row['category_id'] ." THEN 2 ELSE 1 end) + (1 + rel.rlv)) 
          AS relevance FROM " . DB_PREFIX . "product p  
          INNER JOIN " . DB_PREFIX . "product_description pd ON p.product_id = pd.product_id 
          INNER JOIN " . DB_PREFIX . "product_to_category p2c ON p.product_id = p2c.product_id 
          INNER JOIN (SELECT product_id, MATCH(name, description) AGAINST ('". strip_tags(trim($this->db->escape(htmlspecialchars_decode(str_replace(array('%', '_', '"', "'"), array('', ' ', ' ', ' '), $row['name']))))) . ' ' . strip_tags(trim($this->db->escape(htmlspecialchars_decode(str_replace(array('%', '_', '"', "'"), array('', ' ', ' ', ' '), $row['description']))))) ."') AS rlv FROM " . DB_PREFIX . "product_description) AS rel ON rel.product_id = p.product_id   
          GROUP BY p.product_id 
          HAVING p.product_id <> ". (int) $row['product_id'] ." AND relevance >= ".(int) $relevance." AND p.product_id NOT IN (SELECT related_id FROM " . DB_PREFIX . "product_related WHERE product_id = ". (int) $row['product_id'] .") 
          ORDER BY relevance DESC 
          LIMIT 0, ". (int) $max_items)->rows; 
      } 
       
      $new_related = array(); 
      foreach ($results as $res) { 
        if (!$simulate) { 
          $this->db->query("INSERT INTO " . DB_PREFIX . "product_related (product_id, related_id) VALUES (" . $row['product_id'] . ", " . $res['product_id'] . ")"); 
        } 
        $new_item = $this->db->query("SELECT name FROM " . DB_PREFIX . "product_description WHERE product_id=" . $res['product_id'] . " AND language_id=" . $this->config->get('config_language_id'))->row; 
        $new_related[] = '- ' . $new_item['name']; 
      } 
      sort($old_related); 
      sort($new_related); 
       
      $changed = false; 
       
      if (!empty($new_related) && $old_related != $new_related) { 
        $changed = true; 
        $this->session->data['seopackage_updated']++; 
      } 
       
      $values[] = array( 
        'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'), 
        'name' =>  $row['name'], 
        'old_value' =>  implode('<br/> ', $old_related), 
        'value' =>  implode("<br/> ", $new_related), 
        'changed' =>  $changed, 
      ); 
       
      if (defined('SEO_PACKAGE_CLI')) { 
        if ($changed) { 
          $this->log('product.related: ' . $row['name'] . ' => ' . "\n\t\t" . implode("\n\t\t", $new_related)); 
        } 
      } 
    } 
     
    $data['langs'][0]['rows'] = &$values; 
    return $data; 
  } 
   
  public function generator_product($mode, $simulate, $empty_only, $redirect) { 
    if ($mode == 'related') return $this->generator_related_product($mode, $simulate, $empty_only, $redirect); 
     
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); die('No language selected');} 
     
    // get languages  
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
    unset($languages); 
     
    $image_simulate = array(); 
    if ($mode == 'image_name' && count($this->request->post['langs']) > 1) { 
      die($this->language->get('text_image_name_lang')); 
      die('<div class="alert alert-warning"><i class="fa fa-warning"> ' . $this->language->get('text_image_name_lang') . '</i></div>'); 
    } 
     
    switch ($mode) { 
      case 'url': $field = 'seo_keyword'; break; 
      case 'h1': $field = 'seo_h1'; break; 
      case 'h2': $field = 'seo_h2'; break; 
      case 'h3': $field = 'seo_h3'; break; 
      case 'title': $field = 'meta_title'; break; 
      case 'keyword': $field = 'meta_keyword'; break; 
      case 'description': $field = 'meta_description'; break; 
      case 'full_desc': $field = 'description'; break; 
      case 'image_name': $field = 'image'; break; 
      case 'image_title': $field = 'image_title'; break; 
      case 'image_alt': $field = 'image_alt'; break; 
      case 'tag': $field = 'tag'; break; 
    } 
       
    $values = $data = array(); 
     
    if ($mode == 'store_copy') { 
      foreach($this->request->post['langs'] as $lang) { 
        if (!$simulate) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_product_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'"); 
           
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_product_description SELECT product_id, '".(int) $lang."', '".(int) $this->store."', name, description, meta_title, meta_description, meta_keyword, image_title, image_alt, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "product_description d WHERE d.language_id = '".(int) $lang."'"); 
        } 
         
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang]; 
        $data['langs'][$lang]['rows'][] = array( 
          'link' =>  '', 
          'name' =>  'Product data copy to sub-store', 
          'old_value' =>  '', 
          'value' =>  'Done', 
          'changed' =>  '', 
        ); 
      } 
       
      return $data; 
    } 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $this->config->set('mlseo_current_lang', $lang_code[$lang]); 
      $values[$lang]['lang_img'] = $lang_img[$lang]; 
      $values[$lang]['rows'] = array(); 
      $change_count = 0; 
       
      if (isset($this->request->post['mlseo_product_'.$mode.'_pattern'])) { 
        $pattern = $this->request->post['mlseo_product_'.$mode.'_pattern']; 
      } else { 
        $pattern = $this->config->get('mlseo_product_'.$mode.'_pattern'); 
      } 
       
      //if ($this->store) { 
      if ($this->multistore_mode) { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) WHERE s.store_id = ".(int) $this->store)->row; 
      } else { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product p")->row; 
      } 
       
      $this->total_items = $total['total']; 
       
      $special = ''; 
      if ($this->config->get('mlseo_special_group')) { 
        $special = ", (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.customer_group_id = ".(int)$this->config->get('mlseo_special_group')." ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special"; 
      } 
       
      $extra_select = ''; 
       
      if ($mode == 'url') { 
       if (version_compare(VERSION, '4', '>=')) { 
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'product_id' AND `value` = p.product_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
       } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
         //$extra_select .= ",IFNULL((SELECT meta_title FROM " . DB_PREFIX . "seo_product_description sd WHERE (sd.product_id = p.product_id) AND (sd.language_id = d.language_id)  AND (sd.store_id = ".(int) $this->store.") LIMIT 1), null) AS seo_table_exists"; 
       } else if ($this->multistore_mode) { 
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
       } else if ($this->ml_mode) { 
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword"; 
       } else { 
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('product_id=', p.product_id) LIMIT 1), '') AS seo_keyword"; 
       } 
      } 
 
      if ($this->store) { 
        $desc_table = 'seo_product_description'; 
        $extra_desc = "AND store_id = '" . (int)$this->store . "'"; 
        if (!empty($this->request->post['filter_category'])) { 
          $rows = $this->db->query("SELECT sd.*, p.*, d.name as orig_name, d.description as orig_description ".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) LEFT JOIN " . DB_PREFIX . "seo_product_description sd ON (p.product_id = sd.product_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "product_description d ON (p.product_id = d.product_id AND d.language_id = ".(int) $lang.") WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND s.store_id = ".(int) $this->store." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } else { 
          $rows = $this->db->query("SELECT sd.*, p.*, d.name as orig_name, d.description as orig_description ".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "seo_product_description sd ON (p.product_id = sd.product_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "product_description d ON (p.product_id = d.product_id AND d.language_id = ".(int) $lang.") WHERE s.store_id = ".(int) $this->store." ORDER BY sd.product_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } 
      } else { 
        $desc_table = 'product_description'; 
        $extra_desc = ''; 
        if (!empty($this->request->post['filter_category'])) { 
          if ($this->multistore_mode) { 
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
          } else { 
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
          } 
        } else { 
          if ($this->multistore_mode) { 
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
          } else { 
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id WHERE d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
          } 
        } 
      } 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        $_SESSION['seopackage_lastItem'] = $row['product_id']; 
         
        if (empty($row['name']) && isset($row['orig_name'])) { 
          $row['name'] = $row['orig_name']; 
        } 
         
        if (empty($row['description']) && isset($row['orig_description'])) { 
          $row['description'] = $row['orig_description']; 
        } 
         
        /* 
        $langDescriptions = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = ".(int) $row['product_id'])->rows; 
         
        foreach ($langDescriptions as $langDesc) { 
          $row['name_'.$langDesc['language_id']] = $langDesc['name']; 
        } 
        */ 
         
        if (!array_key_exists($field, $row)) continue; 
         
        $value = str_replace('[current]', $row[$field], $pattern); 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($value, $lang, $row, $this->store); 
         
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) { 
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_product_description SET product_id = '" . (int)$row['product_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'"); 
        } 
         
        // urls 
        if ($mode == 'url') 
        { 
          if ($empty_only && $row['seo_keyword']) continue; 
           
          if (!$simulate) { 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'product_id' AND `value` = '" . $row['product_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND store_id = " . (int)$this->store); 
            } else if ($this->ml_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND language_id IN (".(int) $lang.", 0)"); 
            } else { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "'"); 
            } 
          } 
           
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'product', $row['product_id'], $lang, $simulate); 
           
          if (!$simulate) { 
            if ($this->config->get('mlseo_backup')) { 
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) { 
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/product&product_id=" . (int) $row['product_id'] . "', language_id = '" . (int) $lang . "'"); 
              } 
            } 
             
            //$this->db->query("UPDATE " . DB_PREFIX . "product_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . $row['language_id'] . "' "); 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET  `key` = 'product_id', `value` = '" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->ml_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'"); 
            } else { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', keyword = '" . $this->db->escape($value) . "'"); 
            } 
          } 
          //$field = 'seo_keyword'; 
        } 
        // Meta title 
        elseif ($mode == 'h1') 
        { 
          if ($empty_only && $row['seo_h1']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h2') 
        { 
          if ($empty_only && $row['seo_h2']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h2'; 
        } 
        elseif ($mode == 'h3') 
        { 
          if ($empty_only && $row['seo_h3']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h3'; 
        } 
        // Meta title 
        elseif ($mode == 'title') 
        { 
          if ($empty_only && $row['meta_title']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_title'; 
        } 
        // Meta keywords 
        elseif ($mode == 'keyword') 
        { 
          if ($empty_only && $row['meta_keyword']) continue; 
           
          if (function_exists('mb_strtolower')) { 
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } else { 
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_keyword'; 
        } 
        // Meta description 
        elseif ($mode == 'description') 
        { 
          if ($empty_only && $row['meta_description']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_description'; 
        } 
        // Description 
        elseif ($mode == 'full_desc') 
        { 
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'description'; 
        } 
        // image name 
        if ($mode == 'image_name') 
        { 
          if (!$row['image']) continue; 
           
          $img_count = $this->db->query("SELECT COUNT(image) as count FROM " . DB_PREFIX . "product WHERE image='" . $this->db->escape($row['image']) . "'")->row; 
          if ($img_count['count'] > 1) continue; 
           
          $path = pathinfo($row['image']); 
           
          // skip if no extension 
          if (empty($path['extension'])) { 
            continue; 
          } 
           
          $patternArray = explode(';', $pattern); 
           
          $value = str_replace('[current]', $row[$field], $patternArray[0]); 
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($value, $lang, $row, $this->store); 
         
          $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'image', '', $lang, false, true); 
          $value = $path['dirname'] . '/' . $filename . '.' . $path['extension']; 
           
          if ($row['image'] != $value) { 
            $x = 1; 
             
            if ($simulate) { 
              while (file_exists(DIR_IMAGE . $value) || in_array(DIR_IMAGE . $value, $image_simulate)) { 
                $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension']; 
                $x++; 
              } 
              $image_simulate[] = DIR_IMAGE . $value; 
            } else { 
              while (file_exists(DIR_IMAGE . $value)) { 
                $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension']; 
                $x++; 
              } 
              if (@rename(DIR_IMAGE . $row['image'], DIR_IMAGE . $value)) { 
                //$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE product_id = '" . $row['product_id'] . "'"); 
 
                // replace all images with such value 
                $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($row['image']) . "'"); 
                $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($row['image']) . "'"); 
              } else { 
                continue; 
              } 
            } 
          } 
           
          $additionalImages = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id='" . $this->db->escape($row['product_id']) . "'")->rows; 
           
          foreach ($additionalImages as $imgIndex => $addImageRow) { 
            $path = pathinfo($addImageRow['image']); 
             
            $row['image'] .= '<br> '.$addImageRow['image']; 
             
            // skip if no extension 
            if (empty($path['extension'])) { 
              continue; 
            } 
             
            $currentPattern = isset($patternArray[$imgIndex+1]) ? $patternArray[$imgIndex+1] : $patternArray[0]; 
             
            $subValue = str_replace('[current]', $addImageRow['image'], $currentPattern); 
            $subValue = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($subValue, $lang, $row, $this->store); 
         
            $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($subValue, 'image', '', $lang, false, true); 
            $subValue = $path['dirname'] . '/' . $filename . '.' . $path['extension']; 
             
            if ($addImageRow['image'] != $subValue) { 
              $x = 1; 
               
              if ($simulate) { 
                while (file_exists(DIR_IMAGE . $subValue) || in_array(DIR_IMAGE . $subValue, $image_simulate)) { 
                  $subValue = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension']; 
                  $x++; 
                } 
                $image_simulate[] = DIR_IMAGE . $subValue; 
              } else { 
                while (file_exists(DIR_IMAGE . $subValue)) { 
                  $subValue = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension']; 
                  $x++; 
                } 
                if (@rename(DIR_IMAGE . $addImageRow['image'], DIR_IMAGE . $subValue)) { 
                  // replace all images with such value 
                  $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($subValue) ."' WHERE image = '" . $this->db->escape($addImageRow['image']) . "'"); 
                  $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($subValue) ."' WHERE image = '" . $this->db->escape($addImageRow['image']) . "'"); 
                } else { 
                  continue; 
                } 
              } 
            } 
             
            $value .= '<br> '.$subValue; 
          } 
           
          $row['image'] = ' '.$row['image']; 
          $value = ' '.$value; 
          // $field = 'image'; 
        } 
         // Image title 
        elseif ($mode == 'image_title') 
        { 
          if ($empty_only && $row['image_title']) continue; 
           
          $value = str_replace(array('"', "'"), '', $value); 
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET image_title = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'image_title'; 
        } 
         // Image alt 
        elseif ($mode == 'image_alt') 
        { 
          if ($empty_only && $row['image_alt']) continue; 
           
          $value = str_replace(array('"', "'"), '', $value); 
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET image_alt = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'image_alt'; 
        } 
        // Tags 
        elseif ($mode == 'tag') 
        { 
          if ($empty_only && $row['tag']) continue; 
           
          if ($lang) { 
            $remove = $this->config->get('mlseo_remove_'.$lang); 
          } else { 
            $remove = $this->config->get('mlseo_remove_'.$this->config->get('config_language_id')); 
          } 
           
          $value = str_replace('"', '', $value); 
           
          if (!empty($remove)) { 
            $beforeWord = "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|^)"; 
            $afterWord =  "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|$)"; 
            $removeArray = array(); 
             
            foreach (explode(',', $remove) as $rem) { 
              $removeArray[] = '`'.$beforeWord.preg_quote(trim($rem), '`').$afterWord.'`'; 
            } 
             
            if ($removeArray) { 
              $value = preg_replace($removeArray, '$1$2', $value); 
            } 
          } 
           
          if ($this->config->get('mlseo_format_tag')) { 
            $value = str_replace('.', ',', $value); 
            $value = str_replace(array('  ',' '), ', ', $value); 
             
            if (function_exists('mb_strtolower')) { 
              $value = trim(mb_strtolower($value), ', '); 
            } else { 
              $value = trim(strtolower($value), ', '); 
            } 
          } 
           
          $value = trim(preg_replace('/(?:,\s*)+/', ',', $value), ', '); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . "product_description SET tag = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'tag'; 
        } 
         
        if (!$simulate) { 
          $this->db->query("UPDATE " . DB_PREFIX . "product SET date_modified = NOW() WHERE product_id = '".(int)$row['product_id']."'"); 
        } 
         
        if (array_key_exists($field, $row)) { 
          $changed = !($value === $row[$field]); 
        } else { 
          $changed = false; 
        } 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) { 
            $values[$lang]['rows'][] = array( 
              'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'), 
              'name' =>  $row['name'], 
              'old_value' =>  (string) $row[$field], 
              'value' =>  '[backup url to redirect to new one]', 
              'changed' =>  false, 
            ); 
          } 
           
          $values[$lang]['rows'][] = array( 
            'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'), 
            'name' =>  $row['name'], 
            'old_value' =>  (string) $row[$field], 
            'value' =>  $value, 
            'changed' =>  $changed, 
          ); 
        } 
         
        if ($changed) { 
          if (defined('SEO_PACKAGE_CLI')) { 
            $this->log('product.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value); 
          } 
           
          $change_count++; 
          $this->session->data['seopackage_updated']++; 
          //Powercache::remove('seo_rewrite', 'product_id=' . $row['product_id']); 
        } 
      } // end foreach $rows 
      $values[$lang]['count'] = $change_count; 
    } 
    $data['langs'] = &$values; 
    return $data; 
  } 
   
  public function getChildCategories($cat_id) { 
    $parentsArray = array($cat_id); 
     
    if ($cat_id) { 
      $catQuery = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = '".(int) $cat_id."'")->rows; 
       
      if (!empty($catQuery)) { 
        foreach ($catQuery as $cat) { 
          $parentsArray[] = $cat['category_id']; 
          $parentsArray = array_unique(array_merge($parentsArray, $this->getChildCategories($cat['category_id']))); 
        } 
      } 
    } 
     
    return $parentsArray; 
  } 
   
  public function generator_category($mode, $simulate, $empty_only, $redirect) { 
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;} 
     
    if (version_compare(VERSION, '4', '>=')) { 
      $this->load->model('extension/complete_seo/catalog/seo_package'); 
      $modelSeoPackage = $this->model_extension_complete_seo_catalog_seo_package; 
    } else { 
      $this->load->model('catalog/seo_package'); 
      $modelSeoPackage = $this->model_catalog_seo_package; 
    } 
     
    // get languages  
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
    unset($languages); 
     
    switch ($mode) { 
      case 'url': $field = 'seo_keyword'; break; 
      case 'h1': $field = 'seo_h1'; break; 
      case 'h2': $field = 'seo_h2'; break; 
      case 'h3': $field = 'seo_h3'; break; 
      case 'title': $field = 'meta_title'; break; 
      case 'keyword': $field = 'meta_keyword'; break; 
      case 'description': $field = 'meta_description'; break; 
      case 'full_desc': $field = 'description'; break; 
    } 
     
    $values = $data = array(); 
     
    if ($mode == 'store_copy') { 
      foreach($this->request->post['langs'] as $lang) { 
        if (!$simulate) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_category_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'"); 
           
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_category_description SELECT category_id, '".(int) $lang."', '".(int) $this->store."', name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "category_description d WHERE d.language_id = '".(int) $lang."'"); 
        } 
         
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang]; 
        $data['langs'][$lang]['rows'][] = array( 
          'link' =>  '', 
          'name' =>  'Category data copy to sub-store', 
          'old_value' =>  '', 
          'value' =>  'Done', 
          'changed' =>  '', 
        ); 
      } 
       
      return $data; 
    } 
     
    $filterCats = ''; 
     
    if (!empty($this->request->post['filter_cat_category'])) { 
      $parentsArray = array(); 
      $cat_id = $this->request->post['filter_cat_category']; 
       
      if (empty($this->request->post['filter_cat_category_current'])) { 
        $parentsArray = $this->getChildCategories($cat_id); 
       
        if (!empty($parentsArray)) { 
          $filterCats = " AND c.category_id IN (".implode(',', $parentsArray).")"; 
        } 
      } else { 
        $filterCats = " AND c.category_id = '".(int) $cat_id."'"; 
      } 
    } 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $this->config->set('mlseo_current_lang', $lang_code[$lang]); 
      $values[$lang]['lang_img'] = $lang_img[$lang]; 
      $values[$lang]['rows'] = array(); 
      $change_count = 0; 
       
      if (isset($this->request->post['mlseo_category_'.$mode.'_pattern'])) { 
        $pattern = $this->request->post['mlseo_category_'.$mode.'_pattern']; 
      } else { 
        $pattern = $this->config->get('mlseo_category_'.$mode.'_pattern'); 
      } 
       
      if ($this->multistore_mode) { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) WHERE s.store_id = ".(int) $this->store . $filterCats)->row; 
      } else { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "category c WHERE 1" . $filterCats)->row; 
      } 
       
      $this->total_items = $total['total']; 
       
      $extra_select = ''; 
       
      if ($mode == 'url') { 
        if (version_compare(VERSION, '4', '>=')) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'path' AND `value` = d.category_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.language_id = d.language_id OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->multistore_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->ml_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword"; 
        } else { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('category_id=', d.category_id) LIMIT 1), '') AS seo_keyword"; 
        } 
      } 
 
      if ($this->store) { 
        $desc_table = 'seo_category_description'; 
        $extra_desc = "AND store_id = '" . (int)$this->store . "'"; 
        $rows = $this->db->query("SELECT sd.*, c.*, d.name as orig_name, d.description as orig_description ".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) LEFT JOIN " . DB_PREFIX . "seo_category_description sd ON (c.category_id = sd.category_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "category_description d ON (c.category_id = d.category_id AND d.language_id=".(int) $lang.") WHERE s.store_id = ".(int) $this->store. $filterCats ." ORDER BY sd.category_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
      } else { 
        $desc_table = 'category_description'; 
        $extra_desc = ''; 
        if ($this->multistore_mode) { 
          $rows = $this->db->query("SELECT d.*, c.*".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description d ON c.category_id = d.category_id LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang . $filterCats . " ORDER BY d.category_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } else { 
          $rows = $this->db->query("SELECT d.*, c.*".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description d ON c.category_id = d.category_id WHERE d.language_id=".(int) $lang . $filterCats . " ORDER BY d.category_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } 
      } 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        if (empty($row['name']) && isset($row['orig_name'])) { 
          $row['name'] = $row['orig_name']; 
        } 
         
        if (empty($row['description']) && isset($row['orig_description'])) { 
          $row['description'] = $row['orig_description']; 
        } 
         
        $value = str_replace('[current]', $row[$field], $pattern); 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformCategory($value, $lang, $row, $this->store); 
         
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) { 
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_category_description SET category_id = '" . (int)$row['category_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'"); 
        } 
         
        // urls 
        if ($mode == 'url') 
        { 
          if (version_compare(VERSION, '4', '>=')) { 
            $row['seo_keyword'] = $modelSeoPackage->getCategorySeoV4($row['category_id'], $lang, $this->store); 
          } 
           
          if ($empty_only && $row['seo_keyword']) continue; 
           
          if (!$simulate) { 
            if (version_compare(VERSION, '4', '>=')) { 
              //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'path' AND `value` = '" . $row['category_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND store_id = " . (int)$this->store); 
            } else if ($this->ml_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND language_id IN (".(int) $lang.", 0)"); 
            } else { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "'"); 
            } 
          } 
           
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'category', $row['category_id'], $lang, $simulate); 
           
          if (!$simulate) { 
            if ($this->config->get('mlseo_backup')) { 
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) { 
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/category&category_id=" . (int) $row['category_id'] . "', language_id = '" . (int) $lang . "'"); 
              } 
            } 
             
            //$this->db->query("UPDATE " . DB_PREFIX . "category_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . $row['language_id'] . "' "); 
            if (version_compare(VERSION, '4', '>=')) { 
              //$this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'path', `value` = '" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
              if ($row['seo_keyword'] != $value) { 
                $modelSeoPackage->setCategorySeoV4($row['category_id'], $value, $lang, $this->store); 
              } 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->ml_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "'"); 
            } else { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', keyword = '" . $this->db->escape($value) . "'"); 
            } 
          } 
          // $field = 'seo_keyword'; 
        } 
        // Meta title 
        elseif ($mode == 'h1') 
        { 
          if ($empty_only && $row['seo_h1']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h2') 
        { 
          if ($empty_only && $row['seo_h2']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h3') 
        { 
          if ($empty_only && $row['seo_h3']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        // Meta title 
        elseif ($mode == 'title') 
        { 
          if ($empty_only && $row['meta_title']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_title'; 
        } 
        // Meta keywords 
        elseif ($mode == 'keyword') 
        { 
          if ($empty_only && $row['meta_keyword']) continue; 
           
          if (function_exists('mb_strtolower')) { 
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } else { 
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_keyword'; 
        } 
        // Meta description 
        elseif ($mode == 'description') 
        { 
          if ($empty_only && $row['meta_description']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_description'; 
        } 
        // Description 
        elseif ($mode == 'full_desc') 
        { 
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'description'; 
        } 
         
        if (!$simulate) { 
          $this->db->query("UPDATE " . DB_PREFIX . "category SET date_modified = NOW() WHERE category_id = '".(int)$row['category_id']."'"); 
        } 
         
        if (array_key_exists($field, $row)) { 
          $changed = !($value === $row[$field]); 
        } else { 
          $changed = false; 
        } 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) { 
            $values[$lang]['rows'][] = array( 
              'link' =>  $this->url->link('catalog/category/'.$this->edit_action, $this->token . '&category_id=' . $row['category_id'], 'SSL'), 
              'name' =>  $row['name'], 
              'old_value' =>  (string) $row[$field], 
              'value' =>  '[backup url to redirect to new one]', 
              'changed' =>  false, 
            ); 
          } 
           
          $values[$lang]['rows'][] = array( 
            'link' =>  $this->url->link('catalog/category/'.$this->edit_action, $this->token . '&category_id=' . $row['category_id'], 'SSL'), 
            'name' =>  $row['name'], 
            'old_value' =>  (string) $row[$field], 
            'value' =>  $value, 
            'changed' =>  $changed, 
          ); 
        } 
         
        if ($changed) { 
          if (defined('SEO_PACKAGE_CLI')) { 
            $this->log('category.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value); 
          } 
           
          $this->session->data['seopackage_updated']++; 
          $change_count++; 
          //Powercache::remove('seo_rewrite', 'path=', $row['category_id']); 
        } 
      } // end foreach $rows 
      $values[$lang]['count'] = $change_count; 
    } 
    $data['langs'] = &$values; 
    return $data; 
  } 
   
  public function generator_information($mode, $simulate, $empty_only, $redirect) { 
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;} 
     
    // get languages  
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
    unset($languages); 
     
    switch ($mode) { 
      case 'url': $field = 'seo_keyword'; break; 
      case 'h1': $field = 'seo_h1'; break; 
      case 'h2': $field = 'seo_h2'; break; 
      case 'h3': $field = 'seo_h3'; break; 
      case 'title': $field = 'meta_title'; break; 
      case 'keyword': $field = 'meta_keyword'; break; 
      case 'description': $field = 'meta_description'; break; 
      case 'full_desc': $field = 'description'; break; 
    } 
     
    $values = $data = array(); 
     
    if ($mode == 'store_copy') { 
      foreach($this->request->post['langs'] as $lang) { 
        if (!$simulate) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_information_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'"); 
           
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_information_description SELECT information_id, '".(int) $lang."', '".(int) $this->store."', title, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "information_description d WHERE d.language_id = '".(int) $lang."'"); 
        } 
         
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang]; 
        $data['langs'][$lang]['rows'][] = array( 
          'link' =>  '', 
          'name' =>  'Information data copy to sub-store', 
          'old_value' =>  '', 
          'value' =>  'Done', 
          'changed' =>  '', 
        ); 
      } 
       
      return $data; 
    } 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $this->config->set('mlseo_current_lang', $lang_code[$lang]); 
      $values[$lang]['lang_img'] = $lang_img[$lang]; 
      $values[$lang]['rows'] = array(); 
      $change_count = 0; 
       
      if (isset($this->request->post['mlseo_information_'.$mode.'_pattern'])) { 
        $pattern = $this->request->post['mlseo_information_'.$mode.'_pattern']; 
      } else { 
        $pattern = $this->config->get('mlseo_information_'.$mode.'_pattern'); 
      } 
       
      if ($this->multistore_mode) { 
        $total = $this->db->query("SELECT COUNT(*) as total  FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store)->row; 
      } else { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "information")->row; 
      } 
       
      $this->total_items = $total['total']; 
       
      $extra_select = ''; 
       
      if ($mode == 'url') { 
        if (version_compare(VERSION, '4', '>=')) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'information_id' AND `value` = d.information_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.language_id = d.language_id OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->multistore_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->ml_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword"; 
        } else { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('information_id=', d.information_id) LIMIT 1), '') AS seo_keyword"; 
        } 
      } 
       
      if ($this->store) { 
        $desc_table = 'seo_information_description'; 
        $extra_desc = "AND store_id = '" . (int)$this->store . "'"; 
        $rows = $this->db->query("SELECT sd.*, i.*, sd.name as title, d.title as orig_title, d.description as orig_description ".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) LEFT JOIN " . DB_PREFIX . "seo_information_description sd ON (i.information_id = sd.information_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "information_description d ON (i.information_id = d.information_id AND d.language_id=".(int) $lang.") WHERE s.store_id = ".(int) $this->store." ORDER BY i.information_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        //$rows = $this->db->query("SELECT d.*, i.*, cd.title, cd.description ".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "seo_information_description d ON i.information_id = d.information_id /*LEFT JOIN " . DB_PREFIX . "information_description id ON i.information_id = cd.information_id*/ LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." AND cd.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
      } else { 
        $desc_table = 'information_description'; 
        $extra_desc = ''; 
        if ($this->multistore_mode) { 
          $rows = $this->db->query("SELECT d.*, i.*".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description d ON i.information_id = d.information_id LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } else { 
          $rows = $this->db->query("SELECT d.*, i.*".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description d ON i.information_id = d.information_id WHERE d.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
        } 
      } 
       
      //$rows = $this->db->query("SELECT *".$extra_select." FROM " . DB_PREFIX . "information_description d WHERE d.language_id=".(int) $lang." ORDER BY d.information_id LIMIT ".$this->start.",".$this->limit)->rows; 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        if (empty($row['title']) && isset($row['orig_title'])) { 
          $row['title'] = $row['orig_title']; 
        } 
         
        if (empty($row['description']) && isset($row['orig_description'])) { 
          $row['description'] = $row['orig_description']; 
        } 
         
        $value = str_replace('[current]', $row[$field], $pattern); 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformInformation($value, $lang, $row, $this->store); 
         
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) { 
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_information_description SET information_id = '" . (int)$row['information_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'"); 
        } 
         
        // urls 
        if ($mode == 'url') 
        { 
          if ($empty_only && $row['seo_keyword']) continue; 
           
          if (!$simulate) { 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'information_id' AND `value` = '" . $row['information_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND store_id = " . (int)$this->store); 
            } else if ($this->ml_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND language_id IN (".(int) $lang.", 0)"); 
            } else { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "'"); 
            } 
          } 
           
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'information', $row['information_id'], $lang, $simulate); 
           
          if (!$simulate) { 
            if ($this->config->get('mlseo_backup')) { 
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) { 
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'information/information&information_id=" . (int) $row['information_id'] . "', language_id = '" . (int) $lang . "'"); 
              } 
            } 
             
            //$this->db->query("UPDATE " . DB_PREFIX . "information_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . $row['language_id'] . "' "); 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'information_id', `value` = '" . $row['information_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->ml_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'"); 
            } else { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', keyword = '" . $this->db->escape($value) . "'"); 
            } 
          } 
          // $field = 'seo_keyword'; 
        } 
        // h1 
        elseif ($mode == 'h1') 
        { 
          if ($empty_only && $row['seo_h1']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h2') 
        { 
          if ($empty_only && $row['seo_h2']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h3') 
        { 
          if ($empty_only && $row['seo_h3']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        // Meta title 
        elseif ($mode == 'title') 
        { 
          if ($empty_only && $row['meta_title']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_title'; 
        } 
        // Meta keywords 
        elseif ($mode == 'keyword') 
        { 
          if ($empty_only && $row['meta_keyword']) continue; 
           
          if (function_exists('mb_strtolower')) { 
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } else { 
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_keyword'; 
        } 
        // Meta description 
        elseif ($mode == 'description') 
        { 
          if ($empty_only && $row['meta_description']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_description'; 
        } 
        // Description 
        elseif ($mode == 'full_desc') 
        { 
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'description'; 
        } 
         
        if (array_key_exists($field, $row)) { 
          $changed = !($value === $row[$field]); 
        } else { 
          $changed = false; 
        } 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) { 
            $values[$lang]['rows'][] = array( 
              'link' =>  $this->url->link('catalog/information/'.$this->edit_action, $this->token . '&information_id=' . $row['information_id'], 'SSL'), 
              'name' =>  $row['title'], 
              'old_value' =>  (string) $row[$field], 
              'value' =>  '[backup url to redirect to new one]', 
              'changed' =>  false, 
            ); 
          } 
           
          $values[$lang]['rows'][] = array( 
            'link' =>  $this->url->link('catalog/information/'.$this->edit_action, $this->token . '&information_id=' . $row['information_id'], 'SSL'), 
            'name' =>  $row['title'], 
            'old_value' =>  (string) $row[$field], 
            'value' =>  $value, 
            'changed' =>  $changed, 
          ); 
        } 
         
        if ($changed) { 
          if (defined('SEO_PACKAGE_CLI')) { 
            $this->log('information.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['title'] . ' => ' . $value); 
          } 
           
          $this->session->data['seopackage_updated']++; 
          $change_count++; 
          //Powercache::remove('seo_rewrite', 'information_id=' . $row['information_id']); 
        } 
      } // end foreach $rows 
      $values[$lang]['count'] = $change_count; 
    } 
    $data['langs'] = &$values; 
     
    return $data; 
  } 
   
  public function generator_manufacturer($mode, $simulate, $empty_only, $redirect) { 
    if (version_compare(VERSION, '3', '<')) { 
      //return $this->generator_manufacturer_old($mode, $simulate, $empty_only, $redirect); 
    } 
     
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;} 
     
    // get languages  
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
    unset($languages); 
     
    switch ($mode) { 
      case 'url': $field = 'seo_keyword'; break; 
      case 'h1': $field = 'seo_h1'; break; 
      case 'h2': $field = 'seo_h2'; break; 
      case 'h3': $field = 'seo_h3'; break; 
      case 'title': $field = 'meta_title'; break; 
      case 'keyword': $field = 'meta_keyword'; break; 
      case 'description': $field = 'meta_description'; break; 
      case 'full_desc': $field = 'description'; break; 
    } 
     
    $values = $data = array(); 
     
    if ($mode == 'store_copy') { 
      foreach($this->request->post['langs'] as $lang) { 
        if (!$simulate) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_manufacturer_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'"); 
           
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description SELECT manufacturer_id, '".(int) $lang."', '".(int) $this->store."', title, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "seo_manufacturer_description d WHERE d.language_id = '".(int) $lang."' AND d.store_id = '0'"); 
        } 
         
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang]; 
        $data['langs'][$lang]['rows'][] = array( 
          'link' =>  '', 
          'name' =>  'manufacturer data copy to sub-store', 
          'old_value' =>  '', 
          'value' =>  'Done', 
          'changed' =>  '', 
        ); 
      } 
       
      return $data; 
    } 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $this->config->set('mlseo_current_lang', $lang_code[$lang]); 
      $values[$lang]['lang_img'] = $lang_img[$lang]; 
      $values[$lang]['rows'] = array(); 
      $change_count = 0; 
       
      if (isset($this->request->post['mlseo_manufacturer_'.$mode.'_pattern'])) { 
        $pattern = $this->request->post['mlseo_manufacturer_'.$mode.'_pattern']; 
      } else { 
        $pattern = $this->config->get('mlseo_manufacturer_'.$mode.'_pattern'); 
      } 
     
      if ($this->multistore_mode) { 
        $total = $this->db->query("SELECT COUNT(*) as total  FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) WHERE s.store_id = ".(int) $this->store)->row; 
      } else { 
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "manufacturer")->row; 
      } 
       
      $this->total_items = $total['total']; 
       
      $extra_select = ''; 
       
      if ($mode == 'url') { 
        if (version_compare(VERSION, '4', '>=')) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'manufacturer_id' AND `value` = m.manufacturer_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.language_id = ".(int) $lang." OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->multistore_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword"; 
        } else if ($this->ml_mode) { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.language_id = ".(int) $lang." OR u.language_id = 0) LIMIT 1), '') AS seo_keyword"; 
        } else { 
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) LIMIT 1), '') AS seo_keyword"; 
        } 
      } 
       
      $desc_table = 'seo_manufacturer_description'; 
      $extra_desc = "AND store_id = '" . (int)$this->store . "'"; 
 
      $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) WHERE s.store_id = ".(int) $this->store." ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
 
      /* manufacturers always need the store id 
      if ($this->multistore_mode) { 
        $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) WHERE s.store_id = ".(int) $this->store." ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
      } else { 
        $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows; 
      }*/ 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        if (empty($row['name']) && isset($row['orig_name'])) { 
          $row['name'] = $row['orig_name']; 
        } 
         
        $value = str_replace('[current]', $row[$field], $pattern); 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformManufacturer($value, $lang, $row, $this->store); 
         
        //if (!$simulate && !array_key_exists('meta_title', $row)) { 
        if (!$simulate && is_null($row['store_id'])) { 
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description SET manufacturer_id = '" . (int)$row['manufacturer_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'"); 
        } 
         
        // urls 
        if ($mode == 'url') 
        { 
          if ($empty_only && $row['seo_keyword']) continue; 
           
          if (!$simulate) { 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = '" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store); 
            } else if ($this->ml_mode) { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND language_id IN (".(int) $lang.", 0)"); 
            } else { 
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "'"); 
            } 
          } 
           
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'manufacturer', $row['manufacturer_id'], $lang, $simulate); 
           
          if (!$simulate) { 
            if ($this->config->get('mlseo_backup')) { 
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) { 
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/manufacturer&manufacturer_id=" . (int) $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "'"); 
              } 
            } 
             
            if (version_compare(VERSION, '4', '>=')) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'manufacturer_id', `value` = '" . $row['manufacturer_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->multistore_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'"); 
            } else if ($this->ml_mode) { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'"); 
            } else { 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "'"); 
            } 
          } 
          // $field = 'seo_keyword'; 
        } 
        // h1 
        elseif ($mode == 'h1') 
        { 
          if ($empty_only && $row['seo_h1']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h2') 
        { 
          if ($empty_only && $row['seo_h2']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        elseif ($mode == 'h3') 
        { 
          if ($empty_only && $row['seo_h3']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'seo_h1'; 
        } 
        // Meta title 
        elseif ($mode == 'title') 
        { 
          if ($empty_only && $row['meta_title']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_title'; 
        } 
        // Meta keywords 
        elseif ($mode == 'keyword') 
        { 
          if ($empty_only && $row['meta_keyword']) continue; 
           
          if (function_exists('mb_strtolower')) { 
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } else { 
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); 
          } 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_keyword'; 
        } 
        // Meta description 
        elseif ($mode == 'description') 
        { 
          if ($empty_only && $row['meta_description']) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'meta_description'; 
        } 
        // Description 
        elseif ($mode == 'full_desc') 
        { 
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue; 
           
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); 
           
          if (!$simulate) { 
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc); 
          } 
          // $field = 'description'; 
        } 
         
        if (array_key_exists($field, $row)) { 
          $changed = !($value === $row[$field]); 
        } else { 
          $changed = false; 
        } 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) { 
            $values[$lang]['rows'][] = array( 
              'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'), 
              'name' =>  $row['name'], 
              'old_value' =>  (string) $row[$field], 
              'value' =>  '[backup url to redirect to new one]', 
              'changed' =>  false, 
            ); 
          } 
           
          $values[$lang]['rows'][] = array( 
            'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'), 
            'name' =>  $row['name'], 
            'old_value' =>  (string) $row[$field], 
            'value' =>  $value, 
            'changed' =>  $changed, 
          ); 
        } 
         
        if ($changed) { 
          if (defined('SEO_PACKAGE_CLI')) { 
            $this->log('manufacturer.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value); 
          } 
           
          $this->session->data['seopackage_updated']++; 
          $change_count++; 
          //Powercache::remove('seo_rewrite', 'manufacturer_id=' . $row['manufacturer_id']); 
        } 
      } // end foreach $rows 
      $values[$lang]['count'] = $change_count; 
    } 
    $data['langs'] = &$values; 
     
    return $data; 
  } 
   
  public function generator_manufacturer_old($mode, $simulate, $empty_only, $redirect) { 
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
     
    $values = $data = array(); 
    $values['lang_img'] = ''; 
    $values['no_old'] = true; 
    $values['rows'] = array(); 
     
    if (isset($this->request->post['mlseo_manufacturer_'.$mode.'_pattern'])) { 
      $pattern = $this->request->post['mlseo_manufacturer_'.$mode.'_pattern']; 
    } else { 
      $pattern = $this->config->get('mlseo_manufacturer_'.$mode.'_pattern'); 
    } 
     
    $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "manufacturer")->row; 
    $this->total_items = $total['total']; 
     
    if (version_compare(VERSION, '4', '>=')) { 
      $rows = $this->db->query("SELECT name, manufacturer_id, IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = manufacturer_id LIMIT 1), '') AS seo_keyword FROM " . DB_PREFIX . "manufacturer ORDER BY manufacturer_id LIMIT ".$this->start.",".$this->limit)->rows; 
    } else { 
      $rows = $this->db->query("SELECT name, manufacturer_id, IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('manufacturer_id=',manufacturer_id) LIMIT 1), '') AS seo_keyword FROM " . DB_PREFIX . "manufacturer ORDER BY manufacturer_id LIMIT ".$this->start.",".$this->limit)->rows; 
    } 
   
    foreach ($rows as $row) 
    { 
      //Powercache::remove('seo_rewrite', 'manufacturer_id=' . $row['manufacturer_id']); 
      $value = str_replace('[current]', $row['seo_keyword'], $pattern); 
      $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformManufacturer($value, false, $row, $this->store); 
       
      if ($mode == 'url') 
      { 
        if ($empty_only && $row['seo_keyword']) continue; 
         
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'manufacturer', $row['manufacturer_id'], '', $simulate); 
 
        if (!$simulate) { 
          if (version_compare(VERSION, '4', '>=')) { 
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = '" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
          } else if (version_compare(VERSION, '3', '>=')) { 
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)"); 
          } else { 
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "'"); 
          } 
           
          if (version_compare(VERSION, '4', '>=')) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'manufacturer_id', `value` = '" . $row['manufacturer_id'] . "', language_id = 0, keyword = '" . $this->db->escape($value) . "'"); 
          } else if ($this->ml_mode) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = 0, keyword = '" . $this->db->escape($value) . "'"); 
          } else { 
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "'"); 
          } 
        } 
      } 
       
      if (!defined('SEO_PACKAGE_CLI')) { 
        $values['rows'][] = array( 
          'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'), 
          'name' =>  $row['name'], 
          'old_value' =>  $row['seo_keyword'], 
          'value' =>  $value, 
          'changed' =>  $row['seo_keyword'] != $value, 
        ); 
      } 
       
      if (defined('SEO_PACKAGE_CLI')) { 
        $this->log('manufacturer.' . $mode . ': ' . $row['name'] . ' => ' . $value); 
      } 
    } 
    $data['langs'][0] = &$values; 
     
    return $data; 
    } 
   
  public function generator_redirect($mode, $simulate, $empty_only, $redirect) { 
    $data = array(); 
     
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
     
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
     
    // define('FRONT_MODEL_LOADER', true); 
     
    // require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php'));  
    // $this->seo_url = new ControllerCommonSeoUrl($this->registry); 
    //$this->seo_url->index(); 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $values = array(); 
      $values['lang_img'] = $lang_img[$lang]; 
      $values['no_old'] = true; 
      $values['rows'] = array(); 
       
      $this->config->set('mlseo_cache', false); 
       
      $this->config->set('config_language_id', (int) $lang); 
      $this->config->set('config_language', $lang_code[$lang]); 
      $this->session->data['language'] = $lang_code[$lang]; 
       
      $type = $mode; 
       
      switch($type) { 
        case 'information': 
          $route = 'information/information'; 
          $field = $param = 'information_id'; 
          break; 
        case 'product': 
          $route = 'product/product'; 
          $field = $param = 'product_id'; 
          break; 
        case 'category': 
          $route = 'product/category'; 
          $field = 'category_id'; 
          $param = 'path'; 
          break; 
        case 'manufacturer': 
          $route = 'product/manufacturer/info'; 
          $field = $param = 'manufacturer_id'; 
          break; 
      } 
       
      $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type)->row; 
      $this->total_items = $total['total']; 
       
      if ($type == 'category') { 
        $rows = $this->getCategories(0, '', " LIMIT " . $this->start . "," . $this->limit); 
      } else { 
        $rows = $this->db->query("SELECT " . $field . " FROM " . DB_PREFIX . $type . " ORDER BY " . $field . " LIMIT " . $this->start . "," . $this->limit)->rows; 
      } 
       
      if (version_compare(VERSION, '4', '>=')) { 
        require_once(DIR_CATALOG . 'model/design/seo_url.php'); 
      } 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        $this->config->set('config_store_id', $this->store); 
         
        if (version_compare(VERSION, '4', '>=')) { 
          require_once(DIR_CATALOG . 'model/design/seo_url.php'); 
          $this->config->set('application', 'Catalog'); 
          $this->load->model('design/seo_url'); 
           
          $url = $this->front_url->link($route, $param . '=' . $row[$param]); 
           
          $this->config->set('application', 'Admin'); 
        } else { 
          $url = $this->front_url->link($route, $param . '=' . $row[$param]); 
        } 
         
        // get relative url 
        $rel_url = str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url); 
          
        $redir = $route . '&' . $param . '=' . $row[$param]; 
         
        // do not redirect default links 
        if (strpos($url, 'index.php?route=') !== false) continue; 
         
        //if ($empty_only && $row['seo_keyword']) continue; 
         
        $count = $this->db->query("SELECT COUNT(*) as count FROM " . DB_PREFIX . "url_redirect WHERE query = '" . $this->db->escape($rel_url) . "' AND redirect = '" . $this->db->escape($redir) . "' AND language_id = '" . (int) $lang . "'")->row; 
         
        if ($count['count']) { 
          $changed = 0; 
        } else { 
          if (!$simulate) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . "url_redirect SET query = '" . $this->db->escape($rel_url) . "', redirect = '" . $this->db->escape($redir) . "', language_id = '" . (int) $lang . "'"); 
          } 
           
          $changed = 1; 
          $this->session->data['seopackage_updated']++; 
        } 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
        $values['rows'][] = array( 
          'link' =>  str_replace(HTTP_SERVER, '../', $url), 
          'name' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url), 
          'old_value' =>  '', 
          'value' => $redir, 
          'changed' =>  $changed, 
        ); 
        } 
       
        if (defined('SEO_PACKAGE_CLI')) { 
          if ($changed) { 
            $this->log('redirect.' . $mode . ': ' . $rel_url . ' => ' . str_replace(HTTP_SERVER, '../', $url)); 
          } 
        } 
      } 
       
      $data['langs'][$lang] = $values; 
      $data['langs'][$lang]['count'] = count($values['rows']); 
       
      if ($type == 'manufacturer') { 
        $data['langs'][$lang]['lang_img'] = false; 
        break; 
      } 
    } 
     
    return $data; 
  } 
   
  public function generator_report($mode, $simulate, $empty_only, $redirect) { 
    $values = $data = array(); 
    $values['lang_img'] = ''; 
    $values['no_old'] = true; 
    $values['rows'] = array(); 
    $data['nohidecol'] = true; 
    $data['hidesim'] = true; 
    $data['col1'] = $this->language->get('text_query'); 
    $data['col2'] = $this->language->get('text_keyword'); 
    $data['col3'] = $this->language->get('text_status'); 
     
    if (version_compare(VERSION, '4', '>=')) { 
      $urls = $this->db->query("SELECT `key`, `value`, `keyword` FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = ''")->rows; 
    } else { 
      $urls = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = ''")->rows; 
    } 
     
    foreach($urls as $url) { 
      if (version_compare(VERSION, '4', '>=')) { 
        $url['query'] = $url['key'].'='.$url['value']; 
      } 
       
      $values['rows'][] = array( 
        'name' =>  $url['query'], 
        'old_value' =>  $url['keyword'], 
        'value' =>  '<span style="color:#C94644">'.$this->language->get('text_empty').'</span>', 
        'changed' =>  0, 
      ); 
    } 
     
    if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) { 
      $where = " WHERE store_id = ".(int) $this->store." "; 
    } else { 
      $where = ''; 
    } 
 
    //$urls = $this->db->query("SELECT count(*) AS count, query, keyword FROM " . DB_PREFIX . $this->url_alias . " GROUP BY keyword")->rows; 
    if (version_compare(VERSION, '4', '>=')) { 
      if ($this->ml_mode && $this->config->get('mlseo_duplicate')) { 
        $urls = $this->db->query("SELECT count(*) AS count, CONCAT(`key`, `value`) AS query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows; 
      } else { 
        $urls = $this->db->query("SELECT count(*) AS count, CONCAT(`key`, `value`) AS query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows; 
      } 
    } else { 
      if ($this->ml_mode && $this->config->get('mlseo_duplicate')) { 
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows; 
      } else { 
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows; 
      } 
    } 
     
    foreach($urls as $url) { 
      if ($url['keyword'] && $url['count']> 1) { 
        if (version_compare(VERSION, '4', '>=')) { 
          $duplicates = $this->db->query("SELECT CONCAT(`key`, `value`) AS query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."'")->rows; 
        } else { 
          $duplicates = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."'")->rows; 
        } 
         
        foreach($duplicates as $duplicate) { 
          $values['rows'][] = array( 
            'name' =>  $duplicate['query'], 
            'old_value' =>  $duplicate['keyword'], 
            'value' =>  '<span style="color:#82669B">'.$this->language->get('text_duplicate').'</span>', 
            'changed' =>  0, 
          ); 
        } 
      } 
    } 
     
    $data['langs'][0] = &$values; 
    //$data['langs'][0]['count'] = count($urls); 
     
    return $data; 
  } 
   
  public function generator_links($mode, $simulate, $empty_only, $redirect) { 
    $data = array(); 
     
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
     
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
     
    // define('FRONT_MODEL_LOADER', true); 
     
    // require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php'));  
    // $this->seo_url = new ControllerCommonSeoUrl($this->registry); 
    //$this->seo_url->index(); 
     
    $mode = 'product'; 
     
    foreach($this->request->post['langs'] as $lang) 
    { 
      $values = array(); 
      $values['lang_img'] = $lang_img[$lang]; 
      $values['no_old'] = true; 
      $values['rows'] = array(); 
       
      $this->config->set('mlseo_cache', false); 
       
      $this->config->set('config_language_id', (int) $lang); 
      $this->config->set('config_language', $lang_code[$lang]); 
      $this->session->data['language'] = $lang_code[$lang]; 
       
      $type = $mode; 
       
      switch($type) { 
        case 'information': 
          $route = 'information/information'; 
          $field = $param = 'information_id'; 
          break; 
        case 'product': 
          $route = 'product/product'; 
          $field = $param = 'name'; 
          break; 
        case 'category': 
          $route = 'product/category'; 
          $field = 'category_id'; 
          $param = 'path'; 
          break; 
        case 'manufacturer': 
          $route = 'product/manufacturer/info'; 
          $field = $param = 'manufacturer_id'; 
          break; 
      } 
       
      $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type)->row; 
      $this->total_items = $total['total']; 
       
      if ($type == 'category') { 
        $rows = $this->getCategories(0, '', " LIMIT " . $this->start . "," . $this->limit); 
      } else { 
        $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description ORDER BY " . $field . " LIMIT " . $this->start . "," . $this->limit)->rows; 
      } 
       
      foreach ($rows as $row) { 
        $this->session->data['seopackage_processed']++; 
         
        $this->config->set('config_store_id', $this->store); 
         
        $url = $this->front_url->link($route, $type . '_id=' . $row[$type.'_id']); 
         
        // get relative url 
        $rel_url = str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url); 
          
        //$redir = $route . '&' . $param . '=' . $row[$param]; 
         
        // do not redirect default links 
        //if (strpos($url, 'index.php?route=') !== false) continue; 
         
        //if ($empty_only && $row['seo_keyword']) continue; 
         
        if (empty($row[$field])) continue; 
         
        $changed = 0; 
         
        $insertedInto = $insertedIntoHref = array(); 
        $searchLinks = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description WHERE description LIKE '%" . $this->db->escape($row[$field]) . "%' AND language_id = '" . (int) $lang . "'")->rows; 
         
        foreach ($searchLinks as $res) { 
          $orig_desc = $new_desc = $res['description']; 
           
          preg_match_all('/(?:&lt;a.+?&gt;)?\b'.preg_quote($row[$field], '/').'\b(?:&lt;\/a&gt;)?/', $orig_desc, $matches); 
           
          if (empty($matches)) continue; 
           
          foreach ($matches as $match) { 
            if (empty($match[0])) continue; 
            $new_desc = str_replace($match[0], '&lt;a href="'.$url.'"&gt;'.$row[$field].'&lt;/a&gt;', $orig_desc); 
          } 
           
          $insertedInto[] = $res[$type.'_id']; 
          $insertedIntoHref[] = '<a href="'.$this->url->link('catalog/'.$type.'/edit', $type.'_id='.$res[$type.'_id'].'&'.$this->token).'">'.$res[$type.'_id'].'</a>'; 
           
           
          if ($orig_desc != $new_desc) { 
            if (!$simulate) { 
              $this->db->query("UPDATE " . DB_PREFIX . $type . "_description SET description = '" . $this->db->escape($new_desc) . "' WHERE " . $type . "_id = '" . (int) $res[$type . '_id'] . "' AND language_id = '" . (int) $lang . "'"); 
            } 
             
            $changed = 1; 
          } 
        } 
         
        if (empty($insertedInto)) continue; 
         
        if ($changed) $this->session->data['seopackage_updated']++; 
         
        if (!defined('SEO_PACKAGE_CLI')) { 
          $values['rows'][] = array( 
            'link' =>  $this->url->link('catalog/'.$type.'/edit', $type.'_id='.$row[$type.'_id'].'&'.$this->token), 
            'name' =>  $row['name'], 
            'old_value' =>  $url, 
            'value' => ($changed ? 'Added link into: ' : 'Link exists into: ') . implode(', ', $insertedIntoHref), 
            'changed' => $changed, 
          ); 
        } 
       
        if (defined('SEO_PACKAGE_CLI')) { 
          if ($changed) { 
            $this->log('internal_links: ' . $url . ' => ' . implode(', ', $insertedInto)); 
          } 
        } 
      } 
       
      $data['langs'][$lang] = $values; 
      $data['langs'][$lang]['count'] = count($values['rows']); 
       
      if ($type == 'manufacturer') { 
        $data['langs'][$lang]['lang_img'] = false; 
        break; 
      } 
    } 
     
    return $data; 
  } 
   
  public function generator_robots($mode, $simulate, $empty_only, $redirect) { 
    $values = $data = array(); 
    $values['lang_img'] = ''; 
    $values['no_old'] = true; 
    $values['no_main'] = true; 
    $values['rows'] = array(); 
    $data['nohidecol'] = true; 
    $data['hidesim'] = true; 
    $data['col1'] = $this->language->get('text_query'); 
    $data['col2'] = $this->language->get('text_keyword'); 
    $data['col3'] = $this->language->get('text_status'); 
     
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
     
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
     
    if (!$simulate) { 
      $fh = fopen(DIR_CATALOG.'../robots.txt', 'w') or die('robots.txt can not be written, please check rights'); 
    } 
     
    $robots = 'User-agent: * 
Disallow: /*?route=checkout/ 
Disallow: /*?route=account/ 
Disallow: /*?route=affiliate/ 
Disallow: /*?route=product/search 
Disallow: /*&limit 
Disallow: /*?limit 
Disallow: /*?sort 
Disallow: /*&sort 
Disallow: /*?order 
Disallow: /*&order 
Disallow: /*?price 
Disallow: /*&price 
Disallow: /*?mode 
Disallow: /*&mode 
Disallow: /*?cat 
Disallow: /*&cat 
Disallow: /*?dir 
Disallow: /*&dir 
Disallow: /*?color 
Disallow: /*&color 
Disallow: /*?product_id 
Disallow: /*&product_id 
Disallow: /*?minprice 
Disallow: /*&minprice 
Disallow: /*?maxprice 
Disallow: /*&maxprice 
Disallow: /*?page=1 
Disallow: /*&create=1 
Disallow: /*?keyword 
Disallow: /*?av 
 
Sitemap: '.HTTP_CATALOG.'sitemap.xml'; 
 
    if (!$simulate) { 
      fwrite($fh, $robots); 
    } 
     
    $values['rows'][] = array( 
          'name' =>  '', 
          'old_value' =>  '', 
          'value' => nl2br($robots), 
          'changed' =>  0, 
        ); 
     
    $query = $this->db->query("SELECT product_id FROM " . DB_PREFIX . "product WHERE meta_robots IN ('noindex', 'none')")->rows; 
     
    foreach ($query as $product) { 
      foreach ($this->request->post['langs'] as $lang) { 
        $this->config->set('config_language_id', (int) $lang); 
        $this->config->set('config_language', $lang_code[$lang]); 
        $this->session->data['language'] = $lang_code[$lang]; 
 
        $this->session->data['seopackage_processed']++; 
         
        $this->config->set('config_store_id', $this->store); 
         
        $url = str_replace(array(HTTP_CATALOG, HTTPS_CATALOG), '/', $this->front_url->link('product/product', 'product_id=' . $product['product_id'])); 
         
        fwrite($fh, "\n" . 'Disallow: ' . $url); 
       
        $values['rows'][] = array( 
          'name' =>  '', 
          'old_value' =>  '', 
          'value' => 'Disallow: ' . $url, 
          'changed' =>  0, 
        ); 
      } 
    } 
     
    if (!$simulate) { 
      fclose($fh); 
    } 
     
    $data['langs'][0] = &$values; 
     
    return $data; 
  } 
   
  protected function getCategories($parent_id, $current_path = '', $limits = '') { 
    $route = 'product/category'; 
    $field = 'category_id'; 
    $param = 'path'; 
     
    $categories = array(); 
 
    $results = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = " . (int) $parent_id . " ORDER BY " . $field . $limits)->rows;; 
     
    foreach ($results as $result) { 
      if (!$current_path) { 
        $new_path = $result['category_id']; 
      } else { 
        $new_path = $current_path . '_' . $result['category_id']; 
      } 
 
      $categories[] = array( 
        'category_id' => $result['category_id'], 
        'path' => $new_path, 
      ); 
 
      $categories = array_merge($categories, $this->getCategories($result['category_id'], $new_path)); 
    } 
 
    return $categories; 
  } 
   
  public function generator_cache($mode, $simulate, $empty_only, $redirect) { 
    $data = array(); 
     
    $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    foreach ($languages as $language) { 
      $lang_code[$language['language_id']] = $language['code']; 
      if (version_compare(VERSION, '2.2', '>=')) { 
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png'; 
      } else { 
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image']; 
      } 
    } 
     
    if ($mode == 'delete') { 
      $values = array(); 
      $values['lang_img'] = ''; 
      $values['no_old'] = true; 
      $values['rows'] = array(); 
      foreach($this->request->post['langs'] as $lang) 
      { 
        $res = Powercache::delete('seo_rewrite.' . (int) $lang); 
        if ($res) { 
          $values['rows'][] = array( 
            'link' =>  0, 
            'name' =>  '/system/cache/pcache.seo_rewrite.'.$lang, 
            'old_value' =>  '', 
            'value' => $this->language->get('text_deleted'), 
            'changed' =>  0, 
          ); 
        } 
      } 
      $data['langs'][$lang] = $values; 
      $data['langs'][$lang]['count'] = count($values['rows']); 
      return $data; 
    } 
     
    $data['simulate'] = false; 
 
    //define('FRONT_MODEL_LOADER', true); 
     
    //require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php'));  
    //$this->seo_url = new ControllerCommonSeoUrl($this->registry); 
 
    foreach($this->request->post['langs'] as $lang) 
    { 
      $values = array(); 
      $values['lang_img'] = $lang_img[$lang]; 
      $values['no_old'] = true; 
      $values['rows'] = array(); 
     
      Powercache::delete('seo_rewrite.' . (int) $lang); 
       
      $this->config->set('config_language_id', (int) $lang); 
      $this->config->set('config_language', $lang_code[$lang]); 
      $this->session->data['language'] = $lang_code[$lang]; 
       
      $types = array('product', 'information'); 
      $this->total_items = 0; 
      foreach ($types as $type) 
      { 
        switch($type) { 
          case 'information': 
            $route = 'information/information'; 
            $field = $param = 'information_id'; 
            break; 
          case 'product': 
            $route = 'product/product'; 
            $field = $param = 'product_id'; 
            break; 
          case 'category': 
            $route = 'product/category'; 
            $field = 'category_id'; 
            $param = 'path'; 
            break; 
          } 
         
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type."_description WHERE language_id=".(int)$lang)->row; 
        $this->total_items += $total['total']; 
         
        $rows = $this->db->query("SELECT ".$field.", seo_keyword, language_id FROM " . DB_PREFIX . $type."_description WHERE language_id=".(int)$lang . " ORDER BY ".$field." LIMIT ".$this->start.",".$this->limit)->rows; 
        foreach ($rows as $row) 
        { 
           
          //$url = $this->front_link($route, $param . '=' . $row[$field]); 
          $url = $this->front_url->link($route, $param . '=' . $row[$field]); 
           
          $values['rows'][] = array( 
            'link' =>  str_replace(HTTP_SERVER, '../', $url), 
            'name' =>  'index.php?route=' . $route . '&' . $param . '=' . $row[$field], 
            'old_value' =>  '', 
            'value' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url), 
            'changed' =>  0, 
          ); 
 
          // product link from categories 
          if ($type == 'product') 
          { 
            $paths = $this->{self::$MODEL_PATH.'tool_seo_package'}->getFullProductPaths($row['product_id']); 
            foreach ($paths as $path) 
            { 
              //$url = $this->url->link('product/product', 'path=' . $path . '&product_id=' . $row['product_id']); 
              $url = $this->front_url->link('product/product', 'path=' . $path . '&product_id=' . $row['product_id']); 
               
              $values['rows'][] = array( 
                'link' =>  str_replace(HTTP_SERVER, '../', $url), 
                'name' =>  'index.php?route=product/product&path=' . $path . '&product_id=' . $row['product_id'], 
                'old_value' =>  '', 
                'value' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url), 
                'changed' =>  0, 
              ); 
            } 
          } 
           
          //Powercache::add('seo_rewrite', $row['language_id'] . '-route=product/product&product_id=' . $row['product_id'], $url); 
           
        } 
      } 
       
      $data['langs'][$lang] = $values; 
      $data['langs'][$lang]['count'] = count($values['rows']); 
    } 
     
    return $data; 
  } 
   
  public function generator_cleanup($mode, $simulate, $empty_only, $redirect) { 
    $values = $data = array(); 
    $values['lang_img'] = ''; 
    $values['no_old'] = true; 
    $values['rows'] = array(); 
     
    if ($mode == 'url') { 
      if ($this->ml_mode) { 
        if (version_compare(VERSION, '4', '>=')) { 
          $urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` IN ('path', 'product_id', 'information_id', 'route') AND language_id=0")->rows; 
        } else { 
          $urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0")->rows; 
        } 
      } else { 
        //$urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%')")->rows; 
        $urls = array(); 
      } 
       
      foreach ($urls as $url) 
      { 
        $values['rows'][] = array( 
          'name' =>  $url['query'] . ' ('.$url['keyword'].')', 
          'old_value' =>  '', 
          'value' => 'Fix assigned language ID', 
          'changed' =>  0, 
        ); 
      } 
       
      if (!$simulate && false) { 
        // Copy keyword values to item tables - Common to all modules - copy first without language id to be sure to have it in case of not defined 
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '')"); 
        $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '')"); 
        $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '')"); 
         
        if ($this->ml_mode) { 
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id"); 
          $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id"); 
          $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id"); 
        } 
      } 
       
      if (!$simulate) { 
        if ($this->ml_mode) { 
          if (version_compare(VERSION, '4', '<')) { 
            $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET language_id = ".(int) $this->config->get('config_language_id')." WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0"); 
          } 
          //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%') AND language_id=0"); 
        } else { 
          //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%')"); 
        } 
      } 
         
      $data['langs'][0] = &$values; 
      $data['langs'][0]['count'] = count($urls); 
    } else if ($mode == 'duplicate') { 
      $data['nohidecol'] = true; 
      $data['col1'] = $this->language->get('text_query'); 
      $data['col2'] = $this->language->get('text_keyword'); 
      $data['col3'] = $this->language->get('text_status'); 
     
      $deleted = 0; 
       
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) { 
        $where = " WHERE store_id = ".(int) $this->store." "; 
        $and_store = " AND store_id = ".(int) $this->store." "; 
      } else { 
        $where = ''; 
        $and_store = ''; 
      } 
       
      if ($this->ml_mode) { 
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows; 
      } else { 
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows; 
      } 
       
      foreach($urls as $url) { 
        if ($url['count'] > 1) { 
          if (!$simulate) { 
            if (version_compare(VERSION, '4', '>=')) { 
              list($queryKey, $queryVal) = explode('=', $url['query']); 
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $queryKey . "' AND `value` = '" . $queryVal . "' AND keyword = '".$url['keyword']."' AND language_id = '".$url['language_id']."' ".$and_store." LIMIT " . ($url['count']-1)); 
            } else if ($this->ml_mode) { 
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '".$url['query']."' AND keyword = '".$url['keyword']."' AND language_id = '".$url['language_id']."' ".$and_store." LIMIT " . ($url['count']-1)); 
            } else { 
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '".$url['query']."' AND keyword = '".$url['keyword']."' ".$and_store." LIMIT " . ($url['count']-1)); 
            } 
          } 
 
          $values['rows'][] = array( 
            'name' =>  $url['query'], 
            'old_value' =>  $url['keyword'], 
            'value' =>  $this->language->get('text_deleted'), 
            'changed' =>  0, 
          ); 
          $deleted++; 
        } 
      } 
       
      $data['langs'][0] = &$values; 
      $data['langs'][0]['count'] = $deleted; 
    } 
       
      return $data; 
  } 
   
  public function get_value() { 
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
    $type = $this->request->get['type']; 
    $fields = $this->request->get['field']; 
    $item_id = (int) $this->request->get['id']; 
    $store_id = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
     
    if ($store_id) { 
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '".$store_id."'"); 
			 
			foreach ($query->rows as $setting) { 
				if (!$setting['serialized']) { 
					$this->config->set($setting['key'], $setting['value']); 
        } else if ($this->OC_V21X) { 
					$this->config->set($setting['key'], json_decode($setting['value'], true)); 
				} else { 
					$this->config->set($setting['key'], unserialize($setting['value'])); 
				} 
			} 
		} 
     
    $lgCodes = $this->config->get('mlseo_lang_codes'); 
       
    if (!empty($lgCodes[$lang])) { 
      $this->config->set('mlseo_current_lang', $lgCodes[$lang]); 
    } 
 
    if (!in_array($type, array('product', 'category', 'information', 'manufacturer'))) { 
      return ''; 
    } 
     
     
    if ($fields == 'all') { 
      if ($type == 'product') { 
        $fields = array('seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'image_alt', 'image_title', 'meta_title', 'meta_keyword', 'meta_description', 'tag'); 
      } else { 
        $fields = array('seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'meta_title', 'meta_keyword', 'meta_description'); 
      } 
       
      if ($this->config->get('mlseo_update_description')) { 
        $fields[] = 'description'; 
      } 
    } 
     
    if (empty($fields)) { 
      return ''; 
    } 
     
    $values = array(); 
     
    foreach ((array) $fields as $field) { 
       
      switch ($field) { 
        case 'seo_keyword': $mode = 'url'; break; 
        case 'seo_h1': $mode = 'h1'; break; 
        case 'seo_h2': $mode = 'h2'; break; 
        case 'seo_h3': $mode = 'h3'; break; 
        case 'meta_title': $mode = 'title'; break; 
        case 'meta_keyword': $mode = 'keyword'; break; 
        case 'meta_description': $mode = 'description'; break; 
        case 'description': $mode = 'full_desc'; break; 
        case 'image': $mode = 'image_name'; break; 
        case 'image_title': $mode = 'image_title'; break; 
        case 'image_alt': $mode = 'image_alt'; break; 
        case 'tag': $mode = 'tag'; break; 
      } 
 
      //$row = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description WHERE " . $type . "_id = " . (int) $item_id . " AND language_id=" . (int) $lang)->row; 
 
      //$row = $this->request->post[$type.'_description'][$lang]; 
      $row = $this->request->post; 
      $row[$type.'_id'] = $item_id; 
       
      // set substore values 
      if ($store_id && !empty($row['seo_'.$type.'_description'][$store_id])) { 
        if (isset($row[$type.'_description'])) { 
          foreach ($row[$type.'_description'] as $language_id => $desc) { 
            $row[$type.'_description'][$language_id]['orig_name'] = ''; 
            if (isset($row[$type.'_description'][$language_id]['name'])) { 
              $row[$type.'_description'][$language_id]['orig_name'] = $row[$type.'_description'][$language_id]['name']; 
            } else if (isset($row[$type.'_description'][$language_id]['title'])) { 
              $row[$type.'_description'][$language_id]['orig_name'] = $row[$type.'_description'][$language_id]['title']; 
            } 
            $row[$type.'_description'][$language_id]['orig_description'] = $row[$type.'_description'][$language_id]['description']; 
            $row[$type.'_description'][$language_id] = array_merge($row[$type.'_description'][$language_id], array_filter($row['seo_'.$type.'_description'][$store_id][$language_id])); 
          } 
        } 
      } 
       
      $pattern = $this->config->get('mlseo_'.$type.'_'.$mode.'_pattern'); 
       
      if ($type == 'manufacturer') { 
        $pattern = str_replace('[current]', $row['seo_'.$type.'_description'][$store_id][$lang][$field], $pattern); 
      } else { 
        $pattern = str_replace('[current]', $row[$type.'_description'][$lang][$field], $pattern); 
      } 
       
      $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
       
      $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->{'transform'.ucfirst($type)}($pattern, $lang, $row, $store_id, true); 
       
      if ($field == 'tag') { 
        if ($lang) { 
          $remove = $this->config->get('mlseo_remove_'.$lang); 
        } else { 
          $remove = $this->config->get('mlseo_remove_'.$this->config->get('config_language_id')); 
        } 
         
        $value = str_replace('"', '', $value); 
         
        if (!empty($remove)) { 
          $beforeWord = "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|^)"; 
          $afterWord =  "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|$)"; 
          $removeArray = array(); 
           
          foreach (explode(',', $remove) as $rem) { 
            $removeArray[] = '`'.$beforeWord.preg_quote(trim($rem), '`').$afterWord.'`'; 
          } 
           
          if ($removeArray) { 
            $value = preg_replace($removeArray, '$1$2', $value); 
          } 
        } 
         
        if ($this->config->get('mlseo_format_tag')) { 
          $value = str_replace('.', ',', $value); 
          $value = str_replace(array('  ',' '), ', ', $value); 
          $value = trim(mb_strtolower($value), ', '); 
        } 
         
        $value = trim(preg_replace('/(?:,\s*)+/', ',', $value), ', '); 
      } 
       
      if ($field == 'seo_keyword') { 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, $type, $row[$type.'_id'], $lang); 
      } 
       
      if ($mode == 'full_desc') { 
        $value = nl2br($value); 
      } 
       
      if ($mode == 'keyword') { 
        if (function_exists('mb_strtolower')) { 
          $value = mb_strtolower($value); 
        } else { 
          $value = strtolower($value); 
        } 
      } 
       
      if ($store || $type == 'manufacturer') { 
        $values['seo_'.$type.'_description['.$store.']['.$lang.']['.$field.']'] = $value; 
      } else { 
        $values[$type.'_description['.$lang.']['.$field.']'] = $value; 
      } 
    } 
     
    header('Content-Type: application/json'); 
    echo json_encode($values); 
    exit; 
  } 
   
  public function generator($type = '', $mode = '', $redirect = '') { 
    //sleep (2); 
     
    $this->session->data['seopackage_processed'] = 0; 
    $this->session->data['seopackage_updated'] = 0; 
     
    $benchmark = false; 
    if ($benchmark) { 
      ini_set('memory_limit', -1); 
      set_time_limit(3600); 
    } 
    $this->start_time = microtime(true)*1000; 
     
    $data['OC_V2'] = version_compare(VERSION, '2', '>='); 
     
    if (defined('SEO_PACKAGE_CLI')) { 
      $this->start = 0; 
      $this->limit = 9999999999; 
    } else { 
      $this->start = (int) $this->request->get['start']; 
    } 
       
    $this->store = isset($this->request->get['store']) ? $this->request->get['store'] : 0; 
     
    if (!$this->start) unset($this->session->data['kwCountArray']); 
     
    if (!$type && !isset($this->request->get['type'])) return; 
    if (!$mode && !isset($this->request->get['mode'])) return; 
     
    if (!$type) $type = $this->request->get['type']; 
    if (!$mode) $mode = $this->request->get['mode']; 
    if (!$redirect) $redirect = !empty($this->request->get['redirect']) ? $this->request->get['redirect'] : false; 
     
    $data['type'] = $type; 
    $data['mode'] = $mode; 
    $data['simulate'] = $simulate = !empty($this->request->post['simulate']); 
    if (!$this->user->hasPermission('modify', self::$LINK)) { 
      $data['simulate'] = $simulate = true; 
    } 
    $data['empty_only'] = $empty_only = !empty($this->request->post['empty_only']); 
     
    if (!defined('SEO_PACKAGE_CLI') && $mode == 'related') { 
      $this->limit = 100; 
    } 
       
    $res = $this->{'generator_'.$type}($mode, $simulate, $empty_only, $redirect); 
     
    $data['_language'] = $this->language; 
    $data['_config'] = $this->config; 
    $data['_url'] = $this->url; 
    $data['token'] = $this->token; 
     
    if ($benchmark) { 
      $end_time = microtime(true)*1000; 
      var_dump('time: '. ((int)($end_time - $this->start_time) /1000). 's'); 
      var_dump('mem peak: ' . memory_get_peak_usage()/1000000); 
      die; 
    } 
     
    $processed = $this->start + $this->limit; 
     
    if ($processed > $this->total_items) { 
      $processed = $this->total_items; 
    } 
     
    if (!$this->total_items) { 
      $progress = 100; 
    } else { 
      $progress = round(($processed / $this->total_items) * 100); 
    } 
     
    header('Content-Type: application/json'); 
     
    echo json_encode(array( 
      'success'=> 1, 
      'processed' => $processed, 
      'progress' => $progress, 
      'finished' => $processed >= $this->total_items, 
      'log' => $res, 
    )); 
     
    exit; 
    /* 
    if ($this->OC_V2) { 
      $this->response->setOutput($this->load->view('module/seo_generator.tpl', $data)); 
    } else { 
      $this->data = &$data; 
      $this->template = 'module/seo_generator.tpl'; 
      echo $this->render(); 
    } 
    */ 
  } 
   
  /*<complete*/ 
 
  public function cli($params = '') { 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
     
    $start_time = time(); 
     
    foreach ($languages as $language) { 
      $this->request->post['langs'][] = $language['language_id']; 
    } 
 
    $this->session->data['seopackage_processed'] = 0; 
    $this->session->data['seopackage_updated'] = 0; 
     
    $this->start = 0; 
    $this->limit = 9999999999; 
       
    $this->store = isset($this->request->get['store']) ? $this->request->get['store'] : 0; 
     
    // overwrite store settings 
    if ($this->store) { 
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '".$this->store."'"); 
			 
			foreach ($query->rows as $setting) { 
				if (!$setting['serialized']) { 
					$this->config->set($setting['key'], $setting['value']); 
        } else if ($this->OC_V21X) { 
					$this->config->set($setting['key'], json_decode($setting['value'], true)); 
				} else { 
					$this->config->set($setting['key'], unserialize($setting['value'])); 
				} 
			} 
		} 
     
    $params = $this->config->get('mlseo_cron'); 
     
    if (isset($_GET['product']) || isset($_GET['category']) || isset($_GET['information']) || isset($_GET['manufacturer']) || isset($_GET['redirect'])) { 
      $params = $_GET; 
    } else { 
      $params = $this->config->get('mlseo_cron'); 
      if (!is_array($params)) { 
        echo 'No parameters found'; 
        return; 
      } 
    } 
     
    $simulation = isset($params['simulation']) && $params['simulation']; 
    $empty_only = isset($params['empty_only']) && $params['empty_only']; 
     
    $simu = $simulation ? 'SIMULATION MODE - ' : ''; 
    $this->log(PHP_EOL . '----------------------------- CLI Request - ' . $simu . date('d/m/Y H:i:s') . ' - Store ' . $this->store . ' -----------------------------', 'report'); 
     
    foreach (array('product', 'category', 'information', 'manufacturer', 'redirect') as $mode) { 
      if (!empty($_GET[$mode])) { 
        $params['update'][$mode] = (array) $_GET[$mode]; 
      } 
    } 
     
    if (count($params['update'])) { 
      foreach ($params['update'] as $type => $modes) { 
        foreach ($modes as $mode) { 
          $this->{'generator_'.$type}($mode, $simulation, $empty_only, ''); 
        } 
      } 
    } 
     
    $total_time = time() - $start_time; 
    $hours = floor($total_time/3600); 
    $mins = floor(($total_time-($hours * 3600))/60); 
    $secs = $total_time-($hours * 3600)-($mins * 60); 
    $process_time = ''; 
     
    if ($hours) { 
      $process_time = $hours . ' ' . $this->language->get('text_hours'); 
    } 
     
    if ($hours || $mins) { 
      $process_time .= ($hours ? ', ': '') . $mins . ' ' . $this->language->get('text_minutes'); 
    } 
     
    if ($hours || $mins || $secs) { 
      $process_time .= ($mins ? ' and ' : '') . $secs . ' ' . $this->language->get('text_seconds'); 
    } else if (!$process_time) { 
      $process_time .= '1 ' . $this->language->get('text_seconds'); 
    } 
     
    $this->log(PHP_EOL .  'Process terminated:', 'report'); 
    $this->log('- Total items: ' . $this->session->data['seopackage_processed'], 'report'); 
    $this->log('- Total updated: ' . $this->session->data['seopackage_updated'], 'report'); 
    $this->log('- Total process time: ' . $process_time, 'report'); 
    $this->log('-------------------------------------------------------------------------------------------------------' . PHP_EOL, 'report'); 
     
    echo 'Process terminated - Processed: ' . $this->session->data['seopackage_processed'] . ' - Updated: ' . $this->session->data['seopackage_updated'] . ' - Total time: '. $process_time; 
  } 
   
  public function editor_data() { 
    // DataTables PHP library 
    $this->load->model(self::$EXT_PATH.'tool/seo_package_editor'); 
    $this->load->model('tool/image'); 
     
    if (!isset($this->request->get['type'])) return; 
    if (!isset($this->request->get['lang'])) return; 
     
    $type = $this->request->get['type']; 
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
     
    $columns = array(); 
    // image column 
    $dt = 0; 
    if ($type == 'image') { 
      $columns[] = array( 'db' => 'image',  'dt' => $dt++, 'formatter' => 'inlineeditor_image'); 
      $columns[] = array( 'db' => 'name', 'dt' => $dt++); 
      $columns[] = array( 'db' => 'image', 'dt' => $dt++, 'formatter' => 'inlineeditor_image_name'); 
      $columns[] = array( 'db' => 'image_alt', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'image_title', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $type = 'product'; 
      $columns[] = array( 'db' => $type.'_id', 'dt' => $dt++, 'table_alias' => 'd'); 
    } else if ($type == 'absolute') { 
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'url_absolute_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn' ); 
    } else if (in_array($type, array('common', 'special'))) { 
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_keyword'); 
      $columns[] = array( 'db' => 'keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => $this->url_alias.'_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn' ); 
    } else if ($type == 'redirect') { 
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'url_redirect_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn'); 
     } else if ($type == 'autolink') { 
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      $columns[] = array( 'db' => 'url_autolink_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn'); 
    } else if ($type == '404') { 
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'editor_404color'); 
      $columns[] = array( 'db' => 'referer', 'dt' => $dt++); 
      $columns[] = array( 'db' => 'date_accessed', 'dt' => $dt++, 'formatter' => 'editor_date'); 
      $columns[] = array( 'db' => 'count', 'dt' => $dt++); 
      $columns[] = array( 'db' => 'url_404_id', 'dt' => $dt++, 'formatter' => 'editor_404actions'); 
    } else { 
      if (in_array($type, array('product', 'category', 'manufacturer'))) { 
        $columns[] = array( 'db' => 'image',  'dt' => $dt++, 'formatter' => 'inlineeditor_image'); 
        $columns[] = array( 'db' => 'name', 'dt' => $dt++, 'formatter' => 'inlineeditor_text', 'table_alias' => 'd'); 
      } 
      if (in_array($type, array('information'))) { 
        if ($store) { 
          $columns[] = array( 'db' => 'name', 'dt' => $dt++, 'formatter' => 'inlineeditor_text', 'table_alias' => 'd'); 
        } else { 
          $columns[] = array( 'db' => 'title', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
        } 
      } 
      /* 
      if (in_array($type, array('manufacturer'))) { 
        $columns[] = array( 'db' => 'keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
      } 
      */ 
      //if (!in_array($type, array('manufacturer'))) { 
      if (true) { 
        $columns[] = array( 'db' => 'seo_keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text'); 
        $columns[] = array( 'db' => 'meta_title', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
        $columns[] = array( 'db' => 'meta_keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
        $columns[] = array( 'db' => 'meta_description', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
        if (in_array($type, array('product')) && version_compare(VERSION, '1.5.3', '>') && !$store) { 
          $columns[] = array( 'db' => 'tag', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
        } 
        if (in_array($type, array('product')) && !$store) { 
          $columns[] = array( 'db' => 'related', 'dt' => $dt++, 'formatter' => 'inlineeditor_related'); 
        } 
        if (in_array($type, array('product','category'))) { 
          $columns[] = array( 'db' => 'seo_h1', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
          $columns[] = array( 'db' => 'seo_h2', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
          $columns[] = array( 'db' => 'seo_h3', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea'); 
        } 
      } 
      $columns[] = array( 'db' => $type.'_id', 'dt' => $dt++, 'table_alias' => 'i'); 
    } 
     
    //header('Content-Type: application/json'); 
     
    echo json_encode( 
      $this->{self::$MODEL_PATH.'tool_seo_package_editor'}->simple( $_GET, $type, $lang, $store, $columns ) 
    ); 
    exit; 
  } 
   
  public function editor_update() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) { 
      header('Content-Type: application/json'); 
      echo json_encode(array('status' => 'error', 'msg' => $this->language->get('error_permission'))); 
      exit; 
    } 
     
    $pk = $this->request->post['pk']; 
     
    if (isset($this->request->get['store'])) { 
      $store_id = (int) $this->request->get['store']; 
    } else if (isset($this->request->post['store'])) { 
      $store_id = (int) $this->request->post['store']; 
    } else { 
      $store_id = 0; 
    } 
     
    if (is_string($this->request->post['value'])) { 
      $value = html_entity_decode($this->request->post['value'], ENT_QUOTES, 'UTF-8'); 
    } else { 
      $value = $this->request->post['value']; 
    } 
     
    $col = $this->request->post['col']; 
    $type =  isset($this->request->post['type']) ? $this->request->post['type'] : ''; 
    $lang = isset($this->request->post['lang']) ? $this->request->post['lang'] : ''; 
     
    if ($type == 'image') { 
      $type = 'product'; 
    } 
     
    // return if something is empty 
    if (empty($pk) || empty($col)) return; 
     
    // allowed values 
    if (!in_array($col, array('title', 'name', 'seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'meta_title', 'meta_keyword', 'meta_description', 'tag', 'query', 'keyword', 'redirect', 'related', 'image', 'image_alt', 'image_title'))) return; 
     
    if ($col == 'image') { 
      $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
       
      $prod = $this->db->query("SELECT image FROM " . DB_PREFIX . "product WHERE product_id = '" . (int) $pk . "'")->row; 
       
      $path = pathinfo($prod['image']); 
      $new_path = pathinfo($value); 
       
      if (empty($prod['image']) || empty($new_path['filename'])) { 
        header('Content-Type: application/json'); 
        echo json_encode( 
          array('status' => 'error', 'pk' => $pk, 'msg' => 'Empty value not allowed') 
        ); 
        exit; 
      } 
       
      $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($new_path['filename'], 'image', ''); 
      $value = $path['dirname'] . '/' . $filename . '.' . $path['extension']; 
       
      $x = 1; 
       
      while (file_exists(DIR_IMAGE . $value)) { 
        $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension']; 
        $x++; 
      } 
       
      if (rename(DIR_IMAGE . $prod['image'], DIR_IMAGE . $value)) { 
        //$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE product_id = '" . (int) $pk . "'"); 
         
        // replace all images with such value 
        $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($prod['image']) . "'"); 
        $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($prod['image']) . "'"); 
      } 
       
      $value = pathinfo($value); 
       
      header('Content-Type: application/json'); 
       
      echo json_encode( 
        array('status' => 'success', 'pk' => $pk, 'msg' => $value['basename']) 
      ); 
       
      exit; 
    } 
     
    if ($col == 'related') { 
       $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $pk . "'" ); 
       $res_ids = $res_names = array(); 
        
       if (empty($value)) { 
          $value = array(); 
       } 
        
       foreach ($value as $rel_id) { 
          $rel_id = (int) $rel_id; 
          if ((int) $rel_id) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . "product_related (product_id, related_id) VALUES (" . (int) $pk . ", " . (int) $rel_id . ")"); 
            $prod = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE language_id=" . $this->config->get('config_language_id') . " AND product_id = '" . (int) $rel_id . "'")->row; 
            $res_ids[] = $prod['product_id']; 
            $res_names[] = $prod['name']; 
          } 
      } 
       
      header('Content-Type: application/json'); 
       
      echo json_encode( 
        //array('status' => 'success-related', 'val' => implode(',', $res_ids), 'msg' => implode(', ', $res_names), 'pk' => $pk) 
        array('status' => 'success', 'pk' => $pk, 'msg' => implode(', ', $res_names)) 
      ); 
       
      exit; 
    } 
     
    $primaryKey = $type . '_id'; 
     
    if (in_array($type, array('common', 'special'))) { 
      $primaryKey = $this->url_alias.'_id'; 
    } else if ($type == 'redirect') { 
      $primaryKey = 'url_redirect_id'; 
    } else if ($type == 'absolute') { 
      $primaryKey = 'url_absolute_id'; 
    } else if ($type == 'autolink') { 
      $primaryKey = 'url_autolink_id'; 
    } 
     
    // update products, categories or informations 
    if (in_array($type, array('product', 'category', 'information', 'manufacturer', 'common', 'special', 'redirect', 'absolute', 'autolink'))) { 
      if (in_array($type, array('common', 'special'))) { 
        // delete route if set by user 
        str_replace('route=', '', $value); 
        // insert it if necessary 
        $route = ($type == 'common' && $col == 'query') ? 'route=' : ''; 
         
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET " . $col . " = '" . $this->db->escape($route.$value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'"); 
      } else if ($type == 'redirect') { 
        $this->db->query("UPDATE " . DB_PREFIX . "url_redirect SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'"); 
      } else if ($type == 'autolink') { 
        $this->db->query("UPDATE " . DB_PREFIX . "url_autolink SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'"); 
      } else if ($type == 'absolute') { 
        $value = ltrim($value, '/'); 
        $value = str_replace(array('route=', 'index.php?route='), '', $value); 
        $this->db->query("UPDATE " . DB_PREFIX . "url_absolute SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'"); 
      } 
       
      if ($col == 'seo_keyword') { 
        $this->load->model(self::$EXT_PATH.'tool/seo_package'); 
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, $type, $pk, $lang); 
         
        if ($this->config->get('mlseo_backup')) { 
          if (version_compare(VERSION, '4', '>=')) { 
            if ($primaryKey == 'category_id') { 
              $primaryKey = 'path'; 
            } 
             
            $currentKeywordsQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $primaryKey . "' AND `value` = '" . (int)$pk . "'")->rows; 
          } else { 
            $currentKeywordsQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "'")->rows; 
          } 
           
          $currentKeywords = array(); 
           
          foreach ($currentKeywordsQuery as $curKeyword) { 
            $currentKeywords[(isset($curKeyword['store_id']) ? $curKeyword['store_id'] : 0)][(isset($curKeyword['language_id']) ? $curKeyword['language_id'] : $this->config->get('config_language_id'))] = $curKeyword['keyword']; 
          } 
           
          $currentKeyword = isset($currentKeywords[$store_id][$lang]) ? $currentKeywords[$store_id][$lang] : ''; 
           
          if ($currentKeyword && $currentKeyword != $value) { 
            if ($type == 'product') { 
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/product&product_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'"); 
            } else if ($type == 'category') { 
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/category&category_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'"); 
            } else if ($type == 'information') { 
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'information/information&information_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'"); 
            } else if ($type == 'manufacturer') { 
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/manufacturer&manufacturer_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'"); 
            } 
          } 
        } 
         
        // manufacturer has no multilingual keyword 
        if (version_compare(VERSION, '4', '>=')) { 
          if ($type == 'category') { 
            if (version_compare(VERSION, '4', '>=')) { 
              $this->load->model('extension/complete_seo/catalog/seo_package'); 
              $modelSeoPackage = $this->model_extension_complete_seo_catalog_seo_package; 
            } else { 
              $this->load->model('catalog/seo_package'); 
              $modelSeoPackage = $this->model_catalog_seo_package; 
            } 
             
            $modelSeoPackage->setCategorySeoV4($pk, $value, $lang, $store_id); 
          } else { 
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $primaryKey . "' AND `value` = '" . (int)$pk . "' AND store_id = " . (int)$store_id . " AND language_id IN (".(int) $lang.", 0)"); 
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = '" . $primaryKey . "', `value` = '" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "', store_id = '" . (int)$store_id . "'"); 
          } 
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND store_id = " . (int)$store_id . " AND language_id IN (".(int) $lang.", 0)"); 
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "', store_id = '" . (int)$store_id . "'"); 
        } else if ($this->multistore_mode) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND store_id = " . (int)$store_id); 
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$store_id . "'"); 
        } else if ($this->ml_mode) { 
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND language_id IN (".(int) $lang.", 0)"); 
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "'"); 
        } else { 
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "'"); 
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "'"); 
        } 
      } else if (in_array($type, array('product', 'category', 'information', 'manufacturer'))) { 
        $seoDesc = ($store_id || $type == 'manufacturer') ? 'seo_' : ''; 
        $extraWhere = $seoDesc ? " AND store_id = '" . (int)$store_id . "'" : ''; 
         
        // insert seo desc table if not exists 
        if ($seoDesc) { 
          $hasSeoDesc = $this->db->query("SELECT * FROM " . DB_PREFIX . $seoDesc . $type . "_description WHERE " . $primaryKey . " = '" . (int)$pk . "' AND language_id = '" . (int)$lang . "'" . $extraWhere)->row; 
           
          if(!$hasSeoDesc) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . $seoDesc . $type . "_description SET " . $primaryKey . " = '" . (int)$pk . "', store_id = '" . (int)$store_id . "', language_id = '" . (int)$lang . "'"); 
          } 
        } 
         
        // update the value 
        $this->db->query("UPDATE " . DB_PREFIX . $seoDesc . $type . "_description SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "' AND language_id = '" . (int)$lang . "'" . $extraWhere); 
      } 
       
      header('Content-Type: application/json'); 
       
      echo json_encode( 
        array('status' => 'success', 'msg' => $value) 
      ); 
      exit; 
    } 
  } 
   
  public function editor_add_alias() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) return; 
     
    $type = $this->request->get['type']; 
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
    $query = $_GET['query']; 
    $keyword = $_GET['keyword']; 
     
    $table = 'url_alias'; 
     
    if ($type == 'common') { 
      $query = 'route=' . str_replace('route=', '', $query); 
    } else if ($type == 'absolute') { 
      $query = ltrim($query, '/'); 
      $query = str_replace(array('route=', 'index.php?route='), '', $query); 
    } 
     
    if ($type == 'redirect' || $type == '404') { 
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_redirect SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'"); 
    } else if ($type == 'autolink') { 
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_autolink SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'"); 
    } else if ($type == 'absolute') { 
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_absolute SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'"); 
    } else { 
      $storeData = ''; 
       
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) { 
        $storeData = ", store_id = '".(int) $store."'"; 
      } 
       
      if (version_compare(VERSION, '4', '>=')) { 
        list($queryKey, $queryVal) = explode('=', $query); 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = '" . $this->db->escape($queryKey) . "', `value` = '" . $this->db->escape($queryVal) . "', keyword = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'" . $storeData); 
      } else if ($this->ml_mode) { 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $this->db->escape($query) . "', keyword = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'" . $storeData); 
      } else { 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $this->db->escape($query) . "', keyword = '" . $this->db->escape($keyword) . "'" . $storeData); 
      } 
    } 
     
  } 
   
  public function editor_delete_alias() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) return; 
     
    $type = $this->request->get['type']; 
    $alias_id = $this->request->get['pk']; 
     
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
     
    if ($type == '404') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_404 WHERE url_404_id =  '". (int) $alias_id . "'"); 
    } else if ($type == 'redirect') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_redirect WHERE url_redirect_id =  '". (int) $alias_id . "'"); 
    } else if ($type == 'autolink') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_autolink WHERE url_autolink_id =  '". (int) $alias_id . "'"); 
    } else if ($type == 'absolute') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_absolute WHERE url_absolute_id =  '". (int) $alias_id . "'"); 
    } else { 
      $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE ".$this->url_alias."_id =  '". (int) $alias_id . "'"); 
    } 
  } 
   
  public function editor_delete_aliases() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) return; 
     
    $type = $this->request->get['type']; 
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
     
    if ($type == 'common') { 
      $extra_where = "query LIKE 'route=%'"; 
    } elseif ($type == 'special') { 
      $extra_where = "query NOT LIKE 'route=%' 
                   AND query NOT LIKE 'product_id=%' 
                   AND query NOT LIKE 'category_id=%' 
                   AND query NOT LIKE 'information_id=%' 
                   AND query NOT LIKE 'manufacturer_id=%'"; 
    } 
     
    if ($type == '404') { 
      if (!empty($this->request->get['redir_only'])) { 
        $this->db->query("DELETE u FROM " . DB_PREFIX . "url_404 u LEFT JOIN " . DB_PREFIX . "url_redirect r ON (u.query = r.query OR REPLACE(u.query, '".HTTP_CATALOG."', '/') = r.query) WHERE r.query IS NOT NULL"); 
      } else { 
        $this->db->query("DELETE FROM " . DB_PREFIX . "url_404"); 
      } 
    } else if ($type == 'redirect') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_redirect"); 
    } else if ($type == 'autolink') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_autolink"); 
    } else if ($type == 'absolute') { 
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_absolute"); 
    } else { 
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) { 
        $extra_where .= " AND store_id = '".(int) $store."'"; 
      } 
       
      if ($this->ml_mode) { 
        $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where . " AND language_id = '" . (int) $lang . "'"); 
      } else { 
        $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where); 
      } 
    } 
  } 
 
  public function editor_restore_aliases() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) return; 
     
    $this->load->model(self::$EXT_PATH.'setting/friendlyurls'); 
    $this->load->model('localisation/language'); 
     
    $lang_code = $this->request->get['lang_code']; 
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0; 
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0; 
     
    $languages = $this->model_localisation_language->getLanguages(); 
     
    $langs = array(); 
    foreach ($languages as $language) { 
      $langs[$language['language_id']] = $language['code']; 
    } 
     
    $this->editor_delete_aliases(); 
     
    $default_urls = version_compare(VERSION, '4', '>=') ? $this->model_extension_complete_seo_setting_friendlyurls->getFriendlyUrls($lang_code) : $this->model_setting_friendlyurls->getFriendlyUrls($lang_code); 
     
    if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) { 
      $storeData = ", store_id = '".(int) $store."'"; 
    } 
       
    foreach ($default_urls as $query => $keyword) { 
      if ($this->config->get('mlseo_ascii_'.$lang)) { 
        include_once(DIR_SYSTEM . 'library/gkd_urlify.php'); 
        if (function_exists('mb_substr')) { 
          $keyword = URLify::downcode($keyword, mb_substr($lang_code, 0, 2)); 
        } else { 
          $keyword = URLify::downcode($keyword, substr($lang_code, 0, 2)); 
        } 
      } 
       
      if (version_compare(VERSION, '4', '>=')) { 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'route', `value` = '" . $query . "', keyword = '" . $keyword . "', language_id = '" . (int) $lang . "'" . $storeData); 
      } else if ($this->ml_mode) { 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'route=" . $query . "', keyword = '" . $keyword . "', language_id = '" . (int) $lang . "'" . $storeData); 
      } else { 
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'route=" . $query . "', keyword = '" . $keyword . "'" . $storeData); 
      } 
    } 
  } 
   
  public function editor_export_aliases() { 
    $type = $this->request->get['type']; 
    $lang = $this->request->get['lang']; 
    $lang_code = $this->request->get['lang_code']; 
     
    header("Content-type: text/plain"); 
    header("Content-Disposition: attachment; filename=friendly_export.txt"); 
 
    echo "You translated friendly urls and want to integrate them in official package?" . PHP_EOL . "Please send this file to [email protected]" . PHP_EOL . PHP_EOL; 
    echo "Language : " . $lang_code . PHP_EOL . PHP_EOL; 
      
    if ($type == 'common') { 
      $extra_where = "query LIKE 'route=%'"; 
    } elseif ($type == 'special') { 
      $extra_where = "query NOT LIKE 'route=%' 
                   AND query NOT LIKE 'product_id=%' 
                   AND query NOT LIKE 'category_id=%' 
                   AND query NOT LIKE 'information_id=%' 
                   AND query NOT LIKE 'manufacturer_id=%'"; 
    } else { 
      exit(); 
    } 
     
    if ($this->ml_mode) { 
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where . " AND language_id = '" . (int) $lang . "'"); 
    } else { 
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where); 
    } 
     
    foreach($query->rows as $row) { 
      echo "'".str_replace('route=', '', $row['query'])."' => '".$row['keyword']."',". PHP_EOL; 
    } 
     
    exit(); 
  } 
   
  /*complete>*/ 
   
   public function modal_related() { 
    $id = $this->request->post['id']; 
        
    $related = $this->db->query("SELECT pr.related_id, pd.name FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product_description pd ON pd.product_id = pr.related_id WHERE pr.product_id=" . (int) $id . " AND pd.language_id=" . $this->config->get('config_language_id'))->rows; 
        
    echo '<div class="modal-dialog"> 
      <div class="modal-content"> 
        <div class="modal-header"> 
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
          <h4 class="modal-title">' . $this->language->get('text_seo_mode_related') . '</h4> 
        </div> 
        <div class="modal-body"> 
          <select class="related-select" multiple="multiple">'; 
     
    foreach ($related as $rel) { 
      echo '<option value="' . $rel['related_id'] . '">' . $rel['name'] . '</option>'; 
    } 
     
    echo '</select> 
<script type="text/javascript"> 
  $("select.related-select").select2({ 
     
  }); 
</script> 
        </div> 
      </div> 
    </div>'; 
     
    die; 
  } 
   
  public function product_search() { 
    if (!isset($this->request->get['q'])) { 
      header('Content-Type: application/json'); 
      echo json_encode(array('results')); 
      exit; 
    } 
     
    $q = $this->request->get['q']; 
      
    $json = array('results'); 
     
    $products = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE name LIKE '" . $this->db->escape($q) . "%' AND language_id=" . $this->config->get('config_language_id') . " LIMIT 30")->rows;  
     
    if (!$products) { 
      $products = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE name LIKE '%" . $this->db->escape($q) . "%' AND language_id=" . $this->config->get('config_language_id') . " LIMIT 30")->rows; 
    } 
     
    foreach ($products as $product) { 
      $json['results'][] = array( 
        'id' => $product['product_id'], 
        'text' => htmlspecialchars_decode($product['name']), 
      ); 
    } 
     
    header('Content-Type: application/json'); 
    echo json_encode($json); 
     
    exit; 
   } 
    
   public function modal_info() { 
    $item = $this->request->post['info']; 
     
    $extra_class = $this->language->get('info_css_' . $item) != 'info_css_' . $item ? $this->language->get('info_css_' . $item) : 'modal-lg'; 
    $title = $this->language->get('info_title_' . $item) != 'info_title_' . $item ? $this->language->get('info_title_' . $item) : $this->language->get('info_title_default'); 
    $message = $this->language->get('info_msg_' . $item) != 'info_msg_' . $item? $this->language->get('info_msg_' . $item) : $this->language->get('info_msg_default'); 
     
    echo '<div class="modal-dialog ' . $extra_class . '"> 
      <div class="modal-content"> 
        <div class="modal-header"> 
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
          <h4 class="modal-title"><i class="fa fa-info-circle"></i> ' . $title . '</h4> 
        </div> 
        <div class="modal-body">' . $message . '</div> 
      </div> 
    </div>'; 
     
    die; 
  } 
   
  public function install($redir = false) { 
    if ($this->config->get('mlseo_enabled')) return; 
     
    if (version_compare(VERSION, '3', '<') && is_dir(DIR_APPLICATION.'controller/extension/module')) { 
      //@rename(DIR_APPLICATION.'controller/extension/module', DIR_APPLICATION.'controller/extension/.seo_package'); 
    } 
     
    // rights 
    /* 
    $this->load->model('user/user_group'); 
 
    if (!$this->user->hasPermission('modify', self::$LINK)) { 
      $this->model_user_user_group->addPermission(version_compare(VERSION, '2.0.2', '>=') ? $this->user->getGroupId() : 1, 'access', 'module/' . self::MODULE); 
      $this->model_user_user_group->addPermission(version_compare(VERSION, '2.0.2', '>=') ? $this->user->getGroupId() : 1, 'modify', 'module/' . self::MODULE); 
    } 
    */ 
     
    // check tables 
    $this->db_tables(); 
     
    $this->load->model('localisation/language'); 
    $languages = array(); 
    $results = $this->model_localisation_language->getLanguages(); 
     
    foreach ($results as $result) { 
      $languages[$result['code']] = $result; 
    } 
 
    // set old keywords to all languages 
    /* 
    if (count($languages) > 1) { 
      $keywords = $this->db->query("SELECT * FROM `" . DB_PREFIX . $this->url_alias . "`")->rows; 
      foreach ($languages as $language) { 
        foreach ($keywords as $row) { 
          if (strpos($row['query'], '=') !== false) { 
            list($type, $id) = explode('=', $row['query']); 
            $type = str_replace('_id', '', $type); 
            if (in_array($type, array('product', 'category', 'information'))) { 
              $this->db->query("UPDATE " . DB_PREFIX . $type . "_description SET seo_keyword = '" . $row['keyword'] . "' WHERE  " . $type . "_id = '" . $id . "' AND language_id = '" . $language['language_id'] . "'"); 
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $row['query'] . "', keyword = '" . $row['keyword'] . "', language_id = '" . $language['language_id'] . "'"); 
            } 
          } 
        } 
      } 
 
      $this->db->query("DELETE FROM `" . DB_PREFIX . $this->url_alias . "` WHERE language_id = 0 AND (query LIKE 'product_id=%' OR query LIKE 'category_id=%' OR query LIKE 'information_id=%')"); 
    } 
    */ 
 
    // Friendly urls 
    /* @todo 
    $this->load->model('localisation/language'); 
    $this->load->model('setting/friendlyurls'); 
    $languages = $this->model_localisation_language->getLanguages(); 
    $friendly_urls = array(); 
    foreach($languages as $language) 
    { 
      $friendly_urls['mlseo_urls_'.$language['code']] = $this->model_setting_friendlyurls->getFriendlyUrls($language['code']); 
    } 
    */ 
     
    $this->load->model('setting/setting'); 
    $this->model_setting_setting->editSetting('mlseo', array( 
        'mlseo_whitespace' => '-', 
        'mlseo_extension' => '', 
        'mlseo_hreflang' => true, 
        'mlseo_friendly' => true, 
        //'mlseo_absolute' => true, 
        'mlseo_lowercase' => true, 
        'mlseo_duplicate' => true, 
        'mlseo_canonical' => true, 
        'mlseo_pagination_fix' => true, 
        'mlseo_default_lang' => $this->config->get('config_language'), 
        'mlseo_insertautotitle' => true, 
        'mlseo_insertautourl' => true, 
        'mlseo_editautourl' => true, 
        'mlseo_insertautometakeyword' => true, 
        'mlseo_editautometakeyword' => true, 
        'mlseo_insertautoseotitle' => true, 
        'mlseo_editautoseotitle' => true, 
        'mlseo_insertautometadesc' => true, 
        'mlseo_editautometadesc' => true, 
        //'mlseo_banners' => true, 
        'mlseo_safe_url' => 'ext', 
        'mlseo_product_url_pattern' => '[name]', 
        'mlseo_product_h1_pattern' => '[name]', 
        'mlseo_product_h2_pattern' => '[name]', 
        'mlseo_product_h3_pattern' => '[name]', 
        'mlseo_product_image_alt_pattern' => '[name]', 
        'mlseo_product_image_title_pattern' => '[name]', 
        'mlseo_product_image_name_pattern' => '[name]', 
        'mlseo_product_title_pattern' => '[name] - [model]', 
        'mlseo_product_keyword_pattern' => '[name], [model], [category]', 
        'mlseo_product_description_pattern' => '[name] - [model] - [category] - [desc]', 
        'mlseo_product_full_desc_pattern' => '[name] - [model] - [category]', 
        'mlseo_product_tag_pattern' => '[name], [model], [category]', 
        'mlseo_category_url_pattern' => '[name]', 
        'mlseo_category_h1_pattern' => '[name]', 
        'mlseo_category_h2_pattern' => '[name]', 
        'mlseo_category_h3_pattern' => '[name]', 
        'mlseo_category_title_pattern' => '[name]', 
        'mlseo_category_keyword_pattern' => '[name], [desc]', 
        'mlseo_category_description_pattern' => '[name] - [desc]', 
        'mlseo_category_full_desc_pattern' => '[name]', 
        'mlseo_information_url_pattern' => '[name]', 
        'mlseo_information_h1_pattern' => '[name]', 
        'mlseo_information_h2_pattern' => '[name]', 
        'mlseo_information_h3_pattern' => '[name]', 
        'mlseo_information_title_pattern' => '[name]', 
        'mlseo_information_keyword_pattern' => '[name] [desc]', 
        'mlseo_information_description_pattern' => '[name] - [desc]', 
        'mlseo_information_full_desc_pattern' => '[name]', 
        'mlseo_manufacturer_url_pattern' => '[name]', 
        'mlseo_manufacturer_h1_pattern' => '[name]', 
        'mlseo_manufacturer_h2_pattern' => '[name]', 
        'mlseo_manufacturer_h3_pattern' => '[name]', 
        'mlseo_manufacturer_title_pattern' => '[name]', 
        'mlseo_product_related_relevance' => 5, 
        'mlseo_product_related_no' => 5, 
        'mlseo_microdata_data' => array('model' => 1, 'desc' => 1, 'brand' => 1, 'reviews' => 1, 'product' => 1, 'organization' => 1, 'store' => 1, 'website' => 1, 'breadcrumbs' => 1, 'organization_search' => 1, 'store_logo' => 1, 'store_mail' => 1, 'website_search' => 1), 
        'mlseo_tcard_data' => array('desc' => 1), 
        'mlseo_opengraph_data' => array('desc' => 1), 
      )); 
       
    if (is_writable(DIR_CATALOG.'../index.php')) { 
      $index = file_get_contents(DIR_CATALOG.'../index.php'); 
      if (strpos($index, 'new multilingual_seo') === false && strpos($index, '$languages = array();') !== false) { 
        $index = str_replace('$languages = array();', '$languages = array();'."\n".'$multilingual = new multilingual_seo($registry); $multilingual->detect();', $index); 
        file_put_contents(DIR_CATALOG.'../index.php', $index); 
      } 
    } 
     
    if ($redir || !empty($this->request->get['redir'])) { 
      if (version_compare(VERSION, '2', '>=')) { 
				$this->response->redirect($this->url->link('module/'.self::MODULE, $this->token, 'SSL')); 
			} else { 
				$this->redirect($this->url->link('module/'.self::MODULE, $this->token, 'SSL')); 
			} 
    } 
  } 
   
  private function log($msg = '', $mode = 'all') { 
    if ($this->config->get('mlseo_cron_log') == 'off') return; 
    if ($this->config->get('mlseo_cron_log') == 'report' && $mode != 'report') return; 
     
    $log = DIR_LOGS.'seo_package_cli.log'; 
    $txt = $msg . PHP_EOL; 
    file_put_contents($log, $txt, FILE_APPEND | LOCK_EX); 
  } 
   
  public function uninstall() { 
  /* 
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` DROP `seo_keyword`"); 
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `seo_keyword`"); 
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` DROP `seo_keyword`"); 
    if (!$this->OC_V2) { 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` DROP `meta_title`"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_title`"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_description'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_description`"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_keyword'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_keyword`"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` DROP `meta_title`"); 
    } 
    */ 
    //$default_lang = $this->db->query("SELECT language_id FROM " . DB_PREFIX . "language WHERE code = '" . $this->config->get('config_language') . "'")->row['language_id']; 
    $default_lang = $this->config->get('config_language_id'); 
     
    if (version_compare(VERSION, '3', '<')) { 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row) { 
        $this->db->query("DELETE FROM `" . DB_PREFIX . $this->url_alias . "` WHERE language_id <> " . $default_lang . " AND language_id <> 0"); 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` DROP `language_id`"); 
      } 
    } 
     
    if (version_compare(VERSION, '2.2', '<')) { 
      $index = file_get_contents(DIR_CATALOG.'../index.php'); 
      $index = str_replace('$multilingual = new multilingual_seo($registry); $multilingual->detect();', '', $index); 
      file_put_contents(DIR_CATALOG.'../index.php', $index); 
    } 
  } 
   
  private function validate() { 
    if (!$this->user->hasPermission('modify', self::$LINK)) { 
      $this->error['error'] = $this->language->get('error_permission'); 
    } 
     
    if (!$this->error) 
      return true; 
    return false; 
  } 
   
  private function db_tables() { 
    $this->load->model('localisation/language'); 
    $languages = $this->model_localisation_language->getLanguages(); 
       
    // check DB columns 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product` LIKE 'meta_robots'")->row) { 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` CHANGE `date_available` `date_available` DATE NULL"); // fix incorrect default value on some sql version 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` ADD `meta_robots` VARCHAR(40) NOT NULL"); 
    } 
    if (!$this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "category LIKE 'meta_robots'")->row) { 
      $this->db->query("ALTER TABLE " . DB_PREFIX . "category ADD meta_robots VARCHAR(40) NOT NULL"); 
    } 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information` LIKE 'meta_robots'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information` ADD `meta_robots` VARCHAR(40) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product` LIKE 'seo_canonical'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` ADD `seo_canonical` VARCHAR(32) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_keyword` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h1'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h1` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h2'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h2` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h3'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h3` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'image_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `image_title` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'image_alt'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `image_alt` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_keyword` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_keyword'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_keyword` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h1'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h1` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h2'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h2` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h3'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h3` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h1'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h1` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h2'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h2` VARCHAR(255) NOT NULL"); 
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h3'")->row) 
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h3` VARCHAR(255) NOT NULL"); 
    if (!version_compare(VERSION, '2', '>=')) { 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL"); 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL"); 
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `meta_title` VARCHAR(255) NOT NULL"); 
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_title` VARCHAR(255) NOT NULL"); 
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_description'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_description` VARCHAR(255) NOT NULL"); 
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_keyword'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_keyword` VARCHAR(255) NOT NULL"); 
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `meta_title` VARCHAR(255) NOT NULL"); 
    } 
     
    if (version_compare(VERSION, '3', '<')) { 
      if (count($languages) > 1) { 
        if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row) 
          $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` ADD `language_id` INT(11) NOT NULL DEFAULT '0'"); 
         
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET language_id = ".(int) $this->config->get('config_language_id')." WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0"); 
      } 
    } 
     
    try { 
      if (!$this->db->query("SHOW INDEX FROM " . DB_PREFIX . "product_description WHERE Key_name='related_generator'")->row) 
        $this->db->query("CREATE FULLTEXT INDEX related_generator ON " . DB_PREFIX . "product_description (name, description)"); 
    } catch (Exception $e) {} 
     
    if ($this->config->get('mlseo_multistore')) { 
       if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'store_id'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` ADD `store_id` INT(11) NOT NULL DEFAULT '0'"); 
       
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_product_description` ( 
          `product_id` int(11) NOT NULL, 
          `language_id` int(11) NOT NULL DEFAULT 0, 
          `store_id` int(11) NOT NULL DEFAULT 0, 
          `name` varchar(255) NOT NULL DEFAULT '', 
          `description` text NOT NULL DEFAULT '', 
          `meta_title` varchar(255) NOT NULL DEFAULT '', 
          `meta_description` varchar(255) NOT NULL DEFAULT '', 
          `meta_keyword` varchar(255) NOT NULL DEFAULT '', 
          `image_title` varchar(255) NOT NULL DEFAULT '', 
          `image_alt` varchar(255) NOT NULL DEFAULT '', 
          `seo_h1` varchar(255) NOT NULL DEFAULT '', 
          `seo_h2` varchar(255) NOT NULL DEFAULT '', 
          `seo_h3` varchar(255) NOT NULL DEFAULT '', 
          PRIMARY KEY (`product_id`,`language_id`,`store_id`) 
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
         
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_category_description` ( 
          `category_id` int(11) NOT NULL, 
          `language_id` int(11) NOT NULL DEFAULT 0, 
          `store_id` int(11) NOT NULL DEFAULT 0, 
          `name` varchar(255) NOT NULL DEFAULT '', 
          `description` text NOT NULL DEFAULT '', 
          `meta_title` varchar(255) NOT NULL DEFAULT '', 
          `meta_description` varchar(255) NOT NULL DEFAULT '', 
          `meta_keyword` varchar(255) NOT NULL DEFAULT '', 
          `seo_h1` varchar(255) NOT NULL DEFAULT '', 
          `seo_h2` varchar(255) NOT NULL DEFAULT '', 
          `seo_h3` varchar(255) NOT NULL DEFAULT '', 
          PRIMARY KEY (`category_id`,`language_id`,`store_id`) 
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
       
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_information_description` ( 
          `information_id` int(11) NOT NULL, 
          `language_id` int(11) NOT NULL DEFAULT 0, 
          `store_id` int(11) NOT NULL DEFAULT 0, 
          `name` varchar(255) NOT NULL DEFAULT '', 
          `description` text NOT NULL DEFAULT '', 
          `meta_title` varchar(255) NOT NULL DEFAULT '', 
          `meta_description` varchar(255) NOT NULL DEFAULT '', 
          `meta_keyword` varchar(255) NOT NULL DEFAULT '', 
          `seo_h1` varchar(255) NOT NULL DEFAULT '', 
          `seo_h2` varchar(255) NOT NULL DEFAULT '', 
          `seo_h3` varchar(255) NOT NULL DEFAULT '', 
          PRIMARY KEY (`information_id`,`language_id`,`store_id`) 
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
      } 
     
    if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_manufacturer_description'")->row) { 
      if (!$this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "seo_manufacturer_description LIKE 'store_id'")->row) { 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_manufacturer_description` RENAME TO " . DB_PREFIX . "seo_manufacturer_description_old"); 
         
        $transferManufacturerData = true; 
      } 
    } 
         
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_manufacturer_description` ( 
        `manufacturer_id` int(11) NOT NULL, 
        `language_id` int(11) NOT NULL DEFAULT 0, 
        `store_id` int(11) NOT NULL DEFAULT 0, 
        `name` varchar(255) NOT NULL DEFAULT '', 
        `description` text NOT NULL DEFAULT '', 
        `meta_title` varchar(255) NOT NULL DEFAULT '', 
        `meta_description` varchar(255) NOT NULL DEFAULT '', 
        `meta_keyword` varchar(255) NOT NULL DEFAULT '', 
        `seo_h1` varchar(255) NOT NULL DEFAULT '', 
        `seo_h2` varchar(255) NOT NULL DEFAULT '', 
        `seo_h3` varchar(255) NOT NULL DEFAULT '', 
        PRIMARY KEY (`manufacturer_id`,`language_id`,`store_id`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
     
    if (!empty($transferManufacturerData)) { 
      $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description (manufacturer_id, language_id, store_id, name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3) 
                              SELECT md.manufacturer_id, md.language_id, '0', '', md.description, md.meta_title, md.meta_description, md.meta_keyword, '', '', '' FROM " . DB_PREFIX . "seo_manufacturer_description_old md"); 
    } 
     
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_absolute` ( 
        `url_absolute_id` int(11) NOT NULL AUTO_INCREMENT, 
        `query` varchar(1000) NOT NULL, 
        `redirect` varchar(1000) NOT NULL, 
        `language_id` int(3) NOT NULL DEFAULT '0', 
        PRIMARY KEY (`url_absolute_id`), 
        KEY `query` (`query`), 
        KEY `redirect` (`redirect`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
     
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_autolink` ( 
        `url_autolink_id` int(11) NOT NULL AUTO_INCREMENT, 
        `query` varchar(256) NOT NULL, 
        `redirect` varchar(1000) NOT NULL, 
        `language_id` int(3) NOT NULL DEFAULT '0', 
        PRIMARY KEY (`url_autolink_id`), 
        KEY `query` (`query`), 
        KEY `redirect` (`redirect`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
       
       
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_redirect` ( 
        `url_redirect_id` int(11) NOT NULL AUTO_INCREMENT, 
        `query` varchar(1000) NOT NULL, 
        `redirect` varchar(1000) NOT NULL, 
        `language_id` int(3) NOT NULL DEFAULT '0', 
        `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  
        PRIMARY KEY (`url_redirect_id`), 
        KEY `query` (`query`), 
        KEY `redirect` (`redirect`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
      
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_404` ( 
        `url_404_id` int(11) NOT NULL AUTO_INCREMENT, 
        `query` varchar(1000) NOT NULL, 
        `referer` varchar(1000) NOT NULL, 
        `count` int(11) NOT NULL DEFAULT '0', 
        `date_accessed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  
        PRIMARY KEY (`url_404_id`), 
        KEY `query` (`query`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 
       
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "url_404` LIKE 'referer'")->row) 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "url_404` ADD `referer` VARCHAR(1000) NOT NULL"); 
     
    foreach (array('product', 'category', 'information') as $type) { 
      $varchar = $this->db->query("SELECT CHARACTER_MAXIMUM_LENGTH AS length FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = '" . DB_PREFIX . $type . "_description' AND COLUMN_NAME = 'seo_keyword'")->row; 
      if ($varchar['length'] < 255) { 
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $type . "_description` MODIFY COLUMN `seo_keyword` VARCHAR(255) NOT NULL"); 
      } 
    } 
  } 
   
  public function report() { 
    set_time_limit(600); 
     
    echo '<h3>URL ALIAS report</h3>'; 
    echo '<table border="1" cellpadding="10" style="border-collapse:collapse;"><tr style="font-weight:bold">'; 
    echo '<td>query</td> 
          <td>keyword</td> 
          <td>Issue</td>'; 
 
     
    $urls = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '' ")->rows; 
     
    foreach($urls as $url) { 
       echo '<tr> 
          <td>'.$url['query'].'</td> 
          <td>'.$url['keyword'].'</td> 
          <td><span style="color:red">empty</span></td> 
          </tr>'; 
    } 
     
    $urls = $this->db->query("SELECT count(*) AS count, query, keyword FROM " . DB_PREFIX . $this->url_alias . " GROUP BY keyword ")->rows; 
     
    foreach($urls as $url) { 
      if ($url['keyword'] && $url['count']> 1) { 
        $duplicates = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."' ")->rows; 
        foreach($duplicates as $duplicate) { 
        echo '<tr> 
          <td>'.$duplicate['query'].'</td> 
          <td>'.$duplicate['keyword'].'</td> 
          <td>'.(!$duplicate['keyword'] ? '<span style="color:red">empty</span>' : '<span style="color:orange">duplicate</span>').'</td> 
          </tr>'; 
        } 
      } 
    } 
    die; 
  } 
   
  private function sortByName($a, $b) { 
    return strcmp($a['name'], $b['name']); 
  } 
   
  public function backup() { 
    header('Pragma: public'); 
    header('Expires: 0'); 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename="complete_seo_' . date('Y-m-d', time()) . '_backup.sql"'); 
    header('Content-Transfer-Encoding: binary'); 
     
    $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE code = 'mlseo'")->rows; 
     
    echo "DELETE FROM " . DB_PREFIX . "setting WHERE code = 'mlseo';\n\n"; 
     
    foreach ($rows as $row) { 
      echo "INSERT INTO " . DB_PREFIX . "setting (`store_id`, `code`, `key`, `value`, `serialized`) VALUES "; 
      echo "(".$row['store_id'].", 'mlseo', '".$row['key']."', '".$row['value']."', ".$row['serialized'].");\n"; 
    } 
     
    die; 
  } 
   
  public function upgrade() { 
    if (($this->request->server['REQUEST_METHOD'] == 'POST')) { 
      if (!$this->user->hasPermission('modify', self::$LINK)) { 
        die('Not allowed'); 
      } 
       
      $this->load->model('setting/setting'); 
       
      $data['info'] = array(); 
       
      $data['info'][] = 'SEO URLs correctly transferred'; 
       
      // Remove extension 
      if ($this->request->post['module'] == 'broken_link_manager') { 
        $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . "error")->rows; 
         
        foreach ($rows as $row) { 
          $this->db->query("INSERT INTO `" . DB_PREFIX . "url_redirect` SET `query` = '".$this->db->escape(urldecode($row['error']))."', `redirect` = '".$this->db->escape($row['redirect'])."'"); 
        } 
         
        goto end; 
      } 
       
      if (!empty($this->request->post['ext'])) { 
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET keyword = REPLACE(keyword, '".$this->db->escape($this->request->post['ext'])."', '')"); 
      } 
       
      // Copy image title and alt - Paladin 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'title_image'")->row) { 
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `image_title` = `title_image`"); 
      } 
       
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'alt_image'")->row) { 
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `image_alt` = `alt_image`"); 
      } 
       
      // Copy lang id of url alias table - All in one SEO 
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'lang'")->row) { 
        $this->db->query("UPDATE `" . DB_PREFIX . $this->url_alias . "` SET `language_id` = `lang`"); 
      } 
       
      // Pack pro 
      if ($this->request->post['module'] == 'seo_pack_pro') { 
        foreach (array('canonicals', 'clickfix', 'custom_alt_generator', 'custom_h1_generator', 'custom_h2_generator', 'autolinks', 'keywords_generator', 'mlseo', 'not_found_report', 'bot_report', 'redirect', 'rename_files', 'richsnippets', 'seoedit', 'seoeditor', 'seoimages', 'seopagination', 'seoreplacer', 'custom_title_generator', 'custom_imgtitle_generator', 'extendedseo', 'l', 'meta_description_generator', 'rp_generator', 'seopack', 'seoreport', 'table_edit_ajax', 'tag_generator') as $file) { 
          @rename(DIR_APPLICATION.'controller/extension/extension/'.$file.'.php', DIR_APPLICATION.'controller/extension/extension/'.$file.'.php.bak'); 
        } 
         
        $data['info'][] = 'Disabled unecessary seo pack pro files'; 
         
        $store_seo_title = $this->config->get('config_meta_title'); 
        $store_seo_desc = $this->config->get('config_meta_description'); 
        $store_seo_keyword = $this->config->get('config_meta_keyword'); 
         
        $settings = $this->model_setting_setting->getSetting('mlseo'); 
         
        foreach (array('0') as $store) { 
          if (is_array($store_seo_title)) { 
            foreach ($store_seo_title as $language => $value) { 
              $settings['mlseo_store'][$store.$language]['seo_title'] = $value; 
            } 
          } 
          if (is_array($store_seo_desc)) { 
            foreach ($store_seo_desc as $language => $value) { 
              $settings['mlseo_store'][$store.$language]['description'] = $value; 
            } 
          } 
          if (is_array($store_seo_keyword)) { 
            foreach ($store_seo_keyword as $language => $value) { 
              $settings['mlseo_store'][$store.$language]['keywords'] = $value; 
            } 
          } 
        } 
		 
        $this->model_setting_setting->editSetting('mlseo', $settings); 
         
        $data['info'][] = 'Store SEO correctly transferred'; 
         
        // Copy image title and alt 
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "product_description_seo'")->row) { 
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description_seo` LIKE 'custom_h1'")->row) { 
            $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . "product_description_seo` u SET d.image_title = u.custom_imgtitle, d.image_alt = u.custom_alt, d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.product_id = u.product_id AND d.language_id = u.language_id"); 
          } 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "category_description_seo'")->row) { 
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description_seo` LIKE 'custom_h1'")->row) { 
            $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . "category_description_seo` u SET d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.category_id = u.category_id AND d.language_id = u.language_id"); 
          } 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "information_description_seo'")->row) { 
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description_seo` LIKE 'custom_h1'")->row) { 
            $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . "information_description_seo` u SET d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.information_id = u.information_id AND d.language_id = u.language_id"); 
          } 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "url_redirect'")->row) { 
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "url_redirect` LIKE 'oldurl'")->row) { 
            $this->db->query("RENAME TABLE " . DB_PREFIX . "url_redirect TO " . DB_PREFIX . "url_redirect_seopackpro"); 
          } 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "manufacturer_description'")->row) { 
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "manufacturer_description` LIKE 'manufacturer_id'")->row) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description (manufacturer_id, language_id, store_id, name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3) 
                              SELECT md.manufacturer_id, md.language_id, '0', '', md.description, md.custom_title, md.meta_description, md.meta_keyword, '', '', '' FROM " . DB_PREFIX . "manufacturer_description md 
                              LEFT JOIN " . DB_PREFIX . "manufacturer_to_store ms ON (ms.manufacturer_id = md.manufacturer_id)"); 
          } 
        } 
         
        $data['info'][] = 'SEO img titles, img alt, H1, H2, manufacturers correctly transferred'; 
      } else if ($this->request->post['module'] == 'paladin') { 
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_title'")->row) { 
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `meta_title` = `seo_title`"); 
        } 
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_title'")->row) { 
          $this->db->query("UPDATE `" . DB_PREFIX . "category_description` SET `meta_title` = `seo_title`"); 
        } 
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_title'")->row) { 
          $this->db->query("UPDATE `" . DB_PREFIX . "information_description` SET `meta_title` = `seo_title`"); 
        } 
         
        $this->db->query("DELETE FROM `" . DB_PREFIX . "url_alias` WHERE query LIKE 'manufacturer_id=%' AND auto_gen = 'CPBI_urls'"); 
        $this->db->query("UPDATE `" . DB_PREFIX . "url_alias` SET language_id = 0 WHERE query LIKE 'manufacturer_id=%'"); 
        if (version_compare(VERSION, '4', '<')) { 
          $this->db->query("UPDATE `" . DB_PREFIX . "url_alias` SET query = CONCAT('route=', query) WHERE auto_gen = 'STAN_urls'"); 
        } 
         
      // iSense BackPack 
      } else if ($this->request->post['module'] == 'backpack') { 
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_manufacturer_description'")->row) { 
          $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_manufacturer_description` RENAME TO " . DB_PREFIX . "seo_manufacturer_description_isense"); 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_product_description'")->row) { 
          $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_product_description` RENAME TO " . DB_PREFIX . "seo_product_description_isense"); 
           
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . "seo_product_description_isense` u SET d.seo_h1 = u.h1, d.seo_h2 = u.h2 WHERE d.product_id = u.product_id AND d.language_id = u.language_id"); 
        } 
         
        if (version_compare(VERSION, '2.2', '>=')) { 
          $this->load->model("setting/event"); 
          $this->model_setting_event->deleteEventByCode('isenselabs_seo'); 
        } 
         
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_url_alias'")->row) { 
          $this->db->query("TRUNCATE `" . DB_PREFIX . $this->url_alias . "`"); 
          $this->db->query("INSERT INTO `" . DB_PREFIX . $this->url_alias . "` (query, keyword, language_id) SELECT query, keyword, language_id FROM `" . DB_PREFIX . "seo_url_alias`"); 
        } 
 
      // Mega Kit Plus 
      } else if ($this->request->post['module'] == 'mega_kit') { 
       if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'smp_language_id'")->row) { 
         $this->db->query("UPDATE `" . DB_PREFIX . $this->url_alias . "` SET language_id = smp_language_id"); 
          
         if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'smp_language_id'")->row) { 
           $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` DROP `smp_language_id`"); 
         } 
        } 
         
        $store_seo = $this->config->get('smp_meta_stores'); 
         
        $settings = $this->model_setting_setting->getSetting('mlseo'); 
         
        foreach ((array) $store_seo as $store) { 
          foreach ($store['title'] as $language => $value) { 
            $settings['mlseo_store'][$store.$language]['seo_title'] = $value; 
          } 
          foreach ($store['description'] as $language => $value) { 
            $settings['mlseo_store'][$store.$language]['description'] = $value; 
          } 
          foreach ($store['keywords'] as $language => $value) { 
            $settings['mlseo_store'][$store.$language]['keywords'] = $value; 
          } 
        } 
		 
        $this->model_setting_setting->editSetting('mlseo', $settings); 
         
        $data['info'][] = 'Store SEO correctly transferred'; 
         
        $this->db->query("INSERT INTO `" . DB_PREFIX . "url_redirect` (query, redirect) SELECT broken_link, new_link FROM `" . DB_PREFIX . "redirects_smp`"); 
         
        $data['info'][] = 'Redirections correctly transferred'; 
       
      // Webkul Advanced SEO 
      } else if ($this->request->post['module'] == 'webkul_advanced_seo') { 
        $this->db->query("INSERT INTO `" . DB_PREFIX . $this->url_alias . "` (query, keyword, language_id) SELECT CONCAT('route=', route), keyword, language_id FROM `" . DB_PREFIX . "wkseo_sef`"); 
         
      } 
       
      // Copy seo manufacturer data from other table 
      // INSERT INTO `oc_seo_manufacturer_description` (`manufacturer_id`, `language_id`, `description`, `meta_title`, `seo_h1`, `meta_description`, `meta_keyword`) SELECT manufacturer_id, language_id, description, meta_title, meta_h1, meta_description, meta_keyword FROM `oc_manufacturer_description` 
       
      // Copy keyword values to item tables - Common to all modules - copy first without language id to be sure to have it in case of not defined 
      /* no more useful, we don't use anymore seo_keyword in desc 
      $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '')"); 
      $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '')"); 
      $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '')"); 
       
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row) { 
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id"); 
        $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id"); 
        $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id"); 
      } 
      */ 
      /* SQL query for manual input 
      UPDATE oc_product_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', ''); 
      UPDATE oc_product_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id; 
      UPDATE oc_category_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', ''); 
      UPDATE oc_category_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id; 
      UPDATE oc_information_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', ''); 
      UPDATE oc_information_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id; 
      */ 
      /* now handled by previous requests in pure sql 
      $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE query LIKE 'information_id=%' OR query LIKE 'product_id=%' OR query LIKE 'category_id=%'")->rows; 
       
      foreach($rows as $row) { 
        list($field, $id) = explode('=', $row['query']); 
         
        $table = str_replace('_id', '', $field); 
         
        $this->db->query("UPDATE " . DB_PREFIX . $table . "_description SET seo_keyword = '" . $this->db->escape($row['keyword']) . "' WHERE " .$field ." = '".$id."'"); 
        //echo "UPDATE " . DB_PREFIX . $table . "_description SET seo_keyword = '" . $this->db->escape($row['keyword']) . "' WHERE " .$field ." = '".$id."'". "<br/>"; 
      } 
      */ 
      end: 
      $data['upgrade_complete'] = true; 
    } 
     
    $this->document->setTitle('SEO Package Upgrade Tool'); 
     
    $data['upgrade'] = true; 
     
    $data['action'] = $this->url->link(self::$LINK_SEP.'upgrade', $this->token, 'SSL'); 
    $data['cancel'] = $this->url->link(self::$LINK, $this->token, 'SSL'); 
     
    if (version_compare(VERSION, '2', '>=')) { 
      $data['header'] = $this->load->controller('common/header'); 
      $data['column_left'] = $this->load->controller('common/column_left'); 
      $data['footer'] = $this->load->controller('common/footer'); 
       
      if (version_compare(VERSION, '3', '>=')) { 
        $this->config->set('template_engine', 'template'); 
        $this->response->setOutput($this->load->view('module/complete_seo', $data)); 
      } else { 
        $this->response->setOutput($this->load->view('module/complete_seo.tpl', $data)); 
      } 
    } else { 
      $data['column_left'] = ''; 
      $this->data = &$data; 
      $this->template = 'module/complete_seo.tpl'; 
      $this->children = array( 
        'common/header', 
        'common/footer' 
      ); 
 
      // fix OC 1.5 
      $this->response->setOutput(str_replace(array('view/javascript/jquery/jquery-1.6.1.min.js', 'view/javascript/jquery/jquery-1.7.1.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'), self::$ASSET_PATH . 'jquery.min.js', $this->render())); 
    } 
     
  } 
   
  public function category_autocomplete() { 
		$json = array(); 
 
		if (isset($this->request->get['filter_name'])) { 
			$this->load->model('catalog/category'); 
 
			$filter_data = array( 
				'filter_name' => $this->request->get['filter_name'], 
				'sort'        => 'name', 
				'order'       => 'ASC', 
				'start'       => 0, 
				'limit'       => 20 
			); 
 
			$results = $this->model_catalog_category->getCategories($filter_data); 
 
			foreach ($results as $result) { 
				$json[] = array( 
					'category_id' => $result['category_id'], 
					'name'        => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) 
				); 
			} 
		} 
 
		$sort_order = array(); 
 
		foreach ($json as $key => $value) { 
			$sort_order[$key] = $value['name']; 
		} 
 
		array_multisort($sort_order, SORT_ASC, $json); 
 
		$this->response->addHeader('Content-Type: application/json'); 
		$this->response->setOutput(json_encode($json)); 
	} 
} 
//disable admin_save_and_keep_editing.xml ?>

Did this file decode correctly?

Original Code

<?php
/*
if (!defined('_JEXEC')) {
  register_shutdown_function('gkd_fatal_handler');
  set_error_handler('var_dump', 0);
}

function gkd_fatal_handler() {
  $error = error_get_last();
  
  if (!empty($error['type']) && $error['type'] == '1') {
    ob_end_clean();
    if ($error !== NULL) {
      echo 'Error: ' . $error['message'] . ' in ' . $error['file'] . ' on line '  . $error['line'];
    } else {
      echo 'Unknown fatal error';
    }
    
    if (!empty($_SESSION['seopackage_lastItem'])) {
      echo "\n".'Last item id: '.$_SESSION['seopackage_lastItem'];
    }
  }
}
*/

#custom_code#
class ControllerModuleCompleteSeo extends Controller {
  const MODULE = 'complete_seo';
  const PREFIX = 'mlseo';
  const MOD_FILE = 'seo_package';
  const LINK = 'module/complete_seo';
  const EXT_PATH = 'extension/complete_seo/';
  const OCID = 9486;
  
  static $EXT_PATH = '';
  static $MODEL_PATH = 'model_';
  static $LINK = 'module/complete_seo';
  static $LINK_SEP = 'module/complete_seo/';
  static $ASSET_PATH = 'view/seo_package/';
  
  private $error = array();
  private $OC_VERSION;
  private $OC_V2;
  private $OC_V21X;
  private $OC_V22X;
  private $OC_V23X;
  private $EXT_23X = '';
  private $OC_V151;
  private $ml_mode = false;
  private $multistore_mode = false;
  private $start;
  private $limit = 500;
  private $start_time;
  private $token;
  private $url_alias;
  private $front_url;
  private $total_items;
  private $store;
  private $edit_action = 'edit';
  
  public function __construct($registry) {
    ini_set('memory_limit', -1);
      $this->OC_VERSION = (int) str_replace('.', '', substr(VERSION, 0, 5));
      $this->OC_V2 = version_compare(VERSION, '2', '>=');
      $this->OC_V151 = (substr(VERSION, 0, 5) == '1.5.1');
      $this->OC_V21X = version_compare(VERSION, '2.1', '>=');
      $this->OC_V22X = version_compare(VERSION, '2.2', '>=');
      $this->OC_V23X = version_compare(VERSION, '2.3', '>=');
      
      if ($this->OC_V23X) {
        $this->EXT_23X = 'extension/';
      }
      
      if (!version_compare(VERSION, '2', '>=')) {
        $this->edit_action = 'update';
      }
      
    parent::__construct($registry);
    
      if (!defined('SEO_PACKAGE_CLI')) {
        $this->token = isset($this->session->data['user_token']) ? 'user_token='.$this->session->data['user_token'] : 'token='.$this->session->data['token'];
      }
      
      if (version_compare(VERSION, '3', '>=')) {
        $this->url_alias = 'seo_url';
      } else {
        $this->url_alias = 'url_alias';
      }
    
    if ($this->config->get('mlseo_ml_mode')) {
      $this->ml_mode = true;
    }
    
    if ($this->config->get('mlseo_multistore')) {
      $this->multistore_mode = true;
    }
    
    // front url handler
    if (version_compare(VERSION, '4', '>=')) {
      $this->front_url = new \Opencart\System\Library\Url($this->config->get('site_url'));
      
      defined('HTTP_CATALOG') ?: define('HTTP_CATALOG', $this->config->get('site_url'));
      defined('HTTPS_CATALOG') ?: define('HTTPS_CATALOG', $this->config->get('site_url'));
      
      self::$LINK = self::EXT_PATH.self::$LINK;
      self::$LINK_SEP = self::$LINK . (version_compare(VERSION, '4', '<') ? '/' : '|');
      self::$EXT_PATH = 'extension/'.self::MODULE.'/';
      self::$MODEL_PATH = 'model_extension_'.self::MODULE.'_';
      self::$ASSET_PATH = '../extension/'.self::MODULE.'/admin/'.self::$ASSET_PATH;
    } else {
      $this->front_url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG);
    }
    
    if ($this->config->get('config_seo_url')) {
      if (version_compare(VERSION, '2.2', '>=')) {
        $seourl_file = DIR_SYSTEM.'../catalog/controller/startup/seo_url.php';
      } else {
        $seourl_file = DIR_SYSTEM.'../catalog/controller/common/seo_url.php';
      }
      
      if (isset($vqmod)) {
        require_once($vqmod->modCheck($seourl_file));
      } else if (class_exists('VQMod') && function_exists('modification')) {
        require_once(VQMod::modCheck(modification($seourl_file), $seourl_file));
      } else if (function_exists('modification')) {
        require_once(modification($seourl_file));
      } else if (class_exists('VQMod')) {
        require_once(\VQMod::modCheck($seourl_file));
      } else {
        require_once($seourl_file);
      }
      
      if (version_compare(VERSION, '4', '>=')) {
        $rewriter = new \Opencart\Catalog\Controller\Startup\SeoUrl($this->registry);
      } else if (version_compare(VERSION, '2.2', '>=')) {
        $rewriter = new ControllerStartupSeoUrl($this->registry);
      } else {
        $rewriter = new ControllerCommonSeoUrl($this->registry);
      }
      
      $this->front_url->addRewrite($rewriter);
    }
    
    if (version_compare(VERSION, '3', '>=') && version_compare(VERSION, '4', '<')) {
      $this->load->language('extension/'.self::$LINK);
    } else {
      $this->load->language(self::$LINK);
    }
  }

  public function save() {
    $isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
    
		$json = [];

		if (!$this->user->hasPermission('modify', self::$LINK)) {
			$json['error']['warning'] = $this->language->get('error_permission');
		}

		if (!$json) {
			$this->load->model('setting/setting');
			
      $this->load->model('localisation/language');
      $languages = $this->model_localisation_language->getLanguages();
      
      $current_lang_codes = array();
      $current_code2id = array();
    
      foreach ($languages as $k => $language) {
        if ($language['status']) {
          $current_lang_codes[$language['language_id']] = $language['code'];
          $langaugeCodeToId[$language['code']] = $language['language_id'];
        }
      }
    
      // define multilingual handler
      $this->load->model('setting/store');
    
      $data['stores'] = array();
      $data['stores'][] = array(
        'store_id' => 0,
        'name'     => $this->config->get('config_name')
      );

      $stores = $this->model_setting_store->getStores();

      foreach ($stores as $store) {
        $action = array();

        $data['stores'][] = array(
          'store_id' => $store['store_id'],
          'name'     => $store['name']
        );
      }
      
      $store_id = 0;
      
      if (isset($this->request->get['store_id']) && $this->request->get['store_id']) {
        $data['store_id'] = $store_id = (int) $this->request->get['store_id'];
      }
      
      $redirect_store = '';
    
      if ($store_id) {
        $redirect_store = '&store_id=' . $store_id;
      }
      
      $lang_to_store = array();
    
      foreach ($data['stores'] as $store) {
        $store_info = $this->model_setting_setting->getSetting('config', $store['store_id']);
        
        if (!empty($store_info['config_language'])) {
          $lang_to_store[$store_info['config_language']] = array(
            'config_url' => !empty($store_info['config_url']) ? rtrim($store_info['config_url'], '/') : rtrim(HTTP_CATALOG, '/'),
            'config_ssl' => !empty($store_info['config_ssl']) ? rtrim($store_info['config_ssl'], '/') : rtrim(HTTPS_CATALOG, '/'),
          );
        }
      }
      
      if (version_compare(VERSION, '4', '>=')) {
        foreach ($this->request->post['mlseo_flag_custom'] as $langTag => $langVal) {
          $langQuery = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'language' AND `value` = '" . $this->db->escape($langTag) . "'")->row;
          
          // reset to empty if not tag mode
          if ($this->request->post['mlseo_flag_mode'] != 'tag') {
            $langVal = '';
          }
          
          // update tag
          if (!empty($langQuery['seo_url_id'])) {
            $this->db->query("UPDATE `" . DB_PREFIX . "seo_url` SET `keyword` = '" . $this->db->escape($langVal) . "', `sort_order` = '".($langVal ? '-10' : '')."' WHERE `seo_url_id` = '" . (int)$langQuery['seo_url_id'] . "'");
          } else {
            $this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$langaugeCodeToId[$langTag] . "', `key` = 'language', `value` = '" . $this->db->escape($langTag) . "', `keyword` = '" . $this->db->escape($langVal) . "', `sort_order` = '".($langVal ? '-10' : '')."'");
          }
        }
      }
      
      $this->request->post['mlseo_ml_mode'] = (count($languages) > 1);
      $this->request->post['mlseo_lang_codes'] = $current_lang_codes;
      
      // save store bindings
      $this->request->post['mlseo_lang_to_store'] = $lang_to_store;
      
      unset($this->request->post['langs'], $this->request->post['simulate'], $this->request->post['empty_only'], $this->request->post['redirect_mode']);
      
      // urls management
      foreach($languages as $lang) {
        if (isset($this->request->post['mlseo_urls_'.$lang['code']])) {
          $this->request->post['mlseo_urls_'.$lang['code']] = array_combine($this->request->post['mlseo_urls_'.$lang['code']]['keys'], $this->request->post['mlseo_urls_'.$lang['code']]['values']);
        }
      }
      
      // $this->request->post['mlseo_default_lang'] = (!empty($this->request->post['mlseo_flag_short'])) ? substr($this->config->get('config_language'), 0, 2) : $this->config->get('config_language'); // do not use short code here !
      // $this->request->post['mlseo_default_lang'] = $this->config->get('config_language');
			$this->model_setting_setting->editSetting('module_'.self::MODULE, array('module_'.self::MODULE.'_status' => !empty($this->request->post['mlseo_enabled'])));				
			$this->model_setting_setting->editSetting('mlseo', $this->request->post, $store_id);
      
      if (defined('DIR_EXTENSION') && !empty($this->request->post['mlseo_enabled']) && is_file(DIR_EXTENSION.self::MODULE.'/seo_package.xml_')) {
        rename(DIR_EXTENSION.self::MODULE.'/seo_package.xml_', DIR_EXTENSION.self::MODULE.'/seo_package.xml');
        @unlink(DIR_OPENCART.'vqmod/checked.cache');
        @unlink(DIR_OPENCART.'vqmod/mods.cache');
        array_map('unlink', glob(DIR_OPENCART.'vqmod/vqcache/*.*'));
      } else if (defined('DIR_EXTENSION') && empty($this->request->post['mlseo_enabled']) && is_file(DIR_EXTENSION.self::MODULE.'/seo_package.xml')) {
        rename(DIR_EXTENSION.self::MODULE.'/seo_package.xml', DIR_EXTENSION.self::MODULE.'/seo_package.xml_');
        @unlink(DIR_OPENCART.'vqmod/checked.cache');
        @unlink(DIR_OPENCART.'vqmod/mods.cache');
        array_map('unlink', glob(DIR_OPENCART.'vqmod/vqcache/*.*'));
      }
      
			$json['success'] = $this->language->get('text_success');
		}

    if ($isAjax) {
      $this->response->addHeader('Content-Type: application/json');
      $this->response->setOutput(json_encode($json));
    } else {
      if (!empty($json['error']['warning'])) {
        $this->session->data['error'] = $this->language->get($json['error']['warning']);
        return $this->index();
      }
      
      $this->session->data['success'] = $this->language->get('text_success');
      $this->response->redirect($this->url->link(self::$LINK, $this->token.$redirect_store, 'SSL'));
    }
  }
  
  public function index() { goto eWyOX; YRdi_: Tktvl: goto mtyne; R8z5h: if ($data["\155\157\x64\x75\x6c\x65\137\164\171\160\145"] == "\x76\161\155\x6f\144") { goto O7NDK; } goto Vqef4; Hr76T: if (!version_compare(VERSION, 4, "\x3e\x3d")) { goto FyqtB; } goto OggeH; qk9bq: wd3Pl: goto xIxNI; YHqKR: $data["\137\x6c\141\156\147\x75\141\x67\145"] =& $this->language; goto lUF20; wdSih: goto Ht6v5; goto iORLQ; Vqef4: $this->session->data["\145\x72\x72\157\162"] = "\115\157\144\165\x6c\145\40\x6d\157\x64\x69\x66\x69\x63\x61\164\x69\157\156\x20\141\162\145\x20\x6e\157\164\40\141\x70\160\154\x69\x65\144\74\x62\x72\57\76\x4e\157\40\x6d\157\144\151\x66\x69\x63\x61\164\x69\x6f\156\x20\146\151\154\145\40\x68\141\166\145\40\142\x65\145\156\40\x66\x6f\165\156\144\x2c\40\x74\x68\x65\162\x65\x20\163\x68\157\165\154\144\40\x62\x65\40\164\x68\x65\x20\x66\x69\x6c\145\x20\145\151\164\x68\x65\162\40\x69\x6e\40\x2f\x73\x79\x73\x74\x65\x6d\57" . self::MOD_FILE . "\56\157\x63\155\x6f\144\56\x78\x6d\154\x20\x66\157\x72\40\157\143\155\x6f\144\x20\x76\145\162\x73\x69\157\x6e\54\x20\157\x72\40\151\156\x20\x2f\166\x71\x6d\x6f\x64\57\170\x6d\154\57" . self::MOD_FILE . "\x2e\x78\x6d\154\x20\146\157\x72\x20\166\x71\x6d\x6f\x64\x20\166\145\x72\163\151\x6f\156\54\40\160\154\145\x61\x73\145\40\x75\160\x6c\x6f\x61\144\x20\x74\x68\145\x20\146\x69\x6c\145\x20\146\x72\x6f\155\x20\155\157\x64\165\154\x65\x20\160\x61\143\153\141\x67\145\40\151\146\40\151\x74\40\151\163\40\156\x6f\164\40\x79\x65\x74\56"; goto FTFlW; esOab: goto kD8OF; goto Aohj5; lUF20: $data["\137\143\157\156\x66\x69\147"] =& $this->config; goto vXKlM; nXB0A: curl_close($KwAQS); goto QId3n; rMUKg: goto CVK2s; goto FosLe; DK53K: $this->session->data["\x65\x72\x72\x6f\162"] = "\x57\x61\x72\156\151\x6e\x67\40\x3a\x20\x50\x48\x50\40\x65\x78\164\145\x6e\x73\x69\157\x6e\x20\x3c\142\x3e\155\x62\163\164\x72\151\x6e\147\x3c\57\x62\76\x20\x6e\x6f\164\x20\154\157\x61\144\145\144\x2c\x20\155\x61\153\x65\40\163\165\162\145\40\x74\x6f\40\145\x6e\x61\142\x6c\145\x20\x74\x68\x69\163\x20\145\170\x74\x65\x6e\x73\151\x6f\156\40\151\x6e\40\157\x72\144\x65\162\x20\164\157\x20\x75\x73\145\x20\143\x6f\162\x72\x65\x63\x74\x6c\171\x20\x74\150\x65\40\x6d\x6f\x64\165\x6c\145\56"; goto b0YVg; ykXHy: $this->config->set("\164\x65\x6d\x70\154\141\164\x65\137\x65\156\x67\x69\x6e\x65", "\x74\x65\155\x70\x6c\x61\164\x65"); goto JTxgL; iM354: R0QNh: goto CS45X; MuDeD: $this->template = "\155\157\x64\x75\154\145\x2f\x63\157\x6d\160\154\145\164\x65\x5f\163\x65\x6f\x2e\164\160\154"; goto OluKb; QilHN: $data["\145\x72\162\x6f\162"] = $this->session->data["\145\x72\x72\157\162"]; goto MJYm8; SEMOu: $data["\x63\141\x74\x65\147\157\x72\x69\145\163"] = $this->model_catalog_category->getCategories(array()); goto zGN33; quyMm: aGIYP: goto vttEu; zUTPC: U2sOE: goto jS86b; BD_gn: goto u8lxy; goto vMXBJ; vFOOZ: goto h0wsN; goto Q06kI; uS0Fa: $data["\x62\x72\x65\x61\x64\143\x72\x75\155\142\163"][] = array("\x74\145\170\x74" => strip_tags($this->language->get("\150\145\x61\144\x69\x6e\x67\137\x74\151\x74\x6c\x65")), "\x68\162\145\146" => $this->url->link(self::$LINK, $this->token, "\123\123\x4c"), "\x73\x65\160\x61\x72\x61\164\157\x72" => "\x20\72\72\40"); goto gIfYu; OGj1E: s7sn6: goto QSEbR; O5U2r: goto zmXyh; goto aMeRt; MJYm8: unset($this->session->data["\145\x72\x72\157\x72"]); goto Z0TZ1; NoZi0: lCiyA: goto gZmGp; N1uZF: H2x6X: goto LhgYO; kyjMK: goto OKEPI; goto trIFh; XfoSD: $this->load->model("\143\x61\164\x61\154\157\x67\57\143\x61\x74\x65\147\x6f\162\x79"); goto SEMOu; K0dTV: $E5bYQ = 0; goto YNjue; p0wtn: goto sJqH6; goto NMXkQ; nZh12: $data["\142\162\x65\x61\x64\143\162\x75\155\x62\163"][] = array("\164\145\x78\164" => $this->language->get("\x74\x65\170\x74\x5f\x68\x6f\x6d\x65"), "\150\162\145\x66" => $this->url->link("\x63\157\x6d\155\x6f\x6e\57\150\x6f\x6d\145", $this->token, "\x53\x53\x4c"), "\163\145\160\x61\x72\141\x74\x6f\x72" => false); goto TeR3y; x5daT: $this->session->data["\x73\165\x63\143\x65\x73\x73"] = $MGEsw["\x73\165\143\143\145\x73\163"]; goto Dhg41; moaNm: pC9VL: goto F2_W4; b8qT0: $data["\x63\165\163\x74\x6f\x6d\x65\162\137\147\162\157\165\160\x73"] = $this->model_customer_customer_group->getCustomerGroups(); goto UxJOm; GjvtR: if ($this->config->get("\x6d\154\163\x65\157\137\x65\156\141\142\x6c\145\144")) { goto stq6R; } goto Qsxvl; zko0O: $this->load->model("\143\165\163\x74\x6f\155\145\x72\x2f\143\x75\x73\164\x6f\x6d\x65\x72\137\x67\162\x6f\165\160"); goto b8qT0; K2REs: Xh0m8: goto bWoTI; vo1Jj: wi60I: goto b11yH; Hn7bi: $this->response->redirect($this->url->link(self::$LINK, $this->token, "\x53\x53\114")); goto beXVm; p1wVd: qhash: goto wHNV4; lT1AV: $dfq9k = "\155\x6c\x73\x65\157\137\146\160\x70\x5f"; goto us_B6; xFzTm: if (!version_compare(VERSION, "\62", "\x3e\x3d")) { goto EV71N; } goto EWp3H; TeSIv: curl_setopt($KwAQS, CURLOPT_SSL_VERIFYPEER, 0); goto PB5BL; wGce8: curl_setopt($KwAQS, CURLOPT_URL, "\x68\x74\164\x70\x73\72\x2f\x2f\x67\145\145\153\x6f\x64\x65\x76\56\143\157\155\x2f\154\151\143\x65\x6e\x73\x65\56\x70\x68\160"); goto WyOJ6; J4pt1: goto CZYvf; goto AQU4I; iaKGW: if (!($this->config->get("\155\x6c\x73\145\x6f\137\141\x62\163\157\x6c\x75\164\x65") && ($this->config->get("\155\154\x73\x65\157\x5f\146\x70\x70\137\144\151\162\x65\x63\164\143\x61\164") || !$this->config->get("\155\154\163\145\x6f\x5f\146\x70\160\137\x63\x61\x74\x5f\143\x61\x6e\157\156\x69\143\141\154")))) { goto BIjJS; } goto O5i_E; tOuMH: if (version_compare(VERSION, 4, "\74") && !is_file(DIR_TEMPLATE . "\164\157\157\154\57\x67\153\144\x5f\x6c\151\x63\x65\156\163\x65\x2e\x74\160\x6c")) { goto MHxBE; } goto cjql4; VLnRc: if (!(!$this->config->get("\155\154\163\145\157\x5f\x6d\154\137\155\157\x64\x65") && count($XktyI) > 1)) { goto BojEF; } goto c7zrD; NTfTf: $data["\x63\x75\162\162\x65\x6e\x74\124\x61\142"] = "\164\x61\142\55\144\141\163\150\x62\157\x61\162\x64"; goto wsd2l; VFZHb: $KntYp = curl_exec($KwAQS); goto IslHb; WNUFz: goto BUV62; goto sAHQ6; lFax7: goto YaG9G; goto PXOa5; NYzmT: Ob4ey: goto nXB0A; LPzjN: DScjT: goto pBDPh; INNuR: $Kcjpq = file_get_contents(DIR_CATALOG . "\56\x2e\x2f\x69\156\x64\145\170\x2e\x70\150\160"); goto t5ibL; e8jjZ: if (!$UEbbE) { goto Hd5Bt; } goto DIcKV; jY13w: kbLt2: goto Ep3Ui; Cqs3q: if (version_compare(VERSION, "\63", "\76\75")) { goto SjV1f; } goto H6f5u; hI4rY: if (!file_exists(DIR_APPLICATION . "\x63\x6f\156\x74\x72\x6f\154\154\145\x72\x2f\x66\145\x65\144\57\x73\145\x6f\160\141\143\x6b\x61\147\145\137\x73\151\164\145\155\141\x70\x2e\x70\150\x70")) { goto kbLt2; } goto B583F; ZbNuc: goto yaZqM; goto Pa0M5; SSaO8: $this->session->data["\145\162\162\157\x72"] = "\x55\x70\x67\162\x61\x64\x65\x20\146\x72\157\155\x20\157\154\144\x20\x76\145\162\163\x69\x6f\156\54\40\160\x6c\145\x61\x73\145\40\x65\144\x69\x74\40\171\157\165\162\40\150\x74\x61\143\x63\145\x73\163\40\x66\151\x6c\x65\40\x6c\x69\x6b\145\40\164\150\x69\x73\40\x3a\x3c\142\x72\57\x3e\x52\145\155\x6f\166\145\40\164\x68\x65\x20\x65\156\164\x69\x72\145\x20\x6c\x69\156\x65\72\x20\x3c\x62\76\122\x65\x77\x72\x69\164\x65\x52\x75\x6c\145\40\136\50\x3f\x3a\50\x3f\x3a\50\134\167\173\x32\x7d\51\x28\77\72\57\174\x5c\172\51\51\x3f\x28\77\72\x2f\x7c\x5c\x7a\51\x3f\51\77\50\77\x3a\x28\133\x5e\77\135\x2a\51\x29\x3f\x20\151\156\144\145\x78\x2e\160\x68\160\77\x5f\x72\157\165\164\145\137\x3d\x24\62\46\x73\151\164\145\x5f\x6c\141\156\x67\x75\141\x67\x65\x3d\44\x31\x20\133\x4c\54\x51\x53\x41\x5d\74\x2f\x62\76\x3c\142\x72\57\76\x52\145\155\157\166\x65\40\x74\x68\x65\x20\43\x20\142\x65\x66\157\162\145\40\x74\150\x65\x20\154\151\x6e\x65\72\x20\74\x62\x3e\43\122\x65\167\x72\x69\164\x65\122\x75\154\x65\40\x5e\50\x5b\x5e\77\135\52\x29\40\x69\156\x64\x65\x78\x2e\160\150\160\x3f\x5f\162\x6f\x75\x74\145\137\x3d\x24\61\40\x5b\x4c\54\121\x53\101\135\74\x2f\142\76"; goto Kqx03; o_lbF: DHfbB: goto qnJiu; CYOUI: I6EA8: goto pAjfd; cdi4M: q3mXM: goto IZ0gZ; kOXGI: $this->session->data["\145\162\162\x6f\162"] = "\131\157\165\40\x68\x61\166\145\x20\145\156\141\142\154\145\x64\40\162\x65\x64\x69\x72\145\143\x74\x20\164\x6f\x20\x63\x61\x6e\x6f\x6e\151\x63\141\x6c\54\x20\x79\157\x75\x20\x73\x68\157\x75\x6c\x64\x20\x65\x6e\141\x62\154\145\40\164\x68\145\40\x6f\160\164\151\x6f\156\x20\x50\141\x74\x68\x20\x6d\x61\156\x61\x67\x65\162\x20\76\40\x22\x52\145\x77\162\x69\x74\x65\40\x70\162\157\x64\x75\143\164\x20\160\141\164\150\40\x69\156\x20\143\x61\x74\x65\147\157\162\151\145\163\42\x20\x69\156\x20\x6f\x72\144\x65\x72\40\x74\157\40\x68\141\166\145\40\164\x68\x65\40\x70\162\157\144\x75\x63\164\40\x75\x72\154\163\x20\164\157\40\x62\145\40\x61\x6c\167\141\x79\163\40\164\150\x65\40\x63\141\156\157\x6e\x69\x63\141\x6c\40\157\x6e\145\x73\x2c\40\145\x6c\x73\x65\40\151\x74\40\x77\x69\154\154\x20\x67\x65\x6e\x65\x72\141\x74\145\x20\141\40\162\145\x64\151\x72\145\x63\x74\151\x6f\x6e\40\x6f\156\40\x65\141\x63\150\x20\x70\x72\x6f\144\165\x63\x74\x20\x63\154\151\143\x6b\145\144\x20\x69\156\40\x63\x61\x74\145\147\x6f\162\151\x65\163"; goto zDIk0; euUqp: fXTLL: goto KJohC; G7pct: tciec: goto Pu4Ts; VldMs: $data["\141\x63\164\151\x6f\x6e"] = $this->url->link(self::$LINK_SEP . "\x73\x61\166\x65", $this->token . $yygZ5, "\x53\x53\114"); goto H4UTK; LdWEy: $glDMO[] = $dfq9k . "\143\x61\x74\145\x67\157\x72\151\x65\163"; goto JaxZF; cH8zE: xLS8o: goto WDebS; w1IeK: goto itW6K; goto rELE7; WbRIF: if (!(false && $this->db->query("\x53\x48\117\x57\x20\x43\117\114\x55\115\116\123\40\x46\x52\x4f\115\x20\140" . DB_PREFIX . $this->url_alias . "\140\40\114\111\113\x45\40\47\x6c\x61\x6e\x67\165\x61\147\x65\137\x69\144\x27")->row)) { goto KXU3q; } goto xNRKz; uWVfm: $data["\163\164\157\x72\145\163"] = array(); goto Q3qRW; H_dH5: $data["\163\x74\x79\x6c\145\137\163\x63\x6f\160\145\144"] .= str_replace("\x69\x6d\x67\57", self::$ASSET_PATH . "\151\155\x67\57", file_get_contents(self::$ASSET_PATH . "\163\164\171\x6c\145\x2e\143\x73\x73")); goto qFgpB; hBOhW: $XktyI = $this->model_localisation_language->getLanguages(); goto wYOzp; HiMyM: $glDMO[] = $dfq9k . "\142\x79\160\141\163\163\143\141\164"; goto MDq5K; PdqKe: F7leC: goto E2vYj; EGnhv: if (!(isset($this->request->get["\x73\164\157\x72\x65\137\x69\x64"]) && $this->request->get["\x73\x74\157\x72\145\x5f\151\x64"])) { goto R2RVC; } goto uBN7d; jS86b: $zOm7L = new \Opencart\System\Library\Template("\x74\145\x6d\160\x6c\141\164\145"); goto Yy91z; RlWHr: goto Dkal0; goto uXWkf; lqT18: goto WXj4H; goto nhT2L; utpoH: if (empty($Wy0d3) || $RKWTW) { goto eYHvH; } goto gKPjE; Q2AFX: gy0UK: goto Yt22v; s_YlN: goto hthaO; goto GIM7l; Y7l9u: curl_setopt($KwAQS, CURLOPT_POSTFIELDS, http_build_query(array("\163\x6e" => $this->request->post["\x6c\151\143\x5f\156\165\155\x62\145\x72"], "\164\167" => !empty($this->request->post["\x6c\151\143\137\x74\145\163\164"]), "\151\x70" => isset($_SERVER["\123\105\x52\x56\x45\122\x5f\x41\x44\x44\122"]) ? $_SERVER["\123\105\x52\126\105\122\x5f\101\x44\104\122"] : '', "\155\x64" => self::MODULE, "\x77\x73" => HTTP_SERVER, "\162\x66" => $RKWTW))); goto WObrm; Ao33z: hthaO: goto t2BW1; omtVV: goto f1Ckh; goto mLjNJ; wHgkQ: $VslUq = $this->model_setting_extension->getInstalled("\x66\x65\145\x64"); goto qsOyZ; zICuH: goto uslt2; goto LPzjN; wlB1E: tsHPw: goto U_jdY; Mf_XZ: $this->load->model("\x73\145\x74\164\x69\156\147\57\x65\x78\x74\x65\x6e\163\151\x6f\156"); goto Y58Ab; Cg1qQ: $this->load->model(self::$EXT_PATH . "\163\145\x74\164\x69\156\147\x2f\146\x72\x69\x65\156\x64\x6c\x79\165\x72\154\x73"); goto W25mR; kTrX5: $this->db_tables(); goto IsFNd; ChJua: if (empty($YLVI9[$this->url_alias . "\137\151\x64"])) { goto hxfHh; } goto ezHYS; r7L3h: FaUJ5: goto VldMs; J8wkT: goto ahhud; goto Q2AFX; VuO5b: $data["\143\x6c\151\x5f\154\x6f\147"] = sprintf($this->language->get("\164\145\x78\164\137\x63\154\x69\137\154\x6f\147\137\164\x6f\157\x5f\x62\x69\147"), round(substr($ieocD, 0, strpos($ieocD, "\x2e") + 4), 2) . $lVHlh[$E5bYQ]); goto lDBSc; xUops: $this->response->redirect($this->url->link(self::$LINK, $this->token, "\123\123\114")); goto vmGvA; lPkC_: Co1Sr: goto QQdRC; UONwS: $this->model_setting_setting->deleteSetting(md5(HTTP_SERVER . self::MODULE)); goto jOEsE; yeW1l: $data["\x62\x75\164\164\x6f\x6e\x5f\163\141\x76\x65"] = $this->language->get("\142\165\164\164\157\156\x5f\163\x61\166\x65"); goto DHIOl; GeFVP: oiSlh: goto FKmlZ; WnSX6: MGEfU: goto FGSgv; msqEd: E6fTe: goto pLtEi; a8cMo: $this->data =& $data; goto MuDeD; KnPBS: goto JGZJm; goto zuteY; AmwvT: $ieocD = $ieocD / 1024; goto yWZ4t; bI3eO: goto NKbsH; goto xAD3r; maKBr: ZYRX8: goto kk_ZF; ScKfj: ne10O: goto mUhRA; ThQsH: $data["\143\x6c\x69\x5f\x6c\x6f\147\137\x6c\151\x6e\x6b"] = $this->url->link("\x6d\x6f\x64\x75\154\x65\57\143\x6f\155\160\x6c\145\164\145\x5f\163\145\157\57\x73\x61\x76\x65\x5f\143\x6c\151\x5f\154\x6f\147", $this->token, "\123\123\114"); goto kVpaN; Ur7Ka: goto xkLM6; goto if_dy; CPwSA: $data["\x6d\x6f\144\x75\154\x65"] = self::MODULE; goto vDrU9; xruWw: if (!empty($data["\154\x69\x63\145\156\x73\145\137\151\156\x66\157"]["\167\x65\x62\x73\x69\x74\145"]) && strpos($_SERVER["\110\124\124\x50\137\110\117\x53\x54"], $data["\154\x69\x63\x65\156\x73\x65\137\151\x6e\146\157"]["\x77\145\x62\x73\151\x74\145"]) !== false) { goto PL_Zz; } goto a2nQh; ndmsU: xkLM6: goto SvBDS; HxAVF: R6pkt: goto aYJEu; xgqUR: goto WQ00i; goto L2fHK; JTJze: goto XYe2v; goto uGsgR; vWvCp: goto ONRO2; goto a6xyT; bAzPF: $pulAQ = @file_get_contents(DIR_CATALOG . "\56\x2e\57\56\x68\x74\x61\x63\x63\145\163\163"); goto neBSO; Yxu0v: $data["\117\x43\x49\x44"] = self::OCID; goto CPwSA; bKbNt: $data["\145\162\162\157\x72"] = ''; goto WlOFJ; w7frK: if (version_compare(VERSION, "\62\x2e\x31", "\76\75")) { goto WTMfi; } goto w_9Wl; D31ta: ZLzv3: goto w7frK; IybqL: goto Y2ip6; goto HRNE5; Lhp1O: $data["\145\162\x72\x6f\x72"] = $this->error["\145\x72\162\157\162"]; goto D31ta; wLhPW: goto wig5K; goto TA7CL; WQj4T: $this->document->setTitle(strip_tags($this->language->get("\150\x65\141\144\x69\x6e\x67\x5f\x74\x69\164\x6c\x65"))); goto iADIk; i3I5p: curl_setopt($KwAQS, CURLOPT_RETURNTRANSFER, 1); goto TJj2s; ow405: $this->session->data["\x65\162\162\157\x72"] = "\117\156\40\x6f\143\x53\x74\157\x72\x65\40\171\x6f\x75\x20\155\165\x73\x74\40\163\145\x6c\145\x63\164\x20\104\145\146\141\x75\154\164\x20\x53\x45\x4f\40\x55\x72\154\40\x65\156\x67\x69\156\145\x20\x69\x6e\x20\123\x79\x73\164\145\x6d\40\76\40\123\x65\164\x74\151\156\x67\163\x20\76\x20\x53\x65\162\166\x65\x72\x20\151\156\x20\157\162\x64\x65\162\x20\x74\157\x20\x43\157\x6d\160\x6c\x65\164\145\40\123\105\x4f\40\164\157\x20\167\157\x72\x6b"; goto e2cjG; uXWkf: UTZ41: goto x5daT; oNhYG: uslt2: goto G_V7g; GIM7l: xoWwu: goto Rfk38; pBDPh: $this->config->set("\164\145\155\x70\154\x61\164\145\x5f\x65\x6e\147\x69\x6e\x65", "\x74\x65\x6d\160\154\x61\x74\x65"); goto zfaum; KjdIP: $this->document->addScript(self::$ASSET_PATH . "\160\162\x65\x74\164\171\103\150\x65\143\x6b\x61\142\154\145\56\x6a\x73"); goto KYeIU; TQzxx: $this->response->setOutput(str_replace(array("\x76\151\145\167\57\x6a\x61\166\141\163\143\x72\x69\x70\x74\57\152\x71\165\x65\x72\171\57\x6a\161\165\145\162\171\55\61\x2e\66\x2e\61\x2e\155\151\x6e\56\152\x73", "\x76\x69\x65\x77\57\x6a\x61\166\141\163\143\162\x69\x70\x74\57\152\x71\x75\x65\x72\171\57\152\x71\165\x65\x72\x79\x2d\x31\56\67\x2e\x31\56\x6d\x69\x6e\56\x6a\x73", "\x68\164\x74\x70\163\72\x2f\57\x61\x6a\141\x78\56\147\157\157\x67\x6c\x65\141\160\x69\163\56\x63\157\x6d\57\x61\152\x61\x78\x2f\x6c\x69\142\x73\57\152\x71\x75\145\162\x79\57\61\x2e\67\x2e\x32\x2f\152\161\x75\x65\162\x79\56\155\x69\156\x2e\152\163"), self::$ASSET_PATH . "\152\161\x75\145\x72\171\x2e\155\151\x6e\56\x6a\x73", $this->render())); goto L8fGO; Ulp7q: P6cpl: goto suDbr; l4OHH: ax3DL: goto tWtSO; fo1pS: A4f_w: goto Y7l9u; ZKJy8: f1Ckh: goto zICuH; uQh4b: $data["\151\156\x66\x6f"] = "\104\145\155\157\156\163\x74\x72\141\x74\x69\157\156\40\155\157\144\145\x20\151\x73\40\x72\145\141\x64\40\157\x6e\x6c\171\54\40\x6e\x6f\40\143\150\141\x6e\x67\145\x20\x77\151\154\x6c\x20\x62\x65\40\x73\x61\166\x65\x64\56"; goto OGj1E; Kqx03: goto Mplkr; goto iirF7; IsFNd: goto KuxKD; goto o_lbF; IslHb: goto Ob4ey; goto IgEJP; XXcfx: ZUHkM: goto OCJBF; If0Ss: itW6K: goto rcqeH; S6ZkA: yaZqM: goto Hn7bi; mUhRA: if (!$I2PwC) { goto xILuV; } goto BiuZ8; clzOL: if (version_compare(VERSION, "\x32", "\x3c")) { goto GE2Uo; } goto Jz83I; JMXKA: if (isset($this->error["\x77\141\162\x6e\151\x6e\x67"])) { goto JBmfK; } goto uVVFY; zKet3: goto tp2Me; goto euUqp; XUT7n: $this->document->addScript(self::$ASSET_PATH . "\142\157\x6f\x74\x73\x74\162\141\x70\x2e\x6d\x69\156\56\x6a\x73"); goto AHi1S; SQv18: eYHvH: goto Brz2W; J9Jnl: goto bM7hS; goto XGAmu; jwRaD: goto XHdVY; goto Vmnw3; QId3n: goto H2x6X; goto cGwju; VKeAO: foreach ($XktyI as $rhdWd => $Kl4xZ) { goto bW5HR; OWbD0: $XktyI[$rhdWd]["\151\155\141\147\145"] = "\x6c\x61\x6e\147\x75\x61\x67\x65\57" . $Kl4xZ["\143\157\144\x65"] . "\x2f" . $Kl4xZ["\143\157\x64\x65"] . "\56\x70\156\x67"; goto oVZe5; e5JBX: goto cWziR; goto dkCCW; m18TG: meL09: goto tY4jP; iX0VR: $XktyI[$rhdWd]["\x69\155\x61\x67\x65"] = "\x76\x69\145\167\57\x69\155\x61\x67\145\57\x66\x6c\141\147\163\57" . $Kl4xZ["\x69\x6d\141\147\x65"]; goto e5JBX; bW5HR: if (version_compare(VERSION, "\62\x2e\x32", "\x3e\x3d")) { goto GH_N7; } goto iX0VR; dkCCW: GH_N7: goto OWbD0; Yh_50: $Sc3w7[$Kl4xZ["\154\x61\x6e\147\x75\141\147\x65\x5f\151\x64"]] = $Kl4xZ["\x63\x6f\144\x65"]; goto m18TG; IOnk8: if (!$Kl4xZ["\163\164\x61\164\x75\x73"]) { goto meL09; } goto Yh_50; oVZe5: cWziR: goto IOnk8; tY4jP: FLAs7: goto qTNk2; qTNk2: } goto tCK94; icFdC: b8dg4: goto PhKSX; L2fHK: grxUj: goto f4Igy; sAHQ6: peZwj: goto YhKhr; KxyoD: goto QLh9g; goto zUTPC; ENoc_: $data["\x68\145\x61\x64\151\156\x67\x5f\164\151\x74\x6c\x65"] = $this->language->get("\x6d\157\x64\165\x6c\x65\137\164\151\164\x6c\145"); goto yeW1l; kk_ZF: if (empty(self::$LINK)) { goto S20PO; } goto J9Jnl; EWp3H: goto hSw6K; goto S0K_R; S8wnQ: if (!(in_array($_SERVER["\x52\x45\115\x4f\124\x45\x5f\101\104\x44\122"], array("\x31\62\x37\x2e\x30\x2e\x30\56\61", "\x3a\x3a\61", "\61\71\62\56\61\66\x38\56\60\56\61")) || !$this->user->hasPermission("\155\x6f\144\x69\146\x79", self::$LINK))) { goto y368o; } goto bI3eO; eWyOX: if (!(!empty($this->request->get["\143\154\145\x61\162\137\143\154\x69\137\x6c\x6f\x67\163"]) && file_exists(DIR_LOGS . "\163\x65\x6f\137\160\x61\x63\x6b\141\x67\x65\x5f\143\x6c\x69\x2e\x6c\157\147"))) { goto wd3Pl; } goto U_9Cd; dzJNP: if (version_compare(VERSION, "\x34", "\74")) { goto RFbg9; } goto sidLB; cbK7_: goto DScjT; goto oNhYG; W1B6n: if (version_compare(VERSION, "\62\x2e\63", "\76\x3d")) { goto LYm80; } goto LOPWb; XCQlC: if (version_compare(VERSION, "\62\x2e\x33", "\76\75")) { goto xLS8o; } goto JC4xA; imPT5: JDDUE: goto OocR0; mM6ky: sEW2r: goto o9zAR; BiuZ8: goto kCCw5; goto OCJh7; mLjNJ: zTbAp: goto esOab; ncI1j: $TqFxN = array(); goto W9hnQ; BojNg: HVcvU: goto KnPBS; C432k: zNNHP: goto MiDw4; PsJt2: goto UTZ41; goto YRdi_; WDebS: $data["\x6c\151\x6e\153\137\163\151\x74\145\155\x61\x70"] = $this->url->link("\145\x78\164\x65\156\x73\151\157\x6e\x2f\145\170\x74\145\156\x73\151\157\x6e", "\x74\171\160\145\75\x66\x65\145\x64\x26" . $this->token, "\x53\123\x4c"); goto ciQUe; pAjfd: if (version_compare(VERSION, "\62", "\x3e\75")) { goto wyoN7; } goto V0hKi; TA7CL: c2zDh: goto E1RKb; TXsHI: $this->document->addStyle(self::$ASSET_PATH . "\163\x65\154\x65\143\164\x32\56\155\151\x6e\x2e\143\163\x73"); goto cJK6i; xAD3r: y368o: goto y6LDy; hgqJ9: goto aGIYP; goto mHOEY; U_9Cd: unlink(DIR_LOGS . "\x73\x65\x6f\x5f\160\141\143\153\141\147\145\x5f\143\x6c\151\x2e\x6c\x6f\147"); goto LmAbP; aO_YX: $data["\143\x75\x72\x72\x65\156\x74\x54\x61\142"] = $this->session->data["\x63\165\162\162\145\156\164\x54\x61\142"]; goto qR9VH; jX1Lx: NxDW4: goto YLLsl; lxsWx: goto Tktvl; goto XXcfx; KPTLK: V31PC: goto HA0uW; JC4xA: $data["\x6c\x69\156\153\x5f\163\x69\164\145\155\141\160"] = $this->url->link("\x66\145\x65\144\57\141\144\166\x61\156\143\145\x64\137\163\x69\x74\x65\x6d\x61\160", $this->token, "\x53\123\x4c"); goto wR4q_; GzJat: goto KL7t0; goto mXY76; vewEb: $glDMO[] = $dfq9k . "\156\157\x70\x72\157\144\142\162\145\141\x64\x63\162\x75\x6d\x62"; goto R4BDR; aMeRt: y0Ge3: goto UONwS; oNgZO: $data["\154\x61\156\x67\137\x74\157\137\163\x74\x6f\162\145"] = $sXCGV; goto fa7Qr; kxiD6: goto GFZxm; goto DHaCG; NZJPD: $this->response->redirect($this->url->link(self::LINK, $this->token, "\123\x53\114")); goto Tnpwx; NvK5r: $data["\x4f\103\137\x56\x45\122\x53\x49\117\116"] = $this->OC_VERSION; goto a4_ke; rehCP: vJjOA: goto x7UB0; d3my7: unset($this->session->data["\163\x75\143\x63\145\163\163"]); goto zSoaW; vttEu: goto Taqnj; goto ndmsU; gIfYu: if (version_compare(VERSION, "\x34", "\76\x3d")) { goto D1q0_; } goto WzRGv; E355q: $data["\163\x74\171\x6c\145\x5f\x73\x63\x6f\x70\x65\x64"] .= str_replace("\151\x6d\x67\x2f", self::$ASSET_PATH . "\151\x6d\147\x2f", file_get_contents(self::$ASSET_PATH . "\x6a\161\165\145\x72\171\x2d\145\144\x69\x74\141\142\x6c\145\x2e\143\x73\x73")); goto DngBZ; TZE_h: $this->response->setOutput($this->load->view("\145\x78\x74\145\156\163\x69\x6f\x6e\x2f" . self::MODULE . "\57\x74\x6f\x6f\x6c\57\x67\x6b\144\x5f\154\151\x63\x65\x6e\x73\145", $data)); goto ijHHG; IUuyZ: SjV1f: goto ykXHy; WlOFJ: goto ZLzv3; goto NDt27; jGTQ1: Gxopa: goto WbRIF; q8InA: $data["\145\x72\162\x6f\x72\137\x77\x61\x72\x6e\151\156\x67"] = $this->error["\167\141\x72\x6e\x69\156\147"]; goto QL01I; Qsxvl: $this->session->data["\x65\162\x72\157\162"] = $this->language->get("\x65\162\x72\x6f\162\137\155\157\x64\165\x6c\x65\x5f\144\151\163\x61\x62\154\x65\144"); goto tbF5r; W25mR: $data["\x66\x72\x69\x65\x6e\144\x6c\171\x5f\165\x72\154\163\137\x6c\x61\x6e\x67\x73"] = $this->{self::$MODEL_PATH . "\163\x65\x74\164\x69\156\x67\x5f\x66\x72\151\x65\x6e\x64\x6c\171\165\162\154\163"}->getAvailableLangs(); goto zNLR0; JaxZF: $glDMO[] = $dfq9k . "\163\154\x61\163\x68"; goto iRAtT; WObrm: goto cVgmm; goto wlB1E; fVgkt: $glDMO[] = $dfq9k . "\142\x72\x65\x61\x64\143\162\165\155\142\163"; goto vewEb; GnCao: goto ZwQfm; goto WkcRT; Pcqen: wll4p: goto PsJt2; pBHnY: KfFJp: goto q505M; EFzR6: pHXIa: goto ev2xs; CS45X: if (!isset($MGEsw["\x65\x72\162\157\162"])) { goto ylCKb; } goto vFOOZ; S_Jna: $yygZ5 = ''; goto e8jjZ; iRAtT: foreach ($XktyI as $Kl4xZ) { goto JTDh9; u2jMa: $glDMO[] = $Qtmx4 . "\x70\x61\147\x69\x6e\x61\164\151\x6f\x6e\x5f" . $Kl4xZ["\x6c\x61\156\x67\165\141\147\145\137\x69\x64"]; goto cOiFo; ifmCu: $glDMO[] = $Qtmx4 . "\154\x69\155\x69\x74\x5f" . $Kl4xZ["\x6c\141\x6e\147\x75\141\147\145\x5f\151\144"]; goto wW5b3; leP4x: $glDMO[] = $Qtmx4 . "\163\x6f\162\x74\x6e\x61\155\x65\x5f" . $Kl4xZ["\154\141\156\147\165\141\x67\x65\137\x69\144"]; goto WJBW9; cOiFo: $glDMO[] = $Qtmx4 . "\163\157\162\x74\x5f" . $Kl4xZ["\x6c\141\156\147\165\141\x67\145\137\x69\x64"]; goto ifmCu; JTDh9: $glDMO[] = $Qtmx4 . "\162\x65\x6d\157\166\x65\x5f" . $Kl4xZ["\154\141\x6e\x67\165\141\x67\145\x5f\x69\x64"]; goto MHhWN; wW5b3: $glDMO[] = $Qtmx4 . "\157\x72\x64\145\162\137" . $Kl4xZ["\154\x61\x6e\x67\165\x61\147\145\x5f\x69\144"]; goto leP4x; WJBW9: $glDMO[] = $Qtmx4 . "\x70\x61\147\x69\x6e\x61\164\151\x6f\x6e\x5f\156\x61\155\x65\137" . $Kl4xZ["\x6c\x61\x6e\x67\165\141\x67\145\x5f\151\144"]; goto WVEOF; MHhWN: $glDMO[] = $Qtmx4 . "\162\145\160\154\141\143\x65\x5f" . $Kl4xZ["\x6c\x61\156\147\165\141\147\x65\x5f\151\144"]; goto u2jMa; bgVg5: $glDMO[] = $dfq9k . "\163\x65\141\162\143\150\x5f" . $Kl4xZ["\154\x61\x6e\147\165\x61\147\x65\x5f\151\144"]; goto wfCdl; WVEOF: $glDMO[] = $dfq9k . "\164\x61\x67\137" . $Kl4xZ["\154\141\x6e\147\165\141\x67\x65\x5f\x69\144"]; goto bgVg5; wfCdl: rb140: goto zhmLg; zhmLg: } goto RpPy1; cGwju: lTibQ: goto JrFNH; E2vYj: $this->response->setOutput($this->render()); goto ni9lW; Uiaii: $this->load->model("\x73\x65\164\164\x69\x6e\x67\x2f\x73\145\164\x74\x69\156\147"); goto k_VYk; nH1dO: BIjJS: goto GjvtR; sidLB: $this->session->data["\x65\162\x72\x6f\162"] .= "\x3c\x62\x72\57\x3e\x3c\142\162\x2f\x3e\x41\x6c\x73\x6f\40\155\141\153\x65\40\x73\x75\162\x65\x74\x6f\40\x69\156\163\x74\x61\x6c\x6c\40\x74\x68\x69\163\x20\160\141\143\153\141\x67\145\x3a\40\x3c\141\40\150\x72\x65\x66\75\x22\150\x74\164\x70\x73\72\x2f\57\147\x65\x65\153\x6f\x64\x65\x76\x2e\x63\157\x6d\57\x65\141\x73\171\55\x76\x71\155\157\x64\x2d\x69\156\x73\x74\141\154\x6c\145\x72\42\76\x68\164\164\160\163\x3a\x2f\57\147\x65\x65\153\157\x64\x65\x76\56\x63\157\x6d\57\145\x61\x73\171\55\x76\x71\155\x6f\144\55\151\x6e\163\164\141\154\154\x65\162\x3c\57\141\76"; goto EFbfg; gDexH: ZR7YW: goto coaeH; guuTc: goto aGIYP; goto F9gv7; rrX0r: if (version_compare(VERSION, "\63", "\76\75")) { goto sRfJY; } goto XCQlC; O5i_E: $this->session->data["\145\162\162\x6f\162"] = "\131\x6f\165\40\150\141\x76\145\40\x65\156\x61\x62\x6c\x65\144\x20\74\142\76\101\x62\163\157\x6c\x75\164\145\40\143\141\x74\x65\147\157\162\x79\x20\x70\141\164\x68\x3c\x2f\142\x3e\x2c\40\151\x6e\x20\x74\150\x69\163\x20\143\x6f\x6e\x66\x69\147\165\x72\141\x74\x69\157\x6e\x20\151\164\x20\x69\x73\40\x6e\x65\x63\x65\x73\x73\141\162\x79\x20\x74\x6f\40\163\x65\164\40\74\142\76\103\x61\x74\x65\147\x6f\x72\x79\40\x70\x61\x74\x68\40\x6d\157\x64\x65\74\57\x62\76\x20\x61\156\144\x20\74\x62\x3e\103\x61\x74\x65\147\x6f\162\x79\x20\x63\x61\156\x6f\x6e\151\143\141\154\74\x2f\x62\76\40\164\157\40\74\x62\76\x46\x75\154\x6c\40\x70\x61\164\x68\x3c\57\x62\76\40\145\x6c\163\145\x20\x69\x74\40\x77\x69\154\x6c\40\156\157\164\40\x62\x65\40\160\x6f\163\x73\x69\142\x6c\145\x20\164\x6f\40\146\151\x6e\144\40\164\x68\x65\x20\143\x6f\x72\x72\x65\163\160\157\156\x64\151\x6e\x67\40\x63\x61\x74\x65\x67\157\x72\171\56\74\x62\162\57\76\x49\x74\x20\x69\x73\40\x61\x6c\x73\157\x20\x72\145\143\157\x6d\155\x65\156\x64\x65\x64\40\164\x6f\x20\150\141\x76\x65\x20\74\142\x3e\120\x72\x6f\144\165\143\x74\x20\160\x61\x74\150\x20\x6d\157\144\x65\74\57\x62\76\40\x74\x6f\40\x3c\142\x3e\x4c\x61\162\147\145\x73\x74\40\x70\x61\164\x68\56\x3c\x2f\142\76"; goto nH1dO; YhKhr: msLwd: goto lfYCB; W5rAL: $glDMO[] = $dfq9k . "\162\145\x6d\x6f\x76\145\137\x73\x65\141\162\x63\150"; goto SYFFf; fuAYw: goto JJqsH; goto O5U2r; M61Dd: $data["\163\164\x79\x6c\x65\137\163\x63\x6f\160\145\x64"] .= str_replace("\x69\155\147\57", self::$ASSET_PATH . "\151\x6d\x67\57", file_get_contents(self::$ASSET_PATH . "\152\x71\x75\x65\x72\x79\55\x65\144\151\x74\141\142\x6c\145\x2e\x63\x73\x73")); goto l7AAM; QHYRE: if (!(version_compare(VERSION, "\62", "\74") && is_dir(DIR_APPLICATION . "\143\x6f\x6e\x74\x72\x6f\x6c\154\x65\x72\57\145\x78\x74\x65\x6e\163\151\157\156\57\x6d\157\x64\x75\x6c\x65"))) { goto lCiyA; } goto S6Arn; ZiUIY: XHdVY: goto xruWw; Gdrq9: BGpcI: goto ZKJy8; Rqqf0: rPngW: goto q_0kd; Q3qRW: $data["\x73\164\x6f\x72\x65\163"][] = array("\x73\x74\157\x72\145\137\151\144" => 0, "\x6e\x61\155\145" => $this->config->get("\x63\157\156\x66\x69\147\x5f\x6e\x61\155\145")); goto sJMa_; IgEJP: Taqnj: goto utpoH; c0pmh: kcNa1: goto XMws7; Q1Oe1: $data["\143\x6f\154\165\155\156\x5f\x6c\x65\146\x74"] = $this->load->controller("\143\x6f\155\155\157\x6e\x2f\143\157\154\x75\155\x6e\x5f\154\145\x66\x74"); goto WNUFz; QIOmi: R2RVC: goto YvgXT; UFMse: goto sb6ug; goto vhURE; nR3Mh: $data["\163\x74\x6f\x63\x6b\137\x73\164\x61\164\165\163\x65\163"] = $this->model_localisation_stock_status->getStockStatuses(); goto ncI1j; wHNV4: Rs78v: goto v7x0d; XsvF9: $data["\x62\x72\145\x61\x64\143\x72\165\x6d\142\163"][] = array("\164\145\x78\164" => $this->language->get("\x74\145\x78\164\137\x6d\x6f\144\165\154\x65"), "\150\x72\x65\x66" => $xfz3p, "\163\x65\x70\141\162\x61\164\157\162" => "\x20\x3a\x3a\x20"); goto uS0Fa; wjKCN: t0jZR: goto Ex9bo; GG3fW: goto rR44w; goto gDexH; tzsqg: $data["\x73\164\x6f\162\x65\137\x69\x64"] = $UEbbE = 0; goto EGnhv; vgn10: goto bA44i; goto g_Sed; In2Oa: vRceA: goto quyMm; lhSZ1: goto StTmw; goto CeiZ4; vhURE: P8Pym: goto xUops; vXHvH: wqsBC: goto S_Jna; YvgXT: $y46IY = $this->config->get("\x63\157\x6e\x66\151\x67\x5f\147\x6b\x64\115\123\114\141\x6e\x67"); goto WCdOI; L5lWL: goto bYxCK; goto GsSYr; Xqus9: goto AQi4L; goto uqpTl; P5fG4: if (!($ieocD / 1024 > 1)) { goto GY8B0; } goto AmwvT; lQu4F: goto imG3F; goto ykNSo; WIpHD: Pn6S8: goto tKA_4; JrFNH: $this->response->setOutput($this->load->view("\164\x6f\157\154\x2f\147\153\144\x5f\154\x69\143\x65\156\163\x65", $data)); goto hH51K; HBKMd: goto Owqly; goto Ao33z; rELE7: shMeG: goto HH007; jqU2e: CZYvf: goto dx1GT; zSoaW: ZwQfm: goto f0j2a; lrKJ1: if (in_array("\141\x64\166\x61\156\x63\145\x64\137\163\151\x74\145\155\141\160", $VslUq)) { goto KfFJp; } goto rrX0r; bWoTI: goto Ss6pf; goto N1uZF; RR6jr: KL7t0: goto keH4r; PEpus: OKEPI: goto If0Ss; hH51K: goto tsHPw; goto jX1Lx; ZzYvI: if (!version_compare(VERSION, 3, "\x3e\75")) { goto S_BIf; } goto PZbpL; Q7KP3: $uPYqh = count($TqFxN); goto w76Fe; wR4q_: goto XBA11; goto cH8zE; LLTF5: iLU_Q: goto fJt6f; SHjnZ: $this->document->addStyle(self::$ASSET_PATH . "\141\x77\145\x73\157\155\145\57\143\x73\x73\x2f\146\157\x6e\164\55\x61\x77\145\x73\157\x6d\x65\56\x6d\151\156\56\x63\x73\x73"); goto LuUW3; wIySS: yNxiU: goto BlDHP; FTFlW: goto hw3sc; goto EMUv7; Q_QQI: ry9Wx: goto y55aT; Glohr: $VslUq = $this->model_setting_extension->getInstalled("\x66\145\145\144"); goto okULr; Z0TZ1: goto ZLzv3; goto ejMIN; SJQpW: goto lxn9M; goto CPizL; LKN6F: foreach ($ih4Ag as $hYkcD) { goto sytbi; VIVFD: i02DG: goto uzt0h; sytbi: $Tt9wx = array(); goto YPead; YPead: $data["\x73\164\x6f\162\x65\163"][] = array("\163\x74\x6f\x72\145\137\x69\144" => $hYkcD["\x73\x74\x6f\x72\x65\137\151\144"], "\x6e\141\155\145" => $hYkcD["\156\x61\x6d\x65"]); goto VIVFD; uzt0h: } goto cqbWx; U_jdY: n624J: goto lvAAz; OCJBF: $this->redirect($this->url->link(self::LINK, $this->token, "\123\123\114")); goto phmJ1; ilTFm: goto RpLVC; goto WR4Xn; MuPU6: goto jC3yu; goto Tn8fF; N3sr0: goto e_T_g; goto Tgpxq; P1aAT: $data["\x65\x72\x72\157\162"] = "\x45\x72\x72\x6f\x72\40\144\165\x72\151\156\147\x20\x61\x63\x74\x69\x76\x61\x74\151\157\156\40\x70\x72\x6f\143\145\x73\163\54\x20\160\154\x65\x61\163\x65\x20\143\x6f\156\x74\141\x63\164\40\163\165\x70\160\157\162\x74"; goto HoQ4U; mz7Q1: tFz1_: goto QIOmi; sR2Ri: $this->load->model("\163\x65\164\x74\x69\x6e\147\x2f\x73\x74\x6f\x72\x65"); goto uWVfm; BlDHP: $data["\145\162\x72\157\162"] = "\114\151\143\145\156\163\145\40\x6e\165\155\x62\x65\162\40\146\x6f\x72\155\x61\x74\40\x69\x73\40\151\x6e\143\157\162\x72\x65\143\164"; goto kyjMK; Iz0DW: if (!empty($this->error["\x65\x72\x72\x6f\x72"])) { goto ZPtf_; } goto bKbNt; h76bJ: $data["\x63\x6c\151\x5f\x6c\x6f\x67"] = file_get_contents($mMubI); goto IBw26; bIyMx: if (!(version_compare(VERSION, "\x32", "\x3c") && is_dir(DIR_APPLICATION . "\x63\157\x6e\164\162\x6f\x6c\x6c\145\x72\x2f\x65\x78\164\x65\x6e\163\x69\x6f\x6e\57\x6d\x6f\x64\165\154\145"))) { goto rmC9B; } goto QHYRE; vJq4g: goto E6fTe; goto PpgDC; Q_pOR: goto sKWVG; goto iLhLV; PZbpL: goto dIeod; goto eDWVu; WfgVc: $this->document->addStyle(self::$ASSET_PATH . "\x73\x74\171\x6c\145\x2e\x63\x73\x73"); goto H3f9b; nKNVw: goto HVcvU; goto J4pt1; uvLDV: GFZxm: goto lFax7; Q06kI: ylCKb: goto aT7yy; xqdhG: frHiO: goto Q1Oe1; A1Vgu: goto ZR7YW; goto S5w_X; LOPWb: $xfz3p = $this->url->link("\x65\x78\x74\x65\x6e\x73\x69\157\156\57\155\x6f\144\165\154\145", $this->token, "\x53\x53\114"); goto kxiD6; jYGjx: curl_setopt($KwAQS, CURLOPT_USERAGENT, "\115\157\172\151\x6c\154\141\57\65\x2e\60\x20\x28\127\151\x6e\x64\157\x77\163\40\116\x54\x20\61\x30\x2e\x30\73\x20\127\117\127\66\64\51\40\101\x70\x70\x6c\145\127\x65\x62\113\x69\x74\x2f\65\x33\67\56\63\66\x20\50\x4b\110\x54\115\114\x2c\40\154\x69\153\x65\40\x47\x65\143\153\157\51\40\103\x68\162\x6f\155\145\x2f\65\61\x2e\x30\x2e\62\67\x30\x34\x2e\x31\60\63\40\x53\x61\146\141\162\151\57\x35\63\67\x2e\x33\66"); goto RlWHr; S0K_R: EV71N: goto dZdJm; ev2xs: $Qtmx4 = "\155\x6c\x73\x65\x6f\137"; goto EX6T8; keH4r: if (empty($MGEsw["\163\x75\143\x63\x65\163\163"])) { goto Pn6S8; } goto OFqy0; uBN7d: $data["\x73\164\x6f\162\145\x5f\x69\x64"] = $UEbbE = (int) $this->request->get["\163\164\x6f\x72\x65\x5f\151\144"]; goto Dj2Yc; y_ntd: KuxKD: goto KubLq; MDq5K: $glDMO[] = $dfq9k . "\x64\151\x72\x65\143\164\x63\x61\164"; goto jA1Xy; mHOEY: goto c2zDh; goto CeRSL; idG3M: $mMubI = DIR_LOGS . "\163\x65\157\137\x70\x61\143\x6b\141\x67\x65\137\x63\x6c\151\x2e\x6c\157\x67"; goto L8cYb; wMAQb: pF5Dh: goto D0wuj; fSzr6: $data["\142\162\x65\x61\x64\143\x72\165\155\x62\163"] = array(); goto nZh12; tKA_4: goto R0QNh; goto tuQzZ; dhVoH: if (!$RKWTW) { goto oiSlh; } goto AwOur; uVVFY: $data["\x65\x72\162\x6f\x72\x5f\167\x61\x72\156\151\x6e\147"] = ''; goto wqK_m; lfYCB: goto g1OmK; goto tY2Ki; OocR0: $this->load->model("\x65\x78\164\x65\x6e\163\x69\157\156\57\x65\x78\x74\145\x6e\x73\151\x6f\156"); goto UzcxS; JTxgL: $this->response->setOutput($this->load->view("\x6d\157\144\x75\x6c\x65\x2f\x63\x6f\x6d\x70\x6c\145\x74\145\137\x73\145\157", $data)); goto qHFsN; w76Fe: $data["\163\x65\x6f\137\163\143\157\x72\x65"] = round(count(array_filter($TqFxN)) * 100 / $uPYqh); goto ENoc_; AQU4I: PKvjB: goto aPFvN; EK28l: $this->session->data["\x65\162\162\157\x72"] = "\x4d\157\x64\165\x6c\145\40\155\157\144\151\x66\x69\x63\x61\x74\x69\x6f\156\40\141\162\145\40\156\157\164\40\x61\160\x70\x6c\151\145\x64\74\x62\x72\x2f\x3e\x59\x6f\165\40\150\x61\166\x65\40\x69\156\x73\x74\141\154\154\145\144\40\x3c\x62\76\x6f\x63\x6d\x6f\144\74\57\142\x3e\40\x76\x65\162\163\x69\x6f\x6e\x2c\40\x67\157\x20\164\x6f\x20\x65\x78\x74\x65\x6e\163\151\157\156\x73\x20\76\40\x3c\x61\x20\150\x72\145\x66\75\x22" . $this->url->link("\x65\x78\164\x65\x6e\x73\x69\157\156\57\x6d\157\144\x69\146\x69\x63\x61\164\151\x6f\156", $this->token) . "\x22\76\x6d\157\144\151\146\151\x63\x61\x74\x69\157\x6e\x73\74\57\141\x3e\x20\141\156\144\40\160\165\x73\x68\x20\162\x65\146\162\145\x73\x68\x20\x62\165\x74\164\157\156"; goto aonE0; YRMW1: hSw6K: goto dbOze; uJ4jU: $data["\x63\x6f\154\165\155\156\x5f\x6c\145\x66\x74"] = $this->load->controller("\x63\157\155\155\x6f\x6e\x2f\x63\x6f\154\x75\155\156\x5f\154\145\146\x74"); goto eZ0QL; MiDw4: goto PKvjB; goto szAlc; szAlc: oIAE9: goto UNzEb; jr8au: $this->session->data["\x65\x72\162\x6f\162"] .= "\74\x62\x72\x2f\x3e\74\x62\x72\57\x3e\x49\146\40\x79\x6f\x75\40\150\141\166\145\40\157\160\x65\156\x63\x61\162\164\40\x76\x32\56\170\x20\x6f\x72\40\x33\56\170\x20\x61\x6e\x64\40\144\157\x6e\x27\x74\40\x6b\156\x6f\x77\x20\x77\x68\141\164\x20\x69\x73\x20\166\x71\155\157\144\40\x6f\x72\40\157\x63\155\x6f\x64\54\x20\164\x68\145\x6e\x20\151\x6e\163\x74\x61\x6c\x6c\x20\157\143\x6d\x6f\x64\x20\x76\x65\x72\x73\151\157\156"; goto yLWsk; dbIwA: $this->load->model("\x6c\x6f\143\141\x6c\x69\x73\x61\x74\x69\157\156\57\154\x61\x6e\147\165\x61\147\x65"); goto hBOhW; u8QAY: goto otT6f; goto eU1sh; ciQUe: XBA11: goto vJq4g; obHup: $data["\x6a\x6f\165\162\x6e\x61\154\62\137\141\143\164\151\166\145"] = is_dir(DIR_APPLICATION . "\x6d\157\144\145\154\x2f\x6a\x6f\x75\x72\x6e\141\154\62"); goto Uhf1y; k_VYk: goto y0Ge3; goto KHPb9; akfOF: $this->session->data["\x65\162\x72\157\x72"] = "\x49\164\40\x73\145\145\155\x73\x20\x79\157\165\x20\x68\141\x76\x65\40\155\157\x64\151\146\151\x65\144\x20\x79\157\x75\162\40\154\141\x6e\x67\165\141\x67\x65\163\x20\143\x6f\156\x66\x69\x67\165\162\141\x74\151\157\x6e\54\40\160\x6c\x65\141\x73\x65\x20\x73\141\166\145\40\155\157\x64\165\x6c\x65\x20\157\x70\164\151\x6f\x6e\163\x20\x74\x6f\x20\141\x63\x74\x69\x76\141\x74\145\40\155\x75\x6c\164\x69\154\x69\156\x67\x75\x61\154\x20\150\x61\156\144\154\x69\156\147"; goto jGTQ1; EU5mi: goto NSF3Y; goto LLTF5; Tnpwx: goto fOHi8; goto gcwSx; iORLQ: egvC5: goto hrM_J; hud_m: goto WEwMY; goto QwGii; D8y6l: goto vRceA; goto IERSE; OluKb: $this->children = array("\143\157\x6d\x6d\x6f\156\57\150\x65\141\144\145\162", "\143\157\155\155\157\156\x2f\146\x6f\x6f\164\145\x72"); goto TQzxx; NDt27: lnFgc: goto QilHN; i09It: goto BGpcI; goto xqdhG; x7UB0: goto EsHWq; goto UmvVT; tCK94: lUWNq: goto I9SsE; Ex9bo: curl_setopt($KwAQS, CURLOPT_POST, 1); goto LhssX; phmJ1: goto vaALZ; goto fo1pS; yb2NI: goto QVHjQ; goto wMAQb; a4_ke: $data["\117\x43\137\x56\62"] = version_compare(VERSION, "\62", "\76\75"); goto JQMDc; CeiZ4: Hm25k: goto JTJze; eKCXq: foreach ($glDMO as $yEvqp) { goto z1p_g; ecnkd: XUny_: goto dThQz; kXPch: $data[$yEvqp] = is_null($this->config->get($yEvqp)) ? '' : $this->config->get($yEvqp); goto ITHoA; tvHXX: Clvfo: goto elTcX; z1p_g: if (!($yEvqp && !isset($Wy0d3))) { goto XUny_; } goto A7Igl; ITHoA: goto iqCqq; goto tvHXX; elTcX: $data[$yEvqp] = $this->request->post[$yEvqp]; goto PN88Q; dThQz: if (isset($this->request->post[$yEvqp])) { goto Clvfo; } goto kXPch; A7Igl: return; goto ecnkd; PN88Q: iqCqq: goto pR0aV; pR0aV: nn7Sb: goto IYdCY; IYdCY: } goto CYOUI; U18oJ: if (empty($this->request->get["\x74\141\x62"])) { goto Wydk5; } goto h6zMB; DBaZ0: if (!($this->config->get("\155\x6c\163\145\x6f\137\x72\145\x64\151\162\145\x63\164\x5f\143\141\x6e\157\156\x69\x63\141\154") > 1 && !$this->config->get("\155\154\163\145\157\x5f\146\160\160\x5f\x62\171\x70\x61\163\x73\143\141\x74"))) { goto Zxs01; } goto kOXGI; zGN33: usort($data["\143\141\x74\x65\x67\157\162\x69\145\x73"], array($this, "\x73\157\x72\164\102\x79\x4e\x61\x6d\x65")); goto eKCXq; Dw04C: goto RicnI; goto F87gY; pDNL0: wyoN7: goto yubq2; PsQks: if (is_writable(DIR_CATALOG . "\56\56\x2f\56\x68\164\141\x63\x63\145\x73\x73")) { goto QzCfQ; } goto SSaO8; cJK6i: $data["\163\x74\x79\x6c\x65\x5f\x72\x61\144\x69\141\154\137\155\145\164\x65\162"] = file_get_contents(self::$ASSET_PATH . "\x72\141\x64\151\x61\x6c\55\x6d\145\164\x65\162\x2e\x63\163\x73"); goto mN7_K; zfaum: goto lTibQ; goto In2Oa; jaMn4: if (version_compare(VERSION, "\62\56\63", "\76\75") && !$this->config->has("\x6d\x6c\163\x65\157\137\144\145\x66\141\165\154\164\x5f\154\141\156\147")) { goto DHfbB; } goto kTrX5; YnzO_: v7fM5: goto MpvzY; Pu4Ts: if (!function_exists("\x6d\142\x5f\x73\164\162\x74\157\154\x6f\x77\145\x72")) { $this->error["\167\x61\x72\x6e\x69\156\x67"] = "\x54\150\145\40\160\150\160\x20\x65\x78\x74\145\x6e\163\151\x6f\156\40\155\142\137\163\x74\162\151\156\147\x20\151\x73\40\x6e\157\164\40\151\x6e\163\164\141\x6c\x6c\x65\x64\x2c\40\x74\x68\145\40\155\x6f\144\x75\154\145\40\143\141\x6e\x20\x77\x6f\162\153\40\167\x69\x74\x68\x6f\165\164\40\x69\x74\x20\142\x75\164\40\x79\157\x75\x20\155\x61\x79\40\145\170\x70\145\x72\x69\145\x6e\x63\145\x20\x73\x6f\x6d\x65\40\151\x6e\x63\157\x72\x72\x65\x63\164\x20\x76\141\x6c\x75\145\x73\40\167\x68\x65\x6e\x20\x67\145\156\x65\x72\x61\x74\x69\x6e\x67\40\x73\145\157\40\x76\141\x6c\165\145\x73\x2c\x20\151\x74\x20\151\x73\x20\x72\x65\x63\x6f\155\x6d\x65\156\144\145\144\40\164\x6f\x20\145\x6e\x61\142\x6c\x65\x20\x74\150\x69\163\40\145\x78\x74\x65\156\163\x69\157\156\40\151\x6e\40\x70\150\x70\x2e\x69\156\x69"; } goto Sb0jx; pLtEi: goto FaUJ5; goto pBHnY; V0hKi: $data["\x63\157\x6c\x75\155\x6e\x5f\x6c\x65\146\x74"] = ''; goto a8cMo; yWZ4t: $E5bYQ++; goto rMUKg; E1RKb: kCCw5: goto bAq23; iLGGN: $data["\163\x74\171\x6c\x65\137\x73\143\157\160\145\144"] .= str_replace("\151\x6d\x67\x2f", self::$ASSET_PATH . "\x69\x6d\x67\x2f", file_get_contents(self::$ASSET_PATH . "\163\164\171\154\x65\x2e\143\163\x73")); goto QjXPJ; LzoWL: $data["\154\151\x6e\153\x5f\x73\151\x74\x65\155\x61\160"] = $this->url->link("\x6d\x61\x72\x6b\145\x74\x70\x6c\x61\143\x65\57\x65\170\164\x65\x6e\x73\x69\157\156", "\x74\x79\x70\x65\x3d\x66\x65\145\144\x26" . $this->token, "\x53\x53\114"); goto msqEd; HH007: goto yNxiU; goto xOnEt; zpdTS: goto qt199; goto IUuyZ; AwOur: goto M1PSK; goto GeFVP; wYOzp: $Sc3w7 = array(); goto VKeAO; uGsgR: HWj91: goto mcRfn; Es1dX: goto NxDW4; goto SW5tH; P6Ej8: KXU3q: goto s6sxA; sJMa_: $ih4Ag = $this->model_setting_store->getStores(); goto LKN6F; AlNw7: goto A4f_w; goto QLNdn; A7wcY: $this->document->addScript(self::$ASSET_PATH . "\163\145\x6c\145\143\x74\x32\x2e\155\151\156\x2e\152\163"); goto jVu8q; y55aT: NKbsH: goto HBKMd; S5w_X: g1OmK: goto Hn1An; coaeH: $this->request->server["\x52\x45\x51\125\x45\x53\x54\137\115\x45\x54\x48\x4f\x44"] = "\x50\117\123\x54"; goto tInOR; Ep3Ui: if (!($Sc3w7 !== $this->config->get("\x6d\x6c\x73\145\x6f\x5f\154\x61\156\x67\x5f\x63\157\x64\x65\x73"))) { goto Gxopa; } goto akfOF; HRNE5: fOHi8: goto oU6mg; rFOE8: $Wy0d3 = 1; goto N3sr0; GsSYr: JGZJm: goto K2REs; lvAAz: goto JvUeH; goto cdi4M; qR9VH: O6sXa: goto sR2Ri; HthF8: $this->response->setOutput($zOm7L->render("\x65\170\x74\x65\156\x73\x69\157\x6e\x2f\143\x6f\155\x70\x6c\x65\164\145\137\163\x65\157\x2f\155\x6f\x64\165\154\x65\x2f\143\x6f\x6d\160\x6c\x65\164\x65\x5f\163\145\157", $data)); goto dyVYp; OCJh7: xILuV: goto CSPmV; ufvZQ: foreach ($data["\163\164\x6f\162\x65\163"] as $hYkcD) { goto D0hx6; D0hx6: $lKV_k = $this->model_setting_setting->getSetting("\x63\157\156\x66\151\147", $hYkcD["\x73\164\x6f\x72\145\x5f\151\x64"]); goto TXpMv; qsfNg: VY7p3: goto iWPYP; AkPJV: $sXCGV[$lKV_k["\143\x6f\156\146\151\x67\x5f\x6c\141\156\147\x75\x61\x67\x65"]] = array("\143\x6f\x6e\146\151\x67\x5f\x75\x72\x6c" => !empty($lKV_k["\143\x6f\156\x66\151\x67\137\x75\x72\154"]) ? rtrim($lKV_k["\143\157\x6e\x66\x69\147\137\x75\x72\154"], "\x2f") : rtrim(HTTP_CATALOG, "\x2f"), "\143\x6f\156\x66\x69\x67\x5f\163\163\x6c" => !empty($lKV_k["\143\157\156\x66\x69\x67\x5f\x73\163\x6c"]) ? rtrim($lKV_k["\143\157\156\146\x69\147\137\163\x73\x6c"], "\x2f") : rtrim(HTTPS_CATALOG, "\57")); goto qsfNg; TXpMv: if (empty($lKV_k["\x63\157\156\146\x69\x67\137\154\x61\156\x67\x75\141\x67\145"])) { goto VY7p3; } goto AkPJV; iWPYP: b4BnW: goto gzqJL; gzqJL: } goto YwXeI; gdsgA: vaALZ: goto FwIVx; TwPcP: RpLVC: goto nKNVw; wTwXj: ZUw1_: goto lqT18; HyeUX: GE2Uo: goto o2mDb; EHBTQ: $glDMO[] = $dfq9k . "\x62\x63\137\x6d\x6f\x64\145"; goto HiMyM; iRPTY: $data["\x63\141\x6e\143\x65\x6c"] = $xfz3p; goto JeCNV; BsgaD: $this->document->addStyle(self::$ASSET_PATH . "\x70\x72\145\164\x74\x79\103\150\x65\143\x6b\x61\x62\154\x65\56\143\x73\x73"); goto KjdIP; L8cYb: if (!file_exists($mMubI)) { goto pHXIa; } goto ThQsH; mcRfn: h0wsN: goto SJQpW; g_Jkz: e_T_g: goto hgqJ9; cjql4: goto QDqYA; goto iB7ST; DngBZ: $data["\x73\164\171\154\x65\137\163\143\x6f\160\145\144"] .= str_replace("\151\155\x67\57", self::$ASSET_PATH . "\x69\x6d\x67\57", file_get_contents(self::$ASSET_PATH . "\147\x6b\x64\55\164\150\x65\155\145\x2e\143\163\163")); goto H_dH5; H_kGT: dIeod: goto cbK7_; wsd2l: if (empty($this->session->data["\143\x75\162\x72\145\156\x74\124\141\142"])) { goto O6sXa; } goto aO_YX; zdGY3: $data["\x66\x6f\157\x74\145\x72"] = $this->load->controller("\143\157\155\155\x6f\156\x2f\x66\157\x6f\164\x65\162"); goto yb2NI; CSPmV: goto x0s8t; goto KAChM; XMws7: $lVHlh = array("\x42", "\113\x42", "\115\x42", "\x47\102", "\x54\x42", "\120\102", "\105\102", "\x5a\102", "\x59\x42"); goto K0dTV; SQ6kE: $glDMO[] = $dfq9k . "\x62\x72\x61\156\144\x5f\x70\x61\162\145\156\x74"; goto W5rAL; QjXPJ: $this->document->addScript(self::$ASSET_PATH . "\142\x6f\157\164\163\164\x72\x61\160\x2e\x6d\151\156\x2e\152\163"); goto KPTLK; t2BW1: die; goto Xqus9; jOEsE: goto oIAE9; goto Ulp7q; DfZc3: i9Mfn: goto GQKzO; Hn1An: if ($this->request->server["\122\x45\x51\x55\x45\123\124\x5f\x4d\x45\124\110\117\104"] == "\x50\117\x53\124" && isset($this->request->post["\x6c\151\x63\137\x6e\165\x6d\142\145\x72"])) { goto zTbAp; } goto omtVV; O0gtf: $data["\x61\x73\x73\145\x74\x5f\x70\x61\x74\150"] = self::$ASSET_PATH; goto BsgaD; dLqaS: JBmfK: goto q8InA; Pa0M5: cVgmm: goto VFZHb; ZlxUE: $this->children = array("\x63\x6f\x6d\x6d\x6f\x6e\x2f\150\145\x61\144\145\x72", "\143\x6f\155\155\x6f\x6e\57\146\x6f\x6f\164\x65\x72"); goto YuWnB; JcBKM: $this->document->addStyle(self::$ASSET_PATH . "\147\x6b\x64\x2d\x74\x68\145\x6d\145\56\143\163\x73"); goto WfgVc; FGSgv: $KwAQS = curl_init(); goto Dw04C; JCIe_: $this->session->data["\145\162\162\157\x72"] = "\x4d\157\144\165\154\x65\40\155\x6f\144\151\x66\x69\143\141\x74\x69\x6f\156\40\x61\162\145\40\156\x6f\164\40\x61\x70\x70\x6c\x69\145\x64\x3c\x62\162\x2f\76\x59\x6f\165\40\x68\141\x76\x65\x20\151\156\x73\164\x61\154\154\145\x64\40\x3c\142\x3e\166\161\155\157\144\74\57\x62\76\x20\166\x65\162\163\151\157\156\x2c\40\155\x61\153\x65\40\x73\165\x72\145\x20\166\x71\x6d\157\144\40\x69\x73\x20\143\157\x72\x72\x65\x63\164\x6c\171\x20\x69\x6e\x73\164\x61\154\154\x65\144\x20\x61\x6e\x64\40\167\157\162\153\151\x6e\147\56\xa\40\x20\40\40\x20\x20\40\40\x20\x20\74\142\162\x2f\76\74\142\162\x2f\76\111\146\40\x76\x71\155\157\x64\x20\x69\163\40\x63\157\162\162\x65\143\x74\154\171\x20\x69\x6e\x73\164\x61\x6c\x6c\145\x64\x2c\x20\160\154\x65\141\x73\145\40\x74\162\171\40\164\x68\145\x20\x66\157\x6c\x6c\x6f\x77\x69\x6e\x67\72\xa\x20\40\x20\x20\x20\x20\x20\40\40\x20\x3c\142\162\57\76\x2d\x20\144\145\154\145\164\145\40\x61\x6c\154\x20\146\151\154\145\x73\40\151\156\164\157\x20\74\142\x3e\x2f\166\x71\155\x6f\x64\x2f\166\x71\x63\x61\x63\150\145\x2f\x3c\x2f\x62\x3e\40\x66\x6f\x6c\x64\x65\162\12\40\40\40\x20\x20\40\40\40\40\x20\74\x62\162\57\76\x2d\x20\144\x65\154\145\x74\x65\40\x74\150\x65\40\146\151\x6c\x65\163\40\x3c\142\x3e\143\150\x65\x63\153\x65\144\x2e\x63\141\x63\150\x65\74\57\x62\x3e\x20\141\x6e\x64\40\74\x62\x3e\155\157\144\x73\56\x63\x61\x63\x68\145\x3c\x2f\x62\x3e\40\151\x6e\x20\74\142\76\57\166\x71\x6d\157\144\x2f\x3c\57\142\x3e\40\x66\x6f\154\144\x65\x72\12\x20\40\40\x20\x20\x20\40\40\x20\x20\74\x62\x72\57\x3e\x2d\x20\162\x65\x6c\157\141\x64\40\x74\150\x69\x73\40\x70\141\x67\x65"; goto dzJNP; QwGii: XSgis: goto BojNg; MpvzY: goto n624J; goto GG3fW; OggeH: goto ZUw1_; goto wShAW; LuUW3: $data["\x73\164\x79\x6c\x65\x5f\163\x63\157\160\x65\144"] = file_get_contents(self::$ASSET_PATH . "\x62\x6f\157\x74\163\x74\x72\x61\160\56\155\x69\156\56\x63\x73\163"); goto M61Dd; H3f9b: goto V31PC; goto HyeUX; mWhRd: $RKWTW = isset($this->request->get["\162\145\146\x72\145\x73\150"]) ? 1 : rand(1, 12) == 2; goto D8y6l; PhKSX: $data["\163\x74\171\x6c\145\x5f\x73\x63\x6f\x70\x65\x64"] = file_get_contents(self::$ASSET_PATH . "\x62\x6f\157\x74\x73\x74\x72\x61\x70\x2e\x6d\x69\x6e\56\143\x73\163"); goto E355q; QgNI2: sNy7f: goto Cg1qQ; Q7mrS: $sXCGV = array(); goto ufvZQ; bAq23: goto tYa6i; goto iM354; j4a6M: tp2Me: goto pQ1H2; neBSO: if (!(strpos($pulAQ, "\151\x6e\x64\145\170\56\x70\x68\x70\77\x5f\x72\157\165\164\145\137\x3d\44\x32\46\x73\151\164\x65\137\x6c\141\156\x67\165\x61\x67\x65\75\44\x31") !== false)) { goto i9Mfn; } goto PsQks; KJohC: StTmw: goto EU5mi; gZmGp: rmC9B: goto Q7mrS; fa7Qr: $data["\152\157\x75\162\156\141\154\x5f\x61\x63\x74\x69\166\x65"] = is_dir(DIR_APPLICATION . "\x6d\x6f\144\x65\x6c\x2f\152\x6f\165\162\156\x61\154\62") || is_dir(DIR_APPLICATION . "\x6d\x6f\x64\x65\x6c\x2f\152\x6f\x75\162\156\141\154\63"); goto obHup; FwIVx: goto z8p_W; goto lQu4F; Sb0jx: if ($this->OC_V22X) { goto Rs78v; } goto INNuR; UmvVT: NSF3Y: goto mr51M; KAChM: pbejP: goto fuAYw; dbOze: goto jmPSq; goto FV9fK; QLNdn: QVHjQ: goto Hr76T; XteGL: O1PDs: goto CrCl3; wShAW: FyqtB: goto YE3MU; Jz83I: $this->document->addStyle(self::$ASSET_PATH . "\152\x71\x75\x65\x72\x79\x2d\145\144\151\x74\x61\x62\154\x65\56\x63\163\163"); goto JcBKM; L8fGO: goto HeLGV; goto pDNL0; KHPb9: XYe2v: goto tOuMH; PJGjp: $this->error["\x77\141\162\x6e\151\x6e\147"] = "\x57\141\x72\156\151\x6e\x67\40\x3a\40\x62\x6f\164\x68\40\x76\x71\155\157\x64\40\141\x6e\x64\x20\157\x63\x6d\157\x64\40\x76\x65\162\163\x69\x6f\x6e\40\141\x72\145\40\x69\156\x73\x74\141\154\154\145\x64\x3c\142\x72\x2f\x3e\x2d\x20\144\x65\154\x65\164\x65\x20\57\166\x71\x6d\x6f\144\57\170\155\x6c\57" . self::MOD_FILE . "\x2e\x78\155\154\x20\x69\146\40\171\x6f\165\40\167\x61\x6e\x74\40\x74\157\40\x75\x73\x65\x20\157\x63\x6d\x6f\144\40\x76\145\x72\x73\x69\x6f\156\x3c\x62\162\x2f\x3e\55\x20\x6f\x72\40\x64\145\x6c\145\x74\145\x20\x2f\163\x79\163\164\x65\155\x2f" . self::MOD_FILE . "\x2e\x6f\143\155\x6f\144\56\170\155\154\x20\151\146\40\171\x6f\165\x20\x77\x61\156\x74\40\x74\157\x20\x75\163\145\40\166\161\x6d\157\144\40\x76\145\x72\163\x69\x6f\156"; goto moaNm; IBw26: goto IKppR; goto c0pmh; kVpaN: $ieocD = filesize($mMubI); goto GsjWO; fzl30: $xfz3p = $this->url->link("\155\141\x72\153\x65\x74\160\154\141\x63\145\x2f\x65\170\x74\x65\156\x73\x69\157\x6e", "\x74\x79\x70\145\x3d\155\x6f\144\165\x6c\145\46" . $this->token, "\x53\123\x4c"); goto C2tp2; LhgYO: $MGEsw = (array) @json_decode($KntYp); goto GzJat; NVtaz: goto R6pkt; goto wIySS; JeCNV: $data["\x63\154\151\137\x6c\157\x67"] = $data["\x63\154\x69\x5f\x6c\x6f\147\137\154\151\x6e\153"] = ''; goto idG3M; vDrU9: $data["\155\157\144\165\154\x65\137\162\157\165\x74\145"] = self::$LINK; goto DBvGq; desbV: wig5K: goto T0M9X; trIFh: Dkal0: goto QTXtG; F47tw: goto fXTLL; goto Ja3I6; JQMDc: $data["\117\103\x5f\126\61\x35\x31"] = $this->OC_V151; goto Yxu0v; o2mDb: $this->document->addScript(self::$ASSET_PATH . "\x6a\161\x75\145\x72\x79\x2d\x6d\x69\147\162\x61\x74\145\x2e\x6a\163"); goto SHjnZ; UxJOm: ONRO2: goto xs5Zo; nZZKl: if ($data["\155\x6f\x64\x75\154\145\x5f\164\x79\x70\145"] == "\x6f\x63\x6d\x6f\x64") { goto PMOm6; } goto R8z5h; TJj2s: goto TlGrc; goto OpATk; Bcexg: goto sEW2r; goto l4OHH; WkcRT: AyyjU: goto hxO1g; ip5J_: $glDMO[] = $dfq9k . "\144\x65\160\x74\x68"; goto fVgkt; B583F: @rename(DIR_APPLICATION . "\x63\x6f\x6e\x74\x72\157\154\x6c\x65\x72\x2f\x66\145\145\x64\x2f\163\145\157\x70\x61\x63\153\141\147\145\137\163\151\x74\x65\155\141\160\56\160\x68\160", DIR_APPLICATION . "\x63\157\156\x74\162\157\x6c\154\145\x72\x2f\x66\x65\x65\144\57\163\x65\x6f\x70\141\x63\x6b\x61\147\x65\x5f\x73\151\164\x65\155\x61\x70\56\160\x68\x70\x5f\x64\x69\163\141\142\x6c\145\144"); goto jY13w; IERSE: JvUeH: goto Q_pOR; PXOa5: wqPkW: goto fzl30; UsPKO: bYxCK: goto cfaS1; vlqAp: goto peZwj; goto TwPcP; pSla1: goto W9O5y; goto PEpus; b11yH: if (!(is_file(DIR_SYSTEM . "\x2e\x2e\57\166\161\x6d\157\144\x2f\170\x6d\154\x2f" . self::MOD_FILE . "\56\170\x6d\x6c") && is_file(DIR_SYSTEM . "\56\56\x2f\x73\x79\x73\164\145\155\x2f" . self::MOD_FILE . "\x2e\x6f\143\155\157\x64\x2e\170\155\x6c"))) { goto pC9VL; } goto PJGjp; fJt6f: JJqsH: goto L5lWL; uqpTl: bA44i: goto AmDxN; w_9Wl: $this->load->model("\x73\x61\154\x65\57\143\165\163\x74\x6f\155\145\162\137\147\x72\157\x75\160"); goto zJQI8; KubLq: if (extension_loaded("\155\142\163\x74\x72\x69\x6e\x67")) { goto dVewr; } goto DK53K; cqbWx: IZnGn: goto tzsqg; PpgDC: sRfJY: goto LzoWL; YuWnB: goto F7leC; goto PdqKe; iLhLV: goto ugQJ2; goto desbV; Dhg41: goto ZYRX8; goto maKBr; Iz5Kz: iwNr8: goto jYGjx; HoQ4U: goto xoWwu; goto VUeh0; WVkwz: NF0sK: goto ErqUl; CrCl3: if (!is_file(DIR_CATALOG . "\x2e\x2e\x2f\x76\x71\x6d\157\x64\x2f\170\x6d\154\57\x6d\165\154\x74\x69\154\151\156\x67\x75\141\x6c\x5f\x73\145\x6f\56\170\x6d\x6c")) { goto tciec; } goto BGpyO; WR4Xn: TlGrc: goto TeSIv; dZdJm: goto ZUHkM; goto WnSX6; KYeIU: $this->document->addScript(self::$ASSET_PATH . "\151\164\x6f\147\x67\154\145\56\152\163"); goto Lx0Fy; l7AAM: $data["\x73\x74\x79\154\145\137\x73\x63\x6f\x70\145\144"] .= str_replace("\151\x6d\x67\57", self::$ASSET_PATH . "\151\x6d\147\57", file_get_contents(self::$ASSET_PATH . "\147\153\144\55\x74\x68\145\155\x65\56\x63\163\x73")); goto iLGGN; us_B6: $glDMO[] = $dfq9k . "\155\157\x64\x65"; goto ip5J_; XGAmu: S20PO: goto hud_m; aPFvN: $this->load->model("\x73\145\x74\164\x69\156\x67\57\x73\145\164\164\151\156\147"); goto BTV3I; YE3MU: goto xlb1G; goto NYzmT; beXVm: goto XSgis; goto YnzO_; SYFFf: $glDMO[] = $dfq9k . "\x72\x65\x6d\157\166\145\x5f\x74\141\147"; goto LdWEy; F87gY: Ozol2: goto dhVoH; oU6mg: z8p_W: goto ilTFm; XWhny: HeLGV: goto RXXZt; FV9fK: zmXyh: goto gCUf2; TeR3y: if (version_compare(VERSION, "\x33", "\x3e\x3d")) { goto wqPkW; } goto W1B6n; EFbfg: goto FMzvq; goto yeyGu; vXKlM: $data["\x5f\165\x72\x6c"] =& $this->url; goto NvK5r; mtyne: goto WaDVC; goto xbTMV; xbTMV: goto HWj91; goto j4a6M; cNZqa: PL_Zz: goto VXjSA; vSET7: $this->document->addStyle(self::$ASSET_PATH . "\152\x71\x75\x65\x72\x79\56\144\141\x74\x61\x54\x61\x62\x6c\145\163\x2e\155\151\x6e\x2e\143\163\163"); goto TXsHI; Yt22v: $this->request->server["\x52\105\x51\x55\x45\123\x54\137\115\105\x54\110\x4f\x44"] = "\x47\105\x54"; goto xH49a; eZ0QL: $data["\146\157\157\164\x65\x72"] = $this->load->controller("\143\x6f\155\x6d\157\156\x2f\146\157\157\x74\x65\162"); goto mVUk2; v2529: foreach ($Lw2AU as $tV0zs) { $VslUq[] = $tV0zs["\143\157\x64\145"]; Gpf7f: } goto Rqqf0; SC202: if (!$RKWTW || isset($this->request->get["\162\x65\146\x72\145\x73\150"])) { goto wll4p; } goto AP4pm; MXPSm: kD8OF: goto Zozj3; g_Sed: WEwMY: goto xFzTm; xs5Zo: $this->load->model("\154\157\x63\141\154\151\163\x61\x74\151\x6f\156\57\163\164\157\x63\153\x5f\x73\x74\x61\164\x75\163"); goto nR3Mh; tF1pd: $data["\x63\x6f\154\x75\155\156\x5f\154\x65\146\x74"] = ''; goto Ur7Ka; G_V7g: if (empty($MGEsw["\x73\x75\143\143\x65\x73\x73"])) { goto Hm25k; } goto lhSZ1; vmGvA: sb6ug: goto qk9bq; lDBSc: IKppR: goto EFzR6; AP4pm: goto Xh0m8; goto Pcqen; tuQzZ: ugQJ2: goto wTwXj; f0j2a: if (isset($this->session->data["\145\x72\162\157\x72"])) { goto lnFgc; } goto Iz0DW; RpPy1: OhI8w: goto XfoSD; T0M9X: if (!version_compare(VERSION, "\x32", "\76\x3d")) { goto il4__; } goto p0wtn; eDWVu: S_BIf: goto Bcexg; rcqeH: goto pF5Dh; goto jqU2e; Jd09w: foreach ($XktyI as $rhdWd => $Zu00a) { goto OAZxg; OAZxg: if (empty($y46IY[$Zu00a["\143\x6f\x64\x65"]])) { goto gPVpD; } goto YDDj3; YDDj3: unset($XktyI[$rhdWd]); goto PzU1e; PzU1e: gPVpD: goto D9OqA; D9OqA: aei_d: goto crSu9; crSu9: } goto AlV64; OFqy0: goto zNNHP; goto WIpHD; Nxcx_: ahhud: goto BO2J2; o9zAR: $this->response->setOutput($this->load->view("\164\157\x6f\x6c\x2f\147\x6b\144\137\154\x69\x63\x65\x6e\163\145\56\x74\160\x6c", $data)); goto iqjDY; hxO1g: $data["\163\165\143\143\x65\163\x73"] = $this->session->data["\163\165\x63\x63\145\x73\163"]; goto d3my7; UNzEb: $data["\x65\162\x72\x6f\162"] = $MGEsw["\145\162\162\x6f\x72"]; goto zKet3; OpATk: jmPSq: goto NZJPD; QSEbR: if (!(strpos(strtolower($_SERVER["\x53\x45\122\x56\105\122\x5f\x53\117\106\x54\127\x41\x52\105"]), "\141\x70\141\x63\x68\145") !== false && !is_file(DIR_CATALOG . "\x2e\x2e\x2f\x2e\150\164\141\x63\143\145\163\x73"))) { goto O1PDs; } goto bTwB0; Dj2Yc: $R7oWZ = $this->db->query("\123\x45\114\105\x43\x54\40\x2a\x20\x46\x52\x4f\x4d\x20" . DB_PREFIX . "\x73\145\164\164\151\x6e\147\40\x57\x48\105\x52\105\x20\163\164\157\162\x65\137\151\x64\x20\x3d\40\47" . $UEbbE . "\x27"); goto T93KV; dTky9: Mplkr: goto DfZc3; tbF5r: stq6R: goto QgNI2; TrsBr: $data["\x62\x75\164\x74\x6f\x6e\x5f\x72\x65\x6d\157\x76\x65"] = $this->language->get("\142\165\x74\164\x6f\x6e\x5f\162\145\x6d\x6f\x76\x65"); goto JMXKA; DIcKV: $yygZ5 = "\46\163\x74\x6f\162\145\137\x69\x64\75" . $UEbbE; goto CXr_n; Gttr5: tlHjw: goto gh32N; T93KV: foreach ($R7oWZ->rows as $ZoaKJ) { goto mWOZ9; w515t: A98WX: goto Nzl5u; u8bRx: if ($this->OC_V21X) { goto A98WX; } goto Ke92J; Nzl5u: $this->config->set($ZoaKJ["\x6b\145\171"], json_decode($ZoaKJ["\x76\141\x6c\x75\x65"], true)); goto nwN4D; XfH9V: goto R2SoO; goto w515t; T84p6: G1a9E: goto QDqe9; va7WV: $this->config->set($ZoaKJ["\x6b\145\171"], $ZoaKJ["\166\x61\154\165\x65"]); goto zwJyA; Ke92J: $this->config->set($ZoaKJ["\153\145\x79"], unserialize($ZoaKJ["\x76\141\154\165\145"])); goto XfH9V; i4sFo: goto iDEL2; goto KoBN7; zwJyA: iDEL2: goto T84p6; nwN4D: R2SoO: goto i4sFo; KoBN7: aROFm: goto va7WV; mWOZ9: if (!$ZoaKJ["\x73\x65\x72\x69\x61\154\151\172\145\x64"]) { goto aROFm; } goto u8bRx; QDqe9: } goto mz7Q1; v7x0d: if (!($this->config->get("\155\x6c\163\x65\157\137\146\x6c\x61\147") || isset($this->request->post["\155\154\163\145\x6f\x5f\146\x6c\x61\147"]) && $this->request->post["\x6d\154\x73\x65\x6f\x5f\x66\x6c\141\147"])) { goto piCNG; } goto bAzPF; Y58Ab: $Lw2AU = $this->model_setting_extension->getInstalls(); goto v2529; kVydk: fsJHu: goto i09It; zDIk0: Zxs01: goto iaKGW; NbOsx: $data["\x68\x65\141\x64\x65\x72"] = $this->load->controller("\143\157\x6d\x6d\x6f\156\57\150\x65\141\x64\145\162"); goto zOEPj; gCUf2: sJqH6: goto BD_gn; y0sVb: goto SDUK9; goto MXPSm; WCdOI: if (empty($y46IY)) { goto wqsBC; } goto Jd09w; e2cjG: OJDud: goto VLnRc; gtREI: PMOm6: goto EK28l; ijHHG: goto P6cpl; goto WVkwz; Uhf1y: $data["\x6a\x6f\x75\x72\156\141\154\63\x5f\x61\143\164\151\x76\x65"] = is_dir(DIR_APPLICATION . "\155\157\x64\145\x6c\57\x6a\157\165\162\156\x61\x6c\x33"); goto qtj2r; M1Wlq: hw3sc: goto J3YX1; a6xyT: WTMfi: goto zko0O; Brz2W: goto grxUj; goto RR6jr; OBwxw: file_put_contents(DIR_CATALOG . "\56\56\x2f\x2e\x68\x74\x61\143\143\145\x73\x73", $pulAQ); goto dTky9; Aohj5: otT6f: goto S8wnQ; zJQI8: $data["\x63\x75\x73\x74\x6f\155\x65\x72\137\147\162\157\x75\x70\163"] = $this->model_sale_customer_group->getCustomerGroups(); goto vWvCp; VUeh0: xlb1G: goto ZzYvI; EMUv7: O7NDK: goto JCIe_; eU1sh: wWOde: goto C432k; zNLR0: foreach (array(self::MOD_FILE, "\141\137" . self::MOD_FILE, "\x7a\x5f" . self::MOD_FILE) as $lJFer) { goto AHWQa; Cz9_2: qo1VS: goto Up1o5; RJu2S: goto qNdtv; goto WthvM; n1DP2: goto UhoiE; goto edfmN; XgwkT: if (is_file(DIR_SYSTEM . "\56\x2e\57\x73\171\x73\164\x65\155\x2f" . $lJFer . "\56\x6f\143\x6d\157\x64\56\x78\x6d\x6c")) { goto MXPQF; } goto QXQR9; uChVE: $data["\x6d\157\x64\x75\x6c\145\x5f\x76\x65\x72\x73\151\157\x6e"] = @simplexml_load_file(DIR_SYSTEM . "\x2e\56\57\163\x79\163\164\145\x6d\57" . $lJFer . "\x2e\157\x63\155\157\x64\x2e\170\x6d\x6c")->version; goto nyqNT; NDTJ7: qNdtv: goto d3KO9; AM_UF: $data["\155\x6f\x64\165\x6c\x65\x5f\x74\x79\x70\145"] = ''; goto RJu2S; d3KO9: goto GNRkP; goto Cz9_2; UR6HU: goto Co1Sr; goto NDTJ7; edfmN: HgDeF: goto IMQhG; b2VG4: GNRkP: goto n1DP2; QXQR9: $data["\x6d\157\144\165\x6c\145\137\x76\x65\162\163\x69\157\156"] = "\156\x6f\x74\x20\x66\157\x75\x6e\x64"; goto AM_UF; xcPoz: $data["\155\x6f\x64\x75\x6c\x65\137\164\x79\x70\x65"] = "\x76\x71\x6d\x6f\x64"; goto b2e_H; CEGXW: goto Co1Sr; goto b2VG4; qWiLb: $data["\x6d\x6f\144\x75\154\145\137\x74\x79\x70\145"] = "\166\161\x6d\157\x64"; goto CEGXW; HGE6h: UhoiE: goto nMrIq; WthvM: MXPQF: goto uChVE; nyqNT: $data["\155\x6f\144\165\x6c\x65\137\x74\171\x70\145"] = "\x6f\x63\155\x6f\x64"; goto UR6HU; nMrIq: Wq2Ij: goto RA3QJ; Up1o5: $data["\155\x6f\144\165\154\145\137\x76\145\162\x73\x69\157\156"] = @simplexml_load_file(DIR_SYSTEM . "\56\56\x2f\166\161\155\x6f\144\57\170\155\x6c\x2f" . $lJFer . "\x2e\170\155\154")->version; goto qWiLb; b2e_H: goto Co1Sr; goto HGE6h; AHWQa: if (defined("\104\111\122\137\105\x58\124\x45\116\x53\111\x4f\x4e") && is_file(DIR_EXTENSION . self::MODULE . "\x2f" . $lJFer . "\56\x78\x6d\154")) { goto HgDeF; } goto gmHBC; IMQhG: $data["\x6d\x6f\144\165\x6c\x65\137\x76\x65\162\x73\151\157\156"] = @simplexml_load_file(DIR_EXTENSION . self::MODULE . "\x2f" . $lJFer . "\x2e\x78\x6d\154")->version; goto xcPoz; gmHBC: if (is_file(DIR_SYSTEM . "\56\56\57\166\x71\x6d\157\144\57\170\x6d\x6c\57" . $lJFer . "\x2e\x78\x6d\154")) { goto qo1VS; } goto XgwkT; RA3QJ: } goto lPkC_; Ja3I6: Y2ip6: goto ZlxUE; DHIOl: $data["\x62\x75\x74\x74\x6f\x6e\137\x63\141\156\x63\145\x6c"] = $this->language->get("\142\x75\x74\164\157\156\137\x63\141\156\143\145\x6c"); goto GjPR2; s6sxA: if (!($this->config->get("\x63\157\x6e\x66\151\x67\x5f\x73\145\157\137\165\162\x6c\x5f\x74\171\x70\145") == "\x73\x65\157\137\160\162\x6f")) { goto OJDud; } goto ow405; aT7yy: goto Ozol2; goto S6ZkA; UO8jK: if ($UEbbE) { goto sNy7f; } goto hI4rY; YNjue: CVK2s: goto P5fG4; VXjSA: goto c6SyB; goto zcnON; RDFxE: p1Ixd: goto wdSih; LmAbP: if (version_compare(VERSION, "\62", "\76\x3d")) { goto P8Pym; } goto Tl5r5; qHFsN: qt199: goto KxyoD; NtiSD: Wydk5: goto NTfTf; DBvGq: $data["\x72\x6f\x75\164\x65\x5f\163\x65\160"] = version_compare(VERSION, "\64", "\x3c") ? "\57" : "\174"; goto V8KtV; gh32N: goto MGEfU; goto Q_QQI; xIxNI: $data["\164\157\153\145\156"] = $this->token; goto YHqKR; CPizL: c6SyB: goto tJ7JO; NMXkQ: il4__: goto xgqUR; IibAM: goto SCmO8; goto Iz5Kz; tWtSO: $this->model_setting_setting->editSetting(md5(HTTP_SERVER . self::MODULE), array(md5(HTTP_SERVER . self::MODULE) => $MGEsw["\x69\156\146\157"])); goto rYqOJ; IZ0gZ: $this->request->post = array("\x6c\x69\143\x5f\x6e\165\x6d\142\145\162" => $data["\x6c\151\143\145\156\163\145\x5f\151\156\146\157"]["\154\151\143\145\x6e\x73\x65"]); goto vlqAp; LhssX: goto iwNr8; goto UsPKO; Tgpxq: EsHWq: goto kVydk; ck01b: pOwY1: goto A1Vgu; Zozj3: if (!$this->request->post["\x6c\151\x63\x5f\156\165\x6d\142\x65\162"] || strlen(trim($this->request->post["\154\x69\x63\137\156\165\155\142\x65\x72"])) != 17) { goto shMeG; } goto w1IeK; QTXtG: curl_setopt($KwAQS, CURLOPT_BINARYTRANSFER, true); goto AlNw7; J3YX1: goto cOQlJ; goto gtREI; qFgpB: $this->document->addStyle(self::$ASSET_PATH . "\141\167\145\x73\x6f\x6d\145\57\143\163\163\x2f\x66\157\156\x74\x2d\141\167\x65\x73\x6f\x6d\x65\x2e\155\151\156\x2e\143\x73\163"); goto XUT7n; CeRSL: BUV62: goto zdGY3; SW5tH: tYa6i: goto Axs9T; WyOJ6: goto NF0sK; goto gdsgA; yLWsk: FMzvq: goto M1Wlq; D0wuj: if (empty($data["\x65\162\162\157\162"])) { goto tlHjw; } goto iFhcR; tInOR: goto q3mXM; goto yXFi9; yXFi9: SDUK9: goto g7YSI; AmDxN: $RKWTW = false; goto u8QAY; dNIQq: hxfHh: goto P6Ej8; AHi1S: VmM3E: goto WQj4T; ni9lW: goto pbejP; goto XuGlZ; rsY0V: $data["\163\165\x63\x63\x65\163\x73"] = ''; goto GnCao; HA0uW: goto VmM3E; goto icFdC; TuUk8: BojEF: goto DBaZ0; rUqv1: $this->session->data["\145\x72\x72\157\x72"] = "\111\x6e\163\164\141\x6c\154\x20\x6e\x6f\164\x20\x63\157\x6d\160\x6c\145\164\145\x20\x3a\40\x6d\165\x6c\164\x69\154\x69\156\x67\165\x61\x6c\137\163\x65\157\40\x63\154\141\163\x73\x20\x64\x65\x63\x6c\141\162\x61\164\151\157\156\40\x6e\x6f\164\40\146\x6f\165\156\x64\40\151\x6e\40\151\x6e\144\x65\170\x2e\x70\150\x70\54\40\155\141\x79\142\x65\40\164\x68\x65\x20\146\x69\154\x65\40\167\x61\163\x20\156\157\164\40\167\162\151\164\145\x61\142\x6c\145\x2c\40\x6d\141\x6e\165\141\154\x20\x70\x72\157\x63\145\x64\165\162\x65\x20\x3a\x20\x3c\142\162\57\76\55\40\157\160\x65\156\x20\x69\156\x64\145\170\56\160\x68\x70\74\142\162\x20\57\76\55\x20\146\x69\156\144\x20\x74\x68\x65\x20\x74\145\170\x74\40\50\167\x69\x74\150\x6f\165\x74\40\x6f\x75\164\164\145\162\x20\x71\165\x6f\164\145\163\x29\x3a\40\44\x6c\x61\x6e\x67\165\141\147\x65\163\40\75\x20\x61\x72\162\141\171\50\51\73\74\x62\162\x2f\x3e\x2d\x20\x61\x64\144\40\x6a\165\x73\x74\40\142\145\x6c\x6f\167\40\x74\x68\x65\40\x70\162\145\x76\x69\157\165\163\40\154\x69\x6e\145\40\164\150\151\x73\40\x74\x65\170\x74\72\x20\x24\x6d\165\154\164\151\154\151\156\x67\165\x61\x6c\x20\x3d\40\x6e\145\167\40\155\x75\x6c\x74\151\x6c\151\x6e\147\165\141\154\x5f\x73\x65\157\50\x24\x72\145\147\x69\163\x74\x72\x79\x29\x3b\x20\44\x6d\165\154\x74\x69\x6c\x69\x6e\147\x75\x61\154\55\76\144\x65\x74\x65\x63\x74\50\x29\x3b"; goto p1wVd; iFhcR: goto fsJHu; goto Gttr5; FosLe: GY8B0: goto VuO5b; mN7_K: if (version_compare(VERSION, "\64", "\76")) { goto b8dg4; } goto clzOL; C2tp2: YaG9G: goto XsvF9; zuteY: CClwY: goto P1aAT; W9hnQ: $TqFxN[] = $this->config->get("\155\x6c\x73\145\157\x5f\x65\156\x61\142\x6c\145\144"); goto Q7KP3; h6zMB: $this->session->data["\143\165\x72\162\145\156\x74\124\141\x62"] = $this->request->get["\164\x61\142"]; goto NtiSD; UzcxS: $VslUq = $this->model_extension_extension->getInstalled("\146\x65\145\144"); goto RDFxE; xH49a: goto JnJRz; goto g_Jkz; Axs9T: $data["\x6c\x69\x63\145\x6e\x73\x65\x5f\x69\156\x66\157"] = json_decode(base64_decode($I2PwC), 1); goto jwRaD; iADIk: $this->load->model("\163\145\164\164\x69\x6e\147\x2f\x73\145\x74\x74\x69\156\x67"); goto dbIwA; qnJiu: $this->install("\x72\145\x64\x69\x72"); goto y_ntd; a2nQh: goto v5VXr; goto cNZqa; BO2J2: $I2PwC = $this->config->get(md5(HTTP_SERVER . self::MODULE)); goto vgn10; ipkjI: goto wWOde; goto Gdrq9; I9SsE: $data["\154\141\x6e\147\x75\x61\147\145\x73"] = $XktyI; goto U18oJ; SvBDS: $this->data =& $data; goto Es1dX; Ny7f1: W9O5y: goto mWhRd; Yy91z: $zOm7L->addPath("\145\170\x74\x65\156\x73\x69\x6f\156\x2f\143\157\x6d\x70\154\x65\x74\145\x5f\x73\x65\157", DIR_EXTENSION . "\143\x6f\x6d\x70\x6c\145\x74\x65\x5f\x73\145\157\x2f\x61\144\x6d\x69\x6e\x2f\166\x69\x65\x77\x2f\164\x65\155\160\154\x61\164\145\57"); goto HthF8; V8KtV: $data["\155\157\x64\165\x6c\145\137\162\x6f\x75\164\x65\137\x73\145\160"] = self::$LINK . $data["\162\x6f\165\x74\x65\x5f\x73\x65\160"]; goto O0gtf; f9N1E: QDqYA: goto wLhPW; jA1Xy: $glDMO[] = $dfq9k . "\150\x6f\x6d\145\x6c\151\156\153"; goto SQ6kE; aonE0: cOQlJ: goto vo1Jj; c7zrD: $this->session->data["\x65\162\162\x6f\x72"] = "\x49\164\x20\163\145\145\x6d\163\x20\171\x6f\165\40\150\141\x76\145\x20\x69\156\x73\x74\141\x6c\154\x65\144\x20\x61\x6e\157\164\150\x65\162\40\154\x61\x6e\147\x75\x61\x67\145\54\x20\x70\154\x65\x61\x73\x65\40\163\141\x76\x65\x20\155\157\144\165\x6c\x65\40\x6f\x70\x74\151\157\156\x73\40\164\x6f\x20\x61\x63\164\151\x76\141\164\x65\x20\155\165\x6c\164\151\x6c\151\x6e\x67\165\x61\x6c\x20\x68\x61\x6e\144\x6c\151\x6e\147"; goto TuUk8; b0YVg: dVewr: goto UO8jK; i1OZF: $pulAQ = str_replace("\122\145\167\x72\x69\x74\x65\x52\x75\x6c\x65\40\136\x28\77\x3a\50\x3f\72\x28\x5c\167\173\62\x7d\51\50\77\72\57\x7c\134\172\x29\51\77\x28\x3f\72\57\174\134\x7a\x29\77\51\77\50\x3f\72\50\x5b\136\x3f\x5d\x2a\51\51\x3f\x20\151\156\144\145\170\56\x70\x68\160\77\x5f\x72\x6f\x75\x74\145\x5f\75\x24\62\x26\163\151\x74\145\x5f\154\141\x6e\147\165\x61\147\x65\75\x24\61\40\x5b\x4c\54\121\123\x41\x5d", '', $pulAQ); goto OBwxw; mr51M: KuVBd: goto jaMn4; f4Igy: if ($RKWTW) { goto pOwY1; } goto uJV1m; jVu8q: $this->document->addScript(self::$ASSET_PATH . "\x74\x6f\147\x67\154\145\x72\x2e\152\163"); goto X9K4Y; if_dy: WXj4H: goto TZE_h; q_0kd: jC3yu: goto lrKJ1; y6LDy: goto ne10O; goto mM6ky; YwXeI: Oxzmp: goto oNgZO; uJV1m: goto msLwd; goto ck01b; nhT2L: WQ00i: goto tF1pd; DHaCG: LYm80: goto p6bdu; iB7ST: MHxBE: goto s_YlN; Waydq: u8lxy: goto NbOsx; S6Arn: $this->session->data["\x65\x72\162\157\x72"] = "\x4f\103\40\166\61\56\65\x20\x2d\40\x50\x6c\x65\x61\163\x65\x20\144\145\x6c\145\164\x65\x20\x74\150\145\40\146\157\154\x64\x65\x72\x20" . DIR_APPLICATION . "\x63\157\156\164\x72\x6f\x6c\154\x65\x72\57\145\170\164\145\156\163\151\157\x6e\x2f\x6d\157\144\165\154\145"; goto NoZi0; ezHYS: $this->session->data["\145\162\162\x6f\x72"] = "\x54\x68\145\162\x65\40\x69\163\40\x73\157\155\145\40\165\162\x6c\163\40\167\x68\x69\143\x68\40\150\x61\166\x65\x20\x69\156\x63\x6f\x72\162\145\143\164\40\154\141\x6e\147\x75\141\147\x65\x20\141\163\163\151\x67\156\141\164\151\157\x6e\54\x20\160\154\145\141\x73\x65\40\x67\x6f\x20\151\x6e\40\115\141\163\163\x20\x55\x70\144\141\x74\145\x20\x61\156\x64\40\144\x6f\x20\141\x20\x22\x43\154\x65\141\x6e\40\x75\160\x22"; goto dNIQq; H4UTK: $data["\165\160\x67\162\x61\x64\x65\x5f\165\x72\154"] = $this->url->link(self::$LINK_SEP . "\x75\160\x67\x72\x61\144\145", $this->token, "\x53\x53\x4c"); goto iRPTY; zcnON: imG3F: goto YRMW1; pQ1H2: WaDVC: goto NVtaz; Tn8fF: D1q0_: goto JZ75x; yeyGu: RFbg9: goto jr8au; JZ75x: $a_wta = []; goto Mf_XZ; Th9Qb: goto iLU_Q; goto Nxcx_; q505M: $data["\x6c\151\x6e\153\137\x73\x69\x74\145\x6d\x61\x70"] = $this->url->link("\x66\145\145\144\x2f\141\144\x76\141\x6e\x63\145\x64\137\163\151\164\x65\x6d\x61\160", $this->token, "\x53\123\x4c"); goto r7L3h; YLLsl: $this->template = "\x74\x6f\x6f\x6c\x2f\147\x6b\x64\137\x6c\x69\143\x65\x6e\x73\145\56\164\x70\x6c"; goto IybqL; zOEPj: goto frHiO; goto Ny7f1; QQdRC: $modification_active = false; goto FxsyT; t5ibL: if (!(strpos($Kcjpq, "\x6e\x65\167\x20\x6d\x75\154\164\151\154\151\x6e\147\165\x61\x6c\x5f\163\x65\x6f") === false)) { goto qhash; } goto rUqv1; okULr: goto p1Ixd; goto imPT5; p6bdu: $xfz3p = $this->url->link("\x65\170\x74\x65\x6e\163\151\157\156\57\145\170\x74\145\x6e\x73\x69\x6f\x6e", "\x74\171\160\x65\x3d\155\157\144\165\x6c\145\46" . $this->token, "\123\123\x4c"); goto uvLDV; ykNSo: AQi4L: goto f9N1E; vMXBJ: Owqly: goto rFOE8; GQKzO: piCNG: goto J8wkT; Rfk38: M1PSK: goto lxsWx; HAxdm: if (version_compare(VERSION, "\62", "\76\75")) { goto JDDUE; } goto CPKH1; xOnEt: Ss6pf: goto rehCP; WzRGv: if (version_compare(VERSION, "\63", "\76\x3d")) { goto egvC5; } goto HAxdm; s0yf2: $pulAQ = str_replace("\43\x52\x65\x77\x72\151\164\x65\x52\165\x6c\x65\x20\136\50\133\x5e\x3f\135\x2a\x29\x20\x69\x6e\144\x65\170\56\160\x68\160\x3f\x5f\x72\x6f\165\x74\x65\x5f\75\44\61\x20\133\x4c\54\121\123\x41\x5d", "\x52\x65\x77\x72\x69\x74\x65\x52\165\x6c\x65\x20\x5e\50\133\136\77\135\52\51\x20\x69\156\144\x65\x78\56\x70\150\x70\77\x5f\162\x6f\x75\164\x65\137\x3d\x24\x31\x20\x5b\x4c\54\x51\123\101\135", $pulAQ); goto i1OZF; ErqUl: curl_setopt($KwAQS, CURLOPT_REFERER, "\150\x74\164\x70\x3a\57\x2f{$_SERVER["\110\x54\x54\120\137\110\x4f\123\x54"]}{$_SERVER["\122\x45\121\x55\x45\123\124\x5f\125\122\111"]}"); goto IibAM; iirF7: QzCfQ: goto s0yf2; EX6T8: $glDMO = array("\155\154\x73\x65\157\137\145\x6e\x61\142\x6c\x65\x64", "\155\154\163\145\x6f\137\x75\x72\154\137\x61\142\x73\157\154\x75\164\145", "\155\154\x73\145\x6f\x5f\x66\162\151\145\156\x64\154\x79", "\x6d\154\163\145\x6f\137\155\165\x6c\x74\151\x73\x74\x6f\x72\145", "\x6d\x6c\x73\x65\x6f\x5f\142\x61\x63\153\x75\x70", "\x6d\154\x73\145\x6f\137\x34\60\x34", "\x6d\154\x73\x65\x6f\x5f\x72\145\144\151\162\145\x63\x74", "\x6d\154\163\145\x6f\x5f\x61\x75\164\157\154\x69\x6e\153", "\155\154\163\145\157\137\x61\x62\163\157\154\165\164\145", "\155\154\163\145\157\137\x72\145\144\x69\162\x65\x63\164\x5f\144\x79\156\x61\x6d\151\x63", "\x6d\x6c\163\145\157\137\162\x65\144\151\162\145\x63\164\137\x68\x74\x74\x70", "\x6d\x6c\163\145\157\137\162\x65\144\151\x72\145\143\x74\137\x63\141\156\x6f\156\x69\x63\x61\x6c", "\x6d\154\163\145\157\137\143\x61\x74\x5f\x73\154\141\x73\150", "\155\x6c\x73\145\157\x5f\x72\145\x64\151\162\137\162\x65\166\151\x65\167\x73", "\155\154\163\x65\157\x5f\143\x61\x63\x68\145", "\x6d\x6c\163\x65\157\137\x70\x72\x65\154\157\x61\x64", "\x6d\154\163\145\x6f\x5f\x62\141\156\x6e\x65\x72\x73", "\155\x6c\163\145\157\x5f\163\x70\145\143\x69\x61\x6c\137\x67\162\157\165\x70", "\155\154\163\145\157\x5f\x66\x6f\x72\155\141\x74\137\164\141\x67", "\x6d\x6c\x73\x65\157\x5f\x66\x69\170\137\163\x65\x61\162\x63\150", "\x6d\x6c\x73\x65\x6f\137\146\151\170\x5f\143\141\162\164", "\155\x6c\163\x65\x6f\137\x65\x64\x69\x74\157\x72", "\x6d\154\163\x65\x6f\x5f\163\150\x6f\162\x74\143\165\x74", "\155\x6c\x73\145\x6f\137\x68\145\141\x64\151\156\x67\x73", "\155\154\x73\x65\x6f\x5f\64\x30\x34\x5f\x6c\x6f\147", "\x6d\154\163\145\x6f\137\x34\60\x34\x5f\146\151\x6c\x74\145\x72", "\155\154\x73\145\x6f\x5f\x34\x30\x34\137\146\x69\154\164\x65\162\x5f\145\170\164", "\155\154\163\145\x6f\137\x34\x30\64\x5f\162\145\144\x69\162", "\x6d\x6c\163\145\x6f\137\x66\154\x61\x67\x5f\x6d\157\x64\x65", "\x6d\x6c\163\145\157\137\x73\164\x6f\x72\145\x5f\155\157\x64\145", "\x6d\154\163\145\157\137\146\x6c\x61\147", "\x6d\154\163\145\x6f\x5f\146\154\141\x67\137\x64\x65\x74\145\x63\x74", "\155\154\x73\x65\157\x5f\146\x6c\x61\147\x5f\163\x68\x6f\162\164", "\x6d\x6c\x73\x65\157\137\146\154\x61\147\x5f\x75\x70\160\x65\x72", "\x6d\154\163\145\x6f\x5f\146\154\141\x67\137\144\x65\146\x61\165\x6c\x74", "\x6d\154\x73\145\157\x5f\146\154\141\147\137\x63\165\163\164\157\155", "\155\x6c\163\145\157\137\x74\141\x67", "\x6d\154\x73\145\157\x5f\x73\157\x72\164", "\x6d\x6c\163\145\x6f\137\163\145\x61\162\143\150", "\155\x6c\163\x65\x6f\x5f\x70\x61\147\151\156\x61\x74\151\157\x6e", "\155\154\x73\x65\157\137\160\x61\147\x69\x6e\x61\x74\151\157\156\137\146\x69\x78", "\155\154\x73\x65\x6f\x5f\160\x61\147\151\156\141\x74\x69\157\156\137\143\141\156\157\156\x69\143\141\x6c", "\x6d\154\163\x65\157\137\144\151\163\x61\142\154\x65\x5f\157\x74\x68\145\162\x5f\x73\164\157\162\145\137\154\151\x6e\153\x73", "\155\x6c\163\x65\x6f\x5f\162\x65\x76\151\145\167\x73", "\155\154\x73\x65\x6f\x5f\143\x61\x6e\157\156\x69\143\x61\x6c", "\x6d\154\x73\x65\x6f\137\x68\162\x65\146\x6c\141\x6e\x67", "\155\154\163\x65\x6f\137\150\x72\x65\146\154\141\156\147\137\x6d\x6f\144\145", "\x6d\x6c\163\145\157\x5f\150\162\x65\x66\x6c\141\156\147\137\x78\x64\145\x66\x61\165\x6c\164", "\x6d\154\x73\x65\x6f\x5f\x72\157\x62\157\164\163", "\155\154\x73\145\157\x5f\x6d\145\x74\141\137\x72\157\x62\x6f\164\x73", "\x6d\x6c\x73\x65\x6f\x5f\x73\164\157\x72\145", "\x6d\154\163\145\157\x5f\x74\151\164\154\x65\x5f\160\x72\145\146\151\x78", "\155\x6c\163\145\x6f\x5f\x74\x69\164\154\145\x5f\x73\x75\146\146\x69\x78", "\155\x6c\163\x65\157\137\x68\x65\x61\144\x65\162\x5f\x6c\x6d\x5f\160\x72\157\144\165\143\x74", "\155\x6c\163\x65\x6f\137\x68\x65\141\x64\145\162\137\154\x6d\137\143\x61\164\145\x67\157\162\171", "\x6d\x6c\163\x65\x6f\x5f\150\145\x61\144\x65\x72\137\154\x6d\x5f\x69\156\x66\157\162\155\x61\x74\151\x6f\156", "\155\x6c\163\145\x6f\137\x68\145\x61\x64\x65\x72\x5f\x6c\155\137\x6d\x61\156\x75\x66\x61\143\x74\165\x72\145\x72", "\155\x6c\163\145\x6f\x5f\x77\150\x69\164\145\163\x70\x61\x63\x65", "\x6d\154\x73\x65\x6f\x5f\x65\x78\164\145\x6e\x73\151\157\x6e", "\x6d\154\163\145\x6f\x5f\x65\x78\x74\145\156\163\151\157\x6e\x5f\x6d\x6f\144\x65", "\x6d\x6c\163\145\x6f\x5f\163\141\x66\145\137\165\162\x6c", "\155\x6c\x73\145\x6f\137\154\x6f\x77\145\162\143\x61\x73\x65", "\155\154\x73\145\157\137\x64\x75\x70\154\151\x63\141\164\x65", "\x6d\x6c\163\145\x6f\x5f\151\x6e\163\145\x72\x74\x61\165\x74\157\x74\151\164\x6c\x65", "\155\x6c\x73\x65\157\x5f\145\144\151\164\141\165\164\x6f\164\151\x74\154\145", "\155\154\x73\x65\x6f\x5f\x75\x70\144\x61\164\x65\137\x64\145\x73\143\162\151\x70\x74\151\157\x6e", "\x6d\154\x73\x65\157\137\x69\156\163\x65\x72\164\x61\165\x74\x6f\x75\x72\x6c", "\155\154\x73\145\x6f\x5f\145\144\x69\x74\x61\165\x74\x6f\165\162\154", "\x6d\x6c\x73\145\157\137\151\156\x73\x65\162\164\x61\165\164\157\163\x65\157\x74\x69\x74\154\145", "\x6d\154\x73\x65\157\x5f\145\144\151\164\141\165\164\x6f\x73\x65\x6f\164\151\164\x6c\145", "\155\x6c\x73\145\157\x5f\151\x6e\x73\145\x72\164\141\165\x74\x6f\x6d\x65\164\x61\x6b\x65\171\167\x6f\162\x64", "\155\154\163\x65\x6f\137\145\144\x69\164\x61\165\164\x6f\x6d\x65\164\141\153\x65\171\x77\157\162\x64", "\155\x6c\163\x65\157\137\x69\x6e\163\145\162\x74\141\x75\x74\x6f\155\x65\x74\141\144\x65\x73\x63", "\155\x6c\163\145\x6f\x5f\x65\x64\x69\164\x61\x75\x74\157\155\x65\164\141\x64\145\163\x63", "\x6d\154\x73\x65\x6f\x5f\x69\x6e\163\x65\162\x74\141\x75\164\x6f\144\x65\x73\x63", "\155\154\163\145\157\x5f\145\144\151\x74\x61\165\x74\x6f\x64\145\163\x63", "\x6d\x6c\x73\145\157\137\151\x6e\163\x65\162\164\141\x75\164\157\150\61", "\155\x6c\163\x65\x6f\137\145\144\151\164\141\165\164\157\x68\61", "\x6d\154\163\145\x6f\x5f\x69\156\163\x65\162\x74\141\165\x74\x6f\150\62", "\155\154\x73\x65\157\137\145\144\x69\x74\141\165\164\157\x68\62", "\x6d\x6c\163\x65\157\137\151\156\163\145\x72\164\x61\165\164\x6f\x68\x33", "\155\x6c\163\145\x6f\x5f\x65\x64\151\x74\x61\x75\164\x6f\x68\63", "\155\x6c\x73\145\157\137\x69\x6e\x73\145\162\x74\x61\165\x74\157\151\155\x67\164\x69\164\154\145", "\x6d\154\163\x65\x6f\x5f\145\144\151\x74\141\x75\x74\x6f\x69\155\x67\164\151\164\x6c\145", "\155\154\163\x65\x6f\137\x69\156\x73\x65\x72\x74\141\x75\164\157\x69\x6d\147\141\154\164", "\155\154\x73\x65\x6f\137\145\144\x69\x74\x61\x75\x74\x6f\x69\x6d\147\141\154\164", "\155\x6c\163\145\x6f\x5f\x69\156\x73\145\162\164\141\x75\x74\157\x69\x6d\147\x6e\141\x6d\x65", "\155\x6c\x73\145\157\x5f\145\x64\x69\x74\141\x75\164\157\151\x6d\147\x6e\x61\155\145", "\155\154\x73\x65\x6f\x5f\x69\156\163\x65\x72\x74\x61\x75\x74\x6f\x74\x61\147\x73", "\x6d\154\x73\145\157\137\x65\x64\x69\x74\x61\x75\x74\157\x74\x61\147\163", "\155\154\x73\x65\157\x5f\151\156\163\x65\x72\x74\x61\165\164\x6f\x72\145\x6c\141\x74\x65\144", "\x6d\x6c\x73\x65\157\x5f\x65\x64\151\x74\x61\165\x74\157\x72\145\x6c\x61\x74\145\144", "\155\154\163\x65\157\137\160\162\x6f\144\x75\x63\164\x5f\165\162\x6c\137\x70\x61\x74\x74\x65\162\156", "\x6d\x6c\163\x65\157\137\160\162\157\x64\x75\x63\x74\x5f\164\x69\x74\x6c\145\137\x70\141\x74\164\x65\x72\x6e", "\x6d\154\x73\145\157\137\x70\x72\157\144\x75\143\x74\x5f\x68\x31\x5f\x70\141\x74\x74\145\x72\156", "\x6d\154\x73\145\157\x5f\160\x72\157\x64\x75\x63\164\x5f\x68\x32\137\160\x61\x74\x74\x65\162\x6e", "\x6d\x6c\x73\x65\x6f\x5f\x70\x72\157\144\165\x63\x74\137\x68\63\137\x70\141\x74\x74\x65\162\156", "\155\x6c\163\145\157\137\x70\x72\157\144\x75\x63\164\x5f\153\x65\x79\167\x6f\x72\144\x5f\x70\141\164\x74\145\162\156", "\155\x6c\x73\x65\x6f\137\160\x72\157\144\165\x63\x74\x5f\x64\145\163\143\162\x69\x70\x74\151\x6f\156\137\x70\141\164\x74\145\162\x6e", "\x6d\154\163\x65\157\x5f\160\x72\x6f\x64\165\x63\164\x5f\146\x75\x6c\x6c\137\144\x65\163\x63\137\160\x61\164\164\x65\162\156", "\x6d\154\x73\x65\157\137\x70\162\157\144\x75\143\164\x5f\x69\x6d\141\147\x65\137\x6e\141\155\x65\x5f\x70\x61\x74\x74\x65\162\x6e", "\155\154\163\x65\157\137\160\162\x6f\x64\x75\x63\164\137\151\x6d\141\147\145\137\141\154\x74\x5f\160\x61\164\164\145\x72\156", "\x6d\x6c\x73\145\x6f\x5f\x70\162\x6f\144\x75\x63\x74\137\151\x6d\x61\x67\145\137\164\151\164\x6c\145\x5f\x70\x61\164\164\x65\x72\x6e", "\x6d\x6c\x73\145\157\x5f\x70\162\157\x64\x75\143\x74\137\164\x61\147\137\x70\141\x74\x74\145\162\156", "\155\x6c\x73\145\x6f\137\160\162\x6f\144\165\143\164\137\162\145\154\x61\x74\x65\x64\137\156\x6f", "\x6d\154\163\x65\157\137\x70\162\157\144\165\x63\164\x5f\162\x65\x6c\141\164\145\144\137\x72\145\x6c\145\x76\x61\156\143\145", "\155\154\x73\x65\157\137\x70\162\157\x64\165\x63\164\x5f\162\x65\154\141\164\x65\144\137\163\141\155\x65\x63\x61\x74", "\155\154\x73\x65\157\x5f\143\x61\164\145\147\x6f\x72\171\x5f\x75\162\154\137\160\141\x74\x74\145\x72\156", "\x6d\154\163\x65\x6f\137\143\x61\x74\145\147\157\x72\x79\x5f\x68\61\x5f\x70\141\x74\164\x65\x72\x6e", "\155\154\163\x65\157\137\143\141\164\x65\x67\x6f\x72\171\137\150\x32\137\x70\x61\x74\x74\x65\x72\156", "\155\x6c\163\145\157\x5f\143\141\x74\145\x67\157\x72\171\x5f\x68\x33\x5f\160\141\x74\x74\145\162\156", "\x6d\x6c\x73\145\x6f\x5f\143\141\164\145\x67\157\x72\171\137\x74\151\164\154\x65\137\x70\141\164\164\145\x72\x6e", "\155\154\163\145\x6f\137\x63\x61\x74\145\x67\x6f\x72\x79\137\x6b\145\x79\x77\x6f\162\x64\137\x70\141\164\x74\145\162\156", "\x6d\154\163\145\x6f\x5f\143\141\x74\x65\147\157\x72\171\x5f\x64\145\163\143\x72\151\160\x74\x69\157\x6e\137\x70\141\164\x74\x65\162\156", "\x6d\x6c\163\145\157\137\x63\x61\164\x65\x67\x6f\x72\x79\x5f\x66\165\154\x6c\137\144\145\x73\x63\137\x70\x61\x74\164\145\162\156", "\155\154\163\145\157\x5f\x69\156\146\157\162\x6d\141\164\x69\157\156\x5f\x75\x72\154\x5f\x70\141\x74\x74\145\162\156", "\155\154\163\145\157\137\x69\156\x66\x6f\x72\x6d\x61\164\x69\157\x6e\137\150\x31\137\160\141\x74\164\145\162\156", "\155\154\163\x65\x6f\x5f\x69\156\146\x6f\x72\x6d\141\164\151\157\156\137\x68\x32\x5f\160\141\x74\x74\145\x72\x6e", "\155\x6c\x73\x65\x6f\137\151\156\x66\x6f\x72\x6d\x61\x74\151\x6f\x6e\137\150\x33\137\x70\x61\x74\164\x65\x72\156", "\155\x6c\x73\x65\x6f\137\151\x6e\x66\157\x72\x6d\x61\164\x69\x6f\x6e\137\x74\x69\164\154\145\x5f\160\141\164\164\x65\162\x6e", "\x6d\154\163\x65\x6f\x5f\x69\156\x66\x6f\x72\155\141\164\151\157\x6e\137\153\145\x79\167\x6f\x72\x64\137\x70\x61\x74\x74\145\162\x6e", "\x6d\154\x73\145\x6f\x5f\x69\156\146\x6f\162\155\141\164\151\x6f\x6e\x5f\144\x65\x73\x63\x72\151\x70\164\x69\x6f\x6e\x5f\x70\141\x74\x74\145\x72\156", "\155\x6c\x73\x65\x6f\x5f\x69\156\x66\x6f\162\155\x61\164\x69\157\156\137\x66\165\154\x6c\137\144\x65\163\143\x5f\x70\141\164\x74\x65\162\156", "\x6d\154\x73\145\x6f\x5f\155\x61\x6e\x75\146\141\x63\164\165\x72\145\162\137\x75\162\154\x5f\x70\x61\x74\164\x65\x72\x6e", "\155\x6c\163\x65\157\137\x6d\x61\x6e\165\x66\141\143\x74\165\x72\x65\x72\x5f\x68\61\x5f\160\x61\x74\x74\145\162\x6e", "\x6d\x6c\163\x65\x6f\137\x6d\x61\x6e\x75\x66\x61\143\x74\165\162\x65\x72\x5f\x68\62\137\160\x61\x74\164\145\x72\x6e", "\155\x6c\163\x65\x6f\x5f\x6d\x61\x6e\x75\x66\141\143\164\x75\162\145\162\x5f\150\x33\x5f\x70\141\164\164\145\162\156", "\x6d\154\x73\145\157\x5f\x6d\141\x6e\165\146\141\143\x74\x75\x72\145\162\137\164\151\164\x6c\x65\137\160\141\164\x74\145\162\156", "\155\154\x73\x65\x6f\x5f\x6d\x61\156\x75\146\141\x63\164\165\162\x65\162\137\153\145\x79\x77\x6f\x72\x64\x5f\160\x61\164\164\145\162\x6e", "\x6d\x6c\163\x65\x6f\137\155\x61\156\165\x66\141\x63\164\x75\162\145\x72\x5f\144\145\x73\143\162\x69\160\x74\x69\157\156\137\x70\x61\x74\x74\145\162\x6e", "\155\154\163\145\x6f\137\155\x61\156\165\146\141\143\164\x75\x72\x65\162\137\x66\165\154\x6c\x5f\x64\145\163\143\137\160\141\164\x74\x65\x72\156", "\x6d\154\163\145\157\x5f\155\x69\143\x72\x6f\x64\x61\x74\141", "\155\154\x73\x65\157\x5f\x6d\151\x63\x72\157\x64\141\x74\141\x5f\x64\141\164\141", "\x6d\x6c\x73\145\x6f\137\157\160\x65\x6e\x67\162\141\x70\x68", "\x6d\154\163\x65\157\x5f\157\x70\145\156\147\x72\x61\160\150\137\x64\141\164\141", "\155\154\163\145\157\137\x66\142\137\x70\x69\x78\145\154", "\x6d\154\x73\x65\x6f\x5f\x74\143\141\x72\144", "\155\x6c\163\145\x6f\x5f\x74\143\x61\162\144\137\144\x61\x74\x61", "\x6d\154\x73\x65\x6f\137\x67\160\x75\142\154\151\163\x68\x65\162", "\x6d\x6c\x73\x65\157\137\147\x70\165\x62\x6c\x69\x73\150\145\x72\137\x64\x61\164\141", "\155\x6c\163\x65\x6f\137\x63\162\157\156", "\155\154\163\145\x6f\x5f\x63\162\x6f\156\137\x6c\157\147"); goto lT1AV; F9gv7: goto ry9Wx; goto ZiUIY; rYqOJ: goto gy0UK; goto f8UqU; bTwB0: $this->session->data["\145\x72\x72\x6f\x72"] = "\x68\164\x61\143\x63\x65\x73\x73\40\146\151\154\x65\x20\156\x6f\164\x20\146\x6f\x75\156\x64\x20\72\x20\x50\154\x65\141\x73\145\40\162\x65\x6e\141\x6d\x65\40\74\142\76\56\x68\164\x61\143\143\145\163\163\x2e\x74\x78\164\74\57\142\76\40\164\x6f\x20\x3c\x62\x3e\56\150\164\141\143\x63\145\163\x73\x3c\57\x62\x3e\x20\151\156\40\157\x72\x64\x65\162\x20\164\x6f\40\x65\x6e\141\x62\x6c\145\x20\165\x72\x6c\40\162\x65\x77\162\x69\164\151\156\147"; goto XteGL; BTV3I: goto ax3DL; goto wjKCN; ejMIN: ZPtf_: goto Lhp1O; FxsyT: if ($modification_active) { goto wi60I; } goto nZZKl; Vmnw3: RicnI: goto wGce8; BGpyO: $this->session->data["\x65\x72\162\157\162"] = "\117\154\x64\40\166\x65\162\163\x69\x6f\x6e\x20\x6f\x66\40\x74\150\x65\x20\x6d\x6f\x64\x75\154\x65\x20\144\x65\x74\x65\x63\x74\145\144\54\x20\160\154\x65\141\x73\x65\x20\x72\x65\x6d\x6f\166\x65\x20\x74\150\x69\163\x20\146\x69\x6c\145\x20\x3a\x3c\142\76\57\166\x71\155\157\x64\x2f\x78\x6d\x6c\x2f\155\x75\154\x74\151\x6c\x69\x6e\147\x75\141\x6c\137\x73\x65\x6f\x2e\x78\155\x6c\x3c\57\x62\76"; goto G7pct; iqjDY: goto v7fM5; goto ScKfj; R4BDR: $glDMO[] = $dfq9k . "\x63\141\x74\137\143\x61\156\157\156\151\143\141\154"; goto EHBTQ; gcwSx: x0s8t: goto guuTc; tJ7JO: $Wy0d3 = 1; goto y0sVb; GjPR2: $data["\142\x75\x74\x74\157\156\137\141\144\144\137\x6d\x6f\x64\x75\154\x65"] = $this->language->get("\x62\x75\164\164\x6f\156\x5f\141\144\144\x5f\155\157\x64\165\x6c\x65"); goto TrsBr; CXr_n: Hd5Bt: goto bIyMx; FKmlZ: goto CClwY; goto HxAVF; dyVYp: QLh9g: goto XWhny; dx1GT: bM7hS: goto ZbNuc; H6f5u: $this->response->setOutput($this->load->view("\x6d\x6f\x64\165\154\x65\x2f\143\157\x6d\x70\x6c\145\164\x65\x5f\x73\145\x6f\56\164\x70\x6c", $data)); goto zpdTS; qsOyZ: Ht6v5: goto MuPU6; wqK_m: goto CCkUp; goto dLqaS; hrM_J: $this->load->model("\163\x65\x74\x74\151\156\147\x2f\145\x78\x74\x65\156\163\x69\x6f\156"); goto wHgkQ; QL01I: CCkUp: goto fSzr6; suDbr: sKWVG: goto Th9Qb; XuGlZ: rR44w: goto H_kGT; F2_W4: if (isset($this->session->data["\163\x75\143\143\x65\x73\163"])) { goto AyyjU; } goto rsY0V; CPKH1: $this->load->model("\x73\145\x74\164\x69\156\x67\57\145\170\164\145\x6e\163\151\x6f\156"); goto Glohr; tY2Ki: JnJRz: goto SC202; cfaS1: return 0; goto F47tw; Lx0Fy: $this->document->addScript(self::$ASSET_PATH . "\152\x71\x75\x65\162\171\x2d\x65\144\151\x74\x61\x62\154\x65\56\x6d\x69\x6e\x2e\x6a\x73"); goto A7wcY; Tl5r5: $this->redirect($this->url->link(self::$LINK, $this->token, "\123\x53\x4c")); goto UFMse; PB5BL: goto t0jZR; goto Waydq; aYJEu: goto vJjOA; goto ipkjI; xNRKz: $YLVI9 = $this->db->query("\123\x45\x4c\105\x43\x54\x20" . $this->url_alias . "\x5f\x69\x64\40\x46\122\117\115\x20" . DB_PREFIX . $this->url_alias . "\x20\127\110\105\122\x45\x20\50\x71\x75\x65\x72\171\40\114\x49\x4b\x45\40\47\x63\141\x74\145\x67\x6f\162\x79\x5f\151\x64\x3d\x25\47\x20\117\122\40\x71\165\145\x72\171\40\114\x49\113\105\x20\47\160\162\157\x64\165\x63\x74\137\x69\144\75\x25\47\x20\x4f\122\x20\x71\x75\x65\x72\x79\x20\x4c\x49\x4b\105\x20\x27\x69\156\146\157\162\155\x61\x74\x69\x6f\x6e\137\151\144\75\45\47\40\x4f\122\40\x71\165\x65\162\x79\40\x4c\111\x4b\x45\x20\x27\x72\157\x75\164\145\x3d\45\47\51\x20\x41\116\x44\x20\x6c\141\156\147\165\141\147\x65\x5f\151\x64\75\x30\40\114\111\x4d\111\x54\x20\61")->row; goto ChJua; GsjWO: if ($ieocD >= 5242880) { goto kcNa1; } goto h76bJ; gKPjE: goto KuVBd; goto SQv18; g7YSI: v5VXr: goto pSla1; AlV64: PoTnz: goto vXHvH; f8UqU: lxn9M: goto Uiaii; mXY76: SCmO8: goto i3I5p; qtj2r: if ($this->user->hasPermission("\155\x6f\x64\x69\x66\171", self::$LINK)) { goto s7sn6; } goto uQh4b; mVUk2: if (version_compare(VERSION, "\64", "\x3e\x3d")) { goto U2sOE; } goto Cqs3q; X9K4Y: $this->document->addScript(self::$ASSET_PATH . "\x6a\161\x75\145\162\x79\56\x64\x61\164\141\124\141\x62\x6c\x65\163\x2e\155\151\156\x2e\x6a\x73"); goto vSET7; yubq2: $data["\150\145\x61\144\x65\162"] = $this->load->controller("\x63\157\155\155\x6f\x6e\x2f\150\x65\141\144\x65\162"); goto uJ4jU; RXXZt: } 
  
  public function save_cli_log() {
    $file = DIR_LOGS.'seo_package_cli.log';
    header('Content-Description: File Transfer');
    header('Content-Disposition: attachment; filename=seo_package_cron.log');
    header('Content-Type: text/plain');
    header('Cache-Control: must-revalidate');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
  }
  
  public function generator_related_product($mode, $simulate, $empty_only, $redirect) {
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    
    if (!defined('SEO_PACKAGE_CLI')) {
      $this->limit = 50; // limit more to not cause timeout
    }
    
    $values = $data = array();
    $data['langs'][0]['lang_img'] = '';
      
    if (isset($this->request->post['mlseo_product_related_samecat'])) {
      $same_cat = $this->request->post['mlseo_product_related_samecat'];
    } else if ($this->config->get('mlseo_product_related_samecat')) {
      $same_cat = $this->config->get('mlseo_product_related_samecat');
    } else {
      $same_cat = false;
    }
    
    $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=".$this->config->get('config_language_id')." ORDER BY pd.product_id,pd.language_id")->row;
    $this->total_items = $total['total'];
      
    if ($same_cat) {
      $rows = $this->db->query("SELECT pd.*, p.*, (SELECT cp.category_id FROM " . DB_PREFIX . "product_to_category pc LEFT JOIN " . DB_PREFIX . "category_path cp on cp.category_id = pc.category_id WHERE pc.product_id = pd.product_id ORDER BY cp.level DESC LIMIT 1) as category_id FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=" . $this->config->get('config_language_id') . " ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
    } else {
      $rows = $this->db->query("SELECT pd.*, p.* FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id WHERE language_id=" . $this->config->get('config_language_id') . " GROUP BY pd.product_id ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
      //$rows = $this->db->query("SELECT pd.*, p.*, pc.category_id FROM " . DB_PREFIX . "product_description pd LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = pd.product_id LEFT JOIN " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id WHERE language_id=" . $this->config->get('config_language_id') . " GROUP BY pd.product_id ORDER BY pd.product_id,pd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
    }
    
    foreach ($rows as $row) {
      $this->session->data['seopackage_processed']++;
      
      if (empty($row['product_id'])) continue;
      
      //$rel_count = $this->db->query("SELECT COUNT(*) AS count FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $row['product_id'] . "'")->row;
      
      $related = $this->db->query("SELECT pr.related_id, pd.name FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product_description pd ON (pd.product_id = pr.related_id AND pd.language_id='" . (int) $this->config->get('config_language_id')."') WHERE pr.product_id='" . (int) $row['product_id'] . "'")->rows;
      
      $old_related = array();
      foreach ($related as $rel) {
        $old_related[] = '- ' . $rel['name'];
      }
      
      if ($empty_only) {
        if (count($related)) {
          continue;
        }
      } else {
        if (!$simulate) {
          $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $row['product_id'] . "'" );
        }
      }
      
      $prod_name = str_replace(array('%', '#', "'", '"'), '', $row['name']);
      $prod_tag = str_replace(array('%', '#', "'", '"'), '', $row['tag']);
      $prod_desc = str_replace(array('\n', '\r', '%', '#', "'", '"'), '', $row['description']);
      $prod_cat = '';
      
      if ($same_cat && !empty($row['category_id'])) {
        $prod_cat = " AND pc.category_id = '" .$row['category_id'] . "' ";
      }
      
      if (!empty($this->request->post['mlseo_product_related_relevance'])) {
        $relevance = $this->request->post['mlseo_product_related_relevance'];
      } else if ($this->config->get('mlseo_product_related_relevance')) {
        $relevance = $this->config->get('mlseo_product_related_relevance');
      } else {
        $relevance = 2;
      }
      
      if (!empty($this->request->post['mlseo_product_related_no'])) {
        $max_items = $this->request->post['mlseo_product_related_no'];
      } else if ($this->config->get('mlseo_product_related_no')) {
        $max_items = $this->config->get('mlseo_product_related_no');
      } else {
        $max_items = 5;
      }
      
      if (empty($row['category_id'])) {
        $row['category_id'] = 0;
      }
      
      if (true) { // related generator method
        $results = $this->db->query("SELECT DISTINCT p.product_id, pd.name,
          ROUND(MATCH (pd.name, pd.description) AGAINST ('" . $prod_name . " " . $prod_tag . " " . $prod_desc . "'), 0) / 5 as relevance
          FROM " . DB_PREFIX . "product_description pd
          LEFT JOIN " . DB_PREFIX . "product p on pd.product_id = p.product_id
          INNER JOIN " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id
          WHERE
            p.product_id <> " . $row['product_id'] . $prod_cat . "
            AND p.status = 1
            AND p.quantity > 0
          GROUP BY p.product_id
            HAVING relevance >= " . (int) $relevance . "
          ORDER BY relevance DESC
          LIMIT 0, " . (int) $max_items)->rows;
      } else { // method 2
        $results = $this->db->query("SELECT DISTINCT p.product_id, pd.name, 
          MAX(2 / (CASE p.price >= ". $this->db->escape($row['price']) ." WHEN 0 THEN (". $this->db->escape($row['price']) ." / p.price) ELSE (p.price / ". $this->db->escape($row['price']) .") END) * 
          (CASE category_id WHEN ". (int) $row['category_id'] ." THEN 2 ELSE 1 end) + (1 + rel.rlv))
          AS relevance FROM " . DB_PREFIX . "product p 
          INNER JOIN " . DB_PREFIX . "product_description pd ON p.product_id = pd.product_id
          INNER JOIN " . DB_PREFIX . "product_to_category p2c ON p.product_id = p2c.product_id
          INNER JOIN (SELECT product_id, MATCH(name, description) AGAINST ('". strip_tags(trim($this->db->escape(htmlspecialchars_decode(str_replace(array('%', '_', '"', "'"), array('', ' ', ' ', ' '), $row['name']))))) . ' ' . strip_tags(trim($this->db->escape(htmlspecialchars_decode(str_replace(array('%', '_', '"', "'"), array('', ' ', ' ', ' '), $row['description']))))) ."') AS rlv FROM " . DB_PREFIX . "product_description) AS rel ON rel.product_id = p.product_id  
          GROUP BY p.product_id
          HAVING p.product_id <> ". (int) $row['product_id'] ." AND relevance >= ".(int) $relevance." AND p.product_id NOT IN (SELECT related_id FROM " . DB_PREFIX . "product_related WHERE product_id = ". (int) $row['product_id'] .")
          ORDER BY relevance DESC
          LIMIT 0, ". (int) $max_items)->rows;
      }
      
      $new_related = array();
      foreach ($results as $res) {
        if (!$simulate) {
          $this->db->query("INSERT INTO " . DB_PREFIX . "product_related (product_id, related_id) VALUES (" . $row['product_id'] . ", " . $res['product_id'] . ")");
        }
        $new_item = $this->db->query("SELECT name FROM " . DB_PREFIX . "product_description WHERE product_id=" . $res['product_id'] . " AND language_id=" . $this->config->get('config_language_id'))->row;
        $new_related[] = '- ' . $new_item['name'];
      }
      sort($old_related);
      sort($new_related);
      
      $changed = false;
      
      if (!empty($new_related) && $old_related != $new_related) {
        $changed = true;
        $this->session->data['seopackage_updated']++;
      }
      
      $values[] = array(
        'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'),
        'name' =>  $row['name'],
        'old_value' =>  implode('<br/> ', $old_related),
        'value' =>  implode("<br/> ", $new_related),
        'changed' =>  $changed,
      );
      
      if (defined('SEO_PACKAGE_CLI')) {
        if ($changed) {
          $this->log('product.related: ' . $row['name'] . ' => ' . "\n\t\t" . implode("\n\t\t", $new_related));
        }
      }
    }
    
    $data['langs'][0]['rows'] = &$values;
    return $data;
  }
  
  public function generator_product($mode, $simulate, $empty_only, $redirect) {
    if ($mode == 'related') return $this->generator_related_product($mode, $simulate, $empty_only, $redirect);
    
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); die('No language selected');}
    
    // get languages 
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    unset($languages);
    
    $image_simulate = array();
    if ($mode == 'image_name' && count($this->request->post['langs']) > 1) {
      die($this->language->get('text_image_name_lang'));
      die('<div class="alert alert-warning"><i class="fa fa-warning"> ' . $this->language->get('text_image_name_lang') . '</i></div>');
    }
    
    switch ($mode) {
      case 'url': $field = 'seo_keyword'; break;
      case 'h1': $field = 'seo_h1'; break;
      case 'h2': $field = 'seo_h2'; break;
      case 'h3': $field = 'seo_h3'; break;
      case 'title': $field = 'meta_title'; break;
      case 'keyword': $field = 'meta_keyword'; break;
      case 'description': $field = 'meta_description'; break;
      case 'full_desc': $field = 'description'; break;
      case 'image_name': $field = 'image'; break;
      case 'image_title': $field = 'image_title'; break;
      case 'image_alt': $field = 'image_alt'; break;
      case 'tag': $field = 'tag'; break;
    }
      
    $values = $data = array();
    
    if ($mode == 'store_copy') {
      foreach($this->request->post['langs'] as $lang) {
        if (!$simulate) {
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_product_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'");
          
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_product_description SELECT product_id, '".(int) $lang."', '".(int) $this->store."', name, description, meta_title, meta_description, meta_keyword, image_title, image_alt, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "product_description d WHERE d.language_id = '".(int) $lang."'");
        }
        
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang];
        $data['langs'][$lang]['rows'][] = array(
          'link' =>  '',
          'name' =>  'Product data copy to sub-store',
          'old_value' =>  '',
          'value' =>  'Done',
          'changed' =>  '',
        );
      }
      
      return $data;
    }
    
    foreach($this->request->post['langs'] as $lang)
    {
      $this->config->set('mlseo_current_lang', $lang_code[$lang]);
      $values[$lang]['lang_img'] = $lang_img[$lang];
      $values[$lang]['rows'] = array();
      $change_count = 0;
      
      if (isset($this->request->post['mlseo_product_'.$mode.'_pattern'])) {
        $pattern = $this->request->post['mlseo_product_'.$mode.'_pattern'];
      } else {
        $pattern = $this->config->get('mlseo_product_'.$mode.'_pattern');
      }
      
      //if ($this->store) {
      if ($this->multistore_mode) {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) WHERE s.store_id = ".(int) $this->store)->row;
      } else {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "product p")->row;
      }
      
      $this->total_items = $total['total'];
      
      $special = '';
      if ($this->config->get('mlseo_special_group')) {
        $special = ", (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.customer_group_id = ".(int)$this->config->get('mlseo_special_group')." ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special";
      }
      
      $extra_select = '';
      
      if ($mode == 'url') {
       if (version_compare(VERSION, '4', '>=')) {
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'product_id' AND `value` = p.product_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
       } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
         //$extra_select .= ",IFNULL((SELECT meta_title FROM " . DB_PREFIX . "seo_product_description sd WHERE (sd.product_id = p.product_id) AND (sd.language_id = d.language_id)  AND (sd.store_id = ".(int) $this->store.") LIMIT 1), null) AS seo_table_exists";
       } else if ($this->multistore_mode) {
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
       } else if ($this->ml_mode) {
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('product_id=', p.product_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword";
       } else {
         $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('product_id=', p.product_id) LIMIT 1), '') AS seo_keyword";
       }
      }

      if ($this->store) {
        $desc_table = 'seo_product_description';
        $extra_desc = "AND store_id = '" . (int)$this->store . "'";
        if (!empty($this->request->post['filter_category'])) {
          $rows = $this->db->query("SELECT sd.*, p.*, d.name as orig_name, d.description as orig_description ".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) LEFT JOIN " . DB_PREFIX . "seo_product_description sd ON (p.product_id = sd.product_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "product_description d ON (p.product_id = d.product_id AND d.language_id = ".(int) $lang.") WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND s.store_id = ".(int) $this->store." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        } else {
          $rows = $this->db->query("SELECT sd.*, p.*, d.name as orig_name, d.description as orig_description ".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "seo_product_description sd ON (p.product_id = sd.product_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "product_description d ON (p.product_id = d.product_id AND d.language_id = ".(int) $lang.") WHERE s.store_id = ".(int) $this->store." ORDER BY sd.product_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        }
      } else {
        $desc_table = 'product_description';
        $extra_desc = '';
        if (!empty($this->request->post['filter_category'])) {
          if ($this->multistore_mode) {
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
          } else {
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_category c ON (p.product_id = c.product_id) WHERE c.category_id = '".(int) $this->request->post['filter_category']."' AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
          }
        } else {
          if ($this->multistore_mode) {
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id LEFT JOIN " . DB_PREFIX . "product_to_store s ON (p.product_id = s.product_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
          } else {
            $rows = $this->db->query("SELECT d.*, p.*".$special.$extra_select." FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description d ON p.product_id = d.product_id WHERE d.language_id=".(int) $lang." ORDER BY d.product_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
          }
        }
      }
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        $_SESSION['seopackage_lastItem'] = $row['product_id'];
        
        if (empty($row['name']) && isset($row['orig_name'])) {
          $row['name'] = $row['orig_name'];
        }
        
        if (empty($row['description']) && isset($row['orig_description'])) {
          $row['description'] = $row['orig_description'];
        }
        
        /*
        $langDescriptions = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = ".(int) $row['product_id'])->rows;
        
        foreach ($langDescriptions as $langDesc) {
          $row['name_'.$langDesc['language_id']] = $langDesc['name'];
        }
        */
        
        if (!array_key_exists($field, $row)) continue;
        
        $value = str_replace('[current]', $row[$field], $pattern);
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($value, $lang, $row, $this->store);
        
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) {
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_product_description SET product_id = '" . (int)$row['product_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'");
        }
        
        // urls
        if ($mode == 'url')
        {
          if ($empty_only && $row['seo_keyword']) continue;
          
          if (!$simulate) {
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'product_id' AND `value` = '" . $row['product_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if ($this->multistore_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND store_id = " . (int)$this->store);
            } else if ($this->ml_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "' AND language_id IN (".(int) $lang.", 0)");
            } else {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'product_id=" . $row['product_id'] . "'");
            }
          }
          
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'product', $row['product_id'], $lang, $simulate);
          
          if (!$simulate) {
            if ($this->config->get('mlseo_backup')) {
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) {
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/product&product_id=" . (int) $row['product_id'] . "', language_id = '" . (int) $lang . "'");
              }
            }
            
            //$this->db->query("UPDATE " . DB_PREFIX . "product_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . $row['language_id'] . "' ");
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET  `key` = 'product_id', `value` = '" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->multistore_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->ml_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'");
            } else {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'product_id=" . $row['product_id'] . "', keyword = '" . $this->db->escape($value) . "'");
            }
          }
          //$field = 'seo_keyword';
        }
        // Meta title
        elseif ($mode == 'h1')
        {
          if ($empty_only && $row['seo_h1']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h2')
        {
          if ($empty_only && $row['seo_h2']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h2';
        }
        elseif ($mode == 'h3')
        {
          if ($empty_only && $row['seo_h3']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h3';
        }
        // Meta title
        elseif ($mode == 'title')
        {
          if ($empty_only && $row['meta_title']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_title';
        }
        // Meta keywords
        elseif ($mode == 'keyword')
        {
          if ($empty_only && $row['meta_keyword']) continue;
          
          if (function_exists('mb_strtolower')) {
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          } else {
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          }
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_keyword';
        }
        // Meta description
        elseif ($mode == 'description')
        {
          if ($empty_only && $row['meta_description']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_description';
        }
        // Description
        elseif ($mode == 'full_desc')
        {
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'description';
        }
        // image name
        if ($mode == 'image_name')
        {
          if (!$row['image']) continue;
          
          $img_count = $this->db->query("SELECT COUNT(image) as count FROM " . DB_PREFIX . "product WHERE image='" . $this->db->escape($row['image']) . "'")->row;
          if ($img_count['count'] > 1) continue;
          
          $path = pathinfo($row['image']);
          
          // skip if no extension
          if (empty($path['extension'])) {
            continue;
          }
          
          $patternArray = explode(';', $pattern);
          
          $value = str_replace('[current]', $row[$field], $patternArray[0]);
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($value, $lang, $row, $this->store);
        
          $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'image', '', $lang, false, true);
          $value = $path['dirname'] . '/' . $filename . '.' . $path['extension'];
          
          if ($row['image'] != $value) {
            $x = 1;
            
            if ($simulate) {
              while (file_exists(DIR_IMAGE . $value) || in_array(DIR_IMAGE . $value, $image_simulate)) {
                $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension'];
                $x++;
              }
              $image_simulate[] = DIR_IMAGE . $value;
            } else {
              while (file_exists(DIR_IMAGE . $value)) {
                $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension'];
                $x++;
              }
              if (@rename(DIR_IMAGE . $row['image'], DIR_IMAGE . $value)) {
                //$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE product_id = '" . $row['product_id'] . "'");

                // replace all images with such value
                $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($row['image']) . "'");
                $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($row['image']) . "'");
              } else {
                continue;
              }
            }
          }
          
          $additionalImages = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id='" . $this->db->escape($row['product_id']) . "'")->rows;
          
          foreach ($additionalImages as $imgIndex => $addImageRow) {
            $path = pathinfo($addImageRow['image']);
            
            $row['image'] .= '<br> '.$addImageRow['image'];
            
            // skip if no extension
            if (empty($path['extension'])) {
              continue;
            }
            
            $currentPattern = isset($patternArray[$imgIndex+1]) ? $patternArray[$imgIndex+1] : $patternArray[0];
            
            $subValue = str_replace('[current]', $addImageRow['image'], $currentPattern);
            $subValue = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformProduct($subValue, $lang, $row, $this->store);
        
            $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($subValue, 'image', '', $lang, false, true);
            $subValue = $path['dirname'] . '/' . $filename . '.' . $path['extension'];
            
            if ($addImageRow['image'] != $subValue) {
              $x = 1;
              
              if ($simulate) {
                while (file_exists(DIR_IMAGE . $subValue) || in_array(DIR_IMAGE . $subValue, $image_simulate)) {
                  $subValue = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension'];
                  $x++;
                }
                $image_simulate[] = DIR_IMAGE . $subValue;
              } else {
                while (file_exists(DIR_IMAGE . $subValue)) {
                  $subValue = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension'];
                  $x++;
                }
                if (@rename(DIR_IMAGE . $addImageRow['image'], DIR_IMAGE . $subValue)) {
                  // replace all images with such value
                  $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($subValue) ."' WHERE image = '" . $this->db->escape($addImageRow['image']) . "'");
                  $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($subValue) ."' WHERE image = '" . $this->db->escape($addImageRow['image']) . "'");
                } else {
                  continue;
                }
              }
            }
            
            $value .= '<br> '.$subValue;
          }
          
          $row['image'] = ' '.$row['image'];
          $value = ' '.$value;
          // $field = 'image';
        }
         // Image title
        elseif ($mode == 'image_title')
        {
          if ($empty_only && $row['image_title']) continue;
          
          $value = str_replace(array('"', "'"), '', $value);
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET image_title = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'image_title';
        }
         // Image alt
        elseif ($mode == 'image_alt')
        {
          if ($empty_only && $row['image_alt']) continue;
          
          $value = str_replace(array('"', "'"), '', $value);
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET image_alt = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'image_alt';
        }
        // Tags
        elseif ($mode == 'tag')
        {
          if ($empty_only && $row['tag']) continue;
          
          if ($lang) {
            $remove = $this->config->get('mlseo_remove_'.$lang);
          } else {
            $remove = $this->config->get('mlseo_remove_'.$this->config->get('config_language_id'));
          }
          
          $value = str_replace('"', '', $value);
          
          if (!empty($remove)) {
            $beforeWord = "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|^)";
            $afterWord =  "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|$)";
            $removeArray = array();
            
            foreach (explode(',', $remove) as $rem) {
              $removeArray[] = '`'.$beforeWord.preg_quote(trim($rem), '`').$afterWord.'`';
            }
            
            if ($removeArray) {
              $value = preg_replace($removeArray, '$1$2', $value);
            }
          }
          
          if ($this->config->get('mlseo_format_tag')) {
            $value = str_replace('.', ',', $value);
            $value = str_replace(array('  ',' '), ', ', $value);
            
            if (function_exists('mb_strtolower')) {
              $value = trim(mb_strtolower($value), ', ');
            } else {
              $value = trim(strtolower($value), ', ');
            }
          }
          
          $value = trim(preg_replace('/(?:,\s*)+/', ',', $value), ', ');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . "product_description SET tag = '" . $this->db->escape($value) . "' WHERE product_id = '" . $row['product_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'tag';
        }
        
        if (!$simulate) {
          $this->db->query("UPDATE " . DB_PREFIX . "product SET date_modified = NOW() WHERE product_id = '".(int)$row['product_id']."'");
        }
        
        if (array_key_exists($field, $row)) {
          $changed = !($value === $row[$field]);
        } else {
          $changed = false;
        }
        
        if (!defined('SEO_PACKAGE_CLI')) {
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) {
            $values[$lang]['rows'][] = array(
              'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'),
              'name' =>  $row['name'],
              'old_value' =>  (string) $row[$field],
              'value' =>  '[backup url to redirect to new one]',
              'changed' =>  false,
            );
          }
          
          $values[$lang]['rows'][] = array(
            'link' =>  $this->url->link('catalog/product/'.$this->edit_action, $this->token . '&product_id=' . $row['product_id'], 'SSL'),
            'name' =>  $row['name'],
            'old_value' =>  (string) $row[$field],
            'value' =>  $value,
            'changed' =>  $changed,
          );
        }
        
        if ($changed) {
          if (defined('SEO_PACKAGE_CLI')) {
            $this->log('product.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value);
          }
          
          $change_count++;
          $this->session->data['seopackage_updated']++;
          //Powercache::remove('seo_rewrite', 'product_id=' . $row['product_id']);
        }
      } // end foreach $rows
      $values[$lang]['count'] = $change_count;
    }
    $data['langs'] = &$values;
    return $data;
  }
  
  public function getChildCategories($cat_id) {
    $parentsArray = array($cat_id);
    
    if ($cat_id) {
      $catQuery = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = '".(int) $cat_id."'")->rows;
      
      if (!empty($catQuery)) {
        foreach ($catQuery as $cat) {
          $parentsArray[] = $cat['category_id'];
          $parentsArray = array_unique(array_merge($parentsArray, $this->getChildCategories($cat['category_id'])));
        }
      }
    }
    
    return $parentsArray;
  }
  
  public function generator_category($mode, $simulate, $empty_only, $redirect) {
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;}
    
    if (version_compare(VERSION, '4', '>=')) {
      $this->load->model('extension/complete_seo/catalog/seo_package');
      $modelSeoPackage = $this->model_extension_complete_seo_catalog_seo_package;
    } else {
      $this->load->model('catalog/seo_package');
      $modelSeoPackage = $this->model_catalog_seo_package;
    }
    
    // get languages 
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    unset($languages);
    
    switch ($mode) {
      case 'url': $field = 'seo_keyword'; break;
      case 'h1': $field = 'seo_h1'; break;
      case 'h2': $field = 'seo_h2'; break;
      case 'h3': $field = 'seo_h3'; break;
      case 'title': $field = 'meta_title'; break;
      case 'keyword': $field = 'meta_keyword'; break;
      case 'description': $field = 'meta_description'; break;
      case 'full_desc': $field = 'description'; break;
    }
    
    $values = $data = array();
    
    if ($mode == 'store_copy') {
      foreach($this->request->post['langs'] as $lang) {
        if (!$simulate) {
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_category_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'");
          
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_category_description SELECT category_id, '".(int) $lang."', '".(int) $this->store."', name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "category_description d WHERE d.language_id = '".(int) $lang."'");
        }
        
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang];
        $data['langs'][$lang]['rows'][] = array(
          'link' =>  '',
          'name' =>  'Category data copy to sub-store',
          'old_value' =>  '',
          'value' =>  'Done',
          'changed' =>  '',
        );
      }
      
      return $data;
    }
    
    $filterCats = '';
    
    if (!empty($this->request->post['filter_cat_category'])) {
      $parentsArray = array();
      $cat_id = $this->request->post['filter_cat_category'];
      
      if (empty($this->request->post['filter_cat_category_current'])) {
        $parentsArray = $this->getChildCategories($cat_id);
      
        if (!empty($parentsArray)) {
          $filterCats = " AND c.category_id IN (".implode(',', $parentsArray).")";
        }
      } else {
        $filterCats = " AND c.category_id = '".(int) $cat_id."'";
      }
    }
    
    foreach($this->request->post['langs'] as $lang)
    {
      $this->config->set('mlseo_current_lang', $lang_code[$lang]);
      $values[$lang]['lang_img'] = $lang_img[$lang];
      $values[$lang]['rows'] = array();
      $change_count = 0;
      
      if (isset($this->request->post['mlseo_category_'.$mode.'_pattern'])) {
        $pattern = $this->request->post['mlseo_category_'.$mode.'_pattern'];
      } else {
        $pattern = $this->config->get('mlseo_category_'.$mode.'_pattern');
      }
      
      if ($this->multistore_mode) {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) WHERE s.store_id = ".(int) $this->store . $filterCats)->row;
      } else {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "category c WHERE 1" . $filterCats)->row;
      }
      
      $this->total_items = $total['total'];
      
      $extra_select = '';
      
      if ($mode == 'url') {
        if (version_compare(VERSION, '4', '>=')) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'path' AND `value` = d.category_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.language_id = d.language_id OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if ($this->multistore_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword";
        } else if ($this->ml_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('category_id=', d.category_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword";
        } else {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('category_id=', d.category_id) LIMIT 1), '') AS seo_keyword";
        }
      }

      if ($this->store) {
        $desc_table = 'seo_category_description';
        $extra_desc = "AND store_id = '" . (int)$this->store . "'";
        $rows = $this->db->query("SELECT sd.*, c.*, d.name as orig_name, d.description as orig_description ".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) LEFT JOIN " . DB_PREFIX . "seo_category_description sd ON (c.category_id = sd.category_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "category_description d ON (c.category_id = d.category_id AND d.language_id=".(int) $lang.") WHERE s.store_id = ".(int) $this->store. $filterCats ." ORDER BY sd.category_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
      } else {
        $desc_table = 'category_description';
        $extra_desc = '';
        if ($this->multistore_mode) {
          $rows = $this->db->query("SELECT d.*, c.*".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description d ON c.category_id = d.category_id LEFT JOIN " . DB_PREFIX . "category_to_store s ON (c.category_id = s.category_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang . $filterCats . " ORDER BY d.category_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        } else {
          $rows = $this->db->query("SELECT d.*, c.*".$extra_select." FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description d ON c.category_id = d.category_id WHERE d.language_id=".(int) $lang . $filterCats . " ORDER BY d.category_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        }
      }
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        if (empty($row['name']) && isset($row['orig_name'])) {
          $row['name'] = $row['orig_name'];
        }
        
        if (empty($row['description']) && isset($row['orig_description'])) {
          $row['description'] = $row['orig_description'];
        }
        
        $value = str_replace('[current]', $row[$field], $pattern);
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformCategory($value, $lang, $row, $this->store);
        
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) {
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_category_description SET category_id = '" . (int)$row['category_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'");
        }
        
        // urls
        if ($mode == 'url')
        {
          if (version_compare(VERSION, '4', '>=')) {
            $row['seo_keyword'] = $modelSeoPackage->getCategorySeoV4($row['category_id'], $lang, $this->store);
          }
          
          if ($empty_only && $row['seo_keyword']) continue;
          
          if (!$simulate) {
            if (version_compare(VERSION, '4', '>=')) {
              //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'path' AND `value` = '" . $row['category_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if ($this->multistore_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND store_id = " . (int)$this->store);
            } else if ($this->ml_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "' AND language_id IN (".(int) $lang.", 0)");
            } else {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'category_id=" . $row['category_id'] . "'");
            }
          }
          
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'category', $row['category_id'], $lang, $simulate);
          
          if (!$simulate) {
            if ($this->config->get('mlseo_backup')) {
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) {
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/category&category_id=" . (int) $row['category_id'] . "', language_id = '" . (int) $lang . "'");
              }
            }
            
            //$this->db->query("UPDATE " . DB_PREFIX . "category_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . $row['language_id'] . "' ");
            if (version_compare(VERSION, '4', '>=')) {
              //$this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'path', `value` = '" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
              if ($row['seo_keyword'] != $value) {
                $modelSeoPackage->setCategorySeoV4($row['category_id'], $value, $lang, $this->store);
              }
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->multistore_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->ml_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "'");
            } else {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'category_id=" . $row['category_id'] . "', keyword = '" . $this->db->escape($value) . "'");
            }
          }
          // $field = 'seo_keyword';
        }
        // Meta title
        elseif ($mode == 'h1')
        {
          if ($empty_only && $row['seo_h1']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h2')
        {
          if ($empty_only && $row['seo_h2']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h3')
        {
          if ($empty_only && $row['seo_h3']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        // Meta title
        elseif ($mode == 'title')
        {
          if ($empty_only && $row['meta_title']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_title';
        }
        // Meta keywords
        elseif ($mode == 'keyword')
        {
          if ($empty_only && $row['meta_keyword']) continue;
          
          if (function_exists('mb_strtolower')) {
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          } else {
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          }
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_keyword';
        }
        // Meta description
        elseif ($mode == 'description')
        {
          if ($empty_only && $row['meta_description']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_description';
        }
        // Description
        elseif ($mode == 'full_desc')
        {
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE category_id = '" . $row['category_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'description';
        }
        
        if (!$simulate) {
          $this->db->query("UPDATE " . DB_PREFIX . "category SET date_modified = NOW() WHERE category_id = '".(int)$row['category_id']."'");
        }
        
        if (array_key_exists($field, $row)) {
          $changed = !($value === $row[$field]);
        } else {
          $changed = false;
        }
        
        if (!defined('SEO_PACKAGE_CLI')) {
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) {
            $values[$lang]['rows'][] = array(
              'link' =>  $this->url->link('catalog/category/'.$this->edit_action, $this->token . '&category_id=' . $row['category_id'], 'SSL'),
              'name' =>  $row['name'],
              'old_value' =>  (string) $row[$field],
              'value' =>  '[backup url to redirect to new one]',
              'changed' =>  false,
            );
          }
          
          $values[$lang]['rows'][] = array(
            'link' =>  $this->url->link('catalog/category/'.$this->edit_action, $this->token . '&category_id=' . $row['category_id'], 'SSL'),
            'name' =>  $row['name'],
            'old_value' =>  (string) $row[$field],
            'value' =>  $value,
            'changed' =>  $changed,
          );
        }
        
        if ($changed) {
          if (defined('SEO_PACKAGE_CLI')) {
            $this->log('category.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value);
          }
          
          $this->session->data['seopackage_updated']++;
          $change_count++;
          //Powercache::remove('seo_rewrite', 'path=', $row['category_id']);
        }
      } // end foreach $rows
      $values[$lang]['count'] = $change_count;
    }
    $data['langs'] = &$values;
    return $data;
  }
  
  public function generator_information($mode, $simulate, $empty_only, $redirect) {
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;}
    
    // get languages 
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    unset($languages);
    
    switch ($mode) {
      case 'url': $field = 'seo_keyword'; break;
      case 'h1': $field = 'seo_h1'; break;
      case 'h2': $field = 'seo_h2'; break;
      case 'h3': $field = 'seo_h3'; break;
      case 'title': $field = 'meta_title'; break;
      case 'keyword': $field = 'meta_keyword'; break;
      case 'description': $field = 'meta_description'; break;
      case 'full_desc': $field = 'description'; break;
    }
    
    $values = $data = array();
    
    if ($mode == 'store_copy') {
      foreach($this->request->post['langs'] as $lang) {
        if (!$simulate) {
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_information_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'");
          
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_information_description SELECT information_id, '".(int) $lang."', '".(int) $this->store."', title, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "information_description d WHERE d.language_id = '".(int) $lang."'");
        }
        
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang];
        $data['langs'][$lang]['rows'][] = array(
          'link' =>  '',
          'name' =>  'Information data copy to sub-store',
          'old_value' =>  '',
          'value' =>  'Done',
          'changed' =>  '',
        );
      }
      
      return $data;
    }
    
    foreach($this->request->post['langs'] as $lang)
    {
      $this->config->set('mlseo_current_lang', $lang_code[$lang]);
      $values[$lang]['lang_img'] = $lang_img[$lang];
      $values[$lang]['rows'] = array();
      $change_count = 0;
      
      if (isset($this->request->post['mlseo_information_'.$mode.'_pattern'])) {
        $pattern = $this->request->post['mlseo_information_'.$mode.'_pattern'];
      } else {
        $pattern = $this->config->get('mlseo_information_'.$mode.'_pattern');
      }
      
      if ($this->multistore_mode) {
        $total = $this->db->query("SELECT COUNT(*) as total  FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store)->row;
      } else {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "information")->row;
      }
      
      $this->total_items = $total['total'];
      
      $extra_select = '';
      
      if ($mode == 'url') {
        if (version_compare(VERSION, '4', '>=')) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'information_id' AND `value` = d.information_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.language_id = d.language_id OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if ($this->multistore_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword";
        } else if ($this->ml_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('information_id=', d.information_id) AND (u.language_id = d.language_id OR u.language_id = 0) LIMIT 1), '') AS seo_keyword";
        } else {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('information_id=', d.information_id) LIMIT 1), '') AS seo_keyword";
        }
      }
      
      if ($this->store) {
        $desc_table = 'seo_information_description';
        $extra_desc = "AND store_id = '" . (int)$this->store . "'";
        $rows = $this->db->query("SELECT sd.*, i.*, sd.name as title, d.title as orig_title, d.description as orig_description ".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) LEFT JOIN " . DB_PREFIX . "seo_information_description sd ON (i.information_id = sd.information_id AND sd.language_id=".(int) $lang." AND sd.store_id = s.store_id) LEFT JOIN " . DB_PREFIX . "information_description d ON (i.information_id = d.information_id AND d.language_id=".(int) $lang.") WHERE s.store_id = ".(int) $this->store." ORDER BY i.information_id,sd.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        //$rows = $this->db->query("SELECT d.*, i.*, cd.title, cd.description ".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "seo_information_description d ON i.information_id = d.information_id /*LEFT JOIN " . DB_PREFIX . "information_description id ON i.information_id = cd.information_id*/ LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." AND cd.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
      } else {
        $desc_table = 'information_description';
        $extra_desc = '';
        if ($this->multistore_mode) {
          $rows = $this->db->query("SELECT d.*, i.*".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description d ON i.information_id = d.information_id LEFT JOIN " . DB_PREFIX . "information_to_store s ON (i.information_id = s.information_id) WHERE s.store_id = ".(int) $this->store." AND d.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        } else {
          $rows = $this->db->query("SELECT d.*, i.*".$extra_select." FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description d ON i.information_id = d.information_id WHERE d.language_id=".(int) $lang." ORDER BY d.information_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
        }
      }
      
      //$rows = $this->db->query("SELECT *".$extra_select." FROM " . DB_PREFIX . "information_description d WHERE d.language_id=".(int) $lang." ORDER BY d.information_id LIMIT ".$this->start.",".$this->limit)->rows;
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        if (empty($row['title']) && isset($row['orig_title'])) {
          $row['title'] = $row['orig_title'];
        }
        
        if (empty($row['description']) && isset($row['orig_description'])) {
          $row['description'] = $row['orig_description'];
        }
        
        $value = str_replace('[current]', $row[$field], $pattern);
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformInformation($value, $lang, $row, $this->store);
        
        if ($mode != 'url' && $this->multistore_mode && $this->store && !$simulate && is_null($row['store_id'])) {
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_information_description SET information_id = '" . (int)$row['information_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'");
        }
        
        // urls
        if ($mode == 'url')
        {
          if ($empty_only && $row['seo_keyword']) continue;
          
          if (!$simulate) {
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'information_id' AND `value` = '" . $row['information_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if ($this->multistore_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND store_id = " . (int)$this->store);
            } else if ($this->ml_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "' AND language_id IN (".(int) $lang.", 0)");
            } else {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'information_id=" . $row['information_id'] . "'");
            }
          }
          
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'information', $row['information_id'], $lang, $simulate);
          
          if (!$simulate) {
            if ($this->config->get('mlseo_backup')) {
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) {
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'information/information&information_id=" . (int) $row['information_id'] . "', language_id = '" . (int) $lang . "'");
              }
            }
            
            //$this->db->query("UPDATE " . DB_PREFIX . "information_description SET seo_keyword = '". $this->db->escape($value) ."' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . $row['language_id'] . "' ");
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'information_id', `value` = '" . $row['information_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->multistore_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->ml_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'");
            } else {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'information_id=" . $row['information_id'] . "', keyword = '" . $this->db->escape($value) . "'");
            }
          }
          // $field = 'seo_keyword';
        }
        // h1
        elseif ($mode == 'h1')
        {
          if ($empty_only && $row['seo_h1']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h2')
        {
          if ($empty_only && $row['seo_h2']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h3')
        {
          if ($empty_only && $row['seo_h3']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        // Meta title
        elseif ($mode == 'title')
        {
          if ($empty_only && $row['meta_title']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_title';
        }
        // Meta keywords
        elseif ($mode == 'keyword')
        {
          if ($empty_only && $row['meta_keyword']) continue;
          
          if (function_exists('mb_strtolower')) {
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          } else {
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          }
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_keyword';
        }
        // Meta description
        elseif ($mode == 'description')
        {
          if ($empty_only && $row['meta_description']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_description';
        }
        // Description
        elseif ($mode == 'full_desc')
        {
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE information_id = '" . $row['information_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'description';
        }
        
        if (array_key_exists($field, $row)) {
          $changed = !($value === $row[$field]);
        } else {
          $changed = false;
        }
        
        if (!defined('SEO_PACKAGE_CLI')) {
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) {
            $values[$lang]['rows'][] = array(
              'link' =>  $this->url->link('catalog/information/'.$this->edit_action, $this->token . '&information_id=' . $row['information_id'], 'SSL'),
              'name' =>  $row['title'],
              'old_value' =>  (string) $row[$field],
              'value' =>  '[backup url to redirect to new one]',
              'changed' =>  false,
            );
          }
          
          $values[$lang]['rows'][] = array(
            'link' =>  $this->url->link('catalog/information/'.$this->edit_action, $this->token . '&information_id=' . $row['information_id'], 'SSL'),
            'name' =>  $row['title'],
            'old_value' =>  (string) $row[$field],
            'value' =>  $value,
            'changed' =>  $changed,
          );
        }
        
        if ($changed) {
          if (defined('SEO_PACKAGE_CLI')) {
            $this->log('information.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['title'] . ' => ' . $value);
          }
          
          $this->session->data['seopackage_updated']++;
          $change_count++;
          //Powercache::remove('seo_rewrite', 'information_id=' . $row['information_id']);
        }
      } // end foreach $rows
      $values[$lang]['count'] = $change_count;
    }
    $data['langs'] = &$values;
    
    return $data;
  }
  
  public function generator_manufacturer($mode, $simulate, $empty_only, $redirect) {
    if (version_compare(VERSION, '3', '<')) {
      //return $this->generator_manufacturer_old($mode, $simulate, $empty_only, $redirect);
    }
    
    if (!isset($this->request->post['langs'])) { $data['langs'] = array(); return;}
    
    // get languages 
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    unset($languages);
    
    switch ($mode) {
      case 'url': $field = 'seo_keyword'; break;
      case 'h1': $field = 'seo_h1'; break;
      case 'h2': $field = 'seo_h2'; break;
      case 'h3': $field = 'seo_h3'; break;
      case 'title': $field = 'meta_title'; break;
      case 'keyword': $field = 'meta_keyword'; break;
      case 'description': $field = 'meta_description'; break;
      case 'full_desc': $field = 'description'; break;
    }
    
    $values = $data = array();
    
    if ($mode == 'store_copy') {
      foreach($this->request->post['langs'] as $lang) {
        if (!$simulate) {
          $this->db->query("DELETE FROM " . DB_PREFIX . "seo_manufacturer_description WHERE language_id = '".(int) $lang."' AND store_id = '".(int) $this->store."'");
          
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description SELECT manufacturer_id, '".(int) $lang."', '".(int) $this->store."', title, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3 FROM " . DB_PREFIX . "seo_manufacturer_description d WHERE d.language_id = '".(int) $lang."' AND d.store_id = '0'");
        }
        
        $data['langs'][$lang]['lang_img'] = $lang_img[$lang];
        $data['langs'][$lang]['rows'][] = array(
          'link' =>  '',
          'name' =>  'manufacturer data copy to sub-store',
          'old_value' =>  '',
          'value' =>  'Done',
          'changed' =>  '',
        );
      }
      
      return $data;
    }
    
    foreach($this->request->post['langs'] as $lang)
    {
      $this->config->set('mlseo_current_lang', $lang_code[$lang]);
      $values[$lang]['lang_img'] = $lang_img[$lang];
      $values[$lang]['rows'] = array();
      $change_count = 0;
      
      if (isset($this->request->post['mlseo_manufacturer_'.$mode.'_pattern'])) {
        $pattern = $this->request->post['mlseo_manufacturer_'.$mode.'_pattern'];
      } else {
        $pattern = $this->config->get('mlseo_manufacturer_'.$mode.'_pattern');
      }
    
      if ($this->multistore_mode) {
        $total = $this->db->query("SELECT COUNT(*) as total  FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) WHERE s.store_id = ".(int) $this->store)->row;
      } else {
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "manufacturer")->row;
      }
      
      $this->total_items = $total['total'];
      
      $extra_select = '';
      
      if ($mode == 'url') {
        if (version_compare(VERSION, '4', '>=')) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE `key` = 'manufacturer_id' AND `value` = m.manufacturer_id AND (u.language_id = d.language_id OR u.language_id = 0)  AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.language_id = ".(int) $lang." OR u.language_id = 0) AND (u.store_id = ".(int) $this->store.") LIMIT 1), '') AS seo_keyword";
        } else if ($this->multistore_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.store_id = s.store_id) LIMIT 1), '') AS seo_keyword";
        } else if ($this->ml_mode) {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " u WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) AND (u.language_id = ".(int) $lang." OR u.language_id = 0) LIMIT 1), '') AS seo_keyword";
        } else {
          $extra_select = ",IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('manufacturer_id=', m.manufacturer_id) LIMIT 1), '') AS seo_keyword";
        }
      }
      
      $desc_table = 'seo_manufacturer_description';
      $extra_desc = "AND store_id = '" . (int)$this->store . "'";

      $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) WHERE s.store_id = ".(int) $this->store." ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;

      /* manufacturers always need the store id
      if ($this->multistore_mode) {
        $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) WHERE s.store_id = ".(int) $this->store." ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
      } else {
        $rows = $this->db->query("SELECT d.*, m.*, d.name as title, m.name as orig_name ".$extra_select." FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store s ON (m.manufacturer_id = s.manufacturer_id) LEFT JOIN " . DB_PREFIX . "seo_manufacturer_description d ON (m.manufacturer_id = d.manufacturer_id AND d.language_id=".(int) $lang." AND d.store_id = s.store_id) ORDER BY m.manufacturer_id,d.language_id LIMIT ".$this->start.",".$this->limit)->rows;
      }*/
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        if (empty($row['name']) && isset($row['orig_name'])) {
          $row['name'] = $row['orig_name'];
        }
        
        $value = str_replace('[current]', $row[$field], $pattern);
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformManufacturer($value, $lang, $row, $this->store);
        
        //if (!$simulate && !array_key_exists('meta_title', $row)) {
        if (!$simulate && is_null($row['store_id'])) {
          $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description SET manufacturer_id = '" . (int)$row['manufacturer_id'] . "', store_id = '" . (int)$this->store . "', language_id = '" . (int)$lang . "'");
        }
        
        // urls
        if ($mode == 'url')
        {
          if ($empty_only && $row['seo_keyword']) continue;
          
          if (!$simulate) {
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = '" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
            } else if ($this->multistore_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store);
            } else if ($this->ml_mode) {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND language_id IN (".(int) $lang.", 0)");
            } else {
              $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "'");
            }
          }
          
          $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'manufacturer', $row['manufacturer_id'], $lang, $simulate);
          
          if (!$simulate) {
            if ($this->config->get('mlseo_backup')) {
              if ($row['seo_keyword'] && $row['seo_keyword'] != $value) {
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($row['seo_keyword']) . "', redirect = 'product/manufacturer&manufacturer_id=" . (int) $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "'");
              }
            }
            
            if (version_compare(VERSION, '4', '>=')) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'manufacturer_id', `value` = '" . $row['manufacturer_id'] . "', language_id = '" . $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->multistore_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$this->store . "'");
            } else if ($this->ml_mode) {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = '" . (int) $lang . "', keyword = '" . $this->db->escape($value) . "'");
            } else {
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "'");
            }
          }
          // $field = 'seo_keyword';
        }
        // h1
        elseif ($mode == 'h1')
        {
          if ($empty_only && $row['seo_h1']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h1 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h2')
        {
          if ($empty_only && $row['seo_h2']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h2 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        elseif ($mode == 'h3')
        {
          if ($empty_only && $row['seo_h3']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET seo_h3 = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'seo_h1';
        }
        // Meta title
        elseif ($mode == 'title')
        {
          if ($empty_only && $row['meta_title']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_title = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_title';
        }
        // Meta keywords
        elseif ($mode == 'keyword')
        {
          if ($empty_only && $row['meta_keyword']) continue;
          
          if (function_exists('mb_strtolower')) {
            $value = mb_strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          } else {
            $value = strtolower(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
          }
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_keyword = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_keyword';
        }
        // Meta description
        elseif ($mode == 'description')
        {
          if ($empty_only && $row['meta_description']) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET meta_description = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'meta_description';
        }
        // Description
        elseif ($mode == 'full_desc')
        {
          if ($empty_only && trim(strip_tags(html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8')))) continue;
          
          $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
          
          if (!$simulate) {
            $this->db->query("UPDATE " . DB_PREFIX . $desc_table . " SET description = '" . $this->db->escape($value) . "' WHERE manufacturer_id = '" . $row['manufacturer_id'] . "' AND language_id = '" . (int) $lang . "' " . $extra_desc);
          }
          // $field = 'description';
        }
        
        if (array_key_exists($field, $row)) {
          $changed = !($value === $row[$field]);
        } else {
          $changed = false;
        }
        
        if (!defined('SEO_PACKAGE_CLI')) {
          if ($row[$field] && $changed && $mode == 'url' && $this->config->get('mlseo_backup')) {
            $values[$lang]['rows'][] = array(
              'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'),
              'name' =>  $row['name'],
              'old_value' =>  (string) $row[$field],
              'value' =>  '[backup url to redirect to new one]',
              'changed' =>  false,
            );
          }
          
          $values[$lang]['rows'][] = array(
            'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'),
            'name' =>  $row['name'],
            'old_value' =>  (string) $row[$field],
            'value' =>  $value,
            'changed' =>  $changed,
          );
        }
        
        if ($changed) {
          if (defined('SEO_PACKAGE_CLI')) {
            $this->log('manufacturer.' . $mode . ': [' . $lang_code[$lang] . '] ' . $row['name'] . ' => ' . $value);
          }
          
          $this->session->data['seopackage_updated']++;
          $change_count++;
          //Powercache::remove('seo_rewrite', 'manufacturer_id=' . $row['manufacturer_id']);
        }
      } // end foreach $rows
      $values[$lang]['count'] = $change_count;
    }
    $data['langs'] = &$values;
    
    return $data;
  }
  
  public function generator_manufacturer_old($mode, $simulate, $empty_only, $redirect) {
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    
    $values = $data = array();
    $values['lang_img'] = '';
    $values['no_old'] = true;
    $values['rows'] = array();
    
    if (isset($this->request->post['mlseo_manufacturer_'.$mode.'_pattern'])) {
      $pattern = $this->request->post['mlseo_manufacturer_'.$mode.'_pattern'];
    } else {
      $pattern = $this->config->get('mlseo_manufacturer_'.$mode.'_pattern');
    }
    
    $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "manufacturer")->row;
    $this->total_items = $total['total'];
    
    if (version_compare(VERSION, '4', '>=')) {
      $rows = $this->db->query("SELECT name, manufacturer_id, IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = manufacturer_id LIMIT 1), '') AS seo_keyword FROM " . DB_PREFIX . "manufacturer ORDER BY manufacturer_id LIMIT ".$this->start.",".$this->limit)->rows;
    } else {
      $rows = $this->db->query("SELECT name, manufacturer_id, IFNULL((SELECT keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE query = CONCAT('manufacturer_id=',manufacturer_id) LIMIT 1), '') AS seo_keyword FROM " . DB_PREFIX . "manufacturer ORDER BY manufacturer_id LIMIT ".$this->start.",".$this->limit)->rows;
    }
  
    foreach ($rows as $row)
    {
      //Powercache::remove('seo_rewrite', 'manufacturer_id=' . $row['manufacturer_id']);
      $value = str_replace('[current]', $row['seo_keyword'], $pattern);
      $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->transformManufacturer($value, false, $row, $this->store);
      
      if ($mode == 'url')
      {
        if ($empty_only && $row['seo_keyword']) continue;
        
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, 'manufacturer', $row['manufacturer_id'], '', $simulate);

        if (!$simulate) {
          if (version_compare(VERSION, '4', '>=')) {
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = 'manufacturer_id' AND `value` = '" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
          } else if (version_compare(VERSION, '3', '>=')) {
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "' AND store_id = " . (int)$this->store . " AND language_id IN (".(int) $lang.", 0)");
          } else {
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = 'manufacturer_id=" . $row['manufacturer_id'] . "'");
          }
          
          if (version_compare(VERSION, '4', '>=')) {
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'manufacturer_id', `value` = '" . $row['manufacturer_id'] . "', language_id = 0, keyword = '" . $this->db->escape($value) . "'");
          } else if ($this->ml_mode) {
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', language_id = 0, keyword = '" . $this->db->escape($value) . "'");
          } else {
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'manufacturer_id=" . $row['manufacturer_id'] . "', keyword = '" . $this->db->escape($value) . "'");
          }
        }
      }
      
      if (!defined('SEO_PACKAGE_CLI')) {
        $values['rows'][] = array(
          'link' =>  $this->url->link('catalog/manufacturer/'.$this->edit_action, $this->token . '&manufacturer_id=' . $row['manufacturer_id'], 'SSL'),
          'name' =>  $row['name'],
          'old_value' =>  $row['seo_keyword'],
          'value' =>  $value,
          'changed' =>  $row['seo_keyword'] != $value,
        );
      }
      
      if (defined('SEO_PACKAGE_CLI')) {
        $this->log('manufacturer.' . $mode . ': ' . $row['name'] . ' => ' . $value);
      }
    }
    $data['langs'][0] = &$values;
    
    return $data;
    }
  
  public function generator_redirect($mode, $simulate, $empty_only, $redirect) {
    $data = array();
    
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    
    // define('FRONT_MODEL_LOADER', true);
    
    // require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php')); 
    // $this->seo_url = new ControllerCommonSeoUrl($this->registry);
    //$this->seo_url->index();
    
    foreach($this->request->post['langs'] as $lang)
    {
      $values = array();
      $values['lang_img'] = $lang_img[$lang];
      $values['no_old'] = true;
      $values['rows'] = array();
      
      $this->config->set('mlseo_cache', false);
      
      $this->config->set('config_language_id', (int) $lang);
      $this->config->set('config_language', $lang_code[$lang]);
      $this->session->data['language'] = $lang_code[$lang];
      
      $type = $mode;
      
      switch($type) {
        case 'information':
          $route = 'information/information';
          $field = $param = 'information_id';
          break;
        case 'product':
          $route = 'product/product';
          $field = $param = 'product_id';
          break;
        case 'category':
          $route = 'product/category';
          $field = 'category_id';
          $param = 'path';
          break;
        case 'manufacturer':
          $route = 'product/manufacturer/info';
          $field = $param = 'manufacturer_id';
          break;
      }
      
      $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type)->row;
      $this->total_items = $total['total'];
      
      if ($type == 'category') {
        $rows = $this->getCategories(0, '', " LIMIT " . $this->start . "," . $this->limit);
      } else {
        $rows = $this->db->query("SELECT " . $field . " FROM " . DB_PREFIX . $type . " ORDER BY " . $field . " LIMIT " . $this->start . "," . $this->limit)->rows;
      }
      
      if (version_compare(VERSION, '4', '>=')) {
        require_once(DIR_CATALOG . 'model/design/seo_url.php');
      }
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        $this->config->set('config_store_id', $this->store);
        
        if (version_compare(VERSION, '4', '>=')) {
          require_once(DIR_CATALOG . 'model/design/seo_url.php');
          $this->config->set('application', 'Catalog');
          $this->load->model('design/seo_url');
          
          $url = $this->front_url->link($route, $param . '=' . $row[$param]);
          
          $this->config->set('application', 'Admin');
        } else {
          $url = $this->front_url->link($route, $param . '=' . $row[$param]);
        }
        
        // get relative url
        $rel_url = str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url);
         
        $redir = $route . '&' . $param . '=' . $row[$param];
        
        // do not redirect default links
        if (strpos($url, 'index.php?route=') !== false) continue;
        
        //if ($empty_only && $row['seo_keyword']) continue;
        
        $count = $this->db->query("SELECT COUNT(*) as count FROM " . DB_PREFIX . "url_redirect WHERE query = '" . $this->db->escape($rel_url) . "' AND redirect = '" . $this->db->escape($redir) . "' AND language_id = '" . (int) $lang . "'")->row;
        
        if ($count['count']) {
          $changed = 0;
        } else {
          if (!$simulate) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "url_redirect SET query = '" . $this->db->escape($rel_url) . "', redirect = '" . $this->db->escape($redir) . "', language_id = '" . (int) $lang . "'");
          }
          
          $changed = 1;
          $this->session->data['seopackage_updated']++;
        }
        
        if (!defined('SEO_PACKAGE_CLI')) {
        $values['rows'][] = array(
          'link' =>  str_replace(HTTP_SERVER, '../', $url),
          'name' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url),
          'old_value' =>  '',
          'value' => $redir,
          'changed' =>  $changed,
        );
        }
      
        if (defined('SEO_PACKAGE_CLI')) {
          if ($changed) {
            $this->log('redirect.' . $mode . ': ' . $rel_url . ' => ' . str_replace(HTTP_SERVER, '../', $url));
          }
        }
      }
      
      $data['langs'][$lang] = $values;
      $data['langs'][$lang]['count'] = count($values['rows']);
      
      if ($type == 'manufacturer') {
        $data['langs'][$lang]['lang_img'] = false;
        break;
      }
    }
    
    return $data;
  }
  
  public function generator_report($mode, $simulate, $empty_only, $redirect) {
    $values = $data = array();
    $values['lang_img'] = '';
    $values['no_old'] = true;
    $values['rows'] = array();
    $data['nohidecol'] = true;
    $data['hidesim'] = true;
    $data['col1'] = $this->language->get('text_query');
    $data['col2'] = $this->language->get('text_keyword');
    $data['col3'] = $this->language->get('text_status');
    
    if (version_compare(VERSION, '4', '>=')) {
      $urls = $this->db->query("SELECT `key`, `value`, `keyword` FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = ''")->rows;
    } else {
      $urls = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = ''")->rows;
    }
    
    foreach($urls as $url) {
      if (version_compare(VERSION, '4', '>=')) {
        $url['query'] = $url['key'].'='.$url['value'];
      }
      
      $values['rows'][] = array(
        'name' =>  $url['query'],
        'old_value' =>  $url['keyword'],
        'value' =>  '<span style="color:#C94644">'.$this->language->get('text_empty').'</span>',
        'changed' =>  0,
      );
    }
    
    if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) {
      $where = " WHERE store_id = ".(int) $this->store." ";
    } else {
      $where = '';
    }

    //$urls = $this->db->query("SELECT count(*) AS count, query, keyword FROM " . DB_PREFIX . $this->url_alias . " GROUP BY keyword")->rows;
    if (version_compare(VERSION, '4', '>=')) {
      if ($this->ml_mode && $this->config->get('mlseo_duplicate')) {
        $urls = $this->db->query("SELECT count(*) AS count, CONCAT(`key`, `value`) AS query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows;
      } else {
        $urls = $this->db->query("SELECT count(*) AS count, CONCAT(`key`, `value`) AS query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows;
      }
    } else {
      if ($this->ml_mode && $this->config->get('mlseo_duplicate')) {
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows;
      } else {
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows;
      }
    }
    
    foreach($urls as $url) {
      if ($url['keyword'] && $url['count']> 1) {
        if (version_compare(VERSION, '4', '>=')) {
          $duplicates = $this->db->query("SELECT CONCAT(`key`, `value`) AS query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."'")->rows;
        } else {
          $duplicates = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."'")->rows;
        }
        
        foreach($duplicates as $duplicate) {
          $values['rows'][] = array(
            'name' =>  $duplicate['query'],
            'old_value' =>  $duplicate['keyword'],
            'value' =>  '<span style="color:#82669B">'.$this->language->get('text_duplicate').'</span>',
            'changed' =>  0,
          );
        }
      }
    }
    
    $data['langs'][0] = &$values;
    //$data['langs'][0]['count'] = count($urls);
    
    return $data;
  }
  
  public function generator_links($mode, $simulate, $empty_only, $redirect) {
    $data = array();
    
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    
    // define('FRONT_MODEL_LOADER', true);
    
    // require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php')); 
    // $this->seo_url = new ControllerCommonSeoUrl($this->registry);
    //$this->seo_url->index();
    
    $mode = 'product';
    
    foreach($this->request->post['langs'] as $lang)
    {
      $values = array();
      $values['lang_img'] = $lang_img[$lang];
      $values['no_old'] = true;
      $values['rows'] = array();
      
      $this->config->set('mlseo_cache', false);
      
      $this->config->set('config_language_id', (int) $lang);
      $this->config->set('config_language', $lang_code[$lang]);
      $this->session->data['language'] = $lang_code[$lang];
      
      $type = $mode;
      
      switch($type) {
        case 'information':
          $route = 'information/information';
          $field = $param = 'information_id';
          break;
        case 'product':
          $route = 'product/product';
          $field = $param = 'name';
          break;
        case 'category':
          $route = 'product/category';
          $field = 'category_id';
          $param = 'path';
          break;
        case 'manufacturer':
          $route = 'product/manufacturer/info';
          $field = $param = 'manufacturer_id';
          break;
      }
      
      $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type)->row;
      $this->total_items = $total['total'];
      
      if ($type == 'category') {
        $rows = $this->getCategories(0, '', " LIMIT " . $this->start . "," . $this->limit);
      } else {
        $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description ORDER BY " . $field . " LIMIT " . $this->start . "," . $this->limit)->rows;
      }
      
      foreach ($rows as $row) {
        $this->session->data['seopackage_processed']++;
        
        $this->config->set('config_store_id', $this->store);
        
        $url = $this->front_url->link($route, $type . '_id=' . $row[$type.'_id']);
        
        // get relative url
        $rel_url = str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url);
         
        //$redir = $route . '&' . $param . '=' . $row[$param];
        
        // do not redirect default links
        //if (strpos($url, 'index.php?route=') !== false) continue;
        
        //if ($empty_only && $row['seo_keyword']) continue;
        
        if (empty($row[$field])) continue;
        
        $changed = 0;
        
        $insertedInto = $insertedIntoHref = array();
        $searchLinks = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description WHERE description LIKE '%" . $this->db->escape($row[$field]) . "%' AND language_id = '" . (int) $lang . "'")->rows;
        
        foreach ($searchLinks as $res) {
          $orig_desc = $new_desc = $res['description'];
          
          preg_match_all('/(?:&lt;a.+?&gt;)?\b'.preg_quote($row[$field], '/').'\b(?:&lt;\/a&gt;)?/', $orig_desc, $matches);
          
          if (empty($matches)) continue;
          
          foreach ($matches as $match) {
            if (empty($match[0])) continue;
            $new_desc = str_replace($match[0], '&lt;a href="'.$url.'"&gt;'.$row[$field].'&lt;/a&gt;', $orig_desc);
          }
          
          $insertedInto[] = $res[$type.'_id'];
          $insertedIntoHref[] = '<a href="'.$this->url->link('catalog/'.$type.'/edit', $type.'_id='.$res[$type.'_id'].'&'.$this->token).'">'.$res[$type.'_id'].'</a>';
          
          
          if ($orig_desc != $new_desc) {
            if (!$simulate) {
              $this->db->query("UPDATE " . DB_PREFIX . $type . "_description SET description = '" . $this->db->escape($new_desc) . "' WHERE " . $type . "_id = '" . (int) $res[$type . '_id'] . "' AND language_id = '" . (int) $lang . "'");
            }
            
            $changed = 1;
          }
        }
        
        if (empty($insertedInto)) continue;
        
        if ($changed) $this->session->data['seopackage_updated']++;
        
        if (!defined('SEO_PACKAGE_CLI')) {
          $values['rows'][] = array(
            'link' =>  $this->url->link('catalog/'.$type.'/edit', $type.'_id='.$row[$type.'_id'].'&'.$this->token),
            'name' =>  $row['name'],
            'old_value' =>  $url,
            'value' => ($changed ? 'Added link into: ' : 'Link exists into: ') . implode(', ', $insertedIntoHref),
            'changed' => $changed,
          );
        }
      
        if (defined('SEO_PACKAGE_CLI')) {
          if ($changed) {
            $this->log('internal_links: ' . $url . ' => ' . implode(', ', $insertedInto));
          }
        }
      }
      
      $data['langs'][$lang] = $values;
      $data['langs'][$lang]['count'] = count($values['rows']);
      
      if ($type == 'manufacturer') {
        $data['langs'][$lang]['lang_img'] = false;
        break;
      }
    }
    
    return $data;
  }
  
  public function generator_robots($mode, $simulate, $empty_only, $redirect) {
    $values = $data = array();
    $values['lang_img'] = '';
    $values['no_old'] = true;
    $values['no_main'] = true;
    $values['rows'] = array();
    $data['nohidecol'] = true;
    $data['hidesim'] = true;
    $data['col1'] = $this->language->get('text_query');
    $data['col2'] = $this->language->get('text_keyword');
    $data['col3'] = $this->language->get('text_status');
    
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    
    if (!$simulate) {
      $fh = fopen(DIR_CATALOG.'../robots.txt', 'w') or die('robots.txt can not be written, please check rights');
    }
    
    $robots = 'User-agent: *
Disallow: /*?route=checkout/
Disallow: /*?route=account/
Disallow: /*?route=affiliate/
Disallow: /*?route=product/search
Disallow: /*&limit
Disallow: /*?limit
Disallow: /*?sort
Disallow: /*&sort
Disallow: /*?order
Disallow: /*&order
Disallow: /*?price
Disallow: /*&price
Disallow: /*?mode
Disallow: /*&mode
Disallow: /*?cat
Disallow: /*&cat
Disallow: /*?dir
Disallow: /*&dir
Disallow: /*?color
Disallow: /*&color
Disallow: /*?product_id
Disallow: /*&product_id
Disallow: /*?minprice
Disallow: /*&minprice
Disallow: /*?maxprice
Disallow: /*&maxprice
Disallow: /*?page=1
Disallow: /*&create=1
Disallow: /*?keyword
Disallow: /*?av

Sitemap: '.HTTP_CATALOG.'sitemap.xml';

    if (!$simulate) {
      fwrite($fh, $robots);
    }
    
    $values['rows'][] = array(
          'name' =>  '',
          'old_value' =>  '',
          'value' => nl2br($robots),
          'changed' =>  0,
        );
    
    $query = $this->db->query("SELECT product_id FROM " . DB_PREFIX . "product WHERE meta_robots IN ('noindex', 'none')")->rows;
    
    foreach ($query as $product) {
      foreach ($this->request->post['langs'] as $lang) {
        $this->config->set('config_language_id', (int) $lang);
        $this->config->set('config_language', $lang_code[$lang]);
        $this->session->data['language'] = $lang_code[$lang];

        $this->session->data['seopackage_processed']++;
        
        $this->config->set('config_store_id', $this->store);
        
        $url = str_replace(array(HTTP_CATALOG, HTTPS_CATALOG), '/', $this->front_url->link('product/product', 'product_id=' . $product['product_id']));
        
        fwrite($fh, "\n" . 'Disallow: ' . $url);
      
        $values['rows'][] = array(
          'name' =>  '',
          'old_value' =>  '',
          'value' => 'Disallow: ' . $url,
          'changed' =>  0,
        );
      }
    }
    
    if (!$simulate) {
      fclose($fh);
    }
    
    $data['langs'][0] = &$values;
    
    return $data;
  }
  
  protected function getCategories($parent_id, $current_path = '', $limits = '') {
    $route = 'product/category';
    $field = 'category_id';
    $param = 'path';
    
    $categories = array();

    $results = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = " . (int) $parent_id . " ORDER BY " . $field . $limits)->rows;;
    
    foreach ($results as $result) {
      if (!$current_path) {
        $new_path = $result['category_id'];
      } else {
        $new_path = $current_path . '_' . $result['category_id'];
      }

      $categories[] = array(
        'category_id' => $result['category_id'],
        'path' => $new_path,
      );

      $categories = array_merge($categories, $this->getCategories($result['category_id'], $new_path));
    }

    return $categories;
  }
  
  public function generator_cache($mode, $simulate, $empty_only, $redirect) {
    $data = array();
    
    $this->load->model(self::$EXT_PATH.'tool/seo_package');
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    foreach ($languages as $language) {
      $lang_code[$language['language_id']] = $language['code'];
      if (version_compare(VERSION, '2.2', '>=')) {
        $lang_img[$language['language_id']] = 'language/'.$language['code'].'/'.$language['code'].'.png';
      } else {
        $lang_img[$language['language_id']] = 'view/image/flags/'. $language['image'];
      }
    }
    
    if ($mode == 'delete') {
      $values = array();
      $values['lang_img'] = '';
      $values['no_old'] = true;
      $values['rows'] = array();
      foreach($this->request->post['langs'] as $lang)
      {
        $res = Powercache::delete('seo_rewrite.' . (int) $lang);
        if ($res) {
          $values['rows'][] = array(
            'link' =>  0,
            'name' =>  '/system/cache/pcache.seo_rewrite.'.$lang,
            'old_value' =>  '',
            'value' => $this->language->get('text_deleted'),
            'changed' =>  0,
          );
        }
      }
      $data['langs'][$lang] = $values;
      $data['langs'][$lang]['count'] = count($values['rows']);
      return $data;
    }
    
    $data['simulate'] = false;

    //define('FRONT_MODEL_LOADER', true);
    
    //require_once(VQMod::modCheck(DIR_CATALOG . 'controller/common/seo_url.php')); 
    //$this->seo_url = new ControllerCommonSeoUrl($this->registry);

    foreach($this->request->post['langs'] as $lang)
    {
      $values = array();
      $values['lang_img'] = $lang_img[$lang];
      $values['no_old'] = true;
      $values['rows'] = array();
    
      Powercache::delete('seo_rewrite.' . (int) $lang);
      
      $this->config->set('config_language_id', (int) $lang);
      $this->config->set('config_language', $lang_code[$lang]);
      $this->session->data['language'] = $lang_code[$lang];
      
      $types = array('product', 'information');
      $this->total_items = 0;
      foreach ($types as $type)
      {
        switch($type) {
          case 'information':
            $route = 'information/information';
            $field = $param = 'information_id';
            break;
          case 'product':
            $route = 'product/product';
            $field = $param = 'product_id';
            break;
          case 'category':
            $route = 'product/category';
            $field = 'category_id';
            $param = 'path';
            break;
          }
        
        $total = $this->db->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . $type."_description WHERE language_id=".(int)$lang)->row;
        $this->total_items += $total['total'];
        
        $rows = $this->db->query("SELECT ".$field.", seo_keyword, language_id FROM " . DB_PREFIX . $type."_description WHERE language_id=".(int)$lang . " ORDER BY ".$field." LIMIT ".$this->start.",".$this->limit)->rows;
        foreach ($rows as $row)
        {
          
          //$url = $this->front_link($route, $param . '=' . $row[$field]);
          $url = $this->front_url->link($route, $param . '=' . $row[$field]);
          
          $values['rows'][] = array(
            'link' =>  str_replace(HTTP_SERVER, '../', $url),
            'name' =>  'index.php?route=' . $route . '&' . $param . '=' . $row[$field],
            'old_value' =>  '',
            'value' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url),
            'changed' =>  0,
          );

          // product link from categories
          if ($type == 'product')
          {
            $paths = $this->{self::$MODEL_PATH.'tool_seo_package'}->getFullProductPaths($row['product_id']);
            foreach ($paths as $path)
            {
              //$url = $this->url->link('product/product', 'path=' . $path . '&product_id=' . $row['product_id']);
              $url = $this->front_url->link('product/product', 'path=' . $path . '&product_id=' . $row['product_id']);
              
              $values['rows'][] = array(
                'link' =>  str_replace(HTTP_SERVER, '../', $url),
                'name' =>  'index.php?route=product/product&path=' . $path . '&product_id=' . $row['product_id'],
                'old_value' =>  '',
                'value' =>  str_replace(array(HTTP_SERVER, HTTP_CATALOG), '/', $url),
                'changed' =>  0,
              );
            }
          }
          
          //Powercache::add('seo_rewrite', $row['language_id'] . '-route=product/product&product_id=' . $row['product_id'], $url);
          
        }
      }
      
      $data['langs'][$lang] = $values;
      $data['langs'][$lang]['count'] = count($values['rows']);
    }
    
    return $data;
  }
  
  public function generator_cleanup($mode, $simulate, $empty_only, $redirect) {
    $values = $data = array();
    $values['lang_img'] = '';
    $values['no_old'] = true;
    $values['rows'] = array();
    
    if ($mode == 'url') {
      if ($this->ml_mode) {
        if (version_compare(VERSION, '4', '>=')) {
          $urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` IN ('path', 'product_id', 'information_id', 'route') AND language_id=0")->rows;
        } else {
          $urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0")->rows;
        }
      } else {
        //$urls = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%')")->rows;
        $urls = array();
      }
      
      foreach ($urls as $url)
      {
        $values['rows'][] = array(
          'name' =>  $url['query'] . ' ('.$url['keyword'].')',
          'old_value' =>  '',
          'value' => 'Fix assigned language ID',
          'changed' =>  0,
        );
      }
      
      if (!$simulate && false) {
        // Copy keyword values to item tables - Common to all modules - copy first without language id to be sure to have it in case of not defined
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '')");
        $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '')");
        $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '')");
        
        if ($this->ml_mode) {
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id");
          $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id");
          $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id");
        }
      }
      
      if (!$simulate) {
        if ($this->ml_mode) {
          if (version_compare(VERSION, '4', '<')) {
            $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET language_id = ".(int) $this->config->get('config_language_id')." WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0");
          }
          //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%') AND language_id=0");
        } else {
          //$this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'route=%')");
        }
      }
        
      $data['langs'][0] = &$values;
      $data['langs'][0]['count'] = count($urls);
    } else if ($mode == 'duplicate') {
      $data['nohidecol'] = true;
      $data['col1'] = $this->language->get('text_query');
      $data['col2'] = $this->language->get('text_keyword');
      $data['col3'] = $this->language->get('text_status');
    
      $deleted = 0;
      
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) {
        $where = " WHERE store_id = ".(int) $this->store." ";
        $and_store = " AND store_id = ".(int) $this->store." ";
      } else {
        $where = '';
        $and_store = '';
      }
      
      if ($this->ml_mode) {
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword, language_id  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword, language_id")->rows;
      } else {
        $urls = $this->db->query("SELECT count(*) AS count, query, keyword  FROM " . DB_PREFIX . $this->url_alias . $where . " GROUP BY query, keyword")->rows;
      }
      
      foreach($urls as $url) {
        if ($url['count'] > 1) {
          if (!$simulate) {
            if (version_compare(VERSION, '4', '>=')) {
              list($queryKey, $queryVal) = explode('=', $url['query']);
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $queryKey . "' AND `value` = '" . $queryVal . "' AND keyword = '".$url['keyword']."' AND language_id = '".$url['language_id']."' ".$and_store." LIMIT " . ($url['count']-1));
            } else if ($this->ml_mode) {
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '".$url['query']."' AND keyword = '".$url['keyword']."' AND language_id = '".$url['language_id']."' ".$and_store." LIMIT " . ($url['count']-1));
            } else {
              $total_deleted = $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '".$url['query']."' AND keyword = '".$url['keyword']."' ".$and_store." LIMIT " . ($url['count']-1));
            }
          }

          $values['rows'][] = array(
            'name' =>  $url['query'],
            'old_value' =>  $url['keyword'],
            'value' =>  $this->language->get('text_deleted'),
            'changed' =>  0,
          );
          $deleted++;
        }
      }
      
      $data['langs'][0] = &$values;
      $data['langs'][0]['count'] = $deleted;
    }
      
      return $data;
  }
  
  public function get_value() {
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    $type = $this->request->get['type'];
    $fields = $this->request->get['field'];
    $item_id = (int) $this->request->get['id'];
    $store_id = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    
    if ($store_id) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '".$store_id."'");
			
			foreach ($query->rows as $setting) {
				if (!$setting['serialized']) {
					$this->config->set($setting['key'], $setting['value']);
        } else if ($this->OC_V21X) {
					$this->config->set($setting['key'], json_decode($setting['value'], true));
				} else {
					$this->config->set($setting['key'], unserialize($setting['value']));
				}
			}
		}
    
    $lgCodes = $this->config->get('mlseo_lang_codes');
      
    if (!empty($lgCodes[$lang])) {
      $this->config->set('mlseo_current_lang', $lgCodes[$lang]);
    }

    if (!in_array($type, array('product', 'category', 'information', 'manufacturer'))) {
      return '';
    }
    
    
    if ($fields == 'all') {
      if ($type == 'product') {
        $fields = array('seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'image_alt', 'image_title', 'meta_title', 'meta_keyword', 'meta_description', 'tag');
      } else {
        $fields = array('seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'meta_title', 'meta_keyword', 'meta_description');
      }
      
      if ($this->config->get('mlseo_update_description')) {
        $fields[] = 'description';
      }
    }
    
    if (empty($fields)) {
      return '';
    }
    
    $values = array();
    
    foreach ((array) $fields as $field) {
      
      switch ($field) {
        case 'seo_keyword': $mode = 'url'; break;
        case 'seo_h1': $mode = 'h1'; break;
        case 'seo_h2': $mode = 'h2'; break;
        case 'seo_h3': $mode = 'h3'; break;
        case 'meta_title': $mode = 'title'; break;
        case 'meta_keyword': $mode = 'keyword'; break;
        case 'meta_description': $mode = 'description'; break;
        case 'description': $mode = 'full_desc'; break;
        case 'image': $mode = 'image_name'; break;
        case 'image_title': $mode = 'image_title'; break;
        case 'image_alt': $mode = 'image_alt'; break;
        case 'tag': $mode = 'tag'; break;
      }

      //$row = $this->db->query("SELECT * FROM " . DB_PREFIX . $type . "_description WHERE " . $type . "_id = " . (int) $item_id . " AND language_id=" . (int) $lang)->row;

      //$row = $this->request->post[$type.'_description'][$lang];
      $row = $this->request->post;
      $row[$type.'_id'] = $item_id;
      
      // set substore values
      if ($store_id && !empty($row['seo_'.$type.'_description'][$store_id])) {
        if (isset($row[$type.'_description'])) {
          foreach ($row[$type.'_description'] as $language_id => $desc) {
            $row[$type.'_description'][$language_id]['orig_name'] = '';
            if (isset($row[$type.'_description'][$language_id]['name'])) {
              $row[$type.'_description'][$language_id]['orig_name'] = $row[$type.'_description'][$language_id]['name'];
            } else if (isset($row[$type.'_description'][$language_id]['title'])) {
              $row[$type.'_description'][$language_id]['orig_name'] = $row[$type.'_description'][$language_id]['title'];
            }
            $row[$type.'_description'][$language_id]['orig_description'] = $row[$type.'_description'][$language_id]['description'];
            $row[$type.'_description'][$language_id] = array_merge($row[$type.'_description'][$language_id], array_filter($row['seo_'.$type.'_description'][$store_id][$language_id]));
          }
        }
      }
      
      $pattern = $this->config->get('mlseo_'.$type.'_'.$mode.'_pattern');
      
      if ($type == 'manufacturer') {
        $pattern = str_replace('[current]', $row['seo_'.$type.'_description'][$store_id][$lang][$field], $pattern);
      } else {
        $pattern = str_replace('[current]', $row[$type.'_description'][$lang][$field], $pattern);
      }
      
      $this->load->model(self::$EXT_PATH.'tool/seo_package');
      
      $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->{'transform'.ucfirst($type)}($pattern, $lang, $row, $store_id, true);
      
      if ($field == 'tag') {
        if ($lang) {
          $remove = $this->config->get('mlseo_remove_'.$lang);
        } else {
          $remove = $this->config->get('mlseo_remove_'.$this->config->get('config_language_id'));
        }
        
        $value = str_replace('"', '', $value);
        
        if (!empty($remove)) {
          $beforeWord = "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|^)";
          $afterWord =  "(\\s|\\.|\\,|\\!|\\?|\\(|\\)|\\'|\\\"|$)";
          $removeArray = array();
          
          foreach (explode(',', $remove) as $rem) {
            $removeArray[] = '`'.$beforeWord.preg_quote(trim($rem), '`').$afterWord.'`';
          }
          
          if ($removeArray) {
            $value = preg_replace($removeArray, '$1$2', $value);
          }
        }
        
        if ($this->config->get('mlseo_format_tag')) {
          $value = str_replace('.', ',', $value);
          $value = str_replace(array('  ',' '), ', ', $value);
          $value = trim(mb_strtolower($value), ', ');
        }
        
        $value = trim(preg_replace('/(?:,\s*)+/', ',', $value), ', ');
      }
      
      if ($field == 'seo_keyword') {
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, $type, $row[$type.'_id'], $lang);
      }
      
      if ($mode == 'full_desc') {
        $value = nl2br($value);
      }
      
      if ($mode == 'keyword') {
        if (function_exists('mb_strtolower')) {
          $value = mb_strtolower($value);
        } else {
          $value = strtolower($value);
        }
      }
      
      if ($store || $type == 'manufacturer') {
        $values['seo_'.$type.'_description['.$store.']['.$lang.']['.$field.']'] = $value;
      } else {
        $values[$type.'_description['.$lang.']['.$field.']'] = $value;
      }
    }
    
    header('Content-Type: application/json');
    echo json_encode($values);
    exit;
  }
  
  public function generator($type = '', $mode = '', $redirect = '') {
    //sleep (2);
    
    $this->session->data['seopackage_processed'] = 0;
    $this->session->data['seopackage_updated'] = 0;
    
    $benchmark = false;
    if ($benchmark) {
      ini_set('memory_limit', -1);
      set_time_limit(3600);
    }
    $this->start_time = microtime(true)*1000;
    
    $data['OC_V2'] = version_compare(VERSION, '2', '>=');
    
    if (defined('SEO_PACKAGE_CLI')) {
      $this->start = 0;
      $this->limit = 9999999999;
    } else {
      $this->start = (int) $this->request->get['start'];
    }
      
    $this->store = isset($this->request->get['store']) ? $this->request->get['store'] : 0;
    
    if (!$this->start) unset($this->session->data['kwCountArray']);
    
    if (!$type && !isset($this->request->get['type'])) return;
    if (!$mode && !isset($this->request->get['mode'])) return;
    
    if (!$type) $type = $this->request->get['type'];
    if (!$mode) $mode = $this->request->get['mode'];
    if (!$redirect) $redirect = !empty($this->request->get['redirect']) ? $this->request->get['redirect'] : false;
    
    $data['type'] = $type;
    $data['mode'] = $mode;
    $data['simulate'] = $simulate = !empty($this->request->post['simulate']);
    if (!$this->user->hasPermission('modify', self::$LINK)) {
      $data['simulate'] = $simulate = true;
    }
    $data['empty_only'] = $empty_only = !empty($this->request->post['empty_only']);
    
    if (!defined('SEO_PACKAGE_CLI') && $mode == 'related') {
      $this->limit = 100;
    }
      
    $res = $this->{'generator_'.$type}($mode, $simulate, $empty_only, $redirect);
    
    $data['_language'] = $this->language;
    $data['_config'] = $this->config;
    $data['_url'] = $this->url;
    $data['token'] = $this->token;
    
    if ($benchmark) {
      $end_time = microtime(true)*1000;
      var_dump('time: '. ((int)($end_time - $this->start_time) /1000). 's');
      var_dump('mem peak: ' . memory_get_peak_usage()/1000000);
      die;
    }
    
    $processed = $this->start + $this->limit;
    
    if ($processed > $this->total_items) {
      $processed = $this->total_items;
    }
    
    if (!$this->total_items) {
      $progress = 100;
    } else {
      $progress = round(($processed / $this->total_items) * 100);
    }
    
    header('Content-Type: application/json');
    
    echo json_encode(array(
      'success'=> 1,
      'processed' => $processed,
      'progress' => $progress,
      'finished' => $processed >= $this->total_items,
      'log' => $res,
    ));
    
    exit;
    /*
    if ($this->OC_V2) {
      $this->response->setOutput($this->load->view('module/seo_generator.tpl', $data));
    } else {
      $this->data = &$data;
      $this->template = 'module/seo_generator.tpl';
      echo $this->render();
    }
    */
  }
  
  /*<complete*/

  public function cli($params = '') {
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
    
    $start_time = time();
    
    foreach ($languages as $language) {
      $this->request->post['langs'][] = $language['language_id'];
    }

    $this->session->data['seopackage_processed'] = 0;
    $this->session->data['seopackage_updated'] = 0;
    
    $this->start = 0;
    $this->limit = 9999999999;
      
    $this->store = isset($this->request->get['store']) ? $this->request->get['store'] : 0;
    
    // overwrite store settings
    if ($this->store) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '".$this->store."'");
			
			foreach ($query->rows as $setting) {
				if (!$setting['serialized']) {
					$this->config->set($setting['key'], $setting['value']);
        } else if ($this->OC_V21X) {
					$this->config->set($setting['key'], json_decode($setting['value'], true));
				} else {
					$this->config->set($setting['key'], unserialize($setting['value']));
				}
			}
		}
    
    $params = $this->config->get('mlseo_cron');
    
    if (isset($_GET['product']) || isset($_GET['category']) || isset($_GET['information']) || isset($_GET['manufacturer']) || isset($_GET['redirect'])) {
      $params = $_GET;
    } else {
      $params = $this->config->get('mlseo_cron');
      if (!is_array($params)) {
        echo 'No parameters found';
        return;
      }
    }
    
    $simulation = isset($params['simulation']) && $params['simulation'];
    $empty_only = isset($params['empty_only']) && $params['empty_only'];
    
    $simu = $simulation ? 'SIMULATION MODE - ' : '';
    $this->log(PHP_EOL . '----------------------------- CLI Request - ' . $simu . date('d/m/Y H:i:s') . ' - Store ' . $this->store . ' -----------------------------', 'report');
    
    foreach (array('product', 'category', 'information', 'manufacturer', 'redirect') as $mode) {
      if (!empty($_GET[$mode])) {
        $params['update'][$mode] = (array) $_GET[$mode];
      }
    }
    
    if (count($params['update'])) {
      foreach ($params['update'] as $type => $modes) {
        foreach ($modes as $mode) {
          $this->{'generator_'.$type}($mode, $simulation, $empty_only, '');
        }
      }
    }
    
    $total_time = time() - $start_time;
    $hours = floor($total_time/3600);
    $mins = floor(($total_time-($hours * 3600))/60);
    $secs = $total_time-($hours * 3600)-($mins * 60);
    $process_time = '';
    
    if ($hours) {
      $process_time = $hours . ' ' . $this->language->get('text_hours');
    }
    
    if ($hours || $mins) {
      $process_time .= ($hours ? ', ': '') . $mins . ' ' . $this->language->get('text_minutes');
    }
    
    if ($hours || $mins || $secs) {
      $process_time .= ($mins ? ' and ' : '') . $secs . ' ' . $this->language->get('text_seconds');
    } else if (!$process_time) {
      $process_time .= '1 ' . $this->language->get('text_seconds');
    }
    
    $this->log(PHP_EOL .  'Process terminated:', 'report');
    $this->log('- Total items: ' . $this->session->data['seopackage_processed'], 'report');
    $this->log('- Total updated: ' . $this->session->data['seopackage_updated'], 'report');
    $this->log('- Total process time: ' . $process_time, 'report');
    $this->log('-------------------------------------------------------------------------------------------------------' . PHP_EOL, 'report');
    
    echo 'Process terminated - Processed: ' . $this->session->data['seopackage_processed'] . ' - Updated: ' . $this->session->data['seopackage_updated'] . ' - Total time: '. $process_time;
  }
  
  public function editor_data() {
    // DataTables PHP library
    $this->load->model(self::$EXT_PATH.'tool/seo_package_editor');
    $this->load->model('tool/image');
    
    if (!isset($this->request->get['type'])) return;
    if (!isset($this->request->get['lang'])) return;
    
    $type = $this->request->get['type'];
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    
    $columns = array();
    // image column
    $dt = 0;
    if ($type == 'image') {
      $columns[] = array( 'db' => 'image',  'dt' => $dt++, 'formatter' => 'inlineeditor_image');
      $columns[] = array( 'db' => 'name', 'dt' => $dt++);
      $columns[] = array( 'db' => 'image', 'dt' => $dt++, 'formatter' => 'inlineeditor_image_name');
      $columns[] = array( 'db' => 'image_alt', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'image_title', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $type = 'product';
      $columns[] = array( 'db' => $type.'_id', 'dt' => $dt++, 'table_alias' => 'd');
    } else if ($type == 'absolute') {
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'url_absolute_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn' );
    } else if (in_array($type, array('common', 'special'))) {
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_keyword');
      $columns[] = array( 'db' => 'keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => $this->url_alias.'_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn' );
    } else if ($type == 'redirect') {
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'url_redirect_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn');
     } else if ($type == 'autolink') {
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'redirect', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      $columns[] = array( 'db' => 'url_autolink_id', 'dt' => $dt++, 'formatter' => 'editor_deletebtn');
    } else if ($type == '404') {
      $columns[] = array( 'db' => 'query', 'dt' => $dt++, 'formatter' => 'editor_404color');
      $columns[] = array( 'db' => 'referer', 'dt' => $dt++);
      $columns[] = array( 'db' => 'date_accessed', 'dt' => $dt++, 'formatter' => 'editor_date');
      $columns[] = array( 'db' => 'count', 'dt' => $dt++);
      $columns[] = array( 'db' => 'url_404_id', 'dt' => $dt++, 'formatter' => 'editor_404actions');
    } else {
      if (in_array($type, array('product', 'category', 'manufacturer'))) {
        $columns[] = array( 'db' => 'image',  'dt' => $dt++, 'formatter' => 'inlineeditor_image');
        $columns[] = array( 'db' => 'name', 'dt' => $dt++, 'formatter' => 'inlineeditor_text', 'table_alias' => 'd');
      }
      if (in_array($type, array('information'))) {
        if ($store) {
          $columns[] = array( 'db' => 'name', 'dt' => $dt++, 'formatter' => 'inlineeditor_text', 'table_alias' => 'd');
        } else {
          $columns[] = array( 'db' => 'title', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
        }
      }
      /*
      if (in_array($type, array('manufacturer'))) {
        $columns[] = array( 'db' => 'keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
      }
      */
      //if (!in_array($type, array('manufacturer'))) {
      if (true) {
        $columns[] = array( 'db' => 'seo_keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_text');
        $columns[] = array( 'db' => 'meta_title', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
        $columns[] = array( 'db' => 'meta_keyword', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
        $columns[] = array( 'db' => 'meta_description', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
        if (in_array($type, array('product')) && version_compare(VERSION, '1.5.3', '>') && !$store) {
          $columns[] = array( 'db' => 'tag', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
        }
        if (in_array($type, array('product')) && !$store) {
          $columns[] = array( 'db' => 'related', 'dt' => $dt++, 'formatter' => 'inlineeditor_related');
        }
        if (in_array($type, array('product','category'))) {
          $columns[] = array( 'db' => 'seo_h1', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
          $columns[] = array( 'db' => 'seo_h2', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
          $columns[] = array( 'db' => 'seo_h3', 'dt' => $dt++, 'formatter' => 'inlineeditor_textarea');
        }
      }
      $columns[] = array( 'db' => $type.'_id', 'dt' => $dt++, 'table_alias' => 'i');
    }
    
    //header('Content-Type: application/json');
    
    echo json_encode(
      $this->{self::$MODEL_PATH.'tool_seo_package_editor'}->simple( $_GET, $type, $lang, $store, $columns )
    );
    exit;
  }
  
  public function editor_update() {
    if (!$this->user->hasPermission('modify', self::$LINK)) {
      header('Content-Type: application/json');
      echo json_encode(array('status' => 'error', 'msg' => $this->language->get('error_permission')));
      exit;
    }
    
    $pk = $this->request->post['pk'];
    
    if (isset($this->request->get['store'])) {
      $store_id = (int) $this->request->get['store'];
    } else if (isset($this->request->post['store'])) {
      $store_id = (int) $this->request->post['store'];
    } else {
      $store_id = 0;
    }
    
    if (is_string($this->request->post['value'])) {
      $value = html_entity_decode($this->request->post['value'], ENT_QUOTES, 'UTF-8');
    } else {
      $value = $this->request->post['value'];
    }
    
    $col = $this->request->post['col'];
    $type =  isset($this->request->post['type']) ? $this->request->post['type'] : '';
    $lang = isset($this->request->post['lang']) ? $this->request->post['lang'] : '';
    
    if ($type == 'image') {
      $type = 'product';
    }
    
    // return if something is empty
    if (empty($pk) || empty($col)) return;
    
    // allowed values
    if (!in_array($col, array('title', 'name', 'seo_keyword', 'seo_h1', 'seo_h2', 'seo_h3', 'meta_title', 'meta_keyword', 'meta_description', 'tag', 'query', 'keyword', 'redirect', 'related', 'image', 'image_alt', 'image_title'))) return;
    
    if ($col == 'image') {
      $this->load->model(self::$EXT_PATH.'tool/seo_package');
      
      $prod = $this->db->query("SELECT image FROM " . DB_PREFIX . "product WHERE product_id = '" . (int) $pk . "'")->row;
      
      $path = pathinfo($prod['image']);
      $new_path = pathinfo($value);
      
      if (empty($prod['image']) || empty($new_path['filename'])) {
        header('Content-Type: application/json');
        echo json_encode(
          array('status' => 'error', 'pk' => $pk, 'msg' => 'Empty value not allowed')
        );
        exit;
      }
      
      $filename = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($new_path['filename'], 'image', '');
      $value = $path['dirname'] . '/' . $filename . '.' . $path['extension'];
      
      $x = 1;
      
      while (file_exists(DIR_IMAGE . $value)) {
        $value = $path['dirname'] . '/' . $filename . '-' . $x . '.' . $path['extension'];
        $x++;
      }
      
      if (rename(DIR_IMAGE . $prod['image'], DIR_IMAGE . $value)) {
        //$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE product_id = '" . (int) $pk . "'");
        
        // replace all images with such value
        $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($prod['image']) . "'");
        $this->db->query("UPDATE " . DB_PREFIX . "product_image SET image = '". $this->db->escape($value) ."' WHERE image = '" . $this->db->escape($prod['image']) . "'");
      }
      
      $value = pathinfo($value);
      
      header('Content-Type: application/json');
      
      echo json_encode(
        array('status' => 'success', 'pk' => $pk, 'msg' => $value['basename'])
      );
      
      exit;
    }
    
    if ($col == 'related') {
       $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $pk . "'" );
       $res_ids = $res_names = array();
       
       if (empty($value)) {
          $value = array();
       }
       
       foreach ($value as $rel_id) {
          $rel_id = (int) $rel_id;
          if ((int) $rel_id) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "product_related (product_id, related_id) VALUES (" . (int) $pk . ", " . (int) $rel_id . ")");
            $prod = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE language_id=" . $this->config->get('config_language_id') . " AND product_id = '" . (int) $rel_id . "'")->row;
            $res_ids[] = $prod['product_id'];
            $res_names[] = $prod['name'];
          }
      }
      
      header('Content-Type: application/json');
      
      echo json_encode(
        //array('status' => 'success-related', 'val' => implode(',', $res_ids), 'msg' => implode(', ', $res_names), 'pk' => $pk)
        array('status' => 'success', 'pk' => $pk, 'msg' => implode(', ', $res_names))
      );
      
      exit;
    }
    
    $primaryKey = $type . '_id';
    
    if (in_array($type, array('common', 'special'))) {
      $primaryKey = $this->url_alias.'_id';
    } else if ($type == 'redirect') {
      $primaryKey = 'url_redirect_id';
    } else if ($type == 'absolute') {
      $primaryKey = 'url_absolute_id';
    } else if ($type == 'autolink') {
      $primaryKey = 'url_autolink_id';
    }
    
    // update products, categories or informations
    if (in_array($type, array('product', 'category', 'information', 'manufacturer', 'common', 'special', 'redirect', 'absolute', 'autolink'))) {
      if (in_array($type, array('common', 'special'))) {
        // delete route if set by user
        str_replace('route=', '', $value);
        // insert it if necessary
        $route = ($type == 'common' && $col == 'query') ? 'route=' : '';
        
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET " . $col . " = '" . $this->db->escape($route.$value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'");
      } else if ($type == 'redirect') {
        $this->db->query("UPDATE " . DB_PREFIX . "url_redirect SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'");
      } else if ($type == 'autolink') {
        $this->db->query("UPDATE " . DB_PREFIX . "url_autolink SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'");
      } else if ($type == 'absolute') {
        $value = ltrim($value, '/');
        $value = str_replace(array('route=', 'index.php?route='), '', $value);
        $this->db->query("UPDATE " . DB_PREFIX . "url_absolute SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "'");
      }
      
      if ($col == 'seo_keyword') {
        $this->load->model(self::$EXT_PATH.'tool/seo_package');
        $value = $this->{self::$MODEL_PATH.'tool_seo_package'}->filter_seo($value, $type, $pk, $lang);
        
        if ($this->config->get('mlseo_backup')) {
          if (version_compare(VERSION, '4', '>=')) {
            if ($primaryKey == 'category_id') {
              $primaryKey = 'path';
            }
            
            $currentKeywordsQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $primaryKey . "' AND `value` = '" . (int)$pk . "'")->rows;
          } else {
            $currentKeywordsQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "'")->rows;
          }
          
          $currentKeywords = array();
          
          foreach ($currentKeywordsQuery as $curKeyword) {
            $currentKeywords[(isset($curKeyword['store_id']) ? $curKeyword['store_id'] : 0)][(isset($curKeyword['language_id']) ? $curKeyword['language_id'] : $this->config->get('config_language_id'))] = $curKeyword['keyword'];
          }
          
          $currentKeyword = isset($currentKeywords[$store_id][$lang]) ? $currentKeywords[$store_id][$lang] : '';
          
          if ($currentKeyword && $currentKeyword != $value) {
            if ($type == 'product') {
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/product&product_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'");
            } else if ($type == 'category') {
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/category&category_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'");
            } else if ($type == 'information') {
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'information/information&information_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'");
            } else if ($type == 'manufacturer') {
              $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "url_redirect SET query = '/" . $this->db->escape($currentKeyword) . "', redirect = 'product/manufacturer&manufacturer_id=" . (int) $pk . "', language_id = '" . (int) $lang . "'");
            }
          }
        }
        
        // manufacturer has no multilingual keyword
        if (version_compare(VERSION, '4', '>=')) {
          if ($type == 'category') {
            if (version_compare(VERSION, '4', '>=')) {
              $this->load->model('extension/complete_seo/catalog/seo_package');
              $modelSeoPackage = $this->model_extension_complete_seo_catalog_seo_package;
            } else {
              $this->load->model('catalog/seo_package');
              $modelSeoPackage = $this->model_catalog_seo_package;
            }
            
            $modelSeoPackage->setCategorySeoV4($pk, $value, $lang, $store_id);
          } else {
            $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE `key` = '" . $primaryKey . "' AND `value` = '" . (int)$pk . "' AND store_id = " . (int)$store_id . " AND language_id IN (".(int) $lang.", 0)");
            $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = '" . $primaryKey . "', `value` = '" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "', store_id = '" . (int)$store_id . "'");
          }
        } else if (version_compare(VERSION, '3', '>=') || ($this->multistore_mode && $this->ml_mode)) {
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND store_id = " . (int)$store_id . " AND language_id IN (".(int) $lang.", 0)");
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "', store_id = '" . (int)$store_id . "'");
        } else if ($this->multistore_mode) {
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND store_id = " . (int)$store_id);
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', store_id = '" . (int)$store_id . "'");
        } else if ($this->ml_mode) {
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "' AND language_id IN (".(int) $lang.", 0)");
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "', language_id = '" . (int)$lang . "'");
        } else {
          $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE query = '". $primaryKey . "=" . (int)$pk . "'");
          $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '". $primaryKey . "=" . (int)$pk . "', keyword = '" . $this->db->escape($value) . "'");
        }
      } else if (in_array($type, array('product', 'category', 'information', 'manufacturer'))) {
        $seoDesc = ($store_id || $type == 'manufacturer') ? 'seo_' : '';
        $extraWhere = $seoDesc ? " AND store_id = '" . (int)$store_id . "'" : '';
        
        // insert seo desc table if not exists
        if ($seoDesc) {
          $hasSeoDesc = $this->db->query("SELECT * FROM " . DB_PREFIX . $seoDesc . $type . "_description WHERE " . $primaryKey . " = '" . (int)$pk . "' AND language_id = '" . (int)$lang . "'" . $extraWhere)->row;
          
          if(!$hasSeoDesc) {
            $this->db->query("INSERT INTO " . DB_PREFIX . $seoDesc . $type . "_description SET " . $primaryKey . " = '" . (int)$pk . "', store_id = '" . (int)$store_id . "', language_id = '" . (int)$lang . "'");
          }
        }
        
        // update the value
        $this->db->query("UPDATE " . DB_PREFIX . $seoDesc . $type . "_description SET " . $col . " = '" . $this->db->escape($value) . "' WHERE " . $primaryKey . " = '" . (int)$pk . "' AND language_id = '" . (int)$lang . "'" . $extraWhere);
      }
      
      header('Content-Type: application/json');
      
      echo json_encode(
        array('status' => 'success', 'msg' => $value)
      );
      exit;
    }
  }
  
  public function editor_add_alias() {
    if (!$this->user->hasPermission('modify', self::$LINK)) return;
    
    $type = $this->request->get['type'];
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    $query = $_GET['query'];
    $keyword = $_GET['keyword'];
    
    $table = 'url_alias';
    
    if ($type == 'common') {
      $query = 'route=' . str_replace('route=', '', $query);
    } else if ($type == 'absolute') {
      $query = ltrim($query, '/');
      $query = str_replace(array('route=', 'index.php?route='), '', $query);
    }
    
    if ($type == 'redirect' || $type == '404') {
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_redirect SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'");
    } else if ($type == 'autolink') {
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_autolink SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'");
    } else if ($type == 'absolute') {
      $this->db->query("INSERT INTO " . DB_PREFIX . "url_absolute SET query = '" . $this->db->escape($query) . "', redirect = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'");
    } else {
      $storeData = '';
      
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) {
        $storeData = ", store_id = '".(int) $store."'";
      }
      
      if (version_compare(VERSION, '4', '>=')) {
        list($queryKey, $queryVal) = explode('=', $query);
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = '" . $this->db->escape($queryKey) . "', `value` = '" . $this->db->escape($queryVal) . "', keyword = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'" . $storeData);
      } else if ($this->ml_mode) {
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $this->db->escape($query) . "', keyword = '" . $this->db->escape($keyword) . "', language_id = '" . (int) $lang . "'" . $storeData);
      } else {
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $this->db->escape($query) . "', keyword = '" . $this->db->escape($keyword) . "'" . $storeData);
      }
    }
    
  }
  
  public function editor_delete_alias() {
    if (!$this->user->hasPermission('modify', self::$LINK)) return;
    
    $type = $this->request->get['type'];
    $alias_id = $this->request->get['pk'];
    
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    
    if ($type == '404') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_404 WHERE url_404_id =  '". (int) $alias_id . "'");
    } else if ($type == 'redirect') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_redirect WHERE url_redirect_id =  '". (int) $alias_id . "'");
    } else if ($type == 'autolink') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_autolink WHERE url_autolink_id =  '". (int) $alias_id . "'");
    } else if ($type == 'absolute') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_absolute WHERE url_absolute_id =  '". (int) $alias_id . "'");
    } else {
      $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE ".$this->url_alias."_id =  '". (int) $alias_id . "'");
    }
  }
  
  public function editor_delete_aliases() {
    if (!$this->user->hasPermission('modify', self::$LINK)) return;
    
    $type = $this->request->get['type'];
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    
    if ($type == 'common') {
      $extra_where = "query LIKE 'route=%'";
    } elseif ($type == 'special') {
      $extra_where = "query NOT LIKE 'route=%'
                   AND query NOT LIKE 'product_id=%'
                   AND query NOT LIKE 'category_id=%'
                   AND query NOT LIKE 'information_id=%'
                   AND query NOT LIKE 'manufacturer_id=%'";
    }
    
    if ($type == '404') {
      if (!empty($this->request->get['redir_only'])) {
        $this->db->query("DELETE u FROM " . DB_PREFIX . "url_404 u LEFT JOIN " . DB_PREFIX . "url_redirect r ON (u.query = r.query OR REPLACE(u.query, '".HTTP_CATALOG."', '/') = r.query) WHERE r.query IS NOT NULL");
      } else {
        $this->db->query("DELETE FROM " . DB_PREFIX . "url_404");
      }
    } else if ($type == 'redirect') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_redirect");
    } else if ($type == 'autolink') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_autolink");
    } else if ($type == 'absolute') {
      $this->db->query("DELETE FROM " . DB_PREFIX . "url_absolute");
    } else {
      if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) {
        $extra_where .= " AND store_id = '".(int) $store."'";
      }
      
      if ($this->ml_mode) {
        $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where . " AND language_id = '" . (int) $lang . "'");
      } else {
        $this->db->query("DELETE FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where);
      }
    }
  }

  public function editor_restore_aliases() {
    if (!$this->user->hasPermission('modify', self::$LINK)) return;
    
    $this->load->model(self::$EXT_PATH.'setting/friendlyurls');
    $this->load->model('localisation/language');
    
    $lang_code = $this->request->get['lang_code'];
    $lang = isset($this->request->get['lang']) ? (int) $this->request->get['lang'] : 0;
    $store = isset($this->request->get['store']) ? (int) $this->request->get['store'] : 0;
    
    $languages = $this->model_localisation_language->getLanguages();
    
    $langs = array();
    foreach ($languages as $language) {
      $langs[$language['language_id']] = $language['code'];
    }
    
    $this->editor_delete_aliases();
    
    $default_urls = version_compare(VERSION, '4', '>=') ? $this->model_extension_complete_seo_setting_friendlyurls->getFriendlyUrls($lang_code) : $this->model_setting_friendlyurls->getFriendlyUrls($lang_code);
    
    if (version_compare(VERSION, '3', '>=') || $this->multistore_mode) {
      $storeData = ", store_id = '".(int) $store."'";
    }
      
    foreach ($default_urls as $query => $keyword) {
      if ($this->config->get('mlseo_ascii_'.$lang)) {
        include_once(DIR_SYSTEM . 'library/gkd_urlify.php');
        if (function_exists('mb_substr')) {
          $keyword = URLify::downcode($keyword, mb_substr($lang_code, 0, 2));
        } else {
          $keyword = URLify::downcode($keyword, substr($lang_code, 0, 2));
        }
      }
      
      if (version_compare(VERSION, '4', '>=')) {
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET `key` = 'route', `value` = '" . $query . "', keyword = '" . $keyword . "', language_id = '" . (int) $lang . "'" . $storeData);
      } else if ($this->ml_mode) {
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'route=" . $query . "', keyword = '" . $keyword . "', language_id = '" . (int) $lang . "'" . $storeData);
      } else {
        $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = 'route=" . $query . "', keyword = '" . $keyword . "'" . $storeData);
      }
    }
  }
  
  public function editor_export_aliases() {
    $type = $this->request->get['type'];
    $lang = $this->request->get['lang'];
    $lang_code = $this->request->get['lang_code'];
    
    header("Content-type: text/plain");
    header("Content-Disposition: attachment; filename=friendly_export.txt");

    echo "You translated friendly urls and want to integrate them in official package?" . PHP_EOL . "Please send this file to [email protected]" . PHP_EOL . PHP_EOL;
    echo "Language : " . $lang_code . PHP_EOL . PHP_EOL;
     
    if ($type == 'common') {
      $extra_where = "query LIKE 'route=%'";
    } elseif ($type == 'special') {
      $extra_where = "query NOT LIKE 'route=%'
                   AND query NOT LIKE 'product_id=%'
                   AND query NOT LIKE 'category_id=%'
                   AND query NOT LIKE 'information_id=%'
                   AND query NOT LIKE 'manufacturer_id=%'";
    } else {
      exit();
    }
    
    if ($this->ml_mode) {
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where . " AND language_id = '" . (int) $lang . "'");
    } else {
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE " . $extra_where);
    }
    
    foreach($query->rows as $row) {
      echo "'".str_replace('route=', '', $row['query'])."' => '".$row['keyword']."',". PHP_EOL;
    }
    
    exit();
  }
  
  /*complete>*/
  
   public function modal_related() {
    $id = $this->request->post['id'];
       
    $related = $this->db->query("SELECT pr.related_id, pd.name FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product_description pd ON pd.product_id = pr.related_id WHERE pr.product_id=" . (int) $id . " AND pd.language_id=" . $this->config->get('config_language_id'))->rows;
       
    echo '<div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">' . $this->language->get('text_seo_mode_related') . '</h4>
        </div>
        <div class="modal-body">
          <select class="related-select" multiple="multiple">';
    
    foreach ($related as $rel) {
      echo '<option value="' . $rel['related_id'] . '">' . $rel['name'] . '</option>';
    }
    
    echo '</select>
<script type="text/javascript">
  $("select.related-select").select2({
    
  });
</script>
        </div>
      </div>
    </div>';
    
    die;
  }
  
  public function product_search() {
    if (!isset($this->request->get['q'])) {
      header('Content-Type: application/json');
      echo json_encode(array('results'));
      exit;
    }
    
    $q = $this->request->get['q'];
     
    $json = array('results');
    
    $products = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE name LIKE '" . $this->db->escape($q) . "%' AND language_id=" . $this->config->get('config_language_id') . " LIMIT 30")->rows; 
    
    if (!$products) {
      $products = $this->db->query("SELECT product_id, name FROM " . DB_PREFIX . "product_description WHERE name LIKE '%" . $this->db->escape($q) . "%' AND language_id=" . $this->config->get('config_language_id') . " LIMIT 30")->rows;
    }
    
    foreach ($products as $product) {
      $json['results'][] = array(
        'id' => $product['product_id'],
        'text' => htmlspecialchars_decode($product['name']),
      );
    }
    
    header('Content-Type: application/json');
    echo json_encode($json);
    
    exit;
   }
   
   public function modal_info() {
    $item = $this->request->post['info'];
    
    $extra_class = $this->language->get('info_css_' . $item) != 'info_css_' . $item ? $this->language->get('info_css_' . $item) : 'modal-lg';
    $title = $this->language->get('info_title_' . $item) != 'info_title_' . $item ? $this->language->get('info_title_' . $item) : $this->language->get('info_title_default');
    $message = $this->language->get('info_msg_' . $item) != 'info_msg_' . $item? $this->language->get('info_msg_' . $item) : $this->language->get('info_msg_default');
    
    echo '<div class="modal-dialog ' . $extra_class . '">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title"><i class="fa fa-info-circle"></i> ' . $title . '</h4>
        </div>
        <div class="modal-body">' . $message . '</div>
      </div>
    </div>';
    
    die;
  }
  
  public function install($redir = false) {
    if ($this->config->get('mlseo_enabled')) return;
    
    if (version_compare(VERSION, '3', '<') && is_dir(DIR_APPLICATION.'controller/extension/module')) {
      //@rename(DIR_APPLICATION.'controller/extension/module', DIR_APPLICATION.'controller/extension/.seo_package');
    }
    
    // rights
    /*
    $this->load->model('user/user_group');

    if (!$this->user->hasPermission('modify', self::$LINK)) {
      $this->model_user_user_group->addPermission(version_compare(VERSION, '2.0.2', '>=') ? $this->user->getGroupId() : 1, 'access', 'module/' . self::MODULE);
      $this->model_user_user_group->addPermission(version_compare(VERSION, '2.0.2', '>=') ? $this->user->getGroupId() : 1, 'modify', 'module/' . self::MODULE);
    }
    */
    
    // check tables
    $this->db_tables();
    
    $this->load->model('localisation/language');
    $languages = array();
    $results = $this->model_localisation_language->getLanguages();
    
    foreach ($results as $result) {
      $languages[$result['code']] = $result;
    }

    // set old keywords to all languages
    /*
    if (count($languages) > 1) {
      $keywords = $this->db->query("SELECT * FROM `" . DB_PREFIX . $this->url_alias . "`")->rows;
      foreach ($languages as $language) {
        foreach ($keywords as $row) {
          if (strpos($row['query'], '=') !== false) {
            list($type, $id) = explode('=', $row['query']);
            $type = str_replace('_id', '', $type);
            if (in_array($type, array('product', 'category', 'information'))) {
              $this->db->query("UPDATE " . DB_PREFIX . $type . "_description SET seo_keyword = '" . $row['keyword'] . "' WHERE  " . $type . "_id = '" . $id . "' AND language_id = '" . $language['language_id'] . "'");
              $this->db->query("INSERT INTO " . DB_PREFIX . $this->url_alias . " SET query = '" . $row['query'] . "', keyword = '" . $row['keyword'] . "', language_id = '" . $language['language_id'] . "'");
            }
          }
        }
      }

      $this->db->query("DELETE FROM `" . DB_PREFIX . $this->url_alias . "` WHERE language_id = 0 AND (query LIKE 'product_id=%' OR query LIKE 'category_id=%' OR query LIKE 'information_id=%')");
    }
    */

    // Friendly urls
    /* @todo
    $this->load->model('localisation/language');
    $this->load->model('setting/friendlyurls');
    $languages = $this->model_localisation_language->getLanguages();
    $friendly_urls = array();
    foreach($languages as $language)
    {
      $friendly_urls['mlseo_urls_'.$language['code']] = $this->model_setting_friendlyurls->getFriendlyUrls($language['code']);
    }
    */
    
    $this->load->model('setting/setting');
    $this->model_setting_setting->editSetting('mlseo', array(
        'mlseo_whitespace' => '-',
        'mlseo_extension' => '',
        'mlseo_hreflang' => true,
        'mlseo_friendly' => true,
        //'mlseo_absolute' => true,
        'mlseo_lowercase' => true,
        'mlseo_duplicate' => true,
        'mlseo_canonical' => true,
        'mlseo_pagination_fix' => true,
        'mlseo_default_lang' => $this->config->get('config_language'),
        'mlseo_insertautotitle' => true,
        'mlseo_insertautourl' => true,
        'mlseo_editautourl' => true,
        'mlseo_insertautometakeyword' => true,
        'mlseo_editautometakeyword' => true,
        'mlseo_insertautoseotitle' => true,
        'mlseo_editautoseotitle' => true,
        'mlseo_insertautometadesc' => true,
        'mlseo_editautometadesc' => true,
        //'mlseo_banners' => true,
        'mlseo_safe_url' => 'ext',
        'mlseo_product_url_pattern' => '[name]',
        'mlseo_product_h1_pattern' => '[name]',
        'mlseo_product_h2_pattern' => '[name]',
        'mlseo_product_h3_pattern' => '[name]',
        'mlseo_product_image_alt_pattern' => '[name]',
        'mlseo_product_image_title_pattern' => '[name]',
        'mlseo_product_image_name_pattern' => '[name]',
        'mlseo_product_title_pattern' => '[name] - [model]',
        'mlseo_product_keyword_pattern' => '[name], [model], [category]',
        'mlseo_product_description_pattern' => '[name] - [model] - [category] - [desc]',
        'mlseo_product_full_desc_pattern' => '[name] - [model] - [category]',
        'mlseo_product_tag_pattern' => '[name], [model], [category]',
        'mlseo_category_url_pattern' => '[name]',
        'mlseo_category_h1_pattern' => '[name]',
        'mlseo_category_h2_pattern' => '[name]',
        'mlseo_category_h3_pattern' => '[name]',
        'mlseo_category_title_pattern' => '[name]',
        'mlseo_category_keyword_pattern' => '[name], [desc]',
        'mlseo_category_description_pattern' => '[name] - [desc]',
        'mlseo_category_full_desc_pattern' => '[name]',
        'mlseo_information_url_pattern' => '[name]',
        'mlseo_information_h1_pattern' => '[name]',
        'mlseo_information_h2_pattern' => '[name]',
        'mlseo_information_h3_pattern' => '[name]',
        'mlseo_information_title_pattern' => '[name]',
        'mlseo_information_keyword_pattern' => '[name] [desc]',
        'mlseo_information_description_pattern' => '[name] - [desc]',
        'mlseo_information_full_desc_pattern' => '[name]',
        'mlseo_manufacturer_url_pattern' => '[name]',
        'mlseo_manufacturer_h1_pattern' => '[name]',
        'mlseo_manufacturer_h2_pattern' => '[name]',
        'mlseo_manufacturer_h3_pattern' => '[name]',
        'mlseo_manufacturer_title_pattern' => '[name]',
        'mlseo_product_related_relevance' => 5,
        'mlseo_product_related_no' => 5,
        'mlseo_microdata_data' => array('model' => 1, 'desc' => 1, 'brand' => 1, 'reviews' => 1, 'product' => 1, 'organization' => 1, 'store' => 1, 'website' => 1, 'breadcrumbs' => 1, 'organization_search' => 1, 'store_logo' => 1, 'store_mail' => 1, 'website_search' => 1),
        'mlseo_tcard_data' => array('desc' => 1),
        'mlseo_opengraph_data' => array('desc' => 1),
      ));
      
    if (is_writable(DIR_CATALOG.'../index.php')) {
      $index = file_get_contents(DIR_CATALOG.'../index.php');
      if (strpos($index, 'new multilingual_seo') === false && strpos($index, '$languages = array();') !== false) {
        $index = str_replace('$languages = array();', '$languages = array();'."\n".'$multilingual = new multilingual_seo($registry); $multilingual->detect();', $index);
        file_put_contents(DIR_CATALOG.'../index.php', $index);
      }
    }
    
    if ($redir || !empty($this->request->get['redir'])) {
      if (version_compare(VERSION, '2', '>=')) {
				$this->response->redirect($this->url->link('module/'.self::MODULE, $this->token, 'SSL'));
			} else {
				$this->redirect($this->url->link('module/'.self::MODULE, $this->token, 'SSL'));
			}
    }
  }
  
  private function log($msg = '', $mode = 'all') {
    if ($this->config->get('mlseo_cron_log') == 'off') return;
    if ($this->config->get('mlseo_cron_log') == 'report' && $mode != 'report') return;
    
    $log = DIR_LOGS.'seo_package_cli.log';
    $txt = $msg . PHP_EOL;
    file_put_contents($log, $txt, FILE_APPEND | LOCK_EX);
  }
  
  public function uninstall() {
  /*
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` DROP `seo_keyword`");
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `seo_keyword`");
    if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` DROP `seo_keyword`");
    if (!$this->OC_V2) {
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` DROP `meta_title`");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_title`");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_description'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_description`");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_keyword'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` DROP `meta_keyword`");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` DROP `meta_title`");
    }
    */
    //$default_lang = $this->db->query("SELECT language_id FROM " . DB_PREFIX . "language WHERE code = '" . $this->config->get('config_language') . "'")->row['language_id'];
    $default_lang = $this->config->get('config_language_id');
    
    if (version_compare(VERSION, '3', '<')) {
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row) {
        $this->db->query("DELETE FROM `" . DB_PREFIX . $this->url_alias . "` WHERE language_id <> " . $default_lang . " AND language_id <> 0");
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` DROP `language_id`");
      }
    }
    
    if (version_compare(VERSION, '2.2', '<')) {
      $index = file_get_contents(DIR_CATALOG.'../index.php');
      $index = str_replace('$multilingual = new multilingual_seo($registry); $multilingual->detect();', '', $index);
      file_put_contents(DIR_CATALOG.'../index.php', $index);
    }
  }
  
  private function validate() {
    if (!$this->user->hasPermission('modify', self::$LINK)) {
      $this->error['error'] = $this->language->get('error_permission');
    }
    
    if (!$this->error)
      return true;
    return false;
  }
  
  private function db_tables() {
    $this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
      
    // check DB columns
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product` LIKE 'meta_robots'")->row) {
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` CHANGE `date_available` `date_available` DATE NULL"); // fix incorrect default value on some sql version
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` ADD `meta_robots` VARCHAR(40) NOT NULL");
    }
    if (!$this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "category LIKE 'meta_robots'")->row) {
      $this->db->query("ALTER TABLE " . DB_PREFIX . "category ADD meta_robots VARCHAR(40) NOT NULL");
    }
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information` LIKE 'meta_robots'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information` ADD `meta_robots` VARCHAR(40) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product` LIKE 'seo_canonical'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product` ADD `seo_canonical` VARCHAR(32) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_keyword` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h1'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h1` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h2'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h2` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_h3'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `seo_h3` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'image_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `image_title` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'image_alt'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `image_alt` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_keyword` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_keyword'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_keyword` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h1'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h1` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h2'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h2` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_h3'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `seo_h3` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h1'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h1` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h2'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h2` VARCHAR(255) NOT NULL");
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_h3'")->row)
      $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `seo_h3` VARCHAR(255) NOT NULL");
    if (!version_compare(VERSION, '2', '>=')) {
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL");
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_title'")->row && !$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` CHANGE `seo_title` `meta_title` VARCHAR(255) NOT NULL");
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "product_description` ADD `meta_title` VARCHAR(255) NOT NULL");
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_title` VARCHAR(255) NOT NULL");
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_description'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_description` VARCHAR(255) NOT NULL");
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'meta_keyword'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_keyword` VARCHAR(255) NOT NULL");
      if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'meta_title'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "category_description` ADD `meta_title` VARCHAR(255) NOT NULL");
    }
    
    if (version_compare(VERSION, '3', '<')) {
      if (count($languages) > 1) {
        if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row)
          $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` ADD `language_id` INT(11) NOT NULL DEFAULT '0'");
        
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET language_id = ".(int) $this->config->get('config_language_id')." WHERE (query LIKE 'category_id=%' OR query LIKE 'product_id=%' OR query LIKE 'information_id=%' OR query LIKE 'route=%') AND language_id=0");
      }
    }
    
    try {
      if (!$this->db->query("SHOW INDEX FROM " . DB_PREFIX . "product_description WHERE Key_name='related_generator'")->row)
        $this->db->query("CREATE FULLTEXT INDEX related_generator ON " . DB_PREFIX . "product_description (name, description)");
    } catch (Exception $e) {}
    
    if ($this->config->get('mlseo_multistore')) {
       if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'store_id'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` ADD `store_id` INT(11) NOT NULL DEFAULT '0'");
      
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_product_description` (
          `product_id` int(11) NOT NULL,
          `language_id` int(11) NOT NULL DEFAULT 0,
          `store_id` int(11) NOT NULL DEFAULT 0,
          `name` varchar(255) NOT NULL DEFAULT '',
          `description` text NOT NULL DEFAULT '',
          `meta_title` varchar(255) NOT NULL DEFAULT '',
          `meta_description` varchar(255) NOT NULL DEFAULT '',
          `meta_keyword` varchar(255) NOT NULL DEFAULT '',
          `image_title` varchar(255) NOT NULL DEFAULT '',
          `image_alt` varchar(255) NOT NULL DEFAULT '',
          `seo_h1` varchar(255) NOT NULL DEFAULT '',
          `seo_h2` varchar(255) NOT NULL DEFAULT '',
          `seo_h3` varchar(255) NOT NULL DEFAULT '',
          PRIMARY KEY (`product_id`,`language_id`,`store_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
        
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_category_description` (
          `category_id` int(11) NOT NULL,
          `language_id` int(11) NOT NULL DEFAULT 0,
          `store_id` int(11) NOT NULL DEFAULT 0,
          `name` varchar(255) NOT NULL DEFAULT '',
          `description` text NOT NULL DEFAULT '',
          `meta_title` varchar(255) NOT NULL DEFAULT '',
          `meta_description` varchar(255) NOT NULL DEFAULT '',
          `meta_keyword` varchar(255) NOT NULL DEFAULT '',
          `seo_h1` varchar(255) NOT NULL DEFAULT '',
          `seo_h2` varchar(255) NOT NULL DEFAULT '',
          `seo_h3` varchar(255) NOT NULL DEFAULT '',
          PRIMARY KEY (`category_id`,`language_id`,`store_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
      
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_information_description` (
          `information_id` int(11) NOT NULL,
          `language_id` int(11) NOT NULL DEFAULT 0,
          `store_id` int(11) NOT NULL DEFAULT 0,
          `name` varchar(255) NOT NULL DEFAULT '',
          `description` text NOT NULL DEFAULT '',
          `meta_title` varchar(255) NOT NULL DEFAULT '',
          `meta_description` varchar(255) NOT NULL DEFAULT '',
          `meta_keyword` varchar(255) NOT NULL DEFAULT '',
          `seo_h1` varchar(255) NOT NULL DEFAULT '',
          `seo_h2` varchar(255) NOT NULL DEFAULT '',
          `seo_h3` varchar(255) NOT NULL DEFAULT '',
          PRIMARY KEY (`information_id`,`language_id`,`store_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
      }
    
    if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_manufacturer_description'")->row) {
      if (!$this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "seo_manufacturer_description LIKE 'store_id'")->row) {
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_manufacturer_description` RENAME TO " . DB_PREFIX . "seo_manufacturer_description_old");
        
        $transferManufacturerData = true;
      }
    }
        
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "seo_manufacturer_description` (
        `manufacturer_id` int(11) NOT NULL,
        `language_id` int(11) NOT NULL DEFAULT 0,
        `store_id` int(11) NOT NULL DEFAULT 0,
        `name` varchar(255) NOT NULL DEFAULT '',
        `description` text NOT NULL DEFAULT '',
        `meta_title` varchar(255) NOT NULL DEFAULT '',
        `meta_description` varchar(255) NOT NULL DEFAULT '',
        `meta_keyword` varchar(255) NOT NULL DEFAULT '',
        `seo_h1` varchar(255) NOT NULL DEFAULT '',
        `seo_h2` varchar(255) NOT NULL DEFAULT '',
        `seo_h3` varchar(255) NOT NULL DEFAULT '',
        PRIMARY KEY (`manufacturer_id`,`language_id`,`store_id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
    
    if (!empty($transferManufacturerData)) {
      $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description (manufacturer_id, language_id, store_id, name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3)
                              SELECT md.manufacturer_id, md.language_id, '0', '', md.description, md.meta_title, md.meta_description, md.meta_keyword, '', '', '' FROM " . DB_PREFIX . "seo_manufacturer_description_old md");
    }
    
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_absolute` (
        `url_absolute_id` int(11) NOT NULL AUTO_INCREMENT,
        `query` varchar(1000) NOT NULL,
        `redirect` varchar(1000) NOT NULL,
        `language_id` int(3) NOT NULL DEFAULT '0',
        PRIMARY KEY (`url_absolute_id`),
        KEY `query` (`query`),
        KEY `redirect` (`redirect`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
    
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_autolink` (
        `url_autolink_id` int(11) NOT NULL AUTO_INCREMENT,
        `query` varchar(256) NOT NULL,
        `redirect` varchar(1000) NOT NULL,
        `language_id` int(3) NOT NULL DEFAULT '0',
        PRIMARY KEY (`url_autolink_id`),
        KEY `query` (`query`),
        KEY `redirect` (`redirect`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
      
      
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_redirect` (
        `url_redirect_id` int(11) NOT NULL AUTO_INCREMENT,
        `query` varchar(1000) NOT NULL,
        `redirect` varchar(1000) NOT NULL,
        `language_id` int(3) NOT NULL DEFAULT '0',
        `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
        PRIMARY KEY (`url_redirect_id`),
        KEY `query` (`query`),
        KEY `redirect` (`redirect`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
     
    $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "url_404` (
        `url_404_id` int(11) NOT NULL AUTO_INCREMENT,
        `query` varchar(1000) NOT NULL,
        `referer` varchar(1000) NOT NULL,
        `count` int(11) NOT NULL DEFAULT '0',
        `date_accessed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
        PRIMARY KEY (`url_404_id`),
        KEY `query` (`query`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
      
    if (!$this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "url_404` LIKE 'referer'")->row)
        $this->db->query("ALTER TABLE `" . DB_PREFIX . "url_404` ADD `referer` VARCHAR(1000) NOT NULL");
    
    foreach (array('product', 'category', 'information') as $type) {
      $varchar = $this->db->query("SELECT CHARACTER_MAXIMUM_LENGTH AS length FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = '" . DB_PREFIX . $type . "_description' AND COLUMN_NAME = 'seo_keyword'")->row;
      if ($varchar['length'] < 255) {
        $this->db->query("ALTER TABLE `" . DB_PREFIX . $type . "_description` MODIFY COLUMN `seo_keyword` VARCHAR(255) NOT NULL");
      }
    }
  }
  
  public function report() {
    set_time_limit(600);
    
    echo '<h3>URL ALIAS report</h3>';
    echo '<table border="1" cellpadding="10" style="border-collapse:collapse;"><tr style="font-weight:bold">';
    echo '<td>query</td>
          <td>keyword</td>
          <td>Issue</td>';

    
    $urls = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '' ")->rows;
    
    foreach($urls as $url) {
       echo '<tr>
          <td>'.$url['query'].'</td>
          <td>'.$url['keyword'].'</td>
          <td><span style="color:red">empty</span></td>
          </tr>';
    }
    
    $urls = $this->db->query("SELECT count(*) AS count, query, keyword FROM " . DB_PREFIX . $this->url_alias . " GROUP BY keyword ")->rows;
    
    foreach($urls as $url) {
      if ($url['keyword'] && $url['count']> 1) {
        $duplicates = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . $this->url_alias . " WHERE keyword = '".$url['keyword']."' ")->rows;
        foreach($duplicates as $duplicate) {
        echo '<tr>
          <td>'.$duplicate['query'].'</td>
          <td>'.$duplicate['keyword'].'</td>
          <td>'.(!$duplicate['keyword'] ? '<span style="color:red">empty</span>' : '<span style="color:orange">duplicate</span>').'</td>
          </tr>';
        }
      }
    }
    die;
  }
  
  private function sortByName($a, $b) {
    return strcmp($a['name'], $b['name']);
  }
  
  public function backup() {
    header('Pragma: public');
    header('Expires: 0');
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="complete_seo_' . date('Y-m-d', time()) . '_backup.sql"');
    header('Content-Transfer-Encoding: binary');
    
    $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE code = 'mlseo'")->rows;
    
    echo "DELETE FROM " . DB_PREFIX . "setting WHERE code = 'mlseo';\n\n";
    
    foreach ($rows as $row) {
      echo "INSERT INTO " . DB_PREFIX . "setting (`store_id`, `code`, `key`, `value`, `serialized`) VALUES ";
      echo "(".$row['store_id'].", 'mlseo', '".$row['key']."', '".$row['value']."', ".$row['serialized'].");\n";
    }
    
    die;
  }
  
  public function upgrade() {
    if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
      if (!$this->user->hasPermission('modify', self::$LINK)) {
        die('Not allowed');
      }
      
      $this->load->model('setting/setting');
      
      $data['info'] = array();
      
      $data['info'][] = 'SEO URLs correctly transferred';
      
      // Remove extension
      if ($this->request->post['module'] == 'broken_link_manager') {
        $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . "error")->rows;
        
        foreach ($rows as $row) {
          $this->db->query("INSERT INTO `" . DB_PREFIX . "url_redirect` SET `query` = '".$this->db->escape(urldecode($row['error']))."', `redirect` = '".$this->db->escape($row['redirect'])."'");
        }
        
        goto end;
      }
      
      if (!empty($this->request->post['ext'])) {
        $this->db->query("UPDATE " . DB_PREFIX . $this->url_alias . " SET keyword = REPLACE(keyword, '".$this->db->escape($this->request->post['ext'])."', '')");
      }
      
      // Copy image title and alt - Paladin
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'title_image'")->row) {
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `image_title` = `title_image`");
      }
      
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'alt_image'")->row) {
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `image_alt` = `alt_image`");
      }
      
      // Copy lang id of url alias table - All in one SEO
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'lang'")->row) {
        $this->db->query("UPDATE `" . DB_PREFIX . $this->url_alias . "` SET `language_id` = `lang`");
      }
      
      // Pack pro
      if ($this->request->post['module'] == 'seo_pack_pro') {
        foreach (array('canonicals', 'clickfix', 'custom_alt_generator', 'custom_h1_generator', 'custom_h2_generator', 'autolinks', 'keywords_generator', 'mlseo', 'not_found_report', 'bot_report', 'redirect', 'rename_files', 'richsnippets', 'seoedit', 'seoeditor', 'seoimages', 'seopagination', 'seoreplacer', 'custom_title_generator', 'custom_imgtitle_generator', 'extendedseo', 'l', 'meta_description_generator', 'rp_generator', 'seopack', 'seoreport', 'table_edit_ajax', 'tag_generator') as $file) {
          @rename(DIR_APPLICATION.'controller/extension/extension/'.$file.'.php', DIR_APPLICATION.'controller/extension/extension/'.$file.'.php.bak');
        }
        
        $data['info'][] = 'Disabled unecessary seo pack pro files';
        
        $store_seo_title = $this->config->get('config_meta_title');
        $store_seo_desc = $this->config->get('config_meta_description');
        $store_seo_keyword = $this->config->get('config_meta_keyword');
        
        $settings = $this->model_setting_setting->getSetting('mlseo');
        
        foreach (array('0') as $store) {
          if (is_array($store_seo_title)) {
            foreach ($store_seo_title as $language => $value) {
              $settings['mlseo_store'][$store.$language]['seo_title'] = $value;
            }
          }
          if (is_array($store_seo_desc)) {
            foreach ($store_seo_desc as $language => $value) {
              $settings['mlseo_store'][$store.$language]['description'] = $value;
            }
          }
          if (is_array($store_seo_keyword)) {
            foreach ($store_seo_keyword as $language => $value) {
              $settings['mlseo_store'][$store.$language]['keywords'] = $value;
            }
          }
        }
		
        $this->model_setting_setting->editSetting('mlseo', $settings);
        
        $data['info'][] = 'Store SEO correctly transferred';
        
        // Copy image title and alt
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "product_description_seo'")->row) {
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description_seo` LIKE 'custom_h1'")->row) {
            $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . "product_description_seo` u SET d.image_title = u.custom_imgtitle, d.image_alt = u.custom_alt, d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.product_id = u.product_id AND d.language_id = u.language_id");
          }
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "category_description_seo'")->row) {
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description_seo` LIKE 'custom_h1'")->row) {
            $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . "category_description_seo` u SET d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.category_id = u.category_id AND d.language_id = u.language_id");
          }
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "information_description_seo'")->row) {
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description_seo` LIKE 'custom_h1'")->row) {
            $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . "information_description_seo` u SET d.seo_h1 = u.custom_h1, d.seo_h2 = u.custom_h2 WHERE d.information_id = u.information_id AND d.language_id = u.language_id");
          }
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "url_redirect'")->row) {
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "url_redirect` LIKE 'oldurl'")->row) {
            $this->db->query("RENAME TABLE " . DB_PREFIX . "url_redirect TO " . DB_PREFIX . "url_redirect_seopackpro");
          }
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "manufacturer_description'")->row) {
          if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "manufacturer_description` LIKE 'manufacturer_id'")->row) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "seo_manufacturer_description (manufacturer_id, language_id, store_id, name, description, meta_title, meta_description, meta_keyword, seo_h1, seo_h2, seo_h3)
                              SELECT md.manufacturer_id, md.language_id, '0', '', md.description, md.custom_title, md.meta_description, md.meta_keyword, '', '', '' FROM " . DB_PREFIX . "manufacturer_description md
                              LEFT JOIN " . DB_PREFIX . "manufacturer_to_store ms ON (ms.manufacturer_id = md.manufacturer_id)");
          }
        }
        
        $data['info'][] = 'SEO img titles, img alt, H1, H2, manufacturers correctly transferred';
      } else if ($this->request->post['module'] == 'paladin') {
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "product_description` LIKE 'seo_title'")->row) {
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `meta_title` = `seo_title`");
        }
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category_description` LIKE 'seo_title'")->row) {
          $this->db->query("UPDATE `" . DB_PREFIX . "category_description` SET `meta_title` = `seo_title`");
        }
        if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "information_description` LIKE 'seo_title'")->row) {
          $this->db->query("UPDATE `" . DB_PREFIX . "information_description` SET `meta_title` = `seo_title`");
        }
        
        $this->db->query("DELETE FROM `" . DB_PREFIX . "url_alias` WHERE query LIKE 'manufacturer_id=%' AND auto_gen = 'CPBI_urls'");
        $this->db->query("UPDATE `" . DB_PREFIX . "url_alias` SET language_id = 0 WHERE query LIKE 'manufacturer_id=%'");
        if (version_compare(VERSION, '4', '<')) {
          $this->db->query("UPDATE `" . DB_PREFIX . "url_alias` SET query = CONCAT('route=', query) WHERE auto_gen = 'STAN_urls'");
        }
        
      // iSense BackPack
      } else if ($this->request->post['module'] == 'backpack') {
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_manufacturer_description'")->row) {
          $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_manufacturer_description` RENAME TO " . DB_PREFIX . "seo_manufacturer_description_isense");
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_product_description'")->row) {
          $this->db->query("ALTER TABLE `" . DB_PREFIX . "seo_product_description` RENAME TO " . DB_PREFIX . "seo_product_description_isense");
          
          $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . "seo_product_description_isense` u SET d.seo_h1 = u.h1, d.seo_h2 = u.h2 WHERE d.product_id = u.product_id AND d.language_id = u.language_id");
        }
        
        if (version_compare(VERSION, '2.2', '>=')) {
          $this->load->model("setting/event");
          $this->model_setting_event->deleteEventByCode('isenselabs_seo');
        }
        
        if ($this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "seo_url_alias'")->row) {
          $this->db->query("TRUNCATE `" . DB_PREFIX . $this->url_alias . "`");
          $this->db->query("INSERT INTO `" . DB_PREFIX . $this->url_alias . "` (query, keyword, language_id) SELECT query, keyword, language_id FROM `" . DB_PREFIX . "seo_url_alias`");
        }

      // Mega Kit Plus
      } else if ($this->request->post['module'] == 'mega_kit') {
       if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'smp_language_id'")->row) {
         $this->db->query("UPDATE `" . DB_PREFIX . $this->url_alias . "` SET language_id = smp_language_id");
         
         if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'smp_language_id'")->row) {
           $this->db->query("ALTER TABLE `" . DB_PREFIX . $this->url_alias . "` DROP `smp_language_id`");
         }
        }
        
        $store_seo = $this->config->get('smp_meta_stores');
        
        $settings = $this->model_setting_setting->getSetting('mlseo');
        
        foreach ((array) $store_seo as $store) {
          foreach ($store['title'] as $language => $value) {
            $settings['mlseo_store'][$store.$language]['seo_title'] = $value;
          }
          foreach ($store['description'] as $language => $value) {
            $settings['mlseo_store'][$store.$language]['description'] = $value;
          }
          foreach ($store['keywords'] as $language => $value) {
            $settings['mlseo_store'][$store.$language]['keywords'] = $value;
          }
        }
		
        $this->model_setting_setting->editSetting('mlseo', $settings);
        
        $data['info'][] = 'Store SEO correctly transferred';
        
        $this->db->query("INSERT INTO `" . DB_PREFIX . "url_redirect` (query, redirect) SELECT broken_link, new_link FROM `" . DB_PREFIX . "redirects_smp`");
        
        $data['info'][] = 'Redirections correctly transferred';
      
      // Webkul Advanced SEO
      } else if ($this->request->post['module'] == 'webkul_advanced_seo') {
        $this->db->query("INSERT INTO `" . DB_PREFIX . $this->url_alias . "` (query, keyword, language_id) SELECT CONCAT('route=', route), keyword, language_id FROM `" . DB_PREFIX . "wkseo_sef`");
        
      }
      
      // Copy seo manufacturer data from other table
      // INSERT INTO `oc_seo_manufacturer_description` (`manufacturer_id`, `language_id`, `description`, `meta_title`, `seo_h1`, `meta_description`, `meta_keyword`) SELECT manufacturer_id, language_id, description, meta_title, meta_h1, meta_description, meta_keyword FROM `oc_manufacturer_description`
      
      // Copy keyword values to item tables - Common to all modules - copy first without language id to be sure to have it in case of not defined
      /* no more useful, we don't use anymore seo_keyword in desc
      $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '')");
      $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '')");
      $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '')");
      
      if ($this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . $this->url_alias . "` LIKE 'language_id'")->row) {
        $this->db->query("UPDATE `" . DB_PREFIX . "product_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id");
        $this->db->query("UPDATE `" . DB_PREFIX . "category_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id");
        $this->db->query("UPDATE `" . DB_PREFIX . "information_description` d, `" . DB_PREFIX . $this->url_alias . "` u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id");
      }
      */
      /* SQL query for manual input
      UPDATE oc_product_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '');
      UPDATE oc_product_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'product_id=%' AND d.product_id = REPLACE(u.query, 'product_id=', '') AND d.language_id = u.language_id;
      UPDATE oc_category_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '');
      UPDATE oc_category_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'category_id=%' AND d.category_id = REPLACE(u.query, 'category_id=', '') AND d.language_id = u.language_id;
      UPDATE oc_information_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '');
      UPDATE oc_information_description d, oc_url_alias u SET d.seo_keyword = u.keyword WHERE u.query LIKE 'information_id=%' AND d.information_id = REPLACE(u.query, 'information_id=', '') AND d.language_id = u.language_id;
      */
      /* now handled by previous requests in pure sql
      $rows = $this->db->query("SELECT * FROM " . DB_PREFIX . $this->url_alias . " WHERE query LIKE 'information_id=%' OR query LIKE 'product_id=%' OR query LIKE 'category_id=%'")->rows;
      
      foreach($rows as $row) {
        list($field, $id) = explode('=', $row['query']);
        
        $table = str_replace('_id', '', $field);
        
        $this->db->query("UPDATE " . DB_PREFIX . $table . "_description SET seo_keyword = '" . $this->db->escape($row['keyword']) . "' WHERE " .$field ." = '".$id."'");
        //echo "UPDATE " . DB_PREFIX . $table . "_description SET seo_keyword = '" . $this->db->escape($row['keyword']) . "' WHERE " .$field ." = '".$id."'". "<br/>";
      }
      */
      end:
      $data['upgrade_complete'] = true;
    }
    
    $this->document->setTitle('SEO Package Upgrade Tool');
    
    $data['upgrade'] = true;
    
    $data['action'] = $this->url->link(self::$LINK_SEP.'upgrade', $this->token, 'SSL');
    $data['cancel'] = $this->url->link(self::$LINK, $this->token, 'SSL');
    
    if (version_compare(VERSION, '2', '>=')) {
      $data['header'] = $this->load->controller('common/header');
      $data['column_left'] = $this->load->controller('common/column_left');
      $data['footer'] = $this->load->controller('common/footer');
      
      if (version_compare(VERSION, '3', '>=')) {
        $this->config->set('template_engine', 'template');
        $this->response->setOutput($this->load->view('module/complete_seo', $data));
      } else {
        $this->response->setOutput($this->load->view('module/complete_seo.tpl', $data));
      }
    } else {
      $data['column_left'] = '';
      $this->data = &$data;
      $this->template = 'module/complete_seo.tpl';
      $this->children = array(
        'common/header',
        'common/footer'
      );

      // fix OC 1.5
      $this->response->setOutput(str_replace(array('view/javascript/jquery/jquery-1.6.1.min.js', 'view/javascript/jquery/jquery-1.7.1.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'), self::$ASSET_PATH . 'jquery.min.js', $this->render()));
    }
    
  }
  
  public function category_autocomplete() {
		$json = array();

		if (isset($this->request->get['filter_name'])) {
			$this->load->model('catalog/category');

			$filter_data = array(
				'filter_name' => $this->request->get['filter_name'],
				'sort'        => 'name',
				'order'       => 'ASC',
				'start'       => 0,
				'limit'       => 20
			);

			$results = $this->model_catalog_category->getCategories($filter_data);

			foreach ($results as $result) {
				$json[] = array(
					'category_id' => $result['category_id'],
					'name'        => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
				);
			}
		}

		$sort_order = array();

		foreach ($json as $key => $value) {
			$sort_order[$key] = $value['name'];
		}

		array_multisort($sort_order, SORT_ASC, $json);

		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	}
}
//disable admin_save_and_keep_editing.xml

Function Calls

None

Variables

None

Stats

MD5 cfe8b8b02d3613ce32ac078b3bb53bb1
Eval Count 0
Decode Time 277 ms