Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 77 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Marker | |
0.00% |
0 / 77 |
|
0.00% |
0 / 3 |
702 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getElementName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setProperty | |
0.00% |
0 / 71 |
|
0.00% |
0 / 1 |
600 | |||
| 1 | <?php |
| 2 | namespace MultiMaps; |
| 3 | |
| 4 | use MediaWiki\Title\Title; |
| 5 | |
| 6 | /** |
| 7 | * Marker class for collection of map elements |
| 8 | * |
| 9 | * @file Marker.php |
| 10 | * @ingroup MultiMaps |
| 11 | * @author Pavel Astakhov <pastakhov@yandex.ru> |
| 12 | * @license GPL-2.0-or-later |
| 13 | * @property string $icon Icon URL of marker |
| 14 | * @property array $size Size of icon |
| 15 | * @property array $anchor Anchor of icon |
| 16 | * @property string $shadow Shadow of icon |
| 17 | * @property array $shSize Size of shadow |
| 18 | * @property array $shAnchor Anchor of shadow |
| 19 | */ |
| 20 | class Marker extends BaseMapElement { |
| 21 | |
| 22 | function __construct() { |
| 23 | parent::__construct(); |
| 24 | |
| 25 | $this->availableProperties = array_merge( |
| 26 | $this->availableProperties, |
| 27 | [ 'icon' ] |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Returns element name |
| 33 | * return string Element name |
| 34 | */ |
| 35 | public function getElementName() { |
| 36 | return 'Marker'; // TODO i18n? |
| 37 | } |
| 38 | |
| 39 | public function setProperty( $name, $value ) { |
| 40 | global $egMultiMaps_CoordinatesSeparator, $egMultiMaps_OptionsSeparator, |
| 41 | $egMultiMaps_IconPath, $egMultiMaps_IconAllowFromDirectory; |
| 42 | |
| 43 | if ( strtolower( $name ) != 'icon' ) { |
| 44 | return parent::setProperty( $name, $value ); |
| 45 | } |
| 46 | |
| 47 | // Explode icon, it containt 'icon', 'size', 'anchor', 'shadow', 'shSize', 'shAnchor' |
| 48 | $properties = array_map( |
| 49 | 'trim', |
| 50 | explode( $egMultiMaps_CoordinatesSeparator, $value ) |
| 51 | ); |
| 52 | |
| 53 | // Icon URL |
| 54 | if ( !empty( $properties[0] ) ) { |
| 55 | $v = $properties[0]; |
| 56 | if ( $v[0] == '/' && $egMultiMaps_IconAllowFromDirectory ) { |
| 57 | if ( preg_match( '#[^0-9a-zA-Zа-яА-Я/_=\.\+\-]#', $v ) || mb_strpos( $v, '/../' ) !== false ) { |
| 58 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-icon-url', $v )->escaped(); |
| 59 | return false; |
| 60 | } |
| 61 | $v = $GLOBALS['wgServer'] . $egMultiMaps_IconPath . $v; |
| 62 | } else { |
| 63 | $title = Title::newFromText( $v, NS_FILE ); |
| 64 | if ( $title !== null && $title->exists() ) { |
| 65 | $imagePage = new \ImagePage( $title ); |
| 66 | $v = $imagePage->getDisplayedFile()->getURL(); |
| 67 | } else { |
| 68 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-icon', $v )->escaped(); |
| 69 | return false; |
| 70 | } |
| 71 | } |
| 72 | $this->properties['icon'] = htmlspecialchars( $v, ENT_NOQUOTES ); |
| 73 | } |
| 74 | |
| 75 | // Icon size |
| 76 | if ( !empty( $properties[1] ) ) { |
| 77 | $v = array_map( |
| 78 | 'intval', |
| 79 | explode( $egMultiMaps_OptionsSeparator, $properties[1] ) |
| 80 | ); |
| 81 | if ( count( $v ) != 2 ) { |
| 82 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-icon-size', $v, $value )->escaped(); |
| 83 | return false; |
| 84 | } |
| 85 | $this->properties['size'] = $v; |
| 86 | } |
| 87 | |
| 88 | // Icon anchor |
| 89 | if ( !empty( $properties[2] ) ) { |
| 90 | $v = array_map( |
| 91 | 'intval', |
| 92 | explode( $egMultiMaps_OptionsSeparator, $properties[2] ) |
| 93 | ); |
| 94 | if ( count( $v ) != 2 ) { |
| 95 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-icon-anchor', $v, $value )->escaped(); |
| 96 | return false; |
| 97 | } |
| 98 | $this->properties['anchor'] = $v; |
| 99 | } |
| 100 | |
| 101 | // Shadow URL |
| 102 | if ( !empty( $properties[3] ) ) { |
| 103 | $v = $properties[3]; |
| 104 | if ( $v[0] == '/' && $egMultiMaps_IconAllowFromDirectory ) { |
| 105 | if ( preg_match( '#[^0-9a-zA-Zа-яА-Я./_=\+\-]#', $v ) || preg_match( '#/../#', $v ) ) { |
| 106 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-shadow-url', $v )->escaped(); |
| 107 | return false; |
| 108 | } |
| 109 | $v = $GLOBALS['wgServer'] . $egMultiMaps_IconPath . $v; |
| 110 | } else { |
| 111 | $title = Title::newFromText( $v, NS_FILE ); |
| 112 | if ( $title !== null && $title->exists() ) { |
| 113 | $imagePage = new \ImagePage( $title ); |
| 114 | $v = $imagePage->getDisplayedFile()->getURL(); |
| 115 | } else { |
| 116 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-shadow-file', $v )->escaped(); |
| 117 | return false; |
| 118 | } |
| 119 | } |
| 120 | $this->properties['shadow'] = htmlspecialchars( $v, ENT_NOQUOTES ); |
| 121 | } |
| 122 | |
| 123 | // Shadow size |
| 124 | if ( !empty( $properties[4] ) ) { |
| 125 | $v = array_map( |
| 126 | 'intval', |
| 127 | explode( $egMultiMaps_OptionsSeparator, $properties[4] ) |
| 128 | ); |
| 129 | if ( count( $v ) != 2 ) { |
| 130 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-shadow-size', $v, $value )->escaped(); |
| 131 | return false; |
| 132 | } |
| 133 | $this->properties['shSize'] = $v; |
| 134 | } |
| 135 | |
| 136 | // Shadow anchor |
| 137 | if ( !empty( $properties[5] ) ) { |
| 138 | $v = array_map( |
| 139 | 'intval', |
| 140 | explode( $egMultiMaps_OptionsSeparator, $properties[5] ) |
| 141 | ); |
| 142 | if ( count( $v ) != 2 ) { |
| 143 | $this->errormessages[] = \wfMessage( 'multimaps-marker-incorrect-shadow-anchor', $v, $value )->escaped(); |
| 144 | return false; |
| 145 | } |
| 146 | $this->properties['shAnchor'] = $v; |
| 147 | } |
| 148 | |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | } |