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