Proyectos de Subversion LeadersLinked - Services

Rev

Rev 137 | Rev 249 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 137 Rev 247
Línea 559... Línea 559...
559
 
559
 
560
            return new JsonModel($response);
560
            return new JsonModel($response);
561
        }
561
        }
Línea -... Línea 562...
-
 
562
    }
-
 
563
 
-
 
564
    
-
 
565
    
-
 
566
    public function languageAction()
-
 
567
    {
-
 
568
        $request = $this->getRequest();
-
 
569
 
-
 
570
        if ($request->isGet()) {
-
 
571
            
-
 
572
     
-
 
573
            
-
 
574
            $pathname = dirname(__DIR__);
-
 
575
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
-
 
576
            
-
 
577
            
-
 
578
            if(file_exists($filename)) {
-
 
579
                
-
 
580
                $arr =  include $filename;
-
 
581
                $arr = array_filter($arr, function($a)  {
-
 
582
                    return strpos($a, 'LABEL_') !== false;
-
 
583
                }, ARRAY_FILTER_USE_KEY); 
-
 
584
                
-
 
585
                
-
 
586
                $data = [];
-
 
587
                foreach($arr as $key => $value) 
-
 
588
                {
-
 
589
                    $key = str_replace('LABEL_', 'LANG_', $key);
-
 
590
                    
-
 
591
                    $data[ $key ] = $value;
-
 
592
                     
-
 
593
                }
-
 
594
                
-
 
595
                
-
 
596
                
-
 
597
                $response = [
-
 
598
                    'success' => true,
-
 
599
                    'data' => $data
-
 
600
                ];
-
 
601
                
-
 
602
                return new JsonModel($response);
-
 
603
                
-
 
604
                
-
 
605
            } else {
-
 
606
                $response = [
-
 
607
                    'success' => false,
-
 
608
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
609
                ];
-
 
610
                
-
 
611
                return new JsonModel($response);
-
 
612
            }
-
 
613
            
-
 
614
            
-
 
615
            
-
 
616
            
-
 
617
            
-
 
618
        } else {
-
 
619
            $response = [
-
 
620
                'success' => false,
-
 
621
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
622
            ];
-
 
623
            
-
 
624
            return new JsonModel($response);
-
 
625
        }
-
 
626
 
-
 
627
        
562
    }
628
    }
563
 
629
    
564
    public function shareAction()
630
    public function shareAction()
