summaryrefslogtreecommitdiffstats
path: root/core/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'core/ajax')
-rw-r--r--core/ajax/requesttoken.php40
-rw-r--r--core/ajax/share.php50
-rw-r--r--core/ajax/vcategories/add.php20
-rw-r--r--core/ajax/vcategories/addToFavorites.php38
-rw-r--r--core/ajax/vcategories/delete.php25
-rw-r--r--core/ajax/vcategories/edit.php14
-rw-r--r--core/ajax/vcategories/favorites.php30
-rw-r--r--core/ajax/vcategories/removeFromFavorites.php38
8 files changed, 186 insertions, 69 deletions
diff --git a/core/ajax/requesttoken.php b/core/ajax/requesttoken.php
deleted file mode 100644
index 9d43a722852..00000000000
--- a/core/ajax/requesttoken.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
-* ownCloud
-* @author Christian Reiner
-* @copyright 2011-2012 Christian Reiner <foss@christian-reiner.info>
-*
-* 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/>.
-*
-*/
-
-/**
- * @file core/ajax/requesttoken.php
- * @brief Ajax method to retrieve a fresh request protection token for ajax calls
- * @return json: success/error state indicator including a fresh request token
- * @author Christian Reiner
- */
-
-// don't load apps or filesystem for this task
-$RUNTIME_NOAPPS = true;
-$RUNTIME_NOSETUPFS = true;
-
-// Sanity checks
-// using OCP\JSON::callCheck() below protects the token refreshing itself.
-//OCP\JSON::callCheck ( );
-OCP\JSON::checkLoggedIn ( );
-// hand out a fresh token
-OCP\JSON::success ( array ( 'token' => OCP\Util::callRegister() ) );
-?>
diff --git a/core/ajax/share.php b/core/ajax/share.php
index efe01dff886..12206e0fd79 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -28,13 +28,19 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
case 'share':
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
try {
- if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') {
+ $shareType = (int)$_POST['shareType'];
+ $shareWith = $_POST['shareWith'];
+ if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') {
$shareWith = null;
+ }
+
+ $token = OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], $shareType, $shareWith, $_POST['permissions']);
+
+ if (is_string($token)) {
+ OC_JSON::success(array('data' => array('token' => $token)));
} else {
- $shareWith = $_POST['shareWith'];
+ OC_JSON::success();
}
- OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $shareWith, $_POST['permissions']);
- OC_JSON::success();
} catch (Exception $exception) {
OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
}
@@ -63,6 +69,42 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
+ case 'email':
+ // read post variables
+ $user = OCP\USER::getUser();
+ $type = $_POST['itemType'];
+ $link = $_POST['link'];
+ $file = $_POST['file'];
+ $to_address = $_POST['toaddress'];
+
+ // enable l10n support
+ $l = OC_L10N::get('core');
+
+ // setup the email
+ $subject = (string)$l->t('User %s shared a file with you', $user);
+ if ($type === 'dir')
+ $subject = (string)$l->t('User %s shared a folder with you', $user);
+
+ $text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($user, $file, $link));
+ if ($type === 'dir')
+ $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($user, $file, $link));
+
+ // handle localhost installations
+ $server_host = OCP\Util::getServerHost();
+ if ($server_host === 'localhost')
+ $server_host = "example.com";
+
+ $default_from = 'sharing-noreply@' . $server_host;
+ $from_address = OCP\Config::getUserValue($user, 'settings', 'email', $default_from );
+
+ // send it out now
+ try {
+ OCP\Util::sendMail($to_address, $to_address, $subject, $text, $from_address, $user);
+ OCP\JSON::success();
+ } catch (Exception $exception) {
+ OCP\JSON::error(array('data' => array('message' => $exception->getMessage())));
+ }
+ break;
}
} else if (isset($_GET['fetch'])) {
switch ($_GET['fetch']) {
diff --git a/core/ajax/vcategories/add.php b/core/ajax/vcategories/add.php
index 8d31275dbfb..23d00af70ab 100644
--- a/core/ajax/vcategories/add.php
+++ b/core/ajax/vcategories/add.php
@@ -14,23 +14,25 @@ function debug($msg) {
OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
}
-OC_JSON::checkLoggedIn();
-$category = isset($_GET['category'])?strip_tags($_GET['category']):null;
-$app = isset($_GET['app'])?$_GET['app']:null;
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
-if(is_null($app)) {
- bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
-}
+$l = OC_L10N::get('core');
+
+$category = isset($_POST['category']) ? strip_tags($_POST['category']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
-OC_JSON::checkAppEnabled($app);
+if(is_null($type)) {
+ bailOut($l->t('Category type not provided.'));
+}
if(is_null($category)) {
- bailOut(OC_Contacts_App::$l10n->t('No category to add?'));
+ bailOut($l->t('No category to add?'));
}
debug(print_r($category, true));
-$categories = new OC_VCategories($app);
+$categories = new OC_VCategories($type);
if($categories->hasCategory($category)) {
bailOut(OC_Contacts_App::$l10n->t('This category already exists: '.$category));
} else {
diff --git a/core/ajax/vcategories/addToFavorites.php b/core/ajax/vcategories/addToFavorites.php
new file mode 100644
index 00000000000..52f62d5fc6b
--- /dev/null
+++ b/core/ajax/vcategories/addToFavorites.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
+
+$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
+
+if(is_null($id)) {
+ bailOut($l->t('%s ID not provided.', $type));
+}
+
+$categories = new OC_VCategories($type);
+if(!$categories->addToFavorites($id, $type)) {
+ bailOut($l->t('Error adding %s to favorites.', $id));
+}
+
+OC_JSON::success();
diff --git a/core/ajax/vcategories/delete.php b/core/ajax/vcategories/delete.php
index 74b0220870c..dfec3785743 100644
--- a/core/ajax/vcategories/delete.php
+++ b/core/ajax/vcategories/delete.php
@@ -15,21 +15,26 @@ function debug($msg) {
OC_Log::write('core', 'ajax/vcategories/delete.php: '.$msg, OC_Log::DEBUG);
}
-OC_JSON::checkLoggedIn();
-$app = isset($_POST['app'])?$_POST['app']:null;
-$categories = isset($_POST['categories'])?$_POST['categories']:null;
-if(is_null($app)) {
- bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
-}
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
-OC_JSON::checkAppEnabled($app);
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
-debug('The application "'.$app.'" uses the default file. OC_VObjects will not be updated.');
+debug('The application using category type "'
+ . $type
+ . '" uses the default file for deletion. OC_VObjects will not be updated.');
if(is_null($categories)) {
- bailOut('No categories selected for deletion.');
+ bailOut($l->t('No categories selected for deletion.'));
}
-$vcategories = new OC_VCategories($app);
+$vcategories = new OC_VCategories($type);
$vcategories->delete($categories);
OC_JSON::success(array('data' => array('categories'=>$vcategories->categories())));
diff --git a/core/ajax/vcategories/edit.php b/core/ajax/vcategories/edit.php
index caeebcaa940..0387b17576c 100644
--- a/core/ajax/vcategories/edit.php
+++ b/core/ajax/vcategories/edit.php
@@ -16,16 +16,18 @@ function debug($msg) {
}
OC_JSON::checkLoggedIn();
-$app = isset($_GET['app'])?$_GET['app']:null;
-if(is_null($app)) {
- bailOut('Application name not provided.');
+$l = OC_L10N::get('core');
+
+$type = isset($_GET['type']) ? $_GET['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Category type not provided.'));
}
-OC_JSON::checkAppEnabled($app);
-$tmpl = new OC_TEMPLATE("core", "edit_categories_dialog");
+$tmpl = new OCP\Template("core", "edit_categories_dialog");
-$vcategories = new OC_VCategories($app);
+$vcategories = new OC_VCategories($type);
$categories = $vcategories->categories();
debug(print_r($categories, true));
$tmpl->assign('categories', $categories);
diff --git a/core/ajax/vcategories/favorites.php b/core/ajax/vcategories/favorites.php
new file mode 100644
index 00000000000..db4244d601a
--- /dev/null
+++ b/core/ajax/vcategories/favorites.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$type = isset($_GET['type']) ? $_GET['type'] : null;
+
+if(is_null($type)) {
+ $l = OC_L10N::get('core');
+ bailOut($l->t('Object type not provided.'));
+}
+
+$categories = new OC_VCategories($type);
+$ids = $categories->getFavorites($type);
+
+OC_JSON::success(array('ids' => $ids));
diff --git a/core/ajax/vcategories/removeFromFavorites.php b/core/ajax/vcategories/removeFromFavorites.php
new file mode 100644
index 00000000000..ba6e95c2497
--- /dev/null
+++ b/core/ajax/vcategories/removeFromFavorites.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/removeFromFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/removeFromFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
+
+$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
+
+if(is_null($id)) {
+ bailOut($l->t('%s ID not provided.', $type));
+}
+
+$categories = new OC_VCategories($type);
+if(!$categories->removeFromFavorites($id, $type)) {
+ bailOut($l->t('Error removing %s from favorites.', $id));
+}
+
+OC_JSON::success();