How to show text files?

Hi all.
I am currently using zenphoto just a bit like an photo diary. For this reason i would like to show textfiles.
I am still a php beginner and for this reason i cannot figure out how to do this properly by my own. At this time i just extended the "is_valid_video" function with the "txt" and whenever a txt file is in the album, the content will show up in an iframe. But iframes are not really where i want to end up!
I already tried out to clone the whole zenvideo functions, but for any reason txt files
are not identified.
Is there any workaround to do that, or can any one push me in the right direction?

Thank You
Andis

Comments

  • acrylian Administrator, Developer
    Seriously, why should an image gallery show text files? Why so complicated anyway, why don't you just put your texts into the image description field in the admin? That's what it's for.
  • trisweb Administrator
    I also recommend using the image Description field, if it is a photo diary. One photo with as much text as you want under the description.

    If you want mostly text, try a text-oriented content management system such as Wordpress or Joomla. From there you can copy Zenphoto image URLs to use in your posts.
  • Andis Member
    Well, my Photo Diary sometimes contain email-textfiles related to some galleries.
    The image Description field here constricts me to much. I do not want to show an image with a singel textfile. The Description field is fine for me to have a short description for an image, but in my eyes (resp. my template) it is not usefull to extend this to much.
    Zenphoto can show different image files, and a some video formats, why not a text file?
    Anyway, i asked for how to not for not to.

    To specify my problem, i added to functions.php
    function is_valid_text($filename) {
    $ext = strtolower(substr(strrchr($filename, "."), 1));
    return in_array($ext, array('txt'));
    }

    an call it in in class-image.php just below the is_valid_video check.
    if (is_valid_text($filename)) {
    echo "show something";
    }

    But for any reason nothing shows up. Any Ideas?
  • So, you want to show text without an image? That is really not the intent of a software like zenphoto.

    If the text is supposed to be associated with an image, use the description field. If the description field is too small for you (a strange issue since it is limited only to what the database can store) then you could add to your theme to fetch a text file based, say, on the custom data field of an image.
  • Andis Member
    It might not be zenphotos intent yet, but it is defintely mine.
    I have different data in my albums. Images, video and textfieles as well. For me it is just easier to show textfiles than insert all the fieles into the database. Although a huge image or album description just explodes my design.
    As far as i know, even zenvideo has not been part of zenphoto from the beginning.
    I do not understand why everybody resists against this at the moment.
    Btw, shure i can store mass amount of text in one database, i can also store images in it but i wont do that.
  • trisweb Administrator
    There are many reasons:

    1. Databases are designed for storing text. It's what they're for. They're not designed for storing image data, which is why we don't do that. I would not even hesitate to store a novel in a database.

    2. Zenphoto is a photo and predominantly visual media software (including videos, which are very similar to photos you must admit). We simply think that if the majority of your content is in Text, then another program will be easier for you, rather than hacking a photo gallery software to display text files. That's what we programmers call 'inelegant' and 'a hack' and we mainly discourage this.

    3. Helping you hack zenphoto is not our main priority - you're welcome to if you want, and we are helpful people, but we cannot spend time making this work for you, since you seem like you can't do it yourself, and we simply have very little time and have to focus on zenphoto features.

    4. Honestly, we're trying to help you here. Zenphoto is a photo gallery software, if you want text you should use a text-based CMS, that's just going to be easier for you. We're not trying to say "don't do it" we're just trying to figure out an easier way! Because we know how hard this will be, and it's not something simple like you think it is.

    If you still want to continue, you're on your own unless someone else on the forums wants to help. We simply can't spend time implementing every feature people want for them.

    You'll have to do several things - you'll need a 'Text' class, or to modify the Image class, take care of reading the file from disk, and outputting its content. You'll also need to create database entries for each file you read, take care of sorting and ordering, figure out what thumbnail you want for text files to display in the theme, create new template functions to display the text, and more. Good luck.

    Or, http://www.wordpress.com will already do all this for you, because it's already designed for that.
  • Andis Member
    Thank you for your answer.
    As i said in my first post, i already found an easy way to display text in iframes by extending the zenvideo function. But iframes are not what i want in my code.
    And as i did say in the last post, it is just easier to display text files than to store in a database by copying into a cms. My Zenphoto provides about 3534 Images in 157 albums and about 25 text files. By that i would say the majority of my contents are images.
    I did just ask for potentially existing workaround, which is not inelegant and a hack in the negative way. And last but not least persistant in view to future zenphoto updates. I did not ask anyone to implement anything for me!

    I am not sure about your last point, to create a db entry for each file. There is no entry for the video files as well.
  • Aside from trying to use text as some sort of display object in an image/video gallery, the core of your problem would be formatting. If you just output regular text it will not look very good at all. In particular, line breaks would not be honored by the HTML renderer (the user's web browser).

    But, if you really want to do it, the simplest way to output text from a text file in-place would be this:

    `

    <?php<br />
    $fp = fopen('file.txt', 'rb');

    $text = fpassthru($fp);

    fclose($fp);

    print($text);

    ?>

    `
  • trisweb Administrator
    Yep. I'm not sure where your iframe code is outputting, but you can just replace the iframe with whatever is in that code that jsumners gave, to output the text directly.

    It most likely will not be able to be "persistent in view to future zenphoto updates" since any files you edit would be overwritten on upgrade. You can keep track of your changes in some document, or keep your PHP functions in a separate file so you don't have to change as much in zenphoto.
  • Andis Member
    I surely know how to read and output text via php. The main problem her is/was to filter the txt files while zenphoto goes through the albums. I just extended zenvideo is_valid_video function with the txt an added the following into template-functions.php
    elseif ($ext == ".txt") {
    echo '<iframe height="auto" width="100%" frameborder ="0" src="' . getUnprotectedImageURL() . '" scrolling="yes"></iframe>
    }

    But as you said, this is higly inelegant and doesnot satisfiy my :)
Sign In or Register to comment.