PluginProbe
MaxButtons – Create buttons / 7.1.1
MaxButtons – Create buttons v7.1.1
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 7.1.1, at blocks/basic.php

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