/**
  * 
  * @return AtomDocumentAdapterFactory
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new AtomDocumentAdapterFactory();
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 protected function _postCommentEntry($rawBody, $item)
 {
     // Get the Atom Adapter
     $entry = AtomDocumentAdapterFactory::getInstance()->adapt($rawBody);
     /* @var $entry AtomEntryAdapter */
     // Check whether the entry is an atom entry or not
     if ($entry->getDocumentType() == Atomns::ENTRY_ELEMENT) {
         $atomProcessor = new AtomProcessor();
         // Read the Entry
         $data = $atomProcessor->readCommentEntry($entry);
         if ($data['timestamp'] == '') {
             $data['timestamp'] = time();
         }
         $data['source_id'] = $item->getSource();
         $data['item_id'] = $item->getID();
         // Add new comment
         $comments = new Comments();
         $comments->setUser($this->_application->user);
         $data['id'] = $comments->addComment($data['source_id'], $data['item_id'], $data['comment'], $data['name'], $data['email'], $data['website'], $data['timestamp'], 0);
         return new Comment($data);
     } else {
         $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Invalid Data!!! Atom Entry Document is required!!');
         return false;
     }
 }
Ejemplo n.º 3
0
 protected function _putEntry($item, $rawBody)
 {
     // Get the Atom Adapter
     $entry = AtomDocumentAdapterFactory::getInstance()->adapt($rawBody);
     /* @var $entry AtomEntryAdapter */
     if ($entry->getDocumentType() == Atomns::ENTRY_ELEMENT) {
         // Read the Entry
         $atomProcessor = new AtomProcessor();
         $data = $atomProcessor->readEntry($entry);
         if ($data['published'] == '') {
             $data['published'] = $item->getTimestamp();
         }
         // Check whether the new resource has different type
         if ($data['type'] != $item->getType()) {
             $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'The updated resource has different type than the old one!!!');
             return false;
         }
         // Check whether the new resource has the same iri with the old one - it will be implemented later if the unit testing is ready (I think it works)
         //    		if ($this->_getItemIri() != $data['iri']) {
         //    			$this->_buildResponse(Api_BaseController::HTTP_FAILED, 'The updated resource has different IRI than the old one!!!');
         //    			return false;
         //    		}
         unset($data['iri']);
         // If an image (should be audio as well) and the URL was given and it is a stuffpress item, we change the image
         if ($item->getPrefix() == 'stuffpress' && ($data['type'] == SourceItem::IMAGE_TYPE && $data['type'] == SourceItem::AUDIO_TYPE) && ($url = $data['url']) && strlen($url) > 0) {
             // Check whether the url is the same as the old one - not tested yet
             if ($item->getImageUrl(ImageItem::SIZE_LARGE) != $url) {
                 $this->_deleteFileFromDb($item->getFile());
                 $key = $this->_saveFileToDb($data['type'], $url);
                 if ($key == false) {
                     return false;
                 }
                 $data['file'] = $key;
             }
         }
         return $data;
     } else {
         $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Invalid Data!!! Atom Entry Document is required!!');
         return false;
     }
 }