示例#1
0
 /**
  * Manages CSS relationship classes applied to Shopp elements appearing in a WordPress navigation menu
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $menuitems The provided WordPress menu items
  * @return array Updated menu items with proper relationship classes
  **/
 public function menus($menuitems)
 {
     $is_shopp_page = is_shopp_page();
     $keymap = array();
     $parents = array();
     foreach ($menuitems as $key => $item) {
         $page = false;
         // Remove the faulty wp_page_menu (deprecated) class for Shopp pages
         if ($is_shopp_page && in_array('current_page_parent', $item->classes)) {
             unset($item->classes[array_search('current_page_parent', $item->classes)]);
         }
         // Otherwise, skip dealing with any non-Shopp page
         if (ShoppPages::QUERYVAR == $item->type) {
             // Determine the queried Shopp page object name
             $Page = ShoppPages()->requested();
             if ($Page && !is_shopp_collection()) {
                 $page = $Page->name();
             }
             // Set the catalog as current page parent
             if ('catalog' == $item->object && ($is_shopp_page || is_shopp_product())) {
                 $item->classes[] = 'current-page-parent';
             }
             $keymap[$item->db_id] = $key;
         }
         if ('shopp_collection' == $item->type) {
             $page = get_query_var($item->type);
             $keymap[$item->db_id] = $key;
         }
         if ($page == $item->object) {
             $item->classes[] = 'current-page-item';
             $item->classes[] = 'current-menu-item';
             $parents[] = $item->menu_item_parent;
         }
     }
     foreach ((array) $parents as $parentid) {
         if (!isset($keymap[$parentid])) {
             continue;
         }
         $parent = $menuitems[$keymap[$parentid]];
         $parent->classes[] = 'current-menu-parent';
         $parent->classes[] = 'current-page-parent';
         $parent->classes[] = 'current-menu-ancestor';
         $parent->classes[] = 'current-page-ancestor';
         $ancestor = $parent;
         while (0 != $ancestor->menu_item_parent) {
             $ancestor = $menuitems[$keymap[$ancestor->menu_item_parent]];
             $ancestor->classes[] = 'current-menu-ancestor';
             $ancestor->classes[] = 'current-page-ancestor';
         }
     }
     return $menuitems;
 }
 function shopp_transaction_tracking($push)
 {
     global $Shopp;
     // Only process if we're in the checkout process (receipt page)
     if (version_compare(substr(SHOPP_VERSION, 0, 3), '1.1') >= 0) {
         // Only process if we're in the checkout process (receipt page)
         if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) {
             return $push;
         }
         if (empty($Shopp->Order->purchase)) {
             return $push;
         }
         $Purchase = new Purchase($Shopp->Order->purchase);
         $Purchase->load_purchased();
     } else {
         // For 1.0.x
         // Only process if we're in the checkout process (receipt page)
         if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) {
             return $push;
         }
         // Only process if we have valid order data
         if (!isset($Shopp->Cart->data->Purchase)) {
             return $push;
         }
         if (empty($Shopp->Cart->data->Purchase->id)) {
             return $push;
         }
         $Purchase = $Shopp->Cart->data->Purchase;
     }
     $push[] = "'_addTrans'," . "'" . $Purchase->id . "'," . "'" . GA_Filter::ga_str_clean(get_bloginfo('name')) . "'," . "'" . number_format($Purchase->total, 2) . "'," . "'" . number_format($Purchase->tax, 2) . "'," . "'" . number_format($Purchase->shipping, 2) . "'," . "'" . $Purchase->city . "'," . "'" . $Purchase->state . "'," . "'.{$Purchase->country}.'";
     // Country
     foreach ($Purchase->purchased as $item) {
         $sku = empty($item->sku) ? 'PID-' . $item->product . str_pad($item->price, 4, '0', STR_PAD_LEFT) : $item->sku;
         $push[] = "'_addItem'," . "'" . $Purchase->id . "'," . "'" . $sku . "'," . "'" . str_replace("'", "", $item->name) . "'," . "'" . $item->optionlabel . "'," . "'" . number_format($item->unitprice, 2) . "'," . "'" . $item->quantity . "'";
     }
     $push[] = "'_trackTrans'";
     return $push;
 }
 function tag($property, $options = array())
 {
     global $Shopp;
     $pages = $Shopp->Settings->get('pages');
     if (SHOPP_PERMALINKS) {
         $path = $Shopp->shopuri;
     } else {
         $page = add_query_arg('page_id', $pages['catalog']['id'], $Shopp->shopuri);
     }
     switch ($property) {
         case "url":
             return $Shopp->link('catalog');
             break;
         case "display":
         case "type":
             return $this->type;
             break;
         case "is-landing":
         case "is-catalog":
             return is_shopp_page('catalog') && $this->type == "catalog";
             break;
         case "is-category":
             return is_shopp_page('catalog') && $this->type == "category";
             break;
         case "is-product":
             return is_shopp_page('catalog') && $this->type == "product";
             break;
         case "is-cart":
             return is_shopp_page('cart');
             break;
         case "is-checkout":
             return is_shopp_page('checkout');
             break;
         case "is-account":
             return is_shopp_page('account');
             break;
         case "tagcloud":
             if (!empty($options['levels'])) {
                 $levels = $options['levels'];
             } else {
                 $levels = 7;
             }
             if (empty($this->tags)) {
                 $this->load_tags();
             }
             $min = -1;
             $max = -1;
             foreach ($this->tags as $tag) {
                 if ($min == -1 || $tag->products < $min) {
                     $min = $tag->products;
                 }
                 if ($max == -1 || $tag->products > $max) {
                     $max = $tag->products;
                 }
             }
             if ($max == 0) {
                 $max = 1;
             }
             $string = '<ul class="shopp tagcloud">';
             foreach ($this->tags as $tag) {
                 $level = floor((1 - $tag->products / $max) * $levels) + 1;
                 if (SHOPP_PERMALINKS) {
                     $link = $path . 'tag/' . urlencode($tag->name) . '/';
                 } else {
                     $link = add_query_arg('shopp_tag', urlencode($tag->name), $page);
                 }
                 $string .= '<li class="level-' . $level . '"><a href="' . $link . '" rel="tag">' . $tag->name . '</a></li> ';
             }
             $string .= '</ul>';
             return $string;
             break;
         case "has-categories":
             if (empty($this->categories)) {
                 $this->load_categories(array('where' => 'true'), $options['showsmart']);
             }
             if (count($this->categories) > 0) {
                 return true;
             } else {
                 return false;
             }
             break;
         case "categories":
             if (!$this->categoryloop) {
                 reset($this->categories);
                 $Shopp->Category = current($this->categories);
                 $this->categoryloop = true;
             } else {
                 $Shopp->Category = next($this->categories);
             }
             if (current($this->categories)) {
                 $Shopp->Category = current($this->categories);
                 return true;
             } else {
                 $this->categoryloop = false;
                 return false;
             }
             break;
         case "category-list":
             $defaults = array('title' => '', 'before' => '', 'after' => '', 'class' => '', 'exclude' => '', 'orderby' => 'name', 'order' => 'ASC', 'depth' => 0, 'childof' => 0, 'parent' => false, 'showall' => false, 'linkall' => false, 'linkcount' => false, 'dropdown' => false, 'hierarchy' => false, 'products' => false, 'wraplist' => true, 'showsmart' => false);
             $options = array_merge($defaults, $options);
             extract($options, EXTR_SKIP);
             $this->load_categories(array("where" => "(pd.published='on' OR pd.id IS NULL)", "orderby" => $orderby, "order" => $order), $showsmart);
             $string = "";
             $depthlimit = $depth;
             $depth = 0;
             $exclude = explode(",", $exclude);
             $classes = ' class="shopp_categories' . (empty($class) ? '' : ' ' . $class) . '"';
             $wraplist = value_is_true($wraplist);
             if (value_is_true($dropdown)) {
                 if (!isset($default)) {
                     $default = __('Select category&hellip;', 'Shopp');
                 }
                 $string .= $title;
                 $string .= '<form><select name="shopp_cats" id="shopp-categories-menu"' . $classes . '>';
                 $string .= '<option value="">' . $default . '</option>';
                 foreach ($this->categories as &$category) {
                     if (!empty($category->id) && in_array($category->id, $exclude)) {
                         continue;
                     }
                     // Skip excluded categories
                     if ($category->total == 0 && !isset($category->smart)) {
                         continue;
                     }
                     // Only show categories with products
                     if ($depthlimit && $category->depth >= $depthlimit) {
                         continue;
                     }
                     if (value_is_true($hierarchy) && $category->depth > $depth) {
                         $parent =& $previous;
                         if (!isset($parent->path)) {
                             $parent->path = '/' . $parent->slug;
                         }
                     }
                     if (value_is_true($hierarchy)) {
                         $padding = str_repeat("&nbsp;", $category->depth * 3);
                     }
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $category->uri;
                     } else {
                         $link = add_query_arg('shopp_category', $category->id, $Shopp->shopuri);
                     }
                     $total = '';
                     if (value_is_true($products) && $category->total > 0) {
                         $total = ' (' . $category->total . ')';
                     }
                     $string .= '<option value="' . $link . '">' . $padding . $category->name . $total . '</option>';
                     $previous =& $category;
                     $depth = $category->depth;
                 }
                 $string .= '</select></form>';
                 $string .= '<script type="text/javascript">';
                 $string .= 'var menu = document.getElementById(\'shopp-categories-menu\');';
                 $string .= 'if (menu) {';
                 $string .= '	menu.onchange = function () {';
                 $string .= '		document.location.href = this.options[this.selectedIndex].value;';
                 $string .= '	}';
                 $string .= '}';
                 $string .= '</script>';
             } else {
                 $string .= $title;
                 if ($wraplist) {
                     $string .= '<ul' . $classes . '>';
                 }
                 foreach ($this->categories as &$category) {
                     if (!isset($category->total)) {
                         $category->total = 0;
                     }
                     if (!isset($category->depth)) {
                         $category->depth = 0;
                     }
                     if (!empty($category->id) && in_array($category->id, $exclude)) {
                         continue;
                     }
                     // Skip excluded categories
                     if ($depthlimit && $category->depth >= $depthlimit) {
                         continue;
                     }
                     if (value_is_true($hierarchy) && $category->depth > $depth) {
                         $parent =& $previous;
                         if (!isset($parent->path)) {
                             $parent->path = $parent->slug;
                         }
                         $string = substr($string, 0, -5);
                         // Remove the previous </li>
                         $active = '';
                         if (isset($Shopp->Category) && !empty($parent->slug) && preg_match('/(^|\\/)' . $parent->path . '(\\/|$)/', $Shopp->Category->uri)) {
                             $active = ' active';
                         }
                         $subcategories = '<ul class="children' . $active . '">';
                         $string .= $subcategories;
                     }
                     if (value_is_true($hierarchy) && $category->depth < $depth) {
                         for ($i = $depth; $i > $category->depth; $i--) {
                             if (substr($string, strlen($subcategories) * -1) == $subcategories) {
                                 // If the child menu is empty, remove the <ul> to avoid breaking standards
                                 $string = substr($string, 0, strlen($subcategories) * -1) . '</li>';
                             } else {
                                 $string .= '</ul></li>';
                             }
                         }
                     }
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $category->uri;
                     } else {
                         $link = add_query_arg('shopp_category', !empty($category->id) ? $category->id : $category->uri, $Shopp->shopuri);
                     }
                     $total = '';
                     if (value_is_true($products) && $category->total > 0) {
                         $total = ' <span>(' . $category->total . ')</span>';
                     }
                     $current = '';
                     if (isset($Shopp->Category) && $Shopp->Category->slug == $category->slug) {
                         $current = ' class="current"';
                     }
                     $listing = '';
                     if ($category->total > 0 || isset($category->smart) || $linkall) {
                         $listing = '<a href="' . $link . '"' . $current . '>' . $category->name . ($linkcount ? $total : '') . '</a>' . (!$linkcount ? $total : '');
                     } else {
                         $listing = $category->name;
                     }
                     if (value_is_true($showall) || $category->total > 0 || isset($category->smart) || $category->children) {
                         $string .= '<li' . $current . '>' . $listing . '</li>';
                     }
                     $previous =& $category;
                     $depth = $category->depth;
                 }
                 if (value_is_true($hierarchy) && $depth > 0) {
                     for ($i = $depth; $i > 0; $i--) {
                         if (substr($string, strlen($subcategories) * -1) == $subcategories) {
                             // If the child menu is empty, remove the <ul> to avoid breaking standards
                             $string = substr($string, 0, strlen($subcategories) * -1) . '</li>';
                         } else {
                             $string .= '</ul></li>';
                         }
                     }
                 }
                 if ($wraplist) {
                     $string .= '</ul>';
                 }
             }
             return $string;
             break;
         case "views":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             $string = "";
             $string .= '<ul class="views">';
             if (isset($options['label'])) {
                 $string .= '<li>' . $options['label'] . '</li>';
             }
             $string .= '<li><button type="button" class="grid"></button></li>';
             $string .= '<li><button type="button" class="list"></button></li>';
             $string .= '</ul>';
             return $string;
         case "orderby-list":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             if (isset($Shopp->Category->smart)) {
                 return false;
             }
             $menuoptions = Category::sortoptions();
             $title = "";
             $string = "";
             $default = $Shopp->Settings->get('default_product_order');
             if (empty($default)) {
                 $default = "title";
             }
             if (isset($options['default'])) {
                 $default = $options['default'];
             }
             if (isset($options['title'])) {
                 $title = $options['title'];
             }
             if (value_is_true($options['dropdown'])) {
                 if (isset($Shopp->Cart->data->Category['orderby'])) {
                     $default = $Shopp->Cart->data->Category['orderby'];
                 }
                 $string .= $title;
                 $string .= '<form action="' . esc_url($_SERVER['REQUEST_URI']) . '" method="get" id="shopp-' . $Shopp->Category->slug . '-orderby-menu">';
                 if (!SHOPP_PERMALINKS) {
                     foreach ($_GET as $key => $value) {
                         if ($key != 'shopp_orderby') {
                             $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
                         }
                     }
                 }
                 $string .= '<select name="shopp_orderby" class="shopp-orderby-menu">';
                 $string .= menuoptions($menuoptions, $default, true);
                 $string .= '</select>';
                 $string .= '</form>';
                 $string .= '<script type="text/javascript">';
                 $string .= "jQuery('#shopp-" . $Shopp->Category->slug . "-orderby-menu select.shopp-orderby-menu').change(function () { this.form.submit(); });";
                 $string .= '</script>';
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], "?") !== false) {
                     list($link, $query) = explode("\\?", $_SERVER['REQUEST_URI']);
                 }
                 $query = $_GET;
                 unset($query['shopp_orderby']);
                 $query = http_build_query($query);
                 if (!empty($query)) {
                     $query .= '&';
                 }
                 foreach ($menuoptions as $value => $option) {
                     $label = $option;
                     $href = esc_url($link . '?' . $query . 'shopp_orderby=' . $value);
                     $string .= '<li><a href="' . $href . '">' . $label . '</a></li>';
                 }
             }
             return $string;
             break;
         case "breadcrumb":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             if (empty($this->categories)) {
                 $this->load_categories();
             }
             $separator = "&nbsp;&raquo; ";
             if (isset($options['separator'])) {
                 $separator = $options['separator'];
             }
             $category = false;
             if (isset($Shopp->Cart->data->breadcrumb)) {
                 $category = $Shopp->Cart->data->breadcrumb;
             }
             $trail = false;
             $search = array();
             if (isset($Shopp->Cart->data->Search)) {
                 $search = array('search' => $Shopp->Cart->data->Search);
             }
             $path = explode("/", $category);
             if ($path[0] == "tag") {
                 $category = "tag";
                 $search = array('tag' => urldecode($path[1]));
             }
             $Category = Catalog::load_category($category, $search);
             if (!empty($Category->uri)) {
                 $type = "category";
                 if (isset($Category->tag)) {
                     $type = "tag";
                 }
                 if (SHOPP_PERMALINKS) {
                     $link = esc_url(add_query_arg($_GET, $Shopp->shopuri . $type . '/' . $Category->uri));
                 } else {
                     if (isset($Category->smart)) {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $Category->slug, 'shopp_pid' => null)), $Shopp->shopuri));
                     } else {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $Category->id, 'shopp_pid' => null)), $Shopp->shopuri));
                     }
                 }
                 $filters = false;
                 if (!empty($Shopp->Cart->data->Category[$Category->slug])) {
                     $filters = ' (<a href="?shopp_catfilters=cancel">' . __('Clear Filters', 'Shopp') . '</a>)';
                 }
                 if (!empty($Shopp->Product)) {
                     $trail .= '<li><a href="' . $link . '">' . $Category->name . (!$trail ? '' : $separator) . '</a></li>';
                 } elseif (!empty($Category->name)) {
                     $trail .= '<li>' . $Category->name . $filters . (!$trail ? '' : $separator) . '</li>';
                 }
                 // Build category names path by going from the target category up the parent chain
                 $parentkey = !empty($Category->id) ? $this->categories[$Category->id]->parent : 0;
                 while ($parentkey != 0) {
                     $tree_category = $this->categories[$parentkey];
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $tree_category->uri;
                     } else {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $tree_category->id, 'shopp_pid' => null)), $Shopp->shopuri));
                     }
                     $trail = '<li><a href="' . $link . '">' . $tree_category->name . '</a>' . (empty($trail) ? '' : $separator) . '</li>' . $trail;
                     $parentkey = $tree_category->parent;
                 }
             }
             $trail = '<li><a href="' . $Shopp->link('catalog') . '">' . $pages['catalog']['title'] . '</a>' . (empty($trail) ? '' : $separator) . '</li>' . $trail;
             return '<ul class="breadcrumb">' . $trail . '</ul>';
             break;
         case "search":
             global $wp;
             $type = "hidden";
             if (isset($options['type'])) {
                 $type = $options['type'];
             }
             if ($type == "radio") {
                 $option = "shopp";
                 if (isset($options['option'])) {
                     $option = $options['option'];
                 }
                 $default = false;
                 if (isset($options['default'])) {
                     $default = value_is_true($options['default']);
                 }
                 $selected = '';
                 if ($default) {
                     $selected = ' checked="checked"';
                 }
                 if (!empty($wp->query_vars['st'])) {
                     $selected = '';
                     if ($wp->query_vars['st'] == $option) {
                         $selected = ' checked="checked"';
                     }
                 }
                 if ($option == "blog") {
                     return '<input type="radio" name="st" value="blog"' . $selected . ' />';
                 } else {
                     return '<input type="radio" name="st" value="shopp"' . $selected . ' />';
                 }
             } elseif ($type == "menu") {
                 if (empty($options['store'])) {
                     $options['store'] = __('Search the store', 'Shopp');
                 }
                 if (empty($options['blog'])) {
                     $options['blog'] = __('Search the blog', 'Shopp');
                 }
                 if (isset($wp->query_vars['st'])) {
                     $selected = $wp->query_vars['st'];
                 }
                 $menu = '<select name="st">';
                 if (isset($options['default']) && $options['default'] == "blog") {
                     $menu .= '<option value="blog"' . ($selected == "blog" ? ' selected="selected"' : '') . '>' . $options['blog'] . '</option>';
                     $menu .= '<option value="shopp"' . ($selected == "shopp" ? ' selected="selected"' : '') . '>' . $options['store'] . '</option>';
                 } else {
                     $menu .= '<option value="shopp"' . ($selected == "shopp" ? ' selected="selected"' : '') . '>' . $options['store'] . '</option>';
                     $menu .= '<option value="blog"' . ($selected == "blog" ? ' selected="selected"' : '') . '>' . $options['blog'] . '</option>';
                 }
                 $menu .= '</select>';
                 return $menu;
             } else {
                 return '<input type="hidden" name="st" value="shopp" />';
             }
             break;
         case "catalog-products":
             if ($property == "catalog-products") {
                 $Shopp->Category = new CatalogProducts($options);
             }
         case "new-products":
             if ($property == "new-products") {
                 $Shopp->Category = new NewProducts($options);
             }
         case "featured-products":
             if ($property == "featured-products") {
                 $Shopp->Category = new FeaturedProducts($options);
             }
         case "onsale-products":
             if ($property == "onsale-products") {
                 $Shopp->Category = new OnSaleProducts($options);
             }
         case "bestseller-products":
             if ($property == "bestseller-products") {
                 $Shopp->Category = new BestsellerProducts($options);
             }
         case "random-products":
             if ($property == "random-products") {
                 $Shopp->Category = new RandomProducts($options);
             }
         case "tag-products":
             if ($property == "tag-products") {
                 $Shopp->Category = new TagProducts($options);
             }
         case "related-products":
             if ($property == "related-products") {
                 $Shopp->Category = new RelatedProducts($options);
             }
         case "search-products":
             if ($property == "search-products") {
                 $Shopp->Category = new SearchResults($options);
             }
         case "category":
             if ($property == "category") {
                 if (isset($options['name'])) {
                     $Shopp->Category = new Category($options['name'], 'name');
                 } else {
                     if (isset($options['slug'])) {
                         $Shopp->Category = new Category($options['slug'], 'slug');
                     } else {
                         if (isset($options['id'])) {
                             $Shopp->Category = new Category($options['id']);
                         }
                     }
                 }
             }
             if (isset($options['reset'])) {
                 return $Shopp->Category = false;
             }
             if (isset($options['title'])) {
                 $Shopp->Category->name = $options['title'];
             }
             if (isset($options['show'])) {
                 $Shopp->Category->loading['limit'] = $options['show'];
             }
             if (isset($options['pagination'])) {
                 $Shopp->Category->loading['pagination'] = $options['pagination'];
             }
             if (isset($options['order'])) {
                 $Shopp->Category->loading['order'] = $options['order'];
             }
             if (isset($options['load'])) {
                 return true;
             }
             if (isset($options['controls']) && !value_is_true($options['controls'])) {
                 $Shopp->Category->controls = false;
             }
             if (isset($options['view'])) {
                 if ($options['view'] == "grid") {
                     $Shopp->Category->view = "grid";
                 } else {
                     $Shopp->Category->view = "list";
                 }
             }
             ob_start();
             if (isset($Shopp->Category->smart) && file_exists(SHOPP_TEMPLATES . "/category-{$Shopp->Category->slug}.php")) {
                 include SHOPP_TEMPLATES . "/category-{$Shopp->Category->slug}.php";
             } elseif (isset($Shopp->Category->id) && file_exists(SHOPP_TEMPLATES . "/category-{$Shopp->Category->id}.php")) {
                 include SHOPP_TEMPLATES . "/category-{$Shopp->Category->id}.php";
             } else {
                 include SHOPP_TEMPLATES . "/category.php";
             }
             $content = ob_get_contents();
             ob_end_clean();
             $Shopp->Category = false;
             // Reset the current category
             return $content;
             break;
         case "product":
             if (isset($options['name'])) {
                 $Shopp->Product = new Product($options['name'], 'name');
             } else {
                 if (isset($options['slug'])) {
                     $Shopp->Product = new Product($options['slug'], 'slug');
                 } else {
                     if (isset($options['id'])) {
                         $Shopp->Product = new Product($options['id']);
                     }
                 }
             }
             if (isset($options['load'])) {
                 return true;
             }
             ob_start();
             if (file_exists(SHOPP_TEMPLATES . "/product-{$Shopp->Product->id}.php")) {
                 include SHOPP_TEMPLATES . "/product-{$Shopp->Product->id}.php";
             } else {
                 include SHOPP_TEMPLATES . "/product.php";
             }
             $content = ob_get_contents();
             ob_end_clean();
             return $content;
             break;
         case "sideproduct":
             $content = false;
             $source = $options['source'];
             if ($source == "product" && isset($options['product'])) {
                 // Save original requested product
                 if ($Shopp->Product) {
                     $Requested = $Shopp->Product;
                 }
                 $products = explode(",", $options['product']);
                 if (!is_array($products)) {
                     $products = array($products);
                 }
                 foreach ($products as $product) {
                     $product = trim($product);
                     if (empty($product)) {
                         continue;
                     }
                     if (preg_match('/^[\\d+]$/', $product)) {
                         $Shopp->Product = new Product($product);
                     } else {
                         $Shopp->Product = new Product($product, 'slug');
                     }
                     if (empty($Shopp->Product->id)) {
                         continue;
                     }
                     if (isset($options['load'])) {
                         return true;
                     }
                     ob_start();
                     if (file_exists(SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php")) {
                         include SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php";
                     } else {
                         include SHOPP_TEMPLATES . "/sideproduct.php";
                     }
                     $content .= ob_get_contents();
                     ob_end_clean();
                 }
                 // Restore original requested category
                 if (!empty($Requested)) {
                     $Shopp->Product = $Requested;
                 } else {
                     $Shopp->Product = false;
                 }
             }
             if ($source == "category" && isset($options['category'])) {
                 // Save original requested category
                 if ($Shopp->Category) {
                     $Requested = $Shopp->Category;
                 }
                 if (empty($options['category'])) {
                     return false;
                 }
                 $Shopp->Category = Catalog::load_category($options['category']);
                 $Shopp->Category->load_products($options);
                 if (isset($options['load'])) {
                     return true;
                 }
                 foreach ($Shopp->Category->products as $product) {
                     $Shopp->Product = $product;
                     ob_start();
                     if (file_exists(SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php")) {
                         include SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php";
                     } else {
                         include SHOPP_TEMPLATES . "/sideproduct.php";
                     }
                     $content .= ob_get_contents();
                     ob_end_clean();
                 }
                 // Restore original requested category
                 if (!empty($Requested)) {
                     $Shopp->Category = $Requested;
                 } else {
                     $Shopp->Category = false;
                 }
             }
             return $content;
             break;
     }
 }
