_service = $service; if ($values instanceof DOMElement) { $values = self::_parsePostNode($values); } if (!is_array($values) || !isset($values['url']) || !isset($values['title'])) { /** * @see Zend_Service_Delicious_Exception */ #require_once 'Zend/Service/Delicious/Exception.php'; throw new Zend_Service_Delicious_Exception("Second argument must be array with at least 2 keys ('url' and" . " 'title')"); } if (isset($values['date']) && ! $values['date'] instanceof Zend_Date) { /** * @see Zend_Service_Delicious_Exception */ #require_once 'Zend/Service/Delicious/Exception.php'; throw new Zend_Service_Delicious_Exception("Date has to be an instance of Zend_Date"); } foreach (array('url', 'title', 'notes', 'others', 'tags', 'date', 'shared', 'hash') as $key) { if (isset($values[$key])) { $this->{"_$key"} = $values[$key]; } } } /** * Setter for title * * @param string $newTitle * @return Zend_Service_Delicious_Post */ public function setTitle($newTitle) { $this->_title = (string) $newTitle; return $this; } /** * Setter for notes * * @param string $newNotes * @return Zend_Service_Delicious_Post */ public function setNotes($newNotes) { $this->_notes = (string) $newNotes; return $this; } /** * Setter for tags * * @param array $tags * @return Zend_Service_Delicious_Post */ public function setTags(array $tags) { $this->_tags = $tags; return $this; } /** * Add a tag * * @param string $tag * @return Zend_Service_Delicious_Post */ public function addTag($tag) { $this->_tags[] = (string) $tag; return $this; } /** * Remove a tag * * @param string $tag * @return Zend_Service_Delicious_Post */ public function removeTag($tag) { $this->_tags = array_diff($this->_tags, array((string) $tag)); return $this; } /** * Getter for date * * @return Zend_Date */ public function getDate() { return $this->_date; } /** * Getter for others * * This property is only populated when posts are retrieved * with getPosts() method. The getAllPosts() and getRecentPosts() * methods will not populate this property. * * @return int */ public function getOthers() { return $this->_others; } /** * Getter for hash * * @return string */ public function getHash() { return $this->_hash; } /** * Getter for shared * * @return bool */ public function getShared() { return $this->_shared; } /** * Setter for shared * * @param bool $isShared * @return Zend_Service_Delicious_Post */ public function setShared($isShared) { $this->_shared = (bool) $isShared; return $this; } /** * Deletes post * * @return Zend_Service_Delicious */ public function delete() { return $this->_service->deletePost($this->_url); } /** * Saves post * * @return DOMDocument */ public function save() { $parms = array( 'url' => $this->_url, 'description'=> $this->_title, 'extended' => $this->_notes, 'shared' => ($this->_shared ? 'yes' : 'no'), 'tags' => implode(' ', (array) $this->_tags), 'replace' => 'yes' ); /* if ($this->_date instanceof Zend_Date) { $parms['dt'] = $this->_date->get('Y-m-d\TH:i:s\Z'); } */ return $this->_service->makeRequest(Zend_Service_Delicious::PATH_POSTS_ADD, $parms); } /** * Extracts content from the DOM element of a post * * @param DOMElement $node * @return array */ protected static function _parsePostNode(DOMElement $node) { return array( 'url' => $node->getAttribute('href'), 'title' => $node->getAttribute('description'), 'notes' => $node->getAttribute('extended'), 'others' => (int) $node->getAttribute('others'), 'tags' => explode(' ', $node->getAttribute('tag')), /** * @todo replace strtotime() with Zend_Date equivalent */ 'date' => new Zend_Date(strtotime($node->getAttribute('time'))), 'shared' => ($node->getAttribute('shared') == 'no' ? false : true), 'hash' => $node->getAttribute('hash') ); } }