Jetpack_Media_Meta_Extractor::extract PHP Method

extract() public static method

NOTE: If you have the post's HTML content already and don't need image data, use extract_from_content() instead.
public static extract ( $blog_id, $post_id, $what_to_extract = self::ALL )
$blog_id The ID of the blog
$post_id The ID of the post
$what_to_extract (int) A mask of things to extract, e.g. Jetpack_Media_Meta_Extractor::IMAGES | Jetpack_Media_Meta_Extractor::MENTIONS
    public static function extract($blog_id, $post_id, $what_to_extract = self::ALL)
    {
        // multisite?
        if (function_exists('switch_to_blog')) {
            switch_to_blog($blog_id);
        }
        $post = get_post($post_id);
        $content = $post->post_title . "\n\n" . $post->post_content;
        $char_cnt = strlen($content);
        //prevent running extraction on really huge amounts of content
        if ($char_cnt > 100000) {
            //about 20k English words
            $content = substr($content, 0, 100000);
        }
        $extracted = array();
        // Get images first, we need the full post for that
        if (self::IMAGES & $what_to_extract) {
            $extracted = self::get_image_fields($post);
            // Turn off images so we can safely call extract_from_content() below
            $what_to_extract = $what_to_extract - self::IMAGES;
        }
        if (function_exists('switch_to_blog')) {
            restore_current_blog();
        }
        // All of the other things besides images can be extracted from just the content
        $extracted = self::extract_from_content($content, $what_to_extract, $extracted);
        return $extracted;
    }

Usage Example

コード例 #1
0
    /**
     * @author scotchfield
     * @covers Jetpack_Media_Meta_Extractor::extract
     * @since 3.2
     */
    public function test_mediaextractor_exclude_video_links()
    {
        $post_id = $this->factory->post->create(array('post_author' => '23314024', 'post_date' => '2013-10-25 16:43:34', 'post_date_gmt' => '2013-10-25 16:43:34', 'post_content' => 'Sed dapibus ut mauris imperdiet volutpat. http://vimeo.com/77120044/ Nullam in dolor vel nulla pulvinar accumsan facilisis quis lorem.
			', 'post_title' => 'Sed dapibus ut mauris imperdiet volutpat http vimeo...', 'post_excerpt' => '', 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'open', 'post_password' => '', 'post_name' => 'sed-dapibus-ut-mauris-imperdiet-volutpat-http-vimeo', 'to_ping' => '', 'pinged' => '
			http://vimeo.com/77120044/', 'post_modified' => '2013-10-28 22:54:50', 'post_modified_gmt' => '2013-10-28 22:54:50', 'post_content_filtered' => '', 'post_parent' => 0, 'guid' => 'http://breakmyblog.wordpress.com/2013/10/25/sed-dapibus-ut-mauris-imperdiet-volutpat-http-vimeo/', 'menu_order' => 0, 'post_type' => 'post', 'post_mime_type' => '', 'comment_count' => '0', 'filter' => 'raw'));
        $expected = array('has' => array('link' => 1), 'link' => array(array('url' => 'vimeo.com/77120044/', 'host_reversed' => 'com.vimeo', 'host' => 'vimeo.com')));
        $result = Jetpack_Media_Meta_Extractor::extract(get_current_blog_id(), $post_id, Jetpack_Media_Meta_Extractor::ALL);
        $this->assertEquals($expected, $result);
    }
All Usage Examples Of Jetpack_Media_Meta_Extractor::extract