[첫화면으로]UseModWiki소스수정/UploadedFiles매크로

마지막으로 [b]

UploadedFiles 매크로 추가

wiki.pl
sub MacroSubst {
    ...
### <UploadedFiles>
    $txt =~ s/(\&__LT__;uploadedfiles\&__GT__;)/&MacroUploadedFiles($1)/gei;
###
###############
    return $txt;
}

함수를 통채로 추가
sub MacroUploadedFiles {
    my ($itself) = (@_);
    my (@files, %filesize, %filemtime, $size, $totalSize);
    my $txt;
    my $uploadsearch = "<img style='border:0' src='$IconUrl/upload-search.gif'>";
    my $canDelete = &UserIsAdmin();

    if (!(-e $UploadDir)) {
        &CreateDir($UploadDir);
    }

    opendir (DIR, "$UploadDir") || die Ts('cant opening %s', $UploadDir) . ": $!";
    @files = grep { !/^\.\.?$/ } readdir(DIR);
    close (DIR);

    $totalSize = 0;
    foreach (@files) {
        $filesize{$_} = (-s "$UploadDir/$_");
        $totalSize += $filesize{$_};
        $filemtime{$_} = ($Now - (-M "$UploadDir/$_") * 86400);
    }

    @files = sort {
        $filemtime{$b} <=> $filemtime{$a}
                ||
                $a cmp $b
    } @files;

    my ( @dirs, @p_files );
    foreach my $f ( @files ) {
        if ( -d "$UploadDir/$f" ) {
            push @dirs, $f;
        }
        else {
            push @p_files, $f;
        }
    }

    $txt = $q->start_form("post","$ScriptName","");
    $txt .= "<input type='hidden' name='action' value='deleteuploadedfiles'>";
    $txt .= "<input type='hidden' name='pagename' value='$OpenPageName'>";

    $txt .= "<TABLE class='uploadedfiles'>";
    $txt .= "<TR class='uploadedfiles'>";
    if ($canDelete) {
        $txt .= "<TH class='uploadedfiles'><b>".T('Delete')."</b></TH>";
    }
    $txt .= "<TH class='uploadedfiles'><b>".T('File Name')."</b></TH>".
        "<TH class='uploadedfiles'><b>".T('Size (byte)')."</b></TH>".
        "<TH class='uploadedfiles'><b>".T('Date')."</b></TH>";
    $txt .= "</TR>\n";


    foreach (@dirs, @p_files) {
        $txt .= "<TR class='uploadedfiles'>";
        if ($canDelete) {
            $txt .= "<TD class='uploadedfiles' align='center'>";
            $txt .= "<input type='checkbox' name='files' value='$_'></input> ";
            $txt .= "</TD>";
        }
        $txt .= "<TD class='uploadedfiles'>";
        $txt .= &GetReverseLink("Upload:$_", $uploadsearch) . " ";
        if ( -d "$UploadDir/$_" ) {
            $txt .= "$_/";
        }
        else {
            $txt .= "<a href='$UploadUrl/$_'>$_</a>";
        }
        $txt .= "</TD>";

        $size = $filesize{$_};
        while ($size =~ m/(\d+)(\d{3})((,\d{3})*$)/) {
            $size = "$1,$2$3";
        }
        $txt .= "<TD class='uploadedfiles' align='right'>$size</TD>";
        $txt .= "<TD class='uploadedfiles'>".&TimeToText($filemtime{$_})."</TD>";
        $txt .= "</TR>\n";
    }
    $txt .= "<TR class='uploadedfiles'>";
    $txt .= "<TD class='uploadedfiles'>&nbsp;</TD>" if ($canDelete);
    $txt .= "<TD class='uploadedfiles'>";
    $txt .= "<b>". Ts('Total %s files', ($#files + 1))."</b>";
    $txt .= "</TD>";
    while ($totalSize =~ m/(\d+)(\d{3})((,\d{3})*$)/) {
        $totalSize = "$1,$2$3";
    }
    $txt .= "<TD class='uploadedfiles' align='right'>";
    $txt .= "<b>$totalSize</b>";
    $txt .= "</TD>";
    $txt .= "<TD class='uploadedfiles'>&nbsp;</TD></TR>\n";

    $txt .= "</TABLE>";
    $txt .= $q->submit(T('Delete Checked Files')) if ($canDelete);
    $txt .= $q->endform;
    return $txt;

}

sub DoOtherRequest {
    ...
        } elsif ($action eq "upload") {
            &DoUpload();
###
###############
###############
### added by gypark
### UploadedFiles 매크로
        } elsif ($action eq "deleteuploadedfiles") {
            &DoDeleteUploadedFiles();
###
###############
        } else {
            # Later improve error reporting
            &ReportError(Ts('Invalid action parameter %s', $action));
    ...
}

함수를 통채로 추가
### DeleteUploadedFiles 매크로
sub DoDeleteUploadedFiles {
    my (%vars, @files);

    print &GetHeader("", T('Delete Uploaded Files'), "");

    if (!(&UserIsAdmin())) {
        print T('Deleting is not allowed');
        print "<br>\n";
    } else {
        %vars = $q->Vars;
        @files = split(/\0/,$vars{'files'}, -1);
        foreach (@files) {
            if ( -d "$UploadDir/$_" ) {
                foreach my $sub_f ( glob("$UploadDir/$_/*") ) {
                    unlink $sub_f;
                }
                if ( rmdir "$UploadDir/$_" ) {
                    print Ts('%s is deleted successfully', $_)."<br>";
                }
                else {
                    print Ts('%s can not be deleted', $_). " : $!<br>";
                }
            }
            else {
                if (unlink ("$UploadDir/$_")) {
                    print Ts('%s is deleted successfully', $_)."<br>";
                } else {
                    print Ts('%s can not be deleted', $_). " : $!<br>";
                }
            }
        }
    }

    if (&GetParam('pagename') ne "") {
        print "<hr size='1'>".Ts('Return to %s' , &GetPageLink(&GetParam('pagename')));
    }

    print &GetCommonFooter();
}

translations/korean.pl
Delete
삭제
File Name
화일명
Size (byte)
크기 (byte)
Date
날짜
Total %s files
전체 화일 갯수 : %s
Delete Checked Files
선택한 화일 삭제
Delete Uploaded Files
업로드한 화일 삭제
Deleting is not allowed
화일 삭제가 허용되지 않습니다
%s is deleted successfully
%s 화일이 삭제되었습니다
%s can not be deleted
%s 화일을 삭제할 수 없습니다

Notes

돋보기 아이콘을 클릭했을 때, 어떻게 검색을 할 것인가를 궁리해 봤는데
-- Raymundo 2003-3-16 7:53 pm


추가 업데이트 내역

ext1.42b 에서 한 라인이 수정되었습니다. /화일업로드를 꼭 읽어보세요.
2268c2269
<       $txt .= "<a href='$UploadDir/$_'>$_</a>";
---
>       $txt .= "<a href='$UploadUrl/$_'>$_</a>";

ext1.95b
-- Raymundo 2006-3-29 11:57 pm

ext2.25
-- Raymundo 2012-4-27 11:09 pm

사용자 의견

Hi and good evening over there,
a minor tweak:

- if (!(-e $UploadDir)) {
&CreateDir($UploadDir);
- }

"&CreateDir" implies "if (!(-e $UploadDir))", isn´t it?.
Thanks.
-- JuanmaMP 2012-5-8 8:53 pm

By the way, this great feature open the way to bulk actions on whole wiki.
-- JuanmaMP 2012-5-8 9:04 pm

You're right. The 'if' test isn't necessary. Thank you.
-- Raymundo 2012-5-9 3:38 pm

I'm sorry but I can't understand your second comment.
-- Raymundo 2012-5-9 3:40 pm

You're right Raymundo, because I didn't put examples about that second comment. For instance, this snippet can be reuse in order to all-pages list with check box and to do selective erase, lock, hide and other actions over files (I hope to do something about this in a future). I was having in mind during long time this feature that I am watching here!. :)
One more subject about file attributes (if you like), I use http://search.cpan.org/~rjray/Image-Size-3.230/lib/Image/Size.pm on my system, so I can obtain the dimensions of an image.
Kind Regards.

("open" wants to mean "opens" at previous comment of mine.)
-- JuanmaMP 2012-5-10 12:46 am

Oh, I see. :-) That's a good idea.
-- Raymundo 2012-5-10 7:56 am

