From 3e58060b308f045613c3b57b62c0fb47890c7bdb Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 15 Feb 2013 20:14:45 +0100 Subject: [PATCH] API: beautify the output of repeated items Vier: Birthday reminder looks better --- include/api.php | 22 +++++++++--------- include/bbcode.php | 49 ++++++++++++++++++++++++++++++++------- view/theme/vier/style.css | 5 +++- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/include/api.php b/include/api.php index 4efb0c614..81255ca37 100644 --- a/include/api.php +++ b/include/api.php @@ -516,13 +516,13 @@ $txt = $purifier->purify($txt); } $txt = html2bbcode($txt); - + $a->argv[1]=$user_info['screen_name']; //should be set to username? - + $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo require_once('mod/wall_upload.php'); $bebop = wall_upload_post($a); - + //now that we have the img url in bbcode we can add it to the status and insert the wall item. $_REQUEST['body']=$txt."\n\n".$bebop; require_once('mod/item.php'); @@ -629,7 +629,7 @@ if (count($lastwall)>0){ $lastwall = $lastwall[0]; - + $in_reply_to_status_id = ''; $in_reply_to_user_id = ''; $in_reply_to_screen_name = ''; @@ -637,9 +637,9 @@ $in_reply_to_status_id=$lastwall['parent']; $in_reply_to_user_id = $lastwall['reply_uid']; $in_reply_to_screen_name = $lastwall['reply_author']; - } + } $status_info = array( - 'text' => html2plain(bbcode($lastwall['body']), 0), + 'text' => html2plain(bbcode($lastwall['body'], false, false, true), 0), 'truncated' => false, 'created_at' => api_date($lastwall['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, @@ -694,11 +694,11 @@ $in_reply_to_status_id=$lastwall['parent']; $in_reply_to_user_id = $lastwall['reply_uid']; $in_reply_to_screen_name = $lastwall['reply_author']; - } + } $user_info['status'] = array( 'created_at' => api_date($lastwall['created']), 'id' => $lastwall['contact-id'], - 'text' => html2plain(bbcode($lastwall['body']), 0), + 'text' => html2plain(bbcode($lastwall['body'], false, false, true), 0), 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'), 'truncated' => false, 'in_reply_to_status_id' => $in_reply_to_status_id, @@ -1300,11 +1300,11 @@ $ret['text'] = bbcode($item['body']); } elseif ($_GET["getText"] == "plain") { - $ret['text'] = html2plain(bbcode($item['body']), 0); + $ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0); } } else { - $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0); + $ret['text'] = $item['title']."\n".html2plain(bbcode($item['body'], false, false, true), 0); } if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") { unset($ret['sender']); @@ -1348,7 +1348,7 @@ } // Workaround for ostatus messages where the title is identically to the body - $statusbody = trim(html2plain(bbcode($item['body']), 0)); + $statusbody = trim(html2plain(bbcode($item['body'], false, false, true), 0)); $statustitle = trim($item['title']); if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false)) diff --git a/include/bbcode.php b/include/bbcode.php index 45213cc3b..a587d8c38 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -278,10 +278,37 @@ function bb_ShareAttributes($match) { return($text); } +function bb_ShareAttributesSimple($match) { + + $attributes = $match[1]; + + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); + + preg_match('/author="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $author = $matches[1]; + + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.":
»".$match[2]."«"; + + return($text); +} + // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin -function bbcode($Text,$preserve_nl = false, $tryoembed = true) { +function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = false) { $stamp1 = microtime(true); @@ -342,13 +369,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace("\r\n","\n", $Text); // removing multiplicated newlines -// $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]"); -// $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]"); -// do { -// $oldtext = $Text; -// $Text = str_replace($search, $replace, $Text); -// } while ($oldtext != $Text); - + if (get_config("system", "remove_multiplicated_lines")) { + $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]"); + $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]"); + do { + $oldtext = $Text; + $Text = str_replace($search, $replace, $Text); + } while ($oldtext != $Text); + } $Text = str_replace(array("\r","\n"), array('
','
'), $Text); @@ -517,7 +545,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); // Shared content - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + if (!$simplehtml) + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + else + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple",$Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index aa66769db..4a116c5b7 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -1020,6 +1020,9 @@ section { max-width: 766px; padding: 10px 10px 10px 10px; background-color: white; + border-bottom: 1px solid lightgray; + border-right: 1px solid lightgray; + border-left: 1px solid lightgray; } /* wall item */ .tread-wrapper { @@ -1727,7 +1730,7 @@ div.pager, .birthday-notice, ul.tabs a, #jot-preview-link, .comment-edit-submit- background: linear-gradient(top, #ffffff 0%,#ececf2 100%);*/ } -#event-notice:hover, ul.tabs li .active, ul.tabs a:hover, #jot-preview-link:hover, .comment-edit-submit-wrapper .fakelink:hover { +#event-notice:hover, #birthday-notice:hover, ul.tabs li .active, ul.tabs a:hover, #jot-preview-link:hover, .comment-edit-submit-wrapper .fakelink:hover { color: black; background-color: #e5e5e5; text-decoration: none;