forked from 7foots/Flava2DayOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flava.php
116 lines (95 loc) · 3.01 KB
/
flava.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
include("PlistParser.inc");
$db = new SQLite3('flava.db');
$results = $db->query('SELECT * FROM notes WHERE 1');
$entries = 0;
$photos = 0;
while ($row = $results->fetchArray())
{
$date = (int)$row['created_date'];
$datetime = system('date -r "'.$date.'"');
$title = $row['title'];
$contents = $row['contents'];
$user_latitude = $row['user_latitude'];
$user_longitude = $row['user_longitude'];
$text_tags = $row['text_tags'];
$photo_file = $row['photo_file'];
if (substr($contents, 0, strlen($title)) != $title)
{
$contents = $title."\n\n".$contents;
}
echo "\033[47m\n\033[0m\n\n";
echo "\033[31m".$row['idx']."\033[0m\n";
echo "\033[32m".$datetime."\033[0m\n";
echo "\033[30m".$contents."\033[0m\n";
if ($user_latitude != 360 && $user_longitude != 360)
{
echo "\033[33m".$user_latitude.', '.$user_longitude."\033[0m\n";
}
echo "\033[34m".$text_tags."\033[0m\n";
echo "\033[35m".$photo_file."\033[0m\n";
$options = ' -d="'.$datetime.'"';
if ($photo_file != '')
{
$photo_file_path = dirname(__FILE__).'/Photo/'.$photo_file;
$options .= ' -p="'.$photo_file_path.'"';
}
$newentry = system('echo "'.$contents.'" | dayone '.$options.' new');
$newentry = str_replace('New entry : ~/', '', $newentry);
$newentry = system('ls ~/"'.$newentry.'"');
$parser = new plistParser();
$plist = $parser->parseFile($newentry);
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Creation Date</key>
<date>'.$plist['Creation Date'].'</date>
<key>Entry Text</key>
<string>'.$plist['Entry Text'].'</string>
<key>Starred</key>
<false/>
<key>Tags</key>
<array>'.Tags($text_tags).'</array>
'.Location($user_latitude, $user_longitude).'
<key>UUID</key>
<string>'.$plist['UUID'].'</string>
</dict>
</plist>';
file_put_contents($newentry, $xml);
$entries++;
if ($photo_file != '')
{
$photos++;
}
}
echo "\033[1;32m\033[40m\nComplete!\nExported: ".$entries.' notes and '.$photos." photos \033[0m\n";
function Tags($tags)
{
$tags = trim($tags);
if ($tags == '')
{
return '';
}
$res = explode('|', $tags);
$return = '';
foreach ($res as $key => $value) {
$return .= "\t\t\t<string>".$value."</string>\n";
}
return $return;
}
function Location($user_latitude, $user_longitude)
{
if ($user_latitude == 360 && $user_longitude == 360)
{
return '';
}
return '<key>Location</key>
<dict>
<key>Latitude</key>
<real>'.$user_latitude.'</real>
<key>Longitude</key>
<real>'.$user_longitude.'</real>
</dict>';
}
?>