本文整理汇总了PHP中get_enclosed函数的典型用法代码示例。如果您正苦于以下问题:PHP get_enclosed函数的具体用法?PHP get_enclosed怎么用?PHP get_enclosed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_enclosed函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: do_enclose
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added. This is called as
* pingbacks and trackbacks.
*
* @package WordPress
* @since 1.5.0
*
* @uses $wpdb
*
* @param string $content Post Content
* @param int $post_ID Post ID
*/
function do_enclose($content, $post_ID)
{
global $wpdb;
include_once ABSPATH . WPINC . '/class-IXR.php';
$log = debug_fopen(ABSPATH . 'enclosures.log', 'a');
$post_links = array();
debug_fwrite($log, 'BEGIN ' . date('YmdHis', time()) . "\n");
$pung = get_enclosed($post_ID);
$ltrs = '\\w';
$gunk = '/#~:.?+=&%@!\\-';
$punc = '.:?\\-';
$any = $ltrs . $gunk . $punc;
preg_match_all("{\\b http : [{$any}] +? (?= [{$punc}] * [^{$any}] | \$)}x", $content, $post_links_temp);
debug_fwrite($log, 'Post contents:');
debug_fwrite($log, $content . "\n");
foreach ((array) $post_links_temp[0] as $link_test) {
if (!in_array($link_test, $pung)) {
// If we haven't pung it already
$test = parse_url($link_test);
if (isset($test['query'])) {
$post_links[] = $link_test;
} elseif ($test['path'] != '/' && $test['path'] != '') {
$post_links[] = $link_test;
}
}
}
foreach ((array) $post_links as $url) {
if ($url != '' && !$wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%'))) {
if ($headers = wp_get_http_headers($url)) {
$len = (int) $headers['content-length'];
$type = $wpdb->escape($headers['content-type']);
$allowed_types = array('video', 'audio');
if (in_array(substr($type, 0, strpos($type, "/")), $allowed_types)) {
$meta_value = "{$url}\n{$len}\n{$type}\n";
$wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->postmeta}` ( `post_id` , `meta_key` , `meta_value` )\n\t\t\t\t\tVALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value));
}
}
}
}
}
开发者ID:joelglennwright,项目名称:agencypress,代码行数:54,代码来源:functions.php
示例2: do_enclose
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @package WordPress
* @since 1.5.0
*
* @uses $wpdb
*
* @param string $content Post Content
* @param int $post_ID Post ID
*/
function do_enclose($content, $post_ID)
{
global $wpdb;
include_once ABSPATH . WPINC . '/class-IXR.php';
$log = debug_fopen(ABSPATH . 'enclosures.log', 'a');
$post_links = array();
debug_fwrite($log, 'BEGIN ' . date('YmdHis', time()) . "\n");
$pung = get_enclosed($post_ID);
$ltrs = '\\w';
$gunk = '/#~:.?+=&%@!\\-';
$punc = '.:?\\-';
$any = $ltrs . $gunk . $punc;
preg_match_all("{\\b http : [{$any}] +? (?= [{$punc}] * [^{$any}] | \$)}x", $content, $post_links_temp);
debug_fwrite($log, 'Post contents:');
debug_fwrite($log, $content . "\n");
foreach ($pung as $link_test) {
if (!in_array($link_test, $post_links_temp[0])) {
// link no longer in post
$mid = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%'));
do_action('delete_postmeta', $mid);
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN(%s)", implode(',', $mid)));
do_action('deleted_postmeta', $mid);
}
}
foreach ((array) $post_links_temp[0] as $link_test) {
if (!in_array($link_test, $pung)) {
// If we haven't pung it already
$test = @parse_url($link_test);
if (false === $test) {
continue;
}
if (isset($test['query'])) {
$post_links[] = $link_test;
} elseif ($test['path'] != '/' && $test['path'] != '') {
$post_links[] = $link_test;
}
}
}
foreach ((array) $post_links as $url) {
if ($url != '' && !$wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%'))) {
if ($headers = wp_get_http_headers($url)) {
$len = (int) $headers['content-length'];
$type = $headers['content-type'];
$allowed_types = array('video', 'audio');
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url($url);
if (false !== $url_parts) {
$extension = pathinfo($url_parts['path'], PATHINFO_EXTENSION);
if (!empty($extension)) {
foreach (get_allowed_mime_types() as $exts => $mime) {
if (preg_match('!^(' . $exts . ')$!i', $extension)) {
$type = $mime;
break;
}
}
}
}
if (in_array(substr($type, 0, strpos($type, "/")), $allowed_types)) {
$meta_value = "{$url}\n{$len}\n{$type}\n";
$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value));
do_action('added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value);
}
}
}
}
}
开发者ID:Ogwang,项目名称:sainp,代码行数:82,代码来源:functions.php
示例3: do_enclose
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose($content, $post_ID)
{
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once ABSPATH . WPINC . '/class-IXR.php';
$post_links = array();
$pung = get_enclosed($post_ID);
$post_links_temp = wp_extract_urls($content);
foreach ($pung as $link_test) {
if (!in_array($link_test, $post_links_temp)) {
// link no longer in post
$mids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like($link_test) . '%'));
foreach ($mids as $mid) {
delete_metadata_by_mid('post', $mid);
}
}
}
foreach ((array) $post_links_temp as $link_test) {
if (!in_array($link_test, $pung)) {
// If we haven't pung it already
$test = @parse_url($link_test);
if (false === $test) {
continue;
}
if (isset($test['query'])) {
$post_links[] = $link_test;
} elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
$post_links[] = $link_test;
}
}
}
foreach ((array) $post_links as $url) {
if ($url != '' && !$wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like($url) . '%'))) {
if ($headers = wp_get_http_headers($url)) {
$len = isset($headers['content-length']) ? (int) $headers['content-length'] : 0;
$type = isset($headers['content-type']) ? $headers['content-type'] : '';
$allowed_types = array('video', 'audio');
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url($url);
if (false !== $url_parts) {
$extension = pathinfo($url_parts['path'], PATHINFO_EXTENSION);
if (!empty($extension)) {
foreach (wp_get_mime_types() as $exts => $mime) {
if (preg_match('!^(' . $exts . ')$!i', $extension)) {
$type = $mime;
break;
}
}
}
}
if (in_array(substr($type, 0, strpos($type, "/")), $allowed_types)) {
add_post_meta($post_ID, 'enclosure', "{$url}\n{$len}\n{$mime}\n");
}
}
}
}
}
开发者ID:hpilevar,项目名称:WordPress,代码行数:72,代码来源:functions.php
示例4: podcasting_save_form
function podcasting_save_form($postID)
{
global $wpdb;
// Security prevention
if (!current_user_can('edit_post', $postID)) {
return $postID;
}
// Extra security prevention
if (isset($_POST['comment_post_ID'])) {
return $postID;
}
if (isset($_POST['not_spam'])) {
return $postID;
}
// akismet fix
if (isset($_POST['comment'])) {
return $postID;
}
// moderation.php fix
// Ignore save_post action for revisions and autosaves
if (function_exists('wp_is_post_revision') && function_exists('wp_is_post_autosave')) {
if (wp_is_post_revision($postID) || wp_is_post_autosave($postID)) {
return $postID;
}
}
// Add new enclosures
if ($_POST['pod_new_enclosure_ids'] != '') {
$pod_new_enclosure_ids = explode(',', substr($_POST['pod_new_enclosure_ids'], 0, -1));
$pod_ignore_enclosure_ids = explode(',', substr($_POST['pod_ignore_enclosure_ids'], 0, -1));
$added_enclosure_ids = array();
foreach ($pod_new_enclosure_ids as $pod_enclosure_id) {
$pod_enclosure_id = (int) $pod_enclosure_id;
// Check if the enclosure is on the ignore list
if (!in_array($pod_enclosure_id, $pod_ignore_enclosure_ids)) {
$pod_content = podcasting_urlencode($_POST['pod_new_file_' . $pod_enclosure_id]);
$pod_format = $_POST['pod_new_format_' . $pod_enclosure_id];
$enclosed = get_enclosed($postID);
do_enclose($pod_content, $postID);
// Add relationship if new enclosure
if (!in_array($pod_content, $enclosed)) {
$pod_enclosure_id2 = $wpdb->get_var("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id DESC");
// Find the enclosure we just added
wp_set_object_terms($pod_enclosure_id2, $pod_format, 'podcast_format', false);
}
$added_enclosure_ids[] = $pod_enclosure_id;
}
}
}
// Update enclosures
if (isset($_POST['pod_enclosure_ids'])) {
$pod_enclosure_ids = explode(',', $_POST['pod_enclosure_ids']);
$pod_new_enclosure_ids = explode(',', substr($_POST['pod_new_enclosure_ids'], 0, -1));
$pod_ignore_enclosure_ids = explode(',', substr($_POST['pod_ignore_enclosure_ids'], 0, -1));
$pod_delete_enclosure_ids = explode(',', substr($_POST['pod_delete_enclosure_ids'], 0, -1));
$enclosures = $wpdb->get_results("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id", ARRAY_A);
$i = 0;
if ($_POST['pod_enclosure_ids'] != '') {
foreach ($pod_enclosure_ids as $pod_enclosure_id) {
// Ensure we're dealing with an ID
$pod_enclosure_id = (int) $pod_enclosure_id;
$itunes = serialize(array('format' => $_POST['pod_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_author_' . $pod_enclosure_id], 'length' => $_POST['pod_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_explicit_' . $pod_enclosure_id]));
// Update format
wp_set_object_terms($pod_enclosure_id, $_POST['pod_format_' . $pod_enclosure_id], 'podcast_format', false);
// Update enclsoure
$enclosure = explode("\n", $enclosures[$i]['meta_value']);
$enclosure[3] = $itunes;
update_post_meta($postID, 'enclosure', implode("\n", $enclosure), $enclosures[$i]['meta_value']);
$i++;
// Delete enclosure
if (in_array($pod_enclosure_id, $pod_delete_enclosure_ids)) {
// Remove format
wp_delete_object_term_relationships($pod_enclosure_id, 'podcast_format');
// Remove enclosure
delete_meta($pod_enclosure_id);
}
}
}
if (count($added_enclosure_ids) > 0) {
foreach ($added_enclosure_ids as $pod_enclosure_id) {
// Ensure we're dealing with an ID
$pod_enclosure_id = (int) $pod_enclosure_id;
// Check if the enclosure is on the ignore list
if (!in_array($pod_enclosure_id, $pod_ignore_enclosure_ids)) {
$itunes = serialize(array('format' => $_POST['pod_new_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_new_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_new_author_' . $pod_enclosure_id], 'length' => $_POST['pod_new_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_new_explicit_' . $pod_enclosure_id]));
// Update format
$meta_id = $enclosures[$i]['meta_id'];
wp_set_object_terms($meta_id, $_POST['pod_new_format_' . $pod_enclosure_id], 'podcast_format', false);
// Update enclsoure
$enclosure = explode("\n", $enclosures[$i]['meta_value']);
$enclosure[3] = $itunes;
$enclosure_insert = implode("\n", $enclosure);
$wpdb->query("UPDATE {$wpdb->postmeta} SET meta_value = '{$enclosure_insert}' WHERE meta_id = '{$meta_id}'");
$i++;
}
}
}
}
return $postID;
}
开发者ID:alx,项目名称:barceloneta,代码行数:99,代码来源:podcasting.php
示例5: ap_insert_player_widgets
function ap_insert_player_widgets($content = '')
{
global $ap_behaviour, $ap_instances;
// Reset instance array
$ap_instances = array();
// Replace mp3 links
if (in_array("links", $ap_behaviour)) {
$content = preg_replace_callback("/<a ([^=]+=\"[^\"]+\" )*href=\"([^\"]+\\.mp3)\"( [^=]+=\"[^\"]+\")*>[^<]+<\\/a>/i", "ap_replace", $content);
}
// Replace [audio syntax]
if (in_array("default", $ap_behaviour)) {
$content = preg_replace_callback("/\\[audio:(([^]]+))]/i", "ap_replace", $content);
}
// Enclosure integration
if (in_array("enclosure", $ap_behaviour)) {
$enclosure = get_enclosed($post_id);
// Insert prefix and postfix clips if set
$prefixAudio = get_option("audio_player_prefixaudio");
if ($prefixAudio != "") {
$prefixAudio .= ",";
}
$postfixAudio = get_option("audio_player_postfixaudio");
if ($postfixAudio != "") {
$postfixAudio = "," . $postfixAudio;
}
if (count($enclosure) > 0) {
for ($i = 0; $i < count($enclosure); $i++) {
// Make sure the enclosure is an mp3 file and it hasn't been inserted into the post yet
if (preg_match("/.*\\.mp3\$/", $enclosure[$i]) == 1 && !in_array($enclosure[$i], $ap_instances)) {
$content .= "\n\n" . ap_getplayer($prefixAudio . $enclosure[$i] . $postfixAudio);
}
}
}
}
return $content;
}
开发者ID:cslauritsen,项目名称:qualereunion,代码行数:36,代码来源:audio-player.php
示例6: podcasting_save_form
function podcasting_save_form($postID)
{
global $wpdb;
// Security prevention
if (!current_user_can('edit_post', $postID)) {
return $postID;
}
// Extra security prevention
if (isset($_POST['comment_post_ID'])) {
return $postID;
}
if (isset($_POST['not_spam'])) {
return $postID;
}
// akismet fix
if (isset($_POST['comment'])) {
return $postID;
}
// moderation.php fix
// Update enclosures
$enclosure_ids = explode(',', $_POST['enclosure_ids']);
$enclosures = get_post_meta($postID, 'enclosure');
$i = 0;
foreach ($enclosure_ids as $enclosure_id) {
// Ensure we're dealing with an ID
$enclosure_id = (int) $enclosure_id;
$itunes = serialize(array('format' => $_POST['pod_format_' . $enclosure_id], 'keywords' => $_POST['pod_keywords_' . $enclosure_id], 'author' => $_POST['pod_author_' . $enclosure_id], 'length' => $_POST['pod_length_' . $enclosure_id], 'explicit' => $_POST['pod_explicit_' . $enclosure_id]));
// Update format
wp_set_object_terms($enclosure_id, $_POST['pod_format_' . $enclosure_id], 'podcast_format', false);
// Update enclsoure
$enclosure = explode("\n", $enclosures[$i]);
$enclosure[3] = $itunes;
update_post_meta($postID, 'enclosure', implode("\n", $enclosure), $enclosures[$i]);
$i++;
// Delete enclosure
if (isset($_POST['delete_pod_' . $enclosure_id])) {
// Remove format
wp_delete_object_term_relationships($enclosure_id, 'podcast_format');
// Remove enclosure
delete_meta($enclosure_id);
// Fake a save
$_POST['save'] = 'Update';
}
}
// Add new enclosures
if (isset($_POST['pod_new_file']) && '' != $_POST['pod_new_file']) {
$content = $_POST['pod_new_file'];
$enclosed = get_enclosed($postID);
do_enclose($content, $postID);
// Add relationship if new enclosure
if (!in_array($content, $enclosed)) {
$enclosure_id = $wpdb->get_var("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id DESC");
// Find the enclosure we just added
wp_set_object_terms($enclosure_id, 'default-format', 'podcast_format', false);
}
}
return $postID;
}
开发者ID:AkimBolushbek,项目名称:wordpress-soc-2007,代码行数:58,代码来源:podcasting.php
示例7: do_enclose
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @package WordPress
* @since 1.5.0
*
* @uses $wpdb
*
* @param string $content Post Content
* @param int $post_ID Post ID
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
$post_links = array();
debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" );
$pung = get_enclosed( $post_ID );
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = $ltrs . $gunk . $punc;
preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
debug_fwrite( $log, 'Post contents:' );
debug_fwrite( $log, $content . "\n" );
foreach ( $pung as $link_test ) {
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
$mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
do_action( 'delete_postmeta', $mid );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id IN(%s)", implode( ',', $mid ) ) );
do_action( 'deleted_postmeta', $mid );
}
}
foreach ( (array) $post_links_temp[0] as $link_test ) {
if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
$test = parse_url( $link_test );
if ( isset( $test['query'] ) )
$post_links[] = $link_test;
elseif ( $test['path'] != '/' && $test['path'] != '' )
$post_links[] = $link_test;
}
}
foreach ( (array) $post_links as $url ) {
if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = (int) $headers['content-length'];
$type = $headers['content-type'];
$allowed_types = array( 'video', 'audio' );
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
$meta_value = "$url\n$len\n$type\n";
$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
}
}
}
}
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:69,代码来源:functions.php
示例8: do_enclose
function do_enclose( $content, $post_ID ) {
global $wp_version, $wpdb;
include_once (ABSPATH . WPINC . '/class-IXR.php');
$log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
$post_links = array();
debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
$pung = get_enclosed( $post_ID );
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = $ltrs . $gunk . $punc;
preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
debug_fwrite($log, 'Post contents:');
debug_fwrite($log, $content."\n");
foreach($post_links_temp[0] as $link_test) :
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
$test = parse_url($link_test);
if ( isset($test['query']) )
$post_links[] = $link_test;
elseif (($test['path'] != '/') && ($test['path'] != ''))
$post_links[] = $link_test;
endif;
endforeach;
foreach ($post_links as $url) :
if ( $url != '' && !$wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE post_id = '$post_ID' AND meta_key = 'enclosure' AND meta_value LIKE ('$url%')") ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = (int) $headers['content-length'];
$type = $wpdb->escape( $headers['content-type'] );
$allowed_types = array( 'video', 'audio' );
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
$meta_value = "$url\n$len\n$type\n";
$wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
}
}
}
endforeach;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:45,代码来源:functions.php
示例9: do_enclose
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @package WordPress
* @since 1.5.0
*
* @uses $wpdb
*
* @param string $content Post Content
* @param int $post_ID Post ID
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$post_links = array();
$pung = get_enclosed( $post_ID );
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = $ltrs . $gunk . $punc;
preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
foreach ( $pung as $link_test ) {
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
$mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
foreach ( $mids as $mid )
delete_metadata_by_mid( 'post', $mid );
}
}
foreach ( (array) $post_links_temp[0] as $link_test ) {
if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
$test = @parse_url( $link_test );
if ( false === $test )
continue;
if ( isset( $test['query'] ) )
$post_links[] = $link_test;
elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) )
$post_links[] = $link_test;
}
}
foreach ( (array) $post_links as $url ) {
if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
if ( !empty( $extension ) ) {
foreach ( get_allowed_mime_types( ) as $exts => $mime ) {
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
$type = $mime;
break;
}
}
}
}
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
}
}
}
}
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:82,代码来源:functions.php
示例10: processContent
/**
* Filter function (inserts player instances according to behaviour option)
* @return the parsed and formatted content
* @param $content String[optional] the content to parse
*/
function processContent($content = '')
{
global $comment;
$this->loadLanguageFile();
// Reset instance array (this is so we don't insert duplicate players)
$this->instances = array();
// Replace mp3 links (don't do this in feeds and excerpts)
if (!is_feed() && !$this->inExcerpt && in_array("links", $this->options["behaviour"])) {
$pattern = "/<a ([^=]+=['\"][^\"']+['\"] )*href=['\"](([^\"']+\\.mp3))['\"]( [^=]+=['\"][^\"']+['\"])*>([^<]+)<\\/a>/i";
$content = preg_replace_callback($pattern, array(&$this, "insertPlayer"), $content);
}
// Replace [audio syntax]
if (in_array("default", $this->options["behaviour"])) {
$pattern = "/(<p>)?\\[audio:(([^]]+))\\](<\\/p>)?/i";
$content = preg_replace_callback($pattern, array(&$this, "insertPlayer"), $content);
}
// Enclosure integration (don't do this for feeds, excerpts and comments)
if (!is_feed() && !$this->inExcerpt && !$comment && in_array("enclosure", $this->options["behaviour"])) {
$enclosure = get_enclosed($post_id);
// Insert intro and outro clips if set
$introClip = $this->options["introClip"];
if ($introClip != "") {
$introClip .= ",";
}
$outroClip = $this->options["outroClip"];
if ($outroClip != "") {
$outroClip = "," . $outroClip;
}
if (count($enclosure) > 0) {
for ($i = 0; $i < count($enclosure); $i++) {
// Make sure the enclosure is an mp3 file and it hasn't been inserted into the post yet
if (preg_match("/.*\\.mp3\$/", $enclosure[$i]) == 1 && !in_array($enclosure[$i], $this->instances)) {
if ($this->options["enclosuresAtTop"]) {
$content = $this->getPlayer($introClip . $enclosure[$i] . $outroClip, null, $enclosure[$i]) . "\n\n" . $content;
} else {
$content .= "\n\n" . $this->getPlayer($introClip . $enclosure[$i] . $outroClip, null, $enclosure[$i]);
}
}
}
}
}
return $content;
}
开发者ID:maduhu,项目名称:opengovplatform-alpha,代码行数:48,代码来源:audio-player.php
示例11: saveForm
/**
* Saves information about enclosures
*/
function saveForm($postID)
{
global $wpdb;
// Security prevention
if (!current_user_can('edit_post', $postID)) {
return $postID;
}
// Extra security prevention
if (isset($_POST['comment_post_ID'])) {
return $postID;
}
if (isset($_POST['not_spam'])) {
return $postID;
}
// akismet fix
if (isset($_POST['comment'])) {
return $postID;
}
// moderation.php fix
// Ignore save_post action for revisions and autosave
if (wp_is_post_revision($postID) || wp_is_post_autosave($postID)) {
return $postID;
}
// Add new enclosures
if ($_POST['pod_new_enclosure_ids'] != '') {
$pod_new_enclosure_ids = explode(',', substr($_POST['pod_new_enclosure_ids'], 0, -1));
$pod_ignore_enclosure_ids = explode(',', substr($_POST['pod_ignore_enclosure_ids'], 0, -1));
$added_enclosure_ids = array();
foreach ($pod_new_enclosure_ids as $pod_enclosure_id) {
$pod_enclosure_id = (int) $pod_enclosure_id;
// Check if the enclosure is on the ignore list
if (!in_array($pod_enclosure_id, $pod_ignore_enclosure_ids)) {
$pod_content = $this->prepareEnclosure($_POST['pod_new_file_' . $pod_enclosure_id]);
$pod_format = $_POST['pod_new_format_' . $pod_enclosure_id];
$enclosed = get_enclosed($postID);
// Enclose the file using a custom method
$headers = $this->getHttpHeaders($pod_content);
# Check if the headers processed the file correctly, if they didn't try to clean up the file
if ($headers['response'] != '200') {
$pod_content = podcasting_urlencode($pod_content);
$headers = $this->getHttpHeaders($pod_content);
}
$length = (int) $headers['content-length'];
$type = addslashes($headers['content-type']);
if ($headers['response'] != '404' && is_array($headers)) {
add_post_meta($postID, 'enclosure', "{$pod_content}\n{$length}\n{$type}\n");
// Add relationship if new enclosure
if (!in_array($pod_content, $enclosed)) {
$pod_enclosure_id2 = $wpdb->get_var("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id DESC");
// Find the enclosure we just added
wp_set_object_terms($pod_enclosure_id2, $pod_format, 'podcast_format', false);
}
$added_enclosure_ids[] = $pod_enclosure_id;
}
}
}
}
// Update enclosures
if (isset($_POST['pod_enclosure_ids'])) {
$pod_enclosure_ids = explode(',', $_POST['pod_enclosure_ids']);
$pod_new_enclosure_ids = explode(',', substr($_POST['pod_new_enclosure_ids'], 0, -1));
$pod_ignore_enclosure_ids = explode(',', substr($_POST['pod_ignore_enclosure_ids'], 0, -1));
$pod_delete_enclosure_ids = explode(',', substr($_POST['pod_delete_enclosure_ids'], 0, -1));
$enclosures = $wpdb->get_results("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id", ARRAY_A);
$i = 0;
if ($_POST['pod_enclosure_ids'] != '') {
foreach ($pod_enclosure_ids as $pod_enclosure_id) {
// Ensure we're dealing with an ID
$pod_enclosure_id = (int) $pod_enclosure_id;
$itunes = serialize(array('format' => $_POST['pod_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_author_' . $pod_enclosure_id], 'length' => $_POST['pod_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_explicit_' . $pod_enclosure_id]));
// Update format
wp_set_object_terms($pod_enclosure_id, $_POST['pod_format_' . $pod_enclosure_id], 'podcast_format', false);
// Update enclsoure
$enclosure = explode("\n", $enclosures[$i]['meta_value']);
$enclosure[3] = $itunes;
// Check that we have the full enclosure before updating it
if (is_array($enclosures)) {
update_post_meta($postID, 'enclosure', implode("\n", $enclosure), $enclosures[$i]['meta_value']);
}
$i++;
// Delete enclosure
if (in_array($pod_enclosure_id, $pod_delete_enclosure_ids)) {
// Remove format
wp_delete_object_term_relationships($pod_enclosure_id, 'podcast_format');
// Remove enclosure
delete_meta($pod_enclosure_id);
}
}
}
if (count($added_enclosure_ids) > 0) {
foreach ($added_enclosure_ids as $pod_enclosure_id) {
// Ensure we're dealing with an ID
$pod_enclosure_id = (int) $pod_enclosure_id;
// Check if the enclosure is on the ignore list
if (!in_array($pod_enclosure_id, $pod_ignore_enclosure_ids)) {
$itunes = serialize(array('format' => $_POST['pod_new_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_new_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_new_author_' . $pod_enclosure_id], 'length' => $_POST['pod_new_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_new_explicit_' . $pod_enclosure_id]));
// Update format
//.........这里部分代码省略.........
开发者ID:howardlei82,项目名称:IGSM-Website,代码行数:101,代码来源:podcasting-metabox.php
示例12: do_enclose
function do_enclose( $content, $post_ID ) {
global $wp_version, $wpdb;
include_once (ABSPATH . WPINC . '/class-IXR.php');
$log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
$post_links = array();
debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
$pung = get_enclosed( $post_ID );
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = $ltrs . $gunk . $punc;
preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
debug_fwrite($log, 'Post contents:');
debug_fwrite($log, $content."\n");
foreach($post_links_temp[0] as $link_test) :
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
$test = parse_url($link_test);
if (isset($test['query']))
$post_links[] = $link_test;
elseif(($test['path'] != '/') && ($test['path'] != ''))
$post_links[] = $link_test;
endif;
endforeach;
foreach ($post_links as $url){
if( $url != '' && in_array($url, $pung) == false ) {
set_time_limit( 60 );
$file = str_replace( "http://", "", $url );
$host = substr( $file, 0, strpos( $file, "/" ) );
$file = substr( $file, strpos( $file, "/" ) );
$headers = "HEAD $file HTTP/1.1\r\nHOST: $host\r\n\r\n";
$port = 80;
$timeout = 3;
$fp = @fsockopen($host, $port, $err_num, $err_msg, $timeout);
if( $fp ) {
fputs($fp, $headers );
$response = '';
while ( !feof($fp) && strpos( $response, "\r\n\r\n" ) == false )
$response .= fgets($fp, 2048);
fclose( $fp );
} else {
$response = '';
}
if( $response != '' ) {
$len = substr( $response, strpos( $response, "Content-Length:" ) + 16 );
$len = substr( $len, 0, strpos( $len, "\n" ) );
$type = substr( $response, strpos( $response, "Content-Type:" ) + 14 );
$type = substr( $type, 0, strpos( $type, "\n" ) + 1 );
$allowed_types = array( 'video', 'audio' );
if( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
$meta_value = "$url\n$len\n$type\n";
$query = "INSERT INTO `".$wpdb->postmeta."` ( `meta_id` , `post_id` , `meta_key` , `meta_value` )
VALUES ( NULL, '$post_ID', 'enclosure' , '".$meta_value."')";
$wpdb->query( $query );
}
}
}
}
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:65,代码来源:functions.php
注:本文中的get_enclosed函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论