Beispiel #1
0
 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;
 }