function write_user_info($user_id, $content, $root_folder)
{
    global $bad_word_list;
    $file_name = "data/" . $root_folder . "/user/" . $user_id . ".json";
    if (file_exists($file_name) == false) {
        $file = fopen($file_name, "w") or die($file_name);
        fclose($file);
        chmod($file_name, 0777);
        $data = array("messages" => array(), "messages_no" => 0, "bad_words" => array(), "bad_words_no" => 0, "weight" => 0, "location" => array());
        file_put_contents($file_name, json_encode($data));
    }
    $data_string = file_get_contents($file_name);
    $data = json_decode($data_string, true);
    $tmp_item = json_decode($content, true);
    var_dump($tmp_item);
    array_push($data["messages"], $tmp_item['text']);
    $mess_no = $data["messages_no"];
    $data["messages_no"] = $mess_no + 1;
    $bad_word_no = $data['bad_words_no'];
    $data['bad_words_no'] = $bad_word_no + count_bad_word_in_message($bad_word_list, $tmp_item['text']);
    // $data ['location'] = $tmp_item ['geo'] ['coordinates'];
    if ($tmp_item['geo']['coordinates'] != null) {
        $data['location'] = array_merge($data['location'], $tmp_item['geo']['coordinates']);
    }
    file_put_contents($file_name, json_encode($data));
}
function write_user_info($user_id, $content, $root_folder)
{
    global $bad_word_list;
    $file_name = "data/" . $root_folder . "/user/" . $user_id . ".json";
    echo $file_name;
    if (file_exists($file_name) == false) {
        $file = fopen($file_name, "w") or die($file_name);
        fclose($file);
        chmod($file_name, 0777);
        $data = array("messages" => array(), "messages_no" => 0, "bad_words" => array(), "bad_words_no" => 0, "weight" => 0, "location" => array(), "friends" => array());
        file_put_contents($file_name, json_encode($data));
    }
    $data_string = file_get_contents($file_name);
    $data = json_decode($data_string, true);
    $tmp_item = json_decode($content, true);
    var_dump($tmp_item);
    array_push($data["messages"], $tmp_item['text']);
    $mess_no = $data["messages_no"];
    $data["messages_no"] = $mess_no + 1;
    $bad_word_no = $data['bad_words_no'];
    $data['bad_words_no'] = $bad_word_no + count_bad_word_in_message($bad_word_list, $tmp_item['text']);
    //add dummy location data for user's friends
    /*
    42.080617734132, -93.26355664062498
    40.629301849760935, -87.70447460937498
    33.04404077043604, -112.13806835937498
    30.957267749065043, -95.293287109375
    */
    $data['friends'][0] = 1;
    $data['friends'][1] = 2;
    $data['friends'][2] = 3;
    $data['friends'][3] = 4;
    // $data ['location'] = $tmp_item ['geo'] ['coordinates'];
    if ($tmp_item['geo']['coordinates'] != null) {
        // $data ['location'] = array_merge ( $data ['location'], $tmp_item ['geo'] ['coordinates'] );
        $data['location'][count($data['location'])] = $tmp_item['geo']['coordinates'];
    }
    file_put_contents($file_name, json_encode($data));
}