SimplePie::get_base PHP Method

get_base() public method

Uses if available, otherwise uses the first link in the feed, or failing that, the URL of the feed itself.
See also: get_link
See also: subscribe_url
public get_base ( array $element = [] ) : string
$element array
return string
    public function get_base($element = array())
    {
        if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) {
            return $element['xml_base'];
        } elseif ($this->get_link() !== null) {
            return $this->get_link();
        } else {
            return $this->subscribe_url();
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Find the feed's icon
  *
  * @param SimplePie $feed SimplePie object to retrieve logo for
  * @return string URL to feed icon
  */
 protected static function discover_favicon($feed, $id)
 {
     if ($return = $feed->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) {
         $favicon = SimplePie_Misc::absolutize_url($return[0]['data'], $feed->get_base($return[0]));
     } elseif (($url = $feed->get_link()) !== null && preg_match('/^http(s)?:\\/\\//i', $url)) {
         $filename = $id . '.ico';
         $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $url);
     } else {
         return false;
     }
     $cache = new DataHandler(get_option('cachedir'));
     $request = new HTTPRequest();
     $file = $request->get($favicon, array('X-Forwarded-For' => $_SERVER['REMOTE_ADDR']));
     if ($file->success && strlen($file->body) > 0) {
         $sniffer = new $feed->content_type_sniffer_class($file);
         if (substr($sniffer->get_type(), 0, 6) === 'image/') {
             $body = array('type' => $sniffer->get_type(), 'body' => $file->body);
             return $cache->save($filename, serialize($body));
         } else {
             return false;
         }
     }
     return false;
 }
All Usage Examples Of SimplePie::get_base