142 private $settingsChanged =
false;
148 private $dataConnector = null;
157 public function __construct($key = null, $dataConnector = null, $autoEnable =
false)
161 if (empty($dataConnector)) {
164 $this->dataConnector = $dataConnector;
166 $this->load($key, $autoEnable);
182 $this->secret = null;
183 $this->ltiVersion = null;
184 $this->consumerName = null;
185 $this->consumerVersion = null;
186 $this->consumerGuid = null;
187 $this->profile = null;
188 $this->toolProxy = null;
189 $this->settings = array();
190 $this->
protected =
false;
191 $this->enabled =
false;
192 $this->enableFrom = null;
193 $this->enableUntil = null;
194 $this->lastAccess = null;
196 $this->defaultEmail =
'';
197 $this->created = null;
198 $this->updated = null;
222 $ok = $this->dataConnector->saveToolConsumer($this);
224 $this->settingsChanged =
false;
236 public function delete()
239 return $this->dataConnector->deleteToolConsumer($this);
299 return $this->dataConnector;
314 if ($ok && !is_null($this->enableFrom)) {
315 $ok = $this->enableFrom <= $now;
317 if ($ok && !is_null($this->enableUntil)) {
318 $ok = $this->enableUntil > $now;
336 if (array_key_exists(
$name, $this->settings)) {
337 $value = $this->settings[
$name];
356 if ($value !== $old_value) {
357 if (!empty($value)) {
358 $this->settings[
$name] = $value;
360 unset($this->settings[
$name]);
362 $this->settingsChanged =
true;
399 if ($this->settingsChanged) {
417 $url = $this->
getSetting(
'custom_system_setting_url');
433 $url = $this->
getSetting(
'custom_system_setting_url');
435 $response = $service->get();
451 $url = $this->
getSetting(
'custom_system_setting_url');
474 $queryParams = array();
475 $queryString = parse_url($url, PHP_URL_QUERY);
476 if (!is_null($queryString)) {
477 $queryItems = explode(
'&', $queryString);
478 foreach ($queryItems as $item) {
479 if (strpos($item,
'=') !==
false) {
480 list(
$name, $value) = explode(
'=', $item);
481 $queryParams[urldecode(
$name)] = urldecode($value);
483 $queryParams[urldecode($item)] =
'';
487 $params = $params + $queryParams;
489 $params[
'lti_version'] = $version;
490 $params[
'lti_message_type'] = $type;
491 $params[
'oauth_callback'] =
'about:blank';
496 $req->sign_request($hmacMethod, $consumer, null);
497 $params = $req->get_parameters();
499 foreach (array_keys($queryParams) as
$name) {
500 unset($params[$name]);
513 public static function addSignature($endpoint, $consumerKey, $consumerSecret, $data, $method =
'POST', $type = null)
517 if (is_array($data)) {
521 $queryParams = array();
522 $queryString = parse_url($endpoint, PHP_URL_QUERY);
523 if (!is_null($queryString)) {
524 $queryItems = explode(
'&', $queryString);
525 foreach ($queryItems as $item) {
526 if (strpos($item,
'=') !==
false) {
527 list(
$name, $value) = explode(
'=', $item);
528 $queryParams[urldecode(
$name)] = urldecode($value);
530 $queryParams[urldecode($item)] =
'';
533 $params = $params + $queryParams;
536 if (!is_array($data)) {
538 $hash = base64_encode(sha1($data,
true));
539 $params[
'oauth_body_hash'] = $hash;
546 $oauthReq->sign_request($hmacMethod, $oauthConsumer, null);
547 $params = $oauthReq->get_parameters();
549 foreach (array_keys($queryParams) as
$name) {
550 unset($params[$name]);
553 if (!is_array($data)) {
554 $header = $oauthReq->to_header();
557 $header .=
"\nAccept: {$type}";
559 }
else if (isset($type)) {
560 $header .=
"\nContent-Type: {$type}";
561 $header .=
"\nContent-Length: " . strlen($data);
586 $http =
new HTTPMessage($service->endpoint, $method, $data, $header);
588 if ($http->send() && !empty($http->response)) {
589 $http->responseJson = json_decode($http->response);
590 $http->ok = !is_null($http->responseJson);
610 $toolConsumer->initialize();
611 $toolConsumer->setRecordId($id);
612 if (!$dataConnector->loadToolConsumer($toolConsumer)) {
613 $toolConsumer->initialize();
616 return $toolConsumer;
633 private function load($key, $autoEnable =
false)
637 $ok = $this->dataConnector->loadToolConsumer($this);
639 $this->enabled = $autoEnable;
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=null)
pretty much a helper function to set up the request
Class to represent an OAuth Consumer.
Class to represent an HTTP message.
Class to represent an OAuth HMAC_SHA1 signature method.