aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Widget
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Widget')
-rw-r--r--Zotlabs/Widget/Hq_controls.php39
-rw-r--r--Zotlabs/Widget/Messages.php184
-rw-r--r--Zotlabs/Widget/Notes.php3
-rw-r--r--Zotlabs/Widget/Notifications.php38
4 files changed, 233 insertions, 31 deletions
diff --git a/Zotlabs/Widget/Hq_controls.php b/Zotlabs/Widget/Hq_controls.php
index 0caa54a1a..91335fd76 100644
--- a/Zotlabs/Widget/Hq_controls.php
+++ b/Zotlabs/Widget/Hq_controls.php
@@ -2,24 +2,43 @@
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'),
+ 'href' => '#',
+ 'class' => 'btn jot-toggle',
+ 'type' => 'button',
+ 'icon' => 'pencil',
+ 'extra' => 'data-toggle="button"'
+ ]
+ ];
+
+ if(Apps::system_app_installed(local_channel(), 'Notes')) {
+ $entries['toggle_notes'] = [
+ 'label' => t('Toggle personal notes'),
+ 'href' => '#',
+ 'class' => 'btn notes-toggle',
+ '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['wrapper_class'],
+ '$entry_class' => $options['entry_class']
]
);
}
diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php
new file mode 100644
index 000000000..21375b08f
--- /dev/null
+++ b/Zotlabs/Widget/Messages.php
@@ -0,0 +1,184 @@
+<?php
+
+namespace Zotlabs\Widget;
+
+use App;
+use Zotlabs\Lib\IConfig;
+
+class Messages {
+
+ public static function widget($arr) {
+ if (!local_channel())
+ return EMPTY_STR;
+
+ $page = self::get_messages_page($options);
+
+ $_SESSION['messages_loadtime'] = datetime_convert();
+
+ $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'),
+ 'empty' => t('No messages')
+ ]
+ ]);
+
+ 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;
+ $dummy_order_sql = '';
+
+ $offset = 0;
+ if ($options['offset']) {
+ $offset = intval($options['offset']);
+ }
+
+ $loadtime = (($offset) ? $_SESSION['messages_loadtime'] : datetime_convert());
+
+ switch($options['type']) {
+ case 'direct':
+ $type_sql = ' AND item_private = 2 ';
+ // $dummy_order_sql has no other meaning but to trick
+ // some mysql backends into using the right index.
+ $dummy_order_sql = ', received DESC ';
+ 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 $dummy_order_sql
+ 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'], ['drop_media' => true]), 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 d59312148..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')
@@ -71,8 +71,8 @@ class 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')
@@ -87,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')
@@ -98,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[] = [
@@ -134,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'),
];
}
@@ -145,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')
@@ -161,11 +161,9 @@ 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;