コード例 #1
0
function post_grid_get_link_url()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    $link = $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
    return '<a href="' . $link . '">' . $link . '</a>';
}
コード例 #2
0
ファイル: content-grabbers.php プロジェクト: jun200/wordpress
 /**
  * Return the URL for the first link found in this post.
  *
  * @param string the_content Post content, falls back to current post content if empty.
  * @return string URL or empty string when no link is present.
  */
 function chunk_url_grabber($the_content = '')
 {
     if (empty($the_content)) {
         $the_content = make_clickable(get_the_content());
     }
     if (function_exists('get_url_in_content')) {
         return get_url_in_content($the_content);
     }
     if (preg_match('/<a\\s[^>]*?href=([\'"])(.+?)\\1/is', $the_content, $matches)) {
         return esc_url_raw($matches[1]);
     }
     return '';
 }
function simple_boostrap_the_link_url()
{
    $has_url = get_url_in_content(get_the_content());
    echo $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #4
0
/**
 * Returns the URL from the post.
 */
function metro_creativex_link_post_format()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #5
0
ファイル: template-tags.php プロジェクト: un1coin/ovn-space
/**
 * Return the post URL.
 *
 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 *
 * Falls back to the post permalink if no URL is found in the post.
 *
 */
function flat_responsive_get_link_url()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #6
0
ファイル: post-meta.php プロジェクト: radscheit/unicorn
function mr_tailor_get_link_url()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #7
0
ファイル: functions.php プロジェクト: ahmedghazi/tpls
 function et_get_link_url()
 {
     if ('' !== ($link_url = get_post_meta(get_the_ID(), '_format_link_url', true))) {
         return $link_url;
     }
     $content = get_the_content();
     $has_url = get_url_in_content($content);
     return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
 }
コード例 #8
0
 /**
  * get the link in content
  * 
  * @return string
  */
 function bootstrapBasicGetLinkInContent()
 {
     $content = get_the_content();
     $has_url = get_url_in_content($content);
     if ($has_url) {
         return $has_url;
     } else {
         return apply_filters('the_permalink', get_permalink());
     }
 }
コード例 #9
0
/**
 * Returns the URL from the post.
 *
 * @uses get_the_link() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 *
 * Falls back to the post permalink if no URL is found in the post.
 *
 * @return string URL
 */
function edin_get_link_url()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    return $has_url && has_post_format('link') ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #10
0
/**
 * Return the post URL.
 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 * Falls back to the post permalink if no URL is found in the post.
 * @since Twenty Thirteen 1.0
 * @return string The Link format URL.
 */
function direitoacidade_get_link_url()
{
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #11
0
 function zn_get_link_url($current_post)
 {
     $has_url = get_url_in_content($current_post['content']);
     return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
 }
コード例 #12
0
ファイル: loop-link.php プロジェクト: bonnbonito/adkins-theme
<?php

/**
 * @package firmasite
 */
global $firmasite_settings, $post;
$has_url = get_url_in_content(get_the_content());
?>

<article id="post-<?php 
the_ID();
?>
" <?php 
post_class("loop_list format_link");
?>
>
 <div class="panel panel-default">
   <div class="panel-body clearfix">
	<?php 
if (has_post_thumbnail()) {
    ?>
	<div class="entry-thumbnail col-xs-4 col-md-4 pull-left fs-content-thumbnail">
      <?php 
    the_post_thumbnail('medium');
    ?>
	</div>
	<?php 
}
?>
    <div class="fs-have-thumbnail">
		<?php 
コード例 #13
0
ファイル: formats.php プロジェクト: boonebgorges/wp
    /**
     * @ticket 23570
     */
    function test_get_url_in_content()
    {
        $link = 'http://nytimes.com';
        $commentary = 'This is my favorite link';
        $link_with_commentary = <<<DATA
{$link}

{$commentary}
DATA;
        $href = '<a href="http://nytimes.com">NYT</a>';
        $href_with_commentary = <<<DATA
{$href}

{$commentary}
DATA;
        $link_post_id = $this->factory->post->create(array('post_content' => $link));
        $content_link = get_url_in_content(get_post_field('post_content', $link_post_id));
        $this->assertEquals(false, $content_link);
        $link_with_post_id = $this->factory->post->create(array('post_content' => $link_with_commentary));
        $content_link = get_url_in_content(get_post_field('post_content', $link_with_post_id));
        $this->assertEquals(false, $content_link);
        $content_link = get_url_in_content(get_post_field('post_content', $link_post_id));
        $this->assertEquals(false, $content_link);
        $content_link = get_url_in_content(get_post_field('post_content', $link_with_post_id));
        $this->assertEquals(false, $content_link);
        $empty_post_id = $this->factory->post->create(array('post_content' => ''));
        $content_link = get_url_in_content(get_post_field('post_content', $empty_post_id));
        $this->assertEquals(false, $content_link);
        $comm_post_id = $this->factory->post->create(array('post_content' => $commentary));
        $content_link = get_url_in_content(get_post_field('post_content', $comm_post_id));
        $this->assertEquals(false, $content_link);
        // Now with an href
        $href_post_id = $this->factory->post->create(array('post_content' => $href));
        $content_link = get_url_in_content(get_post_field('post_content', $href_post_id));
        $this->assertEquals($link, $content_link);
        $href_with_post_id = $this->factory->post->create(array('post_content' => $href_with_commentary));
        $content_link = get_url_in_content(get_post_field('post_content', $href_with_post_id));
        $this->assertEquals($link, $content_link);
        $content_link = get_url_in_content(get_post_field('post_content', $href_post_id));
        $this->assertEquals($link, $content_link);
        $content_link = get_url_in_content(get_post_field('post_content', $href_with_post_id));
        $this->assertEquals($link, $content_link);
        $empty_post_id = $this->factory->post->create(array('post_content' => ''));
        $content_link = get_url_in_content(get_post_field('post_content', $empty_post_id));
        $this->assertEquals(false, $content_link);
        $comm_post_id = $this->factory->post->create(array('post_content' => $commentary));
        $content_link = get_url_in_content(get_post_field('post_content', $comm_post_id));
        $this->assertEquals(false, $content_link);
    }
コード例 #14
0
function laborator_extract_post_content($type, $replace_original = false, $meta = array())
{
    global $post, $post_title, $post_excerpt, $post_content, $blog_post_formats;
    $content = array('content' => '', 'data' => array());
    if (!($post && $blog_post_formats)) {
        return $content;
    }
    //$post_content = apply_filters('the_content', $post->post_content); # Currently Removed
    switch ($type) {
        case 'quote':
            if (preg_match("/^\\s*<blockquote.*?>(.*?)<\\/blockquote>/s", $post_content, $matches)) {
                $blockquote = lab_esc_script(wpautop($matches[1]));
                // Replace Original Content
                if ($replace_original) {
                    $post_excerpt = laborator_get_excerpt(str_replace($matches[0], '', $post_content));
                    $post_content = str_replace($matches[0], '', $post_content);
                }
                if (preg_match("/(<br.*?>\\s*)?<cite>(.*?)<\\/cite>/s", $blockquote, $blockquote_matches)) {
                    $cite = $blockquote_matches[2];
                    $blockquote = str_replace($blockquote_matches[0], '', $blockquote);
                    // Add attributes
                    $content['data']['cite'] = $cite;
                }
                // Set content
                $content['content'] = $blockquote;
            } else {
                $post_content_lines = explode(PHP_EOL, $post_content);
                $blockquote = reset($post_content_lines);
                $content['content'] = $blockquote;
                // Replace Original Content
                if ($replace_original) {
                    $post_content = str_replace($blockquote, '', $post_content);
                    $post_excerpt = laborator_get_excerpt($post_content);
                }
            }
            break;
        case 'image':
            if (preg_match("/<img(.*?)>/s", $post_content, $matches)) {
                $image_args = wp_parse_args(str_replace(" ", "&", $matches[1]));
                if (isset($image_args['src'])) {
                    $src = trim($image_args['src'], "\"'");
                    $content['content'] = $src;
                }
                // Is inside a href
                $img = $matches[0];
                if (preg_match("/((<a.*?>)(.*)?(<img.*?>)(.*)?<\\/a>)/s", $post_content, $a_matches)) {
                    if ($a_matches[4] == $img) {
                        $a_args = wp_parse_args(trim(str_replace(array('<a', '>'), array('', '', '&'), $a_matches[2])));
                        if (isset($a_args['href'])) {
                            $a_href = trim($a_args['href'], "\"'");
                            $content['data']['href'] = $a_href;
                        }
                    }
                }
                if ($replace_original) {
                    $what_to_replace = $matches[0];
                    if (isset($content['data']['href'])) {
                        $what_to_replace = $a_matches[0];
                    }
                    $post_content = str_replace(array($matches[0], '<p></p>'), '', $post_content);
                }
            } else {
                $post_content_lines = explode(PHP_EOL, $post_content);
                $first_line = strip_tags(trim(reset($post_content_lines)));
                if (preg_match("/https?:\\/\\/.*/s", $first_line, $matches)) {
                    $content['content'] = $matches[0];
                }
                if ($replace_original && count($matches)) {
                    $post_content = str_replace($first_line, '', $post_content);
                    $post_excerpt = laborator_get_excerpt($post_content);
                }
            }
            break;
        case 'link':
            $has_url = get_url_in_content(get_the_content());
            $has_url = $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
            $content['content'] = $has_url;
            break;
        case 'video':
            switch (get_data('blog_post_formats_video_player_skin')) {
                case '_2':
                    $player_skin = 'vjs-sublime-skin';
                    break;
                case '_1':
                default:
                    $player_skin = 'vjs-default-skin';
                    break;
            }
            if (preg_match("/\\[video.*?\\[\\/video\\]/s", $post->post_content, $matches)) {
                $videojs_atts = "data-setup=\"{}\" preload=\"auto\"";
                if (isset($meta['poster'])) {
                    $videojs_atts .= ' poster="' . $meta['poster'] . '"';
                }
                $video_shortcode = do_shortcode($matches[0]);
                $video_shortcode = preg_replace(array('/<div.*?>.*?(<video.*?<\\/video>).*?<\\/div.*?>/s', '/(width|height)=".*?"\\s?/'), array('\\1', ''), $video_shortcode);
                $video_shortcode = str_replace(array('wp-video-shortcode', '<video'), array('video-js ' . $player_skin, '<video ' . $videojs_atts), $video_shortcode);
                $content['content'] = $video_shortcode;
                $content['data']['type'] = 'native';
                if ($replace_original && count($matches)) {
                    $post_content = str_replace($matches[0], '', $post->post_content);
                    $post_content = apply_filters('the_content', $post_content);
                }
            } else {
                $post_content_lines = explode(PHP_EOL, $post->post_content);
                $first_line = strip_tags(trim(reset($post_content_lines)));
                $videojs_atts = '';
                if (isset($meta['poster']) && isset($meta['uploadedPoster']) && $meta['uploadedPoster']) {
                    $videojs_atts .= ' poster="' . $meta['poster'] . '"';
                }
                if (preg_match("/(https?:\\/\\/(www\\.)?youtube.com[^\\s]+)/s", $first_line, $matches)) {
                    $youtube_url = $matches[1];
                    $content['data']['type'] = 'youtube';
                    $content['content'] = '<video src="" class="video-js ' . $player_skin . '" controls preload="auto" data-setup=\'{ "techOrder": ["youtube"], "src": "' . $youtube_url . '" }\' ' . $videojs_atts . '>';
                } else {
                    if (preg_match("/(https?:\\/\\/(www\\.)?vimeo.com[^\\s]+)/s", $first_line, $matches)) {
                        $vimeo_url = $matches[1];
                        $content['data']['type'] = 'vimeo';
                        $content['content'] = '<video src="" class="video-js ' . $player_skin . '" controls preload="auto" data-setup=\'{ "techOrder": ["vimeo"], "src": "' . $vimeo_url . '" }\' ' . $videojs_atts . '>';
                    }
                }
                if ($replace_original && count($matches)) {
                    $post_content = str_replace($matches[0], '', $post->post_content);
                    $post_content = apply_filters('the_content', $post_content);
                }
            }
            break;
        case 'audio':
            switch (get_data('blog_post_formats_video_player_skin')) {
                case '_2':
                    $player_skin = 'vjs-sublime-skin';
                    break;
                case '_1':
                default:
                    $player_skin = 'vjs-default-skin';
                    break;
            }
            if (preg_match("/\\[audio.*?(https?[^\\s]+?)\\](\\[\\/audio\\])?/s", $post->post_content, $matches)) {
                $audio_url = $matches[1];
                $videojs_atts = "data-setup=\"{}\" preload=\"auto\"";
                if (isset($meta['poster'])) {
                    $videojs_atts .= ' poster="' . $meta['poster'] . '"';
                }
                $content['content'] = '<audio id="audio_example" class="video-js ' . $player_skin . '" controls ' . $videojs_atts . '><source src="' . $audio_url . '" type=\'audio/mp3\'/></audio>';
                if ($replace_original) {
                    $post_content = str_replace($matches[0], '', $post->post_content);
                    $post_content = apply_filters('the_content', $post_content);
                }
            }
            break;
    }
    return $content;
}
コード例 #15
0
 /**
  * Validate the get_url_in_content function
  * @dataProvider get_input_output
  */
 function test_get_url_in_content($in_str, $exp_str)
 {
     $this->assertEquals($exp_str, get_url_in_content($in_str));
 }
コード例 #16
0
 /**
  * Return the post URL.
  *
  * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
  *     the first link found in the post content.
  *
  * Falls back to the post permalink if no URL is found in the post.
  *
  * @since 3.1.0
  * @todo wp_extract_urls()
  *
  * @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post.
  * @return string     The Link format URL.
  */
 public function get_link_url($post = 0)
 {
     $post = get_post($post);
     $has_url = get_url_in_content($post->post_content);
     return $has_url ? $has_url : apply_filters('the_permalink', get_permalink($post->ID));
 }
コード例 #17
0
ファイル: content-link.php プロジェクト: Arkon13/magazin2
		<?php 
}
?>

		<div class="wc-shortcodes-post-content">
			<?php 
if ($atts['title']) {
    ?>
			<div class="wc-shortcodes-entry-header">
				<<?php 
    echo $atts['heading_type'];
    ?>
 class="wc-shortcodes-entry-title">
					<?php 
    $content = get_the_content();
    $has_url = get_url_in_content($content);
    $link = $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
    ?>
					<a href="<?php 
    echo esc_url($link);
    ?>
"><?php 
    the_title();
    ?>
</a>
				</<?php 
    echo $atts['heading_type'];
    ?>
>
			</div><!-- .entry-header -->
			<?php 
コード例 #18
0
 function avia_link_content_filter($current_post)
 {
     //retrieve the link for the post
     $link = "";
     $newlink = false;
     $pattern1 = '$^\\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i';
     $pattern2 = "!^\\<a.+?<\\/a>!";
     $pattern3 = "!\\<a.+?<\\/a>!";
     //if the url is at the begnning of the content extract it
     preg_match($pattern1, $current_post['content'], $link);
     if (!empty($link[0])) {
         $link = $link[0];
         $markup = avia_markup_helper(array('context' => 'entry_title', 'echo' => false));
         $current_post['title'] = "<a href='{$link}' rel='bookmark' title='" . __('Link to:', 'avia_framework') . " " . the_title_attribute('echo=0') . "' {$markup}>" . get_the_title() . "</a>";
         $current_post['content'] = preg_replace("!" . str_replace("?", "\\?", $link) . "!", "", $current_post['content'], 1);
     } else {
         preg_match($pattern2, $current_post['content'], $link);
         if (!empty($link[0])) {
             $link = $link[0];
             $current_post['title'] = $link;
             $current_post['content'] = preg_replace("!" . str_replace("?", "\\?", $link) . "!", "", $current_post['content'], 1);
             $newlink = get_url_in_content($link);
         } else {
             preg_match($pattern3, $current_post['content'], $link);
             if (!empty($link[0])) {
                 $current_post['title'] = $link[0];
                 $newlink = get_url_in_content($link[0]);
             }
         }
     }
     if ($link) {
         if (is_array($link)) {
             $link = $link[0];
         }
         if ($newlink) {
             $link = $newlink;
         }
         $heading = is_singular() ? "h1" : "h2";
         //$current_post['title'] = "<{$heading} class='post-title entry-title ". avia_offset_class('meta', false). "'>".$current_post['title']."</{$heading}>";
         $current_post['title'] = "<{$heading} class='post-title entry-title' " . avia_markup_helper(array('context' => 'entry_title', 'echo' => false)) . ">" . $current_post['title'] . "</{$heading}>";
         //needs to be set for masonry
         $current_post['url'] = $link;
     } else {
         $current_post = avia_default_title_filter($current_post);
     }
     return $current_post;
 }
コード例 #19
0
ファイル: template-tags.php プロジェクト: train147369/tec
 /**
  * Return the post URL.
  *
  * Falls back to the post permalink if no URL is found in the post.
  *
  * @since tec 1.0
  *
  * @see get_url_in_content()
  *
  * @return string The Link format URL.
  */
 function tec_get_link_url()
 {
     $has_url = get_url_in_content(get_the_content());
     return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
 }
コード例 #20
0
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @since Twenty Eleven 1.0
 *
 * @uses get_url_in_content() to get the first URL from the post content.
 *
 * @return string The first link.
 */
function twentyeleven_get_first_url()
{
    $content = get_the_content();
    $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false;
    if (!$has_url) {
        $has_url = twentyeleven_url_grabber();
    }
    //duplicate_hook
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #21
0
/**
 * Return the post URL to use as link for h1 on link post formats.
 *
 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 *
 * Falls back to the post permalink if no URL is found in the post.
 *
 * @return string The Link format URL.
 */
function editor_get_link_url()
{
    $content = get_the_content();
    $check_url = get_url_in_content($content);
    return $check_url ? $check_url : apply_filters('the_permalink', get_permalink());
}
コード例 #22
0
ファイル: template-tags.php プロジェクト: unisexx/drtooth
/**
 * Returns the URL from the post.
 *
 * @uses get_the_link() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 *
 * Falls back to the post permalink if no URL is found in the post.
 *
 * @return string URL
 */
function sketch_get_link_url() {
	$content = get_the_content();
	$has_url = get_url_in_content( $content );

	return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
}
コード例 #23
0
ファイル: functions.php プロジェクト: Hipermedia/icobelli
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @uses get_url_in_content() to get the first URL from the post content.
 *
 * @return string
 */
function shbase_get_first_url()
{
    $content = get_the_content();
    $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false;
    if (!$has_url) {
        $has_url = shbase_url_grabber();
    }
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #24
0
ファイル: content-link.php プロジェクト: zypherman/CaitiBlog
echo esc_url(get_post_format_link('link'));
?>
" title="<?php 
echo esc_attr(__('All Link Posts', 'match'));
?>
" class="entry-format-icon">
				<i class="fa fa-link"></i>
			</a>
		</div><!-- .entry-format -->
	</div><!-- .entry-media -->

	<header class="entry-header">		
		<?php 
// Extract the first URL from the content.
$post_title_link = get_permalink();
$url_in_content = get_url_in_content(get_the_content());
if (!empty($url_in_content) && false !== $url_in_content) {
    $post_title_link = $url_in_content;
}
?>

		<?php 
if (is_single()) {
    the_title('<h1 class="entry-title">', '</h1>');
} else {
    the_title('<h1 class="entry-title"><a href="' . esc_url($post_title_link) . '" rel="bookmark">', '</a></h1>');
}
?>

		<div class="entry-meta">
			<?php 
コード例 #25
0
ファイル: functions.php プロジェクト: nstungxd/F2CA5
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @since Twenty Eleven 1.0
 *
 * @uses get_url_in_content() to get the first URL from the post content.
 *
 * @return string The first link.
 */
function twentyeleven_get_first_url()
{
    $content = get_the_content();
    $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false;
    if (!$has_url) {
        $has_url = twentyeleven_url_grabber();
    }
    /** This filter is documented in wp-includes/link-template.php */
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
コード例 #26
0
ファイル: functions.php プロジェクト: jdmdigital/bootplate
 function bootplate_get_post_link()
 {
     if (get_post_format(get_the_ID()) == 'link') {
         $content = get_the_content();
         $has_url = get_url_in_content($content);
         if ($has_url) {
             return $has_url;
         } else {
             // Ok, maybe the user didn't link it.  It's just a string in the form of a link...
             // Try and get the URL another way.
             //$links = wp_extract_urls($content) - doesn't work in this context
             preg_match_all('#\\bhttps?://[^,\\s()<>]+(?:\\([\\w\\d]+\\)|([^,[:punct:]\\s]|/))#', $content, $urls);
             if (isset($urls)) {
                 //print_r($urls[0]);
                 $url = $urls[0];
                 $url = implode('', $url);
                 return $url;
             } else {
                 // I give up. Fallback.
                 return apply_filters('the_permalink', get_permalink());
             }
         }
     } else {
         // Normal Post Format
         return esc_url(get_permalink());
     }
 }