Skip to content

Commit

Permalink
feature 2955: make the keywords separator configurable
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@31097 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Apr 21, 2015
1 parent 796ac2f commit b3541bf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
48 changes: 34 additions & 14 deletions admin/include/functions_metadata.php
Expand Up @@ -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)
Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -351,4 +344,31 @@ function get_filelist($category_id = '', $site_id=1, $recursive = false,
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;
}
?>
4 changes: 4 additions & 0 deletions include/config_default.inc.php
Expand Up @@ -371,6 +371,10 @@
// 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 |
// +-----------------------------------------------------------------------+
Expand Down

0 comments on commit b3541bf

Please sign in to comment.