Project "FreeSWITCH user-contributed scripts, etc" received a push.

branch: master updated

       via: 078d663ef932223e27db8166e074cc4f4542a339 (commit)
       via: 7342c77d10810960f49fc5213db4a23dc203fd7a (commit)
       via: 9ecdde39b5fb94c4708b530a7c90e82900ff15ed (commit)
       via: 69415c934e4b3dc70b22816aa847706336c442f5 (commit)
       via: 8b7b83f0a42fc7cce5deaacd1c3a56f76c392175 (commit)
       via: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
      from: 4bebf82901b579b38a58642bf4e409db912f33bb (commit)


= COMMIT LOG ===========================================================
committer: Mitch Capper
comments: 
Merge branch 'master' of ssh://git.freeswitch.org/freeswitch-contrib
committer: Mathieu Parent
comments: 
MediaBrotha: Add missing HTML files

diff --git a/sathieu/cisco-xml/browser/static/default.css b/sathieu/cisco-xml/browser/static/default.css
new file mode 100644
index 0000000..6ef61fc
--- /dev/null
+++ b/sathieu/cisco-xml/browser/static/default.css
@@ -0,0 +1,49 @@
+/*
+ * body > ul#mediaListElement > li.mediaElement
+ */
+li.mediaElement {
+	padding: 2px;
+	margin: 0px;
+	list-style-type: none;
+}
+
+li.mediaElement:nth-child(odd) {
+	background-color: #d1e3ed;
+}
+
+/*
+ * body > ul#mediaListElement
+ */
+#mediaListElement {
+	padding: 2px;
+	margin: 0px;
+}
+
+
+/*
+ * body > ul#mediaListElement > li.mediaElement > ul.mediaActionsListElement
+ */
+li.mediaElement .mediaActionsListElement {
+	padding: 2px;
+	margin: 0px;
+	margin-left: 20px;
+	list-style-type: none;
+
+	-moz-transition-property: max-height, opacity, visibility;
+	-moz-transition-duration: 3s, 2s, 0.2s;
+	-moz-transition-delay: 0s, 1s, 1s;
+	max-height: 0px;
+	opacity: 0;
+	visibility: hidden;
+}
+
+li.mediaElement:hover .mediaActionsListElement {
+	-moz-transition-property: max-height, opacity, visibility;
+	-moz-transition-duration: 0.5s, 2s, 0.2s;
+	-moz-transition-delay: 0.4s, 0.4s, 0.4s;
+	max-height: 200px;
+	opacity: 1;
+	visibility: visible;
+}
+
+
diff --git a/sathieu/cisco-xml/browser/static/dynamic.js b/sathieu/cisco-xml/browser/static/dynamic.js
new file mode 100644
index 0000000..721eb51
--- /dev/null
+++ b/sathieu/cisco-xml/browser/static/dynamic.js
@@ -0,0 +1,4 @@
+function bodyLoaded() {
+	//nothing yet
+}
+
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
new file mode 100644
index 0000000..6d09e1b
--- /dev/null
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
@@ -0,0 +1,127 @@
+<?php
+/*
+Copyright 2011 Mathieu Parent <math.parent@gmail.com> 
+
+This file is part of MediaBrotha.
+
+	MediaBrotha is free software: you can
+	redistribute it and/or modify it under the terms of the GNU General
+	Public License as published by the Free Software Foundation, either
+	version 3 of the License, or (at your option) any later version.
+
+	MediaBrotha is distributed in the hope that it
+	will be useful, but WITHOUT ANY WARRANTY; without even the implied
+	warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+	the GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with MediaBrotha. If not, see
+	<http://www.gnu.org/licenses/>.
+
+*/
+
+/**
+ * @author Mathieu Parent
+ */
+
+require_once('HTTP.php');
+
+class MediaBrotha_Frontend_HTML extends MediaBrotha_Frontend_HTTP {
+	private $_xml = NULL;
+	private $_body = NULL;
+	private $_mediaListElement = NULL;
+	private $_actionsListElement = NULL;
+
+	private function _mediaActionLinks($parent, $media, $tag_name) {
+		$url = $this->rootURL().'?'.
+			MediaBrotha_Core::value2hash(
+				'mime_type='.urlencode($media->getMimeType()).'&'.
+				($media->getMimeEncoding() ? ('mime_encoding='.urlencode($media->getMimeEncoding()).'&') : '').
+				'uri='.urlencode($media->getURI()));
+
+		foreach (MediaBrotha_Core::getBackends() as $backend) {
+			foreach ($backend->getMediaActions($media) as $action) {
+				$tag = $this->_xml->createElement($tag_name);
+				$tag = $parent->appendChild($tag);
+
+				$a = $this->_xml->createElement('a');
+				$a = $tag->appendChild($a);
+				$a->setAttribute('href', "$url&".MediaBrotha_Core::value2hash('action='.$action.'&backend='.$backend->getBackendName()));
+
+				$text = $this->_xml->createTextNode($action);
+				$text = $a->appendChild($text);
+			}
+		}
+	}
+
+	public function begin($item) {
+		$this->_xml = new DOMDocument('1.0');
+		$root = $this->_xml->createElement('html');
+		$root = $this->_xml->appendChild($root);
+
+		$head = $this->_xml->createElement('head');
+		$head = $root->appendChild($head);
+
+		$title = $this->_xml->createElement('title');
+		$title = $head->appendChild($title);
+
+		$text = $this->_xml->createTextNode($item->getDisplayName());
+		$text = $title->appendChild($text);
+
+		$style = $this->_xml->createElement('link');
+		$style = $head->appendChild($style);
+		$style->setAttribute('type', 'text/css');
+		$style->setAttribute('rel', 'stylesheet');
+		$style->setAttribute('href', $this->rootURL().'static/default.css');
+
+		$script = $this->_xml->createElement('script');
+		$script = $head->appendChild($script);
+		$script->setAttribute('type', 'text/javascript');
+		$script->setAttribute('src', $this->rootURL().'static/dynamic.js');
+
+		$this->_body = $this->_xml->createElement('body');
+		$this->_body = $root->appendChild($this->_body);
+		$this->_body->setAttribute('onload', 'bodyLoaded();');
+
+		$this->_mediaListElement = $this->_xml->createElement('ul');
+		$this->_mediaListElement = $this->_body->appendChild($this->_mediaListElement);
+		$this->_mediaListElement->setAttribute('id', 'mediaListElement');
+		if ($parent = $item->getParent()) {
+			$this->addItem($parent);
+		}
+	}
+	public function addItem($item) {
+		$url = $this->rootURL().'?'.
+			MediaBrotha_Core::value2hash(
+				'mime_type='.urlencode($item->getMimeType()).'&'.
+				($item->getMimeEncoding() ? ('mime_encoding='.urlencode($item->getMimeEncoding()).'&') : '').
+				'uri='.urlencode($item->getURI()));
+
+		$li = $this->_xml->createElement('li');
+		$li = $this->_mediaListElement->appendChild($li);
+		$li->setAttribute('class', 'mediaElement');
+
+		$a = $this->_xml->createElement('a');
+		$a = $li->appendChild($a);
+		$a->setAttribute('href', $url);
+
+		$text = $this->_xml->createTextNode($item->getDisplayName());
+		$text = $a->appendChild($text);
+
+		$ul = $this->_xml->createElement('ul');
+		$ul = $li->appendChild($ul);
+		$ul->setAttribute('class', 'mediaActionsListElement');
+
+		$this->_mediaActionLinks($ul, $item, 'li');
+	}
+	public function finish($item) {
+		$this->_actionsListElement = $this->_xml->createElement('ul');
+		$this->_actionsListElement = $this->_body->appendChild($this->_actionsListElement);
+		$this->_actionsListElement->setAttribute('id', 'actionsListElement');
+		$this->_mediaActionLinks($this->_actionsListElement, $item, 'li');
+	}
+	public function render() {
+		print $this->_xml->saveHTML();
+	}
+}
+
committer: Mathieu Parent
comments: 
MediaBrotha: various enhancements
- add a HTML frontend
- frontend choosen automaticaly depending on browser
- handling of parent media
- max length for metadata and display_name

diff --git a/sathieu/cisco-xml/browser/index.php b/sathieu/cisco-xml/browser/index.php
index d142ff5..137b409 100644
--- a/sathieu/cisco-xml/browser/index.php
+++ b/sathieu/cisco-xml/browser/index.php
@@ -35,7 +35,11 @@ require_once('MediaBrotha/Core.php');
 
 // Init
 MediaBrotha_Core::init();
