Results 1 to 17 of 17

Thread: Help convert this code from php5 to php4

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Exclamation Help convert this code from php5 to php4

    My current host refuses to upgrade to php 5 so I am stuck (for the time being) on php 4.

    My test server is php 5 but my live server is php 4 so the code I got will not work as it delivers error after error.
    Please help. Thank you

    The original code is:
    rss_feeds.php

    PHP Code:
    <?php
    // rss_feeds.php written by Static & Penagate @ http://staticfx.com 
    // this file goes in the /bb3portal/block/ directory 

    class OnlyHellRssFeed {
        
        private 
    $nr_news=10;
        private 
    $rss_channel = array();
        private 
    $currently_writing "";
        private 
    $main "";
        private 
    $item_counter 0;
        private 
    $template;
        private 
    $feedname;
        private 
    $url;

        function 
    __construct($feedname$url) {
          
    $this->feedname $feedname;
          
    $this->url $url;
        }
        
        function 
    startElement($parser$name$attrs) {
               switch(
    $name) {
                   case 
    "RSS":
                   case 
    "RDF:RDF":
                   case 
    "ITEMS":
                       
    $this->currently_writing "";
                       break;
                   case 
    "CHANNEL":
                       
    $this->main "CHANNEL";
                       break;
                   case 
    "IMAGE":
                       
    $this->main "IMAGE";
                       
    $this->rss_channel["IMAGE"] = array();
                       break;
                   case 
    "ITEM":
                       
    $this->main "ITEMS";
                       break;
                   default:
                       
    $this->currently_writing $name;
                       break;
               }
        }
        
        function 
    endElement($parser$name) {
               
    $this->currently_writing "";
               if (
    $name == "ITEM") {
                   
    $this->item_counter++;
               }
        }
        
        function 
    characterData($parser$data) {
            if (
    $this->currently_writing != "") {
                switch(
    $this->main) {
                    case 
    "ITEMS":
                        if (isset(
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) {
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data;
                        } else {
                            
    //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>");
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data;
                        }
                        break;
                }
            }
        }
        
        function 
    get_data(&$template) {
                    
    $xml_parser xml_parser_create();
                    
    xml_set_element_handler
                      
    $xml_parser
                      array(
    $this'startElement'), 
                      array(
    $this'endElement'
                    ); 
                    
    xml_set_character_data_handler
                      
    $xml_parser
                      array(
    $this'characterData'
                    ); 
                    
                    
    $data self::curl_string($this->url);
                    
    xml_parse($xml_parser,$data);
                    
    xml_parser_free($xml_parser);
                    
                    
    // putting in array
                    
    $news=array();
                    if (isset(
    $this->rss_channel["ITEMS"])) 
                    {
                        if (
    count($this->rss_channel["ITEMS"]) > 0
                            for(
    $i 0;$i count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i];
                    }
                    
    $c=0;
                    
                    foreach(
    $news as $key=>$val)
                    {
                        if(
    $c<$this->nr_news)
                        {
                            
    $template->assign_block_vars($this->feedname, array(
                            
    'LINK' => $val['LINK'],
                            
    'TITLE' => $val['TITLE'],
                            
    'DESC' => $val['DESCRIPTION'])
                            );
                        }
                        
    $c++;
                    }
                }
        private static function 
    curl_string ($url,$user_agent='Mozilla 4.0'){

           
    $ch curl_init();

           
    curl_setopt ($chCURLOPT_URL$url);
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent);
           
    curl_setopt ($chCURLOPT_HEADER0);
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1);
           
    curl_setopt ($chCURLOPT_TIMEOUT120);
           
    $result curl_exec ($ch);
           
    curl_close($ch);
           return 
    $result;
      
            }
    }


    ?>
    This gave the error:
    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 9

    When I change:
    Code:
    	private $nr_news=10;
    	private $rss_channel = array();
    	private $currently_writing = "";
    	private $main = "";
    	private $item_counter = 0;
    	private $template;
    	private $feedname;
    	private $url;
    
    
    
    	private static function curl_string ($url,$user_agent='Mozilla 4.0'){
    to: (removing the "private" code)
    Code:
    	var $nr_news=10;
    	var $rss_channel = array();
    	var $currently_writing = "";
    	var $main = "";
    	var $item_counter = 0;
    	var $template;
    	var $feedname;
    	var $url;
    
    
    
    	var static function curl_string ($url,$user_agent='Mozilla 4.0'){
    Parse error: syntax error, unexpected T_STATIC, expecting T_VARIABLE in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 106

    It was then said to remove "var static" and leave only function curl_string

    the new error:
    Fatal error: Undefined class name 'self' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 80

    so I searched and found only 1 reference to self:: and changed it to $this->

    now I get no errors but the list is not showing up as it should in my block.

    Current code:

    PHP Code:
    <?php
    // rss_feeds.php written by Static & Penagate @ http://staticfx.com 
    // this file goes in the /bb3portal/block/ directory 


    class OnlyHellRssFeed 
         
        var 
    $nr_news=10
        var 
    $rss_channel = array(); 
        var 
    $currently_writing ""
        var 
    $main ""
        var 
    $item_counter 0
        var 
    $template
        var 
    $feedname
        var 
    $url

        function 
    OnlyHellRssFeed ($feedname$url) { 
          
    $this->feedname $feedname
          
    $this->url $url
        } 
         
        function 
    startElement($parser$name$attrs) { 
               switch(
    $name) { 
                   case 
    "RSS"
                   case 
    "RDF:RDF"
                   case 
    "ITEMS"
                       
    $this->currently_writing ""
                       break; 
                   case 
    "CHANNEL"
                       
    $this->main "CHANNEL"
                       break; 
                   case 
    "IMAGE"
                       
    $this->main "IMAGE"
                       
    $this->rss_channel["IMAGE"] = array(); 
                       break; 
                   case 
    "ITEM"
                       
    $this->main "ITEMS"
                       break; 
                   default: 
                       
    $this->currently_writing $name
                       break; 
               } 
        } 
         
        function 
    endElement($parser$name) { 
               
    $this->currently_writing ""
               if (
    $name == "ITEM") { 
                   
    $this->item_counter++; 
               } 
        } 
         
        function 
    characterData($parser$data) { 
            if (
    $this->currently_writing != "") { 
                switch(
    $this->main) { 
                    case 
    "ITEMS"
                        if (isset(
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { 
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data
                        } else { 
                            
    //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); 
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data
                        } 
                        break; 
                } 
            } 
        } 
         
        function 
    get_data(&$template) { 
                    
    $xml_parser xml_parser_create(); 
                    
    xml_set_element_handler(  
                      
    $xml_parser,  
                      array(
    $this'startElement'),  
                      array(
    $this'endElement')  
                    );  
                    
    xml_set_character_data_handler(  
                      
    $xml_parser,  
                      array(
    $this'characterData')  
                    );  
                     
                    
    $data $this->curl_string($this->url); 
                    
    xml_parse($xml_parser,$data); 
                    
    xml_parser_free($xml_parser); 
                     
                    
    // putting in array 
                    
    $news=array(); 
                    if (isset(
    $this->rss_channel["ITEMS"]))  
                    { 
                        if (
    count($this->rss_channel["ITEMS"]) > 0)  
                            for(
    $i 0;$i count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; 
                    } 
                    
    $c=0
                     
                    foreach(
    $news as $key=>$val
                    { 
                        if(
    $c<$this->nr_news
                        { 
                            
    $template->assign_block_vars($this->feedname, array( 
                            
    'LINK' => $val['LINK'], 
                            
    'TITLE' => $val['TITLE'], 
                            
    'DESC' => $val['DESCRIPTION']) 
                            ); 
                        } 
                        
    $c++; 
                    } 
                } 
        function 
    curl_string ($url,$user_agent='Mozilla 4.0'){ 

           
    $ch curl_init(); 

           
    curl_setopt ($chCURLOPT_URL$url); 
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent); 
           
    curl_setopt ($chCURLOPT_HEADER0); 
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1); 
           
    curl_setopt ($chCURLOPT_TIMEOUT120); 
           
    $result curl_exec ($ch); 
           
    curl_close($ch); 
           return 
    $result
       
            } 



    ?>
    there are 2 more files that go with this:

    rss_feedlist.php

    PHP Code:
    <?php

    $feeds 
    = array(
        
    'mtgbks'      => 'http://www.wizards.com/rss.asp?x=books',
        
    'mtgdnd'      => 'http://www.wizards.com/rss.asp?x=dnd',
        
    'mtgd20'      => 'http://www.wizards.com/rss.asp?x=d20modern',
        
    'mtgebr'      => 'http://www.wizards.com/rss.asp?x=eberron',
        
    'mtgfr'      => 'http://www.wizards.com/rss.asp?x=forgottenrealms',
        
    'mtgmtg'      => 'http://www.wizards.com/rss.asp?x=magic',
        
    'mtgswrpg' => 'http://www.wizards.com/rss.asp?x=starwars-rpg',
        );    
    foreach (
    $feeds as $feed_name => $url) {
      
    $feed = new OnlyHellRssFeed($feed_name$url);
        
    $feed->get_data($template);
        }

    ?>
    and rss_feeds.html which is the output page.


    if you could please look closley at this code and help with a rewrite for php 4 I would be gratly appreciative.
    Thank you

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Help convert this code from php5 to php4

    i am not sure, but i dont think any one will convert your code.

    Have you tried using the cod eyou have on your new server?
    Last edited by penagate; May 10th, 2007 at 11:28 PM.
    My usual boring signature: Something

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    All of the code you see here (original code) is on my test server. but when I upload it I get the errors mentioned above.

    I had changed some code as I new what some of the issues were and with help of the original creator of this code was able to get where it is now.

    The code I am using now still works on my test server but when I upload it I get the block with the tabs but the feeds do not appear.

    I believe it is in the curl code:
    PHP Code:
        function curl_string ($url,$user_agent='Mozilla 4.0'){  

           
    $ch curl_init();  

           
    curl_setopt ($chCURLOPT_URL$url);  
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent);  
           
    curl_setopt ($chCURLOPT_HEADER0);  
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);  
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1);  
           
    curl_setopt ($chCURLOPT_TIMEOUT120);  
           
    $result curl_exec ($ch);  
           
    curl_close($ch);  
           return 
    $result;  
        
            }  

    Originally
    PHP Code:
    private static function curl_string ($url,$user_agent='Mozilla 4.0'){ 

           
    $ch curl_init(); 

           
    curl_setopt ($chCURLOPT_URL$url); 
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent); 
           
    curl_setopt ($chCURLOPT_HEADER0); 
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1); 
           
    curl_setopt ($chCURLOPT_TIMEOUT120); 
           
    $result curl_exec ($ch); 
           
    curl_close($ch); 
           return 
    $result
       
            } 


  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help convert this code from php5 to php4

    I believe what fails is the member function reference in get_data().
    There is a comment to the documentation that may help. Try:
    PHP Code:
    $xml_parser xml_parser_create(); 
    xml_set_object($xml_parser, &$this);
    xml_set_element_handler($parser'startElement''endElement');
    xml_set_character_data_handler($parser'characterData'); 

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    HI, this is what I have:

    Code:
    function get_data($template) { 
                    $xml_parser = xml_parser_create(); 
                    xml_set_element_handler(  
                      $xml_parser,  
                      array($this, 'startElement'),  
                      array($this, 'endElement')  
                    );  
                    xml_set_character_data_handler(  
                      $xml_parser,  
                      array($this, 'characterData')  
                    );  
                     
                    $data = $this->curl_string($this->url); 
                    xml_parse($xml_parser,$data); 
                    xml_parser_free($xml_parser);
    Do I replace everything in there or just this:
    Code:
    $xml_parser = xml_parser_create(); 
                    xml_set_element_handler(  
                      $xml_parser,  
                      array($this, 'startElement'),  
                      array($this, 'endElement')  
                    );  
                    xml_set_character_data_handler(  
                      $xml_parser,  
                      array($this, 'characterData')  
                    );

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help convert this code from php5 to php4

    Just the second part.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    Made this change
    PHP Code:
        function get_data($template) {
                    
            
    $xml_parser xml_parser_create();  
                               
    xml_set_object($xml_parser, &$this); 
    **
    70          xml_set_element_handler($parser'startElement''endElement'); 
    **
    71            xml_set_character_data_handler($parser'characterData');  

    /*                $xml_parser = xml_parser_create(); 
                    xml_set_element_handler(  
                      $xml_parser,  
                      array($this, 'startElement'),  
                      array($this, 'endElement')  
                    );  
                    xml_set_character_data_handler(  
                      $xml_parser,  
                      array($this, 'characterData')  
                    );  
      */ 
    Get this error

    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 70: xml_set_element_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 71: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3724: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3726: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3727: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3728: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    Last edited by caspert_ghost; May 11th, 2007 at 03:12 AM. Reason: made note of the line numbers

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help convert this code from php5 to php4

    Typo. It should be $xml_parser, not $parser.

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    I figured as much so changed it, now back to square 1... everything works on test server but live server still no feeds.

  10. #10

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    PHP Code:
                    $data self::curl_string($this->url); 
                    
    xml_parse($xml_parser,$data); 
                    
    xml_parser_free($xml_parser); 

       private static function 
    curl_string ($url,$user_agent='Mozilla 4.0'){ 

           
    $ch curl_init(); 

           
    curl_setopt ($chCURLOPT_URL$url); 
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent); 
           
    curl_setopt ($chCURLOPT_HEADER0); 
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1); 
           
    curl_setopt ($chCURLOPT_TIMEOUT120); 
           
    $result curl_exec ($ch); 
           
    curl_close($ch); 
           return 
    $result
       
            } 

    changed to
    PHP Code:
                    $data $this->curl_string($this->url);  
                    
    xml_parse($xml_parser,$data);  
                    
    xml_parser_free($xml_parser);  

        function 
    curl_string ($url,$user_agent='Mozilla 4.0'){  

           
    $ch curl_init();  

           
    curl_setopt ($chCURLOPT_URL$url);  
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent);  
           
    curl_setopt ($chCURLOPT_HEADER0);  
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);  
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1);  
           
    curl_setopt ($chCURLOPT_TIMEOUT120);  
           
    $result curl_exec ($ch);  
           
    curl_close($ch);  
           return 
    $result;  
        
            }  

    would this change mean anything to you?? it was changed due to a php 4 self:: error changed to $this->

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help convert this code from php5 to php4

    I don't see anything immediately wrong with the code.

    Place this statement at the top of it and see if any messages are produced.

    PHP Code:
    error_reporting(E_ALL); 

  12. #12

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    WOW

    I put that code at the top of the script and get this:

    Code:
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /bb3portal/block/rss_feeds.php on line 105: Undefined index: DESCRIPTION
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3724: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3726: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3727: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)
    [phpBB Debug] PHP Notice: in file /includes/functions.php on line 3728: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3264)

  13. #13

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    What I have now:
    PHP Code:
    <?php
    // rss_feeds.php written by Static & Penagate @ http://staticfx.com 
    // this file goes in the /bb3portal/block/ directory 


    class OnlyHellRssFeed 
         
        var 
    $nr_news=10
        var 
    $rss_channel = array(); 
        var 
    $currently_writing ""
        var 
    $main ""
        var 
    $item_counter 0
        var 
    $template
        var 
    $feedname
        var 
    $url

        function 
    OnlyHellRssFeed ($feedname$url) { 
          
    $this->feedname $feedname
          
    $this->url $url
        } 
         
        function 
    startElement($parser$name$attrs) { 
               switch(
    $name) { 
                   case 
    "RSS"
                   case 
    "RDF:RDF"
                   case 
    "ITEMS"
                       
    $this->currently_writing ""
                       break; 
                   case 
    "CHANNEL"
                       
    $this->main "CHANNEL"
                       break; 
                   case 
    "IMAGE"
                       
    $this->main "IMAGE"
                       
    $this->rss_channel["IMAGE"] = array(); 
                       break; 
                   case 
    "ITEM"
                       
    $this->main "ITEMS"
                       break; 
                   default: 
                       
    $this->currently_writing $name
                       break; 
               } 
        } 
         
        function 
    endElement($parser$name) { 
               
    $this->currently_writing ""
               if (
    $name == "ITEM") { 
                   
    $this->item_counter++; 
               } 
        } 
         
        function 
    characterData($parser$data) { 
            if (
    $this->currently_writing != "") { 
                switch(
    $this->main) { 
                    case 
    "ITEMS"
                        if (isset(
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { 
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data
                        } else { 
                            
    //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); 
                            
    $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data
                        } 
                        break; 
                } 
            } 
        } 
         
        function 
    get_data($template) {
                    
        
    $xml_parser xml_parser_create();  
        
    xml_set_object($xml_parser, &$this); 
        
    xml_set_element_handler($xml_parser'startElement''endElement'); 
        
    xml_set_character_data_handler($xml_parser'characterData');  

    /*                $xml_parser = xml_parser_create(); 
                    xml_set_element_handler(  
                      $xml_parser,  
                      array($this, 'startElement'),  
                      array($this, 'endElement')  
                    );  
                    xml_set_character_data_handler(  
                      $xml_parser,  
                      array($this, 'characterData')  
                    );  
      */                                              
                    
    $data $this->curl_string($this->url); 
                    
    xml_parse($xml_parser,$data); 
                    
    xml_parser_free($xml_parser); 
                     
                    
    // putting in array 
                    
    $news=array(); 
                    if (isset(
    $this->rss_channel["ITEMS"]))  
                    { 
                        if (
    count($this->rss_channel["ITEMS"]) > 0)  
                            for(
    $i 0;$i count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; 
                    } 
                    
    $c=0
                     
                    foreach(
    $news as $key=>$val
                    { 
                        if(
    $c<$this->nr_news
                        { 
                            
    $template->assign_block_vars($this->feedname, array( 
                            
    'LINK' => $val['LINK'], 
                            
    'TITLE' => $val['TITLE'],
                           
    'DESC' => $val['DESCRIPTION']) 
                            );                    
                         } 
                        
    $c++; 
                    } 
                } 
        
        function 
    curl_string ($url,$user_agent='Mozilla 4.0'){

           
    $ch curl_init(); 

           
    curl_setopt ($chCURLOPT_URL$url); 
           
    curl_setopt ($chCURLOPT_USERAGENT$user_agent); 
           
    curl_setopt ($chCURLOPT_HEADER0); 
           
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
           
    curl_setopt ($chCURLOPT_FOLLOWLOCATION1); 
           
    curl_setopt ($chCURLOPT_TIMEOUT120); 
           
    $result curl_exec ($ch); 
           
    curl_close($ch); 
           return 
    $result
       
            } 



    ?>
    and feedlist
    PHP Code:
    <?php
    // rss_feeds.php written by Static & Penagate @ http://staticfx.com 
    // this file goes in the /bb3portal/block/ directory 
    /*
    setup:
    'variablename' => 'RSS URL'
    example:
    'oneup' => 'http://www.1up.com/rss?x=1',
    the variable name is used in the html file to loop thru and create the data,
    take a look at the first feed in the rss_feeds.html file - see how ign is used

    */

    $feeds = array(
        
    'mtgbks'    => 'http://www.wizards.com/rss.asp?x=books',
        
    'mtgdnd'    => 'http://www.wizards.com/rss.asp?x=dnd',
        
    'mtgd20'    => 'http://www.wizards.com/rss.asp?x=d20modern',
        
    'mtgebr'    => 'http://www.wizards.com/rss.asp?x=eberron',
        
    'mtgfr'        => 'http://www.wizards.com/rss.asp?x=forgottenrealms',
        
    'mtgmtg'    => 'http://www.wizards.com/rss.asp?x=magic',
        
    'mtgswrpg'    => 'http://www.wizards.com/rss.asp?x=starwars-rpg',
        );    
    foreach (
    $feeds as $feed_name => $url) {
      
    $feed = new OnlyHellRssFeed($feed_name$url);
        
    $feed->get_data($template);
        }

    ?>
    Last edited by caspert_ghost; May 11th, 2007 at 05:03 AM.

  14. #14
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Help convert this code from php5 to php4

    Bingo, you are very close. the issue is the RSS feeds dont have "descriptions"

    so change

    PHP Code:
    $template->assign_block_vars($this->feedname, array(  
                            
    'LINK' => $val['LINK'],  
                            
    'TITLE' => $val['TITLE'], 
                           
    'DESC' => $val['DESCRIPTION'])  
                            ); 
    to this:
    PHP Code:
    $template->assign_block_vars($this->feedname, array(
    'LINK' => isset($val['LINK']) ? $val['LINK'] : '',
    'TITLE' => isset($val['TITLE']) ? $val['TITLE'] : '',
    'DESC' => isset($val['DESCRIPTION']) ? $val['DESCRIPTION'] : '')
    ); 
    that happens occasionally with mine.. if the feed screws up, it screwed everything up. using the isset will test if its there, if not, it will just use ''

    let me know
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  15. #15
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Help convert this code from php5 to php4

    Another little change:
    PHP Code:
    curl_setopt ($chCURLOPT_TIMEOUT120); 
    change the 120 to ... like 15 or 20. 120 seconds is much to long. i use 10 on mine and it works like a charm (I mustve given u and older copy.. sorry)

    Actually, here is another issue... those RSS feeds dont seem to work.
    I put every url in, and got nothing. It just sits there...loading... it should be almost instant.

    Like take a look at this. IGN has a DnD vault...

    http://dndvault.ign.com/show_rss.php

    the XML shows instantly....
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  16. #16

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    Made the above changes and still just the tabs.
    added: error_reporting(E_ALL); to the top...
    no errors and still no feeds

  17. #17

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    11

    Re: Help convert this code from php5 to php4

    I will test another feed tomorrow see if that is the problem...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width