function testWhiteList() { $r = new Rule_WhiteList(array('-1', '0', '42')); $this->assertTrue($r->isValid('-1')); $this->assertTrue($r->isValid('0')); $this->assertTrue($r->isValid('42')); $this->assertFalse($r->isValid('1')); $this->assertFalse($r->isValid('100')); $this->assertFalse($r->isValid('toto')); }
function stats_site_projects($span = 7, $orderby = "ranking", $offset = 0, $projects = 0, $trove_cat = 0) { global $Language; $sql = "SELECT s.month AS month, s.week AS week, s.day AS day, s.group_id AS group_id, " . "g.group_name AS group_name, m.ranking AS ranking, m.percentile AS percentile, SUM(s.downloads) AS downloads, " . "SUM(s.site_views) AS site_views, SUM(s.subdomain_views) AS subdomain_views, " . "SUM(s.msg_posted) AS msg_posted, SUM(s.bugs_opened) AS bugs_opened, " . "SUM(s.bugs_closed) AS bugs_closed, SUM(s.support_opened) AS support_opened, " . "SUM(s.support_closed) AS support_closed, SUM(s.patches_opened) AS patches_opened, " . "SUM(s.patches_closed) AS patches_closed, SUM(s.tasks_opened) AS tasks_opened, " . "SUM(s.tasks_closed) AS tasks_closed, SUM(s.cvs_checkouts) AS cvs_checkouts, " . "SUM(s.cvs_commits) AS cvs_commits, SUM(s.cvs_adds) AS cvs_adds, " . "SUM(s.svn_access_count) AS svn_access_count " . "FROM stats_project AS s,groups AS g,project_metric AS m "; // Get information about the date $span days ago $begin_date = localtime(time() - $span * 86400, 1); $year = $begin_date["tm_year"] + 1900; $month = sprintf("%02d", $begin_date["tm_mon"] + 1); $day = $begin_date["tm_mday"]; $sql .= "WHERE ( "; if ($span != "All") { $sql .= "( ( month = " . $year . $month . " AND day >= " . $day . " ) OR ( month > " . $year . $month . " ) ) "; } $sql .= "AND ( s.group_id = g.group_id ) "; $sql .= "AND ( s.group_id = m.group_id ) "; if (is_array($projects)) { $sql .= "AND ( s.group_id IN (" . db_ei_implode($projects) . ") ) "; } else { $sql .= "AND g.type = 1 "; } $sql .= " ) "; $sql .= "GROUP BY s.group_id "; $valid_orderby_value = new Rule_WhiteList(stats_site_projects_orderby_values()); if (!$valid_orderby_value->isValid($orderby)) { $orderby = 'ranking'; } if ($orderby == "ranking") { $sql .= "ORDER BY {$orderby} ASC "; } else { $sql .= "ORDER BY {$orderby} DESC "; } if ($offset > 0) { $sql .= "LIMIT " . db_ei($offset) . ",50"; } else { $sql .= "LIMIT 50"; } // Executions will continue until morale improves. $res = db_query($sql); // if there are any rows, we have valid data (or close enough). if (($valid_days = db_numrows($res)) > 1) { $purifier = Codendi_HTMLPurifier::instance(); print "<P><B>" . $Language->getText('stats_site_stats_utils', 'proj_stats_for') . " "; if ($span == $Language->getText('stats_site_stats_utils', 'all')) { print $Language->getText('stats_site_stats_utils', 'all_time'); } else { print $Language->getText('stats_site_stats_utils', 'past_x_days', $purifier->purify($span)); } print " " . $Language->getText('stats_site_stats_utils', 'sorted_by', $purifier->purify($orderby)); if ($trove_cat > 0) { print " " . $Language->getText('stats_site_stats_utils', 'within_cat', $purifier->purify(stats_trove_cat_to_name($trove_cat))); } if (is_array($projects) && $trove_cat <= 0) { print "<br> " . $Language->getText('stats_site_stats_utils', 'for_group', $purifier->purify(implode(", ", $projects))); } print ". </B></P><BR>"; print '<P><TABLE width="100%" cellpadding=0 cellspacing=0 border=0>'; print '<TR valign="top" class="boxitem">' . '<TD><B>' . $Language->getText('stats_site_stats_utils', 'proj_name') . '</B></TD>' . '<TD align="right"><B>' . $Language->getText('stats_site_stats_utils', 'ranking') . '</B></TD>' . '<TD align="right" COLSPAN="2"><B>' . $Language->getText('stats_site_stats_utils', 'page_views') . '</B></TD>' . '<TD align="right"><B>' . $Language->getText('stats_site_stats_utils', 'downl') . '</B></TD>' . '<TD align="center" COLSPAN="2"><B>' . $Language->getText('stats_site_stats_utils', 'bugs') . '</B></TD>' . '<TD align="center" COLSPAN="2"><B>' . $Language->getText('stats_site_stats_utils', 'support') . '</B></TD>' . '<TD align="center" COLSPAN="2"><B>' . $Language->getText('stats_site_stats_utils', 'patches') . '</B></TD>' . '<TD align="center" COLSPAN="2"><B>' . $Language->getText('stats_site_stats_utils', 'tasks') . '</B></TD>' . '<TD align="center" COLSPAN="3"><B>' . $Language->getText('stats_site_stats_utils', 'cvs') . '</B></TD>' . '<TD align="center" COLSPAN="3"><B>' . $Language->getText('stats_site_stats_utils', 'svn') . '</B></TD>' . '</TR>' . "\n"; // Build the query string to resort results. $uri_string = "projects.php?span=" . urlencode($span); if ($trove_cat > 0) { $uri_string .= "&trovecatid=" . urlencode($trove_cat); } if ($trove_cat == -1) { $uri_string .= "&projects=" . urlencode(implode(" ", $projects)); } $uri_string .= "&orderby="; print '<TR valign="top" class="boxitem">' . '<TD align="right"> </TD>' . '<TD align="right"><A HREF="' . $uri_string . 'ranking">' . $Language->getText('stats_site_stats_utils', 'rank') . '</A></TD>' . '<TD align="right"><A HREF="' . $uri_string . 'site_views">' . $Language->getText('stats_site_stats_utils', 'site') . '</A></TD>' . '<TD align="right"><A HREF="' . $uri_string . 'subdomain_views">' . $Language->getText('stats_site_stats_utils', 'subdomain') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'downloads">' . $Language->getText('stats_site_stats_utils', 'total') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'bugs_opened">' . $Language->getText('stats_site_stats_utils', 'opn') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'bugs_closed">' . $Language->getText('stats_site_stats_utils', 'cls') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'support_opened">' . $Language->getText('stats_site_stats_utils', 'opn') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'support_closed">' . $Language->getText('stats_site_stats_utils', 'cls') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'patches_opened">' . $Language->getText('stats_site_stats_utils', 'opn') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'patches_closed">' . $Language->getText('stats_site_stats_utils', 'cls') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'tasks_opened">' . $Language->getText('stats_site_stats_utils', 'opn') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'tasks_closed">' . $Language->getText('stats_site_stats_utils', 'cls') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'cvs_checkouts">' . $Language->getText('stats_site_stats_utils', 'co') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'cvs_commits">' . $Language->getText('stats_site_stats_utils', 'comms') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'cvs_adds">' . $Language->getText('stats_site_stats_utils', 'adds') . '</TD>' . '<TD align="right"><A HREF="' . $uri_string . 'svn_access_count">' . $Language->getText('stats_site_stats_utils', 'access_cnt') . '</TD>' . '</TR>' . "\n"; $i = $offset; $sum = array(); while ($row = db_fetch_array($res)) { print '<TR class="' . util_get_alt_row_color($i) . '">' . '<TD>' . ($i + 1) . '. <A HREF="/project/stats/?group_id=' . $row["group_id"] . '">' . $row["group_name"] . '</A></TD>' . '<TD align="right"> ' . number_format($i + 1) . ' (' . $row["percentile"] . '%) </TD>' . '<TD align="right"> ' . number_format($row["site_views"]) . '</TD>' . '<TD align="right"> ' . number_format($row["subdomain_views"]) . '</TD>' . '<TD align="right"> ' . number_format($row["downloads"]) . '</TD>' . '<TD align="right"> ' . number_format($row["bugs_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($row["bugs_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($row["support_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($row["support_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($row["patches_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($row["patches_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($row["tasks_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($row["tasks_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($row["cvs_checkouts"]) . '</TD>' . '<TD align="right"> ' . number_format($row["cvs_commits"]) . '</TD>' . '<TD align="right"> ' . number_format($row["cvs_adds"]) . '</TD>' . '<TD align="right"> ' . number_format($row["svn_access_count"]) . '</TD>' . '</TR>' . "\n"; $i++; $sum = stats_util_sum_array($sum, $row); } if ($trove_cat == -1) { print '<TR><TD COLSPAN="16"> </TD></TR>' . "\n"; print '<TR><TD COLSPAN="16" align="center"></TD></TR>' . "\n"; print '<TR class="' . util_get_alt_row_color($i) . '">' . '<TD><B>' . $Language->getText('stats_site_stats_utils', 'totals') . '</B></TD>' . '<TD> </TD>' . '<TD align="right"> ' . number_format($sum["site_views"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["subdomain_views"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["downloads"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["bugs_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["bugs_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["support_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["support_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["patches_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["patches_closed"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["tasks_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["tasks_opened"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["cvs_checkouts"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["cvs_commits"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["cvs_adds"]) . '</TD>' . '<TD align="right"> ' . number_format($sum["svn_access_count"]) . '</TD>' . '</TR>' . "\n"; } print '</TABLE>'; } else { echo $Language->getText('stats_site_stats_utils', 'no_valid_data') . "\n"; } }
private function getComparatorFromRequestParameter(array $param) { $rule = new Rule_WhiteList(Tracker_Rule_Date::$allowed_comparators); if (isset($param[self::PARAMETER_COMPARATOR]) && $rule->isValid($param[self::PARAMETER_COMPARATOR])) { return $param[self::PARAMETER_COMPARATOR]; } }