コード例 #1
0
 /**
  * Creates a new ArchiveProcessing object
  * 
  * @param string $periodLabel
  * @param string $dateLabel
  * @param string $siteTimezone
  * @return Piwik_ArchiveProcessing
  */
 private function _createArchiveProcessing($periodLabel, $dateLabel, $siteTimezone)
 {
     $site = $this->_createWebsite($siteTimezone);
     $date = Piwik_Date::factory($dateLabel);
     $period = Piwik_Period::factory($periodLabel, $date);
     $archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
     $archiveProcessing->setSite($site);
     $archiveProcessing->setPeriod($period);
     $archiveProcessing->setSegment(new Piwik_Segment('', $site->getId()));
     $archiveProcessing->init();
     return $archiveProcessing;
 }
コード例 #2
0
ファイル: Archive.php プロジェクト: Doluci/tomatocart
 /**
  * Builds an Archive object or returns the same archive if previously built.
  *
  * @param int $idSite
  * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory()
  * @param string $period 'week' 'day' etc.
  * 
  * @return Piwik_Archive
  */
 public static function build($idSite, $period, $strDate)
 {
     $oSite = new Piwik_Site($idSite);
     // if a period date string is detected: either 'last30', 'previous10' or 'YYYY-MM-DD,YYYY-MM-DD'
     if (is_string($strDate) && (ereg('^(last|previous){1}([0-9]*)$', $strDate, $regs) || ereg('^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$', $strDate, $regs))) {
         require_once 'Archive/Array.php';
         $archive = new Piwik_Archive_Array($oSite, $period, $strDate);
     } else {
         if (is_string($strDate)) {
             $oDate = Piwik_Date::factory($strDate);
         } else {
             $oDate = $strDate;
         }
         $date = $oDate->toString();
         if (isset(self::$alreadyBuilt[$idSite][$date][$period])) {
             return self::$alreadyBuilt[$idSite][$date][$period];
         }
         $oPeriod = Piwik_Period::factory($period, $oDate);
         $archive = new Piwik_Archive_Single();
         $archive->setPeriod($oPeriod);
         $archive->setSite($oSite);
         self::$alreadyBuilt[$idSite][$date][$period] = $archive;
     }
     return $archive;
 }
コード例 #3
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
	private function loadLastVisitorDetailsFromDatabase($idSite, $period = false, $date = false, $segment = false, $filter_limit = false, $maxIdVisit = false, $visitorId = false, $minTimestamp = false)
	{
//		var_dump($period); var_dump($date); var_dump($filter_limit); var_dump($maxIdVisit); var_dump($visitorId);
//var_dump($minTimestamp);
		if(empty($filter_limit))
		{
			$filter_limit = 100;
		}
		$where = $whereBind = array();
		$where[] = "log_visit.idsite = ? ";
		$whereBind[] = $idSite;
		$orderBy = "idsite, visit_last_action_time DESC";
		$orderByParent = "sub.visit_last_action_time DESC";
		if(!empty($visitorId))
		{
			$where[] = "log_visit.idvisitor = ? ";
			$whereBind[] = Piwik_Common::hex2bin($visitorId);
		}

		if(!empty($maxIdVisit))
		{
			$where[] = "log_visit.idvisit < ? ";
			$whereBind[] = $maxIdVisit;
			$orderBy = "idvisit DESC";
			$orderByParent = "sub.idvisit DESC";
		}
		
		if(!empty($minTimestamp))
		{
			$where[] = "log_visit.visit_last_action_time > ? ";
			$whereBind[] = date("Y-m-d H:i:s", $minTimestamp);
		}
		
		// If no other filter, only look at the last 24 hours of stats
		if(empty($visitorId)
			&& empty($maxIdVisit)
			&& empty($period) 
			&& empty($date))
		{
			$period = 'day';
			$date = 'yesterdaySameTime';
		}

		// SQL Filter with provided period
		if (!empty($period) && !empty($date))
		{
			$currentSite = new Piwik_Site($idSite);
			$currentTimezone = $currentSite->getTimezone();
		
			$dateString = $date;
			if($period == 'range') 
			{ 
				$processedPeriod = new Piwik_Period_Range('range', $date);
				if($parsedDate = Piwik_Period_Range::parseDateRange($date))
				{
					$dateString = $parsedDate[2];
				}
			}
			else
			{
				$processedDate = Piwik_Date::factory($date);
				if($date == 'today'
					|| $date == 'now'
					|| $processedDate->toString() == Piwik_Date::factory('now', $currentTimezone)->toString())
				{
					$processedDate = $processedDate->subDay(1);
				}
				$processedPeriod = Piwik_Period::factory($period, $processedDate); 
			}
			$dateStart = $processedPeriod->getDateStart()->setTimezone($currentTimezone);
			$where[] = "log_visit.visit_last_action_time >= ?";
			$whereBind[] = $dateStart->toString('Y-m-d H:i:s');
			
			if(!in_array($date, array('now', 'today', 'yesterdaySameTime'))
				&& strpos($date, 'last') === false
				&& strpos($date, 'previous') === false
				&& Piwik_Date::factory($dateString)->toString('Y-m-d') != Piwik_Date::factory('now', $currentTimezone)->toString())
			{
				$dateEnd = $processedPeriod->getDateEnd()->setTimezone($currentTimezone);
				$where[] = " log_visit.visit_last_action_time <= ?";
				$dateEndString = $dateEnd->addDay(1)->toString('Y-m-d H:i:s');
				$whereBind[] = $dateEndString;
			}
		}

		$sqlWhere = "";
		if(count($where) > 0)
		{
			$sqlWhere = "
			WHERE " . join(" 
				AND ", $where);
		}

		$segment = new Piwik_Segment($segment, $idSite);
		$segmentSql = $segment->getSql();
		$sqlSegment = $segmentSql['sql'];
		if(!empty($sqlSegment)) $sqlSegment = ' AND '.$sqlSegment;
		$whereBind = array_merge ( $whereBind, $segmentSql['bind'] );
		
		// Subquery to use the indexes for ORDER BY
		// Group by idvisit so that a visitor converting 2 goals only appears twice
		$sql = "
				SELECT sub.* 
				FROM ( 
					SELECT 	*
					FROM " . Piwik_Common::prefixTable('log_visit') . " AS log_visit
					$sqlWhere
					$sqlSegment
					ORDER BY $orderBy
					LIMIT ".(int)$filter_limit."
				) AS sub
				GROUP BY sub.idvisit
				ORDER BY $orderByParent
			"; 
		try {
			$data = Piwik_FetchAll($sql, $whereBind);
		} catch(Exception $e) {
			echo $e->getMessage();exit;
		}
		
//var_dump($whereBind);	echo($sql);
//var_dump($data);
		return $data;
	}
