Ejemplo n.º 1
0
function setupDocsClient($token = null)
{
    global $authSubURL;
    $docsClient = null;
    // Fetch a new AuthSub token?
    if (!$token && !isset($_SESSION['sessionToken'])) {
        $next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        $scope = 'http://docs.google.com/feeds/ https://docs.google.com/feeds/';
        $secure = 0;
        $session = 1;
        $permission = 1;
        // 1 - allows posting notices && allows reading profile data
        $authSubURL = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
    } else {
        if (isset($_SESSION['sessionToken'])) {
            $httpClient = new Zend_Gdata_HttpClient();
            $httpClient->setAuthSubToken($_SESSION['sessionToken']);
            $docsClient = new Zend_Gdata_Docs($httpClient, 'google-OCRPHPDemo-v0.1');
        } else {
            $httpClient = new Zend_Gdata_HttpClient();
            $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken(trim($token), $httpClient);
            $httpClient->setAuthSubToken($_SESSION['sessionToken']);
            $docsClient = new Zend_Gdata_Docs($httpClient, 'google-OCRPHPDemo-v0.1');
        }
    }
    return $docsClient;
}
Ejemplo n.º 2
0
/**
 * Upgrade the single-use token to a session token.
 *
 * @param string $singleUseToken A valid single use token that is upgradable to a session token.
 * @return void
 */
function updateAuthSubToken($singleUseToken)
{
    try {
        $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);
    } catch (Zend_Gdata_App_Exception $e) {
        print 'ERROR - Token upgrade for ' . $singleUseToken . ' failed : ' . $e->getMessage();
        return;
    }
    $_SESSION['sessionToken'] = $sessionToken;
    header('Location: ' . HOME_URL);
}
Ejemplo n.º 3
0
 /**
  * Returns a HTTP client object with the appropriate headers for communicating
  * with Google using AuthSub authentication.
  *
  * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  * it is obtained.  The single use token supplied in the URL when redirected
  * after the user succesfully authenticated to Google is retrieved from the
  * $_GET['token'] variable.
  *
  * @return Zend_Http_Client
  */
 function getAuthSubHttpClient()
 {
     global $_SESSION, $_GET;
     $client = new Zend_Gdata_HttpClient();
     if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
         $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
     }
     if (empty($_SESSION['sessionToken'])) {
         return null;
     }
     $client->setAuthSubToken($_SESSION['sessionToken']);
     return $client;
 }
Ejemplo n.º 4
0
 /**
  * Returns a HTTP client object with the appropriate headers for communicating
  * with Google using AuthSub authentication.
  *
  * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  * it is obtained.  The single use token supplied in the URL when redirected
  * after the user succesfully authenticated to Google is retrieved from the
  * $_GET['token'] variable.
  *
  * @return Zend_Http_Client
  */
 public function getAuthSubHttpClient()
 {
     global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase;
     $client = new Zend_Gdata_HttpClient();
     if ($_authSubKeyFile != null) {
         // set the AuthSub key
         $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true);
     }
     if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
         $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
     }
     $client->setAuthSubToken($_SESSION['sessionToken']);
     return $client;
 }
Ejemplo n.º 5
0
 function getAuthSubHttpClient($mmm_id, $username)
 {
     if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
         $this->redirect('/yts/index/');
         exit;
         return false;
     } else {
         if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
             $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
             $sessionToken = $_SESSION['sessionToken'];
             $this->time = time();
             $this->record['Yt']['mmm_id'] = $mmm_id;
             $this->record['Yt']['sessionToken'] = $sessionToken;
             $this->record['Yt']['status'] = '1';
             $this->record['Yt']['etime'] = $this->time;
             /*$qry="insert into yt_login(mmm_id , user_id ,sessionToken , status) values
             	 ('$mmm_id', '$username' , '$sessionToken', '1')";
             	 $result = mysql_query($qry);
             	 */
         }
     }
     $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
     return $httpClient;
 }
Ejemplo n.º 6
0
 /**
  * @expectedException Zend_Gdata_App_HttpException
  */
 public function testAuthSubSessionTokenCatchesHttpClientException()
 {
     $adapter = new Zend_Http_Client_Adapter_Test();
     $adapter->setNextRequestWillFail(true);
     $client = new Zend_Gdata_HttpClient();
     $client->setUri('http://example.com/AuthSub');
     $client->setAdapter($adapter);
     $newtok = Zend_Gdata_AuthSub::getAuthSubSessionToken($this->token, $client);
 }
 public function googleAction()
 {
     //$this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full';
     if (!isset($_SESSION['cal_token'])) {
         if (isset($_GET['token'])) {
             // You can convert the single-use token to a session token.
             $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
             // Store the session token in our session.
             $_SESSION['cal_token'] = $session_token;
         } else {
             // Display link to generate single-use token
             $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], $my_calendar, 0, 1);
             echo "Click <a href='{$googleUri}'>here</a> " . "to authorize this application.";
             exit;
         }
     }
     // Create an authenticated HTTP Client to talk to Google.
     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']);
     // Create a Gdata object using the authenticated Http Client
     $cal = new Zend_Gdata_Calendar($client);
     var_export($cal->getCalendarListFeed()->count());
 }
