Commit 6708683f authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

host and sourceKey oriented sitemap

parent 1bd2828c
......@@ -182,10 +182,42 @@ class DefaultController extends CommunecterController {
$this->redirect(Yii::app()->createUrl("/".$this->module->id));
}
public function actionSitemap($type=null)
public function actionSitemap($sourceKey=null,$host=null)
{
$list = PHDB::find( "slugs" , array(), array("name","elemUpdated") );
$this->renderPartial("sitemap",array("list"=>$list));
$list = null;
//dont reference private project to search engines
$p = array(
'$or' =>array(
array( "preferences.private"=> array( '$exists' => true, '$in' => array( "false", false ) )),
array( "preferences.private"=>array( '$exists' => false))
)
) ;
//reduce search to sourceKey
if( isset($sourceKey )){
$list = array();
$p["source.key"] = $sourceKey;
$list = array_merge(
PHDB::find ( Organization::COLLECTION , $p , array("slug","updated") ),
PHDB::find ( Project::COLLECTION , $p , array("slug","updated") ),
PHDB::find ( Event::COLLECTION , $p , array("slug","updated") )
);
}
//value only Organizations, Projects and Events
$list = array_merge(
PHDB::find ( Organization::COLLECTION , $p , array("slug","updated") ),
PHDB::find ( Project::COLLECTION , $p , array("slug","updated") ),
PHDB::find ( Event::COLLECTION , $p , array("slug","updated") )
);
//var_dump($list);
$this->renderPartial("sitemap",array(
"list"=>$list,
"host"=>(isset($host)) ? $host : "www.communecter.org",
));
}
public function actionRemoveData($type=null){
......
......@@ -2,11 +2,11 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" >
<?php
foreach ($list as $key => $value) {
if(isset($value["name"])){
if(isset($value["name"]) || isset($value["slug"])){
?>
<url>
<loc>https://www.communecter.org/#@<?php echo $value["name"]?></loc>
<lastmod><?php echo date("Y-m-d",@$value["elemUpdated"])?></lastmod>
<loc>https://<?php echo $host; ?>/#@<?php echo ( isset($value["slug"])) ? $value["slug"] : $value["name"]?></loc>
<lastmod><?php echo date( "Y-m-d",( isset($value["updated"])) ? $value["updated"] : @$value["elemUpdated"])?></lastmod>
</url>
<?php
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment