本文整理汇总了PHP中Piwik_Date::now方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Date::now方法的具体用法?PHP Piwik_Date::now怎么用?PHP Piwik_Date::now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Date
的用法示例。
在下文中一共展示了Piwik_Date::now方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$view = Piwik_View::factory('SitesManager');
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
foreach ($sites as $site) {
$sitesIndexedById[$site['idsite']] = $site;
}
Piwik_Site::setSites($sitesIndexedById);
foreach ($sites as &$site) {
$site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']);
$site['excluded_ips'] = str_replace(',', '<br/>', $site['excluded_ips']);
$site['excluded_parameters'] = str_replace(',', '<br/>', $site['excluded_parameters']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList();
$view->timezoneSupported = Piwik::isTimezoneSupportEnabled();
$view->timezones = json_encode($timezones);
$view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
$view->currencies = json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList());
$view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency();
$view->utcTime = Piwik_Date::now()->getDatetime();
$excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal();
$view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
$excludedQueryParametersGlobal = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal();
$view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
$view->currentIpAddress = Piwik_Common::getIpString();
$this->setBasicVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
echo $view->render();
}
示例2: index
function index()
{
$view = Piwik_View::factory('SitesManager');
if (Piwik::isUserIsSuperUser()) {
$sites = Piwik_SitesManager_API::getInstance()->getAllSites();
Piwik_Site::setSites($sites);
$sites = array_values($sites);
} else {
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
Piwik_Site::setSitesFromArray($sites);
}
foreach ($sites as &$site) {
$site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']);
$site['excluded_ips'] = str_replace(',', '<br/>', $site['excluded_ips']);
$site['excluded_parameters'] = str_replace(',', '<br/>', $site['excluded_parameters']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList();
$view->timezoneSupported = Piwik::isTimezoneSupportEnabled();
$view->timezones = Piwik_Common::json_encode($timezones);
$view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
$view->currencies = Piwik_Common::json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList());
$view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency();
$view->utcTime = Piwik_Date::now()->getDatetime();
$excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal();
$view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
$excludedQueryParametersGlobal = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal();
$view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
$view->currentIpAddress = Piwik_IP::getIpFromHeader();
$view->showAddSite = (bool) Piwik_Common::getRequestVar('showaddsite', false);
$this->setBasicVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
echo $view->render();
}
示例3: testFactoryTimezone
/**
* @group Core
* @group Date
*/
public function testFactoryTimezone()
{
// now in UTC converted to UTC+10 means adding 10 hours
$date = Piwik_Date::factory('now', 'UTC+10');
$dateExpected = Piwik_Date::now()->addHour(10);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
// Congo is in UTC+1 all year long (no DST)
$date = Piwik_Date::factory('now', 'Africa/Brazzaville');
$dateExpected = Piwik_Date::factory('now')->addHour(1);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
// yesterday same time in Congo is the same as today in Congo - 24 hours
$date = Piwik_Date::factory('yesterdaySameTime', 'Africa/Brazzaville');
$dateExpected = Piwik_Date::factory('now', 'Africa/Brazzaville')->subHour(24);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
if (Piwik::isTimezoneSupportEnabled()) {
// convert to/from local time
$now = time();
$date = Piwik_Date::factory($now, 'America/New_York');
$time = $date->getTimestamp();
$this->assertTrue($time < $now);
$date = Piwik_Date::factory($time)->setTimezone('America/New_York');
$time = $date->getTimestamp();
$this->assertEquals($now, $time);
}
}
示例4: cacheDataByArchiveNameReports
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = Piwik_DBStats_API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Piwik_Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
Piwik_SetOption(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
示例5: testRangeTodayUtcPlus12
/**
* @group Core
* @group Period
* @group Period_Range
*/
public function testRangeTodayUtcPlus12()
{
// rather ugly test, UTC+23 doesn't exist, but it's a way to test that last1 in UTC+23 will be "our" UTC tomorrow
$range = new Piwik_Period_Range('day', 'last1', 'UTC+23');
$today = Piwik_Date::now()->addHour(23);
$correct = array($today->toString());
$correct = array_reverse($correct);
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
示例6: sendReport
public function sendReport($idReport, $period = false, $date = false)
{
Piwik::checkUserIsNotAnonymous();
$reports = $this->getReports($idSite = false, false, $idReport);
$report = reset($reports);
if ($report['period'] == 'never') {
$report['period'] = 'day';
}
if (!empty($period)) {
$report['period'] = $period;
}
if (empty($date)) {
$date = Piwik_Date::now()->subPeriod(1, $report['period'])->toString();
}
$language = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($report['login']);
// generate report
list($outputFilename, $prettyDate, $websiteName, $additionalFiles) = $this->generateReport($idReport, $date, $language, self::OUTPUT_SAVE_ON_DISK, $report['period']);
if (!file_exists($outputFilename)) {
throw new Exception("The report file wasn't found in {$outputFilename}");
}
$filename = basename($outputFilename);
$handle = fopen($outputFilename, "r");
$contents = fread($handle, filesize($outputFilename));
fclose($handle);
$notificationObject = null;
Piwik_PostEvent(self::SEND_REPORT_EVENT, $notificationObject, $notificationInfo = array(self::REPORT_TYPE_INFO_KEY => $report['type'], self::REPORT_KEY => $report, self::REPORT_CONTENT_KEY => $contents, self::FILENAME_KEY => $filename, self::PRETTY_DATE_KEY => $prettyDate, self::WEBSITE_NAME_KEY => $websiteName, self::ADDITIONAL_FILES_KEY => $additionalFiles));
// Update flag in DB
Zend_Registry::get('db')->update(Piwik_Common::prefixTable('report'), array('ts_last_sent' => Piwik_Date::now()->getDatetime()), "idreport = " . $report['idreport']);
// If running from piwik.php with debug, do not delete the PDF after sending the email
if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
@chmod($outputFilename, 0600);
}
}
示例7: addUser
/**
* Add a user in the database.
* A user is defined by
* - a login that has to be unique and valid
* - a password that has to be valid
* - an alias
* - an email that has to be in a correct format
*
* @see userExists()
* @see isValidLoginString()
* @see isValidPasswordString()
* @see isValidEmailString()
*
* @exception in case of an invalid parameter
*/
public function addUser($userLogin, $password, $email, $alias = false)
{
Piwik::checkUserIsSuperUser();
$this->checkLogin($userLogin);
$this->checkUserIsNotSuperUser($userLogin);
$this->checkEmail($email);
$password = Piwik_Common::unsanitizeInputValue($password);
$this->checkPassword($password);
$alias = $this->getCleanAlias($alias, $userLogin);
$passwordTransformed = $this->getCleanPassword($password);
$token_auth = $this->getTokenAuth($userLogin, $passwordTransformed);
$db = Zend_Registry::get('db');
$db->insert(Piwik_Common::prefixTable("user"), array('login' => $userLogin, 'password' => $passwordTransformed, 'alias' => $alias, 'email' => $email, 'token_auth' => $token_auth, 'date_registered' => Piwik_Date::now()->getDatetime()));
// we reload the access list which doesn't yet take in consideration this new user
Zend_Registry::get('access')->reloadAccess();
Piwik_Common::deleteTrackerCache();
Piwik_PostEvent('UsersManager.addUser', $userLogin);
}
示例8: sendReportEmail
protected function sendReportEmail($emails, $outputFilename, $prettyDate, $websiteName, $report, $reportFormat, $additionalFiles)
{
$periods = self::getPeriodToFrequency();
$message = Piwik_Translate('PDFReports_EmailHello');
$subject = Piwik_Translate('General_Report') . ' ' . $websiteName . " - " . $prettyDate;
if (!file_exists($outputFilename)) {
throw new Exception("The report file wasn't found in {$outputFilename}");
}
$filename = basename($outputFilename);
$handle = fopen($outputFilename, "r");
$contents = fread($handle, filesize($outputFilename));
fclose($handle);
$mail = new Piwik_Mail();
$mail->setSubject($subject);
$fromEmailName = Piwik_Config::getInstance()->branding['use_custom_logo'] ? Piwik_Translate('CoreHome_WebAnalyticsReports') : Piwik_Translate('PDFReports_PiwikReports');
$fromEmailAddress = Piwik_Config::getInstance()->General['noreply_email_address'];
$attachmentName = $subject;
$mail->setFrom($fromEmailAddress, $fromEmailName);
switch ($reportFormat) {
case 'html':
// Needed when using images as attachment with cid
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$message .= "<br/>" . Piwik_Translate('PDFReports_PleaseFindBelow', array($periods[$report['period']], $websiteName));
$mail->setBodyHtml($message . "<br/><br/>" . $contents);
break;
default:
case 'pdf':
$message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $websiteName));
$mail->setBodyText($message);
$mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf');
break;
}
foreach ($additionalFiles as $additionalFile) {
$fileContent = $additionalFile['content'];
$at = $mail->createAttachment($fileContent, $additionalFile['mimeType'], Zend_Mime::DISPOSITION_INLINE, $additionalFile['encoding'], $additionalFile['filename']);
$at->id = $additionalFile['cid'];
unset($fileContent);
}
foreach ($emails as $email) {
$mail->addTo($email);
try {
$mail->send();
} catch (Exception $e) {
// If running from piwik.php with debug, we ignore the 'email not sent' error
if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
throw new Exception("An error occured while sending '{$filename}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'");
}
}
$mail->clearRecipients();
}
// Update flag in DB
Zend_Registry::get('db')->update(Piwik_Common::prefixTable('pdf'), array('ts_last_sent' => Piwik_Date::now()->getDatetime()), "idreport = " . $report['idreport']);
// If running from piwik.php with debug, do not delete the PDF after sending the email
if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
@chmod($outputFilename, 0600);
@unlink($outputFilename);
}
}
示例9: getMinMaxDateAcrossWebsites
/**
* The Multisites reports displays the first calendar date as the earliest day available for all websites.
* Also, today is the later "today" available across all timezones.
* @param array $siteIds Array of IDs for each site being displayed.
* @return array of two Piwik_Date instances. First is the min-date & the second
* is the max date.
*/
private function getMinMaxDateAcrossWebsites($siteIds)
{
$now = Piwik_Date::now();
$minDate = null;
$maxDate = $now->subDay(1)->getTimestamp();
foreach ($siteIds as $idsite) {
// look for 'now' in the website's timezone
$timezone = Piwik_Site::getTimezoneFor($idsite);
$date = Piwik_Date::adjustForTimezone($now->getTimestamp(), $timezone);
if ($date > $maxDate) {
$maxDate = $date;
}
// look for the absolute minimum date
$creationDate = Piwik_Site::getCreationDateFor($idsite);
$date = Piwik_Date::adjustForTimezone(strtotime($creationDate), $timezone);
if (is_null($minDate) || $date < $minDate) {
$minDate = $date;
}
}
return array(Piwik_Date::factory($minDate), Piwik_Date::factory($maxDate));
}
示例10: sendReportEmailPdfAttached
protected function sendReportEmailPdfAttached($emails, $outputFilename, $prettyDate, $websiteName, $report)
{
$periods = self::getPeriodToFrequency();
$message = Piwik_Translate('PDFReports_EmailHello');
$message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $websiteName));
$subject = Piwik_Translate('General_Report') . ' ' . $websiteName . " - " . $prettyDate;
if (!file_exists($outputFilename)) {
throw new Exception("The PDF file wasn't found in {$outputFilename}");
}
$filename = basename($outputFilename);
$handle = fopen($outputFilename, "r");
$contents = fread($handle, filesize($outputFilename));
fclose($handle);
$mail = new Piwik_Mail();
$mail->setSubject($subject);
$mail->setBodyText($message);
$fromEmailName = Piwik_Translate('PDFReports_PiwikReports');
$fromEmailAddress = Zend_Registry::get('config')->General->noreply_email_address;
$attachmentName = $subject;
$mail->setFrom($fromEmailAddress, $fromEmailName);
$mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf');
foreach ($emails as $email) {
$mail->addTo($email);
try {
$mail->send();
} catch (Exception $e) {
// If running from piwik.php with debug, we ignore the 'email not sent' error
if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
throw new Exception("An error occured while sending '{$filename}' " . " to " . implode(', ', $mail->getRecipients()) . ". \n \t\t\t\t\t\t\t\tError was '" . $e->getMessage() . "'");
}
}
$mail->clearRecipients();
}
// Update flag in DB
Zend_Registry::get('db')->update(Piwik_Common::prefixTable('pdf'), array('ts_last_sent' => Piwik_Date::now()->getDatetime()), "idreport = " . $report['idreport']);
// If running from piwik.php with debug, do not delete the PDF after sending the email
if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
unlink($outputFilename);
}
}
示例11: addSite
/**
* Add a website.
* Requires Super User access.
*
* The website is defined by a name and an array of URLs.
* @param string Site name
* @param array|string The URLs array must contain at least one URL called the 'main_url' ;
* if several URLs are provided in the array, they will be recorded
* as Alias URLs for this website.
* @param int Is Ecommerce Reporting enabled for this website?
* @param string Comma separated list of IPs to exclude from the reports (allows wildcards)
* @param string Timezone string, eg. 'Europe/London'
* @param string Currency, eg. 'EUR'
* @param string Website group identifier
* @param string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
*
*
* @return int the website ID created
*/
public function addSite( $siteName, $urls, $ecommerce = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null )
{
Piwik::checkUserIsSuperUser();
$this->checkName($siteName);
$urls = $this->cleanParameterUrls($urls);
$this->checkUrls($urls);
$this->checkAtLeastOneUrl($urls);
$timezone = trim($timezone);
if(empty($timezone))
{
$timezone = $this->getDefaultTimezone();
}
$this->checkValidTimezone($timezone);
if(empty($currency))
{
$currency = $this->getDefaultCurrency();
}
$this->checkValidCurrency($currency);
$db = Zend_Registry::get('db');
$url = $urls[0];
$urls = array_slice($urls, 1);
$bind = array( 'name' => $siteName,
'main_url' => $url,
);
$bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps);
$bind['excluded_parameters'] = $this->checkAndReturnExcludedQueryParameters($excludedQueryParameters);
$bind['timezone'] = $timezone;
$bind['currency'] = $currency;
$bind['ecommerce'] = (int)$ecommerce;
$bind['ts_created'] = !is_null($startDate)
? Piwik_Date::factory($startDate)->getDatetime()
: Piwik_Date::now()->getDatetime();
if(!empty($group)
&& Piwik::isUserIsSuperUser())
{
$bind['group'] = trim($group);
}
else
{
$bind['group'] = "";
}
$db->insert(Piwik_Common::prefixTable("site"), $bind);
$idSite = $db->lastInsertId();
$this->insertSiteUrls($idSite, $urls);
// we reload the access list which doesn't yet take in consideration this new website
Zend_Registry::get('access')->reloadAccess();
$this->postUpdateWebsite($idSite);
return (int)$idSite;
}
示例12: setMinMaxDateAcrossWebsites
/**
* The Multisites reports displays the first calendar date as the earliest day available for all websites.
* Also, today is the later "today" available across all timezones.
* @param array $mySites
* @param Piwik_View $view
* @return void
*/
private function setMinMaxDateAcrossWebsites($mySites, $view)
{
$minDate = null;
$maxDate = Piwik_Date::now()->subDay(1);
foreach ($mySites as &$site) {
// look for 'now' in the website's timezone
$timezone = $site['timezone'];
$date = Piwik_Date::factory('now', $timezone);
if ($date->isLater($maxDate)) {
$maxDate = clone $date;
}
// look for the absolute minimum date
$creationDate = $site['ts_created'];
$date = Piwik_Date::factory($creationDate, $timezone);
if (is_null($minDate) || $date->isEarlier($minDate)) {
$minDate = clone $date;
}
}
$this->setMinDateView($minDate, $view);
$this->setMaxDateView($maxDate, $view);
}