name = 'boproductfinder'; $this->tab = 'administration'; $this->version = '1.2.1'; $this->author = 'MyPresta.eu'; $this->mypresta_link = 'https://mypresta.eu/modules/payment-process/bankwire-with-discount.html'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Back office ajax product filter'); $this->description = $this->l('Module allows to use quick filter tool to search products with AJAX method'); $this->checkforupdates(); } public function psversion() { $version = _PS_VERSION_; $exp = $explode = explode(".", $version); return $exp[1]; } public function checkforupdates($display_msg = 0, $form = 0) { // ---------- // // ---------- // // VERSION 14 // // ---------- // // ---------- // $this->mkey = "nlc"; if (@file_exists('../modules/' . $this->name . '/key.php')) { @require_once('../modules/' . $this->name . '/key.php'); } else { if (@file_exists(dirname(__FILE__) . $this->name . '/key.php')) { @require_once(dirname(__FILE__) . $this->name . '/key.php'); } else { if (@file_exists('modules/' . $this->name . '/key.php')) { @require_once('modules/' . $this->name . '/key.php'); } } } if (@file_exists('../modules/' . $this->name . '/key.php')) { @require_once('../modules/' . $this->name . '/key.php'); } else { if (@file_exists(dirname(__FILE__) . $this->name . '/key.php')) { @require_once(dirname(__FILE__) . $this->name . '/key.php'); } else { if (@file_exists('modules/' . $this->name . '/key.php')) { @require_once('modules/' . $this->name . '/key.php'); } } } if ($form == 1) { return '
' . ($this->psversion() == 6 || $this->psversion() == 7 ? '
' . $this->l('MyPresta updates') . '
' : '') . '
' . ($this->psversion() == 5 ? '' . $this->l('MyPresta updates') . '' : '') . '
' . (Tools::isSubmit('submit_settings_updates_now') ? ($this->inconsistency(0) ? '' : '') . $this->checkforupdates(1) : '') . '

' . $this->l('Turn this option on if you want to check MyPresta.eu for module updates automatically. This option will display notification about new versions of this addon.') . '

' . $this->displayName . '

' . $this->l('This is direct link to official addon page, where you can read about changes in the module (changelog)') . '

