欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal如何给内容添加审核功能

drupal如何给内容添加审核功能
drupal默认安装,当你添加内容时,默认的状态是发布状态.也就是说,只要你有权限发布,你发布的内容无需要管理员审核.
drupal对于page和forum是通过节点来管理的,如果有administer node的权限,就能够对所有节点进行管理.对于一个企业的网站,我们希望普通用户能够发布内容,但希望管理员审核之后才可以发布.
现在我就将介绍如何修改代码使其支持管理员审核的这一功能.
1 修改默认的状态为0,也就是未发布.
  修改modules/node/node.install 335L,使默认状态为0
 
2 查看node_object_prepare这个函数.发现有段代码很奇怪.
  修改modules/node/node.pages.inc L606,强制添加$node->status = 0
  
3 为了保证上述修改生效,你必须禁用Trigger功能.因为这个功能将调用这个函数.
  文件modules/node/node.module.函数node_publish_action将会修改未发布状态为发布状态,很烦人.
  

ps:此修改限制没有administer nodes权限的用户, 发布内容必须管理员审核.
代码
  1. 'status' => array(  
  2.         'description' => t('Boolean indicating whether the node is published (visible to non-administrators).'),  
  3.         'type' => 'int',  
  4.         'not null' => TRUE,  
  5.         'default' => 0),  
  6.      
代码 
  1.  function node_object_prepare(&$node) {  
      // Set up default values, if required.  
      //$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));  
      $node_options = variable_get('node_options_'. $node->type, array('promote')); 
      // If this is a new node, fill in the default values.  
  2.   if (!isset($node->nid)) {  
  3.     foreach (array('status''promote''sticky') as $key) {  
  4.       $node->$key = in_array($key, $node_options);  
  5.     }  
  6.     global $user;  
  7.     $node->uid = $user->uid;  
  8.     $node->created = time();  
  9.     //$node->$key是通过in_array返回的参数来赋值的,并没有从配置文件里取,这是我奇怪的地方,所以对于新添加的节点,我强制其为0.  
  10.     $node->status = 0;  
  11.   }  
  12.   else {  
  13.     $node->date = format_date($node->created, 'custom''Y-m-d H:i:s O');  
  14.   }  
  15.   // Always use the default revision setting.  
  16.   $node->revision = in_array('revision', $node_options);  
  17.   
  18.   node_invoke($node, 'prepare');  
  19.   node_invoke_nodeapi($node, 'prepare');  
  20. }  
代码
  1. function node_publish_action(&$node, $context = array()) {  
  2.   $node->status = 1;   
  3.   ....  
  4.   } 

此修改限制没有administer nodes权限的用户, 发布内容必须管理员审核.

普通分类: