[Pkg-owncloud-commits] [php-sabredav] 132/163: Lots of design tweaks.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:55:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.

commit f65a56815d2515b9d0a564f2fc83c22ff1fdcc33
Author: Evert Pot <me at evertpot.com>
Date:   Thu May 8 18:25:53 2014 -0400

    Lots of design tweaks.
---
 lib/DAV/Browser/Plugin.php                      | 146 +++++++++++++++++++-----
 lib/DAV/Browser/PropFindAll.php                 | 132 +++++++++++++++++++++
 lib/DAV/Browser/assets/sabredav.css             |  31 ++++-
 lib/DAV/PropFind.php                            |   1 -
 lib/DAVACL/Property/CurrentUserPrivilegeSet.php |  11 ++
 5 files changed, 284 insertions(+), 37 deletions(-)

diff --git a/lib/DAV/Browser/Plugin.php b/lib/DAV/Browser/Plugin.php
index 25fa0cd..51e75f4 100644
--- a/lib/DAV/Browser/Plugin.php
+++ b/lib/DAV/Browser/Plugin.php
@@ -230,7 +230,7 @@ class Plugin extends DAV\ServerPlugin {
 <!DOCTYPE html>
 <html>
 <head>
-    <title>$vars[path] "/ - sabre/dav " . $version "</title>
+    <title>$vars[path] / - sabre/dav $version</title>
     <link rel="shortcut icon" href="$vars[favicon]"   type="image/vnd.microsoft.icon" />
     <link rel="stylesheet"    href="$vars[style]"     type="text/css" />
     <link rel="stylesheet"    href="$vars[iconstyle]" type="text/css" />
@@ -309,20 +309,14 @@ HTML;
         $html.="<table>";
 
         // Allprops request
-        $properties = $this->server->getProperties($path, []);
+        $propFind = new PropFindAll($path);
+        $properties = $this->server->getPropertiesByNode($propFind, $node);
+
+        $properties = $propFind->getResultForMultiStatus()[200];
 
         foreach($properties as $propName => $propValue) {
-            $html.="<tr><th>";
-            $html.=$this->escapeHTML($propName);
-            $html.="</th>";
-            $html.="<td>";
-            if (is_string($propValue)) {
-                $html.=$this->escapeHTML($propValue);
-            } else {
-                $html.="<em>complex</em>";
-            }
-            $html.="</td>";
-            $html.="</tr>";
+            $html.=$this->drawPropertyRow($propName, $propValue);
+
         }
 
 
@@ -331,9 +325,7 @@ HTML;
 
 
         $html.="<section><h1>Actions</h1>";
-        $html.="<table>";
-        $html.="</table>";
-        $html.="</section>";
+
 
         $output = '';
 
@@ -342,8 +334,9 @@ HTML;
         }
 
         $html.=$output;
+        $html.="</section>";
 
-        $html.= "</table>
+        $html.= "
         <address>Generated by SabreDAV " . $version . " (c)2007-2014 <a href=\"http://sabre.io/\">http://sabre.io/</a></address>
         </body>
         </html>";
@@ -375,20 +368,24 @@ HTML;
         if (get_class($node)==='Sabre\\DAV\\SimpleCollection')
             return;
 
-        $output.= '<tr><td colspan="2"><form method="post" action="">
-            <h3>Create new folder</h3>
-            <input type="hidden" name="sabreAction" value="mkcol" />
-            Name: <input type="text" name="name" /><br />
-            <input type="submit" value="create" />
-            </form>
-            <form method="post" action="" enctype="multipart/form-data">
-            <h3>Upload file</h3>
-            <input type="hidden" name="sabreAction" value="put" />
-            Name (optional): <input type="text" name="name" /><br />
-            File: <input type="file" name="file" /><br />
-            <input type="submit" value="upload" />
-            </form>
-            </td></tr>';
+        ob_start();
+        echo '<form method="post" action="">
+        <h2>Create new folder</h2>
+        <input type="hidden" name="sabreAction" value="mkcol" />
+        Name:<br />
+        <input type="text" name="name" /><br />
+        <input type="submit" value="create" />
+        </form>
+        <form method="post" action="" enctype="multipart/form-data">
+        <h2>Upload file</h2>
+        <input type="hidden" name="sabreAction" value="put" />
+        Name (optional): <input type="text" name="name" /><br />
+        File: <input type="file" name="file" /><br />
+        <input type="submit" value="upload" />
+        </form>
+        ';
+
+        $output.=ob_get_clean();
 
     }
 
@@ -555,4 +552,91 @@ HTML;
 
     }
 
