Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
lang_helper.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\profilefields;
015
016 /**
017 * Custom Profile Fields
018 */
019 class lang_helper
020 {
021 /**
022 * Array with the language option, grouped by field and language
023 * @var array
024 */
025 protected $options_lang = array();
026
027 /**
028 * Database object
029 * @var \phpbb\db\driver\driver_interface
030 */
031 protected $db;
032
033 /**
034 * Table where the language strings are stored
035 * @var string
036 */
037 protected $language_table;
038
039 /**
040 * Construct
041 *
042 * @param \phpbb\db\driver\driver_interface $db Database object
043 * @param string $language_table Table where the language strings are stored
044 */
045 public function __construct($db, $language_table)
046 {
047 $this->db = $db;
048 $this->language_table = $language_table;
049 }
050
051 /**
052 * Loads preview options into language entries for options
053 *
054 * @param int $field_id
055 * @param int $lang_id
056 * @param mixed $preview_options
057 */
058 public function load_preview_options($field_id, $lang_id, $preview_options)
059 {
060 $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
061
062 foreach ($lang_options as $num => $var)
063 {
064 if (!isset($this->options_lang[$field_id]))
065 {
066 $this->options_lang[$field_id] = array();
067 }
068 if (!isset($this->options_lang[$field_id][$lang_id]))
069 {
070 $this->options_lang[$field_id][$lang_id] = array();
071 }
072 $this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
073 }
074 }
075
076 /**
077 * Fetches language entries for options from DB
078 *
079 * @param int $lang_id
080 */
081 public function load_option_lang($lang_id)
082 {
083 $sql = 'SELECT field_id, option_id, lang_value
084 FROM ' . $this->language_table . '
085 WHERE lang_id = ' . (int) $lang_id . "
086 ORDER BY option_id";
087
088 $result = $this->db->sql_query($sql);
089
090 while ($row = $this->db->sql_fetchrow($result))
091 {
092 $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
093 }
094
095 $this->db->sql_freeresult($result);
096 }
097
098 /**
099 * Are language options set for this field?
100 *
101 * @param int $field_id Database ID of the field
102 * @param int $lang_id ID of the language
103 * @param int $field_value Selected value of the field
104 * @return boolean
105 */
106 public function is_set($field_id, $lang_id = null, $field_value = null)
107 {
108 $is_set = isset($this->options_lang[$field_id]);
109
110 if ($is_set && (!is_null($lang_id) || !is_null($field_value)))
111 {
112 $is_set = isset($this->options_lang[$field_id][$lang_id]);
113 }
114
115 if ($is_set && !is_null($field_value))
116 {
117 $is_set = isset($this->options_lang[$field_id][$lang_id][$field_value]);
118 }
119
120 return $is_set;
121 }
122
123 /**
124 * Get the selected language string
125 *
126 * @param int $field_id Database ID of the field
127 * @param int $lang_id ID of the language
128 * @param int $field_value Selected value of the field
129 * @return string
130 */
131 public function get($field_id, $lang_id, $field_value = null)
132 {
133 if (is_null($field_value))
134 {
135 return $this->options_lang[$field_id][$lang_id];
136 }
137
138 return $this->options_lang[$field_id][$lang_id][$field_value];
139 }
140 }
141