-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.php
155 lines (136 loc) · 5.41 KB
/
map.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
$replies = get_comments(array(
'status' => 'approve',
'post_id' => get_the_ID(),
'orderby' => 'date'
));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
<title><?php the_title(); ?> (Map) | <?php bloginfo('name'); ?></title>
<link href='http://fonts.googleapis.com/css?family=Junge' rel='stylesheet' type='text/css'>
<?php wp_head(); ?>
</head>
<body class="knbu-map-view <?php echo isset($_GET['map-frame']) ? 'knbu-map-frame' : 'knbu-map-full'; ?>">
<div id="map">
<div id="raven"></div>
<div id="fps"></div>
<div id="grouping">
Show notes: <select id="grouping-select">
<option value="discussion">as discussion</option>
<option value="knowledgetypes">by knowledge types</option>
<option value="users">by authors</option>
<option value="time">by time</option>
</select>
</div>
<div id="navigation">
<img src="<?php echo plugins_url('knowledge-building'); ?>/images/toggle-hide.png" width="15" height="15" id="navi-toggle-button">
<div id="navi-toggle-container">
<div id="pan">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/navi-bg.png" id="navigation-background">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/arrow-left.png" class="arrow" id="arrow-left">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/arrow-up.png" class="arrow" id="arrow-up">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/arrow-right.png" class="arrow" id="arrow-right">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/arrow-down.png" class="arrow" id="arrow-down">
<img src="<?php echo plugins_url(); ?>/knowledge-building/images/center.png" class="arrow" id="arrow-center">
</div>
+<div id="zoom"></div>-
</div>
</div>
<div id="legend">
<ul>
<?php knbu_get_legends(); ?>
</ul>
</div>
<?php if(isset($_GET['map-frame'])) { ?>
<div id="full-screen">
<a href="<?php echo remove_query_arg( 'map-frame' ); ?>" target="_blank">
<img src="<?php echo plugins_url() ?>/knowledge-building/images/full-screen.png" id="full-screen">
</a>
</div>
<?php } ?>
</div>
<div id="message"><?php knbu_comment(get_the_ID()); ?></div>
<?php
usort($replies, 'knbu_cmp');
knbu_get_childs(get_the_ID(), $replies);
?>
</body>
</html>
<?php
function knbu_get_childs($id, $replies) {
global $knowledgeTypes, $knbu_kbsets, $post;
// The post itself will be the starting node
$nodes = array(
array(
'id' => 0,
'parent' => false,
'content' => $post->post_content,
'avatar' => knbu_get_avatar_url( $post->user_id ),
'username' => get_the_author_meta( 'display_name', $post->post_author ),
'email' => $post->user_email,
'date' => date(get_option('date_format'), strtotime($post->post_date)),
'time' => date(get_option('time_format'), strtotime($post->post_date)),
'timestamp' => strtotime( $post->post_date ),
'typeName' => 'Start',
'title' => $post->post_title,
'static' => true,
'index' => 1
)
);
$map_index = get_post_meta( $id, 'knbu_map_index', true);
if(empty($map_index))
$map_index = 2;
foreach($replies as $reply) {
// Get comment meta data
// Should be combined to one variable(?)
$type = get_comment_meta($reply->comment_ID, 'kbtype', true);
$title = get_comment_meta($reply->comment_ID, 'comment_title', true);
$node_index = get_comment_meta( $reply->comment_ID, 'knbu_map_comment_index' );
$anchor = json_decode(get_comment_meta($reply->comment_ID, 'node_position', true));
// Default values
$name = 'Unspecified';
$color = '#fff';
// Get type name and color
foreach($knbu_kbsets[knbu_get_kbset_for_post(get_the_ID())]->KnowledgeTypeSet->KnowledgeType as $t) {
if($t['ID'] == $type) {
$name = (string)$t['Name'];
$color = (string)$t['Colour'];
}
}
// If there's no title, get some text from content to be one
$title = knbu_generate_title($title, $reply->comment_content);
// Check if there's no index set for the note
if(empty($node_index)) {
$node_index = $map_index;
$map_index++;
update_comment_meta( $reply->comment_ID, 'knbu_map_comment_index', $node_index );
update_post_meta( $id, 'knbu_map_index', $map_index);
}
$reply->user_email = isset($reply->user_email) ? $reply->user_email : '';
$nodes[] = array(
'id' => $reply->comment_ID,
'parent' => $reply->comment_parent,
'content' => $reply->comment_content,
'avatar' => knbu_get_avatar_url($reply->user_id),
'username' => $reply->comment_author,
'email' => $reply->user_email,
'date' => date(get_option('date_format').' '.get_option('time_format'), strtotime($reply->comment_date)),
'timestamp' => strtotime($reply->comment_date),
'title' => $title,
'typeName' => $name,
'anchor' => $anchor,
'color' => $color,
'index' => $node_index
);
}
echo '<script type="text/javascript">var NodesFromServer = '.json_encode($nodes).'; var MapIndexFromServer = '.$map_index.'; var plugin_url = "'.plugins_url('knowledge-building').'";</script>';
}
function knbu_cmp($a, $b) {
if(strtotime($a->comment_date) == strtotime($b->comment_date))
return 0;
return strtotime($a->comment_date) > strtotime($b->comment_date) ? 1 : -1;
}
?>