示例#1
0
 function launch()
 {
     global $interface;
     global $timer;
     global $logger;
     global $user;
     //Build the actual view
     $interface->setTemplate('view-series.tpl');
     $id = $_REQUEST['id'];
     require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
     $recordDriver = new GroupedWorkDriver($id);
     if (!$recordDriver->isValid) {
         $logger->log("Did not find a record for id {$id} in solr.", PEAR_LOG_DEBUG);
         $interface->setTemplate('invalidRecord.tpl');
         $interface->display('layout.tpl');
         die;
     }
     $timer->logTime('Initialized the Record Driver');
     $novelist = NovelistFactory::getNovelist();
     $seriesData = $novelist->getSeriesTitles($id, $recordDriver->getISBNs());
     //Loading the series title is not reliable.  Do not try to load it.
     $seriesTitle = null;
     $seriesAuthors = array();
     $resourceList = array();
     $seriesTitles = $seriesData->seriesTitles;
     $recordIndex = 1;
     if (isset($seriesTitles) && is_array($seriesTitles)) {
         foreach ($seriesTitles as $key => $title) {
             if (isset($title['series']) && strlen($title['series']) > 0 && !isset($seriesTitle)) {
                 $seriesTitle = $title['series'];
                 $interface->assign('seriesTitle', $seriesTitle);
             }
             if (isset($title['author'])) {
                 $author = preg_replace('/[^\\w]*$/i', '', $title['author']);
                 $seriesAuthors[$author] = $author;
             }
             $interface->assign('recordIndex', $recordIndex);
             $interface->assign('resultIndex', $recordIndex++);
             if ($title['libraryOwned']) {
                 /** @var GroupedWorkDriver $tmpRecordDriver */
                 $tmpRecordDriver = $title['recordDriver'];
                 $resourceList[] = $interface->fetch($tmpRecordDriver->getSearchResult($user, null, false));
             } else {
                 $interface->assign('record', $title);
                 $resourceList[] = $interface->fetch('RecordDrivers/Index/nonowned_result.tpl');
             }
         }
     }
     $interface->assign('seriesAuthors', $seriesAuthors);
     $interface->assign('recordSet', $seriesTitles);
     $interface->assign('resourceList', $resourceList);
     $interface->assign('recordStart', 1);
     $interface->assign('recordEnd', count($seriesTitles));
     $interface->assign('recordCount', count($seriesTitles));
     $interface->assign('recordDriver', $recordDriver);
     $interface->assign('sidebar', 'GroupedWork/full-record-sidebar.tpl');
     $interface->setPageTitle($seriesTitle);
     // Display Page
     $interface->display('layout.tpl');
 }
示例#2
0
 static function getNovelistRecommendations($userRating, $isbn, $resource, $allRatedTitles, &$suggestions, $notInterestedTitles)
 {
     //We now have the title, we can get the related titles from Novelist
     $novelist = NovelistFactory::getNovelist();
     //Use loadEnrichmentInfo even though there is more data than we need since it uses caching.
     $enrichmentInfo = $novelist->loadEnrichment($isbn);
     $numRecommendations = 0;
     if (isset($enrichmentInfo['similarTitleCountOwned']) && $enrichmentInfo['similarTitleCountOwned'] > 0) {
         //For each related title
         foreach ($enrichmentInfo['similarTitles'] as $similarTitle) {
             if ($similarTitle['libraryOwned']) {
                 Suggestions::addTitleToSuggestions($userRating, $resource->title, $resource->record_id, $similarTitle, $allRatedTitles, $suggestions, $notInterestedTitles);
                 $numRecommendations++;
             }
         }
     }
     return $numRecommendations;
 }