コード例 #4
0
ファイル: Archive.php プロジェクト: BackupTheBerlios/oos-svn
	/**
	 * Builds an Archive object or returns the same archive if previously built.
	 *
	 * @param string|int idSite integer, or comma separated list of integer
	 * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory()
	 * @param string $period 'week' 'day' etc.
	 * 
	 * @return Piwik_Archive
	 */
	static public function build($idSite, $period, $strDate )
	{
		if($idSite === 'all')
		{
			$sites = Piwik_SitesManager_API::getSitesIdWithAtLeastViewAccess();
		}
		else
		{
			$sites = Piwik_Site::getIdSitesFromIdSitesString($idSite);
		}
		
		// idSite=1,3 or idSite=all
		if( count($sites) > 1 
			|| $idSite === 'all' )
		{
			$archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate);
		}
		// if a period date string is detected: either 'last30', 'previous10' or 'YYYY-MM-DD,YYYY-MM-DD'
		elseif(is_string($strDate) 
			&& (
				preg_match('/^(last|previous){1}([0-9]*)$/', $strDate, $regs)
				|| preg_match('/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$/', $strDate, $regs)
				)
			)
		{
			$oSite = new Piwik_Site($idSite);
			$archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate);
		}
		// case we request a single archive
		else
		{
			if(is_string($strDate))
			{
				$oDate = Piwik_Date::factory($strDate);
			}
			else
			{
				$oDate = $strDate;
			}
			$date = $oDate->toString();
			
			if(isset(self::$alreadyBuilt[$idSite][$date][$period]))
			{
				return self::$alreadyBuilt[$idSite][$date][$period];
			}
			
			$oPeriod = Piwik_Period::factory($period, $oDate);
			
			$archive = new Piwik_Archive_Single();
			$archive->setPeriod($oPeriod);
			$archive->setSite(new Piwik_Site($idSite));
			$archiveJustProcessed = $archive->prepareArchive();
			
			//we don't cache the archives just processed, the datatable were freed from memory 
			if(!$archiveJustProcessed)
			{
				self::$alreadyBuilt[$idSite][$date][$period] = $archive;
			}
		}
		
		return $archive;
	}
コード例 #5
0
	public function getSitesInfo()
	{
		$view = new Piwik_View("MultiSites/templates/index.tpl");
		$mySites = Piwik_SitesManager_API::getSitesWithAtLeastViewAccess();


		$params = $this->getGraphParamsModified();
		$this->dateToStr = $params['date'];

		$ids = 'all';
		$this->period = PiwiK_Common::getRequestVar('period', 'day');		

		$this->date = PiwiK_Common::getRequestVar('date', 'today');
		$lastDate =  date('Y-m-d',strtotime("-1 ".$this->period, strtotime($this->date)));

		$visits = Piwik_VisitsSummary_API::getVisits($ids, $this->period, $this->date);
		$lastVisits = Piwik_VisitsSummary_API::getVisits($ids, $this->period, $lastDate);

		$actions = Piwik_VisitsSummary_API::getActions($ids, $this->period, $this->date);
		$lastActions = Piwik_VisitsSummary_API::getActions($ids, $this->period, $lastDate);

		$uniqueUsers = Piwik_VisitsSummary_API::getUniqueVisitors($ids, $this->period, $this->date);
		$lastUniqueUsers = Piwik_VisitsSummary_API::getUniqueVisitors($ids, $this->period, $lastDate);

		$visitsSummary = $this->getSummary($lastVisits, $visits, $mySites, "visits");
		$actionsSummary = $this->getSummary($lastActions, $actions, $mySites, "actions");
		$uniqueSummary = $this->getSummary($lastUniqueUsers, $uniqueUsers, $mySites, "unique");

		$visitsArray = $visits->getArray();
		$actionsArray = $actions->getArray();
		$uniqueUsersArray = $uniqueUsers->getArray();
		$lastVisitsArray = $lastVisits->getArray();
		$lastActionsArray = $lastActions->getArray();
		$lastUniqueUsersArray = $lastUniqueUsers->getArray();
		foreach($mySites as &$site)
		{
			$idSite = $site['idsite'];
			$site['visits'] = array_shift($visitsArray[$idSite]->getColumn(0));
			$site['actions'] = array_shift($actionsArray[$idSite]->getColumn(0));
			$site['unique'] = array_shift($uniqueUsersArray[$idSite]->getColumn(0));
			$site['lastVisits'] = array_shift($lastVisitsArray[$idSite]->getColumn(0));
			$site['lastActions'] = array_shift($lastActionsArray[$idSite]->getColumn(0));
			$site['lastUnique'] = array_shift($lastUniqueUsersArray[$idSite]->getColumn(0));
			$site['visitsSummaryValue'] = $visitsSummary[$idSite];
			$site['actionsSummaryValue'] = $actionsSummary[$idSite];
			$site['uniqueSummaryValue'] = $uniqueSummary[$idSite];
		}

		$view->mySites = $mySites;
		$view->arrowAsc = '<img src="plugins/MultiSites/images/arrow_asc.gif" width="16px" height="16px" />';
		$view->arrowDesc = '<img src="plugins/MultiSites/images/arrow_desc.gif" width="16px" height="16px" />';
		$view->evolutionBy = $this->evolutionBy;
		$view->period = $this->period;
		$view->date = $this->date;
		$view->page = $this->page;
		$view->limit = $this->limit;
		$view->orderBy = $this->orderBy;
		$view->order = $this->order;
		$view->dateToStr = $this->dateToStr;
		
		$this->setGeneralVariablesView($view);
		$period = Piwik_Period::factory(Piwik_Common::getRequestVar('period'), Piwik_Date::factory($this->strDate));
		$view->prettyDate = $period->getLocalizedLongString();
		
		echo $view->render();
	}
