Remove items that link back to this before destroying this object
public __destruct ( ) |
/** * Initialize our class and load the items in * * {@internal Long Description Missing}} */ public function init() { if (is_null($this->simplepie)) { $this->load(); } $this->simplepie_items =& $this->simplepie->get_items(); /** Run through each item at least once */ foreach ($this->simplepie_items as $item) { $new_item = $this->normalise($item); $this->items[$new_item->hash] = $new_item; } uasort($this->items, array($this, 'sort_items')); $this->simplepie->__destruct(); unset($this->simplepie); unset($this->simplepie_items); return $this->items; }
function powerpress_get_news($feed_url, $limit = 10) { include_once ABSPATH . WPINC . '/feed.php'; $rss = fetch_feed($feed_url); // If feed doesn't work... if (is_wp_error($rss)) { require_once ABSPATH . WPINC . '/class-feed.php'; // Try fetching the feed using CURL directly... $content = powerpress_remote_fopen($feed_url, false, array(), 3, false, true); if (!$content) { return false; } // Load the content in a fetch_feed object... $rss = new SimplePie(); $rss->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); // We must manually overwrite $feed->sanitize because SimplePie's // constructor sets it before we have a chance to set the sanitization class $rss->sanitize = new WP_SimplePie_Sanitize_KSES(); $rss->set_cache_class('WP_Feed_Cache'); $rss->set_file_class('WP_SimplePie_File'); $rss->set_raw_data($content); $rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $feed_url)); do_action_ref_array('wp_feed_options', array(&$rss, $feed_url)); $rss->init(); $rss->set_output_encoding(get_option('blog_charset')); $rss->handle_content_type(); if ($rss->error()) { return false; } } $rss_items = $rss->get_items(0, $rss->get_item_quantity($limit)); // If the feed was erroneously if (!$rss_items) { $md5 = md5($this->feed); delete_transient('feed_' . $md5); delete_transient('feed_mod_' . $md5); $rss->__destruct(); unset($rss); $rss = fetch_feed($this->feed); $rss_items = $rss->get_items(0, $rss->get_item_quantity($num)); $rss->__destruct(); unset($rss); } return $rss_items; }
/** * Update the feeds * */ function UpdateFeeds() { if (!is_dir('./tmp')) { mkdir('./tmp', 0777); } $feedData = array(); $lock = Lock("Update Feeds", false); if (isset($lock)) { // load the list of feeds require_once './settings/feeds.inc'; require_once './lib/simplepie.inc'; // loop through and update each one foreach ($feeds as $category => &$feedList) { $feedData[$category] = array(); foreach ($feedList as $feedSource => $feedUrl) { $feedUrl = trim($feedUrl); if (strlen($feedUrl)) { $feed = new SimplePie(); if ($feed) { $rawFeed = trim(http_fetch($feedUrl)); $feed->set_raw_data($rawFeed); $feed->enable_cache(false); $feed->init(); // try sanitizing the data if we have a problem parsing the feed if (strlen($feed->error())) { FixFeed($rawFeed); $feed->set_raw_data($rawFeed); $feed->enable_cache(false); $feed->init(); } foreach ($feed->get_items() as $item) { $dateStr = $item->get_date(DATE_RSS); if ($dateStr && strlen($dateStr)) { $date = strtotime($dateStr); if ($date) { // only include articles from the last 30 days $now = time(); $elapsed = 0; if ($now > $date) { $elapsed = $now - $date; } $days = (int) ($elapsed / 86400); if ($days <= 30) { // make sure we don't have another article from the exact same time while (isset($feedData[$category][$date])) { $date++; } $feedData[$category][$date] = array('source' => $feedSource, 'title' => $item->get_title(), 'link' => urldecode($item->get_permalink()), 'date' => $dateStr); } } } $item->__destruct(); } $feed->__destruct(); unset($feed); } } } if (count($feedData[$category])) { krsort($feedData[$category]); } } // save out the feed data file_put_contents('./tmp/feeds.dat', json_encode($feedData)); Unlock($lock); } }
public function addAllGroupFeed() { if (OW::getConfig()->getValue('grouprss', 'disablePosting') == '1') { return; } $commentService = BOL_CommentService::getInstance(); $newsfeedService = NEWSFEED_BOL_Service::getInstance(); $router = OW::getRouter(); $displayText = OW::getLanguage()->text('grouprss', 'feed_display_text'); $location = OW::getConfig()->getValue('grouprss', 'postLocation'); include_once 'autoloader.php'; $allFeeds = $this->feeddao->findAll(); foreach ($allFeeds as $feed) { $simplefeed = new SimplePie(); $simplefeed->set_feed_url($feed->feedUrl); $simplefeed->set_stupidly_fast(true); $simplefeed->enable_cache(false); $simplefeed->init(); $simplefeed->handle_content_type(); $items = $simplefeed->get_items(0, $feed->feedCount); foreach ($items as $item) { $content = UTIL_HtmlTag::autoLink($item->get_content()); if ($location == 'wall' && !$this->isDuplicateComment($feed->groupId, $content)) { $commentService->addComment('groups_wal', $feed->groupId, 'groups', $feed->userId, $content); } if (trim($location) == 'newsfeed' && !$this->isDuplicateFeed($feed->groupId, $content)) { $statusObject = $newsfeedService->saveStatus('groups', (int) $feed->groupId, $content); $content = UTIL_HtmlTag::autoLink($content); $action = new NEWSFEED_BOL_Action(); $action->entityId = $statusObject->id; $action->entityType = "groups-status"; $action->pluginKey = "newsfeed"; $data = array("string" => $content, "content" => "[ph:attachment]", "view" => array("iconClass" => "ow_ic_comment"), "attachment" => array("oembed" => null, "url" => null, "attachId" => null), "data" => array("userId" => $feed->userId), "actionDto" => null, "context" => array("label" => $displayText, "url" => $router->urlForRoute('groups-view', array('groupId' => $feed->groupId)))); $action->data = json_encode($data); $actionObject = $newsfeedService->saveAction($action); $activity = new NEWSFEED_BOL_Activity(); $activity->activityType = NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_CREATE; $activity->activityId = $feed->userId; $activity->actionId = $actionObject->id; $activity->privacy = NEWSFEED_BOL_Service::PRIVACY_EVERYBODY; $activity->userId = $feed->userId; $activity->visibility = NEWSFEED_BOL_Service::VISIBILITY_FULL; $activity->timeStamp = time(); $activity->data = json_encode(array()); $activityObject = $newsfeedService->saveActivity($activity); $newsfeedService->addActivityToFeed($activity, 'groups', $feed->groupId); } } $simplefeed->__destruct(); unset($feed); } }
public function items() { if ($this->input->is_ajax_request()) { $this->readerself_library->set_template('_json'); $this->readerself_library->set_content_type('application/json'); $content = array(); } else { $this->readerself_library->set_template('_plain'); $this->readerself_library->set_content_type('text/plain'); $content = ''; } if ($this->input->is_cli_request() && !$this->config->item('refresh_by_cron')) { $content .= 'Refresh by cron disabled' . "\n"; } else { include_once 'thirdparty/simplepie/autoloader.php'; include_once 'thirdparty/simplepie/idn/idna_convert.class.php'; if ($this->config->item('facebook/enabled')) { include_once 'thirdparty/facebook/autoload.php'; $fb = new Facebook\Facebook(array('app_id' => $this->config->item('facebook/id'), 'app_secret' => $this->config->item('facebook/secret'))); $fbApp = $fb->getApp(); $accessToken = $fbApp->getAccessToken(); } $query = $this->db->query('SELECT fed.* FROM ' . $this->db->dbprefix('feeds') . ' AS fed WHERE fed.fed_nextcrawl IS NULL OR fed.fed_nextcrawl <= ? GROUP BY fed.fed_id HAVING (SELECT COUNT(DISTINCT(sub.mbr_id)) FROM ' . $this->db->dbprefix('subscriptions') . ' AS sub WHERE sub.fed_id = fed.fed_id) > 0', array(date('Y-m-d H:i:s'))); if ($query->num_rows() > 0) { $microtime_start = microtime(1); $errors = 0; foreach ($query->result() as $fed) { $parse_url = parse_url($fed->fed_link); if (isset($parse_url['host']) == 1 && $parse_url['host'] == 'www.facebook.com' && $this->config->item('facebook/enabled')) { try { $parts = explode('/', $parse_url['path']); $total_parts = count($parts); $last_part = $parts[$total_parts - 1]; $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=link,name,about'); $response = $fb->getClient()->sendRequest($request); $result = $response->getDecodedBody(); $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=feed{created_time,id,message,story,full_picture,place,type,status_type,link}'); $response = $fb->getClient()->sendRequest($request); $posts = $response->getDecodedBody(); $this->readerself_library->crawl_items_facebook($fed->fed_id, $posts['feed']['data']); $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row(); $this->db->set('fed_title', $result['name']); $this->db->set('fed_url', $result['link']); $this->db->set('fed_link', $result['link']); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } $this->db->set('fed_description', $result['about']); $this->db->set('fed_lasterror', ''); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); if ($lastitem) { $nextcrawl = ''; //older than 96 hours, next crawl in 12 hours if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24 * 96)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 12); //older than 48 hours, next crawl in 6 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 48)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 6); //older than 24 hours, next crawl in 3 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 3); } } } $this->db->set('fed_nextcrawl', $nextcrawl); } $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } catch (Facebook\Exceptions\FacebookResponseException $e) { $errors++; $this->db->set('fed_lasterror', 'Graph returned an error: ' . $e->getMessage()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } catch (Facebook\Exceptions\FacebookSDKException $e) { $errors++; $this->db->set('fed_lasterror', 'Facebook SDK returned an error: ' . $e->getMessage()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } } else { $sp_feed = new SimplePie(); $sp_feed->set_feed_url(convert_to_ascii($fed->fed_link)); $sp_feed->enable_cache(false); $sp_feed->set_timeout(5); $sp_feed->force_feed(true); $sp_feed->init(); $sp_feed->handle_content_type(); if ($sp_feed->error()) { $errors++; $this->db->set('fed_lasterror', $sp_feed->error()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } else { $this->readerself_library->crawl_items($fed->fed_id, $sp_feed->get_items()); $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row(); $parse_url = parse_url($sp_feed->get_link()); $this->db->set('fed_title', $sp_feed->get_title()); $this->db->set('fed_url', $sp_feed->get_link()); $this->db->set('fed_link', $sp_feed->subscribe_url()); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } if ($sp_feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $this->db->set('fed_type', 'rss'); } else { if ($sp_feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $this->db->set('fed_type', 'atom'); } } if ($sp_feed->get_image_url()) { $this->db->set('fed_image', $sp_feed->get_image_url()); } $this->db->set('fed_description', $sp_feed->get_description()); $this->db->set('fed_lasterror', ''); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); if ($lastitem) { $nextcrawl = ''; //older than 96 hours, next crawl in 12 hours if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24 * 96)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 12); //older than 48 hours, next crawl in 6 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 48)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 6); //older than 24 hours, next crawl in 3 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 3); } } } $this->db->set('fed_nextcrawl', $nextcrawl); } $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } $sp_feed->__destruct(); unset($sp_feed); } } $this->db->set('crr_time', microtime(1) - $microtime_start); if (function_exists('memory_get_peak_usage')) { $this->db->set('crr_memory', memory_get_peak_usage()); } $this->db->set('crr_feeds', $query->num_rows()); if ($errors > 0) { $this->db->set('crr_errors', $errors); } $this->db->set('crr_datecreated', date('Y-m-d H:i:s')); $this->db->insert('crawler'); if ($this->db->dbdriver == 'mysqli') { $this->db->query('OPTIMIZE TABLE categories, connections, enclosures, favorites, feeds, folders, history, items, members, share, subscriptions'); } } } $this->readerself_library->set_content($content); }
$aStories[] = array('title' => $sTitle, 'authors' => $oItem->get_authors(), 'description' => $oItem->get_description(), 'url' => $sLink, 'local_uri' => $sLocalUri, 'published_at' => $nTimestamp); } } $SimplePie->__destruct(); unset($SimplePie); $_GLOBAL['aStories'] = $aStories; // #2: Get the weather $sWeatherFeed = 'http://www.wunderground.com/auto/rss_full/CA/Palo_Alto.xml'; $SimplePie = new SimplePie(); $SimplePie->enable_cache(false); $SimplePie->set_feed_url($sWeatherFeed); $SimplePie->init(); $SimplePie->handle_content_type(); if ($SimplePie->error()) { // TODO: Delete that feed?? $SimplePie->__destruct(); continue; } $aWeather = $SimplePie->get_items(); foreach ($aWeather as $oItem) { $sTitle = $oItem->get_title(); if (stristr($sTitle, 'Current Condition')) { $GLOBALS['sWeather'] = mb_substr($sTitle, 21); break; } /*if (preg_match('/^Current Conditions : (-?[0-9]{1,3}[.][0-9])/', $sTitle, $aMatches)) { $GLOBALS['sCurrentTemp'] = $aMatches[1]; break; }*/ } $SimplePie->__destruct(); unset($SimplePie);
public function create() { if (!$this->axipi_session->userdata('mbr_id')) { redirect(base_url() . '?u=' . $this->input->get('u')); } $data = array(); $content = array(); $this->load->library(array('form_validation', 'analyzer_library')); if ($this->config->item('folders')) { $query = $this->db->query('SELECT flr.* FROM ' . $this->db->dbprefix('folders') . ' AS flr WHERE flr.mbr_id = ? GROUP BY flr.flr_id ORDER BY flr.flr_title ASC', array($this->member->mbr_id)); $data['folders'] = array(); $data['folders'][0] = $this->lang->line('no_folder'); if ($query->num_rows() > 0) { foreach ($query->result() as $flr) { $data['folders'][$flr->flr_id] = $flr->flr_title; } } } $this->form_validation->set_rules('url', 'lang:url_feed', 'required'); if ($this->config->item('folders')) { $this->form_validation->set_rules('folder', 'lang:folder', 'required'); } $this->form_validation->set_rules('priority', 'lang:priority', 'numeric'); //$this->form_validation->set_rules('direction', 'lang:direction', ''); $data['error'] = false; $data['feeds'] = array(); if ($this->input->post('url') && !$this->input->post('analyze_done')) { $this->analyzer_library->start($this->input->post('url')); $metas = $this->analyzer_library->metas; if (count($metas) > 0) { $data['feeds'][''] = '-'; foreach ($metas as $meta) { $add = true; $headers = get_headers($meta['href'], 1); if (isset($headers['Location']) == 1) { $meta['href'] = $headers['Location']; $headers = get_headers($meta['href'], 1); if (isset($headers['Location']) == 1) { $add = false; } } if ($add) { if ($meta['title'] == '') { $data['feeds'][$meta['href']] = $meta['href']; } else { $this->analyzer_library->encoding($meta['title']); $data['feeds'][$meta['href']] = $meta['title']; } } } } } if ($this->form_validation->run() == FALSE || count($data['feeds']) > 0) { $content = $this->load->view('subscriptions_create', $data, TRUE); } else { if ($this->config->item('folders')) { $folder = false; if ($this->input->post('folder')) { $query = $this->db->query('SELECT flr.* FROM ' . $this->db->dbprefix('folders') . ' AS flr WHERE flr.mbr_id = ? AND flr.flr_id = ? GROUP BY flr.flr_id', array($this->member->mbr_id, $this->input->post('folder'))); if ($query->num_rows() > 0) { $folder = $this->input->post('folder'); } } } $query = $this->db->query('SELECT fed.*, sub.sub_id FROM ' . $this->db->dbprefix('feeds') . ' AS fed LEFT JOIN ' . $this->db->dbprefix('subscriptions') . ' AS sub ON sub.fed_id = fed.fed_id AND sub.mbr_id = ? WHERE fed.fed_link = ? GROUP BY fed.fed_id', array($this->member->mbr_id, $this->input->post('url'))); if ($query->num_rows() == 0) { $parse_url = parse_url($this->input->post('url')); if (isset($parse_url['host']) == 1 && $parse_url['host'] == 'instagram.com' && $this->config->item('instagram/enabled')) { if ($this->config->item('instagram/access_token')) { $parts = explode('/', rtrim($parse_url['path'], '/')); $total_parts = count($parts); $last_part = $parts[$total_parts - 1]; $result = json_decode(file_get_contents('https://api.instagram.com/v1/users/search?q=' . $last_part . '&count=15&access_token=' . $this->config->item('instagram/access_token'))); if (count($result->data) == 0) { $data['error'] = 'User not found'; } else { $user_id = false; foreach ($result->data as $user) { if ($user->username == $last_part) { $user_id = $user->id; break; } } if (!$user_id) { $data['error'] = 'User not found'; } else { $result = json_decode(file_get_contents('https://api.instagram.com/v1/users/' . $user_id . '?access_token=' . $this->config->item('instagram/access_token'))); $this->db->set('fed_title', 'Instagram @' . $result->data->username); $this->db->set('fed_url', $this->input->post('url')); $this->db->set('fed_description', $result->data->bio); $this->db->set('fed_image', $result->data->profile_picture); $this->db->set('fed_link', $this->input->post('url')); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->set('fed_datecreated', date('Y-m-d H:i:s')); $this->db->insert('feeds'); $fed_id = $this->db->insert_id(); $this->db->set('mbr_id', $this->member->mbr_id); $this->db->set('fed_id', $fed_id); if ($this->config->item('folders')) { if ($folder) { $this->db->set('flr_id', $folder); } } $this->db->set('sub_priority', $this->input->post('priority')); $this->db->set('sub_direction', $this->input->post('direction')); $this->db->set('sub_datecreated', date('Y-m-d H:i:s')); $this->db->insert('subscriptions'); $sub_id = $this->db->insert_id(); $result = json_decode(file_get_contents('https://api.instagram.com/v1/users/' . $user_id . '/media/recent?access_token=' . $this->config->item('instagram/access_token'))); $this->readerself_library->crawl_items_instagram($fed_id, $result->data); } } } } else { if (isset($parse_url['host']) == 1 && $parse_url['host'] == 'www.facebook.com' && $this->config->item('facebook/enabled')) { include_once 'thirdparty/facebook/autoload.php'; $fb = new Facebook\Facebook(array('app_id' => $this->config->item('facebook/id'), 'app_secret' => $this->config->item('facebook/secret'))); $fbApp = $fb->getApp(); $accessToken = $fbApp->getAccessToken(); try { $parts = explode('/', rtrim($parse_url['path'], '/')); $total_parts = count($parts); $last_part = $parts[$total_parts - 1]; $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=link,name,about'); $response = $fb->getClient()->sendRequest($request); $result = $response->getDecodedBody(); $this->db->set('fed_title', $result['name']); $this->db->set('fed_url', $result['link']); $this->db->set('fed_description', $result['about']); $this->db->set('fed_link', $result['link']); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->set('fed_datecreated', date('Y-m-d H:i:s')); $this->db->insert('feeds'); $fed_id = $this->db->insert_id(); $this->db->set('mbr_id', $this->member->mbr_id); $this->db->set('fed_id', $fed_id); if ($this->config->item('folders')) { if ($folder) { $this->db->set('flr_id', $folder); } } $this->db->set('sub_priority', $this->input->post('priority')); $this->db->set('sub_direction', $this->input->post('direction')); $this->db->set('sub_datecreated', date('Y-m-d H:i:s')); $this->db->insert('subscriptions'); $sub_id = $this->db->insert_id(); $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=feed{created_time,id,message,story,full_picture,place,type,status_type,link}'); $response = $fb->getClient()->sendRequest($request); $posts = $response->getDecodedBody(); $this->readerself_library->crawl_items_facebook($fed_id, $posts['feed']['data']); redirect(base_url() . 'subscriptions/read/' . $sub_id); } catch (Facebook\Exceptions\FacebookResponseException $e) { $data['error'] = 'Graph returned an error: ' . $e->getMessage(); } catch (Facebook\Exceptions\FacebookSDKException $e) { $data['error'] = 'Facebook SDK returned an error: ' . $e->getMessage(); } } else { include_once 'thirdparty/simplepie/autoloader.php'; include_once 'thirdparty/simplepie/idn/idna_convert.class.php'; $sp_feed = new SimplePie(); $sp_feed->set_feed_url(convert_to_ascii($this->input->post('url'))); $sp_feed->enable_cache(false); $sp_feed->set_timeout(60); $sp_feed->force_feed(true); $sp_feed->init(); $sp_feed->handle_content_type(); if ($sp_feed->error()) { $data['error'] = $sp_feed->error(); } else { $parse_url = parse_url($sp_feed->get_link()); $this->db->set('fed_title', $sp_feed->get_title()); $this->db->set('fed_url', $sp_feed->get_link()); $this->db->set('fed_description', $sp_feed->get_description()); $this->db->set('fed_link', $sp_feed->subscribe_url()); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->set('fed_datecreated', date('Y-m-d H:i:s')); $this->db->insert('feeds'); $fed_id = $this->db->insert_id(); $this->db->set('mbr_id', $this->member->mbr_id); $this->db->set('fed_id', $fed_id); if ($this->config->item('folders')) { if ($folder) { $this->db->set('flr_id', $folder); } } $this->db->set('sub_priority', $this->input->post('priority')); $this->db->set('sub_direction', $this->input->post('direction')); $this->db->set('sub_datecreated', date('Y-m-d H:i:s')); $this->db->insert('subscriptions'); $sub_id = $this->db->insert_id(); $data['sub_id'] = $sub_id; $data['fed_title'] = $sp_feed->get_title(); $this->readerself_library->crawl_items($fed_id, $sp_feed->get_items()); } $sp_feed->__destruct(); unset($sp_feed); } } } else { $fed = $query->row(); if (!$fed->sub_id) { $this->db->set('mbr_id', $this->member->mbr_id); $this->db->set('fed_id', $fed->fed_id); if ($this->config->item('folders')) { if ($folder) { $this->db->set('flr_id', $folder); } } $this->db->set('sub_priority', $this->input->post('priority')); $this->db->set('sub_direction', $this->input->post('direction')); $this->db->set('sub_datecreated', date('Y-m-d H:i:s')); $this->db->insert('subscriptions'); $sub_id = $this->db->insert_id(); } else { $sub_id = $fed->sub_id; } $data['sub_id'] = $sub_id; $data['fed_title'] = $fed->fed_title; } if ($data['error']) { $content = $this->load->view('subscriptions_create', $data, TRUE); } else { redirect(base_url() . 'subscriptions/read/' . $sub_id); } } $this->readerself_library->set_content($content); }
/** * Fetches all current events from this extension. * @return {Array} List of events. */ function fetch($urls = null, $initial = false) { if (!$urls) { $urls = $this->get_url(); } if (!is_array($urls)) { $urls = array($urls); } $items = array(); foreach ($urls as $url_data) { if (is_array($url_data)) { // url, key list($url, $key) = $url_data; } else { $url = $url_data; $key = ''; } $feed = new SimplePie(); $feed->enable_cache(false); $data = $this->lifestream->file_get_contents($url); $feed->set_raw_data($data); $feed->enable_order_by_date(false); $feed->force_feed(true); $success = $feed->init(); if (!$success) { $sample = substr($data, 0, 150); throw new Lifestream_FeedFetchError("Error fetching feed from {$url} ({$feed->error()})....\n\n{$sample}"); } $feed->handle_content_type(); foreach ($feed->get_items() as $row) { $rows =& $this->yield_many($row, $url, $key); foreach ($rows as $row) { if (!$row) { continue; } if (!$row['key']) { $row['key'] = $key; } if (count($row)) { $items[] = $row; } } } $feed->__destruct(); unset($feed); } return $items; }
/** * The actual function that can be called on webpages. */ function SimplePieWP($feed_url, $options = null) { // Quit if the SimplePie class isn't loaded. if (!class_exists('SimplePie')) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> There is a problem with the SimplePie Plugin for WordPress. Check your <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">Installation Status</a> for more information.</p>'); } if (isset($locale) && !empty($locale) && $locale != 'auto') { setlocale(LC_TIME, $locale); } // Default general settings $template = get_option('simplepie_template'); $items = get_option('simplepie_items'); $items_per_feed = get_option('simplepie_items_per_feed'); $date_format = get_option('simplepie_date_format'); $enable_cache = get_option('simplepie_enable_cache'); $set_cache_location = get_option('simplepie_set_cache_location'); $set_cache_duration = get_option('simplepie_set_cache_duration'); $enable_order_by_date = get_option('simplepie_enable_order_by_date'); $set_timeout = get_option('simplepie_set_timeout'); // Default text-shortening settings $truncate_feed_title = get_option('simplepie_truncate_feed_title'); $truncate_feed_description = get_option('simplepie_truncate_feed_description'); $truncate_item_title = get_option('simplepie_truncate_item_title'); $truncate_item_description = get_option('simplepie_truncate_item_description'); // Default advanced settings $processing = get_option('simplepie_processing'); $locale = get_option('simplepie_locale'); $local_date_format = get_option('simplepie_local_date_format'); $strip_htmltags = get_option('simplepie_strip_htmltags'); $strip_attributes = get_option('simplepie_strip_attributes'); $set_max_checked_feeds = get_option('simplepie_set_max_checked_feeds'); // Overridden settings if ($options) { // Fix the template location if one was passed in. if (isset($options['template']) && !empty($options['template'])) { $options['template'] = SIMPLEPIE_PLUGINDIR . '/templates/' . strtolower(str_replace(' ', '_', $options['template'])) . '.tmpl'; } // Fix the processing location if one was passed in. if (isset($options['processing']) && !empty($options['processing'])) { $options['processing'] = SIMPLEPIE_PLUGINDIR . '/processing/' . strtolower(str_replace(' ', '_', $options['processing'])) . '.php'; } extract($options); } // Load post-processing file. if ($processing && $processing != '') { include_once $processing; } // If template doesn't exist, die. if (!file_exists($template) || !is_readable($template)) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> The SimplePie template file is not readable by WordPress. Check the <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">WordPress Control Panel</a> for more information.</p>'); } // Initialize SimplePie $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->enable_cache($enable_cache); $feed->set_item_limit($items_per_feed); $feed->set_cache_location($set_cache_location); $feed->set_cache_duration($set_cache_duration); $feed->enable_order_by_date($enable_order_by_date); $feed->set_timeout($set_timeout); $feed->strip_htmltags(explode(' ', $strip_htmltags)); $feed->strip_attributes(explode(' ', $strip_attributes)); $feed->set_max_checked_feeds($set_max_checked_feeds); $feed->init(); // Load up the selected template file $handle = fopen($template, 'r'); $tmpl = fread($handle, filesize($template)); fclose($handle); /**************************************************************************************************************/ // ERRORS // I'm absolutely sure that there is a better way to do this. // Define what we're looking for $error_start_tag = '{IF_ERROR_BEGIN}'; $error_end_tag = '{IF_ERROR_END}'; $error_start_length = strlen($error_start_tag); $error_end_length = strlen($error_end_tag); // Find what we're looking for $error_start_pos = strpos($tmpl, $error_start_tag); $error_end_pos = strpos($tmpl, $error_end_tag); $error_length_pos = $error_end_pos - $error_start_pos; // Grab what we're looking for $error_string = substr($tmpl, $error_start_pos + $error_start_length, $error_length_pos - $error_start_length); $replacable_string = $error_start_tag . $error_string . $error_end_tag; if ($error_message = $feed->error()) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', $error_message), $tmpl); } elseif ($feed->get_item_quantity() == 0) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', 'There are no items in this feed.'), $tmpl); } else { $tmpl = str_replace($replacable_string, '', $tmpl); } /**************************************************************************************************************/ // FEED // FEED_AUTHOR_EMAIL /* if ($author = $feed->get_author()) { if ($email = $author->get_email()) { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('FEED_AUTHOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } // FEED_AUTHOR_LINK if ($author = $feed->get_author()) { if ($link = $author->get_link()) { $tmpl = str_replace('{FEED_AUTHOR_LINK}', SimplePie_WordPress::post_process('FEED_AUTHOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } // FEED_AUTHOR_NAME if ($author = $feed->get_author()) { if ($name = $author->get_name()) { $tmpl = str_replace('{FEED_AUTHOR_NAME}', SimplePie_WordPress::post_process('FEED_AUTHOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } // FEED_CONTRIBUTOR_EMAIL if ($contributor = $feed->get_contributor()) { if ($email = $contributor->get_email()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } // FEED_CONTRIBUTOR_LINK if ($contributor = $feed->get_contributor()) { if ($link = $contributor->get_link()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } // FEED_CONTRIBUTOR_NAME if ($contributor = $feed->get_contributor()) { if ($name = $contributor->get_name()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } // FEED_COPYRIGHT if ($copyright = $feed->get_copyright()) { $tmpl = str_replace('{FEED_COPYRIGHT}', SimplePie_WordPress::post_process('FEED_COPYRIGHT', $copyright), $tmpl); } else { $tmpl = str_replace('{FEED_COPYRIGHT}', '', $tmpl); } // FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{FEED_DESCRIPTION}', SimplePie_WordPress::post_process('FEED_DESCRIPTION', $description), $tmpl); } else { $tmpl = str_replace('{FEED_DESCRIPTION}', '', $tmpl); } // FEED_ENCODING if ($encoding = $feed->get_encoding()) { $tmpl = str_replace('{FEED_ENCODING}', SimplePie_WordPress::post_process('FEED_ENCODING', $encoding), $tmpl); } else { $tmpl = str_replace('{FEED_ENCODING}', '', $tmpl); } // FEED_FAVICON if ($favicon = $feed->get_favicon()) { $tmpl = str_replace('{FEED_FAVICON}', SimplePie_WordPress::post_process('FEED_FAVICON', $favicon), $tmpl); } else { $tmpl = str_replace('{FEED_FAVICON}', '', $tmpl); } // FEED_IMAGE_HEIGHT if ($image_height = $feed->get_image_height()) { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('FEED_IMAGE_HEIGHT', $image_height), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', '', $tmpl); } // FEED_IMAGE_LINK if ($image_link = $feed->get_image_link()) { $tmpl = str_replace('{FEED_IMAGE_LINK}', SimplePie_WordPress::post_process('FEED_IMAGE_LINK', $image_link), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_LINK}', '', $tmpl); } // FEED_IMAGE_TITLE if ($image_title = $feed->get_image_title()) { $tmpl = str_replace('{FEED_IMAGE_TITLE}', SimplePie_WordPress::post_process('FEED_IMAGE_TITLE', $image_title), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_TITLE}', '', $tmpl); } // FEED_IMAGE_URL if ($image_url = $feed->get_image_url()) { $tmpl = str_replace('{FEED_IMAGE_URL}', SimplePie_WordPress::post_process('FEED_IMAGE_URL', $image_url), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_URL}', '', $tmpl); } // FEED_IMAGE_WIDTH if ($image_width = $feed->get_image_width()) { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', SimplePie_WordPress::post_process('FEED_IMAGE_WIDTH', $image_width), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', '', $tmpl); } // FEED_LANGUAGE if ($language = $feed->get_language()) { $tmpl = str_replace('{FEED_LANGUAGE}', SimplePie_WordPress::post_process('FEED_LANGUAGE', $language), $tmpl); } else { $tmpl = str_replace('{FEED_LANGUAGE}', '', $tmpl); } // FEED_LATITUDE if ($latitude = $feed->get_latitude()) { $tmpl = str_replace('{FEED_LATITUDE}', SimplePie_WordPress::post_process('FEED_LATITUDE', $latitude), $tmpl); } else { $tmpl = str_replace('{FEED_LATITUDE}', '', $tmpl); } // FEED_LONGITUDE if ($longitude = $feed->get_longitude()) { $tmpl = str_replace('{FEED_LONGITUDE}', SimplePie_WordPress::post_process('FEED_LONGITUDE', $longitude), $tmpl); } else { $tmpl = str_replace('{FEED_LONGITUDE}', '', $tmpl); } // FEED_PERMALINK if ($permalink = $feed->get_permalink()) { $tmpl = str_replace('{FEED_PERMALINK}', SimplePie_WordPress::post_process('FEED_PERMALINK', $permalink), $tmpl); } else { $tmpl = str_replace('{FEED_PERMALINK}', '', $tmpl); } // FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{FEED_TITLE}', SimplePie_WordPress::post_process('FEED_TITLE', $title), $tmpl); } else { $tmpl = str_replace('{FEED_TITLE}', '', $tmpl); } // SUBSCRIBE_URL if ($subscribe_url = $feed->subscribe_url()) { $tmpl = str_replace('{SUBSCRIBE_URL}', SimplePie_WordPress::post_process('SUBSCRIBE_URL', $subscribe_url), $tmpl); } else { $tmpl = str_replace('{SUBSCRIBE_URL}', '', $tmpl); } // TRUNCATE_FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_DESCRIPTION', $description), $truncate_feed_description), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', '', $tmpl); } // TRUNCATE_FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_TITLE', $title), $truncate_feed_title), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', '', $tmpl); } */ /**************************************************************************************************************/ // ITEMS // Separate out the pre-item template $tmpl = explode('{ITEM_LOOP_BEGIN}', $tmpl); $pre_tmpl = $tmpl[0]; // Separate out the item template $tmpl = explode('{ITEM_LOOP_END}', $tmpl[1]); $item_tmpl = $tmpl[0]; // Separate out the post-item template $post_tmpl = $tmpl[1]; // Clear out the variable unset($tmpl); // Start putting the output string together. $tmpl = $pre_tmpl; // Loop through all of the items that we're supposed to. foreach ($feed->get_items(0, $items) as $item) { // Get a reference to the parent $feed object. $parent = $item->get_feed(); // Get a working copy of the item template. We don't want to edit the original. $working_item = $item_tmpl; // ITEM_CONTRIBUTOR_EMAIL /* if ($contributor = $item->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_CONTRIBUTOR_LINK if ($contributor = $item->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_CONTRIBUTOR_NAME if ($contributor = $item->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_COPYRIGHT if ($copyright = $item->get_copyright()) { $working_item = str_replace('{ITEM_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_AUTHOR_EMAIL if ($author = $parent->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } // ITEM_PARENT_AUTHOR_LINK if ($author = $parent->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } // ITEM_PARENT_AUTHOR_NAME if ($author = $parent->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_EMAIL if ($contributor = $parent->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_LINK if ($contributor = $parent->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_NAME if ($contributor = $parent->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_AUTHOR_EMAIL if ($author = $item->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } // ITEM_AUTHOR_LINK if ($author = $item->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } // ITEM_AUTHOR_NAME if ($author = $item->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } // ITEM_CATEGORY if ($category = $item->get_category()) { if ($label = $category->get_label()) { $working_item = str_replace('{ITEM_CATEGORY}', SimplePie_WordPress::post_process('ITEM_CATEGORY', $label), $working_item); } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } */ // ITEM_CONTENT if ($content = $item->get_content()) { $working_item = str_replace('{ITEM_CONTENT}', SimplePie_WordPress::post_process('ITEM_CONTENT', $content), $working_item); } else { $working_item = str_replace('{ITEM_CONTENT}', '', $working_item); } // ITEM_DATE if ($date = $item->get_date($date_format)) { $working_item = str_replace('{ITEM_DATE}', SimplePie_WordPress::post_process('ITEM_DATE', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE}', '', $working_item); } // ITEM_DATE_UTC if ($date = $item->get_date('U')) { $date = gmdate($date_format, $date); $working_item = str_replace('{ITEM_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_DATE_UTC', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE_UTC}', '', $working_item); } // ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{ITEM_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_DESCRIPTION}', '', $working_item); } /* // ITEM_ENCLOSURE_EMBED if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->native_embed()) { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EMBED', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } // ITEM_ENCLOSURE_EXTENSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_extension()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXTENSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } // ITEM_ENCLOSURE_HANDLER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_handler()) { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HANDLER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } // ITEM_ENCLOSURE_LENGTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_length()) { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LENGTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } // ITEM_ENCLOSURE_LINK if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_link()) { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LINK', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } // ITEM_ENCLOSURE_REAL_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_real_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_REAL_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_SIZE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_size()) { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SIZE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } // ITEM_ENCLOSURE_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_BITRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_bitrate()) { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_BITRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } // ITEM_ENCLOSURE_CHANNELS if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_channels()) { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_CHANNELS', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } // ITEM_ENCLOSURE_DESCRIPTION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_description()) { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DESCRIPTION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } // ITEM_ENCLOSURE_DURATION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_duration()) { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DURATION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } // ITEM_ENCLOSURE_EXPRESSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_expression()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXPRESSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } // ITEM_ENCLOSURE_FRAMERATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_framerate()) { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_FRAMERATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } // ITEM_ENCLOSURE_HASH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_hash()) { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HASH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } // ITEM_ENCLOSURE_HEIGHT if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_height()) { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HEIGHT', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } // ITEM_ENCLOSURE_LANGUAGE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_language()) { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LANGUAGE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } // ITEM_ENCLOSURE_MEDIUM if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_medium()) { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_MEDIUM', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } // ITEM_ENCLOSURE_PLAYER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_player()) { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_PLAYER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } // ITEM_ENCLOSURE_SAMPLINGRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_sampling_rate()) { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SAMPLINGRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } // ITEM_ENCLOSURE_THUMBNAIL if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_thumbnail()) { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_THUMBNAIL', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } // ITEM_ENCLOSURE_TITLE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_title()) { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TITLE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } // ITEM_ENCLOSURE_WIDTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_width()) { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_WIDTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } // ITEM_ID if ($id = $item->get_id()) { $working_item = str_replace('{ITEM_ID}', SimplePie_WordPress::post_process('ITEM_ID', $id), $working_item); } else { $working_item = str_replace('{ITEM_ID}', '', $working_item); } // ITEM_ID if ($latitude = $item->get_latitude()) { $working_item = str_replace('{ITEM_LATITUDE}', SimplePie_WordPress::post_process('ITEM_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_LATITUDE}', '', $working_item); } // ITEM_LOCAL_DATE if ($local_date = $item->get_local_date($local_date_format)) { $working_item = str_replace('{ITEM_LOCAL_DATE}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE}', '', $working_item); } // ITEM_LOCAL_DATE_UTC if ($local_date = $item->get_date('U')) { $local_date = gmdate('U', $local_date); $local_date = strftime($local_date_format, $local_date); $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE_UTC', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', '', $working_item); } // ITEM_LONGITUDE if ($longitude = $item->get_longitude()) { $working_item = str_replace('{ITEM_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_LONGITUDE}', '', $working_item); } */ // ITEM_PERMALINK if ($permalink = $item->get_permalink()) { $working_item = str_replace('{ITEM_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PERMALINK}', '', $working_item); } // ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{ITEM_TITLE}', SimplePie_WordPress::post_process('ITEM_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_TITLE}', '', $working_item); } /* // ITEM_PARENT_COPYRIGHT if ($copyright = $parent->get_copyright()) { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_PARENT_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', '', $working_item); } // ITEM_PARENT_ENCODING if ($encoding = $parent->get_encoding()) { $working_item = str_replace('{ITEM_PARENT_ENCODING}', SimplePie_WordPress::post_process('ITEM_PARENT_ENCODING', $encoding), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_ENCODING}', '', $working_item); } // ITEM_PARENT_FAVICON if ($favicon = $parent->get_favicon()) { $working_item = str_replace('{ITEM_PARENT_FAVICON}', SimplePie_WordPress::post_process('ITEM_PARENT_FAVICON', $favicon), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_FAVICON}', '', $working_item); } // ITEM_PARENT_IMAGE_HEIGHT if ($image_height = $parent->get_image_height()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_HEIGHT', $image_height), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', '', $working_item); } // ITEM_PARENT_IMAGE_LINK if ($image_link = $parent->get_image_link()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_LINK', $image_link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', '', $working_item); } // ITEM_PARENT_IMAGE_TITLE if ($image_title = $parent->get_image_title()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_TITLE', $image_title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', '', $working_item); } // ITEM_PARENT_IMAGE_URL if ($image_url = $parent->get_image_url()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_URL', $image_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', '', $working_item); } // ITEM_PARENT_IMAGE_WIDTH if ($image_width = $parent->get_image_width()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_WIDTH', $image_width), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', '', $working_item); } // ITEM_PARENT_LANGUAGE if ($language = $parent->get_language()) { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_PARENT_LANGUAGE', $language), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', '', $working_item); } // ITEM_PARENT_LATITUDE if ($latitude = $parent->get_latitude()) { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', '', $working_item); } // ITEM_PARENT_LONGITUDE if ($longitude = $parent->get_longitude()) { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', '', $working_item); } // ITEM_PARENT_PERMALINK if ($permalink = $parent->get_permalink()) { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PARENT_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', '', $working_item); } // ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{ITEM_PARENT_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_TITLE}', '', $working_item); } // ITEM_PARENT_SUBSCRIBE_URL if ($subscribe_url = $parent->subscribe_url()) { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_SUBSCRIBE_URL', $subscribe_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', '', $working_item); } */ // TRUNCATE_ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_DESCRIPTION', $description), $truncate_item_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_TITLE', $title), $truncate_item_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', '', $working_item); } /* // TRUNCATE_ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_DESCRIPTION', $description), $truncate_feed_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_TITLE', $title), $truncate_feed_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', '', $working_item); } */ $tmpl .= $working_item; } /**************************************************************************************************************/ // LAST STUFF // Start by removing all line breaks and tabs. $tmpl = preg_replace('/(\\n|\\r|\\t)/i', "", $tmpl); // PLUGIN_DIR $tmpl = str_replace('{PLUGIN_DIR}', SIMPLEPIE_PLUGINDIR_WEB, $tmpl); $tmpl .= $post_tmpl; // Kill the object to prevent memory leaks. $feed->__destruct(); unset($feed); unset($encltemp); unset($working_item); // Return the data back to the page. return $tmpl; }
function getItemsFromFeeds($rs, $print) { global $blog_settings, $core; $output = ""; $cron_file = dirname(__FILE__) . '/cron_running.txt'; # Duree de mise a jour $debut = explode(" ", microtime()); $debut = $debut[1] + $debut[0]; $cpt = 0; while ($rs->fetch()) { # On verifie si on n'a pas demandĂ© l'arrĂȘt de l'algo if (file_exists(dirname(__FILE__) . '/STOP')) { $log_msg = logMsg(T_("STOP file detected, trying to shut down cron job"), "", 2, $print); if ($print) { $output .= $log_msg; } break; } $log_msg = logMsg(T_("Check feed : ") . $rs->feed_url, "", 0, $print); if ($print) { $output .= $log_msg; } require_once dirname(__FILE__) . '/lib/simplepie_1.3.compiled.php'; # On cree un objet SimplePie et on ajuste les parametres de base $feed = new SimplePie(); $feed->set_feed_url($rs->feed_url); $feed->set_cache_location(dirname(__FILE__) . '/../admin/cache'); #$feed->enable_cache(false); # $feed->set_cache_duration($item_refresh); $feed->init(); # Pour faire fonctionner les lecteurs flash, non recomande par simplepie $feed->strip_htmltags(false); # Si le flux ne contient pas de donnee #$item_nb = $feed->get_item_quantity(); $error = $feed->error(); if (isset($error)) { # Affichage du message d'erreur if (ereg($rs->feed_url, $error)) { $log_msg = logMsg(T_("No feed found : ") . $error, "", 3, $print); } else { $log_msg = logMsg(sprintf(T_("No feed found on %s (owner : %s)"), $rs->feed_url, $rs->user_id) . $error, "", 3, $print); } if ($print) { $output .= $log_msg; } } else { $items = $feed->get_items(); foreach ($items as $item) { #print $item->get_permalink().'<br>'; #continue; # open log file and write activity down $fp = @fopen($cron_file, 'wb'); if ($fp === false) { throw new Exception(sprintf(T_('Cannot write %s file.'), $cron_file)); } fwrite($fp, time()); fclose($fp); # Analyse the item ##################### # Content $item_content = strip_script($item->get_content()); if (empty($item_content)) { $item_content = $item->get_description(); } $item_content = traitementEncodage($item_content); # Title $item_title = traitementEncodage($item->get_title()); if (strlen($item_title) > 254) { $item_title = substr($item_title, 0, 254); } # Permalink $permalink = $item->get_permalink(); $item_image = getFirstPostImageUrl($item->get_content()); # Analyse the possible tags of the item ########################################## # Get tags defined in the database for all posts of that feed $item_tags = array(); # Get the tags on the feed $rs_feed_tag = $core->con->select("SELECT tag_id FROM " . $core->prefix . "feed_tag\r\n\t\t\t\t\tWHERE feed_id = " . $rs->feed_id); while ($rs_feed_tag->fetch()) { $item_tags[] = strtolower($rs_feed_tag->tag_id); } # Get the reserved tags $reserved_tags = array(); $planet_tags = getArrayFromList($blog_settings->get('planet_reserved_tags')); if (is_array($planet_tags)) { foreach ($planet_tags as $tag) { $reserved_tags[] = strtolower($tag); } } # Get tags defined on the item in the feed $categs = $item->get_categories(); if ($categs) { foreach ($categs as $category) { $label = strtolower($category->get_label()); if (!in_array($label, $item_tags) && !in_array($label, $reserved_tags) && !is_int($label) && strlen($label) > 1) { $item_tags[] = $label; } } } # Find hashtags in title $hashtags = array(); preg_match('/#([\\d\\w]+)/', $item->get_title(), $hashtags); foreach ($hashtags as $tag) { $tag = strtolower($tag); if (!in_array($tag, $item_tags) && !in_array($tag, $reserved_tags) && !is_int($tag) && strlen($tag) > 1) { $item_tags[] = $tag; } } # check if some existing tags are in the title foreach (explode(' ', $item_title) as $word) { $word = strtolower($word); $tagRq = $core->con->select('SELECT tag_id FROM ' . $core->prefix . 'post_tag WHERE tag_id = \'' . $word . "'"); if ($tagRq->count() > 1 && !in_array($word, $item_tags) && !in_array($word, $reserved_tags) && !is_int($word) && strlen($word) > 1) { $item_tags[] = $word; } } if (empty($item_content)) { $log_msg = logMsg(sprintf(T_("No content on feed %s"), $rs->feed_url), "", 3, $print); } elseif (empty($permalink)) { $log_msg = logMsg(T_("Error in link cutting : ") . $permalink, "", 3, $print); } else { $log_msg = insertPostToDatabase($rs, $permalink, $item->get_date("U"), $item_title, $item_content, $item_tags, $item_image, $print, $rs->feed_id); $cpt++; } # fin du $item->get_content() if ($print) { $output .= $log_msg; } } # fin du foreach # Le flux a ete mis a jour, on le marque a la derniere date $cur = $core->con->openCursor($core->prefix . 'feed'); $cur->feed_checked = array('NOW()'); $cur->update("WHERE feed_id = '{$rs->feed_id}'"); $log_msg = logMsg(sprintf(T_("The feed %s is updated"), $rs->feed_url), "", 2, $print); if ($print) { $output .= $log_msg; } # On fait un reset du foreach reset($items); } # fin $feed->error() # Destruction de l'objet feed avant de passer a un autre $feed->__destruct(); unset($feed); if ($blog_settings->get('auto_feed_disabling')) { $toolong = time() - 86400 * 7; # seven days ago $check_sql = "SELECT feed_checked FROM " . $core->prefix . "feed WHERE feed_id=" . $rs->feed_id; $rs_check = $core->con->select($check_sql); $last_checked = mysqldatetime_to_timestamp($rs_check->f('feed_checked')); if ($last_checked < $toolong) { $diff = (time() - $last_checked) / 86400; $log_msg = logMsg(sprintf(T_("The feed was not updated since %d days. It'll be disabled : "), $diff) . $rs->feed_url, "", 2, $print); if ($print) { $output .= $log_msg; } # if feed was in error for too long, let's disable it $cur = $core->con->openCursor($core->prefix . 'feed'); $cur->feed_status = 2; $cur->update("WHERE feed_id = '{$rs->feed_id}'"); $from = $blog_settings->get('author_mail'); $to = $from . ',' . $rs->user_email; $reply_to = $from; $subject = sprintf(T_("Due to errors, a feed has been disabled on %s"), $blog_settings->get('planet_title')); $content = sprintf(T_("The feed of %s has been disabled :\n"), $rs->user_fullname); $content .= $rs->feed_url . "\n"; $content .= sprintf(T_("The feed was in error during more than %d days"), $diff); $content .= "\n\n" . T_("Details :"); $content .= "\n" . T_("User id : ") . $rs->user_id; $content .= "\n" . T_("User name : ") . $rs->user_fullname; $content .= "\n" . T_("User email : ") . $rs->user_email; $content .= "\n" . T_("Feed url : ") . $rs->feed_url; $content .= "\n" . T_("Last checked timestamp : ") . $last_checked; $content .= "\n" . T_("Website : ") . $rs->site_url; if (!sendmail($from, $to, $subject, $content, 'normal', $reply_to)) { $log_msg = logMsg(T_("Email alert could not be send")); if ($print) { $output .= $log_msg; } } else { $log_msg = logMsg(T_("Feed disabled and email alert sent !")); if ($print) { $output .= $log_msg; } } } } } # fin du while # Duree de la mise a jour $fin = explode(" ", microtime()); $fin = $fin[1] + $fin[0]; $temps_passe = round($fin - $debut, 2); $log_msg = logMsg("{$cpt} articles mis a jour en {$temps_passe} secondes", "", 2, $print); if ($print) { $output .= $log_msg; } return $output; }
function fof_update_feed($url) { global $FOF_FEED_TABLE; # # Get feed data. # if (!$url) { return 0; } if (!empty($url)) { $piefeed = new SimplePie(); $piefeed->set_feed_url($url); } else { return 0; } $piefeed->set_cache_location(FOF_CACHE_DIR); // echo "Memory usage after set cache: " . number_format(memory_get_usage()); $piefeed->init(); //echo "Memory usage after set init: " . number_format(memory_get_usage()); $piefeed->handle_content_type(); //echo "Memory usage after contenttype: " . number_format(memory_get_usage()); if (!$piefeed->data) { //print "<font color=\"red\">" . _("error was") . "</font>: <B>" . $piefeed->error . "</b> "; //print "<a href=\"http://feedvalidator.org/check?url=$url\">" . _("try to validate it?") . "</a> "; //unset($piefeed); $piefeed->__destruct(); // Do what PHP should be doing on it's own. return 0; } $title = $piefeed->get_title(); $link = $piefeed->get_link(); $description = $piefeed->get_description(); $safeurl = mysql_escape_string($url); $result = fof_do_query("select id, url, aging from feeds where url='{$safeurl}'"); $row = mysql_fetch_array($result); mysql_free_result($result); // echo "Memory usage after first query: " . number_format(memory_get_usage()); $feed_id = $row['id']; $keep_days = $row['aging']; if ($keep_days < 0) { $keep_days = 60; } // $result2 = fof_do_query("select image from feeds where `id`='$feed_id'"); // $row2 = mysql_fetch_array($result2); // mysql_free_result($result); //echo "Memory usage after second query: " . number_format(memory_get_usage()); // $image2 = $row2['image']; /* if (!$image2) { $imagelink = $piefeed->get_favicon(true, ''); $HTTPRequest = @fopen($imagelink, 'r'); if ($HTTPRequest) { stream_set_timeout($HTTPRequest, 0.1); $favicon = fread($HTTPRequest, 8192); $HTTPRequestData = stream_get_meta_data($HTTPRequest); fclose($HTTPRequest); if (!$HTTPRequestData['timed_out'] && strlen($favicon) < 42) { $imagelink = ""; } } else { $imagelink = $piefeed->get_image_url(); $HTTPRequest = @fopen($imagelink, 'r'); if ($HTTPRequest) { stream_set_timeout($HTTPRequest, 0.1); $favicon = fread($HTTPRequest, 8192); $HTTPRequestData = stream_get_meta_data($HTTPRequest); fclose($HTTPRequest); if (!$HTTPRequestData['timed_out'] && strlen($favicon) < 42) { $imagelink = ""; } } else { $imagelink=""; } } $sql = "update `$FOF_FEED_TABLE` set `image`='$imagelink' where `id`='$feed_id'"; $result = fof_do_query($sql); mysql_free_result($result); } // closes image */ # # Get article items and attributes # foreach ($piefeed->get_items() as $item) { $ageflag = "0"; $dccreator = ""; $dcsubject = ""; $link = mysql_escape_string($item->get_permalink()); if (!$link) { $link = $item->get_id(); } $title = mysql_escape_string($item->get_title()); if (!$title) { $title = "[" . _("no title") . "]"; } # get <dc:creator> or <author> foreach ($item->get_authors() as $author) { $authorname = $author->get_name() . " " . $author->get_email(); if (!empty($authorname)) { $dccreator .= $authorname . ', '; } } $dccreator = mysql_escape_string(substr("{$dccreator}", 0, -2)); # get <dc:date> and <pubdate> $dcdate = mysql_escape_string($item->get_date()); $dcdate = eregi_replace(",", "", $dcdate); # get <dc:subject> or <category> $category_array = $item->get_category(); $category_array = array_unique($category_array); foreach ($category_array as $category) { if (!empty($category)) { $dcsubject .= $category . ', '; } } $dcsubject = substr(mysql_escape_string($dcsubject), 0, -2); unset($category_array); # get article content $content = mysql_escape_string($item->get_description()); $content = str_replace('"?i=http', '"http', $content); # dont know why # this creeps in if ($enclosure = $item->get_enclosure(0)) { $content .= '<br />(' . $enclosure->get_type() . '; ' . $enclosure->get_size() . ' MB)<br />'; } # # Now manage the article data # $sql = "select id from items where feed_id='{$feed_id}' and link='{$link}'"; #print "<br />" . $sql . "<br />"; $result = fof_do_query($sql); $row = mysql_fetch_array($result); $id = $row['id']; //mysql_free_result($result); # if the item does not already exist, add it if (mysql_num_rows($result) == 0) { # dcdate : August 2, 2006, 1:30 am # timestamp: 2006-09-16 15:51:53 # add it only if it's not older than keep_days $dcdatetime = strtotime($dcdate); # We set ageflag == 1 if its OK to add the item to the database if ($dcdatetime < 1) { $dcdatetime = NULL; $ageflag = 1; } else { if (time() - $dcdatetime < $keep_days * 24 * 60 * 60) { $ageflag = 1; } } if ($ageflag) { //$n++; $sql = "insert into items (feed_id,link,title,content,dcdate,dccreator,dcsubject) values ('{$feed_id}','{$link}','{$title}','{$content}','{$dcdatetime}','{$dccreator}','{$dcsubject}')"; #print "<br />" . $sql . "<br />"; $result = fof_do_query($sql); mysql_free_result($result); $ids[] = $id; #keep track of it so we don't delete it below $ageflag = 0; } } //echo "Memory usage after item foreach loop: " . number_format(memory_get_usage()); } // closes opening foreach loop //unset($piefeed); $piefeed->__destruct(); // Do what PHP should be doing on it's own. //unset($item); //unset($feed); unset($title); unset($link); unset($description); unset($content); unset($dcdatetime); unset($dccreator); unset($dcsubject); //return $n; }