本文整理汇总了PHP中Piwik\Date::now方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::now方法的具体用法?PHP Date::now怎么用?PHP Date::now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Date
的用法示例。
在下文中一共展示了Date::now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFactoryTimezone
/**
* @group Core
*/
public function testFactoryTimezone()
{
// now in UTC converted to UTC+10 means adding 10 hours
$date = Date::factory('now', 'UTC+10');
$dateExpected = Date::now()->addHour(10);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
// Congo is in UTC+1 all year long (no DST)
$dateExpected = Date::factory('now')->addHour(1);
$date = Date::factory('now', 'Africa/Brazzaville');
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
// yesterday same time in Congo is the same as today in Congo - 24 hours
$date = Date::factory('yesterdaySameTime', 'Africa/Brazzaville');
$dateExpected = Date::factory('now', 'Africa/Brazzaville')->subHour(24);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
if (SettingsServer::isTimezoneSupportEnabled()) {
// convert to/from local time
$now = time();
$date = Date::factory($now, 'America/New_York');
$time = $date->getTimestamp();
$this->assertTrue($time < $now);
$date = Date::factory($time)->setTimezone('America/New_York');
$time = $date->getTimestamp();
$this->assertEquals($now, $time);
}
}
示例2: migrateConfigSuperUserToDb
private static function migrateConfigSuperUserToDb()
{
$config = Config::getInstance();
if (!$config->existsLocalConfig()) {
return;
}
try {
$superUser = $config->superuser;
} catch (\Exception $e) {
$superUser = null;
}
if (!empty($superUser['bridge']) || empty($superUser) || empty($superUser['login'])) {
// there is a super user which is not from the config but from the bridge, that means we already have
// a super user in the database
return;
}
$userApi = UsersManagerApi::getInstance();
try {
Db::get()->insert(Common::prefixTable('user'), array('login' => $superUser['login'], 'password' => $superUser['password'], 'alias' => $superUser['login'], 'email' => $superUser['email'], 'token_auth' => $userApi->getTokenAuth($superUser['login'], $superUser['password']), 'date_registered' => Date::now()->getDatetime(), 'superuser_access' => 1));
} catch (\Exception $e) {
echo "There was an issue, but we proceed: " . $e->getMessage();
}
if (array_key_exists('salt', $superUser)) {
$salt = $superUser['salt'];
} else {
$salt = Common::generateUniqId();
}
$config->General['salt'] = $salt;
$config->superuser = array();
$config->forceSave();
}
示例3: index
public function index()
{
Piwik::checkUserHasSuperUserAccess();
$view = new View('@TasksTimetable/index.twig');
$this->setGeneralVariablesView($view);
$tasks = Option::get('TaskScheduler.timetable');
if (!empty($tasks)) {
$tasks = unserialize($tasks);
}
if (empty($tasks)) {
$tasks = array();
} else {
asort($tasks);
}
$tsNow = Date::now()->getTimestamp();
$dateFormat = Piwik::translate(Date::DATE_FORMAT_LONG) . ' h:mm:ss';
$formatter = new Formatter();
$tasksFormatted = array();
foreach ($tasks as $name => $timestamp) {
$tasksFormatted[] = array('name' => $name, 'executionDate' => Date::factory($timestamp)->getLocalized($dateFormat), 'ts_difference' => $formatter->getPrettyTimeFromSeconds($timestamp - $tsNow));
}
$view->currentTime = Date::now()->getLocalized($dateFormat);
$view->tasks = $tasksFormatted;
return $view->render();
}
示例4: test_deleteAlertsForWebsite
public function test_deleteAlertsForWebsite()
{
$this->createAlert('Initial1', array(), array(2));
$this->createAlert('Initial2', array(), array(1, 2, 3));
$this->createAlert('Initial3', array(), array(1));
$this->createAlert('Initial4', array(), array(1, 3));
$this->createAlert('Initial5', array(), array(2));
$this->createAlert('Initial6', array(), array(2));
$this->model->triggerAlert(1, 1, 99, 48, Date::now()->getDatetime());
$this->model->triggerAlert(1, 2, 99, 48, Date::now()->getDatetime());
$this->model->triggerAlert(2, 3, 99, 48, Date::now()->getDatetime());
$this->model->triggerAlert(3, 2, 99, 48, Date::now()->getDatetime());
$alerts = $this->model->getTriggeredAlerts(array(1, 2, 3), 'superUserLogin');
$this->assertCount(4, $alerts);
$this->plugin->deleteAlertsForSite(2);
$alerts = $this->model->getAllAlerts();
$this->assertCount(6, $alerts);
$this->assertEquals($alerts[0]['id_sites'], array());
$this->assertEquals($alerts[1]['id_sites'], array(1, 3));
$this->assertEquals($alerts[2]['id_sites'], array(1));
$this->assertEquals($alerts[3]['id_sites'], array(1, 3));
$this->assertEquals($alerts[4]['id_sites'], array());
$this->assertEquals($alerts[5]['id_sites'], array());
$alerts = $this->model->getTriggeredAlerts(array(1, 2, 3), 'superUserLogin');
$this->assertCount(2, $alerts);
}
示例5: cacheDataByArchiveNameReports
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
示例6: cacheDataByArchiveNameReports
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Date::now()->getLocalized(Date::DATE_FORMAT_SHORT);
Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
示例7: testRangeTodayUtcPlus12
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 Range('day', 'last1', 'UTC+23');
$today = Date::now()->addHour(23);
$correct = array($today->toString());
$correct = array_reverse($correct);
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
示例8: assertDeprecatedClassIsRemoved
private function assertDeprecatedClassIsRemoved($className, $removalDate)
{
$now = Date::now();
$removalDate = Date::factory($removalDate);
$classExists = class_exists($className);
if (!$now->isLater($removalDate)) {
$errorMessage = $className . ' should still exists until ' . $removalDate . ' although it is deprecated.';
$this->assertTrue($classExists, $errorMessage);
return;
}
$errorMessage = $className . ' should be removed as the method is deprecated but it is not.';
$this->assertFalse($classExists, $errorMessage);
}
示例9: assertDeprecatedMethodIsRemoved
private function assertDeprecatedMethodIsRemoved($className, $method, $removalDate)
{
$now = \Piwik\Date::now();
$removalDate = \Piwik\Date::factory($removalDate);
$class = new ReflectionClass($className);
$methodExists = $class->hasMethod($method);
if (!$now->isLater($removalDate)) {
$errorMessage = $className . '::' . $method . ' should still exists until ' . $removalDate . ' although it is deprecated.';
$this->assertTrue($methodExists, $errorMessage);
return;
}
$errorMessage = $className . '::' . $method . ' should be removed as the method is deprecated but it is not.';
$this->assertFalse($methodExists, $errorMessage);
}
示例10: getMostUsedActionDimensionValues
/**
* @param array $dimension
* @param int $idSite
* @param int $maxValuesToReturn
* @return array
*/
public function getMostUsedActionDimensionValues($dimension, $idSite, $maxValuesToReturn)
{
$maxValuesToReturn = (int) $maxValuesToReturn;
$idSite = (int) $idSite;
$startDate = Date::now()->subDay(60)->toString();
$name = LogTable::buildCustomDimensionColumnName($dimension);
$table = Common::prefixTable('log_link_visit_action');
$query = "SELECT {$name}, count({$name}) as countName FROM {$table}\n WHERE idsite = ? and server_time > {$startDate} and {$name} is not null\n GROUP by {$name}\n ORDER BY countName DESC LIMIT {$maxValuesToReturn}";
$rows = Db::get()->fetchAll($query, array($idSite));
$values = array();
foreach ($rows as $row) {
$values[] = $row[$name];
}
return $values;
}
示例11: index
/**
* Main view showing listing of websites and settings
*/
public function index()
{
$view = new View('@SitesManager/index');
Site::clearCache();
if (Piwik::isUserIsSuperUser()) {
$sitesRaw = API::getInstance()->getAllSites();
} else {
$sitesRaw = API::getInstance()->getSitesWithAdminAccess();
}
// Gets sites after Site.setSite hook was called
$sites = array_values(Site::getSites());
if (count($sites) != count($sitesRaw)) {
throw new Exception("One or more website are missing or invalid.");
}
foreach ($sites as &$site) {
$site['alias_urls'] = API::getInstance()->getSiteUrlsFromId($site['idsite']);
$site['excluded_ips'] = explode(',', $site['excluded_ips']);
$site['excluded_parameters'] = explode(',', $site['excluded_parameters']);
$site['excluded_user_agents'] = explode(',', $site['excluded_user_agents']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$timezones = API::getInstance()->getTimezonesList();
$view->timezoneSupported = SettingsServer::isTimezoneSupportEnabled();
$view->timezones = Common::json_encode($timezones);
$view->defaultTimezone = API::getInstance()->getDefaultTimezone();
$view->currencies = Common::json_encode(API::getInstance()->getCurrencyList());
$view->defaultCurrency = API::getInstance()->getDefaultCurrency();
$view->utcTime = Date::now()->getDatetime();
$excludedIpsGlobal = API::getInstance()->getExcludedIpsGlobal();
$view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
$excludedQueryParametersGlobal = API::getInstance()->getExcludedQueryParametersGlobal();
$view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
$globalExcludedUserAgents = API::getInstance()->getExcludedUserAgentsGlobal();
$view->globalExcludedUserAgents = str_replace(',', "\n", $globalExcludedUserAgents);
$view->globalSearchKeywordParameters = API::getInstance()->getSearchKeywordParametersGlobal();
$view->globalSearchCategoryParameters = API::getInstance()->getSearchCategoryParametersGlobal();
$view->isSearchCategoryTrackingEnabled = \Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables');
$view->allowSiteSpecificUserAgentExclude = API::getInstance()->isSiteSpecificUserAgentExcludeEnabled();
$view->globalKeepURLFragments = API::getInstance()->getKeepURLFragmentsGlobal();
$view->currentIpAddress = IP::getIpFromHeader();
$view->showAddSite = (bool) Common::getRequestVar('showaddsite', false);
$this->setBasicVariablesView($view);
return $view->render();
}
示例12: getUser
/**
* Returns the user on hand the settings done
* in the config.ini.php.
*/
public function getUser()
{
$auth = new Auth();
$login = $auth->getLogin();
$alias = $auth->getAlias();
$websites = $auth->getWebsites();
$email = $auth->getEmail();
$token = $auth->getToken();
$superuser = $auth->getSuperuser();
if (!$this->userExists($login)) {
$this->addUser($login, md5($auth->getPassword()), $email, $alias, $token, Date::now()->getDatetime(), 0);
foreach ($websites as $w) {
$this->addUserAccess($login, $w['access'], $w['ids']);
}
if ($superuser) {
$this->setSuperUserAccess($login, $superuser);
}
} else {
if ($superuser) {
$this->setSuperUserAccess($login, $superuser);
}
if ($this->getSitesAccessFromUser($login) != 0) {
$localSiteIds = array();
foreach ($this->getSitesAccessFromUser($login) as $siteAccess) {
if (!in_array($siteAccess['site'], $websites[0]['ids']) || !in_array($siteAccess['site'], $websites[1]['ids'])) {
$this->deleteUserAccess($login, $siteAccess['site']);
} else {
array_push($localSiteIds, $siteAccess['site']);
}
}
foreach ($websites[0]['ids'] as $si) {
if (!in_array($si, $localSiteIds)) {
$this->addUserAccess($login, $websites[0]['access'], $si);
}
}
foreach ($websites[1]['ids'] as $si) {
if (!in_array($si, $localSiteIds)) {
$this->addUserAccess($login, $websites[1]['access'], $si);
}
}
}
}
return array('login' => $login, 'alias' => $alias, 'email' => $email, 'token_auth' => $token, 'superuser_access' => $superuser);
}
示例13: authenticate
/**
* Authenticates user
*
* @return AuthResult
*/
public function authenticate()
{
$logger = StaticContainer::get('Psr\\Log\\LoggerInterface');
$model = new Model();
$user = $model->getUser($this->login);
if (!$user) {
$user = $model->getUserByTokenAuth($this->token_auth);
if (!$user) {
$logger->info("Creating user " . $this->login);
$model->addUser($this->login, $this->getTokenAuthSecret(), $this->email, $this->alias, $this->token_auth, Date::now()->getDatetime());
$user = $model->getUser($this->login);
}
}
$accessCode = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS;
$this->login = $user['login'];
if ($this->getViewableUserStatus() || $this->getSuperUserStatus()) {
$site_ids = $this->getDefaultSiteIds();
$current_accesses = array();
foreach ($site_ids as $site_id) {
$accesses = $model->getUsersAccessFromSite($site_id);
foreach ($accesses as $user => $access) {
if ($this->login == $user && ($access == "view" || $access == 'admin')) {
$current_accesses[] = $site_id;
}
}
}
$new_accesses = array();
foreach ($site_ids as $site_id) {
if (!in_array($site_id, $current_accesses)) {
$new_accesses[] = $site_id;
}
}
if (count($new_accesses) > 0) {
$logger->info("Adding default site ids to " . $this->login);
$model->addUserAccess($this->login, "view", $new_accesses);
}
}
$is_superuser = $this->getSuperUserStatus();
$model->setSuperUserAccess($this->login, $is_superuser);
return new AuthResult($accessCode, $this->login, $this->token_auth);
}
示例14: trackApiCall
public function trackApiCall(&$return, $endHookParams)
{
$endTime = microtime(true);
$name = $endHookParams['module'];
$method = $name . '.' . $endHookParams['action'];
$neededTimeInMs = 0;
do {
$call = array_pop($this->profilingStack);
// we need to make sure the call was actually for this method to not send wrong data.
if ($method === $call['method']) {
$neededTimeInMs = ceil(($endTime - $call['time']) * 1000);
break;
}
} while (!empty($this->profilingStack));
if (empty($neededTimeInMs)) {
return;
}
$profiles = StaticContainer::get('Piwik\\Plugins\\AnonymousPiwikUsageMeasurement\\Tracker\\Profiles');
$now = Date::now()->getDatetime();
$category = 'API';
$profiles->pushProfile($now, $category, $name, $method, $count = 1, (int) $neededTimeInMs);
}
开发者ID:piwik,项目名称:plugin-AnonymousPiwikUsageMeasurement,代码行数:22,代码来源:AnonymousPiwikUsageMeasurement.php
示例15: createUser
/**
* Create a user upon call from frontend
* This API method will be called from Controller of this module
*
* @param String $userLogin
* @param String $userPassword
* @param String $userEmail
* @return Boolean
*/
public function createUser($userLogin, $userPassword, $userEmail)
{
if ($userLogin and $userPassword) {
$userManager = UserManagerAPI::getInstance();
if (!$this->userManagerModel->userEmailExists($userEmail) and !$this->userManagerModel->userExists($userLogin)) {
$password = Common::unsanitizeInputValue($userPassword);
UserManager::checkPassword($password);
$passwordTransformed = UserManager::getPasswordHash($password);
$token_auth = $userManager->getTokenAuth($userEmail, $passwordTransformed);
try {
$this->userManagerModel->addUser($userEmail, $passwordTransformed, $userEmail, $userLogin, $token_auth, Date::now()->getDatetime());
return true;
} catch (Exception $e) {
//throw new Exception($e->getMessage());
$this->__errors[] = 'Error in creating the user in database.';
}
} else {
$this->__errors[] = 'User email already exists or the login name already exists';
}
}
return false;
}