Merge pull request #508 from dawnbreak/master

Templified cloud's directory listing.
This commit is contained in:
RedMatrix 2014-06-26 10:30:47 +10:00
commit e6d7bfc8a3
2 changed files with 201 additions and 173 deletions

View File

@ -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) {
$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);
$version = '';
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 .= "
<body>
<h1>".t('Files').": ".$this->escapeHTML($path) . "/</h1>
<table id=\"cloud-index\">
<tr>
<th></th>
<th>".t('Name')."&nbsp;&nbsp;&nbsp;</th>
<th></th><th></th><th></th>
<th>".t('Type')."&nbsp;&nbsp;&nbsp;</th>
<th>".t('Size')."&nbsp;&nbsp;&nbsp;</th>
<th>".t('Last modified')."</th>
</tr>
<tr><td colspan=\"8\"><hr /></td></tr>";
$files = $this->server->getPropertiesForPath($path,array(
'{DAV:}displayname',
'{DAV:}resourcetype',
@ -915,24 +906,19 @@ class RedBrowser extends DAV\Browser\Plugin {
$parent = $this->server->tree->getNodeForPath($path);
if ($path) {
$parentpath = array();
// only show parent if not leaving /cloud/; TODO how to improve this?
if ($path && $path != "cloud") {
list($parentUri) = DAV\URLUtil::splitPath($path);
$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>':'';
$html.= "
<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>";
$parentpath['icon'] = $this->enableAssets?'<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="'.t('parent').'"></a>':'';
$parentpath['path'] = $fullPath;
}
foreach($files as $file) {
$f = array();
foreach ($files as $file) {
$ft = array();
// This is the current directory, we can skip it
if (rtrim($file['href'],'/')==$path) continue;
@ -941,15 +927,13 @@ class RedBrowser extends DAV\Browser\Plugin {
$type = null;
if (isset($file[200]['{DAV:}resourcetype'])) {
$type = $file[200]['{DAV:}resourcetype']->getValue();
// resourcetype can have multiple values
if (!is_array($type)) $type = array($type);
foreach($type as $k=>$v) {
foreach ($type as $k=>$v) {
// Some name mapping is preferred
switch($v) {
case '{DAV:}collection' :
@ -977,7 +961,6 @@ class RedBrowser extends DAV\Browser\Plugin {
$type[$k] = 'Proxy-Write';
break;
}
}
$type = implode(', ', $type);
}
@ -1000,18 +983,14 @@ class RedBrowser extends DAV\Browser\Plugin {
$type = $this->escapeHTML($type);
$icon = '';
if ($this->enableAssets) {
$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) {
$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;
}
}
}
$parentHash="";
@ -1024,33 +1003,28 @@ class RedBrowser extends DAV\Browser\Plugin {
$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>";
$html.= "<tr>
<td>$icon</td>
<td style=\"min-width: 15em\"><a href=\"{$fullPath}\">{$displayName}</a></td>";
if($is_owner) {
$html .= "<td>" . (($size) ? $attachIcon : '') . "</td>
<td><a href=\"".$fileStorageUrl."/".$attachId."/edit\" title=\"".t('Edit')."\"><i class=\"icon-pencil btn btn-default\"></i></a></td>
<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>";
}
else {
$html .= "<td></td><td></td><td></td>";
}
$html .=
"<td>{$type}</td>
<td>". $this->userReadableSize($size) ."</td>
<td>" . (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(),$lastmodified) : '') . "</td>
</tr>";
// put the array for this file together
$ft['attachId'] = $this->findAttachIdByHash($attachHash);
$ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath,"cloud/")) ."filestorage/".$this->auth->channel_name;
$ft['icon'] = $icon;
$ft['attachIcon'] = (($size) ? $attachIcon : '');
// is global or per item?
$ft['is_owner'] = $is_owner;
$ft['fullPath'] = $fullPath;
$ft['displayName'] = $displayName;
$ft['type'] = $type;
$ft['size'] = $size;
$ft['sizeFormatted'] = $this->userReadableSize($size);
$ft['lastmodified'] = (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '');
$f[] = $ft;
}
$html.= "<tr><td colspan=\"8\"><hr /></td></tr>
</table>";
$limit = service_class_fetch ($owner,'attach_upload_limit');
// Storage and Quota
$limit = service_class_fetch($owner, 'attach_upload_limit');
$r = q("select sum(filesize) as total from attach where aid = %d ",
intval($this->auth->channel_account_id)
);
@ -1067,9 +1041,18 @@ class RedBrowser extends DAV\Browser\Plugin {
$this->userReadableSize($limit),
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 = '';
if ($this->enablePost) {
@ -1079,9 +1062,6 @@ class RedBrowser extends DAV\Browser\Plugin {
get_app()->page['content'] = $html;
construct_page(get_app());
// return $html;
}
function userReadableSize($size){

View File

@ -0,0 +1,48 @@
<h1>{{$header}}</h1>
<table id="cloud-index">
<tr>
<th></th>
<th>{{t('Name')}}&nbsp;&nbsp;&nbsp;</th>
<th></th><th></th><th></th>
<th>{{t('Type')}}&nbsp;&nbsp;&nbsp;</th>
<th>{{t('Size')}}&nbsp;&nbsp;&nbsp;</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}}