Esempio n. 1
0
 /**
  * Do the actual work of loading the notes.
  *
  * @param string $isbn ISBN of book to find notes for
  *
  * @return array
  */
 public function __invoke($isbn)
 {
     // We can't proceed without an ISBN:
     if (empty($isbn)) {
         return array();
     }
     $this->config = ConfigReader::getConfig();
     $this->isbn = new ISBN($isbn);
     $results = array();
     // Fetch from provider
     if (isset($this->config->Content->authorNotes)) {
         $providers = explode(',', $this->config->Content->authorNotes);
         foreach ($providers as $provider) {
             $parts = explode(':', trim($provider));
             $provider = strtolower($parts[0]);
             $func = 'load' . ucwords($provider);
             $key = $parts[1];
             try {
                 $results[$provider] = method_exists($this, $func) ? $this->{$func}($key) : false;
                 // If the current provider had no valid notes, store nothing:
                 if (empty($results[$provider])) {
                     unset($results[$provider]);
                 }
             } catch (\Exception $e) {
                 // Ignore exceptions:
                 unset($results[$provider]);
             }
         }
     }
     return $results;
 }
Esempio n. 2
0
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     $this->searchIni = $this->facetsIni = 'WorldCat';
     parent::__construct();
     // Load the configuration file:
     $searchSettings = ConfigReader::getConfig($this->searchIni);
     // Search handler setup:
     $this->defaultHandler = 'srw.kw';
     if (isset($searchSettings->Basic_Searches)) {
         foreach ($searchSettings->Basic_Searches as $key => $value) {
             $this->basicHandlers[$key] = $value;
         }
     }
     if (isset($searchSettings->Advanced_Searches)) {
         foreach ($searchSettings->Advanced_Searches as $key => $value) {
             $this->advancedHandlers[$key] = $value;
         }
     }
     // Load sort preferences:
     if (isset($searchSettings->Sorting)) {
         foreach ($searchSettings->Sorting as $key => $value) {
             $this->sortOptions[$key] = $value;
         }
     }
     if (isset($searchSettings->General->default_sort)) {
         $this->defaultSort = $searchSettings->General->default_sort;
     }
     if (isset($searchSettings->DefaultSortingByType) && count($searchSettings->DefaultSortingByType) > 0) {
         foreach ($searchSettings->DefaultSortingByType as $key => $val) {
             $this->defaultSortByHandler[$key] = $val;
         }
     }
 }
Esempio n. 3
0
 /**
  * Connect to the index.
  *
  * @param string $type Index type to connect to (null for standard Solr).
  * @param string $core Index core to use (null for default).
  * @param string $url  Connection URL for index (null for config.ini default).
  *
  * @return object
  */
 public static function connectToIndex($type = null, $core = null, $url = null)
 {
     $configArray = ConfigReader::getConfig();
     // Load config.ini settings for missing parameters:
     if ($type == null) {
         $type = 'Solr';
     }
     if ($url == null) {
         // Load appropriate default server URL based on index type:
         $url = $type == 'SolrStats' && isset($configArray->Statistics->solr) ? $configArray->Statistics->solr : $configArray->Index->url;
     }
     // Set appropriate default core if necessary:
     if (empty($core) && $type == 'Solr') {
         $core = isset($configArray->Index->default_core) ? $configArray->Index->default_core : "biblio";
     }
     // Construct the object appropriately based on the $core setting:
     $class = 'VuFind\\Connection\\' . $type;
     if (empty($core)) {
         $index = new $class($url);
     } else {
         $index = new $class($url, $core);
     }
     // Set the service locator:
     $index->setServiceLocator(self::$serviceLocator);
     // Set the logger:
     $index->setLogger(self::$serviceLocator->get('Logger'));
     return $index;
 }
 /**
  * Prepare and direct the home page where it needs to go
  *
  * @return mixed
  */
 public function homeAction()
 {
     // Process login request, if necessary:
     if ($this->params()->fromPost('processLogin')) {
         try {
             $this->getAuthManager()->login($this->getRequest());
         } catch (AuthException $e) {
             $this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage());
         }
     }
     // Not logged in?  Force user to log in:
     if (!$this->getAuthManager()->isLoggedIn()) {
         return $this->forwardTo('MyResearch', 'Login');
     }
     // Logged in?  Forward user to followup action (if set) or default action
     // (if no followup provided):
     $followup = $this->followup()->retrieve();
     if (isset($followup->url)) {
         $url = $followup->url;
         unset($followup->url);
         return $this->redirect()->toUrl($url);
     }
     $config = ConfigReader::getConfig();
     $page = isset($configArray->Site->defaultAccountPage) ? $configArray->Site->defaultAccountPage : 'Favorites';
     return $this->forwardTo('MyResearch', $page);
 }
Esempio n. 5
0
 /**
  * Return search specs
  *
  * @param string $filename config file name
  *
  * @return array
  */
 public function get($filename)
 {
     // Load data if it is not already in the object's cache:
     if (!isset($this->searchSpecs[$filename])) {
         // Connect to searchspecs cache:
         $sm = $this->getServiceLocator();
         $cache = is_object($sm) && $sm->has('CacheManager') ? $sm->get('CacheManager')->getCache('searchspecs') : false;
         // Determine full configuration file path:
         $fullpath = Reader::getBaseConfigPath($filename);
         $local = Reader::getLocalConfigPath($filename);
         // Generate cache key:
         $key = $filename . '-' . filemtime($fullpath);
         if (!empty($local)) {
             $key .= '-local-' . filemtime($local);
         }
         $key = md5($key);
         // Generate data if not found in cache:
         if (!$cache || !($results = $cache->getItem($key))) {
             $results = Yaml::load(file_get_contents($fullpath));
             if (!empty($local)) {
                 $localResults = Yaml::load(file_get_contents($local));
                 foreach ($localResults as $key => $value) {
                     $results[$key] = $value;
                 }
             }
             if ($cache) {
                 $cache->setItem($key, $results);
             }
         }
         $this->searchSpecs[$filename] = $results;
     }
     return $this->searchSpecs[$filename];
 }
Esempio n. 6
0
 /**
  * Constructor
  *
  * @param \Zend\Mail\Transport\TransportInterface $transport Mail transport
  * object (we'll build our own if none is provided).
  * @param \Zend\Config\Config                     $config    VuFind configuration
  * object (we'll auto-load if none is provided).
  */
 public function __construct($transport = null, $config = null)
 {
     if (!is_null($transport)) {
         $this->setTransport($transport);
     }
     $this->config = is_null($config) ? ConfigReader::getConfig() : $config;
 }
Esempio n. 7
0
 /**
  * Shared OAI logic.
  *
  * @param string $serverClass Class to load for handling OAI requests.
  *
  * @return \Zend\Http\Response
  */
 protected function handleOAI($serverClass)
 {
     // Check if the OAI Server is enabled before continuing
     $config = ConfigReader::getConfig();
     $response = $this->getResponse();
     if (!isset($config->OAI)) {
         $response->setStatusCode(404);
         $response->setContent('OAI Server Not Configured.');
         return $response;
     }
     // Collect relevant parameters for OAI server:
     $url = explode('?', $this->getServerUrl());
     $baseURL = $url[0];
     // Build OAI response or die trying:
     try {
         $server = new $serverClass($this->getSearchManager(), $baseURL, $this->getRequest()->getQuery()->toArray());
         $xml = $server->getResponse();
     } catch (\Exception $e) {
         $response->setStatusCode(500);
         $response->setContent($e->getMessage());
         return $response;
     }
     // Return response:
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-type', 'text/xml');
     $response->setContent($xml);
     return $response;
 }
Esempio n. 8
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct('http://www.worldcat.org/webservices/catalog/search/sru');
     $config = ConfigReader::getConfig();
     $this->wskey = isset($config->WorldCat->apiKey) ? $config->WorldCat->apiKey : null;
     $this->limitCodes = isset($config->WorldCat->LimitCodes) ? $config->WorldCat->LimitCodes : null;
 }
Esempio n. 9
0
 /**
  * getSuggestions
  *
  * This returns an array of suggestions based on current request parameters.
  * This logic is present in the factory class so that it can be easily shared
  * by multiple AJAX handlers.
  *
  * @param \Zend\Stdlib\Parameters $request    The user request
  * @param string                  $typeParam  Request parameter containing search
  * type
  * @param string                  $queryParam Request parameter containing query
  * string
  *
  * @return array
  */
 public function getSuggestions($request, $typeParam = 'type', $queryParam = 'q')
 {
     // Process incoming parameters:
     $type = $request->get($typeParam, '');
     $query = $request->get($queryParam, '');
     // get Autocomplete_Type config
     $searcher = $request->get('searcher', 'Solr');
     $options = $this->getServiceLocator()->get('SearchManager')->setSearchClassId($searcher)->getOptionsInstance();
     $config = ConfigReader::getConfig($options->getSearchIni());
     $types = isset($config->Autocomplete_Types) ? $config->Autocomplete_Types->toArray() : array();
     // Figure out which handler to use:
     if (!empty($type) && isset($types[$type])) {
         $module = $types[$type];
     } else {
         if (isset($config->Autocomplete->default_handler)) {
             $module = $config->Autocomplete->default_handler;
         } else {
             $module = false;
         }
     }
     // Get suggestions:
     if ($module) {
         if (strpos($module, ':') === false) {
             $module .= ':';
             // force colon to avoid warning in explode below
         }
         list($name, $params) = explode(':', $module, 2);
         $handler = $this->get($name);
         $handler->setConfig($params);
     }
     return isset($handler) && is_object($handler) ? array_values($handler->getSuggestions($query)) : array();
 }
Esempio n. 10
0
 /**
  * Get the name of the folder for storing statistics.
  *
  * @return string
  */
 protected function getFolder()
 {
     if (null === $this->folder) {
         $configs = ConfigReader::getConfig();
         $this->folder = $configs->Statistics->file;
     }
     return $this->folder;
 }
Esempio n. 11
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // Call standard record controller initialization:
     parent::__construct();
     // Load default tab setting:
     $config = ConfigReader::getConfig();
     $this->defaultTab = isset($config->Site->defaultRecordTab) ? $config->Site->defaultRecordTab : 'Holdings';
 }
Esempio n. 12
0
 /**
  * Determines what elements are displayed on the home page based on whether
  * the user is logged in.
  *
  * @return mixed
  */
 public function homeAction()
 {
     $config = ConfigReader::getConfig();
     $loggedInModule = isset($config->Site->defaultLoggedInModule) ? $config->Site->defaultLoggedInModule : 'MyResearch';
     $loggedOutModule = isset($config->Site->defaultModule) ? $config->Site->defaultModule : 'Search';
     $module = $this->getUser() ? $loggedInModule : $loggedOutModule;
     return $this->forwardTo($module, 'Home');
 }
Esempio n. 13
0
 /**
  * Apply proxy prefix to URL (if configured).
  *
  * @param string $url The raw URL to adjust
  *
  * @return string
  */
 public function __invoke($url)
 {
     $config = ConfigReader::getConfig();
     if (isset($config->EZproxy->host)) {
         $url = $config->EZproxy->host . '/login?qurl=' . urlencode($url);
     }
     return $url;
 }
Esempio n. 14
0
 /**
  * Constructor. Create a new search result scroller.
  */
 public function __construct()
 {
     // Is this functionality enabled in config.ini?
     $config = ConfigReader::getConfig();
     $this->enabled = isset($config->Record->next_prev_navigation) && $config->Record->next_prev_navigation;
     // Set up session namespace for the class.
     $this->data = new SessionContainer('ResultScroller');
 }
