Warning, file /webapps/ocs-webserver/library/Zend/Service/Delicious/Post.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Service
0018  * @subpackage Delicious
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 
0025 /**
0026  * @see Zend_Date
0027  */
0028 // require_once 'Zend/Date.php';
0029 
0030 /**
0031  * @see Zend_Service_Delicious_SimplePost
0032  */
0033 // require_once 'Zend/Service/Delicious/SimplePost.php';
0034 
0035 
0036 /**
0037  * Zend_Service_Delicious_Post represents a post of a user that can be edited
0038  *
0039  * @category   Zend
0040  * @package    Zend_Service
0041  * @subpackage Delicious
0042  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0043  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0044  */
0045 class Zend_Service_Delicious_Post extends Zend_Service_Delicious_SimplePost
0046 {
0047     /**
0048      * Service that has downloaded the post
0049      *
0050      * @var Zend_Service_Delicious
0051      */
0052     protected $_service;
0053 
0054     /**
0055      * @var int Number of people that have the same post
0056      */
0057     protected $_others;
0058 
0059     /**
0060      * @var Zend_Date Post date
0061      */
0062     protected $_date;
0063 
0064     /**
0065      * @var bool Post share
0066      */
0067     protected $_shared = true;
0068 
0069     /**
0070      * @var string Post hash
0071      */
0072     protected $_hash;
0073 
0074     /**
0075      * Constructs a new del.icio.us post
0076      *
0077      * @param  Zend_Service_Delicious $service Service that has downloaded the post
0078      * @param  DOMElement|array       $values  Post content
0079      * @throws Zend_Service_Delicious_Exception
0080      * @return void
0081      */
0082     public function __construct(Zend_Service_Delicious $service, $values)
0083     {
0084         $this->_service = $service;
0085 
0086         if ($values instanceof DOMElement) {
0087             $values = self::_parsePostNode($values);
0088         }
0089 
0090         if (!is_array($values) || !isset($values['url']) || !isset($values['title'])) {
0091             /**
0092              * @see Zend_Service_Delicious_Exception
0093              */
0094             // require_once 'Zend/Service/Delicious/Exception.php';
0095             throw new Zend_Service_Delicious_Exception("Second argument must be array with at least 2 keys ('url' and"
0096                                                      . " 'title')");
0097         }
0098 
0099         if (isset($values['date']) && ! $values['date'] instanceof Zend_Date) {
0100             /**
0101              * @see Zend_Service_Delicious_Exception
0102              */
0103             // require_once 'Zend/Service/Delicious/Exception.php';
0104             throw new Zend_Service_Delicious_Exception("Date has to be an instance of Zend_Date");
0105         }
0106 
0107         foreach (array('url', 'title', 'notes', 'others', 'tags', 'date', 'shared', 'hash') as $key) {
0108             if (isset($values[$key])) {
0109                 $this->{"_$key"}  = $values[$key];
0110             }
0111         }
0112     }
0113 
0114     /**
0115      * Setter for title
0116      *
0117      * @param  string $newTitle
0118      * @return Zend_Service_Delicious_Post
0119      */
0120     public function setTitle($newTitle)
0121     {
0122         $this->_title = (string) $newTitle;
0123 
0124         return $this;
0125     }
0126 
0127     /**
0128      * Setter for notes
0129      *
0130      * @param  string $newNotes
0131      * @return Zend_Service_Delicious_Post
0132      */
0133     public function setNotes($newNotes)
0134     {
0135         $this->_notes = (string) $newNotes;
0136 
0137         return $this;
0138     }
0139 
0140     /**
0141      * Setter for tags
0142      *
0143      * @param  array $tags
0144      * @return Zend_Service_Delicious_Post
0145      */
0146     public function setTags(array $tags)
0147     {
0148         $this->_tags = $tags;
0149 
0150         return $this;
0151     }
0152 
0153     /**
0154      * Add a tag
0155      *
0156      * @param  string $tag
0157      * @return Zend_Service_Delicious_Post
0158      */
0159     public function addTag($tag)
0160     {
0161         $this->_tags[] = (string) $tag;
0162 
0163         return $this;
0164     }
0165 
0166     /**
0167      * Remove a tag
0168      *
0169      * @param  string $tag
0170      * @return Zend_Service_Delicious_Post
0171      */
0172     public function removeTag($tag)
0173     {
0174         $this->_tags = array_diff($this->_tags, array((string) $tag));
0175 
0176         return $this;
0177     }
0178 
0179     /**
0180      * Getter for date
0181      *
0182      * @return Zend_Date
0183      */
0184     public function getDate()
0185     {
0186         return $this->_date;
0187     }
0188 
0189     /**
0190      * Getter for others
0191      *
0192      * This property is only populated when posts are retrieved
0193      * with getPosts() method. The getAllPosts() and getRecentPosts()
0194      * methods will not populate this property.
0195      *
0196      * @return int
0197      */
0198     public function getOthers()
0199     {
0200         return $this->_others;
0201     }
0202 
0203     /**
0204      * Getter for hash
0205      *
0206      * @return string
0207      */
0208     public function getHash()
0209     {
0210         return $this->_hash;
0211     }
0212 
0213     /**
0214      * Getter for shared
0215      *
0216      * @return bool
0217      */
0218     public function getShared()
0219     {
0220         return $this->_shared;
0221     }
0222 
0223     /**
0224      * Setter for shared
0225      *
0226      * @param  bool $isShared
0227      * @return Zend_Service_Delicious_Post
0228      */
0229     public function setShared($isShared)
0230     {
0231         $this->_shared = (bool) $isShared;
0232 
0233         return $this;
0234     }
0235 
0236     /**
0237      * Deletes post
0238      *
0239      * @return Zend_Service_Delicious
0240      */
0241     public function delete()
0242     {
0243         return $this->_service->deletePost($this->_url);
0244     }
0245 
0246     /**
0247      * Saves post
0248      *
0249      * @return DOMDocument
0250      */
0251     public function save()
0252     {
0253         $parms = array(
0254             'url'        => $this->_url,
0255             'description'=> $this->_title,
0256             'extended'   => $this->_notes,
0257             'shared'     => ($this->_shared ? 'yes' : 'no'),
0258             'tags'       => implode(' ', (array) $this->_tags),
0259             'replace'    => 'yes'
0260         );
0261         /*
0262         if ($this->_date instanceof Zend_Date) {
0263             $parms['dt'] = $this->_date->get('Y-m-d\TH:i:s\Z');
0264         }
0265         */
0266 
0267         return $this->_service->makeRequest(Zend_Service_Delicious::PATH_POSTS_ADD, $parms);
0268     }
0269 
0270     /**
0271      * Extracts content from the DOM element of a post
0272      *
0273      * @param  DOMElement $node
0274      * @return array
0275      */
0276     protected static function _parsePostNode(DOMElement $node)
0277     {
0278         return array(
0279             'url'    => $node->getAttribute('href'),
0280             'title'  => $node->getAttribute('description'),
0281             'notes'  => $node->getAttribute('extended'),
0282             'others' => (int) $node->getAttribute('others'),
0283             'tags'   => explode(' ', $node->getAttribute('tag')),
0284             /**
0285              * @todo replace strtotime() with Zend_Date equivalent
0286              */
0287             'date'   => new Zend_Date(strtotime($node->getAttribute('time'))),
0288             'shared' => ($node->getAttribute('shared') == 'no' ? false : true),
0289             'hash'   => $node->getAttribute('hash')
0290         );
0291     }
0292 }