summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-04-18 17:27:34 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-04-18 17:27:34 +0200
commit45de7ad221f9e505abdabcc5084dd12c80851469 (patch)
tree9afe2994fe01d35cf7aa2e16389c04bb3e298faf /apps/files/ajax
parentdfc92675e0d76ad9550a274b712e084e1738831c (diff)
downloadnextcloud-server-45de7ad221f9e505abdabcc5084dd12c80851469.tar.gz
nextcloud-server-45de7ad221f9e505abdabcc5084dd12c80851469.zip
move files to app folder
Diffstat (limited to 'apps/files/ajax')
-rw-r--r--apps/files/ajax/autocomplete.php56
-rw-r--r--apps/files/ajax/delete.php29
-rw-r--r--apps/files/ajax/download.php37
-rw-r--r--apps/files/ajax/list.php46
-rw-r--r--apps/files/ajax/mimeicon.php11
-rw-r--r--apps/files/ajax/move.php20
-rw-r--r--apps/files/ajax/newfile.php47
-rw-r--r--apps/files/ajax/newfolder.php22
-rw-r--r--apps/files/ajax/rawlist.php26
-rw-r--r--apps/files/ajax/rename.php21
-rw-r--r--apps/files/ajax/scan.php38
-rw-r--r--apps/files/ajax/timezone.php6
-rw-r--r--apps/files/ajax/upload.php64
13 files changed, 423 insertions, 0 deletions
diff --git a/apps/files/ajax/autocomplete.php b/apps/files/ajax/autocomplete.php
new file mode 100644
index 00000000000..8cdb6188a02
--- /dev/null
+++ b/apps/files/ajax/autocomplete.php
@@ -0,0 +1,56 @@
+<?php
+//provide auto completion of paths for use with jquer ui autocomplete
+
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get data
+$query = $_GET['term'];
+$dirOnly=(isset($_GET['dironly']))?($_GET['dironly']=='true'):false;
+
+if($query[0]!='/'){
+ $query='/'.$query;
+}
+
+if(substr($query,-1,1)=='/'){
+ $base=$query;
+}else{
+ $base=dirname($query);
+}
+
+$query=substr($query,strlen($base));
+
+if($base!='/'){
+ $query=substr($query,1);
+}
+$queryLen=strlen($query);
+$query=strtolower($query);
+
+// echo "$base - $query";
+
+$files=array();
+
+if(OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)){
+ $dh = OC_Filesystem::opendir($base);
+ if($dh){
+ if(substr($base,-1,1)!='/'){
+ $base=$base.'/';
+ }
+ while (($file = readdir($dh)) !== false) {
+ if ($file != "." && $file != ".."){
+ if(substr(strtolower($file),0,$queryLen)==$query){
+ $item=$base.$file;
+ if((!$dirOnly or OC_Filesystem::is_dir($item))){
+ $files[]=(object)array('id'=>$item,'label'=>$item,'name'=>$item);
+ }
+ }
+ }
+ }
+ }
+}
+OC_JSON::encodedPrint($files);
+
+?>
diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php
new file mode 100644
index 00000000000..d8a01d7acf1
--- /dev/null
+++ b/apps/files/ajax/delete.php
@@ -0,0 +1,29 @@
+<?php
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get data
+$dir = stripslashes($_GET["dir"]);
+$files = isset($_GET["file"]) ? stripslashes($_GET["file"]) : stripslashes($_GET["files"]);
+
+$files = explode(';', $files);
+$filesWithError = '';
+$success = true;
+//Now delete
+foreach($files as $file) {
+ if( !OC_Files::delete( $dir, $file )){
+ $filesWithError .= $file . "\n";
+ $success = false;
+ }
+}
+
+if($success) {
+ OC_JSON::success(array("data" => array( "dir" => $dir, "files" => $files )));
+} else {
+ OC_JSON::error(array("data" => array( "message" => "Could not delete:\n" . $filesWithError )));
+}
+
+?>
diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php
new file mode 100644
index 00000000000..65c04c36faf
--- /dev/null
+++ b/apps/files/ajax/download.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+* ownCloud - ajax frontend
+*
+* @author Robin Appelman
+* @copyright 2010 Robin Appelman icewind1991@gmail.com
+*
+* 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 Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+// only need filesystem apps
+$RUNTIME_APPTYPES=array('filesystem');
+
+// Init owncloud
+
+
+// Check if we are a user
+OC_Util::checkLoggedIn();
+
+$files = $_GET["files"];
+$dir = $_GET["dir"];
+
+OC_Files::get($dir,$files);
+?>
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php
new file mode 100644
index 00000000000..83914332a7d
--- /dev/null
+++ b/apps/files/ajax/list.php
@@ -0,0 +1,46 @@
+<?php
+
+// only need filesystem apps
+$RUNTIME_APPTYPES=array('filesystem');
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Load the files
+$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+$doBreadcrumb = isset( $_GET['breadcrumb'] ) ? true : false;
+$data = array();
+
+// Make breadcrumb
+if($doBreadcrumb){
+ $breadcrumb = array();
+ $pathtohere = "/";
+ foreach( explode( "/", $dir ) as $i ){
+ if( $i != "" ){
+ $pathtohere .= "$i/";
+ $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
+ }
+ }
+
+ $breadcrumbNav = new OC_Template( "files", "part.breadcrumb", "" );
+ $breadcrumbNav->assign( "breadcrumb", $breadcrumb );
+
+ $data['breadcrumb'] = $breadcrumbNav->fetchPage();
+}
+
+// make filelist
+$files = array();
+foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
+ $i["date"] = OC_Util::formatDate($i["mtime"] );
+ $files[] = $i;
+}
+
+$list = new OC_Template( "files", "part.list", "" );
+$list->assign( "files", $files );
+$data = array('files' => $list->fetchPage());
+
+OC_JSON::success(array('data' => $data));
+
+?>
diff --git a/apps/files/ajax/mimeicon.php b/apps/files/ajax/mimeicon.php
new file mode 100644
index 00000000000..57898cd82d9
--- /dev/null
+++ b/apps/files/ajax/mimeicon.php
@@ -0,0 +1,11 @@
+<?php
+
+// no need for apps
+$RUNTIME_NOAPPS=false;
+
+// Init owncloud
+
+
+print OC_Helper::mimetypeIcon($_GET['mime']);
+
+?>
diff --git a/apps/files/ajax/move.php b/apps/files/ajax/move.php
new file mode 100644
index 00000000000..0ad314f873c
--- /dev/null
+++ b/apps/files/ajax/move.php
@@ -0,0 +1,20 @@
+<?php
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get data
+$dir = stripslashes($_GET["dir"]);
+$file = stripslashes($_GET["file"]);
+$target = stripslashes($_GET["target"]);
+
+
+if(OC_Files::move($dir,$file,$target,$file)){
+ OC_JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
+}else{
+ OC_JSON::error(array("data" => array( "message" => "Could not move $file" )));
+}
+
+?>
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
new file mode 100644
index 00000000000..472b577a32a
--- /dev/null
+++ b/apps/files/ajax/newfile.php
@@ -0,0 +1,47 @@
+<?php
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get the params
+$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
+$filename = isset( $_POST['filename'] ) ? stripslashes($_POST['filename']) : '';
+$content = isset( $_POST['content'] ) ? $_POST['content'] : '';
+$source = isset( $_POST['source'] ) ? stripslashes($_POST['source']) : '';
+
+if($filename == '') {
+ OC_JSON::error(array("data" => array( "message" => "Empty Filename" )));
+ exit();
+}
+
+if($source){
+ if(substr($source,0,8)!='https://' and substr($source,0,7)!='http://'){
+ OC_JSON::error(array("data" => array( "message" => "Not a valid source" )));
+ exit();
+ }
+ $sourceStream=fopen($source,'rb');
+ $target=$dir.'/'.$filename;
+ $result=OC_Filesystem::file_put_contents($target,$sourceStream);
+ if($result){
+ $mime=OC_Filesystem::getMimetype($target);
+ OC_JSON::success(array("data" => array('mime'=>$mime)));
+ exit();
+ }else{
+ OC_JSON::error(array("data" => array( "message" => "Error while downloading ".$source. ' to '.$target )));
+ exit();
+ }
+}
+
+
+if(OC_Files::newFile($dir, $filename, 'file')) {
+ if($content){
+ OC_Filesystem::file_put_contents($dir.'/'.$filename,$content);
+ }
+ OC_JSON::success(array("data" => array('content'=>$content)));
+ exit();
+}
+
+
+OC_JSON::error(array("data" => array( "message" => "Error when creating the file" )));
diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
new file mode 100644
index 00000000000..2aff95e5b35
--- /dev/null
+++ b/apps/files/ajax/newfolder.php
@@ -0,0 +1,22 @@
+<?php
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get the params
+$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
+$foldername = isset( $_POST['foldername'] ) ? stripslashes($_POST['foldername']) : '';
+
+if(trim($foldername) == '') {
+ OC_JSON::error(array("data" => array( "message" => "Empty Foldername" )));
+ exit();
+}
+
+if(OC_Files::newFile($dir, stripslashes($foldername), 'dir')) {
+ OC_JSON::success(array("data" => array()));
+ exit();
+}
+
+OC_JSON::error(array("data" => array( "message" => "Error when creating the folder" )));
diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php
new file mode 100644
index 00000000000..8f1990d1b8f
--- /dev/null
+++ b/apps/files/ajax/rawlist.php
@@ -0,0 +1,26 @@
+<?php
+
+// only need filesystem apps
+$RUNTIME_APPTYPES=array('filesystem');
+
+// Init owncloud
+
+require_once('../../lib/template.php');
+
+OC_JSON::checkLoggedIn();
+
+// Load the files
+$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
+
+// make filelist
+$files = array();
+foreach( OC_Files::getdirectorycontent( $dir, $mimetype ) as $i ){
+ $i["date"] = OC_Util::formatDate($i["mtime"] );
+ $i['mimetype_icon'] = $i['type'] == 'dir' ? mimetype_icon('dir'): mimetype_icon($i['mimetype']);
+ $files[] = $i;
+}
+
+OC_JSON::success(array('data' => $files));
+
+?>
diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php
new file mode 100644
index 00000000000..dc5d3962abd
--- /dev/null
+++ b/apps/files/ajax/rename.php
@@ -0,0 +1,21 @@
+<?php
+
+// Init owncloud
+
+
+OC_JSON::checkLoggedIn();
+
+// Get data
+$dir = stripslashes($_GET["dir"]);
+$file = stripslashes($_GET["file"]);
+$newname = stripslashes($_GET["newname"]);
+
+// Delete
+if( OC_Files::move( $dir, $file, $dir, $newname )) {
+ OC_JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
+}
+else{
+ OC_JSON::error(array("data" => array( "message" => "Unable to rename file" )));
+}
+
+?>
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php
new file mode 100644
index 00000000000..db09b7d5c64
--- /dev/null
+++ b/apps/files/ajax/scan.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once '../../lib/base.php';
+
+set_time_limit(0);//scanning can take ages
+
+$force=isset($_GET['force']) and $_GET['force']=='true';
+$checkOnly=isset($_GET['checkonly']) and $_GET['checkonly']=='true';
+
+if(!$checkOnly){
+ $eventSource=new OC_EventSource();
+}
+
+
+//create the file cache if necesary
+if($force or !OC_FileCache::inCache('')){
+ if(!$checkOnly){
+ OC_DB::beginTransaction();
+ OC_FileCache::scan('',$eventSource);
+ OC_FileCache::clean();
+ OC_DB::commit();
+ $eventSource->send('success',true);
+ }else{
+ OC_JSON::success(array('data'=>array('done'=>true)));
+ exit;
+ }
+}else{
+ if($checkOnly){
+ OC_JSON::success(array('data'=>array('done'=>false)));
+ exit;
+ }
+ if(isset($eventSource)){
+ $eventSource->send('success',false);
+ }else{
+ exit;
+ }
+}
+$eventSource->close(); \ No newline at end of file
diff --git a/apps/files/ajax/timezone.php b/apps/files/ajax/timezone.php
new file mode 100644
index 00000000000..8e1d2aa1ec1
--- /dev/null
+++ b/apps/files/ajax/timezone.php
@@ -0,0 +1,6 @@
+<?php
+ // FIXME: this should start a secure session if forcessl is enabled
+ // see lib/base.php for an example
+ session_start();
+ $_SESSION['timezone'] = $_GET['time'];
+?>
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
new file mode 100644
index 00000000000..c60e1a3752a
--- /dev/null
+++ b/apps/files/ajax/upload.php
@@ -0,0 +1,64 @@
+<?php
+
+// Init owncloud
+
+
+// Firefox and Konqueror tries to download application/json for me. --Arthur
+OC_JSON::setContentTypeHeader('text/plain');
+
+OC_JSON::checkLoggedIn();
+
+if (!isset($_FILES['files'])) {
+ OC_JSON::error(array("data" => array( "message" => "No file was uploaded. Unknown error" )));
+ exit();
+}
+foreach ($_FILES['files']['error'] as $error) {
+ if ($error != 0) {
+ $l=OC_L10N::get('files');
+ $errors = array(
+ UPLOAD_ERR_OK=>$l->t("There is no error, the file uploaded with success"),
+ UPLOAD_ERR_INI_SIZE=>$l->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
+ UPLOAD_ERR_FORM_SIZE=>$l->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
+ UPLOAD_ERR_PARTIAL=>$l->t("The uploaded file was only partially uploaded"),
+ UPLOAD_ERR_NO_FILE=>$l->t("No file was uploaded"),
+ UPLOAD_ERR_NO_TMP_DIR=>$l->t("Missing a temporary folder"),
+ UPLOAD_ERR_CANT_WRITE=>$l->t('Failed to write to disk'),
+ );
+ OC_JSON::error(array("data" => array( "message" => $errors[$error] )));
+ exit();
+ }
+}
+$files=$_FILES['files'];
+
+$dir = $_POST['dir'];
+$dir .= '/';
+$error='';
+
+$totalSize=0;
+foreach($files['size'] as $size){
+ $totalSize+=$size;
+}
+if($totalSize>OC_Filesystem::free_space('/')){
+ OC_JSON::error(array("data" => array( "message" => "Not enough space available" )));
+ exit();
+}
+
+$result=array();
+if(strpos($dir,'..') === false){
+ $fileCount=count($files['name']);
+ for($i=0;$i<$fileCount;$i++){
+ $target = OC_Helper::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
+ if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){
+ $meta=OC_FileCache::getCached($target);
+ $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>basename($target));
+ }
+ }
+ OC_JSON::encodedPrint($result);
+ exit();
+}else{
+ $error='invalid dir';
+}
+
+OC_JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
+
+?>