Passed
Push — master ( 678db7...164b32 )
by Cody
06:12 queued 03:06
created
classes/dbupdater.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -2,84 +2,84 @@
 block discarded – undo
2 2
 
3 3
 class DbUpdater {
4 4
 
5
-	private $pdo;
6
-	private $db_type;
7
-	private $need_version;
8
-
9
-	public function __construct($db_type, $need_version) {
10
-		$this->pdo = Db::pdo();
11
-		$this->db_type = $db_type;
12
-		$this->need_version = (int) $need_version;
13
-	}
14
-
15
-	public function getSchemaVersion() {
16
-		$row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
17
-		return (int) $row['schema_version'];
18
-	}
19
-
20
-	public function isUpdateRequired() {
21
-		return $this->getSchemaVersion() < $this->need_version;
22
-	}
23
-
24
-	public function getSchemaLines($version) {
25
-		$filename = "schema/versions/".$this->db_type."/$version.sql";
26
-
27
-		if (file_exists($filename)) {
28
-			return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
29
-		} else {
30
-			user_error("DB Updater: schema file for version $version is not found.");
31
-			return false;
32
-		}
33
-	}
34
-
35
-	public function performUpdateTo($version, $html_output = true) {
36
-		if ($this->getSchemaVersion() == $version - 1) {
37
-
38
-			$lines = $this->getSchemaLines($version);
39
-
40
-			if (is_array($lines)) {
41
-
42
-				$this->pdo->beginTransaction();
43
-
44
-				foreach ($lines as $line) {
45
-					if (strpos($line, "--") !== 0 && $line) {
46
-
47
-						if ($html_output) {
48
-													print "<pre>$line</pre>";
49
-						} else {
50
-													Debug::log("> $line");
51
-						}
52
-
53
-						try {
54
-							$this->pdo->query($line); // PDO returns errors as exceptions now
55
-						} catch (PDOException $e) {
56
-							if ($html_output) {
57
-								print "<div class='text-error'>Error: ".$e->getMessage()."</div>";
58
-							} else {
59
-								Debug::log("Error: ".$e->getMessage());
60
-							}
61
-
62
-							$this->pdo->rollBack();
63
-							return false;
64
-						}
65
-					}
66
-				}
67
-
68
-				$db_version = $this->getSchemaVersion();
69
-
70
-				if ($db_version == $version) {
71
-					$this->pdo->commit();
72
-					return true;
73
-				} else {
74
-					$this->pdo->rollBack();
75
-					return false;
76
-				}
77
-			} else {
78
-				return false;
79
-			}
80
-		} else {
81
-			return false;
82
-		}
83
-	}
5
+    private $pdo;
6
+    private $db_type;
7
+    private $need_version;
8
+
9
+    public function __construct($db_type, $need_version) {
10
+        $this->pdo = Db::pdo();
11
+        $this->db_type = $db_type;
12
+        $this->need_version = (int) $need_version;
13
+    }
14
+
15
+    public function getSchemaVersion() {
16
+        $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
17
+        return (int) $row['schema_version'];
18
+    }
19
+
20
+    public function isUpdateRequired() {
21
+        return $this->getSchemaVersion() < $this->need_version;
22
+    }
23
+
24
+    public function getSchemaLines($version) {
25
+        $filename = "schema/versions/".$this->db_type."/$version.sql";
26
+
27
+        if (file_exists($filename)) {
28
+            return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
29
+        } else {
30
+            user_error("DB Updater: schema file for version $version is not found.");
31
+            return false;
32
+        }
33
+    }
34
+
35
+    public function performUpdateTo($version, $html_output = true) {
36
+        if ($this->getSchemaVersion() == $version - 1) {
37
+
38
+            $lines = $this->getSchemaLines($version);
39
+
40
+            if (is_array($lines)) {
41
+
42
+                $this->pdo->beginTransaction();
43
+
44
+                foreach ($lines as $line) {
45
+                    if (strpos($line, "--") !== 0 && $line) {
46
+
47
+                        if ($html_output) {
48
+                                                    print "<pre>$line</pre>";
49
+                        } else {
50
+                                                    Debug::log("> $line");
51
+                        }
52
+
53
+                        try {
54
+                            $this->pdo->query($line); // PDO returns errors as exceptions now
55
+                        } catch (PDOException $e) {
56
+                            if ($html_output) {
57
+                                print "<div class='text-error'>Error: ".$e->getMessage()."</div>";
58
+                            } else {
59
+                                Debug::log("Error: ".$e->getMessage());
60
+                            }
61
+
62
+                            $this->pdo->rollBack();
63
+                            return false;
64
+                        }
65
+                    }
66
+                }
67
+
68
+                $db_version = $this->getSchemaVersion();
69
+
70
+                if ($db_version == $version) {
71
+                    $this->pdo->commit();
72
+                    return true;
73
+                } else {
74
+                    $this->pdo->rollBack();
75
+                    return false;
76
+                }
77
+            } else {
78
+                return false;
79
+            }
80
+        } else {
81
+            return false;
82
+        }
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
classes/digest.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -2,126 +2,126 @@  discard block
 block discarded – undo
2 2
 class Digest
3 3
 {
4 4
 
5
-	/**
6
-	 * Send by mail a digest of last articles.
7
-	 *
8
-	 * @param mixed $link The database connection.
9
-	 * @param integer $limit The maximum number of articles by digest.
10
-	 * @return boolean Return false if digests are not enabled.
11
-	 */
12
-	public static function send_headlines_digests() {
5
+    /**
6
+     * Send by mail a digest of last articles.
7
+     *
8
+     * @param mixed $link The database connection.
9
+     * @param integer $limit The maximum number of articles by digest.
10
+     * @return boolean Return false if digests are not enabled.
11
+     */
12
+    public static function send_headlines_digests() {
13 13
 
14
-		$user_limit = 15; // amount of users to process (e.g. emails to send out)
15
-		$limit = 1000; // maximum amount of headlines to include
14
+        $user_limit = 15; // amount of users to process (e.g. emails to send out)
15
+        $limit = 1000; // maximum amount of headlines to include
16 16
 
17
-		Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit");
17
+        Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit");
18 18
 
19
-		if (DB_TYPE == "pgsql") {
20
-			$interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'";
21
-		} else if (DB_TYPE == "mysql") {
22
-			$interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
23
-		}
19
+        if (DB_TYPE == "pgsql") {
20
+            $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'";
21
+        } else if (DB_TYPE == "mysql") {
22
+            $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
23
+        }
24 24
 
25
-		$pdo = Db::pdo();
25
+        $pdo = Db::pdo();
26 26
 
27
-		$res = $pdo->query("SELECT id,email FROM ttrss_users
27
+        $res = $pdo->query("SELECT id,email FROM ttrss_users
28 28
 				WHERE email != '' AND (last_digest_sent IS NULL OR $interval_qpart)");
29 29
 
30
-		while ($line = $res->fetch()) {
30
+        while ($line = $res->fetch()) {
31 31
 
32
-			if (@get_pref('DIGEST_ENABLE', $line['id'], false)) {
33
-				$preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00'));
32
+            if (@get_pref('DIGEST_ENABLE', $line['id'], false)) {
33
+                $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00'));
34 34
 
35
-				// try to send digests within 2 hours of preferred time
36
-				if ($preferred_ts && time() >= $preferred_ts &&
37
-					time() - $preferred_ts <= 7200
38
-				) {
35
+                // try to send digests within 2 hours of preferred time
36
+                if ($preferred_ts && time() >= $preferred_ts &&
37
+                    time() - $preferred_ts <= 7200
38
+                ) {
39 39
 
40
-					Debug::log("Sending digest for UID:".$line['id']." - ".$line["email"]);
40
+                    Debug::log("Sending digest for UID:".$line['id']." - ".$line["email"]);
41 41
 
42
-					$do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false);
42
+                    $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false);
43 43
 
44
-					global $tz_offset;
44
+                    global $tz_offset;
45 45
 
46
-					// reset tz_offset global to prevent tz cache clash between users
47
-					$tz_offset = -1;
46
+                    // reset tz_offset global to prevent tz cache clash between users
47
+                    $tz_offset = -1;
48 48
 
49
-					$tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit);
50
-					$digest = $tuple[0];
51
-					$headlines_count = $tuple[1];
52
-					$affected_ids = $tuple[2];
53
-					$digest_text = $tuple[3];
49
+                    $tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit);
50
+                    $digest = $tuple[0];
51
+                    $headlines_count = $tuple[1];
52
+                    $affected_ids = $tuple[2];
53
+                    $digest_text = $tuple[3];
54 54
 
55
-					if ($headlines_count > 0) {
55
+                    if ($headlines_count > 0) {
56 56
 
57
-						$mailer = new Mailer();
57
+                        $mailer = new Mailer();
58 58
 
59
-						//$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
59
+                        //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
60 60
 
61
-						$rc = $mailer->mail(["to_name" => $line["login"],
62
-							"to_address" => $line["email"],
63
-							"subject" => DIGEST_SUBJECT,
64
-							"message" => $digest_text,
65
-							"message_html" => $digest]);
61
+                        $rc = $mailer->mail(["to_name" => $line["login"],
62
+                            "to_address" => $line["email"],
63
+                            "subject" => DIGEST_SUBJECT,
64
+                            "message" => $digest_text,
65
+                            "message_html" => $digest]);
66 66
 
67
-						//if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError());
67
+                        //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError());
68 68
 
69
-						Debug::log("RC=$rc");
69
+                        Debug::log("RC=$rc");
70 70
 
71
-						if ($rc && $do_catchup) {
72
-							Debug::log("Marking affected articles as read...");
73
-							Article::catchupArticlesById($affected_ids, 0, $line["id"]);
74
-						}
75
-					} else {
76
-						Debug::log("No headlines");
77
-					}
71
+                        if ($rc && $do_catchup) {
72
+                            Debug::log("Marking affected articles as read...");
73
+                            Article::catchupArticlesById($affected_ids, 0, $line["id"]);
74
+                        }
75
+                    } else {
76
+                        Debug::log("No headlines");
77
+                    }
78 78
 
79
-					$sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW()
79
+                    $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW()
80 80
 						WHERE id = ?");
81
-					$sth->execute([$line["id"]]);
81
+                    $sth->execute([$line["id"]]);
82 82
 
83
-				}
84
-			}
85
-		}
83
+                }
84
+            }
85
+        }
86 86
 
87
-		Debug::log("All done.");
87
+        Debug::log("All done.");
88 88
 
89
-	}
89
+    }
90 90
 
91
-	public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) {
91
+    public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) {
92 92
 
93
-		require_once "lib/MiniTemplator.class.php";
93
+        require_once "lib/MiniTemplator.class.php";
94 94
 
95
-		$tpl = new MiniTemplator;
96
-		$tpl_t = new MiniTemplator;
95
+        $tpl = new MiniTemplator;
96
+        $tpl_t = new MiniTemplator;
97 97
 
98
-		$tpl->readTemplateFromFile("templates/digest_template_html.txt");
99
-		$tpl_t->readTemplateFromFile("templates/digest_template.txt");
98
+        $tpl->readTemplateFromFile("templates/digest_template_html.txt");
99
+        $tpl_t->readTemplateFromFile("templates/digest_template.txt");
100 100
 
101
-		$user_tz_string = get_pref('USER_TIMEZONE', $user_id);
102
-		$local_ts = convert_timestamp(time(), 'UTC', $user_tz_string);
101
+        $user_tz_string = get_pref('USER_TIMEZONE', $user_id);
102
+        $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string);
103 103
 
104
-		$tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
105
-		$tpl->setVariable('CUR_TIME', date('G:i', $local_ts));
106
-		$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
104
+        $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
105
+        $tpl->setVariable('CUR_TIME', date('G:i', $local_ts));
106
+        $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
107 107
 
108
-		$tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
109
-		$tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts));
110
-		$tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH);
108
+        $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
109
+        $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts));
110
+        $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH);
111 111
 
112
-		$affected_ids = array();
112
+        $affected_ids = array();
113 113
 
114
-		$days = (int) $days;
114
+        $days = (int) $days;
115 115
 
116
-		if (DB_TYPE == "pgsql") {
117
-			$interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
118
-		} else if (DB_TYPE == "mysql") {
119
-			$interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
120
-		}
116
+        if (DB_TYPE == "pgsql") {
117
+            $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
118
+        } else if (DB_TYPE == "mysql") {
119
+            $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
120
+        }
121 121
 
122
-		$pdo = Db::pdo();
122
+        $pdo = Db::pdo();
123 123
 
124
-		$sth = $pdo->prepare("SELECT ttrss_entries.title,
124
+        $sth = $pdo->prepare("SELECT ttrss_entries.title,
125 125
 				ttrss_feeds.title AS feed_title,
126 126
 				COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized')."') AS cat_title,
127 127
 				date_updated,
@@ -143,76 +143,76 @@  discard block
 block discarded – undo
143 143
 				AND score >= 0
144 144
 			ORDER BY ttrss_feed_categories.title, ttrss_feeds.title, score DESC, date_updated DESC
145 145
 			LIMIT :limit");
146
-		$sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT);
147
-		$sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT);
148
-		$sth->execute();
146
+        $sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT);
147
+        $sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT);
148
+        $sth->execute();
149 149
 
150
-		$headlines_count = 0;
151
-		$headlines = array();
150
+        $headlines_count = 0;
151
+        $headlines = array();
152 152
 
153
-		while ($line = $sth->fetch()) {
154
-			array_push($headlines, $line);
155
-			$headlines_count++;
156
-		}
153
+        while ($line = $sth->fetch()) {
154
+            array_push($headlines, $line);
155
+            $headlines_count++;
156
+        }
157 157
 
158
-		for ($i = 0; $i < sizeof($headlines); $i++) {
158
+        for ($i = 0; $i < sizeof($headlines); $i++) {
159 159
 
160
-			$line = $headlines[$i];
160
+            $line = $headlines[$i];
161 161
 
162
-			array_push($affected_ids, $line["ref_id"]);
162
+            array_push($affected_ids, $line["ref_id"]);
163 163
 
164
-			$updated = make_local_datetime($line['last_updated'], false,
165
-				$user_id);
164
+            $updated = make_local_datetime($line['last_updated'], false,
165
+                $user_id);
166 166
 
167
-			if (get_pref('ENABLE_FEED_CATS', $user_id)) {
168
-				$line['feed_title'] = $line['cat_title']." / ".$line['feed_title'];
169
-			}
167
+            if (get_pref('ENABLE_FEED_CATS', $user_id)) {
168
+                $line['feed_title'] = $line['cat_title']." / ".$line['feed_title'];
169
+            }
170 170
 
171
-			$article_labels = Article::get_article_labels($line["ref_id"], $user_id);
172
-			$article_labels_formatted = "";
171
+            $article_labels = Article::get_article_labels($line["ref_id"], $user_id);
172
+            $article_labels_formatted = "";
173 173
 
174
-			if (is_array($article_labels) && count($article_labels) > 0) {
175
-				$article_labels_formatted = implode(", ", array_map(function($a) {
176
-					return $a[1];
177
-				}, $article_labels));
178
-			}
174
+            if (is_array($article_labels) && count($article_labels) > 0) {
175
+                $article_labels_formatted = implode(", ", array_map(function($a) {
176
+                    return $a[1];
177
+                }, $article_labels));
178
+            }
179 179
 
180
-			$tpl->setVariable('FEED_TITLE', $line["feed_title"]);
181
-			$tpl->setVariable('ARTICLE_TITLE', $line["title"]);
182
-			$tpl->setVariable('ARTICLE_LINK', $line["link"]);
183
-			$tpl->setVariable('ARTICLE_UPDATED', $updated);
184
-			$tpl->setVariable('ARTICLE_EXCERPT',
185
-				truncate_string(strip_tags($line["content"]), 300));
180
+            $tpl->setVariable('FEED_TITLE', $line["feed_title"]);
181
+            $tpl->setVariable('ARTICLE_TITLE', $line["title"]);
182
+            $tpl->setVariable('ARTICLE_LINK', $line["link"]);
183
+            $tpl->setVariable('ARTICLE_UPDATED', $updated);
184
+            $tpl->setVariable('ARTICLE_EXCERPT',
185
+                truncate_string(strip_tags($line["content"]), 300));
186 186
 //			$tpl->setVariable('ARTICLE_CONTENT',
187 187
 //				strip_tags($article_content));
188
-			$tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true);
188
+            $tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true);
189 189
 
190
-			$tpl->addBlock('article');
190
+            $tpl->addBlock('article');
191 191
 
