first commit

This commit is contained in:
2024-10-25 14:16:28 +02:00
commit 925276dbb2
33795 changed files with 4780077 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowAdminController extends ModuleAdminController
{
public $bootstrap = true;
public $alerts = array();
public $filepath = null;
public $template_isset = false;
public $newSystemLoc = "";
/**
* Tips
*
* @var array
*/
public $tips = array();
/**
*
* @param warning|success|info|danger $type
* @param string $id Uniq id
* @param string $message
*/
public function addTip($type, $id, $message)
{
$this->tips[] = array(
'type' => $type,
'id' => $id,
'message' => $message
);
}
public function __construct()
{
@ini_set('display_errors', 'on');
@error_reporting(E_ERROR | E_PARSE | E_STRICT);
if (version_compare(_PS_VERSION_, '1.7.0') >= 0) {
$this->translator = Context::getContext()->getTranslator();
}
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
if (is_dir(PShowUpdate::getInstance($this->filepath)->getModulePath() . "vendor/system")) {
$this->newSystemLoc = "vendor/";
}
$this->addTip(
'info', 'tips_information', $this->l('The module provides instructions on how to use the module.'
. 'You can close each tip. At any time you can restore all the '
. 'instructions by going to the module settings and activating '
. 'the `Show hints` option.')
);
// create required directories
$modulePath = getModulePath(__FILE__);
$req = array(
$modulePath . 'update',
$modulePath . 'update/backups',
$modulePath . 'update/tmp',
);
foreach ($req as $path) {
if (!is_dir($path)) {
mkdir($path);
chmod($path, 0777);
}
}
parent::__construct();
if (Tools::getValue('controller') != 'PShowImporterImport') {
PShowUpdate::getInstance($this->filepath)->getNewestVersionNumber();
}
$this->modulepath = PShowUpdate::getInstance($this->filepath)->getModulePath();
$this->modulename = PShowUpdate::getInstance($this->filepath)->getModuleName();
$this->module = new $this->modulename();
$this->context->smarty->assign(
'prestashow_logo_url', Tools::getShopDomain() . __PS_BASE_URI__ . 'modules/' . $this->modulename . '/' . $this->newSystemLoc . 'system/view/img/prestashow-logo.jpg'
);
$displayModuleVersion = (Tools::getValue('controller') == 'PShowImporterImport') ? 'ajax' :
PShowUpdate::getInstance($this->filepath)->formatVersionToDisplay(
PShowUpdate::getInstance($this->filepath)->getModuleVersionNumber()
);
$this->context->smarty->assign('moduleVersion', $displayModuleVersion);
$this->context->smarty->assign('module', $this->module);
$isUpdateAvailable = (Tools::getValue('controller') == 'PShowImporterImport') ? false :
(!PShowUpdate::getInstance($this->filepath)->compareModuleAndNewestVersion());
$this->context->smarty->assign('isUpdateAvailable', $isUpdateAvailable);
$settings = PShow_Settings::getInstance(__FILE__)->getAll();
$this->mod_settings = array();
foreach ($settings as $s) {
$this->mod_settings[$s['name']] = PShow_Settings::getInstance(__FILE__)->get($s['name']);
}
$this->context->smarty->assign('mod_settings', $this->mod_settings);
}
public function createTemplate($tpl_name)
{
if (file_exists($this->getTemplatePath() . $tpl_name) && $this->viewAccess()) {
return $this->context->smarty->createTemplate($this->getTemplatePath() . $tpl_name, $this->context->smarty);
}
return parent::createTemplate($tpl_name);
}
public function getTemplatePath()
{
return PShowUpdate::getInstance($this->filepath)->getModulePath() . 'views/templates/admin/';
}
public function initContent()
{
parent::initContent();
if (!$this->display) {
$this->display = $this->default_action;
}
// Temporary bypass to helpers
if (method_exists($this, $this->display . 'HelperAction') === false) {
$this->action = Tools::getValue('page');
if (!$this->action || !method_exists($this, $this->action . 'Action')) {
$this->action = $this->default_action;
}
$this->{$this->action . 'Action'}();
}
if (!$this->template_isset) {
$this->setTemplate(str_repeat('../', 4) . 'modules/' . $this->modulename . '/' . $this->newSystemLoc . "system/view/admin_controller.tpl");
}
if (version_compare(_PS_VERSION_, '1.6', '<')) {
// PS 1.5 is not compatibile with bootstrap
$this->context->controller->addCSS(__PS_BASE_URI__ . 'modules/' . $this->modulename . '/' . $this->newSystemLoc . 'system/view/css/backward-compatibility.css');
}
$this->context->controller->addJS(__PS_BASE_URI__ . 'modules/' . $this->modulename . '/' . $this->newSystemLoc . 'system/view/js/select_tab.js');
$this->context->controller->addJS(__PS_BASE_URI__ . 'modules/' . $this->modulename . '/' . $this->newSystemLoc . 'system/view/js/tips.js');
$this->context->smarty->assign('moduleurl', __PS_BASE_URI__ . 'modules/' . $this->modulename . '/');
$this->context->smarty->assign('TOKEN', Tools::getValue('token'));
$mainClassContent = Tools::file_get_contents($this->modulepath . $this->modulename . '.php');
preg_match_all('~class ([a-zA-Z]+) ~', $mainClassContent, $matches);
$arrayWithClass = end($matches);
$classname = end($arrayWithClass);
$this->context->smarty->assign('PSHOW_MODULE_CLASS_NAME_', $classname);
$recommended = PShowUpdate::getInstance($this->filepath)->getRecommendedProduct();
$this->context->smarty->assign('recommended', $recommended);
$this->context->smarty->assign('action', $this->action);
$this->context->smarty->assign('alerts', $this->alerts);
$this->context->smarty->assign('tips', $this->tips);
$this->context->smarty->assign('action_displayName', $this->action_displayName);
$this->context->smarty->assign('controller_displayName', $this->controller_displayName);
$this->context->smarty->assign('__FILE__', __FILE__);
$this->context->smarty->assign('select_menu_tab', $this->select_menu_tab);
$modulename_low = Tools::strtolower($this->modulename);
$classname_low = Tools::strtolower(get_class($this));
$controllername = str_replace(array("controller", $modulename_low), "", $classname_low);
$this->context->smarty->assign('controllername', $controllername);
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowBackupController extends PShowAdminController
{
public $default_action = 'index';
public $filepath = null;
public function __construct()
{
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
require_once dirname($this->filepath) . "/../../config.php";
parent::__construct();
$this->controller_displayName = $this->l('Backup');
}
public function human_filesize($bytes, $dec = 2)
{
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$dec}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
public function indexAction()
{
$this->action_displayName = $this->l('List');
$backups = array();
$glob = glob(getModulePath($this->filepath) . "update/backups/*.zip");
foreach ($glob as $f) {
$filename = pathinfo($f, PATHINFO_FILENAME);
$data = explode("_", $filename);
$backups[$f] = array(
'filename' => $filename,
'modulename' => $data[0],
'version' => $data[1],
'time' => $data[2],
'size' => $this->human_filesize(filesize($f)),
'date' => $data[3]
);
}
usort($backups, function($a, $b) {
return ($a['date'] > $b['date']) ? 1 : -1;
});
$this->context->smarty->assign('backups', $backups);
}
public function removeAction()
{
if (($filename = Tools::getValue('filename')) && file_exists(getModulePath($this->filepath) . "update/backups/" . $filename . ".zip")) {
$unlink = @unlink(getModulePath($this->filepath) . "update/backups/" . $filename . ".zip");
if ($unlink)
$this->alerts[] = array('success', $this->l('Removed module backup: ' . $filename));
else
$this->alerts[] = array('warning',
$this->l('I don\'t have permissions to delete file: ' . $filename));
}
$this->action = 'index';
$this->indexAction();
}
public function backupAction()
{
if (PShowUpdate::getInstance($this->filepath)->makeModuleBackup())
$this->alerts[] = array('success', $this->l('Maked module backup'));
else
$this->alerts[] = array('warning', $this->l('Module backup create error'));
$this->action = 'index';
$this->indexAction();
}
public function updateChmod($path = null)
{
if ($path === null)
$path = getModulePath($this->filepath);
$files = glob($path);
foreach ($files as $file) {
if (is_dir($file))
$this->updateChmod($file . "/*");
@chmod($file, 0777);
}
}
public function restorebackupAction()
{
$this->action = 'index';
$this->indexAction();
if (!Tools::getValue('filename'))
return false;
$this->updateChmod();
PShowUpdate::getInstance($this->filepath)->clearTmpDir();
PShowUpdate::getInstance($this->filepath)->makeModuleBackup();
PShowUpdate::getInstance($this->filepath)->moveBackupToTmp(Tools::getValue('filename'));
if (!PShowUpdate::getInstance($this->filepath)->extractBackup(Tools::getValue('filename'))) {
$this->alerts[] = array('warning', 'Backup package extract error');
return false;
} else {
$this->alerts[] = array('success', 'Backup package extracted');
}
if (!PShowUpdate::getInstance($this->filepath)->moveBackupToModule(Tools::getValue('filename'))) {
$this->alerts[] = array('warning', 'Module backup restore error');
return false;
} else {
$this->alerts[] = array('success', 'Module backup restored');
}
PShowUpdate::getInstance($this->filepath)->clearTmpDir();
$this->alerts[] = array('success', 'Cleaned after backup restoring');
}
}

View File

@@ -0,0 +1,205 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowHook extends ObjectModel
{
public $id;
/** @var int Hook */
public $id_hook;
/** @var string Name */
public $hook_name;
/** @var int */
public $presta_id_hook;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => null,
'primary' => 'id_hook',
'multilang' => false,
'multilang_shop' => false,
'fields' => array(
'hook_name' => array('type' => self::TYPE_STRING, 'required' => true),
'presta_id_hook' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt',
'required' => true),
),
);
public function __construct($id_hook = null, $id_lang = null, $id_shop = null)
{
self::initDefinition();
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
parent::__construct($id_hook, $id_lang, $id_shop);
}
public static function getReflection()
{
return new ReflectionClass(get_called_class());
}
public static function initDefinition()
{
self::$definition['table'] = 'pshow_' . getModuleName(self::getReflection()->getFileName()) . '_hook';
}
public static function getHooks()
{
self::initDefinition();
$q = "SELECT * FROM `" . _DB_PREFIX_ . self::$definition['table'] . "` h";
return Db::getInstance()->executeS($q);
}
public static function getHookIdByPrestaHookId($presta_id_hook)
{
self::initDefinition();
$q = "SELECT h.`id_hook` FROM `" . _DB_PREFIX_ . self::$definition['table'] . "` h
WHERE h.`presta_id_hook` = " . (int) $presta_id_hook;
return Db::getInstance()->getValue($q);
}
public static function getHookIdByPrestaHookName($presta_hook_name)
{
$hook_id = Hook::getIdByName($presta_hook_name);
return self::getHookIdByPrestaHookId($hook_id);
}
public static function countHooks()
{
self::initDefinition();
$q = "SELECT COUNT(*) FROM `" . _DB_PREFIX_ . self::$definition['table'] . "` h";
$query = Db::getInstance()->getValue($q);
if ($query === false)
return false;
return $query;
}
public function add($autodate = true, $null_values = false)
{
return parent::add($autodate, $null_values);
}
public function update($null_values = false)
{
return parent::update($null_values);
}
public static function getAvailableHooks($module_name, $shop_id, $except_hook_name = false)
{
if ($except_hook_name)
$hook_id = Hook::getIdByName($hook_name);
$hooks = Hook::getHooks();
foreach ($hooks as $key => $hook) {
$hook_name = Hook::getNameById($hook['id_hook']);
if ($except_hook_name && $hook_id == $hook['id_hook'])
continue;
if (!self::isHookRegistered($module_name, $hook_name, $shop_id))
continue;
unset($hooks[$key]);
}
return $hooks;
}
public static function isHookRegistered($module_name, $hook_name, $shop_id)
{
$id_module = Module::getModuleIdByName($module_name);
$hook_id = Hook::getIdByName($hook_name);
$sql = 'SELECT `id_hook`
FROM `' . _DB_PREFIX_ . 'hook_module` WHERE
`id_module` = ' . (int) $id_module . ' AND
`id_hook` = ' . (int) $hook_id . ' AND
`id_shop` = ' . (int) $shop_id;
return Db::getInstance()->getRow($sql);
}
public static function unregisterHook($module_name, $hook_name, $shop_id)
{
$id_module = Module::getModuleIdByName($module_name);
$hook_id = Hook::getIdByName($hook_name);
// Unregister module on hook by id
$sql = 'DELETE FROM `' . _DB_PREFIX_ . 'hook_module` WHERE
`id_module` = ' . (int) $id_module . ' AND
`id_hook` = ' . (int) $hook_id . ' AND
`id_shop` = ' . (int) $shop_id;
$result = Db::getInstance()->execute($sql);
return $result;
}
public static function registerHook($module_name, $hook_name, $shop_id)
{
$id_hook = Hook::getIdByName($hook_name);
if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {
$live_edit = false;
} else {
$live_edit = Hook::getLiveEditById((int) $id_hook);
}
if (!$id_hook) {
$new_hook = new Hook();
$new_hook->name = pSQL($hook_name);
$new_hook->title = pSQL($hook_name);
$new_hook->live_edit = false;
$new_hook->position = (bool) $new_hook->live_edit;
$new_hook->add();
$id_hook = $new_hook->id;
}
if (!$id_hook)
throw new PrestaShopException('Hook add error');
// Get module position in hook
$sql = 'SELECT MAX(`position`) AS position
FROM `' . _DB_PREFIX_ . 'hook_module`
WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id;
if (!$position = Db::getInstance()->getValue($sql))
$position = 0;
$id_module = Module::getModuleIdByName($module_name);
$q = Db::getInstance()->insert('hook_module', array(
'id_module' => (int) $id_module,
'id_hook' => (int) $id_hook,
'id_shop' => (int) $shop_id,
'position' => (int) ($position + 1),
));
if (!$q)
throw new PrestaShopException('Hook add error');
return $id_hook;
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowHookController extends PShowAdminController
{
public $default_action = 'index';
public $filepath = null;
public function __construct()
{
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
require_once dirname($this->filepath) . "/../../config.php";
parent::__construct();
$this->id_shop = (int) $this->context->shop->id;
$this->id_lang = (int) $this->context->cookie->id_lang;
$this->controller_displayName = $this->l('Hooks');
}
public function indexAction()
{
$this->action_displayName = $this->l('List');
$hooks = PShowHook::getHooks();
$hooksCount = PShowHook::countHooks();
$this->context->smarty->assign('hooks', $hooks);
$this->context->smarty->assign('hooksCount', $hooksCount);
}
public function removeAction()
{
$this->action_displayName = $this->l('List');
$id_hook = Tools::getValue('id_hook');
if (!$id_hook) {
$this->action = 'index';
$this->indexAction();
return;
}
$hook = new PShowHook($id_hook);
if (!is_object($hook)) {
$this->action = 'index';
$this->indexAction();
return;
}
PShowHook::unregisterHook('skeleton', $hook->hook_name, $this->id_shop);
$hook->delete();
$this->alerts[] = array('success', $this->l('Hook removed'));
$this->action = 'index';
$this->indexAction();
return;
}
public function editAction()
{
$this->action_displayName = $this->l('Edit hook');
$id_hook = Tools::getValue('id_hook');
if (!$id_hook) {
$this->action = 'index';
$this->indexAction();
return;
}
$h = new PShowHook($id_hook);
if (!is_object($h)) {
$this->action = 'index';
$this->indexAction();
return;
}
if (Tools::isSubmit('submit')) {
$hook_name = pSQL(Tools::getValue('hook_name'));
if (!empty($hook_name)) {
try {
PShowHook::unregisterHook('skeleton', $h->hook_name, $this->id_shop);
$presta_id_hook = PShowHook::registerHook('skeleton', $hook_name, $this->id_shop);
$h->hook_name = $hook_name;
$h->presta_id_hook = $presta_id_hook;
$h->update();
$this->alerts[] = array('success', $this->l('Hook updated'));
$this->action = 'index';
$this->indexAction();
return;
} catch (PrestaShopException $e) {
$this->alerts[] = array('warning', $this->l('Hook update error, try again'));
}
} else {
$this->alerts[] = array('warning', $this->l('Hook update error, try again'));
}
}
$hooks = Hook::getHooks();
$this->context->smarty->assign('h', $h);
$this->context->smarty->assign('hooks', $hooks);
}
public function addAction()
{
$this->action_displayName = $this->l('Add hook');
$hooks = PShowHook::getAvailableHooks('skeleton', $this->id_shop, false);
if (Tools::isSubmit('submit')) {
$hook_name = pSQL(Tools::getValue('hook_name'));
if (!empty($hook_name)) {
$hook = new PShowHook();
$hook->hook_name = $hook_name;
try {
$presta_id_hook = PShowHook::registerHook('skeleton', $hook_name, $this->id_shop);
$hook->presta_id_hook = (int) $presta_id_hook;
$hook->add();
$this->alerts[] = array('success', $this->l('Hook added'));
$this->action = 'index';
$this->indexAction();
return;
} catch (PrestaShopException $e) {
$this->alerts[] = array('warning', $this->l('Hook add error, try again'));
}
} else {
$this->alerts[] = array('warning', $this->l('Hook add error, try again'));
}
}
$this->context->smarty->assign('hooks', $hooks);
}
}

View File

@@ -0,0 +1,438 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowModule extends Module
{
/**
* Add hooks here to register during installation
*/
public $hooks = array();
/**
* Module controller with tab in admin menu
*/
public $admin_menu_tab;
/**
* Module controllers without tab in admin menu
*/
public $controllers = array();
/**
* Append here all new versions which has got update functions
*
* example:
* $moduleVersionPath = array('1.0.0', '1.1.0', '1.2.0')
* during update from 1.0.0 to 1.2.0 functions with be called(if exists):
* update_from_1_1()
* update_from_1_2()
*/
public $moduleVersionPath = array();
/**
* Primary configuration
*/
public $version = '1.0.0';
public $author = 'PrestaShow.pl';
public $need_instance = 0;
public $bootstrap = true;
public $filepath = null;
public function __construct()
{
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
parent::__construct();
if (version_compare(_PS_VERSION_, '1.5.6.1', '<')) {
$this->ps_versions_compliancy['max'] = '1.6';
}
$this->controllers[] = $reflection->getShortName() . 'Settings';
if (Module::isInstalled($this->name)) {
// reinstall hooks after upgrade
Configuration::loadConfiguration();
$key = (version_compare(_PS_VERSION_, '1.6') >= 0) ? $reflection->getShortName() . '_hooks' : substr($reflection->getShortName() . '_hooks', 0, 31);
$hooks_install_version = Configuration::get($key);
if (!$hooks_install_version || version_compare($hooks_install_version, $this->version) < 0) {
foreach ($this->hooks as $hook_name) {
if (!$this->getPosition(Hook::getIdByName($hook_name))) {
$this->registerHook($hook_name);
}
}
Configuration::updateValue($key, $this->version);
$this->adminDisplayInformation($this->l('Hooks updated for this module :)'));
}
}
}
public function install()
{
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
return die('Module require PHP version >= 5.3.0');
}
$reflection = new ReflectionClass($this);
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!parent::install()) {
return false;
}
foreach ($this->hooks as $hook_name) {
$this->registerHook($hook_name);
}
$key = (version_compare(_PS_VERSION_, '1.6') >= 0) ? $reflection->getShortName() . '_hooks' : substr($reflection->getShortName() . '_hooks', 0, 31);
Configuration::updateValue($key, $this->version);
$this->createAdminTabs();
$q = "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . "pshow_" . $this->name . "_hook` (
`id_hook` INT NOT NULL AUTO_INCREMENT ,
`hook_name` text NOT NULL ,
`presta_id_hook` INT NOT NULL ,
PRIMARY KEY (`id_hook`)
) ENGINE = " . _MYSQL_ENGINE_ . "; ";
Db::getInstance()->query($q);
$this->registerHook('displayBackOfficeTop');
return true;
}
public function uninstallControllers()
{
$idTab = Tab::getIdFromClassName($this->admin_menu_tab);
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
}
foreach ($this->controllers as $ctrl_name) {
$idTab = Tab::getIdFromClassName($ctrl_name);
if ($idTab != 0) {
$tab = new Tab($idTab);
$tab->delete();
}
}
}
public function reinstallControllers()
{
$this->uninstallControllers();
$this->_installControllers();
}
public function _installControllers()
{
if (!Tab::getIdFromClassName($this->admin_menu_tab)) {
$tabsub = new Tab();
$tabsub->class_name = $this->admin_menu_tab;
$tabsub->module = $this->name;
foreach (Language::getLanguages() as $lang) {
$tabsub->name[$lang['id_lang']] = $this->displayName;
}
$tabsub->id_parent = Tab::getIdFromClassName('PrestashowModules');
$tabsub->save();
}
foreach ($this->controllers as $ctrl_name) {
if (!Tab::getIdFromClassName($ctrl_name)) {
try {
$tabsub = new Tab();
$tabsub->class_name = $ctrl_name;
$tabsub->module = $this->name;
foreach (Language::getLanguages() as $lang) {
$tabsub->name[$lang['id_lang']] = $ctrl_name;
}
$tabsub->id_parent = -1;
$tabsub->save();
} catch (Exception $e) {
}
}
}
}
public function createAdminTabs()
{
if (!Tab::getIdFromClassName('PrestashowModules')) {
try {
$tabsub = new Tab();
$tabsub->class_name = 'PrestashowModules';
$tabsub->module = $this->name;
foreach (Language::getLanguages() as $lang) {
$tabsub->name[$lang['id_lang']] = $this->l('PrestaShow Modules');
}
$tabsub->id_parent = 0;
$tabsub->save();
} catch (Exception $e) {
return false;
}
}
$this->_installControllers();
}
public function uninstall()
{
if (!parent::uninstall()) {
return false;
}
$this->uninstallControllers();
return true;
}
/**
* catch all hooks
*
* @param string $method
* @param array $args
* @return boolean
*/
public function __call($method, $args = array())
{
$hook_name = str_replace('hook', '', $method);
if (!Validate::isHookName($hook_name)) {
return false;
}
if (method_exists($this, $method)) {
return $this->{$method}();
}
return false;
}
/**
* Check for modules updates
*/
public function hookDisplayBackOfficeTop()
{
$controller = Tools::getValue('controller');
if ($controller && in_array($controller, array('AdminLogin'))) {
return;
}
$moduleName = PShowUpdate::getInstance($this->filepath)->getModuleDisplayName();
$moduleVersion = PShowUpdate::getInstance($this->filepath)->getModuleVersionNumber();
ob_start();
if (!function_exists('sanitize_output')) {
function sanitize_output($_buffer)
{
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $_buffer);
return $buffer;
}
?>
<style>
.icon-PrestashowModules {
font-size: 17px !important;
margin-top: 0!important;
}
.icon-PrestashowModules:before,
.icon-PrestashowModules.noalert:before {
content: '\f217';
}
</style>
<script>
/**
* version_compare()
*
* @param string a
* @param string b
* @returns 1 if a > b
* @returns -1 if a < b
* @returns 0 if a == b
*/
window.version_compare = function (a, b) {
if (a === b) {
return 0;
}
var a_components = a.split(".");
var b_components = b.split(".");
var len = Math.min(a_components.length, b_components.length);
for (var i = 0; i < len; i++) {
if (parseInt(a_components[i]) > parseInt(b_components[i])) {
return 1;
}
if (parseInt(a_components[i]) < parseInt(b_components[i])) {
return -1;
}
}
if (a_components.length > b_components.length) {
return 1;
}
if (a_components.length < b_components.length) {
return -1;
}
return 0;
}
</script>
<?php
}
?>
<script>
if (typeof $ !== 'undefined') {
$(function () {
$.ajax({
url: 'ajax-tab.php',
dataType: 'json',
method: 'POST',
data: 'token=<?php echo Tools::getAdminTokenLite($moduleName . 'Update') ?>&controller=<?php echo $moduleName ?>Update&getNewestVersion=1'
}).done(function (result) {
console.log("<?php echo $moduleName ?>");
console.log("<?php echo $moduleVersion ?>");
console.log(result);
var isVersion = /^([0-9]+)\.([0-9]+)\.([0-9]+)$/;
if (isVersion.test(result) && version_compare(result, "<?php echo $moduleVersion ?>") === 1) {
console.log("<?php echo $moduleName ?> - New version available! " + result);
$("head").append(' \
<style> \
body:not(.page-sidebar-closed) .icon-PrestashowModules { \
margin-top: 4px !important; \
} \
.icon-PrestashowModules:before, \
.icon-PrestashowModules<?php echo $moduleName ?>:before { \
content: "\\f06a" !important; \
color: #FF0000 !important; \
} \
</style> \
');
$('li').filter(function () {
return this.id.match(/subtab-<?php echo $moduleName ?>([a-zA-Z]+)/g);
}).find('a').eq(0).prepend('<i class=\'icon-PrestashowModules<?php echo $moduleName ?>\' title=\'New update is available\'></i>');
setInterval(function () {
$('.icon-PrestashowModules').addClass('noalert');
setTimeout(function () {
$('.icon-PrestashowModules').removeClass('noalert');
}, 1500);
}, 3000);
}
});
});
}
</script>
<?php
$html = sanitize_output(ob_get_contents());
ob_end_clean();
return $html;
}
/**
* Override default FrontController::canonicalRedirection for exclude more parameters used in our modules
*
* @param string $canonical_url
*/
public static function canonicalRedirection($canonical_url = '')
{
if (!$canonical_url || !Configuration::get('PS_CANONICAL_REDIRECT') || strtoupper($_SERVER['REQUEST_METHOD']) != 'GET' || Tools::getValue('live_edit')) {
return;
}
$match_url = rawurldecode(Tools::getCurrentUrlProtocolPrefix() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
if (!preg_match('/^' . Tools::pRegexp(rawurldecode($canonical_url), '/') . '([&?].*)?$/', $match_url)) {
$params = array();
$str_params = '';
$url_details = parse_url($canonical_url);
if (!empty($url_details['query'])) {
parse_str($url_details['query'], $query);
foreach ($query as $key => $value) {
$params[Tools::safeOutput($key)] = Tools::safeOutput($value);
}
}
$excluded_key = array('id', 'module', 'isolang', 'id_lang',
'controller', 'fc', 'id_product', 'id_category', 'id_manufacturer',
'id_supplier', 'id_cms');
foreach ($_GET as $key => $value) {
if (!in_array($key, $excluded_key) && Validate::isUrl($key) && Validate::isUrl($value)) {
$params[Tools::safeOutput($key)] = Tools::safeOutput($value);
}
}
$str_params = http_build_query($params, '', '&');
if (!empty($str_params)) {
$final_url = preg_replace('/^([^?]*)?.*$/', '$1', $canonical_url) . '?' . $str_params;
} else {
$final_url = preg_replace('/^([^?]*)?.*$/', '$1', $canonical_url);
}
// Don't send any cookie
Context::getContext()->cookie->disallowWriting();
if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ && $_SERVER['REQUEST_URI'] != __PS_BASE_URI__) {
die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $final_url . '">' . $final_url . '</a>');
}
$redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302';
header('HTTP/1.0 ' . $redirect_type . ' Moved');
header('Cache-Control: no-cache');
Tools::redirectLink($final_url);
}
}
}

View File

@@ -0,0 +1,177 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
abstract class PShowSettingsAbstract
{
/** @var array */
public static $global_settings = array(
array(
'type' => 'switch',
'name' => 'fold_menu_on_enter',
'label' => 'Fold menu after entering the module',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => 'Enabled'
),
array(
'id' => 'active_off',
'value' => 0,
'label' => 'Disabled'
)
)
),
array(
'type' => 'switch',
'name' => 'tips',
'label' => 'Show tips',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => 'Enabled'
),
array(
'id' => 'active_off',
'value' => 0,
'label' => 'Disabled'
)
),
'is_bool' => true
),
);
/** @var array of PShow_Settings */
protected static $instance = null;
/** @var string */
public static $filepath;
public function __construct()
{
}
/**
*
* @param string $filepath
* @return PShow_Settings
*/
public static function getInstance($filepath)
{
self::$filepath = getModulePath($filepath);
if (self::$instance === null) {
self::$instance = new PShow_Settings();
$x = &self::$instance;
if ($filepath !== null && file_exists(getModulePath($filepath) . 'settings.php')) {
$x::$settings = array_merge(self::$global_settings, include(getModulePath($filepath) . 'settings.php'));
}
self::modyfiFormPS15($x::$settings);
}
return self::$instance;
}
/**
* Change 'switch' elements to 'select' to support PS1.5
*
* @param PShow_Settings $instance
*/
public static function modyfiFormPS15(&$instance)
{
if (version_compare(_PS_VERSION_, '1.6.0', '>=')) {
return;
}
foreach ($instance as $key1 => $element) {
$toChange = false;
foreach ($element as $key2 => $item) {
if ($item == 'switch' && $key2 == 'type') {
$toChange = true;
$instance[$key1][$key2] = 'select';
}
if ($toChange) {
if ($key2 == 'is_bool') {
unset($instance[$key1][$key2]);
}
if ($key2 == 'values') {
unset($instance[$key1][$key2]);
$instance[$key1]['options'] = array(
'query' => array(
array(
'value' => 1,
'label' => 'Enabled'
),
array(
'value' => 0,
'label' => 'Disabled'
)
),
'id' => 'value',
'name' => 'label'
);
}
}
}
}
}
/**
*
* @return array
*/
public function getAll()
{
return static::$settings;
}
/**
* Get setting value
*
* @param string $name
* @return string|null
*/
public function get($name)
{
$confName = strtolower(getModuleName(self::$filepath)) . '_' . $name;
// support PS1.5 - max length of key is 33 chars
if (version_compare(_PS_VERSION_, '1.6.0', '<')) {
$confName = substr($confName, 0, 32);
}
return Configuration::get($confName);
}
/**
* Set setting value
*
* @param string $name
* @param string $value
* @return string|null
*/
public function set($name, $value)
{
$confName = strtolower(getModuleName(self::$filepath)) . '_' . $name;
// support PS1.5 - max length of key is 33 chars
if (version_compare(_PS_VERSION_, '1.6.0', '<')) {
$confName = substr($confName, 0, 32);
}
Configuration::updateValue($confName, $value);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowSettingsController extends PShowAdminController
{
public $default_action = 'index';
public $filepath = null;
public function __construct()
{
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
require_once dirname($this->filepath) . "/../../config.php";
parent::__construct();
$this->controller_displayName = $this->l('Module settings');
$this->action_displayName = $this->l('Module settings');
}
public function updateAction()
{
$key = pSQL(Tools::getValue('key'));
$value = pSQL(Tools::getValue('val'));
PShow_Settings::getInstance($this->filepath)->set($key, $value);
die('OK');
}
public function indexAction()
{
$mod_settings = PShow_Settings::getInstance($this->filepath)->getAll();
if (Tools::getValue('btnSubmit')) {
$settings = $_POST;
unset($settings['btnSubmit']);
foreach ($settings as $k => $v) {
PShow_Settings::getInstance($this->filepath)->set(pSQL($k), pSQL($v));
if ($k == 'tips' && $v) {
$q = "DELETE FROM `%s` WHERE `name` LIKE '%s'; ";
Db::getInstance()->execute(
sprintf($q, _DB_PREFIX_ . 'configuration', getModuleName($this->filepath) . '_tip_%')
);
}
}
}
$this->context->smarty->assign('mod_settings', $mod_settings);
$this->context->smarty->assign('form', $this->generateConfigForm($mod_settings));
}
public function getConfigFieldsValues()
{
$settings = PShow_Settings::getInstance($this->filepath)->getAll();
$res = array();
foreach ($settings as $s) {
$res[$s['name']] = PShow_Settings::getInstance($this->filepath)->get($s['name']);
}
return $res;
}
public function generateConfigForm($mod_settings)
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Module settings'),
'icon' => 'icon-cogs'
),
'input' => $mod_settings,
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right" '
. 'onclick="$(\'#configuration_form\').submit();"',
'name' => 'btnSubmit'
)
)
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$lang = new Language(
(int) Configuration::get('PS_LANG_DEFAULT')
);
$helper->default_form_language = $lang->id;
$this->fields_form = array();
$helper->submit_action = 'btnSubmit';
$helper->currentIndex = null;
$helper->token = Tools::getAdminTokenLite('AdminModules');
if (version_compare(_PS_VERSION_, '1.6.0', '<')) {
$helper->currentIndex = $this->context->link->getAdminLink('PShowImporterSettings', false);
$helper->token = Tools::getAdminTokenLite('PShowImporterSettings');
}
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
ini_set('default_socket_timeout', 3);
/**
* @deprecated since version 58
*/
class PShowUpdate
{
/**
* For backward compatibility !
* Get singleton instance
*
* @param string $filepath
* @return \PShowUpdateNew
*/
public static function getInstance($filepath)
{
return PShowUpdateNew::getInstance($filepath);
}
public static $modulename;
public static $customercode;
public static $prestaversion;
public static $tmppath;
public static $reportbugurl = 'http://modules.prestashow.pl/bug_report.php';
public static $updateurl = 'http://modules.prestashow.pl';
public static $modulepath = null;
public static function getBugReportUrl()
{
$context = Context::getContext();
$employee = new Employee($context->cookie->id_employee);
$url = self::$reportbugurl;
$url .= "?module=" . getModuleName(__FILE__);
$url .= "&email=" . $context->cookie->email;
$url .= "&moduleversion=" . self::getModuleVersionNumber();
$url .= "&prestaversion=" . self::$prestaversion;
$url .= "&customercode=" . self::$customercode;
$url .= "&shopname=" . Configuration::get('PS_SHOP_NAME');
$url .= "&adminname=" . $employee->firstname . " " . $employee->lastname;
$url .= "&domain=" . $context->shop->domain . $context->shop->physical_uri;
$url .= "&moduledisplayname=" . self::getModuleDisplayName();
return $url;
}
public static function getCustomerCode()
{
return self::getInstance(__FILE__)->getCustomerCode();
}
public static function getModuleDisplayName()
{
return self::getInstance(__FILE__)->getModuleDisplayName();
}
public static function setModuleName($name)
{
self::$modulename = $name;
}
public static function getModuleName()
{
return self::getInstance(__FILE__)->getModuleName();
}
public static function setModulePath($path)
{
self::$modulepath = $path;
self::$tmppath = self::$modulepath . '/update/tmp/';
}
public static function getModulePath()
{
return self::getInstance(__FILE__)->getModulePath();
}
public static function getModuleVersionNumber($version = false, $modulename = false, $modulepath = false)
{
return self::getInstance(__FILE__)->getModuleVersionNumber();
}
public static function getRecommendedProduct()
{
return self::getInstance(__FILE__)->getRecommendedProduct();
}
public static $newestVersionNumber = null;
public static $hostname = null;
public static function gethostname()
{
if (self::$hostname === null)
self::$hostname = gethostname();
return self::$hostname;
}
public static $urlHeaders = array();
public static function get_headers($url)
{
$urlmd5 = md5($url);
if (!array_key_exists($urlmd5, self::$urlHeaders))
self::$urlHeaders[$urlmd5] = @get_headers($url);
return self::$urlHeaders[$urlmd5];
}
public static function getNewestVersionNumber($modulename = false)
{
return self::getInstance(__FILE__)->getNewestVersionNumber();
}
public static function compareModuleAndNewestVersion($modulename = false, $modulepath = false)
{
return self::getInstance(__FILE__)->compareModuleAndNewestVersion();
}
public static function downloadUpdate()
{
return self::getInstance(__FILE__)->downloadUpdate();
}
public static function extractUpdate($version = false)
{
return self::getInstance(__FILE__)->extractUpdate();
}
public static function recurseCopy($src, $dst)
{
return self::getInstance(__FILE__)->recurseCopy($src, $dst);
}
public static function clearTmpDir()
{
return self::getInstance(__FILE__)->clearTmpDir();
}
public static function moveUpdateToModule()
{
return self::getInstance(__FILE__)->moveUpdateToModule();
}
public static function recurseRemoveDir($path, $removePath = false)
{
return self::getInstance(__FILE__)->recurseRemoveDir($path, $removePath);
}
public static function makeModuleBackup()
{
return self::getInstance(__FILE__)->makeModuleBackup();
}
public static function moveBackupToTmp($file)
{
return self::getInstance(__FILE__)->moveBackupToTmp($file);
}
public static function extractBackup($file)
{
return self::getInstance(__FILE__)->extractBackup($file);
}
public static function moveBackupToModule()
{
return self::getInstance(__FILE__)->moveBackupToModule();
}
public static function execUpdate($from_ver)
{
return self::getInstance(__FILE__)->execUpdate($from_ver);
}
public static function formatVersionToDisplay($version)
{
return self::getInstance(__FILE__)->formatVersionToDisplay($version);
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShowUpdateController extends PShowAdminController
{
public $default_action = 'index';
public $filepath = null;
public function ajaxProcess()
{
if (!defined('PS_ADMIN_DIR')) {
define('PS_ADMIN_DIR', true);
}
if (Tools::isSubmit('getNewestVersion')) {
die(Tools::jsonEncode(PShowUpdate::getInstance($this->filepath)->getNewestVersionNumber()));
}
}
public function __construct()
{
$reflection = new ReflectionClass($this);
$this->filepath = $reflection->getFileName();
require_once dirname($this->filepath) . "/../../config.php";
parent::__construct();
$this->controller_displayName = $this->l('Module update');
$this->action_displayName = $this->l('Update informations');
$smarty = Context::getContext()->smarty;
$displayModuleVersion = PShowUpdate::getInstance($this->filepath)->formatVersionToDisplay(
PShowUpdate::getInstance($this->filepath)->getModuleVersionNumber()
);
$displayNewestVersion = PShowUpdate::getInstance($this->filepath)->formatVersionToDisplay(
PShowUpdate::getInstance($this->filepath)->getNewestVersionNumber()
);
$changelog_url = 'http://git.layersshow.com/Prestashow/changelog/raw/master/' . PShowUpdate::getInstance($this->filepath)->getModuleName() . '.md';
$changelog = Tools::file_get_contents($changelog_url);
$changelog_path = PShowUpdate::getInstance($this->filepath)->getModulePath() . 'changelog.md';
if (!$changelog) {
if (file_exists($changelog_path)) {
$changelog = Tools::file_get_contents($changelog_path);
} else {
$changelog = $this->l('Changelog not found :(');
}
}
$smarty->assign('changelog', $changelog);
$smarty->assign('PShowUpdateInstance', PShowUpdate::getInstance($this->filepath));
$smarty->assign('ModuleVersionNumber', $displayModuleVersion);
$smarty->assign('NewestVersionNumber', $displayNewestVersion);
$smarty->assign('compareModuleAndNewestVersion', PShowUpdate::getInstance($this->filepath)->compareModuleAndNewestVersion());
}
public function getCHMOD()
{
return Tools::substr(sprintf('%o', fileperms($this->filepath)), -4);
}
public function indexAction()
{
$this->action_displayName = $this->l('Update informations');
if ($this->getCHMOD() !== "0777") {
$this->updateChmod();
if ($this->getCHMOD() !== "0777") {
$this->alerts[] = array('danger', 'To update module you must set CHMOD 777 for all module files');
return;
}
}
}
public function updateChmod($path = null)
{
if ($path === null) {
$path = PShowUpdate::getInstance($this->filepath)->getModulePath();
}
$files = glob($path);
foreach ($files as $file) {
if (is_dir($file)) {
$this->updateChmod($file . "/*");
}
@chmod($file, 0777);
}
}
public function updateAction()
{
$this->action = 'index';
$this->action_displayName = $this->l('Update informations');
$this->updateChmod();
$from_ver = PShowUpdate::getInstance($this->filepath)->getModuleVersionNumber();
if (PShowUpdate::getInstance($this->filepath)->compareModuleAndNewestVersion() && !Tools::getValue('force')) {
return false;
}
$backup = PShowUpdate::getInstance($this->filepath)->makeModuleBackup();
if ($backup !== true) {
$this->alerts[] = array('warning', $this->l('Module backup error: ') . $backup);
return false;
} else {
$this->alerts[] = array('success', $this->l('Module backup completed'));
}
PShowUpdate::getInstance($this->filepath)->clearTmpDir();
$download = PShowUpdate::getInstance($this->filepath)->downloadUpdate();
if ($download !== true) {
$this->alerts[] = array('warning', $this->l('Download error: ') . $download);
return false;
} else {
$this->alerts[] = array('success', $this->l('Update downloaded'));
}
if (!PShowUpdate::getInstance($this->filepath)->extractUpdate()) {
$this->alerts[] = array('warning', $this->l('Update package extract error'));
return false;
} else {
$this->alerts[] = array('success', $this->l('Update package extracted'));
}
if (!PShowUpdate::getInstance($this->filepath)->moveUpdateToModule()) {
$this->alerts[] = array('warning', $this->l('Module update error'));
return false;
} else {
$this->alerts[] = array('success', $this->l('Module updated'));
}
Tools::redirectAdmin('index.php?controller=' . PShowUpdate::getInstance($this->filepath)->getModuleName() . ''
. 'Update&token=' . $this->token . '&page=execupdate&from_version=' . $from_ver);
}
public function execupdateAction()
{
$this->action = 'index';
$this->action_displayName = $this->l('Update informations');
PShowUpdate::getInstance($this->filepath)->execUpdate(Tools::getValue('from_version'));
PShowUpdate::getInstance($this->filepath)->clearTmpDir();
$this->alerts[] = array('success', $this->l('Module updated. In case of problems, reinstall the module.'));
$this->indexAction();
}
}

View File

@@ -0,0 +1,682 @@
<?php
class PShowUpdateNew
{
/**
* @deprecated since version 58
* do not use this !
*/
public static $modulename;
public static $customercode;
public static $prestaversion;
public static $tmppath;
public static $reportbugurl = 'http://modules.prestashow.pl/bug_report.php';
public static $updateurl = 'http://modules.prestashow.pl';
public static $modulepath = null;
/**
* @var array of \PShowUpdateNew
*/
private static $instance = array();
/**
* @var string
*/
private $filepath;
/**
* Get singleton instance
*
* @param string $_filepath
* @return \PShowUpdateNew
*/
public static function getInstance($_filepath)
{
$filepath = self::findRealFilePathFromBacktrace($_filepath);
$md5 = md5($filepath);
if (!array_key_exists($md5, self::$instance)) {
self::$instance[$md5] = new self($filepath);
}
return self::$instance[$md5];
}
/**
*
* @param string $filepath
* @return string
*/
public static function findRealFilePathFromBacktrace($filepath)
{
$backtrace = debug_backtrace();
foreach ($backtrace as $call) {
if (array_key_exists('file', $call) && stripos($call['file'], '/vendor/system/') === false && stripos($call['file'], '/modules/') !== false) {
return $call['file'];
}
}
// this should not happen !
return $filepath;
}
/**
* Get recommended product
*
* @return string
*/
public static function getRecommendedProduct()
{
if (!defined('PS_ADMIN_DIR')) {
return array(
'name' => 'PrestaShow.pl',
'description' => '',
'image' => '',
'url' => 'http://prestashow.pl'
);
}
if (_PS_CACHE_ENABLED_ && Cache::getInstance()->exists('pshow_recommended')) {
return Cache::getInstance()->get('pshow_recommended');
}
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'timeout' => 1
)
));
$products = @unserialize(file_get_contents('http://modules.prestashow.pl/recommended_products/1', false, $context));
if (!$products) {
$products = array(array('name' => 'PrestaShow.pl', 'description' => '', 'image' => '', 'url' => 'http://prestashow.pl'));
}
if (_PS_CACHE_ENABLED_) {
Cache::getInstance()->set('pshow_recommended', reset($products), 60);
}
return reset($products);
}
/**
* Constructor
*
* @param string $filepath
*/
private function __construct($filepath)
{
$this->filepath = $filepath;
}
/**
* Get module name
*
* @return string
*/
public function getModuleName()
{
$module_path = $this->getModulePath();
$module_path_arr = explode(DIRECTORY_SEPARATOR, $module_path);
return $module_path_arr[count($module_path_arr) - 2];
}
/**
* Get module path
*
* @return string
*/
public function getModulePath()
{
$filepath = $this->filepath;
if (Tools::getValue('controller') && stripos(Tools::getValue('controller'), 'PShow')) {
$controller = strtolower(Tools::getValue('controller'));
$bestpath = false;
for ($i = 0; $i <= strlen($controller); ++$i) {
$tmp = _PS_MODULE_DIR_ . substr($controller, 0, $i);
$bestpath = is_dir($tmp) ? $tmp : $bestpath;
}
return $bestpath . '/';
}
if (Tools::substr($filepath, -1, 1) == DIRECTORY_SEPARATOR) {
$filepath = Tools::substr($filepath, 0, Tools::strlen($filepath) - 1);
}
$explode = explode(DIRECTORY_SEPARATOR, dirname($filepath));
$stay = array_search('modules', $explode) + 1;
if (!array_key_exists($stay, $explode)) {
return $filepath . DIRECTORY_SEPARATOR;
}
$newpath_ = array();
for ($i = 0; $i <= $stay; ++$i) {
$newpath_[] = $explode[$i];
}
$newpath = implode(DIRECTORY_SEPARATOR, $newpath_);
return $newpath . DIRECTORY_SEPARATOR;
}
/**
* Get license key
*
* @return string
*/
public function getCustomerCode()
{
$customercode = 'no-license';
$customercode_file = $this->getModulePath($this->filepath) . "license";
// to protect license -> move code to php file
if (file_exists($customercode_file) && !file_exists($customercode_file . ".php")) {
$key = file_get_contents($customercode_file);
$key = preg_replace('/\s+/', '', $key);
file_put_contents($customercode_file . ".php", "<?php return '" . $key . "';");
}
if (file_exists($customercode_file . ".php")) {
$customercode_ = require($customercode_file . ".php");
if (is_string($customercode_)) {
$customercode = $customercode_;
}
if (file_exists($customercode_file)) {
unlink($customercode_file);
}
}
return $customercode;
}
/**
* Get module display name
*
* @return string
*/
public function getModuleDisplayName()
{
$module_file = Tools::file_get_contents($this->getModulePath() . $this->getModuleName() . '.php');
$matches = array();
preg_match_all('~class ([a-zA-Z0-9]+) extends~', $module_file, $matches);
$_matches = end($matches);
return end($_matches);
}
/**
* Get module version number
*
* @return string
*/
public function getModuleVersionNumber()
{
$path = $this->getModulePath() . $this->getModuleName() . '.php';
if (stripos($path, 'modules') === false || !file_exists($path)) {
return $path;
}
$module = Module::getInstanceByName($this->getModuleName());
if (!is_object($module)) {
return '0.0.0';
}
$module_version_arr = explode('.', $module->version);
if (file_exists($this->getModulePath() . 'vendor/system/version')) {
$skeleton_version = (int) Tools::file_get_contents($this->getModulePath() . 'vendor/system/version');
} else {
$skeleton_version = 0;
}
return ((int) $module_version_arr[0]) . '.' . ((int) $module_version_arr[1]) . '.' . ((int) $skeleton_version + (int) $module_version_arr[2]);
}
/**
* Get newest module version
*
* @return string
*/
public function getNewestVersionNumber()
{
if (!defined('PS_ADMIN_DIR')) {
return 'notInAdmin';
}
$controller = Tools::getValue('controller');
if (!$controller || stripos($controller, 'Update') === false) {
return 'notInUpdatePage';
}
$url = 'http://modules.prestashow.pl';
$url .= '/' . $this->getPrestashopVersion();
$url .= '/' . $this->getModuleName();
$url .= '/' . $this->getModuleVersionNumber();
$url .= '/' . $this->getCustomerCode();
$url .= '/' . gethostbyname(gethostname());
$url .= '/' . $_SERVER["HTTP_HOST"];
// try to get version by curl
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$newestVersionNumber = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
return $newestVersionNumber;
}
}
$headers = get_headers($url);
if (!strpos($headers[0], '200')) {
return 'Unable to check. Try again later...';
}
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'timeout' => 3
)
));
$newestVersionNumber = @file_get_contents($url, false, $context);
if (!$newestVersionNumber || $newestVersionNumber == '0.0.0') {
return 'Unable to check. Try again later...';
}
return $newestVersionNumber;
}
/**
* Get prestashop version
*
* @return string
*/
public function getPrestashopVersion()
{
return _PS_VERSION_;
}
/**
* Compare current module version with newest version
*
* @return mixed
*/
public function compareModuleAndNewestVersion()
{
return version_compare(
$this->getModuleVersionNumber(), $this->getNewestVersionNumber(), '>='
);
}
/**
* Download update package
*
* @return boolean | string
*/
public function downloadUpdate()
{
$url = 'http://modules.prestashow.pl';
$url .= '/download';
$url .= '/' . $this->getPrestashopVersion();
$url .= '/' . $this->getModuleName();
$url .= '/' . $this->getModuleVersionNumber();
$url .= '/' . $this->getCustomerCode();
$url .= '/' . gethostbyname(gethostname());
$url .= '/http://' . $_SERVER["HTTP_HOST"] . __PS_BASE_URI__;
$tmppath = $this->getTmpPath();
if (!is_dir($tmppath)) {
@mkdir($tmppath);
if (!is_dir($tmppath)) {
echo 'brak katalogu ' . $tmppath;
return false;
}
}
if (!is_writable($this->getTmpPath())) {
echo 'brak uprawnień, ustaw uprawnienia zapisu dla katalogu ' . $tmppath;
return false;
}
if (function_exists('curl_init')) {
set_time_limit(0);
$fp = fopen($tmppath . $this->getNewestVersionNumber() . '.zip', 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
} else {
$package = Tools::file_get_contents($url);
file_put_contents($tmppath . $this->getNewestVersionNumber() . '.zip', $package);
}
return (file_exists($tmppath . $this->getNewestVersionNumber() . '.zip'));
}
/**
* Get path to the temporary fir
*
* @return string
*/
public function getTmpPath()
{
return $this->getModulePath() . 'update/tmp/';
}
/**
* Extract update package
*
* @return boolean
*/
public function extractUpdate()
{
$version = $this->getNewestVersionNumber();
if (!file_exists($this->getTmpPath() . $version . '.zip')) {
return false;
}
$zip = new ZipArchive();
$res = $zip->open($this->getTmpPath() . $version . '.zip');
if ($res === true) {
$zip->extractTo($this->getTmpPath());
$zip->close();
return true;
} else {
return false;
}
}
/**
* Recursively copy directory
*
* @param string $src
* @param string $dst
* @return boolean
*/
public function recurseCopy($src, $dst)
{
$dir = opendir($src);
@mkdir($dst);
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' ) && ( $file != 'license' )) {
if (is_dir($src . '/' . $file)) {
$this->recurseCopy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
}
/**
* Clear temporary dir
*
* @return boolean
*/
public function clearTmpDir()
{
$this->recurseRemoveDir($this->getTmpPath());
return true;
}
/**
* Introduce new update into module
*
* @return boolean
*/
public function moveUpdateToModule()
{
$from = $this->getTmpPath() . $this->getModuleName() . "/";
$to = $this->getModulePath();
$this->recurseCopy($from, $to);
return true;
}
/**
* Recursively remove dir
*
* @param string $_path
* @param boolean $removePath
* @return boolean
*/
public function recurseRemoveDir($_path, $removePath = false)
{
if (!is_dir($_path)) {
return false;
}
$path = str_replace('//', '/', $_path);
if (Tools::substr($path, -1, 1) == DIRECTORY_SEPARATOR) {
$path = Tools::substr($path, 0, Tools::strlen($path) - 1);
}
$files = glob($path . '/*');
foreach ($files as $file) {
if (is_dir($file)) {
$this->recurseRemoveDir($file, true);
continue;
}
unlink($file);
}
if ($removePath === true) {
@rmdir($path);
}
}
/**
* Create module backup package
*
* @return boolean|string
*/
public function makeModuleBackup()
{
$path = $this->getModulePath() . "update/backups/";
$destPath = $path . $this->getModuleName() . "_" . $this->getModuleVersionNumber() . "_" . date('H.i_d.m.Y') . ".zip";
$zip = new ZipArchive();
if (!is_dir($path)) {
@mkdir($path);
if (!is_dir($path)) {
return 'brak katalogu ' . $path;
}
}
if (!$zip->open($destPath, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
return false;
}
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->getModulePath()), RecursiveIteratorIterator::LEAVES_ONLY
);
try {
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = Tools::substr($filePath, Tools::strlen($this->getModulePath()));
if (preg_match('~/update/~', $filePath)) {
continue;
}
if (preg_match('~\/.git\/~', $filePath)) {
continue;
}
if (preg_match('~\/license~', $filePath)) {
continue;
}
if (preg_match('~\/log\/~', $filePath)) {
continue;
}
if (preg_match('~\/' . $this->getModuleName() . '_~', $filePath)) {
continue;
}
$zip->addFile($filePath, $relativePath);
}
}
} catch (UnexpectedValueException $e) {
}
$zip->close();
return (file_exists($destPath));
}
/**
* Move backup package to temporary dir
*
* @param string $file
* @return boolean
*/
public function moveBackupToTmp($file)
{
if (!file_exists($this->getModulePath() . "update/backups/" . $file)) {
return false;
}
copy($this->getModulePath() . "update/backups/" . $file, $this->getTmpPath() . $file);
if (!file_exists($this->getTmpPath() . $file)) {
return false;
}
return true;
}
/**
* Extract backup package
*
* @param string $file
* @return boolean
*/
public function extractBackup($file)
{
if (!file_exists($this->getTmpPath() . $file)) {
return false;
}
$zip = new ZipArchive();
$res = $zip->open($this->getTmpPath() . $file);
if (!file_exists($this->getTmpPath() . 'backup/')) {
mkdir($this->getTmpPath() . 'backup/', 0777);
}
if ($res === TRUE) {
$zip->extractTo($this->getTmpPath() . 'backup/');
$zip->close();
return true;
} else {
return false;
}
}
/**
* Introduce backup to the module
*
* @return boolean
*/
public function moveBackupToModule()
{
$from = $this->getTmpPath() . 'backup/';
$to = $this->getModulePath();
$this->recurseCopy($from, $to);
return true;
}
/**
* Execute updates
*
* @param string $from_ver
* @return boolean
*/
public function execUpdate($from_ver)
{
$ver_expl = explode('.', $from_ver);
$from_ver = $ver_expl[0] . '.' . $ver_expl[1];
$modulename = $this->getModuleName();
require_once $this->getModulePath() . $modulename . '.php';
$instance = new $modulename();
if (!isset($instance->moduleVersionPath)) {
$instance->moduleVersionPath = array();
}
foreach ($instance->moduleVersionPath as $ver) {
$funcName = str_replace('.', '_', $from_ver);
if (version_compare($instance->version, $from_ver . '.0') == 1 && method_exists($instance, $funcName)) {
$instance->funcName();
}
}
//if (method_exists($instance, 'reinstallControllers')) $instance->reinstallControllers();
return false;
}
/**
* Format version to display
*
* @param string $version
* @return string
*/
public function formatVersionToDisplay($version)
{
return preg_replace('/([0-9]+).([0-9]+).([0-9]+)/i', '$1.$2-$3', $version);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShow_Ini
{
/**
* @param string $file
* @return mixed
*/
public static function read($file)
{
return ((file_exists($file)) ? parse_ini_file($file, true) : false);
}
/**
* @param array $array
* @param string $file
* @return boolean
*/
public static function write(array $array, $file)
{
$res = array();
foreach ($array as $key => $val) {
if (!is_array($val)) {
$res[] = "$key = " . (is_numeric($val) ? $val : '"' . $val . '"');
continue;
}
$res[] = "[$key]";
foreach ($val as $skey => $sval) {
$res[] = "$skey = " . (is_numeric($sval) ? $sval : '"' . $sval . '"');
}
}
return file_put_contents($file, implode("\r\n", $res));
}
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: /');
exit;