auto generate dynamic Albums

Hi,
I am currently migrating my phography website into Zenphoto and am particuarly interested
in the dynamic albums. Can any of you senior users help me to achieve the following.
Out of all existing tags I would like to run all permutations of (two tags max) against the database. In case there is 3 or more results I would then like to automatically save those as dynamic albums.

Can anyone help me with this ?

Comments

  • So, I hope you have some skills with SQL and some programming language (from which you can run SQL commands)!

    There are two tables involved with tags:

    First, there is the `tags` table itself which is a set of the text values of each tags. Given a tag "id" this table will give you its textual representation.

    Then there is the `obj_to_tag` table. This is a many to one set of tags to zenphoto elements. The `type` field tells you what kind of zenphoto object. In your case you would be intersed in the fields where the type field is "images". The `tagid` field is the index into the `tag` table. The `objectid` is the record id of the zenphoto object (for instance of the image).

    So you can query this table, do your permutation computations and end up with the pairs of tags you discover. From there you create a file in the appropraite album folder named `dynamicalbum_name``.alb` the contents of that file is the search string, thumbnail assignment and search fields. You can create a simple dynamic album from two tags to see the exact format of the file.
  • Ok, thanks I will get to work on those.
    Looks like I should run that as a cron job once a days instead of on the fly I got about 91 combinations of tags

    Thanks / Daniel
  • Hi,
    I have finished what I had talked about above and would like to share it now for inspiration to others.
    I have created a custom function which permutes through all existing combination's of two tags, searches for matching images and if at least one is found it will
    then create a dynamic album called 'tag1 & tag2'.

    At the moment it is set to recreate every hour (called from header.php), not because of new tags but the SQL also shuffles the order in which they are created and so the album page varies nicely.
    potentially once I start being LIVE with ZP I will properly ,for the sake of speed, limit the album creation to minimum of 3 or more matching images.
    But till now it works nicely

    Have a look: http://www.dev.bregler.net/gallery

    function produce_dynalbums($path = '') {

    $path = $_SERVER["DOCUMENT_ROOT"].$path;

    $Diff = (time() - filemtime("$path/portraits.alb"))/60/60;
    if ($Diff > 1) // 1 hour
    {
    foreach (glob($path."*.alb") as $filename) {
    unlink($filename);
    }

    $result = mysql_query("select count(*) as hitcount, t3.name,t4.name from (SELECT distinct t1.objectid, t1.tagid as tag1,t2.tagid as tag2 FROM zp_obj_to_tag as t1 left join `zp_obj_to_tag` as t2 on t1.objectid=t2.objectid and t1.id>t2.id and t2.type='images' where t1.type='images' ) dbr left join zp_tags t3 on dbr.tag1=t3.id left join zp_tags t4 on dbr.tag2=t4.id left join zp_images as i on dbr.objectid=i.id where title is not NULL group by t3.name,t4.name order by rand()");
    $dbfields = array();
    while ($row = mysql_fetch_row($result)) {

    $fileContainer = $path.$row[1];
    if ($row[2]) $fileContainer = $fileContainer."_".$row[2];
    $fileContainer = $fileContainer.".alb";
    $filePointer = fopen($fileContainer,"w+");
    $fileContent = "WORDS=".$row[1];
    if ($row[2]) $fileContent = $fileContent." AND ".$row[2];
    $fileContent = $fileContent."\n";
    fputs($filePointer,"$fileContent");
    fputs($filePointer,"THUMB=\n");
    fputs($filePointer,"FIELDS=tags\n");
    fclose($filePointer);
    }

    }

    }
  • acrylian Administrator, Developer
    I haven't looked in details but this would perhaps make a nice plugin, too (hint, hint..;-))

    Btw, if you are located in Germany, your site is missing the required impressum...
  • I am not actually, but I am German. ;)
    My layout is far from finished; it will happen
    I will see about the plugin when time permits after my go-live
Sign In or Register to comment.