192
-			$tpl_t->setVariable('FEED_TITLE', $line["feed_title"]);
193
-			$tpl_t->setVariable('ARTICLE_TITLE', $line["title"]);
194
-			$tpl_t->setVariable('ARTICLE_LINK', $line["link"]);
195
-			$tpl_t->setVariable('ARTICLE_UPDATED', $updated);
196
-			$tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true);
197
-			$tpl_t->setVariable('ARTICLE_EXCERPT',
198
-				truncate_string(strip_tags($line["content"]), 300, "..."), true);
192
+            $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]);
193
+            $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]);
194
+            $tpl_t->setVariable('ARTICLE_LINK', $line["link"]);
195
+            $tpl_t->setVariable('ARTICLE_UPDATED', $updated);
196
+            $tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true);
197
+            $tpl_t->setVariable('ARTICLE_EXCERPT',
198
+                truncate_string(strip_tags($line["content"]), 300, "..."), true);
199 199
 
200
-			$tpl_t->addBlock('article');
200
+            $tpl_t->addBlock('article');
201 201
 
202
-			if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) {
203
-				$tpl->addBlock('feed');
204
-				$tpl_t->addBlock('feed');
205
-			}
202
+            if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) {
203
+                $tpl->addBlock('feed');
204
+                $tpl_t->addBlock('feed');
205
+            }
206 206
 
207
-		}
207
+        }
208 208
 
209
-		$tpl->addBlock('digest');
210
-		$tpl->generateOutputToString($tmp);
209
+        $tpl->addBlock('digest');
210
+        $tpl->generateOutputToString($tmp);
211 211
 
212
-		$tpl_t->addBlock('digest');
213
-		$tpl_t->generateOutputToString($tmp_t);
212
+        $tpl_t->addBlock('digest');
213
+        $tpl_t->generateOutputToString($tmp_t);
214 214
 
215
-		return array($tmp, $headlines_count, $affected_ids, $tmp_t);
216
-	}
215
+        return array($tmp, $headlines_count, $affected_ids, $tmp_t);
216
+    }
217 217
 
218 218
 }
Please login to merge, or discard this patch.
classes/db/mysqli.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -1,88 +1,88 @@
 block discarded – undo
1 1
 <?php
2 2
 class Db_Mysqli implements IDb {
3
-	private $link;
4
-	private $last_error;
5
-
6
-	public function connect($host, $user, $pass, $db, $port) {
7
-		if ($port) {
8
-					$this->link = mysqli_connect($host, $user, $pass, $db, $port);
9
-		} else {
10
-					$this->link = mysqli_connect($host, $user, $pass, $db);
11
-		}
12
-
13
-		if ($this->link) {
14
-			$this->init();
15
-
16
-			return $this->link;
17
-		} else {
18
-			print("Unable to connect to database (as $user to $host, database $db): ".mysqli_connect_error());
19
-			exit(102);
20
-		}
21
-	}
22
-
23
-	public function escape_string($s, $strip_tags = true) {
24
-		if ($strip_tags) {
25
-		    $s = strip_tags($s);
26
-		}
27
-
28
-		return mysqli_real_escape_string($this->link, $s);
29
-	}
30
-
31
-	public function query($query, $die_on_error = true) {
32
-		$result = @mysqli_query($this->link, $query);
33
-		if (!$result) {
34
-			$this->last_error = @mysqli_error($this->link);
35
-
36
-			@mysqli_query($this->link, "ROLLBACK");
37
-			user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
38
-				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
39
-		}
40
-
41
-		return $result;
42
-	}
43
-
44
-	public function fetch_assoc($result) {
45
-		return mysqli_fetch_assoc($result);
46
-	}
47
-
48
-
49
-	public function num_rows($result) {
50
-		return mysqli_num_rows($result);
51
-	}
52
-
53
-	public function fetch_result($result, $row, $param) {
54
-		if (mysqli_data_seek($result, $row)) {
55
-			$line = mysqli_fetch_assoc($result);
56
-			return $line[$param];
57
-		} else {
58
-			return false;
59
-		}
60
-	}
61
-
62
-	public function close() {
63
-		return mysqli_close($this->link);
64
-	}
65
-
66
-	public function affected_rows($result) {
67
-		return mysqli_affected_rows($this->link);
68
-	}
69
-
70
-	public function last_error() {
71
-		return mysqli_error($this->link);
72
-	}
73
-
74
-	public function last_query_error() {
75
-		return $this->last_error;
76
-	}
77
-
78
-	public function init() {
79
-		$this->query("SET time_zone = '+0:0'");
80
-
81
-		if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
82
-			mysqli_set_charset($this->link, MYSQL_CHARSET);
83
-		}
84
-
85
-		return true;
86
-	}
3
+    private $link;
4
+    private $last_error;
5
+
6
+    public function connect($host, $user, $pass, $db, $port) {
7
+        if ($port) {
8
+                    $this->link = mysqli_connect($host, $user, $pass, $db, $port);
9
+        } else {
10
+                    $this->link = mysqli_connect($host, $user, $pass, $db);
11
+        }
12
+
13
+        if ($this->link) {
14
+            $this->init();
15
+
16
+            return $this->link;
17
+        } else {
18
+            print("Unable to connect to database (as $user to $host, database $db): ".mysqli_connect_error());
19
+            exit(102);
20
+        }
21
+    }
22
+
23
+    public function escape_string($s, $strip_tags = true) {
24
+        if ($strip_tags) {
25
+            $s = strip_tags($s);
26
+        }
27
+
28
+        return mysqli_real_escape_string($this->link, $s);
29
+    }
30
+
31
+    public function query($query, $die_on_error = true) {
32
+        $result = @mysqli_query($this->link, $query);
33
+        if (!$result) {
34
+            $this->last_error = @mysqli_error($this->link);
35
+
36
+            @mysqli_query($this->link, "ROLLBACK");
37
+            user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
38
+                $die_on_error ? E_USER_ERROR : E_USER_WARNING);
39
+        }
40
+
41
+        return $result;
42
+    }
43
+
44
+    public function fetch_assoc($result) {
45
+        return mysqli_fetch_assoc($result);
46
+    }
47
+
48
+
49
+    public function num_rows($result) {
50
+        return mysqli_num_rows($result);
51
+    }
52
+
53
+    public function fetch_result($result, $row, $param) {
54
+        if (mysqli_data_seek($result, $row)) {
55
+            $line = mysqli_fetch_assoc($result);
56
+            return $line[$param];
57
+        } else {
58
+            return false;
59
+        }
60
+    }
61
+
62
+    public function close() {
63
+        return mysqli_close($this->link);
64
+    }
65
+
66
+    public function affected_rows($result) {
67
+        return mysqli_affected_rows($this->link);
68
+    }
69
+
70
+    public function last_error() {
71
+        return mysqli_error($this->link);
72
+    }
73
+
74
+    public function last_query_error() {
75
+        return $this->last_error;
76
+    }
77
+
78
+    public function init() {
79
+        $this->query("SET time_zone = '+0:0'");
80
+
81
+        if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
82
+            mysqli_set_charset($this->link, MYSQL_CHARSET);
83
+        }
84
+
85
+        return true;
86
+    }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
classes/db/pgsql.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,93 +1,93 @@
 block discarded – undo
1 1
 <?php
2 2
 class Db_Pgsql implements IDb {
3
-	private $link;
4
-	private $last_error;
3
+    private $link;
4
+    private $last_error;
5 5
 
6
-	public function connect($host, $user, $pass, $db, $port) {
7
-		$string = "dbname=$db user=$user";
6
+    public function connect($host, $user, $pass, $db, $port) {
7
+        $string = "dbname=$db user=$user";
8 8
 
9
-		if ($pass) {
10
-			$string .= " password=$pass";
11
-		}
9
+        if ($pass) {
10
+            $string .= " password=$pass";
11
+        }
12 12
 
13
-		if ($host) {
14
-			$string .= " host=$host";
15
-		}
13
+        if ($host) {
14
+            $string .= " host=$host";
15
+        }
16 16
 
17
-		if (is_numeric($port) && $port > 0) {
18
-			$string = "$string port=".$port;
19
-		}
17
+        if (is_numeric($port) && $port > 0) {
18
+            $string = "$string port=".$port;
19
+        }
20 20
 
21
-		$this->link = pg_connect($string);
21
+        $this->link = pg_connect($string);
22 22
 
23
-		if (!$this->link) {
24
-			print("Unable to connect to database (as $user to $host, database $db):".pg_last_error());
25
-			exit(102);
26
-		}
23
+        if (!$this->link) {
24
+            print("Unable to connect to database (as $user to $host, database $db):".pg_last_error());
25
+            exit(102);
26
+        }
27 27
 
28
-		$this->init();
28
+        $this->init();
29 29
 
30
-		return $this->link;
31
-	}
30
+        return $this->link;
31
+    }
32 32
 
33
-	public function escape_string($s, $strip_tags = true) {
34
-		if ($strip_tags) {
35
-		    $s = strip_tags($s);
36
-		}
33
+    public function escape_string($s, $strip_tags = true) {
34
+        if ($strip_tags) {
35
+            $s = strip_tags($s);
36
+        }
37 37
 
38
-		return pg_escape_string($s);
39
-	}
38
+        return pg_escape_string($s);
39
+    }
40 40
 
41
-	public function query($query, $die_on_error = true) {
42
-		$result = @pg_query($this->link, $query);
41
+    public function query($query, $die_on_error = true) {
42
+        $result = @pg_query($this->link, $query);
43 43
 
44
-		if (!$result) {
45
-			$this->last_error = @pg_last_error($this->link);
44
+        if (!$result) {
45
+            $this->last_error = @pg_last_error($this->link);
46 46
 
47
-			@pg_query($this->link, "ROLLBACK");
48
-			$query = htmlspecialchars($query); // just in case
49
-			user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
50
-				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
51
-		}
52
-		return $result;
53
-	}
47
+            @pg_query($this->link, "ROLLBACK");
48
+            $query = htmlspecialchars($query); // just in case
49
+            user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
50
+                $die_on_error ? E_USER_ERROR : E_USER_WARNING);
51
+        }
52
+        return $result;
53
+    }
54 54
 
55
-	public function fetch_assoc($result) {
56
-		return pg_fetch_assoc($result);
57
-	}
55
+    public function fetch_assoc($result) {
56
+        return pg_fetch_assoc($result);
57
+    }
58 58
 
59 59
 
60
-	public function num_rows($result) {
61
-		return pg_num_rows($result);
62
-	}
60
+    public function num_rows($result) {
61
+        return pg_num_rows($result);
62
+    }
63 63
 
64
-	public function fetch_result($result, $row, $param) {
65
-		return pg_fetch_result($result, $row, $param);
66
-	}
64
+    public function fetch_result($result, $row, $param) {
65
+        return pg_fetch_result($result, $row, $param);
66
+    }
67 67
 
68
-	public function close() {
69
-		return pg_close($this->link);
70
-	}
68
+    public function close() {
69
+        return pg_close($this->link);
70
+    }
71 71
 
72
-	public function affected_rows($result) {
73
-		return pg_affected_rows($result);
74
-	}
72
+    public function affected_rows($result) {
73
+        return pg_affected_rows($result);
74
+    }
75 75
 
76
-	public function last_error() {
77
-		return pg_last_error($this->link);
78
-	}
76
+    public function last_error() {
77
+        return pg_last_error($this->link);
78
+    }
79 79
 
80
-	public function last_query_error() {
81
-		return $this->last_error;
82
-	}
80
+    public function last_query_error() {
81
+        return $this->last_error;
82
+    }
83 83
 
84
-	public function init() {
85
-		$this->query("set client_encoding = 'UTF-8'");
86
-		pg_set_client_encoding("UNICODE");
87
-		$this->query("set datestyle = 'ISO, european'");
88
-		$this->query("set TIME ZONE 0");
89
-		$this->query("set cpu_tuple_cost = 0.5");
84
+    public function init() {
85
+        $this->query("set client_encoding = 'UTF-8'");
86
+        pg_set_client_encoding("UNICODE");
87
+        $this->query("set datestyle = 'ISO, european'");
88
+        $this->query("set TIME ZONE 0");
89
+        $this->query("set cpu_tuple_cost = 0.5");
90 90
 
91
-		return true;
92
-	}
91
+        return true;
92
+    }
93 93
 }
Please login to merge, or discard this patch.
classes/db/prefs.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,35 +1,35 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class Db_Prefs {
3
-	private $pdo;
4
-	private static $instance;
5
-	private $cache;
3
+    private $pdo;
4
+    private static $instance;
5
+    private $cache;
6 6
 
7
-	public function __construct() {
8
-		$this->pdo = Db::pdo();
9
-		$this->cache = array();
7
+    public function __construct() {
8
+        $this->pdo = Db::pdo();
9
+        $this->cache = array();
10 10
 
11
-		if ($_SESSION["uid"]) {
12
-		    $this->cache();
13
-		}
14
-	}
11
+        if ($_SESSION["uid"]) {
12
+            $this->cache();
13
+        }
14
+    }
15 15
 
16
-	public static function get() {
17
-		if (self::$instance == null) {
18
-					self::$instance = new self();
19
-		}
16
+    public static function get() {
17
+        if (self::$instance == null) {
18
+                    self::$instance = new self();
19
+        }
20 20
 
21
-		return self::$instance;
22
-	}
21
+        return self::$instance;
22
+    }
23 23
 
24
-	public function cache() {
25
-		$user_id = $_SESSION["uid"];
26
-		@$profile = $_SESSION["profile"];
24
+    public function cache() {
25
+        $user_id = $_SESSION["uid"];
26
+        @$profile = $_SESSION["profile"];
27 27
 
28
-		if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
29
-		    $profile = null;
30
-		}
28
+        if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
29
+            $profile = null;
30
+        }
31 31
 
32
-		$sth = $this->pdo->prepare("SELECT
32
+        $sth = $this->pdo->prepare("SELECT
33 33
 			value,ttrss_prefs_types.type_name as type_name,ttrss_prefs.pref_name AS pref_name
34 34
 			FROM
35 35
 				ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
@@ -40,37 +40,37 @@  discard block
 block discarded – undo
40 40
 				owner_uid = :uid AND
41 41
 				ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
42 42
 
43
-		$sth->execute([":profile" => $profile, ":uid" => $user_id]);
43
+        $sth->execute([":profile" => $profile, ":uid" => $user_id]);
44 44
 
45
-		while ($line = $sth->fetch()) {
46
-			if ($user_id == $_SESSION["uid"]) {
47
-				$pref_name = $line["pref_name"];
45
+        while ($line = $sth->fetch()) {
46
+            if ($user_id == $_SESSION["uid"]) {
47
+                $pref_name = $line["pref_name"];
48 48
 
49
-				$this->cache[$pref_name]["type"] = $line["type_name"];
50
-				$this->cache[$pref_name]["value"] = $line["value"];
51
-			}
52
-		}
53
-	}
49
+                $this->cache[$pref_name]["type"] = $line["type_name"];
50
+                $this->cache[$pref_name]["value"] = $line["value"];
51
+            }
52
+        }
53
+    }
54 54
 
55
-	public function read($pref_name, $user_id = false, $die_on_error = false) {
55
+    public function read($pref_name, $user_id = false, $die_on_error = false) {
56 56
 
57
-		if (!$user_id) {
58
-			$user_id = $_SESSION["uid"];
59
-			@$profile = $_SESSION["profile"];
60
-		} else {
61
-			$profile = false;
62
-		}
57
+        if (!$user_id) {
58
+            $user_id = $_SESSION["uid"];
59
+            @$profile = $_SESSION["profile"];
60
+        } else {
61
+            $profile = false;
62
+        }
63 63
 
64
-		if ($user_id == $_SESSION['uid'] && isset($this->cache[$pref_name])) {
65
-			$tuple = $this->cache[$pref_name];
66
-			return $this->convert($tuple["value"], $tuple["type"]);
67
-		}
64
+        if ($user_id == $_SESSION['uid'] && isset($this->cache[$pref_name])) {
65
+            $tuple = $this->cache[$pref_name];
66
+            return $this->convert($tuple["value"], $tuple["type"]);
67
+        }
68 68
 
69
-		if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
70
-		    $profile = null;
71
-		}
69
+        if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
70
+            $profile = null;
71
+        }
72 72
 
73
-		$sth = $this->pdo->prepare("SELECT
73
+        $sth = $this->pdo->prepare("SELECT
74 74
 			value,ttrss_prefs_types.type_name as type_name
75 75
 			FROM
76 76
 				ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
@@ -80,101 +80,101 @@  discard block
 block discarded – undo
80 80
 				ttrss_prefs_types.id = type_id AND
81 81
 				owner_uid = :uid AND
82 82
 				ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
83
-		$sth->execute([":uid" => $user_id, ":profile" => $profile, ":pref_name" => $pref_name]);
84
-
85
-		if ($row = $sth->fetch()) {
86
-			$value = $row["value"];
87
-			$type_name = $row["type_name"];
88
-
89
-			if ($user_id == $_SESSION["uid"]) {
90
-				$this->cache[$pref_name]["type"] = $type_name;
91
-				$this->cache[$pref_name]["value"] = $value;
92
-			}
93
-
94
-			return $this->convert($value, $type_name);
95
-
96
-		} else if ($die_on_error) {
97
-			user_error("Fatal error, unknown preferences key: $pref_name (owner: $user_id)", E_USER_ERROR);
98
-			return null;
99
-		} else {
100
-			return null;
101
-		}
102
-	}
103
-
104
-	public function convert($value, $type_name) {
105
-		if ($type_name == "bool") {
106
-			return $value == "true";
107
-		} else if ($type_name == "integer") {
108
-			return (int) $value;
109
-		} else {
110
-			return $value;
111
-		}
112
-	}
113
-
114
-	public function write($pref_name, $value, $user_id = false, $strip_tags = true) {
115
-		if ($strip_tags) {
116
-		    $value = strip_tags($value);
117
-		}
118
-
119
-		if (!$user_id) {
120
-			$user_id = $_SESSION["uid"];
121
-			@$profile = $_SESSION["profile"];
122
-		} else {
123
-			$profile = null;
124
-		}
125
-
126
-		if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
127
-		    $profile = null;
128
-		}
129
-
130
-		$type_name = "";
131
-		$current_value = "";
132
-
133
-		if (isset($this->cache[$pref_name])) {
134
-			$type_name = $this->cache[$pref_name]["type"];
135
-			$current_value = $this->cache[$pref_name]["value"];
136
-		}
137
-
138
-		if (!$type_name) {
139
-			$sth = $this->pdo->prepare("SELECT type_name
83
+        $sth->execute([":uid" => $user_id, ":profile" => $profile, ":pref_name" => $pref_name]);
84
+
85
+        if ($row = $sth->fetch()) {
86
+            $value = $row["value"];
87
+            $type_name = $row["type_name"];
88
+
89
+            if ($user_id == $_SESSION["uid"]) {
90
+                $this->cache[$pref_name]["type"] = $type_name;
91
+                $this->cache[$pref_name]["value"] = $value;
92
+            }
93
+
94
+            return $this->convert($value, $type_name);
95
+
96
+        } else if ($die_on_error) {
97
+            user_error("Fatal error, unknown preferences key: $pref_name (owner: $user_id)", E_USER_ERROR);
98
+            return null;
99
+        } else {
100
+            return null;
101
+        }
102
+    }
103
+
104
+    public function convert($value, $type_name) {
105
+        if ($type_name == "bool") {
106
+            return $value == "true";
107
+        } else if ($type_name == "integer") {
108
+            return (int) $value;
109
+        } else {
110
+            return $value;
111
+        }
112
+    }
113
+
114
+    public function write($pref_name, $value, $user_id = false, $strip_tags = true) {
115
+        if ($strip_tags) {
116
+            $value = strip_tags($value);
117
+        }
118
+
119
+        if (!$user_id) {
120
+            $user_id = $_SESSION["uid"];
121
+            @$profile = $_SESSION["profile"];
122
+        } else {
123
+            $profile = null;
124
+        }
125
+
126
+        if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
127
+            $profile = null;
128
+        }
129
+
130
+        $type_name = "";
131
+        $current_value = "";
132
+
133
+        if (isset($this->cache[$pref_name])) {
134
+            $type_name = $this->cache[$pref_name]["type"];
135
+            $current_value = $this->cache[$pref_name]["value"];
136
+        }
137
+
138
+        if (!$type_name) {
139
+            $sth = $this->pdo->prepare("SELECT type_name
140 140
 				FROM ttrss_prefs,ttrss_prefs_types
141 141
 				WHERE pref_name = ? AND type_id = ttrss_prefs_types.id");
142
-			$sth->execute([$pref_name]);
143
-
144
-			if ($row = $sth->fetch()) {
145
-							$type_name = $row["type_name"];
146
-			}
147
-
148
-		} else if ($current_value == $value) {
149
-			return;
150
-		}
151
-
152
-		if ($type_name) {
153
-			if ($type_name == "bool") {
154
-				if ($value == "1" || $value == "true") {
155
-					$value = "true";
156
-				} else {
157
-					$value = "false";
158
-				}
159
-			} else if ($type_name == "integer") {
160
-				$value = (int) $value;
161
-			}
162
-
163
-			if ($pref_name == 'USER_TIMEZONE' && $value == '') {
164
-				$value = 'UTC';
165
-			}
166
-
167
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_prefs SET
142
+            $sth->execute([$pref_name]);
143
+
144
+            if ($row = $sth->fetch()) {
145
+                            $type_name = $row["type_name"];
146
+            }
147
+
148
+        } else if ($current_value == $value) {
149
+            return;
150
+        }
151
+
152
+        if ($type_name) {
153
+            if ($type_name == "bool") {
154
+                if ($value == "1" || $value == "true") {
155
+                    $value = "true";
156
+                } else {
157
+                    $value = "false";
158
+                }
159
+            } else if ($type_name == "integer") {
160
+                $value = (int) $value;
161
+            }
162
+
163
+            if ($pref_name == 'USER_TIMEZONE' && $value == '') {
164
+                $value = 'UTC';
165
+            }
166
+
167
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_prefs SET
168 168
 				value = :value WHERE pref_name = :pref_name
169 169
 					AND (profile = :profile OR (:profile IS NULL AND profile IS NULL))
170 170
 					AND owner_uid = :uid");
171 171
 
172
-			$sth->execute([":pref_name" => $pref_name, ":value" => $value, ":uid" => $user_id, ":profile" => $profile]);
172
+            $sth->execute([":pref_name" => $pref_name, ":value" => $value, ":uid" => $user_id, ":profile" => $profile]);
173 173
 
174
-			if ($user_id == $_SESSION["uid"]) {
175
-				$this->cache[$pref_name]["type"] = $type_name;
176
-				$this->cache[$pref_name]["value"] = $value;
177
-			}
178
-		}
179
-	}
174
+            if ($user_id == $_SESSION["uid"]) {
175
+                $this->cache[$pref_name]["type"] = $type_name;
176
+                $this->cache[$pref_name]["value"] = $value;
177
+            }
178
+        }
179
+    }
180 180
 }
Please login to merge, or discard this patch.
classes/api.php 3 patches
Indentation   +769 added lines, -769 removed lines patch added patch discarded remove patch
@@ -1,148 +1,148 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class API extends Handler {
3 3
 
4
-	const API_LEVEL  = 14;
5
-
6
-	const STATUS_OK  = 0;
7
-	const STATUS_ERR = 1;
8
-
9
-	private $seq;
10
-
11
-	public static function param_to_bool($p) {
12
-		return $p && ($p !== "f" && $p !== "false");
13
-	}
14
-
15
-	public function before($method) {
16
-		if (parent::before($method)) {
17
-			header("Content-Type: text/json");
18
-
19
-			if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
20
-				$this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN'));
21
-				return false;
22
-			}
23
-
24
-			if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) {
25
-				$this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED'));
26
-				return false;
27
-			}
28
-
29
-			$this->seq = (int) clean($_REQUEST['seq']);
30
-
31
-			return true;
32
-		}
33
-		return false;
34
-	}
35
-
36
-	public function wrap($status, $reply) {
37
-		print json_encode(array("seq" => $this->seq,
38
-			"status" => $status,
39
-			"content" => $reply));
40
-	}
41
-
42
-	public function getVersion() {
43
-		$rv = array("version" => VERSION);
44
-		$this->wrap(self::STATUS_OK, $rv);
45
-	}
46
-
47
-	public function getApiLevel() {
48
-		$rv = array("level" => self::API_LEVEL);
49
-		$this->wrap(self::STATUS_OK, $rv);
50
-	}
51
-
52
-	public function login() {
53
-		@session_destroy();
54
-		@session_start();
55
-
56
-		$login = clean($_REQUEST["user"]);
57
-		$password = clean($_REQUEST["password"]);
58
-		$password_base64 = base64_decode(clean($_REQUEST["password"]));
59
-
60
-		if (SINGLE_USER_MODE) {
61
-		    $login = "admin";
62
-		}
63
-
64
-		$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
65
-		$sth->execute([$login]);
66
-
67
-		if ($row = $sth->fetch()) {
68
-			$uid = $row["id"];
69
-		} else {
70
-			$uid = 0;
71
-		}
72
-
73
-		if (!$uid) {
74
-			$this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
75
-			return;
76
-		}
77
-
78
-		if (get_pref("ENABLE_API_ACCESS", $uid)) {
79
-			if (authenticate_user($login, $password, false, Auth_Base::AUTH_SERVICE_API)) {               // try login with normal password
80
-				$this->wrap(self::STATUS_OK, array("session_id" => session_id(),
81
-					"api_level" => self::API_LEVEL));
82
-			} else if (authenticate_user($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password
83
-				$this->wrap(self::STATUS_OK, array("session_id" => session_id(),
84
-					"api_level" => self::API_LEVEL));
85
-			} else {                                                         // else we are not logged in
86
-				user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
87
-				$this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
88
-			}
89
-		} else {
90
-			$this->wrap(self::STATUS_ERR, array("error" => "API_DISABLED"));
91
-		}
92
-
93
-	}
94
-
95
-	public function logout() {
96
-		logout_user();
97
-		$this->wrap(self::STATUS_OK, array("status" => "OK"));
98
-	}
99
-
100
-	public function isLoggedIn() {
101
-		$this->wrap(self::STATUS_OK, array("status" => $_SESSION["uid"] != ''));
102
-	}
103
-
104
-	public function getUnread() {
105
-		$feed_id = clean($_REQUEST["feed_id"]);
106
-		$is_cat = clean($_REQUEST["is_cat"]);
107
-
108
-		if ($feed_id) {
109
-			$this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat)));
110
-		} else {
111
-			$this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread()));
112
-		}
113
-	}
114
-
115
-	/* Method added for ttrss-reader for Android */
116
-	public function getCounters() {
117
-		$this->wrap(self::STATUS_OK, Counters::getAllCounters());
118
-	}
119
-
120
-	public function getFeeds() {
121
-		$cat_id = clean($_REQUEST["cat_id"]);
122
-		$unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
123
-		$limit = (int) clean($_REQUEST["limit"]);
124
-		$offset = (int) clean($_REQUEST["offset"]);
125
-		$include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
126
-
127
-		$feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
128
-
129
-		$this->wrap(self::STATUS_OK, $feeds);
130
-	}
131
-
132
-	public function getCategories() {
133
-		$unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
134
-		$enable_nested = API::param_to_bool(clean($_REQUEST["enable_nested"]));
135
-		$include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
136
-
137
-		// TODO do not return empty categories, return Uncategorized and standard virtual cats
138
-
139
-		if ($enable_nested) {
140
-					$nested_qpart = "parent_cat IS NULL";
141
-		} else {
142
-					$nested_qpart = "true";
143
-		}
144
-
145
-		$sth = $this->pdo->prepare("SELECT
4
+    const API_LEVEL  = 14;
5
+
6
+    const STATUS_OK  = 0;
7
+    const STATUS_ERR = 1;
8
+
9
+    private $seq;
10
+
11
+    public static function param_to_bool($p) {
12
+        return $p && ($p !== "f" && $p !== "false");
13
+    }
14
+
15
+    public function before($method) {
16
+        if (parent::before($method)) {
17
+            header("Content-Type: text/json");
18
+
19
+            if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
20
+                $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN'));
21
+                return false;
22
+            }
23
+
24
+            if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) {
25
+                $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED'));
26
+                return false;
27
+            }
28
+
29
+            $this->seq = (int) clean($_REQUEST['seq']);
30
+
31
+            return true;
32
+        }
33
+        return false;
34
+    }
35
+
36
+    public function wrap($status, $reply) {
37
+        print json_encode(array("seq" => $this->seq,
38
+            "status" => $status,
39
+            "content" => $reply));
40
+    }
41
+
42
+    public function getVersion() {
43
+        $rv = array("version" => VERSION);
44
+        $this->wrap(self::STATUS_OK, $rv);
45
+    }
46
+
47
+    public function getApiLevel() {
48
+        $rv = array("level" => self::API_LEVEL);
49
+        $this->wrap(self::STATUS_OK, $rv);
50
+    }
51
+
52
+    public function login() {
53
+        @session_destroy();
54
+        @session_start();
55
+
56
+        $login = clean($_REQUEST["user"]);
57
+        $password = clean($_REQUEST["password"]);
58
+        $password_base64 = base64_decode(clean($_REQUEST["password"]));
59
+
60
+        if (SINGLE_USER_MODE) {
61
+            $login = "admin";
62
+        }
63
+
64
+        $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
65
+        $sth->execute([$login]);
66
+
67
+        if ($row = $sth->fetch()) {
68
+            $uid = $row["id"];
69
+        } else {
70
+            $uid = 0;
71
+        }
72
+
73
+        if (!$uid) {
74
+            $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
75
+            return;
76
+        }
77
+
78
+        if (get_pref("ENABLE_API_ACCESS", $uid)) {
79
+            if (authenticate_user($login, $password, false, Auth_Base::AUTH_SERVICE_API)) {               // try login with normal password
80
+                $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
81
+                    "api_level" => self::API_LEVEL));
82
+            } else if (authenticate_user($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password
83
+                $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
84
+                    "api_level" => self::API_LEVEL));
85
+            } else {                                                         // else we are not logged in
86
+                user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
87
+                $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
88
+            }
89
+        } else {
90
+            $this->wrap(self::STATUS_ERR, array("error" => "API_DISABLED"));
91
+        }
92
+
93
+    }
94
+
95
+    public function logout() {
96
+        logout_user();
97
+        $this->wrap(self::STATUS_OK, array("status" => "OK"));
98
+    }
99
+
100
+    public function isLoggedIn() {
101
+        $this->wrap(self::STATUS_OK, array("status" => $_SESSION["uid"] != ''));
102
+    }
103
+
104
+    public function getUnread() {
105
+        $feed_id = clean($_REQUEST["feed_id"]);
106
+        $is_cat = clean($_REQUEST["is_cat"]);
107
+
108
+        if ($feed_id) {
109
+            $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat)));
110
+        } else {
111
+            $this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread()));
112
+        }
113
+    }
114
+
115
+    /* Method added for ttrss-reader for Android */
116
+    public function getCounters() {
117
+        $this->wrap(self::STATUS_OK, Counters::getAllCounters());
118
+    }
119
+
120
+    public function getFeeds() {
121
+        $cat_id = clean($_REQUEST["cat_id"]);
122
+        $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
123
+        $limit = (int) clean($_REQUEST["limit"]);
124
+        $offset = (int) clean($_REQUEST["offset"]);
125
+        $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
126
+
127
+        $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
128
+
129
+        $this->wrap(self::STATUS_OK, $feeds);
130
+    }
131
+
132
+    public function getCategories() {
133
+        $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
134
+        $enable_nested = API::param_to_bool(clean($_REQUEST["enable_nested"]));
135
+        $include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
136
+
137
+        // TODO do not return empty categories, return Uncategorized and standard virtual cats
138
+
139
+        if ($enable_nested) {
140
+                    $nested_qpart = "parent_cat IS NULL";
141
+        } else {
142
+                    $nested_qpart = "true";
143
+        }
144
+
145
+        $sth = $this->pdo->prepare("SELECT
146 146
 				id, title, order_id, (SELECT COUNT(id) FROM
147 147
 				ttrss_feeds WHERE
148 148
 				ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds,
@@ -151,191 +151,191 @@  discard block
 block discarded – undo
151 151
 				c2.parent_cat = ttrss_feed_categories.id) AS num_cats
152 152
 			FROM ttrss_feed_categories
153 153
 			WHERE $nested_qpart AND owner_uid = ?");
154
-		$sth->execute([$_SESSION['uid']]);
155
-
156
-		$cats = array();
157
-
158
-		while ($line = $sth->fetch()) {
159
-			if ($include_empty || $line["num_feeds"] > 0 || $line["num_cats"] > 0) {
160
-				$unread = getFeedUnread($line["id"], true);
161
-
162
-				if ($enable_nested) {
163
-									$unread += Feeds::getCategoryChildrenUnread($line["id"]);
164
-				}
165
-
166
-				if ($unread || !$unread_only) {
167
-					array_push($cats, array("id" => $line["id"],
168
-						"title" => $line["title"],
169
-						"unread" => $unread,
170
-						"order_id" => (int) $line["order_id"],
171
-					));
172
-				}
173
-			}
174
-		}
175
-
176
-		foreach (array(-2, -1, 0) as $cat_id) {
177
-			if ($include_empty || !$this->isCategoryEmpty($cat_id)) {
178
-				$unread = getFeedUnread($cat_id, true);
179
-
180
-				if ($unread || !$unread_only) {
181
-					array_push($cats, array("id" => $cat_id,
182
-						"title" => Feeds::getCategoryTitle($cat_id),
183
-						"unread" => $unread));
184
-				}
185
-			}
186
-		}
187
-
188
-		$this->wrap(self::STATUS_OK, $cats);
189
-	}
190
-
191
-	public function getHeadlines() {
192
-		$feed_id = clean($_REQUEST["feed_id"]);
193
-		if ($feed_id !== "") {
194
-
195
-			if (is_numeric($feed_id)) $feed_id = (int) $feed_id;
196
-
197
-			$limit = (int) clean($_REQUEST["limit"]);
198
-
199
-			if (!$limit || $limit >= 200) $limit = 200;
200
-
201
-			$offset = (int) clean($_REQUEST["skip"]);
202
-			$filter = clean($_REQUEST["filter"]);
203
-			$is_cat = API::param_to_bool(clean($_REQUEST["is_cat"]));
204
-			$show_excerpt = API::param_to_bool(clean($_REQUEST["show_excerpt"]));
205
-			$show_content = API::param_to_bool(clean($_REQUEST["show_content"]));
206
-			/* all_articles, unread, adaptive, marked, updated */
207
-			$view_mode = clean($_REQUEST["view_mode"]);
208
-			$include_attachments = API::param_to_bool(clean($_REQUEST["include_attachments"]));
209
-			$since_id = (int) clean($_REQUEST["since_id"]);
210
-			$include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
211
-			$sanitize_content = !isset($_REQUEST["sanitize"]) ||
212
-				API::param_to_bool($_REQUEST["sanitize"]);
213
-			$force_update = API::param_to_bool(clean($_REQUEST["force_update"]));
214
-			$has_sandbox = API::param_to_bool(clean($_REQUEST["has_sandbox"]));
215
-			$excerpt_length = (int) clean($_REQUEST["excerpt_length"]);
216
-			$check_first_id = (int) clean($_REQUEST["check_first_id"]);
217
-			$include_header = API::param_to_bool(clean($_REQUEST["include_header"]));
218
-
219
-			$_SESSION['hasSandbox'] = $has_sandbox;
220
-
221
-			$skip_first_id_check = false;
222
-
223
-			$override_order = false;
224
-			switch (clean($_REQUEST["order_by"])) {
225
-				case "title":
226
-					$override_order = "ttrss_entries.title, date_entered, updated";
227
-					break;
228
-				case "date_reverse":
229
-					$override_order = "score DESC, date_entered, updated";
230
-					$skip_first_id_check = true;
231
-					break;
232
-				case "feed_dates":
233
-					$override_order = "updated DESC";
234
-					break;
235
-			}
236
-
237
-			/* do not rely on params below */
238
-
239
-			$search = clean($_REQUEST["search"]);
240
-
241
-			list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
242
-				$filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,
243
-				$include_attachments, $since_id, $search,
244
-				$include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check);
245
-
246
-			if ($include_header) {
247
-				$this->wrap(self::STATUS_OK, array($headlines_header, $headlines));
248
-			} else {
249
-				$this->wrap(self::STATUS_OK, $headlines);
250
-			}
251
-		} else {
252
-			$this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
253
-		}
254
-	}
255
-
256
-	public function updateArticle() {
257
-		$article_ids = explode(",", clean($_REQUEST["article_ids"]));
258
-		$mode = (int) clean($_REQUEST["mode"]);
259
-		$data = clean($_REQUEST["data"]);
260
-		$field_raw = (int) clean($_REQUEST["field"]);
261
-
262
-		$field = "";
263
-		$set_to = "";
264
-
265
-		switch ($field_raw) {
266
-			case 0:
267
-				$field = "marked";
268
-				$additional_fields = ",last_marked = NOW()";
269
-				break;
270
-			case 1:
271
-				$field = "published";
272
-				$additional_fields = ",last_published = NOW()";
273
-				break;
274
-			case 2:
275
-				$field = "unread";
276
-				$additional_fields = ",last_read = NOW()";
277
-				break;
278
-			case 3:
279
-				$field = "note";
280
-		};
281
-
282
-		switch ($mode) {
283
-			case 1:
284
-				$set_to = "true";
285
-				break;
286
-			case 0:
287
-				$set_to = "false";
288
-				break;
289
-			case 2:
290
-				$set_to = "not $field";
291
-				break;
292
-		}
293
-
294
-		if ($field == "note") {
295
-		    $set_to = $this->pdo->quote($data);
296
-		}
297
-
298
-		if ($field && $set_to && count($article_ids) > 0) {
299
-
300
-			$article_qmarks = arr_qmarks($article_ids);
301
-
302
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
154
+        $sth->execute([$_SESSION['uid']]);
155
+
156
+        $cats = array();
157
+
158
+        while ($line = $sth->fetch()) {
159
+            if ($include_empty || $line["num_feeds"] > 0 || $line["num_cats"] > 0) {
160
+                $unread = getFeedUnread($line["id"], true);
161
+
162
+                if ($enable_nested) {
163
+                                    $unread += Feeds::getCategoryChildrenUnread($line["id"]);
164
+                }
165
+
166
+                if ($unread || !$unread_only) {
167
+                    array_push($cats, array("id" => $line["id"],
168
+                        "title" => $line["title"],
169
+                        "unread" => $unread,
170
+                        "order_id" => (int) $line["order_id"],
171
+                    ));
172
+                }
173
+            }
174
+        }
175
+
176
+        foreach (array(-2, -1, 0) as $cat_id) {
177
+            if ($include_empty || !$this->isCategoryEmpty($cat_id)) {
178
+                $unread = getFeedUnread($cat_id, true);
179
+
180
+                if ($unread || !$unread_only) {
181
+                    array_push($cats, array("id" => $cat_id,
182
+                        "title" => Feeds::getCategoryTitle($cat_id),
183
+                        "unread" => $unread));
184
+                }
185
+            }
186
+        }
187
+
188
+        $this->wrap(self::STATUS_OK, $cats);
189
+    }
190
+
191
+    public function getHeadlines() {
192
+        $feed_id = clean($_REQUEST["feed_id"]);
193
+        if ($feed_id !== "") {
194
+
195
+            if (is_numeric($feed_id)) $feed_id = (int) $feed_id;
196
+
197
+            $limit = (int) clean($_REQUEST["limit"]);
198
+
199
+            if (!$limit || $limit >= 200) $limit = 200;
200
+
201
+            $offset = (int) clean($_REQUEST["skip"]);
202
+            $filter = clean($_REQUEST["filter"]);
203
+            $is_cat = API::param_to_bool(clean($_REQUEST["is_cat"]));
204
+            $show_excerpt = API::param_to_bool(clean($_REQUEST["show_excerpt"]));
205
+            $show_content = API::param_to_bool(clean($_REQUEST["show_content"]));
206
+            /* all_articles, unread, adaptive, marked, updated */
207
+            $view_mode = clean($_REQUEST["view_mode"]);
208
+            $include_attachments = API::param_to_bool(clean($_REQUEST["include_attachments"]));
209
+            $since_id = (int) clean($_REQUEST["since_id"]);
210
+            $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
211
+            $sanitize_content = !isset($_REQUEST["sanitize"]) ||
212
+                API::param_to_bool($_REQUEST["sanitize"]);
213
+            $force_update = API::param_to_bool(clean($_REQUEST["force_update"]));
214
+            $has_sandbox = API::param_to_bool(clean($_REQUEST["has_sandbox"]));
215
+            $excerpt_length = (int) clean($_REQUEST["excerpt_length"]);
216
+            $check_first_id = (int) clean($_REQUEST["check_first_id"]);
217
+            $include_header = API::param_to_bool(clean($_REQUEST["include_header"]));
218
+
219
+            $_SESSION['hasSandbox'] = $has_sandbox;
220
+
221
+            $skip_first_id_check = false;
222
+
223
+            $override_order = false;
224
+            switch (clean($_REQUEST["order_by"])) {
225
+                case "title":
226
+                    $override_order = "ttrss_entries.title, date_entered, updated";
227
+                    break;
228
+                case "date_reverse":
229
+                    $override_order = "score DESC, date_entered, updated";
230
+                    $skip_first_id_check = true;
231
+                    break;
232
+                case "feed_dates":
233
+                    $override_order = "updated DESC";
234
+                    break;
235
+            }
236
+
237
+            /* do not rely on params below */
238
+
239
+            $search = clean($_REQUEST["search"]);
240
+
241
+            list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
242
+                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,
243
+                $include_attachments, $since_id, $search,
244
+                $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check);
245
+
246
+            if ($include_header) {
247
+                $this->wrap(self::STATUS_OK, array($headlines_header, $headlines));
248
+            } else {
249
+                $this->wrap(self::STATUS_OK, $headlines);
250
+            }
251
+        } else {
252
+            $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
253
+        }
254
+    }
255
+
256
+    public function updateArticle() {
257
+        $article_ids = explode(",", clean($_REQUEST["article_ids"]));
258
+        $mode = (int) clean($_REQUEST["mode"]);
259
+        $data = clean($_REQUEST["data"]);
260
+        $field_raw = (int) clean($_REQUEST["field"]);
261
+
262
+        $field = "";
263
+        $set_to = "";
264
+
265
+        switch ($field_raw) {
266
+            case 0:
267
+                $field = "marked";
268
+                $additional_fields = ",last_marked = NOW()";
269
+                break;
270
+            case 1:
271
+                $field = "published";
272
+                $additional_fields = ",last_published = NOW()";
273
+                break;
274
+            case 2:
275
+                $field = "unread";
276
+                $additional_fields = ",last_read = NOW()";
277
+                break;
278
+            case 3:
279
+                $field = "note";
280
+        };
281
+
282
+        switch ($mode) {
283
+            case 1:
284
+                $set_to = "true";
285
+                break;
286
+            case 0:
287
+                $set_to = "false";
288
+                break;
289
+            case 2:
290
+                $set_to = "not $field";
291
+                break;
292
+        }
293
+
294
+        if ($field == "note") {
295
+            $set_to = $this->pdo->quote($data);
296
+        }
297
+
298
+        if ($field && $set_to && count($article_ids) > 0) {
299
+
300
+            $article_qmarks = arr_qmarks($article_ids);
301
+
302
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
303 303
 				$field = $set_to $additional_fields
304 304
 				WHERE ref_id IN ($article_qmarks) AND owner_uid = ?");
305
-			$sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
305
+            $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
306 306
 
307
-			$num_updated = $sth->rowCount();
307
+            $num_updated = $sth->rowCount();
308 308
 
309
-			if ($num_updated > 0 && $field == "unread") {
310
-				$sth = $this->pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries
309
+            if ($num_updated > 0 && $field == "unread") {
310
+                $sth = $this->pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries
311 311
 					WHERE ref_id IN ($article_qmarks)");
312
-				$sth->execute($article_ids);
312
+                $sth->execute($article_ids);
313 313
 
314
-				while ($line = $sth->fetch()) {
315
-					CCache::update($line["feed_id"], $_SESSION["uid"]);
316
-				}
317
-			}
314
+                while ($line = $sth->fetch()) {
315
+                    CCache::update($line["feed_id"], $_SESSION["uid"]);
316
+                }
317
+            }
318 318
 
319
-			$this->wrap(self::STATUS_OK, array("status" => "OK",
320
-				"updated" => $num_updated));
319
+            $this->wrap(self::STATUS_OK, array("status" => "OK",
320
+                "updated" => $num_updated));
321 321
 
322
-		} else {
323
-			$this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
324
-		}
322
+        } else {
323
+            $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
324
+        }
325 325
 
326
-	}
326
+    }
327 327
 
328
-	public function getArticle() {
328
+    public function getArticle() {
329 329
 
330
-		$article_ids = explode(",", clean($_REQUEST["article_id"]));
331
-		$sanitize_content = !isset($_REQUEST["sanitize"]) ||
332
-			API::param_to_bool($_REQUEST["sanitize"]);
330
+        $article_ids = explode(",", clean($_REQUEST["article_id"]));
331
+        $sanitize_content = !isset($_REQUEST["sanitize"]) ||
332
+            API::param_to_bool($_REQUEST["sanitize"]);
333 333
 
334
-		if ($article_ids) {
334
+        if ($article_ids) {
335 335
 
336
-			$article_qmarks = arr_qmarks($article_ids);
336
+            $article_qmarks = arr_qmarks($article_ids);
337 337
 
338
-			$sth = $this->pdo->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id,
338
+            $sth = $this->pdo->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id,
339 339
 				marked,unread,published,score,note,lang,
340 340
 				".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
341 341
 				author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title,
@@ -344,567 +344,567 @@  discard block
 block discarded – undo
344 344
 				FROM ttrss_entries,ttrss_user_entries
345 345
 				WHERE id IN ($article_qmarks) AND ref_id = id AND owner_uid = ?");
346 346
 
347
-			$sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
348
-
349
-			$articles = array();
350
-
351
-			while ($line = $sth->fetch()) {
352
-
353
-				$attachments = Article::get_article_enclosures($line['id']);
354
-
355
-				$article = array(
356
-					"id" => $line["id"],
357
-					"guid" => $line["guid"],
358
-					"title" => $line["title"],
359
-					"link" => $line["link"],
360
-					"labels" => Article::get_article_labels($line['id']),
361
-					"unread" => API::param_to_bool($line["unread"]),
362
-					"marked" => API::param_to_bool($line["marked"]),
363
-					"published" => API::param_to_bool($line["published"]),
364
-					"comments" => $line["comments"],
365
-					"author" => $line["author"],
366
-					"updated" => (int) strtotime($line["updated"]),
367
-					"feed_id" => $line["feed_id"],
368
-					"attachments" => $attachments,
369
-					"score" => (int) $line["score"],
370
-					"feed_title" => $line["feed_title"],
371
-					"note" => $line["note"],
372
-					"lang" => $line["lang"]
373
-				);
374
-
375
-				if ($sanitize_content) {
376
-					$article["content"] = sanitize(
377
-						$line["content"],
378
-						API::param_to_bool($line['hide_images']),
379
-						false, $line["site_url"], false, $line["id"]);
380
-				} else {
381
-					$article["content"] = $line["content"];
382
-				}
383
-
384
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
385
-					$article = $p->hook_render_article_api(array("article" => $article));
386
-				}
387
-
388
-				$article['content'] = DiskCache::rewriteUrls($article['content']);
389
-
390
-				array_push($articles, $article);
391
-
392
-			}
393
-
394
-			$this->wrap(self::STATUS_OK, $articles);
395
-		} else {
396
-			$this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
397
-		}
398
-	}
399
-
400
-	public function getConfig() {
401
-		$config = array(
402
-			"icons_dir" => ICONS_DIR,
403
-			"icons_url" => ICONS_URL);
404
-
405
-		$config["daemon_is_running"] = file_is_locked("update_daemon.lock");
406
-
407
-		$sth = $this->pdo->prepare("SELECT COUNT(*) AS cf FROM
347
+            $sth->execute(array_merge($article_ids, [$_SESSION['uid']]));
348
+
349
+            $articles = array();
350
+
351
+            while ($line = $sth->fetch()) {
352
+
353
+                $attachments = Article::get_article_enclosures($line['id']);
354
+
355
+                $article = array(
356
+                    "id" => $line["id"],
357
+                    "guid" => $line["guid"],
358
+                    "title" => $line["title"],
359
+                    "link" => $line["link"],
360
+                    "labels" => Article::get_article_labels($line['id']),
361
+                    "unread" => API::param_to_bool($line["unread"]),
362
+                    "marked" => API::param_to_bool($line["marked"]),
363
+                    "published" => API::param_to_bool($line["published"]),
364
+                    "comments" => $line["comments"],
365
+                    "author" => $line["author"],
366
+                    "updated" => (int) strtotime($line["updated"]),
367
+                    "feed_id" => $line["feed_id"],
368
+                    "attachments" => $attachments,
369
+                    "score" => (int) $line["score"],
370
+                    "feed_title" => $line["feed_title"],
371
+                    "note" => $line["note"],
372
+                    "lang" => $line["lang"]
373
+                );
374
+
375
+                if ($sanitize_content) {
376
+                    $article["content"] = sanitize(
377
+                        $line["content"],
378
+                        API::param_to_bool($line['hide_images']),
379
+                        false, $line["site_url"], false, $line["id"]);
380
+                } else {
381
+                    $article["content"] = $line["content"];
382
+                }
383
+
384
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
385
+                    $article = $p->hook_render_article_api(array("article" => $article));
386
+                }
387
+
388
+                $article['content'] = DiskCache::rewriteUrls($article['content']);
389
+
390
+                array_push($articles, $article);
391
+
392
+            }
393
+
394
+            $this->wrap(self::STATUS_OK, $articles);
395
+        } else {
396
+            $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
397
+        }
398
+    }
399
+
400
+    public function getConfig() {
401
+        $config = array(
402
+            "icons_dir" => ICONS_DIR,
403
+            "icons_url" => ICONS_URL);
404
+
405
+        $config["daemon_is_running"] = file_is_locked("update_daemon.lock");
406
+
407
+        $sth = $this->pdo->prepare("SELECT COUNT(*) AS cf FROM
408 408
 			ttrss_feeds WHERE owner_uid = ?");
409
-		$sth->execute([$_SESSION['uid']]);
410
-		$row = $sth->fetch();
409
+        $sth->execute([$_SESSION['uid']]);
410
+        $row = $sth->fetch();
411 411
 
412
-		$config["num_feeds"] = $row["cf"];
412
+        $config["num_feeds"] = $row["cf"];
413 413
 
414
-		$this->wrap(self::STATUS_OK, $config);
415
-	}
414
+        $this->wrap(self::STATUS_OK, $config);
415
+    }
416 416
 
