Passed
Push — master ( a3c0d0...678db7 )
by Cody
06:27 queued 03:12
created
classes/feedenclosure.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 class FeedEnclosure {
3
-	public $link;
4
-	public $type;
5
-	public $length;
6
-	public $title;
7
-	public $height;
8
-	public $width;
3
+    public $link;
4
+    public $type;
5
+    public $length;
6
+    public $title;
7
+    public $height;
8
+    public $width;
9 9
 }
10 10
 
Please login to merge, or discard this patch.
classes/iauthmodule.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1 1
 <?php
2 2
 interface IAuthModule {
3
-	public function authenticate($login, $password); // + optional third parameter: $service
3
+    public function authenticate($login, $password); // + optional third parameter: $service
4 4
 }
Please login to merge, or discard this patch.
classes/pluginhandler.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@
 block discarded – undo
1 1
 <?php
2 2
 class PluginHandler extends Handler_Protected {
3
-	public function csrf_ignore($method) {
4
-		return true;
5
-	}
3
+    public function csrf_ignore($method) {
4
+        return true;
5
+    }
6 6
 
7
-	public function catchall($method) {
8
-		$plugin_name = clean($_REQUEST["plugin"]);
9
-		$plugin = PluginHost::getInstance()->get_plugin($plugin_name);
7
+    public function catchall($method) {
8
+        $plugin_name = clean($_REQUEST["plugin"]);
9
+        $plugin = PluginHost::getInstance()->get_plugin($plugin_name);
10 10
 
11
-		if ($plugin) {
12
-			if (method_exists($plugin, $method)) {
13
-				$plugin->$method();
14
-			} else {
15
-				user_error("PluginHandler: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
16
-				print error_json(13);
17
-			}
18
-		} else {
19
-			user_error("PluginHandler: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
20
-			print error_json(14);
21
-		}
22
-	}
11
+        if ($plugin) {
12
+            if (method_exists($plugin, $method)) {
13
+                $plugin->$method();
14
+            } else {
15
+                user_error("PluginHandler: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
16
+                print error_json(13);
17
+            }
18
+        } else {
19
+            user_error("PluginHandler: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
20
+            print error_json(14);
21
+        }
22
+    }
23 23
 }
Please login to merge, or discard this patch.
classes/db/pgsql.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
 	}
32 32
 
33 33
 	public function escape_string($s, $strip_tags = true) {
34
-		if ($strip_tags) $s = strip_tags($s);
34
+		if ($strip_tags) {
35
+		    $s = strip_tags($s);
36
+		}
35 37
 
36 38
 		return pg_escape_string($s);
37 39
 	}
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,91 +1,91 @@
 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) $s = strip_tags($s);
33
+    public function escape_string($s, $strip_tags = true) {
34
+        if ($strip_tags) $s = strip_tags($s);
35 35
 
36
-		return pg_escape_string($s);
37
-	}
36
+        return pg_escape_string($s);
37
+    }
38 38
 
39
-	public function query($query, $die_on_error = true) {
40
-		$result = @pg_query($this->link, $query);
39
+    public function query($query, $die_on_error = true) {
40
+        $result = @pg_query($this->link, $query);
41 41
 
42
-		if (!$result) {
43
-			$this->last_error = @pg_last_error($this->link);
42
+        if (!$result) {
43
+            $this->last_error = @pg_last_error($this->link);
44 44
 
45
-			@pg_query($this->link, "ROLLBACK");
46
-			$query = htmlspecialchars($query); // just in case
47
-			user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
48
-				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
49
-		}
50
-		return $result;
51
-	}
45
+            @pg_query($this->link, "ROLLBACK");
46
+            $query = htmlspecialchars($query); // just in case
47
+            user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
48
+                $die_on_error ? E_USER_ERROR : E_USER_WARNING);
49
+        }
50
+        return $result;
51
+    }
52 52
 
53
-	public function fetch_assoc($result) {
54
-		return pg_fetch_assoc($result);
55
-	}
53
+    public function fetch_assoc($result) {
54
+        return pg_fetch_assoc($result);
55
+    }
56 56
 
57 57
 
58
-	public function num_rows($result) {
59
-		return pg_num_rows($result);
60
-	}
58
+    public function num_rows($result) {
59
+        return pg_num_rows($result);
60
+    }
61 61
 
62
-	public function fetch_result($result, $row, $param) {
63
-		return pg_fetch_result($result, $row, $param);
64
-	}
62
+    public function fetch_result($result, $row, $param) {
63
+        return pg_fetch_result($result, $row, $param);
64
+    }
65 65
 
66
-	public function close() {
67
-		return pg_close($this->link);
68
-	}
66
+    public function close() {
67
+        return pg_close($this->link);
68
+    }
69 69
 
70
-	public function affected_rows($result) {
71
-		return pg_affected_rows($result);
72
-	}
70
+    public function affected_rows($result) {
71
+        return pg_affected_rows($result);
72
+    }
73 73
 
74
-	public function last_error() {
75
-		return pg_last_error($this->link);
76
-	}
74
+    public function last_error() {
75
+        return pg_last_error($this->link);
76
+    }
77 77
 
78
-	public function last_query_error() {
79
-		return $this->last_error;
80
-	}
78
+    public function last_query_error() {
79
+        return $this->last_error;
80
+    }
81 81
 
82
-	public function init() {
83
-		$this->query("set client_encoding = 'UTF-8'");
84
-		pg_set_client_encoding("UNICODE");
85
-		$this->query("set datestyle = 'ISO, european'");
86
-		$this->query("set TIME ZONE 0");
87
-		$this->query("set cpu_tuple_cost = 0.5");
82
+    public function init() {
83
+        $this->query("set client_encoding = 'UTF-8'");
84
+        pg_set_client_encoding("UNICODE");
85
+        $this->query("set datestyle = 'ISO, european'");
86
+        $this->query("set TIME ZONE 0");
87
+        $this->query("set cpu_tuple_cost = 0.5");
88 88
 
89
-		return true;
90
-	}
89
+        return true;
90
+    }
91 91
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@  discard block
 block discarded – undo
15 15
 		}
16 16
 
17 17
 		if (is_numeric($port) && $port > 0) {
18
-			$string = "$string port=" . $port;
18
+			$string = "$string port=".$port;
19 19
 		}
20 20
 
21 21
 		$this->link = pg_connect($string);
22 22
 
23 23
 		if (!$this->link) {
24
-			print("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
24
+			print("Unable to connect to database (as $user to $host, database $db):".pg_last_error());
25 25
 			exit(102);
26 26
 		}
27 27
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
 			@pg_query($this->link, "ROLLBACK");
46 46
 			$query = htmlspecialchars($query); // just in case
47
-			user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
47
+			user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
48 48
 				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
49 49
 		}
50 50
 		return $result;
Please login to merge, or discard this patch.
classes/db/mysqli.php 3 patches
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,10 +4,11 @@  discard block
 block discarded – undo
4 4
 	private $last_error;
5 5
 
6 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);
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
+		}
11 12
 
12 13
 		if ($this->link) {
13 14
 			$this->init();
@@ -20,7 +21,9 @@  discard block
 block discarded – undo
20 21
 	}
21 22
 
22 23
 	public function escape_string($s, $strip_tags = true) {
23
-		if ($strip_tags) $s = strip_tags($s);
24
+		if ($strip_tags) {
25
+		    $s = strip_tags($s);
26
+		}
24 27
 
25 28
 		return mysqli_real_escape_string($this->link, $s);
26 29
 	}
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,85 +1,85 @@
 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
