From 65aa6cf708a34e20ebad3c6b6dfc4088e927cce1 Mon Sep 17 00:00:00 2001 From: marijus Date: Tue, 27 Jan 2015 19:00:16 +0100 Subject: move userReadableSize() and getIconFromType() from /include/RedDAV/RedBrowser.php to include/text.php and add template for mod/sharedwithme --- include/RedDAV/RedBrowser.php | 95 ++++--------------------------------------- include/text.php | 71 ++++++++++++++++++++++++++++++++ mod/sharedwithme.php | 38 ++++++++++------- view/css/conversation.css | 4 ++ view/css/mod_sharedwithme.css | 24 +++++++++++ view/tpl/sharedwithme.tpl | 31 ++++++++++++++ 6 files changed, 161 insertions(+), 102 deletions(-) create mode 100644 view/css/mod_sharedwithme.css create mode 100644 view/tpl/sharedwithme.tpl diff --git a/include/RedDAV/RedBrowser.php b/include/RedDAV/RedBrowser.php index 5642c3f86..e893d6ebd 100644 --- a/include/RedDAV/RedBrowser.php +++ b/include/RedDAV/RedBrowser.php @@ -82,7 +82,7 @@ class RedBrowser extends DAV\Browser\Plugin { date_default_timezone_set($this->auth->getTimezone()); require_once('include/conversation.php'); - + require_once('include/text.php'); if ($this->auth->owner_nick) { $html = profile_tabs(get_app(), (($is_owner) ? true : false), $this->auth->owner_nick); } @@ -208,9 +208,9 @@ class RedBrowser extends DAV\Browser\Plugin { $ft['displayName'] = $displayName; $ft['type'] = $type; $ft['size'] = $size; - $ft['sizeFormatted'] = $this->userReadableSize($size); + $ft['sizeFormatted'] = userReadableSize($size); $ft['lastmodified'] = (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : ''); - $ft['iconFromType'] = $this->getIconFromType($type); + $ft['iconFromType'] = getIconFromType($type); $f[] = $ft; } @@ -224,13 +224,13 @@ class RedBrowser extends DAV\Browser\Plugin { if ($used) { $quotaDesc = t('%1$s used'); $quotaDesc = sprintf($quotaDesc, - $this->userReadableSize($used)); + userReadableSize($used)); } if ($limit && $used) { $quotaDesc = t('%1$s used of %2$s (%3$s%)'); $quotaDesc = sprintf($quotaDesc, - $this->userReadableSize($used), - $this->userReadableSize($limit), + userReadableSize($used), + userReadableSize($limit), round($used / $limit, 1)); } @@ -282,29 +282,6 @@ class RedBrowser extends DAV\Browser\Plugin { construct_page(get_app()); } - /** - * @brief Returns a human readable formatted string for filesizes. - * - * Don't we need such a functionality in other places, too? - * - * @param int $size filesize in bytes - * @return string - */ - function userReadableSize($size) { - $ret = ""; - if (is_numeric($size)) { - $incr = 0; - $k = 1024; - $unit = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB'); - while (($size / $k) >= 1){ - $incr++; - $size = round($size / $k, 2); - } - $ret = $size . " " . $unit[$incr]; - } - return $ret; - } - /** * @brief Creates a form to add new folders and upload files. * @@ -339,65 +316,6 @@ class RedBrowser extends DAV\Browser\Plugin { return z_root() . '/cloud/?sabreAction=asset&assetName=' . urlencode($assetName); } - /** - * @brief returns icon name for use with e.g. font-awesome based on mime-type - * - * @param string $type - * @return string - */ - protected function getIconFromType($type) { - $iconMap = array( - //Folder - t('Collection') => 'icon-folder-close', - - //Common file - 'application/octet-stream' => 'icon-file-alt', - - //Text - 'text/plain' => 'icon-file-text-alt', - 'application/msword' => 'icon-file-text-alt', - 'application/pdf' => 'icon-file-text-alt', - 'application/vnd.oasis.opendocument.text' => 'icon-file-text-alt', - 'application/epub+zip' => 'icon-book', - - //Spreadsheet - 'application/vnd.oasis.opendocument.spreadsheet' => 'icon-table', - 'application/vnd.ms-excel' => 'icon-table', - - //Image - 'image/jpeg' => 'icon-picture', - 'image/png' => 'icon-picture', - 'image/gif' => 'icon-picture', - 'image/svg+xml' => 'icon-picture', - - //Archive - 'application/zip' => 'icon-archive', - 'application/x-rar-compressed' => 'icon-archive', - - //Audio - 'audio/mpeg' => 'icon-music', - 'audio/wav' => 'icon-music', - 'application/ogg' => 'icon-music', - 'audio/ogg' => 'icon-music', - 'audio/webm' => 'icon-music', - 'audio/mp4' => 'icon-music', - - //Video - 'video/quicktime' => 'icon-film', - 'video/webm' => 'icon-film', - 'video/mp4' => 'icon-film' - ); - - $iconFromType = 'icon-file-alt'; - - if (array_key_exists($type, $iconMap)) - { - $iconFromType = $iconMap[$type]; - } - - return $iconFromType; - } - /** * @brief Return the hash of an attachment. * @@ -412,6 +330,7 @@ class RedBrowser extends DAV\Browser\Plugin { * The name of the attachment * @return string */ + protected function findAttachHash($owner, $parentHash, $attachName) { $r = q("SELECT hash FROM attach WHERE uid = %d AND folder = '%s' AND filename = '%s' ORDER BY edited DESC LIMIT 1", intval($owner), diff --git a/include/text.php b/include/text.php index 47694a17c..cfe87991c 100644 --- a/include/text.php +++ b/include/text.php @@ -2378,3 +2378,74 @@ function linkify_tags($a, &$body, $uid) { return $results; } +/** + * @brief returns icon name for use with e.g. font-awesome based on mime-type + * + * @param string $type + * @return string + */ +function getIconFromType($type) { + $iconMap = array( + //Folder + t('Collection') => 'icon-folder-close', + //Common file + 'application/octet-stream' => 'icon-file-alt', + //Text + 'text/plain' => 'icon-file-text-alt', + 'application/msword' => 'icon-file-text-alt', + 'application/pdf' => 'icon-file-text-alt', + 'application/vnd.oasis.opendocument.text' => 'icon-file-text-alt', + 'application/epub+zip' => 'icon-book', + //Spreadsheet + 'application/vnd.oasis.opendocument.spreadsheet' => 'icon-table', + 'application/vnd.ms-excel' => 'icon-table', + //Image + 'image/jpeg' => 'icon-picture', + 'image/png' => 'icon-picture', + 'image/gif' => 'icon-picture', + 'image/svg+xml' => 'icon-picture', + //Archive + 'application/zip' => 'icon-archive', + 'application/x-rar-compressed' => 'icon-archive', + //Audio + 'audio/mpeg' => 'icon-music', + 'audio/wav' => 'icon-music', + 'application/ogg' => 'icon-music', + 'audio/ogg' => 'icon-music', + 'audio/webm' => 'icon-music', + 'audio/mp4' => 'icon-music', + //Video + 'video/quicktime' => 'icon-film', + 'video/webm' => 'icon-film', + 'video/mp4' => 'icon-film' + ); + + $iconFromType = 'icon-file-alt'; + + if (array_key_exists($type, $iconMap)) { + $iconFromType = $iconMap[$type]; + } + + return $iconFromType; +} + +/** + * @brief Returns a human readable formatted string for filesizes. + * + * @param int $size filesize in bytes + * @return string + */ +function userReadableSize($size) { + $ret = ""; + if (is_numeric($size)) { + $incr = 0; + $k = 1024; + $unit = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB'); + while (($size / $k) >= 1){ + $incr++; + $size = round($size / $k, 2); + } + $ret = $size . " " . $unit[$incr]; + } + return $ret; +} diff --git a/mod/sharedwithme.php b/mod/sharedwithme.php index 8b7d2661c..56cbc35ec 100644 --- a/mod/sharedwithme.php +++ b/mod/sharedwithme.php @@ -73,27 +73,37 @@ function sharedwithme_content(&$a) { dbesc($channel['channel_hash']) ); - $o = profile_tabs($a, $is_owner, $channel['channel_address']); - - $o .= '
'; - - $o .= ' ' . t('Remove all entries') . ''; - - $o .= '

