opml.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. class Opml extends Handler_Protected {
  3. function csrf_ignore($method) {
  4. $csrf_ignored = array("export", "import");
  5. return array_search($method, $csrf_ignored) !== false;
  6. }
  7. function export() {
  8. $output_name = "tt-rss_".date("Y-m-d").".opml";
  9. $include_settings = $_REQUEST["include_settings"] == "1";
  10. $owner_uid = $_SESSION["uid"];
  11. $rc = $this->opml_export($output_name, $owner_uid, false, $include_settings);
  12. return $rc;
  13. }
  14. function import() {
  15. $owner_uid = $_SESSION["uid"];
  16. header('Content-Type: text/html; charset=utf-8');
  17. print "<html>
  18. <head>
  19. ".stylesheet_tag("css/default.css")."
  20. <title>".__("OPML Utility")."</title>
  21. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  22. </head>
  23. <body class='claro ttrss_utility'>
  24. <h1>".__('OPML Utility')."</h1><div class='content'>";
  25. Feeds::add_feed_category("Imported feeds");
  26. $this->opml_notice(__("Importing OPML..."));
  27. $this->opml_import($owner_uid);
  28. print "<br><form method=\"GET\" action=\"prefs.php\">
  29. <input type=\"submit\" value=\"".__("Return to preferences")."\">
  30. </form>";
  31. print "</div></body></html>";
  32. }
  33. // Export
  34. private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds = false, $include_settings = true) {
  35. $cat_id = (int) $cat_id;
  36. if ($hide_private_feeds)
  37. $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')";
  38. else
  39. $hide_qpart = "true";
  40. $out = "";
  41. $ttrss_specific_qpart = "";
  42. if ($cat_id) {
  43. $sth = $this->pdo->prepare("SELECT title,order_id
  44. FROM ttrss_feed_categories WHERE id = ?
  45. AND owner_uid = ?");
  46. $sth->execute([$cat_id, $owner_uid]);
  47. $row = $sth->fetch();
  48. $cat_title = htmlspecialchars($row['title']);
  49. if ($include_settings) {
  50. $order_id = (int)$row["order_id"];
  51. $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\"";
  52. }
  53. } else {
  54. $cat_title = "";
  55. }
  56. if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n";
  57. $sth = $this->pdo->prepare("SELECT id,title
  58. FROM ttrss_feed_categories WHERE
  59. (parent_cat = :cat OR (:cat = 0 AND parent_cat IS NULL)) AND
  60. owner_uid = :uid ORDER BY order_id, title");
  61. $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]);
  62. while ($line = $sth->fetch()) {
  63. $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings);
  64. }
  65. $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id
  66. FROM ttrss_feeds WHERE
  67. (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart
  68. ORDER BY order_id, title");
  69. $fsth->execute([':cat' => $cat_id, ':uid' => $owner_uid]);
  70. while ($fline = $fsth->fetch()) {
  71. $title = htmlspecialchars($fline["title"]);
  72. $url = htmlspecialchars($fline["feed_url"]);
  73. $site_url = htmlspecialchars($fline["site_url"]);
  74. if ($include_settings) {
  75. $update_interval = (int)$fline["update_interval"];
  76. $order_id = (int)$fline["order_id"];
  77. $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\"";
  78. } else {
  79. $ttrss_specific_qpart = "";
  80. }
  81. if ($site_url) {
  82. $html_url_qpart = "htmlUrl=\"$site_url\"";
  83. } else {
  84. $html_url_qpart = "";
  85. }
  86. $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n";
  87. }
  88. if ($cat_title) $out .= "</outline>\n";
  89. return $out;
  90. }
  91. function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) {
  92. if (!$owner_uid) return;
  93. if (!isset($_REQUEST["debug"])) {
  94. header("Content-type: application/xml+opml");
  95. header("Content-Disposition: attachment; filename=" . $name );
  96. } else {
  97. header("Content-type: text/xml");
  98. }
  99. $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">";
  100. $out .= "<opml version=\"1.0\">";
  101. $out .= "<head>
  102. <dateCreated>" . date("r", time()) . "</dateCreated>
  103. <title>Tiny Tiny RSS Feed Export</title>
  104. </head>";
  105. $out .= "<body>";
  106. $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings);
  107. # export tt-rss settings
  108. if ($include_settings) {
  109. $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">";
  110. $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE
  111. profile IS NULL AND owner_uid = ? ORDER BY pref_name");
  112. $sth->execute([$owner_uid]);
  113. while ($line = $sth->fetch()) {
  114. $name = $line["pref_name"];
  115. $value = htmlspecialchars($line["value"]);
  116. $out .= "<outline pref-name=\"$name\" value=\"$value\"/>";
  117. }
  118. $out .= "</outline>";
  119. $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">";
  120. $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE
  121. owner_uid = ?");
  122. $sth->execute([$owner_uid]);
  123. while ($line = $sth->fetch()) {
  124. $name = htmlspecialchars($line['caption']);
  125. $fg_color = htmlspecialchars($line['fg_color']);
  126. $bg_color = htmlspecialchars($line['bg_color']);
  127. $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>";
  128. }
  129. $out .= "</outline>";
  130. $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">";
  131. $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2
  132. WHERE owner_uid = ? ORDER BY id");
  133. $sth->execute([$owner_uid]);
  134. while ($line = $sth->fetch()) {
  135. $line["rules"] = array();
  136. $line["actions"] = array();
  137. $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules
  138. WHERE filter_id = ?");
  139. $tmph->execute([$line['id']]);
  140. while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) {
  141. unset($tmp_line["id"]);
  142. unset($tmp_line["filter_id"]);
  143. $cat_filter = $tmp_line["cat_filter"];
  144. if (!$tmp_line["match_on"]) {
  145. if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
  146. $tmp_line["feed"] = Feeds::getFeedTitle(
  147. $cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
  148. $cat_filter);
  149. } else {
  150. $tmp_line["feed"] = "";
  151. }
  152. } else {
  153. $match = [];
  154. foreach (json_decode($tmp_line["match_on"], true) as $feed_id) {
  155. if (strpos($feed_id, "CAT:") === 0) {
  156. $feed_id = (int)substr($feed_id, 4);
  157. if ($feed_id) {
  158. array_push($match, [Feeds::getCategoryTitle($feed_id), true, false]);
  159. } else {
  160. array_push($match, [0, true, true]);
  161. }
  162. } else {
  163. if ($feed_id) {
  164. array_push($match, [Feeds::getFeedTitle((int)$feed_id), false, false]);
  165. } else {
  166. array_push($match, [0, false, true]);
  167. }
  168. }
  169. }
  170. $tmp_line["match"] = $match;
  171. unset($tmp_line["match_on"]);
  172. }
  173. unset($tmp_line["feed_id"]);
  174. unset($tmp_line["cat_id"]);
  175. array_push($line["rules"], $tmp_line);
  176. }
  177. $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions
  178. WHERE filter_id = ?");
  179. $tmph->execute([$line['id']]);
  180. while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) {
  181. unset($tmp_line["id"]);
  182. unset($tmp_line["filter_id"]);
  183. array_push($line["actions"], $tmp_line);
  184. }
  185. unset($line["id"]);
  186. unset($line["owner_uid"]);
  187. $filter = json_encode($line);
  188. $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>";
  189. }
  190. $out .= "</outline>";
  191. }
  192. $out .= "</body></opml>";
  193. // Format output.
  194. $doc = new DOMDocument();
  195. $doc->formatOutput = true;
  196. $doc->preserveWhiteSpace = false;
  197. $doc->loadXML($out);
  198. $xpath = new DOMXpath($doc);
  199. $outlines = $xpath->query("//outline[@title]");
  200. // cleanup empty categories
  201. foreach ($outlines as $node) {
  202. if ($node->getElementsByTagName('outline')->length == 0)
  203. $node->parentNode->removeChild($node);
  204. }
  205. $res = $doc->saveXML();
  206. /* // saveXML uses a two-space indent. Change to tabs.
  207. $res = preg_replace_callback('/^(?: )+/mu',
  208. create_function(
  209. '$matches',
  210. 'return str_repeat("\t", intval(strlen($matches[0])/2));'),
  211. $res); */
  212. print $res;
  213. }
  214. // Import
  215. private function opml_import_feed($node, $cat_id, $owner_uid) {
  216. $attrs = $node->attributes;
  217. $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250);
  218. if (!$feed_title) $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250);
  219. $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue;
  220. if (!$feed_url) $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue;
  221. $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250);
  222. if ($feed_url) {
  223. $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
  224. feed_url = ? AND owner_uid = ?");
  225. $sth->execute([$feed_url, $owner_uid]);
  226. if (!$feed_title) $feed_title = '[Unknown]';
  227. if (!$sth->fetch()) {
  228. #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id");
  229. $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title));
  230. if (!$cat_id) $cat_id = null;
  231. $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue;
  232. if (!$update_interval) $update_interval = 0;
  233. $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue;
  234. if (!$order_id) $order_id = 0;
  235. $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
  236. (title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES
  237. (?, ?, ?, ?, ?, ?, ?)");
  238. $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]);
  239. } else {
  240. $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title));
  241. }
  242. }
  243. }
  244. private function opml_import_label($node, $owner_uid) {
  245. $attrs = $node->attributes;
  246. $label_name = $attrs->getNamedItem('label-name')->nodeValue;
  247. if ($label_name) {
  248. $fg_color = $attrs->getNamedItem('label-fg-color')->nodeValue;
  249. $bg_color = $attrs->getNamedItem('label-bg-color')->nodeValue;
  250. if (!Labels::find_id($label_name, $_SESSION['uid'])) {
  251. $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name)));
  252. Labels::create($label_name, $fg_color, $bg_color, $owner_uid);
  253. } else {
  254. $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name)));
  255. }
  256. }
  257. }
  258. private function opml_import_preference($node) {
  259. $attrs = $node->attributes;
  260. $pref_name = $attrs->getNamedItem('pref-name')->nodeValue;
  261. if ($pref_name) {
  262. $pref_value = $attrs->getNamedItem('value')->nodeValue;
  263. $this->opml_notice(T_sprintf("Setting preference key %s to %s",
  264. $pref_name, $pref_value));
  265. set_pref($pref_name, $pref_value);
  266. }
  267. }
  268. private function opml_import_filter($node) {
  269. $attrs = $node->attributes;
  270. $filter_type = $attrs->getNamedItem('filter-type')->nodeValue;
  271. if ($filter_type == '2') {
  272. $filter = json_decode($node->nodeValue, true);
  273. if ($filter) {
  274. $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]);
  275. $enabled = bool_to_sql_bool($filter["enabled"]);
  276. $inverse = bool_to_sql_bool($filter["inverse"]);
  277. $title = $filter["title"];
  278. //print "F: $title, $inverse, $enabled, $match_any_rule";
  279. $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 (match_any_rule,enabled,inverse,title,owner_uid)
  280. VALUES (?, ?, ?, ?, ?)");
  281. $sth->execute([$match_any_rule, $enabled, $inverse, $title, $_SESSION['uid']]);
  282. $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE
  283. owner_uid = ?");
  284. $sth->execute([$_SESSION['uid']]);
  285. $row = $sth->fetch();
  286. $filter_id = $row['id'];
  287. if ($filter_id) {
  288. $this->opml_notice(T_sprintf("Adding filter %s...", $title));
  289. foreach ($filter["rules"] as $rule) {
  290. $feed_id = null;
  291. $cat_id = null;
  292. if ($rule["match"]) {
  293. $match_on = [];
  294. foreach ($rule["match"] as $match) {
  295. list ($name, $is_cat, $is_id) = $match;
  296. if ($is_id) {
  297. array_push($match_on, ($is_cat ? "CAT:" : "") . $name);
  298. } else {
  299. if (!$is_cat) {
  300. $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
  301. WHERE title = ? AND owner_uid = ?");
  302. $tsth->execute([$name, $_SESSION['uid']]);
  303. if ($row = $tsth->fetch()) {
  304. $match_id = $row['id'];
  305. array_push($match_on, $match_id);
  306. }
  307. } else {
  308. $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
  309. WHERE title = ? AND owner_uid = ?");
  310. $tsth->execute([$name, $_SESSION['uid']]);
  311. if ($row = $tsth->fetch()) {
  312. $match_id = $row['id'];
  313. array_push($match_on, "CAT:$match_id");
  314. }
  315. }
  316. }
  317. }
  318. $reg_exp = $rule["reg_exp"];
  319. $filter_type = (int)$rule["filter_type"];
  320. $inverse = bool_to_sql_bool($rule["inverse"]);
  321. $match_on = json_encode($match_on);
  322. $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
  323. (feed_id,cat_id,match_on,filter_id,filter_type,reg_exp,cat_filter,inverse)
  324. VALUES
  325. (NULL, NULL, ?, ?, ?, ?, false, ?)");
  326. $usth->execute([$match_on, $filter_id, $filter_type, $reg_exp, $inverse]);
  327. } else {
  328. if (!$rule["cat_filter"]) {
  329. $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
  330. WHERE title = ? AND owner_uid = ?");
  331. $tsth->execute([$rule['feed'], $_SESSION['uid']]);
  332. if ($row = $tsth->fetch()) {
  333. $feed_id = $row['id'];
  334. }
  335. } else {
  336. $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
  337. WHERE title = ? AND owner_uid = ?");
  338. $tsth->execute([$rule['feed'], $_SESSION['uid']]);
  339. if ($row = $tsth->fetch()) {
  340. $feed_id = $row['id'];
  341. }
  342. }
  343. $cat_filter = bool_to_sql_bool($rule["cat_filter"]);
  344. $reg_exp = $rule["reg_exp"];
  345. $filter_type = (int)$rule["filter_type"];
  346. $inverse = bool_to_sql_bool($rule["inverse"]);
  347. $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
  348. (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter,inverse)
  349. VALUES
  350. (?, ?, ?, ?, ?, ?, ?)");
  351. $usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]);
  352. }
  353. }
  354. foreach ($filter["actions"] as $action) {
  355. $action_id = (int)$action["action_id"];
  356. $action_param = $action["action_param"];
  357. $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions
  358. (filter_id,action_id,action_param)
  359. VALUES
  360. (?, ?, ?)");
  361. $usth->execute([$filter_id, $action_id, $action_param]);
  362. }
  363. }
  364. }
  365. }
  366. }
  367. private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
  368. $default_cat_id = (int) $this->get_feed_category('Imported feeds', false);
  369. if ($root_node) {
  370. $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250);
  371. if (!$cat_title)
  372. $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250);
  373. if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) {
  374. $cat_id = $this->get_feed_category($cat_title, $parent_id);
  375. if ($cat_id === false) {
  376. $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue;
  377. if (!$order_id) $order_id = 0;
  378. Feeds::add_feed_category($cat_title, $parent_id, $order_id);
  379. $cat_id = $this->get_feed_category($cat_title, $parent_id);
  380. }
  381. } else {
  382. $cat_id = 0;
  383. }
  384. $outlines = $root_node->childNodes;
  385. } else {
  386. $xpath = new DOMXpath($doc);
  387. $outlines = $xpath->query("//opml/body/outline");
  388. $cat_id = 0;
  389. }
  390. #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id");
  391. $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized")));
  392. foreach ($outlines as $node) {
  393. if ($node->hasAttributes() && strtolower($node->tagName) == "outline") {
  394. $attrs = $node->attributes;
  395. $node_cat_title = $attrs->getNamedItem('text')->nodeValue;
  396. if (!$node_cat_title)
  397. $node_cat_title = $attrs->getNamedItem('title')->nodeValue;
  398. $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue;
  399. if ($node_cat_title && !$node_feed_url) {
  400. $this->opml_import_category($doc, $node, $owner_uid, $cat_id);
  401. } else {
  402. if (!$cat_id) {
  403. $dst_cat_id = $default_cat_id;
  404. } else {
  405. $dst_cat_id = $cat_id;
  406. }
  407. switch ($cat_title) {
  408. case "tt-rss-prefs":
  409. $this->opml_import_preference($node);
  410. break;
  411. case "tt-rss-labels":
  412. $this->opml_import_label($node, $owner_uid);
  413. break;
  414. case "tt-rss-filters":
  415. $this->opml_import_filter($node);
  416. break;
  417. default:
  418. $this->opml_import_feed($node, $dst_cat_id, $owner_uid);
  419. }
  420. }
  421. }
  422. }
  423. }
  424. function opml_import($owner_uid) {
  425. if (!$owner_uid) return;
  426. $doc = false;
  427. if ($_FILES['opml_file']['error'] != 0) {
  428. print_error(T_sprintf("Upload failed with error code %d",
  429. $_FILES['opml_file']['error']));
  430. return;
  431. }
  432. if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
  433. $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml');
  434. $result = move_uploaded_file($_FILES['opml_file']['tmp_name'],
  435. $tmp_file);
  436. if (!$result) {
  437. print_error(__("Unable to move uploaded file."));
  438. return;
  439. }
  440. } else {
  441. print_error(__('Error: please upload OPML file.'));
  442. return;
  443. }
  444. if (is_file($tmp_file)) {
  445. $doc = new DOMDocument();
  446. libxml_disable_entity_loader(false);
  447. $doc->load($tmp_file);
  448. libxml_disable_entity_loader(true);
  449. unlink($tmp_file);
  450. } else if (!$doc) {
  451. print_error(__('Error: unable to find moved OPML file.'));
  452. return;
  453. }
  454. if ($doc) {
  455. $this->pdo->beginTransaction();
  456. $this->opml_import_category($doc, false, $owner_uid, false);
  457. $this->pdo->commit();
  458. } else {
  459. print_error(__('Error while parsing document.'));
  460. }
  461. }
  462. private function opml_notice($msg) {
  463. print "$msg<br/>";
  464. }
  465. static function opml_publish_url(){
  466. $url_path = get_self_url_prefix();
  467. $url_path .= "/opml.php?op=publish&key=" .
  468. Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]);
  469. return $url_path;
  470. }
  471. function get_feed_category($feed_cat, $parent_cat_id = false) {
  472. $parent_cat_id = (int) $parent_cat_id;
  473. $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
  474. WHERE title = :title
  475. AND (parent_cat = :parent OR (:parent = 0 AND parent_cat IS NULL))
  476. AND owner_uid = :uid");
  477. $sth->execute([':title' => $feed_cat, ':parent' => $parent_cat_id, ':uid' => $_SESSION['uid']]);
  478. if ($row = $sth->fetch()) {
  479. return $row['id'];
  480. } else {
  481. return false;
  482. }
  483. }
  484. }