コード例 #6
0
ファイル: PeriodTest.php プロジェクト: nnnnathann/piwik
 /**
  * @group Core
  * @group Period
  */
 public function testFactoryInvalid()
 {
     try {
         $period = Piwik_Period::factory('inValid', Piwik_Date::today());
     } catch (Exception $e) {
         return;
     }
     $this->fail('Expected Exception not raised');
 }
コード例 #7
0
 public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true)
 {
     $timer = new Piwik_Timer();
     if ($apiParameters === false) {
         $apiParameters = array();
     }
     if (!empty($idGoal) && empty($apiParameters['idGoal'])) {
         $apiParameters['idGoal'] = $idGoal;
     }
     // Is this report found in the Metadata available reports?
     $reportMetadata = $this->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date);
     if (empty($reportMetadata)) {
         throw new Exception("Requested report {$apiModule}.{$apiAction} for Website id={$idSite} not found in the list of available reports. \n");
     }
     $reportMetadata = reset($reportMetadata);
     // Generate Api call URL passing custom parameters
     $parameters = array_merge($apiParameters, array('method' => $apiModule . '.' . $apiAction, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'language' => $language));
     if (!empty($segment)) {
         $parameters['segment'] = $segment;
     }
     $url = Piwik_Url::getQueryStringFromParameters($parameters);
     $request = new Piwik_API_Request($url);
     try {
         /** @var Piwik_DataTable */
         $dataTable = $request->process();
     } catch (Exception $e) {
         throw new Exception("API returned an error: " . $e->getMessage() . "\n");
     }
     list($newReport, $columns, $rowsMetadata) = $this->handleTableReport($idSite, $dataTable, $reportMetadata, isset($reportMetadata['dimension']));
     foreach ($columns as $columnId => &$name) {
         $name = ucfirst($name);
     }
     $website = new Piwik_Site($idSite);
     //    	$segment = new Piwik_Segment($segment, $idSite);
     if (Piwik_Archive::isMultiplePeriod($date, $period)) {
         $period = new Piwik_Period_Range($period, $date);
     } else {
         if ($period == 'range') {
             $period = new Piwik_Period_Range($period, $date);
         } else {
             $period = Piwik_Period::factory($period, Piwik_Date::factory($date));
         }
     }
     $period = $period->getLocalizedLongString();
     $return = array('website' => $website->getName(), 'prettyDate' => $period, 'metadata' => $reportMetadata, 'columns' => $columns, 'reportData' => $newReport, 'reportMetadata' => $rowsMetadata);
     if ($showTimer) {
         $return['timerMillis'] = $timer->getTimeMs(0);
     }
     return $return;
 }
コード例 #8
0
 protected function setGeneralVariablesView($view)
 {
     $view->date = $this->strDate;
     try {
         $this->setPeriodVariablesView($view);
         $period = Piwik_Period::factory(Piwik_Common::getRequestVar('period'), Piwik_Date::factory($this->strDate));
         $view->prettyDate = $period->getLocalizedLongString();
         $idSite = Piwik_Common::getRequestVar('idSite');
         $view->idSite = $idSite;
         $site = new Piwik_Site($idSite);
         $view->siteName = $site->getName();
         $view->siteMainUrl = $site->getMainUrl();
         $minDate = $site->getCreationDate();
         $view->minDateYear = $minDate->toString('Y');
         $view->minDateMonth = $minDate->toString('m');
         $view->minDateDay = $minDate->toString('d');
     } catch (Exception $e) {
         self::redirectToIndex(Piwik::getModule(), Piwik::getAction());
     }
 }
コード例 #9
0
ファイル: Range.php プロジェクト: Gninety/Microweber
 function fillArraySubPeriods($startDate, $endDate, $period)
 {
     $arrayPeriods = array();
     $endSubperiod = Piwik_Period::factory($period, $endDate);
     $arrayPeriods[] = $endSubperiod;
     while ($endDate->isLater($startDate)) {
         $endDate = self::removePeriod($period, $endDate, 1);
         $subPeriod = Piwik_Period::factory($period, $endDate);
         $arrayPeriods[] = $subPeriod;
     }
     $arrayPeriods = array_reverse($arrayPeriods);
     foreach ($arrayPeriods as $period) {
         $this->addSubperiod($period);
     }
 }
コード例 #10
0
ファイル: API.php プロジェクト: BeezyT/piwik-sitesearch
 /** Returns period object
  * @return Piwik_Period */
 private function getPeriod($date, $period)
 {
     return Piwik_Period::factory($period, Piwik_Date::factory($date));
 }
コード例 #11
0
ファイル: Archive.php プロジェクト: nnnnathann/piwik
 /**
  * Creates a period instance using a Piwik_Site instance and two strings describing
  * the period & date.
  * 
  * @param Piwik_Site $site
  * @param string $strPeriod The period string: day, week, month, year, range
  * @param string $strDate The date or date range string.
  * @return Piwik_Period
  */
 public static function makePeriodFromQueryParams($site, $strPeriod, $strDate)
 {
     $tz = $site->getTimezone();
     if ($strPeriod == 'range') {
         $oPeriod = new Piwik_Period_Range('range', $strDate, $tz, Piwik_Date::factory('today', $tz));
     } else {
         if (is_string($strDate)) {
             if ($strDate == 'now' || $strDate == 'today') {
                 $strDate = date('Y-m-d', Piwik_Date::factory('now', $tz)->getTimestamp());
             } elseif ($strDate == 'yesterday' || $strDate == 'yesterdaySameTime') {
                 $strDate = date('Y-m-d', Piwik_Date::factory('now', $tz)->subDay(1)->getTimestamp());
             }
             $oDate = Piwik_Date::factory($strDate);
         } else {
             $oDate = $strDate;
         }
         $date = $oDate->toString();
         $oPeriod = Piwik_Period::factory($strPeriod, $oDate);
     }
     return $oPeriod;
 }
コード例 #12
0
ファイル: API.php プロジェクト: nomoto-ubicast/piwik
 /**
  * When tracking data in the past (using Tracking API), this function
  * can be used to invalidate reports for the idSites and dates where new data
  * was added. 
  * DEV: If you call this API, the UI should display the data correctly, but will process
  *      in real time, which could be very slow after large data imports. 
  *      After calling this function via REST, you can manually force all data 
  *      to be reprocessed by visiting the script as the Super User:
  *      http://example.net/piwik/misc/cron/archive.php?token_auth=$SUPER_USER_TOKEN_AUTH_HERE 
  * REQUIREMENTS: On large piwik setups, you will need in PHP configuration: max_execution_time = 0
  * 	We recommend to use an hourly schedule of the script at misc/cron/archive.php 
  * 	More information: http://piwik.org/setup-auto-archiving/
  * 
  * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates
  * @param string $dates Comma separated list of dates to invalidate for all these websites
  * @return array
  */
 public function invalidateArchivedReports($idSites, $dates)
 {
     $idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites);
     if (empty($idSites)) {
         throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission");
     }
     Piwik::checkUserHasAdminAccess($idSites);
     // Ensure the specified dates are valid
     $toInvalidate = $invalidDates = array();
     $dates = explode(',', $dates);
     $dates = array_unique($dates);
     foreach ($dates as $theDate) {
         try {
             $date = Piwik_Date::factory($theDate);
         } catch (Exception $e) {
             $invalidDates[] = $theDate;
             continue;
         }
         if ($date->toString() == $theDate) {
             $toInvalidate[] = $date;
         } else {
             $invalidDates[] = $theDate;
         }
     }
     // Lookup archive tables
     $tables = Piwik::getTablesInstalled();
     $archiveTables = Piwik::getTablesArchivesInstalled();
     // If using the feature "Delete logs older than N days"...
     $logsAreDeletedBeforeThisDate = Piwik_Config::getInstance()->Deletelogs['delete_logs_schedule_lowest_interval'];
     $logsDeleteEnabled = Piwik_Config::getInstance()->Deletelogs['delete_logs_enable'];
     $minimumDateWithLogs = false;
     if ($logsDeleteEnabled && $logsAreDeletedBeforeThisDate) {
         $minimumDateWithLogs = Piwik_Date::factory('today')->subDay($logsAreDeletedBeforeThisDate);
     }
     // Given the list of dates, process which tables they should be deleted from
     $minDate = false;
     $warningDates = $processedDates = array();
     /* @var $date Piwik_Date */
     foreach ($toInvalidate as $date) {
         // we should only delete reports for dates that are more recent than N days
         if ($minimumDateWithLogs && $date->isEarlier($minimumDateWithLogs)) {
             $warningDates[] = $date->toString();
         } else {
             $processedDates[] = $date->toString();
         }
         $month = $date->toString('Y_m');
         // For a given date, we must invalidate in the monthly archive table
         $datesByMonth[$month][] = $date->toString();
         // But also the year stored in January
         $year = $date->toString('Y_01');
         $datesByMonth[$year][] = $date->toString();
         // but also weeks overlapping several months stored in the month where the week is starting
         /* @var $week Piwik_Period_Week */
         $week = Piwik_Period::factory('week', $date);
         $week = $week->getDateStart()->toString('Y_m');
         $datesByMonth[$week][] = $date->toString();
         // Keep track of the minimum date for each website
         if ($minDate === false || $date->isEarlier($minDate)) {
             $minDate = $date;
         }
     }
     // In each table, invalidate day/week/month/year containing this date
     $sqlIdSites = implode(",", $idSites);
     foreach ($archiveTables as $table) {
         // Extract Y_m from table name
         $suffix = str_replace(array('archive_numeric_', 'archive_blob_'), '', Piwik_Common::unprefixTable($table));
         if (!isset($datesByMonth[$suffix])) {
             continue;
         }
         // Dates which are to be deleted from this table
         $datesToDeleteInTable = $datesByMonth[$suffix];
         // Build one statement to delete all dates from the given table
         $sql = $bind = array();
         $datesToDeleteInTable = array_unique($datesToDeleteInTable);
         foreach ($datesToDeleteInTable as $dateToDelete) {
             $sql[] = '(date1 <= ? AND ? <= date2)';
             $bind[] = $dateToDelete;
             $bind[] = $dateToDelete;
         }
         $sql = implode(" OR ", $sql);
         $query = "DELETE FROM {$table} " . " WHERE ( {$sql} ) " . " AND idsite IN (" . $sqlIdSites . ")";
         Piwik_Query($query, $bind);
         //			var_dump($query);var_dump($bind);
     }
     // Update piwik_site.ts_created
     $query = "UPDATE " . Piwik_Common::prefixTable("site") . " SET ts_created = ?" . " WHERE idsite IN ( {$sqlIdSites} )\n\t\t\t\t\tAND ts_created > ?";
     $minDateSql = $minDate->subDay(1)->getDatetime();
     $bind = array($minDateSql, $minDateSql);
     Piwik_Query($query, $bind);
     //		var_dump($query);var_dump($bind);
     // Force to re-process data for these websites in the next archive.php cron run
     $invalidatedIdSites = Piwik_CoreAdminHome_API::getWebsiteIdsToInvalidate();
     $invalidatedIdSites = array_merge($invalidatedIdSites, $idSites);
     $invalidatedIdSites = array_unique($invalidatedIdSites);
     $invalidatedIdSites = array_values($invalidatedIdSites);
     Piwik_SetOption(self::OPTION_INVALIDATED_IDSITES, serialize($invalidatedIdSites));
     Piwik_Site::clearCache();
     $output = array();
     // output logs
     if ($warningDates) {
         $output[] = 'Warning: the following Dates have not been invalidated, because they are earlier than your Log Deletion limit: ' . implode(", ", $warningDates) . "\n The last day with logs is " . $minimumDateWithLogs . ". " . "\n Please disable 'Delete old Logs' or set it to a higher deletion threshold (eg. 180 days or 365 years).'.";
     }
     $output[] = "Success. The following dates were invalidated successfully: " . implode(", ", $processedDates);
     return $output;
 }
