functions2.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482
  1. <?php
  2. function make_init_params() {
  3. $params = array();
  4. foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS",
  5. "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP",
  6. "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE",
  7. "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) {
  8. $params[strtolower($param)] = (int) get_pref($param);
  9. }
  10. $params["icons_url"] = ICONS_URL;
  11. $params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
  12. $params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
  13. $params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT");
  14. $params["default_view_order_by"] = get_pref("_DEFAULT_VIEW_ORDER_BY");
  15. $params["bw_limit"] = (int) $_SESSION["bw_limit"];
  16. $params["label_base_index"] = (int) LABEL_BASE_INDEX;
  17. $theme = get_pref( "USER_CSS_THEME", false, false);
  18. $params["theme"] = theme_valid("$theme") ? $theme : "";
  19. $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names());
  20. $params["php_platform"] = PHP_OS;
  21. $params["php_version"] = PHP_VERSION;
  22. $params["sanity_checksum"] = sha1(file_get_contents("include/sanity_check.php"));
  23. $result = db_query("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM
  24. ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
  25. $max_feed_id = db_fetch_result($result, 0, "mid");
  26. $num_feeds = db_fetch_result($result, 0, "nf");
  27. $params["max_feed_id"] = (int) $max_feed_id;
  28. $params["num_feeds"] = (int) $num_feeds;
  29. $params["hotkeys"] = get_hotkeys_map();
  30. $params["csrf_token"] = $_SESSION["csrf_token"];
  31. $params["widescreen"] = (int) $_COOKIE["ttrss_widescreen"];
  32. $params['simple_update'] = defined('SIMPLE_UPDATE_MODE') && SIMPLE_UPDATE_MODE;
  33. return $params;
  34. }
  35. function get_hotkeys_info() {
  36. $hotkeys = array(
  37. __("Navigation") => array(
  38. "next_feed" => __("Open next feed"),
  39. "prev_feed" => __("Open previous feed"),
  40. "next_article" => __("Open next article"),
  41. "prev_article" => __("Open previous article"),
  42. "next_article_noscroll" => __("Open next article (don't scroll long articles)"),
  43. "prev_article_noscroll" => __("Open previous article (don't scroll long articles)"),
  44. "next_article_noexpand" => __("Move to next article (don't expand or mark read)"),
  45. "prev_article_noexpand" => __("Move to previous article (don't expand or mark read)"),
  46. "search_dialog" => __("Show search dialog")),
  47. __("Article") => array(
  48. "toggle_mark" => __("Toggle starred"),
  49. "toggle_publ" => __("Toggle published"),
  50. "toggle_unread" => __("Toggle unread"),
  51. "edit_tags" => __("Edit tags"),
  52. "dismiss_selected" => __("Dismiss selected"),
  53. "dismiss_read" => __("Dismiss read"),
  54. "open_in_new_window" => __("Open in new window"),
  55. "catchup_below" => __("Mark below as read"),
  56. "catchup_above" => __("Mark above as read"),
  57. "article_scroll_down" => __("Scroll down"),
  58. "article_scroll_up" => __("Scroll up"),
  59. "select_article_cursor" => __("Select article under cursor"),
  60. "email_article" => __("Email article"),
  61. "close_article" => __("Close/collapse article"),
  62. "toggle_expand" => __("Toggle article expansion (combined mode)"),
  63. "toggle_widescreen" => __("Toggle widescreen mode"),
  64. "toggle_embed_original" => __("Toggle embed original")),
  65. __("Article selection") => array(
  66. "select_all" => __("Select all articles"),
  67. "select_unread" => __("Select unread"),
  68. "select_marked" => __("Select starred"),
  69. "select_published" => __("Select published"),
  70. "select_invert" => __("Invert selection"),
  71. "select_none" => __("Deselect everything")),
  72. __("Feed") => array(
  73. "feed_refresh" => __("Refresh current feed"),
  74. "feed_unhide_read" => __("Un/hide read feeds"),
  75. "feed_subscribe" => __("Subscribe to feed"),
  76. "feed_edit" => __("Edit feed"),
  77. "feed_catchup" => __("Mark as read"),
  78. "feed_reverse" => __("Reverse headlines"),
  79. "feed_debug_update" => __("Debug feed update"),
  80. "catchup_all" => __("Mark all feeds as read"),
  81. "cat_toggle_collapse" => __("Un/collapse current category"),
  82. "toggle_combined_mode" => __("Toggle combined mode"),
  83. "toggle_cdm_expanded" => __("Toggle auto expand in combined mode")),
  84. __("Go to") => array(
  85. "goto_all" => __("All articles"),
  86. "goto_fresh" => __("Fresh"),
  87. "goto_marked" => __("Starred"),
  88. "goto_published" => __("Published"),
  89. "goto_tagcloud" => __("Tag cloud"),
  90. "goto_prefs" => __("Preferences")),
  91. __("Other") => array(
  92. "create_label" => __("Create label"),
  93. "create_filter" => __("Create filter"),
  94. "collapse_sidebar" => __("Un/collapse sidebar"),
  95. "help_dialog" => __("Show help dialog"))
  96. );
  97. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_INFO) as $plugin) {
  98. $hotkeys = $plugin->hook_hotkey_info($hotkeys);
  99. }
  100. return $hotkeys;
  101. }
  102. function get_hotkeys_map() {
  103. $hotkeys = array(
  104. // "navigation" => array(
  105. "k" => "next_feed",
  106. "j" => "prev_feed",
  107. "n" => "next_article",
  108. "p" => "prev_article",
  109. "(38)|up" => "prev_article",
  110. "(40)|down" => "next_article",
  111. // "^(38)|Ctrl-up" => "prev_article_noscroll",
  112. // "^(40)|Ctrl-down" => "next_article_noscroll",
  113. "(191)|/" => "search_dialog",
  114. // "article" => array(
  115. "s" => "toggle_mark",
  116. "*s" => "toggle_publ",
  117. "u" => "toggle_unread",
  118. "*t" => "edit_tags",
  119. "*d" => "dismiss_selected",
  120. "*x" => "dismiss_read",
  121. "o" => "open_in_new_window",
  122. "c p" => "catchup_below",
  123. "c n" => "catchup_above",
  124. "*n" => "article_scroll_down",
  125. "*p" => "article_scroll_up",
  126. "*(38)|Shift+up" => "article_scroll_up",
  127. "*(40)|Shift+down" => "article_scroll_down",
  128. "a *w" => "toggle_widescreen",
  129. "a e" => "toggle_embed_original",
  130. "e" => "email_article",
  131. "a q" => "close_article",
  132. // "article_selection" => array(
  133. "a a" => "select_all",
  134. "a u" => "select_unread",
  135. "a *u" => "select_marked",
  136. "a p" => "select_published",
  137. "a i" => "select_invert",
  138. "a n" => "select_none",
  139. // "feed" => array(
  140. "f r" => "feed_refresh",
  141. "f a" => "feed_unhide_read",
  142. "f s" => "feed_subscribe",
  143. "f e" => "feed_edit",
  144. "f q" => "feed_catchup",
  145. "f x" => "feed_reverse",
  146. "f *d" => "feed_debug_update",
  147. "f *c" => "toggle_combined_mode",
  148. "f c" => "toggle_cdm_expanded",
  149. "*q" => "catchup_all",
  150. "x" => "cat_toggle_collapse",
  151. // "goto" => array(
  152. "g a" => "goto_all",
  153. "g f" => "goto_fresh",
  154. "g s" => "goto_marked",
  155. "g p" => "goto_published",
  156. "g t" => "goto_tagcloud",
  157. "g *p" => "goto_prefs",
  158. // "other" => array(
  159. "(9)|Tab" => "select_article_cursor", // tab
  160. "c l" => "create_label",
  161. "c f" => "create_filter",
  162. "c s" => "collapse_sidebar",
  163. "^(191)|Ctrl+/" => "help_dialog",
  164. );
  165. if (get_pref('COMBINED_DISPLAY_MODE')) {
  166. $hotkeys["^(38)|Ctrl-up"] = "prev_article_noscroll";
  167. $hotkeys["^(40)|Ctrl-down"] = "next_article_noscroll";
  168. }
  169. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_MAP) as $plugin) {
  170. $hotkeys = $plugin->hook_hotkey_map($hotkeys);
  171. }
  172. $prefixes = array();
  173. foreach (array_keys($hotkeys) as $hotkey) {
  174. $pair = explode(" ", $hotkey, 2);
  175. if (count($pair) > 1 && !in_array($pair[0], $prefixes)) {
  176. array_push($prefixes, $pair[0]);
  177. }
  178. }
  179. return array($prefixes, $hotkeys);
  180. }
  181. function check_for_update() {
  182. if (defined("GIT_VERSION_TIMESTAMP")) {
  183. $content = @fetch_file_contents("http://tt-rss.org/version.json");
  184. if ($content) {
  185. $content = json_decode($content, true);
  186. if ($content && isset($content["changeset"])) {
  187. if ((int)GIT_VERSION_TIMESTAMP < (int)$content["changeset"]["timestamp"] &&
  188. GIT_VERSION_HEAD != $content["changeset"]["id"]) {
  189. return $content["changeset"]["id"];
  190. }
  191. }
  192. }
  193. }
  194. return "";
  195. }
  196. function make_runtime_info() {
  197. $data = array();
  198. $result = db_query("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM
  199. ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
  200. $max_feed_id = db_fetch_result($result, 0, "mid");
  201. $num_feeds = db_fetch_result($result, 0, "nf");
  202. $data["max_feed_id"] = (int) $max_feed_id;
  203. $data["num_feeds"] = (int) $num_feeds;
  204. $data['last_article_id'] = getLastArticleId();
  205. $data['cdm_expanded'] = get_pref('CDM_EXPANDED');
  206. $data['dep_ts'] = calculate_dep_timestamp();
  207. $data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE');
  208. if (CHECK_FOR_UPDATES && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
  209. $update_result = @check_for_update();
  210. $data["update_result"] = $update_result;
  211. $_SESSION["last_version_check"] = time();
  212. }
  213. if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
  214. $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
  215. if (time() - $_SESSION["daemon_stamp_check"] > 30) {
  216. $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
  217. if ($stamp) {
  218. $stamp_delta = time() - $stamp;
  219. if ($stamp_delta > 1800) {
  220. $stamp_check = 0;
  221. } else {
  222. $stamp_check = 1;
  223. $_SESSION["daemon_stamp_check"] = time();
  224. }
  225. $data['daemon_stamp_ok'] = $stamp_check;
  226. $stamp_fmt = date("Y.m.d, G:i", $stamp);
  227. $data['daemon_stamp'] = $stamp_fmt;
  228. }
  229. }
  230. }
  231. return $data;
  232. }
  233. function search_to_sql($search) {
  234. $search_query_part = "";
  235. $keywords = str_getcsv($search, " ");
  236. $query_keywords = array();
  237. $search_words = array();
  238. foreach ($keywords as $k) {
  239. if (strpos($k, "-") === 0) {
  240. $k = substr($k, 1);
  241. $not = "NOT";
  242. } else {
  243. $not = "";
  244. }
  245. $commandpair = explode(":", mb_strtolower($k), 2);
  246. switch ($commandpair[0]) {
  247. case "title":
  248. if ($commandpair[1]) {
  249. array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE '%".
  250. db_escape_string(mb_strtolower($commandpair[1]))."%'))");
  251. } else {
  252. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  253. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  254. array_push($search_words, $k);
  255. }
  256. break;
  257. case "author":
  258. if ($commandpair[1]) {
  259. array_push($query_keywords, "($not (LOWER(author) LIKE '%".
  260. db_escape_string(mb_strtolower($commandpair[1]))."%'))");
  261. } else {
  262. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  263. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  264. array_push($search_words, $k);
  265. }
  266. break;
  267. case "note":
  268. if ($commandpair[1]) {
  269. if ($commandpair[1] == "true")
  270. array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))");
  271. else if ($commandpair[1] == "false")
  272. array_push($query_keywords, "($not (note IS NULL OR note = ''))");
  273. else
  274. array_push($query_keywords, "($not (LOWER(note) LIKE '%".
  275. db_escape_string(mb_strtolower($commandpair[1]))."%'))");
  276. } else {
  277. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  278. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  279. if (!$not) array_push($search_words, $k);
  280. }
  281. break;
  282. case "star":
  283. if ($commandpair[1]) {
  284. if ($commandpair[1] == "true")
  285. array_push($query_keywords, "($not (marked = true))");
  286. else
  287. array_push($query_keywords, "($not (marked = false))");
  288. } else {
  289. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  290. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  291. if (!$not) array_push($search_words, $k);
  292. }
  293. break;
  294. case "pub":
  295. if ($commandpair[1]) {
  296. if ($commandpair[1] == "true")
  297. array_push($query_keywords, "($not (published = true))");
  298. else
  299. array_push($query_keywords, "($not (published = false))");
  300. } else {
  301. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  302. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  303. if (!$not) array_push($search_words, $k);
  304. }
  305. break;
  306. case "unread":
  307. if ($commandpair[1]) {
  308. if ($commandpair[1] == "true")
  309. array_push($query_keywords, "($not (unread = true))");
  310. else
  311. array_push($query_keywords, "($not (unread = false))");
  312. } else {
  313. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  314. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  315. if (!$not) array_push($search_words, $k);
  316. }
  317. break;
  318. default:
  319. if (strpos($k, "@") === 0) {
  320. $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']);
  321. $orig_ts = strtotime(substr($k, 1));
  322. $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC'));
  323. //$k = date("Y-m-d", strtotime(substr($k, 1)));
  324. array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')");
  325. } else {
  326. array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
  327. OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
  328. if (!$not) array_push($search_words, $k);
  329. }
  330. }
  331. }
  332. $search_query_part = implode("AND", $query_keywords);
  333. return array($search_query_part, $search_words);
  334. }
  335. function getParentCategories($cat, $owner_uid) {
  336. $rv = array();
  337. $result = db_query("SELECT parent_cat FROM ttrss_feed_categories
  338. WHERE id = '$cat' AND parent_cat IS NOT NULL AND owner_uid = $owner_uid");
  339. while ($line = db_fetch_assoc($result)) {
  340. array_push($rv, $line["parent_cat"]);
  341. $rv = array_merge($rv, getParentCategories($line["parent_cat"], $owner_uid));
  342. }
  343. return $rv;
  344. }
  345. function getChildCategories($cat, $owner_uid) {
  346. $rv = array();
  347. $result = db_query("SELECT id FROM ttrss_feed_categories
  348. WHERE parent_cat = '$cat' AND owner_uid = $owner_uid");
  349. while ($line = db_fetch_assoc($result)) {
  350. array_push($rv, $line["id"]);
  351. $rv = array_merge($rv, getChildCategories($line["id"], $owner_uid));
  352. }
  353. return $rv;
  354. }
  355. function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false) {
  356. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  357. $ext_tables_part = "";
  358. $search_words = array();
  359. if ($search) {
  360. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) {
  361. list($search_query_part, $search_words) = $plugin->hook_search($search);
  362. break;
  363. }
  364. // fall back in case of no plugins
  365. if (!$search_query_part) {
  366. list($search_query_part, $search_words) = search_to_sql($search);
  367. }
  368. $search_query_part .= " AND ";
  369. } else {
  370. $search_query_part = "";
  371. }
  372. if ($filter) {
  373. if (DB_TYPE == "pgsql") {
  374. $query_strategy_part .= " AND updated > NOW() - INTERVAL '14 days' ";
  375. } else {
  376. $query_strategy_part .= " AND updated > DATE_SUB(NOW(), INTERVAL 14 DAY) ";
  377. }
  378. $override_order = "updated DESC";
  379. $filter_query_part = filter_to_sql($filter, $owner_uid);
  380. // Try to check if SQL regexp implementation chokes on a valid regexp
  381. $result = db_query("SELECT true AS true_val
  382. FROM ttrss_entries
  383. JOIN ttrss_user_entries ON ttrss_entries.id = ttrss_user_entries.ref_id
  384. JOIN ttrss_feeds ON ttrss_feeds.id = ttrss_user_entries.feed_id
  385. WHERE $filter_query_part LIMIT 1", false);
  386. if ($result) {
  387. $test = db_fetch_result($result, 0, "true_val");
  388. if (!$test) {
  389. $filter_query_part = "false AND";
  390. } else {
  391. $filter_query_part .= " AND";
  392. }
  393. } else {
  394. $filter_query_part = "false AND";
  395. }
  396. } else {
  397. $filter_query_part = "";
  398. }
  399. if ($since_id) {
  400. $since_id_part = "ttrss_entries.id > $since_id AND ";
  401. } else {
  402. $since_id_part = "";
  403. }
  404. $view_query_part = "";
  405. if ($view_mode == "adaptive") {
  406. if ($search) {
  407. $view_query_part = " ";
  408. } else if ($feed != -1) {
  409. $unread = getFeedUnread($feed, $cat_view);
  410. if ($cat_view && $feed > 0 && $include_children)
  411. $unread += getCategoryChildrenUnread($feed);
  412. if ($unread > 0)
  413. $view_query_part = " unread = true AND ";
  414. }
  415. }
  416. if ($view_mode == "marked") {
  417. $view_query_part = " marked = true AND ";
  418. }
  419. if ($view_mode == "has_note") {
  420. $view_query_part = " (note IS NOT NULL AND note != '') AND ";
  421. }
  422. if ($view_mode == "published") {
  423. $view_query_part = " published = true AND ";
  424. }
  425. if ($view_mode == "unread" && $feed != -6) {
  426. $view_query_part = " unread = true AND ";
  427. }
  428. if ($limit > 0) {
  429. $limit_query_part = "LIMIT " . $limit;
  430. }
  431. $allow_archived = false;
  432. $vfeed_query_part = "";
  433. // override query strategy and enable feed display when searching globally
  434. if ($search && $search_mode == "all_feeds") {
  435. $query_strategy_part = "true";
  436. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  437. /* tags */
  438. } else if (!is_numeric($feed)) {
  439. $query_strategy_part = "true";
  440. $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
  441. id = feed_id) as feed_title,";
  442. } else if ($search && $search_mode == "this_cat") {
  443. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  444. if ($feed > 0) {
  445. if ($include_children) {
  446. $subcats = getChildCategories($feed, $owner_uid);
  447. array_push($subcats, $feed);
  448. $cats_qpart = join(",", $subcats);
  449. } else {
  450. $cats_qpart = $feed;
  451. }
  452. $query_strategy_part = "ttrss_feeds.cat_id IN ($cats_qpart)";
  453. } else {
  454. $query_strategy_part = "ttrss_feeds.cat_id IS NULL";
  455. }
  456. } else if ($feed > 0) {
  457. if ($cat_view) {
  458. if ($feed > 0) {
  459. if ($include_children) {
  460. # sub-cats
  461. $subcats = getChildCategories($feed, $owner_uid);
  462. array_push($subcats, $feed);
  463. $query_strategy_part = "cat_id IN (".
  464. implode(",", $subcats).")";
  465. } else {
  466. $query_strategy_part = "cat_id = '$feed'";
  467. }
  468. } else {
  469. $query_strategy_part = "cat_id IS NULL";
  470. }
  471. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  472. } else {
  473. $query_strategy_part = "feed_id = '$feed'";
  474. }
  475. } else if ($feed == 0 && !$cat_view) { // archive virtual feed
  476. $query_strategy_part = "feed_id IS NULL";
  477. $allow_archived = true;
  478. } else if ($feed == 0 && $cat_view) { // uncategorized
  479. $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
  480. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  481. } else if ($feed == -1) { // starred virtual feed
  482. $query_strategy_part = "marked = true";
  483. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  484. $allow_archived = true;
  485. if (!$override_order) {
  486. $override_order = "last_marked DESC, date_entered DESC, updated DESC";
  487. }
  488. } else if ($feed == -2) { // published virtual feed OR labels category
  489. if (!$cat_view) {
  490. $query_strategy_part = "published = true";
  491. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  492. $allow_archived = true;
  493. if (!$override_order) {
  494. $override_order = "last_published DESC, date_entered DESC, updated DESC";
  495. }
  496. } else {
  497. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  498. $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2";
  499. $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
  500. ttrss_user_labels2.article_id = ref_id";
  501. }
  502. } else if ($feed == -6) { // recently read
  503. $query_strategy_part = "unread = false AND last_read IS NOT NULL";
  504. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  505. $allow_archived = true;
  506. $ignore_vfeed_group = true;
  507. if (!$override_order) $override_order = "last_read DESC";
  508. /* } else if ($feed == -7) { // shared
  509. $query_strategy_part = "uuid != ''";
  510. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  511. $allow_archived = true; */
  512. } else if ($feed == -3) { // fresh virtual feed
  513. $query_strategy_part = "unread = true AND score >= 0";
  514. $intl = get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
  515. if (DB_TYPE == "pgsql") {
  516. $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
  517. } else {
  518. $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
  519. }
  520. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  521. } else if ($feed == -4) { // all articles virtual feed
  522. $allow_archived = true;
  523. $query_strategy_part = "true";
  524. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  525. } else if ($feed <= LABEL_BASE_INDEX) { // labels
  526. $label_id = feed_to_label_id($feed);
  527. $query_strategy_part = "label_id = '$label_id' AND
  528. ttrss_labels2.id = ttrss_user_labels2.label_id AND
  529. ttrss_user_labels2.article_id = ref_id";
  530. $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
  531. $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2";
  532. $allow_archived = true;
  533. } else {
  534. $query_strategy_part = "true";
  535. }
  536. $order_by = "score DESC, date_entered DESC, updated DESC";
  537. if ($override_order) {
  538. $order_by = $override_order;
  539. }
  540. if ($override_strategy) {
  541. $query_strategy_part = $override_strategy;
  542. }
  543. if ($override_vfeed) {
  544. $vfeed_query_part = $override_vfeed;
  545. }
  546. $feed_title = "";
  547. if ($search) {
  548. $feed_title = T_sprintf("Search results: %s", $search);
  549. } else {
  550. if ($cat_view) {
  551. $feed_title = getCategoryTitle($feed);
  552. } else {
  553. if (is_numeric($feed) && $feed > 0) {
  554. $result = db_query("SELECT title,site_url,last_error,last_updated
  555. FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = $owner_uid");
  556. $feed_title = db_fetch_result($result, 0, "title");
  557. $feed_site_url = db_fetch_result($result, 0, "site_url");
  558. $last_error = db_fetch_result($result, 0, "last_error");
  559. $last_updated = db_fetch_result($result, 0, "last_updated");
  560. } else {
  561. $feed_title = getFeedTitle($feed);
  562. }
  563. }
  564. }
  565. $content_query_part = "content, ";
  566. if (is_numeric($feed)) {
  567. if ($feed >= 0) {
  568. $feed_kind = "Feeds";
  569. } else {
  570. $feed_kind = "Labels";
  571. }
  572. if ($limit_query_part) {
  573. $offset_query_part = "OFFSET $offset";
  574. }
  575. // proper override_order applied above
  576. if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) {
  577. if (!$override_order) {
  578. $order_by = "ttrss_feeds.title, $order_by";
  579. } else {
  580. $order_by = "ttrss_feeds.title, $override_order";
  581. }
  582. }
  583. if (!$allow_archived) {
  584. $from_qpart = "ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part";
  585. $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
  586. } else {
  587. $from_qpart = "ttrss_entries$ext_tables_part,ttrss_user_entries
  588. LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
  589. }
  590. if ($vfeed_query_part)
  591. $vfeed_query_part .= "favicon_avg_color,";
  592. if ($start_ts) {
  593. $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts));
  594. $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND";
  595. } else {
  596. $start_ts_query_part = "";
  597. }
  598. $query = "SELECT DISTINCT
  599. date_entered,
  600. guid,
  601. ttrss_entries.id,ttrss_entries.title,
  602. updated,
  603. label_cache,
  604. tag_cache,
  605. always_display_enclosures,
  606. site_url,
  607. note,
  608. num_comments,
  609. comments,
  610. int_id,
  611. uuid,
  612. lang,
  613. hide_images,
  614. unread,feed_id,marked,published,link,last_read,orig_feed_id,
  615. last_marked, last_published,
  616. $vfeed_query_part
  617. $content_query_part
  618. author,score
  619. FROM
  620. $from_qpart
  621. WHERE
  622. $feed_check_qpart
  623. ttrss_user_entries.ref_id = ttrss_entries.id AND
  624. ttrss_user_entries.owner_uid = '$owner_uid' AND
  625. $search_query_part
  626. $start_ts_query_part
  627. $filter_query_part
  628. $view_query_part
  629. $since_id_part
  630. $query_strategy_part ORDER BY $order_by
  631. $limit_query_part $offset_query_part";
  632. if ($_REQUEST["debug"]) print $query;
  633. $result = db_query($query);
  634. } else {
  635. // browsing by tag
  636. $select_qpart = "SELECT DISTINCT " .
  637. "date_entered," .
  638. "guid," .
  639. "note," .
  640. "ttrss_entries.id as id," .
  641. "title," .
  642. "updated," .
  643. "unread," .
  644. "feed_id," .
  645. "orig_feed_id," .
  646. "marked," .
  647. "num_comments, " .
  648. "comments, " .
  649. "tag_cache," .
  650. "label_cache," .
  651. "link," .
  652. "lang," .
  653. "uuid," .
  654. "last_read," .
  655. "(SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images," .
  656. "last_marked, last_published, " .
  657. $since_id_part .
  658. $vfeed_query_part .
  659. $content_query_part .
  660. "score ";
  661. $feed_kind = "Tags";
  662. $all_tags = explode(",", $feed);
  663. if ($search_mode == 'any') {
  664. $tag_sql = "tag_name in (" . implode(", ", array_map("db_quote", $all_tags)) . ")";
  665. $from_qpart = " FROM ttrss_entries,ttrss_user_entries,ttrss_tags ";
  666. $where_qpart = " WHERE " .
  667. "ref_id = ttrss_entries.id AND " .
  668. "ttrss_user_entries.owner_uid = $owner_uid AND " .
  669. "post_int_id = int_id AND $tag_sql AND " .
  670. $view_query_part .
  671. $search_query_part .
  672. $query_strategy_part . " ORDER BY $order_by " .
  673. $limit_query_part;
  674. } else {
  675. $i = 1;
  676. $sub_selects = array();
  677. $sub_ands = array();
  678. foreach ($all_tags as $term) {
  679. array_push($sub_selects, "(SELECT post_int_id from ttrss_tags WHERE tag_name = " . db_quote($term) . " AND owner_uid = $owner_uid) as A$i");
  680. $i++;
  681. }
  682. if ($i > 2) {
  683. $x = 1;
  684. $y = 2;
  685. do {
  686. array_push($sub_ands, "A$x.post_int_id = A$y.post_int_id");
  687. $x++;
  688. $y++;
  689. } while ($y < $i);
  690. }
  691. array_push($sub_ands, "A1.post_int_id = ttrss_user_entries.int_id and ttrss_user_entries.owner_uid = $owner_uid");
  692. array_push($sub_ands, "ttrss_user_entries.ref_id = ttrss_entries.id");
  693. $from_qpart = " FROM " . implode(", ", $sub_selects) . ", ttrss_user_entries, ttrss_entries";
  694. $where_qpart = " WHERE " . implode(" AND ", $sub_ands);
  695. }
  696. // error_log("TAG SQL: " . $tag_sql);
  697. // $tag_sql = "tag_name = '$feed'"; DEFAULT way
  698. // error_log("[". $select_qpart . "][" . $from_qpart . "][" .$where_qpart . "]");
  699. $result = db_query($select_qpart . $from_qpart . $where_qpart);
  700. }
  701. return array($result, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words);
  702. }
  703. function iframe_whitelisted($entry) {
  704. $whitelist = array("youtube.com", "youtu.be", "vimeo.com");
  705. @$src = parse_url($entry->getAttribute("src"), PHP_URL_HOST);
  706. if ($src) {
  707. foreach ($whitelist as $w) {
  708. if ($src == $w || $src == "www.$w")
  709. return true;
  710. }
  711. }
  712. return false;
  713. }
  714. function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) {
  715. if (!$owner) $owner = $_SESSION["uid"];
  716. $res = trim($str); if (!$res) return '';
  717. $charset_hack = '<head>
  718. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  719. </head>';
  720. $res = trim($res); if (!$res) return '';
  721. libxml_use_internal_errors(true);
  722. $doc = new DOMDocument();
  723. $doc->loadHTML($charset_hack . $res);
  724. $xpath = new DOMXPath($doc);
  725. $entries = $xpath->query('(//a[@href]|//img[@src])');
  726. foreach ($entries as $entry) {
  727. if ($site_url) {
  728. if ($entry->hasAttribute('href')) {
  729. $entry->setAttribute('href',
  730. rewrite_relative_url($site_url, $entry->getAttribute('href')));
  731. $entry->setAttribute('rel', 'noreferrer');
  732. }
  733. if ($entry->hasAttribute('src')) {
  734. $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
  735. $cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png';
  736. if (file_exists($cached_filename)) {
  737. $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src);
  738. }
  739. $entry->setAttribute('src', $src);
  740. }
  741. if ($entry->nodeName == 'img') {
  742. if (($owner && get_pref("STRIP_IMAGES", $owner)) ||
  743. $force_remove_images || $_SESSION["bw_limit"]) {
  744. $p = $doc->createElement('p');
  745. $a = $doc->createElement('a');
  746. $a->setAttribute('href', $entry->getAttribute('src'));
  747. $a->appendChild(new DOMText($entry->getAttribute('src')));
  748. $a->setAttribute('target', '_blank');
  749. $p->appendChild($a);
  750. $entry->parentNode->replaceChild($p, $entry);
  751. }
  752. }
  753. }
  754. if (strtolower($entry->nodeName) == "a") {
  755. $entry->setAttribute("target", "_blank");
  756. }
  757. }
  758. $entries = $xpath->query('//iframe');
  759. foreach ($entries as $entry) {
  760. if (!iframe_whitelisted($entry)) {
  761. $entry->setAttribute('sandbox', 'allow-scripts');
  762. } else {
  763. if ($_SERVER['HTTPS'] == "on") {
  764. $entry->setAttribute("src",
  765. str_replace("http://", "https://",
  766. $entry->getAttribute("src")));
  767. }
  768. }
  769. }
  770. $allowed_elements = array('a', 'address', 'audio', 'article', 'aside',
  771. 'b', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br',
  772. 'caption', 'cite', 'center', 'code', 'col', 'colgroup',
  773. 'data', 'dd', 'del', 'details', 'div', 'dl', 'font',
  774. 'dt', 'em', 'footer', 'figure', 'figcaption',
  775. 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'html', 'i',
  776. 'img', 'ins', 'kbd', 'li', 'main', 'mark', 'nav', 'noscript',
  777. 'ol', 'p', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section',
  778. 'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary',
  779. 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time',
  780. 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video' );
  781. if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe';
  782. $disallowed_attributes = array('id', 'style', 'class');
  783. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
  784. $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id);
  785. if (is_array($retval)) {
  786. $doc = $retval[0];
  787. $allowed_elements = $retval[1];
  788. $disallowed_attributes = $retval[2];
  789. } else {
  790. $doc = $retval;
  791. }
  792. }
  793. $doc->removeChild($doc->firstChild); //remove doctype
  794. $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes);
  795. if ($highlight_words) {
  796. foreach ($highlight_words as $word) {
  797. // http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph
  798. $elements = $xpath->query("//*/text()");
  799. foreach ($elements as $child) {
  800. $fragment = $doc->createDocumentFragment();
  801. $text = $child->textContent;
  802. while (($pos = mb_stripos($text, $word)) !== false) {
  803. $fragment->appendChild(new DomText(mb_substr($text, 0, $pos)));
  804. $word = mb_substr($text, $pos, mb_strlen($word));
  805. $highlight = $doc->createElement('span');
  806. $highlight->appendChild(new DomText($word));
  807. $highlight->setAttribute('class', 'highlight');
  808. $fragment->appendChild($highlight);
  809. $text = mb_substr($text, $pos + mb_strlen($word));
  810. }
  811. if (!empty($text)) $fragment->appendChild(new DomText($text));
  812. $child->parentNode->replaceChild($fragment, $child);
  813. }
  814. }
  815. }
  816. $res = $doc->saveHTML();
  817. return $res;
  818. }
  819. function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) {
  820. $xpath = new DOMXPath($doc);
  821. $entries = $xpath->query('//*');
  822. foreach ($entries as $entry) {
  823. if (!in_array($entry->nodeName, $allowed_elements)) {
  824. $entry->parentNode->removeChild($entry);
  825. }
  826. if ($entry->hasAttributes()) {
  827. $attrs_to_remove = array();
  828. foreach ($entry->attributes as $attr) {
  829. if (strpos($attr->nodeName, 'on') === 0) {
  830. array_push($attrs_to_remove, $attr);
  831. }
  832. if (in_array($attr->nodeName, $disallowed_attributes)) {
  833. array_push($attrs_to_remove, $attr);
  834. }
  835. }
  836. foreach ($attrs_to_remove as $attr) {
  837. $entry->removeAttributeNode($attr);
  838. }
  839. }
  840. }
  841. return $doc;
  842. }
  843. function catchupArticlesById($ids, $cmode, $owner_uid = false) {
  844. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  845. if (count($ids) == 0) return;
  846. $tmp_ids = array();
  847. foreach ($ids as $id) {
  848. array_push($tmp_ids, "ref_id = '$id'");
  849. }
  850. $ids_qpart = join(" OR ", $tmp_ids);
  851. if ($cmode == 0) {
  852. db_query("UPDATE ttrss_user_entries SET
  853. unread = false,last_read = NOW()
  854. WHERE ($ids_qpart) AND owner_uid = $owner_uid");
  855. } else if ($cmode == 1) {
  856. db_query("UPDATE ttrss_user_entries SET
  857. unread = true
  858. WHERE ($ids_qpart) AND owner_uid = $owner_uid");
  859. } else {
  860. db_query("UPDATE ttrss_user_entries SET
  861. unread = NOT unread,last_read = NOW()
  862. WHERE ($ids_qpart) AND owner_uid = $owner_uid");
  863. }
  864. /* update ccache */
  865. $result = db_query("SELECT DISTINCT feed_id FROM ttrss_user_entries
  866. WHERE ($ids_qpart) AND owner_uid = $owner_uid");
  867. while ($line = db_fetch_assoc($result)) {
  868. ccache_update($line["feed_id"], $owner_uid);
  869. }
  870. }
  871. function get_article_tags($id, $owner_uid = 0, $tag_cache = false) {
  872. $a_id = db_escape_string($id);
  873. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  874. $query = "SELECT DISTINCT tag_name,
  875. owner_uid as owner FROM
  876. ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE
  877. ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name";
  878. $tags = array();
  879. /* check cache first */
  880. if ($tag_cache === false) {
  881. $result = db_query("SELECT tag_cache FROM ttrss_user_entries
  882. WHERE ref_id = '$id' AND owner_uid = $owner_uid");
  883. $tag_cache = db_fetch_result($result, 0, "tag_cache");
  884. }
  885. if ($tag_cache) {
  886. $tags = explode(",", $tag_cache);
  887. } else {
  888. /* do it the hard way */
  889. $tmp_result = db_query($query);
  890. while ($tmp_line = db_fetch_assoc($tmp_result)) {
  891. array_push($tags, $tmp_line["tag_name"]);
  892. }
  893. /* update the cache */
  894. $tags_str = db_escape_string(join(",", $tags));
  895. db_query("UPDATE ttrss_user_entries
  896. SET tag_cache = '$tags_str' WHERE ref_id = '$id'
  897. AND owner_uid = $owner_uid");
  898. }
  899. return $tags;
  900. }
  901. function trim_array($array) {
  902. $tmp = $array;
  903. array_walk($tmp, 'trim');
  904. return $tmp;
  905. }
  906. function tag_is_valid($tag) {
  907. if ($tag == '') return false;
  908. if (preg_match("/^[0-9]*$/", $tag)) return false;
  909. if (mb_strlen($tag) > 250) return false;
  910. if (!$tag) return false;
  911. return true;
  912. }
  913. function render_login_form() {
  914. header('Cache-Control: public');
  915. require_once "login_form.php";
  916. exit;
  917. }
  918. function format_warning($msg, $id = "") {
  919. return "<div class=\"warning\" id=\"$id\">
  920. <span><img src=\"images/alert.png\"></span><span>$msg</span></div>";
  921. }
  922. function format_notice($msg, $id = "") {
  923. return "<div class=\"notice\" id=\"$id\">
  924. <span><img src=\"images/information.png\"></span><span>$msg</span></div>";
  925. }
  926. function format_error($msg, $id = "") {
  927. return "<div class=\"error\" id=\"$id\">
  928. <span><img src=\"images/alert.png\"></span><span>$msg</span></div>";
  929. }
  930. function print_notice($msg) {
  931. return print format_notice($msg);
  932. }
  933. function print_warning($msg) {
  934. return print format_warning($msg);
  935. }
  936. function print_error($msg) {
  937. return print format_error($msg);
  938. }
  939. function T_sprintf() {
  940. $args = func_get_args();
  941. return vsprintf(__(array_shift($args)), $args);
  942. }
  943. function format_inline_player($url, $ctype) {
  944. $entry = "";
  945. $url = htmlspecialchars($url);
  946. if (strpos($ctype, "audio/") === 0) {
  947. if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
  948. $_SESSION["hasMp3"])) {
  949. $entry .= "<audio preload=\"none\" controls>
  950. <source type=\"$ctype\" src=\"$url\"></source>
  951. </audio>";
  952. } else {
  953. $entry .= "<object type=\"application/x-shockwave-flash\"
  954. data=\"lib/button/musicplayer.swf?song_url=$url\"
  955. width=\"17\" height=\"17\" style='float : left; margin-right : 5px;'>
  956. <param name=\"movie\"
  957. value=\"lib/button/musicplayer.swf?song_url=$url\" />
  958. </object>";
  959. }
  960. if ($entry) $entry .= "&nbsp; <a target=\"_blank\"
  961. href=\"$url\">" . basename($url) . "</a>";
  962. return $entry;
  963. }
  964. return "";
  965. /* $filename = substr($url, strrpos($url, "/")+1);
  966. $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
  967. $filename . " (" . $ctype . ")" . "</a>"; */
  968. }
  969. function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
  970. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  971. $rv = array();
  972. $rv['id'] = $id;
  973. /* we can figure out feed_id from article id anyway, why do we
  974. * pass feed_id here? let's ignore the argument :(*/
  975. $result = db_query("SELECT feed_id FROM ttrss_user_entries
  976. WHERE ref_id = '$id'");
  977. $feed_id = (int) db_fetch_result($result, 0, "feed_id");
  978. $rv['feed_id'] = $feed_id;
  979. //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
  980. if ($mark_as_read) {
  981. $result = db_query("UPDATE ttrss_user_entries
  982. SET unread = false,last_read = NOW()
  983. WHERE ref_id = '$id' AND owner_uid = $owner_uid");
  984. ccache_update($feed_id, $owner_uid);
  985. }
  986. $result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,lang,
  987. ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
  988. (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
  989. (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
  990. (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images,
  991. (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures,
  992. num_comments,
  993. tag_cache,
  994. author,
  995. orig_feed_id,
  996. note
  997. FROM ttrss_entries,ttrss_user_entries
  998. WHERE id = '$id' AND ref_id = id AND owner_uid = $owner_uid");
  999. if ($result) {
  1000. $line = db_fetch_assoc($result);
  1001. $line["tags"] = get_article_tags($id, $owner_uid, $line["tag_cache"]);
  1002. unset($line["tag_cache"]);
  1003. $line["content"] = sanitize($line["content"],
  1004. sql_bool_to_bool($line['hide_images']),
  1005. $owner_uid, $line["site_url"], false, $line["id"]);
  1006. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
  1007. $line = $p->hook_render_article($line);
  1008. }
  1009. $num_comments = $line["num_comments"];
  1010. $entry_comments = "";
  1011. if ($num_comments > 0) {
  1012. if ($line["comments"]) {
  1013. $comments_url = htmlspecialchars($line["comments"]);
  1014. } else {
  1015. $comments_url = htmlspecialchars($line["link"]);
  1016. }
  1017. $entry_comments = "<a class=\"postComments\"
  1018. target='_blank' href=\"$comments_url\">$num_comments ".
  1019. _ngettext("comment", "comments", $num_comments)."</a>";
  1020. } else {
  1021. if ($line["comments"] && $line["link"] != $line["comments"]) {
  1022. $entry_comments = "<a class=\"postComments\" target='_blank' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
  1023. }
  1024. }
  1025. if ($zoom_mode) {
  1026. header("Content-Type: text/html");
  1027. $rv['content'] .= "<html><head>
  1028. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  1029. <title>Tiny Tiny RSS - ".$line["title"]."</title>".
  1030. stylesheet_tag("css/tt-rss.css").
  1031. stylesheet_tag("css/zoom.css").
  1032. stylesheet_tag("css/dijit.css")."
  1033. <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
  1034. <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
  1035. <script type=\"text/javascript\">
  1036. function openSelectedAttachment(elem) {
  1037. try {
  1038. var url = elem[elem.selectedIndex].value;
  1039. if (url) {
  1040. window.open(url);
  1041. elem.selectedIndex = 0;
  1042. }
  1043. } catch (e) {
  1044. exception_error(\"openSelectedAttachment\", e);
  1045. }
  1046. }
  1047. </script>
  1048. </head><body id=\"ttrssZoom\">";
  1049. }
  1050. $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">";
  1051. $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-$id\">";
  1052. $entry_author = $line["author"];
  1053. if ($entry_author) {
  1054. $entry_author = __(" - ") . $entry_author;
  1055. }
  1056. $parsed_updated = make_local_datetime($line["updated"], true,
  1057. $owner_uid, true);
  1058. if (!$zoom_mode)
  1059. $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
  1060. if ($line["link"]) {
  1061. $rv['content'] .= "<div class='postTitle'><a target='_blank'
  1062. title=\"".htmlspecialchars($line['title'])."\"
  1063. href=\"" .
  1064. htmlspecialchars($line["link"]) . "\">" .
  1065. $line["title"] . "</a>" .
  1066. "<span class='author'>$entry_author</span></div>";
  1067. } else {
  1068. $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "$entry_author</div>";
  1069. }
  1070. if ($zoom_mode) {
  1071. $feed_title = "<a href=\"".htmlspecialchars($line["site_url"]).
  1072. "\" target=\"_blank\">".
  1073. htmlspecialchars($line["feed_title"])."</a>";
  1074. $rv['content'] .= "<div class=\"postFeedTitle\">$feed_title</div>";
  1075. $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
  1076. }
  1077. $tags_str = format_tags_string($line["tags"], $id);
  1078. $tags_str_full = join(", ", $line["tags"]);
  1079. if (!$tags_str_full) $tags_str_full = __("no tags");
  1080. if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
  1081. $rv['content'] .= "<div class='postTags' style='float : right'>
  1082. <img src='images/tag.png'
  1083. class='tagsPic' alt='Tags' title='Tags'>&nbsp;";
  1084. if (!$zoom_mode) {
  1085. $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>
  1086. <a title=\"".__('Edit tags for this article')."\"
  1087. href=\"#\" onclick=\"editArticleTags($id, $feed_id)\">(+)</a>";
  1088. $rv['content'] .= "<div dojoType=\"dijit.Tooltip\"
  1089. id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
  1090. position=\"below\">$tags_str_full</div>";
  1091. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
  1092. $rv['content'] .= $p->hook_article_button($line);
  1093. }
  1094. } else {
  1095. $tags_str = strip_tags($tags_str);
  1096. $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>";
  1097. }
  1098. $rv['content'] .= "</div>";
  1099. $rv['content'] .= "<div clear='both'>";
  1100. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
  1101. $rv['content'] .= $p->hook_article_left_button($line);
  1102. }
  1103. $rv['content'] .= "$entry_comments</div>";
  1104. if ($line["orig_feed_id"]) {
  1105. $tmp_result = db_query("SELECT * FROM ttrss_archived_feeds
  1106. WHERE id = ".$line["orig_feed_id"]);
  1107. if (db_num_rows($tmp_result) != 0) {
  1108. $rv['content'] .= "<div clear='both'>";
  1109. $rv['content'] .= __("Originally from:");
  1110. $rv['content'] .= "&nbsp;";
  1111. $tmp_line = db_fetch_assoc($tmp_result);
  1112. $rv['content'] .= "<a target='_blank'
  1113. href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
  1114. $tmp_line['title'] . "</a>";
  1115. $rv['content'] .= "&nbsp;";
  1116. $rv['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
  1117. $rv['content'] .= "<img title='".__('Feed URL')."' class='tinyFeedIcon' src='images/pub_set.png'></a>";
  1118. $rv['content'] .= "</div>";
  1119. }
  1120. }
  1121. $rv['content'] .= "</div>";
  1122. $rv['content'] .= "<div id=\"POSTNOTE-$id\">";
  1123. if ($line['note']) {
  1124. $rv['content'] .= format_article_note($id, $line['note'], !$zoom_mode);
  1125. }
  1126. $rv['content'] .= "</div>";
  1127. if (!$line['lang']) $line['lang'] = 'en';
  1128. $rv['content'] .= "<div class=\"postContent\" lang=\"".$line['lang']."\">";
  1129. $rv['content'] .= $line["content"];
  1130. $rv['content'] .= format_article_enclosures($id,
  1131. sql_bool_to_bool($line["always_display_enclosures"]),
  1132. $line["content"],
  1133. sql_bool_to_bool($line["hide_images"]));
  1134. $rv['content'] .= "</div>";
  1135. $rv['content'] .= "</div>";
  1136. }
  1137. if ($zoom_mode) {
  1138. $rv['content'] .= "
  1139. <div class='footer'>
  1140. <button onclick=\"return window.close()\">".
  1141. __("Close this window")."</button></div>";
  1142. $rv['content'] .= "</body></html>";
  1143. }
  1144. return $rv;
  1145. }
  1146. function print_checkpoint($n, $s) {
  1147. $ts = microtime(true);
  1148. echo sprintf("<!-- CP[$n] %.4f seconds -->\n", $ts - $s);
  1149. return $ts;
  1150. }
  1151. function sanitize_tag($tag) {
  1152. $tag = trim($tag);
  1153. $tag = mb_strtolower($tag, 'utf-8');
  1154. $tag = preg_replace('/[\'\"\+\>\<]/', "", $tag);
  1155. // $tag = str_replace('"', "", $tag);
  1156. // $tag = str_replace("+", " ", $tag);
  1157. $tag = str_replace("technorati tag: ", "", $tag);
  1158. return $tag;
  1159. }
  1160. function get_self_url_prefix() {
  1161. if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) {
  1162. return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1);
  1163. } else {
  1164. return SELF_URL_PATH;
  1165. }
  1166. }
  1167. /**
  1168. * Compute the Mozilla Firefox feed adding URL from server HOST and REQUEST_URI.
  1169. *
  1170. * @return string The Mozilla Firefox feed adding URL.
  1171. */
  1172. function add_feed_url() {
  1173. //$url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
  1174. $url_path = get_self_url_prefix() .
  1175. "/public.php?op=subscribe&feed_url=%s";
  1176. return $url_path;
  1177. } // function add_feed_url
  1178. function encrypt_password($pass, $salt = '', $mode2 = false) {
  1179. if ($salt && $mode2) {
  1180. return "MODE2:" . hash('sha256', $salt . $pass);
  1181. } else if ($salt) {
  1182. return "SHA1X:" . sha1("$salt:$pass");
  1183. } else {
  1184. return "SHA1:" . sha1($pass);
  1185. }
  1186. } // function encrypt_password
  1187. function load_filters($feed_id, $owner_uid, $action_id = false) {
  1188. $filters = array();
  1189. $cat_id = (int)getFeedCategory($feed_id);
  1190. if ($cat_id == 0)
  1191. $null_cat_qpart = "cat_id IS NULL OR";
  1192. else
  1193. $null_cat_qpart = "";
  1194. $result = db_query("SELECT * FROM ttrss_filters2 WHERE
  1195. owner_uid = $owner_uid AND enabled = true ORDER BY order_id, title");
  1196. $check_cats = join(",", array_merge(
  1197. getParentCategories($cat_id, $owner_uid),
  1198. array($cat_id)));
  1199. while ($line = db_fetch_assoc($result)) {
  1200. $filter_id = $line["id"];
  1201. $result2 = db_query("SELECT
  1202. r.reg_exp, r.inverse, r.feed_id, r.cat_id, r.cat_filter, t.name AS type_name
  1203. FROM ttrss_filters2_rules AS r,
  1204. ttrss_filter_types AS t
  1205. WHERE
  1206. ($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats)) AND
  1207. (feed_id IS NULL OR feed_id = '$feed_id') AND
  1208. filter_type = t.id AND filter_id = '$filter_id'");
  1209. $rules = array();
  1210. $actions = array();
  1211. while ($rule_line = db_fetch_assoc($result2)) {
  1212. # print_r($rule_line);
  1213. $rule = array();
  1214. $rule["reg_exp"] = $rule_line["reg_exp"];
  1215. $rule["type"] = $rule_line["type_name"];
  1216. $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
  1217. array_push($rules, $rule);
  1218. }
  1219. $result2 = db_query("SELECT a.action_param,t.name AS type_name
  1220. FROM ttrss_filters2_actions AS a,
  1221. ttrss_filter_actions AS t
  1222. WHERE
  1223. action_id = t.id AND filter_id = '$filter_id'");
  1224. while ($action_line = db_fetch_assoc($result2)) {
  1225. # print_r($action_line);
  1226. $action = array();
  1227. $action["type"] = $action_line["type_name"];
  1228. $action["param"] = $action_line["action_param"];
  1229. array_push($actions, $action);
  1230. }
  1231. $filter = array();
  1232. $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
  1233. $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
  1234. $filter["rules"] = $rules;
  1235. $filter["actions"] = $actions;
  1236. if (count($rules) > 0 && count($actions) > 0) {
  1237. array_push($filters, $filter);
  1238. }
  1239. }
  1240. return $filters;
  1241. }
  1242. function get_score_pic($score) {
  1243. if ($score > 100) {
  1244. return "score_high.png";
  1245. } else if ($score > 0) {
  1246. return "score_half_high.png";
  1247. } else if ($score < -100) {
  1248. return "score_low.png";
  1249. } else if ($score < 0) {
  1250. return "score_half_low.png";
  1251. } else {
  1252. return "score_neutral.png";
  1253. }
  1254. }
  1255. function feed_has_icon($id) {
  1256. return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
  1257. }
  1258. function init_plugins() {
  1259. PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
  1260. return true;
  1261. }
  1262. function format_tags_string($tags, $id) {
  1263. if (!is_array($tags) || count($tags) == 0) {
  1264. return __("no tags");
  1265. } else {
  1266. $maxtags = min(5, count($tags));
  1267. for ($i = 0; $i < $maxtags; $i++) {
  1268. $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"viewfeed('".$tags[$i]."')\">" . $tags[$i] . "</a>, ";
  1269. }
  1270. $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2);
  1271. if (count($tags) > $maxtags)
  1272. $tags_str .= ", &hellip;";
  1273. return $tags_str;
  1274. }
  1275. }
  1276. function format_article_labels($labels, $id) {
  1277. if (!is_array($labels)) return '';
  1278. $labels_str = "";
  1279. foreach ($labels as $l) {
  1280. $labels_str .= sprintf("<span class='hlLabelRef'
  1281. style='color : %s; background-color : %s'>%s</span>",
  1282. $l[2], $l[3], $l[1]);
  1283. }
  1284. return $labels_str;
  1285. }
  1286. function format_article_note($id, $note, $allow_edit = true) {
  1287. $str = "<div class='articleNote' onclick=\"editArticleNote($id)\">
  1288. <div class='noteEdit' onclick=\"editArticleNote($id)\">".
  1289. ($allow_edit ? __('(edit note)') : "")."</div>$note</div>";
  1290. return $str;
  1291. }
  1292. function get_feed_category($feed_cat, $parent_cat_id = false) {
  1293. if ($parent_cat_id) {
  1294. $parent_qpart = "parent_cat = '$parent_cat_id'";
  1295. $parent_insert = "'$parent_cat_id'";
  1296. } else {
  1297. $parent_qpart = "parent_cat IS NULL";
  1298. $parent_insert = "NULL";
  1299. }
  1300. $result = db_query(
  1301. "SELECT id FROM ttrss_feed_categories
  1302. WHERE $parent_qpart AND title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
  1303. if (db_num_rows($result) == 0) {
  1304. return false;
  1305. } else {
  1306. return db_fetch_result($result, 0, "id");
  1307. }
  1308. }
  1309. function add_feed_category($feed_cat, $parent_cat_id = false) {
  1310. if (!$feed_cat) return false;
  1311. db_query("BEGIN");
  1312. if ($parent_cat_id) {
  1313. $parent_qpart = "parent_cat = '$parent_cat_id'";
  1314. $parent_insert = "'$parent_cat_id'";
  1315. } else {
  1316. $parent_qpart = "parent_cat IS NULL";
  1317. $parent_insert = "NULL";
  1318. }
  1319. $feed_cat = mb_substr($feed_cat, 0, 250);
  1320. $result = db_query(
  1321. "SELECT id FROM ttrss_feed_categories
  1322. WHERE $parent_qpart AND title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
  1323. if (db_num_rows($result) == 0) {
  1324. $result = db_query(
  1325. "INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat)
  1326. VALUES ('".$_SESSION["uid"]."', '$feed_cat', $parent_insert)");
  1327. db_query("COMMIT");
  1328. return true;
  1329. }
  1330. return false;
  1331. }
  1332. function getArticleFeed($id) {
  1333. $result = db_query("SELECT feed_id FROM ttrss_user_entries
  1334. WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  1335. if (db_num_rows($result) != 0) {
  1336. return db_fetch_result($result, 0, "feed_id");
  1337. } else {
  1338. return 0;
  1339. }
  1340. }
  1341. /**
  1342. * Fixes incomplete URLs by prepending "http://".
  1343. * Also replaces feed:// with http://, and
  1344. * prepends a trailing slash if the url is a domain name only.
  1345. *
  1346. * @param string $url Possibly incomplete URL
  1347. *
  1348. * @return string Fixed URL.
  1349. */
  1350. function fix_url($url) {
  1351. if (strpos($url, '://') === false) {
  1352. $url = 'http://' . $url;
  1353. } else if (substr($url, 0, 5) == 'feed:') {
  1354. $url = 'http:' . substr($url, 5);
  1355. }
  1356. //prepend slash if the URL has no slash in it
  1357. // "http://www.example" -> "http://www.example/"
  1358. if (strpos($url, '/', strpos($url, ':') + 3) === false) {
  1359. $url .= '/';
  1360. }
  1361. if ($url != "http:///")
  1362. return $url;
  1363. else
  1364. return '';
  1365. }
  1366. function validate_feed_url($url) {
  1367. $parts = parse_url($url);
  1368. return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https');
  1369. }
  1370. function get_article_enclosures($id) {
  1371. $query = "SELECT * FROM ttrss_enclosures
  1372. WHERE post_id = '$id' AND content_url != ''";
  1373. $rv = array();
  1374. $result = db_query($query);
  1375. if (db_num_rows($result) > 0) {
  1376. while ($line = db_fetch_assoc($result)) {
  1377. array_push($rv, $line);
  1378. }
  1379. }
  1380. return $rv;
  1381. }
  1382. /* function save_email_address($email) {
  1383. // FIXME: implement persistent storage of emails
  1384. if (!$_SESSION['stored_emails'])
  1385. $_SESSION['stored_emails'] = array();
  1386. if (!in_array($email, $_SESSION['stored_emails']))
  1387. array_push($_SESSION['stored_emails'], $email);
  1388. } */
  1389. function get_feed_access_key($feed_id, $is_cat, $owner_uid = false) {
  1390. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  1391. $sql_is_cat = bool_to_sql_bool($is_cat);
  1392. $result = db_query("SELECT access_key FROM ttrss_access_keys
  1393. WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
  1394. AND owner_uid = " . $owner_uid);
  1395. if (db_num_rows($result) == 1) {
  1396. return db_fetch_result($result, 0, "access_key");
  1397. } else {
  1398. $key = db_escape_string(uniqid(base_convert(rand(), 10, 36)));
  1399. $result = db_query("INSERT INTO ttrss_access_keys
  1400. (access_key, feed_id, is_cat, owner_uid)
  1401. VALUES ('$key', '$feed_id', $sql_is_cat, '$owner_uid')");
  1402. return $key;
  1403. }
  1404. return false;
  1405. }
  1406. function get_feeds_from_html($url, $content)
  1407. {
  1408. $url = fix_url($url);
  1409. $baseUrl = substr($url, 0, strrpos($url, '/') + 1);
  1410. libxml_use_internal_errors(true);
  1411. $doc = new DOMDocument();
  1412. $doc->loadHTML($content);
  1413. $xpath = new DOMXPath($doc);
  1414. $entries = $xpath->query('/html/head/link[@rel="alternate" and '.
  1415. '(contains(@type,"rss") or contains(@type,"atom"))]|/html/head/link[@rel="feed"]');
  1416. $feedUrls = array();
  1417. foreach ($entries as $entry) {
  1418. if ($entry->hasAttribute('href')) {
  1419. $title = $entry->getAttribute('title');
  1420. if ($title == '') {
  1421. $title = $entry->getAttribute('type');
  1422. }
  1423. $feedUrl = rewrite_relative_url(
  1424. $baseUrl, $entry->getAttribute('href')
  1425. );
  1426. $feedUrls[$feedUrl] = $title;
  1427. }
  1428. }
  1429. return $feedUrls;
  1430. }
  1431. function is_html($content) {
  1432. return preg_match("/<html|DOCTYPE html/i", substr($content, 0, 20)) !== 0;
  1433. }
  1434. function url_is_html($url, $login = false, $pass = false) {
  1435. return is_html(fetch_file_contents($url, false, $login, $pass));
  1436. }
  1437. function print_label_select($name, $value, $attributes = "") {
  1438. $result = db_query("SELECT caption FROM ttrss_labels2
  1439. WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
  1440. print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
  1441. "\" $attributes onchange=\"labelSelectOnChange(this)\" >";
  1442. while ($line = db_fetch_assoc($result)) {
  1443. $issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
  1444. print "<option value=\"".htmlspecialchars($line["caption"])."\"
  1445. $issel>" . htmlspecialchars($line["caption"]) . "</option>";
  1446. }
  1447. # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
  1448. print "</select>";
  1449. }
  1450. function format_article_enclosures($id, $always_display_enclosures,
  1451. $article_content, $hide_images = false) {
  1452. $result = get_article_enclosures($id);
  1453. $rv = '';
  1454. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) {
  1455. $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images);
  1456. if (is_array($retval)) {
  1457. $rv = $retval[0];
  1458. $result = $retval[1];
  1459. } else {
  1460. $rv = $retval;
  1461. }
  1462. }
  1463. if ($rv === '' && !empty($result)) {
  1464. $entries_html = array();
  1465. $entries = array();
  1466. $entries_inline = array();
  1467. foreach ($result as $line) {
  1468. $url = $line["content_url"];
  1469. $ctype = $line["content_type"];
  1470. $title = $line["title"];
  1471. $width = $line["width"];
  1472. $height = $line["height"];
  1473. if (!$ctype) $ctype = __("unknown type");
  1474. $filename = substr($url, strrpos($url, "/")+1);
  1475. $player = format_inline_player($url, $ctype);
  1476. if ($player) array_push($entries_inline, $player);
  1477. # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
  1478. # $filename . " (" . $ctype . ")" . "</a>";
  1479. $entry = "<div onclick=\"window.open('".htmlspecialchars($url)."')\"
  1480. dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>";
  1481. array_push($entries_html, $entry);
  1482. $entry = array();
  1483. $entry["type"] = $ctype;
  1484. $entry["filename"] = $filename;
  1485. $entry["url"] = $url;
  1486. $entry["title"] = $title;
  1487. $entry["width"] = $width;
  1488. $entry["height"] = $height;
  1489. array_push($entries, $entry);
  1490. }
  1491. if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) {
  1492. if ($always_display_enclosures ||
  1493. !preg_match("/<img/i", $article_content)) {
  1494. foreach ($entries as $entry) {
  1495. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin)
  1496. $retval = $plugin->hook_render_enclosure($entry, $hide_images);
  1497. if ($retval) {
  1498. $rv .= $retval;
  1499. } else {
  1500. if (preg_match("/image/", $entry["type"]) ||
  1501. preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
  1502. if (!$hide_images) {
  1503. $encsize = '';
  1504. if ($entry['height'] > 0)
  1505. $encsize .= ' height="' . intval($entry['width']) . '"';
  1506. if ($entry['width'] > 0)
  1507. $encsize .= ' width="' . intval($entry['height']) . '"';
  1508. $rv .= "<p><img
  1509. alt=\"".htmlspecialchars($entry["filename"])."\"
  1510. src=\"" .htmlspecialchars($entry["url"]) . "\"
  1511. " . $encsize . " /></p>";
  1512. } else {
  1513. $rv .= "<p><a target=\"_blank\"
  1514. href=\"".htmlspecialchars($entry["url"])."\"
  1515. >" .htmlspecialchars($entry["url"]) . "</a></p>";
  1516. }
  1517. if ($entry['title']) {
  1518. $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
  1519. }
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if (count($entries_inline) > 0) {
  1526. $rv .= "<hr clear='both'/>";
  1527. foreach ($entries_inline as $entry) { $rv .= $entry; };
  1528. $rv .= "<hr clear='both'/>";
  1529. }
  1530. $rv .= "<select class=\"attachments\" onchange=\"openSelectedAttachment(this)\">".
  1531. "<option value=''>" . __('Attachments')."</option>";
  1532. foreach ($entries as $entry) {
  1533. if ($entry["title"])
  1534. $title = "&mdash; " . truncate_string($entry["title"], 30);
  1535. else
  1536. $title = "";
  1537. $rv .= "<option value=\"".htmlspecialchars($entry["url"])."\">" . htmlspecialchars($entry["filename"]) . "$title</option>";
  1538. };
  1539. $rv .= "</select>";
  1540. }
  1541. return $rv;
  1542. }
  1543. function getLastArticleId() {
  1544. $result = db_query("SELECT ref_id AS id FROM ttrss_user_entries
  1545. WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY ref_id DESC LIMIT 1");
  1546. if (db_num_rows($result) == 1) {
  1547. return db_fetch_result($result, 0, "id");
  1548. } else {
  1549. return -1;
  1550. }
  1551. }
  1552. function build_url($parts) {
  1553. return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
  1554. }
  1555. /**
  1556. * Converts a (possibly) relative URL to a absolute one.
  1557. *
  1558. * @param string $url Base URL (i.e. from where the document is)
  1559. * @param string $rel_url Possibly relative URL in the document
  1560. *
  1561. * @return string Absolute URL
  1562. */
  1563. function rewrite_relative_url($url, $rel_url) {
  1564. if (strpos($rel_url, ":") !== false) {
  1565. return $rel_url;
  1566. } else if (strpos($rel_url, "://") !== false) {
  1567. return $rel_url;
  1568. } else if (strpos($rel_url, "//") === 0) {
  1569. # protocol-relative URL (rare but they exist)
  1570. return $rel_url;
  1571. } else if (strpos($rel_url, "/") === 0)
  1572. {
  1573. $parts = parse_url($url);
  1574. $parts['path'] = $rel_url;
  1575. return build_url($parts);
  1576. } else {
  1577. $parts = parse_url($url);
  1578. if (!isset($parts['path'])) {
  1579. $parts['path'] = '/';
  1580. }
  1581. $dir = $parts['path'];
  1582. if (substr($dir, -1) !== '/') {
  1583. $dir = dirname($parts['path']);
  1584. $dir !== '/' && $dir .= '/';
  1585. }
  1586. $parts['path'] = $dir . $rel_url;
  1587. return build_url($parts);
  1588. }
  1589. }
  1590. function cleanup_tags($days = 14, $limit = 1000) {
  1591. if (DB_TYPE == "pgsql") {
  1592. $interval_query = "date_updated < NOW() - INTERVAL '$days days'";
  1593. } else if (DB_TYPE == "mysql") {
  1594. $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)";
  1595. }
  1596. $tags_deleted = 0;
  1597. while ($limit > 0) {
  1598. $limit_part = 500;
  1599. $query = "SELECT ttrss_tags.id AS id
  1600. FROM ttrss_tags, ttrss_user_entries, ttrss_entries
  1601. WHERE post_int_id = int_id AND $interval_query AND
  1602. ref_id = ttrss_entries.id AND tag_cache != '' LIMIT $limit_part";
  1603. $result = db_query($query);
  1604. $ids = array();
  1605. while ($line = db_fetch_assoc($result)) {
  1606. array_push($ids, $line['id']);
  1607. }
  1608. if (count($ids) > 0) {
  1609. $ids = join(",", $ids);
  1610. $tmp_result = db_query("DELETE FROM ttrss_tags WHERE id IN ($ids)");
  1611. $tags_deleted += db_affected_rows($tmp_result);
  1612. } else {
  1613. break;
  1614. }
  1615. $limit -= $limit_part;
  1616. }
  1617. return $tags_deleted;
  1618. }
  1619. function print_user_stylesheet() {
  1620. $value = get_pref('USER_STYLESHEET');
  1621. if ($value) {
  1622. print "<style type=\"text/css\">";
  1623. print str_replace("<br/>", "\n", $value);
  1624. print "</style>";
  1625. }
  1626. }
  1627. function filter_to_sql($filter, $owner_uid) {
  1628. $query = array();
  1629. if (DB_TYPE == "pgsql")
  1630. $reg_qpart = "~";
  1631. else
  1632. $reg_qpart = "REGEXP";
  1633. foreach ($filter["rules"] AS $rule) {
  1634. $rule['reg_exp'] = str_replace('/', '\/', $rule["reg_exp"]);
  1635. $regexp_valid = preg_match('/' . $rule['reg_exp'] . '/',
  1636. $rule['reg_exp']) !== FALSE;
  1637. if ($regexp_valid) {
  1638. $rule['reg_exp'] = db_escape_string($rule['reg_exp']);
  1639. switch ($rule["type"]) {
  1640. case "title":
  1641. $qpart = "LOWER(ttrss_entries.title) $reg_qpart LOWER('".
  1642. $rule['reg_exp'] . "')";
  1643. break;
  1644. case "content":
  1645. $qpart = "LOWER(ttrss_entries.content) $reg_qpart LOWER('".
  1646. $rule['reg_exp'] . "')";
  1647. break;
  1648. case "both":
  1649. $qpart = "LOWER(ttrss_entries.title) $reg_qpart LOWER('".
  1650. $rule['reg_exp'] . "') OR LOWER(" .
  1651. "ttrss_entries.content) $reg_qpart LOWER('" . $rule['reg_exp'] . "')";
  1652. break;
  1653. case "tag":
  1654. $qpart = "LOWER(ttrss_user_entries.tag_cache) $reg_qpart LOWER('".
  1655. $rule['reg_exp'] . "')";
  1656. break;
  1657. case "link":
  1658. $qpart = "LOWER(ttrss_entries.link) $reg_qpart LOWER('".
  1659. $rule['reg_exp'] . "')";
  1660. break;
  1661. case "author":
  1662. $qpart = "LOWER(ttrss_entries.author) $reg_qpart LOWER('".
  1663. $rule['reg_exp'] . "')";
  1664. break;
  1665. }
  1666. if (isset($rule['inverse'])) $qpart = "NOT ($qpart)";
  1667. if (isset($rule["feed_id"]) && $rule["feed_id"] > 0) {
  1668. $qpart .= " AND feed_id = " . db_escape_string($rule["feed_id"]);
  1669. }
  1670. if (isset($rule["cat_id"])) {
  1671. if ($rule["cat_id"] > 0) {
  1672. $children = getChildCategories($rule["cat_id"], $owner_uid);
  1673. array_push($children, $rule["cat_id"]);
  1674. $children = join(",", $children);
  1675. $cat_qpart = "cat_id IN ($children)";
  1676. } else {
  1677. $cat_qpart = "cat_id IS NULL";
  1678. }
  1679. $qpart .= " AND $cat_qpart";
  1680. }
  1681. $qpart .= " AND feed_id IS NOT NULL";
  1682. array_push($query, "($qpart)");
  1683. }
  1684. }
  1685. if (count($query) > 0) {
  1686. $fullquery = "(" . join($filter["match_any_rule"] ? "OR" : "AND", $query) . ")";
  1687. } else {
  1688. $fullquery = "(false)";
  1689. }
  1690. if ($filter['inverse']) $fullquery = "(NOT $fullquery)";
  1691. return $fullquery;
  1692. }
  1693. if (!function_exists('gzdecode')) {
  1694. function gzdecode($string) { // no support for 2nd argument
  1695. return file_get_contents('compress.zlib://data:who/cares;base64,'.
  1696. base64_encode($string));
  1697. }
  1698. }
  1699. function get_random_bytes($length) {
  1700. if (function_exists('openssl_random_pseudo_bytes')) {
  1701. return openssl_random_pseudo_bytes($length);
  1702. } else {
  1703. $output = "";
  1704. for ($i = 0; $i < $length; $i++)
  1705. $output .= chr(mt_rand(0, 255));
  1706. return $output;
  1707. }
  1708. }
  1709. function read_stdin() {
  1710. $fp = fopen("php://stdin", "r");
  1711. if ($fp) {
  1712. $line = trim(fgets($fp));
  1713. fclose($fp);
  1714. return $line;
  1715. }
  1716. return null;
  1717. }
  1718. function tmpdirname($path, $prefix) {
  1719. // Use PHP's tmpfile function to create a temporary
  1720. // directory name. Delete the file and keep the name.
  1721. $tempname = tempnam($path,$prefix);
  1722. if (!$tempname)
  1723. return false;
  1724. if (!unlink($tempname))
  1725. return false;
  1726. return $tempname;
  1727. }
  1728. function getFeedCategory($feed) {
  1729. $result = db_query("SELECT cat_id FROM ttrss_feeds
  1730. WHERE id = '$feed'");
  1731. if (db_num_rows($result) > 0) {
  1732. return db_fetch_result($result, 0, "cat_id");
  1733. } else {
  1734. return false;
  1735. }
  1736. }
  1737. function implements_interface($class, $interface) {
  1738. return in_array($interface, class_implements($class));
  1739. }
  1740. function geturl($url, $depth = 0, $nobody = true){
  1741. if ($depth == 20) return $url;
  1742. if (!function_exists('curl_init'))
  1743. return user_error('CURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini', E_USER_ERROR);
  1744. $curl = curl_init();
  1745. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  1746. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  1747. $header[] = "Cache-Control: max-age=0";
  1748. $header[] = "Connection: keep-alive";
  1749. $header[] = "Keep-Alive: 300";
  1750. $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  1751. $header[] = "Accept-Language: en-us,en;q=0.5";
  1752. $header[] = "Pragma: ";
  1753. curl_setopt($curl, CURLOPT_URL, $url);
  1754. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
  1755. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  1756. curl_setopt($curl, CURLOPT_HEADER, true);
  1757. curl_setopt($curl, CURLOPT_NOBODY, $nobody);
  1758. curl_setopt($curl, CURLOPT_REFERER, $url);
  1759. curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  1760. curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  1761. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1762. //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled...
  1763. curl_setopt($curl, CURLOPT_TIMEOUT, 60);
  1764. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1765. if (defined('_CURL_HTTP_PROXY')) {
  1766. curl_setopt($curl, CURLOPT_PROXY, _CURL_HTTP_PROXY);
  1767. }
  1768. $html = curl_exec($curl);
  1769. $status = curl_getinfo($curl);
  1770. if($status['http_code']!=200){
  1771. // idiot site not allowing http head
  1772. if($status['http_code'] == 405) {
  1773. curl_close($curl);
  1774. return geturl($url, $depth +1, false);
  1775. }
  1776. if($status['http_code'] == 301 || $status['http_code'] == 302) {
  1777. curl_close($curl);
  1778. list($header) = explode("\r\n\r\n", $html, 2);
  1779. $matches = array();
  1780. preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
  1781. $url = trim(str_replace($matches[1],"",$matches[0]));
  1782. $url_parsed = parse_url($url);
  1783. return (isset($url_parsed))? geturl($url, $depth + 1):'';
  1784. }
  1785. global $fetch_last_error;
  1786. $fetch_last_error = curl_errno($curl) . " " . curl_error($curl);
  1787. curl_close($curl);
  1788. # $oline='';
  1789. # foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';}
  1790. # $line =$oline." \r\n ".$url."\r\n-----------------\r\n";
  1791. # $handle = @fopen('./curl.error.log', 'a');
  1792. # fwrite($handle, $line);
  1793. return FALSE;
  1794. }
  1795. curl_close($curl);
  1796. return $url;
  1797. }
  1798. function get_minified_js($files) {
  1799. require_once 'lib/jshrink/Minifier.php';
  1800. $rv = '';
  1801. foreach ($files as $js) {
  1802. if (!isset($_GET['debug'])) {
  1803. $cached_file = CACHE_DIR . "/js/".basename($js).".js";
  1804. if (file_exists($cached_file) && is_readable($cached_file) && filemtime($cached_file) >= filemtime("js/$js.js")) {
  1805. list($header, $contents) = explode("\n", file_get_contents($cached_file), 2);
  1806. if ($header && $contents) {
  1807. list($htag, $hversion) = explode(":", $header);
  1808. if ($htag == "tt-rss" && $hversion == VERSION) {
  1809. $rv .= $contents;
  1810. continue;
  1811. }
  1812. }
  1813. }
  1814. $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js"));
  1815. file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified);
  1816. $rv .= $minified;
  1817. } else {
  1818. $rv .= file_get_contents("js/$js.js"); // no cache in debug mode
  1819. }
  1820. }
  1821. return $rv;
  1822. }
  1823. function stylesheet_tag($filename) {
  1824. $timestamp = filemtime($filename);
  1825. return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
  1826. }
  1827. function javascript_tag($filename) {
  1828. $query = "";
  1829. if (!(strpos($filename, "?") === FALSE)) {
  1830. $query = substr($filename, strpos($filename, "?")+1);
  1831. $filename = substr($filename, 0, strpos($filename, "?"));
  1832. }
  1833. $timestamp = filemtime($filename);
  1834. if ($query) $timestamp .= "&$query";
  1835. return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
  1836. }
  1837. function calculate_dep_timestamp() {
  1838. $files = array_merge(glob("js/*.js"), glob("css/*.css"));
  1839. $max_ts = -1;
  1840. foreach ($files as $file) {
  1841. if (filemtime($file) > $max_ts) $max_ts = filemtime($file);
  1842. }
  1843. return $max_ts;
  1844. }
  1845. function T_js_decl($s1, $s2) {
  1846. if ($s1 && $s2) {
  1847. $s1 = preg_replace("/\n/", "", $s1);
  1848. $s2 = preg_replace("/\n/", "", $s2);
  1849. $s1 = preg_replace("/\"/", "\\\"", $s1);
  1850. $s2 = preg_replace("/\"/", "\\\"", $s2);
  1851. return "T_messages[\"$s1\"] = \"$s2\";\n";
  1852. }
  1853. }
  1854. function init_js_translations() {
  1855. print 'var T_messages = new Object();
  1856. function __(msg) {
  1857. if (T_messages[msg]) {
  1858. return T_messages[msg];
  1859. } else {
  1860. return msg;
  1861. }
  1862. }
  1863. function ngettext(msg1, msg2, n) {
  1864. return __((parseInt(n) > 1) ? msg2 : msg1);
  1865. }';
  1866. $l10n = _get_reader();
  1867. for ($i = 0; $i < $l10n->total; $i++) {
  1868. $orig = $l10n->get_original_string($i);
  1869. if(strpos($orig, "\000") !== FALSE) { // Plural forms
  1870. $key = explode(chr(0), $orig);
  1871. print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular
  1872. print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural
  1873. } else {
  1874. $translation = __($orig);
  1875. print T_js_decl($orig, $translation);
  1876. }
  1877. }
  1878. }
  1879. function label_to_feed_id($label) {
  1880. return LABEL_BASE_INDEX - 1 - abs($label);
  1881. }
  1882. function feed_to_label_id($feed) {
  1883. return LABEL_BASE_INDEX - 1 + abs($feed);
  1884. }
  1885. function theme_valid($file) {
  1886. if ($file == "default.css" || $file == "night.css") return true; // needed for array_filter
  1887. $file = "themes/" . basename($file);
  1888. if (file_exists($file) && is_readable($file)) {
  1889. $fh = fopen($file, "r");
  1890. if ($fh) {
  1891. $header = fgets($fh);
  1892. fclose($fh);
  1893. return strpos($header, "supports-version:" . VERSION_STATIC) !== FALSE;
  1894. }
  1895. }
  1896. return false;
  1897. }
  1898. function error_json($code) {
  1899. require_once "errors.php";
  1900. @$message = $ERRORS[$code];
  1901. return json_encode(array("error" =>
  1902. array("code" => $code, "message" => $message)));
  1903. }
  1904. function abs_to_rel_path($dir) {
  1905. $tmp = str_replace(dirname(__DIR__), "", $dir);
  1906. if (strlen($tmp) > 0 && substr($tmp, 0, 1) == "/") $tmp = substr($tmp, 1);
  1907. return $tmp;
  1908. }
  1909. ?>