/** * Return the pagination links for the current loop. * * See {@link paginate_links()} for the available options that you can use with this function. * * @since 4.0 * @uses $wp_rewrite * @uses apply_filters() Applies 'wpsc_product_pagination_links' filter. * @uses apply_filters() Applies 'wpsc_product_pagination_links_args' filter. * @uses home_url() * @uses is_rtl() * @uses paginate_links() * @uses wp_parse_args() * @uses WP_Rewrite::using_permalinks() * @uses wpsc_get_current_page_number() * * @param string|array $args Query string or an array of options. */ function wpsc_get_product_pagination_links($args = '') { global $wp_rewrite, $wp_query; $base = ''; if (wpsc_is_store()) { $base = home_url($wp_rewrite->root . wpsc_get_option('store_slug')); } elseif (wpsc_is_product_category()) { $base = wpsc_get_product_category_permalink(); } elseif (wpsc_is_product_tag()) { $base = wpsc_get_product_tag_permalink(); } if ($wp_rewrite->using_permalinks()) { $format = 'page/%#%'; } else { $format = '?page=%#%'; } $defaults = array('base' => trailingslashit($base) . '%_%', 'format' => $format, 'total' => $wp_query->max_num_pages, 'current' => wpsc_get_current_page_number(), 'prev_text' => is_rtl() ? __('→', 'wpsc') : __('←', 'wpsc'), 'next_text' => is_rtl() ? __('←', 'wpsc') : __('→', 'wpsc'), 'end_size' => 3, 'mid_size' => 2); $defaults = apply_filters('wpsc_get_product_pagination_links', $defaults); $r = wp_parse_args($args, $defaults); return apply_filters('wpsc_get_product_pagination_links', paginate_links($r)); }
/** * Override the per page parameter to use WPEC own "products per page" option. * * @since 4.0 * @uses WP_Query::is_main_query() * @uses wpsc_get_option() Gets WPEC 'products_per_page' option. * @uses wpsc_is_pagination_enabled() * @uses wpsc_is_store() * @uses wpsc_is_product_category() * @uses wpsc_is_product_tag() * * @param object $query */ function wpsc_action_set_product_per_page_query_var($query) { if (is_single()) { return; } if (wpsc_is_pagination_enabled() && $query->is_main_query() && (wpsc_is_store() || wpsc_is_product_category() || wpsc_is_product_tag())) { $query->set('posts_per_archive_page', wpsc_get_option('products_per_page')); } }
/** * Parse drill-down arguments based on current page's URL * * @access private * @since 0.1 */ public function _action_get_current_url_args() { global $wp_rewrite; $arg_str = get_query_var('wpsc_cat_drill_down'); // break down the query into arrays of categories for each widget // being in used $this->url_args = $this->parse_url($arg_str); // depending on whether this is a store page, category or tag page, // prepare the base URL if (wpsc_is_product_category()) { $base = $wp_rewrite->get_extra_permastruct('wpsc_cat_drill_down_category'); $obj = get_queried_object(); $this->url_base = str_replace('%wpsc_product_category%', $obj->slug, $base); $this->queried_object = $obj; } elseif (wpsc_is_product_tag()) { $base = $wp_rewrite->get_extra_permastruct('wpsc_cat_drill_down_tag'); $obj = get_queried_object(); $this->url_base = str_replace('%wpsc_product_tag%', $obj->slug, $base); $this->queried_object = $obj; } else { $this->url_base = $wp_rewrite->get_extra_permastruct('wpsc_cat_drill_down_store'); } }
/** * Return the HTML for the breadcrumb of a shop page. * * The available options to customize the output include: * 'before' - HTML before the breadcrumb. Defaults to '<p class="%s">'. The %s * placeholder will be replaced by the class attribute. * 'after' - HTML after the breadcrumb. Defaults to '</p>'. * 'separator' - The separator between breadcrumb items. Defaults to › . * 'padding' - The number of spaces you want to insert to the both sides of the * separator. Defaults to 1. * 'include_home' - Whether to include a link to home in the breadcrumb. Defaults to true. * 'home_text' - The text for the home link. Defaults to "Home". * 'include_store' - Whether to include a link to the main store in the breadcrumb. * Defaults to true. * 'store_text' - The text for the store link. Defaults to "Products". * 'include_current' - Whether to include a link to the current page in the breadcrumb. * Defaults to true. * 'current_text' - The text for the current link. Defaults to the category / product title. * * @since 4.0 * @uses apply_filters() Applies 'wpsc_breadcrumb_array' filter. * @uses apply_filters() Applies 'wpsc_breadcrumb_class' filter. * @uses apply_filters() Applies 'wpsc_breadcrumb_separator' filter. * @uses apply_filters() Applies 'wpsc_get_breadcrumb' filter. * @uses get_option() Get the 'page_on_front' option. * @uses get_queried_object() * @uses get_term_field() * @uses get_the_title() * @uses wp_get_object_terms() * @uses wp_parse_args() * @uses wpsc_is_store() * @uses wpsc_get_store_url() * @uses wpsc_get_store_title() * @uses wpsc_get_product_category_name() * @uses wpsc_get_product_category_permalink() * @uses wpsc_get_product_tag_name() * @uses wpsc_get_product_title() * @uses wpsc_is_product_category() * @uses wpsc_is_product_tag() * @uses wpsc_is_single() * * @param string|array $args Optional. Query string or array of options. Defaults to ''. * @return string */ function wpsc_get_breadcrumb($args = '') { $args = wp_parse_args($args); $pre_front_text = $pre_current_text = ''; // No custom home text if (empty($args['home_text'])) { // Set home text to page title if ($front_id = get_option('page_on_front')) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'wp-e-commerce'); } } // No custom store text if (empty($args['store_text'])) { $pre_store_text = wpsc_get_store_title(); } else { $pre_store_text = $args['store_text']; } $parent = null; if (wpsc_is_single()) { // if this is a single product, find its product category $pre_current_text = wpsc_get_product_title(); $product_categories = wp_get_object_terms(wpsc_get_product_id(), 'wpsc_product_category'); // if there are multiple product categories associated with this product, choose the most // appropriate one based on the context if (!empty($product_categories)) { $parent = $product_categories[0]; $context = get_query_var('wpsc_product_category'); if ($context && in_array($context, wp_list_pluck($product_categories, 'slug'))) { $parent = get_term_by('slug', $context, 'wpsc_product_category'); } } } elseif (wpsc_is_store()) { // if this is the main store, default the "current_text" argument to // the store title $pre_current_text = wpsc_get_store_title(); } elseif (wpsc_is_product_category()) { // if this is a product category, find its parent category if it has // one $pre_current_text = wpsc_get_product_category_name(); $term = get_queried_object(); if ($term->parent) { $parent = get_term($term->parent, 'wpsc_product_category'); } } elseif (wpsc_is_product_tag()) { // if this is a product tag, set "current_text" to the tag name by default $pre_current_text = wpsc_get_product_tag_name(); } elseif (wpsc_is_customer_account()) { // if this is the customer account page $c = _wpsc_get_current_controller(); // if we're displaying an order's details, set the parent to the // "Your Account" page if ($c->order_id) { $pre_current_text = $c->order_id; $parent = array(array('title' => __('Your Account', 'wp-e-commerce'), 'url' => wpsc_get_customer_account_url())); } else { // otherwise, set the "current_text" argument to "Your Account" $pre_current_text = __('Your Account', 'wp-e-commerce'); } } $defaults = array('before' => '<ul class="%s">', 'after' => '</ul>', 'before_item' => '<li class="%s">', 'after_item' => '</li>', 'before_divider' => '<span class="%s">', 'after_divider' => '</span>', 'divider' => '»', 'padding' => 0, 'include_home' => true, 'home_text' => $pre_front_text, 'include_store' => true, 'store_text' => $pre_store_text, 'include_current' => true, 'current_text' => $pre_current_text); $defaults = apply_filters('wpsc_get_breadcrumb_default_args', $defaults); $r = array_merge($defaults, $args); extract($r); // replace placeholders in arguments $before = sprintf($before, 'wpsc-breadcrumb'); $before_item = sprintf($before_item, 'wpsc-breadcrumb-item'); $before_divider = sprintf($before_divider, 'wpsc-breadcrumb-divider'); // if padding is set, prepare the length, padding string and divider if ($padding) { $length = strlen(html_entity_decode($divider, ENT_COMPAT, 'UTF-8')) + $padding * 2; $padding = str_repeat(" ", $length); $divider = $padding . $divider . $padding; } $divider = $before_divider . $divider . $after_divider; // generate the breadcrumb array in reverse $breadcrumbs = array(); // include current page in breadcrumb if ($include_current && !empty($current_text)) { $before_current_item = sprintf($before_item, 'wpsc-breadcrumb-item wpsc-breadcrumb-current'); $breadcrumbs[] = $before_current_item . $current_text . $after_item; } // include ancestors in breadcrumb $ancestors = array(); // if the current page has a parent if ($parent) { if (is_array($parent)) { // if $parent is an array, then use the 'url' and 'title' elements foreach ($parent as $p) { $before_this_item = sprintf($before_item, 'wpsc-breadcrumb-item wpsc-breadcrumb-ancestor'); $link = '<a href="' . esc_url($p['url']) . '">' . esc_html($p['title']) . '</a>'; $breadcrumbs[] = $before_this_item . $link . $divider . $after_item; } } else { // if $parent is a term object, recursively find all ancestors and // include them in the breadcrumb array while (!is_wp_error($parent) && is_object($parent)) { if (in_array($parent->parent, $ancestors)) { break; } $ancestors[] = $parent->parent; $before_this_item = sprintf($before_item, 'wpsc-breadcrumb-item wpsc-breadcrumb-ancestor'); $link = '<a href="' . wpsc_get_product_category_permalink($parent) . '">' . esc_html($parent->name) . '</a>'; $breadcrumbs[] = $before_this_item . $link . $divider . $after_item; $parent = get_term($parent->parent, 'wpsc_product_category'); } } } // include the store link if this is not the main store itself if ($include_store && !empty($store_text) && !wpsc_is_store()) { $before_this_item = sprintf($before_item, 'wpsc-breadcrumb-item wpsc-breadcrumb-store'); $link = '<a href="' . wpsc_get_store_url() . '">' . $store_text . '</a>'; $breadcrumbs[] = $before_this_item . $link . $divider . $after_item; } // include the home link if ($include_home && !empty($home_text) && !is_home() && !wpsc_get_option('store_as_front_page')) { $before_this_item = sprintf($before_item, 'wpsc-breadcrumb-item wpsc-breadcrumb-home'); $link = '<a href="' . trailingslashit(home_url()) . '">' . $home_text . '</a>'; $breadcrumbs[] = $before_this_item . $link . $divider . $after_item; } // reverse the breadcrumb array $breadcrumbs = apply_filters('wpsc_breadcrumb_array', array_reverse($breadcrumbs), $r); $html = $before . implode('', $breadcrumbs) . $after; return apply_filters('wpsc_get_breadcrumb', $html, $breadcrumbs, $r); }
function _wpsc_filter_body_class($classes) { if (!wpsc_is_controller()) { return $classes; } $classes[] = 'wpsc-controller'; $classes[] = 'wpsc-' . _wpsc_get_current_controller_name(); $classes[] = 'wpsc-controller-' . _wpsc_get_current_controller_slug(); if (wpsc_is_store() || wpsc_is_store_front_page() || wpsc_is_product_category() || wpsc_is_product_tag()) { $classes[] = 'wpsc-' . wpsc_get_option('layout'); } return $classes; }