Location: PHPKode > projects > Anantasoft Gazelle CMS > sitemap.php
<?php
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
';

include("settings.php");
include("modules/databaseconnection.php");

// get user's permissions: articles the user shouldn't see can't show up
$perms = mysql_query("select number from ".$tableprefix."permissions"); // initiate all permissions
while ($perm = mysql_fetch_array($perms, MYSQL_ASSOC)) {
	$auth[$perm{'number'}] = 0;
}
$auth[1] = 1; // every visitor has permission 'Everyone', hidden pages should not be known to general public ;)

// set the link to our article
$url = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
	$url = $url."s";
}
$url = $url."://";
if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] <> "80") {
	$url = $url.$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
	$url = $url.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}

$curpage = str_replace("sitemap", "index", $url);

function menu($nr) {
	global $tableprefix, $auth;
	// admin panel results shouldn't show up
	$menus = mysql_query("select parent, name, permissions from ".$tableprefix."menus where number='".$nr."' and backend='0'");
	while ($menu = mysql_fetch_array($menus, MYSQL_ASSOC)) {
		$authenticated = 0;
		$perms = $menu{'permissions'};
		if ($auth[2] == 1) {
			$authenticated = 1; // if user is admin, then he definately can see everything
		}
		while ($perms <> "" && $authenticated <> 1) { // even if we belong to more then 1 usergroup, if you have permissions to see this menu item in just 1 group, you can see it, so we don't have to look further
			if (strpos($perms, ",")) { // 
				if ($auth[substr($perms, 0, strpos($perms, ","))] == 1) {
					$authenticated = 1;
				}
				$perms = substr($perms, strpos($perms, ",") + 1);
			} else {
				if ($auth[$perms] == 1) {
					$authenticated = 1;
				}
				$perms = "";
			}
		}
		if ($authenticated == 1) { // hoorray, we may see it!
			if ($menu{'parent'} == "0") {
				return $menu{'name'};
			} else {
				$parents = menu($menu{'parent'});
				if ($parents) {
					return $parents."/".$menu{'name'};
				} else {
					return "";
				}
			}
		} else {
			return "";
		}
	}
	return "";
}

$q = mysql_query("select number, showper from ".$tableprefix."menus where backend='0' order by parent, sort");
while ($k = mysql_fetch_array($q, MYSQL_ASSOC)) {
	$menu = menu($k{'number'});
	if ($menu) {
		$lastmod = "1970-01-01";
		$totalart = 0;
		$q2 = mysql_query("select edittime from ".$tableprefix."content where parent='".$k{'number'}."' order by edittime desc");
		while ($k2 = mysql_fetch_array($q2, MYSQL_ASSOC)) {
			if ($lastmod == "1970-01-01") {
				$lastmod = date('Y-m-d', strtotime($k2{'edittime'}));
			}
			$totalart++;
		}
		$priority = 1 - (0.1 * substr_count($menu, "/"));
		if ($k{'showper'} <> 0) {
			for ($i = 0; $i < $totalart; $i = $i + $k{'showper'}) {
				$page = "";
				if ($i/$k{'showper'} <> 0) {
					$page = "&amp;page=".(($i / $k{'showper'}) + 1);
				}
				echo '
	<url>
		<loc>'.$curpage.'?'.$menu.$page.'</loc>
		<lastmod>'.$lastmod.'</lastmod>
		<priority>'.($priority - (0.1 * $i / $k{'showper'})).'</priority>
	</url>';
			}
		} else {
			echo '
	<url>
		<loc>'.$curpage.'?'.$menu.'</loc>
		<lastmod>'.$lastmod.'</lastmod>
		<priority>'.$priority.'</priority>
	</url>';
		}
		$priority = 1;
		$q2 = mysql_query("select title, edittime from ".$tableprefix."content where parent='".$k{'number'}."' order by sort");
		while ($k2 = mysql_fetch_array($q2, MYSQL_ASSOC)) {
			echo '
	<url>
		<loc>'.str_replace("index", "article", $curpage).'?'.$menu."/".$k2{'title'}.'</loc>
		<lastmod>'.date('Y-m-d', strtotime($k2{'edittime'})).'</lastmod>
		<priority>'.$priority.'</priority>
	</url>';
			if ($priority > 0) {
				$priority = $priority - 0.1;
			}
		}	
	}
}

include_once("modules/closeconnection.php"); // close database connection

echo '
</urlset>';
?>
Return current item: Anantasoft Gazelle CMS