當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WPSEO_Utils::is_url_relative方法代碼示例

本文整理匯總了PHP中WPSEO_Utils::is_url_relative方法的典型用法代碼示例。如果您正苦於以下問題:PHP WPSEO_Utils::is_url_relative方法的具體用法?PHP WPSEO_Utils::is_url_relative怎麽用?PHP WPSEO_Utils::is_url_relative使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WPSEO_Utils的用法示例。


在下文中一共展示了WPSEO_Utils::is_url_relative方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add_image

 /**
  * Display an OpenGraph image tag
  *
  * @param string $img - Source URL to the image
  *
  * @return bool
  */
 private function add_image($img)
 {
     // Filter: 'wpseo_opengraph_image' - Allow changing the OpenGraph image */
     $img = trim(apply_filters('wpseo_opengraph_image', $img));
     if (empty($img)) {
         return false;
     }
     if (WPSEO_Utils::is_url_relative($img) === true) {
         $img = $this->get_relative_path($img);
     }
     if (in_array($img, $this->images)) {
         return false;
     }
     array_push($this->images, $img);
     return true;
 }
開發者ID:goodbayscott,項目名稱:wwr-temp,代碼行數:23,代碼來源:class-opengraph.php

示例2: wpseo_is_url_relative

/**
 * Check whether a url is relative
 *
 * @deprecated 1.6.1
 * @deprecated use WPSEO_Utils::is_url_relative()
 * @see WPSEO_Utils::is_url_relative()
 *
 * @param string $url
 *
 * @return bool
 */
function wpseo_is_url_relative($url)
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.6.1', 'WPSEO_Utils::is_url_relative()');
    return WPSEO_Utils::is_url_relative($url);
}
開發者ID:presteege,項目名稱:presteege.fr,代碼行數:16,代碼來源:wpseo-functions.php

示例3: get_anchor_count

 /**
  * Count the number of anchors and group them by type.
  *
  * @param object $xpath An XPATH object of the current document.
  *
  * @return array
  */
 function get_anchor_count(&$xpath)
 {
     $query = '//a|//A';
     $dom_objects = $xpath->query($query);
     $count = array('total' => 0, 'internal' => array('nofollow' => 0, 'dofollow' => 0), 'external' => array('nofollow' => 0, 'dofollow' => 0), 'other' => array('nofollow' => 0, 'dofollow' => 0));
     if (is_object($dom_objects) && is_a($dom_objects, 'DOMNodeList') && $dom_objects->length > 0) {
         foreach ($dom_objects as $dom_object) {
             $count['total']++;
             if ($dom_object->attributes->getNamedItem('href')) {
                 $href = $dom_object->attributes->getNamedItem('href')->textContent;
                 $wpurl = get_bloginfo('url');
                 if (WPSEO_Utils::is_url_relative($href) === true || substr($href, 0, strlen($wpurl)) === $wpurl) {
                     $type = 'internal';
                 } elseif (substr($href, 0, 4) == 'http') {
                     $type = 'external';
                 } else {
                     $type = 'other';
                 }
                 if ($dom_object->attributes->getNamedItem('rel')) {
                     $link_rel = $dom_object->attributes->getNamedItem('rel')->textContent;
                     if (stripos($link_rel, 'nofollow') !== false) {
                         $count[$type]['nofollow']++;
                     } else {
                         $count[$type]['dofollow']++;
                     }
                 } else {
                     $count[$type]['dofollow']++;
                 }
             }
         }
     }
     return $count;
 }
開發者ID:Nisha318,項目名稱:p3edtech,代碼行數:40,代碼來源:class-metabox.php

