/[drupal]/drupal/modules/node.module
ViewVC logotype

Diff of /drupal/modules/node.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.641, Thu Apr 27 22:20:51 2006 UTC revision 1.641.2.29, Mon Jan 1 22:16:11 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node.module,v 1.640 2006/04/23 05:22:05 drumm Exp $  // $Id: node.module,v 1.641.2.28 2007/01/01 18:28:34 killes Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 43  function node_help($section) { Line 43  function node_help($section) {
43        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>');        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>');
44    }    }
45    
46    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'revisions') {    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'revisions' && !arg(3)) {
47      return t('The revisions let you track differences between multiple versions of a post.');      return t('The revisions let you track differences between multiple versions of a post.');
48    }    }
49    
# Line 160  function node_teaser($body, $format = NU Line 160  function node_teaser($body, $format = NU
160      return $body;      return $body;
161    }    }
162    
163      // If a valid delimiter has been specified, use it to chop off the teaser.
164      if ($delimiter !== FALSE) {
165        return substr($body, 0, $delimiter);
166      }
167    
168    // We check for the presence of the PHP evaluator filter in the current    // We check for the presence of the PHP evaluator filter in the current
169    // format. If the body contains PHP code, we do not split it up to prevent    // format. If the body contains PHP code, we do not split it up to prevent
170    // parse errors.    // parse errors.
# Line 170  function node_teaser($body, $format = NU Line 175  function node_teaser($body, $format = NU
175      }      }
176    }    }
177    
   // If a valid delimiter has been specified, use it to chop of the teaser.  
   if ($delimiter !== FALSE) {  
     return substr($body, 0, $delimiter);  
   }  
   
