forked from awaln/datapress
/
wp-exhibit-insert-exhibit.php
199 lines (174 loc) · 7.45 KB
/
wp-exhibit-insert-exhibit.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
class WpExhibitHtmlBuilder {
static $datapress_statistics_logger = "http://projects.csail.mit.edu/datapress/logger/logger.php";
static function insert_exhibit($exhibit, $content) {
global $wp_query;
$exhibit_string = '';
if ($exhibit->get('lightbox')) {
$exhibit_string = self::get_exhibit_lightbox_link($exhibit);
} else {
$exhibit_string = self::get_inline_exhibit($exhibit);
}
if (is_feed()) {
$postid = $wp_query->post->ID;
$permalink = get_permalink($postid);
$exhibit_string .= "<p><b>Note: This post contains a interactive data presentation that may not show up in your feed reader.</b> For the full experience, visit <a href='$permalink'>this article</a> in your web browser.</p>";
}
$content = str_replace("{{Exhibit}}", $exhibit_string, $content);
$footnotes_string = self::get_data_footnotes_html($exhibit);
$content = str_replace("{{Footnotes}}", $footnotes_string, $content);
return $content;
}
static function get_exhibit_lightbox_link($exhibit) {
global $wp_query;
if (!$guessurl = site_url())
$guessurl = wp_guess_url();
$baseuri = $guessurl;
$exhibituri = $baseuri . '/wp-content/plugins/datapress';
$exhibitid = $exhibit->get('id');
$postid = $wp_query->post->ID;
$exhibit_html .= "<a href='$exhibituri/wp-exhibit-only.php?iframe&exhibitid=$exhibitid&postid=$postid¤tview=lightbox' class='exhibit_link_$exhibitid'>";
$exhibit_html .= "<div class='teaser' id='teaser_$exhibitid'>
<iframe src='$exhibituri/wp-exhibit-only.php?iframe&exhibitid=$exhibitid&postid=$postid¤tview=preview' width='100%' height='300' scrolling='no' frameborder='0'>
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div class='cover' id='cover_$exhibitid'>
</div>";
$exhibit_html .= "</a>";
return $exhibit_html;
}
static function get_inline_exhibit($exhibit) {
global $wp_query;
if (!$guessurl = site_url())
$guessurl = wp_guess_url();
$baseuri = $guessurl;
$exhibituri = $baseuri . '/wp-content/plugins/datapress';
$exhibitid = $exhibit->get('id');
$postid = $wp_query->post->ID;
$height = $exhibit->get('height');
$exhibit_html = "<iframe src='$exhibituri/wp-exhibit-only.php?iframe&exhibitid=$exhibitid&postid=$postid¤tview=inline' width='100%' height='$height' scrolling='auto' frameborder='0'>
<p>Your browser does not support iframes.</p>
</iframe>";
return $exhibit_html;
}
static function get_view_html($exhibit, $currentView, $postid) {
// add statistics gathering
$tracker_html = self::statistics_html($exhibit, $currentView, $postid);
// add views
$view_html = "";
if ($currentView == 'preview') {
foreach ($exhibit->get('views') as $view) {
$view_html .= $view->htmlContent();
return "$tracker_html $view_html";
}
}
else {
$grouped_html = "";
foreach ($exhibit->get('views') as $view) {
if ($view->get('ungrouped') == NULL) {
$grouped_html .= "\n" . $view->htmlContent();
}
}
$printedGroup = 0;
foreach ($exhibit->get('views') as $view) {
if (($view->get('ungrouped') == NULL) && (0 == $printedGroup)) {
$view_html .= "<div ex:role=\"viewPanel\">$grouped_html</div>";
$printedGroup = 1;
}
else {
//$view_html .= "\n" . $view->htmlContent();
}
}
}
if ($view_html == "") {
$view_html = "<div ex:role=\"view\"></div>";
}
// ex:role=\"viewPanel\">
return "$tracker_html $view_html";
}
static function get_exhibit_html($exhibit, $currentView, $postid) {
$view_html = self::get_view_html($exhibit, $currentView, $postid);
$lens_html = "";
foreach ($exhibit->get('lenses') as $lens) {
$lens_html = $lens_html . $lens->htmlContent();
$lens_html = $lens_html . "\n";
}
if ($currentView == 'preview') {
$exhibit_html = "$lens_html $view_html";
} else {
$top_facet_html = self::facet_html($exhibit->get('facets'), 'top');
$bottom_facet_html = self::facet_html($exhibit->get('facets'), 'bottom');
$left_facet_html = self::facet_html($exhibit->get('facets'), 'left');
$right_facet_html = self::facet_html($exhibit->get('facets'), 'right');
if ($exhibit->get('lightbox')) {
$right_facet_html .= self::facet_html($exhibit->get('facets'), 'widget');
}
$exhibit_colspan = 3;
if (strlen($left_facet_html) > 0) {
$exhibit_colspan--;
$left_facet_html = "<td width=\"15%\"> $left_facet_html </td>";
}
if (strlen($right_facet_html) > 0) {
$exhibit_colspan--;
$right_facet_html = "<td width=\"15%\"> $right_facet_html </td>";
}
$custom_html = "";
if ($exhibit->get('custom_html') != NULL) {
$custom_html .= $exhibit->get('custom_html');
}
$exhibit_html = "
$custom_html
$lens_html
<table class=\"dpcontainer\" width=\"100%\">
<tr>
<td colspan='3'>
$top_facet_html
</td>
</tr>
<tr valign=\"top\">
$left_facet_html
<td colspan='$exhibit_colspan'>$view_html</td>
$right_facet_html
</tr>
<tr>
<td colspan='3'>
$bottom_facet_html
</td>
</tr>
</table>";
}
return $exhibit_html;
}
static function statistics_html($exhibit, $currentView, $postid) {
$html = "";
if (get_option('datapress_et_phone_home') == "Y") {
$html .= "<script type='text/javascript'>\n";
$report = $exhibit->getStatisticReport($currentView, $postid);
$html .= "$.get('" . self::$datapress_statistics_logger . "', $report, null, 'script');\n";
$html .= "</script>\n";
}
return $html;
}
static function facet_html($facets, $location) {
$facet_html = "";
foreach ($facets as $facet) {
if ($facet->get('location') == $location) {
$facet_html = $facet_html . $facet->htmlContent();
$facet_html = $facet_html . "\n";
}
}
return $facet_html;
}
static function get_data_footnotes_html($exhibit) {
$html = "<ul>";
$ex_datasources = $exhibit->get('datasources');
foreach($ex_datasources as $ex_datasource) {
$sourcename = $ex_datasource->get('sourcename');
$uri = $ex_datasource->get('uri');
$html .= "<li> <a href='$uri'>$sourcename</a>\n";
}
$html .= "</ul>";
return $html;
}
}