1
SabineC
php script in block
  • 2004/2/26 1:47

  • SabineC

  • Just popping in

  • Posts: 6

  • Since: 2003/11/30


Hi, I would like to insert the news from www.golem.de on my site. Golem provides a php script for this - now I am not a programmer and I am not sure if I am doing what I should do.

I created a block - inserted the php-script, choose php-script in the options below the text window when creating the block.

The code I inserted is this:

*************************
<?
/*
// golemxml.php
//
// Version: 1.0.0
// Author: Soeren Fuhrmann - sf@golem.de
// Homepage:http://www.golem.de
//
// Based on: freshmeat.php3
// Version: 2.0.4
// Author: Kalle Kiviaho - kivi@chl.chalmers.se
// Lastmod: 2000-09-24
// Homepage:http://swamp.chl.chalmers.se/backends/
*/
// Customize as you like it

$link_prefix = "·&nbsp;";
$link_postfix = "<BR>\n";

$show_abstract = true;
$ab_link_prefix = "";
$ab_link_postfix = "<BR>\n";
$ab_prefix = "";
$ab_postfix = "<BR><BR>\n";
$ab_more = "[mehr...]";
$ab_more_prefix = "&nbsp;\n";

$cache_file = "/www/tmp/golem.de.cache";
$cache_time = 0;
$max_items = 10;
$max_readsize = 10000;
$target = "_top";

// End of customizations

$backend = "http://www.golem.de/golem_backend.xml";

$items = 0;
$time = split(" ", microtime());

srand((double)microtime()*1000000);
$cache_time_rnd = 300 - rand(0, 600);

if ( (!(file_exists($cache_file))) || ((filectime($cache_file) + $cache_time - $time[1]) + $cache_time_rnd < 0) || (!(filesize($cache_file))) ) {

$fpread = fopen($backend, 'r');
if(!$fpread) {
// echo "$errstr ($errno)<br>\n";
// exit;
} else {

$fpwrite = fopen($cache_file, 'w');
if(!$fpwrite) {
// echo "$errstr ($errno)<br>\n";
// exit;
} else {
$string = fread($fpread, $max_readsize);

$pattern = "/<ARTIKEL>(.*?)<\/ARTIKEL>/is";
if (preg_match_all($pattern, $string, $match, PREG_SET_ORDER))
for($i= 0; $i< min(count($match), $max_items); $i++){
$artikel= $match[$i][1];

$pattern = "/<HEADLINE>(.*?)<\/HEADLINE>/i";
preg_match($pattern, $artikel, $lmatch);
$title= $lmatch[1];

$pattern = "/<URL>(.*?)<\/URL>/i";
preg_match($pattern, $artikel, $lmatch);
$link= $lmatch[1];


if($items== 0 && $show_abstract){
$pattern = "/<ABSTRACT>(.*?)<\/ABSTRACT>/i";
preg_match($pattern, $artikel, $lmatch);
$abstract= $lmatch[1];

fputs($fpwrite, $ab_link_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$title."</A>".$ab_link_postfix);
fputs($fpwrite, $ab_prefix.$abstract.$ab_more_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$ab_more."</A>".$ab_postfix);
}else
fputs($fpwrite, $link_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$title."</A>".$link_postfix);

$items++;
}
}
fclose($fpread);
}
fclose($fpwrite);
}
if (file_exists($cache_file)) {
include($cache_file);
}
?>
***************************

now: is there something I am doing wrong? I don't understand, as when I test the script (http://www3.golem.de/golemxml.php) it works - when I insert it in the block it doesnt ... or should I just insert the above link in an i-frame window?

Thank you for any hint.

Best, Sabine

2
robekras
Re: php script in block
  • 2004/2/26 6:11

  • robekras

  • Documentation Writer

  • Posts: 187

  • Since: 2002/12/10


Remove the <? from the beginning
and the ?> from the end.

3
SabineC
Re: php script in block
  • 2004/2/28 12:34

  • SabineC

  • Just popping in

  • Posts: 6

  • Since: 2003/11/30


Thank you!!!

But I could not resolve - I tried also to modify some options like cache time, but it just doesn't work (below php Script is choosen).



Ciao, Sabine

4
Dave_L
Re: php script in block
  • 2004/2/28 13:21

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I would use Debugging Technique #1: "Print stuff out".

5
SabineC
Re: php script in block
  • 2004/3/3 8:36

  • SabineC

  • Just popping in

  • Posts: 6

  • Since: 2003/11/30


Dave, ehm, sorry, if I understand right, you are joking? Otherwise, what do you mean by print stuff out?

I am just getting mad with this, as normal additional blocks with html code work fine - this one just won't ... maybe I am somewhat unsymphathic to the script ....

6
Dave_L
Re: php script in block
  • 2004/3/3 14:35

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I wasn't joking.

If a script isn't working, and I can't find any obvious cause, I'll start inserting code to display variables to see what's going on internally.

For example:
var_dump('cache_file'$cache_file);
$ctime filectime($cache_file);
var_dump('ctime'$ctime);


Inserting an arbitrary PHP script into a block is tricky, because now it's running in a completely new environment.

Login

Who's Online

236 user(s) are online (156 user(s) are browsing Support Forums)


Members: 0


Guests: 236


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