FeedFinder::find PHP Метод

find() публичный Метод

public find ( $uri = NULL, $params = [] )
    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);
    }

Usage Example

Пример #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;
 }
All Usage Examples Of FeedFinder::find