adding notes app to git repo

This commit is contained in:
CaCO3 2013-01-03 19:42:15 +01:00
parent f3e249a4a2
commit a8bdb9daa1
17 changed files with 2831 additions and 0 deletions

12
appinfo/app.php Normal file
View File

@ -0,0 +1,12 @@
<?php
// $l=new OC_L10N('Notes');
$l=OC_L10N::get('notes');
OCP\App::addNavigationEntry( array(
'id' => 'notes_index',
'order' => 11,
'href' => OCP\Util::linkTo( 'notes', 'index.php' ),
'icon' => OCP\Util::imagePath( 'notes', 'icon.png' ),
'name' => $l->t('Notes'))
);

11
appinfo/info.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<info>
<id>notes</id>
<name>Notes</name>
<version>0.5.2</version>
<licence>GPL</licence>
<author>George Ruinelli</author>
<require>4.5</require>
<shipped>true</shipped>
<description>A simple Notes viewer and editor</description>
</info>

75
css/notes.css Normal file
View File

@ -0,0 +1,75 @@
#leftcontent {
box-sizing: border-box;
overflow: auto;
}
#entries {
position: fixed;
background: white;
width: 20em;
left: 12.5em;
top: 6.7em;
bottom: 0;
overflow: auto;
padding: 0;
margin: 0;
}
#rightcontent{
position:fixed;
margin-top: 5px;
margin-left: 5px;
top:6.4em;
left:32.5em;
overflow:auto
}
#rightcontent2{
margin-top: 50px;
margin-left: 10px;
}
#notes_preview h1 {
font-size: 1.6em;
font-weight: bold;
margin-top: 8px;
margin-right: 15px;
}
#notes_preview h2 {
font-size: 1.3em;
font-weight: bold;
}
#notes_preview h3 {
font-size: 1.1em;
font-weight: bold;
font-style:italic;
}
/* #notes_preview p { */
/* line-height: 1.1; */
/* } */
#notes_preview ul {
list-style: square inside;
}
#notes_preview ol {
list-style: decimal inside
}
#notes_preview a {
text-decoration:underline
}
#notes_preview code {
background-color:#dbdbdb;
font-size:smaller;
}
#markdown{
font-size: 1.2em;
}

BIN
img/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

31
index.php Normal file
View File

@ -0,0 +1,31 @@
<?php
/**************************************************
* ownCloud - Notes Plugin *
* *
* (c) Copyright 2012 by George Ruinell *
* This file is licensed under the GPL2 *
*************************************************/
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('notes');
OCP\Util::addStyle('notes', 'notes');
OCP\App::setActiveNavigationEntry('notes_index');
if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = ""; //show main page
}
if($page == "Help"){
$output = new OCP\Template('notes', 'help', 'user');
}
else if($page == "Edit Categories"){
$output = new OCP\Template('notes', 'categories', 'user');
}
else{
$output = new OCP\Template('notes', 'notes', 'user');
}
$output -> printPage();

2
js/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

115
js/main.js Normal file
View File

@ -0,0 +1,115 @@
$(document).on("ready", function(){
editor = {
// variables
fitHeightElements: $(".full-height"),
wrappersMargin: $("#left_column > .wrapper:first").outerHeight(true) - $("#left_column > .wrapper:first").height(),
markdownConverter: new Showdown.converter(),
markdownSource: $("#markdown"),
markdownPreview: $("#preview"),
markdownTargets: $("#html, #preview"),
markdownTargetsTriggers: $("#right_column .overlay .switch"),
topPanels: $("#top_panels_container .top_panel"),
topPanelsTriggers: $("#left_column .overlay .toppanel"),
quickReferencePreText: $("#quick_reference pre"),
// functions
init: function(){
this.onloadEffect(0);
this.bind();
this.switchToTarget('preview');
this.fitHeight();
this.convert();
this.onloadEffect(1);
},
bind: function(){
$(window).on("resize", function(){
editor.fitHeight();
});
this.markdownSource.on("keyup change", function(){
editor.convert();
});
this.markdownSource.on("cut paste drop", function(){
setTimeout(function(){
editor.convert();
}, 1);
});
this.markdownTargetsTriggers.on("click", function(e){
e.preventDefault();
editor.switchToTarget($(this).data("switchto"));
});
this.topPanelsTriggers.on("click", function(e){
e.preventDefault();
editor.toggleTopPanel($(this).data("toppanel"));
});
this.topPanels.children(".close").on("click", function(e){
e.preventDefault();
editor.closeTopPanel();
});
this.quickReferencePreText.on("click", function(){
editor.addToMarkdownSource($(this).text());
});
},
fitHeight: function(){
var newHeight = $(window).height() - this.wrappersMargin;
this.fitHeightElements.each(function(){
if($(this).closest("#left_column").length){
var thisNewHeight = newHeight - $("#top_panels_container").outerHeight();
} else {
var thisNewHeight = newHeight;
}
$(this).css({ height: thisNewHeight +'px' });
});
},
convert: function(){
var markdown = this.markdownSource.val(),
html = this.markdownConverter.makeHtml(markdown);
$("#html").val(html);
$("#preview").html(html);
},
addToMarkdownSource: function(markdown){
var markdownSourceValue = this.markdownSource.val();
if(markdownSourceValue != '') markdownSourceValue += '\n\n';
this.markdownSource.val(markdownSourceValue + markdown);
this.convert();
},
switchToTarget: function(which){
var target = $("#"+ which),
targetTrigger = this.markdownTargetsTriggers.filter("[data-switchto="+ which +"]");
this.markdownTargets.not(target).hide();
target.show();
this.markdownTargetsTriggers.not(targetTrigger).removeClass("active");
targetTrigger.addClass("active");
},
toggleTopPanel: function(which){
var panel = $("#"+ which),
panelTrigger = this.topPanelsTriggers.filter("[data-toppanel="+ which +"]");
this.topPanels.not(panel).hide();
panel.toggle();
this.topPanelsTriggers.not(panelTrigger).removeClass("active");
panelTrigger.toggleClass("active");
this.fitHeight();
},
closeTopPanel: function(){
this.topPanels.hide();
this.topPanelsTriggers.removeClass("active");
this.fitHeight();
},
onloadEffect: function(step){
var theBody = $(document.body);
switch(step){
case 0:
theBody.fadeTo(0, 0);
break;
case 1:
theBody.fadeTo(1000, 1);
break;
}
}
};
editor.init();
});

21
js/showdown.js Normal file

File diff suppressed because one or more lines are too long

0
l10n/.gitkeep Normal file
View File

29
l10n/de.php Normal file
View File

@ -0,0 +1,29 @@
<?php
//Copyright 2012 by George Ruinelli
$TRANSLATIONS = array(
"Notes" => "Notizen",
"Add Note" => "Notiz hinzufügen",
"Edit Categories" => "Kategorien bearbeiten",
"Help" => "Hilfe",
"Edit" => "Bearbeiten",
"Save" => "Speichern",
"Restore" => "Wiederherstellen",
"Restore content" => "Inhalt wiederherstellen",
"Delete" => "Löschen",
"Title" => "Titel",
"Content" => "Inhalt",
"Category" => "Kategorie",
"Categories" => "Kategorien",
"New category" => "Neue Kategorie",
"Add" => "Hinzufügen",
"Back to Notes" => "Zurück zu den Notizen",
"Note" => "Hinweis",
"If you delete a category, all containing notes get moved to the following category" => "Wenn Sie eine Kategorie löschen, werden alle darin enthaltenen Notizen in die folgende Kategorie verschoben",
"No categories available yet" => "Noch keine Kategorien verfügbar",
"No note available in this category" => "Noch keine Notiz in dieser Kategorien verfügbar",
"The title can not be empty" => "Der Titel darf nicht leer sein",
"Invalid title" => "Ungültiger Titel",
"The following characters are not allowed" => "Die folgenden Zeichen sind nicht erlaubt",
"General" => "Allgemein"
);

27
l10n/fr.php Executable file
View File