Esempio n. 15
0
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     $this->searchIni = $this->facetsIni = 'Summon';
     parent::__construct();
     // Load facet preferences:
     $facetSettings = ConfigReader::getConfig($this->facetsIni);
     if (isset($facetSettings->Advanced_Settings->translated_facets) && count($facetSettings->Advanced_Facet_Settings->translated_facets) > 0) {
         $list = $facetSettings->Advanced_Facet_Settings->translated_facets;
         foreach ($list as $c) {
             $this->translatedFacets[] = $c;
         }
     }
     if (isset($facetSettings->Advanced_Facet_Settings->special_facets)) {
         $this->specialAdvancedFacets = $facetSettings->Advanced_Facet_Settings->special_facets;
     }
     // Load the search configuration file:
     $searchSettings = ConfigReader::getConfig($this->searchIni);
     // Set up highlighting preference
     if (isset($searchSettings->General->highlighting)) {
         $this->highlight = $searchSettings->General->highlighting;
     }
     // Set up spelling preference
     if (isset($searchSettings->Spelling->enabled)) {
         $this->spellcheck = $searchSettings->Spelling->enabled;
     }
     // Load search preferences:
     if (isset($searchSettings->General->retain_filters_by_default)) {
         $this->retainFiltersByDefault = $searchSettings->General->retain_filters_by_default;
     }
     if (isset($searchSettings->General->result_limit)) {
         $this->resultLimit = $searchSettings->General->result_limit;
     }
     // Search handler setup:
     if (isset($searchSettings->Basic_Searches)) {
         foreach ($searchSettings->Basic_Searches as $key => $value) {
             $this->basicHandlers[$key] = $value;
         }
     }
     if (isset($searchSettings->Advanced_Searches)) {
         foreach ($searchSettings->Advanced_Searches as $key => $value) {
             $this->advancedHandlers[$key] = $value;
         }
     }
     // Load sort preferences:
     if (isset($searchSettings->Sorting)) {
         foreach ($searchSettings->Sorting as $key => $value) {
             $this->sortOptions[$key] = $value;
         }
     }
     if (isset($searchSettings->General->default_sort)) {
         $this->defaultSort = $searchSettings->General->default_sort;
     }
     if (isset($searchSettings->DefaultSortingByType) && count($searchSettings->DefaultSortingByType) > 0) {
         foreach ($searchSettings->DefaultSortingByType as $key => $val) {
             $this->defaultSortByHandler[$key] = $val;
         }
     }
 }
Esempio n. 16
0
 /**
  * Get the WorldCat ID from the config file.
  *
  * @return string
  */
 protected function getWorldCatId()
 {
     static $wcId = null;
     if (is_null($wcId)) {
         $config = ConfigReader::getConfig();
         $wcId = isset($config->WorldCat->id) ? $config->WorldCat->id : false;
     }
     return $wcId;
 }
Esempio n. 17
0
 /**
  * Get the cover loader object
  *
  * @return Loader
  */
 protected function getLoader()
 {
     // Construct object for loading cover images if it does not already exist:
     if (!$this->loader) {
         $this->loader = new Loader(ConfigReader::getConfig(), $this->getServiceLocator()->get('CacheManager')->getCacheDir());
         $this->loader->setLogger($this->getServiceLocator()->get('Logger'));
     }
     return $this->loader;
 }
Esempio n. 18
0
 /**
  * Accepts $keysToHash, a list of array keys, and $keyValueArray, a keyed array
  *
  * @param array $keysToHash    A list of keys to hash
  * @param array $keyValueArray A keyed array
  *
  * @return sting A hash_hmac string using md5
  */
 public static function generate($keysToHash, $keyValueArray)
 {
     $config = ConfigReader::getConfig();
     $str = '';
     foreach ($keysToHash as $key) {
         $value = isset($keyValueArray[$key]) ? $keyValueArray[$key] : '';
         $str .= $key . '=' . $value . '|';
     }
     return hash_hmac('md5', $str, $config->Security->HMACkey);
 }
Esempio n. 19
0
 /**
  * Constructor
  *
  * @param \Zend\Config\Config $config Configuration to use (set to null to load
  * default configuration using ConfigReader class).
  */
 public function __construct($config = null)
 {
     if (is_null($config)) {
         $config = ConfigReader::getConfig();
     }
     // Set Display Date Format
     $this->displayDateFormat = isset($config->Site->displayDateFormat) ? $config->Site->displayDateFormat : "m-d-Y";
     // Set Display Date Format
     $this->displayTimeFormat = isset($config->Site->displayTimeFormat) ? $config->Site->displayTimeFormat : "H:i";
 }
