PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
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
← All changes | classes/Initialization.php +678 -566 5.0.322.7.8 View file →
@@ -1,631 +1,743 @@
1 1 <?php
2 -
3 2 /**
4 3 * Initialization Action.
5 - *
6 - * @package ULTP\ULTP_Initialization
4 + *
5 + * @package ULTP\Notice
7 6 * @since v.1.1.0
8 7 */
9 -
10 8 namespace ULTP;
11 9
12 -defined( 'ABSPATH' ) || exit;
10 +defined('ABSPATH') || exit;
13 11
14 -use ULTP\Includes\Durbin\Xpo;
15 -use ULTP\Includes\Notice\Notice;
16 -
17 12 /**
18 13 * Initialization class.
19 - *
20 - * Handles plugin initialization for Ultimate Post.
21 - *
22 - * @package ULTP\Initialization
23 - * @since 4.0.0
24 14 */
25 -class ULTP_Initialization {
15 +class ULTP_Initialization{
26 16
27 - /**
17 + private $all_blocks;
18 +
19 + /**
28 20 * Setup class.
29 21 *
30 - * @since 4.0.0
31 - * @return void No return value.
22 + * @since v.1.1.0
32 23 */
33 - public function __construct() {
24 + public function __construct() {
25 + $this->compatibility_check();
26 + $this->requires(); // Include Necessary Files
27 + $this->blocks(); // Include Blocks
28 + $this->include_addons(); // Include Addons
34 29
35 - $this->compatibility_check();
36 - $this->requires();
37 - $this->include_addons();
30 + add_action('wp', array($this, 'popular_posts_tracker_callback'));
31 + add_filter('block_categories_all', array($this, 'register_category_callback'), 10, 2); // Block Category Register
32 + add_action('after_setup_theme', array($this, 'add_image_size'));
38 33
39 - add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ) ); // add body class in editor.
40 - add_filter( 'body_class', array( $this, 'add_body_class' ) ); // add body class in front end.
34 + add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor
35 + add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel
36 + add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend
37 + register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
38 + add_action( 'activated_plugin', array($this, 'activation_redirect'));
41 39
42 - add_action( 'wp', array( $this, 'popular_posts_tracker_callback' ) );
43 - add_action( 'after_setup_theme', array( $this, 'add_image_size' ) );
44 - add_filter( 'block_categories_all', array( $this, 'register_category_callback' ), 999999999, 2 ); // Block Category Register.
40 + add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
41 + add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
42 + add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
43 + add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
44 + add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call
45 + add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User
46 + add_action('wp_ajax_ultp_addon', array($this, 'ultp_addon_callback')); // Next Previous AJAX Call
47 + add_action('wp_ajax_ultp_share_count', array($this, 'ultp_shareCount_callback')); // share Count save
45 48
46 - add_filter( 'safe_style_css', array( $this, 'ultp_handle_safe_style_css' ) ); // support for css used in svg icon.
47 - add_filter( 'wp_kses_allowed_html', array( $this, 'ultp_handle_allowed_html' ), 99, 2 ); // support for svg icon used in list, row, icon block.
49 + add_action('admin_init', array($this, 'check_theme_compatibility'));
50 + add_action( 'after_switch_theme', array($this, 'wpxpo_swithch_thememe'));
48 51
49 - add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_scripts_editor_area' ) ); // Only editor.
50 - add_action( 'admin_enqueue_scripts', array( $this, 'register_option_panel_scripts_callback' ) ); // Option Panel.
51 - register_activation_hook( ULTP_PATH . 'ultimate-post.php', array( $this, 'plugin_activation_hook' ) );
52 - add_action( 'activated_plugin', array( $this, 'ultp_plugin_activation' ) ); // Plugin Activation Call.
53 - // new Notice();
54 - }
52 + add_action( 'wp_ajax_plugin_settings', array( $this, 'save_plugin_settings_data' ) );
53 + add_action( 'in_plugin_update_message-'.ULTP_BASE, array( $this, 'in_plugin_settings_update_message' ) );
54 + }
55 55
56 - /**
57 - * Check plugin compatibility.
58 - *
59 - * @since v.1.0.0
60 - * @return void
56 + /**
57 + * Theme Switch Callback
58 + *
59 + * @since v.1.1.0
60 + * @return NULL
61 61 */
62 - public function compatibility_check() {
63 - require_once ULTP_PATH . 'classes/Compatibility.php';
64 - new \ULTP\Compatibility();
65 - }
62 + public function wpxpo_swithch_thememe () {
63 + $this->check_theme_compatibility();
64 + }
66 65
67 - /**
68 - * Load all required classes.
69 - *
70 - * @since v.1.0.0
71 - * @return void No return value.
66 +
67 + /**
68 + * Theme Compatibility Action
69 + *
70 + * @since v.1.1.0
71 + * @return NULL
72 72 */
73 - public function requires() {
74 - require_once ULTP_PATH . 'classes/Styles.php';
75 - require_once ULTP_PATH . 'classes/Options.php';
76 - require_once ULTP_PATH . 'classes/REST_API.php';
77 - require_once ULTP_PATH . 'classes/Caches.php';
78 - require_once ULTP_PATH . 'classes/Importer.php';
79 - require_once ULTP_PATH . 'classes/Dashboard.php';
80 - require_once ULTP_PATH . 'classes/Blocks.php';
81 - new \ULTP\REST_API();
82 - new \ULTP\Options();
83 - new \ULTP\Caches();
84 - new \ULTP\Styles();
85 - new \ULTP\Importer();
86 - new \ULTP\Dashboard();
87 - new \ULTP\Blocks();
73 + public function check_theme_compatibility() {
74 + $licence = apply_filters( 'ultp_theme_integration' , FALSE);
75 + $theme = get_transient( 'ulpt_theme_enable' );
88 76
89 - require_once ULTP_PATH . 'includes/durbin/class-durbin-client.php';
90 - require_once ULTP_PATH . 'includes/durbin/class-xpo.php';
91 - require_once ULTP_PATH . 'includes/deactive/class-deactive.php';
92 - require_once ULTP_PATH . 'includes/notice/class-notice.php';
93 - require_once ULTP_PATH . 'includes/durbin/class-our-plugins.php';
94 - require_once ULTP_PATH . 'includes/notice/class-wow-shipping-promotion.php';
95 - require_once ULTP_PATH . 'includes/notice/class-wow-revenue-promotion.php';
96 - require_once ULTP_PATH . 'includes/notice/class-wow-addons-promotion.php';
97 - new \ULTP\Includes\Deactive\Deactive();
98 - new \ULTP\Includes\notice\Notice();
99 - new \ULTP\Includes\notice\WowShippingPromotion();
100 - new \ULTP\Includes\notice\WowRevenuePromotion();
101 - new \ULTP\Includes\notice\WowAddonsPromotion();
102 - new \ULTP\Includes\Durbin\OurPlugins();
103 - }
77 + if ($licence ) {
78 + if ($theme != 'integration' ) {
79 + $themes = wp_get_theme();
80 + $api_params = array(
81 + 'wpxpo_theme_action' => 'theme_license',
82 + 'slug' => $themes->get('TextDomain'),
83 + 'author' => $themes->get('Author'),
84 + 'item_id' => 181,
85 + 'url' => home_url()
86 + );
87 +
88 + $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
104 89
105 - /**
106 - * Include all addons from the addons directory.
107 - *
108 - * @since v.1.0.0
109 - * @return void
90 + if (!is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
91 + $license_data = json_decode( wp_remote_retrieve_body( $response ) );
92 + if (isset($license_data->license)) {
93 + if ($license_data->license == 'valid' ) {
94 + set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
95 + }
96 + }
97 + }
98 + }
99 + } else {
100 + if ($theme == 'integration' ) {
101 + delete_transient('ulpt_theme_enable');
102 + }
103 + }
104 + }
105 +
106 +
107 + /**
108 + * Check Compatibility
109 + *
110 + * @since v.1.0.0
111 + * @return NULL
110 112 */
111 - public function include_addons() {
112 - $addons_dir = array_filter( glob( ULTP_PATH . 'addons/*' ), 'is_dir' );
113 - if ( count( $addons_dir ) > 0 ) {
114 - foreach ( $addons_dir as $key => $value ) {
115 - $addon_dir_name = str_replace( dirname( $value ) . '/', '', $value );
116 - $file_name = ULTP_PATH . 'addons/' . $addon_dir_name . '/init.php';
117 - if ( file_exists( $file_name ) ) {
118 - include_once $file_name;
119 - }
120 - }
121 - }
122 - }
113 + public function compatibility_check() {
114 + require_once ULTP_PATH.'classes/Compatibility.php';
115 + new \ULTP\Compatibility();
116 + }
123 117
124 118
125 - /**
126 - * Add admin body class in editor.
127 - *
128 - * @since v.3.1.6
129 - * @param STRING $classes The existing admin body classes.
130 - * @return STRING Modified admin body classes.
119 + /**
120 + * Option Panel CSS and JS Scripts
121 + *
122 + * @since v.1.0.0
123 + * @return NULL
131 124 */
132 - public function add_admin_body_class( $classes ) {
133 - $classes .= ' postx-admin-page ';
134 - return $classes;
135 - }
125 + public function register_scripts_option_panel_callback() {
126 + $is_active = ultimate_post()->is_lc_active();
127 + $license_key = $is_active ? get_option('edd_ultp_license_key') : '';
128 +
129 + wp_enqueue_style('wp-color-picker');
130 + wp_enqueue_script('wp-color-picker');
131 + wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
132 + wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
133 + wp_localize_script('ultp-option-script', 'ultp_option_panel', array(
134 + 'security' => wp_create_nonce('ultp-nonce'),
135 + 'ajax' => admin_url('admin-ajax.php'),
136 + 'license' => $license_key,
137 + ));
136 138
137 - /**
138 - * Add body class in front end.
139 - *
140 - * @since v.3.1.6
141 - * @param ARRAY $classes The existing body classes.
142 - * @return ARRAY Modified body classes.
139 + // Conditions
140 + $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
141 + if ($_page == 'ultp-settings' || get_post_type(get_the_ID()) == 'ultp_builder') {
142 + wp_enqueue_script('ultp-conditions-script', ULTP_URL.'addons/builder/assets/js/conditions.js', array('wp-api-fetch','wp-components','wp-i18n','wp-blocks'), ULTP_VER, true);
143 + wp_localize_script('ultp-conditions-script', 'ultp_condition', array(
144 + 'url' => ULTP_URL,
145 + 'active' => $is_active,
146 + 'premium_link' => ultimate_post()->get_premium_link(),
147 + 'license' => $license_key,
148 + 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
149 + ));
150 + }
151 + }
152 +
153 +
154 + /**
155 + * Only Frontend CSS and JS Scripts
156 + *
157 + * @since v.1.0.0
158 + * @return NULL
143 159 */
144 - public function add_body_class( $classes ) {
145 - $classes[] = 'postx-page';
146 - return $classes;
147 - }
160 + public function register_scripts_front_callback() {
161 + $call_common = false;
162 + if (isset($_GET['preview_id']) && isset($_GET['preview_nonce'])) {
163 + $call_common = true;
164 + ultimate_post()->register_scripts_common();
165 + } else if ('yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true)) {
166 + $call_common = true;
167 + ultimate_post()->register_scripts_common();
168 + } else if (ultimate_post()->is_builder()) {
169 + $call_common = true;
170 + ultimate_post()->register_scripts_common();
171 + } else if (apply_filters('postx_common_script', false)) {
172 + $call_common = true;
173 + ultimate_post()->register_scripts_common();
174 + }
148 175
149 - /**
150 - * Post view counter for every post.
151 - *
152 - * @since v.1.0.0
153 - * @param INT $post_id The post ID.
154 - * @return NULL No return value.
176 + // For WidgetWidget
177 + $has_block = false;
178 + $widget_blocks = array();
179 + global $wp_registered_sidebars, $sidebars_widgets;
180 + foreach ($wp_registered_sidebars as $key => $value) {
181 + if (is_active_sidebar($key)) {
182 + foreach ($sidebars_widgets[$key] as $val) {
183 + if (strpos($val, 'block-') !== false) {
184 + if (empty($widget_blocks)) {
185 + $widget_blocks = get_option( 'widget_block' );
186 + }
187 + foreach ( (array) $widget_blocks as $block ) {
188 + if (isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) {
189 + $has_block = true;
190 + break;
191 + }
192 + }
193 + if ($has_block) {
194 + break;
195 + }
196 + }
197 + }
198 + }
199 + }
200 + if ($has_block) {
201 + if (!$call_common) {
202 + ultimate_post()->register_scripts_common();
203 + }
204 + $css = get_option('ultp-widget', true);
205 + if ($css) {
206 + wp_register_style('ultp-post-widget', false );
207 + wp_enqueue_style('ultp-post-widget' );
208 + wp_add_inline_style('ultp-post-widget', $css);
209 + }
210 + }
211 + }
212 +
213 +
214 + /**
215 + * Only Backend CSS and JS Scripts
216 + *
217 + * @since v.1.0.0
218 + * @return NULL
155 219 */
156 - public function popular_posts_tracker_callback( $post_id ) {
157 - if ( ! is_single() ) {
158 - return;
159 - }
160 - global $post;
161 - $post_id = isset( $post->ID ) ? $post->ID : '';
162 - $isEnable = apply_filters( 'ultp_view_cookies', true );
163 - // add_filter( 'ultp_view_cookies', '__return_false' );
164 - $cookies_disable = ultimate_post()->get_setting( 'disable_view_cookies' );
165 - if ( $post_id && $isEnable && $cookies_disable != 'yes' ) {
166 - $has_cookie = isset( $_COOKIE[ 'ultp_view_' . $post_id ] ) ? sanitize_text_field( $_COOKIE[ 'ultp_view_' . $post_id ] ) : false;
167 - if ( ! $has_cookie ) {
168 - $count = (int) get_post_meta( $post_id, '__post_views_count', true );
169 - update_post_meta( $post_id, '__post_views_count', $count ? (int) $count + 1 : 1 );
170 - setcookie( 'ultp_view_' . $post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
171 - }
172 - }
173 - }
220 + public function register_scripts_back_callback() {
221 + ultimate_post()->register_scripts_common();
222 + global $pagenow;
223 + $depends = 'wp-editor';
224 + if ($pagenow === 'widgets.php' ) {
225 + $depends = 'wp-edit-widgets';
226 + }
227 + wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true);
228 + wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
229 + if (is_rtl()) {
230 + wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
231 + }
232 + $is_active = ultimate_post()->is_lc_active();
233 + wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
234 + 'url' => ULTP_URL,
235 + 'ajax' => admin_url('admin-ajax.php'),
236 + 'security' => wp_create_nonce('ultp-nonce'),
237 + 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'),
238 + 'upload' => wp_upload_dir()['basedir'] . '/ultp',
239 + 'premium_link' => ultimate_post()->get_premium_link(),
240 + 'license' => $is_active ? get_option('edd_ultp_license_key') : '',
241 + 'active' => $is_active,
242 + 'archive' => ultimate_post()->is_archive_builder(),
243 + 'settings' => ultimate_post()->get_setting(),
244 + 'post_type' => get_post_type(),
245 + 'date_format' => get_option('date_format'),
246 + 'time_format' => get_option('time_format')
247 + ));
248 + wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
249 + }
174 250
175 - /**
176 - * Set image sizes for the plugin.
177 - *
178 - * @since v.1.0.0
179 - * @return void No return value.
251 +
252 + /**
253 + * Fire When Plugin First Install
254 + *
255 + * @since v.1.0.0
256 + * @return NULL
180 257 */
181 - public function add_image_size() {
182 - $size_disable = ultimate_post()->get_setting( 'disable_image_size' );
183 - if ( $size_disable != 'yes' ) {
184 - add_image_size( 'ultp_layout_landscape_large', 1200, 800, true );
185 - add_image_size( 'ultp_layout_landscape', 870, 570, true );
186 - add_image_size( 'ultp_layout_portrait', 600, 900, true );
187 - add_image_size( 'ultp_layout_square', 600, 600, true );
188 - }
189 - }
258 + public function install_hook() {
259 + if (!get_option('ultp_options')) {
260 + ultimate_post()->init_set_data();
261 + }
262 + if (!get_transient('wpxpo_installation_date')) {
263 + set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
264 + }
265 + }
190 266
191 - /**
192 - * Block categories initialization.
193 - *
194 - * @since v.1.0.0
195 - * @param ARRAY $categories The block categories.
196 - * @param ARRAY $post The post object.
197 - * @return ARRAY Modified block categories.
267 +
268 + /**
269 + * Redirect After Active Plugin
270 + *
271 + * @since v.1.0.0
272 + * @param STRING | Plugin Path
273 + * @return NULL
198 274 */
199 - public function register_category_callback( $categories, $post ) {
200 - $attr = array(
201 - array(
202 - 'slug' => 'ultimate-post',
203 - 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ),
204 - ),
205 - array(
206 - 'slug' => 'postx-site-builder',
207 - 'title' => __( 'PostX Site Builder', 'ultimate-post' ),
208 - ),
209 - );
210 - return array_merge( $attr, $categories );
211 - }
275 + public function activation_redirect($plugin) {
276 + if ($plugin == 'ultimate-post/ultimate-post.php' ) {
277 + exit(wp_redirect(admin_url('admin.php?page=ultp-settings#templatekit')));
278 + }
279 + }
212 280
213 - /**
214 - * Add support for CSS to use SVG.
215 - *
216 - * @since 4.0.0
217 - * @param ARRAY $styles The allowed CSS styles.
218 - * @return ARRAY Modified allowed CSS styles.
281 +
282 + /**
283 + * Require Blocks
284 + *
285 + * @since v.1.0.0
286 + * @return NULL
219 287 */
220 - public function ultp_handle_safe_style_css( $styles ) {
221 - if ( ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
222 - return $styles;
223 - }
224 - return array_merge(
225 - $styles,
226 - array(
227 - 'opacity',
228 - // for SVG gradients.
229 - // 'stop-opacity',
230 - // 'stop-color',
231 - )
232 - );
233 - }
288 + public function blocks() {
289 + global $unique_ID;
290 + $setting = ultimate_post()->get_setting();
291 + require_once ULTP_PATH.'blocks/Post_List_1.php';
292 + require_once ULTP_PATH.'blocks/Post_List_2.php';
293 + require_once ULTP_PATH.'blocks/Post_List_3.php';
294 + require_once ULTP_PATH.'blocks/Post_List_4.php';
295 + require_once ULTP_PATH.'blocks/Post_Grid_1.php';
296 + require_once ULTP_PATH.'blocks/Post_Grid_2.php';
297 + require_once ULTP_PATH.'blocks/Post_Grid_3.php';
298 + require_once ULTP_PATH.'blocks/Post_Grid_4.php';
299 + require_once ULTP_PATH.'blocks/Post_Grid_5.php';
300 + require_once ULTP_PATH.'blocks/Post_Grid_6.php';
301 + require_once ULTP_PATH.'blocks/Post_Grid_7.php';
302 + require_once ULTP_PATH.'blocks/Post_Slider_1.php';
303 + require_once ULTP_PATH.'blocks/Post_Module_1.php';
304 + require_once ULTP_PATH.'blocks/Post_Module_2.php';
305 + require_once ULTP_PATH.'blocks/Heading.php';
306 + require_once ULTP_PATH.'blocks/Image.php';
307 + require_once ULTP_PATH.'blocks/Taxonomy.php';
308 + require_once ULTP_PATH.'blocks/News_Ticker.php';
309 +
310 + $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
311 + $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
312 + $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
313 + $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
314 + $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
315 + $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
316 + $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
317 + $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
318 + $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
319 + $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
320 + $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
321 + $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
322 + $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
323 + $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
324 + $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
325 + $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
326 + $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
327 + $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker();
234 328
235 - /**
236 - * Add support for HTML tags to use SVG.
237 - *
238 - * @since 4.0.0
239 - * @param ARRAY $tags The allowed HTML tags.
240 - * @param STRING $context The context for allowed HTML.
241 - * @return ARRAY Modified allowed HTML tags.
329 + if (ultimate_post()->get_setting('ultp_builder') == 'true') {
330 + require_once ULTP_PATH.'addons/builder/blocks/Archive_Title.php';
331 + require_once ULTP_PATH.'addons/builder/blocks/Post_Title.php';
332 + require_once ULTP_PATH.'addons/builder/blocks/Post_Content.php';
333 + require_once ULTP_PATH.'addons/builder/blocks/Post_Featured_Image.php';
334 + require_once ULTP_PATH.'addons/builder/blocks/Post_Breadcrumb.php';
335 + require_once ULTP_PATH.'addons/builder/blocks/Post_Tag.php';
336 + require_once ULTP_PATH.'addons/builder/blocks/Post_Category.php';
337 + require_once ULTP_PATH.'addons/builder/blocks/Next_Previous.php';
338 + require_once ULTP_PATH.'addons/builder/blocks/Post_Excerpt.php';
339 + // require_once ULTP_PATH.'addons/builder/blocks/Post_Video.php';
340 + require_once ULTP_PATH.'addons/builder/blocks/Author_Box.php';
341 + require_once ULTP_PATH.'addons/builder/blocks/Post_Comments.php';
342 + require_once ULTP_PATH.'addons/builder/blocks/Post_View_Count.php';
343 + require_once ULTP_PATH.'addons/builder/blocks/Post_Reading_Time.php';
344 + require_once ULTP_PATH.'addons/builder/blocks/Post_Comment_Count.php';
345 + require_once ULTP_PATH.'addons/builder/blocks/Post_Author_Meta.php';
346 + require_once ULTP_PATH.'addons/builder/blocks/Post_Date_Meta.php';
347 + // require_once ULTP_PATH.'addons/builder/blocks/Related_Posts.php';
348 + require_once ULTP_PATH.'addons/builder/blocks/Post_Social_Share.php';
349 + require_once ULTP_PATH.'addons/builder/blocks/Advance_Post_Meta.php';
350 +
351 + new \ULTP\blocks\Archive_Title();
352 + new \ULTP\blocks\Post_Title();
353 + new \ULTP\blocks\Post_Content();
354 + new \ULTP\blocks\Post_Featured_Image();
355 + new \ULTP\blocks\Post_Breadcrumb();
356 + new \ULTP\blocks\Post_Tag();
357 + new \ULTP\blocks\Post_Category();
358 + new \ULTP\blocks\Next_Previous();
359 + new \ULTP\blocks\Post_Excerpt();
360 + // new \ULTP\blocks\Post_Video();
361 + new \ULTP\blocks\Author_Box();
362 + new \ULTP\blocks\Post_Comments();
363 + new \ULTP\blocks\Post_View_Count();
364 + new \ULTP\blocks\Post_Reading_Time();
365 + new \ULTP\blocks\Post_Comment_Count();
366 + new \ULTP\blocks\Post_Author_Meta();
367 + new \ULTP\blocks\Post_Date_Meta();
368 + // new \ULTP\blocks\Related_Posts();
369 + new \ULTP\blocks\Post_Social_Share();
370 + new \ULTP\blocks\Advance_Post_Meta();
371 + }
372 + }
373 +
374 +
375 + /**
376 + * Necessary Requires Class
377 + *
378 + * @since v.1.0.0
379 + * @return NULL
242 380 */
243 - public function ultp_handle_allowed_html( $tags, $context ) {
244 - if ( 'post' !== $context && ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
245 - return $tags;
246 - }
247 - if ( ! isset( $tags['svg'] ) ) {
248 - $tags['svg'] = array_merge(
249 - array(
250 - 'xmlns' => true,
251 - // 'xmlns:xlink' => true,
252 - // 'xlink:href' => true,
253 - // 'xml:id' => true,
254 - // 'xlink:title' => true,
255 - // 'xml:space' => true,
256 - 'viewbox' => true,
257 - 'enable-background' => true,
258 - 'version' => true,
259 - 'preserveaspectratio' => true,
260 - 'fill' => true,
261 - )
262 - );
263 - }
264 - if ( ! isset( $tags['path'] ) || ! is_array( $tags['path'] ) ) {
265 - $tags['path'] = array();
266 - }
381 + public function requires() {
382 + require_once ULTP_PATH.'classes/Notice.php';
383 + require_once ULTP_PATH.'classes/Styles.php';
384 + require_once ULTP_PATH.'classes/Options.php';
385 + require_once ULTP_PATH.'classes/REST_API.php';
386 + require_once ULTP_PATH.'classes/Caches.php';
387 + new \ULTP\REST_API();
388 + new \ULTP\Caches();
389 + new \ULTP\Options();
390 + new \ULTP\Styles();
391 + new \ULTP\Notice();
267 392
268 - $tags['path'] = array_merge(
269 - $tags['path'],
270 - array(
271 - 'd' => true,
272 - 'stroke' => true,
273 - 'stroke-miterlimit' => true,
274 - 'data-original' => true,
275 - 'class' => true,
276 - 'transform' => true,
277 - 'style' => true,
278 - 'opacity' => true,
279 - 'fill' => true,
280 - 'stroke-width' => true,
281 - 'stroke-linecap' => true,
282 - 'stroke-linejoin' => true,
283 - )
284 - );
393 + require_once ULTP_PATH.'classes/Deactive.php';
394 + new \ULTP\Deactive();
395 + }
285 396
286 - if ( ! isset( $tags['g'] ) ) {
287 - $tags['g'] = array(
288 - 'transform' => true,
289 - 'clip-path' => true,
290 - );
291 - }
292 - if ( ! isset( $tags['clippath'] ) ) {
293 - $tags['clippath'] = array();
294 - }
295 - if ( ! isset( $tags['defs'] ) ) {
296 - $tags['defs'] = array();
297 - }
298 - if ( ! isset( $tags['rect'] ) ) {
299 - $tags['rect'] = array(
300 - 'rx' => true,
301 - 'height' => true,
302 - 'width' => true,
303 - 'transform' => true,
304 - 'x' => true,
305 - 'fill' => true,
306 - );
307 - }
308 - if ( ! isset( $tags['circle'] ) ) {
309 - $tags['circle'] = array(
310 - 'cx' => true,
311 - 'cy' => true,
312 - 'transform' => true,
313 - 'r' => true,
314 - );
315 - }
316 - if ( ! isset( $tags['polygon'] ) ) {
317 - $tags['polygon'] = array(
318 - 'points' => true,
319 - );
320 - }
321 - if ( ! isset( $tags['lineargradient'] ) ) {
322 - $tags['lineargradient'] = array(
323 - 'gradienttransform' => true,
324 - 'id' => true,
325 - );
326 - }
327 - if ( ! isset( $tags['stop'] ) ) {
328 - $tags['stop'] = array(
329 - 'offset' => true,
330 - 'stop-color' => true,
331 - 'style' => true,
332 - 'stop-opacity' => true,
333 - );
334 - }
335 - return $tags;
336 - }
337 397
338 - /**
339 - * Plugin activation callback.
340 - *
341 - * @since v.1.1.0
342 - * @param STRING $plugin The plugin file path.
343 - * @return NULL No return value.
398 + /**
399 + * Block Categories Initialization
400 + *
401 + * @since v.1.0.0
402 + * @param $categories(ARRAY) | $post (ARRAY)
403 + * @return NULL
344 404 */
345 - public function ultp_plugin_activation( $plugin ) {
346 - if ( wp_doing_ajax() ) {
347 - return;
348 - }
349 - if ( $plugin == 'ultimate-post/ultimate-post.php' ) {
350 - if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || isset( $_POST['action'] ) && 'activate-selected' == $_POST['action'] ) {
351 - return;
405 + public function register_category_callback( $categories, $post ) {
406 + $attr = array(
407 + array(
408 + 'slug' => 'ultimate-post',
409 + 'title' => __('PostX - Gutenberg Post Blocks', 'ultimate-post')
410 + ),
411 + array(
412 + 'slug' => 'postx-site-builder',
413 + 'title' => __('PostX Site Builder', 'ultimate-post')
414 + )
415 + );
416 + return array_merge($attr, $categories);
417 + }
418 +
419 +
420 + /**
421 + * Post View Counter for Every Post
422 + *
423 + * @since v.1.0.0
424 + * @param NUMBER | Post ID
425 + * @return NULL
426 + */
427 + public function popular_posts_tracker_callback($post_id) {
428 + if (!is_single()) { return; }
429 + global $post;
430 + $post_id = isset($post->ID) ? $post->ID : '';
431 + $isEnable = apply_filters('ultp_view_cookies', true);
432 + // add_filter( 'ultp_view_cookies', '__return_false' );
433 + $cookies_disable = ultimate_post()->get_setting('disable_view_cookies');
434 + if ($post_id && $isEnable && $cookies_disable != 'yes') {
435 + $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false;
436 + if (!$has_cookie) {
437 + $count = (int)get_post_meta( $post_id, '__post_views_count', true );
438 + update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
439 + setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
440 + }
441 + }
442 + }
443 +
444 +
445 + /**
446 + * Set Image Size
447 + *
448 + * @since v.1.0.0
449 + * @return NULL
450 + */
451 + public function add_image_size() {
452 + $size_disable = ultimate_post()->get_setting('disable_image_size');
453 + if ($size_disable != 'yes') {
454 + add_image_size('ultp_layout_landscape_large', 1200, 800, true);
455 + add_image_size('ultp_layout_landscape', 870, 570, true);
456 + add_image_size('ultp_layout_portrait', 600, 900, true);
457 + add_image_size('ultp_layout_square', 600, 600, true);
458 + }
459 + }
460 +
461 +
462 + /**
463 + * Include Addons Directory
464 + *
465 + * @since v.1.0.0
466 + * @return NULL
467 + */
468 + public function include_addons() {
469 + $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
470 + if (count($addons_dir) > 0) {
471 + foreach( $addons_dir as $key => $value ) {
472 + $addon_dir_name = str_replace(dirname($value).'/', '', $value);
473 + $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
474 + if (file_exists($file_name) ) {
475 + include_once $file_name;
476 + }
352 477 }
353 - if ( ultimate_post()->get_setting( 'init_setup' ) != 'yes' ) {
354 - ultimate_post()->set_setting( 'init_setup', 'yes' );
355 - exit(wp_safe_redirect(admin_url('admin.php?page=ultp-setup-wizard'))); //phpcs:ignore
356 - } else {
357 - exit(wp_safe_redirect(admin_url('admin.php?page=ultp-settings#home'))); //phpcs:ignore
358 - }
359 478 }
360 - }
479 + }
361 480
362 - /**
363 - * Enqueue option panel CSS and JS scripts.
364 - *
365 - * @since v.1.0.0
366 - * @return void No return value.
481 +
482 + /**
483 + * Addon Callback
484 + *
485 + * @since v.1.0.0
486 + * @return STRING
367 487 */
368 - public function register_option_panel_scripts_callback() {
369 - $is_active = ultimate_post()->is_lc_active();
370 - $is_expired = Xpo::is_lc_expired();
488 + public function ultp_addon_callback() {
489 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
490 + return ;
491 + }
492 + $addon_name = sanitize_text_field($_POST['addon']);
493 + $addon_value = sanitize_text_field($_POST['value']);
494 + if ($addon_name && current_user_can('administrator')) {
495 + $addon_data = ultimate_post()->get_setting();
496 + $addon_data[$addon_name] = $addon_value;
497 + $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
498 + update_option('ultp_options', $addon_data);
499 + }
500 + }
371 501
372 - $license_key = Xpo::get_lc_key();
373 - $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // @codingStandardsIgnoreLine
374 - $post_type = get_post_type();
375 - $is_woocommerce_active = class_exists( 'WooCommerce' ) ? true : false;
376 502
377 - wp_enqueue_style( 'wp-color-picker' );
378 - wp_enqueue_script( 'wp-color-picker' );
503 + /**
504 + * Next Preview Callback of the Blocks
505 + *
506 + * @since v.1.0.0
507 + * @return STRING
508 + */
509 + public function ultp_next_prev_callback() {
510 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
511 + return ;
512 + }
379 513
380 - wp_enqueue_script( 'ultp-option-script', ULTP_URL . 'assets/js/ultp-option.js', array( 'jquery' ), ULTP_VER, true );
381 - wp_enqueue_style( 'ultp-option-style', ULTP_URL . 'assets/css/ultp-option.css', array(), ULTP_VER );
382 - wp_localize_script(
383 - 'ultp-option-script',
384 - 'ultp_option_panel',
385 - array(
386 - 'url' => ULTP_URL,
387 - 'version' => ULTP_VER,
388 - 'active' => $is_active,
389 - 'expierd' => $is_expired,
390 - 'security' => wp_create_nonce( 'ultp-nonce' ),
391 - 'ajax' => admin_url( 'admin-ajax.php' ),
392 - 'settings' => ultimate_post()->get_setting(),
393 - 'post_type' => $post_type,
394 - 'saved_template_url' => admin_url( 'admin.php?page=ultp-settings#saved-templates' ),
395 - 'woocommerce' => $is_woocommerce_active,
396 - )
397 - );
514 + $paged = sanitize_text_field($_POST['paged']);
515 + $blockId = sanitize_text_field($_POST['blockId']);
516 + $postId = sanitize_text_field($_POST['postId']);
517 + $blockRaw = sanitize_text_field($_POST['blockName']);
518 + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
519 +
520 + $blockName = str_replace('_','/', $blockRaw);
398 521
399 - if ( $post_type == 'ultp_custom_font' ) {
400 - $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
401 - if ( $font_settings == 'true' ) {
402 - wp_enqueue_media();
403 - }
404 - }
522 + if ($paged && $blockId && $postId && $blockName ) {
523 + $post = get_post($postId);
524 + if (has_blocks($post->post_content)) {
525 + $blocks = parse_blocks($post->post_content);
526 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
527 + }
528 + }
529 + }
405 530
406 - /* === Installation Wizard === */
407 - if ( $_page == 'ultp-setup-wizard' ) {
408 - wp_enqueue_script( 'ultp-initial-setup-script', ULTP_URL . 'assets/js/ultp_initial_setup_min.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-api-request' ), ULTP_VER, true );
409 - wp_set_script_translations( 'ultp-initial-setup-script', 'ultimate-post', ULTP_PATH . 'languages/' );
410 - }
411 531
412 - /* === Builder And Setting Pannel === */
413 - if ( get_post_type( get_the_ID() ) == 'ultp_builder' ) {
414 - wp_enqueue_script( 'ultp-conditions-script', ULTP_URL . 'addons/builder/assets/js/conditions.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-components', 'wp-i18n', 'wp-blocks' ), ULTP_VER, true );
415 - wp_localize_script(
416 - 'ultp-conditions-script',
417 - 'ultp_condition',
418 - array(
419 - 'url' => ULTP_URL,
420 - 'active' => $is_active,
421 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
422 - )
423 - );
424 - wp_set_script_translations( 'ultp-conditions-script', 'ultimate-post', ULTP_PATH . 'languages/' );
425 - }
532 + /**
533 + * Filter Callback of the Blocks
534 + *
535 + * @since v.1.0.0
536 + * @return STRING
537 + */
538 + public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
539 + foreach ($blocks as $key => $value) {
540 + if ($blockName == $value['blockName']) {
541 + if ($value['attrs']['blockId'] == $blockId) {
542 + $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
543 + if ($taxonomy) {
544 + $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
545 + $value['attrs']['queryTax'] = $taxtype;
546 + $value['attrs']['ajaxCall'] = true;
547 + }
548 + if (isset($value['attrs']['queryNumber'])) {
549 + $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
550 + }
551 + $attr = array_merge($attr, $value['attrs']);
552 + echo $this->all_blocks[$blockRaw]->content($attr, true);
553 + die();
554 + }
555 + }
556 + if (!empty($value['innerBlocks'])) {
557 + $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
558 + }
559 + }
560 + }
426 561
427 - /* === Dashboard === */
428 - if ( $_page == 'ultp-settings' ) {
429 - wp_enqueue_script( 'ultp-dashboard-script', ULTP_URL . 'assets/js/ultp_dashboard_min.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-api-request', 'wp-components', 'wp-blocks' ), ULTP_VER, true );
430 - $user_info = get_userdata( get_current_user_id() );
431 - wp_localize_script(
432 - 'ultp-dashboard-script',
433 - 'ultp_dashboard_pannel',
434 - array_merge(
435 - array(
436 - 'ajax' => admin_url( 'admin-ajax.php' ),
437 - 'security' => wp_create_nonce( 'ultp-nonce' ),
438 - 'url' => ULTP_URL,
439 - 'active' => $is_active,
440 - 'expierd' => $is_expired,
441 - 'license' => $license_key,
442 - 'settings' => ultimate_post()->get_setting(),
443 - 'addons_settings' => apply_filters( 'ultp_settings', array() ),
444 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
445 - 'version' => ULTP_VER,
446 - 'setup_wizard_link' => admin_url( 'admin.php?page=ultp-setup-wizard' ),
447 - 'is_free' => ! $is_active,
448 - 'user_email' => wp_get_current_user()->user_email,
449 - 'home_url' => home_url(),
450 - 'generalDiscount' => get_transient( 'ultp_generalDiscount' ),
451 - 'helloBar' => Notice::get_hellobar_config(),
452 - 'userInfo' => array(
453 - 'name' => $user_info->first_name ? $user_info->first_name . ( $user_info->last_name ? ' ' . $user_info->last_name : '' ) : $user_info->user_login,
454 - 'email' => $user_info->user_email,
455 - ),
456 - ),
457 - Xpo::get_wow_products_details()
458 - )
459 - );
460 - wp_set_script_translations( 'ultp-dashboard-script', 'ultimate-post', ULTP_PATH . 'languages/' );
461 - }
462 - }
463 562
464 - /**
465 - * Enqueue backend CSS and JS scripts for the block editor.
466 - *
467 - * @since v.1.0.0
468 - * @return void No return value.
563 + /**
564 + * Filter Callback of the Blocks
565 + *
566 + * @since v.1.0.0
567 + * @return STRING
469 568 */
470 - public function register_block_scripts_editor_area() {
471 - ultimate_post()->register_scripts_common();
472 - $is_expired = Xpo::is_lc_expired();
473 - global $pagenow;
474 - $depends = 'wp-editor';
475 - if ( $pagenow === 'widgets.php' ) {
476 - $depends = 'wp-edit-widgets';
477 - }
478 - wp_enqueue_script( 'ultp-blocks-editor-script', ULTP_URL . 'assets/js/editor.blocks.js', array( 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true );
479 - wp_enqueue_style( 'ultp-blocks-editor-css', ULTP_URL . 'assets/css/blocks.editor.css', array(), ULTP_VER );
480 - if ( is_rtl() ) {
481 - wp_enqueue_style( 'ultp-blocks-editor-rtl-css', ULTP_URL . 'assets/css/rtl.css', array(), ULTP_VER );
482 - }
483 - $is_active = ultimate_post()->is_lc_active();
484 - $post_type = get_post_type();
569 + public function ultp_filter_callback() {
570 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
571 + return ;
572 + }
573 +
574 + $taxtype = sanitize_text_field($_POST['taxtype']);
575 + if ($taxtype ) {
576 + $blockId = sanitize_text_field($_POST['blockId']);
577 + $postId = sanitize_text_field($_POST['postId']);
578 + $taxonomy = sanitize_text_field($_POST['taxonomy']);
579 + $blockRaw = sanitize_text_field($_POST['blockName']);
580 + $blockName = str_replace('_','/', $blockRaw);
581 + $post = get_post($postId);
582 + if (has_blocks($post->post_content)) {
583 + $blocks = parse_blocks($post->post_content);
584 + $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
585 + }
586 + }
587 + }
485 588
486 - // Custom Font Support Added
487 - $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
488 - $custom_fonts = array();
489 - if ( $font_settings == 'true' ) {
490 - $args = array(
491 - 'post_type' => 'ultp_custom_font',
492 - 'post_status' => 'publish',
493 - 'numberposts' => -1,
494 - 'order' => 'ASC',
495 - );
496 - $posts = get_posts( $args );
497 - if ( $posts ) {
498 - foreach ( $posts as $post ) {
499 - setup_postdata( $post );
500 - $font = get_post_meta( $post->ID, '__font_settings', true );
501 589
502 - if ( $font ) {
503 - array_push(
504 - $custom_fonts,
505 - array(
506 - 'title' => $post->post_title,
507 - 'font' => $font,
508 - )
509 - );
510 - }
511 - }
512 - wp_reset_postdata();
513 - }
514 - }
590 + /**
591 + * Pagination of the Blocks
592 + *
593 + * @since v.1.0.0
594 + * @return STRING
595 + */
596 + public function ultp_pagination_callback() {
597 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local) {
598 + return ;
599 + }
515 600
516 - wp_localize_script(
517 - 'ultp-blocks-editor-script',
518 - 'ultp_data',
519 - array(
520 - 'url' => ULTP_URL,
521 - 'ajax' => admin_url( 'admin-ajax.php' ),
522 - 'security' => wp_create_nonce( 'ultp-nonce' ),
523 - 'hide_import_btn' => ultimate_post()->get_setting( 'hide_import_btn' ),
524 - 'premium_link' => Xpo::generate_utm_link(),
525 - 'license' => $is_active ? Xpo::get_lc_key() : '',
526 - 'active' => $is_active,
527 - 'archive' => ultimate_post()->is_archive_builder(),
528 - 'settings' => ultimate_post()->get_setting(),
529 - 'post_type' => $post_type == 'premade' ? 'ultp_builder' : $post_type, // premade used for ultp.wpxpo.com
530 - 'date_format' => get_option( 'date_format' ),
531 - 'time_format' => get_option( 'time_format' ),
532 - 'blog' => get_current_blog_id(),
533 - 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
534 - 'category_url' => admin_url( 'edit-tags.php?taxonomy=category' ),
535 - 'disable_image_size' => ultimate_post()->get_setting( 'disable_image_size' ),
536 - 'dark_logo' => get_option( 'ultp_site_dark_logo' ) ? get_option( 'ultp_site_dark_logo' ) : false,
537 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
538 - 'custom_fonts' => $custom_fonts,
539 - 'expierd' => $is_expired,
540 - )
541 - );
542 - wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
543 - }
601 + $paged = sanitize_text_field($_POST['paged']);
602 + if ($paged) {
603 + $blockId = sanitize_text_field($_POST['blockId']);
604 + $postId = sanitize_text_field($_POST['postId']);
605 + $blockRaw = sanitize_text_field($_POST['blockName']);
606 + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
607 + $blockName = str_replace('_','/', $blockRaw);
608 + $post = get_post($postId);
609 + if (has_blocks($post->post_content)) {
610 + $blocks = parse_blocks($post->post_content);
611 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
612 + }
613 + }
614 + }
544 615
616 + /**
617 + * share Count callback
618 + *
619 + * @since v.1.0.0
620 + * @return STRING
621 + */
622 + public function ultp_shareCount_callback() {
623 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
624 + return ;
625 + }
626 + $id = sanitize_text_field($_POST['postId']);
627 + $count = sanitize_text_field($_POST['shareCount']);
628 + $post_id = $id;
629 + $new_count = $count+1;
630 + update_post_meta($post_id, 'share_count', $new_count);
631 + }
545 632
546 - /**
547 - * Fire when plugin is first installed.
548 - *
549 - * @since v.1.0.0
550 - * @return void No return value.
633 + /**
634 + * Blocks Content Start
635 + *
636 + * @since v.1.0.0
637 + * @return STRING
551 638 */
552 - public function plugin_activation_hook() {
553 - $data = get_option( 'ultp_options', array() );
554 - $currentDate = new \DateTime();
555 - $currentDate->setTime( 0, 0, 0, 0 );
556 - $init_data = array(
557 - 'preloader_style' => 'style1',
558 - 'preloader_color' => '#037fff',
559 - 'container_width' => '1140',
560 - 'hide_import_btn' => '',
561 - 'disable_image_size' => '',
562 - 'disable_view_cookies' => '',
563 - 'disable_google_font' => '',
564 - 'ultp_templates' => 'true',
565 - 'ultp_elementor' => 'true',
566 - 'ultp_table_of_content' => 'true',
567 - 'ultp_builder' => 'true',
568 - 'ultp_dynamic_content' => 'true',
569 - 'ultp_custom_font' => 'true',
570 - 'ultp_chatgpt' => 'true',
571 - 'post_grid_1' => 'yes',
572 - 'post_grid_2' => 'yes',
573 - 'post_grid_3' => 'yes',
574 - 'post_grid_4' => 'yes',
575 - 'post_grid_5' => 'yes',
576 - 'post_grid_6' => 'yes',
577 - 'post_grid_7' => 'yes',
578 - 'post_list_1' => 'yes',
579 - 'post_list_2' => 'yes',
580 - 'post_list_3' => 'yes',
581 - 'post_list_4' => 'yes',
582 - 'post_module_1' => 'yes',
583 - 'post_module_2' => 'yes',
584 - 'post_slider_1' => 'yes',
585 - 'post_slider_2' => 'yes',
586 - 'heading' => 'yes',
587 - 'image' => 'yes',
588 - 'taxonomy' => 'yes',
589 - 'wrapper' => 'yes',
590 - 'news_ticker' => 'yes',
591 - 'accordion' => 'yes',
592 - 'star_rating' => 'yes',
593 - 'youtube_gallery' => 'yes',
594 - 'builder_advance_post_meta' => 'yes',
595 - 'builder_archive_title' => 'yes',
596 - 'builder_author_box' => 'yes',
597 - 'builder_post_next_previous' => 'yes',
598 - 'builder_post_author_meta' => 'yes',
599 - 'builder_post_breadcrumb' => 'yes',
600 - 'builder_post_category' => 'yes',
601 - 'builder_post_comment_count' => 'yes',
602 - 'builder_post_comments' => 'yes',
603 - 'builder_post_content' => 'yes',
604 - 'builder_post_date_meta' => 'yes',
605 - 'builder_post_excerpt' => 'yes',
606 - 'builder_post_featured_image' => 'yes',
607 - 'builder_post_reading_time' => 'yes',
608 - 'builder_post_social_share' => 'yes',
609 - 'builder_post_tag' => 'yes',
610 - 'builder_post_title' => 'yes',
611 - 'builder_post_view_count' => 'yes',
612 - 'save_version' => wp_rand( 1, 1000 ),
613 - 'activated_date' => $currentDate->getTimestamp(),
614 - );
615 - if ( empty( $data ) ) {
616 - update_option( 'ultp_options', $init_data );
617 - $GLOBALS['ultp_settings'] = $init_data;
618 - } else {
619 - foreach ( $init_data as $key => $single ) {
620 - if ( ! isset( $data[ $key ] ) ) {
621 - $data[ $key ] = $single;
622 - }
623 - }
624 - update_option( 'ultp_options', $data );
625 - $GLOBALS['ultp_settings'] = $data;
626 - }
627 - if ( ! get_transient( 'wpxpo_installation_date' ) ) {
628 - set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
629 - }
630 - }
631 -}
639 + public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId) {
640 + foreach ($blocks as $key => $value) {
641 + if ($blockName == $value['blockName']) {
642 + if ($value['attrs']['blockId'] == $blockId) {
643 + $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
644 + $value['attrs']['paged'] = $paged;
645 + if ($builder) {
646 + $value['attrs']['builder'] = $builder;
647 + }
648 + if ($postId) {
649 + $attr['current_post'] = $postId;
650 + }
651 + $attr = array_merge($attr, $value['attrs']);
652 + echo $this->all_blocks[$blockRaw]->content($attr, true);
653 + die();
654 + }
655 + }
656 + if (!empty($value['innerBlocks'])) {
657 + $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
658 + }
659 + }
660 + }
661 +
662 + /**
663 + * Save Settings of Option Panel
664 + *
665 + * @since v.2.6.0
666 + * @return NULL
667 + */
668 + public function save_plugin_settings_data() {
669 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
670 + return ;
671 + }
672 + $data = ultimate_post()->recursive_sanitize_text_field($_POST['data']);
673 + if (count($data) > 0) {
674 + foreach ($data as $key => $val) {
675 + ultimate_post()->set_setting($key, $val);
676 + }
677 + }
678 + wp_send_json_success(__('Settings Data Saved...', 'ultimate-post'));
679 + }
680 +
681 + /**
682 + * WordPress Plugin Notice
683 + *
684 + * @since v.2.6.4
685 + * @return NULL
686 + */
687 + public function in_plugin_settings_update_message() {
688 + $response = wp_remote_get(
689 + 'https://plugins.svn.wordpress.org/ultimate-post/trunk/readme.txt', array(
690 + 'method' => 'GET'
691 + ));
692 +
693 + if ( is_wp_error( $response ) || $response['response']['code'] != 200 ) {
694 + return;
695 + }
696 +
697 + $changelog_lines = preg_split("/(\r\n|\n|\r)/", $response['body']);
698 +
699 + $is_copy = false;
700 + $current_tag = '';
701 + $tag_text = 'Stable tag:';
702 + if (!empty($changelog_lines)) {
703 + echo '<div style="color:#cc0303;font-size:14px;font-weight:bold;">' . esc_html('PostX is ready for the next update. Here is the changelog:-') . '</div>';
704 + echo '<ul style="max-height:200px;overflow:scroll;display: grid;grid-template-columns: 1fr 1fr;grid-column-gap: 100px;">';
705 + $i = 0;
706 + foreach ($changelog_lines as $key => $line) {
707 + // Get Current Vesion
708 + if ($current_tag == '') {
709 + if (strpos($line, $tag_text) !== false) {
710 + $current_tag = trim(str_replace($tag_text, '', $line));
711 + }
712 + } else {
713 + if ($is_copy) {
714 + if (strpos($line, '= '.ULTP_VER) !== false) {
715 + break;
716 + }
717 + if (!empty($line)) {
718 + if (strpos($line, '= ') !== false) {
719 + if($i%2 == 1){
720 + echo '<li></li>';
721 + }
722 + }
723 + echo '<li>'.esc_html($line).'</li>';
724 + if (strpos($line, '= ') !== false) {
725 + echo '<li></li>';
726 + $i++;
727 + }
728 + }
729 + } else {
730 + if (strpos($line, '= '.$current_tag) !== false) { // Current Version
731 + $is_copy = true;
732 + echo '<li>'.esc_html($line).'</li><li></li>';
733 + }
734 + }
735 + }
736 + $i++;
737 + }
738 + echo '</ul>';
739 + }
740 + }
741 +
742 +
743 +}