Textpattern Forum

You are not logged in. Register | Login | Help

#11 2012-05-08 07:22:50

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

I just discovered a problem with the site on hblack.net

On the previous server set up, the home page was displaying a random image in the background. For that I was using a script and was calling it with background: url('<?php include("ri.php");?>');. Now that includes are not accepted I tried using background: url(<?php echo file_get_contents('ri.php');?>); but again, nothing is parsed.

this is the php script

<?php
$your_dirname="rando/";

$your_alt_tag="hb";
//
/*

*/
p. function displayAaPHPrandomImage($dirname, $alt){
  $dirhandle = opendir($dirname);
  while (false !== ($file = readdir($dirhandle))) {
    if ($file != "." && $file != ".." && !@is_dir($file)) {
      $filelist[] = $file;
    }
  }
  closedir($dirhandle); 

  if(sizeof($filelist) ==0) { 
    echo "No file was found in the directory!";
    exit;
  }

  srand((double)microtime()*1000000);
  $picnum = @rand(0, sizeof($filelist) - 1);
  $imageName=$dirname.$filelist[$picnum];
  $imageSize = getimagesize($imageName);

$result="$imageName";
return $result;

  }
?>
<?=displayAaPHPrandomImage($your_dirname)?>

Can anyone point me as to what might be going wrong?


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#12 2012-05-08 08:14:32

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

Sorted :)

Note to self: Don’t use any third party scripts when a combination of native txp tags and a trusted txp plugin can do the job just as well and possibly in a safer way.


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#13 2012-05-08 08:29:53

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: migrating

colak wrote:

Now that includes are not accepted

Are not accepted where? Includes are accepted, valid. If you are referring to previous mentions concerning rah_external_output, those where about non-local filesystem files, where actual content where transferred over internet.

file_get_contents

File_get_contents is a file function and just merely reads files. include on the other hand is for evaluating PHP source code. file_get_contents will not evaluate (i.e. execute) any code, it just reads files.

<?php […] ?>

Let’s start with the tags. Use of raw PHP is deprecated, and the support will be removed in the next release, Textpattern v4.5.0. Instead of those, please see and use txp:php> tags when working with PHP block in page and form templates.

nothing is […] what might be going wrong?

Try to turn Debugging mode on. Potentially one the file paths could be incorrect (using absolute paths might not hurt), or you may not have rights to the directory.

As the random image script goes, you probably could minify it something much more smaller and put it into a single PHP in your page template. For example:

background: url('/rando/<txp:php>
	$f = array_filter((array) glob(txpath.'/../rando/*.{png,jpg,gif}', GLOB_NOSORT|GLOB_BRACE), 'is_file');
	echo $f ? basename($f[mt_rand(0, count($f)-1)]) : '';
</txp:php>');

Edit. glad you got it sorted. Seems you migrated to Textpattern’s own image management and <txp:images /> tag or similar :)

Last edited by Gocom (2012-05-08 08:34:51)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#14 2012-05-08 08:45:28

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

Gocom wrote:

Hi Jukka

Are not accepted where? Includes are accepted, valid. If you are referring to previous mentions concerning rah_external_output, those where about non-local filesystem files, where actual content where transferred over internet.

My new server at joyent does not like includes and it initially broke all my pages which were using the include function

File_get_contents is a file function and just merely reads files. include on the other hand is for evaluating PHP source code. file_get_contents will not evaluate (i.e. execute) any code, it just reads files.

It is nevertheless this code which solved my problems a few days ago

Edit. glad you got it sorted. Seems you migrated to Textpattern’s own image management and <txp:images /> tag or similar :)

Yes :) I used <txp:images limit="1" category="random_images" sort="rand()"><txp:image_url /></txp:images> and added body{background: url(<?php echo file_get_contents('path_to_ext_output/?rah_external_output=myextTxpTags');?>); and all was sorted.

Thanks soo much for your intervention nevertheless


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#15 2012-05-08 13:39:01

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

OK… :) There are still problems.

On forum.neme.org I have a little file which calls for rah_external_output.

I used to be able to get it by using <?php include($DOCUMENT_ROOT . "http://mysite.tld/?rah_external_output=bar"); ?> but not any more.

// does not work (the whole forum page goes white)
<?php include($DOCUMENT_ROOT . "http://mysite.tld/?rah_external_output=bar"); ?>

// same as above
<?php include 'http://mysite.tld/?rah_external_output=bar'; ?>

//same as above
<?php include("http://mysite.tld/?rah_external_output=bar"); ?>

// semi works as the forum page is rendering but the external output is not fetched
<?php echo file_get_contents('http://mysite.tld/?rah_external_output=bar'); ?>

any advice would be appreciated


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#16 2012-05-09 14:08:42

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

Maybe I should clarify the difference between my old server up and the new one. In the old server the forum was residing inside the main domain. After Joyend’s advice, now the forum is working like an independent domain. The includes I was using in the previous setup were cross-domain (fetching content from our sites) except the forum as I mentioned earlier and everything was working wonderfully.

<?php echo file_get_contents('http://mysite.tld/?rah_external_output=bar'); ?> works fine for the txp sites but for the forum, it is not parsed.

Can anyone point me to the right direction on how I can display this txp content?


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#17 2012-05-09 22:55:57

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 814
Website

Re: migrating

Try using Curl

I had a similar problem a few years ago with get_file_contents and include, both of which had been turned off or something on the server and the admins told me to use Curl…. I did, and it worked.

Not sure on the technicalities though

Offline

#18 2012-05-10 05:47:44

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

Thanks tye

I tried

<?php
	$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, 'http://mysite.tld/?rah_external_output=bar');
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
	echo curl_exec ($curl);
	curl_close ($curl);
?>

and

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mysite.tld/?rah_external_output=bar');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$file = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $file !== false && $http == '200' ? $file : 'Error appeared. Sad face.';
?>

neither of which returned any results.


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#19 2012-05-10 06:33:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,987
Website

Re: migrating

[SOLVED]… I had an include in my rah page which I forgot to change.


Yiannis
——————————
neme.org | neme-imca.org | hblack.net | LABS

Online

#20 2012-05-10 07:23:47

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 814
Website

Re: migrating

:) Phew… thought I was going to have to pretend I knew what I was doing then

Offline

Board footer

Powered by FluxBB