diafan->configmodules('yandex', 'shop', $row["id"])) { $this->sites[] = $row["id"]; } } if (! $this->sites) { Custom::inc('includes/404.php'); } define('TITLE', defined('TIT'.$this->diafan->_languages->site) ? constant('TIT'.$this->diafan->_languages->site) : ''); header('Content-type: application/xml'); echo utf::to_windows1251($this->get()); } /** * Получает содержимое YML-файла * * @return string */ private function get() { $cache_meta = array( "name" => "yandex" ); if (! $text = $this->diafan->_cache->get($cache_meta, "shop")) { $text = $this->get_info(); $text .= $this->get_categories(); $text .= $this->get_offers(); $text = ' timeedit).'"> '.$text.' '; $this->diafan->_cache->save($text, $cache_meta, "shop"); } return $text; } /** * Генерирует часть YML-файла, содеражащую информацию о магазине * * @return string */ private function get_info() { $text = ' '.$this->prepare($this->diafan->configmodules('nameshop', 'shop', $this->sites[0])).' '.$this->prepare(TITLE).' '.BASE_PATH.' '; return $text; } /** * Генерирует часть YML-файла, содеражащую информацию о категориях магазина * * @return string */ private function get_categories() { $text = ''; foreach ($this->sites as $site_id) { if ($this->diafan->configmodules('cat', 'shop', $site_id)) { $rows = DB::query_fetch_all("SELECT id, [name], parent_id, timeedit FROM {shop_category} WHERE [act]='1' AND trash='0' AND site_id=%d" .($this->diafan->configmodules('show_yandex_category', 'shop', $site_id) ? " AND show_yandex='1'" : ""), $site_id); foreach ($rows as $row) { $text .= ' ' .$this->prepare($row["name"]).''; $this->timeedit = $row["timeedit"] > $this->timeedit ? $row["timeedit"] : $this->timeedit; } } } if($text) { $text = ' '.$text.' '; } return $text; } /** * Генерирует часть YML-файла, содеражащую информацию о товарах магазина * * @return string */ private function get_offers() { $params = DB::query_fetch_key("SELECT id, yandex_name, yandex_unit, [name], type FROM {shop_param} WHERE yandex_use='1' AND trash='0'", "id"); if($params) { foreach($params as $p) { if($p["type"] == 'select' || $p["type"] == 'multiple') { $pselectid[] = $p["id"]; } } if(! empty($pselectid)) { $pselect = DB::query_fetch_key_value("SELECT id, [name] FROM {shop_param_select} WHERE param_id IN (%s)", implode(',', $pselectid), "id", "name"); } $pvs = DB::query_fetch_all("SELECT [value], param_id, element_id FROM {shop_param_element} WHERE param_id IN (%s)", implode(',', array_keys($params)), "param_id"); foreach($pvs as $p) { if($params[$p["param_id"]]["type"] == 'select' || $params[$p["param_id"]]["type"] == 'multiple') { $p["value"] = ! empty($pselect[$p["value"]]) ? $pselect[$p["value"]] : ''; } if(! $p["value"]) { continue; } $params_value[$p["param_id"]][$p["element_id"]][] = $p["value"]; } } $images = DB::query_fetch_key_array("SELECT id, name, folder_num, element_id FROM {images} WHERE module_name='shop' AND element_type='element' AND trash='0' ORDER BY sort ASC", "element_id"); $text = ' '; foreach ($this->sites as $site_id) { if(! isset($GLOBALS['shop_images_variation_medium'])) { $GLOBALS['shop_images_variation_medium'] = ''; $images_variations = unserialize($this->diafan->configmodules("images_variations_element", 'shop', $site_id)); foreach ($images_variations as $images_variation) { if($images_variation["name"] == 'medium') { $GLOBALS['shop_images_variation_medium'] = DB::query_result("SELECT folder FROM {images_variations} WHERE id=%d LIMIT 1", $images_variation["id"]); continue; } } } $query = "SELECT s.* FROM {shop} AS s"; if ($this->diafan->configmodules('cat', 'shop', $site_id) && $this->diafan->configmodules('show_yandex_category', 'shop', $site_id)) { $query .= " INNER JOIN {shop_category} AS c ON c.id=s.cat_id"; } $query .= " WHERE s.[act]='1' AND s.trash='0' AND s.site_id=%d" .($this->diafan->configmodules('show_yandex_element', 'shop', $site_id) ? " AND s.show_yandex='1'" : ""); if ($this->diafan->configmodules('cat', 'shop', $site_id) && $this->diafan->configmodules('show_yandex_category', 'shop', $site_id)) { $query .= " AND c.[act]='1' AND c.trash='0' AND c.show_yandex='1'"; } $i = 0; $max = 1000; while(1==1) { $rows = DB::query_fetch_all($query." LIMIT ".($i * $max).", ".$max, $site_id); if(! $rows) { break; } $i++; foreach ($rows as $row) { $this->diafan->_shop->price_prepare_all($row["id"]); $this->diafan->_route->prepare($row["site_id"], $row["id"], "shop"); } foreach ($rows as $row) { $yandex = array(); $link = BASE_PATH.$this->diafan->_route->link($row["site_id"], $row["id"], "shop"); $this->timeedit = $row["timeedit"] > $this->timeedit ? $row["timeedit"] : $this->timeedit; if ($row["yandex"]) { $y_arr = explode("\n", $this->prepare($row["yandex"])); foreach ($y_arr as $y_a) { list($k, $v) = explode("=", $y_a, 2); $yandex[$k] = $v; } } $oldprice = 0; $prices = $this->diafan->_shop->price_get_all($row["id"], 0); if(empty($prices)) { $price = 0; } else { if($prices[0]["price"]*100%100) { $price = number_format($prices[0]["price"], 2, '.', ''); } else { $price = number_format($prices[0]["price"], 0, '.', ''); } if($prices[0]["old_price"] && $prices[0]["old_price"] != $prices[0]["price"]) { if($prices[0]["old_price"]*100%100) { $oldprice = number_format($prices[0]["old_price"], 2, '.', ''); } else { $oldprice = number_format($prices[0]["old_price"], 0, '.', ''); } } } if(empty($prices) || $this->diafan->configmodules("use_count_goods", 'shop', $site_id) && ! $prices[0]["count_goods"] || $row["no_buy"]) { $available = 'false'; } else { $available = 'true'; } $imgs = ! empty($images[$row["id"]]) ? $images[$row["id"]] : array(); $pictures = array(); foreach($imgs as $img) { $pictures[] = BASE_PATH.USERFILES.'/shop/'.$GLOBALS['shop_images_variation_medium'].'/'.($img["folder_num"] ? $img["folder_num"].'/' : '').$img["name"]; } $bid = ! empty($yandex["bid"]) ? $yandex["bid"] : $this->diafan->configmodules('bid', 'shop', $site_id); if (empty($yandex["typePrefix"]) || empty($yandex["vendor"]) || empty($yandex["vendorCode"]) || empty($yandex["model"])) { $text .= ' '.$link.' '.$price.''; if($oldprice) { $text .= ''.$oldprice.''; } $text .= ''; if ($this->diafan->configmodules('currencyyandex', 'shop', $site_id)) { $text .= $this->prepare($this->diafan->configmodules('currencyyandex', 'shop', $site_id)); } else { $text .= 'RUR'; } $text .= ''; if ($this->diafan->configmodules('cat', 'shop', $site_id)) { $text .= ' '.$row["cat_id"].''; } foreach ($pictures as $picture) { $text .= ' '.$picture.''; } $text .= ' true '.$this->prepare($row["name".$this->diafan->_languages->site]).''; if (! empty($yandex["model"])) { $text .= ' '.$yandex["model"].''; } if (! empty($yandex["vendor"])) { $text .= ' '.$yandex["vendor"].''; } if (! empty($yandex["vendorCode"])) { $text .= ' '.$yandex["vendorCode"].''; } if (! empty($yandex["sales_notes"])) { $text .= ' '.$yandex["sales_notes"].''; } if ($row["text".$this->diafan->_languages->site]) { $text .= ' '.$this->prepare($row["text".$this->diafan->_languages->site]).''; } $text .= ' '.(! empty($yandex["manufacturer_warranty"]) ? 'true' : 'false').''; if (! empty($yandex["country_of_origin"])) { $text .= ' '.$yandex["country_of_origin"].''; } } else { $text .= ' '.$link.' '.$price.''; if($oldprice) { $text .= ''.$oldprice.''; } $text .= ''; if ($this->diafan->configmodules('currencyyandex', 'shop', $site_id)) { $text .= $this->prepare($this->diafan->configmodules('currencyyandex', 'shop', $site_id)); } else { $text .= 'RUR'; } $text .= ''; if ($this->diafan->configmodules('cat', 'shop', $site_id)) { $text .= ' '.$row["cat_id"].''; } foreach ($pictures as $picture) { $text .= ' '.$picture.''; } $text .= ' true'; $text .= ' '.$yandex["typePrefix"].' '.$yandex["vendor"].''; if (! empty($yandex["vendorCode"])) { $text .= ' '.$yandex["vendorCode"].''; } if (! empty($yandex["sales_notes"])) { $text .= ' '.$yandex["sales_notes"].''; } $text .= ' '.$yandex["model"].''; if ($row["text".$this->diafan->_languages->site]) { $text .= ' '.$this->prepare($row["text".$this->diafan->_languages->site]).''; } $text .= ' '.(! empty($yandex["manufacturer_warranty"]) ? 'true' : 'false').''; if (! empty($yandex["country_of_origin"])) { $text .= ' '.$yandex["country_of_origin"].''; } } if($params) { foreach($params AS $p) { if($p["type"] == 'checkbox') { if(! empty($params_value[$p["id"]][$row["id"]])) { $text .= ' есть'; } } elseif(! empty($params_value[$p["id"]][$row["id"]])) { foreach($params_value[$p["id"]][$row["id"]] as $v) { $text .= ' '.$v.''; } } } } $text .= ' '; } } } $text.=' '; return $text; } /** * Подготавливает текст для отображения в YML-файле * * @param string $text исходный текст * @return string */ private function prepare($text) { $repl = array(' ', '"','&','>','<',"'", chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7), chr(8), chr(11), chr(12), chr(14), chr(15), chr(16), chr(17), chr(18), chr(19), chr(20), chr(21), chr(22), chr(23), chr(24), chr(25), chr(26), chr(27), chr(28), chr(29), chr(30), chr(31)); $replm = array(' ', '"', '&', '>', '<', ''', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); $text = str_replace($repl, $replm, strip_tags($text)); return $text; } } try { $class = new Shop_yandex($diafan); $class->init(); exit; } catch (Exception $e) { Dev::exception($e); }