FALSE, 'nothispage' => FALSE, 'smart' => FALSE ); // オプションチェック $toppage = ''; if (func_num_args()) { foreach(func_get_args() as $arg) { if(array_key_exists($arg,$params)) { $params[$arg] = TRUE; } else { $toppage = $arg; } } } if($toppage=='') { // パラメータ省略時は設置ページを基準とする $toppage = $vars['page']; } $pattern = preg_quote($toppage,'/'); if($params['nothispage']) { // 設置ページを含めない $pattern .= "\/.+"; } else { // 設置ページを含める $pattern .= "(?:\/.+)?"; } // パターンに合致するページ名、ファイル名の取得 $matches = array(); $attachpages = array(); $attachfiles = array(); $dir = UPLOAD_DIR; $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.'); while ($filename = readdir($dp)) { if(preg_match("/^((?:[0-9A-F]{2})+)_((?:[0-9A-F]{2})+)$/", $filename, $matches)) { $pagename = decode($matches[1]); $attachname = decode($matches[2]); if(preg_match("/^$pattern$/",$pagename)) { if(!in_array($pagename,$attachpages)) { $attachpages[] = $pagename; } $attachfiles[$pagename][] = "$attachname"; } } } closedir($dp); // 取得した一覧の表示 $body = ''; sort($attachpages); foreach($attachpages as $attachpage) { sort($attachfiles[$attachpage]); if($params['smart']==FALSE) { $body .= "-[[$attachpage]]\n"; foreach($attachfiles[$attachpage] as $filename) { if($params['noref']) { $body .= "--$filename\n"; } else { $body .= "--&ref($attachpage/$filename,noimg);\n"; } } } else { foreach($attachfiles[$attachpage] as $filename) { if($params['noref']) { $body .= "-$attachpage/$filename\n"; } else { $body .= "-&ref($attachpage/$filename,noimg,$attachpage/$filename);\n"; } } } } return convert_html($body); } ?>