Beispiel #1
0
 /**
  *  Attempt to turn a relative URI into an absolute URI
  */
 protected function _absolutiseUri($link, $uri = null)
 {
     if (!Uri\Url::validate($link)) {
         if ($uri !== null) {
             $uri = new Uri\Url($uri);
             if ($link[0] !== '/') {
                 $link = $uri->getPath() . '/' . $link;
             }
             $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link);
             if (!URI\URL::validate($link)) {
                 $link = null;
             }
         }
     }
     return $link;
 }
Beispiel #2
0
 /**
  * Add a feed category
  *
  * @param string $category
  */ 
 public function addCategory(array $category)
 {
     if (!isset($category['term'])) {
         throw new Exception('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\Url::validate($category['scheme'])
         ) {
             throw new Exception('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;
 }
Beispiel #3
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.
  */
 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;
 }
Beispiel #4
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 = 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;
 }
Beispiel #5
0
 public function setBy(array $by)
 {
     $author = array();
     if (!array_key_exists('name', $by) || empty($by['name']) || !is_string($by['name'])) {
         throw new 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 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']) || !Uri\Url::validate($by['uri'])) {
             throw new Exception('Invalid parameter: "uri" array value must' . ' be a non-empty string and valid URI/IRI');
         }
         $author['uri'] = $by['uri'];
     }
     $this->_data['by'] = $author;
 }
Beispiel #6
0
 /**
  * Set feed channel image
  * 
  * @param \DOMDocument $dom 
  * @param \DOMElement $root 
  * @return void
  */
 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($message);
         if (!$this->_ignoreExceptions) {
             throw $exception;
         } else {
             $this->_exceptions[] = $exception;
             return;
         }
     }
     if (empty($image['link']) || !is_string($image['link']) || !Uri\Url::validate($image['link'])) {
         $message = 'Invalid parameter: parameter \'link\'' . ' must be a non-empty string and valid URI/IRI';
         $exception = new Writer\Exception($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($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($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($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);
     }
 }
Beispiel #7
0
 /**
  * Add a Hub Server URL supported by Publisher
  *
  * @param  string $url
  * @return \Zend\Feed\PubSubHubbub\Subscriber\Subscriber
  */
 public function addHubUrl($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->_hubUrls[] = $url;
     return $this;
 }
Beispiel #8
0
 /**
  * Notifies a single Hub Server URL of changes
  *
  * @param  string $url The Hub Server's URL
  * @return void
  * @throws \Zend\Feed\PubSubHubbub\Exception Thrown on failure
  */
 public function notifyHub($url)
 {
     if (empty($url) || !is_string($url) || !Uri\Url::validate($url)) {
         throw new Exception('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . 'URL');
     }
     $client = $this->_getHttpClient();
     $client->setUri($url);
     $response = $client->request();
     if ($response->getStatus() !== 204) {
         throw new Exception('Notification to Hub Server ' . 'at "' . $url . '" appears to have failed with a status code of "' . $response->getStatus() . '" and message "' . $response->getMessage() . '"');
     }
 }
Beispiel #9
0
 /**
  * Set new feed URL
  * 
  * @param  string $value 
  * @return Zend_Feed_Writer_Extension_ITunes_Feed
  */
 public function setItunesNewFeedUrl($value)
 {
     if (!Uri\Url::validate($value)) {
         throw new Writer\Exception('invalid parameter: "newFeedUrl" may only' . ' be a valid URI/IRI');
     }
     $this->_data['newFeedUrl'] = $value;
     return $this;
 }
Beispiel #10
0
    /**
     * Set blog URL
     *
     * @param string $blogUrl
     * @return Zend_Service_Akismet
     * @throws Zend\Service\Exception if invalid URL provided
     */
    public function setBlogUrl($blogUrl)
    {
        if (!Uri\Url::validate($blogUrl)) {
            throw new Exception\InvalidArgumentException('Invalid url provided for blog');
        }

        $this->_blogUrl = $blogUrl;
        return $this;
    }
Beispiel #11
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 $enclosures
  */
 public function setEnclosure(array $enclosure)
 {
     if (!isset($enclosure['uri'])) {
         throw new Exception('Enclosure "uri" is not set');
     }
     if (!Uri\Url::validate($enclosure['uri'])) {
         throw new Exception('Enclosure "uri" is not a valid URI/IRI');
     }
     $this->_data['enclosure'] = $enclosure;
 }