backend.php 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880
  1. <?php
  2. require_once "sessions.php";
  3. require_once "backend-rpc.php";
  4. header("Cache-Control: no-cache, must-revalidate");
  5. header("Pragma: no-cache");
  6. header("Expires: -1");
  7. /* if ($_GET["debug"]) {
  8. define('DEFAULT_ERROR_LEVEL', E_ALL);
  9. } else {
  10. define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
  11. }
  12. error_reporting(DEFAULT_ERROR_LEVEL); */
  13. $op = $_REQUEST["op"];
  14. define('SCHEMA_VERSION', 9);
  15. require_once "sanity_check.php";
  16. require_once "config.php";
  17. require_once "db.php";
  18. require_once "db-prefs.php";
  19. require_once "functions.php";
  20. require_once "magpierss/rss_fetch.inc";
  21. $err_msg = check_configuration_variables();
  22. if ($err_msg) {
  23. header("Content-Type: application/xml");
  24. print_error_xml(9, $err_msg); die;
  25. }
  26. if ((!$op || $op == "rpc" || $op == "rss" ||
  27. $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
  28. header("Content-Type: application/xml");
  29. }
  30. if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss") {
  31. if ($op == "rpc") {
  32. print_error_xml(6); die;
  33. } else {
  34. print "
  35. <html><body>
  36. <p>Error: Not logged in.</p>
  37. <script type=\"text/javascript\">
  38. if (parent.window != 'undefined') {
  39. parent.window.location = \"login.php\";
  40. } else {
  41. window.location = \"login.php\";
  42. }
  43. </script>
  44. </body></html>
  45. ";
  46. }
  47. exit;
  48. }
  49. if (!$op) {
  50. print_error_xml(7); exit;
  51. }
  52. $purge_intervals = array(
  53. 0 => "Use default",
  54. -1 => "Never purge",
  55. 5 => "1 week old",
  56. 14 => "2 weeks old",
  57. 31 => "1 month old",
  58. 60 => "2 months old",
  59. 90 => "3 months old");
  60. $update_intervals = array(
  61. 0 => "Use default",
  62. -1 => "Disable updates",
  63. 30 => "Each 30 minutes",
  64. 60 => "Hourly",
  65. 240 => "Each 4 hours",
  66. 720 => "Each 12 hours",
  67. 1440 => "Daily",
  68. 10080 => "Weekly");
  69. $access_level_names = array(
  70. 0 => "User",
  71. 10 => "Administrator");
  72. $script_started = getmicrotime();
  73. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  74. if (!$link) {
  75. if (DB_TYPE == "mysql") {
  76. print mysql_error();
  77. }
  78. // PG seems to display its own errors just fine by default.
  79. return;
  80. }
  81. if (DB_TYPE == "pgsql") {
  82. pg_query("set client_encoding = 'utf-8'");
  83. }
  84. if ($_SESSION["uid"]) {
  85. // setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
  86. // setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
  87. /* if (get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED")) {
  88. setcookie('ttrss_vf_catchupnext', 1);
  89. } else {
  90. setcookie('ttrss_vf_catchupnext', 0);
  91. } */
  92. }
  93. $fetch = $_GET["fetch"];
  94. // setcookie("ttrss_icons_url", ICONS_URL);
  95. if (!sanity_check($link)) { return; }
  96. function outputFeedList($link, $tags = false) {
  97. print "<html><head>
  98. <title>Tiny Tiny RSS : Feedlist</title>
  99. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
  100. $user_theme = $_SESSION["theme"];
  101. if ($user_theme) {
  102. print "<link rel=\"stylesheet\" type=\"text/css\"
  103. href=\"themes/$user_theme/theme.css\">";
  104. }
  105. if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
  106. print "<link rel=\"stylesheet\" type=\"text/css\"
  107. href=\"tt-rss_compact.css\"/>";
  108. } else {
  109. print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
  110. type=\"text/css\" href=\"tt-rss_compact.css\"/>";
  111. }
  112. $script_dt_add = get_script_dt_add();
  113. print "
  114. <script type=\"text/javascript\" src=\"prototype.js\"></script>
  115. <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
  116. <script type=\"text/javascript\" src=\"feedlist.js?$script_dt_add\"></script>
  117. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  118. <!--[if gte IE 5.5000]>
  119. <script type=\"text/javascript\" src=\"pngfix.js\"></script>
  120. <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
  121. <![endif]-->
  122. </head><body>
  123. <script type=\"text/javascript\">
  124. if (document.addEventListener) {
  125. document.addEventListener(\"DOMContentLoaded\", init, null);
  126. }
  127. window.onload = init;
  128. </script>";
  129. print "<ul class=\"feedList\" id=\"feedList\">\n";
  130. $owner_uid = $_SESSION["uid"];
  131. if (!$tags) {
  132. /* virtual feeds */
  133. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  134. print "<li class=\"feedCat\">Special</li>";
  135. print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
  136. }
  137. $num_starred = getFeedUnread($link, -1);
  138. $class = "virt";
  139. if ($num_starred > 0) $class .= "Unread";
  140. printFeedEntry(-1, $class, "Starred articles", $num_starred,
  141. "images/mark_set.png", $link);
  142. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  143. print "</ul>\n";
  144. }
  145. if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
  146. $result = db_query($link, "SELECT id,sql_exp,description FROM
  147. ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
  148. if (db_num_rows($result) > 0) {
  149. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  150. print "<li class=\"feedCat\">Labels</li>";
  151. print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
  152. } else {
  153. print "<li><hr></li>";
  154. }
  155. }
  156. while ($line = db_fetch_assoc($result)) {
  157. error_reporting (0);
  158. $label_id = -$line['id'] - 11;
  159. $count = getFeedUnread($link, $label_id);
  160. $class = "label";
  161. if ($count > 0) {
  162. $class .= "Unread";
  163. }
  164. error_reporting (DEFAULT_ERROR_LEVEL);
  165. printFeedEntry($label_id,
  166. $class, db_unescape_string($line["description"]),
  167. $count, "images/label.png", $link);
  168. }
  169. if (db_num_rows($result) > 0) {
  170. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  171. print "</ul>";
  172. }
  173. }
  174. }
  175. // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
  176. print "<li><hr></li>";
  177. // }
  178. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  179. if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
  180. $order_by_qpart = "category,unread DESC,title";
  181. } else {
  182. $order_by_qpart = "category,title";
  183. }
  184. } else {
  185. if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
  186. $order_by_qpart = "unread DESC,title";
  187. } else {
  188. $order_by_qpart = "title";
  189. }
  190. }
  191. $result = db_query($link, "SELECT ttrss_feeds.*,
  192. SUBSTRING(last_updated,1,19) AS last_updated_noms,
  193. (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
  194. WHERE feed_id = ttrss_feeds.id AND
  195. ttrss_user_entries.ref_id = ttrss_entries.id AND
  196. owner_uid = '$owner_uid') AS total,
  197. (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
  198. WHERE feed_id = ttrss_feeds.id AND unread = true
  199. AND ttrss_user_entries.ref_id = ttrss_entries.id
  200. AND owner_uid = '$owner_uid') as unread,
  201. cat_id,last_error,
  202. ttrss_feed_categories.title AS category,
  203. ttrss_feed_categories.collapsed
  204. FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
  205. ON (ttrss_feed_categories.id = cat_id)
  206. WHERE
  207. ttrss_feeds.hidden = false AND
  208. ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
  209. ORDER BY $order_by_qpart");
  210. $actid = $_GET["actid"];
  211. /* real feeds */
  212. $lnum = 0;
  213. $total_unread = 0;
  214. $category = "";
  215. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  216. while ($line = db_fetch_assoc($result)) {
  217. $feed = db_unescape_string($line["title"]);
  218. $feed_id = $line["id"];
  219. $subop = $_GET["subop"];
  220. $total = $line["total"];
  221. $unread = $line["unread"];
  222. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  223. $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
  224. } else {
  225. $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
  226. }
  227. $rtl_content = sql_bool_to_bool($line["rtl_content"]);
  228. if ($rtl_content) {
  229. $rtl_tag = "dir=\"RTL\"";
  230. } else {
  231. $rtl_tag = "";
  232. }
  233. $tmp_result = db_query($link,
  234. "SELECT id,COUNT(unread) AS unread
  235. FROM ttrss_feeds LEFT JOIN ttrss_user_entries
  236. ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
  237. WHERE parent_feed = '$feed_id' AND unread = true
  238. GROUP BY ttrss_feeds.id");
  239. if (db_num_rows($tmp_result) > 0) {
  240. while ($l = db_fetch_assoc($tmp_result)) {
  241. $unread += $l["unread"];
  242. }
  243. }
  244. $cat_id = $line["cat_id"];
  245. $tmp_category = $line["category"];
  246. if (!$tmp_category) {
  247. $tmp_category = "Uncategorized";
  248. }
  249. // $class = ($lnum % 2) ? "even" : "odd";
  250. if ($line["last_error"]) {
  251. $class = "error";
  252. } else {
  253. $class = "feed";
  254. }
  255. if ($unread > 0) $class .= "Unread";
  256. if ($actid == $feed_id) {
  257. $class .= "Selected";
  258. }
  259. $total_unread += $unread;
  260. if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
  261. if ($category) {
  262. print "</ul></li>";
  263. }
  264. $category = $tmp_category;
  265. $collapsed = $line["collapsed"];
  266. // workaround for NULL category
  267. if ($category == "Uncategorized") {
  268. if ($_COOKIE["ttrss_vf_uclps"] == 1) {
  269. $collapsed = "t";
  270. }
  271. }
  272. if ($collapsed == "t" || $collapsed == "1") {
  273. $holder_class = "invisible";
  274. $ellipsis = "...";
  275. } else {
  276. $holder_class = "";
  277. $ellipsis = "";
  278. }
  279. $cat_id = sprintf("%d", $cat_id);
  280. $cat_unread = getCategoryUnread($link, $cat_id);
  281. print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
  282. <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
  283. <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
  284. <span id=\"FCATCTR-$cat_id\"
  285. class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
  286. </a></li>";
  287. // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
  288. // -> keyboard navigation, etc.
  289. print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
  290. }
  291. printFeedEntry($feed_id, $class, $feed, $unread,
  292. "icons/$feed_id.ico", $link, $rtl_content,
  293. $last_updated, $line["last_error"]);
  294. ++$lnum;
  295. }
  296. } else {
  297. // tags
  298. /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
  299. FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
  300. post_int_id = ttrss_user_entries.int_id AND
  301. unread = true AND ref_id = ttrss_entries.id
  302. AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
  303. UNION
  304. select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
  305. ORDER BY tag_name"); */
  306. $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
  307. FROM ttrss_user_entries WHERE int_id = post_int_id
  308. AND unread = true)) AS count FROM ttrss_tags
  309. WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
  310. $tags = array();
  311. while ($line = db_fetch_assoc($result)) {
  312. $tags[$line["tag_name"]] += $line["count"];
  313. }
  314. foreach (array_keys($tags) as $tag) {
  315. $unread = $tags[$tag];
  316. $class = "tag";
  317. if ($unread > 0) {
  318. $class .= "Unread";
  319. }
  320. printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
  321. }
  322. }
  323. if (db_num_rows($result) == 0) {
  324. if ($tags) {
  325. $what = "tags";
  326. } else {
  327. $what = "feeds";
  328. }
  329. print "<li>No $what to display.</li>";
  330. }
  331. print "</ul>";
  332. print '
  333. <script type="text/javascript">
  334. /* for IE */
  335. function statechange() {
  336. if (document.readyState == "interactive") init();
  337. }
  338. if (document.readyState) {
  339. if (document.readyState == "interactive" || document.readyState == "complete") {
  340. init();
  341. } else {
  342. document.onreadystatechange = statechange;
  343. }
  344. }
  345. </script></body></html>';
  346. }
  347. if ($op == "rpc") {
  348. handle_rpc_request($link);
  349. }
  350. if ($op == "feeds") {
  351. $tags = $_GET["tags"];
  352. $subop = $_GET["subop"];
  353. if ($subop == "catchupAll") {
  354. db_query($link, "UPDATE ttrss_user_entries SET
  355. last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
  356. }
  357. if ($subop == "collapse") {
  358. $cat_id = db_escape_string($_GET["cid"]);
  359. db_query($link, "UPDATE ttrss_feed_categories SET
  360. collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
  361. $_SESSION["uid"]);
  362. return;
  363. }
  364. outputFeedList($link, $tags);
  365. }
  366. if ($op == "view") {
  367. $id = db_escape_string($_GET["id"]);
  368. $feed_id = db_escape_string($_GET["feed"]);
  369. $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
  370. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  371. if (db_num_rows($result) == 1) {
  372. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  373. } else {
  374. $rtl_content = false;
  375. }
  376. if ($rtl_content) {
  377. $rtl_tag = "dir=\"RTL\"";
  378. $rtl_class = "RTL";
  379. } else {
  380. $rtl_tag = "";
  381. $rtl_class = "";
  382. }
  383. $result = db_query($link, "UPDATE ttrss_user_entries
  384. SET unread = false,last_read = NOW()
  385. WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  386. $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
  387. SUBSTRING(updated,1,16) as updated,
  388. (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
  389. num_comments,
  390. author
  391. FROM ttrss_entries,ttrss_user_entries
  392. WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
  393. print "<html><head>
  394. <title>Tiny Tiny RSS : Article $id</title>
  395. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
  396. $user_theme = $_SESSION["theme"];
  397. if ($user_theme) {
  398. print "<link rel=\"stylesheet\" type=\"text/css\"
  399. href=\"themes/$user_theme/theme.css\">";
  400. }
  401. if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
  402. print "<link rel=\"stylesheet\" type=\"text/css\"
  403. href=\"tt-rss_compact.css\"/>";
  404. } else {
  405. print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
  406. type=\"text/css\" href=\"tt-rss_compact.css\"/>";
  407. }
  408. $script_dt_add = get_script_dt_add();
  409. print "
  410. <script type=\"text/javascript\" src=\"prototype.js\"></script>
  411. <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
  412. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  413. </head><body $rtl_tag>";
  414. if ($result) {
  415. $link_target = "";
  416. if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
  417. $link_target = "target=\"_new\"";
  418. }
  419. $line = db_fetch_assoc($result);
  420. if ($line["icon_url"]) {
  421. $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
  422. } else {
  423. $feed_icon = "&nbsp;";
  424. }
  425. /* if ($line["comments"] && $line["link"] != $line["comments"]) {
  426. $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
  427. } else {
  428. $entry_comments = "";
  429. } */
  430. $num_comments = $line["num_comments"];
  431. $entry_comments = "";
  432. if ($num_comments > 0) {
  433. if ($line["comments"]) {
  434. $comments_url = $line["comments"];
  435. } else {
  436. $comments_url = $line["link"];
  437. }
  438. $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
  439. } else {
  440. if ($line["comments"] && $line["link"] != $line["comments"]) {
  441. $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
  442. }
  443. }
  444. print "<div class=\"postReply\">";
  445. print "<div class=\"postHeader\"><table width=\"100%\">";
  446. $entry_author = $line["author"];
  447. if ($entry_author) {
  448. $entry_author = " - by $entry_author";
  449. }
  450. print "<tr><td><a $link_target href=\"" . $line["link"] . "\">" . $line["title"] .
  451. "</a>$entry_author</td>";
  452. $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
  453. strtotime($line["updated"]));
  454. print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
  455. print "</tr>";
  456. $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
  457. ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
  458. ORDER BY tag_name");
  459. $tags_str = "";
  460. $f_tags_str = "";
  461. $num_tags = 0;
  462. while ($tmp_line = db_fetch_assoc($tmp_result)) {
  463. $num_tags++;
  464. $tag = $tmp_line["tag_name"];
  465. $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
  466. if ($num_tags == 5) {
  467. $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
  468. } else if ($num_tags < 5) {
  469. $tags_str .= $tag_str;
  470. }
  471. $f_tags_str .= $tag_str;
  472. }
  473. $tags_str = preg_replace("/, $/", "", $tags_str);
  474. $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
  475. // $truncated_link = truncate_string($line["link"], 60);
  476. if ($tags_str || $entry_comments) {
  477. print "<tr><td width='50%'>
  478. $entry_comments</td>
  479. <td align=\"right\">$tags_str</td></tr>";
  480. }
  481. print "</table></div>";
  482. print "<div class=\"postIcon\">" . $feed_icon . "</div>";
  483. print "<div class=\"postContent\">";
  484. if (db_num_rows($tmp_result) > 5) {
  485. print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
  486. }
  487. if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
  488. $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
  489. }
  490. print $line["content"] . "</div>";
  491. print "</div>";
  492. print "<script type=\"text/javascript\">
  493. try {
  494. parent.update_all_counters('$feed_id');
  495. } catch (e) {
  496. exception_error('view/footer', e);
  497. }
  498. </script>";
  499. }
  500. print "</body></html>";
  501. }
  502. if ($op == "viewfeed") {
  503. $feed = db_escape_string($_GET["feed"]);
  504. $subop = db_escape_string($_GET["subop"]);
  505. $view_mode = db_escape_string($_GET["view_mode"]);
  506. $limit = db_escape_string($_GET["limit"]);
  507. $cat_view = db_escape_string($_GET["cat"]);
  508. $next_unread_feed = db_escape_string($_GET["nuf"]);
  509. if ($subop == "undefined") $subop = "";
  510. print "<html><head>
  511. <title>Tiny Tiny RSS : Feed $feed</title>
  512. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
  513. $user_theme = $_SESSION["theme"];
  514. if ($user_theme) {
  515. print "<link rel=\"stylesheet\" type=\"text/css\"
  516. href=\"themes/$user_theme/theme.css\">";
  517. }
  518. if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
  519. print "<link rel=\"stylesheet\"
  520. type=\"text/css\" href=\"tt-rss_compact.css\"/>";
  521. } else {
  522. print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
  523. type=\"text/css\" href=\"tt-rss_compact.css\"/>";
  524. }
  525. if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
  526. update_generic_feed($link, $feed, $cat_view);
  527. }
  528. if ($subop == "MarkAllRead") {
  529. catchup_feed($link, $feed, $cat_view);
  530. if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
  531. if ($next_unread_feed) {
  532. $feed = $next_unread_feed;
  533. }
  534. }
  535. }
  536. if ($feed_id > 0) {
  537. $result = db_query($link,
  538. "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
  539. if (db_num_rows($result) == 0) {
  540. print "<div align='center'>
  541. Feed not found.</div>";
  542. return;
  543. }
  544. }
  545. if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
  546. $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
  547. WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
  548. if (db_num_rows($result) == 1) {
  549. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  550. } else {
  551. $rtl_content = false;
  552. }
  553. if ($rtl_content) {
  554. $rtl_tag = "dir=\"RTL\"";
  555. } else {
  556. $rtl_tag = "";
  557. }
  558. } else {
  559. $rtl_tag = "";
  560. $rtl_content = false;
  561. }
  562. $script_dt_add = get_script_dt_add();
  563. print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  564. <script type=\"text/javascript\" src=\"prototype.js\"></script>
  565. <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
  566. <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
  567. <!--[if gte IE 5.5000]>
  568. <script type=\"text/javascript\" src=\"pngfix.js\"></script>
  569. <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
  570. <![endif]-->
  571. </head><body $rtl_tag>
  572. <script type=\"text/javascript\">
  573. if (document.addEventListener) {
  574. document.addEventListener(\"DOMContentLoaded\", init, null);
  575. }
  576. window.onload = init;
  577. </script>";
  578. /// START /////////////////////////////////////////////////////////////////////////////////
  579. $search = db_escape_string($_GET["query"]);
  580. $search_mode = db_escape_string($_GET["search_mode"]);
  581. $match_on = db_escape_string($_GET["match_on"]);
  582. if (!$match_on) {
  583. $match_on = "both";
  584. }
  585. $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on);
  586. $result = $qfh_ret[0];
  587. $feed_title = $qfh_ret[1];
  588. $feed_site_url = $qfh_ret[2];
  589. $last_error = $qfh_ret[3];
  590. /// STOP //////////////////////////////////////////////////////////////////////////////////
  591. print "<div id=\"headlinesContainer\">";
  592. if (!$result) {
  593. print "<div align='center'>
  594. Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
  595. return;
  596. }
  597. function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
  598. $bottom = false, $rtl_content = false, $feed_id = 0,
  599. $is_cat = false, $search = false, $match_on = false,
  600. $search_mode = false) {
  601. if (!$bottom) {
  602. $class = "headlinesSubToolbar";
  603. $tid = "headlineActionsTop";
  604. } else {
  605. $class = "invisible";
  606. $tid = "headlineActionsBottom";
  607. }
  608. print "<table class=\"$class\" id=\"$tid\"
  609. width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
  610. if ($rtl_content) {
  611. $rtl_cpart = "RTL";
  612. } else {
  613. $rtl_cpart = "";
  614. }
  615. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  616. print "<td class=\"headlineActions$rtl_cpart\">
  617. Select:
  618. <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
  619. <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
  620. <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
  621. &nbsp;&nbsp;
  622. Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
  623. <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
  624. print "</td>";
  625. if ($search && $feed_id > 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
  626. print "<td class=\"headlineActions$rtl_cpart\">
  627. <a href=\"javascript:labelFromSearch('$search', '$search_mode',
  628. '$match_on', '$feed_id', '$is_cat');\">
  629. Convert this search to label</a></td>";
  630. }
  631. } else {
  632. print "<td class=\"headlineActions$rtl_cpart\">
  633. Select:
  634. <a href=\"javascript:cdmSelectArticles('all')\">All</a>,
  635. <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
  636. <a href=\"javascript:cdmSelectArticles('none')\">None</a>
  637. &nbsp;&nbsp;
  638. Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>,
  639. <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>";
  640. print "</td>";
  641. }
  642. print "<td class=\"headlineTitle$rtl_cpart\">";
  643. if ($feed_site_url) {
  644. if (!$bottom) {
  645. $target = "target=\"_blank\"";
  646. }
  647. print "<a $target href=\"$feed_site_url\">$feed_title</a>";
  648. } else {
  649. print $feed_title;
  650. }
  651. if ($search) {
  652. $search_q = "&q=$search&m=$match_on&smode=$search_mode";
  653. }
  654. if (!$bottom) {
  655. print "&nbsp;
  656. <a target=\"_new\"
  657. href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\"
  658. <img class=\"noborder\"
  659. alt=\"Generated feed\" src=\"images/feed-icon-12x12.png\">
  660. </a>";
  661. }
  662. print "</td>";
  663. print "</tr></table>";
  664. }
  665. if (db_num_rows($result) > 0) {
  666. print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
  667. $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode);
  668. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  669. print "<table class=\"headlinesList\" id=\"headlinesList\"
  670. cellspacing=\"0\" width=\"100%\">";
  671. }
  672. $lnum = 0;
  673. error_reporting (DEFAULT_ERROR_LEVEL);
  674. $num_unread = 0;
  675. while ($line = db_fetch_assoc($result)) {
  676. $class = ($lnum % 2) ? "even" : "odd";
  677. $id = $line["id"];
  678. $feed_id = $line["feed_id"];
  679. if ($line["last_read"] == "" &&
  680. ($line["unread"] != "t" && $line["unread"] != "1")) {
  681. $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
  682. alt=\"Updated\">";
  683. } else {
  684. $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
  685. alt=\"Updated\">";
  686. }
  687. if ($line["unread"] == "t" || $line["unread"] == "1") {
  688. $class .= "Unread";
  689. ++$num_unread;
  690. $is_unread = true;
  691. } else {
  692. $is_unread = false;
  693. }
  694. if ($line["marked"] == "t" || $line["marked"] == "1") {
  695. $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
  696. alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
  697. } else {
  698. $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
  699. alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
  700. }
  701. $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
  702. $line["title"] . "</a>";
  703. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  704. $updated_fmt = smart_date_time(strtotime($line["updated"]));
  705. } else {
  706. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  707. $updated_fmt = date($short_date, strtotime($line["updated"]));
  708. }
  709. if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
  710. $content_preview = truncate_string(strip_tags($line["content_preview"]),
  711. 100);
  712. }
  713. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  714. print "<tr class='$class' id='RROW-$id'>";
  715. print "<td class='hlUpdatePic'>$update_pic</td>";
  716. print "<td class='hlSelectRow'>
  717. <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
  718. class=\"feedCheckBox\" id=\"RCHK-$id\">
  719. </td>";
  720. print "<td class='hlMarkedPic'>$marked_pic</td>";
  721. if ($line["feed_title"]) {
  722. print "<td class='hlContent'>$content_link</td>";
  723. print "<td class='hlFeed'>
  724. <a href='javascript:viewfeed($feed_id)'>".
  725. $line["feed_title"]."</a>&nbsp;</td>";
  726. } else {
  727. print "<td class='hlContent' valign='middle'>";
  728. print "<a href=\"javascript:view($id,$feed_id);\">" .
  729. $line["title"];
  730. if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
  731. if ($content_preview) {
  732. print "<span class=\"contentPreview\"> - $content_preview</span>";
  733. }
  734. }
  735. print "</a>";
  736. print "</td>";
  737. }
  738. print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
  739. print "</tr>";
  740. } else {
  741. if ($is_unread) {
  742. $add_class = "Unread";
  743. } else {
  744. $add_class = "";
  745. }
  746. print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
  747. print "<div class=\"cdmHeader\">";
  748. print "<div style=\"float : right\">$updated_fmt,
  749. <a class=\"cdmToggleLink\"
  750. href=\"javascript:toggleUnread($id)\">Toggle unread</a>
  751. </div>";
  752. print "<a class=\"title\"
  753. onclick=\"javascript:toggleUnread($id, 0)\"
  754. target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
  755. if ($line["feed_title"]) {
  756. print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
  757. }
  758. print "</div>";
  759. print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
  760. print "<div style=\"float : right\">$marked_pic</div>
  761. <div lass=\"cdmFooter\">
  762. <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
  763. 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
  764. # print "<div align=\"center\"><a class=\"cdmToggleLink\"
  765. # href=\"javascript:toggleUnread($id)\">
  766. # Toggle unread</a></div>";
  767. print "</div>";
  768. }
  769. ++$lnum;
  770. }
  771. if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
  772. print "</table>";
  773. }
  774. print_headline_subtoolbar($link,
  775. "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
  776. } else {
  777. print "<div width='100%' align='center'>No articles found.</div>";
  778. }
  779. print "</div>";
  780. print "
  781. <script type=\"text/javascript\">
  782. try {
  783. document.onkeydown = hotkey_handler;
  784. try {
  785. parent.update_all_counters(\"$feed\");
  786. } catch (e) {
  787. // this is workaround against mysterious permission
  788. // denied feature/bug of firefox (ticket #73)
  789. // if call from this context failed - ignore silently
  790. exception_error(\"viewfeed/footer1/counters\", e, true);
  791. }
  792. } catch (e) {
  793. exception_error(\"viewfeed/footer1\", e);
  794. }
  795. /* for IE */
  796. function statechange() {
  797. if (document.readyState == \"interactive\") init();
  798. }
  799. if (document.readyState) {
  800. if (document.readyState == \"interactive\" || document.readyState == \"complete\") {
  801. init();
  802. } else {
  803. document.onreadystatechange = statechange;
  804. }
  805. }
  806. </script>";
  807. print "</body></html>";
  808. }
  809. if ($op == "pref-feeds") {
  810. $subop = $_REQUEST["subop"];
  811. $quiet = $_REQUEST["quiet"];
  812. if ($subop == "massSubscribe") {
  813. $ids = split(",", db_escape_string($_GET["ids"]));
  814. $subscribed = array();
  815. foreach ($ids as $id) {
  816. $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
  817. WHERE id = '$id'");
  818. $feed_url = db_fetch_result($result, 0, "feed_url");
  819. $title = db_fetch_result($result, 0, "title");
  820. $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
  821. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  822. if (db_num_rows($result) == 0) {
  823. $result = db_query($link,
  824. "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
  825. VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
  826. array_push($subscribed, $title);
  827. }
  828. }
  829. if (count($subscribed) > 0) {
  830. print "<div class=\"notice\">";
  831. print "<b>Subscribed to feeds:</b>";
  832. print "<ul class=\"nomarks\">";
  833. foreach ($subscribed as $title) {
  834. print "<li>$title</li>";
  835. }
  836. print "</ul>";
  837. print "</div>";
  838. }
  839. }
  840. if ($subop == "browse") {
  841. if (!ENABLE_FEED_BROWSER) {
  842. print "Feed browser is administratively disabled.";
  843. return;
  844. }
  845. print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
  846. print "<div class=\"infoBoxContents\">";
  847. print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
  848. # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
  849. # FROM ttrss_feeds
  850. # WHERE auth_login = '' AND auth_pass = '' AND private = false
  851. # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
  852. $owner_uid = $_SESSION["uid"];
  853. $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
  854. FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
  855. WHERE tf.feed_url = ttrss_feeds.feed_url
  856. AND owner_uid = '$owner_uid') GROUP BY feed_url
  857. ORDER BY subscribers DESC LIMIT 25");
  858. print "<ul class='browseFeedList' id='browseFeedList'>";
  859. $feedctr = 0;
  860. while ($line = db_fetch_assoc($result)) {
  861. $feed_url = $line["feed_url"];
  862. $subscribers = $line["subscribers"];
  863. $det_result = db_query($link, "SELECT site_url,title,id
  864. FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
  865. $details = db_fetch_assoc($det_result);
  866. $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
  867. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  868. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
  869. "/".$details["id"].".ico\">";
  870. } else {
  871. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
  872. }
  873. $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
  874. type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
  875. $class = ($feedctr % 2) ? "even" : "odd";
  876. print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
  877. "$feed_icon " . db_unescape_string($details["title"]) .
  878. "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
  879. ++$feedctr;
  880. }
  881. if ($feedctr == 0) {
  882. print "<li>No feeds found to subscribe.</li>";
  883. }
  884. print "</ul>";
  885. print "<div align='center'>
  886. <input type=\"submit\" class=\"button\"
  887. onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
  888. <input type='submit' class='button'
  889. onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
  890. print "</div>";
  891. return;
  892. }
  893. if ($subop == "editfeed") {
  894. $feed_id = db_escape_string($_REQUEST["id"]);
  895. $result = db_query($link,
  896. "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
  897. owner_uid = " . $_SESSION["uid"]);
  898. $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
  899. 0, "title")));
  900. $icon_file = ICONS_DIR . "/$feed_id.ico";
  901. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  902. $feed_icon = "<img width=\"16\" height=\"16\"
  903. src=\"" . ICONS_URL . "/$feed_id.ico\">";
  904. } else {
  905. $feed_icon = "";
  906. }
  907. print "<div id=\"infoBoxTitle\">Feed editor</div>";
  908. print "<div class=\"infoBoxContents\">";
  909. print "<form id=\"edit_feed_form\">";
  910. print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
  911. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  912. print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
  913. print "<table width='100%'>";
  914. print "<tr><td>Title:</td>";
  915. print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
  916. name=\"title\" value=\"$title\"></td></tr>";
  917. $feed_url = db_fetch_result($result, 0, "feed_url");
  918. $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
  919. 0, "feed_url")));
  920. print "<tr><td>Feed URL:</td>";
  921. print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
  922. name=\"feed_url\" value=\"$feed_url\"></td></tr>";
  923. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  924. $cat_id = db_fetch_result($result, 0, "cat_id");
  925. print "<tr><td>Category:</td>";
  926. print "<td>";
  927. print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\"");
  928. print "</td>";
  929. print "</td></tr>";
  930. }
  931. $update_interval = db_fetch_result($result, 0, "update_interval");
  932. print "<tr><td>Update Interval:</td>";
  933. print "<td>";
  934. print_select_hash("update_interval", $update_interval, $update_intervals,
  935. "class=\"iedit\"");
  936. print "</td>";
  937. print "<tr><td>Link to:</td><td>";
  938. $tmp_result = db_query($link, "SELECT COUNT(id) AS count
  939. FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
  940. $linked_count = db_fetch_result($tmp_result, 0, "count");
  941. $parent_feed = db_fetch_result($result, 0, "parent_feed");
  942. if ($linked_count > 0) {
  943. $disabled = "disabled";
  944. }
  945. print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
  946. print "<option value=\"0\">Not linked</option>";
  947. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  948. if ($cat_id) {
  949. $cat_qpart = "AND cat_id = '$cat_id'";
  950. } else {
  951. $cat_qpart = "AND cat_id IS NULL";
  952. }
  953. }
  954. $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
  955. WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
  956. $cat_qpart ORDER BY title");
  957. if (db_num_rows($tmp_result) > 0) {
  958. print "<option disabled>--------</option>";
  959. }
  960. while ($tmp_line = db_fetch_assoc($tmp_result)) {
  961. if ($tmp_line["id"] == $parent_feed) {
  962. $is_selected = "selected";
  963. } else {
  964. $is_selected = "";
  965. }
  966. printf("<option $is_selected value='%d'>%s</option>",
  967. $tmp_line["id"], $tmp_line["title"]);
  968. }
  969. print "</select>";
  970. print "</td></tr>";
  971. $purge_interval = db_fetch_result($result, 0, "purge_interval");
  972. print "<tr><td>Article purging:</td>";
  973. print "<td>";
  974. print_select_hash("purge_interval", $purge_interval, $purge_intervals,
  975. "class=\"iedit\"");
  976. print "</td>";
  977. $auth_login = db_fetch_result($result, 0, "auth_login");
  978. print "<tr><td>Login:</td>";
  979. print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
  980. name=\"auth_login\" value=\"$auth_login\"></td></tr>";
  981. $auth_pass = db_fetch_result($result, 0, "auth_pass");
  982. print "<tr><td>Password:</td>";
  983. print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
  984. onkeypress=\"return filterCR(event)\"
  985. value=\"$auth_pass\"></td></tr>";
  986. $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
  987. if ($private) {
  988. $checked = "checked";
  989. } else {
  990. $checked = "";
  991. }
  992. print "<tr><td valign='top'>Options:</td>";
  993. print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
  994. $checked><label for=\"private\">Hide from \"Other Feeds\"</label>";
  995. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  996. if ($rtl_content) {
  997. $checked = "checked";
  998. } else {
  999. $checked = "";
  1000. }
  1001. print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
  1002. $checked><label for=\"rtl_content\">Right-to-left content</label>";
  1003. $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
  1004. if ($hidden) {
  1005. $checked = "checked";
  1006. } else {
  1007. $checked = "";
  1008. }
  1009. print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
  1010. $checked><label for=\"hidden\">Hide from my feed list</label>";
  1011. print "</td></tr>";
  1012. print "</table>";
  1013. print "</form>";
  1014. print "<div align='right'>
  1015. <input type=\"submit\" class=\"button\"
  1016. onclick=\"return feedEditSave()\" value=\"Save\">
  1017. <input type='submit' class='button'
  1018. onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
  1019. print "</div>";
  1020. return;
  1021. }
  1022. if ($subop == "editSave") {
  1023. $feed_title = db_escape_string(trim($_POST["title"]));
  1024. $feed_link = db_escape_string(trim($_POST["feed_url"]));
  1025. $upd_intl = db_escape_string($_POST["update_interval"]);
  1026. $purge_intl = db_escape_string($_POST["purge_interval"]);
  1027. $feed_id = db_escape_string($_POST["id"]);
  1028. $cat_id = db_escape_string($_POST["cat_id"]);
  1029. $auth_login = db_escape_string(trim($_POST["auth_login"]));
  1030. $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
  1031. $parent_feed = db_escape_string($_POST["parent_feed"]);
  1032. $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
  1033. $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
  1034. $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
  1035. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  1036. if ($cat_id && $cat_id != 0) {
  1037. $category_qpart = "cat_id = '$cat_id',";
  1038. } else {
  1039. $category_qpart = 'cat_id = NULL,';
  1040. }
  1041. } else {
  1042. $category_qpart = "";
  1043. }
  1044. if ($parent_feed && $parent_feed != 0) {
  1045. $parent_qpart = "parent_feed = '$parent_feed',";
  1046. } else {
  1047. $parent_qpart = 'parent_feed = NULL,';
  1048. }
  1049. $result = db_query($link, "UPDATE ttrss_feeds SET
  1050. $category_qpart
  1051. $parent_qpart
  1052. title = '$feed_title', feed_url = '$feed_link',
  1053. update_interval = '$upd_intl',
  1054. purge_interval = '$purge_intl',
  1055. auth_login = '$auth_login',
  1056. auth_pass = '$auth_pass',
  1057. private = $private,
  1058. rtl_content = $rtl_content,
  1059. hidden = $hidden
  1060. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  1061. }
  1062. if ($subop == "saveCat") {
  1063. $cat_title = db_escape_string(trim($_GET["title"]));
  1064. $cat_id = db_escape_string($_GET["id"]);
  1065. $result = db_query($link, "UPDATE ttrss_feed_categories SET
  1066. title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
  1067. }
  1068. if ($subop == "remove") {
  1069. if (!WEB_DEMO_MODE) {
  1070. $ids = split(",", db_escape_string($_GET["ids"]));
  1071. foreach ($ids as $id) {
  1072. if ($id > 0) {
  1073. db_query($link, "DELETE FROM ttrss_feeds
  1074. WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  1075. $icons_dir = ICONS_DIR;
  1076. if (file_exists($icons_dir . "/$id.ico")) {
  1077. unlink($icons_dir . "/$id.ico");
  1078. }
  1079. } else if ($id < -10) {
  1080. $label_id = -$id - 11;
  1081. db_query($link, "DELETE FROM ttrss_labels
  1082. WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. if ($subop == "add") {
  1088. if (!WEB_DEMO_MODE) {
  1089. $feed_url = db_escape_string(trim($_GET["feed_url"]));
  1090. $cat_id = db_escape_string($_GET["cat_id"]);
  1091. if (subscribe_to_feed($link, $feed_url, $cat_id)) {
  1092. print "Added feed.";
  1093. } else {
  1094. print "<div class=\"warning\">
  1095. Feed <b>$feed_url</b> already exists in the database.
  1096. </div>";
  1097. }
  1098. }
  1099. }
  1100. if ($subop == "addCat") {
  1101. if (!WEB_DEMO_MODE) {
  1102. $feed_cat = db_escape_string(trim($_GET["cat"]));
  1103. $result = db_query($link,
  1104. "SELECT id FROM ttrss_feed_categories
  1105. WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
  1106. if (db_num_rows($result) == 0) {
  1107. $result = db_query($link,
  1108. "INSERT INTO ttrss_feed_categories (owner_uid,title)
  1109. VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
  1110. } else {
  1111. print "<div class=\"warning\">
  1112. Category <b>$feed_cat</b> already exists in the database.
  1113. </div>";
  1114. }
  1115. }
  1116. }
  1117. if ($subop == "removeCats") {
  1118. if (!WEB_DEMO_MODE) {
  1119. $ids = split(",", db_escape_string($_GET["ids"]));
  1120. foreach ($ids as $id) {
  1121. db_query($link, "BEGIN");
  1122. $result = db_query($link,
  1123. "SELECT count(id) as num_feeds FROM ttrss_feeds
  1124. WHERE cat_id = '$id'");
  1125. $num_feeds = db_fetch_result($result, 0, "num_feeds");
  1126. if ($num_feeds == 0) {
  1127. db_query($link, "DELETE FROM ttrss_feed_categories
  1128. WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  1129. } else {
  1130. print "<div class=\"warning\">
  1131. Unable to delete non empty feed categories.</div>";
  1132. }
  1133. db_query($link, "COMMIT");
  1134. }
  1135. }
  1136. }
  1137. if ($subop == "categorize") {
  1138. if (!WEB_DEMO_MODE) {
  1139. $ids = split(",", db_escape_string($_GET["ids"]));
  1140. $cat_id = db_escape_string($_GET["cat_id"]);
  1141. if ($cat_id == 0) {
  1142. $cat_id_qpart = 'NULL';
  1143. } else {
  1144. $cat_id_qpart = "'$cat_id'";
  1145. }
  1146. db_query($link, "BEGIN");
  1147. foreach ($ids as $id) {
  1148. db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
  1149. WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  1150. }
  1151. db_query($link, "COMMIT");
  1152. }
  1153. }
  1154. if ($quiet) return;
  1155. // print "<h3>Edit Feeds</h3>";
  1156. $result = db_query($link, "SELECT id,title,feed_url,last_error
  1157. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  1158. if (db_num_rows($result) > 0) {
  1159. print "<div class=\"warning\">";
  1160. // print"<img class=\"closeButton\"
  1161. // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
  1162. print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
  1163. <b>Some feeds have update errors (click for details)</b></a>";
  1164. print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
  1165. while ($line = db_fetch_assoc($result)) {
  1166. print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
  1167. $line["last_error"];
  1168. }
  1169. print "</ul>";
  1170. print "</div>";
  1171. }
  1172. $feed_search = db_escape_string($_GET["search"]);
  1173. if (array_key_exists("search", $_GET)) {
  1174. $_SESSION["prefs_feed_search"] = $feed_search;
  1175. } else {
  1176. $feed_search = $_SESSION["prefs_feed_search"];
  1177. }
  1178. print "<table width='100%' class=\"prefGenericAddBox\"
  1179. cellspacing='0' cellpadding='0'><tr>
  1180. <td>
  1181. <input id=\"fadd_link\"
  1182. onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
  1183. size=\"40\">
  1184. <input type=\"submit\" class=\"button\"
  1185. disabled=\"true\" id=\"fadd_submit_btn\"
  1186. onclick=\"addFeed()\" value=\"Subscribe\">";
  1187. if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
  1188. print " <input type=\"submit\" class=\"button\"
  1189. onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
  1190. }
  1191. print "</td><td align='right'>
  1192. <input id=\"feed_search\" size=\"20\"
  1193. onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
  1194. <input type=\"submit\" class=\"button\"
  1195. onclick=\"javascript:updateFeedList()\" value=\"Search\">
  1196. </td>
  1197. </tr></table>";
  1198. $feeds_sort = db_escape_string($_GET["sort"]);
  1199. if (!$feeds_sort || $feeds_sort == "undefined") {
  1200. $feeds_sort = $_SESSION["pref_sort_feeds"];
  1201. if (!$feeds_sort) $feeds_sort = "title";
  1202. }
  1203. $_SESSION["pref_sort_feeds"] = $feeds_sort;
  1204. if ($feed_search) {
  1205. $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
  1206. UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
  1207. } else {
  1208. $search_qpart = "";
  1209. }
  1210. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  1211. $order_by_qpart = "category,$feeds_sort,title";
  1212. } else {
  1213. $order_by_qpart = "$feeds_sort,title";
  1214. }
  1215. $result = db_query($link, "SELECT
  1216. F1.id,
  1217. F1.title,
  1218. F1.feed_url,
  1219. substring(F1.last_updated,1,16) AS last_updated,
  1220. F1.parent_feed,
  1221. F1.update_interval,
  1222. F1.purge_interval,
  1223. F1.cat_id,
  1224. F2.title AS parent_title,
  1225. C1.title AS category,
  1226. F1.hidden
  1227. FROM
  1228. ttrss_feeds AS F1
  1229. LEFT JOIN ttrss_feeds AS F2
  1230. ON (F1.parent_feed = F2.id)
  1231. LEFT JOIN ttrss_feed_categories AS C1
  1232. ON (F1.cat_id = C1.id)
  1233. WHERE
  1234. $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
  1235. ORDER by $order_by_qpart");
  1236. if (db_num_rows($result) != 0) {
  1237. // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
  1238. print "<p><table width=\"100%\" cellspacing=\"0\"
  1239. class=\"prefFeedList\" id=\"prefFeedList\">";
  1240. print "<tr><td class=\"selectPrompt\" colspan=\"8\">
  1241. Select:
  1242. <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
  1243. <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
  1244. </td</tr>";
  1245. if (!get_pref($link, 'ENABLE_FEED_CATS')) {
  1246. print "<tr class=\"title\">
  1247. <td width='5%' align='center'>&nbsp;</td>";
  1248. if (get_pref($link, 'ENABLE_FEED_ICONS')) {
  1249. print "<td width='3%'>&nbsp;</td>";
  1250. }
  1251. print "
  1252. <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
  1253. <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
  1254. <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
  1255. }
  1256. $lnum = 0;
  1257. $cur_cat_id = -1;
  1258. while ($line = db_fetch_assoc($result)) {
  1259. $feed_id = $line["id"];
  1260. $cat_id = $line["cat_id"];
  1261. $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
  1262. $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
  1263. $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
  1264. $hidden = sql_bool_to_bool($line["hidden"]);
  1265. if (!$edit_cat) $edit_cat = "Uncategorized";
  1266. $last_updated = $line["last_updated"];
  1267. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  1268. $last_updated = smart_date_time(strtotime($last_updated));
  1269. } else {
  1270. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  1271. $last_updated = date($short_date, strtotime($last_updated));
  1272. }
  1273. if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
  1274. $lnum = 0;
  1275. print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
  1276. print "<tr class=\"title\">
  1277. <td width='5%'>&nbsp;</td>";
  1278. if (get_pref($link, 'ENABLE_FEED_ICONS')) {
  1279. print "<td width='3%'>&nbsp;</td>";
  1280. }
  1281. print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
  1282. <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
  1283. <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
  1284. $cur_cat_id = $cat_id;
  1285. }
  1286. $class = ($lnum % 2) ? "even" : "odd";
  1287. $this_row_id = "id=\"FEEDR-$feed_id\"";
  1288. print "<tr class=\"$class\" $this_row_id>";
  1289. $icon_file = ICONS_DIR . "/$feed_id.ico";
  1290. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  1291. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
  1292. } else {
  1293. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
  1294. }
  1295. print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
  1296. type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
  1297. if (get_pref($link, 'ENABLE_FEED_ICONS')) {
  1298. print "<td class='feedIcon'>$feed_icon</td>";
  1299. }
  1300. $edit_title = truncate_string($edit_title, 40);
  1301. $edit_link = truncate_string($edit_link, 60);
  1302. if ($hidden) {
  1303. $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
  1304. $edit_link = "<span class=\"insensitive\">$edit_link</span>";
  1305. $last_updated = "<span class=\"insensitive\">$last_updated</span>";
  1306. }
  1307. $parent_title = $line["parent_title"];
  1308. if ($parent_title) {
  1309. $parent_title = "<span class='groupPrompt'>(linked to
  1310. $parent_title)</span>";
  1311. }
  1312. print "<td><a href=\"javascript:editFeed($feed_id);\">" .
  1313. "$edit_title $parent_title" . "</a></td>";
  1314. print "<td><a href=\"javascript:editFeed($feed_id);\">" .
  1315. $edit_link . "</a></td>";
  1316. print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
  1317. "$last_updated</a></td>";
  1318. print "</tr>";
  1319. ++$lnum;
  1320. }
  1321. print "</table>";
  1322. print "<p><span id=\"feedOpToolbar\">";
  1323. if ($subop == "edit") {
  1324. print "Edit feed:&nbsp;
  1325. <input type=\"submit\" class=\"button\"
  1326. onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
  1327. <input type=\"submit\" class=\"button\"
  1328. onclick=\"javascript:feedEditSave()\" value=\"Save\">";
  1329. } else {
  1330. print "
  1331. Selection:&nbsp;
  1332. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1333. onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
  1334. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1335. onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
  1336. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  1337. print "&nbsp;|&nbsp;";
  1338. print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
  1339. print " <input type=\"submit\" class=\"button\" disabled=\"true\"
  1340. onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
  1341. }
  1342. print "</span>
  1343. &nbsp;All feeds: <input type=\"submit\"
  1344. class=\"button\" onclick=\"gotoExportOpml()\"
  1345. value=\"Export OPML\">";
  1346. }
  1347. } else {
  1348. print "<p>No feeds defined.</p>";
  1349. }
  1350. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  1351. print "<h3>Edit Categories</h3>";
  1352. print "<div class=\"prefGenericAddBox\">
  1353. <input id=\"fadd_cat\"
  1354. onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
  1355. size=\"40\">&nbsp;
  1356. <input
  1357. type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
  1358. onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
  1359. $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
  1360. WHERE owner_uid = ".$_SESSION["uid"]."
  1361. ORDER BY title");
  1362. if (db_num_rows($result) != 0) {
  1363. print "<form id=\"feed_cat_edit_form\">";
  1364. print "<p><table width=\"100%\" class=\"prefFeedCatList\"
  1365. cellspacing=\"0\" id=\"prefFeedCatList\">";
  1366. print "<tr><td class=\"selectPrompt\" colspan=\"8\">
  1367. Select:
  1368. <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
  1369. <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
  1370. </td</tr>";
  1371. print "<tr class=\"title\">
  1372. <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
  1373. </tr>";
  1374. $lnum = 0;
  1375. while ($line = db_fetch_assoc($result)) {
  1376. $class = ($lnum % 2) ? "even" : "odd";
  1377. $cat_id = $line["id"];
  1378. $edit_cat_id = $_GET["id"];
  1379. if ($subop == "editCat" && $cat_id != $edit_cat_id) {
  1380. $class .= "Grayed";
  1381. $this_row_id = "";
  1382. } else {
  1383. $this_row_id = "id=\"FCATR-$cat_id\"";
  1384. }
  1385. print "<tr class=\"$class\" $this_row_id>";
  1386. $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
  1387. if (!$edit_cat_id || $subop != "editCat") {
  1388. print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
  1389. type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
  1390. print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
  1391. $edit_title . "</a></td>";
  1392. } else if ($cat_id != $edit_cat_id) {
  1393. print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
  1394. id=\"FRCHK-".$line["id"]."\"></td>";
  1395. print "<td>$edit_title</td>";
  1396. } else {
  1397. print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
  1398. print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
  1399. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  1400. print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
  1401. print "</td>";
  1402. print "<td><input onkeypress=\"return filterCR(event)\"
  1403. name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
  1404. }
  1405. print "</tr>";
  1406. ++$lnum;
  1407. }
  1408. print "</table>";
  1409. print "</form>";
  1410. print "<p id=\"catOpToolbar\">";
  1411. if ($subop == "editCat") {
  1412. print "Edit category:&nbsp;
  1413. <input type=\"submit\" class=\"button\"
  1414. onclick=\"return feedCatEditSave()\" value=\"Save\">
  1415. <input type=\"submit\" class=\"button\"
  1416. onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
  1417. } else {
  1418. print "
  1419. Selection:&nbsp;
  1420. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1421. onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
  1422. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1423. onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
  1424. }
  1425. } else {
  1426. print "<p>No feed categories defined.</p>";
  1427. }
  1428. }
  1429. print "<h3>Import OPML</h3>
  1430. <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
  1431. File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
  1432. <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
  1433. type=\"submit\" value=\"Import\">
  1434. </form>";
  1435. }
  1436. if ($op == "pref-filters") {
  1437. $subop = $_GET["subop"];
  1438. $quiet = $_GET["quiet"];
  1439. if ($subop == "edit") {
  1440. $filter_id = db_escape_string($_GET["id"]);
  1441. $result = db_query($link,
  1442. "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
  1443. $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
  1444. $filter_type = db_fetch_result($result, 0, "filter_type");
  1445. $feed_id = db_fetch_result($result, 0, "feed_id");
  1446. $action_id = db_fetch_result($result, 0, "action_id");
  1447. print "<div id=\"infoBoxTitle\">Filter editor</div>";
  1448. print "<div class=\"infoBoxContents\">";
  1449. print "<form id=\"filter_edit_form\">";
  1450. print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
  1451. print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
  1452. print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
  1453. // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
  1454. $result = db_query($link, "SELECT id,description
  1455. FROM ttrss_filter_types ORDER BY description");
  1456. $filter_types = array();
  1457. while ($line = db_fetch_assoc($result)) {
  1458. //array_push($filter_types, $line["description"]);
  1459. $filter_types[$line["id"]] = $line["description"];
  1460. }
  1461. print "<table width='100%'>";
  1462. print "<tr><td>Match:</td>
  1463. <td><input onkeypress=\"return filterCR(event)\"
  1464. onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1465. name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
  1466. print "</td><td>";
  1467. print_select_hash("filter_type", $filter_type, $filter_types, "class=\"iedit\"");
  1468. print "</td></tr>";
  1469. print "<tr><td>Feed:</td><td colspan='2'>";
  1470. print_feed_select($link, "feed_id", $feed_id);
  1471. print "</td></tr>";
  1472. print "<tr><td>Action:</td>";
  1473. print "<td colspan='2'><select name=\"action_id\">";
  1474. $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
  1475. ORDER BY name");
  1476. while ($line = db_fetch_assoc($result)) {
  1477. $is_sel = ($line["id"] == $action_id) ? "selected" : "";
  1478. printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
  1479. }
  1480. print "</select>";
  1481. print "</td></tr></table>";
  1482. print "</form>";
  1483. print "<div align='right'>";
  1484. print "<input type=\"submit\"
  1485. id=\"infobox_submit\"
  1486. class=\"button\" onclick=\"return filterEditSave()\"
  1487. value=\"Save\"> ";
  1488. print "<input class=\"button\"
  1489. type=\"submit\" onclick=\"return filterEditCancel()\"
  1490. value=\"Cancel\">";
  1491. print "</div>";
  1492. return;
  1493. }
  1494. if ($subop == "editSave") {
  1495. $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
  1496. $filter_type = db_escape_string(trim($_GET["filter_type"]));
  1497. $filter_id = db_escape_string($_GET["id"]);
  1498. $feed_id = db_escape_string($_GET["feed_id"]);
  1499. $action_id = db_escape_string($_GET["action_id"]);
  1500. if (!$feed_id) {
  1501. $feed_id = 'NULL';
  1502. } else {
  1503. $feed_id = sprintf("'%s'", db_escape_string($feed_id));
  1504. }
  1505. $result = db_query($link, "UPDATE ttrss_filters SET
  1506. reg_exp = '$reg_exp',
  1507. feed_id = $feed_id,
  1508. action_id = '$action_id',
  1509. filter_type = '$filter_type'
  1510. WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
  1511. }
  1512. if ($subop == "remove") {
  1513. if (!WEB_DEMO_MODE) {
  1514. $ids = split(",", db_escape_string($_GET["ids"]));
  1515. foreach ($ids as $id) {
  1516. db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
  1517. }
  1518. }
  1519. }
  1520. if ($subop == "add") {
  1521. if (!WEB_DEMO_MODE) {
  1522. $regexp = db_escape_string(trim($_GET["reg_exp"]));
  1523. $filter_type = db_escape_string(trim($_GET["filter_type"]));
  1524. $feed_id = db_escape_string($_GET["feed_id"]);
  1525. $action_id = db_escape_string($_GET["action_id"]);
  1526. if (!$feed_id) {
  1527. $feed_id = 'NULL';
  1528. } else {
  1529. $feed_id = sprintf("'%s'", db_escape_string($feed_id));
  1530. }
  1531. $result = db_query($link,
  1532. "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
  1533. action_id)
  1534. VALUES
  1535. ('$regexp', '$filter_type','".$_SESSION["uid"]."',
  1536. $feed_id, '$action_id')");
  1537. }
  1538. }
  1539. if ($quiet) return;
  1540. // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
  1541. $result = db_query($link, "SELECT id,description
  1542. FROM ttrss_filter_types ORDER BY description");
  1543. $filter_types = array();
  1544. while ($line = db_fetch_assoc($result)) {
  1545. //array_push($filter_types, $line["description"]);
  1546. $filter_types[$line["id"]] = $line["description"];
  1547. }
  1548. print "<input type=\"submit\"
  1549. class=\"button\"
  1550. onclick=\"return displayDlg('quickAddFilter', false)\"
  1551. id=\"create_filter_btn\"
  1552. value=\"Create filter\">";
  1553. $result = db_query($link, "SELECT
  1554. ttrss_filters.id AS id,reg_exp,
  1555. ttrss_filter_types.name AS filter_type_name,
  1556. ttrss_filter_types.description AS filter_type_descr,
  1557. feed_id,
  1558. ttrss_filter_actions.description AS action_description,
  1559. ttrss_feeds.title AS feed_title
  1560. FROM
  1561. ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
  1562. ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
  1563. WHERE
  1564. filter_type = ttrss_filter_types.id AND
  1565. ttrss_filter_actions.id = action_id AND
  1566. ttrss_filters.owner_uid = ".$_SESSION["uid"]."
  1567. ORDER by reg_exp");
  1568. if (db_num_rows($result) != 0) {
  1569. print "<form id=\"filter_edit_form\">";
  1570. print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
  1571. id=\"prefFilterList\">";
  1572. print "<tr><td class=\"selectPrompt\" colspan=\"8\">
  1573. Select:
  1574. <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
  1575. <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
  1576. </td</tr>";
  1577. print "<tr class=\"title\">
  1578. <td align='center' width=\"5%\">&nbsp;</td>
  1579. <td width=\"20%\">Filter expression</td>
  1580. <td width=\"20%\">Feed</td>
  1581. <td width=\"15%\">Match</td>
  1582. <td width=\"15%\">Action</td>";
  1583. $lnum = 0;
  1584. while ($line = db_fetch_assoc($result)) {
  1585. $class = ($lnum % 2) ? "even" : "odd";
  1586. $filter_id = $line["id"];
  1587. $edit_filter_id = $_GET["id"];
  1588. if ($subop == "edit" && $filter_id != $edit_filter_id) {
  1589. $class .= "Grayed";
  1590. $this_row_id = "";
  1591. } else {
  1592. $this_row_id = "id=\"FILRR-$filter_id\"";
  1593. }
  1594. print "<tr class=\"$class\" $this_row_id>";
  1595. $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
  1596. if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
  1597. $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
  1598. print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
  1599. type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
  1600. print "<td><a href=\"javascript:editFilter($filter_id);\">" .
  1601. $line["reg_exp"] . "</td>";
  1602. print "<td><a href=\"javascript:editFilter($filter_id);\">" .
  1603. $line["feed_title"] . "</td>";
  1604. print "<td><a href=\"javascript:editFilter($filter_id);\">" .
  1605. $line["filter_type_descr"] . "</td>";
  1606. print "<td><a href=\"javascript:editFilter($filter_id);\">" .
  1607. $line["action_description"] . "</td>";
  1608. print "</tr>";
  1609. ++$lnum;
  1610. }
  1611. if ($lnum == 0) {
  1612. print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
  1613. }
  1614. print "</table>";
  1615. print "</form>";
  1616. print "<p id=\"filterOpToolbar\">";
  1617. print "
  1618. Selection:
  1619. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1620. onclick=\"return editSelectedFilter()\" value=\"Edit\">
  1621. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1622. onclick=\"return removeSelectedFilters()\" value=\"Remove\">";
  1623. print "</p>";
  1624. } else {
  1625. print "<p>No filters defined.</p>";
  1626. }
  1627. }
  1628. // We need to accept raw SQL data in label queries, so not everything is escaped
  1629. // here, this is by design. If you don't like the whole idea, disable labels
  1630. // altogether with GLOBAL_ENABLE_LABELS = false
  1631. if ($op == "pref-labels") {
  1632. if (!GLOBAL_ENABLE_LABELS) {
  1633. print "<p>Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.</p>";
  1634. return;
  1635. }
  1636. $subop = $_GET["subop"];
  1637. if ($subop == "edit") {
  1638. $label_id = db_escape_string($_GET["id"]);
  1639. $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
  1640. owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
  1641. $line = db_fetch_assoc($result);
  1642. $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"]));
  1643. $description = htmlspecialchars(db_unescape_string($line["description"]));
  1644. print "<div id=\"infoBoxTitle\">Label editor</div>";
  1645. print "<div class=\"infoBoxContents\">";
  1646. print "<form id=\"label_edit_form\">";
  1647. print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
  1648. print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
  1649. print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
  1650. print "<table width='100%'>";
  1651. print "<tr><td>Caption:</td>
  1652. <td><input onkeypress=\"return filterCR(event)\"
  1653. onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1654. name=\"description\" class=\"iedit\" value=\"$description\">";
  1655. print "</td></tr>";
  1656. print "<tr><td colspan=\"2\">
  1657. <p>SQL Expression:</p>";
  1658. print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1659. rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
  1660. print "</td></tr></table>";
  1661. print "</form>";
  1662. print "<div style=\"display : none\" id=\"label_test_result\"></div>";
  1663. print "<div align='right'>";
  1664. print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
  1665. ";
  1666. print "<input type=\"submit\"
  1667. id=\"infobox_submit\"
  1668. class=\"button\" onclick=\"return labelEditSave()\"
  1669. value=\"Save\"> ";
  1670. print "<input class=\"button\"
  1671. type=\"submit\" onclick=\"return labelEditCancel()\"
  1672. value=\"Cancel\">";
  1673. print "</div>";
  1674. return;
  1675. }
  1676. if ($subop == "test") {
  1677. $expr = db_unescape_string(trim($_GET["expr"]));
  1678. $descr = db_unescape_string(trim($_GET["descr"]));
  1679. print "<div>";
  1680. error_reporting(0);
  1681. $result = db_query($link,
  1682. "SELECT count(ttrss_entries.id) AS num_matches
  1683. FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
  1684. WHERE ($expr) AND
  1685. ttrss_user_entries.ref_id = ttrss_entries.id AND
  1686. ttrss_user_entries.feed_id = ttrss_feeds.id AND
  1687. ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false);
  1688. error_reporting (DEFAULT_ERROR_LEVEL);
  1689. if (!$result) {
  1690. print "<p>" . db_last_error($link) . "</p>";
  1691. print "</div>";
  1692. return;
  1693. }
  1694. $num_matches = db_fetch_result($result, 0, "num_matches");;
  1695. if ($num_matches > 0) {
  1696. if ($num_matches > 10) {
  1697. $showing_msg = ", showing first 10";
  1698. }
  1699. print "<p>Query returned <b>$num_matches</b> matches$showing_msg:</p>";
  1700. $result = db_query($link,
  1701. "SELECT ttrss_entries.title,
  1702. (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
  1703. FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
  1704. WHERE ($expr) AND
  1705. ttrss_user_entries.ref_id = ttrss_entries.id
  1706. AND ttrss_user_entries.feed_id = ttrss_feeds.id
  1707. AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
  1708. ORDER BY date_entered DESC LIMIT 10", false);
  1709. print "<ul class=\"labelTestResults\">";
  1710. $row_class = "even";
  1711. while ($line = db_fetch_assoc($result)) {
  1712. $row_class = toggleEvenOdd($row_class);
  1713. print "<li class=\"$row_class\">".$line["title"].
  1714. " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
  1715. }
  1716. print "</ul>";
  1717. } else {
  1718. print "<p>Query didn't return any matches.</p>";
  1719. }
  1720. print "</div>";
  1721. return;
  1722. }
  1723. if ($subop == "editSave") {
  1724. $sql_exp = trim($_GET["sql_exp"]);
  1725. $descr = db_escape_string(trim($_GET["description"]));
  1726. $label_id = db_escape_string($_GET["id"]);
  1727. $result = db_query($link, "UPDATE ttrss_labels SET
  1728. sql_exp = '$sql_exp',
  1729. description = '$descr'
  1730. WHERE id = '$label_id'");
  1731. }
  1732. if ($subop == "remove") {
  1733. if (!WEB_DEMO_MODE) {
  1734. $ids = split(",", db_escape_string($_GET["ids"]));
  1735. foreach ($ids as $id) {
  1736. db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
  1737. }
  1738. }
  1739. }
  1740. if ($subop == "add") {
  1741. if (!WEB_DEMO_MODE) {
  1742. // no escaping is done here on purpose
  1743. $sql_exp = trim($_GET["sql_exp"]);
  1744. $description = db_escape_string($_GET["description"]);
  1745. $result = db_query($link,
  1746. "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
  1747. VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')");
  1748. }
  1749. }
  1750. print "<div class=\"prefGenericAddBox\">";
  1751. print"<input type=\"submit\" class=\"button\"
  1752. id=\"label_create_btn\"
  1753. onclick=\"return displayDlg('quickAddLabel', false)\"
  1754. value=\"Create label\"></div>";
  1755. $result = db_query($link, "SELECT
  1756. id,sql_exp,description
  1757. FROM
  1758. ttrss_labels
  1759. WHERE
  1760. owner_uid = ".$_SESSION["uid"]."
  1761. ORDER by description");
  1762. // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
  1763. if (db_num_rows($result) != 0) {
  1764. print "<form id=\"label_edit_form\">";
  1765. print "<p><table width=\"100%\" cellspacing=\"0\"
  1766. class=\"prefLabelList\" id=\"prefLabelList\">";
  1767. print "<tr><td class=\"selectPrompt\" colspan=\"8\">
  1768. Select:
  1769. <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
  1770. <a href=\"javascript:selectPrefRows('label', false)\">None</a>
  1771. </td</tr>";
  1772. print "<tr class=\"title\">
  1773. <td width=\"5%\">&nbsp;</td>
  1774. <td width=\"30%\">Caption</td>
  1775. <td width=\"50%\">SQL Expression
  1776. <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
  1777. </td>
  1778. </tr>";
  1779. $lnum = 0;
  1780. while ($line = db_fetch_assoc($result)) {
  1781. $class = ($lnum % 2) ? "even" : "odd";
  1782. $label_id = $line["id"];
  1783. $edit_label_id = $_GET["id"];
  1784. if ($subop == "edit" && $label_id != $edit_label_id) {
  1785. $class .= "Grayed";
  1786. $this_row_id = "";
  1787. } else {
  1788. $this_row_id = "id=\"LILRR-$label_id\"";
  1789. }
  1790. print "<tr class=\"$class\" $this_row_id>";
  1791. $line["sql_exp"] = htmlspecialchars(db_unescape_string($line["sql_exp"]));
  1792. $line["description"] = htmlspecialchars(
  1793. db_unescape_string($line["description"]));
  1794. if (!$line["description"]) $line["description"] = "[No caption]";
  1795. print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
  1796. type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
  1797. print "<td><a href=\"javascript:editLabel($label_id);\">" .
  1798. $line["description"] . "</td>";
  1799. print "<td><a href=\"javascript:editLabel($label_id);\">" .
  1800. $line["sql_exp"] . "</td>";
  1801. print "</tr>";
  1802. ++$lnum;
  1803. }
  1804. if ($lnum == 0) {
  1805. print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
  1806. }
  1807. print "</table>";
  1808. print "</form>";
  1809. print "<p id=\"labelOpToolbar\">";
  1810. print "
  1811. Selection:
  1812. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1813. onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
  1814. <input type=\"submit\" class=\"button\" disabled=\"true\"
  1815. onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
  1816. } else {
  1817. print "<p>No labels defined.</p>";
  1818. }
  1819. }
  1820. if ($op == "error") {
  1821. print "<div width=\"100%\" align='center'>";
  1822. $msg = $_GET["msg"];
  1823. print $msg;
  1824. print "</div>";
  1825. }
  1826. if ($op == "help") {
  1827. if (!$_GET["noheaders"]) {
  1828. print "<html><head>
  1829. <title>Tiny Tiny RSS : Help</title>
  1830. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
  1831. <script type=\"text/javascript\" src=\"prototype.js\"></script>
  1832. <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
  1833. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  1834. </head><body>";
  1835. }
  1836. $tid = sprintf("%d", $_GET["tid"]);
  1837. print "<div id=\"infoBoxTitle\">Help</div>";
  1838. print "<div class='infoBoxContents'>";
  1839. if (file_exists("help/$tid.php")) {
  1840. include("help/$tid.php");
  1841. } else {
  1842. print "<p>Help topic not found.</p>";
  1843. }
  1844. print "</div>";
  1845. print "<div align='center'>
  1846. <input type='submit' class='button'
  1847. onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
  1848. if (!$_GET["noheaders"]) {
  1849. print "</body></html>";
  1850. }
  1851. }
  1852. if ($op == "dlg") {
  1853. $id = $_GET["id"];
  1854. $param = $_GET["param"];
  1855. if ($id == "quickAddFeed") {
  1856. print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
  1857. print "<div class=\"infoBoxContents\">";
  1858. print "<form id='feed_add_form'>";
  1859. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  1860. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  1861. print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
  1862. print "<table width='100%'>
  1863. <tr><td>Feed URL:</td><td>
  1864. <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
  1865. onkeypress=\"return filterCR(event)\"
  1866. onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
  1867. onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
  1868. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  1869. print "<tr><td>Category:</td><td>";
  1870. print_feed_cat_select($link, "cat_id");
  1871. print "</td></tr>";
  1872. }
  1873. print "</table>";
  1874. print "</form>";
  1875. print "<div align='right'>
  1876. <input class=\"button\"
  1877. id=\"fadd_submit_btn\" disabled=\"true\"
  1878. type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
  1879. <input class=\"button\"
  1880. type=\"submit\" onclick=\"javascript:closeInfoBox()\"
  1881. value=\"Cancel\"></div>";
  1882. }
  1883. if ($id == "search") {
  1884. print "<div id=\"infoBoxTitle\">Search</div>";
  1885. print "<div class=\"infoBoxContents\">";
  1886. print "<form id='search_form'>";
  1887. #$active_feed_id = db_escape_string($_GET["param"]);
  1888. $params = split(":", db_escape_string($_GET["param"]));
  1889. $active_feed_id = sprintf("%d", $params[0]);
  1890. $is_cat = $params[1] == "true";
  1891. print "<table width='100%'><tr><td>Search:</td><td>";
  1892. print "<input name=\"query\" class=\"iedit\"
  1893. onkeypress=\"return filterCR(event)\"
  1894. onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
  1895. value=\"\">
  1896. </td></tr>";
  1897. print "<tr><td>Where:</td><td>";
  1898. print "<select name=\"search_mode\">
  1899. <option value=\"all_feeds\">All feeds</option>";
  1900. $feed_title = getFeedTitle($link, $active_feed_id);
  1901. if (!$is_cat) {
  1902. $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
  1903. } else {
  1904. $feed_cat_title = getCategoryTitle($link, $active_feed_id);
  1905. }
  1906. if ($active_feed_id && !$is_cat) {
  1907. print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
  1908. } else {
  1909. print "<option disabled>This feed</option>";
  1910. }
  1911. if ($is_cat) {
  1912. $cat_preselected = "selected";
  1913. }
  1914. if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
  1915. print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
  1916. } else {
  1917. print "<option disabled>This category</option>";
  1918. }
  1919. print "</select></td></tr>";
  1920. print "<tr><td>Match on:</td><td>";
  1921. $search_fields = array(
  1922. "title" => "Title",
  1923. "content" => "Content",
  1924. "both" => "Title or content");
  1925. print_select_hash("match_on", 3, $search_fields);
  1926. print "</td></tr></table>";
  1927. print "</form>";
  1928. print "<div align=\"right\">
  1929. <input type=\"submit\"
  1930. class=\"button\" onclick=\"javascript:search()\"
  1931. id=\"search_submit_btn\" disabled=\"true\"
  1932. value=\"Search\">
  1933. <input class=\"button\"
  1934. type=\"submit\" onclick=\"javascript:searchCancel()\"
  1935. value=\"Cancel\"></div>";
  1936. print "</div>";
  1937. }
  1938. if ($id == "quickAddLabel") {
  1939. print "<div id=\"infoBoxTitle\">Create label</div>";
  1940. print "<div class=\"infoBoxContents\">";
  1941. print "<form id=\"label_edit_form\">";
  1942. print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
  1943. print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
  1944. print "<table width='100%'>";
  1945. print "<tr><td>Caption:</td>
  1946. <td><input onkeypress=\"return filterCR(event)\"
  1947. onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1948. name=\"description\" class=\"iedit\">";
  1949. print "</td></tr>";
  1950. print "<tr><td colspan=\"2\">
  1951. <p>SQL Expression:</p>";
  1952. print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1953. rows=\"4\" name=\"sql_exp\" class=\"iedit\"></textarea>";
  1954. print "</td></tr></table>";
  1955. print "</form>";
  1956. print "<div style=\"display : none\" id=\"label_test_result\"></div>";
  1957. print "<div align='right'>";
  1958. print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
  1959. ";
  1960. print "<input type=\"submit\"
  1961. id=\"infobox_submit\"
  1962. disabled=\"true\"
  1963. class=\"button\" onclick=\"return addLabel()\"
  1964. value=\"Create\"> ";
  1965. print "<input class=\"button\"
  1966. type=\"submit\" onclick=\"return labelEditCancel()\"
  1967. value=\"Cancel\">";
  1968. }
  1969. if ($id == "quickAddFilter") {
  1970. $active_feed_id = db_escape_string($_GET["param"]);
  1971. print "<div id=\"infoBoxTitle\">Create filter</div>";
  1972. print "<div class=\"infoBoxContents\">";
  1973. print "<form id=\"filter_add_form\">";
  1974. print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
  1975. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  1976. print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
  1977. // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
  1978. $result = db_query($link, "SELECT id,description
  1979. FROM ttrss_filter_types ORDER BY description");
  1980. $filter_types = array();
  1981. while ($line = db_fetch_assoc($result)) {
  1982. //array_push($filter_types, $line["description"]);
  1983. $filter_types[$line["id"]] = $line["description"];
  1984. }
  1985. print "<table width='100%'>";
  1986. print "<tr><td>Match:</td>
  1987. <td><input onkeypress=\"return filterCR(event)\"
  1988. onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
  1989. name=\"reg_exp\" class=\"iedit\">";
  1990. print "</td><td>";
  1991. print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
  1992. print "</td></tr>";
  1993. print "<tr><td>Feed:</td><td colspan='2'>";
  1994. print_feed_select($link, "feed_id", $active_feed_id);
  1995. print "</td></tr>";
  1996. print "<tr><td>Action:</td>";
  1997. print "<td colspan='2'><select name=\"action_id\">";
  1998. $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
  1999. ORDER BY name");
  2000. while ($line = db_fetch_assoc($result)) {
  2001. printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
  2002. }
  2003. print "</select>";
  2004. print "</td></tr></table>";
  2005. print "</form>";
  2006. print "<div align='right'>";
  2007. print "<input type=\"submit\"
  2008. id=\"infobox_submit\"
  2009. class=\"button\" onclick=\"return qaddFilter()\"
  2010. disabled=\"true\" value=\"Create\"> ";
  2011. print "<input class=\"button\"
  2012. type=\"submit\" onclick=\"return closeInfoBox()\"
  2013. value=\"Cancel\">";
  2014. print "</div>";
  2015. // print "</td></tr></table>";
  2016. }
  2017. print "</div>";
  2018. }
  2019. // update feeds of all users, may be used anonymously
  2020. if ($op == "globalUpdateFeeds") {
  2021. $result = db_query($link, "SELECT id FROM ttrss_users");
  2022. while ($line = db_fetch_assoc($result)) {
  2023. $user_id = $line["id"];
  2024. // print "<!-- updating feeds of uid $user_id -->";
  2025. update_all_feeds($link, false, $user_id);
  2026. }
  2027. print "<rpc-reply>
  2028. <message msg=\"All feeds updated\"/>
  2029. </rpc-reply>";
  2030. }
  2031. if ($op == "pref-prefs") {
  2032. $subop = $_REQUEST["subop"];
  2033. if ($subop == "Save configuration") {
  2034. if (WEB_DEMO_MODE) {
  2035. header("Location: prefs.php");
  2036. return;
  2037. }
  2038. $_SESSION["prefs_op_result"] = "save-config";
  2039. $_SESSION["prefs_cache"] = false;
  2040. foreach (array_keys($_POST) as $pref_name) {
  2041. $pref_name = db_escape_string($pref_name);
  2042. $value = db_escape_string($_POST[$pref_name]);
  2043. $result = db_query($link, "SELECT type_name
  2044. FROM ttrss_prefs,ttrss_prefs_types
  2045. WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
  2046. if (db_num_rows($result) > 0) {
  2047. $type_name = db_fetch_result($result, 0, "type_name");
  2048. // print "$pref_name : $type_name : $value<br>";
  2049. if ($type_name == "bool") {
  2050. if ($value == "1") {
  2051. $value = "true";
  2052. } else {
  2053. $value = "false";
  2054. }
  2055. } else if ($type_name == "integer") {
  2056. $value = sprintf("%d", $value);
  2057. }
  2058. // print "$pref_name : $type_name : $value<br>";
  2059. db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
  2060. WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
  2061. }
  2062. header("Location: prefs.php");
  2063. }
  2064. } else if ($subop == "getHelp") {
  2065. $pref_name = db_escape_string($_GET["pn"]);
  2066. $result = db_query($link, "SELECT help_text FROM ttrss_prefs
  2067. WHERE pref_name = '$pref_name'");
  2068. if (db_num_rows($result) > 0) {
  2069. $help_text = db_fetch_result($result, 0, "help_text");
  2070. print $help_text;
  2071. } else {
  2072. print "Unknown option: $pref_name";
  2073. }
  2074. } else if ($subop == "Change e-mail") {
  2075. if (WEB_DEMO_MODE) {
  2076. header("Location: prefs.php");
  2077. return;
  2078. }
  2079. $email = db_escape_string($_GET["email"]);
  2080. $active_uid = $_SESSION["uid"];
  2081. if ($email) {
  2082. db_query($link, "UPDATE ttrss_users SET email = '$email'
  2083. WHERE id = '$active_uid'");
  2084. }
  2085. header("Location: prefs.php");
  2086. } else if ($subop == "Change password") {
  2087. if (WEB_DEMO_MODE) {
  2088. header("Location: prefs.php");
  2089. return;
  2090. }
  2091. $old_pw = $_POST["OLD_PASSWORD"];
  2092. $new_pw = $_POST["OLD_PASSWORD"];
  2093. $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
  2094. $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
  2095. $active_uid = $_SESSION["uid"];
  2096. if ($old_pw && $new_pw) {
  2097. $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
  2098. $result = db_query($link, "SELECT id FROM ttrss_users WHERE
  2099. id = '$active_uid' AND (pwd_hash = '$old_pw' OR
  2100. pwd_hash = '$old_pw_hash')");
  2101. if (db_num_rows($result) == 1) {
  2102. db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
  2103. WHERE id = '$active_uid'");
  2104. $_SESSION["pwd_change_result"] = "ok";
  2105. } else {
  2106. $_SESSION["pwd_change_result"] = "failed";
  2107. }
  2108. }
  2109. header("Location: prefs.php");
  2110. } else if ($subop == "Reset to defaults") {
  2111. if (WEB_DEMO_MODE) {
  2112. header("Location: prefs.php");
  2113. return;
  2114. }
  2115. $_SESSION["prefs_op_result"] = "reset-to-defaults";
  2116. if (DB_TYPE == "pgsql") {
  2117. db_query($link,"UPDATE ttrss_user_prefs
  2118. SET value = ttrss_prefs.def_value
  2119. WHERE owner_uid = '".$_SESSION["uid"]."' AND
  2120. ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
  2121. } else {
  2122. db_query($link, "DELETE FROM ttrss_user_prefs
  2123. WHERE owner_uid = ".$_SESSION["uid"]);
  2124. initialize_user_prefs($link, $_SESSION["uid"]);
  2125. }
  2126. header("Location: prefs.php");
  2127. } else if ($subop == "Change theme") {
  2128. $theme = db_escape_string($_POST["theme"]);
  2129. if ($theme == "Default") {
  2130. $theme_qpart = 'NULL';
  2131. } else {
  2132. $theme_qpart = "'$theme'";
  2133. }
  2134. $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
  2135. WHERE theme_name = '$theme'");
  2136. if (db_num_rows($result) == 1) {
  2137. $theme_id = db_fetch_result($result, 0, "id");
  2138. $theme_path = db_fetch_result($result, 0, "theme_path");
  2139. } else {
  2140. $theme_id = "NULL";
  2141. $theme_path = "";
  2142. }
  2143. db_query($link, "UPDATE ttrss_users SET
  2144. theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
  2145. $_SESSION["theme"] = $theme_path;
  2146. header("Location: prefs.php");
  2147. } else {
  2148. if (!SINGLE_USER_MODE) {
  2149. $result = db_query($link, "SELECT id,email FROM ttrss_users
  2150. WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
  2151. pwd_hash = 'SHA1:".sha1("password")."')");
  2152. if (db_num_rows($result) != 0) {
  2153. print "<div class=\"warning\">
  2154. Your password is at default value, please change it.
  2155. </div>";
  2156. }
  2157. if ($_SESSION["pwd_change_result"] == "failed") {
  2158. print "<div class=\"warning\">
  2159. There was an error while changing your password.
  2160. </div>";
  2161. }
  2162. if ($_SESSION["pwd_change_result"] == "ok") {
  2163. print "<div class=\"notice\">
  2164. Password changed successfully.
  2165. </div>";
  2166. }
  2167. $_SESSION["pwd_change_result"] = "";
  2168. if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
  2169. print "<div class=\"notice\">
  2170. Your configuration was reset to defaults.
  2171. </div>";
  2172. }
  2173. if ($_SESSION["prefs_op_result"] == "save-config") {
  2174. print "<div class=\"notice\">
  2175. Your configuration was saved successfully.
  2176. </div>";
  2177. }
  2178. $_SESSION["prefs_op_result"] = "";
  2179. print "<form action=\"backend.php\" method=\"GET\">";
  2180. print "<table width=\"100%\" class=\"prefPrefsList\">";
  2181. print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
  2182. $result = db_query($link, "SELECT email FROM ttrss_users
  2183. WHERE id = ".$_SESSION["uid"]);
  2184. $email = db_fetch_result($result, 0, "email");
  2185. print "<tr><td width=\"40%\">E-mail</td>";
  2186. print "<td><input class=\"editbox\" name=\"email\"
  2187. value=\"$email\"></td></tr>";
  2188. print "</table>";
  2189. print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
  2190. print "<p><input class=\"button\" type=\"submit\"
  2191. value=\"Change e-mail\" name=\"subop\">";
  2192. print "</form>";
  2193. print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
  2194. print "<table width=\"100%\" class=\"prefPrefsList\">";
  2195. print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
  2196. print "<tr><td width=\"40%\">Old password</td>";
  2197. print "<td><input class=\"editbox\" type=\"password\"
  2198. name=\"OLD_PASSWORD\"></td></tr>";
  2199. print "<tr><td width=\"40%\">New password</td>";
  2200. print "<td><input class=\"editbox\" type=\"password\"
  2201. name=\"NEW_PASSWORD\"></td></tr>";
  2202. print "</table>";
  2203. print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
  2204. print "<p><input class=\"button\" type=\"submit\"
  2205. onclick=\"return validateNewPassword(this.form)\"
  2206. value=\"Change password\" name=\"subop\">";
  2207. print "</form>";
  2208. }
  2209. $result = db_query($link, "SELECT
  2210. theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
  2211. $user_theme_id = db_fetch_result($result, 0, "theme_id");
  2212. $result = db_query($link, "SELECT
  2213. id,theme_name FROM ttrss_themes ORDER BY theme_name");
  2214. if (db_num_rows($result) > 0) {
  2215. print "<form action=\"backend.php\" method=\"POST\">";
  2216. print "<table width=\"100%\" class=\"prefPrefsList\">";
  2217. print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
  2218. print "<tr><td width=\"40%\">Select theme</td>";
  2219. print "<td><select name=\"theme\">";
  2220. print "<option>Default</option>";
  2221. print "<option disabled>--------</option>";
  2222. while ($line = db_fetch_assoc($result)) {
  2223. if ($line["id"] == $user_theme_id) {
  2224. $selected = "selected";
  2225. } else {
  2226. $selected = "";
  2227. }
  2228. print "<option $selected>" . $line["theme_name"] . "</option>";
  2229. }
  2230. print "</select></td></tr>";
  2231. print "</table>";
  2232. print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
  2233. print "<p><input class=\"button\" type=\"submit\"
  2234. value=\"Change theme\" name=\"subop\">";
  2235. print "</form>";
  2236. }
  2237. $result = db_query($link, "SELECT
  2238. ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
  2239. section_name,def_value
  2240. FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
  2241. WHERE type_id = ttrss_prefs_types.id AND
  2242. section_id = ttrss_prefs_sections.id AND
  2243. ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
  2244. owner_uid = ".$_SESSION["uid"]."
  2245. ORDER BY section_id,short_desc");
  2246. print "<form action=\"backend.php\" method=\"POST\">";
  2247. $lnum = 0;
  2248. $active_section = "";
  2249. while ($line = db_fetch_assoc($result)) {
  2250. if ($active_section != $line["section_name"]) {
  2251. if ($active_section != "") {
  2252. print "</table>";
  2253. }
  2254. print "<p><table width=\"100%\" class=\"prefPrefsList\">";
  2255. $active_section = $line["section_name"];
  2256. print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
  2257. // print "<tr class=\"title\">
  2258. // <td width=\"25%\">Option</td><td>Value</td></tr>";
  2259. $lnum = 0;
  2260. }
  2261. // $class = ($lnum % 2) ? "even" : "odd";
  2262. print "<tr>";
  2263. $type_name = $line["type_name"];
  2264. $pref_name = $line["pref_name"];
  2265. $value = $line["value"];
  2266. $def_value = $line["def_value"];
  2267. $help_text = $line["help_text"];
  2268. print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
  2269. if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
  2270. print "</td>";
  2271. print "<td>";
  2272. if ($type_name == "bool") {
  2273. // print_select($pref_name, $value, array("true", "false"));
  2274. if ($value == "true") {
  2275. $value = "Yes";
  2276. } else {
  2277. $value = "No";
  2278. }
  2279. print_radio($pref_name, $value, array("Yes", "No"));
  2280. } else {
  2281. print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
  2282. }
  2283. print "</td>";
  2284. print "</tr>";
  2285. $lnum++;
  2286. }
  2287. print "</table>";
  2288. print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
  2289. print "<p><input class=\"button\" type=\"submit\"
  2290. name=\"subop\" value=\"Save configuration\">";
  2291. print "&nbsp;<input class=\"button\" type=\"submit\"
  2292. name=\"subop\" onclick=\"return validatePrefsReset()\"
  2293. value=\"Reset to defaults\"></p>";
  2294. print "</form>";
  2295. }
  2296. }
  2297. if ($op == "pref-users") {
  2298. $subop = $_GET["subop"];
  2299. if ($subop == "edit") {
  2300. $id = db_escape_string($_GET["id"]);
  2301. print "<div id=\"infoBoxTitle\">User editor</div>";
  2302. print "<div class=\"infoBoxContents\">";
  2303. print "<form id=\"user_edit_form\">";
  2304. print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
  2305. print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
  2306. print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
  2307. $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
  2308. $login = db_fetch_result($result, 0, "login");
  2309. $access_level = db_fetch_result($result, 0, "access_level");
  2310. $email = db_fetch_result($result, 0, "email");
  2311. print "<table width='100%'>";
  2312. print "<tr><td>Login:</td><td>
  2313. <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
  2314. name=\"login\" value=\"$login\"></td></tr>";
  2315. print "<tr><td>Change password:</td><td>
  2316. <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
  2317. name=\"password\"></td></tr>";
  2318. print "<tr><td>E-mail:</td><td>
  2319. <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
  2320. value=\"$email\"></td></tr>";
  2321. $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
  2322. print "<tr><td>Access level:</td><td>";
  2323. print_select_hash("access_level", $access_level, $access_level_names,
  2324. $sel_disabled);
  2325. print "</td></tr>";
  2326. print "</table>";
  2327. print "</form>";
  2328. print "<div align='right'>
  2329. <input class=\"button\"
  2330. type=\"submit\" onclick=\"return userEditSave()\"
  2331. value=\"Save\">
  2332. <input class=\"button\"
  2333. type=\"submit\" onclick=\"return userEditCancel()\"
  2334. value=\"Cancel\"></div>";
  2335. print "</div>";
  2336. return;
  2337. }
  2338. if ($subop == "editSave") {
  2339. if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
  2340. $login = db_escape_string(trim($_GET["login"]));
  2341. $uid = db_escape_string($_GET["id"]);
  2342. $access_level = sprintf("%d", $_GET["access_level"]);
  2343. $email = db_escape_string(trim($_GET["email"]));
  2344. $password = db_escape_string(trim($_GET["password"]));
  2345. if ($password) {
  2346. $pwd_hash = 'SHA1:' . sha1($password);
  2347. $pass_query_part = "pwd_hash = '$pwd_hash', ";
  2348. print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
  2349. } else {
  2350. $pass_query_part = "";
  2351. }
  2352. db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
  2353. access_level = '$access_level', email = '$email' WHERE id = '$uid'");
  2354. }
  2355. } else if ($subop == "remove") {
  2356. if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
  2357. $ids = split(",", db_escape_string($_GET["ids"]));
  2358. foreach ($ids as $id) {
  2359. db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
  2360. }
  2361. }
  2362. } else if ($subop == "add") {
  2363. if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
  2364. $login = db_escape_string(trim($_GET["login"]));
  2365. $tmp_user_pwd = make_password(8);
  2366. $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
  2367. $result = db_query($link, "SELECT id FROM ttrss_users WHERE
  2368. login = '$login'");
  2369. if (db_num_rows($result) == 0) {
  2370. db_query($link, "INSERT INTO ttrss_users
  2371. (login,pwd_hash,access_level,last_login)
  2372. VALUES ('$login', '$pwd_hash', 0, NOW())");
  2373. $result = db_query($link, "SELECT id FROM ttrss_users WHERE
  2374. login = '$login' AND pwd_hash = '$pwd_hash'");
  2375. if (db_num_rows($result) == 1) {
  2376. $new_uid = db_fetch_result($result, 0, "id");
  2377. print "<div class=\"notice\">Added user <b>".$_GET["login"].
  2378. "</b> with password <b>$tmp_user_pwd</b>.</div>";
  2379. initialize_user($link, $new_uid);
  2380. } else {
  2381. print "<div class=\"warning\">Could not create user <b>".
  2382. $_GET["login"]."</b></div>";
  2383. }
  2384. } else {
  2385. print "<div class=\"warning\">User <b>".
  2386. $_GET["login"]."</b> already exists.</div>";
  2387. }
  2388. }
  2389. } else if ($subop == "resetPass") {
  2390. if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
  2391. $uid = db_escape_string($_GET["id"]);
  2392. $result = db_query($link, "SELECT login,email
  2393. FROM ttrss_users WHERE id = '$uid'");
  2394. $login = db_fetch_result($result, 0, "login");
  2395. $email = db_fetch_result($result, 0, "email");
  2396. $tmp_user_pwd = make_password(8);
  2397. $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
  2398. db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
  2399. WHERE id = '$uid'");
  2400. print "<div class=\"notice\">Changed password of
  2401. user <b>$login</b> to <b>$tmp_user_pwd</b>.";
  2402. if (MAIL_RESET_PASS && $email) {
  2403. print " Notifying <b>$email</b>.";
  2404. mail("$login <$email>", "Password reset notification",
  2405. "Hi, $login.\n".
  2406. "\n".
  2407. "Your password for this TT-RSS installation was reset by".
  2408. " an administrator.\n".
  2409. "\n".
  2410. "Your new password is $tmp_user_pwd, please remember".
  2411. " it for later reference.\n".
  2412. "\n".
  2413. "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
  2414. }
  2415. print "</div>";
  2416. }
  2417. }
  2418. print "<div class=\"prefGenericAddBox\">
  2419. <input id=\"uadd_box\"
  2420. onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
  2421. size=\"40\">&nbsp;";
  2422. print"<input type=\"submit\" class=\"button\"
  2423. id=\"user_add_btn\" disabled=\"true\"
  2424. onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
  2425. $result = db_query($link, "SELECT
  2426. id,login,access_level,email,
  2427. SUBSTRING(last_login,1,16) as last_login
  2428. FROM
  2429. ttrss_users
  2430. ORDER by login");
  2431. // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
  2432. print "<p><table width=\"100%\" cellspacing=\"0\"
  2433. class=\"prefUserList\" id=\"prefUserList\">";
  2434. print "<tr><td class=\"selectPrompt\" colspan=\"8\">
  2435. Select:
  2436. <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
  2437. <a href=\"javascript:selectPrefRows('user', false)\">None</a>
  2438. </td</tr>";
  2439. print "<tr class=\"title\">
  2440. <td align='center' width=\"5%\">&nbsp;</td>
  2441. <td width='40%'>Login</td>
  2442. <td width='40%'>Access Level</td>
  2443. <td width='30%'>Last login</td></tr>";
  2444. $lnum = 0;
  2445. while ($line = db_fetch_assoc($result)) {
  2446. $class = ($lnum % 2) ? "even" : "odd";
  2447. $uid = $line["id"];
  2448. $edit_uid = $_GET["id"];
  2449. if ($subop == "edit" && $uid != $edit_uid) {
  2450. $class .= "Grayed";
  2451. $this_row_id = "";
  2452. } else {
  2453. $this_row_id = "id=\"UMRR-$uid\"";
  2454. }
  2455. print "<tr class=\"$class\" $this_row_id>";
  2456. $line["login"] = htmlspecialchars($line["login"]);
  2457. $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
  2458. strtotime($line["last_login"]));
  2459. $access_level_names = array(0 => "User", 10 => "Administrator");
  2460. // if (!$edit_uid || $subop != "edit") {
  2461. print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
  2462. type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
  2463. print "<td><a href=\"javascript:editUser($uid);\">" .
  2464. $line["login"] . "</td>";
  2465. if (!$line["email"]) $line["email"] = "&nbsp;";
  2466. print "<td><a href=\"javascript:editUser($uid);\">" .
  2467. $access_level_names[$line["access_level"]] . "</td>";
  2468. /* } else if ($uid != $edit_uid) {
  2469. if (!$line["email"]) $line["email"] = "&nbsp;";
  2470. print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
  2471. id=\"UMCHK-".$line["id"]."\"></td>";
  2472. print "<td>".$line["login"]."</td>";
  2473. print "<td>".$line["email"]."</td>";
  2474. print "<td>".$access_level_names[$line["access_level"]]."</td>";
  2475. } else {
  2476. print "<td align='center'>
  2477. <input disabled=\"true\" type=\"checkbox\" checked></td>";
  2478. print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
  2479. "\"></td>";
  2480. print "<td><input id=\"iedit_email\" value=\"".$line["email"].
  2481. "\"></td>";
  2482. print "<td>";
  2483. print "<select id=\"iedit_ulevel\">";
  2484. foreach (array_keys($access_level_names) as $al) {
  2485. if ($al == $line["access_level"]) {
  2486. $selected = "selected";
  2487. } else {
  2488. $selected = "";
  2489. }
  2490. print "<option $selected id=\"$al\">" .
  2491. $access_level_names[$al] . "</option>";
  2492. }
  2493. print "</select>";
  2494. print "</td>";
  2495. } */
  2496. print "<td>".$line["last_login"]."</td>";
  2497. print "</tr>";
  2498. ++$lnum;
  2499. }
  2500. print "</table>";
  2501. print "<p id='userOpToolbar'>";
  2502. /* if ($subop == "edit") {
  2503. print "Edit user:
  2504. <input type=\"submit\" class=\"button\"
  2505. onclick=\"javascript:userEditSave()\" value=\"Save\">
  2506. <input type=\"submit\" class=\"button\"
  2507. onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
  2508. } else { */
  2509. print "
  2510. Selection:
  2511. <input type=\"submit\" class=\"button\" disabled=\"true\"
  2512. onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
  2513. <input type=\"submit\" class=\"button\" disabled=\"true\"
  2514. onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
  2515. <input type=\"submit\" class=\"button\" disabled=\"true\"
  2516. onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
  2517. <input type=\"submit\" class=\"button\" disabled=\"true\"
  2518. onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
  2519. // }
  2520. }
  2521. if ($op == "user-details") {
  2522. if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
  2523. return;
  2524. }
  2525. /* print "<html><head>
  2526. <title>Tiny Tiny RSS : User Details</title>
  2527. <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
  2528. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  2529. </head><body>"; */
  2530. $uid = sprintf("%d", $_GET["id"]);
  2531. print "<div id=\"infoBoxTitle\">User details</div>";
  2532. print "<div class='infoBoxContents'>";
  2533. $result = db_query($link, "SELECT login,
  2534. SUBSTRING(last_login,1,16) AS last_login,
  2535. access_level,
  2536. (SELECT COUNT(int_id) FROM ttrss_user_entries
  2537. WHERE owner_uid = id) AS stored_articles
  2538. FROM ttrss_users
  2539. WHERE id = '$uid'");
  2540. if (db_num_rows($result) == 0) {
  2541. print "<h1>User not found</h1>";
  2542. return;
  2543. }
  2544. # print "<h1>User Details</h1>";
  2545. $login = db_fetch_result($result, 0, "login");
  2546. # print "<h1>$login</h1>";
  2547. print "<table width='100%'>";
  2548. $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
  2549. strtotime(db_fetch_result($result, 0, "last_login")));
  2550. $access_level = db_fetch_result($result, 0, "access_level");
  2551. $stored_articles = db_fetch_result($result, 0, "stored_articles");
  2552. # print "<tr><td>Username</td><td>$login</td></tr>";
  2553. # print "<tr><td>Access level</td><td>$access_level</td></tr>";
  2554. print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
  2555. print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
  2556. $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
  2557. WHERE owner_uid = '$uid'");
  2558. $num_feeds = db_fetch_result($result, 0, "num_feeds");
  2559. print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
  2560. /* $result = db_query($link, "SELECT
  2561. SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
  2562. FROM ttrss_user_entries,ttrss_entries
  2563. WHERE owner_uid = '$uid' AND ref_id = id");
  2564. $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
  2565. print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
  2566. print "</table>";
  2567. print "<h1>Subscribed feeds</h1>";
  2568. $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
  2569. WHERE owner_uid = '$uid' ORDER BY title");
  2570. print "<ul class=\"userFeedList\">";
  2571. $row_class = "odd";
  2572. while ($line = db_fetch_assoc($result)) {
  2573. $icon_file = ICONS_URL."/".$line["id"].".ico";
  2574. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  2575. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
  2576. } else {
  2577. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
  2578. }
  2579. print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
  2580. $row_class = toggleEvenOdd($row_class);
  2581. }
  2582. if (db_num_rows($result) < $num_feeds) {
  2583. // FIXME - add link to show ALL subscribed feeds here somewhere
  2584. print "<li><img
  2585. class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
  2586. }
  2587. print "</ul>";
  2588. print "</div>";
  2589. print "<div align='center'>
  2590. <input type='submit' class='button'
  2591. onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
  2592. // print "</body></html>";
  2593. }
  2594. if ($op == "pref-feed-browser") {
  2595. if (!ENABLE_FEED_BROWSER) {
  2596. print "Feed browser is administratively disabled.";
  2597. return;
  2598. }
  2599. $subop = $_REQUEST["subop"];
  2600. if ($subop == "details") {
  2601. $id = db_escape_string($_GET["id"]);
  2602. print "<div class=\"browserFeedInfo\">";
  2603. print "<b>Feed information:</b>";
  2604. print "<div class=\"detailsPart\">";
  2605. $result = db_query($link, "SELECT
  2606. feed_url,site_url,
  2607. SUBSTRING(last_updated,1,19) AS last_updated
  2608. FROM ttrss_feeds WHERE id = '$id'");
  2609. $feed_url = db_fetch_result($result, 0, "feed_url");
  2610. $site_url = db_fetch_result($result, 0, "site_url");
  2611. $last_updated = db_fetch_result($result, 0, "last_updated");
  2612. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  2613. $last_updated = smart_date_time(strtotime($last_updated));
  2614. } else {
  2615. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  2616. $last_updated = date($short_date, strtotime($last_updated));
  2617. }
  2618. print "Site: <a href='$site_url'>$site_url</a> ".
  2619. "(<a href='$feed_url'>feed</a>), ".
  2620. "Last updated: $last_updated";
  2621. print "</div>";
  2622. $result = db_query($link, "SELECT
  2623. ttrss_entries.title,
  2624. content,
  2625. substring(date_entered,1,19) as date_entered,
  2626. substring(updated,1,19) as updated
  2627. FROM ttrss_entries,ttrss_user_entries
  2628. WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
  2629. ORDER BY updated DESC LIMIT 5");
  2630. if (db_num_rows($result) > 0) {
  2631. print "<b>Last headlines:</b><br>";
  2632. print "<div class=\"detailsPart\">";
  2633. print "<ul class=\"compact\">";
  2634. while ($line = db_fetch_assoc($result)) {
  2635. if (get_pref($link, 'HEADLINES_SMART_DATE')) {
  2636. $entry_dt = smart_date_time(strtotime($line["updated"]));
  2637. } else {
  2638. $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
  2639. $entry_dt = date($short_date, strtotime($line["updated"]));
  2640. }
  2641. print "<li>" . $line["title"] .
  2642. "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
  2643. }
  2644. print "</ul></div>";
  2645. }
  2646. print "</div>";
  2647. return;
  2648. }
  2649. print "<p>This panel shows feeds subscribed by other users of this system, just in case you are interested in some of them too.</p>";
  2650. $limit = db_escape_string($_GET["limit"]);
  2651. if (!$limit) $limit = 25;
  2652. $owner_uid = $_SESSION["uid"];
  2653. $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
  2654. FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
  2655. WHERE tf.feed_url = ttrss_feeds.feed_url
  2656. AND owner_uid = '$owner_uid') GROUP BY feed_url
  2657. ORDER BY subscribers DESC LIMIT $limit");
  2658. print "<div style=\"float : right\">
  2659. Top <select id=\"feedBrowserLimit\">";
  2660. foreach (array(25, 50, 100) as $l) {
  2661. $issel = ($l == $limit) ? "selected" : "";
  2662. print "<option $issel>$l</option>";
  2663. }
  2664. print "</select>
  2665. <input type=\"submit\" class=\"button\"
  2666. onclick=\"updateBigFeedBrowser()\" value=\"Show\">
  2667. </div>";
  2668. print "<p id=\"fbrOpToolbar\">Selection:
  2669. <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
  2670. disabled=\"true\" value=\"Subscribe\">";
  2671. print "<ul class='nomarks' id='browseBigFeedList'>";
  2672. $feedctr = 0;
  2673. while ($line = db_fetch_assoc($result)) {
  2674. $feed_url = $line["feed_url"];
  2675. $subscribers = $line["subscribers"];
  2676. $det_result = db_query($link, "SELECT site_url,title,id
  2677. FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
  2678. $details = db_fetch_assoc($det_result);
  2679. $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
  2680. if (file_exists($icon_file) && filesize($icon_file) > 0) {
  2681. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
  2682. "/".$details["id"].".ico\">";
  2683. } else {
  2684. $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
  2685. }
  2686. $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
  2687. type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
  2688. $class = ($feedctr % 2) ? "even" : "odd";
  2689. print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
  2690. "$feed_icon ";
  2691. print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
  2692. $details["title"] ."</a>&nbsp;" .
  2693. "<span class='subscribers'>($subscribers)</span>";
  2694. print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
  2695. print "</div>";
  2696. print "</li>";
  2697. ++$feedctr;
  2698. }
  2699. if ($feedctr == 0) {
  2700. print "<li>No feeds found to subscribe.</li>";
  2701. }
  2702. print "</ul>";
  2703. print "</div>";
  2704. }
  2705. if ($op == "rss") {
  2706. $feed = db_escape_string($_GET["id"]);
  2707. $user = db_escape_string($_GET["user"]);
  2708. $pass = db_escape_string($_GET["pass"]);
  2709. $is_cat = $_GET["is_cat"] != false;
  2710. $search = db_escape_string($_GET["q"]);
  2711. $match_on = db_escape_string($_GET["m"]);
  2712. $search_mode = db_escape_string($_GET["smode"]);
  2713. if (!$_SESSION["uid"] && $user && $pass) {
  2714. authenticate_user($link, $user, $pass);
  2715. }
  2716. if ($_SESSION["uid"] ||
  2717. http_authenticate_user($link)) {
  2718. generate_syndicated_feed($link, $feed, $is_cat,
  2719. $search, $search_mode, $match_on);
  2720. }
  2721. }
  2722. function check_configuration_variables() {
  2723. if (!defined('SESSION_EXPIRE_TIME')) {
  2724. return "config: SESSION_EXPIRE_TIME is undefined";
  2725. }
  2726. if (SESSION_EXPIRE_TIME < 60) {
  2727. return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
  2728. }
  2729. if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
  2730. return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
  2731. "SESSION_COOKIE_LIFETIME_REMEMBER";
  2732. }
  2733. if (defined('DISABLE_SESSIONS')) {
  2734. return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
  2735. }
  2736. if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
  2737. return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
  2738. }
  2739. return false;
  2740. }
  2741. if ($op == "labelFromSearch") {
  2742. $search = db_escape_string($_GET["search"]);
  2743. $search_mode = db_escape_string($_GET["smode"]);
  2744. $match_on = db_escape_string($_GET["match"]);
  2745. $is_cat = db_escape_string($_GET["is_cat"]);
  2746. $title = db_escape_string($_GET["title"]);
  2747. $feed = sprintf("%d", $_GET["feed"]);
  2748. $label_qparts = array();
  2749. $search_expr = getSearchSql($search, $match_on);
  2750. if ($is_cat) {
  2751. if ($feed != 0) {
  2752. $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
  2753. } else {
  2754. $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
  2755. }
  2756. } else {
  2757. if ($search_mode == "all_feeds") {
  2758. // NOOP
  2759. } else if ($search_mode == "this_cat") {
  2760. $tmp_result = db_query($link, "SELECT cat_id
  2761. FROM ttrss_feeds WHERE id = '$feed'");
  2762. $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
  2763. if ($cat_id > 0) {
  2764. $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
  2765. } else {
  2766. $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
  2767. }
  2768. } else {
  2769. $search_expr .= " AND ttrss_feeds.id = $feed ";
  2770. }
  2771. }
  2772. $search_expr = db_escape_string($search_expr);
  2773. print $search_expr;
  2774. if ($title) {
  2775. $result = db_query($link,
  2776. "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
  2777. VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
  2778. }
  2779. }
  2780. db_close($link);
  2781. ?>
  2782. <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->