PHPFusion\QuantumFields::display_fields PHP Метод

display_fields() публичный Метод

Display fields for each fieldDB record entry
public display_fields ( array $data, $callback_data, string $method = 'input', array $options = [] ) : array | boolean | string
$data array The array of the user field.
$callback_data
$method string input or display. In case of any other value the method return FALSE. See the description of return for more details.
$options array
  • deactivate (boolean): FALSE by default. disable fields
  • debug (bolean): FALSE by default. Show some information to debug.
  • encrypt (boolean): FALSE by default. encrypt field names
  • error_text (string): empty string by default. sets the field error text
  • hide_value (boolean): FALSE by default. input value is not shown on fields render
  • inline (boolean): FALSE by default. sets the field inline
  • required (boolean): FALSE by default. input must be filled when validate
  • show_title (boolean): FALSE by default. display field label
  • placeholder (string): empty string by default. helper text in field value
  • plugin_folder (string): INCLUDES.'user_fields/' by default The folder's path where the field's source files are.
  • plugin_locale_folder (string): LOCALE.LOCALESET.'/user_fields/' by default. The folder's path where the field's locale files are.
Результат array | boolean | string
  • FALSE on failure
  • string if $method 'display'
  • array if $method is 'input'
    public function display_fields(array $data, $callback_data, $method = 'input', array $options = array())
    {
        // Add compatibality to V7's UF module.
        // Security concerns: remove all password hashes and salt
        unset($callback_data['user_algo']);
        unset($callback_data['user_salt']);
        unset($callback_data['user_password']);
        unset($callback_data['user_admin_algo']);
        unset($callback_data['user_admin_salt']);
        unset($callback_data['user_admin_password']);
        $data += array('field_required' => TRUE, 'field_error' => '', 'field_default' => '');
        $default_options = array('hide_value' => FALSE, 'encrypt' => FALSE, 'show_title' => $method == "input" ? TRUE : FALSE, 'deactivate' => FALSE, 'inline' => FALSE, 'error_text' => $data['field_error'], 'required' => (bool) $data['field_required'], 'placeholder' => $data['field_default'], 'plugin_folder' => INCLUDES . 'user_fields/', 'plugin_locale_folder' => LOCALE . LOCALESET . '/user_fields/', 'debug' => FALSE);
        $options += $default_options;
        if (!$options['plugin_folder']) {
            $options['plugin_folder'] = $default_options['plugin_folder'];
        }
        if (!$options['plugin_locale_folder']) {
            $options['plugin_locale_folder'] = $default_options['plugin_locale_folder'];
        }
        if (substr($options['plugin_folder'], -1) !== '/') {
            $options['plugin_folder'] .= '/';
        }
        if (substr($options['plugin_locale_folder'], -1) !== '/') {
            $options['plugin_locale_folder'] .= '/';
        }
        // Sets callback data automatically.
        $option_list = $data['field_options'] ? explode(',', $data['field_options']) : array();
        // Format Callback Data
        $field_value = isset($callback_data[$data['field_name']]) ? $callback_data[$data['field_name']] : '';
        if (isset($_POST[$data['field_name']]) && !$options['hide_value']) {
            $field_value = $_POST[$data['field_name']];
        } elseif ($options['hide_value']) {
            $field_value = '';
        }
        switch ($data['field_type']) {
            case 'file':
                // Do not remove it. It is used in included files.
                $user_data = $callback_data;
                $profile_method = $method;
                // can access options vars
                if (file_exists($options['plugin_locale_folder'] . $data['field_name'] . ".php")) {
                    include $options['plugin_locale_folder'] . $data['field_name'] . ".php";
                }
                if (file_exists($options['plugin_folder'] . $data['field_name'] . "_include.php")) {
                    include $options['plugin_folder'] . $data['field_name'] . "_include.php";
                }
                if (isset($options['debug']) && $options['debug']) {
                    print_p("Finding " . $options['plugin_locale_folder'] . $data['field_name'] . ".php");
                    if (file_exists($options['plugin_locale_folder'] . $data['field_name'] . ".php")) {
                        print_p($data['field_name'] . " locale loaded");
                    }
                    print_p("Finding " . $options['plugin_folder'] . $data['field_name'] . "_include.php");
                    if (file_exists($options['plugin_folder'] . $data['field_name'] . "_include.php")) {
                        print_p($data['field_name'] . " module loaded");
                    }
                }
                if (isset($user_fields)) {
                    return $user_fields;
                }
                break;
            case 'textbox':
                if ($method == 'input') {
                    return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'number':
                if ($method == 'input') {
                    $options += array('type' => 'number');
                    return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'url':
                if ($method == 'input') {
                    $options += array('type' => 'url');
                    return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'email':
                if ($method == 'input') {
                    $options += array('type' => 'email');
                    return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'select':
                if ($method == 'input') {
                    $options['options'] = $option_list;
                    return form_select($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    $options_value = explode(",", $data['field_options']);
                    return array('title' => self::parse_label($data['field_title']), 'value' => !empty($options_value[$field_value]) ? $options_value[$field_value] : $field_value);
                }
                break;
            case 'tags':
                if ($method == 'input') {
                    $options += array('options' => $option_list, 'tags' => 1, 'multiple' => 1, 'width' => '100%');
                    return form_select($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'location':
                if ($method == 'input') {
                    $options += array('width' => '100%');
                    return form_location($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'textarea':
                if ($method == 'input') {
                    return form_textarea($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'checkbox':
                if ($method == 'input') {
                    return form_checkbox($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'datepicker':
                if ($method == 'input') {
                    return form_datepicker($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => showdate('shortdate', $field_value));
                }
                break;
            case 'colorpicker':
                if ($method == 'input') {
                    return form_colorpicker($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'uploader':
                if ($method == 'input') {
                    return form_fileinput($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'hidden':
                if ($method == 'input') {
                    return form_hidden($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
            case 'address':
                if ($method == 'input') {
                    return form_geo($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => implode('|', $field_value));
                }
                break;
            case 'toggle':
                $options['toggle'] = 1;
                $options['toggle_text'] = array($this->locale['off'], $this->locale['on']);
                if ($method == 'input') {
                    return form_checkbox($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
                } elseif ($method == 'display' && $field_value) {
                    return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
                }
                break;
        }
        return FALSE;
    }