-		if ($this->link) {
13
-			$this->init();
14
-
15
-			return $this->link;
16
-		} else {
17
-			print("Unable to connect to database (as $user to $host, database $db): " . mysqli_connect_error());
18
-			exit(102);
19
-		}
20
-	}
21
-
22
-	public function escape_string($s, $strip_tags = true) {
23
-		if ($strip_tags) $s = strip_tags($s);
24
-
25
-		return mysqli_real_escape_string($this->link, $s);
26
-	}
27
-
28
-	public function query($query, $die_on_error = true) {
29
-		$result = @mysqli_query($this->link, $query);
30
-		if (!$result) {
31
-			$this->last_error = @mysqli_error($this->link);
32
-
33
-			@mysqli_query($this->link, "ROLLBACK");
34
-			user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
35
-				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
36
-		}
37
-
38
-		return $result;
39
-	}
40
-
41
-	public function fetch_assoc($result) {
42
-		return mysqli_fetch_assoc($result);
43
-	}
44
-
45
-
46
-	public function num_rows($result) {
47
-		return mysqli_num_rows($result);
48
-	}
49
-
50
-	public function fetch_result($result, $row, $param) {
51
-		if (mysqli_data_seek($result, $row)) {
52
-			$line = mysqli_fetch_assoc($result);
53
-			return $line[$param];
54
-		} else {
55
-			return false;
56
-		}
57
-	}
58
-
59
-	public function close() {
60
-		return mysqli_close($this->link);
61
-	}
62
-
63
-	public function affected_rows($result) {
64
-		return mysqli_affected_rows($this->link);
65
-	}
66
-
67
-	public function last_error() {
68
-		return mysqli_error($this->link);
69
-	}
70
-
71
-	public function last_query_error() {
72
-		return $this->last_error;
73
-	}
74
-
75
-	public function init() {
76
-		$this->query("SET time_zone = '+0:0'");
77
-
78
-		if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
79
-			mysqli_set_charset($this->link, MYSQL_CHARSET);
80
-		}
81
-
82
-		return true;
83
-	}
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
+        if ($this->link) {
13
+            $this->init();
14
+
15
+            return $this->link;
16
+        } else {
17
+            print("Unable to connect to database (as $user to $host, database $db): " . mysqli_connect_error());
18
+            exit(102);
19
+        }
20
+    }
21
+
22
+    public function escape_string($s, $strip_tags = true) {
23
+        if ($strip_tags) $s = strip_tags($s);
24
+
25
+        return mysqli_real_escape_string($this->link, $s);
26
+    }
27
+
28
+    public function query($query, $die_on_error = true) {
29
+        $result = @mysqli_query($this->link, $query);
30
+        if (!$result) {
31
+            $this->last_error = @mysqli_error($this->link);
32
+
33
+            @mysqli_query($this->link, "ROLLBACK");
34
+            user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
35
+                $die_on_error ? E_USER_ERROR : E_USER_WARNING);
36
+        }
37
+
38
+        return $result;
39
+    }
40
+
41
+    public function fetch_assoc($result) {
42
+        return mysqli_fetch_assoc($result);
43
+    }
44
+
45
+
46
+    public function num_rows($result) {
47
+        return mysqli_num_rows($result);
48
+    }
49
+
50
+    public function fetch_result($result, $row, $param) {
51
+        if (mysqli_data_seek($result, $row)) {
52
+            $line = mysqli_fetch_assoc($result);
53
+            return $line[$param];
54
+        } else {
55
+            return false;
56
+        }
57
+    }
58
+
59
+    public function close() {
60
+        return mysqli_close($this->link);
61
+    }
62
+
63
+    public function affected_rows($result) {
64
+        return mysqli_affected_rows($this->link);
65
+    }
66
+
67
+    public function last_error() {
68
+        return mysqli_error($this->link);
69
+    }
70
+
71
+    public function last_query_error() {
72
+        return $this->last_error;
73
+    }
74
+
75
+    public function init() {
76
+        $this->query("SET time_zone = '+0:0'");
77
+
78
+        if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
79
+            mysqli_set_charset($this->link, MYSQL_CHARSET);
80
+        }
81
+
82
+        return true;
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 			return $this->link;
16 16
 		} else {
17
-			print("Unable to connect to database (as $user to $host, database $db): " . mysqli_connect_error());
17
+			print("Unable to connect to database (as $user to $host, database $db): ".mysqli_connect_error());
18 18
 			exit(102);
19 19
 		}
20 20
 	}
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 			$this->last_error = @mysqli_error($this->link);
32 32
 
33 33
 			@mysqli_query($this->link, "ROLLBACK");
34
-			user_error("query $query failed: " . ($this->link ? $this->last_error : "No connection"),
34
+			user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"),
35 35
 				$die_on_error ? E_USER_ERROR : E_USER_WARNING);
36 36
 		}
37 37
 
Please login to merge, or discard this patch.
classes/auth/base.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,48 +1,48 @@
 block discarded – undo
1 1
 <?php
2 2
 class Auth_Base {
3
-	private $pdo;
3
+    private $pdo;
4 4
 
5
-	const AUTH_SERVICE_API = '_api';
5
+    const AUTH_SERVICE_API = '_api';
6 6
 
7
-	public function __construct() {
8
-		$this->pdo = Db::pdo();
9
-	}
7
+    public function __construct() {
8
+        $this->pdo = Db::pdo();
9
+    }
10 10
 
11
-	// Auto-creates specified user if allowed by system configuration
12
-	// Can be used instead of find_user_by_login() by external auth modules
13
-	public function auto_create_user($login, $password = false) {
14
-		if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
15
-			$user_id = $this->find_user_by_login($login);
11
+    // Auto-creates specified user if allowed by system configuration
12
+    // Can be used instead of find_user_by_login() by external auth modules
13
+    public function auto_create_user($login, $password = false) {
14
+        if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
15
+            $user_id = $this->find_user_by_login($login);
16 16
 
17
-			if (!$password) $password = make_password();
17
+            if (!$password) $password = make_password();
18 18
 
19
-			if (!$user_id) {
20
-				$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
21
-				$pwd_hash = encrypt_password($password, $salt, true);
19
+            if (!$user_id) {
20
+                $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
21
+                $pwd_hash = encrypt_password($password, $salt, true);
22 22
 
23
-				$sth = $this->pdo->prepare("INSERT INTO ttrss_users
23
+                $sth = $this->pdo->prepare("INSERT INTO ttrss_users
24 24
 						(login,access_level,last_login,created,pwd_hash,salt)
25 25
 						VALUES (?, 0, null, NOW(), ?,?)");
26
-				$sth->execute([$login, $pwd_hash, $salt]);
26
+                $sth->execute([$login, $pwd_hash, $salt]);
27 27
 
28
-				return $this->find_user_by_login($login);
28
+                return $this->find_user_by_login($login);
29 29
 
30
-			} else {
31
-				return $user_id;
32
-			}
33
-		}
30
+            } else {
31
+                return $user_id;
32
+            }
33
+        }
34 34
 
35
-		return $this->find_user_by_login($login);
36
-	}
35
+        return $this->find_user_by_login($login);
36
+    }
37 37
 
38
-	public function find_user_by_login($login) {
39
-		$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
40
-		$sth->execute([$login]);
38
+    public function find_user_by_login($login) {
39
+        $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
40
+        $sth->execute([$login]);
41 41
 
42
-		if ($row = $sth->fetch()) {
43
-			return $row["id"];
44
-		} else {
45
-			return false;
46
-		}
47
-	}
42
+        if ($row = $sth->fetch()) {
43
+            return $row["id"];
44
+        } else {
45
+            return false;
46
+        }
47
+    }
48 48
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@
 block discarded – undo
14 14
 		if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
15 15
 			$user_id = $this->find_user_by_login($login);
16 16
 
17
-			if (!$password) $password = make_password();
17
+			if (!$password) {
18
+			    $password = make_password();
19
+			}
18 20
 
19 21
 			if (!$user_id) {
20 22
 				$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
Please login to merge, or discard this patch.
classes/feeditem/rss.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -1,147 +1,147 @@
 block discarded – undo
1 1
 <?php
2 2
 class FeedItem_RSS extends FeedItem_Common {
3
-	public function get_id() {
4
-		$id = $this->elem->getElementsByTagName("guid")->item(0);
3
+    public function get_id() {
4
+        $id = $this->elem->getElementsByTagName("guid")->item(0);
5 5
 
6
-		if ($id) {
7
-			return clean($id->nodeValue);
8
-		} else {
9
-			return clean($this->get_link());
10
-		}
11
-	}
6
+        if ($id) {
7
+            return clean($id->nodeValue);
8
+        } else {
9
+            return clean($this->get_link());
10
+        }
11
+    }
12 12
 
13
-	public function get_date() {
14
-		$pubDate = $this->elem->getElementsByTagName("pubDate")->item(0);
13
+    public function get_date() {
14
+        $pubDate = $this->elem->getElementsByTagName("pubDate")->item(0);
15 15
 
16
-		if ($pubDate) {
17
-			return strtotime($pubDate->nodeValue);
18
-		}
16
+        if ($pubDate) {
17
+            return strtotime($pubDate->nodeValue);
18
+        }
19 19
 
20
-		$date = $this->xpath->query("dc:date", $this->elem)->item(0);
20
+        $date = $this->xpath->query("dc:date", $this->elem)->item(0);
21 21
 
22
-		if ($date) {
23
-			return strtotime($date->nodeValue);
24
-		}
25
-	}
22
+        if ($date) {
23
+            return strtotime($date->nodeValue);
24
+        }
25
+    }
26 26
 
27
-	public function get_link() {
28
-		$links = $this->xpath->query("atom:link", $this->elem);
27
+    public function get_link() {
28
+        $links = $this->xpath->query("atom:link", $this->elem);
29 29
 
30
-		foreach ($links as $link) {
31
-			if ($link && $link->hasAttribute("href") &&
32
-				(!$link->hasAttribute("rel")
33
-					|| $link->getAttribute("rel") == "alternate"
34
-					|| $link->getAttribute("rel") == "standout")) {
30
+        foreach ($links as $link) {
31
+            if ($link && $link->hasAttribute("href") &&
32
+                (!$link->hasAttribute("rel")
33
+                    || $link->getAttribute("rel") == "alternate"
34
+                    || $link->getAttribute("rel") == "standout")) {
35 35
 
36
-				return clean(trim($link->getAttribute("href")));
37
-			}
38
-		}
36
+                return clean(trim($link->getAttribute("href")));
37
+            }
38
+        }
39 39
 
40
-		$link = $this->elem->getElementsByTagName("guid")->item(0);
40
+        $link = $this->elem->getElementsByTagName("guid")->item(0);
41 41
 
42
-		if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
43
-			return clean(trim($link->nodeValue));
44
-		}
42
+        if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
43
+            return clean(trim($link->nodeValue));
44
+        }
45 45
 
46
-		$link = $this->elem->getElementsByTagName("link")->item(0);
46
+        $link = $this->elem->getElementsByTagName("link")->item(0);
47 47
 
48
-		if ($link) {
49
-			return clean(trim($link->nodeValue));
50
-		}
51
-	}
48
+        if ($link) {
49
+            return clean(trim($link->nodeValue));
50
+        }
51
+    }
52 52
 
53
-	public function get_title() {
54
-		$title = $this->xpath->query("title", $this->elem)->item(0);
53
+    public function get_title() {
54
+        $title = $this->xpath->query("title", $this->elem)->item(0);
55 55
 
56
-		if ($title) {
57
-			return clean(trim($title->nodeValue));
58
-		}
56
+        if ($title) {
57
+            return clean(trim($title->nodeValue));
58
+        }
59 59
 
60
-		// if the document has a default namespace then querying for
61
-		// title would fail because of reasons so let's try the old way
62
-		$title = $this->elem->getElementsByTagName("title")->item(0);
60
+        // if the document has a default namespace then querying for
61
+        // title would fail because of reasons so let's try the old way
62
+        $title = $this->elem->getElementsByTagName("title")->item(0);
63 63
 
64
-		if ($title) {
65
-			return clean(trim($title->nodeValue));
66
-		}
67
-	}
64
+        if ($title) {
65
+            return clean(trim($title->nodeValue));
66
+        }
67
+    }
68 68
 
69
-	public function get_content() {
70
-		$contentA = $this->xpath->query("content:encoded", $this->elem)->item(0);
71
-		$contentB = $this->elem->getElementsByTagName("description")->item(0);
69
+    public function get_content() {
70
+        $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0);
71
+        $contentB = $this->elem->getElementsByTagName("description")->item(0);
72 72
 
73
-		if ($contentA && !$contentB) {
74
-			return $this->subtree_or_text($contentA);
75
-		}
73
+        if ($contentA && !$contentB) {
74
+            return $this->subtree_or_text($contentA);
75
+        }
76 76
 
77 77
 
78
-		if ($contentB && !$contentA) {
79
-			return $this->subtree_or_text($contentB);
80
-		}
78
+        if ($contentB && !$contentA) {
79
+            return $this->subtree_or_text($contentB);
80
+        }
81 81
 
82
-		if ($contentA && $contentB) {
83
-			$resultA = $this->subtree_or_text($contentA);
84
-			$resultB = $this->subtree_or_text($contentB);
82
+        if ($contentA && $contentB) {
83
+            $resultA = $this->subtree_or_text($contentA);
84
+            $resultB = $this->subtree_or_text($contentB);
85 85
 
86
-			return mb_strlen($resultA) > mb_strlen($resultB) ? $resultA : $resultB;
87
-		}
88
-	}
86
+            return mb_strlen($resultA) > mb_strlen($resultB) ? $resultA : $resultB;
87
+        }
88
+    }
89 89
 
