Welcome to mirror list, hosted at ThFree Co, Russian Federation.

controller.php « tags « core - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e06a343f2b3a25362237c0d94000e1e5c2098951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Thomas Tanghus <thomas@tanghus.net>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program 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, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OC\Core\Tags;

class Controller {
	protected static function getTagger($type) {
		\OC_JSON::checkLoggedIn();
		\OC_JSON::callCheck();

		try {
			$tagger = \OC::$server->getTagManager()->load($type);
			return $tagger;
		} catch(\Exception $e) {
			\OCP\Util::writeLog('core', __METHOD__ . ' Exception: ' . $e->getMessage(), \OCP\Util::ERROR);
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error loading tags')));
			exit;
		}
	}

	public static function getTags($args) {
		$tagger = self::getTagger($args['type']);
		\OC_JSON::success(array('tags'=> $tagger->getTags()));
	}

	public static function getFavorites($args) {
		$tagger = self::getTagger($args['type']);
		\OC_JSON::success(array('ids'=> $tagger->getFavorites()));
	}

	public static function getIdsForTag($args) {
		$tagger = self::getTagger($args['type']);
		\OC_JSON::success(array('ids'=> $tagger->getIdsForTag($_GET['tag'])));
	}

	public static function addTag($args) {
		$tagger = self::getTagger($args['type']);

		$id = $tagger->add(strip_tags($_POST['tag']));
		if($id === false) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Tag already exists')));
		} else {
			\OC_JSON::success(array('id'=> $id));
		}
	}

	public static function deleteTags($args) {
		$tags = $_POST['tags'];
		if(!is_array($tags)) {
			$tags = array($tags);
		}

		$tagger = self::getTagger($args['type']);

		if(!$tagger->delete($tags)) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error deleting tag(s)')));
		} else {
			\OC_JSON::success();
		}
	}

	public static function tagAs($args) {
		$tagger = self::getTagger($args['type']);

		if(!$tagger->tagAs($args['id'], $_POST['tag'])) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error tagging')));
		} else {
			\OC_JSON::success();
		}
	}

	public static function unTag($args) {
		$tagger = self::getTagger($args['type']);

		if(!$tagger->unTag($args['id'], $_POST['tag'])) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error untagging')));
		} else {
			\OC_JSON::success();
		}
	}

	public static function favorite($args) {
		$tagger = self::getTagger($args['type']);

		if(!$tagger->addToFavorites($args['id'])) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error favoriting')));
		} else {
			\OC_JSON::success();
		}
	}

	public static function unFavorite($args) {
		$tagger = self::getTagger($args['type']);

		if(!$tagger->removeFromFavorites($args['id'])) {
			$l = new \OC_L10n('core');
			\OC_JSON::error(array('message'=> $l->t('Error unfavoriting')));
		} else {
			\OC_JSON::success();
		}
	}

}