]> git.mxchange.org Git - friendica.git/commitdiff
Display attach with missing title
authorHypolite Petovan <mrpetovan@gmail.com>
Fri, 9 Mar 2018 04:52:01 +0000 (23:52 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Fri, 9 Mar 2018 04:52:01 +0000 (23:52 -0500)
- Rework preg_match_all call to remove 3 indentation levels

include/text.php

index 5f01fae361f6ab1d8f9790db451302ddc42a3b5e..1474b8bf09a230f439cd920552818c505e0b57f2 100644 (file)
@@ -1281,62 +1281,55 @@ function prepare_body(&$item, $attach = false, $preview = false) {
 
        $as = '';
        $vhead = false;
-       $arr = explode('[/attach],', $item['attach']);
-       if (count($arr)) {
-               foreach ($arr as $r) {
-                       $matches = false;
-                       $icon = '';
-                       $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r ,$matches, PREG_SET_ORDER);
-                       if ($cnt) {
-                               foreach ($matches as $mtch) {
-                                       $mime = $mtch[3];
-
-                                       if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
-                                               $the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
-                                       } else {
-                                               $the_url = $mtch[1];
-                                       }
-
-                                       if (strpos($mime, 'video') !== false) {
-                                               if (!$vhead) {
-                                                       $vhead = true;
-                                                       $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [
-                                                               '$baseurl' => System::baseUrl(),
-                                                       ]);
-                                                       $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [
-                                                               '$baseurl' => System::baseUrl(),
-                                                       ]);
-                                               }
-
-                                               $id = end(explode('/', $the_url));
-                                               $as .= replace_macros(get_markup_template('video_top.tpl'), [
-                                                       '$video' => [
-                                                               'id'     => $id,
-                                                               'title'  => L10n::t('View Video'),
-                                                               'src'    => $the_url,
-                                                               'mime'   => $mime,
-                                                       ],
-                                               ]);
-                                       }
-
-                                       $filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
-                                       if ($filetype) {
-                                               $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
-                                               $filesubtype = str_replace('.', '-', $filesubtype);
-                                       } else {
-                                               $filetype = 'unkn';
-                                               $filesubtype = 'unkn';
-                                       }
-
-                                       $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
-                                       $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
-
-                                       $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
-                                       $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
-                               }
+       $matches = [];
+       preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\"(?: title=\"(.*?)\")?|', $item['attach'], $matches, PREG_SET_ORDER);
+       foreach ($matches as $mtch) {
+               $mime = $mtch[3];
+
+               if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
+                       $the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
+               } else {
+                       $the_url = $mtch[1];
+               }
+
+               if (strpos($mime, 'video') !== false) {
+                       if (!$vhead) {
+                               $vhead = true;
+                               $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [
+                                       '$baseurl' => System::baseUrl(),
+                               ]);
+                               $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [
+                                       '$baseurl' => System::baseUrl(),
+                               ]);
                        }
+
+                       $id = end(explode('/', $the_url));
+                       $as .= replace_macros(get_markup_template('video_top.tpl'), [
+                               '$video' => [
+                                       'id'     => $id,
+                                       'title'  => L10n::t('View Video'),
+                                       'src'    => $the_url,
+                                       'mime'   => $mime,
+                               ],
+                       ]);
                }
+
+               $filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
+               if ($filetype) {
+                       $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
+                       $filesubtype = str_replace('.', '-', $filesubtype);
+               } else {
+                       $filetype = 'unkn';
+                       $filesubtype = 'unkn';
+               }
+
+               $title = escape_tags(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1]));
+               $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
+
+               $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
+               $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
        }
+
        if ($as != '') {
                $s .= '<div class="body-attach">'.$as.'<div class="clear"></div></div>';
        }