这个模块目前包含四个功能:
1. 给节点页面添加”Delete“菜单。
说明:有客户问我怎么删除一个内容,让我意识到这个链接有必要加上,以便让客户以最快捷的方式删除某个内容。
2. 给节点页面添加”Add another“菜单。
说明:这个功能很方便不是吗?有个add another模块就是干这个的。
3. 给teaser节点加上“编辑”和“删除”链接。
说明:通常项目中不经常有teaser列表形式的页面,所以这个对博客更实用。
4. 非超级用户要修改非当前用户的信息必须提供要修改的用户的密码。
说明:最初的起因是不想让拥有管理用户权限的管理员修改超级用户的密码,后来发现有的项目有多个管理员,也不能让他们相互可以修改密码,安全问题,你知道的。
代码同样很少,所以直接贴出来:
/**
* @file
* Defination some extra function for administer.
* 1. 给节点页面添加”Delete“菜单
* 2. 给节点页面添加”Add another“菜单
* 3. 给teaser节点加上“编辑”和“删除”链接
* 4. 非超级用户要修改非当前用户的信息必须提供要修改的用户的密码
*/
/**
* Implements of hook_menu().
*/
function system_extra_menu() {
$items['node/%node/add_another'] = array(
'title' => t('Add another'),
'page callback' => 'add_another',
'page arguments' => array(1),
'access callback' => 'node_access',
'access arguments' => array('create', 1),
'weight' => 3,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Page callback of menu - 'add_another'.
*/
function add_another($node) {
drupal_goto('node/add/'.str_replace('_', '-', $node->type));
}
/**
* Implements of hook_menu_alter().
* Add 'Add another' menu to node page.
*/
function system_extra_menu_alter(&$items) {
$items['node/%node/delete']['type'] = MENU_LOCAL_TASK;
$items['node/%node/delete']['weight'] = 2;
}
/**
* Implements of hook_link().
* 给teaser节点加上“编辑”和“删除”链接
*/
function system_extra_link($type, $object, $teaser = FALSE) {
global $is_admin;
$links = array();
if($is_admin && $type == 'node' && $teaser) {
$links['edit'] = array(
'title' => t('edit'),
'href' => 'node/' . $object->nid.'/edit',
);
$links['delete'] = array(
'title' => t('delete'),
'href' => 'node/' . $object->nid.'/delete',
);
}
return $links;
}
/**
* Implements of hook_user().
* 非超级用户要修改非当前用户的信息必须提供要修改的用户的密码
*/
function system_extra_user($op, &$edit, &$edit_user, $category = NULL) {
global $user;
switch($op) {
case 'form':
if($user->uid != 1 && $edit_user->uid != $user->uid) {
$fields['account']['user_old_passwd'] = array(
'#type' => 'password',
'#title' => '请填写该用户的密码',
'#weight' => 0,
'#required' => TRUE,
);
return $fields;
}
break;
case 'validate':
if($user->uid != 1 && $edit_user->uid != $user->uid) {
$sql = "SELECT u.pass FROM {users} u WHERE u.uid = %d";
$edit_pass = db_result(db_query($sql, $edit_user->uid));
if(!$edit['user_old_passwd']) {
$message = '请填写该用户的密码!';
form_set_error('user_old_passwd', $message, $reset = FALSE);
} else if(md5($edit['user_old_passwd']) != $edit_pass) {
$message = '该用户的密码填写不正确!';
form_set_error('user_old_passwd', $message, $reset = FALSE);
}
}
break;
}
}
| Attachment | Size |
|---|---|
| system_extra.rar | 1.04 KB |
