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
maxbuttons / blocks / icon.php

icon.php in MaxButtons – Create buttons 6.28, at blocks/icon.php

204 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MaxButtons;
3 defined('ABSPATH') or die('No direct access permitted');
4 $blockClass["icon"] = "iconBlock";
5 $blockOrder[60][] = "icon";
6
7 use \simple_html_dom as simple_html_dom;
8
9 class iconBlock extends maxBlock
10 {
11 protected $blockname = "icon";
12 protected $fields = array("use_fa_icon" => array("default" => 0),
13 "fa_icon_value" => array("default" => '',
14 "css" => ''),
15
16 "fa_icon_size" => array("default" => '30px',
17 "css" => 'font-size',
18 "csspart" => "fa"),
19
20 "icon_id" => array('default' => '',
21 'css' => ''
22 ),
23 "icon_url" => array('default' => '',
24 'css' => ''),
25 'icon_size' => array('default' => '',),
26 /*"background_url" => array('default' => '',
27 'css' => 'background-image',
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
37 'icon_padding_top' => array('default' => '13px',
38 'css' => 'padding-top',
39 'csspart' => 'mb-icon'),
40
41 'icon_padding_right' => array('default' => '6px',
42 'css' => 'padding-right',
43 'csspart' => 'mb-icon'),
44
45 'icon_padding_bottom' => array('default' => '0px',
46 'css' => 'padding-bottom',
47 'csspart' => 'mb-icon'),
48
49 'icon_padding_left' => array('default' => '18px',
50 'css' => 'padding-left',
51 'csspart' => 'mb-icon'),
52 );
53
54
55 public function parse_css($css, $mode = 'normal')
56 {
57
58 $csspart = 'mb-icon';
59 $csspseudo = 'normal';
60
61 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
62 if (count($data) == 0)
63 return $css; // no icons present here.
64
65 $css = parent::parse_css($css);
66 $css["mb-icon"]["normal"]["line-height"] = "0px"; // prevent rendering bigger div than icon
67 $css["mb-icon"]["normal"]["display"] = "block";
68 $css['mb-icon']['normal']['background-color'] = 'unset'; // prevent background overwrite.
69
70 /*if (isset($css["maxbutton"]["normal"]["background-image"]))
71 {
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 }
93 }
94 print_R($css["maxbutton"]);
95 */
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 {
107 switch( $css[$csspart][$csspseudo]["text-align"])
108 {
109 case "left":
110 $css[$csspart][$csspseudo]["float"] = 'left';
111 unset($css[$csspart][$csspseudo]["text-align"]);
112 break;
113 case "right":
114 $css[$csspart][$csspseudo]["float"] = 'right';
115 unset($css[$csspart][$csspseudo]["text-align"]);
116
117 break;
118 case "top":
119 case "bottom":
120 $css[$csspart][$csspseudo]["text-align"] = 'center';
121 break;
122 }
123 }
124
125 return $css;
126 }
127
128 public function parse_button($domObj, $mode = 'normal')
129 {
130 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
131 if (count($data) == 0)
132 return $domObj; // no icons present here.
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
142 if ($icon_url == '' && ($use_fa_icon == 0 || $use_fa_icon == '') ) return $domObj; // no icon
143
144 $anchor = $domObj->find("a",0);
145 $anchor_text = '';
146
147 if ($use_fa_icon == 1)
148 {
149 if ($data["fa_icon_value"] == '') return $domObj; // still no icon
150 $anchor_text = '<span class="mb-icon "><i class="fa ' . $data["fa_icon_value"] . '"></i></span>';
151 }
152 else
153 {
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 }
157 if ($position == 'bottom')
158 $anchor->innertext = $anchor->innertext . $anchor_text;
159 else
160 $anchor->innertext = $anchor_text . $anchor->innertext;
161
162 $newhtml = $domObj->save();
163
164 $domObj = new simple_html_dom();
165 $domObj->load($newhtml);
166
167 return $domObj;
168
169 }
170
171 // empty save, leave the data alone plz.
172 public function save_fields($data, $post)
173 {
174 return $data;
175 }
176
177 public function admin_fields()
178 {
179
180 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
181
182 $icon_url = isset($data["icon_url"]) ? $data["icon_url"] : '';
183
184 if ($icon_url == '' )
185 return; // hide if no setting
186
187
188
189 ?>
190 <div class="option-container mb_tab">
191 <div class="title"><?php _e('Icons and images', 'maxbuttons') ?></div>
192 <div class="inside">
193 <?php _e("This setting can only be changed in MaxButtons Pro","maxbuttons"); ?>
194
195 <p><img src="<?php echo $icon_url ?>"> </p>
196 </div>
197 </div>
198 <?php
199
200
201 }
202
203 } // class
204