Proyectos de Subversion LeadersLinked - Services

Rev

Rev 809 | Rev 811 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
 
8
use Laminas\Mvc\Controller\AbstractActionController;
283 www 9
 
1 efrain 10
use Laminas\View\Model\JsonModel;
11
use LeadersLinked\Model\Page;
12
use LeadersLinked\Mapper\NotificationMapper;
13
use LeadersLinked\Mapper\PageMapper;
14
use LeadersLinked\Mapper\UserMapper;
15
use LeadersLinked\Mapper\ConnectionMapper;
16
 
17
use LeadersLinked\Mapper\PostMapper;
18
use LeadersLinked\Model\Post;
19
 
20
use LeadersLinked\Mapper\FeedMapper;
21
use LeadersLinked\Model\Feed;
22
use LeadersLinked\Model\User;
23
use LeadersLinked\Model\Connection;
24
use LeadersLinked\Mapper\NetworkMapper;
25
use LeadersLinked\Library\Functions;
26
use LeadersLinked\Model\Network;
27
 
257 efrain 28
use LeadersLinked\Library\ExternalCredentials;
341 www 29
use Nullix\CryptoJsAes\CryptoJsAes;
345 www 30
use LeadersLinked\Library\Storage;
257 efrain 31
 
1 efrain 32
class HomeController extends AbstractActionController
33
{
34
    /**
35
     *
36
     * @var \Laminas\Db\Adapter\AdapterInterface
37
     */
38
    private $adapter;
39
 
40
    /**
41
     *
42
     * @var \LeadersLinked\Cache\CacheInterface
43
     */
44
    private $cache;
45
 
46
 
47
    /**
48
     *
49
     * @var \Laminas\Log\LoggerInterface
50
     */
51
    private $logger;
52
 
53
    /**
54
     *
55
     * @var array
56
     */
57
    private $config;
58
 
59
 
60
    /**
61
     *
62
     * @var \Laminas\Mvc\I18n\Translator
63
     */
64
    private $translator;
65
 
66
 
67
    /**
68
     *
69
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
70
     * @param \LeadersLinked\Cache\CacheInterface $cache
71
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
72
     * @param array $config
73
     * @param \Laminas\Mvc\I18n\Translator $translator
74
     */
75
    public function __construct($adapter, $cache, $logger, $config, $translator)
76
    {
77
        $this->adapter      = $adapter;
78
        $this->cache        = $cache;
79
        $this->logger       = $logger;
80
        $this->config       = $config;
81
        $this->translator   = $translator;
82
    }
341 www 83
 
84
    public function cryptoAction()
85
    {
86
        header('Content-type: text/plain');
87
 
88
 
343 www 89
        $email = '{"ct":"eZd1aD5p3miv+UsN/7CfAst+8U/Tu4de/n5Rmaf/VsicEYlJG3DH4JvRoxCUwcSA","iv":"8abe13978c33e8701857c6377f09864c","s":"cb61b5d25010408b"}';
90
        $password  = '{"ct":"v5maMXocpQT5Jr02vBzXhw==","iv":"a2f8244c89dd690c60ded5f49092d552","s":"522aeee2356f0677"}';
341 www 91
        $aes = 'HP8Rc6vBnr2CJyVG';
92
 
93
        echo "Email = $email \r\n";
94
        echo "Password = $password \r\n";
95
        echo "AES = $aes \r\n\r\n";
96
 
97
        $emailDecrypt  = CryptoJsAes::decrypt($email, $aes);
98
        $passwordDecrypt  = CryptoJsAes::decrypt($password, $aes);
99
 
100
        echo "EmailDecrypt = $emailDecrypt \r\n";
101
        echo "PasswordDecrypt = $passwordDecrypt \r\n";
102
 
103
        exit;
104
    }
1 efrain 105
 
333 www 106
 
107
    public function storageAction()
108
    {
109
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
110
        $currentNetwork = $currentNetworkPlugin->getNetwork();
111
 
112
        $request = $this->getRequest();
113
        if ($request->isGet()) {
114
 
115
            $code = $this->params()->fromRoute('code');
116
            if(empty($code)) {
117
                $data = [
118
                    'success' => false,
119
                    'data' => 'ERROR_STORAGE_CODE_INVALID'
120
                ];
121
 
122
                return new JsonModel($data);
123
            }
124
 
125
            $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
126
            $storageFile = $storageFileMapper->fetchOneByCode($code);
127
 
809 stevensc 128
            $storageDir = $this->config['leaderslinked.storage.path'];
129
            $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $storageFile->path;
810 stevensc 130
 
131
            $this->logger->err('storageFileFullPath = ' . $storageFileFullPath);
333 www 132
 
807 stevensc 133
            if($storageFileFullPath) {
333 www 134
 
135
 
807 stevensc 136
                if(file_exists($storageFileFullPath)) {
333 www 137
 
770 stevensc 138
                    // Check if the path is a directory instead of a file
807 stevensc 139
                    if(is_dir($storageFileFullPath)) {
770 stevensc 140
                        $this->logger->err('StorageFile path is a directory instead of a file: ' . $storageFile->path . ' (code: ' . $code . ')');
141
                        return $this->getResponse()->setStatusCode(500);
142
                    }
143
 
333 www 144
                    // Try to open file
807 stevensc 145
                    if (!is_readable($storageFileFullPath)) {
333 www 146
                        return $this->getResponse()->setStatusCode(500);
147
                    }
148
 
149
                    // Get file size in bytes.
807 stevensc 150
                    $fileSize = filesize($storageFileFullPath);
333 www 151
 
152
                    // Get MIME type of the file.
807 stevensc 153
                    $mimeType = mime_content_type($storageFileFullPath);
333 www 154
                    if($mimeType===false) {
155
                        $mimeType = 'application/octet-stream';
156
                    }
157
 
810 stevensc 158
                    $fileContent = file_get_contents($storageFile->path);
333 www 159
 
160
                    $response = $this->getResponse();
161
                    $headers = $response->getHeaders();
162
                    $headers->addHeaderLine('Content-type: ' . $mimeType);
163
                    $headers->addHeaderLine('Content-length: ' . $fileSize);
164
 
165
                    if($fileContent!==false) {
166
                        $response->setContent($fileContent);
167
                        return $response;
168
                    } else {
169
                        $this->getResponse()->setStatusCode(500);
170
                        return;
171
                    }
172
                } else {
173
                    return $this->getResponse()->setStatusCode(404);
174
                }
175
 
176
            } else {
177
                return $this->getResponse()->setStatusCode(404);
178
            }
179
 
180
        } else {
181
            $data = [
182
                'success' => false,
183
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
184
            ];
185
 
186
            return new JsonModel($data);
187
        }
188
    }
1 efrain 189
 
190
 
764 stevensc 191
    public function dataStorageAction()
192
    {
193
        $request = $this->getRequest();
194
        if ($request->isGet()) {
195
 
196
            $type = $this->params()->fromRoute('type');
197
            $uuid = $this->params()->fromRoute('uuid');
198
            $filename = $this->params()->fromRoute('filename');
199
 
200
            if(empty($type) || empty($uuid) || empty($filename)) {
201
                return $this->getResponse()->setStatusCode(404);
202
            }
203
 
204
            // Map type to config key
205
            $configKey = 'leaderslinked.fullpath.' . $type;
206
            if(!isset($this->config[$configKey])) {
207
                return $this->getResponse()->setStatusCode(404);
208
            }
209
 
210
            // Build the file path using the configured base path
211
            $basePath = $this->config[$configKey];
212
            $filePath = $basePath . $uuid . DIRECTORY_SEPARATOR . $filename;
213
 
214
            // Security check: ensure the path is within the allowed directory
215
            $realFilePath = realpath($filePath);
216
            $realBasePath = realpath($basePath);
217
            if(!$realFilePath || !$realBasePath || strpos($realFilePath, $realBasePath) !== 0) {
218
                return $this->getResponse()->setStatusCode(403);
219
            }
220
 
221
            if(file_exists($realFilePath)) {
222
 
223
                // Try to open file
224
                if (!is_readable($realFilePath)) {
225
                    return $this->getResponse()->setStatusCode(500);
226
                }
227
 
228
                // Get file size in bytes.
229
                $fileSize = filesize($realFilePath);
230
 
231
                // Get MIME type of the file.
232
                $mimeType = mime_content_type($realFilePath);
233
                if($mimeType===false) {
234
                    $mimeType = 'application/octet-stream';
235
                }
236
 
237
                $fileContent = file_get_contents($realFilePath);
238
 
239
                $response = $this->getResponse();
240
                $headers = $response->getHeaders();
241
                $headers->addHeaderLine('Content-type: ' . $mimeType);
242
                $headers->addHeaderLine('Content-length: ' . $fileSize);
243
 
244
                if($fileContent!==false) {
245
                    $response->setContent($fileContent);
246
                    return $response;
247
                } else {
248
                    return $this->getResponse()->setStatusCode(500);
249
                }
250
            } else {
251
                return $this->getResponse()->setStatusCode(404);
252
            }
253
 
254
        } else {
255
            $data = [
256
                'success' => false,
257
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
258
            ];
259
 
260
            return new JsonModel($data);
261
        }
262
    }
263
 
264
 
1 efrain 265
    public function indexAction()
266
    {
267
        /*
268
        if(!empty($this->config['leaderslinked.runmode.autologin'])) {
269
 
270
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
271
            $currentNetwork = $currentNetworkPlugin->getNetwork();
272
 
273
            $authService = new AuthenticationService();
274
            if(!$authService->hasIdentity()) {
275
                $adapter = new AuthEmailAdapter($this->adapter);
276
                $adapter->setData('santiago.olivera@leaderslinked.com',  $currentNetwork->id);
277
 
278
                $authService->authenticate($adapter);
279
            }
280
        }
257 efrain 281
        /*
1 efrain 282
        $currentUserPlugin = $this->plugin('currentUserPlugin');
283
        if ($currentUserPlugin->hasIdentity()) {
284
            return $this->redirect()->toRoute('dashboard');
285
        } else {
286
            return $this->redirect()->toRoute('signin');
287
        }*/
288
 
289
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
290
        $currentNetwork = $currentNetworkPlugin->getNetwork();
291
 
292
        $request = $this->getRequest();
293
        if ($request->isGet()) {
294
 
295
            $currentUserPlugin = $this->plugin('currentUserPlugin');
296
 
297
            if (empty($_SESSION['aes'])) {
298
                $_SESSION['aes'] = Functions::generatePassword(16);
299
            }
300
 
301
            if ($this->config['leaderslinked.runmode.sandbox']) {
302
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
303
            } else {
304
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
305
            }
306
 
307
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
308
 
309
 
310
 
311
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
312
            if ($sandbox) {
313
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
314
            } else {
315
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
316
            }
257 efrain 317
 
318
 
319
 
1 efrain 320
 
257 efrain 321
            $data = [
1 efrain 322
                'site_key'  => $site_key,
323
                'google_map_key' => $google_map_key,
324
                'aes'       => $_SESSION['aes'],
325
                'defaultNetwork' => $currentNetwork->default,
326
                'is_logged_in' =>  $currentUserPlugin->hasIdentity() ? true : false,
7 efrain 327
                'access_usign_social_networks' => $access_usign_social_networks &&  $currentNetwork && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
257 efrain 328
            ];
1 efrain 329
 
257 efrain 330
            if($currentNetwork->default == Network::DEFAULT_YES) {
331
                $currentUserPlugin = $this->plugin('currentUserPlugin');
332
                if ($currentUserPlugin->hasIdentity()) {
333
                  $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
334
                  $externalCredentials->getUserBy($currentUserPlugin->getUserId());
335
 
336
                  if($currentNetwork->xmpp_active) {
337
                      $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
338
                      $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
339
                      $data['xmpp_port']        = $currentNetwork->xmpp_port;
340
                      $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
341
                      $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
283 www 342
                      $data['inmail_username']    = $externalCredentials->getUsernameInmail();
343
                      $data['inmail_password']    = $externalCredentials->getPasswordInmail();
257 efrain 344
                  }
345
                }
346
            }
347
 
348
            return  new JsonModel($data);
349
 
1 efrain 350
 
351
        } else {
352
            $data = [
353
                'success' => false,
354
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
355
            ];
356
 
357
            return new JsonModel($data);
358
        }
359
 
360
    }
361
 
754 stevensc 362
    public function themeAction()
363
    {
364
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
365
        $currentNetwork = $currentNetworkPlugin->getNetwork();
1 efrain 366
 
754 stevensc 367
        $request = $this->getRequest();
368
 
369
        if(!$request->isGet()) {
370
            $data = [
371
                'success' => false,
372
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
373
            ];
374
 
375
            return new JsonModel($data);
376
        }
1 efrain 377
 
754 stevensc 378
        if(!$currentNetwork) {
379
            $data = [
380
                'success' => false,
381
                'data' => 'ERROR_NETWORK_NOT_FOUND'
382
            ];
1 efrain 383
 
754 stevensc 384
            return new JsonModel($data);
385
        }
386
 
387
        $data = [
388
            'success' => true,
389
            'theme' => [
390
                'bg-color' => $currentNetwork->css_bg_color,
391
                'body-bg-color' => $currentNetwork->css_body_bg_color,
392
                'bg-color-secondary' => $currentNetwork->css_bg_color_secondary,
393
                'font-color' => $currentNetwork->css_font_color,
394
                'font-color-hover' => $currentNetwork->css_font_color_hover,
395
                'title-color' => $currentNetwork->css_title_color,
396
                'subtitle-color' => $currentNetwork->css_subtitle_color,
397
                'icons-color' => $currentNetwork->css_icons_color,
398
                'button-bg' => $currentNetwork->css_button_bg,
399
                'button-bg-hover' => $currentNetwork->css_button_bg_hover,
400
                'button-text-color' => $currentNetwork->css_button_text_color,
401
                'button-bg-secondary' => $currentNetwork->css_button_bg_secondary,
402
                'button-bg-secondary-hover' => $currentNetwork->css_button_bg_secondary_hover,
403
                'button-text-color-secondary' => $currentNetwork->css_button_text_color_secondary,
404
                'button-bg-tertiary' => $currentNetwork->css_button_bg_tertiary,
405
                'button-text-color-tertiary' => $currentNetwork->css_button_text_color_tertiary,
406
                'border-primary' => $currentNetwork->css_border_primary,
407
                'border-trasnparent' => $currentNetwork->css_border_trasnparent,
408
                'chat-received' => $currentNetwork->css_chat_received,
409
                'chat-send' => $currentNetwork->css_chat_send,
410
                'chat-color' => $currentNetwork->css_chat_color,
411
                'light-gray' => $currentNetwork->css_light_gray,
412
                'gray' => $currentNetwork->css_gray,
413
                'danger' => $currentNetwork->css_danger,
414
                'danger-hover' => $currentNetwork->css_danger_hover,
415
                'online-green' => $currentNetwork->css_online_green,
416
                'border-gray-primary' => $currentNetwork->css_border_gray_primary,
417
                'white' => $currentNetwork->css_white,
418
                'white-backdrop' => $currentNetwork->css_white_backdrop,
419
                'border-radius' => $currentNetwork->css_border_radius,
420
                'light-shadow' => $currentNetwork->css_light_shadow,
421
                'shadow' => $currentNetwork->css_shadow
422
            ]
423
        ];
424
 
425
        return new JsonModel($data);
426
    }
427
 
1 efrain 428
    public function privacyPolicyAction()
429
    {
430
 
431
 
432
 
433
 
434
        $pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
435
 
436
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
437
        $currentNetwork = $currentNetworkPlugin->getNetwork();
438
 
439
        $currentUserPlugin = $this->plugin('currentUserPlugin');
440
 
441
        $pageMapper = PageMapper::getInstance($this->adapter);
442
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
443
 
444
        if (!$page) {
445
            $networkMapper = NetworkMapper::getInstance($this->adapter);
446
            $network = $networkMapper->fetchOneByDefault();
447
 
448
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
449
            if ($pageDefault) {
450
                $page = new Page();
451
                $page->network_id = $currentNetwork->id;
452
                $page->code = $pageDefault->code;
453
                $page->content = $pageDefault->content;
454
                $page->fixed = $pageDefault->fixed;
455
                $page->page_default_id = $pageDefault->id;
456
                $page->title = $pageDefault->title;
457
                $page->status = $pageDefault->status;
458
                $page->type = $pageDefault->type;
459
                $page->url = $pageDefault->url;
460
 
461
                $pageMapper->insert($page);
462
            }
463
        }
464
 
465
        return new JsonModel([
466
            'success' => true,
467
            'data' => [
468
                'title' => $page->title,
469
                'content' => $page->content
470
            ]
471
        ]);
472
 
473
    }
474
 
475
    public function cookiesAction()
476
    {
477
 
478
        $pageCode = Page::PAGE_CODE_COOKIES;
479
 
480
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
481
        $currentNetwork = $currentNetworkPlugin->getNetwork();
482
 
483
        $currentUserPlugin = $this->plugin('currentUserPlugin');
484
 
485
        $pageMapper = PageMapper::getInstance($this->adapter);
486
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
487
 
488
        if (!$page) {
489
            $networkMapper = NetworkMapper::getInstance($this->adapter);
490
            $network = $networkMapper->fetchOneByDefault();
491
 
492
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
493
            if ($pageDefault) {
494
                $page = new Page();
495
                $page->network_id = $currentNetwork->id;
496
                $page->code = $pageDefault->code;
497
                $page->content = $pageDefault->content;
498
                $page->fixed = $pageDefault->fixed;
499
                $page->page_default_id = $pageDefault->id;
500
                $page->title = $pageDefault->title;
501
                $page->status = $pageDefault->status;
502
                $page->type = $pageDefault->type;
503
                $page->url = $pageDefault->url;
504
 
505
                $pageMapper->insert($page);
506
            }
507
        }
508
 
509
        return new JsonModel([
510
            'success' => true,
511
            'data' => [
512
                'title' => $page->title,
513
                'content' => $page->content
514
            ]
515
        ]);
516
    }
517
 
518
    public function professionalismPolicyAction()
519
    {
520
        $pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
521
 
522
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
523
        $currentNetwork = $currentNetworkPlugin->getNetwork();
524
 
525
        $currentUserPlugin = $this->plugin('currentUserPlugin');
526
 
527
 
528
        $pageMapper = PageMapper::getInstance($this->adapter);
529
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
530
 
531
        if (!$page) {
532
            $networkMapper = NetworkMapper::getInstance($this->adapter);
533
            $network = $networkMapper->fetchOneByDefault();
534
 
535
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
536
            if ($pageDefault) {
537
                $page = new Page();
538
                $page->network_id = $currentNetwork->id;
539
                $page->code = $pageDefault->code;
540
                $page->content = $pageDefault->content;
541
                $page->fixed = $pageDefault->fixed;
542
                $page->page_default_id = $pageDefault->id;
543
                $page->title = $pageDefault->title;
544
                $page->status = $pageDefault->status;
545
                $page->type = $pageDefault->type;
546
                $page->url = $pageDefault->url;
547
 
548
                $pageMapper->insert($page);
549
            }
550
        }
551
 
552
        return new JsonModel([
553
            'success' => true,
554
            'data' => [
555
                'title' => $page->title,
556
                'content' => $page->content
557
            ]
558
        ]);
559
    }
560
 
561
 
562
    public function termsAndConditionsAction()
563
    {
564
        $pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
565
 
566
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
567
        $currentNetwork = $currentNetworkPlugin->getNetwork();
568
 
569
        $currentUserPlugin = $this->plugin('currentUserPlugin');
570
 
571
 
572
        $pageMapper = PageMapper::getInstance($this->adapter);
573
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
574
 
575
        if (!$page) {
576
            $networkMapper = NetworkMapper::getInstance($this->adapter);
577
            $network = $networkMapper->fetchOneByDefault();
578
 
579
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
580
            if ($pageDefault) {
581
                $page = new Page();
582
                $page->network_id = $currentNetwork->id;
583
                $page->code = $pageDefault->code;
584
                $page->content = $pageDefault->content;
585
                $page->fixed = $pageDefault->fixed;
586
                $page->page_default_id = $pageDefault->id;
587
                $page->title = $pageDefault->title;
588
                $page->status = $pageDefault->status;
589
                $page->type = $pageDefault->type;
590
                $page->url = $pageDefault->url;
591
 
592
                $pageMapper->insert($page);
593
            }
594
        }
595
 
596
        return new JsonModel([
597
            'success' => true,
598
            'data' => [
599
                'title' => $page->title,
600
                'content' => $page->content
601
            ]
602
        ]);
603
    }
604
 
605
    public function checkSessionAction()
606
    {
607
 
608
        $request = $this->getRequest();
609
        if ($request->isGet()) {
610
 
611
            $currentUserPlugin = $this->plugin('currentUserPlugin');
612
            if (!$currentUserPlugin->hasIdentity()) {
613
                //$flashMessenger = $this->plugin('FlashMessenger');
614
                //$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
615
 
616
                $response = [
617
                    'success' => false,
618
                    'data' => [
619
                        'message' =>  '', //ERROR_SESSION_NOT_FOUND',
620
                        'url' => $this->url()->fromRoute('signout')
621
                    ]
622
                ];
623
 
624
                return new JsonModel($response);
625
            }
626
 
627
            $currentUser = $currentUserPlugin->getUser();
628
 
629
 
630
            if ($currentUser->last_activity_on) {
631
                $last_activity_on = strtotime($currentUser->last_activity_on);
632
            } else {
633
                $last_activity_on = strtotime('-1 day');
634
            }
635
 
636
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
637
            if (time() > $expiry_time) {
638
                //$flashMessenger = $this->plugin('FlashMessenger');
639
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
640
 
641
                $response = [
642
                    'success' => false,
643
                    'data' => [
644
                        'message' => 'ERROR_SESSION_EXPIRED',
645
                        'url' => $this->url()->fromRoute('signout')
646
                    ]
647
                ];
648
            } else {
649
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
650
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
651
 
283 www 652
                /*
1 efrain 653
                $messageMapper = MessageMapper::getInstance($this->adapter);
283 www 654
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);*/
655
 
656
                $total_messages = 0;
1 efrain 657
                $response = [
658
                    'success' => true,
659
                    'data' => [
660
                        'total_notifications' => $total_notifications,
661
                        'total_messages' => $total_messages
662
                    ]
663
                ];
664
            }
665
        } else {
666
            $response = [
667
                'success' => false,
668
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
669
            ];
670
        }
671
 
672
        return new JsonModel($response);
673
    }
674
 
675
 
676
 
677
 
678
 
679
    public function incTotalExternalSharedAction()
680
    {
681
 
682
        $request = $this->getRequest();
683
        if ($request->isPost()) {
684
            $currentUserPlugin = $this->plugin('currentUserPlugin');
685
            $currentUser = $currentUserPlugin->getUser();
686
 
687
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
688
            $currentNetwork = $currentNetworkPlugin->getNetwork();
689
 
690
            $code       = $this->params()->fromRoute('code');
691
            $type       = $this->params()->fromRoute('type');
692
            $user       = $this->params()->fromRoute('user');
693
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
694
            $rand       = intval($this->params()->fromRoute('rand'), 10);
695
            $password   = $this->params()->fromRoute('password');
696
 
697
 
698
 
699
            $checkpassword = '';
700
 
701
 
702
            $userCheck = '';
703
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
704
                $userMapper = UserMapper::getInstance($this->adapter);
705
                $userCheck = $userMapper->fetchOneByUuid($user);
706
                if ($userCheck) {
707
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
708
                }
709
            }
710
 
711
            if (empty($password) || $password != $checkpassword) {
712
                $data = [
713
                    'success' => false,
714
                    'data' => 'ERROR_UNAUTHORIZED'
715
                ];
716
 
717
                return new JsonModel($data);
718
            }
719
 
720
 
721
 
722
 
723
 
724
 
725
 
726
 
727
 
728
            if ($type == 'feed' && $code) {
729
                $feedMapper =  FeedMapper::getInstance($this->adapter);
730
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
731
 
732
 
733
                if ($feed) {
734
 
735
                    if ($feed->network_id != $currentNetwork->id) {
736
                        $data = [
737
                            'success' => false,
738
                            'data' =>    'ERROR_UNAUTHORIZED'
739
                        ];
740
 
741
                        return new JsonModel($data);
742
                    }
743
 
744
                    if ($feedMapper->incTotalExternalShared($feed->id)) {
745
                        $total = $feedMapper->fetchTotalExternalShared($feed->id);
746
 
747
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
748
 
749
                        $data = [
750
                            'success' => true,
751
                            'data' => $total,
752
                        ];
753
 
754
                        return new JsonModel($data);
755
                    } else {
756
                        $data = [
757
                            'success' => false,
758
                            'data' => $feedMapper->getError()
759
                        ];
760
 
761
                        return new JsonModel($data);
762
                    }
763
                } else {
764
                    $data = [
765
                        'success' => false,
766
                        'data' => 'ERROR_FEED_NOT_FOUND',
767
                    ];
768
 
769
                    return new JsonModel($data);
770
                }
771
            } else if ($type == 'post' && $code) {
772
 
773
                $postMapper = PostMapper::getInstance($this->adapter);
774
                $post = $postMapper->fetchOneByUuid($code);
775
 
776
                if ($post && $post->status == Post::STATUS_ACTIVE) {
777
 
778
                    if ($post->network_id != $currentNetwork->id) {
779
                        $data = [
780
                            'success' => false,
781
                            'data' =>    'ERROR_UNAUTHORIZED'
782
                        ];
783
 
784
                        return new JsonModel($data);
785
                    }
786
 
787
 
788
                    if ($postMapper->incTotalExternalShared($post->id)) {
789
                        $total = $postMapper->fetchTotalExternalShared($post->id);
790
 
791
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el post : ' . $post->title);
792
 
793
 
794
 
795
                        $data = [
796
                            'success' => true,
797
                            'data' => $total,
798
                        ];
799
 
800
                        return new JsonModel($data);
801
                    } else {
802
                        $data = [
803
                            'success' => false,
804
                            'data' => $postMapper->getError()
805
                        ];
806
 
807
                        return new JsonModel($data);
808
                    }
809
                } else {
810
                    $data = [
811
                        'success' => false,
812
                        'data' => 'ERROR_POST_NOT_FOUND'
813
                    ];
814
 
815
                    return new JsonModel($data);
816
                }
817
            }
818
        } else {
819
            $response = [
820
                'success' => false,
821
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
822
            ];
823
 
824
            return new JsonModel($response);
825
        }
826
    }
