@@ -1,148 +1,148 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -1,28 +1,28 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -1,37 +1,37 @@ |
||
| 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 | + } |
|
@@ -1,361 +1,361 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function print_select($id, $default, $values, $attributes = "", $name = "") { |
| 4 | - if (!$name) { |
|
| 5 | - $name = $id; |
|
| 6 | - } |
|
| 7 | - |
|
| 8 | - print "<select name=\"$name\" id=\"$id\" $attributes>"; |
|
| 9 | - foreach ($values as $v) { |
|
| 10 | - if ($v == $default) { |
|
| 11 | - $sel = "selected=\"1\""; |
|
| 12 | - } else { |
|
| 13 | - $sel = ""; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - $v = trim($v); |
|
| 17 | - |
|
| 18 | - print "<option value=\"$v\" $sel>$v</option>"; |
|
| 19 | - } |
|
| 20 | - print "</select>"; |
|
| 4 | + if (!$name) { |
|
| 5 | + $name = $id; |
|
| 6 | + } |
|
| 7 | + |
|
| 8 | + print "<select name=\"$name\" id=\"$id\" $attributes>"; |
|
| 9 | + foreach ($values as $v) { |
|
| 10 | + if ($v == $default) { |
|
| 11 | + $sel = "selected=\"1\""; |
|
| 12 | + } else { |
|
| 13 | + $sel = ""; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + $v = trim($v); |
|
| 17 | + |
|
| 18 | + print "<option value=\"$v\" $sel>$v</option>"; |
|
| 19 | + } |
|
| 20 | + print "</select>"; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | function print_select_hash($id, $default, $values, $attributes = "", $name = "") { |
| 24 | - if (!$name) { |
|
| 25 | - $name = $id; |
|
| 26 | - } |
|
| 24 | + if (!$name) { |
|
| 25 | + $name = $id; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - print "<select name=\"$name\" id='$id' $attributes>"; |
|
| 29 | - foreach (array_keys($values) as $v) { |
|
| 30 | - if ($v == $default) { |
|
| 31 | - $sel = 'selected="selected"'; |
|
| 32 | - } else { |
|
| 33 | - $sel = ""; |
|
| 34 | - } |
|
| 28 | + print "<select name=\"$name\" id='$id' $attributes>"; |
|
| 29 | + foreach (array_keys($values) as $v) { |
|
| 30 | + if ($v == $default) { |
|
| 31 | + $sel = 'selected="selected"'; |
|
| 32 | + } else { |
|
| 33 | + $sel = ""; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $v = trim($v); |
|
| 36 | + $v = trim($v); |
|
| 37 | 37 | |
| 38 | - print "<option $sel value=\"$v\">".$values[$v]."</option>"; |
|
| 39 | - } |
|
| 38 | + print "<option $sel value=\"$v\">".$values[$v]."</option>"; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - print "</select>"; |
|
| 41 | + print "</select>"; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function print_hidden($name, $value) { |
| 45 | - print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">"; |
|
| 45 | + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">"; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function print_checkbox($id, $checked, $value = "", $attributes = "") { |
| 49 | - $checked_str = $checked ? "checked" : ""; |
|
| 50 | - $value_str = $value ? "value=\"$value\"" : ""; |
|
| 49 | + $checked_str = $checked ? "checked" : ""; |
|
| 50 | + $value_str = $value ? "value=\"$value\"" : ""; |
|
| 51 | 51 | |
| 52 | - print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">"; |
|
| 52 | + print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function print_button($type, $value, $attributes = "") { |
| 56 | - print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>"; |
|
| 56 | + print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function print_radio($id, $default, $true_is, $values, $attributes = "") { |
| 60 | - foreach ($values as $v) { |
|
| 60 | + foreach ($values as $v) { |
|
| 61 | 61 | |
| 62 | - if ($v == $default) { |
|
| 63 | - $sel = "checked"; |
|
| 64 | - } else { |
|
| 65 | - $sel = ""; |
|
| 66 | - } |
|
| 62 | + if ($v == $default) { |
|
| 63 | + $sel = "checked"; |
|
| 64 | + } else { |
|
| 65 | + $sel = ""; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($v == $true_is) { |
|
| 69 | - $sel .= " value=\"1\""; |
|
| 70 | - } else { |
|
| 71 | - $sel .= " value=\"0\""; |
|
| 72 | - } |
|
| 68 | + if ($v == $true_is) { |
|
| 69 | + $sel .= " value=\"1\""; |
|
| 70 | + } else { |
|
| 71 | + $sel .= " value=\"0\""; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" |
|
| 74 | + print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" |
|
| 75 | 75 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; |
| 76 | 76 | |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | function print_feed_multi_select($id, $default_ids = [], |
| 81 | - $attributes = "", $include_all_feeds = true, |
|
| 82 | - $root_id = null, $nest_level = 0) { |
|
| 81 | + $attributes = "", $include_all_feeds = true, |
|
| 82 | + $root_id = null, $nest_level = 0) { |
|
| 83 | 83 | |
| 84 | - $pdo = DB::pdo(); |
|
| 84 | + $pdo = DB::pdo(); |
|
| 85 | 85 | |
| 86 | - print_r(in_array("CAT:6", $default_ids)); |
|
| 86 | + print_r(in_array("CAT:6", $default_ids)); |
|
| 87 | 87 | |
| 88 | - if (!$root_id) { |
|
| 89 | - print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>"; |
|
| 90 | - if ($include_all_feeds) { |
|
| 91 | - $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; |
|
| 92 | - print "<option $is_selected value=\"0\">".__('All feeds')."</option>"; |
|
| 93 | - } |
|
| 94 | - } |
|
| 88 | + if (!$root_id) { |
|
| 89 | + print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>"; |
|
| 90 | + if ($include_all_feeds) { |
|
| 91 | + $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; |
|
| 92 | + print "<option $is_selected value=\"0\">".__('All feeds')."</option>"; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 96 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 97 | 97 | |
| 98 | - if (!$root_id) { |
|
| 99 | - $root_id = null; |
|
| 100 | - } |
|
| 98 | + if (!$root_id) { |
|
| 99 | + $root_id = null; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $sth = $pdo->prepare("SELECT id,title, |
|
| 102 | + $sth = $pdo->prepare("SELECT id,title, |
|
| 103 | 103 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE |
| 104 | 104 | c2.parent_cat = ttrss_feed_categories.id) AS num_children |
| 105 | 105 | FROM ttrss_feed_categories |
| 106 | 106 | WHERE owner_uid = :uid AND |
| 107 | 107 | (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); |
| 108 | 108 | |
| 109 | - $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
|
| 109 | + $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
|
| 110 | 110 | |
| 111 | - while ($line = $sth->fetch()) { |
|
| 111 | + while ($line = $sth->fetch()) { |
|
| 112 | 112 | |
| 113 | - for ($i = 0; $i < $nest_level; $i++) { |
|
| 114 | - $line["title"] = " - " . $line["title"]; |
|
| 115 | - } |
|
| 113 | + for ($i = 0; $i < $nest_level; $i++) { |
|
| 114 | + $line["title"] = " - " . $line["title"]; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; |
|
| 117 | + $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; |
|
| 118 | 118 | |
| 119 | - printf("<option $is_selected value='CAT:%d'>%s</option>", |
|
| 120 | - $line["id"], htmlspecialchars($line["title"])); |
|
| 119 | + printf("<option $is_selected value='CAT:%d'>%s</option>", |
|
| 120 | + $line["id"], htmlspecialchars($line["title"])); |
|
| 121 | 121 | |
| 122 | - if ($line["num_children"] > 0) { |
|
| 123 | - print_feed_multi_select($id, $default_ids, $attributes, |
|
| 124 | - $include_all_feeds, $line["id"], $nest_level+1); |
|
| 125 | - } |
|
| 122 | + if ($line["num_children"] > 0) { |
|
| 123 | + print_feed_multi_select($id, $default_ids, $attributes, |
|
| 124 | + $include_all_feeds, $line["id"], $nest_level+1); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 127 | + $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 128 | 128 | WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); |
| 129 | 129 | |
| 130 | - $f_sth->execute([$line['id'], $_SESSION['uid']]); |
|
| 130 | + $f_sth->execute([$line['id'], $_SESSION['uid']]); |
|
| 131 | 131 | |
| 132 | - while ($fline = $f_sth->fetch()) { |
|
| 133 | - $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; |
|
| 132 | + while ($fline = $f_sth->fetch()) { |
|
| 133 | + $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; |
|
| 134 | 134 | |
| 135 | - $fline["title"] = " + " . $fline["title"]; |
|
| 135 | + $fline["title"] = " + " . $fline["title"]; |
|
| 136 | 136 | |
| 137 | - for ($i = 0; $i < $nest_level; $i++) { |
|
| 138 | - $fline["title"] = " - " . $fline["title"]; |
|
| 139 | - } |
|
| 137 | + for ($i = 0; $i < $nest_level; $i++) { |
|
| 138 | + $fline["title"] = " - " . $fline["title"]; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - printf("<option $is_selected value='%d'>%s</option>", |
|
| 142 | - $fline["id"], htmlspecialchars($fline["title"])); |
|
| 143 | - } |
|
| 144 | - } |
|
| 141 | + printf("<option $is_selected value='%d'>%s</option>", |
|
| 142 | + $fline["id"], htmlspecialchars($fline["title"])); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - if (!$root_id) { |
|
| 147 | - $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; |
|
| 146 | + if (!$root_id) { |
|
| 147 | + $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; |
|
| 148 | 148 | |
| 149 | - printf("<option $is_selected value='CAT:0'>%s</option>", |
|
| 150 | - __("Uncategorized")); |
|
| 149 | + printf("<option $is_selected value='CAT:0'>%s</option>", |
|
| 150 | + __("Uncategorized")); |
|
| 151 | 151 | |
| 152 | - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 152 | + $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 153 | 153 | WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); |
| 154 | - $f_sth->execute([$_SESSION['uid']]); |
|
| 154 | + $f_sth->execute([$_SESSION['uid']]); |
|
| 155 | 155 | |
| 156 | - while ($fline = $f_sth->fetch()) { |
|
| 157 | - $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; |
|
| 156 | + while ($fline = $f_sth->fetch()) { |
|
| 157 | + $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; |
|
| 158 | 158 | |
| 159 | - $fline["title"] = " + " . $fline["title"]; |
|
| 159 | + $fline["title"] = " + " . $fline["title"]; |
|
| 160 | 160 | |
| 161 | - for ($i = 0; $i < $nest_level; $i++) { |
|
| 162 | - $fline["title"] = " - " . $fline["title"]; |
|
| 163 | - } |
|
| 161 | + for ($i = 0; $i < $nest_level; $i++) { |
|
| 162 | + $fline["title"] = " - " . $fline["title"]; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - printf("<option $is_selected value='%d'>%s</option>", |
|
| 166 | - $fline["id"], htmlspecialchars($fline["title"])); |
|
| 167 | - } |
|
| 168 | - } |
|
| 165 | + printf("<option $is_selected value='%d'>%s</option>", |
|
| 166 | + $fline["id"], htmlspecialchars($fline["title"])); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - } else { |
|
| 171 | - $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 170 | + } else { |
|
| 171 | + $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
|
| 172 | 172 | WHERE owner_uid = ? ORDER BY title"); |
| 173 | - $sth->execute([$_SESSION['uid']]); |
|
| 173 | + $sth->execute([$_SESSION['uid']]); |
|
| 174 | 174 | |
| 175 | - while ($line = $sth->fetch()) { |
|
| 175 | + while ($line = $sth->fetch()) { |
|
| 176 | 176 | |
| 177 | - $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; |
|
| 177 | + $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; |
|
| 178 | 178 | |
| 179 | - printf("<option $is_selected value='%d'>%s</option>", |
|
| 180 | - $line["id"], htmlspecialchars($line["title"])); |
|
| 181 | - } |
|
| 182 | - } |
|
| 179 | + printf("<option $is_selected value='%d'>%s</option>", |
|
| 180 | + $line["id"], htmlspecialchars($line["title"])); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if (!$root_id) { |
|
| 185 | - print "</select>"; |
|
| 186 | - } |
|
| 184 | + if (!$root_id) { |
|
| 185 | + print "</select>"; |
|
| 186 | + } |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | function print_feed_cat_select($id, $default_id, |
| 190 | - $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { |
|
| 190 | + $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { |
|
| 191 | 191 | |
| 192 | - if (!$root_id) { |
|
| 193 | - print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; |
|
| 194 | - } |
|
| 192 | + if (!$root_id) { |
|
| 193 | + print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - $pdo = DB::pdo(); |
|
| 196 | + $pdo = DB::pdo(); |
|
| 197 | 197 | |
| 198 | - if (!$root_id) { |
|
| 199 | - $root_id = null; |
|
| 200 | - } |
|
| 198 | + if (!$root_id) { |
|
| 199 | + $root_id = null; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $sth = $pdo->prepare("SELECT id,title, |
|
| 202 | + $sth = $pdo->prepare("SELECT id,title, |
|
| 203 | 203 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE |
| 204 | 204 | c2.parent_cat = ttrss_feed_categories.id) AS num_children |
| 205 | 205 | FROM ttrss_feed_categories |
| 206 | 206 | WHERE owner_uid = :uid AND |
| 207 | 207 | (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); |
| 208 | - $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
|
| 209 | - |
|
| 210 | - $found = 0; |
|
| 211 | - |
|
| 212 | - while ($line = $sth->fetch()) { |
|
| 213 | - ++$found; |
|
| 214 | - |
|
| 215 | - if ($line["id"] == $default_id) { |
|
| 216 | - $is_selected = "selected=\"1\""; |
|
| 217 | - } else { |
|
| 218 | - $is_selected = ""; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - for ($i = 0; $i < $nest_level; $i++) { |
|
| 222 | - $line["title"] = " - " . $line["title"]; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - if ($line["title"]) { |
|
| 226 | - printf("<option $is_selected value='%d'>%s</option>", |
|
| 227 | - $line["id"], htmlspecialchars($line["title"])); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ($line["num_children"] > 0) { |
|
| 231 | - print_feed_cat_select($id, $default_id, $attributes, |
|
| 232 | - $include_all_cats, $line["id"], $nest_level+1); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (!$root_id) { |
|
| 237 | - if ($include_all_cats) { |
|
| 238 | - if ($found > 0) { |
|
| 239 | - print "<option disabled=\"1\">--------</option>"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if ($default_id == 0) { |
|
| 243 | - $is_selected = "selected=\"1\""; |
|
| 244 | - } else { |
|
| 245 | - $is_selected = ""; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>"; |
|
| 249 | - } |
|
| 250 | - print "</select>"; |
|
| 251 | - } |
|
| 208 | + $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
|
| 209 | + |
|
| 210 | + $found = 0; |
|
| 211 | + |
|
| 212 | + while ($line = $sth->fetch()) { |
|
| 213 | + ++$found; |
|
| 214 | + |
|
| 215 | + if ($line["id"] == $default_id) { |
|
| 216 | + $is_selected = "selected=\"1\""; |
|
| 217 | + } else { |
|
| 218 | + $is_selected = ""; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + for ($i = 0; $i < $nest_level; $i++) { |
|
| 222 | + $line["title"] = " - " . $line["title"]; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + if ($line["title"]) { |
|
| 226 | + printf("<option $is_selected value='%d'>%s</option>", |
|
| 227 | + $line["id"], htmlspecialchars($line["title"])); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ($line["num_children"] > 0) { |
|
| 231 | + print_feed_cat_select($id, $default_id, $attributes, |
|
| 232 | + $include_all_cats, $line["id"], $nest_level+1); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (!$root_id) { |
|
| 237 | + if ($include_all_cats) { |
|
| 238 | + if ($found > 0) { |
|
| 239 | + print "<option disabled=\"1\">--------</option>"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if ($default_id == 0) { |
|
| 243 | + $is_selected = "selected=\"1\""; |
|
| 244 | + } else { |
|
| 245 | + $is_selected = ""; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>"; |
|
| 249 | + } |
|
| 250 | + print "</select>"; |
|
| 251 | + } |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | function stylesheet_tag($filename, $id = false) { |
| 255 | - $timestamp = filemtime($filename); |
|
| 255 | + $timestamp = filemtime($filename); |
|
| 256 | 256 | |
| 257 | - $id_part = $id ? "id=\"$id\"" : ""; |
|
| 257 | + $id_part = $id ? "id=\"$id\"" : ""; |
|
| 258 | 258 | |
| 259 | - return "<link rel=\"stylesheet\" $id_part type=\"text/css\" data-orig-href=\"$filename\" href=\"$filename?$timestamp\"/>\n"; |
|
| 259 | + return "<link rel=\"stylesheet\" $id_part type=\"text/css\" data-orig-href=\"$filename\" href=\"$filename?$timestamp\"/>\n"; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | function javascript_tag($filename) { |
| 263 | - $query = ""; |
|
| 263 | + $query = ""; |
|
| 264 | 264 | |
| 265 | - if (!(strpos($filename, "?") === false)) { |
|
| 266 | - $query = substr($filename, strpos($filename, "?") + 1); |
|
| 267 | - $filename = substr($filename, 0, strpos($filename, "?")); |
|
| 268 | - } |
|
| 265 | + if (!(strpos($filename, "?") === false)) { |
|
| 266 | + $query = substr($filename, strpos($filename, "?") + 1); |
|
| 267 | + $filename = substr($filename, 0, strpos($filename, "?")); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - $timestamp = filemtime($filename); |
|
| 270 | + $timestamp = filemtime($filename); |
|
| 271 | 271 | |
| 272 | - if ($query) { |
|
| 273 | - $timestamp .= "&$query"; |
|
| 274 | - } |
|
| 272 | + if ($query) { |
|
| 273 | + $timestamp .= "&$query"; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n"; |
|
| 276 | + return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n"; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | function format_warning($msg, $id = "") { |
| 280 | - return "<div class=\"alert\" id=\"$id\">$msg</div>"; |
|
| 280 | + return "<div class=\"alert\" id=\"$id\">$msg</div>"; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | function format_notice($msg, $id = "") { |
| 284 | - return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>"; |
|
| 284 | + return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>"; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | function format_error($msg, $id = "") { |
| 288 | - return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>"; |
|
| 288 | + return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>"; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | function print_notice($msg) { |
| 292 | - return print format_notice($msg); |
|
| 292 | + return print format_notice($msg); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | function print_warning($msg) { |
| 296 | - return print format_warning($msg); |
|
| 296 | + return print format_warning($msg); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | function print_error($msg) { |
| 300 | - return print format_error($msg); |
|
| 300 | + return print format_error($msg); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | function format_inline_player($url, $ctype) { |
| 304 | 304 | |
| 305 | - $entry = ""; |
|
| 305 | + $entry = ""; |
|
| 306 | 306 | |
| 307 | - $url = htmlspecialchars($url); |
|
| 307 | + $url = htmlspecialchars($url); |
|
| 308 | 308 | |
| 309 | - if (strpos($ctype, "audio/") === 0) { |
|
| 309 | + if (strpos($ctype, "audio/") === 0) { |
|
| 310 | 310 | |
| 311 | - $entry .= "<div class='inline-player'>"; |
|
| 311 | + $entry .= "<div class='inline-player'>"; |
|
| 312 | 312 | |
| 313 | - if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || |
|
| 314 | - $_SESSION["hasMp3"])) { |
|
| 313 | + if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || |
|
| 314 | + $_SESSION["hasMp3"])) { |
|
| 315 | 315 | |
| 316 | - $entry .= "<audio preload=\"none\" controls> |
|
| 316 | + $entry .= "<audio preload=\"none\" controls> |
|
| 317 | 317 | <source type=\"$ctype\" src=\"$url\"/> |
| 318 | 318 | </audio> "; |
| 319 | 319 | |
| 320 | - } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - if ($entry) { |
|
| 323 | - $entry .= "<a target=\"_blank\" rel=\"noopener noreferrer\" |
|
| 322 | + if ($entry) { |
|
| 323 | + $entry .= "<a target=\"_blank\" rel=\"noopener noreferrer\" |
|
| 324 | 324 | href=\"$url\">" . basename($url) . "</a>"; |
| 325 | - } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - $entry .= "</div>"; |
|
| 327 | + $entry .= "</div>"; |
|
| 328 | 328 | |
| 329 | - return $entry; |
|
| 329 | + return $entry; |
|
| 330 | 330 | |
| 331 | - } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - return ""; |
|
| 333 | + return ""; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | function print_label_select($name, $value, $attributes = "") { |
| 337 | 337 | |
| 338 | - $pdo = Db::pdo(); |
|
| 338 | + $pdo = Db::pdo(); |
|
| 339 | 339 | |
| 340 | - $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
| 340 | + $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
| 341 | 341 | WHERE owner_uid = ? ORDER BY caption"); |
| 342 | - $sth->execute([$_SESSION['uid']]); |
|
| 342 | + $sth->execute([$_SESSION['uid']]); |
|
| 343 | 343 | |
| 344 | - print "<select default=\"$value\" name=\"".htmlspecialchars($name). |
|
| 345 | - "\" $attributes>"; |
|
| 344 | + print "<select default=\"$value\" name=\"".htmlspecialchars($name). |
|
| 345 | + "\" $attributes>"; |
|
| 346 | 346 | |
| 347 | - while ($line = $sth->fetch()) { |
|
| 347 | + while ($line = $sth->fetch()) { |
|
| 348 | 348 | |
| 349 | - $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; |
|
| 349 | + $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; |
|
| 350 | 350 | |
| 351 | - print "<option value=\"".htmlspecialchars($line["caption"])."\" |
|
| 351 | + print "<option value=\"".htmlspecialchars($line["caption"])."\" |
|
| 352 | 352 | $issel>".htmlspecialchars($line["caption"])."</option>"; |
| 353 | 353 | |
| 354 | - } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>"; |
| 357 | 357 | |
| 358 | - print "</select>"; |
|
| 358 | + print "</select>"; |
|
| 359 | 359 | |
| 360 | 360 | |
| 361 | 361 | } |
@@ -1,190 +1,190 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - function make_self_url() { |
|
| 4 | - $proto = is_server_https() ? 'https' : 'http'; |
|
| 3 | + function make_self_url() { |
|
| 4 | + $proto = is_server_https() ? 'https' : 'http'; |
|
| 5 | 5 | |
| 6 | - return $proto.'://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; |
|
| 7 | - } |
|
| 6 | + return $proto.'://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; |
|
| 7 | + } |
|
| 8 | 8 | |
| 9 | - function make_self_url_path() { |
|
| 10 | - $proto = is_server_https() ? 'https' : 'http'; |
|
| 11 | - $url_path = $proto.'://'.$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
| 9 | + function make_self_url_path() { |
|
| 10 | + $proto = is_server_https() ? 'https' : 'http'; |
|
| 11 | + $url_path = $proto.'://'.$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
| 12 | 12 | |
| 13 | - return $url_path; |
|
| 14 | - } |
|
| 13 | + return $url_path; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - function check_mysql_tables() { |
|
| 17 | - $pdo = Db::pdo(); |
|
| 16 | + function check_mysql_tables() { |
|
| 17 | + $pdo = Db::pdo(); |
|
| 18 | 18 | |
| 19 | - $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE |
|
| 19 | + $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE |
|
| 20 | 20 | table_schema = ? AND table_name LIKE 'ttrss_%' AND engine != 'InnoDB'"); |
| 21 | - $sth->execute([DB_NAME]); |
|
| 21 | + $sth->execute([DB_NAME]); |
|
| 22 | 22 | |
| 23 | - $bad_tables = []; |
|
| 23 | + $bad_tables = []; |
|
| 24 | 24 | |
| 25 | - while ($line = $sth->fetch()) { |
|
| 26 | - array_push($bad_tables, $line); |
|
| 27 | - } |
|
| 25 | + while ($line = $sth->fetch()) { |
|
| 26 | + array_push($bad_tables, $line); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - return $bad_tables; |
|
| 30 | - } |
|
| 29 | + return $bad_tables; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - function initial_sanity_check() { |
|
| 32 | + function initial_sanity_check() { |
|
| 33 | 33 | |
| 34 | - $errors = array(); |
|
| 34 | + $errors = array(); |
|
| 35 | 35 | |
| 36 | - if (!file_exists("config.php")) { |
|
| 37 | - array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it."); |
|
| 38 | - } else { |
|
| 36 | + if (!file_exists("config.php")) { |
|
| 37 | + array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it."); |
|
| 38 | + } else { |
|
| 39 | 39 | |
| 40 | - require_once "sanity_config.php"; |
|
| 40 | + require_once "sanity_config.php"; |
|
| 41 | 41 | |
| 42 | - if (file_exists("install") && !file_exists("config.php")) { |
|
| 43 | - array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); |
|
| 44 | - } |
|
| 42 | + if (file_exists("install") && !file_exists("config.php")) { |
|
| 43 | + array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if (strpos(PLUGINS, "auth_") === false) { |
|
| 47 | - array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); |
|
| 48 | - } |
|
| 46 | + if (strpos(PLUGINS, "auth_") === false) { |
|
| 47 | + array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - if (function_exists('posix_getuid') && posix_getuid() == 0) { |
|
| 51 | - array_push($errors, "Please don't run this script as root."); |
|
| 52 | - } |
|
| 50 | + if (function_exists('posix_getuid') && posix_getuid() == 0) { |
|
| 51 | + array_push($errors, "Please don't run this script as root."); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
| 55 | - array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
|
| 56 | - } |
|
| 54 | + if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
| 55 | + array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if (!class_exists("UConverter")) { |
|
| 59 | - array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); |
|
| 60 | - } |
|
| 58 | + if (!class_exists("UConverter")) { |
|
| 59 | + array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { |
|
| 63 | - array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); |
|
| 64 | - } |
|
| 62 | + if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { |
|
| 63 | + array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if (!is_writable(CACHE_DIR."/images")) { |
|
| 67 | - array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); |
|
| 68 | - } |
|
| 66 | + if (!is_writable(CACHE_DIR."/images")) { |
|
| 67 | + array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if (!is_writable(CACHE_DIR."/upload")) { |
|
| 71 | - array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); |
|
| 72 | - } |
|
| 70 | + if (!is_writable(CACHE_DIR."/upload")) { |
|
| 71 | + array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if (!is_writable(CACHE_DIR."/export")) { |
|
| 75 | - array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); |
|
| 76 | - } |
|
| 74 | + if (!is_writable(CACHE_DIR."/export")) { |
|
| 75 | + array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { |
|
| 79 | - array_push($errors, |
|
| 80 | - "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); |
|
| 81 | - } |
|
| 78 | + if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { |
|
| 79 | + array_push($errors, |
|
| 80 | + "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - foreach ($required_defines as $d) { |
|
| 84 | - if (!defined($d)) { |
|
| 85 | - array_push($errors, |
|
| 86 | - "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); |
|
| 87 | - } |
|
| 88 | - } |
|
| 83 | + foreach ($required_defines as $d) { |
|
| 84 | + if (!defined($d)) { |
|
| 85 | + array_push($errors, |
|
| 86 | + "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - if (SINGLE_USER_MODE && class_exists("PDO")) { |
|
| 91 | - $pdo = DB::pdo(); |
|
| 90 | + if (SINGLE_USER_MODE && class_exists("PDO")) { |
|
| 91 | + $pdo = DB::pdo(); |
|
| 92 | 92 | |
| 93 | - $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); |
|
| 93 | + $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); |
|
| 94 | 94 | |
| 95 | - if (!$res->fetch()) { |
|
| 96 | - array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); |
|
| 97 | - } |
|
| 98 | - } |
|
| 95 | + if (!$res->fetch()) { |
|
| 96 | + array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - $ref_self_url_path = make_self_url_path(); |
|
| 101 | - $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); |
|
| 100 | + $ref_self_url_path = make_self_url_path(); |
|
| 101 | + $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); |
|
| 102 | 102 | |
| 103 | - if (SELF_URL_PATH == "http://example.org/tt-rss/") { |
|
| 104 | - array_push($errors, |
|
| 105 | - "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>$ref_self_url_path</b>)"); |
|
| 106 | - } |
|
| 103 | + if (SELF_URL_PATH == "http://example.org/tt-rss/") { |
|
| 104 | + array_push($errors, |
|
| 105 | + "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>$ref_self_url_path</b>)"); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - if (isset($_SERVER["HTTP_HOST"]) && |
|
| 109 | - (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && |
|
| 110 | - SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path) - 1)) { |
|
| 111 | - array_push($errors, |
|
| 112 | - "Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b>"); |
|
| 113 | - } |
|
| 108 | + if (isset($_SERVER["HTTP_HOST"]) && |
|
| 109 | + (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && |
|
| 110 | + SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path) - 1)) { |
|
| 111 | + array_push($errors, |
|
| 112 | + "Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b>"); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - if (!is_writable(ICONS_DIR)) { |
|
| 116 | - array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); |
|
| 117 | - } |
|
| 115 | + if (!is_writable(ICONS_DIR)) { |
|
| 116 | + array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if (!is_writable(LOCK_DIRECTORY)) { |
|
| 120 | - array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); |
|
| 121 | - } |
|
| 119 | + if (!is_writable(LOCK_DIRECTORY)) { |
|
| 120 | + array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
|
| 124 | - 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."); |
|
| 125 | - } |
|
| 123 | + if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
|
| 124 | + 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."); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - if (!function_exists("json_encode")) { |
|
| 128 | - array_push($errors, "PHP support for JSON is required, but was not found."); |
|
| 129 | - } |
|
| 127 | + if (!function_exists("json_encode")) { |
|
| 128 | + array_push($errors, "PHP support for JSON is required, but was not found."); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - if (DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
| 132 | - array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php."); |
|
| 133 | - } |
|
| 131 | + if (DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
| 132 | + array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php."); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
| 136 | - array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php"); |
|
| 137 | - } |
|
| 135 | + if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
| 136 | + array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php"); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!class_exists("PDO")) { |
|
| 140 | - array_push($errors, "PHP support for PDO is required but was not found."); |
|
| 141 | - } |
|
| 139 | + if (!class_exists("PDO")) { |
|
| 140 | + array_push($errors, "PHP support for PDO is required but was not found."); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if (!function_exists("mb_strlen")) { |
|
| 144 | - array_push($errors, "PHP support for mbstring functions is required but was not found."); |
|
| 145 | - } |
|
| 143 | + if (!function_exists("mb_strlen")) { |
|
| 144 | + array_push($errors, "PHP support for mbstring functions is required but was not found."); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - if (!function_exists("hash")) { |
|
| 148 | - array_push($errors, "PHP support for hash() function is required but was not found."); |
|
| 149 | - } |
|
| 147 | + if (!function_exists("hash")) { |
|
| 148 | + array_push($errors, "PHP support for hash() function is required but was not found."); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - if (ini_get("safe_mode")) { |
|
| 152 | - array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss."); |
|
| 153 | - } |
|
| 151 | + if (ini_get("safe_mode")) { |
|
| 152 | + array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss."); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - if (!function_exists("mime_content_type")) { |
|
| 156 | - array_push($errors, "PHP function mime_content_type() is missing, try enabling fileinfo module."); |
|
| 157 | - } |
|
| 155 | + if (!function_exists("mime_content_type")) { |
|
| 156 | + array_push($errors, "PHP function mime_content_type() is missing, try enabling fileinfo module."); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - if (!class_exists("DOMDocument")) { |
|
| 160 | - array_push($errors, "PHP support for DOMDocument is required, but was not found."); |
|
| 161 | - } |
|
| 159 | + if (!class_exists("DOMDocument")) { |
|
| 160 | + array_push($errors, "PHP support for DOMDocument is required, but was not found."); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - if (DB_TYPE == "mysql") { |
|
| 164 | - $bad_tables = check_mysql_tables(); |
|
| 163 | + if (DB_TYPE == "mysql") { |
|
| 164 | + $bad_tables = check_mysql_tables(); |
|
| 165 | 165 | |
| 166 | - if (count($bad_tables) > 0) { |
|
| 167 | - $bad_tables_fmt = []; |
|
| 166 | + if (count($bad_tables) > 0) { |
|
| 167 | + $bad_tables_fmt = []; |
|
| 168 | 168 | |
| 169 | - foreach ($bad_tables as $bt) { |
|
| 170 | - array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); |
|
| 171 | - } |
|
| 169 | + foreach ($bad_tables as $bt) { |
|
| 170 | + array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - $msg = "<p>The following tables use an unsupported MySQL engine: <b>". |
|
| 174 | - implode(", ", $bad_tables_fmt)."</b>.</p>"; |
|
| 173 | + $msg = "<p>The following tables use an unsupported MySQL engine: <b>". |
|
| 174 | + implode(", ", $bad_tables_fmt)."</b>.</p>"; |
|
| 175 | 175 | |
| 176 | - $msg .= "<p>The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run |
|
| 176 | + $msg .= "<p>The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run |
|
| 177 | 177 | tt-rss. |
| 178 | 178 | Please backup your data (via OPML) and re-import the schema before continuing.</p> |
| 179 | 179 | <p><b>WARNING: importing the schema would mean LOSS OF ALL YOUR DATA.</b></p>"; |
| 180 | 180 | |
| 181 | 181 | |
| 182 | - array_push($errors, $msg); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - } |
|
| 182 | + array_push($errors, $msg); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?> |
|
| 187 | + if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?> |
|
| 188 | 188 | <!DOCTYPE html> |
| 189 | 189 | <html> |
| 190 | 190 | <head> |
@@ -211,22 +211,22 @@ discard block |
||
| 211 | 211 | </html> |
| 212 | 212 | |
| 213 | 213 | <?php |
| 214 | - die; |
|
| 215 | - } else if (count($errors) > 0) { |
|
| 216 | - echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n"; |
|
| 217 | - echo "Please fix errors indicated by the following messages:\n\n"; |
|
| 214 | + die; |
|
| 215 | + } else if (count($errors) > 0) { |
|
| 216 | + echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n"; |
|
| 217 | + echo "Please fix errors indicated by the following messages:\n\n"; |
|
| 218 | 218 | |
| 219 | - foreach ($errors as $error) { |
|
| 220 | - echo " * $error\n"; |
|
| 221 | - } |
|
| 219 | + foreach ($errors as $error) { |
|
| 220 | + echo " * $error\n"; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - echo "\nYou might want to check tt-rss wiki or the forums for more information.\n"; |
|
| 224 | - echo "Please search the forums before creating new topic for your question.\n"; |
|
| 223 | + echo "\nYou might want to check tt-rss wiki or the forums for more information.\n"; |
|
| 224 | + echo "Please search the forums before creating new topic for your question.\n"; |
|
| 225 | 225 | |
| 226 | - exit(-1); |
|
| 227 | - } |
|
| 228 | - } |
|
| 226 | + exit(-1); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - initial_sanity_check(); |
|
| 230 | + initial_sanity_check(); |
|
| 231 | 231 | |
| 232 | 232 | ?> |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | // TODO: should this support POST requests or not? idk |
| 392 | 392 | |
| 393 | - $context_options = array( |
|
| 394 | - 'http' => array( |
|
| 393 | + $context_options = array( |
|
| 394 | + 'http' => array( |
|
| 395 | 395 | 'header' => array( |
| 396 | 396 | 'Connection: close' |
| 397 | 397 | ), |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | 'ignore_errors' => true, |
| 400 | 400 | 'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT, |
| 401 | 401 | 'protocol_version'=> 1.1) |
| 402 | - ); |
|
| 402 | + ); |
|
| 403 | 403 | |
| 404 | 404 | if (!$post_query && $last_modified) { |
| 405 | 405 | array_push($context_options['http']['header'], "If-Modified-Since: $last_modified"); |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | function logout_user() { |
| 682 | 682 | @session_destroy(); |
| 683 | 683 | if (isset($_COOKIE[session_name()])) { |
| 684 | - setcookie(session_name(), '', time() - 42000, '/'); |
|
| 684 | + setcookie(session_name(), '', time() - 42000, '/'); |
|
| 685 | 685 | } |
| 686 | 686 | session_commit(); |
| 687 | 687 | } |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | if (AUTH_AUTO_LOGIN && authenticate_user(null, null)) { |
| 726 | 726 | $_SESSION["ref_schema_version"] = get_schema_version(true); |
| 727 | 727 | } else { |
| 728 | - authenticate_user(null, null, true); |
|
| 728 | + authenticate_user(null, null, true); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | if (!$_SESSION["uid"]) { |
@@ -1012,9 +1012,9 @@ discard block |
||
| 1012 | 1012 | $params = array(); |
| 1013 | 1013 | |
| 1014 | 1014 | foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS", |
| 1015 | - "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP", |
|
| 1016 | - "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE", |
|
| 1017 | - "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) { |
|
| 1015 | + "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP", |
|
| 1016 | + "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE", |
|
| 1017 | + "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) { |
|
| 1018 | 1018 | |
| 1019 | 1019 | $params[strtolower($param)] = (int) get_pref($param); |
| 1020 | 1020 | } |
@@ -1,80 +1,80 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | function format_backtrace($trace) { |
| 3 | - $rv = ""; |
|
| 4 | - $idx = 1; |
|
| 5 | - |
|
| 6 | - if (is_array($trace)) { |
|
| 7 | - foreach ($trace as $e) { |
|
| 8 | - if (isset($e["file"]) && isset($e["line"])) { |
|
| 9 | - $fmt_args = []; |
|
| 10 | - |
|
| 11 | - if (is_array($e["args"])) { |
|
| 12 | - foreach ($e["args"] as $a) { |
|
| 13 | - if (!is_object($a)) { |
|
| 14 | - array_push($fmt_args, $a); |
|
| 15 | - } else { |
|
| 16 | - array_push($fmt_args, "[".get_class($a)."]"); |
|
| 17 | - } |
|
| 18 | - } |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - $filename = str_replace(dirname(__DIR__)."/", "", $e["file"]); |
|
| 22 | - |
|
| 23 | - $rv .= sprintf("%d. %s(%s): %s(%s)\n", |
|
| 24 | - $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); |
|
| 25 | - |
|
| 26 | - $idx++; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - return $rv; |
|
| 3 | + $rv = ""; |
|
| 4 | + $idx = 1; |
|
| 5 | + |
|
| 6 | + if (is_array($trace)) { |
|
| 7 | + foreach ($trace as $e) { |
|
| 8 | + if (isset($e["file"]) && isset($e["line"])) { |
|
| 9 | + $fmt_args = []; |
|
| 10 | + |
|
| 11 | + if (is_array($e["args"])) { |
|
| 12 | + foreach ($e["args"] as $a) { |
|
| 13 | + if (!is_object($a)) { |
|
| 14 | + array_push($fmt_args, $a); |
|
| 15 | + } else { |
|
| 16 | + array_push($fmt_args, "[".get_class($a)."]"); |
|
| 17 | + } |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + $filename = str_replace(dirname(__DIR__)."/", "", $e["file"]); |
|
| 22 | + |
|
| 23 | + $rv .= sprintf("%d. %s(%s): %s(%s)\n", |
|
| 24 | + $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); |
|
| 25 | + |
|
| 26 | + $idx++; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + return $rv; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function ttrss_error_handler($errno, $errstr, $file, $line, $context) { |
| 35 | - if (error_reporting() == 0 || !$errno) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 35 | + if (error_reporting() == 0 || !$errno) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
| 39 | + $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
| 40 | 40 | |
| 41 | - $context = format_backtrace(debug_backtrace()); |
|
| 42 | - $errstr = truncate_middle($errstr, 16384, " (...) "); |
|
| 41 | + $context = format_backtrace(debug_backtrace()); |
|
| 42 | + $errstr = truncate_middle($errstr, 16384, " (...) "); |
|
| 43 | 43 | |
| 44 | - if (class_exists("Logger")) { |
|
| 45 | - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
| 46 | - } |
|
| 47 | - } |
|
| 44 | + if (class_exists("Logger")) { |
|
| 45 | + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | function ttrss_fatal_handler() { |
| 50 | - global $last_query; |
|
| 50 | + global $last_query; |
|
| 51 | 51 | |
| 52 | - $error = error_get_last(); |
|
| 52 | + $error = error_get_last(); |
|
| 53 | 53 | |
| 54 | - if ($error !== null) { |
|
| 55 | - $errno = $error["type"]; |
|
| 56 | - $file = $error["file"]; |
|
| 57 | - $line = $error["line"]; |
|
| 58 | - $errstr = $error["message"]; |
|
| 54 | + if ($error !== null) { |
|
| 55 | + $errno = $error["type"]; |
|
| 56 | + $file = $error["file"]; |
|
| 57 | + $line = $error["line"]; |
|
| 58 | + $errstr = $error["message"]; |
|
| 59 | 59 | |
| 60 | - if (!$errno) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 60 | + if (!$errno) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $context = format_backtrace(debug_backtrace()); |
|
| 64 | + $context = format_backtrace(debug_backtrace()); |
|
| 65 | 65 | |
| 66 | - $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
| 66 | + $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
| 67 | 67 | |
| 68 | - if ($last_query) { |
|
| 69 | - $errstr .= " [Last query: $last_query]"; |
|
| 70 | - } |
|
| 68 | + if ($last_query) { |
|
| 69 | + $errstr .= " [Last query: $last_query]"; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if (class_exists("Logger")) { |
|
| 73 | - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
| 74 | - } |
|
| 75 | - } |
|
| 72 | + if (class_exists("Logger")) { |
|
| 73 | + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return false; |
|
| 77 | + return false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | register_shutdown_function('ttrss_fatal_handler'); |
@@ -1,38 +1,38 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function db_escape_string($s, $strip_tags = true) { |
| 4 | - return Db::get()->escape_string($s, $strip_tags); |
|
| 4 | + return Db::get()->escape_string($s, $strip_tags); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function db_query($query, $die_on_error = true) { |
| 8 | - return Db::get()->query($query, $die_on_error); |
|
| 8 | + return Db::get()->query($query, $die_on_error); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function db_fetch_assoc($result) { |
| 12 | - return Db::get()->fetch_assoc($result); |
|
| 12 | + return Db::get()->fetch_assoc($result); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | function db_num_rows($result) { |
| 17 | - return Db::get()->num_rows($result); |
|
| 17 | + return Db::get()->num_rows($result); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function db_fetch_result($result, $row, $param) { |
| 21 | - return Db::get()->fetch_result($result, $row, $param); |
|
| 21 | + return Db::get()->fetch_result($result, $row, $param); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function db_affected_rows($result) { |
| 25 | - return Db::get()->affected_rows($result); |
|
| 25 | + return Db::get()->affected_rows($result); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | function db_last_error() { |
| 29 | - return Db::get()->last_error(); |
|
| 29 | + return Db::get()->last_error(); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function db_last_query_error() { |
| 33 | - return Db::get()->last_query_error(); |
|
| 33 | + return Db::get()->last_query_error(); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | function db_quote($str) { |
| 37 | - return Db::get()->quote($str); |
|
| 37 | + return Db::get()->quote($str); |
|
| 38 | 38 | } |
@@ -1,28 +1,28 @@ |
||
| 1 | 1 | <?php |
| 2 | - require_once "functions.php"; |
|
| 2 | + require_once "functions.php"; |
|
| 3 | 3 | |
| 4 | - spl_autoload_register(function($class) { |
|
| 5 | - $namespace = ''; |
|
| 6 | - $class_name = $class; |
|
| 4 | + spl_autoload_register(function($class) { |
|
| 5 | + $namespace = ''; |
|
| 6 | + $class_name = $class; |
|
| 7 | 7 | |
| 8 | - if (strpos($class, '\\') !== false) { |
|
| 9 | - list ($namespace, $class_name) = explode('\\', $class, 2); |
|
| 10 | - } |
|
| 8 | + if (strpos($class, '\\') !== false) { |
|
| 9 | + list ($namespace, $class_name) = explode('\\', $class, 2); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
| 12 | + $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
| 13 | 13 | |
| 14 | - // 1. third party libraries with namespaces are loaded from vendor/ |
|
| 15 | - // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
| 16 | - // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
| 14 | + // 1. third party libraries with namespaces are loaded from vendor/ |
|
| 15 | + // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
| 16 | + // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
| 17 | 17 | |
| 18 | - if ($namespace && $class_name) { |
|
| 19 | - $class_file = "$root_dir/vendor/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
| 20 | - } else { |
|
| 21 | - $class_file = "$root_dir/classes/".str_replace("_", "/", strtolower($class)).".php"; |
|
| 22 | - } |
|
| 18 | + if ($namespace && $class_name) { |
|
| 19 | + $class_file = "$root_dir/vendor/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
| 20 | + } else { |
|
| 21 | + $class_file = "$root_dir/classes/".str_replace("_", "/", strtolower($class)).".php"; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - if (file_exists($class_file)) { |
|
| 25 | - include $class_file; |
|
| 26 | - } |
|
| 24 | + if (file_exists($class_file)) { |
|
| 25 | + include $class_file; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - }); |
|
| 28 | + }); |
|