This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.php
184 lines (171 loc) · 5.6 KB
/
syntax.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
<?php
/*
* Copyright (c) 2014-2016 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
if (!defined('DOKU_INC'))
die ();
if (!defined('DOKU_PLUGIN'))
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once (DOKU_PLUGIN . 'syntax.php');
/**
* DokuWiki Plugin mapillary (Syntax Component).
*
* Handles the rendering part of the Mapillary plugin.
*
* @license BSD license
* @author Mark C. Prins <mprins@users.sf.net>
*/
class syntax_plugin_mapillary extends DokuWiki_Syntax_Plugin {
/**
*
* @see DokuWiki_Syntax_Plugin::getType()
*/
public function getType() {
return 'substition';
}
/**
*
* @see DokuWiki_Syntax_Plugin::getPType()
*/
public function getPType() {
return 'block';
}
/**
*
* @see Doku_Parser_Mode::getSort()
*/
public function getSort() {
return 305;
}
/**
* Define the syntax pattern.
* The syntax for this plugin is: {{mapillary>imagehash&width&sequences&legs}}
* where imagehash is the hash of the first image of a sequence
* and width is the widget width in pixels. One (optional) space
* either after the opening pair of brackets or before the closing
* pair signifies floating aligment to right of left.
*
* @see http://www.mapillary.com/integrate.html
*
* @see Doku_Parser_Mode::connectTo()
*/
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{\s?mapillary>[^}\s]*\s?\}\}', $mode, 'plugin_mapillary');
}
/**
* parse the syntax.
*
* @see DokuWiki_Syntax_Plugin::handle()
*/
public function handle($match, $state, $pos, Doku_Handler $handler) {
// check for float assignment left/right
$float = 'none';
$space = stripos($match, ' ');
if ($space > 0) {
if ($space < 12) {
$float = 'right';
}
if ($space > 12) {
$float = 'left';
}
}
// parse te match
$match = substr(str_replace(' ', '', $match), 12, - 2);
$params = explode('&', $match);
list ($img, $width, $sequences, $legs) = $params;
//TODO add support for showImage=
//TODO add support for showPlayControls=
//TODO add support for showMap=
//TODO add support for directions=
//TODO add support for showThumbs=
// make sure we have a min. width & sanity check
$width = intval($width);
if ($width < 100)
$width = 320;
if ($width > 2048)
$width = 2048;
return array(
hsc($img),
$width,
hsc($sequences),
hsc($legs),
$float
);
}
/**
* Render the syntax for xhtml, odt or metadata.
*
* @see DokuWiki_Syntax_Plugin::render()
*
* @see http://www.mapillary.com/javascripts/mapillary.js
* @see https://dga406zepc8gy.cloudfront.net/javascripts/mapillary.js
*/
public function render($mode, Doku_Renderer $renderer, $data) {
if ($data === false) {
return false;
}
static $id = 0;
list ($image, $width, $sequences, $legs, $float) = $data;
// this url might break, no idea if this url will be persistant but it
// is mentioned in the api docs
$image_url = 'http://d1cuyjsrcm0gby.cloudfront.net/' . $image . '/thumb-1024.jpg';
if ($mode == 'xhtml') {
// based on the embed javascript at http://www.mapillary.com/integrate.html
// TODO this used to work but not anaymore $height = ($width / 4 * 3 * 2 - 30);
/*h= map div height + photo + location,author etc + mapillary link*/
$height = 150 + 3 / 4 * intval($width) + 40 + 20;
$url = '//www.mapillary.com/jsapi/?';
if (!empty ($image)) {
$url .= 'image=' . $image . '&';
}
if (!empty ($sequences)) {
$url .= 'sequences=' . $sequences . '&';
}
if (!empty ($legs)) {
$url .= 'legs=' . $legs;
}
$renderer->doc .= '<div id="mapillary-' . $id . '" class="mapillary-' . $float . '">';
$renderer->doc .= '<iframe src="' . $url . '" id="mapillary-iframe-' . $id . '"';
$renderer->doc .= ' style="width:' . $width . 'px;height:' . $height . 'px;"; title="Mapillary (' . $image . ')">';
$renderer->doc .= '</iframe>';
$renderer->doc .= '<figure class="mapillary-print">';
$renderer->externalmedia($image_url, 'Mapillary (' . $image . ')', 'left', 1024, null, 'cache', 'nolink');
$renderer->doc .= '<figcaption>Mapillary: ';
$renderer->externallink('http://www.mapillary.com/map/im/' . $image, $image);
$renderer->doc .= ' (CC BY-SA 4.0)</figcaption></figure>';
$renderer->doc .= '</div>';
$id ++;
return true;
} elseif ($mode == 'metadata') {
global $ID;
$rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE);
$img = $rel [ 'firstimage' ];
if (empty ($img)) {
$renderer->externalmedia($image_url, 'Mapillary (' . $image . ')');
}
return true;
} elseif ($mode == 'odt') {
$renderer->p_open();
$renderer->externalmedia($image_url, 'Mapillary (' . $image . ')', 'left', 1024, null, 'cache', 'nolink');
$renderer->linebreak();
$renderer->cdata('Mapillary: ');
$renderer->externallink('http://www.mapillary.com/map/im/' . $image, $image);
$renderer->cdata(' (CC BY-SA 4.0)');
$renderer->p_close();
return true;
}
return false;
}
}