90
-	public function get_description() {
91
-		$summary = $this->elem->getElementsByTagName("description")->item(0);
90
+    public function get_description() {
91
+        $summary = $this->elem->getElementsByTagName("description")->item(0);
92 92
 
93
-		if ($summary) {
94
-			return $summary->nodeValue;
95
-		}
96
-	}
93
+        if ($summary) {
94
+            return $summary->nodeValue;
95
+        }
96
+    }
97 97
 
98
-	public function get_categories() {
99
-		$categories = $this->elem->getElementsByTagName("category");
100
-		$cats = [];
98
+    public function get_categories() {
99
+        $categories = $this->elem->getElementsByTagName("category");
100
+        $cats = [];
101 101
 
102
-		foreach ($categories as $cat) {
103
-			array_push($cats, $cat->nodeValue);
104
-		}
102
+        foreach ($categories as $cat) {
103
+            array_push($cats, $cat->nodeValue);
104
+        }
105 105
 
106
-		$categories = $this->xpath->query("dc:subject", $this->elem);
106
+        $categories = $this->xpath->query("dc:subject", $this->elem);
107 107
 
108
-		foreach ($categories as $cat) {
109
-			array_push($cats, $cat->nodeValue);
110
-		}
108
+        foreach ($categories as $cat) {
109
+            array_push($cats, $cat->nodeValue);
110
+        }
111 111
 
112
-		return $this->normalize_categories($cats);
113
-	}
112
+        return $this->normalize_categories($cats);
113
+    }
114 114
 
115
-	public function get_enclosures() {
116
-		$enclosures = $this->elem->getElementsByTagName("enclosure");
115
+    public function get_enclosures() {
116
+        $enclosures = $this->elem->getElementsByTagName("enclosure");
117 117
 
118
-		$encs = array();
118
+        $encs = array();
119 119
 
120
-		foreach ($enclosures as $enclosure) {
121
-			$enc = new FeedEnclosure();
120
+        foreach ($enclosures as $enclosure) {
121
+            $enc = new FeedEnclosure();
122 122
 
123
-			$enc->type = clean($enclosure->getAttribute("type"));
124
-			$enc->link = clean($enclosure->getAttribute("url"));
125
-			$enc->length = clean($enclosure->getAttribute("length"));
126
-			$enc->height = clean($enclosure->getAttribute("height"));
127
-			$enc->width = clean($enclosure->getAttribute("width"));
123
+            $enc->type = clean($enclosure->getAttribute("type"));
124
+            $enc->link = clean($enclosure->getAttribute("url"));
125
+            $enc->length = clean($enclosure->getAttribute("length"));
126
+            $enc->height = clean($enclosure->getAttribute("height"));
127
+            $enc->width = clean($enclosure->getAttribute("width"));
128 128
 
129
-			array_push($encs, $enc);
130
-		}
129
+            array_push($encs, $enc);
130
+        }
131 131
 
132
-		$encs = array_merge($encs, parent::get_enclosures());
132
+        $encs = array_merge($encs, parent::get_enclosures());
133 133
 
134
-		return $encs;
135
-	}
134
+        return $encs;
135
+    }
136 136
 
137
-	public function get_language() {
138
-		$languages = $this->doc->getElementsByTagName('language');
137
+    public function get_language() {
138
+        $languages = $this->doc->getElementsByTagName('language');
139 139
 
140
-		if (count($languages) == 0) {
141
-			return "";
142
-		}
140
+        if (count($languages) == 0) {
141
+            return "";
142
+        }
143 143
 
144
-		return clean($languages[0]->textContent);
145
-	}
144
+        return clean($languages[0]->textContent);
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
classes/idb.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 interface IDb {
3
-	public function connect($host, $user, $pass, $db, $port);
4
-	public function escape_string($s, $strip_tags = true);
5
-	public function query($query, $die_on_error = true);
6
-	public function fetch_assoc($result);
7
-	public function num_rows($result);
8
-	public function fetch_result($result, $row, $param);
9
-	public function close();
10
-	public function affected_rows($result);
11
-	public function last_error();
12
-	public function last_query_error();
3
+    public function connect($host, $user, $pass, $db, $port);
4
+    public function escape_string($s, $strip_tags = true);
5
+    public function query($query, $die_on_error = true);
6
+    public function fetch_assoc($result);
7
+    public function num_rows($result);
8
+    public function fetch_result($result, $row, $param);
9
+    public function close();
10
+    public function affected_rows($result);
11
+    public function last_error();
12
+    public function last_query_error();
13 13
 }
Please login to merge, or discard this patch.
classes/pluginhost.php 3 patches
Braces   +36 added lines, -17 removed lines patch added patch discarded remove patch
@@ -82,8 +82,9 @@  discard block
 block discarded – undo
82 82
 	}
83 83
 
84 84
 	public static function getInstance() {
85
-		if (self::$instance == null)
86
-			self::$instance = new self();
85
+		if (self::$instance == null) {
86
+					self::$instance = new self();
87
+		}
87 88
 
88 89
 		return self::$instance;
89 90
 	}
@@ -191,7 +192,9 @@  discard block
 block discarded – undo
191 192
 			$class_file = strtolower(clean_filename($class));
192 193
 
193 194
 			if (!is_dir(__DIR__."/../plugins/$class_file") &&
194
-					!is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195
+					!is_dir(__DIR__."/../plugins.local/$class_file")) {
196
+			    continue;
197
+			}
195 198
 
196 199
 			// try system plugin directory first
197 200
 			$file = __DIR__ . "/../plugins/$class_file/init.php";
@@ -203,7 +206,9 @@  discard block
 block discarded – undo
203 206
 			}
204 207
 
