当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_extract_urls函数代码示例

本文整理汇总了PHP中wp_extract_urls函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_extract_urls函数的具体用法?PHP wp_extract_urls怎么用?PHP wp_extract_urls使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_extract_urls函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate_links

 /**
  * Validate post links
  *
  * @since   0.1.0
  * @change  0.7.1
  *
  * @hook    array  spcl_acceptable_protocols
  *
  * @param   intval  $id  Post ID
  */
 public static function validate_links($id)
 {
     /* No PostID? */
     if (empty($id)) {
         return;
     }
     /* Get post data */
     $post = get_post($id);
     /* Post incomplete? */
     if (empty($post) or empty($post->post_content)) {
         return;
     }
     /* Extract urls */
     if (!($urls = wp_extract_urls($post->post_content))) {
         return;
     }
     /* Init */
     $found = array();
     /* Loop the urls */
     foreach ($urls as $url) {
         /* Acceptable protocols filter */
         $acceptable_protocols = (array) apply_filters('spcl_acceptable_protocols', array('http', 'https'));
         /* Scheme check */
         if (!in_array(parse_url($url, PHP_URL_SCHEME), $acceptable_protocols)) {
             continue;
         }
         /* Fragment check */
         if ($hash = parse_url($url, PHP_URL_FRAGMENT)) {
             $url = str_replace('#' . $hash, '', $url);
         }
         /* URL sanitization */
         $url = esc_url_raw($url, $acceptable_protocols);
         /* Skip URL */
         if (empty($url)) {
             continue;
         }
         /* Ping */
         $response = wp_safe_remote_head($url);
         /* Error? */
         if (is_wp_error($response)) {
             $found[] = array('url' => $url, 'error' => $response->get_error_message());
             /* Respronse code */
         } else {
             /* Status code */
             $code = (int) wp_remote_retrieve_response_code($response);
             /* Handle error codes */
             if ($code >= 400 && $code != 405) {
                 $found[] = array('url' => $url, 'error' => sprintf('Status Code %d', $code));
             }
         }
     }
     /* No items? */
     if (empty($found)) {
         return;
     }
     /* Cache the result */
     set_transient(self::_transient_hash(), $found, 60 * 30);
 }
开发者ID:pluginkollektiv,项目名称:spcl,代码行数:68,代码来源:spcl.class.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.
 *
 * @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

示例3: pingback

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 *
 * @global string $wp_version
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filter the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}
开发者ID:hadywisam,项目名称:WordPress,代码行数:83,代码来源:comment-functions.php