417
-	public function updateFeed() {
418
-		$feed_id = (int) clean($_REQUEST["feed_id"]);
417
+    public function updateFeed() {
418
+        $feed_id = (int) clean($_REQUEST["feed_id"]);
419 419
 
420
-		if (!ini_get("open_basedir")) {
421
-			RSSUtils::update_rss_feed($feed_id);
422
-		}
420
+        if (!ini_get("open_basedir")) {
421
+            RSSUtils::update_rss_feed($feed_id);
422
+        }
423 423
 
424
-		$this->wrap(self::STATUS_OK, array("status" => "OK"));
425
-	}
424
+        $this->wrap(self::STATUS_OK, array("status" => "OK"));
425
+    }
426 426
 
427
-	public function catchupFeed() {
428
-		$feed_id = clean($_REQUEST["feed_id"]);
429
-		$is_cat = clean($_REQUEST["is_cat"]);
427
+    public function catchupFeed() {
428
+        $feed_id = clean($_REQUEST["feed_id"]);
429
+        $is_cat = clean($_REQUEST["is_cat"]);
430 430
 
431
-		Feeds::catchup_feed($feed_id, $is_cat);
431
+        Feeds::catchup_feed($feed_id, $is_cat);
432 432
 
433
-		$this->wrap(self::STATUS_OK, array("status" => "OK"));
434
-	}
433
+        $this->wrap(self::STATUS_OK, array("status" => "OK"));
434
+    }
435 435
 
436
-	public function getPref() {
437
-		$pref_name = clean($_REQUEST["pref_name"]);
436
+    public function getPref() {
437
+        $pref_name = clean($_REQUEST["pref_name"]);
438 438
 
439
-		$this->wrap(self::STATUS_OK, array("value" => get_pref($pref_name)));
440
-	}
439
+        $this->wrap(self::STATUS_OK, array("value" => get_pref($pref_name)));
440
+    }
441 441
 
442
-	public function getLabels() {
443
-		$article_id = (int) clean($_REQUEST['article_id']);
442
+    public function getLabels() {
443
+        $article_id = (int) clean($_REQUEST['article_id']);
444 444
 
445
-		$rv = array();
445
+        $rv = array();
446 446
 
447
-		$sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color
447
+        $sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color
448 448
 			FROM ttrss_labels2
449 449
 			WHERE owner_uid = ? ORDER BY caption");
450
-		$sth->execute([$_SESSION['uid']]);
450
+        $sth->execute([$_SESSION['uid']]);
451 451
 
452
-		if ($article_id) {
453
-					$article_labels = Article::get_article_labels($article_id);
454
-		} else {
455
-					$article_labels = array();
456
-		}
452
+        if ($article_id) {
453
+                    $article_labels = Article::get_article_labels($article_id);
454
+        } else {
455
+                    $article_labels = array();
456
+        }
457 457
 
458
-		while ($line = $sth->fetch()) {
458
+        while ($line = $sth->fetch()) {
459 459
 
460
-			$checked = false;
461
-			foreach ($article_labels as $al) {
462
-				if (Labels::feed_to_label_id($al[0]) == $line['id']) {
463
-					$checked = true;
464
-					break;
465
-				}
466
-			}
460
+            $checked = false;
461
+            foreach ($article_labels as $al) {
462
+                if (Labels::feed_to_label_id($al[0]) == $line['id']) {
463
+                    $checked = true;
464
+                    break;
465
+                }
466
+            }
467 467
 
468
-			array_push($rv, array(
469
-				"id" => (int) Labels::label_to_feed_id($line['id']),
470
-				"caption" => $line['caption'],
471
-				"fg_color" => $line['fg_color'],
472
-				"bg_color" => $line['bg_color'],
473
-				"checked" => $checked));
474
-		}
468
+            array_push($rv, array(
469
+                "id" => (int) Labels::label_to_feed_id($line['id']),
470
+                "caption" => $line['caption'],
471
+                "fg_color" => $line['fg_color'],
472
+                "bg_color" => $line['bg_color'],
473
+                "checked" => $checked));
474
+        }
475 475
 
476
-		$this->wrap(self::STATUS_OK, $rv);
477
-	}
476
+        $this->wrap(self::STATUS_OK, $rv);
477
+    }
478 478
 
479
-	public function setArticleLabel() {
479
+    public function setArticleLabel() {
480 480
 
481
-		$article_ids = explode(",", clean($_REQUEST["article_ids"]));
482
-		$label_id = (int) clean($_REQUEST['label_id']);
483
-		$assign = API::param_to_bool(clean($_REQUEST['assign']));
481
+        $article_ids = explode(",", clean($_REQUEST["article_ids"]));
482
+        $label_id = (int) clean($_REQUEST['label_id']);
483
+        $assign = API::param_to_bool(clean($_REQUEST['assign']));
484 484
 
485
-		$label = Labels::find_caption(Labels::feed_to_label_id($label_id), $_SESSION["uid"]);
485
+        $label = Labels::find_caption(Labels::feed_to_label_id($label_id), $_SESSION["uid"]);
486 486
 
487
-		$num_updated = 0;
487
+        $num_updated = 0;
488 488
 
489
-		if ($label) {
489
+        if ($label) {
490 490
 
491
-			foreach ($article_ids as $id) {
491
+            foreach ($article_ids as $id) {
492 492
 
493
-				if ($assign) {
494
-									Labels::add_article($id, $label, $_SESSION["uid"]);
495
-				} else {
496
-									Labels::remove_article($id, $label, $_SESSION["uid"]);
497
-				}
493
+                if ($assign) {
494
+                                    Labels::add_article($id, $label, $_SESSION["uid"]);
495
+                } else {
496
+                                    Labels::remove_article($id, $label, $_SESSION["uid"]);
497
+                }
498 498
 
499
-				++$num_updated;
499
+                ++$num_updated;
500 500
 
501
-			}
502
-		}
501
+            }
502
+        }
503 503
 
504
-		$this->wrap(self::STATUS_OK, array("status" => "OK",
505
-			"updated" => $num_updated));
504
+        $this->wrap(self::STATUS_OK, array("status" => "OK",
505
+            "updated" => $num_updated));
506 506
 
507
-	}
507
+    }
508 508
 
509
-	public function index($method) {
510
-		$plugin = PluginHost::getInstance()->get_api_method(strtolower($method));
509
+    public function index($method) {
510
+        $plugin = PluginHost::getInstance()->get_api_method(strtolower($method));
511 511
 
512
-		if ($plugin && method_exists($plugin, $method)) {
513
-			$reply = $plugin->$method();
512
+        if ($plugin && method_exists($plugin, $method)) {
513
+            $reply = $plugin->$method();
514 514
 
515
-			$this->wrap($reply[0], $reply[1]);
515
+            $this->wrap($reply[0], $reply[1]);
516 516
 
517
-		} else {
518
-			$this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD', "method" => $method));
519
-		}
520
-	}
517
+        } else {
518
+            $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD', "method" => $method));
519
+        }
520
+    }
521 521
 
522
-	public function shareToPublished() {
523
-		$title = strip_tags(clean($_REQUEST["title"]));
524
-		$url = strip_tags(clean($_REQUEST["url"]));
525
-		$content = strip_tags(clean($_REQUEST["content"]));
522
+    public function shareToPublished() {
523
+        $title = strip_tags(clean($_REQUEST["title"]));
524
+        $url = strip_tags(clean($_REQUEST["url"]));
525
+        $content = strip_tags(clean($_REQUEST["content"]));
526 526
 
527
-		if (Article::create_published_article($title, $url, $content, "", $_SESSION["uid"])) {
528
-			$this->wrap(self::STATUS_OK, array("status" => 'OK'));
529
-		} else {
530
-			$this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));
531
-		}
532
-	}
527
+        if (Article::create_published_article($title, $url, $content, "", $_SESSION["uid"])) {
528
+            $this->wrap(self::STATUS_OK, array("status" => 'OK'));
529
+        } else {
530
+            $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));
531
+        }
532
+    }
533 533
 
534
-	public static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) {
534
+    public static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) {
535 535
 
536
-			$feeds = array();
536
+            $feeds = array();
537 537
 
538
-			$pdo = Db::pdo();
538
+            $pdo = Db::pdo();
539 539
 
540
-			$limit = (int) $limit;
541
-			$offset = (int) $offset;
542
-			$cat_id = (int) $cat_id;
540
+            $limit = (int) $limit;
541
+            $offset = (int) $offset;
542
+            $cat_id = (int) $cat_id;
543 543
 
544
-			/* Labels */
544
+            /* Labels */
545 545
 
546
-			/* API only: -4 All feeds, including virtual feeds */
547
-			if ($cat_id == -4 || $cat_id == -2) {
548
-				$counters = Counters::getLabelCounters(true);
546
+            /* API only: -4 All feeds, including virtual feeds */
547
+            if ($cat_id == -4 || $cat_id == -2) {
548
+                $counters = Counters::getLabelCounters(true);
549 549
 
550
-				foreach (array_values($counters) as $cv) {
550
+                foreach (array_values($counters) as $cv) {
551 551
 
552
-					$unread = $cv["counter"];
552
+                    $unread = $cv["counter"];
553 553
 
554
-					if ($unread || !$unread_only) {
554
+                    if ($unread || !$unread_only) {
555 555
 
556
-						$row = array(
557
-								"id" => (int) $cv["id"],
558
-								"title" => $cv["description"],
559
-								"unread" => $cv["counter"],
560
-								"cat_id" => -2,
561
-							);
556
+                        $row = array(
557
+                                "id" => (int) $cv["id"],
558
+                                "title" => $cv["description"],
559
+                                "unread" => $cv["counter"],
560
+                                "cat_id" => -2,
561
+                            );
562 562
 
563
-						array_push($feeds, $row);
564
-					}
565
-				}
566
-			}
563
+                        array_push($feeds, $row);
564
+                    }
565
+                }
566
+            }
567 567
 
568
-			/* Virtual feeds */
568
+            /* Virtual feeds */
569 569
 
570
-			if ($cat_id == -4 || $cat_id == -1) {
571
-				foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
572
-					$unread = getFeedUnread($i);
570
+            if ($cat_id == -4 || $cat_id == -1) {
571
+                foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
572
+                    $unread = getFeedUnread($i);
573 573
 
574
-					if ($unread || !$unread_only) {
575
-						$title = Feeds::getFeedTitle($i);
574
+                    if ($unread || !$unread_only) {
575
+                        $title = Feeds::getFeedTitle($i);
576 576
 
577
-						$row = array(
578
-								"id" => $i,
579
-								"title" => $title,
580
-								"unread" => $unread,
581
-								"cat_id" => -1,
582
-							);
583
-						array_push($feeds, $row);
584
-					}
577
+                        $row = array(
578
+                                "id" => $i,
579
+                                "title" => $title,
580
+                                "unread" => $unread,
581
+                                "cat_id" => -1,
582
+                            );
583
+                        array_push($feeds, $row);
584
+                    }
585 585
 
586
-				}
587
-			}
586
+                }
587
+            }
588 588
 
589
-			/* Child cats */
589
+            /* Child cats */
590 590
 
591
-			if ($include_nested && $cat_id) {
592
-				$sth = $pdo->prepare("SELECT
591
+            if ($include_nested && $cat_id) {
592
+                $sth = $pdo->prepare("SELECT
593 593
 					id, title, order_id FROM ttrss_feed_categories
594 594
 					WHERE parent_cat = ? AND owner_uid = ? ORDER BY order_id, title");
595 595
 
596
-				$sth->execute([$cat_id, $_SESSION['uid']]);
596
+                $sth->execute([$cat_id, $_SESSION['uid']]);
597 597
 
598
-				while ($line = $sth->fetch()) {
599
-					$unread = getFeedUnread($line["id"], true) +
600
-						Feeds::getCategoryChildrenUnread($line["id"]);
598
+                while ($line = $sth->fetch()) {
599
+                    $unread = getFeedUnread($line["id"], true) +
600
+                        Feeds::getCategoryChildrenUnread($line["id"]);
601 601
 
602
-					if ($unread || !$unread_only) {
603
-						$row = array(
604
-								"id" => (int) $line["id"],
605
-								"title" => $line["title"],
606
-								"unread" => $unread,
607
-								"is_cat" => true,
602
+                    if ($unread || !$unread_only) {
603
+                        $row = array(
604
+                                "id" => (int) $line["id"],
605
+                                "title" => $line["title"],
606
+                                "unread" => $unread,
607
+                                "is_cat" => true,
608 608
                                 "order_id" => (int) $line["order_id"]
609
-							);
610
-						array_push($feeds, $row);
611
-					}
612
-				}
613
-			}
614
-
615
-			/* Real feeds */
616
-
617
-			if ($limit) {
618
-				$limit_qpart = "limit $limit OFFSET $offset";
619
-			} else {
620
-				$limit_qpart = "";
621
-			}
622
-
623
-			/* API only: -3 All feeds, excluding virtual feeds (e.g. Labels and such) */
624
-			if ($cat_id == -4 || $cat_id == -3) {
625
-				$sth = $pdo->prepare("SELECT
609
+                            );
610
+                        array_push($feeds, $row);
611
+                    }
612
+                }
613
+            }
614
+
615
+            /* Real feeds */
616
+
617
+            if ($limit) {
618
+                $limit_qpart = "limit $limit OFFSET $offset";
619
+            } else {
620
+                $limit_qpart = "";
621
+            }
622
+
623
+            /* API only: -3 All feeds, excluding virtual feeds (e.g. Labels and such) */
624
+            if ($cat_id == -4 || $cat_id == -3) {
625
+                $sth = $pdo->prepare("SELECT
626 626
 					id, feed_url, cat_id, title, order_id, ".
627
-						SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
627
+                        SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
628 628
 						FROM ttrss_feeds WHERE owner_uid = ?
629 629
 						ORDER BY order_id, title " . $limit_qpart);
630
-				$sth->execute([$_SESSION['uid']]);
630
+                $sth->execute([$_SESSION['uid']]);
631 631
 
632
-			} else {
632
+            } else {
633 633
 
634
-				$sth = $pdo->prepare("SELECT
634
+                $sth = $pdo->prepare("SELECT
635 635
 					id, feed_url, cat_id, title, order_id, ".
636
-						SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
636
+                        SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
637 637
 						FROM ttrss_feeds WHERE
638 638
 						(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))
639 639
 						AND owner_uid = :uid
640 640
 						ORDER BY order_id, title " . $limit_qpart);
641
-				$sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]);
642
-			}
641
+                $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]);
642
+            }
643 643
 
644
-			while ($line = $sth->fetch()) {
644
+            while ($line = $sth->fetch()) {
645 645
 
646
-				$unread = getFeedUnread($line["id"]);
646
+                $unread = getFeedUnread($line["id"]);
647 647
 
648
-				$has_icon = Feeds::feedHasIcon($line['id']);
648
+                $has_icon = Feeds::feedHasIcon($line['id']);
649 649
 
650
-				if ($unread || !$unread_only) {
650
+                if ($unread || !$unread_only) {
651 651
 
652
-					$row = array(
653
-							"feed_url" => $line["feed_url"],
654
-							"title" => $line["title"],
655
-							"id" => (int) $line["id"],
656
-							"unread" => (int) $unread,
657
-							"has_icon" => $has_icon,
658
-							"cat_id" => (int) $line["cat_id"],
659
-							"last_updated" => (int) strtotime($line["last_updated"]),
660
-							"order_id" => (int) $line["order_id"],
661
-						);
652
+                    $row = array(
653
+                            "feed_url" => $line["feed_url"],
654
+                            "title" => $line["title"],
655
+                            "id" => (int) $line["id"],
656
+                            "unread" => (int) $unread,
657
+                            "has_icon" => $has_icon,
658
+                            "cat_id" => (int) $line["cat_id"],
659
+                            "last_updated" => (int) strtotime($line["last_updated"]),
660
+                            "order_id" => (int) $line["order_id"],
661
+                        );
662 662
 
663
-					array_push($feeds, $row);
664
-				}
665
-			}
663
+                    array_push($feeds, $row);
664
+                }
665
+            }
666 666
 
667
-		return $feeds;
668
-	}
667
+        return $feeds;
668
+    }
669 669
 
