PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.0.3
Post Grid Gutenberg Blocks – PostX v4.0.3
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 5.0.17 2.1.1 All 238 releases
ultimate-post / addons / builder / blocks / Next_Previous.php

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

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