attachfileの表示について


投稿ツリー


前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 .2 .3 .4 | 投稿日時 2011/4/8 11:41
hiro1613  半人前   投稿数: 24

こんにちは。
d3diaryでattachfileを使用してみようとチャレンジしていますが、
テンプレートのコメントアウトを外すと簡単に添付できたのですが、
添付ファイルが無い場合も0と表示されてしましますが、
添付ファイルが無い場合は表示しないとしたくてifでやろうとしてますが、
どうしても出来ません。
いつも質問ばかりですみません。
よろしくお願いします。

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2011/4/8 13:09 | 最終変更
なーお  長老   投稿数: 1784

hiro1613さん、こんにちは。

attachfileの添付ファイル数やダウンロードリンク表示などは、attachfileモジュール側smartyプラグインから返されてきたものが表示されますので、d3diary側では制御できませんね。。
 (確認ですが、他のモジュールへのattachでも同様ですよね?)

smartyプラグイン側で何とかしようと思えば出来なくもないのですが、元々プラグインはattachfileの関数を呼び出しているため、丸ごとハックするか、プラグイン側をごっそり作り込む必要がありそうです。

ということで、このまま使っていただくか、attachfile作者さんにお願いしてみてください。

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 .2 | 投稿日時 2011/4/8 18:44
ゲスト 

お返事ありがとうございます。
やはり無理っぽいですね。
他のモジュールでは使っていないので不明ですが、
attachfileの添付ファイル数を取得できると可能なんですけどね。
少し考えてみます。
ありがとうございました。

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2011/4/9 15:36
なーお  長老   投稿数: 1784

attachfile_attach_num プラグインを使えば、添付ファイル数を取得できますが、、 これをifの中に入れようとするとエラー。

echoではなくassignしてくれる構造なら簡単なんだが。。

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2011/4/9 17:06 | 最終変更
なーお  長老   投稿数: 1784

添付数とpopupリンクをアサインするプラグインを書いてみました。

プラグイン「function.attachfile_attach_download_r.php」

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
 
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     attach_download_r
 * Version:  1.0
 * Date:     2011/04/09
 * Author:   naao
 * Purpose:  
 * Input:    
 * 
 * Example1: {attachfile_attach_download item=attached item2=attach_link module_dirname=$mydirname dirname=attachfile target_id=$post.id}
 * -------------------------------------------------------------
 */
function smarty_function_attachfile_attach_download_r( $params, &$smarty )
{
    $mydirname = isset( $params['dirname'] ) ? $params['dirname'] : @$GLOBALS['xoopsModuleConfig']['attachfile_attach_dirname'] ;
 
    if( ! preg_match( '/^[0-9a-zA-Z_-]+$/' , $mydirname ) || ! file_exists( XOOPS_TRUST_PATH.'/modules/attachfile/include/attach_smarty_functions.php' ) ) {
        echo "<p>attach_download does not set properly.</p>" ;
    } else {
        require_once( XOOPS_TRUST_PATH.'/modules/attachfile/include/attach_smarty_functions.php' ) ;
 
        // 'isactive'/'module_read' check and include language
        // If the check failed, this function does nothing (not error).
        if( ! attachfile_process_instead_of_common( $mydirname ) ) {
            return ;
        }
 
        //$module_dirname = $xoopsModule->getVar('dirname') ;
        $module_dirname = $params['module_dirname'] ;
        $target_id = intval( $params['target_id'] ) ;
        $item = !empty($params['item']) ? $params['item'] : "attached" ;
        $item2 = !empty($params['item2']) ? $params['item2'] : "attach_link" ;
 
        // check download permission(= check num permission)
        $error_msg = attachfile_check_download_permission( $mydirname , $module_dirname , $target_id ) ;
        if ( isset( $error_msg ) ) {
            echo $error_msg ;
        }
 
        $xoopsDB =& Database::getInstance() ;
 
        // transaction and view
        $sql = "SELECT COUNT(*) FROM ".$xoopsDB->prefix( $mydirname."_attach" )." WHERE module_dirname='$module_dirname' AND target_id=$target_id" ;
        if( ! $result = $xoopsDB->query( $sql ) ) die( "DB ERROR in num popup" ) ;
        $row = $xoopsDB->fetchRow( $result ) ;
        $rtn = attachfile_display_popup_link_r( $mydirname , $module_dirname , $target_id , 'dpop' , _MD_ATTACHFILE_DOWNLOAD_POPUP , $row[0] );
        $smarty->assign( $item , $row[0] ) ;
        $smarty->assign( $item2 , $rtn ) ;
    }
}
 
function attachfile_display_popup_link_r( $mydirname , $module_dirname , $target_id , $mode , $title , $count )
{
    return '<a href="java script:void(0)" onclick="window.open(\''.XOOPS_URL.'/modules/'.$mydirname.'/index.php?mode='.$mode.'&module_dirname='.$module_dirname.'&target_id='.$target_id.'\', \'attachfile_popup\', \'width=400,height=200,toolbar=no,menubar=no,scrollbars=yes,location=yes,status=yes,resizable=yes\')">'.$title.'(<span id="'.$mydirname.'_COUNT_'.$module_dirname.'_'.$target_id.'">'.$count.'</span>)</a>' ;
 
}
 
?>

テンプレート内の記述 (diary)_detail.html

Everything is expanded.Everything is shortened.
1
2
3
4
 
 
 
 
<{attachfile_attach_download_r item=attached item2=attach_link module_dirname=$mydirname dirname=attachfile target_id=$yd_data.bid}>
<{if $attached >0}>
<{$attach_link}>&nbsp;|&nbsp;
<{/if}>

テンプレート内の記述 (diary)_index.html

Everything is expanded.Everything is shortened.
1
2
3
4
 
 
 
 
<{attachfile_attach_download_r item=attached item2=attach_link module_dirname=$mydirname dirname=attachfile target_id=$entry.bid}>
<{if $attached >0}>
<{$attach_link}>&nbsp;|&nbsp;
<{/if}>
投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2011/6/12 15:16
hiro1613  半人前   投稿数: 24

こんにちは。
function.attachfile_attach_download_r.phpをpreloadに入れて(diary)_detail.htmlに記述したところ真っ白になりました。
phpデバックを見たら
Warning [PHP]: array_diff() [function.array-diff]: Argument #2 is not an array in file C:\xampp\htdocs\ディレクトリー名\xoops_trust_path\modules\d3diary\class\func.class.php line 1370
Error [Xoops]: Smarty error: [in db:news_detail.html line 6]: syntax error: unrecognized tag 'attachfile_attach_download_r' (Smarty_Compiler.class.php, line 590) in file C:\xampp\htdocs\ディレクトリー名\class\smarty\Smarty.class.php line 1093
何がおかしいのでしょうか?

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2011/6/12 17:26 | 最終変更
なーお  長老   投稿数: 1784

hiro1613さん、こんにちは。

携帯からなので要点だけ。

preloadに入れたんですか? だとしたらそれでは間違いです。

投票数:0 平均点:0.00
返信する
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2011/6/12 18:26
hiro1613  半人前   投稿数: 24

ありがとうございます。
勘違いしていました。
無事、0の場合は非表示が出来ました。

投票数:0 平均点:0.00
返信する

このトピックに投稿する

題名
ゲスト名
投稿本文
  条件検索へ