Jump to content

Recommended Posts

Hello all, I have an rss script that works fine on my test server but when I upload to a live server I get errors.

 

my test server is using php 5.2.1 and my live server is running php 4.4.6

 

here is the code:

rss_feeds.php

<?php

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 ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $result = curl_exec ($ch);
       curl_close($ch);
       return $result;
  
	}
}


?>

 

rss_feedlist.php

<?php
/*
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);
}

?>

 

on my test server this works fine. on my live server I get an 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

 

any help is appreciated, thank you

Link to comment
https://forums.phpfreaks.com/topic/49949-php-version-help/
Share on other sites

code as it is now (this site wont allow edits so I must create new post :( )

 

rss_feeds.php

<?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 __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++;
			}
		}
var static function curl_string ($url,$user_agent='Mozilla 4.0'){

       $ch = curl_init();

       curl_setopt ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $result = curl_exec ($ch);
       curl_close($ch);
       return $result;
  
	}
}


?>

 

with these changes I get a new error:

 

Parse error: syntax error, unexpected T_STATIC, expecting T_VARIABLE in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 106

 

Link to comment
https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245896
Share on other sites

try this...

 

 


rss_feeds.php

<?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 __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++;
			}
		}

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

       $ch = curl_init();

       curl_setopt ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $result = curl_exec ($ch);
       curl_close($ch);
       return $result;
  
	}
}


?>

 

Link to comment
https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245900
Share on other sites

great so far so good. I got no errors however the feeds are not showing up... the feeds are in another php file called feedlist.php

 

after changing (there was only one) self:: to $this->

 

So I am wondering if I should combine the feeds and feedlist php's into 1 php file.

Link to comment
https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245912
Share on other sites

Well unfortunatly I must return to this issue as moving is now not an option for us at this time.

 

A re glimps of what has aspired thus far.

 

I have a script that is written in php 5 and I need some help in re writing it for php 4.

 

The original code is:

rss_feeds.php

<?php

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 ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $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:

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)

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.

 

there are 2 more files that go with this:

 

rss_feedlist.php

<?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

Link to comment
https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-247968
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.