diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 97c81bd8..5c61fa49 100755 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -112,9 +112,6 @@ class NumericScore implements Extension { //TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats) //TODO: Add Popular_by_week. - $sql = "SELECT * FROM images "; - $args = array(); - //year if(int_escape($event->get_arg(0)) == 0){ $year = date("Y"); @@ -135,40 +132,45 @@ class NumericScore implements Extension { } $totaldate = $year."/".$month."/".$day; + $sql = + "SELECT * FROM images + WHERE EXTRACT(YEAR FROM posted) = :year + "; + + $agrs = array("limit" => $t_images, "year" => $year); + if($event->page_matches("popular_by_day")){ $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND EXTRACT(MONTH FROM posted) = :month + "AND EXTRACT(MONTH FROM posted) = :month AND EXTRACT(DAY FROM posted) = :day AND NOT numeric_score=0 "; + //array_push doesn't seem to like using double arrows + //this requires us to instead create two arrays and merge + $sgra = array("month" => $month, "day" => $day); + $args = array_merge($agrs, $sgra); + $dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day"); } if($event->page_matches("popular_by_month")){ $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND EXTRACT(MONTH FROM posted) = :month + "AND EXTRACT(MONTH FROM posted) = :month AND NOT numeric_score=0 "; + $sgra = array("month" => $month); + $args = array_merge($agrs, $sgra); + $title = date("F Y", (strtotime($totaldate))); $dte = array($totaldate, $title, "Y/m", "month"); } if($event->page_matches("popular_by_year")){ - $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND NOT numeric_score=0 - "; + $sql .= "AND NOT numeric_score=0"; $dte = array($totaldate, $year, "Y", "year"); + $args = $agrs; } $sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0"; //filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score - $args = array( - "year" => $year, - "month" => $month, - "day" => $day, - "limit" => $t_images - ); $result = $database->get_all($sql, $args); $images = array();