diff --git a/bl-modules/atom/languages/en.json b/bl-modules/atom/languages/en.json new file mode 100644 index 00000000..771dffb3 --- /dev/null +++ b/bl-modules/atom/languages/en.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Atom Feed", + "description": "This plugin generates an Atom feed of your site.
The feed has the URL https://example.com/rss.xml" + } +} diff --git a/bl-modules/atom/languages/fr_FR.json b/bl-modules/atom/languages/fr_FR.json new file mode 100644 index 00000000..464d5450 --- /dev/null +++ b/bl-modules/atom/languages/fr_FR.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Flux Atom", + "description": "Ce plugin génère un flux Atom de votre site.
Le flux est accessible a l'URL de ce genre : https://example.com/atom.xml" + } +} diff --git a/bl-modules/atom/metadata.json b/bl-modules/atom/metadata.json new file mode 100644 index 00000000..c4539610 --- /dev/null +++ b/bl-modules/atom/metadata.json @@ -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": "" +} diff --git a/bl-modules/atom/plugin.php b/bl-modules/atom/plugin.php new file mode 100644 index 00000000..7c91ff69 --- /dev/null +++ b/bl-modules/atom/plugin.php @@ -0,0 +1,125 @@ +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 .= ''; + $xml .= '' . $site->title() . ''; + $xml .= '' . $site->description() . ''; + $xml .= ''; + $xml .= '' . date(DATE_RSS) . ''; + + // 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 .= ''; + $xml .= '' . $page->title() . ''; + $xml .= ''; + $xml .= ''; + $xml .= ''.strip_tags( $page->contentBreak() ).''; + $xml .= '' . date(DATE_RSS, strtotime($page->getValue('dateRaw'))) . ''; + $xml .= 'urn:uuid:' . $page->uuid() . ''; + $xml .= ''; + $xml .= ''.$page->user('nickname').''; + $xml .= ''; + $xml .= ''; + } catch (Exception $e) { + // Continue + } + } + + $xml .= ''; + + // 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 '' . 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); + } + } +}