示例#1
0
function attachment_folder($contact, $ts, $relative = false)
{
    $folder = contact_name($contact);
    return ($relative ? '' : 'messages/' . $folder . '/') . date('Y-m', $ts) . '/';
}
    $last = 0;
    $fp = fopen($csv_file, 'a');
    fputcsv($fp, array('Timestamp', 'Date', 'Time', 'To', 'To Name', 'From', 'From Name', 'Message', 'Emoji', 'Attachments'));
}
$query = query_messages_since($db, $last);
$last_timestamp = 0;
while ($line = $query->fetch(PDO::FETCH_ASSOC)) {
    $attachment_query = $db->query('SELECT attachment.*
    FROM attachment 
    JOIN message_attachment_join ON message_attachment_join.attachment_id=attachment.ROWID
    WHERE message_attachment_join.message_id = ' . $line['ROWID']);
    $attachments = array();
    while ($attachment = $attachment_query->fetch(PDO::FETCH_ASSOC)) {
        $attachments[] = $attachment;
    }
    if ($line['is_from_me']) {
        $from = $me;
        $to = $line['contact'];
    } else {
        $from = $line['contact'];
        $to = $me;
    }
    $from_name = contact_name($from);
    $to_name = contact_name($to);
    $num_emoji = 0;
    if (preg_match_all('/(?:[0-9|#][\\x{20E3}])|[\\x{00ae}|\\x{00a9}|\\x{203C}|\\x{2047}|\\x{2048}|\\x{2049}|\\x{3030}|\\x{303D}|\\x{2139}|\\x{2122}|\\x{3297}|\\x{3299}][\\x{FE00}-\\x{FEFF}]?|[\\x{2190}-\\x{21FF}][\\x{FE00}-\\x{FEFF}]?|[\\x{2300}-\\x{23FF}][\\x{FE00}-\\x{FEFF}]?|[\\x{2460}-\\x{24FF}][\\x{FE00}-\\x{FEFF}]?|[\\x{25A0}-\\x{25FF}][\\x{FE00}-\\x{FEFF}]?|[\\x{2600}-\\x{27BF}][\\x{FE00}-\\x{FEFF}]?|[\\x{2900}-\\x{297F}][\\x{FE00}-\\x{FEFF}]?|[\\x{2B00}-\\x{2BF0}][\\x{FE00}-\\x{FEFF}]?|[\\x{1F000}-\\x{1F6FF}][\\x{FE00}-\\x{FEFF}]?/u', $line['text'], $matches)) {
        $num_emoji = count($matches[0]);
    }
    fputcsv($fp, array($line['date'], date('Y-m-d', $line['date']), date('H:i:s', $line['date']), $from, $from_name, $to, $to_name, trim($line['text']), $num_emoji, count($attachments)));
}
fclose($fp);