ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilCharSelectorConfig.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 {
10  const INACTIVE = 0; // default for admin: deactivates the whole tool
11  const INHERIT = 0; // default for user and test: take the plattform default
12  const ENABLED = 1; // enable the selector
13  const DISABLED = 2; // disable the selector
14 
18  const CONTEXT_NONE = ''; // no context => no initialisation
19  const CONTEXT_ADMIN = 'admin'; // administrative settings
20  const CONTEXT_USER = 'user'; // user specific settings
21  const CONTEXT_TEST = 'test'; // test specific settings
22 
27  static $unicode_blocks = array
28  (
29  'basic_latin' => array('Basic Latin', '0020', '007F'), // only printing characters
30  'latin_1_supplement' => array('Latin-1 Supplement', '00A0', '00FF'), // only printing characters
31  'latin_extended_a' => array('Latin Extended-A', '0100', '017F'),
32  'latin_extended_b' => array('Latin Extended-B', '0180', '024F'),
33  'ipa_extensions' => array('IPA Extensions', '0250', '02AF'),
34  'spacing_modifier_letters' => array('Spacing Modifier Letters', '02B0', '02FF'),
35  'combining_diacritical_marks' => array('Combining Diacritical Marks', '0300', '036F'),
36  'greek_and_coptic' => array('Greek and Coptic', '0370', '03FF'),
37  'cyrillic' => array('Cyrillic', '0400', '04FF'),
38  'cyrillic_supplement' => array('Cyrillic Supplement', '0500', '052F'),
39  'armenian' => array('Armenian', '0530', '058F'),
40  'hebrew' => array('Hebrew', '0590', '05FF'),
41  'arabic' => array('Arabic', '0600', '06FF'),
42  'syriac' => array('Syriac', '0700', '074F'),
43  'arabic_supplement' => array('Arabic Supplement', '0750', '077F'),
44  'thaana' => array('Thaana', '0780', '07BF'),
45  'nko' => array('NKo', '07C0', '07FF'),
46  'samaritan' => array('Samaritan', '0800', '083F'),
47  'mandaic' => array('Mandaic', '0840', '085F'),
48  'arabic_extended_a' => array('Arabic Extended-A', '08A0', '08FF'),
49  'devanagari' => array('Devanagari', '0900', '097F'),
50  'bengali' => array('Bengali', '0980', '09FF'),
51  'gurmukhi' => array('Gurmukhi', '0A00', '0A7F'),
52  'gujarati' => array('Gujarati', '0A80', '0AFF'),
53  'oriya' => array('Oriya', '0B00', '0B7F'),
54  'tamil' => array('Tamil', '0B80', '0BFF'),
55  'telugu' => array('Telugu', '0C00', '0C7F'),
56  'kannada' => array('Kannada', '0C80', '0CFF'),
57  'malayalam' => array('Malayalam', '0D00', '0D7F'),
58  'sinhala' => array('Sinhala', '0D80', '0DFF'),
59  'thai' => array('Thai', '0E00', '0E7F'),
60  'lao' => array('Lao', '0E80', '0EFF'),
61  'tibetan' => array('Tibetan', '0F00', '0FFF'),
62  'myanmar' => array('Myanmar', '1000', '109F'),
63  'georgian' => array('Georgian', '10A0', '10FF'),
64  'hangul_jamo' => array('Hangul Jamo', '1100', '11FF'),
65  'ethiopic' => array('Ethiopic', '1200', '137F'),
66  'ethiopic_supplement' => array('Ethiopic Supplement', '1380', '139F'),
67  'cherokee' => array('Cherokee', '13A0', '13FF'),
68  'unified_canadian_aboriginal_syllabics' => array('Unified Canadian Aboriginal Syllabics', '1400', '167F'),
69  'ogham' => array('Ogham', '1680', '169F'),
70  'runic' => array('Runic', '16A0', '16FF'),
71  'tagalog' => array('Tagalog', '1700', '171F'),
72  'hanunoo' => array('Hanunoo', '1720', '173F'),
73  'buhid' => array('Buhid', '1740', '175F'),
74  'tagbanwa' => array('Tagbanwa', '1760', '177F'),
75  'khmer' => array('Khmer', '1780', '17FF'),
76  'mongolian' => array('Mongolian', '1800', '18AF'),
77  'unified_canadian_aboriginal_syllabics_extended' => array('Unified Canadian Aboriginal Syllabics Extended', '18B0', '18FF'),
78  'limbu' => array('Limbu', '1900', '194F'),
79  'tai_le' => array('Tai Le', '1950', '197F'),
80  'new_tai_lue' => array('New Tai Lue', '1980', '19DF'),
81  'khmer_symbols' => array('Khmer Symbols', '19E0', '19FF'),
82  'buginese' => array('Buginese', '1A00', '1A1F'),
83  'tai_tham' => array('Tai Tham', '1A20', '1AAF'),
84  'balinese' => array('Balinese', '1B00', '1B7F'),
85  'sundanese' => array('Sundanese', '1B80', '1BBF'),
86  'batak' => array('Batak', '1BC0', '1BFF'),
87  'lepcha' => array('Lepcha', '1C00', '1C4F'),
88  'ol_chiki' => array('Ol Chiki', '1C50', '1C7F'),
89  'sundanese_supplement' => array('Sundanese Supplement', '1CC0', '1CCF'),
90  'vedic_extensions' => array('Vedic Extensions', '1CD0', '1CFF'),
91  'phonetic_extensions' => array('Phonetic Extensions', '1D00', '1D7F'),
92  'phonetic_extensions_supplement' => array('Phonetic Extensions Supplement', '1D80', '1DBF'),
93  'combining_diacritical_marks_supplement' => array('Combining Diacritical Marks Supplement', '1DC0', '1DFF'),
94  'latin_extended_additional' => array('Latin Extended Additional', '1E00', '1EFF'),
95  'greek_extended' => array('Greek Extended', '1F00', '1FFF'),
96  'general_punctuation' => array('General Punctuation', '2000', '206F'),
97  'superscripts_and_subscripts' => array('Superscripts and Subscripts', '2070', '209F'),
98  'currency_symbols' => array('Currency Symbols', '20A0', '20CF'),
99  'combining_diacritical_marks_for_symbols' => array('Combining Diacritical Marks for Symbols', '20D0', '20FF'),
100  'letterlike_symbols' => array('Letterlike Symbols', '2100', '214F'),
101  'number_forms' => array('Number Forms', '2150', '218F'),
102  'arrows' => array('Arrows', '2190', '21FF'),
103  'mathematical_operators' => array('Mathematical Operators', '2200', '22FF'),
104  'miscellaneous_technical' => array('Miscellaneous Technical', '2300', '23FF'),
105  'control_pictures' => array('Control Pictures', '2400', '243F'),
106  'optical_character_recognition' => array('Optical Character Recognition', '2440', '245F'),
107  'enclosed_alphanumerics' => array('Enclosed Alphanumerics', '2460', '24FF'),
108  'box_drawing' => array('Box Drawing', '2500', '257F'),
109  'block_elements' => array('Block Elements', '2580', '259F'),
110  'geometric_shapes' => array('Geometric Shapes', '25A0', '25FF'),
111  'miscellaneous_symbols' => array('Miscellaneous Symbols', '2600', '26FF'),
112  'dingbats' => array('Dingbats', '2700', '27BF'),
113  'miscellaneous_mathematical_symbols_a' => array('Miscellaneous Mathematical Symbols-A', '27C0', '27EF'),
114  'supplemental_arrows_a' => array('Supplemental Arrows-A', '27F0', '27FF'),
115  'braille_patterns' => array('Braille Patterns', '2800', '28FF'),
116  'supplemental_arrows_b' => array('Supplemental Arrows-B', '2900', '297F'),
117  'miscellaneous_mathematical_symbols_b' => array('Miscellaneous Mathematical Symbols-B', '2980', '29FF'),
118  'supplemental_mathematical_operators' => array('Supplemental Mathematical Operators', '2A00', '2AFF'),
119  'miscellaneous_symbols_and_arrows' => array('Miscellaneous Symbols and Arrows', '2B00', '2BFF'),
120  'glagolitic' => array('Glagolitic', '2C00', '2C5F'),
121  'latin_extended_c' => array('Latin Extended-C', '2C60', '2C7F'),
122  'coptic' => array('Coptic', '2C80', '2CFF'),
123  'georgian_supplement' => array('Georgian Supplement', '2D00', '2D2F'),
124  'tifinagh' => array('Tifinagh', '2D30', '2D7F'),
125  'ethiopic_extended' => array('Ethiopic Extended', '2D80', '2DDF'),
126  'cyrillic_extended_a' => array('Cyrillic Extended-A', '2DE0', '2DFF'),
127  'supplemental_punctuation' => array('Supplemental Punctuation', '2E00', '2E7F'),
128  'cjk_radicals_supplement' => array('CJK Radicals Supplement', '2E80', '2EFF'),
129  'kangxi_radicals' => array('Kangxi Radicals', '2F00', '2FDF'),
130  'ideographic_description_characters' => array('Ideographic Description Characters', '2FF0', '2FFF'),
131  'cjk_symbols_and_punctuation' => array('CJK Symbols and Punctuation', '3000', '303F'),
132  'hiragana' => array('Hiragana', '3040', '309F'),
133  'katakana' => array('Katakana', '30A0', '30FF'),
134  'bopomofo' => array('Bopomofo', '3100', '312F'),
135  'hangul_compatibility_jamo' => array('Hangul Compatibility Jamo', '3130', '318F'),
136  'kanbun' => array('Kanbun', '3190', '319F'),
137  'bopomofo_extended' => array('Bopomofo Extended', '31A0', '31BF'),
138  'cjk_strokes' => array('CJK Strokes', '31C0', '31EF'),
139  'katakana_phonetic_extensions' => array('Katakana Phonetic Extensions', '31F0', '31FF'),
140  'enclosed_cjk_letters_and_months' => array('Enclosed CJK Letters and Months', '3200', '32FF'),
141  'cjk_compatibility' => array('CJK Compatibility', '3300', '33FF'),
142  'cjk_unified_ideographs_extension_a' => array('CJK Unified Ideographs Extension A', '3400', '4DBF'),
143  'yijing_hexagram_symbols' => array('Yijing Hexagram Symbols', '4DC0', '4DFF'),
144  'cjk_unified_ideographs' => array('CJK Unified Ideographs', '4E00', '9FFF'),
145  'yi_syllables' => array('Yi Syllables', 'A000', 'A48F'),
146  'yi_radicals' => array('Yi Radicals', 'A490', 'A4CF'),
147  'lisu' => array('Lisu', 'A4D0', 'A4FF'),
148  'vai' => array('Vai', 'A500', 'A63F'),
149  'cyrillic_extended_b' => array('Cyrillic Extended-B', 'A640', 'A69F'),
150  'bamum' => array('Bamum', 'A6A0', 'A6FF'),
151  'modifier_tone_letters' => array('Modifier Tone Letters', 'A700', 'A71F'),
152  'latin_extended_d' => array('Latin Extended-D', 'A720', 'A7FF'),
153  'syloti_nagri' => array('Syloti Nagri', 'A800', 'A82F'),
154  'common_indic_number_forms' => array('Common Indic Number Forms', 'A830', 'A83F'),
155  'phags_pa' => array('Phags-pa', 'A840', 'A87F'),
156  'saurashtra' => array('Saurashtra', 'A880', 'A8DF'),
157  'devanagari_extended' => array('Devanagari Extended', 'A8E0', 'A8FF'),
158  'kayah_li' => array('Kayah Li', 'A900', 'A92F'),
159  'rejang' => array('Rejang', 'A930', 'A95F'),
160  'hangul_jamo_extended_a' => array('Hangul Jamo Extended-A', 'A960', 'A97F'),
161  'javanese' => array('Javanese', 'A980', 'A9DF'),
162  'cham' => array('Cham', 'AA00', 'AA5F'),
163  'myanmar_extended_a' => array('Myanmar Extended-A', 'AA60', 'AA7F'),
164  'tai_viet' => array('Tai Viet', 'AA80', 'AADF'),
165  'meetei_mayek_extensions' => array('Meetei Mayek Extensions', 'AAE0', 'AAFF'),
166  'ethiopic_extended_a' => array('Ethiopic Extended-A', 'AB00', 'AB2F'),
167  'meetei_mayek' => array('Meetei Mayek', 'ABC0', 'ABFF'),
168  'hangul_syllables' => array('Hangul Syllables', 'AC00', 'D7AF'),
169  'hangul_jamo_extended_b' => array('Hangul Jamo Extended-B', 'D7B0', 'D7FF'),
170  'high_surrogates' => array('High Surrogates', 'D800', 'DB7F'),
171  'high_private_use_surrogates' => array('High Private Use Surrogates', 'DB80', 'DBFF'),
172  'low_surrogates' => array('Low Surrogates', 'DC00', 'DFFF'),
173  'private_use_area' => array('Private Use Area', 'E000', 'F8FF'),
174  'cjk_compatibility_ideographs' => array('CJK Compatibility Ideographs', 'F900', 'FAFF'),
175  'alphabetic_presentation_forms' => array('Alphabetic Presentation Forms', 'FB00', 'FB4F'),
176  'arabic_presentation_forms_a' => array('Arabic Presentation Forms-A', 'FB50', 'FDFF'),
177  'variation_selectors' => array('Variation Selectors', 'FE00', 'FE0F'),
178  'vertical_forms' => array('Vertical Forms', 'FE10', 'FE1F'),
179  'combining_half_marks' => array('Combining Half Marks', 'FE20', 'FE2F'),
180  'cjk_compatibility_forms' => array('CJK Compatibility Forms', 'FE30', 'FE4F'),
181  'small_form_variants' => array('Small Form Variants', 'FE50', 'FE6F'),
182  'arabic_presentation_forms_b' => array('Arabic Presentation Forms-B', 'FE70', 'FEFF'),
183  'halfwidth_and_fullwidth_forms' => array('Halfwidth and Fullwidth Forms', 'FF00', 'FFEF'),
184  'specials' => array('Specials', 'FFF0', 'FFFF'),
185  /* here ends the Basic Multilinguage Plane (BMP) */
186 
187  /*
188  * The following blocks are not yet supported well.
189  * It seems that the chars are taken from the BMP instead
190  *
191  'linear_b_syllabary' => array('Linear B Syllabary', '10000', '1007F'),
192  'linear_b_ideograms' => array('Linear B Ideograms', '10080', '100FF'),
193  'aegean_numbers' => array('Aegean Numbers', '10100', '1013F'),
194  'ancient_greek_numbers' => array('Ancient Greek Numbers', '10140', '1018F'),
195  'ancient_symbols' => array('Ancient Symbols', '10190', '101CF'),
196  'phaistos_disc' => array('Phaistos Disc', '101D0', '101FF'),
197  'lycian' => array('Lycian', '10280', '1029F'),
198  'carian' => array('Carian', '102A0', '102DF'),
199  'old_italic' => array('Old Italic', '10300', '1032F'),
200  'gothic' => array('Gothic', '10330', '1034F'),
201  'ugaritic' => array('Ugaritic', '10380', '1039F'),
202  'old_persian' => array('Old Persian', '103A0', '103DF'),
203  'deseret' => array('Deseret', '10400', '1044F'),
204  'shavian' => array('Shavian', '10450', '1047F'),
205  'osmanya' => array('Osmanya', '10480', '104AF'),
206  'cypriot_syllabary' => array('Cypriot Syllabary', '10800', '1083F'),
207  'imperial_aramaic' => array('Imperial Aramaic', '10840', '1085F'),
208  'phoenician' => array('Phoenician', '10900', '1091F'),
209  'lydian' => array('Lydian', '10920', '1093F'),
210  'meroitic_hieroglyphs' => array('Meroitic Hieroglyphs', '10980', '1099F'),
211  'meroitic_cursive' => array('Meroitic Cursive', '109A0', '109FF'),
212  'kharoshthi' => array('Kharoshthi', '10A00', '10A5F'),
213  'old_south_arabian' => array('Old South Arabian', '10A60', '10A7F'),
214  'avestan' => array('Avestan', '10B00', '10B3F'),
215  'inscriptional_parthian' => array('Inscriptional Parthian', '10B40', '10B5F'),
216  'inscriptional_pahlavi' => array('Inscriptional Pahlavi', '10B60', '10B7F'),
217  'old_turkic' => array('Old Turkic', '10C00', '10C4F'),
218  'rumi_numeral_symbols' => array('Rumi Numeral Symbols', '10E60', '10E7F'),
219  'brahmi' => array('Brahmi', '11000', '1107F'),
220  'kaithi' => array('Kaithi', '11080', '110CF'),
221  'sora_sompeng' => array('Sora Sompeng', '110D0', '110FF'),
222  'chakma' => array('Chakma', '11100', '1114F'),
223  'sharada' => array('Sharada', '11180', '111DF'),
224  'takri' => array('Takri', '11680', '116CF'),
225  'cuneiform' => array('Cuneiform', '12000', '123FF'),
226  'cuneiform_numbers_and_punctuation' => array('Cuneiform Numbers and Punctuation', '12400', '1247F'),
227  'egyptian_hieroglyphs' => array('Egyptian Hieroglyphs', '13000', '1342F'),
228  'bamum_supplement' => array('Bamum Supplement', '16800', '16A3F'),
229  'miao' => array('Miao', '16F00', '16F9F'),
230  'kana_supplement' => array('Kana Supplement', '1B000', '1B0FF'),
231  'byzantine_musical_symbols' => array('Byzantine Musical Symbols', '1D000', '1D0FF'),
232  'musical_symbols' => array('Musical Symbols', '1D100', '1D1FF'),
233  'ancient_greek_musical_notation' => array('Ancient Greek Musical Notation', '1D200', '1D24F'),
234  'tai_xuan_jing_symbols' => array('Tai Xuan Jing Symbols', '1D300', '1D35F'),
235  'counting_rod_numerals' => array('Counting Rod Numerals', '1D360', '1D37F'),
236  'mathematical_alphanumeric_symbols' => array('Mathematical Alphanumeric Symbols', '1D400', '1D7FF'),
237  'arabic_mathematical_alphabetic_symbols' => array('Arabic Mathematical Alphabetic Symbols', '1EE00', '1EEFF'),
238  'mahjong_tiles' => array('Mahjong Tiles', '1F000', '1F02F'),
239  'domino_tiles' => array('Domino Tiles', '1F030', '1F09F'),
240  'playing_cards' => array('Playing Cards', '1F0A0', '1F0FF'),
241  'enclosed_alphanumeric_supplement' => array('Enclosed Alphanumeric Supplement', '1F100', '1F1FF'),
242  'enclosed_ideographic_supplement' => array('Enclosed Ideographic Supplement', '1F200', '1F2FF'),
243  'miscellaneous_symbols_and_pictographs' => array('Miscellaneous Symbols And Pictographs', '1F300', '1F5FF'),
244  'emoticons' => array('Emoticons', '1F600', '1F64F'),
245  'transport_and_map_symbols' => array('Transport And Map Symbols', '1F680', '1F6FF'),
246  'alchemical_symbols' => array('Alchemical Symbols', '1F700', '1F77F'),
247  'cjk_unified_ideographs_extension_b' => array('CJK Unified Ideographs Extension B', '20000', '2A6DF'),
248  'cjk_unified_ideographs_extension_c' => array('CJK Unified Ideographs Extension C', '2A700', '2B73F'),
249  'cjk_unified_ideographs_extension_d' => array('CJK Unified Ideographs Extension D', '2B740', '2B81F'),
250  'cjk_compatibility_ideographs_supplement' => array('CJK Compatibility Ideographs Supplement', '2F800', '2FA1F'),
251  'tags' => array('Tags', 'E0000', 'E007F'),
252  'variation_selectors_supplement' => array('Variation Selectors Supplement', 'E0100', 'E01EF'),
253  'supplementary_private_use_area_a' => array('Supplementary Private Use Area-A', 'F0000', 'FFFFF'),
254  'supplementary_private_use_area_b' => array('Supplementary Private Use Area-B', '100000', '10FFFF')
255  */
256  );
257 
262 
267 
271  private $added_blocks = array();
272 
276  private $custom_items = array();
277 
278 
284  public function __construct($a_context = self::CONTEXT_NONE)
285  {
286  switch($a_context)
287  {
288  case self::CONTEXT_ADMIN:
289  case self::CONTEXT_TEST:
290  case self::CONTEXT_USER:
291  $this->context = $a_context;
292  break;
293  default:
294  $this->context = self::CONTEXT_NONE;
295  }
296  }
297 
303  static function _getCurrentConfig(ilObjTest $a_test_obj = null)
304  {
305  global $ilSetting, $ilUser;
306 
307  // check configuration from administration settings
308  $admin_config = new self(self::CONTEXT_ADMIN, true);
309  $admin_config->setAvailability($ilSetting->get('char_selector_availability'));
310  $admin_config->setDefinition($ilSetting->get('char_selector_definition'));
311  if ($admin_config->getAvailability() == self::INACTIVE)
312  {
313  // a globally inactive selector can't be overwritten by users or tests
314  return $admin_config;
315  }
316 
317  // a test configuration is relevant for test runs
318  if (isset($a_test_obj))
319  {
320  $test_config = new self(self::CONTEXT_TEST, false);
321  $test_config->setAvailability($a_test_obj->getCharSelectorAvailability());
322  $test_config->setDefinition($a_test_obj->getCharSelectorDefinition());
323  if ($test_config->getAvailability() != self::INHERIT)
324  {
325  // a specific test configuration has precedence over user configuration
326  return $test_config;
327  }
328  }
329 
330  // check configuration from user settings
331  $user_config = new self(self::CONTEXT_USER, true);
332  $user_config->setAvailability($ilUser->getPref('char_selector_availability'));
333  $user_config->setDefinition($ilUser->getPref('char_selector_definition'));
334  if ($user_config->getAvailability() != self::INHERIT)
335  {
336  // take user specific config
337  return $user_config;
338  }
339  else
340  {
341  // take admin config as default
342  return $admin_config;
343  }
344  }
345 
346 
352  public function getContext()
353  {
354  return $this->context;
355  }
356 
357 
362  public function setAvailability($a_availability)
363  {
364  switch((int) $a_availability)
365  {
366  case self::INACTIVE:
367  case self::INHERIT:
368  case self::ENABLED:
369  case self::DISABLED:
370  $this->availability = (int) $a_availability;
371  break;
372  default:
373  $this->availability = self::INHERIT;
374  }
375  }
376 
377 
382  public function getAvailability()
383  {
384  return $this->availability;
385  }
386 
391  public function setAddedBlocks($a_blocks = array())
392  {
393  $this->added_blocks = array();
394  foreach ($a_blocks as $block_name)
395  {
396  if ($block_name == "all" or
397  in_array($block_name, array_keys(self::$unicode_blocks)))
398  {
399  array_push($this->added_blocks, $block_name);
400  }
401  }
402  }
403 
408  public function getAddedBlocks()
409  {
410  return $this->added_blocks;
411  }
412 
418  public function setCustomItems($a_items = '')
419  {
420  $this->custom_items = explode(' ', $a_items);
421  }
422 
428  public function getCustomItems()
429  {
430  return implode(' ', $this->custom_items);
431  }
432 
449  public function setDefinition($a_definition = '')
450  {
451  // first reset all previous settings
452  $this->added_blocks = array();
453  $this->custom_items = array();
454 
455  // set the default definition to all unicode blocks
456  if (trim($a_definition) == '')
457  {
458  $a_definition = "[all]";
459  }
460 
461  // analyze definition items
462  $items = explode(' ', $a_definition);
463  foreach ($items as $item)
464  {
465  if (strlen($block_name = $this->extractUnicodeBlock($item)))
466  {
467  array_push($this->added_blocks, $block_name);
468  }
469  else if ($item != '')
470  {
471  array_push($this->custom_items, trim($item));
472  }
473  }
474  }
475 
481  public function getDefinition()
482  {
483  $definition = implode(' ', $this->custom_items);
484  foreach($this->added_blocks as $block_name)
485  {
486  $definition = $definition . ' [' . $block_name . ']';
487  }
488  return trim($definition);
489  }
490 
491 
496  public function getBlockOptions()
497  {
498  global $lng;
499 
500  $options = array(
501  '' => $lng->txt('please_select'),
502  'all' => $lng->txt('char_selector_unicode_all')
503  );
504  foreach (array_keys(self::$unicode_blocks) as $block_name)
505  {
506  $options[$block_name] = $this->getBlockTitle($block_name);
507  }
508  return $options;
509  }
510 
511 
519  public function getBlockTitle($a_block_name)
520  {
521  global $lng;
522 
523  $langvar = 'char_selector_unicode_'. $a_block_name;
524  if ($lng->txt($langvar) != '-'.$langvar.'-' )
525  {
526  return $lng->txt($langvar);
527  }
528  else
529  {
530  return self::$unicode_blocks[$a_block_name][0];
531  }
532  }
533 
540  private function extractUnicodeBlock($a_item = '')
541  {
542  $a_item = trim($a_item);
543  $matches = array();
544  if (preg_match('/^\[(.+)\]$/', $a_item, $matches))
545  {
546  $block_name = $matches[1];
547  if ($block_name == 'all'
548  or in_array($block_name, array_keys(self::$unicode_blocks)))
549  {
550  return $block_name;
551  }
552  }
553  return '';
554  }
555 
556 
562  public function getCharPages()
563  {
564  global $lng;
565 
566  $pages = array();
567 
568  // add custom block
569  //
570  $page = array($lng->txt('char_selector_custom_items'));
571  foreach ($this->custom_items as $item)
572  {
573  if (strpos($item, '-') > 0)
574  {
575  // handle range
576  $subitems = explode('-', $item);
577  $start = $this->getItemCodepoint($subitems[0]);
578  $end = $this->getItemCodepoint($subitems[1]);
579  array_push($page, array($start, $end));
580  }
581  else
582  {
583  // handle normal item
584  array_push($page, $this->getItemParsed($item));
585  }
586  }
587  if (count($page) > 1)
588  {
589  array_push($pages, $page);
590  }
591 
592  // add unicode blocks
593  //
594  $blocks = in_array('all', $this->added_blocks) ?
595  array_keys(self::$unicode_blocks) :
597 
598  foreach ($blocks as $block_name)
599  {
600  $start = hexdec(self::$unicode_blocks[$block_name][1]);
601  $end = hexdec(self::$unicode_blocks[$block_name][2]);
602  $page = array($this->getBlockTitle($block_name), array($start, $end));
603  array_push($pages, $page);
604  }
605 
606  return $pages;
607  }
608 
609 
614  private function getItemCodepoint($a_item)
615  {
616  if (preg_match('/^[uU]\+[0-9a-fA-F]+$/', $a_item))
617  {
618  return (int) hexdec(substr($a_item, 2));
619  }
620  else
621  {
622  //take the codepoint of the first character
623  require_once "include/Unicode/UtfNormalUtil.php";
624  return (int) utf8ToCodepoint($a_item);
625  }
626  }
627 
633  private function getItemParsed($a_item)
634  {
635  return preg_replace_callback(
636  '/[uU]\+[0-9a-fA-F]+/',
637  array($this,'getItemParsedCallback'),
638  $a_item
639  );
640  }
641 
647  private function getItemParsedCallback($matches)
648  {
649  require_once "include/Unicode/UtfNormalUtil.php";
650  return codepointToUtf8(hexdec(substr($matches[0], 2)));
651  }
652 
653 }
654 ?>