Esempio n. 20
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     // Turn on highlighting as needed:
     $searchSettings = ConfigReader::getConfig('Summon');
     $this->highlight = !isset($searchSettings->General->highlighting) ? false : $searchSettings->General->highlighting;
     // Set up resource source to allow tagging/saving/etc.
     $this->resourceSource = 'Summon';
     // Make sure we read appropriate config file:
     $this->recordIni = 'Summon';
 }
Esempio n. 21
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->config = ConfigReader::getConfig();
     $this->disabledFacets = array();
     foreach ($this->config->Browse as $key => $setting) {
         if ($setting == false) {
             $this->disabledFacets[] = $key;
         }
     }
 }
Esempio n. 22
0
 /**
  * setConfig
  *
  * Store the configuration of the recommendation module.
  *
  * TopFacets:[ini section]:[ini name]
  *      Display facets listed in the specified section of the specified ini file;
  *      if [ini name] is left out, it defaults to "facets."
  *
  * @param string $settings Settings from searches.ini.
  *
  * @return void
  */
 public function setConfig($settings)
 {
     $settings = explode(':', $settings);
     $mainSection = empty($settings[0]) ? 'ResultsTop' : $settings[0];
     $iniName = isset($settings[1]) ? $settings[1] : 'facets';
     // Load the desired facet information:
     $config = ConfigReader::getConfig($iniName);
     $this->facets = isset($config->{$mainSection}) ? $config->{$mainSection}->toArray() : array();
     // Load other relevant settings:
     $this->baseSettings = array('rows' => $config->Results_Settings->top_rows, 'cols' => $config->Results_Settings->top_cols);
 }
Esempio n. 23
0
 /**
  * Constructor
  *
  * @param \VuFind\Auth\Manager $account Auth manager object
  * @param ILSConnection        $ils     A catalog connection
  */
 public function __construct(\VuFind\Auth\Manager $account, ILSConnection $ils)
 {
     $this->account = $account;
     $this->config = ConfigReader::getConfig();
     if (isset($this->config->Record->hide_holdings)) {
         foreach ($this->config->Record->hide_holdings as $current) {
             $this->hideHoldings[] = $current;
         }
     }
     $this->catalog = $ils;
 }
Esempio n. 24
0
 /**
  * Get configuration (load automatically if not previously set).  Throw an
  * exception if the configuration is invalid.
  *
  * @throws AuthException
  * @return \Zend\Config\Config
  */
 public function getConfig()
 {
     // Load configuration if not already present:
     if (is_null($this->config)) {
         $this->setConfig(ConfigReader::getConfig());
     }
     // Validate configuration if not already validated:
     if (!$this->configValidated) {
         $this->validateConfig();
     }
     return $this->config;
 }
