/** * Sets up unit test wide variables at the start * of each test method. * @access public */ function setUp() { $this->bNum = ByteSize::withValue(280); $this->kbNum = ByteSize::withValue(2800); $this->mbNum = ByteSize::withValue(2808093); $this->gbNum = ByteSize::withValue(8808033932); $this->reallyBigNum = ByteSize::withValue(8.000000000000001E+25); }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { ArgumentValidator::validate($value, StringValidatorRule::getRule()); // Store the size in the object in case its asked for again. try { $size = ByteSize::fromString($value); } catch (InvalidArgumentException $e) { $size = ByteSize::withValue(0); } $this->_size = $size->value(); // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // Check to see if the name is in the database $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("size")); $query->setValues(array("'" . addslashes($this->_size) . "'")); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->setColumns(array("id", "size")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Answer a step for all of the the files of the asset * * @return object WizardStep * @access public * @since 10/31/05 */ function getRemoteFileRecordsStep() { $idManager = Services::getService("Id"); $repository = $this->getRepository(); $recStructId = $idManager->getId("REMOTE_FILE"); $recStruct = $repository->getRecordStructure($recStructId); $step = new WizardStep(); $step->setDisplayName($recStruct->getDisplayName()); ob_start(); print "\n<h2>" . _("Remote Files") . "</h2>"; print "\n[[files]]"; $step->setContent(ob_get_clean()); $repeatableComponent = $step->addComponent("files", new WRepeatableComponentCollection()); $repeatableComponent->setStartingNumber(0); $repeatableComponent->setAddLabel(_("Add New File")); $repeatableComponent->setRemoveLabel(_("Remove File")); ob_start(); $component = $repeatableComponent->addComponent("record_id", new WHiddenField()); $component = $repeatableComponent->addComponent("file_url", new WTextField()); $component->setSize(50); $vComponent = $repeatableComponent->addComponent("file_name", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent(new WTextField()); $vComponent = $repeatableComponent->addComponent("file_size", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent(new WTextField()); $vComponent = $repeatableComponent->addComponent("mime_type", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent(new WTextField()); // Dimensions $dimensionComponent = new WTextField(); $dimensionComponent->setSize(8); $dimensionComponent->setStyle("text-align: right"); $dimensionComponent->setErrorRule(new WECOptionalRegex("^([0-9]+px)?\$")); $dimensionComponent->setErrorText(_("Must be a positive integer followed by 'px'.")); $dimensionComponent->addOnChange("validateWizard(this.form);"); $vComponent = $repeatableComponent->addComponent("height", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy()); $vComponent = $repeatableComponent->addComponent("width", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy()); // Thumnail Upload $component = $repeatableComponent->addComponent("thumbnail_upload", new WFileUploadField()); $vComponent = $repeatableComponent->addComponent("thumbnail_mime_type", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent(new WTextField()); // Thumbnail dimensions $vComponent = $repeatableComponent->addComponent("thumbnail_height", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy()); $vComponent = $repeatableComponent->addComponent("thumbnail_width", new WVerifiedChangeInput()); $vComponent->setChecked(FALSE); $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy()); print "\n<p>" . _("Url:") . " "; print "\n[[file_url]]</p>"; print "\n<p>"; print _("By default, the values below will be automatically populated from your uploaded file."); print " " . _("If needed, change the properties below to custom values: "); print "\n<table border='1'>"; print "\n<tr>"; print "\n\t<th>"; print "\n\t\t" . _("Property") . ""; print "\n\t</th>"; print "\n\t<th>"; print "\n\t\t" . _("Custom Value") . ""; print "\n\t</th>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("File Name") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[file_name]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("File Size") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[file_size]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Mime Type") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[mime_type]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Width") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[width]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Height") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[height]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Thumbnail") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n[[thumbnail_upload]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Thumbnail Mime Type") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[thumbnail_mime_type]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Thumbnail Width") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[thumbnail_width]]"; print "\n\t</td>"; print "\n</tr>"; print "\n<tr>"; print "\n\t<td>"; print "\n\t\t" . _("Thumbnail Height") . ""; print "\n\t</td>"; print "\n\t<td>"; print "\n\t\t[[thumbnail_height]]"; print "\n\t</td>"; print "\n</tr>"; print "\n</table>"; print "\n</p>"; $repeatableComponent->setContent(ob_get_contents()); ob_end_clean(); $records = $this->_assets[0]->getRecordsByRecordStructure($recStructId); while ($records->hasNext()) { $record = $records->next(); $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } $collection = array(); $recordId = $record->getId(); $collection['record_id'] = $recordId->getIdString(); $collection['file_url'] = $parts['FILE_URL']->getValue(); $collection['file_name'] = $parts['FILE_NAME']->getValue(); $size = ByteSize::withValue($parts['FILE_SIZE']->getValue()); $collection['file_size'] = $size->asString(); $collection['mime_type'] = $parts['MIME_TYPE']->getValue(); $dim = $parts['DIMENSIONS']->getValue(); if ($dim[1]) { $collection['height'] = $dim[1] . 'px'; } if ($dim[0]) { $collection['width'] = $dim[0] . 'px'; } $collection['thumbnail_upload'] = array("starting_name" => "thumb.jpg", "starting_size" => strlen($parts['THUMBNAIL_DATA']->getValue())); $collection['thumbnail_mime_type'] = $parts['THUMBNAIL_MIME_TYPE']->getValue(); $thumDim = $parts['THUMBNAIL_DIMENSIONS']->getValue(); if ($thumDim[1]) { $collection['thumbnail_height'] = $thumDim[1] . 'px'; } if ($thumDim[0]) { $collection['thumbnail_width'] = $thumDim[0] . 'px'; } $repeatableComponent->addValueCollection($collection); } return $step; }
/** * Recursively list a directory * * @param string $path * @return void * @access protected * @since 7/28/08 */ protected function listDir($path, $tabs = "") { ob_start(); if (is_dir($path)) { print "\n\t"; } else { print "\n" . ByteSize::withValue(filesize($path))->asString(); } print $tabs . basename($path); if (is_dir($path)) { $entries = scandir($path); foreach ($entries as $entry) { if ($entry != '.' && $entry != '..') { print $this->listDir($path . DIRECTORY_SEPARATOR . $entry, $tabs . "\t"); } } } return ob_get_clean(); }
/** * Decompress a tar archive of a site. * * @param string $archivePath * @param string $decompressDir * @return void * @access public * @since 3/14/08 */ public function decompressArchive($archivePath, $decompressDir) { if (!file_exists($archivePath)) { throw new Exception("Archive, '" . basename($archivePath) . "' does not exist."); } if (!is_readable($archivePath)) { throw new Exception("Archive, '" . basename($archivePath) . "' is not readable."); } // Decompress the archive into our temp-dir $archive = new Archive_Tar($archivePath); // Check for a containing directory and strip it if needed. $content = @$archive->listContent(); if (!is_array($content) || !count($content)) { throw new Exception("Invalid Segue archive. '" . basename($archivePath) . "' is not a valid GZIPed Tar archive."); } $containerName = null; // printpre($content); if ($content[0]['typeflag'] == 5) { $containerName = trim($content[0]['filename'], '/') . '/'; for ($i = 1; $i < count($content); $i++) { // if one of the files isn't in the container, then we don't have a container of all if (strpos($content[$i]['filename'], $containerName) === false) { $containerName = null; break; } } } // printpre($containerName); $decompressResult = @$archive->extractModify($decompressDir, $containerName); if (!$decompressResult) { throw new Exception("Could not decompress Segue archive: '" . basename($archivePath) . "' size, " . ByteSize::withValue(filesize($archivePath))->asString() . "."); } if (!file_exists($decompressDir . "/site.xml")) { throw new Exception("Invalid Segue archive. 'site.xml' was not found in '" . implode("', '", scandir($decompressDir)) . "'."); } }
/** * Answer the size of the file as a ByteSize object * * @return object ByteSize * @access public * @since 4/27/07 */ function getSize() { $size = ByteSize::withValue($this->_getPartValue('FILE_SIZE')); return $size; }
/** * Answer the media library quota * * @return object ByteSize * @access public * @since 3/20/08 */ public function getMediaQuota() { return ByteSize::withValue($this->mediaQuota); }
/** * Convert a Segue1 export into a Segue2 export * * @param string $destFilePath The path that Segue2 export file will be placed in. * @param string $relativeOutputFilePath The output file path relative to * encode into the xml output. * @return object DOMDocument The Segue2 export document * @access protected * @since 3/14/08 */ protected function convertFrom1To2($destFilePath, $relativeOutputFilePath) { try { $sourcePath = $this->downloadSegue1Export(); $sourceFilePath = $sourcePath . "/media"; $sourceDocPath = $sourcePath . "/site.xml"; $sourceDoc = new Harmoni_DOMDocument(); $sourceDoc->load($sourceDocPath); $converter = new Segue1To2Director($destFilePath, $relativeOutputFilePath); $outputDoc = $converter->convert($sourceDoc, $sourceFilePath); // Delete the source directory $this->cleanUpSourcePath($sourcePath); } catch (DOMException $e) { $size = ByteSize::withValue(filesize($sourceDocPath)); $this->cleanUpSourcePath($sourcePath); if ($e->getCode() === DOMSTRING_SIZE_ERR) { throw new DOMException("The export of '" . $this->getSourceSlotName() . "' is too large to load (" . $size->asString() . ") or contains an element that is too large to load.", DOMSTRING_SIZE_ERR); } throw $e; } catch (Exception $e) { if (isset($sourcePath)) { $this->cleanUpSourcePath($sourcePath); } throw $e; } return $outputDoc; }
/** * Executes an SQL query. * Executes an SQL query. * @access private * @param string The SQL query string. * @return mixed For a SELECT statement, a resource identifier, if * successful; For INSERT, DELETE, UPDATE statements, TRUE if successful; * for all: FALSE, if not successful. */ function _query($query) { // do not attempt to query, if not connected if (!$this->isConnected()) { throw new ConnectionDatabaseException("Attempted to query but there was no database connection."); return false; } if (is_array($query)) { $queries = $query; } else { if (is_string($query)) { $queries = array($query); } } // If we have a persistant connection, it might be shared with other // databases, so make sure our database is selected. if ($this->_isConnectionPersistant == true) { if (!mysql_select_db($this->_dbName, $this->_linkId)) { throw new ConnectionDatabaseException("Cannot select database, " . $this->_dbName . " : " . mysql_error($this->_linkId)); } } foreach ($queries as $q) { // attempt to execute the query $resourceId = mysql_query($q, $this->_linkId); debug::output("<pre>Query: <div>" . $query . "</div>Result: {$resourceId}</pre>", 1, "DBHandler"); if ($resourceId === false) { $this->_failedQueries++; switch (mysql_errno($this->_linkId)) { // No Such Table case 1146: case 1177: throw new NoSuchTableDatabaseException("MySQL Error: " . mysql_error($this->_linkId), mysql_errno($this->_linkId)); // Duplicate Key // Duplicate Key case 1022: case 1062: throw new DuplicateKeyDatabaseException("MySQL Error: " . mysql_error($this->_linkId), mysql_errno($this->_linkId)); // max_allowed_packet // max_allowed_packet case 1153: // Got a packet bigger than 'max_allowed_packet' bytes // Got a packet bigger than 'max_allowed_packet' bytes case 1162: // Result string is longer than 'max_allowed_packet' bytes // Result string is longer than 'max_allowed_packet' bytes case 1301: // Result of %s() was larger than max_allowed_packet (%ld) - truncated $size = ByteSize::withValue(strlen($query)); throw new QuerySizeDatabaseException("MySQL Error: " . mysql_error($this->_linkId) . " (Query Size: " . $size->asString() . ")", mysql_errno($this->_linkId)); default: throw new QueryDatabaseException("MySQL Error: " . mysql_error($this->_linkId), mysql_errno($this->_linkId)); } } else { $this->_successfulQueries++; } } return $resourceId; }
/** * Returns a block of XHTML-valid code that contains markup for this specific * component. * @param string $fieldName The field name to use when outputting form data or * similar parameters/information. * @access public * @return string */ function getMarkup($fieldName) { $name = RequestContext::name($fieldName); $m = ""; if ($this->_filename) { $size = ByteSize::withValue($this->_size); $m .= "<i>" . $this->_filename . " (" . $size->asString() . ")</i>\n"; } else { if ($this->_startingDisplayFilename && $this->_startingDisplaySize) { $size = ByteSize::withValue($this->_startingDisplaySize); $m .= "<i>" . $this->_startingDisplayFilename . " (" . $size->asString() . ")</i>\n"; } } $m .= "<input type='file' name='{$name}'"; if (count($this->_accept)) { $m .= " accept='" . implode(", ", $this->_accept) . "'"; } if ($this->_style) { $m .= " style=\"" . addslashes($this->_style) . "\""; } $m .= " />"; if ($this->_errString) { $m .= "<span style='color: red; font-weight: 900;'>" . $this->_errString . "</span>"; $this->_errString = null; } return $m; }
/** * Generate HTML for displaying particular parts of the Record * * @param object $record The record to print. * @param array $partStructures An array of particular partStructures to print. * @return string * @access public * @since 10/19/04 */ function generateDisplayForPartStructures(Id $repositoryId, Id $assetId, Record $record, array $partStructures) { ArgumentValidator::validate($partStructures, new ArrayValidatorRuleWithRule(new ExtendsValidatorRule("PartStructure"))); $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); if (!isset($parts[$partStructureId->getIdString()]) || !is_array($parts[$partStructureId->getIdString()])) { $parts[$partStructureId->getIdString()] = array(); } $parts[$partStructureId->getIdString()][] = $part; } // print out the parts; ob_start(); $partStructuresToSkip = array('FILE_DATA', 'THUMBNAIL_DATA', 'THUMBNAIL_MIME_TYPE', 'THUMBNAIL_DIMENSIONS'); $printThumbnail = FALSE; foreach (array_keys($partStructures) as $key) { $partStructure = $partStructures[$key]; $partStructureId = $partStructure->getId(); if (!in_array($partStructureId->getIdString(), $partStructuresToSkip)) { print "\n<strong>" . $partStructure->getDisplayName() . ":</strong> \n"; switch ($partStructureId->getIdString()) { case 'FILE_SIZE': $size = ByteSize::withValue($parts[$partStructureId->getIdString()][0]->getValue()); print $size->asString(); break; case 'DIMENSIONS': $dimensionArray = $parts[$partStructureId->getIdString()][0]->getValue(); print "<em>" . _('width: ') . "</em>" . $dimensionArray[0] . 'px<em>;</em> '; print "<em>" . _('height: ') . "</em>" . $dimensionArray[1] . 'px'; break; default: print $parts[$partStructureId->getIdString()][0]->getValue(); } print "\n<br />"; } else { $printThumbnail = TRUE; } } $html = ob_get_clean(); $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("polyphony-repository"); if ($printThumbnail) { ob_start(); $recordId = $record->getId(); $ns = $harmoni->request->endNamespace(); // ======= VIEWER LINK ======== // $xmlAssetIdString = $harmoni->request->get("asset_id"); print "<a href='#' onclick='Javascript:window.open("; print '"' . VIEWER_URL . "?&source="; print urlencode($harmoni->request->quickURL("asset", "browserecordxml", array("collection_id" => $repositoryId->getIdString(), "asset_id" => $xmlAssetIdString, "record_id" => $recordId->getIdString(), RequestContext::name("limit_by") => RequestContext::value("limit_by"), RequestContext::name("type") => RequestContext::value("type"), RequestContext::name("searchtype") => RequestContext::value("searchtype"), RequestContext::name("searchstring") => RequestContext::value("searchstring")))); print '&start=0", '; print '"' . preg_replace("/[^a-z0-9]/i", '_', $assetId->getIdString()) . '", '; print '"toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=500"'; print ")'>"; $harmoni->request->startNamespace($ns); // If we have a thumbnail with a valid mime type, print a link to that. $thumbnailName = preg_replace("/\\.[^\\.]+\$/", "", $parts['FILE_NAME'][0]->getValue()); if ($thumbnailMimeType = $parts['THUMBNAIL_MIME_TYPE'][0]->getValue()) { $mime = Services::getService("MIME"); $thumbnailName .= "." . $mime->getExtensionForMIMEType($thumbnailMimeType); } print "\n<img src='"; print RepositoryInputOutputModuleManager::getThumbnailUrlForRecord($assetId, $record); print "'"; print " style='border: 0px;'"; print " alt='Thumbnail image.'"; print " align='left'"; print " />"; print "</a> <br />"; $html2 = ob_get_clean(); ob_start(); print "\n<a href='"; print RepositoryInputOutputModuleManager::getFileUrlForRecord($assetId, $record); print "' target='_blank'>"; print "Download This File</a>\n"; $downloadlink = ob_get_clean(); $html = "<table border=0><tr><td>" . $html2 . "</td><td>" . $html . $downloadlink . "</td></tr></table>"; } $harmoni->request->endNamespace(); return $html; }