6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
15 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
17 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
19 global $color, $msgs, $msort;
20 global $sent_folder, $draft_folder;
21 global $default_use_priority;
22 global $message_highlight_list;
25 $color_string = $color[4];
26 if ($GLOBALS['alt_index_colors']) {
27 if (!isset($GLOBALS["row_count"])) {
28 $GLOBALS["row_count"] = 0;
30 $GLOBALS["row_count"]++
;
31 if ($GLOBALS["row_count"] %
2) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
33 $color_string = $color[12];
38 $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
39 if( $mailbox == 'None' ) {
40 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 $boxes = sqimap_mailbox_list($imapConnection);
42 // sqimap_logout($imapConnection);
43 $mailbox = $boxes[0]['unformatted'];
46 $urlMailbox = urlencode($mailbox);
47 $subject = processSubject($msg['SUBJECT']);
50 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
51 $flag = "<font color=$color[2]>";
52 $flag_end = '</font>';
57 if (!isset($msg['FLAG_SEEN']) ||
($msg['FLAG_SEEN'] == false)) {
65 if (($mailbox == $sent_folder) ||
($mailbox == $draft_folder)) {
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
81 for ($i=0; $i < count($message_highlight_list); $i++
) {
82 if (trim($message_highlight_list[$i]['value']) != '') {
83 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
84 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
85 $hlt_color = $message_highlight_list[$i]['color'];
88 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
89 $hlt_color = $message_highlight_list[$i]['color'];
95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
99 if ($where && $what) {
100 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
103 $checked = ($checkall == 1 ?
' checked' : '');
105 for ($i=1; $i <= count($index_order); $i++
) {
106 switch ($index_order[$i]) {
107 case 1: /* checkbox */
108 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
111 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
114 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
116 case 4: /* subject */
117 echo " <td bgcolor=$hlt_color>$bold";
118 if (! isset($search_stuff)) { $search_stuff = ''; }
119 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
120 do_hook("subject_link");
122 if ($subject != $msg['SUBJECT']) {
123 $title = get_html_translation_table(HTML_SPECIALCHARS
);
124 $title = array_flip($title);
125 $title = strtr($msg['SUBJECT'], $title);
126 $title = str_replace('"', "''", $title);
127 echo " title=\"$title\"";
129 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
133 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
134 if (isset($msg['FLAG_ANSWERED']) &&
135 $msg['FLAG_ANSWERED'] == true) {
139 if ($msg['TYPE0'] == 'multipart') {
143 if ($default_use_priority) {
144 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
145 echo "<font color=$color[1]>!</font>\n";
148 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
149 echo "<font color=$color[8]>?</font>\n";
153 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
154 echo "<font color=\"$color[1]\">D</font>\n";
158 if (!$stuff) echo " \n";
159 echo "</small></b></td>\n";
162 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
170 * This function loops through a group of messages in the mailbox
171 * and shows them to the user.
173 function showMessagesForMailbox
174 ($imapConnection, $mailbox, $num_msgs, $start_msg,
175 $sort, $color,$show_num, $use_cache) {
176 global $msgs, $msort;
177 global $sent_folder, $draft_folder;
178 global $message_highlight_list;
179 global $auto_expunge;
181 /* If autoexpunge is turned on, then do it now. */
182 if ($auto_expunge == true) {
183 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
185 sqimap_mailbox_select($imapConnection, $mailbox);
187 $issent = (($mailbox == $sent_folder) ||
($mailbox == $draft_folder));
189 /* If it is sorted... */
190 if ($num_msgs >= 1) {
192 $id = range(1, $num_msgs);
194 // if it's not sorted
195 if ($start_msg +
($show_num - 1) < $num_msgs) {
196 $end_msg = $start_msg +
($show_num-1);
198 $end_msg = $num_msgs;
201 if ($end_msg < $start_msg) {
202 $start_msg = $start_msg - $show_num;
203 if ($start_msg < 1) {
208 $real_startMessage = $num_msgs - $start_msg +
1;
209 $real_endMessage = $num_msgs - $start_msg - $show_num +
2;
210 if ($real_endMessage <= 0) {
211 $real_endMessage = 1;
213 $id = array_reverse(range($real_endMessage, $real_startMessage));
216 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
217 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
218 foreach ($msgs_list as $hdr) {
219 $from[] = $hdr->from
;
220 $date[] = $hdr->date
;
221 $subject[] = $hdr->subject
;
223 $priority[] = $hdr->priority
;
225 $size[] = $hdr->size
;
226 $type[] = $hdr->type0
;
232 $end = $start_msg +
$show_num - 1;
233 if ($num_msgs < $show_num) {
234 $end_loop = $num_msgs;
235 } else if ($end > $num_msgs) {
236 $end_loop = $num_msgs - $start_msg +
1;
238 $end_loop = $show_num;
245 while ($j < $end_loop) {
246 if (isset($date[$j])) {
247 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
248 $tmpdate = explode(' ', trim($date[$j]));
250 $tmpdate = $date = array("","","","","","");
253 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
254 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
255 $messages[$j]['ID'] = $id[$j];
256 $messages[$j]['FROM'] = decodeHeader($from[$j]);
257 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
258 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
259 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
260 $messages[$j]['TO'] = decodeHeader($to[$j]);
261 $messages[$j]['PRIORITY'] = $priority[$j];
262 $messages[$j]['CC'] = $cc[$j];
263 $messages[$j]['SIZE'] = $size[$j];
264 $messages[$j]['TYPE0'] = $type[$j];
266 # fix SUBJECT-SORT to remove Re:
267 $re_abbr = # Add more here!
268 'vedr|sv|' . # Danish
271 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
272 $messages[$j]['SUBJECT-SORT'] = $regs[2];
275 while ($num < count($flags[$j])) {
276 if ($flags[$j][$num] == 'Deleted') {
277 $messages[$j]['FLAG_DELETED'] = true;
278 } else if ($flags[$j][$num] == 'Answered') {
279 $messages[$j]['FLAG_ANSWERED'] = true;
280 } else if ($flags[$j][$num] == 'Seen') {
281 $messages[$j]['FLAG_SEEN'] = true;
282 } else if ($flags[$j][$num] == 'Flagged') {
283 $messages[$j]['FLAG_FLAGGED'] = true;
290 /* Only ignore messages flagged as deleted if we are using a
291 * trash folder or auto_expunge */
292 if (((isset($move_to_trash) && $move_to_trash)
293 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
295 /** Find and remove the ones that are deleted */
299 while ($j < $num_msgs) {
300 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
304 $msgs[$i] = $messages[$j];
311 if (!isset($messages)) {
318 // There's gotta be messages in the array for it to sort them.
319 if ($num_msgs > 0 && ! $use_cache) {
320 /** 0 = Date (up) 4 = Subject (up)
321 ** 1 = Date (dn) 5 = Subject (dn)
325 session_unregister("msgs");
326 if (($sort == 0) ||
($sort == 1))
327 $msort = array_cleave ($msgs, 'TIME_STAMP');
328 elseif (($sort == 2) ||
($sort == 3))
329 $msort = array_cleave ($msgs, 'FROM-SORT');
330 elseif (($sort == 4) ||
($sort == 5))
331 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
342 session_register('msort');
344 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
345 session_register('msgs');
348 /******************************************************************/
349 /* Generic function to convert the msgs array into an HTML table. */
350 /******************************************************************/
351 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
352 global $folder_prefix, $sent_folder;
353 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
354 global $index_order, $real_endMessage, $real_startMessage, $checkall;
356 /* If cache isn't already set, do it now. */
357 if (!session_is_registered('msgs')) { session_register('msgs'); }
358 if (!session_is_registered('msort')) { session_register('msort'); }
360 if ($start_msg +
($show_num - 1) < $num_msgs) {
361 $end_msg = $start_msg +
($show_num-1);
363 $end_msg = $num_msgs;
366 if ($end_msg < $start_msg) {
367 $start_msg = $start_msg - $show_num;
368 if ($start_msg < 1) { $start_msg = 1; }
371 $urlMailbox = urlencode($mailbox);
373 do_hook('mailbox_index_before');
375 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
376 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
382 mail_message_listing_beginning
384 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
385 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
387 $groupNum = $start_msg %
($show_num - 1);
388 $real_startMessage = $start_msg;
390 if ($end_msg - $start_msg < $show_num - 1) {
391 $end_msg = $end_msg - $start_msg +
1;
393 } else if ($start_msg > $show_num) {
394 $end_msg = $show_num;
398 $endVar = $end_msg +
1;
400 /* Loop through and display the info for each message. */
401 $t = 0; // $t is used for the checkbox number
402 if ($num_msgs == 0) { // if there's no messages in this folder
403 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
404 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n".
406 } else if ($start_msg == $end_msg) {
407 /* If there's only one message in the box, handle it differently. */
420 } while (isset ($key) && ($k < $i));
421 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
431 } while (isset ($key) && ($k < $i));
434 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
439 } while ($i && $i < $endVar);
443 "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
444 "<tr BGCOLOR=\"$color[4]\">" .
445 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
446 "<td align=right>$msg_cnt_str</td></tr></table>".
449 /** End of message-list table */
451 do_hook('mailbox_index_after');
452 echo "</TABLE></FORM>\n";
456 * Displays the standard message list header. To finish the table,
457 * you need to do a "</table></table>";
459 * $moveURL is the URL to submit the delete/move form to
460 * $mailbox is the current mailbox
461 * $sort is the current sorting method (-1 for no sorting available [searches])
462 * $Message is a message that is centered on top of the list
463 * $More is a second line that is left aligned
465 function mail_message_listing_beginning
466 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
467 $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) {
468 global $color, $index_order, $auto_expunge, $move_to_trash;
469 global $checkall, $sent_folder, $draft_folder;
470 $urlMailbox = urlencode($mailbox);
472 /****************************************************
473 * This is the beginning of the message list table. *
474 * It wraps around all messages *
475 ****************************************************/
476 echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n".
477 "<TR BGCOLOR=\"$color[0]\"><TD>".
478 "<TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n".
479 " <TD ALIGN=LEFT>$paginator</TD>\n".
480 ' <TD ALIGN=CENTER>' . get_selectall_link($start_msg, $sort) . "</TD>\n".
481 " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n".
484 "<TR><TD BGCOLOR=\"$color[0]\">\n".
485 "<FORM name=messageList method=post action=\"$moveURL\">\n".
486 "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n".
488 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
489 ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n" .
491 " <TD ALIGN=RIGHT NOWRAP>\n" .
492 ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n" .
496 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
497 ' <SMALL> <TT><SELECT NAME="targetMailbox">';
499 $boxes = sqimap_mailbox_list($imapConnection);
500 for ($i = 0; $i < count($boxes); $i++
) {
501 if (!in_array("noselect", $boxes[$i]['flags'])) {
502 $box = $boxes[$i]['unformatted'];
503 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
504 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
507 echo ' </SELECT></TT></SMALL>'.
508 "<SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
510 " <TD ALIGN=RIGHT NOWRAP> \n";
511 if (!$auto_expunge) {
512 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n";
514 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
515 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
516 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n".
520 do_hook('mailbox_form_before');
523 "<TR><TD BGCOLOR=\"$color[0]\">".
524 "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
525 if ($GLOBALS['alt_index_colors']) {
530 echo " BGCOLOR=\"$color[0]\">".
531 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
533 /* Print the headers. */
534 for ($i=1; $i <= count($index_order); $i++
) {
535 switch ($index_order[$i]) {
536 case 1: /* checkbox */
538 echo ' <TD WIDTH="1%"><B> </B></TD>';
542 if (($mailbox == $sent_folder)
543 ||
($mailbox == $draft_folder)) {
544 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
546 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
549 ShowSortButton($sort, $mailbox, 2, 3);
554 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
555 ShowSortButton($sort, $mailbox, 0, 1);
559 case 4: /* subject */
560 echo ' <TD><B>'. _("Subject") .'</B> ';
561 ShowSortButton($sort, $mailbox, 4, 5);
566 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
573 /*******************************************************************/
574 /* This function shows the sort button. Isn't this a good comment? */
575 /*******************************************************************/
576 function ShowSortButton($sort, $mailbox, $Up, $Down) {
577 /* Figure out which image we want to use. */
578 if ($sort != $Up && $sort != $Down) {
579 $img = 'sort_none.gif';
581 } elseif ($sort == $Up) {
582 $img = 'up_pointer.gif';
585 $img = 'down_pointer.gif';
589 /* Now that we have everything figured out, show the actual button. */
590 echo ' <a href="right_main.php?newsort=' . $which .
591 '&startMessage=1&mailbox=' . urlencode($mailbox) .
592 '"><IMG SRC="../images/' . $img .
593 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
596 function get_selectall_link($start_msg, $sort) {
597 global $checkall, $PHP_SELF, $what, $where, $mailbox;
600 ' <script language="JavaScript">' .
602 "function CheckAll() {\n" .
603 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
604 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
605 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
609 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" .
611 "</script>\n<noscript>\n";
613 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
614 . "&startMessage=$start_msg&sort=$sort&checkall=";
615 if (isset($checkall) && $checkall == '1') {
621 if (isset($where) && isset($what)) {
622 $result .= '&where=' . urlencode($where) . '&what=' . urlencode($what);
627 if (isset($checkall) && ($checkall == '1')) {
628 $result .= _("Unselect All");
630 $result .= _("Select All");
633 $result .= "</A>\n</noscript>\n";
635 /* Return our final result. */
640 * This function computes the "Viewing Messages..." string.
642 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
643 /* Compute the $msg_cnt_str. */
645 if ($start_msg < $end_msg) {
646 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
647 } else if ($start_msg == $end_msg) {
648 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
653 /* Return our result string. */
658 * This function computes the paginator string.
660 function get_paginator_str
661 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
662 global $username, $data_dir, $use_mailbox_cache, $color;
664 $nextGroup = $start_msg +
$show_num;
665 $prevGroup = $start_msg - $show_num;
674 if (($nextGroup <= $num_msgs) && ($prevGroup >= 0)) {
675 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
676 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
677 } else if (($nextGroup > $num_msgs) && ($prevGroup >= 0)) {
678 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
679 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
680 } else if (($nextGroup <= $num_msgs) && ($prevGroup < 0)) {
681 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
682 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
685 $lMore .= ' | ';
688 /* Page selector block. Following code computes page links. */
690 if (getPref($data_dir, $username, 'page_selector')
691 && ($num_msgs > $show_num)) {
692 $j = intval( $num_msgs / $show_num ); // Max pages
693 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
) );
694 if ($num_msgs %
$show_num <> 0 ) {
697 $start_msg = min( $start_msg, $num_msgs );
698 $p = intval( $start_msg / $show_num ) +
1;
702 $start = ( ($pg-1) * $show_num ) +
1;
703 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
704 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
707 $mMore .= "<B>$p</B> ";
711 $start = ( ($pg-1) * $show_num ) +
1;
712 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start"
713 . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
716 $mMore .= ' | ';
719 /* Return the resulting string. */
720 if( $lMore . $mMore . $rMore == '' ) {
723 return ($lMore . $mMore . $rMore);
726 function processSubject($subject) {
727 // Shouldn't ever happen -- caught too many times in the IMAP functions
729 return _("(no subject)");
731 if (strlen($subject) <= 55)
734 $ent_strlen=strlen($subject);
737 // see if this is entities-encoded string
738 // If so, Iterate through the whole string, find out
739 // the real number of characters, and if more
740 // than 55, substr with an updated trim value.
741 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
742 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
744 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
745 $ent_strlen -= $ent_loc_end-$ent_loc;
746 $ent_offset = $ent_loc_end+
1;
749 if ($ent_strlen <= 55)
752 return substr($subject, 0, $trim_val) . '...';