Commit 90f9bffb authored by Dries's avatar Dries

- Patch #82045 by chx, eaton et al: fixed nodeapi.

parent a8f20420
......@@ -1810,15 +1810,7 @@ function drupal_render(&$elements) {
if (isset($content) && $content !== '') {
$prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
$suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
$content = $prefix . $content . $suffix;
if (isset($elements['#after_render'])) {
foreach ($elements['#after_render'] as $function) {
$function($elements, $content);
}
}
return $content;
return $prefix . $content . $suffix;
}
}
......
......@@ -658,6 +658,9 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
unset($node->teaser);
}
// Allow modules to modify the fully-built node.
node_invoke_nodeapi($node, 'alter', $teaser, $page);
return theme('node', $node, $teaser, $page);
}
......@@ -718,9 +721,6 @@ function node_build_content($node, $teaser = FALSE, $page = FALSE) {
// Allow modules to make their own additions to the node.
node_invoke_nodeapi($node, 'view', $teaser, $page);
// Allow modules to modify the fully-built node.
node_invoke_nodeapi($node, 'alter', $teaser, $page);
return $node;
}
......
......@@ -497,30 +497,34 @@ function upload_nodeapi(&$node, $op, $teaser) {
'#weight' => 50,
);
}
// Manipulate so that inline references work in preview
if (!variable_get('clean_url', 0)) {
$previews = array();
foreach ($node->files as $file) {
$file = (object)$file;
if (strpos($file->fid, 'upload') !== FALSE) {
$previews[] = $file;
}
}
// URLs to files being previewed are actually Drupal paths. When Clean
// URLs are disabled, the two do not match. We perform an automatic
// replacement from temporary to permanent URLs. That way, the author
// can use the final URL in the body before having actually saved (to
// place inline images for example).
foreach ($previews as $file) {
$old = file_create_filename($file->filename, file_create_path());
$node->content['#upload_urls'][$old] = url($old);
}
}
break;
case 'alter':
if (isset($node->files) && user_access('view uploaded files')) {
// Manipulate so that inline references work in preview
if (!variable_get('clean_url', 0)) {
$previews = array();
foreach ($node->files as $file) {
if (strpos($file['fid'], 'upload') !== FALSE) {
$previews[] = $file;
}
$node->content['#after_render'][] = 'upload_fix_preview_urls';
}
// URLs to files being previewed are actually Drupal paths. When Clean
// URLs are disabled, the two do not match. We perform an automatic
// replacement from temporary to permanent URLs. That way, the author
// can use the final URL in the body before having actually saved (to
// place inline images for example).
foreach ($previews as $file) {
$old = file_create_filename($file['filename'], file_create_path());
$new = url($old);
$node->body = str_replace($old, $new, $node->body);
$node->teaser = str_replace($old, $new, $node->teaser);
}
}
}
break;
case 'insert':
case 'update':
if (user_access('upload files')) {
......@@ -566,18 +570,6 @@ function upload_nodeapi(&$node, $op, $teaser) {
}
}
function upload_fix_preview_urls($elements, &$content) {
if (is_array($elements['#upload_urls'])) {
$old_list = array();
$new_list = array();
foreach ($elements['#upload_urls'] as $old => $new) {
$old_list[] = $old;
$new_list[] = $new;
}
$content = str_replace($old_list, $new_list, $content);
}
}
/**
* Displays file attachments in table
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment