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>
<li>search for content at <a href="%search">search</a>.</li>
2006-01-29 07:50:45 +00:00
<li>administer nodes at <a href="%admin-settings-content-types">administer >> settings >> content types</a>.</li>
2005-11-01 10:17:34 +00:00
</ul>
2006-01-29 07:50:45 +00:00
', array('%search' => url('search'), '%admin-settings-content-types' => url('admin/settings/content-types')));
2005-11-01 10:17:34 +00:00
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%node">Node page</a>.', array('%node' => 'http://www.drupal.org/handbook/modules/node/')) .'</p>';
2004-06-22 20:24:27 +00:00
return $output;
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2005-04-01 15:55:02 +00:00
return t('Allows content to be submitted to the site and displayed on pages.');
2004-06-20 19:49:14 +00:00
case 'admin/node/configure':
case 'admin/node/configure/settings':
2004-11-23 22:20:41 +00:00
return t('<p>Settings for the core of Drupal. Almost everything is a node so these settings will affect most of the site.</p>');
2003-08-23 18:25:35 +00:00
case 'admin/node':
2005-02-02 00:55:59 +00:00
return t('<p>Below is a list of all of the posts on your site. Other forms of content are listed elsewhere (e.g. <a href="%comments">comments</a>).</p><p>Clicking a title views the post, while clicking an author\'s name views their user information.</p>', array('%comments' => url('admin/comment')));
2003-08-23 18:25:35 +00:00
case 'admin/node/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>');
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)) {
return variable_get($type .'_help', '');
}
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
2004-11-15 09:55:28 +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)) {
2004-11-04 21:02:30 +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.
2004-08-04 21:19:12 +00:00
if ($size == 0 && $delimiter == 0) {
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);
2005-06-01 03:42:47 +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.
2003-05-24 16:26:13 +00:00
if ($delimiter > 0) {
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.
2005-06-06 14:07:04 +00:00
$breakpoints = array('</p>' => 4, '<br />' => 0, '<br>' => 0, "\n" => 0, '. ' => 1, '! ' => 1, '? ' => 1, '。' => 1, '؟ ' => 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
}
- 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
function _node_names($op = '', $node = NULL) {
2005-12-14 13:26:39 +00:00
static $node_names = array();
static $node_list = 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
2005-12-14 13:26:39 +00:00
if (empty($node_names)) {
2005-08-29 19:58:49 +00:00
$node_names = module_invoke_all('node_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
foreach ($node_names as $type => $value) {
$node_list[$type] = $value['name'];
}
}
if ($node) {
if (is_array($node)) {
$type = $node['type'];
}
elseif (is_object($node)) {
$type = $node->type;
}
elseif (is_string($node)) {
$type = $node;
}
if (!isset($node_names[$type])) {
return FALSE;
}
}
switch ($op) {
case 'base':
return $node_names[$type]['base'];
case 'list':
return $node_list;
case 'name':
return $node_list[$type];
}
}
2004-02-08 20:36:13 +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
* Determine the basename for hook_load etc.
2004-01-23 18:42: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
* @param $node
2004-06-22 20:24:27 +00:00
* Either a node object, a node array, or a string containing the node type.
2004-01-23 18:42:43 +00:00
* @return
- 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
* The basename for hook_load, hook_nodeapi etc.
2004-01-23 18:42: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
function node_get_base($node) {
return _node_names('base', $node);
}
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
/**
* Determine the human readable name for a given type.
*
* @param $node
* Either a node object, a node array, or a string containing the node type.
* @return
* The human readable name of the node type.
*/
function node_get_name($node) {
return _node_names('name', $node);
2004-01-27 18:47:07 +00:00
}
2004-01-23 18:42:43 +00:00
2004-02-08 20:36:13 +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
* Return the list of available node types.
2004-01-23 18:42: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
* @param $node
* Either a node object, a node array, or a string containing the node type.
2004-01-23 18:42:43 +00:00
* @return
2005-10-11 19:44:35 +00:00
* An array consisting ('#type' => name) pairs.
2004-01-23 18:42: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
function node_get_types() {
return _node_names('list');
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) {
- 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 module_hook(node_get_base($node), $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)) {
$function = node_get_base($node) ."_$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.
2005-08-30 15:22:29 +00:00
if ($revision) {
2006-01-05 23:35:34 +00:00
array_unshift($arguments, $revision);
$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, 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-01-05 23:35:34 +00:00
$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, 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
2005-08-30 15:22:29 +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.
2005-08-30 15:22:29 +00:00
$node->is_new = true;
2001-12-08 11:12:26 +00:00
2001-12-08 13:11:33 +00:00
// Set some required fields:
2002-09-27 16:49:19 +00:00
if (!$node->created) {
$node->created = time();
}
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
}
2005-12-22 00:22:19 +00:00
// If node has never changed, set $node->changed to $node->created
// If we set $node->created to time(), then 'changed' and 'created' will be
// different for new nodes which were previewed before submission
2005-12-21 14:30:09 +00:00
// The changed timestamp is always updated for bookkeeping purposes (revisions, searching, ...)
2005-12-22 00:22:19 +00:00
$node->changed = $node->changed ? time() : $node->created;
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,
'promote' => $node->promote, 'moderate' => $node->moderate,
'sticky' => $node->sticky);
$node_table_types = array('nid' => '%d', 'vid' => '%d',
'title' => "'%s'", 'type' => "'%s'", 'uid' => '%d',
'status' => '%d', 'created' => '%d',
'changed' => '%d', 'comment' => '%d',
'promote' => '%d', 'moderate' => '%d',
'sticky' => '%d');
//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
}
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-10-19 18:02:31 +00:00
// Remove the delimiter (if any) that separates the teaser from the body.
2004-06-22 20:24:27 +00:00
// TODO: this strips legitimate uses of '<!--break-->' also.
2004-02-01 22:13:59 +00:00
$node->body = str_replace('<!--break-->', '', $node->body);
2002-12-10 20:35:20 +00:00
2005-08-30 15:22:29 +00:00
if ($node->log != '' && !$teaser && $node->moderate) {
2006-01-17 21:19:43 +00:00
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. filter_xss($node->log) .'</div>';
2005-08-30 15:22:29 +00:00
}
2004-06-22 20:24:27 +00:00
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
2004-02-01 22:13:59 +00:00
if (node_hook($node, 'view')) {
- 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
node_invoke($node, 'view', $teaser, $page);
2001-12-08 11:12:26 +00:00
}
else {
- 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
$node = node_prepare($node, $teaser);
2004-01-02 16:30:09 +00:00
}
- 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
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
2004-11-23 23:11:59 +00:00
if ($links) {
$node->links = module_invoke_all('link', 'node', $node, !$page);
}
2005-06-29 19:53:14 +00:00
// unset unused $node part so that a bad theme can not open a security hole
if ($teaser) {
unset($node->body);
}
else {
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
/**
* Apply filters to a node in preparation for theming.
*/
2004-06-18 15:04:37 +00:00
function node_prepare($node, $teaser = FALSE) {
2004-03-06 10:57:53 +00:00
$node->readmore = (strlen($node->teaser) < strlen($node->body));
2004-06-18 15:04:37 +00:00
if ($teaser == FALSE) {
2005-07-29 21:06:33 +00:00
$node->body = check_markup($node->body, $node->format, FALSE);
2004-01-02 16:30:09 +00:00
}
else {
2005-07-29 21:06:33 +00:00
$node->teaser = check_markup($node->teaser, $node->format, FALSE);
2001-12-08 11:12:26 +00:00
}
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-01-17 19:26:49 +00:00
return array('administer nodes', 'access content', 'view revisions', 'revert revisions');
2001-06-20 20:00:40 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_search().
*/
- 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
function node_search($op = 'search', $keys = null) {
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-01-14 09:51:57 +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'));
if (module_exist('comment')) {
$ranking['node_rank_comments'] = t('Number of comments');
}
if (module_exist('statistics') && variable_get('statistics_count_content_views', 0)) {
$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
$stats_join = false;
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';
$stats_join = true;
}
if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
// 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';
}
}
if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&
$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;
$join2 .= ' LEFT JOIN {node_counter} nc ON n.nid = nc.nid';
}
$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) {
2005-07-17 18:29:32 +00:00
$node = node_load($item);
2005-07-29 03:21:09 +00:00
// Get node output (filtered and with module-specific fields).
if (node_hook($node, 'view')) {
node_invoke($node, 'view', false, false);
}
else {
$node = node_prepare($node, false);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', false, false);
2005-10-18 14:41:27 +00:00
// Fetch comments for snippet
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
2004-12-31 09:30:12 +00:00
$extra = node_invoke_nodeapi($node, 'search result');
- 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('link' => url('node/'. $item),
- 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
'type' => node_get_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;
2005-10-18 14:41:27 +00:00
case 'form':
$form = array();
// Keyword boxes
2005-11-23 16:18:28 +00:00
$form['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced search'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#attributes' => array('class' => 'search-advanced'));
2005-10-18 14:41:27 +00:00
$form['advanced']['keywords'] = array('#type' => 'markup', '#prefix' => '<div class="criterium">', '#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')) {
$form['advanced']['category'] = array('#type' => 'select', '#title' => t('Only in the category'), '#prefix' => '<div class="criterium">', '#suffix' => '</div>', '#options' => $taxonomy, '#extra' => 'size="10"', '#multiple' => true);
}
// Node types
$types = node_get_types();
2005-12-26 11:21:19 +00:00
$form['advanced']['type'] = array('#type' => 'checkboxes', '#title' => t('Only of the type'), '#prefix' => '<div class="criterium">', '#suffix' => '</div>', '#options' => $types);
2005-10-18 14:41:27 +00:00
$form['advanced']['submit'] = array('#type' => 'submit', '#value' => t('Advanced Search'), '#prefix' => '<div class="action">', '#suffix' => '</div>');
return $form;
case 'post':
// Insert extra restrictions into the search keywords string.
$edit = &$_POST['edit'];
2005-12-14 20:10:45 +00:00
if (isset($edit['type']) && is_array($edit['type'])) {
2005-10-18 14:41:27 +00:00
$keys = search_query_insert($keys, 'type', implode(',', array_keys($edit['type'])));
}
2005-12-14 20:10:45 +00:00
if (isset($edit['category']) && is_array($edit['category'])) {
2005-10-18 14:41:27 +00:00
$keys = search_query_insert($keys, 'category', implode(',', $edit['category']));
}
if ($edit['or'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $edit['or'], $matches)) {
$keys = $keys .' '. implode(' OR ', $matches[1]);
}
}
if ($edit['negative'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' '. $edit['negative'], $matches)) {
$keys = $keys .' -'. implode(' -', $matches[1]);
}
}
if ($edit['phrase'] != '') {
$keys .= ' "'. str_replace('"', ' ', $edit['phrase']) .'"';
}
return trim($keys);
- 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
}
2001-11-01 11:00:51 +00:00
}
2005-10-18 14:41:27 +00:00
function theme_node_search_admin($form) {
$output = form_render($form['info']);
$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']);
$row[] = form_render($form['factors'][$key]);
$rows[] = $row;
}
$output .= theme('table', $header, $rows);
$output .= form_render($form);
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')),
2005-10-11 19:44:35 +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
2005-10-07 06:11:12 +00:00
return system_settings_form('node_configure', $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().
*/
2001-11-23 17:10:46 +00:00
function node_link($type, $node = 0, $main = 0) {
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
2004-03-06 10:57:53 +00:00
if ($main == 1 && $node->teaser && $node->readmore) {
2004-06-18 15:04:37 +00:00
$links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
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) {
$items[] = array('path' => 'admin/node', 'title' => t('content'),
2005-11-24 22:03:40 +00:00
'callback' => 'node_admin_nodes',
2004-09-16 07:17:56 +00:00
'access' => user_access('administer nodes'));
$items[] = array('path' => 'admin/node/overview', 'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
2005-11-24 22:03:40 +00:00
$items[] = array('path' => 'admin/node/action', 'title' => t('content'),
'callback' => 'node_admin_nodes',
'type' => MENU_CALLBACK);
if (module_exist('search')) {
$items[] = array('path' => 'admin/node/search', 'title' => t('search'),
'callback' => 'node_admin_search',
'access' => user_access('administer nodes'),
'type' => MENU_LOCAL_TASK);
}
2005-07-03 16:41:42 +00:00
$items[] = array('path' => 'admin/settings/node', 'title' => t('posts'),
2004-09-16 07:17:56 +00:00
'callback' => 'node_configure',
2005-07-03 16:41:42 +00:00
'access' => user_access('administer nodes'));
$items[] = array('path' => 'admin/settings/content-types', 'title' => t('content types'),
2005-03-01 20:07:48 +00:00
'callback' => 'node_types_configure',
2005-07-03 16:41:42 +00:00
'access' => user_access('administer nodes'));
2004-07-04 10:30:42 +00:00
2004-09-16 07:17:56 +00:00
$items[] = array('path' => 'node', 'title' => t('content'),
2004-06-18 15:04:37 +00:00
'callback' => 'node_page',
2004-09-16 07:17:56 +00:00
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'node/add', 'title' => t('create content'),
2004-06-18 15:04:37 +00:00
'callback' => 'node_page',
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);
2004-09-16 07:17:56 +00:00
}
else {
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'),
2004-09-16 07:17:56 +00:00
'callback' => 'node_page',
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'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'node/'. arg(1) .'/edit', 'title' => t('edit'),
'callback' => 'node_page',
'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'),
2005-11-04 19:40:28 +00:00
'callback' => '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
}
2005-08-25 21:22:00 +00:00
else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) {
$items[] = array('path' => 'admin/settings/content-types/'. arg(3),
- 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
'title' => t("'%name' content type", array('%name' => node_get_name(arg(3)))),
2005-01-24 21:20:16 +00:00
'type' => MENU_CALLBACK);
}
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);
}
2005-10-07 06:11:12 +00:00
/*
** Node operations
*/
function node_operations() {
2003-08-02 06:49:32 +00:00
$operations = array(
2005-02-02 00:55:59 +00:00
'approve' => array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'),
'promote' => array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d'),
'sticky' => array(t('Make the selected posts sticky'), 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d'),
'demote' => array(t('Demote the selected posts'), 'UPDATE {node} SET promote = 0 WHERE nid = %d'),
'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'),
'delete' => array(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
2005-10-07 06:11:12 +00:00
/*
** Filters
*/
function node_filters() {
2005-02-02 00:55:59 +00:00
// Regular filters
$filters = array(
2005-02-04 20:14:05 +00:00
'status' => array('title' => t('status'),
2005-02-02 00:55:59 +00:00
'options' => array('status-1' => t('published'), 'status-0' => t('not published'),
'moderate-1' => t('in moderation'), 'moderate-0' => t('not in moderation'),
'promote-1' => t('promoted'), 'promote-0' => t('not promoted'),
'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))),
2005-03-18 18:46:23 +00:00
'type' => array('title' => t('type'), 'where' => "n.type = '%s'",
- 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
'options' => node_get_types()));
2005-03-18 18:46:23 +00:00
// Merge all vocabularies into one for retrieving $value below
if ($taxonomy = module_invoke('taxonomy', 'form_all')) {
$terms = array();
2005-10-07 06:11:12 +00:00
foreach ($taxonomy as $value) {
2005-03-18 18:46:23 +00:00
$terms = $terms + $value;
}
$filters['category'] = array('title' => t('category'), 'where' => 'tn.tid = %d',
'options' => $terms, 'join' => 'INNER JOIN {term_node} tn ON n.nid = tn.nid');
}
if (isset($filters['category'])) {
$filters['category']['options'] = $taxonomy;
}
2001-10-09 21:01:47 +00:00
2005-10-07 06:11:12 +00:00
return $filters;
}
function node_build_filter_query() {
$filters = node_filters();
2005-02-02 00:55:59 +00:00
// Build query
$where = $args = array();
$join = '';
2005-10-07 06:11:12 +00:00
foreach ($_SESSION['node_overview_filter'] as $filter) {
2005-02-02 00:55:59 +00:00
list($key, $value) = $filter;
if ($key == 'status') {
// Note: no exploit hole as $value has already been checked
list($key, $value) = explode('-', $value, 2);
$where[] = 'n.'. $key .' = %d';
}
else {
$where[] = $filters[$key]['where'];
}
$args[] = $value;
$join .= $filters[$key]['join'];
}
$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
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;
2005-10-11 19:44:35 +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;
$string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');
2005-10-11 19:44:35 +00:00
$form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $filters[$type]['options'][$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
2005-10-07 06:11:12 +00:00
return drupal_get_form('node_filter_form', $form);
}
function theme_node_filter_form(&$form) {
$output .= '<div id="node-admin-filter">';
$output .= form_render($form['filters']);
2005-02-02 00:55:59 +00:00
$output .= '</div>';
2005-10-07 06:11:12 +00:00
$output .= form_render($form);
return $output;
}
2003-08-02 06:49:32 +00:00
2005-10-07 06:11:12 +00:00
function theme_node_filters(&$form) {
$output .= '<ul>';
if (sizeof($form['current'])) {
foreach (element_children($form['current']) as $key) {
$output .= '<li>' . form_render($form['current'][$key]) . '</li>';
}
}
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">';
2005-10-07 06:11:12 +00:00
foreach(element_children($form['filter']) as $key) {
$output .= form_render($form['filter'][$key]);
}
$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
foreach(element_children($form['status']) as $key) {
$output .= form_render($form['status'][$key]);
}
$output .= '</dd>';
$output .= '</dl>';
$output .= '<div class="container-inline" id="node-admin-buttons">'. form_render($form['buttons']) .'</div>';
$output .= '</li></ul><br class="clear" />';
return $output;
}
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) {
case t('Filter'): case t('Refine'):
if (isset($form_values['filter'])) {
$filter = $form_values['filter'];
if (isset($filters[$filter]['options'][$form_values[$filter]])) {
$_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;
case t('Update'):
return;
}
if ($op != '') {
drupal_goto('admin/node');
}
}
/**
* Generate the content administration overview.
*/
2005-12-02 15:21:01 +00:00
function node_admin_nodes_submit($form_id, $edit) {
2005-10-07 06:11:12 +00:00
$operations = node_operations();
if ($operations[$edit['operation']][1]) {
// Flag changes
$operation = $operations[$edit['operation']][1];
foreach ($edit['nodes'] as $nid => $value) {
if ($value) {
db_query($operation, $nid);
}
}
drupal_set_message(t('The update has been performed.'));
2005-11-04 19:40:28 +00:00
drupal_goto('admin/node');
2005-10-07 06:11:12 +00:00
}
}
function node_admin_nodes_validate($form_id, $edit) {
$edit['nodes'] = array_diff($edit['nodes'], array(0));
if (count($edit['nodes']) == 0) {
form_set_error('', t('Please select some items to perform the update on.'));
}
}
function node_admin_nodes() {
global $form_values;
$output = node_filter_form();
2005-11-24 22:03:40 +00:00
if ($_POST['edit']['operation'] == 'delete') {
return node_multiple_delete_confirm();
}
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']);
$form['options'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'fieldset', '#title' => t('Update options'),
'#prefix' => "<div class=\"container-inline\">" , '#suffix' => "</div>"
2005-10-07 06:11:12 +00:00
);
$options = array();
foreach (node_operations() as $key => $value) {
$options[$key] = $value[0];
}
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)));
$form['name'][$node->nid] = array('#value' => node_get_name($node));
$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));
2002-12-30 13:02:47 +00:00
2005-10-11 19:44:35 +00:00
$form['#method'] = 'post';
$form['#action'] = url('admin/node/action');
2005-10-07 06:11:12 +00:00
// Call the form first, to allow for the form_values array to be populated.
$output .= drupal_get_form('node_admin_nodes', $form);
return $output;
}
function theme_node_admin_nodes($form) {
// Overview table:
$header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
$output .= form_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();
$row[] = form_render($form['nodes'][$key]);
$row[] = form_render($form['title'][$key]);
$row[] = form_render($form['name'][$key]);
$row[] = form_render($form['username'][$key]);
$row[] = form_render($form['status'][$key]);
$row[] = form_render($form['operations'][$key]);
$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']) {
2005-10-07 06:11:12 +00:00
$output .= form_render($form['pager']);
}
2005-11-17 06:48:25 +00:00
$output .= form_render($form);
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);
2005-11-24 22:03:40 +00:00
// array filter returns only elements with true values
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
2005-11-24 22:03:40 +00:00
return confirm_form('node_multiple_delete_confirm', $form,
2005-10-07 06:11:12 +00:00
t('Are you sure you want to delete these items?'),
'admin/node', t('This action cannot be undone.'),
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.'));
}
drupal_goto('admin/node');
2001-06-04 15:40:39 +00:00
}
2005-03-01 20:07:48 +00:00
/**
* Menu callback; presents each node type configuration page.
*/
function node_types_configure($type = NULL) {
if (isset($type)) {
2005-03-07 21:58:13 +00:00
$node = new stdClass();
$node->type = $type;
2005-10-11 19:44:35 +00:00
$form['submission'] = array('#type' => 'fieldset', '#title' =>t('Submission form') );
2005-10-07 06:11:12 +00:00
$form['submission'][$type . '_help'] = array(
2005-11-12 11:26:16 +00:00
'#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => variable_get($type .'_help', ''),
2005-10-11 19:44:35 +00:00
'#description' => t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type)))
2005-10-07 06:11:12 +00:00
);
$form['submission']['minimum_'. $type .'_size'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'select', '#title' => t('Minimum number of words'), '#default_value' => variable_get('minimum_'. $type .'_size', 0), '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
'#description' => t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type)))
2005-10-07 06:11:12 +00:00
);
2005-10-11 19:44:35 +00:00
$form['workflow'] = array('#type' => 'fieldset', '#title' =>t('Workflow'));
2005-11-27 11:11:46 +00:00
$form['type'] = array('#type' => 'value', '#value' => $type);
2005-10-07 06:11:12 +00:00
2005-10-13 10:02:31 +00:00
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
2005-11-25 10:11:59 +00:00
return system_settings_form($type .'_node_settings', $form);
2003-03-08 14:35:42 +00:00
}
2005-03-01 20:07:48 +00:00
else {
$header = array(t('Type'), t('Operations'));
2005-01-26 22:59:41 +00:00
2005-03-01 20:07:48 +00:00
$rows = 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 (node_get_types() as $type => $name) {
$rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type));
2005-03-01 20:07:48 +00:00
}
2003-03-07 22:11:44 +00:00
2005-04-24 16:34:36 +00:00
return theme('table', $header, $rows);
2005-03-01 20:07:48 +00:00
}
2003-03-07 22:11:44 +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) {
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($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);
$i = 0;
$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-01-17 19:26:49 +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-01-17 19:26:49 +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;
$node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
2006-02-06 05:54:17 +00:00
node_save($node);
2001-11-03 18:38:30 +00:00
2006-01-17 19:26:49 +00:00
drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $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');
drupal_set_message(t('Deleted %title revision %revision.', array('%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
watchdog('content', t('%type: deleted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
}
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.'));
}
2001-11-04 23:30:39 +00:00
2005-12-24 13:05:22 +00:00
drupal_goto("node/$nid/revisions");
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() {
$output = search_form(url('admin/node/search'), $_POST['edit']['keys'], 'node') . search_data($_POST['edit']['keys'], 'node');
2005-04-24 16:34:36 +00:00
return $output;
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) {
2005-09-18 10:37:57 +00:00
$nodes = db_query_range(db_rewrite_sql('SELECT n.nid 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
}
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-02-01 14:09:31 +00:00
// Allow modules to add additional item fields
$extra = node_invoke_nodeapi($item, 'rss item');
2005-11-24 20:15:09 +00:00
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))));
2005-09-18 10:37:57 +00:00
foreach ($extra as $element) {
if ($element['namespace']) {
2005-12-15 15:57:55 +00:00
$namespaces = array_merge($namespaces, $element['namespace']);
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";
2004-02-01 22:13:59 +00:00
drupal_set_header('Content-Type: text/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
2004-02-01 22:13:59 +00:00
if (user_access('administer nodes')) {
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
}
2005-11-12 02:54:13 +00:00
$node->created = strtotime($node->date);
2001-11-01 11:00:51 +00:00
}
2003-03-07 22:11:44 +00:00
else {
// Validate for normal users:
$node->uid = $user->uid ? $user->uid : 0;
2003-03-10 12:01:26 +00:00
// Force defaults in case people modify the form:
2005-03-04 00:48:22 +00:00
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
2005-01-24 21:20:16 +00:00
$node->status = in_array('status', $node_options);
$node->moderate = in_array('moderate', $node_options);
$node->promote = in_array('promote', $node_options);
$node->sticky = in_array('sticky', $node_options);
$node->revision = in_array('revision', $node_options);
2003-03-10 12:01:26 +00:00
unset($node->created);
}
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.
*/
function node_validate($node) {
// Convert the node to an object, if necessary.
2005-12-31 10:48:56 +00:00
$node = (object)$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
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) {
form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_get_name($node))));
}
if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
form_set_error('changed', t('This content has been modified by another user, unable to save changes.'));
}
if (user_access('administer nodes')) {
// Validate the "authored by" field.
if (!empty($node->name) && !($account = user_load(array('name' => $node->name)))) {
// The use of empty() is mandatory in the context of usernames
// as the empty string denotes the anonymous user. In case we
// are dealing with an anonymous user we set the user ID to 0.
form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name))));
}
2005-12-15 16:02:50 +00:00
// Validate the "authored on" field. As of PHP 5.1.O, strtotime returns FALSE instead of -1 upon failure.
if (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.
node_invoke($node, 'validate');
node_invoke_nodeapi($node, 'validate');
}
2005-09-23 08:47:13 +00:00
/**
* Validate the title of a node
*/
function node_validate_title($node, $message = NULL) {
// Validate the title field.
2005-09-27 15:09:28 +00:00
if (isset($node->title)) {
if (trim($node->title) == '') {
form_set_error('title', isset($message) ? $message : t('You have to specify a title.'));
}
2005-09-23 08:47:13 +00:00
}
}
2005-10-26 01:24:09 +00:00
function node_form_validate($form_id, $edit) {
node_validate($edit);
}
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
/**
* Generate the node editing form.
*/
2005-10-07 06:11:12 +00:00
function node_form($node) {
2006-01-18 14:30:42 +00:00
$node = (object)$node;
2006-01-17 17:42:29 +00:00
$form = node_form_array($node);
2006-01-18 14:30:42 +00:00
return drupal_get_form($node->type .'_node_form', $form, 'node_form');
2006-01-17 17:42:29 +00:00
}
/**
* Generate the node editing form array.
*/
function node_form_array($node) {
2005-10-22 15:14:46 +00:00
$op = isset($_POST['op']) ? $_POST['op'] : '';
2005-10-07 06:11:12 +00:00
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
2005-10-11 19:44:35 +00:00
$form['#attributes']['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
*/
2005-10-11 19:44:35 +00:00
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
$form['vid'] = array('#type' => 'value', '#value' => $node->vid);
$form['uid'] = array('#type' => 'value', '#value' => $node->uid);
$form['created'] = array('#type' => 'value', '#value' => $node->created);
$form['changed'] = array('#type' => 'value', '#value' => $node->changed);
$form['type'] = array('#type' => 'value', '#value' => $node->type);
2005-12-05 09:11:33 +00:00
$form['#node'] = $node;
2005-10-07 06:11:12 +00:00
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
// If this is a new node, fill in the default values.
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
if (!isset($node->status)) {
$node->status = in_array('status', $node_options);
}
if (!isset($node->moderate)) {
$node->moderate = in_array('moderate', $node_options);
}
if (!isset($node->promote)) {
$node->promote = in_array('promote', $node_options);
}
if (!isset($node->sticky)) {
$node->sticky = in_array('sticky', $node_options);
}
if (!isset($node->revision)) {
$node->revision = in_array('revision', $node_options);
}
2001-11-01 11:00:51 +00:00
2005-10-11 19:44:35 +00:00
if (user_access('administer nodes')) {
2005-11-29 03:18:57 +00:00
// Node author information
2005-12-15 16:24:40 +00:00
$form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20);
2006-01-03 19:40:29 +00:00
$form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#required' => TRUE, '#default_value' => $node->name ? $node->name : variable_get('anonymous', 'Anonymous'), '#weight' => -1);
2005-10-11 19:44:35 +00:00
$form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#required' => TRUE, '#default_value' => $node->date);
2001-11-01 11:00:51 +00:00
2005-11-29 03:18:57 +00:00
// Node options for administrators
2005-12-15 16:24:40 +00:00
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25);
2005-11-29 03:18:57 +00:00
$form['options']['status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
$form['options']['moderate'] = array('#type' => 'checkbox', '#title' => t('In moderation queue'), '#default_value' => $node->moderate);
$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);
}
else {
// Don't show node options because the user doesn't have admin access.
$form['status'] = array('#type' => 'value', '#value' => $node->status);
$form['moderate'] = array('#type' => 'value', '#value' => $node->moderate);
$form['promote'] = array('#type' => 'value', '#value' => $node->promote);
$form['sticky'] = array('#type' => 'value', '#value' => $node->sticky);
$form['revision'] = array('#type' => 'value', '#value' => $node->revision);
2005-10-11 19:44:35 +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
}
2005-10-26 01:24:09 +00:00
2006-01-04 09:04:27 +00:00
$form['#after_build'] = 'node_form_add_preview';
2005-10-26 01:24:09 +00:00
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
2005-11-21 18:10:26 +00:00
function node_form_add_preview($form, $edit) {
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()) {
$form['node_preview'] = array('#value' => node_preview((object)$edit), '#weight' => -100);
}
}
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) {
2005-10-22 15:14:46 +00:00
$output = '<div class="node-form">';
2005-10-07 06:11:12 +00:00
if (isset($form['node_preview'])) {
$output .= form_render($form['node_preview']);
2004-04-28 20:23:30 +00:00
}
2005-10-28 14:04:20 +00:00
$output .= ' <div class="standard">';
$output .= form_render($form);
$output .= ' </div>';
2005-10-07 06:11:12 +00:00
$output .= ' <div class="admin">';
$output .= ' <div class="authored">';
$output .= form_render($form['author']);
$output .= ' </div>';
$output .= ' <div class="options">';
$output .= form_render($form['options']);
$output .= ' </div>';
$output .= ' </div>';
$output .= '</div>';
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.
*/
2001-11-01 11:00:51 +00:00
function node_add($type) {
2003-05-13 18:36:38 +00:00
global $user;
2005-10-22 15:14:46 +00:00
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
2001-11-01 11:00:51 +00:00
2004-06-22 20:24:27 +00:00
// If a node type has been specified, validate its existence.
- 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 (array_key_exists($type, node_get_types()) && 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
2004-06-22 20:24:27 +00:00
// Allow the following fields to be initialized via $_GET (e.g. for use
// with a "blog it" bookmarklet):
2004-02-01 22:13:59 +00:00
foreach (array('title', 'teaser', 'body') as $field) {
if ($_GET['edit'][$field]) {
$node[$field] = $_GET['edit'][$field];
2002-10-17 09:21:03 +00:00
}
2002-10-22 18:46:43 +00:00
}
2002-10-17 09:21:03 +00:00
$output = node_form($node);
- 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
drupal_set_title(t('Submit %name', array('%name' => node_get_name($node))));
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.
- 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 (node_get_types() as $type => $name) {
2004-02-01 22:13:59 +00:00
if (node_access('create', $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
$out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>';
2005-06-21 18:58:27 +00:00
$out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
- 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
$item[$name] = $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)) {
ksort($item);
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 {
2005-08-22 20:39:43 +00:00
$output = t('You are not allowed to create content.');
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
2004-06-22 20:24:27 +00:00
// Set the created time when needed:
2002-12-30 13:02:47 +00:00
if (empty($node->created)) {
$node->created = 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'));
- 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
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_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>';
$output .= node_view($node, 1, FALSE, 0);
$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;
}
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);
2005-03-31 09:25:33 +00:00
watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
2006-01-24 08:26:21 +00:00
drupal_set_message(t('The %post was updated.', array ('%post' => node_get_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);
2005-03-31 09:25:33 +00:00
watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
2006-01-24 08:26:21 +00:00
drupal_set_message(t('Your %post was created.', array ('%post' => node_get_name($node))));
2001-12-06 17:33:05 +00:00
}
2002-12-10 20:35:20 +00:00
}
2006-01-24 08:26:21 +00:00
2005-10-07 06:11:12 +00:00
if ($node->nid) {
if (node_access('view', $node)) {
drupal_goto('node/'. $node->nid);
}
else {
drupal_goto();
}
}
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);
2005-10-07 06:11:12 +00:00
$output = confirm_form('node_delete_confirm', $form,
t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
$_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']);
2005-12-27 14:31:42 +00:00
drupal_goto();
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
}
2005-11-04 19:40:28 +00:00
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $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);
}
else {
drupal_access_denied();
}
break;
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)) {
drupal_set_title(t('Revision of %title from %date', array('%title' => theme('placeholder', $node->title), '%date' => format_date($node->revision_timestamp))));
return node_show($node, arg(2));
}
else {
drupal_access_denied();
}
}
}
drupal_not_found();
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;
default:
drupal_not_found();
break;
}
}
drupal_not_found();
}
2004-06-22 20:24:27 +00:00
/**
* Generate a listing of promoted nodes.
*/
2004-02-08 21:16:03 +00:00
function node_page_default() {
2005-01-29 22:02:37 +00:00
$result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));
2004-02-08 21:16:03 +00:00
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 {
$output = t("
2004-02-09 00:56:23 +00:00
<p>Welcome to your new <a href=\"%drupal\">Drupal</a>-powered website. This message will guide you through your first steps with Drupal, and will disappear once you have posted your first piece of content.</p>
<p>The first thing you will need to do is <a href=\"%register\">create the first account</a>. This account will have full administration rights and will allow you to configure your website. Once logged in, you can visit the <a href=\"%admin\">administration section</a> and <a href=\"%config\">set up your site's configuration</a>.</p>
<p>Drupal comes with various modules, each of which contains a specific piece of functionality. You should visit the <a href=\"%modules\">module list</a> and enable those modules which suit your website's needs.</p>
<p><a href=\"%themes\">Themes</a> handle the presentation of your website. You can use one of the existing themes, modify them or create your own from scratch.</p>
2005-11-13 02:43:33 +00:00
<p>We suggest you look around the administration section and explore the various options Drupal offers you. For more information, you can refer to the <a href=\"%handbook\">Drupal handbooks online</a>.</p>", array('%drupal' => 'http://www.drupal.org/', '%register' => url('user/register'), '%admin' => url('admin'), '%config' => url('admin/settings'), '%modules' => url('admin/modules'), '%themes' => url('admin/themes'), '%handbook' => 'http://www.drupal.org/handbooks'));
2004-02-08 21:16:03 +00:00
}
return $output;
}
2004-06-22 20:24:27 +00:00
/**
* Menu callback; dispatches control to the appropriate operation handler.
*/
2001-07-15 16:56:44 +00:00
function node_page() {
2005-10-07 06:11:12 +00:00
$op = arg(1);
2001-11-01 11:00:51 +00:00
2004-06-18 15:04:37 +00:00
if (is_numeric($op)) {
2004-10-16 07:22:26 +00:00
$op = (arg(2) && !is_numeric(arg(2))) ? arg(2) : 'view';
2004-06-18 15:04:37 +00:00
}
2004-02-15 20:09:46 +00:00
switch ($op) {
2005-08-22 10:11:15 +00:00
case 'view':
if (is_numeric(arg(1))) {
2005-12-22 10:57:02 +00:00
$node = node_load(arg(1));
2005-08-22 10:11:15 +00:00
if ($node->nid) {
drupal_set_title(check_plain($node->title));
return node_show($node, arg(2));
}
else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
drupal_access_denied();
}
else {
drupal_not_found();
}
}
break;
2004-02-15 20:09:46 +00:00
case 'add':
2005-04-24 16:34:36 +00:00
return node_add(arg(2));
2004-02-15 20:09:46 +00:00
break;
2005-10-07 06:51:43 +00:00
case 'edit':
2005-10-07 06:11:12 +00:00
if ($_POST['op'] == t('Delete')) {
// Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
if ($_REQUEST['destination']) {
$destination = drupal_get_destination();
unset($_REQUEST['destination']);
}
drupal_goto('node/'. arg(1) .'/delete', $destination);
}
2005-05-25 07:14:00 +00:00
if (is_numeric(arg(1))) {
2005-07-17 18:29:32 +00:00
$node = node_load(arg(1));
2005-05-25 07:14:00 +00:00
if ($node->nid) {
2005-10-07 06:11:12 +00:00
drupal_set_title(check_plain($node->title));
return node_form($node);
2005-05-25 07:14:00 +00:00
}
2005-08-05 00:38:38 +00:00
else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
drupal_access_denied();
}
2005-05-25 07:14:00 +00:00
else {
drupal_not_found();
}
}
break;
2004-02-15 20:09:46 +00:00
default:
2004-12-15 21:19:42 +00:00
drupal_set_title('');
2005-04-24 16:34:36 +00:00
return node_page_default();
2004-02-15 20:09:46 +00:00
}
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-02-01 14:11:53 +00:00
$result = db_query_range('SELECT GREATEST(c.last_comment_timestamp, n.changed, n.created) 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.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)) ORDER BY GREATEST(n.created, 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
2004-12-02 06:44:55 +00:00
// Get node output (filtered and with module-specific fields).
- 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
if (node_hook($node, 'view')) {
2004-11-03 16:46:58 +00:00
node_invoke($node, 'view', false, false);
- 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
}
else {
$node = node_prepare($node, false);
}
2004-12-02 06:44:55 +00:00
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', false, false);
- 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
2005-11-25 10:11:59 +00:00
function node_form_alter($form_id, &$form) {
2005-11-27 11:11:46 +00:00
if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
$form['workflow']['node_options_'. $form['type']['#value']] = array(
'#type' => 'checkboxes', '#title' => t('Default options'), '#default_value' => variable_get('node_options_'. $form['type']['#value'], array('status', 'promote')),
2005-11-25 10:11:59 +00:00
'#options' => array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')),
'#description' => t('Users with the <em>administer nodes</em> permission will be able to override these options.'),
);
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.
- 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
$access = module_invoke(node_get_base($node), '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
}
}
2005-02-18 18:40:05 +00:00
/**
* @} End of "defgroup node_access".
*/
2005-08-25 21:14:17 +00:00