示例#1
0
function moderate($cid, $zid, $rid)
{
    if (!db_has_rec("comment", $cid)) {
        return;
    }
    if (db_has_rec("comment_vote", array("cid" => $cid, "zid" => $zid))) {
        $comment_vote = db_get_rec("comment_vote", array("cid" => $cid, "zid" => $zid));
        $old = $comment_vote["rid"];
        if ($rid == $old) {
            return;
        } else {
            if ($rid == 0) {
                db_del_rec("comment_vote", array("cid" => $cid, "zid" => $zid));
            } else {
                $comment_vote["rid"] = $rid;
                db_set_rec("comment_vote", $comment_vote);
                return;
            }
        }
    }
    $comment_vote = array();
    $comment_vote["cid"] = $cid;
    $comment_vote["zid"] = $zid;
    $comment_vote["rid"] = $rid;
    $comment_vote["time"] = time();
    db_set_rec("comment_vote", $comment_vote);
}
示例#2
0
function db_set_rec($table, $rec)
{
    global $db_table;
    global $cache_enabled;
    if (!array_key_exists($table, $db_table)) {
        die("unknown table [{$table}]");
    }
    $key = $db_table[$table]["key"];
    $col = $db_table[$table]["col"];
    if (is_array($key)) {
        $id = array();
        for ($i = 0; $i < count($key); $i++) {
            $id[$key[$i]] = $rec[$key[$i]];
        }
    } else {
        $id = $rec[$key];
    }
    $insert = true;
    $auto = false;
    if ($id === 0 && array_key_exists("auto", $db_table[$table])) {
        $auto = true;
    } else {
        if (db_has_rec($table, $id)) {
            $insert = false;
        }
    }
    $a = array();
    if ($insert) {
        $sql = "insert into {$table} (";
        for ($i = 0; $i < count($col); $i++) {
            if (!$auto || $col[$i] != $key) {
                $sql .= $col[$i] . ", ";
                $a[] = $rec[$col[$i]];
            }
        }
        if ($auto) {
            $count = count($col) - 2;
        } else {
            $count = count($col) - 1;
        }
        $sql = substr($sql, 0, -2) . ") values (" . str_repeat("?, ", $count) . "?)";
        run_sql($sql, $a);
    } else {
        $sql = "update {$table} set ";
        for ($i = 0; $i < count($col); $i++) {
            $is_key = false;
            if (is_array($key)) {
                if (in_array($col[$i], $key)) {
                    $is_key = true;
                }
            } else {
                if ($col[$i] == $key) {
                    $is_key = true;
                }
            }
            if (!$is_key) {
                $sql .= $col[$i] . " = ?, ";
                $a[] = $rec[$col[$i]];
            }
        }
        $sql = substr($sql, 0, -2) . " where ";
        if (is_array($key)) {
            for ($i = 0; $i < count($key); $i++) {
                $sql .= $key[$i] . " = ? and ";
                $a[] = $rec[$key[$i]];
            }
            $sql = substr($sql, 0, -5);
        } else {
            $sql .= "{$key} = ?";
            $a[] = $id;
        }
        run_sql($sql, $a);
    }
    if ($cache_enabled) {
        $cache_key = "{$table}.rec.{$id}";
        cache_set($cache_key, map_to_conf_string($rec));
    }
}
示例#3
0
文件: add.php 项目: scarnago/pipecode
if ($col < 0 || $col > 2) {
    die("invalid col [{$col}]");
}
if (http_post()) {
    $fid = http_post_int("fid", array("required" => false));
    $uri = http_post_string("uri", array("required" => false, "len" => 100, "valid" => "[a-z][A-Z][0-9]~@#\$%&()-_=+[];:,./?"));
    if ($fid == 0) {
        if ($uri == "") {
            die("no feed uri given");
        }
        $fid = add_feed($uri);
    }
    if (!db_has_rec("feed", $fid)) {
        die("fid not found [{$fid}]");
    }
    if (db_has_rec("feed_user", array("zid" => $auth_zid, "fid" => $fid))) {
        die("feed [{$fid}] is already on your page");
    }
    $row = run_sql("select max(pos) as max_pos from feed_user where zid = ? and col = ?", array($auth_zid, $col));
    $pos = $row[0]["max_pos"] + 1;
    $feed_user = array();
    $feed_user["zid"] = $auth_zid;
    $feed_user["fid"] = $fid;
    $feed_user["col"] = $col;
    $feed_user["pos"] = $pos;
    db_set_rec("feed_user", $feed_user);
    header("Location: edit");
    die;
}
print_header();
writeln('<table class="fill">');
示例#4
0
function get_comment_score($cid)
{
    global $cache_enabled;
    //	if ($cache_enabled) {
    //		$cache_key = "comment_score.$cid";
    //		$s = cache_get($cache_key);
    //		if ($s !== false) {
    //			return $s;
    //		}
    //	}
    $row = run_sql("select sum(value) as score from comment_vote inner join reason on comment_vote.rid = reason.rid where cid = ?", array($cid));
    $score = (int) $row[0]["score"];
    if (db_has_rec("comment", $cid)) {
        $comment = db_get_rec("comment", $cid);
        if ($comment["zid"] != "") {
            $score++;
        }
    }
    if ($score < -1) {
        $score = -1;
    } else {
        if ($score > 5) {
            $score = 5;
        }
    }
    //$up = array("Insightful", "Interesting", "Informative", "Funny", "Underrated");
    //$down = array("Offtopic", "Flamebait", "Troll", "Redundant", "Overrated");
    $reason = "";
    $row = run_sql("select reason, count(reason) as reason_count, value from comment_vote inner join reason on comment_vote.rid = reason.rid where cid = ? group by reason order by value desc, reason_count desc", array($cid));
    for ($i = 0; $i < count($row); $i++) {
        if ($score < 0 && $row[$i]["value"] < 0 && $row[$i]["reason_count"] > 1 && $row[$i]["reason"] != "Overrated") {
            $reason = ", " . $row[$i]["reason"];
            break;
        }
        if ($score > 1 && $row[$i]["value"] > 0 && $row[$i]["reason_count"] > 1 && $row[$i]["reason"] != "Underrated") {
            $reason = ", " . $row[$i]["reason"];
            break;
        }
    }
    //	if ($cache_enabled) {
    //		cache_set($cache_key, "$score$reason");
    //	}
    return "{$score}{$reason}";
}
示例#5
0
function add_feed($uri)
{
    if (db_has_rec("feed", array("uri" => $uri))) {
        //die("feed already exists [$uri]");
        $feed = db_get_rec("feed", array("uri" => $uri));
        return $feed["fid"];
    }
    $data = download_feed($uri);
    $sp = new SimplePie();
    $sp->set_raw_data($data);
    $sp->init();
    $title = $sp->get_title();
    $link = get_feed_link($sp, $uri);
    $count = $sp->get_item_quantity();
    if (strlen($title) == 0 || $count == 0) {
        die("unable to parse feed [{$uri}]");
        //die("unable to parse feed [$uri] data [$data]");
    }
    $feed = array();
    $feed["fid"] = 0;
    $feed["time"] = time();
    $feed["uri"] = $uri;
    $feed["title"] = $title;
    $feed["link"] = $link;
    db_set_rec("feed", $feed);
    $feed = db_get_rec("feed", array("uri" => $uri));
    save_feed($feed["fid"], $data);
    return $feed["fid"];
}
示例#6
0
}
if (!db_has_rec("pipe", $pid)) {
    die("error: pipe not found [{$pid}]");
}
//var_dump($_POST);
//if (!empty(@$_POST["up_x"]) || !empty(@$_POST["down_x"])) {
if (array_key_exists("up_x", $_POST) || array_key_exists("down_x", $_POST) || array_key_exists("undo_x", $_POST)) {
    $redirect = true;
    $up = array_key_exists("up_x", $_POST);
    //die("up");
} else {
    $redirect = false;
    $up = http_post_int("up");
}
//die("here");
if (db_has_rec("pipe_vote", array("pid" => $pid, "zid" => $auth_zid))) {
    //$pipe_vote = db_get_rec("pipe_vote", array("pid" => $pid, "zid" => $auth_zid));
    //$value = $pipe_vote["value"];
    db_del_rec("pipe_vote", array("pid" => $pid, "zid" => $auth_zid));
    $result = "undone";
} else {
    if ($up) {
        $result = "up";
    } else {
        $result = "down";
    }
    $pipe_vote = array();
    $pipe_vote["pid"] = $pid;
    $pipe_vote["zid"] = $auth_zid;
    $pipe_vote["time"] = time();
    if ($up) {
示例#7
0
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pipecode.  If not, see <http://www.gnu.org/licenses/>.
//
include "render.php";
$cid = (int) $s2;
if (!http_post()) {
    die("error: post method required");
}
if ($auth_zid == "") {
    die("error: sign in to moderate");
}
if (!db_has_rec("comment", $cid)) {
    die("error: comment not found [{$cid}]");
}
if (db_has_rec("comment_vote", array("cid" => $cid, "zid" => $auth_zid))) {
    db_del_rec("comment_vote", array("cid" => $cid, "zid" => $auth_zid));
}
$rid = http_post_int("rid");
if ($rid > 0 && $rid <= 10) {
    $comment_vote = array();
    $comment_vote["cid"] = $cid;
    $comment_vote["zid"] = $auth_zid;
    $comment_vote["rid"] = $rid;
    $comment_vote["time"] = time();
    db_set_rec("comment_vote", $comment_vote);
}
$score = get_comment_score($cid);
writeln("{$cid} {$score}");
示例#8
0
     db_set_conf("user_conf", $user_conf, $zid);
     db_del_rec("email_challenge", $verify);
     print_header("Password Reset");
     writeln('<h1>Password Reset</h1>');
     writeln('<p>Don\'t forget it this time!</p>');
     print_footer();
     die;
 }
 $username = http_post_string("username", array("len" => 20, "valid" => "[a-z][A-Z][0-9]"));
 $zid = strtolower($username) . "@{$site_name}";
 if (!is_local_user($zid)) {
     die("no such user [{$zid}]");
 }
 $user_conf = db_get_conf("user_conf", $zid);
 $hash = crypt_sha256(rand());
 if (db_has_rec("email_challenge", array("username" => $username))) {
     db_del_rec("email_challenge", array("username" => $username));
 }
 $email_challenge = array();
 $email_challenge["challenge"] = $hash;
 $email_challenge["username"] = $username;
 $email_challenge["email"] = $user["email"];
 $email_challenge["expires"] = time() + 86400 * 3;
 db_set_rec("email_challenge", $email_challenge);
 $subject = "Forgot Password";
 $body = "Did you forget your password for \"{$username}\" on {$server_name}?\n";
 $body .= "\n";
 $body .= "In order to reset your password, you must visit the following link:\n";
 $body .= "\n";
 if ($https_enabled) {
     $body .= "https://{$server_name}/forgot?verify={$hash}\n";
示例#9
0
                 $aid = $keys[$i];
                 $score = (int) $aids[$aid];
                 if ($aids[$aid] === "0" || $score > $max) {
                     die("score out of bounds [{$score}]");
                 }
                 if ($score > 0) {
                     $scores[] = $score;
                 }
             }
             if (count($scores) !== count(array_unique($scores))) {
                 die("duplicate score detected");
             }
         }
     }
 }
 if (db_has_rec("poll_vote", array("qid" => $qid, "zid" => $auth_zid))) {
     run_sql("delete from poll_vote where qid = ? and zid = ?", array($qid, $auth_zid));
 }
 if ($type_id == 1) {
     run_sql("insert into poll_vote (qid, aid, zid, time) values (?, ?, ?, ?)", array($qid, $aid, $auth_zid, time()));
 } else {
     if ($type_id == 2) {
         for ($i = 0; $i < count($aids); $i++) {
             run_sql("insert into poll_vote (qid, aid, zid, time) values (?, ?, ?, ?)", array($qid, $aids[$i], $auth_zid, time()));
         }
     } else {
         if ($type_id == 3) {
             for ($i = 0; $i < count($aids); $i++) {
                 $aid = $keys[$i];
                 if ($aids[$aid] === "") {
                     $points = 0;