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