' . t('Files shared with me') . '

'; - - $o .= '
'; - - $o .= '
'; + $items =array(); if($r) { foreach($r as $rr) { $object = json_decode($rr['object'],true); - $url = rawurldecode(get_rel_link($object['link'],'alternate')); - $o .= '' . $url . ' 

'; + + $item = array(); + $item['id'] = $rr['id']; + $item['objfiletype'] = $object['filetype']; + $item['objfiletypeclass'] = getIconFromType($object['filetype']); + $item['objurl'] = rawurldecode(get_rel_link($object['link'],'alternate')) . '?f=&zid=' . $channel['xchan_addr']; + $item['objfilename'] = $object['filename']; + $item['objfilesize'] = userReadableSize($object['filesize']); + $item['objedited'] = $object['edited']; + + $items[] = $item; + } } - $o .= '
'; + $o = profile_tabs($a, $is_owner, $channel['channel_address']); + + $o .= replace_macros(get_markup_template('sharedwithme.tpl'), array( + '$header' => t('Files: shared with me'), + '$name' => t('Name'), + '$size' => t('Size'), + '$lastmod' => t('Last Modified'), + '$dropall' => t('Remove all files'), + '$drop' => t('Remove this file'), + '$items' => $items + )); return $o; diff --git a/view/css/conversation.css b/view/css/conversation.css index 7a5ffc2f7..8bc71bb6d 100644 --- a/view/css/conversation.css +++ b/view/css/conversation.css @@ -195,6 +195,10 @@ a.wall-item-name-link { clear: both; } +.shared_header { + margin-bottom: 20px; +} + /* comment_item */ .comment-edit-text-empty, .comment-edit-text-full { diff --git a/view/css/mod_sharedwithme.css b/view/css/mod_sharedwithme.css new file mode 100644 index 000000000..f1c2f5350 --- /dev/null +++ b/view/css/mod_sharedwithme.css @@ -0,0 +1,24 @@ +#cloud-index { + width: 100%; +} + +#cloud-index td:nth-child(1){ + padding: 7px 3px 7px 10px; +} + +#cloud-index th:nth-child(8), +#cloud-index td:nth-child(8){ + padding: 7px 3px; + white-space: nowrap; +} + +#cloud-index th:nth-child(9), +#cloud-index td:nth-child(9){ + padding: 7px 10px 7px 7px; + white-space: nowrap; +} + +.cloud-index-tool { + padding: 7px 10px; +} + diff --git a/view/tpl/sharedwithme.tpl b/view/tpl/sharedwithme.tpl new file mode 100644 index 000000000..3a3d7e36a --- /dev/null +++ b/view/tpl/sharedwithme.tpl @@ -0,0 +1,31 @@ +
+  {{$dropall}} +

