Skip to content

Commit 0cd3463

Browse files
committed
Simplified path configuration
1 parent c5b759c commit 0cd3463

File tree

5 files changed

+28
-46
lines changed

5 files changed

+28
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
### v2.0.6
2-
- Removed fontawesome
2+
- Added contextmenu
33
- Updated easyMDE to v2.14.0
44
- Updated tagify to v3.22.3
5-
- Added contextmenu
65
- Fixed tag tooltips
76
- Fixed error message with empty noteslist
7+
- Removed fontawesome
8+
- Simplified path configuration
89

910
### v2.0.5
1011
- Added function to change YAML metadata

config.inc.php.dist

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
2-
$config['notes_basepath'] = '/path/to/server/folder/'; // absolute base! path where your notes are stored
3-
$config['notes_folder'] = '/files/Notes/'; // notes folder under basepath. in the end the folder is calculated by 'basepath' + 'username' + 'notes_folder'
2+
$config['notes_path'] = '/path/to/server/folder/%u/files/Notes'; // path to your notes, use %u for username
43
$config['media_folder'] = '.media'; // folder to store embedded images or binary file like *.pdf
54
$config['default_format'] = 'md'; // default format, you can choose between 'md' or 'txt'
65
$config['list_formats'] = ['md', 'txt']; // list of displayed formats, can be a combination of md, html, txt, pdf, jpg, png
76
$config['yaml_support'] = true; // set to true, if you want enable yaml support
8-
$config['yaml_start'] = '---'; // the yaml header should starts as the first sign in a markdown note and is marked by default with '---'
9-
$config['yaml_end'] = '---'; // the signs which marks the end of the yaml header
10-
$config['rm_md_media'] = true; // if set to yes, embedded media will be removed
7+
$config['rm_md_media'] = false; // if set to yes, embedded media will be removed
118
?>

notes.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,21 @@
1212
$rcmail = rcmail::get_instance();
1313

1414
if (!empty($rcmail->user->ID)) {
15-
if(substr($rcmail->config->get('notes_basepath', false), -1) != '/') {
16-
error_log('PrimitiveNotes: check $config[\'notes_basepath\'] the path must end with a backslash.');
17-
die();
18-
}
19-
20-
if(substr($rcmail->config->get('notes_folder', false), -1) != '/') {
21-
error_log('PrimitiveNotes: check $config[\'notes_folder\'] the path must end with a backslash.');
22-
die();
23-
}
24-
25-
$notes_path = $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false);
15+
$notes_path = $rcmail->config->get('notes_path', false);
16+
$notes_path = (strpos($notes_path, '%u') === false) ? $notes_path:str_replace('%u', $rcmail->user->get_username(), $notes_path);
17+
$notes_path = ($notes_path[-1] != '/') ? $notes_path.'/':$notes_path;
18+
2619
$media_folder = $rcmail->config->get('media_folder', false);
20+
$media_folder = ($media_folder[-1] != '/') ? $media_folder.'/':$media_folder;
2721
setcookie('pn_', json_encode($media_folder), 0, parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '.'.$_SERVER['HTTP_HOST'], true);
2822
$default_format = $rcmail->config->get('default_format', false);
2923
$language = $rcmail->get_user_language();
30-
$yh_begin = $rcmail->config->get('yaml_start', '');
31-
$yh_end = $rcmail->config->get('yaml_end', '');
24+
$yh_begin = '---';
25+
$yh_end = '---';
3226

3327
if (!is_dir($notes_path)) {
3428
if(!mkdir($notes_path, 0774, true)) {
35-
error_log('PrimitiveNotes: Subfolders for $config[\'notes_basepath\'] ($config[\'notes_folder\']) failed. Please check your directory permissions.');
29+
error_log('PrimitiveNotes: Check notes folder ($config[\'notes_path\']) failed. Please check directory permissions.');
3630
die();
3731
}
3832
}
@@ -58,7 +52,7 @@
5852
if($_FILES['localFile'] && $_FILES['localFile']['error'] == 0 ) {
5953
if (!is_dir($notes_path.$media_folder)) {
6054
if(!mkdir($notes_path.$media_folder, 0774, true)) {
61-
error_log('PrimitiveNotes: Subfolders for $config[\'notes_basepath\'] ($config[\'notes_folder\']) (media) failed. Please check your directory permissions.');
55+
error_log('PrimitiveNotes: Check media folder ($config[\'media_folder\']) failed. Please check directory permissions.');
6256
die();
6357
}
6458
}
@@ -230,7 +224,6 @@
230224
$tags_str = ($tags_str != "") ? "[".$tags_str."]" : $tags_str;
231225
$new_name = $note_name.$tags_str.".".$note_type;
232226
}
233-
$notes_path = $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false);
234227

