function filefield_paths_nodeapi in File (Field) Paths 5
Same name and namespace in other branches
- 6.2 filefield_paths.module \filefield_paths_nodeapi()
- 6 filefield_paths.module \filefield_paths_nodeapi()
Implementation of hook_nodeapi().
2 calls to filefield_paths_nodeapi()
- filefield_filefield_paths_update in modules/
filefield.inc - Implementation of hook_filefield_paths_batch_update().
- upload_filefield_paths_update in modules/
upload.inc - Implementation of hook_filefield_paths_batch_update().
File
- ./
filefield_paths.module, line 289 - Adds extra functionality to FileFields Path settings.
Code
function filefield_paths_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'submit':
if (module_exists('content')) {
$content_type = content_types($node->type);
foreach ($content_type['fields'] as $field) {
if (preg_match('/\\bfile\\b|\\bimage\\b/', $field['type']) && is_array($node->{$field}['field_name'])) {
foreach ($node->{$field}['field_name'] as $count => &$file) {
if (empty($file['filepath'])) {
continue;
}
// If file is newly uploaded, flag to be processed
if ($file['fid'] == 'upload') {
$file['data']['process'] = TRUE;
}
}
}
}
}
break;
case 'insert':
case 'update':
$update = new stdClass();
$update->node = FALSE;
if (($ffp = filefield_paths_get_fields($node)) == FALSE) {
break;
}
// Process files.
foreach ($ffp['#files'] as &$file) {
// Convert Upload.module file to Array.
if ($file['module'] == 'upload') {
$file['field'] = (array) $file['field'];
}
module_invoke_all('filefield_paths_process_file', $file['new'], $file, $ffp['#settings'][$file['name']], $node, $update);
// Convert Upload.module file back to Object.
if ($file['module'] == 'upload') {
$file['field'] = (object) $file['field'];
}
}
// Re-write node entry if required.
if ($update->node == TRUE) {
$arr = array();
foreach ($node_table_types as $key => $value) {
$arr[] = $key . ' = ' . $value;
}
$node_table_values[] = $node->nid;
$node_query = 'UPDATE {node} SET ' . implode(', ', $arr) . ' WHERE nid = %d';
if ($node->revision) {
$revisions_query = 'INSERT INTO {node_revisions} (' . implode(', ', array_keys($revisions_table_types)) . ') VALUES (' . implode(', ', $revisions_table_types) . ')';
}
else {
$arr = array();
foreach ($revisions_table_types as $key => $value) {
$arr[] = $key . ' = ' . $value;
}
$revisions_table_values[] = $node->vid;
$revisions_query = 'UPDATE {node_revisions} SET ' . implode(', ', $arr) . ' WHERE vid = %d';
}
db_query($node_query, $node_table_values);
db_query($revisions_query, $revisions_table_values);
}
// Re-write cck fields.
if (module_exists('content')) {
_content_field_invoke_default('update', $node);
cache_clear_all('content:' . $node->nid . ':' . $node->vid, 'cache_content');
}
// Cleanup temporary paths.
if ($ffp['#settings']) {
foreach ($ffp['#settings'] as $name => $field) {
$paths = explode('/', $field['filepath']['value']);
filefield_paths_cleanup_temp($paths);
}
}
break;
}
}