@ -0,0 +1,27 @@
<?php $TRANSLATIONS = array(
"Notes" => "Note",
"Add Note" => "Ajouter une note",
"Edit Categories" => "Gestion des categories",
"Help" => "Aide",
"Edit" => "Edition",
"Save" => "Sauver",
"Restore" => "Restorer",
"Restore content" => "Restaurer le contenu",
"Delete" => "Supprimer",
"Title" => "Titre",
"Content" => "Corps de la Note",
"Category" => "Catégorie",
"Categories" => "Catégories",
"New category" => "Nouvelle Catégorie",
"Add" => "Ajouter",
"Back to Notes" => "Retourner à la note",
"Note" => "note",
"If you delete a category, all containing notes get moved to the following category" => "Si vous supprimez la categorie, toutes les notes contenues sont déplacées dans la catégorie suivante",
"No categories available yet" => "Pas de categorie disponible pour le moment",
"No note available in this category" => "Pas de note disponible dans cette categorie",
"The title can not be empty" => "Le titre ne peux pas être vide",
"Invalid title" => "Titre invalide",
"The following characters are not allowed" => "Les caractères suivants ne sont pas admis",
"General" => "Générale"
);

28
l10n/it.php Normal file
View File

@ -0,0 +1,28 @@
<?php
//Copyright 2012 by Matteo Bettineschi
$TRANSLATIONS = array(
"Notes" => "Note",
"Add Note" => "Nuova Nota",
"Edit Categories" => "Modifica Categorie",
"Help" => "Aiuto",
"Edit" => "Modifica",
"Save" => "Salva",
"Restore" => "Rispristina",
"Restore content" => "Ripristina contenuto",
"Delete" => "Cancella",
"Title" => "Titolo",
"Content" => "Contenuto",
"Category" => "Categoria",
"Categories" => "Categorie",
"New category" => "Nuova Categoria",
"Add" => "Aggiungi",
"Back to Notes" => "Torna alla Nota",
"Note" => "Note",
"If you delete a category, all containing notes get moved to the following category" => "Se cancelli una categoria, tutte le note contenute saranno spostate nella seguente categoria",
"No categories available yet" => "Nessuna categoria disponibile",
"No note available in this category" => "Nessuna nota disponibile in questa categoria",
"The title can not be empty" => "Il Titolo non può essere vuoto",
"Invalid title" => "Titolo non valido",
"The following characters are not allowed" => "I seguenti caratteri non sono ammessi",
"General" => "Generica"
);

1732
lib/markdown.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,66 @@
<div id="controls">
<!-- <input type="text" id="tasks_newtask"> -->
<!-- <input type="button" id="tasks_addtask" value="<?php echo $l->t('Add Task'); ?>">
<input type="button" id="tasks_order_due" value="<?php echo $l->t('Order Due'); ?>">
<input type="button" id="tasks_order_category" value="<?php echo $l->t('Order List'); ?>">
<input type="button" id="tasks_order_complete" value="<?php echo $l->t('Order Complete'); ?>">
<input type="button" id="tasks_order_location" value="<?php echo $l->t('Order Location'); ?>">
<input type="button" id="tasks_order_prio" value="<?php echo $l->t('Order Priority'); ?>">
<input type="button" id="tasks_order_label" value="<?php echo $l->t('Order Label'); ?>">-->
</div>
<div id="notes_lists" class="leftcontent">
<!-- <div class="all">All</div>
<div class="done">Done</div>-->
<ul id="entries">
<?
// Check if we are a user
OCP\User::checkLoggedIn();
$dir = "/KhtNotes";
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
$i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file') {
$fileinfo=pathinfo($i['name']);
$i['basename']=$fileinfo['filename'];
if (!empty($fileinfo['extension'])) {
$i['extension']='.' . $fileinfo['extension'];
}
else {
$i['extension']='';
}
}
echo "<li><p><a href=\"?app=kht_notes&note=" . $i['basename'] . $i['extension'] . "\"><b>" . $i['basename'] . "</b><br><i>" . $i['date'] ."</i><br></a></p></li>";
}
?>
</ul>
</div>
<div id="tasks_list" class="rightcontent">
<p class="loading"></p>
<?
$note = isset($_GET['note']) ? $_GET['note'] : null;
echo "<h2>Note: $note</h2>";
?>
<form action="?app=kht_notes" method="post" target="_self">
<p><b>Title:</b><br><input name="title" type="text" size="1000" maxlength="1000"></p>
<textarea name="content" cols="50" rows="10"></textarea>
</form>
</div>

151
templates/categories.php Normal file
View File

