Drupal 7 如何将这个hook_nodeapi()转换为drupal 7 hook?

Drupal 7 如何将这个hook_nodeapi()转换为drupal 7 hook?,drupal-7,Drupal 7,我有drupal 6模块,它实现了hook_nodeapi()。我必须把它转换成Drupal7。我需要建议。任何帮助都会很好 “alter”:已经呈现了$node->content数组,因此节点主体或摘要被过滤,现在包含HTML。仅当需要文本替换、筛选或其他原始文本操作时,才应使用此op “删除”:正在删除节点 “删除修订”:删除节点的修订。您可以删除与该修订相关联的数据 “插入”:节点刚刚创建(插入到数据库中) “加载”:即将从数据库加载节点。这个钩子可以用来加载额外的数据 “准备”:节点将

我有drupal 6模块,它实现了hook_nodeapi()。我必须把它转换成Drupal7。我需要建议。任何帮助都会很好

  • “alter”:已经呈现了$node->content数组,因此节点主体或摘要被过滤,现在包含HTML。仅当需要文本替换、筛选或其他原始文本操作时,才应使用此op
  • “删除”:正在删除节点
  • “删除修订”:删除节点的修订。您可以删除与该修订相关联的数据
  • “插入”:节点刚刚创建(插入到数据库中)
  • “加载”:即将从数据库加载节点。这个钩子可以用来加载额外的数据
  • “准备”:节点将显示在添加/编辑表单上
  • “准备翻译”:正在克隆节点以进行翻译。从$node->translation\u source加载其他数据或复制值
  • “打印”:准备要打印的节点视图。用于book_模块中的打印机友好视图
  • “rss项目”:生成rss提要。模块可以返回要添加到此节点生成的RSS项的属性。有关示例,请参见注释和上传。 还可以修改传递的$node以向提要项添加或删除内容
  • “搜索结果”:节点显示为搜索结果。如果要显示结果的额外信息,请返回它
  • “presave”:节点已通过验证,即将保存。在将节点保存到数据库之前,模块可以使用此选项对节点进行更改
  • “更新”:该节点刚刚在数据库中更新
  • “更新索引”:正在索引节点。如果您希望索引其他信息,而这些信息在nodeapi“视图”中尚不可见,则应在此处返回
  • “验证”:用户刚刚完成对节点的编辑,正在尝试预览或提交节点。这个钩子可以用来检查节点数据。错误应使用表单\u set\u error()设置
  • “视图”:渲染前正在组装节点内容。模块可以在渲染之前添加元素$node->content。此挂钩将在hook_view()之后调用。$node->content的格式与Forms API使用的格式相同

     function px_nodeapi(&$node, $op, $teaser, $page) {
        // px_logger(PX_INFO, 'nodeapi', $op, $node);
        switch ($op) {
            case 'delete_revision':
                switch ($node->type) {
                    case 'case':
                    case 'case_slide':
                    case 'case_fov':
                        px_case_delete_revision($node);
                        break;
                    default:
                        break;
                }
                break;
            case 'insert':                // apply uploadpath logic to images
            case 'update':
                if ($node->type == 'image') {
                    //px_logger(PX_INFO, 'uploadpath', $op, $node);
                    if (isset($node->images) && user_access('upload files') && $node->new_file == 1) {
                        px_set_tokens($node);
                        foreach ($node->images as $size => $src_file) {
                            if (!isset($src_file) or empty($src_file)) {
                                continue;
                            }
                            $fid = db_result(db_query("SELECT fid FROM {image} WHERE nid=%d and image_size='%s' LIMIT 1", $node->nid, $size));
                            $base_file_name = basename($src_file);
                            //px_logger(PX_INFO, 'uploadpath', '$base_file_name='.$base_file_name);
    
                        //get the token path pattern
                        $pattern = variable_get('uploadpath_prefix_'.$node->type, 'px/users/[case-owner]/[case-handle]/images');
    
                        if(variable_get('uploadpath_clean_filenames', false)){
                            //get path info of file
                            $file_info = pathinfo($src_file);
                            px_logger(PX_INFO, 'uploadpath', '$file_info=', $file_info);
                            /*crop lowercase node title to max
                             replace anything except numbers and letters with underscore
                             add 10 digit unique id and file extension*/
                            $file_name = substr($file_info['filename'], 0, 50);
                            //replace anything except numbers and letters with an underscore
                            //$file_name = preg_replace("/([^a-z0-9])/", '_', strtolower($file_name));
                            $file_name = preg_replace("/([^a-zA-Z0-9])/", '_', $file_name);
                            //replace multiple underscores with a single one
                            $file_name = preg_replace("/_+/", '_', $file_name);
                            //$file_name .= '_'. substr(uniqid(rand(), true),0,5). '.'. $file_info['extension'];
                            $file_name .= '.' . $file_info['extension'];
                            // apply new, prefixed file name by token replacing the path pattern
                            $file_path = token_replace($pattern . '/', 'node', $node);
                            $file_name = $file_path . $file_name;
                        }else{
                            // apply new, prefixed file name by token replacing the path pattern
                            $file_name = str_replace(array(' ', "\n", "\t"), '_', token_replace($pattern . '/', 'node', $node)) . $base_file_name;
                        }
    
                        //px_logger(PX_INFO, 'uploadpath', 'new path is '.$file_name);
    
                        // SECURITY NOTE:
                        // Tokens include user supplied information and could provide an attack vector.
                        // The current method of creating directories prevents the use of .. or other malicious
                        // paths, but future developers should keep this in mind when modifying the following code
                        // Create the directory if it doesn't exist yet.
                        $dirs = explode('/', dirname($file_name));
                        $directory = file_directory_path();
                        $file_name = $directory.'/'.$file_name;
                        while (count($dirs)) {
                            $directory .= '/' . array_shift($dirs);
                            file_check_directory($directory, FILE_CREATE_DIRECTORY);
                        }
                        px_logger(PX_INFO, 'uploadpath', 'about to move file from '.$src_file.' to '.$file_name);
    
                        //move file to new subfolder
                        if (file_move($src_file, $file_name, FILE_EXISTS_RENAME)) {
                            //update node file array with new path, if needed
                            $node->images[$size] = $file_name;
                            // update file record in database
                            db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $file_name, $fid);
                        }
                        //px_logger(PX_INFO, 'uploadpath', 'node', $node);
                    }
                }
            }
            break;
        case 'presave':
            //   if ($node->type == 'case_slide') {
            //     $node->title = $test_type;
            //   }
            break;
        case 'view':
            if (($node->type == 'case' or $node->type == 'case_slide' or $node->type == 'case_fov')
            and $teaser and !$node->iid) {
                $node->content['image_attach'] = array(
                      '#value' => theme("image_attach_teaser", $node),
                      '#weight' => variable_get("image_attach_weight_teaser_{$node->type}", 0),
                );
            }
            if ($node->type == 'group' and !$teaser) {
                $num_members = db_result(db_query('SELECT COUNT(*) FROM {og_uid} WHERE is_active = 1 and nid = %d', $node->nid));
                $num_cases = db_result(db_query('SELECT COUNT(*) FROM {og_ancestry} WHERE group_nid = %d', $node->nid));
                unset($node->content['og_mission']);
                $case_user = user_load(array('uid' => $node->uid));
                $node->content['group_details'] = array(
                      '#value' => '
                        <div id="group_desc">
                            <!--div class="value">'.$node->og_description.'</div-->
                        </div>',
          '#weight' => -10,
                );
                if (!empty($node->body)) {
                    $node->content['group_details']['#value'] = '<div id="group_body">'.$node->body.'</div>' . $node->content['group_details']['#value'];
                }
                $node->content['group_details']['#value'] = '<div id="group_created">Created on '.px_case_format_date($node->created).' by '.theme('username', $case_user).'</div>' . $node->content['group_details']['#value'];
                $group_members = '<ul>';
                $ml = 5;
                $result = db_query('SELECT uid, created FROM {og_uid} WHERE is_active = 1 and nid = %d ORDER BY created DESC LIMIT '.$ml, $node->nid);
                while ($row = db_fetch_array($result)) {
                    $member = user_load(array('uid' => $row['uid']));
                    $group_members .= '<li>'.theme('username', $member).'</li>';
                }
                $group_members .= '</ul>';
                $node->content['group_members'] = array(
                      '#value' => '
                          <div id="group_recent_members">
                            <span class="stats"><a href="/og/users/'.$node->nid.'">All members ('.$num_members.')</a></span>
                            <span class="label">Recent members</span>
                            <div class="value">'.$group_members.'</div>
                          </div>',
                      '#weight' => -8,
                );
                $node->content['view']['#value'] = '
                      <div id="group_recent_cases">
                        <span class="stats"><a href="/node/'.$node->nid.'/cases">All cases ('.$num_cases.')</a></span>
                        <span class="label">Recent cases</span>
                        <div class="value">'.$node->content['view']['#value'].'</div>
                      </div>';
                // px_logger(PX_INFO, 'nodeapi', 'node is', $node);
            }
        default:
            // px_logger(PX_INFO, 'nodeapi', 'op is '.$op.' type is '.$node->type);
            break;
    }
    
    函数px_nodeapi(&$node,$op,$striser,$page){
    //px_记录器(px_信息,'nodeapi',$op,$node);
    交换机($op){
    案例“删除修订”:
    开关($node->type){
    案例“案例”:
    案例“案例幻灯片”:
    案例“案例”:
    px案例删除修订($node);
    打破
    违约:
    打破
    }
    打破
    案例“insert”://将uploadpath逻辑应用于图像
    案例“更新”:
    如果($node->type=='image'){
    //px_记录器(px_信息,'uploadpath',$op,$node);
    if(isset($node->images)&&user_access('upload files')&&&node->new_file==1){
    px_集合_令牌($node);
    foreach($node->imagesas$size=>$src\u文件){
    如果(!isset($src_文件)或空($src_文件)){
    继续;
    }
    $fid=db_结果(db_查询(“从{image}中选择fid,其中nid=%d,image_大小=“%s”LIMIT 1”,$node->nid,$size));
    $base\u file\u name=basename($src\u file);
    //px_记录器(px_信息,'uploadpath','$base_file_name='。$base_file_name);
    //获取令牌路径模式
    $pattern=variable\u get('uploadpath\u prefix.'$node->type,'px/users/[case owner]/[case handle]/images');
    if(变量_get('uploadpath_clean_filenames',false)){
    //获取文件的路径信息
    $file\u info=pathinfo($src\u file);
    px_记录器(px_信息,'uploadpath','$file_信息=',$file_信息);
    /*将小写节点标题裁剪为最大值
    用下划线替换除数字和字母以外的任何内容
    添加10位唯一id和文件扩展名*/
    $file\u name=substr($file\u info['filename'],0,50);
    //用下划线替换除数字和字母以外的任何内容
    //$file_name=preg_replace(“/([^a-z0-9])/”,“'''u',strtolower($file_name));
    $file\u name=preg\u replace(“/([^a-zA-Z0-9])/”,“\u',$file\u name);
    //用一个下划线替换多个下划线
    $file\u name=preg\u replace(“/\u+/”、“\u”、$file\u name);
    //$file_name.='''u'.substr(uniqid(rand(),true),0,5)。'.$file_info['extension'];
    $file_name.='..$file_info['extension'];
    //通过替换路径模式的标记应用新的带前缀的文件名
    $file\u path=token\u replace($pattern.'/','node',$node);
    $file\u name=$file\u path.$file\u name;
    }否则{
    //通过替换路径模式的标记应用新的带前缀的文件名
    $file\u name=str\u replace(数组(“”,“\n”,“\t”),“\u”,标记\u replace($pattern./','node',$node))。$base\u file\u name;
    }
    //px_记录器(px_信息,“上载路径”,“新路径为“.$file_name”);
    //安全说明:
    / /令牌包括用户提供的信息,并且可以提供攻击向量。
    //当前创建目录的方法可防止使用..或其他恶意文件
    //但是未来的开发人员在修改以下代码时应该记住这一点
    //制造灾难