aboutsummaryrefslogtreecommitdiff
path: root/mod/openid_server/lib/session.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2013-11-09 16:26:19 +0100
committerSem <sembrestels@riseup.net>2013-11-09 16:26:19 +0100
commit5cc7f96262509b2a5d43fa6fbb6cd083064385be (patch)
treec2de1ca30876063882cbbb0818d1d618cc6da4c4 /mod/openid_server/lib/session.php
parent2161e2335c9c650b8e44a56f6c9b0bd37546ae1f (diff)
parentb6c722ac63d250972fea066b30e58026d00ab3e2 (diff)
downloadelgg-5cc7f96262509b2a5d43fa6fbb6cd083064385be.tar.gz
elgg-5cc7f96262509b2a5d43fa6fbb6cd083064385be.tar.bz2
Add 'mod/openid_server/' from commit 'b6c722ac63d250972fea066b30e58026d00ab3e2'
git-subtree-dir: mod/openid_server git-subtree-mainline: 2161e2335c9c650b8e44a56f6c9b0bd37546ae1f git-subtree-split: b6c722ac63d250972fea066b30e58026d00ab3e2
Diffstat (limited to 'mod/openid_server/lib/session.php')
-rwxr-xr-xmod/openid_server/lib/session.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/mod/openid_server/lib/session.php b/mod/openid_server/lib/session.php
new file mode 100755
index 000000000..ccd1e8f4c
--- /dev/null
+++ b/mod/openid_server/lib/session.php
@@ -0,0 +1,140 @@
+<?php
+
+//require_once(dirname(dirname(__FILE__)).'/config.php');
+//require_once "render.php";
+
+require_once "Auth/OpenID/Server.php";
+
+// require_once('elgg/includes.php');
+
+/**
+ * Set up the session
+ */
+// get information from Elgg if logged in
+// KJ - this should not be necessary as it can always be generated from the user name
+function init()
+{
+ global $CFG;
+
+ if (elgg_is_logged_in()) {
+ setLoggedInUser(normaliseUsername($_SESSION['user']->username));
+ } else {
+ setLoggedInUser(null);
+ }
+}
+
+
+/**
+ * Get the URL of the current script
+ */
+function getServerURL()
+{
+ global $CONFIG;
+
+ return $CONFIG->wwwroot.'mod/openid_server/server.php';
+}
+
+/**
+ * Build a URL to a server action
+ */
+function buildURL($action=null, $escaped=true)
+{
+ $url = getServerURL();
+ if ($action) {
+ $url .= '/' . $action;
+ }
+ return $escaped ? htmlspecialchars($url, ENT_QUOTES) : $url;
+}
+
+/**
+ * Extract the current action from the request
+ * KJ - this should be replaced by Elgg 1 action system
+ */
+function getAction()
+{
+ $path_info = @$_SERVER['PATH_INFO'];
+ $action = ($path_info) ? substr($path_info, 1) : '';
+ $function_name = 'action_' . $action;
+ return $function_name;
+}
+
+/**
+ * Write the response to the request
+ */
+function writeResponse($resp)
+{
+ list ($headers, $body) = $resp;
+ array_walk($headers, 'header');
+ header(header_connection_close);
+ print $body;
+}
+
+/**
+ * Instantiate a new OpenID server object
+ */
+function getServer()
+{
+ global $CONFIG;
+ static $server;
+ $op_endpoint = getServerURL();
+ if (!isset($server)) {
+ $server =& new Auth_OpenID_Server(getOpenIDServerStore(),$op_endpoint);
+ }
+ return $server;
+}
+
+/**
+ * Return whether the trust root is currently trusted
+ *
+ */
+function isTrusted($identity_url, $trust_root, $return_to)
+{
+ global $store;
+
+ if ($identity_url != getLoggedInUser()) {
+ return false;
+ }
+
+ $sites = $store->getTrustedSites($identity_url);
+
+ if (empty($sites)) {
+ return false;
+ } else {
+ return in_array($trust_root, $sites) && fnmatch($trust_root.'*',$return_to);
+ }
+}
+
+
+/**
+ * Get the openid_url out of the cookie
+ *
+ * @return mixed $openid_url The URL that was stored in the cookie or
+ * false if there is none present or if the cookie is bad.
+ */
+function getLoggedInUser()
+{
+ global $CONFIG;
+ if (elgg_is_logged_in()) {
+ return $CONFIG->wwwroot.'profile/'.$_SESSION['user']->username;
+ } else {
+ return '';
+ }
+}
+
+function getRequestInfo()
+{
+ return isset($_SESSION['openid_server_request'])
+ ? unserialize($_SESSION['openid_server_request'])
+ : false;
+}
+
+function setRequestInfo($info=null)
+{
+ if (!isset($info)) {
+ unset($_SESSION['openid_server_request']);
+ } else {
+ $_SESSION['openid_server_request'] = serialize($info);
+ }
+}
+
+?>