Datafeed HikaShop
";
echo "script version " . $script_version . "
";
exit;
}
// Set no time limit only if php is not running in Safe Mod
if (!@ini_get("safe_mode")) {
if (function_exists('set_time_limit')) {
@set_time_limit(0);
}
if ((int)substr(@ini_get("memory_limit"), 0, -1) < 512) {
@ini_set("memory_limit", "512M");
}
}
ignore_user_abort();
error_reporting(E_ALL^E_NOTICE);
$_SVR = array();
##### Include configuration files ################################################
define ( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
$hasShipping = false;
if (!file_exists(JPATH_BASE .DS.'includes'.DS.'defines.php')) {
echo("An include file not found. Check the path.");
}
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
include_once('administrator/components/com_hikashop/helpers/helper.php');
// Print current Script version
if (@$_GET['get'] == "vm_version") {
echo "VM version " . vmVersion::$RELEASE . "
";
exit;
}
####################################################################
// Datafeed specific settings
$datafeed_separator = "|"; // Possible options are \t or |
##### Extract params from url ################################################
$apply_taxes = (@$_GET['taxes'] == "off") ? "off" : "on";
$apply_storetaxes = (@$_GET['storetaxes'] == "off") ? "off" : "on";
$apply_discount = (@$_GET['discount'] == "off") ? "off" : "on";
$add_vat = (@$_GET['add_vat'] == "on") ? "on" : "off";
$vat_value = (@$_GET['vat_value'] > 0) ? ((100 + $_GET['vat_value']) / 100) : 1.24; // default value
$add_shipping = (@$_GET['shipping'] == "on") ? "on" : "off";
$add_availability = (@$_GET['availability'] == "off") ? "off" : "on";
$add_gtin = (@$_GET['gtin'] == "off") ? "off" : "on";
$add_tagging = (@$_GET['add_tagging'] == "off") ? "off" : "on";
$tagging_params = (@$_GET['tagging_params'] != "") ? urldecode($_GET['tagging_params']) : "utm_source=shopmania&utm_medium=cpc&utm_campaign=direct_link";
$show_description = (@$_GET['description'] == "off") ? "off" : ((@$_GET['description'] == "limited") ? "limited" : "on");
$show_image = (@$_GET['image'] == "off" || @$_GET['images'] == "off") ? "off" : "on";
$show_manufacturer = (@$_GET['manufacturer'] == "off") ? "off" : "on";
$show_specialprice = (@$_GET['specialprice'] == "off") ? "off" : "on";
$sef = (@$_GET['sef'] == "on") ? "on" : "off";
$on_stock_only = (@$_GET['on_stock'] == "on") ? "on" : "off";
$use_currency = (@$_GET['currency'] != "") ? strtoupper($_GET['currency']) : "";
$force_path = (@$_GET['forcepath'] == "on") ? "on" : "off";
$use_shoppergroup = (@$_GET['use_shoppergroup'] == "off") ? "off" : "on";
$use_path = (@$_GET['usepath'] != "") ? $_GET['usepath'] : "";
$force_folder = (@$_GET['forcefolder'] != "") ? $_GET['forcefolder'] : "";
$limit = (@$_GET['limit'] > 0) ? $_GET['limit'] : "";
$encoding = (@$_GET['encoding'] != "") ? $_GET['encoding'] : "";
$cat_order = (@$_GET['cat_order'] == "on") ? "on" : "off";
$display_currency = (@$_GET['display_currency'] != "") ? $_GET['display_currency'] : "";
####################################################################
// Get system configuration.
$JCONFIG = new JConfig();
$config = hikashop_config();
$db = JFactory::getDBO();
$base_img_path = JURI::base();
$base_path = ($use_path != "") ? $use_path : (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'];
// Print URL options
if (@$_GET['get'] == "options") {
$script_basepath = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo "Datafeed HikaShop
";
echo "script version " . $script_version . "
";
echo "Show vm version
";
/*echo "Taxes options - possible values on, off default value on
";
echo "taxes=on (on,off) " . $script_basepath . "?taxes=off" . "
";
echo "Store taxes options - possible values on, off default value on
";
echo "storetaxes = on (on,off) " . $script_basepath . "?storetaxes=off" . "
";
echo "Discount options - possible values on, off default value on
";
echo "discount=on (on,off) " . $script_basepath . "?discount=off" . "
";
*/
echo "Add VAT to prices - possible values on, off default value off
";
echo "add_vat=off (on,off) " . $script_basepath . "?add_vat=on" . "
";
echo "VAT value - possible values percent value default value 24 - interger or float number ex 19 or 19.5
";
echo "vat_value=24 (VAT_VALUE) " . $script_basepath . "?add_vat=on&vat_value=19" . "
";
//echo "Add shipping to datafeed - possible values on, off default value off
";
//echo "shipping=off (on,off) " . $script_basepath . "?shipping=on" . "
";
//echo "Add availability to datafeed - possible values on, off default value on
";
//echo "availability=on (on,off) " . $script_basepath . "?availability=off" . "
";
//echo "Add GTIN to datafeed - possible values on, off default value on
";
//echo "gtin=on (on,off) " . $script_basepath . "?gtin=off" . "
";
echo "Add GA Tagging to product URL - possible values on, off default value on
";
echo "add_tagging=on (on,off) " . $script_basepath . "?add_tagging=off" . "
";
echo "Add custom Tagging to product URL - possible values url_encode(TAGGING_PARAMS) default value tagging_params=utm_source=shopmania&utm_medium=cpc&utm_campaign=direct_link
";
echo "tagging_params=utm_source=shopmania&utm_medium=cpc&utm_campaign=direct_link (TAGGING_PARAMS) " . $script_basepath . "?tagging_params=from%3Dshopmania" . "
";
//echo "Display Description options - possible values on, off, limited default value on
";
//echo "description=on (on,off) " . $script_basepath . "?description=off" . "
";
//echo "" . $script_basepath . "?description=limited" . "
";
echo "Display image options - possible values on, off default value on
";
echo "image=on (on,off) " . $script_basepath . "?image=off" . "
";
//echo "Display manufacturer options - possible values on, off default value on
";
//echo "manufacturer=on (on,off) " . $script_basepath . "?manufacturer=off" . "
";
echo "Display currency code - force the display of certain currency code possible values USD,EUR etc.
";
echo "display_currency=DEFAULT_CURRENCY " . $script_basepath . "?display_currency=EUR" . "
";
//echo "Special price options - possible values on, off default value on
";
//echo "specialprice=on (on,off) " . $script_basepath . "?specialprice=off" . "
";
//echo "Show only on stock products - possible values on, off default value off
";
//echo "on_stock=off (on,off) " . $script_basepath . "?on_stock=on" . "
";
//echo "Show SEO friendly url - possible values on, off default value off
";
//echo "sef=off (on,off) " . $script_basepath . "?sef=on" . "
";
//echo "Get prices in specified currency - possible values USD,EUR etc.
";
//echo "currency=DEFAULT_CURRENCY " . $script_basepath . "?currency=EUR" . "
";
//echo "Get texts in specified language code - possible values en,ro etc.
";
//echo "language=DEFAULT_LANGUAGE_CODE " . $script_basepath . "?language=en" . "
";
//echo "Get texts in specified language id - possible values 1,2 etc.
";
//echo "language_id=DEFAULT_LANGUAGE_ID " . $script_basepath . "?language_id=1" . "
";
//echo "Limit displayed products - possible values integer
";
//echo "limit=no_limit " . $script_basepath . "?limit=10" . "
";
//echo "Add basepath to product URL - possible values on, off default value off
";
//echo "forcepath=off (on,off) " . $script_basepath . "?forcepath=on" . "
";
//echo "Usepath - force defined basepath to product URL - possible values ex: www.site.com
";
//echo "usepath=BASEPATH " . $script_basepath . "forcepath=on&usepath=http://www.site.com" . "
";
//echo "Cat ordering options - possible values on, off default value off
";
//echo "cat_order=off (on,off) " . $script_basepath . "?cat_order=on" . "
";
//echo " - possible values on, off default value on
";
//echo "use_shoppergroup=on (on,off) " . $script_basepath . "?use_shoppergroup=off" . "
";
echo "
";
exit;
}
// Get currencies rates values
if ($use_currency != "") {
$file = "cache/daily.xml";
$xml_parser = xml_parser_create();
$handle = fopen($file, "r");
$data = fread($handle, filesize($file));
fclose($handle);
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
foreach ($vals as $i=>$v) {
if (($v['tag'] == "RATE") && ($v['type'] == 'complete') && ($v['value'] > 0)) {
$RATES[$v['attributes']['CURRENCY']] = $v['value'];
}
elseif (($v['tag'] == "CUBE") && ($v['type'] == 'complete') && ($v['attributes']['RATE'] > 0)) {
$RATES[$v['attributes']['CURRENCY']] = $v['attributes']['RATE'];
}
if ($v['tag'] == "ORIGCURRENCY") {
$origcurrency = $v['value'];
}
}
$origcurrency = ($origcurrency != "") ? $origcurrency : "EUR";
$RATES[$origcurrency] = 1;
}
$main_currency = (int)$config->get('main_currency', 1);
$db->setQuery('SELECT currency_code FROM '.hikashop_table('currency').' WHERE currency_id = '. (int)$main_currency);
$main_currency_code = $db->loadResult();
// Force displayed currency
$main_currency_code = ($display_currency != "") ? $display_currency : $main_currency_code;
$CAT_ARR = array();
$queryCategory="SELECT * FROM " . hikashop_table('category') . " WHERE category_type='product'";
$db->setQuery($queryCategory);
$categories = $db->loadObjectList();
foreach($categories as $k=>$row){
$CAT_ARR[$row->category_id]['id'] = $row->category_id;
$CAT_ARR[$row->category_id]['name'] = $row->category_name;
$CAT_ARR[$row->category_id]['parent_id'] = $row->category_parent_id;
}
$query = 'SELECT a.* FROM '.hikashop_table('product').' AS a WHERE a.product_access=\'all\' AND a.product_published=1 AND a.product_type=\'main\'';
$query .= ' AND ( product_sale_start < '.time().' OR product_sale_start = 0 )' .
' AND ( product_sale_end > '.time().' OR product_sale_end = 0 ) ';
if(!$config->get('show_out_of_stock',1)){
$query.=' AND product_quantity!=0 ';
}
$db->setQuery($query);
$products = $db->loadObjectList();
if(!empty($products)){
$ids = array();
$productClass = hikashop_get('class.product');
foreach($products as $key => $row){
$ids[]=$row->product_id;
$productClass->addAlias($products[$key]);
}
$productClass->getProducts($ids);
$queryCategoryId='SELECT * FROM '.hikashop_table('product_category').' WHERE product_id IN ('.implode(',',$ids).')';
$db->setQuery($queryCategoryId);
$categoriesId = $db->loadObjectList();
foreach($products as $k=>$row){
foreach($categoriesId as $catId){
if($row->product_id == $catId->product_id){
$products[$k]->categories_id[0] = $catId->category_id;
}
}
}
$queryImage = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id IN ('.implode(',',$ids).') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC';
$db->setQuery($queryImage);
$images = $db->loadObjectList();
foreach($products as $k=>$row){
foreach($images as $image){
if($row->product_id==$image->file_ref_id){
foreach(get_object_vars($image) as $key => $name){
$products[$k]->images[0]->$key = $name;
}
break;
}
}
}
$db->setQuery('SELECT * FROM '.hikashop_table('variant').' WHERE variant_product_id IN ('.implode(',',$ids).')');
$variants = $db->loadObjectList();
if(!empty($variants)){
foreach($products as $k => $product){
foreach($variants as $variant){
if($product->product_id==$variant->variant_product_id){
$products[$k]->has_options = true;
}
}
}
}
$db->setQuery('SELECT * FROM '.hikashop_table('price').' WHERE price_product_id IN ('.implode(',',$ids).')');
$prices = $db->loadObjectList();
if(!empty($prices)){
foreach($prices as $price){
$products[$price->price_product_id]->prices[]=$price;
}
}
$zone_id=hikashop_getZone();
$currencyClass = hikashop_get('class.currency');
$currencyClass->getListingPrices($products,$zone_id,$main_currency,'cheapest');
$app = JFactory::getApplication();
$imageHelper = hikashop_get('helper.image');
$uploadFolder_url = $imageHelper->main_uploadFolder_url;
foreach ( $products as $product ){
//$product = $productClass->products[$product->product_id];
$title = $product->product_name;
$title = html_entity_decode( $title );
$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
$link = JURI::base().'index.php?option=com_hikashop&ctrl=product&task=show&cid='.$product->product_id.'&name='.$product->alias.'&Itemid='.$Itemid.'&'.$pathway_sef_name.'='.$product->category_id;
//$prod_price = $currencyClass->format($product->prices[0]->price_value_with_tax,$product->prices[0]->price_currency_id);
/*if($product->prices['0']->price_value_with_tax != 0 ){
$desc = $product->product_description.JText::_('CART_PRODUCT_PRICE').' : '.$currencyClass->format($product->prices[0]->price_value_with_tax,$product->prices[0]->price_currency_id);
}
else{
$desc= $product->product_description.JText::_('FREE_PRICE');
}*/
$desc = $product->product_description;
$desc = preg_replace('#
#i','',$desc);
$prod_desc = $desc;
$prod_image = ($show_image == "on" && $product->images[0]->file_path != "") ? $base_path . $uploadFolder_url.$product->images[0]->file_path : "";
$prod_id = $product->product_id;
$prod_name = $title;
$prod_url = $link;
// Add GA Tagging parameters to url
if ($add_tagging == "on") {
$and_param = (preg_match("/\?/", $prod_url)) ? "&" : "?";
$prod_url = $prod_url . $and_param . $tagging_params;
}
@$category_name = smfeed_get_full_cat($product->categories_id[0], $CAT_ARR);
$prod_price = $product->product_msrp;
// Add VAT to prices
if ($add_vat == "on") {
$prod_price = $prod_price * $vat_value;
}
$prod_price = number_format($prod_price, 2);
// Clean product name (new lines)
$prod_name = str_replace("\n", "", strip_tags($prod_name));
$prod_name = str_replace("\r", "", strip_tags($prod_name));
$prod_name = str_replace("\t", " ", strip_tags($prod_name));
// Clean product description (Replace new line with
). In order to make sure the code does not contains other HTML code it might be a good ideea to strip_tags()
$prod_desc = smfeed_replace_not_in_tags("\n", "
", $prod_desc);
$prod_desc = str_replace("\n", " ", $prod_desc);
$prod_desc = str_replace("\r", "", $prod_desc);
$prod_desc = str_replace("\t", " ", $prod_desc);
// Clean product names and descriptions (separators)
if ($datafeed_separator == "\t") {
// Continue... tabs were already removed
}
elseif ($datafeed_separator == "|") {
$prod_name = str_replace("|", " ", strip_tags($prod_name));
$prod_desc = str_replace("|", " ", $prod_desc);
}
else {
print "Incorrect columns separator.";
exit;
}
// Output the datafeed content
// Category, Manufacturer, Model, ProdCode, ProdName, ProdDescription, ProdURL, ImageURL, Price, Currency, Shipping value, Availability, GTIN (UPC/EAN/ISBN)
print $category_name . $datafeed_separator .
$prod_manufacturer . $datafeed_separator .
$prod_model . $datafeed_separator .
$prod_id . $datafeed_separator .
$prod_name . $datafeed_separator .
$prod_desc . $datafeed_separator .
$prod_url . $datafeed_separator .
$prod_image . $datafeed_separator .
$prod_price . $datafeed_separator .
$main_currency_code . $datafeed_separator .
$shipping_value . $datafeed_separator .
$availability . $datafeed_separator .
$gtin . "\n";
// Debuging
if (isset($_GET['debug'])) {
$cnt_prod ++;
echo $cnt_prod . ".";
echo "\t" . number_format(microtime(true) - $time, 3) . "s \n";
$time = microtime(true);
echo "\t" . number_format(memory_get_usage()/1048576, 3) . "Mb\n\n";
}
$prod_count++;
// Limit displayed products
if ($limit > 0 && $prod_count >= $limit && !isset($_GET['pg'])) {
break;
}
}
}
// Debuging
if (isset($_GET['debug'])) {
echo "\npage loaded in " . number_format(microtime(true) - $time_start, 3) . "s \n";
echo "memory limit " . ini_get("memory_limit") . "\n";
echo "max_execution_time " . ini_get("max_execution_time") . "\n\n";
}
##### Functions ########################################################
function smfeed_html_to_text($string){
$search = array (
"''si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&(reg|#174);'i",
"'™'i",
"''i",
"''i"
); // evaluate as php
$replace = array (
" ",
" ",
"\\1",
"\"",
"&",
"<",
">",
" ",
"¡",
"¢",
"£",
"©",
"®",
"TM",
"•",
"-",
);
$text = preg_replace ($search, $replace, $string);
return $text;
}
function smfeed_clean_description($string){
$search = array (
"''i",
"''i",
"''i",
"''i",
"'.*?'si",
"']*?>'si"
);
$replace = array (
"",
"",
"",
"",
"",
""
);
$text = preg_replace ($search, $replace, $string);
return $text;
}
function smfeed_clean_accents($text){
$search = array (
"'%C4%99'", #e
"'%C3%A8'", #e
"'%C3%A9'", #e
"'%C3%AA'", #e
"'%C3%AB'", #e
"'%C3%89'", #e
"'%C3%88'", #E
"'%C3%8A'", #E
"'%C4%85'", #a
"'%C3%A3'", #a
"'%C3%A0'", #a
"'%C3%A4'", #a
"'%C3%A2'", #a
"'%C3%A1'", #a
"'%C3%A5'", #a
"'%C3%81'", #A
"'%C3%82'", #A
"'%C3%84'", #A
"'%C3%85'", #A
"'%C3%80'", #A
"'%C4%87'", #c
"'%C3%A7'", #c
"'%C3%87'", #C
"'%C5%9B'", #s
"'%C5%A1'", #s
"'%C5%A0'", #S
"'%C5%9A'", #S
"'%C3%B0'", #d
"'%C3%B1'", #n
"'%C3%BD'", #y
"'%C4%9F'", #g
"'%C4%B1'", #i
"'%C3%AE'", #i
"'%C3%AD'", #i
"'%C3%AF'", #i
"'%C3%AC'", #i
"'%C3%8D'", #I
"'%C3%8E'", #I
"'%C4%B0'", #I
"'%C5%82'", #l
"'%C5%84'", #n
"'%C3%BA'", #u
"'%C3%BB'", #u
"'%C3%B9'", #u
"'%C3%BC'", #u
"'%C5%B1'", #u
"'%C3%9C'", #U
"'%C3%B4'", #o
"'%C3%B3'", #o
"'%C3%91'", #o
"'%C3%B6'", #o
"'%C5%91'", #o
"'%C3%B2'", #o
"'%C3%B5'", #o
"'%C3%93'", #O
"'%C3%96'", #O
"'%C3%9F'", #ss
"'%C5%BC'", #z
"'%C5%BA'", #z
"'%C5%BB'", #Z
"'%C3%A6'", #ae
"'%C3%B8'", #oe
"'%C2%AE'",
"'%C2%B4'",
"'%E2%84%A2'",
);
$replace = array (
"e",
"e",
"e",
"e",
"e",
"e",
"E",
"E",
"a",
"a",
"a",
"a",
"a",
"a",
"a",
"A",
"A",
"A",
"A",
"A",
"c",
"c",
"C",
"s",
"s",
"S",
"S",
"d",
"n",
"y",
"g",
"i",
"i",
"i",
"i",
"i",
"I",
"I",
"I",
"l",
"n",
"u",
"u",
"u",
"u",
"u",
"U",
"o",
"o",
"o",
"o",
"o",
"o",
"o",
"O",
"O",
"ss",
"z",
"z",
"Z",
"ae",
"oe",
"",
"",
"",
);
$text = preg_replace($search, $replace, $text);
return $text;
}
// Cleans strings
function smfeed_string_clean_search($string){
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip ($trans);
$string = strtr($string, $trans);
$search = array (
"','",
"'"'",
"'<'",
"'>'",
"'%£'",
"'%€'",
"'-'",
"'~'",
"'!'",
"'\?'",
"'@'",
"'#'",
"'\\$'",
"'%'",
"'\^'",
"'&'",
"'\*'",
"'\('",
"'\)'",
"'_'",
"'='",
"'\''",
"'\['",
"'\]'",
"'{'",
"'}'",
"'\|'",
"'\"'",
"':'",
"';'",
"'\\\'",
"'>'",
"'<'",
"'[\r]+'",
"'[\n]+'",
"'[\t]+'",
"'[\s]+'",
//"'\.'",
//"'\+'",
//"'/'",
);
$replace = array (
"",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
//" ",
//" ",
//" ",
);
$string = preg_replace($search, $replace, $string);
return $string;
}
function smfeed_replace_not_in_tags($find_str, $replace_str, $string) {
$find = array($find_str);
$replace = array($replace_str);
preg_match_all('#[^>]+(?=<)|[^>]+$#', $string, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
if (trim($val[0]) != "") {
$string = str_replace($val[0], str_replace($find, $replace, $val[0]), $string);
}
}
return $string;
}
// Function to get category with full path
function smfeed_get_full_cat($cat_id, $CATEGORY_ARR) {
$item_arr = $CATEGORY_ARR[$cat_id];
$cat_name = $item_arr['name'];
while (sizeof($CATEGORY_ARR[$item_arr['parent_id']]) > 0 && is_array($CATEGORY_ARR[$item_arr['parent_id']]) ) {
$cat_name = $CATEGORY_ARR[$item_arr['parent_id']]['name'] . " > " . $cat_name;
$item_arr = $CATEGORY_ARR[$item_arr['parent_id']];
}
// Strip html from category name
$cat_name = smfeed_html_to_text($cat_name);
return $cat_name;
}
###################################################################
exit;
?>