%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/friendstravel.al/wp-content/plugins/travel-booking/inc/
Upload File :
Create Path :
Current File : /var/www/html/friendstravel.al/wp-content/plugins/travel-booking/inc/rewrite_url_tour.php

<?php
add_filter( 'template_include', 'filter_template_include_phys' );
function filter_template_include_phys( $template ) {
	if ( ! empty( $_GET['page_id'] ) && get_option( 'permalink_structure' ) == "" && $_GET['page_id'] == (int) get_option( 'tours_show_page_id' ) ) {
		wp_safe_redirect( home_url( '?is_tour=1' ) );
		exit;
	}

	if ( $GLOBALS['wp_query']->get( 'is_tour' ) ) {
		$template = tb_get_file_template( 'archive-tour.php' );
		//		$template = TB_PHYS_TEMPLATE_PATH_DEFAULT . 'archive-tour.php';
	}

	return $template;
}

add_filter( 'post_type_link', 'filter_post_type_link_phys', 10, 4 );
function filter_post_type_link_phys( $post_link, $post, $leavename, $sample ) {
	if ( 'product' == $post->post_type ) {
		$product = wc_get_product( $post );
		if ( $product->is_type( 'tour_phys' ) ) {
			static $product_struct, $is_complex_struct, $cache = array();

			$cache_key = $post_link;
			if ( isset( $cache[$cache_key] ) ) {
				return $cache[$cache_key];
			}

			if ( null === $product_struct ) {
				if ( isset( $GLOBALS['wp_rewrite']->extra_permastructs['product'] ) ) {
					$product_struct_init = $GLOBALS['wp_rewrite']->extra_permastructs['product']['struct'];
					$mapper              = array(
						'`%product%`' => '{XPRODUCTX}',
						'`%\w+%`'     => '[^/]+',
					);
					$product_struct      = preg_replace( array_keys( $mapper ), $mapper, ( $product_struct_init && $product_struct_init[0] != '/' ? '/' : '' ) . $product_struct_init );
					$is_complex_struct   = strpos( $product_struct, '[^/]+' ) !== false;
				}
			}

			$what_replace   = str_replace( '{XPRODUCTX}', $post->post_name, $product_struct );
			$full_tour_slug = get_tour_base_rewrite_rule_phys( true ) . $post->post_name;
			if ( $is_complex_struct ) {
				$fixed_link = preg_replace( '`' . $what_replace . '`', $full_tour_slug, $post_link );
			} else {
				$fixed_link = str_replace( $what_replace, $full_tour_slug, $post_link );
			}
			$cache[$cache_key] = $fixed_link;

			return $fixed_link;
		}
	}

	return $post_link;
}

add_filter( 'rewrite_rules_array', 'filter_rewrite_rules_array_phys' );
function filter_rewrite_rules_array_phys( $rules ) {
	$tour_base_url = get_tour_base_rewrite_rule_phys( true, true );
	if ( $tour_base_url ) {
		$tour_base_url = ltrim( $tour_base_url, '/' );
		$new_rules     = array(
			$tour_base_url . 'page/([0-9]{1,})/?' => 'index.php?is_tour=1&paged=$matches[1]',
			$tour_base_url . '?$'                 => 'index.php?is_tour=1', // &post_type=product&product_type=tour_phys

			$tour_base_url . '([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?product=$matches[1]&feed=$matches[2]',
			$tour_base_url . '([^/]+)/(feed|rdf|rss|rss2|atom)/?$'      => 'index.php?product=$matches[1]&feed=$matches[2]',
			$tour_base_url . '([^/]+)/comment-page-([0-9]{1,})/?'       => 'index.php?product=$matches[1]&cpage=$matches[2]',
			$tour_base_url . '(.+)'                                     => 'index.php?product=$matches[1]',
		);

		return array_merge( $new_rules, $rules );
	}

	return $rules;
}

function get_tour_base_rewrite_rule_phys( $with_front = false, $reset_cache = false ) {
	static $base_url, $base_full, $is_front_page, $default_lang, $cur_lang;

	if ( null === $base_url || $reset_cache ) {
		$tours_page_id = (int) get_option( 'tours_show_page_id' );

		if ( $tours_page_id && 'page' == get_option( 'show_on_front' ) && $tours_page_id == get_option( 'page_on_front' ) ) {
			$base_url      = '';
			$is_front_page = true;
		} else {
			$base_url = $tours_page_id ? get_page_uri( $tours_page_id ) : 'tours';
			if ( $base_url ) {
				$base_url .= '/';
			}
		}
	}

	if ( $with_front ) {
		if ( null === $base_full || $reset_cache ) {
			$front = $GLOBALS['wp_rewrite']->front;
			if ( $front != '/index.php/' ) {
				$front = '/';
			}
			$base_full = $base_url || $is_front_page ? $front . $base_url : '';
		}

		return $base_full;
	}

	return $base_url;
}