示例#4
0
function shopp_default_script_settings()
{
    $base = array();
    $settings = Shopp::currency_format();
    if (!empty($settings)) {
        $currency = array('cp' => $settings['cpos'], 'c' => $settings['currency'], 'p' => (int) $settings['precision'], 't' => $settings['thousands'], 'd' => $settings['decimals']);
        if (isset($settings['grouping'])) {
            $currency['g'] = is_array($settings['grouping']) ? join(',', $settings['grouping']) : $settings['grouping'];
        }
    }
    if (!is_admin()) {
        $base = array('nocache' => is_shopp_page('account'));
    }
    // Validation alerts
    shopp_localize_script('catalog', '$cv', array('field' => __('Your %s is required.', 'Shopp'), 'email' => __('The e-mail address you provided does not appear to be a valid address.', 'Shopp'), 'minlen' => __('The %s you entered is too short. It must be at least %d characters long.', 'Shopp'), 'pwdmm' => __('The passwords you entered do not match. They must match in order to confirm you are correctly entering the password you want to use.', 'Shopp'), 'chkbox' => __('%s must be checked before you can proceed.', 'Shopp')));
    // Checkout page settings & localization
    shopp_localize_script('checkout', '$co', array('ajaxurl' => admin_url('admin-ajax.php'), 'loginname' => Shopp::__('You did not enter a login.'), 'loginpwd' => Shopp::__('You did not enter a password to login with.'), 'badpan' => Shopp::__('Not a valid card number.'), 'submitting' => Shopp::__('Submitting&hellip;'), 'error' => Shopp::__('An error occurred while submitting your order. Please try submitting your order again.'), 'timeout' => (int) SHOPP_SUBMIT_TIMEOUT));
    // Validation alerts
    shopp_localize_script('cart', '$ct', array('items' => __('Items', 'Shopp'), 'total' => __('Total', 'Shopp')));
    // Calendar localization
    shopp_localize_script('calendar', '$cal', array('jan' => __('January', 'Shopp'), 'feb' => __('February', 'Shopp'), 'mar' => __('March', 'Shopp'), 'apr' => __('April', 'Shopp'), 'may' => __('May', 'Shopp'), 'jun' => __('June', 'Shopp'), 'jul' => __('July', 'Shopp'), 'aug' => __('August', 'Shopp'), 'sep' => __('September', 'Shopp'), 'oct' => __('October', 'Shopp'), 'nov' => __('November', 'Shopp'), 'dec' => __('December', 'Shopp'), 'sun' => __('Sun', 'Shopp'), 'mon' => __('Mon', 'Shopp'), 'tue' => __('Tue', 'Shopp'), 'wed' => __('Wed', 'Shopp'), 'thu' => __('Thu', 'Shopp'), 'fri' => __('Fri', 'Shopp'), 'sat' => __('Sat', 'Shopp')));
    // Product editor: unsaved changes warning
    shopp_localize_script('product-editor', '$msg', array('confirm' => __('The changes you made will be lost if you navigate away from this page.', 'Shopp')));
    $defaults = apply_filters('shopp_js_settings', array_merge($currency, $base));
    shopp_localize_script('shopp', '$s', $defaults);
}
示例#5
0
/**
 * Determines if the passed WP_Query object is a Shopp storefront page, Shopp product collection, Shopp product taxonomy, or Shopp product query.
 * Alias for is_shopp_page() with reordered arguments, as it will usually be used for testing parse_query action referenced objects for custom WP_Query loops.
 *
 * @api
 * @since 1.2.1
 *
 * @param WP_Query $wp_query (optional) will use the global wp_query by default if false, or the WP_Query object to evaluation
 * @param string $page (optional) System page name ID for the correct ShoppStorefront page {@see ShoppPages class}
 * @return bool
 **/
function is_shopp_query($wp_query = false, $page = false)
{
    return is_shopp_page($page, $wp_query);
}
示例#6
0
 public function content($content)
 {
     global $wp_query;
     // Make sure this is the main query and it is the thanks page
     if (!$wp_query->is_main_query() || !is_shopp_page('thanks')) {
         return $content;
     }
     ob_start();
     locate_shopp_template(array('thanks.php'), true);
     $content = ob_get_contents();
     ob_end_clean();
     return apply_filters('shopp_thanks', $content);
 }
    /**
     * header()
     * Adds stylesheets necessary for Shopp public shopping pages */
    function header()
    {
        ?>
<link rel='stylesheet' href='<?php 
        echo htmlentities(add_query_arg(array('shopp_lookup' => 'catalog.css', 'ver' => urlencode(SHOPP_VERSION)), get_bloginfo('url')));
        ?>
' type='text/css' />
<link rel='stylesheet' href='<?php 
        echo SHOPP_TEMPLATES_URI;
        ?>
/shopp.css?ver=<?php 
        echo urlencode(SHOPP_VERSION);
        ?>
' type='text/css' />
<link rel='stylesheet' href='<?php 
        echo $this->uri;
        ?>
/core/ui/styles/thickbox.css?ver=<?php 
        echo urlencode(SHOPP_VERSION);
        ?>
' type='text/css' />
<?php 
        $canonurl = $this->canonurls(false);
        if (is_shopp_page('catalog') && !empty($canonurl)) {
            ?>
<link rel='canonical' href='<?php 
            echo $canonurl;
            ?>
' /><?php 
        }
    }
