Merge branch 'develop' of git://github.com/shish/shimmie2
This commit is contained in:
@ -63,7 +63,7 @@ class NumericScore extends Extension {
|
||||
}
|
||||
die($html);
|
||||
}
|
||||
if($event->page_matches("numeric_score_vote") && $user->check_auth_token()) {
|
||||
else if($event->page_matches("numeric_score_vote") && $user->check_auth_token()) {
|
||||
if(!$user->is_anonymous()) {
|
||||
$image_id = int_escape($_POST['image_id']);
|
||||
$char = $_POST['vote'];
|
||||
@ -76,7 +76,7 @@ class NumericScore extends Extension {
|
||||
$page->set_redirect(make_link("post/view/$image_id"));
|
||||
}
|
||||
}
|
||||
if($event->page_matches("numeric_score/remove_votes_on") && $user->check_auth_token()) {
|
||||
else if($event->page_matches("numeric_score/remove_votes_on") && $user->check_auth_token()) {
|
||||
if($user->can("edit_other_vote")) {
|
||||
$image_id = int_escape($_POST['image_id']);
|
||||
$database->execute(
|
||||
@ -89,83 +89,62 @@ class NumericScore extends Extension {
|
||||
$page->set_redirect(make_link("post/view/$image_id"));
|
||||
}
|
||||
}
|
||||
if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) {
|
||||
else if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) {
|
||||
if($user->can("edit_other_vote")) {
|
||||
$this->delete_votes_by(int_escape($_POST['user_id']));
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link());
|
||||
}
|
||||
}
|
||||
if($event->page_matches("popular_by_day") || $event->page_matches("popular_by_month") || $event->page_matches("popular_by_year")) {
|
||||
$t_images = $config->get_int("index_images");
|
||||
else if($event->page_matches("popular_by_day") || $event->page_matches("popular_by_month") || $event->page_matches("popular_by_year")) {
|
||||
//FIXME: popular_by isn't linked from anywhere
|
||||
list($day, $month, $year) = array(date("d"), date("m"), date("Y"));
|
||||
|
||||
//TODO: Add Popular_by_week.
|
||||
if(!empty($_GET['day'])){
|
||||
$D = (int) $_GET['day'];
|
||||
if($D >= 1 && $D <= 31) $day = $D;
|
||||
}
|
||||
if(!empty($_GET['month'])){
|
||||
$M = (int) $_GET['month'];
|
||||
if($M >= 1 && $M <= 12) $month = $M;
|
||||
}
|
||||
if(!empty($_GET['year'])){
|
||||
$Y = (int) $_GET['year'];
|
||||
if($Y >= 1970 && $Y < 2100) $year = $Y;
|
||||
}
|
||||
|
||||
//year
|
||||
if(empty($_GET['year'])){
|
||||
$year = date("Y");
|
||||
}else{
|
||||
$year = $_GET['year'];
|
||||
}
|
||||
//month
|
||||
if(empty($_GET['month']) || int_escape($_GET['month']) > 12){
|
||||
$month = date("m");
|
||||
}else{
|
||||
$month = $_GET['month'];
|
||||
}
|
||||
//day
|
||||
if(empty($_GET['day']) || int_escape($_GET['day']) > 31){
|
||||
$day = date("d");
|
||||
}else{
|
||||
$day = $_GET['day'];
|
||||
}
|
||||
$totaldate = $year."/".$month."/".$day;
|
||||
|
||||
$sql =
|
||||
"SELECT * FROM images
|
||||
WHERE EXTRACT(YEAR FROM posted) = :year
|
||||
";
|
||||
|
||||
$agrs = array("limit" => $t_images, "year" => $year);
|
||||
$sql = "SELECT id FROM images
|
||||
WHERE EXTRACT(YEAR FROM posted) = :year
|
||||
";
|
||||
$args = array("limit" => $config->get_int("index_images"), "year" => $year);
|
||||
|
||||
if($event->page_matches("popular_by_day")){
|
||||
$sql .=
|
||||
"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);
|
||||
AND EXTRACT(DAY FROM posted) = :day";
|
||||
|
||||
$args = array_merge($args, array("month" => $month, "day" => $day));
|
||||
$dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m\\&\\d\\a\\y\\=d", "day");
|
||||
}
|
||||
if($event->page_matches("popular_by_month")){
|
||||
$sql .=
|
||||
"AND EXTRACT(MONTH FROM posted) = :month
|
||||
AND NOT numeric_score=0
|
||||
";
|
||||
$sgra = array("month" => $month);
|
||||
$args = array_merge($agrs, $sgra);
|
||||
else if($event->page_matches("popular_by_month")){
|
||||
$sql .= "AND EXTRACT(MONTH FROM posted) = :month";
|
||||
|
||||
$title = date("F Y", (strtotime($totaldate)));
|
||||
$dte = array($totaldate, $title, "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m", "month");
|
||||
$args = array_merge($args, array("month" => $month));
|
||||
$dte = array($totaldate, date("F Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m", "month");
|
||||
}
|
||||
if($event->page_matches("popular_by_year")){
|
||||
$sql .= "AND NOT numeric_score=0";
|
||||
$dte = array($totaldate, $year, "\y\e\a\\r\=Y", "year");
|
||||
$args = $agrs;
|
||||
else if($event->page_matches("popular_by_year")){
|
||||
$dte = array($totaldate, $year, "\\y\\e\\a\\r\=Y", "year");
|
||||
}
|
||||
$sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0";
|
||||
$sql .= " AND NOT numeric_score=0 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
|
||||
$result = $database->get_all($sql, $args);
|
||||
//filter images by score != 0 + date > limit to max images on one page > order from highest to lowest score
|
||||
|
||||
$result = $database->get_col($sql, $args);
|
||||
$images = array();
|
||||
foreach($result as $singleResult) {
|
||||
$images[] = Image::by_id($singleResult["id"]);
|
||||
}
|
||||
foreach($result as $id) { $images[] = Image::by_id($id); }
|
||||
|
||||
$this->theme->view_popular($images, $dte);
|
||||
}
|
||||
}
|
||||
@ -217,12 +196,12 @@ class NumericScore extends Extension {
|
||||
|
||||
public function onSearchTermParse(SearchTermParseEvent $event) {
|
||||
$matches = array();
|
||||
if(preg_match("/^score([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(-?\d+)$/", $event->term, $matches)) {
|
||||
if(preg_match("/^score([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(-?\d+)$/i", $event->term, $matches)) {
|
||||
$cmp = ltrim($matches[1], ":") ?: "=";
|
||||
$score = $matches[2];
|
||||
$event->add_querylet(new Querylet("numeric_score $cmp $score"));
|
||||
}
|
||||
if(preg_match("/^upvoted_by[=|:](.*)$/", $event->term, $matches)) {
|
||||
else if(preg_match("/^upvoted_by[=|:](.*)$/i", $event->term, $matches)) {
|
||||
$duser = User::by_name($matches[1]);
|
||||
if(is_null($duser)) {
|
||||
throw new SearchTermParseException(
|
||||
@ -232,7 +211,7 @@ class NumericScore extends Extension {
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
|
||||
array("ns_user_id"=>$duser->id)));
|
||||
}
|
||||
if(preg_match("/^downvoted_by[=|:](.*)$/", $event->term, $matches)) {
|
||||
else if(preg_match("/^downvoted_by[=|:](.*)$/i", $event->term, $matches)) {
|
||||
$duser = User::by_name($matches[1]);
|
||||
if(is_null($duser)) {
|
||||
throw new SearchTermParseException(
|
||||
@ -242,18 +221,39 @@ class NumericScore extends Extension {
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
|
||||
array("ns_user_id"=>$duser->id)));
|
||||
}
|
||||
if(preg_match("/^upvoted_by_id[=|:](\d+)$/", $event->term, $matches)) {
|
||||
else if(preg_match("/^upvoted_by_id[=|:](\d+)$/i", $event->term, $matches)) {
|
||||
$iid = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
|
||||
array("ns_user_id"=>$iid)));
|
||||
}
|
||||
if(preg_match("/^downvoted_by_id[=|:](\d+)$/", $event->term, $matches)) {
|
||||
else if(preg_match("/^downvoted_by_id[=|:](\d+)$/i", $event->term, $matches)) {
|
||||
$iid = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet(
|
||||
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
|
||||
array("ns_user_id"=>$iid)));
|
||||
}
|
||||
else if(preg_match("/^order[=|:](numeric_)?(score)[_]?(desc|asc)?$/i", $event->term, $matches)){
|
||||
global $order_sql;
|
||||
$default_order_for_column = "DESC";
|
||||
$sort = isset($matches[3]) ? strtoupper($matches[3]) : $default_order_for_column;
|
||||
$order_sql = "numeric_score $sort";
|
||||
$event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
|
||||
}
|
||||
}
|
||||
|
||||
public function onTagTermParse(TagTermParseEvent $event) {
|
||||
$matches = array();
|
||||
|
||||
if(preg_match("/^vote[=|:](up|down|remove)$/", $event->term, $matches)) {
|
||||
global $user;
|
||||
$score = ($matches[1] == "up" ? 1 : ($matches[1] == "down" ? -1 : 0));
|
||||
if(!$user->is_anonymous()) {
|
||||
send_event(new NumericScoreSetEvent($event->id, $user, $score));
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($matches)) $event->metatag = true;
|
||||
}
|
||||
|
||||
private function install() {
|
||||
|
Reference in New Issue
Block a user