*/
class Toolkit_FileServer_ImageAdapter extends Toolkit_FileServer_AdapterAbstract
{
- // {{{ getAllowedMimeTypes()
-
- /**
- * Get the mime types that are allowed to be uploaded
- *
- * @return array allowed mime types
- */
- public function getAllowedMimeTypes()
- {
- return array(
- 'image/jpe',
- 'image/jpeg',
- 'image/jpg',
- 'image/jfif',
- 'image/pjpeg',
- 'image/pjp',
- 'image/gif',
- 'image/gif',
- 'image/png',
- );
- }
-
- // }}}
- // {{{ getFileElement()
+ // {{{ getAllowedMimeTypes()
+
+ /**
+ * Get the mime types that are allowed to be uploaded
+ *
+ * @return array allowed mime types
+ */
+ public function getAllowedMimeTypes()
+ {
+ return array(
+ 'image/jpe',
+ 'image/jpeg',
+ 'image/jpg',
+ 'image/jfif',
+ 'image/pjpeg',
+ 'image/pjp',
+ 'image/gif',
+ 'image/gif',
+ 'image/png',
+ );
+ }
+
+ // }}}
+ // {{{ getFileElement()
/**
* Creates the file element for the XML string
$file = $xml->createElement('File');
switch ($type) {
- case 'Upload' :
- $action = $xml->createElement('FileAction', 'Submit');
- $delivery = $xml->createElement('DeliveryMethod', 'Submit');
- $fieldName = $xml->createElement('FieldName', 'file_upload');
-
- $file->appendChild($action);
- $file->appendChild($delivery);
- $file->appendChild($fieldName);
- break;
-
- case 'URL':
- $action = $xml->createElement('FileAction', 'Submit');
- $delivery = $xml->createElement('DeliveryMethod', 'URL');
- $src = $xml->createElement('Src', $fName);
-
- $file->appendChild($action);
- $file->appendChild($delivery);
- $file->appendChild($src);
- break;
-
- case 'Delete':
- $action = $xml->createElement('FileAction', 'Delete');
- $file->appendChild($action);
-
- $fileName = $xml->createElement('FileName', $fName);
- $file->appendChild($fileName);
- break;
-
- default :
- throw new RuntimeException("Invalid XML type - `$type`.");
- break;
+ case 'Upload' :
+ $action = $xml->createElement('FileAction', 'Submit');
+ $delivery = $xml->createElement('DeliveryMethod', 'Submit');
+ $fieldName = $xml->createElement('FieldName', 'file_upload');
+
+ $file->appendChild($action);
+ $file->appendChild($delivery);
+ $file->appendChild($fieldName);
+ break;
+
+ case 'URL':
+ $action = $xml->createElement('FileAction', 'Submit');
+ $delivery = $xml->createElement('DeliveryMethod', 'URL');
+ $src = $xml->createElement('Src', $fName);
+
+ $file->appendChild($action);
+ $file->appendChild($delivery);
+ $file->appendChild($src);
+ break;
+
+ case 'Delete':
+ $action = $xml->createElement('FileAction', 'Delete');
+ $file->appendChild($action);
+
+ $fileName = $xml->createElement('FileName', $fName);
+ $file->appendChild($fileName);
+ break;
+
+ default :
+ throw new RuntimeException("Invalid XML type - `$type`.");
+ break;
}
return $file;
}
- // }}}
+ // }}}
// {{{ getImageSize()
/**
$response = curl_exec($ch);
curl_close($ch);
- if (!@simplexml_load_string($response)) {
- $logger = Toolkit_Logger::getLogger();
- $logger->warning("$response - $image");
- }
+ if (!@simplexml_load_string($response)) {
+ $logger = Toolkit_Logger::getLogger();
+ $logger->warning("$response - $image");
+ }
$wPattern = '/<width>(.*)<\/width>/';
preg_match($wPattern, $response, $matches);
}
// }}}
- // {{{ uploadImageFile()
+ // {{{ uploadImageFile()
/**
* Upload a file to the File Server
*/
public function uploadImageFile($fname)
{
- if (!file_exists($fname)) {
- throw new RuntimeException("could not find file `$fname`");
- }
-
- $request = $this->buildFileServerXML(basename($fname), 'Upload');
-
- $ch = curl_init();
- $fileData = array(
- 'request' => $request,
- 'file_upload' => "@$fname",
- 'file_upload_name' => basename($fname)
- );
-
- $curlOptions = array(
- CURLOPT_URL => IS_SUBMIT_URL,
- CURLOPT_HEADER => 0,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_POSTFIELDS => $fileData
- );
- curl_setopt_array($ch, $curlOptions);
-
- $response = curl_exec($ch);
- curl_close($ch);
-
- try {
- $xmlDoc = new DOMDocument();
- $response = str_replace('<?xml version="1.0"?'. '>', '', $response);
- $xmlDoc->loadXML($response);
- $successCode = $this->xmlPathContent(
- $xmlDoc,
- '/FileServerResponse/ReplyStatus/SuccessCode'
- );
- $message = $this->xmlPathContent(
- $xmlDoc,
- '/FileServerResponse/ReplyStatus/Message'
- );
- $storedName = $this->xmlPathContent(
- $xmlDoc,
- '/FileServerResponse/File/StoredName'
- );
- $storedSize = $this->xmlPathContent(
- $xmlDoc,
- '/FileServerResponse/File/StoredSize'
- );
- $mediaType = $this->xmlPathContent(
- $xmlDoc,
- '/FileServerResponse/File/MediaType'
- );
-
- if ($successCode != 0) {
- throw new RangeException(
- "Invalid response `$response` - `$message`"
- );
- }
-
- return array(
- 'name' => $storedName,
- 'size' => $storedSize,
- 'type' => $mediaType,
- );
- } catch (RangeException $e) {
- Toolkit_Logger::logException('Image Server', $e);
- throw new Toolkit_FileServer_Exception(
- 'Invalid File Server Response'
- );
- }
+ if (!file_exists($fname)) {
+ throw new RuntimeException("could not find file `$fname`");
+ }
+
+ $request = $this->buildFileServerXML(basename($fname), 'Upload');
+
+ $ch = curl_init();
+ $fileData = array(
+ 'request' => $request,
+ 'file_upload' => "@$fname",
+ 'file_upload_name' => basename($fname)
+ );
+
+ $curlOptions = array(
+ CURLOPT_URL => IS_SUBMIT_URL,
+ CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_POSTFIELDS => $fileData
+ );
+ curl_setopt_array($ch, $curlOptions);
+
+ $response = curl_exec($ch);
+ curl_close($ch);
+
+ try {
+ $xmlDoc = new DOMDocument();
+ $response = str_replace('<?xml version="1.0"?'. '>', '', $response);
+ $xmlDoc->loadXML($response);
+ $successCode = $this->xmlPathContent(
+ $xmlDoc,
+ '/FileServerResponse/ReplyStatus/SuccessCode'
+ );
+ $message = $this->xmlPathContent(
+ $xmlDoc,
+ '/FileServerResponse/ReplyStatus/Message'
+ );
+ $storedName = $this->xmlPathContent(
+ $xmlDoc,
+ '/FileServerResponse/File/StoredName'
+ );
+ $storedSize = $this->xmlPathContent(
+ $xmlDoc,
+ '/FileServerResponse/File/StoredSize'
+ );
+ $mediaType = $this->xmlPathContent(
+ $xmlDoc,
+ '/FileServerResponse/File/MediaType'
+ );
+
+ if ($successCode != 0) {
+ throw new RangeException(
+ "Invalid response `$response` - `$message`"
+ );
+ }
+
+ return array(
+ 'name' => $storedName,
+ 'size' => $storedSize,
+ 'type' => $mediaType,
+ );
+ } catch (RangeException $e) {
+ Toolkit_Logger::logException('Image Server', $e);
+ throw new Toolkit_FileServer_Exception(
+ 'Invalid File Server Response'
+ );
+ }
}
- // }}}
+ // }}}
}
?>