예제 #1
0
}
//doesn't work
function autolink($content)
{
    $re = '/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/';
    $content = preg_replace($re, '<a href="$0" rel="nofollow">$0</a>', $content);
    return $content;
}
$submittedanswer = autolink($submittedanswer);
$submittedanswer = str_replace("\n", '\\-n', $submittedanswer);
for ($seeifalreadyanswered = 10; $seeifalreadyanswered < count($lines); $seeifalreadyanswered++) {
    $individualparts = preg_split("/(!n!)/", $lines[$seeifalreadyanswered], -1, PREG_SPLIT_DELIM_CAPTURE);
    if ($individualparts[6] == $username) {
        exit("You've already answered!");
    }
}
$submittedanswer = strip_tags($submittedanswer);
$submittedanswer = str_replace("!n!", '', $submittedanswer);
$submittedanswer = str_replace("!c!", '', $submittedanswer);
//sanitaze stuff here
array_push($lines, "\n" . "0!n!.!f!.!n!.!n!" . $username . "!n!" . $submittedanswer);
file_put_contents($filename, $lines);
$filename = substr($filename, 0, strlen($filename) - 4);
$title = $filename;
$title = $title . ".php";
echo "/misconception/questions/" . $title;
$title = decodeURIComponent($title);
$contentoffile = file_get_contents($title);
//removed <addanswer> in index.php for testing
$contentoffile = str_replace("<addanswer></addanswer>", '<div class="solutionsdiv"><pre class="answer" id=' . $username . '></pre><?php include "answer-structure.php"; ?><addanswer></addanswer>', $contentoffile);
file_put_contents($title, $contentoffile);
예제 #2
0
    $query = $con->prepare("SELECT * FROM srating where title = :questiontitle");
    $query->bindParam(':questiontitle', $filename);
    $query->execute();
    $data = $query->fetch(PDO::FETCH_ASSOC);
    $newrating = $data['rating'];
    $newrating = $newrating - 8;
    $sql = "UPDATE srating SET rating=:newrating WHERE title=:questiontitle";
    $stmt = $con->prepare($sql);
    $stmt->bindParam(':questiontitle', $filename);
    $stmt->bindParam(':newrating', $newrating);
    $stmt->execute();
} else {
    $individualparts[0] = $individualparts[0] + 1;
    $individualparts[2] = "~" . $username . "~" . $individualparts[2];
    $lines[6] = implode($individualparts);
    file_put_contents($filename, $lines);
    echo "inserted username";
    $filename = substr($filename, 0, -4);
    $filename = decodeURIComponent($filename);
    $query = $con->prepare("SELECT * FROM srating where title = :questiontitle");
    $query->bindParam(':questiontitle', $filename);
    $query->execute();
    $data = $query->fetch(PDO::FETCH_ASSOC);
    $newrating = $data['rating'];
    $newrating = $newrating + 8;
    $sql = "UPDATE srating SET rating=:newrating WHERE title=:questiontitle";
    $stmt = $con->prepare($sql);
    $stmt->bindParam(':questiontitle', $filename);
    $stmt->bindParam(':newrating', $newrating);
    $stmt->execute();
}
예제 #3
0



</html>');
fclose($fp);
//make the txt file that holds the info
$misconceptiontitle = encodeURIComponent($misconceptiontitle);
$fm = fopen($_SERVER['DOCUMENT_ROOT'] . "/misconception/questions/" . $misconceptiontitle . ".txt", "wb");
fwrite($fm, '0' . "\n" . "\n" . "\n" . '0!n!~undefined~' . "\n" . date("M") . " " . date("j") . ',' . date("Y") . "\n" . date("M") . " " . date("j") . ',' . date("Y") . "!n!" . "\n" . '0' . "!n!" . "~undefined~" . "\n" . ',undefined,' . "\n" . $username . "\n" . $whatyouthinkyouknow . "!n!");
fclose($fm);
$ratingval = 0;
include '../config.php';
$con = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . '', DB_USER, DB_PASSWORD);
$tagsinstring = implode(',', $tagarray);
$misconceptiontitle = decodeURIComponent($misconceptiontitle);
$query = $con->prepare("INSERT INTO srating (title, rating, tags) VALUES (:title,:rating,:tags) ");
//bind parameters
$query->bindParam(':title', $misconceptiontitle);
$query->bindParam(':rating', $ratingval);
// for everytag that a thing has, give it an increased rating by one
$query->bindParam(':tags', $tagsinstring);
$query->execute();
//update user rep cause htey'd asked a question
$uquery = $con->prepare("SELECT * FROM accounts where username = :questionowner");
$uquery->bindParam(':questionowner', $username);
$uquery->execute();
$data = $uquery->fetch(PDO::FETCH_ASSOC);
$newrep = $data['reputation'];
$newrep = $newrep + 5;
$stmt = $con->prepare("UPDATE accounts SET reputation=:newrep WHERE username=:questionowner");
예제 #4
0
 public function auth($username = "", $password = "")
 {
     $output = "";
     $d_username = decodeURIComponent($username);
     $d_password = decodeURIComponent($password);
     $this->log_debug("Authorizing as " . $d_username);
     $r = $this->executeCommand(new initConnectionCommand($d_username, $d_password), true);
     if ($r == NULL) {
         return $this->addExtraOutput("");
     }
     if ($r instanceof errorCommand) {
         $this->log_error($r->getMessage(), BTG::ERR_INITCONNECTION);
     } else {
         if ($r instanceof ackCommand) {
             $this->log_debug("Authorized as {$d_username}.");
             $this->username = $username;
             $_SESSION['btg_username'] = $this->username;
             // Maybee we should save hash instead?
             $_SESSION['btg_password'] = $password;
             $output .= "<ack/>";
         }
     }
     return $this->addExtraOutput($output);
 }
예제 #5
0
    $currentquery = $orderedarray[$querynumber];
    for ($unorderedquery = 0; $unorderedquery < count($orderedarray); $unorderedquery++) {
        $individualparts = explode("~!~", $firstsearcharray[$unorderedquery]);
        if ($individualparts[0] == $currentquery) {
            $individualparts[1] = decodeURIComponent($individualparts[1]);
            $query = $con->prepare("SELECT * FROM srating WHERE title = :misconceptionname");
            $query->bindParam(':misconceptionname', $individualparts[1]);
            $query->execute();
            $data = $query->fetch(PDO::FETCH_ASSOC);
            $repofanswers = $data['repofanswers'];
            $views = $data['views'];
            $tags = $data['tags'];
            $individualparts[1] = encodeURIComponent($individualparts[1]);
            $lines = file("../questions/" . $individualparts[1] . ".txt");
            // turn it back to spaces for client side
            $individualparts[1] = decodeURIComponent($individualparts[1]);
            $questionrep = $lines[0];
            $whatithinkiknow = preg_split("/(!n!)/", $lines[9], -1, PREG_SPLIT_DELIM_CAPTURE);
            //$questionrep = data['questionrep'];
            $compiledinfo = $repofanswers . "~!~" . $views . "~!~" . $tags . "~!~" . $questionrep . "~!~" . $individualparts[1] . "~!~" . $whatithinkiknow[0];
            $compiledinfo = str_replace("\n", "", $compiledinfo);
            array_push($searchquerydata, $compiledinfo);
        }
    }
}
echo json_encode(array_values($searchquerydata));
//push $current query into firstsearcharray
//once we do that we look into the relavent titles (first search array) and see the number of accurances does our token show up
//for loop
//loop through every single key in first search array and count the number of accurances with substr_count() basically search for the tokens and cout them
//    we add up the counts of the words to give it our "search rank"(we should multiply this number by 4 so each accurance of a word is less than an upvote)