summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus2021-01-17 23:06:59 +0100
committerHorus2021-01-17 23:06:59 +0100
commitdbb49c2d9160ef8c13670113bb34ce8452385a62 (patch)
treeaf5e5f7aec807efc7f7558673c035203e4a4619e
downloaddilbert_rss-dbb49c2d9160ef8c13670113bb34ce8452385a62.tar.gz
Initial commit.
-rw-r--r--.gitignore3
-rw-r--r--composer.json6
-rw-r--r--composer.lock124
-rw-r--r--index.php83
4 files changed, 216 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..be1f437
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.swp
+public/
+vendor/
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..7aa0e78
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,6 @@
+{
+ "require": {
+ "imangazaliev/didom": "^1.5",
+ "suin/php-rss-writer": "^1.6"
+ }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..e5efe15
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,124 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "4bb2f254a3d00b364f462c6ad16c3dfa",
+ "packages": [
+ {
+ "name": "imangazaliev/didom",
+ "version": "1.16.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Imangazaliev/DiDOM.git",
+ "reference": "c88f5a562868d92b86d0b6aa8dfb30aa7f99977f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/c88f5a562868d92b86d0b6aa8dfb30aa7f99977f",
+ "reference": "c88f5a562868d92b86d0b6aa8dfb30aa7f99977f",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-iconv": "*",
+ "php": ">=5.4"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.8"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "DiDom\\": "src/DiDom/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Imangazaliev Muhammad",
+ "email": "imangazalievm@gmail.com"
+ }
+ ],
+ "description": "Simple and fast HTML parser",
+ "homepage": "https://github.com/Imangazaliev/DiDOM",
+ "keywords": [
+ "didom",
+ "html",
+ "parser",
+ "xml"
+ ],
+ "support": {
+ "issues": "https://github.com/Imangazaliev/DiDOM/issues",
+ "source": "https://github.com/Imangazaliev/DiDOM/tree/1.16.1"
+ },
+ "time": "2020-11-16T10:57:57+00:00"
+ },
+ {
+ "name": "suin/php-rss-writer",
+ "version": "1.6.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/suin/php-rss-writer.git",
+ "reference": "78f45e44a2a7cb0d82e4b9efb6f7b7a075b9051c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/suin/php-rss-writer/zipball/78f45e44a2a7cb0d82e4b9efb6f7b7a075b9051c",
+ "reference": "78f45e44a2a7cb0d82e4b9efb6f7b7a075b9051c",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "require-dev": {
+ "eher/phpunit": ">=1.6",
+ "mockery/mockery": ">=0.7.2",
+ "suin/xoopsunit": ">=1.2"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Suin\\RSSWriter": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "suin",
+ "email": "suinyeze@gmail.com"
+ }
+ ],
+ "description": "Yet another simple RSS writer library for PHP 5.4 or later.",
+ "homepage": "https://github.com/suin/php-rss-writer",
+ "keywords": [
+ "feed",
+ "generator",
+ "php",
+ "rss",
+ "writer"
+ ],
+ "support": {
+ "issues": "https://github.com/suin/php-rss-writer/issues",
+ "source": "https://github.com/suin/php-rss-writer/tree/master"
+ },
+ "time": "2017-07-13T10:47:50+00:00"
+ }
+ ],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": [],
+ "plugin-api-version": "2.0.0"
+}
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..f6f8872
--- /dev/null
+++ b/index.php
@@ -0,0 +1,83 @@
+<?php
+
+define('PUBLIC_DIR', 'public');
+
+require_once __DIR__ . '/vendor/autoload.php';
+
+use DiDom\Document;
+use Suin\RSSWriter\Channel;
+use Suin\RSSWriter\Feed;
+use Suin\RSSWriter\Item;
+
+function get_dilbert_items(){
+ $xml = simplexml_load_file("http://dilbert.com/feed");
+ if (false === $xml) {
+ die('Error: Loading http://dilbert.com/feed failed. ' . strtotime(date("r")) );
+ }
+
+ $return_values = array();
+ $count = 0;
+
+ foreach ($xml as $node) {
+ $link = (string)$node->link["href"];
+ if ( $link != "" ) {
+
+ $document = new Document($link, true);
+ $img = $document->find(".img-comic-container")[0]->find(".img-comic-link")[0]->find("img")[0];
+
+ $time = (string)$node->updated;
+
+ $doc = new DOMDocument();
+ $doc->loadHTML($img);
+ $xpath = new DOMXPath($doc);
+ $src = $xpath->evaluate("string(//img/@src)");
+ $title = $xpath->evaluate("string(//img/@alt)");
+
+ $count++;
+ $return_values[$count]["title"] = $title;
+ $return_values[$count]["link"] = $src;
+ $return_values[$count]["time"] = $time;
+ $return_values[$count]["description"] = "<img src='".$src."' title='".$title."' alt='".$title."'>";
+ }
+ }
+
+ return $return_values;
+}
+
+function generate() {
+ $feed = new Feed();
+
+ $channel = new Channel();
+ $channel
+ ->title("Dilbert")
+ ->description("Dilbert - with Pictures")
+ ->url( "https://feeds.iamfabulous.de/Dilbert.xml" )
+ ->pubDate(strtotime(date("r", time())))
+ ->lastBuildDate(strtotime(date("r", time())))
+ ->ttl(5)
+ ->appendTo($feed);
+
+ #->url("http://feeds.iamfabulous.de/".$name)
+
+
+ $r = get_dilbert_items();
+
+ foreach($r as $item) {
+ $item_out = new Item();
+
+ $item_out
+ ->title($item["title"])
+ ->description($item["description"])
+ ->url($item["link"])
+ ->pubDate(strtotime(date($item["time"])))
+ ->appendTo($channel);
+ }
+
+ if ( ! file_exists( PUBLIC_DIR ) ) {
+ mkdir( PUBLIC_DIR );
+ }
+
+ file_put_contents(PUBLIC_DIR . '/Dilbert.xml', $feed );
+}
+
+generate();