From b4e83b65375e62259671749c089d9cd7a2a2967a Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Oct 2015 22:14:19 +0200 Subject: [PATCH] allow photo-items to appear full width if large photos feature is enabled. in prepare_body() split off mentions, tags, categories folders and attachments from body for easier theming. some other little fixes. --- include/ItemObject.php | 16 ++++-- include/conversation.php | 32 +++++------ include/items.php | 2 + include/photos.php | 2 +- include/text.php | 88 ++++++++++++++----------------- mod/photos.php | 3 +- view/css/conversation.css | 22 +++----- view/theme/redbasic/css/style.css | 22 ++------ view/tpl/conv_item.tpl | 49 ++++++++++------- view/tpl/item_attach.tpl | 9 ++-- view/tpl/item_categories.tpl | 2 +- view/tpl/search_item.tpl | 85 +++++++++++++++++++---------- 12 files changed, 179 insertions(+), 153 deletions(-) diff --git a/include/ItemObject.php b/include/ItemObject.php index 5296a1cf0..46bb78ecd 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -278,13 +278,21 @@ class Item extends BaseObject { $children = $this->get_children(); + $is_photo = (($item['resource_type'] == 'photo') ? true : false) && feature_enabled($conv->get_profile_owner(),'large_photos'); + + $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false); + $tmp_item = array( 'template' => $this->get_template(), 'mode' => $mode, 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), - 'tags' => array(), - 'body' => $body, - 'text' => strip_tags($body), + 'body' => $body['html'], + 'tags' => $body['tags'], + 'categories' => $body['categories'], + 'mentions' => $body['mentions'], + 'attachments' => $body['attachments'], + 'folders' => $body['folders'], + 'text' => strip_tags($body['html']), 'id' => $this->get_id(), 'mid' => $item['mid'], 'isevent' => $isevent, @@ -325,6 +333,8 @@ class Item extends BaseObject { 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), + 'is_photo' => $is_photo, + 'has_tags' => $has_tags, // Item toolbar buttons 'like' => $like, diff --git a/include/conversation.php b/include/conversation.php index 0f6f8685b..0d357e2eb 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -629,11 +629,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; - - $tags=array(); - $hashtags = array(); - $mentions = array(); - $sp = false; $profile_link = best_link_url($item,$sp); if($sp) @@ -678,14 +673,17 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $unverified = ''; - $tags=array(); - $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN)); - if(count($terms)) - foreach($terms as $tag) - $tags[] = format_term_for_display($tag); +// $tags=array(); +// $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN)); +// if(count($terms)) +// foreach($terms as $tag) +// $tags[] = format_term_for_display($tag); $body = prepare_body($item,true); + $is_photo = (($item['resource_type'] == 'photo') ? true : false); + $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false); + $tmp_item = array( 'template' => $tpl, 'toplevel' => 'toplevel_item', @@ -699,10 +697,12 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'lock' => $lock, 'thumb' => $profile_avatar, 'title' => $item['title'], - 'body' => $body, - 'tags' => $tags, - 'hashtags' => $hashtags, - 'mentions' => $mentions, + 'body' => $body['html'], + 'tags' => $body['tags'], + 'categories' => $body['categories'], + 'mentions' => $body['mentions'], + 'attachments' => $body['attachments'], + 'folders' => $body['folders'], 'verified' => $verified, 'unverified' => $unverified, 'forged' => $forged, @@ -712,7 +712,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'has_folders' => ((count($folders)) ? 'true' : ''), 'categories' => $categories, 'folders' => $folders, - 'text' => strip_tags($body), + 'text' => strip_tags($body['html']), 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf( t('from %s'), $item['app']), @@ -738,6 +738,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'previewing' => $previewing, 'wait' => t('Please wait'), 'thread_level' => 1, + 'is_photo' => $is_photo, + 'has_tags' => $has_tags, ); $arr = array('item' => $item, 'output' => $tmp_item); diff --git a/include/items.php b/include/items.php index e7cc02579..3b0072956 100755 --- a/include/items.php +++ b/include/items.php @@ -889,6 +889,7 @@ function get_item_elements($x,$allow_code = false) { $arr['mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'], ENT_COMPAT,'UTF-8',false) : ''); $arr['obj_type'] = (($x['object_type']) ? htmlspecialchars($x['object_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['tgt_type'] = (($x['target_type']) ? htmlspecialchars($x['target_type'], ENT_COMPAT,'UTF-8',false) : ''); + $arr['resource_type'] = (($x['resource_type']) ? htmlspecialchars($x['resource_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['public_policy'] = (($x['public_scope']) ? htmlspecialchars($x['public_scope'], ENT_COMPAT,'UTF-8',false) : ''); if($arr['public_policy'] === 'public') @@ -1285,6 +1286,7 @@ function encode_item($item,$mirror = false) { $x['verb'] = $item['verb']; $x['object_type'] = $item['obj_type']; $x['target_type'] = $item['tgt_type']; + $x['resource_type'] = $item['resource_type']; $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; diff --git a/include/photos.php b/include/photos.php index 49aab6865..c0917ce28 100644 --- a/include/photos.php +++ b/include/photos.php @@ -281,7 +281,7 @@ function photo_upload($channel, $observer, $args) { } } else { - $title = ''; + $title = $args['filename'] ? $args['filename'] : ''; $mid = item_message_id(); $arr = array(); diff --git a/include/text.php b/include/text.php index 205736502..0354402af 100644 --- a/include/text.php +++ b/include/text.php @@ -1216,36 +1216,13 @@ function theme_attachments(&$item) { if(is_array($arr) && count($arr)) { $attaches = array(); foreach($arr as $r) { - $icon = ''; - $icontype = substr($r['type'],0,strpos($r['type'],'/')); - /** - * @FIXME This should probably be a giant "if" statement in the - * template so that we don't have icon names embedded in php code. - */ + $icon = getIconFromType($r['type']); - switch($icontype) { - case 'video': - $icon = 'icon-facetime-video'; - break; - case 'audio': - $icon = 'icon-volume-up'; - break; - case 'image': - $icon = 'icon-picture'; - break; - case 'text': - $icon = 'icon-align-justify'; - break; - default: - $icon = 'icon-question'; - break; - } - - $title = htmlspecialchars($r['title'], ENT_COMPAT,'UTF-8'); + $label = urldecode(htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8')); if(! $title) $title = t('unknown.???'); - $title .= ' ' . (($r['length']) ? $r['length'] . ' ' . t('bytes') : ''); + $title = t('Attachment') . (($r['length']) ? ' ' . userReadableSize($r['length']) : ''); require_once('include/identity.php'); if(is_foreigner($item['author_xchan'])) @@ -1253,14 +1230,14 @@ function theme_attachments(&$item) { else $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision']; - $s .= '' . $icon . ''; - $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon ); + //$s .= '' . $icon . ''; + $attaches[] = array('label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title); } - } - $s = replace_macros(get_markup_template('item_attach.tpl'), array( - '$attaches' => $attaches - )); + $s = replace_macros(get_markup_template('item_attach.tpl'), array( + '$attaches' => $attaches + )); + } return $s; } @@ -1279,11 +1256,12 @@ function format_categories(&$item,$writeable) { $removelink = (($writeable) ? z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . urlencode($t['term']) : ''); $categories[] = array('term' => $term, 'writeable' => $writeable, 'removelink' => $removelink, 'url' => zid($t['url'])); } + + $s = replace_macros(get_markup_template('item_categories.tpl'),array( + '$remove' => t('remove category'), + '$categories' => $categories + )); } - $s = replace_macros(get_markup_template('item_categories.tpl'),array( - '$remove' => t('remove category'), - '$categories' => $categories - )); return $s; } @@ -1294,6 +1272,7 @@ function format_categories(&$item,$writeable) { * @param[in] array &$item * @return string HTML link of hashtag */ + function format_hashtags(&$item) { $s = ''; @@ -1354,11 +1333,12 @@ function format_filer(&$item) { $removelink = z_root() . '/filerm/' . $item['id'] . '?f=&term=' . urlencode($t['term']); $categories[] = array('term' => $term, 'removelink' => $removelink); } + + $s = replace_macros(get_markup_template('item_filer.tpl'),array( + '$remove' => t('remove from file'), + '$categories' => $categories + )); } - $s = replace_macros(get_markup_template('item_filer.tpl'),array( - '$remove' => t('remove from file'), - '$categories' => $categories - )); return $s; } @@ -1411,19 +1391,19 @@ function prepare_body(&$item,$attach = false) { } } - $s .= theme_attachments($item); + $attachments = theme_attachments($item); $writeable = ((get_observer_hash() == $item['owner_xchan']) ? true : false); - $s .= format_hashtags($item); + $tags = format_hashtags($item); if($item['resource_type']) - $s .= format_mentions($item); + $mentions = format_mentions($item); - $s .= format_categories($item,$writeable); + $categories = format_categories($item,$writeable); if(local_channel() == $item['uid']) - $s .= format_filer($item); + $filer = format_filer($item); $s = sslify($s); @@ -1456,9 +1436,19 @@ function prepare_body(&$item,$attach = false) { $s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch)); } - $prep_arr = array('item' => $item, 'html' => $s); + $prep_arr = array( + 'item' => $item, + 'html' => $s, + 'categories' => $categories, + 'folders' => $filer, + 'tags' => $tags, + 'mentions' => $mentions, + 'attachments' => $attachments + ); + call_hooks('prepare_body_final', $prep_arr); - return $prep_arr['html']; + + return $prep_arr; } /** @@ -2490,6 +2480,7 @@ function linkify_tags($a, &$body, $uid, $diaspora = false) { * * @param string $type mime type * @return string + * @todo rename to get_icon_from_type() */ function getIconFromType($type) { $iconMap = array( @@ -2542,6 +2533,7 @@ function getIconFromType($type) { * * @param int $size filesize in bytes * @return string human readable formatted filesize + * @todo rename to user_readable_size() */ function userReadableSize($size) { $ret = ''; @@ -2607,4 +2599,4 @@ function item_url_replace($channel,&$item,$old,$new) { $item['item_verified'] = 1; } -} \ No newline at end of file +} diff --git a/mod/photos.php b/mod/photos.php index cd293b39d..64e96c52c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -330,13 +330,14 @@ function photos_post(&$a) { // make sure the linked item has the same permissions as the photo regardless of any other changes - $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d + $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d, title = '%s' where id = %d", dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), intval($acl->is_private()), + dbesc($desc), intval($item_id) ); diff --git a/view/css/conversation.css b/view/css/conversation.css index 9b659ea9f..d72315fc2 100644 --- a/view/css/conversation.css +++ b/view/css/conversation.css @@ -77,6 +77,10 @@ code { /* conv_item */ +.wall-photo-item img { + width: 100%; +} + .wall-item-info { display: block; float: left; @@ -144,22 +148,8 @@ a.wall-item-name-link { word-wrap: break-word; } -.body-tag, .filesavetags, .categorytags { - opacity: 0.5; - filter:alpha(opacity=50); -} - -.body-tag:hover, .filesavetags:hover, .categorytags:hover { - opacity: 1.0 !important; - filter:alpha(opacity=100) !important; -} - -.body-tag { - margin-top: 10px; -} - -.categorytags { - margin-top: 10px; +.body-tags { + margin-top: 5px; } .item-tool { diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index 59b928ee9..b25ca333b 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -1529,22 +1529,6 @@ a .drop-icons:hover { margin-right: 10px; color: #FF0000; } - -.attachlink { - float: left; - border: 1px solid black; - padding: 5px; - margin-right: 8px; -} - -.attach-icons { - font-size: 1.4em; -} - -.attach-clip { - margin-right: 3px; - font-size: 1.8em; -} #menulist { list-style-type: none; @@ -1646,13 +1630,17 @@ img.mail-conv-sender-photo { padding: 1em 10px; } +.wall-photo-item { + padding: 10px 0px; +} + .wall-item-tools { padding: 0px 10px 10px 10px; } .wall-item-title { - font-size: $font_size; + font-size: $font_size; } .wall-item-content-wrapper { diff --git a/view/tpl/conv_item.tpl b/view/tpl/conv_item.tpl index a9661d9b5..5bac5b412 100755 --- a/view/tpl/conv_item.tpl +++ b/view/tpl/conv_item.tpl @@ -33,29 +33,42 @@
-
+
{{$item.body}} - {{if $item.tags}} -
- {{foreach $item.tags as $tag}} - {{$tag}} - {{/foreach}} -
- {{/if}} - {{if $item.has_cats}} -
- {{$item.txt_cats}} {{foreach $item.categories as $cat}}{{$cat.name}} [{{$remove}}] {{if $cat.last}}{{else}}, {{/if}}{{/foreach}} -
- {{/if}} - {{if $item.has_folders}} -
- {{$item.txt_folders}} {{foreach $item.folders as $cat}}{{$cat.name}} [{{$remove}}] {{if $cat.last}}{{else}}, {{/if}}{{/foreach}} -
- {{/if}}
+ {{if $item.has_tags}} +
+ {{if $item.mentions}} +
+ {{$item.mentions}} +
+ {{/if}} + {{if $item.tags}} +
+ {{$item.tags}} +
+ {{/if}} + {{if $item.categories}} +
+ {{$item.categories}} +
+ {{/if}} + {{if $item.folders}} +
+ {{$item.folders}} +
+ {{/if}} + {{if $item.attachments}} +
+ {{$item.attachments}} +
+ {{/if}} +
+
+ {{/if}}
{{if $item.like}} diff --git a/view/tpl/item_attach.tpl b/view/tpl/item_attach.tpl index eeea25967..7638f39e7 100644 --- a/view/tpl/item_attach.tpl +++ b/view/tpl/item_attach.tpl @@ -1,8 +1,5 @@ -
{{if $attaches}} -
- {{foreach $attaches as $a}} - - {{/foreach}} -
+{{foreach $attaches as $a}} + {{$a.label}} +{{/foreach}} {{/if}} diff --git a/view/tpl/item_categories.tpl b/view/tpl/item_categories.tpl index ec2639a6f..eea0e0b8f 100644 --- a/view/tpl/item_categories.tpl +++ b/view/tpl/item_categories.tpl @@ -1,7 +1,7 @@ {{if $categories}}
{{foreach $categories as $cat}} - {{if $cat.url}}{{$cat.term}}{{else}}{{$cat.term}}{{/if}} +{{if $cat.url}}{{$cat.term}}{{else}}{{$cat.term}}{{/if}} {{/foreach}}
{{/if}} diff --git a/view/tpl/search_item.tpl b/view/tpl/search_item.tpl index 256443b84..003dae993 100755 --- a/view/tpl/search_item.tpl +++ b/view/tpl/search_item.tpl @@ -2,33 +2,68 @@
-
-
- {{$item.name}} +
+
+
+ {{$item.name}} +
+
-
+ {{if $item.title}} +
+

