get('sitename');
}
$minRating = isset($minRating) ? $minRating : 1;
$maxRating = isset($maxRating) ? $maxRating : 5;
//import the hikashop router to construct the urls
//jimport only seems to work locally so we just use an include
//jimport('helpers.route', JPATH_SITE.'/components/com_hikashop');
include_once ('../components/com_hikashop/helpers/route.php');
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the hikashop vote table
// Order it by the id field, newest first.
$query->select('*');
$query->from($db->quoteName('#__hikashop_vote'));
$query->order('vote_ref_id DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects.
$reviews = $db->loadObjectList();
$xmlItems = array();
if($reviews){
//Function to clean the comment and make it xml compatible
function clean_comment($text) {
$text = strip_tags($text); //Remove all html tags
$text = str_replace(' ', ' ', $text); // Replaces non-breaking spaces with a normal space
$text = str_replace('–', '-', $text);
$text = str_replace('£', '£', $text);
$text = str_replace('&', '&', $text);
$text = str_replace(array('‘', '’', '”', '“', '’', '‘', '”', '“'), '\'', $text); //Converts different quotes to singles
$text = htmlspecialchars($text, ENT_QUOTES); //Converts any other chars to the correct entities and encodes single quotes
$text = str_replace(''', ''', $text);
$text = preg_replace('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', '', $text); //Strips and urls from the text
return $text;
}
//Loop through the reviews and add a node for each
foreach ($reviews as $review) {
//Get the item details
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__hikashop_product'));
$query->where('product_id = '. $review->vote_ref_id);
$query->setLimit('1');
$db->setQuery($query);
// Load the results as a list of stdClass objects.
$product = $db->loadAssoc();
if ($product['product_published'] == 1) {
$mpn = str_replace(array(' ','-'),array('',''), $product['product_code']);
$itemLink = str_replace('/cli/', '/', hikashopTagRouteHelper::getProductRoute($review->vote_ref_id));
$itemTitle = $item->title;
$item = "\t".''."\n";
$item .= "\t\t".''.$review->vote_id.''."\n";
$item .= "\t\t".''."\n";
$item .= "\t\t\t".''.trim($review->vote_pseudo). ''."\n";
$item .= "\t\t".''."\n";
$item .= "\t\t".''.date('Y-m-d\Th:i:s\Z', $review->vote_date).''."\n";
$item .= "\t\t".''.clean_comment($review->vote_comment).''."\n";
$item .= "\t\t".''.$itemLink.''."\n";
$item .= "\t\t".''."\n";
$item .= "\t\t\t".''.$review->vote_rating. ''."\n";
$item .= "\t\t".''."\n";
$item .= "\t\t".''."\n";
$item .= "\t\t\t".''."\n";
$item .= "\t\t\t\t\n";
$item .= "\t\t\t\t\t\n";
$item .= "\t\t\t\t\t\t".$mpn."\n";
$item .= "\t\t\t\t\t\n";
$item .= "\t\t\t\t\t\n";
$item .= "\t\t\t\t\t\tJuicy Bike\n";
$item .= "\t\t\t\t\t\n";
$item .= "\t\t\t\t\n";
$item .= "\t\t\t\t".$itemLink."\n";
$item .= "\t\t\t".''."\n";
$item .= "\t\t".''."\n";
$item .= "\t".''."\n";
//push into the items
$xmlItems[] = $item;
} //end if published
}
}
// Output XML header.
$xml = '' . "\n";
$xml .= '' . "\n";
// Output root element.
$xml .= ''."\n";
$xml .= ''.$siteTitle.''."\n";
$xml .= ''.$favicon.''."\n";
$xml .= ''."\n";
$xml .= ''."\n";
// Output the data.
if(!empty($xmlItems)){
foreach ($xmlItems as $xmlItem){
$xml .= $xmlItem;
}
}
// Terminate the reviews element
$xml .= ''."\n";
// Terminate feed element.
$xml .= ''."\n";
if(JFile::write($file_path, $xml)) {
echo "Product review feed generated sucessfully";
} else {
echo "There was an error saving the product review feed";
}