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

init.php « api_feedreader « tt-rss-feedreader-plugin « data - github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6e445a69d7ca1340522062994c67101ca0d35e2 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
class Api_feedreader extends Plugin {
	private $host;
	private $dbh;

	function about()
	{
		return array(1.0,
			"API plugin for FeedReader",
			"JeanLuc",
			true
			);
	}

	function api_version()
	{
		return 2;
	}

	function init($host)
	{
		$this->host = $host;
		$this->dbh = $host->get_dbh();
		$this->host->add_api_method("addLabel", $this);
		$this->host->add_api_method("removeLabel", $this);
		$this->host->add_api_method("renameLabel", $this);
		$this->host->add_api_method("addCategory", $this);
		$this->host->add_api_method("removeCategory", $this);
		$this->host->add_api_method("renameCategory", $this);
		$this->host->add_api_method("moveCategory", $this);
		$this->host->add_api_method("renameFeed", $this);
		$this->host->add_api_method("moveFeed", $this);
	}

	function removeLabel()
	{
		$label_id = (int)$_REQUEST["label_id"];
		if($label_id != "")
		{
			Labels::remove(Labels::feed_to_label_id($label_id), $_SESSION["uid"]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function addLabel()
	{
		$caption = $_REQUEST["caption"];
		if($caption != "")
		{
			Labels::create($caption);
			$id = Labels::find_id($caption, $_SESSION["uid"]);
			return array(API::STATUS_OK, Labels::label_to_feed_id($id));
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function renameLabel()
	{
		$caption = $_REQUEST["caption"];
		$label_id = Labels::feed_to_label_id((int)$_REQUEST["label_id"]);

		if($label_id != "" && $caption != "")
		{
			$sth = $this->dbh->prepare("UPDATE ttrss_labels2 SET caption = ? WHERE id = ? AND owner_uid = ?");
			$sth->execute([$caption, $label_id, $_SESSION["uid"]]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function removeCategory()
	{
		$category_id = (int)$_REQUEST["category_id"];
		if($category_id != "")
		{
			$sth = $this->dbh->prepare("DELETE FROM ttrss_feed_categories WHERE id = ? AND owner_uid = ?");
			$sth->execute([$category_id, $_SESSION["uid"]]);
			ccache_remove($category_id, $_SESSION["uid"], true);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function moveCategory()
	{
		$category_id = (int)db_escape_string($_REQUEST["category_id"]);
		$parent_id = (int)db_escape_string($_REQUEST["parent_id"]);

		if($category_id != "")
		{
			if($parent_id == "")
			{
				$parent_id = null;
			}

			$sth = $this->dbh->prepare("UPDATE ttrss_feed_categories SET parent_cat = ? WHERE id = ? AND owner_uid = ?");
			$sth->execute([$parent_id, $category_id, $_SESSION["uid"]]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function addCategory()
	{
		$caption = $_REQUEST["caption"];
		$parent_id = (int)$_REQUEST["parent_id"];
		if($caption != "")
		{
			$query = "SELECT id FROM ttrss_feed_categories WHERE title = ? AND owner_uid = ?";
			$params = [$caption, $_SESSION["uid"]];
			if($parent_id != "")
			{
				add_feed_category($caption, $parent_id);
				$query = $query . " AND parent_cat = ?";
				array_push($params, $parent_id);
			}
			else
			{
				add_feed_category($caption);
				$query = $query . "AND parent_cat IS NULL";
			}
			$sth = $this->dbh->prepare($query);
			$sth->execute($params);
			$id = $sth->fetchColumn();
			return array(API::STATUS_OK, $id);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function renameCategory() {
		$cat_id = (int)$_REQUEST["category_id"];
		$caption = $_REQUEST["caption"];

		if($caption != "")
		{
			$sth = $this->dbh->prepare("UPDATE ttrss_feed_categories SET title = ? WHERE id = ? AND owner_uid = ?");
			$sth->execute([$caption, $cat_id, $_SESSION["uid"]]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function renameFeed() {
		$feed_id = (int)$_REQUEST["feed_id"];
		$caption = $_REQUEST["caption"];

		if($caption != "")
		{
			$sth = $this->dbh->prepare("UPDATE ttrss_feeds SET title = ? WHERE id = ? AND owner_uid = ?");
			$sth->execute([$caption, $feed_id, $_SESSION["uid"]]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}

	function moveFeed() {
		$feed_id = (int)$_REQUEST["feed_id"];
		$cat_id = (int)$_REQUEST["category_id"];

		if($feed_id != "" && $cat_id != "")
		{
			$sth = $this->dbh->prepare("UPDATE ttrss_feeds SET cat_id = ? WHERE id = ? AND owner_uid = ?");
			$sth->execute([$cat_id, $feed_id, $_SESSION["uid"]]);
			return array(API::STATUS_OK);
		}
		else
		{
			return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
		}
	}
}
?>