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 http://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 = "· ";
$link_postfix = "
\n";

$show_abstract = true;
$ab_link_prefix = "";
$ab_link_postfix = "
\n";
$ab_prefix = "";
$ab_postfix = "

\n";
$ab_more = "[mehr...]";
$ab_more_prefix = " \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)
\n";
// exit;
} else {

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

$pattern = "/(.*?)<\/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>/i";
preg_match($pattern, $artikel, $lmatch);
$title= $lmatch[1];

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


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

fputs($fpwrite, $ab_link_prefix."".$title."".$ab_link_postfix);
fputs($fpwrite, $ab_prefix.$abstract.$ab_more_prefix."".$ab_more."".$ab_postfix);
}else
fputs($fpwrite, $link_prefix."".$title."".$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 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

186 user(s) are online (56 user(s) are browsing Support Forums)


Members: 0


Guests: 186


more...

Donat-O-Meter

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

Latest GitHub Commits