<h1>Project "FreeSWITCH user-contributed scripts, etc" received a push.</h1>
<h2>branch: master updated</h2>
<pre>
via: 078d663ef932223e27db8166e074cc4f4542a339 (commit)
via: 7342c77d10810960f49fc5213db4a23dc203fd7a (commit)
via: 9ecdde39b5fb94c4708b530a7c90e82900ff15ed (commit)
via: 69415c934e4b3dc70b22816aa847706336c442f5 (commit)
via: 8b7b83f0a42fc7cce5deaacd1c3a56f76c392175 (commit)
via: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
from: 4bebf82901b579b38a58642bf4e409db912f33bb (commit)
</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Mitch Capper
comments:
Merge branch 'master' of ssh://git.freeswitch.org/freeswitch-contrib
</pre></div>
<div class="highlight"><pre>committer: Mathieu Parent
comments:
MediaBrotha: Add missing HTML files
<span style="color: #000080; font-weight: bold">diff --git a/sathieu/cisco-xml/browser/static/default.css b/sathieu/cisco-xml/browser/static/default.css</span>
new file mode 100644
<span style="color: #000080; font-weight: bold">index 0000000..6ef61fc</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/sathieu/cisco-xml/browser/static/default.css</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,49 @@</span>
<span style="color: #00A000">+/*</span>
<span style="color: #00A000">+ * body > ul#mediaListElement > li.mediaElement</span>
<span style="color: #00A000">+ */</span>
<span style="color: #00A000">+li.mediaElement {</span>
<span style="color: #00A000">+        padding: 2px;</span>
<span style="color: #00A000">+        margin: 0px;</span>
<span style="color: #00A000">+        list-style-type: none;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+li.mediaElement:nth-child(odd) {</span>
<span style="color: #00A000">+        background-color: #d1e3ed;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+/*</span>
<span style="color: #00A000">+ * body > ul#mediaListElement</span>
<span style="color: #00A000">+ */</span>
<span style="color: #00A000">+#mediaListElement {</span>
<span style="color: #00A000">+        padding: 2px;</span>
<span style="color: #00A000">+        margin: 0px;</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">+ * body > ul#mediaListElement > li.mediaElement > ul.mediaActionsListElement</span>
<span style="color: #00A000">+ */</span>
<span style="color: #00A000">+li.mediaElement .mediaActionsListElement {</span>
<span style="color: #00A000">+        padding: 2px;</span>
<span style="color: #00A000">+        margin: 0px;</span>
<span style="color: #00A000">+        margin-left: 20px;</span>
<span style="color: #00A000">+        list-style-type: none;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        -moz-transition-property: max-height, opacity, visibility;</span>
<span style="color: #00A000">+        -moz-transition-duration: 3s, 2s, 0.2s;</span>
<span style="color: #00A000">+        -moz-transition-delay: 0s, 1s, 1s;</span>
<span style="color: #00A000">+        max-height: 0px;</span>
<span style="color: #00A000">+        opacity: 0;</span>
<span style="color: #00A000">+        visibility: hidden;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+li.mediaElement:hover .mediaActionsListElement {</span>
<span style="color: #00A000">+        -moz-transition-property: max-height, opacity, visibility;</span>
<span style="color: #00A000">+        -moz-transition-duration: 0.5s, 2s, 0.2s;</span>
<span style="color: #00A000">+        -moz-transition-delay: 0.4s, 0.4s, 0.4s;</span>
<span style="color: #00A000">+        max-height: 200px;</span>
<span style="color: #00A000">+        opacity: 1;</span>
<span style="color: #00A000">+        visibility: visible;</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/browser/static/dynamic.js b/sathieu/cisco-xml/browser/static/dynamic.js</span>
new file mode 100644
<span style="color: #000080; font-weight: bold">index 0000000..721eb51</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/sathieu/cisco-xml/browser/static/dynamic.js</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,4 @@</span>
<span style="color: #00A000">+function bodyLoaded() {</span>
<span style="color: #00A000">+        //nothing yet</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/Frontend/HTML.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php</span>
new file mode 100644
<span style="color: #000080; font-weight: bold">index 0000000..6d09e1b</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,127 @@</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('HTTP.php');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+class MediaBrotha_Frontend_HTML extends MediaBrotha_Frontend_HTTP {</span>
<span style="color: #00A000">+        private $_xml = NULL;</span>
<span style="color: #00A000">+        private $_body = NULL;</span>
<span style="color: #00A000">+        private $_mediaListElement = NULL;</span>
<span style="color: #00A000">+        private $_actionsListElement = NULL;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        private function _mediaActionLinks($parent, $media, $tag_name) {</span>
<span style="color: #00A000">+                $url = $this->rootURL().'?'.</span>
<span style="color: #00A000">+                        MediaBrotha_Core::value2hash(</span>
<span style="color: #00A000">+                                'mime_type='.urlencode($media->getMimeType()).'&'.</span>
<span style="color: #00A000">+                                ($media->getMimeEncoding() ? ('mime_encoding='.urlencode($media->getMimeEncoding()).'&') : '').</span>
<span style="color: #00A000">+                                'uri='.urlencode($media->getURI()));</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                foreach (MediaBrotha_Core::getBackends() as $backend) {</span>
<span style="color: #00A000">+                        foreach ($backend->getMediaActions($media) as $action) {</span>
<span style="color: #00A000">+                                $tag = $this->_xml->createElement($tag_name);</span>
<span style="color: #00A000">+                                $tag = $parent->appendChild($tag);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                $a = $this->_xml->createElement('a');</span>
<span style="color: #00A000">+                                $a = $tag->appendChild($a);</span>
<span style="color: #00A000">+                                $a->setAttribute('href', "$url&".MediaBrotha_Core::value2hash('action='.$action.'&backend='.$backend->getBackendName()));</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                $text = $this->_xml->createTextNode($action);</span>
<span style="color: #00A000">+                                $text = $a->appendChild($text);</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">+        public function begin($item) {</span>
<span style="color: #00A000">+                $this->_xml = new DOMDocument('1.0');</span>
<span style="color: #00A000">+                $root = $this->_xml->createElement('html');</span>
<span style="color: #00A000">+                $root = $this->_xml->appendChild($root);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $head = $this->_xml->createElement('head');</span>
<span style="color: #00A000">+                $head = $root->appendChild($head);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $title = $this->_xml->createElement('title');</span>
<span style="color: #00A000">+                $title = $head->appendChild($title);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $text = $this->_xml->createTextNode($item->getDisplayName());</span>
<span style="color: #00A000">+                $text = $title->appendChild($text);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $style = $this->_xml->createElement('link');</span>
<span style="color: #00A000">+                $style = $head->appendChild($style);</span>
<span style="color: #00A000">+                $style->setAttribute('type', 'text/css');</span>
<span style="color: #00A000">+                $style->setAttribute('rel', 'stylesheet');</span>
<span style="color: #00A000">+                $style->setAttribute('href', $this->rootURL().'static/default.css');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $script = $this->_xml->createElement('script');</span>
<span style="color: #00A000">+                $script = $head->appendChild($script);</span>
<span style="color: #00A000">+                $script->setAttribute('type', 'text/javascript');</span>
<span style="color: #00A000">+                $script->setAttribute('src', $this->rootURL().'static/dynamic.js');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $this->_body = $this->_xml->createElement('body');</span>
<span style="color: #00A000">+                $this->_body = $root->appendChild($this->_body);</span>
<span style="color: #00A000">+                $this->_body->setAttribute('onload', 'bodyLoaded();');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $this->_mediaListElement = $this->_xml->createElement('ul');</span>
<span style="color: #00A000">+                $this->_mediaListElement = $this->_body->appendChild($this->_mediaListElement);</span>
<span style="color: #00A000">+                $this->_mediaListElement->setAttribute('id', 'mediaListElement');</span>
<span style="color: #00A000">+                if ($parent = $item->getParent()) {</span>
<span style="color: #00A000">+                        $this->addItem($parent);</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function addItem($item) {</span>
<span style="color: #00A000">+                $url = $this->rootURL().'?'.</span>
<span style="color: #00A000">+                        MediaBrotha_Core::value2hash(</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>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $li = $this->_xml->createElement('li');</span>
<span style="color: #00A000">+                $li = $this->_mediaListElement->appendChild($li);</span>
<span style="color: #00A000">+                $li->setAttribute('class', 'mediaElement');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $a = $this->_xml->createElement('a');</span>
<span style="color: #00A000">+                $a = $li->appendChild($a);</span>
<span style="color: #00A000">+                $a->setAttribute('href', $url);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $text = $this->_xml->createTextNode($item->getDisplayName());</span>
<span style="color: #00A000">+                $text = $a->appendChild($text);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $ul = $this->_xml->createElement('ul');</span>
<span style="color: #00A000">+                $ul = $li->appendChild($ul);</span>
<span style="color: #00A000">+                $ul->setAttribute('class', 'mediaActionsListElement');</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                $this->_mediaActionLinks($ul, $item, 'li');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function finish($item) {</span>
<span style="color: #00A000">+                $this->_actionsListElement = $this->_xml->createElement('ul');</span>
<span style="color: #00A000">+                $this->_actionsListElement = $this->_body->appendChild($this->_actionsListElement);</span>
<span style="color: #00A000">+                $this->_actionsListElement->setAttribute('id', 'actionsListElement');</span>
<span style="color: #00A000">+                $this->_mediaActionLinks($this->_actionsListElement, $item, 'li');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function render() {</span>
<span style="color: #00A000">+                print $this->_xml->saveHTML();</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
</pre></div>
<div class="highlight"><pre>committer: Mathieu Parent
comments:
MediaBrotha: various enhancements
<span style="color: #A00000">- add a HTML frontend</span>
<span style="color: #A00000">- frontend choosen automaticaly depending on browser</span>
<span style="color: #A00000">- handling of parent media</span>
<span style="color: #A00000">- max length for metadata and display_name</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 d142ff5..137b409 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">@@ -35,7 +35,11 @@ require_once('MediaBrotha/Core.php');</span>
// Init
MediaBrotha_Core::init();
<span style="color: #A00000">-MediaBrotha_Core::connectFrontend('CiscoXML', Array('push_url' => 'http://cisco:cisco@192.168.0.220/CGI/Execute'));</span>
<span style="color: #00A000">+if (CiscoIPPhone::userAgentIsCiscoIPPhone()) {</span>
<span style="color: #00A000">+        MediaBrotha_Core::connectFrontend('CiscoXML', Array('push_url' => 'http://cisco:cisco@192.168.0.220/CGI/Execute'));</span>
<span style="color: #00A000">+} else {</span>
<span style="color: #00A000">+        MediaBrotha_Core::connectFrontend('HTML');</span>
<span style="color: #00A000">+}</span>
// Backends
MediaBrotha_Core::loadBackend('FileSystem', Array('base_path' => '/home/share/music/'));
<span style="color: #800080; font-weight: bold">@@ -51,10 +55,9 @@ $ldap_connect_config = Array(</span>
MediaBrotha_Core::loadBackend('LDAP', Array('ldap_connect_config' => $ldap_connect_config));
// Roots
<span style="color: #A00000">-MediaBrotha_Core::addRootMedia('file:///home/share/music/', Array('name'=> 'Fichiers'));</span>
<span style="color: #A00000">-MediaBrotha_Core::addRootMedia('ldap:///', Array('name'=> 'Annuaire'));</span>
<span style="color: #00A000">+MediaBrotha_Core::addRootMedia('file:///home/share/music/', Array('display_name'=> 'Fichiers'));</span>
<span style="color: #00A000">+MediaBrotha_Core::addRootMedia('ldap:///', Array('display_name'=> 'Annuaire'));</span>
MediaBrotha_Core::go();
<span style="color: #A00000">-</span>
<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 c711f9c..216aad6 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">@@ -23,6 +23,12 @@ This file is part of XML services for Cisco IP Phones.</span>
/**
* @author Mathieu Parent
*/
<span style="color: #00A000">+class CiscoIPPhone {</span>
<span style="color: #00A000">+        static public function userAgentIsCiscoIPPhone() {</span>
<span style="color: #00A000">+                return preg_match('/^Allegro-Software-WebClient\//', $_SERVER['HTTP_USER_AGENT']);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+}</span>
class CiscoXMLField {
        private $_allowed_fields = NULL;
<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 84a6a89..28a8441 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">@@ -71,12 +71,17 @@ class MediaBrotha_Backend {</span>
        }
        // Actions
<span style="color: #A00000">-        public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #00A000">+        public function getMediaActions(MediaBrotha_Media $media) {</span>
                return Array();
        }
        public function doMediaAction($action, MediaBrotha_Media $media) {
                return false;
        }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Populate</span>
<span style="color: #00A000">+        public function populateMedia(MediaBrotha_Media $media) {</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/FileSystem.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php</span>
<span style="color: #000080; font-weight: bold">index 39928b4..006814b 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">@@ -40,10 +40,13 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {</span>
        // Browsing
        public function mediaFromBufferItem($file) {
                if ($file) {
<span style="color: #00A000">+                        if ($file->getFilename() === '..') {</span>
<span style="color: #00A000">+                                return NULL;</span>
<span style="color: #00A000">+                        }</span>
                        $media = new MediaBrotha_Media(
                                'file://'.realpath($file->getPathname()),
                                Array(
<span style="color: #A00000">-                                        'name' => $file->getFilename(),</span>
<span style="color: #00A000">+                                        'display_name' => $file->getFilename(),</span>
                                        'hidden' => !$file->isReadable() || preg_match('/^\.([^.]|$)/', $file->getFilename()),
                                )
                        );
<span style="color: #800080; font-weight: bold">@@ -59,31 +62,47 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {</span>
        }
        public function fetch(MediaBrotha_Media $media) {
<span style="color: #A00000">-                $uri =$media->getURI();</span>
<span style="color: #00A000">+                $uri = $media->getURI();</span>
                if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
<span style="color: #A00000">-                        $uri = 'file://'.$this->getMetadata('base_path');</span>
<span style="color: #00A000">+                        $uri = 'file://'.$this->getParam('base_path');</span>
                }
                $path = parse_url($uri, PHP_URL_PATH);
                if (is_dir($path)) {
                        return new MediaBrotha_MediaIterator($this, $media, new DirectoryIterator($path));
                } else {
<span style="color: #A00000">-                        $this->setURI(NULL);</span>
                        return false;
                }
        }
        // Actions
<span style="color: #A00000">-        public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #A00000">-                if ($mime_type === 'application/x-directory') {</span>
<span style="color: #A00000">-                        return Array(</span>
<span style="color: #A00000">-                                'browse',</span>
<span style="color: #A00000">-                        );</span>
<span style="color: #A00000">-                } elseif ($uri && (substr($uri, 0, 7) === 'file://')) {</span>
<span style="color: #00A000">+        protected function _isHandled(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                return ($media->getMimeType() === 'application/x-directory')</span>
<span style="color: #00A000">+                        || (substr($media->getURI(), 0, 7) === 'file://');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function getMediaActions(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                if ($this->_isHandled($media)) {</span>
                        return Array(
                                'browse',
                        );
                } else {
<span style="color: #A00000">-                        return parent::getMediaActions($uri, $mime_type, $mime_encoding);</span>
<span style="color: #00A000">+                        return parent::getMediaActions($media);</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Populate</span>
<span style="color: #00A000">+        public function populateMedia(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                if ($this->_isHandled($media)) {</span>
<span style="color: #00A000">+                        $parent_path = 'file://'.dirname(parse_url($media->getURI(), PHP_URL_PATH));</span>
<span style="color: #00A000">+                        if ($this->isURISafe($parent_path)) {</span>
<span style="color: #00A000">+                                $media->setParent(</span>
<span style="color: #00A000">+                                        new MediaBrotha_Media($parent_path,</span>
<span style="color: #00A000">+                                                Array(</span>
<span style="color: #00A000">+                                                        'display_name' => '..',</span>
<span style="color: #00A000">+                                                )</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 c882dd7..365e78e 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">@@ -54,7 +54,7 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
                        $media = new MediaBrotha_Media(
                                'ldap:///'.$entry->dn(),
                                Array(
<span style="color: #A00000">-                                        'name' => $entry->dn(), //$entry->getValue('sn', 'single'),</span>
<span style="color: #00A000">+                                        'display_name' => $entry->dn(), //$entry->getValue('sn', 'single'),</span>
                                ),
                                'text/directory'
                                //$finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING);
<span style="color: #800080; font-weight: bold">@@ -79,17 +79,18 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
                return true;
        }
        // Actions
<span style="color: #A00000">-        public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #A00000">-                if ($mime_type === 'text/directory') {</span>
<span style="color: #A00000">-                        return Array(</span>
<span style="color: #A00000">-                                'browse',</span>
<span style="color: #A00000">-                        );</span>
<span style="color: #A00000">-                } elseif ($uri && (substr($uri, 0, 7) === 'ldap://')) {</span>
<span style="color: #00A000">+        protected function _isHandled(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                return ($media->getMimeType() === 'text/directory')</span>
<span style="color: #00A000">+                        || (substr($media->getURI(), 0, 7) === 'ldap://');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function getMediaActions(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                if ($this->_isHandled($media)) {</span>
                        return Array(
                                'browse',
                        );
                } else {
<span style="color: #A00000">-                        return parent::getMediaActions($uri, $mime_type, $mime_encoding);</span>
<span style="color: #00A000">+                        return parent::getMediaActions($media);</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 addba42..9616be8 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">@@ -30,11 +30,18 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {</span>
        public function __construct($params = NULL) {
                parent::__construct($params);
<span style="color: #A00000">-                $this->_media = new MediaBrotha_Media('MediaBrotha:///');</span>
<span style="color: #00A000">+                $this->_media = new MediaBrotha_Media('MediaBrotha:///',</span>
<span style="color: #00A000">+                        Array(</span>
<span style="color: #00A000">+                                'display_name' => 'Root',</span>
<span style="color: #00A000">+                        )</span>
<span style="color: #00A000">+                );</span>
                $this->_media_iterator = new MediaBrotha_MediaIterator($this, $this->_media);
        }
<span style="color: #A00000">-        public function addRootMedia($media) {</span>
<span style="color: #00A000">+        public function addRootMedia($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #00A000">+                $this->addRootMediaObj(new MediaBrotha_Media($URI, $metadata, $mime_type,$mime_encoding));</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function addRootMediaObj($media) {</span>
                $this->_media_iterator->bufferAdd($media);
        }
<span style="color: #800080; font-weight: bold">@@ -42,13 +49,6 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {</span>
        public function fetch(MediaBrotha_Media $media) {
                return $this->_media_iterator;
        }
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        // Actions</span>
<span style="color: #A00000">-        public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #A00000">-                return Array(</span>
<span style="color: #A00000">-                );</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/Backend/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php</span>
<span style="color: #000080; font-weight: bold">index 2b4e7c6..8c3208e 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">@@ -50,17 +50,13 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {</span>
        }
        // Actions
<span style="color: #A00000">-        public function getMediaActions($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #A00000">-                if (in_array($mime_type, Array($this::$_supported_mime_types))) {</span>
<span style="color: #A00000">-                        return Array(</span>
<span style="color: #A00000">-                                'play_media',</span>
<span style="color: #A00000">-                                'pause_media',</span>
<span style="color: #A00000">-                                'stop_media',</span>
<span style="color: #A00000">-                                'enqueue_media',</span>
<span style="color: #A00000">-                                'next_media',</span>
<span style="color: #A00000">-                                'previous_media',</span>
<span style="color: #A00000">-                        );</span>
<span style="color: #A00000">-                } elseif ($uri && (substr($uri, 0, 7) === 'file://')) {</span>
<span style="color: #00A000">+        protected function _isHandled(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                return in_array($media->getMimeType(), Array($this::$_supported_mime_types))</span>
<span style="color: #00A000">+                        || (substr($media->getURI(), 0, 7) === 'file://');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function getMediaActions(MediaBrotha_Media $media) {</span>
<span style="color: #00A000">+                if ($this->_isHandled($media)) {</span>
                        return Array(
                                'play_media',
                                'pause_media',
<span style="color: #800080; font-weight: bold">@@ -70,7 +66,7 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {</span>
                                'previous_media',
                        );
                } else {
<span style="color: #A00000">-                        return parent::getMediaActions($uri, $mime_type, $mime_encoding);</span>
<span style="color: #00A000">+                        return parent::getMediaActions($media);</span>
                }
        }
        public function doMediaAction($action, MediaBrotha_Media $media) {
<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 5ec90e8..8997a7c 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">@@ -34,47 +34,17 @@ class MediaBrotha_Core {</span>
        private static $_backends = Array();
        private static $_media = NULL;
        
<span style="color: #00A000">+        /*</span>
<span style="color: #00A000">+         * Core</span>
<span style="color: #00A000">+         */</span>
        public static function init() {
                if (!session_start()) {
                        die('Unable to start session');
                }
<span style="color: #A00000">-                if (!isset($_SESSION['HASHES'])) {</span>
<span style="color: #A00000">-                        $_SESSION['HASHES'] = Array();</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                if (isset($_SERVER["QUERY_STRING"])) {</span>
<span style="color: #A00000">-                        $tmp = explode('&', $_SERVER["QUERY_STRING"]);</span>
<span style="color: #A00000">-                        foreach ($tmp as $h) {</span>
<span style="color: #A00000">-                                if (preg_match('/^[a-z0-9]+$/', $h)) {</span>
<span style="color: #A00000">-                                        if ($s = MediaBrotha_Core::hash2string($h)) {</span>
<span style="color: #A00000">-                                                parse_str($s, $output);</span>
<span style="color: #A00000">-                                                $_GET = array_merge($_GET, $output);</span>
<span style="color: #A00000">-                                        }</span>
<span style="color: #A00000">-                                }</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                }</span>
<span style="color: #00A000">+                MediaBrotha_Core::_unhashRequest();</span>
                MediaBrotha_Core::loadBackend('Root');
        }
<span style="color: #A00000">-        public static function hash2string($h) {</span>
<span style="color: #A00000">-                if (isset($_SESSION['HASHES'][$h])) {</span>
<span style="color: #A00000">-                        return $_SESSION['HASHES'][$h];</span>
<span style="color: #A00000">-                } else {</span>
<span style="color: #A00000">-                        //print 'NO string for hash '.$h;</span>
<span style="color: #A00000">-                        return NULL;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        public static function string2hash($s) {</span>
<span style="color: #A00000">-                for($hash_length = 1 ; $hash_length <=41 ; $hash_length++) {</span>
<span style="color: #A00000">-                        $h = substr(sha1($s), 0, $hash_length);</span>
<span style="color: #A00000">-                        if (!isset($_SESSION['HASHES'][$h]) || ($_SESSION['HASHES'][$h] === $s)) {</span>
<span style="color: #A00000">-                                break;</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                $_SESSION['HASHES'][$h] = $s;</span>
<span style="color: #A00000">-                return $h;</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
        public static function go() {
                $current_backend = MediaBrotha_Core::getCurrentBackend();
                $current_media = MediaBrotha_Core::getCurrentMedia();
<span style="color: #800080; font-weight: bold">@@ -82,7 +52,7 @@ class MediaBrotha_Core {</span>
                        if ($media_iterator = $current_backend->fetch($current_media)) {
                                MediaBrotha_Core::$_frontend->begin($current_media);
                                foreach ($media_iterator as $item) {
<span style="color: #A00000">-                                        if ($item->isHidden()) {</span>
<span style="color: #00A000">+                                        if (($item === NULL) || $item->isHidden()) {</span>
                                                continue;
                                        }
                                        MediaBrotha_Core::$_frontend->addItem($item);
<span style="color: #800080; font-weight: bold">@@ -97,10 +67,9 @@ class MediaBrotha_Core {</span>
        }
        public function addRootMedia($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
<span style="color: #A00000">-                MediaBrotha_Core::$_backends['Root']->addRootMedia(</span>
<span style="color: #A00000">-                        new MediaBrotha_Media($URI, $metadata, $mime_type,$mime_encoding)</span>
<span style="color: #A00000">-                );</span>
<span style="color: #00A000">+                MediaBrotha_Core::$_backends['Root']->addRootMedia($URI, $metadata, $mime_type, $mime_encoding);</span>
        }
<span style="color: #00A000">+</span>
        /*
         * Backends
         */
<span style="color: #800080; font-weight: bold">@@ -120,22 +89,7 @@ class MediaBrotha_Core {</span>
        public static function getBackends() {
                return MediaBrotha_Core::$_backends;
        }
<span style="color: #A00000">-        public static function getCurrentBackend() {</span>
<span style="color: #A00000">-                if (!empty($_GET['backend']) && !empty(MediaBrotha_Core::$_backends[$_GET['backend']])) {</span>
<span style="color: #A00000">-                        return MediaBrotha_Core::$_backends[$_GET['backend']];</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                foreach (MediaBrotha_Core::getBackends() as $backend) {</span>
<span style="color: #A00000">-                        foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {</span>
<span style="color: #A00000">-                                if ($backend->getBackendName() == 'Root') {</span>
<span style="color: #A00000">-                                        continue;</span>
<span style="color: #A00000">-                                }</span>
<span style="color: #A00000">-                                if ($action === MediaBrotha_Core::getAction()) {</span>
<span style="color: #A00000">-                                        return $backend;</span>
<span style="color: #A00000">-                                }</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                return MediaBrotha_Core::$_backends['Root'];</span>
<span style="color: #A00000">-        }</span>
<span style="color: #00A000">+</span>
        /*
         * Frontend
         */
<span style="color: #800080; font-weight: bold">@@ -151,8 +105,26 @@ class MediaBrotha_Core {</span>
                MediaBrotha_Core::$_frontend = new $class_name($args);
        }
        /*
<span style="color: #A00000">-         * ...</span>
<span style="color: #00A000">+         * Current *</span>
         */
<span style="color: #00A000">+        public static function getCurrentBackend() {</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">+                $current_media = MediaBrotha_Core::getCurrentMedia();</span>
<span style="color: #00A000">+                foreach (MediaBrotha_Core::getBackends() as $backend) {</span>
<span style="color: #00A000">+                        foreach ($backend->getMediaActions($current_media) 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">+                }</span>
<span style="color: #00A000">+                return MediaBrotha_Core::$_backends['Root'];</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
        public static function getAction() {
                if (!empty($_GET['action'])) {
                        return $_GET['action'];
<span style="color: #800080; font-weight: bold">@@ -161,17 +133,63 @@ class MediaBrotha_Core {</span>
                }
        }
<span style="color: #A00000">-        public static function getCurrentURI() {</span>
<span style="color: #A00000">-                if (!empty($_GET['uri'])) {</span>
<span style="color: #A00000">-                        return (string) $_GET['uri'];</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
        public static function getCurrentMedia() {
                if (empty(MediaBrotha_Core::$_media)) {
<span style="color: #A00000">-                        MediaBrotha_Core::$_media = new MediaBrotha_Media(MediaBrotha_Core::getCurrentURI());</span>
<span style="color: #00A000">+                        if (!empty($_GET['uri'])) {</span>
<span style="color: #00A000">+                                MediaBrotha_Core::$_media = new MediaBrotha_Media($_GET['uri']);</span>
<span style="color: #00A000">+                        } else {</span>
<span style="color: #00A000">+                                MediaBrotha_Core::$_media = new MediaBrotha_Media('MediaBrotha:///');</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                        foreach (MediaBrotha_Core::getBackends() as $backend) {</span>
<span style="color: #00A000">+                                $backend->populateMedia(MediaBrotha_Core::$_media);</span>
<span style="color: #00A000">+                        }</span>
                }
                return MediaBrotha_Core::$_media;
        }
<span style="color: #00A000">+        /*</span>
<span style="color: #00A000">+         * helper functions</span>
<span style="color: #00A000">+         */</span>
<span style="color: #00A000">+        /* hashes */</span>
<span style="color: #00A000">+        public static function hash2value($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">+                        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 value2hash($v) {</span>
<span style="color: #00A000">+                for($hash_length = 1 ; $hash_length <=41 ; $hash_length++) {</span>
<span style="color: #00A000">+                        $h = substr(sha1($v), 0, $hash_length);</span>
<span style="color: #00A000">+                        if (!isset($_SESSION['HASHES'][$h]) || ($_SESSION['HASHES'][$h] === $v)) {</span>
<span style="color: #00A000">+                                break;</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $_SESSION['HASHES'][$h] = $v;</span>
<span style="color: #00A000">+                return $h;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public static function hash2array($h) {</span>
<span style="color: #00A000">+                if ($v = MediaBrotha_Core::hash2value($h)) {</span>
<span style="color: #00A000">+                        parse_str($v, $output);</span>
<span style="color: #00A000">+                        return $output;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        private static function _unhashRequest() {</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">+                                        $_GET = array_merge($_GET, MediaBrotha_Core::hash2array($h));</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">+</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 2baa6af..914e6ee 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">@@ -30,12 +30,15 @@ class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend_HTTP {</span>
        private $_xml = NULL;
        public function begin($item) {
                $this->_xml = new CiscoIPPhoneMenu();
<span style="color: #A00000">-                $this->_xml->setCiscoElement('Title', $item->getDisplayName());</span>
<span style="color: #00A000">+                $this->_xml->setCiscoElement('Title', $item->getDisplayName(32));</span>
                $this->_xml->setCiscoElement('Prompt', substr($item->getURI(), -32));
<span style="color: #00A000">+                if ($parent = $item->getParent()) {</span>
<span style="color: #00A000">+                        $this->addItem($parent);</span>
<span style="color: #00A000">+                }</span>
        }
        public function addItem($item) {
                $url = $this->rootURL().'?'.
<span style="color: #A00000">-                        MediaBrotha_Core::string2hash(</span>
<span style="color: #00A000">+                        MediaBrotha_Core::value2hash(</span>
                                'mime_type='.urlencode($item->getMimeType()).'&'.
                                ($item->getMimeEncoding() ? ('mime_encoding='.urlencode($item->getMimeEncoding()).'&') : '').
                                'uri='.urlencode($item->getURI()));
<span style="color: #800080; font-weight: bold">@@ -49,10 +52,10 @@ class MediaBrotha_Frontend_CiscoXML extends MediaBrotha_Frontend_HTTP {</span>
                        'URL' => 'SoftKey:Select',
                        'Position' => $pos++));
                foreach (MediaBrotha_Core::getBackends() as $backend) {
<span style="color: #A00000">-                        foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentURI()) as $action) {</span>
<span style="color: #00A000">+                        foreach ($backend->getMediaActions(MediaBrotha_Core::getCurrentMedia()) as $action) {</span>
                                $this->_xml->setCiscoElement('SoftKeyItem',
                                        Array('Name' => $action,
<span style="color: #A00000">-                                        'URL' => 'QueryStringParam:'.MediaBrotha_Core::string2hash('action='.$action.'&backend='.$backend->getBackendName()),</span>
<span style="color: #00A000">+                                        'URL' => 'QueryStringParam:'.MediaBrotha_Core::value2hash('action='.$action.'&backend='.$backend->getBackendName()),</span>
                                        'Position' => $pos++));
                        }
                }
<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 6efd1db..7964473 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">@@ -25,14 +25,15 @@ This file is part of MediaBrotha.</span>
*/
class MediaBrotha_Media {
<span style="color: #A00000">-        private $_metadata = Array();</span>
<span style="color: #A00000">-</span>
        private $_URI = NULL;
<span style="color: #00A000">+        private $_metadata = Array();</span>
        private $_mimeType = NULL;
        private $_mimeEncoding = NULL;
<span style="color: #00A000">+        private $_parent = NULL;</span>
<span style="color: #00A000">+</span>
        public function __construct($URI, array $metadata = Array(), $mime_type = NULL, $mime_encoding = NULL) {
<span style="color: #A00000">-                 $this->setURI($URI);</span>
<span style="color: #00A000">+                 $this->_URI = $URI;</span>
                 $this->setMetadata($metadata);
                 $this->setMimeType($mime_type);
                 $this->setMimeEncoding($mime_encoding);
<span style="color: #800080; font-weight: bold">@@ -42,16 +43,17 @@ class MediaBrotha_Media {</span>
        public function getURI() {
                return $this->_URI;
        }
<span style="color: #A00000">-        public function setURI($URI) {</span>
<span style="color: #A00000">-                $this->_URI = $URI;</span>
<span style="color: #A00000">-        }</span>
        /* metadata */
<span style="color: #A00000">-        public function getMetadata($name = NULL) {</span>
<span style="color: #00A000">+        public function getMetadata($name = NULL, $max_length = NULL) {</span>
                if ($name === NULL) {
                        return $this->_metadata;
                } elseif (isset($this->_metadata[$name])) {
<span style="color: #A00000">-                        return $this->_metadata[$name];</span>
<span style="color: #00A000">+                        if ($max_length) {</span>
<span style="color: #00A000">+                                return substr($this->_metadata[$name], 0, $max_length);</span>
<span style="color: #00A000">+                        } else {</span>
<span style="color: #00A000">+                                return $this->_metadata[$name];</span>
<span style="color: #00A000">+                        }</span>
                } else {
                        return NULL;
                }
<span style="color: #800080; font-weight: bold">@@ -60,6 +62,17 @@ class MediaBrotha_Media {</span>
                if (is_array($name)) {
                        $this->_metadata = $name;
                } else {
<span style="color: #00A000">+                        switch($name) {</span>
<span style="color: #00A000">+                                case 'hidden':</span>
<span style="color: #00A000">+                                case 'display_name':</span>
<span style="color: #00A000">+                                case 'Array':</span>
<span style="color: #00A000">+                                //music</span>
<span style="color: #00A000">+                                case 'artist':</span>
<span style="color: #00A000">+                                case 'album':</span>
<span style="color: #00A000">+                                        break;</span>
<span style="color: #00A000">+                                default:</span>
<span style="color: #00A000">+                                        print "Unusual metadata '$name'.\n";</span>
<span style="color: #00A000">+                        }</span>
                        $this->_metadata[$name] = $value;
                }
<span style="color: #800080; font-weight: bold">@@ -81,10 +94,22 @@ class MediaBrotha_Media {</span>
                $this->_mimeEncoding = $mime_encoding;
        }
<span style="color: #00A000">+        /* parent */</span>
<span style="color: #00A000">+        public function getParent() {</span>
<span style="color: #00A000">+                return $this->_parent;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function setParent($parent) {</span>
<span style="color: #00A000">+                $this->_parent = $parent;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
        /* Most used metadata */
<span style="color: #A00000">-        public function getDisplayName($max_length = 0) {</span>
<span style="color: #A00000">-                if ($name = $this->getMetadata('name')) {</span>
<span style="color: #A00000">-                        return $name;</span>
<span style="color: #00A000">+        public function getDisplayName($max_length = NULL) {</span>
<span style="color: #00A000">+                if ($name = $this->getMetadata('display_name')) {</span>
<span style="color: #00A000">+                        if ($max_length) {</span>
<span style="color: #00A000">+                                return substr($name, 0, $max_length);</span>
<span style="color: #00A000">+                        } else {</span>
<span style="color: #00A000">+                                return $name;</span>
<span style="color: #00A000">+                        }</span>
                } else {
                        return '?';
                }
<span style="color: #800080; font-weight: bold">@@ -97,13 +122,3 @@ class MediaBrotha_Media {</span>
        }
}
<span style="color: #A00000">-/*</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-Mandatory metadata:</span>
<span style="color: #A00000">-uri</span>
<span style="color: #A00000">-name</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-Usual metadata:</span>
<span style="color: #A00000">-artist</span>
<span style="color: #A00000">-album</span>
<span style="color: #A00000">-*/</span>
</pre></div>
<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>
<div class="highlight"><pre>committer: Mathieu Parent
comments:
MediaBrotha: adding LDAP backend
<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>
new file mode 100644
<span style="color: #000080; font-weight: bold">index 0000000..d275ff1</span>
<span style="color: #A00000">--- /dev/null</span>
<span style="color: #00A000">+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php</span>
<span style="color: #800080; font-weight: bold">@@ -0,0 +1,88 @@</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">+require_once('Net/LDAP2.php');</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">+class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
<span style="color: #00A000">+        private $_ldap;</span>
<span style="color: #00A000">+        public function __construct(array $args = Array()) {</span>
<span style="color: #00A000">+                parent::__construct($args);</span>
<span style="color: #00A000">+                $this->_ldap = Net_LDAP2::connect($this->getMetadata('ldap_connect_config'));</span>
<span style="color: #00A000">+                if (Net_LDAP2::isError($this->_ldap)) {</span>
<span style="color: #00A000">+                        die('Could not fetch entry: '.$this->_ldap->getMessage());</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        public function register() {</span>
<span style="color: #00A000">+                parent::register();</span>
<span style="color: #00A000">+                MediaBrotha_Core::registerMimeType($this, 'text/directory');</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {</span>
<span style="color: #00A000">+                return Array(</span>
<span style="color: #00A000">+                        'browse',</span>
<span style="color: #00A000">+                );</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        public function isURISafe($uri) {</span>
<span style="color: #00A000">+                return true;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        public static function parseLDAPURI($uri, $component = NULL) {</span>
<span style="color: #00A000">+                $uri = preg_replace('@^ldap:///@', 'ldap://fake_host/', $uri);</span>
<span style="color: #00A000">+                $components = parse_url($uri, $component);</span>
<span style="color: #00A000">+                if (is_array($components) && ($components['host'] === 'fake_host')) {</span>
<span style="color: #00A000">+                        $components['host'] = NULL;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                return $components;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Capability browse</span>
<span style="color: #00A000">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != 'ldap') || !$this->isURISafe($uri)) {</span>
<span style="color: #00A000">+                        $ldap_connect_config = $this->getMetadata('ldap_connect_config');</span>
<span style="color: #00A000">+                        $uri = 'ldap:///'.$ldap_connect_config['basedn'];</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);</span>
<span style="color: #00A000">+                if ($basedn && ($basedn{0} = '/')) {</span>
<span style="color: #00A000">+                        $basedn = substr($basedn, 1);        </span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $this->_buffer = $this->_ldap->search($basedn, NULL,</span>
<span style="color: #00A000">+                        Array());</span>
<span style="color: #00A000">+                return true;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        protected function _mediaFromBufferItem($entry) {</span>
<span style="color: #00A000">+                if ($entry) {</span>
<span style="color: #00A000">+                        $media = new MediaBrotha_Media(Array(</span>
<span style="color: #00A000">+                                'uri' => 'ldap:///'.$entry->dn(),</span>
<span style="color: #00A000">+                                'name' => $entry->dn(), //$entry->getValue('sn', 'single'),</span>
<span style="color: #00A000">+                        ));</span>
<span style="color: #00A000">+                        $media->setMimeType('text/directory');</span>
<span style="color: #00A000">+                        //        $media->setMimeEncoding($finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING));</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">+</span>
</pre></div>
<div class="highlight"><pre>committer: Mathieu Parent
comments:
MediaBrotha: Rewrite backend logic a bit
And:
<span style="color: #A00000">- use type hinting</span>
<span style="color: #A00000">- MediaBrotha_Backend::_buffer is an Iterator</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 f85001b..bb1fe8f 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">@@ -28,7 +28,7 @@ require_once('MediaBrotha/Media.php');</span>
class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
        protected $_buffer = Array();
<span style="color: #A00000">-        public function __construct($args = Array()) {</span>
<span style="color: #00A000">+        public function __construct(array $args = Array()) {</span>
                parent::__construct($args);
                $this->register();
                $this->setMimeType('application/x-mediabrotha-backend-'.strtolower($this->getName()));
<span style="color: #800080; font-weight: bold">@@ -54,34 +54,36 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {</span>
        }
        // Capability browse
<span style="color: #00A000">+        protected function _mediaFromBufferItem($item) {</span>
<span style="color: #00A000">+                return $item;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
        public function fetch($uri) {
                return false;
        }
        public function rewind() {
<span style="color: #A00000">-                reset($this->_buffer);</span>
<span style="color: #00A000">+                $this->_buffer->rewind();</span>
        }
        public function current() {
<span style="color: #A00000">-                return current($this->_buffer);</span>
<span style="color: #00A000">+                return $this->_mediaFromBufferItem($this->_buffer->current());</span>
        }
        public function key() {
<span style="color: #A00000">-                return key($this->_buffer);</span>
<span style="color: #00A000">+                return $this->_buffer->key();</span>
        }
        public function next() {
<span style="color: #A00000">-                return next($this->_buffer);</span>
<span style="color: #00A000">+                return $this->_mediaFromBufferItem($this->_buffer->next());</span>
        }
        public function valid() {
<span style="color: #A00000">-                $key = key($this->_buffer);</span>
<span style="color: #A00000">-                $var = ($key !== NULL && $key !== FALSE);</span>
<span style="color: #A00000">-                return $var;</span>
<span style="color: #00A000">+                return $this->_buffer->valid();</span>
        }
        // Capability play
<span style="color: #A00000">-        public function play($media) {</span>
<span style="color: #00A000">+        public function play(MediaBrotha_Media $media) {</span>
                return false;
        }
        public function pause() {
<span style="color: #800080; font-weight: bold">@@ -91,13 +93,13 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {</span>
                return false;
        }
        // Capability playlist
<span style="color: #A00000">-        public function playlistEnqueue($media) {</span>
<span style="color: #00A000">+        public function playlistEnqueue(MediaBrotha_Media $media) {</span>
                return false;
        }
<span style="color: #A00000">-        public function playlistNext($media) {</span>
<span style="color: #00A000">+        public function playlistNext(MediaBrotha_Media $media) {</span>
                return false;
        }
<span style="color: #A00000">-        public function playlistPrevious($media) {</span>
<span style="color: #00A000">+        public function playlistPrevious(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 62fcb6f..0dc8972 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">@@ -41,20 +41,13 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {</span>
                return false;
        }
<span style="color: #A00000">-        public function fetch($uri) {</span>
<span style="color: #A00000">-                if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {</span>
<span style="color: #A00000">-                        $uri = 'file://'.$this->getMetadata('base_path');</span>
<span style="color: #A00000">-                }</span>
<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: #A00000">-        }</span>
        public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
                return Array(
                        'browse',
                );
        }
<span style="color: #A00000">-        // Iterator</span>
<span style="color: #A00000">-        public function mediaFromFile($file) {</span>
<span style="color: #00A000">+        // Capability browse</span>
<span style="color: #00A000">+        protected function _mediaFromBufferItem($file) {</span>
                if ($file) {
                        $media = new MediaBrotha_Media(Array(
                                'uri' => 'file://'.realpath($file->getPathname()),
<span style="color: #800080; font-weight: bold">@@ -72,16 +65,12 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {</span>
                }
        }
<span style="color: #A00000">-        public function current() {</span>
<span style="color: #A00000">-                return $this->mediaFromFile($this->_buffer->current());</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->mediaFromFile($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">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {</span>
<span style="color: #00A000">+                        $uri = 'file://'.$this->getMetadata('base_path');</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));</span>
<span style="color: #00A000">+                return true;</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 5e9c5fb..5357cc3 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,13 +25,6 @@ This file is part of MediaBrotha.</span>
*/
class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
<span style="color: #A00000">-        public function fetch($uri) {</span>
<span style="color: #A00000">-                $this->_buffer = Array();</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: #A00000">-        }</span>
        public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
                return Array(
                        'browse',
<span style="color: #800080; font-weight: bold">@@ -40,6 +33,16 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {</span>
        public function isHidden() {
                return true;
        }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Capability browse</span>
<span style="color: #00A000">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                $this->_buffer = new ArrayIterator();</span>
<span style="color: #00A000">+                foreach(MediaBrotha_Core::getBackends() as $id => $backend) {</span>
<span style="color: #00A000">+                        $this->_buffer[] = $backend;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                return true;</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/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php</span>
<span style="color: #000080; font-weight: bold">index 12cbff6..df10f93 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">@@ -31,28 +31,32 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {</span>
                MediaBrotha_Core::registerMimeType($this, 'video/x-msvideo');
        }
<span style="color: #A00000">-        public function fetch($uri) {</span>
<span style="color: #A00000">-                $this->_buffer[] = new MediaBrotha_Media();</span>
<span style="color: #A00000">-                return true;</span>
<span style="color: #A00000">-        }</span>
        public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
                return Array(
                        'play',
                        'playlist',
                );
        }
<span style="color: #A00000">-        private function send_command($command, $args = Array()) {</span>
<span style="color: #00A000">+        private function send_command($command, array $args = Array()) {</span>
                $url = $this->getMetadata('http_intf').
                        '/requests/status.xml'.
                        '?command='.$command;
                foreach ($args as $k => $v) {
                        $url.= '&'.$k.'='.rawurlencode($v);
                }
<span style="color: #A00000">-                return fopen($url, 'r');</span>
<span style="color: #00A000">+                $output = file_get_contents($url);</span>
<span style="color: #00A000">+                Header('Content-Type: text/xml');</span>
<span style="color: #00A000">+                print $output.'<!--'.$url."-->\n";</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        // Capability browse</span>
<span style="color: #00A000">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                $this->_buffer[] = new MediaBrotha_Media();</span>
<span style="color: #00A000">+                return true;</span>
        }
        // Capability play
<span style="color: #A00000">-        public function play($media) {</span>
<span style="color: #00A000">+        public function play(MediaBrotha_Media $media) {</span>
                return $this->send_command('in_play', Array('input' => $media->getURI()));
        }
        public function pause() {
<span style="color: #800080; font-weight: bold">@@ -62,13 +66,13 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {</span>
                return $this->send_command('pl_stop');
        }
        // Capability playlist
<span style="color: #A00000">-        public function playlistEnqueue($media) {</span>
<span style="color: #00A000">+        public function playlistEnqueue(MediaBrotha_Media $media) {</span>
                return $this->send_command('in_enqueue', Array('input' => $media->getURI()));
        }
<span style="color: #A00000">-        public function playlistNext($media) {</span>
<span style="color: #00A000">+        public function playlistNext(MediaBrotha_Media $media) {</span>
                return $this->send_command('pl_next');
        }
<span style="color: #A00000">-        public function playlistPrevious($media) {</span>
<span style="color: #00A000">+        public function playlistPrevious(MediaBrotha_Media $media) {</span>
                return $this->send_command('pl_previous');
        }
}
<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 e31ee47..b3eaa84 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">@@ -60,7 +60,8 @@ class MediaBrotha_Core {</span>
                                break;
                        case 'browse':
                        default:
<span style="color: #A00000">-                                $current_backend->fetch(MediaBrotha_Core::getCurrentURI());</span>
<span style="color: #00A000">+                                $current_uri = MediaBrotha_Core::getCurrentURI();</span>
<span style="color: #00A000">+                                $current_backend->fetch((string) $current_uri);</span>
                                MediaBrotha_Core::$_frontend->begin($current_backend);
                                foreach($current_backend as $item) {
                                        if ($item->isHidden()) {
<span style="color: #800080; font-weight: bold">@@ -126,7 +127,7 @@ class MediaBrotha_Core {</span>
        public static function getCurrentURI() {
                if (!empty($_GET['uri'])) {
<span style="color: #A00000">-                        return $_GET['uri'];</span>
<span style="color: #00A000">+                        return (string) $_GET['uri'];</span>
                }
        }
        public static function getCurrentMedia() {
<span style="color: #800080; font-weight: bold">@@ -136,5 +137,6 @@ class MediaBrotha_Core {</span>
                }
                return MediaBrotha_Core::$_media;
        }
<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.php</span>
<span style="color: #000080; font-weight: bold">index 9eab63c..84ce7b7 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">@@ -25,10 +25,8 @@ This file is part of MediaBrotha.</span>
*/
class MediaBrotha_Frontend {
<span style="color: #A00000">-        protected $_browser = NULL;</span>
        protected $_infos = NULL;
<span style="color: #A00000">-        public function __construct($browser, $args = Array()) {</span>
<span style="color: #A00000">-                $this->_browser = $browser;</span>
<span style="color: #00A000">+        public function __construct(array $args = Array()) {</span>
                $this->_infos = $args;
        }
}
<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 0b50a52..cf3d66d 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">@@ -28,7 +28,7 @@ class MediaBrotha_Media {</span>
        private $_metadata = Array();
        private $_mimeType = NULL;
        private $_mimeEncoding = NULL;
<span style="color: #A00000">-        public function __construct($metadata = Array()) {</span>
<span style="color: #00A000">+        public function __construct(array $metadata = Array()) {</span>
                 $this->_metadata = $metadata;
        }
        public function setMimeType($mime_type) {
<span style="color: #800080; font-weight: bold">@@ -63,7 +63,7 @@ class MediaBrotha_Media {</span>
                }
        }
        /* Most used metadata */
<span style="color: #A00000">-        public function getDisplayName() {</span>
<span style="color: #00A000">+        public function getDisplayName($max_length = 0) {</span>
                return $this->getMetadata('name');
        }
        public function getURI() {
</pre></div>
========================================================================<pre>
Summary of changes:
sathieu/cisco-xml/browser/index.php | 23 +++-
sathieu/cisco-xml/browser/static/default.css | 49 +++++++
sathieu/cisco-xml/browser/static/dynamic.js | 4 +
sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php | 11 ++-
sathieu/cisco-xml/lib/MediaBrotha/Backend.php | 89 +++++-------
.../lib/MediaBrotha/Backend/FileSystem.php | 85 +++++++----
sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php | 98 +++++++++++++
sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php | 33 +++--
sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php | 84 +++++++-----
sathieu/cisco-xml/lib/MediaBrotha/Core.php | 147 ++++++++++++++------
sathieu/cisco-xml/lib/MediaBrotha/Frontend.php | 6 +-
.../lib/MediaBrotha/Frontend/CiscoXML.php | 61 +++++----
.../cisco-xml/lib/MediaBrotha/Frontend/HTML.php | 127 +++++++++++++++++
.../{Frontend.php => Frontend/HTTP.php} | 13 +-
sathieu/cisco-xml/lib/MediaBrotha/Media.php | 104 +++++++++-----
.../cisco-xml/lib/MediaBrotha/MediaIterator.php | 71 ++++++++++
16 files changed, 751 insertions(+), 254 deletions(-)
create mode 100644 sathieu/cisco-xml/browser/static/default.css
create mode 100644 sathieu/cisco-xml/browser/static/dynamic.js
create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Frontend/HTML.php
copy sathieu/cisco-xml/lib/MediaBrotha/{Frontend.php => Frontend/HTTP.php} (77%)
create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/MediaIterator.php
</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>