Your IP : 216.73.216.209


Current Path : /home/megadansyp/www/administrator/components/com_eventgallery/controllers/
Upload File :
Current File : /home/megadansyp/www/administrator/components/com_eventgallery/controllers/flickr.php

<?php
/**
 * @package     Sven.Bluege
 * @subpackage  com_eventgallery
 *
 * @copyright   Copyright (C) 2005 - 2019 Sven Bluege All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use \Joomla\Component\Eventgallery\Site\Library\Connector\Flickr;


class EventgalleryControllerFlickr extends JControllerForm
{
    public function getAlbums() {
        header('Content-Type: application/json');
        $app = JFactory::getApplication();
        $db = JFactory::getDbo();

        $id = $app->input->getInt('id');

        /**
         * @var EventgalleryLibraryFactoryFlickraccount $accountFactory
         *
         */
        $accountFactory = EventgalleryLibraryFactoryFlickraccount::getInstance();
        $account = $accountFactory->getAccountById($id);

        $albums = Flickr::getPhotoSets($account);

        echo '{"albums":' . json_encode($albums) . '}';
        die();
    }

    public function testAuthToken() {
        header('Content-Type: application/json');
        $result =  '{"valid":false}';
        /**
         * @var Joomla\CMS\Application\AdministratorApplication $app
         */

        $app = JFactory::getApplication();
        $accountid = $app->input->getInt('accountid',  null);

        if ($accountid != null) {
            /**
             * @var EventgalleryLibraryFactoryFlickraccount $accountFactory
             *
             */
            $accountFactory = EventgalleryLibraryFactoryFlickraccount::getInstance();
            $flickrAccount = $accountFactory->getAccountById($accountid);

            if ($flickrAccount != null) {
                if ($this->checkAuthToken($flickrAccount)) {
                    $result =  '{"valid":true}';
                }
            }
        }

        echo $result;
        die();
    }

    /**
     * @param $flickrAccount EventgalleryLibraryFlickraccount
     */
    private function checkAuthToken($flickrAccount) {
        $oauth_nonce = '12345';
        $oauth_timestamp = time();
        $result = false;

        if (empty($flickrAccount->getAPISecret())) {
            return true;
        }

        $url = 'https://www.flickr.com/services/rest?nojsoncallback=1&format=json&oauth_nonce='.$oauth_nonce.'&oauth_consumer_key='.urlencode($flickrAccount->getAPIKey()).'&oauth_timestamp='.$oauth_timestamp.'&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token='.urlencode($flickrAccount->getAuthToken()).'&method=flickr.test.login';

        $signedUrl = \Joomla\Component\Eventgallery\Site\Library\Connector\Flickr::appendSignaturetoUrl('GET', $url, $flickrAccount->getAPISecret(), $flickrAccount->getAuthTokenSecret());

        $response = \JHttpFactory::getHttp()->get($signedUrl, [], 5);
        $code = $response->code;
        $body = $response->body;
        if ($code == 200) {
            $data = json_decode($response->body);
            if ($data->stat == 'ok') {
                $result = true;
            }


        }
        return $result;
    }

}