Proyectos de Subversion LeadersLinked - Services

Rev

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