275 lines
13 KiB
PHP
275 lines
13 KiB
PHP
<?php
|
|
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
{
|
|
exit;
|
|
}
|
|
|
|
class boproductfinder extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->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 '
|
|
<div class="panel" id="fieldset_myprestaupdates" style="margin-top:20px;">
|
|
' . ($this->psversion() == 6 || $this->psversion() == 7 ? '<div class="panel-heading"><i class="icon-wrench"></i> ' . $this->l('MyPresta updates') . '</div>' : '') . '
|
|
<div class="form-wrapper" style="padding:0px!important;">
|
|
<div id="module_block_settings">
|
|
<fieldset id="fieldset_module_block_settings">
|
|
' . ($this->psversion() == 5 ? '<legend style="">' . $this->l('MyPresta updates') . '</legend>' : '') . '
|
|
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
|
|
<label>' . $this->l('Check updates') . '</label>
|
|
<div class="margin-form">' . (Tools::isSubmit('submit_settings_updates_now') ? ($this->inconsistency(0) ? '' : '') . $this->checkforupdates(1) : '') . '
|
|
<button style="margin: 0px; top: -3px; position: relative;" type="submit" name="submit_settings_updates_now" class="button btn btn-default" />
|
|
<i class="process-icon-update"></i>
|
|
' . $this->l('Check now') . '
|
|
</button>
|
|
</div>
|
|
<label>' . $this->l('Updates notifications') . '</label>
|
|
<div class="margin-form">
|
|
<select name="mypresta_updates">
|
|
<option value="-">' . $this->l('-- select --') . '</option>
|
|
<option value="1" ' . ((int)(Configuration::get('mypresta_updates') == 1) ? 'selected="selected"' : '') . '>' . $this->l('Enable') . '</option>
|
|
<option value="0" ' . ((int)(Configuration::get('mypresta_updates') == 0) ? 'selected="selected"' : '') . '>' . $this->l('Disable') . '</option>
|
|
</select>
|
|
<p class="clear">' . $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.') . '</p>
|
|
</div>
|
|
<label>' . $this->l('Module page') . '</label>
|
|
<div class="margin-form">
|
|
<a style="font-size:14px;" href="' . $this->mypresta_link . '" target="_blank">' . $this->displayName . '</a>
|
|
<p class="clear">' . $this->l('This is direct link to official addon page, where you can read about changes in the module (changelog)') . '</p>
|
|
</div>
|
|
<div class="panel-footer">
|
|
<button type="submit" name="submit_settings_updates"class="button btn btn-default pull-right" />
|
|
<i class="process-icon-save"></i>
|
|
' . $this->l('Save') . '
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</fieldset>
|
|
<style>
|
|
#fieldset_myprestaupdates {
|
|
display:block;clear:both;
|
|
float:inherit!important;
|
|
}
|
|
</style>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
} 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[] = '<strong>'. $this->displayName . '</strong>: ' .$this->l('New version available, check http://MyPresta.eu for more informations'). ' <a href="'.$this->mypresta_link.'">'.$this->l('More details in changelog').'</a>';
|
|
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 "<span style='color:red; font-weight:bold; font-size:16px; margin-right:10px;'>" . $this->l('New version available!') . "</span>";
|
|
} else {
|
|
return "<span style='color:green; font-weight:bold; font-size:16px; margin-right:10px;'>" . $this->l('Module is up to date!') . "</span>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 '<script>
|
|
var admin_module_edit_url = \''.$this->context->link->getAdminLink('AdminModules').'\';
|
|
</script>';
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|