duanjipiao7076 2012-07-31 13:22
浏览 38
已采纳

使用simplepie和codeigniter列出特定Feed类型旁边的设置图标

I have a small issue which I'm hoping someone can help me resolve.

Copied below is a piece of code which goes away to my database model and returns an array with a URL and a feed type. The user enters whether they have used a twitter name, blogger site etc.

However, to parse this data with simplepie I need to pass an array of URL's... and I lose my "type" option. Is there anyway I could add this back to the simplepie item so that I can display a specific icon if the user has selected a specific type of feed.

$feed = $this->profile_model->get_module_feed();

    $feedarr = array();
    foreach($feed['data'] as $feeds) {
        if ($feeds['type'] == 1 ) {
            $i = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=" . $feeds['rss'];
        }
        if ($feeds['type'] == 2 ) {
            $i = "http://search.twitter.com/search.atom?q=" . $feeds['rss'];
        }
        if ($feeds['type'] >= 3 ) {
            $i = $feeds['rss'];
        }

        $d = $feeds['type'];

        //else $i = $feeds['rss'];

        echo $i . " " . $d . "<br />";

        array_push($feedarr, $i);
    }

    $this->simplepie->set_feed_url($feedarr);
    $this->simplepie->enable_cache(false);
    $this->simplepie->init();
    $this->simplepie->handle_content_type();


    $data = $this->simplepie;

    foreach($data->get_items() as $item) { ?>
        <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
        <p><?php echo $item->get_description(); ?></p>
        <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
    <?php


    }


    }
}


?>

Eg, if the $feed['type'] is 1 I would like to display the image associated with 1

hoping someone can help as I'm a wee bit stumped!

  • 写回答

1条回答 默认 最新

  • dongliang1865 2012-08-01 20:05
    关注

    You can use the individual feed item's feed property to get it's subscribe url and try to match it with the feed urls you used for the fetching. Here's a simplified example:

    // array with unique feed url => feed type (icon)
    $feed_types = array(
        'http://feed.one.com/' => 'type1',
        'http://feed.two.com/' => 'type2',
    );
    
    $pie = new SimplePie;
    $pie->set_feed_url(array_keys($feed_types));
    $pie->enable_cache(false);
    $pie->init();
    $pie->handle_content_type();
    
    foreach ($pie->get_items() as $item) {
        $feed_url = $item->feed->subscribe_url();
        $type = isset($feed_types[$feed_url]) ? $feed_types[$feed_url] : 'unknown type';
        print $type;
    }
    

    As long as you use the same url's for fetching that embedded into the feed results the subscribe_ul() method's result should align up with the urls used in set_feed_url().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算