本文整理汇总了PHP中CRM_Utils_Time::getTimeRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Time::getTimeRaw方法的具体用法?PHP CRM_Utils_Time::getTimeRaw怎么用?PHP CRM_Utils_Time::getTimeRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Time
的用法示例。
在下文中一共展示了CRM_Utils_Time::getTimeRaw方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_crmSigner
/**
* Generate a secure signature
*
* {code}
* {crmSigner var=mySig extra=123}
* var urlParams = ts={$mySig.ts}&extra={$mySig.extra}&sig={$mySig.signature}
* {endcode}
*
* @param $params array with keys:
* - var: string, a smarty variable to generate
* - ts: int, the current time (if omitted, autogenerated)
* - any other vars are put into the signature (sorted)
*/
function smarty_function_crmSigner($params, &$smarty)
{
$var = $params['var'];
unset($params['var']);
$params['ts'] = CRM_Utils_Time::getTimeRaw();
$fields = array_keys($params);
sort($fields);
$signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), $fields);
$params['signature'] = $signer->sign($params);
$smarty->assign($var, $params);
}
示例2: parseExpiration
/**
* Parse the expiration time from a series of HTTP headers.
*
* @param array $headers
* @return int|NULL
* Expiration tme as seconds since epoch, or NULL if not cacheable.
*/
public static function parseExpiration($headers)
{
$headers = CRM_Utils_Array::rekey($headers, function ($k, $v) {
return strtolower($k);
});
if (!empty($headers['cache-control'])) {
$cc = self::parseCacheControl($headers['cache-control']);
if ($cc['max-age'] && is_numeric($cc['max-age'])) {
return CRM_Utils_Time::getTimeRaw() + $cc['max-age'];
}
}
return NULL;
}
示例3: stealItem
/**
* Get the next item, even if there's an active lease
*
* @param $lease_time seconds
*
* @return object with key 'data' that matches the inputted data
*/
function stealItem($lease_time = 3600)
{
$sql = "\n SELECT id, queue_name, submit_time, release_time, data\n FROM civicrm_queue_item\n WHERE queue_name = %1\n ORDER BY weight ASC, release_time ASC, id ASC\n LIMIT 1\n ";
$params = array(1 => array($this->getName(), 'String'));
$dao = CRM_Core_DAO::executeQuery($sql, $params, TRUE, 'CRM_Queue_DAO_QueueItem');
if ($dao->fetch()) {
$nowEpoch = CRM_Utils_Time::getTimeRaw();
CRM_Core_DAO::executeQuery("UPDATE civicrm_queue_item SET release_time = %1 WHERE id = %2", array('1' => array(date('YmdHis', $nowEpoch + $lease_time), 'String'), '2' => array($dao->id, 'Integer')));
$dao->data = unserialize($dao->data);
return $dao;
} else {
CRM_Core_Error::debug_var('no items found');
return FALSE;
}
}
示例4: download
/**
* @param string $file
* Local file path.
* @param string $mimeType
* @param int $ttl
* Time to live (seconds).
*/
protected function download($file, $mimeType, $ttl)
{
if (!file_exists($file)) {
header("HTTP/1.0 404 Not Found");
return;
} elseif (!is_readable($file)) {
header('HTTP/1.0 403 Forbidden');
return;
}
CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', CRM_Utils_Time::getTimeRaw() + $ttl));
CRM_Utils_System::setHttpHeader("Content-Type", $mimeType);
CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename=\"" . basename($file) . "\"");
CRM_Utils_System::setHttpHeader("Cache-Control", "max-age={$ttl}, public");
CRM_Utils_System::setHttpHeader('Pragma', 'public');
readfile($file);
}
示例5: send
/**
* @param string $verb
* @param string $url
* @param string $blob
* @param array $headers
* Array of headers (e.g. "Content-type" => "text/plain").
* @return array
* array($headers, $blob, $code)
*/
public function send($verb, $url, $blob, $headers = array())
{
$lowVerb = strtolower($verb);
if ($lowVerb === 'get' && $this->cache) {
$cachePath = 'get/' . md5($url);
$cacheLine = $this->cache->get($cachePath);
if ($cacheLine && $cacheLine['expires'] > CRM_Utils_Time::getTimeRaw()) {
return $cacheLine['data'];
}
}
$result = parent::send($verb, $url, $blob, $headers);
if ($lowVerb === 'get' && $this->cache) {
$expires = CRM_Utils_Http::parseExpiration($result[0]);
if ($expires !== NULL) {
$cachePath = 'get/' . md5($url);
$cacheLine = array('url' => $url, 'expires' => $expires, 'data' => $result);
$this->cache->set($cachePath, $cacheLine);
}
}
return $result;
}
示例6: checkUserName
/**
* check the CMS username.
*/
public static function checkUserName()
{
$signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('for', 'ts'));
$sig = CRM_Utils_Request::retrieve('sig', 'String', CRM_Core_DAO::$_nullObject);
$for = CRM_Utils_Request::retrieve('for', 'String', CRM_Core_DAO::$_nullObject);
if (CRM_Utils_Time::getTimeRaw() > $_REQUEST['ts'] + self::CHECK_USERNAME_TTL || $for != 'civicrm/ajax/cmsuser' || !$signer->validate($sig, $_REQUEST)) {
$user = array('name' => 'error');
CRM_Utils_JSON::output($user);
}
$config = CRM_Core_Config::singleton();
$username = trim(CRM_Utils_Array::value('cms_name', $_REQUEST));
$params = array('name' => $username);
$errors = array();
$config->userSystem->checkUserNameEmailExists($params, $errors);
if (isset($errors['cms_name']) || isset($errors['name'])) {
//user name is not available
$user = array('name' => 'no');
CRM_Utils_JSON::output($user);
} else {
//user name is available
$user = array('name' => 'yes');
CRM_Utils_JSON::output($user);
}
// Not reachable: JSON::output() above exits.
CRM_Utils_System::civiExit();
}
示例7: checkToken
/**
* @param string $token
* A token supplied by the user.
* @return bool
* TRUE if the token is valid for submitting attachments
* @throws Exception
*/
public static function checkToken($token)
{
list($signature, $ts) = explode(';;;', $token);
$signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('for', 'ts'));
if (!is_numeric($ts) || CRM_Utils_Time::getTimeRaw() > $ts + self::ATTACHMENT_TOKEN_TTL) {
return FALSE;
}
return $signer->validate($signature, array('for' => 'crmAttachment', 'ts' => $ts));
}
示例8: testGetDocument_NewOK_UpdateFailure_CacheOK_UpdateOK
/**
* First download of new doc is OK.
* The update fails (due to some bad web response).
* The old data is retained in the cache.
* The failure eventually expires.
* A new update succeeds.
*
* @dataProvider badWebResponses
* @param array $badWebResponse
* Description of a web request that returns some kind of failure.
*/
public function testGetDocument_NewOK_UpdateFailure_CacheOK_UpdateOK($badWebResponse)
{
$this->assertNotEmpty($badWebResponse);
// first try, good response
CRM_Utils_Time::setTime('2013-03-01 10:00:00');
$communityMessages = new CRM_Core_CommunityMessages($this->cache, $this->expectOneHttpRequest(self::$webResponses['first-valid-response']));
$doc1 = $communityMessages->getDocument();
$this->assertEquals('<h1>First valid response</h1>', $doc1['messages'][0]['markup']);
$this->assertApproxEquals(strtotime('2013-03-01 10:10:00'), $doc1['expires'], self::APPROX_TIME_EQUALITY);
// second try, $doc1 has expired; bad response; keep old data
CRM_Utils_Time::setTime('2013-03-01 12:00:02');
// more than 2 hours later (DEFAULT_RETRY)
$communityMessages = new CRM_Core_CommunityMessages($this->cache, $this->expectOneHttpRequest($badWebResponse));
$doc2 = $communityMessages->getDocument();
$this->assertEquals('<h1>First valid response</h1>', $doc2['messages'][0]['markup']);
$this->assertTrue($doc2['expires'] > CRM_Utils_Time::getTimeRaw());
// third try, $doc2 hasn't expired yet; no request; keep old data
CRM_Utils_Time::setTime('2013-03-01 12:09:00');
$communityMessages = new CRM_Core_CommunityMessages($this->cache, $this->expectNoHttpRequest());
$doc3 = $communityMessages->getDocument();
$this->assertEquals('<h1>First valid response</h1>', $doc3['messages'][0]['markup']);
$this->assertEquals($doc2['expires'], $doc3['expires']);
// fourth try, $doc2 has expired yet; new request; replace data
CRM_Utils_Time::setTime('2013-03-01 12:10:02');
$communityMessages = new CRM_Core_CommunityMessages($this->cache, $this->expectOneHttpRequest(self::$webResponses['second-valid-response']));
$doc4 = $communityMessages->getDocument();
$this->assertEquals('<h1>Second valid response</h1>', $doc4['messages'][0]['markup']);
$this->assertApproxEquals(strtotime('2013-03-01 12:20:02'), $doc4['expires'], self::APPROX_TIME_EQUALITY);
}
示例9: getDocument
/**
* Get the messages document (either from the cache or by downloading)
*
* @return NULL|array
*/
public function getDocument()
{
$isChanged = FALSE;
$document = $this->cache->get('communityMessages');
if (empty($document) || !is_array($document)) {
$document = array('messages' => array(), 'expires' => 0, 'ttl' => self::DEFAULT_RETRY, 'retry' => self::DEFAULT_RETRY);
$isChanged = TRUE;
}
if ($document['expires'] <= CRM_Utils_Time::getTimeRaw()) {
$newDocument = $this->fetchDocument();
if ($newDocument && $this->validateDocument($newDocument)) {
$document = $newDocument;
$document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['ttl'];
} else {
// keep the old messages for now, try again later
$document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['retry'];
}
$isChanged = TRUE;
}
if ($isChanged) {
$this->cache->set('communityMessages', $document);
}
return $document;
}
示例10: checkUserName
/**
*Function to check the CMS username
*
*/
public static function checkUserName()
{
$signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('for', 'ts'));
if (CRM_Utils_Time::getTimeRaw() > $_REQUEST['ts'] + self::CHECK_USERNAME_TTL || $_REQUEST['for'] != 'civicrm/ajax/cmsuser' || !$signer->validate($_REQUEST['sig'], $_REQUEST)) {
$user = array('name' => 'error');
echo json_encode($user);
CRM_Utils_System::civiExit();
}
$config = CRM_Core_Config::singleton();
$username = trim($_REQUEST['cms_name']);
$params = array('name' => $username);
$errors = array();
$config->userSystem->checkUserNameEmailExists($params, $errors);
if (isset($errors['cms_name']) || isset($errors['name'])) {
//user name is not availble
$user = array('name' => 'no');
echo json_encode($user);
} else {
//user name is available
$user = array('name' => 'yes');
echo json_encode($user);
}
CRM_Utils_System::civiExit();
}
示例11: stealItem
/**
* Get the next item
*
* @param int|\seconds $leaseTime seconds
*
* @return object with key 'data' that matches the inputted data
*/
function stealItem($leaseTime = 3600)
{
// foreach hits the items in order -- but we short-circuit after the first
foreach ($this->items as $id => $data) {
$nowEpoch = CRM_Utils_Time::getTimeRaw();
$this->releaseTimes[$id] = $nowEpoch + $leaseTime;
$item = new stdClass();
$item->id = $id;
$item->data = unserialize($data);
return $item;
}
// nothing in queue
return FALSE;
}
示例12: addQuickFormElement
//.........这里部分代码省略.........
case 'File':
// we should not build upload file in search mode
if ($search) {
return;
}
$qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
$qf->addUploadElement($elementName);
break;
case 'Select State/Province':
//Add State
$stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
$qf->add('select', $elementName, $label, $stateOption, $useRequired && !$search, $dataCrmCustomAttr);
break;
case 'Multi-Select State/Province':
//Add Multi-select State/Province
$stateOption = CRM_Core_PseudoConstant::stateProvince();
$qf->addElement('select', $elementName, $label, $stateOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal));
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'Select Country':
//Add Country
$countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$qf->add('select', $elementName, $label, $countryOption, $useRequired && !$search, $dataCrmCustomAttr);
break;
case 'Multi-Select Country':
//Add Country
$countryOption = CRM_Core_PseudoConstant::country();
$qf->addElement('select', $elementName, $label, $countryOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal));
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'RichTextEditor':
$attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
$qf->addWysiwyg($elementName, $label, $attributes, $search);
break;
case 'Autocomplete-Select':
$qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search);
$hiddenEleName = $elementName . '_id';
if (substr($elementName, -1) == ']') {
$hiddenEleName = substr($elementName, 0, -1) . '_id]';
}
$qf->addElement('hidden', $hiddenEleName, '', array('id' => str_replace(array(']', '['), array('', '_'), $hiddenEleName)));
static $customUrls = array();
if ($field->data_type == 'ContactReference') {
//$urlParams = "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=customfield&id={$field->id}";
$urlParams = "context=customfield&id={$field->id}";
$customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE);
$actualElementValue = $qf->getSubmitValue($hiddenEleName);
$qf->addRule($elementName, ts('Select a valid contact for %1.', array(1 => $label)), 'validContact', $actualElementValue);
} else {
$signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('cfid', 'ogid', 'sigts'));
$signParams = array('reset' => 1, 'sigts' => CRM_Utils_Time::getTimeRaw(), 'ogid' => $field->option_group_id, 'cfid' => $field->id);
$signParams['sig'] = $signer->sign($signParams);
$customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/auto', $signParams, FALSE, NULL, FALSE);
$qf->addRule($elementName, ts('Select a valid value for %1.', array(1 => $label)), 'autocomplete', array('fieldID' => $field->id, 'optionGroupID' => $field->option_group_id));
}
$qf->assign('customUrls', $customUrls);
break;
}
switch ($field->data_type) {
case 'Int':
// integers will have numeric rule applied to them.
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer');
$qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer');
} else {
$qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer');
}
break;
case 'Float':
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
$qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
} else {
$qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
}
break;
case 'Money':
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
$qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
} else {
$qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
}
break;
case 'Link':
$qf->add('text', $elementName, $label, array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false", 'data-crm-custom' => $dataCrmCustomVal), $useRequired && !$search);
$qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL');
break;
}
if ($field->is_view && !$search) {
$qf->freeze($elementName);
}
}