178    // If we have a short body, the entire body is the teaser.    // If we have a short body, the entire body is the teaser.
179    if (strlen($body) < $size) {    if (strlen($body) < $size) {
180      return $body;      return $body;
# Line 256  function node_get_name($node) { Line 256  function node_get_name($node) {
256  /**  /**
257   * Return the list of available node types.   * Return the list of available node types.
258   *   *
  * @param $node  
  *   Either a node object, a node array, or a string containing the node type.  
259   * @return   * @return
260   *   An array consisting ('#type' => name) pairs.   *   An array consisting ('#type' => name) pairs.
261   */   */
# Line 345  function node_load($param = array(), $re Line 343  function node_load($param = array(), $re
343      $nodes = array();      $nodes = array();
344    }    }
345    
346      $cachable = ($revision == NULL);
347    $arguments = array();    $arguments = array();
348    if (is_numeric($param)) {    if (is_numeric($param)) {
     $cachable = $revision == NULL;  
349      if ($cachable && isset($nodes[$param])) {      if ($cachable && isset($nodes[$param])) {
350        return $nodes[$param];        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
351      }      }
352      $cond = 'n.nid = %d';      $cond = 'n.nid = %d';
353      $arguments[] = $param;      $arguments[] = $param;
# Line 364  function node_load($param = array(), $re Line 362  function node_load($param = array(), $re
362    }    }
363    
364    // Retrieve the node.    // Retrieve the node.
365      // No db_rewrite_sql is applied so as to get complete indexing for search.
366    if ($revision) {    if ($revision) {
367      array_unshift($arguments, $revision);      array_unshift($arguments, $revision);
368      $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond), $arguments));      $node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
369    }    }
370    else {    else {
371      $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond), $arguments));      $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
372    }    }
373    
374    if ($node->nid) {    if ($node->nid) {
# Line 386  function node_load($param = array(), $re Line 385  function node_load($param = array(), $re
385          $node->$key = $value;          $node->$key = $value;
386        }        }
387      }      }
388    }      if ($cachable) {
389          $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
390    if ($cachable) {      }
     $nodes[$param] = $node;  
391    }    }
392    
393    return $node;    return $node;
# Line 660  function node_search($op = 'search', $ke Line 658  function node_search($op = 'search', $ke
658        $ranking = array();        $ranking = array();
659        $arguments2 = array();        $arguments2 = array();
660        $join2 = '';        $join2 = '';
661          $total = 0;
662        // Used to avoid joining on node_comment_statistics twice        // Used to avoid joining on node_comment_statistics twice
663        $stats_join = false;        $stats_join = false;
664        if ($weight = (int)variable_get('node_rank_relevance', 5)) {        if ($weight = (int)variable_get('node_rank_relevance', 5)) {
665          // Average relevance values hover around 0.15          // Average relevance values hover around 0.15
666          $ranking[] = '%d * i.relevance';          $ranking[] = '%d * i.relevance';
667          $arguments2[] = $weight;          $arguments2[] = $weight;
668            $total += $weight;
669        }        }
670        if ($weight = (int)variable_get('node_rank_recent', 5)) {        if ($weight = (int)variable_get('node_rank_recent', 5)) {
671          // Exponential decay with half-life of 6 months, starting at last indexed node          // Exponential decay with half-life of 6 months, starting at last indexed node
# Line 674  function node_search($op = 'search', $ke Line 674  function node_search($op = 'search', $ke
674          $arguments2[] = (int)variable_get('node_cron_last', 0);          $arguments2[] = (int)variable_get('node_cron_last', 0);
675          $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';          $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
676          $stats_join = true;          $stats_join = true;
677            $total += $weight;
678        }        }
679        if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {        if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
680          // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.          // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
# Line 684  function node_search($op = 'search', $ke Line 685  function node_search($op = 'search', $ke
685          if (!$stats_join) {          if (!$stats_join) {
686            $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';            $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
687          }          }
688            $total += $weight;
689        }        }
690        if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&        if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&
691            $weight = (int)variable_get('node_rank_views', 5)) {            $weight = (int)variable_get('node_rank_views', 5)) {
# Line 693  function node_search($op = 'search', $ke Line 695  function node_search($op = 'search', $ke
695          $arguments2[] = $weight;          $arguments2[] = $weight;
696          $arguments2[] = $scale;          $arguments2[] = $scale;
697          $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';          $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
698            $total += $weight;
699        }        }
700        $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') . ' AS score';        $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') . ' AS score';
701    
# Line 727  function node_search($op = 'search', $ke Line 730  function node_search($op = 'search', $ke
730                             'date' => $node->changed,                             'date' => $node->changed,
731                             'node' => $node,                             'node' => $node,
732                             'extra' => $extra,                             'extra' => $extra,
733                               'score' => $item->score / $total,
734                             'snippet' => search_excerpt($keys, $node->body));                             'snippet' => search_excerpt($keys, $node->body));
735        }        }
736        return $results;        return $results;
# Line 805  function node_link($type, $node = 0, $ma Line 809  function node_link($type, $node = 0, $ma
809    $links = array();    $links = array();
810    
811    if ($type == 'node') {    if ($type == 'node') {
     if (array_key_exists('links', $node)) {  
       $links = $node->links;  
     }  
   
812      if ($main == 1 && $node->teaser && $node->readmore) {      if ($main == 1 && $node->teaser && $node->readmore) {
813        $links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));        $links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
814      }      }
# Line 847  function node_menu($may_cache) { Line 847  function node_menu($may_cache) {
847      $items[] = array('path' => 'node', 'title' => t('content'),      $items[] = array('path' => 'node', 'title' => t('content'),
848        'callback' => 'node_page',        'callback' => 'node_page',
849        'access' => user_access('access content'),        'access' => user_access('access content'),
850        'type' => MENU_SUGGESTED_ITEM);        'type' => MENU_MODIFIABLE_BY_ADMIN);
851      $items[] = array('path' => 'node/add', 'title' => t('create content'),      $items[] = array('path' => 'node/add', 'title' => t('create content'),
852        'callback' => 'node_page',        'callback' => 'node_page',
853        'access' => user_access('access content'),        'access' => user_access('access content'),
# Line 884  function node_menu($may_cache) { Line 884  function node_menu($may_cache) {
884            'access' => $revisions_access,            'access' => $revisions_access,
885            'weight' => 2,            'weight' => 2,
886            'type' => MENU_LOCAL_TASK);            'type' => MENU_LOCAL_TASK);
887            $items[] = array('path' => 'node/'. arg(1) .'/revisions/' . arg(3) . '/delete',
888              'title' => t('revisions'),
889              'callback' => 'node_revisions',
890              'access' => $revisions_access,
891              'weight' => 2,
892              'type' => MENU_CALLBACK);
893            $items[] = array('path' => 'node/'. arg(1) .'/revisions/' . arg(3) . '/revert',
894              'title' => t('revisions'),
895              'callback' => 'node_revisions',
896              'access' => $revisions_access,
897              'weight' => 2,
898              'type' => MENU_CALLBACK);
899        }        }
900      }      }
901      else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) {      else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) {
# Line 907  function node_last_changed($nid) { Line 919  function node_last_changed($nid) {
919  function node_operations() {  function node_operations() {
920    $operations = array(    $operations = array(
921      'approve' =>   array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'),      'approve' =>   array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'),
922      'promote' =>   array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d'),      'promote' =>   array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1, moderate = 0 WHERE nid = %d'),
923      'sticky' =>    array(t('Make the selected posts sticky'), 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d'),      'sticky' =>    array(t('Make the selected posts sticky'), 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d'),
924      'demote' =>    array(t('Demote the selected posts'), 'UPDATE {node} SET promote = 0 WHERE nid = %d'),      'demote' =>    array(t('Demote the selected posts'), 'UPDATE {node} SET promote = 0 WHERE nid = %d'),
925      'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'),      'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'),
# Line 1094  function node_admin_nodes_submit($form_i Line 1106  function node_admin_nodes_submit($form_i
1106          db_query($operation, $nid);          db_query($operation, $nid);
1107        }        }
1108      }      }
1109        cache_clear_all();
1110      drupal_set_message(t('The update has been performed.'));      drupal_set_message(t('The update has been performed.'));
1111    }    }
1112  }  }
# Line 1307  function node_revision_revert($nid, $rev Line 1320  function node_revision_revert($nid, $rev
1320    $node = node_load($nid, $revision);    $node = node_load($nid, $revision);
1321    if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {    if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
1322      if ($node->vid) {      if ($node->vid) {
1323        $node->revision = 1;        $form = array();
1324        $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));        $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
1325        $node->taxonomy = array_keys($node->taxonomy);        $form['vid'] = array('#type' => 'value', '#value' => $node->vid);
1326          return confirm_form('node_revision_revert_confirm', $form,
1327        node_save($node);                       t('Are you sure you want to revert %title to the revision from %revision-date?', array('%title' => theme('placeholder', $node->title), '%revision-date' => theme('placeholder', format_date($node->revision_timestamp)))),
1328                         "node/$nid/revisions", ' ', t('Revert'), t('Cancel'));
       drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));  
       watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));  
