Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ReportsRequest.prototype.send = function (params) {
this.init();
this.site = params.site;
var settings = Piwik.require('App/Settings');
var session = Piwik.require('App/Session');
var language = settings.getLanguage();
// the report contains text/translations, therefore we have to add the language to the cache key.
// the report contains a list of reports which are site specific, for example goals. Therefore we have to cache
// the result by idSite and accountId.
this.sessionKey = 'piwik_report_metadata_' + this.site.accountId + '_' + this.site.idsite + '_' + language;
var cachedReportData = session.get(this.sessionKey);
settings = null;
session = null;
if (!params.reload
&& cachedReportData
&& Piwik.isArray(cachedReportData)
&& 0 < cachedReportData.length) {
}
}
win.waitIndicatorImage.show();
win = null;
break;
}
var that = this;
function waitIndicatorTimeout () {
that.hide(true);
}
var settings = Piwik.require('App/Settings');
// this ensures the activity indicator will be removed even if the hide method was not called due to any error.
this.waitIndicatorTimeout = setTimeout(waitIndicatorTimeout, (settings.getHttpTimeout() * 1.6));
settings = null;
};
var buttons = event.source.labels;
var button = buttons[event.index];
if (button && button.command) {
button.command.execute({source: that.toolBar});
}
buttons = null;
button = null;
});
}
} else if (this.menuView) {
var stringUtils = Piwik.require('Utils/String');
// android
var right = 0;
// remove previous added menu items
for (var commandId in this.availableCommands) {
var availableCommand = this.availableCommands[commandId];
try {
availableCommand.hide();
this.menuView.remove(availableCommand);
availableCommand = null;
this.availableCommands[commandId] = null;
} catch (e){
piwikRequest.setCallback(this, function (response) {
if (!account) {
return;
}
account.dateVersionUpdated = (new Date()) + '';
if (response) {
var stringUtils = Piwik.require('Utils/String');
account.version = stringUtils.toPiwikVersion(response.value);
stringUtils = null;
} else if (!account.version) {
account.version = 0;
} else {
// there went something wrong with the request. For example the network connection broke up.
// do not set account version to 0 in such a case. We would overwrite an existing version, eg 183
}
var accountManager = Piwik.require('App/Accounts');
accountManager.updateAccount(account.id, {version: account.version,
dateVersionUpdated: account.dateVersionUpdated});
accountManager = null;
response = null;
});
ReportsRequest.prototype.loaded = function (reportMetaData) {
if (!reportMetaData) {
reportMetaData = [];
}
this.availableReports = reportMetaData;
// do not cache an empty result
if (reportMetaData && Piwik.isArray(reportMetaData) && 0 < reportMetaData.length) {
var session = Piwik.require('App/Session');
session.set(this.sessionKey, reportMetaData);
session = null;
}
reportMetaData = null;
this.fire();
};
WebsitesRequest.prototype.loaded = function () {
if (!this.filterUsed) {
// cache only if no filter was used
var session = Piwik.require('App/Session');
session.set('piwik_sites_allowed', this.sites);
session = null;
}
var eventResult = {type: 'onload',
sites: this.sites,
filterUsed: this.filterUsed,
achievedSitesLimit: this.achievedSitesLimit,
showMultiChart: this.showMultiChart};
this.fireEvent('onload', eventResult);
eventResult = null;
};
return;
}
}
var parameter = null;
for (var index = 0; index < this.accounts.length; index++) {
if (!this.accounts[index] || !Boolean(this.accounts[index].active)) {
// account is not set or not active
continue;
}
// create a request to fetch all sites the user has at least view access
piwikRequest = Piwik.require('Network/PiwikApiRequest');
parameter = {accountId: this.accounts[index].id, limit: config.piwik.numDisplayedWebsites};
if (params && params.filterName) {
parameter.pattern = params.filterName;
piwikRequest.setMethod('SitesManager.getPatternMatchSites');
this.filterUsed = true;
} else {
piwikRequest.setMethod('SitesManager.getSitesWithAtLeastViewAccess');
this.filterUsed = false;
}
piwikRequest.setParameter(parameter);
piwikRequest.setAccount(this.accounts[index]);
piwikRequest.setCallback(this, this.onReceiveSitesWithAtLeastViewAccess);
if (!account.dateVersionUpdated) {
// version not updated yet. Set it to null. new Date(null) will be Jan 01 1970 and therefore force an update
account.dateVersionUpdated = null;
}
var dateNow = (new Date()).toDateString();
var lastUpdatedDate = new Date(account.dateVersionUpdated);
var alreadyUpdatedToday = dateNow == lastUpdatedDate.toDateString();
if (alreadyUpdatedToday) {
// request it max once per day
return;
}
var piwikRequest = Piwik.require('Network/PiwikApiRequest');
piwikRequest.setMethod('API.getPiwikVersion');
piwikRequest.setAccount(account);
piwikRequest.setCallback(this, function (response) {
if (!account) {
return;
}
account.dateVersionUpdated = (new Date()) + '';
if (response) {
var stringUtils = Piwik.require('Utils/String');
account.version = stringUtils.toPiwikVersion(response.value);
stringUtils = null;
AccountRequest.prototype.requestVersion = function () {
var that = this;
var accountManager = Piwik.require('App/Accounts');
var account = accountManager.getAccountById(this.accountId);
var piwikRequest = Piwik.require('Network/PiwikApiRequest');
piwikRequest.setMethod('API.getPiwikVersion');
piwikRequest.setAccount(account);
piwikRequest.setCallback(this, function (response) {
if (!response) {
return;
}
if (response && response.result && 'error' == response.result) {
// in most cases the ExampleApi is deactivated or token_auth is not valid
Piwik.getLog().debug('Compare Version error, message: ' + response.message,
'Piwik.Network.AccountRequest::requestVersion');
return;
}
if (this.report.uniqueId) {
// Small hack for graphs to be disabled correctly
this.report.uniqueId = this.report.uniqueId.replace(/--[^_]/, '--X');
}
}
if (!this.showAll) {
parameter.filter_limit = config.piwik.filterLimit;
} else {
// -1 means request really all results
parameter.filter_limit = -1;
}
var statsRequest = Piwik.require('Network/PiwikApiRequest');
statsRequest.setMethod('API.getProcessedReport');
statsRequest.setParameter(parameter);
statsRequest.setAccount(account);
statsRequest.setCallback(this, function (response) {
if (!response) {
this.loaded();
return;
}
this.reportWebsite = response.website;
this.reportDate = response.prettyDate;
this.metadata = response.metadata;
this.columns = response.columns;
this.reportData = this._formatReportData(response, account);