Exemplo n.º 1
0
function register($username, $password)
{
    global $error_message;
    $db = new Database(df_db());
    try {
        $res = $db->insertObject("users", (object) array('username' => $username, 'password' => $password));
        $res = $db->insertObject("profiles", (object) array('username' => $username, 'screen_name' => $username));
        return true;
    } catch (Exception $ex) {
        $error_message = $ex->getMessage();
        return false;
    }
}
Exemplo n.º 2
0
function post($token = null, $comment, $uploaded_image_path)
{
    $db = new Database(df_db());
    global $error_message;
    $user = get_user($token);
    if (!$user) {
        $error_message = "Not logged in";
        return false;
    }
    $filename = null;
    if (@$uploaded_image_path) {
        $imagesDir = 'uploads';
        @mkdir($imagesDir);
        $imagesDir = 'uploads/' . sha1($user);
        @mkdir($imagesDir);
        $filename = time() . basename($uploaded_image_path) . '.png';
        if (!move_uploaded_file($uploaded_image_path, $imagesDir . '/' . $filename)) {
            $error_message = "Failed to upload file";
            return false;
        }
    }
    try {
        $res = $db->insertObject("posts", (object) array('username' => $user, 'date_posted' => time(), 'photo' => $filename, 'comment' => $comment));
        return xf_db_insert_id(df_db());
    } catch (Exception $ex) {
        $error_message = $ex->getMessage();
        return false;
    }
}