'; } else { if (defined('_PS_ADMIN_DIR_')) { if (Tools::isSubmit('submit_settings_updates')) { Configuration::updateValue('mypresta_updates', Tools::getValue('mypresta_updates')); } if (Configuration::get('mypresta_updates') != 0 || (bool)Configuration::get('mypresta_updates') == false) { if (Configuration::get('update_' . $this->name) < (date("U") - 259200)) { $actual_version = boproductfinderUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version); } if (boproductfinderUpdate::version($this->version) < boproductfinderUpdate::version(Configuration::get('updatev_' . $this->name))) { $this->context->controller->warnings[] = ''. $this->displayName . ': ' .$this->l('New version available, check http://MyPresta.eu for more informations'). ' '.$this->l('More details in changelog').''; if (isset($this->context->controller->warnings[0])) { $this->warning = $this->context->controller->warnings[0]; } } } if ($display_msg == 1) { if (boproductfinderUpdate::version($this->version) < boproductfinderUpdate::version(boproductfinderUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version))) { return "" . $this->l('New version available!') . ""; } else { return "" . $this->l('Module is up to date!') . ""; } } } } } public function inconsistency($ret) { return; } public function install() { if (!parent::install() || !$this->registerHook('actionAdminControllerSetMedia') || !$this->registerHook('displayBackOfficeHeader')) { return false; } return true; } public function getContent() { if (Tools::getValue('ajax', 'false') != 'false') { $query = Tools::getValue('q', false); if ( ! $query or $query == '' or strlen($query) < 1) { die(); } if ($pos = strpos($query, ' (ref:')) { $query = substr($query, 0, $pos); } $excludeIds = Tools::getValue('excludeIds', false); if ($excludeIds && $excludeIds != 'NaN') { $excludeIds = implode(',', array_map('intval', explode(',', $excludeIds))); } else { $excludeIds = ''; $excludePackItself = Tools::getValue('packItself', false); } $excludeVirtuals = (bool)Tools::getValue('excludeVirtuals', true); $exclude_packs = (bool)Tools::getValue('exclude_packs', true); $context = Context::getContext(); $sql = 'SELECT p.`id_product`, pl.`link_rewrite`, p.`reference`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, p.`cache_default_attribute` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.id_product = p.id_product AND pl.id_lang = ' . (int)$context->language->id . Shop::addSqlRestrictionOnLang('pl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int)$context->shop->id . ') LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int)$context->language->id . ') WHERE (pl.name LIKE \'%' . pSQL($query) . '%\' OR p.reference LIKE \'%' . pSQL($query) . '%\')' . (! empty($excludeIds) ? ' AND p.id_product NOT IN (' . $excludeIds . ') ' : ' ') . (! empty($excludePackItself) ? ' AND p.id_product <> ' . $excludePackItself . ' ' : ' ') . ($excludeVirtuals ? 'AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'product_download` pd WHERE (pd.id_product = p.id_product))' : '') . ($exclude_packs ? 'AND (p.cache_is_pack IS NULL OR p.cache_is_pack = 0)' : '') . ' GROUP BY p.id_product'; $items = Db::getInstance()->executeS($sql); if ($items && ($excludeIds)) { foreach ($items as $item) { $item['name'] = str_replace('|', '|', $item['name']); $item['url'] = Context::getContext()->link->getAdminLink('AdminProducts', true, array('id_product' => $item['id_product']), array('id_product' => $item['id_product'])); echo trim($item['name']) . (! empty($item['reference']) ? ' (ref: ' . $item['reference'] . ')' : '') . '|' . (int)($item['id_product']) . '|' . self::getImagesByID($item['link_rewrite'], (int)($item['id_product']))."|".$item['url']."\n"; } } die(); } else { return $this->checkforupdates(0,1); } } public static function getImagesByID($link_rewrite, $id_product) { $limit = 1; $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE cover=1 AND `id_product` = ' . (int)$id_product . ' ORDER BY position ASC LIMIT 0, ' . (int)$limit); $toReturn = array(); if (!$id_image) { return; } else { foreach ($id_image as $image) { $toReturn = Context::getContext()->link->getImageLink($link_rewrite, $id_product . '-' . $image['id_image'], 'small_default'); } } return $toReturn; } public function hookDisplayBackOfficeHeader() { return ''; } public function hookactionAdminControllerSetMedia() { $this->context->controller->addJs($this->_path . 'views/boproductfinder.js'); $this->context->controller->addJs($this->_path . 'views/autocomplete.js'); $this->context->controller->addCss($this->_path . 'views/autocomplete.css'); } } class boproductfinderUpdate extends boproductfinder { public static function version($version) { $version = (int)str_replace(".", "", $version); if (strlen($version) == 4) { $version = (int)$version . "0"; } if (strlen($version) == 3) { $version = (int)$version . "00"; } if (strlen($version) == 2) { $version = (int)$version . "000"; } if (strlen($version) == 1) { $version = (int)$version . "0000"; } if (strlen($version) == 0) { $version = (int)$version . "00000"; } return (int)$version; } public static function encrypt($string) { return base64_encode($string); } public static function verify($module, $key, $version) { if (ini_get("allow_url_fopen")) { if (function_exists("file_get_contents")) { $actual_version = @file_get_contents('http://dev.mypresta.eu/update/get.php?module=' . $module . "&version=" . self::encrypt($version) . "&lic=$key&u=" . self::encrypt(_PS_BASE_URL_ . __PS_BASE_URI__)); } } Configuration::updateValue("update_" . $module, date("U")); Configuration::updateValue("updatev_" . $module, $actual_version); return $actual_version; } }