Mercurial > defr > drupal > core
comparison modules/node/node.module @ 7:fff6d4c8c043 6.3
Drupal 6.3
| author | Franck Deroche <webmaster@defr.org> |
|---|---|
| date | Tue, 23 Dec 2008 14:30:28 +0100 |
| parents | 2427550111ae |
| children | 3edae6ecd6c6 |
comparison
equal
deleted
inserted
replaced
| 6:2cfdc3c92142 | 7:fff6d4c8c043 |
|---|---|
| 1 <?php | 1 <?php |
| 2 // $Id: node.module,v 1.947.2.6 2008/04/09 21:11:48 goba Exp $ | 2 // $Id: node.module,v 1.947.2.11 2008/06/25 08:59:57 goba Exp $ |
| 3 | 3 |
| 4 /** | 4 /** |
| 5 * @file | 5 * @file |
| 6 * The core that allows content to be submitted to the site. Modules and scripts may | 6 * The core that allows content to be submitted to the site. Modules and scripts may |
| 7 * programmatically submit nodes using the usual form API pattern. | 7 * programmatically submit nodes using the usual form API pattern. |
| 133 */ | 133 */ |
| 134 function node_title_list($result, $title = NULL) { | 134 function node_title_list($result, $title = NULL) { |
| 135 $items = array(); | 135 $items = array(); |
| 136 $num_rows = FALSE; | 136 $num_rows = FALSE; |
| 137 while ($node = db_fetch_object($result)) { | 137 while ($node = db_fetch_object($result)) { |
| 138 $items[] = l($node->title, 'node/'. $node->nid, !empty($node->comment_count) ? array('title' => format_plural($node->comment_count, '1 comment', '@count comments')) : array()); | 138 $items[] = l($node->title, 'node/'. $node->nid, !empty($node->comment_count) ? array('attributes' => array('title' => format_plural($node->comment_count, '1 comment', '@count comments'))) : array()); |
| 139 $num_rows = TRUE; | 139 $num_rows = TRUE; |
| 140 } | 140 } |
| 141 | 141 |
| 142 return $num_rows ? theme('node_list', $items, $title) : FALSE; | 142 return $num_rows ? theme('node_list', $items, $title) : FALSE; |
| 143 } | 143 } |
| 905 $node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT; | 905 $node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT; |
| 906 $update_node = TRUE; | 906 $update_node = TRUE; |
| 907 | 907 |
| 908 // Generate the node table query and the node_revisions table query. | 908 // Generate the node table query and the node_revisions table query. |
| 909 if ($node->is_new) { | 909 if ($node->is_new) { |
| 910 _node_save_revision($node, $user->uid); | |
| 910 drupal_write_record('node', $node); | 911 drupal_write_record('node', $node); |
| 911 _node_save_revision($node, $user->uid); | 912 db_query('UPDATE {node_revisions} SET nid = %d WHERE vid = %d', $node->nid, $node->vid); |
| 912 $op = 'insert'; | 913 $op = 'insert'; |
| 913 } | 914 } |
| 914 else { | 915 else { |
| 915 drupal_write_record('node', $node, 'nid'); | 916 drupal_write_record('node', $node, 'nid'); |
| 916 if (!empty($node->revision)) { | 917 if (!empty($node->revision)) { |
| 917 _node_save_revision($node, $user->uid); | 918 _node_save_revision($node, $user->uid); |
| 919 db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid); | |
| 918 } | 920 } |
| 919 else { | 921 else { |
| 920 _node_save_revision($node, $user->uid, 'vid'); | 922 _node_save_revision($node, $user->uid, 'vid'); |
| 921 $update_node = FALSE; | 923 $update_node = FALSE; |
| 922 } | 924 } |
| 923 $op = 'update'; | 925 $op = 'update'; |
| 924 } | |
| 925 if ($update_node) { | |
| 926 db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid); | |
| 927 } | 926 } |
| 928 | 927 |
| 929 // Call the node specific callback (if any). | 928 // Call the node specific callback (if any). |
| 930 node_invoke($node, $op); | 929 node_invoke($node, $op); |
| 931 node_invoke_nodeapi($node, $op); | 930 node_invoke_nodeapi($node, $op); |
| 1255 $arguments2[] = $weight; | 1254 $arguments2[] = $weight; |
| 1256 $arguments2[] = $scale; | 1255 $arguments2[] = $scale; |
| 1257 $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid'; | 1256 $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid'; |
| 1258 $total += $weight; | 1257 $total += $weight; |
| 1259 } | 1258 } |
| 1260 $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') .' AS score'; | 1259 |
| 1261 | 1260 // When all search factors are disabled (ie they have a weight of zero), |
| 1262 // Do search | 1261 // the default score is based only on keyword relevance and there is no need to |
| 1263 $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); | 1262 // adjust the score of each item. |
| 1264 | 1263 if ($total == 0) { |
| 1265 // Load results | 1264 $select2 = 'i.relevance AS score'; |
| 1265 $total = 1; | |
| 1266 } | |
| 1267 else { | |
| 1268 $select2 = implode(' + ', $ranking) . ' AS score'; | |
| 1269 } | |
| 1270 | |
| 1271 // Do search. | |
| 1272 $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1, $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2); | |
| 1273 | |
| 1274 // Load results. | |
| 1266 $results = array(); | 1275 $results = array(); |
| 1267 foreach ($find as $item) { | 1276 foreach ($find as $item) { |
| 1268 // Build the node body. | 1277 // Build the node body. |
| 1269 $node = node_load($item->sid); | 1278 $node = node_load($item->sid); |
| 1270 $node->build_mode = NODE_BUILD_SEARCH_RESULT; | 1279 $node->build_mode = NODE_BUILD_SEARCH_RESULT; |
| 1271 $node = node_build_content($node, FALSE, FALSE); | 1280 $node = node_build_content($node, FALSE, FALSE); |
| 1272 $node->body = drupal_render($node->content); | 1281 $node->body = drupal_render($node->content); |
| 1273 | 1282 |
| 1274 // Fetch comments for snippet | 1283 // Fetch comments for snippet. |
| 1275 $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index'); | 1284 $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index'); |
| 1276 // Fetch terms for snippet | 1285 // Fetch terms for snippet. |
| 1277 $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index'); | 1286 $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index'); |
| 1278 | 1287 |
| 1279 $extra = node_invoke_nodeapi($node, 'search result'); | 1288 $extra = node_invoke_nodeapi($node, 'search result'); |
| 1280 $results[] = array( | 1289 $results[] = array( |
| 1281 'link' => url('node/'. $item->sid, array('absolute' => TRUE)), | 1290 'link' => url('node/'. $item->sid, array('absolute' => TRUE)), |
| 1672 node_invoke_nodeapi($item, 'view', $teaser, FALSE); | 1681 node_invoke_nodeapi($item, 'view', $teaser, FALSE); |
| 1673 } | 1682 } |
| 1674 | 1683 |
| 1675 // Allow modules to add additional item fields and/or modify $item | 1684 // Allow modules to add additional item fields and/or modify $item |
| 1676 $extra = node_invoke_nodeapi($item, 'rss item'); | 1685 $extra = node_invoke_nodeapi($item, 'rss item'); |
| 1677 $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => format_date($item->created, 'custom', 'r')), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid .' at '. $base_url, 'attributes' => array('isPermaLink' => 'false')))); | 1686 $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => gmdate('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid .' at '. $base_url, 'attributes' => array('isPermaLink' => 'false')))); |
| 1678 foreach ($extra as $element) { | 1687 foreach ($extra as $element) { |
| 1679 if (isset($element['namespace'])) { | 1688 if (isset($element['namespace'])) { |
| 1680 $namespaces = array_merge($namespaces, $element['namespace']); | 1689 $namespaces = array_merge($namespaces, $element['namespace']); |
| 1681 } | 1690 } |
| 1682 } | 1691 } |