+    /**
+     * Draws a table row for a property
+     *
+     * @param string $name
+     * @param mixed $value
+     * @return string
+     */
+    private function drawPropertyRow($name, $value) {
+
+        $view = 'unknown';
+        if (is_string($value)) {
+            $view = 'string';
+        } elseif($value instanceof DAV\Property) {
+
+            $mapping = [
+                'Sabre\\DAV\\Property\\IHref' => 'href',
+                'Sabre\\DAV\\Property\\HrefList' => 'hreflist',
+                'Sabre\\DAV\\Property\\SupportedMethodSet' => 'valuelist',
+                'Sabre\\DAV\\Property\\ResourceType' => 'xmlvaluelist',
+                'Sabre\\DAV\\Property\\SupportedReportSet' => 'xmlvaluelist',
+                'Sabre\\DAVACL\\Property\\CurrentUserPrivilegeSet' => 'xmlvaluelist',
+            ];
+
+            $view = 'complex';
+            foreach($mapping as $class=>$val) {
+                if ($value instanceof $class) {
+                    $view = $val;
+                }
+            }
+        }
+
+
+
+        list($ns, $localName) = DAV\XMLUtil::parseClarkNotation($name);
+
+        $realName = $name;
+        if (isset($this->server->xmlNamespaces[$ns])) {
+            $name = $this->server->xmlNamespaces[$ns] . ':' . $localName;
+        }
+
+        ob_start();
+
+        echo "<tr><th><span title=\"", $this->escapeHTML($realName), "\">", $this->escapeHTML($name), "</span></th><td>";
+
+        switch($view) {
+
+            case 'href' :
+                echo "<a href=\"" . $this->server->getBaseUri() . $value->getHref() . '\">' . $this->server->getBaseUri() . $value->getHref() . '</a>';
+                break;
+            case 'hreflist' :
+                echo implode('<br />', array_map(function($href) {
+                    if (strpos($href,'mailto:')===0 || strpos($href,'/')===0 || strpos($href,'http:')===0 || strpos($href,'https:') === 0) {
+                        return "<a href=\"" . $this->escapeHTML($href) . '\">' . $this->escapeHTML($href) . '</a>';
+                    } else {
+                        return "<a href=\"" . $this->escapeHTML($this->server->getBaseUri() . $href) . '\">' . $this->escapeHTML($this->server->getBaseUri() . $href) . '</a>';
+                    }
+                }, $value->getHrefs()));
+                break;
+            case 'xmlvaluelist' :
+                echo implode(', ', array_map(function($propName) {
+                    $realPropName = $propName;
+                    list($ns, $localName) = DAV\XMLUtil::parseClarkNotation($propName);
+                    if (isset($this->server->xmlNamespaces[$ns])) {
+                        $propName = $this->server->xmlNamespaces[$ns] . ':' . $localName;
+                    }
+                    return "<span title=\"" . $this->escapeHTML($realPropName) . "\">" . $this->escapeHTML($propName) . "</span>";
+                }, $value->getValue()));
+                break;
+            case 'valuelist' :
+                echo $this->escapeHTML(implode(', ', $value->getValue()));
+                break;
+            case 'string' :
+                echo $this->escapeHTML($value);
+                break;
+            case 'complex' :
+                echo '<em title="' . get_class($value) . '">complex</em>';
+                break;
+            default :
+                echo '<em>unknown</em>';
+                break;
+
+        }
+
+        return ob_get_clean();
+
+    }
+
 }
