summaryrefslogtreecommitdiff
path: root/sitemap.php
blob: 3a1f189bb3cc4d09cb5a9e3176ad4e1da876e8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * Copyright (c) 2004 bitweaver.org
 * Copyright (c) 2003 tikwiki.org
 * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
 * All Rights Reserved. See below for details and a complete list of authors.
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
 *
 * @package wiki
 * @subpackage functions
 */

/**
 * required setup
 */
require_once '../kernel/includes/setup_inc.php';
use Bitweaver\Wiki\BitBook;
use Bitweaver\Liberty\LibertyContent;
use Bitweaver\Liberty\LibertyStructure;

$book = new BitBook();
$gSiteMapHash = [];

$listHash = [];

if( $bookList = $book->getList( $listHash ) ) {
	foreach( $bookList['data'] as $bookHash ) {
		$bookStructure = new LibertyStructure( $bookHash['structure_id'] );
		if( $rootObject = LibertyContent::getLibertyObject( $bookStructure->getField( 'content_id' ), $bookStructure->getField( 'content_type_guid' ) ) ) {
			if( $rootObject->isPublic() ) {
				$listBook = $bookStructure->buildTreeToc( $bookHash['structure_id'] );
				process_book_list( $listBook );
			}
		}
	}
}

function process_book_list( $pList, $pDepth = 1 ) {
	global $gSiteMapHash;
	foreach( array_keys( $pList ) as $key ) {
		if( !empty( $pList[$key]['display_url'] ) ) {
			$hash = [];
			$hash['loc'] =  BIT_BASE_URI.$pList[$key]['display_url'];
			$hash['lastmod'] = date( 'Y-m-d', $pList[$key]['last_modified'] );
			if( (time() - $pList[$key]['last_modified']) < 86400 ) {
				$freq = 'daily';
			} elseif( (time() - $pList[$key]['last_modified']) < (86400 * 7) ) {
				$freq = 'weekly';
			} else {
				$freq = 'monthly';
			}

			$hash['changefreq'] = $freq;
			$hash['priority'] = 1 - round( $pDepth * .5 ) * .1;
			$gSiteMapHash[$pList[$key]['content_id']] = $hash;
		}
		if( !empty( $pList[$key]['sub'] ) ) {
			process_book_list( $pList[$key]['sub'], $pDepth + 1 );
		}
	}
}

$gBitSmarty->assign( 'gSiteMapHash', $gSiteMapHash );
$gBitThemes->setFormatHeader( 'xml' );
print $gBitSmarty->display( 'bitpackage:kernel/sitemap.tpl' );