function _metatag_importer_convert_data in Metatag 7
Converts a meta tag's name and value from Nodewords to Metatag format.
Parameters
string $name: Meta tag name.
string $value: Meta tag value in Nodewords format.
Return value
array The two arguments returned after being converted.
1 call to _metatag_importer_convert_data()
- _metatag_importer_migrate in metatag_importer/
metatag_importer.nodewords.inc - Batch API callback to convert Nodewords data to the Metatag module.
File
- metatag_importer/
metatag_importer.nodewords.inc, line 479 - Convert data from Nodewords to Metatag.
Code
function _metatag_importer_convert_data($name, $value) {
// Initial simplification of simple values.
if (is_array($value) && isset($value['value']) && count($value) === 1 && empty($value['value'])) {
$value = FALSE;
}
// Reformat the meta tag data, and possibly name.
switch ($name) {
// The Dublin Core date value was stored as three separarate strings.
case 'dcterms.date':
// Skip this value if it doesn't contain an array of three values.
if (!is_array($value) || empty($value['month']) || empty($value['day']) || empty($value['year'])) {
$value = FALSE;
}
else {
$date = mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
$value = date('Y-m-d\\TH:iP', $date);
}
break;
// The location meta tag gets renamed and converted to a semi-colon
// -separated string.
case 'location':
// Catch empty values.
if (!is_array($value) || empty($value['latitutde']) || empty($value['longitude'])) {
$value = FALSE;
}
else {
$name = 'geo.position';
$value = implode(';', $value);
}
break;
// These values always seem to be wrong, just use the Metatag defaults.
case 'og:type':
$value = FALSE;
break;
// Nodewords handle the title tag differently.
case 'page_title':
$name = 'title';
// Remove two options that are no longer used.
unset($value['append']);
unset($value['divider']);
break;
// A bug in Nodewords resulted in lots of junk data for this meta tag.
case 'revisit-after':
if (isset($value['value']) && intval($value['value']) === 1) {
$value = FALSE;
}
break;
// Robots needs some extra processing.
case 'robots':
// The value didn't exist or it was set to use the defaults.
if (!is_array($value) || empty($value['value']) || !empty($value['use_default'])) {
$value = FALSE;
}
else {
$robot_data = array();
// Convert each value to display the name if it is "on" and 0 if it is
// off.
$found = FALSE;
foreach ($value['value'] as $robot_key => $robot_val) {
// Ignore junk values.
if ($robot_key == 'value') {
continue;
}
elseif (!empty($robot_val)) {
$robot_data[$robot_key] = $robot_key;
$found = TRUE;
}
}
// Catch empty values.
if (empty($robot_data)) {
$value = FALSE;
}
else {
$value = array(
'value' => $robot_data,
);
}
}
break;
// This meta tag was renamed.
case 'shorturl':
$name = 'shortlink';
break;
// Everything else should be ok.
default:
}
// A final tidy-up.
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = trim($val);
}
$value = array_filter($value);
}
return array(
$name,
$value,
);
}