"... '
. trim($this->_highlightedArticles[$articleId]) . ' ..." |
';
return false;
}
/**
* @see templates/search/searchResults.tpl
*/
function callbackTemplateSyntaxInstructions($hookName, $params) {
$output =& $params[2];
$output .= __('plugins.generic.lucene.results.syntaxInstructions');
return false;
}
/**
* @see templates/manager/sections/sectionForm.tpl
*/
function callbackTemplateSectionFormAdditionalMetadata($hookName, $params) {
// Assign the ranking boost options to the template.
$smarty =& $params[1];
$smarty->assign('rankingBoostOptions', $this->_getRankingBoostOptions());
// Render the template.
$output =& $params[2];
$output .= $smarty->fetch($this->getTemplatePath() . 'additionalSectionMetadata.tpl');
return false;
}
//
// Private helper methods
//
/**
* Set the page's breadcrumbs, given the plugin's tree of items
* to append.
*/
function _setBreadcrumbs() {
$templateMgr =& TemplateManager::getManager();
$pageCrumbs = array(
array(
Request::url(null, 'user'),
'navigation.user'
),
array(
Request::url('index', 'admin'),
'user.role.siteAdmin'
),
array(
Request::url(null, 'manager', 'plugins'),
'manager.plugins'
)
);
$templateMgr->assign('pageHierarchy', $pageCrumbs);
}
/**
* Return the available options for result
* set ordering.
* @param $journal Journal
* @return array
*/
function _getResultSetOrderingOptions($journal) {
$resultSetOrderingOptions = array(
'score' => __('plugins.generic.lucene.results.orderBy.relevance'),
'authors' => __('plugins.generic.lucene.results.orderBy.author'),
'issuePublicationDate' => __('plugins.generic.lucene.results.orderBy.issue'),
'publicationDate' => __('plugins.generic.lucene.results.orderBy.date'),
'title' => __('plugins.generic.lucene.results.orderBy.article')
);
// Only show the "journal title" option if we have several journals.
if (!is_a($journal, 'Journal')) {
$resultSetOrderingOptions['journalTitle'] = __('plugins.generic.lucene.results.orderBy.journal');
}
return $resultSetOrderingOptions;
}
/**
* Return the available options for the result
* set ordering direction.
* @return array
*/
function _getResultSetOrderingDirectionOptions() {
return array(
'asc' => __('plugins.generic.lucene.results.orderDir.asc'),
'desc' => __('plugins.generic.lucene.results.orderDir.desc')
);
}
/**
* Return the currently selected result
* set ordering option (default: descending relevance).
* @param $journal Journal
* @return array An array with the order field as the
* first entry and the order direction as the second
* entry.
*/
function _getResultSetOrdering($journal) {
// Retrieve the request.
$request =& Application::getRequest();
// Order field.
$orderBy = $request->getUserVar('orderBy');
$orderByOptions = $this->_getResultSetOrderingOptions($journal);
if (is_null($orderBy) || !in_array($orderBy, array_keys($orderByOptions))) {
$orderBy = 'score';
}
// Ordering direction.
$orderDir = $request->getUserVar('orderDir');
$orderDirOptions = $this->_getResultSetOrderingDirectionOptions();
if (is_null($orderDir) || !in_array($orderDir, array_keys($orderDirOptions))) {
if (in_array($orderBy, array('score', 'publicationDate', 'issuePublicationDate'))) {
$orderDir = 'desc';
} else {
$orderDir = 'asc';
}
}
return array($orderBy, $orderDir);
}
/**
* Get all currently enabled facet categories.
* @return array
*/
function _getEnabledFacetCategories() {
if (!is_array($this->_enabledFacetCategories)) {
$this->_enabledFacetCategories = array();
$availableFacetCategories = array(
'discipline', 'subject', 'type', 'coverage',
'journalTitle', 'authors', 'publicationDate'
);
foreach($availableFacetCategories as $facetCategory) {
if ($this->getSetting(0, 'facetCategory' . ucfirst($facetCategory))) {
$this->_enabledFacetCategories[] = $facetCategory;
}
}
}
return $this->_enabledFacetCategories;
}
/**
* Checks whether a minimum amount of time has passed since
* the last email message went out.
*
* @return boolean True if a new email can be sent, false if
* we better keep silent.
*/
function _spamCheck() {
// Avoid spam.
$lastEmailTimstamp = (integer)$this->getSetting(0, 'lastEmailTimestamp');
$threeHours = 60 * 60 * 3;
$now = time();
if ($now - $lastEmailTimstamp < $threeHours) return false;
$this->updateSetting(0, 'lastEmailTimestamp', $now);
return true;
}
/**
* Send an email to the site's tech admin
* warning that an indexing error has occured.
*
* @param $error array An array of article ids.
* @param $journal Journal A journal object.
* @param $isSearchProblem boolean Whether a search problem
* is being reported.
*/
function _informTechAdmin($error, $journal = null, $isSearchProblem = false) {
if (!$this->_spamCheck()) return;
// Is this a search or an indexing problem?
if ($isSearchProblem) {
$mail =& $this->getMailTemplate('LUCENE_SEARCH_SERVICE_ERROR_NOTIFICATION', $journal);
} else {
// Check whether this is journal or article index update problem.
if (is_a($journal, 'Journal')) {
// This must be a journal indexing problem.
$mail =& $this->getMailTemplate('LUCENE_JOURNAL_INDEXING_ERROR_NOTIFICATION', $journal);
} else {
// Instantiate an article mail template.
$mail =& $this->getMailTemplate('LUCENE_ARTICLE_INDEXING_ERROR_NOTIFICATION');
}
}
// Assign parameters.
$request =& PKPApplication::getRequest();
$site =& $request->getSite();
$mail->assignParams(
array('siteName' => $site->getLocalizedTitle(), 'error' => $error)
);
// Send to the site's tech contact.
$mail->addRecipient($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
// Send the mail.
$mail->send($request);
}
/**
* Return the available ranking boost options.
* @return array
*/
function _getRankingBoostOptions() {
return array(
0 => __('plugins.generic.lucene.sectionForm.ranking.never'),
1 => __('plugins.generic.lucene.sectionForm.ranking.low'),
2 => __('plugins.generic.lucene.sectionForm.ranking.normal'),
4 => __('plugins.generic.lucene.sectionForm.ranking.high')
);
}
}
?>