Ejemplo n.º 8
0
 function gCalDemo()
 {
     if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
         $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
     }
     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
     // load the library
     $this->load->library('Gcal');
     // examples of useage for each function
     //################################################
     //##############OutputCalendarList################
     //################################################
     /*
     $calFeed = $this->gcal->outputCalendarList($client);
     
     echo '<h1>' . $calFeed->title->text . '</h1>';
     echo '<ul>';
     foreach ($calFeed as $calendar) {
     	echo '<li>'.$calendar->title->text.'</li>';
     }
     echo '</ul>';
     */
     //################################################
     //##############End OutputCalendarList############
     //################################################
     echo "<br />- - - - - - - - - - - - - - - - - - - - \n\t\t\t- - - - - - - - - - - - - - - - - - - - - - - - - - - -<br />";
     //################################################
     //##############OutputCalendarEvents##############
     //################################################
     /*
     $eventFeed = $this->gcal->outputCalendarEvents($client);
     
     echo "<ul>";
     foreach ($eventFeed as $event){
     	echo "\t<li><b>Event Title: </b>".$event->title->text."</li>\n";
     	
     	echo "\t\t<ul>\n";
     	echo "\t\t\t<li><b>Event ID: </b>". $event->id->text ."</li>\n";
     	echo "\t\t\t<li><b>Content: </b>".$event->content->text."</li>\n";
     	foreach($event->when as $when){
     		//echo "<pre>";
     		//print_r($when);
     		//echo "</pre>";
     		
     		echo "\t\t\t<li><b>Starts:</b> " . $when->startTime . "</li>\n";
     		echo "\t\t\t<li><b>Ends:</b> " . $when->endTime . "</li>\n";
     	}
     	echo "\t\t</ul>\n";
     	echo "\t</li>\n";
     }
     echo "</ul>";
     */
     //################################################
     //############End OutputCalendarEvents############
     //################################################
     echo "<br />- - - - - - - - - - - - - - - - - - - - \n\t\t\t- - - - - - - - - - - - - - - - - - - - - - - - - - - -<br />";
     //################################################
     //##############calEventsByDateRange##############
     //################################################
     /*
     $startDate = '2009-06-15';
     $endDate = '2009-06-17';
     
     $eventQuery = $this->gcal->calEventsByDateRange($client, $startDate, $endDate);
     
     echo "<ul>";
     foreach ($eventQuery as $event){
     	echo "\t<li><b>Event Title: </b>".$event->title->text."</li>\n";
     	
     	echo "\t\t<ul>\n";
     	echo "\t\t\t<li><b>Event ID: </b>". $event->id->text ."</li>\n";
     	echo "\t\t\t<li><b>Content: </b>".$event->content->text."</li>\n";
     	foreach($event->when as $when){
     		//echo "<pre>";
     		//print_r($when);
     		//echo "</pre>";
     		
     		echo "\t\t\t<li><b>Starts:</b> " . $when->startTime . "</li>\n";
     		echo "\t\t\t<li><b>Ends:</b> " . $when->endTime . "</li>\n";
     	}
     	echo "\t\t</ul>\n";
     	echo "\t</li>\n";
     }
     echo "</ul>";
     */
     //################################################
     //############End calEventsByDateRange############
     //################################################
     echo "<br />- - - - - - - - - - - - - - - - - - - - \n\t\t\t- - - - - - - - - - - - - - - - - - - - - - - - - - - -<br />";
     //################################################
     //##############calFullTextQuery##################
     //################################################
     /*
     $query = "enter your query string here"; // searches in both title and event content
     $eventFullQuery = $this->gcal->calFullTextQuery($client, $query);
     
     echo "<ul>";
     foreach ($eventFullQuery as $event){
     	echo "\t<li><b>Event Title: </b>".$event->title->text."</li>\n";
     	
     	echo "\t\t<ul>\n";
     	echo "\t\t\t<li><b>Event ID: </b>". $event->id->text ."</li>\n";
     	echo "\t\t\t<li><b>Content: </b>".$event->content->text."</li>\n";
     	foreach($event->when as $when){
     		//echo "<pre>";
     		//print_r($when);
     		//echo "</pre>";
     		
     		echo "\t\t\t<li><b>Starts:</b> " . $when->startTime . "</li>\n";
     		echo "\t\t\t<li><b>Ends:</b> " . $when->endTime . "</li>\n";
     	}
     	echo "\t\t</ul>\n";
     	echo "\t</li>\n";
     }
     echo "</ul>";
     */
     //################################################
     //##############End calFullTextQuery##############
     //################################################
     echo "<br />- - - - - - - - - - - - - - - - - - - - \n\t\t\t- - - - - - - - - - - - - - - - - - - - - - - - - - - -<br />";
     //################################################
     //#################createEvent####################
     //################################################
     /*
     $eventArray = array('title'     =>  'My test event',
     					'desc'      =>  'This is a description for my test event',
     					'where'     =>  'My house',
     					'startDate' =>  '2009-06-16',
     					'startTime' =>  '22:00',
     					'endDate'   =>  '2009-06-17',
     					'endTime'   =>  '04:00',
     					'tzOffset'  =>  '-04'
     					);
     
     $this->gcal->createEvent($client, $eventArray);
     */
     //################################################
     //###############End createEvent##################
     //################################################
     echo "<br />- - - - - - - - - - - - - - - - - - - - \n\t\t\t- - - - - - - - - - - - - - - - - - - - - - - - - - - -<br />";
     //################################################
     //##############createQuickEvent##################
     //################################################
     /*
     // include a time + am/pm and day
     // day can be day of the week or tomorrow
     // can use a format like "next tuesday"
     $eventInfo = "Dinner at my house next tuesday at 9pm";
     $this->gcal->createQuickEvent($client, $eventInfo);
     */
     //################################################
     //##############End createQuickEvent##############
     //################################################
 }
Ejemplo n.º 9
0
/**
 * Returns a HTTP client object with the appropriate headers for communicating
 * with Google using AuthSub authentication.
 *
 * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
 * it is obtained.  The single use token supplied in the URL when redirected
 * after the user succesfully authenticated to Google is retrieved from the
 * $_GET['token'] variable.
 *
 * @return Zend_Http_Client
 */
