feature 2955: make the keywords separator configurable

git-svn-id: http://piwigo.org/svn/trunk@31097 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall
2015-04-21 12:07:14 +00:00
parent 796ac2f531
commit b3541bf16b
2 changed files with 38 additions and 14 deletions

View File

@@ -68,20 +68,7 @@ function get_sync_iptc_data($file)
if (isset($iptc['keywords']))
{
// official keywords separator is the comma
$iptc['keywords'] = preg_replace('/[.;]/', ',', $iptc['keywords']);
$iptc['keywords'] = preg_replace('/,+/', ',', $iptc['keywords']);
$iptc['keywords'] = preg_replace('/^,+|,+$/', '', $iptc['keywords']);
$iptc['keywords'] = implode(
',',
array_unique(
explode(
',',
$iptc['keywords']
)
)
);
$iptc['keywords'] = metadata_normalize_keywords_string($iptc['keywords']);
}
foreach ($iptc as $pwg_key => $value)
@@ -122,6 +109,12 @@ function get_sync_exif_data($file)
continue;
}
}
if (in_array($pwg_key, array('keywords', 'tags')))
{
$exif[$pwg_key] = metadata_normalize_keywords_string($exif[$pwg_key]);
}
$exif[$pwg_key] = addslashes($exif[$pwg_key]);
}
@@ -351,4 +344,31 @@ SELECT id, path, representative_ext
return hash_from_query($query, 'id');
}
/**
* Returns the list of keywords (future tags) correctly separated with
* commas. Other separators are converted into commas.
*
* @param string $keywords_string
* @return string
*/
function metadata_normalize_keywords_string($keywords_string)
{
global $conf;
$keywords_string = preg_replace($conf['metadata_keyword_separator_regex'], ',', $keywords_string);
$keywords_string = preg_replace('/,+/', ',', $keywords_string);
$keywords_string = preg_replace('/^,+|,+$/', '', $keywords_string);
$keywords_string = implode(
',',
array_unique(
explode(
',',
$keywords_string
)
)
);
return $keywords_string;
}
?>

View File

@@ -371,6 +371,10 @@ $conf['use_exif_mapping'] = array(
// javascript)
$conf['allow_html_in_metadata'] = false;
// decide which characters can be used as keyword separators (works in EXIF
// and IPTC). Coma "," cannot be removed from this list.
$conf['metadata_keyword_separator_regex'] = '/[.,;]/';
// +-----------------------------------------------------------------------+
// | sessions |
// +-----------------------------------------------------------------------+