2007-08-20 07:03:08 +00:00
< ? php
// $Id$
/**
* @ file
* Content administration and module settings UI .
*/
/**
* Menu callback : confirm rebuilding of permissions .
*/
function node_configure_rebuild_confirm () {
2007-11-12 19:06:33 +00:00
return confirm_form ( array (), t ( 'Are you sure you want to rebuild the permissions on site content?' ),
2009-07-06 13:52:57 +00:00
'admin/reports/status' , t ( 'This action rebuilds all permissions on site content, and may be a lengthy process. This action cannot be undone.' ), t ( 'Rebuild permissions' ), t ( 'Cancel' ));
2007-08-20 07:03:08 +00:00
}
/**
* Handler for wipe confirmation
*/
2007-08-29 19:56:09 +00:00
function node_configure_rebuild_confirm_submit ( $form , & $form_state ) {
2007-09-02 14:42:30 +00:00
node_access_rebuild ( TRUE );
2009-06-05 05:28:28 +00:00
$form_state [ 'redirect' ] = 'admin/reports/status' ;
2007-08-20 07:03:08 +00:00
}
/**
2009-05-27 18:34:03 +00:00
* Implement hook_node_operations () .
2007-08-20 07:03:08 +00:00
*/
function node_node_operations () {
$operations = array (
'publish' => array (
'label' => t ( 'Publish' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED )),
2007-08-20 07:03:08 +00:00
),
'unpublish' => array (
'label' => t ( 'Unpublish' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_NOT_PUBLISHED )),
2007-08-20 07:03:08 +00:00
),
'promote' => array (
'label' => t ( 'Promote to front page' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED , 'promote' => NODE_PROMOTED )),
2007-08-20 07:03:08 +00:00
),
'demote' => array (
'label' => t ( 'Demote from front page' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'promote' => NODE_NOT_PROMOTED )),
2007-08-20 07:03:08 +00:00
),
'sticky' => array (
'label' => t ( 'Make sticky' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'status' => NODE_PUBLISHED , 'sticky' => NODE_STICKY )),
2007-08-20 07:03:08 +00:00
),
'unsticky' => array (
'label' => t ( 'Remove stickiness' ),
2007-10-03 17:35:22 +00:00
'callback' => 'node_mass_update' ,
2009-09-05 06:53:01 +00:00
'callback arguments' => array ( 'updates' => array ( 'sticky' => NODE_NOT_STICKY )),
2007-08-20 07:03:08 +00:00
),
'delete' => array (
'label' => t ( 'Delete' ),
'callback' => NULL ,
),
);
return $operations ;
}
/**
* List node administration filters that can be applied .
*/
function node_filters () {
// Regular filters
2008-01-29 11:08:17 +00:00
$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' ),
),
2007-08-20 07:03:08 +00:00
);
// Include translation states if we have this module enabled
if ( module_exists ( 'translation' )) {
2008-01-29 11:08:17 +00:00
$filters [ 'status' ][ 'options' ] += array (
'translate-0' => t ( 'Up to date translation' ),
'translate-1' => t ( 'Outdated translation' ),
);
2007-08-20 07:03:08 +00:00
}
2009-06-04 03:33:29 +00:00
$filters [ 'type' ] = array ( 'title' => t ( 'type' ), 'options' => node_type_get_names ());
2007-08-20 07:03:08 +00:00
// The taxonomy filter
if ( $taxonomy = module_invoke ( 'taxonomy' , 'form_all' , 1 )) {
2008-11-22 14:09:41 +00:00
$filters [ 'term' ] = array ( 'title' => t ( 'term' ), 'options' => $taxonomy );
2007-08-20 07:03:08 +00:00
}
// Language filter if there is a list of languages
if ( $languages = module_invoke ( 'locale' , 'language_list' )) {
$languages = array ( '' => t ( 'Language neutral' )) + $languages ;
$filters [ 'language' ] = array ( 'title' => t ( 'language' ), 'options' => $languages );
}
return $filters ;
}
/**
2009-07-21 01:36:51 +00:00
* Apply filters for node administration filters based on session .
*
* @ param $query
* A SelectQuery to which the filters should be applied .
2007-08-20 07:03:08 +00:00
*/
2009-07-21 01:36:51 +00:00
function node_build_filter_query ( SelectQueryInterface $query ) {
2007-08-20 07:03:08 +00:00
// Build query
2009-06-02 06:58:17 +00:00
$filter_data = isset ( $_SESSION [ 'node_overview_filter' ]) ? $_SESSION [ 'node_overview_filter' ] : array ();
2009-07-21 01:36:51 +00:00
$counter = 0 ;
2009-06-02 06:58:17 +00:00
foreach ( $filter_data as $index => $filter ) {
2007-08-20 07:03:08 +00:00
list ( $key , $value ) = $filter ;
switch ( $key ) {
2009-07-21 01:36:51 +00:00
case 'term' :
$index = 'tn' . $counter ++ ;
$query -> join ( 'taxonomy_term_node' , $index , " n.nid = $index .nid " );
$query -> condition ( $index . '.tid' , $value );
break ;
2007-08-20 07:03:08 +00:00
case 'status' :
// Note: no exploitable hole as $key/$value have already been checked when submitted
list ( $key , $value ) = explode ( '-' , $value , 2 );
case 'type' :
case 'language' :
2009-07-21 01:36:51 +00:00
$query -> condition ( 'n.' . $key , $value );
2007-11-12 17:26:16 +00:00
break ;
2007-08-20 07:03:08 +00:00
}
}
}
/**
* Return form for node administration filters .
*/
function node_filter_form () {
2009-06-02 06:58:17 +00:00
$session = isset ( $_SESSION [ 'node_overview_filter' ]) ? $_SESSION [ 'node_overview_filter' ] : array ();
2007-08-20 07:03:08 +00:00
$filters = node_filters ();
$i = 0 ;
2008-01-29 11:08:17 +00:00
$form [ 'filters' ] = array (
'#type' => 'fieldset' ,
2007-08-20 07:03:08 +00:00
'#title' => t ( 'Show only items where' ),
'#theme' => 'node_filters' ,
);
foreach ( $session as $filter ) {
list ( $type , $value ) = $filter ;
2008-11-22 14:09:41 +00:00
if ( $type == 'term' ) {
2007-08-20 07:03:08 +00:00
// Load term name from DB rather than search and parse options array.
2009-01-08 01:16:57 +00:00
$value = module_invoke ( 'taxonomy' , 'term_load' , $value );
2007-08-20 07:03:08 +00:00
$value = $value -> name ;
}
2008-10-12 04:30:09 +00:00
elseif ( $type == 'language' ) {
2007-08-20 07:03:08 +00:00
$value = empty ( $value ) ? t ( 'Language neutral' ) : module_invoke ( 'locale' , 'language_name' , $value );
}
else {
$value = $filters [ $type ][ 'options' ][ $value ];
}
if ( $i ++ ) {
2009-08-23 04:37:52 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( '<em>and</em> where <strong>%type</strong> is <strong>%value</strong>' , array ( '%type' => $filters [ $type ][ 'title' ], '%value' => $value )));
2007-08-20 07:03:08 +00:00
}
else {
2009-08-23 04:37:52 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( '<strong>%type</strong> is <strong>%value</strong>' , array ( '%type' => $filters [ $type ][ 'title' ], '%value' => $value )));
2007-08-20 07:03:08 +00:00
}
if ( in_array ( $type , array ( 'type' , 'language' ))) {
// Remove the option if it is already being filtered on.
unset ( $filters [ $type ]);
}
}
foreach ( $filters as $key => $filter ) {
$names [ $key ] = $filter [ 'title' ];
$form [ 'filters' ][ 'status' ][ $key ] = array ( '#type' => 'select' , '#options' => $filter [ 'options' ]);
}
$form [ 'filters' ][ 'filter' ] = array ( '#type' => 'radios' , '#options' => $names , '#default_value' => 'status' );
$form [ 'filters' ][ 'buttons' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => ( count ( $session ) ? t ( 'Refine' ) : t ( 'Filter' )));
if ( count ( $session )) {
$form [ 'filters' ][ 'buttons' ][ 'undo' ] = array ( '#type' => 'submit' , '#value' => t ( 'Undo' ));
$form [ 'filters' ][ 'buttons' ][ 'reset' ] = array ( '#type' => 'submit' , '#value' => t ( 'Reset' ));
}
2008-11-10 05:23:01 +00:00
drupal_add_js ( 'misc/form.js' );
2007-08-20 07:03:08 +00:00
return $form ;
}
/**
* Theme node administration filter form .
2007-12-06 09:58:34 +00:00
*
* @ ingroup themeable
2007-08-20 07:03:08 +00:00
*/
function theme_node_filter_form ( $form ) {
$output = '' ;
$output .= '<div id="node-admin-filter">' ;
$output .= drupal_render ( $form [ 'filters' ]);
$output .= '</div>' ;
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-08-20 07:03:08 +00:00
return $output ;
}
/**
* Theme node administration filter selector .
2007-12-06 09:58:34 +00:00
*
* @ ingroup themeable
2007-08-20 07:03:08 +00:00
*/
function theme_node_filters ( $form ) {
$output = '' ;
2009-02-18 14:28:25 +00:00
$output .= '<ul class="clearfix">' ;
2007-08-20 07:03:08 +00:00
if ( ! empty ( $form [ 'current' ])) {
foreach ( element_children ( $form [ 'current' ]) as $key ) {
2008-04-14 17:48:46 +00:00
$output .= '<li>' . drupal_render ( $form [ 'current' ][ $key ]) . '</li>' ;
2007-08-20 07:03:08 +00:00
}
}
2008-04-14 17:48:46 +00:00
$output .= '<li><dl class="multiselect">' . ( ! empty ( $form [ 'current' ]) ? '<dt><em>' . t ( 'and' ) . '</em> ' . t ( 'where' ) . '</dt>' : '' ) . '<dd class="a">' ;
2007-08-20 07:03:08 +00:00
foreach ( element_children ( $form [ 'filter' ]) as $key ) {
$output .= drupal_render ( $form [ 'filter' ][ $key ]);
}
$output .= '</dd>' ;
2008-04-14 17:48:46 +00:00
$output .= '<dt>' . t ( 'is' ) . '</dt><dd class="b">' ;
2007-08-20 07:03:08 +00:00
foreach ( element_children ( $form [ 'status' ]) as $key ) {
$output .= drupal_render ( $form [ 'status' ][ $key ]);
}
$output .= '</dd>' ;
$output .= '</dl>' ;
2008-04-14 17:48:46 +00:00
$output .= '<div class="container-inline" id="node-admin-buttons">' . drupal_render ( $form [ 'buttons' ]) . '</div>' ;
2007-08-20 07:03:08 +00:00
$output .= '</li></ul>' ;
return $output ;
}
/**
* Process result from node administration filter form .
*/
function node_filter_form_submit ( $form , & $form_state ) {
$filters = node_filters ();
switch ( $form_state [ 'values' ][ 'op' ]) {
case t ( 'Filter' ) :
case t ( 'Refine' ) :
if ( isset ( $form_state [ 'values' ][ 'filter' ])) {
$filter = $form_state [ 'values' ][ 'filter' ];
// Flatten the options array to accommodate hierarchical/nested options.
$flat_options = form_options_flatten ( $filters [ $filter ][ 'options' ]);
if ( isset ( $flat_options [ $form_state [ 'values' ][ $filter ]])) {
$_SESSION [ 'node_overview_filter' ][] = array ( $filter , $form_state [ 'values' ][ $filter ]);
}
}
break ;
case t ( 'Undo' ) :
array_pop ( $_SESSION [ 'node_overview_filter' ]);
break ;
case t ( 'Reset' ) :
2009-06-02 06:58:17 +00:00
$_SESSION [ 'node_overview_filter' ] = array ();
2007-08-20 07:03:08 +00:00
break ;
}
}
2007-12-20 09:08:35 +00:00
/**
* Make mass update of nodes , changing all nodes in the $nodes array
* to update them with the field values in $updates .
*
* IMPORTANT NOTE : This function is intended to work when called
* from a form submit handler . Calling it outside of the form submission
* process may not work correctly .
*
* @ param array $nodes
* Array of node nids to update .
* @ param array $updates
* Array of key / value pairs with node field names and the
* value to update that field to .
*/
function node_mass_update ( $nodes , $updates ) {
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if ( count ( $nodes ) > 10 ) {
$batch = array (
'operations' => array (
array ( '_node_mass_update_batch_process' , array ( $nodes , $updates ))
),
'finished' => '_node_mass_update_batch_finished' ,
'title' => t ( 'Processing' ),
// We use a single multi-pass operation, so the default
// 'Remaining x of y operations' message will be confusing here.
'progress_message' => '' ,
'error_message' => t ( 'The update has encountered an error.' ),
// The operations do not live in the .module file, so we need to
// tell the batch engine which file to load before calling them.
2008-04-14 17:48:46 +00:00
'file' => drupal_get_path ( 'module' , 'node' ) . '/node.admin.inc' ,
2007-12-20 09:08:35 +00:00
);
batch_set ( $batch );
}
else {
2007-12-28 12:02:52 +00:00
foreach ( $nodes as $nid ) {
2007-12-20 09:08:35 +00:00
_node_mass_update_helper ( $nid , $updates );
}
drupal_set_message ( t ( 'The update has been performed.' ));
}
}
/**
* Node Mass Update - helper function .
*/
function _node_mass_update_helper ( $nid , $updates ) {
$node = node_load ( $nid , NULL , TRUE );
foreach ( $updates as $name => $value ) {
$node -> $name = $value ;
}
node_save ( $node );
return $node ;
}
/**
* Node Mass Update Batch operation
*/
function _node_mass_update_batch_process ( $nodes , $updates , & $context ) {
if ( ! isset ( $context [ 'sandbox' ][ 'progress' ])) {
$context [ 'sandbox' ][ 'progress' ] = 0 ;
$context [ 'sandbox' ][ 'max' ] = count ( $nodes );
$context [ 'sandbox' ][ 'nodes' ] = $nodes ;
}
// Process nodes by groups of 5.
$count = min ( 5 , count ( $context [ 'sandbox' ][ 'nodes' ]));
for ( $i = 1 ; $i <= $count ; $i ++ ) {
// For each nid, load the node, reset the values, and save it.
$nid = array_shift ( $context [ 'sandbox' ][ 'nodes' ]);
$node = _node_mass_update_helper ( $nid , $updates );
// Store result for post-processing in the finished callback.
2008-04-14 17:48:46 +00:00
$context [ 'results' ][] = l ( $node -> title , 'node/' . $node -> nid );
2007-12-20 09:08:35 +00:00
// Update our progress information.
$context [ 'sandbox' ][ 'progress' ] ++ ;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ( $context [ 'sandbox' ][ 'progress' ] != $context [ 'sandbox' ][ 'max' ]) {
$context [ 'finished' ] = $context [ 'sandbox' ][ 'progress' ] / $context [ 'sandbox' ][ 'max' ];
}
}
/**
* Node Mass Update Batch 'finished' callback .
*/
function _node_mass_update_batch_finished ( $success , $results , $operations ) {
if ( $success ) {
drupal_set_message ( t ( 'The update has been performed.' ));
}
else {
drupal_set_message ( t ( 'An error occurred and processing did not complete.' ), 'error' );
$message = format_plural ( count ( $results ), '1 item successfully processed:' , '@count items successfully processed:' );
$message .= theme ( 'item_list' , $results );
drupal_set_message ( $message );
}
}
2007-08-20 07:03:08 +00:00
/**
* Menu callback : content administration .
*/
function node_admin_content ( $form_state ) {
if ( isset ( $form_state [ 'values' ][ 'operation' ]) && $form_state [ 'values' ][ 'operation' ] == 'delete' ) {
return node_multiple_delete_confirm ( $form_state , array_filter ( $form_state [ 'values' ][ 'nodes' ]));
}
2009-07-07 09:17:19 +00:00
// Show the 'add new content' link.
2009-08-23 01:05:12 +00:00
$form [ 'add_content' ] = array (
'#access' => _node_add_access (),
'#markup' => theme ( 'links' , array ( array ( 'title' => t ( 'Add new content' ), 'href' => 'node/add' )), array ( 'class' => array ( 'action-links' ))),
);
2009-07-07 09:17:19 +00:00
$form [] = node_filter_form ();
2009-08-23 04:37:52 +00:00
$form [ '#submit' ][] = 'node_filter_form_submit' ;
2008-02-03 19:39:52 +00:00
$form [ '#theme' ] = 'node_filter_form' ;
2008-09-15 00:02:10 +00:00
$form [ 'admin' ] = node_admin_nodes ();
2007-08-20 07:03:08 +00:00
return $form ;
}
2008-01-29 11:08:17 +00:00
/**
* Form builder : Builds the node administration overview .
*/
2007-08-20 07:03:08 +00:00
function node_admin_nodes () {
2008-09-15 00:02:10 +00:00
// Enable language column if translation module is enabled
// or if we have any node with language.
2009-05-25 13:42:56 +00:00
$multilanguage = ( module_exists ( 'translation' ) || db_query ( " SELECT COUNT(*) FROM { node} WHERE language <> '' " ) -> fetchField ());
2008-09-15 00:02:10 +00:00
// Build the sortable table header.
$header = array ();
$header [] = theme ( 'table_select_header_cell' );
$header [] = array ( 'data' => t ( 'Title' ), 'field' => 'n.title' );
$header [] = array ( 'data' => t ( 'Type' ), 'field' => 'n.type' );
$header [] = array ( 'data' => t ( 'Author' ), 'field' => 'u.name' );
$header [] = array ( 'data' => t ( 'Status' ), 'field' => 'n.status' );
$header [] = array ( 'data' => t ( 'Updated' ), 'field' => 'n.changed' , 'sort' => 'desc' );
if ( $multilanguage ) {
$header [] = array ( 'data' => t ( 'Language' ), 'field' => 'n.language' );
}
$header [] = array ( 'data' => t ( 'Operations' ));
2007-08-20 07:03:08 +00:00
2008-09-15 00:02:10 +00:00
$form [ 'header' ] = array (
'#type' => 'value' ,
'#value' => $header ,
);
2007-08-20 07:03:08 +00:00
2009-07-21 01:36:51 +00:00
$query = db_select ( 'node' , 'n' ) -> extend ( 'PagerDefault' ) -> extend ( 'TableSort' );
$query -> join ( 'users' , 'u' , 'n.uid = u.uid' );
node_build_filter_query ( $query );
2008-09-15 20:48:10 +00:00
2009-07-21 01:36:51 +00:00
$result = $query
-> fields ( 'n' )
-> fields ( 'u' , array ( 'name' ))
-> limit ( 50 )
-> execute ();
2008-09-15 20:48:10 +00:00
2008-09-15 00:02:10 +00:00
// Build the 'Update options' form.
2008-01-29 11:08:17 +00:00
$form [ 'options' ] = array (
'#type' => 'fieldset' ,
2007-08-20 07:03:08 +00:00
'#title' => t ( 'Update options' ),
'#prefix' => '<div class="container-inline">' ,
'#suffix' => '</div>' ,
);
$options = array ();
foreach ( module_invoke_all ( 'node_operations' ) as $operation => $array ) {
$options [ $operation ] = $array [ 'label' ];
}
2008-01-29 11:08:17 +00:00
$form [ 'options' ][ 'operation' ] = array (
'#type' => 'select' ,
'#options' => $options ,
'#default_value' => 'approve' ,
);
2007-08-20 07:03:08 +00:00
$form [ 'options' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Update' ),
'#submit' => array ( 'node_admin_nodes_submit' ),
);
2007-12-08 14:06:23 +00:00
$languages = language_list ();
2007-08-20 07:03:08 +00:00
$destination = drupal_get_destination ();
$nodes = array ();
2009-07-21 01:36:51 +00:00
foreach ( $result as $node ) {
2007-08-20 07:03:08 +00:00
$nodes [ $node -> nid ] = '' ;
2007-12-05 16:34:07 +00:00
$options = empty ( $node -> language ) ? array () : array ( 'language' => $languages [ $node -> language ]);
2008-07-16 21:59:29 +00:00
$form [ 'title' ][ $node -> nid ] = array ( '#markup' => l ( $node -> title , 'node/' . $node -> nid , $options ) . ' ' . theme ( 'mark' , node_mark ( $node -> nid , $node -> changed )));
2009-06-04 03:33:29 +00:00
$form [ 'name' ][ $node -> nid ] = array ( '#markup' => check_plain ( node_type_get_name ( $node )));
2008-07-16 21:59:29 +00:00
$form [ 'username' ][ $node -> nid ] = array ( '#markup' => theme ( 'username' , $node ));
$form [ 'status' ][ $node -> nid ] = array ( '#markup' => ( $node -> status ? t ( 'published' ) : t ( 'not published' )));
2009-08-25 10:27:15 +00:00
$form [ 'changed' ][ $node -> nid ] = array ( '#markup' => format_date ( $node -> changed , 'short' ));
2007-08-20 07:03:08 +00:00
if ( $multilanguage ) {
2008-07-16 21:59:29 +00:00
$form [ 'language' ][ $node -> nid ] = array ( '#markup' => empty ( $node -> language ) ? t ( 'Language neutral' ) : t ( $languages [ $node -> language ] -> name ));
2007-08-20 07:03:08 +00:00
}
2008-07-16 21:59:29 +00:00
$form [ 'operations' ][ $node -> nid ] = array ( '#markup' => l ( t ( 'edit' ), 'node/' . $node -> nid . '/edit' , array ( 'query' => $destination )));
2007-08-20 07:03:08 +00:00
}
2008-09-15 00:02:10 +00:00
$form [ 'nodes' ] = array (
'#type' => 'checkboxes' ,
'#options' => $nodes ,
);
2009-04-26 19:44:40 +00:00
$form [ 'pager' ] = array ( '#markup' => theme ( 'pager' , NULL ));
2007-08-20 07:03:08 +00:00
$form [ '#theme' ] = 'node_admin_nodes' ;
return $form ;
}
2008-01-29 11:08:17 +00:00
/**
* Validate node_admin_nodes form submissions .
2008-02-06 19:38:28 +00:00
*
2008-01-29 11:08:17 +00:00
* 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 .
2008-02-06 19:38:28 +00:00
*
2008-01-29 11:08:17 +00:00
* 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 {
2008-12-20 18:24:41 +00:00
// We need to rebuild the form to go to a second step. For example, to
2008-01-29 11:08:17 +00:00
// show the confirmation form for the deletion of nodes.
$form_state [ 'rebuild' ] = TRUE ;
}
}
2007-08-20 07:03:08 +00:00
/**
* Theme node administration overview .
2007-12-06 09:58:34 +00:00
*
* @ ingroup themeable
2007-08-20 07:03:08 +00:00
*/
function theme_node_admin_nodes ( $form ) {
$output = '' ;
$output .= drupal_render ( $form [ 'options' ]);
2008-09-15 00:02:10 +00:00
$header = $form [ 'header' ][ '#value' ];
$has_posts = isset ( $form [ 'title' ]) && is_array ( $form [ 'title' ]);
2007-10-24 09:15:04 +00:00
if ( $has_posts ) {
2008-09-15 00:02:10 +00:00
$rows = array ();
2007-08-20 07:03:08 +00:00
foreach ( element_children ( $form [ 'title' ]) as $key ) {
$row = array ();
$row [] = drupal_render ( $form [ 'nodes' ][ $key ]);
$row [] = drupal_render ( $form [ 'title' ][ $key ]);
$row [] = drupal_render ( $form [ 'name' ][ $key ]);
$row [] = drupal_render ( $form [ 'username' ][ $key ]);
$row [] = drupal_render ( $form [ 'status' ][ $key ]);
2008-09-15 00:02:10 +00:00
$row [] = drupal_render ( $form [ 'changed' ][ $key ]);
2007-08-20 07:03:08 +00:00
if ( isset ( $form [ 'language' ])) {
$row [] = drupal_render ( $form [ 'language' ][ $key ]);
}
$row [] = drupal_render ( $form [ 'operations' ][ $key ]);
$rows [] = $row ;
}
}
2007-12-22 23:24:26 +00:00
else {
2008-09-15 00:02:10 +00:00
$rows [] = array (
2009-03-17 03:34:32 +00:00
array ( 'data' => t ( 'No content available.' ), 'colspan' => count ( $header )),
2008-09-15 00:02:10 +00:00
);
2007-08-20 07:03:08 +00:00
}
$output .= theme ( 'table' , $header , $rows );
2008-09-15 20:48:10 +00:00
2008-07-16 21:59:29 +00:00
if ( $form [ 'pager' ][ '#markup' ]) {
2007-08-20 07:03:08 +00:00
$output .= drupal_render ( $form [ 'pager' ]);
}
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-08-20 07:03:08 +00:00
return $output ;
}
function node_multiple_delete_confirm ( & $form_state , $nodes ) {
$form [ 'nodes' ] = array ( '#prefix' => '<ul>' , '#suffix' => '</ul>' , '#tree' => TRUE );
// array_filter returns only elements with TRUE values
foreach ( $nodes as $nid => $value ) {
2009-04-25 16:33:48 +00:00
$title = db_query ( 'SELECT title FROM {node} WHERE nid = :nid' , array ( ':nid' => $nid )) -> fetchField ();
2008-01-29 11:08:17 +00:00
$form [ 'nodes' ][ $nid ] = array (
'#type' => 'hidden' ,
'#value' => $nid ,
'#prefix' => '<li>' ,
2008-04-14 17:48:46 +00:00
'#suffix' => check_plain ( $title ) . " </li> \n " ,
2008-01-29 11:08:17 +00:00
);
2007-08-20 07:03:08 +00:00
}
$form [ 'operation' ] = array ( '#type' => 'hidden' , '#value' => 'delete' );
$form [ '#submit' ][] = 'node_multiple_delete_confirm_submit' ;
2009-05-24 17:39:35 +00:00
$confirm_question = format_plural ( count ( $nodes ),
'Are you sure you want to delete this item?' ,
2009-05-15 03:58:35 +00:00
'Are you sure you want to delete these items?' );
2009-05-24 17:39:35 +00:00
return confirm_form ( $form ,
2009-05-15 03:58:35 +00:00
$confirm_question ,
2009-07-30 19:24:21 +00:00
'admin/content' , t ( 'This action cannot be undone.' ),
2009-05-15 03:58:35 +00:00
t ( 'Delete' ), t ( 'Cancel' ));
2007-08-20 07:03:08 +00:00
}
function node_multiple_delete_confirm_submit ( $form , & $form_state ) {
if ( $form_state [ 'values' ][ 'confirm' ]) {
2009-05-20 05:39:45 +00:00
node_delete_multiple ( array_keys ( $form_state [ 'values' ][ 'nodes' ]));
$count = count ( $form_state [ 'values' ][ 'nodes' ]);
watchdog ( 'content' , 'Deleted @count posts.' , array ( '@count' => $count ));
drupal_set_message ( t ( 'Deleted @count posts.' , array ( '@count' => $count )));
2007-08-20 07:03:08 +00:00
}
2009-07-30 19:24:21 +00:00
$form_state [ 'redirect' ] = 'admin/content' ;
2007-08-20 07:03:08 +00:00
return ;
}
2009-06-28 03:56:43 +00:00
/**
* Implement hook_modules_installed ()
*/
function node_modules_installed ( $modules ) {
// Clear node type cache for node permissions.
node_type_clear ();
2009-08-22 14:34:23 +00:00
}