public static function get_profile($u, $privacy = true, $badges = true, $social_networks = true, $friends = true, $exp = true, $aditional_info = true, $gamertags = true) { Phalanx::loadClasses('Privacy', 'Badges', 'Friendship', 'SocialNetwork', 'Posts', 'GamerTags'); $m = Model::Factory('user u'); $m->where("login='******'"); $user = $m->get(); if (!$user) { return false; } # Em alguns casos, não é necessário utilizarmos todos os dados do usuário if ($privacy) { $user->privacy = Privacy::from_user($user->id); } if ($badges) { $user->badges = Badges::from_user($user->id); } if ($social_networks) { $user->social_networks = SocialNetwork::from_user($user->id); } if ($friends) { $user->friends = Friendship::from_user($user->id, 12); } if ($exp) { $user->experience = self::experience($user->id); } if ($aditional_info) { $user->aditional_info = self::other_data($user->id); } if ($gamertags) { $user->gamertags = GamerTags::from_user($user->id); } return $user; }
function like() { $event_id = (int) $_POST['ids']; $plus = $_POST['plus'] === 'true'; if ($event_id > 0) { if (CurrentUser::$id) { if ($plus) { Badges::progressAction(CurrentUser::$id, Badges::ACTION_TYPE_LIKE); Database::query('INSERT INTO `event_likes` SET user_id=' . CurrentUser::$id . ', event_id=' . $event_id . ', `time`=' . time() . ' ON DUPLICATE KEY UPDATE `time`=' . time()); } else { Database::query('DELETE FROM `event_likes` WHERE user_id=' . CurrentUser::$id . ' AND event_id=' . $event_id); } } } }
public static function get($post_id, $cache_time = 0, $sort = null) { Phalanx::loadClasses('public.Profile', 'public.Badges'); $cache_time = $cache_time ? $cache_time : MEMCACHE_SECONDS; $m = Model::Factory('comment c', true, $cache_time); $m->fields('c.id AS id', 'u.id AS user_id', 'c.comment AS comment', 'c.date AS date', 'c.in_reply_to AS in_reply_to', 'c.like_count AS likes', 'c.dislike_count AS dislikes', 'u.login AS user', 'ud.avatar AS avatar', 'c.wp_comment_author AS wp_comment_author', 'c.wp_comment_author_email AS wp_comment_author_email'); $m->leftJoin('user u', 'u.id = c.user_id'); $m->leftJoin('user_data ud', 'ud.user_id = u.id'); $m->where("posts_id='{$post_id}' AND c.status=1 AND u.banned IS NULL"); if (is_null($sort)) { $m->order("c.id ASC"); } elseif ($sort == 'like') { $m->order("c.like_count DESC"); } $data = $m->all(); $comments = array(); $Session = new Session(); if (is_array($data)) { foreach ($data as $each) { $o = new stdClass(); $o->id = $each->id; $o->comment = $each->comment; $o->date = Date::RelativeTime($each->date); $o->rating = new stdClass(); $o->rating->megaboga = (int) $each->likes; $o->rating->whatever = (int) $each->dislikes; $o->my_rating = self::userRating($Session->user->id, $each->id); $o->user = new stdClass(); $o->create_links = $each->user_id == 0 ? false : true; $o->user->login = $each->user_id == 0 ? $each->wp_comment_author : $each->user; $o->user->avatar = $each->user_id == 0 ? "http://www.gravatar.com/avatar/" . md5(strtolower(trim($each->wp_comment_author_email))) . "?d=" . urlencode(MEDIA_DIR . 'images/avatar/square/default.jpg') . "&s=44" : $each->avatar; $o->user->id = $each->user_id; if ($each->user_id != 0) { $o->user->experience = Profile::experience($each->user_id); $o->user->badges = Badges::from_user($each->user_id, 4); } if ($each->in_reply_to == '' || $each->in_reply_to == '0') { $o->replies = is_array($comments[$each->id]->replies) ? $comments[$each->id]->replies : array(); $comments[$each->id] = $o; } else { $comments[$each->in_reply_to]->replies[] = $o; } } } return $comments; }
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; }
function addEventComment() { $parent_id = isset($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; $event_id = (int) $_POST['object_id']; $object_type = Config::COMMENT_OBJECT_ALBUM_EVENT; $user_id = CurrentUser::$id; $text = htmlspecialchars($_POST['text']); if ($user_id && $event_id && trim($text)) { $album_id = (int) Database::sql2single('SELECT album_id FROM album_events WHERE `id`=' . $event_id); if (!$parent_id) { Database::query('INSERT INTO `comments` SET `parent_id`=' . $parent_id . ', `object_type`=' . $object_type . ', `object_id`=' . $event_id . ', `user_id`=' . $user_id . ', `time`=' . time() . ', `text`=' . Database::escape($text)); header('Location: /album/' . $album_id . '/event/' . $event_id . '#comment-' . Database::lastInsertId()); } else { // parent $thread = Database::sql2single('SELECT `thread` FROM `comments` WHERE `id`=' . $parent_id); $thread = $thread ? $thread : $parent_id; Database::query('INSERT INTO `comments` SET `parent_id`=' . $parent_id . ', `object_type`=' . $object_type . ', `object_id`=' . $event_id . ', `user_id`=' . $user_id . ', `thread`=' . $thread . ', `time`=' . time() . ', `text`=' . Database::escape($text)); header('Location: /album/' . $album_id . '/event/' . $event_id . '#comment-' . Database::lastInsertId()); } Database::query('UPDATE `album_events` SET `comments_count` = (SELECT COUNT(1) FROM `comments` WHERE `object_type`=' . Config::COMMENT_OBJECT_ALBUM_EVENT . ' AND `object_id`=' . $event_id . ') WHERE `id`=' . $event_id); $owner_id = (int) Database::sql2single('SELECT `creator_id` FROM album_events WHERE `id`=' . $event_id); if ($owner_id !== CurrentUser::$id) { Badges::progressAction($user_id, Badges::ACTION_TYPE_COMMENT); Badges::progressAction($owner_id, Badges::ACTION_TYPE_COMMENTED); } } }
public function Login() { $user = Profile::login($this->post->username, md5($this->post->password)); $o = new stdClass(); if ($user and $user->banned != 1) { $this->session->logged_in = true; $this->session->user = $user; $this->session->accept_token = md5(REQUEST_IP) . sha1('SkyNerd a REDE SOCIAL do JoVemNerd'); $o->status = true; $o->login = $user->login; $o->avatar = $user->other_data->avatar; $o->experience = Profile::experience($this->session->user->id); $o->badges = Badges::from_user($this->session->user->id, 4); } else { $o->status = false; $o->reason = $user->banned == 1 ? 'banned' : 'incorrect_info'; } header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: POST"); header("Content-type: text/html; charset=utf-8"); echo json_encode($o); }
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"]); }
public function Comment() { if (!$this->isLoggedIn) { return; } if (!$this->session->recent_comments) { $this->session->recent_comments = new stdClass(); } if (!$this->session->recent_comments->{"pid" . $this->post->post_id}) { $this->session->recent_comments->{"pid" . $this->post->post_id} = array(); } if (in_array(md5($this->post->comment), $this->session->recent_comments->{"pid" . $this->post->post_id})) { header("Content-type:application/json;charset=utf-8"); $o = new stdClass(); $o->status = 0; $o->message = "Comentário duplicado"; die(json_encode($o)); } if (trim($this->post->comment) == '') { header("Content-type:application/json;charset=utf-8"); $o = new stdClass(); $o->status = 0; $o->message = "Comentário vazio"; die(json_encode($o)); } $m = Model::Factory('comment', false, false); $m->posts_id = $this->post->post_id; $m->comment = trim($this->post->comment); $m->user_id = $this->session->user->id; if ($this->post->in_reply_to) { $m->in_reply_to = $this->post->in_reply_to; } $m->date = date('Y-m-d H:i:s'); if (isset($this->post->in_reply_to)) { $m->in_reply_to = $this->post->in_reply_to; $n = new Notification(Notification::REPLYED_COMMENT, $this->session->user->id, $this->post->in_reply_to); } else { $n = new Notification(Notification::COMMENTED_POST, $this->session->user->id, $this->post->post_id); } $s = $m->insert(); if ($s) { $this->session->recent_comments->{"pid" . $this->post->post_id}[] = md5($this->post->comment); Phalanx::loadClasses('Profile'); preg_match_all('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', $this->post->comment, $usernames); foreach ($usernames[1] as $username) { $user = Profile::get_user_info($username); if ($user) { $n = new Notification(Notification::TAGGED_IN_A_COMMENT, $this->session->user->id, $this->post->post_id, $user->id); } } if ($this->post->in_reply_to) { Model::ExecuteQuery("UPDATE posts SET reply_count = reply_count+1 WHERE id='{$this->post->post_id}'"); } else { Model::ExecuteQuery("UPDATE posts SET comment_count = comment_count+1 WHERE id='{$this->post->post_id}'"); } Phalanx::loadClasses('Profile', 'Badges'); header("Content-type:application/json;charset=utf-8"); $o = new stdClass(); $o->status = 1; $o->isReply = $this->post->in_reply_to ? true : false; $o->id = $s; $o->avatar = $this->session->user->other_data->avatar; $o->user = $this->session->user->login; $o->comment = nl2br(trim(preg_replace('/(?<=|(?<=[.A-Za-z0-9_-]))@([.A-Za-z0-9_-]+[.A-Za-z0-9_-]+)/', '<a class="profile-link" href="' . HOST . 'perfil/$1"e>@$1</a>', $this->post->comment))); $o->comment_id = $s; $o->post_id = $this->post->post_id; if ($this->post->in_reply_to) { $o->in_reply_to = $this->post->in_reply_to; } $o->experience = Profile::experience($this->session->user->id); $o->badges = Badges::from_user($this->session->user->id, 4); die(json_encode($o)); } }
if (!isset($current[$id]) || !$current[$id]['gained_time']) { echo "BADGE RECEIVED:" . $id; $last_badge_id = Badges::addBadge($action['user_id'], $action['badge_type_id'], $id, $total_progress); } } if (!$found_next && $total_progress < $existingBadge['repeat']) { $found_next = true; echo "NEXT BADGE " . $id . " TO STORE \n"; $last_badge_id = $id; } } // updating progress if (!$last_badge_id) { // не было прогресса по этому бейджу echo "NEW BADGE TO STORE\n"; $last_badge_id = Badges::getFirstBadgeId($action['badge_type_id']); } Badges::addBadgeStored($action['user_id'], $action['badge_type_id'], $last_badge_id, $total_progress); // deleting row Database::query('DELETE FROM `user_badges_actions` WHERE `user_id`=' . $action['user_id'] . ' AND `badge_type_id`=' . $action['badge_type_id'] . ' AND `time`=' . $action['time']); // if it's no any badge - add badge // set total progress for line - updating last action in line } } else { echo "\nnothing to do\n"; break; } } } else { echo "\nalready running\n"; }
public function Export() { Phalanx::loadClasses('Profile', 'Badges'); $profile = Profile::get_profile($this->session->user->login, 0, 0, 0, 0, 1, 1, 1); $profile->badges = Badges::from_user($this->sessio->user->id, false); $t = new Template("export"); $t->show_login_bar = true; $userPosts = Posts::exportFromUser($this->session->user->id); $postsImages = array(); $avatarImages = array(); $posts = array(); Phalanx::loadExtension('simple_html_dom'); foreach ($userPosts as $key => $each) { $html = str_get_html($each->content); /* * Em alguns casos o objeto não está sendo criado, gerando um fatal error. * Conteúdo vazio? Estranho, ainda não sei o que está rolando. * Isso aqui resolve. * */ if (is_object($html)) { $images = $html->find('img'); foreach ($images as &$image) { if (stripos($image, HOST)) { $postsImages[] = basename($image->src); $image->src = "./images/posts/" . basename($image->src); } } $each->content = $html; } $avatarImages[] = $each->avatar; $v = new Views(); $v->accept_nsfw = Profile::acceptNSFW($this->session->user->id); $v->current_user = $this->session->user->login; $v->user = $each->user; $v->name = $each->name; $v->when = $each->date; $v->title = $each->title; $v->content = $each->content; $v->comments = $each->comments; $v->comments_array = $each->comments_array; $v->replies = $each->replies; $v->post_id = $each->id; $v->original_id = $each->original_id; $v->is_reblogged = $each->is_reblogged; $v->avatar = $each->avatar; $v->rating = $each->rating; $v->my_rating = $each->my_rating; $v->categories = $each->categories; $v->its_mine = $profile_data->id == $this->session->user->id ? true : false; $v->is_favorite = $each->is_favorite; $v->user_points = $each->user_points; foreach ($each->comments_array as $eachComment) { $avatarImages[] = $eachComment->user->avatar; foreach ($eachComment->replies as $eachReply) { $avatarImages[] = $eachReply->user->avatar; } } if (!empty($each->original_id)) { //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações $originalPost = Posts::from_user(false, $v->original_id); $originalPost = reset($originalPost); $v->content = $originalPost->content; $v->title = $originalPost->title; $v->reblogged_from = $originalPost->user; $v->reblog_avatar = $originalPost->avatar; $v->reblog_points = $originalPost->user_points; $v->original_date = $originalPost->date; $v->comments = $originalPost->comments; $v->replies = $originalPost->replies; $v->is_favorite = $originalPost->is_favorite; $v->categories = $originalPost->categories; $v->rating = $originalPost->rating; $v->id = $v->post_id; $v->post_id = $originalPost->id; } $content = $v->render("export/post_body.phtml"); $posts[] = $content; } $v = new Views($t); $v->data = $profile; $v->data->timeline = $posts; ob_start(); $v->display("export/profile.phtml"); $profile_html_data = ob_get_contents(); ob_end_clean(); if (!is_dir(TMP_DIR . DIRECTORY_SEPARATOR . 'export')) { mkdir(TMP_DIR . DIRECTORY_SEPARATOR . 'export', 0755, true); } $dirname = TMP_DIR . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . $this->session->user->login . DIRECTORY_SEPARATOR; if (!is_dir($dirname)) { mkdir($dirname, 0755, true); } $filename = "perfil-{$this->session->user->login}.html"; file_put_contents($dirname . $filename, $profile_html_data); $zip = new ZipArchive(); if ($zip->open("{$dirname}data.zip", ZipArchive::CREATE) === TRUE) { $zip->addEmptyDir('css'); foreach (glob(TEMPLATE_DIR . '/export/css/*') as $file) { $zip->addFile($file, "/css/" . basename($file)); } $zip->addEmptyDir('js'); foreach (glob(TEMPLATE_DIR . '/export/js/*') as $file) { $zip->addFile($file, "/js/" . basename($file)); } $zip->addEmptyDir('fonts'); $zip->addEmptyDir('fonts/Engschrift'); foreach (glob(TEMPLATE_DIR . '/export/fonts/Engschrift/*') as $file) { $zip->addFile($file, "/fonts/Engschrift/" . basename($file)); } $zip->addEmptyDir('images'); foreach (glob(TEMPLATE_DIR . '/export/images/*.*') as $file) { $zip->addFile($file, "/images/" . basename($file)); } $zip->addEmptyDir('images/socialnetworks'); foreach (glob(TEMPLATE_DIR . '/export/images/socialnetworks/*') as $file) { $zip->addFile($file, "/images/socialnetworks/" . basename($file)); } $zip->addEmptyDir('images/images'); foreach (glob(TEMPLATE_DIR . '/export/images/images/*') as $file) { $zip->addFile($file, "/images/images/" . basename($file)); } $zip->addEmptyDir('images/avatar'); $zip->addEmptyDir('images/avatar/big'); $zip->addEmptyDir('images/avatar/small'); $zip->addEmptyDir('images/avatar/square'); foreach ($avatarImages as $avatar) { $zip->addFile(AVATAR_UPLOAD_DIR . "/big/{$avatar}", "/images/avatar/big/{$avatar}"); $zip->addFile(AVATAR_UPLOAD_DIR . "/small/{$avatar}", "/images/avatar/small/{$avatar}"); $zip->addFile(AVATAR_UPLOAD_DIR . "/square/{$avatar}", "/images/avatar/square/{$avatar}"); } $zip->addEmptyDir('images/posts'); foreach ($postsImages as $image) { $zip->addFile(POST_IMAGES_UPLOAD_DIR . "/{$image}", "/images/posts/{$image}"); } $zip->addEmptyDir('images/badges'); foreach (glob(ROOT . PROJECT_DIR . '/media/images/badges/*') as $file) { $zip->addFile($file, "/images/badges/" . basename($file)); } $zip->addFile("{$dirname}{$filename}", "/{$filename}"); } $zip->close(); header("Content-disposition: attachment; filename={$this->session->user->login}.zip"); header("Content-type: application/zip"); readfile("{$dirname}data.zip"); $t = new Template("export", "thankyou.phtml"); $v = new Views($t); $v->display(""); $c = new Cookies(); $c->setExpire(strtotime("+15 days")); $c->data_exported = 1; }
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);
$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; }
} 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); } }
function editEvent() { $error = array(); $album_id = (int) $_POST['album_id']; if (isset($_POST['id'])) { $event_id = max(0, (int) $_POST['id']); $template_id = Database::sql2single('SELECT `template_id` FROM `album_events` AE JOIN `lib_events` LE ON LE.id=AE.event_id WHERE AE.`id`=' . $event_id); } else { if (isset($_POST['template_id'])) { $template_id = max(0, (int) $_POST['template_id']); } } $event_event_id = 0; if (isset($_POST['event_id'])) { $template_id = Database::sql2single('SELECT `template_id` FROM `lib_events` LE WHERE LE.`id`=' . (int) $_POST['event_id']); $event_event_id = (int) $_POST['event_id']; } if (!$template_id) { $template_id = 1; } $q = $q_ = array(); Database::query('START TRANSACTION'); if (!$event_id) { $event_data = Database::sql2row('SELECT * FROM `lib_events` WHERE `id`=' . (int) $event_event_id); if (isset($event_data['multiple']) && !$event_data['multiple']) { // несколько раз нельзя $exists = Database::sql2single('SELECT `id` FROM `album_events` WHERE `album_id`=' . $album_id . ' AND `event_id`=' . $event_data['id']); if ($exists) { throw new Exception('У Вас уже есть такое событие, и добавлять несколько копий этого события бессмысленно'); } } $query = 'INSERT INTO `album_events` SET id=NULL,createTime=' . time() . ''; Badges::progressAction(CurrentUser::$id, Badges::ACTION_TYPE_ADD_EVENT); if ($template_id > 1) { Badges::progressAction(CurrentUser::$id, Badges::ACTION_TYPE_ADD_THEMED_EVENT); } Database::query($query); $event_id = Database::lastInsertId(); } else { $check = Database::sql2single('SELECT `creator_id` FROM `album_events` WHERE `album_id`=' . $album_id . ' AND `id`=' . $event_id); if ((int) $check !== (int) CurrentUser::$id) { throw new Exception('It is not your event ' . $check . ' ' . CurrentUser::$id); } } $template_fields = $this->getTemplateFields($template_id); foreach ($template_fields as $eventName => $field) { if (!isset($_POST[$eventName]) || !trim($_POST[$eventName])) { if ($field['important'] && $field['type'] != 'photo') { $error[$eventName] = 'Обязательно к заполнению'; } if ($field['important'] && $field['type'] == 'photo') { if (!isset($_FILES[$eventName])) { $error[$eventName] = 'Обязательно к заполнению'; } } } if ($field['type'] != 'photo') { switch ($field['type']) { case 'eventTitle': $q_[] = '`title`=' . Database::escape(htmlspecialchars(trim($_POST[$eventName]))); $q[] = '(' . $event_id . ',' . $field['field_id'] . ',NULL,' . Database::escape(trim($_POST[$eventName])) . ',NULL)'; break; case 'eventTime': $_POST[$eventName] = date('Y-m-d H:i:s', strtotime($_POST[$eventName])); $q_[] = '`eventTime`=' . Database::escape(htmlspecialchars(trim($_POST[$eventName]))); $q[] = '(' . $event_id . ',' . $field['field_id'] . ',NULL,' . Database::escape(trim($_POST[$eventName])) . ',NULL)'; break; case 'description': $q_[] = '`description`=' . Database::escape(htmlspecialchars(trim($_POST[$eventName]))); $q[] = '(' . $event_id . ',' . $field['field_id'] . ',NULL,NULL,' . Database::escape(trim($_POST[$eventName])) . ')'; break; case 'height': case 'eyecolor': $q[] = '(' . $event_id . ',' . $field['field_id'] . ',' . Database::escape(trim($_POST[$eventName])) . ',NULL,NULL)'; break; case 'weight': $v = $_POST[$eventName] * 1000 / 1000; if ($v > 200) { $v = $v / 1000; } $q[] = '(' . $event_id . ',' . $field['field_id'] . ',' . Database::escape(trim($v)) . ',NULL,NULL)'; break; default: $q[] = '(' . $event_id . ',' . $field['field_id'] . ',NULL,' . Database::escape(trim($_POST[$eventName])) . ',NULL)'; break; } } } if (count($error)) { Site::passWrite('error_', $error); Site::passWrite('value', $_POST); Database::query('ROLLBACK'); return false; } Database::query('COMMIT'); if (count($q)) { $query = 'REPLACE INTO `album_events_fields`(event_id,field_id,value_int,value_varchar,value_text) VALUES ' . implode(',', $q); Database::query($query); } if (count($q_)) { $query = 'INSERT INTO `album_events` SET `createTime`=' . time() . ', `id`=' . ($event_id ? $event_id : 'NULL') . ', `event_id`=' . $event_event_id . ', `album_id`=' . $album_id . ', `creator_id`=' . CurrentUser::$id . ', ' . implode(',', $q_) . ' ON DUPLICATE KEY UPDATE `id`=' . ($event_id ? $event_id : 'NULL') . ', `event_id`=' . $event_event_id . ', `album_id`=' . $album_id . ', `creator_id`=' . CurrentUser::$id . ', ' . implode(',', $q_) . ' '; Database::query($query); $event_id = $event_id ? $event_id : Database::lastInsertId(); } if (isset($_FILES['photo']) && $_FILES['photo']['tmp_name']) { if (!$_FILES['photo']['error']) { $old_image_id = Database::sql2single('SELECT `picture` FROM `album_events` WHERE `id`=' . $event_id); $result = ImgStore::upload($_FILES['photo']['tmp_name'], Config::$sizes[Config::T_SIZE_PICTURE]); Database::query('UPDATE `album_events` SET `picture`=' . $result . ' WHERE `id`=' . $event_id); if ($old_image_id) { Database::query('UPDATE `images` SET `deleted`=1 WHERE `image_id`=' . $old_image_id); } Badges::progressAction(CurrentUser::$id, Badges::ACTION_TYPE_ADD_PHOTO); } else { $error['photo'] = 'Недопустимый формат файла'; Site::passWrite('error_', $error); Site::passWrite('value', $_POST); return false; } } if (isset($_FILES['photo']) && $_FILES['photo']['error'] != 4 && $_FILES['photo']['error']) { $error['photo'] = 'Недопустимый формат файла'; Site::passWrite('error_', $error); Site::passWrite('value', $_POST); return false; } header('Location: /album/' . $album_id . '/event/' . $event_id); }
function showBadges() { $user_id = array_values(Site::$request_uri_array); $user_id = $user_id[1]; if (!$user_id) { header('Location: /'); exit(0); } $user = Users::getByIdLoaded($user_id); $data = array('badges' => array()); $data['badges'] = Badges::getUserAllBadges($user_id); return $data; }
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @framework RottenEggs App Development * @description Application/API Toolset + Sample * @copyright Copyright (c) 2010, Monir Boktor. (http://www.rotteneggs.com) * @license http://www.opensource.org/licenses/bsd-license.php - BSD * @version Ver: 0.1.1 2011-01-01 14:48 * */ include('framework/app_core.php'); include('program/badges.php'); $app = new Badges(); // Generate the text for this page $Body = $app->AppBody($_GET); // Was an ajax call made? If so, simply display the body without formatting. if ($_GET['aj_call']) {echo $Body;die();} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <base href="<?php echo BASE_URL; ?>
public function DisplayUserBadges() { Phalanx::loadClasses('Badges', 'Profile'); if (isset($this->get->id)) { $template = new Template("default"); $template->show_login_bar = $this->isLoggedIn; $badge = Badges::get($this->get->id); $template->og = new stdClass(); $template->og->description = $badge->description; $template->og->type = 'skynerd_jn:badge'; $template->og->title = $badge->name; $template->og->img = MEDIA_DIR . "images/badges/{$badge->icon_url}"; $this->views = new Views($template); } if (isset($this->get->username)) { $username = $this->get->username; } else { if (!$this->session->user) { Request::redirect(HOST . 'login'); } $username = $this->session->user->login; } $profile_data = Profile::get_profile($username); $this->views->data = $profile_data; if ($username != $this->session->user->login) { $this->views->data->friendship_status = Friendship::get_status($this->session->user->id, $profile_data->id); } $this->views->data->badges_list = Badges::from_user($profile_data->id, false); $this->views->display("profile.phtml"); }
function __construct($inargs) { $defaults = array('group' => 'posts', 'subgroup' => 'worst'); parent::__construct(); $args = array_merge($defaults, $inargs); $this->badge_group = $args['group']; // set some vars $action = 'action_' . $this->badge_group; if (in_array($action, get_class_methods($this))) { $this->gotbadge = $this->{$action}(); } // test the return value. return; }
function register() { $error = array(); if (!valid_email_address($_POST['email'])) { $error['email'] = 'неправильный E-mail'; } if (!trim($_POST['password'])) { $error['password'] = '******'; } if (!isset($_POST['agree'])) { $error['agree'] = 'Примите условия пользовательского соглашения'; } if (count($error)) { Site::passWrite('error_register', $error); return; } else { try { $fields = array(); $data['email'] = strtolower(trim($_POST['email'])); $data['nickname'] = $this->getUniqueNickname(strtolower(trim($_POST['nickname'])), $_POST['email']); $data['password'] = md5(trim($_POST['password'])); $data['registerTime'] = $data['lastAccessTime'] = time(); $data['role'] = User::ROLE_UNVERIFIED; $data['hash'] = md5(time() . '-' . rand(1, 10)); foreach ($data as $f => $v) { $fields[] = '`' . $f . '`=' . Database::escape($v); } Database::query('INSERT INTO `user` SET ' . implode(',', $fields)); $uid = Database::lastInsertId(); try { Site::passWrite('success', true); } catch (Exception $e) { $error['email'] = $e->getMessage(); Site::passWrite('error_register', $error); return; } $this->sendRegisterEmail($data['email'], '', $uid . '-' . $data['hash']); Badges::progressAction($uid, Badges::ACTION_TYPE_REGISTER); } catch (Exception $e) { $error['email'] = 'E-mail уже используется, укажите другой'; Site::passWrite('error_register', $error); return; } CurrentUser::set_cookie($uid); } }
$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") . '" />