SimplePie::subscribe_url PHP Method

subscribe_url() public method

When the 'permanent' mode is enabled, returns the original feed URL, except in the case of an HTTP 301 Moved Permanently status response, in which case the location of the first redirection is returned. When the 'permanent' mode is disabled (default), may or may not be different from the URL passed to {@see \set_feed_url()}, depending on whether auto-discovery was used.
public subscribe_url ( boolean $permanent = false ) : string | null
$permanent boolean Permanent mode to return only the original URL or the first redirection iff it is a 301 redirection
return string | null
    public function subscribe_url($permanent = false)
    {
        if ($permanent) {
            if ($this->permanent_url !== null) {
                // sanitize encodes ampersands which are required when used in a url.
                return str_replace('&', '&', $this->sanitize($this->permanent_url, SIMPLEPIE_CONSTRUCT_IRI));
            }
        } else {
            if ($this->feed_url !== null) {
                return str_replace('&', '&', $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI));
            }
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * Add a new feed to the database
  *
  * Adds the specified feed name and URL to the database. If no name is set
  * by the user, it fetches one from the feed. If the URL specified is a HTML
  * page and not a feed, it lets SimplePie do autodiscovery and uses the XML
  * url returned.
  *
  * @since 1.0
  *
  * @param string $url URL to feed or website (if autodiscovering)
  * @param string $name Title/Name of feed
  * @param string $cat Category to add feed to
  * @return bool True if succeeded, false if failed
  */
 public function add($url, $name = '', $cat = 'default')
 {
     if (empty($url)) {
         throw new Exception(_r("Couldn't add feed: No feed URL supplied"), Errors::get_code('admin.feeds.no_url'));
     }
     if (!preg_match('#https|http|feed#', $url)) {
         if (strpos($url, '://')) {
             throw new Exception(_r('Unsupported URL protocol'), Errors::get_code('admin.feeds.protocol_error'));
         }
         $url = 'http://' . $url;
     }
     require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc';
     $feed_info = new SimplePie();
     $feed_info->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD);
     $feed_info->set_stupidly_fast(true);
     $feed_info->set_cache_location(get_option('cachedir'));
     $feed_info->set_favicon_handler(get_option('baseurl') . '/lilina-favicon.php');
     $feed_info->set_feed_url($url);
     $feed_info->init();
     $feed_error = $feed_info->error();
     $feed_url = $feed_info->subscribe_url();
     if (!empty($feed_error)) {
         throw new Exception(sprintf(_r("Couldn't add feed: %s is not a valid URL or the server could not be accessed. Additionally, no feeds could be found by autodiscovery."), $url), Errors::get_code('admin.feeds.invalid_url'));
     }
     if (empty($name)) {
         //Get it from the feed
         $name = $feed_info->get_title();
     }
     $id = sha1($feed_url);
     $this->feeds[$id] = array('feed' => $feed_url, 'url' => $feed_info->get_link(), 'id' => $id, 'name' => $name, 'cat' => $cat, 'icon' => $feed_info->get_favicon());
     $this->feeds[$id] = apply_filters('feed-create', $this->feeds[$id], $url);
     $this->save();
     return array('msg' => sprintf(_r('Added feed "%1$s"'), $name), 'id' => $id);
 }
All Usage Examples Of SimplePie::subscribe_url