aboutsummaryrefslogtreecommitdiff
path: root/classes/OpenID_ElggStore.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-09-28 19:32:42 +0200
committerSem <sembrestels@riseup.net>2012-09-28 19:32:42 +0200
commit133c0f26d799a4c8747822f92922cd053b865f70 (patch)
treea4ea1b3dfac0846528fd7ac9fb7e6c4aeec9dc65 /classes/OpenID_ElggStore.php
parent94500e7181e9223252156fd91e5fb5b926c3acc9 (diff)
downloadelgg-133c0f26d799a4c8747822f92922cd053b865f70.tar.gz
elgg-133c0f26d799a4c8747822f92922cd053b865f70.tar.bz2
Added trust_root save methods.
Diffstat (limited to 'classes/OpenID_ElggStore.php')
-rw-r--r--classes/OpenID_ElggStore.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/classes/OpenID_ElggStore.php b/classes/OpenID_ElggStore.php
index 35f4797a1..2d4800e9b 100644
--- a/classes/OpenID_ElggStore.php
+++ b/classes/OpenID_ElggStore.php
@@ -277,4 +277,144 @@ class OpenID_ElggStore extends Auth_OpenID_OpenIDStore {
$nonce->delete();
}
}
+
+ protected function getTrustedSites($user_guid = true) {
+
+ if ($user_guid === true) {
+ $user_guid = elgg_get_logged_in_user_guid();
+ } elseif (!$user_guid) {
+ $user_guid = ELGG_ENTITIES_ANY_VALUE;
+ }
+
+ $results = elgg_get_entities(array(
+ 'type' => 'object',
+ 'subtype' => 'openid_server::trust_root',
+ 'owner_guid' => $user_guid,
+ ));
+
+ return $results;
+ }
+
+ public function getTrustedRoots ($user_guid = true) {
+
+ $results = $this->getTrustedSites($user_guid);
+
+ $sites = array();
+ if ($results) {
+ foreach ($results as $site) {
+ $sites[] = $site->trust_root;
+ }
+ }
+ return $sites;
+ }
+
+ /**
+ * Returns the autologin URLs for every trusted site
+ */
+
+ public function getAutoLoginSites() {
+
+ $default_trusted_sites = $this->getTrustedSites(false);
+
+ $sites = array();
+ if ($default_trusted_sites) {
+ foreach ($default_trusted_sites as $site) {
+ if ($site->auto_login_url) {
+ $sites[] = $site;
+ }
+ }
+ }
+ return $sites;
+ }
+
+ /**
+ * Returns the autologout URLs for every trusted site
+ */
+
+ public function getAutoLogoutSites() {
+
+ $default_trusted_sites = $this->getTrustedSites(false);
+
+ $sites = array();
+ if ($default_trusted_sites) {
+ foreach ($default_trusted_sites as $site) {
+ if ($site->auto_logout_url) {
+ $sites[] = $site;
+ }
+ }
+ }
+ return $sites;
+ }
+
+ static function isTrustedRoot($trust_root) {
+ $results = elgg_get_entities_from_metadata(array(
+ 'type' => 'object',
+ 'subtype' => 'openid_server::trust_root',
+ 'owner_guid' => elgg_get_logged_in_user_guid(),
+ 'metadata_name' => 'trust_root',
+ 'metadata_value' => $trust_root,
+ ));
+
+ return !! $results;
+ }
+
+ public function setTrustedSite($trust_root) {
+
+ if (self::isTrustedRoot($trust_root)) {
+ return true;
+ }
+
+ $site = new ElggObject();
+ $site->subtype = 'openid_server::trust_root';
+ $site->owner_guid = elgg_get_logged_in_user_guid();
+ $site->title = 'association';
+ $site->access_id = ACCESS_PUBLIC;
+
+ if ($site->save()) {
+ $site->trust_root = $trust_root->trust_root;
+ $site->site_name = $trust_root->site_name;
+ $site->autologin = $trust_root->autologin;
+ $site->autologout = $trust_root->autologout;
+ $site->width = $trust_root->width;
+ $site->height = $trust_root->height;
+ return true;
+ }
+ return false;
+ }
+
+ public function removeUserTrustedSites($user = true) {
+
+ $results = $this->getTrustedSites($user);
+
+ if ($results) {
+ foreach($results as $trust_root) {
+ $trust_root->delete();
+ }
+ }
+ return true;
+ }
+
+ public function removeTrustedSite($trust_root, $user_guid = true) {
+
+ if ($user_guid === true) {
+ $user_guid = elgg_get_logged_in_user_guid();
+ } elseif (!$user_guid) {
+ $user_guid = ELGG_ENTITIES_ANY_VALUE;
+ }
+
+ $results = elgg_get_entities_from_metadata(array(
+ 'type' => 'object',
+ 'subtype' => 'openid_server::trust_root',
+ 'owner_guid' => $user_guid,
+ 'metadata_name' => 'trust_root',
+ 'metadata_value' => $trust_root,
+ ));
+
+ if ($results) {
+ foreach($results as $trust_root) {
+ $trust_root->delete();
+ }
+ }
+ return true;
+ }
}