private function _depositmetsswap() { $response = ''; try { $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 == 'deposit') { break; } include_once APPPATH . 'controllers/' . $stepname . '.php'; $stepclass = ucfirst($stepname); call_user_func(array($stepclass, '_package'), $package); } $package->create(); // Deposit the package $sac = new SWORDAPPClient(); $contenttype = "application/zip"; $format = "http://purl.org/net/sword-types/METSDSpaceSIP"; $response = $sac->deposit($_SESSION['depositurl'], $_SESSION['sword-username'], $_SESSION['sword-password'], $_SESSION['sword-obo'], $this->config->item('easydeposit_deposit_packages') . $this->userid . '.zip', $format, $contenttype); if ($response->sac_status >= 200 && $response->sac_status < 300) { $_SESSION['deposited-response'] = $response->sac_xml; $_SESSION['deposited-url'] = (string) $response->sac_id; } else { $error = 'Server returned status code: ' . $response->sac_status . "\n\n"; $error .= 'Server provided response: ' . $response->sac_xml; } } 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); } }
/** * 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; }
$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"); } }
if (!empty($collection->sac_service)) { echo " - Service document: " . $collection->sac_service . "\n"; } } } } } print "\n\n"; if (true) { print "About to deposit file (" . $testfile . ") to " . $testdepositurl . "\n"; if (empty($testuser)) { print "As: anonymous\n"; } else { print "As: " . $testuser . "\n"; } $testdr = $testsac->deposit($testdepositurl, $testuser, $testpw, $testobo, $testfile, $testformat, $testcontenttype); print "Received HTTP status code: " . $testdr->sac_status . " (" . $testdr->sac_statusmessage . ")\n"; if ($testdr->sac_status == 201) { print " - ID: " . $testdr->sac_id . "\n"; print " - Title: " . $testdr->sac_title . "\n"; print " - Content: " . $testdr->sac_content_src . " (" . $testdr->sac_content_type . ")\n"; foreach ($testdr->sac_authors as $author) { print " - Author: " . $author . "\n"; } foreach ($testdr->sac_contributors as $contributor) { print " - Contributor: " . $contributor . "\n"; } foreach ($testdr->sac_links as $link) { print " - Link: " . $link . "\n"; } print " - Summary: " . $testdr->sac_summary . "\n";
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(); }