public static function Release($question = 0, $Receiver_User = 0) { $db = new SQL(0); $rows = $db->cmdrows(0, 'SELECT * FROM question_bounty WHERE question={0} GROUP BY currency', array($question + 0)); foreach ($rows as $row) { switch ($row["currency"]) { case "kar": Karma::add($Receiver_User, 6, $row["amount"], $row["question"]); break; case "BTC": break; case "EUR": break; default: } } $db->cmd(0, 'UPDATE questions SET is_bounty =0 WHERE question={0} LIMIT 1', true, array($question + 0)); $db->cmd(0, 'DELETE FROM question_bounty WHERE question={0}', true, array($question + 0)); }
/** * A question has been voted on * This method will determine what type * of vote has been cast and what karma to give. * * Key Votes: * - up vote on question * - up vote on answer * - marked as best answer * * @param type $event */ public static function onQuestionVoteAfterSave($event) { switch ($event->sender->vote_type) { case "up": // Only vote on questions and answers switch ($event->sender->vote_on) { case "question": Karma::model()->addKarma('question_up_vote', $event->sender->created_by); break; case "answer": Karma::model()->addKarma('answer_up_vote', $event->sender->created_by); break; } break; case "accepted_answer": Karma::model()->addKarma('accepted_answer', $event->sender->created_by); break; } }
/** * Deletes a karma record */ public function actionDelete() { $id = (int) Yii::app()->request->getQuery('id'); $doit = (int) Yii::app()->request->getQuery('doit'); $karma = Karma::model()->resetScope()->findByPk($id); if ($karma == null) { throw new CHttpException(404, "Karma record not found"); } if ($doit == 2) { $this->forcePostRequest(); $karma->delete(); $this->redirect($this->createUrl('index')); } $this->render('delete', array('model' => $karma)); }
/** * Private method that handles assinging * karma to a user * @param string $karma_name * @param int $user_id * @return bool */ public function addKarma($karma_name, $user_id) { // First find the karma record $karma = Karma::model()->findByAttributes(array('name' => $karma_name)); if ($karma) { KarmaUser::model()->attachKarma($user_id, $karma->id); return true; } else { return false; } }
$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"; }
public static function setbounty($data) { if (!MyUser::isloggedin()) { throw new APIException("User ist nicht angemeldet.", 100); } $data["karma"] = floor(string2::vall($data["karma"] + 0)); $data["bitcoin"] = string2::vall($data["bitcoin"] + 0); $data["EUR"] = string2::vall($data["EUR"] + 0); $db = new SQL(0); if ($data["karma"] > 0) { if (MyUser::getKarmaPoints() < 75) { throw new APIException("Du benötigst 75 Karma-Punkte um eine Karma Bounty zu geben.", 200); } if (MyUser::getKarmaPoints() < $data["karma"] + 0) { throw new APIException("Du hast nur " . MyUser::getKarmaPoints() . " Karma Punkte zu verschenken!", 200); } $w = array(); $w["question"] = $data["question"] + 0; $w["user"] = MyUser::id(); $w["amount"] = $data["karma"]; $w["currency"] = "kar"; $w["dt_created"] = time(); $db->Create(0, 'question_bounty', $w); Karma::add(MyUser::id(), 5, 0 - $w["amount"], $w["question"]); } if ($data["bitcoin"] > 0) { throw new APIException("Sie haben nicht genügend Bitcoin Guthaben.", 610); } if ($data["EUR"] > 0) { throw new APIException("Sie haben nicht genügend Euro Guthaben.", 710); } }
$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();
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; }