Open Journal Systems  3.3.0
UsageStatsPlugin Class Reference
Inheritance diagram for UsageStatsPlugin:
GenericPlugin LazyLoadPlugin Plugin

Public Member Functions

 __construct ()
 
 _downloadStatsCacheMiss ($cache, $pubObjectId)
 
 _getDownloadStats ($pubObjectId)
 
 _getPluginSetting ($context, $name)
 
 _hashIp ($ip, $salt)
 
 _writeUsageEventInLogFile ($usageEvent)
 
 addJavascriptData ($data, $pubObjectType, $pubObjectId, $contexts)
 
 callbackLoadHandler ($hookName, $args)
 
 callbackParseCronTab ($hookName, $args)
 
 displayReaderArticleGraph ($hookName, $params)
 
 displayReaderMonographGraph ($hookName, $params)
 
 displayReaderPreprintGraph ($hookName, $params)
 
 displayReaderStatistics ()
 
 getActions ($request, $verb)
 
 getAllDownloadsStats ($pubObjectId, $stats=array())
 
 getDescription ()
 
 getDisplayName ()
 
 getFilesPath ()
 
getGeoLocationTool ()
 
 getInstallMigration ()
 
 getInstallSitePluginSettingsFile ()
 
 getReportPlugin ()
 
 getSaltpath ()
 
 getTemplate ($args, $template, $smarty)
 
 getUsageEventCurrentDayLogName ()
 
 getUsageEventLogsPath ()
 
 isSitePlugin ()
 
 loadJavascript ($contexts)
 
 logUsageEvent ($hookName, $args)
 
 manage ($args, $request)
 
 register ($category, $path, $mainContextId=null)
 
 validateSaltpath ($saltpath)
 
- Public Member Functions inherited from LazyLoadPlugin
 getCanDisable ()
 
 getCanEnable ()
 
 getCurrentContextId ()
 
 getEnabled ($contextId=null)
 
 getName ()
 
 setEnabled ($enabled)
 
- Public Member Functions inherited from Plugin
 _overridePluginTemplates ($hookName, $args)
 
 addLocaleData ($locale=null)
 
 getCategory ()
 
 getContextSpecificPluginSettingsFile ()
 
 getCurrentVersion ()
 
 getDirName ()
 
 getEnabled ()
 
 getHideManagement ()
 
 getInstallControlledVocabFiles ()
 
 getInstallDataFile ()
 
 getInstallEmailTemplateDataFile ()
 
 getInstallEmailTemplatesFile ()
 
 getInstallFilterConfigFiles ()
 
 getInstallSchemaFile ()
 
 getLocaleFilename ($locale)
 
 getPluginPath ()
 
getRequest ()
 
 getSeq ()
 
 getSetting ($contextId, $name)
 
 getTemplatePath ($inCore=false)
 
 getTemplateResource ($template=null, $inCore=false)
 
 import ($class)
 
 installContextSpecificSettings ($hookName, $args)
 
 installControlledVocabs ($hookName, $args)
 
 installData ($hookName, $args)
 
 installEmailTemplateData ($hookName, $args)
 
 installEmailTemplates ($hookName, $args)
 
 installFilters ($hookName, $args)
 
 installLocale ($hookName, $args)
 
 installSiteSettings ($hookName, $args)
 
 smartyPluginUrl ($params, $smarty)
 
 updateSchema ($hookName, $args)
 
 updateSetting ($contextId, $name, $value, $type=null)
 

Data Fields

 $_currentUsageEvent
 
 $_dataPrivacyOn
 
 $_optedOut
 
 $_saltpath
 
- Data Fields inherited from Plugin
 $pluginCategory
 
 $pluginPath
 
 $request
 

Protected Member Functions

 getDownloadFinishedEventHooks ()
 
- Protected Member Functions inherited from Plugin
 _registerTemplateResource ($inCore=false)
 

Detailed Description

Provide usage statistics to data objects.

Definition at line 18 of file UsageStatsPlugin.inc.php.

Constructor & Destructor Documentation

◆ __construct()

UsageStatsPlugin::__construct ( )

Constructor.

Reimplemented from Plugin.

Definition at line 47 of file UsageStatsPlugin.inc.php.

References $application, and PKPApplication\get().

Member Function Documentation

◆ _downloadStatsCacheMiss()

UsageStatsPlugin::_downloadStatsCacheMiss (   $cache,
  $pubObjectId 
)

Callback to fill cache with data, if empty.

Parameters
$cacheFileCache
$pubObjectIdint
Returns
array

Definition at line 883 of file UsageStatsPlugin.inc.php.

References $application, PKPApplication\get(), and getReportPlugin().

◆ _getDownloadStats()

UsageStatsPlugin::_getDownloadStats (   $pubObjectId)

Get prepared download statistics from the DB

Parameters
$pubObjectIdinteger
Returns
array

Definition at line 788 of file UsageStatsPlugin.inc.php.

References CacheManager\getManager(), and Application\getRepresentationDAO().

Referenced by getAllDownloadsStats().

◆ _getPluginSetting()

UsageStatsPlugin::_getPluginSetting (   $context,
  $name 
)

Get context wide setting. If the context or the setting does not exist, get the site wide setting.

Parameters
$contextContext
$nameSetting name
Returns
mixed

Definition at line 916 of file UsageStatsPlugin.inc.php.

References DAORegistry\getDAO(), and Plugin\getSetting().

Referenced by loadJavascript().

◆ _hashIp()

UsageStatsPlugin::_hashIp (   $ip,
  $salt 
)

Hash (SHA256) the given IP using the given SALT.

NB: This implementation was taken from OA-S directly. See http://sourceforge.net/p/openaccessstati/code-0/3/tree/trunk/logfile-parser/lib/logutils.php We just do not implement the PHP4 part as OJS dropped PHP4 support.

Parameters
$ipstring
$saltstring
Returns
string|boolean The hashed IP or boolean false if something went wrong.

Definition at line 773 of file UsageStatsPlugin.inc.php.

Referenced by _writeUsageEventInLogFile().

◆ _writeUsageEventInLogFile()

UsageStatsPlugin::_writeUsageEventInLogFile (   $usageEvent)
Parameters
$usageEventarray = compact( 'time', 'pubObject', 'assocType', 'canonicalUrl', 'mimeType', 'identifiers', 'docSize', 'downloadSuccess', 'serviceUri', 'ip', 'host', 'user', 'roles', 'userAgent', 'referrer', 'classification')

Definition at line 669 of file UsageStatsPlugin.inc.php.

References _hashIp(), getSaltpath(), getUsageEventCurrentDayLogName(), getUsageEventLogsPath(), and validateSaltpath().

Referenced by logUsageEvent().

◆ addJavascriptData()

UsageStatsPlugin::addJavascriptData (   $data,
  $pubObjectType,
  $pubObjectId,
  $contexts 
)

Add a data set to the script data output

Parameters
$dataarray JS data to pass to the scripts
$pubObjectTypestring The type of object this data is for
$pubObjectIdstring The id of the object this data is for
$contextsstring|array Contexts in which to load the scripts.
Returns
null

Definition at line 497 of file UsageStatsPlugin.inc.php.

References Plugin\$request, PKPApplication\get(), and PKPTemplateManager\getManager().

Referenced by displayReaderArticleGraph(), displayReaderMonographGraph(), and displayReaderPreprintGraph().

◆ callbackLoadHandler()

UsageStatsPlugin::callbackLoadHandler (   $hookName,
  $args 
)
See also
PKPPageRouter::route()
Parameters
$hookNamestring
$argsarray [ @option string page @option string op @option string handler file ]

Definition at line 282 of file UsageStatsPlugin.inc.php.

References $op, LazyLoadPlugin\getName(), and Plugin\getPluginPath().

◆ callbackParseCronTab()

UsageStatsPlugin::callbackParseCronTab (   $hookName,
  $args 
)
See also
AcronPlugin::parseCronTab()
Parameters
$hookNamestring
$argsarray [ @option array Task files paths ]
Returns
bolean

Definition at line 305 of file UsageStatsPlugin.inc.php.

References Plugin\getEnabled(), Plugin\getPluginPath(), and Config\getVar().

◆ displayReaderArticleGraph()

UsageStatsPlugin::displayReaderArticleGraph (   $hookName,
  $params 
)

Add chart to article view page

Hooked to Templates::Article::Main

Parameters
$hookNamestring
$paramsarray [ @option Smarty @option string HTML output to return ]

Definition at line 542 of file UsageStatsPlugin.inc.php.

References addJavascriptData(), getAllDownloadsStats(), DAORegistry\getDAO(), Plugin\getSetting(), getTemplate(), and loadJavascript().

◆ displayReaderMonographGraph()

UsageStatsPlugin::displayReaderMonographGraph (   $hookName,
  $params 
)

Add chart to book view page

Hooked to Templates::Catalog::Book::Main

Parameters
$hookNamestring
$paramsarrayarray [ @option Smarty @option string HTML output to return ]

Definition at line 584 of file UsageStatsPlugin.inc.php.

References addJavascriptData(), getAllDownloadsStats(), DAORegistry\getDAO(), Plugin\getSetting(), getTemplate(), and loadJavascript().

◆ displayReaderPreprintGraph()

UsageStatsPlugin::displayReaderPreprintGraph (   $hookName,
  $params 
)

Add chart to preprint view page

Hooked to Templates::Preprint::Main