Esempio n. 25
0
 /**
  * Get a connection to the Summon API.
  *
  * @return SummonConnection
  */
 public function getSummonConnection()
 {
     static $conn = false;
     if (!$conn) {
         $config = ConfigReader::getConfig();
         $id = isset($config->Summon->apiId) ? $config->Summon->apiId : null;
         $key = isset($config->Summon->apiKey) ? $config->Summon->apiKey : null;
         $conn = new SummonConnection($id, $key);
         $conn->setLogger($this->getServiceLocator()->get('Logger'));
     }
     return $conn;
 }
 /**
  * Gathers data for the view of the AlphaBrowser and does some initialization
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function homeAction()
 {
     $config = ConfigReader::getConfig();
     // Load browse types from config file, or use defaults if unavailable:
     if (isset($config->AlphaBrowse_Types) && !empty($config->AlphaBrowse_Types)) {
         $types = array();
         foreach ($config->AlphaBrowse_Types as $key => $value) {
             $types[$key] = $value;
         }
     } else {
         $types = array('topic' => 'By Topic', 'author' => 'By Author', 'title' => 'By Title', 'lcc' => 'By Call Number');
     }
     // Connect to Solr:
     $db = ConnectionManager::connectToIndex();
     // Process incoming parameters:
     $source = $this->params()->fromQuery('source', false);
     $from = $this->params()->fromQuery('from', false);
     $page = intval($this->params()->fromQuery('page', 0));
     $limit = isset($config->AlphaBrowse->page_size) ? $config->AlphaBrowse->page_size : 20;
     // Create view model:
     $view = $this->createViewModel();
     // If required parameters are present, load results:
     if ($source && $from !== false) {
         // Load Solr data or die trying:
         try {
             $result = $db->alphabeticBrowse($source, $from, $page, $limit);
             // No results?    Try the previous page just in case we've gone past
             // the end of the list....
             if ($result['Browse']['totalCount'] == 0) {
                 $page--;
                 $result = $db->alphabeticBrowse($source, $from, $page, $limit);
             }
         } catch (SolrException $e) {
             if ($e->isMissingBrowseIndex()) {
                 throw new \Exception("Alphabetic Browse index missing.    See " . "http://vufind.org/wiki/alphabetical_heading_browse for " . "details on generating the index.");
             }
             throw $e;
         }
         // Only display next/previous page links when applicable:
         if ($result['Browse']['totalCount'] > $limit) {
             $view->nextpage = $page + 1;
         }
         if ($result['Browse']['offset'] + $result['Browse']['startRow'] > 1) {
             $view->prevpage = $page - 1;
         }
         $view->result = $result;
     }
     $view->alphaBrowseTypes = $types;
     $view->from = $from;
     $view->source = $source;
     return $view;
 }
Esempio n. 27
0
 /**
  * Helper to allow easily configurable page layout -- given a broad class
  * name, return appropriate CSS classes to lay out the page according to
  * the current configuration file settings.
  *
  * @param string $class Type of class to return ('mainbody' or 'sidebar')
  *
  * @return string       CSS classes to apply
  */
 public function __invoke($class)
 {
     $config = ConfigReader::getConfig();
     $left = !isset($config->Site->sidebarOnLeft) ? false : $config->Site->sidebarOnLeft;
     switch ($class) {
         case 'mainbody':
             return $left ? 'span-18 push-5 last' : 'span-18';
         case 'sidebar':
             return $left ? 'span-5 pull-18 sidebarOnLeft' : 'span-5 last';
         default:
             return '';
     }
 }
Esempio n. 28
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $config = ConfigReader::getConfig();
     if (isset($config->Site->showBookBag)) {
         $this->active = (bool) $config->Site->showBookBag;
     }
     if (isset($config->Site->bookBagMaxSize)) {
         $this->maxSize = $config->Site->bookBagMaxSize;
     }
     $this->items = array();
     // Initialize contents
     $this->init();
 }
Esempio n. 29
0
 /**
  * setConfig
  *
  * Store the configuration of the recommendation module.
  *
  * @param string $settings Settings from searches.ini.
  *
  * @return void
  */
 public function setConfig($settings)
 {
     // Save the basic parameters:
     $this->settings = $settings;
     // Parse the additional settings:
     $settings = explode(':', $settings);
     $mainSection = empty($settings[0]) ? 'Results' : $settings[0];
     $checkboxSection = isset($settings[1]) ? $settings[1] : false;
     $iniName = isset($settings[2]) ? $settings[2] : 'facets';
     // Load the desired facet information...
     $config = ConfigReader::getConfig($iniName);
     // All standard facets to display:
     $this->facets = isset($config->{$mainSection}) ? $config->{$mainSection}->toArray() : array();
 }
Esempio n. 30
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // Read Config file
     $config = ConfigReader::getConfig();
     $this->baseUrl = $config->Site->url;
     $this->resultUrl = $this->baseUrl . '/Record/';
     $this->config = ConfigReader::getConfig('sitemap');
     $this->frequency = $this->config->Sitemap->frequency;
     $this->countPerPage = $this->config->Sitemap->countPerPage;
     $this->fileStart = $this->config->Sitemap->fileLocation . "/" . $this->config->Sitemap->fileName;
     if (isset($this->config->SitemapIndex->indexFileName)) {
         $this->indexFile = $this->config->Sitemap->fileLocation . "/" . $this->config->SitemapIndex->indexFileName . ".xml";
     }
 }