-
Notifications
You must be signed in to change notification settings - Fork 1
/
Firebase.hooks.php
47 lines (39 loc) · 1.8 KB
/
Firebase.hooks.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
<?php
class FirebaseHooks {
public static function onBeforePageDisplay(&$out, &$skin) {
$out->addModules( 'ext.Firebase' );
return true;
}
public static function onParserFirstCallInit( Parser $parser ) {
$parser->setHook( 'firebase', 'FirebaseHooks::wfFirebaseRender' );
$parser->setFunctionTagHook( 'firebaseraw', 'FirebaseHooks::wfFirebaseRenderRaw', '' );
return true;
}
// raw replaces the firebase tag with plain text read from the firebase reference once
public static function wfFirebaseRenderRaw( Parser $parser, PPFrame $frame, $input, array $args ) {
// parse the url arg in case it is provided through templating, nested tags, etc.
$parsedURL = $parser->replaceVariables( $args['url'], $frame );
// convert the URL to the REST-accessable URL
$parsedURL = str_replace(" ", "%20", $parsedURL);
$parsedURL = $parsedURL . '.json';
wfDebugLog( 'Firebase', 'entered raw case with url = ' . $parsedURL);
$firebaseGET = Http::request('GET',$parsedURL);
wfDebugLog( 'Firebase', 'Http request returned: ' . $firebaseGET );
if($firebaseGET) {
$firebaseGET = str_replace('"', "", $firebaseGET);
wfDebugLog( 'Firebase', 'Tried to remove quotes from: ' . $firebaseGET );
return $firebaseGET;
}
else {
return "ERR: Firebase query failed.";
}
}
// normal rendering replaces the firebase tag with a live <span> element
// see ext.Firebase.js for the script that makes it live
public static function wfFirebaseRender( $input, array $args, Parser $parser, PPFrame $frame ) {
// parse the url arg in case it is provided through templating, nested tags, etc.
$parsedURL = $parser->replaceVariables( $args['url'], $frame );
return "<span class='firebase' id='" . $parsedURL . "' />";
}
}
?>