/[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.25, Sat Dec 16 13:22:12 2006 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.24 2006/12/12 12:48:57 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 345  function node_load($param = array(), $re Line 345  function node_load($param = array(), $re
345      $nodes = array();      $nodes = array();
346    }    }
347    
348      $cachable = FALSE;
349    $arguments = array();    $arguments = array();
350    if (is_numeric($param)) {    if (is_numeric($param)) {
351      $cachable = $revision == NULL;      $cachable = $revision == NULL;
352      if ($cachable && isset($nodes[$param])) {      if ($cachable && isset($nodes[$param])) {
353        return $nodes[$param];        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
354      }      }
355      $cond = 'n.nid = %d';      $cond = 'n.nid = %d';
356      $arguments[] = $param;      $arguments[] = $param;
# Line 364  function node_load($param = array(), $re Line 365  function node_load($param = array(), $re
365    }    }
366    
367    // Retrieve the node.    // Retrieve the node.
368      // No db_rewrite_sql is applied so as to get complete indexing for search.
369    if ($revision) {    if ($revision) {
370      array_unshift($arguments, $revision);      array_unshift($arguments, $revision);
371      $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));
372    }    }
373    else {    else {
374      $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));
375    }    }
376    
377    if ($node->nid) {    if ($node->nid) {
# Line 389  function node_load($param = array(), $re Line 391  function node_load($param = array(), $re
391    }    }
392    
393    if ($cachable) {    if ($cachable) {
394      $nodes[$param] = $node;      $nodes[$param] = is_object($node) ? drupal_clone($node) : $node;
395    }    }
396    
397    return $node;    return $node;
# Line 660  function node_search($op = 'search', $ke Line 662  function node_search($op = 'search', $ke
662        $ranking = array();        $ranking = array();
663        $arguments2 = array();        $arguments2 = array();
664        $join2 = '';        $join2 = '';
665          $total = 0;
666        // Used to avoid joining on node_comment_statistics twice        // Used to avoid joining on node_comment_statistics twice
667        $stats_join = false;        $stats_join = false;
668        if ($weight = (int)variable_get('node_rank_relevance', 5)) {        if ($weight = (int)variable_get('node_rank_relevance', 5)) {
669          // Average relevance values hover around 0.15          // Average relevance values hover around 0.15
670          $ranking[] = '%d * i.relevance';          $ranking[] = '%d * i.relevance';
671          $arguments2[] = $weight;          $arguments2[] = $weight;
672            $total += $weight;
673        }        }
674        if ($weight = (int)variable_get('node_rank_recent', 5)) {        if ($weight = (int)variable_get('node_rank_recent', 5)) {
675          // 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 678  function node_search($op = 'search', $ke
678          $arguments2[] = (int)variable_get('node_cron_last', 0);          $arguments2[] = (int)variable_get('node_cron_last', 0);
679          $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';
680          $stats_join = true;          $stats_join = true;
681            $total += $weight;
682        }        }
683        if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {        if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
684          // 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 689  function node_search($op = 'search', $ke
689          if (!$stats_join) {          if (!$stats_join) {
690            $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';            $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
691          }          }
692            $total += $weight;
693        }        }
694        if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&        if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&
695            $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 699  function node_search($op = 'search', $ke
699          $arguments2[] = $weight;          $arguments2[] = $weight;
700          $arguments2[] = $scale;          $arguments2[] = $scale;
701          $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';          $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
702            $total += $weight;
703        }        }
704        $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') . ' AS score';        $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') . ' AS score';
705    
# Line 727  function node_search($op = 'search', $ke Line 734  function node_search($op = 'search', $ke
734                             'date' => $node->changed,                             'date' => $node->changed,
735                             'node' => $node,                             'node' => $node,
736                             'extra' => $extra,                             'extra' => $extra,
737                               'score' => $item->score / $total,
738                             'snippet' => search_excerpt($keys, $node->body));                             'snippet' => search_excerpt($keys, $node->body));
739        }        }
740        return $results;        return $results;
# Line 805  function node_link($type, $node = 0, $ma Line 813  function node_link($type, $node = 0, $ma
813    $links = array();    $links = array();
814    
815    if ($type == 'node') {    if ($type == 'node') {
     if (array_key_exists('links', $node)) {  
       $links = $node->links;  
     }  
   
816      if ($main == 1 && $node->teaser && $node->readmore) {      if ($main == 1 && $node->teaser && $node->readmore) {
817        $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'));
818      }      }
# Line 847  function node_menu($may_cache) { Line 851  function node_menu($may_cache) {
851      $items[] = array('path' => 'node', 'title' => t('content'),      $items[] = array('path' => 'node', 'title' => t('content'),
852        'callback' => 'node_page',        'callback' => 'node_page',
853        'access' => user_access('access content'),        'access' => user_access('access content'),
854        'type' => MENU_SUGGESTED_ITEM);        'type' => MENU_MODIFIABLE_BY_ADMIN);
855      $items[] = array('path' => 'node/add', 'title' => t('create content'),      $items[] = array('path' => 'node/add', 'title' => t('create content'),
856        'callback' => 'node_page',        'callback' => 'node_page',
857        'access' => user_access('access content'),        'access' => user_access('access content'),
# Line 884  function node_menu($may_cache) { Line 888  function node_menu($may_cache) {
888            'access' => $revisions_access,            'access' => $revisions_access,
889            'weight' => 2,            'weight' => 2,
890            'type' => MENU_LOCAL_TASK);            'type' => MENU_LOCAL_TASK);
891            $items[] = array('path' => 'node/'. arg(1) .'/revisions/' . arg(3) . '/delete',
892              'title' => t('revisions'),
893              'callback' => 'node_revisions',
894              'access' => $revisions_access,
895              'weight' => 2,
896              'type' => MENU_CALLBACK);
897            $items[] = array('path' => 'node/'. arg(1) .'/revisions/' . arg(3) . '/revert',
898              'title' => t('revisions'),
899              'callback' => 'node_revisions',
900              'access' => $revisions_access,
901              'weight' => 2,
902              'type' => MENU_CALLBACK);
903        }        }
904      }      }
905      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 923  function node_last_changed($nid) {
923  function node_operations() {  function node_operations() {
924    $operations = array(    $operations = array(
925      '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'),
926      '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'),
927      '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'),
928      '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'),
929      '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 1110  function node_admin_nodes_submit($form_i
1110          db_query($operation, $nid);          db_query($operation, $nid);
1111        }        }
1112      }      }
1113        cache_clear_all();
1114      drupal_set_message(t('The update has been performed.'));      drupal_set_message(t('The update has been performed.'));
1115    }    }
1116  }  }
# Line 1307  function node_revision_revert($nid, $rev Line 1324  function node_revision_revert($nid, $rev
1324    $node = node_load($nid, $revision);    $node = node_load($nid, $revision);
1325    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)) {
1326      if ($node->vid) {      if ($node->vid) {
1327        $node->revision = 1;        $form = array();
1328        $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);
1329        $node->taxonomy = array_keys($node->taxonomy);        $form['vid'] = array('#type' => 'value', '#value' => $node->vid);
1330          return confirm_form('node_revision_revert_confirm', $form,
1331        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)))),
1332                         "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))));  
1333      }      }
1334      else {      else {
1335        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 1339  function node_revision_revert($nid, $rev
1339    drupal_access_denied();    drupal_access_denied();
1340  }  }
1341    
1342    function node_revision_revert_confirm_submit($form_id, $form_values) {
1343      $nid = $form_values['nid'];
1344      $revision = $form_values['vid'];
1345      $node = node_load($nid, $revision);
1346      $node->revision = 1;
1347      $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
1348      if (module_exist('taxonomy')) {
1349        $node->taxonomy = array_keys($node->taxonomy);
1350      }
1351    
1352      node_save($node);
1353      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)))));
1354      watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
1355      return 'node/'. $nid .'/revisions';
1356    }
1357    
1358  /**  /**
1359   * 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
1360   * revision is deleted.   * revision is deleted.
# Line 1335  function node_revision_delete($nid, $rev Line 1366  function node_revision_delete($nid, $rev
1366        // Don't delete the current revision        // Don't delete the current revision
1367        if ($revision != $node->vid) {        if ($revision != $node->vid) {
1368          $node = node_load($nid, $revision);          $node = node_load($nid, $revision);
1369            $form = array();
1370          db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);          $form['nid'] = array('#type' => 'value', '#value' => $nid);
1371          node_invoke_nodeapi($node, 'delete revision');          $form['vid'] = array('#type' => 'value', '#value' => $revision);
1372          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,
1373          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))),
1374                         "node/$nid/revisions", '', t('Delete'), t('Cancel'));
1375        }        }
   
1376        else {        else {
1377          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.'));
1378        }        }
# Line 1353  function node_revision_delete($nid, $rev Line 1384  function node_revision_delete($nid, $rev
1384        }        }
1385      }      }
1386    }    }
   
1387    drupal_access_denied();    drupal_access_denied();
1388  }  }
1389    
1390    function node_revision_delete_confirm_submit($form_id, $form_values) {
1391      $node = node_load($form_values['nid'], $form_values['vid']);
1392      db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
1393      node_invoke_nodeapi($node, 'delete revision');
1394      drupal_set_message(t('Deleted %title revision %revision.', array('%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $node->vid))));
1395      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))));
1396    
1397      if (db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d', $node->nid)) > 1) {
1398        return "node/$node->nid/revisions";
1399      }
1400      return "node/$node->nid";
1401    }
1402    
1403  /**  /**
1404   * Return a list of all the existing revision numbers.   * Return a list of all the existing revision numbers.
1405   */   */
# Line 1404  function node_feed($nodes = 0, $channel Line 1447  function node_feed($nodes = 0, $channel
1447    global $base_url, $locale;    global $base_url, $locale;
1448    
1449    if (!$nodes) {    if (!$nodes) {
1450      $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));
1451    }    }
1452    
1453    $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 1473  function node_feed($nodes = 0, $channel
1473        node_invoke_nodeapi($item, 'view', $teaser, FALSE);        node_invoke_nodeapi($item, 'view', $teaser, FALSE);
1474      }      }
1475    
1476        // Allow modules to add additional item fields
1477        $extra = node_invoke_nodeapi($item, 'rss item');
1478        $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'))));
1479        foreach ($extra as $element) {
1480          if ($element['namespace']) {
1481            $namespaces = array_merge($namespaces, $element['namespace']);
1482          }
1483        }
1484    
1485      // Prepare the item description      // Prepare the item description
1486      switch ($item_length) {      switch ($item_length) {
1487        case 'fulltext':        case 'fulltext':
# Line 1446  function node_feed($nodes = 0, $channel Line 1498  function node_feed($nodes = 0, $channel
1498          break;          break;
1499      }      }
1500    
     // 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']);  
       }  
     }  
