Source for file people.php

Documentation is available at people.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Google
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Google+ data class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Google
  17.  * @since       1234
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   JRegistry    $options  Google options object
  24.      * @param   JGoogleAuth  $auth     Google data http client object
  25.      *
  26.      * @since   1234
  27.      */
  28.     public function __construct(JRegistry $options nullJGoogleAuth $auth null)
  29.     {
  30.         parent::__construct($options$auth);
  31.  
  32.         if (isset($this->auth&& !$this->auth->getOption('scope'))
  33.         {
  34.             $this->auth->setOption('scope''https://www.googleapis.com/auth/plus.me');
  35.         }
  36.     }
  37.  
  38.     /**
  39.      * Get a person's profile.
  40.      *
  41.      * @param   string  $id      The ID of the person to get the profile for. The special value "me" can be used to indicate the authenticated user.
  42.      * @param   string  $fields  Used to specify the fields you want returned.
  43.      *
  44.      * @return  mixed  Data from Google
  45.      *
  46.      * @since   1234
  47.      */
  48.     public function getPeople($id$fields null)
  49.     {
  50.         if ($this->isAuthenticated())
  51.         {
  52.             $url $this->getOption('api.url''people/' $id;
  53.  
  54.             // Check if fields is specified.
  55.             if ($fields)
  56.             {
  57.                 $url .= '?fields=' $fields;
  58.             }
  59.  
  60.             $jdata $this->auth->query($url);
  61.  
  62.             return json_decode($jdata->bodytrue);
  63.         }
  64.         else
  65.         {
  66.             return false;
  67.         }
  68.     }
  69.  
  70.     /**
  71.      * Search all public profiles.
  72.      *
  73.      * @param   string   $query     Specify a query string for full text search of public text in all profiles.
  74.      * @param   string   $fields    Used to specify the fields you want returned.
  75.      * @param   string   $language  Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
  76.      * @param   integer  $max       The maximum number of people to include in the response, used for paging.
  77.      * @param   string   $token     The continuation token, used to page through large result sets. To get the next page of results, set this
  78.      *                                  parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
  79.      *
  80.      * @return  mixed  Data from Google
  81.      *
  82.      * @since   1234
  83.      */
  84.     public function search($query$fields null$language null$max 10$token null)
  85.     {
  86.         if ($this->isAuthenticated())
  87.         {
  88.             $url $this->getOption('api.url''people?query=' urlencode($query);
  89.  
  90.             // Check if fields is specified.
  91.             if ($fields)
  92.             {
  93.                 $url .= '&fields=' $fields;
  94.             }
  95.  
  96.             // Check if language is specified.
  97.             if ($language)
  98.             {
  99.                 $url .= '&language=' $language;
  100.             }
  101.  
  102.             // Check if max is specified.
  103.             if ($max != 10)
  104.             {
  105.                 $url .= '&maxResults=' $max;
  106.             }
  107.  
  108.             // Check of token is specified.
  109.             if ($token)
  110.             {
  111.                 $url .= '&pageToken=' $token;
  112.             }
  113.  
  114.             $jdata $this->auth->query($url);
  115.  
  116.             return json_decode($jdata->bodytrue);
  117.         }
  118.         else
  119.         {
  120.             return false;
  121.         }
  122.     }
  123.  
  124.     /**
  125.      * List all of the people in the specified collection for a particular activity.
  126.      *
  127.      * @param   string   $activityId  The ID of the activity to get the list of people for.
  128.      * @param   string   $collection  The collection of people to list. Acceptable values are "plusoners" and "resharers".
  129.      * @param   string   $fields      Used to specify the fields you want returned.
  130.      * @param   integer  $max         The maximum number of people to include in the response, used for paging.
  131.      * @param   string   $token       The continuation token, used to page through large result sets. To get the next page of results, set this
  132.      *                                    parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
  133.      *
  134.      * @return  mixed  Data from Google
  135.      *
  136.      * @since   1234
  137.      */
  138.     public function listByActivity($activityId$collection$fields null$max 10$token null)
  139.     {
  140.         if ($this->isAuthenticated())
  141.         {
  142.             $url $this->getOption('api.url''activities/' $activityId '/people/' $collection;
  143.  
  144.             // Check if fields is specified.
  145.             if ($fields)
  146.             {
  147.                 $url .= '?fields=' $fields;
  148.             }
  149.  
  150.             // Check if max is specified.
  151.             if ($max != 10)
  152.             {
  153.                 $url .= (strpos($url'?'=== false'?maxResults=' '&maxResults=';
  154.                 $url .= $max;
  155.             }
  156.  
  157.             // Check of token is specified.
  158.             if ($token)
  159.             {
  160.                 $url .= (strpos($url'?'=== false'?pageToken=' '&pageToken=';
  161.                 $url .= $token;
  162.             }
  163.  
  164.             $jdata $this->auth->query($url);
  165.  
  166.             return json_decode($jdata->bodytrue);
  167.         }
  168.         else
  169.         {
  170.             return false;
  171.         }
  172.     }
  173. }

Documentation generated on Tue, 19 Nov 2013 15:10:30 +0100 by phpDocumentor 1.4.3