function getAuthSubHttpClient()
{
    global $_SESSION, $_GET;
    if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
        $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
    }
    $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
    return $client;
}
Ejemplo n.º 10
0
function authenticate($singleUseToken = null)
{
    $sessionToken = isset($_SESSION['sessionToken']) ? $_SESSION['sessionToken'] : null;
    // If there is no AuthSub session or one-time token waiting for us,
    // redirect the user to Google Health's AuthSub handler to get one.
    if (!$sessionToken && !$singleUseToken) {
        $next = getCurrentUrl();
        $secure = 1;
        $session = 1;
        $authSubHandler = 'https://www.google.com/h9/authsub';
        $permission = 1;
        // 1 - allows reading of the profile && posting notices
        $authSubURL = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, SCOPE, $secure, $session, $authSubHandler);
        $authSubURL .= '&permission=' . $permission;
        echo '<a href="' . $authSubURL . '">Link your Google Health Account</a>';
        exit;
    }
    $client = new Zend_Gdata_HttpClient();
    $client->setAuthSubPrivateKeyFile(HEALTH_PRIVATE_KEY, null, true);
    // Convert an AuthSub one-time token into a session token if needed
    if ($singleUseToken && !$sessionToken) {
        $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken, $client);
        $_SESSION['sessionToken'] = $sessionToken;
    }
    $client->setAuthSubToken($sessionToken);
    return $client;
}
<?php

session_start();
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Photos');
//Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
if (isset($_GET['token'])) {
    $_SESSION['google_session_token'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
    $params = "";
    foreach ($_GET as $key => $value) {
        $params = $params . $key . '=' . $value . '&';
    }
    //$params = $params . 'ajax=';
    $params = rtrim($params, '&');
    header("location:../download_album.php?" . $params);
}
?>


<html>
	<head>
		<title>Facebook Album</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
		<script src="resources/js/bootstrap.min.js"></script>
		<link rel="stylesheet" type="text/css" href="resources/css/bootstrap.min.css" />
		<style>
		
		#login-div {
			text-align: center;
			margin-top: 15%;
Ejemplo n.º 12
0
 private function _getAuthSubClient()
 {
     if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
         $request = $this->getRequest();
         $nextUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri();
         $scope = 'http://www.google.com/base/feeds/items';
         $secure = false;
         $session = true;
         $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($nextUrl, $scope, $secure, $session);
         header("HTTP/1.0 307 Temporary redirect");
         header("Location: " . $authSubUrl);
         exit;
     }
     if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
         $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
     }
     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
     return $client;
 }
    // Parameters to give to AuthSub server
    $next = getCurrentUrl();
    $scope = GoogleCalendarInterface::GCAL_INTEGRATION_SCOPE;
    $secure = false;
    $session = true;
    // Redirect the user to the AuthSub server to sign in
    $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
    header("HTTP/1.0 307 Temporary redirect");
    header("Location: " . $authSubUrl);
    exit;
} else {
    try {
        $client = new Zend_Gdata_HttpClient();
        $pathToKey = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('app_googleCalendarIntegration_privateKeyPath');
        $client->setAuthSubPrivateKeyFile($pathToKey, null, true);
        $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
    } catch (Exception $e) {
        sfErrorNotifier::alert("Google Calendar Init: " . $e->getMessage());
        $this->redirect('default', array('module' => 'googleCalendarIntegration', 'action' => 'step3Error'));
    }
    $redirectUrl = '';
    if ($sessionToken) {
        $loggedInUser = PcUserPeer::getLoggedInUser();
        if ($loggedInUser) {
            $googleCalendarInterface = new GoogleCalendarInterface($loggedInUser);
            $googleCalendarInterface->resetDbEntry();
            $googleCalendarInterface->setSessionToken($sessionToken);
        }
        $configuration->loadHelpers('Url');
        $redirectUrl = 'http://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController') . '/googleCalendarIntegration/step3';
    } else {
Ejemplo n.º 14
0
 /**
  * Return authenticated http client
  * 
  * @param string  $token
  * 
  * @return \self
  * 
  * @version 5.0
  */
 public static function getAuthSubHttpClient($token = false)
 {
     $next = elgg_get_site_url() . GLOBAL_IZAP_VIDEOS_PAGEHANDLER . '/upload/' . elgg_get_logged_in_user_entity()->username . '/youtube';
     $scope = 'http://gdata.youtube.com';
     $secure = false;
     $session = true;
     if (!isset($_SESSION['YT_TOKEN']) && !$token) {
         return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
     } else {
         if (!isset($_SESSION['YT_TOKEN']) && $token) {
             $_SESSION['YT_TOKEN'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($token);
         }
     }
     return new self(Zend_Gdata_AuthSub::getHttpClient($_SESSION['YT_TOKEN']), izap_admin_settings_izap_videos('youtubeDeveloperKey'));
 }
Ejemplo n.º 15
0
 function _getAuthSubHttpClient()
 {
     //if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
     if (!isset($_COOKIE['sessionToken']) && !isset($_GET['token'])) {
         //echo '<a href="' . $this->_getAuthSubUrl() . '">Login!</a>';
         //exit;
         redirect('http://' . $_SERVER['HTTP_HOST'] . '/signin');
         //} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
     } else {
         if (!isset($_COOKIE['sessionToken']) && isset($_GET['token'])) {
             $sessionToken = $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
             $this->load->helper('cookie');
             $cookie = array('name' => 'sessionToken', 'value' => $sessionToken, 'expire' => '86500');
             set_cookie($cookie);
         }
     }
     //var_dump($_COOKIE);
     if (!empty($_COOKIE['sessionToken'])) {
         $client = Zend_Gdata_AuthSub::getHttpClient($_COOKIE['sessionToken']);
     } else {
         $client = Zend_Gdata_AuthSub::getHttpClient($sessionToken);
     }
     //$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
     $client->setHeaders('X-GData-Key', "key=" . $this->developerKey);
     $client->setAuthSubPrivateKeyFIle('/var/www/myrsakey.pem', null, true);
     return $client;
     /*
     
     	    if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
     
     	        echo '<a href="' . $this->_getAuthSubUrl() . '">Login!</a>';
     	        exit;
     
     	    } else if (isset($_GET['token'])) {
     
     		try{
     
     		        $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
     
     	        } catch(Exception $ex) { }
     	    }
     
     
     		try{
     		    $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
     			    return $client;
     		}  catch(Exception $ex) { }
     		
     		return FALSE;
     */
 }
Ejemplo n.º 16
0
    public function getAuthSubHttpClient() {
        // Security check
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ));

        //global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase;
        $client = new Zend_Gdata_HttpClient();
        if ($_authSubKeyFile != null) {
            // set the AuthSub key
            $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true);
        }
        if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
            $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
        }
        $client->setAuthSubToken($_SESSION['sessionToken']);
        return $client;
    }