-MediaBrotha_Core::connectFrontend('CiscoXML', Array('push_url' => 'http://cisco:cisco@192.168.0.220/CGI/Execute'));
+if (CiscoIPPhone::userAgentIsCiscoIPPhone()) {
+	MediaBrotha_Core::connectFrontend('CiscoXML', Array('push_url' => 'http://cisco:cisco@192.168.0.220/CGI/Execute'));
+} else {
+	MediaBrotha_Core::connectFrontend('HTML');
+}
 
 // Backends
 MediaBrotha_Core::loadBackend('FileSystem', Array('base_path' => '/home/share/music/'));
@@ -51,10 +55,9 @@ $ldap_connect_config = Array(
 MediaBrotha_Core::loadBackend('LDAP', Array('ldap_connect_config' => $ldap_connect_config));
 
 // Roots
-MediaBrotha_Core::addRootMedia('file:///home/share/music/', Array('name'=> 'Fichiers'));
-MediaBrotha_Core::addRootMedia('ldap:///', Array('name'=> 'Annuaire'));
+MediaBrotha_Core::addRootMedia('file:///home/share/music/', Array('display_name'=> 'Fichiers'));
+MediaBrotha_Core::addRootMedia('ldap:///', Array('display_name'=> 'Annuaire'));
 
 MediaBrotha_Core::go();
 
 
-
diff --git a/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php b/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
index c711f9c..216aad6 100644
--- a/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
+++ b/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
@@ -23,6 +23,12 @@ This file is part of XML services for Cisco IP Phones.
 /**
  * @author Mathieu Parent
  */
+class CiscoIPPhone {
+	static public function userAgentIsCiscoIPPhone() {
+		return preg_match('/^Allegro-Software-WebClient\//', $_SERVER['HTTP_USER_AGENT']);
+
+	}
+}
 
 class CiscoXMLField {
 	private $_allowed_fields = NULL;
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
index 84a6a89..28a8441 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
@@ -71,12 +71,17 @@ class MediaBrotha_Backend {
 	}
 
 	// Actions
-	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+	public function getMediaActions(MediaBrotha_Media $media) {
 		return Array();
 	}
 
 	public function doMediaAction($action, MediaBrotha_Media $media) {
 		return false;
 	}
+
+	// Populate
+	public function populateMedia(MediaBrotha_Media $media) {
+	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
index 39928b4..006814b 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
@@ -40,10 +40,13 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 	// Browsing
 	public function mediaFromBufferItem($file) {
 		if ($file) {
+			if ($file->getFilename() === '..') {
+				return NULL;
+			}
 			$media = new MediaBrotha_Media(
 				'file://'.realpath($file->getPathname()),
 				Array(
-					'name' => $file->getFilename(),
+					'display_name' => $file->getFilename(),
 					'hidden' => !$file->isReadable() || preg_match('/^\.([^.]|$)/', $file->getFilename()),
 				)
 			);
@@ -59,31 +62,47 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 	}
 
 	public function fetch(MediaBrotha_Media $media) {
-		$uri =$media->getURI();
+		$uri = $media->getURI();
 		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
-			$uri = 'file://'.$this->getMetadata('base_path');
+			$uri = 'file://'.$this->getParam('base_path');
 		}
 		$path = parse_url($uri, PHP_URL_PATH);
 		if (is_dir($path)) {
 			return new MediaBrotha_MediaIterator($this, $media, new DirectoryIterator($path));
 		} else {
-			$this->setURI(NULL);
 			return false;
 		}
 	}
 
 	// Actions
-	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		if ($mime_type === 'application/x-directory') {
-			return Array(
-				'browse',
-			);
-		} elseif ($uri && (substr($uri, 0, 7) === 'file://')) {
+	protected function _isHandled(MediaBrotha_Media $media) {
+		return ($media->getMimeType() === 'application/x-directory')
+			|| (substr($media->getURI(), 0, 7) === 'file://');
+	}
+
+	public function getMediaActions(MediaBrotha_Media $media) {
+		if ($this->_isHandled($media)) {
 			return Array(
 				'browse',
 			);
 		} else {
-			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
+			return parent::getMediaActions($media);
+		}
+	}
+
+	// Populate
+	public function populateMedia(MediaBrotha_Media $media) {
+		if ($this->_isHandled($media)) {
+			$parent_path = 'file://'.dirname(parse_url($media->getURI(), PHP_URL_PATH));
+			if ($this->isURISafe($parent_path)) {
+				$media->setParent(
+					new MediaBrotha_Media($parent_path,
+						Array(
+							'display_name' => '..',
+						)
+					)
+				);
+			}
 		}
 	}
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
index c882dd7..365e78e 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
@@ -54,7 +54,7 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
 			$media = new MediaBrotha_Media(
 				'ldap:///'.$entry->dn(),
 				Array(
-					'name' => $entry->dn(), //$entry->getValue('sn', 'single'),
+					'display_name' => $entry->dn(), //$entry->getValue('sn', 'single'),
 				),
 				'text/directory'
 				//$finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING);
@@ -79,17 +79,18 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
 		return true;
 	}
 	// Actions
-	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		if ($mime_type === 'text/directory') {
-			return Array(
-				'browse',
-			);
-		} elseif ($uri && (substr($uri, 0, 7) === 'ldap://')) {
+	protected function _isHandled(MediaBrotha_Media $media) {
+		return ($media->getMimeType() === 'text/directory')
+			|| (substr($media->getURI(), 0, 7) === 'ldap://');
+	}
+
+	public function getMediaActions(MediaBrotha_Media $media) {
+		if ($this->_isHandled($media)) {
 			return Array(
 				'browse',
 			);
 		} else {
-			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
+			return parent::getMediaActions($media);
 		}
 	}
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
index addba42..9616be8 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
@@ -30,11 +30,18 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
 
 	public function __construct($params = NULL) {
 		parent::__construct($params);
-		$this->_media = new MediaBrotha_Media('MediaBrotha:///');
+		$this->_media = new MediaBrotha_Media('MediaBrotha:///',
+			Array(
+				'display_name' => 'Root',
+			)
+		);
 		$this->_media_iterator = new MediaBrotha_MediaIterator($this, $this->_media);
 	}
 
-	public function addRootMedia($media) {
+	public function addRootMedia($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
+		$this->addRootMediaObj(new MediaBrotha_Media($URI, $metadata, $mime_type,$mime_encoding));
+	}
+	public function addRootMediaObj($media) {
 		$this->_media_iterator->bufferAdd($media);
 	}
 
@@ -42,13 +49,6 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
 	public function fetch(MediaBrotha_Media $media) {
 		return $this->_media_iterator;
 	}
-
-	// Actions
-	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array(
-		);
-	}
-
 }
 
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
index 2b4e7c6..8c3208e 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
@@ -50,17 +50,13 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 	}
 
 	// Actions
-	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		if (in_array($mime_type, Array($this::$_supported_mime_types))) {
-			return Array(
-				'play_media',
-				'pause_media',
-				'stop_media',
-				'enqueue_media',
-				'next_media',
-				'previous_media',
-			);
-		} elseif ($uri && (substr($uri, 0, 7) === 'file://')) {
+	protected function _isHandled(MediaBrotha_Media $media) {
+		return in_array($media->getMimeType(), Array($this::$_supported_mime_types))
+			|| (substr($media->getURI(), 0, 7) === 'file://');
+	}
+
+	public function getMediaActions(MediaBrotha_Media $media) {
+		if ($this->_isHandled($media)) {
 			return Array(
 				'play_media',
 				'pause_media',
@@ -70,7 +66,7 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 				'previous_media',
 			);
 		} else {
-			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
+			return parent::getMediaActions($media);
 		}
 	}
 	public function doMediaAction($action, MediaBrotha_Media $media) {
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Core.php b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
index 5ec90e8..8997a7c 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Core.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
@@ -34,47 +34,17 @@ class MediaBrotha_Core {
 	private static $_backends = Array();
 	private static $_media = NULL;
 	
+	/*
+	 * Core
+	 */
 	public static function init() {
 		if (!session_start()) {
 			die('Unable to start session');
 		}
-		if (!isset($_SESSION['HASHES'])) {
-			$_SESSION['HASHES'] = Array();
-		}
-		if (isset($_SERVER["QUERY_STRING"])) {
-			$tmp = explode('&', $_SERVER["QUERY_STRING"]);
-			foreach ($tmp as $h) {
-				if (preg_match('/^[a-z0-9]+$/', $h)) {
-					if ($s = MediaBrotha_Core::hash2string($h)) {
-						parse_str($s, $output);
-						$_GET = array_merge($_GET, $output);
-					}
-				}
-			}
-		}
+		MediaBrotha_Core::_unhashRequest();
 		MediaBrotha_Core::loadBackend('Root');
 	}
 
-	public static function hash2string($h) {
-		if (isset($_SESSION['HASHES'][$h])) {
-			return $_SESSION['HASHES'][$h];
-		} else {
-			//print 'NO string for hash '.$h;
-			return NULL;
-		}
-	}
-
-	public static function string2hash($s) {
-		for($hash_length = 1 ; $hash_length <=41 ; $hash_length++) {
-			$h = substr(sha1($s), 0, $hash_length);
-			if (!isset($_SESSION['HASHES'][$h]) || ($_SESSION['HASHES'][$h] === $s)) {
-				break;
-			}
-		}
-		$_SESSION['HASHES'][$h] = $s;
-		return $h;
-	}
-
 	public static function go() {
 		$current_backend = MediaBrotha_Core::getCurrentBackend();
 		$current_media = MediaBrotha_Core::getCurrentMedia();
@@ -82,7 +52,7 @@ class MediaBrotha_Core {
 			if ($media_iterator = $current_backend->fetch($current_media)) {
 				MediaBrotha_Core::$_frontend->begin($current_media);
 				foreach ($media_iterator as $item) {
-					if ($item->isHidden()) {
+					if (($item === NULL) || $item->isHidden()) {
 						continue;
 					}
 					MediaBrotha_Core::$_frontend->addItem($item);
@@ -97,10 +67,9 @@ class MediaBrotha_Core {
 	}
 
 	public function addRootMedia($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
-		MediaBrotha_Core::$_backends['Root']->addRootMedia(
-			new MediaBrotha_Media($URI, $metadata, $mime_type,$mime_encoding)
-		);
+		MediaBrotha_Core::$_backends['Root']->addRootMedia($URI, $metadata, $mime_type, $mime_encoding);
 	}
+
 	/*
 	 * Backends
 	 */
@@ -120,22 +89,7 @@ class MediaBrotha_Core {
 	public static function getBackends() {
 		return MediaBrotha_Core::$_backends;
 	}
-	public static function getCurrentBackend() {
-		if (!empty($_GET['backend']) && !empty(MediaBrotha_Core::$_backends[$_GET['backend']])) {
-			return MediaBrotha_Core::$_backends[$_GET['backend']];
-		}
-		foreach (MediaBrotha_Core::getBackends() as $backend) {
-			foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {
-				if ($backend->getBackendName() == 'Root') {
-					continue;
-				}
-				if ($action === MediaBrotha_Core::getAction()) {
-					return $backend;
-				}
-			}
-		}
-		return MediaBrotha_Core::$_backends['Root'];
-	}
+
 	/*
 	 * Frontend
 	 */
@@ -151,8 +105,26 @@ class MediaBrotha_Core {
 		MediaBrotha_Core::$_frontend = new $class_name($args);
 	}
 	/*
-	 * ...
+	 * Current *
 	 */
+	public static function getCurrentBackend() {
+		if (!empty($_GET['backend']) && !empty(MediaBrotha_Core::$_backends[$_GET['backend']])) {
+			return MediaBrotha_Core::$_backends[$_GET['backend']];
+		}
+		$current_media = MediaBrotha_Core::getCurrentMedia();
+		foreach (MediaBrotha_Core::getBackends() as $backend) {
+			foreach ($backend->getMediaActions($current_media) as $action) {
+				if ($backend->getBackendName() == 'Root') {
+					continue;
+				}
+				if ($action === MediaBrotha_Core::getAction()) {
+					return $backend;
+				}
+			}
+		}
+		return MediaBrotha_Core::$_backends['Root'];
+	}
+
 	public static function getAction() {
 		if (!empty($_GET['action'])) {
 			return $_GET['action'];
@@ -161,17 +133,63 @@ class MediaBrotha_Core {
 		}
 	}
 
-	public static function getCurrentURI() {
-		if (!empty($_GET['uri'])) {
-			return (string) $_GET['uri'];
-		}
-	}
 	public static function getCurrentMedia() {
 		if (empty(MediaBrotha_Core::$_media)) {
-			MediaBrotha_Core::$_media = new MediaBrotha_Media(MediaBrotha_Core::getCurrentURI());
+			if (!empty($_GET['uri'])) {
+				MediaBrotha_Core::$_media = new MediaBrotha_Media($_GET['uri']);
+			} else {
+				MediaBrotha_Core::$_media = new MediaBrotha_Media('MediaBrotha:///');
+			}
+			foreach (MediaBrotha_Core::getBackends() as $backend) {
+				$backend->populateMedia(MediaBrotha_Core::$_media);
+			}
 		}
 		return MediaBrotha_Core::$_media;
 	}
 
+	/*
+	 * helper functions
+	 */
+	/* hashes */
+	public static function hash2value($h) {
+		if (isset($_SESSION['HASHES'][$h])) {
+			return $_SESSION['HASHES'][$h];
+		} else {
+			return NULL;
+		}
+	}
+
+	public static function value2hash($v) {
+		for($hash_length = 1 ; $hash_length <=41 ; $hash_length++) {
+			$h = substr(sha1($v), 0, $hash_length);
+			if (!isset($_SESSION['HASHES'][$h]) || ($_SESSION['HASHES'][$h] === $v)) {
+				break;
+			}
+		}
+		$_SESSION['HASHES'][$h] = $v;
+		return $h;
+	}
+
+	public static function hash2array($h) {
+		if ($v = MediaBrotha_Core::hash2value($h)) {
+			parse_str($v, $output);
+			return $output;
+		}
+	}
+
+	private static function _unhashRequest() {
+		if (!isset($_SESSION['HASHES'])) {
+			$_SESSION['HASHES'] = Array();
+		}
+		if (isset($_SERVER["QUERY_STRING"])) {
+			$tmp = explode('&', $_SERVER["QUERY_STRING"]);
+			foreach ($tmp as $h) {
+				if (preg_match('/^[a-z0-9]+$/', $h)) {
+					$_GET = array_merge($_GET, MediaBrotha_Core::hash2array($h));
+				}
+			}
+		}
+	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
index 2baa6af..914e6ee 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
@@ -30,12 +30,15 @@ class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend_HTTP {
 	private $_xml = NULL;
 	public function begin($item) {
 		$this->_xml = new CiscoIPPhoneMenu();
-		$this->_xml->setCiscoElement('Title', $item->getDisplayName());
+		$this->_xml->setCiscoElement('Title', $item->getDisplayName(32));
 		$this->_xml->setCiscoElement('Prompt', substr($item->getURI(), -32));
+		if ($parent = $item->getParent()) {
+			$this->addItem($parent);
+		}
 	}
 	public function addItem($item) {
 		$url = $this->rootURL().'?'.
-			MediaBrotha_Core::string2hash(
+			MediaBrotha_Core::value2hash(
 				'mime_type='.urlencode($item->getMimeType()).'&'.
 				($item->getMimeEncoding() ? ('mime_encoding='.urlencode($item->getMimeEncoding()).'&') : '').
 				'uri='.urlencode($item->getURI()));
@@ -49,10 +52,10 @@ class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend_HTTP {
 			'URL' => 'SoftKey:Select',
 			'Position' => $pos++));
 		foreach (MediaBrotha_Core::getBackends() as $backend) {
-			foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {
+			foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentMedia()) as $action) {
 				$this->_xml->setCiscoElement('SoftKeyItem',
 					Array('Name' => $action,
-					'URL' => 'QueryStringParam:'.MediaBrotha_Core::string2hash('action='.$action.'&backend='.$backend->getBackendName()),
+					'URL' => 'QueryStringParam:'.MediaBrotha_Core::value2hash('action='.$action.'&backend='.$backend->getBackendName()),
 					'Position' => $pos++));
 			}
 		}
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Media.php b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
index 6efd1db..7964473 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Media.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
@@ -25,14 +25,15 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Media {
-	private $_metadata = Array();
-
 	private $_URI = NULL;
+	private $_metadata = Array();
 	private $_mimeType = NULL;
 	private $_mimeEncoding = NULL;
 
+	private $_parent = NULL;
+
 	public function __construct($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
-		 $this->setURI($URI);
+		 $this->_URI = $URI;
 		 $this->setMetadata($metadata);
 		 $this->setMimeType($mime_type);
 		 $this->setMimeEncoding($mime_encoding);
@@ -42,16 +43,17 @@ class MediaBrotha_Media {
 	public function getURI() {
 		return $this->_URI;
 	}
-	public function setURI($URI) {
-		$this->_URI = $URI;
-	}
 
 	/* metadata */
-	public function getMetadata($name = NULL) {
+	public function getMetadata($name = NULL, $max_length = NULL) {
 		if ($name === NULL) {
 			return $this->_metadata;
 		} elseif (isset($this->_metadata[$name])) {
-			return $this->_metadata[$name];
+			if ($max_length) {
+				return substr($this->_metadata[$name], 0, $max_length);
+			} else {
+				return $this->_metadata[$name];
+			}
 		} else {
 			return NULL;
 		}
@@ -60,6 +62,17 @@ class MediaBrotha_Media {
 		if (is_array($name)) {
 			$this->_metadata = $name;
 		} else {
+			switch($name) {
+				case 'hidden':
+				case 'display_name':
+				case 'Array':
+				//music
+				case 'artist':
+				case 'album':
+					break;
+				default:
+					print "Unusual metadata '$name'.\n";
+			}
 			$this->_metadata[$name] = $value;
 
 		}
@@ -81,10 +94,22 @@ class MediaBrotha_Media {
 		$this->_mimeEncoding = $mime_encoding;
 	}
 
+	/* parent */
+	public function getParent() {
+		return $this->_parent;
+	}
+	public function setParent($parent) {
+		$this->_parent = $parent;
+	}
+
 	/* Most used metadata */
-	public function getDisplayName($max_length = 0) {
-		if ($name = $this->getMetadata('name')) {
-			return $name;
+	public function getDisplayName($max_length = NULL) {
+		if ($name = $this->getMetadata('display_name')) {
+			if ($max_length) {
+				return substr($name, 0, $max_length);
+			} else {
+				return $name;
+			}
 		} else {
 			return '?';
 		}
@@ -97,13 +122,3 @@ class MediaBrotha_Media {
 	}
 }
 
-/*
-
-Mandatory metadata:
-uri
-name
-
-Usual metadata:
-artist
-album
-*/
committer: Mathieu Parent
comments: 
MediaBrother: lot of changes
- Separate Backend from Iterator
- Reduce size of reply by using hashes in session
- ...

diff --git a/sathieu/cisco-xml/browser/index.php b/sathieu/cisco-xml/browser/index.php
index 1f0ae25..d142ff5 100644
--- a/sathieu/cisco-xml/browser/index.php
+++ b/sathieu/cisco-xml/browser/index.php
@@ -33,10 +33,26 @@ ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'../lib');
 require('Cisco-XML/Cisco-XML.php');
 require_once('MediaBrotha/Core.php');
 
+// Init
 MediaBrotha_Core::init();
 MediaBrotha_Core::connectFrontend('CiscoXML', Array('push_url' => 'http://cisco:cisco@192.168.0.220/CGI/Execute'));
+
+// Backends
 MediaBrotha_Core::loadBackend('FileSystem', Array('base_path' => '/home/share/music/'));
 MediaBrotha_Core::loadBackend('VLC', Array('http_intf' => 'http://127.0.0.1:8080'));
+$ldap_connect_config = Array(
+	'host' => '127.0.0.1',
+	//'binddn' => 'cn=nobody,cn=internal,dc=example,dc=org',
+	//'bindpw' => 'not24get',
+	'basedn' => 'dc=sathieu,dc=net',
+	'filter' => '(objectClass=*)',
+	'scope' => 'one',
+);
+MediaBrotha_Core::loadBackend('LDAP', Array('ldap_connect_config' => $ldap_connect_config));
+
+// Roots
+MediaBrotha_Core::addRootMedia('file:///home/share/music/', Array('name'=> 'Fichiers'));
+MediaBrotha_Core::addRootMedia('ldap:///', Array('name'=> 'Annuaire'));
 
 MediaBrotha_Core::go();
 
diff --git a/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php b/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
index 2253ca9..c711f9c 100644
--- a/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
+++ b/sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php
@@ -125,7 +125,10 @@ class CiscoXMLObject {
 			);
 
 		$context  = stream_context_create($opts);
-		return file_get_contents($url, false, $context);
+		$stream = fopen($url, 'r', false, $context);
+		if ($stream !== false) {
+			return stream_get_contents($stream);
+		}
 	}
 
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
index bb1fe8f..84a6a89 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
@@ -26,80 +26,56 @@ This file is part of MediaBrotha.
 
 require_once('MediaBrotha/Media.php');
 
-class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
-	protected $_buffer = Array();
-	public function __construct(array $args = Array()) {
-		parent::__construct($args);
+class MediaBrotha_Backend {
+	protected $_params = NULL;
+
+	public function __construct($params = NULL) {
+		$this->setParam($params);
 		$this->register();
-		$this->setMimeType('application/x-mediabrotha-backend-'.strtolower($this->getName()));
-		MediaBrotha_Core::registerMimeType($this, 'application/x-mediabrotha-backend-'.strtolower($this->getName()));
-		$this->setMetadata('name', $this->getName());
-		$this->setMetadata('uri', 'MediaBrotha_Backend://'.$this->getName());
 	}
 
-	public function register() {
-		MediaBrotha_Core::registerBackend($this);
+	/* params */
+	public function getParam($name = NULL) {
+		if ($name === NULL) {
+			return $this->_params;
+		} elseif (isset($this->_params[$name])) {
+			return $this->_params[$name];
+		} else {
+			return NULL;
+		}
 	}
+	public function setParam($name, $value = NULL) {
+		if (is_array($name)) {
+			$this->_params = $name;
+		} else {
+			$this->_params[$name] = $value;
 
-	public function getName() {
-		return preg_replace('/^MediaBrotha_Backend_(.*)$/', '$1', get_class($this));
+		}
 	}
 
-	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array();
+	public function register() {
+		MediaBrotha_Core::registerBackend($this);
 	}
 
-	public function isHidden() {
-		return parent::isHidden() || !in_array('browse', $this->capabilities());
+	public function getBackendName() {
+		return preg_replace('/^MediaBrotha_Backend_(.*)$/', '$1', get_class($this));
 	}
 
-	// Capability browse
-	protected function _mediaFromBufferItem($item) {
+	// Browsing
+	public function mediaFromBufferItem($item) {
 		return $item;
 	}
 
-	public function fetch($uri) {
+	public function fetch(MediaBrotha_Media $media) {
 		return false;
 	}
 
-	public function rewind() {
-		$this->_buffer->rewind();
-	}
-
-	public function current() {
-		return $this->_mediaFromBufferItem($this->_buffer->current());
-	}
-
-	public function key() {
-		return $this->_buffer->key();
-	}
-
-	public function next() {
-		return $this->_mediaFromBufferItem($this->_buffer->next());
-	}
-
-	public function valid() {
-		return $this->_buffer->valid();
+	// Actions
+	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		return Array();
 	}
 
-	// Capability play
-	public function play(MediaBrotha_Media $media) {
-		return false;
-	}
-	public function pause() {
-		return false;
-	}
-	public function stop() {
-		return false;
-	}
-	// Capability playlist
-	public function playlistEnqueue(MediaBrotha_Media $media) {
-		return false;
-	}
-	public function playlistNext(MediaBrotha_Media $media) {
-		return false;
-	}
-	public function playlistPrevious(MediaBrotha_Media $media) {
+	public function doMediaAction($action, MediaBrotha_Media $media) {
 		return false;
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
index 0dc8972..39928b4 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
@@ -25,14 +25,10 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
-	public function register() {
-		parent::register();
-		MediaBrotha_Core::registerMimeType($this, 'application/x-directory');
-	}
-
+	// Helper functions
 	public function isURISafe($uri) {
 		$real_path = realpath(parse_url($uri, PHP_URL_PATH));
-		$real_base_path = realpath($this->getMetadata('base_path'));
+		$real_base_path = realpath($this->getParam('base_path'));
 		do {
 			if ($real_path === $real_base_path) {
 				return true;
@@ -41,19 +37,16 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		return false;
 	}
 
-	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array(
-			'browse',
-		);
-	}
-	// Capability browse
-	protected function _mediaFromBufferItem($file) {
+	// Browsing
+	public function mediaFromBufferItem($file) {
 		if ($file) {
-			$media = new MediaBrotha_Media(Array(
-				'uri' => 'file://'.realpath($file->getPathname()),
-				'name' => $file->getFilename(),
-				'hidden' => !$file->isReadable() || preg_match('/^\.([^.]|$)/', $file->getFilename()),
-			));
+			$media = new MediaBrotha_Media(
+				'file://'.realpath($file->getPathname()),
+				Array(
+					'name' => $file->getFilename(),
+					'hidden' => !$file->isReadable() || preg_match('/^\.([^.]|$)/', $file->getFilename()),
+				)
+			);
 			if ($file->isDir()) {
 				$media->setMimeType('application/x-directory');
 			} else {
@@ -65,12 +58,34 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		}
 	}
 
-	public function fetch($uri) {
+	public function fetch(MediaBrotha_Media $media) {
+		$uri =$media->getURI();
 		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
 			$uri = 'file://'.$this->getMetadata('base_path');
 		}
-		$this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));
-		return true;
+		$path = parse_url($uri, PHP_URL_PATH);
+		if (is_dir($path)) {
+			return new MediaBrotha_MediaIterator($this, $media, new DirectoryIterator($path));
+		} else {
+			$this->setURI(NULL);
+			return false;
+		}
 	}
+
+	// Actions
+	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		if ($mime_type === 'application/x-directory') {
+			return Array(
+				'browse',
+			);
+		} elseif ($uri && (substr($uri, 0, 7) === 'file://')) {
+			return Array(
+				'browse',
+			);
+		} else {
+			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
+		}
+	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
index d275ff1..c882dd7 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
@@ -29,27 +29,16 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
 	private $_ldap;
 	public function __construct(array $args = Array()) {
 		parent::__construct($args);
-		$this->_ldap = Net_LDAP2::connect($this->getMetadata('ldap_connect_config'));
+		$this->_ldap = Net_LDAP2::connect($this->getParam('ldap_connect_config'));
 		if (Net_LDAP2::isError($this->_ldap)) {
 			die('Could not fetch entry: '.$this->_ldap->getMessage());
 		}
 	}
-	public function register() {
-		parent::register();
-		MediaBrotha_Core::registerMimeType($this, 'text/directory');
-	}
-
-	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array(
-			'browse',
-		);
-	}
-
+	// Helper functions
 	public function isURISafe($uri) {
 		return true;
 	}
-	
-	
+
 	public static function parseLDAPURI($uri, $component = NULL) {
 		$uri = preg_replace('@^ldap:///@', 'ldap://fake_host/', $uri);
 		$components = parse_url($uri, $component);
@@ -59,30 +48,50 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
 		return $components;
 	}
 
-	// Capability browse
-	public function fetch($uri) {
+	// Browsing
+	public function mediaFromBufferItem($entry) {
+		if ($entry) {
+			$media = new MediaBrotha_Media(
+				'ldap:///'.$entry->dn(),
+				Array(
+					'name' => $entry->dn(), //$entry->getValue('sn', 'single'),
+				),
+				'text/directory'
+				//$finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING);
+			);
+			return $media;
+		}
+	}
+
+	public function fetch(MediaBrotha_Media $media) {
+		$uri = $media->getURI();
 		if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != 'ldap') || !$this->isURISafe($uri)) {
-			$ldap_connect_config = $this->getMetadata('ldap_connect_config');
+			$ldap_connect_config = $this->getParam('ldap_connect_config');
 			$uri = 'ldap:///'.$ldap_connect_config['basedn'];
 		}
 		$basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);
 		if ($basedn && ($basedn{0} = '/')) {
-			$basedn = substr($basedn, 1);	
+			$basedn = substr($basedn, 1);
 		}
-		$this->_buffer = $this->_ldap->search($basedn, NULL,
+		$ldap_search = $this->_ldap->search($basedn, NULL,
 			Array());
+		return new MediaBrotha_MediaIterator($this, $media, $ldap_search);
 		return true;
 	}
-	protected function _mediaFromBufferItem($entry) {
-		if ($entry) {
-			$media = new MediaBrotha_Media(Array(
-				'uri' => 'ldap:///'.$entry->dn(),
-				'name' => $entry->dn(), //$entry->getValue('sn', 'single'),
-			));
-			$media->setMimeType('text/directory');
-			//	$media->setMimeEncoding($finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING));
-			return $media;
+	// Actions
+	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		if ($mime_type === 'text/directory') {
+			return Array(
+				'browse',
+			);
+		} elseif ($uri && (substr($uri, 0, 7) === 'ldap://')) {
+			return Array(
+				'browse',
+			);
+		} else {
+			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
 		}
 	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
index 5357cc3..addba42 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
@@ -25,22 +25,28 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
-	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array(
-			'browse',
-		);
+	private $_media = NULL;
+	private $_media_iterator = NULL;
+
+	public function __construct($params = NULL) {
+		parent::__construct($params);
+		$this->_media = new MediaBrotha_Media('MediaBrotha:///');
+		$this->_media_iterator = new MediaBrotha_MediaIterator($this, $this->_media);
+	}
+
+	public function addRootMedia($media) {
+		$this->_media_iterator->bufferAdd($media);
 	}
-	public function isHidden() {
-		return true;
+
+	// Browsing
+	public function fetch(MediaBrotha_Media $media) {
+		return $this->_media_iterator;
 	}
 
-	// Capability browse
-	public function fetch($uri) {
-		$this->_buffer = new ArrayIterator();
-		foreach(MediaBrotha_Core::getBackends() as $id => $backend) {
-			$this->_buffer[] = $backend;
-		}
-		return true;
+	// Actions
+	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		return Array(
+		);
 	}
 
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
index df10f93..2b4e7c6 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
@@ -25,20 +25,14 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
-	public function register() {
-		parent::register();
-		MediaBrotha_Core::registerMimeType($this, 'audio/mpeg');
-		MediaBrotha_Core::registerMimeType($this, 'video/x-msvideo');
-	}
+	static protected $_supported_mime_types = Array(
+		'audio/mpeg',
+		'video/x-msvideo',
+	);
 
-	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
-		return Array(
-			'play',
-			'playlist',
-		);
-	}
+	// Helper functions
 	private function send_command($command, array $args = Array()) {
-		$url = $this->getMetadata('http_intf').
+		$url = $this->getParam('http_intf').
 			'/requests/status.xml'.
 			'?command='.$command;
 		foreach ($args as $k => $v) {
@@ -49,31 +43,53 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 		print $output.'<!--'.$url."-->\n";
 	}
 
-	// Capability browse
-	public function fetch($uri) {
-		$this->_buffer[] = new MediaBrotha_Media();
+	// Browsing
+	public function fetch(MediaBrotha_Media $media) {
+		$this->_buffer[] = $media;
 		return true;
 	}
 
-	// Capability play
-	public function play(MediaBrotha_Media $media) {
-		return $this->send_command('in_play', Array('input' => $media->getURI()));
-	}
-	public function pause() {
-		return $this->send_command('pl_pause');
-	}
-	public function stop() {
-		return $this->send_command('pl_stop');
-	}
-	// Capability playlist
-	public function playlistEnqueue(MediaBrotha_Media $media) {
-		return $this->send_command('in_enqueue', Array('input' => $media->getURI()));
-	}
-	public function playlistNext(MediaBrotha_Media $media) {
-		return $this->send_command('pl_next');
+	// Actions
+	public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		if (in_array($mime_type, Array($this::$_supported_mime_types))) {
+			return Array(
+				'play_media',
+				'pause_media',
+				'stop_media',
+				'enqueue_media',
+				'next_media',
+				'previous_media',
+			);
+		} elseif ($uri && (substr($uri, 0, 7) === 'file://')) {
+			return Array(
+				'play_media',
+				'pause_media',
+				'stop_media',
+				'enqueue_media',
+				'next_media',
+				'previous_media',
+			);
+		} else {
+			return parent::getMediaActions($uri, $mime_type, $mime_encoding);
+		}
 	}
-	public function playlistPrevious(MediaBrotha_Media $media) {
-		return $this->send_command('pl_previous');
+	public function doMediaAction($action, MediaBrotha_Media $media) {
+		switch($action) {
+			case 'play_media':
+				return $this->send_command('in_play', Array('input' => $media->getURI()));
+			case 'pause_media':
+				return $this->send_command('pl_pause');
+			case 'stop_media':
+				return $this->send_command('pl_stop');
+			case 'enqueue_media':
+				return $this->send_command('in_enqueue', Array('input' => $media->getURI()));
+			case 'next_media':
+				return $this->send_command('pl_next');
+			case 'previous_media':
+				return $this->send_command('pl_previous');
+			default:
+				return parent::doMediaAction($action, $media);
+		}
 	}
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Core.php b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
index b3eaa84..5ec90e8 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Core.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
@@ -27,53 +27,80 @@ This file is part of MediaBrotha.
 require_once('MediaBrotha/Backend.php');
 require_once('MediaBrotha/Frontend.php');
 require_once('MediaBrotha/Media.php');
+require_once('MediaBrotha/MediaIterator.php');
 
 class MediaBrotha_Core {
 	private static $_frontend = NULL;
 	private static $_backends = Array();
-	private static $_mime_types = Array();
 	private static $_media = NULL;
 	
 	public static function init() {
+		if (!session_start()) {
+			die('Unable to start session');
+		}
+		if (!isset($_SESSION['HASHES'])) {
+			$_SESSION['HASHES'] = Array();
+		}
+		if (isset($_SERVER["QUERY_STRING"])) {
+			$tmp = explode('&', $_SERVER["QUERY_STRING"]);
+			foreach ($tmp as $h) {
+				if (preg_match('/^[a-z0-9]+$/', $h)) {
+					if ($s = MediaBrotha_Core::hash2string($h)) {
+						parse_str($s, $output);
+						$_GET = array_merge($_GET, $output);
+					}
+				}
+			}
+		}
 		MediaBrotha_Core::loadBackend('Root');
 	}
+
+	public static function hash2string($h) {
+		if (isset($_SESSION['HASHES'][$h])) {
+			return $_SESSION['HASHES'][$h];
+		} else {
+			//print 'NO string for hash '.$h;
+			return NULL;
+		}
+	}
+
+	public static function string2hash($s) {
+		for($hash_length = 1 ; $hash_length <=41 ; $hash_length++) {
+			$h = substr(sha1($s), 0, $hash_length);
+			if (!isset($_SESSION['HASHES'][$h]) || ($_SESSION['HASHES'][$h] === $s)) {
+				break;
+			}
+		}
+		$_SESSION['HASHES'][$h] = $s;
+		return $h;
+	}
+
 	public static function go() {
 		$current_backend = MediaBrotha_Core::getCurrentBackend();
-		switch(MediaBrotha_Core::getAction()) {
-			case 'play':
-				$current_backend->play(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'pause':
-				$current_backend->pause(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'stop':
-				$current_backend->stop(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'pl_enqueue':
-				$current_backend->playlistEnqueue(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'pl_next':
-				$current_backend->playlistNext(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'pl_previous':
-				$current_backend->playlistPrevious(MediaBrotha_Core::getCurrentMedia());
-				break;
-			case 'browse':
-			default:
-				$current_uri = MediaBrotha_Core::getCurrentURI();
-				$current_backend->fetch((string) $current_uri);
-				MediaBrotha_Core::$_frontend->begin($current_backend);
-				foreach($current_backend as $item) {
+		$current_media = MediaBrotha_Core::getCurrentMedia();
+		if (MediaBrotha_Core::getAction() == 'browse') {
+			if ($media_iterator = $current_backend->fetch($current_media)) {
+				MediaBrotha_Core::$_frontend->begin($current_media);
+				foreach ($media_iterator as $item) {
 					if ($item->isHidden()) {
 						continue;
 					}
 					MediaBrotha_Core::$_frontend->addItem($item);
 				}
-				MediaBrotha_Core::$_frontend->finish($current_backend);
-				MediaBrotha_Core::$_frontend->render();
+				MediaBrotha_Core::$_frontend->finish($current_media);
+				MediaBrotha_Core::$_frontend->render($current_media);
+			} else {
+			}
+		} else {
+			$current_backend->doMediaAction(MediaBrotha_Core::getAction(), $current_media);
 		}
 	}
 
+	public function addRootMedia($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
+		MediaBrotha_Core::$_backends['Root']->addRootMedia(
+			new MediaBrotha_Media($URI, $metadata, $mime_type,$mime_encoding)
+		);
+	}
 	/*
 	 * Backends
 	 */
@@ -85,20 +112,29 @@ class MediaBrotha_Core {
 		return new $class_name($args);
 	}
 	public static function registerBackend($backend) {
-		MediaBrotha_Core::$_backends[] = $backend;
+		MediaBrotha_Core::$_backends[$backend->getBackendName()] = $backend;
 	}
-	public static function registerMimeType($backend, $mime_type) {
-		MediaBrotha_Core::$_mime_types[$mime_type][] = $backend;
+	public static function getBackend($name) {
+		return MediaBrotha_Core::$_backends[$name];
 	}
 	public static function getBackends() {
 		return MediaBrotha_Core::$_backends;
 	}
 	public static function getCurrentBackend() {
-		if (!empty($_GET['mime_type']) && !empty(MediaBrotha_Core::$_mime_types[$_GET['mime_type']])) {
-			return MediaBrotha_Core::$_mime_types[$_GET['mime_type']][0];
-		} else {
-			return MediaBrotha_Core::$_backends[0];
+		if (!empty($_GET['backend']) && !empty(MediaBrotha_Core::$_backends[$_GET['backend']])) {
+			return MediaBrotha_Core::$_backends[$_GET['backend']];
+		}
+		foreach (MediaBrotha_Core::getBackends() as $backend) {
+			foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {
+				if ($backend->getBackendName() == 'Root') {
+					continue;
+				}
+				if ($action === MediaBrotha_Core::getAction()) {
+					return $backend;
+				}
+			}
 		}
+		return MediaBrotha_Core::$_backends['Root'];
 	}
 	/*
 	 * Frontend
@@ -132,8 +168,7 @@ class MediaBrotha_Core {
 	}
 	public static function getCurrentMedia() {
 		if (empty(MediaBrotha_Core::$_media)) {
-			MediaBrotha_Core::$_media = new MediaBrotha_Media();
-			MediaBrotha_Core::$_media->setURI(MediaBrotha_Core::getCurrentURI());
+			MediaBrotha_Core::$_media = new MediaBrotha_Media(MediaBrotha_Core::getCurrentURI());
 		}
 		return MediaBrotha_Core::$_media;
 	}
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
index 84ce7b7..2cc6060 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
@@ -26,9 +26,9 @@ This file is part of MediaBrotha.
 
 class MediaBrotha_Frontend {
 	protected $_infos = NULL;
+
 	public function __construct(array $args = Array()) {
 		$this->_infos = $args;
 	}
 }
 
-
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
index ce2f711..2baa6af 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/CiscoXML.php
@@ -24,44 +24,48 @@ This file is part of MediaBrotha.
  * @author Mathieu Parent
  */
 
-class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend {
+require_once('HTTP.php');
+
+class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend_HTTP {
 	private $_xml = NULL;
 	public function begin($item) {
 		$this->_xml = new CiscoIPPhoneMenu();
 		$this->_xml->setCiscoElement('Title', $item->getDisplayName());
-		//$this->_xml->setCiscoElement('Prompt', 'kk');
+		$this->_xml->setCiscoElement('Prompt', substr($item->getURI(), -32));
 	}
 	public function addItem($item) {
-		$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'?'.
-			'mime_type='.urlencode($item->getMimeType()).'&'.
-			($item->getMimeEncoding() ? ('mime_encoding='.urlencode($item->getMimeEncoding()).'&') : '').
-			'uri='.urlencode($item->getURI());
-		//$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
+		$url = $this->rootURL().'?'.
+			MediaBrotha_Core::string2hash(
+				'mime_type='.urlencode($item->getMimeType()).'&'.
+				($item->getMimeEncoding() ? ('mime_encoding='.urlencode($item->getMimeEncoding()).'&') : '').
+				'uri='.urlencode($item->getURI()));
 		$this->_xml->setCiscoElement('MenuItem',
 			Array('Name' => $item->getDisplayName(), 'URL' => $url));
 	}
-	public function finish() {
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Select', 'URL' => 'SoftKey:Select', 'Position' => '1'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Play', 'URL' => 'QueryStringParam:action=play', 'Position' => '2'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Pause', 'URL' => 'QueryStringParam:action=pause', 'Position' => '3'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Stop', 'URL' => 'QueryStringParam:action=stop', 'Position' => '4'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Enqueue', 'URL' => 'QueryStringParam:action=pl_enqueue', 'Position' => '5'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Next', 'URL' => 'QueryStringParam:action=pl_next', 'Position' => '6'));
-		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Previous', 'URL' => 'QueryStringParam:action=pl_previous', 'Position' => '7'));
+	public function finish($item) {
+		$pos = 1;
 		$this->_xml->setCiscoElement('SoftKeyItem',
-			Array('Name' => 'Quit', 'URL' => 'SoftKey:Exit', 'Position' => '8'));
+			Array('Name' => 'Select',
+			'URL' => 'SoftKey:Select',
+			'Position' => $pos++));
+		foreach (MediaBrotha_Core::getBackends() as $backend) {
+			foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {
+				$this->_xml->setCiscoElement('SoftKeyItem',
+					Array('Name' => $action,
+					'URL' => 'QueryStringParam:'.MediaBrotha_Core::string2hash('action='.$action.'&backend='.$backend->getBackendName()),
+					'Position' => $pos++));
+			}
+		}
 	}
 	public function render() {
-		CiscoXMLObject::HttpHeader();
-		print $this->_xml;
-		//$this->_xml->execute($this->_infos['push_url']);
+		if (true) {
+			CiscoXMLObject::HttpHeader();
+			print $this->_xml;
+			//print "\n<!--".strlen($this->_xml).'-->';
+		} else {
+			print strlen($this->_xml)."\n";
+			print $this->_xml->execute($this->_infos['push_url']);
+		}
 	}
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTTP.php
similarity index 77%
copy from sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
copy to sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTTP.php
index 84ce7b7..de19bf7 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTTP.php
@@ -24,11 +24,10 @@ This file is part of MediaBrotha.
  * @author Mathieu Parent
  */
 
-class MediaBrotha_Frontend {
-	protected $_infos = NULL;
-	public function __construct(array $args = Array()) {
-		$this->_infos = $args;
+class MediaBrotha_Frontend_HTTP extends MediaBrotha_Frontend {
+	public function rootURL() {
+		$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
+		$url = preg_replace('/index\.php$/', '', $url);
+		return $url;
 	}
 }
-
-
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Media.php b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
index cf3d66d..6efd1db 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Media.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
@@ -26,25 +26,27 @@ This file is part of MediaBrotha.
 
 class MediaBrotha_Media {
 	private $_metadata = Array();
+
+	private $_URI = NULL;
 	private $_mimeType = NULL;
 	private $_mimeEncoding = NULL;
-	public function __construct(array $metadata = Array()) {
-		 $this->_metadata = $metadata;
-	}
-	public function setMimeType($mime_type) {
-		$this->_mimeType = $mime_type;
-	}
-	public function getMimeType() {
-		// TODO
-		return $this->_mimeType;
+
+	public function __construct($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
+		 $this->setURI($URI);
+		 $this->setMetadata($metadata);
+		 $this->setMimeType($mime_type);
+		 $this->setMimeEncoding($mime_encoding);
 	}
-	public function setMimeEncoding($mime_encoding) {
-		$this->_mimeEncoding = $mime_encoding;
+
+	/* URI */
+	public function getURI() {
+		return $this->_URI;
 	}
-	public function getMimeEncoding() {
-		// TODO
-		return $this->_mimeEncoding;
+	public function setURI($URI) {
+		$this->_URI = $URI;
 	}
+
+	/* metadata */
 	public function getMetadata($name = NULL) {
 		if ($name === NULL) {
 			return $this->_metadata;
@@ -54,7 +56,7 @@ class MediaBrotha_Media {
 			return NULL;
 		}
 	}
-	public function setMetadata($name, $value) {
+	public function setMetadata($name, $value = NULL) {
 		if (is_array($name)) {
 			$this->_metadata = $name;
 		} else {
@@ -62,21 +64,36 @@ class MediaBrotha_Media {
 
 		}
 	}
-	/* Most used metadata */
-	public function getDisplayName($max_length = 0) {
-		return $this->getMetadata('name');
+
+	/* mimeType */
+	public function getMimeType() {
+		return $this->_mimeType;
 	}
-	public function getURI() {
-		return $this->getMetadata('uri');
+	public function setMimeType($mime_type) {
+		$this->_mimeType = $mime_type;
+	}
+
+	/* mimeEncoding */
+	public function getMimeEncoding() {
+		return $this->_mimeEncoding;
 	}
-	public function setURI($value) {
-		return $this->setMetadata('uri', $value);
+	public function setMimeEncoding($mime_encoding) {
+		$this->_mimeEncoding = $mime_encoding;
+	}
+
+	/* Most used metadata */
+	public function getDisplayName($max_length = 0) {
+		if ($name = $this->getMetadata('name')) {
+			return $name;
+		} else {
+			return '?';
+		}
 	}
 	public function getURIComponent($component) {
 		return parse_url($this->getURI($component));
 	}
 	public function isHidden() {
-		return isset($this->_metadata['hidden']) && $this->_metadata['hidden'];
+		return (bool) $this->getMetadata('hidden');
 	}
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php b/sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php
new file mode 100644
index 0000000..096759a
--- /dev/null
+++ b/sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php
@@ -0,0 +1,71 @@
+<?php
+/*
+Copyright 2011 Mathieu Parent <math.parent@gmail.com> 
+
+This file is part of MediaBrotha.
+
+	MediaBrotha is free software: you can
+	redistribute it and/or modify it under the terms of the GNU General
+	Public License as published by the Free Software Foundation, either
+	version 3 of the License, or (at your option) any later version.
+
+	MediaBrotha is distributed in the hope that it
+	will be useful, but WITHOUT ANY WARRANTY; without even the implied
+	warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+	the GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with MediaBrotha. If not, see
+	<http://www.gnu.org/licenses/>.
+
+*/
+
+/**
+ * @author Mathieu Parent
+ */
+
+require_once('MediaBrotha/Media.php');
+
+class MediaBrotha_MediaIterator implements Iterator {
+	private $_backend = NULL;
+	private $_media = NULL;
+	private $_handle = NULL;
+	protected $_buffer = NULL;
+
+	public function __construct(MediaBrotha_Backend $backend, MediaBrotha_Media $media, $buffer = NULL) {
+		$this->_backend = $backend;
+		$this->_media = $media;
+		if ($buffer) {
+			$this->_buffer = $buffer;
+		} else {
+			$this->_buffer = new ArrayIterator();
+		}
+	}
+
+	/* buffer */
+	public function bufferAdd($media) {
+		$this->_buffer[] = $media;
+	}
+
+	/* iterator */
+	public function rewind() {
+		$this->_buffer->rewind();
+	}
+
+	public function current() {
+		return $this->_backend->mediaFromBufferItem($this->_buffer->current());
+	}
+
+	public function key() {
+		return $this->_buffer->key();
+	}
+
+	public function next() {
+		return $this->_backend->mediaFromBufferItem($this->_buffer->next());
+	}
+
+	public function valid() {
+		return $this->_buffer->valid();
+	}
+}
+
committer: Mathieu Parent
comments: 
MediaBrotha: adding LDAP backend

diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
new file mode 100644
index 0000000..d275ff1
--- /dev/null
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
@@ -0,0 +1,88 @@
+<?php
+/*
+Copyright 2011 Mathieu Parent <math.parent@gmail.com> 
+
+This file is part of MediaBrotha.
+
+	MediaBrotha is free software: you can
+	redistribute it and/or modify it under the terms of the GNU General
+	Public License as published by the Free Software Foundation, either
+	version 3 of the License, or (at your option) any later version.
+
+	MediaBrotha is distributed in the hope that it
+	will be useful, but WITHOUT ANY WARRANTY; without even the implied
+	warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+	the GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with MediaBrotha. If not, see
+	<http://www.gnu.org/licenses/>.
+
+*/
+
+require_once('Net/LDAP2.php');
+/**
+ * @author Mathieu Parent
+ */
+
+class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
+	private $_ldap;
+	public function __construct(array $args = Array()) {
+		parent::__construct($args);
+		$this->_ldap = Net_LDAP2::connect($this->getMetadata('ldap_connect_config'));
+		if (Net_LDAP2::isError($this->_ldap)) {
+			die('Could not fetch entry: '.$this->_ldap->getMessage());
+		}
+	}
+	public function register() {
+		parent::register();
+		MediaBrotha_Core::registerMimeType($this, 'text/directory');
+	}
+
+	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+		return Array(
+			'browse',
+		);
+	}
+
+	public function isURISafe($uri) {
+		return true;
+	}
+	
+	
+	public static function parseLDAPURI($uri, $component = NULL) {
+		$uri = preg_replace('@^ldap:///@', 'ldap://fake_host/', $uri);
+		$components = parse_url($uri, $component);
+		if (is_array($components) && ($components['host'] === 'fake_host')) {
+			$components['host'] = NULL;
+		}
+		return $components;
+	}
+
+	// Capability browse
+	public function fetch($uri) {
+		if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != 'ldap') || !$this->isURISafe($uri)) {
+			$ldap_connect_config = $this->getMetadata('ldap_connect_config');
+			$uri = 'ldap:///'.$ldap_connect_config['basedn'];
+		}
+		$basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);
+		if ($basedn && ($basedn{0} = '/')) {
+			$basedn = substr($basedn, 1);	
+		}
+		$this->_buffer = $this->_ldap->search($basedn, NULL,
+			Array());
+		return true;
+	}
+	protected function _mediaFromBufferItem($entry) {
+		if ($entry) {
+			$media = new MediaBrotha_Media(Array(
+				'uri' => 'ldap:///'.$entry->dn(),
+				'name' => $entry->dn(), //$entry->getValue('sn', 'single'),
+			));
+			$media->setMimeType('text/directory');
+			//	$media->setMimeEncoding($finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING));
+			return $media;
+		}
+	}
+}
+
committer: Mathieu Parent
comments: 
MediaBrotha: Rewrite backend logic a bit
And:
- use type hinting
- MediaBrotha_Backend::_buffer is an Iterator

diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
index f85001b..bb1fe8f 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
@@ -28,7 +28,7 @@ require_once('MediaBrotha/Media.php');
 
 class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 	protected $_buffer = Array();
-	public function __construct($args = Array()) {
+	public function __construct(array $args = Array()) {
 		parent::__construct($args);
 		$this->register();
 		$this->setMimeType('application/x-mediabrotha-backend-'.strtolower($this->getName()));
@@ -54,34 +54,36 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 	}
 
 	// Capability browse
+	protected function _mediaFromBufferItem($item) {
+		return $item;
+	}
+
 	public function fetch($uri) {
 		return false;
 	}
 
 	public function rewind() {
-		reset($this->_buffer);
+		$this->_buffer->rewind();
 	}
 
 	public function current() {
-		return current($this->_buffer);
+		return $this->_mediaFromBufferItem($this->_buffer->current());
 	}
 
 	public function key() {
-		return key($this->_buffer);
+		return $this->_buffer->key();
 	}
 
 	public function next() {
-		return next($this->_buffer);
+		return $this->_mediaFromBufferItem($this->_buffer->next());
 	}
 
 	public function valid() {
-		$key = key($this->_buffer);
-		$var = ($key !== NULL && $key !== FALSE);
-		return $var;
+		return $this->_buffer->valid();
 	}
 
 	// Capability play
-	public function play($media) {
+	public function play(MediaBrotha_Media $media) {
 		return false;
 	}
 	public function pause() {
@@ -91,13 +93,13 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 		return false;
 	}
 	// Capability playlist
-	public function playlistEnqueue($media) {
+	public function playlistEnqueue(MediaBrotha_Media $media) {
 		return false;
 	}
-	public function playlistNext($media) {
+	public function playlistNext(MediaBrotha_Media $media) {
 		return false;
 	}
-	public function playlistPrevious($media) {
+	public function playlistPrevious(MediaBrotha_Media $media) {
 		return false;
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
index 62fcb6f..0dc8972 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
@@ -41,20 +41,13 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		return false;
 	}
 
-	public function fetch($uri) {
-		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
-			$uri = 'file://'.$this->getMetadata('base_path');
-		}
-		$this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'browse',
 		);
 	}
-	// Iterator
-	public function mediaFromFile($file) {
+	// Capability browse
+	protected function _mediaFromBufferItem($file) {
 		if ($file) {
 			$media = new MediaBrotha_Media(Array(
 				'uri' => 'file://'.realpath($file->getPathname()),
@@ -72,16 +65,12 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		}
 	}
 
-	public function current() {
-		return $this->mediaFromFile($this->_buffer->current());
-	}
-
-	public function next() {
-		return $this->mediaFromFile($this->_buffer->next());
-	}
-
-	public function valid() {
-		return $this->_buffer->valid();
+	public function fetch($uri) {
+		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
+			$uri = 'file://'.$this->getMetadata('base_path');
+		}
+		$this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));
+		return true;
 	}
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
index 5e9c5fb..5357cc3 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
@@ -25,13 +25,6 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
-	public function fetch($uri) {
-		$this->_buffer = Array();
-		foreach(MediaBrotha_Core::getBackends() as $id => $backend) {
-			$this->_buffer[] = $backend;
-		}
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'browse',
@@ -40,6 +33,16 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
 	public function isHidden() {
 		return true;
 	}
+
+	// Capability browse
+	public function fetch($uri) {
+		$this->_buffer = new ArrayIterator();
+		foreach(MediaBrotha_Core::getBackends() as $id => $backend) {
+			$this->_buffer[] = $backend;
+		}
+		return true;
+	}
+
 }
 
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
index 12cbff6..df10f93 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
@@ -31,28 +31,32 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 		MediaBrotha_Core::registerMimeType($this, 'video/x-msvideo');
 	}
 
-	public function fetch($uri) {
-		$this->_buffer[] = new MediaBrotha_Media();
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'play',
 			'playlist',
 		);
 	}
-	private function send_command($command, $args = Array()) {
+	private function send_command($command, array $args = Array()) {
 		$url = $this->getMetadata('http_intf').
 			'/requests/status.xml'.
 			'?command='.$command;
 		foreach ($args as $k => $v) {
 			$url.= '&'.$k.'='.rawurlencode($v);
 		}
-		return fopen($url, 'r');
+		$output = file_get_contents($url);
+		Header('Content-Type: text/xml');
+		print $output.'<!--'.$url."-->\n";
+	}
+
+	// Capability browse
+	public function fetch($uri) {
+		$this->_buffer[] = new MediaBrotha_Media();
+		return true;
 	}
 
 	// Capability play
-	public function play($media) {
+	public function play(MediaBrotha_Media $media) {
 		return $this->send_command('in_play', Array('input' => $media->getURI()));
 	}
 	public function pause() {
@@ -62,13 +66,13 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 		return $this->send_command('pl_stop');
 	}
 	// Capability playlist
-	public function playlistEnqueue($media) {
+	public function playlistEnqueue(MediaBrotha_Media $media) {
 		return $this->send_command('in_enqueue', Array('input' => $media->getURI()));
 	}
-	public function playlistNext($media) {
+	public function playlistNext(MediaBrotha_Media $media) {
 		return $this->send_command('pl_next');
 	}
-	public function playlistPrevious($media) {
+	public function playlistPrevious(MediaBrotha_Media $media) {
 		return $this->send_command('pl_previous');
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Core.php b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
index e31ee47..b3eaa84 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Core.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
@@ -60,7 +60,8 @@ class MediaBrotha_Core {
 				break;
 			case 'browse':
 			default:
-				$current_backend->fetch(MediaBrotha_Core::getCurrentURI());
+				$current_uri = MediaBrotha_Core::getCurrentURI();
+				$current_backend->fetch((string) $current_uri);
 				MediaBrotha_Core::$_frontend->begin($current_backend);
 				foreach($current_backend as $item) {
 					if ($item->isHidden()) {
@@ -126,7 +127,7 @@ class MediaBrotha_Core {
 
 	public static function getCurrentURI() {
 		if (!empty($_GET['uri'])) {
-			return $_GET['uri'];
+			return (string) $_GET['uri'];
 		}
 	}
 	public static function getCurrentMedia() {
@@ -136,5 +137,6 @@ class MediaBrotha_Core {
 		}
 		return MediaBrotha_Core::$_media;
 	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
index 9eab63c..84ce7b7 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
@@ -25,10 +25,8 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Frontend {
-	protected $_browser = NULL;
 	protected $_infos = NULL;
-	public function __construct($browser, $args = Array()) {
-		$this->_browser = $browser;
+	public function __construct(array $args = Array()) {
 		$this->_infos = $args;
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Media.php b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
index 0b50a52..cf3d66d 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Media.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
@@ -28,7 +28,7 @@ class MediaBrotha_Media {
 	private $_metadata = Array();
 	private $_mimeType = NULL;
 	private $_mimeEncoding = NULL;
-	public function __construct($metadata = Array()) {
+	public function __construct(array $metadata = Array()) {
 		 $this->_metadata = $metadata;
 	}
 	public function setMimeType($mime_type) {
@@ -63,7 +63,7 @@ class MediaBrotha_Media {
 		}
 	}
 	/* Most used metadata */
-	public function getDisplayName() {
+	public function getDisplayName($max_length = 0) {
 		return $this->getMetadata('name');
 	}
 	public function getURI() {
========================================================================

Summary of changes:
 sathieu/cisco-xml/browser/index.php                |   23 +++-
 sathieu/cisco-xml/browser/static/default.css       |   49 +++++++
 sathieu/cisco-xml/browser/static/dynamic.js        |    4 +
 sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php      |   11 ++-
 sathieu/cisco-xml/lib/MediaBrotha/Backend.php      |   89 +++++-------
 .../lib/MediaBrotha/Backend/FileSystem.php         |   85 +++++++----
 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php |   98 +++++++++++++
 sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php |   33 +++--
 sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php  |   84 +++++++-----
 sathieu/cisco-xml/lib/MediaBrotha/Core.php         |  147 ++++++++++++++------
 sathieu/cisco-xml/lib/MediaBrotha/Frontend.php     |    6 +-
 .../lib/MediaBrotha/Frontend/CiscoXML.php          |   61 +++++----
 .../cisco-xml/lib/MediaBrotha/Frontend/HTML.php    |  127 +++++++++++++++++
 .../{Frontend.php => Frontend/HTTP.php}            |   13 +-
 sathieu/cisco-xml/lib/MediaBrotha/Media.php        |  104 +++++++++-----
 .../cisco-xml/lib/MediaBrotha/MediaIterator.php    |   71 ++++++++++
 16 files changed, 751 insertions(+), 254 deletions(-)
 create mode 100644 sathieu/cisco-xml/browser/static/default.css
 create mode 100644 sathieu/cisco-xml/browser/static/dynamic.js
 create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
 create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
 copy sathieu/cisco-xml/lib/MediaBrotha/{Frontend.php => Frontend/HTTP.php} (77%)
 create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php

this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email
For more info, see http://blog.chomperstomp.com/?p=630 --
FreeSWITCH user-contributed scripts, etc