<?php
define('FORUM_ADMIN','1');
define(INCLUDE_PATH,"../../../");
$tm_include='';
require_once(INCLUDE_PATH."config.php");
require_once(INCLUDE_PATH."db/db.php");
require_once("../lib/com/sergids/topmusic/model/ConfigDAO.php");
require_once("../lib/com/sergids/common/PHPNuke.php");
$module_name=PHPNuke::getModuleName(__FILE__);
require_once("../../../modules/$module_name/admin/lib/com/sergids/topmusic/model/ConfigAdminDAO.php");
require_once("../../../modules/$module_name/admin/lib/com/sergids/topmusic/model/ArtistAdminDAO.php");
require_once("../../../modules/$module_name/admin/lib/com/sergids/topmusic/model/AlbumAdminDAO.php");
require_once("../../../modules/$module_name/admin/lib/com/sergids/topmusic/model/SongAdminDAO.php");
require_once("../../../modules/$module_name/admin/lib/com/sergids/topmusic/model/ArtistAdmin.php");
global $prefix,$db,$language,$dbhost;
//load configuration
$confDAO=new ConfigDAO($db,$prefix);
$configAdminDAO=new ConfigAdminDAO($db,$prefix);
$configAdmin=$configAdminDAO->load();
define(_TOPMUSIC_MODULENAME,$module_name);
define(_TOPMUSIC_BASEURL,$configAdmin->baseURL);
$artistDAO = new ArtistAdminDAO($db,$prefix);
$albumDAO = new AlbumAdminDAO($db,$prefix);
$songDAO = new SongAdminDAO($db,$prefix);
$artistOO = new ArtistAdmin();
$artistList=$artistDAO->getArtistIndex();
//header('Content-type: text/xml');
//header('Content-Disposition: attachment; filename="sitemap2.xml"');
$content= "<?xml version = '1.0' encoding = 'UTF-8'?>\n
<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n\n";
$content_artist=$content;
$content_album=$content;
$content_song=$content;
foreach($artistList as $artist){
$content_artist.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/artist".$artist->id."-".urlencode($artist->name).".html</loc>\n\t</url>\n";
$content_artist.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/biography".$artist->id."-".urlencode($artist->name).".html</loc>\n\t</url>\n";
$content_artist.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/discography".$artist->id."-".urlencode($artist->name).".html</loc>\n\t</url>\n";
$albumList=$albumDAO->getAlbumList($artist->id,$language);
if(count($albumList)>0){
foreach($albumList as $album){
$content_album.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/album".$artist->id."_".$album->id."-".urlencode($album->title).".html</loc>\n\t</url>\n";
$songList=$songDAO->getSongList($album->id,$language);
if(count($songList)>0){
foreach($songList as $song){
$content_song.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/song".$artist->id."_".$album->id."_".$song->id."-".urlencode($song->title).".html</loc>\n\t</url>\n";
}
}
}
}
}
$content_artist.="</urlset>";
$content_album.="</urlset>";
$content_song.="</urlset>";
$content_common=$content;
$content_common.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/tops.html</loc>\n\t</url>\n";
$content_common.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/search.html</loc>\n\t</url>\n";
$content_common.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/az.html</loc>\n\t</url>\n";
if(count($artistList)>0){
$artistAZ=$artistOO->orderAZ($artistList);
$letters=$artistAZ[0];
$artistAZ=null;
foreach($letters as $letter){
$content_common.="\t<url>\n\t\t<loc>"._TOPMUSIC_BASEURL."/az-".$letter.".html</loc>\n\t</url>\n";
}
}
$content_common.="</urlset>";
$filename_common = dirname(__FILE__).'/../../../sitemap_tm_common.xml';
$filename_artist = dirname(__FILE__).'/../../../sitemap_tm_artist.xml';
$filename_album = dirname(__FILE__).'/../../../sitemap_tm_album.xml';
$filename_song = dirname(__FILE__).'/../../../sitemap_tm_song.xml';
checkFile($filename_common);
updateFile($filename_common,$content_common);
checkFile($filename_artist);
updateFile($filename_artist,$content_artist);
checkFile($filename_album);
updateFile($filename_album,$content_album);
checkFile($filename_song);
updateFile($filename_song,$content_song);
function checkFile($filename){
if(!file_exists($filename)){
if(!@touch($filename))
print "<font color=\"red\">File $filename doesn't exist and can't be created.<br><b>Create an empty file in root directory called ".basename($filename)."</b></font><br>";
}
}
function updateFile($filename,$content){
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w'))
echo "<font color=\"red\">Cannot open file ($filename)</font>";
else{
if (fwrite($handle, $content) === FALSE)
echo "<font color=\"red\">Cannot write to file ($filename)</font>";
else
echo "<font color=\"green\">Success, <b>".basename($filename)."</b> generated in root directory<br>Submit the file to <a href=\"http://www.google.com/webmasters/sitemaps\" target=\"_blank\">Google Sitemaps</a></font><br>";
fclose($handle);
}
} elseif(file_exists($filename))
echo "<font color=\"red\">The file <b>".basename($filename)."</b> is not writable<br>Change file permisions to 777 and try again.</font><br>";
}
?>