@ -0,0 +1,151 @@
<?php
$show_Warnings = false;
?>
<div id="controls">
<div style="float:left;">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<input type="submit" name="back" value="<?php echo $l->t('Back to Notes'); ?>">
</form>
</div>
<div>
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<button type="submit" name="page" value="Help" ><?php echo $l->t('Help'); ?></button>
</form>
</div>
</div>
<div id="rightcontent2" class="rightcontent2">
<!-- <div id="leftcontent" class="leftcontent"> -->
<?php if($show_Warnings == false){ ?><div style="height: 0px; width: 0px; float:none; display:none;"> <?php } else{ ?><div><?php } ?>
<?php
// print "<pre>";
// echo "POST: ";
// print_r($_POST);
// echo "GET: ";
// print_r($_GET);
// print "</pre>";
// print "--------------------<br>";
// Check if we are a user
OCP\User::checkLoggedIn();
$root = "Notes";
$arr_rootfilelist = array(); //contains all files
$arr_filelist = array(); //containing all files in the selected folder
$user = OCP\USER::getUser();
OC_Filesystem::init($root, '/' . $user . '/');
OC_Filesystem::mkdir($root);
if(isset($_GET['new_category'])){ //new category
$category = $_GET['new_category'];
OC_Filesystem::mkdir($root . "/" . $category);
}
else{
$old_category = isset($_GET['old_category']) ? $_GET['old_category'] : "";
$category = isset($_GET['category']) ? $_GET['category'] : "";
$delete = isset($_GET['delete']) ? $_GET['delete'] : "";
if($old_category != $category){ //rename folder/category
OC_Filesystem::rename($root . "/" . $old_category, $root . "/" . $category);
}
elseif($delete == "Delete"){ //remove folder/category
//move each file in this folder
$arr_filelist = OC_Files::getdirectorycontent( $root . "/" . $category);
foreach( $arr_filelist as $i ) {
// print_r($i);
if($i['type']=='file') {
$file = $i['name'];
OC_Filesystem::rename($root . "/" . $category . '/' . $file, $root . '/' . $file);
}
}
OC_Filesystem::unlink($root . "/" . $category);
}
}
//get file list
$arr_rootfilelist = OC_Files::getdirectorycontent( $root);
?>
</div>
<div id="rightcontent2" class="rightcontent2">
<!-- <div id="notes_list" class="rightcontent" style="margin-top: 5px"> -->
<b><?php echo $l->t('Categories'); ?>:</b><br>
<table>
<?php
$thereisacategory=false;
foreach( $arr_rootfilelist as $i ) {
if($i['type']=='dir') {
$thereisacategory = true;
?>
<tr><td>
<form action="?app=notes" method="get" target="_self">
<input style="width:200px;" name="category" value="<?php echo $i['name']; ?>" type="text" size="200" maxlength="200">
<input type="hidden" name="app" value="notes">
<input type="hidden" name="page" value="Edit Categories">
<input type="hidden" name="old_category" value="<?php echo $i['name']; ?>">
<input type="checkbox" name="delete" value="Delete"><b><?php echo $l->t('Delete'); ?></b>
<button type="submit" name="save" value="true" ><?php echo $l->t('Save'); ?></button>
</form>
</td></tr>
<?php
}
}
?>
</table>
<?php
if($thereisacategory == false){
echo $l->t('No categories available yet');
echo ".<br>";
}
?>
<br>
<form action="?app=notes" method="get" target="_self">
<b><?php echo $l->t('New category'); ?>:</b><br>
<input style="width:200px;" name="new_category" value="" type="text" size="200" maxlength="200">
<input type="hidden" name="app" value="notes">
<input type="hidden" name="page" value="Edit Categories">
<button type="submit" name="add" value="true" ><?php echo $l->t('Add'); ?></button>
</form>
<br>
<b><?php echo $l->t('Note'); ?>:</b><br>
<?php echo $l->t('If you delete a category, all containing notes get moved to the following category'); echo ": <b>"; echo $l->t('General'); ?></b>.
<br><br>
</div>

62
templates/help.php Normal file
View File

