contrib modules security updates
This commit is contained in:
@@ -4,91 +4,139 @@
|
||||
* @file
|
||||
* On behalf implementation of Feeds mapping API for file.module and
|
||||
* image.module.
|
||||
*
|
||||
* Does actually not include mappers for field types defined in fields module
|
||||
* (because there aren't any) but mappers for all fields that contain their
|
||||
* value simply in $entity->fieldname['und'][$i]['value'].
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter().
|
||||
*
|
||||
* @see FeedsNodeProcessor::getMappingTargets().
|
||||
* Implements hook_feeds_processor_targets().
|
||||
*/
|
||||
function file_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
function file_feeds_processor_targets($entity_type, $bundle_name) {
|
||||
$targets = array();
|
||||
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
|
||||
if (in_array($info['type'], array('file', 'image'))) {
|
||||
$targets[$name] = array(
|
||||
'name' => check_plain($instance['label']),
|
||||
$targets[$name . ':uri'] = array(
|
||||
'name' => t('@label: URI', array('@label' => $instance['label'])),
|
||||
'callback' => 'file_feeds_set_target',
|
||||
'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
|
||||
'description' => t('The URI of the @label field.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
|
||||
// Keep the old target name for backwards compatibility, but hide it from
|
||||
// the UI.
|
||||
$targets[$name] = $targets[$name . ':uri'];
|
||||
$targets[$name]['deprecated'] = TRUE;
|
||||
|
||||
if ($info['type'] == 'image') {
|
||||
$targets[$name . ':alt'] = array(
|
||||
'name' => t('@label: Alt', array('@label' => $instance['label'])),
|
||||
'callback' => 'file_feeds_set_target',
|
||||
'description' => t('The alt tag of the @label field.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
$targets[$name . ':title'] = array(
|
||||
'name' => t('@label: Title', array('@label' => $instance['label'])),
|
||||
'callback' => 'file_feeds_set_target',
|
||||
'description' => t('The title of the @label field.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
}
|
||||
elseif ($info['type'] === 'file') {
|
||||
$targets[$name . ':description'] = array(
|
||||
'name' => t('@label: Description', array('@label' => $instance['label'])),
|
||||
'callback' => 'file_feeds_set_target',
|
||||
'description' => t('The description of the @label field.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for mapping. Here is where the actual mapping happens.
|
||||
*
|
||||
* When the callback is invoked, $target contains the name of the field the
|
||||
* user has decided to map to and $value contains the value of the feed item
|
||||
* element the user has picked as a source.
|
||||
* Callback for mapping file fields.
|
||||
*/
|
||||
function file_feeds_set_target($source, $entity, $target, $value) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
module_load_include('inc', 'file');
|
||||
function file_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
|
||||
$language = $mapping['language'];
|
||||
|
||||
// Make sure $value is an array of objects of type FeedsEnclosure.
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
foreach ($value as $k => $v) {
|
||||
if (!($v instanceof FeedsEnclosure)) {
|
||||
if (is_string($v)) {
|
||||
$value[$k] = new FeedsEnclosure($v, file_get_mimetype($v));
|
||||
}
|
||||
else {
|
||||
unset($value[$k]);
|
||||
// Add default of uri for backwards compatibility.
|
||||
list($field_name, $sub_field) = explode(':', $target . ':uri');
|
||||
$info = field_info_field($field_name);
|
||||
|
||||
if ($sub_field == 'uri') {
|
||||
|
||||
foreach ($values as $k => $v) {
|
||||
if (!($v instanceof FeedsEnclosure)) {
|
||||
if (is_string($v)) {
|
||||
$values[$k] = new FeedsEnclosure($v, file_get_mimetype($v));
|
||||
}
|
||||
else {
|
||||
// Set the value for FALSE rather than remove it to keep our deltas
|
||||
// correct.
|
||||
$values[$k] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine file destination.
|
||||
// @todo This needs review and debugging.
|
||||
list($entity_id, $vid, $bundle_name) = entity_extract_ids($entity->feeds_item->entity_type, $entity);
|
||||
$instance_info = field_info_instance($entity->feeds_item->entity_type, $target, $bundle_name);
|
||||
$info = field_info_field($target);
|
||||
$data = array();
|
||||
if (!empty($entity->uid)) {
|
||||
$data[$entity->feeds_item->entity_type] = $entity;
|
||||
if ($entity instanceof Entity) {
|
||||
$entity_type = $entity->entityType();
|
||||
$bundle = $entity->bundle();
|
||||
}
|
||||
else {
|
||||
$entity_type = $source->importer->processor->entityType();
|
||||
$bundle = $source->importer->processor->bundle();
|
||||
}
|
||||
$instance_info = field_info_instance($entity_type, $field_name, $bundle);
|
||||
|
||||
// Determine file destination.
|
||||
// @todo This needs review and debugging.
|
||||
$data = array();
|
||||
if (!empty($entity->uid)) {
|
||||
$data[$entity_type] = $entity;
|
||||
}
|
||||
|
||||
$destination = file_field_widget_uri($info, $instance_info, $data);
|
||||
}
|
||||
$destination = file_field_widget_uri($info, $instance_info, $data);
|
||||
|
||||
// Populate entity.
|
||||
$i = 0;
|
||||
$field = isset($entity->$target) ? $entity->$target : array();
|
||||
foreach ($value as $v) {
|
||||
try {
|
||||
$file = $v->getFile($destination);
|
||||
$field = isset($entity->$field_name) ? $entity->$field_name : array($language => array());
|
||||
$delta = 0;
|
||||
foreach ($values as $v) {
|
||||
if ($info['cardinality'] == $delta) {
|
||||
break;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
|
||||
|
||||
if (!isset($field[$language][$delta])) {
|
||||
$field[$language][$delta] = array();
|
||||
}
|
||||
if ($file) {
|
||||
$field['und'][$i] = (array)$file;
|
||||
$field['und'][$i]['display'] = 1; // @todo: Figure out how to properly populate this field.
|
||||
if ($info['cardinality'] == 1) {
|
||||
|
||||
switch ($sub_field) {
|
||||
case 'alt':
|
||||
case 'title':
|
||||
case 'description':
|
||||
$field[$language][$delta][$sub_field] = $v;
|
||||
break;
|
||||
|
||||
case 'uri':
|
||||
if ($v) {
|
||||
try {
|
||||
$v->setAllowedExtensions($instance_info['settings']['file_extensions']);
|
||||
$field[$language][$delta] += (array) $v->getFile($destination);
|
||||
// @todo: Figure out how to properly populate this field.
|
||||
$field[$language][$delta]['display'] = 1;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog('feeds', check_plain($e->getMessage()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$delta++;
|
||||
}
|
||||
$entity->{$target} = $field;
|
||||
|
||||
$entity->$field_name = $field;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user