diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-04 13:48:44 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-04 13:48:44 +0200 |
commit | 8ecc37bafc86fdf954ea5606b87f04a7bae54570 (patch) | |
tree | 502c8bfb5fac95ff25ecaeec88bdeaf56e76115a /feed | |
parent | 96c7439c7372d603e36412c39d6b2b8948565199 (diff) |
fix #624
Diffstat (limited to 'feed')
-rw-r--r-- | feed/client/curl.php | 25 | ||||
-rw-r--r-- | feed/spec.php | 62 |
2 files changed, 87 insertions, 0 deletions
diff --git a/feed/client/curl.php b/feed/client/curl.php index 3cacfe2aa..289faf902 100644 --- a/feed/client/curl.php +++ b/feed/client/curl.php @@ -20,6 +20,31 @@ class CURL extends HttpClient { } + public function get ($url) { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $this->url); + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->timeout); + curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + curl_setopt($curl, CURLOPT_HTTPHEADER, $request_headers); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === ''); + curl_setopt($curl, CURLOPT_MAXREDIRS, $this->max_redirects); + curl_setopt($curl, CURLOPT_ENCODING, ''); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // For auto-signed certificates... + curl_setopt($curl, CURLOPT_WRITEFUNCTION, array($this, 'readBody')); + curl_setopt($curl, CURLOPT_HEADERFUNCTION, array($this, 'readHeaders')); + + curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxy_port); + curl_setopt($curl, CURLOPT_PROXYTYPE, 'HTTP'); + curl_setopt($curl, CURLOPT_PROXY, $this->proxy_hostname); + curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxy_username.':'.$this->proxy_password); + + curl_errno($curl); + curl_error($curl); + + curl_exec($curl); + } } diff --git a/feed/spec.php b/feed/spec.php new file mode 100644 index 000000000..6a485006b --- /dev/null +++ b/feed/spec.php @@ -0,0 +1,62 @@ +<?php +// TODO: atom has type attribute for values that have html/xhtml if given and have to be decoded +// TODO: link attribute (rel etc) +// TODO: can we distinguish between CDATA and plain content? +// TODO: steal from https://github.com/gothfox/Tiny-Tiny-RSS/blob/master/classes/feedparser.php + +$ownFeed = new OwnFeed([ + 'user_agent' => 'ownFeed version 1', + 'connection_timeout' => 10, + 'timeout' => 10, + 'verify_ssl' => true, + 'http_version' => '1.1', + 'proxy_host' => '', + 'proxy_port' => 80, + 'proxy_user' => '', + 'proxy_password' => '' +]); + +try { + $feed = $ownFeed->fetch($url); + // RSS || ATOM + $feed['title']; // <title> + $feed['link']; // <link> || <link href=""> + + foreach($feed['items'] as $item) { + $item['title']; // <title> + $item['link']; // <link> || <link href=""> + $item['description']; // <description> || <summary> vs <content> + foreach ($item['authors'] as $author) { // <author> or <author><name><email></author> + $author['name']; + $author['email']; + } + $item['enclosure']['url']; // <enclosure url type> || <link rel="enclosure" type href> + $item['enclosure']['type']; + $item['id']; // <guid> || <id> || $item['hash'] + $item['hash']; // hash over title + content + $item['pub_date']; // rfc 822 || rfc 3339 + } +} catch (OwnFeedException $e) { + // SSLVerificationException + // TimeoutException + // ForbiddenException + // NotFoundException + // MaximumRedirectException + // MalformedXMLException + // +} + +/* +curl_setopt($ch, CURLOPT_URL, $this->url); +curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); +curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); +curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); +curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); +curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers); +curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === ''); +curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects); +curl_setopt($ch, CURLOPT_ENCODING, ''); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For auto-signed certificates... +curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'readBody')); +curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'readHeaders')); +*/
\ No newline at end of file |