Ejemplo n.º 1
0
/**
 * 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));
                }
            }
        }
    }
}
Ejemplo n.º 2
0
/**
 * 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);
                }
            }
        }
    }
}
Ejemplo n.º 3
0
/**
 * 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");
                }
            }
        }
    }
}
Ejemplo n.º 4
0
function wpfc_get_filesize($url, $timeout = 10)
{
    $headers = wp_get_http_headers($url);
    $duration = isset($headers['content-length']) ? (int) $headers['content-length'] : 0;
    if ($duration) {
        sscanf($duration, "%d:%d:%d", $hours, $minutes, $seconds);
        $length = isset($seconds) ? $hours * 3600 + $minutes * 60 + $seconds : $hours * 60 + $minutes;
        if (!$length) {
            $length = (int) $duration;
        }
        return $length;
    }
    return 0;
}
 /**
  * Test to see if the deprecated argument is working
  */
 public function test_wp_get_http_headers_deprecated_argument()
 {
     $this->setExpectedDeprecated('wp_get_http_headers');
     wp_get_http_headers('does_not_matter', $deprecated = true);
 }
 function the_enclosure_rss($echo = true)
 {
     if (!empty($GLOBALS['post']->post_password)) {
         // if there's a password
         return _echo('', $echo);
     }
     $content = get_the_content($more_link_text, $stripteaser, $more_file);
     $content = apply_filters('the_content', $content);
     $content = wp_convert_rss_charset($content);
     $post_links = array();
     preg_match('#(http://[^/]*)#', XOOPS_URL, $my_host);
     $my_host = $my_host[0];
     preg_match_all("{href=([\"'])((http://|https://|/)[^\\1]*?)\\1}i", $content, $post_links_temp);
     foreach ($post_links_temp[2] as $link_test) {
         $link_test = wp_get_fullurl($link_test);
         $test = parse_url($link_test);
         if (isset($test['query'])) {
             $post_links[] = $link_test;
         } elseif ($test['path'] != '/' && $test['path'] != '') {
             $post_links[] = $link_test;
         }
     }
     $output = '';
     foreach ($post_links as $url) {
         if ($headers = wp_get_http_headers($url)) {
             $len = (int) $headers['content-length'];
             $type = addslashes($headers['content-type']);
             $allowed_types = array('video', 'audio');
             if (in_array(substr($type, 0, strpos($type, "/")), $allowed_types)) {
                 $output .= "<enclosure url='" . trim(htmlspecialchars($url)) . "' length='" . trim($len) . "' type='" . trim($type) . "'/>\n";
             }
         }
     }
     return _echo($output, $echo);
 }
/**
 * 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 );
				}
			}
		}
	}
}
/**
 * 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" );
				}
			}
		}
	}
}
function wp_get_http_headers( $url, $red = 1 ) {
	global $wp_version;
	@set_time_limit( 60 );

	if ( $red > 5 )
		 return false;

	$parts = parse_url( $url );
	$file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
	$host = $parts['host'];
	if ( !isset( $parts['port'] ) )
		$parts['port'] = 80;

	$head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";

	$fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
	if ( !$fp )
		return false;

	$response = '';
	fputs( $fp, $head );
	while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
		$response .= fgets( $fp, 2048 );
	fclose( $fp );
	preg_match_all('/(.*?): (.*)\r/', $response, $matches);
	$count = count($matches[1]);
	for ( $i = 0; $i < $count; $i++) {
		$key = strtolower($matches[1][$i]);
		$headers["$key"] = $matches[2][$i];
	}

	preg_match('/.*([0-9]{3}).*/', $response, $return);
	$headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404

		$code = $headers['response'];
		if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
				return wp_get_http_headers( $headers['location'], ++$red );

	return $headers;
}
Ejemplo n.º 10
0
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 = addslashes( $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;
}
function sp_UserAvatar($args = '', $contextData = '')
{
    global $spThisUser;
    $defs = array('tagClass' => 'spAvatar', 'imgClass' => 'spAvatar', 'size' => '', 'link' => 'profile', 'context' => 'current', 'wp' => '', 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_Avatar_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagClass = esc_attr($tagClass);
    $imgClass = esc_attr($imgClass);
    $link = esc_attr($link);
    $size = (int) $size;
    $echo = (int) $echo;
    $get = (int) $get;
    $wp = esc_attr($wp);
    # init some vars
    $forceWidth = false;
    # make sure we are displaying avatars
    $spAvatars = sp_get_option('sfavatars');
    if ($spAvatars['sfshowavatars'] == true) {
        $avatarData = new stdClass();
        $avatarData->object = false;
        $avatarData->userId = 0;
        # need user id OR email
        $avatarData->email = '';
        $avatarData->avatar = '';
        $avatarData->admin = '';
        # determine avatar size
        $avatarData->size = !empty($size) ? $size : $spAvatars['sfavatarsize'];
        # get the appropriate user id and email address
        switch ($context) {
            case 'current':
                # we want the avatar for the current user
                global $spThisUser;
                $avatarData->userId = $spThisUser->ID;
                $avatarData->email = !empty($avatarData->userId) ? $spThisUser->user_email : '';
                break;
            case 'user':
                # determine if we have user object, id or email address
                if (is_object($contextData)) {
                    # sp user object passed in
                    # can contain anything, but must contain id or email, avatar array and admin flag
                    $avatarData->object = true;
                    $avatarData->userId = $contextData->ID;
                    $avatarData->email = $contextData->user_email;
                    $avatarData->avatar = $contextData->avatar;
                    $avatarData->admin = $contextData->admin;
                } else {
                    if (is_numeric($contextData)) {
                        # user id passed in
                        $user = get_userdata((int) $contextData);
                    } else {
                        # email address passed in
                        $user = get_user_by('email', sp_esc_str($contextData));
                    }
                    if ($user) {
                        $avatarData->userId = $user->ID;
                        $avatarData->email = $user->user_email;
                    }
                }
                break;
            default:
                # allow themes/plugins to add new avatar user types
                $avatarData = apply_filters('sph_Avatar_' . $context, $avatarData, $a);
                break;
        }
        # loop through prorities until we find an avatar to use
        foreach ($spAvatars['sfavatarpriority'] as $priority) {
            switch ($priority) {
                case 0:
                    # Gravatars
                    if (function_exists('sp_get_gravatar_cache_url')) {
                        $avatarData->url = sp_get_gravatar_cache_url(strtolower($avatarData->email), $avatarData->size);
                        if (empty($avatarData->url)) {
                            $gravatar = false;
                        } else {
                            $gravatar = true;
                            $forceWidth = true;
                            # force width to request since we only cache one size
                        }
                    } else {
                        $rating = $spAvatars['sfgmaxrating'];
                        switch ($rating) {
                            case 1:
                                $grating = 'g';
                                break;
                            case 2:
                                $grating = 'pg';
                                break;
                            case 3:
                                $grating = 'r';
                                break;
                            case 4:
                            default:
                                $grating = 'x';
                                break;
                        }
                        $avatarData->url = 'http://www.gravatar.com/avatar/' . md5(strtolower($avatarData->email)) . "?d=404&size={$avatarData->size}&rating={$grating}";
                        # Is there an gravatar?
                        $headers = wp_get_http_headers($avatarData->url);
                        if (!is_array($headers)) {
                            $gravatar = false;
                        } elseif (isset($headers['content-disposition'])) {
                            $gravatar = true;
                        } else {
                            $gravatar = false;
                        }
                    }
                    # ignore gravatar blank images
                    if ($gravatar == true) {
                        break 2;
                        # if actual gravatar image found, show it
                    }
                    break;
                case 1:
                    # WP avatars
                    # if wp avatars being used, handle slightly different since we get image tags
                    $avatar = "<div class='{$tagClass}'>";
                    if (!empty($wp)) {
                        $avatar .= sp_build_avatar_display($avatarData->userId, $wp, $link);
                    } else {
                        if ($avatarData->userId) {
                            $avatarData->email = $avatarData->userId;
                        }
                        $avatar .= sp_build_avatar_display($avatarData->userId, get_avatar($avatarData->email, $avatarData->size), $link);
                    }
                    $avatar .= '</div>';
                    if ($get) {
                        return $avatarData;
                    }
                    # for wp avatars, we need to display/return and bail
                    if (empty($echo)) {
                        return $avatar;
                    } else {
                        echo $avatar . "\n";
                        return;
                    }
                case 2:
                    # Uploaded avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['uploaded'])) {
                        $avfile = $userAvatar['uploaded'];
                        $avatarData->url = SFAVATARURL . $avfile;
                        if (file_exists(SFAVATARDIR . $avfile)) {
                            $avatarData->path = SFAVATARDIR . $avfile;
                            break 2;
                            # if uploaded avatar exists, show it
                        }
                    }
                    break;
                case 3:
                    # SPF default avatars
                # SPF default avatars
                default:
                    if (empty($avatarData->userId)) {
                        $image = 'guestdefault.png';
                    } else {
                        if ($avatarData->object) {
                            $image = $avatarData->admin ? 'admindefault.png' : 'userdefault.png';
                        } else {
                            $image = sp_is_forum_admin($avatarData->userId) ? 'admindefault.png' : 'userdefault.png';
                        }
                    }
                    $avatarData->url = SFAVATARURL . $image;
                    $avatarData->path = SFAVATARDIR . $image;
                    break 2;
                    # defaults, so show it
                # defaults, so show it
                case 4:
                    # Pool avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['pool'])) {
                        $pavfile = $userAvatar['pool'];
                        $avatarData->url = SFAVATARPOOLURL . $pavfile;
                        if (file_exists(SFAVATARPOOLDIR . $pavfile)) {
                            $avatarData->path = SFAVATARPOOLDIR . $pavfile;
                            break 2;
                            # if pool avatar exists, show it
                        }
                    }
                    break;
                case 5:
                    # Remote avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['remote'])) {
                        $ravfile = $userAvatar['remote'];
                        $avatarData->url = $ravfile;
                        # see if file exists
                        $response = wp_remote_get($avatarData->url);
                        if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) {
                            $avatarData->path = $avatarData->url;
                            break 2;
                            # if remote avatar exists, show it
                        }
                    }
                    break;
            }
        }
        # allow themes/plugins to filter the final avatar data
        $avatarData = apply_filters('sph_Avatar', $avatarData, $a);
        if ($get) {
            return $avatarData;
        }
        # now display the avatar
        $width = $forceWidth ? " width='{$avatarData->size}'" : "";
        $maxwidth = $avatarData->size > 0 ? " style='max-width: {$avatarData->size}px'" : '';
        $avatar = sp_build_avatar_display($avatarData->userId, "<img src='" . esc_url($avatarData->url) . "' class='{$imgClass}'{$width}{$maxwidth} alt='' />", $link);
        $avatar = "<div class='{$tagClass}'>{$avatar}</div>\n";
        if ($echo) {
            echo $avatar;
        } else {
            return $avatar;
        }
    }
}
Ejemplo n.º 12
0
function flv_add_meta($post_id) {
	global $wpdb, $flv_options, $flv_sitemap_options, $flv_metakey, $flv_metavalues;

	// jump out of function if sitemap feature is not enabled
	if (!$flv_options['sitemap']) {
		return $post_id;
	}

	$content = $wpdb->get_var("SELECT post_content
							FROM $wpdb->posts
							WHERE ID = '$post_id'");

	// parse post content for FLV embed tags
	$content = preg_replace_callback( "/\[flv:(([^]]+))]/i", "flv_gen_meta", $content );

	// process each metavalues
	foreach ($flv_metavalues as $metavalue) {
		// read flv custom fields from database for current post_id
		$flvs = $wpdb->get_results("SELECT meta_value, meta_id
								FROM $wpdb->postmeta
								WHERE post_id = '$post_id'
								AND meta_key = '$flv_metakey'");

		// status flag for database operations
		$update = 0;
		$delete = 0;
		$write = 1;

		// if flv custom field already exist, test its content and update the value with new flv path when applicable
		if (!empty($flvs)) {
			$del_metaids = array();		// array that stores flv to be deleted
			
			$input = explode("\n", $metavalue);
			$movie = $input[0];
			
			$file = basename($movie);
			
			// check to see if existing flv custom field can be updated
			foreach ($flvs as $flv) {
				if (stristr($flv->meta_value, $file)) {
					$metaid = $flv->meta_id;
					$update = 1;
				// check to see if existing meta is valid (i.e. flv url is not a dead link)
				} else  {
					$input_meta = explode("\n", $flv->meta_value);
					$url = $input_meta[0];
					
					$headers = wp_get_http_headers($url);
					$code = (int) $headers['response'];
					
					// client error
					if ($code >= 400 && $code < 500) {
						$delete = 1;
						array_push($del_metaids, $flv->meta_id);
					}
				}
			}
		}
		
		// disable custom field writing for YouTube links
		if (stristr($metavalue,"youtube.com")) {
			$write = 0;
		}
		
		// update existing flv custom field
		if ($update) {
			$results=  $wpdb->query("UPDATE $wpdb->postmeta
								SET meta_value = '$metavalue'
								WHERE post_id = '$post_id'
								AND meta_id = '$metaid'
								AND meta_key = '$flv_metakey'");
								
		// or write flv custom field to database
		} else if ($write) {
			$results = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value)
									VALUES ('$post_id', '$flv_metakey', '$metavalue')");
		}
		
		// delete dead flv
		if ($delete) {
			foreach ($del_metaids as $del_metaid) {
				$results=  $wpdb->query("DELETE FROM $wpdb->postmeta
									WHERE post_id = '$post_id'
									AND meta_id = '$del_metaid'
									AND meta_key = '$flv_metakey'");				
			}
		}
	}
	
	// check if flv embed tags are found within current post
	if (!empty($metavalue)) {
		// rebuild video sitemap if allowed
		if ($flv_sitemap_options['allow_auto']) {
			// get post status...
			$post_status = $wpdb->get_var("SELECT post_status
						FROM $wpdb->posts
						WHERE ID = '$post_id'");
			// only rebuild if post is already published
			if ($post_status == 'publish')
				flv_sitemap_build();
		}
	}
	
	// clear the array
	$flv_metavalues = array();
	
	return $post_id;
}
Ejemplo n.º 13
0
 /**
  * Retrieves information about a given podcast through several different methods
  * @param - the URL of the file
  * @return an array containing file information
  */
 function getHttpHeaders($url)
 {
     # Don't attempt to get enclosure information since we're accepting failure
     if (get_option('pod_accept_fail') == 'yes') {
         $headers = array('response' => 200, 'content-length' => '1048576', 'content-type' => $this->getMimeType($url));
         return $headers;
     }
     $wp_head = wp_get_http_headers($url);
     $headers = array('response' => '200', 'content-length' => $wp_head['content-length'], 'content-type' => $this->getMimeType($url));
     # Try to get the headers locally if external URLs fail
     if ($headers['response'] == '' || $headers['response'] == '404') {
         $local_host = $_SERVER['SERVER_NAME'];
         $file_parse_url = parse_url($url);
         $file_host = $file_parse_url['host'];
         $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_parse_url['path'];
         # Double check we have a local file
         if ($local_host == $file_host) {
             if (file_exists($file_path)) {
                 $headers['response'] = '200';
                 $headers['content-type'] = mime_content_type($file_path);
                 $headers['content-length'] = filesize($file_path);
             } else {
                 $headers['response'] = '404';
             }
         }
     }
     return $headers;
 }
Ejemplo n.º 14
0
function powerpressadmin_podpress_do_import()
{
    $Import = !empty($_POST['Import']) ? $_POST['Import'] : array();
    $PodPressData = powerpress_get_podpress_episodes(true);
    while (list($post_id, $podpress_episode_feeds) = each($Import)) {
        while (list($podpress_index, $feed_slug) = each($podpress_episode_feeds)) {
            if ($feed_slug) {
                $EpisodeData = $PodPressData[$post_id]['podpress_data'][$podpress_index];
                if ($EpisodeData['size'] == '' || !is_numeric($EpisodeData['size'])) {
                    $headers = wp_get_http_headers($EpisodeData['url']);
                    if ($headers && $headers['content-length']) {
                        $EpisodeData['size'] = (int) $headers['content-length'];
                    }
                }
                $EnclosureData = trim($EpisodeData['url']) . "\n" . trim($EpisodeData['size']) . "\n" . trim($EpisodeData['type']);
                $Serialized = array();
                if (!empty($EpisodeData['duration'])) {
                    $Serialized['duration'] = $EpisodeData['duration'];
                }
                if (!empty($EpisodeData['image'])) {
                    $Serialized['image'] = $EpisodeData['image'];
                }
                if (count($Serialized) > 0) {
                    $EnclosureData .= "\n" . serialize($Serialized);
                }
                if ($feed_slug == 'podcast') {
                    add_post_meta($post_id, 'enclosure', $EnclosureData, true);
                } else {
                    add_post_meta($post_id, '_' . $feed_slug . ':enclosure', $EnclosureData, true);
                }
                powerpressadmin_podpress_import_log($PodPressData[$post_id]['post_title'], $EpisodeData['url'], $feed_slug);
            }
        }
    }
}