diff options
Diffstat (limited to 'Zotlabs/Widget')
-rw-r--r-- | Zotlabs/Widget/Conversations.php | 175 | ||||
-rw-r--r-- | Zotlabs/Widget/Dirtags.php | 2 | ||||
-rw-r--r-- | Zotlabs/Widget/Hq_controls.php | 40 | ||||
-rw-r--r-- | Zotlabs/Widget/Mailmenu.php | 4 | ||||
-rw-r--r-- | Zotlabs/Widget/Messages.php | 181 | ||||
-rw-r--r-- | Zotlabs/Widget/Notes.php | 3 | ||||
-rw-r--r-- | Zotlabs/Widget/Notifications.php | 55 |
7 files changed, 366 insertions, 94 deletions
diff --git a/Zotlabs/Widget/Conversations.php b/Zotlabs/Widget/Conversations.php index 267d50fa0..3dc260b50 100644 --- a/Zotlabs/Widget/Conversations.php +++ b/Zotlabs/Widget/Conversations.php @@ -9,67 +9,154 @@ class Conversations { if (! local_channel()) return; - if(argc() > 1) { + switch(argv(1)) { + case 'inbox': + $mailbox = 'inbox'; + $header = t('Received Messages'); + break; + case 'outbox': + $mailbox = 'outbox'; + $header = t('Sent Messages'); + break; + default: + $mailbox = 'combined'; + $header = t('Conversations'); + break; + } + + $o = ''; + + // private_messages_list() can do other more complicated stuff, for now keep it simple + $r = self::private_messages_list(local_channel(), $mailbox, \App::$pager['start'], \App::$pager['itemspage']); + + if(! $r) { + info( t('No messages.') . EOL); + return $o; + } + + $messages = []; + + foreach($r as $rr) { + + $selected = ((argc() == 3) ? intval(argv(2)) == intval($rr['id']) : $r[0]['id'] == $rr['id']); + + $messages[] = [ + 'mailbox' => $mailbox, + 'id' => $rr['id'], + 'from_name' => $rr['from']['xchan_name'], + 'from_url' => chanlink_hash($rr['from_xchan']), + 'from_photo' => $rr['from']['xchan_photo_s'], + 'to_name' => $rr['to']['xchan_name'], + 'to_url' => chanlink_hash($rr['to_xchan']), + 'to_photo' => $rr['to']['xchan_photo_s'], + 'subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'), + 'delete' => t('Delete conversation'), + 'body' => $rr['body'], + 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], 'c'), + 'seen' => $rr['seen'], + 'selected' => ((argv(1) != 'new') ? $selected : '') + ]; + } + + $tpl = get_markup_template('mail_head.tpl'); + $o .= replace_macros($tpl, [ + '$header' => $header, + '$messages' => $messages + ]); + + return $o; + } + + function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { + + $where = ''; + $limit = ''; + + $t0 = dba_timer(); + + if($numitems) + $limit = " LIMIT " . intval($numitems) . " OFFSET " . intval($start); + + if($mailbox !== '') { + $x = q("select channel_hash from channel where channel_id = %d limit 1", + intval($uid) + ); + + if(! $x) + return array(); + + $channel_hash = dbesc($x[0]['channel_hash']); + $local_channel = intval(local_channel()); + + switch($mailbox) { - switch(argv(1)) { case 'inbox': - $mailbox = 'inbox'; - $header = t('Received Messages'); + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan != '$channel_hash' ORDER BY created DESC $limit"; break; + case 'outbox': - $mailbox = 'outbox'; - $header = t('Sent Messages'); + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan = '$channel_hash' ORDER BY created DESC $limit"; break; + + case 'combined': default: - $mailbox = 'combined'; - $header = t('Conversations'); + $parents = q("SELECT mail.parent_mid FROM mail LEFT JOIN conv ON mail.conv_guid = conv.guid WHERE mail.mid = mail.parent_mid AND mail.channel_id = %d ORDER BY conv.updated DESC $limit", + intval($local_channel) + ); break; } - require_once('include/message.php'); + } - $o = ''; + $r = null; - // private_messages_list() can do other more complicated stuff, for now keep it simple - $r = private_messages_list(local_channel(), $mailbox, \App::$pager['start'], \App::$pager['itemspage']); + if($parents) { + foreach($parents as $parent) { + $all = q("SELECT * FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY created DESC limit 1", + dbesc($parent['parent_mid']), + intval($local_channel) + ); - if(! $r) { - info( t('No messages.') . EOL); - return $o; + if($all) { + foreach($all as $single) { + $r[] = $single; + } + } } + } + elseif($sql) { + $r = q($sql); + } - $messages = []; - - foreach($r as $rr) { - - $selected = ((argc() == 3) ? intval(argv(2)) == intval($rr['id']) : $r[0]['id'] == $rr['id']); - - $messages[] = [ - 'mailbox' => $mailbox, - 'id' => $rr['id'], - 'from_name' => $rr['from']['xchan_name'], - 'from_url' => chanlink_hash($rr['from_xchan']), - 'from_photo' => $rr['from']['xchan_photo_s'], - 'to_name' => $rr['to']['xchan_name'], - 'to_url' => chanlink_hash($rr['to_xchan']), - 'to_photo' => $rr['to']['xchan_photo_s'], - 'subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'), - 'delete' => t('Delete conversation'), - 'body' => $rr['body'], - 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], 'c'), - 'seen' => $rr['seen'], - 'selected' => ((argv(1) != 'new') ? $selected : '') - ]; - } + if(! $r) { + return array(); + } - $tpl = get_markup_template('mail_head.tpl'); - $o .= replace_macros($tpl, [ - '$header' => $header, - '$messages' => $messages - ]); + $chans = array(); + foreach($r as $rr) { + $s = "'" . dbesc(trim($rr['from_xchan'])) . "'"; + if(! in_array($s,$chans)) + $chans[] = $s; + $s = "'" . dbesc(trim($rr['to_xchan'])) . "'"; + if(! in_array($s,$chans)) + $chans[] = $s; + } + $c = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$chans)) . ")"); + + foreach($r as $k => $rr) { + $r[$k]['from'] = find_xchan_in_array($rr['from_xchan'],$c); + $r[$k]['to'] = find_xchan_in_array($rr['to_xchan'],$c); + $r[$k]['seen'] = intval($rr['mail_seen']); + if(intval($r[$k]['mail_obscured'])) { + if($r[$k]['title']) + $r[$k]['title'] = base64url_decode(str_rot47($r[$k]['title'])); + if($r[$k]['body']) + $r[$k]['body'] = base64url_decode(str_rot47($r[$k]['body'])); + } } - return $o; + + return $r; } } diff --git a/Zotlabs/Widget/Dirtags.php b/Zotlabs/Widget/Dirtags.php index f211d5942..246c47dde 100644 --- a/Zotlabs/Widget/Dirtags.php +++ b/Zotlabs/Widget/Dirtags.php @@ -2,8 +2,6 @@ namespace Zotlabs\Widget; -require_once('include/dir_fns.php'); - class Dirtags { function widget($arr) { diff --git a/Zotlabs/Widget/Hq_controls.php b/Zotlabs/Widget/Hq_controls.php index 0caa54a1a..8b532defe 100644 --- a/Zotlabs/Widget/Hq_controls.php +++ b/Zotlabs/Widget/Hq_controls.php @@ -2,24 +2,44 @@ namespace Zotlabs\Widget; +use Zotlabs\Lib\Apps; + + class Hq_controls { - function widget($arr) { + function widget($options) { if (! local_channel()) return; + $entries = [ + 'toggle_editor' => [ + 'label' => t('Toggle post editor'), + 'id' => 'jot-toggle', + 'href' => '#', + 'class' => 'btn btn-outline-primary', + 'type' => 'button', + 'icon' => 'pencil', + 'extra' => 'data-toggle="button"' + ] + ]; + + if(Apps::system_app_installed(local_channel(), 'Notes')) { + $entries['toggle_notes'] = [ + 'label' => t('Toggle personal notes'), + 'id' => 'notes-toggle', + 'href' => '#', + 'class' => 'btn btn-outline-primary', + 'type' => 'button', + 'icon' => 'sticky-note-o', + 'extra' => 'data-toggle="button"' + ]; + } + return replace_macros(get_markup_template('hq_controls.tpl'), [ - '$title' => t('HQ Control Panel'), - '$menu' => [ - 'create' => [ - 'label' => t('Create a new post'), - 'id' => 'jot-toggle', - 'href' => '#', - 'class' => '' - ] - ] + '$entries' => $entries, + '$wrapper_class' => $options['class'] ] ); } diff --git a/Zotlabs/Widget/Mailmenu.php b/Zotlabs/Widget/Mailmenu.php index 512f7d9c0..ca022c807 100644 --- a/Zotlabs/Widget/Mailmenu.php +++ b/Zotlabs/Widget/Mailmenu.php @@ -14,7 +14,7 @@ class Mailmenu { '$combined' => array( 'label' => t('Combined View'), 'url' => z_root() . '/mail/combined', - 'sel' => (argv(1) == 'combined'), + 'sel' => (argv(1) == 'combined' || argc() == 1), ), '$inbox' => array( 'label' => t('Inbox'), @@ -26,11 +26,13 @@ class Mailmenu { 'url' => z_root() . '/mail/outbox', 'sel' => (argv(1) == 'outbox'), ), +/* '$new' => array( 'label' => t('New Message'), 'url' => z_root() . '/mail/new', 'sel'=> (argv(1) == 'new'), ) +*/ )); } } diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php new file mode 100644 index 000000000..a03238c9a --- /dev/null +++ b/Zotlabs/Widget/Messages.php @@ -0,0 +1,181 @@ +<?php + +namespace Zotlabs\Widget; + +use App; +use Zotlabs\Lib\IConfig; + +class Messages { + + public static function widget($arr) { + if (!local_channel()) + return EMPTY_STR; + + $o = ''; + $page = self::get_messages_page($options); + + if (!$page['entries']) + return $o; + + $tpl = get_markup_template('messages_widget.tpl'); + $o .= replace_macros($tpl, [ + '$entries' => $page['entries'], + '$offset' => $page['offset'], + '$feature_star' => feature_enabled(local_channel(), 'star_posts'), + '$strings' => [ + 'messages_title' => t('Public and restricted messages'), + 'direct_messages_title' => t('Direct messages'), + 'starred_messages_title' => t('Starred messages'), + 'loading' => t('Loading') + ] + ]); + + return $o; + } + + public static function get_messages_page($options) { + if (!local_channel()) + return; + + if ($options['offset'] == -1) { + return; + } + + $channel = App::get_channel(); + $item_normal = item_normal(); + $entries = []; + $limit = 30; + + $offset = 0; + if ($options['offset']) { + $offset = intval($options['offset']); + } + + $loadtime = (($offset) ? $_SESSION['page_loadtime'] : datetime_convert()); + + switch($options['type']) { + case 'direct': + $type_sql = ' AND item_private = 2 '; + break; + case 'starred': + $type_sql = ' AND item_starred = 1 '; + break; + default: + $type_sql = ' AND item_private IN (0, 1) '; + } + + $items = q("SELECT * FROM item WHERE uid = %d + AND created <= '%s' + $type_sql + AND item_thread_top = 1 + $item_normal + ORDER BY created DESC + LIMIT $limit OFFSET $offset", + intval(local_channel()), + dbescdate($loadtime) + ); + + xchan_query($items, false); + + $i = 0; + + foreach($items as $item) { + + $info = ''; + if ($options['type'] == 'direct') { + $info .= self::get_dm_recipients($channel, $item); + } + + if($item['owner_xchan'] !== $item['author_xchan']) { + $info .= t('via') . ' ' . $item['owner']['xchan_name']; + } + + $summary = $item['title']; + if (!$summary) { + $summary = $item['summary']; + } + if (!$summary) { + $summary = htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_QUOTES, 'UTF-8', false); + } + if (!$summary) { + $summary = '...'; + } + $summary = substr_words($summary, 68); + + switch(intval($item['item_private'])) { + case 1: + $icon = '<i class="fa fa-lock"></i>'; + break; + case 2: + $icon = '<i class="fa fa-envelope-o"></i>'; + break; + default: + $icon = ''; + } + + $entries[$i]['author_name'] = $item['author']['xchan_name']; + $entries[$i]['author_addr'] = (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']); + $entries[$i]['info'] = $info; + $entries[$i]['created'] = datetime_convert('UTC', date_default_timezone_get(), $item['created']); + $entries[$i]['summary'] = $summary; + $entries[$i]['b64mid'] = gen_link_id($item['mid']); + $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); + $entries[$i]['icon'] = $icon; + + $i++; + } + + $result = [ + 'offset' => ((count($entries) < $limit) ? -1 : intval($offset + $limit)), + 'entries' => $entries + ]; + + return $result; + } + + public static function get_dm_recipients($channel, $item) { + + if($channel['channel_hash'] === $item['owner']['xchan_hash']) { + // we are the owner, get the recipients from the item + $recips = expand_acl($item['allow_cid']); + if (is_array($recips)) { + array_unshift($recips, $item['owner']['xchan_hash']); + $column = 'xchan_hash'; + } + } + else { + $recips = IConfig::Get($item, 'activitypub', 'recips'); + if (isset($recips['to']) && is_array($recips['to'])) { + $recips = $recips['to']; + array_unshift($recips, $item['owner']['xchan_url']); + $column = 'xchan_url'; + } + else { + $hookinfo = [ + 'item' => $item, + 'recips' => null, + 'column' => '' + ]; + + call_hooks('direct_message_recipients', $hookinfo); + + $recips = $hookinfo['recips']; + $column = $hookinfo['column']; + } + } + + if(is_array($recips)) { + stringify_array_elms($recips, true); + + $query_str = implode(',', $recips); + $xchans = dbq("SELECT DISTINCT xchan_name FROM xchan WHERE $column IN ($query_str)"); + + foreach($xchans as $xchan) { + $recipients .= $xchan['xchan_name'] . ', '; + } + } + + return trim($recipients, ', '); + } + +} diff --git a/Zotlabs/Widget/Notes.php b/Zotlabs/Widget/Notes.php index 238008d81..05c1a0292 100644 --- a/Zotlabs/Widget/Notes.php +++ b/Zotlabs/Widget/Notes.php @@ -21,7 +21,8 @@ class Notes { '$banner' => t('Notes'), '$text' => $text, '$save' => t('Save'), - '$app' => ((isset($arr['app'])) ? true : false) + '$app' => ((isset($arr['app'])) ? true : false), + '$hidden' => ((isset($arr['hidden'])) ? true : false) )); return $o; diff --git a/Zotlabs/Widget/Notifications.php b/Zotlabs/Widget/Notifications.php index dd5a6cd46..a818ae40a 100644 --- a/Zotlabs/Widget/Notifications.php +++ b/Zotlabs/Widget/Notifications.php @@ -13,11 +13,11 @@ class Notifications { 'type' => 'network', 'icon' => 'th', 'severity' => 'secondary', - 'label' => t('New Network Activity'), - 'title' => t('New Network Activity Notifications'), + 'label' => t('Network'), + 'title' => t('New network activity notifications'), 'viewall' => [ 'url' => 'network', - 'label' => t('View your network activity') + 'label' => t('Network stream') ], 'markall' => [ 'label' => t('Mark all notifications read') @@ -33,11 +33,11 @@ class Notifications { 'type' => 'home', 'icon' => 'home', 'severity' => 'danger', - 'label' => t('New Home Activity'), - 'title' => t('New Home Activity Notifications'), + 'label' => t('Home'), + 'title' => t('New home activity notifications'), 'viewall' => [ 'url' => 'channel/' . $channel['channel_address'], - 'label' => t('View your home activity') + 'label' => t('Home stream') ], 'markall' => [ 'label' => t('Mark all notifications seen') @@ -52,11 +52,11 @@ class Notifications { 'type' => 'dm', 'icon' => 'envelope', 'severity' => 'danger', - 'label' => t('New Direct Messages'), - 'title' => t('New Direct Messages Notifications'), + 'label' => t('Direct Messages'), + 'title' => t('New direct messages notifications'), 'viewall' => [ 'url' => 'network/?dm=1', - 'label' => t('View your direct messages') + 'label' => t('Direct messages stream') ], 'markall' => [ 'label' => t('Mark all notifications read') @@ -68,26 +68,11 @@ class Notifications { ]; $notifications[] = [ - 'type' => 'mail', - 'icon' => 'envelope', - 'severity' => 'danger', - 'label' => t('New Mails'), - 'title' => t('New Mails Notifications'), - 'viewall' => [ - 'url' => 'mail/combined', - 'label' => t('View your private mails') - ], - 'markall' => [ - 'label' => t('Mark all messages seen') - ] - ]; - - $notifications[] = [ 'type' => 'all_events', 'icon' => 'calendar', 'severity' => 'secondary', - 'label' => t('New Events'), - 'title' => t('New Events Notifications'), + 'label' => t('Events'), + 'title' => t('New events notifications'), 'viewall' => [ 'url' => 'cdav/calendar', 'label' => t('View events') @@ -102,7 +87,7 @@ class Notifications { 'icon' => 'users', 'severity' => 'danger', 'label' => t('New Connections'), - 'title' => t('New Connections Notifications'), + 'title' => t('New connections notifications'), 'viewall' => [ 'url' => 'connections', 'label' => t('View all connections') @@ -113,8 +98,8 @@ class Notifications { 'type' => 'files', 'icon' => 'folder', 'severity' => 'danger', - 'label' => t('New Files'), - 'title' => t('New Files Notifications'), + 'label' => t('Files'), + 'title' => t('New files notifications'), ]; $notifications[] = [ @@ -149,8 +134,8 @@ class Notifications { 'type' => 'register', 'icon' => 'user-o', 'severity' => 'danger', - 'label' => t('New Registrations'), - 'title' => t('New Registrations Notifications'), + 'label' => t('Registrations'), + 'title' => t('New registrations notifications'), ]; } @@ -160,10 +145,10 @@ class Notifications { 'icon' => 'globe', 'severity' => 'secondary', 'label' => t('Public Stream'), - 'title' => t('Public Stream Notifications'), + 'title' => t('New public stream notifications'), 'viewall' => [ 'url' => 'pubstream', - 'label' => t('View the public stream') + 'label' => t('Public stream') ], 'markall' => [ 'label' => t('Mark all notifications seen') @@ -176,15 +161,13 @@ class Notifications { } $o = replace_macros(get_markup_template('notifications_widget.tpl'), [ - '$module' => \App::$module, '$notifications' => $notifications, '$no_notifications' => t('Sorry, you have got no notifications at the moment'), '$loading' => t('Loading'), - '$startpage' => ($channel ? $channel['channel_startpage'] : '') ]); return $o; } } - + |