rss.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. * to do
  4. * https://dzen.ru/help/news/export-content/export.html
  5. * https://yandex.ru/dev/turbo/doc/rss/simple-rss.html
  6. *
  7. */
  8. use yii\helpers\Html;
  9. header('Content-Type: application/rss+xml; charset=utf-8');
  10. Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
  11. ?>
  12. <?php echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
  13. <rss version="2.0"
  14. xml:base="https://www.amic.ru/"
  15. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  16. xmlns:dc="http://purl.org/dc/elements/1.1/"
  17. >
  18. <channel>
  19. <?php if (isset($channel['title'])) : ?>
  20. <title><![CDATA[<?= $channel['title']; ?>]]></title>
  21. <?php endif; ?>
  22. <?php if (isset($channel['link'])) : ?>
  23. <link><?= Html::encode($channel['link']); ?></link>
  24. <?php endif; ?>
  25. <?php if (isset($channel['description'])) : ?>
  26. <description><![CDATA[<?= $channel['description']; ?>]]></description>
  27. <?php endif; ?>
  28. <?php if (isset($channel['language'])) : ?>
  29. <language><?= $channel['language']; ?></language>
  30. <?php endif; ?>
  31. <image>
  32. <url>https://www.amic.ru/img/amic-logo.svg</url>
  33. <link>https://www.amic.ru</link>
  34. <title>Новости Алтайского края</title>
  35. </image>
  36. <?php foreach ($items as $item): ?>
  37. <?php if (isset($item['url']) ) : ?>
  38. <item>
  39. <guid><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></guid>
  40. <link><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></link>
  41. <pubDate><?= date( "r", strtotime( $item['updated_at'] ) ); ?></pubDate>
  42. <?php if (isset($item['title']) ) : ?>
  43. <title><![CDATA[<?= $item['title']; ?>]]></title>
  44. <?php endif; ?>
  45. <?php if (isset($item['description']) ) : ?>
  46. <description>
  47. <![CDATA[<?= $item['description']; ?>]]>
  48. </description>
  49. <?php endif; ?>
  50. <?php if (isset($item['newscontent']) ) : ?>
  51. <content:encoded>
  52. <![CDATA[
  53. <p><?= ($item['description']) ? $item['description'] : ''; ?></p>
  54. <?= $item['newscontent']; ?>
  55. ]]>
  56. </content:encoded>
  57. <?php endif; ?>
  58. <?php if (isset($item['image'])) :?>
  59. <?
  60. $r = explode(".", $item['image']);
  61. if( is_array($r) ){
  62. if( array_pop($r) == 'webp' ){
  63. $mtype = "image/webp";
  64. }else{
  65. $mtype = "image/jpeg";
  66. }
  67. }
  68. ?>
  69. <enclosure url="<?=$item['image']?>" type="<?=$mtype?>" />
  70. <?php endif; ?>
  71. <?
  72. preg_match_all('/src="([^"]+\.(jpg|png)).*"/i', $item['content'], $ax );
  73. foreach ( $ax[1] as $aa ){
  74. if( !preg_match( "/(\/manager\/|small)/", $aa) ){
  75. $r = explode(".", $aa);
  76. if( is_array($r) ){
  77. if( array_pop($r) == 'png' ){
  78. $mtype = "image/png";
  79. }else{
  80. $mtype = "image/jpeg";
  81. }
  82. }
  83. ?>
  84. <enclosure url="<?=$aa?>" type="<?=$mtype?>" />
  85. <?
  86. }
  87. }
  88. ?>
  89. <dc:creator>ИА Амител</dc:creator>
  90. </item>
  91. <?php endif; ?><?php endforeach; ?>
  92. </channel>
  93. </rss>