Parameters
$hookNamestring
$paramsarray [ @option Smarty @option string HTML output to return ]

Definition at line 626 of file UsageStatsPlugin.inc.php.

References addJavascriptData(), getAllDownloadsStats(), DAORegistry\getDAO(), Plugin\getSetting(), getTemplate(), and loadJavascript().

◆ displayReaderStatistics()

UsageStatsPlugin::displayReaderStatistics ( )

Register assets and output hooks to display statistics on the reader frontend.

Returns
null

Definition at line 149 of file UsageStatsPlugin.inc.php.

References $application, PKPApplication\get(), and HookRegistry\register().

Referenced by register().

◆ getActions()

UsageStatsPlugin::getActions (   $request,
  $verb 
)

Get a list of link actions for plugin management.

Parameters
requestPKPRequest
$actionArgsarray The list of action args to be included in request URLs.
Returns
array List of LinkActions

Reimplemented from Plugin.

Definition at line 249 of file UsageStatsPlugin.inc.php.

References Plugin\$request, getDisplayName(), Plugin\getEnabled(), and LazyLoadPlugin\getName().

◆ getAllDownloadsStats()

UsageStatsPlugin::getAllDownloadsStats (   $pubObjectId,
  $stats = array() 
)

Retrieve the allDownloads dataset from the download stats

Parameters
$pubObjectIdint ID of the object to get stats for
$statsarray Optionally pass in stats that have already been fetched from _getDownloadStats().
Returns
$allDownloadStats array The allDownloads dataset

Definition at line 861 of file UsageStatsPlugin.inc.php.

References _getDownloadStats().

Referenced by displayReaderArticleGraph(), displayReaderMonographGraph(), and displayReaderPreprintGraph().

◆ getDescription()

UsageStatsPlugin::getDescription ( )

Get a description of this plugin.

Returns
string

Reimplemented from Plugin.

Definition at line 188 of file UsageStatsPlugin.inc.php.

◆ getDisplayName()

UsageStatsPlugin::getDisplayName ( )

Get the display name for this plugin.

Returns
string

Reimplemented from Plugin.

Definition at line 181 of file UsageStatsPlugin.inc.php.

Referenced by getActions().

◆ getDownloadFinishedEventHooks()

UsageStatsPlugin::getDownloadFinishedEventHooks ( )
protected

Get all hooks that define the finished file download.

Returns
array

Definition at line 333 of file UsageStatsPlugin.inc.php.

References $application, and PKPApplication\get().

Referenced by logUsageEvent().

◆ getFilesPath()

UsageStatsPlugin::getFilesPath ( )

Get the plugin's files path.

Returns
string

Definition at line 417 of file UsageStatsPlugin.inc.php.

Referenced by getUsageEventLogsPath().

◆ getGeoLocationTool()

& UsageStatsPlugin::getGeoLocationTool ( )

Get the geolocation tool to process geo localization data.

Returns
mixed GeoLocationTool object or null

Definition at line 398 of file UsageStatsPlugin.inc.php.

References $tool.

◆ getInstallMigration()

UsageStatsPlugin::getInstallMigration ( )

Get the installation migration for this plugin.

Returns
Illuminate\Database\Migrations\Migration?

Reimplemented from Plugin.

Definition at line 209 of file UsageStatsPlugin.inc.php.

◆ getInstallSitePluginSettingsFile()

UsageStatsPlugin::getInstallSitePluginSettingsFile ( )

Get the filename of the settings data for this plugin to install when the system is installed (i.e. site-level plugin settings). Subclasses using default settings should override this.

Returns
string

Reimplemented from Plugin.

Definition at line 202 of file UsageStatsPlugin.inc.php.

References Plugin\getPluginPath().

◆ getReportPlugin()

UsageStatsPlugin::getReportPlugin ( )

Get the report plugin object that implements the metric type details.

Returns
UsageStatsReportPlugin

Definition at line 76 of file UsageStatsPlugin.inc.php.

References $application, and PKPApplication\get().

Referenced by _downloadStatsCacheMiss(), and register().

◆ getSaltpath()

UsageStatsPlugin::getSaltpath ( )

Get the path to the salt file.

Returns
string

Definition at line 174 of file UsageStatsPlugin.inc.php.

References $_saltpath.

Referenced by _writeUsageEventInLogFile().

◆ getTemplate()

UsageStatsPlugin::getTemplate (   $args,
  $template,
  $smarty 
)

Fetch a template with the requested params

Parameters
$argsarray Variables to assign to the template
$templatestring Template file name
$smartyobject Smarty template object
Returns
string

Definition at line 527 of file UsageStatsPlugin.inc.php.

References Plugin\getTemplateResource().

Referenced by displayReaderArticleGraph(), displayReaderMonographGraph(), and displayReaderPreprintGraph().

