PluginProbe
MaxButtons – Create buttons / 6.24
MaxButtons – Create buttons v6.24
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.24, at blocks/basic.php

491 lines 16.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'); // 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 $color_copy_self = __("Replace color from other field", "maxbuttons");
216 $color_copy_move = __("Copy Color to other field", "maxbuttons");
217
218 // Name
219 $field_name = new maxField() ;
220 $field_name->label = __('Button Name', 'maxbuttons');
221 // $field_name->note = __('Something that you can quickly identify the button with.', 'maxbuttons');
222 $field_name->value = maxBlocks::getValue('name');
223 $field_name->id = 'name';
224 $field_name->name = $field_name->id;
225 $field_name->placeholder = __("Button Name","maxbuttons");
226 $field_name->output('start','end');
227
228
229 // URL
230 $field_url = new maxField();
231 $field_url->label = __('URL', 'maxbuttons');
232 // $field_url->note = __('The link when the button is clicked.', 'maxbuttons');
233 $field_url->value = rawurldecode(maxBlocks::getValue('url') );
234 $field_url->id = 'url';
235 $field_url->placeholder = __("http://","maxbuttons");
236 $field_url->name = $field_url->id;
237
238 $field_url->output('start','end');
239
240 // Spacer
241 $fspacer = new maxField('spacer');
242 $fspacer->name = 'url_options';
243 $fspacer->label = '&nbsp;';
244 $fspacer->output('start');
245
246
247 // New Window
248 $fwindow = new maxField('checkbox');
249 $fwindow->label = __('Open in New Window', 'maxbuttons');
250 $fwindow->name = 'new_window';
251 $fwindow->id = $fwindow->name;
252 $fwindow->value = 1;
253 //$fwindow->inputclass = 'check_button';
254 $fwindow->checked = checked( maxBlocks::getValue('new_window'), 1, false);
255
256 $fwindow->output('','');
257
258 //$fspacer->name ='rel_options';
259 //$fspacer->output('start');
260
261 // NoRel
262 $ffollow = new maxField('checkbox');
263 $ffollow->label = __('Use rel="nofollow"', 'maxbuttons');
264 $ffollow->value = 1;
265 $ffollow->name = 'nofollow';
266 $ffollow->id = $ffollow->name;
267 $ffollow->checked = checked( maxBlocks::getValue('nofollow'), 1, false);
268
269 $ffollow->output('','end');
270
271 // TITLE
272
273 $field_title = new maxField();
274 $field_title->label = __('Button Title', 'maxbuttons');
275 $field_title->name = 'link_title'; // title is too generic
276 $field_title->id = $field_title->name;
277 $field_title->value = maxBlocks::getValue('link_title');
278
279 $field_title->output('start','end');
280
281 // TEXT
282 $field_text = new maxField();
283 $field_text->label = __('Text','maxbuttons');
284 $field_text->name = 'text';
285 $field_text->id = 'text';
286 $field_text->value = maxBlocks::getValue('text') ;
287
288 $field_text->output('start','end');
289
290 // FONTS
291 $fonts = MB()->getClass('admin')->loadFonts();
292
293 $field_font = new maxField('generic');
294 $field_font->label = __('Font','maxbuttons');
295 $field_font->name = 'font';
296 $field_font->id = $field_font->name;
297 $field_font->value= maxBlocks::getValue('font');
298 $field_font->content = maxUtils::selectify($field_font->name, $fonts, $field_font->value);
299
300 $field_font->output('start');
301 ?>
302
303 <?php
304 // FONT SIZE
305 //global $maxbuttons_font_sizes;
306 $sizes = apply_filters('mb/editor/fontsizes', maxUtils::generate_font_sizes(10,50) );
307
308
309 $field_size = new maxField('number');
310 // $field_size->label = '';
311 $field_size->name = 'font_size';
312 $field_size->id= $field_size->name;
313 $field_size->inputclass = 'tiny';
314 $field_size->min = 8;
315 $field_size->value = maxUtils::strip_px(maxBlocks::getValue('font_size'));
316 //$field_size->content = maxUtils::selectify($field_size->name, $sizes, $field_size->value, '', 'small');
317
318 $field_size->output();
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
332 $fstyle = new maxField('checkbox');
333 $fstyle->icon = 'dashicons-editor-italic';
334 $fstyle->title = __("Italic",'maxbuttons');
335 $fstyle->id = 'check_fstyle';
336 $fstyle->name = 'font_style';
337 $fstyle->value = 'italic';
338 $fstyle->inputclass = 'check_button icon';
339 $fstyle->checked = checked( maxBlocks::getValue('font_style'), 'italic', false);
340
341 $fstyle->output('','group_end');
342
343
344 $falign_left = new maxField('radio');
345 $falign_left->icon = 'dashicons-editor-alignleft';
346 $falign_left->title = __('Align left','maxbuttons');
347 $falign_left->id = 'radio_talign_left';
348 $falign_left->name = 'text_align';
349 $falign_left->value = 'left';
350 $falign_left->inputclass = 'check_button icon';
351 $falign_left->checked = checked ( maxblocks::getValue('text_align'), 'left', false);
352
353 $falign_left->output('group_start');
354
355 $falign_center = new maxField('radio');
356 $falign_center->icon = 'dashicons-editor-aligncenter';
357 $falign_center->title = __('Align center','maxbuttons');
358 $falign_center->id = 'radio_talign_center';
359 $falign_center->name = 'text_align';
360 $falign_center->value = 'center';
361 $falign_center->inputclass = 'check_button icon';
362 $falign_center->checked = checked( maxblocks::getValue('text_align'), 'center', false);
363
364 $falign_center->output();
365
366 $falign_right = new maxField('radio');
367 $falign_right->icon = 'dashicons-editor-alignright';
368 $falign_right->title = __('Align right','maxbuttons');
369 $falign_right->id = 'radio_talign_right';
370 $falign_right->name = 'text_align';
371 $falign_right->value = 'right';
372 $falign_right->inputclass = 'check_button icon';
373 $falign_right->checked = checked( maxblocks::getValue('text_align'), 'right', false);
374
375 $falign_right->output('', array('group_end','end') );
376
377 // Padding - trouble
378 $ptop = new maxField('number');
379 $ptop->label = __('Padding', 'maxbuttons');
380 $ptop->id = 'padding_top';
381 $ptop->name = $ptop->id;
382 $ptop->min = 0;
383 $ptop->inputclass = 'tiny';
384 $ptop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Padding Top","maxbuttons") . '" >';
385 $ptop->value = maxUtils::strip_px(maxBlocks::getValue('padding_top'));
386
387 $ptop->output('start');
388
389 $pright = new maxField('number');
390 $pright->id = 'padding_right';
391 $pright->name = $pright->id;
392 $pright->min = 0;
393 $pright->inputclass = 'tiny';
394 $pright->before_input = '<img src="' . $icon_url . 'p_right.png" class="icon padding" title="' . __("Padding Right","maxbuttons") . '" >';
395 $pright->value = maxUtils::strip_px(maxBlocks::getValue('padding_right'));
396
397 $pright->output();
398
399 $pbottom = new maxField('number');
400 $pbottom->id = 'padding_bottom';
401 $pbottom->name = $pbottom->id;
402 $pbottom->min = 0;
403 $pbottom->inputclass = 'tiny';
404 $pbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" class="icon padding" title="' . __("Padding Bottom","maxbuttons") . '" >';
405 $pbottom->value = maxUtils::strip_px(maxBlocks::getValue('padding_bottom'));
406
407 $pbottom->output();
408
409 $pleft = new maxField('number');
410 $pleft->id = 'padding_left';
411 $pleft->name = $pleft->id;
412 $pleft->min = 0;
413 $pleft->inputclass = 'tiny';
414 $pleft->before_input = '<img src="' . $icon_url . 'p_left.png" class="icon padding" title="' . __("Padding Left","maxbuttons") . '" >';
415 $pleft->value = maxUtils::strip_px(maxBlocks::getValue('padding_left'));
416
417 $pleft->output('','end');
418
419
420 // Text Color
421 $fcolor = new maxField('color');
422 $fcolor->id = 'text_color';
423 $fcolor->name = $fcolor->id;
424 $fcolor->value = maxBlocks::getColorValue('text_color');
425 $fcolor->label = __('Text Color','maxbuttons');
426 $fcolor->copycolor = true;
427 $fcolor->bindto = 'text_color_hover';
428 $fcolor->copypos = 'right';
429 $fcolor->right_title = $color_copy_move;
430 $fcolor->left_title = $color_copy_self;
431 $fcolor->output('start');
432
433 // Text Color Hover
434 $fcolor_hover = new maxField('color');
435 $fcolor_hover->id = 'text_color_hover';
436 $fcolor_hover->name = $fcolor_hover->id;
437 $fcolor_hover->value = maxBlocks::getColorValue('text_color_hover');
438 $fcolor_hover->label = __('Text Color Hover','maxbuttons');
439 $fcolor_hover->copycolor = true;
440 $fcolor_hover->bindto = $fcolor->id;
441 $fcolor_hover->copypos = 'left';
442 $fcolor_hover->right_title = $color_copy_self;
443 $fcolor_hover->left_title = $color_copy_move;
444 $fcolor_hover->output('','end');
445
446 // Dimension : width
447 $field_width = new maxField('number');
448 $field_width->label = __('Button Width','maxbuttons');
449 $field_width->name = 'button_width';
450 $field_width->id = $field_width->name;
451 $field_width->inputclass = 'small';
452 $field_width->min = 0;
453 $field_width->value= maxUtils::strip_px(maxBlocks::getValue('button_width')); // strippx?
454 $field_width->output('start');
455
456 // Dimension : height
457 $field_height = new maxField('number');
458 $field_height->label = __('Button Height','maxbuttons');
459 $field_height->name = 'button_height';
460 $field_height->id = $field_height->name;
461 $field_height->inputclass = 'small';
462 $field_height->min = 0;
463 $field_height->value= maxUtils::strip_px(maxBlocks::getValue('button_height')); // strippx?
464 $field_height->output('','end');
465
466 // Description
467 $description_hide = get_option('maxbuttons_hidedescription');
468 if ($description_hide == 1)
469 $field_desc = new maxField('hidden');
470 else
471 $field_desc = new maxField('textarea');
472
473 $field_desc->label = __('Description', 'maxbuttons');
474 $field_desc->name = 'description';
475 $field_desc->id = $field_desc->name;
476 $field_desc->esc_function = 'esc_textarea';
477 $field_desc->value = maxBlocks::getValue('description') ;
478 $field_desc->placeholder = __('Brief explanation about how and where the button is used.','maxbuttons');
479 $field_desc->output('start','end');
480
481 ?>
482
483
484 </div>
485 </div>
486 <?php } // admin_display
487
488 } // class
489
490 ?>
491