From bae391b5b37939aca9d7aff96e377db43dee3892 Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Thu, 23 Sep 2010 18:48:06 +0000
Subject: [PATCH] Remove hard-coded UNL_Peoplefinder_Record class. Update
 references so we're only adding the lib path once. Get peoplefinder usage
 functioning correctly.

---
 plugins/cas_auth_unl/peoplefinder/include.php | 113 +++---------------
 plugins/cas_auth_unl/start.php                |   6 +-
 2 files changed, 18 insertions(+), 101 deletions(-)

diff --git a/plugins/cas_auth_unl/peoplefinder/include.php b/plugins/cas_auth_unl/peoplefinder/include.php
index d2123641..7a10bbe1 100644
--- a/plugins/cas_auth_unl/peoplefinder/include.php
+++ b/plugins/cas_auth_unl/peoplefinder/include.php
@@ -1,99 +1,16 @@
 <?php
-	set_include_path(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/lib/php'.PATH_SEPARATOR.get_include_path());
-	require_once 'UNL/Services/Peoplefinder.php';
-	
-	//In order to avoid a "__PHP_Incomplete_Class" problem when we unserialize the Peoplefinder data we need to set up the class here
-	//http://us2.php.net/manual/en/function.unserialize.php
-	class UNL_Peoplefinder_Record {
-	 public $cn;
-	 public $ou;	 
-	 public $eduPersonNickname;
-	 public $eduPersonPrimaryAffiliation;
-	 public $givenName;
-	 public $displayName;
-	 public $mail;
-	 public $postalAddress;
-	 public $sn;
-	 public $telephoneNumber;
-	 public $title;
-	 public $uid;
-	 public $unlHRPrimaryDepartment;
-	 public $unlHRAddress;
-	 public $unlSISClassLevel;
-	 public $unlSISCollege;
-	 public $unlSISLocalAddr1;
-	 public $unlSISLocalAddr2;
-	 public $unlSISLocalCity;
-	 public $unlSISLocalPhone;
-	 public $unlSISLocalState;
-	 public $unlSISLocalZip;
-	 public $unlSISPermAddr1;
-	 public $unlSISPermAddr2;
-	 public $unlSISPermCity;
-	 public $unlSISPermState;
-	 public $unlSISPermZip;
-	 public $unlSISMajor;
-	 public $unlEmailAlias;
-	 
-	/**
-	* Takes in a string from the LDAP directory, usually formatted like:
-	*	 ### ___ UNL 68588-####
-	*	Where ### is the room number, ___ = Building Abbreviation, #### zip extension
-	*
-	* @param string
-	* @return array Associative array.
-	*/
-	function formatPostalAddress() {
-		/* this is a faculty postal address
-			Currently of the form:
-			### ___ UNL 68588-####
-			Where ### is the room number, ___ = Building Abbreviation, #### zip extension
-		*/
-		/**
-		 * We assumed that the address format is: ### ___ UNL 68588-####.
-		 * Some 'fortunate' people have addresses not in this format.
-		 */
-		//RLIM
-		// treat UNL as the delimiter for the streetaddress and zip
-		if (strpos($this->postalAddress,'UNL')) {
-			$addressComponent = explode('UNL', $this->postalAddress);
-		} elseif (strpos($this->postalAddress,'UNO')) {
-			$addressComponent = explode('UNO', $this->postalAddress);
-		} elseif (strpos($this->postalAddress,'Omaha')) {
-			$addressComponent = explode('Omaha', $this->postalAddress);
-		} else {
-			$addressComponent = array($this->postalAddress);
-		}
-		$address['region']		 = 'NE';
-		$address['street-address'] = trim($addressComponent[0]);
-		if (isset($addressComponent[1])) {
-			$address['postal-code'] = trim($addressComponent[1]);
-		} else {
-			$address['postal-code'] = '';
-		}
-		switch (substr($address['postal-code'],0,3)) {
-			case '681':
-				$address['locality'] = 'Omaha';
-			break;
-			case '685':
-			default:
-				$address['locality'] = 'Lincoln';
-			break;
-		}
-		
-		return $address;
-	 }
-	}
-	
-	
-	
-	/**
-	 * Gets a UNL SSO user's info from Peoplefinder Services
-	 * 
-	 * @param string $username
-	 * @return array of information from PF Services
-	 */
-	function peoplefinderServices($username){ 
-		$pfrecord = unserialize(file_get_contents('http://peoplefinder.unl.edu/service.php?uid=' . $username . '&format=php'));
-		return $pfrecord;
-	}
\ No newline at end of file
+require_once 'UNL/Peoplefinder/Record.php';
+require_once 'UNL/LDAP/Entry.php';
+require_once 'UNL/LDAP/Entry/Attribute.php';
+
+/**
+ * Gets a UNL SSO user's info from Peoplefinder Services
+ * 
+ * @param string $username
+ * @return array of information from PF Services
+ */
+function peoplefinderServices($username)
+{
+    $pfrecord = unserialize(file_get_contents('http://peoplefinder.unl.edu/service.php?uid=' . $username . '&format=php'));
+    return $pfrecord;
+}
\ No newline at end of file
diff --git a/plugins/cas_auth_unl/start.php b/plugins/cas_auth_unl/start.php
index c5b8b6ac..5fb32a52 100644
--- a/plugins/cas_auth_unl/start.php
+++ b/plugins/cas_auth_unl/start.php
@@ -11,9 +11,9 @@
 
     global $CONFIG;
 
+    set_include_path(dirname(dirname(dirname(dirname(__FILE__)))).'/lib/php'.PATH_SEPARATOR.get_include_path());
+
     require_once 'peoplefinder/include.php';
-    
-    set_include_path(dirname(__FILE__).'/../../../lib/php'.PATH_SEPARATOR.get_include_path());
     // http://code.google.com/p/simplecas/
     require_once 'SimpleCAS/Autoload.php';
     require_once 'HTTP/Request2.php';
@@ -139,7 +139,7 @@ class elggSimpleCas {
             
             $pf_user_info = peoplefinderServices($casusername);
             if(!empty($pf_user_info->cn))
-            	$name = $pf_user_info->cn;
+            	$name = (string)$pf_user_info->cn;
             else //A peoplefinder record does not exist because they've set their privacy flag so set display name to username so register_user below doesn't break
             	$name = $username;
 
-- 
GitLab