565
    {
631
    {
566
        $request = $this->getRequest();
632
        $request = $this->getRequest();
567
        if ($request->isGet()) {
633
        if ($request->isGet()) {
568
            $currentUserPlugin = $this->plugin('currentUserPlugin');
634
            $currentUserPlugin = $this->plugin('currentUserPlugin');
569
            $currentUser = $currentUserPlugin->getUser();
635
            $currentUser = $currentUserPlugin->getUser();
570
 
636
            
571
            $code       = $this->params()->fromRoute('code');
637
            $code       = $this->params()->fromRoute('code');
572
            $type       = $this->params()->fromRoute('type');
638
            $type       = $this->params()->fromRoute('type');
573
            $user       = $this->params()->fromRoute('user');
639
            $user       = $this->params()->fromRoute('user');
574
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
640
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
575
            $rand       = intval($this->params()->fromRoute('rand'), 10);
641
            $rand       = intval($this->params()->fromRoute('rand'), 10);
576
            $password   = $this->params()->fromRoute('password');
642
            $password   = $this->params()->fromRoute('password');
577
 
643
            
578
 
644
            
579
 
645
            
580
            $checkpassword = '';
646
            $checkpassword = '';
581
 
647
            
582
 
648
            
583
            $userCheck = '';
649
            $userCheck = '';
584
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
650
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
585
                $userMapper = UserMapper::getInstance($this->adapter);
651
                $userMapper = UserMapper::getInstance($this->adapter);
586
                $userCheck = $userMapper->fetchOneByUuid($user);
652
                $userCheck = $userMapper->fetchOneByUuid($user);
587
                if ($userCheck) {
653
                if ($userCheck) {
588
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
654
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
589
                }
655
                }
590
            }
656
            }
591
 
657
            
592
            if (empty($password) || $password != $checkpassword) {
658
            if (empty($password) || $password != $checkpassword) {
593
                $data = [
659
                $data = [
594
                    'success' => false,
660
                    'success' => false,
595
                    'data' => 'ERROR_UNAUTHORIZED'
661
                    'data' => 'ERROR_UNAUTHORIZED'
596
                ];
662
                ];
597
 
663
                
598
                return new JsonModel($data);
664
                return new JsonModel($data);
599
            }
665
            }
600
 
666
            
601
            /*
667
            /*
602
            $share_params = [
668
             $share_params = [
603
                'type' => $type,
669
             'type' => $type,
604
                'code' => $code,
670
             'code' => $code,
605
                'user' => $currentUser->uuid,
671
             'user' => $currentUser->uuid,
606
                'timestamp' => $timestamp,
672
             'timestamp' => $timestamp,
607
                'rand' => $rand,
673
             'rand' => $rand,
-
 
674
             'password' => $password,
-
 
675
             ];
-
 
676
             
-
 
677
             $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
-
 
678
             */
Línea 608... Línea -...
608
                'password' => $password,
-
 
609
            ];
-
 
610
            
-
 
611
            $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
-
 
612
            */
-
 
613
 
679
            
614
 
680
            
615
 
681
            
616
            if(empty($_SERVER['HTTP_ORIGIN'])) {
682
            if(empty($_SERVER['HTTP_ORIGIN'])) {
617
                $server_name = $_SERVER['HTTP_HOST'];
683
                $server_name = $_SERVER['HTTP_HOST'];
618
            } else {
684
            } else {
619
                $server_name = $_SERVER['HTTP_ORIGIN'];
685
                $server_name = $_SERVER['HTTP_ORIGIN'];
620
            }
686
            }
621
 
687
            
622
 
688
            
623
 
689
            
624
 
690
            
625
            if (strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
691
            if (strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
626
                $base_share = 'http://' . $server_name;
692
                $base_share = 'http://' . $server_name;
627
            } else {
693
            } else {
628
                $base_share = 'https://' .$server_name;
694
                $base_share = 'https://' .$server_name;
629
            }
695
            }
630
 
696
            
631
 
697
            
632
            /*
698
            /*
633
            echo '<pre>'; 
699
             echo '<pre>';
634
            print_r($_SERVER);
700
             print_r($_SERVER);
635
            echo '</pre>'; 
701
             echo '</pre>';
636
            */
702
             */
637
 
703
            
638
 
704
            
639
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
705
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
640
            $share_image        = $base_share . '/images/ll-logo.png';
706
            $share_image        = $base_share . '/images/ll-logo.png';
641
            $share_title        = '';
707
            $share_title        = '';
642
            $share_description  = '';
708
            $share_description  = '';
643
 
709
            
644
 
710
            
645
            if ($type == 'feed' && $code) {
711
            if ($type == 'feed' && $code) {
646
                $feedMapper =  FeedMapper::getInstance($this->adapter);
712
                $feedMapper =  FeedMapper::getInstance($this->adapter);
647
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
713
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
648
 
714
                
649
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
715
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
650
 
716
                
651
                if ($feed) {
717
                if ($feed) {
652
 
718
                    
653
                    $share_title = $feed->title ? $feed->title : '';
719
                    $share_title = $feed->title ? $feed->title : '';
654
 
720
                    
655
                    if ($feed->posted_or_shared  == Feed::SHARED) {
721
                    if ($feed->posted_or_shared  == Feed::SHARED) {
656
 
722
                        
657
 
723
                        
658
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
724
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
659
                        if ($feed->title) {
725
                        if ($feed->title) {
660
 
726
                            
661
                            $share_title = $share_title  .  ' -  ' . $feed->title;
727
                            $share_title = $share_title  .  ' -  ' . $feed->title;
662
                        }
728
                        }
663
                    }
729
                    }
664
 
730
                    
665
 
731
                    
666
                    $share_description = $feed->description;
732
                    $share_description = $feed->description;
667
 
733
                    
668
                    $image_name = '';
734
                    $image_name = '';
669
                    if ($feed->file_type == Feed::FILE_TYPE_IMAGE) {
735
                    if ($feed->file_type == Feed::FILE_TYPE_IMAGE) {
670
 
736
                        
671
                        $image_name = $feed->file_name;
737
                        $image_name = $feed->file_name;
672
                    } else  if ($feed->file_image_preview) {
738
                    } else  if ($feed->file_image_preview) {
673
                        $image_name = $feed->file_image_preview;
739
                        $image_name = $feed->file_image_preview;
674
                    }
740
                    }
675
 
741
                        
676
 
742
                        
677
 
743
                        
678
                    if ($image_name) {
744
                        if ($image_name) {
679
 
745
                            
680
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
746
                            $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
681
 
747
                            
682
 
748
                            
683
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
749
                            $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
684
 
750
                            
685
                        if (!file_exists($target_path)) {
751
                            if (!file_exists($target_path)) {
686
                            mkdir($target_path, 0755, true);
752
                                mkdir($target_path, 0755, true);
687
                        }
753
                            }
688
 
754
                            
689
 
755
                            
690
 
756
                            
691
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
757
                            $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
692
 
758
                            
693
 
759
                            
694
 
760
                            
695
                        if (!file_exists($target)) {
761
                            if (!file_exists($target)) {
696
 
762
                                
697
                            copy($source, $target);
763
                                copy($source, $target);
-
 
764
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
698
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
765
                            } else {
699
                        } else {
-
 
700
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
766
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
701
                        }
767
                            }
702
                    }
768
                        }
703
                } else {
769
                } else {
704
 
770
                    
705
                    $response = new Response();
771
                    $response = new Response();
Línea 706... Línea 772...
706
                    $headers = $response->getHeaders();
772
                    $headers = $response->getHeaders();
707
                    $headers->clearHeaders();
773
                    $headers->clearHeaders();
708
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
774
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
709
                    
775
                    
710
                    $response->setStatusCode(404);
776
                    $response->setStatusCode(404);
711
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
777
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
712
                    return $response;
778
                    return $response;
713
                }
779
                }
714
            } else if ($type == 'post' && $code) {
780
            } else if ($type == 'post' && $code) {
715
 
781
                
716
                $postMapper = PostMapper::getInstance($this->adapter);
782
                $postMapper = PostMapper::getInstance($this->adapter);
717
                $post = $postMapper->fetchOneByUuid($code);
783
                $post = $postMapper->fetchOneByUuid($code);
718
 
784
                
719
                if ($post && $post->status == Post::STATUS_ACTIVE) {
785
                if ($post && $post->status == Post::STATUS_ACTIVE) {
720
                    $share_title = $post->title;
786
                    $share_title = $post->title;
721
                    $share_description = $post->description;
787
                    $share_description = $post->description;
722
 
788
                    
723
 
789
                    
724
                    if ($post->image) {
790
                    if ($post->image) {
725
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
791
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
726
 
792
                        
727
 
793
                        
728
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
794
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
729
 
795
                        
730
                        if (!file_exists($target_path)) {
796
                        if (!file_exists($target_path)) {
731
                            mkdir($target_path, 0755, true);
797
                            mkdir($target_path, 0755, true);
732
                        }
798
                        }
733
 
799
                        
734
 
800
                        
735
 
801
                        
736
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
802
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
737
 
803
                        
738
 
804
                        
739
 
805
                        
740
                        if (!file_exists($target)) {
806
                        if (!file_exists($target)) {
741
 
807
                            
742
                            copy($source, $target);
808
                            copy($source, $target);
743
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
809
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
744
                        } else {
810
                        } else {
745
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
811
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
746
                        }
812
                        }
747
                    }
813
                    }
748
                } else {
814
                } else {
749
 
815
                    
Línea 750... Línea 816...
750
                    $response = new Response();
816
                    $response = new Response();
751
                    $headers = $response->getHeaders();
817
                    $headers = $response->getHeaders();
752
                    $headers->clearHeaders();
818
                    $headers->clearHeaders();
753
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
819
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
754
                    
820
                    
755
                    $response->setStatusCode(404);
821
                    $response->setStatusCode(404);
756
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
822
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
757
                    return $response;
823
                    return $response;
758
                }
824
                }
759
            }
825
            }
760
 
826
            
761
            /*
827
            /*
762
            echo '<pre>';
828
             echo '<pre>';
763
            print_r([ 'share_image' => $share_image,
829
             print_r([ 'share_image' => $share_image,
764
                'share_url' => $share_url,
830
             'share_url' => $share_url,
765
                'share_title' => strip_tags($share_title),
831
             'share_title' => strip_tags($share_title),
766
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
832
             'share_description' => strip_tags($share_description)]);  echo '</pre>';
767
            exit;
833
             exit;
768
            */
834
             */
769
 
835
            
770
            if ($currentUserPlugin->hasIdentity()) {
836
            if ($currentUserPlugin->hasIdentity()) {
771
                $currentUser = $currentUserPlugin->getUser();
837
                $currentUser = $currentUserPlugin->getUser();
772
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
838
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
773
 
839
                    
774
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
840
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
775
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
841
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
776
 
842
                    
777
                    if ($connection) {
843
                    if ($connection) {
778
 
844
                        
779
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
845
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
780
                            $connectionMapper->approve($connection);
846
                            $connectionMapper->approve($connection);
781
                        }
847
                        }
782
                    } else {
848
                    } else {
783
                        $connection = new Connection();
849
                        $connection = new Connection();
784
                        $connection->request_from = $currentUser->id;
850
                        $connection->request_from = $currentUser->id;
785
                        $connection->request_to = $userCheck->id;
851
                        $connection->request_to = $userCheck->id;
Línea 786... Línea -...
786
                        $connection->status = Connection::STATUS_ACCEPTED;
-
 
787
 
-
 
788
                        $connectionMapper->insert($connection);
-
 
789
                    }
-
 
790
                }
852
                        $connection->status = Connection::STATUS_ACCEPTED;
791
 
853
                        
792
 
-
 
793
 
-
 
794
 
854
                        $connectionMapper->insert($connection);
795
                $this->layout()->setTemplate('layout/layout.phtml');
855
                    }
