コード例 #1
0
/**
 * syndication_comments_feed_link: Escape XML special characters in comments
 * feed links 
 *
 * @param string $link
 * @return string
 *
 * @uses is_syndicated()
 * @uses FeedWordPress::munge_permalinks()
 */
function syndication_comments_feed_link($link)
{
    global $feedwordpress_the_original_permalink, $id;
    if (is_syndicated() and FeedWordPress::munge_permalinks()) {
        // If the source post provided a comment feed URL using
        // wfw:commentRss or atom:link/@rel="replies" we can make use of
        // that value here.
        $source = get_syndication_feed_object();
        $replacement = NULL;
        if ($source->setting('munge comments feed links', 'munge_comments_feed_links', 'yes') != 'no') {
            $commentFeeds = get_post_custom_values('wfw:commentRSS');
            if (is_array($commentFeeds) and count($commentFeeds) > 0 and strlen($commentFeeds[0]) > 0) {
                $replacement = $commentFeeds[0];
                // This is a foreign link; WordPress can't vouch for its not
                // having any entities that need to be &-escaped. So we'll do it
                // here.
                $replacement = esc_html($replacement);
            }
        }
        if (is_null($replacement)) {
            // Q: How can we get the proper feed format, since the
            // format is, stupidly, not passed to the filter?
            // A: Kludge kludge kludge kludge!
            $fancy_permalinks = '' != get_option('permalink_structure');
            if ($fancy_permalinks) {
                preg_match('|/feed(/([^/]+))?/?$|', $link, $ref);
                $format = isset($ref[2]) ? $ref[2] : '';
                if (strlen($format) == 0) {
                    $format = get_default_feed();
                }
                $replacement = trailingslashit($feedwordpress_the_original_permalink) . 'feed';
                if ($format != get_default_feed()) {
                    $replacement .= '/' . $format;
                }
                $replacement = user_trailingslashit($replacement, 'single_feed');
            } else {
                // No fancy permalinks = no problem
                // WordPress doesn't call get_permalink() to
                // generate the comment feed URL, so the
                // comments feed link is never munged by FWP.
            }
        }
        if (!is_null($replacement)) {
            $link = $replacement;
        }
    }
    return $link;
}
コード例 #2
0
ファイル: SicEm.php プロジェクト: radgeek/FWP---SIC--Em
 public function process_captured_images($delta)
 {
     global $post, $wpdb;
     // Let's do this.
     $q = new WP_Query(array('post_type' => 'any', 'meta_key' => '_syndicated_image_capture', 'posts_per_page' => 10));
     while ($q->have_posts()) {
         $q->the_post();
         $this->post = $post;
         $imgs = get_post_custom_values('_syndicated_image_capture');
         $featureUrls = get_post_custom_values('_syndicated_image_featured');
         $source = get_syndication_feed_object($post->ID);
         $replacements = array();
         if (count($imgs) > 0 and !!$imgs[0] and 'yes' == $source->setting('cache images', 'cache_images', 'no')) {
             $seekingFeature = 'yes' == $source->setting('feature captured images', 'feature_captured_images', NULL);
             $customFieldName = trim($source->setting('sicem custom field', 'sicem_custom_field', ''));
             foreach ($imgs as $img) {
                 $imgGuid = SICWebImage::guid($img);
                 $guid = $wpdb->escape($imgGuid);
                 $result = $wpdb->get_row("\n\t\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\t\tWHERE guid='{$guid}' AND post_type='attachment'\n\t\t\t\t\t");
                 if (!$result) {
                     // Attachment not yet created
                     $params = array("min width" => $source->setting('sicem min width', 'sicem_min_width', 0), "min height" => $source->setting('sicem min height', 'sicem_min_height', 0), "blacklist" => explode("|", $source->setting('sicem mime blacklist', 'sicem_mime_blacklist', NULL)), "whitelist" => explode("|", $source->setting('sicem mime whitelist', 'sicem_mime_whitelist', NULL)), "crop" => $source->setting('sicem crop ratio', 'sicem_crop_ratio', NULL), "resize" => $source->setting('sicem resize', 'sicem_resize', NULL));
                     $img_id = $this->attach_image($img, $post->ID, $params);
                 } else {
                     $img_id = $result->ID;
                 }
                 if ($img_id and !is_wp_error($img_id)) {
                     // Mark for replacing all occurrences in img/@src
                     $replacements[$img] = $img_id;
                     // Set as featured image, if applicable.
                     if ($img_id > 0 and $seekingFeature) {
                         if (count($featureUrls) == 0 or in_array($img, $featureUrls)) {
                             update_post_meta($post->ID, '_thumbnail_id', $img_id);
                             $seekingFeature = false;
                         }
                     }
                     $zapit = true;
                 }
             }
             foreach ($replacements as $url => $attach_id) {
                 $replacement = NULL;
                 if ($attach_id < 0) {
                     $new_url = NULL;
                     if ($source->setting('sicem strip uncacheable images', 'sicem_strip_uncacheable_images', 'no') == 'yes') {
                         FeedWordPress::diagnostic('sicem:capture', 'Image  [' . $url . '] not cached; stripping image.');
                         $replacement = '';
                     } else {
                         FeedWordPress::diagnostic('sicem:capture', 'Image  [' . $url . '] not cached; leaving hotlinked image.');
                         $replacement = NULL;
                     }
                 } else {
                     FeedWordPress::diagnostic('sicem:capture', 'Captured image [' . $url . '] to local URL [' . $new_url . ']');
                     $new_url = wp_get_attachment_url($attach_id);
                     if ($new_url) {
                         $replacement = '$1' . $new_url . '$2';
                     } else {
                         $replacement = NULL;
                     }
                 }
                 if (!is_null($replacement)) {
                     $find = preg_quote($url);
                     $post->post_content = preg_replace(':(<img \\s+ [^>]*src=[^>]*)' . $find . '([^>]*>):ix', $replacement, $post->post_content);
                     if ($new_url and strlen($customFieldName) > 0) {
                         add_post_meta($post->ID, $customFieldName, $new_url);
                     }
                 }
             }
             // Save as a revision of the existing post.
             $this->insert_revision($post);
             if ($zapit) {
                 delete_post_meta($post->ID, '_syndicated_image_capture');
             }
         }
     }
 }
コード例 #3
0
 function process_expirations($delta)
 {
     global $post;
     global $wpdb;
     $q = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => get_option('fwplpbd_expiration_chunk', 25), 'meta_key' => '_syndication_expiration_date', 'meta_value' => time(), 'meta_compare' => '<='));
     while ($q->have_posts()) {
         $q->the_post();
         $expiration = get_post_meta($post->ID, '_syndication_expiration_date', true);
         if ((int) $expiration and (int) $expiration <= time()) {
             $action = get_post_meta($post->ID, '_syndication_expiration_action', true);
             FeedWordPress::diagnostic('expiration', 'Post [' . $post->ID . '] "' . esc_html($post->post_title) . '" expired as of ' . date('r', (int) $expiration) . ' and will now be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
             switch ($action) {
                 case 'trash':
                 case 'nuke':
                     $feed = get_syndication_feed_object($post->ID);
                     $thumbId = get_post_thumbnail_id($post->ID);
                     wp_delete_post($post->ID, 'nuke' == $action);
                     // Check to see whether any other posts
                     // use this as a Featured Image. If not
                     // then zap it.
                     if ("nuke" == $feed->setting('post expiration thumbnail', 'post_expiration_thumbnail', "keep")) {
                         if (strlen($thumbId) > 0) {
                             $qrows = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT meta_value FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\tWHERE meta_key = '_thumbnail_id'\n\t\t\t\t\t\t\tAND meta_value = '%d'\n\t\t\t\t\t\t\tAND post_id <> '%d'\n\t\t\t\t\t\t\t", $thumbId, $post->ID));
                             if (count($qrows) < 1) {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, which is not used as the Featured Image for any other post. We will now clean up and the image will be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
                                 wp_delete_attachment($thumbId, 'nuke' == $action);
                             } else {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, but it CANNOT be deleted right now because at least one other post uses the same image as its Featured Image.');
                             }
                         }
                     }
                     break;
                 case 'hide':
                 case 'redirect':
                 default:
                     $old_status = $post->post_status;
                     set_post_field('post_status', 'expired', $post->ID);
                     wp_transition_post_status('expired', $old_status, $post);
                     break;
             }
         }
     }
 }