本文整理汇总了PHP中wp_kses_hair函数 的典型用法代码示例。如果您正苦于以下问题:PHP wp_kses_hair函数的具体用法?PHP wp_kses_hair怎么用?PHP wp_kses_hair使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_kses_hair函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: convert
public function convert($amp_attributes = array())
{
if (!$this->has_tag(self::$tag)) {
return $this->content;
}
$matches = $this->get_tags(self::$tag);
if (empty($matches)) {
return $this->content;
}
$this->did_convert_elements = true;
$content = $this->content;
foreach ($matches as $match) {
$old_element = $match[0];
$old_attr = isset($match[2]) ? $match[2] : '';
$new_element = '';
$attributes = wp_kses_hair($old_attr, array('http', 'https'));
$attributes = $this->filter_attributes($attributes);
$attributes = array_merge($attributes, $amp_attributes);
// TODO: limit child nodes too (only allowed source, div+fallback, and div+placeholder)
$child_nodes = isset($match[4]) ? $match[4] : '';
$new_element .= sprintf('<amp-audio %s>%s</amp-audio>', $this->build_attributes_string($attributes), $child_nodes);
$old_pattern = '~' . preg_quote($old_element, '~') . '~';
$content = preg_replace($old_pattern, $new_element, $content, 1);
}
return $content;
}
开发者ID:vilav, 项目名称:amp-wp, 代码行数:26, 代码来源:class-amp-audio.php
示例2: convert
public function convert($amp_attributes = array())
{
if (!$this->has_tag(self::$tag)) {
return $this->content;
}
$matches = $this->get_tags(self::$tag);
if (empty($matches)) {
return $this->content;
}
$content = $this->content;
foreach ($matches as $match) {
$old_img = $match[0];
$old_img_attr = isset($match[2]) ? $match[2] : '';
$new_img = '';
$attributes = wp_kses_hair($old_img_attr, array('http', 'https'));
if (!empty($attributes['src'])) {
$attributes = $this->filter_attributes($attributes);
$attributes = array_merge($attributes, $amp_attributes);
// Workaround for https://github.com/Automattic/amp-wp/issues/20
// responsive + float don't mix
if (isset($attributes['class']) && (false !== strpos($attributes['class'], 'alignleft') || false !== strpos($attributes['class'], 'alignright'))) {
unset($attributes['layout']);
}
$new_img .= sprintf('<amp-img %s></amp-img>', $this->build_attributes_string($attributes));
}
$old_img_pattern = '~' . preg_quote($old_img, '~') . '~';
$content = preg_replace($old_img_pattern, $new_img, $content, 1);
}
return $content;
}
开发者ID:twclark0, 项目名称:amp-wp, 代码行数:30, 代码来源:class-amp-img.php
示例3: blip_embed_to_shortcode
/**
* Blip.tv embed code:
* <embed src="http://blip.tv/play/g8sVgpfaCgI%2Em4v" type="application/x-shockwave-flash" width="480" height="255" allowscriptaccess="always" allowfullscreen="true"></embed>
* Blip.tv shortcode is: [blip.tv url-or-something-else]
* */
function blip_embed_to_shortcode($content)
{
if (false === stripos($content, '/blip.tv/play/')) {
return $content;
}
$regexp = '!<embed((?:\\s+\\w+="[^"]*")*)\\s+src="http(?:\\:|�*58;)//(blip\\.tv/play/[^"]*)"((?:\\s+\\w+="[^"]*")*)\\s*(?:/>|>\\s*</embed>)!';
$regexp_ent = str_replace('&#0*58;', '&#0*58;|�*58;', htmlspecialchars($regexp, ENT_NOQUOTES));
foreach (array('regexp', 'regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$src = 'http://' . html_entity_decode($match[2]);
$params = $match[1] . $match[3];
if ('regexp_ent' == $reg) {
$src = html_entity_decode($src);
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
if (!isset($params['type']) || 'application/x-shockwave-flash' != $params['type']['value']) {
continue;
}
$content = str_replace($match[0], "[blip.tv {$src}]", $content);
}
}
return $content;
}
开发者ID:StefanBonilla, 项目名称:CoupSoup, 代码行数:32, 代码来源:blip.php
示例4: vimeo_embed_to_shortcode
function vimeo_embed_to_shortcode($content)
{
if (false === stripos($content, 'player.vimeo.com/video/')) {
return $content;
}
$regexp = '!<iframe\\s+src="http://player.vimeo.com/video/(\\d+)"((?:\\s+\\w+="[^"]*")*)></iframe>!i';
$regexp_ent = str_replace('&#0*58;', '&#0*58;|�*58;', htmlspecialchars($regexp, ENT_NOQUOTES));
foreach (array('regexp', 'regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$id = (int) $match[1];
$params = $match[2];
if ('regexp_ent' == $reg) {
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
$width = isset($params['width']) ? (int) $params['width']['value'] : 0;
$height = isset($params['height']) ? (int) $params['height']['value'] : 0;
$wh = '';
if ($width && $height) {
$wh = ' w=' . $width . ' h=' . $height;
}
$shortcode = '[vimeo ' . $id . $wh . ']';
$content = str_replace($match[0], $shortcode, $content);
}
}
return $content;
}
开发者ID:Bencheci, 项目名称:blueRavenStudiosProject, 代码行数:30, 代码来源:vimeo.php
示例5: convert
public function convert($amp_attributes = array())
{
if (!$this->has_tag(self::$tag)) {
return $this->content;
}
$iframes = $this->get_tags(self::$tag);
if (empty($iframes)) {
return $this->content;
}
$content = $this->content;
foreach ($iframes as $iframe) {
$old_iframe = $iframe[0];
$old_iframe_attr = isset($iframe[1]) ? $iframe[1] : '';
$new_iframe = '';
$attributes = wp_kses_hair($old_iframe_attr, array('http', 'https'));
if (!empty($attributes['src'])) {
$attributes = $this->filter_attributes($attributes);
$attributes = array_merge($attributes, $amp_attributes);
$new_iframe .= sprintf('<amp-iframe %s></amp-iframe>', $this->build_attributes_string($attributes));
}
$old_iframe_pattern = '~' . preg_quote($old_iframe, '~') . '~';
$content = preg_replace($old_iframe_pattern, $new_iframe, $content, 1);
}
return $content;
}
开发者ID:RockoDev, 项目名称:amp-wp, 代码行数:25, 代码来源:class-amp-iframe.php
示例6: dailymotion_embed_to_shortcode
/**
* Original codes:
*
* <embed height="270" type="application/x-shockwave-flash" width="480" src="http://www.dailymotion.com/swf/video/xekmrq?additionalInfos=0" wmode="opaque" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="never" allownetworking="internal" />
*
* <object width="480" height="240"><param name="movie" value="http://www.dailymotion.com/swf/video/xen4ms_ghinzu-cold-love-mirror-mirror_music?additionalInfos=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>
* <embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xen4ms_ghinzu-cold-love-mirror-mirror_music?additionalInfos=0" width="480" height="240" allowfullscreen="true" allowscriptaccess="always"></embed>
* </object><br /><b><a href="http://www.dailymotion.com/video/xen4ms_ghinzu-cold-love-mirror-mirror_music">Ghinzu - Cold Love (Mirror Mirror)</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/GhinzuTV">GhinzuTV</a>. - <a href="http://www.dailymotion.com/us/channel/music">Watch more music videos, in HD!</a></i>
*
* Code as of 01.01.11:
* <object width="560" height="421"><param name="movie" value="http://www.dailymotion.com/swf/video/xaose5?width=560&theme=denim&foreground=%2392ADE0&highlight=%23A2ACBF&background=%23202226&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xaose5?width=560&theme=denim&foreground=%2392ADE0&highlight=%23A2ACBF&background=%23202226&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0" width="560" height="421" allowfullscreen="true" allowscriptaccess="always"></embed></object><br /><b><a href="http://www.dailymotion.com/video/xaose5_sexy-surprise_na">Sexy Surprise</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/GilLavie">GilLavie</a>. - <a target="_self" href="http://www.dailymotion.com/channel/sexy/featured/1">Find more steamy, sexy videos.</a></i>
* movie param enforces anti-xss protection
*/
function dailymotion_embed_to_shortcode($content)
{
if (false === stripos($content, 'www.dailymotion.com/swf/')) {
return $content;
}
$regexp = '!<object.*>\\s*(<param.*></param>\\s*)*<embed((?:\\s+\\w+="[^"]*")*)\\s+src="http(?:\\:|�*58;)//(www\\.dailymotion\\.com/swf/[^"]*)"((?:\\s+\\w+="[^"]*")*)\\s*(?:/>|>\\s*</embed>)\\s*</object><br /><b><a .*>.*</a></b><br /><i>.*</i>!';
$regexp_ent = str_replace('&#0*58;', '&#0*58;|�*58;', htmlspecialchars($regexp, ENT_NOQUOTES));
foreach (array('regexp', 'regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$src = html_entity_decode($match[3]);
$params = $match[2] . $match[4];
if ('regexp_ent' == $reg) {
$src = html_entity_decode($src);
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
if (!isset($params['type']) || 'application/x-shockwave-flash' != $params['type']['value']) {
continue;
}
$id = basename(substr($src, strlen('www.dailymotion.com/swf')));
$id = preg_replace('/[^a-z0-9].*$/i', '', $id);
$content = str_replace($match[0], "[dailymotion id={$id}]", $content);
}
}
return $content;
}
开发者ID:sajidsan, 项目名称:sajidsan.github.io, 代码行数:42, 代码来源:dailymotion.php
示例7: youtube_embed_to_short_code
function youtube_embed_to_short_code($content)
{
if (false === strpos($content, 'youtube.com')) {
return $content;
}
//older codes
$regexp = '!<object width="\\d+" height="\\d+"><param name="movie" value="https?://www\\.youtube\\.com/v/([^"]+)"></param>(?:<param name="\\w+" value="[^"]*"></param>)*<embed src="https?://www\\.youtube\\.com/v/(.+)" type="application/x-shockwave-flash"(?: \\w+="[^"]*")* width="\\d+" height="\\d+"></embed></object>!i';
$regexp_ent = htmlspecialchars($regexp, ENT_NOQUOTES);
$old_regexp = '!<embed(?:\\s+\\w+="[^"]*")*\\s+src="https?(?:\\:|�*58;)//www\\.youtube\\.com/v/([^"]+)"(?:\\s+\\w+="[^"]*")*\\s*(?:/>|>\\s*</embed>)!';
$old_regexp_ent = str_replace('&#0*58;', '&#0*58;|�*58;', htmlspecialchars($old_regexp, ENT_NOQUOTES));
//new code
$ifr_regexp = '!<iframe((?:\\s+\\w+="[^"]*")*?)\\s+src="(https?:)?//(?:www\\.)*youtube.com/embed/([^"]+)".*?</iframe>!i';
$ifr_regexp_ent = str_replace('&#0*58;', '&#0*58;|�*58;', htmlspecialchars($ifr_regexp, ENT_NOQUOTES));
foreach (array('regexp', 'regexp_ent', 'old_regexp', 'old_regexp_ent', 'ifr_regexp', 'ifr_regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
// Hack, but '?' should only ever appear once, and
// it should be for the 1st field-value pair in query string,
// if it is present
// YouTube changed their embed code.
// Example of how it is now:
// <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
// As shown at the start of function, previous YouTube didn't '?'
// the 1st field-value pair.
if (in_array($reg, array('ifr_regexp', 'ifr_regexp_ent'))) {
$params = $match[1];
if ('ifr_regexp_ent' == $reg) {
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
$width = isset($params['width']) ? (int) $params['width']['value'] : 0;
$height = isset($params['height']) ? (int) $params['height']['value'] : 0;
$wh = '';
if ($width && $height) {
$wh = "&w={$width}&h={$height}";
}
$url = esc_url_raw("https://www.youtube.com/watch?v={$match[3]}{$wh}");
} else {
$match[1] = str_replace('?', '&', $match[1]);
$url = esc_url_raw("https://www.youtube.com/watch?v=" . html_entity_decode($match[1]));
}
$content = str_replace($match[0], "[youtube {$url}]", $content);
/**
* Fires before the YouTube embed is transformed into a shortcode.
*
* @module shortcodes
*
* @since 1.2.0
*
* @param string youtube Shortcode name.
* @param string $url YouTube video URL.
*/
do_action('jetpack_embed_to_shortcode', 'youtube', $url);
}
}
return $content;
}
开发者ID:phototech, 项目名称:sailvenice, 代码行数:59, 代码来源:youtube.php
示例8: wp_kses_attr
function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols)
{
# Is there a closing XHTML slash at the end of the attributes?
$xhtml_slash = '';
if (preg_match('%\\s/\\s*$%', $attr)) {
$xhtml_slash = ' /';
}
# Are any attributes allowed at all for this element?
if (@count($allowed_html[strtolower($element)]) == 0) {
return "<{$element}{$xhtml_slash}>";
}
# Split it
$attrarr = wp_kses_hair($attr, $allowed_protocols);
# Go through $attrarr, and save the allowed attributes for this element
# in $attr2
$attr2 = '';
foreach ($attrarr as $arreach) {
if (!@isset($allowed_html[strtolower($element)][strtolower($arreach['name'])])) {
continue;
}
# the attribute is not allowed
$current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
if ($current == '') {
continue;
}
# the attribute is not allowed
if (!is_array($current)) {
$attr2 .= ' ' . $arreach['whole'];
} else {
# there are some checks
$ok = true;
foreach ($current as $currkey => $currval) {
if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
$ok = false;
break;
}
}
if ($ok) {
$attr2 .= ' ' . $arreach['whole'];
}
# it passed them
}
# if !is_array($current)
}
# foreach
# Remove any "<" or ">" characters
$attr2 = preg_replace('/[<>]/', '', $attr2);
return "<{$element}{$attr2}{$xhtml_slash}>";
}
开发者ID:robertlange81, 项目名称:Website, 代码行数:49, 代码来源:kses.php
示例9: flickr_embed_to_shortcode
function flickr_embed_to_shortcode($content)
{
if (false === stripos($content, '/www.flickr.com/apps/video/stewart.swf')) {
return $content;
}
$regexp = '%(<object.*?(?:<(?!/?(?:object|embed)\\s+).*?)*?)?<embed((?:\\s+\\w+="[^"]*")*)\\s+src="http(?:\\:|�*58;)//www.flickr.com/apps/video/stewart.swf[^"]*"((?:\\s+\\w+="[^"]*")*)\\s*(?:/>|>\\s*</embed>)(?(1)\\s*</object>)%';
$regexp_ent = str_replace(array('&#0*58;', '[^>]*', '[^<]*'), array('&#0*58;|�*58;', '[^&]*(?:&(?!gt;)[^&]*)*', '[^&]*(?:&(?!lt;)[^&]*)*'), htmlspecialchars($regexp, ENT_NOQUOTES));
foreach (array('regexp', 'regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$params = $match[2] . $match[3];
if ('regexp_ent' == $reg) {
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
if (!isset($params['type']) || 'application/x-shockwave-flash' != $params['type']['value'] || !isset($params['flashvars'])) {
continue;
}
wp_parse_str(html_entity_decode($params['flashvars']['value']), $flashvars);
if (!isset($flashvars['photo_id'])) {
continue;
}
$code_atts = array('video' => $flashvars['photo_id']);
if (isset($flashvars['flickr_show_info_box']) && 'true' == $flashvars['flickr_show_info_box']) {
$code_atts['show_info'] = 'true';
}
if (!empty($flashvars['photo_secret'])) {
$code_atts['secret'] = $flashvars['photo_secret'];
}
if (!empty($params['width']['value'])) {
$code_atts['w'] = (int) $params['width']['value'];
}
if (!empty($params['height']['value'])) {
$code_atts['h'] = (int) $params['height']['value'];
}
$code = '[flickr';
foreach ($code_atts as $k => $v) {
$code .= " {$k}={$v}";
}
$code .= ']';
$content = str_replace($match[0], $code, $content);
/** This action is documented in modules/shortcodes/youtube.php */
do_action('jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id']);
}
}
return $content;
}
开发者ID:StefanBonilla, 项目名称:CoupSoup, 代码行数:49, 代码来源:flickr.php
示例10: jetpack_slide_embed_to_short_code
/**
* slideshow and slideguest shortcodes for slide.com
* [slideshow id=2233785415202545677&w=426&h=320]
*/
function jetpack_slide_embed_to_short_code($content)
{
global $content_width;
if (false === strpos($content, 'slide.com/widgets')) {
return $content;
}
$regexp = '!<div><embed((?:\\s+\\w+="[^"]*")*)\\s+src="http://widget[^"]+slide\\.com/widgets/slideticker\\.swf"((?:\\s+\\w+="[^"]*")*)\\s*(?:/?>|>\\s*</embed>)\\s*<div(?:\\s+[^>]+).*?slide\\.com/p1/.*?slide\\.com/p2.*?</div>\\s*</div>!i';
$regexp_ent = htmlspecialchars($regexp, ENT_NOQUOTES);
foreach (array('regexp', 'regexp_ent') as $reg) {
if (!preg_match_all(${$reg}, $content, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$params = $match[1] . $match[2];
if ('regexp_ent' == $reg) {
$params = html_entity_decode($params);
}
$params = wp_kses_hair($params, array('http'));
if (!isset($params['type']) || 'application/x-shockwave-flash' != $params['type']['value'] || !isset($params['flashvars'])) {
continue;
}
wp_parse_str(html_entity_decode($params['flashvars']['value']), $flashvars);
if (empty($flashvars['channel'])) {
continue;
}
$id = $flashvars['channel'];
$width = 400;
if (!empty($params['width']['value'])) {
$width = (int) $params['width']['value'];
} elseif (!empty($params['style']['value']) && preg_match('/width\\s*:\\s*(\\d+)/i', $params['style']['value'], $width_match)) {
$width = (int) $width_match[1];
}
$height = 300;
if (!empty($params['height']['value'])) {
$height = (int) $params['height']['value'];
} elseif (!empty($params['style']['value']) && preg_match('/height\\s*:\\s*(\\d+)/i', $params['style']['value'], $height_match)) {
$height = (int) $height_match[1];
}
if ($content_width && $width > $content_width) {
$height = intval($height * $content_width / $width);
$width = $content_width;
}
$content = str_replace($match[0], "[slideshow id={$id}&w={$width}&h={$height}]", $content);
do_action('jetpack_embed_to_shortcode', 'slideshow', $id);
}
}
return $content;
}
开发者ID:Bencheci, 项目名称:blueRavenStudiosProject, 代码行数:52, 代码来源:slide.php
示例11: add_image_placeholders
public static function add_image_placeholders($content)
{
// Don't load for feeds, previews, attachment pages, non-mobile views
if (is_preview() || is_feed() || is_attachment() || function_exists('jetpack_is_mobile') && !jetpack_is_mobile()) {
return $content;
}
// In case you want to change the placeholder image
$placeholder_image = apply_filters('responsive_images_placeholder_image', self::get_url('images/1x1.trans.gif'));
preg_match_all('#<img[^>]+?[\\/]?>#', $content, $images, PREG_SET_ORDER);
if (empty($images)) {
return $content;
}
foreach ($images as $image) {
$attributes = wp_kses_hair($image[0], array('http', 'https'));
$new_image = '<img';
$new_image_src = '';
foreach ($attributes as $attribute) {
$name = $attribute['name'];
$value = $attribute['value'];
// Remove the width and height attributes
if (in_array($name, array('width', 'height'))) {
continue;
}
// Move the src to a data attribute and replace with a placeholder
if ('src' == $name) {
$new_image_src = html_entity_decode(urldecode($value));
parse_str(parse_url($new_image_src, PHP_URL_QUERY), $image_args);
$new_image_src = remove_query_arg('h', $new_image_src);
$new_image_src = remove_query_arg('w', $new_image_src);
$new_image .= sprintf(' data-full-src="%s"', esc_url($new_image_src));
if (isset($image_args['w'])) {
$new_image .= sprintf(' data-full-width="%s"', esc_attr($image_args['w']));
}
if (isset($image_args['h'])) {
$new_image .= sprintf(' data-full-height="%s"', esc_attr($image_args['h']));
}
// replace actual src with our placeholder
$value = $placeholder_image;
}
$new_image .= sprintf(' %s="%s"', $name, esc_attr($value));
}
$new_image .= '/>';
$new_image .= sprintf('<noscript><img src="%s" /></noscript>', $new_image_src);
// compat for no-js and better crawling
$content = str_replace($image[0], $new_image, $content);
}
return $content;
}
开发者ID:gopinathshiva, 项目名称:wordpress-vip-plugins, 代码行数:48, 代码来源:responsive-images.php
示例12: apostrophe_get_url
/**
* Search post content for a link
* This is used for "link" post formats, so we can automatically link from the archive page to the link itself.
*/
function apostrophe_get_url()
{
$post_link = get_the_permalink();
if (preg_match('/<a (.+?)>/', get_the_content(), $match)) {
$link = array();
foreach (wp_kses_hair($match[1], array('http')) as $attr) {
$link[$attr['name']] = $attr['value'];
}
$post_link = $link['href'];
}
return $post_link;
}
开发者ID:glugpace, 项目名称:glugpace.org, 代码行数:16, 代码来源:functions.php
示例13: sfc_publish_automatic
function sfc_publish_automatic($id, $post)
{
// check to make sure post is published
if ($post->post_status !== 'publish') {
return;
}
// check options to see if we need to send to FB at all
$options = get_option('sfc_options');
if (!$options['autopublish_app'] && !$options['autopublish_profile']) {
return;
}
// load facebook platform
include_once 'facebook-platform/facebook.php';
$fb = new Facebook($options['api_key'], $options['app_secret']);
// to do this autopublish, we might need to switch users
if ($options['user'] && $options['session_key']) {
$tempuser = $fb->user;
$tempkey = $fb->api_client->session_key = $session_key;
$fb->set_user($options['user'], $options['session_key']);
} else {
return;
// safety net: if we don't have a user and session key, we can't publish properly.
}
// build the post to send to FB
// apply the content filters, in case some plugin is doing weird image stuff
$content = apply_filters('the_content', $post->post_content);
// look for the images to add with image_src
$images = array();
// get the post thumbnail, put it first in the image list
if (current_theme_supports('post-thumbnails')) {
if (has_post_thumbnail($post->ID)) {
$thumbid = get_post_thumbnail_id($post->ID);
$att = wp_get_attachment_image_src($thumbid, 'full');
$images[] = $att[0];
}
}
// look for any images in the content
if (preg_match_all('/<img (.+?)>/', $content, $matches)) {
foreach ($matches[1] as $match) {
foreach (wp_kses_hair($match, array('http')) as $attr) {
$img[$attr['name']] = $attr['value'];
}
if (isset($img['src'])) {
if (isset($img['class']) && false === strpos($img['class'], 'wp-smiley')) {
// ignore smilies
$images[] = $img['src'];
}
}
}
}
// build the attachment
$permalink = get_permalink($post->ID);
$attachment['name'] = $post->post_title;
$attachment['href'] = $permalink;
$attachment['description'] = sfc_publish_make_excerpt($post->post_content);
$attachment['comments_xid'] = urlencode($permalink);
// image attachments (up to 5, as that's all FB allows)
$count = 0;
foreach ($images as $image) {
$attachment['media'][$count]['type'] = 'image';
$attachment['media'][$count]['src'] = $image;
$attachment['media'][$count]['href'] = $permalink;
$count++;
if ($count == 5) {
break;
}
}
// Read Post link
$action_links[0]['text'] = 'Read Post';
$action_links[0]['href'] = $permalink;
// Link to comments
$action_links[1]['text'] = 'See Comments';
$action_links[1]['href'] = get_comments_link($post->ID);
// publish to page
if ($options['autopublish_app'] && !get_post_meta($id, '_fb_post_id_app', true) && $options['fanpage']) {
if ($options['fanpage']) {
$who = $options['fanpage'];
} else {
$who = $options['appid'];
}
// check to see if we can send to FB at all
$result = $fb->api_client->users_hasAppPermission('publish_stream', $who);
if (!$result) {
break;
}
$fb_post_id = $fb->api_client->stream_publish(null, json_encode($attachment), json_encode($action_links), null, $who);
if ($fb_post_id) {
// update the post id so as to prevent automatically posting it twice
update_post_meta($id, '_fb_post_id_app', $fb_post_id);
}
}
// publish to profile
if ($options['autopublish_profile'] && !get_post_meta($id, '_fb_post_id_profile', true)) {
// check to see if we can send to FB at all
$result = $fb->api_client->users_hasAppPermission('publish_stream');
if (!$result) {
break;
}
$fb_post_prof_id = $fb->api_client->stream_publish(null, json_encode($attachment), json_encode($action_links));
if ($fb_post_prof_id) {
//.........这里部分代码省略.........
开发者ID:TheReaCompany, 项目名称:pooplog, 代码行数:101, 代码来源:sfc-publish.php
示例14: fetch_posts
//.........这里部分代码省略.........
// TODO reorg this as needed
switch ((string) $tpost['type']) {
case 'photo':
$post['format'] = 'image';
$post['media']['src'] = (string) $tpost->{'photo-url'}[0];
$post['media']['link'] =(string) $tpost->{'photo-link-url'};
$post['media']['width'] = (string) $tpost['width'];
$post['media']['height'] = (string) $tpost['height'];
$content = '';
if ( !empty( $post['media']['link'] ) ) $content .= "<a href='{$post['media']['link']}'>";
$content .= "<img src='{$post['media']['src']}' width='{$post['media']['width']}' height='{$post['media']['height']}' />";
if ( !empty( $link ) ) $content .= "</a>";
$post['post_content'] = $content;
$post['post_content'] .= "\n\n" . (string) $tpost->{'photo-caption'};
$post['post_title'] = '';
if ( !empty( $tpost->{'photoset'} ) ) {
foreach ( $tpost->{'photoset'}->{'photo'} as $photo ) {
$post['gallery'][] = array (
'src'=>$photo->{'photo-url'}[0],
'width'=>$photo['width'],
'height'=>$photo['height'],
'caption'=>$photo['caption'],
);
}
}
break;
case 'quote':
$post['format'] = 'quote';
$post['post_content'] = (string) $tpost->{'quote-text'};
$post['post_title'] = (string) $tpost->{'quote-source'};
break;
case 'link':
$post['format'] = 'link';
$linkurl = (string) $tpost->{'link-url'};
$linktext = (string) $tpost->{'link-text'};
$post['post_content'] = "<a href='{$linkurl}'>{$linktext}</a>";
$post['post_title'] = (string) $tpost->{'link-description'};
break;
case 'conversation':
$post['format'] = 'chat';
$post['post_title'] = (string) $tpost->{'conversation-title'};
$post['post_content'] = (string) $tpost->{'conversation-text'};
break;
case 'audio':
$post['format'] = 'audio';
$post['media']['filename'] = basename( (string) $tpost->{'authorized-download-url'} ) . '.mp3';
$post['media']['audio'] = (string) $tpost->{'authorized-download-url'} .'?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio';
$post['post_content'] = (string) $tpost->{'authorized-download-url'};
$post['post_content'] .= "\n\n" . (string) $tpost->{'audio-caption'};
$post['post_title'] = '';
break;
case 'video':
$post['format'] = 'video';
if ( is_serialized( (string) $tpost->{'video-source'} ) ) {
if ( preg_match('|\'(http://.*video_file.*)\'|U', $tpost->{'video-player'}[0], $matches) ) {
$post['media']['video'] = $matches[1];
$val = unserialize( (string) $tpost->{'video-source'} );
$vidmeta = $val['o1'];
$post['media']['filename'] = basename($post['media']['video']) . '.' . $vidmeta['extension'];
$post['media']['width'] = $vidmeta['width'];
$post['media']['height'] = $vidmeta['height'];
}
} else if ( false !== strpos( (string) $tpost->{'video-source'}, 'embed' ) ) {
if ( preg_match_all('/<embed (.+?)>/', (string) $tpost->{'video-source'}, $matches) ) {
foreach ($matches[1] as $match) {
foreach ( wp_kses_hair($match, array('http')) as $attr)
$embed[$attr['name']] = $attr['value'];
}
// special case for weird youtube vids
$embed['src'] = preg_replace('|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $embed['src']);
// TODO find other special cases, since tumblr is full of them
$post['post_content'] = $embed['src'];
}
} else {
$post['post_content'] = (string) $tpost->{'video-player'}[0];
$post['post_content'] .= (string) $tpost->{'video-source'};
}
$post['post_content'] .= "\n\n" . (string) $tpost->{'video-caption'};
$post['post_title'] = '';
break;
case 'answer':
$post['post_title'] = (string) $tpost->{'question'};
$post['post_content'] = (string) $tpost->{'answer'};
break;
case 'regular':
default:
$post['post_title'] = (string) $tpost->{'regular-title'};
$post['post_content'] = (string) $tpost->{'regular-body'};
break;
}
$posts[] = $post;
}
return $posts;
}
开发者ID:robotconscience, 项目名称:Robotconscience.com, 代码行数:101, 代码来源:tumblr-importer.php
示例15: wp_kses_attr
/**
* Removes all attributes, if none are allowed for this element.
*
* If some are allowed it calls wp_kses_hair() to split them further, and then
* it builds up new HTML code from the data that kses_hair() returns. It also
* removes "<" and ">" characters, if there are any left. One more thing it does
* is to check if the tag has a closing XHTML slash, and if it does, it puts one
* in the returned code as well.
*
* @since 1.0.0
*
* @param string $element HTML element/tag
* @param string $attr HTML attributes from HTML element to closing HTML element tag
* @param array $allowed_html Allowed HTML elements
* @param array $allowed_protocols Allowed protocols to keep
* @return string Sanitized HTML element
*/
function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
// Is there a closing XHTML slash at the end of the attributes?
if ( ! is_array( $allowed_html ) )
$allowed_html = wp_kses_allowed_html( $allowed_html );
$xhtml_slash = '';
if (preg_match('%\s*/\s*$%', $attr))
$xhtml_slash = ' /';
// Are any attributes allowed at all for this element?
if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 )
return "<$element$xhtml_slash>";
// Split it
$attrarr = wp_kses_hair($attr, $allowed_protocols);
// Go through $attrarr, and save the allowed attributes for this element
// in $attr2
$attr2 = '';
$allowed_attr = $allowed_html[strtolower($element)];
foreach ($attrarr as $arreach) {
if ( ! isset( $allowed_attr[strtolower($arreach['name'])] ) )
continue; // the attribute is not allowed
$current = $allowed_attr[strtolower($arreach['name'])];
if ( $current == '' )
continue; // the attribute is not allowed
if ( strtolower( $arreach['name'] ) == 'style' ) {
$orig_value = $arreach['value'];
$value = safecss_filter_attr( $orig_value );
if ( empty( $value ) )
continue;
$arreach['value'] = $value;
$arreach['whole'] = str_replace( $orig_value, $value, $arreach['whole'] );
}
if ( ! is_array($current) ) {
$attr2 .= ' '.$arreach['whole'];
// there are no checks
} else {
// there are some checks
$ok = true;
foreach ($current as $currkey => $currval) {
if ( ! wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval) ) {
$ok = false;
break;
}
}
if ( $ok )
$attr2 .= ' '.$arreach['whole']; // it passed them
} // if !is_array($current)
} // foreach
// Remove any "<" or ">" characters
$attr2 = preg_replace('/[<>]/', '', $attr2);
return "<$element$attr2$xhtml_slash>";
}
开发者ID:ShankarVellal, 项目名称:WordPress, 代码行数:82, 代码来源:kses.php
示例16: fetch_posts
//.........这里部分代码省略.........
switch ( (string) $tpost->type ) {
case 'photo':
$post['format'] = 'image';
$post['media']['src'] = (string) $tpost->photos[0]->original_size->url;
$post['media']['link'] = '';//TODO: Find out what to use here.(string) $tpost->{'photo-link-url'};
$post['media']['width'] = (string) $tpost->photos[0]->original_size->width;
$post['media']['height'] = (string) $tpost->photos[0]->original_size->height;
$post['post_content'] = (string) $tpost->caption;
if ( ! empty( $tpost->photos ) ) {
$post['format'] = 'gallery';
foreach ( $tpost->photos as $photo ) {
$post['gallery'][] = array (
'src' => $photo->original_size->url,
'width' => $photo->original_size->width,
'height' => $photo->original_size->height,
'caption' => $photo->caption,
);
}
}
break;
case 'quote':
$post['format'] = 'quote';
$post['post_content'] = '<blockquote>' . (string) $tpost->text . '</blockquote>';
$post['post_content'] .= "\n\n<div class='attribution'>" . (string) $tpost->source . '</div>';
break;
case 'link':
$post['format'] = 'link';
$linkurl = (string) $tpost->url;
$linktext = (string) $tpost->title;
$post['post_content'] = "<a href='$linkurl'>$linktext</a>";
if ( ! empty( $tpost->description ) )
$post['post_content'] .= '<div class="link_description">' . (string) $tpost->description . '</div>';
$post['post_title'] = (string) $tpost->title;
break;
case 'chat':
$post['format'] = 'chat';
$post['post_title'] = (string) $tpost->title;
$post['post_content'] = (string) $tpost->body;
break;
case 'audio':
$post['format'] = 'audio';
$post['media']['filename'] = basename( (string) $tpost->audio_url );
// If no .mp3 extension, add one so that sideloading works.
if ( ! preg_match( '/\.mp3$/', $post['media']['filename'] ) )
$post['media']['filename'] .= '.mp3';
$post['media']['audio'] = (string) $tpost->audio_url .'?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio';
$post['post_content'] = (string) $tpost->player . "\n" . (string) $tpost->caption;
break;
case 'video':
$post['format'] = 'video';
$post['post_content'] = '';
$video = array_shift( $tpost->player );
if ( false !== strpos( (string) $video->embed_code, 'embed' ) ) {
if ( preg_match_all('/<embed (.+?)>/', (string) $video->embed_code, $matches) ) {
foreach ($matches[1] as $match) {
foreach ( wp_kses_hair( $match, array( 'http' ) ) as $attr )
$embed[ $attr['name'] ] = $attr['value'];
}
// special case for weird youtube vids
$embed['src'] = preg_replace( '|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $embed['src'] );
// TODO find other special cases, since tumblr is full of them
$post['post_content'] = $embed['src'];
}
// Sometimes, video-source contains iframe markup.
if ( preg_match( '/<iframe/', $video->embed_code ) ) {
$embed['src'] = preg_replace( '|<iframe.*src="http://www.youtube.com/embed/([a-zA-Z0-9_\-]+)\??.*".*</iframe>|', 'http://www.youtube.com/watch?v=$1', $video->embed_code );
$post['post_content'] = $embed['src'];
}
} elseif ( preg_match( '/<iframe.*vimeo/', $video->embed_code ) ) {
$embed['src'] = preg_replace( '|<iframe.*src="(http://player.vimeo.com/video/([a-zA-Z0-9_\-]+))\??.*".*</iframe>.*|', 'http://vimeo.com/$2', $video->embed_code );
$post['post_content'] = $embed['src'];
} else {
// @todo: See if the video source is going to be oEmbed'able before adding the flash player
$post['post_content'] .= $video->embed_code;
}
$post['post_content'] .= "\n" . (string) $tpost->caption;
break;
case 'answer':
// TODO: Include asking_name and asking_url values?
$post['post_title'] = (string) $tpost->question;
$post['post_content'] = (string) $tpost->answer;
break;
case 'regular':
case 'text':
default:
$post['post_title'] = (string) $tpost->title;
$post['post_content'] = (string) $tpost->body;
break;
}
$posts[] = $post;
}
return $posts;
}
开发者ID:unisexx, 项目名称:drtooth, 代码行数:101, 代码来源:tumblr-importer.php
经常有很多初学者问到在delphi中如何调用SQL Server的存储过程?问题其实很好解决,但
阅读:483| 2022-07-18
PacktPublishing/Python-Machine-Learning-Second-Edition: Python Machine Learning
阅读:929| 2022-08-18
There are use-after-free vulnerabilities caused by timer handler in net/rose/ros
阅读:678| 2022-07-08
armancodv/building-energy-model-matlab: It is a small software which is develope
阅读:1112| 2022-08-17
win7系统电脑使用过程中有不少朋友表示遇到过win7系统USB驱动器RAM的状况,当出现win7
阅读:834| 2022-11-06
elipapa/markdown-cv: a simple template to write your CV in a readable markdown f
阅读:484| 2022-08-17
tboronczyk/localization-middleware: PSR-15 middleware to assist primarily with l
阅读:497| 2022-08-16
再的笔顺是什么?再的笔顺笔画顺序怎么写?还有再的拼音及意思是什么,好多初学练字者
阅读:510| 2022-07-30
Call Me Maybe 中英字幕 对于加拿大歌手卡莉·蕾·吉普森很多人有些陌生,她隶属于贾
阅读:574| 2022-11-06
Delphi xe7 android实现透明度可以调整的对话框 要实现对话框透明度可以调
阅读:1551| 2022-07-22
请发表评论