set_time_limit(0);
//error_reporting(E_ALL);
setlocale(LC_ALL, 'ru_RU');
set_include_path(implode(PATH_SEPARATOR, array('/var/www/beta.site.ua/library', get_include_path(),)));
// список iblock-ов, из которых надо экспортировать товары
$arrIblock = array(
20 => 'Мобильные телефоны',
22 => 'Ноутбуки',
21 => 'МП3-плееры',
23 => 'Зарядные устройства',
24 => 'Карты памяти',
25 => 'USB Flash Накопители',
26 => 'Наушники',
27 => 'Элементы питания',
28 => 'Bluetooth гарнитуры',
29 => 'Проводные гарнитуры',
30 => 'Модемы 3G',
31 => 'Стартовые пакеты'
);
// подключаем фаил с конфигурацией
require_once '/var/www/beta.site.ua/application/config/application.php';
// подключаемся к базе данных Инет-магазина
$sqlLink = mysql_connect($dbHost, $dbUser, $dbPass, true) or die(mysql_error());
mysql_select_db($dbName, $sqlLink) or die(mysql_error());
mysql_query("SET NAMES cp1251", $sqlLink) or die(mysql_error());
// достаем список товаров из базы
$arrGoods = array();
$arrIblockId = array_keys($arrIblock);
$strIblockId = "'" . implode("', '", $arrIblockId) . "'";
$sql = "SELECT bie.`ID`, bie.`IBLOCK_ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`, bie.`PREVIEW_TEXT`,
bi.`NAME` AS IBLOCK_NAME, bi.`DETAIL_PAGE_URL`,
bis.`NAME` AS IBLOCK_SECTION_NAME,
bf.`SUBDIR`, bf.`FILE_NAME`
FROM `b_iblock_element` AS bie
JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
JOIN `b_iblock_section_element` AS bise ON bise.`IBLOCK_ELEMENT_ID` = bie.`ID`
JOIN `b_iblock_section` AS bis ON bis.`ID` = bise.`IBLOCK_SECTION_ID`
AND bis.`NAME` != 'Все товары'
JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
WHERE bie.`IBLOCK_ID` IN ({$strIblockId})
AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
AND bie.`ACTIVE` = 'Y'
ORDER BY bie.`DATE_CREATE` DESC
LIMIT 30";
$result = mysql_query($sql, $sqlLink) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$id = (int) $row['ID'];
$iblockId = (int) $row['IBLOCK_ID'];
$iblockSectionId = (int) $row['IBLOCK_SECTION_ID'];
$name = iconv('cp1251', 'utf-8', stripslashes($row['NAME']));
$previewText = stripslashes($row['PREVIEW_TEXT']);
$iblockName = stripslashes($row['IBLOCK_NAME']);
$iblockSectionName = stripslashes($row['IBLOCK_SECTION_NAME']);
$detailUrl = str_replace('#SITE_DIR#', 'http://www.citrus.ua', $row['DETAIL_PAGE_URL']);
$detailUrl = str_replace('#SECTION_ID#', $iblockSectionId, $detailUrl);
$detailUrl = str_replace('#ID#', $id, $detailUrl);
$pic = 'http://img.site.ua/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
$description = iconv('cp1251', 'utf-8', htmlspecialchars(strip_tags($previewText), ENT_QUOTES));
$content = '<img src="' . $pic . '" style="float:left;">' . $previewText;
$content = iconv('cp1251', 'utf-8', $content);
$arrGoods[$id]['title'] = $name;
$arrGoods[$id]['description'] = $description;
$arrGoods[$id]['link'] = $detailUrl;
$arrGoods[$id]['content'] = $content;
$arrGoods[$id]['enclosure'] = array(array('url' => $pic, 'type' => 'image/jpeg'));
}
}
mysql_free_result($result);
$arrRss = array(
'title' => iconv('cp1251', 'utf-8', 'Новинки товаров интернет-магазина'),
'link' => 'http://www.site.ua/',
'charset' => 'windows-1251',
'author' => iconv('cp1251', 'utf-8', 'Интернет-магазин'),
'entries' => $arrGoods
);
// подключаем библиотечку для работы с лентами RSS
require_once 'Zend/Feed.php';
// создаем ленту RSS из массива
$feed = Zend_Feed::importArray($arrRss, 'rss');
$xml = $feed->saveXML();
//$rssFeed->send();
file_put_contents('/var/www/site.ua/public/shop/goods/rss/new.xml', $xml);