Templified cloud's directory listing.
Moved HTML for the directory listing from include/reddav.php to it's own template file. Still need to clean it up bit more, but should be useable already.
This commit is contained in:
parent
37561a18bf
commit
45dde16f3e
@ -878,33 +878,24 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the directory listing for the given path.
|
||||||
|
*
|
||||||
|
* @param String $path
|
||||||
|
*/
|
||||||
public function generateDirectoryIndex($path) {
|
public function generateDirectoryIndex($path) {
|
||||||
|
|
||||||
$is_owner = ((local_user() && $this->auth->owner_id == local_user()) ? true : false);
|
$is_owner = ((local_user() && $this->auth->owner_id == local_user()) ? true : false);
|
||||||
|
|
||||||
if($this->auth->timezone)
|
if ($this->auth->timezone)
|
||||||
date_default_timezone_set($this->auth->timezone);
|
date_default_timezone_set($this->auth->timezone);
|
||||||
|
|
||||||
$version = '';
|
$version = '';
|
||||||
require_once('include/conversation.php');
|
require_once('include/conversation.php');
|
||||||
|
|
||||||
if($this->auth->channel_name)
|
if ($this->auth->channel_name)
|
||||||
$html = profile_tabs(get_app(),(($is_owner) ? true : false),$this->auth->owner_nick);
|
$html = profile_tabs(get_app(),(($is_owner) ? true : false),$this->auth->owner_nick);
|
||||||
|
|
||||||
$html .= "
|
|
||||||
<body>
|
|
||||||
<h1>".t('Files').": ".$this->escapeHTML($path) . "/</h1>
|
|
||||||
<table id=\"cloud-index\">
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th>".t('Name')." </th>
|
|
||||||
<th></th><th></th><th></th>
|
|
||||||
<th>".t('Type')." </th>
|
|
||||||
<th>".t('Size')." </th>
|
|
||||||
<th>".t('Last modified')."</th>
|
|
||||||
</tr>
|
|
||||||
<tr><td colspan=\"8\"><hr /></td></tr>";
|
|
||||||
|
|
||||||
$files = $this->server->getPropertiesForPath($path,array(
|
$files = $this->server->getPropertiesForPath($path,array(
|
||||||
'{DAV:}displayname',
|
'{DAV:}displayname',
|
||||||
'{DAV:}resourcetype',
|
'{DAV:}resourcetype',
|
||||||
@ -915,24 +906,19 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
$parent = $this->server->tree->getNodeForPath($path);
|
$parent = $this->server->tree->getNodeForPath($path);
|
||||||
|
|
||||||
|
$parentpath = array();
|
||||||
if ($path) {
|
// only show parent if not leaving /cloud/; TODO how to improve this?
|
||||||
|
if ($path && $path != "cloud") {
|
||||||
list($parentUri) = DAV\URLUtil::splitPath($path);
|
list($parentUri) = DAV\URLUtil::splitPath($path);
|
||||||
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
|
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
|
||||||
|
|
||||||
$icon = $this->enableAssets?'<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="Parent" /></a>':'';
|
$parentpath['icon'] = $this->enableAssets?'<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="'.t('parent').'"></a>':'';
|
||||||
$html.= "
|
$parentpath['path'] = $fullPath;
|
||||||
<tr>
|
|
||||||
<td>$icon</td>
|
|
||||||
<td><a href=\"{$fullPath}\">..</a></td>
|
|
||||||
<td></td><td></td><th></td>
|
|
||||||
<td>[".t('parent')."]</td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($files as $file) {
|
$f = array();
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$ft = array();
|
||||||
|
|
||||||
// This is the current directory, we can skip it
|
// This is the current directory, we can skip it
|
||||||
if (rtrim($file['href'],'/')==$path) continue;
|
if (rtrim($file['href'],'/')==$path) continue;
|
||||||
@ -941,15 +927,13 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
$type = null;
|
$type = null;
|
||||||
|
|
||||||
|
|
||||||
if (isset($file[200]['{DAV:}resourcetype'])) {
|
if (isset($file[200]['{DAV:}resourcetype'])) {
|
||||||
$type = $file[200]['{DAV:}resourcetype']->getValue();
|
$type = $file[200]['{DAV:}resourcetype']->getValue();
|
||||||
|
|
||||||
// resourcetype can have multiple values
|
// resourcetype can have multiple values
|
||||||
if (!is_array($type)) $type = array($type);
|
if (!is_array($type)) $type = array($type);
|
||||||
|
|
||||||
foreach($type as $k=>$v) {
|
foreach ($type as $k=>$v) {
|
||||||
|
|
||||||
// Some name mapping is preferred
|
// Some name mapping is preferred
|
||||||
switch($v) {
|
switch($v) {
|
||||||
case '{DAV:}collection' :
|
case '{DAV:}collection' :
|
||||||
@ -977,7 +961,6 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
$type[$k] = 'Proxy-Write';
|
$type[$k] = 'Proxy-Write';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$type = implode(', ', $type);
|
$type = implode(', ', $type);
|
||||||
}
|
}
|
||||||
@ -1000,18 +983,14 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
$type = $this->escapeHTML($type);
|
$type = $this->escapeHTML($type);
|
||||||
|
|
||||||
$icon = '';
|
$icon = '';
|
||||||
|
|
||||||
if ($this->enableAssets) {
|
if ($this->enableAssets) {
|
||||||
$node = $this->server->tree->getNodeForPath(($path?$path.'/':'') . $name);
|
$node = $this->server->tree->getNodeForPath(($path?$path.'/':'') . $name);
|
||||||
foreach(array_reverse($this->iconMap) as $class=>$iconName) {
|
foreach (array_reverse($this->iconMap) as $class=>$iconName) {
|
||||||
|
|
||||||
if ($node instanceof $class) {
|
if ($node instanceof $class) {
|
||||||
$icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24" /></a>';
|
$icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$parentHash="";
|
$parentHash="";
|
||||||
@ -1024,33 +1003,28 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
$parentHash = $attachHash;
|
$parentHash = $attachHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$attachId = $this->findAttachIdByHash($attachHash);
|
|
||||||
$fileStorageUrl = substr($fullPath, 0, strpos($fullPath,"cloud/")) . "filestorage/".$this->auth->channel_name;
|
|
||||||
$attachIcon = ""; // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"icon-download\"></i></a>";
|
$attachIcon = ""; // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"icon-download\"></i></a>";
|
||||||
$html.= "<tr>
|
|
||||||
<td>$icon</td>
|
|
||||||
<td style=\"min-width: 15em\"><a href=\"{$fullPath}\">{$displayName}</a></td>";
|
|
||||||
|
|
||||||
if($is_owner) {
|
// put the array for this file together
|
||||||
$html .= "<td>" . (($size) ? $attachIcon : '') . "</td>
|
$ft['attachId'] = $this->findAttachIdByHash($attachHash);
|
||||||
<td><a href=\"".$fileStorageUrl."/".$attachId."/edit\" title=\"".t('Edit')."\"><i class=\"icon-pencil btn btn-default\"></i></a></td>
|
$ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath,"cloud/")) ."filestorage/".$this->auth->channel_name;
|
||||||
<td><a href=\"".$fileStorageUrl."/".$attachId."/delete\" title=\"".t('Delete')."\" onclick=\"return confirm('".t('Are you sure you want to delete this item?')."');\"><i class=\"icon-remove btn btn-default drop-icons\"></i></a></td>";
|
$ft['icon'] = $icon;
|
||||||
}
|
$ft['attachIcon'] = (($size) ? $attachIcon : '');
|
||||||
else {
|
// is global or per item?
|
||||||
$html .= "<td></td><td></td><td></td>";
|
$ft['is_owner'] = $is_owner;
|
||||||
}
|
$ft['fullPath'] = $fullPath;
|
||||||
$html .=
|
$ft['displayName'] = $displayName;
|
||||||
"<td>{$type}</td>
|
$ft['type'] = $type;
|
||||||
<td>". $this->userReadableSize($size) ."</td>
|
$ft['size'] = $size;
|
||||||
<td>" . (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(),$lastmodified) : '') . "</td>
|
$ft['sizeFormatted'] = $this->userReadableSize($size);
|
||||||
</tr>";
|
$ft['lastmodified'] = (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '');
|
||||||
|
|
||||||
|
$f[] = $ft;
|
||||||
}
|
}
|
||||||
|
|
||||||
$html.= "<tr><td colspan=\"8\"><hr /></td></tr>
|
// Storage and Quota
|
||||||
</table>";
|
$limit = service_class_fetch($owner, 'attach_upload_limit');
|
||||||
|
|
||||||
$limit = service_class_fetch ($owner,'attach_upload_limit');
|
|
||||||
$r = q("select sum(filesize) as total from attach where aid = %d ",
|
$r = q("select sum(filesize) as total from attach where aid = %d ",
|
||||||
intval($this->auth->channel_account_id)
|
intval($this->auth->channel_account_id)
|
||||||
);
|
);
|
||||||
@ -1067,9 +1041,18 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
$this->userReadableSize($limit),
|
$this->userReadableSize($limit),
|
||||||
round($used / $limit, 1));
|
round($used / $limit, 1));
|
||||||
}
|
}
|
||||||
if ($limit || $used) {
|
|
||||||
$html.= "<p><strong>".t('Total')."</strong> ".$quotaDesc."</p>";
|
// quota for template
|
||||||
}
|
$quota['used'] = $used;
|
||||||
|
$quota['limit'] = $limit;
|
||||||
|
$quota['desc'] = $quotaDesc;
|
||||||
|
|
||||||
|
$html .= replace_macros(get_markup_template('cloud_directory.tpl'), array(
|
||||||
|
'$header' => t('Files').": ".$this->escapeHTML($path) . "/",
|
||||||
|
'$parentpath' => $parentpath,
|
||||||
|
'$entries' => $f,
|
||||||
|
'$quota' => $quota
|
||||||
|
));
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
if ($this->enablePost) {
|
if ($this->enablePost) {
|
||||||
@ -1079,9 +1062,6 @@ class RedBrowser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
get_app()->page['content'] = $html;
|
get_app()->page['content'] = $html;
|
||||||
construct_page(get_app());
|
construct_page(get_app());
|
||||||
|
|
||||||
// return $html;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function userReadableSize($size){
|
function userReadableSize($size){
|
||||||
|
48
view/tpl/cloud_directory.tpl
Normal file
48
view/tpl/cloud_directory.tpl
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<h1>{{$header}}</h1>
|
||||||
|
<table id="cloud-index">
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>{{t('Name')}} </th>
|
||||||
|
<th></th><th></th><th></th>
|
||||||
|
<th>{{t('Type')}} </th>
|
||||||
|
<th>{{t('Size')}} </th>
|
||||||
|
<th>{{t('Last modified')}}</th>
|
||||||
|
</tr>
|
||||||
|
<tr><td colspan="8"><hr></td></tr>
|
||||||
|
|
||||||
|
{{if $parentpath}}
|
||||||
|
<tr>
|
||||||
|
<td>{{$parentpath.icon}}</td>
|
||||||
|
<td><a href="{{$parentpath.path}}" title="{{t('parent')}}">..</a></td>
|
||||||
|
<td></td><td></td><th></td>
|
||||||
|
<td>[{{t('parent')}}]</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
|
||||||
|
{{foreach $entries as $item}}
|
||||||
|
<tr>
|
||||||
|
<td>{{$item.icon}}</td>
|
||||||
|
<td style="min-width: 15em"><a href="{{$item.fullPath}}">{{$item.displayName}}</a></td>
|
||||||
|
|
||||||
|
{{if $item.is_owner}}
|
||||||
|
<td>{{$item.attachIcon}}</td>
|
||||||
|
<td style="position:relative;"><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/edit" title="{{t('Edit')}}"><i class="icon-pencil btn btn-default"></i></a></td>
|
||||||
|
<td><a href="{{$item.fileStorageUrl}}/{{$item.attachId}}/delete" title="{{t('Delete')}}" onclick="return confirm('{{t('Are you sure you want to delete this item?')}}');"><i class="icon-remove btn btn-default drop-icons"></i></a></td>
|
||||||
|
{{else}}
|
||||||
|
<td></td><td></td><td></td>
|
||||||
|
{{/if}}
|
||||||
|
<td>{{$item.type}}</td>
|
||||||
|
<td>{{$item.sizeFormatted}}</td>
|
||||||
|
<td>{{$item.lastmodified}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/foreach}}
|
||||||
|
|
||||||
|
<tr><td colspan="8"><hr></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{{if $quota.limit || $quota.used}}
|
||||||
|
<p><strong>{{t('Total')}}</strong> {{$quota.desc}}</p>
|
||||||
|
{{/if}}
|
Reference in New Issue
Block a user