本文整理汇总了PHP中Piwik_Site类的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Site类的具体用法?PHP Piwik_Site怎么用?PHP Piwik_Site使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Piwik_Site类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeHoursInFuture
protected function removeHoursInFuture($table, $idSite, $period, $date)
{
$site = new Piwik_Site($idSite);
if( $period == 'day'
&& ($date == 'today'
|| $date == Piwik_Date::factory('now', $site->getTimezone())->toString()))
{
$currentHour = Piwik_Date::factory('now', $site->getTimezone())->toString('G');
// If no data for today, this is an exception to the API output rule, as we normally return nothing:
// we shall return all hours of the day, with nb_visits = 0
if($table->getRowsCount() == 0)
{
for($hour = 0; $hour <= $currentHour; $hour++)
{
$table->addRowFromSimpleArray( array('label' => $hour, 'nb_visits' => 0));
}
return $table;
}
$idsToDelete = array();
foreach($table->getRows() as $id => $row)
{
$hour = $row->getColumn('label');
if($hour > $currentHour)
{
$idsToDelete[] = $id;
}
}
$table->deleteRows($idsToDelete);
}
return $table;
}
示例2: setDateTodayIfWebsiteCreatedToday
protected function setDateTodayIfWebsiteCreatedToday()
{
$date = Piwik_Common::getRequestVar('date', false);
if($date == 'today'
|| Piwik_Common::getRequestVar('period', false) == 'range')
{
return;
}
$websiteId = Piwik_Common::getRequestVar('idSite', false, 'int');
if ($websiteId)
{
$website = new Piwik_Site($websiteId);
$datetimeCreationDate = $this->site->getCreationDate()->getDatetime();
$creationDateLocalTimezone = Piwik_Date::factory($datetimeCreationDate, $website->getTimezone())->toString('Y-m-d');
$todayLocalTimezone = Piwik_Date::factory('now', $website->getTimezone())->toString('Y-m-d');
if( $creationDateLocalTimezone == $todayLocalTimezone )
{
Piwik::redirectToModule( 'CoreHome', 'index',
array( 'date' => 'today',
'idSite' => $websiteId,
'period' => Piwik_Common::getRequestVar('period'))
);
}
}
}
示例3: __construct
/**
* Builds an array of Piwik_Archive of a given date range
*
* @param Piwik_Site $oSite
* @param string $strPeriod eg. 'day' 'week' etc.
* @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
*/
function __construct(Piwik_Site $oSite, $strPeriod, $strDate, Piwik_Segment $segment)
{
$rangePeriod = new Piwik_Period_Range($strPeriod, $strDate, $oSite->getTimezone());
foreach ($rangePeriod->getSubperiods() as $subPeriod) {
$startDate = $subPeriod->getDateStart();
$archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate, $segment->getString());
$archive->setSegment($segment);
$this->archives[] = $archive;
}
}
示例4: __construct
/**
* Builds an array of Piwik_Archive of a given date range
*
* @param Piwik_Site $oSite
* @param string $strPeriod eg. 'day' 'week' etc.
* @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
*/
function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
{
$rangePeriod = new Piwik_Period_Range($strPeriod, $strDate);
foreach ($rangePeriod->getSubperiods() as $subPeriod) {
$startDate = $subPeriod->getDateStart();
$archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate);
$archive->prepareArchive();
$timestamp = $archive->getTimestampStartDate();
$this->archives[$timestamp] = $archive;
}
ksort($this->archives);
}
示例5: getDefaultIndexView
protected function getDefaultIndexView()
{
$view = new Piwik_View('Home/templates/index.tpl');
$this->setGeneralVariablesView($view);
$site = new Piwik_Site($view->idSite);
$minDate = $site->getCreationDate();
$view->minDateYear = $minDate->toString('Y');
$view->minDateMonth = $minDate->toString('m');
$view->minDateDay = $minDate->toString('d');
$view->basicHtmlView = false;
$view->content = '';
return $view;
}
示例6: displayJavascriptCode
function displayJavascriptCode()
{
$idSite = Piwik_Common::getRequestVar('idsite', 1);
Piwik::checkUserHasViewAccess($idSite);
$jsTag = Piwik::getJavascriptCode($idSite, Piwik_Url::getCurrentUrlWithoutFileName());
$view = Piwik_View::factory('DisplayJavascriptCode');
$this->setGeneralVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
$site = new Piwik_Site($idSite);
$view->displaySiteName = $site->getName();
$view->jsTag = $jsTag;
echo $view->render();
}
示例7: generate
public function generate()
{
Piwik::checkUserIsSuperUser();
$nonce = Piwik_Common::getRequestVar('form_nonce', '', 'string', $_POST);
if(Piwik_Common::getRequestVar('choice', 'no') != 'yes' ||
!Piwik_Nonce::verifyNonce('Piwik_VisitorGenerator.generate', $nonce))
{
Piwik::redirectToModule('VisitorGenerator', 'index');
}
Piwik_Nonce::discardNonce('Piwik_VisitorGenerator.generate');
$daysToCompute = Piwik_Common::getRequestVar('daysToCompute', 1, 'int');
// get idSite from POST with fallback to GET
$idSite = Piwik_Common::getRequestVar('idSite', false, 'int', $_GET);
$idSite = Piwik_Common::getRequestVar('idSite', $idSite, 'int', $_POST);
Piwik::setMaxExecutionTime(0);
$timer = new Piwik_Timer;
$time = time() - ($daysToCompute-1)*86400;
// Update site.ts_created if we generate visits on days before the website was created
$site = new Piwik_Site($idSite);
$minGeneratedDate = Piwik_Date::factory($time);
if($minGeneratedDate->isEarlier($site->getCreationDate()))
{
// direct access to the website table (bad practise but this is a debug / dev plugin)
Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"),
array('ts_created' => $minGeneratedDate->getDatetime()),
"idsite = $idSite");
}
$nbActionsTotal = 0;
while($time <= time())
{
$nbActionsTotalThisDay = $this->generateVisits($time, $idSite);
$time += 86400;
$nbActionsTotal += $nbActionsTotalThisDay;
}
// Init view
$view = Piwik_View::factory('generate');
$this->setBasicVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
$view->assign('timer', $timer);
$view->assign('days', $daysToCompute);
$view->assign('nbActionsTotal', $nbActionsTotal);
$view->assign('nbRequestsPerSec', round($nbActionsTotal / $timer->getTime(),0));
echo $view->render();
}
示例8: setDateTodayIfWebsiteCreatedToday
protected function setDateTodayIfWebsiteCreatedToday()
{
$date = Piwik_Common::getRequestVar('date', false);
$date = Piwik_Date::factory($date);
if ($date->isToday()) {
return;
}
$websiteId = Piwik_Common::getRequestVar('idSite', false);
if ($websiteId) {
$website = new Piwik_Site($websiteId);
if ($website->getCreationDate()->isToday()) {
Piwik::redirectToModule('CoreHome', 'index', array('date' => 'today', 'idSite' => $websiteId, 'period' => Piwik_Common::getRequestVar('period')));
}
}
}
示例9: removeHoursInFuture
protected function removeHoursInFuture($table, $idSite, $period, $date)
{
$site = new Piwik_Site($idSite);
if ($period == 'day' && ($date == 'today' || $date == Piwik_Date::factory('now', $site->getTimezone())->toString())) {
$currentHour = Piwik_Date::factory('now', $site->getTimezone())->toString('G');
$idsToDelete = array();
foreach ($table->getRows() as $id => $row) {
$hour = $row->getColumn('label');
if ($hour > $currentHour) {
$idsToDelete[] = $id;
}
}
$table->deleteRows($idsToDelete);
}
return $table;
}
示例10: setColumnsToDisplay
public function setColumnsToDisplay($columnsNames)
{
$newColumnsNames = array();
$goals = array();
$idSite = $this->getIdSite();
if ($idSite) {
$goals = Piwik_Goals_API::getInstance()->getGoals($idSite);
$ecommerceGoal = array('idgoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, 'name' => Piwik_Translate('Goals_EcommerceOrder'));
$site = new Piwik_Site($idSite);
//Case Ecommerce report table
if ($this->isEcommerce) {
$goals = array($ecommerceGoal);
} elseif ($site->isEcommerceEnabled()) {
$goals = array_merge(array($ecommerceGoal), $goals);
}
}
foreach ($columnsNames as $columnName) {
if (in_array($columnName, array('goal_%s_conversion_rate', 'goal_%s_nb_conversions', 'goal_%s_revenue_per_visit', 'goal_%s_revenue', 'goal_%s_avg_order_revenue', 'goal_%s_items'))) {
foreach ($goals as $goal) {
$idgoal = $goal['idgoal'];
// Columns names are escaped in smarty via | escape:'html'
$goal['name'] = Piwik_Common::unsanitizeInputValue($goal['name']);
if ($this->processOnlyIdGoal > Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE && $this->processOnlyIdGoal != $idgoal && !$this->isEcommerce) {
continue;
}
$name = Piwik_Translate($this->getColumnTranslation($columnName), $goal['name']);
$columnNameGoal = str_replace('%s', $idgoal, $columnName);
$this->setColumnTranslation($columnNameGoal, $name);
$this->setDynamicMetricDocumentation($columnName, $columnNameGoal, $goal['name'], $goal['idgoal']);
if (strpos($columnNameGoal, '_rate') === false && $this->processOnlyIdGoal == Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW) {
continue;
}
if (strstr($columnNameGoal, '_revenue') !== false) {
$this->columnsToRevenueFilter[] = $columnNameGoal;
} else {
$this->columnsToConversionFilter[] = $columnNameGoal;
}
$newColumnsNames[] = $columnNameGoal;
}
} else {
$newColumnsNames[] = $columnName;
}
}
parent::setColumnsToDisplay($newColumnsNames);
}
示例11: getRank
function getRank()
{
$idSite = Piwik_Common::getRequestVar('idSite');
$site = new Piwik_Site($idSite);
$url = urldecode(Piwik_Common::getRequestVar('url', '', 'string'));
if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://' . $url;
}
if (empty($url) || !Piwik_Common::isLookLikeUrl($url)) {
$url = $site->getMainUrl();
}
$dataTable = Piwik_SEO_API::getInstance()->getRank($url);
$view = Piwik_View::factory('index');
$view->urlToRank = Piwik_SEO_RankChecker::extractDomainFromUrl($url);
$renderer = Piwik_DataTable_Renderer::factory('php');
$renderer->setSerialize(false);
$view->ranks = $renderer->render($dataTable);
echo $view->render();
}
示例12: getAll
/**
* Returns a report displaying the total visits, actions and revenue, as
* well as the evolution of these values, of all existing sites over a
* specified period of time.
*
* If the specified period is not a 'range', this function will calculcate
* evolution metrics. Evolution metrics are metrics that display the
* percent increase/decrease of another metric since the last period.
*
* This function will merge the result of the archive query so each
* row in the result DataTable will correspond to the metrics of a single
* site. If a date range is specified, the result will be a
* DataTable_Array, but it will still be merged.
*
* @param string $period The period type to get data for.
* @param string $date The date(s) to get data for.
* @param string $segment The segments to get data for.
*/
public function getAll($period, $date, $segment = false)
{
Piwik::checkUserHasSomeViewAccess();
$isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
// get site data for every viewable site and cache them
if (Piwik::isUserIsSuperUser()) {
$sites = Piwik_SitesManager_API::getInstance()->getAllSites();
Piwik_Site::setSites($sites);
} else {
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
Piwik_Site::setSitesFromArray($sites);
}
// build the archive type used to query archive data
$archive = Piwik_Archive::build('all', $period, $date, $segment);
// determine what data will be displayed
$fieldsToGet = array('nb_visits', 'nb_actions');
if ($isGoalPluginEnabled) {
$revenueMetric = Piwik_Goals::getRecordName('revenue');
$fieldsToGet[] = $revenueMetric;
}
// get the data
$dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
// get rid of the DataTable_Array that is created by the IndexedBySite archive type
$dataTable = $dataTable->mergeChildren();
// if the period isn't a range & a lastN/previousN date isn't used, we get the same
// data for the last period to show the evolution of visits/actions/revenue
if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
if (strpos($date, ',')) {
$rangePeriod = new Piwik_Period_Range($period, $date);
$lastStartDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
$lastEndDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
$strLastDate = "{$lastStartDate},{$lastEndDate}";
} else {
$strLastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1)->toString();
}
$pastArchive = Piwik_Archive::build('all', $period, $strLastDate, $segment);
$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
$pastData = $pastData->mergeChildren();
// use past data to calculate evolution percentages
$this->calculateEvolutionPercentages($dataTable, $pastData, $fieldsToGet);
}
// move the site id to a metadata column
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
// set the label of each row to the site name
$getNameFor = array('Piwik_Site', 'getNameFor');
$dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor));
// rename the revenue column from the metric name to 'revenue'
if ($isGoalPluginEnabled) {
$mapping = array($revenueMetric => 'revenue');
$dataTable->filter('ReplaceColumnNames', array($mapping));
}
// Ensures data set sorted, for Metadata output
$dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false));
return $dataTable;
}
示例13: tearDown
public function tearDown()
{
parent::tearDown();
Piwik_DataTable_Manager::getInstance()->deleteAll();
Piwik_Option::getInstance()->clearCache();
Piwik_Site::clearCache();
Piwik_Common::deleteTrackerCache();
Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
$tempTableName = Piwik_Common::prefixTable(Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME);
Piwik_Query("DROP TABLE IF EXISTS " . $tempTableName);
}
示例14: addTopMenu
public function addTopMenu()
{
$tooltip = false;
try {
$idSite = Piwik_Common::getRequestVar('idSite');
$tooltip = Piwik_Translate('Dashboard_TopLinkTooltip', Piwik_Site::getNameFor($idSite));
} catch (Exception $ex) {
// if no idSite parameter, show no tooltip
}
$urlParams = array('module' => 'CoreHome', 'action' => 'index');
Piwik_AddTopMenu('General_Dashboard', $urlParams, true, 1, $isHTML = false, $tooltip);
}
示例15: getRank
function getRank()
{
$idSite = Piwik_Common::getRequestVar('idSite');
$site = new Piwik_Site($idSite);
$url = urldecode(Piwik_Common::getRequestVar('url', '', 'string'));
if(empty($url) || @parse_url($url) === false)
{
$url = $site->getMainUrl();
}
$dataTable = Piwik_SEO_API::getInstance()->getRank($url);
$view = Piwik_View::factory('index');
$view->urlToRank = $url;
$renderer = Piwik_DataTable_Renderer::factory('php');
$renderer->setSerialize(false);
$view->ranks = $renderer->render($dataTable);
echo $view->render();
}