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


PHP feed::simplepie方法代码示例

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


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

示例1: index

 /**
  * parse feed and send feed items to database
  */
 public function index()
 {
     // Max number of feeds to keep
     $max_feeds = 100;
     // Today's Date
     $today = strtotime('now');
     // Get All Feeds From DB
     $feeds = ORM::factory('feed')->find_all();
     foreach ($feeds as $feed) {
         $last_update = $feed->feed_update;
         // Parse Feed URL using Feed Helper
         $feed_data = feed::simplepie($feed->feed_url);
         foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
             $title = $feed_data_item->get_title();
             $link = $feed_data_item->get_link();
             $description = $feed_data_item->get_description();
             $date = $feed_data_item->get_date();
             $latitude = $feed_data_item->get_latitude();
             $longitude = $feed_data_item->get_longitude();
             $categories = $feed_data_item->get_categories();
             // HT: new code
             $category_ids = new stdClass();
             // HT: new code
             // Make Sure Title is Set (Atleast)
             if (isset($title) && !empty($title)) {
                 // We need to check for duplicates!!!
                 // Maybe combination of Title + Date? (Kinda Heavy on the Server :-( )
                 $dupe_count = ORM::factory('feed_item')->where('item_title', $title)->where('item_date', date("Y-m-d H:i:s", strtotime($date)))->count_all();
                 if ($dupe_count == 0) {
                     // Does this feed have a location??
                     $location_id = 0;
                     // STEP 1: SAVE LOCATION
                     if ($latitude and $longitude) {
                         $location = new Location_Model();
                         $location->location_name = "Unknown";
                         $location->latitude = $latitude;
                         $location->longitude = $longitude;
                         $location->location_date = date("Y-m-d H:i:s", time());
                         $location->save();
                         $location_id = $location->id;
                     }
                     $newitem = new Feed_Item_Model();
                     $newitem->feed_id = $feed->id;
                     $newitem->location_id = $location_id;
                     $newitem->item_title = $title;
                     if (isset($description) and !empty($description)) {
                         $newitem->item_description = $description;
                     }
                     if (isset($link) and !empty($link)) {
                         $newitem->item_link = $link;
                     }
                     if (isset($date) and !empty($date)) {
                         $newitem->item_date = date("Y-m-d H:i:s", strtotime($date));
                     } else {
                         $newitem->item_date = date("Y-m-d H:i:s", time());
                     }
                     // HT: new code
                     if (!empty($categories)) {
                         foreach ($categories as $category) {
                             $categoryData = ORM::factory('category')->where('category_title', $category->term)->find();
                             if ($categoryData->loaded == TRUE) {
                                 $category_ids->feed_item_category[$categoryData->id] = $categoryData->id;
                             } elseif (Kohana::config('settings.allow_feed_category')) {
                                 $newcategory = new Category_Model();
                                 $newcategory->category_title = $category->term;
                                 $newcategory->parent_id = 0;
                                 $newcategory->category_description = $category->term;
                                 $newcategory->category_color = '000000';
                                 $newcategory->category_visible = 0;
                                 $newcategory->save();
                                 $category_ids->feed_item_category[$newcategory->id] = $newcategory->id;
                             }
                         }
                     }
                     // HT: End of new code
                     $newitem->save();
                     // HT: New code
                     if (!empty($category_ids->feed_item_category)) {
                         feed::save_category($category_ids, $newitem);
                     }
                     // HT: End of New code
                     // Action::feed_item_add - Feed Item Received!
                     Event::run('ushahidi_action.feed_item_add', $newitem);
                 }
             }
         }
         // Get Feed Item Count
         $feed_count = ORM::factory('feed_item')->where('feed_id', $feed->id)->count_all();
         if ($feed_count > $max_feeds) {
             // Excess Feeds
             $feed_excess = $feed_count - $max_feeds;
         }
         // Set feed update date
         $feed->feed_update = strtotime('now');
         $feed->save();
     }
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:100,代码来源:s_feeds.php

