Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17017 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17017 Rev 17018
Línea 119... Línea 119...
119
                }
119
                }
Línea 120... Línea 120...
120
                
120
                
121
                $habitContentMapper = HabitContentMapper::getInstance($this->adapter);
121
                $habitContentMapper = HabitContentMapper::getInstance($this->adapter);
Línea 122... Línea 122...
122
                $paginator = $habitContentMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
122
                $paginator = $habitContentMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
123
 
123
 
Línea 124... Línea 124...
124
                $storage = Storage::getInstance($this->config);
124
                $storage = Storage::getInstance($this->config, $this->adapter);
125
                $path = $storage->getPathHabitContent();
125
                $path = $storage->getPathHabitContent();
126
                
126
                
Línea 226... Línea 226...
226
                $files = $this->getRequest()->getFiles()->toArray();
226
                $files = $this->getRequest()->getFiles()->toArray();
227
                $type = '';
227
                $type = '';
228
                $filename = '';
228
                $filename = '';
229
                if (isset($files['file']) && empty($files['file']['error'])) {
229
                if (isset($files['file']) && empty($files['file']['error'])) {
230
                    $tmp_filename  = $files['file']['tmp_name'];
230
                    $tmp_filename  = $files['file']['tmp_name'];
231
                    $filename      = $this->normalizeString($files['file']['name']);
231
                    $filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
Línea 232... Línea 232...
232
                    
232
                    
233
                    $mime_type = mime_content_type($tmp_filename);
233
                    $mime_type = mime_content_type($tmp_filename);
234
                    if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
234
                    if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
235
                        $type = HabitContent::TYPE_IMAGE;
235
                        $type = HabitContent::TYPE_IMAGE;
236
                    } else if ($mime_type == 'video/quicktime' ||  $mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
236
                    } else if ($mime_type == 'video/quicktime' ||  $mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
237
                        $type = HabitContent::TYPE_VIDEO;
237
                        $type = HabitContent::TYPE_VIDEO;
238
                    } else if ($mime_type == 'application/pdf') {
238
                    } else if ($mime_type == 'application/pdf') {
239
                        $type = HabitContent::TYPE_DOCUMENT;
239
                        $type = HabitContent::TYPE_DOCUMENT;
240
                    }
240
                    }
241
                }
-
 
242
                
241
                }
243
                
-
 
244
                
-
 
245
          
-
 
246
              
-
 
247
                
242
 
248
                $habitContentMapper = HabitContentMapper::getInstance($this->adapter);
243
                $habitContentMapper = HabitContentMapper::getInstance($this->adapter);
