PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.1
Post Grid Gutenberg Blocks – PostX v5.1.1
5.1.1 5.1.0 5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 All 240 releases
ultimate-post / addons / builder / blocks / Archive_Title.php

Archive_Title.php in Post Grid Gutenberg Blocks – PostX 5.1.1, at addons/builder/blocks/Archive_Title.php

161 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Archive_Title {
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 General Settings
18 ============================*/
19 'layout' => '1',
20 // 'contentAlign' => "left",
21 'titleShow' => true,
22 'excerptShow' => true,
23 'prefixShow' => false,
24 'showImage' => false,
25
26 /*
27 ============================
28 Title Setting/Style
29 ============================*/
30 'titleTag' => 'h1',
31 'customTaxTitleColor' => false,
32 'seperatorTaxTitleLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
33
34 /*
35 ============================
36 Prefix Setting/Style
37 ============================*/
38 'prefixText' => 'Sample Prefix Text',
39 'prefixTop' => false,
40
41 /*
42 ============================
43 Custom Wrapper Style
44 ============================*/
45 'customTaxColor' => false,
46 'seperatorTaxLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
47
48 /*
49 ============================
50 Advance Settings
51 ============================*/
52 'advanceId' => '',
53 'advanceZindex' => '',
54
55 // ---------------------
56 // Advanced > Responsive
57 // ---------------------
58 'hideExtraLarge' => false,
59 'hideTablet' => false,
60 'hideMobile' => false,
61 'advanceCss' => '',
62 );
63 }
64
65 public function register() {
66 register_block_type(
67 'ultimate-post/archive-title',
68 array(
69 'editor_script' => 'ultp-blocks-editor-script',
70 'editor_style' => 'ultp-blocks-editor-css',
71 'render_callback' => array( $this, 'content' ),
72 )
73 );
74 }
75
76 public function get_data() {
77 if ( is_admin() ) {
78 // For Demonstration Purpose
79 return array(
80 'title' => 'Archive Title',
81 'image' => ULTP_URL . 'assets/img/builder-fallback.jpg',
82 'desc' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam molestie aliquet molestie.',
83 'color' => '#037fff',
84 );
85 } else {
86 $_title = $_image = $_desc = $_color = '';
87 if ( is_archive() ) {
88 if ( is_category() || is_tag() || is_tax() ) {
89 $obj = get_queried_object();
90 $attachment_id = ultimate_post()->get_term_image_id( $obj );
91 $_title = $obj->name;
92 $_image = $attachment_id ? wp_get_attachment_url( $attachment_id ) : '';
93 $_desc = $obj->description;
94 $_color = ultimate_post()->get_term_color( $obj );
95 } elseif ( is_date() ) {
96 $_title = is_year() ? get_the_date( 'Y' ) : ( is_month() ? get_the_date( 'F Y' ) : ( is_day() ? get_the_date( 'F j, Y' ) : '' ) );
97 } elseif ( is_author() ) {
98 $_title = get_the_author_meta( 'display_name' );
99 $_image = get_avatar_url( get_the_author_meta( 'ID' ) );
100 $_desc = get_the_author_meta( 'description' );
101 }
102 } elseif ( is_search() ) {
103 $_title = get_search_query();
104 }
105 return array(
106 'title' => $_title,
107 'image' => $_image,
108 'desc' => $_desc,
109 'color' => $_color,
110 );
111 }
112 }
113
114
115 public function content( $attr, $noAjax ) {
116 $attr = wp_parse_args( $attr, $this->get_attributes() );
117
118 // Dummy
119 $data = $this->get_data();
120 $wraper_before = $wraper_after = $post_loop = '';
121 $block_name = 'archive-title';
122
123 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
124 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
125 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
126 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
127 $attr['titleTag'] = in_array( $attr['titleTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['titleTag'] : 'h1';
128 $attr['layout'] = sanitize_html_class( $attr['layout'] );
129 $attr['prefixText'] = wp_kses( $attr['prefixText'], ultimate_post()->ultp_allowed_html_tags() );
130
131 $wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '' . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '">';
132 $wraper_before .= '<div class="ultp-block-wrapper">';
133 $wraper_before .= '<div class="ultp-block-archive-title ultp-archive-layout-' . $attr['layout'] . '">';
134
135 $style = $attr['layout'] == '2' ? ( $data['image'] ? 'style="background-image: url(' . esc_url( $data['image'] ) . ')' : 'style="background-color:' . esc_attr( $data['color'] ? $data['color'] : '#28303d' ) ) . '"' : '';
136 $prefix = ( $attr['prefixShow'] && $attr['prefixText'] ) ? '<span class="ultp-archive-prefix">' . $attr['prefixText'] . '</span> ' : '';
137
138 $name = ( $attr['titleShow'] && $data['title'] ) ? '<' . $attr['titleTag'] . ' class="ultp-archive-name" ' . ( ( $data['color'] && $attr['customTaxTitleColor'] ) ? 'style="color: ' . esc_attr( $data['color'] ) . '"' : '' ) . '>' . $prefix . esc_html( $data['title'] ) . '</' . $attr['titleTag'] . '>' : '';
139
140 $excerpt = ( $attr['excerptShow'] && $data['desc'] ) ? '<div class="ultp-archive-desc">' . wp_kses_post( $data['desc'] ) . '</div>' : '';
141
142 // Prefix
143 switch ( $attr['layout'] ) {
144 case 1:
145 $img = ( $attr['showImage'] && $data['image'] ) ? '<img class="ultp-archive-image" src="' . esc_url( $data['image'] ) . '" alt="' . esc_attr( $data['title'] ) . '"/>' : '';
146 $post_loop .= $img . $name . $excerpt;
147 break;
148 case 2:
149 $style_overlay = $attr['customTaxColor'] ? 'style="background-color: ' . esc_attr( $data['color'] ) . '"' : '';
150 $post_loop .= '<div class="ultp-archive-content" ' . $style . '><div class="ultp-archive-overlay" ' . $style_overlay . '></div>' . $name . $excerpt . '</div>';
151 break;
152 }
153
154 $wraper_after .= '</div>';
155 $wraper_after .= '</div>';
156 $wraper_after .= '</div>';
157
158 return $wraper_before . $post_loop . $wraper_after;
159 }
160 }
161