示例2: _parse_feed

 /**
  * parse feed and send feed items to database
  */
 private function _parse_feed()
 {
     // Max number of feeds to keep
     $max_feeds = 100;
     // Today's Date
     $today = strtotime('now');
     // Get All Feeds From DB
     $feeds = ORM::factory('feed')->find_all();
     foreach ($feeds as $feed) {
         $last_update = $feed->feed_update;
         // Has it been more than 24 hours since the last update?
         // Since its a manual refresh, we don't need to set a time
         if ((int) $today - (int) $last_update > 0) {
             // Parse Feed URL using Feed Helper
             $feed_data = feed::simplepie($feed->feed_url);
             foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
                 $title = $feed_data_item->get_title();
                 $link = $feed_data_item->get_link();
                 $description = $feed_data_item->get_description();
                 $date = $feed_data_item->get_date();
                 $latitude = $feed_data_item->get_latitude();
                 $longitude = $feed_data_item->get_longitude();
                 // Make Sure Title is Set (Atleast)
                 if (isset($title) && !empty($title)) {
                     // We need to check for duplicates!!!
                     // Maybe combination of Title + Date? (Kinda Heavy on the Server :-( )
                     $dupe_count = ORM::factory('feed_item')->where('item_title', $title)->where('item_date', date("Y-m-d H:i:s", strtotime($date)))->count_all();
                     if ($dupe_count == 0) {
                         // Does this feed have a location??
                         $location_id = 0;
                         // STEP 1: SAVE LOCATION
                         if ($latitude && $longitude) {
                             $location = new Location_Model();
                             $location->location_name = Kohana::lang('ui_admin.unknown');
                             $location->latitude = $latitude;
                             $location->longitude = $longitude;
                             $location->location_date = date("Y-m-d H:i:s", time());
                             $location->save();
                             $location_id = $location->id;
                         }
                         $newitem = new Feed_Item_Model();
                         $newitem->feed_id = $feed->id;
                         $newitem->location_id = $location_id;
                         $newitem->item_title = $title;
                         if (isset($description) && !empty($description)) {
                             $newitem->item_description = $description;
                         }
                         if (isset($link) && !empty($link)) {
                             $newitem->item_link = $link;
                         }
                         if (isset($date) && !empty($date)) {
                             $newitem->item_date = date("Y-m-d H:i:s", strtotime($date));
                         } else {
                             $newitem->item_date = date("Y-m-d H:i:s", time());
                         }
                         if (isset($feed_type) && !empty($feed_type)) {
                             $newitem->feed_type = $feed_type;
                         }
                         $newitem->save();
                     }
                 }
             }
             // Get Feed Item Count
             $feed_count = ORM::factory('feed_item')->where('feed_id', $feed->id)->count_all();
             if ($feed_count > $max_feeds) {
                 // Excess Feeds
                 $feed_excess = $feed_count - $max_feeds;
                 // Delete Excess Feeds
                 foreach (ORM::factory('feed_item')->where('feed_id', $feed->id)->orderby('id', 'ASC')->limit($feed_excess)->find_all() as $del_feed) {
                     $del_feed->delete($del_feed->id);
                 }
             }
             // Set feed update date
             $feed->feed_update = strtotime('now');
             $feed->save();
         }
     }
 }
开发者ID:kvin33,项目名称:Ushahidi_Web,代码行数:81,代码来源:manage.php

示例3: index

 /**
  * parse feed and send feed items to database
  */
 public function index()
 {
     // Max number of feeds to keep
     $max_feeds = 100;
     // Today's Date
     $today = strtotime('now');
     // Get All Feeds From DB
     $feeds = ORM::factory('feed')->find_all();
     foreach ($feeds as $feed) {
         $last_update = $feed->feed_update;
         // Parse Feed URL using Feed Helper
         $feed_data = feed::simplepie($feed->feed_url);
         foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
             $title = $feed_data_item->get_title();
             $link = $feed_data_item->get_link();
             $description = $feed_data_item->get_description();
             $date = $feed_data_item->get_date();
             $latitude = $feed_data_item->get_latitude();
             $longitude = $feed_data_item->get_longitude();
             // Make Sure Title is Set (Atleast)
             if (isset($title) && !empty($title)) {
                 // We need to check for duplicates!!!
                 // Maybe combination of Title + Date? (Kinda Heavy on the Server :-( )
                 $dupe_count = ORM::factory('feed_item')->where('item_title', $title)->where('item_date', date("Y-m-d H:i:s", strtotime($date)))->count_all();
                 if ($dupe_count == 0) {
                     // Does this feed have a location??
                     $location_id = 0;
                     // STEP 1: SAVE LOCATION
                     if ($latitude && $longitude) {
                         $location = new Location_Model();
                         $location->location_name = "Unknown";
                         $location->latitude = $latitude;
                         $location->longitude = $longitude;
                         $location->location_date = date("Y-m-d H:i:s", time());
                         $location->save();
                         $location_id = $location->id;
                     }
                     $newitem = new Feed_Item_Model();
                     $newitem->feed_id = $feed->id;
                     $newitem->location_id = $location_id;
                     $newitem->item_title = $title;
                     if (isset($description) && !empty($description)) {
                         $newitem->item_description = $description;
                     }
                     if (isset($link) && !empty($link)) {
                         $newitem->item_link = $link;
                     }
                     if (isset($date) && !empty($date)) {
                         $newitem->item_date = date("Y-m-d H:i:s", strtotime($date));
                     } else {
                         $newitem->item_date = date("Y-m-d H:i:s", time());
                     }
                     $newitem->save();
                 }
             }
         }
         // Get Feed Item Count
         $feed_count = ORM::factory('feed_item')->where('feed_id', $feed->id)->count_all();
         if ($feed_count > $max_feeds) {
             // Excess Feeds
             $feed_excess = $feed_count - $max_feeds;
             // Delete Excess Feeds
             /**** DISABLED FOR NOW ****/
             //				foreach (ORM::factory('feed_item')
             //					->where('feed_id', $feed->id)
             //					->orderby('id', 'ASC')
             //					->limit($feed_excess)
             //					->find_all() as $del_feed)
             //				{
             //					$del_feed->delete($del_feed->id);
             //				}
         }
         // Set feed update date
         $feed->feed_update = strtotime('now');
         $feed->save();
     }
 }
开发者ID:nebogeo,项目名称:borrowed-scenery,代码行数:80,代码来源:s_feeds.php


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