796
            } else {
856
                }
797
                $this->cache->setItem('user_share_invitation', $user);
857
 
798
 
858
            } else {
799
                $this->layout()->setTemplate('layout/share.phtml');
859
                $this->cache->setItem('user_share_invitation', $user);
800
            }
860
            }
801
            return new JsonModel([
-
 
802
                'share_image' => $share_image,
-
 
803
                'share_url' => $share_url,
-
 
804
                'share_title' => strip_tags($share_title),
-
 
805
                'share_description' => strip_tags($share_description),
-
 
806
                // 'share_increment_external_counter_url' => $share_increment_external_counter_url,
-
 
807
 
-
 
808
            ]);
-
 
809
 
-
 
810
        } else {
-
 
811
            $response = [
-
 
812
                'success' => false,
-
 
813
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
814
            ];
-
 
815
 
-
 
816
            return new JsonModel($response);
-
 
817
        }
-
 
818
    }
-
 
819
    
-
 
820
    public function languageAction()
-
 
821
    {
-
 
822
        $request = $this->getRequest();
-
 
823
 
-
 
824
        if ($request->isGet()) {
-
 
825
            
-
 
826
     
-
 
827
            
-
 
828
            $pathname = dirname(__DIR__);
-
 
829
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
-
 
830
            
-
 
831
            
-
 
Línea 832... Línea -...
832
            if(file_exists($filename)) {
-
 
833
                
-
 
834
                $arr =  include $filename;
-
 
835
                $arr = array_filter($arr, function($a)  {
-
 
836
                    return strpos($a, 'LABEL_') !== false;
-
 
837
                }, ARRAY_FILTER_USE_KEY); 
-
 
838
                
-
 
839
                
-
 
840
                $data = [];
-
 
841
                foreach($arr as $key => $value) 
-
 
842
                {
-
 
843
                    $key = str_replace('LABEL_', 'LANG_', $key);
-
 
844
                    
-
 
845
                    $data[ $key ] = $value;
-
 
846
                     
-
 
847
                }
-
 
848
                
-
 
849
                
-
 
850
                
-
 
851
                $response = [
-
 
852
                    'success' => true,
-
 
853
                    'data' => $data
-
 
854
                ];
-
 
855
                
-
 
856
                return new JsonModel($response);
-
 
857
                
-
 
858
                
-
 
859
            } else {
861
            return new JsonModel([
860
                $response = [
-
 
861
                    'success' => false,
-
 
862
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
863
                ];
-
 
Línea 864... Línea 862...
864
                
862
                'share_image' => $share_image,
865
                return new JsonModel($response);
863
                'share_url' => $share_url,
866
            }
864
                'share_title' => strip_tags($share_title),
867
            
865
                'share_description' => strip_tags($share_description),
868
            
866
                // 'share_increment_external_counter_url' => $share_increment_external_counter_url,
Línea 869... Línea 867...
869
            
867
                
870
            
868
            ]);
871
            
-
 
872
        } else {
-
 
873
            $response = [
869
            
874
                'success' => false,
870
        } else {