hook_nodeapi() を実装する drupal 6 モジュールがあります。drupal 7 に変換する必要があります。提案が必要です。どんな助けでも素晴らしいでしょう。
- "alter": $node->content 配列がレンダリングされたため、ノード本体またはティーザーがフィルター処理され、HTML が含まれるようになりました。この操作は、テキストの置換、フィルタリング、またはその他の生のテキスト操作が必要な場合にのみ使用してください。
- "delete": ノードは削除中です。
- 「リビジョン削除」:ノードのリビジョンを削除します。そのリビジョンに関連付けられたデータを削除できます。
- "insert": ノードが作成されました (データベースに挿入されました)。
- "load": ノードがデータベースからロードされようとしています。このフックを使用して、現時点で追加のデータをロードできます。
- "prepare": ノードが追加/編集フォームに表示されようとしています。
- "prepare translation": ノードは翻訳のために複製されています。追加のデータをロードするか、$node->translation_source から値をコピーします。
- "print": 印刷用のノード ビューを準備します。book_module で印刷用に表示するために使用されます
- "rss item": RSS フィードが生成されます。モジュールは、このノード用に生成された RSS アイテムに追加されるプロパティを返すことができます。例については、comment_nodeapi() および upload_nodeapi() を参照してください。渡された $node を変更して、コンテンツをフィード アイテムに追加または削除することもできます。
- 「検索結果」:ノードが検索結果として表示されます。結果とともに追加情報を表示する場合は、それを返します。
- "presave": ノードは検証に合格し、保存されようとしています。モジュールはこれを使用して、データベースに保存する前にノードに変更を加えることができます。
- "update": ノードはデータベースで更新されたばかりです。
- "update index": ノードのインデックスが作成されています。nodeapi "view" でまだ表示されていない追加情報にインデックスを付けたい場合は、ここで返す必要があります。
- "validate": ユーザーはノードの編集を終了したばかりで、プレビューまたは送信しようとしています。このフックは、ノード データをチェックするために使用できます。エラーは form_set_error() で設定する必要があります。
"view": ノード コンテンツはレンダリング前にアセンブルされています。モジュールは、レンダリングの前に要素 $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; }
}