Proyectos de Subversion LeadersLinked - Services

Rev

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