diff --git a/core/ajax/vcategories/addToFavorites.php b/core/ajax/vcategories/addToFavorites.php new file mode 100644 index 0000000000..f330d19c8a --- /dev/null +++ b/core/ajax/vcategories/addToFavorites.php @@ -0,0 +1,40 @@ + + * 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 0000000000..35b23e29c1 --- /dev/null +++ b/core/ajax/vcategories/favorites.php @@ -0,0 +1,33 @@ + + * 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 0000000000..f779df48f2 --- /dev/null +++ b/core/ajax/vcategories/removeFromFavorites.php @@ -0,0 +1,40 @@ + + * 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();