strip_comments() public method

public strip_comments ( $strip = false )
 /**
  *
  * @param object $bookmark
  * @param object $owner
  */
 protected function do_rss($bookmark, $owner)
 {
     // no bookmark, no fun
     if (empty($bookmark) || !is_object($bookmark)) {
         return false;
     }
     // no owner means no email, so no reason to parse
     if (empty($owner) || !is_object($owner)) {
         return false;
     }
     // instead of the way too simple fetch_feed, we'll use SimplePie itself
     if (!class_exists('SimplePie')) {
         require_once ABSPATH . WPINC . '/class-simplepie.php';
     }
     $url = htmlspecialchars_decode($bookmark->link_rss);
     $last_updated = strtotime($bookmark->link_updated);
     static::debug('Fetching: ' . $url, 6);
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_duration(static::revisit_time - 10);
     $feed->set_cache_location($this->cachedir);
     $feed->force_feed(true);
     // optimization
     $feed->enable_order_by_date(true);
     $feed->remove_div(true);
     $feed->strip_comments(true);
     $feed->strip_htmltags(false);
     $feed->strip_attributes(true);
     $feed->set_image_handler(false);
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         $err = new WP_Error('simplepie-error', $feed->error());
         static::debug('Error: ' . $err->get_error_message(), 4);
         $this->failed($owner->user_email, $url, $err->get_error_message());
         return $err;
     }
     // set max items to 12
     // especially useful with first runs
     $maxitems = $feed->get_item_quantity(12);
     $feed_items = $feed->get_items(0, $maxitems);
     $feed_title = $feed->get_title();
     // set the link name from the RSS title
     if (!empty($feed_title) && $bookmark->link_name != $feed_title) {
         global $wpdb;
         $wpdb->update($wpdb->prefix . 'links', array('link_name' => $feed_title), array('link_id' => $bookmark->link_id));
     }
     // if there's a feed author, get it, we may need it if there's no entry
     // author
     $feed_author = $feed->get_author();
     $last_updated_ = 0;
     if ($maxitems > 0) {
         foreach ($feed_items as $item) {
             // U stands for Unix Time
             $date = $item->get_date('U');
             if ($date > $last_updated) {
                 $fromname = $feed_title;
                 $author = $item->get_author();
                 if ($author) {
                     $fromname = $fromname . ': ' . $author->get_name();
                 } elseif ($feed_author) {
                     $fromname = $fromname . ': ' . $feed_author->get_name();
                 }
                 // this is to set the sender mail from our own domain
                 $frommail = get_user_meta($owner->ID, 'blogroll2email_email', true);
                 if (!$frommail) {
                     $sitedomain = parse_url(get_bloginfo('url'), PHP_URL_HOST);
                     $frommail = static::schedule . '@' . $sitedomain;
                 }
                 $from = $fromname . '<' . $frommail . '>';
                 $content = $item->get_content();
                 $matches = array();
                 preg_match_all('/farm[0-9]\\.staticflickr\\.com\\/[0-9]+\\/([0-9]+_[0-9a-zA-Z]+_m\\.jpg)/s', $content, $matches);
                 if (!empty($matches[0])) {
                     foreach ($matches[0] as $to_replace) {
                         $clean = str_replace('_m.jpg', '_c.jpg', $to_replace);
                         $content = str_replace($to_replace, $clean, $content);
                     }
                     $content = preg_replace("/(width|height)=\"(.*?)\" ?/is", '', $content);
                 }
                 $content = apply_filters('blogroll2email_message', $content);
                 if ($this->send($owner->user_email, $item->get_link(), $item->get_title(), $from, $url, $item->get_content(), $date)) {
                     if ($date > $last_updated_) {
                         $last_updated_ = $date;
                     }
                 }
             }
         }
     }
     // poke the link's last update field, so we know what was the last sent
     // entry's date
     $this->update_link_date($bookmark, $last_updated_);
 }
function feedzy_rss($atts, $content = '')
{
    global $feedzyStyle;
    $feedzyStyle = true;
    $count = 0;
    //Load SimplePie if not already
    if (!class_exists('SimplePie')) {
        require_once ABSPATH . WPINC . '/class-feed.php';
    }
    //Retrieve & extract shorcode parameters
    extract(shortcode_atts(array("feeds" => '', "max" => '5', "feed_title" => 'yes', "target" => '_blank', "title" => '', "meta" => 'yes', "summary" => 'yes', "summarylength" => '', "thumb" => 'yes', "default" => '', "size" => '', "keywords_title" => ''), $atts, 'feedzy_default'));
    //Use "shortcode_atts_feedzy_default" filter to edit shortcode parameters default values or add your owns.
    if (!empty($feeds)) {
        $feeds = rtrim($feeds, ',');
        $feeds = explode(',', $feeds);
        //Remove SSL from HTTP request to prevent fetching errors
        foreach ($feeds as $feed) {
            $feedURL[] = preg_replace("/^https:/i", "http:", $feed);
        }
        if (count($feedURL) === 1) {
            $feedURL = $feedURL[0];
        }
    }
    if ($max == '0') {
        $max = '999';
    } else {
        if (empty($max) || !ctype_digit($max)) {
            $max = '5';
        }
    }
    if (empty($size) || !ctype_digit($size)) {
        $size = '150';
    }
    $sizes = array('width' => $size, 'height' => $size);
    $sizes = apply_filters('feedzy_thumb_sizes', $sizes, $feedURL);
    if (!empty($title) && !ctype_digit($title)) {
        $title = '';
    }
    if (!empty($keywords_title)) {
        $keywords_title = rtrim($keywords_title, ',');
        $keywords_title = array_map('trim', explode(',', $keywords_title));
    }
    if (!empty($summarylength) && !ctype_digit($summarylength)) {
        $summarylength = '';
    }
    if (!empty($default)) {
        $default = $default;
    } else {
        $default = apply_filters('feedzy_default_image', $default, $feedURL);
    }
    //Load SimplePie Instance
    $feed = new SimplePie();
    $feed->set_feed_url($feedURL);
    $feed->enable_cache(true);
    $feed->enable_order_by_date(true);
    $feed->set_cache_class('WP_Feed_Cache');
    $feed->set_file_class('WP_SimplePie_File');
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 7200, $feedURL));
    do_action_ref_array('wp_feed_options', array($feed, $feedURL));
    $feed->strip_comments(true);
    $feed->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'));
    $feed->init();
    $feed->handle_content_type();
    // Display the error message
    if ($feed->error()) {
        $content .= apply_filters('feedzy_default_error', $feed->error(), $feedURL);
    }
    $content .= '<div class="feedzy-rss">';
    if ($feed_title == 'yes') {
        $content .= '<div class="rss_header">';
        $content .= '<h2><a href="' . $feed->get_permalink() . '" class="rss_title">' . html_entity_decode($feed->get_title()) . '</a> <span class="rss_description"> ' . $feed->get_description() . '</span></h2>';
        $content .= '</div>';
    }
    $content .= '<ul>';
    //Loop through RSS feed
    $items = apply_filters('feedzy_feed_items', $feed->get_items(), $feedURL);
    foreach ((array) $items as $item) {
        $continue = apply_filters('feedzy_item_keyword', true, $keywords_title, $item, $feedURL);
        if ($continue == true) {
            //Count items
            if ($count >= $max) {
                break;
            }
            $count++;
            //Fetch image thumbnail
            if ($thumb == 'yes' || $thumb == 'auto') {
                $thethumbnail = feedzy_retrieve_image($item);
            }
            $itemAttr = apply_filters('feedzy_item_attributes', $itemAttr = '', $sizes, $item, $feedURL);
            //Build element DOM
            $content .= '<li ' . $itemAttr . '>';
            if ($thumb == 'yes' || $thumb == 'auto') {
                $contentThumb = '';
                if (!empty($thethumbnail) && $thumb == 'auto' || $thumb == 'yes') {
                    $contentThumb .= '<div class="rss_image" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px;">';
                    $contentThumb .= '<a href="' . $item->get_permalink() . '" target="' . $target . '" title="' . $item->get_title() . '" >';
                    if (!empty($thethumbnail)) {
                        $thethumbnail = feedzy_image_encode($thethumbnail);
                        $contentThumb .= '<span class="default" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:  url(' . $default . ');" alt="' . $item->get_title() . '"></span>';
                        $contentThumb .= '<span class="fetched" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:  url(' . $thethumbnail . ');" alt="' . $item->get_title() . '"></span>';
                    } else {
                        if (empty($thethumbnail) && $thumb == 'yes') {
                            $contentThumb .= '<span style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:url(' . $default . ');" alt="' . $item->get_title() . '"></span>';
                        }
                    }
                    $contentThumb .= '</a>';
                    $contentThumb .= '</div>';
                }
                //Filter: feedzy_thumb_output
                $content .= apply_filters('feedzy_thumb_output', $contentThumb, $feedURL);
            }
            $contentTitle = '';
            $contentTitle .= '<span class="title"><a href="' . $item->get_permalink() . '" target="' . $target . '">';
            if (is_numeric($title) && strlen($item->get_title()) > $title) {
                $contentTitle .= preg_replace('/\\s+?(\\S+)?$/', '', substr($item->get_title(), 0, $title)) . '...';
            } else {
                $contentTitle .= $item->get_title();
            }
            $contentTitle .= '</a></span>';
            //Filter: feedzy_title_output
            $content .= apply_filters('feedzy_title_output', $contentTitle, $feedURL);
            $content .= '<div class="rss_content">';
            //Define Meta args
            $metaArgs = array('author' => true, 'date' => true, 'date_format' => get_option('date_format'), 'time_format' => get_option('time_format'));
            //Filter: feedzy_meta_args
            $metaArgs = apply_filters('feedzy_meta_args', $metaArgs, $feedURL);
            if ($meta == 'yes' && ($metaArgs['author'] || $metaArgs['date'])) {
                $contentMeta = '';
                $contentMeta .= '<small>' . __('Posted', 'feedzy_rss_translate') . ' ';
                if ($item->get_author() && $metaArgs['author']) {
                    $author = $item->get_author();
                    if (!($authorName = $author->get_name())) {
                        $authorName = $author->get_email();
                    }
                    if ($authorName) {
                        $domain = parse_url($item->get_permalink());
                        $contentMeta .= __('by', 'feedzy_rss_translate') . ' <a href="http://' . $domain['host'] . '" target="' . $target . '" title="' . $domain['host'] . '" >' . $authorName . '</a> ';
                    }
                }
                if ($metaArgs['date']) {
                    $contentMeta .= __('on', 'feedzy_rss_translate') . ' ' . date_i18n($metaArgs['date_format'], $item->get_date('U'));
                    $contentMeta .= ' ';
                    $contentMeta .= __('at', 'feedzy_rss_translate') . ' ' . date_i18n($metaArgs['time_format'], $item->get_date('U'));
                }
                $contentMeta .= '</small>';
                //Filter: feedzy_meta_output
                $content .= apply_filters('feedzy_meta_output', $contentMeta, $feedURL);
            }
            if ($summary == 'yes') {
                $contentSummary = '';
                $contentSummary .= '<p>';
                //Filter: feedzy_summary_input
                $description = $item->get_description();
                $description = apply_filters('feedzy_summary_input', $description, $item->get_content(), $feedURL);
                if (is_numeric($summarylength) && strlen($description) > $summarylength) {
                    $contentSummary .= preg_replace('/\\s+?(\\S+)?$/', '', substr($description, 0, $summarylength)) . ' […]';
                } else {
                    $contentSummary .= $description . ' […]';
                }
                $contentSummary .= '</p>';
                //Filter: feedzy_summary_output
                $content .= apply_filters('feedzy_summary_output', $contentSummary, $item->get_permalink(), $feedURL);
            }
            $content .= '</div>';
            $content .= '</li>';
        }
        //endContinue
    }
    //endforeach
    $content .= '</ul>';
    $content .= '</div>';
    return apply_filters('feedzy_global_output', $content, $feedURL);
}
示例#3
0
    /**
     * Processing the parameters into placeholders
     * @param string    $spie   snippet parameters
     * @return array    placeholders
     */
    private function _setSimplePieModxPlaceholders($spie) {
        /**
         * @link http://github.com/simplepie/simplepie/tree/one-dot-two
         */
        if (!file_exists($spie['simplePieClassFile'])) {
            return 'File ' . $spie['simplePieClassFile'] . ' does not exist.';
        }
        include_once $spie['simplePieClassFile'];
        $feed = new SimplePie();
        $joinKey = 0;
        foreach ($spie['setFeedUrl'] as $setFeedUrl) {
            $feed->set_cache_location($spie['setCacheLocation']);
            $feed->set_feed_url($setFeedUrl);

            if (isset($spie['setInputEncoding'])) {
                $feed->set_input_encoding($spie['setInputEncoding']);
            }
            if (isset($spie['setOutputEncoding'])) {
                $feed->set_output_encoding($spie['setOutputEncoding']);
            }
            // if no cURL, try fsockopen
            if (isset($spie['forceFSockopen'])) {
                $feed->force_fsockopen(true);
            }
            if (isset($spie['enableCache']))
                $feed->enable_cache($spie['enableCache']);
            if (isset($spie['enableOrderByDate']))
                $feed->enable_order_by_date($spie['enableOrderByDate']);
            if (isset($spie['setCacheDuration']))
                $feed->set_cache_duration($spie['setCacheDuration']);
            if (!empty($spie['setFaviconHandler']))
                $feed->set_favicon_handler($spie['setFaviconHandler'][0], $spie['setFaviconHandler'][1]);
            if (!empty($spie['setImageHandler'])) {
                // handler_image.php?image=67d5fa9a87bad230fb03ea68b9f71090
                $feed->set_image_handler($spie['setImageHandler'][0], $spie['setImageHandler'][1]);
            }

            // disabled since these are all splitted into a single fetching
            // it's  been used with different way, see below looping
//            if (isset($spie['setItemLimit']))
//                $feed->set_item_limit((int) $spie['setItemLimit']);

            if (isset($spie['setJavascript']))
                $feed->set_javascript($spie['setJavascript']);
            if (isset($spie['stripAttributes']))
                $feed->strip_attributes(array_merge($feed->strip_attributes, $spie['stripAttributes']));
            if (isset($spie['stripComments']))
                $feed->strip_comments($spie['stripComments']);
            if (isset($spie['stripHtmlTags']))
                $feed->strip_htmltags(array_merge($feed->strip_htmltags, $spie['stripHtmlTags']));

            /**
             * Initiating the Feeding.
             * This always be placed AFTER all the settings above.
             */
            if (!$feed->init()) {
                echo $feed->error();
                return FALSE;
            }

            $countItems = count($feed->get_items());
            if (1 > $countItems) {
                continue;
            }

            $feed->handle_content_type();

            $countLimit = 0;
            foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) {

                if (isset($spie['setItemLimit']) && $spie['setItemLimit'] == $countLimit)
                    continue;

                $phArray[$joinKey]['favicon'] = $feed->get_favicon();
                $phArray[$joinKey]['link'] = $item->get_link();
                $phArray[$joinKey]['title'] = $item->get_title();
                $phArray[$joinKey]['description'] = $item->get_description();
                $phArray[$joinKey]['content'] = $item->get_content();

                $phArray[$joinKey]['permalink'] = $item->get_permalink();
                $parsedUrl = parse_url($phArray[$joinKey]['permalink']);
                $implodedParsedUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'];
                $imageLink = $feed->get_image_link() != '' ? $feed->get_image_link() : $implodedParsedUrl;
                $phArray[$joinKey]['imageLink'] = $imageLink;

                $phArray[$joinKey]['imageTitle'] = $feed->get_image_title();
                $phArray[$joinKey]['imageUrl'] = $feed->get_image_url();
                $phArray[$joinKey]['imageWidth'] = $feed->get_image_width();
                $phArray[$joinKey]['imageHeight'] = $feed->get_image_height();

                $phArray[$joinKey]['date'] = $item->get_date($spie['dateFormat']);
                $phArray[$joinKey]['localDate'] = $item->get_local_date($spie['localDateFormat']);
                $phArray[$joinKey]['copyright'] = $item->get_copyright();

                $phArray[$joinKey]['latitude'] = $feed->get_latitude();
                $phArray[$joinKey]['longitude'] = $feed->get_longitude();

                $phArray[$joinKey]['language'] = $feed->get_language();
                $phArray[$joinKey]['encoding'] = $feed->get_encoding();

                if ($item->get_authors()) {
                    foreach ($item->get_authors() as $authorObject) {
                        $authorName = $authorObject->get_name();
                        $authorLink = $authorObject->get_link();
                        $authorEmail = $authorObject->get_email();
                    }
                    $phArray[$joinKey]['authorName'] = $authorName;
                    $phArray[$joinKey]['authorLink'] = $authorLink;
                    $phArray[$joinKey]['authorEmail'] = $authorEmail;
                }

                $category = $item->get_category();
                if ($category) {
                    $phArray[$joinKey]['category'] = htmlspecialchars_decode($category->get_label(), ENT_QUOTES);
                }

                $contributor = $item->get_contributor();
                $phArray[$joinKey]['contributor'] = '';
                if ($contributor) {
                    $phArray[$joinKey]['contributor'] = $contributor->get_name();
                }

                if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) {
                    $phArray[$joinKey]['getType'] = 'Unknown';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) {
                    $phArray[$joinKey]['getType'] = 'RSS';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) {
                    $phArray[$joinKey]['getType'] = 'Atom';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) {
                    $phArray[$joinKey]['getType'] = 'Supported';
                }
				
				// Media from Flickr RSS stream
				if ($enclosure = $item->get_enclosure()) {
						$phArray[$joinKey]['itemImageThumbnailUrl'] = $enclosure->get_thumbnail();
						$phArray[$joinKey]['itemImageWidth'] = $enclosure->get_width();
						$phArray[$joinKey]['itemImageHeight'] = $enclosure->get_height();
				}
				

                $countLimit++;
                $joinKey++;
            } // foreach ($feed->get_items($getItemStart, $getItemEnd) as $item)
        } // foreach ($spie['setFeedUrl'] as $setFeedUrl)
        return $this->_filterModxTags($phArray);
    }