Fix formatting and PHP notices in bb_ShareAttributes

- Use x() to check for existence of key in $matches
- Remove unused $reldate from template shared_content
This commit is contained in:
Hypolite Petovan 2018-01-01 15:10:20 -05:00
parent 585c00347d
commit 66dbef93e3
2 changed files with 73 additions and 59 deletions

View File

@ -435,60 +435,67 @@ function bb_replace_images($body, $images) {
return $newbody; return $newbody;
} }
function bb_ShareAttributes($share, $simplehtml) { function bb_ShareAttributes($share, $simplehtml)
{
$attributes = $share[2]; $attributes = $share[2];
$author = ""; $author = "";
preg_match("/author='(.*?)'/ism", $attributes, $matches); preg_match("/author='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); $author = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');
}
preg_match('/author="(.*?)"/ism', $attributes, $matches); preg_match('/author="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$author = $matches[1]; $author = $matches[1];
}
$profile = ""; $profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches); preg_match("/profile='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$profile = $matches[1]; $profile = $matches[1];
}
preg_match('/profile="(.*?)"/ism', $attributes, $matches); preg_match('/profile="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$profile = $matches[1]; $profile = $matches[1];
}
$avatar = ""; $avatar = "";
preg_match("/avatar='(.*?)'/ism", $attributes, $matches); preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$avatar = $matches[1]; $avatar = $matches[1];
}
preg_match('/avatar="(.*?)"/ism', $attributes, $matches); preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$avatar = $matches[1]; $avatar = $matches[1];
}
$link = ""; $link = "";
preg_match("/link='(.*?)'/ism", $attributes, $matches); preg_match("/link='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$link = $matches[1]; $link = $matches[1];
}
preg_match('/link="(.*?)"/ism', $attributes, $matches); preg_match('/link="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$link = $matches[1]; $link = $matches[1];
}
$posted = ""; $posted = "";
$itemcache = get_itemcachepath(); $itemcache = get_itemcachepath();
preg_match("/posted='(.*?)'/ism", $attributes, $matches); preg_match("/posted='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$posted = $matches[1]; $posted = $matches[1];
}
preg_match('/posted="(.*?)"/ism', $attributes, $matches); preg_match('/posted="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") if (x($matches, 1)) {
$posted = $matches[1]; $posted = $matches[1];
}
// relative dates only make sense when they aren't cached
if ($itemcache == "")
$reldate = (($posted) ? " " . relative_date($posted) : '');
// We only call this so that a previously unknown contact can be added. // We only call this so that a previously unknown contact can be added.
// This is important for the function "get_contact_details_by_url". // This is important for the function "get_contact_details_by_url".
@ -497,99 +504,107 @@ function bb_ShareAttributes($share, $simplehtml) {
$data = Contact::getDetailsByURL($profile); $data = Contact::getDetailsByURL($profile);
if (isset($data["name"]) && ($data["name"] != "") && isset($data["addr"]) && ($data["addr"] != "")) if (x($data, "name") && x($data, "addr")) {
$userid_compact = $data["name"]." (".$data["addr"].")"; $userid_compact = $data["name"] . " (" . $data["addr"] . ")";
else } else {
$userid_compact = GetProfileUsername($profile,$author, true); $userid_compact = GetProfileUsername($profile, $author, true);
}
if (isset($data["addr"]) && ($data["addr"] != "")) if (x($data, "addr")) {
$userid = $data["addr"]; $userid = $data["addr"];
else } else {
$userid = GetProfileUsername($profile,$author, false); $userid = GetProfileUsername($profile, $author, false);
}
if (isset($data["name"]) && ($data["name"] != "")) if (x($data, "name")) {
$author = $data["name"]; $author = $data["name"];
}
if (isset($data["micro"]) && ($data["micro"] != "")) if (x($data, "micro")) {
$avatar = $data["micro"]; $avatar = $data["micro"];
}
$preshare = trim($share[1]); $preshare = trim($share[1]);
if ($preshare != "") if ($preshare != "") {
$preshare .= "<br /><br />"; $preshare .= "<br /><br />";
}
switch ($simplehtml) { switch ($simplehtml) {
case 1: case 1:
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').' <a href="'.$profile.'">'.$userid."</a>: <br />»".$share[3]."«"; $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' <a href="' . $profile . '">' . $userid . "</a>: <br />»" . $share[3] . "«";
break; break;
case 2: case 2:
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.": <br />".$share[3]; $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
break; break;
case 3: // Diaspora case 3: // Diaspora
$headline .= '<b>'.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').$userid.':</b><br />'; $headline .= '<b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . $userid . ':</b><br />';
$text = trim($share[1]); $text = trim($share[1]);
if ($text != "") if ($text != "") {
$text .= "<hr />"; $text .= "<hr />";
}
if (substr(normalise_link($link), 0, 19) != "http://twitter.com/") { if (substr(normalise_link($link), 0, 19) != "http://twitter.com/") {
$text .= $headline.'<blockquote>'.trim($share[3])."</blockquote><br />"; $text .= $headline . '<blockquote>' . trim($share[3]) . "</blockquote><br />";
if ($link != "") if ($link != "") {
$text .= '<br /><a href="'.$link.'">[l]</a>'; $text .= '<br /><a href="' . $link . '">[l]</a>';
} else }
$text .= '<br /><a href="'.$link.'">'.$link.'</a>'; } else {
$text .= '<br /><a href="' . $link . '">' . $link . '</a>';
}
break; break;
case 4: case 4:
$headline .= '<br /><b>'.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8'); $headline .= '<br /><b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
$headline .= sprintf(t('<a href="%1$s" target="_blank">%2$s</a> %3$s'), $link, $userid, $posted); $headline .= t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $link, $userid, $posted);
$headline .= ":</b><br />"; $headline .= ":</b><br />";
$text = trim($share[1]); $text = trim($share[1]);
if ($text != "") if ($text != "") {
$text .= "<hr />"; $text .= "<hr />";
}
$text .= $headline.'<blockquote class="shared_content">'.trim($share[3])."</blockquote><br />"; $text .= $headline . '<blockquote class="shared_content">' . trim($share[3]) . "</blockquote><br />";
break; break;
case 5: case 5:
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.": <br />".$share[3]; $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
break; break;
case 6: // app.net case 6: // app.net
$text = $preshare."&gt;&gt; @".$userid_compact.": <br />".$share[3]; $text = $preshare . "&gt;&gt; @" . $userid_compact . ": <br />" . $share[3];
break; break;
case 7: // statusnet/GNU Social case 7: // statusnet/GNU Social
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')." @".$userid_compact.": ".$share[3]; $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . " @" . $userid_compact . ": " . $share[3];
break; break;
case 8: // twitter case 8: // twitter
$text = $preshare."RT @".$userid_compact.": ".$share[3]; $text = $preshare . "RT @" . $userid_compact . ": " . $share[3];
break; break;
case 9: // Google+/Facebook case 9: // Google+/Facebook
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.": <br />".$share[3]; $text = $preshare . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ": <br />" . $share[3];
if ($link != "") if ($link != "") {
$text .= "<br /><br />".$link; $text .= "<br /><br />" . $link;
}
break; break;
default: default:
$text = trim($share[1])."\n"; $text = trim($share[1]) . "\n";
$avatar = proxy_url($avatar, false, PROXY_SIZE_THUMB); $avatar = proxy_url($avatar, false, PROXY_SIZE_THUMB);
$tpl = get_markup_template('shared_content.tpl'); $tpl = get_markup_template('shared_content.tpl');
$text .= replace_macros($tpl, $text .= replace_macros($tpl, array(
array( '$profile' => $profile,
'$profile' => $profile, '$avatar' => $avatar,
'$avatar' => $avatar, '$author' => $author,
'$author' => $author, '$link' => $link,
'$link' => $link, '$posted' => $posted,
'$posted' => $posted, '$content' => trim($share[3])
'$reldate' => $reldate, )
'$content' => trim($share[3]) );
)
);
break; break;
} }

View File

@ -5,7 +5,6 @@
<img src="{{$avatar}}" height="32" width="32"> <img src="{{$avatar}}" height="32" width="32">
</a> </a>
{{/if}} {{/if}}
{{*<span><a href="{{$profile}}" target="_blank" class="shared-wall-item-name">{{$author}}</a> wrote the following <a href="{{$link}}" target="_blank">post</a>{{$reldate}}:</span>*}}
<div><a href="{{$profile}}" target="_blank" class="shared-wall-item-name"><span class="shared-author">{{$author}}</span></a></div> <div><a href="{{$profile}}" target="_blank" class="shared-wall-item-name"><span class="shared-author">{{$author}}</span></a></div>
<div class="shared-wall-item-ago"><small><a href="{{$link}}" target="_blank"><span class="shared-time">{{$posted}}</a></a></small></div> <div class="shared-wall-item-ago"><small><a href="{{$link}}" target="_blank"><span class="shared-time">{{$posted}}</a></a></small></div>
</div> </div>