| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: background |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'SP_PC_Field_background_adv' ) ) { |
| 11 |
class SP_PC_Field_background_adv extends SP_PC_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
$args = wp_parse_args( |
| 19 |
$this->field, |
| 20 |
array( |
| 21 |
'background_color' => true, |
| 22 |
'background_image' => true, |
| 23 |
'background_position' => true, |
| 24 |
'background_repeat' => true, |
| 25 |
'background_attachment' => true, |
| 26 |
'background_size' => true, |
| 27 |
'background_origin' => false, |
| 28 |
'background_clip' => false, |
| 29 |
'background_blend-mode' => false, |
| 30 |
'background_gradient' => false, |
| 31 |
'background_gradient_color' => true, |
| 32 |
'background_gradient_direction' => true, |
| 33 |
'background_image_preview' => true, |
| 34 |
'preview' => true, |
| 35 |
'preview_text' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', |
| 36 |
'background_image_library' => 'image', |
| 37 |
'background_image_placeholder' => esc_html__( 'No background selected', 'smart-post-show' ), |
| 38 |
) |
| 39 |
); |
| 40 |
|
| 41 |
$default_value = array( |
| 42 |
'background-color' => '', |
| 43 |
'background-image' => '', |
| 44 |
'background-position' => '', |
| 45 |
'background-repeat' => '', |
| 46 |
'background-attachment' => '', |
| 47 |
'background-size' => '', |
| 48 |
'background-origin' => '', |
| 49 |
'background-clip' => '', |
| 50 |
'background-blend-mode' => '', |
| 51 |
'background-gradient-color' => '', |
| 52 |
'background-gradient-direction' => '', |
| 53 |
); |
| 54 |
|
| 55 |
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; |
| 56 |
|
| 57 |
$this->value = wp_parse_args( $this->value, $default_value ); |
| 58 |
|
| 59 |
echo wp_kses_post( $this->field_before() ); |
| 60 |
|
| 61 |
echo '<div class="spf--blocks">'; |
| 62 |
// |
| 63 |
// Background Color. |
| 64 |
if ( ! empty( $args['background_color'] ) ) { |
| 65 |
|
| 66 |
echo '<div class="spf--block">'; |
| 67 |
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="spf--title">' . esc_html__( 'From', 'smart-post-show' ) . '</div>' : ''; |
| 68 |
|
| 69 |
SP_PC::field( |
| 70 |
array( |
| 71 |
'id' => 'background-color', |
| 72 |
'type' => 'color', |
| 73 |
'default' => $default_value['background-color'], |
| 74 |
), |
| 75 |
$this->value['background-color'], |
| 76 |
$this->field_name(), |
| 77 |
'field/background' |
| 78 |
); |
| 79 |
|
| 80 |
echo '</div>'; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
// |
| 85 |
// Background Gradient Color. |
| 86 |
if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) { |
| 87 |
|
| 88 |
echo '<div class="spf--block">'; |
| 89 |
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="spf--title">' . esc_html__( 'To', 'smart-post-show' ) . '</div>' : ''; |
| 90 |
|
| 91 |
SP_PC::field( |
| 92 |
array( |
| 93 |
'id' => 'background-gradient-color', |
| 94 |
'type' => 'color', |
| 95 |
'default' => $default_value['background-gradient-color'], |
| 96 |
), |
| 97 |
$this->value['background-gradient-color'], |
| 98 |
$this->field_name(), |
| 99 |
'field/background' |
| 100 |
); |
| 101 |
|
| 102 |
echo '</div>'; |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
// |
| 107 |
// Background Gradient Direction. |
| 108 |
if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) { |
| 109 |
|
| 110 |
echo '<div class="spf--block spf--gradient">'; |
| 111 |
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="spf--title">' . esc_html__( 'Direction', 'smart-post-show' ) . '</div>' : ''; |
| 112 |
|
| 113 |
SP_PC::field( |
| 114 |
array( |
| 115 |
'id' => 'background-gradient-direction', |
| 116 |
'type' => 'select', |
| 117 |
'options' => array( |
| 118 |
'' => esc_html__( 'Gradient Direction', 'smart-post-show' ), |
| 119 |
'to bottom' => esc_html__( '⇓ top to bottom', 'smart-post-show' ), |
| 120 |
'to right' => esc_html__( '⇒ left to right', 'smart-post-show' ), |
| 121 |
'135deg' => esc_html__( '⇘ corner top to right', 'smart-post-show' ), |
| 122 |
'-135deg' => esc_html__( '⇙ corner top to left', 'smart-post-show' ), |
| 123 |
), |
| 124 |
), |
| 125 |
$this->value['background-gradient-direction'], |
| 126 |
$this->field_name(), |
| 127 |
'field/background' |
| 128 |
); |
| 129 |
|
| 130 |
echo '</div>'; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
echo '</div>'; |
| 135 |
echo '<div class="clear"></div>'; |
| 136 |
|
| 137 |
// |
| 138 |
// Background Image. |
| 139 |
if ( ! empty( $args['background_image'] ) ) { |
| 140 |
|
| 141 |
echo '<div class="spf--media">'; |
| 142 |
|
| 143 |
SP_PC::field( |
| 144 |
array( |
| 145 |
'id' => 'background-image', |
| 146 |
'type' => 'media', |
| 147 |
'library' => $args['background_image_library'], |
| 148 |
'preview' => $args['background_image_preview'], |
| 149 |
'placeholder' => $args['background_image_placeholder'], |
| 150 |
), |
| 151 |
$this->value['background-image'], |
| 152 |
$this->field_name(), |
| 153 |
'field/background' |
| 154 |
); |
| 155 |
|
| 156 |
echo '</div>'; |
| 157 |
|
| 158 |
echo '<div class="clear"></div>'; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
// |
| 163 |
// Background Position. |
| 164 |
if ( ! empty( $args['background_position'] ) ) { |
| 165 |
echo '<div class="spf--block spf--select">'; |
| 166 |
|
| 167 |
SP_PC::field( |
| 168 |
array( |
| 169 |
'id' => 'background-position', |
| 170 |
'type' => 'select', |
| 171 |
'options' => array( |
| 172 |
'' => esc_html__( 'Background Position', 'smart-post-show' ), |
| 173 |
'left top' => esc_html__( 'Left Top', 'smart-post-show' ), |
| 174 |
'left center' => esc_html__( 'Left Center', 'smart-post-show' ), |
| 175 |
'left bottom' => esc_html__( 'Left Bottom', 'smart-post-show' ), |
| 176 |
'center top' => esc_html__( 'Center Top', 'smart-post-show' ), |
| 177 |
'center center' => esc_html__( 'Center Center', 'smart-post-show' ), |
| 178 |
'center bottom' => esc_html__( 'Center Bottom', 'smart-post-show' ), |
| 179 |
'right top' => esc_html__( 'Right Top', 'smart-post-show' ), |
| 180 |
'right center' => esc_html__( 'Right Center', 'smart-post-show' ), |
| 181 |
'right bottom' => esc_html__( 'Right Bottom', 'smart-post-show' ), |
| 182 |
), |
| 183 |
), |
| 184 |
$this->value['background-position'], |
| 185 |
$this->field_name(), |
| 186 |
'field/background' |
| 187 |
); |
| 188 |
|
| 189 |
echo '</div>'; |
| 190 |
|
| 191 |
} |
| 192 |
|
| 193 |
// |
| 194 |
// Background Repeat. |
| 195 |
if ( ! empty( $args['background_repeat'] ) ) { |
| 196 |
echo '<div class="spf--block spf--select">'; |
| 197 |
|
| 198 |
SP_PC::field( |
| 199 |
array( |
| 200 |
'id' => 'background-repeat', |
| 201 |
'type' => 'select', |
| 202 |
'options' => array( |
| 203 |
'' => esc_html__( 'Background Repeat', 'smart-post-show' ), |
| 204 |
'repeat' => esc_html__( 'Repeat', 'smart-post-show' ), |
| 205 |
'no-repeat' => esc_html__( 'No Repeat', 'smart-post-show' ), |
| 206 |
'repeat-x' => esc_html__( 'Repeat Horizontally', 'smart-post-show' ), |
| 207 |
'repeat-y' => esc_html__( 'Repeat Vertically', 'smart-post-show' ), |
| 208 |
), |
| 209 |
), |
| 210 |
$this->value['background-repeat'], |
| 211 |
$this->field_name(), |
| 212 |
'field/background' |
| 213 |
); |
| 214 |
|
| 215 |
echo '</div>'; |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
// |
| 220 |
// Background Attachment. |
| 221 |
if ( ! empty( $args['background_attachment'] ) ) { |
| 222 |
echo '<div class="spf--block spf--select">'; |
| 223 |
|
| 224 |
SP_PC::field( |
| 225 |
array( |
| 226 |
'id' => 'background-attachment', |
| 227 |
'type' => 'select', |
| 228 |
'options' => array( |
| 229 |
'' => esc_html__( 'Background Attachment', 'smart-post-show' ), |
| 230 |
'scroll' => esc_html__( 'Scroll', 'smart-post-show' ), |
| 231 |
'fixed' => esc_html__( 'Fixed', 'smart-post-show' ), |
| 232 |
), |
| 233 |
), |
| 234 |
$this->value['background-attachment'], |
| 235 |
$this->field_name(), |
| 236 |
'field/background' |
| 237 |
); |
| 238 |
|
| 239 |
echo '</div>'; |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
// |
| 244 |
// Background Size. |
| 245 |
if ( ! empty( $args['background_size'] ) ) { |
| 246 |
echo '<div class="spf--block spf--select">'; |
| 247 |
|
| 248 |
SP_PC::field( |
| 249 |
array( |
| 250 |
'id' => 'background-size', |
| 251 |
'type' => 'select', |
| 252 |
'options' => array( |
| 253 |
'' => esc_html__( 'Background Size', 'smart-post-show' ), |
| 254 |
'cover' => esc_html__( 'Cover', 'smart-post-show' ), |
| 255 |
'contain' => esc_html__( 'Contain', 'smart-post-show' ), |
| 256 |
), |
| 257 |
), |
| 258 |
$this->value['background-size'], |
| 259 |
$this->field_name(), |
| 260 |
'field/background' |
| 261 |
); |
| 262 |
|
| 263 |
echo '</div>'; |
| 264 |
|
| 265 |
} |
| 266 |
|
| 267 |
// |
| 268 |
// Background Origin. |
| 269 |
if ( ! empty( $args['background_origin'] ) ) { |
| 270 |
echo '<div class="spf--block spf--select">'; |
| 271 |
|
| 272 |
SP_PC::field( |
| 273 |
array( |
| 274 |
'id' => 'background-origin', |
| 275 |
'type' => 'select', |
| 276 |
'options' => array( |
| 277 |
'' => esc_html__( 'Background Origin', 'smart-post-show' ), |
| 278 |
'padding-box' => esc_html__( 'Padding Box', 'smart-post-show' ), |
| 279 |
'border-box' => esc_html__( 'Border Box', 'smart-post-show' ), |
| 280 |
'content-box' => esc_html__( 'Content Box', 'smart-post-show' ), |
| 281 |
), |
| 282 |
), |
| 283 |
$this->value['background-origin'], |
| 284 |
$this->field_name(), |
| 285 |
'field/background' |
| 286 |
); |
| 287 |
|
| 288 |
echo '</div>'; |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
// |
| 293 |
// Background Clip. |
| 294 |
if ( ! empty( $args['background_clip'] ) ) { |
| 295 |
echo '<div class="spf--block spf--select">'; |
| 296 |
|
| 297 |
SP_PC::field( |
| 298 |
array( |
| 299 |
'id' => 'background-clip', |
| 300 |
'type' => 'select', |
| 301 |
'options' => array( |
| 302 |
'' => esc_html__( 'Background Clip', 'smart-post-show' ), |
| 303 |
'border-box' => esc_html__( 'Border Box', 'smart-post-show' ), |
| 304 |
'padding-box' => esc_html__( 'Padding Box', 'smart-post-show' ), |
| 305 |
'content-box' => esc_html__( 'Content Box', 'smart-post-show' ), |
| 306 |
), |
| 307 |
), |
| 308 |
$this->value['background-clip'], |
| 309 |
$this->field_name(), |
| 310 |
'field/background' |
| 311 |
); |
| 312 |
|
| 313 |
echo '</div>'; |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
// |
| 318 |
// Background Blend Mode. |
| 319 |
if ( ! empty( $args['background_blend_mode'] ) ) { |
| 320 |
echo '<div class="spf--block spf--select">'; |
| 321 |
|
| 322 |
SP_PC::field( |
| 323 |
array( |
| 324 |
'id' => 'background-blend-mode', |
| 325 |
'type' => 'select', |
| 326 |
'options' => array( |
| 327 |
'' => esc_html__( 'Background Blend Mode', 'smart-post-show' ), |
| 328 |
'normal' => esc_html__( 'Normal', 'smart-post-show' ), |
| 329 |
'multiply' => esc_html__( 'Multiply', 'smart-post-show' ), |
| 330 |
'screen' => esc_html__( 'Screen', 'smart-post-show' ), |
| 331 |
'overlay' => esc_html__( 'Overlay', 'smart-post-show' ), |
| 332 |
'darken' => esc_html__( 'Darken', 'smart-post-show' ), |
| 333 |
'lighten' => esc_html__( 'Lighten', 'smart-post-show' ), |
| 334 |
'color-dodge' => esc_html__( 'Color Dodge', 'smart-post-show' ), |
| 335 |
'saturation' => esc_html__( 'Saturation', 'smart-post-show' ), |
| 336 |
'color' => esc_html__( 'Color', 'smart-post-show' ), |
| 337 |
'luminosity' => esc_html__( 'Luminosity', 'smart-post-show' ), |
| 338 |
), |
| 339 |
), |
| 340 |
$this->value['background-blend-mode'], |
| 341 |
$this->field_name(), |
| 342 |
'field/background' |
| 343 |
); |
| 344 |
|
| 345 |
echo '</div>'; |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
echo '<div class="clear"></div>'; |
| 350 |
|
| 351 |
// |
| 352 |
// Preview. |
| 353 |
$always_preview = ( 'always' !== $args['preview'] ) ? ' hidden' : ''; |
| 354 |
|
| 355 |
if ( ! empty( $args['preview'] ) ) { |
| 356 |
echo '<div class="spf--block spf--block-preview' . esc_attr( $always_preview ) . '">'; |
| 357 |
echo '<div class="spf--preview">' . esc_html( $args['preview_text'] ) . '</div>'; |
| 358 |
echo '</div>'; |
| 359 |
} |
| 360 |
echo '<div class="clear"></div>'; |
| 361 |
echo wp_kses_post( $this->field_after() ); |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* The field output. |
| 367 |
* |
| 368 |
* @return mixedx |
| 369 |
*/ |
| 370 |
public function output() { |
| 371 |
|
| 372 |
$output = ''; |
| 373 |
$bg_image = array(); |
| 374 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 375 |
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 376 |
|
| 377 |
// Background image and gradient. |
| 378 |
$background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : ''; |
| 379 |
$background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : ''; |
| 380 |
$background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : ''; |
| 381 |
$background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : ''; |
| 382 |
|
| 383 |
if ( $background_color && $background_gd_color ) { |
| 384 |
$gd_direction = ( $background_gd_direction ) ? $background_gd_direction . ',' : ''; |
| 385 |
$bg_image[] = 'linear-gradient(' . $gd_direction . $background_color . ',' . $background_gd_color . ')'; |
| 386 |
} |
| 387 |
|
| 388 |
if ( $background_image ) { |
| 389 |
$bg_image[] = 'url(' . $background_image . ')'; |
| 390 |
} |
| 391 |
|
| 392 |
if ( ! empty( $bg_image ) ) { |
| 393 |
$output .= 'background-image:' . implode( ',', $bg_image ) . $important . ';'; |
| 394 |
} |
| 395 |
|
| 396 |
// Common background properties. |
| 397 |
$properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' ); |
| 398 |
|
| 399 |
foreach ( $properties as $property ) { |
| 400 |
$property = 'background-' . $property; |
| 401 |
if ( ! empty( $this->value[ $property ] ) ) { |
| 402 |
$output .= $property . ':' . $this->value[ $property ] . $important . ';'; |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
if ( $output ) { |
| 407 |
$output = $element . '{' . $output . '}'; |
| 408 |
} |
| 409 |
|
| 410 |
$this->parent->output_css .= $output; |
| 411 |
|
| 412 |
return $output; |
| 413 |
|
| 414 |
} |
| 415 |
|
| 416 |
} |
| 417 |
} |
| 418 |
|