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

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

  ViewVC Help
Powered by ViewVC 1.1.2