HI, I was wondering if this issue has been resolved. It turns up in this thread towards the end: http://ellislab.com/forums/viewthread/99394/
I am attempting to build an RSS feed based on Gallery contents for a client. The important part is that a URL is sent to tinyurl.com for shrinking. The aim being for a service like TwitterFeed to relay it through Twitter.
So, here is the skeletal code I am using. It’s set to run Before processing (running after seems to do nothing). The code here is just what’s needed to demonstrate the problem, so won’t generate proper XML. There is also some debug echo statements which is showing me (and you) where the problem is and where/when it is likely to happen.
<?php
function TinyURL($url)
{
// the URL passed appears to be correct
echo "url passed = $url\n";
// however -
echo strlen($url)."\n";
// note that the value returned will be 18 -
// the length of {custom_field_one}
// the call below actually makes $url equal to {custom_field_one}
// and not the URL you expect!
return (file_get_contents("http://tinyurl.com/api-create.php?url=".$url));
}
?>
{exp:gallery:entries gallery="freeway" orderby="entry_date" columns="3" rows="3" category="1|2"}
{entries}
{row}
<description>
{exp:xml_encode}
<?php
// get the URL from the Gallery output
$theURL='{custom_field_one}';
// send it to tinyurl.com for shrinking
echo TinyURL($theURL);
?>
{/exp:xml_encode}
</description>
{/row}
{/entries}
{/exp:gallery:entries}The code runs, and generates an XML file. However, all the URLs from tinyurl.com are identical, even though the URLs output in their long form are all different. The URL returned from tinyurl.com in all cases is: http://tinyurl.com/6xwqrfe
which resolves to: http://tinyurl.com/{custom_field_one}
In short, instead of the URL I want being passed, the string “{custom_field_one}” is.
The problem is worsened if I include
echo $theURL;after the line which gets the value from Expressionengine. This outputs, correctly, the URL from the gallery. This is what should be going to tinyurl.com
By way of testing, if I include
echo str_len($theURL);in the PHP, I will get the length of the text “{custom_field_one}” and not the the length of the URL I was expecting - so I can’t slice and dice the string and rebuild it for further use (a workaround I was hoping to employ).
The problem happens regardless of whether the calls to tinyurl.com are done in the function or directly in the loop.
So, what I need to know is how to work around this problem. How do I get the URL I was expecting to be sent to tinyurl.com? I can’t think of a way to coerce the contents of $theURL to be what I want it to be, and not “{custom_field_one}”. Clearly the value of that tag is being output correctly as I can echo it in PHP, but somehow I can’t use it for anything more useful.
Thanks.
NB - for reasons that I have no control over, the server in question is running PHP4, so the solution needs to run in that environment.
It’s set to run Before processingDoes that mean PHP on Input? I don’t think that will work, no EE variables are available at this point (as they haven’t been parsed yet). Also, what version and build of EE are you using?
Sorry - yes - running on Input. When I run on Output, no PHP is processed.
Sample Parsing on Input results:
<item>
<title>Dreamscape Photographs</title>
<link>http://www.softpress.com/galleries/freeway/</link>
<description>
Start with PHP processing
theURL = http://dreamscapephotographs.com/
url passed = http://dreamscapephotographs.com/
18
http://tinyurl.com/6xwqrfe From XML: http://dreamscapephotographs.com/
</description>
<date>
2011-02-14T11:22:13+00:00
</date>
<dc:subject>
Freeway Pro
</dc:subject>
<content:encoded>
Name: http://dreamscapephotographs.com/
Title: Dreamscape Photographs
</content:encoded>
<dc:date>2011-02-14T11:22:13+00:00</dc:date>
</item>Sample Parsing on Output results:
<item>
<title>Dreamscape Photographs</title>
<link>http://www.softpress.com/galleries/freeway/</link>
<description>
From XML: http://dreamscapephotographs.com/
</description>
<date>
2011-02-14T11:22:13+00:00
</date>
<dc:subject>
Freeway Pro
</dc:subject>
<content:encoded>
Name: http://dreamscapephotographs.com/
Title: Dreamscape Photographs
</content:encoded>
<dc:date>2011-02-14T11:22:13+00:00</dc:date>
</item>You will notice that bits like
theURL = http://dreamscapephotographs.com/
url passed = http://dreamscapephotographs.com/
18are missing - those are output using PHP echo statements.
If I give an outline of the code I am using, it looks something like this:
<?php
function TinyURL($url)
{
return (file_get_contents("http://tinyurl.com/api-create.php?url=".$url));
}
echo "HELLO";
?>
{exp:rss:feed weblog="gallery"}
[setting up RSS headers here]
{exp:gallery:entries gallery="freeway" orderby="entry_date" columns="10" rows="10" category="1|2"}
{entries}
{row}
<item>
<title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
<link>http://www.softpress.com/galleries/freeway/</link>
<description>
{exp:xml_encode}
<?php
// get URL & shrink it via tinyurl.com
echo "Start with PHP processing\n";
$theURL='{custom_field_one}';
echo "theURL = $theURL\n";
echo TinyURL($theURL);
?>
From XML: {custom_field_one}
{/exp:xml_encode}
</description>
</item>
{/row}
{/entries}
{/exp:gallery:entries}
[close off other stuff here]When I run the code, the only PHP that seems to output is the one that says HELLO at the top. The php in the {exp:gallery} loop seems to be ignored. Even if I just put an echo”HELLO”; statement in there, and nothing else, it doesn’t output anything.
We’re using EE 1.6.7 (I know there is an update - and I have told the client about it - what is on the server is their responsibility, not mine).
Hi, hairydalek - My recommendation would be to turn your PHP code into a plugin and get it working that way. I’m going to move this down to Development and Programming for you as well. Thank you.
Thanks. You’ve lost me with the whole “plug in development” bit though. I thought it would be simpler to do than this 😕
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.