Ejemplo n.º 17
0
 /**
  * Processes the workflow to authenticate users.
  *
  * Uses the _sessionNs session namespace to store the AuthSub session token
  * after it is obtained. The single use token supplied in the URL when
  * redirected after the user succesfully authenticated to Google is
  * retrieved from the token request parameter
  *
  * @return void
  */
 public function processPageLoad()
 {
     $this->_sessionNs = new Zend_Session_Namespace('GoogleAuthSub');
     $token = $this->_request->getParam('token');
     if (!$this->_sessionNs->sessionToken) {
         if (!$token) {
             $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
             $redirector->gotoUrl($this->_getAuthSubUrl());
         } elseif ($token) {
             $this->_client = $this->_getAuthSubHttpClient();
             $this->_sessionNs->sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($token, $this->_client);
             $this->_client->setAuthSubToken($this->_sessionNs->sessionToken);
         }
     } else {
         $this->_client = $this->_getAuthSubHttpClient();
         $this->_client->setAuthSubToken($this->_sessionNs->sessionToken);
     }
 }
Ejemplo n.º 18
0
<?php

try {
    $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);
} catch (Zend_Gdata_App_Exception $e) {
    print 'ERROR - Token upgrade for ' . $singleUseToken . ' failed : ' . $e->getMessage();
    return;
}
$_SESSION['sessionToken'] = $sessionToken;
header('Location: ' . $_SESSION['homeUrl']);
Ejemplo n.º 19
0
$D = DIRECTORY_SEPARATOR;
set_include_path(dirname(__FILE__) . "{$D}..{$D}..{$D}..{$D}library" . PATH_SEPARATOR . get_include_path());
require_once 'Zend.php';
require_once 'Zend/Gdata/Base.php';
require_once 'Zend/Gdata/AuthSub.php';
/**
 * Google Base location
 */