示例4: generate_canonical

 /**
  * This function normally outputs the canonical but is also used in other places to retrieve
  * the canonical URL for the current page.
  *
  * @return void
  */
 private function generate_canonical()
 {
     $canonical = false;
     $canonical_override = false;
     // Set decent canonicals for homepage, singulars and taxonomy pages
     if (is_singular()) {
         $obj = get_queried_object();
         $canonical = get_permalink($obj->ID);
         $this->canonical_unpaged = $canonical;
         $canonical_override = WPSEO_Meta::get_value('canonical');
         // Fix paginated pages canonical, but only if the page is truly paginated.
         if (get_query_var('page') > 1) {
             $num_pages = substr_count($obj->post_content, '<!--nextpage-->') + 1;
             if ($num_pages && get_query_var('page') <= $num_pages) {
                 if (!$GLOBALS['wp_rewrite']->using_permalinks()) {
                     $canonical = add_query_arg('page', get_query_var('page'), $canonical);
                 } else {
                     $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page'));
                 }
             }
         }
     } else {
         if (is_search()) {
             $canonical = get_search_link();
         } elseif (is_front_page()) {
             $canonical = home_url();
         } elseif ($this->is_posts_page()) {
             $canonical = get_permalink(get_option('page_for_posts'));
         } elseif (is_tax() || is_tag() || is_category()) {
             $term = get_queried_object();
             $canonical_override = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical');
             $canonical = get_term_link($term, $term->taxonomy);
         } elseif (is_post_type_archive()) {
             $post_type = get_query_var('post_type');
             if (is_array($post_type)) {
                 $post_type = reset($post_type);
             }
             $canonical = get_post_type_archive_link($post_type);
         } elseif (is_author()) {
             $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
         } elseif (is_archive()) {
             if (is_date()) {
                 if (is_day()) {
                     $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                 } elseif (is_month()) {
                     $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                 } elseif (is_year()) {
                     $canonical = get_year_link(get_query_var('year'));
                 }
             }
         }
         $this->canonical_unpaged = $canonical;
         if ($canonical && get_query_var('paged') > 1) {
             global $wp_rewrite;
             if (!$wp_rewrite->using_permalinks()) {
                 if (is_front_page()) {
                     $canonical = trailingslashit($canonical);
                 }
                 $canonical = add_query_arg('paged', get_query_var('paged'), $canonical);
             } else {
                 if (is_front_page()) {
                     $canonical = wpseo_xml_sitemaps_base_url('');
                 }
                 $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged'));
             }
         }
     }
     $this->canonical_no_override = $canonical;
     if (is_string($canonical) && $canonical !== '') {
         // Force canonical links to be absolute, relative is NOT an option.
         if (WPSEO_Utils::is_url_relative($canonical) === true) {
             $canonical = $this->base_url($canonical);
         }
     }
     /**
      * Filter: 'wpseo_canonical' - Allow filtering of the canonical URL put out by WP SEO
      *
      * @api string $canonical The canonical URL
      */
     $canonical = apply_filters('wpseo_canonical', $canonical);
     if (is_string($canonical_override) && $canonical_override !== '') {
         $this->canonical = $canonical_override;
     } else {
         $this->canonical = $canonical;
     }
 }
開發者ID:shellygraham,項目名稱:livestock-framing,代碼行數:92,代碼來源:class-frontend.php

示例5: build_post_type_map