コード例 #13
0
ファイル: Controller.php プロジェクト: josl/CGE-File-Sharing
 /**
  * Returns the pretty date representation
  *
  * @param $date string
  * @param $period string
  * @return string Pretty date
  */
 public static function getPrettyDate($date, $period)
 {
     return self::getCalendarPrettyDate(Piwik_Period::factory($period, Piwik_Date::factory($date)));
 }
コード例 #14
0
ファイル: Range.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Adds new subperiods
  *
  * @param Piwik_Date  $startDate
  * @param Piwik_Date  $endDate
  * @param string      $period
  */
 protected function fillArraySubPeriods($startDate, $endDate, $period)
 {
     $arrayPeriods = array();
     $endSubperiod = Piwik_Period::factory($period, $endDate);
     $arrayPeriods[] = $endSubperiod;
     // set end date to start of end period since we're comparing against start date.
     $endDate = $endSubperiod->getDateStart();
     while ($endDate->isLater($startDate)) {
         $endDate = self::removePeriod($period, $endDate, 1);
         $subPeriod = Piwik_Period::factory($period, $endDate);
         $arrayPeriods[] = $subPeriod;
     }
     $arrayPeriods = array_reverse($arrayPeriods);
     foreach ($arrayPeriods as $period) {
         $this->addSubperiod($period);
     }
 }
コード例 #15
0
	protected function setGeneralVariablesView($view)
	{
		$view->date = $this->strDate;
		
		try {
			$this->setPeriodVariablesView($view);
			$period = Piwik_Period::factory(Piwik_Common::getRequestVar('period'), Piwik_Date::factory($this->strDate));
			$view->prettyDate = $period->getLocalizedLongString();
			$idSite = Piwik_Common::getRequestVar('idSite');
			$view->idSite = $idSite;
			$site = new Piwik_Site($idSite);
			$view->siteName = $site->getName();
			$view->siteMainUrl = $site->getMainUrl();
			
			$minDate = $site->getCreationDate();
			$view->minDateYear = $minDate->toString('Y');
			$view->minDateMonth = $minDate->toString('m');
			$view->minDateDay = $minDate->toString('d');

			$maxDate = Piwik_Date::factory('today');
			$view->maxDateYear = $maxDate->toString('Y');
			$view->maxDateMonth = $maxDate->toString('m');
			$view->maxDateDay = $maxDate->toString('d');

			$view->debugTrackVisitsInsidePiwikUI = Zend_Registry::get('config')->Debug->track_visits_inside_piwik_ui;

			$view->isSuperUser = Zend_Registry::get('access')->isSuperUser();
		} catch(Exception $e) {
			self::redirectToIndex(Piwik::getModule(), Piwik::getAction());
		}
	}
コード例 #16
0
ファイル: Range.php プロジェクト: Doluci/tomatocart
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
         $lastN = $regs[2];
         $lastOrPrevious = $regs[1];
         if (!is_null($this->defaultEndDate)) {
             $defaultEndDate = $this->defaultEndDate;
         } else {
             $defaultEndDate = Piwik_Date::today();
         }
         if ($lastOrPrevious == 'last') {
             $endDate = $defaultEndDate;
         } elseif ($lastOrPrevious == 'previous') {
             $endDate = $this->removePeriod($defaultEndDate, 1);
         }
         // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
         $lastN--;
         $lastN = abs($lastN);
         $lastN = $this->getMaxN($lastN);
         $startDate = $this->removePeriod($endDate, $lastN);
     } elseif (preg_match('/([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})/', $this->strDate, $regs)) {
         $strDateStart = $regs[1];
         $strDateEnd = $regs[2];
         $startDate = Piwik_Date::factory($strDateStart);
         $endDate = Piwik_Date::factory($strDateEnd);
     } else {
         throw new Exception("The date '{$this->strDate}' is not a date range. Should have the following format: 'lastN' or 'previousN' or 'YYYY-MM-DD,YYYY-MM-DD'.");
     }
     $endSubperiod = Piwik_Period::factory($this->strPeriod, $endDate);
     $arrayPeriods = array();
     $arrayPeriods[] = $endSubperiod;
     while ($endDate->isLater($startDate)) {
         $endDate = $this->removePeriod($endDate, 1);
         $subPeriod = Piwik_Period::factory($this->strPeriod, $endDate);
         $arrayPeriods[] = $subPeriod;
     }
     $arrayPeriods = array_reverse($arrayPeriods);
     foreach ($arrayPeriods as $period) {
         $this->addSubperiod($period);
     }
 }
コード例 #17
0
ファイル: Archive.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * Builds an Archive object or returns the same archive if previously built.
  *
  * @param string|int idSite integer, or comma separated list of integer
  * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory()
  * @param string $period 'week' 'day' etc.
  * @param string Segment definition - defaults to false for Backward Compatibility
  * 
  * @return Piwik_Archive
  */
 public static function build($idSite, $period, $strDate, $segment = false)
 {
     if ($idSite === 'all') {
         $sites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess();
     } else {
         $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite);
     }
     if (!$segment instanceof Piwik_Segment) {
         $segment = new Piwik_Segment($segment, $idSite);
     }
     // idSite=1,3 or idSite=all
     if (count($sites) > 1 || $idSite === 'all') {
         $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate, $segment);
     } elseif (is_string($strDate) && self::isMultiplePeriod($strDate, $period)) {
         $oSite = new Piwik_Site($idSite);
         $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate, $segment);
     } else {
         $oSite = new Piwik_Site($idSite);
         if ($period == 'range') {
             $oPeriod = new Piwik_Period_Range('range', $strDate, $oSite->getTimezone(), Piwik_Date::factory('today', $oSite->getTimezone()));
         } else {
             if (is_string($strDate)) {
                 if ($strDate == 'now' || $strDate == 'today') {
                     $strDate = date('Y-m-d', Piwik_Date::factory('now', $oSite->getTimezone())->getTimestamp());
                 } elseif ($strDate == 'yesterday' || $strDate == 'yesterdaySameTime') {
                     $strDate = date('Y-m-d', Piwik_Date::factory('now', $oSite->getTimezone())->subDay(1)->getTimestamp());
                 }
                 $oDate = Piwik_Date::factory($strDate);
             } else {
                 $oDate = $strDate;
             }
             $date = $oDate->toString();
             $oPeriod = Piwik_Period::factory($period, $oDate);
         }
         $archive = new Piwik_Archive_Single();
         $archive->setPeriod($oPeriod);
         $archive->setSite($oSite);
         $archive->setSegment($segment);
     }
     return $archive;
 }
コード例 #18
0
ファイル: Csv.php プロジェクト: nnnnathann/piwik
 /**
  * Sends the http headers for csv file
  */
 protected function renderHeader()
 {
     $fileName = 'Piwik ' . Piwik_Translate('General_Export');
     $period = Piwik_Common::getRequestVar('period', false);
     $date = Piwik_Common::getRequestVar('date', false);
     if ($period || $date) {
         if ($period == 'range') {
             $period = new Piwik_Period_Range($period, $date);
         } else {
             if (strpos($date, ',') !== false) {
                 $period = new Piwik_Period_Range('range', $date);
             } else {
                 $period = Piwik_Period::factory($period, Piwik_Date::factory($date));
             }
         }
         $prettyDate = $period->getLocalizedLongString();
         $meta = $this->getApiMetaData();
         $fileName .= ' _ ' . $meta['name'] . ' _ ' . $prettyDate . '.csv';
     }
     // silent fail otherwise unit tests fail
     @header('Content-Type: application/vnd.ms-excel');
     @header('Content-Disposition: attachment; filename="' . $fileName . '"');
     Piwik::overrideCacheControlHeaders();
 }