827
 
247 efrain 828
 
829
 
830
    public function languageAction()
831
    {
832
        $request = $this->getRequest();
833
 
834
        if ($request->isGet()) {
835
 
836
 
837
 
838
            $pathname = dirname(__DIR__);
839
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
840
 
841
 
842
            if(file_exists($filename)) {
843
 
844
                $arr =  include $filename;
845
                $arr = array_filter($arr, function($a)  {
846
                    return strpos($a, 'LABEL_') !== false;
847
                }, ARRAY_FILTER_USE_KEY);
848
 
849
 
850
                $data = [];
851
                foreach($arr as $key => $value)
852
                {
853
                    $key = str_replace('LABEL_', 'LANG_', $key);
854
 
855
                    $data[ $key ] = $value;
856
 
857
                }
858
 
859
 
860
 
861
                $response = [
862
                    'success' => true,
863
                    'data' => $data
864
                ];
865
 
866
                return new JsonModel($response);
867
 
868
 
869
            } else {
870
                $response = [
871
                    'success' => false,
872
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
873
                ];
874
 
875
                return new JsonModel($response);
876
            }
877
 
878
 
879
 
880
 
881
 
882
        } else {
883
            $response = [
884
                'success' => false,
885
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
886
            ];
887
 
888
            return new JsonModel($response);
889
        }
890
 
891
 
892
    }