//.........這裏部分代碼省略.........
                  * @api string $url URL to use in the XML sitemap
                  *
                  * @param object $p Post object for the URL
                  */
                 $url['loc'] = apply_filters('wpseo_xml_sitemap_post_url', $url['loc'], $p);
                 $url['chf'] = $this->filter_frequency($post_type . '_single', 'weekly', $url['loc']);
                 /**
                  * Do not include external URLs.
                  * @see https://wordpress.org/plugins/page-links-to/ can rewrite permalinks to external URLs.
                  */
                 if (false === strpos($url['loc'], $this->home_url)) {
                     continue;
                 }
                 $canonical = WPSEO_Meta::get_value('canonical', $p->ID);
                 if ($canonical !== '' && $canonical !== $url['loc']) {
                     /* Let's assume that if a canonical is set for this page and it's different from
                        the URL of this post, that page is either already in the XML sitemap OR is on
                        an external site, either way, we shouldn't include it here. */
                     continue;
                 } else {
                     if ($this->options['trailingslash'] === true && $p->post_type != 'post') {
                         $url['loc'] = trailingslashit($url['loc']);
                     }
                 }
                 unset($canonical);
                 $url['pri'] = $this->calculate_priority($p);
                 $url['images'] = array();
                 $content = $p->post_content;
                 $content = '<p><img src="' . $this->image_url(get_post_thumbnail_id($p->ID)) . '" alt="' . $p->post_title . '" /></p>' . $content;
                 if (preg_match_all('`<img [^>]+>`', $content, $matches)) {
                     foreach ($matches[0] as $img) {
                         if (preg_match('`src=["\']([^"\']+)["\']`', $img, $match)) {
                             $src = $match[1];
                             if (WPSEO_Utils::is_url_relative($src) === true) {
                                 if ($src[0] !== '/') {
                                     continue;
                                 } else {
                                     // The URL is relative, we'll have to make it absolute
                                     $src = $this->home_url . $src;
                                 }
                             } elseif (strpos($src, 'http') !== 0) {
                                 // Protocol relative url, we add the scheme as the standard requires a protocol
                                 $src = $scheme . ':' . $src;
                             }
                             if (strpos($src, $host) === false) {
                                 continue;
                             }
                             if ($src != esc_url($src)) {
                                 continue;
                             }
                             if (isset($url['images'][$src])) {
                                 continue;
                             }
                             $image = array('src' => apply_filters('wpseo_xml_sitemap_img_src', $src, $p));
                             if (preg_match('`title=["\']([^"\']+)["\']`', $img, $title_match)) {
                                 $image['title'] = str_replace(array('-', '_'), ' ', $title_match[1]);
                             }
                             unset($title_match);
                             if (preg_match('`alt=["\']([^"\']+)["\']`', $img, $alt_match)) {
                                 $image['alt'] = str_replace(array('-', '_'), ' ', $alt_match[1]);
                             }
                             unset($alt_match);
                             $image = apply_filters('wpseo_xml_sitemap_img', $image, $p);
                             $url['images'][] = $image;
                         }
                         unset($match, $src);
開發者ID:BennyHudson,項目名稱:foundations,代碼行數:67,代碼來源:class-sitemaps.php

示例6: yoast_wpseo_video_is_url_relative

 /**
  * Fallback function for WP SEO functionality, is_url_relative
  *
  * @param $url
  *
  * @return mixed
  */
 public static function yoast_wpseo_video_is_url_relative($url)
 {
     if (method_exists('WPSEO_Utils', 'is_url_relative')) {
         return WPSEO_Utils::is_url_relative($url);
     }
     return wpseo_is_url_relative($url);
 }
開發者ID:bitrecruiter,項目名稱:wordpress-stackable,代碼行數:14,代碼來源:video-seo.php

示例7: parse_matched_images

 /**
  * Parsing the matched images
  *
  * @param array  $matches
  * @param object $p
  * @param string $scheme
  * @param string $host
  *
  * @return array
  */
 private function parse_matched_images($matches, $p, $scheme, $host)
 {
     $return = array();
     foreach ($matches[0] as $img) {
         if (preg_match('`src=["\']([^"\']+)["\']`', $img, $match)) {
             $src = $match[1];
             if (WPSEO_Utils::is_url_relative($src) === true) {
                 if ($src[0] !== '/') {
                     continue;
                 } else {
                     // The URL is relative, we'll have to make it absolute.
                     $src = $this->home_url . $src;
                 }
             } elseif (strpos($src, 'http') !== 0) {
                 // Protocol relative url, we add the scheme as the standard requires a protocol.
                 $src = $scheme . ':' . $src;
             }
             if (strpos($src, $host) === false) {
                 continue;
             }
             if ($src != esc_url($src)) {
                 continue;
             }
             if (isset($return[$src])) {
                 continue;
             }
             $image = array('src' => apply_filters('wpseo_xml_sitemap_img_src', $src, $p));
             if (preg_match('`title=["\']([^"\']+)["\']`', $img, $title_match)) {
                 $image['title'] = str_replace(array('-', '_'), ' ', $title_match[1]);
             }
             unset($title_match);
             if (preg_match('`alt=["\']([^"\']+)["\']`', $img, $alt_match)) {
                 $image['alt'] = str_replace(array('-', '_'), ' ', $alt_match[1]);
             }
             unset($alt_match);
             $image = apply_filters('wpseo_xml_sitemap_img', $image, $p);
             $return[] = $image;
         }
         unset($match, $src);
     }
     return $return;
 }
開發者ID:flasomm,項目名稱:Montkailash,代碼行數:52,代碼來源:class-sitemaps.php

示例8: get_absolute_url

 /**
  * Make absolute URL for domain or protocol-relative one.
  *
  * @param string $src URL to process.
  *
  * @return string
  */
 protected function get_absolute_url($src)
 {
     if (WPSEO_Utils::is_url_relative($src) === true) {
         if ($src[0] !== '/') {
             return $src;
         }
         // The URL is relative, we'll have to make it absolute.
         return $this->home_url . $src;
     }
     if (strpos($src, 'http') !== 0) {
         // Protocol relative url, we add the scheme as the standard requires a protocol.
         return $this->scheme . ':' . $src;
     }
     return $src;
 }
開發者ID:Garth619,項目名稱:Femi9,代碼行數:22,代碼來源:class-sitemap-image-parser.php

示例9: image_output

 /**
  * Display an OpenGraph image tag
  *
  * @param string $img Source URL to the image
  *
  * @return bool
  */
 public function image_output($img)
 {
     /**
      * Filter: 'wpseo_opengraph_image' - Allow changing the OpenGraph image
      *
      * @api string $img Image URL string
      */
     $img = trim(apply_filters('wpseo_opengraph_image', $img));
     if (empty($img)) {
         return false;
     }
     if (WPSEO_Utils::is_url_relative($img) === true) {
         if ($img[0] != '/') {
             return false;
         }
         // If it's a relative URL, it's relative to the domain, not necessarily to the WordPress install, we
         // want to preserve domain name and URL scheme (http / https) though.
         $parsed_url = parse_url(home_url());
         $img = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $img;
     }
     if (in_array($img, $this->shown_images)) {
         return false;
     }
     array_push($this->shown_images, $img);
     $this->og_tag('og:image', esc_url($img));
     return true;
 }
開發者ID:BennyHudson,項目名稱:foundations,代碼行數:34,代碼來源:class-opengraph.php

示例10: parse_matched_images

 /**
  * Parsing the matched images
  *
  * @param array  $matches Set of matches.
  * @param object $post    Post object.
  *
  * @return array
  */
 private function parse_matched_images($matches, $post)
 {
     $return = array();
     foreach ($matches as $img) {
         if (!preg_match('`src=["\']([^"\']+)["\']`', $img, $match)) {
             continue;
         }
         $src = $match[1];
         if (WPSEO_Utils::is_url_relative($src) === true) {
             if ($src[0] !== '/') {
                 continue;
             }
             // The URL is relative, we'll have to make it absolute.
             $src = $this->home_url . $src;
         } elseif (strpos($src, 'http') !== 0) {
             // Protocol relative url, we add the scheme as the standard requires a protocol.
             $src = $this->scheme . ':' . $src;
         }
         if (strpos($src, $this->host) === false) {
             continue;
         }
         if ($src !== esc_url($src)) {
             continue;
         }
         if (isset($return[$src])) {
             continue;
         }
         $image = array('src' => apply_filters('wpseo_xml_sitemap_img_src', $src, $post));
         if (preg_match('`title=["\']([^"\']+)["\']`', $img, $title_match)) {
             $image['title'] = str_replace(array('-', '_'), ' ', $title_match[1]);
         }
         unset($title_match);
         if (preg_match('`alt=["\']([^"\']+)["\']`', $img, $alt_match)) {
             $image['alt'] = str_replace(array('-', '_'), ' ', $alt_match[1]);
         }
         unset($alt_match);
         /**
          * Filter image data to be included in XML sitemap for the post.
          *
          * @param array $image {
          *     Array of image data.
          *
          *     @type string $src Image URL.
          *     @type string $title Image title attribute (optional).
          *     @type string $alt Image alt attribute (optional).
          * }
          * @param object $post  Post object.
          */
         $image = apply_filters('wpseo_xml_sitemap_img', $image, $post);
         $return[] = $image;
         unset($match, $src);
     }
     return $return;
 }
開發者ID:Friends-School-Atlanta,項目名稱:Deployable-WordPress,代碼行數:62,代碼來源:class-sitemap-image-parser.php

示例11: image_output

 /**
  * Outputs a Twitter image tag for a given image
  *
  * @param string  $img The source URL to the image.
  * @param boolean $tag Deprecated argument, previously used for gallery images.
  *
  * @return bool
  */
 protected function image_output($img, $tag = false)
 {
     if ($tag) {
         _deprecated_argument(__METHOD__, 'WPSEO 2.4');
     }
     /**
      * Filter: 'wpseo_twitter_image' - Allow changing the Twitter Card image
      *
      * @api string $img Image URL string
      */
     $img = apply_filters('wpseo_twitter_image', $img);
     if (WPSEO_Utils::is_url_relative($img) === true && $img[0] === '/') {
         $parsed_url = parse_url(home_url());
         $img = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $img;
     }
     $escaped_img = esc_url($img);
     if (in_array($escaped_img, $this->shown_images)) {
         return false;
     }
     if (is_string($escaped_img) && $escaped_img !== '') {
         $this->output_metatag('image', $escaped_img, true);
         array_push($this->shown_images, $escaped_img);
         return true;
     }
     return false;
 }
開發者ID:jesusmarket,項目名稱:jesusmarket,代碼行數:34,代碼來源:class-twitter.php


注:本文中的WPSEO_Utils::is_url_relative方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。