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
* The core that allows content to be submitted to the site.
*/
2004-01-29 22:00:31 +00:00
define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60);
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_help().
*/
function node_help($section) {
2003-08-23 18:25:35 +00:00
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#node':
2005-11-01 10:17:34 +00:00
$output = '<p>'. t('All content in a website is stored and treated as <b>nodes</b>. Therefore nodes are any postings such as blogs, stories, polls and forums. The node module manages these content types and is one of the strengths of Drupal over other content management systems.') .'</p>';
$output .= '<p>'. t('Treating all content as nodes allows the flexibility of creating new types of content. It also allows you to painlessly apply new features or changes to all content. Comments are not stored as nodes but are always associated with a node.') .'</p>';
$output .= t('<p>Node module features</p>
<ul>
<li>The list tab provides an interface to search and sort all content on your site.</li>
<li>The configure settings tab has basic settings for content on your site.</li>
<li>The configure content types tab lists all content types for your site and lets you configure their default workflow.</li>
<li>The search tab lets you search all content on your site</li>
</ul>
');
$output .= t('<p>You can</p>
<ul>
2006-08-18 12:17:00 +00:00
<li>search for content at <a href="@search">search</a>.</li>
<li>administer nodes at <a href="@admin-settings-content-types">administer >> content management >> content types</a>.</li>
2005-11-01 10:17:34 +00:00
</ul>
2006-08-18 12:17:00 +00:00
', array('@search' => url('search'), '@admin-settings-content-types' => url('admin/content/types')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@node">Node page</a>.', array('@node' => 'http://drupal.org/handbook/modules/node/')) .'</p>';
2004-06-22 20:24:27 +00:00
return $output;
2006-07-31 11:25:55 +00:00
case 'admin/settings/modules#description':
2005-04-01 15:55:02 +00:00
return t('Allows content to be submitted to the site and displayed on pages.');
2006-07-31 11:25:55 +00:00
case 'admin/content/search':
2004-11-23 22:20:41 +00:00
return t('<p>Enter a simple pattern to search for a post. This can include the wildcard character *.<br />For example, a search for "br*" might return "bread bakers", "our daily bread" and "brenda".</p>');
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':
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.');
2001-06-06 20:26:12 +00:00
}
2004-11-27 10:02:06 +00:00
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'revisions') {
return t('The revisions let you track differences between multiple versions of a post.');
}
2005-01-26 22:59:41 +00:00
if (arg(0) == 'node' && arg(1) == 'add' && $type = arg(2)) {
2006-08-06 23:00:42 +00:00
$type = node_get_types('type', arg(2));
return filter_xss_admin($type->help);
2005-01-26 22:59:41 +00:00
}
2001-06-06 20:26:12 +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
2006-05-07 00:08: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
* An HTML list suitable as content for a block.
*/
2002-11-11 20:59:28 +00:00
function node_title_list($result, $title = NULL) {
while ($node = db_fetch_object($result)) {
2006-08-18 12:17:00 +00:00
$items[] = l($node->title, 'node/'. $node->nid, $node->comment_count ? array('title' => format_plural($node->comment_count, '1 comment', '@count comments')) : '');
2002-11-11 20:59:28 +00:00
}
2004-02-01 22:13:59 +00:00
return theme('node_list', $items, $title);
2003-04-29 20:48:50 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Format a listing of links to nodes.
*/
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])) {
$history[$nid] = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
}
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
}
2004-06-22 20:24:27 +00:00
/**
2005-06-01 03:32:22 +00:00
* Automatically generate a teaser for a node body in a given format.
2004-06-22 20:24:27 +00:00
*/
2005-06-01 03:32:22 +00:00
function node_teaser($body, $format = NULL) {
2001-12-08 11:12:26 +00:00
2004-02-01 22:13:59 +00:00
$size = variable_get('teaser_length', 600);
2002-12-10 20:35:20 +00:00
2004-08-04 21:19:12 +00:00
// find where the delimiter is in the body
$delimiter = strpos($body, '<!--break-->');
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
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);
2006-03-09 22:38:40 +00:00
if (isset($filters['filter/1']) && 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
}
2004-06-22 20:24:27 +00:00
// If a valid delimiter has been specified, use it to chop of the teaser.
2006-03-09 22:38:40 +00:00
if ($delimiter !== FALSE) {
2002-12-10 20:35:20 +00:00
return substr($body, 0, $delimiter);
}
2005-06-01 03:32:22 +00:00
// If we have a short body, the entire body is the teaser.
2003-07-21 15:36:05 +00:00
if (strlen($body) < $size) {
return $body;
}
2004-06-22 20:24:27 +00:00
// In some cases, no delimiter has been specified (e.g. when posting using
// the Blogger API). In this case, we try to split at paragraph boundaries.
2005-06-01 03:32:22 +00:00
// When even the first paragraph is too long, we try to split at the end of
2004-06-22 20:24:27 +00:00
// the next sentence.
2006-04-21 19:16:12 +00:00
$breakpoints = array('</p>' => 4, '<br />' => 0, '<br>' => 0, "\n" => 0, '. ' => 1, '! ' => 1, '? ' => 1, '。' => 3, '؟ ' => 1);
2005-06-01 03:32:22 +00:00
foreach ($breakpoints as $point => $charnum) {
if ($length = strpos($body, $point, $size)) {
return substr($body, 0, $length + $charnum);
}
2004-06-10 14:40:55 +00:00
}
2005-06-06 14:07:04 +00:00
2005-06-01 03:32:22 +00:00
// If all else fails, we simply truncate the string.
2004-04-15 14:07:08 +00:00
return truncate_utf8($body, $size);
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
* variable format.
*/
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':
return $_node_types[$type];
case 'module':
return $_node_types[$type]->module;
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':
2006-08-06 23:00:42 +00:00
return $_node_names[$type];
}
}
/**
* 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);
}
- 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;
$is_existing = db_num_rows(db_query("SELECT * FROM {node_type} WHERE type = '%s'", $existing_type));
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);
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);
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
- 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.
*
* @param $orig_type
* 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
/**
2006-08-06 23:00:42 +00:00
* Builds the list of available node types, by querying hook_node_info() in all
* modules, and by looking for node types in the database.
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)) {
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');
}
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-01-05 23:35:34 +00:00
$arguments = array();
2005-07-17 18:29:32 +00:00
if (is_numeric($param)) {
$cachable = $revision == NULL;
2005-10-22 15:14:46 +00:00
if ($cachable && isset($nodes[$param])) {
2005-07-17 18:29:32 +00:00
return $nodes[$param];
}
2006-01-05 23:35:34 +00:00
$cond = 'n.nid = %d';
$arguments[] = $param;
2004-11-17 22:14:43 +00:00
}
2005-07-17 18:29:32 +00:00
else {
// 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
}
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);
2006-07-26 07:04:19 +00:00
$node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data 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 {
2006-07-26 07:04:19 +00:00
$node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data 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
}
2005-08-30 15:22:29 +00:00
if ($node->nid) {
// 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;
}
}
2003-06-01 06:32:55 +00:00
}
2004-11-17 22:14:43 +00:00
if ($cachable) {
2005-07-17 18:29:32 +00:00
$nodes[$param] = $node;
2004-11-17 22:14:43 +00:00
}
2001-12-08 11:12:26 +00:00
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) {
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;
2001-12-08 11:12:26 +00:00
2004-02-01 22:13:59 +00:00
$node->nid = db_next_id('{node}_nid');
2005-08-30 15:22:29 +00:00
$node->vid = db_next_id('{node_revisions}_vid');;
}
else {
// We need to ensure that all node fields are filled.
$node_current = node_load($node->nid);
foreach ($node as $field => $data) {
$node_current->$field = $data;
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
$node = $node_current;
2001-12-08 11:12:26 +00:00
2005-08-30 15:22:29 +00:00
if ($node->revision) {
$node->old_vid = $node->vid;
$node->vid = db_next_id('{node_revisions}_vid');
}
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
2005-08-30 15:22:29 +00:00
// Split off revisions data to another structure
$revisions_table_values = array('nid' => $node->nid, 'vid' => $node->vid,
'title' => $node->title, 'body' => $node->body,
'teaser' => $node->teaser, 'log' => $node->log, 'timestamp' => $node->changed,
'uid' => $user->uid, 'format' => $node->format);
$revisions_table_types = array('nid' => '%d', 'vid' => '%d',
'title' => "'%s'", 'body' => "'%s'",
'teaser' => "'%s'", 'log' => "'%s'", 'timestamp' => '%d',
'uid' => '%d', 'format' => '%d');
$node_table_values = array('nid' => $node->nid, 'vid' => $node->vid,
'title' => $node->title, 'type' => $node->type, 'uid' => $node->uid,
'status' => $node->status, 'created' => $node->created,
'changed' => $node->changed, 'comment' => $node->comment,
2006-07-10 08:05:15 +00:00
'promote' => $node->promote, 'sticky' => $node->sticky);
2005-08-30 15:22:29 +00:00
$node_table_types = array('nid' => '%d', 'vid' => '%d',
'title' => "'%s'", 'type' => "'%s'", 'uid' => '%d',
'status' => '%d', 'created' => '%d',
'changed' => '%d', 'comment' => '%d',
2006-07-10 08:05:15 +00:00
'promote' => '%d', 'sticky' => '%d');
2005-08-30 15:22:29 +00:00
//Generate the node table query and the
//the node_revisions table query
if ($node->is_new) {
$node_query = 'INSERT INTO {node} ('. implode(', ', array_keys($node_table_types)) .') VALUES ('. implode(', ', $node_table_types) .')';
$revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')';
}
else {
$arr = array();
foreach ($node_table_types as $key => $value) {
$arr[] = $key .' = '. $value;
}
$node_table_values[] = $node->nid;
$node_query = 'UPDATE {node} SET '. implode(', ', $arr) .' WHERE nid = %d';
if ($node->revision) {
$revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')';
}
else {
$arr = array();
foreach ($revisions_table_types as $key => $value) {
$arr[] = $key .' = '. $value;
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
$revisions_table_values[] = $node->vid;
$revisions_query = 'UPDATE {node_revisions} SET '. implode(', ', $arr) .' WHERE vid = %d';
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
}
2004-08-16 17:51:12 +00:00
2005-08-30 15:22:29 +00:00
// Insert the node into the database:
db_query($node_query, $node_table_values);
db_query($revisions_query, $revisions_table_values);
2001-12-08 11:12:26 +00:00
2005-08-30 15:22:29 +00:00
// Call the node specific callback (if any):
if ($node->is_new) {
node_invoke($node, 'insert');
node_invoke_nodeapi($node, 'insert');
}
else {
2004-02-01 22:13:59 +00:00
node_invoke($node, 'update');
node_invoke_nodeapi($node, 'update');
2001-12-08 11:12:26 +00:00
}
2006-08-05 02:12:46 +00:00
// Update the node access table for this node.
node_access_acquire_grants($node);
2004-06-22 20:24:27 +00:00
// Clear the cache so an anonymous poster can see the node being added or updated.
2002-11-17 06:42:52 +00:00
cache_clear_all();
2001-12-08 11:12:26 +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
2005-08-07 14:55:17 +00:00
* Whether to display the teaser only, as on the main page.
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
2004-11-23 23:11:59 +00:00
if ($links) {
$node->links = module_invoke_all('link', 'node', $node, !$page);
2006-05-18 14:58:57 +00:00
foreach (module_implements('link_alter') AS $module) {
$function = $module .'_link_alter';
$function($node, $node->links);
}
2004-11-23 23:11:59 +00:00
}
2006-08-10 15:42:33 +00:00
$node = node_build_content($node, $teaser, $page);
// 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
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-08-10 15:42:33 +00:00
$node->content['body'] = array(
'#value' => check_markup($teaser ? $node->teaser : $node->body, $node->format, FALSE),
'#weight' => 0,
);
if ($node->log != '' && !$teaser) {
$node->content['log_message'] = array(
'#value' => theme('node_log_message', filter_xss($node->log)),
'#weight' => 20,
);
}
if (strlen($node->teaser) < strlen($node->body)) {
$node->readmore = TRUE;
}
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) {
// Remove the delimiter (if any) that separates the teaser from the body.
// TODO: this strips legitimate uses of '<!--break-->' also.
$node->body = str_replace('<!--break-->', '', $node->body);
// 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);
// Allow modules to modify the fully-built node.
node_invoke_nodeapi($node, 'alter', $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.
*/
2003-05-31 12:34:11 +00:00
function node_show($node, $cid) {
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
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_perm().
*/
2001-06-20 20:00:40 +00:00
function node_perm() {
2006-08-06 23:00:42 +00:00
$perms = array('administer content types', 'administer nodes', 'access content', 'view revisions', 'revert revisions');
foreach (node_get_types() as $type) {
if ($type->module == 'node') {
$name = check_plain($type->name);
$perms[] = 'create '. $name .' content';
$perms[] = 'edit own '. $name .' content';
$perms[] = 'edit '. $name .' content';
}
}
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':
return t('content');
2005-10-18 14:41:27 +00:00
2004-11-03 16:46:58 +00:00
case 'reset':
variable_del('node_cron_last');
2006-01-18 21:31:40 +00:00
variable_del('node_cron_last_nid');
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':
$last = variable_get('node_cron_last', 0);
2006-01-18 21:31:40 +00:00
$last_nid = variable_get('node_cron_last_nid', 0);
2006-02-01 14:11:53 +00:00
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1'));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.created, n.changed, c.last_comment_timestamp) = %d AND n.nid > %d ) OR (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d))', $last, $last_nid, $last, $last, $last));
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.
$form['content_ranking'] = array('#type' => 'fieldset', '#title' => t('Content ranking'));
$form['content_ranking']['#theme'] = 'node_search_admin';
2006-05-07 00:08:36 +00:00
$form['content_ranking']['info'] = array('#type' => 'markup', '#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) {
$form['content_ranking']['factors'][$var] = array('#title' => $title, '#type' => 'select', '#options' => $options, '#default_value' => variable_get($var, 5));
}
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) .')';
$join1 .= ' INNER JOIN {term_node} tn ON n.nid = tn.nid';
$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;
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;
}
if ($weight = (int)variable_get('node_rank_recent', 5)) {
// Exponential decay with half-life of 6 months, starting at last indexed node
$ranking[] = '%d * POW(2, (GREATEST(n.created, n.changed, c.last_comment_timestamp) - %d) * 6.43e-8)';
$arguments2[] = $weight;
$arguments2[] = (int)variable_get('node_cron_last', 0);
$join2 .= ' INNER JOIN {node} n ON n.nid = i.sid LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
2006-07-05 11:45:51 +00:00
$stats_join = TRUE;
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);
$ranking[] = '%d * (2.0 - 2.0 / (1.0 + c.comment_count * %f))';
$arguments2[] = $weight;
$arguments2[] = $scale;
if (!$stats_join) {
$join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
}
}
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);
$ranking[] = '%d * (2.0 - 2.0 / (1.0 + nc.totalcount * %f))';
$arguments2[] = $weight;
$arguments2[] = $scale;
2006-04-21 10:26:53 +00:00
$join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
2005-10-18 14:41:27 +00:00
}
$select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') . ' AS score';
// 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);
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');
2006-02-28 13:32:33 +00:00
$results[] = array('link' => url('node/'. $item->sid),
2006-08-06 23:00:42 +00:00
'type' => 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,
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);
}
}
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-18 15:04:37 +00:00
/**
2004-06-22 20:24:27 +00:00
* Menu callback; presents general node configuration options.
2004-06-18 15:04:37 +00:00
*/
function node_configure() {
2005-10-07 06:11:12 +00:00
$form['default_nodes_main'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'select', '#title' => t('Number of posts on main page'), '#default_value' => variable_get('default_nodes_main', 10),
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
'#description' => t('The default maximum number of posts to display per page on overview pages such as the main page.')
2005-10-07 06:11:12 +00:00
);
$form['teaser_length'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'select', '#title' => t('Length of trimmed posts'), '#default_value' => variable_get('teaser_length', 600),
'#options' => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
2005-10-07 06:11:12 +00:00
800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
2006-05-07 00:08:36 +00:00
'#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
2005-10-07 06:11:12 +00:00
);
$form['node_preview'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'radios', '#title' => t('Preview post'), '#default_value' => variable_get('node_preview', 0),
'#options' => array(t('Optional'), t('Required')), '#description' => t('Must users preview posts before submitting?')
2005-10-07 06:11:12 +00:00
);
2003-07-16 20:14:26 +00:00
2006-08-18 18:58:47 +00:00
return system_settings_form($form);
2001-06-17 20:35:48 +00:00
}
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') {
2004-07-02 18:46:42 +00:00
if (array_key_exists('links', $node)) {
2001-08-02 15:54:09 +00:00
$links = $node->links;
}
2001-11-01 11:00:51 +00:00
2006-07-19 07:15:35 +00:00
if ($teaser == 1 && $node->teaser && $node->readmore) {
2006-05-18 14:58:57 +00:00
$links['node_read_more'] = array(
2006-07-04 08:59:05 +00:00
'title' => t('read more'),
'href' => "node/$node->nid",
'attributes' => array('title' => t('Read the rest of this posting.'))
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
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2004-09-16 07:17:56 +00:00
function node_menu($may_cache) {
2004-06-18 15:04:37 +00:00
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
2006-07-31 11:25:55 +00:00
$items[] = array('path' => 'admin/content',
'title' => t('content management'),
'description' => t('Manage your site\'s content.'),
'position' => 'left',
'weight' => -10,
'callback' => 'system_admin_menu_block_page',
'access' => user_access('access configuration pages'),
);
$items[] = array(
'path' => 'admin/content/node',
'title' => t('posts'),
'description' => t('View, edit, and delete your site\'s content.'),
2006-08-18 18:58:47 +00:00
'callback' => 'node_admin_content',
2006-07-31 11:25:55 +00:00
'access' => user_access('administer nodes')
);
$items[] = array('path' => 'admin/content/node/overview', 'title' => t('list'),
2004-09-16 07:17:56 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
2005-11-24 22:03:40 +00:00
2006-08-20 05:57:41 +00:00
if (module_exists('search')) {
2006-07-31 11:25:55 +00:00
$items[] = array('path' => 'admin/content/search', 'title' => t('search posts'),
'description' => t('Search posts by keyword.'),
2005-11-24 22:03:40 +00:00
'callback' => 'node_admin_search',
'access' => user_access('administer nodes'),
2006-07-31 11:25:55 +00:00
'type' => MENU_NORMAL_ITEM);
2005-11-24 22:03:40 +00:00
}
2006-07-31 11:25:55 +00:00
$items[] = array(
'path' => 'admin/content/node-settings',
'title' => t('post settings'),
'description' => t('Control posting behavior, such as teaser length, requiring previews before posting, and the number of posts on the front page.'),
2006-08-18 18:58:47 +00:00
'callback' => 'drupal_get_form',
'callback arguments' => array('node_configure'),
2006-07-31 11:25:55 +00:00
'access' => user_access('administer nodes')
);
2006-08-06 23:00:42 +00:00
2006-07-31 11:25:55 +00:00
$items[] = array(
'path' => 'admin/content/types',
'title' => t('content types'),
'description' => t('Manage posts by content type, including default status, front page promotion, etc.'),
2006-08-06 23:00:42 +00:00
'callback' => 'node_overview_types',
'access' => user_access('administer nodes'),
);
$items[] = array(
'path' => 'admin/content/types/list',
'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/content/types/add',
'title' => t('add content type'),
2006-08-18 18:58:47 +00:00
'callback' => 'drupal_get_form',
'callback arguments' => array('node_type_form'),
2006-08-06 23:00:42 +00:00
'type' => MENU_LOCAL_TASK,
2006-07-31 11:25:55 +00:00
);
2006-08-19 21:40:58 +00:00
$items[] = array('path' => 'node',
'title' => t('content'),
2006-08-15 07:30:17 +00:00
'callback' => 'node_page_default',
2004-09-16 07:17:56 +00:00
'access' => user_access('access content'),
2006-05-07 01:00:15 +00:00
'type' => MENU_MODIFIABLE_BY_ADMIN);
2006-08-19 21:40:58 +00:00
$items[] = array('path' => 'node/add',
'title' => t('create content'),
2006-08-15 07:30:17 +00:00
'callback' => 'node_add',
2004-09-16 07:17:56 +00:00
'access' => user_access('access content'),
'type' => MENU_ITEM_GROUPING,
'weight' => 1);
2005-12-07 20:57:45 +00:00
$items[] = array('path' => 'rss.xml', 'title' => t('rss feed'),
'callback' => 'node_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
2006-08-06 23:00:42 +00:00
foreach (node_get_types() as $type) {
2006-08-15 05:09:49 +00:00
if (function_exists($type->module .'_form')) {
2006-08-06 23:00:42 +00:00
$name = check_plain($type->name);
$type_url_str = str_replace('_', '-', $type->type);
$items[] = array(
'path' => 'node/add/'. $type_url_str,
'title' => t($name),
'access' => node_access('create', $type->type),
);
}
}
2004-09-16 07:17:56 +00:00
}
else {
2006-08-14 07:14:50 +00:00
// Add the CSS for this module
// We put this in !$may_cache so it's only added once per request
drupal_add_css(drupal_get_path('module', 'node') .'/node.css');
2004-09-16 07:17:56 +00:00
if (arg(0) == 'node' && is_numeric(arg(1))) {
2005-07-17 18:29:32 +00:00
$node = node_load(arg(1));
2004-10-12 20:01:25 +00:00
if ($node->nid) {
$items[] = array('path' => 'node/'. arg(1), 'title' => t('view'),
2006-08-15 07:30:17 +00:00
'callback' => 'node_page_view',
'callback arguments' => array($node),
2004-10-12 20:01:25 +00:00
'access' => node_access('view', $node),
'type' => MENU_CALLBACK);
$items[] = array('path' => 'node/'. arg(1) .'/view', 'title' => t('view'),
2006-08-15 07:30:17 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10);
2004-10-12 20:01:25 +00:00
$items[] = array('path' => 'node/'. arg(1) .'/edit', 'title' => t('edit'),
2006-08-19 21:40:58 +00:00
'callback' => 'node_page_edit',
'callback arguments' => array($node),
2004-10-12 20:01:25 +00:00
'access' => node_access('update', $node),
'weight' => 1,
2004-09-16 07:17:56 +00:00
'type' => MENU_LOCAL_TASK);
2005-03-03 20:51:27 +00:00
$items[] = array('path' => 'node/'. arg(1) .'/delete', 'title' => t('delete'),
2006-08-18 18:58:47 +00:00
'callback' => 'drupal_get_form',
'callback arguments' => array('node_delete_confirm'),
2005-03-03 20:51:27 +00:00
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
2005-12-22 10:57:02 +00:00
$revisions_access = ((user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node) && db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', arg(1))) > 1);
$items[] = array('path' => 'node/'. arg(1) .'/revisions', 'title' => t('revisions'),
'callback' => 'node_revisions',
'access' => $revisions_access,
'weight' => 2,
'type' => MENU_LOCAL_TASK);
2004-09-16 07:17:56 +00:00
}
2004-07-04 19:24:52 +00:00
}
2006-08-06 23:00:42 +00:00
// Content type configuration.
if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types') {
include_once './'. drupal_get_path('module', 'node') .'/content_types.inc';
if (arg(3) != NULL) {
$type_name = arg(3);
$type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL;
$type = node_get_types('type', $type_name);
if (!empty($type)) {
$type->name = check_plain($type->name);
$type_url_str = str_replace('_', '-', $type->type);
$items[] = array(
'path' => 'admin/content/types/'. $type_url_str,
'title' => t($type->name),
2006-08-18 18:58:47 +00:00
'callback' => 'drupal_get_form',
'callback arguments' => array('node_type_form', $type),
2006-08-06 23:00:42 +00:00
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/content/types/'. $type_url_str .'/delete',
'title' => t('delete'),
2006-08-18 18:58:47 +00:00
'callback' => 'drupal_get_form',
'callback arguments' => array('node_type_delete', $type),
2006-08-06 23:00:42 +00:00
'type' => MENU_CALLBACK,
);
}
}
2005-01-24 21:20:16 +00:00
}
2006-08-05 02:12:46 +00:00
// There is no need to rebuild node_access if there is only 1 record in the table (the default configuration).
if (db_result(db_query('SELECT COUNT(*) FROM {node_access}')) > 1) {
$items[] = array('path' => 'admin/settings/node-access', 'title' => t('node access'),
2006-08-18 18:58:47 +00:00
'callback' => 'node_access_rebuild',
2006-08-05 02:12:46 +00:00
'access' => user_access('administer nodes'));
}
2004-06-18 15:04:37 +00:00
}
return $items;
}
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
/**
2006-07-31 19:12:44 +00:00
* Implementation of hook_node_operations().
2006-02-14 21:12:09 +00:00
*/
2006-07-31 19:12:44 +00:00
function node_node_operations() {
2003-08-02 06:49:32 +00:00
$operations = array(
2006-08-14 06:53:57 +00:00
'approve' => array(
'label' => t('Approve the selected posts'),
'callback' => 'node_operations_approve',
),
'promote' => array(
'label' => t('Promote the selected posts'),
'callback' => 'node_operations_promote',
),
'sticky' => array(
'label' => t('Make the selected posts sticky'),
'callback' => 'node_operations_sticky',
),
'demote' => array(
'label' => t('Demote the selected posts'),
'callback' => 'node_operations_demote',
),
'unpublish' => array(
'label' => t('Unpublish the selected posts'),
'callback' => 'node_operations_unpublish',
),
'delete' => array(
'label' => t('Delete the selected posts'),
),
2003-08-02 06:49:32 +00:00
);
2005-10-07 06:11:12 +00:00
return $operations;
}
2001-06-02 22:12:35 +00:00
2006-07-31 19:12:44 +00:00
/**
* Callback function for admin mass approving nodes.
*/
function node_operations_approve($nodes) {
db_query('UPDATE {node} SET status = 1 WHERE nid IN(%s)', implode(',', $nodes));
}
/**
* Callback function for admin mass promoting nodes.
*/
function node_operations_promote($nodes) {
db_query('UPDATE {node} SET status = 1, promote = 1 WHERE nid IN(%s)', implode(',', $nodes));
}
/**
* Callback function for admin mass editing nodes to be sticky.
*/
function node_operations_sticky($nodes) {
db_query('UPDATE {node} SET status = 1, sticky = 1 WHERE nid IN(%s)', implode(',', $nodes));
}
/**
* Callback function for admin mass demoting nodes.
*/
function node_operations_demote($nodes) {
db_query('UPDATE {node} SET promote = 0 WHERE nid IN(%s)', implode(',', $nodes));
}
/**
* Callback function for admin mass unpublishing nodes.
*/
function node_operations_unpublish($nodes) {
db_query('UPDATE {node} SET status = 0 WHERE nid IN(%s)', implode(',', $nodes));
}
2006-02-14 21:12:09 +00:00
/**
* List node administration filters that can be applied.
*/
2005-10-07 06:11:12 +00:00
function node_filters() {
2005-02-02 00:55:59 +00:00
// Regular filters
2006-02-14 21:12:09 +00:00
$filters['status'] = array('title' => t('status'),
'options' => array('status-1' => t('published'), 'status-0' => t('not published'),
'promote-1' => t('promoted'), 'promote-0' => t('not promoted'),
'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky')));
2006-08-06 23:00:42 +00:00
$filters['type'] = array('title' => t('type'), 'options' => node_get_types('names'));
2006-02-14 21:12:09 +00:00
// The taxonomy filter
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$filters['category'] = array('title' => t('category'), 'options' => $taxonomy);
2005-03-18 18:46:23 +00:00
}
2001-10-09 21:01:47 +00:00
2005-10-07 06:11:12 +00:00
return $filters;
}
2006-02-14 21:12:09 +00:00
/**
* Build query for node administration filters based on session.
*/
2005-10-07 06:11:12 +00:00
function node_build_filter_query() {
$filters = node_filters();
2005-02-02 00:55:59 +00:00
// Build query
$where = $args = array();
$join = '';
2006-02-14 21:12:09 +00:00
foreach ($_SESSION['node_overview_filter'] as $index => $filter) {
2005-02-02 00:55:59 +00:00
list($key, $value) = $filter;
2006-02-14 21:12:09 +00:00
switch($key) {
case 'status':
// Note: no exploitable hole as $key/$value have already been checked when submitted
list($key, $value) = explode('-', $value, 2);
$where[] = 'n.'. $key .' = %d';
break;
case 'category':
$table = "tn$index";
$where[] = "$table.tid = %d";
$join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid ";
break;
case 'type':
$where[] = "n.type = '%s'";
2005-02-02 00:55:59 +00:00
}
$args[] = $value;
}
$where = count($where) ? 'WHERE '. implode(' AND ', $where) : '';
2004-05-03 17:38:40 +00:00
2005-10-07 06:11:12 +00:00
return array('where' => $where, 'join' => $join, 'args' => $args);
}
2004-05-03 17:38:40 +00:00
2006-02-14 21:12:09 +00:00
/**
* Return form for node administration filters.
*/
2005-10-07 06:11:12 +00:00
function node_filter_form() {
$session = &$_SESSION['node_overview_filter'];
$session = is_array($session) ? $session : array();
$filters = node_filters();
$i = 0;
2006-02-14 21:12:09 +00:00
$form['filters'] = array('#type' => 'fieldset',
'#title' => t('Show only items where'),
'#theme' => 'node_filters',
);
2005-10-07 06:11:12 +00:00
foreach ($session as $filter) {
list($type, $value) = $filter;
2006-02-14 21:12:09 +00:00
if ($type == 'category') {
// Load term name from DB rather than search and parse options array.
$value = module_invoke('taxonomy', 'get_term', $value);
$value = $value->name;
}
else {
$value = $filters[$type]['options'][$value];
}
2005-10-07 06:11:12 +00:00
$string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');
2006-02-14 21:12:09 +00:00
$form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $value)));
2003-08-02 06:49:32 +00:00
}
2005-01-17 18:56:11 +00:00
2005-10-07 06:11:12 +00:00
foreach ($filters as $key => $filter) {
$names[$key] = $filter['title'];
2005-10-11 19:44:35 +00:00
$form['filters']['status'][$key] = array('#type' => 'select', '#options' => $filter['options']);
2005-10-07 06:11:12 +00:00
}
2005-10-11 19:44:35 +00:00
$form['filters']['filter'] = array('#type' => 'radios', '#options' => $names, '#default_value' => 'status');
$form['filters']['buttons']['submit'] = array('#type' => 'submit', '#value' => (count($session) ? t('Refine') : t('Filter')));
2005-10-07 06:11:12 +00:00
if (count($session)) {
2005-10-11 19:44:35 +00:00
$form['filters']['buttons']['undo'] = array('#type' => 'submit', '#value' => t('Undo'));
$form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
2005-10-07 06:11:12 +00:00
}
2003-08-02 06:49:32 +00:00
2006-08-18 18:58:47 +00:00
return $form;
2005-10-07 06:11:12 +00:00
}
2006-02-14 21:12:09 +00:00
/**
* Theme node administration filter form.
*/
2006-08-18 18:58:47 +00:00
function theme_node_filter_form($form) {
2005-10-07 06:11:12 +00:00
$output .= '<div id="node-admin-filter">';
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['filters']);
2005-02-02 00:55:59 +00:00
$output .= '</div>';
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form);
2005-10-07 06:11:12 +00:00
return $output;
}
2003-08-02 06:49:32 +00:00
2006-02-14 21:12:09 +00:00
/**
* Theme node administraton filter selector.
*/
2006-08-18 18:58:47 +00:00
function theme_node_filters($form) {
2005-10-07 06:11:12 +00:00
$output .= '<ul>';
if (sizeof($form['current'])) {
foreach (element_children($form['current']) as $key) {
2006-08-10 15:42:33 +00:00
$output .= '<li>' . drupal_render($form['current'][$key]) . '</li>';
2005-10-07 06:11:12 +00:00
}
}
2006-01-18 19:09:46 +00:00
$output .= '<li><dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>'. t('and') .'</em> '. t('where') .'</dt>' : '') . '<dd class="a">';
2006-02-14 21:12:09 +00:00
foreach (element_children($form['filter']) as $key) {
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['filter'][$key]);
2005-10-07 06:11:12 +00:00
}
$output .= '</dd>';
2006-01-18 19:09:46 +00:00
$output .= '<dt>'. t('is') .'</dt>' . '<dd class="b">';
2005-10-07 06:11:12 +00:00
2006-02-14 21:12:09 +00:00
foreach (element_children($form['status']) as $key) {
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['status'][$key]);
2005-10-07 06:11:12 +00:00
}
$output .= '</dd>';
$output .= '</dl>';
2006-08-10 15:42:33 +00:00
$output .= '<div class="container-inline" id="node-admin-buttons">'. drupal_render($form['buttons']) .'</div>';
2005-10-07 06:11:12 +00:00
$output .= '</li></ul><br class="clear" />';
return $output;
}
2006-02-14 21:12:09 +00:00
/**
* Process result from node administration filter form.
*/
2005-12-02 15:21:01 +00:00
function node_filter_form_submit() {
2005-10-07 06:11:12 +00:00
global $form_values;
$op = $_POST['op'];
$filters = node_filters();
switch ($op) {
2006-02-14 21:12:09 +00:00
case t('Filter'):
case t('Refine'):
2005-10-07 06:11:12 +00:00
if (isset($form_values['filter'])) {
$filter = $form_values['filter'];
2006-02-14 21:12:09 +00:00
2006-04-11 11:33:15 +00:00
// Flatten the options array to accommodate hierarchical/nested options.
2006-02-14 21:12:09 +00:00
$flat_options = form_options_flatten($filters[$filter]['options']);
if (isset($flat_options[$form_values[$filter]])) {
2005-10-07 06:11:12 +00:00
$_SESSION['node_overview_filter'][] = array($filter, $form_values[$filter]);
}
}
break;
case t('Undo'):
array_pop($_SESSION['node_overview_filter']);
break;
case t('Reset'):
$_SESSION['node_overview_filter'] = array();
break;
}
}
/**
2006-07-31 19:12:44 +00:00
* Submit the node administration update form.
2005-10-07 06:11:12 +00:00
*/
2005-12-02 15:21:01 +00:00
function node_admin_nodes_submit($form_id, $edit) {
2006-07-31 19:12:44 +00:00
$operations = module_invoke_all('node_operations');
$operation = $operations[$edit['operation']];
// Filter out unchecked nodes
2006-08-14 06:53:57 +00:00
$nodes = array_filter($edit['nodes']);
if ($function = $operation['callback']) {
// Add in callback arguments if present.
if (isset($operation['callback arguments'])) {
$args = array_merge(array($nodes), $operation['callback arguments']);
}
else {
$args = array($nodes);
}
call_user_func_array($function, $args);
2006-07-26 08:25:25 +00:00
cache_clear_all();
2005-10-07 06:11:12 +00:00
drupal_set_message(t('The update has been performed.'));
}
}
function node_admin_nodes_validate($form_id, $edit) {
2006-08-14 06:53:57 +00:00
$nodes = array_filter($edit['nodes']);
if (count($nodes) == 0) {
form_set_error('', t('No items selected.'));
2005-10-07 06:11:12 +00:00
}
}
2006-02-14 21:12:09 +00:00
/**
* Menu callback: content administration.
*/
2006-08-18 18:58:47 +00:00
function node_admin_content() {
$output = drupal_get_form('node_filter_form');
2005-10-07 06:11:12 +00:00
2006-02-09 07:46:04 +00:00
if ($_POST['edit']['operation'] == 'delete' && $_POST['edit']['nodes']) {
2005-11-24 22:03:40 +00:00
return node_multiple_delete_confirm();
}
2006-08-18 18:58:47 +00:00
// Call the form first, to allow for the form_values array to be populated.
$output .= drupal_get_form('node_admin_nodes');
return $output;
}
2005-11-24 22:03:40 +00:00
2006-08-18 18:58:47 +00:00
function node_admin_nodes() {
global $form_values;
2005-10-07 06:11:12 +00:00
$filter = node_build_filter_query();
$result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $filter['join'] .' INNER JOIN {users} u ON n.uid = u.uid '. $filter['where'] .' ORDER BY n.changed DESC', 50, 0, NULL, $filter['args']);
2006-02-14 21:12:09 +00:00
$form['options'] = array('#type' => 'fieldset',
'#title' => t('Update options'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
2005-10-07 06:11:12 +00:00
);
$options = array();
2006-08-14 06:53:57 +00:00
foreach (module_invoke_all('node_operations') as $operation => $array) {
$options[$operation] = $array['label'];
2005-10-07 06:11:12 +00:00
}
2005-10-11 19:44:35 +00:00
$form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'approve');
$form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
2002-12-29 12:03:08 +00:00
2005-02-10 19:30:08 +00:00
$destination = drupal_get_destination();
2001-11-01 11:00:51 +00:00
while ($node = db_fetch_object($result)) {
2005-10-07 06:11:12 +00:00
$nodes[$node->nid] = '';
2005-10-11 19:44:35 +00:00
$form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
2006-08-06 23:00:42 +00:00
$form['name'][$node->nid] = array('#value' => node_get_types('name', $node));
2005-10-11 19:44:35 +00:00
$form['username'][$node->nid] = array('#value' => theme('username', $node));
$form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published')));
$form['operations'][$node->nid] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
2001-10-09 21:01:47 +00:00
}
2005-10-11 19:44:35 +00:00
$form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
2005-10-26 08:06:56 +00:00
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
2006-08-18 18:58:47 +00:00
return $form;
2005-10-07 06:11:12 +00:00
}
2006-02-14 21:12:09 +00:00
/**
* Theme node administration overview.
*/
2005-10-07 06:11:12 +00:00
function theme_node_admin_nodes($form) {
// Overview table:
$header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['options']);
2005-12-14 20:10:45 +00:00
if (isset($form['title']) && is_array($form['title'])) {
2005-10-07 06:11:12 +00:00
foreach (element_children($form['title']) as $key) {
$row = array();
2006-08-10 15:42:33 +00:00
$row[] = drupal_render($form['nodes'][$key]);
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['name'][$key]);
$row[] = drupal_render($form['username'][$key]);
$row[] = drupal_render($form['status'][$key]);
$row[] = drupal_render($form['operations'][$key]);
2005-10-07 06:11:12 +00:00
$rows[] = $row;
}
}
else {
2005-02-14 21:28:08 +00:00
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
2002-12-29 12:20:08 +00:00
}
2001-10-09 21:01:47 +00:00
2004-02-01 22:13:59 +00:00
$output .= theme('table', $header, $rows);
2005-10-11 19:44:35 +00:00
if ($form['pager']['#value']) {
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['pager']);
2005-10-07 06:11:12 +00:00
}
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form);
2005-11-17 06:48:25 +00:00
2005-10-07 06:11:12 +00:00
return $output;
}
2005-11-24 22:03:40 +00:00
function node_multiple_delete_confirm() {
$edit = $_POST['edit'];
2005-11-04 19:40:28 +00:00
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
2006-07-05 11:45:51 +00:00
// array_filter returns only elements with TRUE values
2005-11-24 22:03:40 +00:00
foreach (array_filter($edit['nodes']) as $nid => $value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '<li>', '#suffix' => check_plain($title) ."</li>\n");
2005-10-07 06:11:12 +00:00
}
2005-10-11 19:44:35 +00:00
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
2005-10-07 06:11:12 +00:00
2006-08-18 18:58:47 +00:00
return confirm_form($form,
2005-10-07 06:11:12 +00:00
t('Are you sure you want to delete these items?'),
2006-07-31 11:25:55 +00:00
'admin/content/node', t('This action cannot be undone.'),
2005-10-07 06:11:12 +00:00
t('Delete all'), t('Cancel'));
}
2005-12-02 15:21:01 +00:00
function node_multiple_delete_confirm_submit($form_id, $edit) {
2005-10-07 06:11:12 +00:00
if ($edit['confirm']) {
foreach ($edit['nodes'] as $nid => $value) {
2005-11-04 19:40:28 +00:00
node_delete($nid);
2005-10-07 06:11:12 +00:00
}
drupal_set_message(t('The items have been deleted.'));
}
2006-07-31 11:25:55 +00:00
return 'admin/content/node';
2001-06-04 15:40:39 +00:00
}
2004-06-22 20:24:27 +00:00
/**
2004-09-09 05:51:08 +00:00
* Generate an overview table of older revisions of a node.
2004-06-22 20:24:27 +00:00
*/
2005-12-22 10:57:02 +00:00
function node_revision_overview($node) {
2006-08-18 12:17:00 +00:00
drupal_set_title(t('Revisions for %title', array('%title' => $node->title)));
2003-11-11 16:25:10 +00:00
2006-01-17 19:26:49 +00:00
$header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
2005-08-30 15:22:29 +00:00
2005-12-22 10:57:02 +00:00
$revisions = node_revision_list($node);
$rows = array();
2006-01-17 19:26:49 +00:00
$revert_permission = FALSE;
if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
$revert_permission = TRUE;
2005-12-22 10:57:02 +00:00
}
$delete_permission = FALSE;
if (user_access('administer nodes')) {
$delete_permission = TRUE;
}
foreach ($revisions as $revision) {
2006-01-17 19:26:49 +00:00
$row = array();
$operations = array();
2005-12-22 10:57:02 +00:00
if ($revision->current_vid > 0) {
2006-08-18 12:17:00 +00:00
$row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), '!username' => theme('username', $revision)))
2006-01-17 21:19:43 +00:00
. (($revision->log != '') ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : ''),
2006-01-17 19:26:49 +00:00
'class' => 'revision-current');
$operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
2005-12-22 10:57:02 +00:00
}
else {
2006-08-18 12:17:00 +00:00
$row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', $revision)))
2006-01-17 21:19:43 +00:00
. (($revision->log != '') ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : '');
2006-01-17 19:26:49 +00:00
if ($revert_permission) {
$operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
2003-11-11 16:25:10 +00:00
}
2005-12-22 10:57:02 +00:00
if ($delete_permission) {
2006-01-17 19:26:49 +00:00
$operations[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
2005-12-22 10:57:02 +00:00
}
2003-11-11 16:25:10 +00:00
}
2006-01-17 19:26:49 +00:00
$rows[] = array_merge($row, $operations);
2003-11-11 16:25:10 +00:00
}
2005-12-22 10:57:02 +00:00
$output .= theme('table', $header, $rows);
2003-11-11 16:25:10 +00:00
return $output;
}
2004-06-22 20:24:27 +00:00
/**
2006-02-06 05:54:17 +00:00
* Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered
* (via the node_save() call) when a revision is reverted.
2004-06-22 20:24:27 +00:00
*/
2006-01-17 19:26:49 +00:00
function node_revision_revert($nid, $revision) {
2001-11-05 22:59:11 +00:00
global $user;
2001-11-03 18:38:30 +00:00
2005-12-22 10:57:02 +00:00
$node = node_load($nid, $revision);
2006-01-17 19:26:49 +00:00
if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
2005-12-22 10:57:02 +00:00
if ($node->vid) {
$node->revision = 1;
2006-08-18 12:17:00 +00:00
$node->log = t('Copy of the revision from %date.', array('%date' => format_date($node->revision_timestamp)));
2006-08-20 19:03:59 +00:00
if (module_exists('taxonomy')) {
$node->taxonomy = array_keys($node->taxonomy);
}
2006-02-06 05:54:17 +00:00
node_save($node);
2001-11-03 18:38:30 +00:00
2006-08-18 12:17:00 +00:00
drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => format_date($node->revision_timestamp), '%title' => $node->title)));
watchdog('content', t('@type: reverted %title revision %revision.', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $revision)));
2005-08-30 15:22:29 +00:00
}
else {
2006-01-17 19:26:49 +00:00
drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
2003-11-11 16:25:10 +00:00
}
2004-07-04 19:24:52 +00:00
drupal_goto('node/'. $nid .'/revisions');
2003-11-11 16:25:10 +00:00
}
2005-12-22 10:57:02 +00:00
drupal_access_denied();
2001-11-03 18:38:30 +00:00
}
2004-06-22 20:24:27 +00:00
/**
2006-02-06 05:54:17 +00:00
* Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a
* revision is deleted.
2004-06-22 20:24:27 +00:00
*/
2003-11-11 16:25:10 +00:00
function node_revision_delete($nid, $revision) {
2004-02-01 22:13:59 +00:00
if (user_access('administer nodes')) {
2005-12-22 10:57:02 +00:00
$node = node_load($nid);
if (node_access('delete', $node)) {
// Don't delete the current revision
2005-12-24 13:05:22 +00:00
if ($revision != $node->vid) {
2005-12-22 10:57:02 +00:00
$node = node_load($nid, $revision);
2005-11-23 16:18:28 +00:00
2005-12-22 10:57:02 +00:00
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);
2005-12-24 13:05:22 +00:00
node_invoke_nodeapi($node, 'delete revision');
2006-08-18 12:17:00 +00:00
drupal_set_message(t('Deleted %title revision %revision.', array('%title' => $node->title, '%revision' => $revision)));
watchdog('content', t('@type: deleted %title revision %revision.', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $revision)));
2005-12-24 13:05:22 +00:00
}
2005-11-23 16:18:28 +00:00
2005-12-24 13:05:22 +00:00
else {
drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));
}
2006-03-26 01:03:29 +00:00
if (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $nid)) > 1) {
drupal_goto("node/$nid/revisions");
}
else {
drupal_goto("node/$nid");
}
2005-12-22 10:57:02 +00:00
}
2003-11-11 16:25:10 +00:00
}
2005-12-24 13:05:22 +00:00
2005-12-22 10:57:02 +00:00
drupal_access_denied();
2001-11-04 23:30:39 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Return a list of all the existing revision numbers.
*/
2001-11-05 22:59:11 +00:00
function node_revision_list($node) {
2005-08-30 15:22:29 +00:00
$revisions = array();
2006-01-17 19:26:49 +00:00
$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);
2005-08-30 15:22:29 +00:00
while ($revision = db_fetch_object($result)) {
$revisions[] = $revision;
2001-11-05 22:59:11 +00:00
}
2005-08-30 15:22:29 +00:00
return $revisions;
2001-11-03 18:38:30 +00:00
}
2005-11-24 22:03:40 +00:00
function node_admin_search() {
2006-08-18 18:58:47 +00:00
return drupal_get_form('search_form', url('admin/content/search'), $_POST['edit']['keys'], 'node') . search_data($_POST['edit']['keys'], 'node');
2001-04-02 15:54:37 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_block().
*/
2004-02-01 22:13:59 +00:00
function node_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Syndicate');
2002-10-26 15:17:26 +00:00
return $blocks;
}
2004-10-31 07:34:47 +00:00
else if ($op == 'view') {
2004-02-01 22:13:59 +00:00
$block['subject'] = t('Syndicate');
2005-12-29 04:46:40 +00:00
$block['content'] = theme('feed_icon', url('rss.xml'));
2001-07-15 16:56:44 +00:00
2002-10-26 15:17:26 +00:00
return $block;
}
2001-07-15 16:56:44 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* A generic function for generating RSS feeds from a set of nodes.
*
* @param $nodes
* An object as returned by db_query() which contains the nid field.
* @param $channel
* An associative array containing title, link, description and other keys.
* The link should be an absolute URL.
*/
2002-06-15 13:48:08 +00:00
function node_feed($nodes = 0, $channel = array()) {
2004-09-09 13:36:01 +00:00
global $base_url, $locale;
2003-03-07 06:37:30 +00:00
2002-06-15 13:48:08 +00:00
if (!$nodes) {
2006-06-16 20:16:27 +00:00
$nodes = 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));
2002-06-15 13:48:08 +00:00
}
2001-07-15 16:56:44 +00:00
2005-09-18 10:37:57 +00:00
$item_length = variable_get('feed_item_length', 'teaser');
$namespaces = array('xmlns:dc="http://purl.org/dc/elements/1.1/"');
2002-06-15 13:48:08 +00:00
while ($node = db_fetch_object($nodes)) {
2004-06-22 20:24:27 +00:00
// Load the specified node:
2005-07-17 18:29:32 +00:00
$item = node_load($node->nid);
2004-06-18 15:04:37 +00:00
$link = url("node/$node->nid", NULL, NULL, 1);
2004-09-28 19:13:03 +00:00
2005-09-18 10:37:57 +00:00
if ($item_length != 'title') {
$teaser = ($item_length == 'teaser') ? TRUE : FALSE;
// Filter and prepare node teaser
if (node_hook($item, 'view')) {
node_invoke($item, 'view', $teaser, FALSE);
}
else {
$item = node_prepare($item, $teaser);
}
// Allow modules to change $node->teaser before viewing.
node_invoke_nodeapi($item, 'view', $teaser, FALSE);
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');
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'FALSE'))));
foreach ($extra as $element) {
if ($element['namespace']) {
$namespaces = array_merge($namespaces, $element['namespace']);
}
}
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;
if ($item->readmore) {
$item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'</p>';
}
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',
2004-02-11 19:21:14 +00:00
'title' => variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', ''),
'link' => $base_url,
'description' => variable_get('site_mission', ''),
2004-09-09 13:36:01 +00:00
'language' => $locale
2004-02-11 19:21:14 +00:00
);
$channel = array_merge($channel_defaults, $channel);
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2005-09-18 10:37:57 +00:00
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\" ". implode(' ', $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
/**
2005-11-12 02:54:13 +00:00
* Prepare node for save and allow modules to make changes.
2004-06-22 20:24:27 +00:00
*/
2005-12-02 15:21:01 +00:00
function node_submit($node) {
2001-11-01 11:00:51 +00:00
global $user;
2004-06-22 20:24:27 +00:00
// Convert the node to an object, if necessary.
2005-12-31 10:48:56 +00:00
$node = (object)$node;
2001-11-01 11:00:51 +00:00
2004-09-06 13:26:00 +00:00
// 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)) {
2005-10-22 15:14:46 +00:00
$node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : '';
2004-09-06 13:26:00 +00:00
}
2003-03-07 22:11:44 +00:00
2006-04-20 16:38:22 +00:00
$access = user_access('administer nodes');
if ($access) {
2005-11-12 02:54:13 +00:00
// Populate the "authored by" field.
if ($account = user_load(array('name' => $node->name))) {
2001-11-01 22:54:16 +00:00
$node->uid = $account->uid;
2001-11-01 11:00:51 +00:00
}
else {
2005-11-12 02:54:13 +00:00
$node->uid = 0;
2001-11-01 11:00:51 +00:00
}
2006-04-08 13:13:17 +00:00
$node->created = $node->date ? strtotime($node->date) : NULL;
2001-11-01 11:00:51 +00:00
}
2006-04-20 16:38:22 +00:00
// Force defaults in case people modify the form:
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
2006-07-10 08:05:15 +00:00
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
2006-04-20 16:38:22 +00:00
if (!$access || !isset($node->$key)) {
2006-03-08 19:07:41 +00:00
$node->$key = in_array($key, $node_options);
}
2003-03-10 12:01:26 +00:00
}
2004-06-22 20:24:27 +00:00
// Do node-type-specific validation checks.
2005-12-10 08:12:59 +00:00
node_invoke($node, 'submit');
node_invoke_nodeapi($node, 'submit');
2004-07-04 16:50:02 +00:00
2004-07-08 15:24:30 +00:00
$node->validated = TRUE;
- Bugfix: just before submitting a node, one could change the content of
that node to something that would not have passed the preview pages.
Patch by Revar:
"If you uploaded a valid file, and filled out the form right, you will
get a Submit button. The problem comes in when you choose a different
file to upload, and then click Submit. The filestore_save() function
cannot do proper validation and handling of the form data, as it only
returns a list of what node fields to save. On error, a node entry is
still created, but with only the nid field set. The user can't be
forced to fix their bad entry."
"Add a _form_validate() node hook to process and validate any form
results. That way even on Submit, the node code would check the
validity of the data, and if bad, it could drop you back to the preview
screen with the current bad data warnings. Have it return an array of
errors that can be passed in as $error to the _form() hook. If it
returns a null array, then there's no errors, and the submit can go
through."
2002-05-26 09:23:46 +00:00
2001-11-01 22:54:16 +00:00
return $node;
2001-11-01 11:00:51 +00:00
}
2005-11-12 02:54:13 +00:00
/**
* Perform validation checks on the given node.
*/
2006-04-23 05:22:05 +00:00
function node_validate($node, $form = array()) {
2005-11-12 02:54:13 +00:00
// Convert the node to an object, if necessary.
2005-12-31 10:48:56 +00:00
$node = (object)$node;
2006-08-06 23:00:42 +00:00
$type = node_get_types('type', $node);
2005-11-12 02:54:13 +00:00
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
2006-08-06 23:00:42 +00:00
if (isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
2006-08-20 07:07:17 +00:00
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)));
2005-11-12 02:54:13 +00:00
}
2006-07-18 07:51:39 +00:00
if (isset($node->nid) && (node_last_changed($node->nid) > $_POST['edit']['changed'])) {
form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
2005-11-12 02:54:13 +00:00
}
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
2006-05-07 00:08:36 +00:00
// as the empty string denotes the anonymous user. In case we
2005-11-12 02:54:13 +00:00
// are dealing with an anonymous user we set the user ID to 0.
2006-08-18 12:17:00 +00:00
form_set_error('name', t('The username %name does not exist.', array('%name' => $node->name)));
2005-11-12 02:54:13 +00:00
}
2006-04-10 21:36:40 +00:00
// 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) {
2005-11-12 02:54:13 +00:00
form_set_error('date', t('You have to specify a valid date.'));
}
}
// Do node-type-specific validation checks.
2006-04-23 05:22:05 +00:00
node_invoke($node, 'validate', $form);
node_invoke_nodeapi($node, 'validate', $form);
2005-11-12 02:54:13 +00:00
}
2006-04-23 05:22:05 +00:00
function node_form_validate($form_id, $form_values, $form) {
node_validate($form_values, $form);
2005-10-26 01:24:09 +00:00
}
function node_object_prepare(&$node) {
if (user_access('administer nodes')) {
// Set up default values, if required.
if (!isset($node->created)) {
$node->created = time();
}
if (!isset($node->date)) {
$node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
}
}
node_invoke($node, 'prepare');
node_invoke_nodeapi($node, 'prepare');
}
2004-06-22 20:24:27 +00:00
/**
2006-08-18 18:58:47 +00:00
* Generate the node editing form array
2004-06-22 20:24:27 +00:00
*/
2005-10-07 06:11:12 +00:00
function node_form($node) {
2006-01-18 14:30:42 +00:00
$node = (object)$node;
2005-10-26 01:24:09 +00:00
node_object_prepare($node);
2001-11-01 11:00:51 +00:00
2005-10-07 06:11:12 +00:00
// Set the id of the top-level form tag
2006-02-19 21:47:50 +00:00
$form['#id'] = 'node-form';
2005-10-07 06:11:12 +00:00
/**
* Basic node information.
2005-10-08 12:21:47 +00:00
* These elements are just values so they are not even sent to the client.
2005-10-07 06:11:12 +00:00
*/
2006-07-18 07:51:39 +00:00
foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
2006-02-19 21:47:50 +00:00
$form[$key] = array('#type' => 'value', '#value' => $node->$key);
}
2005-10-07 06:11:12 +00:00
2006-07-18 07:51:39 +00:00
// Changed must be sent to the client, for later overwrite error checking.
$form['changed'] = array('#type' => 'hidden', '#value' => $node->changed);
2004-06-22 20:24:27 +00:00
// Get the node-specific bits.
2006-01-29 07:46:57 +00:00
$form = array_merge_recursive($form, node_invoke($node, 'form'));
2005-12-05 09:11:33 +00:00
if (!isset($form['title']['#weight'])) {
2005-12-15 16:24:40 +00:00
$form['title']['#weight'] = -5;
2005-12-05 09:11:33 +00:00
}
2003-06-05 18:09:39 +00:00
2005-11-29 03:18:57 +00:00
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
2006-02-19 21:47:50 +00:00
// If this is a new node, fill in the default values.
if (!isset($node->nid)) {
2006-07-10 08:05:15 +00:00
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
2006-02-19 21:47:50 +00:00
$node->$key = in_array($key, $node_options);
}
2006-03-26 16:56:08 +00:00
global $user;
2006-03-25 19:32:14 +00:00
$node->uid = $user->uid;
2005-11-29 03:18:57 +00:00
}
2006-03-08 19:07:41 +00:00
else {
// Nodes being edited should always be preset with the default revision setting.
$node->revision = in_array('revision', $node_options);
}
$form['#node'] = $node;
2001-11-01 11:00:51 +00:00
2006-08-22 11:13:04 +00:00
// Node author information for administrators
$form['author'] = array(
'#type' => 'fieldset',
'#access' => user_access('administer nodes'),
'#title' => t('Authoring information'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 20,
);
$form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name ? $node->name : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', 'Anonymous'))));
$form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => $node->date)));
2001-11-01 11:00:51 +00:00
2006-08-22 11:13:04 +00:00
if (isset($node->nid)) {
$form['author']['date']['#default_value'] = $node->date;
2005-11-29 03:18:57 +00:00
}
2006-08-22 11:13:04 +00:00
// Node options for administrators
$form['options'] = array(
'#type' => 'fieldset',
'#access' => user_access('administer nodes'),
'#title' => t('Publishing options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 25,
);
$form['options']['status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
$form['options']['promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
$form['options']['sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
$form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
// These values are used when the user has no administrator accesss.
foreach (array('uid', 'created') as $key) {
$form[$key] = array('#type' => 'value', '#value' => $node->$key);
2006-03-25 19:32:14 +00:00
}
2001-11-01 11:00:51 +00:00
2004-06-22 20:24:27 +00:00
// Add the buttons.
2005-12-15 16:24:40 +00:00
$form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 40);
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 45);
2005-10-07 06:11:12 +00:00
if ($node->nid && node_access('delete', $node)) {
2005-12-15 16:24:40 +00:00
$form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 50);
2001-11-01 11:00:51 +00:00
}
2006-04-20 07:11:37 +00:00
$form['#after_build'] = array('node_form_add_preview');
2006-08-18 18:58:47 +00:00
$form['#base'] = 'node_form';
2006-01-17 17:42:29 +00:00
return $form;
2005-10-07 06:11:12 +00:00
}
2001-11-01 11:00:51 +00:00
2006-04-30 00:43:53 +00:00
function node_form_add_preview($form) {
global $form_values;
2006-05-01 08:38:11 +00:00
2006-01-04 09:04:27 +00:00
$op = isset($_POST['op']) ? $_POST['op'] : '';
if ($op == t('Preview')) {
drupal_validate_form($form['form_id']['#value'], $form);
if (!form_get_errors()) {
2006-04-30 00:43:53 +00:00
// We pass the global $form_values here to preserve changes made during form validation
$form['node_preview'] = array('#value' => node_preview((object)$form_values), '#weight' => -100);
2006-01-04 09:04:27 +00:00
}
}
if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
unset($form['submit']);
}
2005-10-26 01:24:09 +00:00
return $form;
}
2005-10-07 06:11:12 +00:00
function theme_node_form($form) {
2006-05-14 12:56:44 +00:00
$output = "\n<div class=\"node-form\">\n";
2005-10-07 06:11:12 +00:00
if (isset($form['node_preview'])) {
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form['node_preview']);
2004-04-28 20:23:30 +00:00
}
2006-05-14 12:56:44 +00:00
// Admin form fields and submit buttons must be rendered first, because
// they need to go to the bottom of the form, and so should not be part of
2006-08-10 15:42:33 +00:00
// the catch-all call to drupal_render().
2006-05-14 12:56:44 +00:00
$admin = '';
if (isset($form['author'])) {
$admin .= " <div class=\"authored\">\n";
2006-08-10 15:42:33 +00:00
$admin .= drupal_render($form['author']);
2006-05-14 12:56:44 +00:00
$admin .= " </div>\n";
}
if (isset($form['options'])) {
$admin .= " <div class=\"options\">\n";
2006-08-10 15:42:33 +00:00
$admin .= drupal_render($form['options']);
2006-05-14 12:56:44 +00:00
$admin .= " </div>\n";
}
2006-08-10 15:42:33 +00:00
$buttons = drupal_render($form['preview']);
$buttons .= drupal_render($form['submit']);
$buttons .= isset($form['delete']) ? drupal_render($form['delete']) : '';
2006-05-14 12:56:44 +00:00
// Everything else gets rendered here, and is displayed before the admin form
// field and the submit buttons.
$output .= " <div class=\"standard\">\n";
2006-08-10 15:42:33 +00:00
$output .= drupal_render($form);
2006-05-14 12:56:44 +00:00
$output .= " </div>\n";
if (!empty($admin)) {
$output .= " <div class=\"admin\">\n";
$output .= $admin;
$output .= " </div>\n";
}
$output .= $buttons;
$output .= "</div>\n";
2005-10-07 06:11:12 +00:00
return $output;
2001-11-01 11:00:51 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Present a node submission form or a set of links to such forms.
*/
2006-08-15 07:30:17 +00:00
function node_add($type = NULL) {
2003-05-13 18:36:38 +00:00
global $user;
2006-08-06 23:00:42 +00:00
$types = node_get_types();
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
2004-06-22 20:24:27 +00:00
// If a node type has been specified, validate its existence.
2006-08-06 23:00:42 +00:00
if (isset($types[$type]) && node_access('create', $type)) {
2003-05-19 18:36:58 +00:00
// Initialize settings:
2004-02-01 22:13:59 +00:00
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
2003-05-19 18:36:58 +00:00
2006-08-18 18:58:47 +00:00
$output = drupal_get_form($type .'_node_form', $node);
2006-08-20 07:07:17 +00:00
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name)));
2001-11-01 11:00:51 +00:00
}
else {
2004-06-22 20:24:27 +00:00
// If no (valid) node type has been provided, display a node type overview.
2006-08-06 23:00:42 +00:00
foreach ($types as $type) {
2006-08-15 05:09:49 +00:00
if (function_exists($type->module .'_form') && node_access('create', $type->type)) {
2006-08-06 23:00:42 +00:00
$type_url_str = str_replace('_', '-', $type->type);
2006-08-20 07:07:17 +00:00
$title = t('Add a new @s.', array('@s' => $type->name));
2006-08-06 23:00:42 +00:00
$out = '<dt>'. l($type->name, "node/add/$type_url_str", array('title' => $title)) .'</dt>';
$out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
$item[$type->type] = $out;
2001-11-01 17:04:20 +00:00
}
2001-11-01 11:00:51 +00:00
}
2004-10-29 00:51:49 +00:00
if (isset($item)) {
2006-05-15 06:18:01 +00:00
uksort($item, 'strnatcasecmp');
2005-06-21 18:58:27 +00:00
$output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
2004-10-29 00:51:49 +00:00
}
else {
2006-08-06 23:00:42 +00:00
$output = t('No content types available.');
2004-10-29 00:51:49 +00:00
}
2001-11-01 11:00:51 +00:00
}
return $output;
}
2004-06-22 20:24:27 +00:00
/**
2005-10-07 06:11:12 +00:00
* Generate a node preview.
2004-06-22 20:24:27 +00:00
*/
2004-07-04 16:50:02 +00:00
function node_preview($node) {
2004-02-01 22:13:59 +00:00
if (node_access('create', $node) || node_access('update', $node)) {
2004-06-22 20:24:27 +00:00
// Load the user's name when needed:
2002-12-30 13:02:47 +00:00
if (isset($node->name)) {
2004-06-22 20:24:27 +00:00
// The use of isset() is mandatory in the context of user IDs, because
// user ID 0 denotes the anonymous user.
2004-02-01 22:13:59 +00:00
if ($user = user_load(array('name' => $node->name))) {
2002-12-30 13:02:47 +00:00
$node->uid = $user->uid;
}
else {
$node->uid = 0; // anonymous user
}
2001-11-20 22:51:06 +00:00
}
2002-12-30 13:02:47 +00:00
else if ($node->uid) {
2004-02-01 22:13:59 +00:00
$user = user_load(array('uid' => $node->uid));
2002-12-30 13:02:47 +00:00
$node->name = $user->name;
2001-11-20 22:51:06 +00:00
}
2001-11-01 11:00:51 +00:00
2006-04-12 17:06:57 +00:00
// Set the timestamps when needed:
if ($node->date) {
$node->created = strtotime($node->date);
2002-12-30 13:02:47 +00:00
}
2006-04-12 17:06:57 +00:00
$node->changed = time();
2001-11-01 11:00:51 +00:00
2004-10-04 20:34:23 +00:00
// Extract a teaser, if it hasn't been set (e.g. by a module-provided
// 'teaser' form item).
if (!isset($node->teaser)) {
2005-06-01 03:32:22 +00:00
$node->teaser = node_teaser($node->body, $node->format);
2004-10-04 20:34:23 +00:00
}
2002-12-10 20:35:20 +00:00
2004-06-22 20:24:27 +00:00
// Display a preview of the node:
2005-02-27 02:54:24 +00:00
// Previewing alters $node so it needs to be cloned.
2005-06-29 19:53:14 +00:00
if (!form_get_errors()) {
2005-10-28 00:28:14 +00:00
$cloned_node = drupal_clone($node);
$cloned_node->in_preview = TRUE;
$output = theme('node_preview', $cloned_node);
2005-06-29 19:53:14 +00:00
}
2005-10-07 06:11:12 +00:00
drupal_set_title(t('Preview'));
2006-08-18 12:17:00 +00:00
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit @name', array('@name' => node_get_types('name', $node))), 'node/add/'. $node->type)));
2003-12-22 11:55:49 +00:00
2003-11-25 19:26:21 +00:00
return $output;
2002-12-30 13:02:47 +00:00
}
2001-11-01 11:00:51 +00:00
}
2005-02-27 02:54:24 +00:00
/**
* Display a node preview for display during node creation and editing.
*
* @param $node
* The node object which is being previewed.
*/
function theme_node_preview($node) {
$output = '<div class="preview">';
if ($node->teaser && $node->teaser != $node->body) {
2005-07-31 10:28:50 +00:00
drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split.'));
2005-02-27 02:54:24 +00:00
$output .= '<h3>'. t('Preview trimmed version') .'</h3>';
2006-03-09 21:59:43 +00:00
$output .= node_view(drupal_clone($node), 1, FALSE, 0);
2005-02-27 02:54:24 +00:00
$output .= '<h3>'. t('Preview full version') .'</h3>';
$output .= node_view($node, 0, FALSE, 0);
}
else {
$output .= node_view($node, 0, FALSE, 0);
}
$output .= "</div>\n";
return $output;
}
2006-08-10 15:42:33 +00:00
function theme_node_log_message($log) {
return '<div class="log"><div class="title">'. t('Log') .':</div>'. $log .'</div>';
}
2005-12-02 15:21:01 +00:00
function node_form_submit($form_id, $edit) {
2003-02-15 11:39:56 +00:00
global $user;
2002-05-30 20:26:08 +00:00
2004-06-22 20:24:27 +00:00
// Fix up the node when required:
2005-12-02 15:21:01 +00:00
$node = node_submit($edit);
2001-11-25 12:18:51 +00:00
2004-06-22 20:24:27 +00:00
// Prepare the node's body:
2002-12-10 20:35:20 +00:00
if ($node->nid) {
2004-06-22 20:24:27 +00:00
// Check whether the current user has the proper access rights to
// perform this operation:
2004-02-01 22:13:59 +00:00
if (node_access('update', $node)) {
2005-09-02 02:11:41 +00:00
node_save($node);
2006-08-18 12:17:00 +00:00
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
2006-08-06 23:00:42 +00:00
drupal_set_message(t('The %post was updated.', array ('%post' => node_get_types('name', $node))));
2002-12-10 20:35:20 +00:00
}
}
else {
2004-06-22 20:24:27 +00:00
// Check whether the current user has the proper access rights to
// perform this operation:
2004-02-01 22:13:59 +00:00
if (node_access('create', $node)) {
2005-09-02 02:11:41 +00:00
node_save($node);
2006-08-18 12:17:00 +00:00
watchdog('content', t('@type: added %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
2006-08-06 23:00:42 +00:00
drupal_set_message(t('Your %post was created.', array ('%post' => node_get_types('name', $node))));
2001-12-06 17:33:05 +00:00
}
2002-12-10 20:35:20 +00:00
}
2006-02-26 19:44:45 +00:00
if ($node->nid) {
if (node_access('view', $node)) {
return 'node/'. $node->nid;
}
else {
return '';
}
2005-10-07 06:11:12 +00:00
}
2006-02-26 19:44:45 +00:00
// it is very unlikely we get here
return FALSE;
2001-11-01 11:00:51 +00:00
}
2004-06-22 20:24:27 +00:00
/**
2005-11-04 19:40:28 +00:00
* Menu callback -- ask for confirmation of node deletion
2004-06-22 20:24:27 +00:00
*/
2005-11-04 19:40:28 +00:00
function node_delete_confirm() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
2005-07-17 18:29:32 +00:00
$node = node_load($edit['nid']);
2001-11-01 17:04:20 +00:00
2004-02-01 22:13:59 +00:00
if (node_access('delete', $node)) {
2005-11-04 19:40:28 +00:00
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
2006-08-18 18:58:47 +00:00
$output = confirm_form($form,
2006-08-18 12:17:00 +00:00
t('Are you sure you want to delete %title?', array('%title' => $node->title)),
2005-10-07 06:11:12 +00:00
$_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid, t('This action cannot be undone.'),
t('Delete'), t('Cancel') );
}
return $output;
}
2001-11-03 18:38:30 +00:00
2005-11-04 19:40:28 +00:00
/**
* Execute node deletion
*/
2005-12-02 15:21:01 +00:00
function node_delete_confirm_submit($form_id, $form_values) {
2005-11-04 19:40:28 +00:00
if ($form_values['confirm']) {
node_delete($form_values['nid']);
}
2006-04-09 21:36:23 +00:00
return '';
2005-11-04 19:40:28 +00:00
}
2005-10-07 06:11:12 +00:00
2005-11-04 19:40:28 +00:00
/**
* Delete a node.
*/
function node_delete($nid) {
2005-10-07 06:11:12 +00:00
2005-11-04 19:40:28 +00:00
$node = node_load($nid);
2001-11-01 11:00:51 +00:00
2005-11-04 19:40:28 +00:00
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);
2001-11-03 18:38:30 +00:00
2005-11-04 19:40:28 +00:00
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
2003-03-16 21:47:15 +00:00
2005-11-04 19:40:28 +00:00
// Clear the cache so an anonymous poster can see the node being deleted.
cache_clear_all();
2004-11-04 06:47:03 +00:00
2005-11-04 19:40:28 +00:00
// Remove this node from the search index if needed.
if (function_exists('search_wipe')) {
search_wipe($node->nid, 'node');
2001-11-01 17:04:20 +00:00
}
2006-08-18 12:17:00 +00:00
drupal_set_message(t('%title has been deleted.', array('%title' => $node->title)));
watchdog('content', t('@type: deleted %title.', array('@type' => t($node->type), '%title' => $node->title)));
2001-11-01 11:00:51 +00:00
}
}
2005-12-22 10:57:02 +00:00
/**
* Menu callback for revisions related activities.
*/
function node_revisions() {
if (is_numeric(arg(1)) && arg(2) == 'revisions') {
$op = arg(4) ? arg(4) : 'overview';
switch ($op) {
case 'overview':
$node = node_load(arg(1));
if ((user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node)) {
return node_revision_overview($node);
}
2006-02-08 00:47:14 +00:00
drupal_access_denied();
return;
2005-12-22 10:57:02 +00:00
case 'view':
if (is_numeric(arg(3))) {
$node = node_load(arg(1), arg(3));
if ($node->nid) {
if ((user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node)) {
2006-08-18 12:17:00 +00:00
drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))));
2005-12-22 10:57:02 +00:00
return node_show($node, arg(2));
}
2006-02-08 00:47:14 +00:00
drupal_access_denied();
return;
2005-12-22 10:57:02 +00:00
}
}
break;
2006-01-17 19:26:49 +00:00
case 'revert':
node_revision_revert(arg(1), arg(3));
2005-12-22 10:57:02 +00:00
break;
case 'delete':
node_revision_delete(arg(1), arg(3));
break;
}
}
drupal_not_found();
}
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() {
2006-08-18 12:17:00 +00:00
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
2004-02-26 17:55:14 +00:00
if (db_num_rows($result)) {
2005-05-31 21:14:27 +00:00
drupal_add_link(array('rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => t('RSS'),
2005-12-07 20:57:45 +00:00
'href' => url('rss.xml', NULL, NULL, TRUE)));
2004-02-08 21:16:03 +00:00
$output = '';
while ($node = db_fetch_object($result)) {
2005-07-17 18:29:32 +00:00
$output .= node_view(node_load($node->nid), 1);
2004-02-08 21:16:03 +00:00
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
}
else {
2006-05-01 08:38:11 +00:00
$output = 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>
<ol>
<li>
<strong>Create your administrator account</strong>
2006-08-18 12:17:00 +00:00
To begin, <a href="@register">create the first account</a>. This account will have full administration rights and will allow you to configure your website.
2006-05-01 08:38:11 +00:00
</li>
<li>
<strong>Configure your website</strong>
2006-08-18 12:17:00 +00:00
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.
2006-05-01 08:38:11 +00:00
</li>
<li>
<strong>Enable additional functionality</strong>
2006-08-18 12:17:00 +00:00
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>.
2006-05-01 08:38:11 +00:00
</li>
<li>
<strong>Customize your website design</strong>
2006-08-18 12:17:00 +00:00
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>.
2006-05-01 08:38:11 +00:00
</li>
<li>
<strong>Start posting content</strong>
2006-08-18 12:17:00 +00:00
Finally, you can <a href="@content">create content</a> for your website. This message will disappear once you have published your first post.
2006-05-01 08:38:11 +00:00
</li>
</ol>
2006-08-18 12:17:00 +00:00
<p>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.</p>',
array('@drupal' => 'http://drupal.org/', '@register' => url('user/register'), '@admin' => url('admin'), '@config' => url('admin/settings'), '@modules' => url('admin/settings/modules'), '@download_modules' => 'http://drupal.org/project/modules', '@themes' => url('admin/build/themes'), '@download_themes' => 'http://drupal.org/project/themes', '@content' => url('node/add'), '@help' => url('admin/help'), '@handbook' => 'http://drupal.org/handbooks', '@forum' => 'http://drupal.org/forum', '@support' => 'http://drupal.org/support')
2006-05-01 08:38:11 +00:00
);
$output = '<div id="first-time">'. $output .'</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
2006-08-15 07:30:17 +00:00
/**
* Menu callback; presents the node editing form, or redirects to delete confirmation.
*/
function node_page_edit($node) {
if ($_POST['op'] == t('Delete')) {
// Note: we redirect from node/nid/edit to node/nid/delete to make the tabs disappear.
if ($_REQUEST['destination']) {
$destination = drupal_get_destination();
unset($_REQUEST['destination']);
}
drupal_goto('node/'. $node->nid .'/delete', $destination);
2004-06-18 15:04:37 +00:00
}
2006-08-15 07:30:17 +00:00
drupal_set_title(check_plain($node->title));
2006-08-18 18:58:47 +00:00
return drupal_get_form($node->type . '_node_form', $node);
2001-07-15 16:56:44 +00:00
}
2001-11-01 11:00:51 +00:00
2006-01-18 21:31:40 +00:00
/**
* shutdown function to make sure we always mark the last node processed.
*/
function node_update_shutdown() {
global $last_change, $last_nid;
if ($last_change && $last_nid) {
variable_set('node_cron_last', $last_change);
variable_set('node_cron_last_nid', $last_nid);
}
}
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() {
2006-01-18 21:31:40 +00:00
global $last_change, $last_nid;
register_shutdown_function('node_update_shutdown');
- 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
$last = variable_get('node_cron_last', 0);
2006-01-18 21:31:40 +00:00
$last_nid = variable_get('node_cron_last_nid', 0);
- 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}'))));
2006-04-10 21:36:40 +00:00
$result = db_query_range('SELECT GREATEST(c.last_comment_timestamp, n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 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)) {
2006-01-18 21:31:40 +00:00
$last_change = $node->last_change;
$last_nid = $node->nid;
2005-07-17 18:29:32 +00:00
$node = node_load($node->nid);
- 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
2006-08-10 15:42:33 +00:00
// Build the node body.
$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
2005-03-31 09:25:33 +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
2004-12-31 09:30:12 +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
}
// 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().
*/
2005-11-25 10:11:59 +00:00
function node_form_alter($form_id, &$form) {
2006-03-30 20:23:39 +00:00
// Advanced node search form
2006-08-06 23:00:42 +00:00
if ($form_id == 'search_form' && arg(1) == '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:
2006-08-20 19:02:26 +00:00
$types = 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'),
'#prefix' => '<div class="action">',
2006-04-21 10:26:53 +00:00
'#suffix' => '</div><br class="clear" />',
2006-03-30 20:23:39 +00:00
);
$form['#validate']['node_search_validate'] = array();
}
}
/**
* Form API callback for the search form. Registered in node_form_alter().
*/
2006-04-02 13:13:46 +00:00
function node_search_validate($form_id, $form_values, $form) {
2006-03-30 20:23:39 +00:00
// Initialise using any existing basic search keywords.
2006-04-15 21:52:44 +00:00
$keys = $form_values['processed_keys'];
2006-03-30 20:23:39 +00:00
// Insert extra restrictions into the search keywords string.
if (isset($form_values['type']) && is_array($form_values['type'])) {
// Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
$form_values['type'] = array_filter($form_values['type']);
if (count($form_values['type'])) {
$keys = search_query_insert($keys, 'type', implode(',', array_keys($form_values['type'])));
}
}
2006-04-15 21:52:44 +00:00
2006-03-30 20:23:39 +00:00
if (isset($form_values['category']) && is_array($form_values['category'])) {
$keys = search_query_insert($keys, 'category', implode(',', $form_values['category']));
}
if ($form_values['or'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $form_values['or'], $matches)) {
$keys .= ' '. implode(' OR ', $matches[1]);
}
}
if ($form_values['negative'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $form_values['negative'], $matches)) {
$keys .= ' -'. implode(' -', $matches[1]);
}
}
if ($form_values['phrase'] != '') {
$keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
}
if (!empty($keys)) {
2006-04-15 21:52:44 +00:00
form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
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.
2004-09-20 20:06:29 +00:00
* @param $uid
* The user ID on which the operation is to be performed.
2004-07-31 09:30:09 +00:00
* @return
* TRUE if the operation may be performed.
*/
2004-09-20 20:06:29 +00:00
function node_access($op, $node = NULL, $uid = NULL) {
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;
}
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;
}
2004-07-31 09:30:09 +00:00
if (user_access('administer nodes')) {
return TRUE;
}
2004-08-21 16:04:12 +00:00
if (!user_access('access content')) {
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.
}
$access = module_invoke($module, 'access', $op, $node);
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();
foreach (node_access_grants($op, $uid) as $realm => $gids) {
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));
}
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.
* @return
* An SQL where clause.
*/
2005-03-05 11:05:07 +00:00
function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid = 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();
2004-09-20 20:06:29 +00:00
foreach (node_access_grants($op, $uid) 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.
* @param $uid
* The user ID performing the operation. If omitted, the current user is used.
* @return
* An associative array in which the keys are realms, and the values are
* arrays of grants for those realms.
*/
function node_access_grants($op, $uid = NULL) {
global $user;
if (isset($uid)) {
$user_object = user_load(array('uid' => $uid));
}
else {
$user_object = $user;
}
return array_merge(array('all' => array(0)), module_invoke_all('node_grants', $user_object, $op));
}
/**
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);
if (!$grants) {
$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);
}
// only perform work when node_access modules are active
if (count(module_implements('node_grants'))) {
// This optimization reduces the number of db inserts a little bit. We could
// optimize further for mass updates if we wanted.
$values = array();
$query = '';
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']) {
$query .= ($query ? ', ' : '') . "(%d, '%s', %d, %d, %d, %d)";
$values[] = $node->nid;
$values[] = $grant['realm'];
$values[] = $grant['gid'];
$values[] = $grant['grant_view'];
$values[] = $grant['grant_update'];
$values[] = $grant['grant_delete'];
}
}
if ($values) {
$query = "INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES " . $query;
db_query($query, $values);
}
}
}
2006-08-18 18:58:47 +00:00
function node_access_rebuild() {
2006-08-05 02:12:46 +00:00
$form['markup'] = array(
'#prefix' => '<p>',
'#value' => t('Rebuilding the node_access table is necessary immediately after uninstalling a module that utilizes the node_access system. Each node will have its access control recalculated. This may take a while if your site has many nodes.'),
'#suffix' => '</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Rebuild node access'),
);
2006-08-18 18:58:47 +00:00
return $form;
2006-08-05 02:12:46 +00:00
}
/**
* rebuild the node access database
*/
function node_access_rebuild_submit() {
2006-08-18 18:58:47 +00:00
_node_access_rebuild();
2006-08-05 02:12:46 +00:00
drupal_set_message(t('The node access table has been rebuilt.'));
}
2006-08-18 18:58:47 +00:00
function _node_access_rebuild() {
2006-08-05 02:12:46 +00:00
db_query("DELETE FROM {node_access}");
// only recalculate if site is using a node_access module
if (count(module_implements('node_grants'))) {
// 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)) {
node_access_acquire_grants(node_load($node->nid));
}
}
else {
// not using any node_access modules. add the default grant.
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
}
}
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().
*/
function node_content_access($op, $node) {
global $user;
$type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
if ($op == 'create') {
return user_access('create '. $type .' content');
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit '. $type .' content') || (user_access('edit own '. $type .' content') && ($user->uid == $node->uid))) {
return TRUE;
}
}
}
/**
* Implementation of hook_form().
*/
function node_content_form($node) {
$type = node_get_types('type', $node);
if ($type->has_title) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
}
if ($type->has_body) {
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => TRUE);
$form['body_filter']['format'] = filter_form($node->format);
}
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() {
foreach (array_keys(node_get_types()) as $type) {
$forms[$type .'_node_form']['callback'] = 'node_form';
}
return $forms;
}