<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(&#39;MediaBrotha/Media.php&#39;);</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-&gt;register();
                 $this-&gt;setMimeType(&#39;application/x-mediabrotha-backend-&#39;.strtolower($this-&gt;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-&gt;_buffer);</span>
<span style="color: #00A000">+                $this-&gt;_buffer-&gt;rewind();</span>
         }
 
         public function current() {
<span style="color: #A00000">-                return current($this-&gt;_buffer);</span>
<span style="color: #00A000">+                return $this-&gt;_mediaFromBufferItem($this-&gt;_buffer-&gt;current());</span>
         }
 
         public function key() {
<span style="color: #A00000">-                return key($this-&gt;_buffer);</span>
<span style="color: #00A000">+                return $this-&gt;_buffer-&gt;key();</span>
         }
 
         public function next() {
<span style="color: #A00000">-                return next($this-&gt;_buffer);</span>
<span style="color: #00A000">+                return $this-&gt;_mediaFromBufferItem($this-&gt;_buffer-&gt;next());</span>
         }
 
         public function valid() {
<span style="color: #A00000">-                $key = key($this-&gt;_buffer);</span>
<span style="color: #A00000">-                $var = ($key !== NULL &amp;&amp; $key !== FALSE);</span>
<span style="color: #A00000">-                return $var;</span>
<span style="color: #00A000">+                return $this-&gt;_buffer-&gt;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) != &#39;file&#39;) || !$this-&gt;isURISafe($uri)) {</span>
<span style="color: #A00000">-                        $uri = &#39;file://&#39;.$this-&gt;getMetadata(&#39;base_path&#39;);</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                $this-&gt;_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(
                         &#39;browse&#39;,
                 );
         }
<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(
                                 &#39;uri&#39; =&gt; &#39;file://&#39;.realpath($file-&gt;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-&gt;mediaFromFile($this-&gt;_buffer-&gt;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-&gt;mediaFromFile($this-&gt;_buffer-&gt;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-&gt;_buffer-&gt;valid();</span>
<span style="color: #00A000">+        public function fetch($uri) {</span>
<span style="color: #00A000">+                if ((parse_url($uri, PHP_URL_SCHEME) != &#39;file&#39;) || !$this-&gt;isURISafe($uri)) {</span>
<span style="color: #00A000">+                        $uri = &#39;file://&#39;.$this-&gt;getMetadata(&#39;base_path&#39;);</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+                $this-&gt;_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-&gt;_buffer = Array();</span>
<span style="color: #A00000">-                foreach(MediaBrotha_Core::getBackends() as $id =&gt; $backend) {</span>
<span style="color: #A00000">-                        $this-&gt;_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(
                         &#39;browse&#39;,
<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-&gt;_buffer = new ArrayIterator();</span>
<span style="color: #00A000">+                foreach(MediaBrotha_Core::getBackends() as $id =&gt; $backend) {</span>
<span style="color: #00A000">+                        $this-&gt;_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, &#39;video/x-msvideo&#39;);
         }
 
<span style="color: #A00000">-        public function fetch($uri) {</span>
<span style="color: #A00000">-                $this-&gt;_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(
                         &#39;play&#39;,
                         &#39;playlist&#39;,
                 );
         }
<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-&gt;getMetadata(&#39;http_intf&#39;).
                         &#39;/requests/status.xml&#39;.
                         &#39;?command=&#39;.$command;
                 foreach ($args as $k =&gt; $v) {
                         $url.= &#39;&amp;&#39;.$k.&#39;=&#39;.rawurlencode($v);
                 }
<span style="color: #A00000">-                return fopen($url, &#39;r&#39;);</span>
<span style="color: #00A000">+                $output = file_get_contents($url);</span>
<span style="color: #00A000">+                Header(&#39;Content-Type: text/xml&#39;);</span>
<span style="color: #00A000">+                print $output.&#39;&lt;!--&#39;.$url.&quot;--&gt;\n&quot;;</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-&gt;_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-&gt;send_command(&#39;in_play&#39;, Array(&#39;input&#39; =&gt; $media-&gt;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-&gt;send_command(&#39;pl_stop&#39;);
         }
         // Capability playlist
<span style="color: #A00000">-        public function playlistEnqueue($media) {</span>
<span style="color: #00A000">+        public function playlistEnqueue(MediaBrotha_Media $media) {</span>
                 return $this-&gt;send_command(&#39;in_enqueue&#39;, Array(&#39;input&#39; =&gt; $media-&gt;getURI()));
         }
<span style="color: #A00000">-        public function playlistNext($media) {</span>
<span style="color: #00A000">+        public function playlistNext(MediaBrotha_Media $media) {</span>
                 return $this-&gt;send_command(&#39;pl_next&#39;);
         }
<span style="color: #A00000">-        public function playlistPrevious($media) {</span>
<span style="color: #00A000">+        public function playlistPrevious(MediaBrotha_Media $media) {</span>
                 return $this-&gt;send_command(&#39;pl_previous&#39;);
         }
 }
<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 &#39;browse&#39;:
                         default:
<span style="color: #A00000">-                                $current_backend-&gt;fetch(MediaBrotha_Core::getCurrentURI());</span>
<span style="color: #00A000">+                                $current_uri = MediaBrotha_Core::getCurrentURI();</span>
<span style="color: #00A000">+                                $current_backend-&gt;fetch((string) $current_uri);</span>
                                 MediaBrotha_Core::$_frontend-&gt;begin($current_backend);
                                 foreach($current_backend as $item) {
                                         if ($item-&gt;isHidden()) {
<span style="color: #800080; font-weight: bold">@@ -126,7 +127,7 @@ class MediaBrotha_Core {</span>
 
         public static function getCurrentURI() {
                 if (!empty($_GET[&#39;uri&#39;])) {
<span style="color: #A00000">-                        return $_GET[&#39;uri&#39;];</span>
<span style="color: #00A000">+                        return (string) $_GET[&#39;uri&#39;];</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-&gt;_browser = $browser;</span>
<span style="color: #00A000">+        public function __construct(array $args = Array()) {</span>
                 $this-&gt;_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-&gt;_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-&gt;getMetadata(&#39;name&#39;);
         }
         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>