We are using Gallery 2.x as in internal stock photo repository for the licensed stock images we purchase and download from various online "lightbox"-type, royalty-free stock photo sites. Because we want to preserve the key words assigned to these images by the provider and often have quite a few to upload at once, I am attempting to add a "keywords" text field to the Add Items > From Web Browser page. So far I have gotten the keywords field to show up by creating a copy of the ItemAddFromBrowser.tpl in the gallery2/modules/core/templates/local folder. I then added the following code on lines 36 and 37:
<h4> {g->text text="Keywords"} </h4>
<textarea rows="2" cols="60" name="{g->formVar var="form[keywords][$iteration]"}"></textarea>
I then edited the gallery2/modules/core/ItemAddFromBrowser.inc file as so:
**line 84 added:
$keywords = empty($file['keywords']) ? '' : $file['keywords'];
**lines 107-108 added:
$newItem->setKeywords($keywords);
$newItem->save();
By using print_r on the $newItem object I can see that the keywords are getting passed to it, but for some reason they are not being saved. My new image is added, including all other entered data, but upon editing the image after initial creation, the keywords field is blank.
Is there a better way to do this? How should I get these keywords to save as part of the initial creation/upload from web browser process? Thanks in advance for any help!
Posts: 8601
maybe add a $ret check for the save() call and see if that reveals the problem.
Posts: 5
Thanks for the reply. It looks like there is an error code burried in the returned GalleryStatus object -- anyone know if there is a list of error codes with explainations out there? Here is the object data:
\GalleryStatus Object
(
[_stack] =>
[_errorCode] => 1025
[_fileName] => Array
(
[0] => /usr/local/www/apache22/data/gallery2/modules/core/classes/GalleryEntity.class
[1] => /usr/local/www/apache22/data/gallery2/modules/core/classes/GalleryItem.class
)
[_lineNumber] => Array
(
[0] => 287
[1] => 411
)
[_errorMessage] =>
[_stackTrace] => Array
(
[0] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/modules/core/classes/GalleryEntity.class
[line] => 287
[function] => error
[class] => GalleryCoreApi
[object] => GalleryPhotoItem Object
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] => keyword test gallery is cool
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[linkedEntity] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
[_persistentStatus] => Array
(
[flags] => 0
[originalValue] => Array
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] =>
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
)
)
)
[type] => ->
[args] => Array
(
[0] => 1024
[1] => /usr/local/www/apache22/data/gallery2/modules/core/classes/GalleryEntity.class
[2] => 287
)
)
[1] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/modules/core/classes/GalleryItem.class
[line] => 409
[function] => save
[class] => GalleryEntity
[object] => GalleryPhotoItem Object
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] => keyword test gallery is cool
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[linkedEntity] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
[_persistentStatus] => Array
(
[flags] => 0
[originalValue] => Array
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] =>
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
)
)
)
[type] => ->
[args] => Array
(
[0] => 1
[1] => 0
)
)
[2] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/modules/core/ItemAddFromBrowser.inc
[line] => 116
[function] => save
[class] => GalleryItem
[object] => GalleryPhotoItem Object
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] => keyword test gallery is cool
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[linkedEntity] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
[_persistentStatus] => Array
(
[flags] => 0
[originalValue] => Array
(
[width] => 1596
[height] => 2400
[mimeType] => image/jpeg
[size] => 1526040
[canContainChildren] => 0
[description] => testing upload "from web browser"
[keywords] =>
[ownerId] => 1374
[summary] => testing upload "from web browser"
[title] => testing upload "from web browser"
[viewedSinceTimestamp] => 1156380096
[originationTimestamp] => 1102443818
[pathComponent] => 19133618_001.jpg
[parentId] => 1358
[id] => 1903
[creationTimestamp] => 1156380096
[isLinkable] => 1
[linkId] =>
[modificationTimestamp] => 1156380097
[serialNumber] => 1
[entityType] => GalleryPhotoItem
[onLoadHandlers] =>
)
)
)
[type] => ->
[args] => Array
(
)
)
[3] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/modules/core/ItemAdd.inc
[line] => 93
[function] => handleRequest
[class] => ItemAddFromBrowser
[object] => ItemAddFromBrowser Object
(
)
[type] => ->
[args] => Array
(
[0] => Array
(
[formName] => ItemAddFromBrowser
[uploadBoxCount] => 20
[caption] => Array
(
[1] => testing upload "from web browser"
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[keywords] => Array
(
[1] => keyword test gallery is cool
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[set] => Array
(
[title] => caption
[summary] => on
[description] => on
)
[CreateThumbnailOption] => Array
(
[createThumbnail] => on
)
[action] => Array
(
[addFromBrowser] => Add Items
)
[name] => Array
(
[1] => 19133618.jpg
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[type] => Array
(
[1] => image/jpeg
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[tmp_name] => Array
(
[1] => /var/tmp/phpj1BjzT
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[error] => Array
(
[1] => 0
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
[9] => 4
[10] => 4
[11] => 4
[12] => 4
[13] => 4
[14] => 4
[15] => 4
[16] => 4
[17] => 4
[18] => 4
[19] => 4
[20] => 4
)
[size] => Array
(
[1] => 1526040
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 0
[12] => 0
[13] => 0
[14] => 0
[15] => 0
[16] => 0
[17] => 0
[18] => 0
[19] => 0
[20] => 0
)
)
[1] => GalleryAlbumItem Object
(
[theme] =>
[orderBy] =>
[orderDirection] => asc
[canContainChildren] => 1
[description] =>
[keywords] => man, male, white caps, capsize, sports, excitement, oar, daylight, recreation, outdoors, lake, adventure, balance, Caucasian, daytime, risk, kayaker, river, caps, helmet, tip over, choppy, white water, fun, outside, paddling, thrill, action
[ownerId] => 6
[summary] => people
[title] => People
[viewedSinceTimestamp] => 1155075342
[originationTimestamp] => 1155075342
[pathComponent] => people
[parentId] => 12
[id] => 1358
[creationTimestamp] => 1155075342
[isLinkable] => 0
[linkId] =>
[linkedEntity] =>
[modificationTimestamp] => 1156375976
[serialNumber] => 45
[entityType] => GalleryAlbumItem
[onLoadHandlers] =>
[_persistentStatus] => Array
(
[flags] => 0
[originalValue] => Array
(
[theme] =>
[orderBy] =>
[orderDirection] => asc
[canContainChildren] => 1
[description] =>
[keywords] => man, male, white caps, capsize, sports, excitement, oar, daylight, recreation, outdoors, lake, adventure, balance, Caucasian, daytime, risk, kayaker, river, caps, helmet, tip over, choppy, white water, fun, outside, paddling, thrill, action
[ownerId] => 6
[summary] => people
[title] => People
[viewedSinceTimestamp] => 1155075342
[originationTimestamp] => 1155075342
[pathComponent] => people
[parentId] => 12
[id] => 1358
[creationTimestamp] => 1155075342
[isLinkable] => 0
[linkId] =>
[modificationTimestamp] => 1156375976
[serialNumber] => 45
[entityType] => GalleryAlbumItem
[onLoadHandlers] =>
)
)
)
)
)
[4] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/main.php
[line] => 199
[function] => handleRequest
[class] => ItemAddController
[object] => ItemAddController Object
(
[_optionInstances] =>
)
[type] => ->
[args] => Array
(
[0] => Array
(
[formName] => ItemAddFromBrowser
[uploadBoxCount] => 20
[caption] => Array
(
[1] => testing upload "from web browser"
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[keywords] => Array
(
[1] => keyword test gallery is cool
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[set] => Array
(
[title] => caption
[summary] => on
[description] => on
)
[CreateThumbnailOption] => Array
(
[createThumbnail] => on
)
[action] => Array
(
[addFromBrowser] => Add Items
)
[name] => Array
(
[1] => 19133618.jpg
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[type] => Array
(
[1] => image/jpeg
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[tmp_name] => Array
(
[1] => /var/tmp/phpj1BjzT
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
[error] => Array
(
[1] => 0
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
[9] => 4
[10] => 4
[11] => 4
[12] => 4
[13] => 4
[14] => 4
[15] => 4
[16] => 4
[17] => 4
[18] => 4
[19] => 4
[20] => 4
)
[size] => Array
(
[1] => 1526040
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 0
[12] => 0
[13] => 0
[14] => 0
[15] => 0
[16] => 0
[17] => 0
[18] => 0
[19] => 0
[20] => 0
)
)
)
)
[5] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/main.php
[line] => 87
[function] => _GalleryMain
[args] => Array
(
[0] =>
)
)
[6] => Array
(
[file] => /usr/local/www/apache22/data/gallery2/main.php
[line] => 80
[function] => GalleryMain
[args] => Array
(
)
)
)
)
Posts: 8601
yikes.. just copy the same error check as you see everywhere, including the return call. then you'll get an error page that formats the error more nicely.
Posts: 5
Sorry - I'm not seeing an "error check", any errors, or an error page. If I don't print_r the contents of the object I get nothing other than normal output. Is there a debug mode that I can turn on somehow? Thanks.
Posts: 8601
after most API calls you should see something like:
you added "$newItem->save();", but it should be:
The above is for current svn.. copy what you see for whatever G2 version you are using. Your ItemAddFromBrowser.inc may have "return array($ret->wrap(__FILE__, __LINE__), null, null);"
Posts: 5
Perfect! Here is the real error now.
Error (ERROR_LOCK_REQUIRED)
* in modules/core/classes/GalleryEntity.class at line 287 (GalleryCoreApi::error)
* in modules/core/classes/GalleryItem.class at line 409 (GalleryEntity::save)
* in modules/core/ItemAddFromBrowser.inc at line 126 (GalleryItem::save)
* in modules/core/ItemAdd.inc at line 93 (ItemAddFromBrowser::handleRequest)
* in main.php at line 199 (ItemAddController::handleRequest)
* in main.php at line 87
* in main.php at line 80
I guess this means that the db, or at least the item, hasn't been unlocked since initially adding it so I am unable to perform an update on it yet. Any suggestion as to a better way to accomplish my goal? I could modify all of the "Item" Classes so that "keywords" is a default creation variable, but that was much more work than just updating it with a few lines of code immediately after creating it.
Posts: 8601
try
list ($ret, $newLockId) = GalleryCoreApi::acquireWriteLock(array($newItem->getId()));
before save() and $ret = GalleryCoreApi::releaseLocks($newLockId); after.
Posts: 5
Mindless, you are my hero. This worked like a charm! Can I buy you lunch sometime? Thanks for all the help.
Posts: 1
I read this useful discussion to implement keywords in ItemAddFromBrowser.
Since it was written one year ago and it's slightly verbose, I submit here a diff to show briefly how to do the job in Gallery 2.2.2. It works, but I never use the patch command to add it into modules/core (I'm a patch newbie ).
If you find any error, please report here.
Posts: 12
hi guys/gals
i'm using gallery 2.2.3
thanks to this very thread i know that "ItemAddFromBrowser" doesn't fully work since keywords aren't added to the photo in the database even if the option is checked well
i understand now why my search didn't gave any answers while the iptc keyword field was correct
is there a way, once the photos are uploaded, to populate keywords in the database from the iptc fields ?
i've checked that "add item from local server" works, keywords are added, but i'd really like to avoid this process
(first post here, sincere thanks for this gem app)
Posts: 41
Sorry but I have added this file into indicated directory but nothing change.
There is a way to run this patch ?(I'm a newbie in everything).
If not, I have not understand the clear process to add the keyword to ItemAddFromBrowser and not only in Edit Module.
Moreover, I would like to as for two improvementes (if possibile)
1. it's possibile to oblige users to insert keywords ?
2. It's possibile to set, as keywords, two dropdown menu with preset choices ?
Thank U once more, and sorry if the questions are so stupid ;)
Versione di Gallery = 2.2.4 core 1.2.0.6
Versione PHP = 4.4.7 apache2handler
Webserver = Apache/2.0.52 (CentOS)
Posts: 41
Ok, I found myself how run the patch... and everything now it's ok.
Remain the two questions, regarding the two improvements (if possibile)
1. it's possibile to oblige users to insert keywords ?
2. It's possibile to set, as keywords, two dropdown menu with preset choices ?
ThxU
Versione di Gallery = 2.2.4 core 1.2.0.6
Versione PHP = 4.4.7 apache2handler
Webserver = Apache/2.0.52 (CentOS)
Posts: 41
No ideas ?
Versione di Gallery = 2.2.4 core 1.2.0.6
Versione PHP = 4.4.7 apache2handler
Webserver = Apache/2.0.52 (CentOS)