-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagram.php
49 lines (44 loc) · 2.09 KB
/
instagram.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
<?php
// Instagram extension, https://github.com/GiovanniSalmeri/yellow-instagram
class YellowInstagram {
const VERSION = "0.9.1";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
$this->yellow->system->setDefault("instagramStyle", "instagram");
}
// Handle page content element
public function onParseContentElement($page, $name, $text, $attributes, $type) {
$output = null;
if ($name=="instagram" && ($type=="block" || $type=="inline")) {
list($id, $dummy, $style, $width, $height) = $this->yellow->toolbox->getTextArguments($text);
if (is_string_empty($style)) $style = $this->yellow->system->get("instagramStyle");
if (is_string_empty($width)) $width = "100%";
$css = $this->getInstagramStyle($width, $height);
$output = "<div class=\"".htmlspecialchars($style)."\" style=\"".htmlspecialchars($css)."\">";
$output .= "<blockquote class=\"instagram-media\" data-instgrm-captioned style=\"".htmlspecialchars($css)."display:none;\">";
$output .= "<a href=\"https://www.instagram.com/p/".htmlspecialchars($id)."/\">Instagram</a>";
$output .= "</blockquote></div>";
}
return $output;
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;
if ($name=="header") {
$assetLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreAssetLocation");
$output = "<script type=\"text/javascript\" defer=\"defer\" src=\"{$assetLocation}instagram.js\"></script>\n";
}
return $output;
}
// Return CSS style
public function getInstagramStyle($width, $height) {
$css = "";
if (is_numeric($width)) $width .= "px";
if (is_numeric($height)) $height .= "px";
if (!is_string_empty($width)) $css .= " width:$width;";
if (!is_string_empty($height)) $css .= " height:$height;";
return trim($css);
}
}