| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
use \MaxButtons\maxField as maxField; |
| 6 |
use \MaxButtons\maxUtils as maxUtils; |
| 7 |
|
| 8 |
$collectionBlock["layout"] = array('order' => 40, |
| 9 |
'class' => "layoutBlock" |
| 10 |
); |
| 11 |
|
| 12 |
class layoutBlock extends block |
| 13 |
{ |
| 14 |
protected $blockname = "layout"; |
| 15 |
protected $fields = array( |
| 16 |
"margin_left" => array("default" => "0px", |
| 17 |
"css" => "margin-left", |
| 18 |
"csspart" => "maxsocial"), |
| 19 |
|
| 20 |
"margin_right" => array("default" => "0px", |
| 21 |
"css" => "margin-right", |
| 22 |
"csspart" => "maxsocial"), |
| 23 |
|
| 24 |
"margin_top" => array("default" => "0px", |
| 25 |
"css" => "margin-top", |
| 26 |
"csspart" => "maxsocial"), |
| 27 |
|
| 28 |
"margin_bottom" => array("default" => "0px", |
| 29 |
"css" => "margin-bottom", |
| 30 |
"csspart" => "maxsocial"), |
| 31 |
"orientation" => array("default" => "auto"), |
| 32 |
|
| 33 |
"font" => array("default" => "", |
| 34 |
"css" => "font-family", |
| 35 |
"csspart" => 'mb-label,mb-share-count' |
| 36 |
), |
| 37 |
|
| 38 |
"font_label_size" => array("default" => "15px", |
| 39 |
"css" => "font-size", |
| 40 |
"csspart" => 'mb-label' ), |
| 41 |
|
| 42 |
"font_label_style" => array("default" => "normal", |
| 43 |
"css" => "font-style", |
| 44 |
"csspart" => 'mb-label'), |
| 45 |
|
| 46 |
"font_label_weight" => array("default" => "normal", |
| 47 |
"css" => "font-weight", |
| 48 |
"csspart" => 'mb-label'), |
| 49 |
|
| 50 |
"font_label_upper" => array('default' => 'none', |
| 51 |
'css' => 'text-transform', |
| 52 |
'csspart' => 'mb-label', |
| 53 |
), |
| 54 |
|
| 55 |
"font_icon_size" => array("default" => "15px", |
| 56 |
"css" => "font-size", |
| 57 |
"csspart" => 'mb-icon' ), |
| 58 |
|
| 59 |
"font_icon_style" => array("default" => "normal", |
| 60 |
"css" => "font-style", |
| 61 |
"csspart" => 'mb-icon'), |
| 62 |
|
| 63 |
"font_icon_weight" => array("default" => "normal", |
| 64 |
"css" => "font-weight", |
| 65 |
"csspart" => 'mb-icon'), |
| 66 |
|
| 67 |
'use_background' => array('default' => 1, ), |
| 68 |
'background_color' => array('default' => '#000', |
| 69 |
'css' => 'background-color', |
| 70 |
'csspart' => 'mb-social', |
| 71 |
), |
| 72 |
'background_color_hover' => array('default' => '#000', |
| 73 |
'css' => 'background-color', |
| 74 |
'csspart' => 'mb-social', |
| 75 |
'csspseudo' => 'hover', |
| 76 |
), |
| 77 |
'color' => array('default' => '#fff', |
| 78 |
'css' => 'color', |
| 79 |
'csspart' => 'mb-icon,mb-share-count,mb-label'), |
| 80 |
'color_hover' => array('default' => '#fff', |
| 81 |
'css' => 'color', |
| 82 |
'csspart' => 'mb-icon,mb-share-count,mb-label', |
| 83 |
'csspseudo' => 'hover'), |
| 84 |
|
| 85 |
|
| 86 |
"button_spacing" => array('default' => '5', |
| 87 |
), |
| 88 |
"ignore_container" => array("default" => 1), |
| 89 |
|
| 90 |
|
| 91 |
); |
| 92 |
|
| 93 |
public function __construct() |
| 94 |
{ |
| 95 |
parent::__construct(); |
| 96 |
|
| 97 |
if (Install::isPro()) |
| 98 |
add_filter('mbsocial/displaycss/', array($this, 'addWebFont') ); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
public function addWebFont($css) |
| 103 |
{ |
| 104 |
$fonts = ''; |
| 105 |
|
| 106 |
if ( isset ($this->data[$this->blockname]['webfonts'])) |
| 107 |
{ |
| 108 |
|
| 109 |
$webfonts = $this->data[$this->blockname]['webfonts']; |
| 110 |
$fonts .= '@import url(' . $webfonts . ');'; |
| 111 |
|
| 112 |
} |
| 113 |
return $fonts . $css; |
| 114 |
} |
| 115 |
|
| 116 |
function parseCSS($css, $args) |
| 117 |
{ |
| 118 |
$css = parent::parseCSS($css, $args); |
| 119 |
$w = MBSocial()->whistle(); |
| 120 |
|
| 121 |
$hook = $this->collection->getHook(); |
| 122 |
$blockdata = $this->data[$this->blockname]; |
| 123 |
|
| 124 |
$network = $this->network; |
| 125 |
|
| 126 |
// if true, use network colors |
| 127 |
$use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false; |
| 128 |
|
| 129 |
if ($use_background) |
| 130 |
{ |
| 131 |
unset ($css['mb-social']['normal']['background-color']); |
| 132 |
unset ($css['mb-social']['hover']['background-color']); |
| 133 |
|
| 134 |
$color = $network->get('color'); |
| 135 |
|
| 136 |
$css['mb-social']['normal']['background-color'] = $color; |
| 137 |
$css['mb-social']['hover']['background-color'] = "darken($color, 10%)"; |
| 138 |
} |
| 139 |
|
| 140 |
$css["mb-item"]["normal"]["float"] = "left"; |
| 141 |
$css["mb-item"]["normal"]["display"] = "inline-block"; |
| 142 |
$css["mb-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action. |
| 143 |
$css['mb-item a']['normal']['text-decoration'] = 'none'; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
if (isset($blockdata['button_spacing']) && $blockdata['button_spacing'] > 0) |
| 148 |
{ |
| 149 |
$orientation = $this->collection->orientation; |
| 150 |
$is_static = $w->ask('display/env/is_static'); |
| 151 |
|
| 152 |
$button_spacing = $blockdata['button_spacing']; |
| 153 |
|
| 154 |
if ($orientation == 'horizontal') |
| 155 |
{ |
| 156 |
$css['mb-item']['normal']['margin-right'] = $button_spacing . 'px'; |
| 157 |
} |
| 158 |
if ($orientation == 'vertical') |
| 159 |
{ |
| 160 |
$css['mb-item']['normal']['margin-bottom'] = $button_spacing . 'px'; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
// Check font again. |
| 165 |
if (Install::isPro()) |
| 166 |
{ |
| 167 |
//var_dump($css); |
| 168 |
$blockdata = $this->data[$this->blockname]; |
| 169 |
$font = $blockdata['font']; |
| 170 |
$args = array('font' => $font); |
| 171 |
$webfont = patches::checkWebFonts($args); |
| 172 |
$this->data[$this->blockname]['webfonts'] = $webfont; |
| 173 |
} |
| 174 |
|
| 175 |
return $css; |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
public function parse($itemObj, $args = array() ) |
| 180 |
{ |
| 181 |
$blockdata = $this->data[$this->blockname]; |
| 182 |
|
| 183 |
$use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false; |
| 184 |
|
| 185 |
return $itemObj; |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
function save_fields($data, $post) |
| 190 |
{ |
| 191 |
$data = parent::save_fields($data, $post); |
| 192 |
if (! isset($post["ignore_container"]) && ! is_null($post)) |
| 193 |
$data[$this->blockname]["ignore_container"] = 0; |
| 194 |
if (! isset($post['use_background']) && ! is_null($post)) |
| 195 |
$data[$this->blockname]['use_background'] = 0; |
| 196 |
|
| 197 |
if ( count ($post) == 0) |
| 198 |
return $data; // don't run on default situations |
| 199 |
|
| 200 |
// Do the font here |
| 201 |
$blockdata = $data[$this->blockname]; |
| 202 |
$font = $blockdata['font']; |
| 203 |
//$label_weight = $blockdata['font_label_weight']; |
| 204 |
// $icon_weight = $blockdata['icon_label_weight']; |
| 205 |
|
| 206 |
$args = array('font' => $font); |
| 207 |
|
| 208 |
$webfont = patches::checkWebFonts($args); |
| 209 |
$data[$this->blockname]['webfonts'] = $webfont; |
| 210 |
|
| 211 |
return $data; |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
function fontModal() |
| 216 |
{ |
| 217 |
?> |
| 218 |
<div class='maxmodal-data' id='add-fonts' data-load='window.maxFoundry.maxfonts.load' data-height='90%'> |
| 219 |
<span class='title'><?php _e("Font Manager","maxbuttons-pro"); ?> |
| 220 |
|
| 221 |
</span> |
| 222 |
|
| 223 |
<span class='content'> |
| 224 |
<p><?php printf(__("Select from %s fonts you would like to use and they will show up in the dropdown list", 'maxbuttons-pro'), '<span class="fontcount"></span>'); ?></p> |
| 225 |
<div class="loading_overlay"></div> |
| 226 |
<div class='loading'> |
| 227 |
<img src="<?php echo MB()->get_plugin_url(false) ?>images/spinner.gif"> |
| 228 |
<span><?php _e("Loading","maxbuttons-pro"); ?></span> |
| 229 |
</div> |
| 230 |
<div class="font_manager"> |
| 231 |
<div class='font_search'> <span><?php _e("Search","maxbuttons-pro") ?></span> |
| 232 |
<input type='text' name='font_search' value='' /> |
| 233 |
</div> |
| 234 |
|
| 235 |
<div class="font_wrap"> |
| 236 |
<div class='font_left'> |
| 237 |
<ul class='items'> |
| 238 |
|
| 239 |
</ul> |
| 240 |
</div> |
| 241 |
<div class='font_right '> |
| 242 |
<ul class='items'> |
| 243 |
|
| 244 |
</ul> |
| 245 |
</div> |
| 246 |
</div> |
| 247 |
<div class='font_example'> |
| 248 |
<span class='placeholder'><?php _e("Click on a font to see an example","maxbuttons-pro"); ?></span> |
| 249 |
<span class='example_text'><?php _e("AaBbCcDdEeFfGgEeHh") ?></span> |
| 250 |
</div> |
| 251 |
</div> |
| 252 |
</span> |
| 253 |
<div class='controls'> |
| 254 |
<div class='controls_inline'> |
| 255 |
<button type='button' name='save_fonts' class='button-primary'><?php _e("Save changes", 'maxbuttons-pro'); ?></button> |
| 256 |
<button type='button' class='button-primary modal_close'><?php _e("Close","maxbuttons-pro"); ?></button> |
| 257 |
</div> |
| 258 |
</div> |
| 259 |
</div> <!-- maxmodal-data --> |
| 260 |
<?php |
| 261 |
} |
| 262 |
|
| 263 |
function admin() |
| 264 |
{ |
| 265 |
$admin = mbSocial()->admin(); |
| 266 |
|
| 267 |
?> |
| 268 |
|
| 269 |
<div class='options option-container layout' id='layoutBlock' data-refresh='previewBlock' > |
| 270 |
<div class='title'><?php _e('Customization', 'mbsocial' ); ?></div> |
| 271 |
<div class='inside'> |
| 272 |
<?php |
| 273 |
|
| 274 |
$colorsw = new maxField('switch'); |
| 275 |
$colorsw->label = __('Use solid colors','mbsocial'); |
| 276 |
$colorsw->id = 'use_background'; |
| 277 |
$colorsw->value = 1; |
| 278 |
$colorsw->name = $colorsw->id; |
| 279 |
$colorsw->inputclass = 'update_change'; |
| 280 |
$colorsw->checked = checked( $this->getValue('use_background'), 1, false); |
| 281 |
$admin->addField( $colorsw, 'start', ''); |
| 282 |
|
| 283 |
|
| 284 |
$ispacer = new maxField('spacer'); |
| 285 |
$ispacer->label = __('Use Social Network Brand Colors','mbsocial'); |
| 286 |
$ispacer->publish = false; |
| 287 |
$ispacer->output('','end'); |
| 288 |
|
| 289 |
$admin->addField($ispacer, '', 'end', false); |
| 290 |
|
| 291 |
$bgcolor = new maxField('color') ; |
| 292 |
$bgcolor->label = __('Background color', 'mbsocial'); |
| 293 |
$bgcolor->value = $this->getColorValue('background_color'); |
| 294 |
$bgcolor->id = 'background_color'; |
| 295 |
$bgcolor->name = $bgcolor->id; |
| 296 |
$admin->addField($bgcolor, 'start', ''); |
| 297 |
|
| 298 |
$bgcolor_hover = new maxField('color'); |
| 299 |
$bgcolor_hover->label = __('Background Hover', 'mbsocial'); |
| 300 |
$bgcolor_hover->value = $this->getColorValue('background_color_hover'); |
| 301 |
$bgcolor_hover->id = 'background_color_hover'; |
| 302 |
$bgcolor_hover->name = $bgcolor_hover->id; |
| 303 |
$admin->addField( $bgcolor_hover, '', 'end'); |
| 304 |
|
| 305 |
$color = new maxField('color'); |
| 306 |
$color->label = __('Color', 'mbsocial'); |
| 307 |
$color->value = $this->getColorValue('color'); |
| 308 |
$color->id = 'color'; |
| 309 |
$color->name = $color->id; |
| 310 |
$admin->addField($color, 'start', ''); |
| 311 |
|
| 312 |
$color_hover = new maxField('color'); |
| 313 |
$color_hover->label = __('Hover', 'mbsocial'); |
| 314 |
$color_hover->value = $this->getColorValue('color_hover'); |
| 315 |
$color_hover->id = 'color_hover'; |
| 316 |
$color_hover->name = $color_hover->id; |
| 317 |
$admin->addField( $color_hover, '', 'end'); |
| 318 |
|
| 319 |
// FONTS |
| 320 |
/* $button = new maxField('generic'); |
| 321 |
$button->label = ''; |
| 322 |
$button->id = 'manage-fonts'; |
| 323 |
$button->name = 'button_fonts'; |
| 324 |
$button->content = '<div id="manage-fonts" class="button manage-fonts maxmodal" data-modal="add-fonts" title="' . __("Add additional fonts","maxbuttons-pro") . '" ><i class="dashicons dashicons-editor-spellcheck"></i>' . __('Font Manager', 'maxbuttons-pro') . '</div>'; |
| 325 |
$admin->addField($button, 'start', 'end'); |
| 326 |
*/ |
| 327 |
$fonts = MB()->getClass('admin')->loadFonts(); |
| 328 |
|
| 329 |
$field_font = new maxField('generic'); |
| 330 |
$field_font->label = __('Font Family','maxbuttons'); |
| 331 |
$field_font->name = 'font'; |
| 332 |
$field_font->id = $field_font->name; |
| 333 |
$field_font->value= $this->getValue('font'); |
| 334 |
$field_font->content = maxUtils::selectify($field_font->name, $fonts, $field_font->value); |
| 335 |
$admin->addField($field_font,'start', 'end'); |
| 336 |
?> |
| 337 |
|
| 338 |
<?php |
| 339 |
// FONT SIZE |
| 340 |
//global $maxbuttons_font_sizes; |
| 341 |
//$sizes = apply_filters('mb/editor/fontsizes', maxUtils::generate_font_sizes(10,50) ); |
| 342 |
|
| 343 |
// *** LABEL SIZE *** // |
| 344 |
$field_size = new maxField('number'); |
| 345 |
$field_size->label = __('Label Size', 'mbsocial'); |
| 346 |
$field_size->name = 'font_label_size'; |
| 347 |
$field_size->id= $field_size->name; |
| 348 |
$field_size->inputclass = 'tiny'; |
| 349 |
$field_size->min = 8; |
| 350 |
$field_size->value = maxUtils::strip_px($this->getValue('font_label_size')); |
| 351 |
$admin->addField($field_size, 'start'); |
| 352 |
|
| 353 |
// Font style checkboxes |
| 354 |
$fweight = new maxField('checkbox'); |
| 355 |
$fweight->icon = 'dashicons-editor-bold'; |
| 356 |
$fweight->title = __("Bold",'mbsocial'); |
| 357 |
$fweight->id = 'check_label_fweight'; |
| 358 |
$fweight->name = 'font_label_weight'; |
| 359 |
$fweight->value = 'bold'; |
| 360 |
$fweight->inputclass = 'check_button icon'; |
| 361 |
$fweight->checked = checked( $this->getValue('font_label_weight'), 'bold', false); |
| 362 |
$admin->addField($fweight, 'group_start'); |
| 363 |
|
| 364 |
$fstyle = new maxField('checkbox'); |
| 365 |
$fstyle->icon = 'dashicons-editor-italic'; |
| 366 |
$fstyle->title = __("Italic",'mbsocial'); |
| 367 |
$fstyle->id = 'check_label_fstyle'; |
| 368 |
$fstyle->name = 'font_label_style'; |
| 369 |
$fstyle->value = 'italic'; |
| 370 |
$fstyle->inputclass = 'check_button icon'; |
| 371 |
$fstyle->checked = checked( $this->getValue('font_label_style'), 'italic', false); |
| 372 |
$admin->addField($fstyle); |
| 373 |
|
| 374 |
$fupper = new maxField('checkbox'); |
| 375 |
$fupper->icon = 'dashicons-arrow-up'; |
| 376 |
$fupper->title = __('Uppercase', 'mbsocial'); |
| 377 |
$fupper->id = 'check_label_fupper'; |
| 378 |
$fupper->name = 'font_label_upper'; |
| 379 |
$fupper->value = 'uppercase'; |
| 380 |
$fupper->inputclass = 'check_button icon'; |
| 381 |
$fupper->checked = checked ( $this->getValue('font_label_upper'), 'uppercase', false); |
| 382 |
|
| 383 |
$admin->addField($fupper, '', array('group_end', 'end')); |
| 384 |
|
| 385 |
// *** ICON SIZE *** // |
| 386 |
$field_size = new maxField('number'); |
| 387 |
$field_size->label = __('Icon Size', 'mbsocial'); |
| 388 |
$field_size->name = 'font_icon_size'; |
| 389 |
$field_size->id= $field_size->name; |
| 390 |
$field_size->inputclass = 'tiny'; |
| 391 |
$field_size->min = 8; |
| 392 |
$field_size->value = maxUtils::strip_px($this->getValue('font_icon_size')); |
| 393 |
$admin->addField($field_size, 'start'); |
| 394 |
|
| 395 |
// Font style checkboxes |
| 396 |
$fweight = new maxField('checkbox'); |
| 397 |
$fweight->icon = 'dashicons-editor-bold'; |
| 398 |
$fweight->title = __("Bold",'mbsocial'); |
| 399 |
$fweight->id = 'check_icon_fweight'; |
| 400 |
$fweight->name = 'font_icon_weight'; |
| 401 |
$fweight->value = 'bold'; |
| 402 |
$fweight->inputclass = 'check_button icon'; |
| 403 |
$fweight->checked = checked( $this->getValue('font_icon_weight'), 'bold', false); |
| 404 |
$admin->addField($fweight, 'group_start'); |
| 405 |
|
| 406 |
$fstyle = new maxField('checkbox'); |
| 407 |
$fstyle->icon = 'dashicons-editor-italic'; |
| 408 |
$fstyle->title = __("Italic",'mbsocial'); |
| 409 |
$fstyle->id = 'check_icon_fstyle'; |
| 410 |
$fstyle->name = 'font_icon_style'; |
| 411 |
$fstyle->value = 'italic'; |
| 412 |
$fstyle->inputclass = 'check_button icon'; |
| 413 |
$fstyle->checked = checked( $this->getValue('font_icon_style'), 'italic', false); |
| 414 |
$admin->addField($fstyle, '', array('group_end', 'end')); |
| 415 |
|
| 416 |
|
| 417 |
// Margins |
| 418 |
$icon_url = MB()->get_plugin_url() . 'images/icons/' ; |
| 419 |
|
| 420 |
$mtop = new maxField('number'); |
| 421 |
$mtop->publish = false; |
| 422 |
$mtop->label = __('Margin top', 'mbsocial'); |
| 423 |
$mtop->id = 'margin_top'; |
| 424 |
$mtop->name = $mtop->id; |
| 425 |
$mtop->min = 0; |
| 426 |
$mtop->inputclass = 'tiny'; |
| 427 |
$mtop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Margin Top","mbsocial") . '" >'; |
| 428 |
$mtop->value = maxUtils::strip_px($this->getValue('margin_top')); |
| 429 |
|
| 430 |
//$mtop->output('start'); |
| 431 |
$admin->addField($mtop, 'start','', false); |
| 432 |
|
| 433 |
$mbottom = new maxField('number'); |
| 434 |
$mbottom->label = __('Margin Bottom', 'mbsocial'); |
| 435 |
$mbottom->id = 'margin_bottom'; |
| 436 |
$mbottom->name = $mbottom->id; |
| 437 |
$mbottom->min = 0; |
| 438 |
$mbottom->inputclass = 'tiny'; |
| 439 |
$mbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" title="' . __("Margin Bottom","mbsocial") . '" >'; |
| 440 |
$mbottom->value = maxUtils::strip_px($this->getValue('margin_bottom') ); |
| 441 |
|
| 442 |
$admin->addField( $mbottom, '', 'end', false ); |
| 443 |
|
| 444 |
$mleft = new maxField('number'); |
| 445 |
$mleft->label = __('Margin Left', 'mbsocial'); |
| 446 |
$mleft->id = 'margin_left'; |
| 447 |
$mleft->name = $mleft->id; |
| 448 |
$mleft->min = 0; |
| 449 |
$mleft->inputclass = 'tiny'; |
| 450 |
$mleft->before_input = '<img src="' . $icon_url . 'p_left.png" title="' . __("Margin Left","mbsocial") . '" >'; |
| 451 |
$mleft->value = maxUtils::strip_px($this->getValue('margin_left')); |
| 452 |
|
| 453 |
$admin->addField( $mleft,'start', '', false); |
| 454 |
|
| 455 |
$mright = new maxField('number'); |
| 456 |
$mright->label = __('Margin Right', 'mbsocial'); |
| 457 |
$mright->id = 'margin_right'; |
| 458 |
$mright->name = $mright->id; |
| 459 |
$mright->min = 0; |
| 460 |
$mright->inputclass = 'tiny'; |
| 461 |
$mright->before_input = '<img src="' . $icon_url . 'p_right.png" title="' . __("Margin Right","mbsocial") . '" >'; |
| 462 |
$mright->value = maxUtils::strip_px($this->getValue('margin_right')); |
| 463 |
|
| 464 |
$admin->addField( $mright, '', 'end', false); |
| 465 |
|
| 466 |
// Spacing |
| 467 |
|
| 468 |
$spacing = new maxField('number'); |
| 469 |
$spacing->label = __('Button Spacing', 'mbsocial'); |
| 470 |
$spacing->id = 'button_spacing'; |
| 471 |
$spacing->name = $spacing->id; |
| 472 |
$spacing->min = 0; |
| 473 |
$spacing->inputclass = 'tiny'; |
| 474 |
$spacing->value = maxUtils::strip_px($this->getValue('button_spacing')); |
| 475 |
|
| 476 |
$admin->addUpdate($spacing); |
| 477 |
$admin->addField($spacing, 'start', 'end'); |
| 478 |
|
| 479 |
$admin->display_fields(); |
| 480 |
?> |
| 481 |
</div> <!-- inside --> |
| 482 |
</div> <!-- option container --> |
| 483 |
|
| 484 |
|
| 485 |
<?php $this->fontModal(); ?> |
| 486 |
|
| 487 |
<?php |
| 488 |
} // admin |
| 489 |
|
| 490 |
} |
| 491 |
|