✨ Add atom module
This commit is contained in:
parent
069bc5b3a5
commit
c22506a0e5
4 changed files with 149 additions and 0 deletions
7
bl-modules/atom/languages/en.json
Normal file
7
bl-modules/atom/languages/en.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"plugin-data":
|
||||||
|
{
|
||||||
|
"name": "Atom Feed",
|
||||||
|
"description": "This plugin generates an Atom feed of your site.<br>The feed has the URL https://example.com/rss.xml"
|
||||||
|
}
|
||||||
|
}
|
7
bl-modules/atom/languages/fr_FR.json
Normal file
7
bl-modules/atom/languages/fr_FR.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"plugin-data":
|
||||||
|
{
|
||||||
|
"name": "Flux Atom",
|
||||||
|
"description": "Ce plugin génère un flux Atom de votre site.<br/>Le flux est accessible a l'URL de ce genre : https://example.com/atom.xml"
|
||||||
|
}
|
||||||
|
}
|
10
bl-modules/atom/metadata.json
Normal file
10
bl-modules/atom/metadata.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"author": "Koblog",
|
||||||
|
"email": "",
|
||||||
|
"website": "https://plugins.koblog.com",
|
||||||
|
"version": "kb_0.0.1",
|
||||||
|
"releaseDate": "2024-08-23",
|
||||||
|
"license": "MIT",
|
||||||
|
"compatible": "kb_0.0.1",
|
||||||
|
"notes": ""
|
||||||
|
}
|
125
bl-modules/atom/plugin.php
Normal file
125
bl-modules/atom/plugin.php
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class pluginAtom extends Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
private function encodeURL($url)
|
||||||
|
{
|
||||||
|
return preg_replace_callback('/[^\x20-\x7f]/', function ($match) {
|
||||||
|
return urlencode($match[0]);
|
||||||
|
}, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createXML()
|
||||||
|
{
|
||||||
|
global $site;
|
||||||
|
global $pages;
|
||||||
|
global $url;
|
||||||
|
|
||||||
|
// Amount of pages to show
|
||||||
|
$numberOfItems = $site->itemsPerPage();
|
||||||
|
|
||||||
|
// Get the list of public pages (sticky and static included)
|
||||||
|
$list = $pages->getList(
|
||||||
|
$pageNumber = 1,
|
||||||
|
$numberOfItems,
|
||||||
|
$published = true,
|
||||||
|
$static = true,
|
||||||
|
$sticky = true,
|
||||||
|
$draft = false,
|
||||||
|
$scheduled = false
|
||||||
|
);
|
||||||
|
|
||||||
|
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||||
|
$xml .= '<feed xmlns="http://www.w3.org/2005/Atom">';
|
||||||
|
$xml .= '<title>' . $site->title() . '</title>';
|
||||||
|
$xml .= '<subtitle>' . $site->description() . '</subtitle>';
|
||||||
|
$xml .= '<link href="' . $this->encodeURL($site->url()) . '" />';
|
||||||
|
$xml .= '<updated>' . date(DATE_RSS) . '</updated>';
|
||||||
|
|
||||||
|
// Get keys of pages
|
||||||
|
foreach ($list as $pageKey) {
|
||||||
|
try {
|
||||||
|
// Create the page object from the page key
|
||||||
|
$page = new Page($pageKey);
|
||||||
|
$imagepath = parse_url($page->coverImage(true), PHP_URL_PATH);
|
||||||
|
$imagepath = $_SERVER['DOCUMENT_ROOT'] . $imagepath;
|
||||||
|
|
||||||
|
$xml .= '<entry>';
|
||||||
|
$xml .= '<title>' . $page->title() . '</title>';
|
||||||
|
$xml .= '<link rel="alternate" href="' . $this->encodeURL($page->permalink()) . '" />';
|
||||||
|
$xml .= '<link rel="enclosure" url="'.$page->coverImage(true).'" length="'.filesize($imagepath).'" type="'.mime_content_type($imagepath).'" />';
|
||||||
|
$xml .= '<summary>'.strip_tags( $page->contentBreak() ).'</summary>';
|
||||||
|
$xml .= '<updated>' . date(DATE_RSS, strtotime($page->getValue('dateRaw'))) . '</updated>';
|
||||||
|
$xml .= '<id>urn:uuid:' . $page->uuid() . '</id>';
|
||||||
|
$xml .= '<author>';
|
||||||
|
$xml .= '<name>'.$page->user('nickname').'</name>';
|
||||||
|
$xml .= '</author>';
|
||||||
|
$xml .= '</entry>';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml .= '</feed>';
|
||||||
|
|
||||||
|
// New DOM document
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->formatOutput = true;
|
||||||
|
$doc->loadXML($xml);
|
||||||
|
return $doc->save($this->workspace() . 'atom.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function install($position = 0)
|
||||||
|
{
|
||||||
|
parent::install($position);
|
||||||
|
return $this->createXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function post()
|
||||||
|
{
|
||||||
|
parent::post();
|
||||||
|
return $this->createXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterPageCreate()
|
||||||
|
{
|
||||||
|
$this->createXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterPageModify()
|
||||||
|
{
|
||||||
|
$this->createXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterPageDelete()
|
||||||
|
{
|
||||||
|
$this->createXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function siteHead()
|
||||||
|
{
|
||||||
|
return '<link rel="alternate" type="application/atom+xml" href="' . DOMAIN_BASE . 'atom.xml" title="Atom Feed">' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function beforeAll()
|
||||||
|
{
|
||||||
|
$webhook = 'atom.xml';
|
||||||
|
if ($this->webhook($webhook)) {
|
||||||
|
// Send XML header
|
||||||
|
header('Content-type: text/xml');
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
|
||||||
|
// Load XML
|
||||||
|
libxml_disable_entity_loader(false);
|
||||||
|
$doc->load($this->workspace() . 'atom.xml');
|
||||||
|
libxml_disable_entity_loader(true);
|
||||||
|
|
||||||
|
// Print the XML
|
||||||
|
echo $doc->saveXML();
|
||||||
|
|
||||||
|
// Stop Koblog execution
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue