]> git.mxchange.org Git - friendica.git/blob - mod/message.php
ecd377b7d04994f779e58da38d4978a5f2b397a9
[friendica.git] / mod / message.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Content\Smilies;
5 use Friendica\Core\System;
6 use Friendica\Database\DBM;
7 use Friendica\Object\Contact;
8
9 require_once 'include/acl_selectors.php';
10 require_once 'include/message.php';
11
12 function message_init(App $a) {
13
14         $tabs = '';
15
16         if ($a->argc >1 && is_numeric($a->argv[1])) {
17                 $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl');
18         }
19
20         $new = array(
21                 'label' => t('New Message'),
22                 'url' => 'message/new',
23                 'sel'=> ($a->argv[1] == 'new'),
24                 'accesskey' => 'm',
25         );
26
27         $tpl = get_markup_template('message_side.tpl');
28         $a->page['aside'] = replace_macros($tpl, array(
29                 '$tabs'=>$tabs,
30                 '$new'=>$new,
31         ));
32         $base = System::baseUrl();
33
34         $head_tpl = get_markup_template('message-head.tpl');
35         $a->page['htmlhead'] .= replace_macros($head_tpl,array(
36                 '$baseurl' => System::baseUrl(true),
37                 '$base' => $base
38         ));
39
40         $end_tpl = get_markup_template('message-end.tpl');
41         $a->page['end'] .= replace_macros($end_tpl,array(
42                 '$baseurl' => System::baseUrl(true),
43                 '$base' => $base
44         ));
45
46 }
47
48 function message_post(App $a) {
49
50         if (! local_user()) {
51                 notice( t('Permission denied.') . EOL);
52                 return;
53         }
54
55         $replyto   = ((x($_REQUEST,'replyto'))   ? notags(trim($_REQUEST['replyto']))   : '');
56         $subject   = ((x($_REQUEST,'subject'))   ? notags(trim($_REQUEST['subject']))   : '');
57         $body      = ((x($_REQUEST,'body'))      ? escape_tags(trim($_REQUEST['body'])) : '');
58         $recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto'])       : 0 );
59
60         $ret = send_message($recipient, $body, $subject, $replyto);
61         $norecip = false;
62
63         switch($ret){
64                 case -1:
65                         notice( t('No recipient selected.') . EOL );
66                         $norecip = true;
67                         break;
68                 case -2:
69                         notice( t('Unable to locate contact information.') . EOL );
70                         break;
71                 case -3:
72                         notice( t('Message could not be sent.') . EOL );
73                         break;
74                 case -4:
75                         notice( t('Message collection failure.') . EOL );
76                         break;
77                 default:
78                         info( t('Message sent.') . EOL );
79         }
80
81         // fake it to go back to the input form if no recipient listed
82
83         if ($norecip) {
84                 $a->argc = 2;
85                 $a->argv[1] = 'new';
86         } else
87                 goaway($_SESSION['return_url']);
88
89 }
90
91 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
92 // is identical to the code in include/conversation.php
93 if (! function_exists('item_extract_images')) {
94 function item_extract_images($body) {
95
96         $saved_image = array();
97         $orig_body = $body;
98         $new_body = '';
99
100         $cnt = 0;
101         $img_start = strpos($orig_body, '[img');
102         $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
103         $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
104         while(($img_st_close !== false) && ($img_end !== false)) {
105
106                 $img_st_close++; // make it point to AFTER the closing bracket
107                 $img_end += $img_start;
108
109                 if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
110                         // This is an embedded image
111
112                         $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
113                         $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
114
115                         $cnt++;
116                 } else
117                         $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
118
119                 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
120
121                 if ($orig_body === false) // in case the body ends on a closing image tag
122                         $orig_body = '';
123
124                 $img_start = strpos($orig_body, '[img');
125                 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
126                 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
127         }
128
129         $new_body = $new_body . $orig_body;
130
131         return array('body' => $new_body, 'images' => $saved_image);
132 }}
133
134 if (! function_exists('item_redir_and_replace_images')) {
135 function item_redir_and_replace_images($body, $images, $cid) {
136
137         $origbody = $body;
138         $newbody = '';
139
140         for($i = 0; $i < count($images); $i++) {
141                 $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
142                 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
143                            . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
144
145                 $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]');
146                 $process_part = substr($origbody, 0, $img_end);
147                 $origbody = substr($origbody, $img_end);
148
149                 $process_part = preg_replace($search, $replace, $process_part);
150                 $newbody = $newbody . $process_part;
151         }
152         $newbody = $newbody . $origbody;
153
154         $cnt = 0;
155         foreach ($images as $image) {
156                 // We're depending on the property of 'foreach' (specified on the PHP website) that
157                 // it loops over the array starting from the first element and going sequentially
158                 // to the last element
159                 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
160                 $cnt++;
161         }
162
163         return $newbody;
164 }}
165
166
167
168 function message_content(App $a) {
169
170         $o = '';
171         nav_set_selected('messages');
172
173         if (! local_user()) {
174                 notice( t('Permission denied.') . EOL);
175                 return;
176         }
177
178         $myprofile = System::baseUrl().'/profile/' . $a->user['nickname'];
179
180         $tpl = get_markup_template('mail_head.tpl');
181         $header = replace_macros($tpl, array(
182                 '$messages' => t('Messages'),
183                 '$tab_content' => $tab_content
184         ));
185
186
187         if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
188                 if (! intval($a->argv[2]))
189                         return;
190
191                 // Check if we should do HTML-based delete confirmation
192                 if ($_REQUEST['confirm']) {
193                         // <form> can't take arguments in its "action" parameter
194                         // so add any arguments as hidden inputs
195                         $query = explode_querystring($a->query_string);
196                         $inputs = array();
197                         foreach($query['args'] as $arg) {
198                                 if (strpos($arg, 'confirm=') === false) {
199                                         $arg_parts = explode('=', $arg);
200                                         $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
201                                 }
202                         }
203
204                         //$a->page['aside'] = '';
205                         return replace_macros(get_markup_template('confirm.tpl'), array(
206                                 '$method' => 'get',
207                                 '$message' => t('Do you really want to delete this message?'),
208                                 '$extra_inputs' => $inputs,
209                                 '$confirm' => t('Yes'),
210                                 '$confirm_url' => $query['base'],
211                                 '$confirm_name' => 'confirmed',
212                                 '$cancel' => t('Cancel'),
213                         ));
214                 }
215                 // Now check how the user responded to the confirmation query
216                 if ($_REQUEST['canceled']) {
217                         goaway($_SESSION['return_url']);
218                 }
219
220                 $cmd = $a->argv[1];
221                 if ($cmd === 'drop') {
222                         $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
223                                 intval($a->argv[2]),
224                                 intval(local_user())
225                         );
226                         if ($r) {
227                                 info( t('Message deleted.') . EOL );
228                         }
229                         //goaway(System::baseUrl(true) . '/message' );
230                         goaway($_SESSION['return_url']);
231                 } else {
232                         $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
233                                 intval($a->argv[2]),
234                                 intval(local_user())
235                         );
236                         if (DBM::is_result($r)) {
237                                 $parent = $r[0]['parent-uri'];
238                                 $convid = $r[0]['convid'];
239
240                                 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
241                                         dbesc($parent),
242                                         intval(local_user())
243                                 );
244
245                                 // remove diaspora conversation pointer
246                                 // Actually if we do this, we can never receive another reply to that conversation,
247                                 // as we will never again have the info we need to re-create it.
248                                 // We'll just have to orphan it.
249
250                                 //if ($convid) {
251                                 //      q("delete from conv where id = %d limit 1",
252                                 //              intval($convid)
253                                 //      );
254                                 //}
255
256                                 if ($r)
257                                         info( t('Conversation removed.') . EOL );
258                         }
259                         //goaway(System::baseUrl(true) . '/message' );
260                         goaway($_SESSION['return_url']);
261                 }
262
263         }
264
265         if (($a->argc > 1) && ($a->argv[1] === 'new')) {
266
267                 $o .= $header;
268
269                 $tpl = get_markup_template('msg-header.tpl');
270                 $a->page['htmlhead'] .= replace_macros($tpl, array(
271                         '$baseurl' => System::baseUrl(true),
272                         '$nickname' => $a->user['nickname'],
273                         '$linkurl' => t('Please enter a link URL:')
274                 ));
275
276                 $tpl = get_markup_template('msg-end.tpl');
277                 $a->page['end'] .= replace_macros($tpl, array(
278                         '$baseurl' => System::baseUrl(true),
279                         '$nickname' => $a->user['nickname'],
280                         '$linkurl' => t('Please enter a link URL:')
281                 ));
282
283                 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
284
285
286                 $prename = $preurl = $preid = '';
287
288                 if ($preselect) {
289                         $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `id` = %d LIMIT 1",
290                                 intval(local_user()),
291                                 intval($a->argv[2])
292                         );
293                         if (!DBM::is_result($r)) {
294                                 $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
295                                         intval(local_user()),
296                                         dbesc(normalise_link(base64_decode($a->argv[2])))
297                                 );
298                         }
299
300                         if (!DBM::is_result($r)) {
301                                 $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1",
302                                         intval(local_user()),
303                                         dbesc(base64_decode($a->argv[2]))
304                                 );
305                         }
306
307                         if (DBM::is_result($r)) {
308                                 $prename = $r[0]['name'];
309                                 $preurl = $r[0]['url'];
310                                 $preid = $r[0]['id'];
311                                 $preselect = array($preid);
312                         } else
313                                 $preselect = false;
314                 }
315
316                 $prefill = (($preselect) ? $prename  : '');
317
318                 // the ugly select box
319
320                 $select = contact_select('messageto','message-to-select', $preselect, 4, true, false, false, 10);
321
322                 $tpl = get_markup_template('prv_message.tpl');
323                 $o .= replace_macros($tpl,array(
324                         '$header' => t('Send Private Message'),
325                         '$to' => t('To:'),
326                         '$showinputs' => 'true',
327                         '$prefill' => $prefill,
328                         '$autocomp' => $autocomp,
329                         '$preid' => $preid,
330                         '$subject' => t('Subject:'),
331                         '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
332                         '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
333                         '$readonly' => '',
334                         '$yourmessage' => t('Your message:'),
335                         '$select' => $select,
336                         '$parent' => '',
337                         '$upload' => t('Upload photo'),
338                         '$insert' => t('Insert web link'),
339                         '$wait' => t('Please wait'),
340                         '$submit' => t('Submit')
341                 ));
342                 return $o;
343         }
344
345
346         $_SESSION['return_url'] = $a->query_string;
347
348         if ($a->argc == 1) {
349
350                 // List messages
351
352                 $o .= $header;
353
354                 $r = q("SELECT count(*) AS `total`, ANY_VALUE(`created`) AS `created` FROM `mail`
355                         WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `created` DESC",
356                         intval(local_user())
357                 );
358
359                 if (DBM::is_result($r)) {
360                         $a->set_pager_total($r[0]['total']);
361                 }
362
363                 $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']);
364
365                 if (! DBM::is_result($r)) {
366                         info( t('No messages.') . EOL);
367                         return $o;
368                 }
369
370                 $o .= render_messages($r, 'mail_list.tpl');
371
372                 $o .= paginate($a);
373
374                 return $o;
375         }
376
377         if (($a->argc > 1) && (intval($a->argv[1]))) {
378
379                 $o .= $header;
380
381                 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
382                         FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
383                         WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
384                         intval(local_user()),
385                         intval($a->argv[1])
386                 );
387                 if (DBM::is_result($r)) {
388                         $contact_id = $r[0]['contact-id'];
389                         $convid = $r[0]['convid'];
390
391                         $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri']));
392                         if ($convid)
393                                 $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
394                                         dbesc($r[0]['parent-uri']),
395                                         intval($convid)
396                                 );
397
398                         $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
399                                 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
400                                 WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
401                                 intval(local_user())
402                         );
403                 }
404                 if (! count($messages)) {
405                         notice( t('Message not available.') . EOL );
406                         return $o;
407                 }
408
409                 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
410                         dbesc($r[0]['parent-uri']),
411                         intval(local_user())
412                 );
413
414                 require_once("include/bbcode.php");
415
416                 $tpl = get_markup_template('msg-header.tpl');
417                 $a->page['htmlhead'] .= replace_macros($tpl, array(
418                         '$baseurl' => System::baseUrl(true),
419                         '$nickname' => $a->user['nickname'],
420                         '$linkurl' => t('Please enter a link URL:')
421                 ));
422
423                 $tpl = get_markup_template('msg-end.tpl');
424                 $a->page['end'] .= replace_macros($tpl, array(
425                         '$baseurl' => System::baseUrl(true),
426                         '$nickname' => $a->user['nickname'],
427                         '$linkurl' => t('Please enter a link URL:')
428                 ));
429
430                 $mails = array();
431                 $seen = 0;
432                 $unknown = false;
433
434                 foreach($messages as $message) {
435                         if ($message['unknown'])
436                                 $unknown = true;
437                         if ($message['from-url'] == $myprofile) {
438                                 $from_url = $myprofile;
439                                 $sparkle = '';
440                         } elseif ($message['contact-id'] != 0) {
441                                 $from_url = 'redir/'.$message['contact-id'];
442                                 $sparkle = ' sparkle';
443                         } else {
444                                 $from_url = $message['from-url']."?zrl=".urlencode($myprofile);
445                                 $sparkle = ' sparkle';
446                         }
447
448
449                         $extracted = item_extract_images($message['body']);
450                         if ($extracted['images'])
451                                 $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
452
453                         if ($a->theme['template_engine'] === 'internal') {
454                                 $from_name_e = template_escape($message['from-name']);
455                                 $subject_e = template_escape($message['title']);
456                                 $body_e = template_escape(Smilies::replace(bbcode($message['body'])));
457                                 $to_name_e = template_escape($message['name']);
458                         } else {
459                                 $from_name_e = $message['from-name'];
460                                 $subject_e = $message['title'];
461                                 $body_e = Smilies::replace(bbcode($message['body']));
462                                 $to_name_e = $message['name'];
463                         }
464
465                         $contact = get_contact_details_by_url($message['from-url']);
466                         if (isset($contact["thumb"]))
467                                 $from_photo = $contact["thumb"];
468                         else
469                                 $from_photo = $message['from-photo'];
470
471                         $mails[] = array(
472                                 'id' => $message['id'],
473                                 'from_name' => $from_name_e,
474                                 'from_url' => $from_url,
475                                 'from_addr' => $contact['addr'],
476                                 'sparkle' => $sparkle,
477                                 'from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB),
478                                 'subject' => $subject_e,
479                                 'body' => $body_e,
480                                 'delete' => t('Delete message'),
481                                 'to_name' => $to_name_e,
482                                 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'),
483                                 'ago' => relative_date($message['created']),
484                         );
485
486                         $seen = $message['seen'];
487                 }
488
489
490                 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
491                 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
492
493                 $tpl = get_markup_template('mail_display.tpl');
494
495                 if ($a->theme['template_engine'] === 'internal') {
496                         $subjtxt_e = template_escape($message['title']);
497                 } else {
498                         $subjtxt_e = $message['title'];
499                 }
500
501                 $o = replace_macros($tpl, array(
502                         '$thread_id' => $a->argv[1],
503                         '$thread_subject' => $message['title'],
504                         '$thread_seen' => $seen,
505                         '$delete' =>  t('Delete conversation'),
506                         '$canreply' => (($unknown) ? false : '1'),
507                         '$unknown_text' => t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."),
508                         '$mails' => $mails,
509
510                         // reply
511                         '$header' => t('Send Reply'),
512                         '$to' => t('To:'),
513                         '$showinputs' => '',
514                         '$subject' => t('Subject:'),
515                         '$subjtxt' => $subjtxt_e,
516                         '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
517                         '$yourmessage' => t('Your message:'),
518                         '$text' => '',
519                         '$select' => $select,
520                         '$parent' => $parent,
521                         '$upload' => t('Upload photo'),
522                         '$insert' => t('Insert web link'),
523                         '$submit' => t('Submit'),
524                         '$wait' => t('Please wait')
525
526                 ));
527
528                 return $o;
529         }
530 }
531
532 function get_messages($user, $lstart, $lend) {
533         //TODO: rewritte with a sub-query to get the first message of each private thread with certainty
534         return q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
535                 ANY_VALUE(`mail`.`id`) AS `id`, ANY_VALUE(`mail`.`uid`) AS `uid`, ANY_VALUE(`mail`.`guid`) AS `guid`,
536                 ANY_VALUE(`mail`.`from-name`) AS `from-name`, ANY_VALUE(`mail`.`from-photo`) AS `from-photo`,
537                 ANY_VALUE(`mail`.`from-url`) AS `from-url`, ANY_VALUE(`mail`.`contact-id`) AS `contact-id`,
538                 ANY_VALUE(`mail`.`convid`) AS `convid`, ANY_VALUE(`mail`.`title`) AS `title`, ANY_VALUE(`mail`.`body`) AS `body`,
539                 ANY_VALUE(`mail`.`seen`) AS `seen`, ANY_VALUE(`mail`.`reply`) AS `reply`, ANY_VALUE(`mail`.`replied`) AS `replied`,
540                 ANY_VALUE(`mail`.`unknown`) AS `unknown`, ANY_VALUE(`mail`.`uri`) AS `uri`,
541                 `mail`.`parent-uri`,
542                 ANY_VALUE(`mail`.`created`) AS `created`, ANY_VALUE(`contact`.`name`) AS `name`, ANY_VALUE(`contact`.`url`) AS `url`,
543                 ANY_VALUE(`contact`.`thumb`) AS `thumb`, ANY_VALUE(`contact`.`network`) AS `network`,
544                 count( * ) as `count`
545                 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
546                 WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `mailcreated` DESC LIMIT %d , %d ",
547                 intval($user), intval($lstart), intval($lend)
548         );
549 }
550
551 function render_messages(array $msg, $t) {
552
553         $a = get_app();
554
555         $tpl = get_markup_template($t);
556         $rslt = '';
557
558         $myprofile = System::baseUrl().'/profile/' . $a->user['nickname'];
559
560         foreach($msg as $rr) {
561
562                 if ($rr['unknown'])
563                         $participants = sprintf( t("Unknown sender - %s"),$rr['from-name']);
564                 elseif (link_compare($rr['from-url'], $myprofile))
565                         $participants = sprintf( t("You and %s"), $rr['name']);
566                 else
567                         $participants = sprintf(t("%s and You"), $rr['from-name']);
568
569                 if ($a->theme['template_engine'] === 'internal') {
570                         $subject_e = template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'));
571                         $body_e = template_escape($rr['body']);
572                         $to_name_e = template_escape($rr['name']);
573                 } else {
574                         $subject_e = (($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>');
575                         $body_e = $rr['body'];
576                         $to_name_e = $rr['name'];
577                 }
578
579                 $contact = get_contact_details_by_url($rr['url']);
580                 if (isset($contact["thumb"]))
581                         $from_photo = $contact["thumb"];
582                 else
583                         $from_photo = (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']);
584
585                 $rslt .= replace_macros($tpl, array(
586                         '$id' => $rr['id'],
587                         '$from_name' => $participants,
588                         '$from_url' => (($rr['network'] === NETWORK_DFRN) ? 'redir/' . $rr['contact-id'] : $rr['url']),
589                         '$from_addr' => $contact['addr'],
590                         '$sparkle' => ' sparkle',
591                         '$from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB),
592                         '$subject' => $subject_e,
593                         '$delete' => t('Delete conversation'),
594                         '$body' => $body_e,
595                         '$to_name' => $to_name_e,
596                         '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A')),
597                                                                                                                         '$ago' => relative_date($rr['mailcreated']),
598                         '$seen' => $rr['mailseen'],
599                         '$count' => sprintf( tt('%d message', '%d messages', $rr['count']), $rr['count']),
600                 ));
601         }
602
603         return $rslt;
604 }