|
#!/usr/bin/perl # Source Code นี้ใช้งานจริงที่ http://www.thaiall.com/cgi/gallery.pl $update = "ปรับปรุง : 2549-03-04 (ใช้ตัวหลักที่ thaiall.com)"; ########## # ขั้นตอนการนำ Perl Script ไปใช้ # 1. มี Server ที่รองรับภาษา Perl ลองศึกษาได้ที่ http://www.thaiall.com/perl # 2. หาภาพมาจัดเก็บ เช่น dog001.jpg เก็บในห้อง dog # 3. ลดขนาดภาพ แล้วจัดเก็บ เช่น dog001t.jpg เก็บในห้อง dogt # 4. กำหนดตัวแปล เช่น $title[$i]="Dog"; $galt[$i]="dog"; $gale[$i]="dogt"; $i++; # 5. เปลี่ยนตัวแปร $webaddr ตาม Url ที่เก็บภาพของท่าน ########## # Main Configuration # $title[$i]="ชื่อตัวเลือก"; $galt[$i]="ห้องเก็บ Thumbnail"; $gale[$i]="ห้องเก็บ Enlarge"; $i++; $i=0; $title[$i]="Pokemon"; $galt[$i]="pokemon"; $gale[$i]="pokemon"; $i++; $title[$i]="Girl"; $galt[$i]="girlt"; $gale[$i]="girl"; $i++; $title[$i]="Actress"; $galt[$i]="actresst"; $gale[$i]="actresse"; $i++; $title[$i]="People"; $galt[$i]="idt"; $gale[$i]="id"; $i++; $title[$i]="Lampang"; $galt[$i]="nwt"; $gale[$i]="nw"; $i++; $title[$i]="Coolanime"; $galt[$i]="prettyanimet"; $gale[$i]="prettyanime"; $i++; $title[$i]="Wallpaper"; $galt[$i]="wanimet"; $gale[$i]="wanime"; $i++; ########## # กำหนด Server ที่เก็บภาพ # 1. อ่าน Thumbnail จากแฟ้มใน Directory ใน Server เดียวกับที่เก็บ Script # 2. นำ Thumbnail และ Enlarge มาจาก http://www.thaiabc.com # สามารถกำหนดตำแหน่งของภาพด้วย if ($title[$gal] eq "actress") { $webaddr = "http://www.thaiabc.com"} $webaddr = "http://www.thaiabc.com"; ########## # Process Configuration $imax=$i-1; $droot = join '',$ENV{DOCUMENT_ROOT},"/"; &parse_form; ########## # Default of cat # ถ้าไม่กำหนด ?cat=xxx ทำให้ค่าของ $gal เป็น 0 ทำให้กลุ่มแรกคือ "Pokemon" กลายเป็นค่าเริ่มต้น for $j(0..$imax) { if ($v{'cat'} eq $title[$j]) { $gal=$j; } } $gdire=join '',"/",$gale[$gal],"/"; # if ($title[$gal] eq "Pokemon") { $gdire=join '',"/",$v{'cat'},"/"; } else { $gdire=join '',"/",$gale[$gal],"/"; } &getf; ########## $trowcol = $v{'row'} * $v{'col'}; $tot_page = ($tot_pro - ($tot_pro % $trowcol)) / $trowcol + 1; if ($v{'res'} eq '640') { if ($v{'col'} eq '6') {$wd = 80;} if ($v{'col'} eq '7') {$wd = 70;} if ($v{'col'} eq '8') {$wd = 60;} if ($v{'col'} eq '9') {$wd = 55;} } if ($v{'res'} eq '800') { if ($v{'col'} eq '6') {$wd = 110;} if ($v{'col'} eq '7') {$wd = 95;} if ($v{'col'} eq '8') {$wd = 80;} if ($v{'col'} eq '9') {$wd = 70;} } if ($v{'res'} eq '1024') { if ($v{'col'} eq '6') {$wd = 140;} if ($v{'col'} eq '7') {$wd = 120;} if ($v{'col'} eq '8') {$wd = 110;} if ($v{'col'} eq '9') {$wd = 105;} } ########## # Start Content print"Content-type:text/html\n\n"; print'<html><head><title>รวมภาพ ',$title[$gal],'</title>'; print'<meta http-equiv=content-type content="text/html; charset=windows-874">'; print"<meta name=keywords content='gallery,photo,image'>"; print"<meta name=description content='รวมภาพ ห้องสะสมภาพ (Image Gallery)'>"; print'<style type="text/css">',"\n"; print'a:link{color:#ff0000;text-decoration:none;}',"\n"; print'a:visited{color:#800000;text-decoration:none;}',"\n"; print'td{font-size:10pt;font-family:ms sans serif;}',"\n"; print'</style>',"\n"; print'<base target=_blank>'; print'</head><body topmargin=0 leftmargin=0 link="#04669C" vlink="#04669C" alink="#04669C" bgcolor="#046193">'; ########## # Header Title print'<table width=',$v{'res'},' align=center border=0 cellspacing=0 cellpadding=0 bgcolor=#dddddd><tr><td>'; if ($v{'file'}) { print"<font size=6>ภาพขยาย</font>"; } else { print'ห้องสะสมภาพ<br>'; print'เว็บเพจสำรอง (Backup webpages) : '; print'<a href=http://www.thaiall.com/cgi/gallery.pl?row=4&col=6&res=800&seq=asc&cat=actress>thaiall.com</a> | '; print'<a href=http://www.thaiabc.com/ext/gallery.php>thaiabc.com</a> | '; print'<a href=http://www.perlphpasp.com/cgi-bin/gallery.pl>perlphpasp.com</a><br>'; print'</td><td align=right valign=top><a href=http://www.thaiall.com/me>ทีมงาน</a> Tel.0-1992-7223'; print'<br>View : <a href=http://www.thaiall.com/perlphpasp/source.pl?key=9101>Source Code</a></font>'; } print'</td></tr></table>'; ########## # Header menu print'<table width=',$v{'res'},' align=center bgcolor=#808080 border=0 cellpadding=1 cellspacing=1><form action="" action=post target=_top><tr bgcolor=#ddffff>'; if (!$v{'file'}) { print'<td align=center width=100>เลือกหน้าแบบด่วน</td><td align=center>จำนวนบรรทัด</td><td align=center>จำนวนหลัก</td>'; print'<td align=center>ความละเอียด</td><td align=center>จัดเรียง<br>ตามเวลาของแฟ้ม</td><td align=center>ปรับค่าเริ่มต้นใหม่</td>'; print'<td align=center>หน้าที่/ทั้งหมด</td><td align=center>จำนวนภาพ<br>ต่อหน้า</td><td align=center>จำนวน<br>ทั้งหมด</td>'; print"</tr><tr bgcolor=#ffffdd><td align=center>"; if ($tot_page ne '1' and $v{'page'} ne '1') { print'<input type=submit name=page value=1> '; } if ($v{'page'} > "2") { print'<input type=submit name=page value=',$v{'page'}-1,'> '; } if ($tot_page > $v{'page'} and ($tot_page ne $v{'page'} + 1)) { print'<input type=submit name=page value=',$v{'page'} + 1,'> '; } if ($tot_page ne '1' and $tot_page ne $v{'page'}) { print'<input type=submit name=page value=',$tot_page,'> '; } print'</td><td align=center>'; print'<select name=row size=1>'; print'<option value=3 '; if ($v{'row'} eq '3') { print'selected';} print'>3 row'; print'<option value=4 '; if ($v{'row'} eq '4') { print'selected';} print'>4 row'; print'<option value=5 '; if ($v{'row'} eq '5') { print'selected';} print'>5 row'; print'<option value=6 '; if ($v{'row'} eq '6') { print'selected';} print'>6 row'; print'<option value=7 '; if ($v{'row'} eq '7') { print'selected';} print'>7 row'; print'<option value=8 '; if ($v{'row'} eq '8') { print'selected';} print'>8 row'; print'<option value=9 '; if ($v{'row'} eq '9') { print'selected';} print'>9 row'; print'</select></td><td align=center>'; print'<select name=col size=1>'; print'<option value=6 '; if ($v{'col'} eq '6') { print'selected';} print'>6 col'; print'<option value=7 '; if ($v{'col'} eq '7') { print'selected';} print'>7 col'; print'<option value=8 '; if ($v{'col'} eq '8') { print'selected';} print'>8 col'; print'<option value=9 '; if ($v{'col'} eq '9') { print'selected';} print'>9 col'; print'</select></td><td align=center>'; print'<select name=res size=1>'; print'<option value=640 '; if ($v{'res'} eq '640') { print'selected';} print'>640*480'; print'<option value=800 '; if ($v{'res'} eq '800') { print'selected';} print'>800*600'; print'<option value=1024 '; if ($v{'res'} eq '1024') { print'selected';} print'>1024*768'; print'</select></td><td align=center>'; print'<select name=seq size=1>'; print'<option value=asc '; if ($v{'seq'} eq 'asc') { print'selected';} print'>Ascending'; print'<option value=des '; if ($v{'seq'} eq 'des') { print'selected';} print'>Descending'; print'</select></td><td align=center>'; print'<input type=submit value="Update gallery"></td>'; print"<td align=center>$v{'page'} / $tot_page</td><td align=center>", $v{'row'} * $v{'col'} ,"</td><td align=center>$tot_pro</td>"; } print'</tr></table>'; ########## # Left menu print'<table width=',$v{'res'},' align=center border=0 cellpadding=0 cellspacing=0>'; print'<tr><td valign=top width=100 align=center bgcolor=#808080>'; $hr="<hr noshade color=#0000ff>"; print"$hr<input type=submit value='Go gallery'>"; print'<select name=cat size=8>'; for $i(0..$imax) { print"<option value=$title[$i]"; if ($title[$gal] eq $title[$i]) { print" selected";} print">$title[$i]"; } print"</select>$hr เลือกหน้า<div align=left>"; for $i(1..$tot_page) { print'<input type=submit name=page value=',$i,'> '; } print'</div>',$hr,'</form><form action="" target=top><input type=text name=cat size=10 value=Actress><br><input type=submit value="Go directly"></form>'; print'</td><td bgcolor=#000000 width=1></td>'; print'<td bgcolor=#fffffd align=center valign=top><table border=0 cellspacing=0 cellpadding=5 width=100%><td>'; if ($v{'file'}) { # ส่วนนี้แก้ปัญหา thumbnail ชื่อไม่ตรงกับ ภาพขยาย $frn=$v{'file'}; # if ($title[$gal] eq "Actress" or $title[$gal] eq "Girl" or $title[$gal] eq "People" or $title[$gal] eq "Lampang") { if ($title[$gal] ne "Pokemon") { @fr = split ('t\.',$frn); if (@fr > 1) { $frn=join'.',$fr[0],$fr[1]; } } # print"<center><img src=$webaddr$gdire$frn></center>"; } else { for $i(1..$trowcol) { $p = $v{'page'}*$trowcol-$trowcol+$i-1; if ($p<10) { $p=join'','00',$p; } else { if ($p<100) { $p=join'','0',$p; }} if ($p < $tot_pro) { @filetr = split ("\/",$okr[$p]); $filet = $filetr[@filetr - 1]; print'<a href=?cat=',$v{'cat'},'&file=',$filet; print'><img border=0 src=',$webaddr,$okr[$p],' width=',$wd,'></a> ',"\n"; } } } print'</td></tr></table>'; print'</td></tr></table>'; ########## # Footer print'<table width=',$v{'res'},' align=center border=0 cellpadding=0 cellspacing=0 bgcolor=black><td align=center>'; print'<script language=javascript>',"\n"; print'<!--',"\n"; print'url=document.location.href.substr(7,11)',"\n"; print'page="cgi_gallery"',"\n"; print'if(url == "lampang.thc") document.write("<script language=\'javascript1.1\' src=\'http://truehits1.gits.net.th/data/h0013199.js\'></script>")',"\n"; print'if(url == "www.yonok.a") document.write("<script language=\'javascript1.1\' src=\'http://truehits1.gits.net.th/data/c0001943.js\'></script>")',"\n"; print'if(url == "www.thaiall") document.write("<script language=\'javascript1.1\' src=\'http://truehits1.gits.net.th/data/c0001941.js\'></script>")',"\n"; print'if(url == "www.perlphp") document.write("<script language=\'javascript1.1\' src=\'http://truehits1.gits.net.th/data/h0013336.js\'></script>")',"\n"; print'if(url == "thaiall.tha") document.write("<script language=\'javascript1.1\' src=\'http://truehits.gits.net.th/data/k0020653.js\'></script>")',"\n"; print'if(url == "www.thaiabc") document.write("<script language=\'javascript1.1\' src=\'http://truehits1.gits.net.th/data/h0014200.js\'></script>")',"\n"; print'-->',"\n"; print'</script> '; print'<font color=white><a href=http://www.101-idea.com/counterr.php><img src=http://www.101-idea.com/counter1.php border=0></a> ',$update; print'<br>Open Source : ห้องสะสมภาพ (Photo Gallery)</td></table></body></html>',"\n"; ########## sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; $v{$name} = $value; } if (!$v{'cat'}) { $v{'cat'}=$title[0]; } if (!$v{'seq'}) { $v{'seq'}='des'; } if (!$v{'res'}) { $v{'res'}=800; } if (!$v{'col'}) { $v{'col'}=6; } if (!$v{'row'}) { $v{'row'}=3; } if (!$v{'page'}) { $v{'page'}=1; } } ########## sub getf { $gdirt=join '',$droot,$galt[$gal],"/."; opendir(click,"$gdirt"); @allf = readdir click; closedir(click); for $i (0 .. @allf) { $r4 = lc substr($allf[$i],length($allf[$i])-4,4); if (length($allf[$i]) > 4 and ($r4 eq ".jpg" or $r4 eq ".gif")) { $pp = join '',"/",$galt[$gal],"/",$allf[$i]; push @okr,$pp; } } if ($v{'seq'} eq "des") { @okr = reverse( sort { $a <=> $b } @okr ); } $tot_pro = @okr; } |