1329      }      }
1330      else {      else {
1331        drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');        drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
# Line 1324  function node_revision_revert($nid, $rev Line 1335  function node_revision_revert($nid, $rev
1335    drupal_access_denied();    drupal_access_denied();
1336  }  }
1337    
1338    function node_revision_revert_confirm_submit($form_id, $form_values) {
1339      $nid = $form_values['nid'];
1340      $revision = $form_values['vid'];
1341      $node = node_load($nid, $revision);
1342      $node->revision = 1;
1343      $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
1344      if (module_exist('taxonomy')) {
1345        $node->taxonomy = array_keys($node->taxonomy);
1346      }
1347    
1348      node_save($node);
1349      drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
1350      watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
1351      return 'node/'. $nid .'/revisions';
1352    }
1353    
1354  /**  /**
1355   * Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a   * Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a
1356   * revision is deleted.   * revision is deleted.
# Line 1335  function node_revision_delete($nid, $rev Line 1362  function node_revision_delete($nid, $rev
1362        // Don't delete the current revision        // Don't delete the current revision
1363        if ($revision != $node->vid) {        if ($revision != $node->vid) {
1364          $node = node_load($nid, $revision);          $node = node_load($nid, $revision);
1365            $form = array();
1366          db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);          $form['nid'] = array('#type' => 'value', '#value' => $nid);
1367          node_invoke_nodeapi($node, 'delete revision');          $form['vid'] = array('#type' => 'value', '#value' => $revision);
1368          drupal_set_message(t('Deleted %title revision %revision.', array('%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));          return confirm_form('node_revision_delete_confirm', $form,
1369          watchdog('content', t('%type: deleted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));                       t('Are you sure you want to delete %title revision %revision?', array('%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))),
1370                         "node/$nid/revisions", '', t('Delete'), t('Cancel'));
1371        }        }
   
1372        else {        else {
1373          drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));          drupal_set_message(t('Deletion failed. You tried to delete the current revision.'));
1374        }        }
# Line 1353  function node_revision_delete($nid, $rev Line 1380  function node_revision_delete($nid, $rev
1380        }        }
1381      }      }
1382    }    }
   
1383    drupal_access_denied();    drupal_access_denied();
1384  }  }
1385    
1386    function node_revision_delete_confirm_submit($form_id, $form_values) {
1387      $node = node_load($form_values['nid'], $form_values['vid']);
1388      db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
1389      node_invoke_nodeapi($node, 'delete revision');
1390      drupal_set_message(t('Deleted %title revision %revision.', array('%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $node->vid))));
1391      watchdog('content', t('%type: deleted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $node->revision))));
1392    
1393      if (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $node->nid)) > 1) {
1394        return "node/$node->nid/revisions";
1395      }
1396      return "node/$node->nid";
1397    }
1398    
1399  /**  /**
1400   * Return a list of all the existing revision numbers.   * Return a list of all the existing revision numbers.
1401   */   */
# Line 1404  function node_feed($nodes = 0, $channel Line 1443  function node_feed($nodes = 0, $channel
1443    global $base_url, $locale;    global $base_url, $locale;
1444    
1445    if (!$nodes) {    if (!$nodes) {
1446      $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));      $nodes = db_query_range(db_rewrite_sql('SELECT n.nid, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, variable_get('feed_default_items', 10));
1447    }    }
1448    
1449    $item_length = variable_get('feed_item_length', 'teaser');    $item_length = variable_get('feed_item_length', 'teaser');
# Line 1430  function node_feed($nodes = 0, $channel Line 1469  function node_feed($nodes = 0, $channel
1469        node_invoke_nodeapi($item, 'view', $teaser, FALSE);        node_invoke_nodeapi($item, 'view', $teaser, FALSE);
1470      }      }
1471    
1472        // Allow modules to add additional item fields
1473        $extra = node_invoke_nodeapi($item, 'rss item');
1474        $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' =>  date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))));
1475        foreach ($extra as $element) {
1476          if ($element['namespace']) {
1477            $namespaces = array_merge($namespaces, $element['namespace']);
1478          }
1479        }
1480    
1481      // Prepare the item description      // Prepare the item description
1482      switch ($item_length) {      switch ($item_length) {
1483        case 'fulltext':        case 'fulltext':
# Line 1446  function node_feed($nodes = 0, $channel Line 1494  function node_feed($nodes = 0, $channel
1494          break;          break;
1495      }      }
1496    
     // Allow modules to add additional item fields  
     $extra = node_invoke_nodeapi($item, 'rss item');  
     $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' =>  date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))));  
     foreach ($extra as $element) {  
       if ($element['namespace']) {  
         $namespaces = array_merge($namespaces, $element['namespace']);  
       }  
     }  
