-
Notifications
You must be signed in to change notification settings - Fork 4
/
rdftemplating.inc.php
76 lines (63 loc) · 2.11 KB
/
rdftemplating.inc.php
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
<?php
include_once('rdfwriter.inc.php');
include_once('urischeme.inc.php');
function about($uri, $type = null) {
global $___template_engine;
$___template_engine->get_writer()->subject($uri);
if ($type) {
$___template_engine->get_writer()->property_qname('a', $type);
}
}
function property($property, $content, $datatype = null) {
global $___template_engine;
$___template_engine->get_writer()->property_literal($property, $content, $datatype);
}
function rel($property, $uri) {
global $___template_engine;
$___template_engine->get_writer()->property_uri($property, $uri);
}
function rev($property, $uri) {
global $___template_engine;
$___template_engine->get_writer()->triple_uri($uri, $property,
$___template_engine->get_writer()->get_subject());
}
function include_template($template, $data = array()) {
global $___template_engine;
$___template_engine->include_template($template, $data);
}
class TemplateEngine {
var $_namespaces;
var $_uri_scheme;
var $_writer;
var $_template_data_stack = array();
function __construct($uri_scheme, $namespaces) {
$this->_namespaces = $namespaces;
$this->_uri_scheme = $uri_scheme;
$this->_writer = new RDFWriter($this->_namespaces);
global $___template_engine;
$___template_engine = $this;
array_push($this->_template_data_stack, array('modified' => date('c')));
}
function get_writer() {
return $this->_writer;
}
function write($filename) {
$this->_writer->to_turtle_file($filename);
}
function render_template($template, $data = null) {
$this->_run_template($template, $data);
}
function include_template($template, $data = null) {
$this->_run_template($template, $data);
}
function _run_template($template, $data = array()) {
$merged_data = array_merge($this->_template_data_stack[count($this->_template_data_stack) - 1], (array) $data);
foreach ($merged_data as $key => $value) {
$$key = $value;
}
$uris = $this->_uri_scheme;
array_push($this->_template_data_stack, $merged_data);
include "templates/$template.inc.php";
array_pop($this->_template_data_stack);
}
}