| Line 14... |
Line 14... |
| 14 |
|
14 |
|
| 15 |
public $limit;
|
15 |
public $limit;
|
| 16 |
public $apihost;
|
16 |
public $apihost;
|
| 17 |
|
17 |
|
| 18 |
public $components = array(
|
18 |
public $components = array(
|
| 19 |
'Session',
|
19 |
'Session','Resize',
|
| 20 |
'Auth' => array(
|
20 |
'Auth' => array(
|
| 21 |
'loginAction' => array('controller' => 'users', 'action' => 'login'),
|
21 |
'loginAction' => array('controller' => 'users', 'action' => 'login'),
|
| 22 |
'allowedActions' => array('index', 'view', 'display')
|
22 |
'allowedActions' => array('index', 'view', 'display')
|
| 23 |
)
|
23 |
)
|
| 24 |
);
|
24 |
);
|
| Line 267... |
Line 267... |
| 267 |
'_serialize' => array('result')
|
267 |
'_serialize' => array('result')
|
| 268 |
));
|
268 |
));
|
| 269 |
$this->render('/Elements/json');
|
269 |
$this->render('/Elements/json');
|
| 270 |
}
|
270 |
}
|
| 271 |
|
271 |
|
| - |
|
272 |
public function remove($id,$class){
|
| - |
|
273 |
$data['oid'] = $id;
|
| - |
|
274 |
$data['class'] = $class;
|
| - |
|
275 |
|
| - |
|
276 |
$data_string = json_encode($data,JSON_NUMERIC_CHECK);
|
| - |
|
277 |
$ch = curl_init();
|
| - |
|
278 |
$url = $this->apihost.'Catalog/deleteDocument';
|
| - |
|
279 |
$this->log("[url] $url",'api');
|
| - |
|
280 |
$this->log("[fields] ".print_r($data_string,1),'api');
|
| - |
|
281 |
curl_setopt($ch, CURLOPT_URL, $url);
|
| - |
|
282 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
| - |
|
283 |
curl_setopt($ch, CURLOPT_POST, true);
|
| - |
|
284 |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // note the PUT here
|
| - |
|
285 |
|
| - |
|
286 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
| - |
|
287 |
curl_setopt($ch, CURLOPT_HEADER, true);
|
| - |
|
288 |
|
| - |
|
289 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
| - |
|
290 |
'Content-Type: application/json',
|
| - |
|
291 |
'Content-Length: ' . strlen($data_string)
|
| - |
|
292 |
));
|
| - |
|
293 |
|
| - |
|
294 |
// execute the request
|
| - |
|
295 |
|
| - |
|
296 |
$output = curl_exec($ch);
|
| - |
|
297 |
$result = $this->request->data['value'];
|
| - |
|
298 |
$this->log("[response] ".print_r($output,1),'api');
|
| - |
|
299 |
curl_close($ch);
|
| - |
|
300 |
// $this->set(array(
|
| - |
|
301 |
// 'result' => $result,
|
| - |
|
302 |
// '_serialize' => array('result')
|
| - |
|
303 |
// ));
|
| - |
|
304 |
// $this->render('/Elements/json');
|
| - |
|
305 |
return $result;
|
| - |
|
306 |
}
|
| - |
|
307 |
|
| 272 |
function getAutoLoginUrl($userId,$next) {
|
308 |
function getAutoLoginUrl($userId,$next) {
|
| 273 |
$this->loadModel('User');
|
309 |
$this->loadModel('User');
|
| 274 |
$this->User->Behaviors->attach('Containable');
|
310 |
$this->User->Behaviors->attach('Containable');
|
| 275 |
$options = array('contain'=>array('UserAccount'), 'conditions'=>array('User.id'=>$userId),'fields'=>array('username','email'),'recursive'=>-1);
|
311 |
$options = array('contain'=>array('UserAccount'), 'conditions'=>array('User.id'=>$userId),'fields'=>array('username','email'),'recursive'=>-1);
|
| 276 |
$user = $this->User->find('first',$options);
|
312 |
$user = $this->User->find('first',$options);
|
| Line 278... |
Line 314... |
| 278 |
$data = array('email'=>$user['User']['email'],'Id'=>$user['UserAccount'][0]['account_key'],'cartId' => $user['UserAccount'][1]['account_key'],'isPrivateDealUser'=>1,'next'=>$next);
|
314 |
$data = array('email'=>$user['User']['email'],'Id'=>$user['UserAccount'][0]['account_key'],'cartId' => $user['UserAccount'][1]['account_key'],'isPrivateDealUser'=>1,'next'=>$next);
|
| 279 |
$data = '?data='.base64_encode(serialize($data));
|
315 |
$data = '?data='.base64_encode(serialize($data));
|
| 280 |
$token = '&token='.md5(Configure::read('saholicapikey').'|'.$user['UserAccount'][0]['account_key']);
|
316 |
$token = '&token='.md5(Configure::read('saholicapikey').'|'.$user['UserAccount'][0]['account_key']);
|
| 281 |
return Configure::read('saholicauthurl').$data.$token;
|
317 |
return Configure::read('saholicauthurl').$data.$token;
|
| 282 |
}
|
318 |
}
|
| - |
|
319 |
|
| - |
|
320 |
function createUploadDirectory($modelClass) {
|
| - |
|
321 |
//Create directory
|
| - |
|
322 |
if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {
|
| - |
|
323 |
$this->log("making directory for $modelClass". WWW_ROOT.DS.'uploads'.DS.$modelClass);
|
| - |
|
324 |
mkdir(WWW_ROOT.'uploads'.DS.$modelClass,0777);
|
| - |
|
325 |
}
|
| - |
|
326 |
if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {
|
| - |
|
327 |
$this->log("failed to create directory for $modelClass");
|
| - |
|
328 |
return false;
|
| - |
|
329 |
} else {
|
| - |
|
330 |
return true;
|
| - |
|
331 |
}
|
| - |
|
332 |
}
|
| - |
|
333 |
|
| - |
|
334 |
public function upload() {
|
| - |
|
335 |
$result['status'] = 0;
|
| - |
|
336 |
$result['success'] = false;
|
| - |
|
337 |
$result['message'] = __('Unable to upload');
|
| - |
|
338 |
|
| - |
|
339 |
App::import('Vendor','qqFileUploader',array('file' =>'qqFileUploader.php'));
|
| - |
|
340 |
|
| - |
|
341 |
$uploader = new qqFileUploader();
|
| - |
|
342 |
|
| - |
|
343 |
// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
|
| - |
|
344 |
$uploader->allowedExtensions = array('jpeg','png','jpg','gif','bmp');
|
| - |
|
345 |
|
| - |
|
346 |
// Specify max file size in bytes.
|
| - |
|
347 |
$uploader->sizeLimit = 10 * 1024 * 1024;
|
| - |
|
348 |
|
| - |
|
349 |
// Specify the input name set in the javascript.
|
| - |
|
350 |
$uploader->inputName = 'qqfile';
|
| - |
|
351 |
|
| - |
|
352 |
// If you want to use resume feature for uploader, specify the folder to save parts.
|
| - |
|
353 |
$uploader->chunksFolder = 'chunks';
|
| - |
|
354 |
|
| - |
|
355 |
// $min_width = isset($this->request->data['minwidth']) ? $this->request->data['minwidth'] : 0;
|
| - |
|
356 |
// $min_height = isset($this->request->data['minheight']) ? $this->request->data['minheight'] : 0;
|
| - |
|
357 |
$modelClass = $this->modelClass;
|
| - |
|
358 |
|
| - |
|
359 |
$this->log($this->request);
|
| - |
|
360 |
$folderName = Inflector::pluralize(strtolower($modelClass));
|
| - |
|
361 |
|
| - |
|
362 |
if (!$this->createUploadDirectory($folderName)) {
|
| - |
|
363 |
$result['message'] = 'Failed to create directory :'.$modelClass.
|
| - |
|
364 |
'. Sorry we are having trouble. Please try again, or email help@profittill.com';
|
| - |
|
365 |
} else {
|
| - |
|
366 |
// To save the upload with a specified name, set the second parameter
|
| - |
|
367 |
$result = $uploader->handleUpload('uploads'.DS.$folderName.DS, $uploader->getName());
|
| - |
|
368 |
if($result){
|
| - |
|
369 |
//Resize and create thumbnail
|
| - |
|
370 |
$inFile = WWW_ROOT.'uploads'.DS.$folderName.DS. $uploader->getName();
|
| - |
|
371 |
|
| - |
|
372 |
$largeOutFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'large-'.basename($inFile);
|
| - |
|
373 |
$this->resizeImage($inFile,$largeOutFile,800,800);
|
| - |
|
374 |
|
| - |
|
375 |
$outFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'small-'.basename($inFile);
|
| - |
|
376 |
$this->resizeImage($inFile,$outFile,200,200);
|
| - |
|
377 |
|
| - |
|
378 |
$newUrl = '/uploads/'.$folderName.'/'.basename($inFile);
|
| - |
|
379 |
// To return a name used for uploaded file you can use the following line.
|
| - |
|
380 |
$result['uploadName'] = $newUrl;
|
| - |
|
381 |
|
| - |
|
382 |
$result['status'] = 1;
|
| - |
|
383 |
$result['success'] = true;
|
| - |
|
384 |
// $result['filesize'] = $filesize;
|
| - |
|
385 |
$result['message'] = __('Uploaded');
|
| - |
|
386 |
}
|
| - |
|
387 |
}
|
| - |
|
388 |
$this->log($result);
|
| - |
|
389 |
return new CakeResponse(array('body' => json_encode($result)));
|
| - |
|
390 |
}
|
| - |
|
391 |
|
| - |
|
392 |
function cropImage ($url, $height, $width, $x1, $x2, $y1, $y2) {
|
| - |
|
393 |
ini_set('memory_limit', '2G');
|
| - |
|
394 |
$result['status'] = 0;
|
| - |
|
395 |
$result['message'] = __('Unable to crop');
|
| - |
|
396 |
|
| - |
|
397 |
$image_type = substr($url, strrpos($url, '.', -1));
|
| - |
|
398 |
$filepath = WWW_ROOT.substr($url, strlen(FULL_BASE_URL)+1);
|
| - |
|
399 |
$croppedfile = substr($filepath, 0, strrpos($filepath, '/', -1)).
|
| - |
|
400 |
'/C_'.substr($filepath, strrpos($filepath, '/', -1)+1);
|
| - |
|
401 |
|
| - |
|
402 |
// Create image instances
|
| - |
|
403 |
$dest = imagecreatetruecolor($x2,$y2);
|
| - |
|
404 |
|
| - |
|
405 |
switch ($image_type) {
|
| - |
|
406 |
case '.jpg':
|
| - |
|
407 |
case '.jpeg':
|
| - |
|
408 |
case '.JPEG':
|
| - |
|
409 |
case '.JPG':
|
| - |
|
410 |
$src = imagecreatefromjpeg($filepath);
|
| - |
|
411 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
| - |
|
412 |
imagejpeg($dest, $croppedfile);
|
| - |
|
413 |
$ext = '.jpg';
|
| - |
|
414 |
break;
|
| - |
|
415 |
case '.gif':
|
| - |
|
416 |
$src = imagecreatefromgif($filepath);
|
| - |
|
417 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
| - |
|
418 |
imagegif($dest, $croppedfile);
|
| - |
|
419 |
$ext = '.gif';
|
| - |
|
420 |
break;
|
| - |
|
421 |
case '.png':
|
| - |
|
422 |
$src = imagecreatefrompng($filepath);
|
| - |
|
423 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
| - |
|
424 |
imagepng($dest, $croppedfile);
|
| - |
|
425 |
$ext = '.png';
|
| - |
|
426 |
break;
|
| - |
|
427 |
default:
|
| - |
|
428 |
$result['message'] = __('Unsupported image format.');
|
| - |
|
429 |
return $result;
|
| - |
|
430 |
}
|
| - |
|
431 |
$result['status'] = 1;
|
| - |
|
432 |
$result['message'] = __('Cropped');
|
| - |
|
433 |
$result['data'] = substr($url, 0, strrpos($url, '/', -1)).'/C_'.substr($url, strrpos($url, '/', -1)+1);
|
| - |
|
434 |
return $result;
|
| - |
|
435 |
}
|
| - |
|
436 |
|
| - |
|
437 |
function resizeImage ($inFile, $outFile, $w, $h) {
|
| - |
|
438 |
$image = $this->Resize;
|
| - |
|
439 |
$image->load($inFile);
|
| - |
|
440 |
$image->crop($w,$h);
|
| - |
|
441 |
$image->save($outFile);
|
| - |
|
442 |
}
|
| - |
|
443 |
|
| - |
|
444 |
public function crop() {
|
| - |
|
445 |
$url = $this->request->data['file_url'];
|
| - |
|
446 |
$height = $this->request->data['h'];
|
| - |
|
447 |
$width = $this->request->data['w'];
|
| - |
|
448 |
$x1 = $this->request->data['x'];
|
| - |
|
449 |
$x2 = $this->request->data['x2'];
|
| - |
|
450 |
$y1 = $this->request->data['y'];
|
| - |
|
451 |
$y2 = $this->request->data['y2'];
|
| - |
|
452 |
|
| - |
|
453 |
$result = $this->cropImage($url, $height, $width, $x1, $x2, $y1, $y2);
|
| - |
|
454 |
|
| - |
|
455 |
$this->set('result', $result);
|
| - |
|
456 |
$this->set('_serialize', array('result'));
|
| - |
|
457 |
}
|
| 283 |
}
|
458 |
}
|