本文整理汇总了PHP中timespan函数的典型用法代码示例。如果您正苦于以下问题:PHP timespan函数的具体用法?PHP timespan怎么用?PHP timespan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timespan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($segments)
{
extract($_POST);
if (!isset($username)) {
$username = $segments[1];
}
$entry = DB::query('select id,username,title,location,bio,avatar from users where username = \'' . $username . '\'', 1);
$entry['activity'] = DB::query('select count(*) as activity from feed where user_id = \'' . $entry['id'] . '\'', 2, 'activity');
if (!is_file(PATH_UPLOAD . 'profile/' . $entry['avatar'])) {
$entry['avatar'] = 'default.png';
}
$feed = array();
$feedraw = DB::query('select * from feed where user_id = ' . $entry['id'] . ' and privacy_id = 1 order by id desc limit 20', 0);
foreach ($feedraw as $i => $row) {
$feed[$i] = $row;
$feed[$i]['status'] = Feed::parse_status($row['status']);
$feed[$i]['files'] = Feed::get_files($row['id'], 'th');
if (isset($row['created_ts'])) {
$feed[$i]['timespan'] = timespan($row['created_ts']);
}
}
$follow_btn = "";
if ($entry['id'] != $_SESSION['user_id']) {
$following = DB::query('select id from follows where user_id = ' . $_SESSION['user_id'] . ' and user2_id = ' . $entry['id'], 1);
if ($following) {
$follow_btn = '<button class="btn btn-success follow" data-id="' . $entry['id'] . '"><i class="ion-checkmark-round"></i> ' . _l('Following') . ' </button>';
} else {
$follow_btn = '<button class="btn btn-info follow" data-id="' . $entry['id'] . '"><i class="ion-ios-bolt"></i> ' . _l('Follow') . ' </button>';
}
}
return array('view' => "account", 'follow_btn' => $follow_btn, 'entry' => $entry, 'feed' => $feed);
}
示例2: view_forum
function view_forum($forumID = 0)
{
$this->load->helper('date');
$forumID = intval($forumID);
$forum = $this->forum_model->getForum($forumID);
// Check if topic exists
if (!empty($forum)) {
$forum['topic_list'] = array();
// Get a list of posts which have no parents (topics) in this forum
foreach ($this->post_model->getTopicsInForum($forumID) as $topic) {
$topic['post_count'] = count($this->post_model->getPostsInTopic($topic['postID']));
$topic['last_post'] = $this->post_model->getLastPost('topic', $topic['postID']);
// Convert to unix and see how long ago it was posted
$timespan = timespan(mysql_to_unix($topic['last_post']['post_date']));
// If its set and doesnt contain the word days in the timespan
if (isset($forum['last_post']['post_date']) && !strpos($timespan, 'Day')) {
$topic['last_post']['post_date'] = $timespan;
} else {
$topic['last_post']['post_date'] = $topic['last_post']['post_date'];
}
$forum['topic_list'][] = $topic;
}
$this->data = array_merge($this->data, $forum);
$this->layout->title('Forums > ' . $this->data['forum_name']);
$this->layout->create('view_forum', $this->data);
} else {
show_error('The Forum doesn\'t exist!');
$this->layout->create('message', $this->data);
}
}
示例3: duration_human
function duration_human($minutes, $output = 'days,hours,minutes', $short = false, $separator = ', ')
{
$format = function ($value, $unit, $short) {
$unitString = trans_choice("time.{$unit}", $value);
return sprintf('<strong>%d</strong>%s', $value, $short ? $unitString[0] : " {$unitString}");
};
$strings = [];
if ($short && $separator == ', ') {
$separator = ' ';
}
$timespan = timespan(time() + $minutes * 60, time(), $output);
foreach (array_filter($timespan) as $unit => $value) {
$strings[] = $format($value, $unit, $short);
}
if (empty($strings)) {
end($timespan);
$unit = key($timespan);
$strings[] = $format($timespan[$unit], $unit, $short);
}
$last = array_pop($strings);
$count = count($strings);
if ($count && $short) {
return sprintf('%s%s%s', implode($separator, $strings), $separator, $last);
} elseif ($count) {
return sprintf('%s %s %s', implode($separator, $strings), trans('and'), $last);
} else {
return $last;
}
}
示例4: index
function index()
{
if (!is_logged()) {
redirect(base_url());
}
$this->data['title'] = lang('off_vote');
$text = icon('64x64/chart_up.png') . '<p>';
if (config('alt_vote', 'rf_settings')) {
$text .= '<br><h2>' . anchor('evote', 'Emudev Top') . '</h2>';
$text .= '<h2>' . anchor('mmotop', 'MMOTOP') . '</h2>';
} else {
if ($this->_get_last_vote() != 0) {
$text .= lang('off_youvote') . timespan($this->_get_last_vote(true), time()) . ',' . br(1);
$text .= '<p>' . icon('32x32/clock.png') . lang('off_vote_wait') . timespan(time() + $this->_get_last_vote(), time() + $this->limit) . '</p>';
} elseif ($this->_last_ip() != 0) {
$text .= icon("32x32/globe_warning.png") . lang('off_ip_vote');
$text .= '<p>' . icon('32x32/clock.png') . lang('off_vote_wait') . timespan(time() + $this->_last_ip(), time() + $this->limit) . '</p>';
} else {
$text .= lang('off_vote_title') . '</p>' . $this->_show_vote_link() . anchor('vote/getbonus/' . gen_secure(), lang('off_vote_get')) . icon('32x32/note_accept.png');
// .gen_secure()
}
}
$this->data['content'] = $text . br(2) . icon('32x32/sms.png') . anchor('vote/sms', lang('off_vote_sms'));
compile();
}
示例5: GetDateTimeInFormat
function GetDateTimeInFormat($datestamp, $format)
{
switch ($format) {
// Swatch Internet Time
case null:
case 1:
return date_format(date_create($datestamp), 'jS F, Y') . ' @' . date("B", human_to_unix($datestamp)) . ' .beats';
// Unix time
// Unix time
case 2:
return human_to_unix($datestamp);
// Time since
// Time since
case 3:
return timespan(human_to_unix($datestamp), time()) . ' ago';
// Database
// Database
case 4:
return $datestamp;
// English
// English
case 5:
return date_format(date_create($datestamp), 'jS F, Y, g:i a');
// American
// American
case 6:
return date_format(date_create($datestamp), 'F jS, Y, g:i a');
}
}
示例6: post_comments
public function post_comments($post_id = 0)
{
// load date_helper from CI's app singleton
get_instance()->load->helper('date');
$comments = $this->db->where('post_id', (int) $post_id)->order_by('created DESC')->get('comments')->result_array();
return array_map(function ($a) {
$a['time_ago'] = timespan(mysql_to_unix($a['created']), time(), 2);
return $a;
}, $comments);
}
示例7: smart_timestamp
function smart_timestamp($timestamp, $date_format = "j M")
{
$time = explode(',', timespan($timestamp));
$seconds_day = 86400;
if (now() - $timestamp > $seconds_day) {
return date($date_format, $timestamp);
} else {
return $time[0] . " ago";
}
}
示例8: index
public function index($name)
{
$fsdata = dirname(__FILE__) . '/../../data/' . $name;
$filelist = Utils::fileList($fsdata, 5);
$files = array();
foreach ($filelist as $file) {
$ts2 = strtok($file, ".");
$mins = (time() - filename2date($ts2, 'U')) / 60;
$unixtime = filename2date($ts2, $mins > 1440 ? 'Y M j D H:i' : 'D H:i');
$files[] = array('filename' => $file, 'ts' => date2es($unixtime) . ' (hace ' . timespan($mins) . ')');
}
return array('name' => $name, 'files' => $files);
}
示例9: token_time
function token_time($access_token, $time)
{
$access_token_info = $this->general->custom_file_get_contents('https://graph.facebook.com/oauth/access_token_info?client_id=' . $this->app_id . '&access_token=' . $access_token);
$access_token_info = json_decode($access_token_info);
if (isset($access_token_info->access_token) && isset($access_token_info->expires_in)) {
return timespan($time - $access_token_info->expires_in, $time);
} else {
if (isset($access_token_info->access_token) && !isset($access_token_info->expires_in)) {
return LNG_TOKEN_NOT_EXPIRE;
} else {
return LNG_TOKEN_NOT_EXPIRE_TIME;
}
}
}
示例10: show
public function show($segments)
{
$entry = array();
$data = DB::query('select webcams.title, webcams.caption, webcams.code, webcams.location, users.username, users.title as user_title
from webcams
join users on users.id = webcams.user_id
where webcams.code = \'' . $segments[1] . '\'', 1);
if ($data) {
$files = File::dir_content(PATH_WEBCAM . $data['username'], '', 'lastsnap.jpg');
$dotssize = 16;
$dotssize = count($files);
$select = array();
if (count($files)) {
sort($files);
foreach ($files as $i => $file) {
$tmp = stat(PATH_WEBCAM . $data['username'] . '/' . $file);
if (isset($segments[2]) && isset($segments[3])) {
if ($tmp[9] >= $segments[2] && $tmp[9] <= $segments[3]) {
//$select[] = array($tmp[9],date('Y m d H:i:s',$tmp[9]),timespan($tmp[9]));
} else {
unset($files[$i]);
}
} else {
if ($i == count($files) - 1) {
$segments[3] = $tmp[9];
}
}
$select[] = array($tmp[9], date('Y m d H:i:s', $tmp[9]), timespan($tmp[9]));
}
if ($segments[4] == null) {
$segments[4] = 1000;
}
if ($segments[5] == null) {
$segments[5] = 500;
}
$stat = stat(PATH_WEBCAM . $data['username'] . '/' . $files[count($files) - 1]);
$entry = $data;
$entry['count'] = count($files);
$entry['timespan'] = timespan($stat[9]);
//$entry['files'] = array_slice($files,count($files)-$dotssize,count($files));
$entry['files'] = $files;
}
}
return array('view' => 'webcams/show', 'select' => $select, 'segments' => $segments, 'entry' => $entry);
}
示例11: index
function index()
{
$this->data['title'] = lang('off_acc') . gen_name_profile();
$this->data['content'] = '<p>' . lang('off_welcome') . gen_name_profile() . lang('off_welcome2') . '</p>';
if (check_master_answer() == false) {
$this->data['content'] .= icon('32x32/security.png') . anchor('main/profile', b(lang('off_attepprofile')));
}
$this->data['content'] .= br(2) . '<p>' . effect_toggle(b(lang('off_main_lastbuy')), 'log', 'slide') . '</p>
<hr>' . hiddendiv("log", GetLogBuy()) . $this->_reflink();
//$this->data['content'].=anchor('rdonate',icon('24x24/euro_currency_sign.png').lang('off_return_donate')).br(1);
if (is_gm()) {
$this->data['content'] .= lang('off_gm_panel') . anchor('manager', lang('off_gm_btn2'));
}
if (prenium_active() == true) {
$this->data['content'] .= icon('32x32/package_download.png', lang('off_premhave')) . lang('off_premium_expire') . timespan(time(), premium_expire());
}
compile();
}
示例12: index
public function index()
{
// Define the page title.
$data['title'] = lang('tle_recent_discussions');
// Define the template.
$data['template'] = 'pages/home/home';
// Get the discussions from the database.
$discussions = $this->discussions->order_by(array('sticky' => 'DESC', 'posted' => 'DESC'))->get_all();
// Set the table template.
$data['tmpl'] = array('table_open' => '<table class="table table-hover">');
$this->table->set_template(element('tmpl', $data));
// Set the table headings.
$this->table->set_heading('', 'Discussion', 'Users', 'Replies', 'Views', 'Activity');
// Loop through the discussions.
if (!empty($discussions)) {
foreach ($discussions as $row) {
// Get the user who created the discussion.
$poster = $this->users->get_by('username', $row->poster);
$last_poster = $this->users->get_by('username', $row->last_poster);
// Build the posters avatar.
$data['avatar'] = array('src' => $this->gravatar->get_gravatar($poster->email, $this->config->item('gravatar_rating'), $this->config->item('gravatar_size'), $this->config->item('gravatar_default_image')), 'title' => '' . $poster->username . ' - Discussion Creator');
// Get the category associated with the discussion.
$cat = $this->categories->get_by('id', $row->category_id);
if (!empty($this->_unread)) {
if (in_array($row->id, $this->_unread)) {
$unread = true;
} else {
$unread = false;
}
} else {
$unread = false;
}
$data['discussions'][] = array('subject' => $unread == TRUE ? anchor(site_url('discussions/view/' . $row->id), '<i class="fa fa-lightbulb-o"></i> <strong>' . $row->subject . '</strong>') : anchor(site_url('discussions/view/' . $row->id), $row->subject), 'replies' => $row->replies, 'views' => $row->views, 'last_comment' => timespan($row->last_comment, time()), 'last_poster' => anchor(site_url('users/profile/' . $row->last_poster_id), $row->last_poster), 'category' => anchor(site_url('categories/' . $cat->slug . ''), $cat->name), 'avatar' => anchor(site_url('users/profile/' . $poster->id), img(element('avatar', $data))), 'avatar_last_poster' => anchor(site_url('users/profile/' . $last_poster->id), img(element('avatar_last_poster', $data))), 'sticky' => $row->sticky == 1 ? '<span class="label label-success"><i class="fa fa-thumb-tack"></i></span> ' : '', 'closed' => $row->closed == 1 ? '<span class="label label-danger"><i class="fa fa-lock"></i></span> ' : '', 'unread' => in_array($row->id, $this->_unread) ? 'unread' : '');
}
} else {
// Fill with blank data to prevent errors.
$data['discussions'] = '';
}
// Build the page breadcrumbs.
$this->crumbs->add(lang('crumb_recent_discussions'));
// Define the page data.
$data['page'] = array('btn_new_discussion' => anchor(site_url('discussions/new_discussion'), lang('btn_new_discussion'), array('class' => 'btn btn-default btn-xs')), 'lnk_mark_all' => anchor(site_url('discussions/mark_all'), lang('lnk_mark_all')), 'discussions' => element('discussions', $data), 'has_discussions' => !empty($discussions) ? 1 : 0, 'breadcrumbs' => $this->crumbs->output(), 'pagination' => $this->pagination->create_links());
$this->render(element('page', $data), element('title', $data), element('template', $data));
}
示例13: feed
/**
* Load a constant
*
* Magic method to get a constant or global variable
*
* Usage:
* {{ twitter:feed username="twitterusername" limit="5" }}
*
* @return array The tweet objects in an array.
*/
function feed()
{
$username = $this->attribute('username');
$limit = $this->attribute('limit', 5);
if (!($tweets = $this->pyrocache->get('twitter-' . $username))) {
$tweets = json_decode(@file_get_contents($this->feed_url . '&screen_name=' . $username . '&count=' . $limit));
$this->pyrocache->write($tweets, 'twitter-' . $username, $this->settings->twitter_cache);
}
$patterns = array('((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\.&]*)' => '<a href="$0" target="_blank">$0</a>', '|([a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6})|i' => '<a href="mailto:$1">$1</a>', '| @([a-z0-9-_]+)|i' => '<a href="http://twitter.com/$1" target="_blank">$0</a>', '|#([a-z0-9-_]+)|i' => '<a href="http://twitter.com/search?q=%23$1" target="_blank">$0</a>');
if (!$tweets) {
return array();
}
foreach ($tweets as &$tweet) {
$tweet->id = sprintf('%.0f', $tweet->id);
$tweet->text = str_replace($username . ': ', '', $tweet->text);
$tweet->text = preg_replace(array_keys($patterns), $patterns, $tweet->text);
$tweet->timespan = strtolower(current(explode(',', timespan(strtotime($tweet->created_at))))) . ' ago';
}
return $tweets;
}
示例14: nicetime
function nicetime($timestamp)
{
if ($timestamp == '' or !is_numeric($timestamp)) {
return '';
}
$hari = date('l', $timestamp);
$tgl = date('d', $timestamp);
$bln = date('F', $timestamp);
$thn = date('Y', $timestamp);
$pukul = date('H:i', $timestamp);
// timespan dari CI's date helper
$timespan = strtolower(timespan($timestamp));
$timespan = str_replace(',', '', $timespan);
$exp = explode(' ', $timespan);
$k = $exp[1];
$v = $exp[0];
if ($v > 0) {
if (stristr($k, 'year') or date('Y') > $thn) {
return $tgl . ' ' . $bln . ' ' . $thn;
} elseif (stristr($k, 'week') or stristr($k, 'month')) {
return $tgl . ' ' . $bln . ' at ' . $pukul;
} elseif (stristr($k, 'day') or stristr($k, 'hour') or stristr($k, 'minute') or stristr($k, 'second')) {
if ($v >= 2 and stristr($k, 'day')) {
return $hari . ' at ' . $pukul;
} elseif (date('j') - date('j', $timestamp) == 1) {
return 'Yesterday at ' . $pukul;
} elseif (date('D') == date('D', $timestamp) and ($v >= 10 and stristr($k, 'hour'))) {
return 'Today at ' . $pukul;
} elseif (stristr($k, 'hour') and $v < 10 or stristr($k, 'minute') or stristr($k, 'second')) {
if (stristr($k, 'second') and $v <= 15) {
return 'just now';
}
return $v . ' ' . $k . ' ago';
} else {
return $hari . ' at ' . $pukul;
}
}
} else {
return 'just now';
}
}
示例15: get_logged_actions
/**
* Get an array containing logged actions.
*
* If $action is left empty but $item_id is not, or if the $action is an integer,
* it retrieves all the actions pertaining to $item_id.
*
* If $action is NOT empty but $item_id is, it retrieves all the $action actions in the DB.
*
* If both $action and $item_id have a value, it returns all $action actions pertaining to $item_id.
*
* Returns an array. Triggers an error if the action does not exist in My_lang.
*
* Usage:
*
*
* @staticvar array $userIdCache
* @param string|integer $action
* @param integer $item_id
* @return array
*/
function get_logged_actions($action = '', $item_id = 0)
{
# In order to increase performance, whenever the function gets the username
# of a given user_id, it'll cache it, so that it won't need to go query the DB
# again for the duration of the request.
static $userIdCache = array();
if (!empty($action) and !is_int($action) and !lang($action)) {
trigger_error('Action message does not exist for ' . $action . '. Create it in /language/My_lang.php.');
}
$CI =& get_instance();
$CI->load->model('users/user_m');
$where = array();
if (!empty($item_id)) {
$where['item_id'] = $item_id;
}
if (is_int($action)) {
$where['item_id'] = $action;
} elseif (!empty($action)) {
$where['action'] = $action;
}
$buffer = $CI->db->get_where('action_logs', $where)->result_array();
foreach ($buffer as $key => $row) {
$variables = array('timeago' => strtolower(timespan($row['timestamp']) . ' ago'));
if ($row['user_id'] != 0) {
if (!isset($userIdCache[$row['user_id']])) {
$userBuffer = $CI->user_m->select('username')->get($row['user_id']);
$userBuffer = $userBuffer->username;
} else {
$userBuffer = $userIdCache[$row['user_id']];
}
$variables['username'] = $userBuffer;
}
if ($row['item_id'] != 0) {
$variables['item_id'] = $row['item_id'];
}
foreach ($variables as $variable => $value) {
$buffer[$key]['message'] = str_ireplace('{' . $variable . '}', $value, $buffer[$key]['message']);
}
}
return $buffer;
}