dzentopic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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['clink'])) : ?>
  24. <link><?= Html::encode($channel['clink']); ?></link>
  25. <?php endif; ?>
  26. <description>Вопросы ответы amic.ru</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 (isset($item['url']) ) : ?>
  37. <item>
  38. <link><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></link>
  39. <guid><?= rtrim(Html::encode($channel['link']),'/'); ?><?= Html::encode($item['url']); ?></guid>
  40. <?php if (isset($item['title']) ) : ?>
  41. <title><![CDATA[<?= $item['title']; ?>]]></title>
  42. <?php endif; ?>
  43. <?php if (isset($item['description']) ) : ?>
  44. <description>
  45. <![CDATA[
  46. <?= $item['description']; ?>
  47. ]]>
  48. </description>
  49. <?php endif; ?>
  50. <pubDate><?= date( "r", strtotime( $item['updated_at'] ) ); ?></pubDate>
  51. <?php if (isset($item['stext']) ) : ?>
  52. <content:encoded>
  53. <![CDATA[
  54. <?/*<h1><?= ($item['title']) ? $item['title'] : ''; ?></h1>*/?>
  55. <p><?= ($item['description']) ? $item['description'] : ''; ?></p>
  56. <?= $item['stext']; ?>
  57. ]]>
  58. </content:encoded>
  59. <?php endif; ?>
  60. <?php if (isset($item['image'])) :?>
  61. <?
  62. $r = explode(".", $item['image']);
  63. if( is_array($r) ){
  64. if( array_pop($r) == 'webp' ){
  65. $mtype = "image/webp";
  66. }else{
  67. $mtype = "image/jpeg";
  68. }
  69. }
  70. ?>
  71. <enclosure url="<?=$item['image']?>" type="<?=$mtype?>" />
  72. <?php endif; ?>
  73. <?
  74. preg_match_all('/src="([^"]+\.(jpg|png)).*"/i', $item['content'], $ax );
  75. foreach ( $ax[1] as $aa ){
  76. if( !preg_match( "/(\/manager\/|small)/", $aa) ){
  77. $r = explode(".", $aa);
  78. if( is_array($r) ){
  79. if( array_pop($r) == 'png' ){
  80. $mtype = "image/png";
  81. }else{
  82. $mtype = "image/jpeg";
  83. }
  84. }
  85. ?>
  86. <enclosure url="<?=$aa?>" type="<?=$mtype?>" />
  87. <?
  88. }
  89. }
  90. switch( $item['type'] ){
  91. case 2:
  92. case 6:
  93. // статья
  94. $ganre = "article";
  95. case 7:
  96. case 5:
  97. // статья
  98. $ganre = "article";
  99. default:
  100. $ganre = "message";
  101. break;
  102. }
  103. ?>
  104. <?php endif; ?>
  105. <?php if (isset($item['category'])) : ?>
  106. <category><?=$item['category'];?></category>
  107. <?php endif; ?>
  108. <?php if ( $item['export_rss'] & 2 ) : ?>
  109. <category>native-draft</category>
  110. <?php else: ?>
  111. <category>native-yes</category>
  112. <?php endif; ?>
  113. </item>
  114. <?php endforeach; ?>
  115. </channel>
  116. </rss>