forked from hypercities/hypercities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetContent.php
More file actions
123 lines (99 loc) · 4.94 KB
/
Copy pathgetContent.php
File metadata and controls
123 lines (99 loc) · 4.94 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
// vim: ts=4:sw=4:nu:nospell
/**
* @file
* HyperCities query script for Object Content.
*
* Return the KML file that contain all children of given collection Id
* in View and Timespan
*
* @author HyperCities Tech Team
* @copyright Copyright 2008-2009, The Regents of the University of California
* @date 2009-06-28
* @version $Id$
*
*/
include_once('includes/dbUtil.inc');
include_once('includes/HCCollection.inc');
include_once('includes/serverSession.inc');
cServerSession::start();
HC_checkReferer();
$HC_POST = HC_sanitizeInput($_POST,
array('func'=>'str', 'cid'=>'int', 'pid'=>'int'),
array('func', 'cid'),
array('pid'));
$cid = $HC_POST['cid'];
$pid = $HC_POST['pid'];
$isLogin = false;
$isAdmin = false;
$openPublichFolder = '1';
// Creates the root KML Document.
$dom = new DomDocument('1.0','utf-8');
$kml = $dom->appendChild($dom->createElementNS('http://www.opengis.net/kml/2.2', 'kml'));
// Creates HyperCities Collection List document
$kmlDoc = $kml->appendChild($dom->createElement('Document'));
$kmlDoc->setAttribute('id', $cid);
$docName = $kmlDoc->appendChild($dom->createElement('name', 'HyperCities_Item_'.$cid.'.kml'));
$docDescription = $kmlDoc->appendChild($dom->createElement('description', "HyperCities Item $cid"));
// Get Children Info of Collection $cid
$children = HCCollection::getCollectionById($cid, $isAdmin);
// Loop through each children Node
foreach ($children as $index => $item) {
if ( $item['object_type_id'] == HC_OBJECT_TYPE_MEDIA ) {
// Is OBJECT, Create Placemark
$node = $kmlDoc->appendChild($dom->createElement('Placemark'));
$node->setAttribute('id', $item['object_id']);
$objectLink = "http:".$_SERVER['HTTP_HOST']."/object/".$item['object_id'].".kml";
$nodeName = $node->appendChild($dom->createElement('name', $item['title']));
$nodeDescription = $node->appendChild($dom->createElement('description'));
$nodeDescription->appendChild($dom->createCDATASection($item['description']));
$nodeLink = $node->appendChild($dom->createElement('link'));
$nodeHref = $nodeLink->appendChild($dom->createElement('href', $objectLink));
// Create Marker Style From KML Field
$sxe = simplexml_load_string($item['kml']);
$markerDom = dom_import_simplexml($sxe);
$markerNode = $dom->importNode($markerDom, true);
$node->appendChild($markerNode->getElementsByTagName("Style")->item(0));
$node->appendChild($markerNode->getElementsByTagName("Point")->item(0));
$node->appendChild($markerNode->getElementsByTagName("LineString")->item(0));
$node->appendChild($markerNode->getElementsByTagName("Polygon")->item(0));
$node->appendChild($markerNode->getElementsByTagName("LookAt")->item(0));
} else if ( $item['object_type_id'] == HC_OBJECT_TYPE_COLLECTION ) {
// Is Collection, Create NetworkLink
$node = $kmlDoc->appendChild($dom->createElement('NetworkLink'));
$node->setAttribute('id', $item['object_id']);
$collectionLink = "http://".$_SERVER['HTTP_HOST']."/collection/".$item['object_id'].".kml";
$collectionBound = "BBox=[".$item['sw_lon']."],[".$item['sw_lat']."],["
.$item['ne_lon']."],[".$item['ne_lat']."]";
$nodeName = $node->appendChild($dom->createElement('name', $item['title']));
$nodeOpen = $node->appendChild($dom->createElement('open', '0'));
$nodeLink = $node->appendChild($dom->createElement('link'));
$nodeHref = $nodeLink->appendChild($dom->createElement('href', $collectionLink));
// Add HyperCities Extended Data
$nodeHCData = $node->appendChild($dom->createElement('ExtendedData'));
$nodeHCData->setAttribute('xmlns:hc', 'http://hypercities.ats.ucla.edu');
$nodeHCDataViewFormat = $nodeHCData->appendChild($dom->createElement('hc:viewFormat', $collectionBound));
$nodeHCDataExternal = $nodeHCData->appendChild($dom->createElement('hc:external', '0'));
} else if ( $item['object_type_id'] == HC_OBJECT_TYPE_KML ) {
// Is KML, Create External NetworkLink
$node = $kmlDoc->appendChild($dom->createElement('NetworkLink'));
$node->setAttribute('id', $item['object_id']);
$collectionBound = "BBox=[".$item['sw_lon']."],[".$item['sw_lat']."],["
.$item['ne_lon']."],[".$item['ne_lat']."]";
$nodeName = $node->appendChild($dom->createElement('name', $item['title']));
$nodeOpen = $node->appendChild($dom->createElement('open', '0'));
$nodeLink = $node->appendChild($dom->createElement('link'));
$nodeHref = $nodeLink->appendChild($dom->createElement('href', htmlentities($item['kml'])));
// Add HyperCities Extended Data
$nodeHCData = $node->appendChild($dom->createElement('ExtendedData'));
$nodeHCData->setAttribute('xmlns:hc', 'http://hypercities.ats.ucla.edu');
$nodeHCDataViewFormat = $nodeHCData->appendChild($dom->createElement('hc:viewFormat', $collectionBound));
$nodeHCDataExternal = $nodeHCData->appendChild($dom->createElement('hc:external', '1'));
}
}
// Output Final KML Files
$dom->formatOutput = true;
$collection_xml = $dom->saveXML($dom->documentElement);
header('Content-type: application/xml');
echo $collection_xml;
?>