270 lines
8.9 KiB
PHP
270 lines
8.9 KiB
PHP
<?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
|
|
*/
|
|
//error_reporting(E_ALL & ~E_NOTICE);
|
|
error_reporting(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
|
|
ini_set('display_errors', 'On');
|
|
//ini_set('xdebug.collect_vars', 'on');
|
|
//ini_set('xdebug.collect_params', '4');
|
|
//ini_set('xdebug.dump_globals', 'on');
|
|
//ini_set('xdebug.dump.SERVER', 'REQUEST_URI');
|
|
//ini_set('xdebug.show_local_vars', 'on');
|
|
ini_set('upload_max_filesize', '500M');
|
|
ini_set('post_max_size', '500M');
|
|
ini_set('memory_limit', '2000M');
|
|
ini_set('max_execution_time', '86400');
|
|
|
|
libxml_use_internal_errors(true);
|
|
|
|
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "system" . DIRECTORY_SEPARATOR . "autoload.php";
|
|
|
|
// prevent composer to load static classes
|
|
if (!defined('HHVM_VERSION')) {
|
|
define('HHVM_VERSION', true);
|
|
}
|
|
|
|
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
|
|
|
|
ini_set('xdebug.profiler_enable', '1');
|
|
ini_set('xdebug.profiler_output_dir', getModulePath(__FILE__));
|
|
//ini_set('xdebug.profiler_enable_trigger', '1');
|
|
|
|
define('_IMPORT_SECURE_KEY_', md5(getModulePath(__FILE__) . _COOKIE_KEY_));
|
|
|
|
//real path to classes of the module
|
|
define('_MODULE_CLASS_PATH_', getModulePath(__FILE__) . 'classes/');
|
|
|
|
//real path to controllers of the module
|
|
define('_MODULE_CTRL_PATH_', getModulePath(__FILE__) . 'controllers/');
|
|
|
|
//real path to upload directory
|
|
define('_MODULE_UPLOAD_PATH_', getModulePath(__FILE__) . 'upload/');
|
|
|
|
//real path to import configuration directory
|
|
define('_IMPORT_CONFIG_PATH_', getModulePath(__FILE__) . 'import-config/');
|
|
|
|
//real path to import logs directory
|
|
define('_IMPORT_LOG_PATH_', getModulePath(__FILE__) . 'import-log/');
|
|
|
|
//real path to files with list of the prestashop fields
|
|
define('_IMPORT_FIELDS_PATH_', getModulePath(__FILE__) . 'import-fields/');
|
|
|
|
//real path to files with list of the prestashop fields options
|
|
define('_IMPORT_OPTIONS_PATH_', getModulePath(__FILE__) . 'import-options/');
|
|
|
|
//real path to files with import status
|
|
define('_IMPORT_STATUS_PATH_', getModulePath(__FILE__) . 'import-status/');
|
|
|
|
//real path to files with import status
|
|
define('_PRESTA_CLASS_PATH_', getModulePath(__FILE__) . '../../class/');
|
|
|
|
//real path to files with import status
|
|
define('_IMPORT_FILE_EXTENSIONS_', 'csv,xml,CSV,XML');
|
|
|
|
//images quality 0-100
|
|
define('_IMPORT_IMAGE_QUALITY_', 80);
|
|
|
|
// in seconds
|
|
define('_IMPORT_MAX_AJAX_REQUEST_TIME_', 20);
|
|
|
|
if (!function_exists('getmicrotime')) {
|
|
|
|
function getmicrotime() {
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
return ((float) $usec + (float) $sec);
|
|
}
|
|
|
|
}
|
|
|
|
if (!function_exists('varDump')) {
|
|
|
|
function varDump($x) {
|
|
echo "<pre>";
|
|
var_dump($x);
|
|
echo "</pre>";
|
|
}
|
|
|
|
}
|
|
|
|
if (!class_exists('PShow_Import')) {
|
|
|
|
class PShow_Import {
|
|
|
|
public static function getInstance() {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function continueImportOnError() {
|
|
PShow_Import::getInstance()->updateActualRow();
|
|
PShow_Import::getInstance()->updateErrorsCounter();
|
|
|
|
$actual_link = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
if (stripos($actual_link, 'direct_import') !== null) {
|
|
header('Location: ' . __PS_BASE_URI__ . 'modules/pshowimporter/direct_import_continue.php?securekey=' + Tools::getValue('securekey'));
|
|
exit;
|
|
} elseif ((defined('STDIN') || (empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0)) && function_exists('exec')) {
|
|
exec("php " . getModulePath(__FILE__) . "direct_import_continue.php '" . Tools::getValue('securekey') . "'");
|
|
exit;
|
|
} elseif (defined('_PS_ADMIN_DIR_')) {
|
|
if (PShow_Import::getInstance()->isSomethingToImport()) {
|
|
Tools::redirectAdmin(
|
|
Context::getContext()->link->getAdminLink('PShowImporterImport', true)
|
|
. "&page=import&importnextrow=1"
|
|
. ((Tools::getValue('ajax')) ? "&ajax=1" : "")
|
|
. ((Tools::getValue('exc')) ? "&exc=" . (Tools::getValue('exc') + 1) : "&exc=1")
|
|
);
|
|
exit;
|
|
} else {
|
|
Tools::redirectAdmin(
|
|
Context::getContext()->link->getAdminLink('PShowImporterImport', true) . "&page=import"
|
|
);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (defined('_PS_ADMIN_DIR_') && defined('IMPORTING_NOW')) {
|
|
|
|
// set_exception_handler(function($e) {
|
|
// $pattern = "_Handler: Exception in %s [%d]: %s";
|
|
//
|
|
// if (file_exists(_IMPORT_STATUS_PATH_ . 'filename')) {
|
|
// PShow_Import::getInstance(file_get_contents(_IMPORT_STATUS_PATH_ . 'filename'));
|
|
// }
|
|
//
|
|
// if (PShow_Import::getInstance() && defined('IMPORTING_NOW')) {
|
|
// PShow_Log::add(
|
|
// PShow_Import::getInstance()->filename . ".log", sprintf($pattern, $e->getFile(), $e->getLine(), $e->getMessage())
|
|
// );
|
|
// continueImportOnError();
|
|
// } else {
|
|
// PShow_Log::addGlobal(
|
|
// sprintf($pattern, $e->getFile(), $e->getLine(), $e->getMessage())
|
|
// );
|
|
// die(sprintf($pattern, $e->getFile(), $e->getLine(), $e->getMessage()));
|
|
// }
|
|
// });
|
|
|
|
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
|
// skip some errors
|
|
if (in_array($errno, array(E_WARNING, E_NOTICE))) {
|
|
return;
|
|
}
|
|
|
|
switch ($errno) {
|
|
case E_ERROR:
|
|
case E_CORE_ERROR:
|
|
case E_COMPILE_ERROR:
|
|
case E_RECOVERABLE_ERROR:
|
|
case E_PARSE:
|
|
case E_COMPILE_ERROR:
|
|
case E_USER_ERROR:
|
|
$error_type_name = "FATAL ERROR";
|
|
break;
|
|
|
|
case E_USER_WARNING:
|
|
$error_type_name = "USER WARNING";
|
|
break;
|
|
|
|
case E_USER_NOTICE:
|
|
$error_type_name = "USER NOTICE";
|
|
break;
|
|
|
|
case E_WARNING:
|
|
$error_type_name = "WARNING";
|
|
break;
|
|
|
|
case E_DEPRECATED:
|
|
$error_type_name = "DEPRECATED";
|
|
break;
|
|
|
|
default:
|
|
$error_type_name = "UNKNOWN ERROR ";
|
|
break;
|
|
}
|
|
|
|
//$fatal_errors = array(E_ERROR, E_USER_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_RECOVERABLE_ERROR, E_PARSE);
|
|
|
|
$pattern = "Handler: " . $error_type_name . " in %s [%d]: %s";
|
|
|
|
if (file_exists(_IMPORT_STATUS_PATH_ . 'filename')) {
|
|
PShow_Import::getInstance(file_get_contents(_IMPORT_STATUS_PATH_ . 'filename'));
|
|
}
|
|
|
|
if (PShow_Import::getInstance() && defined('IMPORTING_NOW')) {
|
|
PShow_Log::add(
|
|
PShow_Import::getInstance()->filename . ".log", sprintf($pattern, $errfile, $errline, $errstr)
|
|
);
|
|
//continueImportOnError($errno);
|
|
} else {
|
|
PShow_Log::addGlobal(
|
|
sprintf($pattern, $errfile, $errline, $errstr)
|
|
);
|
|
}
|
|
});
|
|
|
|
class PrestaShopException extends PrestaShopExceptionCore {
|
|
|
|
public function displayMessage() {
|
|
$this->logError();
|
|
|
|
// $pattern = "Handler: Exception in %s [%d]: %s";
|
|
//
|
|
// if (file_exists(_IMPORT_STATUS_PATH_ . 'filename')) {
|
|
// PShow_Import::getInstance(file_get_contents(_IMPORT_STATUS_PATH_ . 'filename'));
|
|
// }
|
|
//
|
|
// if (PShow_Import::getInstance() && defined('IMPORTING_NOW')) {
|
|
// PShow_Log::add(
|
|
// PShow_Import::getInstance()->filename . ".log", sprintf($pattern, $this->getFile(), $this->getLine(), $this->getMessage())
|
|
// );
|
|
// continueImportOnError();
|
|
// } else {
|
|
// PShow_Log::addGlobal(
|
|
// sprintf($pattern, $errfile, $errline, $errstr)
|
|
// );
|
|
// }
|
|
}
|
|
|
|
}
|
|
|
|
Context::getContext()->smarty->muteExpectedErrors();
|
|
}
|
|
|
|
if (!function_exists('showTip')) {
|
|
function showTip($params) {
|
|
if (!array_key_exists('id', $params)) {
|
|
$params['id'] = uniqid();
|
|
}
|
|
|
|
if (!array_key_exists('type', $params)) {
|
|
$params['type'] = 'info';
|
|
}
|
|
|
|
if (!array_key_exists('message', $params)) {
|
|
$params['message'] = 'Enter message...';
|
|
}
|
|
|
|
if (!PShow_Settings::getInstance(__FILE__)->get('tip_' . $params['id'])) {
|
|
echo '<div class="alert alert-' . $params['type'] . ' fade in tip" id="' . $params['id'] . '">
|
|
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
|
<p>' . $params['message'] . '</p></div>';
|
|
}
|
|
}
|
|
|
|
smartyRegisterFunction(Context::getContext()->smarty, 'function', 'showTip', 'showTip');
|
|
}
|