Changeset 894 for pro-violet-viettel
- Timestamp:
- Apr 16, 2015 11:47:15 AM (10 years ago)
- Location:
- pro-violet-viettel/www/deploy/api/platform
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php
r784 r894 38 38 } 39 39 } 40 public function createThumb($pathToImage="") { 41 42 if (is_file($pathToImage)) { 43 44 $info = pathinfo($pathToImage); 45 $extension = strtolower($info['extension']); 46 47 if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) { 48 49 switch ($extension) { 50 case 'jpg': 51 $img = imagecreatefromjpeg("{$pathToImage}"); 52 break; 53 case 'jpeg': 54 $img = imagecreatefromjpeg("{$pathToImage}"); 55 break; 56 case 'png': 57 $img = imagecreatefrompng("{$pathToImage}"); 58 break; 59 case 'gif': 60 $img = imagecreatefromgif("{$pathToImage}"); 61 break; 62 default: 63 $img = imagecreatefromjpeg("{$pathToImage}"); 64 } 65 list($width, $height) = getimagesize($pathToImage); 66 $new_width = 64; 67 $new_height = 50; 68 $image_p = imagecreatetruecolor($new_width, $new_height); 69 70 imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 71 $thumnail = $info['dirname']."/".$info['filename']."_thumb.jpg"; 72 imagejpeg($image_p,$thumnail, 30); 73 return str_replace("/srv/www/violet/web/", "", $thumnail); 74 } else { 75 return ""; 76 } 77 } else { 78 return ""; 79 } 80 81 return sfView::NONE; 82 } 40 83 } -
pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php
r887 r894 20 20 21 21 private function createImateThumbnail($fileName, &$thumnail = '') { 22 $thumnailPath = dirname($fileName); 23 $rawFileName = str_replace($thumnailPath, '', $fileName); 24 $thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg'; 25 list($width, $height) = getimagesize($fileName); 26 $new_width = 64; 27 $new_height = 50; 28 $image_p = imagecreatetruecolor($new_width, $new_height); 29 $image = imagecreatefromjpeg($fileName); 30 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 31 $thumnail = $thumnailPath.$thumbnailfileName; 32 return imagejpeg($image_p, $thumnailPath.$thumbnailfileName, 30); 33 } 34 35 private function autoDirName ($folderName, $parentId, $userId) { 36 37 $c = new Criteria(); 38 $c->add(TblspacecategoryPeer::CAT_PARENT, $parentId); 39 $c->add(TblspacecategoryPeer::CAT_USER, $userId); 40 $c->add(TblspacecategoryPeer::CAT_NAME, $folderName); 41 $category = TblspacecategoryPeer::doSelectOne($c); 42 43 if (!is_null($category)) { 44 $newFolderName = 'Copy of ' . $folderName; 45 $folderName = $this->autoDirName($newFolderName, $parentId, $userId); 46 } 47 48 return $folderName; 22 $thumnailPath = dirname($fileName); 23 $rawFileName = str_replace($thumnailPath, '', $fileName); 24 $thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg'; 25 list($width, $height) = getimagesize($fileName); 26 $new_width = 64; 27 $new_height = 50; 28 $image_p = imagecreatetruecolor($new_width, $new_height); 29 $image = imagecreatefromjpeg($fileName); 30 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 31 $thumnail = $thumnailPath . $thumbnailfileName; 32 return imagejpeg($image_p, $thumnailPath . $thumbnailfileName, 30); 33 } 34 35 public function executeTest($pathToImage="") { 36 echo violetUtil::createThumb("/srv/www/violet/web/uploads/space/4/4067/1.jpg"); 37 return sfView::NONE; 38 } 39 40 private function autoDirName($folderName, $parentId, $userId) { 41 42 $c = new Criteria(); 43 $c->add(TblspacecategoryPeer::CAT_PARENT, $parentId); 44 $c->add(TblspacecategoryPeer::CAT_USER, $userId); 45 $c->add(TblspacecategoryPeer::CAT_NAME, $folderName); 46 $category = TblspacecategoryPeer::doSelectOne($c); 47 48 if (!is_null($category)) { 49 $newFolderName = 'Copy of ' . $folderName; 50 $folderName = $this->autoDirName($newFolderName, $parentId, $userId); 51 } 52 53 return $folderName; 49 54 } 50 55 … … 115 120 116 121 private function CopySpaceDir($sourceObj, $destination, $userId, &$aryNewTree) { 117 error_log(date('YmdHis').' - Source Obj: '.var_export($sourceObj, TRUE), 3, '/srv/www/sgb/log/file.log');118 122 error_log(date('YmdHis') . ' - Source Obj: ' . var_export($sourceObj, TRUE), 3, '/srv/www/sgb/log/file.log'); 123 $dirId = $sourceObj->id; 119 124 $c = new Criteria(); 120 125 $c->add(TblspacecategoryPeer::CAT_ID, $dirId); … … 133 138 134 139 if (isset($sourceObj->childDirs)) { 135 136 $this->CopySpaceDir($dir, $newDir->id, $userId, $aryNewTree);137 140 foreach ($sourceObj->childDirs as $key => $dir) { 141 $this->CopySpaceDir($dir, $newDir->id, $userId, $aryNewTree); 142 } 138 143 } 139 144 140 145 if (isset($sourceObj->childFiles)) { 141 foreach ($sourceObj->childFiles as $key => $file) { 142 $aryNewTree['FILES'][] = $this->CopySpaceFile($file->id, $newDirID, $userId); 143 } 144 } 145 146 foreach ($sourceObj->childFiles as $key => $file) { 147 $aryNewTree['FILES'][] = $this->CopySpaceFile($file->id, $newDirID, $userId); 148 } 149 } 146 150 } 147 151 … … 166 170 $res = TblspaceresourcePeer::doSelectOne($c); 167 171 168 $thumbnailUrl = file_exists("previews/$userId/" .$tblfile->getFileId()."/0.png") ? "http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png" : '';172 $thumbnailUrl = file_exists("previews/$userId/" . $tblfile->getFileId() . "/0.png") ? "http://sbgapi.violet.vn/previews/$userId/" . $tblfile->getFileId() . "/0.png" : ''; 169 173 170 174 $newFile = new stdClass(); … … 196 200 197 201 private function createPreview($fileurl, $userId, $fileid) { 198 $url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . ""; 199 file_put_contents("1.html", $url); 200 $content=""; 201 $ch = curl_init(); 202 curl_setopt($ch, CURLOPT_URL, $url); 203 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 204 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 205 $content = curl_exec($ch); 206 file_put_contents("1.html", $content); 207 preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches); 208 $count=0; 209 if (isset($matches[1])) 210 { 211 $id = $matches[1]; 212 $count=0; 213 for ($i = 0; $i <= 20; $i++) { 214 $imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i; 215 $ch = curl_init(); 216 curl_setopt($ch, CURLOPT_URL, $imgurl); 217 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 218 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 219 $image = curl_exec($ch); 220 $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 221 if ($code == 200) 222 { 223 224 $count++; 225 if (!file_exists('previews/'. $userId."/")) { 226 mkdir('previews/'. $userId."/", 0777, true); 227 } 228 229 if (!file_exists('previews/'. $userId."/".$fileid."/")) { 230 231 mkdir('previews/'. $userId."/".$fileid."/", 0777, true); 232 233 } 234 file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image); 235 236 } else { 237 break; 238 } 239 } 240 241 } 242 return $count; 243 } 244 245 public function executePreview(){ 202 $url = "https://docs.google.com/gview?url=" . urlencode($fileurl) . ""; 203 file_put_contents("1.html", $url); 204 $content = ""; 205 $ch = curl_init(); 206 curl_setopt($ch, CURLOPT_URL, $url); 207 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 208 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 209 $content = curl_exec($ch); 210 file_put_contents("1.html", $content); 211 preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches); 212 $count = 0; 213 if (isset($matches[1])) { 214 $id = $matches[1]; 215 $count = 0; 216 for ($i = 0; $i <= 20; $i++) { 217 $imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i; 218 $ch = curl_init(); 219 curl_setopt($ch, CURLOPT_URL, $imgurl); 220 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 221 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 222 $image = curl_exec($ch); 223 $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 224 if ($code == 200) { 225 226 $count++; 227 if (!file_exists('previews/' . $userId . "/")) { 228 mkdir('previews/' . $userId . "/", 0777, true); 229 } 230 231 if (!file_exists('previews/' . $userId . "/" . $fileid . "/")) { 232 233 mkdir('previews/' . $userId . "/" . $fileid . "/", 0777, true); 234 } 235 file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image); 236 } else { 237 break; 238 } 239 } 240 } 241 return $count; 242 } 243 244 public function executePreview() { 246 245 $fileId = $this->getRequestParameter('fileId'); 247 246 $userId = $this->getRequestParameter('userId'); … … 251 250 $currentFile = TblspacefilePeer::doSelectOne($c); 252 251 253 $files = scandir("previews/".$userId."/".$fileId); 254 $count=(count($files)-2); 255 256 if ($count < 1) 257 { 252 $files = scandir("previews/" . $userId . "/" . $fileId); 253 $count = (count($files) - 2); 254 255 if ($count < 1) { 258 256 $tblres = TblspacefilePeer::retrieveByPk($fileId)->getTblspaceresource(); 259 257 $fileName = $tblres->getFullFilename(); 260 258 $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $fileName); 261 $count =$this->createPreview($fileUrl, $userId, $fileId);262 } 263 $data['fileid'] =$fileId;264 $data['folder'] ="previews/".$userId."/".$fileId;265 $data['total'] =$count;259 $count = $this->createPreview($fileUrl, $userId, $fileId); 260 } 261 $data['fileid'] = $fileId; 262 $data['folder'] = "previews/" . $userId . "/" . $fileId; 263 $data['total'] = $count; 266 264 echo json_encode($data); 267 265 return sfView::NONE; … … 307 305 $c->add(TblspacefilePeer::FILE_TYPE, explode(';', $filter), Criteria::IN); 308 306 $c->addAscendingOrderByColumn(TblspacefilePeer::FILE_NAME); 309 $this->userId = $userId;307 $this->userId = $userId; 310 308 $this->tblfiles = TblspacefilePeer::doSelect($c); 311 309 $this->isGetAll = $isGetAll; … … 315 313 316 314 public function executeMkdir() { 317 315 $objNewDir = null; 318 316 $userId = $this->getRequestParameter('userid'); 319 317 $parentId = $this->getRequestParameter('parent_id'); … … 403 401 if ($tblfile) 404 402 $tblfile->delete(); 405 $dirPath ="previews/$userId/$id/";403 $dirPath = "previews/$userId/$id/"; 406 404 array_map('unlink', glob("$dirPath/*.*")); 407 405 rmdir($dirPath); … … 429 427 if (is_array($aryTreeObj)) { 430 428 foreach ($aryTreeObj as $key => $treeObj) { 431 if ($act == 'copy') { 432 if ($treeObj->type == 'directory'){ 433 $this->CopySpaceDir($treeObj, $destination, $userId, $aryNewTree); 434 } 435 else { 436 $newFile = $this->CopySpaceFile($treeObj->id, $destination, $userId); 437 $aryNewTree['FILES'][] = $newFile; 438 } 439 } 429 if ($act == 'copy') { 430 if ($treeObj->type == 'directory') { 431 $this->CopySpaceDir($treeObj, $destination, $userId, $aryNewTree); 432 } else { 433 $newFile = $this->CopySpaceFile($treeObj->id, $destination, $userId); 434 $aryNewTree['FILES'][] = $newFile; 435 } 436 } 440 437 } 441 438 } … … 444 441 $this->errCode = ''; 445 442 $this->aryNewTree = $aryNewTree; 446 error_log(date('YmdHis') .' - $aryNewTree: '.var_export($aryNewTree, TRUE), 3, '/srv/www/sbg/log/file.log');443 error_log(date('YmdHis') . ' - $aryNewTree: ' . var_export($aryNewTree, TRUE), 3, '/srv/www/sbg/log/file.log'); 447 444 } 448 445 … … 487 484 $ext = strtolower($ext); 488 485 489 if (in_array($ext, array("ppt","xls","doc","pdf","docx","pptx","xlsx"))) 490 { 486 if (in_array($ext, array("ppt", "xls", "doc", "pdf", "docx", "pptx", "xlsx"))) { 491 487 $this->createPreview($fileUrl, $userId, $tblfile->getFileId()); 492 488 } 493 489 494 if (in_array($ext, array("jpg", "jpeg", "png","gif","tiff","dvg","bmp"))) 495 { 496 $thumbnail = ''; 497 $this->createImateThumbnail($filePath, $thumnail); 498 } 490 499 491 500 492 if ($response == 1) { 501 493 $aryError = array('err' => "", 'errCode' => 0); 502 494 $ext = pathinfo($fileUrl, PATHINFO_EXTENSION); 503 $thumbnail=""; 504 if (file_exists("previews/$userId/".$tblfile->getFileId()."/0.png")) 505 { 506 $thumbnail="http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png"; 495 $thumbnail = ""; 496 if (in_array($ext, array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) { 497 $thumbnail=violetUtil::createThumb($filePath); 498 } 499 if (file_exists("previews/$userId/" . $tblfile->getFileId() . "/0.png")) { 500 $thumbnail = "previews/$userId/" . $tblfile->getFileId() . "/0.png"; 507 501 } 508 502 $aryFiles = array( 509 0 => array('id' => $tblfile->getFileId(), 'thumbnail'=>$thumbnail, 'fileurl' => $fileUrl, 'name' => $fileName, 'minetype' => $ext, 'size' => $fileSize, 'parentID' => $catId),503 0 => array('id' => $tblfile->getFileId(), 'thumbnail' => $thumbnail, 'fileurl' => $fileUrl, 'name' => $fileName, 'minetype' => $ext, 'size' => $fileSize, 'parentID' => $catId), 510 504 ); 511 505 $aryData = array('DIRECTORIES' => array(), 'FILES' => $aryFiles, 'ERROR' => $aryError); -
pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php
r890 r894 23 23 $tblres = TblspacefilePeer::retrieveByPk($tblfile->getFileId())->getTblspaceresource(); 24 24 $fileName = $tblres->getFullFilename(); 25 //$fileName = str_replace('/srv/www/violet/web', '', $fileName);26 $fileName = str_replace(dirname(dirname(dirname( $fileName))), '', $fileName);27 //$fileName = 'http://sbgapi.violet.vn'.$fileName;25 // $fileName = str_replace('/srv/www/violet/web', '', $fileName); 26 $fileName = str_replace(dirname(dirname(dirname(dirname(dirname($fileName))))), '', $fileName); 27 // $fileName = 'http://sbgapi.violet.vn'.$fileName; 28 28 $fileNames = explode("/", $fileName); 29 29 $name=$fileNames[(count($fileNames)-1)]; 30 30 $fileName = str_replace($name, "", $fileName). $name; 31 $ext = strtolower($tblfile->getFileType()); 32 $filePath=""; 31 33 $thumbnail=""; 32 if ( file_exists("previews/$userId/".$tblfile->getFileId()."/0.png"))34 if (in_array($ext, array("jpg","png","jpeg","bmp","gif"))) 33 35 { 34 $thumbnail="http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png"; 36 $names = explode(".", $name); 37 $filePath = $tblres->getFullFilename(); 38 $filePath = str_replace('/srv/www/violet/web', '', $filePath); 39 $filePath = str_replace($name, "", $fileName). $names[0]."_thumb.jpg"; 40 41 42 $thumbnail= $filePath; 43 35 44 } 45 else 46 { 47 if (file_exists("previews/$userId/".$tblfile->getFileId()."/0.png")) 48 { 49 $thumbnail="previews/$userId/".$tblfile->getFileId()."/0.png"; 50 } 51 } 52 36 53 $fileSize = $tblres->getResFilesize(); 37 54 ?>
Note: See TracChangeset
for help on using the changeset viewer.