| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
use \MaxButtons\maxField as maxField; |
| 6 |
use \MaxButtons\maxBlocks as maxBlocks; |
| 7 |
|
| 8 |
$collectionBlock["display"] = array('class' => "displayBlock", |
| 9 |
'order' => 25); |
| 10 |
|
| 11 |
class displayBlock extends block |
| 12 |
{ |
| 13 |
protected $blockname = "display"; |
| 14 |
protected $fields = array( |
| 15 |
'display_page' => array('default' => 'hidden'), |
| 16 |
'display_page_options' => array('default' => array()), |
| 17 |
'display_post' => array('default' => 'hidden'), |
| 18 |
'display_post_options' => array('default' => array()), |
| 19 |
'display_homepage' => array('default' => 'hidden'), |
| 20 |
'display_homepage_options' => array('default' => array()), |
| 21 |
'display_archive' => array('default' => 'hidden'), |
| 22 |
'display_archive_options' => array('default' => array()), |
| 23 |
'show_desktop' => array('default' => 1), |
| 24 |
'show_mobile' => array('default' => 1), |
| 25 |
); |
| 26 |
|
| 27 |
/*protected $meta_fields = array( |
| 28 |
'display_here' => array('default' => 1 ) |
| 29 |
); |
| 30 |
*/ |
| 31 |
|
| 32 |
/* |
| 33 |
function __construct() |
| 34 |
{ |
| 35 |
|
| 36 |
} |
| 37 |
*/ |
| 38 |
|
| 39 |
function save_fields($data, $post) |
| 40 |
{ |
| 41 |
$data = parent::save_fields($data, $post); |
| 42 |
$blockdata = $data[$this->blockname]; |
| 43 |
|
| 44 |
$post_types = $this->get_post_types(); |
| 45 |
|
| 46 |
$save_global = array('display_page', 'display_post', 'display_homepage', 'display_archive'); |
| 47 |
$save_options = array('display_page_options', 'display_post_options', 'display_homepage_options', 'display_archive_options'); |
| 48 |
|
| 49 |
// check google block realsave as well. Implement this on the main form? Should be there. |
| 50 |
if (! isset($post['show_desktop']) && isset($post['form_post'])) |
| 51 |
$blockdata['show_desktop'] = 0; |
| 52 |
|
| 53 |
if (! isset($post['show_mobile']) && isset($post['form_post'])) |
| 54 |
$blockdata['show_mobile'] = 0; |
| 55 |
|
| 56 |
|
| 57 |
foreach($post_types as $post_type) |
| 58 |
{ |
| 59 |
if (isset($post['display_' . $post_type])) |
| 60 |
{ |
| 61 |
$field_name = 'display_' . $post_type; |
| 62 |
|
| 63 |
$display = sanitize_text_field($post[$field_name]); |
| 64 |
$options = isset($post[$field_name . '_options']) ? $post['display_' . $post_type . '_options'] : array(); |
| 65 |
|
| 66 |
$blockdata[$field_name] = $display; |
| 67 |
$blockdata[$field_name . '_options'] = $options; |
| 68 |
|
| 69 |
if (in_array($field_name, $save_global) === false) { |
| 70 |
$save_global[] = $field_name; |
| 71 |
} |
| 72 |
if ( in_array($field_name . '_options', $save_options) === false) |
| 73 |
{ |
| 74 |
$save_options[] = $field_name . '_options'; |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
foreach($save_global as $field_name) |
| 82 |
{ |
| 83 |
|
| 84 |
$data[$field_name] = $blockdata[$field_name]; |
| 85 |
unset($blockdata[$field_name]); |
| 86 |
} |
| 87 |
|
| 88 |
foreach ($save_options as $option) |
| 89 |
{ |
| 90 |
|
| 91 |
if ( is_string($blockdata[$option]) && strlen($blockdata[$option]) > 0) |
| 92 |
{ |
| 93 |
$blockdata[$option] = json_decode($blockdata[$option], true); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
$data[$this->blockname] = $blockdata; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
return $data; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** Get usable, front-end, custom post types **/ |
| 106 |
public function get_post_types() |
| 107 |
{ |
| 108 |
return \get_post_types( |
| 109 |
array('public' => true, |
| 110 |
'_builtin' => false, |
| 111 |
) |
| 112 |
); |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
public function parseCSS($css, $args) |
| 117 |
{ |
| 118 |
$blockdata = $this->data[$this->blockname]; |
| 119 |
//$button_spacing = $this->data["button_spacing"]; |
| 120 |
|
| 121 |
$hook = $this->collection->getHook(); |
| 122 |
|
| 123 |
$options = isset($blockdata[$hook . "_options"]) ? $blockdata[$hook . '_options'] : array(); |
| 124 |
$display = isset($this->data[$hook]) ? $this->data[$hook] : 'hidden'; |
| 125 |
|
| 126 |
//$position_x = isset($options['position_x']) ? $options['position_x'] : 'auto'; |
| 127 |
//$position_y = isset($options['position_y']) ? $options['position_y'] : 'auto'; |
| 128 |
|
| 129 |
$position = isset($options['position']) ? $options['position'] : false; |
| 130 |
|
| 131 |
$fixed = isset($options['fixed_position'] ) ? $options['fixed_position'] : false; |
| 132 |
|
| 133 |
$orientation = $this->collection->orientation; |
| 134 |
$is_static = $this->collection->is_static; |
| 135 |
$is_post = $this->collection->is_post; |
| 136 |
|
| 137 |
/// $css["mb-item"]["normal"]["float"] = 'left'; |
| 138 |
|
| 139 |
// Decide which auto values go with the default settings of the other dimensions. |
| 140 |
|
| 141 |
if ($position && $is_static) |
| 142 |
{ |
| 143 |
list($position_y, $position_x) = explode("_", $position); |
| 144 |
|
| 145 |
} |
| 146 |
elseif($position && $is_post) |
| 147 |
{ |
| 148 |
$position_x = $position; |
| 149 |
$position_y = false; |
| 150 |
} |
| 151 |
else { |
| 152 |
if ($is_static) |
| 153 |
{ |
| 154 |
$position_x = 'left'; |
| 155 |
$position_y = 'center'; |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
$position_x = 'center'; |
| 160 |
$position_y = false; |
| 161 |
} |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
switch($orientation) |
| 166 |
{ |
| 167 |
case "horizontal": |
| 168 |
$css["mb-item:last-child"]["normal"]["margin-right"] = "0"; |
| 169 |
break; |
| 170 |
|
| 171 |
case "vertical"; |
| 172 |
$css["mb-item"]["normal"]["clear"] = "both"; |
| 173 |
$css['maxsocial']['normal']['width'] = 'auto'; |
| 174 |
break; |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
if ($args["preview"] == true) |
| 179 |
return $css; // don't process move than this in preview. |
| 180 |
|
| 181 |
if ($is_static) // static options |
| 182 |
{ |
| 183 |
// if ($orientation == 'vertical') |
| 184 |
$css['maxsocial']['normal']['width'] = 'auto'; |
| 185 |
|
| 186 |
if ($fixed == 1) |
| 187 |
$css['maxsocial']['normal']['position'] = 'fixed'; |
| 188 |
else |
| 189 |
$css['maxsocial']['normal']['position'] = 'absolute'; |
| 190 |
|
| 191 |
|
| 192 |
switch($position_x) |
| 193 |
{ |
| 194 |
case "left": |
| 195 |
case "right": |
| 196 |
// left or right |
| 197 |
$css["maxsocial"]["normal"][$position_x] = '0'; |
| 198 |
break; |
| 199 |
|
| 200 |
case "center": |
| 201 |
$css['maxsocial']['normal']['left'] = '50%'; |
| 202 |
$css['maxsocial']['normal']['transform'] = 'translateX(-50%)'; |
| 203 |
break; |
| 204 |
} |
| 205 |
|
| 206 |
switch($position_y) |
| 207 |
{ |
| 208 |
case "center": |
| 209 |
$css["maxsocial"]["normal"]["top"] = "50%"; |
| 210 |
if ( isset($css['maxsocial']['normal']['transform'])) // set by x |
| 211 |
{ |
| 212 |
$css['maxsocial']['normal']['transform'] = 'translate(-50%,-50%)'; |
| 213 |
} |
| 214 |
else |
| 215 |
$css["maxsocial"]["normal"]["transform"] = "translateY(-50%)"; |
| 216 |
break; |
| 217 |
case 'top': |
| 218 |
$css['maxsocial']['normal']['top'] = 0; |
| 219 |
break; |
| 220 |
case "bottom": |
| 221 |
$css["maxsocial"]["normal"]["bottom"] = "0"; |
| 222 |
break; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
} // is_static |
| 227 |
/* elseif ($is_post) |
| 228 |
{ |
| 229 |
|
| 230 |
} */ |
| 231 |
|
| 232 |
return $css; |
| 233 |
} |
| 234 |
|
| 235 |
protected function expert_admin() |
| 236 |
{ |
| 237 |
$admin = mbSocial()->admin(); |
| 238 |
|
| 239 |
$data = $this->data; |
| 240 |
$blockdata = $this->data[$this->blockname]; |
| 241 |
|
| 242 |
/* |
| 243 |
$staticIcons = array( |
| 244 |
'auto' => 'icon_auto.png', |
| 245 |
'left' => 'icon_posleft.png', |
| 246 |
'right' => 'icon_posright.png', |
| 247 |
'center' => 'icon_poscenter.png', |
| 248 |
'top' => 'icon_postop.png', |
| 249 |
'bottom' => 'icon_posbottom.png', |
| 250 |
'horizontal' => 'icon_horizontal.png', |
| 251 |
'vertical' => 'icon_vertical.png', |
| 252 |
); |
| 253 |
*/ |
| 254 |
$icon_url = MBSocial()->get_plugin_url() . 'images/icons/'; |
| 255 |
/*$option_icons = array( |
| 256 |
'hidden' => 'icon_manual.png', |
| 257 |
'before' => 'icon_before.png', |
| 258 |
'after' => 'icon_after.png', |
| 259 |
'after-before' => 'icon_both.png', |
| 260 |
'static' => 'icon_absolute.png' |
| 261 |
); */ |
| 262 |
|
| 263 |
$options = array( |
| 264 |
'hidden' => __('Manual / Do not show', 'mbsocial'), |
| 265 |
'before' => __('Before post content','mbsocial'), |
| 266 |
'after' => __('After post content', 'mbsocial'), |
| 267 |
'after-before' => __('Before and after the post content', 'mbsocial'), |
| 268 |
'static' => __('Absolute Position', 'mbsocial'), |
| 269 |
); |
| 270 |
|
| 271 |
$conditional_options = $options; |
| 272 |
unset($conditional_options['hidden']); // all minus hidden |
| 273 |
$conditional_options = array_keys($conditional_options); |
| 274 |
|
| 275 |
|
| 276 |
$option_button = new maxField('button'); |
| 277 |
$option_button->modal = 'modal_options'; |
| 278 |
$option_button->button_label = __("Options",'mbsocial'); |
| 279 |
$option_button->name = 'options'; |
| 280 |
$option_button->inputclass = 'maxmodal'; |
| 281 |
|
| 282 |
$gen = new maxField('generic'); |
| 283 |
$title_off = __('Off / Manual - Hide on this view. You can add it manually via the shortcode', 'mbsocial'); |
| 284 |
$title_content = __('Display around the post content', 'mbsocial'); |
| 285 |
$title_float = __('Display static / floating at the screen. Configure position via options', 'mbsocial'); |
| 286 |
|
| 287 |
$gen->content = '<span title="' . $title_off . '">' . __('Off', 'mbsocial') . '</span> |
| 288 |
<span title="' . $title_content . '">' . __('Content','mbsocial') . '</span> |
| 289 |
<span title="' . $title_float . '">' . __('Float','mbsocial') . '</span>'; |
| 290 |
|
| 291 |
$gen->name = 'display_heading'; |
| 292 |
$admin->addField($gen,'start','end'); |
| 293 |
|
| 294 |
$genrow = new maxField('generic'); |
| 295 |
$genrow->content = '<span>Top</span><span>Bottom</span><span>Both</span>'; |
| 296 |
$genrow->name = 'display_rowhead'; |
| 297 |
|
| 298 |
$admin->addField($genrow, 'start','end'); |
| 299 |
|
| 300 |
// ** HOMEPAGE |
| 301 |
$fspacer = new maxField('spacer'); |
| 302 |
$fspacer->label = __('Homepage', 'mbsocial'); |
| 303 |
$fspacer->name = 'spacer'; |
| 304 |
$fspacer->main_class = 'option display_group'; |
| 305 |
|
| 306 |
$admin->addField($fspacer, 'start'); |
| 307 |
|
| 308 |
$i =0; |
| 309 |
foreach($options as $option => $label) |
| 310 |
{ |
| 311 |
$display = new maxField('radio'); |
| 312 |
$display->id = 'radio_display_homepage_' . $option; |
| 313 |
$display->name = 'display_homepage'; |
| 314 |
$display->title = $label; |
| 315 |
$display->value = $option; |
| 316 |
|
| 317 |
//$display->image = $icon_url . $option_icons[$option]; |
| 318 |
$display->custom_icon = 'display_icon ' . $option; |
| 319 |
|
| 320 |
if (isset($data[$display->name])) |
| 321 |
$display->checked = checked ( $data[$display->name], $option, false); |
| 322 |
$display->inputclass = 'check_button icon'; |
| 323 |
|
| 324 |
$start = ($i == 0) ? 'group_start' : ''; |
| 325 |
$end = ($i == count($options)-1 ) ? 'group_end' : ''; |
| 326 |
$admin->addField($display, $start, $end); |
| 327 |
$i++; |
| 328 |
} |
| 329 |
|
| 330 |
$hidden = new maxField('hidden'); |
| 331 |
$hidden->id = 'display_homepage_options'; |
| 332 |
$hidden->name = $hidden->id; |
| 333 |
if (isset($blockdata['display_homepage_options'])) |
| 334 |
$hidden->value = htmlentities(json_encode($blockdata['display_homepage_options']) ); |
| 335 |
|
| 336 |
$admin->addField($hidden, '',''); |
| 337 |
|
| 338 |
$homepage_button = clone $option_button; |
| 339 |
$homepage_button->id = 'option_homepage'; |
| 340 |
$homepage_button->conditional = htmlentities(json_encode(array('target' => $display->name, 'values' => $conditional_options))); |
| 341 |
$admin->addField( $homepage_button, '', 'end'); |
| 342 |
|
| 343 |
$fspacer = new maxField('spacer'); |
| 344 |
$fspacer->name = 'spacer'; |
| 345 |
$fspacer->main_class = 'option display_group'; |
| 346 |
$fspacer->label = __('Pages', 'mbsocial'); |
| 347 |
|
| 348 |
$admin->addField($fspacer, 'start', ''); |
| 349 |
|
| 350 |
$i = 0; |
| 351 |
foreach($options as $option => $label) |
| 352 |
{ |
| 353 |
$display = new maxField('radio'); |
| 354 |
$display->id = 'radio_display_page_' . $option; |
| 355 |
$display->name = 'display_page'; |
| 356 |
$display->title = $label; |
| 357 |
$display->value = $option; |
| 358 |
// $display->label = ($i == 0) ? __('Pages') : ''; |
| 359 |
|
| 360 |
|
| 361 |
// $display->image = $icon_url . $option_icons[$option]; |
| 362 |
$display->custom_icon = 'display_icon ' . $option; |
| 363 |
|
| 364 |
if (isset($data[$display->name])) |
| 365 |
$display->checked = checked ( $data[$display->name], $option, false); |
| 366 |
|
| 367 |
$display->inputclass = 'check_button icon'; |
| 368 |
|
| 369 |
$start = ($i == 0) ? 'group_start' : ''; |
| 370 |
$end = ($i == count($options)-1) ? 'group_end' : ''; |
| 371 |
$admin->addField($display, $start, $end); |
| 372 |
$i++; |
| 373 |
} |
| 374 |
|
| 375 |
/* |
| 376 |
$display = new maxField('option_select'); |
| 377 |
$display->publish = false; |
| 378 |
$display->label = __('Pages', 'mbsocial'); |
| 379 |
$display->id = 'display_page'; |
| 380 |
$display->name = $display->id; |
| 381 |
$display->selected = isset($data[$display->id]) ? $data[$display->id] : ''; |
| 382 |
$display->options = $options; |
| 383 |
$display->main_class = 'option display_group'; |
| 384 |
|
| 385 |
$admin->addField($display, 'start',''); |
| 386 |
*/ |
| 387 |
|
| 388 |
$pages_button = clone $option_button; |
| 389 |
$pages_button->id = 'option_page'; |
| 390 |
$pages_button->conditional = htmlentities(json_encode(array('target' => $display->name, 'values' => $conditional_options))); |
| 391 |
|
| 392 |
$hidden = new maxField('hidden'); |
| 393 |
$hidden->id = 'display_page_options'; |
| 394 |
$hidden->name = $hidden->id; |
| 395 |
if ( isset($blockdata['display_page_options'])) |
| 396 |
$hidden->value = htmlentities(json_encode($blockdata['display_page_options']) ); |
| 397 |
$admin->addField( $hidden, '',''); |
| 398 |
|
| 399 |
$admin->addField($pages_button, '','end'); |
| 400 |
|
| 401 |
|
| 402 |
// ** POSTS |
| 403 |
$fspacer = new maxField('spacer'); |
| 404 |
$fspacer->label = __('Posts', 'mbsocial'); |
| 405 |
$fspacer->name = 'spacer'; |
| 406 |
$fspacer->main_class = 'option display_group'; |
| 407 |
|
| 408 |
$admin->addField($fspacer, 'start'); |
| 409 |
|
| 410 |
$i = 0; |
| 411 |
foreach($options as $option => $label) |
| 412 |
{ |
| 413 |
$display = new maxField('radio'); |
| 414 |
$display->id = 'radio_display_post_' . $option; |
| 415 |
$display->name = 'display_post'; |
| 416 |
$display->title = $label; |
| 417 |
$display->value = $option; |
| 418 |
|
| 419 |
//$display->image = $icon_url . $option_icons[$option]; |
| 420 |
$display->custom_icon = 'display_icon ' . $option; |
| 421 |
|
| 422 |
if (isset($data[$display->name])) |
| 423 |
$display->checked = checked ( $data[$display->name], $option, false); |
| 424 |
$display->inputclass = 'check_button icon'; |
| 425 |
|
| 426 |
$start = ($i == 0) ? 'group_start' : ''; |
| 427 |
$end = ($i == count($options)-1) ? 'group_end' : ''; |
| 428 |
$admin->addField($display, $start, $end); |
| 429 |
$i++; |
| 430 |
} |
| 431 |
/* |
| 432 |
$display = new maxField('option_select'); |
| 433 |
$display->publish = false; |
| 434 |
$display->label = __('Posts', 'mbsocial'); |
| 435 |
$display->id = 'display_post'; |
| 436 |
$display->name = $display->id; |
| 437 |
$display->selected = isset($data[$display->id]) ? $data[$display->id] : ''; |
| 438 |
$display->options = $options; |
| 439 |
$display->main_class = 'option display_group'; |
| 440 |
|
| 441 |
$admin->addField($display, 'start', ''); |
| 442 |
*/ |
| 443 |
$posts_button = clone $option_button; |
| 444 |
$posts_button->id = 'option_post'; |
| 445 |
$posts_button->conditional = htmlentities(json_encode(array('target' => $display->name, 'values' => $conditional_options))); |
| 446 |
|
| 447 |
$hidden = new maxField('hidden'); |
| 448 |
$hidden->id = 'display_post_options'; |
| 449 |
$hidden->name = $hidden->id; |
| 450 |
if (isset($blockdata['display_post_options'])) |
| 451 |
$hidden->value = htmlentities(json_encode($blockdata['display_post_options']) ); |
| 452 |
$admin->addField($hidden, '',''); |
| 453 |
|
| 454 |
$admin->addField( $posts_button, '','end'); |
| 455 |
|
| 456 |
|
| 457 |
// ** ARCHIVES ** |
| 458 |
$fspacer = new maxField('spacer'); |
| 459 |
$fspacer->name = 'spacer'; |
| 460 |
$fspacer->main_class = 'option display_group'; |
| 461 |
$fspacer->label = __('Archive and Categories', 'mbsocial'); |
| 462 |
$admin->addField($fspacer, 'start'); |
| 463 |
|
| 464 |
$i = 0; |
| 465 |
foreach($options as $option => $label) |
| 466 |
{ |
| 467 |
$display = new maxField('radio'); |
| 468 |
$display->id = 'radio_display_archive_' . $option; |
| 469 |
$display->name = 'display_archive'; |
| 470 |
$display->title = $label; |
| 471 |
$display->value = $option; |
| 472 |
|
| 473 |
// $display->image = $icon_url . $option_icons[$option]; |
| 474 |
$display->custom_icon = 'display_icon ' . $option; |
| 475 |
|
| 476 |
if (isset($data[$display->name])) |
| 477 |
$display->checked = checked ( $data[$display->name], $option, false); |
| 478 |
$display->inputclass = 'check_button icon'; |
| 479 |
|
| 480 |
$start = ($i == 0) ? 'group_start' : ''; |
| 481 |
$end = ($i == count($options)-1 ) ? 'group_end' : ''; |
| 482 |
$admin->addField($display, $start, $end); |
| 483 |
$i++; |
| 484 |
} |
| 485 |
/*$display = new maxField('option_select'); |
| 486 |
$display->publish = false; |
| 487 |
$display->label = __('Archive and Categories', 'mbsocial'); |
| 488 |
$display->id = 'display_archive'; |
| 489 |
$display->name = $display->id; |
| 490 |
$display->selected = isset($data[$display->id]) ? $data[$display->id] : ''; |
| 491 |
$display->options = $options; |
| 492 |
$display->main_class = 'option display_group'; |
| 493 |
|
| 494 |
$admin->addField( $display, 'start', ''); |
| 495 |
*/ |
| 496 |
$archive_button = clone $option_button; |
| 497 |
$archive_button->id = 'option_archive'; |
| 498 |
$archive_button->conditional = htmlentities(json_encode(array('target' => $display->name, 'values' => $conditional_options))); |
| 499 |
|
| 500 |
$hidden = new maxField('hidden'); |
| 501 |
$hidden->id = 'display_archive_options'; |
| 502 |
$hidden->name = $hidden->id; |
| 503 |
if (isset($blockdata['display_archive_options'])) |
| 504 |
$hidden->value = htmlentities(json_encode($blockdata['display_archive_options']) ); |
| 505 |
|
| 506 |
$admin->addField($hidden, '',''); |
| 507 |
|
| 508 |
$admin->addField($archive_button, '', 'end'); |
| 509 |
|
| 510 |
$post_types = $this->get_post_types(); |
| 511 |
|
| 512 |
|
| 513 |
if (count($post_types) > 0) |
| 514 |
{ |
| 515 |
$spacer = new maxField('spacer'); |
| 516 |
$spacer->label = __('Custom Post Types', 'mbsocial'); |
| 517 |
$spacer->id = 'spacer_custom'; |
| 518 |
$spacer->name = $spacer->id; |
| 519 |
|
| 520 |
$admin->addField($spacer, 'start', 'end'); |
| 521 |
|
| 522 |
if (! Install::isPRO() ) { |
| 523 |
$spacer_pro = new maxField('spacer'); |
| 524 |
$spacer_pro->id = 'display_no_pro'; |
| 525 |
$spacer_pro->label = $admin->getProMessage(); |
| 526 |
$spacer_pro->name = $spacer_pro->id; |
| 527 |
|
| 528 |
$admin->addField($spacer_pro,'start', 'end'); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
// Custom Post Types |
| 533 |
foreach ($post_types as $post_type) |
| 534 |
{ |
| 535 |
|
| 536 |
$fspacer = new maxField('spacer'); |
| 537 |
$fspacer->label = ucfirst($post_type); |
| 538 |
$fspacer->name = 'spacer'; |
| 539 |
$fspacer->main_class = 'option display_group'; |
| 540 |
$admin->addField($fspacer, 'start'); |
| 541 |
|
| 542 |
$option_value = isset($data['display_' . $post_type]) ? $data['display_' . $post_type] : 'hidden'; |
| 543 |
|
| 544 |
$i = 0; |
| 545 |
foreach($options as $option => $label) |
| 546 |
{ |
| 547 |
|
| 548 |
$display = new maxField('radio'); |
| 549 |
$display->id = 'radio_display_' . $post_type . '_' . $option; |
| 550 |
$display->name = 'display_' . $post_type; |
| 551 |
$display->title = $label; |
| 552 |
$display->value = $option; |
| 553 |
// $display->image = $icon_url . $option_icons[$option]; |
| 554 |
$display->custom_icon = 'display_icon ' . $option; |
| 555 |
|
| 556 |
$display->checked = checked ( $option_value, $option, false); |
| 557 |
$display->inputclass = 'check_button icon'; |
| 558 |
|
| 559 |
if (! Install::isPRO() ) { |
| 560 |
$display->disabled = true; |
| 561 |
$display->inputclass = 'check_button icon disabled'; |
| 562 |
|
| 563 |
|
| 564 |
} |
| 565 |
|
| 566 |
$start = ($i == 0) ? 'group_start' : ''; |
| 567 |
$end = ($i == count($options)-1 ) ? 'group_end' : ''; |
| 568 |
$admin->addField($display, $start, $end); |
| 569 |
$i++; |
| 570 |
} |
| 571 |
|
| 572 |
/* |
| 573 |
$display = new maxField('option_select'); |
| 574 |
$display->id = 'display_' . $post_type; |
| 575 |
$display->name = $display->id; |
| 576 |
$display->label = ucfirst($post_type); |
| 577 |
$display->selected = isset($data[$display->id]) ? $data[$display->id] : ''; |
| 578 |
$display->options = $options; |
| 579 |
$display->main_class = 'option display_group ' . $display->id; |
| 580 |
*/ |
| 581 |
|
| 582 |
// $admin->addField($display, 'start', ''); |
| 583 |
|
| 584 |
$display_button = clone $option_button; |
| 585 |
$display_button->id = 'option_' . $post_type; |
| 586 |
$display_button->name = $display_button->id; |
| 587 |
$display_button->conditional = htmlentities(json_encode(array('target' => $display->name, 'values' => $conditional_options))); |
| 588 |
|
| 589 |
$hidden = new maxField('hidden'); |
| 590 |
$hidden->id = 'display_' . $post_type . '_options'; |
| 591 |
$hidden->name = $hidden->id; |
| 592 |
if ( isset($blockdata['display_' . $post_type . '_options'])) |
| 593 |
$hidden->value = htmlentities(json_encode($blockdata['display_' . $post_type . '_options'])); |
| 594 |
|
| 595 |
$admin->addField( $hidden, '',''); |
| 596 |
$admin->addField( $display_button, '', 'end'); |
| 597 |
|
| 598 |
|
| 599 |
} |
| 600 |
|
| 601 |
$spacer = new maxField('spacer'); |
| 602 |
$spacer->id = 'show_spacer'; |
| 603 |
$spacer->name = $spacer->id; |
| 604 |
$spacer->label = ' '; |
| 605 |
|
| 606 |
$admin->addField($spacer, 'start', 'end'); |
| 607 |
|
| 608 |
if ( Install::isPRO() ) { |
| 609 |
$show_desktop = new maxField('switch'); |
| 610 |
$show_desktop->id = 'show_desktop'; |
| 611 |
$show_desktop->name = $show_desktop->id; |
| 612 |
$show_desktop->value = 1; |
| 613 |
$show_desktop->label = __('Show on Desktop', 'mbsocial'); |
| 614 |
$show_desktop->checked = checked( $this->getValue('show_desktop'), 1, false); |
| 615 |
|
| 616 |
$admin->addField($show_desktop, 'start', 'end'); |
| 617 |
|
| 618 |
$show_mobile = new maxField('switch'); |
| 619 |
$show_mobile->id = 'show_mobile'; |
| 620 |
$show_mobile->name = $show_mobile->id; |
| 621 |
$show_mobile->value = 1; |
| 622 |
$show_mobile->label = __('Show on Mobile', 'mbsocial'); |
| 623 |
$show_mobile->checked = checked( $this->getValue('show_mobile'), 1, false); |
| 624 |
//$show_mobile->publish = ; |
| 625 |
|
| 626 |
$admin->addField($show_mobile, 'start', 'end'); |
| 627 |
} |
| 628 |
$admin->display_fields(); |
| 629 |
|
| 630 |
} |
| 631 |
|
| 632 |
/*protected function getDisplayRules() |
| 633 |
{ |
| 634 |
$data = $this->data; |
| 635 |
$blockdata = $this->data[$this->blockname]; |
| 636 |
|
| 637 |
return array(); |
| 638 |
} */ |
| 639 |
|
| 640 |
protected function addRule($args) |
| 641 |
{ |
| 642 |
$rule = array( |
| 643 |
'hook' => '', |
| 644 |
'display' => 'hidden', |
| 645 |
'orientation' => '', |
| 646 |
'position' => '', |
| 647 |
'fixed' => '', |
| 648 |
'share_setting' => 'current-post', |
| 649 |
'custom_url' => '', |
| 650 |
); |
| 651 |
|
| 652 |
$rule = wp_parse_args($args, $rule); |
| 653 |
return $rule; |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
/** Just simple for whom? **/ |
| 658 |
protected function simple_admin() |
| 659 |
{ |
| 660 |
|
| 661 |
$admin = mbSocial()->admin(); |
| 662 |
|
| 663 |
$data = $this->data; |
| 664 |
$blockdata = $this->data[$this->blockname]; |
| 665 |
|
| 666 |
$rules = $this->getDisplayRules(); |
| 667 |
|
| 668 |
if(count($rules) == 0) |
| 669 |
{ |
| 670 |
$rule = $this->addRule(array( |
| 671 |
'hook' => 'all', |
| 672 |
'display' => 'static', |
| 673 |
'orientation' => 'vertical', |
| 674 |
'fixed' => true, |
| 675 |
|
| 676 |
)); |
| 677 |
$rules[] = $rule; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
$label = new maxField('spacer'); |
| 682 |
$label->label = __('Label!', 'mbsocial'); |
| 683 |
$label->id = 'label'; |
| 684 |
|
| 685 |
$admin->addField($label, 'start'); |
| 686 |
|
| 687 |
foreach ($rules as $rule) |
| 688 |
{ |
| 689 |
$display = $rule['display']; |
| 690 |
$hook = $rule['hook']; |
| 691 |
|
| 692 |
$output = sprintf('On %s this will show the button %s ', $hook, $display); |
| 693 |
|
| 694 |
|
| 695 |
} |
| 696 |
|
| 697 |
$rfield = new maxField('generic'); |
| 698 |
$rfield->id = 'rule_1'; |
| 699 |
$rfield->content = $output; |
| 700 |
|
| 701 |
$admin->addField($rfield,'','end'); |
| 702 |
|
| 703 |
$admin->display_fields(); |
| 704 |
?> |
| 705 |
<p><h4> |
| 706 |
|
| 707 |
On the <strong>Homepage</strong> this will show <strong>Before the content</strong> |
| 708 |
|
| 709 |
<i>Remove</i> |
| 710 |
|
| 711 |
<p> |
| 712 |
|
| 713 |
<p> <h3> <a>Add a display Rule</a> </h3> |
| 714 |
</p> |
| 715 |
|
| 716 |
<p>I want this to show at the <select> |
| 717 |
<option>Homepage</option> |
| 718 |
<option>Pages</option> |
| 719 |
<option>Posts</option> |
| 720 |
<option>Custom Post Type</option> |
| 721 |
</select> |
| 722 |
section. Show it |
| 723 |
<select><option>Before the content</option> |
| 724 |
<option>After the content</option> |
| 725 |
<option>Both before and after the cotnent</option> |
| 726 |
<option class='selected'>Separate from the content</option> |
| 727 |
</select> |
| 728 |
|
| 729 |
</p> |
| 730 |
<p>The position of the separated content will be <strong>Left </strong> |
| 731 |
<strong>Top</strong> |
| 732 |
</p> |
| 733 |
|
| 734 |
<p> The shared URL will be the one of the page / something else |
| 735 |
<input type='text'> |
| 736 |
<input type="button" value="Do it" class="button-primary"> |
| 737 |
</p> |
| 738 |
|
| 739 |
<?php |
| 740 |
|
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
/** Admin() **/ |
| 745 |
public function admin() |
| 746 |
{ |
| 747 |
$admin = mbSocial()->admin(); |
| 748 |
|
| 749 |
$data = $this->data; |
| 750 |
$blockdata = $this->data[$this->blockname]; |
| 751 |
|
| 752 |
$orientation_options = array('auto' => __('Auto','mbsocial'), |
| 753 |
'horizontal' => __('Horizontal','mbsocial'), |
| 754 |
'vertical' => __('Vertical', 'mbsocial'), |
| 755 |
); |
| 756 |
|
| 757 |
$static_options = array( |
| 758 |
// 'auto' => __('Auto', 'mbsocial'), |
| 759 |
'left' => __('Left', 'mbsocial'), |
| 760 |
'center' => __('Center', 'mbsocial'), |
| 761 |
'right' => __('Right', 'mbsocial'), |
| 762 |
|
| 763 |
// 'bottom' => __('Bottom', 'mbsocial'), |
| 764 |
); |
| 765 |
|
| 766 |
$postpos_options = $static_options; |
| 767 |
|
| 768 |
$staticpos_options = array( |
| 769 |
// 'auto' => __('Auto', 'mbsocial'), |
| 770 |
'top' => __('Top', 'mbsocial'), |
| 771 |
'center' => __('Center', 'mbsocial'), |
| 772 |
'bottom' => __('Bottom', 'mbsocial'), |
| 773 |
); |
| 774 |
|
| 775 |
$collection_id = $this->collection->getID(); |
| 776 |
|
| 777 |
if ($collection_id > 0) |
| 778 |
$display_id = $collection_id; |
| 779 |
else |
| 780 |
$display_id = '*id*'; |
| 781 |
|
| 782 |
?> |
| 783 |
<div class='help-side'> |
| 784 |
<h3><?php _e('Display Options', 'mbsocial') ?></h3> |
| 785 |
<p>You can control where share buttons will appear by section of the site, like posts, pages, categories and custom post types</p> |
| 786 |
|
| 787 |
<p><b>Manual / Off:</b> Use [maxsocial id="<?php echo $display_id ?>"] in your post content where you would like social sharing to appear</p> |
| 788 |
|
| 789 |
<p><b>Content :</b> The buttons will display before or after your main post content, or both. </p> |
| 790 |
|
| 791 |
<p><b>Float: </b> The buttons will display detached from the movement of content on the screen. This will allow you to position them on a fixed position. </p> |
| 792 |
|
| 793 |
<p>Some settings have options which are revealed after clicking that option's button</p> |
| 794 |
</div> |
| 795 |
|
| 796 |
<div id='displayBlock' class='options display option-container'> |
| 797 |
<div class='title'><?php _e('Display Options', 'mbsocial'); ?></div> |
| 798 |
<div class='inside'> |
| 799 |
<?php // [Simple] [Expert] ?> |
| 800 |
<?php |
| 801 |
// ** PAGES ** |
| 802 |
$i = 0; |
| 803 |
|
| 804 |
$interface_option = 'simple'; |
| 805 |
|
| 806 |
// if ($interface_option == 'expert') |
| 807 |
$this->expert_admin(); |
| 808 |
|
| 809 |
/*else { |
| 810 |
$this->simple_admin(); |
| 811 |
|
| 812 |
} */ |
| 813 |
?> |
| 814 |
|
| 815 |
</div> <!-- inside --> |
| 816 |
</div> <!-- option-container --> |
| 817 |
|
| 818 |
<div id='modal_options' class='maxmodal-data' data-load='window.maxFoundry.maxSocial.displayOptions'> |
| 819 |
<div class='title'><?php _e('Options', 'mbsocial'); ?></div> |
| 820 |
<div class='content '> |
| 821 |
<div class='display_modal wrapper'> |
| 822 |
|
| 823 |
<div class='post_options'> |
| 824 |
|
| 825 |
<?php |
| 826 |
/* 07/01/2021 - Seems unused |
| 827 |
$staticIcons = array( |
| 828 |
'auto' => 'icon_auto.png', |
| 829 |
'left' => 'icon_posleft.png', |
| 830 |
'right' => 'icon_posright.png', |
| 831 |
'center' => 'icon_poscenter.png', |
| 832 |
'top' => 'icon_postop.png', |
| 833 |
'bottom' => 'icon_posbottom.png', |
| 834 |
'horizontal' => 'icon_horizontal.png', |
| 835 |
'vertical' => 'icon_vertical.png', |
| 836 |
); |
| 837 |
*/ |
| 838 |
$icon_url = MBSocial()->get_plugin_url() . 'images/icons/'; |
| 839 |
|
| 840 |
$orsp = new maxField('spacer'); |
| 841 |
$orsp->name = 'or_spacer'; |
| 842 |
$orsp->label = __('Orientation of the buttons'); |
| 843 |
|
| 844 |
$admin->addField($orsp, 'start'); |
| 845 |
|
| 846 |
|
| 847 |
$or = new maxField('radio'); |
| 848 |
$or->id = 'orientation_horizontal'; |
| 849 |
$or->name = 'orientation'; |
| 850 |
$or->title = __('Horizontal', 'mbsocial'); |
| 851 |
$or->value = 'horizontal'; |
| 852 |
// $or->image = $icon_url . $staticIcons['horizontal']; |
| 853 |
$or->custom_icon = 'display_icon horizontal'; |
| 854 |
|
| 855 |
|
| 856 |
// $or->checked = |
| 857 |
$or->inputclass = 'check_button icon'; |
| 858 |
|
| 859 |
|
| 860 |
$admin->addField($or, '', ''); |
| 861 |
|
| 862 |
$orv = clone $or; |
| 863 |
$orv->id = 'orientation_vertical'; |
| 864 |
$orv->title = __('Vertical', 'mbsocial'); |
| 865 |
$or->value = 'vertical'; |
| 866 |
// $or->image = $icon_url . $staticIcons['vertical']; |
| 867 |
$or->custom_icon = 'display_icon vertical'; |
| 868 |
|
| 869 |
$admin->addField($orv, '', 'end'); |
| 870 |
|
| 871 |
$admin->display_fields(); |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
?> |
| 876 |
</div> |
| 877 |
<div class='content_options'> |
| 878 |
<?php |
| 879 |
|
| 880 |
/* See : https://bitbucket.org/MF_Team/maxbuttons-social-share/issues/38/inline-share-buttons-cant-be-aligned |
| 881 |
$spacer = new maxField('spacer'); |
| 882 |
$spacer->name = 'pos_spacer'; |
| 883 |
$spacer->label = __('Alignment', 'mbsocial'); |
| 884 |
// $spacer->main_class = 'pos_options'; |
| 885 |
$admin->addField($spacer, 'start',''); |
| 886 |
|
| 887 |
$i = 0; |
| 888 |
|
| 889 |
foreach($postpos_options as $option => $label) |
| 890 |
{ |
| 891 |
|
| 892 |
$posopt = new maxField('radio'); |
| 893 |
$posopt->id = 'position_' . $option; |
| 894 |
$posopt->name = 'position'; |
| 895 |
$posopt->title = $label; |
| 896 |
$posopt->value = $option; |
| 897 |
//$posopt->image = $icon_url . 'icon_' . $y_option . $x_option . '.png'; |
| 898 |
$posopt->custom_icon = 'display_icon center' . $option; // center comes from lookup on icon image |
| 899 |
|
| 900 |
$posopt->checked = checked ( $option, 'auto', false); |
| 901 |
$posopt->inputclass = 'check_button icon'; |
| 902 |
|
| 903 |
//$start = ($i == 0) ? 'start' : ''; |
| 904 |
$end = ($i == 2) ? 'end' : ''; |
| 905 |
$admin->addField($posopt, '', $end); |
| 906 |
$i++; |
| 907 |
} |
| 908 |
|
| 909 |
$admin->display_fields(); |
| 910 |
*/ |
| 911 |
?> |
| 912 |
|
| 913 |
</div> |
| 914 |
|
| 915 |
<div class='static_options'> |
| 916 |
|
| 917 |
<?php |
| 918 |
/* |
| 919 |
$spacer = new maxField('spacer'); |
| 920 |
$spacer->name = 'spacer'; |
| 921 |
$spacer->main_class = 'pos_options'; |
| 922 |
$admin->addField($spacer, 'start',''); |
| 923 |
|
| 924 |
$i = 0; |
| 925 |
foreach($static_options as $option => $label) |
| 926 |
{ |
| 927 |
$posopt = new maxField('radio'); |
| 928 |
$posopt->id = 'position_x_' . $option; |
| 929 |
$posopt->name = 'position_x'; |
| 930 |
$posopt->title = $label; |
| 931 |
$posopt->value = $option; |
| 932 |
$posopt->image = $icon_url . $staticIcons[$option]; |
| 933 |
//default |
| 934 |
$posopt->checked = checked ( $option, 'auto', false); |
| 935 |
$posopt->inputclass = 'check_button icon'; |
| 936 |
$end = ($i == count($static_options)-1) ? 'end' : ''; |
| 937 |
|
| 938 |
$admin->addField($posopt, '',$end); |
| 939 |
$i++; |
| 940 |
} |
| 941 |
*/ |
| 942 |
$spacer = new maxField('spacer'); |
| 943 |
$spacer->name = 'pos_spacer'; |
| 944 |
$spacer->label = __('Position', 'mbsocial'); |
| 945 |
// $spacer->main_class = 'pos_options'; |
| 946 |
$admin->addField($spacer, 'start',''); |
| 947 |
|
| 948 |
$i = 1; |
| 949 |
$end = null; |
| 950 |
|
| 951 |
foreach($staticpos_options as $y_option => $y_label) |
| 952 |
{ |
| 953 |
foreach($static_options as $x_option => $x_label) |
| 954 |
{ |
| 955 |
$posopt = new maxField('radio'); |
| 956 |
$posopt->id = 'position_' . $y_option . '_' . $x_option; |
| 957 |
$posopt->name = 'position'; |
| 958 |
$posopt->title = $y_label . '-' . $x_label; |
| 959 |
$posopt->value = $y_option . '_' . $x_option; |
| 960 |
//$posopt->image = $icon_url . 'icon_' . $y_option . $x_option . '.png'; |
| 961 |
$posopt->custom_icon = 'display_icon ' . $y_option . $x_option; |
| 962 |
|
| 963 |
$posopt->checked = checked ( $x_option, 'auto', false); |
| 964 |
$posopt->inputclass = 'check_button icon'; |
| 965 |
|
| 966 |
$start = ( $end == 'end') ? 'start' : ''; // from prev run |
| 967 |
$end = ($i % 3 === 0 && $i > 0) ? 'end' : ''; |
| 968 |
|
| 969 |
$admin->addField($posopt, $start ,$end); |
| 970 |
$i++; |
| 971 |
} |
| 972 |
|
| 973 |
} |
| 974 |
|
| 975 |
/* $static= new maxField('option_select'); |
| 976 |
$static->id = 'static'; |
| 977 |
$static->name = $static->id; |
| 978 |
$static->options = $static_options; |
| 979 |
$static->label = __('Location on screen', 'mbsocial'); |
| 980 |
$static->note = __('This will define where on the screen your buttons will show up', 'mbsocial'); |
| 981 |
|
| 982 |
$admin->addField($static, 'start', 'end'); |
| 983 |
*/ |
| 984 |
/* $static_pos = new maxField('option_select'); |
| 985 |
$static_pos->id = 'staticpos'; |
| 986 |
$static_pos->name = $static_pos->id; |
| 987 |
$static_pos->options = $staticpos_options; |
| 988 |
$static_pos->label = __('Position on screen', 'mbsocial'); |
| 989 |
$static_pos->note = __('This will define on what level the buttons will show up' , 'mbsocial'); |
| 990 |
|
| 991 |
$admin->addField($static_pos, 'start', 'end'); |
| 992 |
*/ |
| 993 |
|
| 994 |
$fixed = new maxField('switch'); |
| 995 |
$fixed->id = 'fixed_position'; |
| 996 |
$fixed->name = $fixed->id; |
| 997 |
$fixed->label = __('Position fixed', 'mbsocial'); |
| 998 |
$fixed->value = 1; |
| 999 |
|
| 1000 |
$admin->addField($fixed, 'start', 'end'); |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
$admin->display_fields(); |
| 1005 |
?> |
| 1006 |
</div> |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
<div class='share_options'> |
| 1013 |
<?php |
| 1014 |
$share_options = array( |
| 1015 |
'auto' => __('Auto', 'mbsocial'), |
| 1016 |
'current-post' => __('Current Post or Page', 'mbsocial'), |
| 1017 |
'home' => __('Homepage', 'mbsocial'), |
| 1018 |
'custom-url' => __('Custom URL link', 'mbsocial'), |
| 1019 |
); |
| 1020 |
|
| 1021 |
|
| 1022 |
$share_setting = new maxField('option_select'); |
| 1023 |
$share_setting->id = 'share_setting'; |
| 1024 |
$share_setting->name = $share_setting->id; |
| 1025 |
$share_setting->label = __('Share URL setting', 'mbsocial'); |
| 1026 |
$share_setting->options = $share_options; |
| 1027 |
|
| 1028 |
//$custom_conditional = htmlentities(json_encode(array('target' => $share_setting->name, 'values' => 'custom-url'))); |
| 1029 |
|
| 1030 |
$share_custom = new maxField(); |
| 1031 |
$share_custom->id = 'share_custom_url'; |
| 1032 |
$share_custom->note = __("Settings below only apply when Share URL is set to Custom URL", 'mbsocial'); |
| 1033 |
$share_custom->name = $share_custom->id; |
| 1034 |
$share_custom->label = __('Custom URL','mbsocial'); |
| 1035 |
$share_custom->inputclass = 'medium'; |
| 1036 |
// $share_custom->start_conditional = $custom_conditional; |
| 1037 |
|
| 1038 |
$custom_title = new maxField('text'); |
| 1039 |
$custom_title->id = 'share_custom_title'; |
| 1040 |
$custom_title->name = $custom_title->id; |
| 1041 |
$custom_title->label = __('Custom Title', 'mbsocial'); |
| 1042 |
$custom_title->inputclass = 'medium'; |
| 1043 |
// $custom_title->start_conditional = $custom_conditional; //htmlentities(json_encode(array('target' => $share_setting->name, 'values' => 'custom-url'))); |
| 1044 |
|
| 1045 |
$admin->addField($share_setting, 'start', 'end'); |
| 1046 |
|
| 1047 |
$admin->addField($share_custom, 'start', 'end'); |
| 1048 |
$admin->addField($custom_title, 'start', 'end'); |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
$admin->display_fields(); |
| 1053 |
?> |
| 1054 |
|
| 1055 |
|
| 1056 |
</div> |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
</div> <!-- content --> |
| 1061 |
|
| 1062 |
</div> <!-- wrapper --> |
| 1063 |
<div class='controls'> |
| 1064 |
<button class='button-primary modal_close'>Done</button> |
| 1065 |
</div> |
| 1066 |
</div> <!-- modal --> |
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
<?php |
| 1071 |
|
| 1072 |
} |
| 1073 |
} |
| 1074 |
|