serendipity_pickKey oddness
Posted: Tue Feb 19, 2008 5:52 pm
The serendipity_pickKey function works differently than I expected. Here's the code, for a quick reminder (same in 1.2 branch and trunk):
I was expecting a key from the passed array to be returned. What actually happens is the first key in an array nested within the passed array is returned. Keys in the passed array are not considered.
I checked, and pickKey is not used in any templates. It and its Smarty wrapper, serendipity_smarty_pickKey, are actually used only in the functions_images.inc.php, for serendipity_parseMediaProperties(). It's used to get and set the DATE, RUN_LENGTH, DPI, COPYRIGHT, TITLE, COMMENT1, and COMMENT2 image fields.
These, in turn, are used in the media selector.
I'd like to modify pickKey to work as I expected. Is the media selector displaying the image properties as expected? (I don't have properties on any of my images, so far as I'm aware, so I can't check it.) If it's not, perhaps I've found the problem.
If so, I'll need to do something a little more devious.
Anybody use the media metadata in their media selection?
Code: Select all
/* Picks a specified key from an array and returns it
*
* @access public
* @param array The input array
* @param string The key to search for
* @param string The default value to return when not found
* @return null
*/
function &serendipity_pickKey(&$array, $key, $default) {
if (!is_array($array)) {
return $default;
}
foreach($array AS $child) {
if (is_array($child) && isset($child[$key]) && !empty($child[$key])) {
return $child[$key];
}
}
return $default;
}
I checked, and pickKey is not used in any templates. It and its Smarty wrapper, serendipity_smarty_pickKey, are actually used only in the functions_images.inc.php, for serendipity_parseMediaProperties(). It's used to get and set the DATE, RUN_LENGTH, DPI, COPYRIGHT, TITLE, COMMENT1, and COMMENT2 image fields.
These, in turn, are used in the media selector.
I'd like to modify pickKey to work as I expected. Is the media selector displaying the image properties as expected? (I don't have properties on any of my images, so far as I'm aware, so I can't check it.) If it's not, perhaps I've found the problem.
Anybody use the media metadata in their media selection?