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 / basic.php

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

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