// remove active menu on single-tour
add_filter( 'wp_nav_menu_objects', 'filter_nav_menu_item_classes_phys', 10, 3 );
function filter_nav_menu_item_classes_phys( $menu_items ) {
	if ( ! is_woocommerce() || ! $menu_items ) {
		return $menu_items;
	}

	$menu_items_tmp = array();

	if ( is_single() ) {
		foreach ( $menu_items as $key => $menu_item ) {
			// Unset active class for blog page
			foreach ( $menu_item->classes as $k => $val ) {
				if ( $val == 'current-menu-item' || $val == 'current_page_parent' ) {
					$menu_item->classes[$k] = '';
				}
			}

			array_push( $menu_items_tmp, $menu_item );
		}

		return $menu_items_tmp;
	} elseif ( is_post_type_archive( 'product' ) ) {
		if ( get_query_var( 'is_tour' ) ) {
			foreach ( $menu_items as $key => $menu_item ) {// Unset active class for blog page
				foreach ( $menu_item->classes as $k => $val ) {
					if ( $val == 'current-menu-item' || $val == 'current_page_parent' ) {
						$menu_item->classes[$k] = '';
					}
				}

				array_push( $menu_items_tmp, $menu_item );
			}

			return $menu_items_tmp;
		}
	}

	//	echo '<pre>' . print_r( $menu_items_tmp, true ) . '</pre>';
	return $menu_items;
}

function set_menu_item_classes_list_tour( $classes, $item, $args ) {
	if ( get_option( 'tours_show_page_id' ) ) {
		if ( get_option( 'tours_show_page_id' ) && get_query_var( 'is_tour' ) && (int) $item->object_id == (int) get_option( 'tours_show_page_id' )
		) {
			$classes[] = 'current-menu-item';
		}

		return array_unique( $classes );
	}

	return $classes;
}

add_filter( 'nav_menu_css_class', 'set_menu_item_classes_list_tour', 10, 3 );

add_filter( 'wp_title', 'change_title_on_page_tours_phys' );
function change_title_on_page_tours_phys( $title ) {
	if ( get_query_var( 'is_tour' ) && get_option( 'tours_show_page_id' ) ) {
		$title = apply_filters( 'title_travelwp', get_the_title( get_option( 'tours_show_page_id' ) ) . ' - ' );
	}

	return $title;
}

add_action( 'init', 'rewrite_slug_attribute_woo_by_phys' );
function rewrite_slug_attribute_woo_by_phys() {
	$taxonomies    = get_object_taxonomies( 'product', 'objects' );
	$attribute_arr = array();

	if ( empty( $taxonomies ) ) {
		return '';
	}

	foreach ( $taxonomies as $tax ) {
		$tax_name = $tax->name;
		if ( 0 !== strpos( $tax_name, 'pa_' ) ) {
			continue;
		}
		if ( ! in_array( $tax_name, $attribute_arr ) ) {
			$attribute_arr[$tax_name] = $tax_name;
		}
	}

	foreach ( $attribute_arr as $attr ) {
		$attr_name                = str_replace( 'pa_', '', $attr );
		$slug_rewrite             = 'tour-' . $attr_name;
		$label                    = $attr_name;
		$taxonomy_data            = array();
		$taxonomy_data            = array(
			'labels' => array(
				'name'              => $label,
				'singular_name'     => $label,
				'search_items'      => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
				'all_items'         => sprintf( __( 'All %s', 'woocommerce' ), $label ),
				'parent_item'       => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
				'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
				'edit_item'         => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
				'update_item'       => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
				'add_new_item'      => sprintf( __( 'Add New %s', 'woocommerce' ), $label ),
				'new_item_name'     => sprintf( __( 'New %s', 'woocommerce' ), $label ),
				'not_found'         => sprintf( __( 'No &quot;%s&quot; found', 'woocommerce' ), $label ),
			),
			'show_in_menu'  => false,
		);
		$taxonomy_data['rewrite'] = array(
			'slug'         => '/' . $slug_rewrite,
			'with_front'   => false,
			'hierarchical' => true
		);
		register_taxonomy( $attr, apply_filters( "woocommerce_taxonomy_objects_{$attr}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$attr}", $taxonomy_data ) );

		flush_rewrite_rules();
		delete_transient( 'wc_attribute_taxonomies' );
	}
}

Zerion Mini Shell 1.0