670
-	/**
671
-	 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
672
-	 */
673
-	public static function api_get_headlines($feed_id, $limit, $offset,
674
-				$filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
675
-				$include_attachments, $since_id,
676
-				$search = "", $include_nested = false, $sanitize_content = true,
677
-				$force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
670
+    /**
671
+     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
672
+     */
673
+    public static function api_get_headlines($feed_id, $limit, $offset,
674
+                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
675
+                $include_attachments, $since_id,
676
+                $search = "", $include_nested = false, $sanitize_content = true,
677
+                $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
678 678
 
679
-			$pdo = Db::pdo();
679
+            $pdo = Db::pdo();
680 680
 
681
-			if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
682
-				// Update the feed if required with some basic flood control
681
+            if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
682
+                // Update the feed if required with some basic flood control
683 683
 
684
-				$sth = $pdo->prepare(
685
-					"SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
684
+                $sth = $pdo->prepare(
685
+                    "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
686 686
 						FROM ttrss_feeds WHERE id = ?");
687
-				$sth->execute([$feed_id]);
687
+                $sth->execute([$feed_id]);
688 688
 
689
-				if ($row = $sth->fetch()) {
690
-					$last_updated = strtotime($row["last_updated"]);
691
-					$cache_images = API::param_to_bool($row["cache_images"]);
689
+                if ($row = $sth->fetch()) {
690
+                    $last_updated = strtotime($row["last_updated"]);
691
+                    $cache_images = API::param_to_bool($row["cache_images"]);
692 692
 
693
-					if (!$cache_images && time() - $last_updated > 120) {
694
-						RSSUtils::update_rss_feed($feed_id, true);
695
-					} else {
696
-						$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
693
+                    if (!$cache_images && time() - $last_updated > 120) {
694
+                        RSSUtils::update_rss_feed($feed_id, true);
695
+                    } else {
696
+                        $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
697 697
 							WHERE id = ?");
698
-						$sth->execute([$feed_id]);
699
-					}
700
-				}
701
-			}
702
-
703
-			$params = array(
704
-				"feed" => $feed_id,
705
-				"limit" => $limit,
706
-				"view_mode" => $view_mode,
707
-				"cat_view" => $is_cat,
708
-				"search" => $search,
709
-				"override_order" => $order,
710
-				"offset" => $offset,
711
-				"since_id" => $since_id,
712
-				"include_children" => $include_nested,
713
-				"check_first_id" => $check_first_id,
714
-				"skip_first_id_check" => $skip_first_id_check
715
-			);
716
-
717
-			$qfh_ret = Feeds::queryFeedHeadlines($params);
718
-
719
-			$result = $qfh_ret[0];
720
-			$feed_title = $qfh_ret[1];
721
-			$first_id = $qfh_ret[6];
722
-
723
-			$headlines = array();
724
-
725
-			$headlines_header = array(
726
-				'id' => $feed_id,
727
-				'first_id' => $first_id,
728
-				'is_cat' => $is_cat);
729
-
730
-			if (!is_numeric($result)) {
731
-				while ($line = $result->fetch()) {
732
-					$line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
733
-					foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
734
-						$line = $p->hook_query_headlines($line, $excerpt_length, true);
735
-					}
736
-
737
-					$is_updated = ($line["last_read"] == "" &&
738
-						($line["unread"] != "t" && $line["unread"] != "1"));
739
-
740
-					$tags = explode(",", $line["tag_cache"]);
741
-
742
-					$label_cache = $line["label_cache"];
743
-					$labels = false;
744
-
745
-					if ($label_cache) {
746
-						$label_cache = json_decode($label_cache, true);
747
-
748
-						if ($label_cache) {
749
-							if ($label_cache["no-labels"] == 1) {
750
-															$labels = array();
751
-							} else {
752
-															$labels = $label_cache;
753
-							}
754
-						}
755
-					}
756
-
757
-					if (!is_array($labels)) {
758
-					    $labels = Article::get_article_labels($line["id"]);
759
-					}
760
-
761
-					$headline_row = array(
762
-						"id" => (int) $line["id"],
763
-						"guid" => $line["guid"],
764
-						"unread" => API::param_to_bool($line["unread"]),
765
-						"marked" => API::param_to_bool($line["marked"]),
766
-						"published" => API::param_to_bool($line["published"]),
767
-						"updated" => (int) strtotime($line["updated"]),
768
-						"is_updated" => $is_updated,
769
-						"title" => $line["title"],
770
-						"link" => $line["link"],
771
-						"feed_id" => $line["feed_id"] ? $line['feed_id'] : 0,
772
-						"tags" => $tags,
773
-					);
774
-
775
-					$enclosures = Article::get_article_enclosures($line['id']);
776
-
777
-					if ($include_attachments) {
778
-											$headline_row['attachments'] = $enclosures;
779
-					}
780
-
781
-					if ($show_excerpt) {
782
-											$headline_row["excerpt"] = $line["content_preview"];
783
-					}
784
-
785
-					if ($show_content) {
786
-
787
-						if ($sanitize_content) {
788
-							$headline_row["content"] = sanitize(
789
-								$line["content"],
790
-								API::param_to_bool($line['hide_images']),
791
-								false, $line["site_url"], false, $line["id"]);
792
-						} else {
793
-							$headline_row["content"] = $line["content"];
794
-						}
795
-					}
796
-
797
-					// unify label output to ease parsing
798
-					if ($labels["no-labels"] == 1) {
799
-					    $labels = array();
800
-					}
801
-
802
-					$headline_row["labels"] = $labels;
803
-
804
-					$headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : $feed_title;
805
-
806
-					$headline_row["comments_count"] = (int) $line["num_comments"];
807
-					$headline_row["comments_link"] = $line["comments"];
808
-
809
-					$headline_row["always_display_attachments"] = API::param_to_bool($line["always_display_enclosures"]);
698
+                        $sth->execute([$feed_id]);
699
+                    }
700
+                }
701
+            }
702
+
703
+            $params = array(
704
+                "feed" => $feed_id,
705
+                "limit" => $limit,
706
+                "view_mode" => $view_mode,
707
+                "cat_view" => $is_cat,
708
+                "search" => $search,
709
+                "override_order" => $order,
710
+                "offset" => $offset,
711
+                "since_id" => $since_id,
712
+                "include_children" => $include_nested,
713
+                "check_first_id" => $check_first_id,
714
+                "skip_first_id_check" => $skip_first_id_check
715
+            );
716
+
717
+            $qfh_ret = Feeds::queryFeedHeadlines($params);
718
+
719
+            $result = $qfh_ret[0];
720
+            $feed_title = $qfh_ret[1];
721
+            $first_id = $qfh_ret[6];
722
+
723
+            $headlines = array();
724
+
725
+            $headlines_header = array(
726
+                'id' => $feed_id,
727
+                'first_id' => $first_id,
728
+                'is_cat' => $is_cat);
729
+
730
+            if (!is_numeric($result)) {
731
+                while ($line = $result->fetch()) {
732
+                    $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
733
+                    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
734
+                        $line = $p->hook_query_headlines($line, $excerpt_length, true);
735
+                    }
736
+
737
+                    $is_updated = ($line["last_read"] == "" &&
738
+                        ($line["unread"] != "t" && $line["unread"] != "1"));
739
+
740
+                    $tags = explode(",", $line["tag_cache"]);
741
+
742
+                    $label_cache = $line["label_cache"];
743
+                    $labels = false;
744
+
745
+                    if ($label_cache) {
746
+                        $label_cache = json_decode($label_cache, true);
747
+
748
+                        if ($label_cache) {
749
+                            if ($label_cache["no-labels"] == 1) {
750
+                                                            $labels = array();
751
+                            } else {
752
+                                                            $labels = $label_cache;
753
+                            }
754
+                        }
755
+                    }
756
+
757
+                    if (!is_array($labels)) {
758
+                        $labels = Article::get_article_labels($line["id"]);
759
+                    }
760
+
761
+                    $headline_row = array(
762
+                        "id" => (int) $line["id"],
763
+                        "guid" => $line["guid"],
764
+                        "unread" => API::param_to_bool($line["unread"]),
765
+                        "marked" => API::param_to_bool($line["marked"]),
766
+                        "published" => API::param_to_bool($line["published"]),
767
+                        "updated" => (int) strtotime($line["updated"]),
768
+                        "is_updated" => $is_updated,
769
+                        "title" => $line["title"],
770
+                        "link" => $line["link"],
771
+                        "feed_id" => $line["feed_id"] ? $line['feed_id'] : 0,
772
+                        "tags" => $tags,
773
+                    );
774
+
775
+                    $enclosures = Article::get_article_enclosures($line['id']);
776
+
777
+                    if ($include_attachments) {
778
+                                            $headline_row['attachments'] = $enclosures;
779
+                    }
780
+
781
+                    if ($show_excerpt) {
782
+                                            $headline_row["excerpt"] = $line["content_preview"];
783
+                    }
784
+
785
+                    if ($show_content) {
786
+
787
+                        if ($sanitize_content) {
788
+                            $headline_row["content"] = sanitize(
789
+                                $line["content"],
790
+                                API::param_to_bool($line['hide_images']),
791
+                                false, $line["site_url"], false, $line["id"]);
792
+                        } else {
793
+                            $headline_row["content"] = $line["content"];
794
+                        }
795
+                    }
796
+
797
+                    // unify label output to ease parsing
798
+                    if ($labels["no-labels"] == 1) {
799
+                        $labels = array();
800
+                    }
801
+
802
+                    $headline_row["labels"] = $labels;
803
+
804
+                    $headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : $feed_title;
805
+
806
+                    $headline_row["comments_count"] = (int) $line["num_comments"];
807
+                    $headline_row["comments_link"] = $line["comments"];
808
+
809
+                    $headline_row["always_display_attachments"] = API::param_to_bool($line["always_display_enclosures"]);
810 810
 
811
-					$headline_row["author"] = $line["author"];
811
+                    $headline_row["author"] = $line["author"];
812 812
 
813
-					$headline_row["score"] = (int) $line["score"];
814
-					$headline_row["note"] = $line["note"];
815
-					$headline_row["lang"] = $line["lang"];
813
+                    $headline_row["score"] = (int) $line["score"];
814
+                    $headline_row["note"] = $line["note"];
815
+                    $headline_row["lang"] = $line["lang"];
816 816
 
817
-					foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
818
-						$headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
819
-					}
817
+                    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
818
+                        $headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
819
+                    }
820 820
 
821
-					$headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']);
821
+                    $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']);
822 822
 
823
-					list ($flavor_image, $flavor_stream) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]);
823
+                    list ($flavor_image, $flavor_stream) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]);
824 824
 
825
-					$headline_row["flavor_image"] = $flavor_image;
826
-					$headline_row["flavor_stream"] = $flavor_stream;
825
+                    $headline_row["flavor_image"] = $flavor_image;
826
+                    $headline_row["flavor_stream"] = $flavor_stream;
827 827
 
828
-					array_push($headlines, $headline_row);
829
-				}
830
-			} else if (is_numeric($result) && $result == -1) {
831
-				$headlines_header['first_id_changed'] = true;
832
-			}
828
+                    array_push($headlines, $headline_row);
829
+                }
830
+            } else if (is_numeric($result) && $result == -1) {
831
+                $headlines_header['first_id_changed'] = true;
832
+            }
833 833
 
834
-			return array($headlines, $headlines_header);
835
-	}
834
+            return array($headlines, $headlines_header);
835
+    }
836 836
 
837
-	public function unsubscribeFeed() {
838
-		$feed_id = (int) clean($_REQUEST["feed_id"]);
837
+    public function unsubscribeFeed() {
838
+        $feed_id = (int) clean($_REQUEST["feed_id"]);
839 839
 
840
-		$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
840
+        $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
841 841
 			id = ? AND owner_uid = ?");
842
-		$sth->execute([$feed_id, $_SESSION['uid']]);
843
-
844
-		if ($sth->fetch()) {
845
-			Pref_Feeds::remove_feed($feed_id, $_SESSION["uid"]);
846
-			$this->wrap(self::STATUS_OK, array("status" => "OK"));
847
-		} else {
848
-			$this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND"));
849
-		}
850
-	}
851
-
852
-	public function subscribeToFeed() {
853
-		$feed_url = clean($_REQUEST["feed_url"]);
854
-		$category_id = (int) clean($_REQUEST["category_id"]);
855
-		$login = clean($_REQUEST["login"]);
856
-		$password = clean($_REQUEST["password"]);
857
-
858
-		if ($feed_url) {
859
-			$rc = Feeds::subscribe_to_feed($feed_url, $category_id, $login, $password);
860
-
861
-			$this->wrap(self::STATUS_OK, array("status" => $rc));
862
-		} else {
863
-			$this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
864
-		}
865
-	}
866
-
867
-	public function getFeedTree() {
868
-		$include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
869
-
870
-		$pf = new Pref_Feeds($_REQUEST);
871
-
872
-		$_REQUEST['mode'] = 2;
873
-		$_REQUEST['force_show_empty'] = $include_empty;
874
-
875
-		if ($pf) {
876
-			$data = $pf->makefeedtree();
877
-			$this->wrap(self::STATUS_OK, array("categories" => $data));
878
-		} else {
879
-			$this->wrap(self::STATUS_ERR, array("error" =>
880
-				'UNABLE_TO_INSTANTIATE_OBJECT'));
881
-		}
882
-
883
-	}
884
-
885
-	// only works for labels or uncategorized for the time being
886
-	private function isCategoryEmpty($id) {
887
-
888
-		if ($id == -2) {
889
-			$sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2
842
+        $sth->execute([$feed_id, $_SESSION['uid']]);
843
+
844
+        if ($sth->fetch()) {
845
+            Pref_Feeds::remove_feed($feed_id, $_SESSION["uid"]);
846
+            $this->wrap(self::STATUS_OK, array("status" => "OK"));
847
+        } else {
848
+            $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND"));
849
+        }
850
+    }
851
+
852
+    public function subscribeToFeed() {
853
+        $feed_url = clean($_REQUEST["feed_url"]);
854
+        $category_id = (int) clean($_REQUEST["category_id"]);
855
+        $login = clean($_REQUEST["login"]);
856
+        $password = clean($_REQUEST["password"]);
857
+
858
+        if ($feed_url) {
859
+            $rc = Feeds::subscribe_to_feed($feed_url, $category_id, $login, $password);
860
+
861
+            $this->wrap(self::STATUS_OK, array("status" => $rc));
862
+        } else {
863
+            $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
864
+        }
865
+    }
866
+
867
+    public function getFeedTree() {
868
+        $include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
869
+
870
+        $pf = new Pref_Feeds($_REQUEST);
871
+
872
+        $_REQUEST['mode'] = 2;
873
+        $_REQUEST['force_show_empty'] = $include_empty;
874
+
875
+        if ($pf) {
876
+            $data = $pf->makefeedtree();
877
+            $this->wrap(self::STATUS_OK, array("categories" => $data));
878
+        } else {
879
+            $this->wrap(self::STATUS_ERR, array("error" =>
880
+                'UNABLE_TO_INSTANTIATE_OBJECT'));
881
+        }
882
+
883
+    }
884
+
885
+    // only works for labels or uncategorized for the time being
886
+    private function isCategoryEmpty($id) {
887
+
888
+        if ($id == -2) {
889
+            $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2
890 890
 				WHERE owner_uid = ?");
891
-			$sth->execute([$_SESSION['uid']]);
892
-			$row = $sth->fetch();
891
+            $sth->execute([$_SESSION['uid']]);
892
+            $row = $sth->fetch();
893 893
 
894
-			return $row["count"] == 0;
894
+            return $row["count"] == 0;
895 895
 
896
-		} else if ($id == 0) {
897
-			$sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds
896
+        } else if ($id == 0) {
897
+            $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds
898 898
 				WHERE cat_id IS NULL AND owner_uid = ?");
899
-			$sth->execute([$_SESSION['uid']]);
900
-			$row = $sth->fetch();
899
+            $sth->execute([$_SESSION['uid']]);
900
+            $row = $sth->fetch();
901 901
 
902
-			return $row["count"] == 0;
902
+            return $row["count"] == 0;
903 903
 
904
-		}
904
+        }
905 905
 
906
-		return false;
907
-	}
906
+        return false;
907
+    }
908 908
 
