PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
← All changes | blocks/icon.php +135 -105 6.46.28 View file →
@@ -1,173 +1,203 @@
1 1 <?php
2 +namespace MaxButtons;
2 3 defined('ABSPATH') or die('No direct access permitted');
3 -$blockClass["icon"] = "iconBlock";
4 -$blockOrder[60][] = "icon";
4 +$blockClass["icon"] = "iconBlock";
5 +$blockOrder[60][] = "icon";
5 6
6 -class iconBlock extends maxBlock
7 +use \simple_html_dom as simple_html_dom;
8 +
9 +class iconBlock extends maxBlock
7 10 {
8 - protected $blockname = "icon";
11 + protected $blockname = "icon";
9 12 protected $fields = array("use_fa_icon" => array("default" => 0),
10 13 "fa_icon_value" => array("default" => '',
11 14 "css" => ''),
12 -
13 - "fa_icon_size" => array("default" => '30px',
14 - "css" => 'font-size',
15 +
16 + "fa_icon_size" => array("default" => '30px',
17 + "css" => 'font-size',
15 18 "csspart" => "fa"),
16 -
17 - "icon_id" => array('default' => '',
19 +
20 + "icon_id" => array('default' => '',
18 21 'css' => ''
19 - ),
20 - "icon_url" => array('default' => '',
21 - 'css' => ''),
22 - /*"background_url" => array('default' => '',
22 + ),
23 + "icon_url" => array('default' => '',
24 + 'css' => ''),
25 + 'icon_size' => array('default' => '',),
26 + /*"background_url" => array('default' => '',
23 27 'css' => 'background-image',
24 - ), */
25 - "icon_alt" => array('default' => '',
26 - 'css' => ''),
27 -
28 -
29 - "icon_position" => array('default' => 'left',
30 - 'css' => 'text-align',
31 - 'csspart' => 'mb-icon'),
32 -
28 + ), */
29 + /* "icon_alt" => array('default' => '',
30 + 'css' => ''),
31 + */
32 +
33 + "icon_position" => array('default' => 'left',
34 + 'css' => 'text-align',
35 + 'csspart' => 'mb-icon'),
36 +
33 37 'icon_padding_top' => array('default' => '13px',
34 - 'css' => 'padding-top',
38 + 'css' => 'padding-top',
35 39 'csspart' => 'mb-icon'),
36 -
40 +
37 41 'icon_padding_right' => array('default' => '6px',
38 - 'css' => 'padding-right',
39 - 'csspart' => 'mb-icon'),
40 -
42 + 'css' => 'padding-right',
43 + 'csspart' => 'mb-icon'),
44 +
41 45 'icon_padding_bottom' => array('default' => '0px',
42 - 'css' => 'padding-bottom',
43 - 'csspart' => 'mb-icon'),
44 -
46 + 'css' => 'padding-bottom',
47 + 'csspart' => 'mb-icon'),
48 +
45 49 'icon_padding_left' => array('default' => '18px',
46 - 'css' => 'padding-left',
47 - 'csspart' => 'mb-icon'),
48 - );
50 + 'css' => 'padding-left',
51 + 'csspart' => 'mb-icon'),
52 + );
49 53
50 -
51 - public function parse_css($css, $mode = 'normal')
54 +
55 + public function parse_css($css, $mode = 'normal')
52 56 {
53 57
54 - $csspart = 'mb-icon';
55 - $csspseudo = 'normal';
58 + $csspart = 'mb-icon';
59 + $csspseudo = 'normal';
56 60
57 - $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
61 + $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
58 62 if (count($data) == 0)
59 63 return $css; // no icons present here.
60 -
61 - $css = parent::parse_css($css);
64 +
65 + $css = parent::parse_css($css);
62 66 $css["mb-icon"]["normal"]["line-height"] = "0px"; // prevent rendering bigger div than icon
63 67 $css["mb-icon"]["normal"]["display"] = "block";
64 - $css['mb-icon']['normal']['background-color'] = 'unset'; // prevent background overwrite.
65 -
68 + $css['mb-icon']['normal']['background-color'] = 'unset'; // prevent background overwrite.
69 +
66 70 /*if (isset($css["maxbutton"]["normal"]["background-image"]))
67 71 {
68 - $url = $css["maxbutton"]["normal"]["background-image"];
69 - $css["maxbutton"]["normal"]["background-image"] = "url($url)";
70 -
72 + $url = $css["maxbutton"]["normal"]["background-image"];
73 + $css["maxbutton"]["normal"]["background-image"] = "url($url)";
74 +
75 + } if (isset($css[$csspart][$csspseudo]["text-align"]) && $css[$csspart][$csspseudo]["text-align"] != '')
76 + {
77 + switch( $css[$csspart][$csspseudo]["text-align"])
78 + {
79 + case "left":
80 + $css[$csspart][$csspseudo]["float"] = 'left';
81 + unset($css[$csspart][$csspseudo]["text-align"]);
82 + break;
83 + case "right":
84 + $css[$csspart][$csspseudo]["float"] = 'right';
85 + unset($css[$csspart][$csspseudo]["text-align"]);
86 +
87 + break;
88 + case "top":
89 + case "bottom":
90 + $css[$csspart][$csspseudo]["text-align"] = 'center';
91 + break;
92 + }
71 93 }
72 - print_R($css["maxbutton"]);
94 + print_R($css["maxbutton"]);
73 95 */
74 -
75 - if (isset($css[$csspart][$csspseudo]["text-align"]) && $css[$csspart][$csspseudo]["text-align"] != '')
76 - {
96 + $css = $this->parse_rule_textalign($css, 'mb-icon', 'normal');
97 +
98 + return $css;
99 + }
100 +
101 + /* Parse text align rule. Used for alignment of images and icons. In seperate function since it needs to process different pseudo's */
102 + public function parse_rule_textalign($css, $csspart, $csspseudo)
103 + {
104 +
105 + if (isset($css[$csspart][$csspseudo]["text-align"]) && $css[$csspart][$csspseudo]["text-align"] != '')
106 + {
77 107 switch( $css[$csspart][$csspseudo]["text-align"])
78 108 {
79 - case "left":
109 + case "left":
80 110 $css[$csspart][$csspseudo]["float"] = 'left';
81 - unset($css[$csspart][$csspseudo]["text-align"]);
111 + unset($css[$csspart][$csspseudo]["text-align"]);
82 112 break;
83 113 case "right":
84 114 $css[$csspart][$csspseudo]["float"] = 'right';
85 - unset($css[$csspart][$csspseudo]["text-align"]);
86 -
87 - break;
88 - case "top":
89 - case "bottom":
90 - $css[$csspart][$csspseudo]["text-align"] = 'center';
115 + unset($css[$csspart][$csspseudo]["text-align"]);
116 +
91 117 break;
118 + case "top":
119 + case "bottom":
120 + $css[$csspart][$csspseudo]["text-align"] = 'center';
121 + break;
92 122 }
93 - }
123 + }
94 124
95 -
96 125 return $css;
97 126 }
98 -
127 +
99 128 public function parse_button($domObj, $mode = 'normal')
100 129 {
101 - $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
130 + $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
102 131 if (count($data) == 0)
103 132 return $domObj; // no icons present here.
104 -
105 - $id = $this->data["id"];
106 -
107 - $icon_url = $data["icon_url"];
108 - $use_fa_icon= $data["use_fa_icon"];
109 - $position = $data["icon_position"];
110 133
134 + //$button_id = $this->data["id"];
135 +
136 + $icon_id = isset($data['icon_id']) ? $data['icon_id'] : 0;
137 +
138 + $icon_url = $data["icon_url"];
139 + $use_fa_icon= $data["use_fa_icon"];
140 + $position = $data["icon_position"];
141 +
111 142 if ($icon_url == '' && ($use_fa_icon == 0 || $use_fa_icon == '') ) return $domObj; // no icon
112 -
113 - $anchor = $domObj->find("a",0);
114 - $anchor_text = '';
115 -
116 - if ($use_fa_icon == 1)
143 +
144 + $anchor = $domObj->find("a",0);
145 + $anchor_text = '';
146 +
147 + if ($use_fa_icon == 1)
117 148 {
118 - if ($data["fa_icon_value"] == '') return $domObj; // still no icon
149 + if ($data["fa_icon_value"] == '') return $domObj; // still no icon
119 150 $anchor_text = '<span class="mb-icon "><i class="fa ' . $data["fa_icon_value"] . '"></i></span>';
120 151 }
121 - else
152 + else
122 153 {
123 - $anchor_text = '<span class="mb-icon "><img src="' . $data["icon_url"] . '" alt="' . $data["icon_alt"] . '" border="0" /></span>' ;
124 - }
154 + $icon_alt = get_post_meta( $icon_id, '_wp_attachment_image_alt', true );
155 + $anchor_text = '<span class="mb-icon "><img src="' . $data["icon_url"] . '" alt="' . $icon_alt . '" border="0" /></span>' ;
156 + }
125 157 if ($position == 'bottom')
126 - $anchor->innertext = $anchor->innertext . $anchor_text;
158 + $anchor->innertext = $anchor->innertext . $anchor_text;
127 159 else
128 160 $anchor->innertext = $anchor_text . $anchor->innertext;
129 -
130 - $newhtml = $domObj->save();
131 -
132 - $domObj = new simple_html_dom();
161 +
162 + $newhtml = $domObj->save();
163 +
164 + $domObj = new simple_html_dom();
133 165 $domObj->load($newhtml);
134 166
135 - return $domObj;
136 -
137 - }
138 -
139 - // empty save, leave the data alone plz.
167 + return $domObj;
168 +
169 + }
170 +
171 + // empty save, leave the data alone plz.
140 172 public function save_fields($data, $post)
141 173 {
142 - return $data;
174 + return $data;
143 175 }
144 176
145 - public function admin_fields()
177 + public function admin_fields()
146 178 {
147 -
148 - $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
149 -
179 +
180 + $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
181 +
150 182 $icon_url = isset($data["icon_url"]) ? $data["icon_url"] : '';
151 -
152 - if ($icon_url == '' )
183 +
184 + if ($icon_url == '' )
153 185 return; // hide if no setting
154 -
155 -
156 -
186 +
187 +
188 +
157 189 ?>
158 190 <div class="option-container mb_tab">
159 191 <div class="title"><?php _e('Icons and images', 'maxbuttons') ?></div>
160 - <div class="inside">
161 - <?php _e("This setting can only be changed in MaxButtons Pro","maxbuttons"); ?>
162 -
192 + <div class="inside">
193 + <?php _e("This setting can only be changed in MaxButtons Pro","maxbuttons"); ?>
194 +
163 195 <p><img src="<?php echo $icon_url ?>"> </p>
164 196 </div>
165 - </div>
166 - <?php
167 -
168 -
197 + </div>
198 + <?php
199 +
200 +
169 201 }
170 202
171 203 } // class
172 -
173 -?>