18 import(
'lib.pkp.classes.plugins.GenericPlugin');
21 define(
'USAGE_EVENT_PLUGIN_CLASSIFICATION_BOT',
'bot');
22 define(
'USAGE_EVENT_PLUGIN_CLASSIFICATION_ADMIN',
'administrative');
32 function register($category, $path, $mainContextId =
null) {
33 $success = parent::register($category, $path, $mainContextId);
37 foreach ($eventHooks as $hook) {
49 return 'usageeventplugin';
56 return PKP_LIB_PATH . DIRECTORY_SEPARATOR . $this->
getPluginPath() . DIRECTORY_SEPARATOR .
'settings.xml';
63 return __(
'plugins.generic.usageEvent.displayName');
70 return __(
'plugins.generic.usageEvent.description');
96 return $this->
getSetting(CONTEXT_SITE,
'uniqueSiteId');
111 HookRegistry::call(
'UsageEventPlugin::getUsageEvent', array_merge(array($hookName, $usageEvent), $args));
127 'TemplateManager::display',
128 'FileManager::downloadFileFinished'
139 'FileManager::downloadFileFinished'
160 $templateMgr = $args[0];
163 if (!is_a($router,
'PageRouter'))
return false;
166 $context = $router->getContext(
$request);
167 if (!$context)
return false;
170 list($pubObject, $downloadSuccess, $assocType, $idParams, $canonicalUrlPage, $canonicalUrlOp, $canonicalUrlParams) =
173 if (!$pubObject)
return false;
180 if (in_array($assocType, $htmlPageAssocTypes)) {
183 $mimeType =
'text/html';
186 $docSize = (int)$pubObject->getFileSize();
187 $mimeType = $pubObject->getFileType();
190 $canonicalUrl = $router->url(
191 $request,
null, $canonicalUrlPage, $canonicalUrlOp, $canonicalUrlParams
196 $requestBaseUrl =
$request->getBaseUrl();
197 if ($requestBaseUrl !== $configBaseUrl) {
200 $requestBaseUrl !==
Config::getVar(
'general',
'base_url[index]')) {
203 $baseUrlReplacement =
Config::getVar(
'general',
'base_url['.$context->getPath().
']');
204 if (!$baseUrlReplacement) $baseUrlReplacement = $configBaseUrl;
205 $canonicalUrl = str_replace($requestBaseUrl, $baseUrlReplacement, $canonicalUrl);
212 array_unshift($idParams,
'c' . $context->getId());
214 if (empty($siteId)) {
222 array_unshift($idParams, $siteId);
224 $applicationId = $applicationName .
':' . implode(
'-', $idParams);
225 $idKey =
'other::' . $applicationName;
226 $identifiers = array($idKey => $applicationId);
231 if (!empty($pubIdPlugins)) {
232 foreach ($pubIdPlugins as $pubIdPlugin) {
233 if (!$pubIdPlugin->getEnabled())
continue;
234 $pubId = $pubObject->getStoredPubId($pubIdPlugin->getPubIdType());
236 $identifiers[$pubIdPlugin->getPubIdType()] = $pubId;
243 $serviceUri = $router->url(
$request, $context->getPath());
248 if (isset($_SERVER[
'REMOTE_HOST'])) {
252 $host = $_SERVER[
'REMOTE_HOST'];
256 $userAgent =
$request->getUserAgent();
259 $referrer = (isset($_SERVER[
'HTTP_REFERER']) ? $_SERVER[
'HTTP_REFERER'] :
null);
266 $rolesByContext = $roleDao->getByUserIdGroupedByContext($user->getId());
267 foreach (array(CONTEXT_SITE, $context->getId()) as $workingContext) {
268 if(isset($rolesByContext[$workingContext])) {
269 foreach ($rolesByContext[$workingContext] as $roleId => $role) {
277 $classification =
null;
278 if (!empty($roles)) {
280 $internalRoles = array_diff($roles, array(ROLE_ID_READER));
281 if (!empty($internalRoles)) {
282 $classification = USAGE_EVENT_PLUGIN_CLASSIFICATION_ADMIN;
287 $classification = USAGE_EVENT_PLUGIN_CLASSIFICATION_BOT;
316 $usageEvent = compact(
317 'time',
'pubObject',
'assocType',
'canonicalUrl',
'mimeType',
318 'identifiers',
'docSize',
'downloadSuccess',
'serviceUri',
319 'ip',
'host',
'user',
'roles',
'userAgent',
'referrer',
344 $pubObject = $nullVar;
345 $downloadSuccess =
false;
346 $canonicalUrlPage = $canonicalUrlOp = $assocType =
null;
347 $canonicalUrlParams = $idParams = array();
349 if ($hookName ==
'TemplateManager::display') {
350 $page = $router->getRequestedPage(
$request);
354 if (($page ==
'index' || empty($page)) &&
$op ==
'index') {
355 $pubObject = $templateMgr->getTemplateVars(
'currentContext');
356 if (is_a($pubObject,
'Context')) {
358 $canonicalUrlOp =
'';
359 $canonicalUrlPage =
'index';
360 $downloadSuccess =
true;
365 return array($pubObject, $downloadSuccess, $assocType, $idParams, $canonicalUrlPage, $canonicalUrlOp, $canonicalUrlParams);