/**
  * 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 false when no link is present.
  */
 function next_saturday_url_grabber($the_content = '')
 {
     if (empty($the_content)) {
         $the_content = get_the_content();
     }
     $url = get_the_post_format_url();
     if (empty($url)) {
         $url = get_content_url($the_content);
     }
     return esc_url_raw($url);
 }
/**
 * Filter out the first URL or HTML link of the
 * content in a "Link" format post.
 *
 * @since 2.3.0
 *
 * @param string $content Content of post
 * @return string $content Filtered content of post
 */
function themeblvd_content_format_link($content)
{
    // Only continue if this is a "link" format post.
    if (!has_post_format('link')) {
        return $content;
    }
    // Get the URL from the content.
    $url = get_content_url($content);
    // Remove that URL from the start of content,
    // if that's where it was.
    if ($url && 0 === strpos($content, $url)) {
        $content = str_replace($url, '', $content);
    }
    return $content;
}
             } else {
                 $httpClient->setCookies($cookies);
             }
             // $httpClient->get($cookieURL);
             // $cookies = $httpClient->getCookies();
         } while (!$cookies);
     }
     $httpClient->setReferer($refUrl);
     $contentUrl = "http://epub.cnki.net" . $u;
     $contentSize = 0;
     do {
         $httpClient->get($contentUrl);
         $content = $httpClient->getContent();
         //302页面
         /*解析地址*/
         $contentUrl = get_content_url($content);
         echo $contentUrl . "\n";
         $saveContent = $paperName . "\t" . $contentUrl . "\n";
         save($mapFile, $saveContent, "a+");
         //echo "save $saveContent\n";
         /*抓取论文摘要内容*/
         $content = $httpClient->quickGet($contentUrl);
         $contentSize = strlen($content);
         if ($contentSize > 300) {
             save($cachedHtml, $content);
         } else {
             fakeSleep();
         }
     } while ($contentSize < 300);
 } else {
     $sleep = false;
Beispiel #4
0
 /**
  * Captures the HTML code with the featured media based on featured media linking method.
  *
  * @param				array $args
  * @return				string
  */
 function g1_capture_entry_featured_media($args)
 {
     // Prepare arguments
     $defaults = array('size' => '', 'lightbox_group' => '', 'force_placeholder' => true);
     $r = wp_parse_args($args, $defaults);
     /* We need a static counter to generate unique ids for inline lightboxes */
     static $inline_lightbox_counter = 0;
     global $post;
     $url = '';
     $linking = '';
     $holder = '';
     $placeholder = '';
     $out = '';
     // Try to return a placeholder when an entry is password protected
     if (post_password_required($post)) {
         if (!$r['force_placeholder']) {
             return '';
         }
         $out = sprintf('[placeholder icon="lock" size="%s"]', $r['size']);
     } else {
         $post_format = get_post_format($post->ID);
         switch ($post_format) {
             case 'audio':
                 $audio = g1_capture_post_audio($post->ID, $r['size']);
                 $audio = do_shortcode($audio);
                 $js_id = 'g1_var_' . rand();
                 $js = '<script id="' . esc_attr($js_id) . '" class="g1-var">' . 'var ' . $js_id . ' = ' . json_encode(array('html_code' => $audio)) . ';' . '</script>';
                 // Thumbnail image triggers an inline lightbox with the audio player
                 if (has_post_thumbnail($post->ID)) {
                     $thumb = get_the_post_thumbnail($post->ID, $r['size']);
                     // Compose the template
                     $out = '<figure class="entry-featured-media">' . '[frame link="%LINK%"]' . '%THUMB%' . '[/frame]' . $js . '</figure>';
                     // Fill in the template
                     $out = str_replace(array('%LINK%', '%THUMB%'), array('#', $thumb), $out);
                 } else {
                     if ($r['force_placeholder']) {
                         $placeholder = '[placeholder size="' . $r['size'] . '"]';
                     }
                     $out = '<figure class="entry-featured-media">' . $audio . $placeholder . $js . '</figure>';
                 }
                 break;
             case 'image':
                 // Thumbnail image triggers the full version
                 if (has_post_thumbnail($post->ID)) {
                     $thumb = get_the_post_thumbnail($post->ID, $r['size']);
                     $image = get_post_meta($post->ID, '_format_image', true);
                     // @todo get url from $image
                     $url = $image;
                     if (!strlen($url)) {
                         $url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
                         $url = $url[0];
                     }
                     // Compose the template
                     $out = '<figure class="entry-featured-media">' . '[frame link="%LINK%"]' . '%THUMB%' . '[/frame]' . '</figure>';
                     // Fill in the template
                     $out = str_replace(array('%LINK%', '%THUMB%'), array($url, $thumb), $out);
                 }
                 // WP 3.6 post format
                 if (empty($out)) {
                     $image = get_post_meta($post->ID, '_format_image', true);
                     if (!empty($image)) {
                         if (is_html_code($image)) {
                             $out = '<figure class="entry-featured-media">' . $image . '</figure>';
                         } else {
                             $out = '<figure class="entry-featured-media">' . '<img src="' . $image . '" alt="' . $post->post_title . '" />' . '</figure>';
                         }
                     }
                 }
                 // post fromat < WP 3.6
                 if (empty($out)) {
                     // first img tag
                     $img_tag = G1_Post_Format::find_html_tag('img', $post->post_content);
                     // first link tag
                     $url = get_content_url($post->post_content);
                     if (!empty($img_tag)) {
                         $out = '<figure class="entry-featured-media">' . $img_tag . '</figure>';
                     } else {
                         if (!empty($url)) {
                             $out = '<figure class="entry-featured-media">' . '<img src="' . $url . '" alt="' . $post->post_title . '" />' . '</figure>';
                         }
                     }
                 }
                 break;
             case 'gallery':
                 // Thumbnail image triggers the full gallery
                 if (has_post_thumbnail($post->ID)) {
                     $thumb = get_the_post_thumbnail($post->ID, $r['size']);
                     $url = apply_filters('the_permalink', get_permalink($post->ID));
                     $items = g1_get_post_format_gallery($post->ID, 'full');
                     // Compose gallery as a list of links
                     $gallery_data = '';
                     foreach ($items as $item) {
                         $gallery_data .= str_replace(array('%URL%', '%WIDTH%', '%HEIGHT%'), array(esc_url($item['url']), absint($item['width']), absint($item['height'])), '<li><a href="%URL%" data-g1-width="%WIDTH%" data-g1-height="%HEIGHT%"></a></li>');
                     }
                     // Compose the template
                     $out = '<figure class="entry-featured-media">' . '[frame link="%LINK%"]' . '%THUMB%' . '[/frame]' . '<ul class="g1-gallery-data">' . '%GALLERY_DATA%' . '</ul>' . '</figure>';
                     // Fill in the template
                     $out = str_replace(array('%LINK%', '%THUMB%', '%GALLERY_DATA%'), array(esc_url($url), $thumb, $gallery_data), $out);
                 } else {
                     $items = g1_get_post_format_gallery($post->ID, $r['size']);
                     $gallery = '';
                     foreach ($items as $item) {
                         $gallery .= str_replace(array('%URL%', '%WIDTH%', '%HEIGHT%'), array(esc_url($item['url']), absint($item['width']), absint($item['height'])), '<li><img src="%URL%" width="%WIDTH%" height="%HEIGHT%" alt=""/></li>');
                     }
                     // Compose gallery as a list of links
                     $items = g1_get_post_format_gallery($post->ID, 'full');
                     $gallery_data = '';
                     foreach ($items as $item) {
                         $gallery_data .= str_replace(array('%URL%', '%WIDTH%', '%HEIGHT%'), array(esc_url($item['url']), absint($item['width']), absint($item['height'])), '<li><a href="%URL%" data-g1-width="%WIDTH%" data-g1-height="%HEIGHT%"></a></li>');
                     }
                     $out = '<figure class="entry-featured-media">' . '<ul class="g1-gallery-items">' . $gallery . '</ul>' . '<ul class="g1-gallery-data">' . $gallery_data . '</ul>' . '</figure>';
                 }
                 break;
             case 'video':
                 $big_video = g1_capture_post_video($post->ID, 'g1_max');
                 $big_video = do_shortcode($big_video);
                 $js_id = 'g1_var_' . rand();
                 $js = '<script id="' . esc_attr($js_id) . '" class="g1-var">' . 'var ' . $js_id . ' = ' . json_encode(array('html_code' => $big_video)) . ';' . '</script>';
                 // Thumbnail image triggers the video
                 if (has_post_thumbnail($post->ID)) {
                     $thumb = get_the_post_thumbnail($post->ID, $r['size']);
                     // Compose the template
                     $out = '<figure class="entry-featured-media">' . "\n" . '[frame link="%LINK%"]' . '%THUMB%' . '[/frame]' . "\n" . $js . '</figure>';
                     $embed = get_post_meta($post->ID, '_format_video_embed', true);
                     if (false === strpos($embed, 'http://') && false === strpos($embed, 'https://')) {
                         $embed = the_permalink($post->ID);
                     }
                     // Fill in the template
                     $out = str_replace(array('%LINK%', '%THUMB%'), array(esc_url($embed), $thumb), $out);
                 } else {
                     $small_video = g1_capture_post_video($post->ID, $r['size']);
                     $small_video = do_shortcode($small_video);
                     $out = '<figure class="entry-featured-media">' . $small_video . $js . '</figure>';
                 }
                 break;
             case 'link':
                 $linking = 'new-window';
                 // first link tag
                 $url = get_content_url($post->post_content);
             default:
                 if (!has_post_thumbnail($post->ID)) {
                     if (!$r['force_placeholder']) {
                         return '';
                     }
                     $placeholder = sprintf('[placeholder size="%s" icon="post-format"]', $r['size']);
                 } else {
                     $holder = get_the_post_thumbnail($post->ID, $r['size']);
                 }
                 if (empty($url)) {
                     $has_url = get_the_post_format_url($post->ID);
                     $url = $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
                 }
                 // Compose the template
                 $out = '<figure class="entry-featured-media">' . "\n" . '[frame link="%LINK%" linking="%LINKING%"]' . '%HOLDER%' . '%PLACEHOLDER%' . '[/frame]' . "\n" . '</figure>';
                 // Fill in the template
                 $out = str_replace(array('%LINK%', '%LINKING%', '%HOLDER%', '%PLACEHOLDER%'), array($url, $linking, $holder, $placeholder), $out);
                 break;
         }
     }
     // Apply shortcodes
     $out = do_shortcode($out);
     return $out;
 }
Beispiel #5
0
/**
 * Get the_title() taking into account if it should
 * wrapped in a link.
 *
 * @since 2.3.0
 *
 * @param int $post_id Can feed in a post ID if outside the loop.
 * @param bool $foce_link Whether to force the title to link.
 * @return string $title The title of the post
 */
function themeblvd_get_the_title($post_id = 0, $force_link = false)
{
    $url = '';
    $title = get_the_title($post_id);
    // If "link" post format, get URL from start of content.
    if (has_post_format('link', $post_id)) {
        $url = get_content_url(get_the_content($post_id));
    }
    // If not a single post or page, get permalink for URL.
    if (!$url && (!themeblvd_was('single') || $force_link)) {
        $url = get_permalink($post_id);
    }
    // Wrap title in link if there's a URL.
    if ($url) {
        $title = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), esc_attr(the_title_attribute('echo=0')), $title);
    }
    return apply_filters('themeblvd_the_title', $title, $url);
}
/**
 * Attempt to retrieve a URL from a post's content
 *
 * @since 3.6.0
 *
 * @param int $post_id (optional) The post ID.
 * @return string A URL, if found.
 */
function get_the_post_format_url($post_id = 0)
{
    if (!($post = get_post($post_id))) {
        return '';
    }
    $format = get_post_format($post->ID);
    if (in_array($format, array('image', 'link', 'quote'))) {
        $meta = get_post_format_meta($post->ID);
        $meta_link = '';
        switch ($format) {
            case 'link':
                if (!empty($meta['link_url'])) {
                    $meta_link = $meta['link_url'];
                }
                break;
            case 'image':
                if (!empty($meta['url'])) {
                    $meta_link = $meta['url'];
                }
                break;
            case 'quote':
                if (!empty($meta['quote_source_url'])) {
                    $meta_link = $meta['quote_source_url'];
                }
                break;
        }
        if (!empty($meta_link)) {
            return apply_filters('get_the_post_format_url', esc_url_raw($meta_link), $post);
        }
    }
    if (!empty($post->post_content)) {
        return apply_filters('get_the_post_format_url', get_content_url($post->post_content), $post);
    }
}