-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-e-commerce-xml-sitemap.php
134 lines (107 loc) · 4.71 KB
/
wp-e-commerce-xml-sitemap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
* Plugin Name: WP Shopping Cart XML Sitemap
* Version: 1.1.5
* Plugin URI: https://www.ademti-software.co.uk/
* Description: Adds entries to XML sitemaps generated by Google XML Sitemaps Generator plugin (http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/). Adds categories and products.
* Author: Ademti Software
* Author URI: https://www.ademti-software.co.uk/
*/
/**
* Copyright (c) 2009-2015 Lee Willis. All rights reserved.
* Copyright (c) 2015-2024 Ademti Software. All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
function ses_wpsc_generate_category_entries () {
global $wpdb, $wp_rewrite, $table_prefix;
if (!defined('WPSC_VERSION') || WPSC_VERSION < 3.7) {
$product_list_table = "{$table_prefix}product_list";
$item_category_assoc_table = "{$table_prefix}item_category_associations";
$product_categories_table = "{$table_prefix}product_categories";
$date_sql = " NULL AS dt ";
$pwhere_sql = "";
} else {
$product_list_table = WPSC_TABLE_PRODUCT_LIST;
$item_category_assoc_table = WPSC_TABLE_ITEM_CATEGORY_ASSOC;
$product_categories_table = WPSC_TABLE_PRODUCT_CATEGORIES;
$date_sql = " UNIX_TIMESTAMP(MAX(p.date_added)) as dt ";
$pwhere_sql = " AND p.publish = 1 ";
}
$wp_rewrite->flush_rules();
$generatorObject = &GoogleSitemapGenerator::GetInstance(); //Please note the "&" sign!
if($generatorObject!=null) {
$sql = $wpdb->prepare("SELECT c.id,
$date_sql
FROM $product_categories_table c,
$item_category_assoc_table cp,
$product_list_table p
WHERE c.id = cp.category_id
AND cp.product_id = p.id
AND c.active = 1
AND p.active = 1
$pwhere_sql
GROUP BY c.id");
$results = $wpdb->get_results($sql);
foreach ($results as $category) {
// generatorObject will escape & to & etc. Unfortunately WPSC has already done that - so un-encode it first
$generatorObject->AddUrl(html_entity_decode(wpsc_category_url($category->id)), $category->dt, "weekly",0.25);
}
}
}
function ses_wpsc_generate_product_entries (){
global $wpdb, $wp_rewrite, $table_prefix;
if (!defined('WPSC_VERSION') || WPSC_VERSION < 3.7) {
$product_list_table = "{$table_prefix}product_list";
$product_rating_table = "{$table_prefix}product_rating";
$date_sql = " NULL AS dt ";
} else {
$product_list_table = WPSC_TABLE_PRODUCT_LIST;
$product_rating_table = WPSC_TABLE_PRODUCT_RATING;
$date_sql = " IF ( MAX(r.time) IS NULL OR UNIX_TIMESTAMP(date_added) > MAX(r.time),
UNIX_TIMESTAMP(date_added),
MAX(r.time)) AS dt ";
$where_sql = " AND publish = 1 ";
}
$wp_rewrite->flush_rules();
$generatorObject = &GoogleSitemapGenerator::GetInstance(); //Please note the "&" sign!
if($generatorObject!=null) {
$sql = $wpdb->prepare("SELECT p.id,
$date_sql
FROM $product_list_table p
LEFT JOIN $product_rating_table r
ON p.id = r.productid
WHERE active = 1
$where_sql
GROUP BY p.id");
$results = $wpdb->get_results($sql);
foreach ($results as $product) {
// generatorObject will escape & to & etc. Unfortunately WPSC has already done that - so un-encode it first
$generatorObject->AddUrl(html_entity_decode(wpsc_product_url($product->id)), $product->dt, "weekly", 0.25);
}
}
}
function ses_wpsc_rebuild_sitemap ($id) {
do_action('sm_rebuild');
}
add_action('sm_buildmap', 'ses_wpsc_generate_product_entries');
add_action('sm_buildmap', 'ses_wpsc_generate_category_entries');
add_action('wpsc_edit_product', 'ses_wpsc_rebuild_sitemap');
add_action('wpsc_rate_product', 'ses_wpsc_rebuild_sitemap');
?>