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':
2004-06-22 20:24:27 +00:00
$output = t("
2004-01-23 18:42:43 +00:00
<h3>Nodes</h3>
<p>The core of the Drupal system is the node. All of the contents of the system are placed in nodes, or extensions of nodes.
A base node contains:<dl>
<dt>A Title</dt><dd>Up to 128 characters of text that titles the node.</dd>
<dt>A Teaser</dt><dd>A small block of text that is meant to get you interested in the rest of node. Drupal will automatically pull a small amount of the body of the node to make the teaser (To configure how long the teaser will be <a href=\"%teaser\">click here</a>). The teaser can be changed if you don't like what Drupal grabs.</dd>
<dt>The Body</dt><dd>The main text that comprises your content.</dd>
<dt>A Type</dt><dd>What kind of node is this? Blog, book, forum, comment, unextended, etc.</dd>
2004-03-20 13:29:06 +00:00
<dt>An Author</dt><dd>The author's name. It will either be \"anonymous\" or a valid user. You <em>cannot</em> set it to an arbitrary value.</dd>
2004-01-23 18:42:43 +00:00
<dt>Authored on</dt><dd>The date the node was written.</dd>
<dt>Changed</dt><dd>The last time this node was changed.</dd>
2004-06-21 20:05:37 +00:00
<dt>Sticky at top of lists</dt><dd>In listings such as the frontpage or a taxonomy overview the teasers of a selected amount of nodes is displayed. If you want to force a node to appear on the top of such a listing, you must set it to 'sticky'. This way it will float to the top of a listing, and it will not be pushed down by newer content.
2004-01-23 18:42:43 +00:00
<dt>Allow user comments</dt><dd>A node can have comments. These comments can be written by other users (Read-write), or only by admins (Read-only).</dd>
<dt>Revisions</dt><dd>Drupal has a revision system so that you can \"roll back\" to an older version of a post if the new version is not what you want.</dd>
2004-06-19 10:39:36 +00:00
<dt>Promote to front page</dt><dd>To get people to look at the new stuff on your site you can choose to move it to the front page. The front page is configured to show the teasers from only a few of the total nodes you have on your site (To configure how many teasers <a href=\"%teaser\">click here</a>).</dd>
2004-06-20 08:27:03 +00:00
<dt>Published</dt><dd>When using Drupal's moderation system a node remains unpublished -- unavailable to non-moderators -- until it is marked Published.</dd></dl>
2004-06-20 19:49:14 +00:00
<p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/node/configure/settings")));
2003-10-03 14:55:27 +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
foreach (node_get_types() as $type => $name) {
$output .= '<h3>'. t('Node type: %name', array('%name' => $name)). '</h3>';
2004-08-16 18:31:44 +00:00
$output .= implode("\n", module_invoke_all('help', 'node/add#'. $type));
2001-06-06 20:26:12 +00:00
}
2004-08-16 18:31:44 +00:00
2004-06-22 20:24:27 +00:00
return $output;
2003-08-23 18:25:35 +00:00
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) {
static $node_names, $node_list;
if (!isset($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);
if (is_array($result)) {
$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();
}
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];
}
$cond = 'n.nid = '. $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) {
2005-07-17 18:29:32 +00:00
$cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'";
}
$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) {
$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), $revision));
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
else {
$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)));
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');
// We always update the timestamp for new revisions.
$node->changed = time();
}
2001-12-08 11:12:26 +00:00
}
2005-08-30 15:22:29 +00:00
if (!$node->changed) {
2001-12-08 11:12:26 +00:00
$node->changed = time();
2005-08-30 15:22:29 +00:00
}
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) {
2001-12-30 16:16:38 +00:00
$node = array2object($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) {
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. $node->log .'</div>';
}
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() {
2004-02-01 22:13:59 +00:00
return array('administer nodes', 'access content');
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');
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);
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0'));
2005-02-28 18:00:59 +00:00
$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 n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d)', $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';
$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.') .'</em>');
$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
$form['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced search'), '#collapsible' => true, '#collapsed' => true, '#attributes' => array('class' => 'search-advanced'));
$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();
$form['advanced']['type'] = array('#type' => 'checkboxes', '#title' => t('Only of the type'), '#prefix' => '<div class="criterium">', '#suffix' => '</div>', '#options' => $types, '#multiple' => true);
$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'];
if (is_array($edit['type'])) {
$keys = search_query_insert($keys, 'type', implode(',', array_keys($edit['type'])));
}
if (is_array($edit['category'])) {
$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'),
2004-06-18 15:04:37 +00:00
'callback' => 'node_admin',
2004-09-16 07:17:56 +00:00
'access' => user_access('administer nodes'));
2005-02-02 00:55:59 +00:00
$items[] = array('path' => 'admin/node/action', 'title' => t('content'),
'type' => MENU_CALLBACK);
2004-09-16 07:17:56 +00:00
$items[] = array('path' => 'admin/node/overview', 'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
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-09-16 07:17:56 +00:00
if (module_exist('search')) {
$items[] = array('path' => 'admin/node/search', 'title' => t('search'),
'callback' => 'node_admin',
'access' => user_access('administer nodes'),
'type' => MENU_LOCAL_TASK);
}
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);
}
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-07-20 10:48:20 +00:00
'callback' => 'node_delete_page',
2005-03-03 20:51:27 +00:00
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
2005-08-30 15:22:29 +00:00
if (user_access('administer nodes') && db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', arg(1))) > 1) {
2004-10-12 20:01:25 +00:00
$items[] = array('path' => 'node/'. arg(1) .'/revisions', 'title' => t('revisions'),
'callback' => 'node_page',
'access' => user_access('administer nodes'),
'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>';
}
}
$output .= '<li><dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>and</em> where</dt>' : '') . '<dd class="a">';
foreach(element_children($form['filter']) as $key) {
$output .= form_render($form['filter'][$key]);
}
$output .= '</dd>';
$output .= '<dt>is</dt>' . '<dd class="b">';
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;
}
function node_filter_form_execute() {
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.
*/
function node_admin_nodes_execute($form_id, $edit) {
$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.'));
}
drupal_goto('admin/node');
}
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();
$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);
// If you are attempting to delete nodes, display the multiple deletion form.
if ($form_values['operation'] == 'delete') {
$output = node_multiple_delete_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']);
if (is_array($form['title'])) {
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']);
}
return $output;
}
function node_multiple_delete_form() {
global $form_values;
2005-10-11 19:44:35 +00:00
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>');
2005-10-07 06:11:12 +00:00
foreach ($form_values['nodes'] as $nid => $value) {
if ($value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
2005-10-11 19:44:35 +00:00
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#tree' => TRUE, '#prefix' => '<li>', '#suffix' => check_plain($title) .'</li>');
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
return confirm_form('node_multiple_delete_form', $form,
t('Are you sure you want to delete these items?'),
'admin/node', t('This action cannot be undone.'),
t('Delete all'), t('Cancel'));
}
function node_multiple_delete_form_execute($form_id, $edit) {
if ($edit['confirm']) {
foreach ($edit['nodes'] as $nid => $value) {
node_delete(array('nid' => $nid, 'confirm' => 1));
}
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)) {
// Go to the listing page when we submit this form, system_settings_save() calls drupal_goto().
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-10-11 19:44:35 +00:00
'#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => variable_get($type .'_help', ''), '#cols' => 60, '#rows' => 5,
'#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-10-07 06:11:12 +00:00
$form['workflow'] = array_merge($form['workflow'], node_invoke_nodeapi($node, 'settings'));
2005-10-13 10:02:31 +00:00
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
2005-10-07 06:11:12 +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
*/
2003-11-11 16:25:10 +00:00
function node_revision_overview($nid) {
2004-02-01 22:13:59 +00:00
if (user_access('administer nodes')) {
2005-07-17 18:29:32 +00:00
$node = node_load($nid);
2003-11-11 16:25:10 +00:00
2005-08-30 15:22:29 +00:00
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title))));
if ($node->vid) {
$header = array('', t('Author'), t('Title'), t('Date'), array('colspan' => '3', 'data' => t('Operations')));
2004-07-04 19:24:52 +00:00
2005-08-30 15:22:29 +00:00
$revisions = node_revision_list($node);
2003-11-11 16:25:10 +00:00
2005-08-30 15:22:29 +00:00
$i = 0;
foreach ($revisions as $revision) {
$row = ++$i;
if ($revision->current_vid) {
$rows[] = array(
array('data' => $row .' '. t('(current)'), 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
$revision->title,
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid"),
'', '');
}
else {
$rows[] = array(
array('data' => $row, 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
$revision->title,
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid/revision/". $revision->vid),
l(t('set active'), "node/$node->nid/rollback-revision/". $revision->vid),
l(t('delete'), "node/$node->nid/delete-revision/". $revision->vid));
}
if ($revision->log != '') {
$rows[] = array(array('data' => $revision->log, 'colspan' => 6));
}
2003-11-11 16:25:10 +00:00
}
2004-02-01 22:13:59 +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
/**
* Roll back to the revision with the specified revision number.
*/
2003-11-11 16:25:10 +00:00
function node_revision_rollback($nid, $revision) {
2001-11-05 22:59:11 +00:00
global $user;
2001-11-03 18:38:30 +00:00
2004-02-01 22:13:59 +00:00
if (user_access('administer nodes')) {
2005-10-22 15:14:46 +00:00
if ($title = db_fetch_object(db_query('SELECT title, timestamp FROM {node_revisions} WHERE nid = %d AND vid = %d', $nid, $revision))) {
2005-08-30 15:22:29 +00:00
db_query('UPDATE {node} SET vid = %d, changed = %d WHERE nid = %d', $revision, $title->timestamp, $nid);
2001-11-03 18:38:30 +00:00
2005-08-30 15:22:29 +00:00
drupal_set_message(t('%title has been rolled back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($title->timestamp)), '%title' => theme('placeholder', check_plain($title->title)))));
}
else {
drupal_set_message(t('You tried to roll back 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
}
2001-11-03 18:38:30 +00:00
}
2004-06-22 20:24:27 +00:00
/**
* Delete the revision with specified revision number.
*/
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-08-30 15:22:29 +00:00
$count_revisions = db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $nid));
// Don't delete the last revision of the node or the current revision
if ($count_revisions > 1) {
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);
drupal_set_message(t('Deleted revision with the ID %revision.', array('%revision' => theme('placeholder', $revision))));
}
else {
drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));
}
2001-11-04 23:30:39 +00:00
2005-08-30 15:22:29 +00:00
drupal_goto("node/$nid/revisions");
2003-11-11 16:25:10 +00:00
}
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();
$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 ASC', $node->nid);
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
}
2004-06-22 20:24:27 +00:00
/**
* Menu callback; presents the content administration overview.
*/
2001-04-02 15:54:37 +00:00
function node_admin() {
2005-10-22 15:14:46 +00:00
$op = isset($_POST['op']) ? $_POST['op'] : '';
$edit = isset($_POST['edit']) ? $_POST['edit'] : '';
2001-04-10 20:07:27 +00:00
2004-02-15 20:09:46 +00:00
if (empty($op)) {
$op = arg(2);
2001-06-20 20:00:40 +00:00
}
2004-02-15 20:09:46 +00:00
2004-06-22 20:24:27 +00:00
// Compile a list of the administrative links:
2004-02-15 20:09:46 +00:00
switch ($op) {
case '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
case t('Search'):
$output = search_form(url('admin/node/search'), $_POST['edit']['keys'], 'node') . search_data($_POST['edit']['keys'], 'node');
2004-02-15 20:09:46 +00:00
break;
default:
$output = node_admin_nodes();
2001-04-02 15:54:37 +00:00
}
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');
$block['content'] = theme('xml_icon', url('node/feed'));
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-10-08 12:21:47 +00:00
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name)));
2005-09-18 10:37:57 +00:00
foreach ($extra as $element) {
if ($element['namespace']) {
$namespaces = array_merge($namespaces, array($element['namespace']));
}
}
$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";
2002-12-21 19:36:27 +00:00
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\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
/**
2004-09-09 05:51:08 +00:00
* Perform validation checks on the given node.
2004-06-22 20:24:27 +00:00
*/
2004-07-04 16:50:02 +00:00
function node_validate($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.
2001-12-30 16:16:38 +00:00
$node = array2object($node);
2001-11-01 11:00:51 +00:00
2005-03-31 21:18:08 +00:00
// Make sure the body has the minimum number of words.
2005-01-26 22:59:41 +00:00
// 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)) {
- 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
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))));
2005-01-26 22:59:41 +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
2005-10-22 15:14:46 +00:00
if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
2005-01-27 14:45:42 +00:00
form_set_error('changed', t('This content has been modified by another user, unable to save changes.'));
}
2004-02-01 22:13:59 +00:00
if (user_access('administer nodes')) {
2004-06-22 20:24:27 +00:00
// Validate the "authored by" field.
2004-08-14 17:05:32 +00:00
if (empty($node->name)) {
2004-06-22 20:24:27 +00:00
// The use of empty() is mandatory in the context of usernames
// as the empty string denotes the anonymous user. In case we
2004-10-19 18:02:31 +00:00
// are dealing with an anonymous user we set the user ID to 0.
2001-11-20 22:51:06 +00:00
$node->uid = 0;
}
2004-02-01 22:13:59 +00:00
else 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-03-31 09:25:33 +00:00
form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name))));
2001-11-01 11:00:51 +00:00
}
2004-06-22 20:24:27 +00:00
// Validate the "authored on" field.
2004-02-08 20:36:13 +00:00
if (strtotime($node->date) != -1) {
2001-11-01 22:54:16 +00:00
$node->created = strtotime($node->date);
2001-11-01 11:00:51 +00:00
}
else {
2004-10-19 18:02:31 +00:00
form_set_error('date', t('You have to specify a valid 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.
2004-07-04 16:50:02 +00:00
node_invoke($node, 'validate');
node_invoke_nodeapi($node, 'validate');
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-10-07 06:11:12 +00:00
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) {
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 14:49:59 +00:00
$node = array2object($node);
2005-10-26 01:24:09 +00:00
node_object_prepare($node);
2001-11-01 11:00:51 +00:00
2005-10-07 06:11:12 +00:00
// Set the id of the top-level form tag
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-10-07 06:11:12 +00:00
2004-06-22 20:24:27 +00:00
// Get the node-specific bits.
2005-10-28 00:28:14 +00:00
$form = array_merge($form, node_invoke($node, 'form'));
2003-06-05 18:09:39 +00:00
2005-10-07 06:11:12 +00:00
/**
* Node author information
*/
2001-11-01 11:00:51 +00:00
2005-10-11 19:44:35 +00:00
if (user_access('administer nodes')) {
$form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -18);
$form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name, '#weight' => -1);
$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-10-11 19:44:35 +00:00
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
2001-11-01 11:00:51 +00:00
2005-10-11 19:44:35 +00:00
/**
* Node options
*/
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -18);
$form['options']['status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => in_array('status', $node_options));
$form['options']['moderate'] = array('#type' => 'checkbox', '#title' => t('In moderation queue'), '#default_value' => in_array('moderate', $node_options));
$form['options']['promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => in_array('promote', $node_options));
$form['options']['sticky'] = array('#type' => 'checkbox', '#title' =>t('Sticky at top of lists'), '#default_value' => in_array('sticky', $node_options));
$form['options']['revision'] = array('#type' => 'checkbox', '#title' =>t('Create new revision'), '#default_value' => in_array('revision', $node_options));
}
2001-11-01 11:00:51 +00:00
2005-10-07 06:11:12 +00:00
$nodeapi = node_invoke_nodeapi($node, 'form');
if (is_array($nodeapi)) {
foreach ($nodeapi as $key => $element) {
2005-10-11 19:44:35 +00:00
$nodeapi[$key]['#weight'] = isset($nodeapi[$key]['#weight']) ? $nodeapi[$key]['#weight'] : -18;
2005-10-07 06:11:12 +00:00
}
// Append extra node form elements.
$form = array_merge($form, $nodeapi);
2005-01-27 14:45:42 +00:00
}
2005-10-07 06:51:43 +00:00
2005-10-11 19:44:35 +00:00
$form['title']['#weight'] = isset($form['title']['#weight']) ? $form['title']['#weight'] : -17;
$form['body']['#weight'] = isset($form['body']['#weight']) ? $form['body']['#weight'] : -5;
2001-11-01 11:00:51 +00:00
2004-06-22 20:24:27 +00:00
// Add the buttons.
2005-10-11 19:44:35 +00:00
$form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 19);
2001-11-01 11:00:51 +00:00
2005-10-11 19:44:35 +00:00
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 20);
2005-10-07 06:11:12 +00:00
if ($node->nid && node_access('delete', $node)) {
2005-10-11 19:44:35 +00:00
$form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 21);
2001-11-01 11:00:51 +00:00
}
2005-10-26 01:24:09 +00:00
if ($op == t('Preview')) {
$form['#post_process'] = 'node_form_add_preview';
}
2005-10-07 06:11:12 +00:00
return drupal_get_form($node->type . '_node_form', $form, 'node_form');
}
2001-11-01 11:00:51 +00:00
2005-10-26 01:24:09 +00:00
function node_form_add_preview($form_id, $form, $edit) {
$form['node_preview'] = array('#value' => node_preview(node_validate($edit)), '#weight' => -100);
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-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 class="standard">';
$output .= form_render($form);
$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-10-07 06:11:12 +00:00
function node_form_execute($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-10-07 06:11:12 +00:00
$node = node_validate($edit);
- 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
2004-06-22 20:24:27 +00:00
// If something went wrong, go back to the preview form.
2004-07-04 16:50:02 +00:00
if (form_get_errors()) {
2005-10-07 06:11:12 +00:00
return node_form($edit);
2002-12-10 20:35:20 +00:00
}
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));
- 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
$msg = 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"));
- 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
$msg = 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
}
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
/**
* Ask for confirmation, and delete the node.
*/
2001-11-03 18:38:30 +00:00
function node_delete($edit) {
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-10-11 19:44:35 +00:00
$form['nid'] = array('#type' => 'hidden', '#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-10-07 06:11:12 +00:00
function node_delete_confirm_execute() {
global $form_values;
$node = node_load($form_values['nid']);
if (node_access('delete', $node)) {
if ($form_values['confirm']) {
2004-06-22 20:24:27 +00:00
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
2005-08-30 15:22:29 +00:00
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
2001-11-01 11:00:51 +00:00
2004-06-22 20:24:27 +00:00
// Call the node-specific callback (if any):
2004-02-01 22:13:59 +00:00
node_invoke($node, 'delete');
node_invoke_nodeapi($node, 'delete');
2001-11-03 18:38:30 +00:00
2004-06-22 20:24:27 +00:00
// Clear the cache so an anonymous poster can see the node being deleted.
2003-03-16 21:47:15 +00:00
cache_clear_all();
2004-12-20 14:34:41 +00:00
// Remove this node from the search index if needed.
if (function_exists('search_wipe')) {
search_wipe($node->nid, 'node');
}
2004-11-04 06:47:03 +00:00
2005-03-31 09:25:33 +00:00
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
2001-11-01 17:04:20 +00:00
}
2001-11-01 11:00:51 +00:00
}
2005-10-07 06:11:12 +00:00
drupal_goto('node');
2001-11-01 11:00:51 +00:00
}
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'),
'href' => url('node/feed', 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-07-18 08:46:30 +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'), '%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) {
case 'feed':
node_feed();
return;
2005-08-22 10:11:15 +00:00
case 'view':
if (is_numeric(arg(1))) {
$node = node_load(arg(1), $_GET['revision']);
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;
case 'revisions':
2005-05-25 07:14:00 +00:00
if (user_access('administer nodes')) {
return node_revision_overview(arg(1));
}
else {
drupal_access_denied();
}
2004-02-15 20:09:46 +00:00
break;
case 'rollback-revision':
2004-07-04 19:24:52 +00:00
node_revision_rollback(arg(1), arg(3));
2004-02-15 20:09:46 +00:00
break;
case 'delete-revision':
2004-07-04 19:24:52 +00:00
node_revision_delete(arg(1), arg(3));
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;
2005-08-30 15:22:29 +00:00
case 'revision':
if (is_numeric(arg(1)) && is_numeric(arg(3))) {
$node = node_load(arg(1), arg(3));
if ($node->nid) {
drupal_set_title(t('Revision of %title', array('%title' => theme('placeholder', $node->title))));
print theme('page', node_show($node, arg(2)));
}
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
2005-07-20 10:48:20 +00:00
/**
* Menu callback; the page for deleting a single node.
*/
function node_delete_page() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (!($output = node_delete($edit))) {
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
drupal_goto('');
}
return $output;
}
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_update_index().
*/
2002-03-05 20:15:17 +00:00
function node_update_index() {
- Patch #12232 by Steven/UnConed: search module improvements.
1) Clean up the text analyser: make it handle UTF-8 and all sorts of characters. The word splitter now does intelligent splitting into words and supports all Unicode characters. It has smart handling of acronyms, URLs, dates, ...
2) It now indexes the filtered output, which means it can take advantage of HTML tags. Meaningful tags (headers, strong, em, ...) are analysed and used to boost certain words scores. This has the side-effect of allowing the indexing of PHP nodes.
3) Link analyser for node links. The HTML analyser also checks for links. If they point to a node on the current site (handles path aliases) then the link's words are counted as part of the target node. This helps bring out commonly linked FAQs and answers to the top of the results.
4) Index comments along with the node. This means that the search can make a difference between a single node/comment about 'X' and a whole thread about 'X'. It also makes the search results much shorter and more relevant (before this patch, comments were even shown first).
5) We now keep track of total counts as well as a per item count for a word. This allows us to divide the word score by the total before adding up the scores for different words, and automatically makes noisewords have less influence than rare words. This dramatically improves the relevancy of multiword searches. This also makes the disadvantage of now using OR searching instead of AND searching less problematic.
6) Includes support for text preprocessors through a hook. This is required to index Chinese and Japanese, because these languages do not use spaces between words. An external utility can be used to split these into words through a simple wrapper module. Other uses could be spell checking (although it would have no UI).
7) Indexing is now regulated: only a certain amount of items will be indexed per cron run. This prevents PHP from running out of memory or timing out. This also makes the reindexing required for this patch automatic. I also added an index coverage estimate to the search admin screen.
8) Code cleanup! Moved all the search stuff from common.inc into search.module, rewired some hooks and simplified the functions used. The search form and results now also use valid XHTML and form_ functions. The search admin was moved from search/configure to admin/search for consistency.
9) Improved search output: we also show much more info per item: date, author, node type, amount of comments and a cool dynamic excerpt à la Google. The search form is now much more simpler and the help is only displayed as tips when no search results are found.
10) By moving all search logic to SQL, I was able to add a pager to the search results. This improves usability and performance dramatically.
2004-10-31 03:03:27 +00:00
$last = variable_get('node_cron_last', 0);
$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}'))));
2004-11-18 21:16:30 +00:00
$result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit);
- 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)) {
2004-11-18 21:16:30 +00:00
$last_comment = $node->last_comment_timestamp;
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
// We update this variable per node in case cron times out, or if the node
// cannot be indexed (PHP nodes which call drupal_goto, for example).
// In rare cases this can mean a node is only partially indexed, but the
// chances of this happening are very small.
2004-11-18 21:28:34 +00:00
variable_set('node_cron_last', max($last_comment, $node->changed, $node->created));
- 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
2004-06-22 20:24:27 +00:00
/**
* Implementation of hook_nodeapi().
*/
2003-02-23 21:36:29 +00:00
function node_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
2004-02-01 22:13:59 +00:00
case 'settings':
2005-10-07 06:11:12 +00:00
$form['node_options_'. $node->type] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'checkboxes', '#title' => t('Default options'), '#default_value' => variable_get('node_options_'. $node->type, array('status', 'promote')),
'#options' => array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'),
2005-10-07 06:11:12 +00:00
'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')),
2005-10-11 19:44:35 +00:00
'#description' => t('Users with the <em>administer nodes</em> permission will be able to override these options.')
2005-10-07 06:11:12 +00:00
);
return $form;
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"
* @param $node
* The node object (or node array) on which the operation is to be performed.
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:
$node = array2object($node);
// 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.
if ($node->nid && $node->status) {
$sql = 'SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) AND CONCAT(realm, gid) IN (';
$grants = array();
foreach (node_access_grants($op, $uid) as $realm => $gids) {
foreach ($gids as $gid) {
$grants[] = "'". $realm . $gid ."'";
}
}
2005-08-05 13:11:10 +00:00
$sql .= implode(',', $grants) .') 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
}
$sql = $node_access_alias .'.grant_'. $op .' = 1 AND CONCAT('. $node_access_alias .'.realm, '. $node_access_alias .'.gid) IN (';
$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) {
$grants[] = "'". $realm . $gid ."'";
}
}
$sql .= implode(',', $grants) .')';
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)) {
$sql = 'SELECT COUNT(*) FROM {node_access} WHERE nid = 0 AND CONCAT(realm, gid) IN (';
$grants = array();
foreach (node_access_grants('view') as $realm => $gids) {
foreach ($gids as $gid) {
$grants[] = "'". $realm . $gid ."'";
}
}
$sql .= implode(',', $grants) .') 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