| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Image{ |
| 7 |
public function __construct() { |
| 8 |
add_action('init', array($this, 'register')); |
| 9 |
} |
| 10 |
public function get_attributes() { |
| 11 |
|
| 12 |
return array( |
| 13 |
'blockId' => '', |
| 14 |
'previewImg' => '', |
| 15 |
/*-------------------------- |
| 16 |
Image Settings |
| 17 |
--------------------------*/ |
| 18 |
'imageUpload' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ], |
| 19 |
'linkType' => 'link', |
| 20 |
'imgLink' => '', |
| 21 |
'linkTarget' => '_blank', |
| 22 |
'imgAlt' => 'Image', |
| 23 |
'imgAlignment' => ['lg' => 'left'], |
| 24 |
'imgWidth' => (object)['lg' =>'', 'ulg' =>'px'], |
| 25 |
'imgHeight' => (object)['lg' =>'', 'unit' =>'px'], |
| 26 |
'imageScale' => 'cover', |
| 27 |
'imgAnimation' => 'none', |
| 28 |
'imgGrayScale' => (object)['lg' =>'0', 'ulg' =>'%', 'unit' =>'%'], |
| 29 |
'imgHoverGrayScale' => (object)['lg' =>'0', 'unit' =>'%'], |
| 30 |
'imgRadius' => (object)['lg' =>'', 'unit' =>'px'], |
| 31 |
'imgHoverRadius' => (object)['lg' =>'', 'unit' =>'px'], |
| 32 |
'imgShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 33 |
'imgHoverShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 34 |
'imgMargin' => (object)['lg'=>''], |
| 35 |
'imgOverlay' => false, |
| 36 |
'imgOverlayType' => 'default', |
| 37 |
'overlayColor' => (object)['openColor' => 1, 'type' => 'color', 'color' => '#0e1523'], |
| 38 |
'imgOpacity' => .7, |
| 39 |
'imgLazy' => false, |
| 40 |
|
| 41 |
/*-------------------------- |
| 42 |
Heading Setting/Style |
| 43 |
--------------------------*/ |
| 44 |
'headingText' => 'This is a Image Example', |
| 45 |
'headingEnable' => false, |
| 46 |
'headingColor' => '', |
| 47 |
'alignment' => ['lg' => 'left'], |
| 48 |
'headingTypo' => (object)['openTypography' => 1,'size' => (object)['lg' => '14', 'unit' => 'px'], 'height' => (object)['lg' => '', 'unit' => 'px'],'decoration' => '', 'transform' => '', 'family'=>'','weight'=>''], |
| 49 |
'headingMargin' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']], |
| 50 |
|
| 51 |
/*-------------------------- |
| 52 |
Button Settings |
| 53 |
--------------------------*/ |
| 54 |
'buttonEnable' => false, |
| 55 |
'btnText' => 'Free Download', |
| 56 |
'btnLink' => '#', |
| 57 |
'btnTarget' => '_blank', |
| 58 |
'btnPosition' => 'centerCenter', |
| 59 |
|
| 60 |
//style |
| 61 |
'btnTypo' => (object)['openTypography' => 1, 'size' => (object)['lg' =>14, 'unit' =>'px'], 'height' => (object)['lg' =>20, 'unit' =>'px'], 'spacing' => (object)['lg' =>0, 'unit' =>'px'], 'transform' => '', 'weight' => '', 'decoration' => 'none','family'=>'' ], |
| 62 |
'btnColor' => '#fff', |
| 63 |
'btnBgColor' => (object)['openColor' => 1,'type' => 'color', 'color' => '#037fff'], |
| 64 |
'btnBorder' => (object)['openBorder'=>0, 'width' => (object)[ 'top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid' ], |
| 65 |
'btnRadius' => (object)['lg' =>'2', 'unit' =>'px'], |
| 66 |
'btnShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 67 |
'btnHoverColor' => '#fff', |
| 68 |
'btnBgHoverColor' => (object)['openColor' => 1,'type' => 'color', 'color' => '#1239e2'], |
| 69 |
'btnHoverBorder' => (object)['openBorder'=>0, 'width' => (object)[ 'top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid' ], |
| 70 |
'btnHoverRadius' => (object)['lg' =>'', 'unit' =>'px'], |
| 71 |
'btnHoverShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 72 |
'btnSacing' => (object)['lg' =>(object)['top' => 0,'bottom' => 0,'left' => 0,'right' => 0, 'unit' =>'px']], |
| 73 |
'btnPadding' => (object)['lg' =>(object)['top' => "6",'bottom' => "6",'left' => "12",'right' => "12", 'unit' =>'px']], |
| 74 |
|
| 75 |
/*-------------------------- |
| 76 |
Wrapper Settings |
| 77 |
--------------------------*/ |
| 78 |
'wrapBg' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'], |
| 79 |
'wrapBorder' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 80 |
'wrapShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 81 |
'wrapRadius' => (object)['lg' =>'', 'unit' =>'px'], |
| 82 |
'wrapHoverBackground' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#037fff'], |
| 83 |
'wrapHoverBorder' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'], |
| 84 |
'wrapHoverRadius' => (object)['lg' =>'', 'unit' =>'px'], |
| 85 |
'wrapHoverShadow' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'], |
| 86 |
'wrapMargin' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']], |
| 87 |
'wrapOuterPadding' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']], |
| 88 |
'advanceId' => '', |
| 89 |
'advanceZindex' => '', |
| 90 |
'hideExtraLarge' => false, |
| 91 |
'hideTablet' => false, |
| 92 |
'hideMobile' => false, |
| 93 |
'advanceCss' => '', |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
public function register() { |
| 98 |
register_block_type( 'ultimate-post/image', |
| 99 |
array( |
| 100 |
'editor_script' => 'ultp-blocks-editor-script', |
| 101 |
'editor_style' => 'ultp-blocks-editor-css', |
| 102 |
'render_callback' => array($this, 'content') |
| 103 |
) |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
public function content($attr, $noAjax) { |
| 108 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 109 |
|
| 110 |
$wraper_before = ''; |
| 111 |
$block_name = 'image'; |
| 112 |
$attr['headingShow'] = true; |
| 113 |
$wraper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].''.(isset($attr["align"])? ' align' .$attr["align"]:'').''.(isset($attr["className"])?' '.$attr["className"]:'').'">'; |
| 114 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 115 |
$wraper_before .= '<figure class="ultp-image-block-wrapper">'; |
| 116 |
$wraper_before .= '<div class="ultp-image-block ultp-image-block-'.$attr['imgAnimation'].($attr["imgOverlay"] ? ' ultp-image-block-overlay ultp-image-block-'.$attr["imgOverlayType"] : '' ).'">'; |
| 117 |
// Single Image |
| 118 |
$img_arr = (array)$attr['imageUpload']; |
| 119 |
if (!empty($img_arr)) { |
| 120 |
if (($attr['linkType'] == 'link') && $attr['imgLink']) { |
| 121 |
$wraper_before .= '<a href="'.$attr['imgLink'].'" target="'.$attr['linkTarget'].'">'.ultimate_post()->get_image_html($img_arr['url'], 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy']).'</a>'; |
| 122 |
} else { |
| 123 |
$wraper_before .= ultimate_post()->get_image_html($img_arr['url'], 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy']); |
| 124 |
} |
| 125 |
} |
| 126 |
if ($attr['btnLink'] && ($attr['linkType'] == 'button')) { |
| 127 |
$wraper_before .= '<div class="ultp-image-button ultp-image-button-'.$attr['btnPosition'].'"><a href="'.$attr['btnLink'].'" target="'.$attr['btnTarget'].'">'.$attr['btnText'].'</a></div>'; |
| 128 |
} |
| 129 |
$wraper_before .= '</div>'; |
| 130 |
if ($attr['headingEnable'] == 1) { |
| 131 |
$wraper_before .= '<figcaption class="ultp-image-caption">'.$attr['headingText'].'</figcaption>'; |
| 132 |
} |
| 133 |
$wraper_before .= '</figure>'; |
| 134 |
$wraper_before .= '</div>'; |
| 135 |
$wraper_before .= '</div>'; |
| 136 |
|
| 137 |
return $wraper_before; |
| 138 |
} |
| 139 |
} |