forked from Tykov/AMPER
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
31 lines (31 loc) · 1.08 KB
/
plugin.php
File metadata and controls
31 lines (31 loc) · 1.08 KB
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
<?php
//Based on AMP.DEV html template
//author: Constantine - Evergarden
if(!defined("BLUDIT")) { die("You seek for fresh air and peace of mind, Ivanov? I'm in the North, waiting for you."); }
class AMPER extends Plugin {
public function init(){
// Custom fields initialization
global $site;
$userFields = $site->customFields() ?? '{}';
if(!isset($userFields['_amper'])){
$amper_json = json_decode('{"_amper": {"type": "bool","label": "AMPER","tip": "Disable AMP pages for this content"}}', true);
$amper_final = json_encode(array_merge($userFields, $amper_json));
$site->set(array('customFields'=>$amper_final));
}
}
public function beforeSiteLoad(){
global $url, $page, $site;
if(isset($_GET["amp"])){
if($url->whereAmI() == "page" && !$url->notFound() && $page->custom('_amper') !== true){
include(__DIR__ . DS . "php" . DS . "amper.php");
}
}
}
public function siteHead()
{
global $page, $url;
if($url->whereAmI() == "page" && !$url->notFound() && $page->custom('_amper') !== true){
return '<link href="' . $page->permalink() . '?amp" rel="amphtml" />' . PHP_EOL;
}
}
}