893
 
1 efrain 894
    public function shareAction()
895
    {
896
        $request = $this->getRequest();
897
        if ($request->isGet()) {
898
            $currentUserPlugin = $this->plugin('currentUserPlugin');
899
            $currentUser = $currentUserPlugin->getUser();
247 efrain 900
 
1 efrain 901
            $code       = $this->params()->fromRoute('code');
902
            $type       = $this->params()->fromRoute('type');
903
            $user       = $this->params()->fromRoute('user');
904
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
905
            $rand       = intval($this->params()->fromRoute('rand'), 10);
906
            $password   = $this->params()->fromRoute('password');
247 efrain 907
 
908
 
909
 
1 efrain 910
            $checkpassword = '';
247 efrain 911
 
912
 
1 efrain 913
            $userCheck = '';
914
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
915
                $userMapper = UserMapper::getInstance($this->adapter);
916
                $userCheck = $userMapper->fetchOneByUuid($user);
917
                if ($userCheck) {
918
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
919
                }
920
            }
247 efrain 921
 
1 efrain 922
            if (empty($password) || $password != $checkpassword) {
923
                $data = [
924
                    'success' => false,
925
                    'data' => 'ERROR_UNAUTHORIZED'
926
                ];
247 efrain 927
 
1 efrain 928
                return new JsonModel($data);
929
            }
247 efrain 930
 
1 efrain 931
            /*
247 efrain 932
             $share_params = [
933
             'type' => $type,
934
             'code' => $code,
935
             'user' => $currentUser->uuid,
936
             'timestamp' => $timestamp,
937
             'rand' => $rand,
938
             'password' => $password,
939
             ];
940
 
941
             $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
942
             */
1 efrain 943
 
254 efrain 944
            $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
247 efrain 945
 
254 efrain 946
            $networkMapper = NetworkMapper::getInstance($this->adapter);
947
            $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
247 efrain 948
 
254 efrain 949
            if(!$network) {
950
                $network = $networkMapper->fetchOneByDefault();
137 efrain 951
            }
247 efrain 952
 
254 efrain 953
            $hostname = trim($network->main_hostname);
954
            $base_share = 'https://' . $hostname;
247 efrain 955
 
1 efrain 956
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
957
            $share_image        = $base_share . '/images/ll-logo.png';
958
            $share_title        = '';
959
            $share_description  = '';
249 efrain 960
 
247 efrain 961
 
962
 
1 efrain 963
            if ($type == 'feed' && $code) {
964
                $feedMapper =  FeedMapper::getInstance($this->adapter);
965
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
247 efrain 966
 
1 efrain 967
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
247 efrain 968
 
1 efrain 969
                if ($feed) {
247 efrain 970
 
1 efrain 971
                    $share_title = $feed->title ? $feed->title : '';
247 efrain 972
 
1 efrain 973
                    if ($feed->posted_or_shared  == Feed::SHARED) {
247 efrain 974
 
975
 
1 efrain 976
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
977
                        if ($feed->title) {
247 efrain 978
 
1 efrain 979
                            $share_title = $share_title  .  ' -  ' . $feed->title;
980
                        }
981
                    }
247 efrain 982
 
983
 
1 efrain 984
                    $share_description = $feed->description;
247 efrain 985
 
1 efrain 986
                    $image_name = '';
345 www 987
                    if ($feed->file_type == Storage::FILE_TYPE_IMAGE) {
247 efrain 988
 
1 efrain 989
                        $image_name = $feed->file_name;
990
                    } else  if ($feed->file_image_preview) {
991
                        $image_name = $feed->file_image_preview;
992
                    }
247 efrain 993
 
994
 
995
 
996
                        if ($image_name) {
997
 
998
                            $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
999
 
257 efrain 1000
                            $target_path = $this->config['leaderslinked.frontend.frontend']. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
1001
 
247 efrain 1002
 
1003
 
257 efrain 1004
                            //$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
1005
 
247 efrain 1006
                            if (!file_exists($target_path)) {
1007
                                mkdir($target_path, 0755, true);
1008
                            }
1009
 
1010
 
1011
 
1012
                            $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
1013
 
1014
 
1015
 
1016
                            if (!file_exists($target)) {
1017
 
1018
                                copy($source, $target);
1019
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
1020
                            } else {
1021
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
1022
                            }
1 efrain 1023
                        }
1024
                } else {
247 efrain 1025
 
249 efrain 1026
                    return new JsonModel([
1027
                        'success' => false,
1028
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
1029
                    ]);
1 efrain 1030
                }
1031
            } else if ($type == 'post' && $code) {
247 efrain 1032
 
1 efrain 1033
                $postMapper = PostMapper::getInstance($this->adapter);
1034
                $post = $postMapper->fetchOneByUuid($code);
247 efrain 1035
 
1 efrain 1036
                if ($post && $post->status == Post::STATUS_ACTIVE) {
1037
                    $share_title = $post->title;
1038
                    $share_description = $post->description;
247 efrain 1039
 
1040
 
1 efrain 1041
                    if ($post->image) {
1042
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
247 efrain 1043
 
1044
 
257 efrain 1045
                       // $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
247 efrain 1046
 
257 efrain 1047
                        $target_path = $this->config['leaderslinked.frontend.frontend'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
1048
 
1 efrain 1049
                        if (!file_exists($target_path)) {
1050
                            mkdir($target_path, 0755, true);
1051
                        }
247 efrain 1052
 
1053
 
1054
 
1 efrain 1055
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
247 efrain 1056
 
1057
 
1058
 
1 efrain 1059
                        if (!file_exists($target)) {
247 efrain 1060
 
1 efrain 1061
                            copy($source, $target);
1062
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
1063
                        } else {
1064
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
1065
                        }
1066
                    }
1067
                } else {
247 efrain 1068
 
249 efrain 1069
                    return new JsonModel([
1070
                        'success' => false,
1071
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
1072
                    ]);
1 efrain 1073
                }
1074
            }
247 efrain 1075
 
1 efrain 1076
            if ($currentUserPlugin->hasIdentity()) {
1077
                $currentUser = $currentUserPlugin->getUser();
1078
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
247 efrain 1079
 
1 efrain 1080
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1081
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
247 efrain 1082
 
1 efrain 1083
                    if ($connection) {
247 efrain 1084
 
1 efrain 1085
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
1086
                            $connectionMapper->approve($connection);
1087
                        }
1088
                    } else {
1089
                        $connection = new Connection();
1090
                        $connection->request_from = $currentUser->id;
1091
                        $connection->request_to = $userCheck->id;
1092
                        $connection->status = Connection::STATUS_ACCEPTED;
247 efrain 1093
 
1 efrain 1094
                        $connectionMapper->insert($connection);
1095
                    }
1096
                }
1097
 
1098
            } else {
249 efrain 1099
                $this->cache->setItem('user_share_invitation', [
1100
                    'code' => $code,
1101
                    'type' => $type,
1102
                    'user' => $user
1103
                ]);
1 efrain 1104
            }
1105
            return new JsonModel([
249 efrain 1106
                'success' => true,
1107
                'data' => [
1108
                    'image' => $share_image,
1109
                    'url' => $share_url,
1110
                    'title' => strip_tags($share_title),
1111
                    'description' => strip_tags($share_description),
1112
                ]
247 efrain 1113
 
1 efrain 1114
            ]);
1115
 
1116
        } else {
1117
            $response = [
1118
                'success' => false,
1119
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1120
            ];
1121
 
1122
            return new JsonModel($response);
1123
        }
1124
    }
333 www 1125
 
1126
 
1 efrain 1127
}