ZenphotoCMS Forum
How to print the bare contents of a textObject? - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: How to print the bare contents of a textObject? (/thread-11830.html)



How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

Hey

I have some text in a .txt file which using class-textobject (or class-anyfile?) I treat as an image. How do I print the bare contents of this text file?
I tried many functions and only printCustomSizedImage* work, but they don't return bare contents.
I used: ` This returns:This is the content of foo.txt`

I would like pure text returned, nothing else. Is this possible?




How to print the bare contents of a textObject? - acrylian - 2014-06-12

You will have to use standard PHP function like file_get_contents() to read and display the plain file. Which is what the plugin uses to get it as well. See the getContent() method of it. You could also use getContent() and strip the wrapping span via strip_tags.




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

And one more question, is it possible to print just the image filename without anything else? Like getUnprotectedImageURL minus the paths and minus the extension.




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

Ooh thank you, I got it working! Though I don't know if what I did is either correct or efficient Is this the best way to do it?
``




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

I managed to get the full path without the extension using `` which returns
/zp/albums/foo/bar/kitteh
Now how do I get rid of "/zp/albums/foo/bar/"?




How to print the bare contents of a textObject? - acrylian - 2014-06-12

$txtFilename = str_replace(WEBPATH,'',$txtFilename) should work. We have several of these constants like WEBPATH. I guess I should make a user guide entry about these some time.




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

That one just removes "/zp".




How to print the bare contents of a textObject? - acrylian - 2014-06-12

Try `WEBPATH.'/'.ALBUMFOLDER.'/'.$_zp_current_album->name';




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-12

Success!
``
Thank you!




How to print the bare contents of a textObject? - acrylian - 2014-06-12

Btw, of course echo $_zp_current_image->filename gets you the file name even easier. Textobjects are descendents of the image class so a lot works on them like on images. Sorry, forgot to mention earlier.




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-28

For anyone interested, the pathinfo and stripsuffix functions works great for getting parts of a path or filename!

pathinfo returns an array consisting of dirname, basename and extension.
stripsuffix does as the name implies.

To get the txt filename:
$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = $txtFilename ['basename'];
To strip the suffix:
$txtFilename = stripSuffix($txtFilename);

You could shorten and merge the two:
$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = stripSuffix($txtFilename ['basename']);




How to print the bare contents of a textObject? - acrylian - 2014-06-28

Isn't what I told above much easier to get the filename? For other parts of paths there are several path related constants like WEBPATH, ALBUMFOLDER etc.




How to print the bare contents of a textObject? - LondonLight.org - 2014-06-28

I used the code you gave me above for some time, but once things started getting hairy I found this to be quicker to experiment with. Both have uses, hope this helps someone too