Пример #1
0
 /**
  *  Attempt to turn a relative URI into an absolute URI
  */
 protected function absolutiseUri($link, $uri = null)
 {
     $linkUri = Uri::factory($link);
     if (!$linkUri->isAbsolute() or !$linkUri->isValid()) {
         if ($uri !== null) {
             $uri = Uri::factory($uri);
             if ($link[0] !== '/') {
                 $link = $uri->getPath() . '/' . $link;
             }
             $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->canonicalizePath($link);
             if (!Uri::factory($link)->isValid()) {
                 $link = null;
             }
         }
     }
     return $link;
 }
Пример #2
0
 /**
  * Adds an enclosure to the entry. The array parameter may contain the
  * keys 'uri', 'type' and 'length'. Only 'uri' is required for Atom, though the
  * others must also be provided or RSS rendering (where they are required)
  * will throw an Exception.
  *
  * @param array $enclosure
  * @throws Exception\InvalidArgumentException
  * @return Entry
  */
 public function setEnclosure(array $enclosure)
 {
     if (!isset($enclosure['uri'])) {
         throw new Exception\InvalidArgumentException('Enclosure "uri" is not set');
     }
     if (!Uri::factory($enclosure['uri'])->isValid()) {
         throw new Exception\InvalidArgumentException('Enclosure "uri" is not a valid URI/IRI');
     }
     $this->data['enclosure'] = $enclosure;
     return $this;
 }
Пример #3
0
 /**
  * Add a feed category
  *
  * @param array $category
  * @throws Exception\InvalidArgumentException
  * @return AbstractFeed
  */
 public function addCategory(array $category)
 {
     if (!isset($category['term'])) {
         throw new Exception\InvalidArgumentException('Each category must be an array and ' . 'contain at least a "term" element containing the machine ' . ' readable category name');
     }
     if (isset($category['scheme'])) {
         if (empty($category['scheme']) || !is_string($category['scheme']) || !Uri::factory($category['scheme'])->isValid()) {
             throw new Exception\InvalidArgumentException('The Atom scheme or RSS domain of' . ' a category must be a valid URI');
         }
     }
     if (!isset($this->data['categories'])) {
         $this->data['categories'] = array();
     }
     $this->data['categories'][] = $category;
     return $this;
 }
Пример #4
0
 /**
  *  Attempt to absolutise the URI, i.e. if a relative URI apply the
  *  xml:base value as a prefix to turn into an absolute URI.
  *
  * @param $link
  * @return string
  */
 protected function absolutiseUri($link)
 {
     if (!Uri::factory($link)->isAbsolute()) {
         if ($this->getBaseUrl() !== null) {
             $link = $this->getBaseUrl() . $link;
             if (!Uri::factory($link)->isValid()) {
                 $link = null;
             }
         }
     }
     return $link;
 }
Пример #5
0
 /**
  * Set entry identifier
  *
  * @param  DOMDocument $dom
  * @param  DOMElement $root
  * @return void
  * @throws Writer\Exception\InvalidArgumentException
  */
 protected function _setId(DOMDocument $dom, DOMElement $root)
 {
     if (!$this->getDataContainer()->getId() && !$this->getDataContainer()->getLink()) {
         $message = 'Atom 1.0 entry elements MUST contain exactly one ' . 'atom:id element, or as an alternative, we can use the same ' . 'value as atom:link however neither a suitable link nor an ' . 'id have been set';
         $exception = new Writer\Exception\InvalidArgumentException($message);
         if (!$this->ignoreExceptions) {
             throw $exception;
         } else {
             $this->exceptions[] = $exception;
             return;
         }
     }
     if (!$this->getDataContainer()->getId()) {
         $this->getDataContainer()->setId($this->getDataContainer()->getLink());
     }
     if (!Uri::factory($this->getDataContainer()->getId())->isValid() && !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\\-]{1,31}:([a-zA-Z0-9\\(\\)\\+\\,\\.\\:\\=\\@\\;\$\\_\\!\\*\\-]|%[0-9a-fA-F]{2})*#", $this->getDataContainer()->getId()) && !$this->_validateTagUri($this->getDataContainer()->getId())) {
         throw new Writer\Exception\InvalidArgumentException('Atom 1.0 IDs must be a valid URI/IRI');
     }
     $id = $dom->createElement('id');
     $root->appendChild($id);
     $text = $dom->createTextNode($this->getDataContainer()->getId());
     $id->appendChild($text);
 }
Пример #6
0
 /**
  * Set entry identifier
  *
  * @param  DOMDocument $dom
  * @param  DOMElement $root
  * @return void
  */
 protected function _setId(DOMDocument $dom, DOMElement $root)
 {
     if (!$this->getDataContainer()->getId() && !$this->getDataContainer()->getLink()) {
         return;
     }
     $id = $dom->createElement('guid');
     $root->appendChild($id);
     if (!$this->getDataContainer()->getId()) {
         $this->getDataContainer()->setId($this->getDataContainer()->getLink());
     }
     $text = $dom->createTextNode($this->getDataContainer()->getId());
     $id->appendChild($text);
     if (!Uri::factory($this->getDataContainer()->getId())->isValid()) {
         $id->setAttribute('isPermaLink', 'false');
     }
 }
Пример #7
0
 /**
  * Set by
  *
  * @param array $by
  * @throws Exception\InvalidArgumentException
  * @return Deleted
  */
 public function setBy(array $by)
 {
     $author = array();
     if (!array_key_exists('name', $by) || empty($by['name']) || !is_string($by['name'])) {
         throw new Exception\InvalidArgumentException('Invalid parameter: author array must include a' . ' "name" key with a non-empty string value');
     }
     $author['name'] = $by['name'];
     if (isset($by['email'])) {
         if (empty($by['email']) || !is_string($by['email'])) {
             throw new Exception\InvalidArgumentException('Invalid parameter: "email" array' . ' value must be a non-empty string');
         }
         $author['email'] = $by['email'];
     }
     if (isset($by['uri'])) {
         if (empty($by['uri']) || !is_string($by['uri']) || !Uri::factory($by['uri'])->isValid()) {
             throw new Exception\InvalidArgumentException('Invalid parameter: "uri" array value must' . ' be a non-empty string and valid URI/IRI');
         }
         $author['uri'] = $by['uri'];
     }
     $this->data['by'] = $author;
     return $this;
 }
Пример #8
0
 /**
  * Checks validity of the request simply by making a quick pass and
  * confirming the presence of all REQUIRED parameters.
  *
  * @param  array $httpGetData
  * @return bool
  */
 public function isValidHubVerification(array $httpGetData)
 {
     /**
      * As per the specification, the hub.verify_token is OPTIONAL. This
      * implementation of Pubsubhubbub considers it REQUIRED and will
      * always send a hub.verify_token parameter to be echoed back
      * by the Hub Server. Therefore, its absence is considered invalid.
      */
     if (strtolower($_SERVER['REQUEST_METHOD']) !== 'get') {
         return false;
     }
     $required = ['hub_mode', 'hub_topic', 'hub_challenge', 'hub_verify_token'];
     foreach ($required as $key) {
         if (!array_key_exists($key, $httpGetData)) {
             return false;
         }
     }
     if ($httpGetData['hub_mode'] !== 'subscribe' && $httpGetData['hub_mode'] !== 'unsubscribe') {
         return false;
     }
     if ($httpGetData['hub_mode'] == 'subscribe' && !array_key_exists('hub_lease_seconds', $httpGetData)) {
         return false;
     }
     if (!Uri::factory($httpGetData['hub_topic'])->isValid()) {
         return false;
     }
     /**
      * Attempt to retrieve any Verification Token Key attached to Callback
      * URL's path by our Subscriber implementation
      */
     if (!$this->_hasValidVerifyToken($httpGetData)) {
         return false;
     }
     return true;
 }
Пример #9
0
 /**
  * Notifies a single Hub Server URL of changes
  *
  * @param  string $url The Hub Server's URL
  * @return void
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function notifyHub($url)
 {
     if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) {
         throw new Exception\InvalidArgumentException('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . 'URL');
     }
     $client = $this->_getHttpClient();
     $client->setUri($url);
     $response = $client->getResponse();
     if ($response->getStatusCode() !== 204) {
         throw new Exception\RuntimeException('Notification to Hub Server ' . 'at "' . $url . '" appears to have failed with a status code of "' . $response->getStatusCode() . '" and message "' . $response->getContent() . '"');
     }
 }
Пример #10
0
 /**
  * Set new feed URL
  *
  * @param  string $value
  * @return Feed
  * @throws Writer\Exception\InvalidArgumentException
  */
 public function setItunesNewFeedUrl($value)
 {
     if (!Uri::factory($value)->isValid()) {
         throw new Writer\Exception\InvalidArgumentException('invalid parameter: "newFeedUrl" may only' . ' be a valid URI/IRI');
     }
     $this->data['newFeedUrl'] = $value;
     return $this;
 }
Пример #11
0
 /**
  * Add authentication credentials for a given URL
  *
  * @param  string $url
  * @param  array $authentication
  * @return Subscriber
  * @throws Exception\InvalidArgumentException
  */
 public function addAuthentication($url, array $authentication)
 {
     if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) {
         throw new Exception\InvalidArgumentException('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . ' URL');
     }
     $this->authentications[$url] = $authentication;
     return $this;
 }
Пример #12
0
 /**
  * Set feed channel image
  *
  * @param  DOMDocument $dom
  * @param  DOMElement $root
  * @return void
  * @throws Writer\Exception\InvalidArgumentException
  */
 protected function _setImage(DOMDocument $dom, DOMElement $root)
 {
     $image = $this->getDataContainer()->getImage();
     if (!$image) {
         return;
     }
     if (!isset($image['title']) || empty($image['title']) || !is_string($image['title'])) {
         $message = 'RSS 2.0 feed images must include a title';
         $exception = new Writer\Exception\InvalidArgumentException($message);
         if (!$this->ignoreExceptions) {
             throw $exception;
         } else {
             $this->exceptions[] = $exception;
             return;
         }
     }
     if (empty($image['link']) || !is_string($image['link']) || !Uri::factory($image['link'])->isValid()) {
         $message = 'Invalid parameter: parameter \'link\'' . ' must be a non-empty string and valid URI/IRI';
         $exception = new Writer\Exception\InvalidArgumentException($message);
         if (!$this->ignoreExceptions) {
             throw $exception;
         } else {
             $this->exceptions[] = $exception;
             return;
         }
     }
     $img = $dom->createElement('image');
     $root->appendChild($img);
     $url = $dom->createElement('url');
     $text = $dom->createTextNode($image['uri']);
     $url->appendChild($text);
     $title = $dom->createElement('title');
     $text = $dom->createTextNode($image['title']);
     $title->appendChild($text);
     $link = $dom->createElement('link');
     $text = $dom->createTextNode($image['link']);
     $link->appendChild($text);
     $img->appendChild($url);
     $img->appendChild($title);
     $img->appendChild($link);
     if (isset($image['height'])) {
         if (!ctype_digit((string) $image['height']) || $image['height'] > 400) {
             $message = 'Invalid parameter: parameter \'height\'' . ' must be an integer not exceeding 400';
             $exception = new Writer\Exception\InvalidArgumentException($message);
             if (!$this->ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->exceptions[] = $exception;
                 return;
             }
         }
         $height = $dom->createElement('height');
         $text = $dom->createTextNode($image['height']);
         $height->appendChild($text);
         $img->appendChild($height);
     }
     if (isset($image['width'])) {
         if (!ctype_digit((string) $image['width']) || $image['width'] > 144) {
             $message = 'Invalid parameter: parameter \'width\'' . ' must be an integer not exceeding 144';
             $exception = new Writer\Exception\InvalidArgumentException($message);
             if (!$this->ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->exceptions[] = $exception;
                 return;
             }
         }
         $width = $dom->createElement('width');
         $text = $dom->createTextNode($image['width']);
         $width->appendChild($text);
         $img->appendChild($width);
     }
     if (isset($image['description'])) {
         if (empty($image['description']) || !is_string($image['description'])) {
             $message = 'Invalid parameter: parameter \'description\'' . ' must be a non-empty string';
             $exception = new Writer\Exception\InvalidArgumentException($message);
             if (!$this->ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->exceptions[] = $exception;
                 return;
             }
         }
         $desc = $dom->createElement('description');
         $text = $dom->createTextNode($image['description']);
         $desc->appendChild($text);
         $img->appendChild($desc);
     }
 }
Пример #13
0
 /**
  * Add a link
  *
  * @param string $url  the url of the link
  * @param string $role the role of the link
  * @param string $type the mime type of the link
  *
  * @return Feed
  */
 public function addOpensearchLink($url, $role = null, $type = null)
 {
     if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) {
         throw new Exception\InvalidArgumentException('Invalid parameter: "url" must be ' . 'a non-empty string and valid URI/IRI');
     }
     if (!in_array(strtolower($type), ['rss', 'rdf', 'atom'])) {
         throw new Exception\InvalidArgumentException('Invalid parameter: "type"; You must declare the type of ' . 'feed the link points to, i.e. RSS, RDF or Atom');
     }
     $link = [];
     $link['url'] = $url;
     $link['role'] = $role;
     $link['type'] = $type;
     $this->links[] = $link;
     return $this;
 }