public static function boundVector($arr, $min, $max, $type = 'fit') { foreach ($arr as &$item) { $item = bound($item, $min, $max, $type); } return $arr; }
public function fromLatLngToPoint($latLng, $opt_point = null) { $me = $this; $point = $opt_point ? $opt_point : new G_Point(0, 0); $origin = $me->pixelOrigin_; $point->x = $origin->x + $latLng->lng * $me->pixelsPerLonDegree_; // NOTE(appleton): Truncating to 0.9999 effectively limits latitude to // 89.189. This is about a third of a tile past the edge of the world tile. $siny = bound(sin(degreesToRadians($latLng->lat)), -0.9999, 0.9999); $point->y = $origin->y + 0.5 * log((1 + $siny) / (1 - $siny)) * -$me->pixelsPerLonRadian_; return $point; }
function bloodloss_quotient() { $diag = $_SESSION['diag']; $blood = $_SESSION['blood']; if ($diag['temp'] <= 36.6) { $qt = 1; } else { $qt = exp(-($diag['temp'] - 36.6) / 13); } $AD = bound($diag['AD'], 60, 160, 'fit'); $qAD = $AD / 120; $qp = $diag['pulse'] / 60; $qbl = 1 / ((5000 - $blood['left']) / 1000 + 1); return $qAD * $qp * $qt * $qbl; }
function draw_grid_labels($image, $mapradius, $drawradius) { global $zz, $zx, $zy, $cx, $cy, $imagestring, $mgrey; if ($zz >= 10) { $inc = 10; } else { if ($zz <= 0.75) { $inc = 100; } else { $inc = 50; } } $x = bound(-$zx * $zz, -$drawradius, $drawradius - 25); $y = bound($zy * $zz, -$drawradius, $drawradius - 10); for ($v = -$mapradius; $v <= $mapradius; $v += $inc) { $imagestring($image, 3, $cx + $x + 2, $cy - ($v - $zy) * $zz + 1, $v, $mgrey); $imagestring($image, 3, $cx + ($v - $zx) * $zz + 2, $cy + $y + 1, $v, $mgrey); } }
function pkg_search_page($SID = "") { $dbh = DB::connect(); /* * Get commonly used variables. * TODO: Reduce the number of database queries! */ if ($SID) { $myuid = uid_from_sid($SID); } /* Sanitize paging variables. */ if (isset($_GET['O'])) { $_GET['O'] = max(intval($_GET['O']), 0); } else { $_GET['O'] = 0; } if (isset($_GET["PP"])) { $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250); } else { $_GET["PP"] = 50; } /* * FIXME: Pull out DB-related code. All of it! This one's worth a * choco-chip cookie, one of those nice big soft ones. */ /* Build the package search query. */ $q_select = "SELECT "; if ($SID) { $q_select .= "CommentNotify.UserID AS Notify,\n\t\t\t PackageVotes.UsersID AS Voted, "; } $q_select .= "Users.Username AS Maintainer,\n\tPackages.Name, Packages.Version, Packages.Description,\n\tPackageBases.NumVotes, PackageBases.Popularity, Packages.ID,\n\tPackages.PackageBaseID, PackageBases.OutOfDateTS "; $q_from = "FROM Packages\n\tLEFT JOIN PackageBases ON (PackageBases.ID = Packages.PackageBaseID)\n\tLEFT JOIN Users ON (PackageBases.MaintainerUID = Users.ID) "; if ($SID) { /* This is not needed for the total row count query. */ $q_from_extra = "LEFT JOIN PackageVotes\n\t\tON (PackageBases.ID = PackageVotes.PackageBaseID AND PackageVotes.UsersID = {$myuid})\n\t\tLEFT JOIN CommentNotify\n\t\tON (PackageBases.ID = CommentNotify.PackageBaseID AND CommentNotify.UserID = {$myuid}) "; } else { $q_from_extra = ""; } $q_where = 'WHERE PackageBases.PackagerUID IS NOT NULL '; if (isset($_GET['K'])) { if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") { /* Search by maintainer. */ $q_where .= "AND Users.Username = "******" "; } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") { /* Search by submitter. */ $q_where .= "AND SubmitterUID = " . intval(uid_from_username($_GET['K'])) . " "; } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") { /* Search by name. */ $K = "%" . addcslashes($_GET['K'], '%_') . "%"; $q_where .= "AND (Packages.Name LIKE " . $dbh->quote($K) . ") "; } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "b") { /* Search by package base name. */ $K = "%" . addcslashes($_GET['K'], '%_') . "%"; $q_where .= "AND (PackageBases.Name LIKE " . $dbh->quote($K) . ") "; } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "k") { /* Search by keywords. */ $q_where .= construct_keyword_search($dbh, false); } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "N") { /* Search by name (exact match). */ $q_where .= "AND (Packages.Name = " . $dbh->quote($_GET['K']) . ") "; } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "B") { /* Search by package base name (exact match). */ $q_where .= "AND (PackageBases.Name = " . $dbh->quote($_GET['K']) . ") "; } else { /* Keyword search (default). */ $q_where .= construct_keyword_search($dbh, true); } } if (isset($_GET["do_Orphans"])) { $q_where .= "AND MaintainerUID IS NULL "; } if (isset($_GET['outdated'])) { if ($_GET['outdated'] == 'on') { $q_where .= "AND OutOfDateTS IS NOT NULL "; } elseif ($_GET['outdated'] == 'off') { $q_where .= "AND OutOfDateTS IS NULL "; } } $order = isset($_GET["SO"]) && $_GET["SO"] == 'd' ? 'DESC' : 'ASC'; $q_sort = "ORDER BY "; $sort_by = isset($_GET["SB"]) ? $_GET["SB"] : ''; switch ($sort_by) { case 'v': $q_sort .= "NumVotes " . $order . ", "; break; case 'p': $q_sort .= "Popularity " . $order . ", "; break; case 'w': if ($SID) { $q_sort .= "Voted " . $order . ", "; } break; case 'o': if ($SID) { $q_sort .= "Notify " . $order . ", "; } break; case 'm': $q_sort .= "Maintainer " . $order . ", "; break; case 'l': $q_sort .= "ModifiedTS " . $order . ", "; break; case 'a': /* For compatibility with old search links. */ $q_sort .= "-ModifiedTS " . $order . ", "; break; default: break; } $q_sort .= " Packages.Name " . $order . " "; $q_limit = "LIMIT " . $_GET["PP"] . " OFFSET " . $_GET["O"]; $q = $q_select . $q_from . $q_from_extra . $q_where . $q_sort . $q_limit; $q_total = "SELECT COUNT(*) " . $q_from . $q_where; $result = $dbh->query($q); $result_t = $dbh->query($q_total); if ($result_t) { $row = $result_t->fetch(PDO::FETCH_NUM); $total = $row[0]; } else { $total = 0; } if ($result && $total > 0) { if (isset($_GET["SO"]) && $_GET["SO"] == "d") { $SO_next = "a"; } else { $SO_next = "d"; } } /* Calculate the results to use. */ $first = $_GET['O'] + 1; /* Calculation of pagination links. */ $per_page = $_GET['PP'] > 0 ? $_GET['PP'] : 50; $current = ceil($first / $per_page); $pages = ceil($total / $per_page); $templ_pages = array(); if ($current > 1) { $templ_pages['« ' . __('First')] = 0; $templ_pages['‹ ' . __('Previous')] = ($current - 2) * $per_page; } if ($current - 5 > 1) { $templ_pages["..."] = false; } for ($i = max($current - 5, 1); $i <= min($pages, $current + 5); $i++) { $templ_pages[$i] = ($i - 1) * $per_page; } if ($current + 5 < $pages) { $templ_pages["... "] = false; } if ($current < $pages) { $templ_pages[__('Next') . ' ›'] = $current * $per_page; $templ_pages[__('Last') . ' »'] = ($pages - 1) * $per_page; } include 'pkg_search_form.php'; $searchresults = array(); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $searchresults[] = $row; } } include 'pkg_search_results.php'; return; }
html_header(__("Close Request")); $pkgbase_name = pkgreq_get_pkgbase_name($pkgreq_id); include 'pkgreq_close_form.php'; } else { if (!has_credential(CRED_PKGREQ_LIST)) { header('Location: /'); exit; } /* Sanitize paging variables. */ if (isset($_GET['O'])) { $_GET['O'] = max(intval($_GET['O']), 0); } else { $_GET['O'] = 0; } if (isset($_GET["PP"])) { $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250); } else { $_GET["PP"] = 50; } $results = pkgreq_list($_GET['O'], $_GET['PP']); $total = pkgreq_count(); /* Calculate the results to use. */ $first = $_GET['O'] + 1; /* Calculation of pagination links. */ $per_page = $_GET['PP'] > 0 ? $_GET['PP'] : 50; $current = ceil($first / $per_page); $pages = ceil($total / $per_page); $templ_pages = array(); if ($current > 1) { $templ_pages['« ' . __('First')] = 0; $templ_pages['‹ ' . __('Previous')] = ($current - 2) * $per_page;