| 1 |
<?php |
<?php |
| 2 |
// $Id: devel.module,v 1.319 2009/02/11 04:55:38 weitzman Exp $ |
// $Id: devel.module,v 1.320 2009/02/12 03:49:36 weitzman Exp $ |
| 3 |
|
|
| 4 |
// This module holds functions useful for Drupal development. |
// This module holds functions useful for Drupal development. |
| 5 |
// Please contribute! |
// Please contribute! |
| 490 |
} |
} |
| 491 |
|
|
| 492 |
/** |
/** |
| 493 |
* Implementation of hook_block(). |
* Implementation of hook_block_list(). |
| 494 |
*/ |
*/ |
| 495 |
function devel_block($op = 'list', $delta = 0, $edit = array()) { |
function devel_block_list() { |
| 496 |
if ($op == 'list') { |
$blocks[0]['info'] = t('Switch user'); |
|
$blocks[0]['info'] = t('Switch user'); |
|
| 497 |
// $blocks[1]['info'] = t('Devel'); |
// $blocks[1]['info'] = t('Devel'); |
| 498 |
$blocks[2]['info'] = t('Execute PHP'); |
$blocks[2]['info'] = t('Execute PHP'); |
| 499 |
return $blocks; |
return $blocks; |
| 500 |
} |
} |
| 501 |
else if ($op == 'configure' && $delta == 0) { |
|
| 502 |
|
/** |
| 503 |
|
* Implementation of hook_block_list(). |
| 504 |
|
*/ |
| 505 |
|
function devel_block_configure($delta) { |
| 506 |
|
if ($delta == 0) { |
| 507 |
$form['devel_switch_user_list_size'] = array( |
$form['devel_switch_user_list_size'] = array( |
| 508 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 509 |
'#title' => t('Number of users to display in the list'), |
'#title' => t('Number of users to display in the list'), |
| 513 |
); |
); |
| 514 |
return $form; |
return $form; |
| 515 |
} |
} |
| 516 |
else if ($op == 'save' && $delta == 0) { |
} |
| 517 |
|
|
| 518 |
|
function devel_block_save($delta, $edit = array()) { |
| 519 |
|
if ($delta == 0) { |
| 520 |
variable_set('devel_switch_user_list_size', $edit['devel_switch_user_list_size']); |
variable_set('devel_switch_user_list_size', $edit['devel_switch_user_list_size']); |
| 521 |
} |
} |
| 522 |
else if ($op == 'view') { |
} |
| 523 |
$block = array(); |
|
| 524 |
switch ($delta) { |
function devel_block_view($delta) { |
| 525 |
case 0: |
$block = array(); |
| 526 |
$block = devel_block_switch_user(); |
switch ($delta) { |
| 527 |
break; |
case 0: |
| 528 |
case 1: |
$block = devel_block_switch_user(); |
| 529 |
// Deleted in favor of custom menu. do not reuse this index. |
break; |
| 530 |
break; |
case 1: |
| 531 |
case 2: |
// Deleted in favor of custom menu. do not reuse this index. |
| 532 |
if (user_access('execute php code')) { |
break; |
| 533 |
$block['subject'] = t('Execute PHP'); |
case 2: |
| 534 |
$block['content'] = drupal_get_form('devel_execute_form'); |
if (user_access('execute php code')) { |
| 535 |
} |
$block['subject'] = t('Execute PHP'); |
| 536 |
break; |
$block['content'] = drupal_get_form('devel_execute_form'); |
| 537 |
} |
} |
| 538 |
return $block; |
break; |
| 539 |
} |
} |
| 540 |
|
return $block; |
| 541 |
} |
} |
| 542 |
|
|
| 543 |
function devel_block_switch_user() { |
function devel_block_switch_user() { |
|
$block['subject'] = t('Switch user'); |
|
| 544 |
$links = devel_switch_user_list(); |
$links = devel_switch_user_list(); |
| 545 |
if (!empty($links)) { |
if (!empty($links)) { |
| 546 |
$block['content'] = theme('item_list', $links); |
$block['subject'] = t('Switch user'); |
| 547 |
|
$block['content'] = theme('links', $links); |
| 548 |
$block['content'] .= drupal_get_form('devel_switch_user_form'); |
$block['content'] .= drupal_get_form('devel_switch_user_form'); |
| 549 |
return $block; |
return $block; |
| 550 |
} |
} |
| 572 |
$users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size); |
$users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size); |
| 573 |
} |
} |
| 574 |
while ($user = db_fetch_object($users)) { |
while ($user = db_fetch_object($users)) { |
| 575 |
$links[$user->uid] = l(theme('placeholder', $user->name), 'devel/switch/'. $user->name, array('attributes' => array('title' => t('This user can switch back.')), 'query' => $dest, 'html' => TRUE)); |
$links[$user->uid] = array( |
| 576 |
|
'title' => theme('placeholder', $user->name), |
| 577 |
|
'href' => 'devel/switch/' . $user->name, |
| 578 |
|
'query' => $dest, |
| 579 |
|
'attributes' => array('title' => t('This user can switch back.')), |
| 580 |
|
'html' => TRUE, |
| 581 |
|
); |
| 582 |
} |
} |
| 583 |
$num_links = count($links); |
$num_links = count($links); |
| 584 |
if ($num_links < $list_size) { |
if ($num_links < $list_size) { |
| 585 |
// If we don't have enough, add distinct uids until we hit $list_size. |
// If we don't have enough, add distinct uids until we hit $list_size. |
| 586 |
$users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links); |
$users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links); |
| 587 |
while (($user = db_fetch_object($users)) && count($links) < $list_size) { |
while (($user = db_fetch_object($users)) && count($links) < $list_size) { |
| 588 |
$links[$user->uid] = l($user->name ? $user->name : 'anon', 'devel/switch/'. $user->name, array('attributes' => array('title' => t('Caution: this user will be unable switch back.')), 'query' => $dest)); |
$links[$user->uid] = array( |
| 589 |
|
'title' => $user->name ? $user->name : 'anon', |
| 590 |
|
'href' => 'devel/switch/' . $user->name, |
| 591 |
|
'query' => $dest, |
| 592 |
|
'attributes' => array('title' => t('Caution: this user will be unable switch back.')), |
| 593 |
|
); |
| 594 |
} |
} |
| 595 |
} |
} |
| 596 |
} |
} |