dzen.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
  10. header('Content-Type: application/rss+xml; charset=utf-8');
  11. ?>
  12. <?php echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
  13. <rss version="2.0"
  14. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  15. xmlns:dc="http://purl.org/dc/elements/1.1/"
  16. xmlns:media="http://search.yahoo.com/mrss/"
  17. xmlns:atom="http://www.w3.org/2005/Atom"
  18. xmlns:georss="http://www.georss.org/georss">
  19. <channel>
  20. <?php if (isset($channel['title'])) : ?>
  21. <title><?= $channel['title']; ?></title>
  22. <?php endif; ?>
  23. <?php if (isset($channel['link'])) : ?>
  24. <link><?= Html::encode($channel['link']); ?></link>
  25. <?php endif; ?>
  26. <description>Новости Алтайского края и Барнаула</description>
  27. <?php if (isset($channel['language'])) : ?>
  28. <language><?= $channel['language']; ?></language>
  29. <?php endif; ?>
  30. <image>
  31. <url>https://www.amic.ru/img/amic-logo.svg</url>
  32. <link><?= Html::encode($channel['link']); ?></link>
  33. <title><?= $channel['title']; ?></title>
  34. </image>
  35. <?php foreach ($items as $item): ?>
  36. <?php if ($item['stopnews']) continue; ?>
  37. <?php if (isset($item['url']) ) : ?>
  38. <item>
  39. <link><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></link>
  40. <guid><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></guid>
  41. <?php if (isset($item['title']) ) : ?>
  42. <title><![CDATA[<?= $item['title']; ?>]]></title>
  43. <?php endif; ?>
  44. <?php if (isset($item['description']) ) : ?>
  45. <description>
  46. <![CDATA[
  47. <?= $item['description']; ?>
  48. ]]>
  49. </description>
  50. <?php endif; ?>
  51. <pubDate><?= date( "r", strtotime( $item['updated_at'] ) ); ?></pubDate>
  52. <?php if (isset($item['stext']) ) : ?>
  53. <content:encoded>
  54. <![CDATA[
  55. <? if( strlen(strip_tags($item['stext'])) < 800 ){ ?>
  56. <h1><?= ($item['title']) ? $item['title'] : ''; ?></h1>
  57. <?}?>
  58. <p><?= ($item['description']) ? $item['description'] : ''; ?></p>
  59. <img src="<?=$item['image']?>">
  60. <?= $item['stext']; ?><br>
  61. Больше материалов на <a href="https://www.amic.ru">amic.ru</a>.
  62. ]]>
  63. </content:encoded>
  64. <?php endif; ?>
  65. <?php if (isset($item['image'])) :?>
  66. <?
  67. $r = explode(".", $item['image']);
  68. if( is_array($r) ){
  69. if( array_pop($r) == 'webp' ){
  70. $mtype = "image/webp";
  71. }else{
  72. $mtype = "image/jpeg";
  73. }
  74. }
  75. ?>
  76. <enclosure url="<?=$item['image']?>" type="<?=$mtype?>" />
  77. <?php endif; ?>
  78. <?
  79. preg_match_all('/src="([^"]+\.(jpg|png)).*"/i', $item['content'], $ax );
  80. foreach ( $ax[1] as $aa ){
  81. if( !preg_match( "/(\/manager\/|small)/", $aa) ){
  82. $r = explode(".", $aa);
  83. if( is_array($r) ){
  84. if( array_pop($r) == 'png' ){
  85. $mtype = "image/png";
  86. }else{
  87. $mtype = "image/jpeg";
  88. }
  89. }
  90. ?>
  91. <enclosure url="<?=$aa?>" type="<?=$mtype?>" />
  92. <?
  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. <?php endif; ?>
  110. <?php if (isset($item['category'])) : ?>
  111. <category><?=$item['category'];?></category>
  112. <?php endif; ?>
  113. <?php if ( $item['export_rss'] & 2 ) : ?>
  114. <category>native-draft</category>
  115. <?php else: ?>
  116. <category>native-yes</category>
  117. <?php endif; ?>
  118. </item>
  119. <?php endforeach; ?>
  120. <category>format-article</category>
  121. </channel>
  122. </rss>