/** * Answer true if the Asset or AssetId has a thumbnail rather than a default Icon * * @param mixed object Asset Id $assetOrID * @return boolean * @access public * @since 12/4/06 * @static */ static function hasThumbnailNotIcon($assetOrId) { $idManager = Services::getService("IdManager"); $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($assetOrId); if (!$record) { return FALSE; } // Make sure that the structure is the right one. $structure = $record->getRecordStructure(); $fileId = $idManager->getId('FILE'); $remoteFileId = $idManager->getId('REMOTE_FILE'); if (!$fileId->isEqual($structure->getId()) && !$remoteFileId->isEqual($structure->getId())) { return FALSE; } else { // Get the parts for the record. $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } // If we have a thumbnail, print that. if ($parts['THUMBNAIL_MIME_TYPE']->getValue()) { return TRUE; } else { return FALSE; } } }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function outputContent() { $defaultTextDomain = textdomain("polyphony"); $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $harmoni->request->startNamespace("polyphony-repository"); $size = RequestContext::value("size"); $websafe = RequestContext::value("websafe"); // See if we are passed a size if (is_numeric($size)) { $size = intval($size); } else { $size = FALSE; } if ($websafe) { $websafe = TRUE; } else { $websafe = FALSE; } if (RequestContext::value('attachment')) { $attachment = true; } else { $attachment = false; } // Get the requested record. try { $asset = $this->getAsset(); try { $recordId = $idManager->getId(RequestContext::value("record_id")); $record = $asset->getRecord($recordId); } catch (InvalidArgumentException $e) { // If no record id is specified, use the first file record available $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); if (!$record) { throw $e; } } catch (UnknownIdException $e) { // If no record id is specified, use the first file record available $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); if (!$record) { throw $e; } } } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } // Make sure that the structure is the right one. $structure = $record->getRecordStructure(); $remoteFileId = $idManager->getId('REMOTE_FILE'); $fileId = $idManager->getId('FILE'); if ($remoteFileId->isEqual($structure->getId())) { $urlParts = $record->getPartsByPartStructure($idManager->getId("FILE_URL")); $urlPart = $urlParts->next(); header("Location: " . $urlPart->getValue()); } else { if (!$fileId->isEqual($structure->getId())) { try { throw new Exception("The requested record is not of the FILE structure, and therefore cannot be displayed."); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } } else { // Get the parts for the record. $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } $imgProcessor = Services::getService("ImageProcessor"); // If we want to (and can) resize the file, do so if (($size || $websafe) && $imgProcessor->isFormatSupported($parts['MIME_TYPE']->getValue())) { $imageCache = new RepositoryImageCache($record->getId(), $size, $websafe, $parts); header("Content-Type: " . $imageCache->getCachedMimeType()); if ($attachment) { header('Content-Disposition: attachment; filename="' . $imageCache->getCachedFileName() . '"'); } else { header('Content-Disposition: filename="' . $imageCache->getCachedFileName() . '"'); } $data = $imageCache->getCachedImageData(); header('Content-Length: ' . strlen($data)); print $data; } else { header("Content-Type: " . $parts['MIME_TYPE']->getValue()); $filename = $parts['FILE_NAME']->getValue(); if (!preg_match("/[^\\w]/", $filename)) { $mime = Services::getService("MIME"); $extension = $mime->getExtensionForMIMEType($parts['MIME_TYPE']->getValue()); $filename = _("Untitled") . "." . $extension; } if ($attachment) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } else { header('Content-Disposition: filename="' . $filename . '"'); } $data = $parts['FILE_DATA']->getValue(); header('Content-Length: ' . strlen($data)); print $data; } } } $harmoni->request->endNamespace(); textdomain($defaultTextDomain); exit; }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function outputContent() { $defaultTextDomain = textdomain("polyphony"); $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $harmoni->request->startNamespace("polyphony-repository"); // Get the requested record. try { $asset = $this->getAsset(); if (RequestContext::value("record_id")) { $recordId = $idManager->getId(RequestContext::value("record_id")); $record = $asset->getRecord($recordId); } else { $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); } } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } // Make sure that the structure is the right one. $structure = $record->getRecordStructure(); $fileId = $idManager->getId('FILE'); $remoteFileId = $idManager->getId('REMOTE_FILE'); if (!$fileId->isEqual($structure->getId()) && !$remoteFileId->isEqual($structure->getId())) { try { throw new Exception("The requested record is not of the FILE structure, and therefore cannot be displayed."); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } } else { // Get the parts for the record. $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } // If we have a thumbnail, print that. if ($parts['THUMBNAIL_MIME_TYPE']->getValue()) { header("Content-Type: " . $parts['THUMBNAIL_MIME_TYPE']->getValue()); $mime = Services::getService("MIME"); $extension = $mime->getExtensionForMIMEType($parts['THUMBNAIL_MIME_TYPE']->getValue()); $filename = $parts['FILE_NAME']->getValue(); if (!$filename) { $filename = _("Untitled"); } header('Content-Disposition: filename="' . $filename . "." . $extension . '"'); print $parts['THUMBNAIL_DATA']->getValue(); } else { header("Content-Type: image/png"); $mimeType = $parts['MIME_TYPE']->getValue(); if (!$mimeType || $mimeType == 'application/octet-stream') { $mime = Services::getService("MIME"); $mimeType = $mime->getMIMETypeForFileName($parts['FILE_NAME']->getValue()); } // These are mappings to file names in the KDE icon set. $subTypeImages = array("text/plain" => "txt.png", "text/css" => "css.png", "text/html" => "html.png", "text/x-lyx" => "mime_lyx.png", "text/xml" => "xml.png", "audio/midi" => "midi.png", "video/quicktime" => "quicktime.png", "application/vnd.rn-realmedia" => "real.png", "application/x-pn-realaudio" => "real.png", "application/x-pn-realaudio" => "real.png", "application/msword" => "wordprocessing.png", "application/vnd.ms-word" => "wordprocessing.png", "application/vnd.ms-excel" => "spreadsheet.png", "application/msword" => "wordprocessing.png", "application/vnd.ms-powerpoint" => "kpresenter_kpr.png", "application/mspowerpoint" => "kpresenter_kpr.png", "application/pdf" => "pdf.png", "application/x-tar" => "tar.png", "application/x-gtar" => "gtar.png", "application/x-ustar" => "tar.png", "application/x-gzip" => "tar.png", "application/x-bzip" => "tar.png", "application/x-bzip2" => "tar.png", "application/x-bcpio" => "tar.png", "application/x-cpio" => "tar.png", "application/x-shar" => "tar.png", "application/mac-binhex40" => "tar.png", "application/x-stuffit" => "tar.png", "application/zip" => "tar.png"); $typeImages = array("text" => "txt.png", "application" => "binary.png", "audio" => "sound.png", "video" => "video.png", "image" => "image.png"); if (isset($subTypeImages[$mimeType])) { $imageName = $subTypeImages[$mimeType]; } else { $typeParts = explode("/", $mimeType); $imageName = $typeImages[$typeParts[0]]; } header('Content-Disposition: filename="' . $imageName . '"'); print file_get_contents(POLYPHONY_DIR . "/icons/filetypes/" . $imageName); } } $harmoni->request->endNamespace(); textdomain($defaultTextDomain); exit; }