205 208
 			if (!isset($this->plugins[$class])) {
206
-				if (file_exists($file)) require_once $file;
209
+				if (file_exists($file)) {
210
+				    require_once $file;
211
+				}
207 212
 
208 213
 				if (class_exists($class) && is_subclass_of($class, "Plugin")) {
209 214
 
@@ -219,8 +224,9 @@  discard block
 block discarded – undo
219 224
 								if ($namespace && $class_name) {
220 225
 									$class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
221 226
 
222
-									if (file_exists($class_file))
223
-										require_once $class_file;
227
+									if (file_exists($class_file)) {
228
+																			require_once $class_file;
229
+									}
224 230
 								}
225 231
 							}
226 232
 						});
@@ -245,18 +251,24 @@  discard block
 block discarded – undo
245 251
 					switch ($kind) {
246 252
 					case $this::KIND_SYSTEM:
247 253
 						if ($this->is_system($plugin)) {
248
-							if (!$skip_init) $plugin->init($this);
254
+							if (!$skip_init) {
255
+							    $plugin->init($this);
256
+							}
249 257
 							$this->register_plugin($class, $plugin);
250 258
 						}
251 259
 						break;
252 260
 					case $this::KIND_USER:
253 261
 						if (!$this->is_system($plugin)) {
254
-							if (!$skip_init) $plugin->init($this);
262
+							if (!$skip_init) {
263
+							    $plugin->init($this);
264
+							}
255 265
 							$this->register_plugin($class, $plugin);
256 266
 						}
257 267
 						break;
258 268
 					case $this::KIND_ALL:
259
-						if (!$skip_init) $plugin->init($this);
269
+						if (!$skip_init) {
270
+						    $plugin->init($this);
271
+						}
260 272
 						$this->register_plugin($class, $plugin);
261 273
 						break;
262 274
 					}
@@ -367,8 +379,9 @@  discard block
 block discarded – undo
367 379
 				owner_uid= ? AND name = ?");
368 380
 			$sth->execute([$this->owner_uid, $plugin]);
369 381
 
370
-			if (!isset($this->storage[$plugin]))
371
-				$this->storage[$plugin] = array();
382
+			if (!isset($this->storage[$plugin])) {
383
+							$this->storage[$plugin] = array();
384
+			}
372 385
 
373 386
 			$content = serialize($this->storage[$plugin]);
374 387
 
@@ -391,12 +404,15 @@  discard block
 block discarded – undo
391 404
 	public function set($sender, $name, $value, $sync = true) {
392 405
 		$idx = get_class($sender);
393 406
 
394
-		if (!isset($this->storage[$idx]))
395
-			$this->storage[$idx] = array();
407
+		if (!isset($this->storage[$idx])) {
408
+					$this->storage[$idx] = array();
409
+		}
396 410
 
397 411
 		$this->storage[$idx][$name] = $value;
398 412
 
399
-		if ($sync) $this->save_data(get_class($sender));
413
+		if ($sync) {
414
+		    $this->save_data(get_class($sender));
415
+		}
400 416
 	}
401 417
 
