ria.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. use yii\helpers\Html;
  3. Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
  4. header('Content-Type: application/rss+xml; charset=utf-8');
  5. ?>
  6. <?php echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
  7. <rss version="2.0"
  8. xmlns:yandex="http://news.yandex.ru"
  9. xmlns:media="http://search.yahoo.com/mrss/"
  10. >
  11. <channel>
  12. <?php if (isset($channel['title'])) : ?>
  13. <title><?= $channel['title']; ?></title>
  14. <?php endif; ?>
  15. <?php if (isset($channel['link'])) : ?>
  16. <link><?= Html::encode($channel['link']); ?></link>
  17. <?php endif; ?>
  18. <description>Новости amic.ru для rnews</description>
  19. <?php if (isset($channel['language'])) : ?>
  20. <language><?= $channel['language']; ?></language>
  21. <?php endif; ?>
  22. <generator>CMS amic.ru</generator>
  23. <?php foreach ($items as $item): ?>
  24. <?php
  25. if ( $item['export_rss'] & 1 ) continue;
  26. //1 - неотдавать в новости
  27. //2- неотдавать в канал
  28. ?>
  29. <?php if (isset($item['url']) ) : ?>
  30. <item>
  31. <link><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></link>
  32. <?php if (isset($item['title']) ) : ?>
  33. <title><![CDATA[<?= trim( $item['title'] ); ?>]]></title>
  34. <?php endif; ?>
  35. <?php if (isset($item['description']) ) : ?>
  36. <description><![CDATA[<?= trim($item['description']); ?>]]></description>
  37. <?php endif; ?>
  38. <pubDate><?= date( "r", strtotime( $item['updated_at'] ) ); ?></pubDate>
  39. <?php if (isset($item['newscontent']) ) : ?>
  40. <yandex:full-text>
  41. <![CDATA[
  42. <?/*<h1><?= ($item['title']) ? $item['title'] : ''; ?></h1>*/?>
  43. <p><?= ($item['description']) ? $item['description'] : ''; ?></p>
  44. <?= $item['newscontent']; ?>
  45. ]]>
  46. </yandex:full-text>
  47. <?php endif; ?>
  48. <?php if (isset($item['image'])) :?>
  49. <?
  50. $r = explode(".", $item['image']);
  51. if( is_array($r) ){
  52. if( array_pop($r) == 'webp' ){
  53. $mtype = "image/webp";
  54. }else{
  55. $mtype = "image/jpeg";
  56. }
  57. }
  58. ?>
  59. <enclosure url="<?=$item['image']?>" type="<?=$mtype?>" />
  60. <?php endif; ?>
  61. <?
  62. preg_match_all('/src="([^"]+\.(jpg|png)).*"/i', $item['content'], $ax );
  63. foreach ( $ax[1] as $aa ){
  64. if( !preg_match( "/(\/manager\/|small)/", $aa) ){
  65. $r = explode(".", $aa);
  66. if( is_array($r) ){
  67. if( array_pop($r) == 'png' ){
  68. $mtype = "image/png";
  69. }else{
  70. $mtype = "image/jpeg";
  71. }
  72. }
  73. ?>
  74. <enclosure url="<?=$aa?>" type="<?=$mtype?>" />
  75. <?
  76. }
  77. }
  78. if( count( $item['topics'] ) > 0 ){
  79. ?>
  80. <metrics>
  81. <yandex schema_identifier="<?=$item['uid']?>">
  82. <breadcrumblist>
  83. <?
  84. foreach ( $item['topics'] as $topics ){
  85. ?>
  86. <breadcrumb url="<?=$topics['url']?>" text='<?=str_replace("'",'`',$topics['title'])?>'/>
  87. <?
  88. }
  89. ?>
  90. </breadcrumblist>
  91. </yandex>
  92. </metrics>
  93. <?
  94. }
  95. switch( $item['type'] ){
  96. case 2:
  97. case 6:
  98. // статья
  99. $ganre = "article";
  100. case 7:
  101. case 5:
  102. // статья
  103. $ganre = "article";
  104. default:
  105. $ganre = "message";
  106. break;
  107. }
  108. ?>
  109. <yandex:genre><?=$ganre?></yandex:genre>
  110. <?php if (isset($item['story'])) : ?>
  111. <yandex:theme_tags><?=$item['story'];?></yandex:theme_tags>
  112. <?php endif; ?>
  113. <?php if (isset($item['category'])) : ?>
  114. <category><?=$item['category'];?></category>
  115. <?php endif; ?>
  116. <?php if (isset($item['riatop']) && $item['riatop']) : ?>
  117. <category>main_article</category>
  118. <?php endif; ?>
  119. <author><?=$item['author'];?></author>
  120. </item>
  121. <?php endif; ?><?php endforeach; ?>
  122. </channel>
  123. </rss>