ILIAS  release_8 Revision v8.24
ilCharSelectorConfig Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilCharSelectorConfig:

Public Member Functions

 __construct (string $a_context=self::CONTEXT_NONE)
 
 getContext ()
 get the context of the configuration (the context is set at initialisation and can't be changed) More...
 
 setAvailability (int $a_availability)
 
 getAvailability ()
 
 setAddedBlocks (array $a_blocks=array())
 
 getAddedBlocks ()
 
 setCustomItems (string $a_items='')
 set the custom items More...
 
 getCustomItems ()
 set the custom items More...
 
 setDefinition (string $a_definition='')
 
 getDefinition ()
 Set the definition of the available characters. More...
 
 getBlockOptions ()
 get the options for a block selection More...
 
 getBlockTitle (string $a_block_name)
 Get the title of a unicode block for display or selection A translation is used if it exists. More...
 
 getCharPages ()
 Get the character pages. More...
 

Static Public Member Functions

static _getCurrentConfig (ilObjTest $a_test_obj=null)
 Get the configuration that should be used for the current selector. More...
 

Data Fields

const INACTIVE = 0
 Availabilities INACTIVE/INHERIT corresponds to an unconfigured selector (no database entries) More...
 
const INHERIT = 0
 
const ENABLED = 1
 
const DISABLED = 2
 
const CONTEXT_NONE = ''
 Configuration contexts. More...
 
const CONTEXT_ADMIN = 'admin'
 
const CONTEXT_USER = 'user'
 
const CONTEXT_TEST = 'test'
 

Static Public Attributes

static array $unicode_blocks
 

Private Member Functions

 extractUnicodeBlock (string $a_item='')
 Extract the unicode block name from a definition item. More...
 
 getItemCodepoint (string $a_item)
 get the unicode index of an item More...
 
 getItemParsed (string $a_item)
 replace unicode notations with their utf8 chars in a string More...
 
 getItemParsedCallback (array $matches)
 callback for replacement of unicode notations More...
 
 codepointToUtf8 (int $codepoint)
 Return the UTF-8 sequence for a given Unicode code point. More...
 
 utf8ToCodepoint (string $char)
 Determine the Unicode codepoint of a single-character UTF-8 sequence. More...
 

Private Attributes

string $context = self::CONTEXT_NONE
 
int $availability = self::INHERIT
 
array $added_blocks = array()
 
array $custom_items = array()
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 19 of file ilCharSelectorConfig.php.

Constructor & Destructor Documentation

◆ __construct()

ilCharSelectorConfig::__construct ( string  $a_context = self::CONTEXT_NONE)

Definition at line 287 of file ilCharSelectorConfig.php.

288 {
289 switch ($a_context) {
293 $this->context = $a_context;
294 break;
295 default:
296 $this->context = self::CONTEXT_NONE;
297 }
298 }
const CONTEXT_NONE
Configuration contexts.

References CONTEXT_ADMIN, CONTEXT_NONE, CONTEXT_TEST, and CONTEXT_USER.

Member Function Documentation

◆ _getCurrentConfig()

static ilCharSelectorConfig::_getCurrentConfig ( ilObjTest  $a_test_obj = null)
static

Get the configuration that should be used for the current selector.

Definition at line 303 of file ilCharSelectorConfig.php.

303 : self
304 {
305 global $ilSetting, $ilUser;
306
307 // check configuration from administration settings
308 $admin_config = new self(self::CONTEXT_ADMIN);
309 $admin_config->setAvailability((int) $ilSetting->get('char_selector_availability'));
310 $admin_config->setDefinition((string) $ilSetting->get('char_selector_definition'));
311 if ($admin_config->getAvailability() === self::INACTIVE) {
312 // a globally inactive selector can't be overwritten by users or tests
313 return $admin_config;
314 }
315
316 // a test configuration is relevant for test runs
317 if (isset($a_test_obj)) {
318 $test_config = new self(self::CONTEXT_TEST);
319 $test_config->setAvailability((int) $a_test_obj->getCharSelectorAvailability());
320 $test_config->setDefinition((string) $a_test_obj->getCharSelectorDefinition());
321 if ($test_config->getAvailability() !== self::INHERIT) {
322 // a specific test configuration has precedence over user configuration
323 return $test_config;
324 }
325 }
326
327 // check configuration from user settings
328 $user_config = new self(self::CONTEXT_USER);
329 $user_config->setAvailability((int) $ilUser->getPref('char_selector_availability'));
330 $user_config->setDefinition((string) $ilUser->getPref('char_selector_definition'));
331 if ($user_config->getAvailability() !== self::INHERIT) {
332 // take user specific config
333 return $user_config;
334 } else {
335 // take admin config as default
336 return $admin_config;
337 }
338 }
const INACTIVE
Availabilities INACTIVE/INHERIT corresponds to an unconfigured selector (no database entries)
$ilUser
Definition: imgupload.php:34
global $ilSetting
Definition: privfeed.php:17

References $ilSetting, $ilUser, CONTEXT_ADMIN, CONTEXT_TEST, CONTEXT_USER, INACTIVE, and INHERIT.

Referenced by ilCharSelectorGUI\_getCurrentGUI().

+ Here is the caller graph for this function:

◆ codepointToUtf8()

ilCharSelectorConfig::codepointToUtf8 ( int  $codepoint)
private

Return the UTF-8 sequence for a given Unicode code point.

Returns an empty string if the codepoint is not known.

Taken and adapted from UtfNormalUtil which is removed from ILIAS since 8.0 Copyright (C) 2004 Brion Vibber brion.nosp@m.@pob.nosp@m.ox.co.nosp@m.m

See also
http://www.mediawiki.org/
http://www.gnu.org/copyleft/gpl.html

Definition at line 596 of file ilCharSelectorConfig.php.

596 : string
597 {
598 if ($codepoint < 0x80) {
599 return chr($codepoint);
600 }
601 if ($codepoint < 0x800) {
602 return chr($codepoint >> 6&0x3f|0xc0) .
603 chr($codepoint&0x3f|0x80);
604 }
605 if ($codepoint < 0x10000) {
606 return chr($codepoint >> 12&0x0f|0xe0) .
607 chr($codepoint >> 6&0x3f|0x80) .
608 chr($codepoint&0x3f|0x80);
609 }
610 if ($codepoint < 0x110000) {
611 return chr($codepoint >> 18&0x07|0xf0) .
612 chr($codepoint >> 12&0x3f|0x80) .
613 chr($codepoint >> 6&0x3f|0x80) .
614 chr($codepoint&0x3f|0x80);
615 }
616
617 return '';
618 }

Referenced by getItemParsedCallback().

+ Here is the caller graph for this function:

◆ extractUnicodeBlock()

ilCharSelectorConfig::extractUnicodeBlock ( string  $a_item = '')
private

Extract the unicode block name from a definition item.

Parameters
string$a_itemdefinition item
Returns
string unicode block name

Definition at line 493 of file ilCharSelectorConfig.php.

493 : string
494 {
495 $a_item = trim($a_item);
496 $matches = array();
497 if (preg_match('/^\[(.+)\]$/', $a_item, $matches)) {
498 $block_name = $matches[1];
499 if ($block_name === 'all' || array_key_exists($block_name, self::$unicode_blocks)) {
500 return $block_name;
501 }
502 }
503 return '';
504 }

Referenced by setDefinition().

+ Here is the caller graph for this function:

◆ getAddedBlocks()

ilCharSelectorConfig::getAddedBlocks ( )

Definition at line 381 of file ilCharSelectorConfig.php.

381 : array
382 {
383 return $this->added_blocks;
384 }

References $added_blocks.

◆ getAvailability()

ilCharSelectorConfig::getAvailability ( )

Definition at line 363 of file ilCharSelectorConfig.php.

363 : int
364 {
365 return $this->availability;
366 }

References $availability.

◆ getBlockOptions()

ilCharSelectorConfig::getBlockOptions ( )

get the options for a block selection

Definition at line 458 of file ilCharSelectorConfig.php.

458 : array
459 {
460 global $lng;
461
462 $options = array(
463 '' => $lng->txt('please_select'),
464 'all' => $lng->txt('char_selector_unicode_all')
465 );
466 foreach (array_keys(self::$unicode_blocks) as $block_name) {
467 $options[$block_name] = $this->getBlockTitle($block_name);
468 }
469 return $options;
470 }
getBlockTitle(string $a_block_name)
Get the title of a unicode block for display or selection A translation is used if it exists.
$lng

References $lng, and getBlockTitle().

+ Here is the call graph for this function:

◆ getBlockTitle()

ilCharSelectorConfig::getBlockTitle ( string  $a_block_name)

Get the title of a unicode block for display or selection A translation is used if it exists.

Definition at line 476 of file ilCharSelectorConfig.php.

476 : string
477 {
478 global $lng;
479
480 $langvar = 'char_selector_unicode_' . $a_block_name;
481 if ($lng->txt($langvar) !== '-' . $langvar . '-') {
482 return $lng->txt($langvar);
483 } else {
484 return self::$unicode_blocks[$a_block_name][0];
485 }
486 }

References $lng.

Referenced by getBlockOptions(), and getCharPages().

+ Here is the caller graph for this function:

◆ getCharPages()

ilCharSelectorConfig::getCharPages ( )

Get the character pages.

Returns
array [["page1", "A", "BC", [123,456], ...], ["page2], "X", ...], ...]

Definition at line 511 of file ilCharSelectorConfig.php.

511 : array
512 {
513 global $lng;
514
515 $pages = array();
516
517 // add custom block
518 //
519 $page = array($lng->txt('char_selector_custom_items'));
520 foreach ($this->custom_items as $item) {
521 if (strpos($item, '-') > 0) {
522 // handle range
523 $subitems = explode('-', $item);
524 $start = $this->getItemCodepoint($subitems[0]);
525 $end = $this->getItemCodepoint($subitems[1]);
526 $page[] = array($start, $end);
527 } else {
528 // handle normal item
529 $page[] = $this->getItemParsed($item);
530 }
531 }
532 if (count($page) > 1) {
533 $pages[] = $page;
534 }
535
536 // add unicode blocks
537 //
538 $blocks = in_array('all', $this->added_blocks) ?
539 array_keys(self::$unicode_blocks) :
540 $this->added_blocks;
541
542 foreach ($blocks as $block_name) {
543 $start = hexdec(self::$unicode_blocks[$block_name][1]);
544 $end = hexdec(self::$unicode_blocks[$block_name][2]);
545 $page = array($this->getBlockTitle($block_name), array($start, $end));
546 $pages[] = $page;
547 }
548
549 return $pages;
550 }
getItemCodepoint(string $a_item)
get the unicode index of an item
getItemParsed(string $a_item)
replace unicode notations with their utf8 chars in a string

References $added_blocks, $lng, getBlockTitle(), getItemCodepoint(), and getItemParsed().

+ Here is the call graph for this function:

◆ getContext()

ilCharSelectorConfig::getContext ( )

get the context of the configuration (the context is set at initialisation and can't be changed)

Definition at line 344 of file ilCharSelectorConfig.php.

344 : string
345 {
346 return $this->context;
347 }

References $context.

◆ getCustomItems()

ilCharSelectorConfig::getCustomItems ( )

set the custom items

See also
self::setDefinition() for item syntax

Definition at line 399 of file ilCharSelectorConfig.php.

399 : string
400 {
401 return implode(' ', $this->custom_items);
402 }

◆ getDefinition()

ilCharSelectorConfig::getDefinition ( )

Set the definition of the available characters.

See also
self::setDefinition()

Definition at line 446 of file ilCharSelectorConfig.php.

446 : string
447 {
448 $definition = implode(' ', $this->custom_items);
449 foreach ($this->added_blocks as $block_name) {
450 $definition .= ' [' . $block_name . ']';
451 }
452 return trim($definition);
453 }

◆ getItemCodepoint()

ilCharSelectorConfig::getItemCodepoint ( string  $a_item)
private

get the unicode index of an item

Definition at line 555 of file ilCharSelectorConfig.php.

555 : string
556 {
557 if (preg_match('/^[uU]\+[0-9a-fA-F]+$/', $a_item)) {
558 return (int) hexdec(substr($a_item, 2));
559 } else {
560 //take the codepoint of the first character
561 return $this->utf8ToCodepoint($a_item);
562 }
563 }
utf8ToCodepoint(string $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.

References utf8ToCodepoint().

Referenced by getCharPages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemParsed()

ilCharSelectorConfig::getItemParsed ( string  $a_item)
private

replace unicode notations with their utf8 chars in a string

Definition at line 568 of file ilCharSelectorConfig.php.

568 : string
569 {
570 return preg_replace_callback(
571 '/[uU]\+[0-9a-fA-F]+/',
572 array($this, 'getItemParsedCallback'),
573 $a_item
574 );
575 }

Referenced by getCharPages().

+ Here is the caller graph for this function:

◆ getItemParsedCallback()

ilCharSelectorConfig::getItemParsedCallback ( array  $matches)
private

callback for replacement of unicode notations

Parameters
array$matchespreg matches
Returns
string replacement string

Definition at line 582 of file ilCharSelectorConfig.php.

582 : string
583 {
584 return $this->codepointToUtf8((int) hexdec(substr($matches[0], 2)));
585 }
codepointToUtf8(int $codepoint)
Return the UTF-8 sequence for a given Unicode code point.

References codepointToUtf8().

+ Here is the call graph for this function:

◆ setAddedBlocks()

ilCharSelectorConfig::setAddedBlocks ( array  $a_blocks = array())
Parameters
array$a_blockslist of block names

Definition at line 371 of file ilCharSelectorConfig.php.

371 : void
372 {
373 $this->added_blocks = array();
374 foreach ($a_blocks as $block_name) {
375 if ($block_name === "all" || array_key_exists($block_name, self::$unicode_blocks)) {
376 $this->added_blocks[] = $block_name;
377 }
378 }
379 }

◆ setAvailability()

ilCharSelectorConfig::setAvailability ( int  $a_availability)

Definition at line 349 of file ilCharSelectorConfig.php.

349 : void
350 {
351 switch ($a_availability) {
352 case self::INACTIVE:
353 case self::INHERIT:
354 case self::ENABLED:
355 case self::DISABLED:
356 $this->availability = $a_availability;
357 break;
358 default:
359 $this->availability = self::INHERIT;
360 }
361 }

References DISABLED, ENABLED, INACTIVE, and INHERIT.

◆ setCustomItems()

ilCharSelectorConfig::setCustomItems ( string  $a_items = '')

set the custom items

See also
self::setDefinition() for item syntax

Definition at line 390 of file ilCharSelectorConfig.php.

390 : void
391 {
392 $this->custom_items = explode(' ', $a_items);
393 }

◆ setDefinition()

ilCharSelectorConfig::setDefinition ( string  $a_definition = '')

Definition at line 420 of file ilCharSelectorConfig.php.

420 : void
421 {
422 // first reset all previous settings
423 $this->added_blocks = array();
424 $this->custom_items = array();
425
426 // set the default definition to all unicode blocks
427 if (trim($a_definition) === '') {
428 $a_definition = "[all]";
429 }
430
431 // analyze definition items
432 $items = explode(' ', $a_definition);
433 foreach ($items as $item) {
434 if (($block_name = $this->extractUnicodeBlock($item)) !== '') {
435 $this->added_blocks[] = $block_name;
436 } elseif ($item !== '') {
437 $this->custom_items[] = trim($item);
438 }
439 }
440 }
extractUnicodeBlock(string $a_item='')
Extract the unicode block name from a definition item.

References extractUnicodeBlock().

+ Here is the call graph for this function:

◆ utf8ToCodepoint()

ilCharSelectorConfig::utf8ToCodepoint ( string  $char)
private

Determine the Unicode codepoint of a single-character UTF-8 sequence.

Does not check for invalid input data.

Taken and adapted from UtfNormalUtil which is removed from ILIAS since 8.0 Copyright (C) 2004 Brion Vibber brion.nosp@m.@pob.nosp@m.ox.co.nosp@m.m

See also
http://www.mediawiki.org/
http://www.gnu.org/copyleft/gpl.html

Definition at line 629 of file ilCharSelectorConfig.php.

629 : int
630 {
631 # Find the length
632 $z = ord($char[0]);
633 if ($z&0x80) {
634 $length = 0;
635 while ($z&0x80) {
636 $length++;
637 $z <<= 1;
638 }
639 } else {
640 $length = 1;
641 }
642
643 if ($length != strlen($char)) {
644 return false;
645 }
646 if ($length == 1) {
647 return ord($char);
648 }
649
650 # Mask off the length-determining bits and shift back to the original location
651 $z &= 0xff;
652 $z >>= $length;
653
654 # Add in the free bits from subsequent bytes
655 for ($i = 1; $i < $length; $i++) {
656 $z <<= 6;
657 $z |= ord($char[$i])&0x3f;
658 }
659
660 return $z;
661 }
$i
Definition: metadata.php:41

References $i.

Referenced by getItemCodepoint().

+ Here is the caller graph for this function:

Field Documentation

◆ $added_blocks

array ilCharSelectorConfig::$added_blocks = array()
private

Definition at line 282 of file ilCharSelectorConfig.php.

Referenced by getAddedBlocks(), and getCharPages().

◆ $availability

int ilCharSelectorConfig::$availability = self::INHERIT
private

Definition at line 279 of file ilCharSelectorConfig.php.

Referenced by getAvailability().

◆ $context

string ilCharSelectorConfig::$context = self::CONTEXT_NONE
private

Definition at line 276 of file ilCharSelectorConfig.php.

Referenced by getContext().

◆ $custom_items

array ilCharSelectorConfig::$custom_items = array()
private

Definition at line 285 of file ilCharSelectorConfig.php.

◆ $unicode_blocks

array ilCharSelectorConfig::$unicode_blocks
static

Definition at line 42 of file ilCharSelectorConfig.php.

◆ CONTEXT_ADMIN

◆ CONTEXT_NONE

const ilCharSelectorConfig::CONTEXT_NONE = ''

Configuration contexts.

Definition at line 33 of file ilCharSelectorConfig.php.

Referenced by __construct().

◆ CONTEXT_TEST

◆ CONTEXT_USER

◆ DISABLED

const ilCharSelectorConfig::DISABLED = 2

◆ ENABLED

◆ INACTIVE

const ilCharSelectorConfig::INACTIVE = 0

Availabilities INACTIVE/INHERIT corresponds to an unconfigured selector (no database entries)

Definition at line 25 of file ilCharSelectorConfig.php.

Referenced by _getCurrentConfig(), ilCharSelectorGUI\addFormProperties(), and setAvailability().

◆ INHERIT

const ilCharSelectorConfig::INHERIT = 0

The documentation for this class was generated from the following file: