HEX
Server: Apache
System: Linux srv-plesk28.ps.kz 5.14.0-284.18.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 29 17:06:27 EDT 2023 x86_64
User: greencl1 (10085)
PHP: 8.1.33
Disabled: apache_setenv,dl,eval,exec,openlog,passthru,pcntl_exec,pcntl_fork,popen,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,socket_create,socket_create_listen,socket_create_pair,syslog,system,socket_listen,stream_socket_server
Upload Files
File: /var/www/vhosts/greenclinic.kz/test.greenclinic.kz/modules/cms/classes/ComponentHelpers.php
<?php namespace Cms\Classes;

use Lang;

/**
 * Defines some component helpers for the CMS UI.
 *
 * @package october\system
 * @author Alexey Bobkov, Samuel Georges
 */
class ComponentHelpers
{
    /**
     * Returns a component property configuration as a JSON string or array.
     * @param mixed $component The component object
     * @param boolean $addAliasProperty Determines if the Alias property should be added to the result.
     * @param boolean $returnArray Determines if the method should return an array.
     * @return string
     */
    public static function getComponentsPropertyConfig($component, $addAliasProperty = true, $returnArray = false)
    {
        $result = [];

        if ($addAliasProperty) {
            $property = [
                'property'              => 'oc.alias',
                'title'                 => Lang::get('cms::lang.component.alias'),
                'description'           => Lang::get('cms::lang.component.alias_description'),
                'type'                  => 'string',
                'validationPattern'     => '^[a-zA-Z]+[0-9a-z\_]*$',
                'validationMessage'     => Lang::get('cms::lang.component.validation_message'),
                'required'              => true,
                'showExternalParam'     => false
            ];
            $result[] = $property;
        }

        $properties = $component->defineProperties();
        if (is_array($properties)) {
            foreach ($properties as $name => $params) {
                $property = [
                    'property'              => $name,
                    'title'                 => array_get($params, 'title', $name),
                    'type'                  => array_get($params, 'type', 'string'),
                    'showExternalParam'     => array_get($params, 'showExternalParam', true)
                ];

                foreach ($params as $name => $value) {
                    if (isset($property[$name])) {
                        continue;
                    }
                    $property[$name] = $value;
                }

                /*
                 * Translate human values
                 */
                $translate = ['title', 'description', 'options', 'group', 'validationMessage'];
                foreach ($property as $name => $value) {
                    if (!in_array($name, $translate)) {
                        continue;
                    }

                    if (is_array($value)) {
                        array_walk($property[$name], function (&$_value, $key) {
                            $_value = Lang::get($_value);
                        });
                    }
                    else {
                        $property[$name] = Lang::get($value);
                    }
                }

                $result[] = $property;
            }
        }

        if ($returnArray) {
            return $result;
        }

        return json_encode($result);
    }

    /**
     * Returns a component property values.
     * @param mixed $component The component object
     * @return mixed
     */
    public static function getComponentPropertyValues($component)
    {
        $result = [];

        $result['oc.alias'] = $component->alias;

        $properties = $component->defineProperties();
        foreach ($properties as $name => $params) {
            $result[$name] = $component->property($name);
        }

        return json_encode($result);
    }

    /**
     * Returns a component name.
     * @param mixed $component The component object
     * @return string
     */
    public static function getComponentName($component)
    {
        $details = $component->componentDetails();
        $name = $details['name'] ?? 'cms::lang.component.unnamed';

        return Lang::get($name);
    }

    /**
     * Returns a component description.
     * @param mixed $component The component object
     * @return string
     */
    public static function getComponentDescription($component)
    {
        $details = $component->componentDetails();
        $name = $details['description'] ?? 'cms::lang.component.no_description';

        return Lang::get($name);
    }
}