require_once('includes/global_client.inc.php');
require_once('includes/xml_parser.class.php');
$plugin_config_xml_parser = new xml_parser('/xml/'.WEBSITE_ID.'/plugin_config.xml');
$plugin_config=$plugin_config_xml_parser->xml_output['GenericPluginConfig']['PREMProducts'];
header('Content-Type: text/xml');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
if(!isset($db_search)) {
require_once('includes/dbconnect.class.php');
$db_search= new db_search();
}
$edit_page_form_data = db_search::sp_execute('dbo.DCExp_System_Website_CustomXMLSitemap', '@WebsiteID', WEBSITE_ID, 'SQLINT4');
if(!empty($edit_page_form_data[0]['CustomXMLSiteMap'])) {
$xml_output = $edit_page_form_data[0]['CustomXMLSiteMap'];
} else {
$sitemap_data = db_search::sp_execute('DCExp_Client_GoogleSiteMap_Build_XML', '@WebsiteID', WEBSITE_ID, 'SQLINT4');
$xml_output = ''."\n";
$xml_output .= ''."\n";
foreach($sitemap_data as $sitemap_page) {
$lastModPage = !empty($sitemap_page['LastUpdatedDateTime']) ? $sitemap_page['LastUpdatedDateTime'] : $sitemap_page['CreatedDateTime'];
$createdPage = !empty($sitemap_page['CreatedDateTime']) ? $sitemap_page['CreatedDateTime'] : '';
$xml_output.="\t\n";
$website_domain_count = count(explode('.', $sitemap_page['WebsiteDomainName']));
if($website_domain_count==2){
$www = 'www.';
} else {
$www = '';
}
$primary_domain = (explode(',', $sitemap_page['WebsiteDomainName']));
if(is_array($primary_domain)){
$primary_domain = $primary_domain[0];
} else {
$primary_domain = $$primary_domain;
}
$xml_output.="\t\thttps://".$www.$primary_domain.'/'.$sitemap_page['URLAddress']."\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($lastModPage))."\n";
$xml_output.="\t\tweekly\n";
$xml_output.="\t\t0.8\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($createdPage))."\n";
$xml_output.="\t\n";
}
$product_page = 1;
$product_recsperpage = 10000;
$product_whereclause = ' DCEcomm_Products.SystemClientID = '.CLIENT_ID.' ';
$product_order_by = ' CreatedDateTime DESC ';
$sitemap_product_data = db_search::sp_execute('DCEcomm_Client_Product_Search', '@Page||@RecsPerPage||@WhereClause||@OrderBy', $product_page.'||'.$product_recsperpage.'||'.$product_whereclause.'||'.$product_order_by, 'SQLINT4||SQLINT4||SQLVARCHAR||SQLVARCHAR');
if($sitemap_product_data){
foreach($sitemap_product_data as $sitemap_product) {
$lastModProd = !empty($sitemap_product['LastUpdatedDateTime']) ? $sitemap_product['LastUpdatedDateTime'] : $sitemap_product['CreatedDateTime'];
$createdProd = !empty($sitemap_product['CreatedDateTime']) ? $sitemap_product['CreatedDateTime'] : '';
$xml_output.="\t\n";
$sitemap_product_url = buildProductDetailPath($sitemap_product,$plugin_config);
$xml_output.="\t\thttps://".$www.$primary_domain.$sitemap_product_url."\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($lastModProd))."\n";
$xml_output.="\t\tweekly\n";
$xml_output.="\t\t0.5\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($createdProd))."\n";
$xml_output.="\t\n";
}
}
$blog_page = 1;
$blog_recsperpage = 10000;
$blog_whereclause = ' ';
$blog_order_by = ' CreatedDateTime DESC ';
$sitemap_blog_data = db_search::sp_execute('DCExp_Client_Blog_List', '@SystemClientID||@WebsiteID||@Page||@RecsPerPage||@WhereClause', CLIENT_ID.'||'.WEBSITE_ID.'||'.$blog_page.'||'.$blog_recsperpage.'||'.$blog_whereclause, 'SQLINT4||SQLINT4||SQLINT4||SQLINT4||SQLVARCHAR');
if($sitemap_blog_data){
foreach($sitemap_blog_data as $sitemap_blog) {
$lastMod = !empty($sitemap_blog['LastUpdatedDateTime']) ? $sitemap_blog['LastUpdatedDateTime'] : $sitemap_blog['CreatedDateTime'];
$cretedBlog = !empty($sitemap_blog['CreatedDateTime']) ? $sitemap_blog['CreatedDateTime'] : '';
if(empty($lastMod)) {
$lastMod = $sitemap_blog['PublishOnDate'];
}
if(empty($cretedBlog)) {
$cretedBlog = $sitemap_blog['PublishOnDate'];
}
$xml_output.="\t\n";
$blogpost_date_for_url = fix_date( $sitemap_blog['PublishOnDate'],"Y/m/d" );
$sitemap_blog_url = '/'.$blogpost_date_for_url.'/blogpost/'.$sitemap_blog['Permalink'].'/';
$xml_output.="\t\thttps://".$www.$primary_domain.$sitemap_blog_url."\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($lastMod))."\n";
$xml_output.="\t\tweekly\n";
$xml_output.="\t\t0.3\n";
$xml_output.="\t\t".date('Y-m-d',strtotime($cretedBlog))."\n";
$xml_output.="\t\n";
}
}
$xml_output.='';
}
echo trim($xml_output);
function buildProductDetailPath( $product,$plugin_config ) {
$product_detail_path = '';
if( isset( $product['ProductDetailsCustomURL'] ) ){
$product_custom_path = $product['ProductDetailsCustomURL'];
} else {
$product_custom_path = '0';
}
if($product['ProductPermaLink']!=''){
$product_detail_path = '/'.str_replace( '&', '-and-', $product['ProductPermaLink']).$plugin_config['ProductsDetailsUniqueURLPrefix'].$product['ProductID'].'/';
return $product_detail_path;
} else {
if( $product_custom_path=='' || $product_custom_path=='0' ){
$product_detail_path = '';
$product_detail_path_raw = str_replace( ' ', '-', ( strtolower( $product['ProductName'] ) ) ) ;
$product_detail_path_raw = str_replace( '/', '-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '%', '-percent-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '&', '-and-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '?', '', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '"', '', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( "'", '', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '(', '', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '®', '-trademark-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '', '-sup-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '<-sup>', '-endsup-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '<;->', '-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '$', '-dollar-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '+', '-plus-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( ':', '-colon-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '.', '-point-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( ';', '-semicolon-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( ')', '', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '----', '-', ( $product_detail_path_raw ) ) ;
$product_detail_path_raw = str_replace( '---', '-', ( $product_detail_path_raw ) ) ;
$product_detail_path = str_replace( '--', '-', ( $product_detail_path_raw ) ) ;
if(isset($plugin_config['ProductsDetailsUniqueURLPrefix'])){
$unique_url_prefix = $plugin_config['ProductsDetailsUniqueURLPrefix'];
} else {
$unique_url_prefix = '/ecomm-product-detail/';
}
if( isset($product['CleanColorID'] ) ){
$product_detail_path .= $unique_url_prefix.$product['CleanColorID'].'/'.$product['ProductID'].'/';
} else {
$product_detail_path .= $unique_url_prefix.$product['ProductID'].'/';
}
} else {
$product_detail_path = '/'.$product_custom_path;
}
if($product_custom_path=='0'){
return '/'.$product_detail_path;
} else {
return '/'.$product_custom_path;
}
}
}
?>