PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.36
Post Grid Gutenberg Blocks – PostX v5.0.36
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 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / addons / builder / blocks / Next_Previous.php

Next_Previous.php in Post Grid Gutenberg Blocks – PostX 5.0.36, at addons/builder/blocks/Next_Previous.php

164 lines 6.5 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 Next_Previous {
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 Next Preview Settings
18 ============================*/
19 'layout' => 'style1',
20 'headingEnable' => true,
21 'imageShow' => true,
22 'titleShow' => true,
23 'dateShow' => true,
24 'navDivider' => false,
25 'iconShow' => true,
26
27 /*
28 ============================
29 Navigation
30 ============================*/
31 'titlePosition' => true,
32 // Previous
33 'prevHeadText' => 'Previous Post',
34 // Next
35 'nextHeadText' => 'Next Post',
36
37 /*
38 ============================
39 Divider Setting/Style
40 ============================*/
41 'dividerBorderShape' => true,
42
43 /*
44 ============================
45 Arrow Icon
46 ============================*/
47 'arrowIconStyle' => 'Angle2',
48
49 /*
50 ============================
51 Advance Setting
52 ============================*/
53 'advanceId' => '',
54 'advanceZindex' => '',
55 'hideExtraLarge' => false,
56 'hideDesktop' => false,
57 'hideTablet' => false,
58 'hideMobile' => false,
59 'advanceCss' => '',
60 );
61 }
62
63 public function register() {
64 register_block_type(
65 'ultimate-post/next-previous',
66 array(
67 'editor_script' => 'ultp-blocks-editor-script',
68 'editor_style' => 'ultp-blocks-editor-css',
69 'render_callback' => array( $this, 'content' ),
70 )
71 );
72 }
73 public function content( $attr, $noAjax ) {
74 $attr = wp_parse_args( $attr, $this->get_attributes() );
75
76 $block_name = 'next-previous';
77 $wrapper_before = $wrapper_after = $content = $next_prev_img = '';
78
79 if ( $attr['imageShow'] ) {
80 $next_prev_img .= 'next-prev-img';
81 }
82
83 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
84 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
85 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
86 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
87 $attr['arrowIconStyle'] = sanitize_html_class( $attr['arrowIconStyle'] );
88 $attr['layout'] = sanitize_html_class( $attr['layout'] );
89 $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
90 $attr['prevHeadText'] = wp_kses( $attr['prevHeadText'], $allowed_html_tags );
91 $attr['nextHeadText'] = wp_kses( $attr['nextHeadText'], $allowed_html_tags );
92
93 $arrowLeft = '<span class="ultp-icon ultp-icon-' . $attr['arrowIconStyle'] . '">' . ultimate_post()->get_svg_icon( 'left' . $attr['arrowIconStyle'] ) . '</span>';
94 $arrowRight = '<span class="ultp-icon ultp-icon-' . $attr['arrowIconStyle'] . '">' . ultimate_post()->get_svg_icon( 'right' . $attr['arrowIconStyle'] ) . '</span>';
95
96 $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'] : '' ) . '">';
97 $wrapper_before .= '<div class="ultp-block-wrapper">';
98 $content .= '<div class="ultp-block-nav ' . $next_prev_img . '">';
99 $content .= $this->renderHtml( $attr, $arrowLeft, $arrowRight, true );
100 if ( $attr['navDivider'] && $attr['dividerBorderShape'] ) {
101 $content .= '<span class="ultp-divider"></span>';
102 }
103 $content .= $this->renderHtml( $attr, $arrowLeft, $arrowRight, false );
104 $content .= '</div>';
105 $wrapper_after .= '</div>';
106 $wrapper_after .= '</div>';
107
108 return $wrapper_before . $content . $wrapper_after;
109 }
110
111 public function renderHtml( $attr, $arrowLeft, $arrowRight, $left ) {
112 $output = '';
113 $post_data = $left ? get_previous_post() : get_next_post();
114 if ( $post_data ) {
115 $img_overlay = $attr['iconShow'] && $attr['layout'] == 'style2' ? ' ultp-npb-overlay' : '';
116 $imageData = '<div class="ultp-nav-img' . $img_overlay . '">';
117 $imageData .= ( $attr['iconShow'] && $attr['layout'] == 'style2' ) ? ( $left ? $arrowLeft : $arrowRight ) : '';
118 if ( has_post_thumbnail( $post_data->ID ) ) {
119 $imageData .= $attr['imageShow'] ? get_the_post_thumbnail( $post_data->ID ) : '';
120 }
121 $imageData .= '</div>';
122 $output .= '<a class="' . ( $left ? 'ultp-nav-block-prev ultp-nav-prev-' . $attr['layout'] : 'ultp-nav-block-next ultp-nav-next-' . $attr['layout'] ) . '" href="' . get_permalink( $post_data->ID ) . '">';
123 if ( $attr['headingEnable'] && ! $attr['titlePosition'] && ( $attr['layout'] == 'style2' ) ) {
124 $output .= '<div class=' . ( $left ? 'ultp-prev-title' : 'ultp-next-title' ) . ' >' . ( $left ? $attr['prevHeadText'] : $attr['nextHeadText'] ) . '</div>';
125 }
126 if ( $left && $attr['iconShow'] && $attr['layout'] != 'style2' ) {
127 $output .= $arrowLeft;
128 }
129 $output .= '<div class="ultp-nav-inside">';
130 if ( $attr['headingEnable'] && ! $attr['titlePosition'] && $attr['layout'] != 'style2' ) {
131 $output .= '<div class=' . ( $left ? 'ultp-prev-title' : 'ultp-next-title' ) . ' >' . ( $left ? $attr['prevHeadText'] : $attr['nextHeadText'] ) . '</div>';
132 }
133 $output .= '<div class="ultp-nav-inside-container">';
134 if ( $left ) {
135 $output .= $imageData;
136 }
137 if ( $left == false && $attr['layout'] == 'style3' ) {
138 $output .= $imageData;
139 }
140 $output .= '<div class="ultp-nav-text-content">';
141 if ( $attr['headingEnable'] && $attr['titlePosition'] ) {
142 $output .= '<div class=' . ( $left ? 'ultp-prev-title' : 'ultp-next-title' ) . ' >' . ( $left ? $attr['prevHeadText'] : $attr['nextHeadText'] ) . '</div>';
143 }
144 if ( $attr['dateShow'] ) {
145 $output .= '<div class="ultp-nav-date">' . get_the_date( get_option( 'date_format' ), $post_data->ID ) . '</div>';
146 }
147 if ( $attr['titleShow'] ) {
148 $output .= '<div class="ultp-nav-title">' . get_the_title( $post_data->ID ) . '</div>';
149 }
150 $output .= '</div>';
151 if ( $left == false && $attr['layout'] != 'style3' ) {
152 $output .= '<span>' . $imageData . '</span>';
153 }
154 $output .= '</div>';
155 $output .= '</div>';
156 if ( $left == false && $attr['iconShow'] && $attr['layout'] != 'style2' ) {
157 $output .= $arrowRight;
158 }
159 $output .= '</a>';
160 }
161 return $output;
162 }
163 }
164