Changeset 887
- Timestamp:
- Apr 15, 2015 4:05:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php
r878 r887 18 18 $this->forward('default', 'module'); 19 19 } 20 20 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 21 35 private function autoDirName ($folderName, $parentId, $userId) { 22 36 23 37 $c = new Criteria(); 24 38 $c->add(TblspacecategoryPeer::CAT_PARENT, $parentId); … … 26 40 $c->add(TblspacecategoryPeer::CAT_NAME, $folderName); 27 41 $category = TblspacecategoryPeer::doSelectOne($c); 28 42 29 43 if (!is_null($category)) { 30 44 $newFolderName = 'Copy of ' . $folderName; 31 45 $folderName = $this->autoDirName($newFolderName, $parentId, $userId); 32 46 } 33 47 34 48 return $folderName; 35 49 } 36 50 37 51 private function CreateSpaceDir($folderName, $parentId, $userId, &$objNewDir = null) { 38 /*$c = new Criteria();52 $c = new Criteria(); 39 53 $c->add(TblspacecategoryPeer::CAT_PARENT, $parentId); 40 54 $c->add(TblspacecategoryPeer::CAT_USER, $userId); 41 55 $c->add(TblspacecategoryPeer::CAT_NAME, $folderName); 42 56 $category = TblspacecategoryPeer::doSelectOne($c); 43 error_log(var_export($category, TRUE) . "\n", 3, '/srv/www/sbg/log/filename.log'); 44 57 45 58 if (!is_null($category)) { 46 59 $folderName = 'Copy of ' . $folderName; 47 } */ 48 49 $folderName = $this->autoDirName($folderName, $parentId, $userId); 50 60 } 61 51 62 $category = new Tblspacecategory(); 52 63 $category->setCatName($folderName); … … 55 66 $category->setCatDate(date('Y-m-d H:i:s')); 56 67 $category->save(); 57 68 58 69 $objNewDir = $category; 59 70 return $category->getCatId(); … … 102 113 rmdir($path); 103 114 } 104 115 105 116 private function CopySpaceDir($sourceObj, $destination, $userId, &$aryNewTree) { 106 117 error_log(date('YmdHis').' - Source Obj: '.var_export($sourceObj, TRUE), 3, '/srv/www/sgb/log/file.log'); 107 $dirId = $sourceObj->id; 118 $dirId = $sourceObj->id; 108 119 $c = new Criteria(); 109 120 $c->add(TblspacecategoryPeer::CAT_ID, $dirId); … … 111 122 $currentDir = TblspacecategoryPeer::doSelectOne($c); 112 123 $objNewDir = null; 113 124 114 125 $newDirID = $this->CreateSpaceDir($currentDir->getCatName(), $destination, $userId, $objNewDir); 115 126 116 127 $newDir = new stdClass(); 117 128 $newDir->id = $newDirID; 118 129 $newDir->name = $objNewDir->getCatName(); 119 130 $newDir->parentID = $destination; 120 131 121 132 $aryNewTree['DIRECTORIES'][] = $newDir; 122 133 123 134 if (isset($sourceObj->childDirs)) { 124 135 foreach ($sourceObj->childDirs as $key => $dir) { … … 126 137 } 127 138 } 128 139 129 140 if (isset($sourceObj->childFiles)) { 130 141 foreach ($sourceObj->childFiles as $key => $file) { … … 132 143 } 133 144 } 134 145 135 146 } 136 147 … … 150 161 $tblfile->setFileDate(date('Y-m-d H:i:s')); 151 162 $tblfile->save(); 152 163 153 164 $c = new Criteria(); 154 165 $c->add(TblspaceresourcePeer::RES_ID, $currentFile->getFileResource()); 155 166 $res = TblspaceresourcePeer::doSelectOne($c); 156 167 157 168 $thumbnailUrl = file_exists("previews/$userId/".$tblfile->getFileId()."/0.png") ? "http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png" : ''; 158 159 $newFile = new stdClass(); 169 170 $newFile = new stdClass(); 160 171 $newFile->id = $tblfile->getFileId(); 161 172 $newFile->name = $fileName; … … 165 176 $newFile->thumbnail = $thumbnailUrl; 166 177 $newFile->size = $res->getResFilesize(); 167 178 168 179 return $newFile; 169 180 } … … 183 194 return $item; 184 195 } 185 196 186 197 private function createPreview($fileurl, $userId, $fileid) { 187 198 $url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . ""; … … 210 221 if ($code == 200) 211 222 { 212 223 213 224 $count++; 214 225 if (!file_exists('previews/'. $userId."/")) { 215 226 mkdir('previews/'. $userId."/", 0777, true); 216 227 } 217 228 218 229 if (!file_exists('previews/'. $userId."/".$fileid."/")) { 219 230 220 231 mkdir('previews/'. $userId."/".$fileid."/", 0777, true); 221 232 222 233 } 223 234 file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image); 224 235 225 236 } else { 226 237 break; 227 238 } 228 239 } 229 240 230 241 } 231 242 return $count; 232 } 233 243 } 244 234 245 public function executePreview(){ 235 246 $fileId = $this->getRequestParameter('fileId'); … … 239 250 $c->add(TblspacefilePeer::FILE_USER, $userId); 240 251 $currentFile = TblspacefilePeer::doSelectOne($c); 241 252 242 253 $files = scandir("previews/".$userId."/".$fileId); 243 254 $count=(count($files)-2); 244 255 245 256 if ($count < 1) 246 257 { 247 258 $tblres = TblspacefilePeer::retrieveByPk($fileId)->getTblspaceresource(); 248 $fileName = $tblres->getFullFilename(); 259 $fileName = $tblres->getFullFilename(); 249 260 $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $fileName); 250 261 $count=$this->createPreview($fileUrl, $userId, $fileId); … … 346 357 if ($tblfile) 347 358 $tblfile->delete(); 348 349 350 359 360 361 351 362 break; 352 363 } … … 417 428 $aryTreeObj = json_decode($data); 418 429 if (is_array($aryTreeObj)) { 419 foreach ($aryTreeObj as $key => $treeObj) { 430 foreach ($aryTreeObj as $key => $treeObj) { 420 431 if ($act == 'copy') { 421 432 if ($treeObj->type == 'directory'){ … … 429 440 } 430 441 } 431 442 432 443 $this->errMsg = ''; 433 444 $this->errCode = ''; … … 472 483 $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $filePath); 473 484 } 474 485 475 486 $ext = pathinfo($fileUrl, PATHINFO_EXTENSION); 476 487 $ext = strtolower($ext); 477 478 if (in_array($ext, array("ppt","xls","doc","pdf","docx","pptx","xlsx"))) 479 { 488 489 if (in_array($ext, array("ppt","xls","doc","pdf","docx","pptx","xlsx"))) 490 { 480 491 $this->createPreview($fileUrl, $userId, $tblfile->getFileId()); 481 492 } 482 493 494 if (in_array($ext, array("jpg", "jpeg", "png","gif","tiff","dvg","bmp"))) 495 { 496 $thumbnail = ''; 497 $this->createImateThumbnail($filePath, $thumnail); 498 } 499 483 500 if ($response == 1) { 484 501 $aryError = array('err' => "", 'errCode' => 0); … … 493 510 ); 494 511 $aryData = array('DIRECTORIES' => array(), 'FILES' => $aryFiles, 'ERROR' => $aryError); 495 512 496 513 $jsonData = json_encode($aryData); 497 514 echo $jsonData;
Note: See TracChangeset
for help on using the changeset viewer.