Exemple #1
0
function admLinkByModule($module, $table = 'content')
{
    list($siteDocuments, $siteDocumentsByParent, $siteDocumentsByModule) = admGetContentTable($table);
    return admLinkById($siteDocumentsByModule[$module]['id']);
}
Exemple #2
0
    function MakeYML()
    {
        $yml_file = '/yandex.xml';
        $topics_table = 'products_topics';
        //$brands_table = 'brands';
        $products_table = 'products';
        $img = new Images();
        $yml = '<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="' . date('Y-m-d H:i') . '">
<shop>
	<name>' . $_SERVER['SERVER_NAME'] . '</name>
	<company>' . $GLOBALS['config']['site']['title'] . '</company>
	<url>http://' . $_SERVER['SERVER_NAME'] . '/</url>
	
	<currencies>
		<currency id="RUR" rate="1"/>
	</currencies>
	
	<categories>';
        $db = db();
        //Категории
        $topics = array();
        $db->query("SELECT * FROM `prefix_{$topics_table}` WHERE `deleted` = 'N' ORDER BY `top`,`order`");
        while ($t = $db->fetch()) {
            if ($t['top'] == 0) {
                $yml .= '
		<category id="' . $t['id'] . '">' . $t['name'] . '</category>';
            } else {
                $yml .= '
		<category id="' . $t['id'] . '" parentId="' . $t['top'] . '">' . $t['name'] . '</category>';
            }
            $topics[$t['id']] = $t;
        }
        $yml .= '
	</categories>
	<offers>';
        //Бренды
        $brands_table_exist = false;
        $brands = array();
        if (isset($brands_table) && !empty($brands_table)) {
            if ($db->query("SELECT * FROM `prefix_{$brands_table}`")) {
                while ($b = $db->fetch()) {
                    $brands[$b['id']] = $b;
                }
                $brands_table_exist = true;
            }
        }
        //Товары
        $db->query("SELECT * FROM `prefix_{$products_table}` WHERE `deleted` = 'N' AND `show` = 'Y' ORDER BY `top`,`order`");
        while ($i = $db->fetch()) {
            //Находим бренд
            if ($brands_table_exist) {
                $brand = $brands[$i['brand']]['name'];
            } else {
                if (isset($i['brand_name'])) {
                    $brand = $i['brand_name'];
                } elseif (isset($i['brand'])) {
                    $brand = $i['brand'];
                } else {
                    $brand = '';
                }
            }
            //Картинка
            $image = $img->GetMainImage(__CLASS__, $i['id']);
            if (!isset($image['src'])) {
                $picture = '';
            } else {
                $picture = 'http://' . $_SERVER['SERVER_NAME'] . $image['src'];
            }
            $yml .= '
		<offer id="' . $i['id'] . '" type="vendor.model" available="true">
			
  			<url>http://' . $_SERVER['SERVER_NAME'] . admLinkByModule(__CLASS__) . admLinkById($i['top'], $topics_table) . '/' . $i['id'] . '</url>
  			<price>' . $i['price'] . '</price>
  			<currencyId>RUR</currencyId>
  			<categoryId>' . $i['top'] . '</categoryId>
			
  			<picture>' . $picture . '</picture>
  			<typePrefix>' . htmlspecialchars($topics[$i['top']]['name']) . '</typePrefix>
  			<vendor>' . htmlspecialchars($brand) . '</vendor>
			
  			<model>' . htmlspecialchars($i['name']) . '</model>
  			<description>' . htmlspecialchars(strip_tags($i['text'])) . '</description>
		</offer>
			';
        }
        $yml .= '
	</offers>
</shop>
</yml_catalog>';
        if (is_file(DIR . $yml_file)) {
            if (is_writable(DIR . $yml_file)) {
                if (file_put_contents(DIR . $yml_file, $yml)) {
                    $this->content = 'Файл ' . $yml_file . ' успешно обновлен.';
                } else {
                    $this->content = 'Неведомая ошибка записи';
                }
            } else {
                $this->content = 'Невозможно записать файл ' . $yml_file . ', нет прав!';
            }
        } else {
            if (is_writable(DIR)) {
                if (file_put_contents(DIR . $yml_file, $yml)) {
                    $this->content = 'Файл ' . $yml_file . ' успешно создан.';
                } else {
                    $this->content = 'Неведомая ошибка записи';
                }
            } else {
                $this->content = 'Невозможно создать файл ' . $yml_file . ', нет прав! Попробуйте создать его самостоятельно и назначьте права 0777.';
            }
        }
    }