search by owner

I need to write a user page that shows all the images that a user owns, a sort of search by tags (clicking on the word) but by owner. I need it to collect every image a user uploads on my site.
The search form doesn't have a 'owner' option and I can't find a specific function in the documentation.
What function can I use to print them? Any suggestion?


  • acrylian Administrator, Developer
    Probably there should be a search field for the owner as there is one for the author of Zenpage items.

    You have two ways to get them instead:
    a) Use the object model (recommended)
    b) Use a MySQL query
    c) Use the object model to assign a tag to each image based on the owner name and then search that one (we use a tag "author_<name>" for credits for example we do that manually as 3rd party authors are no "users" on our site)
  • I cannot use the tag "author_bob" because I'm already using tags to classify images, that tag would appear among the other "true" tags.

    uhm... I already use the object model to assign the owner to the image while uploading (using `$image->setOwner('bob');`), my idea was to recall that by `$_zp_current_image->getOwner();`, modifying somehow search.php... could be that a good idea?
    I haven't clearly understood how a search is done yet, but I think I could clone the model of search by tag and substitute the control on tag with the control on the owner...
  • acrylian Administrator, Developer
    If you want to hide a tag, you can of course use custom tag display functions to filter that. (we have alway a get variant to each print one and of course the object model).

    Modifying the search is surely an option but not recommended because of upgrade. The best would be to open a ticket so it is actually added. Probably it was just forgotten or something. My colleague will be able to answer this I guess.
  • Thank you for the replies, I partially solved with a `$_GET['owner']`: in my case all user images are in the same album; so when I call the album, if I use `?owner=bob` then this variable is passed in the function
    `$personality->theme_content($map, $_GET['owner']);`
    and then used to skip image prints that don't have the requested owner
    `if ($_zp_current_image->getOwner() == $owner || $owner == '') { print the thumbnail }`

    This worked for me, but if you said Stephan could have a cleaner and more general way to get it, I'll wait. However, it will be a nice feature having it among the search fields, in a future release.
  • The simplest way to implent this is to add
    `$this->search_structure['owner'] = gettext('Owner');`
    To the constructor of the search class. Then the field shows up in the option list and can be checked to cause it to be included in on the search form.

    I am sure that it is just an oversite that it is not already included. I will make sure it is part of 1.4.4
  • Thank you, now it seems to work! It was so simply...
  • uhm, I think there is a bug, or something.
    I simply added `$this->search_structure['owner'] = gettext('Owner');` to the class-search _constructor, but when I search by owner it shows me only 11 results, while that user (the admin) has uploaded about 50 images.
    I checked the images not shown in search results, they belongs to that user too.
  • acrylian Administrator, Developer
    Be sure the images are published and look at your search cache settings. by default results are cached 30min to lower overhead.
  • Look in your database. That field may not be set for all the images. When the admin looks at this it uses the object model, so if an image is in an "owned" album it will be marked as owned by the album owner.

    (This is, of course, the problem with just looking at database fields. But I do not know how the serach could do otherwise.)
  • You're right, Stephan. All the images uploaded within the zip has NULL owner (and lot of other fields) in db, even if in the admin panel was assigned to their album's owner.
    It needs to "save" every pages (even without changing anything) in the album/image control panel in order to set the right parameters for every image.
  • Ok. We can make the album owner propegate to the image by adding code to the image updateMetaData() method.

    after the lines that read:
    $alb = $this->album;
    if (!is_null($alb)) {
    if (!$this->get('owner')) {
    Of course, this requires a metadata refresh if the album owner is changed after the image is discovered.

    This will be added to the 1.4.4 release
  • great, it works. Thank you!
  • I should point out the downside of this change. Once the image owner field is set it becomes "disconnected" from the album owner. So changing the album owner does not change the image owner. All further changes have to be made on the image itself.
  • I think album/images structure should be similar to the unix structure of folder/files; the album should have its own owner, so as any image should. In this vision it's natural that album owner is indipendent from any singular image owner. At least zenphoto uses a unix filesystem to manage images, doesn't it? :)
    However it could be nice having an option to change every image owner while changing album owner.
    My 2 cents
  • A bit late to the party here, but I have modified my image.php to include the "owner" label:

    • <?php printImageDate('','',null,true); ?>

    • <?php printImageData('owner'); ?>

      <?php if (strlen($tagstring) > 0) { ?>
    • <?php printTags('links','','taglist', ', '); ?><?php } ?>


      but really I would like this to be a link and a tag allowing clicking on the owner to do a tag search. I see above that you are recommending using the object model to "assign a tag to each image based on the owner name". Can you provide some tips on how to do this?


  • Custom serches can be done on "owner", so a tag may not be needed.

    The link for "owner" should look something like:


    where `` is the owner of the object
  • Great. URL based search is perfect for my needs. Unfortunately the syntax must be off slightly. On my site you can see the owner is "paul" but yields 0 results.
  • acrylian Administrator, Developer
    Did you enable the field owner for search?
  • Also the owner must be set. You may have an "owner" shown because the album is owned without having the image "owner" field populated.
  • So I have both the field enabled for search and I checked the database and indeed there are images with the owner set to "paul", yet the search URL above does not yield any hits. Results are returned when using the Search field. Although I have other owners, "mike" for example that the Search field does not find any results for, even though it should. Could this be a problem with the theme? I noticed that when I use the Search field to search for owner=paul, I get a result set, but when I click on a result, I get the dreaded "Fatal error: Cannot access protected property SearchEngine::$dynalbumname ...".
  • acrylian Administrator, Developer
    Just to be sure: You don't use "owner=paul" in the search field at all. Just "paul". The search engine will in any case search for it in any fields that are enabled for searching.

    Please post the full error message incl. line numbers etc.
  • Your error is definately a theme issue. That property is private to the search engine class. Prior to the requirement to use PHP 5 there was no way to enforce this restriction, so themes may have used the property even though they should not have.

    I did a little testing. Seems that the link needs to have a page # included to work properly, so try:


    Not sure why that is the case, maybe a problem with rewrite rules.
  • Ok, got it. Either:




    Will work. but


    results in the target for "owner" being "paul/". It is a rewrite issue, but I think there is nothing that can be done for it.
Sign In or Register to comment.