示例4: test_wp_extract_urls

    /**
     * @ticket 9064
     */
    function test_wp_extract_urls()
    {
        $original_urls = array('http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html', 'http://this.com', 'http://127.0.0.1', 'http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&2134362574863.437', 'http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html', 'http://wordpress-core.com:8080/', 'http://www.website.com:5000', 'http://wordpress-core/?346236346326&2134362574863.437', 'http://افغانستا.icom.museum', 'http://الجزائر.icom.museum', 'http://österreich.icom.museum', 'http://বাংলাদেশ.icom.museum', 'http://беларусь.icom.museum', 'http://belgië.icom.museum', 'http://българия.icom.museum', 'http://تشادر.icom.museum', 'http://中国.icom.museum', 'http://českárepublika.icom.museum', 'http://ελλάδα.icom.museum', 'http://magyarország.icom.museum', 'http://ísland.icom.museum', 'http://भारत.icom.museum', 'http://ايران.icom.museum', 'http://éire.icom.museum', 'http://איקו״ם.ישראל.museum', 'http://日本.icom.museum', 'http://الأردن.icom.museum', 'http://қазақстан.icom.museum', 'http://한국.icom.museum', 'http://кыргызстан.icom.museum', 'http://ລາວ.icom.museum', 'http://لبنان.icom.museum', 'http://македонија.icom.museum', 'http://méxico.icom.museum', 'http://монголулс.icom.museum', 'http://नेपाल.icom.museum', 'http://قطر.icom.museum', 'http://românia.icom.museum', 'http://россия.иком.museum', 'http://србијаицрнагора.иком.museum', 'http://இலங்கை.icom.museum', 'http://españa.icom.museum', 'http://ไทย.icom.museum', 'http://تونس.icom.museum', 'http://türkiye.icom.museum', 'http://украина.icom.museum', 'http://việtnam.icom.museum', 'ftp://127.0.0.1/', 'http://www.woo.com/video?v=exvUH2qKLTU', 'http://taco.com?burrito=enchilada#guac');
        $blob = "\n\t\t\thttp://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html\n\n\t\t\thttp://this.com\n\n\t\t\thttp://127.0.0.1\n\n\t\t\thttp://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437\n\n\t\t\thttp://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html\n\n\t\t\thttp://wordpress-core.com:8080/\n\n\t\t\thttp://www.website.com:5000\n\n\t\t\thttp://wordpress-core/?346236346326&amp;2134362574863.437\n\n\t\t\thttp://افغانستا.icom.museum\n\t\t\thttp://الجزائر.icom.museum\n\t\t\thttp://österreich.icom.museum\n\t\t\thttp://বাংলাদেশ.icom.museum\n\t\t\thttp://беларусь.icom.museum\n\t\t\thttp://belgië.icom.museum\n\t\t\thttp://българия.icom.museum\n\t\t\thttp://تشادر.icom.museum\n\t\t\thttp://中国.icom.museum\n\t\t\thttp://českárepublika.icom.museum\n\t\t\thttp://ελλάδα.icom.museum\n\t\t\thttp://magyarország.icom.museum\n\t\t\thttp://ísland.icom.museum\n\t\t\thttp://भारत.icom.museum\n\t\t\thttp://ايران.icom.museum\n\t\t\thttp://éire.icom.museum\n\t\t\thttp://איקו״ם.ישראל.museum\n\t\t\thttp://日本.icom.museum\n\t\t\thttp://الأردن.icom.museum\n\t\t\thttp://қазақстан.icom.museum\n\t\t\thttp://한국.icom.museum\n\t\t\thttp://кыргызстан.icom.museum\n\t\t\thttp://ລາວ.icom.museum\n\t\t\thttp://لبنان.icom.museum\n\t\t\thttp://македонија.icom.museum\n\t\t\thttp://méxico.icom.museum\n\t\t\thttp://монголулс.icom.museum\n\t\t\thttp://नेपाल.icom.museum\n\t\t\thttp://قطر.icom.museum\n\t\t\thttp://românia.icom.museum\n\t\t\thttp://россия.иком.museum\n\t\t\thttp://србијаицрнагора.иком.museum\n\t\t\thttp://இலங்கை.icom.museum\n\t\t\thttp://españa.icom.museum\n\t\t\thttp://ไทย.icom.museum\n\t\t\thttp://تونس.icom.museum\n\t\t\thttp://türkiye.icom.museum\n\t\t\thttp://украина.icom.museum\n\t\t\thttp://việtnam.icom.museum\n\t\t\tftp://127.0.0.1/\n\t\t\thttp://www.woo.com/video?v=exvUH2qKLTU\n\n\t\t\thttp://taco.com?burrito=enchilada#guac\n\t\t";
        $urls = wp_extract_urls($blob);
        $this->assertNotEmpty($urls);
        $this->assertInternalType('array', $urls);
        $this->assertCount(count($original_urls), $urls);
        $this->assertEquals($original_urls, $urls);
        $exploded = array_values(array_filter(array_map('trim', explode("\n", $blob))));
        // wp_extract_urls calls html_entity_decode
        $decoded = array_map('html_entity_decode', $exploded);
        $this->assertEquals($decoded, $urls);
        $this->assertEquals($original_urls, $decoded);
        $blob = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor\n\t\t\tincididunt ut labore http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html et dolore magna aliqua.\n\t\t\tUt http://this.com enim ad minim veniam, quis nostrud exercitation 16.06. to 18.06.2014 ullamco http://127.0.0.1\n\t\t\tlaboris nisi ut aliquip ex http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437 ea\n\t\t\tcommodo consequat. http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html Duis aute irure dolor in reprehenderit in voluptate\n\t\t\tvelit esse http://wordpress-core.com:8080/ cillum dolore eu fugiat nulla <A href=\"http://www.website.com:5000\">http://www.website.com:5000</B> pariatur. Excepteur sint occaecat cupidatat non proident,\n\t\t\tsunt in culpa qui officia deserunt mollit http://wordpress-core/?346236346326&amp;2134362574863.437 anim id est laborum.";
        $urls = wp_extract_urls($blob);
        $this->assertNotEmpty($urls);
        $this->assertInternalType('array', $urls);
        $this->assertCount(8, $urls);
        $this->assertEquals(array_slice($original_urls, 0, 8), $urls);
        $blob = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
			incididunt ut labore <a href="http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html">343462^</a> et dolore magna aliqua.
			Ut <a href="http://this.com">&amp;3640i6p1yi499</a> enim ad minim veniam, quis nostrud exercitation 16.06. to 18.06.2014 ullamco <a href="http://127.0.0.1">localhost</a>
			laboris nisi ut aliquip ex <a href="http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437">343462^</a> ea
			commodo consequat. <a href="http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html">343462^</a> Duis aute irure dolor in reprehenderit in voluptate
			velit esse <a href="http://wordpress-core.com:8080/">-3-4--321-64-4@#!$^$!@^@^</a> cillum dolore eu <A href="http://www.website.com:5000">http://www.website.com:5000</B> fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
			sunt in culpa qui officia deserunt mollit <a href="http://wordpress-core/?346236346326&amp;2134362574863.437">)(*&^%$</a> anim id est laborum.';
        $urls = wp_extract_urls($blob);
        $this->assertNotEmpty($urls);
        $this->assertInternalType('array', $urls);
        $this->assertCount(8, $urls);
        $this->assertEquals(array_slice($original_urls, 0, 8), $urls);
    }
