Exemple #1
0
 public static function voteup($data)
 {
     $out = array();
     if (!MyUser::isloggedin()) {
         throw new APIException("User ist nicht angemeldet.", 100);
     }
     if (MyUser::getKarmaPoints() < 5) {
         throw new APIException("Du benötigst 5 Karma-Punkte um einen positiven Vote zu geben.", 200);
     }
     if (!isset($data["answer"])) {
         throw new APIException("Benötigter Parameter fehlt (answer).", 50);
     }
     $db = new SQL(0);
     $row = $db->cmdrow(0, 'SELECT * FROM answers WHERE id={0} LIMIT 0,1', array($data["answer"] + 0));
     $question = $db->cmdrow(0, 'SELECT * FROM questions WHERE id={0} LIMIT 0,1', array($row["question"] + 0));
     if (!isset($row["id"])) {
         throw new APIException("Diese Antwort existiert nicht (mehr)", 300);
     }
     if ($row["author"] == MyUser::id()) {
         throw new APIException("Sie dürfen nicht auf Ihre eigene Antwort voten", 301);
     }
     $raw = $db->cmdrow(0, 'SELECT * FROM answer_votes WHERE answer={0} AND user={1} LIMIT 0,1', array($data["answer"] + 0, MyUser::id()));
     $w = array();
     $w["answer"] = $data["answer"] + 0;
     $w["user"] = MyUser::id();
     $w["vote"] = 1;
     $db->CreateUpdate(0, "answer_votes", $w);
     $db->cmd(0, 'UPDATE answers as T1 SET count_votes = (SELECT sum(vote) FROM answer_votes WHERE answer=T1.id) WHERE id={0} LIMIT 1', false, array($w["answer"]));
     $out["sumvotes"] = self::getVotes(array("answer" => $w["answer"]));
     if (!isset($raw["id"])) {
         Karma::RuleAction("VOTEUP_ANSWER", array("user" => $row["author"], "question" => $row["question"], "answer" => $row["id"]));
     }
     $posV = $db->cmdvalue(0, 'SELECT count(*) FROM answer_votes WHERE vote="1" AND answer={0}', array($row["id"]));
     if ($posV == 3) {
         Badges::add(51, $row["author"], array("question" => $row["question"], "answer" => $w["answer"]));
     } elseif ($posV == 10) {
         Badges::add(52, $row["author"], array("question" => $row["question"], "answer" => $w["answer"]));
     } elseif ($posV == 25) {
         Badges::add(53, $row["author"], array("question" => $row["question"], "answer" => $w["answer"]));
     }
     //Gute Antwort (Silber) 3 positive Votes
     if ($posV >= 5 and $question["has_bounty"] == "1" and $question["author"] != $ow["author"] and $question["date_created"] + 7 * 86400 < time()) {
         Bounty::Release($question["id"], $row["author"]);
     }
     return $out;
 }
 public static function voteup($data)
 {
     $out = array();
     if (!MyUser::isloggedin()) {
         throw new APIException("User ist nicht angemeldet.", 100);
     }
     if (MyUser::getKarmaPoints() < 5) {
         throw new APIException("Du benötigst 5 Karma-Punkte um einen positiven 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("VOTEUP_QUESTION", array("user" => $row["author"], "question" => $w["question"]));
     }
     if ($db->cmdvalue(0, 'SELECT count(*) FROM question_votes WHERE vote="1" AND question={0}', array($row["id"])) == 3) {
         Badges::add(24, $row["author"], array("question" => $row["id"]));
     }
     //Gute Frage (Silber) 3 positive Votes
     return $out;
 }
    $w["location"] = $_POST["location"];
    $w["country"] = $_POST["country"];
    $w["language"] = $_POST["language"];
    $w["FlattrUID"] = trim($_POST["FlattrUID"]);
    $w["SkypeID"] = trim($_POST["SkypeID"]);
    $w["GooglePlus"] = trim($_POST["GooglePlus"]);
    $w["PayPal_email"] = $_POST["PayPal_email"];
    $w["show_country"] = (isset($_POST["show_country"]) and $_POST["show_country"] == "1" ? 1 : 0);
    $d = $_POST["birthday_year"] . "-" . $_POST["birthday_month"] . "-" . $_POST["birthday_day"];
    if (!preg_match("`^[0-9\\?]{4}-[0-9\\?]{2}-[0-9\\?]{2}\$`", $d)) {
        PageEngine::AddErrorMessage("save", "Ungültiges Geburtsdatum");
    } else {
        $w["birthday"] = $d;
    }
    $w["biography"] = $_POST["text"];
    $db = new SQL(0);
    $db->CreateUpdate(0, "user_list", $w);
    if ($w["username"] != "" and $w["prename"] != "" and $w["familyname"] != "" and $w["location"] != "" and $w["country"] != "" and $w["language"] != "" and $w["birthday"] != "" and $w["biography"] != "") {
        Badges::add(1, $w["id"]);
    }
    if ($w["SkypeID"] . "" != "") {
        Badges::add(6, $w["id"], array("skype" => $w["SkypeID"]));
    }
    PageEngine::AddSuccessMessage("save", "Profil gespeichert");
}
function UsernameAlreadyInUse($name, $myuserid = 0)
{
    $db = new SQL(0);
    $row = $db->cmdrow(0, 'SELECT id FROM user_list WHERE username = "******" AND id != {1} LIMIT 0,1', array($name, $myuserid + 0));
    return isset($row["id"]);
}
Exemple #4
0
 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";
         }
         $twitter->statusesUpdate($tweet);
                } 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();
        Badges::add(5, MyUser::id(), array("question" => $w["question"]));
        //Erster Kommentar geschrieben
        @header("Location: #comment-" . $a);
    }
}
    $w2 = array();
    $w2["id"] = $info["id"];
    $w2["title"] = $_POST["title"];
    $w2["question"] = $_POST["text"];
    $w2["author"] = MyUser::id();
    $w2["tags"] = implode(",", tags2array($_POST["tags"]));
    $w2["date_edited"] = time();
    $w2["date_action"] = time();
    $w2["user_action"] = MyUser::id() + 0;
    $db->CreateUpdate(0, 'questions', $w2);
    $db->cmd(0, 'DELETE FROM `question_tags` WHERE question={0}', true, array($info["id"]));
    foreach (tags2array($_POST["tags"]) as $a) {
        $w3 = array();
        $w3["question"] = $info["id"];
        $w3["tag"] = $a;
        $db->CreateUpdate(0, "question_tags", $w3);
    }
    Badges::add(10, MyUser::id());
    //Erfolg Redakteur: Editiere einen Beitrag
    header("Location: " . Question::PermalinkByData($info["id"], $info["title"]));
    exit(1);
}
function tags2array($text)
{
    $g = explode(",", $text);
    $out = array();
    for ($i = 0; $i < min(5, count($g)); $i++) {
        $out[] = trim(strtolower($g[$i]));
    }
    return $out;
}
        $ansorder = "date_created DESC";
        break;
    default:
        $ansorder = "count_votes DESC";
}
$answers = $db->cmdrows(0, "SELECT T1.*,T2.username as authorname,T2.email_standard as authoremail, T2.GooglePlus, T2.country, T2.show_country, T2.karma as authorkarma, T2.award_gold, T2.award_silver, T2.award_bronce, T2.website as authorwebsite, T2.FlattrUID, T3.vote as MyVote, T4.right as authorexpert\r\tFROM answers as T1\r\tLEFT JOIN user_list as T2 ON T1.author=T2.id \r\tLEFT JOIN answer_votes as T3 ON T1.id=T3.answer AND T3.user={1}\r\tLEFT JOIN user_rights as T4 ON T1.author=T4.user AND T4.right = 'expert'\r\tWHERE T1.question={0} \r\tORDER BY " . $ansorder . ", right_answer DESC", array($info["id"], MyUser::id() + 0));
$bounties = $db->cmdrows(0, 'SELECT sum(amount) as amount, currency FROM question_bounty WHERE question={0} GROUP BY currency', array($info["id"] + 0), "currency");
if ($info["author"] != MyUser::id()) {
    $db->cmd(0, 'INSERT LOW_PRIORITY IGNORE INTO `question_views` (`question`, `IP`, `day`) VALUES (' . $info["id"] . ', "' . $_SERVER["REMOTE_ADDR"] . '", ' . date("Ymd") . ');', true);
    $db->cmd(0, 'UPDATE LOW_PRIORITY `questions` SET count_views=(SELECT count(*) FROM `question_views` WHERE question=questions.id) WHERE id={0} LIMIT 1', true, array($info["id"]));
    if ($info["count_views"] == 500) {
        Badges::add(21, $info["author"], array("question" => $info["id"]));
    } elseif ($info["count_views"] == 250) {
        Badges::add(31, $info["author"], array("question" => $info["id"]));
    } elseif ($info["count_views"] == 150) {
        Badges::add(41, $info["author"], array("question" => $info["id"]));
    }
}
$rows = $db->cmdrows(0, 'SELECT T1.*,T2.username FROM comments as T1 LEFT JOIN user_list as T2 ON T1.user=T2.id WHERE question = {0} ORDER BY created ASC', array($info["id"]));
$comments = array();
foreach ($rows as $row) {
    $comments[$row["answer"]][] = $row;
}
$tagsy = array();
foreach ($tags as $row) {
    $tagsy[] = $row["tag"];
}
$html_meta = "";
if (SiteConfig::val("facebook/appid") . "" != "") {
    $html_meta = '
  <meta property="fb:app_id"        content="' . SiteConfig::val("facebook/appid") . '" />