diff --git a/README.md b/README.md new file mode 100644 index 0000000..5cc82be --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +HTML5 Notepad App +by Kaspars Dambis (http://konstruktors.com) +Fork by BenoƮt HERVIER (http://khertan.net) + +Fork addition : +============ +* Added support for devices without accurate time set, by adding a time delta to +the synchronization process. +* Created a QML Harmattan client for use on Nokia n950 and Nokia n9 + +Planned feature : +============ +* Multi account support + +Installation +============ + +1. Upload files to your server +2. Rename 'entries' folder to something random and harder to guess +3. Make that folder writable (CHMOD 0777) +4. Edit sync.php and specify your new DATA_DIR (the one you just renamed) +5. In sync.php change username and password to something unique +6. Done! + diff --git a/README.txt b/README.txt deleted file mode 100644 index c731c8a..0000000 --- a/README.txt +++ /dev/null @@ -1,14 +0,0 @@ -HTML5 Notepad App -by Kaspars Dambis -http://konstruktors.com - -Installation -============ - -1. Upload files to your server -2. Rename 'entries' folder to something random and harder to guess -3. Make that folder writable (CHMOD 0777) -4. Edit sync.php and specify your new DATA_DIR (the one you just renamed) -5. In sync.php change username and password to something unique -6. Done! - diff --git a/cache.manifest.php b/cache.manifest.php index ccfcb97..582828f 100644 --- a/cache.manifest.php +++ b/cache.manifest.php @@ -1,6 +1,6 @@ CACHE MANIFEST -# v20121 +# v20122 CACHE: index.html @@ -14,4 +14,4 @@ NETWORK: sync.php -logout.php \ No newline at end of file +logout.php diff --git a/html5-notepad-app-chrome.zip b/html5-notepad-app-chrome.zip deleted file mode 100644 index 955fa15..0000000 Binary files a/html5-notepad-app-chrome.zip and /dev/null differ diff --git a/index.html b/index.html index 4666288..42417b4 100644 --- a/index.html +++ b/index.html @@ -228,6 +228,7 @@ function sync() { if (navigator.onLine) { + localStorage.setItem('clientime', (new Date().getTime() + '')); $.post('sync.php', localStorage, function(data) { console.log(data); localStorage.setItem('index', JSON.stringify(data.index)); @@ -276,7 +277,7 @@ if (title === '') title = 'Untitled'; if (val['timestamp'] !== 0) - $items.push('
  • ' + title + ' -
  • '); + $items.push('
  • ' + title + ' -
  • '); }); $('#entries ul').hide().html($items.reverse().join('')).show(); } @@ -306,4 +307,4 @@ - \ No newline at end of file + diff --git a/js/coreyti-showdown/.gitignore b/js/coreyti-showdown/.gitignore old mode 100755 new mode 100644 diff --git a/js/coreyti-showdown/license.txt b/js/coreyti-showdown/license.txt old mode 100755 new mode 100644 diff --git a/js/coreyti-showdown/showdown.js b/js/coreyti-showdown/showdown.js old mode 100755 new mode 100644 diff --git a/sync.php b/sync.php index 5b76116..24f8c3a 100644 --- a/sync.php +++ b/sync.php @@ -3,9 +3,29 @@ error_reporting(E_ERROR); define('DATA_DIR', 'entries'); // use this to protect files from being publicly viewable -define("USERNAME", 'demo'); +define('USERNAME', 'demo'); define('PASSWORD', 'demo'); +// Parse incoming data +if (isset($_POST['clientTime'])) { + $time_delta = time() - bigintval($_POST['clientTime']); + unset($_POST['clientTime']);} +else { + $time_delta = 0;} + +if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) { + list($name, $password) = explode(':', base64_decode($matches[1])); + $_SERVER['PHP_AUTH_USER'] = strip_tags($name); + $_SERVER['PHP_AUTH_PW'] = strip_tags($password); +} + +//set http auth headers for apache+php-cgi work around if variable gets renamed by apache +if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) { + list($name, $password) = explode(':', base64_decode($matches[1])); + $_SERVER['PHP_AUTH_USER'] = strip_tags($name); + $_SERVER['PHP_AUTH_PW'] = strip_tags($password); +} + if (($_SERVER['PHP_AUTH_USER'] !== USERNAME) || ($_SERVER['PHP_AUTH_PW'] !== PASSWORD)) { header('WWW-Authenticate: Basic realm="Cloud Notes"'); header('HTTP/1.0 401 Unauthorized'); @@ -14,8 +34,6 @@ header('Content-type: application/json; charset=utf-8'); -// Parse incoming data - $remote_index = (array)json_decode(stripslashes($_POST['index']), true); unset($_POST['index']); $remote_entries = $_POST; @@ -46,23 +64,27 @@ delete_entry($id); unset($remote_index[$id]); unset($remote_entries[$id]); - } elseif ($item['timestamp'] > $local_index[$id]['timestamp']) { + } elseif (strval(bigintval($item['timestamp'])) - $time_delta > $local_index[$id]['timestamp']) { // Remote entry is newer, replace it and don't send it back $local_index[$id] = $item; + $local_index[$id]['timestamp'] = strval(bigintval($local_index[$id]['timestamp']) - $time_delta); store_entry($id, $_POST[$id]); unset($remote_entries[$id]); unset($local_entries[$id]); - } elseif ($item['timestamp'] == $local_index[$id]['timestamp']) { + } elseif (strval(bigintval($item['timestamp'])) - $time_delta == $local_index[$id]['timestamp']) { // Local entry is already the latest, don't send it back unset($remote_entries[$id]); unset($local_entries[$id]); } else { // Local entry is newer, send it back $remote_index[$id] = $local_index[$id]; + $remote_index[$id]['timestamp'] = strval(bigintval($remote_index[$id]['timestamp']) + $time_delta); $remote_entries[$id] = get_entry($id); + } } else { $local_index[$id] = $remote_index[$id]; + $local_index[$id]['timestamp'] = strval(bigintval($local_index[$id]['timestamp']) - $time_delta); store_entry($id, $_POST[$id]); unset($remote_entries[$id]); } @@ -73,6 +95,7 @@ if ($local_index[$id]['timestamp'] !== 0) { $remote_entries[$id] = get_entry($id); $remote_index[$id] = $local_index[$id]; + $remote_index[$id]['timestamp'] = strval(bigintval($remote_index[$id]['timestamp']) + $time_delta); } else { unset($remote_entries[$id]); unset($remote_index[$id]); @@ -87,6 +110,18 @@ // Helpers +function bigintval($value) { + $value = trim($value); + if (ctype_digit($value)) { + return $value; + } + $value = preg_replace("/[^0-9](.*)$/", '', $value); + if (ctype_digit($value)) { + return $value; + } + return 0; +} + function get_entry($id) { $file = DATA_DIR . '/' . $id; if (file_exists($file)) { @@ -136,4 +171,4 @@ function get_entries() { return json_encode($entries); } -?> \ No newline at end of file +?>