PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 4.1.4
Responsive Menu – Create Mobile-Friendly Menu v4.1.4
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / app / Collections / OptionsCollection.php

OptionsCollection.php in Responsive Menu – Create Mobile-Friendly Menu 4.1.4, at app/Collections/OptionsCollection.php

96 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Collections;
4
5 class OptionsCollection implements \ArrayAccess, \Countable {
6
7 private $options;
8
9 public function __construct(array $options = []) {
10 $this->options = array_map(function($o) {
11 return is_array($o) ? json_encode($o) : $o;
12 }, $options);
13 }
14
15 public function add(array $option) {
16 $value = $option[key($option)];
17 $this->options[key($option)] = is_array($value) ? json_encode($value) : $value;
18 }
19
20 public function getActiveArrow() {
21 if($this->options['active_arrow_image'])
22 return '<img alt="' . $this->options['active_arrow_image_alt'] .'" src="' . $this->getThemedUrl($this->options['active_arrow_image']) .'" />';
23
24 return $this->options['active_arrow_shape'];
25
26 }
27
28 public function getInActiveArrow() {
29 if($this->options['inactive_arrow_image'])
30 return '<img alt="' . $this->options['inactive_arrow_image_alt'] .'" src="' . $this->getThemedUrl($this->options['inactive_arrow_image']) .'" />';
31
32 return $this->options['inactive_arrow_shape'];
33
34 }
35
36 public function getTitleImage() {
37 if($this->options['menu_title_image'])
38 return '<img alt="' . $this->options['menu_title_image_alt'] .'" src="' . $this->getThemedUrl($this->options['menu_title_image']) .'" />';
39
40 return null;
41
42 }
43
44 public function getButtonIcon() {
45 if($this->options['button_image'])
46 return '<img alt="' . $this->options['button_image_alt'] .'" src="' . $this->getThemedUrl($this->options['button_image']) .'" class="responsive-menu-button-icon responsive-menu-button-icon-active" />';
47
48 return '<span class="responsive-menu-inner"></span>';
49 }
50
51 public function getButtonIconActive() {
52 if($this->options['button_image'])
53 return '<img alt="' . $this->options['button_image_alt_when_clicked'] .'" src="' . $this->getThemedUrl($this->options['button_image_when_clicked']) .'" class="responsive-menu-button-icon responsive-menu-button-icon-inactive" />';
54 }
55
56 public function offsetExists($offset) {
57 return array_key_exists($offset, $this->options);
58 }
59
60 public function offsetGet($offset) {
61 if(isset($this->options[$offset]))
62 return $this->options[$offset];
63 return null;
64 }
65
66 public function offsetSet($offset, $value) {
67 $this->add([$offset => $value]);
68 }
69
70 public function offsetUnset($offset) {
71 if(isset($this->options[$offset]))
72 unset($this->options[$offset]);
73 }
74
75 public function toArray() {
76 $array = [];
77 foreach($this->options as $key => $val)
78 $array[$key] = $val;
79 return $array;
80 }
81
82 public function count() {
83 return count($this->options);
84 }
85
86 private function getThemedUrl($image_url) {
87 if($this->options['menu_theme']):
88 $theme_url = wp_upload_dir()['baseurl'] . '/responsive-menu-themes/' . $this->options['menu_theme'];
89 $image_url = str_replace('{theme_images}', $theme_url . '/images', $image_url);
90 endif;
91
92 return $image_url;
93 }
94
95 }
96