{{if $item.title_tosource}}{{if $item.plink}}{{/if}}{{/if}}{{$item.title}}{{if $item.title_tosource}}{{if $item.plink}}{{/if}}{{/if}}

+
+ {{/if}} + {{if $item.lock}} + + {{/if}} +
+ {{$item.name}}{{if $item.owner_url}} {{$item.via}} {{$item.owner_name}}{{/if}} +
+
+ {{if $item.verified}} {{elseif $item.forged}} {{/if}}{{if $item.location}}{{$item.location}}, {{/if}}{{$item.localtime}}{{if $item.editedtime}} {{$item.editedtime}}{{/if}}{{if $item.expiretime}} {{$item.expiretime}}{{/if}}{{if $item.editedtime}} {{/if}} {{if $item.app}}{{$item.str_app}}{{/if}} +
+
- {{if $item.title}} -

{{$item.title}}

- {{/if}} - {{if $item.lock}} - - {{/if}} -
- {{$item.name}}{{if $item.owner_url}} {{$item.via}} {{$item.owner_name}}{{/if}} -
-
- {{if $item.verified}} {{elseif $item.forged}} {{/if}}{{if $item.location}}{{$item.location}}, {{/if}}{{$item.localtime}}{{if $item.editedtime}} {{$item.editedtime}}{{/if}}{{if $item.expiretime}} {{$item.expiretime}}{{/if}}{{if $item.editedtime}} {{/if}} {{if $item.app}}{{$item.str_app}}{{/if}} -
-
-
+
{{$item.body}}
+
-
+ {{if $item.has_tags}} +
+ {{if $item.mentions}} +
+ {{$item.mentions}} +
+ {{/if}} + {{if $item.tags}} +
+ {{$item.tags}} +
+ {{/if}} + {{if $item.categories}} +
+ {{$item.categories}} +
+ {{/if}} + {{if $item.folders}} +
+ {{$item.folders}} +
+ {{/if}} + {{if $item.attachments}} +
+ {{$item.attachments}} +
+ {{/if}} +
+
+ {{/if}} +
+
- {{* we dont' use this do we? - {{if $item.drop.pagedrop}} - - {{/if}} - *}}