当前位置: 首页>>代码示例>>PHP>>正文


PHP date::timespan方法代码示例

本文整理汇总了PHP中date::timespan方法的典型用法代码示例。如果您正苦于以下问题:PHP date::timespan方法的具体用法?PHP date::timespan怎么用?PHP date::timespan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在date的用法示例。


在下文中一共展示了date::timespan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _view

 /**
  * User profile
  */
 public function _view()
 {
     $this->tab_id = 'profile';
     $owner = $this->user && $this->member->id == $this->user->id;
     if ($owner && $this->user->newcomments) {
         $this->user->newcomments = 0;
         $this->user->save();
     }
     // Actions
     if ($this->member->has_access(User_Model::ACCESS_EDIT)) {
         $this->page_actions[] = array('link' => url::user($this->member) . '/edit', 'text' => __('Settings'), 'class' => 'settings');
     }
     // Picture
     widget::add('side', View_Mod::factory('member/member', array('mod_class' => 'member member-' . $this->member->id, 'user' => $this->member)));
     // Comments
     if ($this->member->has_access(User_Model::ACCESS_COMMENT)) {
         $comment = new User_Comment_Model();
         $form_values = $comment->as_array();
         $form_errors = array();
         // check post
         if (csrf::valid() && ($post = $this->input->post())) {
             $comment->user_id = $this->member->id;
             $comment->author_id = $this->user->id;
             $comment->comment = $post['comment'];
             if (isset($post['private'])) {
                 $comment->private = 1;
             }
             try {
                 $comment->save();
                 if (!$owner) {
                     $this->member->newcomments += 1;
                     $this->member->save();
                 }
                 $this->user->commentsleft += 1;
                 $this->user->save();
                 if (!request::is_ajax()) {
                     url::redirect(url::current());
                 }
             } catch (ORM_Validation_Exception $e) {
                 $form_errors = $e->validation->errors();
                 $form_values = arr::overwrite($form_values, $post);
             }
         }
         // Handle pagination
         $per_page = 25;
         $page_num = $this->uri->segment('page') ? $this->uri->segment('page') : 1;
         $page_offset = ($page_num - 1) * $per_page;
         $total_comments = $this->member->get_comment_count();
         $comments = $this->member->find_comments($page_num, $per_page, $this->user);
         $pagination = new Pagination(array('items_per_page' => $per_page, 'total_items' => $total_comments));
         $view = View::factory('generic/comments', array('delete' => '/member/comment/%d/delete/?token=' . csrf::token(), 'private' => '/member/comment/%d/private/?token=' . csrf::token(), 'comments' => $comments, 'errors' => $form_errors, 'values' => $form_values, 'pagination' => $pagination, 'user' => $this->user));
         if (request::is_ajax()) {
             echo $view;
             return;
         }
         widget::add('main', $view);
     }
     // Basic info
     $basic_info = array();
     if (!empty($this->member->name)) {
         $basic_info[__('Name')] = html::specialchars($this->member->name);
     }
     if (!empty($this->member->city_name)) {
         $basic_info[__('City')] = html::specialchars($this->member->city_name);
     }
     if (!empty($this->member->dob) && $this->member->dob != '0000-00-00') {
         $basic_info[__('Date of Birth')] = __(':dob (:years years)', array(':dob' => date::format('DMYYYY', $this->member->dob), ':years' => date::timespan(strtotime($this->member->dob), null, 'years')));
     }
     if (!empty($this->member->gender)) {
         $basic_info[__('Gender')] = $this->member->gender == 'm' ? __('Male') : __('Female');
     }
     if (!empty($this->member->latitude) && !empty($this->member->longitude)) {
         $basic_info[__('Location')] = $this->member->latitude . ', ' . $this->member->longitude;
         $basic_info[__('Location')] = html::anchor('#map', __('Toggle map'), array('class' => 'expander', 'title' => __('Show/hide'))) . '<div id="map" style="display: none">' . __('Map loading') . '</div>';
         $map = new Gmap('map', array('ScrollWheelZoom' => true));
         $map->center($this->member->latitude, $this->member->longitude, 15)->controls('small')->types();
         $map->add_marker($this->member->latitude, $this->member->longitude, html::avatar($this->member->avatar, $this->member->username) . html::user($this->member));
         widget::add('foot', html::script_source($map->render('gmaps/jquery_event')));
         widget::add('foot', html::script_source("\$('a[href*=\"#map\"]:first').click(function() { \$('#map').toggle('normal', gmap_open); return false; });"));
     }
     // Site info
     $site_info = array(__('Registered') => date::format('DMYYYY_HM', $this->member->created) . ' [#' . $this->member->id . ']', __('Logins') => __(':logins (:ago ago)', array(':logins' => number_format($this->member->logins, 0), ':ago' => '<abbr title="' . date::format('DMYYYY_HM', $this->member->last_login) . '">' . date::timespan_short($this->member->last_login) . '</abbr>')), __('Posts') => number_format($this->member->posts, 0), __('Comments') => number_format($this->member->commentsleft, 0));
     // Initialize tabs
     $tabs = array('basic-info' => array('href' => '#basic-info', 'title' => __('Basic info'), 'tab' => new View('generic/list_info', array('id' => 'basic-info', 'title' => __('Basic info'), 'list' => $basic_info))), 'site-info' => array('href' => '#site-info', 'title' => __('Site info'), 'tab' => new View('generic/list_info', array('id' => 'site-info', 'title' => __('Site info'), 'list' => $site_info))));
     widget::add('side', View::factory('generic/tabs', array('id' => 'info-tab', 'tabs' => $tabs)));
     $this->_side_views();
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:90,代码来源:member.php

示例2: get_snips_public

 public function get_snips_public($sql_limit, $sql_offset)
 {
     $results = '';
     $db = Database::instance();
     $query = $db->from('snips')->where(array('private =' => '0'))->limit($sql_limit * 10)->offset($sql_offset)->orderby('date_added', 'DESC')->get();
     if ($query) {
         if ($sql_limit == 1) {
             $results .= "<ol start='" . $sql_limit . "' class='snipList'>\n";
         } else {
             $results .= "<ol start='" . $sql_limit * 10 . "' class='snipList'>\n";
         }
         foreach ($query as $row) {
             $results .= "<li>\n";
             $timeago = date::timespan(strtotime($row->date_added), time(), "days");
             if ($timeago == 0) {
                 $timeago = date::timespan(strtotime($row->date_added), time(), "hours");
                 $timeago .= " hours";
             } else {
                 $timeago .= " days";
             }
             $results .= "<h2>";
             $username = $this->db->query("SELECT username FROM users WHERE id = " . $row->user_id . "");
             foreach ($username as $row2) {
                 $username = $row2->username;
             }
             $results .= "<a href='/home/snip/" . $row->snip_id . "'>" . $row->title . "</a></h2><span class='favLink'><a href=\"#\">Favorite</a></span>" . "submitted " . $timeago . " ago by " . $username . " ";
             $results .= "<p>";
             $results .= "<pre>" . text::limit_words($row->snippet, 10, "...<a href='/home/snip/" . $row->snip_id . "'>see whole snippet</a>") . "</pre>";
             if (strlen($row->description) > 1) {
                 $results .= "Description: " . strip_tags(text::limit_words($row->description, 25));
             }
             $results .= "</p>\n";
             $results .= "</li>\n";
         }
         $results .= "</ol>\n";
     }
     return $results;
 }
开发者ID:kevinroberts,项目名称:snippetz,代码行数:38,代码来源:snip.php

示例3: timespan_string

 /**
  * Returns time difference between two timestamps, in the format:
  * N year, N months, N weeks, N days, N hours, N minutes, and N seconds ago
  *
  * @param   integer       timestamp
  * @param   integer       timestamp, defaults to the current time
  * @param   string        formatting string
  * @return  string
  */
 public static function timespan_string($time1, $time2 = NULL, $output = 'years,months,weeks,days,hours,minutes,seconds')
 {
     if ($difference = date::timespan($time1, $time2, $output) and is_array($difference)) {
         // Determine the key of the last item in the array
         $last = end($difference);
         $last = key($difference);
         $span = array();
         foreach ($difference as $name => $amount) {
             if ($name !== $last and $amount === 0) {
                 // Skip empty amounts
                 continue;
             }
             // Add the amount to the span
             $span[] = ($name === $last ? ' and ' : ', ') . $amount . ' ' . ($amount === 1 ? inflector::singular($name) : $name);
         }
         // Replace difference by making the span into a string
         $difference = trim(implode('', $span), ',');
     } elseif (is_int($difference)) {
         // Single-value return
         $difference = $difference . ' ' . ($difference === 1 ? inflector::singular($output) : $output);
     }
     return $difference;
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:32,代码来源:date.php

示例4: timespan_short

 /**
  * Returns time difference in human readable format with only the largest span
  *
  * @param		int|string	$time1
  * @param		int|string	$time2
  * @param		string			$output
  * @return	string
  */
 public static function timespan_short($time1, $time2 = null)
 {
     if (!is_numeric($time1)) {
         $time1 = strtotime($time1);
     }
     if (!is_null($time2) && !is_int($time2)) {
         $time2 = strtotime($time2);
     }
     if ($difference = date::timespan($time1, $time2) and is_array($difference)) {
         foreach ($difference as $span => $amount) {
             if ($amount > 0) {
                 return $amount . ' ' . __(inflector::singular($span, $amount));
             }
         }
     }
     if (empty($difference)) {
         return '0 ' . __('seconds');
     }
     return __('some time');
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:28,代码来源:MY_date.php

示例5: foreach

/**
 * Forum topic
 *
 * @package    Forum
 * @author     Antti Qvickström
 * @copyright  (c) 2010 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
?>

<?php 
foreach ($posts as $post) {
    // Time difference between posts
    $current = strtotime($post->created);
    $difference = isset($previous) ? date::timespan($current, $previous, 'years,months') : array('years' => 0, 'months' => 0);
    if ($difference['years'] || $difference['months']) {
        ?>

<div class="divider post-old"><?php 
        echo __('Previous post over :ago ago', array(':ago' => date::timespan_short($current, $previous)));
        ?>
</div>

<?php 
    }
    $previous = $current;
    echo View::factory('forum/post', array('topic' => $topic, 'post' => $post, 'user' => $user));
}
?>
开发者ID:anqqa,项目名称:Anqh,代码行数:29,代码来源:topic.php

示例6: _

    ?>
</dd>
		<?php 
}
?>
		<?php 
if (!empty($user->dob) && $user->dob != '0000-00-00') {
    ?>
		<dt><?php 
    echo _('Date of Birth');
    ?>
:</dt><dd><?php 
    echo date::format('DMYYYY', $user->dob);
    ?>
 (<?php 
    echo __(':years years', array(':years' => date::timespan(strtotime($user->dob), null, 'years')));
    ?>
)</dd>
		<?php 
}
?>
		<?php 
if (!empty($user->gender)) {
    ?>
		<dt><?php 
    echo __('Gender');
    ?>
:</dt><dd class="<?php 
    echo $user->gender == 'm' ? 'male' : 'female';
    ?>
"><?php 
开发者ID:anqqa,项目名称:Anqh,代码行数:31,代码来源:info.php


注:本文中的date::timespan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。