<h1>Project "FreeSWITCH user-contributed scripts, etc" received a push.</h1>
<h2>branch: master updated</h2>
<pre>
via: 9ecdde39b5fb94c4708b530a7c90e82900ff15ed (commit)
from: 69415c934e4b3dc70b22816aa847706336c442f5 (commit)
</pre>= COMMIT LOG ===========================================================
<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>
========================================================================<pre>
Summary of changes:
sathieu/cisco-xml/browser/index.php | 11 +-
sathieu/cisco-xml/lib/Cisco-XML/Cisco-XML.php | 6 +
sathieu/cisco-xml/lib/MediaBrotha/Backend.php | 7 +-
.../lib/MediaBrotha/Backend/FileSystem.php | 41 ++++--
sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php | 17 ++-
sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php | 18 ++--
sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php | 20 +--
sathieu/cisco-xml/lib/MediaBrotha/Core.php | 140 +++++++++++---------
.../lib/MediaBrotha/Frontend/CiscoXML.php | 11 +-
sathieu/cisco-xml/lib/MediaBrotha/Media.php | 57 +++++---
10 files changed, 197 insertions(+), 131 deletions(-)
</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>