Файл: adultscript-2.0.3-pro/files/admin/modules/tools/helpers/sitemap.php
Строк: 370
<?php
class VHelper_tools_sitemap
{
private static $error = null;
public static function build($options = array())
{
$options = ($options) ? $options : array(
'max_per_file' => 45000,
'sitemap_frontpage' => '1',
'sitemap_category' => '1',
'sitemap_pornstar' => '1',
'sitemap_static' => 0,
'sitemap_users' => 0,
'sitemap_albums' => '1',
'sitemap_photos' => 0,
'sitemap_videos' => '1',
'sitemap_forum' => 0,
'video_sitemap' => 0,
'ping_google' => 0,
'ping_bing' => 0
);
$file = BASE_DIR.'/sitemap.xml';
if (!VFile::exists($file)) {
@file_put_contents($file, 'oops');
@chmod($file, 0777);
}
if (!VFile::exists($file) or !is_writable($file)) {
static::$error = 'File sitemap.xml not found or not writable! Aborting...';
return false;
}
$dir = BASE_DIR.'/sitemaps';
if (!VFolder::exists($dir) or !is_writable($dir)) {
static::$error = 'Folder '.$dir.' not found or not writable! Aborting...';
return false;
}
$db = VF::factory('database');
$current_date = date('Y-m-d');
$index = array();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
if ($options['sitemap_frontpage'] == '1') {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/'.'</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>daily</changefreq>',"n";
echo ' <priority>1.0</priority>',"n";
echo ' </url>',"n";
}
if ($options['sitemap_category'] == '1') {
$db->query("SELECT slug FROM #__video_categories WHERE status = '1' ORDER BY name ASC");
$categories = $db->fetch_rows();
foreach ($categories as $category) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/'.$category['slug'].'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>daily</changefreq>',"n";
echo ' <priority>0.9</priority>',"n";
echo ' </url>';
}
}
if ($options['sitemap_static'] == '1') {
$db->query("SELECT name FROM #__static WHERE status = '1'");
$pages = $db->fetch_rows();
foreach ($pages as $page) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/static/'.$page['name'].'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.1</priority>',"n";
echo ' </url>',"n";
}
}
echo '</urlset>';
$content = ob_get_contents();
ob_end_clean();
$index[] = array('url' => BASE_URL.'/sitemaps/sitemap-general.xml', 'lastmod' => $current_date);
$file = BASE_DIR.'/sitemaps/sitemap-general.xml';
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write general sitemap file ('.$file.')! Aborting...';
return false;
}
if ($options['sitemap_users'] == '1') {
$sql_count = "SELECT COUNT(*) AS total_users
FROM #__user
WHERE status = '1'";
$total_users = $db->get_field($sql_count, 'total_users');
$sql = "SELECT username
FROM #__user
WHERE status = '1'
ORDER BY user_id DESC";
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_users) {
$filename = 'sitemap-users-'.$count.'.xml';
$users = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
foreach ($users as $user) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/users/'.e($user['username']).'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.1</priority>',"n";
echo ' </url>',"n";
}
echo '</urlset>',"n";
$content = ob_get_contents();
ob_end_clean();
$file = BASE_DIR.'/sitemaps/'.$filename;
$index[] = array('url' => BASE_URL.'/sitemaps/'.$filename, 'lastmod' => $current_date);
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write users sitemap file ('.$file.')! Aborting...';
return false;
}
$start = ($start + $amount);
++$count;
}
}
if ($options['sitemap_albums'] == '1') {
$sql_count = "SELECT COUNT(*) AS total_albums
FROM #__photo_albums
WHERE status = '1'";
$total_albums = $db->get_field($sql_count, 'total_albums');
$sql = "SELECT album_id, slug
FROM #__photo_albums
WHERE status = '1'
ORDER BY album_id DESC";
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_albums) {
$filename = 'sitemap-albums-'.$count.'.xml';
$albums = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
foreach ($albums as $album) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/photo/'.$album['album_id'].'/'.e($album['slug']).'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.3</priority>',"n";
echo ' </url>',"n";
}
echo '</urlset>',"n";
$content = ob_get_contents();
ob_end_clean();
if ($albums) {
$file = BASE_DIR.'/sitemaps/'.$filename;
$index[] = array('url' => BASE_URL.'/sitemaps/'.$filename, 'lastmod' => $current_date);
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write albums sitemap file ('.$file.')! Aborting...';
return false;
}
}
$start = ($start + $amount);
++$count;
}
}
if ($options['sitemap_photos'] == '1') {
$sql_count = "SELECT COUNT(*) AS total_photos
FROM #__photo
WHERE status = '1'";
$total_photos = (int) $db->get_field($sql_count, 'total_photos');
$sql = "SELECT photo_id
FROM #__photo
WHERE status = '1'
ORDER BY photo_id DESC";
if ($total_photos > 0) {
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_photos) {
$filename = 'sitemap-photos-'.$count.'.xml';
$photos = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
foreach ($photos as $photo) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/photo/'.$photo['photo_id'].'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.3</priority>',"n";
echo ' </url>',"n";
}
echo '</urlset>',"n";
$content = ob_get_contents();
ob_end_clean();
if ($photos) {
$file = BASE_DIR.'/sitemaps/'.$filename;
$index[] = array('url' => BASE_URL.'/sitemaps/'.$filename, 'lastmod' => $current_date);
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write photos sitemap file ('.$file.')! Aborting...';
return false;
}
}
$start = ($start + $amount);
++$count;
}
}
}
if ($options['sitemap_pornstar'] == '1') {
$sql_count = "SELECT COUNT(*) AS total_pornstars
FROM #__model
WHERE status = '1'";
$total_pornstars = (int) $db->get_field($sql_count, 'total_pornstars');
$sql = "SELECT slug
FROM #__model
WHERE status = '1'
ORDER BY model_id DESC";
if ($total_pornstars > 0) {
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_pornstars) {
$filename = 'sitemap-pornstars-'.$count.'.xml';
$pornstars = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
foreach ($pornstars as $pornstar) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/pornstar/'.$pornstar['slug'].'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.3</priority>',"n";
echo ' </url>',"n";
}
echo '</urlset>',"n";
$content = ob_get_contents();
ob_end_clean();
if ($pornstars) {
$file = BASE_DIR.'/sitemaps/'.$filename;
$index[] = array('url' => BASE_URL.'/sitemaps/'.$filename, 'lastmod' => $current_date);
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write pornstars sitemap file ('.$file.')! Aborting...';
return false;
}
}
$start = ($start + $amount);
++$count;
}
}
}
if ($options['sitemap_videos'] == '1') {
$sql_count = "SELECT COUNT(*) AS total_videos
FROM #__video
WHERE status = 1";
$total_videos = $db->get_field($sql_count, 'total_videos');
$sql = "SELECT video_id, slug
FROM #__video
WHERE status = 1
ORDER BY video_id DESC";
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_videos) {
$filename = 'sitemap-videos-'.$count.'.xml';
$videos = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.BASE_URL.'/data/sitemap.xsl"?>',"n";
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',"n";
foreach ($videos as $video) {
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/'.$video['video_id'].'/'.$video['slug'].'/</loc>',"n";
echo ' <lastmod>'.$current_date.'</lastmod>',"n";
echo ' <changefreq>weekly</changefreq>',"n";
echo ' <priority>0.4</priority>',"n";
echo ' </url>',"n";
}
echo '</urlset>',"n";
$content = ob_get_contents();
ob_end_clean();
if ($videos) {
$file = BASE_DIR.'/sitemaps/'.$filename;
$index[] = array('url' => BASE_URL.'/sitemaps/'.$filename, 'lastmod' => $current_date);
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write videos sitemap file ('.$file.')! Aborting...';
return false;
}
}
$start = ($start + $amount);
++$count;
}
}
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?>', "n";
echo ' <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', "n";
foreach ($index as $key) {
echo ' <sitemap>',"n";
echo ' <loc>'.$key['url'].'</loc>',"n";
echo ' <lastmod>'.$key['lastmod'].'</lastmod>',"n";
echo ' </sitemap>',"n";
}
echo '</sitemapindex>';
$content = ob_get_contents();
ob_end_clean();
$file = BASE_DIR.'/sitemap.xml';
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write general sitemap file ('.$file.')! Aborting...';
return false;
}
if ($options['ping_google'] == '1') {
$response = VCurl::string('http://www.google.com/webmasters/tools/ping?sitemap='.urlencode(BASE_URL.'/sitemap.xml'));
}
if ($options['ping_bing'] == '1') {
$response = VCurl::string('http://www.bing.com/webmaster/ping.aspx?siteMap='.urlencode(BASE_URL.'/sitemap.xml'));
}
return true;
}
public static function getError()
{
return static::$error;
}
}