本文整理汇总了PHP中Social::comment_broadcast_tokens方法的典型用法代码示例。如果您正苦于以下问题:PHP Social::comment_broadcast_tokens方法的具体用法?PHP Social::comment_broadcast_tokens怎么用?PHP Social::comment_broadcast_tokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Social
的用法示例。
在下文中一共展示了Social::comment_broadcast_tokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_comment_content
/**
* Formats a comment before it's broadcasted.
*
* @param WP_Comment $comment
* @param array $format
* @return string
*/
public function format_comment_content($comment, $format)
{
// Filter the format
$format = apply_filters('social_comment_broadcast_format', $format, $comment, $this);
$_format = $format;
$available = $this->max_broadcast_length();
$used_tokens = array();
// Gather used tokens and subtract remaining characters from available length
foreach (Social::comment_broadcast_tokens() as $token => $description) {
$replaced = 0;
$_format = str_replace($token, '', $_format, $replaced);
if ($replaced) {
$used_tokens[$token] = '';
}
}
$available = $available - strlen($_format);
// Prep token replacement content
foreach ($used_tokens as $token => $content) {
switch ($token) {
case '{url}':
$url = wp_get_shortlink($comment->comment_post_ID);
if (empty($url)) {
$url = home_url('?p=' . $comment->comment_post_ID);
}
$url .= '#comment-' . $comment->comment_ID;
$url = apply_filters('social_comment_broadcast_permalink', $url, $comment, $this);
$used_tokens[$token] = esc_url($url);
break;
case '{content}':
$used_tokens[$token] = strip_tags($comment->comment_content);
$used_tokens[$token] = str_replace(array("\n", "\r", PHP_EOL), '', $used_tokens[$token]);
$used_tokens[$token] = str_replace(' ', '', $used_tokens[$token]);
break;
}
}
// if {url} is used, pre-allocate its length
if (isset($used_tokens['{url}'])) {
$available = $available - strlen($used_tokens['{url}']);
}
$used_tokens['{content}'] = apply_filters('social_format_comment_content', $used_tokens['{content}'], $comment, $format, $this);
// Truncate content to size limit
if (strlen($used_tokens['{content}']) > $available) {
$used_tokens['{content}'] = substr($used_tokens['{content}'], 0, $available - 3) . '...';
}
foreach ($used_tokens as $token => $replacement) {
if (strpos($format, $token) !== false) {
$format = str_replace($token, $replacement, $format);
}
}
$format = apply_filters('social_comment_broadcast_content_formatted', $format, $comment, $this);
return $format;
}
示例2: format_comment_content
/**
* Formats a comment before it's broadcasted.
*
* @param WP_Comment $comment
* @param array $format
* @return string
*/
public function format_comment_content($comment, $format)
{
// Filter the format
$format = apply_filters('social_comment_broadcast_format', $format, $comment, $this);
$_format = $format;
$available = $this->max_broadcast_length();
foreach (Social::comment_broadcast_tokens() as $token => $description) {
$_format = str_replace($token, '', $_format);
}
$available = $available - strlen($_format);
$_format = explode(' ', $format);
foreach (Social::comment_broadcast_tokens() as $token => $description) {
$content = '';
switch ($token) {
case '{url}':
$url = wp_get_shortlink($comment->comment_post_ID);
if (empty($url)) {
$url = home_url('?p=' . $comment->comment_post_ID);
}
$url .= '#comment-' . $comment->comment_ID;
$url = apply_filters('social_comment_broadcast_permalink', $url, $comment, $this);
$content = esc_url($url);
break;
case '{content}':
$content = strip_tags($comment->comment_content);
$content = str_replace(array("\n", "\r", PHP_EOL), '', $content);
$content = str_replace(' ', '', $content);
break;
}
if (strlen($content) > $available) {
$content = substr($content, 0, $available - 3) . '...';
}
$content = apply_filters('social_format_comment_content', $content, $comment, $format, $this);
foreach ($_format as $haystack) {
if (strpos($haystack, $token) !== false and $available > 0) {
$haystack = str_replace($token, $content, $haystack);
$available = $available - strlen($haystack);
$format = str_replace($token, $content, $format);
break;
}
}
}
$format = apply_filters('social_comment_broadcast_content_formatted', $format, $comment, $this);
return $format;
}
示例3: esc_attr
<input type="text" class="regular-text" name="social_comment_broadcast_format" id="social_comment_broadcast_format" value="<?php
echo esc_attr(Social::option('comment_broadcast_format'));
?>
" />
<p class="description"><?php
_e('How you would like comments to be formatted when broadcasting to Twitter or Facebook.', 'social');
?>
</p>
<div class="description">
<?php
_e('Tokens:', 'social');
?>
<ul>
<?php
foreach (Social::comment_broadcast_tokens() as $token => $description) {
if (!empty($description)) {
$description = ' - ' . $description;
}
?>
<li><b><?php
echo esc_html($token);
?>
</b><?php
echo esc_html($description);
?>
</li>
<?php
}
?>
</ul>