Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3377 | Rev 3379 | 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;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
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\CompanyMapper;
16
use LeadersLinked\Mapper\CompanyUserMapper;
17
use LeadersLinked\Model\Company;
18
use LeadersLinked\Mapper\PageMapper;
19
use LeadersLinked\Mapper\MessageMapper;
2466 stevensc 20
use LeadersLinked\Mapper\UserMapper;
21
use LeadersLinked\Mapper\UserProfileMapper;
1 www 22
use LeadersLinked\Mapper\CompanyUserRoleMapper;
23
use LeadersLinked\Model\Role;
24
use LeadersLinked\Library\Functions;
2466 stevensc 25
use LeadersLinked\Mapper\ConnectionMapper;
26
use LeadersLinked\Mapper\LocationMapper;
1 www 27
use LeadersLinked\Mapper\PostMapper;
2466 stevensc 28
use LeadersLinked\Mapper\ProfileVisitMapper;
1 www 29
use LeadersLinked\Model\Post;
3138 efrain 30
use LeadersLinked\Mapper\UtilMapper;
3298 efrain 31
use LeadersLinked\Mapper\FeedMapper;
32
use LeadersLinked\Model\Feed;
33
use LeadersLinked\Model\User;
34
use LeadersLinked\Model\Connection;
1 www 35
 
36
class HomeController extends AbstractActionController
37
{
38
    /**
39
     *
40
     * @var AdapterInterface
41
     */
42
    private $adapter;
2466 stevensc 43
 
44
 
1 www 45
    /**
46
     *
47
     * @var AbstractAdapter
48
     */
49
    private $cache;
2466 stevensc 50
 
1 www 51
    /**
52
     *
53
     * @var  LoggerInterface
54
     */
55
    private $logger;
56
 
2466 stevensc 57
 
1 www 58
    /**
59
     *
60
     * @var array
61
     */
62
    private $config;
2466 stevensc 63
 
1 www 64
    /**
65
     *
66
     * @param AdapterInterface $adapter
67
     * @param AbstractAdapter $cache
68
     * @param LoggerInterface $logger
69
     * @param array $config
70
     */
2466 stevensc 71
    public function __construct($adapter, $cache, $logger,  $config)
1 www 72
    {
73
        $this->adapter      = $adapter;
74
        $this->cache        = $cache;
75
        $this->logger       = $logger;
76
        $this->config       = $config;
77
    }
2466 stevensc 78
 
79
 
80
 
1 www 81
    public function indexAction()
82
    {
83
 
3298 efrain 84
        $currentUserPlugin = $this->plugin('currentUserPlugin');
3302 efrain 85
        if ($currentUserPlugin->hasIdentity()) {
2466 stevensc 86
            return $this->redirect()->toRoute('dashboard');
1 www 87
        } else {
2466 stevensc 88
            return $this->redirect()->toRoute('signin');
1 www 89
        }
90
    }
2466 stevensc 91
 
92
 
93
 
94
 
1 www 95
    public function privacyPolicyAction()
96
    {
97
        $pageMapper = PageMapper::getInstance($this->adapter);
98
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
2466 stevensc 99
 
1 www 100
        $this->layout()->setTemplate('layout/layout.phtml');
101
        $viewModel = new ViewModel();
102
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
103
        $viewModel->setVariable('page', $page);
2466 stevensc 104
        return $viewModel;
1 www 105
    }
2466 stevensc 106
 
1 www 107
    public function cookiesAction()
108
    {
109
        $pageMapper = PageMapper::getInstance($this->adapter);
110
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
2466 stevensc 111
 
1 www 112
        $this->layout()->setTemplate('layout/layout.phtml');
113
        $viewModel = new ViewModel();
114
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
115
        $viewModel->setVariable('page', $page);
2466 stevensc 116
        return $viewModel;
1 www 117
    }
2466 stevensc 118
 
1 www 119
    public function professionalismPolicyAction()
120
    {
121
        //
2466 stevensc 122
 
1 www 123
        $pageMapper = PageMapper::getInstance($this->adapter);
124
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
2466 stevensc 125
 
1 www 126
        $this->layout()->setTemplate('layout/layout.phtml');
127
        $viewModel = new ViewModel();
128
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
129
        $viewModel->setVariable('page', $page);
2466 stevensc 130
        return $viewModel;
1 www 131
    }
2466 stevensc 132
 
133
 
1 www 134
    public function termsAndConditionsAction()
135
    {
136
        $pageMapper = PageMapper::getInstance($this->adapter);
137
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
2466 stevensc 138
 
1 www 139
        $this->layout()->setTemplate('layout/layout.phtml');
140
        $viewModel = new ViewModel();
141
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
142
        $viewModel->setVariable('page', $page);
2466 stevensc 143
        return $viewModel;
1 www 144
    }
2466 stevensc 145
 
1 www 146
    public function checkSessionAction()
147
    {
148
 
149
        $request = $this->getRequest();
2466 stevensc 150
        if ($request->isGet()) {
151
 
1 www 152
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2466 stevensc 153
            if (!$currentUserPlugin->hasIdentity()) {
1 www 154
                $flashMessenger = $this->plugin('FlashMessenger');
155
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
2466 stevensc 156
 
1 www 157
                $response = [
158
                    'success' => false,
159
                    'data' => [
160
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
161
                        'url' => $this->url()->fromRoute('signout')
162
                    ]
163
                ];
2466 stevensc 164
 
1 www 165
                return new JsonModel($response);
166
            }
2466 stevensc 167
 
1 www 168
            $currentUser = $currentUserPlugin->getUser();
2466 stevensc 169
 
170
 
171
            if ($currentUser->last_activity_on) {
1 www 172
                $last_activity_on = strtotime($currentUser->last_activity_on);
173
            } else {
174
                $last_activity_on = strtotime('-1 day');
175
            }
176
 
177
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
178
            if (time() > $expiry_time) {
2466 stevensc 179
                //$flashMessenger = $this->plugin('FlashMessenger');
180
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
1 www 181
 
182
                $response = [
183
                    'success' => false,
184
                    'data' => [
185
                        'message' => 'ERROR_SESSION_EXPIRED',
186
                        'url' => $this->url()->fromRoute('signout')
187
                    ]
188
                ];
189
            } else {
190
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
191
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
2466 stevensc 192
 
193
                $messageMapper = MessageMapper::getInstance($this->adapter);
1 www 194
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
195
                $response = [
196
                    'success' => true,
197
                    'data' => [
198
                        'total_notifications' => $total_notifications,
199
                        'total_messages' => $total_messages
200
                    ]
201
                ];
202
            }
203
        } else {
204
            $response = [
205
                'success' => false,
206
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
207
            ];
208
        }
2466 stevensc 209
 
1 www 210
        return new JsonModel($response);
211
    }
2466 stevensc 212
 
3262 efrain 213
 
1 www 214
    public function postAction()
215
    {
3364 efrain 216
        $request = $this->getRequest();
217
        if ($request->isGet()) {
218
            $currentUserPlugin = $this->plugin('currentUserPlugin');
219
            $currentUser = $currentUserPlugin->getUser();
220
 
221
 
222
            $id = $this->params()->fromRoute('id');
223
 
224
            $postMapper = PostMapper::getInstance($this->adapter);
225
            $post = $postMapper->fetchOneByUuid($id);
226
 
227
            if (!$post || $post->status != Post::STATUS_ACTIVE) {
228
                $flashMessenger = $this->plugin('FlashMessenger');
229
 
230
                if (!$id) {
231
                    $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
232
                    return $this->redirect()->toRoute('dashboard');
233
                }
1 www 234
            }
3364 efrain 235
 
236
 
237
 
238
            $timestamp = time();
239
 
240
            list($usec, $sec) = explode(' ', microtime());
241
            $seed = intval($sec + ((float) $usec * 100000));
242
            mt_srand($seed, MT_RAND_MT19937);
243
            $rand =  mt_rand();
244
 
245
 
2466 stevensc 246
 
3366 efrain 247
            $password  = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key) ;
3298 efrain 248
 
3364 efrain 249
 
250
            $query = [
3373 efrain 251
                'll0' => $currentUser->uuid,
252
                'll1' => $timestamp,
253
                'll2' => $rand,
254
                'll3' => $password,
3364 efrain 255
 
256
            ];
257
 
258
            $share_url = $this->url()->fromRoute('share',  ['type' => 'post', 'code' => $post->uuid], ['force_canonical' => true, 'query' => $query ]);
259
 
260
 
261
            $this->layout()->setTemplate('layout/layout.phtml');
262
            $viewModel = new ViewModel();
263
            $viewModel->setTemplate('leaders-linked/home/post.phtml');
264
            $viewModel->setVariables([
265
                'post' => $post,
266
                'id' => $post->id,
267
                'uuid' => $post->uuid,
268
                'title' => $post->title,
269
                'description' => $post->description,
270
                'url' => $post->url,
271
                'date' => $post->date,
272
                'status' => $post->status,
273
                'image' => $post->image,
274
                'file' => $post->file,
275
                'added_on' => $post->added_on,
276
                'share_external_url' => $share_url,
277
 
278
            ]);
279
            return $viewModel;
280
 
281
        } else {
282
            $response = [
283
                'success' => false,
284
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
285
            ];
286
 
287
            return new JsonModel($response);
288
        }
1 www 289
    }
3298 efrain 290
 
291
    public function shareAction()
292
    {
293
        $request = $this->getRequest();
294
        if ($request->isGet()) {
295
            $currentUserPlugin = $this->plugin('currentUserPlugin');
296
            $currentUser = $currentUserPlugin->getUser();
297
 
3364 efrain 298
            $code       = $this->params()->fromRoute('code');
299
            $type       = $this->params()->fromRoute('type');
3377 efrain 300
 
301
            /*
3373 efrain 302
            $user       = $this->params()->fromQuery('ll0');
303
            $timestamp  = intval($this->params()->fromQuery('ll1'), 10);
304
            $rand       = intval($this->params()->fromQuery('ll2'), 10);
305
            $password   = $this->params()->fromQuery('ll3');
3364 efrain 306
            $checkpassword = '';
307
 
3369 efrain 308
 
309
 
3364 efrain 310
            $userCheck = '';
311
            if($user && $timestamp > 0 && $rand > 0 && $password) {
312
                $userMapper = UserMapper::getInstance($this->adapter);
313
                $userCheck = $userMapper->fetchOneByUuid($user);
314
                if($userCheck) {
3366 efrain 315
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
3364 efrain 316
                }
317
            }
3349 efrain 318
 
3364 efrain 319
            if(empty($password) || $password != $checkpassword) {
320
                $data = [
3349 efrain 321
                    'success' => false,
322
                    'data' => 'ERROR_UNAUTHORIZED'
323
                ];
324
 
3364 efrain 325
                return new JsonModel($data);
3377 efrain 326
            }*/
3371 efrain 327
 
3364 efrain 328
 
329
 
330
 
331
 
3357 efrain 332
 
3298 efrain 333
 
3335 efrain 334
 
335
            if(strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
3355 efrain 336
                $base_share = 'http://' . $_SERVER['HTTP_HOST'];
3298 efrain 337
            } else {
3355 efrain 338
                $base_share = 'https://' . $_SERVER['HTTP_HOST'];
3298 efrain 339
            }
340
 
341
 
3374 efrain 342
            /*
3372 efrain 343
            echo '<pre>';
344
            print_r($_SERVER);
345
            echo '</pre>';
3374 efrain 346
            */
3298 efrain 347
 
3372 efrain 348
 
3355 efrain 349
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
350
            $share_image        = $base_share . '/images/ll-logo.png';
3298 efrain 351
            $share_title        = '';
352
            $share_description  = '';
3364 efrain 353
 
3298 efrain 354
 
355
            if($type == 'feed' && $code ) {
356
                $feedMapper =  FeedMapper::getInstance($this->adapter);
357
                $feed = $feedMapper->fetchOneByUuid($code);
358
 
359
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
360
                    $share_title = $feed->title ? $feed->title : $feed->description;
361
                    $share_description = $feed->description;
362
 
363
                    $image_name = '';
364
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
365
 
366
                        $image_name = $feed->file_name;
367
 
368
                    } else  if($feed->file_image_preview) {
369
                        $image_name = $feed->file_image_preview;
370
                    }
371
 
372
 
373
 
374
                    if( $image_name ) {
375
 
376
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
377
 
378
 
379
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
380
 
381
                        if(!file_exists($target_path)) {
382
                            mkdir($target_path, 0755, true);
383
                        }
384
 
385
 
386
 
387
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
388
 
389
 
390
 
391
                        if(!file_exists($target)) {
392
 
393
                            copy($source, $target);
3355 efrain 394
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 395
 
396
                        } else {
3355 efrain 397
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 398
 
399
                        }
400
 
401
 
402
 
403
 
404
                    }
405
 
3349 efrain 406
                } else {
407
 
408
                    if($currentUserPlugin->hasIdentity()) {
409
                        $this->layout()->setTemplate('layout/layout.phtml');
410
                    } else {
411
                        $this->layout()->setTemplate('layout/share.phtml');
412
                    }
413
                    $viewModel = new ViewModel();
414
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
415
                    return $viewModel;
3298 efrain 416
                }
417
 
418
 
419
            } else if ($type == 'post' && $code) {
420
 
421
                $postMapper = PostMapper::getInstance($this->adapter);
422
                $post = $postMapper->fetchOneByUuid($code);
423
 
424
                if($post && $post->status == Post::STATUS_ACTIVE) {
425
                    $share_title = $post->title;
426
                    $share_description = $post->description;
427
 
428
 
429
                    if($post->image) {
430
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
431
 
432
 
433
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
434
 
435
                        if(!file_exists($target_path)) {
436
                            mkdir($target_path, 0755, true);
437
                        }
438
 
439
 
440
 
441
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
442
 
443
 
444
 
445
                        if(!file_exists($target)) {
446
 
447
                            copy($source, $target);
3355 efrain 448
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 449
 
450
                        } else {
3355 efrain 451
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 452
 
453
                        }
454
                    }
3349 efrain 455
                } else {
456
 
457
                    if($currentUserPlugin->hasIdentity()) {
458
                        $this->layout()->setTemplate('layout/layout.phtml');
459
                    } else {
460
                        $this->layout()->setTemplate('layout/share.phtml');
461
                    }
462
                    $viewModel = new ViewModel();
463
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
464
                    return $viewModel;
3298 efrain 465
                }
466
            }
