How to use customized data

I'm not sure how they are called in the english version; in french, I see them as 'Données personnalisées' in both the album and image page of the admin interface.

What can we put there, and how to format it? Unless I missed something, I didn't find any method to get the information that has been put in this field.

Thanks for your answer.
«1

Comments

  • Oops! Sorry, I just found the related functions in `template-functions.php`.
    I guess that means the formating is free, and I need to decide how to store my own data in there.
  • acrylian Administrator, Developer
    Please just switch the admin to the English language if you are asking something like that. We really don't understand French. Otherwise we really cannot help.

    Since this means apparently "custom data". That is an all purpose text field and it is up to you what you do with it exactly. You can attach The editor TinyMCE to it and use it like any other content field. You can add and output html or js code but not PHP code. For the latter the codeblocks are meant.
  • Where/how can I switch language in the admin?

    As for the custom data, I tried `print $_zp_current_album->getAlbumCustomData();` but got the following error: `Fatal error: Call to undefined method Album::getAlbumCustomData()`. I am missing something, but what?
  • acrylian Administrator, Developer
    1. On the options naturally

    2. Well if you didn't call it within album context it naturally doesn't work since the album object is not available (but this you should really know by now as a long time user :-)).
  • I might be less-advanced level that you think. :-)

    The line before `print $_zp_current_album->getAlbumCustomData();` is `print $_zp_current_album->getDesc();` and it works...

    What could be the difference between those two?
  • acrylian Administrator, Developer
    Ok, I didn't look direclty but your mistake is that `getAlbumCustomData()` is not a class method but a simple template function. So no global needed.
    http://www.zenphoto.org/documentation/functions/_template-functions.php.html#functiongetAlbumCustomData
    `print $_zp_current_album->getCustomData()` would be the class way.

    `getDesc` is a class method, its template equivalent would be `getAlbumDesc`: http://www.zenphoto.org/documentation/functions/_template-functions.php.html#functiongetAlbumDesc`
  • Thanks for the explanation. I've now managed to make work the function without an error.

    But I've not still found the best way to manage more than one information for some several albums:
    - either I use the custom data, but I would like to use an array, in order to get something like "width" => 158, "height" => 108; currently I only succeeded in retrieving one single string, so I need to parse it manually I think
    - the other option would be to use the codeblock and assign values to several variables. `$width=158; $height=108;` does seem to work, but the values are lost after the code block has been executed: they're not there anymore in the page template.

    Any suggestion to do this, in a manner that could be simply managed with different values for several albums?
  • acrylian Administrator, Developer
    Codeblocks are meant to execute code on the theme dependent on an item. If you need to store values you want to use on the theme page itself you maybe should modify the theme. Codeblocks are executed within a function os it is captured within. You could try to use global variable but then you need to modify the theme to use it anyway.

    You can create arrays out of like "158,108" or "158/108) using the php standard function explode.
  • Normally, if I were to create custom sizes I would modify as needed on the index, album, favorites, and image page to suit my taste.

    Reading your comment it seems you want different image sizes depending on which album is called up.

    Having seen how to do this in the past, if you do not need a ton of different sizes, the best way to do so is to create variant themes and use the plugin that allows a different theme assignment per album then call the modified page. Can't remember the plugin name right off, sure someone else can contribute it if yoy can't find it.
  • The custom data field may be used to store array information since it stores arbitrary content. A little PHP knowledge is required here, though. You will need to serialize the array before storing it in the custom data field and unserialize it when retrieving it.
  • The plugin @papyrus refers to is the `multiple_layouts` plugin.
  • fretzl Administrator, Developer
    @Papyrus: You mean the `multiple_layouts` plugin.
  • acrylian Administrator, Developer
    Answer shoot out today :)
  • May be some explanations are in order:

    1) I'm working on my own theme, that works for all the photographies (about 90% of the gallery)

    2) for the remaining pictures files, such as postcards, press-book, graphic work and such, I use the multiple-layouts plugin with a custom album page, and a custom image page

    3) I'd rather avoid different custom pages, because of future maintenances; things are too similar from one type of pictures to the other, so I'd rather find some solution using either custom data or code block on specific albums

    4) entering a list of numeric values in the custom data doesn't seem very user-friendly / reliable, that's why I'd like to link each value to either a meaningful label (width, height, and such) or use the code block to assign a value to each variable.

    @acrylian: I tried to use global variables, but it didn't work. I probably dit it wrong... can I find somewhere an example of codeblock in that manner?
    And by the way, I didn't find the way to switch the language in the admin interface: when I choose English in the general options tab, the interface remains in French!
  • acrylian Administrator, Developer
    3) Ok, maybe the best would be to code the change on the theme switching by the album name. If possible.

    4) I agree but it is the simplest solution probably - especially if you are the only one managing possibly? - without the need of a extra plugin providing extra fields or the like.

    Globals and codeblock: We don't have any example I fear. I haven't tried this, it was just a quick idea.

    Language: That would mean you don't have an English/US locale on your server. The languages are tied to those available. My live server for example has only English and German, so French would not work (my local MAMP server has them all though). Maybe contact your host if they can set it up. It would just help us if we use the same terms when supporting.
  • 3) I can test on the album name. I fact, that's what I had begun with... but I'll need to modify the code each time I'll want to add a new album. And now that I've seen the possibities provided by the album admin page, I'd rather go for a 'cleaner' code.

    4) the simplest thing for putting the gallery on line is not necessarily also the simplest on the long time.
    Yes, I'm the only one managing the gallery, but I'd rather spend as little time as possible tuning code in the future. My main goal is to publish my work on the web, not to manage the gallery. :-)

    I'll go on trying some things tomorrow, and will revert to a hard-coded solution if I don't find quickly something more sustainable.

    Language: I have no idea what the limits of my hosting service are. And I've recently reinstalled locally a new Linux/Fedora version and didn't take time to set up a new local server; guess I'll do it when my Zenphoto gallery will be public so I have no other option if I want to prepare other modifications!
  • acrylian Administrator, Developer
    3) Sure. An idea would just use some of the fields like location and such if you don't use them otherwise.

    4) Although My main goal is to publish my work on the web, not to manage the gallery. :-) is a bit related if you self host, isn't it? :-)
    The best from hte user point of view would be a plugin providing extra fields for that specific purpose. However that means some work ;-)

    Re: language: We have a script to display available locales: https://github.com/zenphoto/Unsupported/tree/master/misc/list_locales
  • 4) If putting on line the Zenphoto gallery had been a priority, it should had been done months ago! As it is, I still make things go with my 'old' Piwigo gallery and my FB page. :-)

    I found out the answer for the language: I needed to deactivate the French otherwise it remains the default. Deactivation of the HTTP_AcceptLanguage was not enough apparently.
  • Ha, thanks everyone for filling in the plugin name. I'd have to say custom codeblocks or functions aren't any simpler than just having one modified line per page that needs modification as you'd run into with the multiple layouts method if you wanted to go that way.

    That being said, here is another method that would require a touch more work but could accomplish the goal with one function. What you could do is grab the URI and match against a list of album names (likely at the top level, where you split into postcards, photo books, etc.. so it'd automatically apply to sub-albums) grab that album name, set it as a variable, then run a loop that checks the variable and (if x album, then y dimensions) prints that on the page. A bit more work but only one function to maintain.
  • You can also get the global parent album from any album by `getUrAlbum($album_object)`
  • And with that useful call it's an even easier job. $variable = getUrAlbum($album_object). If $variable = photocards do this. If $variable = photobook do that. Cuts half the work of writing the function out.
  • Except that the function returns an object, so what you need is `if ($variable->name = photocards)....`
  • Thanks everybody for helping.
    I've succeeded in what I wanted to do: in the custom data field, I can enter as many `name=value` separated by a comma, and get them as an array in the program.

    The only thing that remains to make it 'perfect' is transforming it into a function so I can use it in any other php page.
  • @Papyrus: the purpose of using custom data or code block is precisely to avoid hard-coding. I didn't want either to make references to the album names or their parent.

    With my solution, I have nothing to add/modify when I add a new album, or modify one that already exists. I can even add as many new variables as I want too, they will be automatically available in the program.
  • acrylian Administrator, Developer
    Good you managed it for your purpose! Many roads lead to Rome :-)
  • Yes, once you know how to find your way! ;-)
  • Well I'm very happy you worked it out. Always nice to see the different ways people tackle issues!

    If it does help anyone in the future though, I whipped up my variant of the idea as a foundation. I'm sure many future visitors would appreciate any alternate methods you might be employing spelled out for them if you feel like it, tosca. :)

    http://animepapers.org/software/zenphoto/code-snippets/multiple-layouts-dynamic-modification.html

    Probably far from perfect, but if anybody needs a reference it's there with a tiny bit of documentation.

    I'll also post here...and see how it comes out:

    `

    <?php<br />
    $masal = $_zp_current_album->getParent();

    if (strlen($masal) == 0)

    {

    $theDecider = $_zp_current_album->getTitle();

    } else {

    $theMiddleMan = reset($masal);

    $theDecider = current($masal);

    }

    ?>

    <?php </p>

    if ($theDecider = 'album-name-1') {

    $iw = 189;

    $ih = NULL;

    $cw = 909;

    $ch = 67;

    } elseif($theDecider = 'album-name-2') {

    $iw = NULL;

    $ih = 989;

    $ch = 149;

    $cw = 79;

    } elseif($theDecider = 'album-name-3') {

    $iw = NULL;

    $ih = 389;

    $ch = 89;

    $cw = 67;

    } else {

    $iw = NULL;

    $ih = 85;

    $ch = 99;

    $cw = 99;

    }

    ?>

    echo '

    getCustomImage(NULL, $iw, $ih, $cw, $ch, NULL, NULL, true)) . '); ">"'.getImageTitle().'"';

    `
  • acrylian Administrator, Developer
    @Papyrus: Some quick comments:
    1) `$masal = $_zp_current_album->getParent();`
    `getParent()` returns an album object if there is a parent or NULL, so it is quite different to `$theDecider`;

    2) `$theDecider = $_zp_current_album->getTitle();`
    You should use the album name here. The title is never unique identifier especially since it changes on multilingual sites per language naturally.

    3) `if ($theDecider = 'album-name-1')`
    You mean of course `==` ;-)
  • Here is the function I've written, but it is for retrieving custom data, whatever they are; in addition to custom thumbnails dimension, I've already used it to assign specific classes, and it could be used for anything else.

    `
    /*
    ** Récupération du contenu de "Données personnalisées"
    */
    function mnaCustomData($page) {
    switch ($page) {
    case('album') : global $_zp_current_album; $custom_data = getAlbumCustomData(); break;
    case('image') : global $_zp_current_image; $custom_data = getImageCustomData(); break;
    case('page') : global $_zp_current_zenpage_page; $custom_data = getPageCustomData(); break;
    case('category') : global $_zp_current_category; $custom_data = getNewsCategoryCustomData(); break;
    case('news') : global $_zp_current_zenpage_news; $custom_data = getNewsCustomData(); break;
    }
    $data_array = explode(",",$custom_data);
    foreach ($data_array as $one_data) {
    $label_value = explode("=",$one_data);
    $custom_data_array[trim($label_value[0])] = trim($label_value[1]);
    }
    return $custom_data_array;
    }
    `
  • acrylian Administrator, Developer
    That's actually more or less what I suggested above btw :-) What is `$page` in your context? Just asking since there is no "category" page.
Sign In or Register to comment.