909 909
 
910 910
 }
Please login to merge, or discard this patch.
Switch Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
 
223 223
 			$override_order = false;
224 224
 			switch (clean($_REQUEST["order_by"])) {
225
-				case "title":
226
-					$override_order = "ttrss_entries.title, date_entered, updated";
227
-					break;
228
-				case "date_reverse":
229
-					$override_order = "score DESC, date_entered, updated";
230
-					$skip_first_id_check = true;
231
-					break;
232
-				case "feed_dates":
233
-					$override_order = "updated DESC";
234
-					break;
225
+			case "title":
226
+				$override_order = "ttrss_entries.title, date_entered, updated";
227
+				break;
228
+			case "date_reverse":
229
+				$override_order = "score DESC, date_entered, updated";
230
+				$skip_first_id_check = true;
231
+				break;
232
+			case "feed_dates":
233
+				$override_order = "updated DESC";
234
+				break;
235 235
 			}
236 236
 
237 237
 			/* do not rely on params below */
@@ -263,32 +263,32 @@  discard block
 block discarded – undo
263 263
 		$set_to = "";
264 264
 
265 265
 		switch ($field_raw) {
266
-			case 0:
267
-				$field = "marked";
268
-				$additional_fields = ",last_marked = NOW()";
269
-				break;
270
-			case 1:
271
-				$field = "published";
272
-				$additional_fields = ",last_published = NOW()";
273
-				break;
274
-			case 2:
275
-				$field = "unread";
276
-				$additional_fields = ",last_read = NOW()";
277
-				break;
278
-			case 3:
279
-				$field = "note";
266
+		case 0:
267
+			$field = "marked";
268
+			$additional_fields = ",last_marked = NOW()";
269
+			break;
270
+		case 1:
271
+			$field = "published";
272
+			$additional_fields = ",last_published = NOW()";
273
+			break;
274
+		case 2:
275
+			$field = "unread";
276
+			$additional_fields = ",last_read = NOW()";
277
+			break;
278
+		case 3:
279
+			$field = "note";
280 280
 		};
281 281
 
282 282
 		switch ($mode) {
283
-			case 1:
284
-				$set_to = "true";
285
-				break;
286
-			case 0:
287
-				$set_to = "false";
288
-				break;
289
-			case 2:
290
-				$set_to = "not $field";
291
-				break;
283
+		case 1:
284
+			$set_to = "true";
285
+			break;
286
+		case 0:
287
+			$set_to = "false";
288
+			break;
289
+		case 2:
290
+			$set_to = "not $field";
291
+			break;
292 292
 		}
293 293
 
294 294
 		if ($field == "note") {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -192,11 +192,15 @@
 block discarded – undo
192 192
 		$feed_id = clean($_REQUEST["feed_id"]);
193 193
 		if ($feed_id !== "") {
194 194
 
195
-			if (is_numeric($feed_id)) $feed_id = (int) $feed_id;
195
+			if (is_numeric($feed_id)) {
196
+			    $feed_id = (int) $feed_id;
197
+			}
196 198
 
197 199
 			$limit = (int) clean($_REQUEST["limit"]);
198 200
 
199
-			if (!$limit || $limit >= 200) $limit = 200;
201
+			if (!$limit || $limit >= 200) {
202
+			    $limit = 200;
203
+			}
200 204
 
201 205
 			$offset = (int) clean($_REQUEST["skip"]);
202 206
 			$filter = clean($_REQUEST["filter"]);
Please login to merge, or discard this patch.
install/index.php 1 patch
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	function stylesheet_tag($filename, $id = false) {
3
-		$timestamp = filemtime($filename);
2
+    function stylesheet_tag($filename, $id = false) {
3
+        $timestamp = filemtime($filename);
4 4
 
5
-		$id_part = $id ? "id=\"$id\"" : "";
5
+        $id_part = $id ? "id=\"$id\"" : "";
6 6
 
7
-		return "<link rel=\"stylesheet\" $id_part type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
8
-	}
7
+        return "<link rel=\"stylesheet\" $id_part type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
8
+    }
9 9
 
10
-	function javascript_tag($filename) {
11
-		$query = "";
10
+    function javascript_tag($filename) {
11
+        $query = "";
12 12
 
13
-		if (!(strpos($filename, "?") === false)) {
14
-			$query = substr($filename, strpos($filename, "?") + 1);
15
-			$filename = substr($filename, 0, strpos($filename, "?"));
16
-		}
13
+        if (!(strpos($filename, "?") === false)) {
14
+            $query = substr($filename, strpos($filename, "?") + 1);
15
+            $filename = substr($filename, 0, strpos($filename, "?"));
16
+        }
17 17
 
18
-		$timestamp = filemtime($filename);
18
+        $timestamp = filemtime($filename);
19 19
 
20
-		if ($query) {
21
-		    $timestamp .= "&$query";
22
-		}
20
+        if ($query) {
21
+            $timestamp .= "&$query";
22
+        }
23 23
 
24
-		return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
25
-	}
24
+        return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
25
+    }
26 26
 ?>
27 27
 <!DOCTYPE html>
28 28
 <html>
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 		textarea { font-size : 12px; }
34 34
 	</style>
35 35
 	<?php
36
-		echo stylesheet_tag("../css/default.css");
37
-		echo javascript_tag("../lib/prototype.js");
38
-		echo javascript_tag("../lib/dojo/dojo.js");
39
-		echo javascript_tag("../lib/dojo/tt-rss-layer.js");
40
-	?>
36
+        echo stylesheet_tag("../css/default.css");
37
+        echo javascript_tag("../lib/prototype.js");
38
+        echo javascript_tag("../lib/dojo/dojo.js");
39
+        echo javascript_tag("../lib/dojo/tt-rss-layer.js");
40
+    ?>
41 41
 </head>
42 42
 <body class="flat ttrss_utility installer">
43 43
 
@@ -52,149 +52,149 @@  discard block
 block discarded – undo
52 52
 
53 53
 <?php
54 54
 
55
-	// could be needed because of existing config.php
56
-	function define_default($param, $value) {
57
-		//
58
-	}
55
+    // could be needed because of existing config.php
56
+    function define_default($param, $value) {
57
+        //
58
+    }
59 59
 
60
-	function make_password($length = 12) {
61
-		$password = "";
62
-		$possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
60
+    function make_password($length = 12) {
61
+        $password = "";
62
+        $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
63 63
 
64
-		$i = 0;
64
+        $i = 0;
65 65
 
66
-		while ($i < $length) {
66
+        while ($i < $length) {
67 67
 
68
-			try {
69
-				$idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
70
-			} catch (Exception $e) {
71
-				$idx = mt_rand(0, strlen($possible) - 1);
72
-			}
68
+            try {
69
+                $idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
70
+            } catch (Exception $e) {
71
+                $idx = mt_rand(0, strlen($possible) - 1);
72
+            }
73 73
 
74
-			$char = substr($possible, $idx, 1);
74
+            $char = substr($possible, $idx, 1);
75 75
 
76
-			if (!strstr($password, $char)) {
77
-				$password .= $char;
78
-				$i++;
79
-			}
80
-		}
76
+            if (!strstr($password, $char)) {
77
+                $password .= $char;
78
+                $i++;
79
+            }
80
+        }
81 81
 
82
-		return $password;
83
-	}
82
+        return $password;
83
+    }
84 84
 
85 85
 
86
-	function sanity_check($db_type) {
87
-		$errors = array();
86
+    function sanity_check($db_type) {
87
+        $errors = array();
88 88
 
89
-		if (version_compare(PHP_VERSION, '5.6.0', '<')) {
90
-			array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION.".");
91
-		}
89
+        if (version_compare(PHP_VERSION, '5.6.0', '<')) {
90
+            array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION.".");
91
+        }
92 92
 
93
-		if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
94
-			array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
95
-		}
93
+        if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
94
+            array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
95
+        }
96 96
 
97
-		if (!function_exists("json_encode")) {
98
-			array_push($errors, "PHP support for JSON is required, but was not found.");
99
-		}
97
+        if (!function_exists("json_encode")) {
98
+            array_push($errors, "PHP support for JSON is required, but was not found.");
99
+        }
100 100
 
101
-		if (!class_exists("PDO")) {
102
-			array_push($errors, "PHP support for PDO is required but was not found.");
103
-		}
101
+        if (!class_exists("PDO")) {
102
+            array_push($errors, "PHP support for PDO is required but was not found.");
103
+        }
104 104
 
105
-		if (!function_exists("mb_strlen")) {
106
-			array_push($errors, "PHP support for mbstring functions is required but was not found.");
107
-		}
105
+        if (!function_exists("mb_strlen")) {
106
+            array_push($errors, "PHP support for mbstring functions is required but was not found.");
107
+        }
108 108
 
109
-		if (!function_exists("hash")) {
110
-			array_push($errors, "PHP support for hash() function is required but was not found.");
111
-		}
109
+        if (!function_exists("hash")) {
110
+            array_push($errors, "PHP support for hash() function is required but was not found.");
111
+        }
112 112
 
113
-		if (!function_exists("iconv")) {
114
-			array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
115
-		}
113
+        if (!function_exists("iconv")) {
114
+            array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
115
+        }
116 116
 
117
-		if (ini_get("safe_mode")) {
118
-			array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
119
-		}
117
+        if (ini_get("safe_mode")) {
118
+            array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
119
+        }
120 120
 
121
-		if (!class_exists("DOMDocument")) {
122
-			array_push($errors, "PHP support for DOMDocument is required, but was not found.");
123
-		}
121
+        if (!class_exists("DOMDocument")) {
122
+            array_push($errors, "PHP support for DOMDocument is required, but was not found.");
123
+        }
124 124
 
125
-		return $errors;
126
-	}
125
+        return $errors;
126
+    }
127 127
 
128
-	function print_error($msg) {
129
-		print "<div class='alert alert-error'>$msg</div>";
130
-	}
128
+    function print_error($msg) {
129
+        print "<div class='alert alert-error'>$msg</div>";
130
+    }
131 131
 
132
-	function print_notice($msg) {
133
-		print "<div class=\"alert alert-info\">$msg</div>";
134
-	}
132
+    function print_notice($msg) {
133
+        print "<div class=\"alert alert-info\">$msg</div>";
134
+    }
135 135
 
136
-	function pdo_connect($host, $user, $pass, $db, $type, $port = false) {
136
+    function pdo_connect($host, $user, $pass, $db, $type, $port = false) {
137 137
 
138
-		$db_port = $port ? ';port='.$port : '';
139
-		$db_host = $host ? ';host='.$host : '';
138
+        $db_port = $port ? ';port='.$port : '';
139
+        $db_host = $host ? ';host='.$host : '';
140 140
 
141
-		try {
142
-			$pdo = new PDO($type.':dbname='.$db.$db_host.$db_port,
143
-				$user,
144
-				$pass);
141
+        try {
142
+            $pdo = new PDO($type.':dbname='.$db.$db_host.$db_port,
143
+                $user,
144
+                $pass);
145 145
 
146
-			return $pdo;
147
-		} catch (Exception $e) {
148
-		    print "<div class='alert alert-danger'>".$e->getMessage()."</div>";
149
-		    return null;
146
+            return $pdo;
147
+        } catch (Exception $e) {
148
+            print "<div class='alert alert-danger'>".$e->getMessage()."</div>";
149
+            return null;
150 150
         }
151
-	}
152
-
153
-	function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
154
-			$DB_PORT, $SELF_URL_PATH) {
155
-
156
-		$data = explode("\n", file_get_contents("../config.php-dist"));
157
-
158
-		$rv = "";
159
-
160
-		$finished = false;
161
-
162
-		foreach ($data as $line) {
163
-			if (preg_match("/define\('DB_TYPE'/", $line)) {
164
-				$rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
165
-			} else if (preg_match("/define\('DB_HOST'/", $line)) {
166
-				$rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
167
-			} else if (preg_match("/define\('DB_USER'/", $line)) {
168
-				$rv .= "\tdefine('DB_USER', '$DB_USER');\n";
169
-			} else if (preg_match("/define\('DB_NAME'/", $line)) {
170
-				$rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
171
-			} else if (preg_match("/define\('DB_PASS'/", $line)) {
172
-				$rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
173
-			} else if (preg_match("/define\('DB_PORT'/", $line)) {
174
-				$rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
175
-			} else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
176
-				$rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
177
-			} else if (!$finished) {
178
-				$rv .= "$line\n";
179
-			}
180
-
181
-			if (preg_match("/\?\>/", $line)) {
182
-				$finished = true;
183
-			}
184
-		}
185
-
186
-		return $rv;
187
-	}
188
-
189
-	function is_server_https() {
190
-		return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
191
-	}
192
-
193
-	function make_self_url_path() {
194
-		$url_path = (is_server_https() ? 'https://' : 'http://').$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
195
-
196
-		return $url_path;
197
-	}
151
+    }
152
+
153
+    function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
154
+            $DB_PORT, $SELF_URL_PATH) {
155
+
156
+        $data = explode("\n", file_get_contents("../config.php-dist"));
157
+
158
+        $rv = "";
159
+
160
+        $finished = false;
161
+
162
+        foreach ($data as $line) {
163
+            if (preg_match("/define\('DB_TYPE'/", $line)) {
164
+                $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
165
+            } else if (preg_match("/define\('DB_HOST'/", $line)) {
166
+                $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
167
+            } else if (preg_match("/define\('DB_USER'/", $line)) {
168
+                $rv .= "\tdefine('DB_USER', '$DB_USER');\n";
169
+            } else if (preg_match("/define\('DB_NAME'/", $line)) {
170
+                $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
171
+            } else if (preg_match("/define\('DB_PASS'/", $line)) {
172
+                $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
173
+            } else if (preg_match("/define\('DB_PORT'/", $line)) {
174
+                $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
175
+            } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
176
+                $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
177
+            } else if (!$finished) {
178
+                $rv .= "$line\n";
179
+            }
180
+
181
+            if (preg_match("/\?\>/", $line)) {
182
+                $finished = true;
183
+            }
184
+        }
185
+
186
+        return $rv;
187
+    }
188
+
189
+    function is_server_https() {
190
+        return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
191
+    }
192
+
193
+    function make_self_url_path() {
194
+        $url_path = (is_server_https() ? 'https://' : 'http://').$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
195
+
196
+        return $url_path;
197
+    }
198 198
 
199 199
 ?>
200 200
 
@@ -204,32 +204,32 @@  discard block
 block discarded – undo
204 204
 
205 205
 <?php
206 206
 
207
-	if (file_exists("../config.php")) {
208
-		require "../config.php";
207
+    if (file_exists("../config.php")) {
208
+        require "../config.php";
209 209
 
210
-		if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
211
-			print_error("Error: config.php already exists in tt-rss directory; aborting.");
210
+        if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
211
+            print_error("Error: config.php already exists in tt-rss directory; aborting.");
212 212
 
213
-			print "<form method='GET' action='../index.php'>
213
+            print "<form method='GET' action='../index.php'>
214 214
 				<button type='submit' dojoType='dijit.form.Button' class='alt-primary'>Return to Tiny Tiny RSS</button>
215 215
 				</form>";
216
-			exit;
217
-		}
218
-	}
219
-
220
-	@$op = $_REQUEST['op'];
221
-
222
-	@$DB_HOST = strip_tags($_POST['DB_HOST']);
223
-	@$DB_TYPE = strip_tags($_POST['DB_TYPE']);
224
-	@$DB_USER = strip_tags($_POST['DB_USER']);
225
-	@$DB_NAME = strip_tags($_POST['DB_NAME']);
226
-	@$DB_PASS = strip_tags($_POST['DB_PASS']);
227
-	@$DB_PORT = strip_tags($_POST['DB_PORT']);
228
-	@$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
229
-
230
-	if (!$SELF_URL_PATH) {
231
-		$SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
232
-	}
216
+            exit;
217
+        }
218
+    }
219
+
220
+    @$op = $_REQUEST['op'];
221
+
222
+    @$DB_HOST = strip_tags($_POST['DB_HOST']);
223
+    @$DB_TYPE = strip_tags($_POST['DB_TYPE']);
224
+    @$DB_USER = strip_tags($_POST['DB_USER']);
225
+    @$DB_NAME = strip_tags($_POST['DB_NAME']);
226
+    @$DB_PASS = strip_tags($_POST['DB_PASS']);
227
+    @$DB_PORT = strip_tags($_POST['DB_PORT']);
228
+    @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
229
+
230
+    if (!$SELF_URL_PATH) {
231
+        $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
232
+    }
233 233
 ?>
