<h1>Project "FreeSWITCH user-contributed scripts, etc" received a push.</h1>
<h2>branch: master updated</h2>
<pre>
via: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
from: 68d384edcbabcac7e4058bbf26f409817d2c4505 (commit)
</pre>= COMMIT LOG ===========================================================
<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/lib/MediaBrotha/Backend.php | 26 ++++++++++---------
.../lib/MediaBrotha/Backend/FileSystem.php | 27 ++++++--------------
sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php | 17 +++++++-----
sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php | 24 ++++++++++-------
sathieu/cisco-xml/lib/MediaBrotha/Core.php | 6 +++-
sathieu/cisco-xml/lib/MediaBrotha/Frontend.php | 4 +--
sathieu/cisco-xml/lib/MediaBrotha/Media.php | 4 +-
7 files changed, 53 insertions(+), 55 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>