aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-10-19 00:07:41 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-10-19 00:07:41 +0200
commit26719005a466a0730bd24110115192188c5e60dd (patch)
tree5ab82720589082eed9855ee401aa203e2ff74ccc
parentf4fd4a5a529aac331c7453bc1d3372da5c71f05c (diff)
downloadnextcloud-server-26719005a466a0730bd24110115192188c5e60dd.tar.gz
nextcloud-server-26719005a466a0730bd24110115192188c5e60dd.zip
Added ajax files for favorite category handling.
-rw-r--r--core/ajax/vcategories/addToFavorites.php40
-rw-r--r--core/ajax/vcategories/favorites.php33
-rw-r--r--core/ajax/vcategories/removeFromFavorites.php40
3 files changed, 113 insertions, 0 deletions
diff --git a/core/ajax/vcategories/addToFavorites.php b/core/ajax/vcategories/addToFavorites.php
new file mode 100644
index 00000000000..f330d19c8a4
--- /dev/null
+++ b/core/ajax/vcategories/addToFavorites.php
@@ -0,0 +1,40 @@
+<?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);
+}
+
+require_once '../../../lib/base.php';
+
+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/favorites.php b/core/ajax/vcategories/favorites.php
new file mode 100644
index 00000000000..35b23e29c13
--- /dev/null
+++ b/core/ajax/vcategories/favorites.php
@@ -0,0 +1,33 @@
+<?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);
+}
+
+require_once '../../../lib/base.php';
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+
+$type = isset($_POST['type']) ? $_POST['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..f779df48f21
--- /dev/null
+++ b/core/ajax/vcategories/removeFromFavorites.php
@@ -0,0 +1,40 @@
+<?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);
+}
+
+require_once '../../../lib/base.php';
+
+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();