elitedivision/amos-rss
There is no license information available for the latest version (1.4.0) of this package.
Sistema AMOS per RSS
1.4.0
2021-09-17 08:18 UTC
Requires
- php:>=5.4.0
- elitedivision/amos-core:^1.9.35
- zendframework/zend-feed:~2.9
- zendframework/zend-servicemanager:~3.3
- zendframework/zend-http:~2.7
- kv4nt/yii2-owl-carousel2:*
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-test/1.4.1/1
- dev-test/2.0.0/1
- dev-gianluca/php_8-2
- dev-beta/1.4.0
- dev-test/1.4.0/1
- dev-test/1.3.0
- dev-test/1.2.0
- dev-fabiot_1.2.0
- dev-la_francesca/1.3.0
- dev-lisa_1.2.0
- dev-mattia/1.2.0
- dev-open20/1.1.2/1
- dev-scarface
- dev-test/1.1.1/1
- dev-e015
- dev-cruscotto_lavoro
- dev-riccardo/1.1.1/1
- dev-test/1.1.0/3
- dev-grafica
- dev-rete_comuni
- dev-test/1.1.0/2
- dev-nuova_dashboard
- dev-test/1.1.0/1
- dev-fabiot
- dev-riccardo/1.1.0/1
- dev-riccardo/1.0.3/1
- dev-lisa
- dev-test/1.0.3/1
- dev-DEPLOY_POI_20180921
README
Amos Framework extension to provide functionality for consuming RSS and Atom feeds using zend-feed library.
Installation
{
"require":
{
"elitedivision/amos-rss": "~1.0.0"
}
}
Configuration
In config file
backend/config/components-amos.php
Add feed component
'components' => array(
...
'rss' => array(
'class' => 'amos\rss\components\RssFeed',
),
)
Simple usage
Read Rss feed:
$feed=Yii::$app->feed->reader()->import('http://exapmple.com/feed.rss');
This will get RSS feed, parse it and return feed object. For more details you can read the official Zend-feed extention documentaion: http://framework.zend.com/manual/2.2/en/modules/zend.feed.reader.html
Create Rss feed:
Create action Rss in controller
public function actionRss(){
$feed=Yii::$app->feed->writer();
$feed->setTitle(Yii::$app->params['title']);
$feed->setLink('http://example.com');
$feed->setFeedLink('http://example.com/rss', 'rss');
$feed->setDescription(Yii::t('app','Recent headlines'));
$feed->setGenerator('http://example.com/rss');
$feed->setDateModified(time());
/**
* Add one or more entries. Note that entries must
* be manually added once created.
*/
$posts=Post::find()->orderBy('id DESC')->limit(20)->all();
foreach($posts as $post){
$entry = $feed->createEntry();
$entry->setTitle($post->title);
$entry->setLink(Yii::$app->urlManager->createAbsoluteUrl('/post/view',['id'=>$post->id]));
$entry->setDateModified(intval($post->created));
$entry->setDateCreated(intval($post->created));
$entry->setContent(
$post->content
);
$entry->setEnclosure(
[
'uri'=>$post->image,
'type'=>'image/jpeg',
'length'=>filesize(Yii::getAlias('@webroot').$post->image)
]
);
$feed->addEntry($entry);
}
/**
* Render the resulting feed to Atom 1.0 and assign to $out.
* You can substitute "atom" with "rss" to generate an RSS 2.0 feed.
*/
$out = $feed->export('rss');
header('Content-type: text/xml');
echo $out;
die();
}
add rss migrations to console modules (console/config/migrations-amos.php):
'@vendor/elitedivision/amos-rss/src/migrations'
add rss module to backend modules (backend/config/modules-amos.php):
'rss' => [
'class' => 'amos\rss\Module',
'modelsEnabled' => [
'elitedivision\amos\news\models\News',
],
'federationUrls' => [
'http://domain.from.readrss.com'
]
],