コード例 #19
0
ファイル: Archive.php プロジェクト: BackupTheBerlios/oos-svn
 /**
  * Builds an Archive object or returns the same archive if previously built.
  *
  * @param string|int idSite integer, or comma separated list of integer
  * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory()
  * @param string $period 'week' 'day' etc.
  * 
  * @return Piwik_Archive
  */
 public static function build($idSite, $period, $strDate)
 {
     if ($idSite === 'all') {
         $sites = Piwik_SitesManager_API::getSitesIdWithAtLeastViewAccess();
     } else {
         $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite);
     }
     // idSite=1,3 or idSite=all
     if (count($sites) > 1 || $idSite === 'all') {
         require_once 'Archive/Array/IndexedBySite.php';
         $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate);
     } elseif (is_string($strDate) && (ereg('^(last|previous){1}([0-9]*)$', $strDate, $regs) || ereg('^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$', $strDate, $regs))) {
         $oSite = new Piwik_Site($idSite);
         require_once 'Archive/Array/IndexedByDate.php';
         $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate);
     } else {
         if (is_string($strDate)) {
             $oDate = Piwik_Date::factory($strDate);
         } else {
             $oDate = $strDate;
         }
         $date = $oDate->toString();
         if (isset(self::$alreadyBuilt[$idSite][$date][$period])) {
             return self::$alreadyBuilt[$idSite][$date][$period];
         }
         $oPeriod = Piwik_Period::factory($period, $oDate);
         $archive = new Piwik_Archive_Single();
         $archive->setPeriod($oPeriod);
         $archive->setSite(new Piwik_Site($idSite));
         $archiveJustProcessed = $archive->prepareArchive();
         //we don't cache the archives just processed, the datatable were freed from memory
         if (!$archiveJustProcessed) {
             self::$alreadyBuilt[$idSite][$date][$period] = $archive;
         }
     }
     return $archive;
 }