开发者ID:jaspermdegroot,项目名称:develop.wordpress,代码行数:36,代码来源:functions.php

示例5: wp_extract_urls

<?php

/**
 * @package Sennza Version 3
 */
$links = wp_extract_urls(get_the_content());
?>
<article id="post-<?php 
the_ID();
?>
" <?php 
post_class();
?>
>
	<div class="row">
		<header class="entry-header columns large-8 large-centered">
			<h1 class="entry-title"><a href="<?php 
echo esc_url($links[0]);
?>
" title="<?php 
the_title();
?>
"><?php 
the_title();
?>
</a><span class="genericon genericon-link"></span></h1>

			<div class="entry-meta">
				<?php 
sz_posted_on();
?>
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:31,代码来源:content-link.php

示例6: extract_videos_from_text

 public function extract_videos_from_text($text)
 {
     $hosts = array();
     foreach ($this->hosts as $new_hosts) {
         $hosts = array_merge($hosts, $new_hosts);
     }
     $videos = array();
     $urls = wp_extract_urls($text);
     foreach ($urls as $url) {
         // Get URL Key
         $url_key = md5($url);
         $url_parsed = parse_url($url);
         // No valid host
         if (!isset($url_parsed['host'])) {
             continue;
         }
         // Test host
         if (in_array($url_parsed['host'], $hosts)) {
             $videos[$url_key] = array('url' => $url);
         }
     }
     return $videos;
 }
开发者ID:WordPressUtilities,项目名称:wpusavevideos,代码行数:23,代码来源:wpusavevideos.php

示例7: get_video

 /**
  * Get post embed
  *
  * @since  1.0.0
  * @return string
  */
 public function get_video($args = array(), $id = 0)
 {
     $object = $this->get_post_object($id);
     if (empty($object->ID)) {
         return '';
     }
     $default_args = array('visible' => true, 'size' => apply_filters('cherry_normal_video_size', 'post-thumbnail'), 'mobile_size' => apply_filters('cherry_mobile_video_size', 'post-thumbnail'), 'class' => 'wp-video', 'echo' => false);
     $args = wp_parse_args($args, $default_args);
     $html = '';
     if (!filter_var($args['visible'], FILTER_VALIDATE_BOOLEAN)) {
         return '';
     }
     $size = wp_is_mobile() ? $args['mobile_size'] : $args['size'];
     $size_array = $this->get_thumbnail_size_array($size);
     $url_array = wp_extract_urls($object->post_content);
     if (empty($url_array) || !$url_array) {
         return '';
     }
     $html = wp_oembed_get($url_array[0], array('width' => $size_array['width']));
     if (!$html) {
         $url_array = $this->sorted_array($url_array);
         if (empty($url_array['video'])) {
             return '';
         }
         if (empty($url_array['poster'])) {
             $post_thumbnail_id = get_post_thumbnail_id($object->ID);
             $url_array['poster'] = wp_get_attachment_image_url($post_thumbnail_id, $size);
         }
         $shortcode_attr = array('width' => '100%', 'height' => '100%', 'poster' => $url_array['poster']);
         $shortcode_attr = wp_parse_args($url_array['video'], $shortcode_attr);
         $html = wp_video_shortcode($shortcode_attr);
     }
     return $this->output_method($html, $args['echo']);
 }
开发者ID:CherryFramework,项目名称:cherry-framework,代码行数:40,代码来源:cherry-media-utilit.php

示例8: edd_sl_24_upgrade_site_urls

/**
 * Upgrades old license keys with the new site URL store
 *
 * @since 2.4
 * @return void
 */
function edd_sl_24_upgrade_site_urls()
{
    $edd_sl_version = get_option('edd_sl_version');
    if (version_compare($edd_sl_version, '2.4', '>=')) {
        return;
    }
    ignore_user_abort(true);
    if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
    $offset = $step == 1 ? 0 : $step * 100;
    $args = array('post_type' => 'edd_license_log', 'posts_per_page' => 100, 'offset' => $offset);
    $logs = get_posts($args);
    if ($logs) {
        foreach ($logs as $log) {
            $license_id = get_post_meta($log->ID, '_edd_sl_log_license_id', true);
            $urls = wp_extract_urls($log->post_content);
            $urls = edd_sl_sanitize_urls($urls);
            if (strpos($log->post_title, 'License Activated')) {
                foreach ($urls as $url) {
                    edd_software_licensing()->insert_site($license_id, $url);
                }
            } else {
                foreach ($urls as $url) {
                    edd_software_licensing()->delete_site($license_id, $url);
                }
            }
        }
        // Keys found so upgrade them
        $step++;
        $redirect = add_query_arg(array('page' => 'edd-sl-upgrades', 'edd_upgrade' => 'upgrade_site_urls', 'step' => $step), admin_url('index.php'));
        wp_safe_redirect($redirect);
        exit;
    } else {
        // No more keys found, update the DB version and finish up
        update_option('edd_sl_version', EDD_SL_VERSION);
        wp_redirect(admin_url());
        exit;
    }
}
开发者ID:SelaInc,项目名称:eassignment,代码行数:47,代码来源:upgrades.php

示例9: get_video

 /**
  * Get post embed
  *
  * @since  1.0.0
  * @return string
  */
 public function get_video($args = array(), $ID = 0)
 {
     $object = $this->get_post_object($ID);
     if (empty($object->ID)) {
         return false;
     }
     $default_args = array('size' => apply_filters('cherry_normal_video_size', 'post-thumbnail'), 'mobile_size' => apply_filters('cherry_mobile_video_size', 'post-thumbnail'), 'class' => 'wp-video');
     $args = array_merge($default_args, $args);
     $size = wp_is_mobile() ? $args['mobile_size'] : $args['size'];
     $size_array = $this->get_thumbnail_size_array($size);
     $video_url = wp_extract_urls($object->post_content);
     if (empty($video_url) || !$video_url) {
         return;
     }
     $video = wp_oembed_get($video_url[0], array('width' => $size_array['width']));
     if (!$video) {
         $post_thumbnail_id = get_post_thumbnail_id($object->ID);
         $poster = wp_get_attachment_image_url($post_thumbnail_id, $size);
         $video = wp_video_shortcode(array('src' => $video_url[0], 'width' => '100%', 'height' => '100%', 'poster' => $poster));
     }
     return $video;
 }
开发者ID:vfedushchin,项目名称:KingNews,代码行数:28,代码来源:cherry-media-utilit.php


注:本文中的wp_extract_urls函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。