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