Hi Mr. Raymundo,
this is an intend to implement a new action for admins that returns a list of all pages in order to check or uncheck the lock parameter, having bulk action style.
It works fine for me (big thanks for your snippets).

 
sub PrintPageLockList {
my ($pagename, @pagename);
my ($status, $altname);
my (@results) = @_;
my %hash;

print &GetHeader('', T("'Read' Bulk"), '');
print $q->start_form("post","$ScriptName","");
print "<input type='hidden' name='action' value='lockcheckedfiles'>";
print "<input type='hidden' name='pagename' value='$OpenPageName'>";
print '<ol>';
foreach $pagename (&AllPagesList()) {
next if (&PageIsHidden($pagename));
@pagename = split (/\//,$pagename);
print '<li>';
if (-f &GetLockedPageFile($pagename)) {
print "<input type='checkbox' name='doit' value='$pagename' checked='1'></input> ";
} else {
print "<input type='checkbox' name='doit' value='$pagename' ></input> ";
}
if (!&GetParam('checked') && -f &GetLockedPageFile($pagename)) {
print "<input type='hidden' name='undo' value='$pagename' ></input>" ;
}
for (1 .. $#pagename) {print ' . ',}
print &GetPageLink($pagename);
}
}
print '<br>';
print $q->submit(T('DoIt')) if (&UserIsAdmin());
print $q->endform;
print '</ol>';
print &GetFooterText();
}

sub DoLockCheckedFiles {
my (%vars, %srav, %count, @doit, @undo, @diffs);
my $fname;
my $diffs;

print &GetHeader("", T('Lock Checked Files'), "");
return if (!&UserIsAdminOrError());
%srav = 0;
%srav = $q->Vars;
@undo = split(/\0/,$srav{'undo'}, -1);
%vars = 0;
%vars = $q->Vars;
@doit = split(/\0/,$vars{'doit'}, -1);
# Uncommon elements (changes for submit: check to unchek or viceversa)
map $count{$_}++ , @doit, @undo;
$, = "";
push (@diffs, grep $count{$_} == 1, @doit, @undo);
if (@diffs) {
foreach (@diffs) {
$fname = &GetLockedPageFile($_);
if (-f $fname) {
unlink $fname;
print Ts('%s is unlocked successfully', $_) .'<br>';
next;
}
if (!-f $fname) {
&WriteStringToFile($fname, "editing locked.");
print Ts('%s is locked successfully', $_) .'<br>';
}
}
} else {
print T('Invalid URL or bulk does not exist --nothing done');
}
print &GetFooterText();
}

Good weekend! :)

