Member
Member
maxslug   2010-02-01, 22:21
#1

Hi,

Is there any function to do the same as printAllTagsAs("cloud"), but limit the results to only tags present in the current album's pictures?

I checked the API (http://www.zenphoto.org/documentation/functions/_template-functions.php.html) and plugins, but didn't see anything.

Here is the SQL to accomplish it. If there's not something that does this right now, I'll roll my own...

`
mysql> select t.tagid, tags.name, i.albumid, count(*)
from zp_obj_to_tag AS t
left join (zp_images as i, zp_tags as tags) ON (t.objectid = i.id AND tags.id= t.tagid)
where t.type = 'images' and i.albumid=67
group by t.tagid;

+-------+---------------+---------+----------+
| tagid | name | albumid | count(*) |
+-------+---------------+---------+----------+
| 6 | thailand | 67 | 359 |
| 7 | bangkok | 67 | 58 |
| 8 | temple | 67 | 33 |
| 9 | max | 67 | 36 |
| 10 | kristi | 67 | 45 |
| 11 | beer | 67 | 10 |
| 12 | market | 67 | 79 |
| 13 | chiang mai | 67 | 155 |
| 14 | hdr | 67 | 2 |
| 15 | cooking class | 67 | 36 |
| 16 | sammy's | 67 | 36 |
| 17 | fongshot | 67 | 9 |
| 18 | phuket | 67 | 8 |
| 19 | samui | 67 | 15 |
| 20 | gap | 67 | 102 |
| 21 | sailing | 67 | 102 |
| 22 | phi phi | 67 | 20 |
| 23 | ladyboi | 67 | 5 |
+-------+---------------+---------+----------+
18 rows in set (0.04 sec)
`
Thanks,
-m

Member
Member
sbillard   2010-02-01, 23:09
#2

does the printTags() function not do what you wish? If it does not, then there is not probably a function which does.

Member
Member
maxslug   2010-02-01, 23:29
#3

printTags() didn't quite do it for me, thanks though.

Here's my first stab at it, any improvements or feedback welcome. Chunks of this are obviously lifted straight from zp-core/*.php.

TODO: Make the magic numbers options in the theme (or arguments to the function if you guys want to use this).

`
function FlickrishPrintAlbumTagCloud( ) {
$sql = "SELECT t.tagid, tags.name, COUNT(*) AS count FROM ".
prefix('obj_to_tag').
" AS t LEFT JOIN (".
prefix('images'). "AS i, ".
prefix('tags'). "AS tags)".
" ON (t.objectid = i.id AND tags.id= t.tagid)".
" WHERE t.type = 'images'".
" AND i.albumid=".getAlbumId().
" GROUP BY t.tagid";

echo $sql;


$tags = query_full_array($sql);
if (!is_array($tags)) {
    return;
}
$size_min = 0.8; // ALLTAGS_MINFONTSIZE TODO: make param of theme
$size_max = 3.0;
$count_min = 1;
$count_max = 200;

foreach ($tags as $row) {
    $count = $row['count'];
    $tid   = $row['tagid'];
    $tname = $row['name'];
    // TODO: use distribution instead of linear fn
    $size = min(max(round(($size_max*($count-$count_min))/($count_max-$count_min),
                    2), $size_min)
                ,$size_max);
    $size = str_replace(',','.', $size);

    # TODO: specifying the album doesn't work for some reason.
    #htmlspecialchars(getSearchURL($tname, '', 'tags', 0, array(getAlbumId()))).

    echo "".
        "$tname\n";
}

}
`
Then in album.php :

`

`
And in theme.css :

div.albumTags A { margin-left: 5px; margin-right: 5px; white-space: nowrap; }

Member
Member
sbillard   2010-02-01, 23:47
#4

If you want to share this, you could make a plugin which contains the function. We will add that to the plugins list on the web site.

Administrator
Administrator
acrylian   2010-02-09, 14:51
#5

Btw, #htmlspecialchars(getSearchURL($tname, '', 'tags', 0, array(getAlbumId()))). does not work because Zenphoto's object model always works with the NAME and not the ID of items. Using the album folder name in the sql would probably also make it easier to get tags for an album incl. its subalbums as well. (JOIN queries are not really my speciality though...)

Administrator
Administrator
acrylian   2010-03-16, 20:55
#6

FYI, the current nightly contains a plugin "tags_from_album" which is based on your query.

Member
Member
maxslug   2010-05-18, 18:09
#7

Great, nice to see this officially supported!

Administrator
Administrator
acrylian   2010-05-18, 18:23
#8

The query itself actually did not make it as it caused some issues I don't remember, but the idea itself did..;-)

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.