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