402 418
 	public function get($sender, $name, $default_value = false) {
@@ -433,7 +449,9 @@  discard block
 block discarded – undo
433 449
 
434 450
 	// cat_id: only -1 is supported (Special)
435 451
 	public function add_feed($cat_id, $title, $icon, $sender) {
436
-		if (!$this->feeds[$cat_id]) $this->feeds[$cat_id] = array();
452
+		if (!$this->feeds[$cat_id]) {
453
+		    $this->feeds[$cat_id] = array();
454
+		}
437 455
 
438 456
 		$id = count($this->feeds[$cat_id]);
439 457
 
@@ -479,8 +497,9 @@  discard block
 block discarded – undo
479 497
 	public function add_filter_action($sender, $action_name, $action_desc) {
480 498
 		$sender_class = get_class($sender);
481 499
 
482
-		if (!isset($this->plugin_actions[$sender_class]))
483
-			$this->plugin_actions[$sender_class] = array();
500
+		if (!isset($this->plugin_actions[$sender_class])) {
501
+					$this->plugin_actions[$sender_class] = array();
502
+		}
484 503
 
485 504
 		array_push($this->plugin_actions[$sender_class],
486 505
 			array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
Please login to merge, or discard this patch.
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -1,526 +1,526 @@
 block discarded – undo
1 1
 <?php
2 2
 class PluginHost {
3
-	private $pdo;
4
-	private $hooks = array();
5
-	private $plugins = array();
6
-	private $handlers = array();
7
-	private $commands = array();
8
-	private $storage = array();
9
-	private $feeds = array();
10
-	private $api_methods = array();
11
-	private $plugin_actions = array();
12
-	private $owner_uid;
13
-	private $last_registered;
14
-	private static $instance;
15
-
16
-	const API_VERSION = 2;
17
-
18
-	// Hooks marked with *1 are run in global context and available
19
-	// to plugins loaded in config.php only
20
-
21
-	const HOOK_ARTICLE_BUTTON = 1;
22
-	const HOOK_ARTICLE_FILTER = 2;
23
-	const HOOK_PREFS_TAB = 3;
24
-	const HOOK_PREFS_TAB_SECTION = 4;
25
-	const HOOK_PREFS_TABS = 5;
26
-	const HOOK_FEED_PARSED = 6;
27
-	const HOOK_UPDATE_TASK = 7; // *1
28
-	const HOOK_AUTH_USER = 8;
29
-	const HOOK_HOTKEY_MAP = 9;
30
-	const HOOK_RENDER_ARTICLE = 10;
31
-	const HOOK_RENDER_ARTICLE_CDM = 11;
32
-	const HOOK_FEED_FETCHED = 12;
33
-	const HOOK_SANITIZE = 13;
34
-	const HOOK_RENDER_ARTICLE_API = 14;
35
-	const HOOK_TOOLBAR_BUTTON = 15;
36
-	const HOOK_ACTION_ITEM = 16;
37
-	const HOOK_HEADLINE_TOOLBAR_BUTTON = 17;
38
-	const HOOK_HOTKEY_INFO = 18;
39
-	const HOOK_ARTICLE_LEFT_BUTTON = 19;
40
-	const HOOK_PREFS_EDIT_FEED = 20;
41
-	const HOOK_PREFS_SAVE_FEED = 21;
42
-	const HOOK_FETCH_FEED = 22;
43
-	const HOOK_QUERY_HEADLINES = 23;
44
-	const HOOK_HOUSE_KEEPING = 24; // *1
45
-	const HOOK_SEARCH = 25;
46
-	const HOOK_FORMAT_ENCLOSURES = 26;
47
-	const HOOK_SUBSCRIBE_FEED = 27;
48
-	const HOOK_HEADLINES_BEFORE = 28;
49
-	const HOOK_RENDER_ENCLOSURE = 29;
50
-	const HOOK_ARTICLE_FILTER_ACTION = 30;
51
-	const HOOK_ARTICLE_EXPORT_FEED = 31;
52
-	const HOOK_MAIN_TOOLBAR_BUTTON = 32;
53
-	const HOOK_ENCLOSURE_ENTRY = 33;
54
-	const HOOK_FORMAT_ARTICLE = 34;
55
-	const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */
56
-	const HOOK_FEED_BASIC_INFO = 36;
57
-	const HOOK_SEND_LOCAL_FILE = 37;
58
-	const HOOK_UNSUBSCRIBE_FEED = 38;
59
-	const HOOK_SEND_MAIL = 39;
60
-	const HOOK_FILTER_TRIGGERED = 40;
61
-	const HOOK_GET_FULL_TEXT = 41;
62
-	const HOOK_ARTICLE_IMAGE = 42;
63
-	const HOOK_FEED_TREE = 43;
64
-	const HOOK_IFRAME_WHITELISTED = 44;
65
-
66
-	const KIND_ALL = 1;
67
-	const KIND_SYSTEM = 2;
68
-	const KIND_USER = 3;
69
-
70
-	public static function object_to_domain($plugin) {
71
-		return strtolower(get_class($plugin));
72
-	}
73
-
74
-	public function __construct() {
75
-		$this->pdo = Db::pdo();
76
-
77
-		$this->storage = array();
78
-	}
79
-
80
-	private function __clone() {
81
-		//
82
-	}
83
-
84
-	public static function getInstance() {
85
-		if (self::$instance == null)
86
-			self::$instance = new self();
87
-
88
-		return self::$instance;
89
-	}
90
-
91
-	private function register_plugin($name, $plugin) {
92
-		//array_push($this->plugins, $plugin);
93
-		$this->plugins[$name] = $plugin;
94
-	}
95
-
96
-	// needed for compatibility with API 1
97
-	public function get_link() {
98
-		return false;
99
-	}
100
-
101
-	public function get_dbh() {
102
-		return Db::get();
103
-	}
104
-
105
-	public function get_pdo() {
106
-		return $this->pdo;
107
-	}
108
-
109
-	public function get_plugin_names() {
110
-		$names = array();
111
-
112
-		foreach ($this->plugins as $p) {
113
-			array_push($names, get_class($p));
114
-		}
115
-
116
-		return $names;
117
-	}
118
-
119
-	public function get_plugins() {
120
-		return $this->plugins;
121
-	}
122
-
123
-	public function get_plugin($name) {
124
-		return $this->plugins[strtolower($name)];
125
-	}
126
-
127
-	public function run_hooks($type, $method, $args) {
128
-		foreach ($this->get_hooks($type) as $hook) {
129
-			$hook->$method($args);
130
-		}
131
-	}
132
-
133
-	public function add_hook($type, $sender, $priority = 50) {
134
-		$priority = (int) $priority;
135
-
136
-		if (!is_array($this->hooks[$type])) {
137
-			$this->hooks[$type] = [];
138
-		}
139
-
140
-		if (!is_array($this->hooks[$type][$priority])) {
141
-			$this->hooks[$type][$priority] = [];
142
-		}
143
-
144
-		array_push($this->hooks[$type][$priority], $sender);
145
-		ksort($this->hooks[$type]);
146
-	}
147
-
148
-	public function del_hook($type, $sender) {
149
-		if (is_array($this->hooks[$type])) {
150
-			foreach (array_keys($this->hooks[$type]) as $prio) {
151
-				$key = array_search($sender, $this->hooks[$type][$prio]);
152
-
153
-				if ($key !== false) {
154
-					unset($this->hooks[$type][$prio][$key]);
155
-				}
156
-			}
157
-		}
158
-	}
159
-
160
-	public function get_hooks($type) {
161
-		if (isset($this->hooks[$type])) {
162
-			$tmp = [];
163
-
164
-			foreach (array_keys($this->hooks[$type]) as $prio) {
165
-				$tmp = array_merge($tmp, $this->hooks[$type][$prio]);
166
-			}
167
-
168
-			return $tmp;
169
-		} else {
170
-			return [];
171
-		}
172
-	}
173
-	public function load_all($kind, $owner_uid = false, $skip_init = false) {
174
-
175
-		$plugins = array_merge(glob("plugins/*"), glob("plugins.local/*"));
176
-		$plugins = array_filter($plugins, "is_dir");
177
-		$plugins = array_map("basename", $plugins);
178
-
179
-		asort($plugins);
180
-
181
-		$this->load(join(",", $plugins), $kind, $owner_uid, $skip_init);
182
-	}
183
-
184
-	public function load($classlist, $kind, $owner_uid = false, $skip_init = false) {
185
-		$plugins = explode(",", $classlist);
186
-
187
-		$this->owner_uid = (int) $owner_uid;
188
-
189
-		foreach ($plugins as $class) {
190
-			$class = trim($class);
191
-			$class_file = strtolower(clean_filename($class));
192
-
193
-			if (!is_dir(__DIR__."/../plugins/$class_file") &&
194
-					!is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195
-
196
-			// try system plugin directory first
197
-			$file = __DIR__ . "/../plugins/$class_file/init.php";
198
-			$vendor_dir = __DIR__ . "/../plugins/$class_file/vendor";
199
-
200
-			if (!file_exists($file)) {
201
-				$file = __DIR__ . "/../plugins.local/$class_file/init.php";
202
-				$vendor_dir = __DIR__ . "/../plugins.local/$class_file/vendor";
203
-			}
204
-
205
-			if (!isset($this->plugins[$class])) {
206
-				if (file_exists($file)) require_once $file;
207
-
208
-				if (class_exists($class) && is_subclass_of($class, "Plugin")) {
209
-
210
-					// register plugin autoloader if necessary, for namespaced classes ONLY
211
-					// layout corresponds to tt-rss main /vendor/author/Package/Class.php
212
-
213
-					if (file_exists($vendor_dir)) {
214
-						spl_autoload_register(function($class) use ($vendor_dir) {
215
-
216
-							if (strpos($class, '\\') !== false) {
217
-								list ($namespace, $class_name) = explode('\\', $class, 2);
218
-
219
-								if ($namespace && $class_name) {
220
-									$class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
221
-
222
-									if (file_exists($class_file))
223
-										require_once $class_file;
224
-								}
225
-							}
226
-						});
227
-					}
228
-
229
-					$plugin = new $class($this);
230
-
231
-					$plugin_api = $plugin->api_version();
232
-
233
-					if ($plugin_api < PluginHost::API_VERSION) {
234
-						user_error("plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING);
235
-						continue;
236
-					}
237
-
238
-					if (file_exists(dirname($file) . "/locale")) {
239
-						_bindtextdomain($class, dirname($file) . "/locale");
240
-						_bind_textdomain_codeset($class, "UTF-8");
241
-					}
242
-
243
-					$this->last_registered = $class;
244
-
245
-					switch ($kind) {
246
-					case $this::KIND_SYSTEM:
247
-						if ($this->is_system($plugin)) {
248
-							if (!$skip_init) $plugin->init($this);
249
-							$this->register_plugin($class, $plugin);
250
-						}
251
-						break;
252
-					case $this::KIND_USER:
253
-						if (!$this->is_system($plugin)) {
254
-							if (!$skip_init) $plugin->init($this);
255
-							$this->register_plugin($class, $plugin);
256
-						}
257
-						break;
258
-					case $this::KIND_ALL:
259
-						if (!$skip_init) $plugin->init($this);
260
-						$this->register_plugin($class, $plugin);
261
-						break;
262
-					}
263
-				}
264
-			}
265
-		}
266
-	}
267
-
268
-	public function is_system($plugin) {
269
-		$about = $plugin->about();
270
-
271
-		return @$about[3];
272
-	}
273
-
274
-	// only system plugins are allowed to modify routing
275
-	public function add_handler($handler, $method, $sender) {
276
-		$handler = str_replace("-", "_", strtolower($handler));
277
-		$method = strtolower($method);
278
-
279
-		if ($this->is_system($sender)) {
280
-			if (!is_array($this->handlers[$handler])) {
281
-				$this->handlers[$handler] = array();
282
-			}
283
-
284
-			$this->handlers[$handler][$method] = $sender;
285
-		}
286
-	}
287
-
288
-	public function del_handler($handler, $method, $sender) {
289
-		$handler = str_replace("-", "_", strtolower($handler));
290
-		$method = strtolower($method);
291
-
292
-		if ($this->is_system($sender)) {
293
-			unset($this->handlers[$handler][$method]);
294
-		}
295
-	}
296
-
297
-	public function lookup_handler($handler, $method) {
298
-		$handler = str_replace("-", "_", strtolower($handler));
299
-		$method = strtolower($method);
300
-
301
-		if (is_array($this->handlers[$handler])) {
302
-			if (isset($this->handlers[$handler]["*"])) {
303
-				return $this->handlers[$handler]["*"];
304
-			} else {
305
-				return $this->handlers[$handler][$method];
306
-			}
307
-		}
308
-
309
-		return false;
310
-	}
311
-
312
-	public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") {
313
-		$command = str_replace("-", "_", strtolower($command));
314
-
315
-		$this->commands[$command] = array("description" => $description,
316
-			"suffix" => $suffix,
317
-			"arghelp" => $arghelp,
318
-			"class" => $sender);
319
-	}
320
-
321
-	public function del_command($command) {
322
-		$command = "-" . strtolower($command);
323
-
324
-		unset($this->commands[$command]);
325
-	}
326
-
327
-	public function lookup_command($command) {
328
-		$command = "-" . strtolower($command);
329
-
330
-		if (is_array($this->commands[$command])) {
331
-			return $this->commands[$command]["class"];
332
-		} else {
333
-			return false;
334
-		}
335
-	}
336
-
337
-	public function get_commands() {
338
-		return $this->commands;
339
-	}
340
-
341
-	public function run_commands($args) {
342
-		foreach ($this->get_commands() as $command => $data) {
343
-			if (isset($args[$command])) {
344
-				$command = str_replace("-", "", $command);
345
-				$data["class"]->$command($args);
346
-			}
347
-		}
348
-	}
349
-
350
-	public function load_data() {
351
-		if ($this->owner_uid)  {
352
-			$sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
3
+    private $pdo;
4
+    private $hooks = array();
5
+    private $plugins = array();
6
+    private $handlers = array();
7
+    private $commands = array();
8
+    private $storage = array();
9
+    private $feeds = array();
10
+    private $api_methods = array();
11
+    private $plugin_actions = array();
12
+    private $owner_uid;
13
+    private $last_registered;
14
+    private static $instance;
15
+
16
+    const API_VERSION = 2;
17
+
18
+    // Hooks marked with *1 are run in global context and available
19
+    // to plugins loaded in config.php only
20
+
21
+    const HOOK_ARTICLE_BUTTON = 1;
22
+    const HOOK_ARTICLE_FILTER = 2;
23
+    const HOOK_PREFS_TAB = 3;
24
+    const HOOK_PREFS_TAB_SECTION = 4;
25
+    const HOOK_PREFS_TABS = 5;
26
+    const HOOK_FEED_PARSED = 6;
27
+    const HOOK_UPDATE_TASK = 7; // *1
28
+    const HOOK_AUTH_USER = 8;
29
+    const HOOK_HOTKEY_MAP = 9;
30
+    const HOOK_RENDER_ARTICLE = 10;
31
+    const HOOK_RENDER_ARTICLE_CDM = 11;
32
+    const HOOK_FEED_FETCHED = 12;
33
+    const HOOK_SANITIZE = 13;
34
+    const HOOK_RENDER_ARTICLE_API = 14;
35
+    const HOOK_TOOLBAR_BUTTON = 15;
36
+    const HOOK_ACTION_ITEM = 16;
37
+    const HOOK_HEADLINE_TOOLBAR_BUTTON = 17;
38
+    const HOOK_HOTKEY_INFO = 18;
39
+    const HOOK_ARTICLE_LEFT_BUTTON = 19;
40
+    const HOOK_PREFS_EDIT_FEED = 20;
41
+    const HOOK_PREFS_SAVE_FEED = 21;
42
+    const HOOK_FETCH_FEED = 22;
43
+    const HOOK_QUERY_HEADLINES = 23;
44
+    const HOOK_HOUSE_KEEPING = 24; // *1
45
+    const HOOK_SEARCH = 25;
46
+    const HOOK_FORMAT_ENCLOSURES = 26;
47
+    const HOOK_SUBSCRIBE_FEED = 27;
48
+    const HOOK_HEADLINES_BEFORE = 28;
49
+    const HOOK_RENDER_ENCLOSURE = 29;
50
+    const HOOK_ARTICLE_FILTER_ACTION = 30;
51
+    const HOOK_ARTICLE_EXPORT_FEED = 31;
52
+    const HOOK_MAIN_TOOLBAR_BUTTON = 32;
53
+    const HOOK_ENCLOSURE_ENTRY = 33;
54
+    const HOOK_FORMAT_ARTICLE = 34;
55
+    const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */
56
+    const HOOK_FEED_BASIC_INFO = 36;
57
+    const HOOK_SEND_LOCAL_FILE = 37;
58
+    const HOOK_UNSUBSCRIBE_FEED = 38;
59
+    const HOOK_SEND_MAIL = 39;
60
+    const HOOK_FILTER_TRIGGERED = 40;
61
+    const HOOK_GET_FULL_TEXT = 41;
62
+    const HOOK_ARTICLE_IMAGE = 42;
63
+    const HOOK_FEED_TREE = 43;
64
+    const HOOK_IFRAME_WHITELISTED = 44;
65
+
66
+    const KIND_ALL = 1;
67
+    const KIND_SYSTEM = 2;
68
+    const KIND_USER = 3;
69
+
70
+    public static function object_to_domain($plugin) {
71
+        return strtolower(get_class($plugin));
72
+    }
73
+
74
+    public function __construct() {
75
+        $this->pdo = Db::pdo();
76
+
77
+        $this->storage = array();
78
+    }
79
+
80
+    private function __clone() {
81
+        //
82
+    }
83
+
84
+    public static function getInstance() {
85
+        if (self::$instance == null)
86
+            self::$instance = new self();
87
+
88
+        return self::$instance;
89
+    }
90
+
91
+    private function register_plugin($name, $plugin) {
92
+        //array_push($this->plugins, $plugin);
93
+        $this->plugins[$name] = $plugin;
94
+    }
95
+
96
+    // needed for compatibility with API 1
97
+    public function get_link() {
98
+        return false;
99
+    }
100
+
101
+    public function get_dbh() {
102
+        return Db::get();
103
+    }
104
+
105
+    public function get_pdo() {
106
+        return $this->pdo;
107
+    }
108
+
109
+    public function get_plugin_names() {
110
+        $names = array();
111
+
112
+        foreach ($this->plugins as $p) {
113
+            array_push($names, get_class($p));
114
+        }
115
+
116
+        return $names;
117
+    }
118
+
119
+    public function get_plugins() {
120
+        return $this->plugins;
121
+    }
122
+
123
+    public function get_plugin($name) {
124
+        return $this->plugins[strtolower($name)];
125
+    }
126
+
127
+    public function run_hooks($type, $method, $args) {
128
+        foreach ($this->get_hooks($type) as $hook) {
129
+            $hook->$method($args);
130
+        }
131
+    }
132
+
133
+    public function add_hook($type, $sender, $priority = 50) {
134
+        $priority = (int) $priority;
135
+
136
+        if (!is_array($this->hooks[$type])) {
137
+            $this->hooks[$type] = [];
138
+        }
139
+
140
+        if (!is_array($this->hooks[$type][$priority])) {
141
+            $this->hooks[$type][$priority] = [];
142
+        }
143
+
144
+        array_push($this->hooks[$type][$priority], $sender);
145
+        ksort($this->hooks[$type]);
146
+    }
147
+
148
+    public function del_hook($type, $sender) {
149
+        if (is_array($this->hooks[$type])) {
150
+            foreach (array_keys($this->hooks[$type]) as $prio) {
151
+                $key = array_search($sender, $this->hooks[$type][$prio]);
152
+
153
+                if ($key !== false) {
154
+                    unset($this->hooks[$type][$prio][$key]);
155
+                }
156
+            }
157
+        }
158
+    }
159
+
160
+    public function get_hooks($type) {
161
+        if (isset($this->hooks[$type])) {
162
+            $tmp = [];
163
+
164
+            foreach (array_keys($this->hooks[$type]) as $prio) {
165
+                $tmp = array_merge($tmp, $this->hooks[$type][$prio]);
166
+            }
167
+
168
+            return $tmp;
169
+        } else {
170
+            return [];
171
+        }
172
+    }
173
+    public function load_all($kind, $owner_uid = false, $skip_init = false) {
174
+
175
+        $plugins = array_merge(glob("plugins/*"), glob("plugins.local/*"));
176
+        $plugins = array_filter($plugins, "is_dir");
177
+        $plugins = array_map("basename", $plugins);
178
+
179
+        asort($plugins);
180
+
181
+        $this->load(join(",", $plugins), $kind, $owner_uid, $skip_init);
182
+    }
183
+
184
+    public function load($classlist, $kind, $owner_uid = false, $skip_init = false) {
185
+        $plugins = explode(",", $classlist);
186
+
187
+        $this->owner_uid = (int) $owner_uid;
188
+
189
+        foreach ($plugins as $class) {
190
+            $class = trim($class);
191
+            $class_file = strtolower(clean_filename($class));
192
+
193
+            if (!is_dir(__DIR__."/../plugins/$class_file") &&
194
+                    !is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195
+
196
+            // try system plugin directory first
197
+            $file = __DIR__ . "/../plugins/$class_file/init.php";
198
+            $vendor_dir = __DIR__ . "/../plugins/$class_file/vendor";
199
+
200
+            if (!file_exists($file)) {
201
+                $file = __DIR__ . "/../plugins.local/$class_file/init.php";
202
+                $vendor_dir = __DIR__ . "/../plugins.local/$class_file/vendor";
203
+            }
204
+
205
+            if (!isset($this->plugins[$class])) {
206
+                if (file_exists($file)) require_once $file;
207
+
208
+                if (class_exists($class) && is_subclass_of($class, "Plugin")) {
209
+
210
+                    // register plugin autoloader if necessary, for namespaced classes ONLY
211
+                    // layout corresponds to tt-rss main /vendor/author/Package/Class.php
212
+
213
+                    if (file_exists($vendor_dir)) {
214
+                        spl_autoload_register(function($class) use ($vendor_dir) {
215
+
216
+                            if (strpos($class, '\\') !== false) {
217
+                                list ($namespace, $class_name) = explode('\\', $class, 2);
218
+
219
+                                if ($namespace && $class_name) {
220
+                                    $class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
221
+
222
+                                    if (file_exists($class_file))
223
+                                        require_once $class_file;
224
+                                }
225
+                            }
226
+                        });
227
+                    }
228
+
229
+                    $plugin = new $class($this);
230
+
231
+                    $plugin_api = $plugin->api_version();
232
+
233
+                    if ($plugin_api < PluginHost::API_VERSION) {
234
+                        user_error("plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING);
235
+                        continue;
236
+                    }
237
+
238
+                    if (file_exists(dirname($file) . "/locale")) {
239
+                        _bindtextdomain($class, dirname($file) . "/locale");
240
+                        _bind_textdomain_codeset($class, "UTF-8");
241
+                    }
242
+
243
+                    $this->last_registered = $class;
244
+
245
+                    switch ($kind) {
246
+                    case $this::KIND_SYSTEM:
247
+                        if ($this->is_system($plugin)) {
248
+                            if (!$skip_init) $plugin->init($this);
249
+                            $this->register_plugin($class, $plugin);
250
+                        }
251
+                        break;
252
+                    case $this::KIND_USER:
253
+                        if (!$this->is_system($plugin)) {
254
+                            if (!$skip_init) $plugin->init($this);
255
+                            $this->register_plugin($class, $plugin);
256
+                        }
257
+                        break;
258
+                    case $this::KIND_ALL:
259
+                        if (!$skip_init) $plugin->init($this);
260
+                        $this->register_plugin($class, $plugin);
261
+                        break;
262
+                    }
263
+                }
264
+            }
265
+        }
266
+    }
267
+
268
+    public function is_system($plugin) {
269
+        $about = $plugin->about();
270
+
271
+        return @$about[3];
272
+    }
273
+
274
+    // only system plugins are allowed to modify routing
275
+    public function add_handler($handler, $method, $sender) {
276
+        $handler = str_replace("-", "_", strtolower($handler));
277
+        $method = strtolower($method);
278
+
279
+        if ($this->is_system($sender)) {
280
+            if (!is_array($this->handlers[$handler])) {
281
+                $this->handlers[$handler] = array();
282
+            }
283
+
284
+            $this->handlers[$handler][$method] = $sender;
285
+        }
286
+    }
287
+
288
+    public function del_handler($handler, $method, $sender) {
289
+        $handler = str_replace("-", "_", strtolower($handler));
290
+        $method = strtolower($method);
291
+
292
+        if ($this->is_system($sender)) {
293
+            unset($this->handlers[$handler][$method]);
294
+        }
295
+    }
296
+
297
+    public function lookup_handler($handler, $method) {
298
+        $handler = str_replace("-", "_", strtolower($handler));
299
+        $method = strtolower($method);
300
+
301
+        if (is_array($this->handlers[$handler])) {
302
+            if (isset($this->handlers[$handler]["*"])) {
303
+                return $this->handlers[$handler]["*"];
304
+            } else {
305
+                return $this->handlers[$handler][$method];
306
+            }
307
+        }
308
+
309
+        return false;
310
+    }
311
+
312
+    public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") {
313
+        $command = str_replace("-", "_", strtolower($command));
314
+
315
+        $this->commands[$command] = array("description" => $description,
316
+            "suffix" => $suffix,
317
+            "arghelp" => $arghelp,
318
+            "class" => $sender);
319
+    }
320
+
321
+    public function del_command($command) {
322
+        $command = "-" . strtolower($command);
323
+
324
+        unset($this->commands[$command]);
325
+    }
326
+
327
+    public function lookup_command($command) {
328
+        $command = "-" . strtolower($command);
329
+
330
+        if (is_array($this->commands[$command])) {
331
+            return $this->commands[$command]["class"];
332
+        } else {
333
+            return false;
334
+        }
335
+    }
336
+
337
+    public function get_commands() {
338
+        return $this->commands;
339
+    }
340
+
341
+    public function run_commands($args) {
342
+        foreach ($this->get_commands() as $command => $data) {
343
+            if (isset($args[$command])) {
344
+                $command = str_replace("-", "", $command);
345
+                $data["class"]->$command($args);
346
+            }
347
+        }
348
+    }
349
+
350
+    public function load_data() {
351
+        if ($this->owner_uid)  {
352
+            $sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
353 353
 				WHERE owner_uid = ?");
354
-			$sth->execute([$this->owner_uid]);
354
+            $sth->execute([$this->owner_uid]);
355 355
 
356
-			while ($line = $sth->fetch()) {
357
-				$this->storage[$line["name"]] = unserialize($line["content"]);
358
-			}
359
-		}
360
-	}
356
+            while ($line = $sth->fetch()) {
357
+                $this->storage[$line["name"]] = unserialize($line["content"]);
358
+            }
359
+        }
360
+    }
361 361
 
362
-	private function save_data($plugin) {
363
-		if ($this->owner_uid) {
364
-			$this->pdo->beginTransaction();
362
+    private function save_data($plugin) {
363
+        if ($this->owner_uid) {
364
+            $this->pdo->beginTransaction();
365 365
 
366
-			$sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE
366
+            $sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE
367 367
 				owner_uid= ? AND name = ?");
368
-			$sth->execute([$this->owner_uid, $plugin]);
368
+            $sth->execute([$this->owner_uid, $plugin]);
369 369
 
370
-			if (!isset($this->storage[$plugin]))
371
-				$this->storage[$plugin] = array();
370
+            if (!isset($this->storage[$plugin]))
371
+                $this->storage[$plugin] = array();
372 372
 
373
-			$content = serialize($this->storage[$plugin]);
373
+            $content = serialize($this->storage[$plugin]);
374 374
 
375
-			if ($sth->fetch()) {
376
-				$sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
375
+            if ($sth->fetch()) {
376
+                $sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
377 377
 					WHERE owner_uid= ? AND name = ?");
378
-				$sth->execute([(string)$content, $this->owner_uid, $plugin]);
378
+                $sth->execute([(string)$content, $this->owner_uid, $plugin]);
379 379
 
380
-			} else {
381
-				$sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
380
+            } else {
381
+                $sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
382 382
 					(name,owner_uid,content) VALUES
383 383
 					(?, ?, ?)");
384
-				$sth->execute([$plugin, $this->owner_uid, (string)$content]);
385
-			}
384
+                $sth->execute([$plugin, $this->owner_uid, (string)$content]);
385
+            }
386 386
 
387
-			$this->pdo->commit();
388
-		}
389
-	}
387
+            $this->pdo->commit();
388
+        }
389
+    }
390 390
 
391
-	public function set($sender, $name, $value, $sync = true) {
392
-		$idx = get_class($sender);
391
+    public function set($sender, $name, $value, $sync = true) {
392
+        $idx = get_class($sender);
393 393
 
394
-		if (!isset($this->storage[$idx]))
395
-			$this->storage[$idx] = array();
394
+        if (!isset($this->storage[$idx]))
395
+            $this->storage[$idx] = array();
396 396
 
397
-		$this->storage[$idx][$name] = $value;
397
+        $this->storage[$idx][$name] = $value;
398 398
 
399
-		if ($sync) $this->save_data(get_class($sender));
400
-	}
399
+        if ($sync) $this->save_data(get_class($sender));
400
+    }
401 401
 
402
-	public function get($sender, $name, $default_value = false) {
403
-		$idx = get_class($sender);
402
+    public function get($sender, $name, $default_value = false) {
403
+        $idx = get_class($sender);
404 404
 
405
-		if (isset($this->storage[$idx][$name])) {
406
-			return $this->storage[$idx][$name];
407
-		} else {
408
-			return $default_value;
409
-		}
410
-	}
405
+        if (isset($this->storage[$idx][$name])) {
406
+            return $this->storage[$idx][$name];
407
+        } else {
408
+            return $default_value;
409
+        }
410
+    }
411 411
 
412
-	public function get_all($sender) {
413
-		$idx = get_class($sender);
412
+    public function get_all($sender) {
413
+        $idx = get_class($sender);
414 414
 
415
-		$data = $this->storage[$idx];
415
+        $data = $this->storage[$idx];
416 416
 
417
-		return $data ? $data : [];
418
-	}
417
+        return $data ? $data : [];
418
+    }
419 419
 
420
-	public function clear_data($sender) {
421
-		if ($this->owner_uid) {
422
-			$idx = get_class($sender);
420
+    public function clear_data($sender) {
421
+        if ($this->owner_uid) {
422
+            $idx = get_class($sender);
423 423
 
424
-			unset($this->storage[$idx]);
424
+            unset($this->storage[$idx]);
425 425
 
426
-			$sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ?
426
+            $sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ?
427 427
 				AND owner_uid = ?");
428
-			$sth->execute([$idx, $this->owner_uid]);
429
-		}
430
-	}
431
-
432
-	// Plugin feed functions are *EXPERIMENTAL*!
433
-
434
-	// cat_id: only -1 is supported (Special)
435
-	public function add_feed($cat_id, $title, $icon, $sender) {
436
-		if (!$this->feeds[$cat_id]) $this->feeds[$cat_id] = array();
437
-
438
-		$id = count($this->feeds[$cat_id]);
439
-
440
-		array_push($this->feeds[$cat_id],
441
-			array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon));
442
-
443
-		return $id;
444
-	}
445
-
446
-	public function get_feeds($cat_id) {
447
-		return $this->feeds[$cat_id];
448
-	}
449
-
450
-	// convert feed_id (e.g. -129) to pfeed_id first
451
-	public function get_feed_handler($pfeed_id) {
452
-		foreach ($this->feeds as $cat) {
453
-			foreach ($cat as $feed) {
454
-				if ($feed['id'] == $pfeed_id) {
455
-					return $feed['sender'];
456
-				}
457
-			}
458
-		}
459
-	}
460
-
461
-	public static function pfeed_to_feed_id($label) {
462
-		return PLUGIN_FEED_BASE_INDEX - 1 - abs($label);
463
-	}
464
-
465
-	public static function feed_to_pfeed_id($feed) {
466
-		return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
467
-	}
468
-
469
-	public function add_api_method($name, $sender) {
470
-		if ($this->is_system($sender)) {
471
-			$this->api_methods[strtolower($name)] = $sender;
472
-		}
473
-	}
474
-
475
-	public function get_api_method($name) {
476
-		return $this->api_methods[$name];
477
-	}
478
-
479
-	public function add_filter_action($sender, $action_name, $action_desc) {
480
-		$sender_class = get_class($sender);
481
-
482
-		if (!isset($this->plugin_actions[$sender_class]))
483
-			$this->plugin_actions[$sender_class] = array();
484
-
485
-		array_push($this->plugin_actions[$sender_class],
486
-			array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
487
-	}
488
-
489
-	public function get_filter_actions() {
490
-		return $this->plugin_actions;
491
-	}
492
-
493
-	public function get_owner_uid() {
494
-		return $this->owner_uid;
495
-	}
496
-
497
-	// handled by classes/pluginhandler.php, requires valid session
498
-	public function get_method_url($sender, $method, $params)  {
499
-		return get_self_url_prefix() . "/backend.php?" .
500
-			http_build_query(
501
-				array_merge(
502
-					[
503
-						"op" => "pluginhandler",
504
-						"plugin" => strtolower(get_class($sender)),
505
-						"method" => $method
506
-					],
507
-					$params));
508
-	}
509
-
510
-	// WARNING: endpoint in public.php, exposed to unauthenticated users
511
-	public function get_public_method_url($sender, $method, $params)  {
512
-		if ($sender->is_public_method($method)) {
513
-			return get_self_url_prefix() . "/public.php?" .
514
-				http_build_query(
515
-					array_merge(
516
-						[
517
-							"op" => "pluginhandler",
518
-							"plugin" => strtolower(get_class($sender)),
519
-							"pmethod" => $method
520
-						],
521
-						$params));
522
-		} else {
523
-			user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
524
-		}
525
-	}
428
+            $sth->execute([$idx, $this->owner_uid]);
429
+        }
430
+    }
431
+
432
+    // Plugin feed functions are *EXPERIMENTAL*!
433
+
434
+    // cat_id: only -1 is supported (Special)
435
+    public function add_feed($cat_id, $title, $icon, $sender) {
436
+        if (!$this->feeds[$cat_id]) $this->feeds[$cat_id] = array();
437
+
438
+        $id = count($this->feeds[$cat_id]);
439
+
440
+        array_push($this->feeds[$cat_id],
441
+            array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon));
442
+
443
+        return $id;
444
+    }
445
+
446
+    public function get_feeds($cat_id) {
447
+        return $this->feeds[$cat_id];
448
+    }
449
+
450
+    // convert feed_id (e.g. -129) to pfeed_id first
451
+    public function get_feed_handler($pfeed_id) {
452
+        foreach ($this->feeds as $cat) {
453
+            foreach ($cat as $feed) {
454
+                if ($feed['id'] == $pfeed_id) {
455
+                    return $feed['sender'];
456
+                }
457
+            }
458
+        }
459
+    }
460
+
461
+    public static function pfeed_to_feed_id($label) {
462
+        return PLUGIN_FEED_BASE_INDEX - 1 - abs($label);
463
+    }
464
+
465
+    public static function feed_to_pfeed_id($feed) {
466
+        return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
467
+    }
468
+
469
+    public function add_api_method($name, $sender) {
470
+        if ($this->is_system($sender)) {
471
+            $this->api_methods[strtolower($name)] = $sender;
472
+        }
473
+    }
474
+
475
+    public function get_api_method($name) {
476
+        return $this->api_methods[$name];
477
+    }
478
+
479
+    public function add_filter_action($sender, $action_name, $action_desc) {
480
+        $sender_class = get_class($sender);
481
+
482
+        if (!isset($this->plugin_actions[$sender_class]))
483
+            $this->plugin_actions[$sender_class] = array();
484
+
485
+        array_push($this->plugin_actions[$sender_class],
486
+            array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
487
+    }
488
+
489
+    public function get_filter_actions() {
490
+        return $this->plugin_actions;
491
+    }
492
+
493
+    public function get_owner_uid() {
494
+        return $this->owner_uid;
495
+    }
496
+
497
+    // handled by classes/pluginhandler.php, requires valid session
498
+    public function get_method_url($sender, $method, $params)  {
499
+        return get_self_url_prefix() . "/backend.php?" .
500
+            http_build_query(
501
+                array_merge(
502
+                    [
503
+                        "op" => "pluginhandler",
504
+                        "plugin" => strtolower(get_class($sender)),
505
+                        "method" => $method
506
+                    ],
507
+                    $params));
508
+    }
509
+
510
+    // WARNING: endpoint in public.php, exposed to unauthenticated users
511
+    public function get_public_method_url($sender, $method, $params)  {
512
+        if ($sender->is_public_method($method)) {
513
+            return get_self_url_prefix() . "/public.php?" .
514
+                http_build_query(
515
+                    array_merge(
516
+                        [
517
+                            "op" => "pluginhandler",
518
+                            "plugin" => strtolower(get_class($sender)),
519
+                            "pmethod" => $method
520
+                        ],
521
+                        $params));
522
+        } else {
523
+            user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
524
+        }
525
+    }
526 526
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 					!is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195 195
 
196 196
 			// try system plugin directory first
197
-			$file = __DIR__ . "/../plugins/$class_file/init.php";
198
-			$vendor_dir = __DIR__ . "/../plugins/$class_file/vendor";
197
+			$file = __DIR__."/../plugins/$class_file/init.php";
198
+			$vendor_dir = __DIR__."/../plugins/$class_file/vendor";
199 199
 
200 200
 			if (!file_exists($file)) {
201
-				$file = __DIR__ . "/../plugins.local/$class_file/init.php";
202
-				$vendor_dir = __DIR__ . "/../plugins.local/$class_file/vendor";
201
+				$file = __DIR__."/../plugins.local/$class_file/init.php";
202
+				$vendor_dir = __DIR__."/../plugins.local/$class_file/vendor";
203 203
 			}
204 204
 
205 205
 			if (!isset($this->plugins[$class])) {
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 								list ($namespace, $class_name) = explode('\\', $class, 2);
218 218
 
219 219
 								if ($namespace && $class_name) {
220
-									$class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
220
+									$class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php";
221 221
 
222 222
 									if (file_exists($class_file))
223 223
 										require_once $class_file;
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 					$plugin_api = $plugin->api_version();
232 232
 
233 233
 					if ($plugin_api < PluginHost::API_VERSION) {
234
-						user_error("plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING);
234
+						user_error("plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING);
235 235
 						continue;
236 236
 					}
237 237
 
238
-					if (file_exists(dirname($file) . "/locale")) {
239
-						_bindtextdomain($class, dirname($file) . "/locale");
238
+					if (file_exists(dirname($file)."/locale")) {
239
+						_bindtextdomain($class, dirname($file)."/locale");
240 240
 						_bind_textdomain_codeset($class, "UTF-8");
241 241
 					}
242 242
 
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 	}
320 320
 
321 321
 	public function del_command($command) {
322
-		$command = "-" . strtolower($command);
322
+		$command = "-".strtolower($command);
323 323
 
324 324
 		unset($this->commands[$command]);
325 325
 	}
326 326
 
327 327
 	public function lookup_command($command) {
328
-		$command = "-" . strtolower($command);
328
+		$command = "-".strtolower($command);
329 329
 
330 330
 		if (is_array($this->commands[$command])) {
331 331
 			return $this->commands[$command]["class"];
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	}
349 349
 
350 350
 	public function load_data() {
351
-		if ($this->owner_uid)  {
351
+		if ($this->owner_uid) {
352 352
 			$sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
353 353
 				WHERE owner_uid = ?");
354 354
 			$sth->execute([$this->owner_uid]);
@@ -375,13 +375,13 @@  discard block
 block discarded – undo
375 375
 			if ($sth->fetch()) {
376 376
 				$sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
377 377
 					WHERE owner_uid= ? AND name = ?");
378
-				$sth->execute([(string)$content, $this->owner_uid, $plugin]);
378
+				$sth->execute([(string) $content, $this->owner_uid, $plugin]);
379 379
 
380 380
 			} else {
381 381
 				$sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
382 382
 					(name,owner_uid,content) VALUES
383 383
 					(?, ?, ?)");
384
-				$sth->execute([$plugin, $this->owner_uid, (string)$content]);
384
+				$sth->execute([$plugin, $this->owner_uid, (string) $content]);
385 385
 			}
386 386
 
387 387
 			$this->pdo->commit();
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 	}
496 496
 
497 497
 	// handled by classes/pluginhandler.php, requires valid session
498
-	public function get_method_url($sender, $method, $params)  {
499
-		return get_self_url_prefix() . "/backend.php?" .
498
+	public function get_method_url($sender, $method, $params) {
499
+		return get_self_url_prefix()."/backend.php?".
500 500
 			http_build_query(
501 501
 				array_merge(
502 502
 					[
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
 	}
509 509
 
510 510
 	// WARNING: endpoint in public.php, exposed to unauthenticated users
511
-	public function get_public_method_url($sender, $method, $params)  {
511
+	public function get_public_method_url($sender, $method, $params) {
512 512
 		if ($sender->is_public_method($method)) {
513
-			return get_self_url_prefix() . "/public.php?" .
513
+			return get_self_url_prefix()."/public.php?".
514 514
 				http_build_query(
515 515
 					array_merge(
516 516
 						[
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 						],
521 521
 						$params));
522 522
 		} else {
523
-			user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
523
+			user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private.");
524 524
 		}
525 525
 	}
526 526
 }
Please login to merge, or discard this patch.