API: beautify the output of repeated items

Vier: Birthday reminder looks better
This commit is contained in:
Michael Vogel 2013-02-15 20:14:45 +01:00
parent 5e077e541a
commit 3e58060b30
3 changed files with 55 additions and 21 deletions

View file

@ -639,7 +639,7 @@
$in_reply_to_screen_name = $lastwall['reply_author']; $in_reply_to_screen_name = $lastwall['reply_author'];
} }
$status_info = array( $status_info = array(
'text' => html2plain(bbcode($lastwall['body']), 0), 'text' => html2plain(bbcode($lastwall['body'], false, false, true), 0),
'truncated' => false, 'truncated' => false,
'created_at' => api_date($lastwall['created']), 'created_at' => api_date($lastwall['created']),
'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id' => $in_reply_to_status_id,
@ -698,7 +698,7 @@
$user_info['status'] = array( $user_info['status'] = array(
'created_at' => api_date($lastwall['created']), 'created_at' => api_date($lastwall['created']),
'id' => $lastwall['contact-id'], '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'), 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
'truncated' => false, 'truncated' => false,
'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id' => $in_reply_to_status_id,
@ -1300,11 +1300,11 @@
$ret['text'] = bbcode($item['body']); $ret['text'] = bbcode($item['body']);
} }
elseif ($_GET["getText"] == "plain") { elseif ($_GET["getText"] == "plain") {
$ret['text'] = html2plain(bbcode($item['body']), 0); $ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0);
} }
} }
else { 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") { if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
unset($ret['sender']); unset($ret['sender']);
@ -1348,7 +1348,7 @@
} }
// Workaround for ostatus messages where the title is identically to the body // 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']); $statustitle = trim($item['title']);
if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false)) if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false))

View file

@ -278,10 +278,37 @@ function bb_ShareAttributes($match) {
return($text); 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 = "<br />".html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').' <a href="'.$profile.'">'.$author."</a>: <br />»".$match[2]."«";
return($text);
}
// BBcode 2 HTML was written by WAY2WEB.net // BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendica - Mike Macgirvin // 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); $stamp1 = microtime(true);
@ -342,13 +369,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = str_replace("\r\n","\n", $Text); $Text = str_replace("\r\n","\n", $Text);
// removing multiplicated newlines // removing multiplicated newlines
// $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]"); if (get_config("system", "remove_multiplicated_lines")) {
// $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]"); $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
// do { $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
// $oldtext = $Text; do {
// $Text = str_replace($search, $replace, $Text); $oldtext = $Text;
// } while ($oldtext != $Text); $Text = str_replace($search, $replace, $Text);
} while ($oldtext != $Text);
}
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text); $Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
@ -517,7 +545,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text); $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
// Shared content // Shared content
if (!$simplehtml)
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); $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",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);

View file

@ -1020,6 +1020,9 @@ section {
max-width: 766px; max-width: 766px;
padding: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;
background-color: white; background-color: white;
border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray;
border-left: 1px solid lightgray;
} }
/* wall item */ /* wall item */
.tread-wrapper { .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%);*/ 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; color: black;
background-color: #e5e5e5; background-color: #e5e5e5;
text-decoration: none; text-decoration: none;