Skip to content

Commit 35237e5

Browse files
committed
Merge pull request #78 from Fmstrat/csp
Csp and API fixes
2 parents 80ae822 + 7b86943 commit 35237e5

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
## Installation
44
- Place this app in **owncloud/apps/ownnote** (Rename the extracted ZIP to "ownnote" or you will receive errors)
5-
- Add the following to your **owncloud/config/config.php**:
6-
- 'custom_csp_policy' => "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src *; font-src 'self' data:; media-src *",
5+
- Note: *custom_csp_policy* changes are no longer required
76

87
## Mobile Apps
98
ownNote for Android in the Google Play store: http://goo.gl/pHjQY9

js/script.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
origNote = tinymce.activeEditor.getContent();
107107
idleIterval = setInterval(timerIncrement, checkDuration*1000);
108108
$(document).mousemove(function (e) { notIdle(); });
109-
$(document).keypress(function (e) { noteIdle(); });
109+
$(document).keypress(function (e) { notIdle(); });
110110
$('#editable_ifr').contents().find("body").mousemove(function (e) { notIdle(); });
111111
tinymce.activeEditor.on('keyup', function(e) { notIdle(); });
112112
}
@@ -640,8 +640,14 @@
640640
}
641641
}
642642

643+
var disableAnnouncement = "";
644+
function getSettings() {
645+
disableAnnouncement = $('#disableAnnouncement').val();
646+
}
647+
643648
$(document).ready(function() {
644649
$.ajaxSetup ({ cache: false });
650+
getSettings();
645651
loadListing();
646652
});
647653

lib/backend.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,31 @@ function getTimeString($filetime, $now) {
108108

109109
function getListing($FOLDER, $showdel) {
110110
// Get the listing from the database
111+
$requery = false;
111112
$uid = \OCP\User::getUser();
112113
$query = OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
113114
$results = $query->execute(Array($uid))->fetchAll();
115+
$results2 = $results;
116+
if ($results)
117+
foreach($results as $result)
118+
foreach($results2 as $result2)
119+
if ($result['id'] != $result2['id'] && $result['name'] == $result2['name'] && $result['grouping'] == $result2['grouping'] && $result['mtime'] == $result2['mtime']) {
120+
// We have a duplicate that should not exist. Need to remove the offending record first
121+
$delid = $result['id'];
122+
if ($result['id'] > $result2['id'])
123+
$delid = $result2['id'];
124+
$delquery = OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE id=?");
125+
$delquery->execute(Array($delid));
126+
$requery = true;
127+
}
128+
if ($requery) {
129+
$query = OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
130+
$results = $query->execute(Array($uid))->fetchAll();
131+
$requery = false;
132+
}
114133
// Create directory if it doesn't exist
115134
$farray = array();
116135
if ($FOLDER != '') {
117-
$requery = false;
118136
// Create the folder if it doesn't exist
119137
if (!\OC\Files\Filesystem::is_dir($FOLDER)) {
120138
if (!\OC\Files\Filesystem::mkdir($FOLDER)) {
@@ -298,6 +316,18 @@ function saveNote($FOLDER, $name, $group, $content) {
298316
$now = new DateTime();
299317
$mtime = $now->getTimestamp();
300318
$uid = \OCP\User::getUser();
319+
// First check to see if we're creating a new note, createNote handles all of this
320+
createNote($FOLDER, $name, $group);
321+
//$query = OCP\DB::prepare("SELECT note FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
322+
//$results = $query->execute(Array($uid, $name, $group))->fetchAll();
323+
//$indb = false;
324+
//$deldb = false;
325+
//foreach($results as $result) {
326+
//$indb = true;
327+
//if ($result['deleted'] == 1)
328+
//$deldb = true;
329+
//}AAA
330+
// Then save
301331
if ($FOLDER != '') {
302332
$tmpfile = $FOLDER."/".$name.".htm";
303333
if ($group != '')
@@ -315,9 +345,9 @@ function saveNote($FOLDER, $name, $group, $content) {
315345
function renameNote($FOLDER, $name, $group, $newname, $newgroup) {
316346
// We actually need to delete and create so that the delete flag exists for syncing clients
317347
$content = editNote($name, $group);
348+
deleteNote($FOLDER, $name, $group);
318349
createNote($FOLDER, $newname, $newgroup);
319350
saveNote($FOLDER, $newname, $newgroup, $content);
320-
deleteNote($FOLDER, $name, $group);
321351
return "DONE";
322352
}
323353

templates/main.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
\OCP\Util::addStyle('ownnote', 'style');
55

66
$disableAnnouncement = \OCP\Config::getAppValue('ownnote', 'disableAnnouncement', '');
7-
87
?>
9-
108
<div id="app">
11-
<script>
12-
var disableAnnouncement = "<?php echo $disableAnnouncement; ?>";
13-
</script>
149
<div id="app-navigation">
1510
<ul id="grouplist">
1611
</ul>
1712
</div>
1813
<div id="app-content">
1914
<div id="ownnote"></div>
2015
</div>
16+
<input type=hidden value="<?php echo $disableAnnouncement; ?>">
2117
</div>

0 commit comments

Comments
 (0)