Author: ggrekhov
Date: Fri May 18 04:13:44 2012
New Revision: 1339968
URL: http://svn.apache.org/viewvc?rev=1339968&view=rev
Log:
TeamBox plugin
Added:
incubator/openmeetings/trunk/plugins/teambox/
incubator/openmeetings/trunk/plugins/teambox/OAuth2/
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Client.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/
incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/Session.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Exception.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/HttpClient.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/Configuration.php
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Token.php
incubator/openmeetings/trunk/plugins/teambox/Readme.txt (with props)
incubator/openmeetings/trunk/plugins/teambox/config/
incubator/openmeetings/trunk/plugins/teambox/config/.htaccess (with props)
incubator/openmeetings/trunk/plugins/teambox/config/settings.ini
incubator/openmeetings/trunk/plugins/teambox/css/
incubator/openmeetings/trunk/plugins/teambox/css/index.css (with props)
incubator/openmeetings/trunk/plugins/teambox/index.php
incubator/openmeetings/trunk/plugins/teambox/oauthLogin.php
incubator/openmeetings/trunk/plugins/teambox/openmeetings.js (with props)
incubator/openmeetings/trunk/plugins/teambox/rest_lib/
incubator/openmeetings/trunk/plugins/teambox/rest_lib/OpenMeetingsRestService.php
incubator/openmeetings/trunk/plugins/teambox/rest_lib/RestService.php
incubator/openmeetings/trunk/plugins/teambox/rest_lib/TeamBoxRestService.php
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/Client.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/Client.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/Client.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/Client.php Fri May 18
04:13:44 2012
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+class Client
+{
+ /**
+ * @var string
+ */
+ private $_clientKey;
+
+ /**
+ * @var string
+ */
+ private $_clientSecret;
+
+ /**
+ * @var string
+ */
+ private $_callbackUrl;
+
+ /**
+ *
+ * @param string $clientKey
+ * @param string $clientSecret
+ * @param string $callbackUrl
+ */
+ public function __construct($clientKey, $clientSecret, $callbackUrl) {
+ $this->_clientKey = $clientKey;
+ $this->_clientSecret = $clientSecret;
+ $this->_callbackUrl = $callbackUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getClientKey() {
+ return $this->_clientKey;
+ }
+
+ /**
+ * @return string
+ */
+ public function getClientSecret() {
+ return $this->_clientSecret;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCallbackUrl() {
+ return $this->_callbackUrl;
+ }
+}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore.php Fri May
18 04:13:44 2012
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+interface DataStore
+{
+ /**
+ * @param \OAuth2\Token $token
+ */
+ function storeAccessToken(Token $token);
+
+ /**
+ * @return \OAuth2\Token
+ */
+ function retrieveAccessToken();
+}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/Session.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/Session.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/Session.php
(added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/DataStore/Session.php
Fri May 18 04:13:44 2012
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2\DataStore;
+
+use OAuth2\DataStore;
+use OAuth2\Token;
+
+class Session implements DataStore
+{
+ public function __construct() {
+ session_start();
+ }
+
+ /**
+ *
+ * @return \OAuth2\Token
+ */
+ public function retrieveAccessToken() {
+ return isset($_SESSION['oauth2_token']) ? $_SESSION['oauth2_token'] :
new Token();
+ }
+
+ /**
+ * @param \OAuth2\Token $token
+ */
+ public function storeAccessToken(Token $token) {
+ $_SESSION['oauth2_token'] = $token;
+ }
+
+ public function __destruct() {
+ session_write_close();
+ }
+}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/Exception.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/Exception.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/Exception.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/Exception.php Fri May
18 04:13:44 2012
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+class Exception extends \Exception {}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/HttpClient.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/HttpClient.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/HttpClient.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/HttpClient.php Fri May
18 04:13:44 2012
@@ -0,0 +1,180 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+class HttpClient
+{
+ /**
+ * @var string
+ */
+ private $_url;
+
+ /**
+ * @var string
+ */
+ private $_method;
+
+ /**
+ * @var string
+ */
+ private $_parameters;
+
+ /**
+ * @var array
+ */
+ private $_requestHeader;
+
+ /**
+ * @var string
+ */
+ private $_response;
+
+ /**
+ * @var array
+ */
+ private $_headers;
+
+ /**
+ * @var array
+ */
+ private $_info;
+
+ /**
+ * @var boolean
+ */
+ private $_debug = false;
+
+ /**
+ * @param string $url
+ * @param string $method
+ * @param string $parameters
+ * @param array $header any additional header which should be set
+ */
+ public function __construct($url, $method, $parameters = null, array
$header = array()) {
+ $this->_url = $url;
+ $this->_method = $method;
+ $this->_parameters = $parameters;
+ $this->_requestHeader = $header;
+ }
+
+ /**
+ * parses a string with two delimiters to an array
+ *
+ * example:
+ *
+ * param1=value1¶m2=value2
+ *
+ * will result with delimiters & and = to
+ *
+ * array(
+ * 'param1' => 'value1',
+ * 'param2' => 'value2',
+ * )
+ *
+ * @param string $string
+ * @param string $firstDelimiter
+ * @param string $secondDelimiter
+ * @return array
+ */
+ public static function parseStringToArray($string, $firstDelimiter,
$secondDelimiter) {
+ $resultArray = array();
+ $parts = explode($firstDelimiter, $string);
+ foreach ($parts as $part) {
+ $partsPart = explode($secondDelimiter, $part);
+ $resultArray[$partsPart[0]] = isset($partsPart[1]) ?
trim($partsPart[1]) : '';
+ }
+ return $resultArray;
+ }
+
+ /**
+ * executes the curl request
+ */
+ public function execute() {
+ $ch = curl_init();
+
+ if ($this->_method === 'POST') {
+ curl_setopt($ch, CURLOPT_URL, $this->_url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_parameters);
+ } else {
+ curl_setopt($ch, CURLOPT_URL, $this->_url . ($this->_parameters ?
'?' . $this->_parameters : ''));
+ }
+
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+ if (! empty($this->_requestHeader)) {
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_requestHeader);
+ }
+
+ $fullResponse = curl_exec($ch);
+ $this->_info = curl_getinfo($ch);
+
+ $this->_response = substr($fullResponse, $this->_info['header_size'],
strlen($fullResponse));
+ if ($this->_response === false) {
+ $this->_response = '';
+ }
+ $headers = rtrim(substr($fullResponse, 0,
$this->_info['header_size']));
+
+ $this->_headers = static::parseStringToArray($headers, PHP_EOL, ':');
+
+ if ($this->_debug) {
+ echo "<pre>";
+ print_r($this->_url);
+ echo PHP_EOL;
+ print_r($this->_headers);
+ echo PHP_EOL;
+ print_r($this->_response);
+ echo "</pre>";
+ }
+
+ curl_close($ch);
+ }
+
+ /**
+ * @return string
+ */
+ public function getResponse() {
+ return $this->_response;
+ }
+
+ /**
+ * @return array
+ */
+ public function getHeaders() {
+ return $this->_headers;
+ }
+
+ /**
+ * @param boolean $debug
+ */
+ public function setDebug($debug) {
+ $this->_debug = $debug;
+ }
+}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service.php Fri May 18
04:13:44 2012
@@ -0,0 +1,257 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+class Service
+{
+ /**
+ * @var \OAuth2\Client
+ */
+ private $_client;
+
+ /**
+ * @var \OAuth2\Service\Configuration
+ */
+ private $_configuration;
+
+ /**
+ * @var \OAuth2\DataStore
+ */
+ private $_dataStore;
+
+ /**
+ * @var string
+ */
+ private $_scope;
+
+ /**
+ * @param \OAuth2\Client $client
+ * @param \OAuth2\Service\Configuration $configuration
+ * @param \OAuth2\DataStore $dataStore
+ * @param string $scope optional
+ */
+ public function __construct(Client $client,
+ Service\Configuration $configuration,
+ DataStore $dataStore,
+ $scope = null) {
+ $this->_client = $client;
+ $this->_configuration = $configuration;
+ $this->_dataStore = $dataStore;
+ $this->_scope = $scope;
+ }
+
+ /**
+ * redirect to authorize endpoint of service
+ */
+ public function authorize() {
+ $parameters = array(
+ 'type' => 'web_server',
+ 'client_id' => $this->_client->getClientKey(),
+ 'redirect_uri' => $this->_client->getCallbackUrl(),
+ 'response_type' => 'code',
+ );
+ if ($this->_scope) {
+ $parameters['scope'] = $this->_scope;
+ }
+
+ $url = $this->_configuration->getAuthorizeEndpoint();
+ $url .= (strpos($url, '?') !== false ? '&' : '?') .
http_build_query($parameters);
+
+ header('Location: ' . $url);
+ die();
+ }
+
+ /**
+ * get access token of from service, has to be called after successful
authorization
+ *
+ * @param string $code optional, if no code given method tries to get it
out of $_GET
+ */
+ public function getAccessToken($code = null) {
+ if (! $code) {
+ if (! isset($_GET['code'])) {
+ throw new Exception('could not retrieve code out of callback
request and no code given');
+ }
+ $code = $_GET['code'];
+ }
+
+ $parameters = array(
+ 'grant_type' => 'authorization_code',
+ 'type' => 'web_server',
+ 'client_id' => $this->_client->getClientKey(),
+ 'client_secret' => $this->_client->getClientSecret(),
+ 'redirect_uri' => $this->_client->getCallbackUrl(),
+ 'code' => $code,
+ );
+
+ if ($this->_scope) {
+ $parameters['scope'] = $this->_scope;
+ }
+
+ $http = new
HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST',
http_build_query($parameters));
+ //$http->setDebug(true);
+ $http->execute();
+
+ $this->_parseAccessTokenResponse($http);
+ }
+
+ /**
+ * refresh access token
+ *
+ * @param \OAuth2\Token $token
+ * @return \OAuth2\Token new token object
+ */
+ public function refreshAccessToken(Token $token) {
+ if (! $token->getRefreshToken()) {
+ throw new Exception('could not refresh access token, no refresh
token available');
+ }
+
+ $parameters = array(
+ 'grant_type' => 'refresh_token',
+ 'type' => 'web_server',
+ 'client_id' => $this->_client->getClientKey(),
+ 'client_secret' => $this->_client->getClientSecret(),
+ 'refresh_token' => $token->getRefreshToken(),
+ );
+
+ $http = new
HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST',
http_build_query($parameters));
+ $http->execute();
+
+ return $this->_parseAccessTokenResponse($http,
$token->getRefreshToken());
+ }
+
+ /**
+ * parse the response of an access token request and store it in dataStore
+ *
+ * @param \OAuth2\HttpClient $http
+ * @param string $oldRefreshToken
+ * @return \OAuth2\Token
+ */
+ private function _parseAccessTokenResponse(HttpClient $http,
$oldRefreshToken = null) {
+ $headers = $http->getHeaders();
+ $type = 'text';
+ if (isset($headers['Content-Type']) &&
strpos($headers['Content-Type'], 'application/json') !== false) {
+ $type = 'json';
+ }
+
+ switch ($type) {
+ case 'json':
+ $response = json_decode($http->getResponse(), true);
+ break;
+ case 'text':
+ default:
+ $response =
HttpClient::parseStringToArray($http->getResponse(), '&', '=');
+ break;
+ }
+
+ if (isset($response['error'])) {
+ throw new Exception('got error while requesting access token: ' .
$response['error']);
+ }
+ if (! isset($response['access_token'])) {
+ throw new Exception('no access_token found');
+ }
+
+ $token = new Token($response['access_token'],
+ isset($response['refresh_token']) ? $response['refresh_token']
: $oldRefreshToken,
+ isset($response['expires_in']) ? $response['expires_in'] :
null);
+
+ unset($response['access_token']);
+ unset($response['refresh_token']);
+ unset($response['expires_in']);
+
+ // add additional parameters which may be returned depending on
service and scope
+ foreach ($response as $key => $value) {
+ $token->{'set' . $key}($value);
+ }
+
+ $this->_dataStore->storeAccessToken($token);
+
+ return $token;
+ }
+
+ /**
+ * call an api endpoint. automatically adds needed authorization headers
with access token or parameters
+ *
+ * @param string $endpoint
+ * @param string $method default 'GET'
+ * @param array $uriParameters optional
+ * @param mixed $postBody optional, can be string or array
+ * @param array $additionalHeaders
+ * @return string
+ */
+ public function callApiEndpoint($endpoint, $method = 'GET', array
$uriParameters = array(), $postBody = null, array $additionalHeaders = array())
{
+ $token = $this->_dataStore->retrieveAccessToken();
+
+ //check if token is invalid
+ if ($token->getLifeTime() && $token->getLifeTime() < time()) {
+ $token = $this->refreshAccessToken($token);
+ }
+
+ $parameters = null;
+
+ $authorizationMethod = $this->_configuration->getAuthorizationMethod();
+
+ switch ($authorizationMethod) {
+ case Service\Configuration::AUTHORIZATION_METHOD_HEADER:
+ $additionalHeaders = array_merge(array('Authorization: OAuth '
. $token->getAccessToken()), $additionalHeaders);
+ break;
+ case Service\Configuration::AUTHORIZATION_METHOD_ALTERNATIVE:
+ if ($method !== 'GET') {
+ if (is_array($postBody)) {
+ $postBody['oauth_token'] = $token->getAccessToken();
+ } else {
+ $postBody .= '&oauth_token=' .
urlencode($token->getAccessToken());
+ }
+ } else {
+ $uriParameters['oauth_token'] = $token->getAccessToken();
+ }
+ break;
+ default:
+ throw new Exception("Invalid authorization method specified");
+ break;
+ }
+
+ if ($method !== 'GET') {
+ if (is_array($postBody)) {
+ $parameters = http_build_query($postBody);
+ } else {
+ $parameters = $postBody;
+ }
+ }
+
+ if (! empty($uriParameters)) {
+ $endpoint .= (strpos($endpoint, '?') !== false ? '&' : '?') .
http_build_query($uriParameters);
+ }
+
+
+ $http = new HttpClient($endpoint, $method, $parameters,
$additionalHeaders);
+ $http->execute();
+
+ return $http->getResponse();
+ }
+}
Added:
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/Configuration.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/Configuration.php?rev=1339968&view=auto
==============================================================================
---
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/Configuration.php
(added)
+++
incubator/openmeetings/trunk/plugins/teambox/OAuth2/Service/Configuration.php
Fri May 18 04:13:44 2012
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2\Service;
+
+class Configuration
+{
+ const AUTHORIZATION_METHOD_HEADER = 1;
+ const AUTHORIZATION_METHOD_ALTERNATIVE = 2;
+
+ /**
+ * @var string
+ */
+ private $_authorizeEndpoint;
+
+ /**
+ * @var string
+ */
+ private $_accessTokenEndpoint;
+
+ /**
+ * @var string
+ */
+ private $_authorizationMethod = self::AUTHORIZATION_METHOD_HEADER;
+
+ /**
+ * @param string $authorizeEndpoint
+ * @param string $accessTokenEndpoint
+ */
+ public function __construct($authorizeEndpoint, $accessTokenEndpoint) {
+ $this->_authorizeEndpoint = $authorizeEndpoint;
+ $this->_accessTokenEndpoint = $accessTokenEndpoint;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAuthorizeEndpoint() {
+ return $this->_authorizeEndpoint;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccessTokenEndpoint() {
+ return $this->_accessTokenEndpoint;
+ }
+
+ /**
+ * @return string
+ */
+ public function setAuthorizationMethod($authorizationMethod) {
+ $this->_authorizationMethod = $authorizationMethod;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAuthorizationMethod() {
+ return $this->_authorizationMethod;
+ }
+
+}
Added: incubator/openmeetings/trunk/plugins/teambox/OAuth2/Token.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/OAuth2/Token.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/OAuth2/Token.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/OAuth2/Token.php Fri May 18
04:13:44 2012
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Copyright (c) 2010 VZnet Netzwerke Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Bastian Hofmann <[email protected]>
+ * @author Vyacheslav Slinko <[email protected]>
+ * @copyright 2010 VZnet Netzwerke Ltd.
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth2;
+
+class Token
+{
+ /**
+ * @var string
+ */
+ private $_accessToken;
+
+ /**
+ * @var string
+ */
+ private $_refreshToken;
+
+ /**
+ * @var string
+ */
+ private $_lifeTime;
+
+ /**
+ * @var array
+ */
+ private $_additionalParams = array();
+ /**
+ *
+ * @param string $accessToken
+ * @param string $refreshToken
+ * @param int $lifeTime
+ */
+ public function __construct($accessToken = null, $refreshToken = null,
$lifeTime = null) {
+ $this->_accessToken = $accessToken;
+ $this->_refreshToken = $refreshToken;
+ if ($lifeTime) {
+ $this->_lifeTime = ((int)$lifeTime) + time();
+ }
+ }
+
+ /**
+ * magic method for setting and getting additional parameters returned from
+ * service
+ *
+ * e.g. user_id parameter with scope openid
+ *
+ * @param string $name
+ * @param array $arguments
+ * @return mixed
+ */
+ public function __call($name, $arguments) {
+ if (strlen($name) < 4) {
+ throw new Exception('undefined magic method called');
+ }
+ $method = substr($name, 0, 3);
+ $param = substr($name, 3);
+ switch ($method) {
+ case 'get':
+ if (! isset($this->_additionalParams[$param])) {
+ throw new Exception($param . ' was not returned by
service');
+ }
+ return $this->_additionalParams[$param];
+ case 'set':
+ if (! array_key_exists(0, $arguments)) {
+ throw new Exception('magic setter has no argument');
+ }
+ $this->_additionalParams[$param] = $arguments[0];
+ break;
+ default:
+ throw new Exception('undefined magic method called');
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccessToken() {
+ return $this->_accessToken;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRefreshToken() {
+ return $this->_refreshToken;
+ }
+
+ /**
+ * @return int
+ */
+ public function getLifeTime() {
+ return $this->_lifeTime;
+ }
+}
Added: incubator/openmeetings/trunk/plugins/teambox/Readme.txt
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/Readme.txt?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/Readme.txt (added)
+++ incubator/openmeetings/trunk/plugins/teambox/Readme.txt Fri May 18 04:13:44
2012
@@ -0,0 +1,12 @@
+If you want to set up the TeamBox plugin then you need:
+1) Register you application at TeamBox site here:
+ https://teambox.com/oauth_clients/
+2) Edit the file ./config/settings.ini. Here you need to:
+ _ choose a protocol (https or http);
+ _ set up TeamBox acceess (app key and secret from the first step);
+ _ set up OpenMeetings reas api acceess;
+ _ set up OpenMeetings mysql access.
+3) Edit the file openmeetings.js:
+ replace the string "protocol://host/teambox/index.php?action=authorize"
with you protocol and host
+4) Visit the TeamBox site enter javascript console if you browser there and
enter the string:
+ Teambox.models.user.saveSetting('custom_apps',
["protocol://host/teambox_js/openmeetings.js"]);
Propchange: incubator/openmeetings/trunk/plugins/teambox/Readme.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openmeetings/trunk/plugins/teambox/config/.htaccess
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/config/.htaccess?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/config/.htaccess (added)
+++ incubator/openmeetings/trunk/plugins/teambox/config/.htaccess Fri May 18
04:13:44 2012
@@ -0,0 +1,2 @@
+Order Deny,Allow
+Deny from all
Propchange: incubator/openmeetings/trunk/plugins/teambox/config/.htaccess
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openmeetings/trunk/plugins/teambox/config/settings.ini
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/config/settings.ini?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/config/settings.ini (added)
+++ incubator/openmeetings/trunk/plugins/teambox/config/settings.ini Fri May 18
04:13:44 2012
@@ -0,0 +1,27 @@
+; Set up "host" where OpenMeetings is installed.
+; Choose http or https
+; Set up TeamBox, OpenMeetings and mysql access
+
+[OpenMeetings protocol]
+https = false;
+
+[TeamBox access]
+app_key = "";
+app_secret = "";
+callback_url_http = "http://host/teambox/index.php";
+callback_url_https = "https://host/teambox/index.php";
+authorize_end = "https://teambox.com/oauth/authorize";
+token_end = "https://teambox.com/oauth/token";
+teambox_api_url = "https://teambox.com/api/2/";
+
+[OpenMeetings access]
+cookie_domain = "host";
+om_api_url = "http://host/openmeetings/services/";
+om_hash_url = "http://host/openmeetings/?secureHash=";
+admin_login = "";
+admin_password = "";
+
+[OpenMeetings mysql access]
+mysql_login = "";
+mysql_password = "";
+mysql_databse = "teambox";
Added: incubator/openmeetings/trunk/plugins/teambox/css/index.css
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/css/index.css?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/css/index.css (added)
+++ incubator/openmeetings/trunk/plugins/teambox/css/index.css Fri May 18
04:13:44 2012
@@ -0,0 +1,6 @@
+.button-primary {
+ width: 200px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
Propchange: incubator/openmeetings/trunk/plugins/teambox/css/index.css
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openmeetings/trunk/plugins/teambox/index.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/index.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/index.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/index.php Fri May 18 04:13:44
2012
@@ -0,0 +1,51 @@
+<?php
+
+global $CFG;
+$CFG = parse_ini_file('config/settings.ini');
+
+require_once('rest_lib/TeamBoxRestService.php');
+require_once('rest_lib/OpenMeetingsRestService.php');
+require_once('oauthLogin.php');
+
+$token = getTeamBoxAccessToken();
+
+$tbService = new TeamBoxRestService($token);
+$account = $tbService->getAccountInfo();
+$projects = $tbService->getUserProjects();
+
+$omService = new OpenMeetingsRestService();
+$logged = $omService->loginAdmin();
+if (!$logged) {
+ print 'OpenMeetings internal error. Ask your system administrator.';
+ exit(0);
+}
+
+$invitationsMap = $omService->getInvitationsMap($projects, $account);
+
+?>
+
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<link rel="stylesheet" type="text/css"
href="https://d238xsvyykqg39.cloudfront.net/assets/public-9083c95676119d2654a02c3057084689.css"
media="screen" />
+<link rel="stylesheet" type="text/css" href="css/index.css" media="screen" />
+
+<div style="text-align: center;">
+<?php
+
+if (0 == count($invitationsMap)) {
+ echo '<p>You do not participate in any project, so you can not enter any
project conference room</p>';
+} else {
+ echo '<p>Please, choose the project which conference room you want to
enter:</p>';
+ foreach ($invitationsMap as $project => $url) {
+ echo '<p><a class="button button-primary"
href="'.$url.'"><span>'.$project.'</span></a></p>';
+ }
+}
+
+?>
+</div>
+
+</body>
+</html>
Added: incubator/openmeetings/trunk/plugins/teambox/oauthLogin.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/oauthLogin.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/oauthLogin.php (added)
+++ incubator/openmeetings/trunk/plugins/teambox/oauthLogin.php Fri May 18
04:13:44 2012
@@ -0,0 +1,69 @@
+<?php
+
+require_once('rest_lib/TeamBoxRestService.php');
+
+function validateAccessToken($token) {
+ $tbService = new TeamBoxRestService($token);
+ return $tbService->isValidAccessToken();
+}
+
+function getTeamBoxAccessToken() {
+ global $CFG;
+ $appKey = $CFG[app_key];
+ $appSecret = $CFG[app_secret];
+ if ($CFG[https]) {
+ $callbackUrl = $CFG[callback_url_https];
+ } else {
+ $callbackUrl = $CFG[callback_url_http];
+ }
+ $authorizeEnd = $CFG[authorize_end];
+ $tokenEnd = $CFG[token_end];
+ $cookieDomain = $CFG[cookie_domain];
+ $tokenCookieId = 'access_token';
+
+ spl_autoload_register(function ($class) {
+ require str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
+ });
+
+ $client = new OAuth2\Client($appKey, $appSecret, $callbackUrl);
+ $configuration = new OAuth2\Service\Configuration($authorizeEnd,
$tokenEnd);
+ $dataStore = new OAuth2\DataStore\Session();
+ $scope = 'read_projects';
+
+ $service = new OAuth2\Service($client, $configuration, $dataStore, $scope);
+
+ if (isset($_GET['action'])) {
+ if ('authorize' == $_GET['action']) {
+ if (isset($_COOKIE[$tokenCookieId])) {
+ $tokenString = $_COOKIE[$tokenCookieId];
+ $valid = validateAccessToken($tokenString);
+ if ($valid) {
+ return $tokenString;
+ }
+ }
+
+ // redirects to authorize endpoint
+ $service->authorize();
+ } else {
+ exit(0);
+ }
+ }
+
+ if (isset($_GET['code'])) {
+ // retrieve access token from endpoint
+ $service->getAccessToken();
+ $token = $dataStore->retrieveAccessToken();
+ $dataStore->storeAccessToken($token);
+ }
+
+ $token = $dataStore->retrieveAccessToken();
+ if ($CFG[https]) {
+ setcookie($tokenCookieId, $token->getAccessToken(),
$token->getLifeTime(), '/teambox/', $cookieDomain, true);
+ } else {
+ setcookie($tokenCookieId, $token->getAccessToken(),
$token->getLifeTime());
+ }
+
+ return $token->getAccessToken();
+}
+
+?>
Added: incubator/openmeetings/trunk/plugins/teambox/openmeetings.js
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/openmeetings.js?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/openmeetings.js (added)
+++ incubator/openmeetings/trunk/plugins/teambox/openmeetings.js Fri May 18
04:13:44 2012
@@ -0,0 +1,36 @@
+(function () {
+ // Initialize a basic Teambox app
+ Teambox.Apps.Openmeetings = Teambox.BaseApp.extend({});
+
+ // Router to handle paths (in this case, /#!/openmeetings) with regular
links
+ Teambox.Apps.Openmeetings.Controller =
Teambox.Controllers.BaseController.extend({
+ routes: { '!/openmeetings' : 'index' },
+ index: function () {
+ // Helper Teambox function to highlight the sidebar
+ Teambox.Views.Sidebar.highlightSidebar('openmeetings_link');
+
+ // Helper Teambox function to render content to the main area
+ Teambox.helpers.views.renderContent(
+ "<iframe
src='protocol://host/teambox/index.php?action=authorize'
style='width:100%;height:100%'></iframe>",
+ "Openmeetings",
+ "openmeetings_content",
+ false,
+ true
+ );
+ }
+ });
+
+ // Init app. Will be executed once on pageload when apps are instantiated.
+ Teambox.Apps.Openmeetings = Teambox.Apps.Openmeetings.extend({
+ initialize: function () {
+ // Instantiate the controller
+ this.controller = new Teambox.Apps.Openmeetings.Controller();
+ // Add an element to the Apps section in the sidebar
+ $(".more_section .separator")
+ .after("<div class='el' id='openmeetings_link'>"+
+ "<a href='#!/openmeetings'><span class='icon
star'></span>Openmeetings</a>"+
+ "</div>");
+ }
+ });
+
+}());
Propchange: incubator/openmeetings/trunk/plugins/teambox/openmeetings.js
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/openmeetings/trunk/plugins/teambox/rest_lib/OpenMeetingsRestService.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/rest_lib/OpenMeetingsRestService.php?rev=1339968&view=auto
==============================================================================
---
incubator/openmeetings/trunk/plugins/teambox/rest_lib/OpenMeetingsRestService.php
(added)
+++
incubator/openmeetings/trunk/plugins/teambox/rest_lib/OpenMeetingsRestService.php
Fri May 18 04:13:44 2012
@@ -0,0 +1,139 @@
+<?php
+
+require_once('RestService.php');
+
+class OpenMeetingsRestService extends RestService {
+
+ private $mysqlLogin;
+ private $mysqlPassword;
+ private $mysqlDatabse;
+
+ private $adminLogin;
+ private $adminPassword;
+
+ private $restApiUrl;
+ private $omHashUrl;
+
+ private $sessionId;
+
+ public function OpenMeetingsRestService() {
+ parent::RestService('OpenMeetings');
+
+ global $CFG;
+ $this->restApiUrl = $CFG[om_api_url];
+ $this->omHashUrl = $CFG[om_hash_url];
+ $this->adminLogin = $CFG[admin_login];
+ $this->adminPassword = $CFG[admin_password];
+
+ $this->mysqlLogin = $CFG[mysql_login];
+ $this->mysqlPassword = $CFG[mysql_password];
+ $this->mysqlDatabse = $CFG[mysql_databse];
+ }
+
+ public function loginAdmin() {
+ $request = $this->restApiUrl . 'UserService/getSession';
+ $response = $this->call($request);
+ $xml = $this->getXmlContent($response);
+ $this->sessionId = $xml->children('ns',
true)->return->children('ax23', true)->session_id;
+
+ $request = $this->restApiUrl.'UserService/loginUser?'
+ .'SID='.$this->sessionId
+ .'&username=' . $this->adminLogin
+ .'&userpass=' . $this->adminPassword;
+ $response = $this->call($request);
+ $xml = $this->getXmlContent($response);
+ $returnValue = $xml->children('ns', true)->return[0];
+
+ return ($returnValue>0);
+ }
+
+ public function getInvitationsMap($projects, $account) {
+ $link = mysql_connect('localhost', $this->mysqlLogin,
$this->mysqlPassword);
+ if (!$link) {
+ die("Can't create a connection to the teambox databse");
+ }
+
+ $ret = array();
+
+ foreach ($projects as $proj) {
+ $projectId = $proj->id;
+ $query = 'select roomId from '.$this->mysqlDatabse.'.ProjectRooms
where projectId = '.$projectId;
+ $result = mysql_query($query);
+
+ $createRoom = true;
+ if ($row = mysql_fetch_assoc($result)) {
+ $roomId = $row['roomId'];
+ $createRoom = false;
+ }
+ mysql_free_result($result);
+
+ if ($createRoom) {
+ $roomId = $this->createRoom($proj->name);
+ if ($roomId < 0) {
+ die("Can't create a room: ".$proj->name);
+ }
+ $query = 'insert into '.$this->mysqlDatabse.'.ProjectRooms
values('.$projectId.', '.$roomId.')';
+ mysql_query($query);
+ }
+
+ $hash = $this->getRoomHash($roomId, $account);
+ if ($hash < 0) {
+ die("Can't create a secure hash: ".$proj->name);
+ }
+
+ $url = $this->omHashUrl.$hash;
+ $ret[$proj->name] = $url;
+ }
+
+ mysql_close($link);
+ return $ret;
+ }
+
+ public function createRoom($name) {
+ $request = $this->restApiUrl."RoomService/addRoomWithModeration?"
+ ."SID=".$this->sessionId
+ ."&name=".$name
+ ."&roomtypes_id=3"
+ ."&numberOfPartizipants=10"
+ ."&ispublic=false"
+ ."&isModeratedRoom=false";
+
+ $request = str_replace(' ', '_', $request);
+ $response = $this->call($request);
+ $xml = $this->getXmlContent($response);
+ $roomId = $xml->children('ns', true)->return[0];
+
+ return $roomId;
+ }
+
+ public function getRoomHash($roomId, $account) {
+ $request =
$this->restApiUrl."UserService/setUserObjectAndGenerateRoomHash?"
+ ."SID=".$this->sessionId
+ ."&username=".$account->last_name
+ ."&firstname=".$account->first_name
+ ."&lastname=".$account->last_name
+ ."&email=".$account->email
+ ."&room_id=".$roomId
+ ."&becomeModeratorAsInt=1"
+ ."&showAudioVideoTestAsInt=0";
+ $request = str_replace(' ', '_', $request);
+ $response = $this->call($request);
+ $xml = $this->getXmlContent($response);
+ $hash = $xml->children('ns', true)->return[0];
+
+ return $hash;
+ }
+
+ private function getXmlContent($response) {
+ if (!($xml = strstr($response, '<ns'))) {
+ $xml = null;
+ }
+
+ // Create a SimpleXML object with XML response
+ $simple_xml = simplexml_load_string($xml, "SimpleXMLElement",
0,"http://services.axis.openmeetings.org", true);
+
+ return $simple_xml;
+ }
+}
+
+?>
Added: incubator/openmeetings/trunk/plugins/teambox/rest_lib/RestService.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/rest_lib/RestService.php?rev=1339968&view=auto
==============================================================================
--- incubator/openmeetings/trunk/plugins/teambox/rest_lib/RestService.php
(added)
+++ incubator/openmeetings/trunk/plugins/teambox/rest_lib/RestService.php Fri
May 18 04:13:44 2012
@@ -0,0 +1,126 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+/*
+ * Created on 03.01.2012 by [email protected]
+*
+*
+*/
+
+class RestService {
+
+ protected $serviceName;
+
+ public function RestService($serviceName) {
+ $this->serviceName = $serviceName;
+ }
+
+ public function call($url, $parameters = null, $method = 'GET',
$dieOnError = true){
+ // This will allow you to view errors in the browser
+ // Note: set "display_errors" to 0 in production
+ //ini_set('display_errors',1);
+
+ // Report all PHP errors (notices, errors, warnings, etc.)
+ //error_reporting(E_ALL);
+
+ // URI used for making REST call. Each Web Service uses a unique URL.
+ //$request
+
+ // Initialize the session by passing the request as a parameter
+ $session = curl_init();
+
+ if ($method === 'POST') {
+ curl_setopt($session, CURLOPT_URL, $url);
+ curl_setopt($session, CURLOPT_POST, true);
+ curl_setopt($session, CURLOPT_POSTFIELDS, $parameters);
+ } else {
+ $request = $url . ($parameters ? '?' . $parameters : '');
+ curl_setopt($session, CURLOPT_URL, $request);
+ }
+
+ // Set curl options by passing session and flags
+ // CURLOPT_HEADER allows us to receive the HTTP header
+ curl_setopt($session, CURLOPT_HEADER, true);
+
+ // CURLOPT_RETURNTRANSFER will return the response
+ curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
+
+ // Make the request
+ $response = curl_exec($session);
+
+ // Close the curl session
+ curl_close($session);
+
+ // Confirm that the request was transmitted to the service! Image
Search Service
+ if(!$response) {
+ die("Request ".$this->serviceName."! ".$this->serviceName."
Service failed and no response was returned.");
+ }
+
+ // Create an array to store the HTTP response codes
+ $status_code = array();
+
+ // Use regular expressions to extract the code from the header
+ preg_match('/\d\d\d/', $response, $status_code);
+
+ // Check the HTTP Response code and display message if status code is
not 200 (OK)
+ switch( $status_code[0] ) {
+ case 200:
+ // Success
+ break;
+ case 503:
+ if ($dieOnError) {
+ die('Your call to '.$this->serviceName.' Web Services
failed and returned an HTTP status of 503.
+ That means: Service unavailable. An internal problem
prevented us from returning'.
+ ' data to you.');
+ } else {
+ return false;
+ }
+ break;
+ case 403:
+ if ($dieOnError) {
+ die('Your call to '.$this->serviceName.' Web Services
failed and returned an HTTP status of 403.
+ That means: Forbidden. You do not have permission to
access this resource, or are over'.
+ ' your rate limit.');
+ } else {
+ return false;
+ }
+ break;
+ case 400:
+ // You may want to fall through here and read the specific XML
error
+ if ($dieOnError) {
+ die('Your call to '.$this->serviceName.' Web Services
failed and returned an HTTP status of 400.
+ That means: Bad request. The parameters passed to the
service did not match as expected.
+ The exact error is returned in the XML response.');
+ } else {
+ return false;
+ }
+ break;
+ default:
+ if ($dieOnError) {
+ die('Your call to '.$this->serviceName.' Web Services
returned an unexpected HTTP status of: ' . $status_code[0]);
+ } else {
+ return false;
+ }
+ }
+
+ return $response;
+ }
+}
+
+?>
Added:
incubator/openmeetings/trunk/plugins/teambox/rest_lib/TeamBoxRestService.php
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/plugins/teambox/rest_lib/TeamBoxRestService.php?rev=1339968&view=auto
==============================================================================
---
incubator/openmeetings/trunk/plugins/teambox/rest_lib/TeamBoxRestService.php
(added)
+++
incubator/openmeetings/trunk/plugins/teambox/rest_lib/TeamBoxRestService.php
Fri May 18 04:13:44 2012
@@ -0,0 +1,90 @@
+<?php
+
+require_once('RestService.php');
+
+class TeamBoxRestService extends RestService {
+
+ private $restApiUrl;
+ private $accessToken;
+
+ public function TeamBoxRestService($accessToken) {
+ parent::RestService('TeamBox');
+
+ global $CFG;
+ $this->restApiUrl = $CFG[teambox_api_url];
+ $this->accessToken = $accessToken;
+ }
+
+ public function isValidAccessToken() {
+ $url = $this->restApiUrl . 'account';
+ $parameters = 'access_token=' . $this->accessToken;
+ $response = $this->call($url, $parameters, 'GET', false);
+ if (false == $response) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public function getAccountInfo() {
+ $url = $this->restApiUrl . 'account';
+ $parameters = 'access_token=' . $this->accessToken;
+ $response = $this->call($url, $parameters, 'GET');
+ $data = $this->getJsonSingleData($response);
+
+ return $data;
+ }
+
+ public function getUserProjects() {
+ $url = $this->restApiUrl . 'projects';
+ $parameters = 'access_token=' . $this->accessToken;
+ $response = $this->call($url, $parameters, 'GET');
+ $data = $this->getJsonMultiData($response);
+
+ return $data;
+ }
+
+ private function getJsonSingleData($response) {
+ if (!($content = strstr($response, '{'))) {
+ $content = null;
+ }
+
+ $data = json_decode($content);
+
+ return $data;
+ }
+
+ private function getJsonMultiData($response) {
+ $singlePos = stripos($response, '{');
+ $multiPos = stripos($response, '[');
+
+ $multy = false;
+ if (-1 != $multiPos) {
+ if (-1 != $singlePos) {
+ $multy = ($multiPos < $singlePos);
+ } else {
+ $multy = true;
+ }
+ }
+
+ if ($multy) {
+ $content = strstr($response, '[');
+ } else {
+ $content = strstr($response, '{');
+ }
+
+ if (!$content) {
+ return null;
+ }
+
+ $data = json_decode($content);
+ if (!$multy) {
+ $data = array(0 => $data);
+ }
+
+ return $data;
+ }
+
+}
+
+?>