1
EMSguy
php script in a block? not working
  • 2005/5/30 5:03

  • EMSguy

  • Just popping in

  • Posts: 86

  • Since: 2004/9/28


Hi all,

I am trtying to put some simple php in a block to call a newsfeed. Its not working. It works under HTML with javascript but not with php.

Did the developers put the "use php script option in a custom block" for future use? cause I cannot get PHP to work at all in a custom block.

Any thoughts?

2
hyperpod
Re: php script in a block? not working
  • 2005/5/30 5:30

  • hyperpod

  • Quite a regular

  • Posts: 359

  • Since: 2004/10/4


I do beleive you need to not include the < ?php and ? > tags.

And of course set content type to PHP.

Only PHP code can be put into this, since you cannot use the open and close PHP tags.


Hope that helps,

3
EMSguy
Re: php script in a block? not working
  • 2005/5/30 10:58

  • EMSguy

  • Just popping in

  • Posts: 86

  • Since: 2004/9/28


will try it thx

4
EMSguy
Re: php script in a block? not working
  • 2005/5/30 22:18

  • EMSguy

  • Just popping in

  • Posts: 86

  • Since: 2004/9/28


It still does not work when I add php code. I know the code works cause when I load up a script outside of the XOOPS environment it functions properly.

I am not including the //<?php// //?>// tags

5
ladon
Re: php script in a block? not working
  • 2005/5/30 22:31

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


Is it possible to show the code. Because I assure you the php-option hasn't been put in for future use, it actually works

6
EMSguy
Re: php script in a block? not working
  • 2005/5/30 22:36

  • EMSguy

  • Just popping in

  • Posts: 86

  • Since: 2004/9/28


Its a php include generated for a newsfeed since xhld is so horrible I have been tring to create my own rss parser but to no avail so this is my last option, in a block.

include_once('http://www.allheadlinenews.com/cgi-bin/news/account_news.cgi?account=yourname;feed=php;category=fire services;n=10;w=200;nb=yes');



Also I left out my username account=yourname.

7
EMSguy
Re: php script in a block? not working
  • 2005/6/1 22:24

  • EMSguy

  • Just popping in

  • Posts: 86

  • Since: 2004/9/28


well I guess no one has an answer to this? I will just assume that PHP in a block is a bug and was not meant to work properly with php.

8
Bassman
Re: php script in a block? not working
  • 2005/6/1 22:46

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


PHP in a block does work, please don't assume it doesn't just because you can't get it to work.There's any number of users who have it working fine.

What is the actual script you're using? Maybe we can work out why it's not working from that.

9
pod
Re: php script in a block? not working
  • 2005/6/2 0:10

  • pod

  • Quite a regular

  • Posts: 301

  • Since: 2003/4/19


try
include_once('cgi-bin/news/account_news.cgi?account=yourname;feed=php;category=fire services;n=10;w=200;nb=yes');


relative paths might do the trick.

10
Bassman
Re: php script in a block? not working
  • 2005/6/2 0:34

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


try this:
Quote:


/*
Created by Global Syndication's RSS Parser
http://www.globalsyndication.com/rss-parser
*/

set_time_limit(0);

$file = "http://www.allheadlinenews.com/cgi-bin/news/account_news.cgi?account=yourname;feed=php;category=fire services;n=10;w=200;nb=yes";

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}

function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}

function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);

// output HTML
print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");

if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
} else {
print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
}
print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); }
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
print ("<span style="font-size:xx-small;"><a href=\"http://www.globalsyndication.com/rss-parser\" style=\"color:white;\">Free PHP RSS Parser</a> - <a href=\"http://www.globalsyndication.com/rss-hosting\" style=\"color:white\">RSS Newsfeed Hosting</a></span>");

Login

Who's Online

206 user(s) are online (123 user(s) are browsing Support Forums)


Members: 0


Guests: 206


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits