/** * Attempt to turn a relative URI into an absolute URI */ protected function _absolutiseUri($link, $uri = null) { if (!URI\URL::validate($link)) { if (!is_null($uri)) { $uri = new URI\URL($uri); if ($link[0] !== '/') { $link = $uri->getPath() . '/' . $link; } $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link); if (!URI\Zend\Uri\Uri::check($link)) { $link = null; } } } return $link; }
/** * 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 = array('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 (!\Zend\URI\URL::validate($httpGetData['hub_topic'])) { 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; }
/** * Set new feed URL * * @param string $value * @return \Zend\Feed\Writer\Extension\ITunes\Feed */ public function setItunesNewFeedUrl($value) { if (!\Zend\URI\URL::validate($value)) { throw new \Zend\Feed\Exception('invalid parameter: "newFeedUrl" may only' . ' be a valid URI/IRI'); } $this->_data['newFeedUrl'] = $value; return $this; }
/** * 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()) { $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($message); if (!$this->_ignoreExceptions) { throw $exception; } else { $this->_exceptions[] = $exception; return; } } if (!$this->getDataContainer()->getId()) { $this->getDataContainer()->setId($this->getDataContainer()->getLink()); } if (!URI\URL::validate($this->getDataContainer()->getId()) && !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 Exception('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); }
/** * 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 (!\Zend\URI\URL::validate($this->getDataContainer()->getId())) { $id->setAttribute('isPermaLink', 'false'); } }
public function setBy(array $by) { $author = array(); if (!array_key_exists('name', $by) || empty($by['name']) || !is_string($by['name'])) { throw new Feed\Exception('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 Feed\Exception('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']) || !\Zend\URI\URL::validate($by['uri'])) { throw new Feed\Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'); } $author['uri'] = $by['uri']; } $this->_data['by'] = $author; }
/** * Add a URL to a topic (Atom or RSS feed) which has been updated * * @param string $url * @return \Zend\Feed\PubSubHubbub\Publisher */ public function addUpdatedTopicUrl($url) { if (empty($url) || !is_string($url) || !\Zend\URI\URL::validate($url)) { throw new Exception('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . 'URL'); } $this->_updatedTopicUrls[] = $url; return $this; }
/** * 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. */ protected function _absolutiseUri($link) { if (!\Zend\URI\URL::validate($link)) { if (!is_null($this->getBaseUrl())) { $link = $this->getBaseUrl() . $link; if (!\Zend\URI\URL::validate($link)) { $link = null; } } } return $link; }
/** * Set link to feed * * @param DOMDocument $dom * @param DOMElement $root * @return void */ protected function _setLink(\DOMDocument $dom, \DOMElement $root) { $value = $this->getDataContainer()->getLink(); if (!$value) { $message = 'RSS 2.0 feed elements MUST contain exactly one' . ' link element but one has not been set'; $exception = new Feed\Exception($message); if (!$this->_ignoreExceptions) { throw $exception; } else { $this->_exceptions[] = $exception; return; } } $link = $dom->createElement('link'); $root->appendChild($link); $text = $dom->createTextNode($value); $link->appendChild($text); if (!\Zend\URI\URL::validate($value)) { $link->setAttribute('isPermaLink', 'false'); } }
/** * Adds an enclosure to the entry. * * @param array $enclosures */ public function setEnclosure(array $enclosure) { if (!isset($enclosure['type'])) { throw new Feed\Exception('Enclosure "type" is not set'); } if (!isset($enclosure['length'])) { throw new Feed\Exception('Enclosure "length" is not set'); } if (!isset($enclosure['uri'])) { throw new Feed\Exception('Enclosure "uri" is not set'); } if (!\Zend\URI\URL::validate($enclosure['uri'])) { throw new Feed\Exception('Enclosure "uri" is not a valid URI/IRI'); } if ((int) $enclosure['length'] <= 0) { throw new Feed\Exception('Enclosure "length" must be an integer' . ' indicating the content\'s length in bytes'); } $this->_data['enclosure'] = $enclosure; }