/** * Overridden */ function cache_expire() { $filename = $this->cached_page_filename(); if (file_exists($filename) && filemtime($filename) < Time::ago(300)) { $this->expire_cached_page($_REQUEST); } }
/** * Return the timestamp with the user's timezone and his display options. * @param integer $timestamp time in seconds * @param integer $ago_days number of days to display x day(s) ago formating */ public static function date($timestamp, $ago_days = 2) { // Check if $ago_days is null, or if timestamp is more then time - $ago_days. if (!$ago_days or $timestamp > time() - Date::DAY * $ago_days) { return Time::ago($timestamp); } $timestamp += Time::$offset * 3600; return date(Time::$display, $timestamp); }
/** * @fn test_ago * @short Test method for ago. */ public function test_ago() { $this->assertEquals(time() - 3600, Time::ago("hour"), 'Bad timestamp'); $this->assertTrue(Time::ago("hour") < time(), 'Bad timestamp'); $this->assertEquals(time() - 24 * 3600, Time::ago("day"), 'Bad timestamp'); $this->assertTrue(Time::ago("day") < time(), 'Bad timestamp'); $this->assertEquals(time() - 7 * 24 * 3600, Time::ago("week"), 'Bad timestamp'); $this->assertTrue(Time::ago("week") < time(), 'Bad timestamp'); $this->assertEquals(time() - 30 * 24 * 3600, Time::ago("month"), 'Bad timestamp'); $this->assertTrue(Time::ago("month") < time(), 'Bad timestamp'); $this->assertEquals(time(), Time::ago(), 'Bad timestamp'); $this->assertEquals(time(), Time::ago(), 'Bad timestamp'); }
/** * @fn hits_by_host * @short Action method that shows the list of hosts that have visited the website. */ public function hits_by_host() { $conn = Db::get_connection(); $conn->prepare("SELECT `ip_addr`, `params`, COUNT(*) AS `weight` " . "FROM `visits` " . "WHERE `gate` LIKE '%{1}%' " . "AND `date` >= '{2}' " . "AND (`ip_addr` LIKE '%{3}%' " . "OR `params` LIKE '%Apache'' => ''%{3}%') " . "AND `referrer` LIKE '%{4}%' " . "AND `user_agent` LIKE '%{5}%' " . "GROUP BY CONCAT(`ip_addr`, `user_agent`) " . "HAVING `weight` >= '{6}' AND `weight` <= '{7}' " . "ORDER BY `weight` DESC " . "LIMIT {8}", @$_REQUEST['p'], date("Y-m-d H:i:s", Time::ago(@$_REQUEST['t'])), @$_REQUEST['f'], @$_REQUEST['r'], @$_REQUEST['u'], @$_REQUEST['l'], @$_REQUEST['h'], 9999); $conn->exec(); $this->hosts = array(); if ($conn->num_rows() > 0) { while ($line = $conn->fetch_assoc()) { $host = Geoip::by_ip_addr($line['ip_addr'], $line['params']); $host->weight = $line['weight']; $this->hosts[] = $host; } } Db::close_connection($conn); }
/** * @fn attribute_visits * @short Action method to attribute a visit to a person. * @details This method is designed to be called with AJAX, and does not render anything. * It assigns a visit object to a person object. */ public function attribute_visits() { $conn = Db::get_connection(); $visit_factory = new Visit(); $visits = $visit_factory->find_all(array('where_clause' => "`date` >= '{$conn->escape(date("Y-m-d H:i:s", Time::ago(@$_REQUEST['t'])))}' " . "AND (`ip_addr` = '{$conn->escape(@$_REQUEST['ip'])}' " . "OR `params` LIKE '%Apache'' => ''{$conn->escape(@$_REQUEST['ip'])}%')")); if (count($visits) > 0) { foreach ($visits as $visit) { $visit->person_id = @$_REQUEST['person_id']; $visit->save(); } } Db::close_connection($conn); $this->render(NULL); }
/** * @return array */ public static function yiiVersions() { $_versions = array(); $p = VENDOR_PATH . DS . 'yii'; $d = dir($p); while (false !== ($entry = $d->read())) { if (substr($entry, 0, 4) == 'yii-') { $time = filemtime($p . DS . $entry); $_versions[$time] = array('entry' => $entry, 'display' => $entry . ' -- ' . date(self::item('dateTimeFormat'), $time) . ' -- (' . Time::ago($time) . ')'); } } $d->close(); krsort($_versions); $versions = array(); foreach ($_versions as $version) { $versions[$version['entry']] = $version['display']; } return $versions; }
* @author Brett O'Donnell <*****@*****.**> * @author Zain Ul abidin <*****@*****.**> * @copyright 2013 Mr PHP * @link https://github.com/cornernote/yii-audit-module * @license BSD-3-Clause https://raw.github.com/cornernote/yii-audit-module/master/LICENSE * * @package yii-audit-module */ echo '<tr>'; echo '<td>'; echo isset($data->old_value) ? $data->old_value : ' '; echo isset($data->old_value) && isset($data->new_value) ? ' > ' : ''; echo isset($data->new_value) ? $data->new_value : ' '; echo '</td>'; echo '<td>'; echo Time::ago($data->created); echo '</td>'; echo '<td>'; echo '<small>' . $data->created . '</small>'; echo '</td>'; echo '<td>'; if (Yii::app()->user->checkAccess('admin')) { echo $data->user_id && is_numeric($data->user_id) ? User::model()->findByPk($data->user_id)->getLink() : $data->user_id; } else { echo $data->user_id && is_numeric($data->user_id) ? User::model()->findByPk($data->user_id)->name : $data->user_id; } echo '</td>'; if (Yii::app()->user->checkAccess('admin')) { echo '<td>'; echo $data->audit ? $data->audit->getLink() : ''; echo '</td>';