コード例 #20
0
ファイル: Controller.php プロジェクト: nomoto-ubicast/piwik
 public function getSitesInfo($isWidgetized)
 {
     Piwik::checkUserHasSomeViewAccess();
     $displayRevenueColumn = Piwik_Common::isGoalPluginEnabled();
     $date = Piwik_Common::getRequestVar('date', 'today');
     $period = Piwik_Common::getRequestVar('period', 'day');
     $siteIds = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess();
     list($minDate, $maxDate) = $this->getMinMaxDateAcrossWebsites($siteIds);
     // overwrites the default Date set in the parent controller
     // Instead of the default current website's local date,
     // we set "today" or "yesterday" based on the default Piwik timezone
     $piwikDefaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
     if ($period != 'range') {
         $date = $this->getDateParameterInTimezone($date, $piwikDefaultTimezone);
         $this->setDate($date);
         $date = $date->toString();
     }
     $dataTable = Piwik_MultiSites_API::getInstance()->getAll($period, $date, $segment = false);
     // put data into a form the template will understand better
     $digestableData = array();
     foreach ($siteIds as $idSite) {
         $isEcommerceEnabled = Piwik_Site::isEcommerceEnabledFor($idSite);
         $digestableData[$idSite] = array('idsite' => $idSite, 'main_url' => Piwik_Site::getMainUrlFor($idSite), 'name' => Piwik_Site::getNameFor($idSite), 'visits' => 0, 'pageviews' => 0);
         if ($period != 'range') {
             $digestableData[$idSite]['visits_evolution'] = 0;
             $digestableData[$idSite]['pageviews_evolution'] = 0;
         }
         if ($displayRevenueColumn) {
             $revenueDefault = $isEcommerceEnabled ? 0 : "'-'";
             if ($period != 'range') {
                 $digestableData[$idSite]['revenue_evolution'] = $revenueDefault;
             }
         }
     }
     foreach ($dataTable->getRows() as $row) {
         $idsite = (int) $row->getMetadata('idsite');
         $site =& $digestableData[$idsite];
         $site['visits'] = (int) $row->getColumn('nb_visits');
         $site['pageviews'] = (int) $row->getColumn('nb_pageviews');
         if ($displayRevenueColumn) {
             if ($row->getColumn('revenue') !== false) {
                 $site['revenue'] = $row->getColumn('revenue');
             }
         }
         if ($period != 'range') {
             $site['visits_evolution'] = $row->getColumn('visits_evolution');
             $site['pageviews_evolution'] = $row->getColumn('pageviews_evolution');
             if ($displayRevenueColumn) {
                 $site['revenue_evolution'] = $row->getColumn('revenue_evolution');
             }
         }
     }
     $this->applyPrettyMoney($digestableData);
     $view = new Piwik_View("MultiSites/templates/index.tpl");
     $view->isWidgetized = $isWidgetized;
     $view->sitesData = array_values($digestableData);
     $view->evolutionBy = $this->evolutionBy;
     $view->period = $period;
     $view->page = $this->page;
     $view->limit = $this->limit;
     $view->orderBy = $this->orderBy;
     $view->order = $this->order;
     $view->totalVisits = $dataTable->getMetadata('total_nb_visits');
     $view->totalRevenue = $dataTable->getMetadata('total_revenue');
     $view->displayRevenueColumn = $displayRevenueColumn;
     $view->totalPageviews = $dataTable->getMetadata('total_nb_pageviews');
     $view->pastTotalVisits = $dataTable->getMetadata('last_period_total_nb_visits');
     $view->totalVisitsEvolution = $dataTable->getMetadata('total_visits_evolution');
     if ($view->totalVisitsEvolution > 0) {
         $view->totalVisitsEvolution = '+' . $view->totalVisitsEvolution;
     }
     if ($period != 'range') {
         $lastPeriod = Piwik_Period::factory($period, $dataTable->getMetadata('last_period_date'));
         $view->pastPeriodPretty = self::getCalendarPrettyDate($lastPeriod);
     }
     $params = $this->getGraphParamsModified();
     $view->dateSparkline = $period == 'range' ? $date : $params['date'];
     $view->autoRefreshTodayReport = false;
     // if the current date is today, or yesterday,
     // in case the website is set to UTC-12), or today in UTC+14, we refresh the page every 5min
     if (in_array($date, array('today', date('Y-m-d'), 'yesterday', Piwik_Date::factory('yesterday')->toString('Y-m-d'), Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d')))) {
         $view->autoRefreshTodayReport = Piwik_Config::getInstance()->General['multisites_refresh_after_seconds'];
     }
     $this->setGeneralVariablesView($view);
     $this->setMinDateView($minDate, $view);
     $this->setMaxDateView($maxDate, $view);
     $view->show_sparklines = Piwik_Config::getInstance()->General['show_multisites_sparklines'];
     echo $view->render();
 }
コード例 #21
0
ファイル: Controller.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Sets general variables to the view that are used by
  * various templates and Javascript.
  * If any error happens, displays the login screen
  *
  * @param Piwik_View  $view
  * @throws Exception
  * @return void
  */
 protected function setGeneralVariablesView($view)
 {
     $view->date = $this->strDate;
     try {
         $view->idSite = $this->idSite;
         if (empty($this->site) || empty($this->idSite)) {
             throw new Exception("The requested website idSite is not found in the request, or is invalid.\n\t\t\t\tPlease check that you are logged in Piwik and have permission to access the specified website.");
         }
         $this->setPeriodVariablesView($view);
         $rawDate = Piwik_Common::getRequestVar('date');
         $periodStr = Piwik_Common::getRequestVar('period');
         if ($periodStr != 'range') {
             $date = Piwik_Date::factory($this->strDate);
             $period = Piwik_Period::factory($periodStr, $date);
         } else {
             $period = new Piwik_Period_Range($periodStr, $rawDate, $this->site->getTimezone());
         }
         $view->rawDate = $rawDate;
         $view->prettyDate = self::getCalendarPrettyDate($period);
         $view->siteName = $this->site->getName();
         $view->siteMainUrl = $this->site->getMainUrl();
         $datetimeMinDate = $this->site->getCreationDate()->getDatetime();
         $minDate = Piwik_Date::factory($datetimeMinDate, $this->site->getTimezone());
         $this->setMinDateView($minDate, $view);
         $maxDate = Piwik_Date::factory('now', $this->site->getTimezone());
         $this->setMaxDateView($maxDate, $view);
         // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
         $dateStart = $period->getDateStart();
         if ($dateStart->isEarlier($minDate)) {
             $dateStart = $minDate;
         }
         $dateEnd = $period->getDateEnd();
         if ($dateEnd->isLater($maxDate)) {
             $dateEnd = $maxDate;
         }
         $view->startDate = $dateStart;
         $view->endDate = $dateEnd;
         $language = Piwik_LanguagesManager::getLanguageForSession();
         $view->language = !empty($language) ? $language : Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
         $view->config_action_url_category_delimiter = Piwik_Config::getInstance()->General['action_url_category_delimiter'];
         $this->setBasicVariablesView($view);
     } catch (Exception $e) {
         Piwik_ExitWithMessage($e->getMessage());
     }
 }
コード例 #22
0
ファイル: Controller.php プロジェクト: Gninety/Microweber
 /**
  * Sets general variables to the view that are used by various templates and Javascript.
  * If any error happens, displays the login screen
  * @param Piwik_View $view
  * @return void
  */
 protected function setGeneralVariablesView($view)
 {
     $view->date = $this->strDate;
     try {
         $view->idSite = $this->idSite;
         if (empty($this->site) || empty($this->idSite)) {
             throw new Exception("The requested website idSite is not found in the request, or is invalid");
         }
         $this->setPeriodVariablesView($view);
         $rawDate = Piwik_Common::getRequestVar('date');
         $periodStr = Piwik_Common::getRequestVar('period');
         if ($periodStr != 'range') {
             $date = Piwik_Date::factory($this->strDate);
             $period = Piwik_Period::factory($periodStr, $date);
         } else {
             $period = new Piwik_Period_Range($periodStr, $rawDate, $this->site->getTimezone());
         }
         $view->rawDate = $rawDate;
         $view->prettyDate = $period->getPrettyString();
         $view->siteName = $this->site->getName();
         $view->siteMainUrl = $this->site->getMainUrl();
         $datetimeMinDate = $this->site->getCreationDate()->getDatetime();
         $minDate = Piwik_Date::factory($datetimeMinDate, $this->site->getTimezone());
         $this->setMinDateView($minDate, $view);
         $maxDate = Piwik_Date::factory('now', $this->site->getTimezone());
         $this->setMaxDateView($maxDate, $view);
         // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
         $dateStart = $period->getDateStart();
         if ($dateStart->isEarlier($minDate)) {
             $dateStart = $minDate;
         }
         $dateEnd = $period->getDateEnd();
         if ($dateEnd->isLater($maxDate)) {
             $dateEnd = $maxDate;
         }
         $view->startDate = $dateStart;
         $view->endDate = $dateEnd;
         $this->setBasicVariablesView($view);
     } catch (Exception $e) {
         Piwik_ExitWithMessage($e->getMessage());
     }
 }