234 234
 
235 235
 <form action="" method="post">
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	<h2>Database settings</h2>
239 239
 
240 240
 	<?php
241
-		$issel_pgsql = $DB_TYPE == "pgsql" ? "selected='selected'" : "";
242
-		$issel_mysql = $DB_TYPE == "mysql" ? "selected='selected'" : "";
243
-	?>
241
+        $issel_pgsql = $DB_TYPE == "pgsql" ? "selected='selected'" : "";
242
+        $issel_mysql = $DB_TYPE == "mysql" ? "selected='selected'" : "";
243
+    ?>
244 244
 
245 245
 	<fieldset>
246 246
 		<label>Database type:</label>
@@ -294,87 +294,87 @@  discard block
 block discarded – undo
294 294
 	<h2>Checking configuration</h2>
295 295
 
296 296
 	<?php
297
-		$errors = sanity_check($DB_TYPE);
297
+        $errors = sanity_check($DB_TYPE);
298 298
 
299
-		if (count($errors) > 0) {
300
-			print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
299
+        if (count($errors) > 0) {
300
+            print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
301 301
 
302
-			print "<ul>";
302
+            print "<ul>";
303 303
 
304
-			foreach ($errors as $error) {
305
-				print "<li style='color : red'>$error</li>";
306
-			}
304
+            foreach ($errors as $error) {
305
+                print "<li style='color : red'>$error</li>";
306
+            }
307 307
 
308
-			print "</ul>";
308
+            print "</ul>";
309 309
 
310
-			exit;
311
-		}
310
+            exit;
311
+        }
312 312
 
313
-		$notices = array();
313
+        $notices = array();
314 314
 
315
-		if (!function_exists("curl_init")) {
316
-			array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
317
-		}
315
+        if (!function_exists("curl_init")) {
316
+            array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
317
+        }
318 318
 
319
-		if (function_exists("curl_init") && ini_get("open_basedir")) {
320
-			array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
321
-		}
319
+        if (function_exists("curl_init") && ini_get("open_basedir")) {
320
+            array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
321
+        }
322 322
 
323
-		if (!function_exists("idn_to_ascii")) {
324
-			array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
325
-		}
323
+        if (!function_exists("idn_to_ascii")) {
324
+            array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
325
+        }
326 326
 
327 327
         if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) {
328 328
             array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working.");
329 329
         }
330 330
 
331 331
         if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
332
-			array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working.");
332
+            array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working.");
333 333
         }
334 334
 
335
-		if (count($notices) > 0) {
336
-			print_notice("Configuration check succeeded with minor problems:");
335
+        if (count($notices) > 0) {
336
+            print_notice("Configuration check succeeded with minor problems:");
337 337
 
338
-			print "<ul>";
338
+            print "<ul>";
339 339
 
340
-			foreach ($notices as $notice) {
341
-				print "<li>$notice</li>";
342
-			}
340
+            foreach ($notices as $notice) {
341
+                print "<li>$notice</li>";
342
+            }
343 343
 
344
-			print "</ul>";
345
-		} else {
346
-			print_notice("Configuration check succeeded.");
347
-		}
344
+            print "</ul>";
345
+        } else {
346
+            print_notice("Configuration check succeeded.");
347
+        }
348 348
 
349
-	?>
349
+    ?>
350 350
 
351 351
 	<h2>Checking database</h2>
352 352
 
353 353
 	<?php
354
-		$pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
354
+        $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
355 355
 
356
-		if (!$pdo) {
357
-			print_error("Unable to connect to database using specified parameters (driver: $DB_TYPE).");
358
-			exit;
359
-		}
356
+        if (!$pdo) {
357
+            print_error("Unable to connect to database using specified parameters (driver: $DB_TYPE).");
358
+            exit;
359
+        }
360 360
 
361
-		print_notice("Database test succeeded.");
362
-	?>
361
+        print_notice("Database test succeeded.");
362
+    ?>
363 363
 
364 364
 	<h2>Initialize database</h2>
365 365
 
366 366
 	<p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p>
367 367
 
368 368
 	<?php
369
-		$res = $pdo->query("SELECT true FROM ttrss_feeds");
369
+        $res = $pdo->query("SELECT true FROM ttrss_feeds");
370 370
 
371
-		if ($res && $res->fetch()) {
372
-			print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data <b>WILL BE LOST</b>.");
373
-			$need_confirm = true;
374
-		} else {
375
-			$need_confirm = false;
376
-		}
377
-	?>
371
+        if ($res && $res->fetch()) {
372
+            print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data <b>WILL BE LOST</b>.");
373
+            $need_confirm = true;
374
+        } else {
375
+            $need_confirm = false;
376
+        }
377
+    ?>
378 378
 
379 379
 	<table><tr><td>
380 380
 	<form method="post">
@@ -417,44 +417,44 @@  discard block
 block discarded – undo
417 417
 
418 418
 	<?php
419 419
 
420
-		} else if ($op == 'installschema' || $op == 'skipschema') {
420
+        } else if ($op == 'installschema' || $op == 'skipschema') {
421 421
 
422
-			$pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
422
+            $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
423 423
 
424
-			if (!$pdo) {
425
-				print_error("Unable to connect to database using specified parameters.");
426
-				exit;
427
-			}
424
+            if (!$pdo) {
425
+                print_error("Unable to connect to database using specified parameters.");
426
+                exit;
427
+            }
428 428
 
429
-			if ($op == 'installschema') {
429
+            if ($op == 'installschema') {
430 430
 
431
-				print "<h2>Initializing database...</h2>";
431
+                print "<h2>Initializing database...</h2>";
432 432
 
433
-				$lines = explode(";", preg_replace("/[\r\n]/", "",
433
+                $lines = explode(";", preg_replace("/[\r\n]/", "",
434 434
                     file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql")));
435 435
 
436
-				foreach ($lines as $line) {
437
-					if (strpos($line, "--") !== 0 && $line) {
438
-						$res = $pdo->query($line);
436
+                foreach ($lines as $line) {
437
+                    if (strpos($line, "--") !== 0 && $line) {
438
+                        $res = $pdo->query($line);
439 439
 
440
-						if (!$res) {
441
-							print_notice("Query: $line");
442
-							print_error("Error: ".implode(", ", $pdo->errorInfo()));
440
+                        if (!$res) {
441
+                            print_notice("Query: $line");
442
+                            print_error("Error: ".implode(", ", $pdo->errorInfo()));
443 443
                         }
444
-					}
445
-				}
444
+                    }
445
+                }
446 446
 
447
-				print_notice("Database initialization completed.");
447
+                print_notice("Database initialization completed.");
448 448
 
449
-			} else {
450
-				print_notice("Database initialization skipped.");
451
-			}
449
+            } else {
450
+                print_notice("Database initialization skipped.");
451
+            }
452 452
 
453
-			print "<h2>Generated configuration file</h2>";
453
+            print "<h2>Generated configuration file</h2>";
454 454
 
455
-			print "<p>Copy following text and save as <code>config.php</code> in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.</p>";
455
+            print "<p>Copy following text and save as <code>config.php</code> in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.</p>";
456 456
 
457
-			print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?>
457
+            print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?>
458 458
 
459 459
 			<form action="" method="post">
460 460
 				<input type="hidden" name="op" value="saveconfig">
@@ -466,9 +466,9 @@  discard block
 block discarded – undo
466 466
 				<input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/>
467 467
 				<input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/>
468 468
 			<?php print "<textarea rows='20' style='width : 100%'>";
469
-			echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
470
-				$DB_PORT, $SELF_URL_PATH);
471
-			print "</textarea>"; ?>
469
+            echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
470
+                $DB_PORT, $SELF_URL_PATH);
471
+            print "</textarea>"; ?>
472 472
 
473 473
 			<hr/>
474 474
 
@@ -478,40 +478,40 @@  discard block
 block discarded – undo
478 478
 				<p><button type="submit" dojoType='dijit.form.Button' class='alt-primary'>Save configuration</button></p>
479 479
 				</form>
480 480
 			<?php } else {
481
-				print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
482
-			}
481
+                print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
482
+            }
483 483
 
484
-		   print_notice("You can generate the file again by changing the form above.");
484
+            print_notice("You can generate the file again by changing the form above.");
485 485
 
486
-		} else if ($op == "saveconfig") {
486
+        } else if ($op == "saveconfig") {
487 487
 
488
-			print "<h2>Saving configuration file to parent directory...</h2>";
488
+            print "<h2>Saving configuration file to parent directory...</h2>";
489 489
 
490
-			if (!file_exists("../config.php")) {
490
+            if (!file_exists("../config.php")) {
491 491
 
492
-				$fp = fopen("../config.php", "w");
492
+                $fp = fopen("../config.php", "w");
493 493
 
494
-				if ($fp) {
495
-					$written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
496
-						$DB_USER, $DB_NAME, $DB_PASS,
497
-						$DB_PORT, $SELF_URL_PATH));
494
+                if ($fp) {
495
+                    $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
496
+                        $DB_USER, $DB_NAME, $DB_PASS,
497
+                        $DB_PORT, $SELF_URL_PATH));
498 498
 
499
-					if ($written > 0) {
500
-						print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
499
+                    if ($written > 0) {
500
+                        print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
501 501
 
502
-					} else {
503
-						print_notice("Unable to write into config.php in tt-rss directory.");
504
-					}
502
+                    } else {
503
+                        print_notice("Unable to write into config.php in tt-rss directory.");
504
+                    }
505 505
 
506
-					fclose($fp);
507
-				} else {
508
-					print_error("Unable to open config.php in tt-rss directory for writing.");
509
-				}
510
-			} else {
511
-				print_error("config.php already present in tt-rss directory, refusing to overwrite.");
512
-			}
513
-		}
514
-	?>
506
+                    fclose($fp);
507
+                } else {
508
+                    print_error("Unable to open config.php in tt-rss directory for writing.");
509
+                }
510
+            } else {
511
+                print_error("config.php already present in tt-rss directory, refusing to overwrite.");
512
+            }
513
+        }
514
+    ?>
515 515
 
516 516
 </div>
517 517
 
Please login to merge, or discard this patch.
opml.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,37 +1,37 @@
 block discarded – undo
1 1
 <?php
2
-	set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR.
3
-		get_include_path());
2
+    set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR.
3
+        get_include_path());
4 4
 
5
-	require_once "autoload.php";
6
-	require_once "functions.php";
7
-	require_once "sessions.php";
8
-	require_once "sanity_check.php";
9
-	require_once "config.php";
10
-	require_once "db.php";
11
-	require_once "db-prefs.php";
5
+    require_once "autoload.php";
6
+    require_once "functions.php";
7
+    require_once "sessions.php";
8
+    require_once "sanity_check.php";
9
+    require_once "config.php";
10
+    require_once "db.php";
11
+    require_once "db-prefs.php";
12 12
 
13
-	if (!init_plugins()) {
14
-	    return;
15
-	}
13
+    if (!init_plugins()) {
14
+        return;
15
+    }
16 16
 
17
-	$op = $_REQUEST['op'];
17
+    $op = $_REQUEST['op'];
18 18
 
19
-	if ($op == "publish") {
20
-		$key = $_REQUEST["key"];
21
-		$pdo = Db::pdo();
19
+    if ($op == "publish") {
20
+        $key = $_REQUEST["key"];
21
+        $pdo = Db::pdo();
22 22
 
23
-		$sth = $pdo->prepare("SELECT owner_uid
23
+        $sth = $pdo->prepare("SELECT owner_uid
24 24
 				FROM ttrss_access_keys WHERE
25 25
 				access_key = ? AND feed_id = 'OPML:Publish'");
26
-		$sth->execute([$key]);
26
+        $sth->execute([$key]);
27 27
 
28
-		if ($row = $sth->fetch()) {
29
-			$owner_uid = $row['owner_uid'];
28
+        if ($row = $sth->fetch()) {
29
+            $owner_uid = $row['owner_uid'];
30 30
 
31
-			$opml = new Opml($_REQUEST);
32
-			$opml->opml_export("", $owner_uid, true, false);
31
+            $opml = new Opml($_REQUEST);
32
+            $opml->opml_export("", $owner_uid, true, false);
33 33
 
34
-		} else {
35
-			print "<error>User not found</error>";
36
-		}
37
-	}
34
+        } else {
35
+            print "<error>User not found</error>";
36
+        }
37
+    }
Please login to merge, or discard this patch.
include/colors.php 1 patch
Braces   +19 added lines, -15 removed lines patch added patch discarded remove patch
@@ -262,12 +262,20 @@  discard block
 block discarded – undo
262 262
         $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
263 263
         $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
264 264
 
265
-        if ($var_R == $var_Max) $h = $del_B - $del_G;
266
-        else if ($var_G == $var_Max) $h = (1 / 3) + $del_R - $del_B;
267
-        else if ($var_B == $var_Max) $h = (2 / 3) + $del_G - $del_R;
265
+        if ($var_R == $var_Max) {
266
+            $h = $del_B - $del_G;
267
+        } else if ($var_G == $var_Max) {
268
+            $h = (1 / 3) + $del_R - $del_B;
269
+        } else if ($var_B == $var_Max) {
270
+            $h = (2 / 3) + $del_G - $del_R;
271
+        }
268 272
 
269
-        if ($h < 0) $h++;
270
-        if ($h > 1) $h--;
273
+        if ($h < 0) {
274
+            $h++;
275
+        }
276
+        if ($h > 1) {
277
+            $h--;
278
+        }
271 279
     }
272 280
 
273 281
     return array($h, $s, $v);
@@ -287,12 +295,7 @@  discard block
 block discarded – undo
287 295
         $var_2 = $v * (1 - $s * ($var_H - $var_i));
288 296
         $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i)));
289 297
 
290
-        if ($var_i == 0) { $var_R = $v; $var_G = $var_3; $var_B = $var_1; }
291
-        else if ($var_i == 1) { $var_R = $var_2; $var_G = $v; $var_B = $var_1; }
292
-        else if ($var_i == 2) { $var_R = $var_1; $var_G = $v; $var_B = $var_3; }
293
-        else if ($var_i == 3) { $var_R = $var_1; $var_G = $var_2; $var_B = $v; }
294
-        else if ($var_i == 4) { $var_R = $var_3; $var_G = $var_1; $var_B = $v; }
295
-        else { $var_R = $v; $var_G = $var_1; $var_B = $var_2; }
298
+        if ($var_i == 0) { $var_R = $v; $var_G = $var_3; $var_B = $var_1; } else if ($var_i == 1) { $var_R = $var_2; $var_G = $v; $var_B = $var_1; } else if ($var_i == 2) { $var_R = $var_1; $var_G = $v; $var_B = $var_3; } else if ($var_i == 3) { $var_R = $var_1; $var_G = $var_2; $var_B = $v; } else if ($var_i == 4) { $var_R = $var_3; $var_G = $var_1; $var_B = $v; } else { $var_R = $v; $var_G = $var_1; $var_B = $var_2; }
296 299
 
297 300
         $r = $var_R * 255;
298 301
         $g = $var_G * 255;
@@ -315,10 +318,11 @@  discard block
 block discarded – undo
315 318
             $ico = new floIcon();
316 319
             @$ico->readICO($imageFile);
317 320
 
318
-            if (count($ico->images) == 0)
319
-                return false;
320
-            else
321
-                $img = @$ico->images[count($ico->images) - 1]->getImageResource();
321
+            if (count($ico->images) == 0) {
322
+                            return false;
323
+            } else {
324
+                            $img = @$ico->images[count($ico->images) - 1]->getImageResource();
325
+            }
322 326
 
323 327
         } else {
324 328
             return false;
Please login to merge, or discard this patch.