当前位置: 首页>>代码示例>>PHP>>正文


PHP RSSFeed::addRSSItem方法代码示例

本文整理汇总了PHP中RSSFeed::addRSSItem方法的典型用法代码示例。如果您正苦于以下问题:PHP RSSFeed::addRSSItem方法的具体用法?PHP RSSFeed::addRSSItem怎么用?PHP RSSFeed::addRSSItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RSSFeed的用法示例。


在下文中一共展示了RSSFeed::addRSSItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addPageToRSSFeed

function addPageToRSSFeed($html, RSSFeed $rssFeed)
{
    $html = preg_replace("#<script.*?</script>#is", "", $html);
    # Strip out <script> tags so loadHTML() parses the page correctly for $xpath->query()
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath = new DOMXPath($dom);
    # Get the post wrapper divs
    $postDivs = $xpath->query('/descendant::div[@id="posts"]/div[starts-with(@id,"edit") and @class="postbit-wrapper "]');
    # Thread URL
    $pageURL = current(iterator_to_array($xpath->query('/html/head/link[@rel="canonical"]/@href')))->nodeValue;
    # Title
    $title = current(iterator_to_array($xpath->query('//div[@id = "thread-header-bloglike"]//h1')))->nodeValue;
    $rssFeed->title = $title;
    # Get the post element divs
    foreach ($postDivs as $postDiv) {
        $rssItem = new RSSItem();
        # Title (author)
        $rssItem->title = '[Post]';
        // Default to "[Post]" on first post
        foreach ($xpath->query('.//a[starts-with(@class, "bigfusername")]', $postDiv) as $postAuthor) {
            $rssItem->title = trim($postAuthor->nodeValue);
            $rssItem->author = trim($postAuthor->nodeValue);
            break;
        }
        # Link, GUID
        $rssItem->link = $pageURL;
        // Default to page URL on first post
        $rssItem->guid = $rssItem->link;
        foreach ($xpath->query('.//a[@class="postCount"]/@href', $postDiv) as $postLink) {
            # Strip the 's' parameter out since it changes every so often....
            $parsedURL = parse_url($postLink->nodeValue);
            $queryStr = $parsedURL['query'];
            parse_str($queryStr, $queryParams);
            unset($queryParams['s']);
            $rssItem->link = 'http://forum.xda-developers.com/' . $parsedURL['path'] . '?' . http_build_query($queryParams);
            $rssItem->guid = $rssItem->link;
            break;
        }
        # Description
        foreach ($xpath->query('.//div[starts-with(@id, "post_message") and starts-with(@class, "post-text")]', $postDiv) as $postMsgDiv) {
            # Strip ad
            foreach ($xpath->query('.//div[@class="purchad"]', $postDiv) as $postAd) {
                $postAd->parentNode->removeChild($postAd);
            }
            $rssItem->description = cleanPostMessageHTML($dom->saveXML($postMsgDiv));
            break;
        }
        # Publication Date
        $rssItem->setPubDate(new DateTime('1900-01-01'));
        // Default to 1st JAN 1900 on first post... oh well...
        $rssFeed->setLastBuildDate($rssItem->getPubDate());
        foreach ($xpath->query('.//span[@class="time"]', $postDiv) as $postDateSpan) {
            $rssItem->setPubDate(getXDADate(trim($postDateSpan->nodeValue)));
            $rssFeed->setLastBuildDate($rssItem->getPubDate());
            # Set the feed's lastBuildDate to the last post's date
            break;
        }
        $rssFeed->addRSSItem($rssItem);
    }
}
开发者ID:klo2k,项目名称:php-rss,代码行数:61,代码来源:xda.php


注:本文中的RSSFeed::addRSSItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。