re-factor item_photo_menu - there is some room for future development, currently it was made compatible with minimal template changes

This commit is contained in:
zotlabs 2016-12-18 16:26:00 -08:00
parent e1819a874f
commit 92f3d863fa
4 changed files with 190 additions and 8 deletions

View File

@ -335,6 +335,8 @@ class ThreadItem {
'wall' => t('Wall-to-Wall'),
'vwall' => t('via Wall-To-Wall:'),
'profile_url' => $profile_link,
'thread_action_menu' => thread_action_menu($item,$conv->get_mode()),
'thread_author_menu' => thread_author_menu($item,$conv->get_mode()),
'item_photo_menu' => item_photo_menu($item),
'dreport' => $dreport,
'name' => $profile_name,

View File

@ -689,7 +689,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
'id' => (($preview) ? 'P0' : $item['item_id']),
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, $profile_url),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
'thread_action_menu' => thread_action_menu($item,$mode),
'thread_author_menu' => thread_author_menu($item,$mode),
'name' => $profile_name,
'sparkle' => $sparkle,
'lock' => $lock,
@ -960,6 +961,169 @@ function item_photo_menu($item){
return $o;
}
function thread_action_menu($item,$mode = '') {
$menu = [];
if((local_channel()) && local_channel() == $item['uid']) {
$menu[] = [
'menu' => 'view_source',
'title' => t('View Source'),
'icon' => 'eye',
'action' => 'viewsrc(' . $item['id'] . '); return false;',
'href' => '#'
];
if(! in_array($mode, [ 'network-new', 'search', 'community'])) {
if($item['parent'] == $item['id'] && (get_observer_hash() != $item['author_xchan'])) {
$menu[] = [
'menu' => 'follow_thread',
'title' => t('Follow Thread'),
'icon' => 'plus',
'action' => 'dosubthread(' . $item['id'] . '); return false;',
'href' => '#'
];
}
$menu[] = [
'menu' => 'unfollow_thread',
'title' => t('Unfollow Thread'),
'icon' => 'minus',
'action' => 'dounsubthread(' . $item['id'] . '); return false;',
'href' => '#'
];
}
}
$args = [ 'item' => $item, 'mode' => $mode, 'menu' => $menu ];
call_hooks('thread_action_menu', $args);
return $args['menu'];
}
function thread_author_menu($item, $mode = '') {
$menu = [];
$local_channel = local_channel();
if($local_channel) {
if(! count(App::$contacts))
load_contact_links($local_channel);
$channel = App::get_channel();
$channel_hash = (($channel) ? $channel['channel_hash'] : '');
}
$profile_link = chanlink_hash($item['author_xchan']);
if($item['uid'] > 0)
$pm_url = z_root() . '/mail/new/?f=&hash=' . $item['author_xchan'];
if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts))
$contact = App::$contacts[$item['author_xchan']];
else
if($local_channel && $item['author']['xchan_addr'])
$follow_url = z_root() . '/follow/?f=&url=' . $item['author']['xchan_addr'];
if($contact) {
$poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id'];
if (! intval($contact['abook_self']))
$contact_url = z_root() . '/connedit/' . $contact['abook_id'];
$posts_link = z_root() . '/network/?cid=' . $contact['abook_id'];
$clean_url = normalise_link($item['author-link']);
}
$rating_enabled = get_config('system','rating_enabled');
$ratings_url = (($rating_enabled) ? z_root() . '/ratings/' . urlencode($item['author_xchan']) : '');
if($profile_link) {
$menu[] = [
'menu' => 'view_profile',
'title' => t('View Profile'),
'icon' => 'fw',
'action' => '',
'href' => $profile_link
];
}
if($posts_link) {
$menu[] = [
'menu' => 'view_posts',
'title' => t('Activity/Posts'),
'icon' => 'fw',
'action' => '',
'href' => $posts_link
];
}
if($follow_url) {
$menu[] = [
'menu' => 'follow',
'title' => t('Connect'),
'icon' => 'fw',
'action' => '',
'href' => $follow_url
];
}
if($contact_url) {
$menu[] = [
'menu' => 'connedit',
'title' => t('Edit Connection'),
'icon' => 'fw',
'action' => '',
'href' => $contact_url
];
}
if($pm_url) {
$menu[] = [
'menu' => 'prv_message',
'title' => t('Message'),
'icon' => 'fw',
'action' => '',
'href' => $pm_url
];
}
if($ratings_url) {
$menu[] = [
'menu' => 'ratings',
'title' => t('Ratings'),
'icon' => 'fw',
'action' => '',
'href' => $ratings_url
];
}
if($poke_link) {
$menu[] = [
'menu' => 'poke',
'title' => t('Poke'),
'icon' => 'fw',
'action' => '',
'href' => $poke_link
];
}
$args = [ 'item' => $item, 'mode' => $mode, 'menu' => $menu ];
call_hooks('thread_author_menu', $args);
return $args['menu'];
}
/**
* @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
*

View File

@ -166,18 +166,27 @@
{{if $item.star}}
<li role="presentation"><a role="menuitem" href="#" onclick="dostar({{$item.id}}); return false;"><i id="starred-{{$item.id}}" class="fa fa-star {{$item.star.isstarred}}" title="{{$item.star.toggle}}"></i> {{$item.star.toggle}}</a></li>
{{/if}}
{{if $item.thread_action_menu}}
{{foreach $item.thread_action_menu as $mitem}}
<li role="presentation"><a role="menuitem" {{if $mitem.href}}href="{{$mitem.href}}"{{/if}} {{if $mitem.action}}onclick="{{$mitem.action}}"{{/if}} {{if $mitem.title}}title="{{$mitem.title}}"{{/if}} ><i class="fa fa-{{$mitem.icon}}"></i> {{$mitem.title}}</a></li>
{{/foreach}}
{{/if}}
{{if $item.drop.dropping}}
<li role="presentation"><a role="menuitem" href="#" onclick="dropItem('item/drop/{{$item.id}}', '#thread-wrapper-{{$item.id}}'); return false;" title="{{$item.drop.delete}}" ><i class="fa fa-trash-o"></i> {{$item.drop.delete}}</a></li>
{{/if}}
{{if $item.item_photo_menu}}
{{if $item.thread_author_menu}}
<li role="presentation" class="divider"></li>
{{$item.item_photo_menu}}
{{foreach $item.thread_author_menu as $mitem}}
<li role="presentation"><a role="menuitem" {{if $mitem.href}}href="{{$mitem.href}}"{{/if}} {{if $mitem.action}}onclick="{{$mitem.action}}"{{/if}} {{if $mitem.title}}title="{{$mitem.title}}"{{/if}} >{{$mitem.title}}</a></li>
{{/foreach}}
{{/if}}
{{if $item.edpost && $item.dreport}}
<li role="presentation"><a role="menuitem" href="dreport/{{$item.mid}}">{{$item.dreport}}</a></li>
{{/if}}
{{/if}}
</ul>
</div>
</div>

View File

@ -74,13 +74,20 @@
<i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
{{if $item.item_photo_menu}}
{{$item.item_photo_menu}}
{{if $item.thread_action_menu}}
{{foreach $item.thread_action_menu as $mitem}}
<li role="presentation"><a role="menuitem" {{if $mitem.href}}href="{{$mitem.href}}"{{/if}} {{if $mitem.action}}onclick="{{$mitem.action}}"{{/if}} {{if $mitem.title}}title="{{$mitem.title}}"{{/if}} ><i class="fa fa-{{$mitem.icon}}"></i> {{$mitem.title}}</a></li>
{{/foreach}}
{{/if}}
{{if $item.drop.dropping}}
<li role="presentation" class="divider"></li>
<li><a href="item/drop/{{$item.id}}" onclick="return confirmDelete();" title="{{$item.drop.delete}}" ><i class="fa fa-trash-o"></i> {{$item.drop.delete}}</a></li>
{{/if}}
{{if $item.thread_author_menu}}
<li role="presentation" class="divider"></li>
{{foreach $item.thread_author_menu as $mitem}}
<li role="presentation"><a role="menuitem" {{if $mitem.href}}href="{{$mitem.href}}"{{/if}} {{if $mitem.action}}onclick="{{$mitem.action}}"{{/if}} {{if $mitem.title}}title="{{$mitem.title}}"{{/if}} >{{$mitem.title}}</a></li>
{{/foreach}}
{{/if}}
</ul>
</div>
{{if $item.attachments}}