2001-04-02 15:54:37 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-04-02 15:54:37 +00:00
2004-08-21 06:42:38 +00:00
/**
* @file
2006-08-29 18:43:26 +00:00
* The core that allows content to be submitted to the site. Modules and scripts may
* programmatically submit nodes using the usual form API pattern.
2004-08-21 06:42:38 +00:00
*/
2004-01-29 22:00:31 +00:00
define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60);
2007-07-01 21:16:09 +00:00
define('NODE_BUILD_NORMAL', 0);
define('NODE_BUILD_PREVIEW', 1);
define('NODE_BUILD_SEARCH_INDEX', 2);
define('NODE_BUILD_SEARCH_RESULT', 3);
define('NODE_BUILD_RSS', 4);
2007-07-30 18:20:21 +00:00
define('NODE_BUILD_PRINT', 5);
2007-07-01 21:16:09 +00:00
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_help().
*/
2007-06-30 19:46:58 +00:00
function node_help($path, $arg) {
2007-09-02 14:42:30 +00:00
if ($path != 'admin/content/node-settings/rebuild' && strpos($path, '#') === FALSE
&& user_access('access administration pages') && node_access_needs_rebuild()) {
if ($path == 'admin/content/node-settings') {
$message = t('The content access permissions need to be rebuilt.');
}
else {
$message = t('The content access permissions need to be rebuilt. Please visit <a href="@node_access_rebuild">this page</a>.', array('@node_access_rebuild' => url('admin/content/node-settings/rebuild')));
}
drupal_set_message($message, 'error');
}
2007-06-30 19:46:58 +00:00
switch ($path) {
2003-10-09 18:53:22 +00:00
case 'admin/help#node':
2007-12-19 15:55:02 +00:00
$output = '<p>'. t('The node module manages content on your site, and stores all posts (regardless of type) as a "node". In addition to basic publishing settings, including whether the post has been published, promoted to the site front page, or should remain present (or sticky) at the top of lists, the node module also records basic information about the author of a post. Optional revision control over edits is available. For additional functionality, the node module is often extended by other modules.') .'</p>';
$output .= '<p>'. t('Though each post on your site is a node, each post is also of a particular <a href="@content-type">content type</a>. <a href="@content-type">Content types</a> are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Each content type may have different default settings for <em>Publishing options</em> and other workflow controls. By default, the two content types in a standard Drupal installation are <em>Page</em> and <em>Story</em>. Use the <a href="@content-type">content types page</a> to add new or edit existing content types. Additional content types also become available as you enable additional core, contributed and custom modules.', array('@content-type' => url('admin/content/types'))) .'</p>';
$output .= '<p>'. t('The administrative <a href="@content">content page</a> allows you to review and manage your site content. The <a href="@post-settings">post settings page</a> sets certain options for the display of posts. The node module makes a number of permissions available for each content type, which may be set by role on the <a href="@permissions">permissions page</a>.', array('@content' => url('admin/content/node'),'@post-settings' => url('admin/content/node-settings'), '@permissions' => url('admin/user/permissions'))) .'</p>';
2007-12-14 18:08:50 +00:00
$output .= '<p>'. t('For more information, see the online handbook entry for <a href="@node">Node module</a>.', array('@node' => 'http://drupal.org/handbook/modules/node/')) .'</p>';
2004-06-22 20:24:27 +00:00
return $output;
2007-06-30 19:46:58 +00:00
case 'admin/content/node':
return ' '; // Return a non-null value so that the 'more help' link is shown.
2006-08-06 23:00:42 +00:00
case 'admin/content/types':
return '<p>'. t('Below is a list of all the content types on your site. All posts that exist on your site are instances of one of these content types.') .'</p>';
case 'admin/content/types/add':
2006-12-11 16:57:42 +00:00
return '<p>'. t('To create a new content type, enter the human-readable name, the machine-readable name, and all other relevant fields that are on this page. Once created, users of your site will be able to create posts that are instances of this content type.') .'</p>';
2007-06-30 19:46:58 +00:00
case 'node/%/revisions':
return '<p>'. t('The revisions let you track differences between multiple versions of a post.') .'</p>';
case 'node/%/edit':
$node = node_load($arg[1]);
$type = node_get_types('type', $node->type);
2007-10-11 09:51:29 +00:00
return (!empty($type->help) ? '<p>'. filter_xss_admin($type->help) .'</p>' : '');
2001-06-06 20:26:12 +00:00
}
2004-11-27 10:02:06 +00:00
2007-06-30 19:46:58 +00:00
if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) {
$type = node_get_types('type', str_replace('-', '_', $arg[2]));
2007-10-11 09:51:29 +00:00
return (!empty($type->help) ? '<p>'. filter_xss_admin($type->help) .'</p>' : '');
2005-01-26 22:59:41 +00:00
}
2001-06-06 20:26:12 +00:00
}
2007-04-06 13:27:23 +00:00
/**
* Implementation of hook_theme()
*/
function node_theme() {
return array(
2007-07-03 20:31:15 +00:00
'node' => array(
'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
2007-08-26 07:46:11 +00:00
'template' => 'node',
2007-07-03 20:31:15 +00:00
),
2007-04-06 13:27:23 +00:00
'node_list' => array(
'arguments' => array('items' => NULL, 'title' => NULL),
),
'node_search_admin' => array(
'arguments' => array('form' => NULL),
),
'node_filter_form' => array(
'arguments' => array('form' => NULL),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
2007-04-06 13:27:23 +00:00
),
'node_filters' => array(
'arguments' => array('form' => NULL),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
2007-04-06 13:27:23 +00:00
),
'node_admin_nodes' => array(
'arguments' => array('form' => NULL),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
),
'node_add_list' => array(
'arguments' => array('content' => NULL),
'file' => 'node.pages.inc',
2007-04-06 13:27:23 +00:00
),
'node_form' => array(
'arguments' => array('form' => NULL),
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-04-06 13:27:23 +00:00
),
'node_preview' => array(
'arguments' => array('node' => NULL),
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-04-06 13:27:23 +00:00
),
'node_log_message' => array(
'arguments' => array('log' => NULL),
),
2007-07-01 23:15:41 +00:00
'node_submitted' => array(
'arguments' => array('node' => NULL),
),
2007-04-06 13:27:23 +00:00
);
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_cron().
*/
2004-01-29 22:00:31 +00:00
function node_cron() {
2004-02-01 22:13:59 +00:00
db_query('DELETE FROM {history} WHERE timestamp < %d', NODE_NEW_LIMIT);
2004-01-29 22:00:31 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Gather a listing of links to nodes.
*
* @param $result
2007-08-12 15:55:36 +00:00
* A DB result object from a query to fetch node objects. If your query
* joins the <code>node_comment_statistics</code> table so that the
* <code>comment_count</code> field is available, a title attribute will
* be added to show the number of comments.
2004-06-22 20:24:27 +00:00
* @param $title
* A heading for the resulting list.
*
* @return
2007-08-12 15:55:36 +00:00
* An HTML list suitable as content for a block, or FALSE if no result can
* fetch from DB result object.
2004-06-22 20:24:27 +00:00
*/
2002-11-11 20:59:28 +00:00
function node_title_list($result, $title = NULL) {
2007-08-12 15:55:36 +00:00
$items = array();
2007-08-12 16:12:00 +00:00
$num_rows = FALSE;
2002-11-11 20:59:28 +00:00
while ($node = db_fetch_object($result)) {
2007-05-10 19:57:13 +00:00
$items[] = l($node->title, 'node/'. $node->nid, !empty($node->comment_count) ? array('title' => format_plural($node->comment_count, '1 comment', '@count comments')) : array());
2007-08-12 16:12:00 +00:00
$num_rows = TRUE;
2002-11-11 20:59:28 +00:00
}
2007-08-12 16:12:00 +00:00
return $num_rows ? theme('node_list', $items, $title) : FALSE;
2003-04-29 20:48:50 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Format a listing of links to nodes.
2007-12-06 09:58:34 +00:00
*
* @ingroup themeable
2004-06-22 20:24:27 +00:00
*/
2003-05-02 20:44:14 +00:00
function theme_node_list($items, $title = NULL) {
2004-02-01 22:13:59 +00:00
return theme('item_list', $items, $title);
2002-11-11 20:59:28 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Update the 'last viewed' timestamp of the specified node for current user.
*/
2003-03-14 20:41:27 +00:00
function node_tag_new($nid) {
global $user;
if ($user->uid) {
2004-07-13 20:44:13 +00:00
if (node_last_viewed($nid)) {
2004-02-01 22:13:59 +00:00
db_query('UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d', time(), $user->uid, $nid);
2003-03-14 20:41:27 +00:00
}
else {
2004-10-04 22:04:07 +00:00
@db_query('INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)', $user->uid, $nid, time());
2003-03-14 20:41:27 +00:00
}
}
}
2004-06-22 20:24:27 +00:00
/**
* Retrieves the timestamp at which the current user last viewed the
* specified node.
*/
2003-03-14 20:41:27 +00:00
function node_last_viewed($nid) {
global $user;
2004-07-13 20:44:13 +00:00
static $history;
2003-03-14 20:41:27 +00:00
2004-07-13 20:44:13 +00:00
if (!isset($history[$nid])) {
2007-03-07 12:27:31 +00:00
$history[$nid] = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, $nid));
2004-07-13 20:44:13 +00:00
}
2005-10-22 15:14:46 +00:00
return (isset($history[$nid]->timestamp) ? $history[$nid]->timestamp : 0);
2003-03-14 20:41:27 +00:00
}
/**
2005-01-30 09:53:19 +00:00
* Decide on the type of marker to be displayed for a given node.
2003-03-14 20:41:27 +00:00
*
2004-06-22 20:24:27 +00:00
* @param $nid
* Node ID whose history supplies the "last viewed" timestamp.
* @param $timestamp
* Time which is compared against node's "last viewed" timestamp.
2005-01-30 09:53:19 +00:00
* @return
* One of the MARK constants.
2003-12-08 06:32:19 +00:00
*/
2005-01-30 09:53:19 +00:00
function node_mark($nid, $timestamp) {
2003-03-14 20:41:27 +00:00
global $user;
static $cache;
2005-01-30 09:53:19 +00:00
if (!$user->uid) {
return MARK_READ;
}
2003-04-14 18:44:59 +00:00
if (!isset($cache[$nid])) {
2005-01-30 09:53:19 +00:00
$cache[$nid] = node_last_viewed($nid);
2003-03-14 20:41:27 +00:00
}
2005-01-30 09:53:19 +00:00
if ($cache[$nid] == 0 && $timestamp > NODE_NEW_LIMIT) {
return MARK_NEW;
}
elseif ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT) {
return MARK_UPDATED;
}
return MARK_READ;
2003-03-14 20:41:27 +00:00
}
2007-04-09 13:58:03 +00:00
/**
* See if the user used JS to submit a teaser.
*/
2007-06-04 07:22:23 +00:00
function node_teaser_js(&$form, &$form_state) {
2007-04-09 13:58:03 +00:00
// Glue the teaser to the body.
if (isset($form['#post']['teaser_js'])) {
2007-06-04 07:22:23 +00:00
if (trim($form_state['values']['teaser_js'])) {
2007-04-09 13:58:03 +00:00
// Space the teaser from the body
2007-06-04 07:22:23 +00:00
$body = trim($form_state['values']['teaser_js']) ."\r\n<!--break-->\r\n". trim($form_state['values']['body']);
2007-04-09 13:58:03 +00:00
}
else {
// Empty teaser, no spaces.
2007-06-04 07:22:23 +00:00
$body = '<!--break-->'. $form_state['values']['body'];
2007-04-09 13:58:03 +00:00
}
// Pass value onto preview/submit
2007-05-14 13:43:38 +00:00
form_set_value($form['body'], $body, $form_state);
2007-04-09 13:58:03 +00:00
// Pass value back onto form
$form['body']['#value'] = $body;
}
return $form;
}
2004-06-22 20:24:27 +00:00
/**
2007-11-27 11:36:35 +00:00
* Automatically generate a teaser for a node body.
2007-07-01 21:52:43 +00:00
*
2007-11-29 11:29:24 +00:00
* If the end of the teaser is not indicated using the <!--break--> delimiter
* then we try to end it at a sensible place, such as the end of a paragraph,
* a line break, or the end of a sentence (in that order of preference).
*
2007-07-01 21:52:43 +00:00
* @param $body
* The content for which a teaser will be generated.
* @param $format
* The format of the content. If the content contains PHP code, we do not
2007-11-29 11:29:24 +00:00
* split it up to prevent parse errors. If the line break filter is present
* then we treat newlines embedded in $body as line breaks.
2007-07-01 21:52:43 +00:00
* @param $size
2007-07-02 14:41:37 +00:00
* The desired character length of the teaser. If omitted, the default
2007-11-29 11:29:24 +00:00
* value will be used. Ignored if the special delimiter is present
2007-12-08 14:06:23 +00:00
* in $body.
2007-07-01 21:52:43 +00:00
* @return
* The generated teaser.
2004-06-22 20:24:27 +00:00
*/
2007-07-01 21:52:43 +00:00
function node_teaser($body, $format = NULL, $size = NULL) {
2001-12-08 11:12:26 +00:00
2007-07-01 21:52:43 +00:00
if (!isset($size)) {
$size = variable_get('teaser_length', 600);
}
2002-12-10 20:35:20 +00:00
2006-12-10 21:07:15 +00:00
// Find where the delimiter is in the body
2007-01-05 22:01:02 +00:00
$delimiter = strpos($body, '<!--break-->');
2004-08-04 21:19:12 +00:00
2005-06-01 03:32:22 +00:00
// If the size is zero, and there is no delimiter, the entire body is the teaser.
2006-03-09 22:38:40 +00:00
if ($size == 0 && $delimiter === FALSE) {
2002-12-10 20:35:20 +00:00
return $body;
}
2001-12-08 11:12:26 +00:00
2006-12-12 10:05:26 +00:00
// If a valid delimiter has been specified, use it to chop off the teaser.
if ($delimiter !== FALSE) {
return substr($body, 0, $delimiter);
}
2005-06-01 03:32:22 +00:00
// We check for the presence of the PHP evaluator filter in the current
// format. If the body contains PHP code, we do not split it up to prevent
// parse errors.
if (isset($format)) {
$filters = filter_list_format($format);
2007-11-24 21:02:24 +00:00
if (isset($filters['php/0']) && strpos($body, '<?') !== FALSE) {
2005-06-01 03:32:22 +00:00
return $body;
}
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
}
2005-06-01 03:32:22 +00:00
// If we have a short body, the entire body is the teaser.
2007-11-29 11:29:24 +00:00
if (strlen($body) <= $size) {
2003-07-21 15:36:05 +00:00
return $body;
}
2007-11-23 12:27:38 +00:00
// If the delimiter has not been specified, try to split at paragraph or
// sentence boundaries.
2006-12-12 08:35:30 +00:00
// The teaser may not be longer than maximum length specified. Initial slice.
$teaser = truncate_utf8($body, $size);
2007-11-23 12:27:38 +00:00
// Store the actual length of the UTF8 string -- which might not be the same
// as $size.
$max_rpos = strlen($teaser);
// How much to cut off the end of the teaser so that it doesn't end in the
// middle of a paragraph, sentence, or word.
// Initialize it to maximum in order to find the minimum.
$min_rpos = $max_rpos;
// Store the reverse of the teaser. We use strpos on the reversed needle and
// haystack for speed and convenience.
2006-12-12 08:35:30 +00:00
$reversed = strrev($teaser);
2007-11-23 12:27:38 +00:00
// Build an array of arrays of break points grouped by preference.
$break_points = array();
// A paragraph near the end of sliced teaser is most preferable.
$break_points[] = array('</p>' => 0);
2007-11-29 11:29:24 +00:00
// If no complete paragraph then treat line breaks as paragraphs.
$line_breaks = array('<br />' => 6, '<br>' => 4);
// Newline only indicates a line break if line break converter
// filter is present.
if (isset($filters['filter/1'])) {
$line_breaks["\n"] = 1;
}
$break_points[] = $line_breaks;
2007-11-23 12:27:38 +00:00
// If the first paragraph is too long, split at the end of a sentence.
$break_points[] = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);
// Iterate over the groups of break points until a break point is found.
foreach ($break_points as $points) {
// Look for each break point, starting at the end of the teaser.
foreach ($points as $point => $offset) {
// The teaser is already reversed, but the break point isn't.
$rpos = strpos($reversed, strrev($point));
if ($rpos !== FALSE) {
$min_rpos = min($rpos + $offset, $min_rpos);
}
2005-06-01 03:32:22 +00:00
}
2005-06-06 14:07:04 +00:00
2007-11-23 12:27:38 +00:00
// If a break point was found in this group, slice and return the teaser.
if ($min_rpos !== $max_rpos) {
// Don't slice with length 0. Length must be <0 to slice from RHS.
return ($min_rpos === 0) ? $teaser : substr($teaser, 0, 0 - $min_rpos);
2006-12-12 08:35:30 +00:00
}
}
2007-11-23 12:27:38 +00:00
// If a break point was not found, still return a teaser.
return $teaser;
2001-12-08 11:12:26 +00:00
}
2006-08-06 23:00:42 +00:00
/**
* Builds a list of available node types, and returns all of part of this list
* in the specified format.
*
* @param $op
* The format in which to return the list. When this is set to 'type',
* 'module', or 'name', only the specified node type is returned. When set to
* 'types' or 'names', all node types are returned.
* @param $node
* A node object, array, or string that indicates the node type to return.
* Leave at default value (NULL) to return a list of all node types.
* @param $reset
* Whether or not to reset this function's internal cache (defaults to
* FALSE).
*
* @return
* Either an array of all available node types, or a single node type, in a
2007-09-09 20:16:09 +00:00
* variable format. Returns FALSE if the node type is not found.
2006-08-06 23:00:42 +00:00
*/
function node_get_types($op = 'types', $node = NULL, $reset = FALSE) {
static $_node_types, $_node_names;
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
2006-08-06 23:00:42 +00:00
if ($reset || !isset($_node_types)) {
list($_node_types, $_node_names) = _node_types_build();
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
}
2006-08-06 23:00:42 +00:00
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
if ($node) {
if (is_array($node)) {
$type = $node['type'];
}
elseif (is_object($node)) {
$type = $node->type;
}
elseif (is_string($node)) {
$type = $node;
}
2006-08-06 23:00:42 +00:00
if (!isset($_node_types[$type])) {
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
return FALSE;
}
}
switch ($op) {
2006-08-06 23:00:42 +00:00
case 'types':
return $_node_types;
case 'type':
2007-09-09 20:16:09 +00:00
return isset($_node_types[$type]) ? $_node_types[$type] : FALSE;
2006-08-06 23:00:42 +00:00
case 'module':
2007-09-09 20:16:09 +00:00
return isset($_node_types[$type]->module) ? $_node_types[$type]->module : FALSE;
2006-08-06 23:00:42 +00:00
case 'names':
return $_node_names;
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
case 'name':
2007-09-09 20:16:09 +00:00
return isset($_node_names[$type]) ? $_node_names[$type] : FALSE;
2006-08-06 23:00:42 +00:00
}
}
/**
* Resets the database cache of node types, and saves all new or non-modified
* module-defined node types to the database.
*/
function node_types_rebuild() {
_node_types_build();
$node_types = node_get_types('types', NULL, TRUE);
foreach ($node_types as $type => $info) {
if (!empty($info->is_new)) {
node_type_save($info);
}
2007-07-21 09:55:18 +00:00
if (!empty($info->disabled)) {
node_type_delete($info->type);
}
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
}
2006-08-06 23:00:42 +00:00
_node_types_build();
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
}
2004-02-08 20:36:13 +00:00
/**
2006-08-06 23:00:42 +00:00
* Saves a node type to the database.
*
* @param $info
* The node type to save, as an object.
2004-01-23 18:42:43 +00:00
*
* @return
2006-08-06 23:00:42 +00:00
* Status flag indicating outcome of the operation.
2004-01-23 18:42:43 +00:00
*/
2006-08-06 23:00:42 +00:00
function node_type_save($info) {
$is_existing = FALSE;
$existing_type = !empty($info->old_type) ? $info->old_type : $info->type;
2007-08-12 15:55:36 +00:00
$is_existing = db_result(db_query("SELECT COUNT(*) FROM {node_type} WHERE type = '%s'", $existing_type));
2007-03-27 05:13:55 +00:00
if (!isset($info->help)) {
$info->help = '';
}
if (!isset($info->min_word_count)) {
$info->min_word_count = 0;
}
if (!isset($info->body_label)) {
$info->body_label = '';
}
2006-08-06 23:00:42 +00:00
if ($is_existing) {
db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type);
2006-10-31 17:01:04 +00:00
module_invoke_all('node_type', 'update', $info);
2006-08-06 23:00:42 +00:00
return SAVED_UPDATED;
}
else {
db_query("INSERT INTO {node_type} (type, name, module, has_title, title_label, has_body, body_label, description, help, min_word_count, custom, modified, locked, orig_type) VALUES ('%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, '%s')", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $info->orig_type);
2006-10-31 17:01:04 +00:00
module_invoke_all('node_type', 'insert', $info);
2006-08-06 23:00:42 +00:00
return SAVED_NEW;
}
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
}
2005-07-17 20:57:43 +00:00
2006-11-10 19:40:23 +00:00
/**
* Deletes a node type from the database.
*
* @param $type
* The machine-readable name of the node type to be deleted.
*/
function node_type_delete($type) {
$info = node_get_types('type', $type);
2007-10-08 13:04:32 +00:00
db_query("DELETE FROM {node_type} WHERE type = '%s'", $type);
2006-11-10 19:40:23 +00:00
module_invoke_all('node_type', 'delete', $info);
}
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
/**
2006-08-06 23:00:42 +00:00
* Updates all nodes of one type to be of another type.
*
2007-01-03 11:03:26 +00:00
* @param $old_type
2006-08-06 23:00:42 +00:00
* The current node type of the nodes.
* @param $type
* The new node type of the nodes.
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
*
* @return
2006-08-06 23:00:42 +00:00
* The number of nodes whose node type field was modified.
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
*/
2006-08-06 23:00:42 +00:00
function node_type_update_nodes($old_type, $type) {
db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $type, $old_type);
return db_affected_rows();
2004-01-27 18:47:07 +00:00
}
2004-01-23 18:42:43 +00:00
2004-02-08 20:36:13 +00:00
/**
2007-07-21 09:55:18 +00:00
* Builds and returns the list of available node types.
*
* The list of types is built by querying hook_node_info() in all modules, and
* by comparing this information with the node types in the {node_type} table.
2004-01-23 18:42:43 +00:00
*
*/
2006-08-06 23:00:42 +00:00
function _node_types_build() {
$_node_types = array();
$_node_names = array();
$info_array = module_invoke_all('node_info');
foreach ($info_array as $type => $info) {
$info['type'] = $type;
$_node_types[$type] = (object) _node_type_set_defaults($info);
$_node_names[$type] = $info['name'];
}
$type_result = db_query(db_rewrite_sql('SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC', 'nt', 'type'));
while ($type_object = db_fetch_object($type_result)) {
2007-07-21 09:55:18 +00:00
// Check for node types from disabled modules and mark their types for removal.
// Types defined by the node module in the database (rather than by a separate
// module using hook_node_info) have a module value of 'node'.
if ($type_object->module != 'node' && empty($info_array[$type_object->type])) {
2007-12-08 14:06:23 +00:00
$type_object->disabled = TRUE;
2007-07-21 09:55:18 +00:00
}
2006-08-06 23:00:42 +00:00
if (!isset($_node_types[$type_object->type]) || $type_object->modified) {
$_node_types[$type_object->type] = $type_object;
$_node_names[$type_object->type] = $type_object->name;
if ($type_object->type != $type_object->orig_type) {
unset($_node_types[$type_object->orig_type]);
unset($_node_names[$type_object->orig_type]);
}
}
}
asort($_node_names);
return array($_node_types, $_node_names);
}
/**
* Set default values for a node type defined through hook_node_info().
*/
function _node_type_set_defaults($info) {
if (!isset($info['has_title'])) {
$info['has_title'] = TRUE;
}
if ($info['has_title'] && !isset($info['title_label'])) {
$info['title_label'] = t('Title');
}
if (!isset($info['has_body'])) {
$info['has_body'] = TRUE;
}
if ($info['has_body'] && !isset($info['body_label'])) {
$info['body_label'] = t('Body');
}
2007-05-08 17:08:14 +00:00
if (!isset($info['help'])) {
$info['help'] = '';
}
if (!isset($info['min_word_count'])) {
$info['min_word_count'] = 0;
}
2006-08-06 23:00:42 +00:00
if (!isset($info['custom'])) {
$info['custom'] = FALSE;
}
if (!isset($info['modified'])) {
$info['modified'] = FALSE;
}
if (!isset($info['locked'])) {
$info['locked'] = TRUE;
}
$info['orig_type'] = $info['type'];
$info['is_new'] = TRUE;
return $info;
2004-01-27 18:47:07 +00:00
}
2004-01-23 18:42:43 +00:00
2004-02-08 20:36:13 +00:00
/**
2004-01-23 18:42:43 +00:00
* Determine whether a node hook exists.
*
* @param &$node
* Either a node object, node array, or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
* @return
* TRUE iff the $hook exists in the node type of $node.
*/
function node_hook(&$node, $hook) {
2006-08-06 23:00:42 +00:00
$module = node_get_types('module', $node);
if ($module == 'node') {
$module = 'node_content'; // Avoid function name collisions.
}
return module_hook($module, $hook);
2004-01-23 18:42:43 +00:00
}
2004-02-08 20:36:13 +00:00
/**
2004-01-23 18:42:43 +00:00
* Invoke a node hook.
*
* @param &$node
* Either a node object, node array, or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
* @param $a2, $a3, $a4
* Arguments to pass on to the hook, after the $node argument.
* @return
2004-06-22 20:24:27 +00:00
* The returned value of the invoked hook.
2004-01-23 18:42:43 +00:00
*/
function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
if (node_hook($node, $hook)) {
2006-08-06 23:00:42 +00:00
$module = node_get_types('module', $node);
if ($module == 'node') {
$module = 'node_content'; // Avoid function name collisions.
}
$function = $module .'_'. $hook;
2003-09-14 18:33:16 +00:00
return ($function($node, $a2, $a3, $a4));
2001-12-08 11:12:26 +00:00
}
}
2004-06-22 20:24:27 +00:00
/**
* Invoke a hook_nodeapi() operation in all modules.
*
* @param &$node
2005-03-07 21:58:13 +00:00
* A node object.
2004-06-22 20:24:27 +00:00
* @param $op
* A string containing the name of the nodeapi operation.
* @param $a3, $a4
* Arguments to pass on to the hook, after the $node and $op arguments.
* @return
* The returned value of the invoked hooks.
*/
2004-04-28 20:23:30 +00:00
function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
2003-09-23 16:54:19 +00:00
$return = array();
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
foreach (module_implements('nodeapi') as $name) {
2004-02-01 22:13:59 +00:00
$function = $name .'_nodeapi';
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
$result = $function($node, $op, $a3, $a4);
2005-12-14 20:10:45 +00:00
if (isset($result) && is_array($result)) {
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
$return = array_merge($return, $result);
}
else if (isset($result)) {
$return[] = $result;
2003-09-23 16:54:19 +00:00
}
}
return $return;
}
2004-06-22 20:24:27 +00:00
/**
* Load a node object from the database.
*
2005-07-17 18:29:32 +00:00
* @param $param
* Either the nid of the node or an array of conditions to match against in the database query
2004-06-22 20:24:27 +00:00
* @param $revision
* Which numbered revision to load. Defaults to the current version.
2004-11-17 22:14:43 +00:00
* @param $reset
* Whether to reset the internal node_load cache.
2004-06-22 20:24:27 +00:00
*
* @return
* A fully-populated node object.
*/
2005-07-17 18:29:32 +00:00
function node_load($param = array(), $revision = NULL, $reset = NULL) {
2004-11-17 22:14:43 +00:00
static $nodes = array();
if ($reset) {
$nodes = array();
}
2006-12-21 22:22:14 +00:00
$cachable = ($revision == NULL);
2006-01-05 23:35:34 +00:00
$arguments = array();
2005-07-17 18:29:32 +00:00
if (is_numeric($param)) {
2007-08-25 09:25:49 +00:00
if ($cachable) {
2007-08-30 15:31:46 +00:00
// Is the node statically cached?
2007-08-25 09:25:49 +00:00
if (isset($nodes[$param])) {
return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
}
2005-07-17 18:29:32 +00:00
}
2006-01-05 23:35:34 +00:00
$cond = 'n.nid = %d';
$arguments[] = $param;
2004-11-17 22:14:43 +00:00
}
2007-06-24 00:38:40 +00:00
elseif (is_array($param)) {
2005-07-17 18:29:32 +00:00
// Turn the conditions into a query.
2005-07-18 20:27:32 +00:00
foreach ($param as $key => $value) {
2006-01-05 23:35:34 +00:00
$cond[] = 'n.'. db_escape_string($key) ." = '%s'";
$arguments[] = $value;
2005-07-17 18:29:32 +00:00
}
$cond = implode(' AND ', $cond);
2001-12-08 11:12:26 +00:00
}
2007-06-24 00:38:40 +00:00
else {
return FALSE;
}
2001-12-08 11:12:26 +00:00
2007-10-02 16:15:56 +00:00
// Retrieve a field list based on the site's schema.
$fields = drupal_schema_fields_sql('node', 'n');
$fields = array_merge($fields, drupal_schema_fields_sql('node_revisions', 'r'));
2007-11-14 12:43:13 +00:00
$fields = array_merge($fields, array('u.name', 'u.picture', 'u.data'));
2007-12-10 10:52:52 +00:00
// Remove fields not needed in the query: n.vid and r.nid are redundant,
// n.title is unnecessary because the node title comes from the
// node_revisions table. We'll keep r.vid, r.title, and n.nid.
$fields = array_diff($fields, array('n.vid', 'n.title', 'r.nid'));
2007-10-02 16:15:56 +00:00
$fields = implode(', ', $fields);
2007-12-10 10:52:52 +00:00
// Rename timestamp field for clarity.
2007-10-02 16:15:56 +00:00
$fields = str_replace('r.timestamp', 'r.timestamp AS revision_timestamp', $fields);
2007-12-10 10:52:52 +00:00
// Change name of revision uid so it doesn't conflict with n.uid.
$fields = str_replace('r.uid', 'r.uid AS revision_uid', $fields);
2007-10-02 16:15:56 +00:00
2004-06-22 20:24:27 +00:00
// Retrieve the node.
2006-07-26 07:04:19 +00:00
// No db_rewrite_sql is applied so as to get complete indexing for search.
2005-08-30 15:22:29 +00:00
if ($revision) {
2006-01-05 23:35:34 +00:00
array_unshift($arguments, $revision);
2007-10-19 10:19:03 +00:00
$node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
else {
2007-10-19 10:19:03 +00:00
$node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
2001-12-08 11:12:26 +00:00
}
2007-04-06 04:39:51 +00:00
if ($node && $node->nid) {
2005-08-30 15:22:29 +00:00
// Call the node specific callback (if any) and piggy-back the
// results to the node or overwrite some values.
if ($extra = node_invoke($node, 'load')) {
foreach ($extra as $key => $value) {
$node->$key = $value;
}
2004-04-28 20:23:30 +00:00
}
2005-08-30 15:22:29 +00:00
if ($extra = node_invoke_nodeapi($node, 'load')) {
foreach ($extra as $key => $value) {
$node->$key = $value;
}
}
2006-12-21 22:22:14 +00:00
if ($cachable) {
$nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
}
2004-11-17 22:14:43 +00:00
}
2001-12-08 11:12:26 +00:00
return $node;
}
2007-08-20 07:03:08 +00:00
/**
* Perform validation checks on the given node.
*/
function node_validate($node, $form = array()) {
// Convert the node to an object, if necessary.
$node = (object)$node;
$type = node_get_types('type', $node);
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
if (!empty($type->min_word_count) && isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
form_set_error('body', t('The body of your @type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@type' => $type->name)));
}
if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
}
if (user_access('administer nodes')) {
// Validate the "authored by" field.
if (!empty($node->name) && !($account = user_load(array('name' => $node->name)))) {
// The use of empty() is mandatory in the context of usernames
// as the empty string denotes the anonymous user. In case we
// are dealing with an anonymous user we set the user ID to 0.
form_set_error('name', t('The username %name does not exist.', array('%name' => $node->name)));
}
// Validate the "authored on" field. As of PHP 5.1.0, strtotime returns FALSE instead of -1 upon failure.
if (!empty($node->date) && strtotime($node->date) <= 0) {
form_set_error('date', t('You have to specify a valid date.'));
}
}
// Do node-type-specific validation checks.
node_invoke($node, 'validate', $form);
node_invoke_nodeapi($node, 'validate', $form);
}
/**
* Prepare node for save and allow modules to make changes.
*/
function node_submit($node) {
global $user;
// Convert the node to an object, if necessary.
$node = (object)$node;
// Auto-generate the teaser, but only if it hasn't been set (e.g. by a
// module-provided 'teaser' form item).
if (!isset($node->teaser)) {
if (isset($node->body)) {
$node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL);
// Chop off the teaser from the body if needed.
2007-11-05 15:14:54 +00:00
if (empty($node->teaser_include) && $node->teaser == substr($node->body, 0, strlen($node->teaser))) {
2007-08-20 07:03:08 +00:00
$node->body = substr($node->body, strlen($node->teaser));
}
}
else {
$node->teaser = '';
}
}
if (user_access('administer nodes')) {
// Populate the "authored by" field.
if ($account = user_load(array('name' => $node->name))) {
$node->uid = $account->uid;
}
else {
$node->uid = 0;
}
}
2007-09-19 18:11:08 +00:00
$node->created = !empty($node->date) ? strtotime($node->date) : time();
2007-08-20 07:03:08 +00:00
$node->validated = TRUE;
return $node;
}
2004-06-22 20:24:27 +00:00
/**
* Save a node object into the database.
*/
2005-09-02 02:11:41 +00:00
function node_save(&$node) {
2007-06-29 18:06:51 +00:00
// Let modules modify the node before it is saved to the database.
node_invoke_nodeapi($node, 'presave');
2005-08-30 15:22:29 +00:00
global $user;
2001-12-08 11:12:26 +00:00
2006-07-05 11:45:51 +00:00
$node->is_new = FALSE;
2001-12-08 11:12:26 +00:00
2004-06-22 20:24:27 +00:00
// Apply filters to some default node fields:
2001-12-08 11:12:26 +00:00
if (empty($node->nid)) {
2004-06-22 20:24:27 +00:00
// Insert a new node.
2006-07-05 11:45:51 +00:00
$node->is_new = TRUE;
2007-11-20 18:20:37 +00:00
// When inserting a node, $node->log must be set because
// {node_revisions}.log does not (and cannot) have a default
// value. If the user does not have permission to create
// revisions, however, the form will not contain an element for
// log so $node->log will be unset at this point.
if (!isset($node->log)) {
$node->log = '';
}
2007-12-11 14:31:12 +00:00
// For the same reasons, make sure we have $node->teaser and
// $node->body. We should consider making these fields nullable
// in a future version since node types are not required to use them.
if (!isset($node->teaser)) {
$node->teaser = '';
}
if (!isset($node->body)) {
$node->body = '';
}
2005-08-30 15:22:29 +00:00
}
2007-10-02 16:15:56 +00:00
elseif (!empty($node->revision)) {
$node->old_vid = $node->vid;
}
2005-08-30 15:22:29 +00:00
else {
2007-10-02 16:15:56 +00:00
// When updating a node, avoid clobberring an existing log entry with an empty one.
if (empty($node->log)) {
unset($node->log);
2005-08-30 15:22:29 +00:00
}
2001-12-08 11:12:26 +00:00
}
2006-04-10 21:36:40 +00:00
// Set some required fields:
if (empty($node->created)) {
$node->created = time();
}
2005-12-21 14:30:09 +00:00
// The changed timestamp is always updated for bookkeeping purposes (revisions, searching, ...)
2006-04-10 21:36:40 +00:00
$node->changed = time();
2001-12-08 11:12:26 +00:00
2007-10-02 16:15:56 +00:00
$node->timestamp = time();
$node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT;
2007-06-05 12:13:23 +00:00
$update_node = TRUE;
2007-10-02 16:15:56 +00:00
2005-08-30 15:22:29 +00:00
//Generate the node table query and the
//the node_revisions table query
if ($node->is_new) {
2007-10-02 16:15:56 +00:00
drupal_write_record('node', $node);
2007-11-13 14:56:14 +00:00
_node_save_revision($node, $user->uid);
2007-06-05 12:13:23 +00:00
$op = 'insert';
2005-08-30 15:22:29 +00:00
}
else {
2007-10-02 16:15:56 +00:00
drupal_write_record('node', $node, 'nid');
2007-01-31 15:49:26 +00:00
if (!empty($node->revision)) {
2007-11-13 14:56:14 +00:00
_node_save_revision($node, $user->uid);
2005-08-30 15:22:29 +00:00
}
else {
2007-11-13 14:56:14 +00:00
_node_save_revision($node, $user->uid, 'vid');
2007-06-05 12:13:23 +00:00
$update_node = FALSE;
2001-12-08 11:12:26 +00:00
}
2007-06-05 12:13:23 +00:00
$op = 'update';
2005-08-30 15:22:29 +00:00
}
2007-06-05 12:13:23 +00:00
if ($update_node) {
2007-06-17 14:37:33 +00:00
db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid);
2006-08-31 21:58:36 +00:00
}
2007-06-05 12:13:23 +00:00
// Call the node specific callback (if any):
node_invoke($node, $op);
node_invoke_nodeapi($node, $op);
2006-08-05 02:12:46 +00:00
// Update the node access table for this node.
node_access_acquire_grants($node);
2007-08-19 08:08:45 +00:00
// Clear the page and block caches.
2002-11-17 06:42:52 +00:00
cache_clear_all();
2001-12-08 11:12:26 +00:00
}
2007-11-13 14:56:14 +00:00
/**
2007-11-20 09:47:07 +00:00
* Helper function to save a revision with the uid of the current user.
*
* Node is taken by reference, becuse drupal_write_record() updates the
* $node with the revision id, and we need to pass that back to the caller.
2007-11-13 14:56:14 +00:00
*/
2007-11-20 09:47:07 +00:00
function _node_save_revision(&$node, $uid, $update = NULL) {
2007-11-13 14:56:14 +00:00
$temp_uid = $node->uid;
$node->uid = $uid;
if (isset($update)) {
drupal_write_record('node_revisions', $node, $update);
}
else {
drupal_write_record('node_revisions', $node);
}
$node->uid = $temp_uid;
}
2007-08-20 07:03:08 +00:00
/**
* Delete a node.
*/
function node_delete($nid) {
$node = node_load($nid);
if (node_access('delete', $node)) {
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));
2007-12-11 12:13:39 +00:00
drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title)));
2007-08-20 07:03:08 +00:00
}
}
2004-06-22 20:24:27 +00:00
/**
* Generate a display of the given node.
*
* @param $node
* A node array or node object.
* @param $teaser
2007-09-26 18:22:34 +00:00
* Whether to display the teaser only or the full form.
2004-06-22 20:24:27 +00:00
* @param $page
* Whether the node is being displayed by itself as a page.
2004-11-23 23:11:59 +00:00
* @param $links
* Whether or not to display node links. Links are omitted for node previews.
2004-06-22 20:24:27 +00:00
*
* @return
* An HTML representation of the themed node.
*/
2004-11-23 23:11:59 +00:00
function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
2005-12-31 10:48:56 +00:00
$node = (object)$node;
2001-12-08 11:12:26 +00:00
2006-09-07 07:24:22 +00:00
$node = node_build_content($node, $teaser, $page);
2004-11-23 23:11:59 +00:00
if ($links) {
2007-09-26 18:22:34 +00:00
$node->links = module_invoke_all('link', 'node', $node, $teaser);
2007-03-26 00:35:59 +00:00
drupal_alter('link', $node->links, $node);
2004-11-23 23:11:59 +00:00
}
2006-08-10 15:42:33 +00:00
// Set the proper node part, then unset unused $node part so that a bad
// theme can not open a security hole.
$content = drupal_render($node->content);
2005-06-29 19:53:14 +00:00
if ($teaser) {
2006-08-10 15:42:33 +00:00
$node->teaser = $content;
2005-06-29 19:53:14 +00:00
unset($node->body);
}
else {
2006-08-10 15:42:33 +00:00
$node->body = $content;
2005-06-29 19:53:14 +00:00
unset($node->teaser);
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
2006-10-05 15:26:17 +00:00
// Allow modules to modify the fully-built node.
node_invoke_nodeapi($node, 'alter', $teaser, $page);
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
return theme('node', $node, $teaser, $page);
2004-01-02 16:30:09 +00:00
}
2003-05-26 19:50:39 +00:00
2004-06-22 20:24:27 +00:00
/**
2006-08-10 15:42:33 +00:00
* Apply filters and build the node's standard elements.
2004-06-22 20:24:27 +00:00
*/
2004-06-18 15:04:37 +00:00
function node_prepare($node, $teaser = FALSE) {
2006-10-04 06:54:24 +00:00
// First we'll overwrite the existing node teaser and body with
// the filtered copies! Then, we'll stick those into the content
// array and set the read more flag if appropriate.
2006-11-28 03:20:08 +00:00
$node->readmore = (strlen($node->teaser) < strlen($node->body));
2006-10-04 06:54:24 +00:00
if ($teaser == FALSE) {
$node->body = check_markup($node->body, $node->format, FALSE);
}
else {
$node->teaser = check_markup($node->teaser, $node->format, FALSE);
}
2006-08-10 15:42:33 +00:00
$node->content['body'] = array(
2006-10-04 06:54:24 +00:00
'#value' => $teaser ? $node->teaser : $node->body,
2006-08-10 15:42:33 +00:00
'#weight' => 0,
);
return $node;
}
/**
* Builds a structured array representing the node's content.
*
* @param $node
* A node object.
* @param $teaser
* Whether to display the teaser only, as on the main page.
* @param $page
* Whether the node is being displayed by itself as a page.
*
* @return
* An structured array containing the individual elements
* of the node's body.
*/
function node_build_content($node, $teaser = FALSE, $page = FALSE) {
2007-07-01 21:16:09 +00:00
// The build mode identifies the target for which the node is built.
if (!isset($node->build_mode)) {
$node->build_mode = NODE_BUILD_NORMAL;
}
2006-08-10 15:42:33 +00:00
// Remove the delimiter (if any) that separates the teaser from the body.
2007-03-27 05:13:55 +00:00
$node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
2006-08-10 15:42:33 +00:00
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if (node_hook($node, 'view')) {
$node = node_invoke($node, 'view', $teaser, $page);
2004-01-02 16:30:09 +00:00
}
else {
2006-08-10 15:42:33 +00:00
$node = node_prepare($node, $teaser);
2001-12-08 11:12:26 +00:00
}
2006-08-10 15:42:33 +00:00
// Allow modules to make their own additions to the node.
node_invoke_nodeapi($node, 'view', $teaser, $page);
2004-01-02 16:30:09 +00:00
return $node;
2001-12-08 11:12:26 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Generate a page displaying a single node, along with its comments.
*/
2007-12-20 09:20:41 +00:00
function node_show($node, $cid, $message = FALSE) {
if ($message) {
drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))));
}
2004-07-31 09:30:09 +00:00
$output = node_view($node, FALSE, TRUE);
2003-01-06 19:51:01 +00:00
2004-07-31 09:30:09 +00:00
if (function_exists('comment_render') && $node->comment) {
$output .= comment_render($node, $cid);
2001-11-01 17:04:20 +00:00
}
2004-07-31 09:30:09 +00:00
// Update the history table, stating that this user viewed this node.
node_tag_new($node->nid);
2001-11-01 17:04:20 +00:00
2004-07-31 09:30:09 +00:00
return $output;
2001-11-01 17:04:20 +00:00
}
2007-12-06 09:58:34 +00:00
/**
* Theme a log message.
*
* @ingroup themeable
*/
2007-08-20 07:03:08 +00:00
function theme_node_log_message($log) {
return '<div class="log"><div class="title">'. t('Log') .':</div>'. $log .'</div>';
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_perm().
*/
2001-06-20 20:00:40 +00:00
function node_perm() {
2007-12-20 09:20:41 +00:00
$perms = array('administer content types', 'administer nodes', 'access content', 'view revisions', 'revert revisions', 'delete revisions');
2006-08-06 23:00:42 +00:00
foreach (node_get_types() as $type) {
if ($type->module == 'node') {
2006-10-25 16:44:07 +00:00
$name = check_plain($type->type);
2006-08-06 23:00:42 +00:00
$perms[] = 'create '. $name .' content';
2007-06-26 22:27:25 +00:00
$perms[] = 'delete own '. $name .' content';
2007-11-26 11:44:04 +00:00
$perms[] = 'delete any '. $name .' content';
2006-08-06 23:00:42 +00:00
$perms[] = 'edit own '. $name .' content';
2007-11-26 11:44:04 +00:00
$perms[] = 'edit any '. $name .' content';
2006-08-06 23:00:42 +00:00
}
}
return $perms;
2001-06-20 20:00:40 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_search().
*/
2006-07-05 11:45:51 +00:00
function node_search($op = 'search', $keys = NULL) {
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
switch ($op) {
case 'name':
2006-10-23 20:45:08 +00:00
return t('Content');
2005-10-18 14:41:27 +00:00
2004-11-03 16:46:58 +00:00
case 'reset':
2007-12-14 18:40:32 +00:00
db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = 'node'", time());
2004-11-03 16:46:58 +00:00
return;
2005-10-18 14:41:27 +00:00
2005-01-11 09:41:49 +00:00
case 'status':
2006-02-01 14:11:53 +00:00
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1'));
2007-11-13 14:04:08 +00:00
$remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0"));
2005-01-11 09:41:49 +00:00
return array('remaining' => $remaining, 'total' => $total);
2005-10-18 14:41:27 +00:00
case 'admin':
$form = array();
// Output form for defining rank factor weights.
2007-11-27 13:31:04 +00:00
$form['content_ranking'] = array(
2007-11-28 10:29:21 +00:00
'#type' => 'fieldset',
2007-11-27 13:31:04 +00:00
'#title' => t('Content ranking'),
);
2005-10-18 14:41:27 +00:00
$form['content_ranking']['#theme'] = 'node_search_admin';
2007-11-27 13:31:04 +00:00
$form['content_ranking']['info'] = array(
'#value' => '<em>'. t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') .'</em>'
);
2005-10-18 14:41:27 +00:00
$ranking = array('node_rank_relevance' => t('Keyword relevance'),
'node_rank_recent' => t('Recently posted'));
2006-08-20 05:57:41 +00:00
if (module_exists('comment')) {
2005-10-18 14:41:27 +00:00
$ranking['node_rank_comments'] = t('Number of comments');
}
2006-08-20 05:57:41 +00:00
if (module_exists('statistics') && variable_get('statistics_count_content_views', 0)) {
2005-10-18 14:41:27 +00:00
$ranking['node_rank_views'] = t('Number of views');
}
// Note: reversed to reflect that higher number = higher ranking.
$options = drupal_map_assoc(range(0, 10));
foreach ($ranking as $var => $title) {
2007-11-27 13:31:04 +00:00
$form['content_ranking']['factors'][$var] = array(
2007-11-28 10:29:21 +00:00
'#title' => $title,
'#type' => 'select',
'#options' => $options,
2007-11-27 13:31:04 +00:00
'#default_value' => variable_get($var, 5),
);
2005-10-18 14:41:27 +00:00
}
return $form;
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
case 'search':
2005-10-18 14:41:27 +00:00
// Build matching conditions
list($join1, $where1) = _db_rewrite_sql();
$arguments1 = array();
$conditions1 = 'n.status = 1';
if ($type = search_query_extract($keys, 'type')) {
$types = array();
foreach (explode(',', $type) as $t) {
$types[] = "n.type = '%s'";
$arguments1[] = $t;
}
$conditions1 .= ' AND ('. implode(' OR ', $types) .')';
$keys = search_query_insert($keys, 'type');
}
if ($category = search_query_extract($keys, 'category')) {
$categories = array();
foreach (explode(',', $category) as $c) {
$categories[] = "tn.tid = %d";
$arguments1[] = $c;
}
$conditions1 .= ' AND ('. implode(' OR ', $categories) .')';
2007-09-05 08:35:14 +00:00
$join1 .= ' INNER JOIN {term_node} tn ON n.vid = tn.vid';
2005-10-18 14:41:27 +00:00
$keys = search_query_insert($keys, 'category');
}
// Build ranking expression (we try to map each parameter to a
// uniform distribution in the range 0..1).
$ranking = array();
$arguments2 = array();
$join2 = '';
// Used to avoid joining on node_comment_statistics twice
2006-07-05 11:45:51 +00:00
$stats_join = FALSE;
2006-12-16 09:51:22 +00:00
$total = 0;
2005-10-18 14:41:27 +00:00
if ($weight = (int)variable_get('node_rank_relevance', 5)) {
// Average relevance values hover around 0.15
$ranking[] = '%d * i.relevance';
$arguments2[] = $weight;
2006-12-16 09:51:22 +00:00
$total += $weight;
2005-10-18 14:41:27 +00:00
}
if ($weight = (int)variable_get('node_rank_recent', 5)) {
// Exponential decay with half-life of 6 months, starting at last indexed node
2007-12-14 19:19:46 +00:00
$ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp)) - %d) * 6.43e-8)';
2005-10-18 14:41:27 +00:00
$arguments2[] = $weight;
$arguments2[] = (int)variable_get('node_cron_last', 0);
2007-11-13 14:04:08 +00:00
$join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
2006-07-05 11:45:51 +00:00
$stats_join = TRUE;
2006-12-16 09:51:22 +00:00
$total += $weight;
2005-10-18 14:41:27 +00:00
}
2006-08-20 05:57:41 +00:00
if (module_exists('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
2005-10-18 14:41:27 +00:00
// Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
$scale = variable_get('node_cron_comments_scale', 0.0);
2007-12-14 19:19:46 +00:00
$ranking[] = '%d * (2.0 - 2.0 / (1.0 + MAX(c.comment_count) * %f))';
2005-10-18 14:41:27 +00:00
$arguments2[] = $weight;
$arguments2[] = $scale;
if (!$stats_join) {
$join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
}
2006-12-16 09:51:22 +00:00
$total += $weight;
2005-10-18 14:41:27 +00:00
}
2006-08-20 05:57:41 +00:00
if (module_exists('statistics') && variable_get('statistics_count_content_views', 0) &&
2005-10-18 14:41:27 +00:00
$weight = (int)variable_get('node_rank_views', 5)) {
// Inverse law that maps the highest view count on the site to 1 and 0 to 0.
$scale = variable_get('node_cron_views_scale', 0.0);
2007-12-14 19:19:46 +00:00
$ranking[] = '%d * (2.0 - 2.0 / (1.0 + MAX(nc.totalcount) * %f))';
2005-10-18 14:41:27 +00:00
$arguments2[] = $weight;
$arguments2[] = $scale;
2006-04-21 10:26:53 +00:00
$join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
2006-12-16 09:51:22 +00:00
$total += $weight;
2005-10-18 14:41:27 +00:00
}
2007-01-11 08:51:31 +00:00
$select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') .' AS score';
2005-10-18 14:41:27 +00:00
// Do search
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1 .' INNER JOIN {users} u ON n.uid = u.uid', $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2);
// Load results
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
$results = array();
foreach ($find as $item) {
2006-08-10 15:42:33 +00:00
// Build the node body.
2006-02-28 13:32:33 +00:00
$node = node_load($item->sid);
2007-07-01 21:16:09 +00:00
$node->build_mode = NODE_BUILD_SEARCH_RESULT;
2006-08-10 15:42:33 +00:00
$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);
2005-07-29 03:21:09 +00:00
2005-10-18 14:41:27 +00:00
// Fetch comments for snippet
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
2006-04-27 22:20:51 +00:00
// Fetch terms for snippet
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
2005-10-18 14:41:27 +00:00
2004-12-31 09:30:12 +00:00
$extra = node_invoke_nodeapi($node, 'search result');
2007-02-15 11:40:19 +00:00
$results[] = array('link' => url('node/'. $item->sid, array('absolute' => TRUE)),
2007-11-28 10:29:21 +00:00
'type' => check_plain(node_get_types('name', $node)),
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
'title' => $node->title,
2005-08-01 05:14:05 +00:00
'user' => theme('username', $node),
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
'date' => $node->changed,
2005-10-18 14:41:27 +00:00
'node' => $node,
2004-12-31 09:30:12 +00:00
'extra' => $extra,
2006-12-16 09:51:22 +00:00
'score' => $item->score / $total,
2005-07-29 03:29:53 +00:00
'snippet' => search_excerpt($keys, $node->body));
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
}
return $results;
}
2001-11-01 11:00:51 +00:00
}
2006-03-26 19:31:00 +00:00
/**
* Implementation of hook_user().
*/
function node_user($op, &$edit, &$user) {
if ($op == 'delete') {
db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid);
db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid);
}
}
2007-12-06 09:58:34 +00:00
/**
* Theme the content ranking part of the search settings admin page.
*
* @ingroup themeable
*/
2005-10-18 14:41:27 +00:00
function theme_node_search_admin($form) {
2006-08-10 15:42:33 +00:00
$output = drupal_render($form['info']);
2005-10-18 14:41:27 +00:00
$header = array(t('Factor'), t('Weight'));
foreach (element_children($form['factors']) as $key) {
$row = array();
$row[] = $form['factors'][$key]['#title'];
unset($form['factors'][$key]['#title']);
2006-08-10 15:42:33 +00:00
$row[] = drupal_render($form['factors'][$key]);
2005-10-18 14:41:27 +00:00
$rows[] = $row;
}
$output .= theme('table', $header, $rows);
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form);
2005-10-18 14:41:27 +00:00
return $output;
}
2004-06-22 20:24:27 +00:00
/**
* Retrieve the comment mode for the given node ID (none, read, or read/write).
*/
2002-04-14 20:46:41 +00:00
function node_comment_mode($nid) {
2002-06-23 13:42:29 +00:00
static $comment_mode;
if (!isset($comment_mode[$nid])) {
2004-02-01 22:13:59 +00:00
$comment_mode[$nid] = db_result(db_query('SELECT comment FROM {node} WHERE nid = %d', $nid));
2002-06-23 13:42:29 +00:00
}
return $comment_mode[$nid];
2002-04-14 20:46:41 +00:00
}
2004-04-21 13:56:38 +00:00
/**
* Implementation of hook_link().
*/
2006-07-19 07:15:35 +00:00
function node_link($type, $node = NULL, $teaser = FALSE) {
2003-04-21 14:55:03 +00:00
$links = array();
2004-02-01 22:13:59 +00:00
if ($type == 'node') {
2007-08-02 20:08:53 +00:00
if ($teaser == 1 && $node->teaser && !empty($node->readmore)) {
2006-05-18 14:58:57 +00:00
$links['node_read_more'] = array(
2006-10-22 08:28:47 +00:00
'title' => t('Read more'),
2006-07-04 08:59:05 +00:00
'href' => "node/$node->nid",
2007-09-14 09:37:29 +00:00
// The title attribute gets escaped when the links are processed, so
// there is no need to escape here.
'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title)))
2006-05-18 14:58:57 +00:00
);
2003-11-11 16:25:10 +00:00
}
2001-06-29 22:08:57 +00:00
}
2003-04-21 14:55:03 +00:00
return $links;
2001-06-17 18:31:25 +00:00
}
2007-12-20 09:20:41 +00:00
function _node_revision_access($node, $op = 'view') {
static $access = array();
if (!isset($access[$node->vid])) {
$node_current_revision = node_load($node->nid);
$is_current_revision = $node_current_revision->vid == $node->vid;
// There should be at least two revisions. If the vid of the given node
// and the vid of the current revision differs, then we already have two
// different revisions so there is no need for a separate database check.
// Also, if you try to revert to or delete the current revision, that's
// not good.
if ($is_current_revision && (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $node->nid)) == 1 || $op == 'update' || $op == 'delete')) {
$access[$node->vid] = FALSE;
}
elseif (user_access('administer nodes')) {
$access[$node->vid] = TRUE;
}
else {
$map = array('view' => 'view revisions', 'update' => 'revert revisions', 'delete' => 'delete revisions');
// First check the user permission, second check the access to the
// current revision and finally, if the node passed in is not the current
// revision then access to that, too.
$access[$node->vid] = isset($map[$op]) && user_access($map[$op]) && node_access($op, $node_current_revision) && ($is_current_revision || node_access($op, $node));
}
}
return $access[$node->vid];
2007-01-24 14:48:36 +00:00
}
2007-08-20 07:03:08 +00:00
function _node_add_access() {
$types = node_get_types();
foreach ($types as $type) {
if (node_hook($type->type, 'form') && node_access('create', $type->type)) {
return TRUE;
}
}
return FALSE;
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2007-01-24 14:48:36 +00:00
function node_menu() {
$items['admin/content/node'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Content',
'description' => "View, edit, and delete your site's content.",
2007-08-10 06:29:01 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
2007-01-24 14:48:36 +00:00
'access arguments' => array('administer nodes'),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
2007-01-24 14:48:36 +00:00
);
2005-11-24 22:03:40 +00:00
2007-01-24 14:48:36 +00:00
$items['admin/content/node/overview'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'List',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
2005-11-24 22:03:40 +00:00
2007-01-24 14:48:36 +00:00
$items['admin/content/node-settings'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Post settings',
'description' => 'Control posting behavior, such as teaser length, requiring previews before posting, and the number of posts on the front page.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('node_configure'),
'access arguments' => array('administer nodes'),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/content/node-settings/rebuild'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Rebuild permissions',
2007-01-24 14:48:36 +00:00
'page arguments' => array('node_configure_rebuild_confirm'),
2007-08-20 07:03:08 +00:00
'file' => 'node.admin.inc',
2007-09-02 14:42:30 +00:00
// Any user than can potentially trigger a node_acess_needs_rebuild(TRUE)
// has to be allowed access to the 'node access rebuild' confirm form.
'access arguments' => array('access administration pages'),
2007-01-24 14:48:36 +00:00
'type' => MENU_CALLBACK,
);
$items['admin/content/types'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Content types',
'description' => 'Manage posts by content type, including default status, front page promotion, etc.',
2007-01-24 14:48:36 +00:00
'page callback' => 'node_overview_types',
'access arguments' => array('administer content types'),
2007-08-20 07:03:08 +00:00
'file' => 'content_types.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/content/types/list'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'List',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/content/types/add'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Add content type',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('node_type_form'),
2007-08-20 07:03:08 +00:00
'file' => 'content_types.inc',
2007-01-24 14:48:36 +00:00
'type' => MENU_LOCAL_TASK,
);
$items['node'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Content',
2007-01-24 14:48:36 +00:00
'page callback' => 'node_page_default',
'access arguments' => array('access content'),
2007-11-24 20:59:32 +00:00
'type' => MENU_CALLBACK,
2007-01-24 14:48:36 +00:00
);
$items['node/add'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Create content',
2007-08-20 07:03:08 +00:00
'page callback' => 'node_add_page',
2007-03-12 13:01:10 +00:00
'access callback' => '_node_add_access',
2007-01-24 14:48:36 +00:00
'weight' => 1,
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-01-24 14:48:36 +00:00
);
$items['rss.xml'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'RSS feed',
2007-01-24 14:48:36 +00:00
'page callback' => 'node_feed',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
2007-07-21 09:55:18 +00:00
foreach (node_get_types('types', NULL, TRUE) as $type) {
$type_url_str = str_replace('_', '-', $type->type);
$items['node/add/'. $type_url_str] = array(
2007-12-05 19:12:59 +00:00
'title' => drupal_ucfirst($type->name),
2007-07-21 09:55:18 +00:00
'page callback' => 'node_add',
'page arguments' => array(2),
'access callback' => 'node_access',
'access arguments' => array('create', $type->type),
'description' => $type->description,
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-07-21 09:55:18 +00:00
);
$items['admin/content/types/'. $type_url_str] = array(
'title' => $type->name,
'page callback' => 'drupal_get_form',
'page arguments' => array('node_type_form', $type),
2007-08-20 07:03:08 +00:00
'file' => 'content_types.inc',
2007-07-21 09:55:18 +00:00
'type' => MENU_CALLBACK,
);
$items['admin/content/types/'. $type_url_str .'/delete'] = array(
'title' => 'Delete',
'page arguments' => array('node_type_delete_confirm', $type),
2007-08-20 07:03:08 +00:00
'file' => 'content_types.inc',
2007-07-21 09:55:18 +00:00
'type' => MENU_CALLBACK,
);
2004-06-18 15:04:37 +00:00
}
2007-02-11 09:30:51 +00:00
$items['node/%node'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'View',
2007-01-24 14:48:36 +00:00
'page callback' => 'node_page_view',
'page arguments' => array(1),
'access callback' => 'node_access',
'access arguments' => array('view', 1),
'type' => MENU_CALLBACK);
2007-02-11 09:30:51 +00:00
$items['node/%node/view'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'View',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10);
2007-02-11 09:30:51 +00:00
$items['node/%node/edit'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Edit',
2007-01-24 14:48:36 +00:00
'page callback' => 'node_page_edit',
'page arguments' => array(1),
2007-05-16 13:45:17 +00:00
'access callback' => 'node_access',
2007-01-24 14:48:36 +00:00
'access arguments' => array('update', 1),
'weight' => 1,
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
'type' => MENU_LOCAL_TASK,
);
2007-02-11 09:30:51 +00:00
$items['node/%node/delete'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Delete',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('node_delete_confirm', 1),
2007-05-16 13:45:17 +00:00
'access callback' => 'node_access',
2007-01-24 14:48:36 +00:00
'access arguments' => array('delete', 1),
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-01-24 14:48:36 +00:00
'weight' => 1,
'type' => MENU_CALLBACK);
2007-02-11 09:30:51 +00:00
$items['node/%node/revisions'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Revisions',
2007-12-20 09:20:41 +00:00
'page callback' => 'node_revision_overview',
'page arguments' => array(1),
2007-01-24 14:48:36 +00:00
'access callback' => '_node_revision_access',
'access arguments' => array(1),
'weight' => 2,
2007-08-20 07:03:08 +00:00
'file' => 'node.pages.inc',
2007-01-24 14:48:36 +00:00
'type' => MENU_LOCAL_TASK,
);
2007-12-20 09:20:41 +00:00
$items['node/%node/revisions/%/view'] = array(
'title' => 'Revisions',
2007-12-21 11:55:23 +00:00
'load arguments' => array(3),
2007-12-20 09:20:41 +00:00
'page callback' => 'node_show',
'page arguments' => array(1, NULL, TRUE),
'type' => MENU_CALLBACK,
);
2007-12-03 07:45:15 +00:00
$items['node/%node/revisions/%/revert'] = array(
'title' => 'Revert to earlier revision',
2007-12-20 09:20:41 +00:00
'load arguments' => array(3),
'page callback' => 'drupal_get_form',
'page arguments' => array('node_revision_revert_confirm', 1),
2007-12-03 07:45:15 +00:00
'access callback' => '_node_revision_access',
2007-12-20 09:20:41 +00:00
'access arguments' => array(1, 'update'),
2007-12-03 07:45:15 +00:00
'file' => 'node.pages.inc',
'type' => MENU_CALLBACK,
);
$items['node/%node/revisions/%/delete'] = array(
'title' => 'Delete earlier revision',
2007-12-20 09:20:41 +00:00
'load arguments' => array(3),
'page callback' => 'drupal_get_form',
'page arguments' => array('node_revision_delete_confirm', 1),
2007-12-03 07:45:15 +00:00
'access callback' => '_node_revision_access',
2007-12-20 09:20:41 +00:00
'access arguments' => array(1, 'delete'),
2007-12-03 07:45:15 +00:00
'file' => 'node.pages.inc',
'type' => MENU_CALLBACK,
);
2004-06-18 15:04:37 +00:00
return $items;
}
2007-01-24 14:48:36 +00:00
function node_init() {
drupal_add_css(drupal_get_path('module', 'node') .'/node.css');
}
2005-01-27 14:45:42 +00:00
function node_last_changed($nid) {
$node = db_fetch_object(db_query('SELECT changed FROM {node} WHERE nid = %d', $nid));
return ($node->changed);
}
2006-02-14 21:12:09 +00:00
/**
2007-08-20 07:03:08 +00:00
* Return a list of all the existing revision numbers.
2006-07-31 19:12:44 +00:00
*/
2007-08-20 07:03:08 +00:00
function node_revision_list($node) {
$revisions = array();
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revisions} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = %d ORDER BY r.timestamp DESC', $node->nid);
while ($revision = db_fetch_object($result)) {
$revisions[$revision->vid] = $revision;
}
2006-12-08 16:21:15 +00:00
2007-08-20 07:03:08 +00:00
return $revisions;
2006-07-31 19:12:44 +00:00
}
2006-02-14 21:12:09 +00:00
/**
2007-08-20 07:03:08 +00:00
* Implementation of hook_block().
2006-02-14 21:12:09 +00:00
*/
2007-08-20 07:03:08 +00:00
function node_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Syndicate');
// Not worth caching.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;
2007-06-15 18:40:14 +00:00
}
2007-08-20 07:03:08 +00:00
else if ($op == 'view') {
$block['subject'] = t('Syndicate');
$block['content'] = theme('feed_icon', url('rss.xml'), t('Syndicate'));
2007-06-15 18:40:14 +00:00
2007-08-20 07:03:08 +00:00
return $block;
2007-04-25 21:28:00 +00:00
}
2005-10-07 06:11:12 +00:00
}
2006-02-14 21:12:09 +00:00
/**
2007-08-20 07:03:08 +00:00
* A generic function for generating RSS feeds from a set of nodes.
*
* @param $nids
2007-12-10 10:29:19 +00:00
* An array of node IDs (nid). Defaults to FALSE so empty feeds can be
* generated with passing an empty array, if no items are to be added
* to the feed.
2007-08-20 07:03:08 +00:00
* @param $channel
* An associative array containing title, link, description and other keys.
* The link should be an absolute URL.
2006-02-14 21:12:09 +00:00
*/
2007-12-10 10:29:19 +00:00
function node_feed($nids = FALSE, $channel = array()) {
2007-08-20 07:03:08 +00:00
global $base_url, $language;
2004-05-03 17:38:40 +00:00
2007-12-10 10:29:19 +00:00
if ($nids === FALSE) {
$nids = array();
2007-08-20 07:03:08 +00:00
$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, variable_get('feed_default_items', 10));
while ($row = db_fetch_object($result)) {
$nids[] = $row->nid;
2007-04-21 18:10:53 +00:00
}
2003-08-02 06:49:32 +00:00
}
2005-01-17 18:56:11 +00:00
2007-08-20 07:03:08 +00:00
$item_length = variable_get('feed_item_length', 'teaser');
$namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/');
2005-10-07 06:11:12 +00:00
2007-08-20 07:03:08 +00:00
$items = '';
foreach ($nids as $nid) {
// Load the specified node:
$item = node_load($nid);
$node->build_mode = NODE_BUILD_RSS;
$link = url("node/$nid", array('absolute' => TRUE));
2003-08-02 06:49:32 +00:00
2007-08-20 07:03:08 +00:00
if ($item_length != 'title') {
$teaser = ($item_length == 'teaser') ? TRUE : FALSE;
2007-07-14 15:28:02 +00:00
2007-08-20 07:03:08 +00:00
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
$item = node_invoke($item, 'view', $teaser, FALSE);
}
else {
$item = node_prepare($item, $teaser);
}
2005-09-18 10:37:57 +00:00
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', $teaser, FALSE);
2004-09-28 19:13:03 +00:00
}
2006-07-13 12:06:45 +00:00
// Allow modules to add additional item fields and/or modify $item
$extra = node_invoke_nodeapi($item, 'rss item');
2007-12-22 23:24:26 +00:00
$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'))));
2006-07-13 12:06:45 +00:00
foreach ($extra as $element) {
2007-03-27 05:13:55 +00:00
if (isset($element['namespace'])) {
2006-07-13 12:06:45 +00:00
$namespaces = array_merge($namespaces, $element['namespace']);
}
}
2005-09-18 10:37:57 +00:00
// Prepare the item description
switch ($item_length) {
case 'fulltext':
$item_text = $item->body;
break;
case 'teaser':
$item_text = $item->teaser;
2007-08-02 20:08:53 +00:00
if (!empty($item->readmore)) {
2007-12-11 12:42:37 +00:00
$item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, array('absolute' => TRUE, 'attributes' => array('target' => '_blank'))) .'</p>';
2005-09-18 10:37:57 +00:00
}
break;
case 'title':
$item_text = '';
break;
}
2004-12-23 23:26:14 +00:00
2005-09-18 10:37:57 +00:00
$items .= format_rss_item($item->title, $link, $item_text, $extra);
2001-07-15 16:56:44 +00:00
}
2004-02-11 19:21:14 +00:00
$channel_defaults = array(
2005-03-07 21:52:57 +00:00
'version' => '2.0',
2007-07-27 13:07:06 +00:00
'title' => variable_get('site_name', 'Drupal'),
2004-02-11 19:21:14 +00:00
'link' => $base_url,
'description' => variable_get('site_mission', ''),
2007-03-26 01:32:22 +00:00
'language' => $language->language
2004-02-11 19:21:14 +00:00
);
$channel = array_merge($channel_defaults, $channel);
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2007-07-16 07:40:27 +00:00
$output .= "<rss version=\"". $channel["version"] ."\" xml:base=\"". $base_url ."\" ". drupal_attributes($namespaces) .">\n";
2004-02-01 22:13:59 +00:00
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
2001-07-15 16:56:44 +00:00
$output .= "</rss>\n";
2006-07-03 08:04:33 +00:00
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
2001-07-15 16:56:44 +00:00
print $output;
}
2004-06-22 20:24:27 +00:00
/**
2006-08-15 07:30:17 +00:00
* Menu callback; Generate a listing of promoted nodes.
2004-06-22 20:24:27 +00:00
*/
2004-02-08 21:16:03 +00:00
function node_page_default() {
2005-01-29 22:02:37 +00:00
$result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));
2004-02-08 21:16:03 +00:00
2007-08-12 15:55:36 +00:00
$output = '';
2007-08-12 16:12:00 +00:00
$num_rows = FALSE;
2007-08-12 15:55:36 +00:00
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
2007-08-12 16:12:00 +00:00
$num_rows = TRUE;
2007-08-12 15:55:36 +00:00
}
2007-08-12 16:12:00 +00:00
if ($num_rows) {
2007-02-15 11:40:19 +00:00
$feed_url = url('rss.xml', array('absolute' => TRUE));
2006-10-22 08:28:47 +00:00
drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') .' '. t('RSS'));
2004-02-08 21:16:03 +00:00
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
}
else {
2006-12-20 08:06:20 +00:00
$default_message = t('<h1 class="title">Welcome to your new Drupal website!</h1><p>Please follow these steps to set up and start using your website:</p>');
$default_message .= '<ol>';
2007-05-14 13:43:38 +00:00
2006-12-20 08:06:20 +00:00
$default_message .= '<li>'. t('<strong>Configure your website</strong> Once logged in, visit the <a href="@admin">administration section</a>, where you can <a href="@config">customize and configure</a> all aspects of your website.', array('@admin' => url('admin'), '@config' => url('admin/settings'))) .'</li>';
2007-11-24 20:35:37 +00:00
$default_message .= '<li>'. t('<strong>Enable additional functionality</strong> Next, visit the <a href="@modules">module list</a> and enable features which suit your specific needs. You can find additional modules in the <a href="@download_modules">Drupal modules download section</a>.', array('@modules' => url('admin/build/modules'), '@download_modules' => 'http://drupal.org/project/modules')) .'</li>';
$default_message .= '<li>'. t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href="@themes">themes section</a>. You may choose from one of the included themes or download additional themes from the <a href="@download_themes">Drupal themes download section</a>.', array('@themes' => url('admin/build/themes'), '@download_themes' => 'http://drupal.org/project/themes')) .'</li>';
2007-01-04 09:53:58 +00:00
$default_message .= '<li>'. t('<strong>Start posting content</strong> Finally, you can <a href="@content">create content</a> for your website. This message will disappear once you have promoted a post to the front page.', array('@content' => url('node/add'))) .'</li>';
2006-12-20 08:06:20 +00:00
$default_message .= '</ol>';
$default_message .= '<p>'. t('For more information, please refer to the <a href="@help">help section</a>, or the <a href="@handbook">online Drupal handbooks</a>. You may also post at the <a href="@forum">Drupal forum</a>, or view the wide range of <a href="@support">other support options</a> available.', array('@help' => url('admin/help'), '@handbook' => 'http://drupal.org/handbooks', '@forum' => 'http://drupal.org/forum', '@support' => 'http://drupal.org/support')) .'</p>';
$output = '<div id="first-time">'. $default_message .'</div>';
2004-02-08 21:16:03 +00:00
}
2006-08-15 07:30:17 +00:00
drupal_set_title('');
2004-02-08 21:16:03 +00:00
return $output;
}
2004-06-22 20:24:27 +00:00
/**
2006-08-15 07:30:17 +00:00
* Menu callback; view a single node.
2004-06-22 20:24:27 +00:00
*/
2006-08-15 07:30:17 +00:00
function node_page_view($node, $cid = NULL) {
drupal_set_title(check_plain($node->title));
return node_show($node, $cid);
}
2001-11-01 11:00:51 +00:00
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_update_index().
*/
2002-03-05 20:15:17 +00:00
function node_update_index() {
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
$limit = (int)variable_get('search_cron_limit', 100);
2005-10-18 14:41:27 +00:00
// Store the maximum possible comments per thread (used for ranking by reply count)
variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));
variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
2007-11-13 14:04:08 +00:00
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
while ($node = db_fetch_object($result)) {
2007-11-13 14:04:08 +00:00
_node_index_node($node);
}
}
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
2007-11-13 14:04:08 +00:00
/**
* Index a single node.
*
* @param $node
* The node to index.
*/
function _node_index_node($node) {
$node = node_load($node->nid);
2007-09-26 18:22:34 +00:00
2007-11-13 14:04:08 +00:00
// save the changed time of the most recent indexed node, for the search results half-life calculation
variable_set('node_cron_last', $node->changed);
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
2007-11-13 14:04:08 +00:00
// Build the node body.
$node->build_mode = NODE_BUILD_SEARCH_INDEX;
$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
2007-11-13 14:04:08 +00:00
$text = '<h1>'. check_plain($node->title) .'</h1>'. $node->body;
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
2007-11-13 14:04:08 +00:00
// Fetch extra data normally not visible
$extra = node_invoke_nodeapi($node, 'update index');
foreach ($extra as $t) {
$text .= $t;
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
}
2007-11-13 14:04:08 +00:00
// Update index
search_index($node->nid, 'node', $text);
2003-02-23 21:36:29 +00:00
}
2002-03-05 20:15:17 +00:00
2006-03-30 20:23:39 +00:00
/**
* Implementation of hook_form_alter().
*/
2007-05-28 06:08:47 +00:00
function node_form_alter(&$form, $form_state, $form_id) {
2006-03-30 20:23:39 +00:00
// Advanced node search form
2007-02-11 09:30:51 +00:00
if ($form_id == 'search_form' && $form['module']['#value'] == 'node' && user_access('use advanced search')) {
2006-03-30 20:23:39 +00:00
// Keyword boxes:
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced search'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array('class' => 'search-advanced'),
);
$form['advanced']['keywords'] = array(
'#prefix' => '<div class="criterion">',
'#suffix' => '</div>',
);
$form['advanced']['keywords']['or'] = array(
'#type' => 'textfield',
'#title' => t('Containing any of the words'),
'#size' => 30,
'#maxlength' => 255,
);
$form['advanced']['keywords']['phrase'] = array(
'#type' => 'textfield',
'#title' => t('Containing the phrase'),
'#size' => 30,
'#maxlength' => 255,
);
$form['advanced']['keywords']['negative'] = array(
'#type' => 'textfield',
'#title' => t('Containing none of the words'),
'#size' => 30,
'#maxlength' => 255,
);
// Taxonomy box:
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$form['advanced']['category'] = array(
'#type' => 'select',
'#title' => t('Only in the category(s)'),
'#prefix' => '<div class="criterion">',
'#size' => 10,
'#suffix' => '</div>',
'#options' => $taxonomy,
'#multiple' => TRUE,
);
}
// Node types:
2007-11-28 10:29:21 +00:00
$types = array_map('check_plain', node_get_types('names'));
2006-03-30 20:23:39 +00:00
$form['advanced']['type'] = array(
'#type' => 'checkboxes',
'#title' => t('Only of the type(s)'),
'#prefix' => '<div class="criterion">',
'#suffix' => '</div>',
'#options' => $types,
);
$form['advanced']['submit'] = array(
'#type' => 'submit',
'#value' => t('Advanced search'),
2007-03-14 21:41:06 +00:00
'#prefix' => '<div class="action">',
2006-08-25 09:01:12 +00:00
'#suffix' => '</div>',
2006-03-30 20:23:39 +00:00
);
2007-05-14 13:43:38 +00:00
$form['#validate'][] = 'node_search_validate';
2006-03-30 20:23:39 +00:00
}
}
/**
* Form API callback for the search form. Registered in node_form_alter().
*/
2007-06-04 07:22:23 +00:00
function node_search_validate($form, &$form_state) {
2006-03-30 20:23:39 +00:00
// Initialise using any existing basic search keywords.
2007-06-04 07:22:23 +00:00
$keys = $form_state['values']['processed_keys'];
2006-03-30 20:23:39 +00:00
// Insert extra restrictions into the search keywords string.
2007-06-04 07:22:23 +00:00
if (isset($form_state['values']['type']) && is_array($form_state['values']['type'])) {
2006-03-30 20:23:39 +00:00
// Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
2007-06-04 07:22:23 +00:00
$form_state['values']['type'] = array_filter($form_state['values']['type']);
if (count($form_state['values']['type'])) {
$keys = search_query_insert($keys, 'type', implode(',', array_keys($form_state['values']['type'])));
2006-03-30 20:23:39 +00:00
}
}
2006-04-15 21:52:44 +00:00
2007-06-04 07:22:23 +00:00
if (isset($form_state['values']['category']) && is_array($form_state['values']['category'])) {
$keys = search_query_insert($keys, 'category', implode(',', $form_state['values']['category']));
2006-03-30 20:23:39 +00:00
}
2007-06-04 07:22:23 +00:00
if ($form_state['values']['or'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $form_state['values']['or'], $matches)) {
2006-03-30 20:23:39 +00:00
$keys .= ' '. implode(' OR ', $matches[1]);
}
}
2007-06-04 07:22:23 +00:00
if ($form_state['values']['negative'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $form_state['values']['negative'], $matches)) {
2006-03-30 20:23:39 +00:00
$keys .= ' -'. implode(' -', $matches[1]);
}
}
2007-06-04 07:22:23 +00:00
if ($form_state['values']['phrase'] != '') {
$keys .= ' "'. str_replace('"', ' ', $form_state['values']['phrase']) .'"';
2006-03-30 20:23:39 +00:00
}
if (!empty($keys)) {
2007-05-14 13:43:38 +00:00
form_set_value($form['basic']['inline']['processed_keys'], trim($keys), $form_state);
2006-03-30 20:23:39 +00:00
}
2003-02-16 14:57:35 +00:00
}
2004-07-31 09:30:09 +00:00
/**
* @defgroup node_access Node access rights
* @{
* The node access system determines who can do what to which nodes.
*
* In determining access rights for a node, node_access() first checks
* whether the user has the "administer nodes" permission. Such users have
* unrestricted access to all nodes. Then the node module's hook_access()
* is called, and a TRUE or FALSE return value will grant or deny access.
* This allows, for example, the blog module to always grant access to the
* blog author, and for the book module to always deny editing access to
* PHP pages.
*
* If node module does not intervene (returns NULL), then the
* node_access table is used to determine access. All node access
* modules are queried using hook_node_grants() to assemble a list of
* "grant IDs" for the user. This list is compared against the table.
* If any row contains the node ID in question (or 0, which stands for "all
* nodes"), one of the grant IDs returned, and a value of TRUE for the
* operation in question, then access is granted. Note that this table is a
* list of grants; any matching row is sufficient to grant access to the
* node.
*
* In node listings, the process above is followed except that
* hook_access() is not called on each node for performance reasons and for
* proper functioning of the pager system. When adding a node listing to your
2005-02-18 18:40:05 +00:00
* module, be sure to use db_rewrite_sql() to add
2004-07-31 09:30:09 +00:00
* the appropriate clauses to your query for access checks.
*
* To see how to write a node access module of your own, see
* node_access_example.module.
*/
/**
* Determine whether the current user may perform the given operation on the
* specified node.
*
* @param $op
* The operation to be performed on the node. Possible values are:
* - "view"
* - "update"
* - "delete"
2006-01-06 16:21:34 +00:00
* - "create"
2004-07-31 09:30:09 +00:00
* @param $node
2006-01-08 12:49:51 +00:00
* The node object (or node array) on which the operation is to be performed,
2006-01-06 16:21:34 +00:00
* or node type (e.g. 'forum') for "create" operation.
2007-10-11 16:37:43 +00:00
* @param $account
* Optional, a user object representing the user for whom the operation is to
* be performed. Determines access for a user other than the current user.
2004-07-31 09:30:09 +00:00
* @return
* TRUE if the operation may be performed.
*/
2007-10-11 16:37:43 +00:00
function node_access($op, $node, $account = NULL) {
2006-11-12 19:09:11 +00:00
global $user;
2007-01-24 14:48:36 +00:00
if (!$node) {
return FALSE;
}
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
// Convert the node to an object if necessary:
2006-01-06 16:21:34 +00:00
if ($op != 'create') {
$node = (object)$node;
}
2007-10-11 16:37:43 +00:00
// If no user object is supplied, the access check is for the current user.
if (empty($account)) {
$account = $user;
}
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
return FALSE;
}
2007-10-11 16:37:43 +00:00
if (user_access('administer nodes', $account)) {
2004-07-31 09:30:09 +00:00
return TRUE;
}
2007-10-11 16:37:43 +00:00
if (!user_access('access content', $account)) {
2004-08-21 16:04:12 +00:00
return FALSE;
}
2004-07-31 09:30:09 +00:00
// Can't use node_invoke(), because the access hook takes the $op parameter
// before the $node parameter.
2006-08-06 23:00:42 +00:00
$module = node_get_types('module', $node);
if ($module == 'node') {
$module = 'node_content'; // Avoid function name collisions.
}
2007-10-11 16:37:43 +00:00
$access = module_invoke($module, 'access', $op, $node, $account);
2004-07-31 09:30:09 +00:00
if (!is_null($access)) {
return $access;
}
// If the module did not override the access rights, use those set in the
// node_access table.
2006-01-06 16:21:34 +00:00
if ($op != 'create' && $node->nid && $node->status) {
2004-07-31 09:30:09 +00:00
$grants = array();
2007-10-11 16:37:43 +00:00
foreach (node_access_grants($op, $account) as $realm => $gids) {
2004-07-31 09:30:09 +00:00
foreach ($gids as $gid) {
2005-12-08 15:30:27 +00:00
$grants[] = "(gid = $gid AND realm = '$realm')";
2004-07-31 09:30:09 +00:00
}
}
2005-12-08 15:30:27 +00:00
$grants_sql = '';
if (count($grants)) {
$grants_sql = 'AND ('. implode(' OR ', $grants) .')';
}
$sql = "SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) $grants_sql AND grant_$op >= 1";
2004-08-05 20:26:25 +00:00
$result = db_query($sql, $node->nid);
2004-07-31 09:30:09 +00:00
return (db_result($result));
}
2006-11-12 19:09:11 +00:00
// Let authors view their own nodes.
2007-10-11 16:37:43 +00:00
if ($op == 'view' && $account->uid == $node->uid && $account->uid != 0) {
2006-11-12 19:09:11 +00:00
return TRUE;
}
2004-07-31 09:30:09 +00:00
return FALSE;
}
/**
* Generate an SQL join clause for use in fetching a node listing.
*
* @param $node_alias
* If the node table has been given an SQL alias other than the default
* "n", that must be passed here.
* @param $node_access_alias
* If the node_access table has been given an SQL alias other than the default
* "na", that must be passed here.
* @return
* An SQL join clause.
*/
2005-03-05 11:05:07 +00:00
function _node_access_join_sql($node_alias = 'n', $node_access_alias = 'na') {
2005-03-01 20:01:40 +00:00
if (user_access('administer nodes')) {
2004-07-31 09:30:09 +00:00
return '';
}
2005-03-01 20:01:40 +00:00
return 'INNER JOIN {node_access} '. $node_access_alias .' ON '. $node_access_alias .'.nid = '. $node_alias .'.nid';
2004-07-31 09:30:09 +00:00
}
/**
* Generate an SQL where clause for use in fetching a node listing.
*
* @param $op
* The operation that must be allowed to return a node.
* @param $node_access_alias
* If the node_access table has been given an SQL alias other than the default
* "na", that must be passed here.
2007-10-11 16:37:43 +00:00
* @param $account
2007-10-12 14:10:18 +00:00
* The user object for the user performing the operation. If omitted, the
2007-10-11 16:37:43 +00:00
* current user is used.
2004-07-31 09:30:09 +00:00
* @return
* An SQL where clause.
*/
2007-10-11 16:37:43 +00:00
function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $account = NULL) {
2005-03-01 20:01:40 +00:00
if (user_access('administer nodes')) {
2005-02-18 18:40:05 +00:00
return;
2004-07-31 09:30:09 +00:00
}
$grants = array();
2007-10-11 16:37:43 +00:00
foreach (node_access_grants($op, $account) as $realm => $gids) {
2004-07-31 09:30:09 +00:00
foreach ($gids as $gid) {
2005-12-08 15:30:27 +00:00
$grants[] = "($node_access_alias.gid = $gid AND $node_access_alias.realm = '$realm')";
2004-07-31 09:30:09 +00:00
}
}
2005-12-08 15:30:27 +00:00
$grants_sql = '';
if (count($grants)) {
$grants_sql = 'AND ('. implode(' OR ', $grants) .')';
}
$sql = "$node_access_alias.grant_$op >= 1 $grants_sql";
2004-07-31 09:30:09 +00:00
return $sql;
}
/**
* Fetch an array of permission IDs granted to the given user ID.
*
* The implementation here provides only the universal "all" grant. A node
* access module should implement hook_node_grants() to provide a grant
* list for the user.
*
* @param $op
* The operation that the user is trying to perform.
2007-10-11 16:37:43 +00:00
* @param $account
2007-10-12 14:10:18 +00:00
* The user object for the user performing the operation. If omitted, the
2007-10-11 16:37:43 +00:00
* current user is used.
2004-07-31 09:30:09 +00:00
* @return
* An associative array in which the keys are realms, and the values are
* arrays of grants for those realms.
*/
2007-10-11 16:37:43 +00:00
function node_access_grants($op, $account = NULL) {
2004-07-31 09:30:09 +00:00
2007-10-11 16:37:43 +00:00
if (!isset($account)) {
$account = $GLOBALS['user'];
2004-07-31 09:30:09 +00:00
}
2007-10-11 16:37:43 +00:00
return array_merge(array('all' => array(0)), module_invoke_all('node_grants', $account, $op));
2004-07-31 09:30:09 +00:00
}
/**
2005-02-18 18:40:05 +00:00
* Determine whether the user has a global viewing grant for all nodes.
2004-07-31 09:30:09 +00:00
*/
2005-02-18 18:40:05 +00:00
function node_access_view_all_nodes() {
static $access;
if (!isset($access)) {
$grants = array();
foreach (node_access_grants('view') as $realm => $gids) {
foreach ($gids as $gid) {
2005-12-08 15:30:27 +00:00
$grants[] = "(gid = $gid AND realm = '$realm')";
2005-02-18 18:40:05 +00:00
}
}
2005-12-08 15:30:27 +00:00
$grants_sql = '';
if (count($grants)) {
$grants_sql = 'AND ('. implode(' OR ', $grants) .')';
}
$sql = "SELECT COUNT(*) FROM {node_access} WHERE nid = 0 $grants_sql AND grant_view >= 1";
2005-10-07 06:11:12 +00:00
$result = db_query($sql);
2005-02-18 18:40:05 +00:00
$access = db_result($result);
}
return $access;
}
2004-07-31 09:30:09 +00:00
2005-01-16 18:44:49 +00:00
/**
2005-01-29 22:02:37 +00:00
* Implementation of hook_db_rewrite_sql
2005-01-16 18:44:49 +00:00
*/
2005-01-31 20:45:10 +00:00
function node_db_rewrite_sql($query, $primary_table, $primary_field) {
2005-02-18 18:40:05 +00:00
if ($primary_field == 'nid' && !node_access_view_all_nodes()) {
2005-03-24 22:09:31 +00:00
$return['join'] = _node_access_join_sql($primary_table);
2005-03-05 11:05:07 +00:00
$return['where'] = _node_access_where_sql();
2005-03-01 20:01:40 +00:00
$return['distinct'] = 1;
2005-01-29 22:02:37 +00:00
return $return;
2005-01-16 18:44:49 +00:00
}
}
2006-08-05 02:12:46 +00:00
/**
* This function will call module invoke to get a list of grants and then
* write them to the database. It is called at node save, and should be
* called by modules whenever something other than a node_save causes
* the permissions on a node to change.
*
* This function is the only function that should write to the node_access
* table.
*
* @param $node
* The $node to acquire grants for.
*/
function node_access_acquire_grants($node) {
$grants = module_invoke_all('node_access_records', $node);
2007-09-02 14:42:30 +00:00
if (empty($grants)) {
2006-08-05 02:12:46 +00:00
$grants[] = array('realm' => 'all', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
}
else {
// retain grants by highest priority
$grant_by_priority = array();
foreach ($grants as $g) {
$grant_by_priority[intval($g['priority'])][] = $g;
}
krsort($grant_by_priority);
$grants = array_shift($grant_by_priority);
}
node_access_write_grants($node, $grants);
}
/**
* This function will write a list of grants to the database, deleting
* any pre-existing grants. If a realm is provided, it will only
* delete grants from that realm, but it will always delete a grant
* from the 'all' realm. Modules which utilize node_access can
* use this function when doing mass updates due to widespread permission
* changes.
*
* @param $node
* The $node being written to. All that is necessary is that it contain a nid.
* @param $grants
* A list of grants to write. Each grant is an array that must contain the
* following keys: realm, gid, grant_view, grant_update, grant_delete.
* The realm is specified by a particular module; the gid is as well, and
* is a module-defined id to define grant privileges. each grant_* field
* is a boolean value.
* @param $realm
* If provided, only read/write grants for that realm.
* @param $delete
* If false, do not delete records. This is only for optimization purposes,
* and assumes the caller has already performed a mass delete of some form.
*/
function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE) {
if ($delete) {
$query = 'DELETE FROM {node_access} WHERE nid = %d';
if ($realm) {
$query .= " AND realm in ('%s', 'all')";
}
db_query($query, $node->nid, $realm);
}
2006-12-25 22:02:05 +00:00
// Only perform work when node_access modules are active.
2006-08-05 02:12:46 +00:00
if (count(module_implements('node_grants'))) {
foreach ($grants as $grant) {
if ($realm && $realm != $grant['realm']) {
continue;
}
// Only write grants; denies are implicit.
if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
2006-12-25 22:02:05 +00:00
db_query("INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (%d, '%s', %d, %d, %d, %d)", $node->nid, $grant['realm'], $grant['gid'], $grant['grant_view'], $grant['grant_update'], $grant['grant_delete']);
2006-08-05 02:12:46 +00:00
}
}
}
}
2007-09-02 14:42:30 +00:00
/**
* Flag / unflag the node access grants for rebuilding, or read the current
* value of the flag.
*
* When the flag is set, a message is displayed to users with 'access
* administration pages' permission, pointing to the 'rebuild' confirm form.
* This can be used as an alternative to direct node_access_rebuild calls,
* allowing administrators to decide when they want to perform the actual
* (possibly time consuming) rebuild.
* When unsure the current user is an adminisrator, node_access_rebuild
* should be used instead.
*
* @param $rebuild
* (Optional) The boolean value to be written.
* @return
* (If no value was provided for $rebuild) The current value of the flag.
*/
function node_access_needs_rebuild($rebuild = NULL) {
if (!isset($rebuild)) {
return variable_get('node_access_needs_rebuild', FALSE);
}
elseif ($rebuild) {
variable_set('node_access_needs_rebuild', TRUE);
}
else {
variable_del('node_access_needs_rebuild');
}
}
2006-08-05 02:12:46 +00:00
/**
2006-10-23 06:41:28 +00:00
* Rebuild the node access database. This is occasionally needed by modules
* that make system-wide changes to access levels.
2007-09-02 14:42:30 +00:00
*
* When the rebuild is required by an admin-triggered action (e.g module
* settings form), calling node_access_needs_rebuild(TRUE) instead of
* node_access_rebuild() lets the user perform his changes and actually
* rebuild only once he is done.
*
* Note : As of Drupal 6, node access modules are not required to (and actually
* should not) call node_access_rebuild() in hook_enable/disable anymore.
*
* @see node_access_needs_rebuild
*
* @param $batch_mode
* Set to TRUE to process in 'batch' mode, spawning processing over several
* HTTP requests (thus avoiding the risk of PHP timeout if the site has a
* large number of nodes).
* hook_update_N and any form submit handler are safe contexts to use the
* 'batch mode'. Less decidable cases (such as calls from hook_user,
* hook_taxonomy, hook_node_type...) might consider using the non-batch mode.
2006-08-05 02:12:46 +00:00
*/
2007-09-02 14:42:30 +00:00
function node_access_rebuild($batch_mode = FALSE) {
2006-08-05 02:12:46 +00:00
db_query("DELETE FROM {node_access}");
2007-09-02 14:42:30 +00:00
// Only recalculate if the site is using a node_access module.
2006-08-05 02:12:46 +00:00
if (count(module_implements('node_grants'))) {
2007-09-02 14:42:30 +00:00
if ($batch_mode) {
$batch = array(
'title' => t('Rebuilding content access permissions'),
'operations' => array(
array('_node_access_rebuild_batch_operation', array()),
),
'finished' => '_node_access_rebuild_batch_finished'
);
batch_set($batch);
2006-08-05 02:12:46 +00:00
}
2007-09-02 14:42:30 +00:00
else {
// If not in 'safe mode', increase the maximum execution time.
if (!ini_get('safe_mode')) {
set_time_limit(240);
}
$result = db_query("SELECT nid FROM {node}");
while ($node = db_fetch_object($result)) {
$loaded_node = node_load($node->nid, NULL, TRUE);
// To preserve database integrity, only aquire grants if the node
// loads successfully.
if (!empty($loaded_node)) {
node_access_acquire_grants($loaded_node);
}
2007-07-26 07:49:40 +00:00
}
2006-08-05 02:12:46 +00:00
}
}
else {
2007-09-02 14:42:30 +00:00
// Not using any node_access modules. Add the default grant.
2006-08-05 02:12:46 +00:00
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
}
2007-09-02 14:42:30 +00:00
if (!isset($batch)) {
2007-11-12 19:06:33 +00:00
drupal_set_message(t('Content permissions have been rebuilt.'));
2007-09-02 14:42:30 +00:00
node_access_needs_rebuild(FALSE);
cache_clear_all();
}
}
/**
* Batch operation for node_access_rebuild_batch.
*
* This is a mutlistep operation : we go through all nodes by packs of 20.
* The batch processing engine interrupts processing and sends progress
* feedback after 1 second execution time.
*/
function _node_access_rebuild_batch_operation(&$context) {
if (empty($context['sandbox'])) {
// Initiate multistep processing.
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_node'] = 0;
$context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {node}'));
}
// Process the next 20 nodes.
$limit = 20;
$result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit);
while ($row = db_fetch_array($result)) {
$loaded_node = node_load($row['nid'], NULL, TRUE);
// To preserve database integrity, only aquire grants if the node
// loads successfully.
if (!empty($loaded_node)) {
node_access_acquire_grants($loaded_node);
}
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $loaded_node->nid;
}
// Multistep processing : report progress.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}
/**
* Post-processing for node_access_rebuild_batch.
*/
function _node_access_rebuild_batch_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(t('The content access permissions have been rebuilt.'));
node_access_needs_rebuild(FALSE);
}
else {
drupal_set_message(t('The content access permissions have not been properly rebuilt.'), 'error');
}
2006-11-10 09:03:21 +00:00
cache_clear_all();
2006-08-05 02:12:46 +00:00
}
2007-09-02 14:42:30 +00:00
2005-02-18 18:40:05 +00:00
/**
* @} End of "defgroup node_access".
*/
2005-08-25 21:14:17 +00:00
2006-08-06 23:00:42 +00:00
/**
* @defgroup node_content Hook implementations for user-created content types.
* @{
*/
/**
* Implementation of hook_access().
2007-10-11 16:37:43 +00:00
*
* Named so as not to conflict with node_access()
2006-08-06 23:00:42 +00:00
*/
2007-10-11 16:37:43 +00:00
function node_content_access($op, $node, $account) {
2006-08-06 23:00:42 +00:00
global $user;
$type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
if ($op == 'create') {
2007-10-11 16:37:43 +00:00
return user_access('create '. $type .' content', $account);
2006-08-06 23:00:42 +00:00
}
2007-06-26 22:27:25 +00:00
if ($op == 'update') {
2007-11-26 11:44:04 +00:00
if (user_access('edit any '. $type .' content', $account) || (user_access('edit own '. $type .' content', $account) && ($user->uid == $node->uid))) {
2006-08-06 23:00:42 +00:00
return TRUE;
}
}
2007-06-28 07:48:41 +00:00
2007-06-26 22:27:25 +00:00
if ($op == 'delete') {
2007-11-26 11:44:04 +00:00
if (user_access('delete any '. $type .' content') || (user_access('delete own '. $type .' content') && ($user->uid == $node->uid))) {
2007-06-26 22:27:25 +00:00
return TRUE;
}
}
2006-08-06 23:00:42 +00:00
}
/**
* Implementation of hook_form().
*/
2007-06-04 07:22:23 +00:00
function node_content_form($node, $form_state) {
2006-08-06 23:00:42 +00:00
$type = node_get_types('type', $node);
2006-11-12 19:56:07 +00:00
$form = array();
2006-08-06 23:00:42 +00:00
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
2007-07-03 19:42:14 +00:00
'#maxlength' => 255,
2006-08-06 23:00:42 +00:00
'#weight' => -5,
);
}
if ($type->has_body) {
2007-04-09 13:58:03 +00:00
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
2006-08-06 23:00:42 +00:00
}
return $form;
}
/**
* @} End of "defgroup node_content".
*/
2006-08-18 18:58:47 +00:00
/**
* Implementation of hook_forms(). All node forms share the same form handler
*/
function node_forms() {
2007-12-17 12:41:20 +00:00
$forms = array();
if ($types = node_get_types()) {
foreach (array_keys($types) as $type) {
$forms[$type .'_node_form']['callback'] = 'node_form';
}
2006-08-18 18:58:47 +00:00
}
return $forms;
}
2007-06-29 18:06:51 +00:00
2007-07-01 23:15:41 +00:00
/**
* Format the "Submitted by username on date/time" for each node
2007-12-06 09:58:34 +00:00
*
* @ingroup themeable
2007-07-01 23:15:41 +00:00
*/
function theme_node_submitted($node) {
return t('Submitted by !username on @datetime',
array(
'!username' => theme('username', $node),
'@datetime' => format_date($node->created),
));
}
2007-06-29 18:06:51 +00:00
/**
* Implementation of hook_hook_info().
*/
function node_hook_info() {
return array(
'node' => array(
'nodeapi' => array(
'presave' => array(
2007-09-11 14:50:05 +00:00
'runs when' => t('When either saving a new post or updating an existing post'),
2007-06-29 18:06:51 +00:00
),
'insert' => array(
2007-09-11 14:50:05 +00:00
'runs when' => t('After saving a new post'),
2007-06-29 18:06:51 +00:00
),
'update' => array(
2007-09-11 14:50:05 +00:00
'runs when' => t('After saving an updated post'),
2007-06-29 18:06:51 +00:00
),
'delete' => array(
2007-09-11 14:50:05 +00:00
'runs when' => t('After deleting a post')
2007-06-29 18:06:51 +00:00
),
'view' => array(
'runs when' => t('When content is viewed by an authenticated user')
),
),
),
);
}
/**
* Implementation of hook_action_info().
*/
function node_action_info() {
return array(
'node_publish_action' => array(
'type' => 'node',
'description' => t('Publish post'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_unpublish_action' => array(
'type' => 'node',
'description' => t('Unpublish post'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('delete', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_make_sticky_action' => array(
'type' => 'node',
'description' => t('Make post sticky'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_make_unsticky_action' => array(
'type' => 'node',
'description' => t('Make post unsticky'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('delete', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_promote_action' => array(
'type' => 'node',
'description' => t('Promote post to front page'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_unpromote_action' => array(
'type' => 'node',
'description' => t('Remove post from front page'),
'configurable' => FALSE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('delete', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_assign_owner_action' => array(
'type' => 'node',
'description' => t('Change the author of a post'),
'configurable' => TRUE,
2007-09-11 14:50:05 +00:00
'behavior' => array('changes_node_property'),
2007-06-29 18:06:51 +00:00
'hooks' => array(
'any' => TRUE,
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave'),
'comment' => array('delete', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_save_action' => array(
'type' => 'node',
'description' => t('Save post'),
'configurable' => FALSE,
'hooks' => array(
2007-09-11 14:50:05 +00:00
'comment' => array('delete', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
'node_unpublish_by_keyword_action' => array(
'type' => 'node',
'description' => t('Unpublish post containing keyword(s)'),
'configurable' => TRUE,
'hooks' => array(
2007-09-11 14:50:05 +00:00
'nodeapi' => array('presave', 'insert', 'update'),
2007-06-29 18:06:51 +00:00
),
),
);
}
/**
* Implementation of a Drupal action.
* Sets the status of a node to 1, meaning published.
*/
function node_publish_action(&$node, $context = array()) {
$node->status = 1;
watchdog('action', 'Set @type %title to published.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
* Sets the status of a node to 0, meaning unpublished.
*/
function node_unpublish_action(&$node, $context = array()) {
$node->status = 0;
watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
* Sets the sticky-at-top-of-list property of a node to 1.
*/
function node_make_sticky_action(&$node, $context = array()) {
$node->sticky = 1;
watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
2007-12-13 13:06:45 +00:00
* Sets the sticky-at-top-of-list property of a node to 0.
2007-06-29 18:06:51 +00:00
*/
function node_make_unsticky_action(&$node, $context = array()) {
$node->sticky = 0;
watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
* Sets the promote property of a node to 1.
*/
function node_promote_action(&$node, $context = array()) {
$node->promote = 1;
watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_get_types('type', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
* Sets the promote property of a node to 0.
*/
function node_unpromote_action(&$node, $context = array()) {
2007-12-13 13:06:45 +00:00
$node->promote = 0;
2007-06-29 18:06:51 +00:00
watchdog('action', 'Removed @type %title from front page.', array('@type' => node_get_types('type', $node), '%title' => $node->title));
}
/**
* Implementation of a Drupal action.
* Saves a node.
*/
function node_save_action($node) {
node_save($node);
watchdog('action', 'Saved @type %title', array('@type' => node_get_types('type', $node), '%title' => $node->title));
}
/**
* Implementation of a configurable Drupal action.
* Assigns ownership of a node to a user.
*/
function node_assign_owner_action(&$node, $context) {
$node->uid = $context['owner_uid'];
$owner_name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $context['owner_uid']));
watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_get_types('type', $node), '%title' => $node->title, '%name' => $owner_name));
}
function node_assign_owner_action_form($context) {
$description = t('The username of the user to which you would like to assign ownership.');
$count = db_result(db_query("SELECT COUNT(*) FROM {users}"));
$owner_name = '';
if (isset($context['owner_uid'])) {
$owner_name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $context['owner_uid']));
}
// Use dropdown for fewer than 200 users; textbox for more than that.
if (intval($count) < 200) {
$options = array();
$result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY name");
while ($data = db_fetch_object($result)) {
$options[$data->name] = $data->name;
}
$form['owner_name'] = array(
'#type' => 'select',
'#title' => t('Username'),
'#default_value' => $owner_name,
'#options' => $options,
'#description' => $description,
);
}
else {
$form['owner_name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => $owner_name,
'#autocomplete_path' => 'user/autocomplete',
'#size' => '6',
'#maxlength' => '7',
'#description' => $description,
);
}
return $form;
}
function node_assign_owner_action_validate($form, $form_state) {
$count = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE name = '%s'", $form_state['values']['owner_name']));
if (intval($count) != 1) {
form_set_error('owner_name', t('Please enter a valid username.'));
}
}
function node_assign_owner_action_submit($form, $form_state) {
// Username can change, so we need to store the ID, not the username.
$uid = db_result(db_query("SELECT uid from {users} WHERE name = '%s'", $form_state['values']['owner_name']));
return array('owner_uid' => $uid);
}
function node_unpublish_by_keyword_action_form($context) {
$form['keywords'] = array(
'#title' => t('Keywords'),
'#type' => 'textarea',
2007-11-12 19:06:33 +00:00
'#description' => t('The post will be unpublished if it contains any of the character sequences above. Use a comma-separated list of character sequences. Example: funny, bungee jumping, "Company, Inc.". Character sequences are case-sensitive.'),
2007-06-29 18:06:51 +00:00
'#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '',
);
return $form;
}
function node_unpublish_by_keyword_action_submit($form, $form_state) {
return array('keywords' => drupal_explode_tags($form_state['values']['keywords']));
}
/**
* Implementation of a configurable Drupal action.
* Unpublish a node if it contains a certain string.
*
* @param $context
* An array providing more information about the context of the call to this action.
* @param $comment
* A node object.
*/
function node_unpublish_by_keyword_action($node, $context) {
foreach ($context['keywords'] as $keyword) {
if (strstr(node_view(drupal_clone($node)), $keyword) || strstr($node->title, $keyword)) {
$node->status = 0;
watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
break;
}
}
2007-07-01 23:15:41 +00:00
}