-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSmartsheetIframe.php
74 lines (59 loc) · 2.41 KB
/
SmartsheetIframe.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
<?php
/**
* An extension that embeds a smartsheet via iframe.
*
* User supplies smartsheet ID, width, height
* Example: <smartsheet id="53e9029517dc4d8c8b799eaacfee9a1e" width="500" height="500" />
*
* Width/height optional defaults will be used
*
* @author Benjamin Sternthal <[email protected]>
* @license This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$wgExtensionCredits['other'][] = array(
'name' => 'Smartsheet',
'author' => 'Benjamin Sternthal With Inspiration From https://github.com/LegNeato/mediawiki-bugzilla',
'url' => 'https://github.com/bensternthal/Smartsheet-MediaWiki-Extension',
'description' => 'This extension allows embedding of a smartsheet within an iframe.'
);
//Defaults
$wgSmartsheetTagName = 'smartsheet'; // The tag name to be processed
$wgSmartsheetPublishURL = 'https://www.smartsheet.com/b/publish?embed=true&EQBCT='; // The URL for smartsheet published sheets
$wgSmartsheetIframeWidth = 1000; // Default width
$wgSmartsheetIframeHeight = 700; // Default height
// Hooks for plugin display
$wgHooks['ParserFirstCallInit'][] = 'SmartsheetParserInit';
// Hook our callback function into the parser
function SmartsheetParserInit( Parser &$parser ) {
global $wgSmartsheetTagName;
// Register the desired tag
$parser->setHook( $wgSmartsheetTagName, 'SmartsheetRender' );
// Let the other hooks keep processing
return TRUE;
}
// Function to be called when our tag is found by the parser
function SmartsheetRender($input, array $args) {
$attr = array();
global $wgSmartsheetPublishURL;
global $wgSmartsheetIframeWidth;
global $wgSmartsheetIframeHeight;
foreach($args as $key => $value ) {
$attr[$key] = $value;
}
// Handle defaults
if(!isset($attr['width'])) {
$attr['width'] = $wgSmartsheetIframeWidth;
};
if(!isset($attr['height'])) {
$attr['height'] = $wgSmartsheetIframeHeight;
};
// Assemble iframe
$output = '<iframe name="smartsheet" frameborder="0" '.
'src="'.$wgSmartsheetPublishURL . htmlspecialchars($attr['id']).'" ' .
'width="'.htmlspecialchars($attr['width']).'" '.
'height="'.htmlspecialchars($attr['height']).'">'.
'</iframe>';
return $output;
}