Commit 1909326e authored by Gábor Hojtsy's avatar Gábor Hojtsy

#202382 by Pasqualle and Pancho: phpdoc improvements and code style fixes in node module

parent 518c5691
......@@ -16,9 +16,15 @@ function node_configure() {
$status = '<p>'. t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Possible causes for permission problems are disabling modules or configuration changes to permissions. Rebuilding will remove all privileges to posts, and replace them with permissions based on the current modules and settings.') .'</p>';
$status .= '<p>'. t('Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed posts will automatically use the new permissions.') .'</p>';
$form['access'] = array('#type' => 'fieldset', '#title' => t('Node access status'));
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Node access status'),
);
$form['access']['status'] = array('#value' => $status);
$form['access']['rebuild'] = array('#type' => 'submit', '#value' => t('Rebuild permissions'));
$form['access']['rebuild'] = array(
'#type' => 'submit',
'#value' => t('Rebuild permissions'),
);
}
$form['default_nodes_main'] = array(
......@@ -28,15 +34,28 @@ function node_configure() {
);
$form['teaser_length'] = array(
'#type' => 'select', '#title' => t('Length of trimmed posts'), '#default_value' => variable_get('teaser_length', 600),
'#options' => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
'#options' => array(
0 => t('Unlimited'),
200 => t('200 characters'),
400 => t('400 characters'),
600 => t('600 characters'),
800 => t('800 characters'),
1000 => t('1000 characters'),
1200 => t('1200 characters'),
1400 => t('1400 characters'),
1600 => t('1600 characters'),
1800 => t('1800 characters'),
2000 => t('2000 characters'),
),
'#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
);
$form['node_preview'] = array(
'#type' => 'radios', '#title' => t('Preview post'), '#default_value' => variable_get('node_preview', 0),
'#options' => array(t('Optional'), t('Required')), '#description' => t('Must users preview posts before submitting?')
'#type' => 'radios',
'#title' => t('Preview post'),
'#default_value' => variable_get('node_preview', 0),
'#options' => array(t('Optional'), t('Required')),
'#description' => t('Must users preview posts before submitting?'),
);
$form['#validate'] = array('node_configure_validate');
......@@ -118,14 +137,23 @@ function node_node_operations() {
*/
function node_filters() {
// Regular filters
$filters['status'] = array('title' => t('status'),
'options' => array('status-1' => t('published'), 'status-0' => t('not published'),
'promote-1' => t('promoted'), 'promote-0' => t('not promoted'),
'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))
$filters['status'] = array(
'title' => t('status'),
'options' => array(
'status-1' => t('published'),
'status-0' => t('not published'),
'promote-1' => t('promoted'),
'promote-0' => t('not promoted'),
'sticky-1' => t('sticky'),
'sticky-0' => t('not sticky'),
),
);
// Include translation states if we have this module enabled
if (module_exists('translation')) {
$filters['status']['options'] += array('translate-0' => t('up to date translation'), 'translate-1' => t('outdated translation'));
$filters['status']['options'] += array(
'translate-0' => t('Up to date translation'),
'translate-1' => t('Outdated translation'),
);
}
$filters['type'] = array('title' => t('type'), 'options' => node_get_types('names'));
......@@ -187,7 +215,8 @@ function node_filter_form() {
$filters = node_filters();
$i = 0;
$form['filters'] = array('#type' => 'fieldset',
$form['filters'] = array(
'#type' => 'fieldset',
'#title' => t('Show only items where'),
'#theme' => 'node_filters',
);
......@@ -310,41 +339,6 @@ function node_filter_form_submit($form, &$form_state) {
}
}
/**
* Submit the node administration update form.
*/
function node_admin_nodes_submit($form, &$form_state) {
$operations = module_invoke_all('node_operations');
$operation = $operations[$form_state['values']['operation']];
// Filter out unchecked nodes
$nodes = array_filter($form_state['values']['nodes']);
if ($function = $operation['callback']) {
// Add in callback arguments if present.
if (isset($operation['callback arguments'])) {
$args = array_merge(array($nodes), $operation['callback arguments']);
}
else {
$args = array($nodes);
}
call_user_func_array($function, $args);
cache_clear_all();
}
else {
// We need to rebuild the form to go to a second step. For example, to
// show the confirmation form for the deletion of nodes.
$form_state['rebuild'] = TRUE;
}
}
function node_admin_nodes_validate($form, &$form_state) {
$nodes = array_filter($form_state['values']['nodes']);
if (count($nodes) == 0) {
form_set_error('', t('No items selected.'));
}
}
/**
* Make mass update of nodes, changing all nodes in the $nodes array
* to update them with the field values in $updates.
......@@ -459,6 +453,9 @@ function node_admin_content($form_state) {
return $form;
}
/**
* Form builder: Builds the node administration overview.
*/
function node_admin_nodes() {
$filter = node_build_filter_query();
......@@ -469,7 +466,8 @@ function node_admin_nodes() {
$count = db_result(db_query("SELECT COUNT(*) FROM {node} n WHERE language != ''"));
$multilanguage = (module_exists('locale') || $count);
$form['options'] = array('#type' => 'fieldset',
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Update options'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
......@@ -478,7 +476,11 @@ function node_admin_nodes() {
foreach (module_invoke_all('node_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'approve');
$form['options']['operation'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => 'approve',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
......@@ -506,6 +508,49 @@ function node_admin_nodes() {
return $form;
}
/**
* Validate node_admin_nodes form submissions.
*
* Check if any nodes have been selected to perform the chosen
* 'Update option' on.
*/
function node_admin_nodes_validate($form, &$form_state) {
$nodes = array_filter($form_state['values']['nodes']);
if (count($nodes) == 0) {
form_set_error('', t('No items selected.'));
}
}
/**
* Process node_admin_nodes form submissions.
*
* Execute the chosen 'Update option' on the selected nodes.
*/
function node_admin_nodes_submit($form, &$form_state) {
$operations = module_invoke_all('node_operations');
$operation = $operations[$form_state['values']['operation']];
// Filter out unchecked nodes
$nodes = array_filter($form_state['values']['nodes']);
if ($function = $operation['callback']) {
// Add in callback arguments if present.
if (isset($operation['callback arguments'])) {
$args = array_merge(array($nodes), $operation['callback arguments']);
}
else {
$args = array($nodes);
}
call_user_func_array($function, $args);
cache_clear_all();
}
else {
// We need to rebuild the form to go to a second step. For example, to
// show the confirmation form for the deletion of nodes.
$form_state['rebuild'] = TRUE;
}
}
/**
* Theme node administration overview.
*
......@@ -560,7 +605,12 @@ function node_multiple_delete_confirm(&$form_state, $nodes) {
// array_filter returns only elements with TRUE values
foreach ($nodes as $nid => $value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
$form['nodes'][$nid] = array('#type' => 'hidden', '#value' => $nid, '#prefix' => '<li>', '#suffix' => check_plain($title) ."</li>\n");
$form['nodes'][$nid] = array(
'#type' => 'hidden',
'#value' => $nid,
'#prefix' => '<li>',
'#suffix' => check_plain($title) ."</li>\n",
);
}
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
$form['#submit'][] = 'node_multiple_delete_confirm_submit';
......
......@@ -780,7 +780,7 @@ function node_validate($node, $form = array()) {
$type = node_get_types('type', $node);
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
// TODO : use a better word counting algorithm that will work in other languages
if (!empty($type->min_word_count) && isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
form_set_error('body', t('The body of your @type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@type' => $type->name)));
}
......@@ -903,8 +903,7 @@ function node_save(&$node) {
$node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT;
$update_node = TRUE;
//Generate the node table query and the
//the node_revisions table query
// Generate the node table query and the node_revisions table query.
if ($node->is_new) {
drupal_write_record('node', $node);
_node_save_revision($node, $user->uid);
......@@ -925,7 +924,7 @@ function node_save(&$node) {
db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid);
}
// Call the node specific callback (if any):
// Call the node specific callback (if any).
node_invoke($node, $op);
node_invoke_nodeapi($node, $op);
......@@ -936,7 +935,6 @@ function node_save(&$node) {
cache_clear_all();
}
/**
* Helper function to save a revision with the uid of the current user.
*
......@@ -1277,15 +1275,17 @@ function node_search($op = 'search', $keys = NULL) {
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
$extra = node_invoke_nodeapi($node, 'search result');
$results[] = array('link' => url('node/'. $item->sid, array('absolute' => TRUE)),
'type' => check_plain(node_get_types('name', $node)),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
'node' => $node,
'extra' => $extra,
'score' => $item->score / $total,
'snippet' => search_excerpt($keys, $node->body));
$results[] = array(
'link' => url('node/'. $item->sid, array('absolute' => TRUE)),
'type' => check_plain(node_get_types('name', $node)),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
'node' => $node,
'extra' => $extra,
'score' => $item->score / $total,
'snippet' => search_excerpt($keys, $node->body),
);
}
return $results;
}
......@@ -1575,6 +1575,9 @@ function node_page_title($node) {
return $node->title;
}
/**
* Implementation of hook_init().
*/
function node_init() {
drupal_add_css(drupal_get_path('module', 'node') .'/node.css');
}
......
......@@ -361,7 +361,7 @@ function theme_node_form($form) {
*/
function node_preview($node) {
if (node_access('create', $node) || node_access('update', $node)) {
// Load the user's name when needed:
// Load the user's name when needed.
if (isset($node->name)) {
// The use of isset() is mandatory in the context of user IDs, because
// user ID 0 denotes the anonymous user.
......@@ -391,7 +391,7 @@ function node_preview($node) {
}
}
// Display a preview of the node:
// Display a preview of the node.
// Previewing alters $node so it needs to be cloned.
if (!form_get_errors()) {
$cloned_node = drupal_clone($node);
......@@ -514,7 +514,6 @@ function node_delete_confirm_submit($form, &$form_state) {
}
$form_state['redirect'] = '<front>';
return;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment