Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3380 | Rev 3382 | 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
 
3380 efrain 250
            $share_params = [
3379 efrain 251
                'type' => 'post',
252
                'code' => $post->uuid,
253
                'user' => $currentUser->uuid,
254
                'timestamp' => $timestamp,
255
                'rand' => $rand,
256
                'password' => $password,
257
            ];
3364 efrain 258
 
3379 efrain 259
 
3380 efrain 260
            $share_external_url = $this->url()->fromRoute('share',$share_params  , ['force_canonical' => true]);
3379 efrain 261
 
3364 efrain 262
            $this->layout()->setTemplate('layout/layout.phtml');
263
            $viewModel = new ViewModel();
264
            $viewModel->setTemplate('leaders-linked/home/post.phtml');
265
            $viewModel->setVariables([
266
                'post' => $post,
267
                'id' => $post->id,
268
                'uuid' => $post->uuid,
269
                'title' => $post->title,
270
                'description' => $post->description,
271
                'url' => $post->url,
272
                'date' => $post->date,
273
                'status' => $post->status,
274
                'image' => $post->image,
275
                'file' => $post->file,
276
                'added_on' => $post->added_on,
3379 efrain 277
                'share_external_url' =>  $share_external_url,
3364 efrain 278
 
279
            ]);
280
            return $viewModel;
281
 
282
        } else {
283
            $response = [
284
                'success' => false,
285
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
286
            ];
287
 
288
            return new JsonModel($response);
289
        }
1 www 290
    }
3298 efrain 291
 
292
    public function shareAction()
293
    {
294
        $request = $this->getRequest();
295
        if ($request->isGet()) {
296
            $currentUserPlugin = $this->plugin('currentUserPlugin');
297
            $currentUser = $currentUserPlugin->getUser();
298
 
3364 efrain 299
            $code       = $this->params()->fromRoute('code');
300
            $type       = $this->params()->fromRoute('type');
3379 efrain 301
            $user       = $this->params()->fromRoute('user');
302
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
303
            $rand       = intval($this->params()->fromRoute('rand'), 10);
304
            $password   = $this->params()->fromRoute('password');
3377 efrain 305
 
3379 efrain 306
 
307
 
3364 efrain 308
            $checkpassword = '';
309
 
3379 efrain 310
            /*
3369 efrain 311
 
3364 efrain 312
            $userCheck = '';
313
            if($user && $timestamp > 0 && $rand > 0 && $password) {
314
                $userMapper = UserMapper::getInstance($this->adapter);
315
                $userCheck = $userMapper->fetchOneByUuid($user);
316
                if($userCheck) {
3366 efrain 317
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
3364 efrain 318
                }
319
            }
3349 efrain 320
 
3364 efrain 321
            if(empty($password) || $password != $checkpassword) {
322
                $data = [
3349 efrain 323
                    'success' => false,
324
                    'data' => 'ERROR_UNAUTHORIZED'
325
                ];
326
 
3364 efrain 327
                return new JsonModel($data);
3377 efrain 328
            }*/
3371 efrain 329
 
3364 efrain 330
 
331
 
332
 
333
 
3357 efrain 334
 
3298 efrain 335
 
3335 efrain 336
 
337
            if(strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
3355 efrain 338
                $base_share = 'http://' . $_SERVER['HTTP_HOST'];
3298 efrain 339
            } else {
3355 efrain 340
                $base_share = 'https://' . $_SERVER['HTTP_HOST'];
3298 efrain 341
            }
342
 
343
 
3374 efrain 344
            /*
3372 efrain 345
            echo '<pre>';
346
            print_r($_SERVER);
347
            echo '</pre>';
3374 efrain 348
            */
3298 efrain 349
 
3372 efrain 350
 
3355 efrain 351
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
352
            $share_image        = $base_share . '/images/ll-logo.png';
3298 efrain 353
            $share_title        = '';
354
            $share_description  = '';
3364 efrain 355
 
3298 efrain 356
 
357
            if($type == 'feed' && $code ) {
358
                $feedMapper =  FeedMapper::getInstance($this->adapter);
359
                $feed = $feedMapper->fetchOneByUuid($code);
360
 
361
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
362
                    $share_title = $feed->title ? $feed->title : $feed->description;
363
                    $share_description = $feed->description;
364
 
365
                    $image_name = '';
366
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
367
 
368
                        $image_name = $feed->file_name;
369
 
370
                    } else  if($feed->file_image_preview) {
371
                        $image_name = $feed->file_image_preview;
372
                    }
373
 
374
 
375
 
376
                    if( $image_name ) {
377
 
378
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
379
 
380
 
381
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
382
 
383
                        if(!file_exists($target_path)) {
384
                            mkdir($target_path, 0755, true);
385
                        }
386
 
387
 
388
 
389
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
390
 
391
 
392
 
393
                        if(!file_exists($target)) {
394
 
395
                            copy($source, $target);
3355 efrain 396
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 397
 
398
                        } else {
3355 efrain 399
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 400
 
401
                        }
402
 
403
 
404
 
405
 
406
                    }
407
 
3349 efrain 408
                } else {
409
 
410
                    if($currentUserPlugin->hasIdentity()) {
411
                        $this->layout()->setTemplate('layout/layout.phtml');
412
                    } else {
413
                        $this->layout()->setTemplate('layout/share.phtml');
414
                    }
415
                    $viewModel = new ViewModel();
416
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
417
                    return $viewModel;
3298 efrain 418
                }
419
 
420
 
421
            } else if ($type == 'post' && $code) {
422
 
423
                $postMapper = PostMapper::getInstance($this->adapter);
424
                $post = $postMapper->fetchOneByUuid($code);
425
 
426
                if($post && $post->status == Post::STATUS_ACTIVE) {
427
                    $share_title = $post->title;
428
                    $share_description = $post->description;
429
 
430
 
431
                    if($post->image) {
432
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
433
 
434
 
435
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
436
 
437
                        if(!file_exists($target_path)) {
438
                            mkdir($target_path, 0755, true);
439
                        }
440
 
441
 
442
 
443
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
444
 
445
 
446
 
447
                        if(!file_exists($target)) {
448
 
449
                            copy($source, $target);
3355 efrain 450
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 451
 
452
                        } else {
3355 efrain 453
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 454
 
455
                        }
456
                    }
3349 efrain 457
                } else {
458
 
459
                    if($currentUserPlugin->hasIdentity()) {
460
                        $this->layout()->setTemplate('layout/layout.phtml');
461
                    } else {
462
                        $this->layout()->setTemplate('layout/share.phtml');
463
                    }
464
                    $viewModel = new ViewModel();
465
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
466
                    return $viewModel;
3298 efrain 467
                }
468
            }
3374 efrain 469
 
3381 efrain 470
 
3372 efrain 471
            echo '<pre>';
3371 efrain 472
            print_r([ 'share_image' => $share_image,
473
                'share_url' => $share_url,
474
                'share_title' => strip_tags($share_title),
3372 efrain 475
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
476
            exit;
3381 efrain 477
 
3298 efrain 478
 
3349 efrain 479
            if($currentUserPlugin->hasIdentity()) {
3377 efrain 480
                /*
3364 efrain 481
                $currentUser = $currentUserPlugin->getUser();
482
                if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
483
 
484
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
485
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
486
 
487
                    if($connection) {
488
 
489
                        if($connection->status != Connection::STATUS_ACCEPTED) {
490
                            $connectionMapper->approve($connection);
491
                        }
492
 
493
                    } else {
494
                        $connection = new Connection();
495
                        $connection->request_from = $currentUser->id;
496
                        $connection->request_to = $userCheck->id;
497
                        $connection->status = Connection::STATUS_ACCEPTED;
498
 
499
                        $connectionMapper->insert($connection);
500
                    }
501
                }
502
 
3377 efrain 503
                */
3364 efrain 504
 
505
 
3349 efrain 506
                $this->layout()->setTemplate('layout/layout.phtml');
507
            } else {
3378 efrain 508
                //$this->cache->addItem('user_share_invitation', $user);
3364 efrain 509
 
3349 efrain 510
                $this->layout()->setTemplate('layout/share.phtml');
511
            }
3298 efrain 512
            $viewModel = new ViewModel();
513
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
514
            $viewModel->setVariables([
3352 efrain 515
                'share_image' => $share_image,
516
                'share_url' => $share_url,
3356 efrain 517
                'share_title' => strip_tags($share_title),
518
                'share_description' => strip_tags($share_description),
3349 efrain 519
 
3298 efrain 520
            ]);
521
 
522
 
523
            return $viewModel;
524
 
525
 
526
        } else {
527
            $response = [
528
                'success' => false,
529
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
530
            ];
531
 
532
            return new JsonModel($response);
533
        }
534
 
535
 
536
    }
537
 
3364 efrain 538
 
1 www 539
}