| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sureforms - Image |
| 4 |
* |
| 5 |
* @package Sureforms |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! class_exists( 'Advanced_Image' ) ) { |
| 13 |
|
| 14 |
/** |
| 15 |
* Class Advanced_Image. |
| 16 |
*/ |
| 17 |
class Advanced_Image { |
| 18 |
|
| 19 |
/** |
| 20 |
* Member Variable |
| 21 |
* |
| 22 |
* @var Advanced_Image|null |
| 23 |
*/ |
| 24 |
private static $instance; |
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
* |
| 29 |
* @return Advanced_Image The instance of the Advanced_Image class. |
| 30 |
*/ |
| 31 |
public static function get_instance() { |
| 32 |
if ( ! isset( self::$instance ) ) { |
| 33 |
self::$instance = new self(); |
| 34 |
} |
| 35 |
return self::$instance; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor |
| 40 |
*/ |
| 41 |
public function __construct() { |
| 42 |
|
| 43 |
// Activation hook. |
| 44 |
add_action( 'init', [ $this, 'register_blocks' ] ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Registers the `sureforms/image` block on server. |
| 49 |
* |
| 50 |
* @since 0.0.1 |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public function register_blocks() { |
| 55 |
// Check if the register function exists. |
| 56 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$attr = [ |
| 61 |
'block_id' => [ |
| 62 |
'type' => 'string', |
| 63 |
], |
| 64 |
'isPreview' => [ |
| 65 |
'type' => 'boolean', |
| 66 |
'default' => false, |
| 67 |
], |
| 68 |
'layout' => [ |
| 69 |
'type' => 'string', |
| 70 |
'default' => 'default', |
| 71 |
], |
| 72 |
'url' => [ |
| 73 |
'type' => 'string', |
| 74 |
'default' => '', |
| 75 |
], |
| 76 |
'urlTablet' => [ |
| 77 |
'type' => 'string', |
| 78 |
'default' => '', |
| 79 |
], |
| 80 |
'urlMobile' => [ |
| 81 |
'type' => 'string', |
| 82 |
'default' => '', |
| 83 |
], |
| 84 |
'alt' => [ |
| 85 |
'type' => 'string', |
| 86 |
'default' => '', |
| 87 |
], |
| 88 |
'enableCaption' => [ |
| 89 |
'type' => 'boolean', |
| 90 |
'default' => false, |
| 91 |
], |
| 92 |
'caption' => [ |
| 93 |
'type' => 'string', |
| 94 |
'default' => '', |
| 95 |
], |
| 96 |
'align' => [ |
| 97 |
'type' => 'string', |
| 98 |
'default' => '', |
| 99 |
], |
| 100 |
'alignTablet' => [ |
| 101 |
'type' => 'string', |
| 102 |
'default' => '', |
| 103 |
], |
| 104 |
'alignMobile' => [ |
| 105 |
'type' => 'string', |
| 106 |
'default' => '', |
| 107 |
], |
| 108 |
'id' => [ |
| 109 |
'type' => 'integer', |
| 110 |
'default' => '', |
| 111 |
], |
| 112 |
'href' => [ |
| 113 |
'type' => 'string', |
| 114 |
'default' => '', |
| 115 |
], |
| 116 |
'rel' => [ |
| 117 |
'type' => 'string', |
| 118 |
'default' => '', |
| 119 |
], |
| 120 |
'linkClass' => [ |
| 121 |
'type' => 'string', |
| 122 |
'default' => '', |
| 123 |
], |
| 124 |
'linkDestination' => [ |
| 125 |
'type' => 'string', |
| 126 |
'default' => '', |
| 127 |
], |
| 128 |
'title' => [ |
| 129 |
'type' => 'string', |
| 130 |
'default' => '', |
| 131 |
], |
| 132 |
'width' => [ |
| 133 |
'type' => 'integer', |
| 134 |
'default' => '', |
| 135 |
], |
| 136 |
'widthTablet' => [ |
| 137 |
'type' => 'integer', |
| 138 |
'default' => '', |
| 139 |
], |
| 140 |
'widthMobile' => [ |
| 141 |
'type' => 'integer', |
| 142 |
'default' => '', |
| 143 |
], |
| 144 |
'height' => [ |
| 145 |
'type' => 'integer', |
| 146 |
'default' => '', |
| 147 |
], |
| 148 |
'heightTablet' => [ |
| 149 |
'type' => 'integer', |
| 150 |
'default' => '', |
| 151 |
], |
| 152 |
'heightMobile' => [ |
| 153 |
'type' => 'integer', |
| 154 |
'default' => '', |
| 155 |
], |
| 156 |
'naturalWidth' => [ |
| 157 |
'type' => 'integer', |
| 158 |
'default' => '', |
| 159 |
], |
| 160 |
'naturalHeight' => [ |
| 161 |
'type' => 'integer', |
| 162 |
'default' => '', |
| 163 |
], |
| 164 |
'linkTarget' => [ |
| 165 |
'type' => 'string', |
| 166 |
'default' => '', |
| 167 |
], |
| 168 |
'sizeSlug' => [ |
| 169 |
'type' => 'string', |
| 170 |
'default' => '', |
| 171 |
], |
| 172 |
'sizeSlugTablet' => [ |
| 173 |
'type' => 'string', |
| 174 |
'default' => '', |
| 175 |
], |
| 176 |
'sizeSlugMobile' => [ |
| 177 |
'type' => 'string', |
| 178 |
'default' => '', |
| 179 |
], |
| 180 |
'imageTopMargin' => [ |
| 181 |
'type' => 'number', |
| 182 |
], |
| 183 |
'imageRightMargin' => [ |
| 184 |
'type' => 'number', |
| 185 |
], |
| 186 |
'imageLeftMargin' => [ |
| 187 |
'type' => 'number', |
| 188 |
], |
| 189 |
'imageBottomMargin' => [ |
| 190 |
'type' => 'number', |
| 191 |
], |
| 192 |
'imageTopMarginTablet' => [ |
| 193 |
'type' => 'number', |
| 194 |
], |
| 195 |
'imageRightMarginTablet' => [ |
| 196 |
'type' => 'number', |
| 197 |
], |
| 198 |
'imageLeftMarginTablet' => [ |
| 199 |
'type' => 'number', |
| 200 |
], |
| 201 |
'imageBottomMarginTablet' => [ |
| 202 |
'type' => 'number', |
| 203 |
], |
| 204 |
'imageTopMarginMobile' => [ |
| 205 |
'type' => 'number', |
| 206 |
], |
| 207 |
'imageRightMarginMobile' => [ |
| 208 |
'type' => 'number', |
| 209 |
], |
| 210 |
'imageLeftMarginMobile' => [ |
| 211 |
'type' => 'number', |
| 212 |
], |
| 213 |
'imageBottomMarginMobile' => [ |
| 214 |
'type' => 'number', |
| 215 |
], |
| 216 |
'imageMarginUnit' => [ |
| 217 |
'type' => 'string', |
| 218 |
'default' => 'px', |
| 219 |
], |
| 220 |
'imageMarginUnitTablet' => [ |
| 221 |
'type' => 'string', |
| 222 |
'default' => 'px', |
| 223 |
], |
| 224 |
'imageMarginUnitMobile' => [ |
| 225 |
'type' => 'string', |
| 226 |
'default' => 'px', |
| 227 |
], |
| 228 |
'imageMarginLink' => [ |
| 229 |
'type' => 'boolean', |
| 230 |
'default' => true, |
| 231 |
], |
| 232 |
'captionText' => [ |
| 233 |
'type' => 'string', |
| 234 |
'default' => '', |
| 235 |
], |
| 236 |
'captionShowOn' => [ |
| 237 |
'type' => 'string', |
| 238 |
'default' => 'hover', |
| 239 |
], |
| 240 |
'captionLoadGoogleFonts' => [ |
| 241 |
'type' => 'boolean', |
| 242 |
'default' => false, |
| 243 |
], |
| 244 |
'captionColor' => [ |
| 245 |
'type' => 'string', |
| 246 |
], |
| 247 |
'captionAlign' => [ |
| 248 |
'type' => 'string', |
| 249 |
'default' => 'center', |
| 250 |
], |
| 251 |
'captionFontFamily' => [ |
| 252 |
'type' => 'string', |
| 253 |
'default' => 'Default', |
| 254 |
], |
| 255 |
'captionFontWeight' => [ |
| 256 |
'type' => 'string', |
| 257 |
], |
| 258 |
'captionFontStyle' => [ |
| 259 |
'type' => 'string', |
| 260 |
'default' => 'normal', |
| 261 |
], |
| 262 |
'captionTransform' => [ |
| 263 |
'type' => 'string', |
| 264 |
], |
| 265 |
'captionDecoration' => [ |
| 266 |
'type' => 'string', |
| 267 |
], |
| 268 |
'captionFontSizeType' => [ |
| 269 |
'type' => 'string', |
| 270 |
'default' => 'px', |
| 271 |
], |
| 272 |
'captionFontSizeTypeTablet' => [ |
| 273 |
'type' => 'string', |
| 274 |
'default' => 'px', |
| 275 |
], |
| 276 |
'captionFontSizeTypeMobile' => [ |
| 277 |
'type' => 'string', |
| 278 |
'default' => 'px', |
| 279 |
], |
| 280 |
'captionLineHeightType' => [ |
| 281 |
'type' => 'string', |
| 282 |
'default' => 'em', |
| 283 |
], |
| 284 |
'captionFontSize' => [ |
| 285 |
'type' => 'number', |
| 286 |
], |
| 287 |
'captionFontSizeTablet' => [ |
| 288 |
'type' => 'number', |
| 289 |
], |
| 290 |
'captionFontSizeMobile' => [ |
| 291 |
'type' => 'number', |
| 292 |
], |
| 293 |
'captionLineHeight' => [ |
| 294 |
'type' => 'number', |
| 295 |
], |
| 296 |
'captionLineHeightTablet' => [ |
| 297 |
'type' => 'number', |
| 298 |
], |
| 299 |
'captionLineHeightMobile' => [ |
| 300 |
'type' => 'number', |
| 301 |
], |
| 302 |
'captionTopMargin' => [ |
| 303 |
'type' => 'number', |
| 304 |
], |
| 305 |
'captionRightMargin' => [ |
| 306 |
'type' => 'number', |
| 307 |
], |
| 308 |
'captionLeftMargin' => [ |
| 309 |
'type' => 'number', |
| 310 |
], |
| 311 |
'captionBottomMargin' => [ |
| 312 |
'type' => 'number', |
| 313 |
], |
| 314 |
'captionTopMarginTablet' => [ |
| 315 |
'type' => 'number', |
| 316 |
], |
| 317 |
'captionRightMarginTablet' => [ |
| 318 |
'type' => 'number', |
| 319 |
], |
| 320 |
'captionLeftMarginTablet' => [ |
| 321 |
'type' => 'number', |
| 322 |
], |
| 323 |
'captionBottomMarginTablet' => [ |
| 324 |
'type' => 'number', |
| 325 |
], |
| 326 |
'captionTopMarginMobile' => [ |
| 327 |
'type' => 'number', |
| 328 |
], |
| 329 |
'captionRightMarginMobile' => [ |
| 330 |
'type' => 'number', |
| 331 |
], |
| 332 |
'captionLeftMarginMobile' => [ |
| 333 |
'type' => 'number', |
| 334 |
], |
| 335 |
'captionBottomMarginMobile' => [ |
| 336 |
'type' => 'number', |
| 337 |
], |
| 338 |
'captionMarginUnit' => [ |
| 339 |
'type' => 'string', |
| 340 |
'default' => 'px', |
| 341 |
], |
| 342 |
'captionMarginUnitTablet' => [ |
| 343 |
'type' => 'string', |
| 344 |
'default' => 'px', |
| 345 |
], |
| 346 |
'captionMarginUnitMobile' => [ |
| 347 |
'type' => 'string', |
| 348 |
'default' => 'px', |
| 349 |
], |
| 350 |
'captionMarginLink' => [ |
| 351 |
'type' => 'boolean', |
| 352 |
'default' => false, |
| 353 |
], |
| 354 |
// heading. |
| 355 |
'heading' => [ |
| 356 |
'type' => 'string', |
| 357 |
'default' => '', |
| 358 |
], |
| 359 |
'headingShowOn' => [ |
| 360 |
'type' => 'string', |
| 361 |
'default' => 'always', |
| 362 |
], |
| 363 |
'headingTag' => [ |
| 364 |
'type' => 'string', |
| 365 |
'default' => 'h2', |
| 366 |
], |
| 367 |
'headingId' => [ |
| 368 |
'type' => 'string', |
| 369 |
], |
| 370 |
'headingLoadGoogleFonts' => [ |
| 371 |
'type' => 'boolean', |
| 372 |
'default' => false, |
| 373 |
], |
| 374 |
'headingColor' => [ |
| 375 |
'type' => 'string', |
| 376 |
'default' => '#fff', |
| 377 |
], |
| 378 |
'headingFontFamily' => [ |
| 379 |
'type' => 'string', |
| 380 |
'default' => 'Default', |
| 381 |
], |
| 382 |
'headingFontWeight' => [ |
| 383 |
'type' => 'string', |
| 384 |
], |
| 385 |
'headingFontStyle' => [ |
| 386 |
'type' => 'string', |
| 387 |
'default' => 'normal', |
| 388 |
], |
| 389 |
'headingTransform' => [ |
| 390 |
'type' => 'string', |
| 391 |
], |
| 392 |
'headingDecoration' => [ |
| 393 |
'type' => 'string', |
| 394 |
], |
| 395 |
'headingFontSizeType' => [ |
| 396 |
'type' => 'string', |
| 397 |
'default' => 'px', |
| 398 |
], |
| 399 |
'headingFontSizeTypeTablet' => [ |
| 400 |
'type' => 'string', |
| 401 |
'default' => 'px', |
| 402 |
], |
| 403 |
'headingFontSizeTypeMobile' => [ |
| 404 |
'type' => 'string', |
| 405 |
'default' => 'px', |
| 406 |
], |
| 407 |
'headingLineHeightType' => [ |
| 408 |
'type' => 'string', |
| 409 |
'default' => 'em', |
| 410 |
], |
| 411 |
'headingFontSize' => [ |
| 412 |
'type' => 'number', |
| 413 |
], |
| 414 |
'headingFontSizeTablet' => [ |
| 415 |
'type' => 'number', |
| 416 |
], |
| 417 |
'headingFontSizeMobile' => [ |
| 418 |
'type' => 'number', |
| 419 |
], |
| 420 |
'headingLineHeight' => [ |
| 421 |
'type' => 'number', |
| 422 |
], |
| 423 |
'headingLineHeightTablet' => [ |
| 424 |
'type' => 'number', |
| 425 |
], |
| 426 |
'headingLineHeightMobile' => [ |
| 427 |
'type' => 'number', |
| 428 |
], |
| 429 |
'headingTopMargin' => [ |
| 430 |
'type' => 'number', |
| 431 |
], |
| 432 |
'headingRightMargin' => [ |
| 433 |
'type' => 'number', |
| 434 |
], |
| 435 |
'headingLeftMargin' => [ |
| 436 |
'type' => 'number', |
| 437 |
], |
| 438 |
'headingBottomMargin' => [ |
| 439 |
'type' => 'number', |
| 440 |
], |
| 441 |
'headingTopMarginTablet' => [ |
| 442 |
'type' => 'number', |
| 443 |
], |
| 444 |
'headingRightMarginTablet' => [ |
| 445 |
'type' => 'number', |
| 446 |
], |
| 447 |
'headingLeftMarginTablet' => [ |
| 448 |
'type' => 'number', |
| 449 |
], |
| 450 |
'headingBottomMarginTablet' => [ |
| 451 |
'type' => 'number', |
| 452 |
], |
| 453 |
'headingTopMarginMobile' => [ |
| 454 |
'type' => 'number', |
| 455 |
], |
| 456 |
'headingRightMarginMobile' => [ |
| 457 |
'type' => 'number', |
| 458 |
], |
| 459 |
'headingLeftMarginMobile' => [ |
| 460 |
'type' => 'number', |
| 461 |
], |
| 462 |
'headingBottomMarginMobile' => [ |
| 463 |
'type' => 'number', |
| 464 |
], |
| 465 |
'headingMarginUnit' => [ |
| 466 |
'type' => 'string', |
| 467 |
'default' => 'px', |
| 468 |
], |
| 469 |
'headingMarginUnitTablet' => [ |
| 470 |
'type' => 'string', |
| 471 |
'default' => 'px', |
| 472 |
], |
| 473 |
'headingMarginUnitMobile' => [ |
| 474 |
'type' => 'string', |
| 475 |
'default' => 'px', |
| 476 |
], |
| 477 |
'headingMarginLink' => [ |
| 478 |
'type' => 'boolean', |
| 479 |
'default' => false, |
| 480 |
], |
| 481 |
// overlay. |
| 482 |
'overlayPositionFromEdge' => [ |
| 483 |
'type' => 'number', |
| 484 |
'default' => 15, |
| 485 |
], |
| 486 |
'overlayPositionFromEdgeUnit' => [ |
| 487 |
'type' => 'string', |
| 488 |
'default' => 'px', |
| 489 |
], |
| 490 |
'overlayContentPosition' => [ |
| 491 |
'type' => 'string', |
| 492 |
'default' => 'center center', |
| 493 |
], |
| 494 |
'overlayBackground' => [ |
| 495 |
'type' => 'string', |
| 496 |
'default' => '', |
| 497 |
], |
| 498 |
'overlayOpacity' => [ |
| 499 |
'type' => 'float', |
| 500 |
'default' => 0.2, |
| 501 |
], |
| 502 |
'overlayHoverOpacity' => [ |
| 503 |
'type' => 'number', |
| 504 |
'default' => 1, |
| 505 |
], |
| 506 |
// separator. |
| 507 |
'separatorShowOn' => [ |
| 508 |
'type' => 'string', |
| 509 |
'default' => 'hover', |
| 510 |
], |
| 511 |
'separatorStyle' => [ |
| 512 |
'type' => 'string', |
| 513 |
'default' => 'none', |
| 514 |
], |
| 515 |
'separatorColor' => [ |
| 516 |
'type' => 'string', |
| 517 |
'default' => '#fff', |
| 518 |
], |
| 519 |
'separatorPosition' => [ |
| 520 |
'type' => 'string', |
| 521 |
'default' => 'after_title', |
| 522 |
], |
| 523 |
'separatorWidth' => [ |
| 524 |
'type' => 'number', |
| 525 |
'default' => 30, |
| 526 |
], |
| 527 |
'separatorWidthType' => [ |
| 528 |
'type' => 'string', |
| 529 |
'default' => '%', |
| 530 |
], |
| 531 |
'separatorThickness' => [ |
| 532 |
'type' => 'number', |
| 533 |
'default' => 2, |
| 534 |
], |
| 535 |
'separatorThicknessUnit' => [ |
| 536 |
'type' => 'string', |
| 537 |
'default' => 'px', |
| 538 |
], |
| 539 |
'separatorTopMargin' => [ |
| 540 |
'type' => 'number', |
| 541 |
], |
| 542 |
'separatorRightMargin' => [ |
| 543 |
'type' => 'number', |
| 544 |
], |
| 545 |
'separatorLeftMargin' => [ |
| 546 |
'type' => 'number', |
| 547 |
], |
| 548 |
'separatorBottomMargin' => [ |
| 549 |
'type' => 'number', |
| 550 |
], |
| 551 |
'separatorTopMarginTablet' => [ |
| 552 |
'type' => 'number', |
| 553 |
], |
| 554 |
'separatorRightMarginTablet' => [ |
| 555 |
'type' => 'number', |
| 556 |
], |
| 557 |
'separatorLeftMarginTablet' => [ |
| 558 |
'type' => 'number', |
| 559 |
], |
| 560 |
'separatorBottomMarginTablet' => [ |
| 561 |
'type' => 'number', |
| 562 |
], |
| 563 |
'separatorTopMarginMobile' => [ |
| 564 |
'type' => 'number', |
| 565 |
], |
| 566 |
'separatorRightMarginMobile' => [ |
| 567 |
'type' => 'number', |
| 568 |
], |
| 569 |
'separatorLeftMarginMobile' => [ |
| 570 |
'type' => 'number', |
| 571 |
], |
| 572 |
'separatorBottomMarginMobile' => [ |
| 573 |
'type' => 'number', |
| 574 |
], |
| 575 |
'separatorMarginUnit' => [ |
| 576 |
'type' => 'string', |
| 577 |
'default' => 'px', |
| 578 |
], |
| 579 |
'separatorMarginUnitTablet' => [ |
| 580 |
'type' => 'string', |
| 581 |
'default' => 'px', |
| 582 |
], |
| 583 |
'separatorMarginUnitMobile' => [ |
| 584 |
'type' => 'string', |
| 585 |
'default' => 'px', |
| 586 |
], |
| 587 |
'separatorMarginLink' => [ |
| 588 |
'type' => 'boolean', |
| 589 |
'default' => false, |
| 590 |
], |
| 591 |
// effect. |
| 592 |
'imageHoverEffect' => [ |
| 593 |
'type' => 'string', |
| 594 |
'default' => 'static', |
| 595 |
], |
| 596 |
'objectFit' => [ |
| 597 |
'type' => 'string', |
| 598 |
], |
| 599 |
'objectFitTablet' => [ |
| 600 |
'type' => 'string', |
| 601 |
], |
| 602 |
'objectFitMobile' => [ |
| 603 |
'type' => 'string', |
| 604 |
], |
| 605 |
'useSeparateBoxShadows' => [ |
| 606 |
'type' => 'boolean', |
| 607 |
'default' => true, |
| 608 |
], |
| 609 |
'imageBoxShadowColor' => [ |
| 610 |
'type' => 'string', |
| 611 |
'default' => '#00000070', |
| 612 |
], |
| 613 |
'imageBoxShadowHOffset' => [ |
| 614 |
'type' => 'number', |
| 615 |
'default' => 0, |
| 616 |
], |
| 617 |
'imageBoxShadowVOffset' => [ |
| 618 |
'type' => 'number', |
| 619 |
'default' => 0, |
| 620 |
], |
| 621 |
'imageBoxShadowBlur' => [ |
| 622 |
'type' => 'number', |
| 623 |
], |
| 624 |
'imageBoxShadowSpread' => [ |
| 625 |
'type' => 'number', |
| 626 |
], |
| 627 |
'imageBoxShadowPosition' => [ |
| 628 |
'type' => 'string', |
| 629 |
'default' => 'outset', |
| 630 |
], |
| 631 |
'imageBoxShadowColorHover' => [ |
| 632 |
'type' => 'string', |
| 633 |
], |
| 634 |
'imageBoxShadowHOffsetHover' => [ |
| 635 |
'type' => 'number', |
| 636 |
'default' => 0, |
| 637 |
], |
| 638 |
'imageBoxShadowVOffsetHover' => [ |
| 639 |
'type' => 'number', |
| 640 |
'default' => 0, |
| 641 |
], |
| 642 |
'imageBoxShadowBlurHover' => [ |
| 643 |
'type' => 'number', |
| 644 |
], |
| 645 |
'imageBoxShadowSpreadHover' => [ |
| 646 |
'type' => 'number', |
| 647 |
], |
| 648 |
'imageBoxShadowPositionHover' => [ |
| 649 |
'type' => 'string', |
| 650 |
'default' => 'outset', |
| 651 |
], |
| 652 |
// mask. |
| 653 |
'maskShape' => [ |
| 654 |
'type' => 'string', |
| 655 |
'default' => 'none', |
| 656 |
], |
| 657 |
'maskCustomShape' => [ |
| 658 |
'type' => 'object', |
| 659 |
'default' => [ |
| 660 |
'url' => '', |
| 661 |
'alt' => 'mask shape', |
| 662 |
], |
| 663 |
], |
| 664 |
'maskSize' => [ |
| 665 |
'type' => 'string', |
| 666 |
'default' => 'auto', |
| 667 |
], |
| 668 |
'maskPosition' => [ |
| 669 |
'type' => 'string', |
| 670 |
'default' => 'center center', |
| 671 |
], |
| 672 |
'maskRepeat' => [ |
| 673 |
'type' => 'string', |
| 674 |
'default' => 'no-repeat', |
| 675 |
], |
| 676 |
'headingLetterSpacing' => [ |
| 677 |
'type' => 'number', |
| 678 |
], |
| 679 |
'headingLetterSpacingTablet' => [ |
| 680 |
'type' => 'number', |
| 681 |
], |
| 682 |
'headingLetterSpacingMobile' => [ |
| 683 |
'type' => 'number', |
| 684 |
], |
| 685 |
'headingLetterSpacingType' => [ |
| 686 |
'type' => 'string', |
| 687 |
'default' => 'px', |
| 688 |
], |
| 689 |
'captionLetterSpacing' => [ |
| 690 |
'type' => 'number', |
| 691 |
], |
| 692 |
'captionLetterSpacingTablet' => [ |
| 693 |
'type' => 'number', |
| 694 |
], |
| 695 |
'captionLetterSpacingMobile' => [ |
| 696 |
'type' => 'number', |
| 697 |
], |
| 698 |
'captionLetterSpacingType' => [ |
| 699 |
'type' => 'string', |
| 700 |
'default' => 'px', |
| 701 |
], |
| 702 |
'customHeightSetDesktop' => [ |
| 703 |
'type' => 'boolean', |
| 704 |
'default' => false, |
| 705 |
], |
| 706 |
'customHeightSetTablet' => [ |
| 707 |
'type' => 'boolean', |
| 708 |
'default' => false, |
| 709 |
], |
| 710 |
'customHeightSetMobile' => [ |
| 711 |
'type' => 'boolean', |
| 712 |
'default' => false, |
| 713 |
], |
| 714 |
'disableLazyLoad' => [ |
| 715 |
'type' => 'boolean', |
| 716 |
'default' => false, |
| 717 |
], |
| 718 |
]; |
| 719 |
|
| 720 |
$advaned_image_border_attr = Spec_Gb_Helper::get_instance()->generate_php_border_attribute( 'image' ); |
| 721 |
$advaned_image_border_overlay_attr = Spec_Gb_Helper::get_instance()->generate_php_border_attribute( 'overlay' ); |
| 722 |
|
| 723 |
$attr = array_merge( $advaned_image_border_attr, $advaned_image_border_overlay_attr, $attr ); |
| 724 |
|
| 725 |
$attributes = apply_filters( 'srfm_gutenberg_image_attributes_filters', $attr ); |
| 726 |
|
| 727 |
register_block_type( |
| 728 |
'srfm/image', |
| 729 |
[ |
| 730 |
'attributes' => $attributes, |
| 731 |
'render_callback' => [ $this, 'render_html' ], |
| 732 |
] |
| 733 |
); |
| 734 |
} |
| 735 |
|
| 736 |
/** |
| 737 |
* Render CF HTML. |
| 738 |
* |
| 739 |
* @param array<mixed> $attributes Array of block attributes. |
| 740 |
* |
| 741 |
* @since 0.0.1 |
| 742 |
* |
| 743 |
* @return string|false |
| 744 |
*/ |
| 745 |
public function render_html( $attributes ) { |
| 746 |
|
| 747 |
$block_id = ''; |
| 748 |
if ( isset( $attributes['block_id'] ) ) { |
| 749 |
$block_id = $attributes['block_id']; |
| 750 |
} |
| 751 |
|
| 752 |
$image = '<img |
| 753 |
srcset="' . esc_url( $attributes['url'] ) . ( $attributes['urlTablet'] ? ', ' . esc_url( $attributes['urlTablet'] ) . ' 780w' : '' ) |
| 754 |
. ( $attributes['urlMobile'] ? ', ' . esc_url( $attributes['urlMobile'] ) . ' 360w' : '' ) . '" |
| 755 |
sizes="(max-width: 480px) 150px" |
| 756 |
src="' . esc_url( $attributes['url'] ) . '" |
| 757 |
alt="' . esc_attr( $attributes['alt'] ) . '"'; |
| 758 |
|
| 759 |
if ( $attributes['id'] ) { |
| 760 |
$image .= ' class="uag-image-' . esc_attr( $attributes['id'] ) . '"'; |
| 761 |
} |
| 762 |
|
| 763 |
$image .= ' width="' . ( $attributes['width'] ? esc_attr( $attributes['width'] ) : esc_attr( $attributes['naturalWidth'] ) ) |
| 764 |
. '" height="' . ( $attributes['height'] ? esc_attr( $attributes['height'] ) : esc_attr( $attributes['naturalHeight'] ) ) . '" |
| 765 |
title="' . esc_attr( $attributes['title'] ) . '" |
| 766 |
loading="' . ( empty( $attributes['disableLazyLoad'] ) ? 'lazy' : 'eager' ) . |
| 767 |
'" />'; |
| 768 |
|
| 769 |
$figure_image = ''; |
| 770 |
if ( $attributes['href'] && '' !== $attributes['href'] ) { |
| 771 |
$figure_image = '<a |
| 772 |
class="' . esc_attr( $attributes['linkClass'] ) . '" |
| 773 |
href="' . esc_url( $attributes['href'] ) . '" |
| 774 |
target="' . esc_attr( $attributes['linkTarget'] ) . '" |
| 775 |
rel="' . $this->get_rel( $attributes['rel'] ) . '"> |
| 776 |
' . $image . ' |
| 777 |
</a>'; |
| 778 |
} else { |
| 779 |
$figure_image = $image; |
| 780 |
} |
| 781 |
|
| 782 |
$image_heading = ''; |
| 783 |
|
| 784 |
if ( ! empty( $attributes['heading'] ) ) { |
| 785 |
|
| 786 |
// Validate the tag-name attribute against the editor UI options |
| 787 |
// (esc_html() does not strip spaces or `=`, which is unsafe when |
| 788 |
// echoed in tag-name position). |
| 789 |
$allowed_heading_tags = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ]; |
| 790 |
$heading_tag = isset( $attributes['headingTag'] ) && in_array( $attributes['headingTag'], $allowed_heading_tags, true ) |
| 791 |
? $attributes['headingTag'] |
| 792 |
: 'h2'; |
| 793 |
|
| 794 |
$heading_id = ! empty( $attributes['headingId'] ) ? ' id="' . esc_attr( $attributes['headingId'] ) . '"' : ''; |
| 795 |
$image_heading = sprintf( |
| 796 |
'<%1$s%2$s class="uagb-image-heading">%3$s</%1$s>', |
| 797 |
esc_html( $heading_tag ), |
| 798 |
$heading_id, |
| 799 |
esc_html( $attributes['heading'] ) |
| 800 |
); |
| 801 |
} |
| 802 |
|
| 803 |
$image_caption = ''; |
| 804 |
|
| 805 |
if ( ! empty( $attributes['caption'] ) ) { |
| 806 |
$image_caption = sprintf( |
| 807 |
'<figcaption class="uagb-image-caption">%s</figcaption>', |
| 808 |
esc_html( $attributes['caption'] ) |
| 809 |
); |
| 810 |
} |
| 811 |
|
| 812 |
$separator = 'none' !== $attributes['separatorStyle'] ? '<div class="uagb-image-separator"></div>' : ''; |
| 813 |
|
| 814 |
$image_overlay_link = sprintf( |
| 815 |
'<a class="wp-block-uagb-image--layout-overlay-link %1$s" href="%2$s" target="%3$s" rel="%4$s"></a>', |
| 816 |
esc_attr( $attributes['linkClass'] ), |
| 817 |
esc_url( $attributes['href'] ), |
| 818 |
esc_attr( $attributes['linkTarget'] ), |
| 819 |
$this->get_rel( $attributes['rel'] ) |
| 820 |
); |
| 821 |
|
| 822 |
$main_classes = [ |
| 823 |
'wp-block-uagb-image', |
| 824 |
'uagb-block', |
| 825 |
'uagb-block-' . $block_id, |
| 826 |
'wp-block-uagb-image--layout-' . esc_attr( $attributes['layout'] ), |
| 827 |
'wp-block-uagb-image--effect-' . esc_attr( $attributes['imageHoverEffect'] ), |
| 828 |
'wp-block-uagb-image--align-' . ( $attributes['align'] ? esc_attr( $attributes['align'] ) : 'none' ), |
| 829 |
]; |
| 830 |
|
| 831 |
if ( isset( $attributes['className'] ) ) { |
| 832 |
$main_classes[] = $attributes['className']; |
| 833 |
} |
| 834 |
|
| 835 |
ob_start(); |
| 836 |
?> |
| 837 |
<div data-block-id="<?php echo esc_attr( $block_id ); ?>" class="<?php echo esc_attr( implode( ' ', $main_classes ) ); ?>"> |
| 838 |
<figure class="wp-block-uagb-image__figure"> |
| 839 |
<?php echo wp_kses( $figure_image, 'post' ); ?> |
| 840 |
|
| 841 |
<?php if ( 'overlay' === $attributes['layout'] ) : ?> |
| 842 |
<div class="wp-block-uagb-image--layout-overlay__color-wrapper"></div> |
| 843 |
<div class="wp-block-uagb-image--layout-overlay__inner <?php echo esc_attr( str_replace( ' ', '-', $attributes['overlayContentPosition'] ) ); ?>"> |
| 844 |
<?php echo wp_kses( $image_overlay_link, 'post' ); ?> |
| 845 |
|
| 846 |
<?php |
| 847 |
if ( 'before_title' === $attributes['separatorPosition'] ) { |
| 848 |
echo wp_kses( $separator, 'post' );} |
| 849 |
?> |
| 850 |
<?php echo wp_kses( $image_heading, 'post' ); ?> |
| 851 |
<?php |
| 852 |
if ( 'after_title' === $attributes['separatorPosition'] ) { |
| 853 |
echo wp_kses( $separator, 'post' );} |
| 854 |
?> |
| 855 |
<?php echo wp_kses( $image_caption, 'post' ); ?> |
| 856 |
<?php |
| 857 |
if ( 'after_sub_title' === $attributes['separatorPosition'] ) { |
| 858 |
echo wp_kses( $separator, 'post' );} |
| 859 |
?> |
| 860 |
</div> |
| 861 |
<?php else : ?> |
| 862 |
<?php |
| 863 |
if ( $attributes['enableCaption'] ) { |
| 864 |
echo wp_kses( $image_caption, 'post' );} |
| 865 |
?> |
| 866 |
<?php endif; ?> |
| 867 |
</figure> |
| 868 |
</div> |
| 869 |
<?php |
| 870 |
return ob_get_clean(); |
| 871 |
} |
| 872 |
|
| 873 |
/** |
| 874 |
* Utility function to get link relation. |
| 875 |
* |
| 876 |
* @param string|false $rel stored in block attributes. |
| 877 |
* |
| 878 |
* @since 0.0.1 |
| 879 |
* |
| 880 |
* @return string |
| 881 |
*/ |
| 882 |
public function get_rel( $rel ) { |
| 883 |
if ( $rel ) { |
| 884 |
return esc_attr( trim( $rel ) ); |
| 885 |
} |
| 886 |
return 'noopener'; |
| 887 |
} |
| 888 |
|
| 889 |
} |
| 890 |
|
| 891 |
/** |
| 892 |
* Prepare if class 'Advanced_Image' exist. |
| 893 |
* Kicking this off by calling 'get_instance()' method |
| 894 |
*/ |
| 895 |
Advanced_Image::get_instance(); |
| 896 |
} |
| 897 |
|