示例#3
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $library;
     // Initialise from the current search globals
     $searchObject = SearchObjectFactory::initSearchObject();
     $searchObject->init();
     // Build RSS Feed for Results (if requested)
     if ($searchObject->getView() == 'rss') {
         // Throw the XML to screen
         echo $searchObject->buildRSS();
         // And we're done
         exit;
     }
     $interface->caching = false;
     if (!isset($_GET['author'])) {
         PEAR_Singleton::raiseError(new PEAR_Error('Unknown Author'));
     } else {
         $interface->assign('author', $_GET['author']);
     }
     // What language should we use?
     $this->lang = $configArray['Site']['language'];
     // Retrieve User Search History -- note that we only want to offer a
     // "back to search" link if the saved URL is not for the current action;
     // when users first reach this page from search results, the "last URL"
     // will be their original search, which we want to link to.  However,
     // since this module will later set the "last URL" value in order to
     // allow the user to return from a record view to this page, after they
     // return here, we will no longer have access to the last non-author
     // search, and it is better to display nothing than to provide an infinite
     // loop of links.  Perhaps this can be solved more elegantly with a stack
     // or with multiple session variables, but for now this seems okay.
     $interface->assign('lastsearch', isset($_SESSION['lastSearchURL']) && !strstr($_SESSION['lastSearchURL'], 'Author/Home') ? $_SESSION['lastSearchURL'] : false);
     $interface->assign('lookfor', $_GET['author']);
     $interface->assign('basicSearchIndex', 'Author');
     $interface->assign('searchIndex', 'Author');
     if (!$interface->is_cached('layout.tpl|Author' . $_GET['author'])) {
         // Clean up author string
         $author = $_GET['author'];
         if (substr($author, strlen($author) - 1, 1) == ",") {
             $author = substr($author, 0, strlen($author) - 1);
         }
         $author = explode(',', $author);
         $interface->assign('author', $author);
         // Create First Name
         $fname = '';
         if (isset($author[1])) {
             $fname = $author[1];
             if (isset($author[2])) {
                 // Remove punctuation
                 if (strlen($author[2]) > 2 && substr($author[2], -1) == '.') {
                     $author[2] = substr($author[2], 0, -1);
                 }
                 $fname = $author[2] . ' ' . $fname;
             }
         }
         // Remove dates
         $fname = preg_replace('/[0-9]+-[0-9]*/', '', $fname);
         // Build Author name to display.
         if (substr($fname, -3, 1) == ' ') {
             // Keep period after initial
             $authorName = $fname . ' ';
         } else {
             // No initial so strip any punctuation from the end
             if (substr(trim($fname), -1) == ',' || substr(trim($fname), -1) == '.') {
                 $authorName = substr(trim($fname), 0, -1) . ' ';
             } else {
                 $authorName = $fname . ' ';
             }
         }
         $authorName .= $author[0];
         $interface->assign('authorName', trim($authorName));
         // Pull External Author Content
         if ($searchObject->getPage() == 1) {
             // Only load Wikipedia info if turned on in config file:
             if (isset($configArray['Content']['authors']) && stristr($configArray['Content']['authors'], 'wikipedia') && (!$library || $library->showWikipediaContent == 1)) {
                 // Only use first two characters of language string; Wikipedia
                 // uses language domains but doesn't break them up into regional
                 // variations like pt-br or en-gb.
                 $wiki_lang = substr($configArray['Site']['language'], 0, 2);
                 $authorInfo = $this->getWikipedia($authorName, $wiki_lang);
                 $interface->assign('wiki_lang', $wiki_lang);
                 if (!PEAR_Singleton::isError($authorInfo)) {
                     $interface->assign('info', $authorInfo);
                 }
             }
         }
     }
     // Set Interface Variables
     //   Those we can construct BEFORE the search is executed
     $interface->setPageTitle('Author Search Results');
     $interface->assign('sortList', $searchObject->getSortList());
     $interface->assign('limitList', $searchObject->getLimitList());
     $interface->assign('viewList', $searchObject->getViewList());
     $interface->assign('rssLink', $searchObject->getRSSUrl());
     $interface->assign('filterList', $searchObject->getFilterList());
     // Process Search
     /** @var PEAR_Error|null $result */
     $result = $searchObject->processSearch(false, true);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result->getMessage());
     }
     // Some more variables
     //   Those we can construct AFTER the search is executed, but we need
     //   no matter whether there were any results
     $interface->assign('qtime', round($searchObject->getQuerySpeed(), 2));
     // Assign interface variables
     $summary = $searchObject->getResultSummary();
     $interface->assign('recordCount', $summary['resultTotal']);
     $interface->assign('recordStart', $summary['startRecord']);
     $interface->assign('recordEnd', $summary['endRecord']);
     $interface->assign('sideRecommendations', $searchObject->getRecommendationsTemplates('side'));
     //Enable and disable functionality based on library settings
     global $library;
     global $locationSingleton;
     $location = $locationSingleton->getActiveLocation();
     if (isset($library) && $location != null) {
         $interface->assign('showFavorites', $library->showFavorites);
         $interface->assign('showHoldButton', $location->showHoldButton == 1 && $library->showHoldButton == 1 ? 1 : 0);
     } else {
         if ($location != null) {
             $interface->assign('showFavorites', 1);
             $interface->assign('showHoldButton', $location->showHoldButton);
         } else {
             if (isset($library)) {
                 $interface->assign('showFavorites', $library->showFavorites);
                 $interface->assign('showHoldButton', $library->showHoldButton);
             } else {
                 $interface->assign('showFavorites', 1);
                 $interface->assign('showHoldButton', 1);
             }
         }
     }
     // Big one - our results
     $authorTitles = $searchObject->getResultRecordHTML();
     $interface->assign('recordSet', $authorTitles);
     //Load similar author information.
     $authorIsbn = null;
     foreach ($authorTitles as $title) {
         if (isset($title['isbn'])) {
             if (is_array($title['isbn'])) {
                 $authorIsbn = $title['isbn'][0];
             } else {
                 $authorIsbn = $title['isbn'];
             }
             break;
         }
     }
     if (!is_null($authorIsbn)) {
         //Make sure to trim off any format information from the ISBN
         $isbnParts = explode(' ', $authorIsbn);
         $authorIsbn = $isbnParts[0];
         $novelist = NovelistFactory::getNovelist();
         $enrichment['novelist'] = $novelist->loadEnrichment($authorIsbn, false, false, true);
         if ($enrichment) {
             $interface->assign('enrichment', $enrichment);
         }
     }
     // Setup Display
     $interface->assign('sitepath', $configArray['Site']['path']);
     // Process Paging
     $link = $searchObject->renderLinkPageTemplate();
     $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']);
     $pager = new VuFindPager($options);
     $interface->assign('pageLinks', $pager->getLinks());
     // Save the ID of this search to the session so we can return to it easily:
     $_SESSION['lastSearchId'] = $searchObject->getSearchId();
     // Save the URL of this search to the session so we can return to it easily:
     $_SESSION['lastSearchURL'] = $searchObject->renderSearchUrl();
     //Get view & load template
     $currentView = $searchObject->getView();
     $interface->assign('subpage', 'Search/list-' . $currentView . '.tpl');
     $interface->setTemplate('home.tpl');
     $interface->display('layout.tpl', 'Author' . $_GET['author']);
 }
示例#4
0
 function GetSeriesInfo()
 {
     require_once ROOT_DIR . '/sys/NovelistFactory.php';
     $novelist = NovelistFactory::getNovelist();
     $isbns = $_REQUEST['isbn'];
     $seriesInfo = array();
     foreach ($isbns as $isbn) {
         $enrichment = $novelist->loadEnrichment($isbn);
         if (isset($enrichment['seriesTitle'])) {
             $seriesInfo[$isbn] = "<a href='/Search/Results?sort=year&lookfor=series:" . urlencode($enrichment['seriesTitle']) . "'>{$enrichment['seriesTitle']}</a>";
             if (isset($enrichment['volumeLabel']) && strlen($enrichment['volumeLabel']) > 0) {
                 $seriesInfo[$isbn] .= ', ' . $enrichment['volumeLabel'];
             }
         }
     }
     echo json_encode(array('success' => true, 'series' => $seriesInfo));
 }
示例#5
0
 /**
  * novelist
  *
  * This method is responsible for fetching enrichment information from NoveList
  * uses the REST Interface provided by NoveList
  *
  * @param   string    $isbn The ISBN to return data for
  * @return  array       Returns array with enrichment information, otherwise a
  *                      PEAR_Error.
  * @access  public
  * @author  Mark Noble <*****@*****.**>
  */
 function novelist($isbn)
 {
     $novelist = NovelistFactory::getNovelist();
     return $novelist->loadEnrichment($isbn);
 }
 public function loadEnrichment()
 {
     $isbn = $this->getCleanISBN();
     $enrichment = array();
     if ($isbn == null || strlen($isbn) == 0) {
         return $enrichment;
     }
     $novelist = NovelistFactory::getNovelist();
     $enrichment['novelist'] = $novelist->loadEnrichment($this->getPermanentId(), $this->getISBNs());
     return $enrichment;
 }
