use composer based library for feed creator #1970
This commit is contained in:
parent
8df8dbb40d
commit
572dd708be
|
@ -67,7 +67,7 @@ lib/images/*/local/*
|
|||
# composer default ignores
|
||||
composer.phar
|
||||
vendor/bin/*
|
||||
vendor/*/*/phpunit.xml
|
||||
vendor/*/*/phpunit.xml*
|
||||
vendor/*/*/.travis.yml
|
||||
vendor/*/*/bin/*
|
||||
vendor/*/*/tests/*
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
"phpseclib/phpseclib": "~2.0",
|
||||
"paragonie/random_compat": "^2.0",
|
||||
"simplepie/simplepie": "^1.4",
|
||||
"geshi/geshi": "^1.0"
|
||||
"geshi/geshi": "^1.0",
|
||||
"openpsa/universalfeedcreator": "^1.8"
|
||||
},
|
||||
"suggest": {
|
||||
"squizlabs/php_codesniffer": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "d742a607937b645d9c656c9054438fe9",
|
||||
"content-hash": "915e6fb408fdf5780e4f49b03325adcd",
|
||||
"packages": [
|
||||
{
|
||||
"name": "geshi/geshi",
|
||||
|
@ -46,6 +46,54 @@
|
|||
"homepage": "http://qbnz.com/highlighter/",
|
||||
"time": "2017-05-05T05:51:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "openpsa/universalfeedcreator",
|
||||
"version": "v1.8.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/flack/UniversalFeedCreator.git",
|
||||
"reference": "6261e130446d8f787bbfd229a602fb11e6816a4e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/flack/UniversalFeedCreator/zipball/6261e130446d8f787bbfd229a602fb11e6816a4e",
|
||||
"reference": "6261e130446d8f787bbfd229a602fb11e6816a4e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"lib"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Andreas Flack",
|
||||
"email": "flack@contentcontrol-berlin.de",
|
||||
"homepage": "http://www.contentcontrol-berlin.de/"
|
||||
}
|
||||
],
|
||||
"description": "RSS and Atom feed generator by Kai Blankenhorn",
|
||||
"keywords": [
|
||||
"atom",
|
||||
"georss",
|
||||
"gpx",
|
||||
"opml",
|
||||
"pie",
|
||||
"rss"
|
||||
],
|
||||
"time": "2017-05-18T08:28:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "paragonie/random_compat",
|
||||
"version": "v2.0.10",
|
||||
|
|
4
feed.php
4
feed.php
|
@ -51,7 +51,7 @@ if($cache->useCache($depends)) {
|
|||
}
|
||||
|
||||
// create new feed
|
||||
$rss = new DokuWikiFeedCreator();
|
||||
$rss = new UniversalFeedCreator();
|
||||
$rss->title = $conf['title'].(($opt['namespace']) ? ' '.$opt['namespace'] : '');
|
||||
$rss->link = DOKU_URL;
|
||||
$rss->syndicationURL = DOKU_URL.'feed.php';
|
||||
|
@ -85,7 +85,7 @@ if(isset($modes[$opt['feed_mode']])) {
|
|||
}
|
||||
|
||||
rss_buildItems($rss, $data, $opt);
|
||||
$feed = $rss->createFeed($opt['feed_type'], 'utf-8');
|
||||
$feed = $rss->createFeed($opt['feed_type']);
|
||||
|
||||
// save cachefile
|
||||
$cache->storeCache($feed);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -76,7 +76,6 @@ function load_autoload($name){
|
|||
'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php',
|
||||
'Tar' => DOKU_INC.'inc/Tar.class.php',
|
||||
'ZipLib' => DOKU_INC.'inc/ZipLib.class.php',
|
||||
'DokuWikiFeedCreator' => DOKU_INC.'inc/feedcreator.class.php',
|
||||
'Doku_Parser_Mode' => DOKU_INC.'inc/parser/parser.php',
|
||||
'Doku_Parser_Mode_Plugin' => DOKU_INC.'inc/parser/parser.php',
|
||||
'SafeFN' => DOKU_INC.'inc/SafeFN.class.php',
|
||||
|
|
|
@ -6,5 +6,25 @@ $vendorDir = dirname(dirname(__FILE__));
|
|||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'AtomCreator03' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/AtomCreator03.php',
|
||||
'AtomCreator10' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/AtomCreator10.php',
|
||||
'FeedCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/FeedCreator.php',
|
||||
'FeedDate' => $vendorDir . '/openpsa/universalfeedcreator/lib/Element/FeedDate.php',
|
||||
'FeedHtmlField' => $vendorDir . '/openpsa/universalfeedcreator/lib/Element/FeedHtmlField.php',
|
||||
'FeedImage' => $vendorDir . '/openpsa/universalfeedcreator/lib/Element/FeedImage.php',
|
||||
'FeedItem' => $vendorDir . '/openpsa/universalfeedcreator/lib/Element/FeedItem.php',
|
||||
'GPXCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/GPXCreator.php',
|
||||
'GeSHi' => $vendorDir . '/geshi/geshi/src/geshi.php',
|
||||
'HTMLCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/HTMLCreator.php',
|
||||
'HtmlDescribable' => $vendorDir . '/openpsa/universalfeedcreator/lib/Element/HtmlDescribable.php',
|
||||
'JSCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/JSCreator.php',
|
||||
'KMLCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/KMLCreator.php',
|
||||
'MBOXCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/MBOXCreator.php',
|
||||
'OPMLCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/OPMLCreator.php',
|
||||
'PHPCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/PHPCreator.php',
|
||||
'PIECreator01' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/PIECreator01.php',
|
||||
'RSSCreator091' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator091.php',
|
||||
'RSSCreator10' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator10.php',
|
||||
'RSSCreator20' => $vendorDir . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator20.php',
|
||||
'UniversalFeedCreator' => $vendorDir . '/openpsa/universalfeedcreator/lib/UniversalFeedCreator.php',
|
||||
);
|
||||
|
|
|
@ -44,7 +44,27 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
|
|||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'AtomCreator03' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/AtomCreator03.php',
|
||||
'AtomCreator10' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/AtomCreator10.php',
|
||||
'FeedCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/FeedCreator.php',
|
||||
'FeedDate' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Element/FeedDate.php',
|
||||
'FeedHtmlField' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Element/FeedHtmlField.php',
|
||||
'FeedImage' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Element/FeedImage.php',
|
||||
'FeedItem' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Element/FeedItem.php',
|
||||
'GPXCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/GPXCreator.php',
|
||||
'GeSHi' => __DIR__ . '/..' . '/geshi/geshi/src/geshi.php',
|
||||
'HTMLCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/HTMLCreator.php',
|
||||
'HtmlDescribable' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Element/HtmlDescribable.php',
|
||||
'JSCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/JSCreator.php',
|
||||
'KMLCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/KMLCreator.php',
|
||||
'MBOXCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/MBOXCreator.php',
|
||||
'OPMLCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/OPMLCreator.php',
|
||||
'PHPCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/PHPCreator.php',
|
||||
'PIECreator01' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/PIECreator01.php',
|
||||
'RSSCreator091' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator091.php',
|
||||
'RSSCreator10' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator10.php',
|
||||
'RSSCreator20' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/Creator/RSSCreator20.php',
|
||||
'UniversalFeedCreator' => __DIR__ . '/..' . '/openpsa/universalfeedcreator/lib/UniversalFeedCreator.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
|
|
|
@ -299,5 +299,55 @@
|
|||
],
|
||||
"description": "Generic Syntax Highlighter",
|
||||
"homepage": "http://qbnz.com/highlighter/"
|
||||
},
|
||||
{
|
||||
"name": "openpsa/universalfeedcreator",
|
||||
"version": "v1.8.3",
|
||||
"version_normalized": "1.8.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/flack/UniversalFeedCreator.git",
|
||||
"reference": "6261e130446d8f787bbfd229a602fb11e6816a4e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/flack/UniversalFeedCreator/zipball/6261e130446d8f787bbfd229a602fb11e6816a4e",
|
||||
"reference": "6261e130446d8f787bbfd229a602fb11e6816a4e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"time": "2017-05-18T08:28:48+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"lib"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Andreas Flack",
|
||||
"email": "flack@contentcontrol-berlin.de",
|
||||
"homepage": "http://www.contentcontrol-berlin.de/"
|
||||
}
|
||||
],
|
||||
"description": "RSS and Atom feed generator by Kai Blankenhorn",
|
||||
"keywords": [
|
||||
"atom",
|
||||
"georss",
|
||||
"gpx",
|
||||
"opml",
|
||||
"pie",
|
||||
"rss"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# This file is for unifying the coding style for different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
# PHP PSR-2 Coding Standards
|
||||
# http://www.php-fig.org/psr/psr-2/
|
||||
|
||||
root = true
|
||||
|
||||
[*.php]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
*.txt text eol=lf
|
||||
*.js text eol=lf
|
||||
*.html text eol=lf
|
||||
*.css text eol=lf
|
||||
*.php text eol=lf
|
|
@ -0,0 +1,9 @@
|
|||
/.project
|
||||
/.buildpath
|
||||
/.settings
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
.DS_Store
|
||||
*~
|
|
@ -0,0 +1,161 @@
|
|||
UniversalFeedCreator
|
||||
====================
|
||||
|
||||
RSS and Atom feed generator by Kai Blankenhorn, slightly cleaned up and packaged for Composer.
|
||||
|
||||
Supported formats: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated), MBOX, OPML, ATOM, ATOM0.3,
|
||||
HTML, JS, PHP
|
||||
|
||||
[![Build Status](https://travis-ci.org/flack/UniversalFeedCreator.png?branch=master)](https://travis-ci.org/flack/UniversalFeedCreator)
|
||||
|
||||
## General Usage
|
||||
|
||||
```php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$rss = new UniversalFeedCreator();
|
||||
$rss->useCached(); // use cached version if age < 1 hour
|
||||
$rss->title = "PHP news";
|
||||
$rss->description = "daily news from the PHP scripting world";
|
||||
|
||||
//optional
|
||||
$rss->descriptionTruncSize = 500;
|
||||
$rss->descriptionHtmlSyndicated = true;
|
||||
|
||||
$rss->link = "http://www.dailyphp.net/news";
|
||||
$rss->syndicationURL = "http://www.dailyphp.net/" . $_SERVER["PHP_SELF"];
|
||||
|
||||
$image = new FeedImage();
|
||||
$image->title = "dailyphp.net logo";
|
||||
$image->url = "http://www.dailyphp.net/images/logo.gif";
|
||||
$image->link = "http://www.dailyphp.net";
|
||||
$image->description = "Feed provided by dailyphp.net. Click to visit.";
|
||||
|
||||
//optional
|
||||
$image->descriptionTruncSize = 500;
|
||||
$image->descriptionHtmlSyndicated = true;
|
||||
|
||||
$rss->image = $image;
|
||||
|
||||
// get your news items from somewhere, e.g. your database:
|
||||
mysql_select_db($dbHost, $dbUser, $dbPass);
|
||||
$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
|
||||
while ($data = mysql_fetch_object($res)) {
|
||||
$item = new FeedItem();
|
||||
$item->title = $data->title;
|
||||
$item->link = $data->url;
|
||||
$item->description = $data->short;
|
||||
|
||||
//optional
|
||||
$item->descriptionTruncSize = 500;
|
||||
$item->descriptionHtmlSyndicated = true;
|
||||
|
||||
$item->date = $data->newsdate;
|
||||
$item->source = "http://www.dailyphp.net";
|
||||
$item->author = "John Doe";
|
||||
|
||||
$rss->addItem($item);
|
||||
}
|
||||
|
||||
echo $rss->saveFeed("RSS1.0", "news/feed.xml");
|
||||
```
|
||||
|
||||
## Changelog:
|
||||
|
||||
```
|
||||
v1.8 12-03-13
|
||||
packaged for Composer & cleaned up slightly
|
||||
|
||||
v1.7.7(BH) 28-03-06
|
||||
added GPX Feed (Barry Hunter)
|
||||
|
||||
|
||||
v1.7.6(BH) 20-02-06
|
||||
added GeoRSS Feed (Barry Hunter)
|
||||
|
||||
|
||||
v1.7.5(BH) 16-11-05
|
||||
added BASE Feed (Barry Hunter)
|
||||
|
||||
v1.7.4(BH) 05-07-05
|
||||
added KML Feed (Barry Hunter)
|
||||
|
||||
v1.7.3(BH) 05-07-05
|
||||
added PHP Feed (Barry Hunter)
|
||||
|
||||
v1.7.2 10-11-04
|
||||
license changed to LGPL
|
||||
|
||||
v1.7.1
|
||||
fixed a syntax bug
|
||||
fixed left over debug code
|
||||
|
||||
v1.7 07-18-04
|
||||
added HTML and JavaScript feeds (configurable via CSS) (thanks to Pascal Van Hecke)
|
||||
added HTML descriptions for all feed formats (thanks to Pascal Van Hecke)
|
||||
added a switch to select an external stylesheet (thanks to Pascal Van Hecke)
|
||||
changed default content-type to application/xml
|
||||
added character encoding setting
|
||||
fixed numerous smaller bugs (thanks to Sören Fuhrmann of golem.de)
|
||||
improved changing ATOM versions handling (thanks to August Trometer)
|
||||
improved the UniversalFeedCreator's useCached method (thanks to Sören Fuhrmann of golem.de)
|
||||
added charset output in HTTP headers (thanks to Sören Fuhrmann of golem.de)
|
||||
added Slashdot namespace to RSS 1.0 (thanks to Sören Fuhrmann of golem.de)
|
||||
|
||||
v1.6 05-10-04
|
||||
added stylesheet to RSS 1.0 feeds
|
||||
fixed generator comment (thanks Kevin L. Papendick and Tanguy Pruvot)
|
||||
fixed RFC822 date bug (thanks Tanguy Pruvot)
|
||||
added TimeZone customization for RFC8601 (thanks Tanguy Pruvot)
|
||||
fixed Content-type could be empty (thanks Tanguy Pruvot)
|
||||
fixed author/creator in RSS1.0 (thanks Tanguy Pruvot)
|
||||
|
||||
v1.6 beta 02-28-04
|
||||
added Atom 0.3 support (not all features, though)
|
||||
improved OPML 1.0 support (hopefully - added more elements)
|
||||
added support for arbitrary additional elements (use with caution)
|
||||
code beautification :-)
|
||||
considered beta due to some internal changes
|
||||
|
||||
v1.5.1 01-27-04
|
||||
fixed some RSS 1.0 glitches (thanks to Stéphane Vanpoperynghe)
|
||||
fixed some inconsistencies between documentation and code (thanks to Timothy Martin)
|
||||
|
||||
v1.5 01-06-04
|
||||
added support for OPML 1.0
|
||||
added more documentation
|
||||
|
||||
v1.4 11-11-03
|
||||
optional feed saving and caching
|
||||
improved documentation
|
||||
minor improvements
|
||||
|
||||
v1.3 10-02-03
|
||||
renamed to FeedCreator, as it not only creates RSS anymore
|
||||
added support for mbox
|
||||
tentative support for echo/necho/atom/pie/???
|
||||
|
||||
v1.2 07-20-03
|
||||
intelligent auto-truncating of RSS 0.91 attributes
|
||||
don't create some attributes when they're not set
|
||||
documentation improved
|
||||
fixed a real and a possible bug with date conversions
|
||||
code cleanup
|
||||
|
||||
v1.1 06-29-03
|
||||
added images to feeds
|
||||
now includes most RSS 0.91 attributes
|
||||
added RSS 2.0 feeds
|
||||
|
||||
v1.0 06-24-03
|
||||
initial release
|
||||
```
|
||||
|
||||
## Credits
|
||||
```
|
||||
originally (c) Kai Blankenhorn
|
||||
www.bitfolge.de
|
||||
kaib@bitfolge.de
|
||||
v1.3 work by Scott Reynen (scott@randomchaos.com) and Kai Blankenhorn
|
||||
v1.5 OPML support by Dirk Clemens
|
||||
```
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "openpsa/universalfeedcreator",
|
||||
"type": "library",
|
||||
"description": "RSS and Atom feed generator by Kai Blankenhorn",
|
||||
"keywords": ["rss", "atom", "pie", "opml", "gpx", "georss"],
|
||||
"license": "LGPL",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Andreas Flack",
|
||||
"email": "flack@contentcontrol-berlin.de",
|
||||
"homepage": "http://www.contentcontrol-berlin.de/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": ["lib"]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* AtomCreator03 is a FeedCreator that implements the atom specification,
|
||||
* as in http://www.intertwingly.net/wiki/pie/FrontPage.
|
||||
* Please note that just by using AtomCreator03 you won't automatically
|
||||
* produce valid atom files. For example, you have to specify either an editor
|
||||
* for the feed or an author for every single feed item.
|
||||
* Some elements have not been implemented yet. These are (incomplete list):
|
||||
* author URL, item author's email and URL, item contents, alternate links,
|
||||
* other link content types than text/html. Some of them may be created with
|
||||
* AtomCreator03::additionalElements.
|
||||
*
|
||||
* @see FeedCreator#additionalElements
|
||||
* @since 1.6
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class AtomCreator03 extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* AtomCreator03 constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "application/atom+xml";
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createGeneratorComment();
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\"";
|
||||
if ($this->format == 'TOOLBAR') {
|
||||
$feed .= " xmlns:gtb=\"http://toolbar.google.com/custombuttons/\"";
|
||||
}
|
||||
if ($this->language != "") {
|
||||
$feed .= " xml:lang=\"".$this->language."\"";
|
||||
}
|
||||
$feed .= ">\n";
|
||||
$feed .= " <title>".htmlspecialchars($this->title)."</title>\n";
|
||||
$feed .= " <tagline>".htmlspecialchars($this->description)."</tagline>\n";
|
||||
$feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
|
||||
$feed .= " <id>".htmlspecialchars($this->link)."</id>\n";
|
||||
$now = new FeedDate();
|
||||
$feed .= " <modified>".htmlspecialchars($now->iso8601())."</modified>\n";
|
||||
if ($this->editor != "") {
|
||||
$feed .= " <author>\n";
|
||||
$feed .= " <name>".$this->editor."</name>\n";
|
||||
if ($this->editorEmail != "") {
|
||||
$feed .= " <email>".$this->editorEmail."</email>\n";
|
||||
}
|
||||
$feed .= " </author>\n";
|
||||
}
|
||||
$feed .= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
|
||||
$feed .= $this->_createAdditionalElements($this->additionalElements, " ");
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <entry>\n";
|
||||
$feed .= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
|
||||
$feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars(
|
||||
$this->items[$i]->link
|
||||
)."\"/>\n";
|
||||
if ($this->items[$i]->date == "") {
|
||||
$this->items[$i]->date = time();
|
||||
}
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
|
||||
$feed .= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
|
||||
$feed .= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
|
||||
$feed .= " <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
|
||||
$feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
|
||||
if ($this->items[$i]->author != "") {
|
||||
$feed .= " <author>\n";
|
||||
$feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
|
||||
$feed .= " </author>\n";
|
||||
}
|
||||
if ($this->items[$i]->description != "") {
|
||||
$feed .= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
|
||||
}
|
||||
if (isset($this->items[$i]->thumbdata)) {
|
||||
$feed .= " <gtb:icon mode=\"base64\" type=\"image/jpeg\">\n";
|
||||
$feed .= chunk_split(base64_encode($this->items[$i]->thumbdata))."\n";
|
||||
$feed .= " </gtb:icon>\n";
|
||||
}
|
||||
$feed .= " </entry>\n";
|
||||
}
|
||||
$feed .= "</feed>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* AtomCreator10 is a FeedCreator that implements the atom specification,
|
||||
* as in http://www.atomenabled.org/developers/syndication/atom-format-spec.php
|
||||
* Please note that just by using AtomCreator10 you won't automatically
|
||||
* produce valid atom files. For example, you have to specify either an editor
|
||||
* for the feed or an author for every single feed item.
|
||||
* Some elements have not been implemented yet. These are (incomplete list):
|
||||
* author URL, item author's email and URL, item contents, alternate links,
|
||||
* other link content types than text/html. Some of them may be created with
|
||||
* AtomCreator10::additionalElements.
|
||||
*
|
||||
* @see FeedCreator#additionalElements
|
||||
* @since 1.7.2-mod (modified)
|
||||
* @author Mohammad Hafiz Ismail (mypapit@gmail.com)
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class AtomCreator10 extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* AtomCreator10 constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "application/atom+xml";
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createGeneratorComment();
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<feed xmlns=\"http://www.w3.org/2005/Atom\"";
|
||||
if (!empty($this->items[0]->lat)) {
|
||||
$feed .= " xmlns:georss=\"http://www.georss.org/georss\"\n";
|
||||
}
|
||||
if ($this->language != "") {
|
||||
$feed .= " xml:lang=\"".$this->language."\"";
|
||||
}
|
||||
$feed .= ">\n";
|
||||
$feed .= " <title>".htmlspecialchars($this->title)."</title>\n";
|
||||
$feed .= " <subtitle>".htmlspecialchars($this->description)."</subtitle>\n";
|
||||
$feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
|
||||
$feed .= " <id>".htmlspecialchars($this->link)."</id>\n";
|
||||
$now = new FeedDate();
|
||||
$feed .= " <updated>".htmlspecialchars($now->iso8601())."</updated>\n";
|
||||
if ($this->editor != "") {
|
||||
$feed .= " <author>\n";
|
||||
$feed .= " <name>".$this->editor."</name>\n";
|
||||
if ($this->editorEmail != "") {
|
||||
$feed .= " <email>".$this->editorEmail."</email>\n";
|
||||
}
|
||||
$feed .= " </author>\n";
|
||||
}
|
||||
if ($this->category != "") {
|
||||
|
||||
$feed .= " <category term=\"".htmlspecialchars($this->category)."\" />\n";
|
||||
}
|
||||
if ($this->copyright != "") {
|
||||
$feed .= " <rights>".FeedCreator::iTrunc(htmlspecialchars($this->copyright), 100)."</rights>\n";
|
||||
}
|
||||
$feed .= " <generator>".$this->version()."</generator>\n";
|
||||
|
||||
$feed .= " <link rel=\"self\" type=\"application/atom+xml\" href=\"".htmlspecialchars(
|
||||
$this->syndicationURL
|
||||
)."\" />\n";
|
||||
$feed .= $this->_createAdditionalElements($this->additionalElements, " ");
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <entry>\n";
|
||||
$feed .= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
|
||||
$feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars(
|
||||
$this->items[$i]->link
|
||||
)."\"/>\n";
|
||||
if ($this->items[$i]->date == "") {
|
||||
$this->items[$i]->date = time();
|
||||
}
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= " <published>".htmlspecialchars($itemDate->iso8601())."</published>\n";
|
||||
$feed .= " <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n";
|
||||
|
||||
$tempguid = $this->items[$i]->link;
|
||||
if ($this->items[$i]->guid != "") {
|
||||
$tempguid = $this->items[$i]->guid;
|
||||
}
|
||||
|
||||
$feed .= " <id>".htmlspecialchars($tempguid)."</id>\n";
|
||||
$feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
|
||||
if ($this->items[$i]->author != "") {
|
||||
$feed .= " <author>\n";
|
||||
$feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
|
||||
if ($this->items[$i]->authorEmail != "") {
|
||||
$feed .= " <email>".htmlspecialchars($this->items[$i]->authorEmail)."</email>\n";
|
||||
}
|
||||
|
||||
if ($this->items[$i]->authorURL != "") {
|
||||
$feed .= " <uri>".htmlspecialchars($this->items[$i]->authorURL)."</uri>\n";
|
||||
}
|
||||
|
||||
$feed .= " </author>\n";
|
||||
}
|
||||
|
||||
if ($this->items[$i]->category != "") {
|
||||
$feed .= " <category ";
|
||||
|
||||
if ($this->items[$i]->categoryScheme != "") {
|
||||
$feed .= " scheme=\"".htmlspecialchars($this->items[$i]->categoryScheme)."\" ";
|
||||
}
|
||||
|
||||
$feed .= " term=\"".htmlspecialchars($this->items[$i]->category)."\" />\n";
|
||||
}
|
||||
|
||||
if ($this->items[$i]->description != "") {
|
||||
|
||||
/*
|
||||
* ATOM should have at least summary tag, however this implementation may be inaccurate
|
||||
*/
|
||||
$tempdesc = $this->items[$i]->getDescription();
|
||||
$temptype = "";
|
||||
|
||||
if ($this->items[$i]->descriptionHtmlSyndicated) {
|
||||
$temptype = " type=\"html\"";
|
||||
$tempdesc = $this->items[$i]->getDescription();
|
||||
|
||||
}
|
||||
|
||||
if (empty($this->items[$i]->descriptionTruncSize)) {
|
||||
$feed .= " <content".$temptype.">".$tempdesc."</content>\n";
|
||||
}
|
||||
|
||||
$feed .= " <summary".$temptype.">".$tempdesc."</summary>\n";
|
||||
} else {
|
||||
|
||||
$feed .= " <summary>no summary</summary>\n";
|
||||
|
||||
}
|
||||
|
||||
if ($this->items[$i]->enclosure != null) {
|
||||
$feed .= " <link rel=\"enclosure\" href=\"".$this->items[$i]->enclosure->url."\" type=\"".$this->items[$i]->enclosure->type."\" length=\"".$this->items[$i]->enclosure->length."\"";
|
||||
|
||||
if ($this->items[$i]->enclosure->language != "") {
|
||||
$feed .= " xml:lang=\"".$this->items[$i]->enclosure->language."\" ";
|
||||
}
|
||||
|
||||
if ($this->items[$i]->enclosure->title != "") {
|
||||
$feed .= " title=\"".$this->items[$i]->enclosure->title."\" ";
|
||||
}
|
||||
|
||||
$feed .= " /> \n";
|
||||
}
|
||||
if ($this->items[$i]->lat != "") {
|
||||
$feed .= " <georss:point>".$this->items[$i]->lat." ".$this->items[$i]->long."</georss:point>\n";
|
||||
}
|
||||
$feed .= " </entry>\n";
|
||||
}
|
||||
$feed .= "</feed>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* FeedCreator is the abstract base implementation for concrete
|
||||
* implementations that implement a specific format of syndication.
|
||||
*
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @since 1.4
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
abstract class FeedCreator extends HtmlDescribable
|
||||
{
|
||||
|
||||
/**
|
||||
* Mandatory attributes of a feed.
|
||||
*/
|
||||
public $title, $description, $link;
|
||||
public $format = 'BASE';
|
||||
|
||||
/**
|
||||
* Optional attributes of a feed.
|
||||
*/
|
||||
public $syndicationURL, $image, $language, $copyright, $pubDate, $lastBuildDate, $editor, $editorEmail, $webmaster, $category, $docs, $ttl, $rating, $skipHours, $skipDays;
|
||||
|
||||
/**
|
||||
* The url of the external xsl stylesheet used to format the naked rss feed.
|
||||
* Ignored in the output when empty.
|
||||
*/
|
||||
public $xslStyleSheet = "";
|
||||
|
||||
|
||||
/** @var FeedItem[] */
|
||||
public $items = Array();
|
||||
|
||||
/**
|
||||
* Generator string
|
||||
*/
|
||||
public $generator = "info@mypapit.net";
|
||||
|
||||
/**
|
||||
* This feed's MIME content type.
|
||||
*
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected $contentType = "application/xml";
|
||||
|
||||
/**
|
||||
* This feed's character encoding.
|
||||
*
|
||||
* @since 1.6.1
|
||||
*/
|
||||
protected $encoding = "UTF-8"; //"ISO-8859-1";
|
||||
|
||||
/**
|
||||
* Any additional elements to include as an associated array. All $key => $value pairs
|
||||
* will be included unencoded in the feed in the form
|
||||
* <$key>$value</$key>
|
||||
* Again: No encoding will be used! This means you can invalidate or enhance the feed
|
||||
* if $value contains markup. This may be abused to embed tags not implemented by
|
||||
* the FeedCreator class used.
|
||||
*/
|
||||
public $additionalElements = Array();
|
||||
|
||||
/**
|
||||
* Adds a FeedItem to the feed.
|
||||
*
|
||||
* @param FeedItem $item The FeedItem to add to the feed.
|
||||
*/
|
||||
public function addItem($item)
|
||||
{
|
||||
$this->items[] = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version string for the generator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
return FEEDCREATOR_VERSION." (".$this->generator.")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates a string to a certain length at the most sensible point.
|
||||
* First, if there's a '.' character near the end of the string, the string is truncated after this character.
|
||||
* If there is no '.', the string is truncated after the last ' ' character.
|
||||
* If the string is truncated, " ..." is appended.
|
||||
* If the string is already shorter than $length, it is returned unchanged.
|
||||
*
|
||||
* @param string $string A string to be truncated.
|
||||
* @param int $length the maximum length the string should be truncated to
|
||||
* @return string the truncated string
|
||||
*/
|
||||
public static function iTrunc($string, $length)
|
||||
{
|
||||
if (strlen($string) <= $length) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
$pos = strrpos($string, ".");
|
||||
if ($pos >= $length - 4) {
|
||||
$string = substr($string, 0, $length - 4);
|
||||
$pos = strrpos($string, ".");
|
||||
}
|
||||
if ($pos >= $length * 0.4) {
|
||||
return substr($string, 0, $pos + 1)." ...";
|
||||
}
|
||||
|
||||
$pos = strrpos($string, " ");
|
||||
if ($pos >= $length - 4) {
|
||||
$string = substr($string, 0, $length - 4);
|
||||
$pos = strrpos($string, " ");
|
||||
}
|
||||
if ($pos >= $length * 0.4) {
|
||||
return substr($string, 0, $pos)." ...";
|
||||
}
|
||||
|
||||
return substr($string, 0, $length - 4)." ...";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a comment indicating the generator of this feed.
|
||||
* The format of this comment seems to be recognized by
|
||||
* Syndic8.com.
|
||||
*/
|
||||
protected function _createGeneratorComment()
|
||||
{
|
||||
return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string containing all additional elements specified in
|
||||
* $additionalElements.
|
||||
*
|
||||
* @param array $elements an associative array containing key => value pairs
|
||||
* @param string $indentString a string that will be inserted before every generated line
|
||||
* @return string the XML tags corresponding to $additionalElements
|
||||
*/
|
||||
protected function _createAdditionalElements($elements, $indentString = "")
|
||||
{
|
||||
$ae = "";
|
||||
if (is_array($elements)) {
|
||||
foreach ($elements AS $key => $value) {
|
||||
$ae .= $indentString."<$key>$value</$key>\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $ae;
|
||||
}
|
||||
|
||||
protected function _createStylesheetReferences()
|
||||
{
|
||||
$xml = "";
|
||||
if (!empty($this->cssStyleSheet)) {
|
||||
$xml .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";
|
||||
}
|
||||
if (!empty($this->xslStyleSheet)) {
|
||||
$xml .= "<?xml-stylesheet href=\"".$this->xslStyleSheet."\" type=\"text/xsl\"?>\n";
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the feed's text.
|
||||
*
|
||||
* @return string the feed's complete text
|
||||
*/
|
||||
abstract public function createFeed();
|
||||
|
||||
/**
|
||||
* Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed
|
||||
* to .xml. For example: echo $_SERVER["PHP_SELF"]."\n"; echo FeedCreator::_generateFilename(); would produce:
|
||||
* /rss/latestnews.php
|
||||
* latestnews.xml
|
||||
*
|
||||
* @return string the feed cache filename
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected function _generateFilename()
|
||||
{
|
||||
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
|
||||
|
||||
return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".xml";
|
||||
}
|
||||
|
||||
/**
|
||||
* Send given file to Browser
|
||||
*
|
||||
* @since 1.4
|
||||
* @param string $filename
|
||||
*/
|
||||
protected function _redirect($filename)
|
||||
{
|
||||
// attention, heavily-commented-out-area
|
||||
|
||||
// maybe use this in addition to file time checking
|
||||
//header("Expires: ".date("r",time()+$this->_timeout));
|
||||
|
||||
/* no caching at all, doesn't seem to work as good:
|
||||
header("Cache-Control: no-cache");
|
||||
header("Pragma: no-cache");
|
||||
*/
|
||||
|
||||
// HTTP redirect, some feed readers' simple HTTP implementations don't follow it
|
||||
//header("Location: ".$filename);
|
||||
|
||||
header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".basename($filename));
|
||||
if (preg_match('/\.(kml|gpx)$/', $filename)) {
|
||||
header("Content-Disposition: attachment; filename=".basename($filename));
|
||||
} else {
|
||||
header("Content-Disposition: inline; filename=".basename($filename));
|
||||
}
|
||||
readfile($filename);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on caching and checks if there is a recent version of this feed in the cache.
|
||||
* If there is, an HTTP redirect header is sent.
|
||||
* To effectively use caching, you should create the FeedCreator object and call this method
|
||||
* before anything else, especially before you do the time consuming task to build the feed
|
||||
* (web fetching, for example).
|
||||
*
|
||||
* @since 1.4
|
||||
* @param string $filename optional the filename where a recent version of the feed is saved. If not specified,
|
||||
* the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see
|
||||
* _generateFilename()).
|
||||
* @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to
|
||||
* 3600 = 1 hour)
|
||||
*/
|
||||
public function useCached($filename = "", $timeout = 3600)
|
||||
{
|
||||
$this->_timeout = $timeout;
|
||||
if ($filename == "") {
|
||||
$filename = $this->_generateFilename();
|
||||
}
|
||||
if (file_exists($filename) AND (time() - filemtime($filename) < $timeout)) {
|
||||
$this->_redirect($filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this feed as a file on the local disk. After the file is saved, a redirect
|
||||
* header may be sent to redirect the user to the newly created file.
|
||||
*
|
||||
* @since 1.4
|
||||
* @param string $filename optional the filename where a recent version of the feed is saved. If not
|
||||
* specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml
|
||||
* (see _generateFilename()).
|
||||
* @param bool $displayContents optional send an HTTP redirect header or not. If true, the user will be
|
||||
* automatically redirected to the created file.
|
||||
*/
|
||||
public function saveFeed($filename = "", $displayContents = true)
|
||||
{
|
||||
if ($filename == "") {
|
||||
$filename = $this->_generateFilename();
|
||||
}
|
||||
$feedFile = fopen($filename, "w+");
|
||||
if ($feedFile) {
|
||||
fputs($feedFile, $this->createFeed());
|
||||
fclose($feedFile);
|
||||
if ($displayContents) {
|
||||
$this->_redirect($filename);
|
||||
}
|
||||
} else {
|
||||
echo "<br /><b>Error creating feed file, please check write permissions.</b><br />";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* GPXCreator is a FeedCreator that implements a GPX output, suitable for a GIS packages
|
||||
*
|
||||
* @since 1.7.6
|
||||
* @author Barry Hunter <geo@barryhunter.co.uk>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class GPXCreator extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* GPXCreator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "text/xml";
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<gpx xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\"
|
||||
creator=\"".FEEDCREATOR_VERSION."\"
|
||||
xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">\n";
|
||||
|
||||
$now = new FeedDate();
|
||||
$feed .= "<desc>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</desc>
|
||||
<author>{$http_host}</author>
|
||||
<url>".htmlspecialchars($this->link)."</url>
|
||||
<time>".htmlspecialchars($now->iso8601())."</time>
|
||||
\n";
|
||||
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= "<wpt lat=\"".$this->items[$i]->lat."\" lon=\"".$this->items[$i]->long."\">
|
||||
<name>".substr(htmlspecialchars(strip_tags($this->items[$i]->title)), 0, 6)."</name>
|
||||
<desc>".htmlspecialchars(strip_tags($this->items[$i]->title))."</desc>
|
||||
<src>".htmlspecialchars($this->items[$i]->author)."</src>
|
||||
<url>".htmlspecialchars($this->items[$i]->link)."</url>
|
||||
</wpt>\n";
|
||||
}
|
||||
$feed .= "</gpx>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* HTMLCreator is a FeedCreator that writes an HTML feed file to a specific
|
||||
* location, overriding the createFeed method of the parent FeedCreator.
|
||||
* The HTML produced can be included over http by scripting languages, or serve
|
||||
* as the source for an IFrame.
|
||||
* All output by this class is embedded in <div></div> tags to enable formatting
|
||||
* using CSS.
|
||||
*
|
||||
* @author Pascal Van Hecke
|
||||
* @since 1.7
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class HTMLCreator extends FeedCreator
|
||||
{
|
||||
|
||||
protected $contentType = "text/html";
|
||||
|
||||
/**
|
||||
* Contains HTML to be output at the start of the feed's html representation.
|
||||
*/
|
||||
public $header;
|
||||
|
||||
/**
|
||||
* Contains HTML to be output at the end of the feed's html representation.
|
||||
*/
|
||||
public $footer;
|
||||
|
||||
/**
|
||||
* Contains HTML to be output between entries. A separator is only used in
|
||||
* case of multiple entries.
|
||||
*/
|
||||
public $separator;
|
||||
|
||||
/**
|
||||
* Used to prefix the stylenames to make sure they are unique
|
||||
* and do not clash with stylenames on the user's page.
|
||||
*/
|
||||
public $stylePrefix;
|
||||
|
||||
/** @var bool Determines whether the links open in a new window or not. */
|
||||
public $openInNewWindow = true;
|
||||
|
||||
/** @var string image alignments in output */
|
||||
public $imageAlign = "right";
|
||||
|
||||
/**
|
||||
* In case of very simple output you may want to get rid of the style tags,
|
||||
* hence this variable. There's no equivalent on item level, but of course you can
|
||||
* add strings to it while iterating over the items ($this->stylelessOutput .= ...)
|
||||
* and when it is non-empty, ONLY the styleless output is printed, the rest is ignored
|
||||
* in the function createFeed().
|
||||
*/
|
||||
public $stylelessOutput = "";
|
||||
|
||||
/**
|
||||
* Writes the HTML.
|
||||
*
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function createFeed()
|
||||
{
|
||||
// if there is styleless output, use the content of this variable and ignore the rest
|
||||
if ($this->stylelessOutput != "") {
|
||||
return $this->stylelessOutput;
|
||||
}
|
||||
|
||||
//if no stylePrefix is set, generate it yourself depending on the script name
|
||||
if ($this->stylePrefix == "") {
|
||||
$this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_";
|
||||
}
|
||||
|
||||
//set an openInNewWindow_token_to be inserted or not
|
||||
if ($this->openInNewWindow) {
|
||||
$targetInsert = " class='target_blank'";
|
||||
} else {
|
||||
$targetInsert = '';
|
||||
}
|
||||
|
||||
// use this array to put the lines in and implode later with "document.write" javascript
|
||||
$feedArray = array();
|
||||
if ($this->image != null) {
|
||||
$imageStr = "<a href='".$this->image->link."'".$targetInsert.">".
|
||||
"<img src='".$this->image->url."' border='0' alt='".
|
||||
FeedCreator::iTrunc(htmlspecialchars($this->image->title), 100).
|
||||
"' align='".$this->imageAlign."' ";
|
||||
if ($this->image->width) {
|
||||
$imageStr .= " width='".$this->image->width."' ";
|
||||
}
|
||||
if ($this->image->height) {
|
||||
$imageStr .= " height='".$this->image->height."' ";
|
||||
}
|
||||
$imageStr .= "/></a>";
|
||||
$feedArray[] = $imageStr;
|
||||
}
|
||||
|
||||
if ($this->title) {
|
||||
$feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".
|
||||
FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</a></div>";
|
||||
}
|
||||
if ($this->getDescription()) {
|
||||
$feedArray[] = "<div class='".$this->stylePrefix."description'>".
|
||||
str_replace("]]>", "", str_replace("<![CDATA[", "", $this->getDescription())).
|
||||
"</div>";
|
||||
}
|
||||
|
||||
if ($this->header) {
|
||||
$feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
if ($this->separator and $i > 0) {
|
||||
$feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";
|
||||
}
|
||||
|
||||
if ($this->items[$i]->title) {
|
||||
if ($this->items[$i]->link) {
|
||||
$feedArray[] =
|
||||
"<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.
|
||||
"item_title'".$targetInsert.">".FeedCreator::iTrunc(
|
||||
htmlspecialchars(strip_tags($this->items[$i]->title)),
|
||||
100
|
||||
).
|
||||
"</a></div>";
|
||||
} else {
|
||||
$feedArray[] =
|
||||
"<div class='".$this->stylePrefix."item_title'>".
|
||||
FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100).
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
if ($this->items[$i]->getDescription()) {
|
||||
$feedArray[] =
|
||||
"<div class='".$this->stylePrefix."item_description'>".
|
||||
str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
if ($this->footer) {
|
||||
$feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";
|
||||
}
|
||||
|
||||
$feed = "".join($feedArray, "\r\n");
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides parent to produce .html extensions
|
||||
*
|
||||
* @return string the feed cache filename
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected function _generateFilename()
|
||||
{
|
||||
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
|
||||
|
||||
return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".html";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* JSCreator is a class that writes a js file to a specific
|
||||
* location, overriding the createFeed method of the parent HTMLCreator.
|
||||
*
|
||||
* @author Pascal Van Hecke
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class JSCreator extends HTMLCreator
|
||||
{
|
||||
protected $contentType = "text/javascript";
|
||||
|
||||
/**
|
||||
* writes the javascript
|
||||
*
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = parent::createFeed();
|
||||
$feedArray = explode("\n", $feed);
|
||||
|
||||
$jsFeed = "";
|
||||
foreach ($feedArray as $value) {
|
||||
$jsFeed .= "document.write('".trim(addslashes($value))."');\n";
|
||||
}
|
||||
|
||||
return $jsFeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides parent to produce .js extensions
|
||||
*
|
||||
* @return string the feed cache filename
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected function _generateFilename()
|
||||
{
|
||||
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
|
||||
|
||||
return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".js";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* KMLCreator is a FeedCreator that implements a KML output, suitable for Keyhole/Google Earth
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @author Barry Hunter <geo@barryhunter.co.uk>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class KMLCreator extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* KMLCreator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "application/vnd.google-earth.kml+xml";
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n";
|
||||
$feed .= "<Document>\n";
|
||||
if ($_GET['LinkControl']) {
|
||||
$feed .= "<NetworkLinkControl>\n<minRefreshPeriod>3600</minRefreshPeriod>\n</NetworkLinkControl>\n";
|
||||
}
|
||||
if (!empty($_GET['simple']) && count($this->items) > 0) {
|
||||
$feed .= "<Style id=\"defaultIcon\">
|
||||
<LabelStyle>
|
||||
<scale>0</scale>
|
||||
</LabelStyle>
|
||||
</Style>
|
||||
<Style id=\"hoverIcon\">".
|
||||
(($this->items[0]->thumb != "") ? "
|
||||
<IconStyle id=\"hoverIcon\">
|
||||
<scale>2.1</scale>
|
||||
</IconStyle>" : '')."
|
||||
</Style>
|
||||
<StyleMap id=\"defaultStyle\">
|
||||
<Pair>
|
||||
<key>normal</key>
|
||||
<styleUrl>#defaultIcon</styleUrl>
|
||||
</Pair>
|
||||
<Pair>
|
||||
<key>highlight</key>
|
||||
<styleUrl>#hoverIcon</styleUrl>
|
||||
</Pair>
|
||||
</StyleMap>
|
||||
";
|
||||
$style = "#defaultStyle";
|
||||
} else {
|
||||
$style = "root://styleMaps#default?iconId=0x307";
|
||||
}
|
||||
$feed .= "<Folder>\n";
|
||||
$feed .= " <name>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</name>
|
||||
<description>".$this->getDescription()."</description>
|
||||
<visibility>1</visibility>\n";
|
||||
$this->truncSize = 500;
|
||||
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
//added here beucase description gets auto surrounded by cdata
|
||||
$this->items[$i]->description = "<b>".$this->items[$i]->description."</b><br/>
|
||||
".$this->items[$i]->licence."
|
||||
<br/><br/><a href=\"".htmlspecialchars($this->items[$i]->link)."\">View Online</a>";
|
||||
|
||||
$feed .= "
|
||||
<Placemark>
|
||||
<description>".$this->items[$i]->getDescription(true)."</description>
|
||||
<name>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</name>
|
||||
<visibility>1</visibility>
|
||||
<Point>
|
||||
<coordinates>".$this->items[$i]->long.",".$this->items[$i]->lat.",25</coordinates>
|
||||
</Point>";
|
||||
if ($this->items[$i]->thumb != "") {
|
||||
$feed .= "
|
||||
<styleUrl>$style</styleUrl>
|
||||
<Style>
|
||||
<icon>".htmlspecialchars($this->items[$i]->thumb)."</icon>
|
||||
</Style>";
|
||||
}
|
||||
$feed .= "
|
||||
</Placemark>\n";
|
||||
}
|
||||
$feed .= "</Folder>\n</Document>\n</kml>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
|
||||
*
|
||||
* @return string the feed cache filename
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected function _generateFilename()
|
||||
{
|
||||
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
|
||||
|
||||
return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".kml";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* MBOXCreator is a FeedCreator that implements the mbox format
|
||||
* as described in http://www.qmail.org/man/man5/mbox.html
|
||||
*
|
||||
* @since 1.3
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class MBOXCreator extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* MBOXCreator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "text/plain";
|
||||
$this->encoding = "ISO-8859-15";
|
||||
}
|
||||
|
||||
/**
|
||||
* Quoted Printable encoding
|
||||
*
|
||||
* @param string $input
|
||||
* @param int $line_max wrap lines after these number of characters
|
||||
* @return string
|
||||
*/
|
||||
protected function qp_enc($input = "", $line_max = 76)
|
||||
{
|
||||
$hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
|
||||
$lines = preg_split("/(?:\r\n|\r|\n)/", $input);
|
||||
$eol = "\r\n";
|
||||
$escape = "=";
|
||||
$output = "";
|
||||
foreach ($lines as $line) {
|
||||
$linlen = strlen($line);
|
||||
$newline = "";
|
||||
for ($i = 0; $i < $linlen; $i++) {
|
||||
$c = substr($line, $i, 1);
|
||||
$dec = ord($c);
|
||||
if (($dec == 32) && ($i == ($linlen - 1))) { // convert space at eol only
|
||||
$c = "=20";
|
||||
} elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required
|
||||
$h2 = floor($dec / 16);
|
||||
$h1 = floor($dec % 16);
|
||||
$c = $escape.$hex["$h2"].$hex["$h1"];
|
||||
}
|
||||
if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
|
||||
$output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
|
||||
$newline = "";
|
||||
}
|
||||
$newline .= $c;
|
||||
} // end of for
|
||||
$output .= $newline.$eol;
|
||||
}
|
||||
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the MBOX contents.
|
||||
*
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = '';
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
if ($this->items[$i]->author != "") {
|
||||
$from = $this->items[$i]->author;
|
||||
} else {
|
||||
$from = $this->title;
|
||||
}
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= "From ".strtr(MBOXCreator::qp_enc($from), " ", "_")." ".date(
|
||||
"D M d H:i:s Y",
|
||||
$itemDate->unix()
|
||||
)."\n";
|
||||
$feed .= "Content-Type: text/plain;\n";
|
||||
$feed .= " charset=\"".$this->encoding."\"\n";
|
||||
$feed .= "Content-Transfer-Encoding: quoted-printable\n";
|
||||
$feed .= "Content-Type: text/plain\n";
|
||||
$feed .= "From: \"".MBOXCreator::qp_enc($from)."\"\n";
|
||||
$feed .= "Date: ".$itemDate->rfc822()."\n";
|
||||
$feed .= "Subject: ".MBOXCreator::qp_enc(FeedCreator::iTrunc($this->items[$i]->title, 100))."\n";
|
||||
$feed .= "\n";
|
||||
$body = chunk_split(MBOXCreator::qp_enc($this->items[$i]->description));
|
||||
$feed .= preg_replace("~\nFrom ([^\n]*)(\n?)~", "\n>From $1$2\n", $body);
|
||||
$feed .= "\n";
|
||||
$feed .= "\n";
|
||||
}
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
|
||||
*
|
||||
* @return string the feed cache filename
|
||||
* @since 1.4
|
||||
* @access private
|
||||
*/
|
||||
protected function _generateFilename()
|
||||
{
|
||||
$fileInfo = pathinfo($_SERVER["PHP_SELF"]);
|
||||
|
||||
return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".mbox";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* OPMLCreator is a FeedCreator that implements OPML 1.0.
|
||||
*
|
||||
* @see http://opml.scripting.com/spec
|
||||
* @author Dirk Clemens, Kai Blankenhorn
|
||||
* @since 1.5
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class OPMLCreator extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* OPMLCreator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createGeneratorComment();
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
|
||||
$feed .= " <head>\n";
|
||||
$feed .= " <title>".htmlspecialchars($this->title)."</title>\n";
|
||||
if ($this->pubDate != "") {
|
||||
$date = new FeedDate($this->pubDate);
|
||||
$feed .= " <dateCreated>".$date->rfc822()."</dateCreated>\n";
|
||||
}
|
||||
if ($this->lastBuildDate != "") {
|
||||
$date = new FeedDate($this->lastBuildDate);
|
||||
$feed .= " <dateModified>".$date->rfc822()."</dateModified>\n";
|
||||
}
|
||||
if ($this->editor != "") {
|
||||
$feed .= " <ownerName>".$this->editor."</ownerName>\n";
|
||||
}
|
||||
if ($this->editorEmail != "") {
|
||||
$feed .= " <ownerEmail>".$this->editorEmail."</ownerEmail>\n";
|
||||
}
|
||||
$feed .= " </head>\n";
|
||||
$feed .= " <body>\n";
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <outline type=\"rss\" ";
|
||||
$title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", " ")));
|
||||
$feed .= " title=\"".$title."\"";
|
||||
$feed .= " text=\"".$title."\"";
|
||||
|
||||
if (isset($this->items[$i]->xmlUrl)) {
|
||||
$feed .= " xmlUrl=\"".htmlspecialchars($this->items[$i]->xmlUrl)."\"";
|
||||
}
|
||||
|
||||
if (isset($this->items[$i]->link)) {
|
||||
$feed .= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";
|
||||
}
|
||||
|
||||
$feed .= "/>\n";
|
||||
}
|
||||
$feed .= " </body>\n";
|
||||
$feed .= "</opml>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCreator is a FeedCreator that implements a PHP output, suitable for an include
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @author Barry Hunter <geo@barryhunter.co.uk>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class PHPCreator extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* PHPCreator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->contentType = "text/plain";
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?php\n";
|
||||
$feed .= "class FeedItem {}\n";
|
||||
$feed .= " \$feedTitle='".addslashes(FeedCreator::iTrunc(htmlspecialchars($this->title), 100))."';\n";
|
||||
$this->truncSize = 500;
|
||||
$feed .= " \$feedDescription='".addslashes($this->getDescription())."';\n";
|
||||
$feed .= " \$feedLink='".$this->link."';\n";
|
||||
$feed .= " \$feedItem = array();\n";
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " \$feedItem[$i] = new FeedItem();\n";
|
||||
if ($this->items[$i]->guid != "") {
|
||||
$feed .= " \$feedItem[$i]->id='".htmlspecialchars($this->items[$i]->guid)."';\n";
|
||||
}
|
||||
$feed .= " \$feedItem[$i]->title='".addslashes(
|
||||
FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)
|
||||
)."';\n";
|
||||
$feed .= " \$feedItem[$i]->link='".htmlspecialchars($this->items[$i]->link)."';\n";
|
||||
$feed .= " \$feedItem[$i]->date=".htmlspecialchars($this->items[$i]->date).";\n";
|
||||
if ($this->items[$i]->author != "") {
|
||||
$feed .= " \$feedItem[$i]->author='".htmlspecialchars($this->items[$i]->author)."';\n";
|
||||
if ($this->items[$i]->authorEmail != "") {
|
||||
$feed .= " \$feedItem[$i]->authorEmail='".$this->items[$i]->authorEmail."';\n";
|
||||
}
|
||||
}
|
||||
$feed .= " \$feedItem[$i]->description='".addslashes($this->items[$i]->getDescription())."';\n";
|
||||
if ($this->items[$i]->thumb != "") {
|
||||
$feed .= " \$feedItem[$i]->thumbURL='".htmlspecialchars($this->items[$i]->thumb)."';\n";
|
||||
}
|
||||
}
|
||||
$feed .= "?>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PIECreator01 is a FeedCreator that implements the emerging PIE specification,
|
||||
* as in http://intertwingly.net/wiki/pie/Syntax.
|
||||
*
|
||||
* @deprecated
|
||||
* @since 1.3
|
||||
* @author Scott Reynen <scott@randomchaos.com> and Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class PIECreator01 extends FeedCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* PIECreator01 constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->encoding = "utf-8";
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
|
||||
$feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</title>\n";
|
||||
$this->truncSize = 500;
|
||||
$feed .= " <subtitle>".$this->getDescription()."</subtitle>\n";
|
||||
$feed .= " <link>".$this->link."</link>\n";
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <entry>\n";
|
||||
$feed .= " <title>".FeedCreator::iTrunc(
|
||||
htmlspecialchars(strip_tags($this->items[$i]->title)),
|
||||
100
|
||||
)."</title>\n";
|
||||
$feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= " <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
|
||||
$feed .= " <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
|
||||
$feed .= " <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
|
||||
$feed .= " <id>".htmlspecialchars($this->items[$i]->guid)."</id>\n";
|
||||
if ($this->items[$i]->author != "") {
|
||||
$feed .= " <author>\n";
|
||||
$feed .= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
|
||||
if ($this->items[$i]->authorEmail != "") {
|
||||
$feed .= " <email>".$this->items[$i]->authorEmail."</email>\n";
|
||||
}
|
||||
$feed .= " </author>\n";
|
||||
}
|
||||
$feed .= " <content type=\"text/html\" xml:lang=\"en-us\">\n";
|
||||
$feed .= " <div xmlns=\"http://www.w3.org/1999/xhtml\">".$this->items[$i]->getDescription(
|
||||
)."</div>\n";
|
||||
$feed .= " </content>\n";
|
||||
$feed .= " </entry>\n";
|
||||
}
|
||||
$feed .= "</feed>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* RSSCreator091 is a FeedCreator that implements RSS 0.91 Spec, revision 3.
|
||||
*
|
||||
* @see http://my.netscape.com/publish/formats/rss-spec-0.91.html
|
||||
* @since 1.3
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class RSSCreator091 extends FeedCreator
|
||||
{
|
||||
|
||||
/** @var string Stores this RSS feed's version number. */
|
||||
protected $RSSVersion;
|
||||
|
||||
/**
|
||||
* RSSCreator091 constructor.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->_setRSSVersion("0.91");
|
||||
$this->contentType = "application/rss+xml";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this RSS feed's version number.
|
||||
*
|
||||
* @param string $version
|
||||
*/
|
||||
protected function _setRSSVersion($version)
|
||||
{
|
||||
$this->RSSVersion = $version;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createGeneratorComment();
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<rss version=\"".$this->RSSVersion."\"";
|
||||
|
||||
if (count($this->items) > 0
|
||||
&& !empty($this->items[0]->lat)
|
||||
) {
|
||||
$feed .= " xmlns:georss=\"http://www.georss.org/georss/\"\n";
|
||||
}
|
||||
if (count($this->items) > 0
|
||||
&& isset($this->items[0]->additionalElements['xcal:dtstart'])
|
||||
) {
|
||||
$feed .= " xmlns:xcal=\"urn:ietf:params:xml:ns:xcal\"\n";
|
||||
}
|
||||
$feed .= ">\n";
|
||||
if ($this->format == 'BASE') {
|
||||
$feed .= " <channel xmlns:g=\"http://base.google.com/ns/1.0\">\n";
|
||||
} else {
|
||||
$feed .= " <channel>\n";
|
||||
}
|
||||
$feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</title>\n";
|
||||
$this->descriptionTruncSize = 500;
|
||||
$feed .= " <description>".$this->getDescription()."</description>\n";
|
||||
$feed .= " <link>".$this->link."</link>\n";
|
||||
$now = new FeedDate();
|
||||
$feed .= " <lastBuildDate>".htmlspecialchars(
|
||||
$this->lastBuildDate ?: $now->rfc822()
|
||||
)."</lastBuildDate>\n";
|
||||
$feed .= " <generator>".FEEDCREATOR_VERSION."</generator>\n";
|
||||
|
||||
if ($this->image != null) {
|
||||
$feed .= " <image>\n";
|
||||
$feed .= " <url>".$this->image->url."</url>\n";
|
||||
$feed .= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title), 100)."</title>\n";
|
||||
$feed .= " <link>".$this->image->link."</link>\n";
|
||||
if ($this->image->width != "") {
|
||||
$feed .= " <width>".$this->image->width."</width>\n";
|
||||
}
|
||||
if ($this->image->height != "") {
|
||||
$feed .= " <height>".$this->image->height."</height>\n";
|
||||
}
|
||||
if ($this->image->description != "") {
|
||||
$feed .= " <description>".htmlspecialchars($this->image->description)."</description>\n";
|
||||
}
|
||||
$feed .= " </image>\n";
|
||||
}
|
||||
if ($this->language != "") {
|
||||
$feed .= " <language>".$this->language."</language>\n";
|
||||
}
|
||||
if ($this->copyright != "") {
|
||||
$feed .= " <copyright>".FeedCreator::iTrunc(
|
||||
htmlspecialchars($this->copyright),
|
||||
100
|
||||
)."</copyright>\n";
|
||||
}
|
||||
if ($this->editor != "") {
|
||||
$feed .= " <managingEditor>".FeedCreator::iTrunc(
|
||||
htmlspecialchars($this->editor),
|
||||
100
|
||||
)."</managingEditor>\n";
|
||||
}
|
||||
if ($this->webmaster != "") {
|
||||
$feed .= " <webMaster>".FeedCreator::iTrunc(
|
||||
htmlspecialchars($this->webmaster),
|
||||
100
|
||||
)."</webMaster>\n";
|
||||
}
|
||||
if ($this->pubDate != "") {
|
||||
$pubDate = new FeedDate($this->pubDate);
|
||||
$feed .= " <pubDate>".htmlspecialchars($pubDate->rfc822())."</pubDate>\n";
|
||||
}
|
||||
if ($this->category != "") {
|
||||
$feed .= " <category>".htmlspecialchars($this->category)."</category>\n";
|
||||
}
|
||||
if ($this->docs != "") {
|
||||
$feed .= " <docs>".FeedCreator::iTrunc(htmlspecialchars($this->docs), 500)."</docs>\n";
|
||||
}
|
||||
if ($this->ttl != "") {
|
||||
$feed .= " <ttl>".htmlspecialchars($this->ttl)."</ttl>\n";
|
||||
}
|
||||
if ($this->rating != "") {
|
||||
$feed .= " <rating>".FeedCreator::iTrunc(htmlspecialchars($this->rating), 500)."</rating>\n";
|
||||
}
|
||||
if ($this->skipHours != "") {
|
||||
$feed .= " <skipHours>".htmlspecialchars($this->skipHours)."</skipHours>\n";
|
||||
}
|
||||
if ($this->skipDays != "") {
|
||||
$feed .= " <skipDays>".htmlspecialchars($this->skipDays)."</skipDays>\n";
|
||||
}
|
||||
$feed .= $this->_createAdditionalElements($this->additionalElements, " ");
|
||||
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <item>\n";
|
||||
$feed .= " <title>".FeedCreator::iTrunc(
|
||||
htmlspecialchars(strip_tags($this->items[$i]->title)),
|
||||
100
|
||||
)."</title>\n";
|
||||
$feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
|
||||
$feed .= " <description>".$this->items[$i]->getDescription()."</description>\n";
|
||||
|
||||
$creator = $this->getAuthor($this->items[$i]->author, $this->items[$i]->authorEmail);
|
||||
if ($creator) {
|
||||
$feed .= " <author>".htmlspecialchars($creator)."</author>\n";
|
||||
}
|
||||
|
||||
/*
|
||||
// on hold
|
||||
if ($this->items[$i]->source!="") {
|
||||
$feed.= " <source>".htmlspecialchars($this->items[$i]->source)."</source>\n";
|
||||
}
|
||||
*/
|
||||
if ($this->items[$i]->lat != "") {
|
||||
$feed .= " <georss:point>".$this->items[$i]->lat." ".$this->items[$i]->long."</georss:point>\n";
|
||||
}
|
||||
if (is_array($this->items[$i]->category)) {
|
||||
foreach ($this->items[$i]->category as $cat) {
|
||||
$feed .= " <category>".htmlspecialchars($cat)."</category>\n";
|
||||
}
|
||||
} else {
|
||||
if ($this->items[$i]->category != "") {
|
||||
$feed .= " <category>".htmlspecialchars($this->items[$i]->category)."</category>\n";
|
||||
}
|
||||
}
|
||||
if ($this->items[$i]->comments != "") {
|
||||
$feed .= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n";
|
||||
}
|
||||
if ($this->items[$i]->date != "") {
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n";
|
||||
}
|
||||
if ($this->items[$i]->guid != "") {
|
||||
$feed .= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
|
||||
}
|
||||
if ($this->items[$i]->thumb != "") {
|
||||
$feed .= " <g:image_link>".htmlspecialchars($this->items[$i]->thumb)."</g:image_link>\n";
|
||||
}
|
||||
$feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
|
||||
$feed .= " </item>\n";
|
||||
}
|
||||
$feed .= " </channel>\n";
|
||||
$feed .= "</rss>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose the RSS-0.91 and RSS-2.0 author field.
|
||||
*
|
||||
* @author Joe Lapp <joe.lapp@pobox.com>
|
||||
*/
|
||||
function getAuthor($author, $email)
|
||||
{
|
||||
if ($author && $email) {
|
||||
return $email.' ('.$author.')';
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* RSSCreator10 is a FeedCreator that implements RDF Site Summary (RSS) 1.0.
|
||||
*
|
||||
* @see http://www.purl.org/rss/1.0/
|
||||
* @since 1.3
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class RSSCreator10 extends FeedCreator
|
||||
{
|
||||
|
||||
/** @inheritdoc */
|
||||
public function createFeed()
|
||||
{
|
||||
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
|
||||
$feed .= $this->_createGeneratorComment();
|
||||
if (empty($this->cssStyleSheet)) {
|
||||
$this->cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css";
|
||||
}
|
||||
$feed .= $this->_createStylesheetReferences();
|
||||
$feed .= "<rdf:RDF\n";
|
||||
$feed .= " xmlns=\"http://purl.org/rss/1.0/\"\n";
|
||||
$feed .= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
|
||||
$feed .= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
|
||||
if (!empty($this->items[0]->thumb)) {
|
||||
$feed .= " xmlns:photo=\"http://www.pheed.com/pheed/\"\n";
|
||||
}
|
||||
if (!empty($this->items[0]->lat)) {
|
||||
$feed .= " xmlns:georss=\"http://www.georss.org/georss\"\n";
|
||||
}
|
||||
$feed .= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
|
||||
$feed .= " <channel rdf:about=\"".$this->syndicationURL."\">\n";
|
||||
$feed .= " <title>".htmlspecialchars($this->title)."</title>\n";
|
||||
$feed .= " <description>".htmlspecialchars($this->description)."</description>\n";
|
||||
$feed .= " <link>".$this->link."</link>\n";
|
||||
if ($this->image != null) {
|
||||
$feed .= " <image rdf:resource=\"".$this->image->url."\" />\n";
|
||||
}
|
||||
$now = new FeedDate();
|
||||
$feed .= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n";
|
||||
$feed .= " <items>\n";
|
||||
$feed .= " <rdf:Seq>\n";
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
|
||||
}
|
||||
$feed .= " </rdf:Seq>\n";
|
||||
$feed .= " </items>\n";
|
||||
$feed .= " </channel>\n";
|
||||
if ($this->image != null) {
|
||||
$feed .= " <image rdf:about=\"".$this->image->url."\">\n";
|
||||
$feed .= " <title>".$this->image->title."</title>\n";
|
||||
$feed .= " <link>".$this->image->link."</link>\n";
|
||||
$feed .= " <url>".$this->image->url."</url>\n";
|
||||
$feed .= " </image>\n";
|
||||
}
|
||||
$feed .= $this->_createAdditionalElements($this->additionalElements, " ");
|
||||
|
||||
for ($i = 0; $i < count($this->items); $i++) {
|
||||
$feed .= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
|
||||
$feed .= " <dc:format>text/html</dc:format>\n";
|
||||
if ($this->items[$i]->date != null) {
|
||||
$itemDate = new FeedDate($this->items[$i]->date);
|
||||
$feed .= " <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n";
|
||||
}
|
||||
if ($this->items[$i]->source != "") {
|
||||
$feed .= " <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n";
|
||||
}
|
||||
$creator = $this->getAuthor($this->items[$i]->author, $this->items[$i]->authorEmail);
|
||||
if ($creator) {
|
||||
$feed .= " <dc:creator>".htmlspecialchars($creator)."</dc:creator>\n";
|
||||
}
|
||||
if ($this->items[$i]->lat != "") {
|
||||
$feed .= " <georss:point>".$this->items[$i]->lat." ".$this->items[$i]->long."</georss:point>\n";
|
||||
}
|
||||
if ($this->items[$i]->thumb != "") {
|
||||
$feed .= " <photo:thumbnail>".htmlspecialchars($this->items[$i]->thumb)."</photo:thumbnail>\n";
|
||||
}
|
||||
$feed .= " <title>".htmlspecialchars(
|
||||
strip_tags(strtr($this->items[$i]->title, "\n\r", " "))
|
||||
)."</title>\n";
|
||||
$feed .= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
|
||||
$feed .= " <description>".htmlspecialchars($this->items[$i]->description)."</description>\n";
|
||||
$feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
|
||||
$feed .= " </item>\n";
|
||||
}
|
||||
$feed .= "</rdf:RDF>\n";
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose the RSS-1.0 author field.
|
||||
*
|
||||
* @author Joe Lapp <joe.lapp@pobox.com>
|
||||
* @param string $author
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
protected function getAuthor($author, $email)
|
||||
{
|
||||
if ($author) {
|
||||
if ($email) {
|
||||
return $author.' ('.$email.')';
|
||||
}
|
||||
|
||||
return $author;
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* RSSCreator20 is a FeedCreator that implements RDF Site Summary (RSS) 2.0.
|
||||
*
|
||||
* @see http://backend.userland.com/rss
|
||||
* @since 1.3
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class RSSCreator20 extends RSSCreator091
|
||||
{
|
||||
|
||||
/**
|
||||
* RSSCreator20 constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::_setRSSVersion("2.0");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* FeedDate is an internal class that stores a date for a feed or feed item.
|
||||
* Usually, you won't need to use this.
|
||||
*
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class FeedDate
|
||||
{
|
||||
protected $unix;
|
||||
|
||||
/**
|
||||
* Creates a new instance of FeedDate representing a given date.
|
||||
* Accepts RFC 822, ISO 8601 date formats as well as unix time stamps.
|
||||
*
|
||||
* @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and
|
||||
* time is used.
|
||||
*/
|
||||
public function __construct($dateString = "")
|
||||
{
|
||||
if ($dateString == "") {
|
||||
$dateString = date("r");
|
||||
}
|
||||
|
||||
if (is_integer($dateString)) {
|
||||
$this->unix = $dateString;
|
||||
|
||||
return;
|
||||
}
|
||||
$tzOffset = 0;
|
||||
if (preg_match(
|
||||
"~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s+)?(\\d{1,2})\\s+([a-zA-Z]{3})\\s+(\\d{4})\\s+(\\d{2}):(\\d{2}):(\\d{2})\\s+(.*)~",
|
||||
$dateString,
|
||||
$matches
|
||||
)) {
|
||||
$months = Array(
|
||||
"Jan" => 1,
|
||||
"Feb" => 2,
|
||||
"Mar" => 3,
|
||||
"Apr" => 4,
|
||||
"May" => 5,
|
||||
"Jun" => 6,
|
||||
"Jul" => 7,
|
||||
"Aug" => 8,
|
||||
"Sep" => 9,
|
||||
"Oct" => 10,
|
||||
"Nov" => 11,
|
||||
"Dec" => 12,
|
||||
);
|
||||
$this->unix = mktime($matches[4], $matches[5], $matches[6], $months[$matches[2]], $matches[1], $matches[3]);
|
||||
if (substr($matches[7], 0, 1) == '+' OR substr($matches[7], 0, 1) == '-') {
|
||||
$tzOffset = (((int)substr($matches[7], 0, 3) * 60) + (int)substr($matches[7], -2)) * 60;
|
||||
} else {
|
||||
if (strlen($matches[7]) == 1) {
|
||||
$oneHour = 3600;
|
||||
$ord = ord($matches[7]);
|
||||
if ($ord < ord("M")) {
|
||||
$tzOffset = (ord("A") - $ord - 1) * $oneHour;
|
||||
} elseif ($ord >= ord("M") AND $matches[7] != "Z") {
|
||||
$tzOffset = ($ord - ord("M")) * $oneHour;
|
||||
} elseif ($matches[7] == "Z") {
|
||||
$tzOffset = 0;
|
||||
}
|
||||
}
|
||||
switch ($matches[7]) {
|
||||
case "UT":
|
||||
case "GMT":
|
||||
$tzOffset = 0;
|
||||
}
|
||||
}
|
||||
$this->unix += $tzOffset;
|
||||
|
||||
return;
|
||||
}
|
||||
if (preg_match("~(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(.*)~", $dateString, $matches)) {
|
||||
$this->unix = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
|
||||
if (substr($matches[7], 0, 1) == '+' OR substr($matches[7], 0, 1) == '-') {
|
||||
$tzOffset = (((int)substr($matches[7], 0, 3) * 60) + (int)substr($matches[7], -2)) * 60;
|
||||
} else {
|
||||
if ($matches[7] == "Z") {
|
||||
$tzOffset = 0;
|
||||
}
|
||||
}
|
||||
$this->unix += $tzOffset;
|
||||
|
||||
return;
|
||||
}
|
||||
$this->unix = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date stored in this FeedDate as an RFC 822 date.
|
||||
*
|
||||
* @return string a date in RFC 822 format
|
||||
*/
|
||||
public function rfc822()
|
||||
{
|
||||
//return gmdate("r",$this->unix);
|
||||
$date = gmdate("D, d M Y H:i:s O", $this->unix);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date stored in this FeedDate as an ISO 8601 date.
|
||||
*
|
||||
* @return string a date in ISO 8601 format
|
||||
*/
|
||||
public function iso8601()
|
||||
{
|
||||
$date = gmdate("Y-m-d\TH:i:sO", $this->unix);
|
||||
$date = substr($date, 0, 22).':'.substr($date, -2);
|
||||
if (TIME_ZONE != "") {
|
||||
$date = str_replace("+00:00", TIME_ZONE, $date);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date stored in this FeedDate as unix time stamp.
|
||||
*
|
||||
* @return int a date as a unix time stamp
|
||||
*/
|
||||
public function unix()
|
||||
{
|
||||
return $this->unix;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A FeedHtmlField describes and generates
|
||||
* a feed, item or image html field (probably a description). Output is
|
||||
* generated based on $truncSize, $syndicateHtml properties.
|
||||
*
|
||||
* @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info>
|
||||
* @version 1.6
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class FeedHtmlField
|
||||
{
|
||||
/**
|
||||
* Mandatory attributes of a FeedHtmlField.
|
||||
*/
|
||||
protected $rawFieldContent;
|
||||
|
||||
/**
|
||||
* Optional attributes of a FeedHtmlField.
|
||||
*/
|
||||
public $truncSize, $syndicateHtml;
|
||||
|
||||
/**
|
||||
* Creates a new instance of FeedHtmlField.
|
||||
*
|
||||
* @param string $parFieldContent if given, sets the rawFieldContent property
|
||||
*/
|
||||
public function __construct($parFieldContent)
|
||||
{
|
||||
if ($parFieldContent) {
|
||||
$this->rawFieldContent = $parFieldContent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the right output, depending on $truncSize, $syndicateHtml properties.
|
||||
*
|
||||
* @return string the formatted field
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
// when field available and syndicated in html we assume
|
||||
// - valid html in $rawFieldContent and we enclose in CDATA tags
|
||||
// - no truncation (truncating risks producing invalid html)
|
||||
if (!$this->rawFieldContent) {
|
||||
$result = "";
|
||||
} elseif ($this->syndicateHtml) {
|
||||
$result = "<![CDATA[".$this->rawFieldContent."]]>";
|
||||
} else {
|
||||
if ($this->truncSize and is_int($this->truncSize)) {
|
||||
$result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent), $this->truncSize);
|
||||
} else {
|
||||
$result = htmlspecialchars($this->rawFieldContent);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A FeedImage may be added to a FeedCreator feed.
|
||||
*
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @since 1.3
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class FeedImage extends HtmlDescribable
|
||||
{
|
||||
/**
|
||||
* Mandatory attributes of an image.
|
||||
*/
|
||||
public $title, $url, $link;
|
||||
|
||||
/**
|
||||
* Optional attributes of an image.
|
||||
*/
|
||||
public $width, $height, $description;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A FeedItem is a part of a FeedCreator feed.
|
||||
*
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @since 1.3
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class FeedItem extends HtmlDescribable
|
||||
{
|
||||
/**
|
||||
* Mandatory attributes of an item.
|
||||
*/
|
||||
public $title, $description, $link;
|
||||
|
||||
/**
|
||||
* Optional attributes of an item.
|
||||
*/
|
||||
public $author, $authorEmail, $authorURL, $image, $category, $categoryScheme, $comments, $guid, $source, $creator, $contributor, $lat, $long, $thumb;
|
||||
|
||||
/**
|
||||
* Publishing date of an item. May be in one of the following formats:
|
||||
* RFC 822:
|
||||
* "Mon, 20 Jan 03 18:05:41 +0400"
|
||||
* "20 Jan 03 18:05:41 +0000"
|
||||
* ISO 8601:
|
||||
* "2003-01-20T18:05:41+04:00"
|
||||
* Unix:
|
||||
* 1043082341
|
||||
*/
|
||||
public $date;
|
||||
|
||||
/**
|
||||
* Add <enclosure> element tag RSS 2.0, supported by ATOM 1.0 too
|
||||
* modified by : Mohammad Hafiz bin Ismail (mypapit@gmail.com)
|
||||
* display :
|
||||
* <enclosure length="17691" url="http://something.com/picture.jpg" type="image/jpeg" />
|
||||
*/
|
||||
public $enclosure;
|
||||
|
||||
/**
|
||||
* Any additional elements to include as an associated array. All $key => $value pairs
|
||||
* will be included unencoded in the feed item in the form
|
||||
* <$key>$value</$key>
|
||||
* Again: No encoding will be used! This means you can invalidate or enhance the feed
|
||||
* if $value contains markup. This may be abused to embed tags not implemented by
|
||||
* the FeedCreator class used.
|
||||
*/
|
||||
public $additionalElements = Array();
|
||||
|
||||
// on hold
|
||||
// var $source;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* An HtmlDescribable is an item within a feed that can have a description that may
|
||||
* include HTML markup.
|
||||
*
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class HtmlDescribable
|
||||
{
|
||||
/**
|
||||
* Indicates whether the description field should be rendered in HTML.
|
||||
*/
|
||||
public $descriptionHtmlSyndicated;
|
||||
|
||||
/**
|
||||
* Indicates whether and to how many characters a description should be truncated.
|
||||
*/
|
||||
public $descriptionTruncSize;
|
||||
|
||||
/** @var string the Description */
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* Returns a formatted description field, depending on descriptionHtmlSyndicated and
|
||||
* $descriptionTruncSize properties
|
||||
*
|
||||
* @param bool $overrideSyndicateHtml
|
||||
* @return string the formatted description
|
||||
*/
|
||||
public function getDescription($overrideSyndicateHtml = false)
|
||||
{
|
||||
$descriptionField = new FeedHtmlField($this->description);
|
||||
$descriptionField->syndicateHtml = $overrideSyndicateHtml || $this->descriptionHtmlSyndicated;
|
||||
$descriptionField->truncSize = $this->descriptionTruncSize;
|
||||
|
||||
return $descriptionField->output();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
// your local timezone, set to "" to disable or for GMT
|
||||
if (!defined('TIME_ZONE')) {
|
||||
define("TIME_ZONE", date("O", time()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Version string.
|
||||
*/
|
||||
define("FEEDCREATOR_VERSION", "FeedCreator 1.8");
|
||||
|
||||
/**
|
||||
* UniversalFeedCreator lets you choose during runtime which
|
||||
* format to build.
|
||||
* For general usage of a feed class, see the FeedCreator class
|
||||
* below or the example above.
|
||||
*
|
||||
* @since 1.3
|
||||
* @author Kai Blankenhorn <kaib@bitfolge.de>
|
||||
* @package de.bitfolge.feedcreator
|
||||
*/
|
||||
class UniversalFeedCreator extends FeedCreator
|
||||
{
|
||||
/** @var FeedCreator */
|
||||
protected $_feed;
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
*/
|
||||
protected function _setFormat($format)
|
||||
{
|
||||
switch (strtoupper($format)) {
|
||||
|
||||
case "BASE":
|
||||
$this->format = $format;
|
||||
case "2.0":
|
||||
// fall through
|
||||
case "RSS2.0":
|
||||
$this->_feed = new RSSCreator20();
|
||||
break;
|
||||
|
||||
case "GEOPHOTORSS":
|
||||
case "PHOTORSS":
|
||||
case "GEORSS":
|
||||
$this->format = $format;
|
||||
case "1.0":
|
||||
// fall through
|
||||
case "RSS1.0":
|
||||
$this->_feed = new RSSCreator10();
|
||||
break;
|
||||
|
||||
case "0.91":
|
||||
// fall through
|
||||
case "RSS0.91":
|
||||
$this->_feed = new RSSCreator091();
|
||||
break;
|
||||
|
||||
case "PIE0.1":
|
||||
$this->_feed = new PIECreator01();
|
||||
break;
|
||||
|
||||
case "MBOX":
|
||||
$this->_feed = new MBOXCreator();
|
||||
break;
|
||||
|
||||
case "OPML":
|
||||
$this->_feed = new OPMLCreator();
|
||||
break;
|
||||
|
||||
case "TOOLBAR":
|
||||
$this->format = $format;
|
||||
|
||||
case "ATOM":
|
||||
// fall through: always the latest ATOM version
|
||||
case "ATOM1.0":
|
||||
$this->_feed = new AtomCreator10();
|
||||
break;
|
||||
|
||||
case "ATOM0.3":
|
||||
$this->_feed = new AtomCreator03();
|
||||
break;
|
||||
|
||||
case "HTML":
|
||||
$this->_feed = new HTMLCreator();
|
||||
break;
|
||||
|
||||
case "PHP":
|
||||
$this->_feed = new PHPCreator();
|
||||
break;
|
||||
case "GPX":
|
||||
$this->_feed = new GPXCreator();
|
||||
break;
|
||||
case "KML":
|
||||
$this->_feed = new KMLCreator();
|
||||
break;
|
||||
case "JS":
|
||||
// fall through
|
||||
case "JAVASCRIPT":
|
||||
$this->_feed = new JSCreator();
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_feed = new RSSCreator091();
|
||||
break;
|
||||
}
|
||||
|
||||
$vars = get_object_vars($this);
|
||||
foreach ($vars as $key => $value) {
|
||||
// prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself
|
||||
if (!in_array($key, array("_feed", "contentType", "encoding"))) {
|
||||
$this->_feed->{$key} = $this->{$key};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a syndication feed based on the items previously added.
|
||||
*
|
||||
* @see FeedCreator::addItem()
|
||||
* @param string $format format the feed should comply to. Valid values are:
|
||||
* "PIE0.1", "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3", "HTML", "JS"
|
||||
* @return string the contents of the feed.
|
||||
*/
|
||||
public function createFeed($format = "RSS0.91")
|
||||
{
|
||||
$this->_setFormat($format);
|
||||
|
||||
return $this->_feed->createFeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect
|
||||
* header may be sent to redirect the use to the newly created file.
|
||||
*
|
||||
* @since 1.4
|
||||
* @param string $format format the feed should comply to. Valid values are:
|
||||
* "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM",
|
||||
* "ATOM0.3", "HTML", "JS"
|
||||
* @param string $filename optional the filename where a recent version of the feed is saved. If not
|
||||
* specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to
|
||||
* .xml (see _generateFilename()).
|
||||
* @param boolean $displayContents optional send the content of the file or not. If true, the file will be sent
|
||||
* in the body of the response.
|
||||
*/
|
||||
public function saveFeed($format = "RSS0.91", $filename = "", $displayContents = true)
|
||||
{
|
||||
$this->_setFormat($format);
|
||||
$this->_feed->saveFeed($filename, $displayContents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on caching and checks if there is a recent version of this feed in the cache.
|
||||
* If there is, an HTTP redirect header is sent.
|
||||
* To effectively use caching, you should create the FeedCreator object and call this method
|
||||
* before anything else, especially before you do the time consuming task to build the feed
|
||||
* (web fetching, for example).
|
||||
*
|
||||
* @param string $format format the feed should comply to. Valid values are:
|
||||
* "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
|
||||
* @param string $filename optional the filename where a recent version of the feed is saved. If not specified, the
|
||||
* filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see
|
||||
* _generateFilename()).
|
||||
* @param int $timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 =
|
||||
* 1 hour)
|
||||
*/
|
||||
public function useCached($format = "RSS0.91", $filename = "", $timeout = 3600)
|
||||
{
|
||||
$this->_setFormat($format);
|
||||
$this->_feed->useCached($filename, $timeout);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue