[geeklog-cvs] geeklog-1.3/public_html lib-common.php,1.411,1.412
dhaun at iowaoutdoors.org
dhaun at iowaoutdoors.org
Sun Jan 23 06:07:20 EST 2005
Update of /var/cvs/geeklog-1.3/public_html
In directory www:/tmp/cvs-serv31343/public_html
Modified Files:
lib-common.php
Log Message:
Incorporated new framework for reading and writing feeds (RSS, RDF, Atom), provided by Michael Jervis.
Index: lib-common.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.411
retrieving revision 1.412
diff -C2 -d -r1.411 -r1.412
*** lib-common.php 21 Jan 2005 23:31:44 -0000 1.411
--- lib-common.php 23 Jan 2005 11:07:18 -0000 1.412
***************
*** 3248,3252 ****
if( $A['type'] == 'portal' )
{
! if( COM_rdfCheck( $A['bid'], $A['rdfurl'], $A['date'] ))
{
$A['content'] = DB_getItem( $_TABLES['blocks'], 'content',
--- 3248,3252 ----
if( $A['type'] == 'portal' )
{
! if( COM_rdfCheck( $A['bid'], $A['rdfurl'], $A['date'], $A['rdflimit'] ))
{
$A['content'] = DB_getItem( $_TABLES['blocks'], 'content',
***************
*** 3317,3328 ****
* Updates RDF/RSS block if needed
*
! * @param string $bid Block ID
! * @param string $rdfurl URL to get headlines from
! * @param string $date Last time the headlines were imported
! * @see function COM_rdfImport
* @return void
*/
!
! function COM_rdfCheck( $bid, $rdfurl, $date )
{
$retval = false;
--- 3317,3329 ----
* Updates RDF/RSS block if needed
*
! * @param string $bid Block ID
! * @param string $rdfurl URL to get headlines from
! * @param string $date Last time the headlines were imported
! * @param string $maxheadlines max. number of headlines to import
* @return void
+ * @see function COM_rdfImport
+ *
*/
! function COM_rdfCheck( $bid, $rdfurl, $date, $maxheadlines = 0 )
{
$retval = false;
***************
*** 3331,3335 ****
if( $nextupdate < time() )
{
! COM_rdfImport( $bid, $rdfurl );
$retval = true;
}
--- 3332,3336 ----
if( $nextupdate < time() )
{
! COM_rdfImport( $bid, $rdfurl, $maxheadlines );
$retval = true;
}
***************
*** 3339,3514 ****
/**
! * Imports an RDF/RSS block
! *
! * This will pull content from another site and store it in the database
! * to be shown within a portal block
! *
! * new RDF parser provided by Roger Webster
*
! */
!
! $RDFinsideitem = false;
! $RDFtag = '';
! $RDFtitle = '';
! $RDFlink = '';
! $RDFheadlines = array();
!
! function COM_rdfStartElement( $parser, $name, $attrs )
! {
! global $RDFinsideitem, $RDFtag;
!
! if( $RDFinsideitem )
! {
! $RDFtag = $name;
! }
! elseif( $name == 'ITEM' )
! {
! $RDFinsideitem = true;
! }
! }
!
! function COM_rdfEndElement( $parser, $name )
! {
! global $RDFinsideitem, $RDFtag, $RDFtitle, $RDFlink, $RDFheadlines;
!
! if( $name == 'ITEM' )
! {
! $RDFtitle = str_replace( '$', '$', $RDFtitle );
! $RDFheadlines[] = '<a href="' . addslashes( trim( $RDFlink )) . '">' . addslashes( trim( $RDFtitle )) . '</a>';
! $RDFtitle = '';
! $RDFlink = '';
! $RDFinsideitem = false;
! }
! }
!
! function COM_rdfCharacterData( $parser, $data )
! {
! global $RDFinsideitem, $RDFtag, $RDFtitle, $RDFlink;
!
! if( $RDFinsideitem )
! {
! switch( $RDFtag )
! {
! case 'TITLE':
! $RDFtitle .= $data;
! break;
!
! case 'LINK':
! $RDFlink .= $data;
! break;
! }
! }
! }
!
! /**
! * This is the actual RDF parser (the above are just helper functions)
*
! * @param string $bid Block ID
! * @param string $rdfurl URL to get content from
* @see function COM_rdfCheck
*
*/
!
! function COM_rdfImport( $bid, $rdfurl )
{
! global $_CONF, $_TABLES, $LANG21,
! $RDFinsideitem, $RDFtag, $RDFtitle, $RDFlink, $RDFheadlines;
!
! $RDFinsideitem = false;
! $RDFtag = '';
! $RDFtitle = '';
! $RDFlink = '';
! $RDFheadlines = array();
!
! $maxheadlines = 0; // set to something > 0 to limit max. number of headlines
!
! $update = date( 'Y-m-d H:i:s' );
! $result = DB_change( $_TABLES['blocks'], 'rdfupdated', $update,
! 'bid', $bid );
! clearstatcache();
! $rdferror = false;
! $xml_parser = xml_parser_create();
! @xml_parser_set_option( $xml_parser, XML_OPTION_TARGET_ENCODING,
! $_CONF['default_charset'] );
! xml_set_element_handler( $xml_parser, 'COM_rdfStartElement',
! 'COM_rdfEndElement');
! xml_set_character_data_handler( $xml_parser, 'COM_rdfCharacterData' );
! if( $fp = @fopen( $rdfurl, 'r' ))
{
! $startoffeed = true;
! while( $data = fread( $fp, 4096 ))
{
! if( $startoffeed )
{
! $data = ltrim( $data );
! if( empty( $data ))
! {
! break;
! }
! $startoffeed = false;
}
! if( !xml_parse( $xml_parser, $data, feof( $fp )))
{
! $errmsg = sprintf(
! 'Parse error in %s: %s at line %d',
! $rdfurl,
! xml_error_string( xml_get_error_code( $xml_parser )),
! xml_get_current_line_number( $xml_parser )
! );
!
! COM_errorLog( $errmsg, 1 );
! $rdferror = true;
! $result = DB_change( $_TABLES['blocks'], 'content',
! addslashes( $LANG21[4] ), 'bid', $bid );
! break;
}
}
- if( $startoffeed && empty( $data ))
- {
- $errmsg = sprintf( 'The feed at %s exists but is currently empty.',
- $rdfurl );
- COM_errorLog( $errmsg, 1 );
- $rdferror = true;
- $result = DB_change( $_TABLES['blocks'], 'content',
- addslashes( $LANG21[4] ), 'bid', $bid );
- }
! fclose( $fp );
! xml_parser_free( $xml_parser );
! if( !$rdferror )
{
! if( $maxheadlines > 0 )
{
! $RDFheadlines = array_slice( $RDFheadlines, 0, $maxheadlines );
}
- $blockcontent = COM_makeList( $RDFheadlines, 'list-feed' );
- $RDFheadlines = array();
- $blockcontent = preg_replace( "/(\015\012)|(\015)|(\012)/", '',
- $blockcontent );
- $result = DB_change( $_TABLES['blocks'], 'content', $blockcontent,
- 'bid', $bid);
- }
- }
- else
- {
- $errmsg = sprintf( 'Geeklog can not reach the feed at %s.', $rdfurl );
! if( !@ini_get( 'allow_url_fopen' ))
! {
! $errmsg = 'Sorry, your webserver configuration does not allow reading of remote files (allow_url_fopen = off).';
}
! COM_errorLog( $errmsg, 1 );
! $rdferror = true;
$result = DB_change( $_TABLES['blocks'], 'content',
! addslashes( $LANG21[4] ), 'bid', $bid );
}
}
/**
* Returns what HTML is allowed in content
--- 3340,3425 ----
/**
! * Syndication import function. Imports headline data to a portal block.
*
! * Rewritten December 19th 2004 by Michael Jervis (mike at fuckingbrit.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' );
! // Load the actual feed handlers:
! $factory = new FeedParserFactory( $_CONF['path_system']
! . '/classes/syndication/' );
! $feed = $factory->reader( $rdfurl, $_CONF['default_charset'] );
! // Aquire a reader:
! 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' );
! $result = DB_change( $_TABLES['blocks'], 'rdfupdated', $update,
! 'bid', $bid );
! // format articles for display
! for( $i = 0; $i < $maxheadlines; $i++ )
{
! if( empty( $feed->articles[$i]['title'] ))
{
! $feed->articles[$i]['title'] = $LANG21[61];
}
! $content = '<a href="' . $feed->articles[$i]['link'] . '">'
! . $feed->articles[$i]['title'] . '</a>';
! $articles[] = $content;
}
! // build a list
! $content = COM_makeList( $articles );
! $content = preg_replace( "/(\015\012)|(\015)|(\012)/", '', $content );
+ // Standard theme based function to put it in the block
$result = DB_change( $_TABLES['blocks'], 'content',
! addslashes( $content ), 'bid', $bid );
! }
! else
! {
! // failed to aquire info, 0 out the block and log an error
! COM_errorLog( "Unable to aquire feed reader for $rdfurl", 1 );
! $result = DB_change( $_TABLES['blocks'], 'content',
! addslashes( $LANG21[4] ), 'bid', $bid );
}
}
+
/**
* Returns what HTML is allowed in content
***************
*** 5165,5172 ****
* from topics to which the user has access to.
*
! * @param string $type part of the SQL expr. e.g. 'WHERE', 'AND'
! * @param int $u_id user id or 0 = current user
! * @param string $table table name if ambiguous (e.g. in JOINs)
! * @return string SQL expression string (may be empty)
*
*/
--- 5076,5086 ----
* from topics to which the user has access to.
*
! * Note that this function does an SQL request, so you should cache
! * the resulting SQL expression if you need it more than once.
! *
! * @param string $type part of the SQL expr. e.g. 'WHERE', 'AND'
! * @param int $u_id user id or 0 = current user
! * @param string $table table name if ambiguous (e.g. in JOINs)
! * @return string SQL expression string (may be empty)
*
*/
More information about the geeklog-cvs
mailing list