Fns.php
3997 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Helper class. |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | namespace RT\ThePostGrid\Helpers; |
| 9 | |
| 10 | use RT\ThePostGrid\Models\Field; |
| 11 | use RT\ThePostGrid\Models\ReSizer; |
| 12 | |
| 13 | // Do not allow directly accessing this file. |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 'This script cannot be accessed directly.' ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Helper class. |
| 20 | */ |
| 21 | class Fns { |
| 22 | |
| 23 | /** |
| 24 | * Get Ajax URL. |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public function ajax_url() { |
| 29 | return admin_url( 'admin-ajax.php', 'relative' ); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * Render view |
| 35 | * |
| 36 | * @param string $viewName View name. |
| 37 | * @param array $args Args. |
| 38 | * @param boolean $return Include/return. |
| 39 | * |
| 40 | * @return string |
| 41 | */ |
| 42 | public static function view( $viewName, $args = [], $return = false ) { |
| 43 | $file = str_replace( '.', '/', $viewName ); |
| 44 | $file = ltrim( $file, '/' ); |
| 45 | $viewFile = trailingslashit( RT_THE_POST_GRID_PLUGIN_PATH . '/resources' ) . $file . '.php'; |
| 46 | |
| 47 | if ( ! file_exists( $viewFile ) ) { |
| 48 | return new \WP_Error( |
| 49 | 'brock', |
| 50 | sprintf( |
| 51 | /* translators: %s File name */ |
| 52 | esc_html__( '%s file not found', 'the-post-grid' ), |
| 53 | $viewFile |
| 54 | ) |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | if ( $args ) { |
| 59 | extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
| 60 | } |
| 61 | |
| 62 | if ( $return ) { |
| 63 | ob_start(); |
| 64 | include $viewFile; |
| 65 | |
| 66 | return ob_get_clean(); |
| 67 | } |
| 68 | |
| 69 | include $viewFile; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Update post view |
| 74 | * |
| 75 | * @param integer $post_id Listing ID. |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | public static function update_post_views_count( $post_id ) { |
| 80 | |
| 81 | if ( ! $post_id && is_admin() ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | $user_ip = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // retrieve the current IP address of the visitor. |
| 86 | $key = 'tpg_cache_' . $user_ip . '_' . $post_id; |
| 87 | $value = [ $user_ip, $post_id ]; |
| 88 | $visited = get_transient( $key ); |
| 89 | |
| 90 | |
| 91 | if ( false === ( $visited ) ) { |
| 92 | //set_transient( $key, $value, HOUR_IN_SECONDS * 12 ); // store the unique key, Post ID & IP address for 12 hours if it does not exist. |
| 93 | set_transient( $key, $value, HOUR_IN_SECONDS * 12 ); // store the unique key, Post ID & IP address for 12 hours if it does not exist. |
| 94 | |
| 95 | // now run post views function. |
| 96 | $count_key = self::get_post_view_count_meta_key(); |
| 97 | $count = get_post_meta( $post_id, $count_key, true ); |
| 98 | |
| 99 | if ( '' == $count ) { |
| 100 | update_post_meta( $post_id, $count_key, 1 ); |
| 101 | } else { |
| 102 | $count = absint( $count ); |
| 103 | $count ++; |
| 104 | |
| 105 | update_post_meta( $post_id, $count_key, $count ); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Template Content |
| 112 | * |
| 113 | * @param string $template_name Template name. |
| 114 | * @param array $args Arguments. (default: array). |
| 115 | * @param string $template_path Template path. (default: ''). |
| 116 | * @param string $default_path Default path. (default: ''). |
| 117 | */ |
| 118 | public static function get_template( $template_name, $args = null, $template_path = '', $default_path = '' ) { |
| 119 | if ( ! empty( $args ) && is_array( $args ) ) { |
| 120 | extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
| 121 | } |
| 122 | |
| 123 | $located = self::locate_template( $template_name, $template_path, $default_path ); |
| 124 | |
| 125 | if ( ! file_exists( $located ) ) { |
| 126 | /* translators: %s template */ |
| 127 | self::doing_it_wrong( __FUNCTION__, sprintf( esc_html__( '%s does not exist.', 'the-post-grid' ), '<code>' . $located . '</code>' ), '1.0' ); |
| 128 | |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // Allow 3rd party plugin filter template file from their plugin. |
| 133 | $located = apply_filters( 'rttpg_get_template', $located, $template_name, $args ); |
| 134 | |
| 135 | do_action( 'rttpg_before_template_part', $template_name, $located, $args ); |
| 136 | |
| 137 | include $located; |
| 138 | |
| 139 | do_action( 'rttpg_after_template_part', $template_name, $located, $args ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Get template content and return |
| 144 | * |
| 145 | * @param string $template_name Template name. |
| 146 | * @param array $args Arguments. (default: array). |
| 147 | * @param string $template_path Template path. (default: ''). |
| 148 | * @param string $default_path Default path. (default: ''). |
| 149 | * |
| 150 | * @return string |
| 151 | */ |
| 152 | public static function get_template_html( $template_name, $args = [], $template_path = '', $default_path = '' ) { |
| 153 | ob_start(); |
| 154 | self::get_template( $template_name, $args, $template_path, $default_path ); |
| 155 | |
| 156 | return ob_get_clean(); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Locate template. |
| 161 | * |
| 162 | * @param string $template_name Template. |
| 163 | * @param string $template_path Path. |
| 164 | * @param string $default_path Default path. |
| 165 | * |
| 166 | * @return mixed|void |
| 167 | */ |
| 168 | public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
| 169 | $template_name = $template_name . '.php'; |
| 170 | |
| 171 | if ( ! $template_path ) { |
| 172 | $template_path = rtTPG()->get_template_path(); |
| 173 | } |
| 174 | |
| 175 | if ( ! $default_path ) { |
| 176 | $default_path = rtTPG()->default_template_path() . '/templates/'; |
| 177 | } |
| 178 | |
| 179 | // Look within passed path within the theme - this is priority. |
| 180 | $template_files = []; |
| 181 | $template_files[] = trailingslashit( $template_path ) . $template_name; |
| 182 | |
| 183 | $template = locate_template( apply_filters( 'rttpg_locate_template_files', $template_files, $template_name, $template_path, $default_path ) ); |
| 184 | |
| 185 | // Get default template/. |
| 186 | if ( ! $template ) { |
| 187 | $template = trailingslashit( $default_path ) . $template_name; |
| 188 | } |
| 189 | |
| 190 | return apply_filters( 'rttpg_locate_template', $template, $template_name ); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Mark something as being incorrectly called. |
| 195 | * |
| 196 | * @param string $function — The function that was called. |
| 197 | * @param string $message — A message explaining what has been done incorrectly. |
| 198 | * @param string $version — The version of WordPress where the message was added. |
| 199 | * |
| 200 | * @return void |
| 201 | */ |
| 202 | public static function doing_it_wrong( $function, $message, $version ) { |
| 203 | // phpcs:disable |
| 204 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
| 205 | _doing_it_wrong( $function, $message, $version ); |
| 206 | // phpcs:enable |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Verify nonce. |
| 211 | * |
| 212 | * @return bool |
| 213 | */ |
| 214 | public static function verifyNonce() { |
| 215 | $nonce = isset( $_REQUEST[ rtTPG()->nonceId() ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ rtTPG()->nonceId() ] ) ) : null; |
| 216 | $nonceText = rtTPG()->nonceText(); |
| 217 | |
| 218 | if ( ! wp_verify_nonce( $nonce, $nonceText ) ) { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * @param $data |
| 227 | * @param $temp_path |
| 228 | * |
| 229 | * @return void |
| 230 | */ |
| 231 | public static function tpg_template( $data, $temp_path = 'elementor' ) { |
| 232 | $layout = str_replace( '-2', '', $data['layout'] ); |
| 233 | |
| 234 | $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php'; |
| 235 | if ( file_exists( STYLESHEETPATH . $template_name ) ) { |
| 236 | $file = STYLESHEETPATH . $template_name; |
| 237 | } else if ( file_exists( TEMPLATEPATH . $template_name ) ) { |
| 238 | $file = TEMPLATEPATH . $template_name; |
| 239 | } else { |
| 240 | $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; |
| 241 | if ( ! file_exists( $file ) ) { |
| 242 | if ( rtTPG()->hasPro() ) { |
| 243 | $file = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; |
| 244 | } else { |
| 245 | $layout = substr( $layout, 0, - 1 ); |
| 246 | $layout = strpos( $layout, '1' ) ? str_replace( '1', '', $layout ) : $layout; |
| 247 | $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '1.php'; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | ob_start(); |
| 253 | include $file; |
| 254 | echo ob_get_clean(); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @param $data |
| 259 | * |
| 260 | * @return string |
| 261 | */ |
| 262 | public static function tpg_template_path( $data, $temp_path = 'elementor' ) { |
| 263 | $layout = str_replace( '-2', '', $data['layout'] ); |
| 264 | $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php'; |
| 265 | $path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/'; |
| 266 | if ( file_exists( STYLESHEETPATH . $template_name ) ) { |
| 267 | $path = STYLESHEETPATH . '/the-post-grid/' . $temp_path . '/'; |
| 268 | } else if ( file_exists( TEMPLATEPATH . $template_name ) ) { |
| 269 | $path = TEMPLATEPATH . '/the-post-grid/' . $temp_path . '/'; |
| 270 | } else { |
| 271 | $template_path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; |
| 272 | |
| 273 | if ( ! file_exists( $template_path ) && rtTPG()->hasPro() ) { |
| 274 | $path = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/'; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | return $path; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Get Post Pagination, Load more & Scroll markup |
| 283 | * |
| 284 | * @param $query |
| 285 | * @param $data |
| 286 | * |
| 287 | * @return false|string|void |
| 288 | */ |
| 289 | public static function get_pagination_markup( $query, $data ) { |
| 290 | if ( 'show' !== $data['show_pagination'] ) { |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | $htmlUtility = null; |
| 295 | |
| 296 | $posts_loading_type = $data['pagination_type']; |
| 297 | |
| 298 | $posts_per_page = ( isset( $data['display_per_page'] ) && $data['display_per_page'] ) ? $data['display_per_page'] |
| 299 | : ( $data['post_limit'] ? $data['post_limit'] : get_option( 'posts_per_page' ) ); |
| 300 | $hide = ( $query->max_num_pages < 2 ? " rt-hidden-elm" : null ); |
| 301 | |
| 302 | if ( $posts_loading_type == "pagination" ) { |
| 303 | $htmlUtility .= Fns::rt_pagination( $query, $posts_per_page ); |
| 304 | } else if ( rtTPG()->hasPro() && $posts_loading_type == "pagination_ajax" ) { //&& ! $isIsotope |
| 305 | $htmlUtility .= "<div class='rt-page-numbers'></div>"; |
| 306 | } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_more" ) { |
| 307 | $load_more_button_text = $data['load_more_button_text'] ? $data['load_more_button_text'] : __( "Load More", 'the-post-grid' ); |
| 308 | $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'> |
| 309 | <span class='rt-loadmore-text'>" . $load_more_button_text . "</span> |
| 310 | <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div> |
| 311 | </div>"; |
| 312 | } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_on_scroll" ) { |
| 313 | $htmlUtility .= "<div class='rt-infinite-action'> |
| 314 | <div class='rt-infinite-loading la-fire la-2x'> |
| 315 | <div></div><div></div><div></div> |
| 316 | </div> |
| 317 | </div>"; |
| 318 | } |
| 319 | |
| 320 | if ( $htmlUtility ) { |
| 321 | $html = "<div class='rt-pagination-wrap' data-total-pages='{$query->max_num_pages}' data-posts-per-page='{$posts_per_page}' data-type='{$posts_loading_type}' >" |
| 322 | . $htmlUtility . "</div>"; |
| 323 | |
| 324 | return $html; |
| 325 | } |
| 326 | |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * @param $data |
| 332 | * @param $total_pages |
| 333 | * @param $posts_per_page |
| 334 | * @param $_prefix |
| 335 | * @param $is_gutenberg |
| 336 | * |
| 337 | * @return array |
| 338 | */ |
| 339 | public static function get_render_data_set( $data, $total_pages, $posts_per_page, $_prefix, $is_gutenberg = '' ) { |
| 340 | |
| 341 | $data_set = [ |
| 342 | 'block_type' => 'elementor', |
| 343 | 'is_gutenberg' => $is_gutenberg, |
| 344 | 'prefix' => $_prefix, |
| 345 | 'grid_column' => isset( $data[ $_prefix . '_column' ] ) ? $data[ $_prefix . '_column' ] : '0', |
| 346 | 'grid_column_tablet' => isset( $data[ $_prefix . '_column_tablet' ] ) ? $data[ $_prefix . '_column_tablet' ] : '0', |
| 347 | 'grid_column_mobile' => isset( $data[ $_prefix . '_column_mobile' ] ) ? $data[ $_prefix . '_column_mobile' ] : '0', |
| 348 | 'layout' => $data[ $_prefix . '_layout' ], |
| 349 | 'pagination_type' => 'slider' === $_prefix ? 'slider' : $data['pagination_type'], |
| 350 | 'total_pages' => $total_pages, |
| 351 | 'posts_per_page' => $posts_per_page, |
| 352 | 'layout_style' => isset( $data[ $_prefix . '_layout_style' ] ) ? $data[ $_prefix . '_layout_style' ] : '', |
| 353 | 'show_title' => $data['show_title'], |
| 354 | 'excerpt_type' => $data['excerpt_type'], |
| 355 | 'excerpt_limit' => $data['excerpt_limit'], |
| 356 | 'excerpt_more_text' => $data['excerpt_more_text'], |
| 357 | 'title_limit' => $data['title_limit'], |
| 358 | 'title_limit_type' => $data['title_limit_type'], |
| 359 | 'title_visibility_style' => $data['title_visibility_style'], |
| 360 | 'post_link_type' => $data['post_link_type'], |
| 361 | 'link_target' => $data['link_target'], |
| 362 | 'hover_animation' => isset( $data['hover_animation'] ) ? $data['hover_animation'] : '', |
| 363 | 'show_thumb' => $data['show_thumb'], |
| 364 | 'show_meta' => $data['show_meta'], |
| 365 | 'show_author' => $data['show_author'], |
| 366 | 'show_author_image' => $data['show_author_image'], |
| 367 | 'author_icon_visibility' => $data['author_icon_visibility'], |
| 368 | 'show_meta_icon' => $data['show_meta_icon'], |
| 369 | 'show_category' => $data['show_category'], |
| 370 | 'show_date' => $data['show_date'], |
| 371 | 'show_tags' => $data['show_tags'], |
| 372 | 'show_comment_count' => $data['show_comment_count'], |
| 373 | 'show_comment_count_label' => isset( $data['show_comment_count_label'] ) ? $data['show_comment_count_label'] : '', |
| 374 | 'comment_count_label_singular' => isset( $data['comment_count_label_singular'] ) ? $data['comment_count_label_singular'] : '', |
| 375 | 'comment_count_label_plural' => isset( $data['comment_count_label_plural'] ) ? $data['comment_count_label_plural'] : '', |
| 376 | 'show_post_count' => $data['show_post_count'], |
| 377 | 'post_count_icon' => isset( $data['post_count_icon'] ) ? $data['post_count_icon'] : '', |
| 378 | 'show_excerpt' => $data['show_excerpt'], |
| 379 | 'show_read_more' => $data['show_read_more'], |
| 380 | 'show_btn_icon' => $data['show_btn_icon'], |
| 381 | 'show_social_share' => $data['show_social_share'], |
| 382 | 'show_cat_icon' => isset( $data['show_cat_icon'] ) ? $data['show_cat_icon'] : '', |
| 383 | 'is_thumb_linked' => $data['is_thumb_linked'], |
| 384 | 'media_source' => $data['media_source'], |
| 385 | 'no_posts_found_text' => isset( $data['no_posts_found_text'] ) ? esc_html( $data['no_posts_found_text'] ) : '', |
| 386 | 'image_size' => $data['image_size'], |
| 387 | 'image_offset' => $data['image_offset_size'], |
| 388 | 'is_default_img' => $data['is_default_img'], |
| 389 | 'default_image' => $data['default_image'], |
| 390 | 'thumb_overlay_visibility' => isset( $data['thumb_overlay_visibility'] ) ? $data['thumb_overlay_visibility'] : '', |
| 391 | 'overlay_type' => isset( $data['overlay_type'] ) ? $data['overlay_type'] : '', |
| 392 | 'title_tag' => $data['title_tag'], |
| 393 | 'post_type' => $data['post_type'], |
| 394 | 'meta_separator' => $data['meta_separator'], |
| 395 | 'readmore_icon_position' => $data['readmore_icon_position'], |
| 396 | 'read_more_label' => $data['read_more_label'], |
| 397 | 'readmore_btn_icon' => $data['readmore_btn_icon'], |
| 398 | 'category_position' => $data['category_position'], |
| 399 | 'title_position' => isset( $data['title_position'] ) ? $data['title_position'] : 'default', |
| 400 | 'category_style' => isset( $data['category_style'] ) ? $data['category_style'] : '', |
| 401 | 'is_thumb_lightbox' => $data['is_thumb_lightbox'], |
| 402 | 'author_prefix' => $data['author_prefix'], |
| 403 | 'cat_icon' => isset( $data['cat_icon'] ) ? $data['cat_icon'] : '', |
| 404 | 'tag_icon' => isset( $data['tag_icon'] ) ? $data['tag_icon'] : '', |
| 405 | 'date_icon' => isset( $data['date_icon'] ) ? $data['date_icon'] : '', |
| 406 | 'user_icon' => isset( $data['user_icon'] ) ? $data['user_icon'] : '', |
| 407 | 'meta_ordering' => $data['meta_ordering'], |
| 408 | 'comment_icon' => isset( $data['comment_icon'] ) ? $data['comment_icon'] : '', |
| 409 | 'image_custom_dimension' => ( $data['image_size'] == 'custom' && isset( $data['image_custom_dimension'] ) ) ? $data['image_custom_dimension'] : [], |
| 410 | 'img_crop_style' => ( $data['image_size'] == 'custom' && isset( $data['img_crop_style'] ) ) ? $data['img_crop_style'] : '', |
| 411 | 'show_acf' => isset( $data['show_acf'] ) ? $data['show_acf'] : '', |
| 412 | ]; |
| 413 | |
| 414 | $cf = Fns::is_acf(); |
| 415 | if ( $cf && rtTPG()->hasPro() ) { |
| 416 | $post_type = $data['post_type']; |
| 417 | if ( $is_gutenberg && isset( $data['acf_data_lists'][ $post_type . '_cf_group' ] ) ) { |
| 418 | $cf_group = $data['acf_data_lists'][ $post_type . '_cf_group' ]['options']; |
| 419 | $data_set['cf_group'] = wp_list_pluck( $cf_group, 'value' ); |
| 420 | } else { |
| 421 | $data_set['cf_group'] = $data[ $post_type . '_cf_group' ]; |
| 422 | } |
| 423 | $data_set['cf_hide_empty_value'] = $data['cf_hide_empty_value']; |
| 424 | $data_set['cf_show_only_value'] = $data['cf_show_only_value']; |
| 425 | $data_set['cf_hide_group_title'] = $data['cf_hide_group_title']; |
| 426 | } |
| 427 | if ( $is_gutenberg ) { |
| 428 | unset( $data_set['grid_column'] ); |
| 429 | unset( $data_set['grid_column_mobile'] ); |
| 430 | unset( $data_set['grid_column_mobile'] ); |
| 431 | unset( $data_set['layout_style'] ); |
| 432 | $data_set['c_image_width'] = isset( $data['c_image_width'] ) ? $data['c_image_width'] : ''; |
| 433 | $data_set['c_image_height'] = isset( $data['c_image_height'] ) ? $data['c_image_height'] : ''; |
| 434 | $data_set['grid_column'] = (array) $data['grid_column']; |
| 435 | $data_set['layout_style'] = $data['grid_layout_style']; |
| 436 | } |
| 437 | |
| 438 | return $data_set; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | /** |
| 443 | * Get Filter markup |
| 444 | * |
| 445 | * @param $data |
| 446 | * |
| 447 | * @return string |
| 448 | */ |
| 449 | public static function get_frontend_filter_markup( $data, $is_guten = false ) { |
| 450 | if ( ! rtTPG()->hasPro() |
| 451 | || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show' |
| 452 | || $data['show_sort_order'] == 'show' |
| 453 | || $data['show_search'] == 'show' ) |
| 454 | ) { |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | $html = null; |
| 459 | $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = ''; |
| 460 | |
| 461 | if ( 'carousel' === $data['filter_btn_style'] ) { |
| 462 | $wrapperContainer = 'swiper'; |
| 463 | $wrapperClass = 'swiper-wrapper'; |
| 464 | $itemClass = 'swiper-slide'; |
| 465 | $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto'; |
| 466 | $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto'; |
| 467 | $filter_btn_item_per_page |
| 468 | = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'"; |
| 469 | } |
| 470 | |
| 471 | $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>"; |
| 472 | |
| 473 | if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { |
| 474 | $html .= "<div class='filter-left-wrapper {$wrapperContainer}' {$filter_btn_item_per_page}>"; |
| 475 | } |
| 476 | // if($data['filter_btn_style'] == 'carousel') { |
| 477 | // $html .= "<div class='swiper-pagination'></div>"; |
| 478 | // } |
| 479 | $selectedSubTermsForButton = null; |
| 480 | |
| 481 | $filterType = $data['filter_type']; |
| 482 | $post_count = ( 'yes' == $data['filter_post_count'] ) ? true : false; |
| 483 | |
| 484 | |
| 485 | if ( 'show' == $data['show_taxonomy_filter'] ) { |
| 486 | $postCountClass = ( $post_count ? " has-post-count" : null ); |
| 487 | $allSelect = " selected"; |
| 488 | $isTermSelected = false; |
| 489 | |
| 490 | $taxFilterOperator = $data['relation']; |
| 491 | |
| 492 | $taxonomy_label = $default_term = ''; |
| 493 | if ( $is_guten ) { |
| 494 | $taxFilter = $data['filter_taxonomy']; |
| 495 | } else { |
| 496 | $section_term_key = $data['post_type'] . '_filter_taxonomy'; |
| 497 | $taxFilter = $data[ $section_term_key ]; |
| 498 | } |
| 499 | |
| 500 | if ( $taxFilter ) { |
| 501 | $taxonomy_details = get_taxonomy( $taxFilter ); |
| 502 | $taxonomy_label = $taxonomy_details->label; |
| 503 | $default_term_key = $taxFilter . '_default_terms'; |
| 504 | $default_term = isset( $data[ $default_term_key ] ) ? $data[ $default_term_key ] : ''; |
| 505 | } |
| 506 | |
| 507 | $allText = $data['tax_filter_all_text'] ? $data['tax_filter_all_text'] : __( "All ", "the-post-grid" ) . $taxonomy_label; |
| 508 | |
| 509 | |
| 510 | $_taxonomies = get_object_taxonomies( $data['post_type'], 'objects' ); |
| 511 | $terms = []; |
| 512 | |
| 513 | foreach ( $_taxonomies as $index => $object ) { |
| 514 | if ( $object->name != $taxFilter ) { |
| 515 | continue; |
| 516 | } |
| 517 | $setting_key = $object->name . '_ids'; |
| 518 | |
| 519 | if ( $is_guten && ! empty( $data['taxonomy_lists'][ $object->name ]['options'] ) ) { |
| 520 | //This block execute if gutenberg editor has taxonomy query |
| 521 | $terms = wp_list_pluck( $data['taxonomy_lists'][ $object->name ]['options'], 'value' ); |
| 522 | } else if ( ! empty( $data[ $setting_key ] ) ) { |
| 523 | //This block execute for Elementor editor has taxonomy query |
| 524 | $terms = $data[ $setting_key ]; |
| 525 | } else { |
| 526 | //Execute if there is no taxonomy query |
| 527 | $terms = get_terms( [ |
| 528 | 'taxonomy' => $taxFilter, |
| 529 | 'fields' => 'ids', |
| 530 | ] ); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | $taxFilterTerms = $terms; |
| 535 | |
| 536 | if ( $default_term && $taxFilter ) { |
| 537 | $isTermSelected = true; |
| 538 | $allSelect = null; |
| 539 | } |
| 540 | |
| 541 | if ( $filterType == 'dropdown' ) { |
| 542 | $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>"; |
| 543 | $termDefaultText = $allText; |
| 544 | $dataTerm = 'all'; |
| 545 | $htmlButton = ""; |
| 546 | $selectedSubTerms = null; |
| 547 | $pCount = 0; |
| 548 | |
| 549 | |
| 550 | if ( ! empty( $terms ) ) { |
| 551 | $i = 0; |
| 552 | foreach ( $terms as $term_id ) { |
| 553 | $term = get_term( $term_id, $taxFilter, ARRAY_A ); |
| 554 | $id = $term['term_id']; |
| 555 | $pCount = $pCount + $term['count']; |
| 556 | $sT = null; |
| 557 | if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' ) { |
| 558 | $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); |
| 559 | if ( ! empty( $subTerms ) ) { |
| 560 | $count = 0; |
| 561 | $item = $allCount = null; |
| 562 | foreach ( $subTerms as $stId => $t ) { |
| 563 | $count = $count + absint( $t['count'] ); |
| 564 | $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null ); |
| 565 | $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>"; |
| 566 | } |
| 567 | if ( $post_count ) { |
| 568 | $allCount = " (<span class='rt-post-count'>{$count}</span>)"; |
| 569 | } |
| 570 | $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>"; |
| 571 | $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'> |
| 572 | <span class='rt-text'>" . $allText . "</span> |
| 573 | <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i> |
| 574 | </span>"; |
| 575 | $sT .= '<span class="term-dropdown rt-filter-dropdown">'; |
| 576 | $sT .= $item; |
| 577 | $sT .= '</span>'; |
| 578 | $sT .= "</div>"; |
| 579 | } |
| 580 | if ( $default_term === $id ) { |
| 581 | $selectedSubTerms = $sT; |
| 582 | } |
| 583 | } |
| 584 | $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null ); |
| 585 | if ( $default_term && $default_term == $id ) { |
| 586 | $termDefaultText = $term['name'] . $postCount; |
| 587 | $dataTerm = $id; |
| 588 | } |
| 589 | if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { |
| 590 | if ( in_array( $id, $taxFilterTerms ) ) { |
| 591 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>"; |
| 592 | } |
| 593 | } else { |
| 594 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>"; |
| 595 | } |
| 596 | $i ++; |
| 597 | } |
| 598 | } |
| 599 | $pAllCount = null; |
| 600 | if ( $post_count ) { |
| 601 | $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)"; |
| 602 | if ( ! $default_term ) { |
| 603 | $termDefaultText = $termDefaultText; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if ( 'yes' == $data['tpg_hide_all_button'] ) { |
| 608 | $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . "</span></span>" |
| 609 | . $htmlButton; |
| 610 | } |
| 611 | $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton ); |
| 612 | |
| 613 | $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '"> |
| 614 | <span class="rt-text">' . $termDefaultText . '</span> |
| 615 | <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i> |
| 616 | </span>'; |
| 617 | |
| 618 | $html .= $showAllhtml . $htmlButton; |
| 619 | $html .= '</div>' . $selectedSubTerms; |
| 620 | } else { |
| 621 | //if Button the execute |
| 622 | //$termDefaultText = $allText; |
| 623 | |
| 624 | $bCount = 0; |
| 625 | $bItems = null; |
| 626 | |
| 627 | if ( ! empty( $terms ) ) { |
| 628 | foreach ( $terms as $term_id ) { |
| 629 | $term = get_term( $term_id, $taxFilter, ARRAY_A ); |
| 630 | if ( ! isset( $term['term_id'] ) ) { |
| 631 | continue; |
| 632 | } |
| 633 | $id = $term['term_id']; |
| 634 | $bCount = $bCount + absint( $term['count'] ); |
| 635 | $sT = null; |
| 636 | if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' && $data['filter_btn_style'] === 'default' && $data['filter_type'] == 'button' ) { |
| 637 | $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); |
| 638 | if ( ! empty( $subTerms ) ) { |
| 639 | $sT .= "<div class='rt-filter-sub-tax sub-button-group '>"; |
| 640 | foreach ( $subTerms as $stId => $t ) { |
| 641 | $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null ); |
| 642 | $sT .= "<span class='term-button-item rt-filter-button-item ' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>"; |
| 643 | } |
| 644 | $sT .= "</div>"; |
| 645 | if ( $default_term === $id ) { |
| 646 | $selectedSubTermsForButton = $sT; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null ); |
| 651 | $termSelected = null; |
| 652 | if ( $isTermSelected && $id == $default_term ) { |
| 653 | $termSelected = " selected"; |
| 654 | } |
| 655 | if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { |
| 656 | if ( in_array( $id, $taxFilterTerms ) ) { |
| 657 | $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>"; |
| 658 | } |
| 659 | } else { |
| 660 | $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>"; |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass} {$wrapperClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>"; |
| 665 | |
| 666 | //$pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null ); |
| 667 | if ( 'yes' == $data['tpg_hide_all_button'] ) { |
| 668 | $html .= "<span class='term-button-item rt-filter-button-item {$allSelect} {$itemClass}' data-term='all'>" . $allText . "</span>"; |
| 669 | } |
| 670 | |
| 671 | $html .= $bItems; |
| 672 | |
| 673 | $html .= "</div>"; |
| 674 | if ( 'carousel' === $data['filter_btn_style'] ) { |
| 675 | $html .= '<div class="swiper-navigation"><div class="swiper-button-prev slider-btn"></div><div class="swiper-button-next slider-btn"></div></div>'; |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | // TODO: Author filter |
| 681 | if ( 'show' == $data['show_author_filter'] ) { |
| 682 | $user_el = $data['author']; |
| 683 | |
| 684 | $filterAuthors = $user_el; |
| 685 | |
| 686 | if ( ! empty( $user_el ) ) { |
| 687 | $users = get_users( apply_filters( 'tpg_author_arg', [ 'include' => $user_el ] ) ); |
| 688 | } else { |
| 689 | $users = get_users( apply_filters( 'tpg_author_arg', [] ) ); |
| 690 | } |
| 691 | $allText = $allText = $data['author_filter_all_text'] ? $data['author_filter_all_text'] : __( "All Users", "the-post-grid" ); |
| 692 | $allSelect = " selected"; |
| 693 | //$isTermSelected = false; |
| 694 | // if ( $default_term && $taxFilter ) { |
| 695 | $isTermSelected = true; |
| 696 | // $allSelect = null; |
| 697 | // } |
| 698 | if ( $filterType == 'dropdown' ) { |
| 699 | $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-filter='author'>"; |
| 700 | $termDefaultText = $allText; |
| 701 | $dataAuthor = 'all'; |
| 702 | $htmlButton = ""; |
| 703 | $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">'; |
| 704 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . "</span>"; |
| 705 | |
| 706 | if ( ! empty( $users ) ) { |
| 707 | foreach ( $users as $user ) { |
| 708 | $user_post_count = false; |
| 709 | $post_count ? "(" . count_user_posts( $user->ID, $data['post_type'] ) . ")" : null; |
| 710 | if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { |
| 711 | if ( in_array( $user->ID, $filterAuthors ) ) { |
| 712 | if ( $default_term == $user->ID ) { |
| 713 | $termDefaultText = $user->display_name; |
| 714 | $dataTerm = $user->ID; |
| 715 | } else { |
| 716 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name} <span class='rt-text'>{$user_post_count}</span></span>"; |
| 717 | } |
| 718 | } |
| 719 | } else { |
| 720 | if ( $default_term == $user->ID ) { |
| 721 | $termDefaultText = $user->display_name; |
| 722 | $dataTerm = $user->ID; |
| 723 | } else { |
| 724 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'><span class='rt-text'>{$user->display_name} {$user_post_count}</span></span>"; |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | |
| 731 | $htmlButton .= '</span>'; |
| 732 | |
| 733 | $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '"> |
| 734 | <span class="rt-text">' . $termDefaultText . '</span> |
| 735 | <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i> |
| 736 | </span>'; |
| 737 | |
| 738 | $html .= $showAllhtml . $htmlButton; |
| 739 | $html .= '</div>'; |
| 740 | } else { |
| 741 | $bCount = 0; |
| 742 | $bItems = null; |
| 743 | |
| 744 | if ( ! empty( $users ) ) { |
| 745 | foreach ( $users as $user ) { |
| 746 | if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { |
| 747 | if ( in_array( $user->ID, $filterAuthors ) ) { |
| 748 | $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>"; |
| 749 | } |
| 750 | } else { |
| 751 | $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>"; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-filter='author'>"; |
| 757 | // if ( 'yes' == $data['tax_filter_all_text'] ) { |
| 758 | //$pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null ); |
| 759 | $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . "</span>"; |
| 760 | // } |
| 761 | $html .= $bItems; |
| 762 | $html .= "</div>"; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | |
| 767 | if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { |
| 768 | $html .= "</div>"; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { |
| 773 | $html .= "<div class='filter-right-wrapper'>"; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | // TODO: Order Filter |
| 778 | if ( 'show' == $data['show_sort_order'] ) { |
| 779 | $action_order = ( $data['order'] ? strtoupper( $data['order'] ) : "DESC" ); |
| 780 | $html .= '<div class="rt-filter-item-wrap rt-sort-order-action" data-filter="order">'; |
| 781 | $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'> <span></span></span>"; |
| 782 | $html .= '</div>'; |
| 783 | } |
| 784 | |
| 785 | //TODO: Orderby Filter |
| 786 | if ( 'show' == $data['show_order_by'] ) { |
| 787 | $wooFeature = ( $data['post_type'] == "product" ? true : false ); |
| 788 | $orders = Options::rtPostOrderBy( $wooFeature ); |
| 789 | $action_orderby = ( ! empty( $data['orderby'] ) ? $data['orderby'] : "none" ); |
| 790 | if ( $action_orderby == 'none' ) { |
| 791 | $action_orderby_label = __( "Sort By", "the-post-grid" ); |
| 792 | } else if ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) { |
| 793 | $action_orderby_label = __( "Meta value", "the-post-grid" ); |
| 794 | } else { |
| 795 | $action_orderby_label = __( "By ", "the-post-grid" ) . $action_orderby; |
| 796 | } |
| 797 | if ( $action_orderby !== 'none' ) { |
| 798 | $orders['none'] = __( "Sort By", "the-post-grid" ); |
| 799 | } |
| 800 | $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap" data-filter="orderby">'; |
| 801 | $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'> |
| 802 | <span class='rt-text-order-by'>{$action_orderby_label}</span> |
| 803 | <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i> |
| 804 | </span>"; |
| 805 | $html .= '<span class="order-by-dropdown rt-filter-dropdown">'; |
| 806 | |
| 807 | foreach ( $orders as $orderKey => $order ) { |
| 808 | $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>'; |
| 809 | } |
| 810 | $html .= '</span>'; |
| 811 | $html .= '</div>'; |
| 812 | } |
| 813 | |
| 814 | //TODO: Search Filter |
| 815 | if ( 'show' == $data['show_search'] ) { |
| 816 | $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap" data-filter="search">'; |
| 817 | $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( "Search...", 'the-post-grid' ) ); |
| 818 | $html .= "<span class='rt-action'>🔍</span>"; |
| 819 | $html .= "<span class='rt-loading'></span>"; |
| 820 | $html .= '</div>'; |
| 821 | } |
| 822 | |
| 823 | if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { |
| 824 | $html .= "</div>"; |
| 825 | } |
| 826 | |
| 827 | $html .= "</div>$selectedSubTermsForButton</div>"; |
| 828 | |
| 829 | return $html; |
| 830 | } |
| 831 | |
| 832 | |
| 833 | /** |
| 834 | * Get Excluded Taxonomy |
| 835 | * |
| 836 | * @return string[] |
| 837 | */ |
| 838 | public static function get_excluded_taxonomy() { |
| 839 | return [ |
| 840 | 'post_format', |
| 841 | 'nav_menu', |
| 842 | 'link_category', |
| 843 | 'wp_theme', |
| 844 | 'elementor_library_type', |
| 845 | 'elementor_library_type', |
| 846 | 'elementor_library_category', |
| 847 | 'product_visibility', |
| 848 | 'product_shipping_class', |
| 849 | ]; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Get Popup Modal Markup |
| 854 | */ |
| 855 | public static function get_modal_markup() { |
| 856 | $html = null; |
| 857 | $html .= '<div class="md-modal rt-md-effect" id="rt-modal"> |
| 858 | <div class="md-content"> |
| 859 | <div class="rt-md-content-holder"></div> |
| 860 | <div class="md-cls-btn"> |
| 861 | <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button> |
| 862 | </div> |
| 863 | </div> |
| 864 | </div>'; |
| 865 | $html .= "<div class='md-overlay'></div>"; |
| 866 | echo $html; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Get Archive page title |
| 871 | */ |
| 872 | public static function get_archive_title() { |
| 873 | $queried_obj = get_queried_object(); |
| 874 | if ( is_tag() || is_category() ) { |
| 875 | echo esc_html( $queried_obj->name ); |
| 876 | } else if ( is_author() ) { |
| 877 | echo esc_html( $queried_obj->display_name ); |
| 878 | } else if ( is_date() ) { |
| 879 | $year = get_query_var( 'year' ); |
| 880 | $monthnum = get_query_var( 'monthnum' ); |
| 881 | $day = get_query_var( 'day' ); |
| 882 | $time_string = $year . '/' . $monthnum . '/' . $day; |
| 883 | $time_stamp = strtotime( $time_string ); |
| 884 | echo date( get_option( 'date_format' ), $time_stamp ); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Get Last Category ID |
| 890 | * |
| 891 | * @return mixed |
| 892 | */ |
| 893 | public static function get_last_category_id() { |
| 894 | if ( is_archive() ) { |
| 895 | return; |
| 896 | } |
| 897 | $categories = get_terms( [ |
| 898 | 'taxonomy' => 'category', |
| 899 | 'hide_empty' => false, |
| 900 | 'number' => 1, |
| 901 | ] ); |
| 902 | if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) { |
| 903 | return $categories[0]->term_id; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * @param $data |
| 909 | * |
| 910 | * @return string |
| 911 | */ |
| 912 | public static function get_dynamic_class_gutenberg( $data ) { |
| 913 | $uniqueId = isset( $data['uniqueId'] ) ? $data['uniqueId'] : null; |
| 914 | $uniqueClass = 'rttpg-block-postgrid rttpg-block-wrapper rttpg-block-' . $uniqueId; |
| 915 | $dynamicClass = $uniqueClass; |
| 916 | $dynamicClass .= ! empty( $data['align'] ) ? ' align' . $data['align'] : null; |
| 917 | $dynamicClass .= ! empty( $data['className'] ) ? ' ' . $data['className'] : null; |
| 918 | $dynamicClass .= ! empty( $data['full_wrapper_align']['lg'] ) ? " tpg-wrapper-align-{$data['full_wrapper_align']['lg']}" : null; |
| 919 | $dynamicClass .= ! empty( $data['filter_type'] ) ? " tpg-filter-type-{$data['filter_type']}" : null; |
| 920 | $dynamicClass .= ! empty( $data['show_pagination'] ) ? " pagination-visibility-{$data['show_pagination']}" : null; |
| 921 | $dynamicClass .= ! empty( $data['ajax_pagination_type'] ) ? " ajax-pagination-type-next-prev-{$data['ajax_pagination_type']}" : null; |
| 922 | $dynamicClass .= ! empty( $data['show_meta'] ) ? " meta-visibility-{$data['show_meta']}" : null; |
| 923 | $dynamicClass .= ! empty( $data['section_title_style'] ) ? " section-title-style-{$data['section_title_style']}" : null; |
| 924 | $dynamicClass .= ! empty( $data['section_title_alignment'] ) ? " section-title-align-{$data['section_title_alignment']}" : null; |
| 925 | $dynamicClass .= ! empty( $data['hover_animation'] ) ? " img_hover_animation_{$data['hover_animation']}" : null; |
| 926 | $dynamicClass .= ! empty( $data['title_visibility_style'] ) ? " title-{$data['title_visibility_style']}" : null; |
| 927 | $dynamicClass .= ! empty( $data['title_position'] ) ? " title_position_{$data['title_position']}" : null; |
| 928 | $dynamicClass .= ! empty( $data['title_hover_underline'] ) ? " title_hover_border_{$data['title_hover_underline']}" : null; |
| 929 | $dynamicClass .= ! empty( $data['meta_position'] ) ? " meta_position_{$data['meta_position']}" : null; |
| 930 | $dynamicClass .= ! empty( $data['author_icon_visibility'] ) ? " tpg-is-author-icon-{$data['author_icon_visibility']}" : null; |
| 931 | $dynamicClass .= ! empty( $data['show_author_image'] ) ? " author-image-visibility-{$data['show_author_image']}" : null; |
| 932 | $dynamicClass .= ! empty( $data['category_position'] ) ? " tpg-category-position-{$data['category_position']}" : null; |
| 933 | $dynamicClass .= ! empty( $data['readmore_btn_style'] ) ? " readmore-btn-{$data['readmore_btn_style']}" : null; |
| 934 | $dynamicClass .= ! empty( $data['grid_hover_overlay_type'] ) ? " grid-hover-overlay-type-{$data['grid_hover_overlay_type']}" : null; |
| 935 | $dynamicClass .= ! empty( $data['grid_hover_overlay_height'] ) ? " grid-hover-overlay-height-{$data['grid_hover_overlay_height']}" : null; |
| 936 | $dynamicClass .= ! empty( $data['on_hover_overlay'] ) ? " hover-overlay-height-{$data['on_hover_overlay']}" : null; |
| 937 | $dynamicClass .= ! empty( $data['title_border_visibility'] ) ? " tpg-title-border-{$data['title_border_visibility']}" : null; |
| 938 | $dynamicClass .= ! empty( $data['title_alignment'] ) ? " title-alignment-{$data['title_alignment']}" : null; |
| 939 | $dynamicClass .= ! empty( $data['filter_v_alignment'] ) ? " tpg-filter-alignment-{$data['filter_v_alignment']}" : null; |
| 940 | $dynamicClass .= ! empty( $data['border_style'] ) ? " filter-button-border-{$data['border_style']}" : null; |
| 941 | $dynamicClass .= ! empty( $data['filter_next_prev_btn'] ) ? " filter-nex-prev-btn-{$data['filter_next_prev_btn']}" : null; |
| 942 | $dynamicClass .= ! empty( $data['filter_h_alignment'] ) ? " tpg-filter-h-alignment-{$data['filter_h_alignment']}" : null; |
| 943 | $dynamicClass .= ! empty( $data['is_box_border'] ) ? " tpg-el-box-border-{$data['is_box_border']}" : null; |
| 944 | $dynamicClass .= ! empty( $data['category_style'] ) ? " tpg-cat-{$data['category_style']}" : null; |
| 945 | |
| 946 | //Slider layout |
| 947 | $dynamicClass .= ! empty( $data['arrow_position'] ) ? " slider-arrow-position-{$data['arrow_position']}" : null; |
| 948 | $dynamicClass .= ! empty( $data['dots'] ) ? " slider-dot-enable-{$data['dots']}" : null; |
| 949 | $dynamicClass .= ! empty( $data['dots_style'] ) ? " slider-dots-style-{$data['dots_style']}" : null; |
| 950 | $dynamicClass .= ! empty( $data['lazyLoad'] ) ? " is-lazy-load-{$data['lazyLoad']}" : null; |
| 951 | $dynamicClass .= ! empty( $data['carousel_overflow'] ) ? " is-carousel-overflow-{$data['carousel_overflow']}" : null; |
| 952 | $dynamicClass .= ! empty( $data['slider_direction'] ) ? " slider-direction-{$data['slider_direction']}" : null; |
| 953 | $dynamicClass .= ! empty( $data['dots_text_align'] ) ? " slider-dots-align-{$data['dots_text_align']}" : null; |
| 954 | $dynamicClass .= ! empty( $data['pagination_btn_space_btween'] ) && $data['pagination_btn_space_btween'] === 'space-between' ? " tpg-prev-next-space-between" : null; |
| 955 | $dynamicClass .= ! empty( $data['pagination_btn_position'] ) && $data['pagination_btn_position'] === 'absolute' ? " tpg-prev-next-absolute" : null; |
| 956 | $dynamicClass .= ! empty( $data['box_border_bottom'] ) && $data['box_border_bottom'] === 'enable' ? " tpg-border-bottom-enable" : null; |
| 957 | $dynamicClass .= ! empty( $data['offset_img_position'] ) && $data['offset_img_position'] === 'offset-image-right' ? " offset-image-right" : null; |
| 958 | |
| 959 | //ACF |
| 960 | $dynamicClass .= ! empty( $data['acf_label_style'] ) ? " act-label-style-{$data['acf_label_style']}" : null; |
| 961 | $dynamicClass .= ! empty( $data['acf_alignment'] ) && ! is_array( $data['acf_alignment'] ) ? " tpg-acf-align-{$data['acf_alignment']}" : null; |
| 962 | |
| 963 | return $dynamicClass; |
| 964 | } |
| 965 | |
| 966 | |
| 967 | /** |
| 968 | * Get Section Title |
| 969 | * |
| 970 | * @param $data |
| 971 | */ |
| 972 | public static function get_section_title( $data ) { |
| 973 | if ( 'show' != $data['show_section_title'] ) { |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | $_is_link = false; |
| 978 | if ( ! empty( $data['section_title_link']['url'] ) ) { |
| 979 | $_is_link = true; |
| 980 | } |
| 981 | |
| 982 | ob_start(); |
| 983 | ?> |
| 984 | |
| 985 | <div class="tpg-widget-heading-wrapper rt-clear heading-<?php echo esc_attr( $data['section_title_style'] ); ?> "> |
| 986 | <span class="tpg-widget-heading-line line-left"></span> |
| 987 | |
| 988 | <?php printf( "<%s class='tpg-widget-heading'>", $data['section_title_tag'] ); ?> |
| 989 | |
| 990 | <?php |
| 991 | if ( $_is_link ) : ?> |
| 992 | <a href="#"> |
| 993 | <?php endif; ?> |
| 994 | |
| 995 | <?php |
| 996 | if ( 'page_title' == $data['section_title_source'] ) { |
| 997 | $archive_prefix = $data['title_prefix'] ? $data['title_prefix'] . ' ' : null; |
| 998 | $archive_suffix = $data['title_suffix'] ? ' ' . $data['title_suffix'] : null; |
| 999 | printf( "<span class='prefix-text'>%s</span>", esc_html( $archive_prefix ) ); |
| 1000 | if ( is_archive() ) { |
| 1001 | self::get_archive_title(); |
| 1002 | } else if ( is_search() ) { |
| 1003 | echo get_query_var( 's' ); |
| 1004 | } else { |
| 1005 | the_title(); |
| 1006 | } |
| 1007 | printf( "<span class='suffix-text'>%s</span>", esc_html( $archive_suffix ) ); |
| 1008 | } else { |
| 1009 | ?> |
| 1010 | <span> |
| 1011 | <?php echo $data['section_title_text'] ?> |
| 1012 | </span> |
| 1013 | <?php |
| 1014 | } |
| 1015 | ?> |
| 1016 | |
| 1017 | <?php if ( $_is_link ) : ?> |
| 1018 | </a> |
| 1019 | |
| 1020 | <?php endif; ?> |
| 1021 | <?php printf( "</%s>", $data['section_title_tag'] ); ?> |
| 1022 | <span class="tpg-widget-heading-line line-right"></span> |
| 1023 | </div> |
| 1024 | |
| 1025 | <?php if ( isset( $data['show_cat_desc'] ) && $data['show_cat_desc'] == 'yes' && category_description( self::get_last_category_id() ) ) : ?> |
| 1026 | <div class="tpg-category-description"> |
| 1027 | <?php echo category_description( self::get_last_category_id() ); ?> |
| 1028 | </div> |
| 1029 | <?php endif; ?> |
| 1030 | |
| 1031 | <?php echo ob_get_clean(); |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * rtAllOptionFields |
| 1036 | * All settings. |
| 1037 | * |
| 1038 | * @return array |
| 1039 | */ |
| 1040 | public static function rtAllOptionFields() { |
| 1041 | $fields = array_merge( |
| 1042 | Options::rtTPGCommonFilterFields(), |
| 1043 | Options::rtTPGLayoutSettingFields(), |
| 1044 | Options::responsiveSettingsColumn(), |
| 1045 | Options::layoutMiscSettings(), |
| 1046 | Options::stickySettings(), |
| 1047 | // settings. |
| 1048 | Options::rtTPGSCHeadingSettings(), |
| 1049 | Options::rtTPGSCCategorySettings(), |
| 1050 | Options::rtTPGSCTitleSettings(), |
| 1051 | Options::rtTPGSCMetaSettings(), |
| 1052 | Options::rtTPGSCImageSettings(), |
| 1053 | Options::rtTPGSCExcerptSettings(), |
| 1054 | Options::rtTPGSCButtonSettings(), |
| 1055 | // style. |
| 1056 | Options::rtTPGStyleFields(), |
| 1057 | Options::rtTPGStyleHeading(), |
| 1058 | Options::rtTPGStyleFullArea(), |
| 1059 | Options::rtTPGStyleContentWrap(), |
| 1060 | Options::rtTPGStyleCategory(), |
| 1061 | Options::rtTPGPostType(), |
| 1062 | Options::rtTPGStyleButtonColorFields(), |
| 1063 | Options::rtTPAdvanceFilters(), |
| 1064 | Options::itemFields() |
| 1065 | ); |
| 1066 | |
| 1067 | return $fields; |
| 1068 | } |
| 1069 | |
| 1070 | public static function rt_get_all_term_by_taxonomy( $taxonomy = null, $count = false, $parent = false ) { |
| 1071 | $terms = []; |
| 1072 | |
| 1073 | if ( $taxonomy ) { |
| 1074 | $temp_terms = get_terms( |
| 1075 | [ |
| 1076 | 'taxonomy' => $taxonomy, |
| 1077 | 'hide_empty' => 0, |
| 1078 | ] |
| 1079 | ); |
| 1080 | |
| 1081 | if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) { |
| 1082 | foreach ( $temp_terms as $term ) { |
| 1083 | $order = get_term_meta( $term->term_id, '_rt_order', true ); |
| 1084 | if ( $order === '' ) { |
| 1085 | update_term_meta( $term->term_id, '_rt_order', 0 ); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | global $wp_version; |
| 1090 | |
| 1091 | $args = [ |
| 1092 | 'taxonomy' => $taxonomy, |
| 1093 | 'orderby' => 'meta_value_num', |
| 1094 | 'meta_key' => '_rt_order', |
| 1095 | 'hide_empty' => apply_filters( 'rttpg_category_hide_empty', false ), |
| 1096 | ]; |
| 1097 | |
| 1098 | if ( $parent >= 0 && $parent !== false ) { |
| 1099 | $args['parent'] = absint( $parent ); |
| 1100 | } |
| 1101 | |
| 1102 | $args['orderby'] = 'meta_value_num'; |
| 1103 | $args['meta_key'] = '_rt_order'; |
| 1104 | |
| 1105 | $termObjs = get_terms( $args ); |
| 1106 | |
| 1107 | foreach ( $termObjs as $term ) { |
| 1108 | if ( $count ) { |
| 1109 | $terms[ $term->term_id ] = [ |
| 1110 | 'name' => $term->name, |
| 1111 | 'count' => $term->count, |
| 1112 | ]; |
| 1113 | } else { |
| 1114 | $terms[ $term->term_id ] = $term->name; |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return $terms; |
| 1121 | } |
| 1122 | |
| 1123 | public static function rt_get_selected_term_by_taxonomy( $taxonomy = null, $include = [], $count = false, $parent = false ) { |
| 1124 | $terms = []; |
| 1125 | |
| 1126 | if ( $taxonomy ) { |
| 1127 | $temp_terms = get_terms( |
| 1128 | [ |
| 1129 | 'taxonomy' => $taxonomy, |
| 1130 | 'hide_empty' => 0, |
| 1131 | ] |
| 1132 | ); |
| 1133 | |
| 1134 | if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) { |
| 1135 | foreach ( $temp_terms as $term ) { |
| 1136 | $order = get_term_meta( $term->term_id, '_rt_order', true ); |
| 1137 | if ( $order === '' ) { |
| 1138 | update_term_meta( $term->term_id, '_rt_order', 0 ); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | global $wp_version; |
| 1143 | |
| 1144 | $args = [ |
| 1145 | 'taxonomy' => $taxonomy, |
| 1146 | 'orderby' => 'meta_value_num', |
| 1147 | 'meta_key' => '_rt_order', |
| 1148 | 'include' => $include, |
| 1149 | 'hide_empty' => false, |
| 1150 | ]; |
| 1151 | |
| 1152 | if ( $parent >= 0 && $parent !== false ) { |
| 1153 | $args['parent'] = absint( $parent ); |
| 1154 | } |
| 1155 | |
| 1156 | $args['orderby'] = 'meta_value_num'; |
| 1157 | $args['meta_key'] = '_rt_order'; |
| 1158 | |
| 1159 | $termObjs = get_terms( $args ); |
| 1160 | |
| 1161 | foreach ( $termObjs as $term ) { |
| 1162 | if ( $count ) { |
| 1163 | $terms[ $term->term_id ] = [ |
| 1164 | 'name' => $term->name, |
| 1165 | 'count' => $term->count, |
| 1166 | ]; |
| 1167 | } else { |
| 1168 | $terms[ $term->term_id ] = $term->name; |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | return $terms; |
| 1175 | } |
| 1176 | |
| 1177 | public static function getCurrentUserRoles() { |
| 1178 | global $current_user; |
| 1179 | |
| 1180 | return $current_user->roles; |
| 1181 | } |
| 1182 | |
| 1183 | public static function rt_get_taxonomy_for_filter( $post_type = null ) { |
| 1184 | if ( ! $post_type ) { |
| 1185 | $post_type = get_post_meta( get_the_ID(), 'tpg_post_type', true ); |
| 1186 | } |
| 1187 | |
| 1188 | if ( ! $post_type ) { |
| 1189 | $post_type = 'post'; |
| 1190 | } |
| 1191 | |
| 1192 | return self::rt_get_all_taxonomy_by_post_type( $post_type ); |
| 1193 | } |
| 1194 | |
| 1195 | public static function rt_get_all_taxonomy_by_post_type( $post_type = null ) { |
| 1196 | $taxonomies = []; |
| 1197 | |
| 1198 | if ( $post_type && post_type_exists( $post_type ) ) { |
| 1199 | $taxObj = get_object_taxonomies( $post_type, 'objects' ); |
| 1200 | |
| 1201 | if ( is_array( $taxObj ) && ! empty( $taxObj ) ) { |
| 1202 | foreach ( $taxObj as $tKey => $taxonomy ) { |
| 1203 | $taxonomies[ $tKey ] = $taxonomy->label; |
| 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | if ( $post_type == 'post' ) { |
| 1209 | unset( $taxonomies['post_format'] ); |
| 1210 | } |
| 1211 | |
| 1212 | return $taxonomies; |
| 1213 | } |
| 1214 | |
| 1215 | public static function rt_get_users() { |
| 1216 | $users = []; |
| 1217 | $u = get_users( apply_filters( 'tpg_author_arg', [] ) ); |
| 1218 | |
| 1219 | if ( ! empty( $u ) ) { |
| 1220 | foreach ( $u as $user ) { |
| 1221 | $users[ $user->ID ] = $user->display_name; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | return $users; |
| 1226 | } |
| 1227 | |
| 1228 | public static function rtFieldGenerator( $fields = [] ) { |
| 1229 | $html = null; |
| 1230 | |
| 1231 | if ( is_array( $fields ) && ! empty( $fields ) ) { |
| 1232 | $tpgField = new Field(); |
| 1233 | foreach ( $fields as $fieldKey => $field ) { |
| 1234 | $html .= $tpgField->Field( $fieldKey, $field ); |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | return $html; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Sanitize field value |
| 1243 | * |
| 1244 | * @param array $field |
| 1245 | * @param null $value |
| 1246 | * |
| 1247 | * @return array|null |
| 1248 | * @internal param $value |
| 1249 | */ |
| 1250 | public static function sanitize( $field = [], $value = null ) { |
| 1251 | $newValue = null; |
| 1252 | |
| 1253 | if ( is_array( $field ) ) { |
| 1254 | $type = ( ! empty( $field['type'] ) ? $field['type'] : 'text' ); |
| 1255 | |
| 1256 | if ( empty( $field['multiple'] ) ) { |
| 1257 | if ( $type == 'text' || $type == 'number' || $type == 'select' || $type == 'checkbox' || $type == 'radio' ) { |
| 1258 | $newValue = sanitize_text_field( $value ); |
| 1259 | } else if ( $type == 'url' ) { |
| 1260 | $newValue = esc_url( $value ); |
| 1261 | } else if ( $type == 'slug' ) { |
| 1262 | $newValue = sanitize_title_with_dashes( $value ); |
| 1263 | } else if ( $type == 'textarea' ) { |
| 1264 | $newValue = wp_kses_post( $value ); |
| 1265 | } else if ( $type == 'script' ) { |
| 1266 | $newValue = trim( $value ); |
| 1267 | } else if ( $type == 'colorpicker' ) { |
| 1268 | $newValue = self::sanitize_hex_color( $value ); |
| 1269 | } else if ( $type == 'image_size' ) { |
| 1270 | $newValue = []; |
| 1271 | |
| 1272 | foreach ( $value as $k => $v ) { |
| 1273 | $newValue[ $k ] = esc_attr( $v ); |
| 1274 | } |
| 1275 | } else if ( $type == 'style' ) { |
| 1276 | $newValue = []; |
| 1277 | |
| 1278 | foreach ( $value as $k => $v ) { |
| 1279 | if ( $k == 'color' ) { |
| 1280 | $newValue[ $k ] = self::sanitize_hex_color( $v ); |
| 1281 | } else { |
| 1282 | $newValue[ $k ] = self::sanitize( [ 'type' => 'text' ], $v ); |
| 1283 | } |
| 1284 | } |
| 1285 | } else { |
| 1286 | $newValue = sanitize_text_field( $value ); |
| 1287 | } |
| 1288 | } else { |
| 1289 | $newValue = []; |
| 1290 | |
| 1291 | if ( ! empty( $value ) ) { |
| 1292 | if ( is_array( $value ) ) { |
| 1293 | foreach ( $value as $key => $val ) { |
| 1294 | if ( $type == 'style' && $key == 0 ) { |
| 1295 | if ( function_exists( 'sanitize_hex_color' ) ) { |
| 1296 | $newValue = sanitize_hex_color( $val ); |
| 1297 | } else { |
| 1298 | $newValue[] = self::sanitize_hex_color( $val ); |
| 1299 | } |
| 1300 | } else { |
| 1301 | $newValue[] = sanitize_text_field( $val ); |
| 1302 | } |
| 1303 | } |
| 1304 | } else { |
| 1305 | $newValue[] = sanitize_text_field( $value ); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | return $newValue; |
| 1312 | } |
| 1313 | |
| 1314 | public static function sanitize_hex_color( $color ) { |
| 1315 | if ( function_exists( 'sanitize_hex_color' ) ) { |
| 1316 | return sanitize_hex_color( $color ); |
| 1317 | } else { |
| 1318 | if ( '' === $color ) { |
| 1319 | return ''; |
| 1320 | } |
| 1321 | |
| 1322 | // 3 or 6 hex digits, or the empty string. |
| 1323 | if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { |
| 1324 | return $color; |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | public static function rtFieldGeneratorBackup( $fields = [], $multi = false ) { |
| 1330 | $html = null; |
| 1331 | |
| 1332 | if ( is_array( $fields ) && ! empty( $fields ) ) { |
| 1333 | $rtField = new Field(); |
| 1334 | |
| 1335 | if ( $multi ) { |
| 1336 | foreach ( $fields as $field ) { |
| 1337 | $html .= $rtField->Field( $field ); |
| 1338 | } |
| 1339 | } else { |
| 1340 | $html .= $rtField->Field( $fields ); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | return $html; |
| 1345 | } |
| 1346 | |
| 1347 | public static function rtSmartStyle( $fields = [] ) { |
| 1348 | $h = null; |
| 1349 | |
| 1350 | if ( ! empty( $fields ) ) { |
| 1351 | foreach ( $fields as $key => $label ) { |
| 1352 | $atts = ''; |
| 1353 | $proText = ''; |
| 1354 | $class = ''; |
| 1355 | |
| 1356 | $h .= '<div class="field-holder ' . esc_attr( $class ) . '">'; |
| 1357 | |
| 1358 | $h .= '<div class="field-label"><label>' . esc_html( $label ) . '' . self::htmlKses( $proText, 'basic' ) . '</label></div>'; |
| 1359 | $h .= "<div class='field'>"; |
| 1360 | // color. |
| 1361 | $h .= "<div class='field-inner col-4'>"; |
| 1362 | $h .= "<div class='field-inner-container size'>"; |
| 1363 | $h .= "<span class='label'>Color</span>"; |
| 1364 | $cValue = get_post_meta( get_the_ID(), $key . '_color', true ); |
| 1365 | $h .= '<input type="text" value="' . esc_attr( $cValue ) . '" class="rt-color" name="' . esc_attr( $key ) . '_color">'; |
| 1366 | $h .= '</div>'; |
| 1367 | $h .= '</div>'; |
| 1368 | |
| 1369 | // Font size. |
| 1370 | $h .= "<div class='field-inner col-4'>"; |
| 1371 | $h .= "<div class='field-inner-container size'>"; |
| 1372 | $h .= "<span class='label'>Font size</span>"; |
| 1373 | $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_size" class="rt-select2">'; |
| 1374 | $fSizes = Options::scFontSize(); |
| 1375 | $sValue = get_post_meta( get_the_ID(), $key . '_size', true ); |
| 1376 | $h .= "<option value=''>Default</option>"; |
| 1377 | |
| 1378 | foreach ( $fSizes as $size => $sizeLabel ) { |
| 1379 | $sSlt = ( $size == $sValue ? 'selected' : null ); |
| 1380 | $h .= '<option value="' . esc_attr( $size ) . '" ' . esc_attr( $sSlt ) . '>' . esc_html( $sizeLabel ) . '</option>'; |
| 1381 | } |
| 1382 | |
| 1383 | $h .= '</select>'; |
| 1384 | $h .= '</div>'; |
| 1385 | $h .= '</div>'; |
| 1386 | |
| 1387 | // Weight. |
| 1388 | $h .= "<div class='field-inner col-4'>"; |
| 1389 | $h .= "<div class='field-inner-container weight'>"; |
| 1390 | $h .= "<span class='label'>Weight</span>"; |
| 1391 | $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_weight" class="rt-select2">'; |
| 1392 | $h .= "<option value=''>Default</option>"; |
| 1393 | $weights = Options::scTextWeight(); |
| 1394 | $wValue = get_post_meta( get_the_ID(), $key . '_weight', true ); |
| 1395 | |
| 1396 | foreach ( $weights as $weight => $weightLabel ) { |
| 1397 | $wSlt = ( $weight == $wValue ? 'selected' : null ); |
| 1398 | $h .= '<option value="' . esc_attr( $weight ) . '" ' . esc_attr( $wSlt ) . '>' . esc_html( $weightLabel ) . '</option>'; |
| 1399 | } |
| 1400 | |
| 1401 | $h .= '</select>'; |
| 1402 | $h .= '</div>'; |
| 1403 | $h .= '</div>'; |
| 1404 | |
| 1405 | // Alignment. |
| 1406 | $h .= "<div class='field-inner col-4'>"; |
| 1407 | $h .= "<div class='field-inner-container alignment'>"; |
| 1408 | $h .= "<span class='label'>Alignment</span>"; |
| 1409 | $h .= '<select ' . self::htmlKses( $atts, 'basic' ) . ' name="' . esc_attr( $key ) . '_alignment" class="rt-select2">'; |
| 1410 | $h .= "<option value=''>Default</option>"; |
| 1411 | $aligns = Options::scAlignment(); |
| 1412 | $aValue = get_post_meta( get_the_ID(), $key . '_alignment', true ); |
| 1413 | |
| 1414 | foreach ( $aligns as $align => $alignLabel ) { |
| 1415 | $aSlt = ( $align == $aValue ? 'selected' : null ); |
| 1416 | $h .= '<option value="' . esc_attr( $align ) . '" ' . esc_attr( $aSlt ) . '>' . esc_html( $alignLabel ) . '</option>'; |
| 1417 | } |
| 1418 | |
| 1419 | $h .= '</select>'; |
| 1420 | $h .= '</div>'; |
| 1421 | $h .= '</div>'; |
| 1422 | |
| 1423 | $h .= '</div>'; |
| 1424 | $h .= '</div>'; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | return $h; |
| 1429 | } |
| 1430 | |
| 1431 | public static function custom_variation_price( $product ) { |
| 1432 | $price = ''; |
| 1433 | $max = $product->get_variation_sale_price( 'max' ); |
| 1434 | $min = $product->get_variation_sale_price( 'min' ); |
| 1435 | |
| 1436 | if ( ! $min || $min !== $max ) { |
| 1437 | $price .= wc_price( $product->get_price() ); |
| 1438 | } |
| 1439 | |
| 1440 | if ( $max && $max !== $min ) { |
| 1441 | $price .= ' - '; |
| 1442 | $price .= wc_price( $max ); |
| 1443 | } |
| 1444 | |
| 1445 | return $price; |
| 1446 | } |
| 1447 | |
| 1448 | public static function getTPGShortCodeList() { |
| 1449 | $scList = null; |
| 1450 | $scQ = get_posts( |
| 1451 | [ |
| 1452 | 'post_type' => rtTPG()->post_type, |
| 1453 | 'order_by' => 'title', |
| 1454 | 'order' => 'DESC', |
| 1455 | 'post_status' => 'publish', |
| 1456 | 'posts_per_page' => - 1, |
| 1457 | 'meta_query' => [ |
| 1458 | [ |
| 1459 | 'key' => 'layout', |
| 1460 | 'value' => 'layout', |
| 1461 | 'compare' => 'LIKE', |
| 1462 | ], |
| 1463 | ], |
| 1464 | ] |
| 1465 | ); |
| 1466 | |
| 1467 | if ( ! empty( $scQ ) ) { |
| 1468 | foreach ( $scQ as $sc ) { |
| 1469 | $scList[ $sc->ID ] = $sc->post_title; |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | return $scList; |
| 1474 | } |
| 1475 | |
| 1476 | public static function getAllTPGShortCodeList() { |
| 1477 | $scList = null; |
| 1478 | $scQ = get_posts( |
| 1479 | [ |
| 1480 | 'post_type' => rtTPG()->post_type, |
| 1481 | 'order_by' => 'title', |
| 1482 | 'order' => 'ASC', |
| 1483 | 'post_status' => 'publish', |
| 1484 | 'posts_per_page' => - 1, |
| 1485 | ] |
| 1486 | ); |
| 1487 | if ( ! empty( $scQ ) ) { |
| 1488 | foreach ( $scQ as $sc ) { |
| 1489 | $scList[ $sc->ID ] = $sc->post_title; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | return $scList; |
| 1494 | } |
| 1495 | |
| 1496 | public static function socialShare( $pLink ) { |
| 1497 | $html = null; |
| 1498 | $html .= "<div class='single-tpg-share'> |
| 1499 | <div class='fb-share'> |
| 1500 | <div class='fb-share-button' data-href='" . esc_url( $pLink ) . "' data-layout='button_count'></div> |
| 1501 | </div> |
| 1502 | <div class='twitter-share'> |
| 1503 | <a href='" . esc_url( $pLink ) . "' class='twitter-share-button'{count} data-url='https://about.twitter.com/resources/buttons#tweet'>Tweet</a> |
| 1504 | </div> |
| 1505 | <div class='googleplus-share'> |
| 1506 | <div class='g-plusone'></div> |
| 1507 | </div> |
| 1508 | <div class='linkedin-share'> |
| 1509 | <script type='IN/Share' data-counter='right'></script> |
| 1510 | </div> |
| 1511 | <div class='linkedin-share'> |
| 1512 | <a data-pin-do='buttonPin' data-pin-count='beside' href='https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=https%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest'><img src='//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png' /></a> |
| 1513 | </div> |
| 1514 | </div>"; |
| 1515 | $html .= '<div id="fb-root"></div> |
| 1516 | <script>(function(d, s, id) { |
| 1517 | var js, fjs = d.getElementsByTagName(s)[0]; |
| 1518 | if (d.getElementById(id)) return; |
| 1519 | js = d.createElement(s); js.id = id; |
| 1520 | js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5"; |
| 1521 | fjs.parentNode.insertBefore(js, fjs); |
| 1522 | }(document, "script", "facebook-jssdk"));</script>'; |
| 1523 | $html .= "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> |
| 1524 | <script>window.___gcfg = { lang: 'en-US', parsetags: 'onload', };</script>"; |
| 1525 | $html .= "<script src='https://apis.google.com/js/platform.js' async defer></script>"; |
| 1526 | $html .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>'; |
| 1527 | $html .= '<script async defer src="//assets.pinterest.com/js/pinit.js"></script>'; |
| 1528 | |
| 1529 | return $html; |
| 1530 | } |
| 1531 | |
| 1532 | public static function get_image_sizes() { |
| 1533 | global $_wp_additional_image_sizes; |
| 1534 | |
| 1535 | $sizes = []; |
| 1536 | $interSizes = get_intermediate_image_sizes(); |
| 1537 | if ( ! empty( $interSizes ) ) { |
| 1538 | foreach ( get_intermediate_image_sizes() as $_size ) { |
| 1539 | if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ] ) ) { |
| 1540 | $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" ); |
| 1541 | $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" ); |
| 1542 | $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" ); |
| 1543 | } else if ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { |
| 1544 | $sizes[ $_size ] = [ |
| 1545 | 'width' => $_wp_additional_image_sizes[ $_size ]['width'], |
| 1546 | 'height' => $_wp_additional_image_sizes[ $_size ]['height'], |
| 1547 | 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'], |
| 1548 | ]; |
| 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | $imgSize = []; |
| 1554 | |
| 1555 | if ( ! empty( $sizes ) ) { |
| 1556 | $imgSize['full'] = esc_html__( 'Full Size', 'the-post-grid' ); |
| 1557 | foreach ( $sizes as $key => $img ) { |
| 1558 | $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})"; |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | return apply_filters( 'tpg_image_sizes', $imgSize ); |
| 1563 | } |
| 1564 | |
| 1565 | public static function getFeatureImageSrc( |
| 1566 | $post_id = null, |
| 1567 | $fImgSize = 'medium', |
| 1568 | $mediaSource = 'feature_image', |
| 1569 | $defaultImgId = null, |
| 1570 | $customImgSize = [], |
| 1571 | $img_Class = '' |
| 1572 | ) { |
| 1573 | global $post; |
| 1574 | |
| 1575 | $imgSrc = null; |
| 1576 | $img_class = 'rt-img-responsive '; |
| 1577 | |
| 1578 | if ( $img_Class ) { |
| 1579 | $img_class .= $img_Class; |
| 1580 | } |
| 1581 | |
| 1582 | $post_id = ( $post_id ? absint( $post_id ) : $post->ID ); |
| 1583 | $alt = get_the_title( $post_id ); |
| 1584 | $image = null; |
| 1585 | $cSize = false; |
| 1586 | |
| 1587 | if ( $fImgSize == 'rt_custom' ) { |
| 1588 | $fImgSize = 'full'; |
| 1589 | $cSize = true; |
| 1590 | } |
| 1591 | |
| 1592 | if ( $mediaSource == 'feature_image' ) { |
| 1593 | if ( $aID = get_post_thumbnail_id( $post_id ) ) { |
| 1594 | $image = wp_get_attachment_image( |
| 1595 | $aID, |
| 1596 | $fImgSize, |
| 1597 | '', |
| 1598 | [ |
| 1599 | 'class' => $img_class, |
| 1600 | 'loading' => false, |
| 1601 | ] |
| 1602 | ); |
| 1603 | $imgSrc = wp_get_attachment_image_src( $aID, $fImgSize ); |
| 1604 | |
| 1605 | if ( ! empty( $imgSrc ) && $img_Class == 'swiper-lazy' ) { |
| 1606 | $image = '<img class="' . esc_attr( $img_class ) . '" data-src="' . esc_url( $imgSrc[0] ) . '" src="#none" width="' . absint( $imgSrc[1] ) . '" height="' . absint( $imgSrc[2] ) . '" alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>'; |
| 1607 | } |
| 1608 | |
| 1609 | $imgSrc = ! empty( $imgSrc ) ? $imgSrc[0] : $imgSrc; |
| 1610 | } |
| 1611 | } else if ( $mediaSource == 'first_image' ) { |
| 1612 | if ( $img = preg_match_all( |
| 1613 | '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', |
| 1614 | get_the_content( $post_id ), |
| 1615 | $matches |
| 1616 | ) |
| 1617 | ) { |
| 1618 | $imgSrc = $matches[1][0]; |
| 1619 | $size = ''; |
| 1620 | |
| 1621 | if ( strpos( $imgSrc, site_url() ) !== false ) { |
| 1622 | $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc ); |
| 1623 | } else { |
| 1624 | $imgAbs = ABSPATH . $imgSrc; |
| 1625 | } |
| 1626 | |
| 1627 | $imgAbs = apply_filters( 'rt_tpg_sc_first_image_src', $imgAbs ); |
| 1628 | |
| 1629 | if ( file_exists( $imgAbs ) ) { |
| 1630 | $info = getimagesize( $imgAbs ); |
| 1631 | $size = isset( $info[3] ) ? $info[3] : ''; |
| 1632 | } |
| 1633 | |
| 1634 | $image = '<img class="' . esc_attr( $img_class ) . '" src="' . esc_url( $imgSrc ) . '" ' . $size . ' alt="' . esc_attr( $alt ) . '"/>'; |
| 1635 | |
| 1636 | if ( $img_Class == 'swiper-lazy' ) { |
| 1637 | $image = '<img class="' . esc_attr( $img_class ) . ' img-responsive" data-src="' . esc_url( $imgSrc ) . '" src="#none" ' . $size . ' alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>'; |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | if ( ! $imgSrc && $defaultImgId ) { |
| 1643 | $image = wp_get_attachment_image( $defaultImgId, $fImgSize ); |
| 1644 | } |
| 1645 | |
| 1646 | if ( $imgSrc && $cSize ) { |
| 1647 | $w = ( ! empty( $customImgSize[0] ) ? absint( $customImgSize[0] ) : null ); |
| 1648 | $h = ( ! empty( $customImgSize[1] ) ? absint( $customImgSize[1] ) : null ); |
| 1649 | $c = ( ! empty( $customImgSize[2] ) && $customImgSize[2] == 'soft' ? false : true ); |
| 1650 | |
| 1651 | if ( $w && $h ) { |
| 1652 | $post_thumb_id = get_post_thumbnail_id( $post_id ); |
| 1653 | |
| 1654 | if ( $post_thumb_id ) { |
| 1655 | $featured_image = wp_get_attachment_image_src( $post_thumb_id, 'full' ); |
| 1656 | $w = $featured_image[1] < $w ? $featured_image[1] : $w; |
| 1657 | $h = $featured_image[2] < $h ? $featured_image[2] : $h; |
| 1658 | } |
| 1659 | |
| 1660 | $imgSrc = self::rtImageReSize( $imgSrc, $w, $h, $c ); |
| 1661 | |
| 1662 | if ( $img_Class !== 'swiper-lazy' ) { |
| 1663 | $image = '<img class="' . esc_attr( $img_class ) . '" src="' . esc_url( $imgSrc ) . '" width="' . absint( $w ) . '" height="' . absint( $h ) . '" alt="' . esc_attr( $alt ) . '"/>'; |
| 1664 | } else { |
| 1665 | $image = '<img class="' . esc_attr( $img_class ) . ' img-responsive" data-src="' . esc_url( $imgSrc ) . '" src="#none" width="' . absint( $w ) . '" height="' . absint( $h ) . '" alt="' . esc_attr( $alt ) . '"/><div class="lazy-overlay-wrap"><div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>'; |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | return $image; |
| 1671 | } |
| 1672 | |
| 1673 | public static function getFeatureImageUrl( $post_id = null, $fImgSize = 'medium' ) { |
| 1674 | $image = $imgSrc = null; |
| 1675 | |
| 1676 | if ( $aID = get_post_thumbnail_id( $post_id ) ) { |
| 1677 | $image = wp_get_attachment_image_src( $aID, $fImgSize ); |
| 1678 | } |
| 1679 | |
| 1680 | if ( is_array( $image ) ) { |
| 1681 | $imgSrc = $image[0]; |
| 1682 | } |
| 1683 | |
| 1684 | return $imgSrc; |
| 1685 | } |
| 1686 | |
| 1687 | public static function tpgCharacterLimit( $limit, $content ) { |
| 1688 | $limit ++; |
| 1689 | |
| 1690 | $text = ''; |
| 1691 | |
| 1692 | if ( mb_strlen( $content ) > $limit ) { |
| 1693 | $subex = mb_substr( $content, 0, $limit ); |
| 1694 | $exwords = explode( ' ', $subex ); |
| 1695 | $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); |
| 1696 | |
| 1697 | if ( $excut < 0 ) { |
| 1698 | $text = mb_substr( $subex, 0, $excut ); |
| 1699 | } else { |
| 1700 | $text = $subex; |
| 1701 | } |
| 1702 | } else { |
| 1703 | $text = $content; |
| 1704 | } |
| 1705 | |
| 1706 | return $text; |
| 1707 | } |
| 1708 | |
| 1709 | public static function get_the_excerpt( $post_id, $data = [] ) { |
| 1710 | $type = $data['excerpt_type']; |
| 1711 | $post = get_post( $post_id ); |
| 1712 | |
| 1713 | if ( empty( $post ) ) { |
| 1714 | return ''; |
| 1715 | } |
| 1716 | |
| 1717 | if ( $type == 'full' ) { |
| 1718 | ob_start(); |
| 1719 | the_content(); |
| 1720 | $content = ob_get_clean(); |
| 1721 | |
| 1722 | return apply_filters( 'tpg_content_full', $content, $post_id, $data ); |
| 1723 | } else { |
| 1724 | if ( class_exists( 'ET_GB_Block_Layout' ) ) { |
| 1725 | $defaultExcerpt = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 ); |
| 1726 | } else if ( defined( 'WPB_VC_VERSION' ) ) { |
| 1727 | $the_content = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 ); |
| 1728 | $shortcode_tags = [ 'VC_COLUMN_INNTER' ]; |
| 1729 | $values = array_values( $shortcode_tags ); |
| 1730 | $exclude_codes = implode( '|', $values ); |
| 1731 | $defaultExcerpt = trim( preg_replace( "~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s", '', $the_content ) ); |
| 1732 | } else { |
| 1733 | $defaultExcerpt = get_the_excerpt( $post_id ); |
| 1734 | } |
| 1735 | |
| 1736 | $limit = isset( $data['excerpt_limit'] ) && $data['excerpt_limit'] ? abs( $data['excerpt_limit'] ) : 0; |
| 1737 | $more = $data['excerpt_more_text']; |
| 1738 | $excerpt = preg_replace( '`\[[^\]]*\]`', '', $defaultExcerpt ); |
| 1739 | $excerpt = strip_shortcodes( $excerpt ); |
| 1740 | $excerpt = preg_replace( '`[[^]]*]`', '', $excerpt ); |
| 1741 | $excerpt = str_replace( '…', '', $excerpt ); |
| 1742 | |
| 1743 | if ( $limit ) { |
| 1744 | $excerpt = wp_strip_all_tags( $excerpt ); |
| 1745 | |
| 1746 | if ( $type == 'word' ) { |
| 1747 | $limit = $limit + 1; |
| 1748 | $rawExcerpt = $excerpt; |
| 1749 | $excerpt = explode( ' ', $excerpt, $limit ); |
| 1750 | |
| 1751 | if ( count( $excerpt ) >= $limit ) { |
| 1752 | array_pop( $excerpt ); |
| 1753 | $excerpt = implode( ' ', $excerpt ); |
| 1754 | } else { |
| 1755 | $excerpt = $rawExcerpt; |
| 1756 | } |
| 1757 | } else { |
| 1758 | $excerpt = self::tpgCharacterLimit( $limit, $excerpt ); |
| 1759 | } |
| 1760 | $excerpt = stripslashes( $excerpt ); |
| 1761 | } else { |
| 1762 | $allowed_html = [ |
| 1763 | 'a' => [ |
| 1764 | 'href' => [], |
| 1765 | 'title' => [], |
| 1766 | ], |
| 1767 | 'strong' => [], |
| 1768 | 'b' => [], |
| 1769 | 'br' => [ [] ], |
| 1770 | ]; |
| 1771 | |
| 1772 | $excerpt = nl2br( wp_kses( $excerpt, $allowed_html ) ); |
| 1773 | } |
| 1774 | |
| 1775 | $excerpt = ( $more ? $excerpt . ' ' . $more : $excerpt ); |
| 1776 | |
| 1777 | return apply_filters( 'tpg_get_the_excerpt', $excerpt, $post_id, $data, $defaultExcerpt ); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | public static function get_the_title( $post_id, $data = [] ) { |
| 1782 | $title = $originalTitle = get_the_title( $post_id ); |
| 1783 | $limit = isset( $data['title_limit'] ) ? absint( $data['title_limit'] ) : 0; |
| 1784 | $limit_type = isset( $data['title_limit_type'] ) ? trim( $data['title_limit_type'] ) : 'character'; |
| 1785 | |
| 1786 | if ( $limit ) { |
| 1787 | if ( $limit_type == 'word' ) { |
| 1788 | $limit = $limit + 1; |
| 1789 | $title = explode( ' ', $title, $limit ); |
| 1790 | |
| 1791 | if ( count( $title ) >= $limit ) { |
| 1792 | array_pop( $title ); |
| 1793 | $title = implode( ' ', $title ); |
| 1794 | } else { |
| 1795 | $title = $originalTitle; |
| 1796 | } |
| 1797 | } else { |
| 1798 | if ( $limit > 0 && strlen( $title ) > $limit ) { |
| 1799 | $title = mb_substr( $title, 0, $limit, 'utf-8' ); |
| 1800 | $title = preg_replace( '/\W\w+\s*(\W*)$/', '$1', $title ); |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | return apply_filters( 'tpg_get_the_title', $title, $post_id, $data, $originalTitle ); |
| 1806 | } |
| 1807 | |
| 1808 | |
| 1809 | public static function rt_pagination( $postGrid, $range = 4, $ajax = false ) { |
| 1810 | $html = $pages = null; |
| 1811 | $showitems = ( $range * 2 ) + 1; |
| 1812 | |
| 1813 | $wpQuery = $postGrid; |
| 1814 | |
| 1815 | global $wp_query; |
| 1816 | |
| 1817 | if ( empty( $wpQuery ) ) { |
| 1818 | $wpQuery = $wp_query; |
| 1819 | } |
| 1820 | |
| 1821 | $pages = ! empty( $wpQuery->max_num_pages ) ? $wpQuery->max_num_pages : 1; |
| 1822 | $paged = ! empty( $wpQuery->query['paged'] ) ? $wpQuery->query['paged'] : 1; |
| 1823 | |
| 1824 | if ( is_front_page() ) { |
| 1825 | $paged = ! empty( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : 1; |
| 1826 | } |
| 1827 | |
| 1828 | $ajaxClass = null; |
| 1829 | $dataAttr = null; |
| 1830 | |
| 1831 | if ( $ajax ) { |
| 1832 | $ajaxClass = ' rt-ajax'; |
| 1833 | $dataAttr = "data-paged='1'"; |
| 1834 | } |
| 1835 | |
| 1836 | if ( 1 != $pages ) { |
| 1837 | $html .= '<div class="rt-pagination' . $ajaxClass . '" ' . $dataAttr . '>'; |
| 1838 | $html .= '<ul class="pagination-list">'; |
| 1839 | if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages && ! $ajax ) { |
| 1840 | $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>«</a></li>"; |
| 1841 | } |
| 1842 | |
| 1843 | if ( $paged > 1 && $showitems < $pages && ! $ajax ) { |
| 1844 | $p = $paged - 1; |
| 1845 | $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>‹</a></li>"; |
| 1846 | } |
| 1847 | |
| 1848 | if ( $ajax ) { |
| 1849 | for ( $i = 1; $i <= $pages; $i ++ ) { |
| 1850 | $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>'; |
| 1851 | } |
| 1852 | } else { |
| 1853 | for ( $i = 1; $i <= $pages; $i ++ ) { |
| 1854 | if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) { |
| 1855 | $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>'; |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | if ( $paged < $pages && $showitems < $pages && ! $ajax ) { |
| 1861 | $p = $paged + 1; |
| 1862 | $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>›</a></li>"; |
| 1863 | } |
| 1864 | |
| 1865 | if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages && ! $ajax ) { |
| 1866 | $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>»</a></li>"; |
| 1867 | } |
| 1868 | |
| 1869 | $html .= '</ul>'; |
| 1870 | $html .= '</div>'; |
| 1871 | } |
| 1872 | |
| 1873 | return $html; |
| 1874 | } |
| 1875 | |
| 1876 | public static function rt_pagination_ajax( $scID, $range = 4, $pages = '' ) { |
| 1877 | $html = null; |
| 1878 | |
| 1879 | $html .= "<div class='rt-tpg-pagination-ajax' data-sc-id='{$scID}' data-paged='1'>"; |
| 1880 | $html .= '</div>'; |
| 1881 | |
| 1882 | return $html; |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * Call the Image resize model for resize function |
| 1887 | * |
| 1888 | * @param $url |
| 1889 | * @param null $width |
| 1890 | * @param null $height |
| 1891 | * @param null $crop |
| 1892 | * @param bool|true $single |
| 1893 | * @param bool|false $upscale |
| 1894 | * |
| 1895 | * @return array|bool|string |
| 1896 | * @throws Exception |
| 1897 | * @throws Rt_Exception |
| 1898 | */ |
| 1899 | public static function rtImageReSize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { |
| 1900 | $rtResize = new ReSizer(); |
| 1901 | |
| 1902 | return $rtResize->process( $url, $width, $height, $crop, $single, $upscale ); |
| 1903 | } |
| 1904 | |
| 1905 | |
| 1906 | /* Convert hexdec color string to rgb(a) string */ |
| 1907 | public static function rtHex2rgba( $color, $opacity = .5 ) { |
| 1908 | $default = 'rgb(0,0,0)'; |
| 1909 | |
| 1910 | // Return default if no color provided. |
| 1911 | if ( empty( $color ) ) { |
| 1912 | return $default; |
| 1913 | } |
| 1914 | |
| 1915 | // Sanitize $color if "#" is provided. |
| 1916 | if ( $color[0] == '#' ) { |
| 1917 | $color = substr( $color, 1 ); |
| 1918 | } |
| 1919 | |
| 1920 | // Check if color has 6 or 3 characters and get values. |
| 1921 | if ( strlen( $color ) == 6 ) { |
| 1922 | $hex = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ]; |
| 1923 | } else if ( strlen( $color ) == 3 ) { |
| 1924 | $hex = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ]; |
| 1925 | } else { |
| 1926 | return $default; |
| 1927 | } |
| 1928 | |
| 1929 | // Convert hexadec to rgb. |
| 1930 | $rgb = array_map( 'hexdec', $hex ); |
| 1931 | |
| 1932 | // Check if opacity is set(rgba or rgb). |
| 1933 | if ( $opacity ) { |
| 1934 | if ( absint( $opacity ) > 1 ) { |
| 1935 | $opacity = 1.0; |
| 1936 | } |
| 1937 | |
| 1938 | $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')'; |
| 1939 | } else { |
| 1940 | $output = 'rgb(' . implode( ',', $rgb ) . ')'; |
| 1941 | } |
| 1942 | |
| 1943 | // Return rgb(a) color string. |
| 1944 | return $output; |
| 1945 | } |
| 1946 | |
| 1947 | public static function meta_exist( $meta_key, $post_id = null, $type = 'post' ) { |
| 1948 | if ( ! $post_id ) { |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
| 1952 | return metadata_exists( $type, $post_id, $meta_key ); |
| 1953 | } |
| 1954 | |
| 1955 | |
| 1956 | public static function get_offset_col( $col ) { |
| 1957 | $return = [ |
| 1958 | 'big' => 6, |
| 1959 | 'small' => 6, |
| 1960 | ]; |
| 1961 | |
| 1962 | if ( $col ) { |
| 1963 | if ( $col == 12 ) { |
| 1964 | $return['big'] = 12; |
| 1965 | $return['small'] = 12; |
| 1966 | } else if ( $col == 6 ) { |
| 1967 | $return['big'] = 6; |
| 1968 | $return['small'] = 6; |
| 1969 | } else if ( $col == 4 ) { |
| 1970 | $return['big'] = 4; |
| 1971 | $return['small'] = 8; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | return $return; |
| 1976 | } |
| 1977 | |
| 1978 | public static function formatSpacing( $data = '' ) { |
| 1979 | if ( ! empty( $data ) ) { |
| 1980 | $spacing = array_filter( explode( ',', $data ), 'is_numeric' ); |
| 1981 | |
| 1982 | if ( count( $spacing ) > 4 ) { |
| 1983 | $spacing = array_slice( $spacing, 0, 4, true ); |
| 1984 | } |
| 1985 | |
| 1986 | $data = implode( 'px ', $spacing ); |
| 1987 | } |
| 1988 | |
| 1989 | return $data; |
| 1990 | } |
| 1991 | |
| 1992 | public static function layoutStyle( $layoutID, $scMeta, $layout, $scId = null ) { |
| 1993 | $css = null; |
| 1994 | $css .= "<style type='text/css' media='all'>"; |
| 1995 | // primary color |
| 1996 | if ( $scId ) { |
| 1997 | $primaryColor = ( isset( $scMeta['primary_color'][0] ) ? $scMeta['primary_color'][0] : null ); |
| 1998 | $button_bg_color = ( isset( $scMeta['button_bg_color'][0] ) ? $scMeta['button_bg_color'][0] : null ); |
| 1999 | $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'][0] ) ? $scMeta['button_active_bg_color'][0] : null ); |
| 2000 | $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'][0] ) ? $scMeta['button_hover_bg_color'][0] : null ); |
| 2001 | $button_text_color = ( isset( $scMeta['button_text_bg_color'][0] ) ? $scMeta['button_text_bg_color'][0] |
| 2002 | : ( isset( $scMeta['button_text_color'][0] ) ? $scMeta['button_text_color'][0] : null ) ); |
| 2003 | $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'][0] ) ? $scMeta['button_hover_text_color'][0] : null ); |
| 2004 | $button_border_color = ( isset( $scMeta['button_border_color'][0] ) ? $scMeta['button_border_color'][0] : null ); |
| 2005 | $overlay_color = ( ! empty( $scMeta['overlay_color'][0] ) ? self::rtHex2rgba( |
| 2006 | $scMeta['overlay_color'][0], |
| 2007 | ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8 |
| 2008 | ) : null ); |
| 2009 | $overlay_padding = ( ! empty( $scMeta['overlay_padding'][0] ) ? absint( $scMeta['overlay_padding'][0] ) : null ); |
| 2010 | $gutter = ! empty( $scMeta['tgp_gutter'][0] ) ? absint( $scMeta['tgp_gutter'][0] ) : null; |
| 2011 | $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'][0] ) ? $scMeta['tpg_read_more_button_border_radius'][0] : ''; |
| 2012 | // Section |
| 2013 | $sectionBg = ( isset( $scMeta['tpg_full_area_bg'][0] ) ? $scMeta['tpg_full_area_bg'][0] : null ); |
| 2014 | $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'][0] ) ? $scMeta['tpg_full_area_margin'][0] : null ); |
| 2015 | $sectionMargin = self::formatSpacing( $sectionMargin ); |
| 2016 | $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'][0] ) ? $scMeta['tpg_full_area_padding'][0] : null ); |
| 2017 | $sectionPadding = self::formatSpacing( $sectionPadding ); |
| 2018 | // Box |
| 2019 | $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'][0] ) ? $scMeta['tpg_content_wrap_bg'][0] : null ); |
| 2020 | $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'][0] ) ? $scMeta['tpg_content_wrap_border'][0] : null ); |
| 2021 | $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'][0] ) ? $scMeta['tpg_content_wrap_border_color'][0] : null ); |
| 2022 | $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'][0] ) ? $scMeta['tpg_content_wrap_border_radius'][0] : null ); |
| 2023 | $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'][0] ) ? $scMeta['tpg_content_wrap_shadow'][0] : null ); |
| 2024 | $boxPadding = ( isset( $scMeta['tpg_box_padding'][0] ) ? $scMeta['tpg_box_padding'][0] : null ); |
| 2025 | $boxPadding = self::formatSpacing( $boxPadding ); |
| 2026 | $contentPadding = ( isset( $scMeta['tpg_content_padding'][0] ) ? $scMeta['tpg_content_padding'][0] : null ); |
| 2027 | $contentPadding = self::formatSpacing( $contentPadding ); |
| 2028 | // Heading |
| 2029 | $headingBg = ( isset( $scMeta['tpg_heading_bg'][0] ) ? $scMeta['tpg_heading_bg'][0] : null ); |
| 2030 | $headingColor = ( isset( $scMeta['tpg_heading_color'][0] ) ? $scMeta['tpg_heading_color'][0] : null ); |
| 2031 | $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'][0] ) ? $scMeta['tpg_heading_border_color'][0] : null ); |
| 2032 | $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'][0] ) ? $scMeta['tpg_heading_border_size'][0] : null ); |
| 2033 | $headingMargin = ( isset( $scMeta['tpg_heading_margin'][0] ) ? $scMeta['tpg_heading_margin'][0] : null ); |
| 2034 | $headingMargin = self::formatSpacing( $headingMargin ); |
| 2035 | $headingPadding = ( isset( $scMeta['tpg_heading_padding'][0] ) ? $scMeta['tpg_heading_padding'][0] : null ); |
| 2036 | $headingPadding = self::formatSpacing( $headingPadding ); |
| 2037 | // Category |
| 2038 | $catBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : null ); |
| 2039 | $catTextColor = ( isset( $scMeta['tpg_category_color'][0] ) ? $scMeta['tpg_category_color'][0] : null ); |
| 2040 | $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'][0] ) ? $scMeta['tpg_category_border_radius'][0] : null ); |
| 2041 | $catMargin = ( isset( $scMeta['tpg_category_margin'][0] ) ? $scMeta['tpg_category_margin'][0] : null ); |
| 2042 | $catMargin = self::formatSpacing( $catMargin ); |
| 2043 | $catPadding = ( isset( $scMeta['tpg_category_padding'][0] ) ? $scMeta['tpg_category_padding'][0] : null ); |
| 2044 | $catPadding = self::formatSpacing( $catPadding ); |
| 2045 | $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'][0] ) ? absint( $scMeta['rt_tpg_category_font_size'][0] ) : null ); |
| 2046 | // Image |
| 2047 | $image_border_radius = isset( $scMeta['tpg_image_border_radius'][0] ) ? $scMeta['tpg_image_border_radius'][0] : ''; |
| 2048 | // Title |
| 2049 | $title_color = ( ! empty( $scMeta['title_color'][0] ) ? $scMeta['title_color'][0] : null ); |
| 2050 | $title_size = ( ! empty( $scMeta['title_size'][0] ) ? absint( $scMeta['title_size'][0] ) : null ); |
| 2051 | $title_weight = ( ! empty( $scMeta['title_weight'][0] ) ? $scMeta['title_weight'][0] : null ); |
| 2052 | $title_alignment = ( ! empty( $scMeta['title_alignment'][0] ) ? $scMeta['title_alignment'][0] : null ); |
| 2053 | |
| 2054 | $title_hover_color = ( ! empty( $scMeta['title_hover_color'][0] ) ? $scMeta['title_hover_color'][0] : null ); |
| 2055 | |
| 2056 | $excerpt_color = ( ! empty( $scMeta['excerpt_color'][0] ) ? $scMeta['excerpt_color'][0] : null ); |
| 2057 | $excerpt_size = ( ! empty( $scMeta['excerpt_size'][0] ) ? absint( $scMeta['excerpt_size'][0] ) : null ); |
| 2058 | $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'][0] ) ? $scMeta['excerpt_weight'][0] : null ); |
| 2059 | $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'][0] ) ? $scMeta['excerpt_alignment'][0] : null ); |
| 2060 | |
| 2061 | $meta_data_color = ( ! empty( $scMeta['meta_data_color'][0] ) ? $scMeta['meta_data_color'][0] : null ); |
| 2062 | $meta_data_size = ( ! empty( $scMeta['meta_data_size'][0] ) ? absint( $scMeta['meta_data_size'][0] ) : null ); |
| 2063 | $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'][0] ) ? $scMeta['meta_data_weight'][0] : null ); |
| 2064 | $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'][0] ) ? $scMeta['meta_data_alignment'][0] : null ); |
| 2065 | } else { |
| 2066 | $primaryColor = ( isset( $scMeta['primary_color'] ) ? $scMeta['primary_color'] : null ); |
| 2067 | $button_bg_color = ( isset( $scMeta['button_bg_color'] ) ? $scMeta['button_bg_color'] : null ); |
| 2068 | $button_active_bg_color = ( isset( $scMeta['button_active_bg_color'] ) ? $scMeta['button_active_bg_color'] : null ); |
| 2069 | $button_hover_bg_color = ( isset( $scMeta['button_hover_bg_color'] ) ? $scMeta['button_hover_bg_color'] : null ); |
| 2070 | $btn_text_color = get_post_meta( $scMeta['sc_id'], 'button_text_color', true ); |
| 2071 | $button_text_color = ( ! empty( $scMeta['button_text_bg_color'] ) ? $scMeta['button_text_bg_color'] |
| 2072 | : ( ! empty( $btn_text_color ) ? $btn_text_color : null ) ); |
| 2073 | $button_border_color = ( isset( $scMeta['button_border_color'] ) ? $scMeta['button_border_color'] : null ); |
| 2074 | $button_hover_text_color = ( isset( $scMeta['button_hover_text_color'] ) ? $scMeta['button_hover_text_color'] : null ); |
| 2075 | $overlay_color = ( ! empty( $scMeta['overlay_color'] ) ? self::rtHex2rgba( |
| 2076 | $scMeta['overlay_color'], |
| 2077 | ! empty( $scMeta['overlay_opacity'] ) ? absint( $scMeta['overlay_opacity'] ) / 10 : .8 |
| 2078 | ) : null ); |
| 2079 | $overlay_padding = ( ! empty( $scMeta['overlay_padding'] ) ? absint( $scMeta['overlay_padding'] ) : null ); |
| 2080 | $gutter = ! empty( $scMeta['tgp_gutter'] ) ? absint( $scMeta['tgp_gutter'] ) : null; |
| 2081 | $read_more_button_border_radius = isset( $scMeta['tpg_read_more_button_border_radius'] ) ? $scMeta['tpg_read_more_button_border_radius'] : ''; |
| 2082 | // Section |
| 2083 | $sectionBg = ( isset( $scMeta['tpg_full_area_bg'] ) ? $scMeta['tpg_full_area_bg'] : null ); |
| 2084 | $sectionMargin = ( isset( $scMeta['tpg_full_area_margin'] ) ? $scMeta['tpg_full_area_margin'] : null ); |
| 2085 | $sectionMargin = self::formatSpacing( $sectionMargin ); |
| 2086 | $sectionPadding = ( isset( $scMeta['tpg_full_area_padding'] ) ? $scMeta['tpg_full_area_padding'] : null ); |
| 2087 | $sectionPadding = self::formatSpacing( $sectionPadding ); |
| 2088 | // Box |
| 2089 | $boxBg = ( isset( $scMeta['tpg_content_wrap_bg'] ) ? $scMeta['tpg_content_wrap_bg'] : null ); |
| 2090 | $boxBorder = ( isset( $scMeta['tpg_content_wrap_border'] ) ? $scMeta['tpg_content_wrap_border'] : null ); |
| 2091 | $boxBorderColor = ( isset( $scMeta['tpg_content_wrap_border_color'] ) ? $scMeta['tpg_content_wrap_border_color'] : null ); |
| 2092 | $boxBorderRadius = ( isset( $scMeta['tpg_content_wrap_border_radius'] ) ? $scMeta['tpg_content_wrap_border_radius'] : null ); |
| 2093 | $boxShadow = ( isset( $scMeta['tpg_content_wrap_shadow'] ) ? $scMeta['tpg_content_wrap_shadow'] : null ); |
| 2094 | $boxPadding = ( isset( $scMeta['tpg_box_padding'] ) ? $scMeta['tpg_box_padding'] : null ); |
| 2095 | $boxPadding = self::formatSpacing( $boxPadding ); |
| 2096 | $contentPadding = ( isset( $scMeta['tpg_content_padding'] ) ? $scMeta['tpg_content_padding'] : null ); |
| 2097 | $contentPadding = self::formatSpacing( $contentPadding ); |
| 2098 | // Heading |
| 2099 | $headingBg = ( isset( $scMeta['tpg_heading_bg'] ) ? $scMeta['tpg_heading_bg'] : null ); |
| 2100 | $headingColor = ( isset( $scMeta['tpg_heading_color'] ) ? $scMeta['tpg_heading_color'] : null ); |
| 2101 | $headingBorderColor = ( isset( $scMeta['tpg_heading_border_color'] ) ? $scMeta['tpg_heading_border_color'] : null ); |
| 2102 | $headingBorderSize = ( isset( $scMeta['tpg_heading_border_size'] ) ? $scMeta['tpg_heading_border_size'] : null ); |
| 2103 | $headingMargin = ( isset( $scMeta['tpg_heading_margin'] ) ? $scMeta['tpg_heading_margin'] : null ); |
| 2104 | $headingMargin = self::formatSpacing( $headingMargin ); |
| 2105 | $headingPadding = ( isset( $scMeta['tpg_heading_padding'] ) ? $scMeta['tpg_heading_padding'] : null ); |
| 2106 | $headingPadding = self::formatSpacing( $headingPadding ); |
| 2107 | // Category |
| 2108 | $catBg = ( isset( $scMeta['tpg_category_bg'] ) ? $scMeta['tpg_category_bg'] : null ); |
| 2109 | $catTextColor = ( isset( $scMeta['tpg_category_color'] ) ? $scMeta['tpg_category_color'] : null ); |
| 2110 | $catBorderRadius = ( isset( $scMeta['tpg_category_border_radius'] ) ? $scMeta['tpg_category_border_radius'] : null ); |
| 2111 | $catMargin = ( isset( $scMeta['tpg_category_margin'] ) ? $scMeta['tpg_category_margin'] : null ); |
| 2112 | $catPadding = ( isset( $scMeta['tpg_category_padding'] ) ? $scMeta['tpg_category_padding'] : null ); |
| 2113 | $categorySize = ( ! empty( $scMeta['rt_tpg_category_font_size'] ) ? absint( $scMeta['rt_tpg_category_font_size'] ) : null ); |
| 2114 | // Image |
| 2115 | $image_border_radius = isset( $scMeta['tpg_image_border_radius'] ) ? $scMeta['tpg_image_border_radius'] : ''; |
| 2116 | // Title |
| 2117 | $title_color = ( ! empty( $scMeta['title_color'] ) ? $scMeta['title_color'] : null ); |
| 2118 | $title_size = ( ! empty( $scMeta['title_size'] ) ? absint( $scMeta['title_size'] ) : null ); |
| 2119 | $title_weight = ( ! empty( $scMeta['title_weight'] ) ? $scMeta['title_weight'] : null ); |
| 2120 | $title_alignment = ( ! empty( $scMeta['title_alignment'] ) ? $scMeta['title_alignment'] : null ); |
| 2121 | |
| 2122 | $title_hover_color = ( ! empty( $scMeta['title_hover_color'] ) ? $scMeta['title_hover_color'] : null ); |
| 2123 | |
| 2124 | $excerpt_color = ( ! empty( $scMeta['excerpt_color'] ) ? $scMeta['excerpt_color'] : null ); |
| 2125 | $excerpt_size = ( ! empty( $scMeta['excerpt_size'] ) ? absint( $scMeta['excerpt_size'] ) : null ); |
| 2126 | $excerpt_weight = ( ! empty( $scMeta['excerpt_weight'] ) ? $scMeta['excerpt_weight'] : null ); |
| 2127 | $excerpt_alignment = ( ! empty( $scMeta['excerpt_alignment'] ) ? $scMeta['excerpt_alignment'] : null ); |
| 2128 | |
| 2129 | $meta_data_color = ( ! empty( $scMeta['meta_data_color'] ) ? $scMeta['meta_data_color'] : null ); |
| 2130 | $meta_data_size = ( ! empty( $scMeta['meta_data_size'] ) ? absint( $scMeta['meta_data_size'] ) : null ); |
| 2131 | $meta_data_weight = ( ! empty( $scMeta['meta_data_weight'] ) ? $scMeta['meta_data_weight'] : null ); |
| 2132 | $meta_data_alignment = ( ! empty( $scMeta['meta_data_alignment'] ) ? $scMeta['meta_data_alignment'] : null ); |
| 2133 | } |
| 2134 | |
| 2135 | $id = str_replace( 'rt-tpg-container-', '', $layoutID ); |
| 2136 | |
| 2137 | if ( $primaryColor ) { |
| 2138 | $css .= "#{$layoutID} .rt-holder .rt-woo-info .price{"; |
| 2139 | $css .= 'color:' . $primaryColor . ';'; |
| 2140 | $css .= '}'; |
| 2141 | $css .= "body .rt-tpg-container .rt-tpg-isotope-buttons .selected, |
| 2142 | #{$layoutID} .layout12 .rt-holder:hover .rt-detail, |
| 2143 | #{$layoutID} .isotope8 .rt-holder:hover .rt-detail, |
| 2144 | #{$layoutID} .carousel8 .rt-holder:hover .rt-detail, |
| 2145 | #{$layoutID} .layout13 .rt-holder .overlay .post-info, |
| 2146 | #{$layoutID} .isotope9 .rt-holder .overlay .post-info, |
| 2147 | #{$layoutID}.rt-tpg-container .layout4 .rt-holder .rt-detail, |
| 2148 | .rt-modal-{$id} .md-content, |
| 2149 | .rt-modal-{$id} .md-content > .rt-md-content-holder .rt-md-content, |
| 2150 | .rt-popup-wrap-{$id}.rt-popup-wrap .rt-popup-navigation-wrap, |
| 2151 | #{$layoutID} .carousel9 .rt-holder .overlay .post-info{"; |
| 2152 | $css .= 'background-color:' . $primaryColor . ';'; |
| 2153 | $css .= '}'; |
| 2154 | |
| 2155 | $ocp = self::rtHex2rgba( |
| 2156 | $primaryColor, |
| 2157 | ! empty( $scMeta['overlay_opacity'][0] ) ? absint( $scMeta['overlay_opacity'][0] ) / 10 : .8 |
| 2158 | ); |
| 2159 | $css .= "#{$layoutID} .layout5 .rt-holder .overlay, #{$layoutID} .isotope2 .rt-holder .overlay, #{$layoutID} .carousel2 .rt-holder .overlay,#{$layoutID} .layout15 .rt-holder h3, #{$layoutID} .isotope11 .rt-holder h3, #{$layoutID} .carousel11 .rt-holder h3, #{$layoutID} .layout16 .rt-holder h3, |
| 2160 | #{$layoutID} .isotope12 .rt-holder h3, #{$layoutID} .carousel12 .rt-holder h3 {"; |
| 2161 | $css .= 'background-color:' . $ocp . ';'; |
| 2162 | $css .= '}'; |
| 2163 | } |
| 2164 | |
| 2165 | if ( $button_border_color ) { |
| 2166 | $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item, |
| 2167 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item, |
| 2168 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn, |
| 2169 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action, |
| 2170 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item, |
| 2171 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap{"; |
| 2172 | $css .= 'border-color:' . $button_border_color . ' !important;'; |
| 2173 | $css .= '}'; |
| 2174 | $css .= "#{$layoutID} .rt-holder .read-more a {"; |
| 2175 | $css .= 'border-color:' . $button_border_color . ';'; |
| 2176 | $css .= '}'; |
| 2177 | } |
| 2178 | |
| 2179 | if ( $button_bg_color ) { |
| 2180 | $css .= "#{$layoutID} .pagination-list li a, |
| 2181 | {$layoutID} .pagination-list li span, |
| 2182 | {$layoutID} .pagination li a, |
| 2183 | #{$layoutID} .rt-tpg-isotope-buttons button, |
| 2184 | #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button, |
| 2185 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn, |
| 2186 | #{$layoutID}.rt-tpg-container .swiper-pagination-bullet, |
| 2187 | #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a, |
| 2188 | #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart, |
| 2189 | #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart, |
| 2190 | #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart, |
| 2191 | #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart, |
| 2192 | #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart, |
| 2193 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown, |
| 2194 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item, |
| 2195 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a, |
| 2196 | #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item, |
| 2197 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn, |
| 2198 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *, |
| 2199 | #{$layoutID} .rt-read-more, |
| 2200 | #rt-tooltip-{$id}, #rt-tooltip-{$id} .rt-tooltip-bottom:after{"; |
| 2201 | $css .= 'background-color:' . $button_bg_color . ';'; |
| 2202 | $css .= '}'; |
| 2203 | $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item, |
| 2204 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item{"; |
| 2205 | $css .= 'border-color:' . $button_bg_color . ';'; |
| 2206 | $css .= '}'; |
| 2207 | $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom .fa{"; |
| 2208 | $css .= 'color:' . $button_bg_color . ';'; |
| 2209 | $css .= '}'; |
| 2210 | |
| 2211 | $css .= "#{$layoutID} .rt-holder .read-more a {"; |
| 2212 | $css .= 'background-color:' . $button_bg_color . ';padding: 8px 15px;'; |
| 2213 | $css .= '}'; |
| 2214 | } |
| 2215 | |
| 2216 | // button active color. |
| 2217 | if ( $button_active_bg_color ) { |
| 2218 | $css .= "#{$layoutID} .pagination li.active span, |
| 2219 | #{$layoutID} .pagination-list li.active span, |
| 2220 | #{$layoutID} .rt-tpg-isotope-buttons button.selected, |
| 2221 | #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected, |
| 2222 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected, |
| 2223 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a, |
| 2224 | #{$layoutID}.rt-tpg-container .swiper-pagination-bullet.swiper-pagination-bullet-active-main{"; |
| 2225 | $css .= 'background-color:' . $button_active_bg_color . ';'; |
| 2226 | $css .= '}'; |
| 2227 | |
| 2228 | $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected, |
| 2229 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item.selected, |
| 2230 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{"; |
| 2231 | $css .= 'border-color:' . $button_active_bg_color . ';'; |
| 2232 | $css .= '}'; |
| 2233 | } |
| 2234 | |
| 2235 | // Button hover bg color. |
| 2236 | if ( $button_hover_bg_color ) { |
| 2237 | $css .= "#{$layoutID} .pagination-list li a:hover, |
| 2238 | #{$layoutID} .pagination li a:hover, |
| 2239 | #{$layoutID} .rt-tpg-isotope-buttons button:hover, |
| 2240 | #{$layoutID} .rt-holder .read-more a:hover, |
| 2241 | #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover, |
| 2242 | #{$layoutID}.rt-tpg-container .swiper-pagination-bullet:hover, |
| 2243 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover, |
| 2244 | #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a:hover, |
| 2245 | #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart:hover, |
| 2246 | #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart:hover, |
| 2247 | #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart:hover, |
| 2248 | #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart:hover, |
| 2249 | #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart:hover, |
| 2250 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover, |
| 2251 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected, |
| 2252 | #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover, |
| 2253 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover, |
| 2254 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover, |
| 2255 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *:hover, |
| 2256 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover, |
| 2257 | #{$layoutID} .rt-read-more:hover, |
| 2258 | #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button:hover{"; |
| 2259 | $css .= 'background-color:' . $button_hover_bg_color . ';'; |
| 2260 | $css .= '}'; |
| 2261 | |
| 2262 | $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover, |
| 2263 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover, |
| 2264 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover, |
| 2265 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a:hover{"; |
| 2266 | $css .= 'border-color:' . $button_hover_bg_color . ';'; |
| 2267 | $css .= '}'; |
| 2268 | $css .= "#{$layoutID}.rt-tpg-container .layout17 .rt-holder .overlay a.tpg-zoom:hover .fa{"; |
| 2269 | $css .= 'color:' . $button_hover_bg_color . ';'; |
| 2270 | $css .= '}'; |
| 2271 | } |
| 2272 | |
| 2273 | // Button text color. |
| 2274 | if ( $button_text_color ) { |
| 2275 | $css .= "#{$layoutID} .pagination-list li a, |
| 2276 | #{$layoutID} .pagination li a, |
| 2277 | #{$layoutID} .rt-tpg-isotope-buttons button, |
| 2278 | #{$layoutID} .rt-holder .read-more a, |
| 2279 | #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button, |
| 2280 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn, |
| 2281 | #{$layoutID} .wc1 .rt-holder .rt-img-holder .overlay .product-more ul li a, |
| 2282 | #{$layoutID} .edd1 .rt-holder .rt-img-holder .overlay .product-more ul li a, |
| 2283 | #{$layoutID} .wc2 .rt-detail .rt-wc-add-to-cart, |
| 2284 | #{$layoutID} .wc3 .rt-detail .rt-wc-add-to-cart, |
| 2285 | #{$layoutID} .edd2 .rt-detail .rt-wc-add-to-cart, |
| 2286 | #{$layoutID} .wc4 .rt-detail .rt-wc-add-to-cart, |
| 2287 | #{$layoutID} .edd3 .rt-detail .rt-wc-add-to-cart, |
| 2288 | #{$layoutID} .wc-carousel2 .rt-detail .rt-wc-add-to-cart, |
| 2289 | #{$layoutID} .wc-isotope2 .rt-detail .rt-wc-add-to-cart, |
| 2290 | #{$layoutID} .rt-tpg-utility .rt-tpg-load-more button, |
| 2291 | #rt-tooltip-{$id}, |
| 2292 | #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item, |
| 2293 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item, |
| 2294 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action, |
| 2295 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item, |
| 2296 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li>a, |
| 2297 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-cb-page-prev-next > *, |
| 2298 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn, |
| 2299 | #{$layoutID} .rt-read-more, |
| 2300 | #rt-tooltip-{$id} .rt-tooltip-bottom:after{"; |
| 2301 | $css .= 'color:' . $button_text_color . ';'; |
| 2302 | $css .= '}'; |
| 2303 | } |
| 2304 | |
| 2305 | if ( $button_hover_text_color ) { |
| 2306 | $css .= "#{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item:hover, |
| 2307 | #{$layoutID} .rt-holder .read-more a:hover, |
| 2308 | #{$layoutID}.rt-tpg-container .swiper-navigation .slider-btn:hover, |
| 2309 | #{$layoutID} .rt-layout-filter-container .rt-filter-sub-tax.sub-button-group .rt-filter-button-item:hover, |
| 2310 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item:hover, |
| 2311 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-filter-dropdown-wrap .rt-filter-dropdown .rt-filter-dropdown-item.selected, |
| 2312 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action:hover, |
| 2313 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a:hover, |
| 2314 | #{$layoutID} .rt-filter-item-wrap.rt-filter-button-wrap span.rt-filter-button-item.selected, |
| 2315 | #{$layoutID} .rt-layout-filter-container .rt-filter-wrap .rt-filter-item-wrap.rt-sort-order-action, |
| 2316 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-loadmore-btn:hover, |
| 2317 | #{$layoutID} .rt-read-more:hover, |
| 2318 | #{$layoutID}.rt-tpg-container .rt-pagination-wrap .rt-page-numbers .paginationjs .paginationjs-pages ul li.active>a{"; |
| 2319 | $css .= 'color:' . $button_hover_text_color . ';'; |
| 2320 | $css .= '}'; |
| 2321 | } |
| 2322 | |
| 2323 | if ( $overlay_color || $overlay_padding ) { |
| 2324 | if ( in_array( $layout, [ 'layout15', 'isotope11', 'carousel11' ] ) ) { |
| 2325 | $css .= "#{$layoutID} .{$layout} .rt-holder:hover .overlay .post-info{"; |
| 2326 | } else if ( in_array( |
| 2327 | $layout, |
| 2328 | [ 'layout10', 'isotope7', 'carousel6', 'carousel7', 'layout9', 'offset04' ] |
| 2329 | ) |
| 2330 | ) { |
| 2331 | $css .= "#{$layoutID} .{$layout} .rt-holder .post-info{"; |
| 2332 | } else if ( in_array( $layout, [ 'layout7', 'isotope4', 'carousel4' ] ) ) { |
| 2333 | $css .= "#{$layoutID} .{$layout} .rt-holder .overlay:hover{"; |
| 2334 | } else if ( in_array( $layout, [ 'layout16', 'isotope12', 'carousel12' ] ) ) { |
| 2335 | $css .= "#{$layoutID} .{$layout} .rt-holder .overlay .post-info {"; |
| 2336 | } else if ( in_array( $layout, [ 'offset03', 'carousel5' ] ) ) { |
| 2337 | $css .= "#{$layoutID} .{$layout} .rt-holder .overlay{"; |
| 2338 | } else { |
| 2339 | $css .= "#{$layoutID} .rt-post-overlay .post-img > a:first-of-type::after,"; |
| 2340 | $css .= "#{$layoutID} .rt-holder .overlay:hover{"; |
| 2341 | } |
| 2342 | |
| 2343 | if ( $overlay_color ) { |
| 2344 | $css .= 'background-image: none;'; |
| 2345 | $css .= 'background-color:' . $overlay_color . ';'; |
| 2346 | } |
| 2347 | |
| 2348 | if ( $overlay_padding ) { |
| 2349 | $css .= 'padding-top:' . $overlay_padding . '%;'; |
| 2350 | } |
| 2351 | |
| 2352 | $css .= '}'; |
| 2353 | } |
| 2354 | |
| 2355 | if ( $boxShadow ) { |
| 2356 | $css .= "#{$layoutID} .{$layout} .rt-holder {"; |
| 2357 | $css .= "box-shadow : 0px 0px 2px 0px {$boxShadow};"; |
| 2358 | $css .= '}'; |
| 2359 | } |
| 2360 | |
| 2361 | /* gutter */ |
| 2362 | if ( $gutter ) { |
| 2363 | $css .= "#{$layoutID} [class*='rt-col-'] {"; |
| 2364 | $css .= "padding-left : {$gutter}px !important;"; |
| 2365 | $css .= "padding-right : {$gutter}px !important;"; |
| 2366 | $css .= "margin-top : {$gutter}px;"; |
| 2367 | $css .= "margin-bottom : {$gutter}px;"; |
| 2368 | $css .= '}'; |
| 2369 | $css .= "#{$layoutID} .rt-row{"; |
| 2370 | $css .= "margin-left : -{$gutter}px !important;"; |
| 2371 | $css .= "margin-right : -{$gutter}px !important;"; |
| 2372 | $css .= '}'; |
| 2373 | $css .= "#{$layoutID}.rt-container-fluid,#{$layoutID}.rt-container{"; |
| 2374 | $css .= "padding-left : {$gutter}px;"; |
| 2375 | $css .= "padding-right : {$gutter}px;"; |
| 2376 | $css .= '}'; |
| 2377 | |
| 2378 | // remove inner row margin. |
| 2379 | $css .= "#{$layoutID} .rt-row .rt-row [class*='rt-col-'] {"; |
| 2380 | $css .= 'margin-top : 0;'; |
| 2381 | $css .= '}'; |
| 2382 | } |
| 2383 | |
| 2384 | // Read more button border radius. |
| 2385 | if ( isset( $read_more_button_border_radius ) || trim( $read_more_button_border_radius ) !== '' ) { |
| 2386 | $css .= "#{$layoutID} .read-more a{"; |
| 2387 | $css .= 'border-radius:' . $read_more_button_border_radius . 'px;'; |
| 2388 | $css .= '}'; |
| 2389 | } |
| 2390 | |
| 2391 | // Section. |
| 2392 | if ( $sectionBg ) { |
| 2393 | $css .= "#{$layoutID}.rt-tpg-container {"; |
| 2394 | $css .= 'background:' . $sectionBg . ';'; |
| 2395 | $css .= '}'; |
| 2396 | } |
| 2397 | |
| 2398 | if ( $sectionMargin ) { |
| 2399 | $css .= "#{$layoutID}.rt-tpg-container {"; |
| 2400 | $css .= 'margin:' . $sectionMargin . 'px;'; |
| 2401 | $css .= '}'; |
| 2402 | } |
| 2403 | |
| 2404 | if ( $sectionPadding ) { |
| 2405 | $css .= "#{$layoutID}.rt-tpg-container {"; |
| 2406 | $css .= 'padding:' . $sectionPadding . 'px;'; |
| 2407 | $css .= '}'; |
| 2408 | } |
| 2409 | |
| 2410 | // Box. |
| 2411 | if ( $boxBg ) { |
| 2412 | $css .= "#{$layoutID} .rt-holder, #{$layoutID} .rt-holder .rt-detail,#{$layoutID} .rt-post-overlay .post-img + .post-content {"; |
| 2413 | $css .= 'background-color:' . $boxBg . ';'; |
| 2414 | $css .= '}'; |
| 2415 | } |
| 2416 | |
| 2417 | if ( $boxBorderColor ) { |
| 2418 | $css .= "#{$layoutID} .rt-holder {"; |
| 2419 | $css .= 'border-color:' . $boxBorderColor . ';'; |
| 2420 | $css .= '}'; |
| 2421 | } |
| 2422 | |
| 2423 | if ( $boxBorder ) { |
| 2424 | $css .= "#{$layoutID} .rt-holder {"; |
| 2425 | $css .= 'border-style: solid;'; |
| 2426 | $css .= 'border-width:' . $boxBorder . 'px;'; |
| 2427 | $css .= '}'; |
| 2428 | } |
| 2429 | |
| 2430 | if ( $boxBorderRadius ) { |
| 2431 | $css .= "#{$layoutID} .rt-holder {"; |
| 2432 | $css .= 'border-radius:' . $boxBorderRadius . 'px;'; |
| 2433 | $css .= '}'; |
| 2434 | } |
| 2435 | |
| 2436 | if ( $boxPadding ) { |
| 2437 | $css .= "#{$layoutID} .rt-holder {"; |
| 2438 | $css .= 'padding:' . $boxPadding . 'px;'; |
| 2439 | $css .= '}'; |
| 2440 | } |
| 2441 | |
| 2442 | if ( $contentPadding ) { |
| 2443 | $css .= "#{$layoutID} .rt-holder .rt-detail {"; |
| 2444 | $css .= 'padding:' . $contentPadding . 'px;'; |
| 2445 | $css .= '}'; |
| 2446 | } |
| 2447 | |
| 2448 | // Widget heading. |
| 2449 | if ( $headingBg ) { |
| 2450 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading {"; |
| 2451 | $css .= 'background:' . $headingBg . ';'; |
| 2452 | $css .= '}'; |
| 2453 | |
| 2454 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading::after {"; |
| 2455 | $css .= 'border-top-color:' . $headingBg . ';'; |
| 2456 | $css .= '}'; |
| 2457 | } |
| 2458 | |
| 2459 | if ( $headingColor ) { |
| 2460 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading a, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2 .tpg-widget-heading a, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 .tpg-widget-heading a {"; |
| 2461 | $css .= 'color:' . $headingColor . ';'; |
| 2462 | $css .= '}'; |
| 2463 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading::before {"; |
| 2464 | $css .= 'background-color:' . $headingColor . ';'; |
| 2465 | $css .= '}'; |
| 2466 | } |
| 2467 | |
| 2468 | if ( $headingBorderSize ) { |
| 2469 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 {"; |
| 2470 | // $css .= "border-bottom-style: solid;"; |
| 2471 | $css .= 'border-bottom-width:' . $headingBorderSize . 'px;'; |
| 2472 | $css .= '}'; |
| 2473 | |
| 2474 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading-line {"; |
| 2475 | $css .= 'border-width:' . $headingBorderSize . 'px 0;'; |
| 2476 | $css .= '}'; |
| 2477 | } |
| 2478 | |
| 2479 | if ( $headingBorderColor ) { |
| 2480 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper.heading-style1 .tpg-widget-heading-line, #{$layoutID} .tpg-widget-heading-wrapper.heading-style2, #{$layoutID} .tpg-widget-heading-wrapper.heading-style3 {"; |
| 2481 | $css .= 'border-color:' . $headingBorderColor . ';'; |
| 2482 | $css .= '}'; |
| 2483 | } |
| 2484 | |
| 2485 | if ( $headingMargin ) { |
| 2486 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper {"; |
| 2487 | $css .= 'margin:' . $headingMargin . 'px;'; |
| 2488 | $css .= '}'; |
| 2489 | } |
| 2490 | |
| 2491 | if ( $headingPadding ) { |
| 2492 | $css .= "#{$layoutID} .tpg-widget-heading-wrapper .tpg-widget-heading {"; |
| 2493 | $css .= 'padding:' . $headingPadding . 'px;'; |
| 2494 | $css .= '}'; |
| 2495 | } |
| 2496 | |
| 2497 | // Image border. |
| 2498 | if ( isset( $image_border_radius ) || trim( $image_border_radius ) !== '' ) { |
| 2499 | $css .= "#{$layoutID} .rt-img-holder img.rt-img-responsive,#{$layoutID} .rt-img-holder, |
| 2500 | #{$layoutID} .rt-post-overlay .post-img, |
| 2501 | #{$layoutID} .post-sm .post-img, |
| 2502 | #{$layoutID} .rt-post-grid .post-img, |
| 2503 | #{$layoutID} .post-img img {"; |
| 2504 | $css .= 'border-radius:' . $image_border_radius . 'px;'; |
| 2505 | $css .= '}'; |
| 2506 | } |
| 2507 | |
| 2508 | // Title decoration. |
| 2509 | if ( $title_color || $title_size || $title_weight || $title_alignment ) { |
| 2510 | $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title, |
| 2511 | #{$layoutID} .{$layout} .rt-holder h3.entry-title, |
| 2512 | #{$layoutID} .{$layout} .rt-holder h4.entry-title, |
| 2513 | #{$layoutID} .{$layout} .rt-holder h2.entry-title a, |
| 2514 | #{$layoutID} .{$layout} .rt-holder h3.entry-title a, |
| 2515 | #{$layoutID} .{$layout} .rt-holder h4.entry-title a, |
| 2516 | #{$layoutID} .rt-holder .rt-woo-info h2 a, |
| 2517 | #{$layoutID} .rt-holder .rt-woo-info h3 a, |
| 2518 | #{$layoutID} .rt-holder .rt-woo-info h4 a, |
| 2519 | #{$layoutID} .post-content .post-title, |
| 2520 | #{$layoutID} .rt-post-grid .post-title, |
| 2521 | #{$layoutID} .rt-post-grid .post-title a, |
| 2522 | #{$layoutID} .post-content .post-title a, |
| 2523 | #{$layoutID} .rt-holder .rt-woo-info h2, |
| 2524 | #{$layoutID} .rt-holder .rt-woo-info h3, |
| 2525 | #{$layoutID} .rt-holder .rt-woo-info h4{"; |
| 2526 | |
| 2527 | if ( $title_color ) { |
| 2528 | $css .= 'color:' . $title_color . ';'; |
| 2529 | } |
| 2530 | |
| 2531 | if ( $title_size ) { |
| 2532 | $lineHeight = $title_size + 10; |
| 2533 | $css .= 'font-size:' . $title_size . 'px;'; |
| 2534 | $css .= 'line-height:' . $lineHeight . 'px;'; |
| 2535 | } |
| 2536 | |
| 2537 | if ( $title_weight ) { |
| 2538 | $css .= 'font-weight:' . $title_weight . ';'; |
| 2539 | } |
| 2540 | |
| 2541 | if ( $title_alignment ) { |
| 2542 | $css .= 'text-align:' . $title_alignment . ';'; |
| 2543 | } |
| 2544 | |
| 2545 | $css .= '}'; |
| 2546 | |
| 2547 | if ( $title_size ) { |
| 2548 | $css .= "#{$layoutID} .post-grid-lg-style-1 .post-title, |
| 2549 | #{$layoutID} .post-grid-lg-style-1 .post-title a, |
| 2550 | #{$layoutID} .big-layout .post-title, |
| 2551 | #{$layoutID} .big-layout .post-title a, |
| 2552 | #{$layoutID} .post-grid-lg-style-1 .post-title, |
| 2553 | #{$layoutID} .post-grid-lg-style-1 .post-title a {"; |
| 2554 | $css .= 'font-size:' . ( $title_size + 8 ) . 'px;'; |
| 2555 | $css .= 'line-height:' . ( $lineHeight + 8 ) . 'px;'; |
| 2556 | $css .= '}'; |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | // Title hover color. |
| 2561 | if ( $title_hover_color ) { |
| 2562 | $css .= "#{$layoutID} .{$layout} .rt-holder h2.entry-title:hover, |
| 2563 | #{$layoutID} .{$layout} .rt-holder h3.entry-title:hover, |
| 2564 | #{$layoutID} .{$layout} .rt-holder h4.entry-title:hover, |
| 2565 | #{$layoutID} .{$layout} .rt-holder h2.entry-title a:hover, |
| 2566 | #{$layoutID} .{$layout} .rt-holder h3.entry-title a:hover, |
| 2567 | #{$layoutID} .{$layout} .rt-holder h4.entry-title a:hover, |
| 2568 | #{$layoutID} .post-content .post-title a:hover, |
| 2569 | #{$layoutID} .rt-post-grid .post-title a:hover, |
| 2570 | #{$layoutID} .rt-holder .rt-woo-info h2 a:hover, |
| 2571 | #{$layoutID} .rt-holder .rt-woo-info h3 a:hover, |
| 2572 | #{$layoutID} .rt-holder .rt-woo-info h4 a:hover, |
| 2573 | #{$layoutID} .rt-holder .rt-woo-info h2:hover, |
| 2574 | #{$layoutID} .rt-holder .rt-woo-info h3:hover, |
| 2575 | #{$layoutID} .rt-holder .rt-woo-info h4:hover{"; |
| 2576 | $css .= 'color:' . $title_hover_color . ' !important;'; |
| 2577 | $css .= '}'; |
| 2578 | } |
| 2579 | // Excerpt decoration. |
| 2580 | if ( $excerpt_color || $excerpt_size || $excerpt_weight || $excerpt_alignment ) { |
| 2581 | $css .= "#{$layoutID} .{$layout} .rt-holder .tpg-excerpt,#{$layoutID} .{$layout} .tpg-excerpt,#{$layoutID} .{$layout} .rt-holder .post-content,#{$layoutID} .rt-holder .rt-woo-info p,#{$layoutID} .post-content p {"; |
| 2582 | |
| 2583 | if ( $excerpt_color ) { |
| 2584 | $css .= 'color:' . $excerpt_color . ';'; |
| 2585 | } |
| 2586 | |
| 2587 | if ( $excerpt_size ) { |
| 2588 | $css .= 'font-size:' . $excerpt_size . 'px;'; |
| 2589 | } |
| 2590 | |
| 2591 | if ( $excerpt_weight ) { |
| 2592 | $css .= 'font-weight:' . $excerpt_weight . ';'; |
| 2593 | } |
| 2594 | |
| 2595 | if ( $excerpt_alignment ) { |
| 2596 | $css .= 'text-align:' . $excerpt_alignment . ';'; |
| 2597 | } |
| 2598 | |
| 2599 | $css .= '}'; |
| 2600 | } |
| 2601 | |
| 2602 | // Post meta decoration. |
| 2603 | if ( $meta_data_color || $meta_data_size || $meta_data_weight || $meta_data_alignment ) { |
| 2604 | $css .= "#{$layoutID} .{$layout} .rt-holder .post-meta-user, |
| 2605 | #{$layoutID} .{$layout} .rt-meta, |
| 2606 | #{$layoutID} .{$layout} .rt-meta a, |
| 2607 | #{$layoutID} .{$layout} .rt-holder .post-meta-user .meta-data, |
| 2608 | #{$layoutID} .{$layout} .rt-holder .post-meta-user a, |
| 2609 | #{$layoutID} .{$layout} .rt-holder .rt-detail .post-meta .rt-tpg-social-share, |
| 2610 | #{$layoutID} .rt-post-overlay .post-meta-user span, |
| 2611 | #{$layoutID} .rt-post-overlay .post-meta-user, |
| 2612 | #{$layoutID} .rt-post-overlay .post-meta-user a, |
| 2613 | #{$layoutID} .rt-post-grid .post-meta-user, |
| 2614 | #{$layoutID} .rt-post-grid .post-meta-user a, |
| 2615 | #{$layoutID} .rt-post-box-media-style .post-meta-user, |
| 2616 | #{$layoutID} .rt-post-box-media-style .post-meta-user a, |
| 2617 | #{$layoutID} .{$layout} .post-meta-user i, |
| 2618 | #{$layoutID} .rt-detail .post-meta-category a, |
| 2619 | #{$layoutID} .{$layout} .post-meta-user a |
| 2620 | #{$layoutID} .{$layout} .post-meta-user a {"; |
| 2621 | |
| 2622 | if ( $meta_data_color ) { |
| 2623 | $css .= 'color:' . $meta_data_color . ';'; |
| 2624 | } |
| 2625 | |
| 2626 | if ( $meta_data_size ) { |
| 2627 | $css .= 'font-size:' . $meta_data_size . 'px;'; |
| 2628 | } |
| 2629 | |
| 2630 | if ( $meta_data_weight ) { |
| 2631 | $css .= 'font-weight:' . $meta_data_weight . ';'; |
| 2632 | } |
| 2633 | |
| 2634 | if ( $meta_data_alignment ) { |
| 2635 | $css .= 'text-align:' . $meta_data_alignment . ';'; |
| 2636 | } |
| 2637 | |
| 2638 | $css .= '}'; |
| 2639 | } |
| 2640 | |
| 2641 | // Category. |
| 2642 | if ( $catBg ) { |
| 2643 | $css .= "#{$layoutID} .cat-over-image.style2 .categories-links a, |
| 2644 | #{$layoutID} .cat-over-image.style3 .categories-links a, |
| 2645 | #{$layoutID} .cat-above-title.style2 .categories-links a, |
| 2646 | #{$layoutID} .cat-above-title.style3 .categories-links a, |
| 2647 | #{$layoutID} .rt-tpg-category > a { |
| 2648 | background-color: {$catBg}; |
| 2649 | }"; |
| 2650 | |
| 2651 | $css .= "#{$layoutID} .cat-above-title.style3 .categories-links a:after, |
| 2652 | .cat-over-image.style3 .categories-links a:after, |
| 2653 | #{$layoutID} .rt-tpg-category > a, |
| 2654 | #{$layoutID} .rt-tpg-category.style3 > a:after { |
| 2655 | border-top-color: {$catBg} ; |
| 2656 | }"; |
| 2657 | |
| 2658 | $css .= "#{$layoutID} .rt-tpg-category:not(style1) i { |
| 2659 | color: {$catBg}; |
| 2660 | }"; |
| 2661 | } |
| 2662 | |
| 2663 | if ( $catTextColor ) { |
| 2664 | $css .= "#{$layoutID} .cat-over-image .categories-links a, |
| 2665 | #{$layoutID} .cat-above-title .categories-links a, |
| 2666 | #{$layoutID} .rt-tpg-category.style1 > i, |
| 2667 | #{$layoutID} .rt-tpg-category > a {"; |
| 2668 | $css .= 'color:' . $catTextColor . ';'; |
| 2669 | $css .= '}'; |
| 2670 | } |
| 2671 | |
| 2672 | if ( $catBorderRadius ) { |
| 2673 | $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{"; |
| 2674 | $css .= 'border-radius:' . $catBorderRadius . 'px;'; |
| 2675 | $css .= '}'; |
| 2676 | } |
| 2677 | |
| 2678 | if ( $catPadding ) { |
| 2679 | $css .= "#{$layoutID} .cat-over-image .categories-links a,#{$layoutID} .cat-above-title .categories-links a,#{$layoutID} .rt-tpg-category > a{"; |
| 2680 | $css .= 'padding:' . $catPadding . 'px;'; |
| 2681 | $css .= '}'; |
| 2682 | } |
| 2683 | |
| 2684 | if ( $catMargin ) { |
| 2685 | $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a{"; |
| 2686 | $css .= 'margin:' . $catMargin . 'px;'; |
| 2687 | $css .= '}'; |
| 2688 | } |
| 2689 | |
| 2690 | if ( $categorySize ) { |
| 2691 | $css .= "#{$layoutID} .categories-links,#{$layoutID} .rt-tpg-category > a {"; |
| 2692 | $css .= 'font-size:' . $categorySize . 'px;'; |
| 2693 | $css .= '}'; |
| 2694 | } |
| 2695 | |
| 2696 | $css .= '</style>'; |
| 2697 | |
| 2698 | return $css; |
| 2699 | } |
| 2700 | |
| 2701 | public static function get_meta_keys( $post_type ) { |
| 2702 | $meta_keys = self::generate_meta_keys( $post_type ); |
| 2703 | |
| 2704 | return $meta_keys; |
| 2705 | } |
| 2706 | |
| 2707 | public static function generate_meta_keys( $post_type ) { |
| 2708 | $meta_keys = []; |
| 2709 | |
| 2710 | if ( $post_type ) { |
| 2711 | global $wpdb; |
| 2712 | |
| 2713 | $query = "SELECT DISTINCT($wpdb->postmeta.meta_key) |
| 2714 | FROM $wpdb->posts |
| 2715 | LEFT JOIN $wpdb->postmeta |
| 2716 | ON $wpdb->posts.ID = $wpdb->postmeta.post_id |
| 2717 | WHERE $wpdb->posts.post_type = '%s' |
| 2718 | AND $wpdb->postmeta.meta_key != '' |
| 2719 | AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)' |
| 2720 | AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'"; |
| 2721 | $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) ); |
| 2722 | } |
| 2723 | |
| 2724 | return $meta_keys; |
| 2725 | } |
| 2726 | |
| 2727 | public static function remove_all_shortcode( $content ) { |
| 2728 | return preg_replace( '#\[[^\]]+\]#', '', $content ); |
| 2729 | } |
| 2730 | |
| 2731 | public static function remove_divi_shortcodes( $content ) { |
| 2732 | $content = preg_replace( '/\[\/?et_pb.*?\]/', '', $content ); |
| 2733 | |
| 2734 | return $content; |
| 2735 | } |
| 2736 | |
| 2737 | public static function is_acf() { |
| 2738 | $plugin = null; |
| 2739 | |
| 2740 | if ( class_exists( 'acf' ) ) { |
| 2741 | $plugin = 'acf'; |
| 2742 | } |
| 2743 | |
| 2744 | return $plugin; |
| 2745 | } |
| 2746 | |
| 2747 | public static function is_woocommerce() { |
| 2748 | $plugin = null; |
| 2749 | if ( class_exists( 'WooCommerce' ) ) { |
| 2750 | $plugin = 'woo'; |
| 2751 | } |
| 2752 | |
| 2753 | return $plugin; |
| 2754 | } |
| 2755 | |
| 2756 | public static function get_groups_by_post_type( $post_type ) { |
| 2757 | $post_type = $post_type ? $post_type : 'post'; |
| 2758 | $groups = []; |
| 2759 | $plugin = self::is_acf(); |
| 2760 | |
| 2761 | switch ( $plugin ) { |
| 2762 | case 'acf': |
| 2763 | $groups = self::get_groups_by_post_type_acf( $post_type ); |
| 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | return $groups; |
| 2768 | } |
| 2769 | |
| 2770 | /** |
| 2771 | * Get ACF post group |
| 2772 | * |
| 2773 | * @param $post_type |
| 2774 | * |
| 2775 | * @return array |
| 2776 | */ |
| 2777 | public static function get_groups_by_post_type_acf( $post_type ) { |
| 2778 | $groups = []; |
| 2779 | $groups_q = get_posts( |
| 2780 | [ |
| 2781 | 'post_type' => 'acf-field-group', |
| 2782 | 'posts_per_page' => - 1, |
| 2783 | ] |
| 2784 | ); |
| 2785 | |
| 2786 | if ( ! empty( $groups_q ) ) { |
| 2787 | foreach ( $groups_q as $group ) { |
| 2788 | $c = $group->post_content ? unserialize( $group->post_content ) : []; |
| 2789 | $flag = false; |
| 2790 | |
| 2791 | if ( ! empty( $c['location'] ) ) { |
| 2792 | foreach ( $c['location'] as $rules ) { |
| 2793 | foreach ( $rules as $rule ) { |
| 2794 | if ( 'all' === $post_type ) { |
| 2795 | if ( ( ! empty( $rule['param'] ) && $rule['param'] == 'post_type' ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' ) |
| 2796 | ) { |
| 2797 | $flag = true; |
| 2798 | } |
| 2799 | } else { |
| 2800 | if ( ( ! empty( $rule['param'] ) && ( $rule['param'] == 'post_type' || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' ) && ( ! empty( $rule['value'] ) && ( $rule['value'] == $post_type || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) ) |
| 2801 | |
| 2802 | ) { |
| 2803 | $flag = true; |
| 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | } |
| 2809 | if ( $flag ) { |
| 2810 | $groups[ $group->ID ] = $group->post_title; |
| 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | return $groups; |
| 2816 | } |
| 2817 | |
| 2818 | /** |
| 2819 | * Get Post view count meta key |
| 2820 | * |
| 2821 | * @return string |
| 2822 | */ |
| 2823 | public static function get_post_view_count_meta_key() { |
| 2824 | $count_key = 'tpg-post-view-count'; |
| 2825 | |
| 2826 | return apply_filters( 'tpg_post_view_count', $count_key ); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | /** |
| 2831 | * Elementor Functionality |
| 2832 | * ************************************************ |
| 2833 | */ |
| 2834 | |
| 2835 | |
| 2836 | /** |
| 2837 | * Default layout style check |
| 2838 | * |
| 2839 | * @param $data |
| 2840 | * |
| 2841 | * @return bool |
| 2842 | */ |
| 2843 | public static function el_ignore_layout( $data ) { |
| 2844 | |
| 2845 | if ( isset( $data['category'] ) && 'category' == $data['category'] ) { |
| 2846 | return true; |
| 2847 | } |
| 2848 | $all_layout_list = [ |
| 2849 | 'grid-layout4', |
| 2850 | 'grid-layout5', |
| 2851 | 'grid-layout5-2', |
| 2852 | 'grid-layout6', |
| 2853 | 'grid-layout6-2', |
| 2854 | 'list-layout4', |
| 2855 | 'list-layout5', |
| 2856 | 'grid_hover-layout5', |
| 2857 | 'grid_hover-layout6', |
| 2858 | 'grid_hover-layout7', |
| 2859 | 'grid_hover-layout8', |
| 2860 | 'grid_hover-layout9', |
| 2861 | 'grid_hover-layout10', |
| 2862 | 'grid_hover-layout5-2', |
| 2863 | 'grid_hover-layout6-2', |
| 2864 | 'grid_hover-layout7-2', |
| 2865 | 'grid_hover-layout9-2', |
| 2866 | 'grid_hover-layout11', |
| 2867 | 'slider-layout3', |
| 2868 | 'slider-layout5', |
| 2869 | 'slider-layout6', |
| 2870 | 'slider-layout7', |
| 2871 | 'slider-layout8', |
| 2872 | 'slider-layout9', |
| 2873 | 'slider-layout11', |
| 2874 | 'slider-layout12', |
| 2875 | ]; |
| 2876 | |
| 2877 | if ( 'default' == $data['category_position'] && in_array( $data['layout'], $all_layout_list ) ) { |
| 2878 | return false; |
| 2879 | } |
| 2880 | |
| 2881 | return true; |
| 2882 | } |
| 2883 | |
| 2884 | /** |
| 2885 | * Get Post Link |
| 2886 | * |
| 2887 | * @param $data |
| 2888 | * @param $pID |
| 2889 | * |
| 2890 | * @return array |
| 2891 | */ |
| 2892 | public static function get_post_link( $pID, $data ) { |
| 2893 | $link_class = $link_start = $link_end = $readmore_link_start = $readmore_link_end = null; |
| 2894 | |
| 2895 | if ( 'default' == $data['post_link_type'] ) { |
| 2896 | $link_class = 'tpg-post-link'; |
| 2897 | $link_start = $readmore_link_start = sprintf( |
| 2898 | '<a data-id="%s" href="%s" class="%s" target="%s">', |
| 2899 | absint( $pID ), |
| 2900 | esc_url( get_permalink() ), |
| 2901 | esc_attr( $link_class ), |
| 2902 | esc_attr( $data['link_target'] ) |
| 2903 | ); |
| 2904 | $link_end = $readmore_link_end = '</a>'; |
| 2905 | } else if ( 'popup' == $data['post_link_type'] ) { |
| 2906 | $link_class = 'tpg-single-popup tpg-post-link'; |
| 2907 | |
| 2908 | if ( did_action( 'elementor/loaded' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 2909 | $link_class = 'tpg-post-link'; |
| 2910 | } |
| 2911 | |
| 2912 | $link_start = $readmore_link_start = sprintf( |
| 2913 | '<a data-id="%s" href="%s" class="%s" target="%s">', |
| 2914 | absint( $pID ), |
| 2915 | esc_url( get_permalink() ), |
| 2916 | esc_attr( $link_class ), |
| 2917 | esc_attr( $data['link_target'] ) |
| 2918 | ); |
| 2919 | $link_end = $readmore_link_end = '</a>'; |
| 2920 | } else if ( 'multi_popup' == $data['post_link_type'] ) { |
| 2921 | $link_class = 'tpg-multi-popup tpg-post-link'; |
| 2922 | $link_start = $readmore_link_start = sprintf( |
| 2923 | '<a data-id="%s" href="%s" class="%s" target="%s">', |
| 2924 | absint( $pID ), |
| 2925 | esc_url( get_permalink() ), |
| 2926 | esc_attr( $link_class ), |
| 2927 | esc_attr( $data['link_target'] ) |
| 2928 | ); |
| 2929 | $link_end = $readmore_link_end = '</a>'; |
| 2930 | } else { |
| 2931 | $link_class = 'tpg-post-link'; |
| 2932 | $readmore_link_start = sprintf( |
| 2933 | '<a data-id="%s" href="%s" class="%s" target="%s">', |
| 2934 | absint( $pID ), |
| 2935 | esc_url( get_permalink() ), |
| 2936 | esc_attr( $link_class ), |
| 2937 | esc_attr( $data['link_target'] ) |
| 2938 | ); |
| 2939 | $readmore_link_end = '</a>'; |
| 2940 | } |
| 2941 | |
| 2942 | return [ |
| 2943 | 'link_start' => $link_start, |
| 2944 | 'link_end' => $link_end, |
| 2945 | 'readmore_link_start' => $readmore_link_start, |
| 2946 | 'readmore_link_end' => $readmore_link_end, |
| 2947 | ]; |
| 2948 | } |
| 2949 | |
| 2950 | /** |
| 2951 | * Get Post Type |
| 2952 | * |
| 2953 | * @return string[]|\WP_Post_Type[] |
| 2954 | */ |
| 2955 | public static function get_post_types() { |
| 2956 | $post_types = get_post_types( |
| 2957 | [ |
| 2958 | 'public' => true, |
| 2959 | 'show_in_nav_menus' => true, |
| 2960 | ], |
| 2961 | 'objects' |
| 2962 | ); |
| 2963 | $post_types = wp_list_pluck( $post_types, 'label', 'name' ); |
| 2964 | |
| 2965 | $exclude = [ 'attachment', 'revision', 'nav_menu_item', 'elementor_library', 'tpg_builder', 'e-landing-page' ]; |
| 2966 | |
| 2967 | foreach ( $exclude as $ex ) { |
| 2968 | unset( $post_types[ $ex ] ); |
| 2969 | } |
| 2970 | |
| 2971 | if ( ! rtTPG()->hasPro() ) { |
| 2972 | $post_types = [ |
| 2973 | 'post' => $post_types['post'], |
| 2974 | 'page' => $post_types['page'], |
| 2975 | ]; |
| 2976 | } |
| 2977 | |
| 2978 | return $post_types; |
| 2979 | } |
| 2980 | |
| 2981 | public static function rt_get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
| 2982 | $terms = get_the_terms( $post_id, $taxonomy ); |
| 2983 | |
| 2984 | if ( is_wp_error( $terms ) ) { |
| 2985 | return $terms; |
| 2986 | } |
| 2987 | |
| 2988 | if ( empty( $terms ) ) { |
| 2989 | return false; |
| 2990 | } |
| 2991 | |
| 2992 | $links = []; |
| 2993 | |
| 2994 | foreach ( $terms as $term ) { |
| 2995 | $meta_color = get_term_meta( $term->term_id, 'rttpg_category_color', true ); |
| 2996 | $meta_color_code = $meta_color ? "--tpg-primary-color:#" . ltrim( $meta_color, '#' ) : ''; |
| 2997 | |
| 2998 | $link = get_term_link( $term, $taxonomy ); |
| 2999 | if ( is_wp_error( $link ) ) { |
| 3000 | return $link; |
| 3001 | } |
| 3002 | if ( rtTPG()->hasPro() ) { |
| 3003 | $links[] = '<a class="' . $term->slug . '" style="' . esc_attr( $meta_color_code ) . '" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
| 3004 | } else { |
| 3005 | $links[] = '<a class="' . $term->slug . '" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | return $before . implode( $sep, $links ) . $after; |
| 3010 | } |
| 3011 | |
| 3012 | /** |
| 3013 | * Get Post Meta HTML for Elementor |
| 3014 | * |
| 3015 | * @param $post_id |
| 3016 | * @param $data |
| 3017 | * |
| 3018 | * @return html markup |
| 3019 | */ |
| 3020 | public static function get_post_meta_html( $post_id, $data ) { |
| 3021 | global $post; |
| 3022 | |
| 3023 | $author_id = $post->post_author; |
| 3024 | $author_name = get_the_author_meta( 'display_name', $post->post_author ); |
| 3025 | $author = apply_filters( 'rttpg_author_link', sprintf( '<a href="%s">%s</a>', get_author_posts_url( $author_id ), $author_name ) ); |
| 3026 | |
| 3027 | $comments_number = get_comments_number( $post_id ); |
| 3028 | $comment_label = ''; |
| 3029 | |
| 3030 | if ( isset( $data['show_comment_count_label'] ) && $data['show_comment_count_label'] ) { |
| 3031 | $comment_label = $data['comment_count_label_singular']; |
| 3032 | |
| 3033 | if ( $comments_number > 1 ) { |
| 3034 | $comment_label = $data['comment_count_label_plural']; |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | $comments_text = sprintf( '%s (%s)', esc_html( $comment_label ), number_format_i18n( $comments_number ) ); |
| 3039 | $date = get_the_date(); |
| 3040 | |
| 3041 | |
| 3042 | //Category and Tags Management |
| 3043 | $_cat_id = isset( $data['post_type'] ) ? $data['post_type'] . '_taxonomy' : 'category'; |
| 3044 | $_tag_id = isset( $data['post_type'] ) ? $data['post_type'] . '_tags' : 'post_tag'; |
| 3045 | $_category_id = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category'; |
| 3046 | $_tag_id = isset( $data[ $_tag_id ] ) ? $data[ $_tag_id ] : 'post_tag'; |
| 3047 | $categories = self::rt_get_the_term_list( $post_id, $_category_id, null, '<span class="rt-separator">,</span>' ); |
| 3048 | $tags = self::rt_get_the_term_list( $post_id, $_tag_id, null, '<span class="rt-separator">,</span>' ); |
| 3049 | |
| 3050 | $count_key = self::get_post_view_count_meta_key(); |
| 3051 | $get_view_count = get_post_meta( $post_id, $count_key, true ); |
| 3052 | |
| 3053 | $meta_separator = ( $data['meta_separator'] && 'default' !== $data['meta_separator'] ) ? sprintf( "<span class='separator'>%s</span>", $data['meta_separator'] ) : null; |
| 3054 | |
| 3055 | // Author Meta. |
| 3056 | |
| 3057 | $post_meta_html = []; |
| 3058 | ob_start(); |
| 3059 | if ( 'show' === $data['show_author'] ) { |
| 3060 | $is_author_avatar = null; |
| 3061 | |
| 3062 | if ( 'icon' !== $data['show_author_image'] ) { |
| 3063 | $is_author_avatar = 'has-author-avatar'; |
| 3064 | } |
| 3065 | ?> |
| 3066 | <span class='author <?php echo esc_attr( $is_author_avatar ); ?>'> |
| 3067 | |
| 3068 | <?php |
| 3069 | |
| 3070 | if ( isset( $data['author_icon_visibility'] ) && $data['author_icon_visibility'] !== 'hide' ) { |
| 3071 | if ( 'icon' !== $data['show_author_image'] ) { |
| 3072 | echo get_avatar( $author_id, 80 ); |
| 3073 | } else { |
| 3074 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3075 | if ( did_action( 'elementor/loaded' ) && isset( $data['user_icon']['value'] ) && $data['user_icon']['value'] ) { |
| 3076 | \Elementor\Icons_Manager::render_icon( $data['user_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3077 | } else { |
| 3078 | echo "<i class='" . Fns::change_icon( 'fa fa-user', 'flaticon-user' ) . "'></i>"; |
| 3079 | } |
| 3080 | } |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | if ( $data['author_prefix'] ) { |
| 3085 | echo "<span class='author-prefix'>" . esc_html( $data['author_prefix'] ) . '</span>'; |
| 3086 | } |
| 3087 | echo wp_kses( $author, self::allowedHtml() ); |
| 3088 | ?> |
| 3089 | </span> |
| 3090 | <?php |
| 3091 | echo wp_kses( $meta_separator, self::allowedHtml() ); |
| 3092 | } |
| 3093 | |
| 3094 | $post_meta_html['author'] = ob_get_clean(); |
| 3095 | |
| 3096 | ob_start(); |
| 3097 | // Category Meta. |
| 3098 | |
| 3099 | $category_condition = ( $categories && 'show' == $data['show_category'] && self::el_ignore_layout( $data ) && in_array( $data['category_position'], [ 'default', 'with_meta' ] ) ); |
| 3100 | |
| 3101 | if ( ! rtTPG()->hasPro() ) { |
| 3102 | $category_condition = ( $categories && 'show' == $data['show_category'] ); |
| 3103 | } |
| 3104 | |
| 3105 | if ( $category_condition ) { |
| 3106 | ?> |
| 3107 | <span class='categories-links'> |
| 3108 | <?php |
| 3109 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3110 | if ( did_action( 'elementor/loaded' ) && isset( $data['cat_icon']['value'] ) && $data['cat_icon']['value'] ) { |
| 3111 | \Elementor\Icons_Manager::render_icon( $data['cat_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3112 | } else { |
| 3113 | echo "<i class='" . Fns::change_icon( 'fas fa-folder-open', 'flaticon-folder' ) . "'></i>"; |
| 3114 | } |
| 3115 | } |
| 3116 | echo wp_kses( $categories, self::allowedHtml( 'basic' ) ); |
| 3117 | ?> |
| 3118 | |
| 3119 | </span> |
| 3120 | <?php |
| 3121 | echo wp_kses( $meta_separator, self::allowedHtml( 'basic' ) ); |
| 3122 | } |
| 3123 | $post_meta_html['category'] = ob_get_clean(); |
| 3124 | |
| 3125 | ob_start(); |
| 3126 | // Date Meta. |
| 3127 | if ( '' !== $data['show_date'] ) { |
| 3128 | $archive_year = get_the_date( 'Y' ); |
| 3129 | $archive_month = get_the_date( 'm' ); |
| 3130 | $archive_day = get_the_date( 'j' ); |
| 3131 | |
| 3132 | ?> |
| 3133 | <span class='date'> |
| 3134 | |
| 3135 | <?php |
| 3136 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3137 | if ( did_action( 'elementor/loaded' ) && isset( $data['date_icon']['value'] ) && $data['date_icon']['value'] ) { |
| 3138 | \Elementor\Icons_Manager::render_icon( $data['date_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3139 | } else { |
| 3140 | echo "<i class='" . Fns::change_icon( 'far fa-calendar-alt', 'flaticon-calendar' ) . "'></i>"; |
| 3141 | } |
| 3142 | } |
| 3143 | ?> |
| 3144 | <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>"> |
| 3145 | <?php echo esc_html( $date ); ?> |
| 3146 | </a> |
| 3147 | </span> |
| 3148 | <?php |
| 3149 | echo wp_kses( $meta_separator, self::allowedHtml() ); |
| 3150 | } |
| 3151 | |
| 3152 | $post_meta_html['date'] = ob_get_clean(); |
| 3153 | |
| 3154 | ob_start(); |
| 3155 | // Tags Meta. |
| 3156 | if ( $tags && 'show' == $data['show_tags'] ) { |
| 3157 | ?> |
| 3158 | <span class='post-tags-links'> |
| 3159 | <?php |
| 3160 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3161 | if ( did_action( 'elementor/loaded' ) && isset( $data['tag_icon']['value'] ) && $data['tag_icon']['value'] ) { |
| 3162 | \Elementor\Icons_Manager::render_icon( $data['tag_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3163 | } else { |
| 3164 | echo "<i class='" . Fns::change_icon( 'fa fa-tags', 'flaticon-tag' ) . "'></i>"; |
| 3165 | } |
| 3166 | } |
| 3167 | echo wp_kses( $tags, self::allowedHtml() ); |
| 3168 | ?> |
| 3169 | </span> |
| 3170 | <?php |
| 3171 | echo wp_kses( $meta_separator, self::allowedHtml() ); |
| 3172 | } |
| 3173 | $post_meta_html['tags'] = ob_get_clean(); |
| 3174 | |
| 3175 | ob_start(); |
| 3176 | // Comment Meta. |
| 3177 | if ( 'show' == $data['show_comment_count'] ) { |
| 3178 | ?> |
| 3179 | <span class="comment-count"> |
| 3180 | <?php |
| 3181 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3182 | if ( did_action( 'elementor/loaded' ) && isset( $data['comment_icon']['value'] ) && $data['comment_icon']['value'] ) { |
| 3183 | \Elementor\Icons_Manager::render_icon( $data['comment_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3184 | } else { |
| 3185 | echo "<i class='" . Fns::change_icon( 'fas fa-comments', 'flaticon-chat' ) . "'></i>"; |
| 3186 | } |
| 3187 | } |
| 3188 | echo wp_kses( $comments_text, self::allowedHtml() ); |
| 3189 | ?> |
| 3190 | </span> |
| 3191 | <?php |
| 3192 | echo wp_kses( $meta_separator, self::allowedHtml() ); |
| 3193 | } |
| 3194 | |
| 3195 | $post_meta_html['comment_count'] = ob_get_clean(); |
| 3196 | |
| 3197 | ob_start(); |
| 3198 | // Post Count. |
| 3199 | if ( rtTPG()->hasPro() && 'show' == $data['show_post_count'] && ! empty( $get_view_count ) ) { |
| 3200 | ?> |
| 3201 | <span class="post-count"> |
| 3202 | <?php |
| 3203 | if ( $data['show_meta_icon'] === 'yes' ) { |
| 3204 | if ( did_action( 'elementor/loaded' ) && isset( $data['post_count_icon']['value'] ) && $data['post_count_icon']['value'] ) { |
| 3205 | \Elementor\Icons_Manager::render_icon( $data['post_count_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3206 | } else { |
| 3207 | echo "<i class='" . Fns::change_icon( 'fa fa-eye', 'flaticon-view' ) . "'></i>"; |
| 3208 | } |
| 3209 | } |
| 3210 | echo wp_kses( $get_view_count, self::allowedHtml() ); |
| 3211 | ?> |
| 3212 | </span> |
| 3213 | <?php |
| 3214 | echo wp_kses( $meta_separator, self::allowedHtml() ); |
| 3215 | } |
| 3216 | |
| 3217 | $post_meta_html['post_count'] = ob_get_clean(); |
| 3218 | |
| 3219 | if ( isset( $data['is_gutenberg'] ) && $data['is_gutenberg'] ) { |
| 3220 | $meta_ordering = array_keys( $post_meta_html ); |
| 3221 | |
| 3222 | if ( isset( $data['meta_ordering'] ) && is_array( $data['meta_ordering'] ) ) { |
| 3223 | $meta_ordering = wp_list_pluck( $data['meta_ordering'], 'value' ); |
| 3224 | $extra_meta = []; |
| 3225 | $post_meta_html_key = array_keys( $post_meta_html ); |
| 3226 | |
| 3227 | $count_order = count( $meta_ordering ); |
| 3228 | |
| 3229 | if ( $count_order != count( $post_meta_html_key ) ) { |
| 3230 | foreach ( $post_meta_html_key as $key ) { |
| 3231 | if ( ! in_array( $key, $meta_ordering ) ) { |
| 3232 | $extra_meta[] = $key; |
| 3233 | } |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | if ( ! empty( $extra_meta ) ) { |
| 3238 | $meta_ordering = array_merge( $meta_ordering, $extra_meta ); |
| 3239 | } |
| 3240 | } |
| 3241 | foreach ( $meta_ordering as $val ) { |
| 3242 | echo $post_meta_html[ $val ]; |
| 3243 | } |
| 3244 | |
| 3245 | } else { |
| 3246 | $meta_ordering = isset( $data['meta_ordering'] ) && is_array( $data['meta_ordering'] ) ? $data['meta_ordering'] : []; |
| 3247 | foreach ( $meta_ordering as $val ) { |
| 3248 | if ( isset( $post_meta_html[ $val['meta_name'] ] ) ) { |
| 3249 | echo wp_kses_post( $post_meta_html[ $val['meta_name'] ] ); |
| 3250 | } |
| 3251 | |
| 3252 | } |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | /** |
| 3257 | * Custom wp_kses |
| 3258 | * |
| 3259 | * @param $string |
| 3260 | * |
| 3261 | * @return string |
| 3262 | */ |
| 3263 | public static function wp_kses( $string ) { |
| 3264 | $allowed_html = [ |
| 3265 | 'a' => [ |
| 3266 | 'href' => [], |
| 3267 | 'title' => [], |
| 3268 | 'data-id' => [], |
| 3269 | 'target' => [], |
| 3270 | 'class' => [], |
| 3271 | ], |
| 3272 | 'strong' => [], |
| 3273 | 'b' => [], |
| 3274 | 'br' => [ [] ], |
| 3275 | ]; |
| 3276 | |
| 3277 | return wp_kses( $string, $allowed_html ); |
| 3278 | } |
| 3279 | |
| 3280 | |
| 3281 | /** |
| 3282 | * Get Elementor Post Title for Elementor |
| 3283 | * |
| 3284 | * @param $title_tag |
| 3285 | * @param $title |
| 3286 | * @param $link_start |
| 3287 | * @param $link_end |
| 3288 | * @param $data |
| 3289 | */ |
| 3290 | |
| 3291 | public static function get_el_post_title( $title_tag, $title, $link_start, $link_end, $data ) { |
| 3292 | echo '<div class="entry-title-wrapper">'; |
| 3293 | |
| 3294 | if ( rtTPG()->hasPro() && 'above_title' === $data['category_position'] || ! self::el_ignore_layout( $data ) ) { |
| 3295 | self::get_el_thumb_cat( $data, 'cat-above-title' ); |
| 3296 | } |
| 3297 | |
| 3298 | printf( '<%s class="entry-title">', esc_attr( $title_tag ) ); |
| 3299 | self::print_html( $link_start ); |
| 3300 | self::print_html( $title ); |
| 3301 | self::print_html( $link_end ); |
| 3302 | printf( '</%s>', esc_attr( $title_tag ) ); |
| 3303 | echo '</div>'; |
| 3304 | } |
| 3305 | |
| 3306 | static function get_el_thumb_cat( $data, $class = 'cat-over-image' ) { |
| 3307 | if ( ! ( 'show' == $data['show_meta'] && 'show' == $data['show_category'] ) ) { |
| 3308 | return; |
| 3309 | } |
| 3310 | |
| 3311 | $pID = get_the_ID(); |
| 3312 | $_cat_id = $data['post_type'] . '_taxonomy'; |
| 3313 | $_post_taxonomy = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category'; |
| 3314 | $categories = self::rt_get_the_term_list( $pID, $_post_taxonomy, null, '<span class="rt-separator">,</span>' ); |
| 3315 | $category_position = $data['category_position']; |
| 3316 | |
| 3317 | if ( in_array( $data['layout'], [ 'grid-layout4', 'slider-layout3', 'grid_hover-layout11' ] ) && 'default' === $data['category_position'] ) { |
| 3318 | $category_position = 'top_left'; |
| 3319 | } |
| 3320 | ?> |
| 3321 | <div class="tpg-separate-category <?php echo esc_attr( $data['category_style'] . ' ' . $category_position . ' ' . $class ); ?>"> |
| 3322 | <span class='categories-links'> |
| 3323 | <?php echo ( 'yes' === $data['show_cat_icon'] ) ? "<i class='".Fns::change_icon( 'fas fa-folder-open', 'flaticon-folder' )."'></i>" : null; ?> |
| 3324 | <?php echo wp_kses( $categories, self::allowedHtml() ); ?> |
| 3325 | </span> |
| 3326 | </div> |
| 3327 | <?php |
| 3328 | } |
| 3329 | |
| 3330 | |
| 3331 | /** |
| 3332 | * Get first image from the content |
| 3333 | * |
| 3334 | * @param $post_id |
| 3335 | * @param string $type |
| 3336 | * |
| 3337 | * @return mixed|string |
| 3338 | */ |
| 3339 | public static function get_content_first_image( $post_id, $type = 'markup', $imgClass = '' ) { |
| 3340 | if ( $img = preg_match_all( |
| 3341 | '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', |
| 3342 | get_the_content( $post_id ), |
| 3343 | $matches |
| 3344 | ) |
| 3345 | ) { |
| 3346 | $imgSrc = $matches[1][0]; |
| 3347 | $size = ''; |
| 3348 | |
| 3349 | $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc ); |
| 3350 | |
| 3351 | if ( file_exists( $imgAbs ) ) { |
| 3352 | $info = getimagesize( $imgAbs ); |
| 3353 | $size = isset( $info[3] ) ? $info[3] : ''; |
| 3354 | } |
| 3355 | |
| 3356 | $attachment_id = attachment_url_to_postid( $imgSrc ); |
| 3357 | $alt_text = null; |
| 3358 | |
| 3359 | if ( ! empty( $attachment_id ) ) { |
| 3360 | $alt_text = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); |
| 3361 | } |
| 3362 | |
| 3363 | $alt = $alt_text ? $alt_text : get_the_title( $post_id ); |
| 3364 | |
| 3365 | if ( $type == 'markup' ) { |
| 3366 | if ( $imgClass !== 'swiper-lazy' ) { |
| 3367 | return "<img class='rt-img-responsive' src='{$imgSrc}' {$size} alt='{$alt}'>"; |
| 3368 | } else { |
| 3369 | return "<img class='{$imgClass}' data-src='{$imgSrc}' alt='{$alt}'>"; |
| 3370 | } |
| 3371 | } else { |
| 3372 | return $imgSrc; |
| 3373 | } |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | /** |
| 3378 | * Get post thumbnail html |
| 3379 | * |
| 3380 | * @param $pID |
| 3381 | * @param $data |
| 3382 | * @param $link_start |
| 3383 | * @param $link_end |
| 3384 | * @param false $offset_size |
| 3385 | */ |
| 3386 | public static function get_post_thumbnail( $pID, $data, $link_start, $link_end, $offset_size = false ) { |
| 3387 | $thumb_cat_condition = ( ! ( 'above_title' === $data['category_position'] || 'default' === $data['category_position'] ) ); |
| 3388 | |
| 3389 | if ( 'grid-layout4' === $data['layout'] && 'default' === $data['category_position'] ) { |
| 3390 | $thumb_cat_condition = true; |
| 3391 | } else if ( in_array( $data['layout'], [ 'grid-layout4', 'grid_hover-layout11', 'slider-layout3' ] ) && 'default' === $data['category_position'] ) { |
| 3392 | $thumb_cat_condition = true; |
| 3393 | } |
| 3394 | |
| 3395 | if ( rtTPG()->hasPro() && $data['show_category'] == 'show' && $thumb_cat_condition && 'with_meta' !== $data['category_position'] ) { |
| 3396 | self::get_el_thumb_cat( $data ); |
| 3397 | } |
| 3398 | |
| 3399 | $img_link = get_the_post_thumbnail_url( $pID, 'full' ); |
| 3400 | $img_size_key = 'image_size'; |
| 3401 | |
| 3402 | |
| 3403 | if ( $offset_size ) { |
| 3404 | $img_size_key = 'image_offset_size'; |
| 3405 | } |
| 3406 | |
| 3407 | $lazy_load = ( $data['prefix'] == 'slider' && $data['lazy_load'] == 'yes' ) ? true : false; |
| 3408 | $lazy_class = 'rt-img-responsive'; |
| 3409 | |
| 3410 | if ( $lazy_load ) { |
| 3411 | $lazy_class = 'swiper-lazy'; |
| 3412 | } |
| 3413 | |
| 3414 | echo 'yes' === $data['is_thumb_linked'] ? self::print_html( $link_start ) : null; |
| 3415 | |
| 3416 | if ( has_post_thumbnail() && 'feature_image' === $data['media_source'] ) { |
| 3417 | $fImgSize = $data['image_size']; |
| 3418 | |
| 3419 | if ( $offset_size ) { |
| 3420 | echo get_the_post_thumbnail( $pID, $data['image_offset'] ); |
| 3421 | } else { |
| 3422 | if ( $data['image_size'] !== 'custom' ) { |
| 3423 | $attachment_id = get_post_thumbnail_id( $pID ); |
| 3424 | $thumb_info = wp_get_attachment_image_src( $attachment_id, $fImgSize ); |
| 3425 | $thumb_alt = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); |
| 3426 | if ( $lazy_load ) { |
| 3427 | ?> |
| 3428 | <img data-src="<?php echo esc_url( isset( $thumb_info[0] ) ? $thumb_info[0] : '' ); ?>" |
| 3429 | src="#none" |
| 3430 | class="<?php echo esc_attr( $lazy_class ); ?>" |
| 3431 | width="<?php echo esc_attr( isset( $thumb_info[1] ) ? $thumb_info[1] : '' ); ?>" |
| 3432 | height="<?php echo esc_attr( isset( $thumb_info[2] ) ? $thumb_info[2] : '' ); ?>" |
| 3433 | alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?>"> |
| 3434 | <?php |
| 3435 | } else { |
| 3436 | ?> |
| 3437 | <img src="<?php echo esc_url( isset( $thumb_info[0] ) ? $thumb_info[0] : '' ); ?>" |
| 3438 | class="<?php echo esc_attr( $lazy_class ); ?>" |
| 3439 | width="<?php echo esc_attr( isset( $thumb_info[1] ) ? $thumb_info[1] : '' ); ?>" |
| 3440 | height="<?php echo esc_attr( isset( $thumb_info[2] ) ? $thumb_info[2] : '' ); ?>" |
| 3441 | alt="<?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?>"> |
| 3442 | <?php |
| 3443 | } |
| 3444 | ?> |
| 3445 | |
| 3446 | <?php |
| 3447 | } else { |
| 3448 | $fImgSize = 'rt_custom'; |
| 3449 | $mediaSource = 'feature_image'; |
| 3450 | $defaultImgId = null; |
| 3451 | $customImgSize = []; |
| 3452 | |
| 3453 | |
| 3454 | if ( $data['is_gutenberg'] && isset( $data['c_image_width'] ) && isset( $data['c_image_height'] ) ) { |
| 3455 | $data['image_custom_dimension']['width'] = intval( $data['c_image_width'] ); |
| 3456 | $data['image_custom_dimension']['height'] = intval( $data['c_image_height'] ); |
| 3457 | } |
| 3458 | |
| 3459 | |
| 3460 | if ( isset( $data['image_custom_dimension'] ) ) { |
| 3461 | $post_thumb_id = get_post_thumbnail_id( $pID ); |
| 3462 | $default_image_dimension = wp_get_attachment_image_src( $post_thumb_id, 'full' ); |
| 3463 | |
| 3464 | if ( $default_image_dimension[1] <= $data['image_custom_dimension']['width'] || $default_image_dimension[2] <= $data['image_custom_dimension']['height'] ) { |
| 3465 | $customImgSize = []; |
| 3466 | } else { |
| 3467 | $customImgSize[0] = $data['image_custom_dimension']['width']; |
| 3468 | $customImgSize[1] = $data['image_custom_dimension']['height']; |
| 3469 | $customImgSize[2] = $data['img_crop_style']; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | echo wp_kses_post( self::getFeatureImageSrc( $pID, $fImgSize, $mediaSource, $defaultImgId, $customImgSize, $lazy_class ) ); |
| 3474 | } |
| 3475 | } |
| 3476 | } else if ( 'first_image' === $data['media_source'] && self::get_content_first_image( $pID ) ) { |
| 3477 | echo wp_kses_post( self::get_content_first_image( $pID, 'markup', $lazy_class ) ); |
| 3478 | $img_link = self::get_content_first_image( $pID, 'url' ); |
| 3479 | } else if ( 'yes' === $data['is_default_img'] || 'grid_hover' == $data['prefix'] ) { |
| 3480 | //echo \Elementor\Group_Control_Image_Size::get_attachment_image_html( $data, $img_size_key, 'default_image' ); |
| 3481 | if ( isset( $data['default_image']['id'] ) ) { |
| 3482 | echo wp_get_attachment_image( $data['default_image']['id'], $data[ $img_size_key ], '', [ 'class' => 'rt-img-responsive' ] ); |
| 3483 | } |
| 3484 | if ( ! empty( $data['default_image'] ) && isset( $data['default_image']['url'] ) ) { |
| 3485 | $img_link = $data['default_image']['url']; |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | ?> |
| 3490 | <?php if ( $lazy_load ) : ?> |
| 3491 | <div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div> |
| 3492 | <?php endif; ?> |
| 3493 | |
| 3494 | <?php echo 'yes' === $data['is_thumb_linked'] ? wp_kses( $link_end, self::allowedHtml() ) : null; ?> |
| 3495 | |
| 3496 | <?php |
| 3497 | if ( 'show' === $data['is_thumb_lightbox'] || ( in_array( $data['layout'], [ 'grid-layout7', 'slider-layout4' ] ) && in_array( $data['is_thumb_lightbox'], [ 'default', 'show' ] ) ) ) : |
| 3498 | ?> |
| 3499 | |
| 3500 | <a class="tpg-zoom mfp-fade" |
| 3501 | data-elementor-open-lightbox="yes" |
| 3502 | data-elementor-lightbox-slideshow="<?php echo esc_attr( $data['layout'] ); ?>" |
| 3503 | title="<?php echo esc_attr( get_the_title() ); ?>" |
| 3504 | href="<?php echo esc_url( $img_link ) ?>"> |
| 3505 | |
| 3506 | <?php |
| 3507 | if ( did_action( 'elementor/loaded' ) && isset( $data['light_box_icon']['value'] ) && $data['light_box_icon']['value'] ) { |
| 3508 | \Elementor\Icons_Manager::render_icon( $data['light_box_icon'], [ 'aria-hidden' => 'true' ] ); |
| 3509 | } else { |
| 3510 | echo "<i class='fa fa-plus'></i>"; |
| 3511 | } |
| 3512 | ?> |
| 3513 | </a> |
| 3514 | |
| 3515 | <?php endif; ?> |
| 3516 | <div class="overlay grid-hover-content"></div> |
| 3517 | <?php |
| 3518 | } |
| 3519 | |
| 3520 | |
| 3521 | /** |
| 3522 | * Get ACF data for elementor |
| 3523 | * |
| 3524 | * @param $data |
| 3525 | * @param $pID |
| 3526 | * |
| 3527 | * @return bool |
| 3528 | */ |
| 3529 | public static function tpg_get_acf_data_elementor( $data, $pID, $return_type = true ) { |
| 3530 | if ( ! ( rtTPG()->hasPro() && self::is_acf() ) ) { |
| 3531 | return; |
| 3532 | } |
| 3533 | |
| 3534 | if ( isset( $data['show_acf'] ) && 'show' == $data['show_acf'] ) { |
| 3535 | $cf_group = $data['cf_group']; |
| 3536 | |
| 3537 | |
| 3538 | $format = [ |
| 3539 | 'hide_empty' => ( isset( $data['cf_hide_empty_value'] ) && $data['cf_hide_empty_value'] ) ? 'yes' : '', |
| 3540 | 'show_value' => ( isset( $data['cf_show_only_value'] ) && $data['cf_show_only_value'] ) ? '' : 'yes', |
| 3541 | 'hide_group_title' => ( isset( $data['cf_hide_group_title'] ) && $data['cf_hide_group_title'] ) ? '' : 'yes', |
| 3542 | ]; |
| 3543 | |
| 3544 | if ( ! empty( $cf_group ) ) { |
| 3545 | |
| 3546 | $acf_html = "<div class='acf-custom-field-wrap'>"; |
| 3547 | |
| 3548 | $acf_html .= \RT\ThePostGridPro\Helpers\Functions::get_cf_formatted_fields( $cf_group, $format, $pID ); |
| 3549 | $acf_html .= '</div>'; |
| 3550 | |
| 3551 | if ( $return_type ) { |
| 3552 | self::print_html( $acf_html, true ); |
| 3553 | } else { |
| 3554 | return $acf_html; |
| 3555 | } |
| 3556 | } |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | /** |
| 3561 | * Get Read More Button |
| 3562 | * |
| 3563 | * @param $data |
| 3564 | * @param $readmore_link_start |
| 3565 | * @param $readmore_link_end |
| 3566 | * |
| 3567 | * @return void |
| 3568 | */ |
| 3569 | public static function get_read_more_button( $data, $readmore_link_start, $readmore_link_end, $type = 'elementor' ) { ?> |
| 3570 | <div class="post-footer"> |
| 3571 | <div class="read-more"> |
| 3572 | <?php |
| 3573 | echo self::wp_kses( $readmore_link_start ); |
| 3574 | if ( 'yes' == $data['show_btn_icon'] && 'left' == $data['readmore_icon_position'] ) { |
| 3575 | if ( $type === 'elementor' ) { |
| 3576 | if ( did_action( 'elementor/loaded' ) ) { |
| 3577 | \Elementor\Icons_Manager::render_icon( $data['readmore_btn_icon'], [ |
| 3578 | 'aria-hidden' => 'true', |
| 3579 | 'class' => 'left-icon' |
| 3580 | ] ); |
| 3581 | } |
| 3582 | } else { |
| 3583 | //TODO: FlatIcon should chagne |
| 3584 | echo "<i class='left-icon " . Fns::change_icon( 'fas fa-angle-right', 'fas fa-angle-right' ) . "'></i>"; |
| 3585 | } |
| 3586 | } |
| 3587 | echo esc_html( $data['read_more_label'] ); |
| 3588 | if ( 'yes' == $data['show_btn_icon'] && 'right' == $data['readmore_icon_position'] ) { |
| 3589 | if ( $type === 'elementor' ) { |
| 3590 | if ( did_action( 'elementor/loaded' ) ) { |
| 3591 | \Elementor\Icons_Manager::render_icon( $data['readmore_btn_icon'], [ |
| 3592 | 'aria-hidden' => 'true', |
| 3593 | 'class' => 'right-icon' |
| 3594 | ] ); |
| 3595 | } |
| 3596 | } else { |
| 3597 | //TODO: FlatIcon should chagne |
| 3598 | echo "<i class='left-icon " . Fns::change_icon( 'fas fa-angle-right', 'fas fa-angle-right' ) . "'></i>"; |
| 3599 | } |
| 3600 | } |
| 3601 | echo self::wp_kses( $readmore_link_end ); |
| 3602 | ?> |
| 3603 | </div> |
| 3604 | </div> |
| 3605 | <?php |
| 3606 | } |
| 3607 | |
| 3608 | |
| 3609 | /** |
| 3610 | * Check is filter enable or not |
| 3611 | * |
| 3612 | * @param $data |
| 3613 | * |
| 3614 | * @return bool |
| 3615 | */ |
| 3616 | public static function is_filter_enable( $data ) { |
| 3617 | if ( rtTPG()->hasPro() |
| 3618 | && ( $data['show_taxonomy_filter'] == 'show' |
| 3619 | || $data['show_author_filter'] == 'show' |
| 3620 | || $data['show_order_by'] == 'show' |
| 3621 | || $data['show_sort_order'] == 'show' |
| 3622 | || $data['show_search'] == 'show' |
| 3623 | || ( $data['show_pagination'] == 'show' && $data['pagination_type'] != 'pagination' ) ) |
| 3624 | ) { |
| 3625 | return true; |
| 3626 | } |
| 3627 | |
| 3628 | return false; |
| 3629 | } |
| 3630 | |
| 3631 | |
| 3632 | //Get Custom post category: |
| 3633 | public static function tpg_get_categories_by_id( $cat ) { |
| 3634 | $terms = get_terms( [ |
| 3635 | 'taxonomy' => $cat, |
| 3636 | 'hide_empty' => true, |
| 3637 | ] ); |
| 3638 | |
| 3639 | $options = []; |
| 3640 | if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { |
| 3641 | foreach ( $terms as $term ) { |
| 3642 | $options[ $term->term_id ] = $term->name; |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | return $options; |
| 3647 | } |
| 3648 | |
| 3649 | |
| 3650 | |
| 3651 | /** |
| 3652 | * Gutenberg Functionality |
| 3653 | * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
| 3654 | */ |
| 3655 | |
| 3656 | /** |
| 3657 | * Get Post Types. |
| 3658 | * |
| 3659 | * @since 1.0.9 |
| 3660 | */ |
| 3661 | public static function get_post_types_guten() { |
| 3662 | $post_types = get_post_types( |
| 3663 | [ |
| 3664 | 'public' => true, |
| 3665 | 'show_in_rest' => true, |
| 3666 | ], |
| 3667 | 'objects' |
| 3668 | ); |
| 3669 | |
| 3670 | $options = []; |
| 3671 | |
| 3672 | foreach ( $post_types as $post_type ) { |
| 3673 | if ( 'product' === $post_type->name ) { |
| 3674 | continue; |
| 3675 | } |
| 3676 | |
| 3677 | if ( 'attachment' === $post_type->name ) { |
| 3678 | continue; |
| 3679 | } |
| 3680 | |
| 3681 | if ( 'page' === $post_type->name ) { |
| 3682 | continue; |
| 3683 | } |
| 3684 | |
| 3685 | $options[] = [ |
| 3686 | 'value' => $post_type->name, |
| 3687 | 'label' => $post_type->label, |
| 3688 | ]; |
| 3689 | } |
| 3690 | |
| 3691 | return $options; |
| 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * Get all taxonomies. |
| 3696 | * |
| 3697 | * @since 1.0.9 |
| 3698 | */ |
| 3699 | |
| 3700 | public static function get_all_taxonomy_guten() { |
| 3701 | $post_types = Fns::get_post_types(); |
| 3702 | $taxonomies = get_taxonomies( [], 'objects' ); |
| 3703 | $all_taxonomies = []; |
| 3704 | foreach ( $taxonomies as $taxonomy => $object ) { |
| 3705 | if ( ! isset( $object->object_type[0] ) || ! in_array( $object->object_type[0], array_keys( $post_types ) ) |
| 3706 | || in_array( $taxonomy, Fns::get_excluded_taxonomy() ) |
| 3707 | ) { |
| 3708 | continue; |
| 3709 | } |
| 3710 | $all_taxonomies[ $taxonomy ] = Fns::tpg_get_categories_by_id( $taxonomy ); |
| 3711 | } |
| 3712 | |
| 3713 | return $all_taxonomies; |
| 3714 | |
| 3715 | } |
| 3716 | |
| 3717 | /** |
| 3718 | * Get all image sizes. |
| 3719 | * |
| 3720 | * @since 1.0.9 |
| 3721 | */ |
| 3722 | public static function get_all_image_sizes_guten() { |
| 3723 | global $_wp_additional_image_sizes; |
| 3724 | |
| 3725 | $sizes = get_intermediate_image_sizes(); |
| 3726 | $image_sizes = []; |
| 3727 | |
| 3728 | $image_sizes[] = [ |
| 3729 | 'value' => 'full', |
| 3730 | 'label' => esc_html__( 'Full', 'the-post-grid' ), |
| 3731 | ]; |
| 3732 | |
| 3733 | foreach ( $sizes as $size ) { |
| 3734 | if ( in_array( $size, [ 'thumbnail', 'medium', 'medium_large', 'large' ], true ) ) { |
| 3735 | $image_sizes[] = [ |
| 3736 | 'value' => $size, |
| 3737 | 'label' => ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ), |
| 3738 | ]; |
| 3739 | } else { |
| 3740 | $image_sizes[] = [ |
| 3741 | 'value' => $size, |
| 3742 | 'label' => sprintf( |
| 3743 | '%1$s (%2$sx%3$s)', |
| 3744 | ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ), |
| 3745 | $_wp_additional_image_sizes[ $size ]['width'], |
| 3746 | $_wp_additional_image_sizes[ $size ]['height'] |
| 3747 | ), |
| 3748 | ]; |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | if ( rtTPG()->hasPro() ) { |
| 3753 | $image_sizes[] = [ |
| 3754 | 'value' => 'custom', |
| 3755 | 'label' => esc_html__( 'Custom', 'the-post-grid' ), |
| 3756 | ]; |
| 3757 | } |
| 3758 | |
| 3759 | return apply_filters( 'tpg_image_size_guten', $image_sizes ); |
| 3760 | } |
| 3761 | |
| 3762 | |
| 3763 | /** |
| 3764 | * Prints HTML. |
| 3765 | * |
| 3766 | * @param string $html HTML. |
| 3767 | * @param bool $allHtml All HTML. |
| 3768 | * |
| 3769 | * @return mixed |
| 3770 | */ |
| 3771 | public static function print_html( $html, $allHtml = false ) { |
| 3772 | if ( $allHtml ) { |
| 3773 | echo stripslashes_deep( $html ); |
| 3774 | } else { |
| 3775 | echo wp_kses_post( stripslashes_deep( $html ) ); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | /** |
| 3780 | * Allowed HTML for wp_kses. |
| 3781 | * |
| 3782 | * @param string $level Tag level. |
| 3783 | * |
| 3784 | * @return mixed |
| 3785 | */ |
| 3786 | public static function allowedHtml( $level = 'basic' ) { |
| 3787 | $allowed_html = []; |
| 3788 | |
| 3789 | switch ( $level ) { |
| 3790 | case 'basic': |
| 3791 | $allowed_html = [ |
| 3792 | 'b' => [ |
| 3793 | 'class' => [], |
| 3794 | 'id' => [], |
| 3795 | ], |
| 3796 | 'i' => [ |
| 3797 | 'class' => [], |
| 3798 | 'id' => [], |
| 3799 | ], |
| 3800 | 'u' => [ |
| 3801 | 'class' => [], |
| 3802 | 'id' => [], |
| 3803 | ], |
| 3804 | 'br' => [ |
| 3805 | 'class' => [], |
| 3806 | 'id' => [], |
| 3807 | ], |
| 3808 | 'em' => [ |
| 3809 | 'class' => [], |
| 3810 | 'id' => [], |
| 3811 | ], |
| 3812 | 'span' => [ |
| 3813 | 'class' => [], |
| 3814 | 'id' => [], |
| 3815 | ], |
| 3816 | 'strong' => [ |
| 3817 | 'class' => [], |
| 3818 | 'id' => [], |
| 3819 | ], |
| 3820 | 'hr' => [ |
| 3821 | 'class' => [], |
| 3822 | 'id' => [], |
| 3823 | ], |
| 3824 | 'a' => [ |
| 3825 | 'href' => [], |
| 3826 | 'title' => [], |
| 3827 | 'class' => [], |
| 3828 | 'id' => [], |
| 3829 | 'target' => [], |
| 3830 | 'style' => [], |
| 3831 | ], |
| 3832 | 'div' => [ |
| 3833 | 'class' => [], |
| 3834 | 'id' => [], |
| 3835 | ], |
| 3836 | ]; |
| 3837 | break; |
| 3838 | |
| 3839 | case 'advanced': |
| 3840 | $allowed_html = [ |
| 3841 | 'b' => [ |
| 3842 | 'class' => [], |
| 3843 | 'id' => [], |
| 3844 | ], |
| 3845 | 'i' => [ |
| 3846 | 'class' => [], |
| 3847 | 'id' => [], |
| 3848 | ], |
| 3849 | 'u' => [ |
| 3850 | 'class' => [], |
| 3851 | 'id' => [], |
| 3852 | ], |
| 3853 | 'br' => [ |
| 3854 | 'class' => [], |
| 3855 | 'id' => [], |
| 3856 | ], |
| 3857 | 'em' => [ |
| 3858 | 'class' => [], |
| 3859 | 'id' => [], |
| 3860 | ], |
| 3861 | 'span' => [ |
| 3862 | 'class' => [], |
| 3863 | 'id' => [], |
| 3864 | ], |
| 3865 | 'strong' => [ |
| 3866 | 'class' => [], |
| 3867 | 'id' => [], |
| 3868 | ], |
| 3869 | 'hr' => [ |
| 3870 | 'class' => [], |
| 3871 | 'id' => [], |
| 3872 | ], |
| 3873 | 'a' => [ |
| 3874 | 'href' => [], |
| 3875 | 'title' => [], |
| 3876 | 'class' => [], |
| 3877 | 'id' => [], |
| 3878 | 'data-id' => [], |
| 3879 | 'target' => [], |
| 3880 | ], |
| 3881 | 'input' => [ |
| 3882 | 'type' => [], |
| 3883 | 'name' => [], |
| 3884 | 'class' => [], |
| 3885 | 'value' => [], |
| 3886 | ], |
| 3887 | ]; |
| 3888 | break; |
| 3889 | |
| 3890 | case 'image': |
| 3891 | $allowed_html = [ |
| 3892 | 'img' => [ |
| 3893 | 'src' => [], |
| 3894 | 'data-src' => [], |
| 3895 | 'alt' => [], |
| 3896 | 'height' => [], |
| 3897 | 'width' => [], |
| 3898 | 'class' => [], |
| 3899 | 'id' => [], |
| 3900 | 'style' => [], |
| 3901 | 'srcset' => [], |
| 3902 | 'loading' => [], |
| 3903 | 'sizes' => [], |
| 3904 | ], |
| 3905 | 'div' => [ |
| 3906 | 'class' => [], |
| 3907 | ], |
| 3908 | ]; |
| 3909 | break; |
| 3910 | |
| 3911 | case 'anchor': |
| 3912 | $allowed_html = [ |
| 3913 | 'a' => [ |
| 3914 | 'href' => [], |
| 3915 | 'title' => [], |
| 3916 | 'class' => [], |
| 3917 | 'id' => [], |
| 3918 | 'style' => [], |
| 3919 | ], |
| 3920 | ]; |
| 3921 | break; |
| 3922 | |
| 3923 | default: |
| 3924 | // code... |
| 3925 | break; |
| 3926 | } |
| 3927 | |
| 3928 | return $allowed_html; |
| 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * Definition for wp_kses. |
| 3933 | * |
| 3934 | * @param string $string String to check. |
| 3935 | * @param string $level Tag level. |
| 3936 | * |
| 3937 | * @return mixed |
| 3938 | */ |
| 3939 | public static function htmlKses( $string, $level ) { |
| 3940 | if ( empty( $string ) ) { |
| 3941 | return; |
| 3942 | } |
| 3943 | |
| 3944 | return wp_kses( $string, self::allowedHtml( $level ) ); |
| 3945 | } |
| 3946 | |
| 3947 | |
| 3948 | /** |
| 3949 | * Insert Array Item in specific position |
| 3950 | * |
| 3951 | * @param $array |
| 3952 | * @param $position |
| 3953 | * @param $insert_array |
| 3954 | * |
| 3955 | * @return void |
| 3956 | */ |
| 3957 | public static function array_insert( &$array, $position, $insert_array ) { |
| 3958 | $first_array = array_splice( $array, 0, $position + 1 ); |
| 3959 | $array = array_merge( $first_array, $insert_array, $array ); |
| 3960 | } |
| 3961 | |
| 3962 | /** |
| 3963 | * tpg_option |
| 3964 | * |
| 3965 | * @param $option_name |
| 3966 | * @param $default_value |
| 3967 | * |
| 3968 | * @return string |
| 3969 | */ |
| 3970 | public static function tpg_option( $option_name, $default_value = '' ) { |
| 3971 | $settings = get_option( rtTPG()->options['settings'] ); |
| 3972 | if ( ! empty( $settings[ $option_name ] ) ) { |
| 3973 | return $settings[ $option_name ]; |
| 3974 | } else if ( $default_value ) { |
| 3975 | return $default_value; |
| 3976 | } |
| 3977 | |
| 3978 | return ''; |
| 3979 | } |
| 3980 | |
| 3981 | /** |
| 3982 | * change_icon |
| 3983 | * |
| 3984 | * @param $fontawesome |
| 3985 | * @param $flaticon |
| 3986 | * |
| 3987 | * @return mixed |
| 3988 | */ |
| 3989 | public static function change_icon( $fontawesome, $flaticon ) { |
| 3990 | if ( self::tpg_option( 'tpg_icon_font' ) === 'fontawesome' ) { |
| 3991 | return $fontawesome; |
| 3992 | } else { |
| 3993 | return $flaticon; |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | } |