Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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