aboutsummaryrefslogtreecommitdiffstats
path: root/apps/atnotes/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'apps/atnotes/ajax')
-rw-r--r--apps/atnotes/ajax/browse.php112
-rw-r--r--apps/atnotes/ajax/check.php56
-rw-r--r--apps/atnotes/ajax/delete.php34
-rw-r--r--apps/atnotes/ajax/export.php56
-rw-r--r--apps/atnotes/ajax/save.php36
5 files changed, 294 insertions, 0 deletions
diff --git a/apps/atnotes/ajax/browse.php b/apps/atnotes/ajax/browse.php
new file mode 100644
index 00000000000..475b5e8614e
--- /dev/null
+++ b/apps/atnotes/ajax/browse.php
@@ -0,0 +1,112 @@
+<?php
+
+/**
+* ownCloud - ATNotes plugin
+*
+* @author Xavier Beurois
+* @copyright 2012 Xavier Beurois www.djazz-lab.net
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+require_once('../../../lib/base.php');
+require_once('../../../lib/template.php');
+
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('atnotes');
+
+$p = trim($_POST['p']);
+$top = FALSE;
+if($p == '/'){
+ $p = OC::$CONFIG_DATADIRECTORY;
+ $top = TRUE;
+}
+
+$files = Array();
+foreach(OC_Files::getdirectorycontent($p) as $i){
+ $elt = '';
+
+ if($i['type'] == 'file'){
+ $fileinfo = pathinfo($i['name']);
+ $i['basename'] = $fileinfo['filename'];
+ if (!empty($fileinfo['extension'])){
+ $i['extention'] = '.'.$fileinfo['extension'];
+ }else{
+ $i['extention'] = '';
+ }
+ }
+ if($i['directory'] == '/'){
+ $i['directory'] = '';
+ }
+ if($i['extention'] == '.txt' || $i['type'] == 'dir'){
+ $i["date"] = OC_Util::formatDate($i["mtime"]);
+
+ $write = ($i['writeable'])?'true':'false';
+ $simple_file_size = simple_file_size($i['size']);
+ $simple_size_color = intval(200 - $i['size'] / (1024 * 1024) * 2);
+
+ if($simple_size_color < 0){
+ $simple_size_color = 0;
+ }
+
+ $relative_modified_date = relative_modified_date($i['mtime']);
+ $relative_date_color = round((time() - $i['mtime']) / 60 / 60 / 24 * 14);
+
+ if($relative_date_color > 200){
+ $relative_date_color = 200;
+ }
+
+ $name = str_replace('+', '%20', urlencode($i['name']));
+ $name = str_replace('%2F', '/', $name);
+ $directory = str_replace('+', '%20', urlencode($i['directory']));
+ $directory = str_replace('%2F', '/', $directory);
+
+ $elt .= '<tr data-file="'.$name.'" data-type="'.(($i['type'] == 'dir')?'dir':'file').'" data-mime="'.$i['mime'].'" data-size="'.$i['size'].'" data-write="'.$write.'">';
+ $elt .= '<td class="filename svg" data-rel="'.$directory.'/'.$name.'" style="background-image:url('.(($i['type'] == 'dir')?mimetype_icon('dir'):mimetype_icon($i['mime'])).')">';
+ $elt .= '<span class="nametext">';
+ if($i['type'] == 'dir'){
+ $elt .= htmlspecialchars($i['name']);
+ }else{
+ $elt .= htmlspecialchars($i['basename']).'<span class="extention">'.$i['extention'].'</span>';
+ }
+ $elt .= '</span>';
+ $elt .= '</td>';
+ $elt .= '<td class="filesize" title="'.human_file_size($i['size']).'" style="color:rgb('.$simple_size_color.','.$simple_size_color.','.$simple_size_color.')">'.$simple_file_size.'</td>';
+ $elt .= '<td class="date"><span class="modified" title="'.$i['date'].'" style="color:rgb('.$relative_date_color.','.$relative_date_color.','.$relative_date_color.')">'.$relative_modified_date.'</span></td>';
+ $elt .= '</tr>';
+
+ $files[] = $elt;
+ }
+}
+
+if(!$top){
+ $p = str_replace('+', '%20', urlencode($p));
+ $p = str_replace('%2F', '/', $p);
+ $p = substr($p,0,strrpos($p,'/'));
+ if(strlen($p) == 0){
+ $p = '/';
+ }
+
+ $elt = '<tr>';
+ $elt .= '<td class="filename svg" data-rel="'.$p.'" style="background-image:url('.mimetype_icon('dir').')">';
+ $elt .= '<span class="nametext">..</span>';
+ $elt .= '</td>';
+ $elt .= '<td class="filesize">&nbsp;</td>';
+ $elt .= '<td class="date">&nbsp;</td>';
+ $elt .= '</tr>';
+ array_unshift($files, $elt);
+}
+
+OC_JSON::encodedPrint($files); \ No newline at end of file
diff --git a/apps/atnotes/ajax/check.php b/apps/atnotes/ajax/check.php
new file mode 100644
index 00000000000..c2642b620f6
--- /dev/null
+++ b/apps/atnotes/ajax/check.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+* ownCloud - ATNotes plugin
+*
+* @author Xavier Beurois
+* @copyright 2012 Xavier Beurois www.djazz-lab.net
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('atnotes');
+
+$p = trim($_POST['p']);
+$t = trim($_POST['t']);
+
+$normalizeChars = array(
+ 'Á'=>'A', 'À'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Å'=>'A', 'Ä'=>'A', 'Æ'=>'AE', 'Ç'=>'C',
+ 'É'=>'E', 'È'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Í'=>'I', 'Ì'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ð'=>'Eth',
+ 'Ñ'=>'N', 'Ó'=>'O', 'Ò'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O',
+ 'Ú'=>'U', 'Ù'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y',
+ 'á'=>'a', 'à'=>'a', 'â'=>'a', 'ã'=>'a', 'å'=>'a', 'ä'=>'a', 'æ'=>'ae', 'ç'=>'c',
+ 'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'í'=>'i', 'ì'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'eth',
+ 'ñ'=>'n', 'ó'=>'o', 'ò'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o',
+ 'ú'=>'u', 'ù'=>'u', 'û'=>'u', 'ü'=>'u', 'ý'=>'y',
+ 'ß'=>'sz', 'þ'=>'thorn', 'ÿ'=>'y', ' ' => '_', '"' => '', "'" => ' ', '/' => '-'
+);
+
+$r = Array('e' => FALSE, 'p' => '');
+if(strlen($p) != 0 && strlen($t) != 0){
+ $fs = OCP\Files::getStorage('files');
+ if($fs->is_dir($p)){
+ $r['p'] = $p.'/'.strtr($t, $normalizeChars).'.txt';
+ }else{
+ $r['p'] = $p;
+ }
+
+ if($fs->file_exists($r['p'])){
+ $r['e'] = TRUE;
+ }
+}
+
+OCP\JSON::encodedPrint($r);
diff --git a/apps/atnotes/ajax/delete.php b/apps/atnotes/ajax/delete.php
new file mode 100644
index 00000000000..dfb9e116478
--- /dev/null
+++ b/apps/atnotes/ajax/delete.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+* ownCloud - ATNotes plugin
+*
+* @author Xavier Beurois
+* @copyright 2012 Xavier Beurois www.djazz-lab.net
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('atnotes');
+
+$i = trim($_POST['i']);
+
+$r = Array('e' => 1);
+if(is_numeric($i)){
+ $r['e'] = OC_ATNotes::deleteNote($i);
+}
+
+OCP\JSON::encodedPrint($r); \ No newline at end of file
diff --git a/apps/atnotes/ajax/export.php b/apps/atnotes/ajax/export.php
new file mode 100644
index 00000000000..d158f6b3c0c
--- /dev/null
+++ b/apps/atnotes/ajax/export.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+* ownCloud - ATNotes plugin
+*
+* @author Xavier Beurois
+* @copyright 2012 Xavier Beurois www.djazz-lab.net
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('atnotes');
+
+$p = trim($_POST['p']);
+$t = trim($_POST['t']);
+$c = trim($_POST['c']);
+
+$r = Array('e' => '');
+if(strlen($p) != 0 && strlen($t) != 0 && strlen($c) != 0){
+ $fs = OCP\Files::getStorage('files');
+ if(!$fp = $fs->fopen($p, 'w')){
+ $r['e'] = 'Can not open file '.$p;
+ }else{
+ if(fwrite($fp, $t."\n") === FALSE){
+ $r['e'] = 'Can not write to file '.$p;
+ }else{
+ $c = preg_replace('/<br[.*]{0,}>/',"\n",$c);
+ $c = preg_replace('/<u[.*]{0,}>/','',$c);$c = preg_replace('/<\/u>/','',$c);
+ $c = preg_replace('/<b[.*]{0,}>/','',$c);$c = preg_replace('/<\/b>/','',$c);
+ $c = preg_replace('/<i[.*]{0,}>/','',$c);$c = preg_replace('/<\/i>/','',$c);
+ $c = preg_replace('/<hr.*>/',"------------------------\n",$c);
+ $c = preg_replace('/<sup[.*]{0,}>/','(',$c);$c = preg_replace('/<\/sup>/',')',$c);
+ $c = preg_replace('/<sub[.*]{0,}>/','(',$c);$c = preg_replace('/<\/sub>/',')',$c);
+ if(fwrite($fp, $c) === FALSE){
+ $r['e'] = 'Can not write to file '.$p;
+ }else{
+ fclose($fp);
+ }
+ }
+ }
+}
+
+OCP\JSON::encodedPrint($r);
diff --git a/apps/atnotes/ajax/save.php b/apps/atnotes/ajax/save.php
new file mode 100644
index 00000000000..1212c9ea4c3
--- /dev/null
+++ b/apps/atnotes/ajax/save.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+* ownCloud - ATNotes plugin
+*
+* @author Xavier Beurois
+* @copyright 2012 Xavier Beurois www.djazz-lab.net
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('atnotes');
+
+$i = trim($_POST['i']);
+$t = trim($_POST['t']);
+$c = trim($_POST['c']);
+
+$r = Array('e' => '', 'i' => 0);
+if(strlen($t) != 0){
+ $r['i'] = OC_ATNotes::saveNote($i,$t,$c);
+}
+
+OCP\JSON::encodedPrint($r); \ No newline at end of file