3374 efrain 467
 
3376 efrain 468
            /*
3372 efrain 469
            echo '<pre>';
3371 efrain 470
            print_r([ 'share_image' => $share_image,
471
                'share_url' => $share_url,
472
                'share_title' => strip_tags($share_title),
3372 efrain 473
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
474
            exit;
3376 efrain 475
            */
3298 efrain 476
 
3349 efrain 477
            if($currentUserPlugin->hasIdentity()) {
3377 efrain 478
                /*
3364 efrain 479
                $currentUser = $currentUserPlugin->getUser();
480
                if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
481
 
482
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
483
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
484
 
485
                    if($connection) {
486
 
487
                        if($connection->status != Connection::STATUS_ACCEPTED) {
488
                            $connectionMapper->approve($connection);
489
                        }
490
 
491
                    } else {
492
                        $connection = new Connection();
493
                        $connection->request_from = $currentUser->id;
494
                        $connection->request_to = $userCheck->id;
495
                        $connection->status = Connection::STATUS_ACCEPTED;
496
 
497
                        $connectionMapper->insert($connection);
498
                    }
499
                }
500
 
3377 efrain 501
                */
3364 efrain 502
 
503
 
3349 efrain 504
                $this->layout()->setTemplate('layout/layout.phtml');
505
            } else {
3378 efrain 506
                //$this->cache->addItem('user_share_invitation', $user);
3364 efrain 507
 
3349 efrain 508
                $this->layout()->setTemplate('layout/share.phtml');
509
            }
3298 efrain 510
            $viewModel = new ViewModel();
511
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
512
            $viewModel->setVariables([
3352 efrain 513
                'share_image' => $share_image,
514
                'share_url' => $share_url,
3356 efrain 515
                'share_title' => strip_tags($share_title),
516
                'share_description' => strip_tags($share_description),
3349 efrain 517
 
3298 efrain 518
            ]);
519
 
520
 
521
            return $viewModel;
522
 
523
 
524
        } else {
525
            $response = [
526
                'success' => false,
527
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
528
            ];
529
 
530
            return new JsonModel($response);
531
        }
532
 
533
 
534
    }
535
 
3364 efrain 536
 
1 www 537
}