--JuanmaMP
-- JuanmaMP 2012-5-13 2:40 am

Sorry for $altname, &GetFooterText and perhaps, other oddities coming from my own hacked code.
Regards
-- JuanmaMP 2012-5-13 2:51 am

Hi over there,
a bit polished of this matter, here: UseMod:WikiPatches/BulkLock.
Hope it's fun ...
-- JuanmaMP 2012-5-15 12:59 am

Wow, you're so active in usemod.org! Great! :-D
-- Raymundo 2012-5-15 1:50 am

yep, for the being time, a really peaceful place ... :))
-- JuanmaMP 2012-5-15 2:08 am

the next patch that I would like uploading is "this site is hidden" (visibility under password).
Something like this:
http://www.mydigitallife.info/wp-content/uploads/2008/06/forgot-wordpress-password-266x300.jpg.
I'll share it.
Good night over there.
-- JuanmaMP 2012-5-15 2:21 am

if you prefer erased my last comment to your choice. I wanted uploading a typical login snapshot into a web but finally it returned that thing. Sorry.
-- JuanmaMP 2012-5-15 4:43 pm

LOL, I had to guess 'what is that?' hahaha. It's okay.
-- Raymundo 2012-5-15 9:45 pm
이름:  
Homepage:
내용:
 

위키위키분류

마지막 편집일: 2024-4-29 10:14 am (변경사항 [d])
1727 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기