diff --git a/lib/DAV/Browser/PropFindAll.php b/lib/DAV/Browser/PropFindAll.php
new file mode 100644
index 0000000..fa765cb
--- /dev/null
+++ b/lib/DAV/Browser/PropFindAll.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace Sabre\DAV\Browser;
+
+use Sabre\DAV\PropFind;
+
+/**
+ * This class is used by the browser plugin to trick the system in returning
+ * every defined property.
+ *
+ * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class PropFindAll extends PropFind {
+
+    /**
+     * Creates the PROPFIND object
+     *
+     * @param string $path
+     */
+    public function __construct($path) {
+
+        parent::__construct($path, []);
+
+    }
+
+    /**
+     * Handles a specific property.
+     *
+     * This method checks wether the specified property was requested in this
+     * PROPFIND request, and if so, it will call the callback and use the
+     * return value for it's value.
+     *
+     * Example:
+     *
+     * $propFind->handle('{DAV:}displayname', function() {
+     *      return 'hello';
+     * });
+     *
+     * Note that handle will only work the first time. If null is returned, the
+     * value is ignored.
+     *
+     * It's also possible to not pass a callback, but immediately pass a value
+     *
+     * @param string $propertyName
+     * @param mixed $valueOrCallBack
+     * @return void
+     */
+    public function handle($propertyName, $valueOrCallBack) {
+
+        if (is_callable($valueOrCallBack)) {
+            $value = $valueOrCallBack();
+        } else {
+            $value = $valueOrCallBack;
+        }
+        if (!is_null($value)) {
+            $this->result[$propertyName] = [200, $value];
+        }
+
+    }
+
+    /**
+     * Sets the value of the property
+     *
+     * If status is not supplied, the status will default to 200 for non-null
+     * properties, and 404 for null properties.
+     *
+     * @param string $propertyName
+     * @param mixed $value
+     * @param int $status
+     * @return void
+     */
+    public function set($propertyName, $value, $status = null) {
+
+        if (is_null($status)) {
+            $status = is_null($value) ? 404 : 200;
+        }
+        $this->result[$propertyName] = [$status, $value];
+
+    }
+
+    /**
+     * Returns the current value for a property.
+     *
+     * @param string $propertyName
+     * @return mixed
+     */
+    public function get($propertyName) {
+
+        return isset($this->result[$propertyName])?$this->result[$propertyName][1]:null;
+
+    }
+
+    /**
+     * Returns the current status code for a property name.
+     *
+     * If the property does not appear in the list of requested properties,
+     * null will be returned.
+     *
+     * @param string $propertyName
+     * @return int|null
+     */
+    public function getStatus($propertyName) {
+
+        return isset($this->result[$propertyName])?$this->result[$propertyName][0]:404;
+
+    }
+
+    /**
+     * Returns all propertynames that have a 404 status, and thus don't have a
+     * value yet.
+     *
+     * @return array
+     */
+    public function get404Properties() {
+
+        $result = [];
+        foreach($this->result as $propertyName=>$stuff) {
+            if ($stuff[0]===404) {
+                $result[] = $propertyName;
+            }
+        }
+        // If there's nothing in this list, we're adding one fictional item.
+        if (!$result) {
+            $result[] = '{http://sabredav.org/ns}idk';
+        } 
+        return $result;
+
+    }
+
+}
diff --git a/lib/DAV/Browser/assets/sabredav.css b/lib/DAV/Browser/assets/sabredav.css
index bde64c1..dea9f0d 100644
--- a/lib/DAV/Browser/assets/sabredav.css
+++ b/lib/DAV/Browser/assets/sabredav.css
@@ -2,17 +2,20 @@
     box-sizing: border-box;
 }
 
-body {
+body, input {
     font-family: arial, sans-serif;
-    margin: 0;
     font-size: 14px;
+}
+
+body {
+    margin: 0;
     line-height: 22px;
     font-weight: 300;
 }
 
 a {
     text-decoration: none;
-    color: black;
+    color: #31A1CD;
 }
 
 th {
@@ -38,6 +41,11 @@ header a {
     text-decoration: none;
 }
 
+input[type=text] {
+    border: 1px solid #999;
+    font-size: 18px;
+}
+
 nav {
     padding: 5px;
 }
@@ -51,12 +59,20 @@ section h1 {
     color: #B10610;
 }
 
-.btn {
+section h2 {
+    font-size: 28px;
+    color #333;
+    font-weight: 300;
+    line-height: 36px;
+}
+
+.btn, input[type=submit] {
     display: inline-block;
     color: white;
     background: #B10610;
     padding: 3px;
     border-radius: 2px;
+    border: 0;
 }
 
 .btn.disabled {
@@ -74,9 +90,14 @@ section table td {
 
 section table .oi {
     color: #B10610;
-} 
+}
+
+.propTable a {
+    color: #
+}
 
 .nodeTable .namecolumn {
     min-width: 200px;
 }
 
+
diff --git a/lib/DAV/PropFind.php b/lib/DAV/PropFind.php
index 7a7d665..0881e2a 100644
--- a/lib/DAV/PropFind.php
+++ b/lib/DAV/PropFind.php
@@ -32,7 +32,6 @@ class PropFind {
      */
     const PROPNAME = 2;
 
-
     /**
      * Creates the PROPFIND object
      *
diff --git a/lib/DAVACL/Property/CurrentUserPrivilegeSet.php b/lib/DAVACL/Property/CurrentUserPrivilegeSet.php
index 2480af4..0d0517f 100644
--- a/lib/DAVACL/Property/CurrentUserPrivilegeSet.php
+++ b/lib/DAVACL/Property/CurrentUserPrivilegeSet.php
@@ -67,6 +67,17 @@ class CurrentUserPrivilegeSet extends DAV\Property {
     }
 
     /**
+     * Returns the list of privileges.
+     *
+     * @return array
+     */
+    public function getValue() {
+
+        return $this->privileges;
+
+    }
+
+    /**
      * Serializes one privilege
      *
      * @param \DOMDocument $doc

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list