diff options
Diffstat (limited to 'lib/import.pm')
| -rw-r--r-- | lib/import.pm | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/lib/import.pm b/lib/import.pm new file mode 100644 index 0000000..7edefdc --- /dev/null +++ b/lib/import.pm @@ -0,0 +1,204 @@ +sub situate_imports + { + my ($pid, $uname) = @_; + my ($filename, $size, $date); + my $newfilename; + my $tempsubdir; + my $totalsize = 0; + my @stats; + + open T, ">$temp_path/.importnow"; + close T; + system($SYSTEM_CHMOD, "0777", "$temp_path/.importnow"); + print "Waiting to import...<br>" if ($DEBUG); + while (-e "$temp_path/.importnow") + { sleep(1); } + print "Setting permissions...<br>" if ($DEBUG); + while (-e "$temp_path/.importing") + { sleep(1); } + print "Ready to import!<br>" if ($DEBUG); + + foreach my $k (keys %$input) + { + next if ($k !~ /^imp/); + next if (! -e $temp_path."/".$$input{$k}); + $filename = $$input{$k}; + + if (! -e $data_path."/".$pid) + { + print "creating $data_path/$pid<br>\n" if $DEBUG; + system("$MKDIR_PATH", $data_path."/".$pid); + system("$MKDIR_PATH", $data_path."/".$pid."/.thumb"); + system("$CHMOD_PATH", "755", $data_path."/".$pid); + system("$CHMOD_PATH", "755", $data_path."/".$pid."/.thumb"); + } + + print $filename."<br>" if ($DEBUG); + + @stats = stat($temp_path."/".$filename); + $size = $stats[7]; + $date = $stats[9]; + $newfilename = $filename; + $newfilename =~ s/^(.*)\///; + $tempsubdir = $1; + + if (-e $data_path."/".$pid."/".$newfilename) + { + my $tfile = "another-$newfilename"; + my $i = 2; + while (-e $data_path."/".$pid."/".$tfile) + { + $tfile = $newfilename; + $tfile =~ s/(\....)$/-$i$1/; + $i++; + } + $newfilename = $tfile; + } + + system($MV_PATH, $temp_path."/".$filename, $data_path."/".$pid."/".$newfilename); + add_file($pid, $uname, $newfilename, $size, $date); + $totalsize += $size; + } + update_thread_size($pid); + flush_imports($tempsubdir); + } + +sub flush_imports + { + while ($tsd) + { + foreach my $d (recurse_imports($temp_path."/".$tsd."/")) + { + if (! -d $temp_path."/".$tsd."/".$d) + { print "Files still in $tsd, will not flush!<br>" if $DEBUG; return; } + } + system($RM_PATH, "-rf", $temp_path."/".$tsd); + return if ($tsd !~ /\//); + $tsd =~ s/^(.*)\///; + $tsd = $1; + } + } + + +sub list_imports + { + my $r = 0; + my $i = 0; + my $size = 0; + my $inc = 0; + my $title = ""; + my $files; + + print <<FILES; +<center> +<table border=0 cellpadding=0 cellspacing=0 class="main"> + <tr> + <td class="head"> </td> + <td class="head" align="left" nowrap> <b>Name</b><img src="/blank.gif" height="1" width="200"></td> + <td class="head"></td> + <td class="head" align="left" nowrap><b>Date</b></td> + <td class="head" align="right"> <b>Size</b> </td> + </tr> +FILES + + @files = recurse_imports($temp_path."/"); + + foreach $file (sort @files) + { + if (-d $temp_path."/".$file) + { + if ($file =~ /$title\//) + { + $file =~ s/^.*\///; + $title .= " - $file"; + } + else + { $title = $file; } + next; + } + my @stats = stat($temp_path."/".$file); + $inc += display_import({filename => $file, date => $stats[9], size => $stats[7]}, $r, $i); + $size += $stats[7]; + $r = $r ? 0 : 1; + $i++; + } + + print qq!<tr><td colspan=5 align="right" style="border-top: 1px dotted #ccc;">total size: !.(sprintf "%0.1fmb",$size/1000000).qq!</td></tr></table></center>\n\n!; + + return ($title, $inc, $size); + } + +sub recurse_imports + { + my $d = shift; + return unless (-d $d); + my @files; + + opendir (DIR, $d) or die "couldn't list: $d, $!"; + @files = grep (!/^\./, sort readdir (DIR)); + closedir DIR; + + foreach my $f (@files) + { + push @files, + map { $f . "/" . $_ } + recurse_imports($d.$f); + } + + return @files; + } + +sub display_import + { + my ($f, $r, $i) = @_; + my $color; + my $inc = 0; + + if (abs(time - $$f{date}) < 5) # incomplete! use abs in case these are files from THE FUTURE! + { $color = "incomplete"; $inc = 1; } + elsif ((time - $$f{date}) < 86400) # modified today + { $color = "new"; } + elsif ((time - $$f{date}) < 604800) # modifed this week + { $color = "recent"; } + elsif ((time - $$f{date}) < 1209600) # modifed 2 weeks ago + { $color = "old"; } + else + { $color = "quiet"; } + + print qq[<tr class="row$r">]; + if ($color eq "incomplete") + { + print qq[<td align="right"> </td>]; + print '<td></td>'; + print qq[<td align="left" nowrap> <i>$$f{filename}</i></td>]; + print qq[<td align="left" nowrap><i>]. (verbosedate($$f{date})), qq[</i></td>]; + print qq[<td align="right"><i> $$f{size}</i> </td>]; + } + else + { + if ($f->{filename} =~ /^temp_/) + { print qq[<td align="right"> </td>]; } + else + { print qq[<td align="right"><input type="checkbox" name="import$i" value="$$f{filename}"></td>]; } + if ($f->{filename} =~ /jpg|gif|png$/) + { + #print "<td><img src='/bucky/data/incoming/$$f{filename}' width=150></td>"; + print '<td></td>'; + } + else + { + print '<td></td>'; + } + print qq[<td align="left" nowrap> ]; + print qq[<a href="/bucky/data/incoming/$$f{filename}" target="_blank">$$f{filename}</a></td>]; + print qq[<td align="left" nowrap><span class="$color">]. (verbosedate($$f{date})), qq[</span></td>]; + print qq[<td align="right"> $$f{size} </td>]; + } + + print qq[</tr>\n]; + + return $inc; + } + +1; + |
