123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- /*
- * to do
- * https://dzen.ru/help/news/export-content/export.html
- * https://yandex.ru/dev/turbo/doc/rss/simple-rss.html
- *
- */
- use yii\helpers\Html;
- Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
- header('Content-Type: application/rss+xml; charset=utf-8');
- ?>
- <?php echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
- <rss version="2.0"
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:media="http://search.yahoo.com/mrss/"
- xmlns:atom="http://www.w3.org/2005/Atom"
- xmlns:georss="http://www.georss.org/georss">
- <channel>
- <?php if (isset($channel['title'])) : ?>
- <title><?= $channel['title']; ?></title>
- <?php endif; ?>
- <?php if (isset($channel['link'])) : ?>
- <link><?= Html::encode($channel['link']); ?></link>
- <?php endif; ?>
- <description>Новости Алтайского края и Барнаула</description>
- <?php if (isset($channel['language'])) : ?>
- <language><?= $channel['language']; ?></language>
- <?php endif; ?>
- <image>
- <url>https://www.amic.ru/img/amic-logo.svg</url>
- <link><?= Html::encode($channel['link']); ?></link>
- <title><?= $channel['title']; ?></title>
- </image>
- <?php foreach ($items as $item): ?>
- <?php if ($item['stopnews']) continue; ?>
- <?php if (isset($item['url']) ) : ?>
- <item>
- <link><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></link>
- <guid><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></guid>
- <?php if (isset($item['title']) ) : ?>
- <title><![CDATA[<?= $item['title']; ?>]]></title>
- <?php endif; ?>
- <?php if (isset($item['description']) ) : ?>
- <description>
- <![CDATA[
- <?= $item['description']; ?>
- ]]>
- </description>
- <?php endif; ?>
- <pubDate><?= date( "r", strtotime( $item['updated_at'] ) ); ?></pubDate>
- <?php if (isset($item['stext']) ) : ?>
- <content:encoded>
- <![CDATA[
- <? if( strlen(strip_tags($item['stext'])) < 800 ){ ?>
- <h1><?= ($item['title']) ? $item['title'] : ''; ?></h1>
- <?}?>
- <p><?= ($item['description']) ? $item['description'] : ''; ?></p>
- <img src="<?=$item['image']?>">
- <?= $item['stext']; ?><br>
- Больше материалов на <a href="https://www.amic.ru">amic.ru</a>.
- ]]>
- </content:encoded>
- <?php endif; ?>
- <?php if (isset($item['image'])) :?>
- <?
- $r = explode(".", $item['image']);
- if( is_array($r) ){
- if( array_pop($r) == 'webp' ){
- $mtype = "image/webp";
- }else{
- $mtype = "image/jpeg";
- }
- }
- ?>
- <enclosure url="<?=$item['image']?>" type="<?=$mtype?>" />
- <?php endif; ?>
- <?
- preg_match_all('/src="([^"]+\.(jpg|png)).*"/i', $item['content'], $ax );
- foreach ( $ax[1] as $aa ){
- if( !preg_match( "/(\/manager\/|small)/", $aa) ){
- $r = explode(".", $aa);
- if( is_array($r) ){
- if( array_pop($r) == 'png' ){
- $mtype = "image/png";
- }else{
- $mtype = "image/jpeg";
- }
- }
- ?>
- <enclosure url="<?=$aa?>" type="<?=$mtype?>" />
- <?
- }
- }
- switch( $item['type'] ){
- case 2:
- case 6:
- // статья
- $ganre = "article";
- case 7:
- case 5:
- // статья
- $ganre = "article";
- default:
- $ganre = "message";
- break;
- }
- ?>
- <?php endif; ?>
- <?php if (isset($item['category'])) : ?>
- <category><?=$item['category'];?></category>
- <?php endif; ?>
- <?php if ( $item['export_rss'] & 2 ) : ?>
- <category>native-draft</category>
- <?php else: ?>
- <category>native-yes</category>
- <?php endif; ?>
- </item>
- <?php endforeach; ?>
- <category>format-article</category>
- </channel>
- </rss>
|