示例#8
0
 /**
  * Provides the context appropriate URL for selecting shipping options
  *
  * @api `shopp('context.property')`
  * @since 1.0
  *
  * @param string         $result  The output
  * @param array          $options The options
  * @param ShoppShiprates $O       The working object
  * @return void
  **/
 public static function url($result, $options, $O)
 {
     return is_shopp_page('checkout') ? Shopp::url(false, 'confirm-order') : Shopp::url(false, 'cart');
 }
 function tag($property, $options = array())
 {
     global $Shopp;
     $menus = array("account" => __("My Account", "Shopp"), "downloads" => __("Downloads", "Shopp"), "history" => __("Order History", "Shopp"), "status" => __("Order Status", "Shopp"), "logout" => __("Logout", "Shopp"));
     // Return strings with no options
     switch ($property) {
         case "url":
             return $Shopp->link('account');
         case "recover-url":
             return add_query_arg('acct', 'recover', $Shopp->link('account'));
         case "process":
             if (isset($_GET['acct'])) {
                 return $_GET['acct'];
             }
             return false;
         case "loggedin":
             return $Shopp->Cart->data->login;
             break;
         case "notloggedin":
             return !$Shopp->Cart->data->login && $Shopp->Settings->get('account_system') != "none";
             break;
         case "login-label":
             $accounts = $Shopp->Settings->get('account_system');
             $label = __('Email Address', 'Shopp');
             if ($accounts == "wordpress") {
                 $label = __('Login Name', 'Shopp');
             }
             if (isset($options['label'])) {
                 $label = $options['label'];
             }
             return $label;
             break;
         case "email-login":
         case "loginname-login":
         case "account-login":
             if (!empty($_POST['account-login'])) {
                 $options['value'] = $_POST['account-login'];
             }
             return '<input type="text" name="account-login" id="account-login"' . inputattrs($options) . ' />';
             break;
         case "password-login":
             if (!empty($_POST['password-login'])) {
                 $options['value'] = $_POST['password-login'];
             }
             return '<input type="password" name="password-login" id="password-login"' . inputattrs($options) . ' />';
             break;
         case "recover-button":
             if (!isset($options['value'])) {
                 $options['value'] = __('Get New Password', 'Shopp');
             }
             return '<input type="submit" name="recover-login" id="recover-button"' . inputattrs($options) . ' />';
             break;
         case "submit-login":
             // Deprecating
         // Deprecating
         case "login-button":
             if (!isset($options['value'])) {
                 $options['value'] = __('Login', 'Shopp');
             }
             if (is_shopp_page('account')) {
                 $string = '<input type="hidden" name="process-login" id="process-login" value="true" />';
             } else {
                 $string = '<input type="hidden" name="process-login" id="process-login" value="false" />';
             }
             $string .= '<input type="submit" name="submit-login" id="submit-login"' . inputattrs($options) . ' />';
             return $string;
             break;
         case "errors-exist":
             $Errors =& ShoppErrors();
             return $Errors->exist(SHOPP_AUTH_ERR);
             break;
         case "login-errors":
             $Errors =& ShoppErrors();
             $result = "";
             if (!$Errors->exist(SHOPP_AUTH_ERR)) {
                 return false;
             }
             $errors = $Errors->get(SHOPP_AUTH_ERR);
             foreach ((array) $errors as $error) {
                 if (!empty($error)) {
                     $result .= '<p class="error">' . $error->message() . '</p>';
                 }
             }
             $Errors->reset();
             return $result;
             break;
         case "menu":
             if (!$this->looping) {
                 reset($this->management);
                 $this->looping = true;
             } else {
                 next($this->management);
             }
             if (current($this->management)) {
                 return true;
             } else {
                 $this->looping = false;
                 reset($this->management);
                 return false;
             }
             break;
         case "management":
             if (array_key_exists('url', $options)) {
                 return add_query_arg('acct', key($this->management), $Shopp->link('account'));
             }
             if (array_key_exists('action', $options)) {
                 return key($this->management);
             }
             return $menus[key($this->management)];
         case "accounts":
             return $Shopp->Settings->get('account_system');
             break;
         case "order-lookup":
             $auth = $Shopp->Settings->get('account_system');
             if ($auth != "none") {
                 return true;
             }
             if (!empty($_POST['vieworder']) && !empty($_POST['purchaseid'])) {
                 require_once "Purchase.php";
                 $Purchase = new Purchase($_POST['purchaseid']);
                 if ($Purchase->email == $_POST['email']) {
                     $Shopp->Cart->data->Purchase = $Purchase;
                     $Purchase->load_purchased();
                     ob_start();
                     include SHOPP_TEMPLATES . "/receipt.php";
                     $content = ob_get_contents();
                     ob_end_clean();
                     return '<div id="shopp">' . $content . '</div>';
                 }
             }
             ob_start();
             include SHOPP_ADMINPATH . "/orders/account.php";
             $content = ob_get_contents();
             ob_end_clean();
             return '<div id="shopp">' . $content . '</div>';
             break;
         case "firstname":
             if ($options['mode'] == "value") {
                 return $this->firstname;
             }
             if (!empty($this->firstname)) {
                 $options['value'] = $this->firstname;
             }
             return '<input type="text" name="firstname" id="firstname"' . inputattrs($options) . ' />';
             break;
         case "lastname":
             if ($options['mode'] == "value") {
                 return $this->lastname;
             }
             if (!empty($this->lastname)) {
                 $options['value'] = $this->lastname;
             }
             return '<input type="text" name="lastname" id="lastname"' . inputattrs($options) . ' />';
             break;
         case "company":
             if ($options['mode'] == "value") {
                 return $this->company;
             }
             if (!empty($this->company)) {
                 $options['value'] = $this->company;
             }
             return '<input type="text" name="company" id="company"' . inputattrs($options) . ' />';
             break;
         case "email":
             if ($options['mode'] == "value") {
                 return $this->email;
             }
             if (!empty($this->email)) {
                 $options['value'] = $this->email;
             }
             return '<input type="text" name="email" id="email"' . inputattrs($options) . ' />';
             break;
         case "loginname":
             if ($options['mode'] == "value") {
                 return $this->loginname;
             }
             if (!empty($this->login)) {
                 $options['value'] = $this->login;
             }
             return '<input type="text" name="login" id="login"' . inputattrs($options) . ' />';
             break;
         case "password":
             if ($options['mode'] == "value") {
                 return strlen($this->password) == 34 ? str_pad('&bull;', 8) : $this->password;
             }
             if (!empty($this->password)) {
                 $options['value'] = $this->password;
             }
             return '<input type="password" name="password" id="password"' . inputattrs($options) . ' />';
             break;
         case "confirm-password":
             if (!empty($this->confirm_password)) {
                 $options['value'] = $this->confirm_password;
             }
             return '<input type="password" name="confirm-password" id="confirm-password"' . inputattrs($options) . ' />';
             break;
         case "phone":
             if ($options['mode'] == "value") {
                 return $this->phone;
             }
             if (!empty($this->phone)) {
                 $options['value'] = $this->phone;
             }
             return '<input type="text" name="phone" id="phone"' . inputattrs($options) . ' />';
             break;
         case "hasinfo":
         case "has-info":
             if (empty($this->info)) {
                 return false;
             }
             if (!$this->looping) {
                 reset($this->info);
                 $this->looping = true;
             } else {
                 next($this->info);
             }
             if (current($this->info)) {
                 return true;
             } else {
                 $this->looping = false;
                 reset($this->info);
                 return false;
             }
             break;
         case "info":
             $info = current($this->info);
             $name = key($this->info);
             $allowed_types = array("text", "password", "hidden", "checkbox", "radio");
             if (empty($options['type'])) {
                 $options['type'] = "hidden";
             }
             if (in_array($options['type'], $allowed_types)) {
                 if ($options['mode'] == "name") {
                     return $name;
                 }
                 if ($options['mode'] == "value") {
                     return $info;
                 }
                 $options['value'] = $info;
                 return '<input type="text" name="info[' . $name . ']" id="customer-info-' . $name . '"' . inputattrs($options) . ' />';
             }
             break;
         case "save-button":
             if (!isset($options['label'])) {
                 $options['label'] = __('Save', 'Shopp');
             }
             $result = '<input type="hidden" name="customer" value="true" />';
             $result .= '<input type="submit" name="save" id="save-button"' . inputattrs($options) . ' />';
             return $result;
             break;
             // Downloads UI tags
         // Downloads UI tags
         case "hasdownloads":
         case "has-downloads":
             return !empty($this->downloads);
             break;
         case "downloads":
             if (empty($this->downloads)) {
                 return false;
             }
             if (!$this->looping) {
                 reset($this->downloads);
                 $this->looping = true;
             } else {
                 next($this->downloads);
             }
             if (current($this->downloads)) {
                 return true;
             } else {
                 $this->looping = false;
                 reset($this->downloads);
                 return false;
             }
             break;
         case "download":
             $download = current($this->downloads);
             $df = get_option('date_format');
             $properties = unserialize($download->properties);
             $string = '';
             if (array_key_exists('id', $options)) {
                 $string .= $download->download;
             }
             if (array_key_exists('purchase', $options)) {
                 $string .= $download->purchase;
             }
             if (array_key_exists('name', $options)) {
                 $string .= $download->name;
             }
             if (array_key_exists('variation', $options)) {
                 $string .= $download->optionlabel;
             }
             if (array_key_exists('downloads', $options)) {
                 $string .= $download->downloads;
             }
             if (array_key_exists('key', $options)) {
                 $string .= $download->dkey;
             }
             if (array_key_exists('created', $options)) {
                 $string .= $download->created;
             }
             if (array_key_exists('total', $options)) {
                 $string .= money($download->total);
             }
             if (array_key_exists('filetype', $options)) {
                 $string .= $properties['mimetype'];
             }
             if (array_key_exists('size', $options)) {
                 $string .= readableFileSize($download->size);
             }
             if (array_key_exists('date', $options)) {
                 $string .= _d($df, mktimestamp($download->created));
             }
             if (array_key_exists('url', $options)) {
                 $string .= SHOPP_PERMALINKS ? $Shopp->shopuri . "download/" . $download->dkey : add_query_arg('shopp_download', $download->dkey, $Shopp->link('account'));
             }
             return $string;
             break;
             // Downloads UI tags
         // Downloads UI tags
         case "haspurchases":
         case "has-purchases":
             $filters = array();
             if (isset($options['daysago'])) {
                 $filters['where'] = "UNIX_TIMESTAMP(o.created) > UNIX_TIMESTAMP()-" . $options['daysago'] * 86400;
             }
             if (empty($Shopp->purchases)) {
                 $this->load_orders($filters);
             }
             return !empty($Shopp->purchases);
             break;
         case "purchases":
             if (!$this->looping) {
                 reset($Shopp->purchases);
                 $Shopp->Cart->data->Purchase = current($Shopp->purchases);
                 $this->looping = true;
             } else {
                 $Shopp->Cart->data->Purchase = next($Shopp->purchases);
             }
             if (current($Shopp->purchases)) {
                 $Shopp->Cart->data->Purchase = current($Shopp->purchases);
                 return true;
             } else {
                 $this->looping = false;
                 return false;
             }
             break;
         case "receipt":
             return add_query_arg(array('acct' => 'receipt', 'id' => $Shopp->Cart->data->Purchase->id), $Shopp->link('account'));
     }
 }