コード例 #1
0
 public function putAction()
 {
     // Get the content-type of the request
     $contentType = $this->getRequest()->getHeader('Content-Type');
     $contentType = explode(';', $contentType, 2);
     $fileType = explode('/', $contentType[0], 2);
     // Only image and audio file are supported
     if ($fileType[0] != SourceItem::IMAGE_TYPE && $fileType[0] != SourceItem::AUDIO_TYPE) {
         $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Unsupported media type');
         return;
     }
     if (!$this->_authenticateUser()) {
         return;
     }
     // Get the Item from IRI
     $item = $this->_getItemByIri($this->_getItemIri());
     if (!$this->_isItemExists($item)) {
         return;
     }
     // Only stuffpress media item can be edited
     if ($item->getPrefix() != 'stuffpress') {
         $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Uneditable media resource' . $item->getPrefix());
         return;
     }
     // Get the raw body of the request
     $rawBody = $this->getRequest()->getRawBody();
     $data = $this->_putMedia($item, $rawBody);
     // Check if the put process is successful
     if ($data != false) {
         // Update the data
         $item = $this->_updateItem($data, $item->getSource(), $item->getID());
         // Build the entry for the response
         $atomProcessor = new AtomProcessor();
         $newEntry = $atomProcessor->buildItemEntry($item);
         // Build the response
         $this->_buildResponse(Api_BaseController::HTTP_SUCCESS, $newEntry->getXml(), Api_BaseController::CONTENT_TYPE_ATOM);
     }
 }
コード例 #2
0
 public function putAction()
 {
     // Get the content-type of the request
     $contentType = $this->getRequest()->getHeader('Content-Type');
     $contentType = explode(';', $contentType, 2);
     // Only application/atom+xml content type is allowed
     if ($contentType[0] != 'application/atom+xml') {
         $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Unsupported content-type');
         return;
     }
     if (!$this->_authenticateUser()) {
         return;
     }
     // Get the Item from IRI
     $item = $this->_getItemByIri($this->_getItemIri());
     if (!$this->_isItemExists($item)) {
         return;
     }
     // Get the raw body of the request
     $rawBody = $this->getRequest()->getRawBody();
     // Process the request based on the content type of the request
     $data = $this->_putEntry($item, $rawBody);
     // Check if the put process is successful
     if ($data != false) {
         // Update the data
         $item = $this->_updateItem($data, $item->getSource(), $item->getID());
         // Build the entry for the response
         $atomProcessor = new AtomProcessor();
         $newEntry = $atomProcessor->buildItemEntry($item);
         // Build the response
         $this->_buildResponse(Api_BaseController::HTTP_SUCCESS, $newEntry->getXml(), Api_BaseController::CONTENT_TYPE_ATOM);
     }
 }