本文整理汇总了PHP中Piwik_Date::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Date::factory方法的具体用法?PHP Piwik_Date::factory怎么用?PHP Piwik_Date::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Date
的用法示例。
在下文中一共展示了Piwik_Date::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getScheduledTasks
function getScheduledTasks($notification)
{
// Reports have to be sent when the period ends for all websites
$maxHourOffset = 0;
$uniqueTimezones = Piwik_SitesManager_API::getInstance()->getUniqueSiteTimezones();
$baseDate = Piwik_Date::factory("1971-01-01");
foreach ($uniqueTimezones as &$timezone) {
$offsetDate = Piwik_Date::factory($baseDate->toString(), $timezone);
// Earlier means a negative timezone
if ($offsetDate->isEarlier($baseDate)) {
// Gets the timezone offset
$hourOffset = 24 - date('H', $offsetDate->getTimestamp());
if ($hourOffset > $maxHourOffset) {
$maxHourOffset = $hourOffset;
}
}
}
$tasks =& $notification->getNotificationObject();
$dailySchedule = new Piwik_ScheduledTime_Daily();
$dailySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'dailySchedule', $dailySchedule);
$weeklySchedule = new Piwik_ScheduledTime_Weekly();
$weeklySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'weeklySchedule', $weeklySchedule);
$monthlySchedule = new Piwik_ScheduledTime_Monthly();
$monthlySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'monthlySchedule', $monthlySchedule);
}
示例2: renderTable
/**
* Computes the output for the given data table
*
* @param Piwik_DataTable $table
* @return string
* @throws Exception
*/
protected function renderTable($table)
{
if (!$table instanceof Piwik_DataTable_Array || $table->getKeyName() != 'date') {
throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
}
$idSite = Piwik_Common::getRequestVar('idSite', 1, 'int');
$period = Piwik_Common::getRequestVar('period');
$piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
$out = "";
$moreRecentFirst = array_reverse($table->getArray(), true);
foreach ($moreRecentFirst as $date => $subtable) {
$timestamp = $table->metadata[$date]['timestamp'];
$site = $table->metadata[$date]['site'];
$pudDate = date('r', $timestamp);
$dateInSiteTimezone = Piwik_Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
$thisPiwikUrl = Piwik_Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
$siteName = $site->getName();
$title = $siteName . " on " . $date;
$out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
$out .= Piwik_Common::sanitizeInputValue($this->renderDataTable($subtable));
$out .= "</description>\n\t</item>\n";
}
$header = $this->getRssHeader();
$footer = $this->getRssFooter();
return $header . $out . $footer;
}
示例3: 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;
}
示例4: advancedFactory
/**
* The advanced factory method is easier to use from the API than the factory
* method above. It doesn't require an instance of Piwik_Date and works for
* period=range. Generally speaking, anything that can be passed as period
* and range to the API methods can directly be forwarded to this factory
* method in order to get a suitable instance of Piwik_Period.
*
* @param string $strPeriod "day", "week", "month", "year", "range"
* @param string $strDate
* @return Piwik_Period
*/
public static function advancedFactory($strPeriod, $strDate)
{
if (Piwik_Archive::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range') {
return new Piwik_Period_Range($strPeriod, $strDate);
}
return self::factory($strPeriod, Piwik_Date::factory($strDate));
}
示例5: setUp
public function setUp()
{
// add one site
$this->idSite = $this->createWebsite($this->dateTime, 1, "Site #0");
// add two goals
$goals = Piwik_Goals_API::getInstance();
$this->idGoal1 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
$this->idGoal2 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
$urls = array();
for ($i = 0; $i != 2; ++$i) {
$url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1);
$title = "page view " . ($i - 1) . " / " . ($i + 1);
$urls[$url] = $title;
}
$visitTimes = array();
$date = Piwik_Date::factory($this->dateTime);
for ($i = 0; $i != 250; ++$i) {
// spread visits out through entire year
$day = floor(365 * $i / 250);
for ($j = 0; $j != 2; ++$j) {
$visitTimes[] = $date->addDay($day)->addHour($j)->toString();
}
}
// add 12,000 page views (2 visits of 2 page views for 12 visitors on 250 days spread out through year)
for ($visitor = 0; $visitor != 12; ++$visitor) {
$t = $this->getTracker($this->idSite, $this->dateTime);
foreach ($visitTimes as $visitTime) {
$t->setForceVisitDateTime($visitTime);
foreach ($urls as $url => $title) {
$t->setUrl($url);
$t->doTrackPageView($title);
}
}
}
}
示例6: build
/**
* 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;
}
示例7: trackVisits
protected static function trackVisits()
{
// Visitor site1
$visitor = self::getTracker(self::$idSite1, self::$dateTime, $defaultInit = true);
// Test w/ iso-8859-15
$visitor->setForceVisitDateTime(Piwik_Date::factory(self::$dateTime)->addHour(0.3)->getDatetime());
$visitor->setUrlReferrer('http://anothersite.com/whatever.html?whatever=Ato%FC');
$visitor->setUrl('http://example.org/index.htm?random=param&mykwd=Search 2%FC&test&cats= Search Category &search_count=INCORRECT!');
$visitor->setDebugStringAppend('&cs=iso-8859-15');
self::checkResponse($visitor->doTrackPageView('Site Search results'));
$visitor->setDebugStringAppend('');
// Test w/ windows-1251
$visitor = self::getTracker(self::$idSite1, self::$dateTime, $defaultInit = true);
$visitor->setForceVisitDateTime(Piwik_Date::factory(self::$dateTime)->addHour(0.3)->getDatetime());
$visitor->setUrlReferrer('http://anothersite.com/whatever.html?txt=%EC%E5%F8%EA%EE%E2%FB%E5');
$visitor->setUrl('http://example.org/page/index.htm?whatever=%EC%E5%F8%EA%EE%E2%FB%E5');
$visitor->setDebugStringAppend('&cs=windows-1251');
self::checkResponse($visitor->doTrackPageView('Page title is always UTF-8'));
$visitor->setDebugStringAppend('');
// Test invalid char set
$visitor = self::getTracker(self::$idSite1, self::$dateTime, $defaultInit = true);
$visitor->setForceVisitDateTime(Piwik_Date::factory(self::$dateTime)->addHour(1)->getDatetime());
$visitor->setUrlReferrer('http://anothersite.com/whatever.html');
$visitor->setUrl('http://example.org/index.htm?random=param&mykwd=a+keyword&test&cats= Search Category &search_count=INCORRECT!');
$visitor->setDebugStringAppend('&cs=GTF-42');
// galactic transformation format
self::checkResponse($visitor->doTrackPageView('Site Search results'));
$visitor->setDebugStringAppend('');
}
示例8: trackVisits
protected static function trackVisits()
{
// tests run in UTC, the Tracker in UTC
$dateTime = self::$dateTime;
$idSite = self::$idSite;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
// Also testing to record this as a bot while specifically allowing bots
$t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
$t->DEBUG_APPEND_URL .= '&bots=1';
$t->DEBUG_APPEND_URL .= '&forceIpAnonymization=1';
// VISIT 1 = Referrer is "Keyword not defined"
// Alsotrigger goal to check that attribution goes to this keyword
$t->setUrlReferrer('http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC&url=http%3A%2F%2Fpiwik.org%2F&ei=&usg=');
$t->setUrl('http://example.org/this%20is%20cool!');
self::checkResponse($t->doTrackPageView('incredible title!'));
$idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
// VISIT 2 = Referrer has keyword, but the URL should be rewritten
// in Live Output to point to google search result page
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime());
$t->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
// Test with empty title, that the output of Live is valid
self::checkResponse($t->doTrackPageView(''));
}
示例9: 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'))
);
}
}
}
示例10: testGetPrettyString
/**
* @group Core
* @group Period
* @group Period_Year
*/
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
$year = new Piwik_Period_Year(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024';
$this->assertEquals($shouldBe, $year->getPrettyString());
}
示例11: trackVisits
protected function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
$idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit;
$t = $this->getTracker($idSite, $dateTime, $defaultInit = true);
// Record 1st goal, should only have 1 conversion
$t->setUrl('http://example.org/index.htm');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
$this->checkResponse($t->doTrackPageView('Thank you mate'));
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
$this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000));
// Record 2nd goal, should record both conversions
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
$this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300));
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime());
$this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366));
// Update & set to not allow multiple
$goals = Piwik_Goals_API::getInstance()->getGoals($idSite);
$goal = $goals[$idGoal_OneConversionPerVisit];
$this->assertTrue($goal['allow_multiple'] == 0);
Piwik_Goals_API::getInstance()->updateGoal($idSite, $idGoal_OneConversionPerVisit, $goal['name'], @$goal['match_attribute'], @$goal['pattern'], @$goal['pattern_type'], @$goal['case_sensitive'], $goal['revenue'], $goal['allow_multiple'] = 1);
$this->assertTrue($goal['allow_multiple'] == 1);
// 1st goal should Now be tracked
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.61)->getDatetime());
$this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656));
}
示例12: trackVisits
protected static function trackVisits()
{
$dateTimes = self::$dateTimes;
$idSite = self::$idSite;
$i = 0;
$ridx = 0;
foreach ($dateTimes as $dateTime) {
$i++;
$visitor = self::getTracker($idSite, $dateTime, $defaultInit = true);
// Fake the visit count cookie
$visitor->setDebugStringAppend("&_idvc={$i}");
$visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
$visitor->setUrl('http://example.org/homepage');
$visitor->setUrlReferrer(self::$referrerUrls[$ridx++]);
self::checkResponse($visitor->doTrackPageView('ou pas'));
// Test change the IP, the visit should not be split but recorded to the same idvisitor
$visitor->setIp('200.1.15.22');
$visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
$visitor->setUrl('http://example.org/news');
self::checkResponse($visitor->doTrackPageView('ou pas'));
$visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
$visitor->setUrl('http://example.org/news');
$visitor->setUrlReferrer(self::$referrerUrls[$ridx++]);
self::checkResponse($visitor->doTrackPageView('ou pas'));
}
}
示例13: setUp
public function setUp()
{
// add one site
$this->idSite = $this->createWebsite($this->dateTime, 1, "Site #0");
// add two goals
$goals = Piwik_Goals_API::getInstance();
$this->idGoal1 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
$this->idGoal2 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
$urls = array();
for ($i = 0; $i != 10; ++$i) {
$url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1);
$title = "page view " . ($i - 1) . " / " . ($i + 1);
$urls[$url] = $title;
}
$visitTimes = array();
$date = Piwik_Date::factory($this->dateTime);
for ($i = 0; $i != 12; ++$i) {
$visitTimes[] = $date->addHour($i)->toString();
}
// add 10,000 page views (10 visits of 10 page views for 100 visitors)
for ($visitor = 0; $visitor != 100; ++$visitor) {
$t = $this->getTracker($this->idSite, $this->dateTime, $defaultInit = true);
foreach ($visitTimes as $visitTime) {
$t->setForceVisitDateTime($visitTime);
foreach ($urls as $url => $title) {
$t->setUrl($url);
$t->doTrackPageView($title);
}
}
}
}
示例14: trackVisits
protected function trackVisits()
{
$idSite = $this->idSite;
$dateTime = $this->dateTime;
$t = $this->getTracker($idSite, $dateTime, $defaultInit = true);
// Record 1st page view
$t->setUrl('http://example.org/index.htm');
$this->checkResponse($t->doTrackPageView('incredible title!'));
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
$this->checkResponse($t->doTrackGoal($this->idGoal3, $revenue = 42.256));
}
示例15: getSitesInfo
public function getSitesInfo()
{
$view = new Piwik_View("MultiSites/templates/index.tpl");
$mySites = Piwik_SitesManager_API::getInstance()->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::getInstance()->getVisits($ids, $this->period, $this->date);
$lastVisits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $lastDate);
$actions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $this->date);
$lastActions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $lastDate);
$uniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $this->date);
$lastUniqueUsers = Piwik_VisitsSummary_API::getInstance()->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->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);
$minTimestamp = Zend_Registry::get('access')->getSitesMinDate();
if (!empty($minTimestamp)) {
$minDate = Piwik_Date::factory($minTimestamp);
$this->setMinDateView($minDate, $view);
}
echo $view->render();
}