本文整理汇总了PHP中Date::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::resolve方法的具体用法?PHP Date::resolve怎么用?PHP Date::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::resolve方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collectGarbage
/**
* With each call, clean up any really old caches that are no longer needed
*
* @param bool $force Force a collection even if it's not time
* @return void
*/
public function collectGarbage($force = false)
{
// only garbage collect once per week
$last = $this->cache->get('last_garbage_collection', null);
// is it time for garbage collection?
if (!$force && $last && $last >= Date::resolve('-1 week')) {
// not time yet, we're good
return;
}
// log that we're coming through
$this->log->debug('Collecting garbage.');
// set last time
$this->cache->put('last_garbage_collection', time());
// clean up troves
$threshold = $this->fetchConfig('garbage_threshold', null, false, false, false);
if ($threshold) {
$this->cache->purgeFromBefore('-' . $threshold);
}
// clean up keys
$keys = $this->cache->listAll('keys');
foreach ($keys as $key) {
$hashes = $this->cache->getYAML('keys/' . $key);
foreach ($hashes as $hash_key => $hash) {
if (!$this->cache->exists('troves/' . $hash)) {
unset($hashes[$hash_key]);
}
}
if (!count($hashes)) {
$this->cache->delete('keys/' . $key);
} else {
$this->cache->putYAML('keys/' . $key, $hashes);
}
}
}
示例2: saveRevision
/**
* Store a revision for a given $file
*
* @param string $file The file to save a revision for
* @param string $content The content to store as data for this revision
* @param string $message The commit message
* @param null $timestamp An optional timestamp for when this revision occurred
* @param bool $is_new Whether the file is new or not
*/
public function saveRevision($file, $content, $message, $timestamp = null, $is_new = false)
{
// store in folder of hashed file name
$hash = Helper::makeHash($file);
// determine revision number
$nth_revision = count($this->storage->listAll($hash)) + 1;
$revision_data = array('file' => $file, 'revision' => $nth_revision, 'message' => $message, 'timestamp' => $timestamp ? Date::resolve($timestamp) : time(), 'author_uid' => Auth::getCurrentMember()->getUID(), 'data' => $content);
$location = $hash . '/' . str_pad($nth_revision, 4, '0', STR_PAD_LEFT);
$this->storage->putYAML($location, $revision_data);
}
示例3: index
public function index()
{
// if disabled, do nothing
if (!$this->core->isEnabled()) {
return Parse::contextualTemplate($this->content, array(), $this->context);
}
// grab and prepare parameters
$key = $this->fetchParam('key', null, null, false, false);
$age = time() - Date::resolve('-' . $this->fetch(array('for', 'default_cache_length'), '12 hours', null, false, false));
$hash = $this->fetch(array('scope', 'default_scope'), 'site') === 'page' ? Helper::makeHash(URL::getCurrent(), $this->content) : Helper::makeHash($this->content);
$path = 'troves/' . $hash;
// deal with keys
if ($key) {
// split on pipes
$keys = explode('|', $key);
// loop through keys, storing this hash to this key
foreach ($keys as $key) {
$key_path = 'keys/' . trim($key);
// get existing keys
$hashes = $this->cache->getYAML($key_path, array());
$new_hashes = array();
// check that the hashes are all still valid
foreach ($hashes as $new_hash) {
if ($this->cache->exists('troves/' . $new_hash)) {
$new_hashes[] = $new_hash;
}
}
// add this one
$new_hashes[] = $hash;
// append new ones
$this->cache->putYAML($key_path, array_unique($new_hashes));
}
}
// check for pre-existing cache
if (!$this->cache->exists($path) || $this->cache->getAge($path) > $age) {
// cache doesn't exist or has expired, so parse this contextually...
$html = Parse::contextualTemplate($this->content, array(), $this->context);
// ...and store the HTML
$this->cache->put($path, $html);
}
// garbage collection
$this->core->collectGarbage();
// return what we know
return $this->cache->get($path);
}
示例4: index
public function index($value, $parameters = array())
{
$use_smart_relative = !empty($parameters[0]) && $parameters[0] == 'smart';
if ($use_smart_relative) {
// find today, yesterday, and beyond
$today = Date::resolve('today midnight');
$yesterday = Date::resolve('yesterday midnight');
$tomorrow = Date::resolve('tomorrow midnight');
$two_days = Date::resolve('+2 days midnight');
$hour_ago = Date::resolve('-1 hour');
$in_an_hour = Date::resolve('+1 hour');
$now = time();
// normalize date
$timestamp = Date::resolve($value);
// now check
if ($timestamp > $two_days || $timestamp < $yesterday) {
// this is outside of an immediate window, just return date
return Date::format(Config::getDateFormat(), $timestamp) . ' ' . __('at') . ' ' . Date::format(Config::getTimeFormat(), $timestamp);
} elseif ($timestamp > $hour_ago && $timestamp < $in_an_hour) {
// this is very near by, return relative date
return Carbon::createFromTimestamp($timestamp)->diffForHumans();
} elseif ($timestamp < $now) {
if ($timestamp > $today) {
// this is today
return __('today') . ' ' . __('at') . ' ' . Date::format(Config::getTimeFormat(), $timestamp);
} else {
// this is yesterday
return __('yesterday') . ' ' . __('at') . ' ' . Date::format(Config::getTimeFormat(), $timestamp);
}
} else {
// this is tomorrow
return __('tomorrow') . ' ' . __('at') . ' ' . Date::format(Config::getTimeFormat(), $timestamp);
}
} else {
if (is_numeric($value)) {
// this is a timestamp
return Carbon::createFromTimestamp($value)->diffForHumans();
}
// this is a string
return Carbon::parse($value)->diffForHumans();
}
}
示例5: filter
/**
* Filters the current content set down based on the filters given
*
* @param array $filters Filters to use to narrow down content
* @return void
* @throws Exception
*/
public function filter($filters)
{
$hash = Debug::markStart('content', 'filtering');
$filters = Helper::ensureArray($filters);
// nothing to filter, abort
if (!$this->count()) {
return;
}
$since_date = null;
$until_date = null;
$remove_hidden = null;
$remove_drafts = null;
$keep_type = "all";
$folders = null;
$conditions = null;
$located = false;
$where = null;
// standardize filters
// -------------------
$given_filters = $filters;
$filters = array('show_hidden' => isset($given_filters['show_hidden']) ? $given_filters['show_hidden'] : null, 'show_drafts' => isset($given_filters['show_drafts']) ? $given_filters['show_drafts'] : null, 'since' => isset($given_filters['since']) ? $given_filters['since'] : null, 'until' => isset($given_filters['until']) ? $given_filters['until'] : null, 'show_past' => isset($given_filters['show_past']) ? $given_filters['show_past'] : null, 'show_future' => isset($given_filters['show_future']) ? $given_filters['show_future'] : null, 'type' => isset($given_filters['type']) ? strtolower($given_filters['type']) : null, 'folders' => isset($given_filters['folders']) ? $given_filters['folders'] : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'located' => isset($given_filters['located']) ? $given_filters['located'] : null, 'where' => isset($given_filters['where']) ? $given_filters['where'] : null);
// determine filters
// -----------------
if (!is_null($filters['show_hidden'])) {
$remove_hidden = !(bool) $filters['show_hidden'];
}
if (!is_null($filters['show_drafts'])) {
$remove_drafts = !(bool) $filters['show_drafts'];
}
if ($filters['since']) {
$since_date = Date::resolve($filters['since']);
}
if ($filters['show_past'] === false && (!$since_date || $since_date < time())) {
$since_date = Config::getEntryTimestamps() ? time() : Date::resolve("today midnight");
}
if ($filters['until']) {
$until_date = Date::resolve($filters['until']);
}
if ($filters['show_future'] === false && (!$until_date || $until_date > time())) {
$until_date = Config::getEntryTimestamps() ? time() : Date::resolve("tomorrow midnight") - 1;
}
if ($filters['type'] === "entries" || $filters['type'] === "pages") {
$keep_type = $filters['type'];
}
if ($filters['folders']) {
$folders = Parse::pipeList($filters['folders']);
}
if ($filters['conditions']) {
$conditions = Parse::conditions($filters['conditions']);
}
if ($filters['located']) {
$located = true;
}
if ($filters['where']) {
$where = $filters['where'];
}
// before we run filters, we need to look through conditions if they
// were set to see if we're going to need content or content_raw
// -----------
if ($conditions) {
// check for conditions involving content
$uses_content = false;
foreach ($conditions as $field => $instructions) {
if (strtolower($field) === 'content') {
$uses_content = true;
break;
}
}
// this uses content, which means we need to load it for all content
if ($uses_content) {
$this->prepare(true, false);
$this->content_parsed = false;
}
}
// run filters
// -----------
foreach ($this->content as $key => $data) {
// entry or page removal
if ($keep_type === "pages" && !$data['_is_page']) {
unset($this->content[$key]);
continue;
} elseif ($keep_type === "entries" && !$data['_is_entry']) {
unset($this->content[$key]);
continue;
}
// check for non-public content
if ($remove_drafts && $data['_is_draft']) {
unset($this->content[$key]);
continue;
}
if ($remove_hidden && $data['_is_hidden']) {
unset($this->content[$key]);
continue;
//.........这里部分代码省略.........
示例6: index
public function index($value, $parameters = array())
{
$time = Date::resolve($value);
return Carbon::createFromTimestamp($time)->isTomorrow();
}
示例7: processVanityURLs
/**
* If the given redirect conditions are met, redirects the site to the given URL
*
* @param array $config Configuration of the site
* @return bool
*/
public static function processVanityURLs($config)
{
// if no array or an empty one, we're done here
if (!isset($config['_vanity_urls']) || empty($config['_vanity_urls'])) {
return false;
}
// current path
// note: not using API because it's not ready yet
$uri = $_SERVER['REQUEST_URI'];
$query = $_SERVER['QUERY_STRING'];
$current = $query ? str_replace("?" . $query, "", $uri) : $uri;
// loop through configured vanity URLs
foreach ($config['_vanity_urls'] as $url => $redirect) {
$redirect_forward = false;
$redirect_url = null;
// if this wasn't a match, move on
if (Path::tidy("/" . $url) != $current) {
continue;
}
// we have a match
// now check to see how this redirect was set up
if (is_array($redirect)) {
// this was an array
if (!isset($redirect['url'])) {
Log::warn("Vanity URL `" . $url . "` matched, but no redirect URL was configred.", "core", "vanity");
continue;
}
$redirect_start = Helper::choose($redirect, 'start', null);
$redirect_until = Helper::choose($redirect, 'until', null);
$redirect_forward = Helper::choose($redirect, 'forward_query_string', false);
$redirect_url = Helper::choose($redirect, 'url', $redirect);
$redirect_type = (int) Helper::choose($redirect, 'type', 302);
// if start date is set and it's before that date
if ($redirect_start && time() < Date::resolve($redirect_start)) {
Log::info("Vanity URL `" . $url . "` matched, but scheduling does not allowed redirecting yet.", "core", "vanity");
continue;
}
// if until date is set and it's after after that date
if ($redirect_until && time() > Date::resolve($redirect_until)) {
Log::info("Vanity URL `" . $url . "` matched, but scheduling for this redirect has expired.", "core", "vanity");
continue;
}
} else {
// this was a string
$redirect_url = $redirect;
$redirect_type = 302;
}
// optionally forward any query string variables
if ($query && $redirect_forward) {
$redirect_url .= strstr($redirect_url, "?") !== false ? "&" : "?";
$redirect_url .= $query;
}
// ensure a complete URL
if (!substr($redirect_url, 0, 4) == "http") {
$redirect_url = Path::tidy(Config::getSiteRoot() . "/" . $redirect_url);
}
// ensure a valid redirect type
if (!in_array($redirect_type, array(301, 302))) {
$redirect_type = 302;
}
// redirect
header("Location: " . $redirect_url, true, $redirect_type);
exit;
}
}
示例8: getVariable
/**
* Takes a dot-notated key and finds the value for it in the given
* array or object.
*
* @param string $key Dot-notated key to find
* @param array|object $data Array or object to search
* @param mixed $default Default value to use if not found
* @return mixed
*/
protected function getVariable($key, $data, $default = null)
{
$modifiers = null;
if (strpos($key, "|") === false) {
} else {
$parts = explode("|", $key);
$key = $parts[0];
$modifiers = array_splice($parts, 1);
}
if (strpos($key, $this->scopeGlue) === false) {
$parts = explode('.', $key);
} else {
$parts = explode($this->scopeGlue, $key);
}
foreach ($parts as $key_part) {
if (is_array($data)) {
if (!array_key_exists($key_part, $data)) {
return $default;
}
$data = $data[$key_part];
} elseif (is_object($data)) {
if (!isset($data->{$key_part})) {
return $default;
}
$data = $data->{$key_part};
} else {
return $default;
}
}
if ($modifiers) {
foreach ($modifiers as $mod) {
if (strpos($mod, ":") === false) {
$modifier_name = $mod;
$modifier_params = array();
} else {
$parts = explode(":", $mod);
$modifier_name = $parts[0];
$modifier_params = array_splice($parts, 1);
}
if ($modifier_name == 'trim') {
$data = trim($data);
} elseif ($modifier_name == 'img') {
$data = '<img src="' . \Path::toAsset($data) . '" />';
} elseif ($modifier_name == 'link') {
if (filter_var($data, FILTER_VALIDATE_EMAIL)) {
// email address
$data = '<a href="mailto:' . $data . '" />' . $data . '</a>';
} else {
$data = '<a href="' . $data . '" />' . $data . '</a>';
}
} elseif ($modifier_name == 'upper') {
$data = strtoupper($data);
} else {
if ($modifier_name == 'lower') {
$data = strtolower($data);
} else {
if ($modifier_name == 'slugify') {
$data = \Slug::make($data);
} else {
if ($modifier_name == 'deslugify') {
$data = trim(preg_replace('~[-_]~', ' ', $data), " ");
} else {
if ($modifier_name == 'title') {
$data = ucwords($data);
} else {
if ($modifier_name == 'format') {
$data = date($modifier_params[0], $data);
} else {
if ($modifier_name == 'format_number') {
$decimals = isset($modifier_params[0]) ? $modifier_params[0] : 0;
$data = number_format($data, $decimals);
} else {
if ($modifier_name == 'in_future') {
$data = \Date::resolve($data) > time() ? "true" : "";
} else {
if ($modifier_name == 'in_past') {
$data = \Date::resolve($data) < time() ? "true" : "";
} else {
if ($modifier_name == 'markdown') {
$data = Markdown($data);
} else {
if ($modifier_name == 'textile') {
$textile = new \Textile();
$data = $textile->TextileThis($data);
} else {
if ($modifier_name == 'length') {
if (is_array($data)) {
$data = count($data);
} else {
$data = strlen($data);
}
//.........这里部分代码省略.........
示例9: index
public function index($value, $parameters = array())
{
return Date::resolve($value) < time() ? "true" : "";
}
示例10: filter
/**
* Filters the current content set down based on the filters given
*
* @param array $filters Filters to use to narrow down content
* @return void
* @throws Exception
*/
public function filter($filters)
{
$filters = Helper::ensureArray($filters);
// nothing to filter, abort
if (!$this->count()) {
return;
}
$since_date = null;
$until_date = null;
$remove_hidden = null;
$keep_type = "all";
$folders = null;
$conditions = null;
$located = false;
// standardize filters
// -------------------
$given_filters = $filters;
$filters = array('show_all' => isset($given_filters['show_all']) ? $given_filters['show_all'] : null, 'since' => isset($given_filters['since']) ? $given_filters['since'] : null, 'until' => isset($given_filters['until']) ? $given_filters['until'] : null, 'show_past' => isset($given_filters['show_past']) ? $given_filters['show_past'] : null, 'show_future' => isset($given_filters['show_future']) ? $given_filters['show_future'] : null, 'type' => isset($given_filters['type']) ? strtolower($given_filters['type']) : null, 'folders' => isset($given_filters['folders']) ? $given_filters['folders'] : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'located' => isset($given_filters['located']) ? $given_filters['located'] : null);
// determine filters
// -----------------
if ($filters['show_all'] === false) {
$remove_hidden = true;
}
if ($filters['since']) {
$since_date = Date::resolve($filters['since']);
}
if ($filters['show_past'] === false && (!$since_date || $since_date < time())) {
$since_date = time();
}
if ($filters['until']) {
$until_date = Date::resolve($filters['until']);
}
if ($filters['show_future'] === false && (!$until_date || $until_date > time())) {
$until_date = time();
}
if ($filters['type'] === "entries" || $filters['type'] === "pages") {
$keep_type = $filters['type'];
}
if ($filters['folders']) {
$folders = Helper::parseForFolders($filters['folders']);
}
if ($filters['conditions']) {
$conditions = Parse::conditions($filters['conditions']);
}
if ($filters['located']) {
$located = true;
}
// run filters
// -----------
foreach ($this->content as $key => $data) {
// entry or page removal
if ($keep_type === "pages" && !$data['_is_page']) {
unset($this->content[$key]);
continue;
} elseif ($keep_type === "entries" && !$data['_is_entry']) {
unset($this->content[$key]);
continue;
}
// check if this is hidden content
if ($remove_hidden && strpos($data['_local_path'], "/_") !== false) {
unset($this->content[$key]);
continue;
}
// folder
if ($folders) {
$keep = false;
foreach ($folders as $folder) {
if ($folder === "*" || $folder === "/*") {
// include all
$keep = true;
break;
} elseif (substr($folder, -1) === "*") {
// wildcard check
if (strpos($data['_folder'], substr($folder, 0, -1)) === 0) {
$keep = true;
break;
}
} else {
// plain check
if ($folder == $data['_folder']) {
$keep = true;
break;
}
}
}
if (!$keep) {
unset($this->content[$key]);
continue;
}
}
// since & show past
if ($since_date && $data['datestamp'] && $data['datestamp'] < $since_date) {
unset($this->content[$key]);
//.........这里部分代码省略.........