Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16998 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 16998 Rev 17002
Línea 10... Línea 10...
10
use Laminas\Log\LoggerInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Mapper\PostMapper;
14
use LeadersLinked\Mapper\PostMapper;
15
use LeadersLinked\Form\PostCreateForm;
15
use LeadersLinked\Form\Post\PostCreateForm;
16
use LeadersLinked\Form\PostEditForm;
16
use LeadersLinked\Form\Post\PostEditForm;
17
use LeadersLinked\Model\Post;
17
use LeadersLinked\Model\Post;
18
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
18
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
19
use LeadersLinked\Library\Image;
19
use LeadersLinked\Library\Image;
Línea 20... Línea 20...
20
 
20
 
Línea 211... Línea 211...
211
                    $post = $postMapper->fetchOne($post->id);
211
                    $post = $postMapper->fetchOne($post->id);
Línea 212... Línea 212...
212
 
212
 
Línea 213... Línea -...
213
 
-
 
214
                    $files = $this->getRequest()->getFiles()->toArray();
213
 
215
 
214
                    $files = $this->getRequest()->getFiles()->toArray();
216
                    $target_path = $this->config['leaderslinked.fullpath.post'] .  $post->uuid;
-
 
Línea 217... Línea 215...
217
                    if (!file_exists($target_path)) {
215
 
218
                        mkdir($target_path, 0755, true);
216
                    $image = Image::getInstance($this->config);
219
                    }
217
                    $target_path = $image->getStorage()->getPathPost();
Línea 220... Línea 218...
220
 
218
 
Línea 221... Línea 219...
221
 
219
 
222
                    if (isset($files['file']) && empty($files['file']['error'])) {
220
                    if (isset($files['file']) && empty($files['file']['error'])) {
Línea -... Línea 221...
-
 
221
                        $tmp_filename       = $files['file']['tmp_name'];
-
 
222
                        $original_filename  = trim(strtolower($files['file']['name']));
-
 
223
 
-
 
224
                        $original_filename = Functions::normalizeString($original_filename);
223
                        $tmp_filename       = $files['file']['tmp_name'];
225
 
224
                        $original_filename  = trim(strtolower($files['file']['name']));
-
 
225
 
226
                        $parts = explode('.', $original_filename);
226
                        $original_filename = Functions::normalizeString($original_filename);
227
                        $filename = $parts[0] . '.' . $parts[count($parts) - 1];
227
 
228
 
228
                        $parts = explode('.', $original_filename);
229
                        $full_filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
229
                        $original_filename = $parts[0] . '.' . $parts[count($parts) - 1];
230
                        move_uploaded_file($tmp_filename, $full_filename);
230
 
231
                        
231
                        try {
232
                        
Línea 244... Línea 245...
244
 
245
 
245
                        try {
246
                        try {
Línea 246... Línea 247...
246
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
247
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
247
 
248
 
248
                            $filename = 'image-' . uniqid() . '.png';
249
                            $filename = 'image-' . uniqid() . '.png';
249
                            // $crop_to_dimensions = true;
250
                            $crop_to_dimensions = false;
250
                            // if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
251
                            $unlink_source = true;
251
 
252
                            
252
                            if (Image::uploadImageWithoutCompletationSize($tmp_filename, $target_path, $filename, $target_width, $target_height)) {
253
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $post->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) { 
253
                                $post->image = $filename;
254
                                $post->image = $filename;
254
                                $postMapper->update($post);
255
                                $postMapper->update($post);
255
                            }
256
                            }
Línea 327... Línea 328...
327
 
328
 
Línea 328... Línea 329...
328
            $post->status = Post::STATUS_DELETE;
329
            $post->status = Post::STATUS_DELETE;
329
 
330
 
-
 
331
            $result =  $postMapper->update($post);
-
 
332
            if ($result) {
-
 
333
                
-
 
334
                
330
            $result =  $postMapper->update($post);
335
                
Línea 331... Línea 336...
331
            if ($result) {
336
                
332
                $this->logger->info('Se borro la noticia : ' .  $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
337
                $this->logger->info('Se borro la noticia : ' .  $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea 415... Línea 420...
415
 
420
 
Línea 416... Línea -...
416
 
-
 
417
 
421
 
418
                $files = $this->getRequest()->getFiles()->toArray();
422
 
419
 
-
 
Línea 420... Línea 423...
420
                $target_path = $this->config['leaderslinked.fullpath.post'] .  $post->uuid;
423
                $files = $this->getRequest()->getFiles()->toArray();
Línea 421... Línea 424...
421
                if (!file_exists($target_path)) {
424
 
422
                    mkdir($target_path, 0755, true);
425
                $image = Image::getInstance($this->config);
423
                }
426
                $target_path = $image->getStorage()->getPathPost();
Línea 424... Línea 427...
424
 
427
 
425
 
428
 
Línea 426... Línea 429...
426
                if (isset($files['file']) && empty($files['file']['error'])) {
429
                if (isset($files['file']) && empty($files['file']['error'])) {
Línea 427... Línea 430...
427
 
430
 
428
                    if ($post->file) {
431
                    if ($post->file) {
-
 
432
                        $image->getStorage()->deleteFile($target_path, $post->uuid, $post->file);
-
 
433
                    }
-
 
434
 
-
 
435
 
-
 
436
                    $tmp_filename       = $files['file']['tmp_name'];
429
                        Functions::deleteFilename($target_path, $post->file);
437
                    $original_filename  = trim(strtolower($files['file']['name']));
430
                    }
438
 
431
 
-
 
432
 
439
                    $original_filename = Functions::normalizeString($original_filename);
433
                    $tmp_filename       = $files['file']['tmp_name'];
440
 
434
                    $original_filename  = trim(strtolower($files['file']['name']));
441
                    $parts = explode('.', $original_filename);
435
 
442
                    $filename = $parts[0] . '.' . $parts[count($parts) - 1];
436
                    $original_filename = Functions::normalizeString($original_filename);
443
                   
437
 
444
                   
438
                    $parts = explode('.', $original_filename);
445
                    $full_filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
439
                    $original_filename = $parts[0] . '.' . $parts[count($parts) - 1];
446
                    move_uploaded_file($tmp_filename, $full_filename);
Línea 440... Línea 447...
440
 
447
                    
Línea 441... Línea 448...
441
                    try {
448
                    
442
                        $full_filename = $target_path  . DIRECTORY_SEPARATOR . $original_filename;
449
                    try {
443
                        if (move_uploaded_file($tmp_filename, $full_filename)) {
450
                        if ($image->getStorage()->putFile($target_path, $post->uuid, $full_filename)) {
Línea 444... Línea 451...
444
                            $post->file = basename($full_filename);
451
                            $post->file = basename($filename);
Línea 445... Línea 452...
445
                            $post->update($post);
452
                            $post->update($post);
446
                        }
453
                        }
Línea 447... Línea 454...
447
                    } catch (\Throwable $e) {
454
                    } catch (\Throwable $e) {
448
                        error_log($e->getTraceAsString());
455
                        error_log($e->getTraceAsString());
-
 
456
                    }
-
 
457
                }
-
 
458
 
449
                    }
459
                if (isset($files['image']) && empty($files['image']['error'])) {
-
 
460
 
450
                }
461
                    if ($post->image) {
451
 
462
                        $image->getStorage()->deleteFile($target_path, $post->uuid, $post->image);
452
                if (isset($files['image']) && empty($files['image']['error'])) {
463
                    }
453
 
464
 
454
                    if ($post->image) {
465