Welcome to Geeklog, Anonymous Sunday, January 05 2025 @ 02:06 am EST

Geeklog Forums

RSS + DreamHost + cURL = No Work


satburn

Anonymous
I noticed an earlier thread regarding this however did not see an answer posted. I'm trying to mod the lib-common.php file to use cURL to capture an RSS feed instead of fopen. Below is what I have so far. PHP is not my native language so be kind as I'm just learning... Embarassed Although this does not display an error on my site, I only receive

"There was a problem reading this feed (see error.log for details)."

and that leads to an entry which states:

"Sun Jul 10 21:51:34 2005 - The feed at http://slashdot.org/rss/slashdot.rss exists but is currently empty."

Which it is not. Any help would be greatly appreciated. Can someone help me

Running: PHP Version 4.3.10 and Geeklog 1.3.11sr1

Text Formatted Code
// +---------------------------------------------------------------------------+
// | Old fopen statement modified to support curl function for DreamHost.      |
// |                                                                           |
// | if( $fp = @fopen( $rdfurl, 'r' ))                                         |
// +---------------------------------------------------------------------------+

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $rdfurl);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
    if( $fp = curl_exec($ch))
 
    {
        $startoffeed = true;
// +---------------------------------------------------------------------------+
// | Old fread statement modified to support curl function for DreamHost.      |
// |                                                                           |
// | while( $data = fread( $fp, 4096 ))                                        |
// +---------------------------------------------------------------------------+
        while( $data = $fp )
        {
            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 );
        }

// +---------------------------------------------------------------------------+
// | Old fclose statement modified to support curl function for DreamHost.     |
// |                                                                           |
// | fclose( $fp );                                                            |
// +---------------------------------------------------------------------------+

    curl_close($ch);
 
 Quote

satburn

Anonymous
Well after hacking away at it for a while I did finally manage to make it work. I ended up changing the COM_rdfImport function a bit and it seems to be working correctly. Not sure yet if I'm going to break anything else down the road, although the existing code seems pretty robust.

For anybody using DreamHost or other webhost that has disallowed 'url fopen' here's what I did. Keep in mind PHP isn't my cup of tea and anybody with PHP experience please feel free to comment.

praying it will work

Text Formatted Code
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' );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $rdfurl);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
    if( $data = curl_exec($ch) )

    {
        $startoffeed = true;

            if( !xml_parse( $xml_parser, $data ))
            {
                $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 );
            }

        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 );
        }

        xml_parser_free( $xml_parser );
        curl_close($ch);

        if( !$rdferror )
        {
            if( $maxheadlines > 0 )
            {
                $RDFheadlines = array_slice( $RDFheadlines, 0, $maxheadlines );
            }
            $blockcontent = COM_makeList( $RDFheadlines, 'list-feed' );
            $RDFheadlines = array();
            $blockcontent = preg_replace( "/(1512)|(15)|(12)/", '',
                                          $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 );
    }
}

 
 Quote

All times are EST. The time is now 02:06 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content