function returnTitle() { $recordId = $_REQUEST['id']; $itemId = $_REQUEST['itemId']; require_once ROOT_DIR . '/RecordDrivers/PublicEContentDriver.php'; $recordDriver = new PublicEContentDriver($recordId); $result = $recordDriver->returnTitle($itemId); return json_encode($result); }
function launch() { global $configArray; $id = $_REQUEST['id']; $file = $_REQUEST['file']; //Check the database to see if there is an existing title $recordDriver = new PublicEContentDriver($id); $restrictedDriver = new RestrictedEContentDriver($id); if (!$recordDriver->isValid() && !$restrictedDriver->isValid()) { $output = json_encode(array('error' => 'Invalid Record. The specified title does not exist.')); } else { $itemId = $_REQUEST['item']; if (!$recordDriver->isCheckedOut($itemId) && !$restrictedDriver->isCheckedOut($itemId)) { $output = json_encode(array('error' => 'This title is not checked out to you. Please checkout the title.')); } else { //TODO: Validate that this file belongs to the checked out record $libraryPath = $configArray['EContent']['library']; $bookFile = "{$libraryPath}/{$file}"; if (!file_exists($bookFile)) { $bookFile = null; $epubExists = false; } else { $epubExists = true; } require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); if ($epubExists) { if ($_GET['method'] == 'getComponentCustom') { //Content type will depend on the type of content created. $output = $this->{$_GET}['method']($ebook, $id, $itemId, $file); } else { header('Content-type: text/plain'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past if (is_callable(array($this, $_GET['method']))) { $output = json_encode(array('result' => $this->{$_GET}['method']($ebook, $id, $itemId, $file))); } else { $output = json_encode(array('error' => 'invalid_method ' . $_GET['method'])); } } } else { header('Content-type: text/plain'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $output = json_encode(array('error' => 'e-pub file does not exist')); } } } echo $output; }
/** * @param PublicEContentDriver $recordDriver */ function loadCitations($recordDriver) { global $interface; $citationCount = 0; $formats = $recordDriver->getCitationFormats(); foreach ($formats as $current) { $interface->assign(strtolower($current), $recordDriver->getCitation($current)); $citationCount++; } $interface->assign('citationCount', $citationCount); }
/** * Download a file from the server so a user can use it locally. **/ function launch() { global $interface; global $configArray; global $user; $id = $_REQUEST['id']; $interface->assign('id', $id); $recordDriver = new PublicEContentDriver($id); if (!$recordDriver->isValid()) { $interface->setTemplate('../Record/invalidRecord.tpl'); $interface->display('layout.tpl'); die; } else { $interface->assign('recordDriver', $recordDriver); $itemId = $_REQUEST['itemId']; if ($user == false) { $interface->assign('errorMessage', 'Sorry, you must be logged in to download this title.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { if (!$recordDriver->isCheckedOut($itemId)) { $interface->assign('errorMessage', "You must checkout this title before you download it, please <a href='{$configArray['Site']['path']}/PublicEContent/{$id}/Checkout'>click here</a> to checkout the title."); $errorOccurred = true; $interface->assign('showLogin', false); } else { $errorOccurred = false; $filename = $_REQUEST['file']; $bookFile = $configArray['EContent']['library'] . '/' . $filename; if (file_exists($bookFile)) { global $user; //Record that the e-pub file is being downloaded. require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php'; $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->itemId = $itemId; $entry->action = 'Download'; //Open date will be filled out automatically. $entry->insert(); $fileExtension = ''; if (strpos($bookFile, '.') !== FALSE) { $fileExtension = substr($bookFile, strrpos($bookFile, '.') + 1); } if (strcasecmp($fileExtension, 'epub') == 0) { require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); //Return the contents of the epub file header("Content-Type: application/epub+zip;\n"); //header('Content-Length: ' . filesize($bookFile)); header('Content-Description: ' . $ebook->getTitle()); //header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); die; } else { if (strcasecmp($fileExtension, 'pdf') == 0) { header("Content-Type: application/pdf;\n"); header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'mobi') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'pdb') == 0) { header('Content-Length: ' . filesize($bookFile)); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'txt') == 0) { header("Content-Type: text/plain;\n"); header('Content-Length: ' . filesize($bookFile)); header('Content-Disposition: attachment; filename="' . basename($bookFile) . '"'); readfile($bookFile); exit; } else { if (strcasecmp($fileExtension, 'mp3') == 0) { $id = $_REQUEST['id']; $interface->assign('id', $id); $item = $_REQUEST['item']; $interface->assign('item', $item); //Get all of the MP3 files that $dirHnd = opendir($bookFile); $mp3Files = array(); while (false !== ($file = readdir($dirHnd))) { if (preg_match('/^.*?\\.mp3$/i', $file)) { $mp3Files[] = array('name' => preg_replace('/\\.mp3/i', '', $file), 'size' => filesize($bookFile . '/' . $file)); } } $files = readdir($dirHnd); closedir($dirHnd); //Sort the mp3 files by name. sort($mp3Files); $interface->assign('mp3Filenames', $mp3Files); $interface->display('EcontentRecord/download-mp3.tpl'); exit; } } } } } } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Sorry, we could not find that title in our online library.'); } } } } $interface->assign('errorOccurred', $errorOccurred); // Display Page $interface->assign('sidebar', 'PublicEContent/full-record-sidebar.tpl'); $interface->setTemplate('download-error.tpl'); $interface->display('layout.tpl'); }
function launch() { global $interface; global $configArray; global $user; $id = $_REQUEST['id']; $interface->assign('id', $id); $itemId = $_REQUEST['itemId']; $interface->assign('itemId', $itemId); $file = $_REQUEST['file']; $interface->assign('file', $file); $recordDriver = new PublicEContentDriver($id); $isAudio = false; if (!$recordDriver->isValid()) { $interface->setTemplate('../Record/invalidRecord.tpl'); $interface->display('layout.tpl'); die; } else { $interface->assign('recordDriver', $recordDriver); $itemId = $_REQUEST['itemId']; $errorOccurred = false; if ($user == false) { $interface->assign('errorMessage', 'Sorry, you must be logged in to view this title.'); $errorOccurred = true; $interface->assign('showLogin', true); } else { if (!$recordDriver->isCheckedOut($itemId)) { $interface->assign('errorMessage', "You must checkout this title before you view it, please <a href='{$configArray['Site']['path']}/PublicEContent/{$id}/Checkout'>click here</a> to checkout the title."); $errorOccurred = true; $interface->assign('showLogin', false); } else { require_once ROOT_DIR . '/sys/eContent/EContentRecord.php'; $filename = $_REQUEST['file']; $bookFile = $configArray['EContent']['library'] . '/' . $filename; if (file_exists($bookFile)) { //Check the database to see if there is an existing title $fileExtension = ''; if (strpos($bookFile, '.') !== FALSE) { $fileExtension = substr($bookFile, strrpos($bookFile, '.') + 1); } //Record that the title is being viewed. require_once ROOT_DIR . '/sys/eContent/EContentHistoryEntry.php'; $entry = new EContentHistoryEntry(); $entry->userId = $user->id; $entry->recordId = $id; $entry->itemId = $itemId; $entry->action = 'Read Online'; //Open date will be filled out automatically. $entry->insert(); if ($fileExtension == 'epub') { require_once ROOT_DIR . '/sys/eReader/ebook.php'; $ebook = new ebook($bookFile); if ($ebook->readErrorOccurred()) { $errorOccurred = true; $interface->assign('errorMessage', $ebook->readError()); } else { $spineInfo = $ebook->getSpine(); $toc = $ebook->getTOC(); $interface->assign('spineData', $spineInfo); $interface->assign('contents', $toc); $interface->assign('bookCreator', $ebook->getDcCreator()); //Load a translation map to translate locations into ids $manifest = array(); for ($i = 0; $i < $ebook->getManifestSize(); $i++) { $manifestId = $ebook->getManifestItem($i, 'id'); $manifestHref = $ebook->getManifestItem($i, 'href'); $manifestType = $ebook->getManifestItem($i, 'type'); $manifest[$manifestHref] = $manifestId; } $interface->assign('manifest', $manifest); $interface->assign('bookTitle', $ebook->getTitle()); $errorOccurred = false; } } elseif ($fileExtension == 'txt') { header("Content-Type: text/plain;\n"); header('Content-Length: ' . filesize($bookFile)); readfile($bookFile); exit; } elseif (is_dir($bookFile)) { //A folder of mp3 files? //Display information so patron can listen to the recording. //Table of contents is based on the actual files uploaded. $isAudio = true; $dirHnd = opendir($bookFile); $mp3Files = array(); while (false !== ($file = readdir($dirHnd))) { if (preg_match('/^.*?\\.mp3$/i', $file)) { $mp3Files[] = preg_replace('/\\.mp3/i', '', $file); } } $files = readdir($dirHnd); closedir($dirHnd); //Sort the mp3 files by name. sort($mp3Files); $interface->assign('mp3Filenames', $mp3Files); } } else { $errorOccurred = true; $interface->assign('errorMessage', 'Sorry, we could not find that title in our online library.'); } } $interface->assign('errorOccurred', $errorOccurred); if ($isAudio) { $interface->display('EcontentRecord/viewer-mp3.tpl'); } else { $interface->display('EcontentRecord/viewer-custom.tpl'); } } } }