Proyectos de Subversion LeadersLinked - Services

Rev

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