Source for file viewthumbnail.act.php

Documentation is available at viewthumbnail.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.repository
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: viewthumbnail.act.php,v 1.13 2007/09/19 14:04:56 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/ForceAuthAction.class.php");
  13. require_once(POLYPHONY."/main/library/RepositoryInputOutputModules/RepositoryInputOutputModuleManager.class.php");
  14.  
  15.  
  16. /**
  17. * Display the file in the specified record.
  18. *
  19. * @since 11/11/04
  20. * @author Ryan Richards
  21. * @author Adam Franco
  22. *
  23. * @package polyphony.repository
  24. *
  25. * @copyright Copyright &copy; 2005, Middlebury College
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  27. *
  28. * @version $Id: viewthumbnail.act.php,v 1.13 2007/09/19 14:04:56 adamfranco Exp $
  29. */
  30. class viewthumbnailAction
  31. extends ForceAuthAction
  32. {
  33. /**
  34. * Check Authorizations
  35. *
  36. * @return boolean
  37. * @access public
  38. * @since 4/26/05
  39. */
  40. function isExecutionAuthorized () {
  41. $harmoni = Harmoni::instance();
  42. $idManager = Services::getService("Id");
  43. $authZManager = Services::getService("AuthorizationManager");
  44. $harmoni->request->startNamespace("polyphony-repository");
  45. $assetId =$idManager->getId(RequestContext::value("asset_id"));
  46. $harmoni->request->endNamespace();
  47. return $authZManager->isUserAuthorized(
  48. $idManager->getId("edu.middlebury.authorization.view"),
  49. $assetId);
  50. }
  51. /**
  52. * Return a junk image that says you can't view the file
  53. *
  54. * @since 12/22/05
  55. */
  56. function getUnauthorizedMessage() {
  57. header("Content-Type: image/gif");
  58. header('Content-Disposition: filename="english.gif"');
  59. print file_get_contents(POLYPHONY.'/docs/images/unauthorized/english.gif');
  60. exit;
  61. }
  62. /**
  63. * Answer the HTTP Authentication 'Relm' to present to the user for authentication.
  64. *
  65. * @return mixed string or null
  66. * @access public
  67. * @since 8/7/06
  68. */
  69. function getRelm () {
  70. return 'Concerto'; // Override for custom relm.
  71. }
  72. /**
  73. * Answer the cancel function for this action, to use if the user hits
  74. * the 'cancel' button in the http authentication dialog.
  75. *
  76. * @return mixed string or null
  77. * @access public
  78. * @since 8/7/06
  79. */
  80. function getCancelFunction () {
  81. return 'viewthumbnailAction::getUnauthorizedMessage();';
  82. }
  83. /**
  84. * Build the content for this action
  85. *
  86. * @return void
  87. * @access public
  88. * @since 4/26/05
  89. */
  90. function execute () {
  91. if (!$this->isAuthorizedToExecute())
  92. $this->getUnauthorizedMessage();
  93. $defaultTextDomain = textdomain("polyphony");
  94. $harmoni = Harmoni::instance();
  95. $idManager = Services::getService("Id");
  96. $repositoryManager = Services::getService("Repository");
  97. $harmoni->request->startNamespace("polyphony-repository");
  98. $assetId =$idManager->getId(RequestContext::value("asset_id"));
  99. if (RequestContext::value("repository_id")) {
  100. $repositoryId =$idManager->getId(RequestContext::value("repository_id"));
  101. $repository =$repositoryManager->getRepository($repositoryId);
  102. $asset =$repository->getAsset($assetId);
  103. } else {
  104. $repositoryManager = Services::getService("RepositoryManager");
  105. $asset =$repositoryManager->getAsset($assetId);
  106. }
  107. // Get the requested record.
  108. if (RequestContext::value("record_id")) {
  109. $recordId =$idManager->getId(RequestContext::value("record_id"));
  110. $record =$asset->getRecord($recordId);
  111. } else {
  112. $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset);
  113. }
  114. // Make sure that the structure is the right one.
  115. $structure =$record->getRecordStructure();
  116. $fileId =$idManager->getId('FILE');
  117. $remoteFileId =$idManager->getId('REMOTE_FILE');
  118. if (!$fileId->isEqual($structure->getId())
  119. && !$remoteFileId->isEqual($structure->getId()))
  120. {
  121. print "The requested record is not of the FILE structure, and therefore cannot be displayed.";
  122. } else {
  123. // Get the parts for the record.
  124. $partIterator =$record->getParts();
  125. $parts = array();
  126. while($partIterator->hasNext()) {
  127. $part =$partIterator->next();
  128. $partStructure =$part->getPartStructure();
  129. $partStructureId =$partStructure->getId();
  130. $parts[$partStructureId->getIdString()] =$part;
  131. }
  132. // If we have a thumbnail, print that.
  133. if ($parts['THUMBNAIL_MIME_TYPE']->getValue()) {
  134. header("Content-Type: ".$parts['THUMBNAIL_MIME_TYPE']->getValue());
  135. $mime = Services::getService("MIME");
  136. $extension = $mime->getExtensionForMIMEType(
  137. $parts['THUMBNAIL_MIME_TYPE']->getValue());
  138. $filename = $parts['FILE_NAME']->getValue();
  139. if (!$filename)
  140. $filename = _("Untitled");
  141. header('Content-Disposition: filename="'.
  142. $filename.".".$extension.'"');
  143. print $parts['THUMBNAIL_DATA']->getValue();
  144. }
  145. // Otherwise, print a stock image for the mime type.
  146. else {
  147. header("Content-Type: image/png");
  148. $mimeType = $parts['MIME_TYPE']->getValue();
  149. if (!$mimeType || $mimeType == 'application/octet-stream') {
  150. $mime = Services::getService("MIME");
  151. $mimeType = $mime->getMIMETypeForFileName($parts['FILE_NAME']->getValue());
  152. }
  153. // These are mappings to file names in the KDE icon set.
  154. $subTypeImages = array(
  155. "text/plain" => "txt.png",
  156. "text/css" => "css.png",
  157. "text/html" => "html.png",
  158. "text/x-lyx" => "mime_lyx.png",
  159. "text/xml" => "xml.png",
  160. "audio/midi" => "midi.png",
  161. "video/quicktime" => "quicktime.png",
  162. "application/vnd.rn-realmedia" => "real.png",
  163. "application/x-pn-realaudio" => "real.png",
  164. "application/x-pn-realaudio" => "real.png",
  165. "application/msword" => "wordprocessing.png",
  166. "application/vnd.ms-word" => "wordprocessing.png",
  167. "application/vnd.ms-excel" => "spreadsheet.png",
  168. "application/msword" => "wordprocessing.png",
  169. "application/msword" => "wordprocessing.png",
  170. "application/pdf" => "pdf.png",
  171. "application/x-tar" => "tar.png",
  172. "application/x-gtar" => "gtar.png",
  173. "application/x-ustar" => "tar.png",
  174. "application/x-gzip" => "tar.png",
  175. "application/x-bzip" => "tar.png",
  176. "application/x-bzip2" => "tar.png",
  177. "application/x-bcpio" => "tar.png",
  178. "application/x-cpio" => "tar.png",
  179. "application/x-shar" => "tar.png",
  180. "application/mac-binhex40" => "tar.png",
  181. "application/x-stuffit" => "tar.png",
  182. "application/zip" => "tar.png"
  183. );
  184. $typeImages = array (
  185. "text" => "txt.png",
  186. "application" => "binary.png",
  187. "audio" => "sound.png",
  188. "video" => "video.png",
  189. "image" => "image.png",
  190. );
  191. if (isset($subTypeImages[$mimeType])) {
  192. $imageName = $subTypeImages[$mimeType];
  193. } else {
  194. $typeParts = explode("/", $mimeType);
  195. $imageName = $typeImages[$typeParts[0]];
  196. }
  197. header('Content-Disposition: filename="'.$imageName.'"');
  198. print file_get_contents(POLYPHONY_DIR."/icons/filetypes/".$imageName);
  199. }
  200. }
  201. $harmoni->request->endNamespace();
  202. textdomain($defaultTextDomain);
  203. exit;
  204. }
  205. }
  206. ?>

Documentation generated on Wed, 19 Sep 2007 10:27:47 -0400 by phpDocumentor 1.3.0RC3