PluginProbe
MaxButtons – Create buttons / 6.23
MaxButtons – Create buttons v6.23
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 / basic.php

basic.php in MaxButtons – Create buttons 6.23, at blocks/basic.php

485 lines 16.6 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
5 $blockClass["basic"] = "basicBlock";
6 $blockOrder[0][] = "basic";
7
8
9 class basicBlock extends maxBlock
10 {
11 protected $blockname = "basic";
12 protected $fields = array("name" => array("default" => ''),
13 "status" => array("default" => "publish"),
14 "description" => array("default" => ''),
15 "url" => array("default" => ''),
16 'link_title' => array('default' => ''),
17 // "text" => array("default" => ''),
18 "new_window" => array("default" => 0),
19 "nofollow" => array("default" => 0)
20 );
21 protected $protocols = array("http","https",'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'sms', 'callto', 'fax', 'xmpp', "javascript", 'file'); // allowed url protocols for esc_url functions
22
23
24 function __construct()
25 {
26 parent::__construct();
27 }
28
29
30 public function parse_css($css, $mode = 'normal')
31 {
32 // emtpy string init is not like by PHP 7.1
33 if (! is_array($css))
34 $css = array();
35
36 $data = $this->data[$this->blockname];
37
38 $css["maxbutton"]["normal"]["position"] = "relative";
39 $css["maxbutton"]["normal"]["text-decoration"] = "none";
40 // $css["maxbutton"]["normal"]["white-space"] = "nowrap"; // hinders correct rendering of oneline-multilines
41 $css["maxbutton"]["normal"]["display"] = "inline-block";
42
43 /*if (isset($data["url"]) && $data["url"] == '') // don't show clickable anchor if there is no URL.
44 {
45 $css["maxbutton"]["normal"]["cursor"] = 'default';
46 // $css[":hover"]["cursor"] = 'default';
47 } */
48
49 return $css;
50
51 }
52
53
54
55 public function save_fields($data, $post)
56 {
57 // Possible solution:
58 // $post["url"] = isset($post["url"]) ? urldecode(urldecode($post["url"])) : '';
59
60 $description = false;
61
62 if (isset($post["description"]) && $post["description"] != '')
63 {
64 $description = str_replace("\n", '-nwline-', $post["description"]);
65 $description = sanitize_text_field($description);
66 $description = str_replace('-nwline-', "\n", $description);
67
68 }
69
70 $data = parent::save_fields($data, $post);
71
72 // bypass sanitize for description - causing the end of line-breaks
73 if ($description)
74 $data["basic"]["description"] = $description;
75
76 // bypassing sanitize text field - causes problems with URLs and spaces
77 $url = isset($post["url"]) ? trim($post["url"]) : '';
78
79 $parsed_url = parse_url($url);
80 $rawEncode = array("query","fragment");
81 foreach($rawEncode as $item)
82 {
83 if (isset($parsed_url[$item]))
84 {
85 $parsed_url[$item] = rawurlencode($parsed_url[$item]);
86 }
87 }
88
89 $url = $this->unParseURL($parsed_url);
90
91 $url = str_replace(" ", "%20", trim($url) );
92
93 if (! $this->checkRelative($parsed_url))
94 $url = esc_url_raw($url, $this->protocols); // str replace - known WP issue with spaces
95
96 $data[$this->blockname]["url"] = $url;
97
98 if (isset($post["name"]))
99 $data["name"] = sanitize_text_field($post["name"]);
100 if (isset($post["status"]))
101 $data["status"] = sanitize_text_field($post["status"]); // for conversion old - new.
102 return $data;
103 }
104
105 protected function unparseURL($parsed_url)
106 {
107 // Don't add // to these schemes
108 $noslash_schemes = array('javascript', 'mailto', 'tel', 'sms');
109 if (isset($parsed_url['scheme']) && in_array($parsed_url['scheme'], $noslash_schemes) )
110 $scheme = $parsed_url["scheme"] . ":";
111 else
112 $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
113
114
115 $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
116 $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
117 $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
118 $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
119 $pass = ($user || $pass) ? "$pass@" : '';
120 $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
121 $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
122 $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
123 return "$scheme$user$pass$host$port$path$query$fragment";
124 }
125
126 /* Check for a relative URL that gets killed by esc_url ( if there is no / first ) */
127 protected function checkRelative($parsed_url)
128 {
129 if (! isset($parsed_url['host']) && ! isset($parsed_url['scheme']) )
130 {
131 if (isset($parsed_url['path']) && $parsed_url['path'] !== '' && substr($parsed_url['path'], 0,1) !== '/')
132 {
133 return true;
134 }
135 }
136
137 return false;
138
139 }
140
141 public function parse_button($domObj, $mode = 'normal')
142 {
143
144 $data = $this->data[$this->blockname];
145 $button_id = $this->data["id"];
146
147 $anchor = $domObj->find("a",0);
148
149 if (isset($data["nofollow"]) && $data["nofollow"] == 1)
150 $anchor->rel = "nofollow";
151 // $buttonAttrs[] = "rel=nofollow";
152 if (isset($data["new_window"]) && $data["new_window"] == 1)
153 $anchor->target = "_blank";
154 if (isset($data['link_title']) && strlen($data['link_title']) > 0)
155 $anchor->title = $data['link_title'];
156
157
158 if (isset($data["url"]) && $data["url"] != '')
159 {
160 $url = $data["url"];
161 $parsed_url = parse_url($url);
162
163 if (! $this->checkRelative($parsed_url))
164 $url = esc_url($url, $this->protocols);
165
166 $url = rawurldecode($url); // removes the + from a URL part.
167 $url = apply_filters('mb-url', $url, $data['url']); // passes processed url / raw url.
168 $url = apply_filters('mb-url-' . $button_id, $url, $data['url']);
169
170
171 $anchor->href = $url;
172 //do_shortcode( esc_url($url, $this->protocols) );
173
174 }
175 else // fixing an iOS problem which renders anchors without URL wrongly.
176 {
177 $anchor->href = 'javascript:void(0);';
178 }
179
180
181 return $domObj;
182
183 }
184
185 public function map_fields($map)
186 {
187
188 $map["url"]["attr"] = "href";
189 $map["link_title"]["attr"] = "title";
190
191 // $map["text"]["func"] = "updateAnchorText";
192
193 return $map;
194 }
195
196 public function admin_fields()
197 {
198 //parent::admin_fields();
199
200 //$data = $this->data[$this->blockname];
201 // On it's way out this
202 /*foreach($this->fields as $field => $options)
203 {
204 $default = (isset($options["default"])) ? $options["default"] : '';
205 ${$field} = (isset($data[$field])) ? $data[$field] : $default;
206
207 } */
208 $icon_url = MB()->get_plugin_url() . 'images/icons/' ;
209 ?>
210
211 <div class="mb_tab option-container mb_tab">
212 <div class="title"><?php _e('Basics', 'maxbuttons') ?></div>
213 <div class="inside basic">
214 <?php
215
216 // Name
217 $field_name = new maxField() ;
218 $field_name->label = __('Button Name', 'maxbuttons');
219 // $field_name->note = __('Something that you can quickly identify the button with.', 'maxbuttons');
220 $field_name->value = maxBlocks::getValue('name');
221 $field_name->id = 'name';
222 $field_name->name = $field_name->id;
223 $field_name->placeholder = __("Button Name","maxbuttons");
224 $field_name->output('start','end');
225
226
227 // URL
228 $field_url = new maxField();
229 $field_url->label = __('URL', 'maxbuttons');
230 // $field_url->note = __('The link when the button is clicked.', 'maxbuttons');
231 $field_url->value = rawurldecode(maxBlocks::getValue('url') );
232 $field_url->id = 'url';
233 $field_url->placeholder = __("http://","maxbuttons");
234 $field_url->name = $field_url->id;
235
236 $field_url->output('start','end');
237
238 // Spacer
239 $fspacer = new maxField('spacer');
240 $fspacer->name = 'url_options';
241 $fspacer->label = '&nbsp;';
242 $fspacer->output('start');
243
244
245 // New Window
246 $fwindow = new maxField('checkbox');
247 $fwindow->label = __('Open in New Window', 'maxbuttons');
248 $fwindow->name = 'new_window';
249 $fwindow->id = $fwindow->name;
250 $fwindow->value = 1;
251 //$fwindow->inputclass = 'check_button';
252 $fwindow->checked = checked( maxBlocks::getValue('new_window'), 1, false);
253
254 $fwindow->output('','');
255
256 //$fspacer->name ='rel_options';
257 //$fspacer->output('start');
258
259 // NoRel
260 $ffollow = new maxField('checkbox');
261 $ffollow->label = __('Use rel="nofollow"', 'maxbuttons');
262 $ffollow->value = 1;
263 $ffollow->name = 'nofollow';
264 $ffollow->id = $ffollow->name;
265 $ffollow->checked = checked( maxBlocks::getValue('nofollow'), 1, false);
266
267 $ffollow->output('','end');
268
269 // TITLE
270
271 $field_title = new maxField();
272 $field_title->label = __('Button Title', 'maxbuttons');
273 $field_title->name = 'link_title'; // title is too generic
274 $field_title->id = $field_title->name;
275 $field_title->value = maxBlocks::getValue('link_title');
276
277 $field_title->output('start','end');
278
279 // TEXT
280 $field_text = new maxField();
281 $field_text->label = __('Text','maxbuttons');
282 $field_text->name = 'text';
283 $field_text->id = 'text';
284 $field_text->value = maxBlocks::getValue('text') ;
285
286 $field_text->output('start','end');
287
288 // FONTS
289 $fonts = MB()->getClass('admin')->loadFonts();
290
291 $field_font = new maxField('generic');
292 $field_font->label = __('Font','maxbuttons');
293 $field_font->name = 'font';
294 $field_font->id = $field_font->name;
295 $field_font->value= maxBlocks::getValue('font');
296 $field_font->content = maxUtils::selectify($field_font->name, $fonts, $field_font->value);
297
298 $field_font->output('start');
299 ?>
300
301 <?php
302 // FONT SIZE
303 //global $maxbuttons_font_sizes;
304 $sizes = apply_filters('mb/editor/fontsizes', maxUtils::generate_font_sizes(10,50) );
305
306
307 $field_size = new maxField('number');
308 // $field_size->label = '';
309 $field_size->name = 'font_size';
310 $field_size->id= $field_size->name;
311 $field_size->inputclass = 'tiny';
312 $field_size->min = 8;
313 $field_size->value = maxUtils::strip_px(maxBlocks::getValue('font_size'));
314 //$field_size->content = maxUtils::selectify($field_size->name, $sizes, $field_size->value, '', 'small');
315
316 $field_size->output();
317
318 // Font style checkboxes
319 $fweight = new maxField('checkbox');
320 $fweight->icon = 'dashicons-editor-bold';
321 $fweight->title = __("Bold",'maxbuttons');
322 $fweight->id = 'check_fweight';
323 $fweight->name = 'font_weight';
324 $fweight->value = 'bold';
325 $fweight->inputclass = 'check_button icon';
326 $fweight->checked = checked( maxBlocks::getValue('font_weight'), 'bold', false);
327
328 $fweight->output('group_start');
329
330 $fstyle = new maxField('checkbox');
331 $fstyle->icon = 'dashicons-editor-italic';
332 $fstyle->title = __("Italic",'maxbuttons');
333 $fstyle->id = 'check_fstyle';
334 $fstyle->name = 'font_style';
335 $fstyle->value = 'italic';
336 $fstyle->inputclass = 'check_button icon';
337 $fstyle->checked = checked( maxBlocks::getValue('font_style'), 'italic', false);
338
339 $fstyle->output('','group_end');
340
341
342 $falign_left = new maxField('radio');
343 $falign_left->icon = 'dashicons-editor-alignleft';
344 $falign_left->title = __('Align left','maxbuttons');
345 $falign_left->id = 'radio_talign_left';
346 $falign_left->name = 'text_align';
347 $falign_left->value = 'left';
348 $falign_left->inputclass = 'check_button icon';
349 $falign_left->checked = checked ( maxblocks::getValue('text_align'), 'left', false);
350
351 $falign_left->output('group_start');
352
353 $falign_center = new maxField('radio');
354 $falign_center->icon = 'dashicons-editor-aligncenter';
355 $falign_center->title = __('Align center','maxbuttons');
356 $falign_center->id = 'radio_talign_center';
357 $falign_center->name = 'text_align';
358 $falign_center->value = 'center';
359 $falign_center->inputclass = 'check_button icon';
360 $falign_center->checked = checked( maxblocks::getValue('text_align'), 'center', false);
361
362 $falign_center->output();
363
364 $falign_right = new maxField('radio');
365 $falign_right->icon = 'dashicons-editor-alignright';
366 $falign_right->title = __('Align right','maxbuttons');
367 $falign_right->id = 'radio_talign_right';
368 $falign_right->name = 'text_align';
369 $falign_right->value = 'right';
370 $falign_right->inputclass = 'check_button icon';
371 $falign_right->checked = checked( maxblocks::getValue('text_align'), 'right', false);
372
373 $falign_right->output('', array('group_end','end') );
374
375 // Padding - trouble
376 $ptop = new maxField('number');
377 $ptop->label = __('Padding', 'maxbuttons');
378 $ptop->id = 'padding_top';
379 $ptop->name = $ptop->id;
380 $ptop->min = 0;
381 $ptop->inputclass = 'tiny';
382 $ptop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Padding Top","maxbuttons") . '" >';
383 $ptop->value = maxUtils::strip_px(maxBlocks::getValue('padding_top'));
384
385 $ptop->output('start');
386
387 $pright = new maxField('number');
388 $pright->id = 'padding_right';
389 $pright->name = $pright->id;
390 $pright->min = 0;
391 $pright->inputclass = 'tiny';
392 $pright->before_input = '<img src="' . $icon_url . 'p_right.png" class="icon padding" title="' . __("Padding Right","maxbuttons") . '" >';
393 $pright->value = maxUtils::strip_px(maxBlocks::getValue('padding_right'));
394
395 $pright->output();
396
397 $pbottom = new maxField('number');
398 $pbottom->id = 'padding_bottom';
399 $pbottom->name = $pbottom->id;
400 $pbottom->min = 0;
401 $pbottom->inputclass = 'tiny';
402 $pbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" class="icon padding" title="' . __("Padding Bottom","maxbuttons") . '" >';
403 $pbottom->value = maxUtils::strip_px(maxBlocks::getValue('padding_bottom'));
404
405 $pbottom->output();
406
407 $pleft = new maxField('number');
408 $pleft->id = 'padding_left';
409 $pleft->name = $pleft->id;
410 $pleft->min = 0;
411 $pleft->inputclass = 'tiny';
412 $pleft->before_input = '<img src="' . $icon_url . 'p_left.png" class="icon padding" title="' . __("Padding Left","maxbuttons") . '" >';
413 $pleft->value = maxUtils::strip_px(maxBlocks::getValue('padding_left'));
414
415 $pleft->output('','end');
416
417
418 // Text Color
419 $fcolor = new maxField('color');
420 $fcolor->id = 'text_color';
421 $fcolor->name = $fcolor->id;
422 $fcolor->value = maxBlocks::getColorValue('text_color');
423 $fcolor->label = __('Text Color','maxbuttons');
424 $fcolor->copycolor = true;
425 $fcolor->bindto = 'text_color_hover';
426 $fcolor->copypos = 'right';
427 $fcolor->output('start');
428
429 // Text Color Hover
430 $fcolor_hover = new maxField('color');
431 $fcolor_hover->id = 'text_color_hover';
432 $fcolor_hover->name = $fcolor_hover->id;
433 $fcolor_hover->value = maxBlocks::getColorValue('text_color_hover');
434 $fcolor_hover->label = __('Text Color Hover','maxbuttons');
435 $fcolor_hover->copycolor = true;
436 $fcolor_hover->bindto = $fcolor->id;
437 $fcolor_hover->copypos = 'left';
438 $fcolor_hover->output('','end');
439
440 // Dimension : width
441 $field_width = new maxField('number');
442 $field_width->label = __('Button Width','maxbuttons');
443 $field_width->name = 'button_width';
444 $field_width->id = $field_width->name;
445 $field_width->inputclass = 'small';
446 $field_width->min = 0;
447 $field_width->value= maxUtils::strip_px(maxBlocks::getValue('button_width')); // strippx?
448 $field_width->output('start');
449
450 // Dimension : height
451 $field_height = new maxField('number');
452 $field_height->label = __('Button Height','maxbuttons');
453 $field_height->name = 'button_height';
454 $field_height->id = $field_height->name;
455 $field_height->inputclass = 'small';
456 $field_height->min = 0;
457 $field_height->value= maxUtils::strip_px(maxBlocks::getValue('button_height')); // strippx?
458 $field_height->output('','end');
459
460 // Description
461 $description_hide = get_option('maxbuttons_hidedescription');
462 if ($description_hide == 1)
463 $field_desc = new maxField('hidden');
464 else
465 $field_desc = new maxField('textarea');
466
467 $field_desc->label = __('Description', 'maxbuttons');
468 $field_desc->name = 'description';
469 $field_desc->id = $field_desc->name;
470 $field_desc->esc_function = 'esc_textarea';
471 $field_desc->value = maxBlocks::getValue('description') ;
472 $field_desc->placeholder = __('Brief explanation about how and where the button is used.','maxbuttons');
473 $field_desc->output('start','end');
474
475 ?>
476
477
478 </div>
479 </div>
480 <?php } // admin_display
481
482 } // class
483
484 ?>
485