1501      $items .= format_rss_item($item->title, $link, $item_text, $extra);      $items .= format_rss_item($item->title, $link, $item_text, $extra);
1502    }    }
1503    
# Line 1471  function node_feed($nodes = 0, $channel Line 1515  function node_feed($nodes = 0, $channel
1515    $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']);
1516    $output .= "</rss>\n";    $output .= "</rss>\n";
1517    
1518    drupal_set_header('Content-Type: text/xml; charset=utf-8');    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
1519    print $output;    print $output;
1520  }  }
1521    
# Line 1533  function node_validate($node, $form = ar Line 1577  function node_validate($node, $form = ar
1577    }    }
1578    
1579    if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {    if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
1580      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.'));
1581    }    }
1582    
1583    if (user_access('administer nodes')) {    if (user_access('administer nodes')) {
# Line 1597  function node_form_array($node) { Line 1641  function node_form_array($node) {
1641     * Basic node information.     * Basic node information.
1642     * 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.
1643     */     */
1644    foreach (array('nid', 'vid', 'uid', 'created', 'changed', 'type') as $key) {    foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
1645      $form[$key] = array('#type' => 'value', '#value' => $node->$key);      $form[$key] = array('#type' => 'value', '#value' => $node->$key);
1646    }    }
1647    
1648      // Changed must be sent to the client, for later overwrite error checking.
1649      $form['changed'] = array('#type' => 'hidden', '#default_value' => $node->changed);
1650    
1651    // Get the node-specific bits.    // Get the node-specific bits.
1652    $form = array_merge_recursive($form, node_invoke($node, 'form'));    $form = array_merge_recursive($form, node_invoke($node, 'form'));
1653    if (!isset($form['title']['#weight'])) {    if (!isset($form['title']['#weight'])) {
# Line 1659  function node_form_array($node) { Line 1706  function node_form_array($node) {
1706    return $form;    return $form;
1707  }  }
1708    
1709  function node_form_add_preview($form, $edit) {  function node_form_add_preview($form) {
1710      global $form_values;
1711    
1712    $op = isset($_POST['op']) ? $_POST['op'] : '';    $op = isset($_POST['op']) ? $_POST['op'] : '';
1713    if ($op == t('Preview')) {    if ($op == t('Preview')) {
1714      drupal_validate_form($form['form_id']['#value'], $form);      drupal_validate_form($form['form_id']['#value'], $form);
1715      if (!form_get_errors()) {      if (!form_get_errors()) {
1716        $form['node_preview'] = array('#value' => node_preview((object)$edit), '#weight' => -100);        // We pass the global $form_values here to preserve changes made during form validation
1717          $form['node_preview'] = array('#value' => node_preview((object)$form_values), '#weight' => -100);
1718      }      }
1719    }    }
1720    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 1724  function node_form_add_preview($form, $e
1724  }  }
1725    
1726  function theme_node_form($form) {  function theme_node_form($form) {
1727    $output = '<div class="node-form">';    $output = "\n<div class=\"node-form\">\n";
1728    if (isset($form['node_preview'])) {    if (isset($form['node_preview'])) {
1729      $output .= form_render($form['node_preview']);      $output .= form_render($form['node_preview']);
1730    }    }
1731    
1732    $output .= '  <div class="standard">';    // Admin form fields and submit buttons must be rendered first, because
1733      // they need to go to the bottom of the form, and so should not be part of
1734      // the catch-all call to form_render().
1735      $admin = '';
1736      if (isset($form['author'])) {
1737        $admin .= "    <div class=\"authored\">\n";
1738        $admin .= form_render($form['author']);
1739        $admin .= "    </div>\n";
1740      }
1741      if (isset($form['options'])) {
1742        $admin .= "    <div class=\"options\">\n";
1743        $admin .= form_render($form['options']);
1744        $admin .= "    </div>\n";
1745      }
1746      $buttons = form_render($form['preview']);
1747      $buttons .= form_render($form['submit']);
1748      $buttons .= isset($form['delete']) ? form_render($form['delete']) : '';
1749    
1750      // Everything else gets rendered here, and is displayed before the admin form
1751      // field and the submit buttons.
1752      $output .= "  <div class=\"standard\">\n";
1753    $output .= form_render($form);    $output .= form_render($form);
1754    $output .= '  </div>';    $output .= "  </div>\n";
1755    $output .= '  <div class="admin">';  
1756    $output .= '    <div class="authored">';    if (!empty($admin)) {
1757    $output .= form_render($form['author']);      $output .= "  <div class=\"admin\">\n";
1758    $output .= '    </div>';      $output .= $admin;
1759    $output .= '    <div class="options">';      $output .= "  </div>\n";
1760    $output .= form_render($form['options']);    }
1761    $output .= '    </div>';    $output .= $buttons;
1762    $output .= '  </div>';    $output .= "</div>\n";
1763    $output .= '</div>';  
1764    return $output;    return $output;
1765  }  }
1766    
# Line 1711  function node_add($type) { Line 1781  function node_add($type) {
1781    else {    else {
1782      // 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.
1783      foreach (node_get_types() as $type => $name) {      foreach (node_get_types() as $type => $name) {
1784        if (module_invoke(node_get_base($type), 'access', 'create', $type)) {        if (node_access('create', $type)) {
1785          $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>';
1786          $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';          $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
1787          $item[$name] = $out;          $item[$name] = $out;
# Line 1719  function node_add($type) { Line 1789  function node_add($type) {
1789      }      }
1790    
1791      if (isset($item)) {      if (isset($item)) {
1792        uasort($item, 'strnatcasecmp');        uksort($item, 'strnatcasecmp');
1793        $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>';
1794      }      }
1795      else {      else {
# Line 1810  function node_form_submit($form_id, $edi Line 1880  function node_form_submit($form_id, $edi
1880    if ($node->nid) {    if ($node->nid) {
1881      // Check whether the current user has the proper access rights to      // Check whether the current user has the proper access rights to
1882      // perform this operation:      // perform this operation:
1883      if (node_access('update', $node)) {      $original_node = node_load($node->nid); //check access rights using the unmodified node
1884        if (node_access('update', $original_node)) {
1885        node_save($node);        node_save($node);
1886        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));
1887        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 1993  function node_revisions() {
1993          }          }
1994          break;          break;
1995        case 'revert':        case 'revert':
1996          node_revision_revert(arg(1), arg(3));          return node_revision_revert(arg(1), arg(3));
1997          break;          break;
1998        case 'delete':        case 'delete':
1999          node_revision_delete(arg(1), arg(3));          return node_revision_delete(arg(1), arg(3));
2000          break;          break;
2001      }      }
2002    }    }
# Line 1951  function node_page_default() { Line 2022  function node_page_default() {
2022      $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));      $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
2023    }    }
2024    else {    else {
2025      $output = t("      $output = t('
2026        <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>
2027        <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>
2028        <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>
2029        <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>
2030        <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>
2031              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.
2032            </li>
2033            <li>
2034              <strong>Configure your website</strong>
2035              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.
2036            </li>
2037            <li>
2038              <strong>Enable additional functionality</strong>
2039              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>.
2040            </li>
2041            <li>
2042              <strong>Customize your website design</strong>
2043              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>.
2044            </li>
2045            <li>
2046              <strong>Start posting content</strong>
2047              Finally, you can <a href="%content">create content</a> for your website. This message will disappear once you have published your first post.
2048            </li>
2049          </ol>
2050          <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>',
2051          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')
2052        );
2053        $output = '<div id="first-time">'. $output .'</div>';
2054    }    }
2055    
2056    return $output;    return $output;
# Line 2049  function node_update_index() { Line 2143  function node_update_index() {
2143    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}'))));
2144    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}'))));
2145    
2146    $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);
2147    
2148    while ($node = db_fetch_object($result)) {    while ($node = db_fetch_object($result)) {
2149      $last_change = $node->last_change;      $last_change = $node->last_change;

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

  ViewVC Help
Powered by ViewVC 1.1.2