本文整理汇总了PHP中Social::broadcast_tokens方法的典型用法代码示例。如果您正苦于以下问题:PHP Social::broadcast_tokens方法的具体用法?PHP Social::broadcast_tokens怎么用?PHP Social::broadcast_tokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Social
的用法示例。
在下文中一共展示了Social::broadcast_tokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_content
/**
* Formats the broadcast content.
*
* @param object $post
* @param string $format
* @return string
*/
public function format_content($post, $format)
{
// Filter the format
$format = apply_filters('social_broadcast_format', $format, $post, $this);
$_format = $format;
$available = $this->max_broadcast_length();
foreach (Social::broadcast_tokens() as $token => $description) {
$_format = str_replace($token, '', $_format);
}
$available = $available - strlen($_format);
$_format = explode(' ', $format);
foreach (Social::broadcast_tokens() as $token => $description) {
$content = '';
switch ($token) {
case '{url}':
$url = wp_get_shortlink($post->ID);
if (empty($url)) {
$url = home_url('?p=' . $post->ID);
}
$url = apply_filters('social_broadcast_permalink', $url, $post, $this);
$content = esc_url($url);
break;
case '{title}':
$content = htmlspecialchars_decode($post->post_title);
break;
case '{content}':
$content = htmlspecialchars_decode(strip_tags($post->post_content));
$content = str_replace(array("\n", "\r", PHP_EOL, ' '), ' ', $content);
$content = preg_replace('/\\s+/', ' ', $content);
break;
case '{author}':
$user = get_userdata($post->post_author);
$content = htmlspecialchars_decode($user->display_name);
break;
case '{date}':
$content = get_date_from_gmt($post->post_date_gmt);
break;
}
if (strlen($content) > $available) {
if (in_array($token, array('{date}', '{author}'))) {
$content = '';
} else {
$content = substr($content, 0, $available - 3) . '...';
}
}
// Filter the content
$content = apply_filters('social_format_content', $content, $post, $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;
}
}
}
// Filter the content
$format = apply_filters('social_broadcast_content_formatted', $format, $post, $this);
return $format;
}
示例2: esc_attr
<input type="text" class="regular-text" name="social_broadcast_format" id="social_broadcast_format" value="<?php
echo esc_attr(Social::option('broadcast_format'));
?>
" />
<p class="description"><?php
_e('How you would like posts to be formatted when broadcasting to Twitter or Facebook?', 'social');
?>
</p>
<div class="description">
<?php
_e('Tokens:', 'social');
?>
<ul>
<?php
foreach (Social::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>