PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/core/ajax/vcategories/addToFavorites.php

https://github.com/jlgg/simple_trash
PHP | 38 lines | 25 code | 7 blank | 6 comment | 3 complexity | ffdfb22590c6dee2efc863a58d357577 MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. function bailOut($msg) {
  9. OC_JSON::error(array('data' => array('message' => $msg)));
  10. OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
  11. exit();
  12. }
  13. function debug($msg) {
  14. OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
  15. }
  16. OCP\JSON::checkLoggedIn();
  17. OCP\JSON::callCheck();
  18. $l = OC_L10N::get('core');
  19. $id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
  20. $type = isset($_POST['type']) ? $_POST['type'] : null;
  21. if(is_null($type)) {
  22. bailOut($l->t('Object type not provided.'));
  23. }
  24. if(is_null($id)) {
  25. bailOut($l->t('%s ID not provided.', $type));
  26. }
  27. $categories = new OC_VCategories($type);
  28. if(!$categories->addToFavorites($id, $type)) {
  29. bailOut($l->t('Error adding %s to favorites.', $id));
  30. }
  31. OC_JSON::success();