Commit f8f7b664 authored by asmecher's avatar asmecher
Browse files

#3874# OAI tune-ups

parent 4578bd68
......@@ -24,6 +24,7 @@ class OAIHandler extends PKPHandler {
function index() {
OAIHandler::validate();
PluginRegistry::loadCategory('oaiMetadataFormats', true);
$oai = new JournalOAI(new OAIConfig(Request::getRequestUrl(), Config::getVar('oai', 'repository_id')));
$oai->execute();
......
<?php
/**
* @file plugins/generic/referral/ReferralPlugin.inc.php
*
* Copyright (c) 2003-2008 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ReferralPlugin
* @ingroup plugins_generic_referral
*
* @brief Referral plugin to track and maintain potential references to published articles
*/
// $Id$
import('classes.plugins.GenericPlugin');
class ReferralPlugin extends GenericPlugin {
/**
* Register the plugin, if enabled; note that this plugin
* runs under both Journal and Site contexts.
* @param $category string
* @param $path string
* @return boolean
*/
function register($category, $path) {
if (parent::register($category, $path)) {
$this->addLocaleData();
if ($this->getEnabled()) {
HookRegistry::register ('TemplateManager::display', array(&$this, 'handleTemplateDisplay'));
HookRegistry::register ('LoadHandler', array(&$this, 'handleLoadHandler'));
$this->import('Referral');
$this->import('ReferralDAO');
$referralDao = new ReferralDAO();
DAORegistry::registerDAO('ReferralDAO', $referralDao);
}
return true;
}
return false;
}
function handleLoadHandler($hookName, $args) {
$page =& $args[0];
$op =& $args[1];
$sourceFile =& $args[2];
if ($page === 'referral') {
$this->import('ReferralHandler');
Registry::set('plugin', $this);
define('HANDLER_CLASS', 'ReferralHandler');
return true;
}
return false;
}
function handleTemplateInclude($hookName, $args) {
$templateMgr =& $args[0];
$params =& $args[1];
if (!isset($params['smarty_include_tpl_file'])) return false;
switch ($params['smarty_include_tpl_file']) {
case 'common/footer.tpl':
$referralDao =& DAORegistry::getDAO('ReferralDAO');
$user =& Request::getUser();
$rangeInfo =& PKPHandler::getRangeInfo('referrals');
$referralFilter = (int) Request::getUserVar('referralFilter');
if ($referralFilter == 0) $referralFilter = null;
$referrals =& $referralDao->getReferralsByUserId($user->getUserId(), $referralFilter, $rangeInfo);
$templateMgr->assign('referrals', $referrals);
$templateMgr->assign('referralFilter', $referralFilter);
$templateMgr->display($this->getTemplatePath() . 'referrals.tpl', 'text/html', 'ReferralPlugin::addReferralContent');
break;
}
return false;
}
/**
* Hook callback: Handle requests.
*/
function handleTemplateDisplay($hookName, $args) {
$templateMgr =& $args[0];
$template =& $args[1];
switch ($template) {
case 'article/article.tpl':
case 'article/interstitial.tpl':
case 'article/pdfInterstitial.tpl':
$this->logArticleRequest($templateMgr);
break;
case 'author/index.tpl':
// Slightly convoluted: register a hook to
// display the administration options at the
// end of the normal content
HookRegistry::register ('TemplateManager::include', array(&$this, 'handleTemplateInclude'));
break;
}
return false;
}
function logArticleRequest(&$templateMgr) {
$article = $templateMgr->get_template_vars('article');
if (!$article) return false;
$articleId = $article->getArticleId();
$referrer = $_SERVER['HTTP_REFERER'];
// Check if referrer is empty or is the local journal
// if (empty($referrer) || strpos($referrer, Request::getIndexUrl()) !== FALSE) return false;
$referralDao =& DAORegistry::getDAO('ReferralDAO');
if ($referralDao->referralExistsByUrl($articleId, $referrer)) {
// It exists -- increment the count
$referralDao->incrementReferralCount($article->getArticleId(), $referrer);
} else {
// It's a new referral -- log it.
$referral = new Referral();
$referral->setArticleId($article->getArticleId());
$referral->setLinkCount(1);
$referral->setUrl($referrer);
$referral->setStatus(REFERRAL_STATUS_NEW);
$referral->setDateAdded(Core::getCurrentDate());
$referralDao->insertReferral($referral);
}
}
/**
* Get the name of the settings file to be installed on new journal
* creation.
* @return string
*/
function getNewJournalPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* Get the symbolic name of this plugin
* @return string
*/
function getName() {
return 'ReferralPlugin';
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return Locale::translate('plugins.generic.referral.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return Locale::translate('plugins.generic.referral.description');
}
/**
* Check whether or not this plugin is enabled
* @return boolean
*/
function getEnabled() {
$journal =& Request::getJournal();
$journalId = $journal?$journal->getJournalId():0;
return $this->getSetting($journalId, 'enabled');
}
/**
* Get a list of available management verbs for this plugin
* @return array
*/
function getManagementVerbs() {
$verbs = array();
$verbs[] = array(
($this->getEnabled()?'disable':'enable'),
Locale::translate($this->getEnabled()?'manager.plugins.disable':'manager.plugins.enable')
);
return $verbs;
}
/**
* Execute a management verb on this plugin
* @param $verb string
* @param $args array
* @return boolean
*/
function manage($verb, $args) {
$journal =& Request::getJournal();
$journalId = $journal?$journal->getJournalId():0;
switch ($verb) {
case 'enable':
$this->updateSetting($journalId, 'enabled', true);
break;
case 'disable':
$this->updateSetting($journalId, 'enabled', false);
break;
}
return false;
}
}
?>
<?php
/**
* @defgroup plugins_generic_referral
*/
/**
* @file plugins/generic/referral/index.php
*
* Copyright (c) 2003-2008 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @ingroup plugins_generic_referral
* @brief Wrapper for referral plugin.
*
*/
// $Id$
require_once('ReferralPlugin.inc.php');
return new ReferralPlugin();
?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE locale SYSTEM "../../../../../lib/pkp/dtd/locale.dtd">
<!--
* locale.xml
*
* Copyright (c) 2003-2008 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Localization strings for the en_US (U.S. English) locale.
*
* $Id$
-->
<locale name="en_US" full_name="U.S. English">
<message key="plugins.generic.referral.name">Referral Plugin</message>
<message key="plugins.generic.referral.description">The Referral Plugin tracks incoming referral URLs to articles (i.e. when a reader follows an external link to an article), allowing Authors to maintain and potentially publish an automatically-updated list of references to an article.</message>
<message key="plugins.generic.referral.referrals">Referrals</message>
<message key="plugins.generic.referral.count">Hits</message>
<message key="plugins.generic.referral.dateAdded">Date Added</message>
<message key="plugins.generic.referral.all">All</message>
<message key="plugins.generic.referral.all.empty">There are currently no referrals.</message>
<message key="plugins.generic.referral.status.new">New</message>
<message key="plugins.generic.referral.status.new.empty">There are currently no new referrals.</message>
<message key="plugins.generic.referral.status.accept">Published</message>
<message key="plugins.generic.referral.status.accept.empty">There are currently no published referrals.</message>
<message key="plugins.generic.referral.status.decline">Ignored</message>
<message key="plugins.generic.referral.status.decline.empty">There are currently no ignored referrals.</message>
<message key="plugins.generic.referral.confirmDelete">Are you sure you wish to delete this referral?</message>
</locale>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE schema SYSTEM "../../../lib/pkp/dtd/xmlSchema.dtd">
<!--
* schema.xml
*
* Copyright (c) 2003-2008 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Referral tracking plugin schema in XML.
*
* $Id$
-->
<schema version="0.2">
<!--
*
* TABLE referrals
*
-->
<table name="referrals">
<field name="referral_id" type="I8">
<KEY/>
<AUTOINCREMENT/>
</field>
<field name="article_id" type="I8">
<NOTNULL/>
</field>
<field name="status" type="I2">
<NOTNULL/>
</field>
<field name="url" type="C2" size="255">
<NOTNULL/>
</field>
<field name="date_added" type="T">
<NOTNULL/>
</field>
<field name="link_count" type="I8">
<NOTNULL/>
</field>
<descr>List of referrals for articles.</descr>
<index name="referral_article_id">
<col>article_id</col>
<col>url</col>
<UNIQUE/>
</index>
</table>
<!--
*
* TABLE referral_settings
*
-->
<table name="referral_settings">
<field name="referral_id" type="I8">
<NOTNULL />
</field>
<field name="locale" type="C2" size="5">
<NOTNULL />
<DEFAULT VALUE=""/>
</field>
<field name="setting_name" type="C2" size="255">
<NOTNULL />
</field>
<field name="setting_value" type="X"/>
<field name="setting_type" type="C2" size="6">
<NOTNULL/>
</field>
<descr>Referral settings</descr>
<index name="referral_settings_referral_id">
<col>referral_id</col>
</index>
<index name="referral_settings_pkey">
<col>referral_id</col>
<col>locale</col>
<col>setting_name</col>
<UNIQUE />
</index>
</table>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin_settings SYSTEM "../../../lib/pkp/dtd/pluginSettings.dtd">
<!--
* settings.xml
*
* Copyright (c) 2003-2008 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Default plugin settings.
*
* $Id$
-->
<plugin_settings>
<setting type="bool">
<name>enabled</name>
<value>true</value>
</setting>
</plugin_settings>
......@@ -21,7 +21,7 @@ class OAIMetadataFormat_DC extends OAIMetadataFormat {
/**
* @see OAIMetadataFormat#toXML
*/
function toXML(&$record) {
function toXml(&$record, $format = null) {
$article =& $record->getData('article');
$journal =& $record->getData('journal');
$section =& $record->getData('section');
......@@ -69,7 +69,7 @@ class OAIMetadataFormat_DC extends OAIMetadataFormat {
// Relation
$relation = array();
foreach ($article->getSuppFiles() as $suppFile) {
$record->relation[] = Request::url($journal->getPath(), 'article', 'download', array($article->getArticleId(), $suppFile->getFileId()));
$relation[] = Request::url($journal->getPath(), 'article', 'download', array($article->getArticleId(), $suppFile->getFileId()));
}
$response = "<oai_dc:dc\n" .
......@@ -98,7 +98,7 @@ class OAIMetadataFormat_DC extends OAIMetadataFormat {
$this->formatElement('identifier', Request::url($journal->getPath(), 'article', 'view', array($article->getBestArticleId()))) .
$this->formatElement('source', $sources, true) .
$this->formatElement('language', strip_tags($article->getLanguage())) .
$this->formatElement('relation', $record->relation) .
$this->formatElement('relation', $relation) .
$this->formatElement(
'coverage',
array_merge_recursive(
......
......@@ -18,9 +18,9 @@
class OAIMetadataFormat_MARC extends OAIMetadataFormat {
/**
* @see OAIMetadataFormat#toXML
* @see OAIMetadataFormat#toXml
*/
function toXML(&$record) {
function toXml(&$record, $format = null) {
$article =& $record->getData('article');
$issue =& $record->getData('issue');
$journal =& $record->getData('journal');
......
......@@ -18,9 +18,9 @@
class OAIMetadataFormat_MARC21 extends OAIMetadataFormat {
/**
* @see OAIMetadataFormat#toXML
* @see OAIMetadataFormat#toXml
*/
function toXML(&$record) {
function toXml(&$record, $format = null) {
$article =& $record->getData('article');
$issue =& $record->getData('issue');
$journal =& $record->getData('journal');
......
......@@ -18,9 +18,9 @@
class OAIMetadataFormat_RFC1807 extends OAIMetadataFormat {
/**
* @see OAIMetadataFormat#toXML
* @see OAIMetadataFormat#toXml
*/
function toXML(&$record) {
function toXml(&$record, $format = null) {
$article =& $record->getData('article');
$journal =& $record->getData('journal');
$section =& $record->getData('section');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment