PluginProbe
MaxButtons – Create buttons / 6.26
MaxButtons – Create buttons v6.26
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.26, at blocks/icon.php

205 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
99 return $css;
100 }
101
102 /* Parse text align rule. Used for alignment of images and icons. In seperate function since it needs to process different pseudo's */
103 public function parse_rule_textalign($css, $csspart, $csspseudo)
104 {
105
106 if (isset($css[$csspart][$csspseudo]["text-align"]) && $css[$csspart][$csspseudo]["text-align"] != '')
107 {
108 switch( $css[$csspart][$csspseudo]["text-align"])
109 {
110 case "left":
111 $css[$csspart][$csspseudo]["float"] = 'left';
112 unset($css[$csspart][$csspseudo]["text-align"]);
113 break;
114 case "right":
115 $css[$csspart][$csspseudo]["float"] = 'right';
116 unset($css[$csspart][$csspseudo]["text-align"]);
117
118 break;
119 case "top":
120 case "bottom":
121 $css[$csspart][$csspseudo]["text-align"] = 'center';
122 break;
123 }
124 }
125
126 return $css;
127 }
128
129 public function parse_button($domObj, $mode = 'normal')
130 {
131 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
132 if (count($data) == 0)
133 return $domObj; // no icons present here.
134
135 //$button_id = $this->data["id"];
136
137 $icon_id = isset($data['icon_id']) ? $data['icon_id'] : 0;
138
139 $icon_url = $data["icon_url"];
140 $use_fa_icon= $data["use_fa_icon"];
141 $position = $data["icon_position"];
142
143 if ($icon_url == '' && ($use_fa_icon == 0 || $use_fa_icon == '') ) return $domObj; // no icon
144
145 $anchor = $domObj->find("a",0);
146 $anchor_text = '';
147
148 if ($use_fa_icon == 1)
149 {
150 if ($data["fa_icon_value"] == '') return $domObj; // still no icon
151 $anchor_text = '<span class="mb-icon "><i class="fa ' . $data["fa_icon_value"] . '"></i></span>';
152 }
153 else
154 {
155 $icon_alt = get_post_meta( $icon_id, '_wp_attachment_image_alt', true );
156 $anchor_text = '<span class="mb-icon "><img src="' . $data["icon_url"] . '" alt="' . $icon_alt . '" border="0" /></span>' ;
157 }
158 if ($position == 'bottom')
159 $anchor->innertext = $anchor->innertext . $anchor_text;
160 else
161 $anchor->innertext = $anchor_text . $anchor->innertext;
162
163 $newhtml = $domObj->save();
164
165 $domObj = new simple_html_dom();
166 $domObj->load($newhtml);
167
168 return $domObj;
169
170 }
171
172 // empty save, leave the data alone plz.
173 public function save_fields($data, $post)
174 {
175 return $data;
176 }
177
178 public function admin_fields()
179 {
180
181 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
182
183 $icon_url = isset($data["icon_url"]) ? $data["icon_url"] : '';
184
185 if ($icon_url == '' )
186 return; // hide if no setting
187
188
189
190 ?>
191 <div class="option-container mb_tab">
192 <div class="title"><?php _e('Icons and images', 'maxbuttons') ?></div>
193 <div class="inside">
194 <?php _e("This setting can only be changed in MaxButtons Pro","maxbuttons"); ?>
195
196 <p><img src="<?php echo $icon_url ?>"> </p>
197 </div>
198 </div>
199 <?php
200
201
202 }
203
204 } // class
205