Help with doing random news with PHP include

All new Coranto Addons, updates and patches to addons, will be released here...also, get support for addons within!

Moderators: Spunkmeyer, Dale Ray, SrNupsen, Bluetooth, Jackanape

Help with doing random news with PHP include

Postby Andross » Sun Feb 27, 2005 10:08 pm

I am trying to do a PHP include with the Random News 1.2, but apparently, I am doing the PHP code wrong, as I'm assuming that it doesn't recognize the string.

My code:
<?php include("coranto/viewnews.cgi?random&category=artwork"); ?>

I am putting it in my php page though. This isn't supposed to go somewhere else, is it? The documentation on these addons isn't good after all :/

I don't need anything but viewnews to run it as well, correct? And all news is supposed to go in there, right? Or do I have to tell Coranto somewhere to do that? So confused...

On a side note, it would be ideal if I could just pull a random news item from a certain PROFILE, rather than go through all this. Is this possible at all?

EDIT: If it helps, what I'm trying to do is a random image type thing, so when the page refreshes, a new image is there.
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Postby kriko » Sun Feb 27, 2005 11:03 pm

If viewnews supports that function, in which I am not very sure of you would want to use the following code since the one you gave doesn't work. ;)
Code: Select all
<?php include("http://www.sample.com/cgi-bin/coranto/viewnews.cgi?random&category=artwork"); ?>


Replace www.sample.com with your domain name.
Kristjan aka. kriko
now a wireless expert
User avatar
kriko
 
Posts: 3328
Joined: Sat Feb 24, 2007 8:13 pm

Re: Help with doing random news with PHP include

Postby Parahead » Mon Feb 28, 2005 12:42 pm

Andross wrote:My code:
<?php include("coranto/viewnews.cgi?random&category=artwork"); ?>
I don´t use PHP so I can´t tell you if the syntax is correct, but if you don´t have a / at the very begining of a path that path starts from the folder the file you have the above code in. WHAT? OK, an example, placing this code in a file in /path/to/folder1 will try and access viewnews.cgi at /path/to/folder1/coranto/viewnews.cgi, but if you place it in /another/folder you will try and execute viewnews.cgi at /another/folder/coranto/viewnews.cgi. Is this what you want? I would suggest using the absolute path, something like /cgi-bin/coranto/viewnews.cgi instead

I am putting it in my php page though. This isn't supposed to go somewhere else, is it? The documentation on these addons isn't good after all :/
You are *very* much free to contribute with documentation to any of the addons I am author of or any of the ones I am currently developing and I will see if I can include it into the next release of that addon. Covering all aspects of what a user might have problems with is hard with every single addon, so there are room for improvements. Also, if you are having problems with dialing a number on the phone, do you call the manufacturer of the phone or the phone company? In this case you have a problem with PHP, not the addon... ;-)

On a side note, it would be ideal if I could just pull a random news item from a certain PROFILE, rather than go through all this. Is this possible at all?
Nope, this isn´t possible with RandomNews currently, sorry...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Re: Help with doing random news with PHP include

Postby Andross » Mon Feb 28, 2005 11:47 pm

Parahead wrote:
Andross wrote:My code:
<?php include("coranto/viewnews.cgi?random&category=artwork"); ?>
I don´t use PHP so I can´t tell you if the syntax is correct, but if you don´t have a / at the very begining of a path that path starts from the folder the file you have the above code in. WHAT? OK, an example, placing this code in a file in /path/to/folder1 will try and access viewnews.cgi at /path/to/folder1/coranto/viewnews.cgi, but if you place it in /another/folder you will try and execute viewnews.cgi at /another/folder/coranto/viewnews.cgi. Is this what you want? I would suggest using the absolute path, something like /cgi-bin/coranto/viewnews.cgi instead

I'm not that much of a n00b w/servers and PHP, lol :P I already tried my absolute path, and wound up with the same result. I will try kriko's domain suggestion. If I continue to get problems, I'll give the precise error. If I also get some free time, I'll consider contributing to documentation. I'm only a kid in high school after all :P

Thanks for the help/suggestions. BTW, coranto isn't in the cgi-bin, though it would make no sense for it to give problems. Just another side-note.

EDIT: BAH! It didn't work! Absurd! Alright, here are specific errors I get.

When
Code: Select all
<?php include("coranto/viewnews.cgi?random&category=artwork"); ?>

