summaryrefslogtreecommitdiffstats
path: root/lib/Utility
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
commit004fcbbcc7609ca83807f2e38967ef54f469bf72 (patch)
tree49eb99b4ea92b2045793fc567f719b31ec7f9042 /lib/Utility
parent60abc0ed4438c9b6fda245b0dc33cb483bc2aeaf (diff)
Move to new directory structure
Diffstat (limited to 'lib/Utility')
-rw-r--r--lib/Utility/OPMLExporter.php91
-rw-r--r--lib/Utility/PicoFeedClientFactory.php40
-rw-r--r--lib/Utility/PicoFeedFaviconFactory.php38
-rw-r--r--lib/Utility/ProxyConfigParser.php65
-rw-r--r--lib/Utility/Time.php30
-rw-r--r--lib/Utility/Updater.php54
6 files changed, 318 insertions, 0 deletions
diff --git a/lib/Utility/OPMLExporter.php b/lib/Utility/OPMLExporter.php
new file mode 100644
index 000000000..d786c0c6f
--- /dev/null
+++ b/lib/Utility/OPMLExporter.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+namespace OCA\News\Utility;
+
+/**
+* Exports the OPML
+*/
+class OPMLExporter {
+
+ /**
+ * Generates the OPML for the active user
+ *
+ * @param \OCA\News\Db\Folder[] $folders
+ * @param \OCA\News\Db\Feed[] $feeds
+ * @return \DomDocument the document
+ */
+ public function build($folders, $feeds){
+ $document = new \DomDocument('1.0', 'UTF-8');
+ $document->formatOutput = true;
+
+ $root = $document->createElement('opml');
+ $root->setAttribute('version', '2.0');
+
+ // head
+ $head = $document->createElement('head');
+
+ $title = $document->createElement('title', 'Subscriptions');
+ $head->appendChild($title);
+
+ $root->appendChild($head);
+
+ // body
+ $body = $document->createElement('body');
+
+ // feeds with folders
+ foreach($folders as $folder) {
+ $folderOutline = $document->createElement('outline');
+ $folderOutline->setAttribute('title', $folder->getName());
+ $folderOutline->setAttribute('text', $folder->getName());
+
+ // feeds in folders
+ foreach ($feeds as $feed) {
+ if ($feed->getFolderId() === $folder->getId()) {
+ $feedOutline = $this->createFeedOutline($feed, $document);
+ $folderOutline->appendChild($feedOutline);
+ }
+ }
+
+ $body->appendChild($folderOutline);
+ }
+
+ // feeds without folders
+ foreach ($feeds as $feed) {
+ if ($feed->getFolderId() === 0) {
+ $feedOutline = $this->createFeedOutline($feed, $document);
+ $body->appendChild($feedOutline);
+ }
+ }
+
+ $root->appendChild($body);
+
+ $document->appendChild($root);
+
+ return $document;
+ }
+
+
+ protected function createFeedOutline($feed, $document) {
+ $feedOutline = $document->createElement('outline');
+ $feedOutline->setAttribute('title', $feed->getTitle());
+ $feedOutline->setAttribute('text', $feed->getTitle());
+ $feedOutline->setAttribute('type', 'rss');
+ $feedOutline->setAttribute('xmlUrl', $feed->getUrl());
+ $feedOutline->setAttribute('htmlUrl', $feed->getLink());
+ return $feedOutline;
+ }
+
+
+}
+
diff --git a/lib/Utility/PicoFeedClientFactory.php b/lib/Utility/PicoFeedClientFactory.php
new file mode 100644
index 000000000..a57f7f022
--- /dev/null
+++ b/lib/Utility/PicoFeedClientFactory.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+
+namespace OCA\News\Utility;
+
+use \PicoFeed\Config\Config;
+use \PicoFeed\Client\Client;
+
+class PicoFeedClientFactory {
+
+ private $config;
+
+ public function __construct(Config $config) {
+ $this->config = $config;
+ }
+
+
+ /**
+ * Returns a new instance of an PicoFeed Http client
+ * @return \PicoFeed\Client instance
+ */
+ public function build() {
+ $client = Client::getInstance();
+ $client->setConfig($this->config);
+ return $client;
+ }
+
+
+} \ No newline at end of file
diff --git a/lib/Utility/PicoFeedFaviconFactory.php b/lib/Utility/PicoFeedFaviconFactory.php
new file mode 100644
index 000000000..b3a48747a
--- /dev/null
+++ b/lib/Utility/PicoFeedFaviconFactory.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+
+namespace OCA\News\Utility;
+
+use \PicoFeed\Config\Config;
+use \PicoFeed\Reader\Favicon;
+
+class PicoFeedFaviconFactory {
+
+ private $config;
+
+ public function __construct(Config $config) {
+ $this->config = $config;
+ }
+
+
+ /**
+ * Returns a new instance of an PicoFeed Http client
+ * @return \PicoFeed\Favicon instance
+ */
+ public function build() {
+ return new Favicon($this->config);
+ }
+
+
+} \ No newline at end of file
diff --git a/lib/Utility/ProxyConfigParser.php b/lib/Utility/ProxyConfigParser.php
new file mode 100644
index 000000000..4710477e8
--- /dev/null
+++ b/lib/Utility/ProxyConfigParser.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+
+namespace OCA\News\Utility;
+
+use \OCP\IConfig;
+
+
+class ProxyConfigParser {
+
+ private $config;
+
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+
+ /**
+ * Parses the config and splits up the port + url
+ * @return array
+ */
+ public function parse() {
+ $proxy = $this->config->getSystemValue('proxy');
+ $userpasswd = $this->config->getSystemValue('proxyuserpwd');
+
+ $result = [
+ 'host' => null,
+ 'port' => null,
+ 'user' => null,
+ 'password' => null
+ ];
+
+ // we need to filter out the port -.-
+ $url = new \Net_URL2($proxy);
+ $port = $url->getPort();
+
+ $url->setPort(false);
+ $host = $url->getUrl();
+
+
+ $result['host'] = $host;
+ $result['port'] = $port;
+
+ if ($userpasswd) {
+ $auth = explode(':', $userpasswd, 2);
+ $result['user'] = $auth[0];
+ $result['password'] = $auth[1];
+ }
+
+ return $result;
+ }
+
+
+} \ No newline at end of file
diff --git a/lib/Utility/Time.php b/lib/Utility/Time.php
new file mode 100644
index 000000000..e6ea2b470
--- /dev/null
+++ b/lib/Utility/Time.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2016
+ */
+
+namespace OCA\News\Utility;
+
+class Time {
+ public function getTime() {
+ return time();
+ }
+
+ /**
+ * @return int the current unix time in miliseconds
+ */
+ public function getMicroTime() {
+ $utimestamp = microtime(true);
+ $timestamp = floor($utimestamp);
+ $milliseconds = round(($utimestamp - $timestamp) * 1000000);
+ $result = ($timestamp * 1000000) + $milliseconds;
+ return $result;
+ }
+
+} \ No newline at end of file
diff --git a/lib/Utility/Updater.php b/lib/Utility/Updater.php
new file mode 100644
index 000000000..a6f8dc28a
--- /dev/null
+++ b/lib/Utility/Updater.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+
+namespace OCA\News\Utility;
+
+use \OCA\News\Service\FolderService;
+use \OCA\News\Service\FeedService;
+use \OCA\News\Service\ItemService;
+
+
+class Updater {
+
+
+ private $folderService;
+ private $feedService;
+ private $itemService;
+
+ public function __construct(FolderService $folderService,
+ FeedService $feedService,
+ ItemService $itemService) {
+ $this->folderService = $folderService;
+ $this->feedService = $feedService;
+ $this->itemService = $itemService;
+ }
+
+
+ public function beforeUpdate() {
+ $this->folderService->purgeDeleted();
+ $this->feedService->purgeDeleted();
+ }
+
+
+ public function update() {
+ $this->feedService->updateAll();
+ }
+
+
+ public function afterUpdate() {
+ $this->itemService->autoPurgeOld();
+ }
+
+
+} \ No newline at end of file