$uri = Zend_Gdata_Base::BASE_FEED_URI;
session_start();
if (!isset($_SESSION['base_token'])) {
    if (isset($_GET['token'])) {
        /**
         * Convert the single-use token to a session token.
         */
        $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
        $_SESSION['base_token'] = $session_token;
    } else {
        /**
         * Display a link to generate a single-use token.
         */
        $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], $uri, 0, 1);
        echo "Click <a href='{$googleUri}'>here</a> to authorize this application.";
        exit;
    }
}
/**
 * Create an authenticated HTTP Client to talk to Google.
 */
$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['base_token']);
/**
Ejemplo n.º 20
0
/**
 * Exchanges the given single-use token for a session
 * token using AuthSubSessionToken, and returns the result.
 * @param string $token The single-use token from AuthSubRequest
 * @return string The upgraded (session) token
 */
function exchangeToken($token)
{
    return Zend_Gdata_AuthSub::getAuthSubSessionToken($token);
}
Ejemplo n.º 21
0
 public function action_import()
 {
     $this->template->content = "Muahhaa";
     $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full';
     if (!isset($_SESSION['cal_token'])) {
         if (isset($_GET['token'])) {
             // You can convert the single-use token to a session token.
             $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
             // Store the session token in our session.
             $_SESSION['cal_token'] = $session_token;
         } else {
             // Display link to generate single-use token
             $url = url::site('admin/import', TRUE);
             $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri($url, $my_calendar, 0, 1);
             $this->template->content = "Click <a href='{$googleUri}'>here</a> to authorize this application.";
             return;
         }
     }
     // Create an authenticated HTTP Client to talk to Google.
     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']);
     // Create a Gdata object using the authenticated Http Client
     $this->cal = new Zend_Gdata_Calendar($client);
     $this->template->content = "";
     if (isset($_POST['selectedCalendar'])) {
         $_SESSION['selectedCal'] = $_POST['selectedCalendar'];
     }
     $this->_fetchCalendarCache();
     $this->importSelectCal();
     if ($_SESSION['selectedCal']) {
         $this->_fetchEventsCache($_SESSION['selectedCal']);
         $this->template->content .= View::factory('admin/import_calEvents', array('events' => $_SESSION['eventsCache'][$_SESSION['selectedCal']], 'existingRooms' => ORM::factory('room')->find_all()->as_array()));
     }
 }
Ejemplo n.º 22
0
 /**
  * displayEditPicasaSubmit
  * 
  * @return void
  */
 function displayEditPicasaSubmit()
 {
     $singleUseToken = $_GET['token'];
     // Exchange single use token for a session token
     try {
         $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);
     } catch (Zend_Gdata_App_Exception $e) {
         $this->displayHeader();
         echo '<div class="error-alert">ERROR - Token upgrade for [' . $singleUseToken . '] failed: ' . $e->getMessage();
         $this->displayFooter();
         return;
     }
     $sql = "UPDATE `fcms_user_settings`\n                SET `picasa_session_token` = ?\n                WHERE `user` = ?";
     $params = array($sessionToken, $this->fcmsUser->id);
     if (!$this->fcmsDatabase->update($sql, $params)) {
         $this->displayHeader();
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     header("Location: settings.php?view=picasa");
 }