Phoca Gallery Plugin - Tags

Phoca Gallery plugins - plugins for Phoca Gallery extension
sachiel
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 May 2012, 19:19

Phoca Gallery Plugin - Tags

Post by sachiel »

Lacking any ability to display all photos in a gallery using the new Tag features, I edited the phocagallery.php to produce the effect I wanted. Here's the code for anyone that is interested. I love the Tag feature, and hope the Phoca team takes advantage of it more in the future. A Tag button on the administrator Images page would be great: check a bunch of images, then hit the Tag button and apply selected Tags to the images.

Usage example:
{phocagallery view=tag|tagname=Cersei|limitstart=0|limitcount=5|detail=1|displayname=1|displaydetail=1|displaydownload=1}

The "categoryid" switch is optional, but will limit the tag search to a category, but I wanted to search through ALL of my categories and subcategories for anything tagged.

(Line numbers are approximate because I did insert additional commenting)
INSERT Line 125:

Code: Select all

$tag_name = $paramsC->get( 'tag_name', ''); 
INSERT Line 223:

Code: Select all

else if($values[0]=='tagname')    {$tag_name = $values[1];} 
EDIT Line 935:

Code: Select all

if (($view == 'category') || ($view == 'tag')) { 
EDIT Line 981:

Code: Select all

if ($view == 'category') {
    $query = 'SELECT cc.id, cc.alias as catalias, a.id, a.catid, a.title, a.alias, a.filename, a.description, a.extm, a.exts, a.extw, a.exth, a.extid, a.extl, a.exto,'
    . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug, '
    . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
    . ' FROM #__phocagallery_categories AS cc'
    . ' LEFT JOIN #__phocagallery AS a ON a.catid = cc.id'
    . ' WHERE a.catid = '.(int) $catid
    . ' AND a.published = 1'
    . ' AND a.approved = 1'
    . ' AND cc.published = 1'
    . ' AND cc.approved = 1'
    . $where
    . $imageOrdering
    . $limit;
} elseif ($view == 'tag') {
    if ($catid > 0 ) {
        $where = $where . ' AND a.catid = '.(int) $catid;
    }
                    
    $query = 'SELECT cc.id, cc.alias as catalias, a.id, a.catid, a.title, a.alias, a.filename, a.description, a.extm, a.exts, a.extw, a.exth, a.extid, a.extl, a.exto,'
    . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug, '
    . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'
    . ' FROM #__phocagallery_categories AS cc'
    . ' LEFT JOIN #__phocagallery AS a ON a.catid = cc.id'
    . ' INNER JOIN #__phocagallery_tags_ref as tr ON a.id = tr.imgid'
    . ' INNER JOIN #__phocagallery_tags as t ON t.id = tr.tagid'
    . ' WHERE t.title LIKE \'' . $tag_name . '\''
    . ' AND a.published = 1'
    . ' AND a.approved = 1'
    . ' AND cc.published = 1'
    . ' AND cc.approved = 1'
    . ' AND t.published = 1'
    . $where
    . $imageOrdering
    . $limit;
} 
sachiel
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 May 2012, 19:19

Re: Phoca Gallery Plugin - Tags

Post by sachiel »

Edited to include check for Tag published.

You could do it by id on the #__phocagallery_tags table, but you wouldn't cut out the join check for the Tag->published.

Here's an example: kominekafghans.com/index.php/soleil-photos That will go through all of my gallery and put up a random page of all the photos I've tagged "Soleil." Only html in the article is the single line for the Phoca Plugin call.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Phoca Gallery Plugin - Tags

Post by Jan »

Hi, thank you for this guide.

Jan
If you find Phoca extensions useful, please support the project
viltnieks
Phoca Member
Phoca Member
Posts: 10
Joined: 15 Mar 2012, 15:08

Re: Phoca Gallery Plugin - Tags

Post by viltnieks »

Thank you for this great guide, this really helped me.

I tried replicating this in a module, but I understand that it's quite a bit more complicated.

Would be nice if you could display images by tags using module though :)
sachiel
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 May 2012, 19:19

Re: Phoca Gallery Plugin - Tags

Post by sachiel »

So, coming back to this and using Tags more throughout my Phoca Gallery.

