Skip to content

Commit

Permalink
Merge pull request #49 from Offerel/dev
Browse files Browse the repository at this point in the history
Fixed wrong links
  • Loading branch information
Offerel authored Feb 7, 2021
2 parents 01b3bcf + f7e10b8 commit 4145177
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 41 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v2.0.3
- Fixed an issue, where links are converted wrong

### v2.0.2
- Added option button to jump directly to plugin options (thanks to Aleksander Machniak)
- Added function to paste selected text from browser, converted automatically to Markdown with [Turndown](https://github.com/domchristie/turndown)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/Offerel/roundcube_primitivenotes",
"type": "roundcube-plugin",
"license": "AGPL-3.0",
"version": "2.0.2",
"version": "2.0.3",
"authors": [
{
"name": "Offerel",
Expand Down
20 changes: 17 additions & 3 deletions js/notes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Roundcube Notes Plugin
*
* @version 2.0.2
* @version 2.0.3
* @author Offerel
* @copyright Copyright (c) 2021, Offerel
* @license GNU General Public License, version 3
Expand Down Expand Up @@ -33,19 +33,32 @@ $(document).ready(function(){
}
});

let cookiesArr = document.cookie.split(';');
var media_folder;
cookiesArr.forEach(function(element){
let cookie = element.split('=');
if(cookie[0].indexOf('pn_') > 0) media_folder = JSON.parse(decodeURIComponent(cookie[1]));
});

var mde = new EasyMDE({
element: document.getElementById('editor1'),
autoDownloadFontAwesome: false,
autofocus: true,
previewImagesInEditor: false,
spellChecker: false,
autofocus: true,
status: false,
promptURLs: true,
inputStyle: 'contenteditable',
nativeSpellcheck: true,
forceSync: true,
//sideBySideFullscreen: false,
renderingConfig: {
codeSyntaxHighlighting: true,
sanitizerFunction: function(renderedHTML) {
let output = renderedHTML.replaceAll(media_folder,'notes.php?blink=');
return output;
},
},
toolbar: [{ name: 'Save',
action: saveFile,
Expand Down Expand Up @@ -189,7 +202,6 @@ $(document).ready(function(){
let cstart = pastedText.indexOf('---',4) + 3;
for(var i = 1; i < 10; i++) {
if(textArr[i] == '---') break;
console.log(textArr[i]);
let yentry = textArr[i].split(':');
if(yentry[0] == 'title') document.getElementById('note_name').value = yentry[1].trim();
if(yentry[0] == 'tags') tagify.addTags(yentry[1]);
Expand Down Expand Up @@ -305,13 +317,15 @@ $(document).ready(function(){

document.querySelector('.EasyMDEContainer').style = 'display: block;';
document.getElementById('editor1').style = 'display none;';
mde.value(note.content);

document.getElementById('editor1').value = note.content;
mde.value(note.content);

if(note.mime_type.substr(0, 4) == 'text') {
if(document.getElementById('estate').value == 'e') {
document.getElementById('estate').value = 's';
mde.togglePreview();
//if(mde.isPreviewActive()) mde.togglePreview();
}
var headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
if(headings.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions js/notes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/primitivenotes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Roundcube Notes Plugin
*
* @version 2.0.2
* @version 2.0.3
* @author Offerel
* @copyright Copyright (c) 2021, Offerel
* @license GNU General Public License, version 3
Expand Down
2 changes: 1 addition & 1 deletion js/primitivenotes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 12 additions & 28 deletions notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Roundcube Notes Plugin
*
* @version 2.0.2
* @version 2.0.3
* @author Offerel
* @copyright Copyright (c) 2021, Offerel
* @license GNU General Public License, version 3
Expand All @@ -24,6 +24,7 @@

$notes_path = $rcmail->config->get('notes_basepath', false).$rcmail->user->get_username().$rcmail->config->get('notes_folder', false);
$media_folder = $rcmail->config->get('media_folder', false);
setcookie('pn_', json_encode($media_folder), 0, parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '.'.$_SERVER['HTTP_HOST'], true);
$default_format = $rcmail->config->get('default_format', false);
$language = $rcmail->get_user_language();
$yh_begin = $rcmail->config->get('yaml_start', '');
Expand All @@ -44,26 +45,12 @@

if(isset($_GET['blink'])) {
$file = urldecode($_GET['blink']);
$type = $_GET['t'];
if(file_exists($notes_path.$media_folder.$file)) {
$fileh = file_get_contents($notes_path.$media_folder.$file);
if($type == 'i') {
$imagev = imagecreatefromstring($fileh);
list($width, $height, $type, $attr) = getimagesizefromstring($fileh);
if($width > 860) {
$imagev = imagescale($imagev, 860);
}
header("Content-Type: image/jpeg");
header("Content-Disposition: inline; filename=\"".pathinfo($file)['filename'].".jpg\"");
imagejpeg($imagev);
imagedestroy($imagev);
}
elseif($type == 'l') {
$mime = mime_content_type($notes_path.$media_folder.$file);
header("Content-type: $mime");
header("Content-Disposition: inline; filename=\"$file\"");
echo $fileh;
}
$mime_type = mime_content_type($notes_path.$media_folder.$file);
header("Content-type: $mime_type");
header("Content-Disposition: inline; filename=\"$file\"");
echo $fileh;
}
die();
}
Expand Down Expand Up @@ -181,6 +168,7 @@
'date' => $date,
'source' => $source,
];

die(json_encode($noteArr));
break;
case 'getTags':
Expand Down Expand Up @@ -375,23 +363,19 @@ function read_note($id, $filename, $mode, $format) {

if(file_exists($file)) {
$fcontent = file_get_contents($file);
$re = '/(?:[!]?\[(.*?)\]\((.*?)\))/m';
if($mode != 'edit') {
$scontent = preg_replace_callback($re, "parseLink", $fcontent);
if($rcmail->config->get('yaml_support', '')) {
$yhb_pos = strpos($scontent, $yh_begin);
$yhe_pos = strlen($scontent) >= strlen($yh_begin) ? strpos($scontent, $yh_end, strlen($yh_begin)) : 0;
if($yhb_pos == 0 && $yhe_pos > 0) $scontent = substr($scontent,$yhe_pos + strlen($yh_end));
$yhb_pos = strpos($fcontent, $yh_begin);
$yhe_pos = strlen($fcontent) >= strlen($yh_begin) ? strpos($fcontent, $yh_end, strlen($yh_begin)) : 0;
if($yhb_pos == 0 && $yhe_pos > 0) $fcontent = substr($fcontent,$yhe_pos + strlen($yh_end));
}
} else {
$scontent = $fcontent;
}

$mime_type = mime_content_type($file);
$scontent = (substr($mime_type, 0, 4) == 'text') ? $scontent:base64_encode($scontent);
$fcontent = (substr($mime_type, 0, 4) == 'text') ? $fcontent:base64_encode($fcontent);
$note = array(
'name' => substr($filename, 0, stripos($filename, "[")),
'content' => trim($scontent),
'content' => trim($fcontent),
'format' => $format,
'id' => $id,
'mime_type' => $mime_type,
Expand Down
2 changes: 1 addition & 1 deletion primitivenotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Roundcube Notes Plugin
*
* @version 2.0.2
* @version 2.0.3
* @author Offerel
* @copyright Copyright (c) 2021, Offerel
* @license GNU General Public License, version 3
Expand Down
15 changes: 12 additions & 3 deletions skins/primitivenotes.css
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ object {
.editor-preview pre code {
color: unset;
background: unset;
display: block;
}
.editor-preview {
background: #fff;
Expand Down Expand Up @@ -413,9 +414,6 @@ object {
display: block;
max-width: 860px;
}
.editor-preview p > img {
display: initial;
}
.EasyMDEContainer {
top: 0;
position: relative;
Expand Down Expand Up @@ -586,4 +584,15 @@ tags.edit:focus-within {
width: 100%;
display: inline-block;
font-size: 0.9em;
}
.editor-preview code::-webkit-scrollbar {
height: 6px;
background: #dee2e6;
}
.editor-preview code::-webkit-scrollbar-thumb {
background: #bbb;
border-radius: 6px;
}
.editor-preview code::-webkit-scrollbar-thumb:hover {
background: #737677;
}
2 changes: 1 addition & 1 deletion skins/primitivenotes.min.css

Large diffs are not rendered by default.

0 comments on commit 4145177

Please sign in to comment.