is used, error returned is
Warning: main(coranto/viewnews.cgi?random&category=artwork): failed to open stream: No such file or directory in /usr/www/users/switchbd/andross/home.php on line 7

Warning: main(): Failed opening 'coranto/viewnews.cgi?random&category=artwork' for inclusion (include_path='.:/usr/local/lib/php') in /usr/www/users/switchbd/andross/home.php on line 7

When
Code: Select all
<?php include("/usr/www/users/switchbd/andross/coranto/viewnews.cgi?random&category=artwork"); ?>

is used, error returned is
Warning: main(/usr/www/users/switchbd/andross/coranto/viewnews.cgi?random&category=artwork): failed to open stream: No such file or directory in /usr/www/users/switchbd/andross/home.php on line 7

Warning: main(): Failed opening '/usr/www/users/switchbd/andross/coranto/viewnews.cgi?random&category=artwork' for inclusion (include_path='.:/usr/local/lib/php') in /usr/www/users/switchbd/andross/home.php on line 7


When
Code: Select all
<?php include("http://www.designrelief.com/andross/coranto/viewnews.cgi?random&category=artwork"); ?>

is used, error returned is
Warning: main(): URL file-access is disabled in the server configuration in /usr/www/users/switchbd/andross/home.php on line 7

Warning: main(http://www.designrelief.com/andross/cor ... ry=artwork): failed to open stream: no suitable wrapper could be found in /usr/www/users/switchbd/andross/home.php on line 7

Warning: main(): Failed opening 'http://www.designrelief.com/andross/coranto/viewnews.cgi?random&category=artwork' for inclusion (include_path='.:/usr/local/lib/php') in /usr/www/users/switchbd/andross/home.php on line 7


The category only has one item in it at the moment, and while I have no idea why this should affect anything, I'll upload some new stuff in Coranto and see if something happens.[/quote][/url]
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Postby bozoka45 » Tue Mar 01, 2005 4:59 am

Well, you want to use the domain method so that the processed viewnews.cgi is displayed, you don't want to include it via the root path.

It looks like by the error there is something on your server that needs to be configured, have you tried contacting your host?
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby Andross » Tue Mar 01, 2005 10:09 pm

HA! I think I have an answer. Random news is, for whatever reason, bugged/got bugged on upload. Here's what I see when I go to http://designrelief.com/andross/coranto ... cgi?random
Error
Addon Random (cra_randomnews.pl) caused an error. Error: Subroutine main:: was called, but does not exist. (It isn't already loaded, and it isn't in the cache.) at /usr/www/users/switchbd/andross/coranto/crcore.pl line 568.
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Postby Parahead » Wed Mar 02, 2005 9:33 am

Andross wrote:HA! I think I have an answer. Random news is, for whatever reason, bugged/got bugged on upload. Here's what I see when I go to http://designrelief.com/andross/coranto ... cgi?random
Error
Addon Random (cra_randomnews.pl) caused an error. Error: Subroutine main:: was called, but does not exist. (It isn't already loaded, and it isn't in the cache.) at /usr/www/users/switchbd/andross/coranto/crcore.pl line 568.
The errormessage printed out from the AUTOLOAD sub has bugged me for some time now, since it doesn´t provide that much info about what is happening, so I have improved the errormessage and this will be included in the 1.30.x series. Anyway, before trying this *DO A BACKUP*. Then you open up the file crcore.pl and find the sub called AUTOLOAD, replace the hole sub with this code instead:
Code: Select all
sub AUTOLOAD {
 my $sub = $AUTOLOAD;
 CRdie("Error: AUTOLOAD called without providing subroutine. ($sub)") unless $sub;
 # Get rid of package information.
 $sub =~ s/.+\:\://;
 if ($Subs{$sub}) {
  # Compile it.
  eval $Subs{$sub};
  if ($@) { die ("Subroutine $AUTOLOAD encountered a compile error during autoload: $@"); }
 }
 else {
      
  #PARAHEAD: 2005-03-02 Added modified version of the StackTrace as suggested by LoneOwl
  # http://coranto.org/forum/viewtopic.php?t=5816
  my $stack = '';   
  my $i = 0;
  my $prevsub = '';
  my $origin = '';
  while (my (undef, $filename, $line, $childsub) = caller($i++)) {
   $childsub =~ s/^.*:://;
   $stack = "$childsub in $filename, line $line<br>" . $stack;
   if($prevsub =~ m/^AUTOLOAD/) {
    my ($dummie, $originline) = split /\|/, $prevsub;
    $origin = "The call seams to origin from sub $childsub (at subline $originline) in $filename.";
   }
   $prevsub = "$childsub|$line";
  }
  die("Subroutine $AUTOLOAD was called, but does not exist (it isn't already loaded, and it isn't in the cache). $origin<br><br>FULL STACKTRACE:<br>$stack");
 }
 # Delete the source from memory, to save memory.
 delete $Subs{$sub};
 # Now switch to the just-compiled sub.
 goto &$AUTOLOAD;
}

Make sure the linebreaks are correct, since the forum can do a soft linebreak for long lines. Report back the errormessage you recieve now instead.
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Andross » Thu Mar 03, 2005 1:49 am

Here's the error message returned.
Addon Random (cra_randomnews.pl) caused an error. Error: Subroutine main:: was called, but does not exist (it isn't already loaded, and it isn't in the cache). The call seams to origin from sub MaginotURL (at subline 1003) in /usr/www/users/switchbd/andross/coranto/crcfg.dat.

FULL STACKTRACE:
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 35
main in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 36
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 88
NewsStyle_feature_artwork_style in (eval 4), line 50
MaginotURL in /usr/www/users/switchbd/andross/coranto/crcfg.dat, line 340
AUTOLOAD in /usr/www/users/switchbd/andross/coranto/cra_maginot.pl, line 1003
at /usr/www/users/switchbd/andross/coranto/crcore.pl line 585.

Edit: BLIMEY! It seems there's a problem with the Maginot for God knows what reason. I tried switching styles to a default style, one without Maginot, and it worked. And as you can see by the error message, Maginot is being shown as a problem. Grr....

The rest of the problem now seems to be server oriented too. My PHP include STILL won't work when a different style is used. I dunno why, but it just can't seem to open right...I either need to get in touch with the host or a new code is needed. Something that can call random segments from a profile. Anyone think they could do something like that?
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Postby LoneOwl » Thu Mar 03, 2005 2:42 am

Of additional help would be changing the AUTOLOAD sub somewhat, so instead of
Code: Select all
    if ($Subs{$sub}) {
        # Compile it.
        eval $Subs{$sub};
        if ($@) { die ("Subroutine $AUTOLOAD encountered a compile error during autoload: $@"); }
    }
it would be
Code: Select all
    if ($Subs{$sub}) {
        # Compile it.
        $Subs{$sub} =~ s/^\s*sub\s*(\w+)\s*{\s*$/sub $1 {\n#line 0 "$1"\n/;
        eval $Subs{$sub};
        if ($@) { die ("Subroutine $AUTOLOAD encountered a compile error during autoload: $@"); }
    }
[/code]
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Parahead » Thu Mar 03, 2005 8:30 am

Andross wrote:Edit: BLIMEY! It seems there's a problem with the Maginot for God knows what reason. I tried switching styles to a default style, one without Maginot, and it worked. And as you can see by the error message, Maginot is being shown as a problem. Grr....
I would say that this thread explains what is causing you problem. Check out your feature_artwork_style and make sure the MaginotURL call is using a correct Maginot Profile name.

LoneOwl wrote:Of additional help would be changing the AUTOLOAD sub somewhat
What, you don´t think everybody understand we start counting at zero? ;-) Why not just do a simple $originline-1 instead of a "cryptic" s/// in that case, since the "#line 0" will never be presented to the user anyway?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby LoneOwl » Thu Mar 03, 2005 11:05 am

Because it needs to be done for every compiled sub... It helps get rid of the (eval) in things like
FULL STACKTRACE:
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 35
main in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 36
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 88
NewsStyle_feature_artwork_style in (eval 4), line 50
MaginotURL in /usr/www/users/switchbd/andross/coranto/crcfg.dat, line 340
AUTOLOAD in /usr/www/users/switchbd/andross/coranto/cra_maginot.pl, line 1003
at /usr/www/users/switchbd/andross/coranto/crcore.pl line 585.
That way, finding out what was calling what and where the problems were can be found a tad easier....sometimes anyway...
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Parahead » Thu Mar 03, 2005 11:12 am

LoneOwl wrote:Because it needs to be done for every compiled sub...
True... Andross, could you please change the AUTOLOAD sub as suggested by LoneOwl and present the errormessage, would be interesting to see the difference. I will do it myself as well, forcing this problem.

LoneOwl wrote:That way, finding out what was calling what and where the problems were can be found a tad easier....sometimes anyway...
I agree, and it is more to help us (the coders) giving help to users, rather than users trying to make anything out of this information anyway... ;-)
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Andross » Sat Mar 05, 2005 1:20 am

The style is:
<If: Field: Category eq "artwork">
<a href="<MaginotURL: artwork>"><img src="<FilePath: CustomField_Thumbnail>" alt="Thumbnail" border="0" width="150" height="110" /></a>
</If>

The Maginot profile is 'artwork'

It's not something I'm doing here.
I'll make the change.
EDIT
Error
Addon Random (cra_randomnews.pl) caused an error. Error: Subroutine main:: was called, but does not exist (it isn't already loaded, and it isn't in the cache). The call seams to origin from sub MaginotURL (at subline 1003) in /usr/www/users/switchbd/andross/coranto/crcfg.dat.

FULL STACKTRACE:
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 35
main in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 36
(eval) in /usr/www/users/switchbd/andross/coranto/viewnews.cgi, line 88
NewsStyle_feature_artwork_style in (eval 4), line 50
MaginotURL in /usr/www/users/switchbd/andross/coranto/crcfg.dat, line 345
AUTOLOAD in /usr/www/users/switchbd/andross/coranto/cra_maginot.pl, line 1003
at /usr/www/users/switchbd/andross/coranto/crcore.pl line 586.


And to confirm it, it DOES have to do with Maginot, and I'm sure of it. When I take out the link, it works perfectly fine. When the Maginot thing is in, it works. I'll try MaginotFile, but I doubt it'll work. BTW, same happens without <If> tags.

EDIT: Yup, same happens w/Mag File.
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Postby Parahead » Sat Mar 05, 2005 9:32 am

Andross wrote:The style is:
<If: Field: Category eq "artwork">
<a href="<MaginotURL: artwork>"><img src="<FilePath: CustomField_Thumbnail>" alt="Thumbnail" border="0" width="150" height="110" /></a>
</If>

The Maginot profile is 'artwork'

It's not something I'm doing here.

....

And to confirm it, it DOES have to do with Maginot, and I'm sure of it. When I take out the link, it works perfectly fine. When the Maginot thing is in, it works. I'll try MaginotFile, but I doubt it'll work. BTW, same happens without <If> tags.
Yes, it is does include Maginot, but we have allready established that, what differs is that you think it is an error in Maginot, I still think that either the name of the profile is wrong (including a typo or lower/upper-case letters missmatch) *or* the Maginot Profile you are trying to link to isn´t a Maginot Static Profile or Maginot Static Split Profile. The name of the profile you are using must exist on the 'Manage Profile' overview page, it must be enabled, and it must be a Maginot Static [Split] Profile, is this the case?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Andross » Sat Mar 05, 2005 3:25 pm

For the last time, NO. This is not a typo on my part, and if you want, I'll make a temp account for you to go in and see for yourself if that would make things better. But otherwise, the profile is static, lowercase, 'artwork', AND when I tried with other profiles that had correct Maginot URLs (because they work), it still gave me the error.

I still think that a code that you could include in the style would be good. But, anyway, I'm gonna see what I can do with this image rotation script I have on another site. The code:
Code: Select all
<?
//////////////////////////////////////
//      Picture List          //
//  Enter pictures here, each pic   //
// should be the next number in the //
//    array, example shown below.   //
//////////////////////////////////////
$picture = array();
$picture[0] = "/images/features/mainfeature0.jpg";
$picture[1] = "/images/features/mainfeature1.jpg";
$picture[2] = "/images/features/mainfeature2.jpg";

$link = array();
$link[0] = "/platforms/ds/reviews/EEpyyEyylyKKyPoDtd.php";
$link[1] = "/news/EEpFyFAEulYkqAoaFW.php";
$link[2] = "/news/EEpFpFuVyyWnIuNNby.php";

//////////////////////////////////////////
//////////////////////////////////////////
$count = count($picture) - 1;
$num = rand(0,$count);

echo ('<a href="'.$link[$num].'"><img src="'.$picture[$num].'" alt="" border="0" /></a>');
?>


What I want to do is try and do it where the paths are generated by Coranto randomly, and only for that certain category.
User avatar
Andross
 
Posts: 138
Joined: Wed Jun 30, 2004 7:22 pm

Next

Return to Addon Release and Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron