Ejemplo n.º 1
0
/**
 * Object -> tableau
 * @param Object $object
 * @return array|bool
 */
function ObjectToArray($object)
{
    $xml_array = array();
    for ($object->rewind(); $object->valid(); $object->next()) {
        if (array_key_exists($key = $object->key(), $xml_array)) {
            $key .= '-' . uniqid();
        }
        $vars = get_object_vars($object->current());
        if (isset($vars['@attributes'])) {
            foreach ($vars['@attributes'] as $k => $v) {
                $xml_array[$key][$k] = $v;
            }
        }
        if ($object->hasChildren()) {
            $xml_array[$key][] = ObjectToArray($object->current());
        } else {
            $xml_array[$key][] = strval($object->current());
        }
    }
    return $xml_array;
}
Ejemplo n.º 2
0
function Insert_Product_Catalog($atts)
{
    // Include the required global variables, and create a few new ones
    global $wpdb, $categories_table_name, $subcategories_table_name, $tags_table_name, $tagged_items_table_name, $tag_groups_table_name, $catalogues_table_name, $catalogue_items_table_name, $items_table_name, $fields_meta_table_name, $item_videos_table_name;
    global $ProductString, $ProdCats, $ProdSubCats, $ProdTags, $ProdCustomFields, $ProdCatString, $ProdSubCatString, $ProdTagString, $ProdCustomFieldsString, $Catalogue_ID, $Catalogue_Layout_Format, $Catalogue_Sidebar, $Full_Version, $TagGroupName;
    global $link_base;
    $ProductString = "";
    $Filter = get_option("UPCP_Filter_Type");
    $Color = get_option("UPCP_Color_Scheme");
    $Links = get_option("UPCP_Product_Links");
    $Detail_Image = get_option("UPCP_Details_Image");
    $Pretty_Links = get_option("UPCP_Pretty_Links");
    $Mobile_Style = get_option("UPCP_Mobile_SS");
    $Tag_Logic = get_option("UPCP_Tag_Logic");
    $Links = get_option("UPCP_Product_Links");
    $Pagination_Location = get_option("UPCP_Pagination_Location");
    $CaseInsensitiveSearch = get_option("UPCP_Case_Insensitive_Search");
    $Maintain_Filtering = get_option("UPCP_Maintain_Filtering");
    $Show_Category_Descriptions = get_option("UPCP_Show_Category_Descriptions");
    $Products_Per_Page = get_option("UPCP_Products_Per_Page");
    $ProductSearch = get_option("UPCP_Product_Search");
    $Inner_Filter = get_option("UPCP_Inner_Filter");
    $Pagination_Background = get_option("UPCP_Pagination_Background");
    $Pagination_Border = get_option("UPCP_Pagination_Border");
    $Pagination_Shadow = get_option("UPCP_Pagination_Shadow");
    $Pagination_Gradient = get_option("UPCP_Pagination_Gradient");
    $Pagination_Font = get_option("UPCP_Pagination_Font");
    $Products_Pagination_Label = get_option("UPCP_Products_Pagination_Label");
    $Product_Name_Search_Label = get_option("UPCP_Product_Name_Search_Label");
    $Product_Search_Text_Label = get_option("UPCP_Product_Name_Text_Label");
    $No_Results_Found_Label = get_option("UPCP_No_Results_Found_Label");
    if ($Products_Pagination_Label != "") {
        $Products_Pagination_Text = $Products_Pagination_Label;
    } else {
        $Products_Pagination_Text = __(' products', 'UPCP');
    }
    if ($Product_Name_Search_Label != "") {
        $SearchLabel = $Product_Name_Search_Label;
    } else {
        if ($ProductSearch == "namedesc" or $ProductSearch == "namedesccust") {
            $SearchLabel = __("Product Search14", 'UPCP');
        } else {
            $SearchLabel = __("Product Name:", 'UPCP');
        }
    }
    if ($prod_name != "") {
        $Product_Name_Text = $prod_name;
    } elseif ($Product_Search_Text_Label != "") {
        $Product_Name_Text = $Product_Search_Text_Label;
    } else {
        if ($ProductSearch == "namedesc" or $ProductSearch == "namedesccust") {
            $Product_Name_Text = __("Search...", 'UPCP');
        } else {
            $Product_Name_Text = __("Name...", 'UPCP');
        }
    }
    // Get the attributes passed by the shortcode, and store them in new variables for processing
    extract(shortcode_atts(array("id" => "1", "excluded_layouts" => "None", "starting_layout" => "", "products_per_page" => "", "current_page" => 1, "sidebar" => "Yes", "only_inner" => "No", "ajax_reload" => "No", "ajax_url" => "", "request_count" => 0, "category" => "", "subcategory" => "", "tags" => "", "custom_fields" => "", "prod_name" => "", "link_base" => ""), $atts));
    if ($ajax_reload != "No") {
        $ajax_reload = ucfirst(strtolower($ajax_reload));
    }
    // Select the catalogue information from the database
    $Catalogue = $wpdb->get_row("SELECT * FROM {$catalogues_table_name} WHERE Catalogue_ID=" . $id);
    $CatalogueItems = $wpdb->get_results("SELECT * FROM {$catalogue_items_table_name} WHERE Catalogue_ID=" . $id . " ORDER BY Position");
    // Add any additional CSS in-line
    if ($Catalogue->Catalogue_Custom_CSS != "") {
        $HeaderBar .= "<style type='text/css'>";
        $HeaderBar .= $Catalogue->Catalogue_Custom_CSS;
        $HeaderBar .= "</style>";
    }
    //Add styling options that have been set
    if ($Full_Version == "Yes") {
        $HeaderBar .= UPCP_Add_Modified_Styles();
    }
    if ($Detail_Image != "") {
        $HeaderBar .= "<style type='text/css'>";
        $HeaderBar .= ".upcp-thumb-details-link, .upcp-list-details-link, .upcp-detail-details-link {";
        $HeaderBar .= "background: url('" . $Detail_Image . "');";
        $HeaderBar .= "}";
        $HeaderBar .= "</style>";
    }
    $Top_JS .= "<script language='JavaScript' type='text/javascript'>";
    if ($Maintain_Filtering == "Yes") {
        $Top_JS .= "var maintain_filtering = 'Yes';";
    } else {
        $Top_JS .= "var maintain_filtering = 'No';";
    }
    $Top_JS .= "</script>";
    $HeaderBar .= $Top_JS;
    if ($Links == "New") {
        $Target = "_blank";
    } else {
        $Target = "_self";
    }
    $HeaderBar .= "<form id='upcp-hidden-filtering-form' method='post' target='" . $Target . "'>";
    $HeaderBar .= "<input type='hidden' id='upcp-selected-categories' name='categories' value='" . $_POST['categories'] . "' />";
    $HeaderBar .= "<input type='hidden' id='upcp-selected-subcategories' name='subcategories' value='" . $_POST['subcategories'] . "' />";
    $HeaderBar .= "<input type='hidden' id='upcp-selected-tags' name='tags' value='" . $_POST['tags'] . "' />";
    $HeaderBar .= "<input type='hidden' id='upcp-selected-prod-name' name='prod_name' value='" . $_POST['prod_name'] . "' />";
    $HeaderBar .= "</form>";
    if (get_query_var('single_product') != "" or $_GET['SingleProduct'] != "") {
        $ProductString .= $HeaderBar;
        $ProductString .= SingleProductPage();
        return $ProductString;
    }
    $Catalogue_ID = $id;
    $Catalogue_Sidebar = $sidebar;
    $Starting_Layout = ucfirst($starting_layout);
    if ($excluded_layouts != "None") {
        $Excluded_Layouts = explode(",", $excluded_layouts);
    } else {
        $Excluded_Layouts = array();
    }
    if (isset($_GET['categories'])) {
        $category = explode(",", $_GET['categories']);
    } elseif (isset($_POST['categories']) and $_POST['categories'] != "") {
        $category = explode(",", $_POST['categories']);
    } elseif ($category == "") {
        $category = array();
    } else {
        $category = explode(",", $category);
    }
    if (isset($_GET['sub-categories'])) {
        $subcategory = explode(",", $_GET['sub-categories']);
    } elseif (isset($_POST['subcategories']) and $_POST['subcategories'] != "") {
        $subcategory = explode(",", $_POST['subcategories']);
    } elseif ($subcategory == "") {
        $subcategory = array();
    } else {
        $subcategory = explode(",", $subcategory);
    }
    if (isset($_GET['tags'])) {
        $tags = explode(",", $_GET['tags']);
    } elseif (isset($_POST['tags']) and $_POST['tags'] != "") {
        $tags = explode(",", $_POST['tags']);
    } elseif ($tags == "") {
        $tags = array();
    } else {
        $tags = explode(",", $tags);
    }
    if (isset($_POST['prod_name']) and $_POST['prod_name'] != "") {
        $prod_name = $_POST['prod_name'];
    }
    //Pagination early work
    if ($products_per_page == "") {
        $products_per_page = $Products_Per_Page;
    }
    if ($category != "" or $subcategory != "" or $tags != "" or $prod_name != "") {
        $Filtered = "Yes";
    } else {
        $Filtered = "No";
    }
    $ProductString .= "<div class='upcp-Hide-Item' id='upcp-shortcode-atts'>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-catalogue-id'>" . $id . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-catalogue-sidebar'>" . $sidebar . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-starting-layout'>" . $starting_layout . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-current-layout'>" . $starting_layout . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-exclude-layouts'>" . $excluded_layouts . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-current-page'>" . $current_page . "</div>";
    $ProductString .= "<div class='shortcode-attr' id='upcp-default-search-text'>" . $Product_Name_Text . "</div>";
    if ($ajax_reload == "Yes") {
        $ProductString .= "<div class='shortcode-attr' id='upcp-base-url'>" . $ajax_url . "</div>";
    } else {
        $uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
        //if ($uri_parts[0] != "/") {$ProductString .= "<div class='shortcode-attr' id='upcp-base-url'>" . $uri_parts[0] . "</div>";}
        if (strpos($uri_parts[1], "page_id") === false) {
            $ProductString .= "<div class='shortcode-attr' id='upcp-base-url'>" . $uri_parts[0] . "</div>";
        } else {
            $ProductString .= "<div class='shortcode-attr' id='upcp-base-url'>" . $uri_parts[0] . "?" . $uri_parts[1] . "</div>";
        }
        //else {$ProductString .= "<div class='shortcode-attr' id='upcp-base-url'>/?" . $uri_parts[1] . "</div>";}
    }
    $ProductString .= "</div>";
    if (sizeOf($Excluded_Layouts) > 0) {
        for ($i = 0; $i < sizeOf($Excluded_Layouts); $i++) {
            $ExcludedLayouts[$i] = ucfirst(trim($Excluded_Layouts[$i]));
        }
    } else {
        $ExcludedLayouts = array();
    }
    if ($Starting_Layout == "") {
        if (!in_array("Thumbnail", $Excluded_Layouts)) {
            $Starting_Layout = "Thumbnail";
        } elseif (!in_array("List", $Excluded_Layouts)) {
            $Starting_Layout = "List";
        } else {
            $Starting_Layout = "Detail";
        }
    }
    // Make sure that the layout is set
    if ($layout_format != "Thumbnail" and $layout_format != "List") {
        if ($Catalogue->Catalogue_Layout_Format != "") {
            $format = $Catalogue->Catalogue_Layout_Format;
        } else {
            $format = "Thumbnail";
        }
    } else {
        $format = $layout_format;
    }
    // Arrays to store what categories, sub-categories and tags are applied to the product in the catalogue
    $ProdCats = array();
    $ProdSubCats = array();
    $ProdTags = array();
    $ProdCustomFields = array();
    // If filtering for custom fields, build the field/value query string
    if ($custom_fields != "") {
        $Custom_Field_IDs = explode(",", $custom_fields);
        foreach ($Custom_Field_IDs as $Custom_Field_ID) {
            $Field_ID = substr($Custom_Field_ID, 0, strpos($Custom_Field_ID, "=>"));
            $Field_Value = substr($Custom_Field_ID, strpos($Custom_Field_ID, "=>") + 2);
            $Selected_Custom_Fields[$Field_ID][] = html_entity_decode($Field_Value);
        }
        $Custom_Fields_Sql_String .= "(";
        foreach ($Selected_Custom_Fields as $Field_ID => $Selected_Custom_Field) {
            $Custom_Fields_Sql_String .= "(";
            $Custom_Fields_Sql_String .= "Field_ID='" . $Field_ID . "' AND (";
            foreach ($Selected_Custom_Field as $Value) {
                $Custom_Fields_Sql_String .= "Meta_Value LIKE '" . $Value . "' OR Meta_Value LIKE '" . $Value . ",%' OR Meta_Value LIKE '%," . $Value . ",%' OR Meta_Value LIKE '%," . $Value . "' OR ";
            }
            $Custom_Fields_Sql_String = substr($Custom_Fields_Sql_String, 0, -4);
            $Custom_Fields_Sql_String .= "))";
            $Custom_Fields_Sql_String .= " OR ";
        }
        $Custom_Fields_Sql_String = substr($Custom_Fields_Sql_String, 0, -4);
        $Custom_Fields_Sql_String .= ")";
        $Custom_Field_Count = sizeOf($Selected_Custom_Fields);
    }
    $ProdThumbString .= "<div id='prod-cat-" . $id . "' class='prod-cat thumb-display ";
    if ($Starting_Layout != "Thumbnail") {
        $ProdThumbString .= "hidden-field";
    }
    $ProdThumbString .= "'>\n";
    $ProdThumbString .= "%upcp_pagination_placeholder_top%";
    $ProdListString .= "<div id='prod-cat-" . $id . "' class='prod-cat list-display ";
    if ($Starting_Layout != "List") {
        $ProdListString .= "hidden-field";
    }
    $ProdListString .= "'>\n";
    $ProdListString .= "%upcp_pagination_placeholder_top%";
    $ProdDetailString .= "<div id='prod-cat-" . $id . "' class='prod-cat detail-display ";
    if ($Starting_Layout != "Detail") {
        $ProdDetailString .= "hidden-field";
    }
    $ProdDetailString .= "'>\n";
    $ProdDetailString .= "%upcp_pagination_placeholder_top%";
    $Product_Count = 0;
    foreach ($CatalogueItems as $CatalogueItem) {
        // If the item is a product, then simply call the AddProduct function to add it to the code
        if ($CatalogueItem->Item_ID != "" and $CatalogueItem->Item_ID != 0) {
            $Product = $wpdb->get_row("SELECT * FROM {$items_table_name} WHERE Item_ID=" . $CatalogueItem->Item_ID);
            $ProdTagObj = $wpdb->get_results("SELECT Tag_ID FROM {$tagged_items_table_name} WHERE Item_ID=" . $CatalogueItem->Item_ID);
            if ($ajax_reload == "No") {
                $Prod_Custom_Fields = $wpdb->get_results("SELECT Field_ID, Meta_Value FROM {$fields_meta_table_name} WHERE Item_ID=" . $Product->Item_ID);
            }
            if ($Product->Item_Display_Status != "Hide") {
                if (sizeOf($category) == 0 or in_array($Product->Category_ID, $category)) {
                    if (sizeOf($subcategory) == 0 or in_array($Product->SubCategory_ID, $subcategory)) {
                        $ProdTag = ObjectToArray($ProdTagObj);
                        $Tag_Check = CheckTags($tags, $ProdTag, $Tag_Logic);
                        if ($Tag_Check == "Yes") {
                            $Custom_Field_Check = Custom_Field_Check($Custom_Fields_Sql_String, $Custom_Field_Count, $Product->Item_ID);
                            if ($Custom_Field_Check == "Yes") {
                                $Name_Search_Match = SearchProductName($Product->Item_ID, $Product->Item_Name, $Product->Item_Description, $prod_name, $CaseInsensitiveSearch, $ProductSearch);
                                if ($Name_Search_Match == "Yes") {
                                    $Pagination_Check = CheckPagination($Product_Count, $products_per_page, $current_page, $Filtered);
                                    if ($Pagination_Check == "OK") {
                                        $HeaderBar .= "<a id='hidden_FB_link-" . $Product->Item_ID . "' class='fancybox' href='#prod-cat-addt-details-" . $Product->Item_ID . "'></a>";
                                        if (!in_array("Thumbnail", $ExcludedLayouts)) {
                                            $ProdThumbString .= AddProduct("Thumbnail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                        }
                                        if (!in_array("List", $ExcludedLayouts)) {
                                            $ProdListString .= AddProduct("List", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                        }
                                        if (!in_array("Detail", $ExcludedLayouts)) {
                                            $ProdDetailString .= AddProduct("Detail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                        }
                                    }
                                    $Product_Count++;
                                }
                            }
                        }
                    }
                }
            }
            if ($ajax_reload == "No") {
                FilterCount($Product, $ProdTagObj, $Prod_Custom_Fields);
            }
            unset($NameSearchMatch);
        }
        // If the item is a category, then add the appropriate extra HTML and call the AddProduct function
        // for each individual product in the category
        if ($CatalogueItem->Category_ID != "" and $CatalogueItem->Category_ID != 0) {
            if (sizeOf($category) == 0 or in_array($CatalogueItem->Category_ID, $category)) {
                $CatProdCount = 0;
                $Category = $wpdb->get_row("SELECT Category_Name, Category_Description FROM {$categories_table_name} WHERE Category_ID=" . $CatalogueItem->Category_ID);
                $ProdThumbString .= "<div id='prod-cat-category-" . $CatalogueItem->Category_ID . "' class='prod-cat-category upcp-thumb-category'>\n";
                $ProdListString .= "<div id='prod-cat-category-" . $CatalogueItem->Category_ID . "' class='prod-cat-category upcp-list-category'>\n";
                $ProdDetailString .= "<div id='prod-cat-category-" . $CatalogueItem->Category_ID . "' class='prod-cat-category upcp-detail-category'>\n";
                $ProdThumbString .= "%Category_Label%";
                $ProdListString .= "%Category_Label%";
                $ProdDetailString .= "%Category_Label%";
                $CatThumbHead = "<div id='prod-cat-category-label-" . $CatalogueItem->Category_ID . "' class='prod-cat-category-label upcp-thumb-category-label'><div class='prod-cat-category-name'>" . $Category->Category_Name . "</div>";
                if ($Show_Category_Descriptions == "Yes") {
                    $CatThumbHead .= "<div class='prod-cat-category-description'>" . $Category->Category_Description . "</div></div>\n";
                } else {
                    $CatThumbHead .= "</div>\n";
                }
                $CatListHead = "<div id='prod-cat-category-label-" . $CatalogueItem->Category_ID . "' class='prod-cat-category-label upcp-list-category-label'><div class='prod-cat-category-name'>" . $Category->Category_Name . "</div>";
                if ($Show_Category_Descriptions == "Yes") {
                    $CatListHead .= "<div class='prod-cat-category-description'>" . $Category->Category_Description . "</div></div>\n";
                } else {
                    $CatListHead .= "</div>\n";
                }
                $CatDetailHead = "<div id='prod-cat-category-label-" . $CatalogueItem->Category_ID . "' class='prod-cat-category-label upcp-detail-category-label'><div class='prod-cat-category-name'>" . $Category->Category_Name . "</div>";
                if ($Show_Category_Descriptions == "Yes") {
                    $CatDetailHead .= "<div class='prod-cat-category-description'>" . $Category->Category_Description . "</div></div>\n";
                } else {
                    $CatDetailHead .= "</div>\n";
                }
            }
            $Products = $wpdb->get_results("SELECT * FROM {$items_table_name} WHERE Category_ID=" . $CatalogueItem->Category_ID . " ORDER BY Item_Category_Product_Order");
            foreach ($Products as $Product) {
                $ProdTagObj = $wpdb->get_results("SELECT Tag_ID FROM {$tagged_items_table_name} WHERE Item_ID=" . $Product->Item_ID);
                if ($ajax_reload == "No") {
                    $Prod_Custom_Fields = $wpdb->get_results("SELECT Field_ID, Meta_Value FROM {$fields_meta_table_name} WHERE Item_ID=" . $Product->Item_ID);
                }
                if ($Product->Item_Display_Status != "Hide") {
                    if (sizeOf($category) == 0 or in_array($Product->Category_ID, $category)) {
                        if (sizeOf($subcategory) == 0 or in_array($Product->SubCategory_ID, $subcategory)) {
                            $ProdTag = ObjectToArray($ProdTagObj);
                            $Tag_Check = CheckTags($tags, $ProdTag, $Tag_Logic);
                            if ($Tag_Check == "Yes") {
                                $Custom_Field_Check = Custom_Field_Check($Custom_Fields_Sql_String, $Custom_Field_Count, $Product->Item_ID);
                                if ($Custom_Field_Check == "Yes") {
                                    $Name_Search_Match = SearchProductName($Product->Item_ID, $Product->Item_Name, $Product->Item_Description, $prod_name, $CaseInsensitiveSearch, $ProductSearch);
                                    if ($Name_Search_Match == "Yes") {
                                        $Pagination_Check = CheckPagination($Product_Count, $products_per_page, $current_page, $Filtered);
                                        if ($Pagination_Check == "OK") {
                                            $HeaderBar .= "<a id='hidden_FB_link-" . $Product->Item_ID . "' class='fancybox' href='#prod-cat-addt-details-" . $Product->Item_ID . "'></a>";
                                            if (!in_array("Thumbnail", $ExcludedLayouts)) {
                                                $ProdThumbString .= AddProduct("Thumbnail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                            }
                                            if (!in_array("List", $ExcludedLayouts)) {
                                                $ProdListString .= AddProduct("List", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                            }
                                            if (!in_array("Detail", $ExcludedLayouts)) {
                                                $ProdDetailString .= AddProduct("Detail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                            }
                                            $CatProdCount++;
                                        }
                                        $Product_Count++;
                                    }
                                }
                            }
                        }
                    }
                }
                if ($ajax_reload == "No") {
                    FilterCount($Product, $ProdTagObj, $Prod_Custom_Fields);
                }
                unset($NameSearchMatch);
            }
            if (sizeOf($category) == 0 or in_array($CatalogueItem->Category_ID, $category)) {
                if ($CatProdCount > 0) {
                    $ProdThumbString = str_replace("%Category_Label%", $CatThumbHead, $ProdThumbString);
                    $ProdListString = str_replace("%Category_Label%", $CatListHead, $ProdListString);
                    $ProdDetailString = str_replace("%Category_Label%", $CatDetailHead, $ProdDetailString);
                } else {
                    $ProdThumbString = str_replace("%Category_Label%", "", $ProdThumbString);
                    $ProdListString = str_replace("%Category_Label%", "", $ProdListString);
                    $ProdDetailString = str_replace("%Category_Label%", "", $ProdDetailString);
                }
                $ProdThumbString .= "</div>";
                $ProdListString .= "</div>";
                $ProdDetailString .= "</div>";
            }
        }
        // If the item is a sub-category, then add the appropriate extra HTML and call the AddProduct function
        // for each individual product in the sub-category
        if ($CatalogueItem->SubCategory_ID != "" and $CatalogueItem->SubCategory_ID != 0) {
            if (sizeOf($subcategory) == 0 or in_array($CatalogueItem->SubCategory_ID, $subcategory)) {
                $Products = $wpdb->get_results("SELECT * FROM {$items_table_name} WHERE SubCategory_ID=" . $CatalogueItem->SubCategory_ID);
                foreach ($Products as $Product) {
                    $ProdTagObj = $wpdb->get_results("SELECT Tag_ID FROM {$tagged_items_table_name} WHERE Item_ID=" . $CatalogueItem->Item_ID);
                    if ($ajax_reload == "No") {
                        $Prod_Custom_Fields = $wpdb->get_results("SELECT Field_ID, Meta_Value FROM {$fields_meta_table_name} WHERE Item_ID=" . $Product->Item_ID);
                    }
                    if ($Product->Item_Display_Status != "Hide") {
                        if (sizeOf($category) == 0 or in_array($Product->Category_ID, $category)) {
                            if (sizeOf($subcategory) == 0 or in_array($Product->SubCategory_ID, $subcategory)) {
                                $ProdTag = ObjectToArray($ProdTagObj);
                                $Tag_Check = CheckTags($tags, $ProdTag, $Tag_Logic);
                                if ($Tag_Check == "Yes") {
                                    $Custom_Field_Check = Custom_Field_Check($Custom_Fields_Sql_String, $Custom_Field_Count, $Product->Item_ID);
                                    if ($Custom_Field_Check == "Yes") {
                                        $Name_Search_Match = SearchProductName($Product->Item_ID, $Product->Item_Name, $Product->Item_Description, $prod_name, $CaseInsensitiveSearch, $ProductSearch);
                                        if ($Name_Search_Match == "Yes") {
                                            $Pagination_Check = CheckPagination($Product_Count, $products_per_page, $current_page, $Filtered);
                                            if ($Pagination_Check == "OK") {
                                                $HeaderBar .= "<a id='hidden_FB_link-" . $Product->Item_ID . "' class='fancybox' href='#prod-cat-addt-details-" . $Product->Item_ID . "'></a>";
                                                if (!in_array("Thumbnail", $ExcludedLayouts)) {
                                                    $ProdThumbString .= AddProduct("Thumbnail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                                }
                                                if (!in_array("List", $ExcludedLayouts)) {
                                                    $ProdListString .= AddProduct("List", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                                }
                                                if (!in_array("Detail", $ExcludedLayouts)) {
                                                    $ProdDetailString .= AddProduct("Detail", $Product->Item_ID, $Product, $ProdTagObj, $ajax_reload, $ajax_url);
                                                }
                                            }
                                            $Product_Count++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($ajax_reload == "No") {
                        FilterCount($Product, $ProdTagObj, $Prod_Custom_Fields);
                    }
                    unset($NameSearchMatch);
                }
            }
        }
        //if ($Pagination_Check == "Over") {break;}
    }
    if ($Product_Count == 0) {
        $ProdThumbString .= $No_Results_Found_Label;
        $ProdListString .= $No_Results_Found_Label;
        $ProdDetailString .= $No_Results_Found_Label;
    }
    $ProdThumbString .= "<div class='upcp-clear'></div>\n";
    $ProdListString .= "<div class='upcp-clear'></div>\n";
    $ProdDetailString .= "<div class='upcp-clear'></div>\n";
    if ($Pagination_Location == "Bottom" or $Pagination_Location == "Both") {
        $ProdThumbString .= "%upcp_pagination_placeholder_bottom%";
        $ProdListString .= "%upcp_pagination_placeholder_bottom%";
        $ProdDetailString .= "%upcp_pagination_placeholder_bottom%";
        /*$ProdThumbString .= "<div class='upcp-clear'></div>\n";
        		$ProdListString .= "<div class='upcp-clear'></div>\n";
        		$ProdDetailString .= "<div class='upcp-clear'></div>\n";*/
    }
    $ProdThumbString .= "</div>\n";
    $ProdListString .= "</div>\n";
    $ProdDetailString .= "</div>\n";
    if (in_array("Thumbnail", $ExcludedLayouts)) {
        unset($ProdThumbString);
    }
    if (in_array("List", $ExcludedLayouts)) {
        unset($ProdListString);
    }
    if (in_array("Detail", $ExcludedLayouts)) {
        unset($ProdDetailString);
    }
    //Deal with creating the page counter, if pagination is neccessary
    if ($Filtered == "Yes") {
        $Total_Products = $Product_Count;
    } else {
        $Total_Products = $Catalogue->Catalogue_Item_Count;
    }
    if ($Total_Products > $products_per_page) {
        $Num_Pages = ceil($Total_Products / $products_per_page);
        $PrevPage = max($current_page - 1, 1);
        $NextPage = min($current_page + 1, $Num_Pages);
        $PaginationString .= "<div class='catalogue-nav ";
        $PaginationString .= "upcp-cat-nav-bg-" . $Pagination_Background . " ";
        $PaginationString .= "upcp-cat-nav-border-" . $Pagination_Border . " ";
        $PaginationString .= "upcp-cat-nav-" . $Pagination_Shadow . " ";
        $PaginationString .= "upcp-cat-nav-" . $Pagination_Gradient . " ";
        $PaginationString .= "'>";
        $PaginationString .= "<span class='displaying-num'>" . $Total_Products . $Products_Pagination_Text . "</span>";
        $PaginationString .= "<span class='pagination-links'>";
        $PaginationString .= "<a class='first-page' title='Go to the first page' href='#' onclick='UPCP_DisplayPage(\"1\")'>&#171;</a>";
        $PaginationString .= "<a class='prev-page' title='Go to the previous page' href='#' onclick='UPCP_DisplayPage(\"" . $PrevPage . "\")'>&#8249;</a>";
        $PaginationString .= "<span class='paging-input'>" . $current_page . __(' of ', 'UPCP') . "<span class='total-pages'>" . $Num_Pages . "</span></span>";
        $PaginationString .= "<a class='next-page' title='Go to the next page' href='#' onclick='UPCP_DisplayPage(\"" . $NextPage . "\")'>&#8250;</a>";
        $PaginationString .= "<a class='last-page' title='Go to the last page' href='#' onclick='UPCP_DisplayPage(\"" . $Num_Pages . "\")'>&#187;</a>";
        $PaginationString .= "</span>";
        $PaginationString .= "</div>";
        if ($current_page == 1) {
            $PaginationString = str_replace("first-page", "first-page disabled", $PaginationString);
        }
        if ($current_page == 1) {
            $PaginationString = str_replace("prev-page", "prev-page disabled", $PaginationString);
        }
        if ($current_page == $Num_Pages) {
            $PaginationString = str_replace("next-page", "next-page disabled", $PaginationString);
        }
        if ($current_page == $Num_Pages) {
            $PaginationString = str_replace("last-page", "last-page disabled", $PaginationString);
        }
        /*if ($current_page != 1) {$PaginationString .= "<a href='#' onclick='UPCP_DisplayPage(\"1\")>" . __('First', 'UPCP') . "</a>";}
        		if ($current_page != 1) {$PaginationString .= "<a href='#' onclick='UPCP_DisplayPage(\"" . $current_page - 1 . "\")>" . __('Previous', 'UPCP') . "</a>";}
        				
        		$PaginationString .= "<span class='paging-input'>" . $current_page . __(' of ', 'UPCP') . "<span class='total-pages'>" . $Num_Pages . "</span></span>";
        				
        		if ($current_page != $Num_Pages) {$PaginationString .= "<a href='#' onclick='UPCP_DisplayPage(\"" . $current_page + 1 . "\")>" . __('Next', 'UPCP') . "</a>";}
        		if ($current_page != $Num_Pages) {$PaginationString .= "<a href='#' onclick='UPCP_DisplayPage(\"" . $Num_Pages . "\")>" . __('Last', 'UPCP') . "</a>";}*/
    }
    if ($Pagination_Location == "Bottom") {
        $ProdThumbString = str_replace("%upcp_pagination_placeholder_top%", "", $ProdThumbString);
        $ProdListString = str_replace("%upcp_pagination_placeholder_top%", "", $ProdListString);
        $ProdDetailString = str_replace("%upcp_pagination_placeholder_top%", "", $ProdDetailString);
    }
    if ($Pagination_Location == "Top") {
        $ProdThumbString = str_replace("%upcp_pagination_placeholder_bottom%", "", $ProdThumbString);
        $ProdListString = str_replace("%upcp_pagination_placeholder_bottom%", "", $ProdListString);
        $ProdDetailString = str_replace("%upcp_pagination_placeholder_bottom%", "", $ProdDetailString);
    }
    $ProdThumbString = str_replace("%upcp_pagination_placeholder_top%", $PaginationString, $ProdThumbString);
    $ProdListString = str_replace("%upcp_pagination_placeholder_top%", $PaginationString, $ProdListString);
    $ProdDetailString = str_replace("%upcp_pagination_placeholder_top%", $PaginationString, $ProdDetailString);
    $ProdThumbString = str_replace("%upcp_pagination_placeholder_bottom%", $PaginationString, $ProdThumbString);
    $ProdListString = str_replace("%upcp_pagination_placeholder_bottom%", $PaginationString, $ProdListString);
    $ProdDetailString = str_replace("%upcp_pagination_placeholder_bottom%", $PaginationString, $ProdDetailString);
    // Create string from the arrays, should use the implode function instead
    foreach ($ProdCats as $key => $value) {
        $ProdCatString .= $key . ",";
    }
    $ProdCatString = trim($ProdCatString, " ,");
    foreach ($ProdSubCats as $key => $value) {
        $ProdSubCatString .= $key . ",";
    }
    $ProdSubCatString = trim($ProdSubCatString, " ,");
    foreach ($ProdTags as $key => $value) {
        $ProdTagString .= $key . ",";
    }
    $ProdTagString = trim($ProdTagString, " ,");
    foreach ($ProdCustomFields as $key => $value) {
        $ProdCustomFieldsString .= $key . ",";
    }
    $ProdCustomFieldsString = trim($ProdCustomFieldsString, " ,");
    // If the sidebar is requested, add it
    if (($sidebar == "Yes" or $sidebar == "yes" or $sidebar == "YES") and $only_inner != "Yes") {
        $SidebarString = BuildSidebar($category, $subcategory, $tags, $prod_name);
    }
    if ($Mobile_Style == "Yes") {
        $MobileMenuString .= "<div id='prod-cat-mobile-menu' class='upcp-mobile-menu'>\n";
        $MobileMenuString .= "<div id='prod-cat-mobile-search'>\n";
        if ($Tag_Logic == "OR") {
            $MobileMenuString .= "<input type='text' id='upcp-mobile-search' class='jquery-prod-name-text mobile-search' name='Mobile_Search' value='" . __('Product Name', 'UPCP') . "...' onfocus='FieldFocus(this);' onblur='FieldBlur(this);' onkeyup='UPCP_Filer_Results_OR();'>\n";
        } else {
            $MobileMenuString .= "<input type='text' id='upcp-mobile-search' class='jquery-prod-name-text mobile-search' name='Mobile_Search' value='" . __('Product Name', 'UPCP') . "...' onfocus='FieldFocus(this);' onblur='FieldBlur(this);'  onkeyup='UPCP_Filer_Results();'>\n";
        }
        $MobileMenuString .= "</div>";
        $MobileMenuString .= "</div>";
    }
    $HeaderBar .= "<div class='prod-cat-header-div " . $Color . "-prod-cat-header-div'>";
    $HeaderBar .= "<div class='prod-cat-header-padding'></div>";
    $HeaderBar .= "<div id='starting-layout' class='hidden-field'>" . $Starting_Layout . "</div>";
    if (!in_array("Thumbnail", $ExcludedLayouts)) {
        $HeaderBar .= "<a href='#' onclick='ToggleView(\"Thumbnail\");return false;' title='Thumbnail'><div class='upcp-thumb-toggle-icon " . $Color . "-thumb-icon'></div></a>";
    }
    if (!in_array("List", $ExcludedLayouts)) {
        $HeaderBar .= "<a href='#' onclick='ToggleView(\"List\"); return false;' title='List'><div class='upcp-list-toggle-icon " . $Color . "-list-icon'></div></a>";
    }
    if (!in_array("Detail", $ExcludedLayouts)) {
        $HeaderBar .= "<a href='#' onclick='ToggleView(\"Detail\"); return false;' title='Detail'><div class='upcp-details-toggle-icon " . $Color . "-details-icon'></div></a>";
    }
    $HeaderBar .= "<div class='upcp-clear'></div>";
    $HeaderBar .= "</div>";
    $Bottom_JS .= "<script language='JavaScript' type='text/javascript'>";
    if (isset($_GET['Product_ID'])) {
        $Bottom_JS .= "jQuery(window).load(OpenProduct('" . $_GET['Product_ID'] . "'));";
    }
    $Bottom_JS .= "</script>";
    if ($only_inner != "Yes") {
        $InnerString .= "<div class='prod-cat-inner'>";
    }
    $InnerString .= $ProdThumbString . "<div class='upcp-clear'></div>" . $ProdListString . "<div class='upcp-clear'></div>" . $ProdDetailString . "<div class='upcp-clear'></div>";
    if ($only_inner != "Yes") {
        $InnerString .= "</div>";
    }
    if (function_exists("mb_convert_encoding")) {
        $InnerString = mb_convert_encoding($InnerString, 'UTF-8');
    } else {
        $InnerString = htmlspecialchars_decode(utf8_decode(htmlentities($InnerString, ENT_COMPAT, 'utf-8', false)));
    }
    if ($only_inner == "Yes") {
        if ($Inner_Filter == "Yes") {
            $InnerString = apply_filters('the_content', $InnerString);
        }
        $ReturnArray['request_count'] = $request_count;
        $ReturnArray['message'] = $InnerString;
        $PHP_Version = UPCP_Return_PHP_Version();
        if ($PHP_Version > 50300) {
            return json_encode($ReturnArray, JSON_UNESCAPED_UNICODE);
        } else {
            return json_encode($ReturnArray);
        }
    }
    $ProductString .= "<div class='prod-cat-container'>";
    $ProductString .= $HeaderBar;
    $ProductString .= $MobileMenuString;
    $ProductString .= $SidebarString;
    $ProductString .= $InnerString;
    $ProductString .= $Bottom_JS;
    $ProductString .= "<div class='upcp-clear'></div></div>";
    return $ProductString;
}
Ejemplo n.º 3
0
function ObjectToArray($obj)
{
    $retval = array();
    foreach ($obj as $key => $value) {
        if (is_array($value) || is_object($value)) {
            $retval[$key] = ObjectToArray($value);
        } else {
            $retval[$key] = $value;
        }
    }
    return $retval;
}