From f5f7ccbb765b6e59d5dfc2ccd6c25c3fd1c91bcc Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Wed, 30 Jul 2008 21:24:09 +0000
Subject: [PATCH] Add PodcastProducer libraries to UNL Library

---
 library/Unl/Plist.php | 87 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 library/Unl/Plist.php

diff --git a/library/Unl/Plist.php b/library/Unl/Plist.php
new file mode 100644
index 00000000..5ea98afb
--- /dev/null
+++ b/library/Unl/Plist.php
@@ -0,0 +1,87 @@
+<?php
+
+class Unl_Plist
+{
+	static public function plistToArray($xml)
+	{
+		$dom = DOMDocument::loadXML($xml);
+		$xPath = new DOMXPath($dom);
+		
+		$root = $xPath->query('plist/*')->item(0);
+		
+		return self::_parseNode($root);
+	}
+	
+	static protected function _parseNode($node)
+	{
+		switch ($node->nodeName) {
+			case 'integer':
+				return self::_parseInt($node);
+				break;
+			case 'string':
+			case 'key':
+				return self::_parseString($node);
+				break;
+			case 'date':
+				return self::_parseDate($node);
+				break;
+			case 'true':
+			case 'false':
+				return self::_parseBool($node);
+				break;
+			case 'dict':
+				return self::_parseDict($node);
+				break;
+			case 'array':
+				return self::_parseArray($node);
+				break;
+			default:
+				return null;
+		}
+	}
+
+    static protected function _parseInt($node)
+    {
+        return intval($node->textContent);
+    }
+    static protected function _parseString($node)
+    {
+        return $node->textContent;
+    }
+    static protected function _parseDate($node)
+    {
+        
+    }
+    static protected function _parseBool($node)
+    {
+        return (bool) ($node->nodeName == 'true');
+    }
+    static protected function _parseDict($node)
+    {
+    	$dict = array();
+    	$childNodes = array();
+    	foreach ($node->childNodes as $childNode) {
+    		if ($childNode->nodeName == '#text') {
+    			continue;
+    		}
+    		$childNodes[] = $childNode;
+    	}
+        for ($i = 0; $childNodes[$i]; $i += 2) {
+        	$key = self::_parseNode($childNodes[$i]);
+        	$value = self::_parseNode($childNodes[$i+1]);
+            $dict[$key] = $value;
+        }
+        return $dict;
+    }
+    static protected function _parseArray($node)
+    {
+        $array = array();
+        foreach ($node->childNodes as $childNode) {
+            if ($childNode->nodeName == '#text') {
+                continue;
+            }
+            $array[] = self::_parseNode($childNode);
+        }
+        return $array;
+    }
+}
-- 
GitLab