Файл: adultscript-2.0.3-pro/files/admin/modules/video/helpers/sitemap.php
Строк: 138
<?php
class VHelper_video_sitemap
{
private static $error;
public static function build($options = array())
{
$options = ($options) ? $options : array(
'max_per_file' => 35000,
'use_location' => 0,
'use_player' => 1,
'ping_google' => 1
);
$file = BASE_DIR.'/sitemap-video.xml';
if (!file_exists($file) OR !is_file($file) OR !is_writable($file)) {
static::$error = 'Sitemap file ('.$file.') not found or not writable!';
return false;
}
$db = VF::factory('database');
$current_date = date('Y-m-d');
$index = array();
$sql_count = "SELECT COUNT(*) AS total_videos
FROM #__video
WHERE status = 1";
$total_videos = $db->get_field($sql_count, 'total_videos');
$sql = "SELECT v.video_id, v.title, v.slug, v.description, v.ext, v.duration,
v.rating, v.thumb, v.total_views, v.add_time, v.premium, u.username,
GROUP_CONCAT(DISTINCT vc.name) AS categories,
GROUP_CONCAT(DISTINCT t.name) AS tags
FROM #__video AS v
INNER JOIN #__video_category AS c ON (c.video_id = v.video_id)
INNER JOIN #__video_categories AS vc ON (vc.cat_id = c.cat_id)
INNER JOIN #__video_tags AS t ON (t.video_id = v.video_id)
INNER JOIN #__user AS u ON (u.user_id = v.user_id)
WHERE v.status = 1
AND v.embed_code = ''
GROUP BY v.video_id
ORDER BY video_id DESC";
$count = 1;
$start = 0;
$amount = $options['max_per_file'];
while ($start <= $total_videos) {
$filename = 'sitemap-video-'.$count.'.xml';
$videos = $db->get_rows($sql.' LIMIT '.$start.', '.$amount);
ob_start();
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"',"n";
echo ' xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">',"n";
foreach ($videos as $video) {
$player = BASE_URL.'/misc/flowplayer/flowplayer.swf?config='.BASE_URL.'/modules/video/player/config_embed.php?id='.$video['video_id'];
echo ' <url>',"n";
echo ' <loc>'.BASE_URL.'/'.$video['video_id'].'/'.$video['slug'].'/</loc>',"n";
echo ' <video:video>',"n";
echo ' <video:thumbnail_loc>'.BASE_URL.'/media/videos/tmb/'.path($video['video_id']).'/'.$video['thumb'].'.jpg</video:thumbnail_loc>',"n";
if ($options['use_location'] == '1') {
echo ' <video:content_loc>'.BASE_URL.'/media/videos/'.$video['ext'].'/'.$video['video_id'].'.'.$video['ext'].'</video:content_loc>',"n";
}
if ($options['use_player'] == '1') {
echo ' <video:player_loc allow_embed="yes">'.$player.'</video:player_loc>',"n";
}
echo ' <video:title>'.e($video['title']).'</video:title>',"n";
echo ' <video:description>'.e($video['description']).'</video:description>',"n";
echo ' <video:duration>'.(int) $video['duration'].'</video:duration>',"n";
echo ' <video:rating>'.$video['rating'].'</video:rating>',"n";
echo ' <video:view_count>'.$video['total_views'].'</video:view_count>',"n";
echo ' <video:publication_date>'.date('Y-m-d', $video['add_time']).'</video:publication_date>',"n";
$tags = explode(',', $video['tags']);
foreach ($tags as $tag) {
echo ' <video:tag>'.e($tag).'</video:tag>',"n";
}
$categories = explode(',', $video['categories']);
echo ' <video:category>'.e($categories['0']).'</video:category>',"n";
echo ' <video:family_friendly>no</video:family_friendly>',"n";
$subscription = ($video['premium'] == '1') ? 'yes' : 'no';
echo ' <video:requires_subscription>'.$subscription.'</video:requires_subscription>',"n";
echo ' <video:uploader info="'.BASE_URL.'/users/'.$video['username'].'/">'.e($video['username']).'</video:uploader>',"n";
// we still need gallery_loc, price, restriction if applicable
echo ' </video:video>',"n";
echo ' </url>',"n";
}
echo '</urlset>';
$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 videos sitemap file ('.$file.')!';
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-video.xml';
if (!VFile::write($file, $content)) {
static::$error = 'Failed to write video sitemap index file ('.$file.')!';
return false;
}
if ($options['ping_google'] == '1') {
$response = VCurl::string('http://www.google.com/webmasters/tools/ping?sitemap='.urlencode(BASE_URL.'/sitemap-video.xml'));
}
return true;
}
public static function getError()
{
return static::$error;
}
}