Línea 249... Línea 244...
249
                if($habitContentMapper->insert($habitContent)) {
244
                if($habitContentMapper->insert($habitContent)) {
Línea 250... Línea -...
250
                    
-
 
251
                    $habitContent = $habitContentMapper->fetchOne($habitContent->id);
-
 
252
                    
-
 
253
                    
245
                    
254
                   
246
                    $habitContent = $habitContentMapper->fetchOne($habitContent->id);
255
               
-
 
256
                    
-
 
257
                    $storage = Storage::getInstance($this->config);
-
 
258
                    $target_path = $storage->getPathHabitContent();
-
 
259
                    $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
-
 
260
                    if(!file_exists($interal_path)) {
-
 
261
                        mkdir($interal_path, 0775);
-
 
262
                    }
-
 
263
                    
247
                    
Línea 264... Línea 248...
264
                    $full_tmp_filename = $interal_path . DIRECTORY_SEPARATOR . $filename;
248
                    
Línea 265... Línea 249...
265
                    
249
                    $storage        = Storage::getInstance($this->config, $this->adapter);
266
                    move_uploaded_file($tmp_filename,$full_tmp_filename);
250
                    $target_path    = $storage->getPathHabitContent();
267
                    
251
                           
Línea 268... Línea 252...
268
                    
252
                    
269
              
253
              
Línea 270... Línea 254...
270
                    if ($type == HabitContent::TYPE_DOCUMENT) {
254
                    if ($type == HabitContent::TYPE_DOCUMENT) {
271
                        
255
                        
272
                        
-
 
273
                        if($storage->putFile($target_path, $habitContent->uuid,  $full_tmp_filename)) {
256
                        
Línea 274... Línea 257...
274
                            $habitContent->file = $filename;
257
                        if($storage->moveAndPutFile($tmp_filename, $target_path, $habitContent->uuid,  $filename)) {
-
 
258
                            $habitContent->file = $filename;
275
                            $habitContent->type = $type;
259
                            $habitContent->type = $type;
-
 
260
                            
276
                            
261
                            $habitContentMapper->update($habitContent);
277
                            $habitContentMapper->update($habitContent);
262
                        }
278
                        }
263
                        
279
                        
264
                    } else if ($type == HabitContent::TYPE_IMAGE) {
280
                    } else if ($type == HabitContent::TYPE_IMAGE) {
265
                        $image = Image::getInstance($this->config);
281
                        $image = Image::getInstance($this->config);
266
                 
-
 
267
                
282
                        $target_path = $image->getStorage()->getPathFeed();
268
                        $filename = substr($filename, 0, strrpos($filename, '.'))  . '.png';
283
                        
269
                        $full_tmp_filename = $image->uploadProcessWithOutChangeSize($tmp_filename, $filename);
284
                
270
   
285
                        $filename = substr($filename, 0, strrpos($filename, '.'))  . '.png';
271
     
Línea 286... Línea 272...
286
           
272
                        if($full_tmp_filename) {
Línea 287... Línea 273...
287
                        $unlink_source = true;
273
                            if($storage->putFile($target_path, $habitContent->uuid,  $full_tmp_filename)) {
288
                        if($image->uploadImageRaw($full_tmp_filename, $target_path, $habitContent->uuid, $filename, $unlink_source)) {
274
                                $habitContent->file = $filename;
Línea 289... Línea 275...
289
                            $habitContent->file = $filename;
275
                                $habitContent->type = $type;
Línea 401... Línea 387...
401
                'data'   => 'ERROR_UNAUTHORIZED'
387
                'data'   => 'ERROR_UNAUTHORIZED'
402
            ]);
388
            ]);
403
        }
389
        }
Línea 404... Línea 390...
404
        
390
        
-
 
391
        if($request->isPost()) {
-
 
392
           
Línea 405... Línea 393...
405
        if($request->isPost()) {
393
  
406
            
394
            
407
            $result =  $habitContentMapper->delete($habitContent);
395
            $result =  $habitContentMapper->delete($habitContent);
Línea 408... Línea 396...
408
            if($result) {
396
            if($result) {
Línea 409... Línea 397...
409
                $this->logger->info('Se borro el Content : ' .  $habitContent->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
397
                $this->logger->info('Se borro el Content : ' .  $habitContent->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
398
               
410
               
399
                if($habitContent->file) {
411
                if($habitContent->file) {
400
                    
412
                    
401
                    $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
Línea 413... Línea 402...
413
                    $image = Image::getInstance($this->config);
402
                    
414
                    $target_path = $image->getStorage()->getPathHabitContent();
403
                    $target_path = $storage->getPathHabitContent();
415
                    $image->getStorage()->deleteFile($target_path, $habitContent->uuid, $habitContent->file);
404
                    $storage->deleteDirectory($target_path, $habitContent->uuid);
Línea 468... Línea 457...
468
                'data'   => 'ERROR_UNAUTHORIZED'
457
                'data'   => 'ERROR_UNAUTHORIZED'
469
            ]);
458
            ]);
470
        }
459
        }
Línea 471... Línea 460...
471
        
460
        
472
        if($request->isGet()) {
461
        if($request->isGet()) {
Línea 473... Línea 462...
473
            $storage = Storage::getInstance($this->config);
462
            $storage = Storage::getInstance($this->config, $this->adapter);
474
 
463
 
475
            
464
            
Línea 546... Línea 535...
546
        }
535
        }
Línea 547... Línea 536...
547
        
536
        
548
        return new JsonModel($data);
537
        return new JsonModel($data);
Línea 549... Línea -...
549
    }
-
 
550
    
-
 
551
    /**
-
 
552
     *
-
 
553
     * @param string $str
-
 
554
     * @return string
-
 
555
     */
-
 
556
    private function normalizeString($str = '')
-
 
557
    {
-
 
558
        $basename  = substr($str, 0, strrpos($str, '.'));
-
 
559
        $basename  = str_replace('.', '-', $basename);
-
 
560
        
538
    }
561
        $extension  = substr($str, strrpos($str, '.'));
-
 
562
        
-
 
563
        $str = $basename . $extension;
-
 
564
        
-
 
565
        $str = strip_tags($str);
-
 
566
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
-
 
567
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
-
 
568
        $str = strtolower($str);
-
 
569
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
-
 
570
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
-
 
571
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
-
 
572
        $str = str_replace(' ', '-', $str);
-
 
573
        $str = rawurlencode($str);
-
 
574
        $str = str_replace('%', '-', $str);
-
 
Línea 575... Línea 539...
575
        return trim(strtolower($str));
539