@ -0,0 +1,62 @@
<div id="controls">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<input type="submit" name="back" value="<?php echo $l->t('Back to Notes'); ?>">
</form>
</div>
<div id="rightcontent2" class="rightcontent2">
<div id="notes_preview">
<h1><?php echo $l->t('Help'); ?></h1><br>
<h2>About</h2>
Notes is a simple app which you can use to save your notes, shopping lists, links, howtos and much more in your OwnCloud.<br>
You can sort your notes with <b>categories</b>.<br>
The content of a note is under <b>revision control</b>, so you always can restore an earlier version.<br>
To format your notes, you can use the <b>MarkDown syntax</b> and some additional keywords.
<br><br>
<h2>Sync clients</h2>
<b>Notes</b> works with plain text files which are stored in your OwnCloud files under <b>Notes</b>.<br>
This way you can sync them easily with any other device capable of syncing with OwnCloud.<br>
There are currently several notes apps supporting the same file structure:<br>
<ul>
<li>Linux:</b> <a href=http://sourceforge.net/projects/znotes/>zNotes</a></li>
<li>Meego/NemoMobile/Sailfish:</b> <a href=http://khertan.net/khtnotes>khtNotes</a></li>
<li>Android:</b> <a href=https://play.google.com/store/apps/details?id=com.kallisto.papyrusex>Papyrus Ex</a> in conjunction with <a href=https://play.google.com/store/apps/details?id=dk.tacit.android.foldersync.lite>FolderSync</a></li>
</ul>
<br>
<h2>Formating</h2>
<h3>MarkDown Syntax</h3>
MarkDown syntax is a formating style developed by <a href="http://daringfireball.net/projects/markdown/">John Gruber</a>.<br>
You can use it to format your notes in a simple way:<br>
A <strong>title</strong> is created by a leading <strong>#</strong> or a <strong>=</strong> on a new line.<br>
A <strong>subtitle</strong> is created by a leading <strong>##</strong> or a <strong>-</strong> on a new line.<br>
<strong>Bold text</strong> has to be set between a <strong>**</strong><br>
<strong>Italic text</strong> has to be set between a <strong>*</strong><br>
An <strong>unnumbered list</strong> starts with a <strong>-</strong> and a <strong>whitespace</strong><br>
An <strong>numbered list</strong> starts with a <strong>1.</strong> and a <strong>whitespace</strong><br>
<strong>Links</strong> are created this way: [Georges Website](http://www.ruinelli.ch)<br>
<strong>Source code</strong> has to be set beween <strong>`</strong><br><br>
For a complete overview, see <a href="http://sourceforge.net/p/forge/documentation/markdown_syntax/">MarkDown Syntax</a>.<br>
To play arround, you can use this editor: <a href="http://markdown.pioul.fr/">http://markdown.pioul.fr/</a>.
<br><br>
<h3>Additional formating</h3>
The MarkDown Syntax might not support every formating you want.<br>
To work around that, you can use simple HTML key words.<br>
I.e. <b>Striked through text</b> simply needs a leading <b>&lt;del&gt;</b><br>
How ever keep in mind that other Notes vclients might not support this!
<br><br>
<h2>More</h2>
For more information, please have a look at <a href=http://apps.owncloud.com/content/show.php/Notes?content=155599>apps.owncloud.com</a>.<br>
Copyrght 2012 by <a href=http://www.ruinelli.ch>George Ruinelli</a>.
<br><br>
</div>
</div>

469
templates/notes.php Normal file
View File

@ -0,0 +1,469 @@
<?php
$show_Warnings = false;
// $show_Warnings = true;
?>
<div id="controls">
<?php if($show_Warnings == false){ ?><div style="height: 0px; width: 0px; float:none; display:none;"> <?php } else{ ?><div><?php } ?>
<?php
include_once dirname(__FILE__)."/../lib/markdown.php";
// Check if we are a user
OCP\User::checkLoggedIn();
$root = "Notes";
$extension = ".txt"; //default extention
$arr_filelist = array(); //containing all files in the selected folder
$user = OCP\USER::getUser();
OC_Filesystem::init($root, '/' . $user . '/');
OC_Filesystem::mkdir($root);
//get subfolder (category)
if(isset($_GET['category'])){
$category = $_GET['category'];
}
elseif(isset($_POST['category'])){
$category = $_POST['category'];
}
else{
$category = "";
}
if($category == "General")$category = ""; //default category/folder
$arr_filelist = OC_Files::getdirectorycontent($root . "/" . $category);
// print_r($arr_filelist);
$arr_rootfilelist = array(); //contains all files
//get file list
$arr_rootfilelist = OC_Files::getdirectorycontent( $root);
?>
</div>
<div style="float:left;">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<select name="category" size="1" style="width: 150px" onchange="window.open('?app=notes&category='+this.options[this.selectedIndex].value, '_self');">
<option value='General'><?php echo $l->t('General'); ?></option>
<?php
foreach( $arr_rootfilelist as $i ) {
if($i['type']=='dir') {
if($i['name'] == $category){
print "<option value='" . $i['name'] ."' selected='selected'>" . $i['name'] . "</option>\n";
}
else{
print "<option value='" . $i['name'] ."'>" . $i['name'] . "</option>\n";
}
}
}
?>
</select>
</form>
</div>
<div style="float:left;">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<input type="hidden" name="category" value="<?php echo $category; ?>">
<button type="submit" name="new" value="true" ><?php echo $l->t('Add Note'); ?></button>
</form>
</div>
<div style="float:left;">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<button type="submit" name="page" value="Edit Categories" ><?php echo $l->t('Edit Categories'); ?></button>
</form>
</div>
<div>
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<button type="submit" name="page" value="Help" ><?php echo $l->t('Help'); ?></button>
</form>
</div>
</div>
<div id="leftcontent" class="leftcontent">
<?php if($show_Warnings == false){ ?><div style="height: 0px; width: 0px; float:none; display:none;"> <?php } else{ ?><div><?php } ?>
<?php
if($show_Warnings == true){
print "<pre>";
echo "POST: ";
print_r($_POST);
echo "GET: ";
print_r($_GET);
print "</pre>";
print "--------------------<br>";
}
// if(isset($_GET['note'])){ //GET data (from a link)
// if(!isset($_POST['title']) and !isset($_POST['new']) ){ //GET data (from a link)
// if(!isset($_POST['title'])){ //GET data (from a link)
if(!isset($_POST['post'])){ //parameter "post" not set, handle as GET call
$edit = isset($_GET['edit']) ? true : false;
if(isset($_GET['new'])){ //new note
$file = "";
$title = "";
$content = "";
$edit = true; //overwrite
}
elseif(isset($_GET['note'])){ //a note is selected
$file = $_GET['note']; // note.txt
$arr = pathinfo($file);
$title = $arr['filename'];
$content = OC_Filesystem::file_get_contents($root . "/" . $category . '/' . $file);
}
else{ //no note selected, select first one
$thereisanote = false;
foreach( $arr_filelist as $i ) {
if($i['type']=='file') {
$thereisanote = true;
$file = $i['name'];
$arr = pathinfo($file);
$title = $arr['filename'];
$content = OC_Filesystem::file_get_contents($root . "/" . $category . '/' . $file);
break;
}
}
if($thereisanote == false){ //there is no file at all
$file = "";
$title = "";
$content = "";
}
}
}
else{ //POST data (from a form)
$edit = isset($_POST['edit']) ? true : false;
$delete = isset($_POST['delete']) ? true : false; //"Delete" or ""
$file = isset($_POST['file']) ? $_POST['file'] : ""; // note.txt
$title = isset($_POST['title']) ? $_POST['title'] : "";
$content = isset($_POST['content']) ? $_POST['content'] : "";
$old_category = isset($_POST['old_category']) ? $_POST['old_category'] : "";
// if(isset($_POST['new'])){ //new note
// $file = "[unknown]" . $extension; // note.txt
// $title = "";
// $content = "";
// }
// else
if(isset($_POST['restore'])){ //restore note
$file = $_POST['file']; // note.txt
$old_category = $_POST['old_category'];
$version = $_POST['version'];
// print "check if File is versioned: " . $root . "/" . $old_category . '/' . $file . ", Version: " . $version;
if( OCA_Versions\Storage::isversioned($root . "/" . $old_category . '/' . $file ) ) {
// print "File is versioned: " . $root . "/" . $old_category . '/' . $file . ", Version: " . $version;
$versions = new OCA_Versions\Storage();
$ret = $versions->rollback("/" . $root . "/" . $old_category . '/' . $file, (int)$version );
// if($ret == true) print "restored";
// else print "restoration failed";
}
$arr = pathinfo($file);
$title = $arr['filename'];
$content = OC_Filesystem::file_get_contents($root . "/" . $old_category . '/' . $file);
}
elseif($delete == true){ //remove file
if(OC_Filesystem::file_exists($root . "/" . $category . '/' . $file)){
OC_Filesystem::unlink($root . "/" . $category . '/' . $file);
$arr_filelist = OC_Files::getdirectorycontent( $root . "/" . $category); //reload file list
//file removed, select first one
$thereisanote = false;
foreach( $arr_filelist as $i ) {
if($i['type']=='file') {
$thereisanote = true;
$file = $i['name'];
$arr = pathinfo($file);
$title = $arr['filename'];
$content = OC_Filesystem::file_get_contents($root . "/" . $category . '/' . $file);
break;
}
}
if($thereisanote == false){ //there is no file at all
$file = "";
$title = "";
$content = "";
}
}
}
else{ //update or create
if($file != ""){ //update/rename file
$arr = pathinfo($file);
$oldtitle = $arr['filename'];
// if($title =="") $title = "[no name]";
if($oldtitle != $title or $old_category != $category){ //title or category changed, rename/move file
// if(OC_Filesystem::file_exists($root . "/" . $category . '/' . $file) and $file != ""){
$newfile = $title . $extension;
// print "rename $file => $newfile";
OC_Filesystem::rename($root . "/" . $old_category . '/' . $file, $root . "/" . $category . '/' . $newfile);
$file = $newfile;
// }
}
// else{
// $file = "[unknown]" . $extension; // note.txt
// }
OC_Filesystem::file_put_contents($root . "/" . $category . '/' . $file, $content);
$arr_filelist = OC_Files::getdirectorycontent( $root . "/" . $category); //reload file list
}
else{ //new file
$file = $title . $extension;
OC_Filesystem::file_put_contents($root . "/" . $category . '/' . $file, $content);
$arr_filelist = OC_Files::getdirectorycontent( $root . "/" . $category); //reload file list
}
}
}
?>
</div>
<ul id="entries">
<?php
//output file list
$notes_available = false;
foreach( $arr_filelist as $i ) {
if($i['type']=='file'){
$notes_available = true;
break;
}
}
if($notes_available == true){
foreach( $arr_filelist as $i ) {
// print_r($i);
$i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file') {
$fileinfo=pathinfo($i['name']);
$i['basename']=$fileinfo['filename'];
if (!empty($fileinfo['extension'])) {
$i['extension']='.' . $fileinfo['extension'];
}
else {
$i['extension']='';
}
$t = $i['basename'];
if($i['basename'] == $title){ //select entry
$class = "active";
}
else{
$class = "";
}
echo "<li class=\"$class\"><a href=\"?app=notes&category=$category&note=" . $i['basename'] . $i['extension'] . "\"><b>" . $t . "</b><br><i>" . $i['date'] ."</i></a></li>\n";
}
}
}
else{
print "<b>";
echo $l->t('No note available in this category');
print "</b>";
}
?>
</ul>
</div>
<div id="rightcontent" class="rightcontent">
<?php if($edit == false){ ?>
<div id="notes_preview">
<div style="float:left;">
<?php
if($title !="" or $content !=""){ //show data
$content2 = str_replace(array("\r\n", "\n", "\r"), "\n", $content);
$content2 = str_replace("\n", " \n", $content2); //fixing unwanted behaviour of MarkDown Script (every new line should give a new line in preview)
$content2 = str_replace(" \n \n \n", "<br><br>\n", $content2); //if there are more than 1 empty line, actually show an empty line
// print " -----------content2\n$content2\n---------------\n";
$html = Markdown($content2);
//shift headers
$html = str_replace("<h2>", "<h3>", $html);
$html = str_replace("</h2>", "</h3>", $html);
$html = str_replace("<h1>", "<h2>", $html);
$html = str_replace("</h1>", "</h2>", $html);
$html = str_replace("<p>", "", $html); //we do not want those <p> tags
$html = str_replace("</p>", "", $html);
echo "<h1>$title</h1>";
?>
</div>
<div style="float:left;">
<form action="?app=notes" method="get" target="_self">
<input type="hidden" name="app" value="notes">
<input type="hidden" name="note" value="<?php echo $file; ?>">
<input type="hidden" name="category" value="<?php echo $category; ?>">
<button type="submit" name="edit" value="true" ><?php echo $l->t('Edit'); ?></button>
</form>
</div>
<div>
<form action="?app=notes" method="post" target="_self">
<input type="hidden" name="app" value="notes">
<input type="hidden" name="post" value="true">
<input type="hidden" name="file" value="<?php echo $file; ?>">
<input type="hidden" name="category" value="<?php echo $category; ?>">
<input type="hidden" name="title" value="<?php echo $title; ?>">
<button type="submit" name="delete" value="true" ><?php echo $l->t('Delete'); ?></button>
</form>
</div>
<div style="float:none;">
<?php
echo "$html<br><br>";
}
?>
</div>
<?php }
else{ //edit
?>
<div>
<?php if((count($arr_filelist) > 0) or isset($_GET['new'])){ ?>
<form name="notes_save" action="?app=notes" method="post" target="_self" onSubmit="return checkform()">
<input type="hidden" name="post" value="true">
<b><?php echo $l->t('Category'); ?>:</b>
<select name="category" size="1">
<option value="General">General</option>
<?php
foreach( $arr_rootfilelist as $i ) {
if($i['type']=='dir') {
if($i['name'] == $category){
print "<option value='" . $i['name'] ."' selected='selected'>" . $i['name'] . "</option>\n";
}
else{
print "<option value='" . $i['name'] ."'>" . $i['name'] . "</option>\n";
}
}
}
// $content = str_replace("\n\n", "\n", $content);
?>
</select>
<p><b><?php echo $l->t('Title'); ?>:</b><br><input style="width:37em;" name="title" value="<?php echo $title; ?>" type="text" size="200" maxlength="200"></p>
<p><b><?php echo $l->t('Content'); ?>:</b></p>
<textarea id="markdown" style="width:50em;" name="content" cols="200" rows="15"><?php echo $content; ?></textarea><br>
<!-- <b><a href="http://michelf.ca/projects/php-markdown/concepts/" target="_blank">Hint: </b>You can use <b>MarkDown</b> to format your text.</a><br> -->
<input type="hidden" name="file" value="<?php echo $file; ?>">
<input type="hidden" name="old_category" value="<?php echo $category; ?>">
<?php if(!isset($_GET['new'])){ ?>
<!-- <input type="checkbox" name="delete" value="true"><b><?php echo $l->t('Delete'); ?></b> -->
<?php } ?>
<button type="submit" name="save" value="true" ><?php echo $l->t('Save'); ?></button>
<?php
if(!OCP\App::isEnabled('files_versions')){
echo "Version control is not enabled, please enable version in the apps menu!";
}
else{ //versions enabled
$source = $root . "/" . $category . "/" . $file;
// print "Source: $source";
if( OCA_Versions\Storage::isversioned( $source ) ) {
$count=50; //show the newest revisions
$versions = OCA_Versions\Storage::getVersions( $source, $count);
$versionsFormatted = array();
foreach ( $versions AS $version ) {
$versionsFormatted[] = OCP\Util::formatDate( $version['version'] );
}
$versionsSorted = array_reverse( $versions );
?><br>
<b><?php echo $l->t('Restore content'); ?>:</b>
<select name="version" size="1">
<?php
foreach( $versionsSorted as $i ) {
print "<option value='" . $i['version'] . "'>" . OCP\Util::formatDate( $i['version'] ) . "</option>\n";
}
?>
<input type="hidden" name="" value=""><!--Workaround-->
<button type="submit" name="restore" value="true" ><?php echo $l->t('Restore'); ?></button>
<?php
}
}
}
?>
</form>
</div>
<?php } ?>
<script type="text/javascript">
function getEventTarget(e) {
e = e || window.event;
return e.target || e.srcElement;
}
var ul = document.getElementById('entries');
ul.onclick = function(event) {
var target = getEventTarget(event);
var txt = target.innerHTML;
var arr = txt.split('"');
url = arr[1]
url = arr[1].replace(/&amp;/g, "&");
if(url != "active"){
// alert(url);
window.open(url, "_self");
}
};
function checkform()
{
if(String.trim(document.notes_save.title.value) == ""){
alert("<?php echo $l->t('The title can not be empty'); ?>!");
return false;
}
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
for (var i = 0; i < invalid_characters.length; i++) {
if (document.notes_save.title.value.indexOf(invalid_characters[i]) != -1) {
alert("<?php echo $l->t('Invalid title'); echo "!\\n"; echo $l->t('The following characters are not allowed'); ?>: '\\', '/', '<', '>', ':', '\"', '|', '?', '*'");
return false;
}
}
return true;
}
</script>