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

branch: master updated

       via: 69415c934e4b3dc70b22816aa847706336c442f5 (commit)
      from: 8b7b83f0a42fc7cce5deaacd1c3a56f76c392175 (commit)


= COMMIT LOG ===========================================================
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();
+	}
+}
+
========================================================================

Summary of changes:
 sathieu/cisco-xml/browser/index.php                |   16 +++
 sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php      |    5 +-
 sathieu/cisco-xml/lib/MediaBrotha/Backend.php      |   86 ++++++----------
 .../lib/MediaBrotha/Backend/FileSystem.php         |   57 +++++++----
 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php |   65 +++++++-----
 sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php |   32 ++++---
 sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php  |   82 +++++++++------
 sathieu/cisco-xml/lib/MediaBrotha/Core.php         |  109 +++++++++++++-------
 sathieu/cisco-xml/lib/MediaBrotha/Frontend.php     |    2 +-
 .../lib/MediaBrotha/Frontend/CiscoXML.php          |   56 ++++++-----
 .../{Frontend.php => Frontend/HTTP.php}            |   11 +-
 sathieu/cisco-xml/lib/MediaBrotha/Media.php        |   63 +++++++----
 .../cisco-xml/lib/MediaBrotha/MediaIterator.php    |   71 +++++++++++++
 13 files changed, 411 insertions(+), 244 deletions(-)
 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