示例#7
0
 /**
  * Load information from the review provider and update the interface with the data.
  *
  * @return array       Returns array with review data, otherwise a
  *                      PEAR_Error.
  */
 static function loadReviews($id, $isbn, $includeEditorial = false)
 {
     global $interface;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     $reviews = $memCache->get("reviews_{$isbn}");
     if (!$reviews || isset($_REQUEST['reload'])) {
         // Fetch from provider
         if (isset($configArray['Content']['reviews'])) {
             $providers = explode(',', $configArray['Content']['reviews']);
             foreach ($providers as $provider) {
                 $provider = explode(':', trim($provider));
                 $func = strtolower($provider[0]);
                 $key = $provider[1];
                 $reviews[$func] = Record_Reviews::$func($isbn, $key);
                 // If the current provider had no valid reviews, store nothing:
                 if (empty($reviews[$func]) || PEAR_Singleton::isError($reviews[$func])) {
                     unset($reviews[$func]);
                 } else {
                     if (is_array($reviews[$func])) {
                         foreach ($reviews[$func] as $key => $reviewData) {
                             $reviews[$func][$key] = Record_Reviews::cleanupReview($reviews[$func][$key]);
                         }
                     } else {
                         $reviews[$func] = Record_Reviews::cleanupReview($reviews[$func]);
                     }
                 }
             }
         }
         $memCache->set("reviews_{$isbn}", $reviews, 0, $configArray['Caching']['purchased_reviews']);
     }
     //Load Editorial Reviews
     if ($includeEditorial) {
         if (isset($id)) {
             $recordId = $id;
             $editorialReview = new EditorialReview();
             $editorialReviewResults = array();
             $editorialReview->whereAdd("recordId = '{$recordId}'");
             $editorialReview->find();
             if ($editorialReview->N > 0) {
                 while ($editorialReview->fetch()) {
                     $editorialReviewResults[] = clone $editorialReview;
                 }
             }
             //$reviews["editorialReviews"] = array();
             if (count($editorialReviewResults) > 0) {
                 foreach ($editorialReviewResults as $key => $result) {
                     $reviews["editorialReviews"][$key]["Content"] = $result->review;
                     $reviews["editorialReviews"][$key]["Copyright"] = $result->source;
                     $reviews["editorialReviews"][$key]["Source"] = $result->source;
                     $reviews["editorialReviews"][$key]["ISBN"] = null;
                     $reviews["editorialReviews"][$key]["username"] = null;
                     $reviews["editorialReviews"][$key] = Record_Reviews::cleanupReview($reviews["editorialReviews"][$key]);
                     if ($result->teaser) {
                         $reviews["editorialReviews"][$key]["Teaser"] = $result->teaser;
                     }
                 }
             }
         }
     }
     //Load Reviews from Good Reads
     if ($isbn) {
         require_once ROOT_DIR . '/sys/NovelistFactory.php';
         $novelist = NovelistFactory::getNovelist();
         $enrichment = $novelist->loadEnrichment($isbn);
         if (isset($enrichment['goodReads'])) {
             $reviews['goodReads'] = $enrichment['goodReads'];
         }
     }
     if ($reviews) {
         if (!PEAR_Singleton::isError($reviews)) {
             $interface->assign('reviews', $reviews);
         } else {
             echo $reviews;
         }
     }
     return $reviews;
 }
示例#8
0
 function launch()
 {
     global $interface;
     global $user;
     //Enable and disable functionality based on library settings
     global $library;
     /** @var Location $locationSingleton */
     global $locationSingleton;
     $location = $locationSingleton->getActiveLocation();
     if (isset($library)) {
         if ($location != null) {
             $interface->assign('showHoldButton', $location->showHoldButton == 1 && $library->showHoldButton == 1 ? 1 : 0);
         } else {
             $interface->assign('showHoldButton', $library->showHoldButton);
         }
         $interface->assign('showTagging', $library->showTagging);
         $interface->assign('showRatings', $library->showRatings);
         $interface->assign('showComments', $library->showComments);
         $interface->assign('showFavorites', $library->showFavorites);
     } else {
         if ($location != null) {
             $interface->assign('showHoldButton', $location->showHoldButton);
         } else {
             $interface->assign('showHoldButton', 1);
         }
         $interface->assign('showTagging', 1);
         $interface->assign('showRatings', 1);
         $interface->assign('showComments', 1);
         $interface->assign('showFavorites', 1);
     }
     //$this->db->debug = true;
     $similar = $this->db->getMoreLikeThis2($this->id);
     // Send the similar items to the template; if there is only one, we need
     // to force it to be an array or things will not display correctly.
     if (isset($similar) && count($similar['response']['docs']) > 0) {
         $this->similarTitles = $similar['response']['docs'];
     } else {
         $this->similarTitles = array();
     }
     $resourceList = array();
     $curIndex = 0;
     $groupingTerms = array();
     if (isset($this->similarTitles) && is_array($this->similarTitles)) {
         foreach ($this->similarTitles as $title) {
             $groupingTerm = $title['grouping_term'];
             if (array_key_exists($groupingTerm, $groupingTerms)) {
                 continue;
             }
             $groupingTerms[$groupingTerm] = $groupingTerm;
             $interface->assign('resultIndex', ++$curIndex);
             $record = RecordDriverFactory::initRecordDriver($title);
             $resourceList[] = $interface->fetch($record->getSearchResult($user, null, false));
         }
     }
     $interface->assign('recordSet', $this->similarTitles);
     $interface->assign('resourceList', $resourceList);
     $interface->assign('recordStart', 1);
     $interface->assign('recordEnd', count($resourceList));
     $interface->assign('recordCount', count($resourceList));
     $novelist = NovelistFactory::getNovelist();
     $enrichment = $novelist->loadEnrichment($this->isbn);
     $interface->assign('enrichment', $enrichment);
     $interface->assign('id', $this->id);
     //Build the actual view
     $interface->setTemplate('view-similar.tpl');
     $interface->setPageTitle('Similar to ' . $this->record['title']);
     // Display Page
     $interface->display('layout.tpl');
 }