-
Notifications
You must be signed in to change notification settings - Fork 2
/
archive.php
104 lines (87 loc) · 3.07 KB
/
archive.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
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
<?
session_start();
require_once('vendor/init.php');
require_once('vendor/sloph/summary.php');
$headers = apache_request_headers();
$ct = $headers["Accept"];
$acceptheaders = new AcceptHeader($ct);
$base = "https://rhiaro.co.uk";
$archive_uri = "https://rhiaro.co.uk/archive";
$graph = new EasyRdf_Graph($archive_uri);
$graph->addType($archive_uri, "as:Collection");
$graph->add($archive_uri, "as:name", "Archive");
$graph->add($archive_uri, "as:summary", "Contains links to collections of posts by date and by type.");
$types_count = array(
"as:Article" => array("label" => "articles", "url" => "/articles"),
"as:Note" => array("label" => "notes", "url" => "/notes"),
"as:Add" => array("label" => "photos and bookmarks", "url" => "/bookmarks"),
"as:Arrive" => array("label" => "checkins", "url" => "/arrives"),
"asext:Consume" => array("label" => "food logs", "url" => "/eats"),
"asext:Acquire" => array("label" => "stuff logs", "url" => "/stuff"),
"as:Like" => array("label" => "likes", "url" => "/likes"),
"as:Event" => array("label" => "events", "url" => "/events"),
"as:Accept" => array("label" => "rsvps", "url" => "/rsvps"),
"asext:Write" => array("label" => "word count logs", "url" => "/words"),
"as:Travel" => array("label" => "travel plans", "url" => "/travel")
);
foreach($types_count as $type => $data){
$q = query_count_type($type);
$res = execute_query($ep, $q);
$types_count[$type]["count"] = $res["rows"][0]["c"];
$graph->addResource($archive_uri, "as:items", $base.$data["url"]);
}
$dates_count = array();
$now = new DateTime();
$start = new DateTime("2004-01-01");
// $types = array("as:Article", "as:Note", "as:Add");
$types = array("as:Article", "as:Note");
$from = $start->format(DATE_ATOM);
$to = $now->format(DATE_ATOM);
$q = query_select_s_between_types($from, $to, $types);
$res = execute_query($ep, $q);
foreach($res["rows"] as $r){
$pub = new DateTime($r["d"]);
$year = $pub->format("Y");
$month = $pub->format("m");
if(!isset($dates_count[$year])){
$dates_count[$year]["total"] = 1;
}else{
$dates_count[$year]["total"] += 1;
}
if(!isset($dates_count[$year][$month])){
$dates_count[$year][$month] = 1;
}else{
$dates_count[$year][$month] += 1;
}
}
foreach($dates_count as $year => $data){
ksort($dates_count[$year]);
$graph->addResource($archive_uri, "as:items", $base."/$year/");
foreach($data as $month => $count){
if($month != "total"){
$graph->addResource($archive_uri, "as:items", $base."/$year/".$month."/");
}
}
}
krsort($dates_count);
$result = conneg($acceptheaders, $graph);
$header = $result['header'];
$content = $result['content'];
try {
if(gettype($content) == "string"){
header($header);
echo $content;
}else{
$resource = $graph->resource($archive_uri);
if(!$resource->get('view:stylesheet')){
$resource->addLiteral('view:stylesheet', "views/".get_style($resource).".css");
}
$g = $resource->getGraph();
$resource = $g->toRdfPhp();
$includes = array('listing_archive.php');
include 'views/page_template.php';
}
}catch(Exception $e){
var_dump($e);
}
?>