[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\profilefields\type; 15 16 abstract class type_string_common extends type_base 17 { 18 protected $validation_options = array( 19 'CHARS_ANY' => '.*', 20 'NUMBERS_ONLY' => '[0-9]+', 21 'ALPHA_ONLY' => '[a-zA-Z0-9]+', 22 'ALPHA_UNDERSCORE' => '[\w]+', 23 'ALPHA_DOTS' => '[a-zA-Z0-9.]+', 24 'ALPHA_SPACERS' => '[\w\x20+\-\[\]]+', 25 'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-]+', 26 'LETTER_NUM_ONLY' => '[\p{Lu}\p{Ll}0-9]+', 27 'LETTER_NUM_UNDERSCORE' => '[\p{Lu}\p{Ll}0-9_]+', 28 'LETTER_NUM_DOTS' => '[\p{Lu}\p{Ll}0-9.]+', 29 'LETTER_NUM_SPACERS' => '[\p{Lu}\p{Ll}0-9\x20_+\-\[\]]+', 30 'LETTER_NUM_PUNCTUATION' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+', 31 ); 32 33 /** 34 * Return possible validation options 35 */ 36 public function validate_options($field_data) 37 { 38 $validate_options = ''; 39 foreach ($this->validation_options as $lang => $value) 40 { 41 $selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : ''; 42 $validate_options .= '<option value="' . $value . '"' . $selected . '>' . $this->user->lang[$lang] . '</option>'; 43 } 44 45 return $validate_options; 46 } 47 48 /** 49 * {@inheritDoc} 50 */ 51 public function get_default_field_value($field_data) 52 { 53 return $field_data['lang_default_value']; 54 } 55 56 /** 57 * Validate entered profile field data 58 * 59 * @param string $field_type Field type (string or text) 60 * @param mixed $field_value Field value to validate 61 * @param array $field_data Array with requirements of the field 62 * @return mixed String with key of the error language string, false otherwise 63 */ 64 public function validate_string_profile_field($field_type, &$field_value, $field_data) 65 { 66 if (trim($field_value) === '' && !$field_data['field_required']) 67 { 68 return false; 69 } 70 else if (trim($field_value) === '' && $field_data['field_required']) 71 { 72 return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); 73 } 74 75 if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) 76 { 77 return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name'])); 78 } 79 else if ($field_data['field_maxlen'] && utf8_strlen(html_entity_decode($field_value)) > $field_data['field_maxlen']) 80 { 81 return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name'])); 82 } 83 84 if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') 85 { 86 $field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value); 87 if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#iu', $field_validate)) 88 { 89 $validation = array_search($field_data['field_validation'], $this->validation_options); 90 if ($validation) 91 { 92 return $this->user->lang('FIELD_INVALID_CHARS_' . $validation, $this->get_field_name($field_data['lang_name'])); 93 } 94 return $this->user->lang('FIELD_INVALID_CHARS_INVALID', $this->get_field_name($field_data['lang_name'])); 95 } 96 } 97 98 return false; 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 public function get_profile_value($field_value, $field_data) 105 { 106 if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) 107 { 108 return null; 109 } 110 111 $field_value = make_clickable($field_value); 112 $field_value = censor_text($field_value); 113 $field_value = bbcode_nl2br($field_value); 114 return $field_value; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 public function get_profile_value_raw($field_value, $field_data) 121 { 122 if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) 123 { 124 return null; 125 } 126 127 return $field_value; 128 } 129 130 /** 131 * {@inheritDoc} 132 */ 133 public function get_profile_contact_value($field_value, $field_data) 134 { 135 return $this->get_profile_value_raw($field_value, $field_data); 136 } 137 138 /** 139 * {@inheritDoc} 140 */ 141 public function prepare_options_form(&$exclude_options, &$visibility_options) 142 { 143 $exclude_options[1][] = 'lang_default_value'; 144 145 return $this->request->variable('lang_options', '', true); 146 } 147 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |