Пример #1
0
 function subscribe($args)
 {
     $ret = $this->validate($args);
     if (is_array($ret)) {
         // Success
         // The remaining params are feed URLs
         foreach ($args as $arg) {
             $finder = new FeedFinder($arg, false, 1);
             $feeds = array_values(array_unique($finder->find()));
             if (count($feeds) > 0) {
                 $link_id = FeedWordPress::syndicate_link(feedwordpress_display_url($feeds[0]), $feeds[0], $feeds[0]);
                 $ret[] = array('added', $feeds[0], $arg);
             } else {
                 $ret[] = array('error', $arg);
             }
         }
     }
     return $ret;
 }
 function find($uri = NULL)
 {
     $ret = array();
     if (!is_null($this->data($uri))) {
         if ($this->is_feed($uri)) {
             $href = array($this->uri);
         } else {
             // Assume that we have HTML or XHTML (even if we don't, who's it gonna hurt?)
             // Autodiscovery is the preferred method
             $href = $this->_link_rel_feeds();
             // ... but we'll also take the little orange buttons
             $href = array_merge($href, $this->_a_href_feeds(TRUE));
             // If all that failed, look harder
             if (count($href) == 0) {
                 $href = $this->_a_href_feeds(FALSE);
             }
             // Our search may turn up duplicate URIs. We only need to do any given URI once.
             // Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
             $href = array_unique($href);
         }
         /* if */
         // Try some clever URL little tricks before we go
         $href = array_merge($href, $this->_url_manipulation_feeds());
         $href = array_unique($href);
         // Verify feeds and resolve relative URIs
         foreach ($href as $u) {
             $the_uri = SimplePie_Misc::absolutize_url($u, $this->uri);
             if ($this->verify and ($u != $this->uri and $the_uri != $this->uri)) {
                 $feed = new FeedFinder($the_uri);
                 if ($feed->is_feed()) {
                     $ret[] = $the_uri;
                 }
                 unset($feed);
             } else {
                 $ret[] = $the_uri;
             }
         }
         /* foreach */
     }
     /* if */
     return array_values($ret);
 }
    function multiadd_box($page, $box = NULL)
    {
        global $fwp_post;
        $localData = NULL;
        if (isset($_FILES['opml_upload']['name']) and strlen($_FILES['opml_upload']['name']) > 0) {
            $in = 'tag:localhost';
            /*FIXME: check whether $_FILES['opml_upload']['error'] === UPLOAD_ERR_OK or not...*/
            $localData = file_get_contents($_FILES['opml_upload']['tmp_name']);
            $merge_all = true;
        } elseif (isset($fwp_post['multilookup'])) {
            $in = $fwp_post['multilookup'];
            $merge_all = false;
        } elseif (isset($fwp_post['opml_lookup'])) {
            $in = $fwp_post['opml_lookup'];
            $merge_all = true;
        } else {
            $in = '';
            $merge_all = false;
        }
        if (strlen($in) > 0) {
            $lines = preg_split("/\\s+/", $in, -1, PREG_SPLIT_NO_EMPTY);
            $i = 0;
            ?>
			<form id="multiadd-form" action="<?php 
            print $this->form_action();
            ?>
" method="post">
			<div><?php 
            FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
            ?>
			<input type="hidden" name="multiadd" value="<?php 
            print FWP_SYNDICATE_NEW;
            ?>
" />
			<input type="hidden" name="confirm" value="multiadd" />

			<input type="hidden" name="multiadd" value="<?php 
            print FWP_SYNDICATE_NEW;
            ?>
" />
			<input type="hidden" name="confirm" value="multiadd" /></div>

			<div id="multiadd-status">
			<p><img src="<?php 
            print esc_url(admin_url('images/wpspin_light.gif'));
            ?>
" alt="" />
			Looking up feed information...</p>
			</div>

			<div id="multiadd-buttons">
			<input type="submit" class="button" name="cancel" value="<?php 
            _e(FWP_CANCEL_BUTTON);
            ?>
" />
			<input type="submit" class="button-primary" value="<?php 
            print _e('Subscribe to selected sources →');
            ?>
" />
			</div>
			
			<p><?php 
            _e('Here are the feeds that FeedWordPress has discovered from the addresses that you provided. To opt out of a subscription, unmark the checkbox next to the feed.');
            ?>
</p>
			
			<?php 
            print "<ul id=\"multiadd-list\">\n";
            flush();
            foreach ($lines as $line) {
                $url = trim($line);
                if (strlen($url) > 0) {
                    // First, use FeedFinder to check the URL.
                    if (is_null($localData)) {
                        $finder = new FeedFinder($url, false, 1);
                    } else {
                        $finder = new FeedFinder('tag:localhost', false, 1);
                        $finder->upload_data($localData);
                    }
                    $feeds = array_values(array_unique($finder->find()));
                    $found = false;
                    if (count($feeds) > 0) {
                        foreach ($feeds as $feed) {
                            $pie = FeedWordPress::fetch($feed);
                            if (!is_wp_error($pie)) {
                                $found = true;
                                $short_feed = esc_html(feedwordpress_display_url($feed));
                                $feed = esc_html($feed);
                                $title = esc_html($pie->get_title());
                                $checked = ' checked="checked"';
                                $link = esc_html($pie->get_link());
                                $this->display_multiadd_line(array('feed' => $feed, 'title' => $pie->get_title(), 'link' => $pie->get_link(), 'checked' => ' checked="checked"', 'i' => $i));
                                $i++;
                                // Increment field counter
                                if (!$merge_all) {
                                    // Break out after first find
                                    break;
                                }
                            }
                        }
                    }
                    if (!$found) {
                        $this->display_multiadd_line(array('feed' => $url, 'title' => feedwordpress_display_url($url), 'extra' => " [FeedWordPress couldn't detect any feeds for this URL.]", 'link' => NULL, 'checked' => '', 'i' => $i));
                        $i++;
                        // Increment field counter
                    }
                }
            }
            print "</ul>\n";
            ?>
			</form>
			
			<script type="text/javascript">
				jQuery(document).ready( function () {
					// Hide it now that we're done.
					jQuery('#multiadd-status').fadeOut(500 /*ms*/);
				} );
			</script>
			<?php 
        }
        $this->_sources = NULL;
        // Force reload of sources list
        return true;
        // Continue
    }
Пример #4
0
 function find($uri = NULL, $params = array())
 {
     $params = wp_parse_args($params, array("authentication" => -1, "username" => NULL, "password" => NULL));
     // Equivalents
     if ($params['authentication'] == '-') {
         $params['authentication'] = NULL;
         $params['username'] = NULL;
         $params['password'] = NULL;
     }
     // Set/reset
     if ($params['authentication'] != -1) {
         $this->credentials = array("authentication" => $params['authentication'], "username" => $params['username'], "password" => $params['password']);
     }
     $ret = array();
     if (!is_null($this->data($uri))) {
         if ($this->is_opml($uri)) {
             $href = $this->_opml_rss_uris();
         } else {
             if ($this->is_feed($uri)) {
                 $href = array($this->uri);
             } else {
                 // Assume that we have HTML or XHTML (even if we don't, who's
                 // it gonna hurt?) Autodiscovery is the preferred method.
                 $href = $this->_link_rel_feeds();
                 // ... but we'll also take the little orange buttons
                 if ($this->fallbacks > 0) {
                     $href = array_merge($href, $this->_a_href_feeds(TRUE));
                 }
                 // If all that failed, look harder
                 if ($this->fallbacks > 1) {
                     if (count($href) == 0) {
                         $href = $this->_a_href_feeds(FALSE);
                     }
                 }
                 // Our search may turn up duplicate URIs. We only need to do
                 // any given URI once. Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
                 $href = array_unique($href);
             }
             // Try some clever URL little tricks before we go
             if ($this->fallbacks > 2) {
                 $href = array_merge($href, $this->_url_manipulation_feeds());
             }
         }
         $href = array_unique($href);
         // Verify feeds and resolve relative URIs
         foreach ($href as $u) {
             $the_uri = SimplePie_Misc::absolutize_url($u, $this->uri);
             if ($this->verify and ($u != $this->uri and $the_uri != $this->uri)) {
                 $feed = new FeedFinder($the_uri, $this->credentials);
                 if ($feed->is_feed()) {
                     $ret[] = $the_uri;
                 }
                 unset($feed);
             } else {
                 $ret[] = $the_uri;
             }
         }
     }
     if ($this->is_401($uri)) {
         $ret = array_merge(array(new WP_Error('http_request_failed', '401 Not authorized', array("uri" => $this->uri, "status" => 401))), $ret);
     }
     return array_values($ret);
 }
    $temp_path = $config->getDefault("application.tmp_path", "/opt/crawler/tmp");
    $basename = uniqid() . ".html";
    $filename = $temp_path . "/" . $basename;
    write_file($filename, $content);
    print $basename;
    exit;
}
if ($action == "scanrss") {
    if (isset($_POST["url"])) {
        $url = $_POST["url"];
    } else {
        print "invalid url !";
        exit;
    }
    $ret = "";
    $ff = new FeedFinder();
    $proxy_host = $config->get("proxy.host");
    $proxy_port = $config->get("proxy.port");
    if ($proxy_host != undefined && $proxy_port != undefined) {
        $proxy_exclude = $config->get("proxy.exclude");
        if ($proxy_exclude == "undefined") {
            $proxy_exclude = "";
        }
        $proxy_user = $config->get("proxy.username");
        if ($proxy_user == "undefined") {
            $proxy_user = "";
        }
        $proxy_passwd = $config->get("proxy.password");
        if ($proxy_passwd == "undefined") {
            $proxy_passwd = "";
        }