235228
if(file_exists($notes_path.$old_name) && $old_name != '') {
236229
if($old_name != $new_name) if(!rename($notes_path.$old_name, $notes_path.$new_name)) die('Could not rename file.');
@@ -276,7 +269,8 @@
276269
break;
277270
case 'delMedia':
278271
$files = json_decode($_POST['files']);
279-
$mpath = $notes_path = $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false).$rcmail->config->get('media_folder', false);
272+
$mpath = $notes_path.$rcmail->config->get('media_folder', false);
273+
$mpath = ($mpath[-1] != '/') ? $mpath.'/':$mpath;
280274
foreach($files as $key => $file) {
281275
$rfile = filter_var($file, FILTER_SANITIZE_STRING);
282276
$rfile = $mpath.$rfile;
@@ -295,7 +289,7 @@
295289
$img = $notes_path.$media_folder.$fname;
296290
if (!is_dir($notes_path.$media_folder)) {
297291
if(!mkdir($notes_path.$media_folder, 0774, true)) {
298-
error_log('PrimitiveNotes: Subfolders for $config[\'notes_basepath\'] ($config[\'notes_folder\']) (media) failed. Please check your directory permissions.');
292+
error_log('PrimitiveNotes: Check media folders failed. Please check your directory permissions.');
299293
die();
300294
}
301295
}

primitivenotes.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ function note_mail_compose($args) {
114114
$subject = substr($subject,0,47)."...";
115115
}
116116
}
117-
$note_file = $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false).$filename;
117+
$notes_path = $rcmail->config->get('notes_path', false);
118+
$notes_path = (strpos($notes_path, '%u') === false) ? $notes_path:str_replace('%u', $rcmail->user->get_username(), $notes_path);
119+
$notes_path = ($notes_path[-1] != '/') ? $notes_path.'/':$notes_path;
120+
$note_file = $notes_path.$filename;
118121
if(file_exists($note_file)) {
119122
$handle = fopen ($note_file, "r");
120123
$note_content = fread($handle, filesize($note_file));
@@ -152,7 +155,10 @@ function action() {
152155
'tablink' => array($this, 'tablink'),
153156
));
154157

155-
$rcmail->output->set_env('npath', $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false));
158+
$notes_path = $rcmail->config->get('notes_path', false);
159+
$notes_path = (strpos($notes_path, '%u') === false) ? $notes_path:str_replace('%u', $rcmail->user->get_username(), $notes_path);
160+
$notes_path = ($notes_path[-1] != '/') ? $notes_path.'/':$notes_path;
161+
$rcmail->output->set_env('npath', $notes_path);
156162
$rcmail->output->set_env('dformat', $rcmail->config->get('default_format', false));
157163
$rcmail->output->add_handlers(array('notescontent' => array($this, 'content'),));
158164
$rcmail->output->set_pagetitle($this->gettext('notes'));

skins/larry/templates/template.html

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,14 @@
1212
<span class="dropbutton">
1313
<roundcube:button id="newnote" command="newnote" type="link" class="button new" label="primitivenotes.note_new" title="primitivenotes.note_new" />
1414
<a href="#new-note" class="dropbuttontip" id="newmenulink" onclick="UI.toggle_popup('newmenu',event);return false" aria-haspopup="true" aria-expanded="false" aria-owns="newmenu-menu" tabindex="0"><roundcube:label name="primitivenotes.arialabelnewoptions" /></a>
15-
</span>
15+
</span>
16+
<span id="nmenu">
1617
<roundcube:button id="editnote" command="editnote" type="link" class="button edit disabled" label="primitivenotes.note_edit" title="primitivenotes.note_edit" />
1718
<roundcube:button id="deletenote" command="deletenote" type="link" class="button delete disabled" label="primitivenotes.note_del" title="primitivenotes.note_del" />
1819
<roundcube:button id="sendnote" command="sendnote" type="link" class="button send disabled" label="primitivenotes.note_send" title="primitivenotes.note_send" />
20+
</span>
1921
<roundcube:button id="addnote" command="addnote" type="link" class="button upload" label="primitivenotes.note_upload" title="primitivenotes.note_upload" />
2022
<form id="upl_form" method="POST" enctype="multipart/form-data"><input name="path" value="<roundcube:var name="env:npath" />" type="hidden" /><input type="file" id="upl" class="upl" name="files" onchange="javascript:sform(this.value);" /></form>
21-
<script>
22-
function sform(fileName) {
23-
var allowed_extensions = new Array('html', 'pdf', 'jpg', 'png', 'md', 'txt');
24-
var file_extension = fileName.split('.').pop().toLowerCase();
25-
26-
for(var i = 0; i <= allowed_extensions.length; i++)
27-
{
28-
if(allowed_extensions[i]==file_extension)
29-
{
30-
document.getElementById("upl_form").submit();
31-
return true;
32-
}
33-
}
34-
alert('<roundcube:label name="primitivenotes.note_inv_format" />');
35-
return false;
36-
}
37-
</script>
3823
</div>
3924
<div id="pluginbody" class="offset">
4025
<div class="iframebox simplenotes_<roundcube:var name='env:action' />">
@@ -44,7 +29,6 @@
4429
</div>
4530
<div id="newmenu" class="popupmenu" aria-hidden="true">
4631
<ul id="newmenu-menu" class="toolbarmenu" role="menu">
47-
<roundcube:button type="link-menuitem" command="htmlnote" class="menuentry" label="primitivenotes.note_formathtml" prop="html" />
4832
<roundcube:button type="link-menuitem" command="mdnote" class="menuentry" label="primitivenotes.note_formatmd" prop="md" />
4933
<roundcube:button type="link-menuitem" command="txtnote" class="menuentry" label="primitivenotes.note_formattxt" prop="txt" />
5034
<roundcube:container name="newmenu" id="newmenu-menu" />

0 commit comments

Comments
 (0)