public static function votedown($data)
 {
     $out = array();
     if (!MyUser::isloggedin()) {
         throw new APIException("User ist nicht angemeldet.", 100);
     }
     if (MyUser::getKarmaPoints() < 100) {
         throw new APIException("Du benötigst 100 Karma-Punkte um einen negativen Vote zu geben.", 200);
     }
     if (!isset($data["question"])) {
         throw new APIException("Benötigter Parameter fehlt (question).", 50);
     }
     $db = new SQL(0);
     $row = $db->cmdrow(0, 'SELECT * FROM questions WHERE id={0}', array($data["question"] + 0));
     if (!isset($row["id"])) {
         throw new APIException("Diese Frage existiert nicht (mehr)", 300);
     }
     if ($row["author"] == MyUser::id()) {
         throw new APIException("Sie dürfen nicht auf Ihre eigene Frage voten", 301);
     }
     $raw = $db->cmdrow(0, 'SELECT * FROM question_votes WHERE question={0} AND user={1} LIMIT 0,1', array($data["question"] + 0, MyUser::id()));
     $w = array();
     $w["question"] = $data["question"] + 0;
     $w["user"] = MyUser::id();
     $w["vote"] = -1;
     $db->CreateUpdate(0, "question_votes", $w);
     $db->cmd(0, 'UPDATE questions as T1 SET count_votes = (SELECT sum(vote) FROM question_votes WHERE question=T1.id) WHERE id={0} LIMIT 1', false, array($w["question"]));
     $out["sumvotes"] = self::getVotes(array("question" => $w["question"]));
     if (!isset($raw["id"])) {
         Karma::RuleAction("VOTEDOWN_QUESTION", array("user" => $row["author"], "question" => $w["question"]));
     }
     Badge::add(9, MyUser::id(), array("question" => $w["question"]));
     //Kritiker: für downvote
     return $out;
 }
Exemple #2
0
 $frageid = $db->LastInsertKey();
 if (!isset($_GET["tag"])) {
     $_GET["tag"] = "";
 }
 $g = explode(",", $_GET["tag"] . "," . $_POST["tags"]);
 foreach (tags2array($_POST["tags"]) as $a) {
     if (trim($a) == "") {
         continue;
     }
     $w3 = array();
     $w3["question"] = $frageid;
     $w3["tag"] = $a;
     $db->CreateUpdate(0, "question_tags", $w3);
 }
 $_SESSION["myuser"]["lastwritten"]["question"][$frageid] = true;
 Karma::RuleAction("CREATE_QUESTION", array("user" => MyUser::id(), "question" => $frageid));
 Badges::add(3, MyUser::id(), array("question" => $frageid));
 //Erste Frage geschrieben
 @file_get_contents("www.google.com/webmasters/tools/ping?sitemap=" . urlencode(SiteConfig::val("baseurl") . "sitemap.xml"));
 $m = SiteConfig::get(0);
 if ($m["twitter"]["consumer"]["secret"] . "" != "" && $m["twitter"]["access"]["secret"] . "" != "") {
     try {
         $twitter = new Twitter($m["twitter"]["consumer"]["key"], $m["twitter"]["consumer"]["secret"]);
         $twitter->setOAuthToken($m["twitter"]["access"]["key"]);
         $twitter->setOAuthTokenSecret($m["twitter"]["access"]["secret"]);
         $url = API_urlshortener::add(Question::PermalinkByData($w3["question"], $w["title"]));
         if (strlen($w["title"]) > 100) {
             $tweet = substr($w["title"], 0, 100) . "... " . $url . " #wikihelp";
         } else {
             $tweet = substr($w["title"], 0, 100) . " " . $url . " #wikihelp";
         }
            $akismet->setPermalink(Question::PermalinkByData($w["question"], "Frage"));
            $akismet->setUserIP($_SERVER["REMOTE_ADDR"]);
            try {
                if ($akismet->isCommentSpam()) {
                    $w["isSPAM"] = 2;
                } else {
                    $w["isSPAM"] = -2;
                }
            } catch (Exception $ex) {
            }
        }
        $db->CreateUpdate(0, 'answers', $w);
        $answerID = $db->LastInsertKey();
        $db->cmd(0, 'UPDATE questions SET date_action={1},user_action="{2}", count_answers = (SELECT count(*) FROM answers WHERE question=questions.id) WHERE id={0} LIMIT 1', true, array($w["question"], time(), MyUser::id() + 0));
        $_SESSION["myuser"]["lastwritten"]["answers"][$answerID] = true;
        Karma::RuleAction("CREATE_ANSWER", array("user" => MyUser::id(), "question" => $w["question"], "answer" => $answerID));
        Badges::add(4, MyUser::id(), array("question" => $w["question"]));
        //Erste Antwort geschrieben
    }
}
if (isset($_POST["act"]) and $_POST["act"] == "addComment") {
    if (strlen($_POST["comment"]) >= 10 and MyUser::isloggedin()) {
        $w = array();
        $db = new SQL(0);
        $w["question"] = $_POST["question"] + 0;
        $w["answer"] = $_POST["answer"] + 0;
        $w["text"] = $_POST["comment"];
        $w["created"] = time();
        $w["user"] = MyUser::id();
        $db->CreateUpdate(0, 'comments', $w);
        $a = $db->LastInsertKey();
Exemple #4
0
 public static function accept($data)
 {
     $out = array();
     if (!MyUser::isloggedin()) {
         throw new APIException("User ist nicht angemeldet.", 100);
     }
     if (!isset($data["answer"])) {
         throw new APIException("Benötigter Parameter fehlt (answer).", 50);
     }
     $db = new SQL(0);
     $info = $db->cmdrow(0, 'SELECT * FROM answers WHERE id={0} LIMIT 0,1', array($data["answer"] + 0));
     if (!isset($info["id"])) {
         throw new APIException("Diese Antwort existiert nicht (mehr)", 300);
     }
     if ($info["right_answer"] == "1") {
         throw new APIException("Dies ist bereits die beste Antwort", 330);
     }
     $qinfo = $db->cmdrow(0, 'SELECT * FROM questions WHERE id={0} LIMIT 0,1', array($info["question"] + 0));
     if (!isset($qinfo["id"])) {
         throw new APIException("Diese Frage existiert nicht (mehr)", 300);
     }
     if ($qinfo["is_closed"] == "1") {
         throw new APIException("Diese Frage ist bereits geschlossen", 310);
     }
     if ($qinfo["author"] != MyUser::id()) {
         throw new APIException("Dies ist nicht ihre Frage", 320);
     }
     if ($info["author"] == MyUser::id() and MyUser::getKarmaPoints() < 50) {
         throw new APIException("Deine eigene Antwort darf erst ab 50 Karma Punkten die beste Antwort sein", 210);
     }
     $db->cmd(0, 'UPDATE answers SET right_answer = "1" WHERE id={0} LIMIT 1', true, array($info["id"]));
     $db->cmd(0, 'UPDATE questions SET is_answered = "1" WHERE id={0} LIMIT 1', true, array($info["question"]));
     if (MyUser::id() != $info["author"]) {
         Karma::RuleAction("ACCEPT_ANSWER", array("user" => $info["author"], "question" => $info["question"], "answer" => $info["id"]));
     }
     if (MyUser::id() != $info["author"] && $info["is_bounty"] == "1") {
         Bounty::Release($info["question"], $info["author"]);
     }
     //Gib dem Autor die Bounty
     return true;
 }