From b9723aa85bb10347ca28df0e15b16dabea11ec1d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 24 Sep 2015 14:07:44 +0200 Subject: some heavy private mail restructuring - work in progress --- include/message.php | 34 ++++--- include/nav.php | 8 +- include/widgets.php | 97 ++++++++++++++++++- mod/mail.php | 199 ++++++++++++++++++++------------------ mod/message.php | 37 +++++-- view/css/widgets.css | 1 + view/js/mod_mail.js | 1 - view/pdl/mod_mail.pdl | 3 +- view/theme/redbasic/css/style.css | 4 + view/tpl/mail_display.tpl | 2 + view/tpl/mail_head.tpl | 16 ++- view/tpl/mail_list.tpl | 13 +-- view/tpl/message_side.tpl | 11 ++- 13 files changed, 285 insertions(+), 141 deletions(-) diff --git a/include/message.php b/include/message.php index efe1a7710..4b0236db8 100644 --- a/include/message.php +++ b/include/message.php @@ -262,18 +262,30 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { ); if(! $x) return array(); - if($mailbox === 'inbox') - $where = " and sender_xchan != '" . dbesc($x[0]['channel_hash']) . "' "; - elseif($mailbox === 'outbox') - $where = " and sender_xchan = '" . dbesc($x[0]['channel_hash']) . "' "; + + $channel_hash = dbesc($x[0]['channel_hash']); + $local_channel = intval(local_channel()); + + switch($mailbox) { + + case 'inbox': + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan != '$channel_hash' ORDER BY created DESC $limit"; + break; + + case 'outbox': + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan = '$channel_hash' ORDER BY created DESC $limit"; + break; + + case 'combined': + $sql = "SELECT * FROM ( SELECT * FROM mail WHERE channel_id = $local_channel ORDER BY created DESC $limit ) AS temp_table GROUP BY parent_mid ORDER BY created DESC"; + break; + + } + } - // For different orderings, consider applying usort on the results. We thought of doing that - // inside this function or having some preset sorts, but don't wish to limit app developers. - - $r = q("SELECT * from mail WHERE channel_id = %d $where order by created desc $limit", - intval(local_channel()) - ); + $r = q($sql); + if(! $r) { return array(); } @@ -437,4 +449,4 @@ function private_messages_fetch_conversation($channel_id, $messageitem_id, $upda return $messages; -} \ No newline at end of file +} diff --git a/include/nav.php b/include/nav.php index 972795e83..1630c4731 100644 --- a/include/nav.php +++ b/include/nav.php @@ -185,11 +185,11 @@ EOT; $nav['notifications']['all']=array('notifications/system', t('See all notifications'), "", ""); $nav['notifications']['mark'] = array('', t('Mark all system notifications seen'), '',''); - $nav['messages'] = array('message', t('Mail'), "", t('Private mail'),'mail_nav_btn'); - $nav['messages']['all']=array('message', t('See all private messages'), "", ""); + $nav['messages'] = array('mail/combined', t('Mail'), "", t('Private mail'),'mail_nav_btn'); + $nav['messages']['all']=array('mail/combined', t('See all private messages'), "", ""); $nav['messages']['mark'] = array('', t('Mark all private messages seen'), '',''); - $nav['messages']['inbox'] = array('message', t('Inbox'), "", t('Inbox')); - $nav['messages']['outbox']= array('message/sent', t('Outbox'), "", t('Outbox')); + $nav['messages']['inbox'] = array('mail/inbox', t('Inbox'), "", t('Inbox')); + $nav['messages']['outbox']= array('mail/outbox', t('Outbox'), "", t('Outbox')); $nav['messages']['new'] = array('mail/new', t('New Message'), "", t('New Message')); diff --git a/include/widgets.php b/include/widgets.php index 5e40bf54a..9f8b88d54 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -562,14 +562,30 @@ function widget_mailmenu($arr) { return; $a = get_app(); + return replace_macros(get_markup_template('message_side.tpl'), array( - '$title' => t('Messages'), - '$tabs'=> array(), + '$title' => t('Private Mail Menu'), '$check'=>array( 'label' => t('Check Mail'), - 'url' => $a->get_baseurl(true) . '/message', + 'url' => $a->get_baseurl(true) . '/mail/combined', 'sel' => (argv(1) == ''), ), + + '$combined'=>array( + 'label' => t('Combined View'), + 'url' => $a->get_baseurl(true) . '/mail/combined', + 'sel' => (argv(1) == 'combined'), + ), + '$inbox'=>array( + 'label' => t('Inbox'), + 'url' => $a->get_baseurl(true) . '/mail/inbox', + 'sel' => (argv(1) == 'inbox'), + ), + '$outbox'=>array( + 'label' => t('Outbox'), + 'url' => $a->get_baseurl(true) . '/mail/outbox', + 'sel' => (argv(1) == 'outbox'), + ), '$new'=>array( 'label' => t('New Message'), 'url' => $a->get_baseurl(true) . '/mail/new', @@ -578,6 +594,78 @@ function widget_mailmenu($arr) { )); } + +function widget_conversations($arr) { + if (! local_channel()) + return; + + $a = get_app(); + + if(argc() > 1) { + + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + $header = t('Conversations'); + break; + 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; + } + + require_once('include/message.php'); + + // private_messages_list() can do other more complicated stuff, for now keep it simple + $r = private_messages_list(local_channel(), $mailbox, $a->pager['start'], $a->pager['itemspage']); + + if(! $r) { + info( t('No messages.') . EOL); + return $o; + } + + $messages = array(); + + foreach($r as $rr) { + + $messages[] = array( + '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'] : '' . $rr['title'] . ''), + 'delete' => t('Delete conversation'), + 'body' => $rr['body'], + 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')), + 'seen' => $rr['seen'] + ); + } + + $tpl = get_markup_template('mail_head.tpl'); + $o .= replace_macros($tpl, array( + '$header' => $header, + '$messages' => $messages + )); + + $o .= alt_pager($a,count($r)); + + } + + return $o; +} + + function widget_design_tools($arr) { $a = get_app(); @@ -594,6 +682,7 @@ function widget_design_tools($arr) { return design_tools(); } + function widget_findpeople($arr) { return findpeople_widget(); } @@ -1135,4 +1224,4 @@ function widget_admin($arr) { return $o; -} \ No newline at end of file +} diff --git a/mod/mail.php b/mod/mail.php index 80d7f477d..2e7e3699a 100644 --- a/mod/mail.php +++ b/mod/mail.php @@ -101,7 +101,7 @@ function mail_post(&$a) { notice($ret['message']); } - goaway(z_root() . '/message'); + goaway(z_root() . '/mail/combined'); } @@ -137,7 +137,7 @@ function mail_content(&$a) { if($r) { info( t('Message deleted.') . EOL ); } - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/combined' ); } if((argc() == 3) && (argv(1) === 'recall')) { @@ -153,7 +153,7 @@ function mail_content(&$a) { if($r) { info( t('Message recalled.') . EOL ); } - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/combined' ); } @@ -249,117 +249,128 @@ function mail_content(&$a) { return $o; } + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + break; + case 'inbox': + $mailbox = 'inbox'; + break; + case 'outbox': + $mailbox = 'outbox'; + break; + default: + $mailbox = 'combined'; + break; + } - if((argc() > 1) && (intval(argv(1)))) { + $last_message = private_messages_list(local_channel(), $mailbox, 0, 1); - $o .= $header; + $mid = ((argc() > 1) && (intval(argv(1)))) ? argv(1) : $last_message[0]['id']; - $plaintext = true; + $plaintext = true; -// if( local_channel() && feature_enabled(local_channel(),'richtext') ) -// $plaintext = false; +// if( local_channel() && feature_enabled(local_channel(),'richtext') ) +// $plaintext = false; - $messages = private_messages_fetch_conversation(local_channel(), argv(1), true); + $messages = private_messages_fetch_conversation(local_channel(), $mid, true); - if(! $messages) { - info( t('Message not found.') . EOL); - return $o; - } + if(! $messages) { + //info( t('Message not found.') . EOL); + return; + } - if($messages[0]['to_xchan'] === $channel['channel_hash']) - $a->poi = $messages[0]['from']; - else - $a->poi = $messages[0]['to']; + if($messages[0]['to_xchan'] === $channel['channel_hash']) + $a->poi = $messages[0]['from']; + else + $a->poi = $messages[0]['to']; -// require_once('include/Contact.php'); +// require_once('include/Contact.php'); -// $a->set_widget('mail_conversant',vcard_from_xchan($a->poi,$get_observer_hash,'mail')); +// $a->set_widget('mail_conversant',vcard_from_xchan($a->poi,$get_observer_hash,'mail')); - $tpl = get_markup_template('msg-header.tpl'); + $tpl = get_markup_template('msg-header.tpl'); - $a->page['htmlhead'] .= replace_macros($tpl, array( - '$nickname' => $channel['channel_address'], - '$baseurl' => $a->get_baseurl(true), - '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), - '$linkurl' => t('Please enter a link URL:'), - '$expireswhen' => t('Expires YYYY-MM-DD HH:MM') - )); - + $a->page['htmlhead'] .= replace_macros($tpl, array( + '$nickname' => $channel['channel_address'], + '$baseurl' => $a->get_baseurl(true), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$linkurl' => t('Please enter a link URL:'), + '$expireswhen' => t('Expires YYYY-MM-DD HH:MM') + )); - $mails = array(); - $seen = 0; - $unknown = false; - - foreach($messages as $message) { - - $s = theme_attachments($message); - - $mails[] = array( - 'id' => $message['id'], - 'from_name' => $message['from']['xchan_name'], - 'from_url' => chanlink_hash($message['from_xchan']), - 'from_photo' => $message['from']['xchan_photo_m'], - 'to_name' => $message['to']['xchan_name'], - 'to_url' => chanlink_hash($message['to_xchan']), - 'to_photo' => $message['to']['xchan_photo_m'], - 'subject' => $message['title'], - 'body' => smilies(bbcode($message['body']) . $s), - 'delete' => t('Delete message'), - 'recall' => t('Recall message'), - 'can_recall' => (($channel['channel_hash'] == $message['from_xchan']) ? true : false), - 'is_recalled' => (intval($message['mail_recalled']) ? t('Message has been recalled.') : ''), - 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), - ); + $mails = array(); + + $seen = 0; + $unknown = false; + + foreach($messages as $message) { + + $s = theme_attachments($message); + + $mails[] = array( + 'id' => $message['id'], + 'from_name' => $message['from']['xchan_name'], + 'from_url' => chanlink_hash($message['from_xchan']), + 'from_photo' => $message['from']['xchan_photo_m'], + 'to_name' => $message['to']['xchan_name'], + 'to_url' => chanlink_hash($message['to_xchan']), + 'to_photo' => $message['to']['xchan_photo_m'], + 'subject' => $message['title'], + 'body' => smilies(bbcode($message['body']) . $s), + 'delete' => t('Delete message'), + 'recall' => t('Recall message'), + 'can_recall' => (($channel['channel_hash'] == $message['from_xchan']) ? true : false), + 'is_recalled' => (intval($message['mail_recalled']) ? t('Message has been recalled.') : ''), + 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), + ); - $seen = $message['seen']; + $seen = $message['seen']; - } + } - $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); + $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); // FIXME - move this HTML to template - $select = $message[$recp]['xchan_name'] . ''; - $parent = ''; - - $tpl = get_markup_template('mail_display.tpl'); - $o = replace_macros($tpl, array( - '$prvmsg_header' => t('Private Conversation'), - '$thread_id' => $a->argv[1], - '$thread_subject' => $message['title'], - '$thread_seen' => $seen, - '$delete' => t('Delete conversation'), - '$canreply' => (($unknown) ? false : '1'), - '$unknown_text' => t("No secure communications available. You may be able to respond from the sender's profile page."), - '$mails' => $mails, + $select = $message[$recp]['xchan_name'] . ''; + $parent = ''; + $tpl = get_markup_template('mail_display.tpl'); + $o = replace_macros($tpl, array( + '$prvmsg_header' => t('Subject:') . ' ' . $message['title'], + '$thread_id' => $mid, + '$thread_subject' => $message['title'], + '$thread_seen' => $seen, + '$delete' => t('Delete Conversation'), + '$canreply' => (($unknown) ? false : '1'), + '$unknown_text' => t("No secure communications available. You may be able to respond from the sender's profile page."), + '$mails' => $mails, - // reply - '$header' => t('Send Reply'), - '$to' => t('To:'), - '$showinputs' => '', - '$subject' => t('Subject:'), - '$subjtxt' => $message['title'], - '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', - '$yourmessage' => t('Your message:'), - '$text' => '', - '$select' => $select, - '$parent' => $parent, - '$upload' => t('Upload photo'), - '$attach' => t('Attach file'), - '$insert' => t('Insert web link'), - '$submit' => t('Submit'), - '$wait' => t('Please wait'), - '$defexpire' => '', - '$feature_expire' => ((feature_enabled(local_channel(),'content_expire')) ? true : false), - '$expires' => t('Set expiration date'), - '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), - '$encrypt' => t('Encrypt text'), - '$cipher' => $cipher, - - )); + // reply + '$header' => t('Send Reply'), + '$to' => t('To:'), + '$showinputs' => '', + '$subject' => t('Subject:'), + '$subjtxt' => $message['title'], + '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', + '$yourmessage' => t('Your message:'), + '$text' => '', + '$select' => $select, + '$parent' => $parent, + '$upload' => t('Upload photo'), + '$attach' => t('Attach file'), + '$insert' => t('Insert web link'), + '$submit' => t('Submit'), + '$wait' => t('Please wait'), + '$defexpire' => '', + '$feature_expire' => ((feature_enabled(local_channel(),'content_expire')) ? true : false), + '$expires' => t('Set expiration date'), + '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), + '$encrypt' => t('Encrypt text'), + '$cipher' => $cipher, + )); - return $o; - } + return $o; } diff --git a/mod/message.php b/mod/message.php index 9f62f6b61..f8d71aa44 100644 --- a/mod/message.php +++ b/mod/message.php @@ -25,8 +25,6 @@ function message_content(&$a) { $cipher = 'aes256'; - - if((argc() == 3) && (argv(1) === 'dropconv')) { if(! intval(argv(2))) return; @@ -34,14 +32,31 @@ function message_content(&$a) { $r = private_messages_drop(local_channel(), argv(2), true); if($r) info( t('Conversation removed.') . EOL ); - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/combined' ); } - if(argc() == 1) { - +/* + if(argc() == 2) { + + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + $header = t('Conversations'); + break; + case 'inbox': + $mailbox = 'inbox'; + $header = t('Received Messages'); + break; + case 'outbox': + $mailbox = 'outbox'; + $header = t('Sent Messages'); + break; + default: + break; + } // private_messages_list() can do other more complicated stuff, for now keep it simple - $r = private_messages_list(local_channel(), '', $a->pager['start'], $a->pager['itemspage']); + $r = private_messages_list(local_channel(), $mailbox, $a->pager['start'], $a->pager['itemspage']); if(! $r) { info( t('No messages.') . EOL); @@ -51,6 +66,7 @@ function message_content(&$a) { $messages = array(); foreach($r as $rr) { + $messages[] = array( 'id' => $rr['id'], 'from_name' => $rr['from']['xchan_name'], @@ -70,14 +86,19 @@ function message_content(&$a) { $tpl = get_markup_template('mail_head.tpl'); $o = replace_macros($tpl, array( - '$header' => t('Messages'), + '$header' => $header, '$messages' => $messages )); $o .= alt_pager($a,count($r)); + return $o; - } + return; + + } +*/ + return; } diff --git a/view/css/widgets.css b/view/css/widgets.css index c1b80dabb..516e59e6f 100644 --- a/view/css/widgets.css +++ b/view/css/widgets.css @@ -122,3 +122,4 @@ li:hover .group-edit-icon { #tasklist-new-summary { width: 250px; } + diff --git a/view/js/mod_mail.js b/view/js/mod_mail.js index 16e06e6f5..704d0a460 100644 --- a/view/js/mod_mail.js +++ b/view/js/mod_mail.js @@ -2,5 +2,4 @@ $(document).ready(function() { $("#recip").contact_autocomplete(baseurl + '/acl', '', false, function(data) { $("#recip-complete").val(data.xid); }); - }); diff --git a/view/pdl/mod_mail.pdl b/view/pdl/mod_mail.pdl index d8f50ad7a..67632619e 100644 --- a/view/pdl/mod_mail.pdl +++ b/view/pdl/mod_mail.pdl @@ -1,3 +1,4 @@ [region=aside] -[widget=vcard][/widget] +[widget=mailmenu][/widget] +[widget=conversations][/widget] [/region] diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index f75808eb7..efb5b39ba 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -1305,6 +1305,10 @@ a.rconnect:hover, a.rateme:hover, div.rateme:hover { padding: 0; } +.widget .conv-participants { + color: $font_colour; +} + .notif-item a { color: #000; } diff --git a/view/tpl/mail_display.tpl b/view/tpl/mail_display.tpl index 062710f1d..bb89c96ec 100755 --- a/view/tpl/mail_display.tpl +++ b/view/tpl/mail_display.tpl @@ -1,6 +1,8 @@
+ {{$delete}}

{{$prvmsg_header}}

+
{{foreach $mails as $mail}} diff --git a/view/tpl/mail_head.tpl b/view/tpl/mail_head.tpl index 7bc854fff..d52fa40e0 100755 --- a/view/tpl/mail_head.tpl +++ b/view/tpl/mail_head.tpl @@ -1,10 +1,8 @@ -
-
-

{{$header}}

-
-
- {{foreach $messages as $message}} - {{include file="mail_list.tpl"}} - {{/foreach}} -
+
+

{{$header}}

+
diff --git a/view/tpl/mail_list.tpl b/view/tpl/mail_list.tpl index e3f8ef75c..ad042eb59 100755 --- a/view/tpl/mail_list.tpl +++ b/view/tpl/mail_list.tpl @@ -1,6 +1,7 @@ -{{$message.from_name}} -{{$message.from_name}} -{{$message.subject}} -{{$message.date}} - -
+
  • + + {{$message.subject}}
    + {{$message.from_name}} > {{$message.to_name}}
    + {{$message.date}} +
    +
  • diff --git a/view/tpl/message_side.tpl b/view/tpl/message_side.tpl index 3e32eae14..954ada215 100755 --- a/view/tpl/message_side.tpl +++ b/view/tpl/message_side.tpl @@ -1,13 +1,18 @@

    {{$title}}

    {{if $tabs}} {{/if}} -- cgit v1.2.3 From 2844f276b9af6154e36706b7fe53438352493d58 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 24 Sep 2015 16:57:17 -0700 Subject: Document the additional content export options --- include/event.php | 5 ++++- mod/tasks.php | 2 +- mod/uexport.php | 15 +++++++++++++-- view/tpl/uexport.tpl | 7 +++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/event.php b/include/event.php index f0a806dfa..e303ad232 100644 --- a/include/event.php +++ b/include/event.php @@ -755,12 +755,15 @@ function event_store_item($arr, $event) { } } + + $item_arr = array(); $prefix = ''; // $birthday = false; if($event['type'] === 'birthday') { - $prefix = t('This event has been added to your calendar.'); + if(! is_sys_channel($arr['uid'])) + $prefix = t('This event has been added to your calendar.'); // $birthday = true; // The event is created on your own site by the system, but appears to belong diff --git a/mod/tasks.php b/mod/tasks.php index ed267cc92..b1b81473b 100644 --- a/mod/tasks.php +++ b/mod/tasks.php @@ -73,7 +73,7 @@ function tasks_post(&$a) { if(! $text) return array('success' => false); $event = array(); - $event['aid'] = $channel['channel_account_id']; + $event['account'] = $channel['channel_account_id']; $event['uid'] = $channel['channel_id']; $event['event_xchan'] = $channel['channel_hash']; $event['type'] = 'task'; diff --git a/mod/uexport.php b/mod/uexport.php index df66474f1..ee22383a3 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -41,13 +41,24 @@ function uexport_init(&$a) { } function uexport_content(&$a) { + + $y = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); + + $yearurl = z_root() . '/uexport/' . $y; + $janurl = z_root() . '/uexport/' . $y . '/1'; + $impurl = '/import_items'; $o = replace_macros(get_markup_template('uexport.tpl'), array( '$title' => t('Export Channel'), '$basictitle' => t('Export Channel'), - '$basic' => t('Export your basic channel information to a small file. This acts as a backup of your connections, permissions, profile and basic data, which can be used to import your data to a new hub, but does not contain your content.'), + '$basic' => t('Export your basic channel information to a file. This acts as a backup of your connections, permissions, profile and basic data, which can be used to import your data to a new server hub, but does not contain your content.'), '$fulltitle' => t('Export Content'), - '$full' => t('Export your channel information and all the content to a JSON backup. This backs up all of your connections, permissions, profile data and the last year of posts. This file may be VERY large. Please be patient - it may take several minutes for this download to begin.'), + '$full' => t('Export your channel information and recent content to a JSON backup that can be restored or imported to another server hub. This backs up all of your connections, permissions, profile data and several months of posts. This file may be VERY large. Please be patient - it may take several minutes for this download to begin.'), '$by_year' => t('Export your posts from a given year.'), + + '$extra' => t('You may also export your posts and conversations for a particular year or month. Adjust the date in your browser location bar to select other dates. If the export fails (possibly due to memory exhaustion on your server hub), please try again selecting a more limited date range.'), + '$extra2' => sprintf( t('To select all posts for a given year, such as this year, visit %2$s'),$yearurl,$yearurl), + '$extra3' => sprintf( t('To select all posts for a given month, such as January of this year, visit %2$s'),$janurl,$janurl), + '$extra4' => sprintf( t('These content files may be imported or restored by visiting %2$s on any site containing your channel. For best results please import or restore these in date order (oldest first).'),$impurl,$impurl) )); return $o; diff --git a/view/tpl/uexport.tpl b/view/tpl/uexport.tpl index b9a1b9572..7eafd97a6 100644 --- a/view/tpl/uexport.tpl +++ b/view/tpl/uexport.tpl @@ -8,5 +8,12 @@

    {{$fulltitle}}

    {{$full}}

    + +

    {{$extra}}

    +

    {{$extra2}}

    +

    {{$extra3}}

    + +

    {{$extra4}}

    +
    -- cgit v1.2.3 From 2c665e5e4cbd5530bc979c99022a2513c67a5425 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 24 Sep 2015 17:41:05 -0700 Subject: add Diaspora (actually any external service which uses the queue) to delivery reports --- include/deliver.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/deliver.php b/include/deliver.php index 7a43e3d47..82a1ac6df 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -62,9 +62,17 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); + + q("update dreport set status = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", + dbesc('accepted for delivery'), + dbesc(datetime_convert()), + dbesc($argv[$x]) + ); + $y = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]) ); + } else { logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); -- cgit v1.2.3 From e558ddae3f0e9cae8800caf878a07f5530d2e31f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 24 Sep 2015 18:19:33 -0700 Subject: clean up the delivery reports to make them manageable, more approachable, and translateable --- mod/dreport.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/mod/dreport.php b/mod/dreport.php index a20e17372..31a6274c8 100644 --- a/mod/dreport.php +++ b/mod/dreport.php @@ -30,9 +30,48 @@ function dreport_content(&$a) { $o .= '

    ' . sprintf( t('Delivery report for %1$s'),substr($mid,0,32)) . '...' . '

    '; $o .= ''; + for($x = 0; $x < count($r); $x++ ) { + $r[$x]['name'] = escape_tags(substr($r[$x]['dreport_recip'],strpos($r[$x]['dreport_recip'],' '))); + + switch($r[$x]['dreport_result']) { + case 'channel sync processed': + $r[$x]['gravity'] = 0; + $r[$x]['dreport_result'] = t('channel sync processed'); + break; + case 'queued': + $r[$x]['gravity'] = 2; + $r[$x]['dreport_result'] = t('queued'); + break; + case 'posted': + $r[$x]['gravity'] = 3; + $r[$x]['dreport_result'] = t('posted'); + break; + case 'accepted for delivery': + $r[$x]['gravity'] = 4; + $r[$x]['dreport_result'] = t('accepted for delivery'); + break; + case 'updated': + $r[$x]['gravity'] = 5; + $r[$x]['dreport_result'] = t('updated'); + case 'update ignored': + $r[$x]['gravity'] = 6; + $r[$x]['dreport_result'] = t('update ignored'); + break; + case 'permission denied': + $r[$x]['dreport_result'] = t('permission denied'); + $r[$x]['gravity'] = 6; + break; + default: + $r[$x]['gravity'] = 1; + break; + } + } + + usort($r,'dreport_gravity_sort'); + + foreach($r as $rr) { - $name = escape_tags(substr($rr['dreport_recip'],strpos($rr['dreport_recip'],' '))); - $o .= ''; + $o .= ''; } $o .= '
    ' . $name . '' . escape_tags($rr['dreport_result']) . '' . escape_tags($rr['dreport_time']) . '
    ' . $rr['name'] . '' . escape_tags($rr['dreport_result']) . '' . escape_tags($rr['dreport_time']) . '
    '; @@ -40,4 +79,13 @@ function dreport_content(&$a) { +} + +function dreport_gravity_sort($a,$b) { + if($a['gravity'] == $b['gravity']) { + if($a['name'] === $b['name']) + return strcmp($a['dreport_time'],$b['dreport_time']); + return strcmp($a['name'],$b['name']); + } + return (($a['gravity'] > $b['gravity']) ? 1 : (-1)); } \ No newline at end of file -- cgit v1.2.3 From 98f656cfcbaf81c001802dacd593ff9548345014 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 24 Sep 2015 22:51:47 -0700 Subject: delivery optimisations --- include/deliver_hooks.php | 29 +++++++++++++++++++++++++++++ include/notifier.php | 33 +++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 include/deliver_hooks.php diff --git a/include/deliver_hooks.php b/include/deliver_hooks.php new file mode 100644 index 000000000..f0d6ba1b1 --- /dev/null +++ b/include/deliver_hooks.php @@ -0,0 +1,29 @@ += $deliveries_per_process) { proc_run('php','include/deliver.php',$deliver); @@ -684,18 +684,35 @@ function notifier_run($argv, $argc){ @time_sleep_until(microtime(true) + (float) $interval); } } + + if($normal_mode) { + $x = q("select * from hook where hook = 'notifier_normal'"); + if($x) + proc_run('php','deliver_hooks.php', $target_item['id']); + } + + if($deliveries) { + $deliver = array(); + + foreach($deliveries as $d) { + + $deliver[] = $d; + + if(count($deliver) >= $deliveries_per_process) { + proc_run('php','include/deliver.php',$deliver); + $deliver = array(); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); + } + } + } // catch any stragglers - if(count($deliver)) { + if($deliver) proc_run('php','include/deliver.php',$deliver); - } logger('notifier: basic loop complete.', LOGGER_DEBUG); - - if($normal_mode) - call_hooks('notifier_normal',$target_item); - call_hooks('notifier_end',$target_item); -- cgit v1.2.3 From 8aec437c2314758dfaedef190ecaf74245cfc9e7 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 24 Sep 2015 23:02:41 -0700 Subject: remove redundant code --- include/notifier.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index 4ce0c7c9f..3b29229cf 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -675,14 +675,8 @@ function notifier_run($argv, $argc){ ); } } - $deliveries[] = $hash; - if(count($deliver) >= $deliveries_per_process) { - proc_run('php','include/deliver.php',$deliver); - $deliver = array(); - if($interval) - @time_sleep_until(microtime(true) + (float) $interval); - } + $deliveries[] = $hash; } if($normal_mode) { -- cgit v1.2.3 From ba94f824b992f9ed787a71c2956388e975058ca8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 25 Sep 2015 01:31:58 -0700 Subject: deliveries per process ui for setting --- mod/admin.php | 3 +++ view/tpl/admin_site.tpl | 1 + 2 files changed, 4 insertions(+) diff --git a/mod/admin.php b/mod/admin.php index 2b7bb007d..7d7c50dcf 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -254,6 +254,7 @@ function admin_page_site_post(&$a){ $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); + $delivery_batch_count = ((x($_POST,'delivery_batch_count') && $_POST['delivery_batch_count'] > 0)? intval(trim($_POST['delivery_batch_count'])) : 1); $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); @@ -261,6 +262,7 @@ function admin_page_site_post(&$a){ set_config('system', 'feed_contacts', $feed_contacts); set_config('system', 'delivery_interval', $delivery_interval); + set_config('system', 'delivery_batch_count', $delivery_batch_count); set_config('system', 'poll_interval', $poll_interval); set_config('system', 'maxloadavg', $maxloadavg); set_config('system', 'frontpage', $frontpage); @@ -442,6 +444,7 @@ function admin_page_site(&$a) { '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), + '$delivery_batch_count' => array('delivery_batch_count', t('Deliveries per process'),(x(get_config('system','delivery_batch_count'))?get_config('system','delivery_batch_count'):1), t("Number of deliveries to attempt in a single operating system process. Adjust if necessary to tune system performance. Recommend: 1-5.")), '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$default_expire_days' => array('default_expire_days', t('Expiration period in days for imported (matrix/network) content'), intval(get_config('system','default_expire_days')), t('0 for no expiration of imported content')), diff --git a/view/tpl/admin_site.tpl b/view/tpl/admin_site.tpl index e2ce3c552..26434b20a 100755 --- a/view/tpl/admin_site.tpl +++ b/view/tpl/admin_site.tpl @@ -78,6 +78,7 @@ {{include file="field_input.tpl" field=$proxyuser}} {{include file="field_input.tpl" field=$timeout}} {{include file="field_input.tpl" field=$delivery_interval}} + {{include file="field_input.tpl" field=$delivery_batch_count}} {{include file="field_input.tpl" field=$poll_interval}} {{include file="field_input.tpl" field=$maxloadavg}} {{include file="field_input.tpl" field=$abandon_days}} -- cgit v1.2.3