За последние 24 часа нас посетили 22911 программистов и 1260 роботов. Сейчас ищет 761 программист ...

Как исправить ошибку с RSS рассылкой в соц. сети?

Тема в разделе "PHP для новичков", создана пользователем DmitryRW, 17 авг 2017.

Метки:
  1. DmitryRW

    DmitryRW Новичок

    С нами с:
    17 авг 2017
    Сообщения:
    1
    Симпатии:
    0
    Неделю назад отвалилась rss лента,на протяжении 1,5 года все работало исправно,никаких изменений не вносилось.

    Текст с ошибкой:
    This page contains the following errors:

    error on line 2 at column 1: Extra content at the end of the document
    Below is a rendering of the page up to the first error.

    Код файла:
    PHP:
    1. <?php
    2. // spec https://partner.news.yandex.ru/tech.pdf
    3. $this->locator->onlyContent = true;
    4. $this->addHeader("Content-Type", 'text/xml; charset=' . PAGE_CHARSET);
    5. $content .= '<?xml version="1.0" encoding="'.PAGE_CHARSET.'"?>
    6. <rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0"><channel><title>'.$this->parcer->pageContent(array('sharetitle')).'</title>
    7. <link>'.$this->locator->host.'</link>
    8. <description>'.$this->parcer->pageContent(array('sharedescription')).'</description>
    9. <yandex:logo>'.$this->locator->host.'css/normal_logo.png</yandex:logo>
    10. <yandex:logo type="square">'.$this->locator->host.'css/square_logo180x180.png</yandex:logo>';
    11. $deep = (int)$this->tools->valREQUEST('deep');
    12. if($deep==0)$deep=9;
    13. // все ссылки на самостоятельные страницы
    14. /*
    15. /bz/4x4-club/
    16. /bz/spy/
    17. /bz/video/
    18. */
    19. if ($this->sql->exec("select *, datediff(now(),`ndate`) as 'datediff' from meta where (`link` like '/news/%' or `link` like '/bz/4x4-club/%' or `link` like '/bz/spy/%' or `link` like '/bz/video/%' or `link` like '/bz/handmade/%' or `link` like '/bz/retro/%' or `link` like '/news/pdd/%' or `link` like '/bz/camper/%') and datediff(now(),`ndate`) < $deep order by `ndate`")){
    20. if ($this->sql->row > 0){
    21. foreach($this->sql->aResult as $line){
    22.   $resMatch = array('href'=>array(),'src'=>array());
    23.   $descr = $this->parcer->run($line['content']);
    24.   $authorMail = ADMIN_MAIL;
    25.   preg_match_all("/<a[^>]*>.*?<\/a>/iD",$descr,$ancorMatch);
    26.   foreach($ancorMatch as $ancor){
    27.     preg_match_all('/[f|c]="([^"]+)"/iD',$ancor[0],$res);
    28.     $ancorName = strip_tags($ancor[0]);
    29.     foreach($res[0] as $i=>$v){
    30.       if(substr($v,0,1)=='f'){
    31.         if(strpos($v,$this->locator->host)===false){
    32.           if(!in_array($res[1][$i],$resMatch['href']))$resMatch['href'][] = array($res[1][$i],$ancorName);
    33.         }
    34.       }else{
    35.         if(!in_array($res[1][$i],$resMatch['src']))$resMatch['src'][] = $res[1][$i];
    36.       }
    37.     }
    38.   }
    39.   $descr = $this->tools->validXML(strip_tags($descr));
    40.   $link = $this->locator->host.substr($line['link'],1);
    41.   $nDate = new DateTime($line['ndate']);
    42.   $nDate = $nDate->format('r');
    43.   $strPic = ''; $strLink = '';
    44.   foreach($resMatch['src'] as $v){
    45.     $ext = pathinfo($v,PATHINFO_EXTENSION);
    46.     $path = str_replace($this->locator->host,ABSPATH,$v);
    47.     if(is_file($path)){
    48.       $imgInfo = stat($path);
    49.       $strPic .= '<enclosure url="'.$v.'" type="image/'.$ext.'" length="'.$imgInfo['size'].'"/>';
    50.     }
    51.   }
    52.   if(count($resMatch['href'])>0){
    53.     $strLink .= '<yandex:related>';
    54.     foreach($resMatch['href'] as $v){
    55.       $strLink .= '<link url="'.$v[0].'">'.($v[1]?$v[1]:$v[0]).'</link>';
    56.     }
    57.     $strLink .= '</yandex:related>';
    58.   }
    59. $content .= <<<TXT
    60. <item>
    61. <title>{$this->tools->validXML($line['title'])}</title>
    62. <link>$link</link>
    63. <guid>$link</guid>
    64. <description>{$this->tools->validXML($line['description'])}</description>
    65. <author>$authorMail</author>
    66. <category>Авто</category>
    67. <pubDate>$nDate</pubDate>
    68. <yandex:genre>article</yandex:genre>
    69. <yandex:full-text>$descr</yandex:full-text>
    70. <comments></comments>
    71. $strPic
    72. $strLink
    73. </item>
    74. TXT;
    75. }
    76. }
    77. }
    78. /*
    79. картинки
    80. <enclosure url="http://www.rossiyskie-novosti.ru/2003/03/25/yandex.jpg" type="image/jpeg"/>
    81. ссылки на сторонние ресурсы
    82. <yandex:related>
    83. <link url="http://www.kremlin.ru/">Президент России</link>
    84. </yandex:related>
    85. */
    86. $content .= '</channel></rss>';
    87. ?>