So when you create a Tag, you can associate a category with it. That category is unused as far as I can tell anywhere else in Phoca Gallery. When you insert images into a tagged category, I expect the picture to be automatically tagged as well, but it is not. Even if you multiple insert images, you have to individually edit each one and associate the corresponding tag. Frustrated, I resorted to PhpMyAdmin and started poking around the database. After some discovery, I came up with this SQL:

Code: Select all

REPLACE INTO #__phocagallery_tags_ref (imgid, tagid)
SELECT a.id as imgid, b.id as tagid 
FROM #__phocagallery a 
LEFT JOIN #__phocagallery_tags b ON a.catid = b.link_cat 
WHERE b.link_cat != 0
What this does is look through all of your images that reside in a category which has a tag associated with it. It will then create or update the appropriate tag reference in the table. Using this, you can insert a bunch of images into an appropriate category, run the script on the database and then have all the tags generated. This is a retroactive fix for things that went untagged.

Now, my question is: why isn't this done automatically? I figure you would want to fix this in the model, but alternatively, I could just put a trigger on the image table so that whenever one is inserted, I do an tag/cat lookup and insert into tag ref table.
sachiel
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 May 2012, 19:19

Re: Phoca Gallery Plugin - Tags

Post by sachiel »

Well, I know it's not the preferred way, but this worked for me. I created a trigger on the image table that performs an insert into the tag-reference table, looking up all the tags that have a link_cat as the same catid as the inserted image. :

Code: Select all

DELIMITER |

CREATE TRIGGER tr_phocagallery_afterinsert AFTER INSERT ON #__phocagallery
FOR EACH ROW
BEGIN
INSERT INTO #__phocagallery_tags_ref (imgid, tagid)
SELECT NEW.id as imgid, a.id as tagid 
FROM #__phocagallery_tags a
WHERE a.link_cat = NEW.catid;

END;

|
DELIMITER ;
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Phoca Gallery Plugin - Tags

Post by Jan »

Hi, ok, thank you for the guide.

Anyway I don't understand what you mean with "automaticaly adding of tags" - if you are adding images to Phoca Gallery, how the system should know which tag each image should include? Tags are different for each image, tag can be different for image a or image b in category c.

Jan
If you find Phoca extensions useful, please support the project
sachiel
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 May 2012, 19:19

Re: Phoca Gallery Plugin - Tags

Post by sachiel »

Jan wrote:Hi, ok, thank you for the guide.

Anyway I don't understand what you mean with "automaticaly adding of tags" - if you are adding images to Phoca Gallery, how the system should know which tag each image should include? Tags are different for each image, tag can be different for image a or image b in category c.

Jan
While this is true, if you tag a category "food", and you upload a bunch of pictures of different foods, ex: steak dinners, hamburgers, salad, milkshake, while you couldn't specify specific tags for each photo when you perform a multiple add, it would be nice if each photo was simply tagged "food." It's very useful for broad tagging, and if you want to get into specifics later, you could individually.

In my case, I have a kennel website where I have a folder for each dog that I upload pictures of that dog into, usually random photos of her taken at home, at an event, by friends, whatever. I tag the category "Cersei" (one of their names) and link it to a specifc folder \cersei. When I upload images to that folder, do a multiple add of all her photos and put them in the "Cersei" category, I'd like them to all be tagged "Cersei." I also have event folders, so there will be a \2013-11-05-lure-coursing folder, but that will be pictures of many dogs running, but would individually tag Cersei in each of those photos where applicable. When I do a phoca plug on tags like the first post, I want them to pull anything in any album tagged Cersei. Does that make sense?
Brunobdm
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 26 Aug 2012, 15:39

Re: Phoca Gallery Plugin - Tags

Post by Brunobdm »

Unfortunately I could not put to display images based on tags. I'm using the newest version of phoca gallery.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Phoca Gallery Plugin - Tags

Post by Jan »

Hi,
sachiel
Added to the feature request list (needs to be reviewed if e.g. if all images have the same tag, if this is not a kind of duplicity, etc. :idea:)

Brunobdm
Sorry, I don't understand.
If you find Phoca extensions useful, please support the project
Post Reply