Index: node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.487 diff -u -F^f -r1.487 node.module --- node.module 24 Apr 2005 16:34:34 -0000 1.487 +++ node.module 30 Apr 2005 01:46:49 -0000 @@ -708,6 +708,11 @@ function node_menu($may_cache) { 'access' => node_access('delete', $node), 'weight' => 1, 'type' => MENU_CALLBACK); + $items[] = array('path' => 'node/'. arg(1) .'/copy', 'title' => t('copy'), + 'callback' => 'node_page', + 'access' => node_access('copy', $node), + 'weight' => 1, + 'type' => MENU_CALLBACK); if ($node->revisions) { $items[] = array('path' => 'node/'. arg(1) .'/revisions', 'title' => t('revisions'), @@ -746,6 +751,7 @@ function node_admin_nodes() { 'sticky' => array(t('Make the selected posts sticky'), 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d'), 'demote' => array(t('Demote the selected posts'), 'UPDATE {node} SET promote = 0 WHERE nid = %d'), 'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'), + 'copy' => array(t('Copy the selected posts'), ''), 'delete' => array(t('Delete the selected posts'), '') ); @@ -798,6 +804,16 @@ function node_admin_nodes() { return $output; } } + else if ($edit['operation'] == 'copy') { + // Mass copy + foreach ($edit['nodes'] as $nid => $value) { + if (is_numeric($nid) && ($nid >= 0)) { + $node = node_load(array('nid' => $nid)); + node_copy($node); + } + } + drupal_set_message(t('The items have been copied.')); + } } } @@ -1582,6 +1598,44 @@ function node_submit(&$node) { } /** + * Makes a copy of the given node. + * + * @param $node + * A node array or node object. + * + * @return + * If the node is successfully copied the node ID of the copy is + * returned. If the node is not saved, 0 is returned. + */ +function node_copy(&$node) { + global $user; + + // Prepare the node's body: + if ($node->nid) { + // Check whether the current user has the proper access rights to + // perform this operation: + if (node_access('view', $node) && node_access('create', $node)) { + $node->title = "(Copy of node ".$node->nid.") ". $node->title; + $node->nid = ''; // clear node's nid to force new node creation; + $node->nid = node_save($node); + + watchdog('content', t('%type: copied %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); + $msg = t('The %post was copied.', array ('%post' => node_invoke($node, 'node_name'))); + } + else { + watchdog('content', t('%type: lack permissions to copy %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); + $msg = t('The %post could not be copied because you lack permission to do so.', array ('%post' => node_invoke($node, 'node_name'))); + } + } + else { + watchdog('content', t('%type: node id not defined.', array('%type' => theme('placeholder', t($node->type)))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); + } + drupal_set_message(t("node_copy: ").$msg); + + return $node->nid; +} + +/** * Ask for confirmation, and delete the node. */ function node_delete($edit) { @@ -1725,6 +1779,17 @@ function node_page() { } return node_delete($edit); break; + case 'copy': + case t('Copy'): + $node = node_load(array('nid' => arg(1))); + if (node_copy($node)) { + drupal_goto('admin/node'); + } + else { + drupal_set_message(t('The node could not be copied.')); + drupal_goto('admin/node'); + } + break; default: drupal_set_title(''); return node_page_default();