| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Post_Date_Meta { |
| 7 |
public function __construct() { |
| 8 |
add_action( 'init', array( $this, 'register' ) ); |
| 9 |
} |
| 10 |
public function get_attributes() { |
| 11 |
|
| 12 |
return array( |
| 13 |
'blockId' => '', |
| 14 |
|
| 15 |
/* |
| 16 |
============================ |
| 17 |
Post Date Meta Setting |
| 18 |
============================*/ |
| 19 |
'prefixEnable' => false, |
| 20 |
'metaDateIconShow' => true, |
| 21 |
'dateFormat' => 'updated', |
| 22 |
'metaDateFormat' => 'M j, Y', |
| 23 |
|
| 24 |
/* |
| 25 |
============================ |
| 26 |
Post Date Meta Label |
| 27 |
============================*/ |
| 28 |
'datePubLabel' => 'Publish Date', |
| 29 |
'dateUpLabel' => 'Updated Date', |
| 30 |
|
| 31 |
/* |
| 32 |
============================ |
| 33 |
Post Date Meta icon style |
| 34 |
============================*/ |
| 35 |
'metaDateIconStyle' => 'date1', |
| 36 |
|
| 37 |
// -------------------------- |
| 38 |
// Advanced Settings |
| 39 |
// -------------------------- |
| 40 |
'advanceId' => '', |
| 41 |
'advanceZindex' => '', |
| 42 |
'hideExtraLarge' => false, |
| 43 |
'hideDesktop' => false, |
| 44 |
'hideTablet' => false, |
| 45 |
'hideMobile' => false, |
| 46 |
'advanceCss' => '', |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
public function register() { |
| 51 |
register_block_type( |
| 52 |
'ultimate-post/post-date-meta', |
| 53 |
array( |
| 54 |
'editor_script' => 'ultp-blocks-editor-script', |
| 55 |
'editor_style' => 'ultp-blocks-editor-css', |
| 56 |
'render_callback' => array( $this, 'content' ), |
| 57 |
) |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
public function content( $attr, $noAjax ) { |
| 62 |
$attr = wp_parse_args( $attr, $this->get_attributes() ); |
| 63 |
$block_name = 'post-date-meta'; |
| 64 |
|
| 65 |
$attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : ''; |
| 66 |
$attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : ''; |
| 67 |
$attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 68 |
$attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 69 |
$allowed_html_tags = ultimate_post()->ultp_allowed_html_tags(); |
| 70 |
$attr['datePubLabel'] = wp_kses( $attr['datePubLabel'], $allowed_html_tags ); |
| 71 |
$attr['dateUpLabel'] = wp_kses( $attr['dateUpLabel'], $allowed_html_tags ); |
| 72 |
|
| 73 |
$wrapper_before = $wrapper_after = $content = ''; |
| 74 |
|
| 75 |
$wrapper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class=" wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '">'; |
| 76 |
$wrapper_before .= '<div class="ultp-block-wrapper">'; |
| 77 |
$content .= '<div class="ultp-date-meta">'; |
| 78 |
if ( $attr['prefixEnable'] ) { |
| 79 |
$content .= '<span class="ultp-date-meta-prefix">'; |
| 80 |
if ( $attr['dateFormat'] == 'publish' ) { |
| 81 |
$content .= $attr['datePubLabel']; |
| 82 |
} else { |
| 83 |
$content .= $attr['dateUpLabel']; |
| 84 |
} |
| 85 |
|
| 86 |
$content .= '</span>'; |
| 87 |
} |
| 88 |
if ( $attr['metaDateIconShow'] && $attr['metaDateIconStyle'] ) { |
| 89 |
$content .= '<span class="ultp-date-meta-icon">'; |
| 90 |
$content .= ultimate_post()->get_svg_icon( $attr['metaDateIconStyle'] ); |
| 91 |
$content .= '</span>'; |
| 92 |
} |
| 93 |
if ( $attr['metaDateFormat'] ) { |
| 94 |
$content .= '<span class="ultp-date-meta-format">'; |
| 95 |
if ( $attr['dateFormat'] == 'updated' ) { |
| 96 |
$content .= get_the_modified_date( ultimate_post()->get_format( $attr['metaDateFormat'] ) ); |
| 97 |
} else { |
| 98 |
$content .= get_the_date( ultimate_post()->get_format( $attr['metaDateFormat'] ) ); |
| 99 |
} |
| 100 |
|
| 101 |
$content .= '</span>'; |
| 102 |
} |
| 103 |
$content .= '</div>'; |
| 104 |
$wrapper_after .= '</div>'; |
| 105 |
$wrapper_after .= '</div>'; |
| 106 |
|
| 107 |
return $wrapper_before . $content . $wrapper_after; |
| 108 |
} |
| 109 |
} |
| 110 |
|