]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/feeds.php
2 class Pref_Feeds
extends Handler_Protected
{
3 public static $feed_languages = array ( "English" , "Danish" , "Dutch" , "Finnish" , "French" , "German" , "Hungarian" , "Italian" , "Norwegian" ,
4 "Portuguese" , "Russian" , "Spanish" , "Swedish" , "Turkish" , "Simple" );
6 function csrf_ignore ( $method ) {
7 $csrf_ignored = array ( "index" , "getfeedtree" , "add" , "editcats" , "editfeed" ,
8 "savefeedorder" , "uploadicon" , "feedswitherrors" , "inactivefeeds" ,
11 return array_search ( $method , $csrf_ignored ) !== false ;
14 function batch_edit_cbox ( $elem , $label = false ) {
15 print "<input type= \" checkbox \" title= \" " . __ ( "Check to enable field" ). " \"
16 onchange= \" dijit.byId('feedEditDlg').toggleField(this, ' $elem ', ' $label ') \" >" ;
19 function renamecat () {
20 $title = clean ( $_REQUEST [ 'title' ]);
21 $id = clean ( $_REQUEST [ 'id' ]);
24 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories SET
25 title = ? WHERE id = ? AND owner_uid = ?" );
26 $sth -> execute ([ $title , $id , $_SESSION [ 'uid' ]]);
30 private function get_category_items ( $cat_id ) {
32 if ( clean ( $_REQUEST [ 'mode' ]) != 2 )
33 $search = $_SESSION [ "prefs_feed_search" ];
37 // first one is set by API
38 $show_empty_cats = clean ( $_REQUEST [ 'force_show_empty' ]) ||
39 ( clean ( $_REQUEST [ 'mode' ]) != 2 && ! $search );
43 $sth = $this -> pdo
-> prepare ( "SELECT id, title FROM ttrss_feed_categories
44 WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title" );
45 $sth -> execute ([ $_SESSION [ 'uid' ], $cat_id ]);
47 while ( $line = $sth -> fetch ()) {
50 $cat [ 'id' ] = 'CAT:' . $line [ 'id' ];
51 $cat [ 'bare_id' ] = ( int ) $line [ 'id' ];
52 $cat [ 'name' ] = $line [ 'title' ];
53 $cat [ 'items' ] = array ();
54 $cat [ 'checkbox' ] = false ;
55 $cat [ 'type' ] = 'category' ;
57 $cat [ 'child_unread' ] = 0 ;
58 $cat [ 'auxcounter' ] = 0 ;
59 $cat [ 'parent_id' ] = $cat_id ;
61 $cat [ 'items' ] = $this -> get_category_items ( $line [ 'id' ]);
63 $num_children = $this -> calculate_children_count ( $cat );
64 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , ( int ) $num_children ), $num_children );
66 if ( $num_children > 0 ||
$show_empty_cats )
67 array_push ( $items , $cat );
71 $fsth = $this -> pdo
-> prepare ( "SELECT id, title, last_error,
72 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated, update_interval
74 WHERE cat_id = :cat AND
76 (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
77 ORDER BY order_id, title" );
79 $fsth -> execute ([ ":cat" => $cat_id , ":uid" => $_SESSION [ 'uid' ], ":search" => $search ?
"% $search %" : "" ]);
81 while ( $feed_line = $fsth -> fetch ()) {
83 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
84 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
85 $feed [ 'auxcounter' ] = 0 ;
86 $feed [ 'name' ] = $feed_line [ 'title' ];
87 $feed [ 'checkbox' ] = false ;
89 $feed [ 'error' ] = $feed_line [ 'last_error' ];
90 $feed [ 'icon' ] = Feeds
:: getFeedIcon ( $feed_line [ 'id' ]);
91 $feed [ 'param' ] = make_local_datetime (
92 $feed_line [ 'last_updated' ], true );
93 $feed [ 'updates_disabled' ] = ( int )( $feed_line [ 'update_interval' ] < 0 );
95 array_push ( $items , $feed );
101 function getfeedtree () {
102 print json_encode ( $this -> makefeedtree ());
105 function makefeedtree () {
107 if ( clean ( $_REQUEST [ 'mode' ]) != 2 )
108 $search = $_SESSION [ "prefs_feed_search" ];
113 $root [ 'id' ] = 'root' ;
114 $root [ 'name' ] = __ ( 'Feeds' );
115 $root [ 'items' ] = array ();
116 $root [ 'type' ] = 'category' ;
118 $enable_cats = get_pref ( 'ENABLE_FEED_CATS' );
120 if ( clean ( $_REQUEST [ 'mode' ]) == 2 ) {
123 $cat = $this -> feedlist_init_cat (- 1 );
125 $cat [ 'items' ] = array ();
128 foreach ( array (- 4 , - 3 , - 1 , - 2 , 0 , - 6 ) as $i ) {
129 array_push ( $cat [ 'items' ], $this -> feedlist_init_feed ( $i ));
132 /* Plugin feeds for -1 */
134 $feeds = PluginHost
:: getInstance ()-> get_feeds (- 1 );
137 foreach ( $feeds as $feed ) {
138 $feed_id = PluginHost
:: pfeed_to_feed_id ( $feed [ 'id' ]);
141 $item [ 'id' ] = 'FEED:' . $feed_id ;
142 $item [ 'bare_id' ] = ( int ) $feed_id ;
143 $item [ 'auxcounter' ] = 0 ;
144 $item [ 'name' ] = $feed [ 'title' ];
145 $item [ 'checkbox' ] = false ;
147 $item [ 'icon' ] = $feed [ 'icon' ];
150 $item [ 'unread' ] = 0 ; //$feed['sender']->get_unread($feed['id']);
151 $item [ 'type' ] = 'feed' ;
153 array_push ( $cat [ 'items' ], $item );
158 array_push ( $root [ 'items' ], $cat );
160 $root [ 'items' ] = array_merge ( $root [ 'items' ], $cat [ 'items' ]);
163 $sth = $this -> pdo
-> prepare ( "SELECT * FROM
164 ttrss_labels2 WHERE owner_uid = ? ORDER by caption" );
165 $sth -> execute ([ $_SESSION [ 'uid' ]]);
167 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
168 $cat = $this -> feedlist_init_cat (- 2 );
170 $cat [ 'items' ] = array ();
174 while ( $line = $sth -> fetch ()) {
177 $label_id = Labels
:: label_to_feed_id ( $line [ 'id' ]);
179 $feed = $this -> feedlist_init_feed ( $label_id , false , 0 );
181 $feed [ 'fg_color' ] = $line [ 'fg_color' ];
182 $feed [ 'bg_color' ] = $line [ 'bg_color' ];
184 array_push ( $cat [ 'items' ], $feed );
189 array_push ( $root [ 'items' ], $cat );
191 $root [ 'items' ] = array_merge ( $root [ 'items' ], $cat [ 'items' ]);
197 $show_empty_cats = clean ( $_REQUEST [ 'force_show_empty' ]) ||
198 ( clean ( $_REQUEST [ 'mode' ]) != 2 && ! $search );
200 $sth = $this -> pdo
-> prepare ( "SELECT id, title FROM ttrss_feed_categories
201 WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title" );
202 $sth -> execute ([ $_SESSION [ 'uid' ]]);
204 while ( $line = $sth -> fetch ()) {
206 $cat [ 'id' ] = 'CAT:' . $line [ 'id' ];
207 $cat [ 'bare_id' ] = ( int ) $line [ 'id' ];
208 $cat [ 'auxcounter' ] = 0 ;
209 $cat [ 'name' ] = $line [ 'title' ];
210 $cat [ 'items' ] = array ();
211 $cat [ 'checkbox' ] = false ;
212 $cat [ 'type' ] = 'category' ;
214 $cat [ 'child_unread' ] = 0 ;
216 $cat [ 'items' ] = $this -> get_category_items ( $line [ 'id' ]);
218 $num_children = $this -> calculate_children_count ( $cat );
219 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , ( int ) $num_children ), $num_children );
221 if ( $num_children > 0 ||
$show_empty_cats )
222 array_push ( $root [ 'items' ], $cat );
224 $root [ 'param' ] +
= count ( $cat [ 'items' ]);
227 /* Uncategorized is a special case */
230 $cat [ 'id' ] = 'CAT:0' ;
232 $cat [ 'auxcounter' ] = 0 ;
233 $cat [ 'name' ] = __ ( "Uncategorized" );
234 $cat [ 'items' ] = array ();
235 $cat [ 'type' ] = 'category' ;
236 $cat [ 'checkbox' ] = false ;
238 $cat [ 'child_unread' ] = 0 ;
240 $fsth = $this -> pdo
-> prepare ( "SELECT id, title,last_error,
241 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated, update_interval
243 WHERE cat_id IS NULL AND
245 (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
246 ORDER BY order_id, title" );
247 $fsth -> execute ([ ":uid" => $_SESSION [ 'uid' ], ":search" => $search ?
"% $search %" : "" ]);
249 while ( $feed_line = $fsth -> fetch ()) {
251 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
252 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
253 $feed [ 'auxcounter' ] = 0 ;
254 $feed [ 'name' ] = $feed_line [ 'title' ];
255 $feed [ 'checkbox' ] = false ;
256 $feed [ 'error' ] = $feed_line [ 'last_error' ];
257 $feed [ 'icon' ] = Feeds
:: getFeedIcon ( $feed_line [ 'id' ]);
258 $feed [ 'param' ] = make_local_datetime (
259 $feed_line [ 'last_updated' ], true );
261 $feed [ 'type' ] = 'feed' ;
262 $feed [ 'updates_disabled' ] = ( int )( $feed_line [ 'update_interval' ] < 0 );
264 array_push ( $cat [ 'items' ], $feed );
267 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
269 if ( count ( $cat [ 'items' ]) > 0 ||
$show_empty_cats )
270 array_push ( $root [ 'items' ], $cat );
272 $num_children = $this -> calculate_children_count ( $root );
273 $root [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , ( int ) $num_children ), $num_children );
276 $fsth = $this -> pdo
-> prepare ( "SELECT id, title, last_error,
277 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated, update_interval
279 WHERE owner_uid = :uid AND
280 (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
281 ORDER BY order_id, title" );
282 $fsth -> execute ([ ":uid" => $_SESSION [ 'uid' ], ":search" => $search ?
"% $search %" : "" ]);
284 while ( $feed_line = $fsth -> fetch ()) {
286 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
287 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
288 $feed [ 'auxcounter' ] = 0 ;
289 $feed [ 'name' ] = $feed_line [ 'title' ];
290 $feed [ 'checkbox' ] = false ;
291 $feed [ 'error' ] = $feed_line [ 'last_error' ];
292 $feed [ 'icon' ] = Feeds
:: getFeedIcon ( $feed_line [ 'id' ]);
293 $feed [ 'param' ] = make_local_datetime (
294 $feed_line [ 'last_updated' ], true );
296 $feed [ 'type' ] = 'feed' ;
297 $feed [ 'updates_disabled' ] = ( int )( $feed_line [ 'update_interval' ] < 0 );
299 array_push ( $root [ 'items' ], $feed );
302 $root [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
306 $fl [ 'identifier' ] = 'id' ;
307 $fl [ 'label' ] = 'name' ;
309 if ( clean ( $_REQUEST [ 'mode' ]) != 2 ) {
310 $fl [ 'items' ] = array ( $root );
312 $fl [ 'items' ] = $root [ 'items' ];
318 function catsortreset () {
319 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories
320 SET order_id = 0 WHERE owner_uid = ?" );
321 $sth -> execute ([ $_SESSION [ 'uid' ]]);
324 function feedsortreset () {
325 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds
326 SET order_id = 0 WHERE owner_uid = ?" );
327 $sth -> execute ([ $_SESSION [ 'uid' ]]);
330 private function process_category_order (& $data_map , $item_id , $parent_id = false , $nest_level = 0 ) {
331 $debug = isset ( $_REQUEST [ "debug" ]);
334 for ( $i = 0 ; $i < $nest_level ; $i ++
)
337 if ( $debug ) _debug ( " $prefix C: $item_id P: $parent_id " );
339 $bare_item_id = substr ( $item_id , strpos ( $item_id , ':' ) +
1 );
341 if ( $item_id != 'root' ) {
342 if ( $parent_id && $parent_id != 'root' ) {
343 $parent_bare_id = substr ( $parent_id , strpos ( $parent_id , ':' ) +
1 );
344 $parent_qpart = $parent_bare_id ;
346 $parent_qpart = null ;
349 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories
350 SET parent_cat = ? WHERE id = ? AND
352 $sth -> execute ([ $parent_qpart , $bare_item_id , $_SESSION [ 'uid' ]]);
357 $cat = $data_map [ $item_id ];
359 if ( $cat && is_array ( $cat )) {
360 foreach ( $cat as $item ) {
361 $id = $item [ '_reference' ];
362 $bare_id = substr ( $id , strpos ( $id , ':' ) +
1 );
364 if ( $debug ) _debug ( " $prefix [ $order_id ] $id / $bare_id " );
366 if ( $item [ '_reference' ]) {
368 if ( strpos ( $id , "FEED" ) === 0 ) {
370 $cat_id = ( $item_id != "root" ) ?
$bare_item_id : null ;
372 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds
373 SET order_id = ?, cat_id = ?
374 WHERE id = ? AND owner_uid = ?" );
376 $sth -> execute ([ $order_id , $cat_id ?
$cat_id : null , $bare_id , $_SESSION [ 'uid' ]]);
378 } else if ( strpos ( $id , "CAT:" ) === 0 ) {
379 $this -> process_category_order ( $data_map , $item [ '_reference' ], $item_id ,
382 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories
383 SET order_id = ? WHERE id = ? AND
385 $sth -> execute ([ $order_id , $bare_id , $_SESSION [ 'uid' ]]);
394 function savefeedorder () {
395 $data = json_decode ( $_POST [ 'payload' ], true );
397 #file_put_contents("/tmp/saveorder.json", clean($_POST['payload']));
398 #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
400 if (! is_array ( $data [ 'items' ]))
401 $data [ 'items' ] = json_decode ( $data [ 'items' ], true );
403 # print_r($data['items']);
405 if ( is_array ( $data ) && is_array ( $data [ 'items' ])) {
411 foreach ( $data [ 'items' ] as $item ) {
413 # if ($item['id'] != 'root') {
414 if ( is_array ( $item [ 'items' ])) {
415 if ( isset ( $item [ 'items' ][ '_reference' ])) {
416 $data_map [ $item [ 'id' ]] = array ( $item [ 'items' ]);
418 $data_map [ $item [ 'id' ]] = $item [ 'items' ];
421 if ( $item [ 'id' ] == 'root' ) {
422 $root_item = $item [ 'id' ];
426 $this -> process_category_order ( $data_map , $root_item );
430 function removeicon () {
431 $feed_id = clean ( $_REQUEST [ "feed_id" ]);
433 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
434 WHERE id = ? AND owner_uid = ?" );
435 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
437 if ( $row = $sth -> fetch ()) {
438 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
440 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET favicon_avg_color = NULL
442 $sth -> execute ([ $feed_id ]);
446 function uploadicon () {
447 header ( "Content-type: text/html" );
449 if ( is_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ])) {
450 $tmp_file = tempnam ( CACHE_DIR
. '/upload' , 'icon' );
452 $result = move_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ],
462 $icon_file = $tmp_file ;
463 $feed_id = clean ( $_REQUEST [ "feed_id" ]);
465 if ( is_file ( $icon_file ) && $feed_id ) {
466 if ( filesize ( $icon_file ) < 65535 ) {
468 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
469 WHERE id = ? AND owner_uid = ?" );
470 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
472 if ( $row = $sth -> fetch ()) {
473 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
474 if ( rename ( $icon_file , ICONS_DIR
. "/ $feed_id .ico" )) {
476 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET
477 favicon_avg_color = ''
479 $sth -> execute ([ $feed_id ]);
495 print "<script type= \" text/javascript \" >" ;
496 print "parent.uploadIconHandler( $rc );" ;
501 function editfeed () {
502 global $purge_intervals ;
503 global $update_intervals ;
506 $feed_id = clean ( $_REQUEST [ "id" ]);
508 $sth = $this -> pdo
-> prepare ( "SELECT * FROM ttrss_feeds WHERE id = ? AND
510 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
512 if ( $row = $sth -> fetch ()) {
513 print '<div dojoType="dijit.layout.TabContainer" style="height : 450px">
514 <div dojoType="dijit.layout.ContentPane" title="' . __ ( 'General' ). '">' ;
516 $auth_pass_encrypted = $row [ "auth_pass_encrypted" ];
518 $title = htmlspecialchars ( $row [ "title" ]);
520 print_hidden ( "id" , " $feed_id " );
521 print_hidden ( "op" , "pref-feeds" );
522 print_hidden ( "method" , "editSave" );
524 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
525 print "<div class= \" dlgSecCont \" >" ;
529 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
530 placeHolder= \" " . __ ( "Feed Title" ). " \"
531 style= \" font-size : 16px; width: 20em \" name= \" title \" value= \" $title\" >" ;
535 $feed_url = htmlspecialchars ( $row [ "feed_url" ]);
539 print __ ( 'URL:' ) . " " ;
540 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
541 placeHolder= \" " . __ ( "Feed URL" ). " \"
542 regExp='^(http|https)://.*' style= \" width : 20em \"
543 name= \" feed_url \" value= \" $feed_url\" >" ;
545 $last_error = $row [ "last_error" ];
548 print " <img src= \" images/error.png \" alt= \" (error) \"
549 style= \" vertical-align : middle \"
550 title= \" " . htmlspecialchars ( $last_error ). " \" >" ;
556 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
558 $cat_id = $row [ "cat_id" ];
562 print __ ( 'Place in category:' ) . " " ;
564 print_feed_cat_select ( "cat_id" , $cat_id ,
565 'dojoType="dijit.form.Select"' );
568 /* FTS Stemming Language */
570 if ( DB_TYPE
== "pgsql" ) {
571 $feed_language = $row [ "feed_language" ];
575 print __ ( 'Language:' ) . " " ;
576 print_select ( "feed_language" , $feed_language , $this :: $feed_languages ,
577 'dojoType="dijit.form.Select"' );
582 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
583 print "<div class= \" dlgSecCont \" >" ;
585 /* Update Interval */
587 $update_interval = $row [ "update_interval" ];
589 print_select_hash ( "update_interval" , $update_interval , $update_intervals ,
590 'dojoType="dijit.form.Select"' );
594 $purge_interval = $row [ "purge_interval" ];
597 print __ ( 'Article purging:' ) . " " ;
599 print_select_hash ( "purge_interval" , $purge_interval , $purge_intervals ,
600 'dojoType="dijit.form.Select" ' .
601 (( FORCE_ARTICLE_PURGE
== 0 ) ?
"" : 'disabled="1"' ));
605 $auth_login = htmlspecialchars ( $row [ "auth_login" ]);
606 $auth_pass = $row [ "auth_pass" ];
608 if ( $auth_pass_encrypted && function_exists ( "mcrypt_decrypt" )) {
609 require_once "crypt.php" ;
610 $auth_pass = decrypt_string ( $auth_pass );
613 $auth_pass = htmlspecialchars ( $auth_pass );
614 $auth_enabled = $auth_login !== '' ||
$auth_pass !== '' ;
616 $auth_style = $auth_enabled ?
'' : 'display: none' ;
617 print "<div id='feedEditDlg_loginContainer' style=' $auth_style '>" ;
618 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
619 print "<div class= \" dlgSecCont \" >" ;
621 print "<input dojoType= \" dijit.form.TextBox \" id= \" feedEditDlg_login \"
622 placeHolder= \" " . __ ( "Login" ). " \"
623 autocomplete= \" new-password \"
624 name= \" auth_login \" value= \" $auth_login\" ><hr/>" ;
627 print "<input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
628 autocomplete= \" new-password \"
629 placeHolder= \" " . __ ( "Password" ). " \"
630 value= \" $auth_pass\" >" ;
632 print "<div dojoType= \" dijit.Tooltip \" connectId= \" feedEditDlg_login \" position= \" below \" >
633 " . __ ( '<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.' ). "
636 print "</div></div>" ;
638 $auth_checked = $auth_enabled ?
'checked' : '' ;
639 print "<div style= \" clear : both \" >
640 <input type= \" checkbox \" $auth_checked name= \" need_auth \" dojoType= \" dijit.form.CheckBox \" id= \" feedEditDlg_loginCheck \"
641 onclick='checkboxToggleElement(this, \" feedEditDlg_loginContainer \" )'>
642 <label for= \" feedEditDlg_loginCheck \" >" .
643 __ ( 'This feed requires authentication.' ). "</div>" ;
645 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Options' ). '">' ;
647 //print "<div class=\"dlgSec\">".__("Options")."</div>";
648 print "<div class= \" dlgSecSimple \" >" ;
650 $private = $row [ "private" ];
653 $checked = "checked= \" 1 \" " ;
658 print "<input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" name= \" private \" id= \" private \"
659 $checked > <label for= \" private \" >" . __ ( 'Hide from Popular feeds' ). "</label>" ;
661 $include_in_digest = $row [ "include_in_digest" ];
663 if ( $include_in_digest ) {
664 $checked = "checked= \" 1 \" " ;
669 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" include_in_digest \"
670 name= \" include_in_digest \"
671 $checked > <label for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
674 $always_display_enclosures = $row [ "always_display_enclosures" ];
676 if ( $always_display_enclosures ) {
677 $checked = "checked" ;
682 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" always_display_enclosures \"
683 name= \" always_display_enclosures \"
684 $checked > <label for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
686 $hide_images = $row [ "hide_images" ];
689 $checked = "checked= \" 1 \" " ;
694 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" hide_images \"
696 $checked > <label for= \" hide_images \" >" .
697 __ ( 'Do not embed images' ). "</label>" ;
699 $cache_images = $row [ "cache_images" ];
702 $checked = "checked= \" 1 \" " ;
707 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" cache_images \"
708 name= \" cache_images \"
709 $checked > <label for= \" cache_images \" >" .
710 __ ( 'Cache media' ). "</label>" ;
712 $mark_unread_on_update = $row [ "mark_unread_on_update" ];
714 if ( $mark_unread_on_update ) {
715 $checked = "checked" ;
720 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" mark_unread_on_update \"
721 name= \" mark_unread_on_update \"
722 $checked > <label for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
726 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Icon' ). '">' ;
730 print "<div class= \" dlgSecSimple \" >" ;
732 print "<img class= \" feedIcon \" src= \" " . Feeds
:: getFeedIcon ( $feed_id ). " \" >" ;
734 print "<iframe name= \" icon_upload_iframe \"
735 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
737 print "<form style='display : block' target= \" icon_upload_iframe \"
738 enctype= \" multipart/form-data \" method= \" POST \"
739 action= \" backend.php \" >
740 <label class= \" dijitButton \" >" . __ ( "Choose file..." ). "
741 <input style= \" display: none \" id= \" icon_file \" size= \" 10 \" name= \" icon_file \" type= \" file \" >
743 <input type= \" hidden \" name= \" op \" value= \" pref-feeds \" >
744 <input type= \" hidden \" name= \" feed_id \" value= \" $feed_id\" >
745 <input type= \" hidden \" name= \" method \" value= \" uploadicon \" >
746 <button class= \"\" dojoType= \" dijit.form.Button \" onclick= \" return uploadFeedIcon(); \"
747 type= \" submit \" >" . __ ( 'Replace' ). "</button>
748 <button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" return removeFeedIcon( $feed_id ); \"
749 type= \" submit \" >" . __ ( 'Remove' ). "</button>
754 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Plugins' ). '">' ;
756 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_EDIT_FEED
,
757 "hook_prefs_edit_feed" , $feed_id );
760 print "</div></div>" ;
762 $title = htmlspecialchars ( $title , ENT_QUOTES
);
764 print "<div class='dlgButtons'>
765 <div style= \" float : left \" >
766 <button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick='return unsubscribeFeed( $feed_id , \" $title\" )'>" .
767 __ ( 'Unsubscribe' ). "</button>" ;
771 print "<button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').execute() \" >" . __ ( 'Save' ). "</button>
772 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
777 function editfeeds () {
778 global $purge_intervals ;
779 global $update_intervals ;
781 $feed_ids = clean ( $_REQUEST [ "ids" ]);
783 print_notice ( "Enable the options you wish to apply using checkboxes on the right:" );
787 print_hidden ( "ids" , " $feed_ids " );
788 print_hidden ( "op" , "pref-feeds" );
789 print_hidden ( "method" , "batchEditSave" );
791 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
792 print "<div class= \" dlgSecCont \" >" ;
796 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
798 print __ ( 'Place in category:' ) . " " ;
800 print_feed_cat_select ( "cat_id" , false ,
801 'disabled="1" dojoType="dijit.form.Select"' );
803 $this -> batch_edit_cbox ( "cat_id" );
807 /* FTS Stemming Language */
809 if ( DB_TYPE
== "pgsql" ) {
812 print __ ( 'Language:' ) . " " ;
813 print_select ( "feed_language" , "" , $this :: $feed_languages ,
814 'disabled="1" dojoType="dijit.form.Select"' );
816 $this -> batch_edit_cbox ( "feed_language" );
821 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
822 print "<div class= \" dlgSecCont \" >" ;
824 /* Update Interval */
826 print_select_hash ( "update_interval" , "" , $update_intervals ,
827 'disabled="1" dojoType="dijit.form.Select"' );
829 $this -> batch_edit_cbox ( "update_interval" );
833 if ( FORCE_ARTICLE_PURGE
== 0 ) {
837 print __ ( 'Article purging:' ) . " " ;
839 print_select_hash ( "purge_interval" , "" , $purge_intervals ,
840 'disabled="1" dojoType="dijit.form.Select"' );
842 $this -> batch_edit_cbox ( "purge_interval" );
846 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
847 print "<div class= \" dlgSecCont \" >" ;
849 print "<input dojoType= \" dijit.form.TextBox \"
850 placeHolder= \" " . __ ( "Login" ). " \" disabled= \" 1 \"
851 autocomplete= \" new-password \"
852 name= \" auth_login \" value= \"\" >" ;
854 $this -> batch_edit_cbox ( "auth_login" );
856 print "<hr/> <input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
857 autocomplete= \" new-password \"
858 placeHolder= \" " . __ ( "Password" ). " \" disabled= \" 1 \"
861 $this -> batch_edit_cbox ( "auth_pass" );
864 print "<div class= \" dlgSec \" >" . __ ( "Options" ). "</div>" ;
865 print "<div class= \" dlgSecCont \" >" ;
867 print "<input disabled= \" 1 \" type= \" checkbox \" name= \" private \" id= \" private \"
868 dojoType= \" dijit.form.CheckBox \" > <label id= \" private_l \" class='insensitive' for= \" private \" >" . __ ( 'Hide from Popular feeds' ). "</label>" ;
870 print " " ; $this -> batch_edit_cbox ( "private" , "private_l" );
872 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" include_in_digest \"
873 name= \" include_in_digest \"
874 dojoType= \" dijit.form.CheckBox \" > <label id= \" include_in_digest_l \" class='insensitive' for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
876 print " " ; $this -> batch_edit_cbox ( "include_in_digest" , "include_in_digest_l" );
878 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" always_display_enclosures \"
879 name= \" always_display_enclosures \"
880 dojoType= \" dijit.form.CheckBox \" > <label id= \" always_display_enclosures_l \" class='insensitive' for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
882 print " " ; $this -> batch_edit_cbox ( "always_display_enclosures" , "always_display_enclosures_l" );
884 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" hide_images \"
886 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" hide_images_l \"
887 for= \" hide_images \" >" .
888 __ ( 'Do not embed images' ). "</label>" ;
890 print " " ; $this -> batch_edit_cbox ( "hide_images" , "hide_images_l" );
892 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" cache_images \"
893 name= \" cache_images \"
894 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" cache_images_l \"
895 for= \" cache_images \" >" .
896 __ ( 'Cache media' ). "</label>" ;
898 print " " ; $this -> batch_edit_cbox ( "cache_images" , "cache_images_l" );
900 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" mark_unread_on_update \"
901 name= \" mark_unread_on_update \"
902 dojoType= \" dijit.form.CheckBox \" > <label id= \" mark_unread_on_update_l \" class='insensitive' for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
904 print " " ; $this -> batch_edit_cbox ( "mark_unread_on_update" , "mark_unread_on_update_l" );
908 print "<div class='dlgButtons'>
909 <button dojoType= \" dijit.form.Button \"
910 onclick= \" return dijit.byId('feedEditDlg').execute() \" >" .
911 __ ( 'Save' ). "</button>
912 <button dojoType= \" dijit.form.Button \"
913 onclick= \" return dijit.byId('feedEditDlg').hide() \" >" .
914 __ ( 'Cancel' ). "</button>
920 function batchEditSave () {
921 return $this -> editsaveops ( true );
924 function editSave () {
925 return $this -> editsaveops ( false );
928 function editsaveops ( $batch ) {
930 $feed_title = trim ( clean ( $_POST [ "title" ]));
931 $feed_url = trim ( clean ( $_POST [ "feed_url" ]));
932 $upd_intl = ( int ) clean ( $_POST [ "update_interval" ]);
933 $purge_intl = ( int ) clean ( $_POST [ "purge_interval" ]);
934 $feed_id = ( int ) clean ( $_POST [ "id" ]); /* editSave */
935 $feed_ids = explode ( "," , clean ( $_POST [ "ids" ])); /* batchEditSave */
936 $cat_id = ( int ) clean ( $_POST [ "cat_id" ]);
937 $auth_login = trim ( clean ( $_POST [ "auth_login" ]));
938 $auth_pass = trim ( clean ( $_POST [ "auth_pass" ]));
939 $private = checkbox_to_sql_bool ( clean ( $_POST [ "private" ]));
940 $include_in_digest = checkbox_to_sql_bool (
941 clean ( $_POST [ "include_in_digest" ]));
942 $cache_images = checkbox_to_sql_bool (
943 clean ( $_POST [ "cache_images" ]));
944 $hide_images = checkbox_to_sql_bool (
945 clean ( $_POST [ "hide_images" ]));
946 $always_display_enclosures = checkbox_to_sql_bool (
947 clean ( $_POST [ "always_display_enclosures" ]));
949 $mark_unread_on_update = checkbox_to_sql_bool (
950 clean ( $_POST [ "mark_unread_on_update" ]));
952 $feed_language = trim ( clean ( $_POST [ "feed_language" ]));
955 if ( clean ( $_POST [ "need_auth" ]) !== 'on' ) {
960 $sth = $this -> pdo
-> prepare ( "SELECT feed_url FROM ttrss_feeds WHERE id = ?" );
961 $sth -> execute ([ $feed_id ]);
962 $row = $sth -> fetch ();
963 $orig_feed_url = $row [ "feed_url" ];
965 $reset_basic_info = $orig_feed_url != $feed_url ;
967 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET
970 feed_url = :feed_url,
971 update_interval = :upd_intl,
972 purge_interval = :purge_intl,
973 auth_login = :auth_login,
974 auth_pass = :auth_pass,
975 auth_pass_encrypted = false,
977 cache_images = :cache_images,
978 hide_images = :hide_images,
979 include_in_digest = :include_in_digest,
980 always_display_enclosures = :always_display_enclosures,
981 mark_unread_on_update = :mark_unread_on_update,
982 feed_language = :feed_language
983 WHERE id = :id AND owner_uid = :uid" );
985 $sth -> execute ([ ":title" => $feed_title ,
986 ":cat_id" => $cat_id ?
$cat_id : null ,
987 ":feed_url" => $feed_url ,
988 ":upd_intl" => $upd_intl ,
989 ":purge_intl" => $purge_intl ,
990 ":auth_login" => $auth_login ,
991 ":auth_pass" => $auth_pass ,
992 ":private" => ( int ) $private ,
993 ":cache_images" => ( int ) $cache_images ,
994 ":hide_images" => ( int ) $hide_images ,
995 ":include_in_digest" => ( int ) $include_in_digest ,
996 ":always_display_enclosures" => ( int ) $always_display_enclosures ,
997 ":mark_unread_on_update" => ( int ) $mark_unread_on_update ,
998 ":feed_language" => $feed_language ,
1000 ":uid" => $_SESSION [ 'uid' ]]);
1002 if ( $reset_basic_info ) {
1003 RSSUtils
:: set_basic_feed_info ( $feed_id );
1006 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_SAVE_FEED
,
1007 "hook_prefs_save_feed" , $feed_id );
1010 $feed_data = array ();
1012 foreach ( array_keys ( $_POST ) as $k ) {
1013 if ( $k != "op" && $k != "method" && $k != "ids" ) {
1014 $feed_data [ $k ] = clean ( $_POST [ $k ]);
1018 $this -> pdo
-> beginTransaction ();
1020 $feed_ids_qmarks = arr_qmarks ( $feed_ids );
1022 foreach ( array_keys ( $feed_data ) as $k ) {
1028 $qpart = "title = " . $this -> pdo
-> quote ( $feed_title );
1032 $qpart = "feed_url = " . $this -> pdo
-> quote ( $feed_url );
1035 case "update_interval" :
1036 $qpart = "update_interval = " . $this -> pdo
-> quote ( $upd_intl );
1039 case "purge_interval" :
1040 $qpart = "purge_interval =" . $this -> pdo
-> quote ( $purge_intl );
1044 $qpart = "auth_login = " . $this -> pdo
-> quote ( $auth_login );
1048 $qpart = "auth_pass =" . $this -> pdo
-> quote ( $auth_pass ). ", auth_pass_encrypted = false" ;
1052 $qpart = "private = " . $this -> pdo
-> quote ( $private );
1055 case "include_in_digest" :
1056 $qpart = "include_in_digest = " . $this -> pdo
-> quote ( $include_in_digest );
1059 case "always_display_enclosures" :
1060 $qpart = "always_display_enclosures = " . $this -> pdo
-> quote ( $always_display_enclosures );
1063 case "mark_unread_on_update" :
1064 $qpart = "mark_unread_on_update = " . $this -> pdo
-> quote ( $mark_unread_on_update );
1067 case "cache_images" :
1068 $qpart = "cache_images = " . $this -> pdo
-> quote ( $cache_images );
1072 $qpart = "hide_images = " . $this -> pdo
-> quote ( $hide_images );
1076 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1078 $qpart = "cat_id = " . $this -> pdo
-> quote ( $cat_id );
1080 $qpart = 'cat_id = NULL' ;
1088 case "feed_language" :
1089 $qpart = "feed_language = " . $this -> pdo
-> quote ( $feed_language );
1095 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET $qpart WHERE id IN ( $feed_ids_qmarks )
1096 AND owner_uid = ?" );
1097 $sth -> execute ( array_merge ( $feed_ids , [ $_SESSION [ 'uid' ]]));
1101 $this -> pdo
-> commit ();
1108 $ids = explode ( "," , clean ( $_REQUEST [ "ids" ]));
1110 foreach ( $ids as $id ) {
1111 Pref_Feeds
:: remove_feed ( $id , $_SESSION [ "uid" ]);
1117 function removeCat () {
1118 $ids = explode ( "," , clean ( $_REQUEST [ "ids" ]));
1119 foreach ( $ids as $id ) {
1120 $this -> remove_feed_category ( $id , $_SESSION [ "uid" ]);
1125 $feed_cat = trim ( clean ( $_REQUEST [ "cat" ]));
1127 add_feed_category ( $feed_cat );
1132 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
1133 print "<div id= \" pref-feeds-feeds \" dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Feeds' ). " \" >" ;
1135 $sth = $this -> pdo
-> prepare ( "SELECT COUNT(id) AS num_errors
1136 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?" );
1137 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1139 if ( $row = $sth -> fetch ()) {
1140 $num_errors = $row [ "num_errors" ];
1145 if ( $num_errors > 0 ) {
1147 $error_button = "<button dojoType= \" dijit.form.Button \"
1148 onclick= \" showFeedsWithErrors() \" id= \" errorButton \" >" .
1149 __ ( "Feeds with errors" ) . "</button>" ;
1152 $inactive_button = "<button dojoType= \" dijit.form.Button \"
1153 id= \" pref_feeds_inactive_btn \"
1154 style= \" display : none \"
1155 onclick= \" showInactiveFeeds() \" >" .
1156 __ ( "Inactive feeds" ) . "</button>" ;
1158 $feed_search = clean ( $_REQUEST [ "search" ]);
1160 if ( array_key_exists ( "search" , $_REQUEST )) {
1161 $_SESSION [ "prefs_feed_search" ] = $feed_search ;
1163 $feed_search = $_SESSION [ "prefs_feed_search" ];
1166 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
1168 print "<div region='top' dojoType= \" dijit.Toolbar \" >" ; #toolbar
1170 print "<div style='float : right; padding-right : 4px;'>
1171 <input dojoType= \" dijit.form.TextBox \" id= \" feed_search \" size= \" 20 \" type= \" search \"
1172 value= \" $feed_search\" >
1173 <button dojoType= \" dijit.form.Button \" onclick= \" updateFeedList() \" >" .
1174 __ ( 'Search' ). "</button>
1177 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1178 "<span>" . __ ( 'Select' ). "</span>" ;
1179 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1180 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(true) \"
1181 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1182 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(false) \"
1183 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1184 print "</div></div>" ;
1186 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1187 "<span>" . __ ( 'Feeds' ). "</span>" ;
1188 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1189 print "<div onclick= \" quickAddFeed() \"
1190 dojoType= \" dijit.MenuItem \" >" . __ ( 'Subscribe to feed' ). "</div>" ;
1191 print "<div onclick= \" editSelectedFeed() \"
1192 dojoType= \" dijit.MenuItem \" >" . __ ( 'Edit selected feeds' ). "</div>" ;
1193 print "<div onclick= \" resetFeedOrder() \"
1194 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1195 print "<div onclick= \" batchSubscribe() \"
1196 dojoType= \" dijit.MenuItem \" >" . __ ( 'Batch subscribe' ). "</div>" ;
1197 print "<div dojoType= \" dijit.MenuItem \" onclick= \" removeSelectedFeeds() \" >"
1198 . __ ( 'Unsubscribe' ). "</div> " ;
1199 print "</div></div>" ;
1201 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1202 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1203 "<span>" . __ ( 'Categories' ). "</span>" ;
1204 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1205 print "<div onclick= \" createCategory() \"
1206 dojoType= \" dijit.MenuItem \" >" . __ ( 'Add category' ). "</div>" ;
1207 print "<div onclick= \" resetCatOrder() \"
1208 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1209 print "<div onclick= \" removeSelectedCategories() \"
1210 dojoType= \" dijit.MenuItem \" >" . __ ( 'Remove selected' ). "</div>" ;
1211 print "</div></div>" ;
1215 print $error_button ;
1216 print $inactive_button ;
1218 print "</div>" ; # toolbar
1221 print '<div dojoType="dijit.layout.ContentPane" region="center">' ;
1223 print "<div id= \" feedlistLoading \" >
1224 <img src='images/indicator_tiny.gif'>" .
1225 __ ( "Loading, please wait..." ). "</div>" ;
1227 print "<div dojoType= \" fox.PrefFeedStore \" jsId= \" feedStore \"
1228 url= \" backend.php?op=pref-feeds&method=getfeedtree \" >
1230 <div dojoType= \" lib.CheckBoxStoreModel \" jsId= \" feedModel \" store= \" feedStore \"
1231 query= \" {id:'root'} \" rootId= \" root \" rootLabel= \" Feeds \"
1232 childrenAttrs= \" items \" checkboxStrict= \" false \" checkboxAll= \" false \" >
1234 <div dojoType= \" fox.PrefFeedTree \" id= \" feedTree \"
1235 dndController= \" dijit.tree.dndSource \"
1236 betweenThreshold= \" 5 \"
1238 model= \" feedModel \" openOnClick= \" false \" >
1239 <script type= \" dojo/method \" event= \" onClick \" args= \" item \" >
1240 var id = String(item.id);
1241 var bare_id = id.substr(id.indexOf(':')+1);
1243 if (id.match('FEED:')) {
1245 } else if (id.match('CAT:')) {
1246 editCat(bare_id, item);
1249 <script type= \" dojo/method \" event= \" onLoad \" args= \" item \" >
1250 Element.hide( \" feedlistLoading \" );
1252 checkInactiveFeeds();
1256 # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1257 # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1263 print "</div>" ; # feeds pane
1265 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'OPML' ). " \" >" ;
1267 print "<p>" . __ ( "Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings." ) .
1268 __ ( "Only main settings profile can be migrated using OPML." ) . "</p>" ;
1270 print "<iframe id= \" upload_iframe \"
1271 name= \" upload_iframe \" onload= \" opmlImportComplete(this) \"
1272 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
1274 print "<form name= \" opml_form \" style='display : block' target= \" upload_iframe \"
1275 enctype= \" multipart/form-data \" method= \" POST \"
1276 action= \" backend.php \" >
1277 <label class= \" dijitButton \" >" . __ ( "Choose file..." ). "
1278 <input style= \" display : none \" id= \" opml_file \" name= \" opml_file \" type= \" file \" >
1280 <input type= \" hidden \" name= \" op \" value= \" dlg \" >
1281 <input type= \" hidden \" name= \" method \" value= \" importOpml \" >
1282 <button dojoType= \" dijit.form.Button \" onclick= \" return opmlImport(); \" type= \" submit \" >" .
1283 __ ( 'Import my OPML' ) . "</button>" ;
1287 $opml_export_filename = "TinyTinyRSS_" . date ( "Y-m-d" ). ".opml" ;
1289 print "<p>" . __ ( 'Filename:' ) .
1290 " <input class= \" input input-text \" type= \" text \" id= \" filename \" value= \" $opml_export_filename\" /> " .
1291 __ ( 'Include settings' ) . "<input type= \" checkbox \" id= \" settings \" checked= \" 1 \" />" ;
1293 print "</p><button dojoType= \" dijit.form.Button \"
1294 onclick= \" gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked) \" >" .
1295 __ ( 'Export OPML' ) . "</button></p></form>" ;
1299 print "<p>" . __ ( 'Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.' ) . "</p>" ;
1301 print_warning ( "Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds." );
1303 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "Public OPML URL" ). "','pubOPMLUrl') \" >" .
1304 __ ( 'Display published OPML URL' ). "</button> " ;
1306 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1307 "hook_prefs_tab_section" , "prefFeedsOPML" );
1309 print "</div>" ; # pane
1311 if ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], "Firefox" ) !== false ) {
1313 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Firefox integration' ). " \" >" ;
1315 print_notice ( __ ( 'This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.' ));
1319 print "<button onclick='window.navigator.registerContentHandler(" .
1320 " \" application/vnd.mozilla.maybe.feed \" , " .
1321 " \" " . $this -> subscribe_to_feed_url () . " \" , " . " \" Tiny Tiny RSS \" )'>" .
1322 __ ( 'Click here to register this site as a feed reader.' ) .
1327 print "</div>" ; # pane
1330 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Published & shared articles / Generated feeds' ). " \" >" ;
1332 print "<p>" . __ ( 'Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.' ) . "</p>" ;
1334 $rss_url = '-2::' . htmlspecialchars ( get_self_url_prefix () .
1335 "/public.php?op=rss&id=-2&view-mode=all_articles" );;
1339 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "View as RSS" ). "','generatedFeed', ' $rss_url ') \" >" .
1340 __ ( 'Display URL' ). "</button> " ;
1342 print "<button class= \" warning \" dojoType= \" dijit.form.Button \" onclick= \" return clearFeedAccessKeys() \" >" .
1343 __ ( 'Clear all generated URLs' ). "</button> " ;
1347 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1348 "hook_prefs_tab_section" , "prefFeedsPublishedGenerated" );
1350 print "</div>" ; #pane
1352 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
1353 "hook_prefs_tab" , "prefFeeds" );
1355 print "</div>" ; #container
1358 private function feedlist_init_cat ( $cat_id ) {
1360 $cat_id = ( int ) $cat_id ;
1363 $cat_unread = CCache
:: find ( $cat_id , $_SESSION [ "uid" ], true );
1364 } else if ( $cat_id == 0 ||
$cat_id == - 2 ) {
1365 $cat_unread = Feeds
:: getCategoryUnread ( $cat_id );
1368 $obj [ 'id' ] = 'CAT:' . $cat_id ;
1369 $obj [ 'items' ] = array ();
1370 $obj [ 'name' ] = Feeds
:: getCategoryTitle ( $cat_id );
1371 $obj [ 'type' ] = 'category' ;
1372 $obj [ 'unread' ] = ( int ) $cat_unread ;
1373 $obj [ 'bare_id' ] = $cat_id ;
1378 private function feedlist_init_feed ( $feed_id , $title = false , $unread = false , $error = '' , $updated = '' ) {
1380 $feed_id = ( int ) $feed_id ;
1383 $title = Feeds
:: getFeedTitle ( $feed_id , false );
1385 if ( $unread === false )
1386 $unread = getFeedUnread ( $feed_id , false );
1388 $obj [ 'id' ] = 'FEED:' . $feed_id ;
1389 $obj [ 'name' ] = $title ;
1390 $obj [ 'unread' ] = ( int ) $unread ;
1391 $obj [ 'type' ] = 'feed' ;
1392 $obj [ 'error' ] = $error ;
1393 $obj [ 'updated' ] = $updated ;
1394 $obj [ 'icon' ] = Feeds
:: getFeedIcon ( $feed_id );
1395 $obj [ 'bare_id' ] = $feed_id ;
1396 $obj [ 'auxcounter' ] = 0 ;
1401 function inactiveFeeds () {
1403 if ( DB_TYPE
== "pgsql" ) {
1404 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1406 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1409 $sth = $this -> pdo
-> prepare ( "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
1410 ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
1411 FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
1412 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1413 ttrss_entries.id = ref_id AND
1414 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
1415 AND ttrss_feeds.owner_uid = ? AND
1416 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1417 ttrss_entries.id = ref_id
1418 GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
1419 ORDER BY last_article" );
1420 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1422 print "<p" . __ ( "These feeds have not been updated with new content for 3 months (oldest first):" ) . "</p>" ;
1424 print "<div dojoType= \" dijit.Toolbar \" >" ;
1425 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1426 "<span>" . __ ( 'Select' ). "</span>" ;
1427 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1428 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'all') \"
1429 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1430 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'none') \"
1431 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1432 print "</div></div>" ;
1433 print "</div>" ; #toolbar
1435 print "<div class= \" inactiveFeedHolder \" >" ;
1437 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefInactiveFeedList \" >" ;
1441 while ( $line = $sth -> fetch ()) {
1443 $feed_id = $line [ "id" ];
1444 $this_row_id = "id= \" FUPDD- $feed_id\" " ;
1446 # class needed for selectTableRows()
1447 print "<tr class= \" placeholder \" $this_row_id >" ;
1449 # id needed for selectTableRows()
1450 print "<td width='5%' align='center'><input
1451 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1452 type= \" checkbox \" id= \" FUPDC- $feed_id\" ></td>" ;
1455 print "<a class= \" visibleLink \" href= \" # \" " .
1456 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1457 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1458 htmlspecialchars ( $line [ "title" ]). "</a>" ;
1460 print "</td><td class= \" insensitive \" align='right'>" ;
1461 print make_local_datetime ( $line [ 'last_article' ], false );
1471 print "<div class='dlgButtons'>" ;
1472 print "<div style='float : left'>" ;
1473 print "<button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').removeSelected() \" >"
1474 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1477 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').hide() \" >" .
1478 __ ( 'Close this window' ). "</button>" ;
1484 function feedsWithErrors () {
1485 $sth = $this -> pdo
-> prepare ( "SELECT id,title,feed_url,last_error,site_url
1486 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?" );
1487 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1489 print "<div dojoType= \" dijit.Toolbar \" >" ;
1490 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1491 "<span>" . __ ( 'Select' ). "</span>" ;
1492 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1493 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'all') \"
1494 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1495 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'none') \"
1496 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1497 print "</div></div>" ;
1498 print "</div>" ; #toolbar
1500 print "<div class= \" inactiveFeedHolder \" >" ;
1502 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefErrorFeedList \" >" ;
1506 while ( $line = $sth -> fetch ()) {
1508 $feed_id = $line [ "id" ];
1509 $this_row_id = "id= \" FERDD- $feed_id\" " ;
1511 # class needed for selectTableRows()
1512 print "<tr class= \" placeholder \" $this_row_id >" ;
1514 # id needed for selectTableRows()
1515 print "<td width='5%' align='center'><input
1516 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1517 type= \" checkbox \" id= \" FERDC- $feed_id\" ></td>" ;
1520 print "<a class= \" visibleLink \" href= \" # \" " .
1521 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1522 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1523 htmlspecialchars ( $line [ "title" ]). "</a>: " ;
1525 print "<span class= \" insensitive \" >" ;
1526 print htmlspecialchars ( $line [ "last_error" ]);
1538 print "<div class='dlgButtons'>" ;
1539 print "<div style='float : left'>" ;
1540 print "<button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').removeSelected() \" >"
1541 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1544 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').hide() \" >" .
1545 __ ( 'Close this window' ). "</button>" ;
1550 private function remove_feed_category ( $id , $owner_uid ) {
1552 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_feed_categories
1553 WHERE id = ? AND owner_uid = ?" );
1554 $sth -> execute ([ $id , $owner_uid ]);
1556 CCache
:: remove ( $id , $owner_uid , true );
1559 static function remove_feed ( $id , $owner_uid ) {
1560 $debug = isset ( $_REQUEST [ "debug" ]);
1562 foreach ( PluginHost
:: getInstance ()-> get_hooks ( PluginHost
:: HOOK_UNSUBSCRIBE_FEED
) as $p ) {
1563 if ( ! $p -> hook_unsubscribe_feed ( $id , $owner_uid )){
1564 if ( $debug ) _debug ( "Feed not removed due to Error in Plugin. (HOOK_UNSUBSCRIBE_FEED)" );
1572 $pdo -> beginTransaction ();
1574 /* save starred articles in Archived feed */
1576 /* prepare feed if necessary */
1578 $sth = $pdo -> prepare ( "SELECT feed_url FROM ttrss_feeds WHERE id = ?
1579 AND owner_uid = ?" );
1580 $sth -> execute ([ $id , $owner_uid ]);
1582 if ( $row = $sth -> fetch ()) {
1583 $feed_url = $row [ "feed_url" ];
1585 $sth = $pdo -> prepare ( "SELECT id FROM ttrss_archived_feeds
1586 WHERE feed_url = ? AND owner_uid = ?" );
1587 $sth -> execute ([ $feed_url , $owner_uid ]);
1589 if ( $row = $sth -> fetch ()) {
1590 $archive_id = $row [ "id" ];
1592 $res = $pdo -> query ( "SELECT MAX(id) AS id FROM ttrss_archived_feeds" );
1593 $row = $res -> fetch ();
1595 $new_feed_id = ( int ) $row [ 'id' ] +
1 ;
1597 $sth = $pdo -> prepare ( "INSERT INTO ttrss_archived_feeds
1598 (id, owner_uid, title, feed_url, site_url)
1599 SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds
1601 $sth -> execute ([ $new_feed_id , $id ]);
1603 $archive_id = $new_feed_id ;
1606 $sth = $pdo -> prepare ( "UPDATE ttrss_user_entries SET feed_id = NULL,
1607 orig_feed_id = ? WHERE feed_id = ? AND
1608 marked = true AND owner_uid = ?" );
1610 $sth -> execute ([ $archive_id , $id , $owner_uid ]);
1612 /* Remove access key for the feed */
1614 $sth = $pdo -> prepare ( "DELETE FROM ttrss_access_keys WHERE
1615 feed_id = ? AND owner_uid = ?" );
1616 $sth -> execute ([ $id , $owner_uid ]);
1618 /* remove the feed */
1620 $sth = $pdo -> prepare ( "DELETE FROM ttrss_feeds
1621 WHERE id = ? AND owner_uid = ?" );
1622 $sth -> execute ([ $id , $owner_uid ]);
1627 if ( file_exists ( ICONS_DIR
. "/ $id .ico" )) {
1628 unlink ( ICONS_DIR
. "/ $id .ico" );
1631 CCache
:: remove ( $id , $owner_uid );
1634 Labels
:: remove ( Labels
:: feed_to_label_id ( $id ), $owner_uid );
1635 //CCache::remove($id, $owner_uid); don't think labels are cached
1639 function batchSubscribe () {
1640 print_hidden ( "op" , "pref-feeds" );
1641 print_hidden ( "method" , "batchaddfeeds" );
1643 print "<table width='100%'><tr><td>
1644 " . __ ( "Add one valid RSS feed per line (no feed detection is done)" ). "
1645 </td><td align='right'>" ;
1646 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1647 print __ ( 'Place in category:' ) . " " ;
1648 print_feed_cat_select ( "cat" , false , 'dojoType="dijit.form.Select"' );
1650 print "</td></tr><tr><td colspan='2'>" ;
1652 style='font-size : 12px; width : 98%; height: 200px;'
1653 placeHolder= \" " . __ ( "Feeds to subscribe, One per line" ). " \"
1654 dojoType= \" dijit.form.SimpleTextarea \" required= \" 1 \" name= \" feeds \" ></textarea>" ;
1656 print "</td></tr><tr><td colspan='2'>" ;
1658 print "<div id='feedDlg_loginContainer' style='display : none'>
1660 " <input dojoType= \" dijit.form.TextBox \" name='login' \"
1661 placeHolder= \" " . __ ( "Login" ). " \"
1662 style= \" width : 10em; \" > " .
1664 placeHolder= \" " . __ ( "Password" ). " \"
1665 dojoType= \" dijit.form.TextBox \" type='password'
1666 autocomplete= \" new-password \"
1667 style= \" width : 10em; \" name='pass' \" >" .
1670 print "</td></tr><tr><td colspan='2'>" ;
1672 print "<div style= \" clear : both \" >
1673 <input type= \" checkbox \" name= \" need_auth \" dojoType= \" dijit.form.CheckBox \" id= \" feedDlg_loginCheck \"
1674 onclick='checkboxToggleElement(this, \" feedDlg_loginContainer \" )'>
1675 <label for= \" feedDlg_loginCheck \" >" .
1676 __ ( 'Feeds require authentication.' ). "</div>" ;
1680 print "</td></tr></table>" ;
1682 print "<div class= \" dlgButtons \" >
1683 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').execute() \" >" . __ ( 'Subscribe' ). "</button>
1684 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
1688 function batchAddFeeds () {
1689 $cat_id = clean ( $_REQUEST [ 'cat' ]);
1690 $feeds = explode ( " \n " , clean ( $_REQUEST [ 'feeds' ]));
1691 $login = clean ( $_REQUEST [ 'login' ]);
1692 $pass = trim ( clean ( $_REQUEST [ 'pass' ]));
1694 foreach ( $feeds as $feed ) {
1695 $feed = trim ( $feed );
1697 if ( validate_feed_url ( $feed )) {
1699 $this -> pdo
-> beginTransaction ();
1701 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
1702 WHERE feed_url = ? AND owner_uid = ?" );
1703 $sth -> execute ([ $feed , $_SESSION [ 'uid' ]]);
1705 if (! $sth -> fetch ()) {
1706 $sth = $this -> pdo
-> prepare ( "INSERT INTO ttrss_feeds
1707 (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
1708 VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)" );
1710 $sth -> execute ([ $_SESSION [ 'uid' ], $feed , $cat_id ?
$cat_id : null , $login , $pass ]);
1713 $this -> pdo
-> commit ();
1718 function regenOPMLKey () {
1719 $this -> update_feed_access_key ( 'OPML:Publish' ,
1720 false , $_SESSION [ "uid" ]);
1722 $new_link = Opml
:: opml_publish_url ();
1724 print json_encode ( array ( "link" => $new_link ));
1727 function regenFeedKey () {
1728 $feed_id = clean ( $_REQUEST [ 'id' ]);
1729 $is_cat = clean ( $_REQUEST [ 'is_cat' ]) == "true" ;
1731 $new_key = $this -> update_feed_access_key ( $feed_id , $is_cat );
1733 print json_encode ( array ( "link" => $new_key ));
1737 private function update_feed_access_key ( $feed_id , $is_cat , $owner_uid = false ) {
1738 if (! $owner_uid ) $owner_uid = $_SESSION [ "uid" ];
1740 // clear old value and generate new one
1741 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_access_keys
1742 WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?" );
1743 $sth -> execute ([ $feed_id , $is_cat , $owner_uid ]);
1745 return get_feed_access_key ( $feed_id , $is_cat , $owner_uid );
1749 function clearKeys () {
1750 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_access_keys WHERE
1752 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1755 private function calculate_children_count ( $cat ) {
1758 foreach ( $cat [ 'items' ] as $child ) {
1759 if ( $child [ 'type' ] == 'category' ) {
1760 $c +
= $this -> calculate_children_count ( $child );
1769 function getinactivefeeds () {
1770 if ( DB_TYPE
== "pgsql" ) {
1771 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1773 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1776 $sth = $this -> pdo
-> prepare ( "SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE
1777 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1778 ttrss_entries.id = ref_id AND
1779 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1780 ttrss_feeds.owner_uid = ?" );
1781 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1783 if ( $row = $sth -> fetch ()) {
1784 print ( int ) $row [ "num_inactive" ];
1788 static function subscribe_to_feed_url () {
1789 $url_path = get_self_url_prefix () .
1790 "/public.php?op=subscribe&feed_url= %s " ;