Exemple #1
0
function human_diff($date)
{
    if (empty($date)) {
        return;
    }
    // Initialize
    $human = '';
    // Get time increments
    $t = seconds();
    // What difference does it make
    $diff = (int) abs(current_time('timestamp') - $date);
    // Get down to business
    switch ($diff) {
        case $diff < $t['hour']:
            $minutes = round($diff / $t['minute']);
            if ($minutes <= 1) {
                $minutes = 1;
            }
            $human = apply_filters('ubik_time_human_diff_minutes', sprintf(esc_html(_n('%d minute ago', '%d minutes ago', $minutes, 'ubik')), $minutes), $minutes, $diff);
            break;
        case $diff < $t['day']:
            $hours = round($diff / $t['hour']);
            if ($hours <= 1) {
                $hours = 1;
            }
            $human = apply_filters('ubik_time_human_diff_hours', sprintf(esc_html(_n('%d hour ago', '%d hours ago', $hours, 'ubik')), $hours), $hours, $diff);
            break;
        case $diff < $t['week']:
            $days = round($diff / $t['day']);
            if ($days <= 1) {
                $days = 1;
            }
            $human = apply_filters('ubik_time_human_diff_days', sprintf(esc_html(_n('%d day ago', '%d days ago', $days, 'ubik')), $days), $days, $diff);
            break;
        case $diff < $t['month']:
            $weeks = round($diff / $t['week']);
            if ($weeks <= 1) {
                $weeks = 1;
            }
            $human = apply_filters('ubik_time_human_diff_weeks', sprintf(esc_html(_n('%d week ago', '%d weeks ago', $weeks, 'ubik')), $weeks), $weeks, $diff);
            break;
        case $diff < $t['year']:
            $months = round($diff / $t['month']);
            if ($months <= 1) {
                $months = 1;
            }
            $human = apply_filters('ubik_time_human_diff_months', sprintf(esc_html(_n('%d month ago', '%d months ago', $months, 'ubik')), $months), $months, $diff);
            break;
        default:
            $years = round($diff / $t['year']);
            if ($years <= 1) {
                $years = 1;
            }
            $human = apply_filters('ubik_time_human_diff_years', sprintf(esc_html(_n('%d year ago', '%d years ago', $years, 'ubik')), $years), $years, $diff);
            break;
    }
    return apply_filters('ubik_time_human_diff', $human, $date);
}
 public function testFormatShort()
 {
     $this->assertEquals('4ms', milliseconds(4)->format('ms'));
     $this->assertEquals('1s', milliseconds(1000)->format('s'));
     $this->assertEquals('4s', seconds(4)->format('s'));
     $this->assertEquals('4m', minutes(4)->format('m'));
     $this->assertEquals('32h', hours(32)->format('h'));
     $this->assertEquals('4d', days(4)->format('d'));
     $this->assertEquals('1w', days(7)->format('w'));
     $this->assertEquals('3mo', weeks(13)->format('mo'));
     $this->assertEquals('1y', months(12)->format('y'));
 }
Exemple #3
0
 public function driftForwardBySeconds($seconds)
 {
     $this->now = $this->now->after(seconds($seconds));
 }
Exemple #4
0
function fromDateInterval(\DateInterval $interval)
{
    $seconds = (string) $interval->s;
    if ($interval->i) {
        $seconds = bcadd($seconds, bcmul($interval->i, 60));
    }
    if ($interval->h) {
        $seconds = bcadd($seconds, bcmul($interval->h, 3600));
    }
    if ($interval->d) {
        $seconds = bcadd($seconds, bcmul($interval->d, 86400));
    }
    if ($interval->m) {
        $seconds = bcadd($seconds, bcmul($interval->m, 2629740));
    }
    if ($interval->y) {
        $seconds = bcadd($seconds, bcmul($interval->y, 31556874));
    }
    return seconds($seconds);
}
Exemple #5
0
function getTable($caption, $thead, $tFoot, $total, $comments = FALSE, $app = FALSE)
{
    $colspan = count($thead);
    $HTML = '	<table id="results" class="results">
					<caption class="caption">
						<span class="bold">' . $caption . '</span>
					</caption>
					
					<thead>
						<tr>';
    for ($i = 0; $i <= count($thead) - 1; $i++) {
        $HTML .= '<th>' . $thead[$i] . '</th>';
    }
    $HTML .= '			</tr>
					</thead>
					
					<tfoot>
						<tr>
							<td colspan="' . $colspan . '">
								<span class="bold">' . __(_("Total")) . ':</span> ' . $total . '
							</td>
						</tr>
					</tfoot>		  
		
					<tbody>';
    if ($tFoot) {
        foreach ($tFoot as $column) {
            $HTML .= '<tr style="background-color: ' . $column["i"] . '">';
            if (isset($column["checkbox"])) {
                $HTML .= '<td class="center">' . $column["checkbox"] . '</td>';
            }
            if (isset($column["ID"])) {
                $HTML .= '<td class="center">' . $column["ID"] . '</td>';
            }
            if (isset($column["Username"])) {
                $HTML .= '<td class="center">' . $column["Username"] . '</td>';
            }
            if (isset($column["Question"])) {
                $HTML .= '<td class="center">' . $column["Question"] . '</td>';
            }
            if (isset($column["Name"])) {
                $HTML .= '<td>' . $column["Name"] . '</td>';
            }
            if (isset($column["Email"])) {
                $HTML .= '<td class="center">' . $column["Email"] . '</td>';
            }
            if (isset($column["Company"])) {
                $HTML .= '<td class="center">' . $column["Company"] . '</td>';
            }
            if (isset($column["Country"])) {
                $HTML .= '<td class="center">' . $column["Country"] . '</td>';
            }
            if (isset($column["District"])) {
                $HTML .= '<td class="center">' . $column["District"] . '</td>';
            }
            if (isset($column["Subject"])) {
                $HTML .= '<td>' . $column["Subject"] . '</td>';
            }
            if (isset($column["Small"])) {
                $HTML .= '<td class="center"><img src="' . $column["Small"] . '" /></td>';
            }
            if (isset($column["Title"])) {
                $title = cut($column["Title"], 4, "text");
                $HTML .= '<td>' . $title . '</td>';
            }
            if (isset($column["Application"])) {
                $HTML .= '<td>' . $column["Application"] . '</td>';
            }
            if (isset($column["Controller"])) {
                $HTML .= '<td class="center">' . __(_($column["Controller"])) . '</td>';
            }
            if (isset($column["Model"])) {
                $HTML .= '<td class="center">' . __(_($column["Model"])) . '</td>';
            }
            if (isset($column["CPanel"])) {
                $HTML .= '<td class="center">' . __(_($column["CPanel"])) . '</td>';
            }
            if (isset($column["Adding"])) {
                $HTML .= '<td class="center">' . __(_($column["Adding"])) . '</td>';
            }
            if (isset($column["Author"])) {
                $HTML .= '<td class="center">' . $column["Author"] . '</td>';
            }
            if (isset($column["Sponsor"])) {
                $HTML .= '<td>' . $column["Sponsor"] . '</td>';
            }
            if (isset($column["URL"])) {
                $HTML .= '<td class="center">
											<a rel="external" title="' . $column["Title"] . '" href="' . $column["URL"] . '">' . cut($column["URL"], 35, "word") . '</a>
										  </td>';
                $HTML .= '<td class="center">' . __($column["Category"]) . '</td>';
            }
            if (isset($column["Clicks"])) {
                $HTML .= '<td class="center">' . $column["Clicks"] . '</td>';
            }
            if (isset($column["Size"])) {
                $HTML .= '<td class="center">' . $column["Size"] . '</td>';
            }
            if (isset($column["Email_From"])) {
                $HTML .= '<td class="center">' . $column["Email_From"] . '</td>';
            }
            if (isset($column["Text_Date"])) {
                $HTML .= '<td class="center">' . $column["Text_Date"] . '</td>';
            }
            if (isset($column["Website"])) {
                $HTML .= '<td class="center">' . $column["Website"] . '</td>';
            }
            if (isset($column["BeDefault"])) {
                $HTML .= '<td class="center">' . __($column["BeDefault"]) . '</td>';
                $HTML .= '<td class="center">' . __($column["Category"]) . '</td>';
            }
            if (isset($column["Comments"])) {
                $HTML .= '<td class="center">' . __($column["Comments"]) . '</td>';
            }
            if (isset($column["Subscribed"])) {
                $HTML .= '<td class="center">' . __($column["Subscribed"]) . '</td>';
            }
            if (isset($column["Position"])) {
                $HTML .= '<td class="center">' . __($column["Position"]) . '</td>';
            }
            if (isset($column["Image"])) {
                $HTML .= '<td class="center">' . $column["Album"] . '</td>';
                $HTML .= '
										<td class="center">
											<a href="' . $column["Image"] . '" title="Banner" class="image-lightbox">
												' . __(_("Preview")) . '
											</a>
										</td>';
            }
            if (isset($column["Preview"])) {
                $HTML .= '
										<td class="center">
											<a href="' . $column["Preview"] . '" title="Banner" class="work-lightbox">
												' . __(_("Preview")) . '
											</a>
										</td>';
                $HTML .= '
										<td class="center">
											<a href="' . $column["Preview1"] . '" title="Banner" class="work-lightbox">
												' . __(_("Preview")) . '
											</a>
										</td>';
                $HTML .= '
										<td class="center">
											<a href="' . $column["Preview2"] . '" title="Banner" class="work-lightbox">
												' . __(_("Preview")) . '
											</a>
										</td>';
            }
            if (isset($column["Views"])) {
                $HTML .= '<td class="center">' . $column["Views"] . '</td>';
            }
            if (isset($column["Language"])) {
                $HTML .= '<td class="center">' . getLanguage($column["Language"], TRUE) . '</td>';
            }
            if (isset($column["Banner"])) {
                if ($column["Banner"] !== "") {
                    $HTML .= '
											<td class="center">
												<a href="' . path($column["Banner"], TRUE) . '" title="Banner" class="banner-lightbox">
													' . __(_("Preview")) . '
												</a>
											</td>';
                } else {
                    $HTML .= '
											<td class="center">
												' . __(_("Preview")) . '
											</td>';
                }
            }
            if (isset($column["Principal"])) {
                if ($column["Principal"]) {
                    $HTML .= '<td class="center">' . __(_("Yes")) . '</td>';
                } else {
                    $HTML .= '<td class="center">' . __(_("No")) . '</td>';
                }
            }
            if (isset($column["Description"])) {
                $HTML .= '<td class="center">' . $column["Description"] . '</td>';
            }
            if (isset($column["Follow"])) {
                $HTML .= '<td class="center">' . __(_($column["Follow"])) . '</td>';
            }
            if (isset($column["Time"])) {
                $HTML .= '<td class="center">' . seconds($column["Time"]) . '</td>';
            }
            if (isset($column["Privilege"])) {
                $HTML .= '<td class="center">' . $column["Privilege"] . '</td>';
            }
            if (isset($column["Type"])) {
                $HTML .= '<td class="center">' . __(_($column["Type"])) . '</td>';
            }
            if (isset($column["Topics"])) {
                $HTML .= '<td class="center">' . __(_($column["Topics"])) . '</td>';
            }
            if (isset($column["Replies"])) {
                $HTML .= '<td class="center">' . __(_($column["Replies"])) . '</td>';
            }
            if (isset($column["ID_YouTube"])) {
                $HTML .= '
								<td class="center">
									<a href="http://www.youtube.com/watch?v=' . $column["ID_YouTube"] . '" class="video-lightbox" title="' . $title . '">
										' . __(_("Preview")) . '
									</a>
								</td>';
            }
            if (isset($column["Situation"])) {
                $HTML .= '<td class="center">' . __(_($column["Situation"])) . '</td>';
            }
            if (isset($column["Action"])) {
                $HTML .= '<td class="center">' . $column["Action"] . '</td>';
            }
        }
    }
    $HTML .= ' 						</tr>                     
					</tbody>            
				</table>
		
				<div class="table-options" style="position: relative; z-index: 1; margin-bottom: 25px;">
					' . __(_("Select")) . ': <br />
					<a onclick="checkAll(\'records\')" class="pointer" title="' . __(_("All")) . '">' . __(_("All")) . '</a> |
					<a onclick="unCheckAll(\'records\')" class="pointer" title="' . __(_("None")) . '">' . __(_("None")) . '</a><br /><br />';
    if (segment(3, isLang()) === "trash") {
        $HTML .= '	<input class="btn btn-success" onclick="javascript:return confirm(\'' . __(_("Do you want to restore the records?")) . '\')" name="restore" value="' . __(_("Restore")) . '" type="submit" class="small-input" />
									<input class="btn btn-danger" onclick="javascript:return confirm(\'' . __(_("Do you want to delete the records?")) . '\')" name="delete" value="' . __(_("Delete")) . '" type="submit" class="small-input" />';
    } elseif ($comments) {
        $HTML .= ' <input class="btn btn-danger" onclick="javascript:return confirm(\'' . __(_("Do you want to delete the comments?")) . '\')" name="deleteComments" value="' . __(_("Delete")) . '" type="submit" class="small-input" />';
    } else {
        $HTML .= '	<input class="btn btn-warning" onclick="javascript:return confirm(\'' . __(_("Do you want to send to trash the records?")) . '\')" name="trash" value="' . __(_("Send to trash")) . '" type="submit" class="small-input" />';
    }
    $HTML .= '	</div>';
    return $HTML;
}