introducing html_sprintf for easier sprintf'ing with htmlspecialchars

This commit is contained in:
Mikael Nordfeldth 2015-09-06 01:53:11 +02:00
parent ea75e1c29c
commit 4354ce21d1
2 changed files with 14 additions and 5 deletions

View File

@ -2429,3 +2429,12 @@ function common_strip_html($html, $trim=true, $save_whitespace=false)
$text = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8'); $text = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8');
return $trim ? trim($text) : $text; return $trim ? trim($text) : $text;
} }
function html_sprintf()
{
$args = func_get_args();
for ($i=1; $i<count($args); $i++) {
$args[$i] = htmlspecialchars($args[$i]);
}
return call_user_func_array('sprintf', $args);
}

View File

@ -72,7 +72,7 @@ class ActivityPlugin extends Plugin
// TRANS: Text for "started following" item in activity plugin. // TRANS: Text for "started following" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a profile URL, %4$s is a profile name. // TRANS: %3$s is a profile URL, %4$s is a profile name.
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> started following <a href="%3$s">%4$s</a>.'), $rendered = html_sprintf(_m('<a href="%1$s">%2$s</a> started following <a href="%3$s">%4$s</a>.'),
$profile->getUrl(), $profile->getUrl(),
$profile->getBestName(), $profile->getBestName(),
$other->getUrl(), $other->getUrl(),
@ -110,7 +110,7 @@ class ActivityPlugin extends Plugin
// TRANS: Text for "stopped following" item in activity plugin. // TRANS: Text for "stopped following" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a profile URL, %4$s is a profile name. // TRANS: %3$s is a profile URL, %4$s is a profile name.
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> stopped following <a href="%3$s">%4$s</a>.'), $rendered = html_sprintf(_m('<a href="%1$s">%2$s</a> stopped following <a href="%3$s">%4$s</a>.'),
$profile->getUrl(), $profile->getUrl(),
$profile->getBestName(), $profile->getBestName(),
$other->getUrl(), $other->getUrl(),
@ -155,7 +155,7 @@ class ActivityPlugin extends Plugin
// TRANS: Text for "stopped liking" item in activity plugin. // TRANS: Text for "stopped liking" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a notice URL, %4$s is an author name. // TRANS: %3$s is a notice URL, %4$s is an author name.
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> stopped liking <a href="%3$s">%4$s\'s update</a>.'), $rendered = html_sprintf(_m('<a href="%1$s">%2$s</a> stopped liking <a href="%3$s">%4$s\'s update</a>.'),
$profile->getUrl(), $profile->getUrl(),
$profile->getBestName(), $profile->getBestName(),
$notice->getUrl(), $notice->getUrl(),
@ -200,7 +200,7 @@ class ActivityPlugin extends Plugin
// TRANS: Text for "joined group" item in activity plugin. // TRANS: Text for "joined group" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a group URL, %4$s is a group name. // TRANS: %3$s is a group URL, %4$s is a group name.
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'), $rendered = html_sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'),
$profile->getUrl(), $profile->getUrl(),
$profile->getBestName(), $profile->getBestName(),
$group->homeUrl(), $group->homeUrl(),
@ -241,7 +241,7 @@ class ActivityPlugin extends Plugin
// TRANS: Text for "left group" item in activity plugin. // TRANS: Text for "left group" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a group URL, %4$s is a group name. // TRANS: %3$s is a group URL, %4$s is a group name.
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> left the group <a href="%3$s">%4$s</a>.'), $rendered = html_sprintf(_m('<a href="%1$s">%2$s</a> left the group <a href="%3$s">%4$s</a>.'),
$profile->getUrl(), $profile->getUrl(),
$profile->getBestName(), $profile->getBestName(),
$group->homeUrl(), $group->homeUrl(),