From ab2887f4c588d9bab360d1204a71a2602ff45edd Mon Sep 17 00:00:00 2001
From: Eric Rasmussen <erasmussen2@unl.edu>
Date: Wed, 14 Jul 2010 19:24:06 +0000
Subject: [PATCH] add UNL_Services_Peoplefinder to /lib/php

---
 lib/php/UNL/Services/Peoplefinder.php | 92 +++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 lib/php/UNL/Services/Peoplefinder.php

diff --git a/lib/php/UNL/Services/Peoplefinder.php b/lib/php/UNL/Services/Peoplefinder.php
new file mode 100644
index 00000000..21878ab6
--- /dev/null
+++ b/lib/php/UNL/Services/Peoplefinder.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Package which connects to the peoplefinder services to get information about UNL people.
+ *
+ * 
+ * @author Brett Bieber
+ * @package UNL_Services_Peoplefinder
+ */
+
+/**
+ * This is the basic class for utilizing the UNL Peoplefinder service which can
+ * give you various pieces of information about a given uid (uniue user id).
+ * 
+ * @package UNL_Services_Peoplefinder
+ */
+class UNL_Services_Peoplefinder
+{
+    
+    /**
+     * returns the name for a given uid
+     *
+     * @param string $uid
+     * @return string|false
+     */
+    function getFullName($uid)
+    {
+        if ($vcard = UNL_Services_Peoplefinder::getVCard($uid)) {
+            $matches = array();
+            preg_match_all('/FN:(.*)/',$vcard, $matches);
+            if (isset($matches[1][0]) && $matches[1][0] != ' ') {
+                return $matches[1][0];
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    /**
+     * returns the email address for the given uid
+     *
+     * @param string $uid
+     * @return string|false
+     */
+    function getEmail($uid)
+    {
+        if ($hcard = UNL_Services_Peoplefinder::getHCard($uid)) {
+            $matches = array();
+            preg_match_all('/mailto:([^\'\"]*)/',$hcard, $matches);
+            if (isset($matches[1][0])) {
+                return $matches[1][0];
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    /**
+     * Gets an hcard for the uid given.
+     *
+     * @param string $uid
+     * @return string|false
+     */
+    function getHCard($uid)
+    {
+        if ($hcard = file_get_contents('http://peoplefinder.unl.edu/hcards/'.$uid)) {
+            return $hcard;
+        } else {
+            return false;
+        }
+    }
+    
+    /**
+     * Gets a vcard for the given uid.
+     *
+     * @param string $uid
+     * @return string|false
+     */
+    function getVCard($uid)
+    {
+        if ($vcard = file_get_contents('http://peoplefinder.unl.edu/vcards/'.$uid)) {
+            return $vcard;
+        } else {
+            return false;
+        }
+    }
+}
+
+?>
\ No newline at end of file
-- 
GitLab