1497      $items .= format_rss_item($item->title, $link, $item_text, $extra);      $items .= format_rss_item($item->title, $link, $item_text, $extra);
1498    }    }
1499    
# Line 1471  function node_feed($nodes = 0, $channel Line 1511  function node_feed($nodes = 0, $channel
1511    $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);    $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
1512    $output .= "</rss>\n";    $output .= "</rss>\n";
1513    
1514    drupal_set_header('Content-Type: text/xml; charset=utf-8');    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
1515    print $output;    print $output;
1516  }  }
1517    
# Line 1533  function node_validate($node, $form = ar Line 1573  function node_validate($node, $form = ar
1573    }    }
1574    
1575    if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {    if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
1576      form_set_error('changed', t('This content has been modified by another user; changes cannot be saved.'));      form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
1577    }    }
1578    
1579    if (user_access('administer nodes')) {    if (user_access('administer nodes')) {
# Line 1597  function node_form_array($node) { Line 1637  function node_form_array($node) {
1637     * Basic node information.     * Basic node information.
1638     * These elements are just values so they are not even sent to the client.     * These elements are just values so they are not even sent to the client.
1639     */     */
1640    foreach (array('nid', 'vid', 'uid', 'created', 'changed', 'type') as $key) {    foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
1641      $form[$key] = array('#type' => 'value', '#value' => $node->$key);      $form[$key] = array('#type' => 'value', '#value' => $node->$key);
1642    }    }
1643    
1644      // Changed must be sent to the client, for later overwrite error checking.
1645      $form['changed'] = array('#type' => 'hidden', '#default_value' => $node->changed);
1646    
1647    // Get the node-specific bits.    // Get the node-specific bits.
1648    $form = array_merge_recursive($form, node_invoke($node, 'form'));    $form = array_merge_recursive($form, node_invoke($node, 'form'));
1649    if (!isset($form['title']['#weight'])) {    if (!isset($form['title']['#weight'])) {
# Line 1659  function node_form_array($node) { Line 1702  function node_form_array($node) {
1702    return $form;    return $form;
1703  }  }
1704    
1705  function node_form_add_preview($form, $edit) {  function node_form_add_preview($form) {
1706      global $form_values;
1707    
1708    $op = isset($_POST['op']) ? $_POST['op'] : '';    $op = isset($_POST['op']) ? $_POST['op'] : '';
1709    if ($op == t('Preview')) {    if ($op == t('Preview')) {
1710      drupal_validate_form($form['form_id']['#value'], $form);      drupal_validate_form($form['form_id']['#value'], $form);
1711      if (!form_get_errors()) {      if (!form_get_errors()) {
1712        $form['node_preview'] = array('#value' => node_preview((object)$edit), '#weight' => -100);        // Because the node preview may display a form, we must render it
1713          // outside the node submission form tags using the #prefix property
1714          // (i.e. to prevent illegally nested forms).
1715          // If the node form already has a #prefix, we must preserve it.
1716          // In this case, we put the preview before the #prefix so we keep
1717          // the #prefix as "close" to the rest of the form as possible,
1718          // for example, to keep a <div> only around the form, not the
1719          // preview. We pass the global $form_values here to preserve
1720          // changes made during form validation.
1721          $preview = node_preview((object)$form_values);
1722          $form['#prefix'] = isset($form['#prefix']) ? $preview . $form['#prefix'] : $preview;
1723      }      }
1724    }    }
1725    if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {    if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) {
# Line 1674  function node_form_add_preview($form, $e Line 1729  function node_form_add_preview($form, $e
1729  }  }
1730    
1731  function theme_node_form($form) {  function theme_node_form($form) {
1732    $output = '<div class="node-form">';    $output = "\n<div class=\"node-form\">\n";
   if (isset($form['node_preview'])) {  
     $output .= form_render($form['node_preview']);  
   }  
1733    
1734    $output .= '  <div class="standard">';    // Admin form fields and submit buttons must be rendered first, because
1735      // they need to go to the bottom of the form, and so should not be part of
1736      // the catch-all call to form_render().
1737      $admin = '';
1738      if (isset($form['author'])) {
1739        $admin .= "    <div class=\"authored\">\n";
1740        $admin .= form_render($form['author']);
1741        $admin .= "    </div>\n";
1742      }
1743      if (isset($form['options'])) {
1744        $admin .= "    <div class=\"options\">\n";
1745        $admin .= form_render($form['options']);
1746        $admin .= "    </div>\n";
1747      }
1748      $buttons = form_render($form['preview']);
1749      $buttons .= form_render($form['submit']);
1750      $buttons .= isset($form['delete']) ? form_render($form['delete']) : '';
1751    
1752      // Everything else gets rendered here, and is displayed before the admin form
1753      // field and the submit buttons.
1754      $output .= "  <div class=\"standard\">\n";
1755    $output .= form_render($form);    $output .= form_render($form);
1756    $output .= '  </div>';    $output .= "  </div>\n";
1757    $output .= '  <div class="admin">';  
1758    $output .= '    <div class="authored">';    if (!empty($admin)) {
1759    $output .= form_render($form['author']);      $output .= "  <div class=\"admin\">\n";
1760    $output .= '    </div>';      $output .= $admin;
1761    $output .= '    <div class="options">';      $output .= "  </div>\n";
1762    $output .= form_render($form['options']);    }
1763    $output .= '    </div>';    $output .= $buttons;
1764    $output .= '  </div>';    $output .= "</div>\n";
1765    $output .= '</div>';  
1766    return $output;    return $output;
1767  }  }
1768    
# Line 1711  function node_add($type) { Line 1783  function node_add($type) {
1783    else {    else {
1784      // If no (valid) node type has been provided, display a node type overview.      // If no (valid) node type has been provided, display a node type overview.
1785      foreach (node_get_types() as $type => $name) {      foreach (node_get_types() as $type => $name) {
1786        if (module_invoke(node_get_base($type), 'access', 'create', $type)) {        if (node_access('create', $type)) {
1787          $out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>';          $out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>';
1788          $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';          $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
1789          $item[$name] = $out;          $item[$name] = $out;
# Line 1719  function node_add($type) { Line 1791  function node_add($type) {
1791      }      }
1792    
1793      if (isset($item)) {      if (isset($item)) {
1794        uasort($item, 'strnatcasecmp');        uksort($item, 'strnatcasecmp');
1795        $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';        $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
1796      }      }
1797      else {      else {
# Line 1810  function node_form_submit($form_id, $edi Line 1882  function node_form_submit($form_id, $edi
1882    if ($node->nid) {    if ($node->nid) {
1883      // Check whether the current user has the proper access rights to      // Check whether the current user has the proper access rights to
1884      // perform this operation:      // perform this operation:
1885      if (node_access('update', $node)) {      $original_node = node_load($node->nid); //check access rights using the unmodified node
1886        if (node_access('update', $original_node)) {
1887        node_save($node);        node_save($node);
1888        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));        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));
1889        drupal_set_message(t('The %post was updated.', array ('%post' => node_get_name($node))));        drupal_set_message(t('The %post was updated.', array ('%post' => node_get_name($node))));
# Line 1922  function node_revisions() { Line 1995  function node_revisions() {
1995          }          }
1996          break;          break;
1997        case 'revert':        case 'revert':
1998          node_revision_revert(arg(1), arg(3));          return node_revision_revert(arg(1), arg(3));
1999          break;          break;
2000        case 'delete':        case 'delete':
2001          node_revision_delete(arg(1), arg(3));          return node_revision_delete(arg(1), arg(3));
2002          break;          break;
2003      }      }
2004    }    }
# Line 1951  function node_page_default() { Line 2024  function node_page_default() {
2024      $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));      $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
2025    }    }
2026    else {    else {
2027      $output = t("      $output = t('
2028        <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>        <h1 class="title">Welcome to your new Drupal website!</h1>
2029        <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>Please follow these steps to set up and start using your website:</p>
2030        <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>        <ol>
2031        <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>          <li>
2032        <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://drupal.org/', '%register' => url('user/register'), '%admin' => url('admin'), '%config' => url('admin/settings'), '%modules' => url('admin/modules'), '%themes' => url('admin/themes'), '%handbook' => 'http://drupal.org/handbooks'));            <strong>Create your administrator account</strong>
2033              To begin, <a href="%register">create the first account</a>. This account will have full administration rights and will allow you to configure your website.
2034            </li>
2035            <li>
2036              <strong>Configure your website</strong>
2037              Once logged in, visit the <a href="%admin">administration section</a>, where you can <a href="%config">customize and configure</a> all aspects of your website.
2038            </li>
2039            <li>
2040              <strong>Enable additional functionality</strong>
2041              Next, visit the <a href="%modules">module list</a> and enable features which suit your specific needs. You can find additional modules in the <a href="%download_modules">Drupal modules download section</a>.
2042            </li>
2043            <li>
2044              <strong>Customize your website design</strong>
2045              To change the "look and feel" of your website, visit the <a href="%themes">themes section</a>. You may choose from one of the included themes or download additional themes from the <a href="%download_themes">Drupal themes download section</a>.
2046            </li>
2047            <li>
2048              <strong>Start posting content</strong>
2049              Finally, you can <a href="%content">create content</a> for your website. This message will disappear once you have published your first post.
2050            </li>
2051          </ol>
2052          <p>For more information, please refer to the <a href="%help">Help section</a>, or the <a href="%handbook">online Drupal handbooks</a>. You may also post at the <a href="%forum">Drupal forum</a>, or view the wide range of <a href="%support">other support options</a> available.</p>',
2053          array('%drupal' => 'http://drupal.org/', '%register' => url('user/register'), '%admin' => url('admin'), '%config' => url('admin/settings'), '%modules' => url('admin/modules'), '%download_modules' => 'http://drupal.org/project/modules', '%themes' => url('admin/themes'), '%download_themes' => 'http://drupal.org/project/themes', '%content' => url('node/add'), '%help' => url('admin/help'), '%handbook' => 'http://drupal.org/handbooks', '%forum' => 'http://drupal.org/forum', '%support' => 'http://drupal.org/support')
2054        );
2055        $output = '<div id="first-time">'. $output .'</div>';
2056    }    }
2057    
2058    return $output;    return $output;
# Line 2049  function node_update_index() { Line 2145  function node_update_index() {
2145    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_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));
2146    variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));    variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
2147    
2148    $result = db_query_range('SELECT GREATEST(c.last_comment_timestamp, n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);    $result = db_query_range('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);
2149    
2150    while ($node = db_fetch_object($result)) {    while ($node = db_fetch_object($result)) {
2151      $last_change = $node->last_change;      $last_change = $node->last_change;

Legend:
Removed from v.1.641  
changed lines
  Added in v.1.641.2.29

  ViewVC Help
Powered by ViewVC 1.1.2