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