/** * Delete a node. */ function deleteNode($nid) { // Implemention taken from node_delete, with some assumptions regarding // function_exists removed. $node = node_load($nid); db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); // Call the node-specific callback (if any): node_invoke($node, 'delete'); node_invoke_nodeapi($node, 'delete'); // Clear the page and block caches. cache_clear_all(); }
function _ttt_node_delete($nid) { // Clear the cache before the load, so if multiple nodes are deleted, the // memory will not fill up with nodes (possibly) already removed. $node = node_load($nid, NULL, TRUE); db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_access} WHERE nid = %d', $node->nid); // Call the node-specific callback (if any): node_invoke($node, 'delete'); node_invoke_nodeapi($node, 'delete'); // Remove this node from the search index if needed. if (function_exists('search_wipe')) { search_wipe($node->nid, 'node'); } }
/** * Override node_delete() core Drupal function. * Skip user access function during the importing. * * @param int $nid The nodeID */ protected function node_delete($nid) { // Clear the cache before the load, so if multiple nodes are deleted, the // memory will not fill up with nodes (possibly) already removed. $node = node_load($nid, NULL, TRUE); db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); // Call the node-specific callback (if any): node_invoke($node, 'delete'); node_invoke_nodeapi($node, 'delete'); // Clear the page and block caches. cache_clear_all(); // Remove this node from the search index if needed. if (function_exists('search_wipe')) { search_wipe($node->nid, 'node'); } watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title))); }
function phptemplate_views_rss_feed_recent_blog_posts_rss($view, $nodes, $type) { if ($type == 'block') { return; } global $base_url; $channel = array('title' => views_get_title($view, 'page'), 'link' => url($view->feed_url ? $view->feed_url : $view->real_url, NULL, NULL, true), 'description' => $view->description); $item_length = 'fulltext'; $namespaces = array('xmlns:dc="http://purl.org/dc/elements/1.1/"'); // Except for the original being a while and this being a foreach, this is // completely cut & pasted from node.module. foreach ($nodes as $node) { // Load the specified node: $item = node_load($node->nid); $link = url("node/{$node->nid}", NULL, NULL, 1); if ($item_length != 'title') { $teaser = $item_length == 'teaser' ? TRUE : FALSE; // Filter and prepare node teaser if (node_hook($item, 'view')) { node_invoke($item, 'view', $teaser, FALSE); } else { $item = node_prepare($item, $teaser); } // Allow modules to change $node->teaser before viewing. node_invoke_nodeapi($item, 'view', $teaser, FALSE); } // Allow modules to add additional item fields $extra = node_invoke_nodeapi($item, 'rss item'); $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false')))); foreach ($extra as $element) { if ($element['namespace']) { $namespaces = array_merge($namespaces, $element['namespace']); } } // Prepare the item description switch ($item_length) { case 'fulltext': $item_text = $item->body; break; case 'teaser': $item_text = $item->teaser; if ($item->readmore) { $item_text .= '<p>' . l(t('read more'), 'node/' . $item->nid, NULL, NULL, NULL, TRUE) . '</p>'; } break; case 'title': $item_text = ''; break; } $items .= format_rss_item($item->title, $link, $item_text, $extra); } $channel_defaults = array('version' => '2.0', 'title' => variable_get('site_name', 'drupal') . ' - ' . variable_get('site_slogan', ''), 'link' => $base_url, 'description' => variable_get('site_mission', ''), 'language' => $GLOBALS['locale']); $channel = array_merge($channel_defaults, $channel); $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $output .= "<rss version=\"" . $channel["version"] . "\" xml:base=\"" . $base_url . "\" " . implode(' ', $namespaces) . ">\n"; $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']); $output .= "</rss>\n"; drupal_set_header('Content-Type: text/xml; charset=utf-8'); print $output; module_invoke_all('exit'); exit; }
/** * Update Drupal's full-text index for this module. * * Modules can implement this hook if they want to use the full-text indexing * mechanism in Drupal. * * This hook is called every cron run if search.module is enabled. A module * should check which of its items were modified or added since the last * run. It is advised that you implement a throttling mechanism which indexes * at most 'search_cron_limit' items per run (see example below). * * You should also be aware that indexing may take too long and be aborted if * there is a PHP time limit. That's why you should update your internal * bookkeeping multiple times per run, preferably after every item that * is indexed. * * Per item that needs to be indexed, you should call search_index() with * its content as a single HTML string. The search indexer will analyse the * HTML and use it to assign higher weights to important words (such as * titles). It will also check for links that point to nodes, and use them to * boost the ranking of the target nodes. * * @ingroup search */ function hook_update_index() { $last = variable_get('node_cron_last', 0); $limit = (int) variable_get('search_cron_limit', 100); $result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit); while ($node = db_fetch_object($result)) { $last_comment = $node->last_comment_timestamp; $node = node_load(array('nid' => $node->nid)); // We update this variable per node in case cron times out, or if the node // cannot be indexed (PHP nodes which call drupal_goto, for example). // In rare cases this can mean a node is only partially indexed, but the // chances of this happening are very small. variable_set('node_cron_last', max($last_comment, $node->changed, $node->created)); // Get node output (filtered and with module-specific fields). if (node_hook($node, 'view')) { node_invoke($node, 'view', false, false); } else { $node = node_prepare($node, false); } // Allow modules to change $node->body before viewing. module_invoke_all('node_view', $node, false, false); $text = '<h1>' . drupal_specialchars($node->title) . '</h1>' . $node->body; // Fetch extra data normally not visible $extra = module_invoke_all('node_update_index', $node); foreach ($extra as $t) { $text .= $t; } // Update index search_index($node->nid, 'node', $text); } }
function api_node_save($node) { $transaction = db_transaction(); try { // Load the stored entity, if any. if (!empty($node->nid) && !isset($node->original)) { $node->original = entity_load_unchanged('node', $node->nid); } field_attach_presave('node', $node); global $user; // Determine if we will be inserting a new node. if (!isset($node->is_new)) { $node->is_new = empty($node->nid); } /* // Set the timestamp fields. if (empty($node->created)) { $node->created = REQUEST_TIME; } // The changed timestamp is always updated for bookkeeping purposes, // for example: revisions, searching, etc. $node->changed = REQUEST_TIME; $node->timestamp = REQUEST_TIME; */ $update_node = TRUE; // Let modules modify the node before it is saved to the database. module_invoke_all('node_presave', $node); module_invoke_all('entity_presave', $node, 'node'); if ($node->is_new || !empty($node->revision)) { // When inserting either a new node or a new node revision, $node->log // must be set because {node_revision}.log is a text column and therefore // cannot have a default value. However, it might not be set at this // point (for example, if the user submitting a node form does not have // permission to create revisions), so we ensure that it is at least an // empty string in that case. // @todo: Make the {node_revision}.log column nullable so that we can // remove this check. if (!isset($node->log)) { $node->log = ''; } } elseif (!isset($node->log) || $node->log === '') { // If we are updating an existing node without adding a new revision, we // need to make sure $node->log is unset whenever it is empty. As long as // $node->log is unset, drupal_write_record() will not attempt to update // the existing database column when re-saving the revision; therefore, // this code allows us to avoid clobbering an existing log entry with an // empty one. unset($node->log); } // When saving a new node revision, unset any existing $node->vid so as to // ensure that a new revision will actually be created, then store the old // revision ID in a separate property for use by node hook implementations. if (!$node->is_new && !empty($node->revision) && $node->vid) { $node->old_vid = $node->vid; unset($node->vid); } // Save the node and node revision. if ($node->is_new) { // For new nodes, save new records for both the node itself and the node // revision. drupal_write_record('node', $node); _node_save_revision($node, $user->uid); $op = 'insert'; } else { // For existing nodes, update the node record which matches the value of // $node->nid. drupal_write_record('node', $node, 'nid'); // Then, if a new node revision was requested, save a new record for // that; otherwise, update the node revision record which matches the // value of $node->vid. if (!empty($node->revision)) { _node_save_revision($node, $user->uid); } else { _node_save_revision($node, $user->uid, 'vid'); $update_node = FALSE; } $op = 'update'; } if ($update_node) { db_update('node')->fields(array('vid' => $node->vid))->condition('nid', $node->nid)->execute(); } // Call the node specific callback (if any). This can be // node_invoke($node, 'insert') or // node_invoke($node, 'update'). node_invoke($node, $op); // Save fields. $function = "field_attach_{$op}"; $function('node', $node); module_invoke_all('node_' . $op, $node); module_invoke_all('entity_' . $op, $node, 'node'); // Update the node access table for this node. node_access_acquire_grants($node); // Clear internal properties. unset($node->is_new); unset($node->original); // Clear the static loading cache. entity_get_controller('node')->resetCache(array($node->nid)); // Ignore slave server temporarily to give time for the // saved node to be propagated to the slave. db_ignore_slave(); } catch (Exception $e) { $transaction->rollback(); watchdog_exception('node', $e); throw $e; } }