public function allAction() { $requestParams = $this->_request->getParams(); $host = App_Config::getHost(); $frontendOptions = array('lifetime' => 72000, 'automatic_serialization' => true); $backendOptions = array('cache_dir' => './bookdata/'); $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); $requestURI = $this->_request->getRequestUri(); // for testing $requestURI = str_replace("/", "_", $requestURI); $requestURI = str_replace(".", "_", $requestURI); if (isset($requestParams["callback"])) { $requestURI = str_replace("?", "", $requestURI); $requestURI = str_replace("callback=" . $requestParams["callback"], "", $requestURI); } $cache_id = $requestURI; if (isset($requestParams['avar'])) { $aVar = $requestParams['avar']; if ($aVar == ".json") { $books = new Books(); $books->get_all_books(); $outputArray = $books->bookData; unset($books); $output = Zend_Json::encode($outputArray); $this->_helper->viewRenderer->setNoRender(); if (isset($requestParams["callback"])) { header('Content-Type: application/javascript; charset=utf8'); $output = $requestParams["callback"] . "(" . $output . ");"; echo $output; } else { header('Content-Type: application/json; charset=utf8'); header("Access-Control-Allow-Origin: *"); echo $output; //outputs JSON of a given book's word cloud } } elseif (is_numeric($aVar)) { $book = $aVar; if (isset($requestParams['bvar'])) { if ($requestParams['bvar'] == "words.json") { if (!($cache_result = $cache->load($cache_id))) { $bookObj = new Book(); $bookObj->initialize($book); $bookObj->book = $book; $bookObj->get_book_meta(); $bookObj->getBookWordData(); $outputArray = $bookObj->wordSummary; $output = Zend_Json::encode($outputArray); $cache->save($output, $cache_id); } else { $output = $cache_result; } $this->_helper->viewRenderer->setNoRender(); if (isset($requestParams["callback"])) { header('Content-Type: application/javascript; charset=utf8'); $output = $requestParams["callback"] . "(" . $output . ");"; echo $output; } else { header('Content-Type: application/json; charset=utf8'); header("Access-Control-Allow-Origin: *"); echo $output; //outputs JSON of a given book's word cloud } } elseif ($requestParams['bvar'] == "page") { $failPageRequest = true; if (isset($requestParams['cvar'])) { if (stristr($requestParams['cvar'], ".json")) { $page = str_replace(".json", "", $requestParams['cvar']); if (is_numeric($page)) { $failPageRequest = false; $bookObj = new Book(); $bookObj->initialize($book); $bookObj->book = $book; $bookObj->page = $page; $bookObj->get_book_meta(); $bookObj->getBookPageData(); $outputArray = $bookObj->pageOutput; $output = Zend_Json::encode($outputArray); $this->_helper->viewRenderer->setNoRender(); if (isset($requestParams["callback"])) { header('Content-Type: application/javascript; charset=utf8'); $output = $requestParams["callback"] . "(" . $output . ");"; echo $output; } else { header('Content-Type: application/json; charset=utf8'); header("Access-Control-Allow-Origin: *"); echo $output; //outputs JSON of a given book's word cloud } } } } if ($failPageRequest) { $this->view->requestURI = $this->_request->getRequestUri(); return $this->render('404error'); } } } else { $bookObj = new Book(); $bookObj->initialize($book); $bookObj->get_book_meta(); $bookObj->getAllPlaces(); if (!$bookObj->bookURI) { $this->view->requestURI = $this->_request->getRequestUri(); return $this->render('404error'); } else { $this->view->book = $bookObj; return $this->render('summary'); } } } elseif (strlen($aVar) > 5 && stristr($aVar, ".json")) { $book = str_replace(".json", "", $requestParams['avar']); if (is_numeric($book)) { if (!($cache_result = $cache->load($cache_id))) { $bookObj = new Book(); $bookObj->initialize($book); $bookObj->get_book_meta(); $bookObj->getAllPlacesJSON(); $outputArray = array("id" => $bookObj->book, "title" => $bookObj->bookTitle, "uri" => $bookObj->bookURI, "author" => $bookObj->bookAuthors, "printed" => $bookObj->bookDate, "pages" => $bookObj->JSONpageArray, "places" => $bookObj->JSONplacesArray); $output = Zend_Json::encode($outputArray); $cache->save($output, $cache_id); } else { $output = $cache_result; } $this->_helper->viewRenderer->setNoRender(); if (isset($requestParams["callback"])) { header('Content-Type: application/javascript; charset=utf8'); $output = $requestParams["callback"] . "(" . $output . ");"; echo $output; } else { header('Content-Type: application/json; charset=utf8'); header("Access-Control-Allow-Origin: *"); echo $output; //outputs JSON of a given book's word cloud } } else { $this->view->requestURI = $this->_request->getRequestUri(); return $this->render('404error'); } } else { $this->view->requestURI = $this->_request->getRequestUri(); return $this->render('404error'); } } else { $this->_helper->viewRenderer->setNoRender(); echo "Index of books"; } }