/** * Return a data directory. * * @param string $subDirectory * @param bool $createDirectory * @return string */ protected function getDataDirectory($subDirectory = '', $createDirectory = true) { return UtilityComponent::getDataDirectory($subDirectory, $createDirectory); }
/** Add a bitstream to a revision */ public function addBitstream($itemRevisionDao, $bitstreamDao) { /** @var BitstreamModel $BitstreamModel */ $BitstreamModel = MidasLoader::loadModel('Bitstream'); /** @var ItemModel $ItemModel */ $ItemModel = MidasLoader::loadModel('Item'); $bitstreamDao->setItemrevisionId($itemRevisionDao->getItemrevisionId()); // Save the bitstream $bitstreamDao->setDate(date('Y-m-d H:i:s')); $BitstreamModel->save($bitstreamDao); $item = $itemRevisionDao->getItem($bitstreamDao); $item->setSizebytes($this->getSize($itemRevisionDao)); $item->setDateUpdate(date('Y-m-d H:i:s')); Zend_Registry::get('notifier')->notifyEvent('EVENT_CORE_CREATE_THUMBNAIL', array($item)); $notifications = Zend_Registry::get('notifier')->getNotifications(); $createThumb = false; if (!isset($notifications['EVENT_CORE_CREATE_THUMBNAIL']) || empty($notifications['EVENT_CORE_CREATE_THUMBNAIL'])) { $mime = $bitstreamDao->getMimetype(); $tmpfile = $bitstreamDao->getPath(); if (!file_exists($tmpfile)) { $tmpfile = $bitstreamDao->getFullPath(); } // Creating temp image as a source image (original image). $createThumb = true; if (file_exists($tmpfile) && $mime == 'image/jpeg') { try { $src = imagecreatefromjpeg($tmpfile); } catch (Exception $exc) { $createThumb = false; } } elseif (file_exists($tmpfile) && $mime == 'image/png') { try { $src = imagecreatefrompng($tmpfile); } catch (Exception $exc) { $createThumb = false; } } elseif (file_exists($tmpfile) && $mime == 'image/gif') { try { $src = imagecreatefromgif($tmpfile); } catch (Exception $exc) { $createThumb = false; } } else { $createThumb = false; } if ($createThumb) { $tmpPath = UtilityComponent::getDataDirectory('thumbnail'); if (!file_exists($tmpPath)) { throw new Zend_Exception('Problem thumbnail path: ' . UtilityComponent::getDataDirectory('thumbnail')); } /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $destination = $tmpPath . '/' . $randomComponent->generateInt() . '.jpg'; while (file_exists($destination)) { $destination = $tmpPath . '/' . $randomComponent->generateInt() . '.jpg'; } $pathThumbnail = $destination; list($x, $y) = getimagesize($tmpfile); //--- get size of img --- $thumb = 100; //--- max. size of thumb --- if ($x > $y) { $tx = $thumb; //--- landscape --- $ty = round($thumb / $x * $y); } else { $tx = round($thumb / $y * $x); //--- portrait --- $ty = $thumb; } $thb = imagecreatetruecolor($tx, $ty); //--- create thumbnail --- imagecopyresampled($thb, $src, 0, 0, 0, 0, $tx, $ty, $x, $y); imagejpeg($thb, $pathThumbnail, 80); imagedestroy($thb); imagedestroy($src); } } if ($createThumb) { $ItemModel->replaceThumbnail($item, $pathThumbnail); } $ItemModel->save($item, true); }
/** * Handle the get dashboard callback. * * @return array map of dashboard fields to their values */ public function getDasboard() { return array('Data Folder Writable' => array(is_writable(UtilityComponent::getDataDirectory())), 'Temporary Folder Writable' => array(is_writable(UtilityComponent::getTempDirectory('')))); }
/** processParaviewData */ public function processParaviewData($itemDao) { /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); if (!is_object($itemDao)) { $itemDao = $itemModel->load($itemDao['item_id']); } if (!$this->canVisualizeWithParaview($itemDao)) { return; } /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $paraViewWorkDirectory = $settingModel->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName); $useSymlinks = $settingModel->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); $pwApp = $settingModel->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName); $pvBatch = $settingModel->getValueByName(VISUALIZE_PVBATCH_COMMAND_KEY, $this->moduleName); if (empty($pwApp) || empty($pvBatch)) { return; } $pathArray = $this->createParaviewPath(); $path = $pathArray['path']; $tmpFolderName = $pathArray['folderName']; $revision = $itemModel->getLastRevision($itemDao); if ($revision === false) { throw new Zend_Exception('The item has no revisions', MIDAS_INVALID_POLICY); } $bitstreams = $revision->getBitstreams(); foreach ($bitstreams as $bitstream) { if ($useSymlinks) { symlink($bitstream->getFullPath(), $path . '/' . $bitstream->getName()); } else { copy($bitstream->getFullPath(), $path . '/' . $bitstream->getName()); } $ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1)); if ($ext != 'pvsm') { $filePath = $paraViewWorkDirectory . '/' . $tmpFolderName . '/' . $bitstream->getName(); $mainBitstream = $bitstream; } } foreach ($bitstreams as $bitstream) { $ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1)); if ($ext == 'pvsm') { $file_contents = file_get_contents($path . '/' . $bitstream->getName()); $file_contents = preg_replace('/\\"([a-zA-Z0-9_.\\/\\\\:]{1,1000})' . str_replace('.', '\\.', $mainBitstream->getName()) . '/', '"' . $filePath, $file_contents); $filePath = $paraViewWorkDirectory . '/' . $tmpFolderName . '/' . $bitstream->getName(); $inF = fopen($path . '/' . $bitstream->getName(), 'w'); fwrite($inF, $file_contents); fclose($inF); $this->view->json['visualize']['openState'] = true; break; } } $tmpPath = UtilityComponent::getTempDirectory(); if (file_exists($tmpPath . '/screenshot1.png')) { unlink($tmpPath . '/screenshot1.png'); } if (file_exists($tmpPath . '/screenshot2.png')) { unlink($tmpPath . '/screenshot2.png'); } if (file_exists($tmpPath . '/screenshot4.png')) { unlink($tmpPath . '/screenshot4.png'); } if (file_exists($tmpPath . '/screenshot3.png')) { unlink($tmpPath . '/screenshot3.png'); } $return = file_get_contents(str_replace('PWApp', 'processData', $pwApp) . '?file=' . $filePath . '&pvbatch=' . $pvBatch); if (strpos($return, 'PROBLEME') !== false) { return; } copy(str_replace('PWApp', 'processData', $pwApp) . '/screenshot1.png', $tmpPath . '/screenshot1.png'); copy(str_replace('PWApp', 'processData', $pwApp) . '/screenshot2.png', $tmpPath . '/screenshot2.png'); copy(str_replace('PWApp', 'processData', $pwApp) . '/screenshot4.png', $tmpPath . '/screenshot4.png'); copy(str_replace('PWApp', 'processData', $pwApp) . '/screenshot3.png', $tmpPath . '/screenshot3.png'); $json = file_get_contents(str_replace('PWApp', 'processData', $pwApp) . '/metadata.txt'); $metadata = json_decode($json); /** @var MetadataModel $metadataModel */ $metadataModel = MidasLoader::loadModel('Metadata'); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'type'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'type', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'type', $metadata[0]); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'points'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'points', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'points', $metadata[1]); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'cells'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'cells', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'cells', $metadata[2]); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'polygons'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'polygons', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'polygons', $metadata[3]); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'x-range'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'x-range', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'x-range', $metadata[4][0] . ' to ' . $metadata[4][1]); $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'image', 'y-range'); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'image', 'y-range', ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'image', 'y-range', $metadata[4][2] . ' to ' . $metadata[4][3]); // create thumbnail try { $src = imagecreatefrompng($tmpPath . '/screenshot1.png'); } catch (Exception $exc) { return; } /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $thumbnailPath = UtilityComponent::getDataDirectory('thumbnail') . '/' . $randomComponent->generateInt(); if (!file_exists(UtilityComponent::getDataDirectory('thumbnail'))) { throw new Zend_Exception('Problem thumbnail path: ' . UtilityComponent::getDataDirectory('thumbnail')); } if (!file_exists($thumbnailPath)) { mkdir($thumbnailPath); } $thumbnailPath .= '/' . $randomComponent->generateInt(); if (!file_exists($thumbnailPath)) { mkdir($thumbnailPath); } $destination = $thumbnailPath . '/' . $randomComponent->generateInt() . '.jpg'; while (file_exists($destination)) { $destination = $thumbnailPath . '/' . $randomComponent->generateInt() . '.jpg'; } $pathThumbnail = $destination; list($x, $y) = getimagesize($tmpPath . '/screenshot1.png'); //--- get size of img --- $thumb = 100; //--- max. size of thumb --- if ($x > $y) { $tx = $thumb; //--- landscape --- $ty = round($thumb / $x * $y); } else { $tx = round($thumb / $y * $x); //--- portrait --- $ty = $thumb; } $thb = imagecreatetruecolor($tx, $ty); //--- create thumbnail --- imagecopyresampled($thb, $src, 0, 0, 0, 0, $tx, $ty, $x, $y); imagejpeg($thb, $pathThumbnail, 80); imagedestroy($thb); imagedestroy($src); $oldThumbnail = $itemDao->getThumbnail(); if (!empty($oldThumbnail)) { unlink($oldThumbnail); } $itemDao->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1)); $itemModel->save($itemDao); $data_dir = UtilityComponent::getDataDirectory('visualize'); if (!file_exists($data_dir)) { mkdir($data_dir); } rename($tmpPath . '/screenshot1.png', $data_dir . '_' . $itemDao->getKey() . '_1.png'); rename($tmpPath . '/screenshot2.png', $data_dir . '_' . $itemDao->getKey() . '_2.png'); rename($tmpPath . '/screenshot3.png', $data_dir . '_' . $itemDao->getKey() . '_3.png'); rename($tmpPath . '/screenshot4.png', $data_dir . '_' . $itemDao->getKey() . '_4.png'); }
/** Reset database (only works with MySQL) */ public function reset() { $db = Zend_Registry::get('dbAdapter'); $dbname = Zend_Registry::get('configDatabase')->database->params->dbname; $stmt = $db->query("SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = '" . $dbname . "'"); while ($row = $stmt->fetch()) { $db->query('DELETE FROM `' . $row['TABLE_NAME'] . '`'); } $path = UtilityComponent::getDataDirectory('assetstore'); $dir = opendir($path); while ($entry = readdir($dir)) { if (is_dir($path . '/' . $entry) && !in_array($entry, array('.', '..'))) { $this->_rrmdir($path . '/' . $entry); } } $path = UtilityComponent::getDataDirectory('thumbnail'); $dir = opendir($path); while ($entry = readdir($dir)) { if (is_dir($path . '/' . $entry) && !in_array($entry, array('.', '..'))) { $this->_rrmdir($path . '/' . $entry); } } if (file_exists(LOCAL_CONFIGS_PATH . '/ldap.local.ini')) { unlink(LOCAL_CONFIGS_PATH . '/ldap.local.ini'); } /** @var UserModel $userModel */ $userModel = MidasLoader::loadModel('User'); $admin = $userModel->createUser(MIDAS_DEMO_ADMIN_EMAIL, MIDAS_DEMO_ADMIN_PASSWORD, 'Demo', 'Administrator', 1); $userModel->createUser(MIDAS_DEMO_USER_EMAIL, MIDAS_DEMO_USER_PASSWORD, 'Demo', 'User', 0); /** @var CommunityModel $communityModel */ $communityModel = MidasLoader::loadModel('Community'); $communityDao = $communityModel->createCommunity('Demo', 'This is a demo community', MIDAS_COMMUNITY_PUBLIC, $admin, MIDAS_COMMUNITY_CAN_JOIN); /** @var AssetstoreModel $assetstoreModel */ $assetstoreModel = MidasLoader::loadModel('Assetstore'); $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName('Default'); $assetstoreDao->setPath(UtilityComponent::getDataDirectory('assetstore')); $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL); $assetstoreModel->save($assetstoreDao); /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $settingModel->setConfig('default_assetstore', $assetstoreDao->getKey()); $options = array('allowModifications' => true); $config = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/application.ini', null, $options); $config->global->dynamichelp = 1; $config->global->environment = 'production'; $config->global->application->name = 'Midas Platform - Demo'; $description = 'Midas Platform is an open-source toolkit that enables the rapid creation of tailored, web-enabled data storage. Designed to meet the needs of advanced data-centric computing, Midas Platform addresses the growing challenge of large data by providing a flexible, intelligent data storage system. The system integrates multimedia server technology with other open-source data analysis and visualization tools to enable data-intensive applications that easily interface with existing workflows.'; $config->global->application->description = $description; $enabledModules = array('api', 'metadataextractor', 'oai', 'statistics', 'scheduler', 'thumbnailcreator', 'visualize'); foreach ($enabledModules as $module) { if (file_exists(LOCAL_CONFIGS_PATH . '/' . $module . '.demo.local.ini')) { copy(LOCAL_CONFIGS_PATH . '/' . $module . '.demo.local.ini', LOCAL_CONFIGS_PATH . '/' . $module . '.local.ini'); $config->module->{$module} = 1; } else { unlink(LOCAL_CONFIGS_PATH . '/' . $module . '.local.ini'); } } $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename(LOCAL_CONFIGS_PATH . '/application.local.ini'); $writer->write(); $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true); Zend_Registry::set('configGlobal', $configGlobal); /** @var UploadComponent $uploadComponent */ $uploadComponent = MidasLoader::loadComponent('Upload'); $uploadComponent->createUploadedItem($admin, 'midasLogo.gif', BASE_PATH . '/core/public/images/midasLogo.gif', $communityDao->getPublicFolder(), null, '', true); $uploadComponent->createUploadedItem($admin, 'cow.vtp', BASE_PATH . '/modules/demo/public/' . $this->moduleName . '/cow.vtp', $communityDao->getPublicFolder(), null, '', true); }