CMSimple Drupal Yii 內容管理系統三方案 - 提升台灣中小企業競爭力

目前位置:   首頁 > Use CMSimple > CMSimple延伸模組 > Gallery Plugin 程式碼

Gallery Plugin 程式碼

function gallery($dir) {
global $dir_location;
    $action=$_GET['action'];
    if ($action=="rotate")
    {
        $the_file=$_GET['file'];
        do_rotate($the_file);
        return "done rotate";
    }
    elseif ($action=="rotate2")
    {
        $the_file=$_GET['file'];
        do_rotate2($the_file);
        return "done rotate2";
    }
    elseif ($action=="delete")
    {
        $the_file=$_GET['file'];
        do_delete($the_file);
        return "done delete";
    }
    else
    {
//這是影像檔位於CMSimple根目錄下的目錄名稱,相對於$dir_location,thumb檔則放在$dir_location."_thumb"
    //$dir_location="./photo2/";
$dir_location=$dir;
    $string="<table border='0' cellpadding='5' cellspacing='5'>";
$string.=ls_recursive($dir_location);
    $string.="</table>";
    //$string.="<br>".$_GET['file'];
    return $string;
    }
}
function ls_recursive($dir)
{
    global $string,$sn,$su;
    global $sub_dirname;
        global $total_number;
    //初始值設定;
    $num_in_a_row=5;
    $i=1;
    $k=0;
    $thumb_dir=trim($dir,"/")."_thumb/";
$picture=array();
  if (is_dir($dir))
  {
   $files = scandir($dir);
         
   foreach ($files as $file)
   {
     $currentfile = $dir.$file."/";
  
     if (is_dir($currentfile))
     {        
       if ($file != '.' && $file != '..')
       {
          ls_recursive($currentfile);
       }
     }
     else
    {
        //進入這裡表示進入目錄讀檔案
      $is_graphics=eregi(".gif|.GIF|.jpg|.JPG|.png|.PNG",$file);
         if($is_graphics)
         {
         /*
         if($i%$num_in_a_row==0){$string.="<tr>";}
         //為了順利處理檔名為中文的圖檔,將big5碼轉為utf-8
         $utf_filename=iconv("big5","utf-8",$file);
         $string.="<td>".$i."<a href=".$sn."?".$su."&file=".$utf_filename."&action=rotate>r</a> | <a href=".$sn."?".$su."&file=".$utf_filename."&action=rotate2>r2</a> | <a href=".$sn."?".$su."&file=".$utf_filename."&action=delete>d</a><br><a href=".$dir.$utf_filename."><img src=".$thumb_dir.$utf_filename."></a></td>";
         $i++;
         if($i%$num_in_a_row==0){$string.="</tr>";}
         */
         //為了順利處理檔名為中文的圖檔,將big5碼轉為utf-8
         $utf_filename=iconv("big5","utf-8",$file);
         $picture[$i]=$utf_filename;
         $i++;
         }
   }
  }
 }
//開始進行分頁的設計
if (isset($_GET['page']))
{
$page=$_GET['page'];
}
else
{
$page=1;
}
if(isset($_GET['item_per_page']))
{
$item_per_page=$_GET['item_per_page'];
}
else
{
$item_per_page=40;
}
$total_number=$i-1;
if (($total_number % $item_per_page)==0)
$totalpage=$total_number/$item_per_page;
else
$totalpage=(int)($total_number/$item_per_page)+1;
$starti = $item_per_page * ($page - 1)+1 ;
$endi = $starti + $item_per_page - 1;
If ((int)($page * $item_per_page) < $total_number)
{
$notlast = true;
$output.=picturelist($picture,$starti,$endi);
}
else
{
// this is the last page
$output.=picturelist($picture,$starti,$total_number);
}
$output.="</table>";
If ($page > 1)
{
$page_num=$page-1;
$page_output="<a href=".$sn."?".$su."&page=1&item_per_page=".$item_per_page.">|<</a>  <a href=";
$page_output.=$sn."?".$su."&page=".$page_num."&item_per_page=".$item_per_page;
$page_output.=">上一頁</a>  ";
}
for($j=0;$j<$totalpage;$j++)
{
$page_now=$j+1;
// $totalpage=1不印
if($totalpage==1)
{
}
else
{
if($page_now==$page)
{
$page_output.="<b><font color=red> ".$page." </font></b>";
}
else
{
$page_output.=" <a href=".$sn."?".$su."&page=".$page_now."&item_per_page=".$item_per_page;
$page_output.=">".$page_now."</a> ";
}
}
}
If ($notlast == true)
{
$nextpage=$page+1;
$page_output.="  <a href=";
$page_output.=$sn."?".$su."&page=".$nextpage."&item_per_page=".$item_per_page;
$page_output.=">下一頁</a>  <a href=".$sn."?".$su."&page=".$totalpage."&item_per_page=".$item_per_page.">>|</a>";
}
$string.=$page_output;
$string.=$output;
$string.=$page_output;
/*
 //在此show出所有的$picture[]
 for ($j=0;$j<$i;$j++)
 {
     if($k%$num_in_a_row==0){$string.="<tr>";}
     $string.="<td><img src=".$thumb_dir.$picture[$j]."></td>";
     $k++;
     if($k%$num_in_a_row==0){$string.="</tr>";}
 }
*/
  return $string;
}
function picturelist($picture,$from,$to)
{
global $dir_location;
global $total_number;
$string.="  全部".$total_number."張中的第<b><font color=red>".$from."</font></b>張到第<b><font color=red>".$to."</font></b>張圖";
$string.="<br>";
$width=5;
for($i=$from;$i<=$to;$i++)
{
$mod=$i%$width;
if($mod==1)
{
$string.="<tr>";
}
$string.="<td>";
$string.=$i."<br>";
$string.="<a href="".$dir_location."/".$picture[$i].""><img src="".trim($dir_location,"/")."_thumb/".$picture[$i]."" border="0"></a>";
/*
//這裡要列出刪除的連結
$output.="<a href="delete.php?file=".$picture[$i]."">d</a> ";
//echo "<br>";
//這裡要列出旋轉圖面的連結(-90度)
$output.="<a href="rotate.php?file=".$picture[$i]."">-90</a> ";
//這裡要列出旋轉圖面的連結(+90度)
$output.="<a href="rotate2.php?file=".$picture[$i]."">+90</a>";
*/
$string.="</td>";
if ($mod==0)
{
$string.="</tr>";
}
}
return $string;
}
function rotateImage($src, $count = 1, $quality = 95)
{
   if (!file_exists($src)) {
       return false;
   }
   list($w, $h) = getimagesize($src);
   if (($in = imageCreateFromJpeg($src)) === false) {
       echo "Failed create from source<br>";
       return false;
   }
   $angle = 360 - ((($count > 0 && $count < 4) ? $count : 0 ) * 90);
   if ($w == $h || $angle == 180) {
       $out = imageRotate($in, $angle, 0);
   } elseif ($angle == 90 || $angle == 270) {
       $size = ($w > $h ? $w : $h);
       // Create a square image the size of the largest side of our src image
       if (($tmp = imageCreateTrueColor($size, $size)) == false) {
           echo "Failed create square trueColor<br>";
           return false;
       }
       // Exchange sides
       if (($out = imageCreateTrueColor($h, $w)) == false) {
           echo "Failed create trueColor<br>";
           return false;
       }
       // Now copy our src image to tmp where we will rotate and then copy that to $out
       imageCopy($tmp, $in, 0, 0, 0, 0, $w, $h);
       $tmp2 = imageRotate($tmp, $angle, 0);
       // Now copy tmp2 to $out;
       imageCopy($out, $tmp2, 0, 0, ($angle == 270 ? abs($w - $h) : 0), 0, $h, $w);
       imageDestroy($tmp);
       imageDestroy($tmp2);
   } elseif ($angle == 360) {
       imageDestroy($in);
       return true;
   }
   imageJpeg($out, $src, $quality);
   imageDestroy($in);
   imageDestroy($out);
   return true;
}
function do_rotate2($file)
{
    //必須要將thumb與new_files中的圖面同時旋轉
   
    //$dirname=dirname(__FILE__);
    $dirname="./";
    $filename=$_GET["file"];
    $thumbfile = $dirname."photo_thumb".$filename;
    $newfile = $dirname."photo".$filename;
rotateImage2($thumbfile,2,100);
rotateImage2($newfile,2,100);
rotateImage2($thumbfile,3,100);
rotateImage2($newfile,3,100);
}
function rotateImage2($src, $count = 1, $quality = 95)
{
   if (!file_exists($src)) {
       return false;
   }
   list($w, $h) = getimagesize($src);
   if (($in = imageCreateFromJpeg($src)) === false) {
       echo "Failed create from source<br>";
       return false;
   }
   $angle = 360 - ((($count > 0 && $count < 4) ? $count : 0 ) * 90);
   if ($w == $h || $angle == 180) {
       $out = imageRotate($in, $angle, 0);
   } elseif ($angle == 90 || $angle == 270) {
       $size = ($w > $h ? $w : $h);
       // Create a square image the size of the largest side of our src image
       if (($tmp = imageCreateTrueColor($size, $size)) == false) {
           echo "Failed create square trueColor<br>";
           return false;
       }
       // Exchange sides
       if (($out = imageCreateTrueColor($h, $w)) == false) {
           echo "Failed create trueColor<br>";
           return false;
       }
       // Now copy our src image to tmp where we will rotate and then copy that to $out
       imageCopy($tmp, $in, 0, 0, 0, 0, $w, $h);
       $tmp2 = imageRotate($tmp, $angle, 0);
       // Now copy tmp2 to $out;
       imageCopy($out, $tmp2, 0, 0, ($angle == 270 ? abs($w - $h) : 0), 0, $h, $w);
       imageDestroy($tmp);
       imageDestroy($tmp2);
   } elseif ($angle == 360) {
       imageDestroy($in);
       return true;
   }
   imageJpeg($out, $src, $quality);
   imageDestroy($in);
   imageDestroy($out);
   return true;
}
function do_delete($file)
{
    $dirname="./";
    $filename=$_GET["file"];
    $thumbfile = $dirname."photo_thumb".$filename;
    $newfile = $dirname."photo".$filename;
$command="del ".$thumbfile;
exec($command,$status);
$command1="del ".$newfile;
exec($command1,$status);   
}

 

 

Powered by CMSimple_XH| Template: ge-webdesign.de| 登入