public function isMatch($URL) { //Check if we're forcing a new URL $forcingNewAnalysis = $URL == $this->getNewAnalysisURL(); //Are they matching the URL? $isMatchingURL = $URL == $this->getURL() || $forcingNewAnalysis; //Are they logged in? $isLoggedIn = $this->user->isLoggedIn(); if ($isMatchingURL && $isLoggedIn) { //Only start considering if it's a match here as we need to query the database after this. $dbh = Engine::getDatabase(); //If this user exists in the database, they have used our application //before and an analysis would have been created on authentication $this->userExists = $dbh->query("SELECT * FROM Users WHERE User_ID=" . $this->user->id)->fetch(PDO::FETCH_ASSOC) != null; if (!$forcingNewAnalysis && $this->userExists) { ob_clean(); header("Location: " . Engine::getRemoteAbsolutePath((new Account())->getURL())); exit; } if (!$this->userExists) { $dbh->exec("INSERT INTO Users (User_ID, Name, Email) VALUES ('" . User::instance()->id . "', '" . User::instance()->name . "', '" . User::instance()->email . "')"); } //Otherwise, we are a new user and we don't need to force a new analysis return true; } else { if ($isMatchingURL && !$isLoggedIn) { //Go back home as we're not authenticated. require 'login.php'; } else { //Wasn't a match at all. return false; } } }
public function show($template) { $this->template = $template; include "section/header.php"; if (isset($_POST['action']) && $_POST['action'] == "confirm" && isset($_POST['confirm']) && $_POST['confirm'] == "Yes, delete my account") { $this->deleteAccount(Engine::getDatabase()); } if (isset($this->URLMatch[2]) && $this->URLMatch[2] == "delete") { include "section/middle_user_deletion.php"; } else { include "section/middle_account.php"; } include "section/footer.php"; }
public function load($Result_ID) { //TODO - return either null or a Result object. //Get the database $dbh = Engine::getDatabase(); $sql = "SELECT \n\t\t\t\tResults.Result_ID, \n\t\t\t\tUNIX_TIMESTAMP(Results.DATE) AS Date, \n\t\t\t\tResults.Data, \n\t\t\t\tResults.Visible, \n\t\t\t\tUsers.Name,\n\t\t\t\tUsers.User_ID\n\t\t\tFROM Results \n\t\t\t\tINNER JOIN Result_History\n\t\t\t\t\tON Results.Result_ID=Result_History.Result_ID\n\t\t\t\tINNER JOIN Users\n\t\t\t\t\tON Result_History.User_ID=Users.User_ID \n\t\t\tWHERE \n\t\t\t\tResults.Result_ID = :result AND \n\t\t\t\t(Results.Visible " . (User::instance()->isLoggedIn() ? "OR Users.User_ID='" . User::instance()->id . "'" : "") . ") \n\t\t\tLIMIT 1\n\t\t"; $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $stmt->execute(array(':result' => $Result_ID)); //Get the result into an object $result = $stmt->fetch(PDO::FETCH_ASSOC); if ($result) { (new ReflectiveObject())->copy($result, $this); $this->Data = json_decode($this->Data, true); return true; } else { return false; } }
public function run($template) { //Remove the whole string as the first result array_shift($this->URLMatch); //Get the database $dbh = Engine::getDatabase(); //Get result ID $resultID = $this->URLMatch[0]; //Check if the result is in the array and return results $sql = "SELECT * FROM Results WHERE Result_ID IN (SELECT Result_ID FROM Result_History WHERE Result_ID= :result) LIMIT 1"; $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $stmt->execute(array(':result' => $resultID)); $result = $stmt->fetchObject('Result'); if ($result == false) { exit; } //There's no result to give an image for $result->Data = json_decode($result->Data, true); $data = $result->Data; $blueBackground = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/share-background.png', "r")); $friends = array_keys($data['interaction']); $friend1 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[0]))); //200,200 (width x height) $friend2 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[1]))); $friend3 = imagecreatefromstring(file_get_contents(User::getAvatar($friends[2]))); $gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)); for ($i = 0; $i < 60; $i++) { imageconvolution($friend1, $gaussian, 16, 0); imageconvolution($friend2, $gaussian, 16, 0); imageconvolution($friend3, $gaussian, 16, 0); } $graph = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/white-logo-transparent-medium.png', "r")); $foreground = imagecreatefromstring(file_get_contents(__DIR__ . '/../public/images/share-foreground.png', "r")); imagecopy($blueBackground, $friend1, -50, 25, 0, 0, imagesx($friend1), imagesy($friend1)); imagecopy($blueBackground, $friend2, 150, 25, 0, 0, imagesx($friend2), imagesy($friend2)); imagecopy($blueBackground, $friend3, 350, 25, 0, 0, imagesx($friend3), imagesy($friend3)); $graph = imagescale($graph, imagesx($friend1) * 2); imagecopy($blueBackground, $graph, 80, -20, 0, 0, imagesx($graph), imagesy($graph)); imagecopy($blueBackground, $foreground, 0, 0, 0, 0, imagesx($foreground), imagesy($foreground)); ob_clean(); ob_start(); header('Content-Type: image/png'); imagepng($blueBackground); }
public function configure($setup) { try { $dbh = Engine::getDatabase(); //When we create these tables, we assume they're not already created, if they are, //we delete them and start anew as it's easier than just ignoring and potentially //not having these relationships with the data //Delete all tables $dbh->exec("DROP TABLE IF EXISTS Result_History; DROP TABLE IF EXISTS Results;DROP TABLE IF EXISTS Users;"); //Setup all tables $dbh->exec("CREATE TABLE Results (Result_ID VARCHAR(64) NOT NULL, Date datetime NOT NULL, Data text NOT NULL, Visible BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (Result_ID), KEY (Result_ID)) ENGINE=InnoDB DEFAULT CHARSET=latin1"); $dbh->exec("CREATE TABLE Users ( User_ID VARCHAR(64) NOT NULL, Name text NOT NULL, Email text NOT NULL, PRIMARY KEY (User_ID), KEY (User_ID)) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $dbh->exec("CREATE TABLE Result_History ( History_ID int(32) NOT NULL, User_ID VARCHAR(64) NOT NULL, Result_ID VARCHAR(64) NOT NULL, PRIMARY KEY (History_ID)) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $dbh->exec("ALTER TABLE Result_History ADD UNIQUE (Result_ID);"); //create relationships between tables $dbh->exec("ALTER TABLE Result_History ADD CONSTRAINT FOREIGN KEY (User_ID) REFERENCES Users(User_ID) ON DELETE CASCADE;ALTER TABLE Result_History ADD CONSTRAINT FOREIGN KEY (User_ID) REFERENCES Users(User_ID) ON DELETE CASCADE;ALTER TABLE Results ADD FOREIGN KEY (Result_ID) REFERENCES Result_History(Result_ID) ON DELETE CASCADE ON UPDATE CASCADE;"); $dbh->exec("ALTER TABLE Result_History ADD FOREIGN KEY (Result_ID) REFERENCES Results(Result_ID) ON DELETE CASCADE ON UPDATE RESTRICT;"); //Make sure we increment history $dbh->exec("ALTER TABLE Result_History MODIFY History_ID int(32) NOT NULL AUTO_INCREMENT;"); } catch (PDOException $e) { $setup->sendStatus(true, array($setup->addName("template-config-error"), "error_message" => $e->getMessage())); } }