Changeset 855 for pro-violet-viettel


Ignore:
Timestamp:
Mar 30, 2015 3:26:43 PM (10 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php

    r826 r855  
    140140    }
    141141
    142     private function ChangeParentDir($item, $destination) {
     142    private function changeParentDir($item, $destination) {
    143143        if ($item->type == 'directory') {
    144144            $tblfile = TblspacefilePeer::retrieveByPk($item->id);
     
    154154        return $item;
    155155    }
    156 
    157     private function CreatePreview($fileurl, $userId, $fileid) {
    158         $url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . "";
    159         file_put_contents("1.html", $url);
    160         $content="";
    161         $ch = curl_init();
    162         curl_setopt($ch, CURLOPT_URL, $url);
    163         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    164         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    165         $content = curl_exec($ch);
    166         file_put_contents("1.html", $content);
    167         preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches);
    168         $count=0;
    169         if (isset($matches[1]))
    170         {
    171                 $id = $matches[1];
    172                 $count=0;
    173                 for ($i = 0; $i <= 20; $i++) {
    174                         $imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i;
    175                         $ch = curl_init();
    176                         curl_setopt($ch, CURLOPT_URL, $imgurl);
    177                         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    178                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    179                         $image = curl_exec($ch);
    180                         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    181                         if ($code == 200)
    182                         {
    183    
    184                                 $count++;
    185                                 if (!file_exists('previews/'. $userId."/")) {
    186                                         mkdir('previews/'. $userId."/", 0777, true);
    187                                 }
    188    
    189                                 if (!file_exists('previews/'. $userId."/".$fileid."/")) {
    190    
    191                                         mkdir('previews/'. $userId."/".$fileid."/", 0777, true);
    192    
    193                                 }
    194                                 file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image);
    195    
    196                         } else {
    197                                 break;
    198                         }
    199                 }
    200    
    201         }
    202         return $count;
    203     }   
    204    
    205156    public function executePreview(){
    206157        $fileId = $this->getRequestParameter('fileId');
     
    219170            $fileName = $tblres->getFullFilename();
    220171            $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $fileName);
    221             $count=$this->CreatePreview($fileUrl, $userId, $fileId);
     172            $count=$this->createPreview($fileUrl, $userId, $fileId);
    222173        }
    223174        $data['fileid']=$fileId;
     
    395346                    }
    396347                } else if ($act == 'move') {
    397                     $this->ChangeParentDir($treeObj, $destination);
     348                    $this->changeParentDir($treeObj, $destination);
    398349                    if ($treeObj->type == 'directory')
    399350                        $aryNewTree['DIRECTORIES'][] = $treeObj;
     
    427378        $fileError = $this->getRequest()->hasFileError($file);
    428379        $fileErrorNum = $this->getRequest()->getFileError($file);
    429 
    430380        if ($fileErrorNum || $fileError)
    431381            return false;
     
    449399        $ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
    450400        $ext = strtolower($ext);
     401       
    451402        if (in_array($ext, array("ppt","xls","doc","pdf","docx","pptx","xlsx")))
    452403        {
    453             $this->CreatePreview($fileUrl, $userId, $tblfile->getFileId());
    454         }
     404            $this->createPreview($fileUrl, $userId, $tblfile->getFileId());
     405        }
     406       
    455407        if ($response == 1) {
    456408            $aryError = array('err' => "", 'errCode' => 0);
     
    465417            );
    466418            $aryData = array('DIRECTORIES' => array(), 'FILES' => $aryFiles, 'ERROR' => $aryError);
    467             echo json_encode($aryData);
     419           
     420            $jsonData = json_encode($aryData);
     421            echo $jsonData;
    468422        }
    469423
    470424        return sfView::NONE;
     425    }
     426
     427    private function createPreview($fileurl, $userId, $fileid) {
     428
     429       
     430        $url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . "";
     431        file_put_contents("1.html", $url);
     432        $content="";
     433        $ch = curl_init();
     434        curl_setopt($ch, CURLOPT_URL, $url);
     435        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     436        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     437        $content = curl_exec($ch);
     438       file_put_contents("1.html", $content);
     439        preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches);
     440        $count=0;
     441        if (isset($matches[1]))
     442        {
     443        $id = $matches[1];
     444        $count=0;
     445        for ($i = 0; $i <= 20; $i++) {
     446            $imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i;
     447            $ch = curl_init();
     448            curl_setopt($ch, CURLOPT_URL, $imgurl);
     449            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     450            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     451            $image = curl_exec($ch);
     452            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     453            if ($code == 200)
     454            {
     455               
     456                $count++;
     457                if (!file_exists('previews/'. $userId."/")) {
     458                    mkdir('previews/'. $userId."/", 0777, true);
     459                }
     460               
     461                if (!file_exists('previews/'. $userId."/".$fileid."/")) {
     462                   
     463                    mkdir('previews/'. $userId."/".$fileid."/", 0777, true);
     464                   
     465                }
     466                file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image);
     467
     468            } else {
     469                break;
     470            }
     471        }
     472       
     473        }
     474        return $count;
    471475    }
    472476
     
    539543        return sfView::NONE;
    540544    }
    541 
     545    public function executeGetFiles()
     546    {
     547       $tblfile = TblspacefilePeer::retrieveByPk(64);
     548       print_r($tblfile);
     549      return sfView::NONE;
     550    }
    542551}
    543552
Note: See TracChangeset for help on using the changeset viewer.