◆ getUsageEventCurrentDayLogName()

UsageStatsPlugin::getUsageEventCurrentDayLogName ( )

Get current day usage event log name.

Returns
string

Definition at line 436 of file UsageStatsPlugin.inc.php.

Referenced by _writeUsageEventInLogFile().

◆ getUsageEventLogsPath()

UsageStatsPlugin::getUsageEventLogsPath ( )

Get the plugin's usage event logs path.

Returns
string

Definition at line 428 of file UsageStatsPlugin.inc.php.

References getFilesPath().

Referenced by _writeUsageEventInLogFile().

◆ isSitePlugin()

UsageStatsPlugin::isSitePlugin ( )

Site-wide plugins should override this function to return true.

Returns
boolean

Reimplemented from Plugin.

Definition at line 195 of file UsageStatsPlugin.inc.php.

◆ loadJavascript()

UsageStatsPlugin::loadJavascript (   $contexts)

Load the JavaScript assets and pass data to the scripts

Parameters
$contextsstring|array Contexts in which to load the scripts.
Returns
null

Definition at line 446 of file UsageStatsPlugin.inc.php.

References Plugin\$request, _getPluginSetting(), PKPApplication\get(), PKPTemplateManager\getManager(), and Plugin\getPluginPath().

Referenced by displayReaderArticleGraph(), displayReaderMonographGraph(), and displayReaderPreprintGraph().

◆ logUsageEvent()

UsageStatsPlugin::logUsageEvent (   $hookName,
  $args 
)

Log the usage event into a file.

Parameters
$hookNamestring
$argsarray [ @option string hook name @option array usage event = compact( 'time', 'pubObject', 'assocType', 'canonicalUrl', 'mimeType', 'identifiers', 'docSize', 'downloadSuccess', 'serviceUri', 'ip', 'host', 'user', 'roles', 'userAgent', 'referrer', 'classification') ]
Returns
boolean

Definition at line 364 of file UsageStatsPlugin.inc.php.

References $_currentUsageEvent, _writeUsageEventInLogFile(), and getDownloadFinishedEventHooks().

◆ manage()

UsageStatsPlugin::manage (   $args,
  $request 
)

Perform a management function.

Parameters
$argsarray
$requestPKPRequest
Returns
JSONMessage A JSON-encoded response

Reimplemented from Plugin.

Definition at line 217 of file UsageStatsPlugin.inc.php.

References Plugin\$request.

◆ register()

UsageStatsPlugin::register (   $category,
  $path,
  $mainContextId = null 
)

Load and initialize the plug-in and register plugin hooks.

For backwards compatibility this method will be called whenever the plug-in's category is being loaded. If, however, registerOn() returns an array then this method will only be called when the plug-in is enabled and an entry in the result set of registerOn() matches the current request operation. An empty array matches all request operations.

Parameters
$categoryString Name of category plugin was registered to
$pathString The path the plugin was found in
$mainContextIdinteger To identify if the plugin is enabled we need a context. This context is usually taken from the request but sometimes there is no context in the request (e.g. when executing CLI commands). Then the main context can be given as an explicit ID.
Returns
boolean True iff plugin registered successfully; if false, the plugin will not be executed.

Reimplemented from LazyLoadPlugin.

Definition at line 101 of file UsageStatsPlugin.inc.php.

References Plugin\$request, Plugin\_registerTemplateResource(), displayReaderStatistics(), PKPApplication\get(), Plugin\getEnabled(), Plugin\getPluginPath(), getReportPlugin(), Plugin\getSetting(), Config\getVar(), PluginRegistry\register(), and HookRegistry\register().

◆ validateSaltpath()

UsageStatsPlugin::validateSaltpath (   $saltpath)

Validate that the path of the salt file exists and is writable.

Parameters
$saltpathstring
Returns
boolean

Definition at line 318 of file UsageStatsPlugin.inc.php.

Referenced by _writeUsageEventInLogFile().

Field Documentation

◆ $_currentUsageEvent

$_currentUsageEvent UsageStatsPlugin::$_currentUsageEvent

array

Definition at line 24 of file UsageStatsPlugin.inc.php.

Referenced by logUsageEvent().

◆ $_dataPrivacyOn

$_dataPrivacyOn UsageStatsPlugin::$_dataPrivacyOn

boolean

Definition at line 30 of file UsageStatsPlugin.inc.php.

◆ $_optedOut

$_optedOut UsageStatsPlugin::$_optedOut

boolean

Definition at line 36 of file UsageStatsPlugin.inc.php.

◆ $_saltpath

$_saltpath UsageStatsPlugin::$_saltpath

string

Definition at line 42 of file UsageStatsPlugin.inc.php.

Referenced by getSaltpath().


The documentation for this class was generated from the following file: