function time_distance_in_words($from_timestamp, $to_timestamp, $include_seconds = false) { $distance_in_minutes = round(abs($to_timestamp - $from_timestamp) / 60); $distance_in_seconds = round(abs($to_timestamp - $from_timestamp)); if (in_range(0, 1, $distance_in_minutes)) { if ($include_seconds) { if (in_range(0, 4, $distance_in_seconds)) { return 'less than 5 seconds'; } if (in_range(5, 9, $distance_in_seconds)) { return 'less than 10 seconds'; } if (in_range(10, 19, $distance_in_seconds)) { return 'less than 20 seconds'; } if (in_range(20, 39, $distance_in_seconds)) { return 'half a minute'; } if (in_range(40, 59, $distance_in_seconds)) { return 'less than a minute'; } return '1 minute'; } else { return is_equal($distance_in_minutes, 0) ? 'less than a minute' : '1 minute'; } } if (in_range(2, 44, $distance_in_minutes)) { return "{$distance_in_minutes} minutes"; } if (in_range(45, 89, $distance_in_minutes)) { return 'about 1 hour'; } if (in_range(90, 1439, $distance_in_minutes)) { return 'about ' . round($distance_in_minutes / 60.0) . ' hours'; } if (in_range(1440, 2879, $distance_in_minutes)) { return '1 day'; } if (in_range(2880, 43199, $distance_in_minutes)) { return round($distance_in_minutes / 1440) . ' days'; } if (in_range(43200, 86399, $distance_in_minutes)) { return 'about 1 month'; } if (in_range(86400, 525959, $distance_in_minutes)) { return round($distance_in_minutes / 43200) . ' months'; } if (in_range(525960, 1051919, $distance_in_minutes)) { return 'about 1 year'; } return 'over ' . round($distance_in_minutes / 525960) . ' years'; }
/** * Set a notification value for a notitification type * * @param string $type The type of the notification. * @param mixed $value The value of the notification setting. * @param boolean $send_email Boolean flag to whether email the notifications to the user or not * * @return ComNotificationsDomainEntitySetting */ public function setValue($type, $value, $send_email) { $filter = $this->getService('koowa:filter.cmd'); $type = $filter->sanitize($type); $value = $filter->sanitize($value); settype($send_email, 'boolean'); if (!in_range($type, 0, 2)) { $type = 1; } $send_email = (bool) $send_email; $this->__call('setValue', array($type, array('send_email' => $send_email))); return $this; }
/** * Return whether the response is succesful * * @return boolean */ public function successful() { return in_range($this->getCode(), 200, 299); }
} else { if (isset($_POST['setinterest']) && is_numeric($_POST['setinterest'])) { $thread_interest = $_POST['setinterest']; if (thread_set_interest($tid, $thread_interest)) { header_redirect("messages.php?webtag={$webtag}&msg={$msg}&setinterest=1"); exit; } header_redirect("messages.php?webtag={$webtag}&msg={$msg}&setinterest=0"); exit; } } // Submit Code if (isset($_POST['save'])) { $valid = true; if (isset($_POST['markasread']) && is_numeric($_POST['markasread'])) { if (in_range($_POST['markasread'], 0, $thread_data['LENGTH'])) { $thread_data['LAST_READ'] = $_POST['markasread']; if (!messages_set_read($tid, $thread_data['LAST_READ'], $thread_data['MODIFIED'])) { $error_msg_array[] = gettext("Failed to update thread read status"); $valid = false; } } else { $error_msg_array[] = gettext("Failed to update thread read status"); $valid = false; } } if (isset($_POST['interest']) && is_numeric($_POST['interest'])) { $thread_data['INTEREST'] = $_POST['interest']; if (!thread_set_interest($tid, $thread_data['INTEREST'])) { $error_msg_array[] = gettext("Failed to update thread interest"); $valid = false;
function price_sum_statistic($params) { global $to; if (isset($_REQUEST['debug'])) { debug('function price_sum_statistic', $params); } if (array_key_exists($params['sensor'], $params['prices'])) { $prices = $params['prices'][$params['sensor']]; if (isset($_REQUEST['debug'])) { debug('prices and sensor found', $params['prices']); } } elseif (array_key_exists(400, $params['prices'])) { $prices = $params['prices'][400]; if (isset($_REQUEST['debug'])) { debug('no sensor found. using system prices', $params['prices']); } } $last_date = ''; $sum = $price = $cnt = 0; foreach ($prices as $k => $v) { if ($cnt == 0) { $to = @strtotime(@date('Y-m-d')); if (in_range($k, $to, $params['day'])) { $prices = $prices[$k]; } $to = $k; } else { if (in_range($k, $to, $params['day'])) { $prices = $prices[$k]; } $to = $k; } $cnt++; } foreach ($params['data'] as $k => $v) { $sum += $v; @($price += $v * $prices[$k]); } return array('sum' => round($sum, 3), 'price' => round($price, 2)); }
function process_text($text_in, $openRange, $closingRange) { $text_array = array(); $matches = preg_split("/((Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\\s->\\s)/", $text_in, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); for ($loop = 0; $loop < sizeof($matches); $loop = $loop + 3) { if (preg_match("/^\\d{2}\\/\\d{2}\\/\\d{4}/", $matches[$loop + 2], $elements)) { if (in_range($elements[0], $openRange, $closingRange)) { array_push($text_array, $matches[$loop + 2]); } } } // print_r($text_array); return $text_array; }
return true; } function in_range($number) { global $range_down, $range_up; if ($number < $range_down or $number > $range_up) { return false; } else { return true; } } if (isset($_GET['number'])) { $param = $_GET['number']; //echo $param; if (is_numeric($param)) { if (in_range($param)) { if (is_prime($param)) { echo "The number {$param} is prime !"; } else { echo "<p class=blue> The number {$param} is NOT prime !</p>"; } } else { echo "<p class=red> The parameter is not within the range [{$range_down},{$range_up}]</p>"; } } else { echo "<p class=red> The parameter is not a number</p>"; } } ?> </body> </html>