function logout($token = null) { global $error_message; $db = new Database(df_db()); if (!isset($token)) { $token = $_POST['token']; } if (!$token) { $error_message = "No token provided"; return false; } $res = $db->query("delete from sessions where token_id=:token", array('token' => $token)); return true; }
function unfriend($token = null, $friend_username = null) { global $error_message; $db = new Database(df_db()); $user = get_user($token); if (!$user) { $error_message = "You are not logged in"; return false; } if (!isset($friend_username)) { $friend_username = $_POST['friend_username']; } if (!$friend_username) { $error_message = "No friend username supplied"; return false; } if ($friend_username == $user) { $error_message = "Cannot unfriend oneself"; return false; } $user1 = min($friend_username, $user); $user2 = max($friend_username, $user); try { $res = $db->query("delete from friends f where f.user1=:user1 and f.user2=:user2", array('user1' => $user1, 'user2' => $user2)); return true; } catch (Exception $ex) { $error_message = $ex->getMessage(); return false; } }
public static function createPortletWithSQL($sql, $cols = null, $opts = array()) { $db = new Database(df_db()); if (is_array($sql)) { if (count($sql) > 1) { $queryParams = $sql[1]; } else { $queryParams = array(); } $sql = $sql[0]; } $rows = $db->query($sql, (object) $queryParams); return new Portlet($rows, $cols, $opts); }