php ob_start + replaceobjembed + get clean + embedded templates = no work
Posted: 17 April 2007 12:49 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  314
Joined  05-11-2005

(I hoped the keywords in this title tag might help someone else wink )

I read this entry on php global variables but I think it won’t quite apply to the php I’m using. I’m going to paste you my code below.

What happens is the page basically “shows” the embed tags, so they are not getting parsed. . On this template below, I have ‘allow php” set to yes, and to the input stage. In the includes/applications_segment3 I have the same settings. My other embeds do NOT have php allowed. I’ve put up a test page for you here:

http://www.cobaltcfd.com/index.php/site/applications_test/dod_hpc_challenge

Is there any way to get this php to work and also have my embeds all parsed, too? What the php is meant to affect is content in the applications_segment3 file (embedded video object).

<?php
  ob_start
();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Applications and Demonstrations of Cobalt Software | Cobalt Solutions</title>
{embed="includes/header"}
</head>
<
body id="applications-page">

<
div id="header_container">
<
div id="header">
<
a href="index.php"><img src="http://www.cobaltcfd.com/graphics/logo.gif" width="263" height="117" border="0" alt="Cobalt Solutions Logo" id="logo" /></a>
<
h1>Cobalt Solutions</h1>
</
div><!-- end header -->

<
div id="navigation">
{embed="includes/navigation"}
</div>
</
div><!-- header container -->

<
div id="container">

{if segment_3 !=""}
{embed
="includes/applications_segment3}
{if:else}
{embed="
includes/applications_segment2}
{
/if}<!-- end segment 3 -->

</
div>

<
div id="footer">
{embed="includes/footer"}
</div>

</
div><!-- container -->
</
body>
</
html>


<?php
  
include_once "/extras/replaceObjEmbed.php";
  echo
replaceObjEmbed(ob_get_clean());
?>

Thank you!

 Signature 

Websites with impact. Websites that substantially grow your business.
http://www.designbyreese.com

Profile
 
 
Posted: 18 April 2007 08:21 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15833
Joined  06-03-2002

Embeds are parsed after the parent template is completely parsed, so the only reason I can see that it is not continuing and parsing the embeds after you are echoing them back out is that your script is ending execution.

Embedded template:

Hello world!

Parent template (php on input or output—doesn’t matter here, as embeds are parsed long after either):

<?php
ob_start
();
?>
{embed
="test/embed"}
<?php
echo ob_get_clean();
?>

Results:

Hello world!

But note that what is really happening is that the PHP is merely echoing out the embed tag, which gets later processed.  This is demonstrable by halting script execution:

[code]<?php
ob_start
();
?>
{embed
="test/embed"}
<?php
echo ob_get_clean();
exit;
?>

However, your larger problem is that you are wanting your script to have access to the contents of the embedded template, and for the reasons described above, that just isn’t going to work.  All of the PHP will be executed before ExpressionEngine even looks at the embedded templates.  So your PHP script will have access only to the template code, not to any parsed contents.  Your solution in this case is to use your PHP script on output in the embedded template, or better still, convert your script into either a module or a plugin, and use it in the embedded template with tags.  In either case, it appears like you have some modification of the script to do, as it is halting ExpressionEngine from doing any further work.

 Signature 
Profile
MSG
 
 
Posted: 18 April 2007 11:43 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  314
Joined  05-11-2005

Thanks Derek; your explanation makes sense. I wish I knew how to make this into a plugin smile
I tried pulling out the embedded content in question and popping it directly into my template, but that didn’t work, either. I tried your suggestion on putting the embedded template to allow php>>output, and then it gave me some interesting errors which I think may be related to the host’s permissions:

Warning: Unknown(): open_basedir restriction in effect. File(/extras/replaceObjEmbed.php) is not within the allowed path(s): (/www/pmh4973) in /www/pmh####/public_html/path_to_client/core/core.functions.php(626) : eval()'d code on line 45

Warning: Unknown(/extras/replaceObjEmbed.php): failed to open stream: Operation not permitted in /www/pmh####/public_html/path_to_client/core/core.functions.php(626) : eval()'d code on line 45

Warning: (null)(): Failed opening '/extras/replaceObjEmbed.php' for inclusion (include_path='.:/usr/share/pear') in /www/pmh####/public_html/path_to_client/core/core.functions.php(626) : eval()'d code on line 45

Fatal error: Call to undefined function: replaceobjembed() in /www/pmh####/public_html/path_to_client/core/core.functions.php(626) : eval()'d code on line 46

So I think I’d probably need to talk with PMH at this point if I want to proceed further, but I figure those error messages are semi promising ;) Thank you again for your suggestions and help!

 Signature 

Websites with impact. Websites that substantially grow your business.
http://www.designbyreese.com

Profile
 
 
Posted: 18 April 2007 11:57 AM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15833
Joined  06-03-2002

I edited out your pmh account number from the error messages, as that’s a good idea to keep private.  On that environment, you should have seen that error with PHP input as well, perhaps you just had error reporting disabled, or were viewing the page logged out?  At any rate, you will need to use a full server path or relative path to be able to include that file.  PHP’s file handling paths are based on the underlying file system, not the URL.

 Signature 
Profile
MSG
 
 
Posted: 18 April 2007 12:20 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  314
Joined  05-11-2005

thanks; I didn’t realize that pmh### is a unique one. appreciate you looking out for the security issues!
I was viewing the page without ANY debugging on at all—just through the browser. I think I have a couple of various path issues going on here, on the last two lines, that i need to resolve.

 Signature 

Websites with impact. Websites that substantially grow your business.
http://www.designbyreese.com

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64944 Total Logged-in Users: 70
Total Topics: 81925 Total Anonymous Users: 47
Total Replies: 440355 Total Guests: 300
Total Posts: 522280    
Members ( View Memberlist )