403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonexport/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonexport/include.php
<?
namespace Wbs24;

use Bitrix\Main\SystemException;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Loader;

class Ozonexport
{
    protected const ERROR = true;
    public const MAX_MANUAL_ELEMENTS = 1000;
    protected const MANUAL_CALL_FLAG = 'WBS24_OZONEXPORT_MANUAL_CALL';

    protected $adminObject;
    protected $priceObject;
    protected $warehouseObject;
    protected $limitationObject;
    protected $filterObject;
    protected $offersLogObject;

    protected $manualCall;
    protected $elementCounter = 0;

    protected function text2xml(string $text, array $options)
    {
        $text = htmlspecialcharsbx($text, ENT_QUOTES|ENT_XML1);

        $text = preg_replace("/[\x1-\x8\xB-\xC\xE-\x1F]/", "", $text);

        $error = '';
        return \Bitrix\Main\Text\Encoding::convertEncoding($text, LANG_CHARSET, $options['CHARSET'], $error);
    }

    public function loadBlobToExportSettings($XML_DATA, $BLOB)
    {
        if (!empty($BLOB['priceType'])) {
            $XML_DATA['PRICE'] = $BLOB['priceType'];
        }

        return $XML_DATA;
    }

    public function getPropertyIdByCode($code, $iblockId)
    {
        $propertyId = false;
        if ($code != 'ID' && $code != 'XML_ID') {
            $res = \CIBlockProperty::GetList([], [
                'IBLOCK_ID' => $iblockId,
                'CODE' => $code,
            ]);
            if ($field = $res->Fetch()) {
                $propertyId = $field['ID'];
            }
        }

        return $propertyId;
    }

    public function loadPropertyIdToExportSettings($XML_DATA, $propertyId)
    {
        if ($propertyId) {
            if (!isset($XML_DATA['XML_DATA']['PARAMS'])) $XML_DATA['XML_DATA']['PARAMS'] = [];
            $XML_DATA['XML_DATA']['PARAMS'][] = $propertyId;
        }

        return $XML_DATA;
    }

    public function getElementId($element, $code = 'ID')
    {
        $id = false;

        if (is_numeric($code)) {
            $id = $element['PROPERTIES'][$code]['~VALUE'] ?? false;
             if (is_string($id)) {
            	$id = htmlspecialchars($id);
        	} elseif (is_array($id)) {
            	$id = htmlspecialchars($id[0]);
        	}
        } else {
            if ($code == 'XML_ID') $code = 'EXTERNAL_ID';
            if (!$code || !isset($element[$code])) $code = 'ID';
            $id = $element[$code];
        }

        return $id;
    }

    public function getParams($blob)
    {
        $param = [];
        foreach ($blob as $name => $value) {
            $calcValue = $value;
            if ($value == 'Y') $calcValue = true;
            if ($value == 'N') $calcValue = false;
            $param[$name] = $calcValue;
        }

        return $param;
    }

    public function getNeedPropertyIds($param)
    {
        $needProperties = [];
        $needParams = [
            'packageRatioProduct',
            'packageRatioOffer',
            'setPricePropsId',
            'setPricePropsOfferId',
            'setOldPricePropsId',
            'setOldPricePropsOfferId',
        ];

        foreach ($needParams as $paramCode) {
            $propertyId = $param[$paramCode] ?? false;
            if (!$propertyId) continue;

            $needProperties[$propertyId] = true;
        }

        return $needProperties;
    }

    public function updateItemFields($itemFields, $param)
    {
        $paramsWithFormula = [
            'formulaMinPrice',
        ];
        $allMarks = [];
        $addFields = [];

        foreach ($paramsWithFormula as $code) {
            $matches = null;
            preg_match_all('/\{PRICE_\d+\}/', $param[$code] ?? '', $matches);
            if (!empty($matches[0])) $allMarks = array_merge($allMarks, $matches[0]);
        }
        $allMarks = array_unique($allMarks);
        foreach ($allMarks as $mark) $addFields[] = str_replace(['{', '}'], '', $mark);
        $itemFields = array_merge($itemFields, $addFields);

        return $itemFields;
    }

    public function getAdminObject($param = [])
    {
        return $this->adminObject = new Ozonexport\Admin($param);
    }

    public function getPriceObject($param)
    {
        $ignoreSale = $param['ignoreSale'] ?: false;
        $extendPriceByFormula = $param['extendPriceByFormula'] ?: false;
        $extendPrice = $param['extendPrice'] ?: false;

        if ($extendPriceByFormula) {
            $this->priceObject = new Ozonexport\ExtendPriceByFormula($param);
        } elseif ($extendPrice) {
            $this->priceObject = new Ozonexport\ExtendPrice($param);
        } else {
            $this->priceObject = new Ozonexport\CommonPrice($param);
        }

        return $this->priceObject;
    }

    public function getWarehouseObject($param)
    {
        $extendWarehouse = $param['extendWarehouse'] ?: false;
        $warehouseSumOn = $param['warehouseSumOn'] ?: false;
        $propertiesBasedWarehouse = $param['propertiesBasedWarehouse'] ?: false;

        if ($extendWarehouse) {
            if ($warehouseSumOn) {
                $this->warehouseObject = new Ozonexport\ExtendWarehouseSum($param);
            } else {
                $this->warehouseObject = new Ozonexport\ExtendWarehouse($param);
            }
        } elseif ($propertiesBasedWarehouse) {
            $this->warehouseObject = new  Ozonexport\PropertiesBasedWarehouse($param);
        } else {
            $this->warehouseObject = new Ozonexport\CommonWarehouse($param);
        }

        return $this->warehouseObject;
    }

    public function getLimitationObject($param)
    {
        return $this->limitationObject = new Ozonexport\Limit($param);
    }

    public function getFilterObject($param)
    {
        return $this->filterObject = new Ozonexport\Filter($param);
    }

    public function getOffersLogObject($param)
    {
        return $this->offersLogObject = new Ozonexport\OffersLog($param);
    }

    public function setParamToBasicAuthObject($param)
    {
        $this->basicAuthObject = new Ozonexport\BasicAuth($param);
    }

    public function cleanKeysFromQuotes($array)
    {
        $cleanArray = [];
        if (is_array($array)) {
            foreach($array as $key => $value) {
                $key = str_replace(["'", '"'], '', $key);
                $cleanArray[$key] = $value;
            }
        }

        return $cleanArray;
    }

    public static function showReturnAsCode($result)
    {
        echo '<textarea>'.str_replace([
            '[',
            ']',
            '=> ',
            "\n",
            'Array",',
            '(",',
            ')",',
            "Array\n(",
        ], [
            '"',
            '"',
            '=> "',
            "\",\n",
            'Array',
            '(',
            ')',
            "Array(",
        ], print_r($result, true)).'</textarea>';

        //die();
    }

    public function updateExportFile($exportFile, $exportNewLinkedFile)
    {
        $success = false;
        $fullPathExportFile = $_SERVER["DOCUMENT_ROOT"].$exportFile;
        $fullPathExportNewLinkedFile = $_SERVER["DOCUMENT_ROOT"].$exportNewLinkedFile;

        $phpCode = $this->basicAuthObject->getAuthConditionCode($fullPathExportNewLinkedFile);

        $success = $this->writeToFile(
            $fullPathExportFile,
            $phpCode."\n"
        );

        if ($success) {
            $this->writeToFile(
                $fullPathExportFile.'.txt',
                $fullPathExportNewLinkedFile
            );

            $this->deleteOldExportsBeforeCurrent($fullPathExportNewLinkedFile);
        }

        return $success;
    }

    public function errorHandler($errors, $profileId = false)
    {
        $errorMessage = is_array($errors) ? implode('<br>', $errors) : $errors;
        $errorHead = Loc::getMessage("ERROR_HEADER");
        if ($profileId) $errorHead .= ' ('.Loc::getMessage("PROFILE_ID").$profileId.')';
        $errorHead .= ': ';

        $this->createReport('error_log.txt', $errorHead.$errorMessage);

        $notify = new Ozonexport\Notify();
        $notify->addAdminNotify($errorHead.$errorMessage, self::ERROR);
    }

    public function createReport($fileName, $message)
    {
        $prefix = trim(strtolower(str_replace('\\', '_', __CLASS__)), '_');

        $text = date('Y.m.d H:i:s')."\r\n";
        $text .= print_r($message, true)."\r\n\r\n";

        $handle = @fopen($_SERVER['DOCUMENT_ROOT'].'/upload/'.$prefix.'_'.$fileName, 'a');
        fwrite($handle, $text);
        fclose($handle);
    }

    protected function writeToFile($fullPath, $data)
    {
        $success = false;

        $fp = @fopen($fullPath, "wb");
        if ($fp) {
            fwrite($fp, $data);
            fclose($fp);
            $success = true;
        }

        return $success;
    }

    protected function getFromFile($fullPath)
    {
        return file_get_contents($fullPath);
    }

    protected function deleteOldExportsBeforeCurrent($currentFile)
    {
        $filesList = $this->getFilesListSamePath($currentFile);
        $similarFilesList = $this->getFilesByExample($filesList, $currentFile);
        $exportTime = $this->getExportTime($currentFile);
        $oldFilesList = $this->getFilesBeforeTime($similarFilesList, $exportTime);
        foreach ($oldFilesList as $file) {
            $this->deleteFile($file);
        }
    }

    protected function getFilesListSamePath($currentFile)
    {
        $path = dirname($currentFile);
        $filesList = scandir($path);
        $filesListWithPath = [];
        foreach ($filesList as $file) {
            $filesListWithPath[] = $path.'/'.$file;
        }

        return $filesListWithPath;
    }

    protected function getFilesByExample($filesList, $example)
    {
        $similarFilesList = [];
        $separator = '.php_import_';
        list($exampleStartName) = explode($separator, $example);

        foreach ($filesList as $file) {
            if (strpos($file, $separator) === false) continue;

            list($startName, $finishName) = explode($separator, $file);
            if ($startName == $exampleStartName) {
                $similarFilesList[] = $file;
            }
        }

        return $similarFilesList;
    }

    protected function getExportTime($currentFile)
    {
        $separator = '.php_import_';
        if (strpos($currentFile, $separator) === false) return;

        list($startName, $finishName) = explode($separator, $currentFile);
        $time = str_replace(['_', '.php'], '', $finishName);

        return intval($time);
    }

    protected function getFilesBeforeTime($filesList, $beforeTimestamp)
    {
        $oldFilesList = [];

        foreach ($filesList as $file) {
            $fileTime = $this->getExportTime($file);
            if (!$fileTime) continue;

            if ($fileTime < $beforeTimestamp) {
                $oldFilesList[] = $file;
            }
        }

        return $oldFilesList;
    }

    protected function deleteFile($file)
    {
        if ($file) unlink($file);
    }

    public function isLimitOfElementsExpired($trace = false)
    {
        $this->elementCounter++;
        $needLimit = ($this->isManualCall($trace) && $this->isDemoMode());

        return ($needLimit && $this->elementCounter > self::MAX_MANUAL_ELEMENTS);
    }

    protected function isManualCall($trace = false)
    {
        if ($this->manualCall !== null) return $this->manualCall;
        if (!$trace) $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

        $manualCall = false;
        foreach ($trace as $info) {
            $file = $info['file'] ?? '';
            if (strpos($file, 'export_setup.php') !== false) {
                $manualCall = true;
                break;
            }
        }

        $this->manualCall = $manualCall;
        $_SESSION[self::MANUAL_CALL_FLAG] = 'Y';

        return $manualCall;
    }

    public function isDemoMode()
    {
        return (Loader::includeSharewareModule('wbs24.ozonexport') == Loader::MODULE_DEMO);
    }

    public static function OnPrologHandler() {
        $ozon = new Ozonexport();
        if ($ozon->isFinishManualExport() && $ozon->isDemoMode()) {
            \Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/wbs24.ozonexport/init.js");
        }
    }

    public function isFinishManualExport()
    {
        $finish = false;
        if (
            strpos($_SERVER['REQUEST_URI'], '/bitrix/admin/cat_export_setup.php') !== false
            && isset($_SESSION[self::MANUAL_CALL_FLAG])
            && $_SESSION[self::MANUAL_CALL_FLAG] == 'Y'
        ) {
            $finish = true;
            unset($_SESSION[self::MANUAL_CALL_FLAG]);
        }

        return $finish;
    }
}

require_once('autoload.php');
?>

Youez - 2016 - github.com/yon3zu
LinuXploit