Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6866 | | Comparar con el anterior | Ultima modificación | Ver Log |

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