config->get('feed_yandex_turbo_status')) { $this->load->model('extension/feed/yandex_turbo'); $this->load->model('tool/image'); $this->eol = "\n"; $output = '' . $this->eol; $output .= '' . $this->eol; $output .= '' . $this->eol; $output .= '' . $this->eol; $output .= '' . $this->config->get('config_name') . '' . $this->eol ; $output .= '' . $this->config->get('config_owner') . '' . $this->eol ; $output .= '' . HTTPS_SERVER . '' . $this->eol ; $output .= '' . $this->config->get('config_telephone') . '' . $this->eol ; $output .= 'Opencart' . $this->eol ; $output .= '' . VERSION . '' . $this->eol ; $offers_currency = $this->config->get('feed_yandex_turbo_currency'); $this->load->model('localisation/currency'); $this->load->model('tool/image'); if (!$this->currency->has($offers_currency)) exit(); $decimal_place = $this->currency->getDecimalPlace($offers_currency); $shop_currency = $this->config->get('config_currency'); $this->setCurrency($offers_currency, 1); $currencies = $this->model_localisation_currency->getCurrencies(); $supported_currencies = array('RUR', 'RUB', 'USD', 'BYR', 'KZT', 'EUR', 'UAH'); $currencies = array_intersect_key($currencies, array_flip($supported_currencies)); foreach ($currencies as $currency) { if ($currency['code'] != $offers_currency && $currency['status'] == 1) { $this->setCurrency($currency['code'], number_format(1/$this->currency->convert($currency['value'], $offers_currency, $shop_currency), 4, '.', '')); } } $output .= '' . $this->eol; foreach ($this->currencies as $currency) { $output .= $this->getElement($currency, 'currency'); } $output .= '' . $this->eol; $decimal = (int)$this->currency->getDecimalPlace($offers_currency); $categories = $this->model_extension_feed_yandex_turbo->getCategories(); foreach ($categories as $category) { $this->setCategory($category['name'], $category['category_id'], $category['parent_id']); } $output .= '' . $this->eol; foreach ($this->categories as $category) { $category_name = $category['name']; unset($category['name'], $category['export']); $output .= $this->getElement($category, 'category', $category_name); } $output .= '' . $this->eol; $output .= '' . $this->eol; $products = $this->model_extension_feed_yandex_turbo->getProducts(); foreach ($products as $product) { $output .= '' . $this->eol; $output .= '' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '' . $this->eol; $output .= '' . number_format($this->currency->convert($this->tax->calculate($product['price'], $product['tax_class_id']), $shop_currency, $offers_currency), $decimal, '.', '') . ''; $output .= '' . $offers_currency . '' . $this->eol; $output .= '' . $product['category_id'] . '' . $this->eol; $output .= '' . $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')) . '' . $this->eol; $output .= 'prepareField($product['name']) . ']]>' . $this->eol; $output .= 'prepareField($product['description']) . ']]>' . $this->eol; $output .= '' . $this->eol; } $output .= '' . $this->eol; $output .= ''. $this->eol; $output .= ''; $this->response->addHeader('Content-Type: application/xml'); $this->response->setOutput($output); } } private function setCurrency($id, $rate = 'CBRF', $plus = 0) { $allow_id = array('RUR', 'RUB', 'USD', 'BYR', 'KZT', 'EUR', 'UAH'); if (!in_array($id, $allow_id)) { return false; } $allow_rate = array('CBRF', 'NBU', 'NBK', 'CB'); if (in_array($rate, $allow_rate)) { $plus = str_replace(',', '.', $plus); if (is_numeric($plus) && $plus > 0) { $this->currencies[] = array( 'id'=>$this->prepareField(strtoupper($id)), 'rate'=>$rate, 'plus'=>(float)$plus ); } else { $this->currencies[] = array( 'id'=>$this->prepareField(strtoupper($id)), 'rate'=>$rate ); } } else { $rate = str_replace(',', '.', $rate); if (!(is_numeric($rate) && $rate > 0)) { return false; } $this->currencies[] = array( 'id'=>$this->prepareField(strtoupper($id)), 'rate'=>(float)$rate ); } return true; } private function setCategory($name, $id, $parent_id = 0) { $id = (int)$id; if ($id < 1 || trim($name) == '') { return false; } if ((int)$parent_id > 0) { $this->categories[$id] = array( 'id'=>$id, 'parentId'=>(int)$parent_id, 'name'=>$this->prepareField($name) ); } else { $this->categories[$id] = array( 'id'=>$id, 'name'=>$this->prepareField($name) ); } return true; } private function getElement($attributes, $element_name, $element_value = '') { $retval = '<' . $element_name . ' '; foreach ($attributes as $key => $value) { $retval .= $key . '="' . $value . '" '; } $retval .= $element_value ? '>' . $this->eol . $element_value . '' : '/>'; $retval .= $this->eol; return $retval; } private function prepareField($field) { $field = htmlspecialchars_decode($field); $field = strip_tags($field); $from = array('"', '&', '>', '<', '°', '\''); $to = array('"', '&', '>', '<', '°', '''); $field = str_replace($from, $to, $field); $field = preg_replace('#[\x00-\x08\x0B-\x0C\x0E-\x1F]+#is', ' ', $field); return trim($field); } }