/** * Update a feed. * Re-written by Michael Jervis (mike AT fuckingbrit DOT com) * to use the new architecture * * @param int $fid feed id * */ function SYND_updateFeed($fid) { global $_CONF, $_TABLES, $_SYND_DEBUG; SYND_fixCharset($fid); $result = DB_query("SELECT * FROM {$_TABLES['syndication']} WHERE fid = {$fid}"); $A = DB_fetchArray($result); if ($A['is_enabled'] == 1) { // Import the feed handling classes: require_once $_CONF['path_system'] . '/classes/syndication/parserfactory.class.php'; require_once $_CONF['path_system'] . '/classes/syndication/feedparserbase.class.php'; // Load the actual feed handlers: $factory = new FeedParserFactory($_CONF['path_system'] . '/classes/syndication/'); $format = explode('-', $A['format']); $feed = $factory->writer($format[0], $format[1]); if ($feed) { $feed->encoding = $A['charset']; $feed->lang = $A['language']; if ($A['type'] == 'article') { if ($A['topic'] == '::all') { $content = SYND_getFeedContentAll(false, $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid); } elseif ($A['topic'] == '::frontpage') { $content = SYND_getFeedContentAll(true, $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid); } else { // feed for a single topic only $content = SYND_getFeedContentPerTopic($A['topic'], $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid); } } else { $content = PLG_getFeedContent($A['type'], $fid, $link, $data, $format[0], $format[1]); // can't randomly change the api to send a max length, so // fix it here: if ($A['content_length'] != 1) { $count = count($content); for ($i = 0; $i < $count; $i++) { $content[$i]['summary'] = $A['content_length'] == 1 ? $content[$i]['text'] : COM_truncateHTML($content[$i]['text'], $A['content_length'], ' ...'); } } } if (empty($link)) { $link = $_CONF['site_url']; } $feed->title = $A['title']; $feed->description = $A['description']; if (empty($A['feedlogo'])) { $feed->feedlogo = ''; } else { $feed->feedlogo = $_CONF['site_url'] . $A['feedlogo']; } $feed->sitelink = $link; $feed->copyright = 'Copyright ' . strftime('%Y') . ' ' . $_CONF['site_name']; $feed->sitecontact = $_CONF['site_mail']; $feed->system = 'Geeklog'; /* Gather any other stuff */ $feed->namespaces = array_merge($feed->namespaces, PLG_getFeedNSExtensions($A['type'], $format[0], $format[1], $A['topic'], $fid)); /* If the feed is RSS, and trackback is enabled */ if ($_CONF['trackback_enabled'] && $format[0] == 'RSS') { /* Check to see if an article has trackbacks enabled, and if * at least one does, then include the trackback namespace: */ $trackbackenabled = false; foreach ($content as $item) { if (array_key_exists('extensions', $item) && array_key_exists('trackbacktag', $item['extensions'])) { // Found at least one article, with a trackbacktag // in it's extensions tag. $trackbackenabled = true; break; } } if ($trackbackenabled) { $feed->namespaces[] = 'xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"'; } } /* Inject the namespace for Atom into RSS feeds. Illogical? * Well apparantly not: * http://feedvalidator.org/docs/warning/MissingAtomSelfLink.html */ if ($format[0] == 'RSS') { $feed->namespaces[] = 'xmlns:atom="http://www.w3.org/2005/Atom"'; } if (!empty($A['filename'])) { $filename = $A['filename']; } else { $pos = strrpos($_CONF['rdf_file'], '/'); $filename = substr($_CONF['rdf_file'], $pos + 1); } $feed->url = SYND_getFeedUrl($filename); $feed->extensions = PLG_getFeedExtensionTags($A['type'], $format[0], $format[1], $A['topic'], $fid, $feed); /* Inject the self reference for Atom into RSS feeds. Illogical? * Well apparantly not: * http://feedvalidator.org/docs/warning/MissingAtomSelfLink.html */ if ($format[0] == 'RSS') { $feed->extensions[] = '<atom:link href="' . $feed->url . '" rel="self" type="application/rss+xml" />'; } $feed->articles = $content; $feed->createFeed(SYND_getFeedPath($filename)); } else { COM_errorLog("Unable to get a feed writer for {$format[0]} version {$format[1]}.", 1); } if (empty($data)) { $data = 'NULL'; } else { $data = "'" . $data . "'"; } if ($_SYND_DEBUG) { COM_errorLog("update_info for feed {$fid} is {$data}", 1); } DB_query("UPDATE {$_TABLES['syndication']} SET updated = NOW(), update_info = {$data} WHERE fid = {$fid}"); } }
/** * Syndication import function. Imports headline data to a portal block. * * Rewritten December 19th 2004 by Michael Jervis (mike AT fuckingbrit DOT com). * Now utilises a Factory Pattern to open a URL and automaticaly retreive a feed * object populated with feed data. Then import it into the portal block. * * @param string $bid Block ID * @param string $rdfurl URL to get content from * @param int $maxheadlines Maximum number of headlines to display * @return void * @see function COM_rdfCheck * */ function COM_rdfImport($bid, $rdfurl, $maxheadlines = 0) { global $_CONF, $_TABLES, $LANG21; // Import the feed handling classes: require_once $_CONF['path_system'] . '/classes/syndication/parserfactory.class.php'; require_once $_CONF['path_system'] . '/classes/syndication/feedparserbase.class.php'; $result = DB_query("SELECT rdf_last_modified, rdf_etag FROM {$_TABLES['blocks']} WHERE bid = {$bid}"); list($last_modified, $etag) = DB_fetchArray($result); // Load the actual feed handlers: $factory = new FeedParserFactory($_CONF['path_system'] . '/classes/syndication/'); $factory->userAgent = 'Geeklog/' . VERSION; if (!empty($last_modified) && !empty($etag)) { $factory->lastModified = $last_modified; $factory->eTag = $etag; } // Aquire a reader: $feed = $factory->reader($rdfurl, $_CONF['default_charset']); if ($feed) { /* We have located a reader, and populated it with the information from * the syndication file. Now we will sort out our display, and update * the block. */ if ($maxheadlines == 0) { if (!empty($_CONF['syndication_max_headlines'])) { $maxheadlines = $_CONF['syndication_max_headlines']; } else { $maxheadlines = count($feed->articles); } } $update = date('Y-m-d H:i:s'); $last_modified = ''; if (!empty($factory->lastModified)) { $last_modified = addslashes($factory->lastModified); } $etag = ''; if (!empty($factory->eTag)) { $etag = addslashes($factory->eTag); } if (empty($last_modified) || empty($etag)) { DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = '{$bid}'"); } else { DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = '{$last_modified}', rdf_etag = '{$etag}' WHERE bid = '{$bid}'"); } $charset = COM_getCharset(); // format articles for display $readmax = min($maxheadlines, count($feed->articles)); for ($i = 0; $i < $readmax; $i++) { if (empty($feed->articles[$i]['title'])) { $feed->articles[$i]['title'] = $LANG21[61]; } if ($charset == 'utf-8') { $title = $feed->articles[$i]['title']; } else { $title = utf8_decode($feed->articles[$i]['title']); } if ($feed->articles[$i]['link'] != '') { $content = COM_createLink($title, $feed->articles[$i]['link']); } elseif ($feed->articles[$i]['enclosureurl'] != '') { $content = COM_createLink($title, $feed->articles[$i]['enclosureurl']); } else { $content = $title; } $articles[] = $content; } // build a list $content = COM_makeList($articles, 'list-feed'); $content = str_replace(array("\r", "\n"), '', $content); if (strlen($content) > 65000) { $content = $LANG21[68]; } // Standard theme based function to put it in the block $result = DB_change($_TABLES['blocks'], 'content', addslashes($content), 'bid', $bid); } else { if ($factory->errorStatus !== false) { // failed to aquire info, 0 out the block and log an error COM_errorLog("Unable to aquire feed reader for {$rdfurl}", 1); COM_errorLog($factory->errorStatus[0] . ' ' . $factory->errorStatus[1] . ' ' . $factory->errorStatus[2]); $content = addslashes($LANG21[4]); DB_query("UPDATE {$_TABLES['blocks']} SET content = '{$content}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = {$bid}"); } } }
/** * Get a list of feed formats from the feed parser factory. * * @return array array of names of feed formats (and versions) * */ function find_feedFormats() { global $_CONF; // Import the feed handling classes: require_once $_CONF['path_system'] . '/classes/syndication/parserfactory.class.php'; $factory = new FeedParserFactory(); $formats = $factory->getFeedTypes(); sort($formats); return $formats; }