// The test atom multipart file to deposit $testmultipart = "test-files/atom_multipart_package"; // The second test file to deposit $testmultipart2 = "test-files/atom_multipart_package2"; // The test content zip file to deposit $testzipcontentfile = "test-files/atom_multipart_package2.zip"; // A plain content file $testextrafile = "test-files/swordlogo.jpg"; // The file type of the extra file $testextrafiletype = "image/jpg"; // The content type of the test file $testcontenttype = "application/zip"; // The packaging format of the test file $testpackaging = "http://purl.org/net/sword/package/SimpleZip"; require "../swordappclient.php"; $testsac = new SWORDAPPClient(); if (false) { print "About to request servicedocument from " . $testurl . "\n"; if (empty($testuser)) { print "As: anonymous\n"; } else { print "As: " . $testuser . "\n"; } $testsdr = $testsac->servicedocument($testurl, $testuser, $testpw, $testobo); print "Received HTTP status code: " . $testsdr->sac_status . " (" . $testsdr->sac_statusmessage . ")\n"; if ($testsdr->sac_status == 200) { $testsdr->toString(); } print "\n\n"; } if (true) {
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Store the values session_start(); // Try and deposit the multipart package $client = new SWORDAPPClient(); try { $response = $client->depositMultipart($_SESSION['durl'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo'], $_SESSION['filename'], 'http://purl.org/net/sword/package/SimpleZip', 'application/zip', $_SESSION['inprogress']); if ($response->sac_status != 201) { $error = 'Unable to deposit package. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage; $_SESSION['error'] = $error; } else { $_SESSION['error'] = ''; } } catch (Exception $e) { $error = 'Unable to deposit package: ' . $e->getMessage(); $_SESSION['error'] = $error; header('Location: ../../get/sd/'); } // Show the response include '../../common/depositresponse.php';
function display(&$args, $request) { $templateMgr =& TemplateManager::getManager(); parent::display($args, $request); $this->setBreadcrumbs(); $journal =& Request::getJournal(); $plugin =& $this->getSwordPlugin(); $swordUrl = Request::getUserVar('swordUrl'); $depositPointKey = Request::getUserVar('depositPoint'); $depositPoints = $plugin->getSetting($journal->getId(), 'depositPoints'); $username = Request::getUserVar('swordUsername'); $password = Request::getUserVar('swordPassword'); if (isset($depositPoints[$depositPointKey])) { $selectedDepositPoint = $depositPoints[$depositPointKey]; if ($selectedDepositPoint['username'] != '') { $username = $selectedDepositPoint['username']; } if ($selectedDepositPoint['password'] != '') { $password = $selectedDepositPoint['password']; } } $swordDepositPoint = Request::getUserVar('swordDepositPoint'); $depositEditorial = Request::getUserVar('depositEditorial'); $depositGalleys = Request::getUserVar('depositGalleys'); switch (array_shift($args)) { case 'deposit': $depositIds = array(); try { foreach (Request::getUserVar('articleId') as $articleId) { $depositIds[] = $this->deposit($swordDepositPoint, $username, $password, $articleId, $depositEditorial, $depositGalleys); } } catch (Exception $e) { // Deposit failed $templateMgr->assign(array('pageTitle' => 'plugins.importexport.sword.depositFailed', 'messageTranslated' => $e->getMessage(), 'backLink' => Request::url(null, null, null, array('plugin', $this->getName()), array('swordUrl' => $swordUrl, 'swordUsername' => $username, 'swordDepositPoint' => $swordDepositPoint, 'depositEditorial' => $depositEditorial, 'depositGalleys' => $depositGalleys)), 'backLinkLabel' => 'common.back')); return $templateMgr->display('common/message.tpl'); } // Deposit was successful $templateMgr->assign(array('pageTitle' => 'plugins.importexport.sword.depositSuccessful', 'message' => 'plugins.importexport.sword.depositSuccessfulDescription', 'backLink' => Request::url(null, null, null, array('plugin', $this->getName()), array('swordUrl' => $swordUrl, 'swordUsername' => $username, 'swordDepositPoint' => $swordDepositPoint, 'depositEditorial' => $depositEditorial, 'depositGalleys' => $depositGalleys)), 'backLinkLabel' => 'common.continue')); return $templateMgr->display('common/message.tpl'); break; default: $journal =& Request::getJournal(); $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $rangeInfo = Handler::getRangeInfo('articles'); $articleIds = $publishedArticleDao->getPublishedArticleIdsAlphabetizedByJournal($journal->getId(), false); $totalArticles = count($articleIds); if ($rangeInfo->isValid()) { $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount()); } import('lib.pkp.classes.core.VirtualArrayIterator'); $iterator = new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount()); foreach (array('swordUrl', 'swordUsername', 'swordPassword', 'depositEditorial', 'depositGalleys', 'swordDepositPoint') as $var) { $templateMgr->assign($var, Request::getUserVar($var)); } $templateMgr->assign('depositPoints', $depositPoints); if (!empty($swordUrl)) { $client = new SWORDAPPClient(); $doc = $client->servicedocument($swordUrl, $username, $password, ''); $depositPoints = array(); if (is_array($doc->sac_workspaces)) { foreach ($doc->sac_workspaces as $workspace) { if (is_array($workspace->sac_collections)) { foreach ($workspace->sac_collections as $collection) { $depositPoints["{$collection->sac_href}"] = "{$collection->sac_colltitle}"; } } } } $templateMgr->assign_by_ref('swordDepositPoints', $depositPoints); } $templateMgr->assign_by_ref('articles', $iterator); $templateMgr->display($this->getTemplatePath() . 'articles.tpl'); break; } }
} // Store the values if (isset($_POST['sdurl'])) { $_SESSION['sdurl'] = $_POST['sdurl']; } if (isset($_POST['u'])) { $_SESSION['u'] = $_POST['u']; } if (isset($_POST['p'])) { $_SESSION['p'] = $_POST['p']; } if (isset($_POST['obo'])) { $_SESSION['obo'] = $_POST['obo']; } // Try and load the service document $client = new SWORDAPPClient(); $response = $client->servicedocument($_SESSION['sdurl'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); if ($response->sac_status != 200) { $error = 'Unable to load service document. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage; $_SESSION['error'] = $error; header('Location: ../../'); die; } else { $_SESSION['error'] = ''; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - GET the Service Document</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' />
function index() { // A variable to hold an error message $error = ''; try { // Check to see if the packager directory exists, and if not // make the directory to save the files in $path = str_replace('index.php', '', $_SERVER["SCRIPT_FILENAME"]); $id = $this->userid; $savepath = $path . $this->config->item('easydeposit_uploadfiles_savedir') . $id; if (!file_exists($savepath)) { mkdir($savepath); } // Allow each step to contribute to the package require_once $this->config->item('easydeposit_librarylocation') . '/packager_mets_swap.php'; $package = new PackagerMetsSwap($this->config->item('easydeposit_uploadfiles_savedir'), $this->userid, $this->config->item('easydeposit_deposit_packages'), $this->userid . '.zip'); foreach ($this->easydeposit_steps as $stepname) { if ($stepname == 'multipledeposit') { break; } include_once APPPATH . 'controllers/' . $stepname . '.php'; $stepclass = ucfirst($stepname); call_user_func(array($stepclass, '_package'), $package); } $package->create(); // Deposit the package require_once $this->config->item('easydeposit_librarylocation') . '/swordappclient.php'; $counter = 0; foreach ($_SESSION['depositurls'] as $depositurl) { $sac = new SWORDAPPClient(); $contenttype = "application/zip"; $format = "http://purl.org/net/sword-types/METSDSpaceSIP"; $response = $sac->deposit($_SESSION['depositurls'][$counter], $_SESSION['sword-usernames'][$counter], $_SESSION['sword-passwords'][$counter], $_SESSION['sword-obos'][$counter], $this->config->item('easydeposit_deposit_packages') . $this->userid . '.zip', $format, $contenttype); if ($response->sac_status == 200 || $response->sac_status == 201) { $_SESSION['deposited-response'][$counter] = $response->sac_xml; $_SESSION['deposited-url'][$counter] = (string) $response->sac_id; } else { $error .= 'For deposit URL ' . $_SESSION['depositurls'][$counter] . "\n"; $error .= 'Server returned status code: ' . $response->sac_status . "\n\n"; $error .= 'Server provided response: ' . $response->sac_xml . "\n\n"; } $counter++; } } catch (Exception $e) { // Catch the exception for reporting $error = 'Error: ' . $e->getMessage() . "\n\n"; $error .= 'Deposit URL: ' . $_SESSION['depositurls'][$counter] . "\n"; $error .= 'Deposit username: '******'sword-usernames'][$counter] . "\n"; $error .= 'Package file: ' . $this->config->item('easydeposit_deposit_packages') . $this->userid . '.zip' . "\n"; if (!empty($response->sac_xml)) { $error .= "\n\nResponse:" . $response->sac_xml; } } // If there was an error, send it to the administrator if (!empty($error)) { $to = $this->config->item('easydeposit_supportemail'); $subject = 'Error with EasyDeposit system'; $headers = 'From: ' . $to . ' <' . $to . ">\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\r\n"; mail($to, $subject, $error, $headers); } // Go to the next stage $this->_gotonextstep(); }
<?php require_once '../../swordappclient.php'; // Settings $atom = 'atom.xml'; $contentzip = 'content.zip'; $metadatazip = 'metadata.zip'; $servicedocument = 'http://demo.dspace.org/swordv2/servicedocument'; $depositlocation = 'http://demo.dspace.org/swordv2/collection/10673/11'; $dspacerest = 'https://demo.dspace.org/rest'; $user = '******'; $password = '******'; // Initiatiate the SWORD client $sword = new SWORDAPPClient(); // Get the service document print "About to request servicedocument from " . $servicedocument . "\n"; $sd = $sword->servicedocument($servicedocument, $user, $password, ''); print "Received HTTP status code: " . $sd->sac_status . " (" . $sd->sac_statusmessage . ")\n"; if ($sd->sac_status == 200) { $sd->toString(); } print "\n\n"; // Create the item by depositing an atom document print "About to create new item at " . $depositlocation . "\n"; $response = $sword->depositAtomEntry($depositlocation, $user, $password, '', $atom, $sac_inprogress = true); print "Received HTTP status code: " . $response->sac_status . " (" . $response->sac_statusmessage . ")\n"; if ($response->sac_status >= 200 || $response->sac_status < 300) { $response->toString(); } $edit_iri = $response->sac_edit_iri; $edit_media = $response->sac_edit_media_iri;
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Try and load the file session_start(); $client = new SWORDAPPClient(); $response = $client->get($_POST['uri'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - GET a URI</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' /> </head> <body> <div id="header"> <h1>SWORD v2 exerciser</h1> </div> <?php if (!empty($errormsg)) { ?> <div class="error"><?php echo $errormsg; ?> </div><?php } ?>
private function _depositatomtwostep() { $response = ''; $editmediairi = ''; try { $package = new PackagerAtomTwoStep($this->config->item('easydeposit_uploadfiles_savedir'), $this->userid, $this->config->item('easydeposit_deposit_packages'), $this->userid . '.multipart'); foreach ($this->easydeposit_steps as $stepname) { if ($stepname == 'deposit') { break; } include_once APPPATH . 'controllers/' . $stepname . '.php'; $stepclass = ucfirst($stepname); call_user_func(array($stepclass, '_packagemultipart'), $package); } $package->create(); // Deposit the atom entry, leave 'in progress' $sac = new SWORDAPPClient(); $response = $sac->depositAtomEntry($_SESSION['depositurl'], $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo'], $this->config->item('easydeposit_deposit_packages') . $this->userid . '/atom', true); if ($response->sac_status >= 200 && $response->sac_status < 300) { $_SESSION['deposited-response'] = $response->sac_xml; $_SESSION['deposited-url'] = (string) $response->sac_id; $editmediairi = $response->sac_edit_media_iri; } else { $error = 'Server returned status code: ' . $response->sac_status . "\n\n"; $error .= 'Server provided response: ' . $response->sac_xml; } echo '3'; // Deposit each file $counter = 0; $inprogress = True; foreach ($package->getFiles() as $file) { echo $counter; $counter++; if ($counter == count($package->getFiles())) { $inprogress = False; } $response = $sac->addExtraFileToMediaResource($editmediairi, $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo'], $this->config->item('easydeposit_deposit_packages') . $this->userid . '/' . $file, $inprogress); } $response = $sac->completeIncompleteDeposit($editmediairi, $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo']); echo '5'; echo $response; die; } catch (Exception $e) { // Catch the exception for reporting $error = 'Error: ' . $e->getMessage() . "\n\n"; $error .= 'Deposit URL: ' . $_SESSION['depositurl'] . "\n"; $error .= 'Deposit username: '******'sword-username'] . "\n"; $error .= 'Package file: ' . $this->config->item('easydeposit_deposit_packages') . $this->userid . '.zip' . "\n"; if (!empty($response->sac_xml)) { $error .= "\n\nResponse:" . $response->sac_xml; } $_SESSION['deposited-response'] = $error; } // If there was an error, send it to the administrator if (!empty($error)) { $to = $this->config->item('easydeposit_supportemail'); $subject = 'Error with EasyDeposit system'; $headers = 'From: ' . $to . ' <' . $to . ">\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\r\n"; mail($to, $subject, $error, $headers); } }
function _getservicedocument($str) { // Clear out old session data related to the service document $_SESSION['servicedocumenturl'] = ''; $_SESSION['servicedocumentxml'] = ''; $_SESSION['servicedocumentstatuscode'] = ''; // Try and get the service document // If we succeed, store the xml in the SESSION for future steps // If we fail, report so try { $swordappclient = new SWORDAPPClient(); $urls = $this->config->item('easydeposit_selectrepository_list'); if (!empty($_POST['otherurl'])) { $url = $_POST['otherurl']; } else { if (isset($_POST['url'])) { $url = $_POST['url']; $url = str_replace('/client/client/', '/client/', $url); if (is_numeric($_POST['url'])) { $url = $urls[$_POST['url']]; } } else { $this->form_validation->set_message('_getservicedocument', 'No Service Document URL provided'); return FALSE; } } $servicedocument = $swordappclient->servicedocument($url, $_POST['username'], $_POST['password'], $_POST['obo']); if ($servicedocument->sac_status == 200) { // Store the service document in the session $_SESSION['servicedocumenturl'] = $url; $_SESSION['servicedocumentxml'] = $servicedocument->sac_xml; $_SESSION['servicedocumentstatuscode'] = $servicedocument->sac_status; // Store the username / password / obo in the session $_SESSION['sword-username'] = $_POST['username']; $_SESSION['sword-password'] = $_POST['password']; $_SESSION['sword-obo'] = $_POST['obo']; return TRUE; } else { $this->form_validation->set_message('_getservicedocument', $servicedocument->sac_statusmessage); return FALSE; } } catch (Exception $e) { $this->form_validation->set_message('_getservicedocument', 'An error occurred when trying to parse the service document: ' . $e); return FALSE; } }
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Store the values session_start(); // Try and deposit the multipart package $client = new SWORDAPPClient(); $response = $client->depositAtomEntry($_SESSION['durl'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo'], $_SESSION['filename'], $_SESSION['inprogress']); if ($response->sac_status != 201) { $error = 'Unable to deposit package. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage; $_SESSION['error'] = $error; } else { $_SESSION['error'] = ''; } // Show the response include '../../common/depositresponse.php';
// The user (if required) $testuser = "******"; // The password of the user (if required) $testpw = "sword-user"; // The on-behalf-of user (if required) //$testobo = "*****@*****.**"; // The URL of the example deposit collection $testdepositurl = "http://client.swordapp.org/client/deposit/sword-user"; // The test file to deposit $testfile = "test-files/sword-article.zip"; // The content type of the test file $testcontenttype = "application/zip"; // The packaing format of the test fifle $testformat = "http://purl.org/net/sword-types/METSDSpaceSIP"; require "swordappclient.php"; $testsac = new SWORDAPPClient(); if (true) { print "About to request servicedocument from " . $testurl . "\n"; if (empty($testuser)) { print "As: anonymous\n"; } else { print "As: " . $testuser . "\n"; } $testsdr = $testsac->servicedocument($testurl, $testuser, $testpw, $testobo); print "Received HTTP status code: " . $testsdr->sac_status . " (" . $testsdr->sac_statusmessage . ")\n"; if ($testsdr->sac_status == 200) { print " - Version: " . $testsdr->sac_version . "\n"; print " - Supports Verbose: " . $testsdr->sac_verbose . "\n"; print " - Supports NoOp: " . $testsdr->sac_noop . "\n"; print " - Maximum uplaod size: "; if (!empty($testsdr->sac_maxuploadsize)) {
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Store the values session_start(); // Try and delete the edit-iri package $client = new SWORDAPPClient(); $response = $client->deleteContainer($_POST['editiri'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); if ($response->sac_status != 204) { $error = 'Unable to delete container. HTTP response code: ' . $response->sac_status; } else { $_SESSION['error'] = ''; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - DELETE a container</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' /> </head> <body> <div id="header"> <h1>SWORD v2 exerciser</h1> </div> <div class="section"> <h2>Response:</h2> <pre>Status code: <?php
/** * Deposit the package. * @param $url string SWORD deposit URL * @param $username string SWORD deposit username (i.e. email address for DSPACE) * @param $password string SWORD deposit password */ function deposit($url, $username, $password) { $client = new SWORDAPPClient(); $response = $client->deposit($url, $username, $password, '', $this->outPath . '/deposit.zip', 'http://purl.org/net/sword-types/METSDSpaceSIP', 'application/zip', false, true); return $response; }
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Store the values session_start(); // Try and complete the incomplete deposit $client = new SWORDAPPClient(); $response = $client->completeIncompleteDeposit($_SESSION['seiri'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); if ($response->sac_status != 200) { $error = 'Unable to deposit package. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage; $_SESSION['error'] = $error; } else { $_SESSION['error'] = ''; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - Complete an incomplete deposit</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' /> </head> <body> <div id="header"> <h1>SWORD v2 exerciser</h1> </div> <?php if (!empty($errormsg)) {
<?php // Load the PHP library include_once '../../../../swordappclient.php'; include_once '../../utils.php'; // Store the values session_start(); // Try and delete the edit-iri package $client = new SWORDAPPClient(); $response = $client->deleteResourceContent($_POST['editmediairi'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); if ($response->sac_status != 204) { $error = 'Unable to delete content. HTTP response code: ' . $response->sac_status; } else { $_SESSION['error'] = ''; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - DELETE a resource container</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' /> </head> <body> <div id="header"> <h1>SWORD v2 exerciser</h1> </div> <div class="section"> <h2>Response:</h2> <pre>Status code: <?php
$mimetype = $type[(int) $info->parts[$counter]->type] . '/' . $info->parts[$counter]->subtype; $mimetype = strtolower($mimetype); echo " - File: {$filename} ({$mimetype})... "; $fullfilename = 'tmp/attachments/' . $uid . '/' . $filename; $file = 'tmp/attachments/' . $uid . '/mail.txt'; imap_savebody($inbox, $file, $message->msgno); $parser = new MimeMailParser(); $parser->setPath($file); $attachments = $parser->getAttachmentsAsStreams(); file_put_contents($fullfilename, $attachments[$counter - 1]); echo "done\n"; $package->addFile($filename, $mimetype); $counter++; } // Deposit the package $package->create(); $client = new SWORDAPPClient(); $response = $client->deposit($swordurl, $sworduser, $swordpassword, '', 'tmp/' . $packagefilename, 'http://purl.org/net/sword-types/METSDSpaceSIP', 'application/zip', false, true); // print_r($response); $id = $response->sac_id; $id = str_replace("http://hdl.handle.net/", "http://dspace.swordapp.org/jspui/handle/", $id); echo "Deposited at " . $id . "\n\n"; $to = $message->from; $from = "From: " . $mailuser; $subject = "Deposit successful: " . $id; $contents = "Thanks you for your deposit. It can be viewed at " . $id; mail($to, $subject, $contents, $from); // Mark the message as read imap_setflag_full($inbox, $message->msgno, "\\Seen"); } }
function _getDepositableDepositPoints() { import('classes.sword.OJSSwordDeposit'); $depositPoints = $this->swordPlugin->getSetting($this->article->getJournalId(), 'depositPoints'); foreach ($depositPoints as $key => $depositPoint) { $type = $depositPoint['type']; if ($type == SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION) { // Get a list of supported deposit points $client = new SWORDAPPClient(); $doc = $client->servicedocument($depositPoint['url'], $depositPoint['username'], $depositPoint['password'], ''); $points = array(); foreach ($doc->sac_workspaces as $workspace) { foreach ($workspace->sac_collections as $collection) { $points["{$collection->sac_href}"] = "{$collection->sac_colltitle}"; } } unset($client); unset($doc); $depositPoints[$key]['depositPoints'] = $points; } elseif ($type == SWORD_DEPOSIT_TYPE_OPTIONAL_FIXED) { // Don't need to do anything special } else { unset($depositPoints[$key]); } } return $depositPoints; }