fix_references.inc in File (Field) Paths 6.2
File
includes/fix_references.inc
View source
<?php
function _filefield_paths_include_fix_references_filefield_paths_file_postprocess($source, $file, $node, $setings) {
$file_directory_path = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC ? file_directory_path() : 'system/files';
$pattern = array(
'find' => str_replace('/', '\\/', quotemeta($file_directory_path)) . '([^"]*?)' . str_replace('/', '\\/', quotemeta(str_replace(file_directory_path(), '', $source))),
'replace' => $file_directory_path . '$1' . str_replace(file_directory_path(), '', $file['filepath']),
);
if (_filefield_paths_replace_pattern($pattern, $node)) {
global $user;
drupal_write_record('node', $node, 'nid');
_node_save_revision($node, $user->uid, 'vid');
}
}
function _filefield_paths_replace_pattern($pattern, &$node) {
$update = FALSE;
$fields = _filefield_paths_fix_references_fields($node);
foreach ($fields as &$field) {
}
return $update;
}
function _filefield_paths_fix_references_fields($node) {
static $fields = array();
if (!isset($fields[$node->type]) || !is_array($fields[$node->type])) {
if (isset($node->body)) {
$fields[$node->type]['body'] =& $node->body;
$fields[$node->type]['teaser'] =& $node->body;
}
if (isset($node->teaser)) {
$fields['teaser'] =& $node->teaser;
}
$content_type = content_types($node->type);
foreach ($content_type['fields'] as $name => $field) {
if ($field['type'] == 'text' && is_array($node->{$name})) {
foreach ($node->{$name} as $key => $value) {
if (isset($node->{$name}[$key]['value'])) {
$fields["{$name}_{$key}"] =& $node->{$name}[$key]['value'];
}
}
}
}
}
return $fields[$node->type];
}