{{$header}}

+
+
+ + + + + + + + + + {{foreach $items as $item}} + + + + + + + + + + + + + + {{/foreach}} +
{{$name}}
{{$item.objfilename}}{{*{{$item.type}}*}}
+
-- cgit v1.2.3 From 17c684e123157dc5cbfbc48854d6b9c0d1d0503b Mon Sep 17 00:00:00 2001 From: marijus Date: Tue, 27 Jan 2015 19:33:30 +0100 Subject: tpl and css cleanup --- view/css/mod_sharedwithme.css | 8 ++++---- view/tpl/sharedwithme.tpl | 9 +-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/view/css/mod_sharedwithme.css b/view/css/mod_sharedwithme.css index f1c2f5350..79fe0d7a9 100644 --- a/view/css/mod_sharedwithme.css +++ b/view/css/mod_sharedwithme.css @@ -6,14 +6,14 @@ padding: 7px 3px 7px 10px; } -#cloud-index th:nth-child(8), -#cloud-index td:nth-child(8){ +#cloud-index th:nth-child(4), +#cloud-index td:nth-child(4){ padding: 7px 3px; white-space: nowrap; } -#cloud-index th:nth-child(9), -#cloud-index td:nth-child(9){ +#cloud-index th:nth-child(5), +#cloud-index td:nth-child(5){ padding: 7px 10px 7px 7px; white-space: nowrap; } diff --git a/view/tpl/sharedwithme.tpl b/view/tpl/sharedwithme.tpl index 3a3d7e36a..1aeb9d4d7 100644 --- a/view/tpl/sharedwithme.tpl +++ b/view/tpl/sharedwithme.tpl @@ -7,7 +7,6 @@ {{$name}} - {{$size}} {{$lastmod}} @@ -16,13 +15,7 @@ {{$item.objfilename}} - - - - - - - {{*{{$item.type}}*}} + {{$item.objfilesize}} {{$item.objedited}} -- cgit v1.2.3