backend.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  3. require_once "sessions.php";
  4. require_once "modules/backend-rpc.php";
  5. /* if ($_GET["debug"]) {
  6. define('DEFAULT_ERROR_LEVEL', E_ALL);
  7. } else {
  8. define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
  9. }
  10. error_reporting(DEFAULT_ERROR_LEVEL); */
  11. define('SCHEMA_VERSION', 13);
  12. require_once "sanity_check.php";
  13. require_once "config.php";
  14. require_once "db.php";
  15. require_once "db-prefs.php";
  16. require_once "functions.php";
  17. no_cache_incantation();
  18. $script_started = getmicrotime();
  19. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  20. if (!$link) {
  21. if (DB_TYPE == "mysql") {
  22. print mysql_error();
  23. }
  24. // PG seems to display its own errors just fine by default.
  25. return;
  26. }
  27. if (DB_TYPE == "pgsql") {
  28. pg_query("set client_encoding = 'UTF-8'");
  29. pg_set_client_encoding("UNICODE");
  30. }
  31. $op = $_REQUEST["op"];
  32. $print_exec_time = false;
  33. if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" ||
  34. $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
  35. header("Content-Type: application/xml; charset=utf-8");
  36. } else {
  37. header("Content-Type: text/html; charset=utf-8");
  38. }
  39. if (!$op) {
  40. header("Content-Type: application/xml");
  41. print_error_xml(7); exit;
  42. }
  43. if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
  44. && $op != "rss" && $op != "getUnread") {
  45. if ($op == "rpc") {
  46. print_error_xml(6); die;
  47. } else {
  48. print "
  49. <html><body>
  50. <p>Error: Not logged in.</p>
  51. <script type=\"text/javascript\">
  52. if (parent.window != 'undefined') {
  53. parent.window.location = \"tt-rss.php\";
  54. } else {
  55. window.location = \"tt-rss.php\";
  56. }
  57. </script>
  58. </body></html>
  59. ";
  60. }
  61. exit;
  62. }
  63. $purge_intervals = array(
  64. 0 => __("Use default"),
  65. -1 => __("Never purge"),
  66. 5 => __("1 week old"),
  67. 14 => __("2 weeks old"),
  68. 31 => __("1 month old"),
  69. 60 => __("2 months old"),
  70. 90 => __("3 months old"));
  71. $update_intervals = array(
  72. 0 => __("Use default"),
  73. -1 => __("Disable updates"),
  74. 30 => __("Each 30 minutes"),
  75. 60 => __("Hourly"),
  76. 240 => __("Each 4 hours"),
  77. 720 => __("Each 12 hours"),
  78. 1440 => __("Daily"),
  79. 10080 => __("Weekly"));
  80. $access_level_names = array(
  81. 0 => __("User"),
  82. 10 => __("Administrator"));
  83. require_once "modules/pref-prefs.php";
  84. require_once "modules/popup-dialog.php";
  85. require_once "modules/help.php";
  86. require_once "modules/pref-feeds.php";
  87. require_once "modules/pref-filters.php";
  88. require_once "modules/pref-labels.php";
  89. require_once "modules/pref-users.php";
  90. require_once "modules/pref-feed-browser.php";
  91. if (!sanity_check($link)) { return; }
  92. if ($op == "rpc") {
  93. handle_rpc_request($link);
  94. }
  95. if ($op == "feeds") {
  96. $tags = $_GET["tags"];
  97. $subop = $_GET["subop"];
  98. if ($subop == "catchupAll") {
  99. db_query($link, "UPDATE ttrss_user_entries SET
  100. last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
  101. }
  102. if ($subop == "collapse") {
  103. $cat_id = db_escape_string($_GET["cid"]);
  104. db_query($link, "UPDATE ttrss_feed_categories SET
  105. collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
  106. $_SESSION["uid"]);
  107. return;
  108. }
  109. outputFeedList($link, $tags);
  110. }
  111. if ($op == "view") {
  112. $id = db_escape_string($_GET["id"]);
  113. $feed_id = db_escape_string($_GET["feed"]);
  114. $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
  115. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  116. if (db_num_rows($result) == 1) {
  117. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  118. } else {
  119. $rtl_content = false;
  120. }
  121. if ($rtl_content) {
  122. $rtl_tag = "dir=\"RTL\"";
  123. $rtl_class = "RTL";
  124. } else {
  125. $rtl_tag = "";
  126. $rtl_class = "";
  127. }
  128. $result = db_query($link, "UPDATE ttrss_user_entries
  129. SET unread = false,last_read = NOW()
  130. WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  131. $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
  132. SUBSTRING(updated,1,16) as updated,
  133. (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
  134. num_comments,
  135. author
  136. FROM ttrss_entries,ttrss_user_entries
  137. WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
  138. if ($result) {
  139. $link_target = "";
  140. if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
  141. $link_target = "target=\"_new\"";
  142. }
  143. $line = db_fetch_assoc($result);
  144. if ($line["icon_url"]) {
  145. $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
  146. } else {
  147. $feed_icon = "&nbsp;";
  148. }
  149. /* if ($line["comments"] && $line["link"] != $line["comments"]) {
  150. $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
  151. } else {
  152. $entry_comments = "";
  153. } */
  154. $num_comments = $line["num_comments"];
  155. $entry_comments = "";
  156. if ($num_comments > 0) {
  157. if ($line["comments"]) {
  158. $comments_url = $line["comments"];
  159. } else {
  160. $comments_url = $line["link"];
  161. }
  162. $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
  163. } else {
  164. if ($line["comments"] && $line["link"] != $line["comments"]) {
  165. $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
  166. }
  167. }
  168. print "<div class=\"postReply\">";
  169. print "<div class=\"postHeader\">";
  170. $entry_author = $line["author"];
  171. if ($entry_author) {
  172. $entry_author = __(" - by ") . $entry_author;
  173. }
  174. $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
  175. strtotime($line["updated"]));
  176. print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
  177. if ($line["link"]) {
  178. print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
  179. $line["title"] . "</a>$entry_author</div>";
  180. } else {
  181. print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
  182. }
  183. $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
  184. ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
  185. ORDER BY tag_name");
  186. $tags_str = "";
  187. $f_tags_str = "";
  188. $num_tags = 0;
  189. while ($tmp_line = db_fetch_assoc($tmp_result)) {
  190. $num_tags++;
  191. $tag = $tmp_line["tag_name"];
  192. $tag_str = "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
  193. if ($num_tags == 6) {
  194. $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
  195. } else if ($num_tags < 6) {
  196. $tags_str .= $tag_str;
  197. }
  198. $f_tags_str .= $tag_str;
  199. }
  200. $tags_str = preg_replace("/, $/", "", $tags_str);
  201. $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
  202. if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
  203. if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
  204. print "<div style='float : right'>$tags_str
  205. <a title=\"Edit tags for this article\"
  206. href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
  207. <div clear='both'>$entry_comments</div>";
  208. print "</div>";
  209. print "<div class=\"postIcon\">" . $feed_icon . "</div>";
  210. print "<div class=\"postContent\">";
  211. if (db_num_rows($tmp_result) > 0) {
  212. print "<div id=\"allEntryTags\">".__('Tags:')."$f_tags_str</div>";
  213. }
  214. if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
  215. $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
  216. }
  217. $line["content"] = sanitize_rss($line["content"]);
  218. print $line["content"] . "</div>";
  219. print "</div>";
  220. }
  221. }
  222. if ($op == "viewfeed") {
  223. $feed = db_escape_string($_GET["feed"]);
  224. $subop = db_escape_string($_GET["subop"]);
  225. $view_mode = db_escape_string($_GET["view_mode"]);
  226. $limit = db_escape_string($_GET["limit"]);
  227. $cat_view = db_escape_string($_GET["cat"]);
  228. $next_unread_feed = db_escape_string($_GET["nuf"]);
  229. $offset = db_escape_string($_GET["skip"]);
  230. if (!$offset) $offset = 0;
  231. if ($subop == "undefined") $subop = "";
  232. if ($subop == "CatchupSelected") {
  233. $ids = split(",", db_escape_string($_GET["ids"]));
  234. $cmode = sprintf("%d", $_GET["cmode"]);
  235. catchupArticlesById($link, $ids, $cmode);
  236. }
  237. if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
  238. update_generic_feed($link, $feed, $cat_view);
  239. }
  240. if ($subop == "MarkAllRead") {
  241. catchup_feed($link, $feed, $cat_view);
  242. if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
  243. if ($next_unread_feed) {
  244. $feed = $next_unread_feed;
  245. }
  246. }
  247. }
  248. if ($feed_id > 0) {
  249. $result = db_query($link,
  250. "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
  251. if (db_num_rows($result) == 0) {
  252. print "<div align='center'>".__('Feed not found.')."</div>";
  253. return;
  254. }
  255. }
  256. if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
  257. $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
  258. WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
  259. if (db_num_rows($result) == 1) {
  260. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  261. } else {
  262. $rtl_content = false;
  263. }
  264. if ($rtl_content) {
  265. $rtl_tag = "dir=\"RTL\"";
  266. } else {
  267. $rtl_tag = "";
  268. }
  269. } else {
  270. $rtl_tag = "";
  271. $rtl_content = false;
  272. }
  273. $script_dt_add = get_script_dt_add();
  274. /* print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  275. <script type=\"text/javascript\" src=\"prototype.js\"></script>
  276. <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
  277. <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
  278. <!--[if gte IE 5.5000]>
  279. <script type=\"text/javascript\" src=\"pngfix.js\"></script>
  280. <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
  281. <![endif]-->
  282. </head><body $rtl_tag>
  283. <script type=\"text/javascript\">
  284. if (document.addEventListener) {
  285. document.addEventListener(\"DOMContentLoaded\", init, null);
  286. }
  287. window.onload = init;
  288. </script>"; */
  289. /// START /////////////////////////////////////////////////////////////////////////////////
  290. $search = db_escape_string($_GET["query"]);
  291. $search_mode = db_escape_string($_GET["search_mode"]);
  292. $match_on = db_escape_string($_GET["match_on"]);
  293. if (!$match_on) {
  294. $match_on = "both";
  295. }
  296. $real_offset = $offset * $limit;
  297. $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
  298. $search, $search_mode, $match_on, false, $real_offset);
  299. $result = $qfh_ret[0];
  300. $feed_title = $qfh_ret[1];
  301. $feed_site_url = $qfh_ret[2];
  302. $last_error = $qfh_ret[3];
  303. /// STOP //////////////////////////////////////////////////////////////////////////////////
  304. print "<div id=\"headlinesContainer\" $rtl_tag>";
  305. if (!$result) {
  306. print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
  307. return;
  308. }
  309. print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
  310. $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
  311. $offset, $limit);
  312. print "<div id=\"headlinesInnerContainer\">";
  313. if (db_num_rows($result) > 0) {
  314. # print "\{$offset}";
  315. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  316. print "<table class=\"headlinesList\" id=\"headlinesList\"
  317. cellspacing=\"0\" width=\"100%\">";
  318. }
  319. $lnum = 0;
  320. error_reporting (DEFAULT_ERROR_LEVEL);
  321. $num_unread = 0;
  322. while ($line = db_fetch_assoc($result)) {
  323. $class = ($lnum % 2) ? "even" : "odd";
  324. $id = $line["id"];
  325. $feed_id = $line["feed_id"];
  326. if ($line["last_read"] == "" &&
  327. ($line["unread"] != "t" && $line["unread"] != "1")) {
  328. $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
  329. alt=\"Updated\">";
  330. } else {
  331. $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
  332. alt=\"Updated\">";
  333. }
  334. if ($line["unread"] == "t" || $line["unread"] == "1") {
  335. $class .= "Unread";
  336. ++$num_unread;
  337. $is_unread = true;
  338. } else {
  339. $is_unread = false;
  340. }
  341. if ($line["marked"] == "t" || $line["marked"] == "1") {
  342. $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
  343. class=\"markedPic\"
  344. alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
  345. } else {
  346. $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
  347. class=\"markedPic\"
  348. alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
  349. }
  350. # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
  351. # $line["title"] . "</a>";
  352. $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
  353. $line["title"] . "</a>";
  354. # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
  355. # $line["title"] . "</a>";
  356. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  357. $updated_fmt = smart_date_time(strtotime($line["updated"]));
  358. } else {
  359. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  360. $updated_fmt = date($short_date, strtotime($line["updated"]));
  361. }
  362. if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
  363. $content_preview = truncate_string(strip_tags($line["content_preview"]),
  364. 100);
  365. }
  366. $entry_author = $line["author"];
  367. if ($entry_author) {
  368. $entry_author = " - by $entry_author";
  369. }
  370. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  371. print "<tr class='$class' id='RROW-$id'>";
  372. print "<td class='hlUpdatePic'>$update_pic</td>";
  373. print "<td class='hlSelectRow'>
  374. <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
  375. class=\"feedCheckBox\" id=\"RCHK-$id\">
  376. </td>";
  377. print "<td class='hlMarkedPic'>$marked_pic</td>";
  378. if ($line["feed_title"]) {
  379. print "<td class='hlContent'>$content_link</td>";
  380. print "<td class='hlFeed'>
  381. <a href=\"javascript:viewfeed($feed_id, '', false)\">".
  382. $line["feed_title"]."</a>&nbsp;</td>";
  383. } else {
  384. print "<td class='hlContent' valign='middle'>";
  385. print "<a href=\"javascript:view($id,$feed_id);\">" .
  386. $line["title"];
  387. if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
  388. if ($content_preview) {
  389. print "<span class=\"contentPreview\"> - $content_preview</span>";
  390. }
  391. }
  392. print "</a>";
  393. print "</td>";
  394. }
  395. print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
  396. print "</tr>";
  397. } else {
  398. if ($is_unread) {
  399. $add_class = "Unread";
  400. } else {
  401. $add_class = "";
  402. }
  403. print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
  404. print "<div class=\"cdmHeader\">";
  405. print "<div class=\"articleUpdated\">$updated_fmt</div>";
  406. print "<a class=\"title\"
  407. onclick=\"javascript:toggleUnread($id, 0)\"
  408. target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
  409. print $entry_author;
  410. if ($line["feed_title"]) {
  411. print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
  412. }
  413. print "</div>";
  414. print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
  415. print "<div class=\"cdmFooter\">";
  416. print "$marked_pic";
  417. print "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
  418. 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
  419. $tags = get_article_tags($link, $id);
  420. $tags_str = "";
  421. foreach ($tags as $tag) {
  422. $num_tags++;
  423. $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
  424. }
  425. $tags_str = preg_replace("/, $/", "", $tags_str);
  426. if ($tags_str == "") $tags_str = "no tags";
  427. print " $tags_str <a title=\"Edit tags for this article\"
  428. href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
  429. print "</div>";
  430. # print "<div align=\"center\"><a class=\"cdmToggleLink\"
  431. # href=\"javascript:toggleUnread($id)\">
  432. # Toggle unread</a></div>";
  433. print "</div>";
  434. }
  435. ++$lnum;
  436. }
  437. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  438. print "</table>";
  439. }
  440. // print_headline_subtoolbar($link,
  441. // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
  442. } else {
  443. print "<div class='whiteBox'>".__('No articles found.')."</div>";
  444. }
  445. print "</div>";
  446. print "</div>";
  447. }
  448. if ($op == "pref-feeds") {
  449. module_pref_feeds($link);
  450. }
  451. if ($op == "pref-filters") {
  452. module_pref_filters($link);
  453. }
  454. if ($op == "pref-labels") {
  455. module_pref_labels($link);
  456. }
  457. if ($op == "pref-prefs") {
  458. module_pref_prefs($link);
  459. }
  460. if ($op == "pref-users") {
  461. module_pref_users($link);
  462. }
  463. if ($op == "help") {
  464. module_help($link);
  465. }
  466. if ($op == "dlg") {
  467. module_popup_dialog($link);
  468. }
  469. // update feeds of all users, may be used anonymously
  470. if ($op == "globalUpdateFeeds") {
  471. $result = db_query($link, "SELECT id FROM ttrss_users");
  472. while ($line = db_fetch_assoc($result)) {
  473. $user_id = $line["id"];
  474. // print "<!-- updating feeds of uid $user_id -->";
  475. update_all_feeds($link, false, $user_id);
  476. }
  477. print "<rpc-reply>
  478. <message msg=\"All feeds updated\"/>
  479. </rpc-reply>";
  480. }
  481. if ($op == "user-details") {
  482. if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
  483. return;
  484. }
  485. /* print "<html><head>
  486. <title>Tiny Tiny RSS : User Details</title>
  487. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
  488. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  489. </head><body>"; */
  490. $uid = sprintf("%d", $_GET["id"]);
  491. print "<div id=\"infoBoxTitle\">User details</div>";
  492. print "<div class='infoBoxContents'>";
  493. $result = db_query($link, "SELECT login,
  494. SUBSTRING(last_login,1,16) AS last_login,
  495. access_level,
  496. (SELECT COUNT(int_id) FROM ttrss_user_entries
  497. WHERE owner_uid = id) AS stored_articles
  498. FROM ttrss_users
  499. WHERE id = '$uid'");
  500. if (db_num_rows($result) == 0) {
  501. print "<h1>User not found</h1>";
  502. return;
  503. }
  504. # print "<h1>User Details</h1>";
  505. $login = db_fetch_result($result, 0, "login");
  506. # print "<h1>$login</h1>";
  507. print "<table width='100%'>";
  508. $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
  509. strtotime(db_fetch_result($result, 0, "last_login")));
  510. $access_level = db_fetch_result($result, 0, "access_level");
  511. $stored_articles = db_fetch_result($result, 0, "stored_articles");
  512. # print "<tr><td>Username</td><td>$login</td></tr>";
  513. # print "<tr><td>Access level</td><td>$access_level</td></tr>";
  514. print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
  515. print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
  516. $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
  517. WHERE owner_uid = '$uid'");
  518. $num_feeds = db_fetch_result($result, 0, "num_feeds");
  519. print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
  520. /* $result = db_query($link, "SELECT
  521. SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
  522. FROM ttrss_user_entries,ttrss_entries
  523. WHERE owner_uid = '$uid' AND ref_id = id");
  524. $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
  525. print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
  526. print "</table>";
  527. print "<h1>Subscribed feeds</h1>";
  528. $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
  529. WHERE owner_uid = '$uid' ORDER BY title");
  530. print "<ul class=\"userFeedList\">";
  531. $row_class = "odd";
  532. while ($line = db_fetch_assoc($result)) {
  533. $icon_file = ICONS_URL."/".$line["id"].".ico";
  534. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  535. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
  536. } else {
  537. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
  538. }
  539. print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
  540. $row_class = toggleEvenOdd($row_class);
  541. }
  542. if (db_num_rows($result) < $num_feeds) {
  543. // FIXME - add link to show ALL subscribed feeds here somewhere
  544. print "<li><img
  545. class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
  546. }
  547. print "</ul>";
  548. print "</div>";
  549. print "<div align='center'>
  550. <input type='submit' class='button'
  551. onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
  552. // print "</body></html>";
  553. }
  554. if ($op == "pref-feed-browser") {
  555. module_pref_feed_browser($link);
  556. }
  557. if ($op == "rss") {
  558. $feed = db_escape_string($_GET["id"]);
  559. $user = db_escape_string($_GET["user"]);
  560. $pass = db_escape_string($_GET["pass"]);
  561. $is_cat = $_GET["is_cat"] != false;
  562. $search = db_escape_string($_GET["q"]);
  563. $match_on = db_escape_string($_GET["m"]);
  564. $search_mode = db_escape_string($_GET["smode"]);
  565. if (!$_SESSION["uid"] && $user && $pass) {
  566. authenticate_user($link, $user, $pass);
  567. }
  568. if ($_SESSION["uid"] ||
  569. http_authenticate_user($link)) {
  570. generate_syndicated_feed($link, $feed, $is_cat,
  571. $search, $search_mode, $match_on);
  572. }
  573. }
  574. if ($op == "labelFromSearch") {
  575. $search = db_escape_string($_GET["search"]);
  576. $search_mode = db_escape_string($_GET["smode"]);
  577. $match_on = db_escape_string($_GET["match"]);
  578. $is_cat = db_escape_string($_GET["is_cat"]);
  579. $title = db_escape_string($_GET["title"]);
  580. $feed = sprintf("%d", $_GET["feed"]);
  581. $label_qparts = array();
  582. $search_expr = getSearchSql($search, $match_on);
  583. if ($is_cat) {
  584. if ($feed != 0) {
  585. $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
  586. } else {
  587. $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
  588. }
  589. } else {
  590. if ($search_mode == "all_feeds") {
  591. // NOOP
  592. } else if ($search_mode == "this_cat") {
  593. $tmp_result = db_query($link, "SELECT cat_id
  594. FROM ttrss_feeds WHERE id = '$feed'");
  595. $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
  596. if ($cat_id > 0) {
  597. $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
  598. } else {
  599. $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
  600. }
  601. } else {
  602. $search_expr .= " AND ttrss_feeds.id = $feed ";
  603. }
  604. }
  605. $search_expr = db_escape_string($search_expr);
  606. print $search_expr;
  607. if ($title) {
  608. $result = db_query($link,
  609. "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
  610. VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
  611. }
  612. }
  613. if ($op == "getUnread") {
  614. $login = db_escape_string($_GET["login"]);
  615. header("Content-Type: text/plain; charset=utf-8");
  616. $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
  617. if (db_num_rows($result) == 1) {
  618. $uid = db_fetch_result($result, 0, "id");
  619. print getGlobalUnread($link, $uid);
  620. } else {
  621. print "-1;User not found";
  622. }
  623. $print_exec_time = false;
  624. }
  625. if ($op == "digestTest") {
  626. header("Content-Type: text/plain");
  627. print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
  628. $print_exec_time = false;
  629. }
  630. if ($op == "digestSend") {
  631. header("Content-Type: text/plain");
  632. send_headlines_digests($link);
  633. $print_exec_time = false;
  634. }
  635. db_close($link);
  636. ?>
  637. <?php if ($print_exec_time) { ?>
  638. <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
  639. <?php } ?>