/** * This method imports an OPML feed element. * * @param array $feed_elt an OPML element (must be a feed element). * @param string $parent_cat the name of the parent category. * @return boolean true if an error occured, false else. */ private function addFeedOpml($feed_elt, $parent_cat) { $default_cat = $this->catDAO->getDefault(); if (is_null($parent_cat)) { // This feed has no parent category so we get the default one $parent_cat = $default_cat->name(); } $cat = $this->catDAO->searchByName($parent_cat); if (is_null($cat)) { // If there is not $cat, it means parent category does not exist in // database. // If it happens, take the default category. $cat = $default_cat; } // We get different useful information $url = Minz_Helper::htmlspecialchars_utf8($feed_elt['xmlUrl']); $name = Minz_Helper::htmlspecialchars_utf8($feed_elt['text']); $website = ''; if (isset($feed_elt['htmlUrl'])) { $website = Minz_Helper::htmlspecialchars_utf8($feed_elt['htmlUrl']); } $description = ''; if (isset($feed_elt['description'])) { $description = Minz_Helper::htmlspecialchars_utf8($feed_elt['description']); } $error = false; try { // Create a Feed object and add it in DB $feed = new FreshRSS_Feed($url); $feed->_category($cat->id()); $feed->_name($name); $feed->_website($website); $feed->_description($description); // Call the extension hook $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed); if (!is_null($feed)) { // addFeedObject checks if feed is already in DB so nothing else to // check here $id = $this->feedDAO->addFeedObject($feed); $error = $id === false; } else { $error = true; } } catch (FreshRSS_Feed_Exception $e) { Minz_Log::warning($e->getMessage()); $error = true; } return $error; }
public static function daoToFeed($listDAO, $catID = null) { $list = array(); if (!is_array($listDAO)) { $listDAO = array($listDAO); } foreach ($listDAO as $key => $dao) { if (!isset($dao['name'])) { continue; } if (isset($dao['id'])) { $key = $dao['id']; } if ($catID === null) { $category = isset($dao['category']) ? $dao['category'] : 0; } else { $category = $catID; } $myFeed = new FreshRSS_Feed(isset($dao['url']) ? $dao['url'] : '', false); $myFeed->_category($category); $myFeed->_name($dao['name']); $myFeed->_website(isset($dao['website']) ? $dao['website'] : '', false); $myFeed->_description(isset($dao['description']) ? $dao['description'] : ''); $myFeed->_lastUpdate(isset($dao['lastupdate']) ? $dao['lastupdate'] : 0); $myFeed->_priority(isset($dao['priority']) ? $dao['priority'] : 10); $myFeed->_pathEntries(isset($dao['pathentries']) ? $dao['pathentries'] : ''); $myFeed->_httpAuth(isset($dao['httpauth']) ? base64_decode($dao['httpauth']) : ''); $myFeed->_error(isset($dao['error']) ? $dao['error'] === 't' ? true : false : 0); $myFeed->_keepHistory(isset($dao['keep_history']) ? $dao['keep_history'] : -2); $myFeed->_ttl(isset($dao['ttl']) ? $dao['ttl'] : -2); $myFeed->_nbNotRead(isset($dao['cache_nbunreads']) ? $dao['cache_nbunreads'] : 0); $myFeed->_nbEntries(isset($dao['cache_nbentries']) ? $dao['cache_nbentries'] : 0); if (isset($dao['id'])) { $myFeed->_id($dao['id']); } $list[$key] = $myFeed; } return $list; }
function getFeed($outline, $cat_id) { $url = (string) $outline['xmlUrl']; $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8'); $title = ''; if (isset($outline['text'])) { $title = (string) $outline['text']; } elseif (isset($outline['title'])) { $title = (string) $outline['title']; } $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $feed = new FreshRSS_Feed($url); $feed->_category($cat_id); $feed->_name($title); if (isset($outline['htmlUrl'])) { $feed->_website(htmlspecialchars((string) $outline['htmlUrl'], ENT_COMPAT, 'UTF-8')); } if (isset($outline['description'])) { $feed->_description(sanitizeHTML((string) $outline['description'])); } return $feed; }