<h1>Project "FreeSWITCH user-contributed scripts, etc" received a push.</h1>

<h2>branch: master updated</h2>
<pre>
       via: 55ef55a5a9e951b26c52b3d2f0e5f902e568f1f9 (commit)
      from: ca8489d71e127d5ff7beafbd91bcf5f9c683dd8d (commit)


</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Mathieu Parent
comments: 
MediaBrotha: LDAP search and result

<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 2b04351..a1a0e98 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">@@ -50,16 +50,22 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
 
         // Browsing
         public function mediaFromBufferItem($entry) {
<span style="color: #A00000">-                if ($entry) {</span>
<span style="color: #A00000">-                        $media = new MediaBrotha_Media(</span>
<span style="color: #00A000">+                if (is_a($entry, &#39;Net_LDAP2_Entry&#39;)) {</span>
<span style="color: #00A000">+                        return new MediaBrotha_Media(</span>
                                 &#39;ldap:///&#39;.$entry-&gt;dn(),
                                 Array(
                                         &#39;display_name&#39; =&gt; $entry-&gt;dn(), //$entry-&gt;getValue(&#39;sn&#39;, &#39;single&#39;),
                                 ),
                                 &#39;text/directory&#39;
<span style="color: #A00000">-                                //$finfo-&gt;file($file-&gt;getPathname(), FILEINFO_MIME_ENCODING);</span>
                         );
<span style="color: #A00000">-                        return $media;</span>
<span style="color: #00A000">+                } else {</span>
<span style="color: #00A000">+                        return new MediaBrotha_Media(</span>
<span style="color: #00A000">+                                &#39;ldap:///&#39;,</span>
<span style="color: #00A000">+                                Array(</span>
<span style="color: #00A000">+                                        &#39;display_name&#39; =&gt; $entry[0].&#39;: &#39;.$entry[1],</span>
<span style="color: #00A000">+                                ),</span>
<span style="color: #00A000">+                                &#39;text/directory&#39;</span>
<span style="color: #00A000">+                        );</span>
                 }
         }
 
<span style="color: #800080; font-weight: bold">@@ -73,8 +79,10 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
                 if ($this-&gt;_isHandled($media)) {
                         return Array(
                                 &#39;_default&#39;,
<span style="color: #00A000">+                                &#39;detail&#39;,</span>
                                 &#39;browse&#39;,
                                 &#39;search&#39;,
<span style="color: #00A000">+                                &#39;_search-result&#39;,</span>
                         );
                 } else {
                         return parent::getMediaActions($media);
<span style="color: #800080; font-weight: bold">@@ -92,13 +100,48 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
                                 if ($basedn &amp;&amp; ($basedn{0} = &#39;/&#39;)) {
                                         $basedn = substr($basedn, 1);
                                 }
<span style="color: #A00000">-                                $ldap_search = $this-&gt;_ldap-&gt;search($basedn, NULL,</span>
<span style="color: #A00000">-                                        Array());</span>
<span style="color: #00A000">+                                $ldap_search = $this-&gt;_ldap-&gt;search($basedn, NULL, Array());</span>
                                 return new MediaBrotha_MediaIterator($this, $ldap_search);
<span style="color: #00A000">+                        case &#39;detail&#39;:</span>
<span style="color: #00A000">+                                $uri = $media-&gt;getURI();</span>
<span style="color: #00A000">+                                if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != &#39;ldap&#39;) || !$this-&gt;isURISafe($uri)) {</span>
<span style="color: #00A000">+                                        return false;</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+                                $basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);</span>
<span style="color: #00A000">+                                if ($basedn &amp;&amp; ($basedn{0} = &#39;/&#39;)) {</span>
<span style="color: #00A000">+                                        $basedn = substr($basedn, 1);</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+                                $ldap_entry = $this-&gt;_ldap-&gt;getEntry($basedn);</span>
<span style="color: #00A000">+                                $it = new ArrayIterator();</span>
<span style="color: #00A000">+                                foreach ($ldap_entry-&gt;attributes() as $attr) {</span>
<span style="color: #00A000">+                                        foreach($ldap_entry-&gt;getValue($attr, &#39;all&#39;) as $value) {</span>
<span style="color: #00A000">+                                                $it[] = Array($attr, $value);</span>
<span style="color: #00A000">+                                        }</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+                                return new MediaBrotha_MediaIterator($this, $it);</span>
                         case &#39;_default&#39;:
                         case &#39;search&#39;:
<span style="color: #00A000">+                        case &#39;_search-result&#39;:</span>
                                 $form =  new MediaBrotha_Form();
                                 $form-&gt;setTitle(&#39;search&#39;);
<span style="color: #00A000">+                                $form-&gt;addField(Array(</span>
<span style="color: #00A000">+                                        &#39;name&#39; =&gt; &#39;backend&#39;,</span>
<span style="color: #00A000">+                                        &#39;value&#39; =&gt; &#39;LDAP&#39;,</span>
<span style="color: #00A000">+                                        &#39;visibility&#39; =&gt; &#39;hidden&#39;,</span>
<span style="color: #00A000">+                                        )</span>
<span style="color: #00A000">+                                );</span>
<span style="color: #00A000">+                                $form-&gt;addField(Array(</span>
<span style="color: #00A000">+                                        &#39;name&#39; =&gt; &#39;action&#39;,</span>
<span style="color: #00A000">+                                        &#39;value&#39; =&gt; &#39;_search-result&#39;,</span>
<span style="color: #00A000">+                                        &#39;visibility&#39; =&gt; &#39;hidden&#39;,</span>
<span style="color: #00A000">+                                        )</span>
<span style="color: #00A000">+                                );</span>
<span style="color: #00A000">+                                $form-&gt;addField(Array(</span>
<span style="color: #00A000">+                                        &#39;name&#39; =&gt; &#39;uri&#39;,</span>
<span style="color: #00A000">+                                        &#39;value&#39; =&gt; &#39;ldap://&#39;,</span>
<span style="color: #00A000">+                                        &#39;visibility&#39; =&gt; &#39;hidden&#39;,</span>
<span style="color: #00A000">+                                        )</span>
<span style="color: #00A000">+                                );</span>
                                 $search_fields = Array(
                                         &#39;sn&#39;              =&gt; Array(&#39;display_name&#39; =&gt; &#39;last name&#39;),
                                         &#39;givenName&#39;       =&gt; Array(&#39;display_name&#39; =&gt; &#39;first name&#39;),
<span style="color: #800080; font-weight: bold">@@ -124,22 +167,15 @@ class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {</span>
                                         }
                                         $form-&gt;addField($field);
                                 }
<span style="color: #A00000">-                                if (empty($_GET[&#39;ldap_search&#39;])) {</span>
<span style="color: #A00000">-                                        MediaBrotha_Core::addCallback(&#39;MediaBrotha_Backend_LDAP::searchCallback&#39;);</span>
<span style="color: #00A000">+                                if ($action !== &#39;_search-result&#39;) {</span>
                                         return $form;
                                 } else {
<span style="color: #A00000">-                                        $ldap_search = $this-&gt;_ldap-&gt;search(NULL, $filter,</span>
<span style="color: #A00000">-                                                Array(&#39;scope&#39; =&gt; &#39;sub&#39;));</span>
<span style="color: #00A000">+                                        $ldap_search = $this-&gt;_ldap-&gt;search(NULL, $filter, Array(&#39;scope&#39; =&gt; &#39;sub&#39;));</span>
                                         return new MediaBrotha_MediaIterator($this, $ldap_search);
                                 }
                         default:
                                 return parent::doMediaAction($action, $media);
                 }
         }
<span style="color: #A00000">-        static public function searchCallback() {</span>
<span style="color: #A00000">-                $_GET[&#39;backend&#39;] = &#39;LDAP&#39;;</span>
<span style="color: #A00000">-                $_GET[&#39;action&#39;] = &#39;search&#39;;</span>
<span style="color: #A00000">-                $_GET[&#39;ldap_search&#39;] = &#39;1&#39;;</span>
<span style="color: #A00000">-        }</span>
 }
 
</pre></div>
========================================================================<pre>

Summary of changes:
 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php |   66 +++++++++++++++-----
 1 files changed, 51 insertions(+), 15 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>