]>
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 ) {
333 for ( $i = 0 ; $i < $nest_level ; $i ++
)
336 Debug
:: log ( " $prefix C: $item_id P: $parent_id " );
338 $bare_item_id = substr ( $item_id , strpos ( $item_id , ':' ) +
1 );
340 if ( $item_id != 'root' ) {
341 if ( $parent_id && $parent_id != 'root' ) {
342 $parent_bare_id = substr ( $parent_id , strpos ( $parent_id , ':' ) +
1 );
343 $parent_qpart = $parent_bare_id ;
345 $parent_qpart = null ;
348 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories
349 SET parent_cat = ? WHERE id = ? AND
351 $sth -> execute ([ $parent_qpart , $bare_item_id , $_SESSION [ 'uid' ]]);
356 $cat = $data_map [ $item_id ];
358 if ( $cat && is_array ( $cat )) {
359 foreach ( $cat as $item ) {
360 $id = $item [ '_reference' ];
361 $bare_id = substr ( $id , strpos ( $id , ':' ) +
1 );
363 Debug
:: log ( " $prefix [ $order_id ] $id / $bare_id " );
365 if ( $item [ '_reference' ]) {
367 if ( strpos ( $id , "FEED" ) === 0 ) {
369 $cat_id = ( $item_id != "root" ) ?
$bare_item_id : null ;
371 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds
372 SET order_id = ?, cat_id = ?
373 WHERE id = ? AND owner_uid = ?" );
375 $sth -> execute ([ $order_id , $cat_id ?
$cat_id : null , $bare_id , $_SESSION [ 'uid' ]]);
377 } else if ( strpos ( $id , "CAT:" ) === 0 ) {
378 $this -> process_category_order ( $data_map , $item [ '_reference' ], $item_id ,
381 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feed_categories
382 SET order_id = ? WHERE id = ? AND
384 $sth -> execute ([ $order_id , $bare_id , $_SESSION [ 'uid' ]]);
393 function savefeedorder () {
394 $data = json_decode ( $_POST [ 'payload' ], true );
396 #file_put_contents("/tmp/saveorder.json", clean($_POST['payload']));
397 #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
399 if (! is_array ( $data [ 'items' ]))
400 $data [ 'items' ] = json_decode ( $data [ 'items' ], true );
402 # print_r($data['items']);
404 if ( is_array ( $data ) && is_array ( $data [ 'items' ])) {
410 foreach ( $data [ 'items' ] as $item ) {
412 # if ($item['id'] != 'root') {
413 if ( is_array ( $item [ 'items' ])) {
414 if ( isset ( $item [ 'items' ][ '_reference' ])) {
415 $data_map [ $item [ 'id' ]] = array ( $item [ 'items' ]);
417 $data_map [ $item [ 'id' ]] = $item [ 'items' ];
420 if ( $item [ 'id' ] == 'root' ) {
421 $root_item = $item [ 'id' ];
425 $this -> process_category_order ( $data_map , $root_item );
429 function removeicon () {
430 $feed_id = clean ( $_REQUEST [ "feed_id" ]);
432 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
433 WHERE id = ? AND owner_uid = ?" );
434 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
436 if ( $row = $sth -> fetch ()) {
437 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
439 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET favicon_avg_color = NULL
441 $sth -> execute ([ $feed_id ]);
445 function uploadicon () {
446 header ( "Content-type: text/html" );
448 if ( is_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ])) {
449 $tmp_file = tempnam ( CACHE_DIR
. '/upload' , 'icon' );
451 $result = move_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ],
461 $icon_file = $tmp_file ;
462 $feed_id = clean ( $_REQUEST [ "feed_id" ]);
464 if ( is_file ( $icon_file ) && $feed_id ) {
465 if ( filesize ( $icon_file ) < 65535 ) {
467 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
468 WHERE id = ? AND owner_uid = ?" );
469 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
471 if ( $row = $sth -> fetch ()) {
472 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
473 if ( rename ( $icon_file , ICONS_DIR
. "/ $feed_id .ico" )) {
475 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET
476 favicon_avg_color = ''
478 $sth -> execute ([ $feed_id ]);
494 print "<script type= \" text/javascript \" >" ;
495 print "parent.uploadIconHandler( $rc );" ;
500 function editfeed () {
501 global $purge_intervals ;
502 global $update_intervals ;
505 $feed_id = clean ( $_REQUEST [ "id" ]);
507 $sth = $this -> pdo
-> prepare ( "SELECT * FROM ttrss_feeds WHERE id = ? AND
509 $sth -> execute ([ $feed_id , $_SESSION [ 'uid' ]]);
511 if ( $row = $sth -> fetch ()) {
512 print '<div dojoType="dijit.layout.TabContainer" style="height : 450px">
513 <div dojoType="dijit.layout.ContentPane" title="' . __ ( 'General' ). '">' ;
515 $title = htmlspecialchars ( $row [ "title" ]);
517 print_hidden ( "id" , " $feed_id " );
518 print_hidden ( "op" , "pref-feeds" );
519 print_hidden ( "method" , "editSave" );
521 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
522 print "<div class= \" dlgSecCont \" >" ;
526 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
527 placeHolder= \" " . __ ( "Feed Title" ). " \"
528 style= \" font-size : 16px; width: 20em \" name= \" title \" value= \" $title\" >" ;
532 $feed_url = htmlspecialchars ( $row [ "feed_url" ]);
536 print __ ( 'URL:' ) . " " ;
537 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
538 placeHolder= \" " . __ ( "Feed URL" ). " \"
539 regExp='^(http|https)://.*' style= \" width : 20em \"
540 name= \" feed_url \" value= \" $feed_url\" >" ;
542 $last_error = $row [ "last_error" ];
545 print " <img src= \" images/error.png \" alt= \" (error) \"
546 style= \" vertical-align : middle \"
547 title= \" " . htmlspecialchars ( $last_error ). " \" >" ;
553 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
555 $cat_id = $row [ "cat_id" ];
559 print __ ( 'Place in category:' ) . " " ;
561 print_feed_cat_select ( "cat_id" , $cat_id ,
562 'dojoType="dijit.form.Select"' );
567 $site_url = htmlspecialchars ( $row [ "site_url" ]);
571 print __ ( 'Site URL:' ) . " " ;
572 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
573 placeHolder= \" " . __ ( "Site URL" ). " \"
574 regExp='^(http|https)://.*' style= \" width : 15em \"
575 name= \" site_url \" value= \" $site_url\" >" ;
577 /* FTS Stemming Language */
579 if ( DB_TYPE
== "pgsql" ) {
580 $feed_language = $row [ "feed_language" ];
584 print __ ( 'Language:' ) . " " ;
585 print_select ( "feed_language" , $feed_language , $this :: $feed_languages ,
586 'dojoType="dijit.form.Select"' );
591 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
592 print "<div class= \" dlgSecCont \" >" ;
594 /* Update Interval */
596 $update_interval = $row [ "update_interval" ];
598 print_select_hash ( "update_interval" , $update_interval , $update_intervals ,
599 'dojoType="dijit.form.Select"' );
603 $purge_interval = $row [ "purge_interval" ];
606 print __ ( 'Article purging:' ) . " " ;
608 print_select_hash ( "purge_interval" , $purge_interval , $purge_intervals ,
609 'dojoType="dijit.form.Select" ' .
610 (( FORCE_ARTICLE_PURGE
== 0 ) ?
"" : 'disabled="1"' ));
614 $auth_login = htmlspecialchars ( $row [ "auth_login" ]);
615 $auth_pass = htmlspecialchars ( $row [ "auth_pass" ]);
617 $auth_enabled = $auth_login !== '' ||
$auth_pass !== '' ;
619 $auth_style = $auth_enabled ?
'' : 'display: none' ;
620 print "<div id='feedEditDlg_loginContainer' style=' $auth_style '>" ;
621 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
622 print "<div class= \" dlgSecCont \" >" ;
624 print "<input dojoType= \" dijit.form.TextBox \" id= \" feedEditDlg_login \"
625 placeHolder= \" " . __ ( "Login" ). " \"
626 autocomplete= \" new-password \"
627 name= \" auth_login \" value= \" $auth_login\" ><hr/>" ;
629 print "<input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
630 autocomplete= \" new-password \"
631 placeHolder= \" " . __ ( "Password" ). " \"
632 value= \" $auth_pass\" >" ;
634 print "<div dojoType= \" dijit.Tooltip \" connectId= \" feedEditDlg_login \" position= \" below \" >
635 " . __ ( '<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.' ). "
638 print "</div></div>" ;
640 $auth_checked = $auth_enabled ?
'checked' : '' ;
641 print "<div style= \" clear : both \" >
642 <input type= \" checkbox \" $auth_checked name= \" need_auth \" dojoType= \" dijit.form.CheckBox \" id= \" feedEditDlg_loginCheck \"
643 onclick='checkboxToggleElement(this, \" feedEditDlg_loginContainer \" )'>
644 <label for= \" feedEditDlg_loginCheck \" >" .
645 __ ( 'This feed requires authentication.' ). "</div>" ;
647 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Options' ). '">' ;
649 //print "<div class=\"dlgSec\">".__("Options")."</div>";
650 print "<div class= \" dlgSecSimple \" >" ;
652 $private = $row [ "private" ];
655 $checked = "checked= \" 1 \" " ;
660 print "<input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" name= \" private \" id= \" private \"
661 $checked > <label for= \" private \" >" . __ ( 'Hide from Popular feeds' ). "</label>" ;
663 if ( DIGEST_SUBJECT
!== false ) {
664 $include_in_digest = $row [ "include_in_digest" ];
666 if ( $include_in_digest ) {
667 $checked = "checked= \" 1 \" " ;
672 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" include_in_digest \"
673 name= \" include_in_digest \"
674 $checked > <label for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
678 $always_display_enclosures = $row [ "always_display_enclosures" ];
680 if ( $always_display_enclosures ) {
681 $checked = "checked" ;
686 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" always_display_enclosures \"
687 name= \" always_display_enclosures \"
688 $checked > <label for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
690 $hide_images = $row [ "hide_images" ];
693 $checked = "checked= \" 1 \" " ;
698 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" hide_images \"
700 $checked > <label for= \" hide_images \" >" .
701 __ ( 'Do not embed media' ). "</label>" ;
703 $cache_images = $row [ "cache_images" ];
706 $checked = "checked= \" 1 \" " ;
711 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" cache_images \"
712 name= \" cache_images \"
713 $checked > <label for= \" cache_images \" >" .
714 __ ( 'Cache media' ). "</label>" ;
716 $mark_unread_on_update = $row [ "mark_unread_on_update" ];
718 if ( $mark_unread_on_update ) {
719 $checked = "checked" ;
724 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" mark_unread_on_update \"
725 name= \" mark_unread_on_update \"
726 $checked > <label for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
730 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Icon' ). '">' ;
734 print "<div class= \" dlgSecSimple \" >" ;
736 print "<img class= \" feedIcon \" src= \" " . Feeds
:: getFeedIcon ( $feed_id ). " \" >" ;
738 print "<iframe name= \" icon_upload_iframe \"
739 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
741 print "<form style='display : block' target= \" icon_upload_iframe \"
742 enctype= \" multipart/form-data \" method= \" POST \"
743 action= \" backend.php \" >
744 <label class= \" dijitButton \" >" . __ ( "Choose file..." ). "
745 <input style= \" display: none \" id= \" icon_file \" size= \" 10 \" name= \" icon_file \" type= \" file \" >
747 <input type= \" hidden \" name= \" op \" value= \" pref-feeds \" >
748 <input type= \" hidden \" name= \" feed_id \" value= \" $feed_id\" >
749 <input type= \" hidden \" name= \" method \" value= \" uploadicon \" >
750 <button class= \"\" dojoType= \" dijit.form.Button \" onclick= \" return uploadFeedIcon(); \"
751 type= \" submit \" >" . __ ( 'Replace' ). "</button>
752 <button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" return removeFeedIcon( $feed_id ); \"
753 type= \" submit \" >" . __ ( 'Remove' ). "</button>
758 print '</div><div dojoType="dijit.layout.ContentPane" title="' . __ ( 'Plugins' ). '">' ;
760 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_EDIT_FEED
,
761 "hook_prefs_edit_feed" , $feed_id );
764 print "</div></div>" ;
766 $title = htmlspecialchars ( $title , ENT_QUOTES
);
768 print "<div class='dlgButtons'>
769 <div style= \" float : left \" >
770 <button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick='return unsubscribeFeed( $feed_id , \" $title\" )'>" .
771 __ ( 'Unsubscribe' ). "</button>" ;
775 print "<button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').execute() \" >" . __ ( 'Save' ). "</button>
776 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
781 function editfeeds () {
782 global $purge_intervals ;
783 global $update_intervals ;
785 $feed_ids = clean ( $_REQUEST [ "ids" ]);
787 print_notice ( "Enable the options you wish to apply using checkboxes on the right:" );
791 print_hidden ( "ids" , " $feed_ids " );
792 print_hidden ( "op" , "pref-feeds" );
793 print_hidden ( "method" , "batchEditSave" );
795 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
796 print "<div class= \" dlgSecCont \" >" ;
800 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
802 print __ ( 'Place in category:' ) . " " ;
804 print_feed_cat_select ( "cat_id" , false ,
805 'disabled="1" dojoType="dijit.form.Select"' );
807 $this -> batch_edit_cbox ( "cat_id" );
811 /* FTS Stemming Language */
813 if ( DB_TYPE
== "pgsql" ) {
816 print __ ( 'Language:' ) . " " ;
817 print_select ( "feed_language" , "" , $this :: $feed_languages ,
818 'disabled="1" dojoType="dijit.form.Select"' );
820 $this -> batch_edit_cbox ( "feed_language" );
825 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
826 print "<div class= \" dlgSecCont \" >" ;
828 /* Update Interval */
830 print_select_hash ( "update_interval" , "" , $update_intervals ,
831 'disabled="1" dojoType="dijit.form.Select"' );
833 $this -> batch_edit_cbox ( "update_interval" );
837 if ( FORCE_ARTICLE_PURGE
== 0 ) {
841 print __ ( 'Article purging:' ) . " " ;
843 print_select_hash ( "purge_interval" , "" , $purge_intervals ,
844 'disabled="1" dojoType="dijit.form.Select"' );
846 $this -> batch_edit_cbox ( "purge_interval" );
850 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
851 print "<div class= \" dlgSecCont \" >" ;
853 print "<input dojoType= \" dijit.form.TextBox \"
854 placeHolder= \" " . __ ( "Login" ). " \" disabled= \" 1 \"
855 autocomplete= \" new-password \"
856 name= \" auth_login \" value= \"\" >" ;
858 $this -> batch_edit_cbox ( "auth_login" );
860 print "<hr/> <input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
861 autocomplete= \" new-password \"
862 placeHolder= \" " . __ ( "Password" ). " \" disabled= \" 1 \"
865 $this -> batch_edit_cbox ( "auth_pass" );
868 print "<div class= \" dlgSec \" >" . __ ( "Options" ). "</div>" ;
869 print "<div class= \" dlgSecCont \" >" ;
871 print "<input disabled= \" 1 \" type= \" checkbox \" name= \" private \" id= \" private \"
872 dojoType= \" dijit.form.CheckBox \" > <label id= \" private_l \" class='insensitive' for= \" private \" >" . __ ( 'Hide from Popular feeds' ). "</label>" ;
874 print " " ; $this -> batch_edit_cbox ( "private" , "private_l" );
876 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" include_in_digest \"
877 name= \" include_in_digest \"
878 dojoType= \" dijit.form.CheckBox \" > <label id= \" include_in_digest_l \" class='insensitive' for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
880 print " " ; $this -> batch_edit_cbox ( "include_in_digest" , "include_in_digest_l" );
882 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" always_display_enclosures \"
883 name= \" always_display_enclosures \"
884 dojoType= \" dijit.form.CheckBox \" > <label id= \" always_display_enclosures_l \" class='insensitive' for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
886 print " " ; $this -> batch_edit_cbox ( "always_display_enclosures" , "always_display_enclosures_l" );
888 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" hide_images \"
890 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" hide_images_l \"
891 for= \" hide_images \" >" .
892 __ ( 'Do not embed media' ). "</label>" ;
894 print " " ; $this -> batch_edit_cbox ( "hide_images" , "hide_images_l" );
896 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" cache_images \"
897 name= \" cache_images \"
898 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" cache_images_l \"
899 for= \" cache_images \" >" .
900 __ ( 'Cache media' ). "</label>" ;
902 print " " ; $this -> batch_edit_cbox ( "cache_images" , "cache_images_l" );
904 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" mark_unread_on_update \"
905 name= \" mark_unread_on_update \"
906 dojoType= \" dijit.form.CheckBox \" > <label id= \" mark_unread_on_update_l \" class='insensitive' for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
908 print " " ; $this -> batch_edit_cbox ( "mark_unread_on_update" , "mark_unread_on_update_l" );
912 print "<div class='dlgButtons'>
913 <button dojoType= \" dijit.form.Button \"
914 onclick= \" return dijit.byId('feedEditDlg').execute() \" >" .
915 __ ( 'Save' ). "</button>
916 <button dojoType= \" dijit.form.Button \"
917 onclick= \" return dijit.byId('feedEditDlg').hide() \" >" .
918 __ ( 'Cancel' ). "</button>
924 function batchEditSave () {
925 return $this -> editsaveops ( true );
928 function editSave () {
929 return $this -> editsaveops ( false );
932 function editsaveops ( $batch ) {
934 $feed_title = trim ( clean ( $_POST [ "title" ]));
935 $feed_url = trim ( clean ( $_POST [ "feed_url" ]));
936 $site_url = trim ( clean ( $_POST [ "site_url" ]));
937 $upd_intl = ( int ) clean ( $_POST [ "update_interval" ]);
938 $purge_intl = ( int ) clean ( $_POST [ "purge_interval" ]);
939 $feed_id = ( int ) clean ( $_POST [ "id" ]); /* editSave */
940 $feed_ids = explode ( "," , clean ( $_POST [ "ids" ])); /* batchEditSave */
941 $cat_id = ( int ) clean ( $_POST [ "cat_id" ]);
942 $auth_login = trim ( clean ( $_POST [ "auth_login" ]));
943 $auth_pass = trim ( clean ( $_POST [ "auth_pass" ]));
944 $private = checkbox_to_sql_bool ( clean ( $_POST [ "private" ]));
945 $include_in_digest = checkbox_to_sql_bool (
946 clean ( $_POST [ "include_in_digest" ]));
947 $cache_images = checkbox_to_sql_bool (
948 clean ( $_POST [ "cache_images" ]));
949 $hide_images = checkbox_to_sql_bool (
950 clean ( $_POST [ "hide_images" ]));
951 $always_display_enclosures = checkbox_to_sql_bool (
952 clean ( $_POST [ "always_display_enclosures" ]));
954 $mark_unread_on_update = checkbox_to_sql_bool (
955 clean ( $_POST [ "mark_unread_on_update" ]));
957 $feed_language = trim ( clean ( $_POST [ "feed_language" ]));
960 if ( clean ( $_POST [ "need_auth" ]) !== 'on' ) {
965 /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?");
966 $sth->execute([$feed_id]);
967 $row = $sth->fetch();$orig_feed_url = $row["feed_url"];
969 $reset_basic_info = $orig_feed_url != $feed_url; */
971 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET
974 feed_url = :feed_url,
975 site_url = :site_url,
976 update_interval = :upd_intl,
977 purge_interval = :purge_intl,
978 auth_login = :auth_login,
979 auth_pass = :auth_pass,
980 auth_pass_encrypted = false,
982 cache_images = :cache_images,
983 hide_images = :hide_images,
984 include_in_digest = :include_in_digest,
985 always_display_enclosures = :always_display_enclosures,
986 mark_unread_on_update = :mark_unread_on_update,
987 feed_language = :feed_language
988 WHERE id = :id AND owner_uid = :uid" );
990 $sth -> execute ([ ":title" => $feed_title ,
991 ":cat_id" => $cat_id ?
$cat_id : null ,
992 ":feed_url" => $feed_url ,
993 ":site_url" => $site_url ,
994 ":upd_intl" => $upd_intl ,
995 ":purge_intl" => $purge_intl ,
996 ":auth_login" => $auth_login ,
997 ":auth_pass" => $auth_pass ,
998 ":private" => ( int ) $private ,
999 ":cache_images" => ( int ) $cache_images ,
1000 ":hide_images" => ( int ) $hide_images ,
1001 ":include_in_digest" => ( int ) $include_in_digest ,
1002 ":always_display_enclosures" => ( int ) $always_display_enclosures ,
1003 ":mark_unread_on_update" => ( int ) $mark_unread_on_update ,
1004 ":feed_language" => $feed_language ,
1006 ":uid" => $_SESSION [ 'uid' ]]);
1008 /* if ($reset_basic_info) {
1009 RSSUtils::set_basic_feed_info($feed_id);
1012 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_SAVE_FEED
,
1013 "hook_prefs_save_feed" , $feed_id );
1016 $feed_data = array ();
1018 foreach ( array_keys ( $_POST ) as $k ) {
1019 if ( $k != "op" && $k != "method" && $k != "ids" ) {
1020 $feed_data [ $k ] = clean ( $_POST [ $k ]);
1024 $this -> pdo
-> beginTransaction ();
1026 $feed_ids_qmarks = arr_qmarks ( $feed_ids );
1028 foreach ( array_keys ( $feed_data ) as $k ) {
1034 $qpart = "title = " . $this -> pdo
-> quote ( $feed_title );
1038 $qpart = "feed_url = " . $this -> pdo
-> quote ( $feed_url );
1041 case "update_interval" :
1042 $qpart = "update_interval = " . $this -> pdo
-> quote ( $upd_intl );
1045 case "purge_interval" :
1046 $qpart = "purge_interval =" . $this -> pdo
-> quote ( $purge_intl );
1050 $qpart = "auth_login = " . $this -> pdo
-> quote ( $auth_login );
1054 $qpart = "auth_pass =" . $this -> pdo
-> quote ( $auth_pass ). ", auth_pass_encrypted = false" ;
1058 $qpart = "private = " . $this -> pdo
-> quote ( $private );
1061 case "include_in_digest" :
1062 $qpart = "include_in_digest = " . $this -> pdo
-> quote ( $include_in_digest );
1065 case "always_display_enclosures" :
1066 $qpart = "always_display_enclosures = " . $this -> pdo
-> quote ( $always_display_enclosures );
1069 case "mark_unread_on_update" :
1070 $qpart = "mark_unread_on_update = " . $this -> pdo
-> quote ( $mark_unread_on_update );
1073 case "cache_images" :
1074 $qpart = "cache_images = " . $this -> pdo
-> quote ( $cache_images );
1078 $qpart = "hide_images = " . $this -> pdo
-> quote ( $hide_images );
1082 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1084 $qpart = "cat_id = " . $this -> pdo
-> quote ( $cat_id );
1086 $qpart = 'cat_id = NULL' ;
1094 case "feed_language" :
1095 $qpart = "feed_language = " . $this -> pdo
-> quote ( $feed_language );
1101 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_feeds SET $qpart WHERE id IN ( $feed_ids_qmarks )
1102 AND owner_uid = ?" );
1103 $sth -> execute ( array_merge ( $feed_ids , [ $_SESSION [ 'uid' ]]));
1107 $this -> pdo
-> commit ();
1114 $ids = explode ( "," , clean ( $_REQUEST [ "ids" ]));
1116 foreach ( $ids as $id ) {
1117 Pref_Feeds
:: remove_feed ( $id , $_SESSION [ "uid" ]);
1123 function removeCat () {
1124 $ids = explode ( "," , clean ( $_REQUEST [ "ids" ]));
1125 foreach ( $ids as $id ) {
1126 $this -> remove_feed_category ( $id , $_SESSION [ "uid" ]);
1131 $feed_cat = trim ( clean ( $_REQUEST [ "cat" ]));
1133 add_feed_category ( $feed_cat );
1138 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
1139 print "<div id= \" pref-feeds-feeds \" dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Feeds' ). " \" >" ;
1141 $sth = $this -> pdo
-> prepare ( "SELECT COUNT(id) AS num_errors
1142 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?" );
1143 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1145 if ( $row = $sth -> fetch ()) {
1146 $num_errors = $row [ "num_errors" ];
1151 if ( $num_errors > 0 ) {
1153 $error_button = "<button dojoType= \" dijit.form.Button \"
1154 onclick= \" showFeedsWithErrors() \" id= \" errorButton \" >" .
1155 __ ( "Feeds with errors" ) . "</button>" ;
1158 $inactive_button = "<button dojoType= \" dijit.form.Button \"
1159 id= \" pref_feeds_inactive_btn \"
1160 style= \" display : none \"
1161 onclick= \" showInactiveFeeds() \" >" .
1162 __ ( "Inactive feeds" ) . "</button>" ;
1164 $feed_search = clean ( $_REQUEST [ "search" ]);
1166 if ( array_key_exists ( "search" , $_REQUEST )) {
1167 $_SESSION [ "prefs_feed_search" ] = $feed_search ;
1169 $feed_search = $_SESSION [ "prefs_feed_search" ];
1172 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
1174 print "<div region='top' dojoType= \" dijit.Toolbar \" >" ; #toolbar
1176 print "<div style='float : right; padding-right : 4px;'>
1177 <input dojoType= \" dijit.form.TextBox \" id= \" feed_search \" size= \" 20 \" type= \" search \"
1178 value= \" $feed_search\" >
1179 <button dojoType= \" dijit.form.Button \" onclick= \" updateFeedList() \" >" .
1180 __ ( 'Search' ). "</button>
1183 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1184 "<span>" . __ ( 'Select' ). "</span>" ;
1185 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1186 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(true) \"
1187 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1188 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(false) \"
1189 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1190 print "</div></div>" ;
1192 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1193 "<span>" . __ ( 'Feeds' ). "</span>" ;
1194 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1195 print "<div onclick= \" quickAddFeed() \"
1196 dojoType= \" dijit.MenuItem \" >" . __ ( 'Subscribe to feed' ). "</div>" ;
1197 print "<div onclick= \" editSelectedFeed() \"
1198 dojoType= \" dijit.MenuItem \" >" . __ ( 'Edit selected feeds' ). "</div>" ;
1199 print "<div onclick= \" resetFeedOrder() \"
1200 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1201 print "<div onclick= \" batchSubscribe() \"
1202 dojoType= \" dijit.MenuItem \" >" . __ ( 'Batch subscribe' ). "</div>" ;
1203 print "<div dojoType= \" dijit.MenuItem \" onclick= \" removeSelectedFeeds() \" >"
1204 . __ ( 'Unsubscribe' ). "</div> " ;
1205 print "</div></div>" ;
1207 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1208 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1209 "<span>" . __ ( 'Categories' ). "</span>" ;
1210 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1211 print "<div onclick= \" createCategory() \"
1212 dojoType= \" dijit.MenuItem \" >" . __ ( 'Add category' ). "</div>" ;
1213 print "<div onclick= \" resetCatOrder() \"
1214 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1215 print "<div onclick= \" removeSelectedCategories() \"
1216 dojoType= \" dijit.MenuItem \" >" . __ ( 'Remove selected' ). "</div>" ;
1217 print "</div></div>" ;
1221 print $error_button ;
1222 print $inactive_button ;
1224 print "</div>" ; # toolbar
1227 print '<div dojoType="dijit.layout.ContentPane" region="center">' ;
1229 print "<div id= \" feedlistLoading \" >
1230 <img src='images/indicator_tiny.gif'>" .
1231 __ ( "Loading, please wait..." ). "</div>" ;
1233 $auto_expand = $feed_search != "" ?
"true" : "false" ;
1235 print "<div dojoType= \" fox.PrefFeedStore \" jsId= \" feedStore \"
1236 url= \" backend.php?op=pref-feeds&method=getfeedtree \" >
1238 <div dojoType= \" lib.CheckBoxStoreModel \" jsId= \" feedModel \" store= \" feedStore \"
1239 query= \" {id:'root'} \" rootId= \" root \" rootLabel= \" Feeds \"
1240 childrenAttrs= \" items \" checkboxStrict= \" false \" checkboxAll= \" false \" >
1242 <div dojoType= \" fox.PrefFeedTree \" id= \" feedTree \"
1243 dndController= \" dijit.tree.dndSource \"
1244 betweenThreshold= \" 5 \"
1245 autoExpand=' $auto_expand '
1246 model= \" feedModel \" openOnClick= \" false \" >
1247 <script type= \" dojo/method \" event= \" onClick \" args= \" item \" >
1248 var id = String(item.id);
1249 var bare_id = id.substr(id.indexOf(':')+1);
1251 if (id.match('FEED:')) {
1253 } else if (id.match('CAT:')) {
1254 editCat(bare_id, item);
1257 <script type= \" dojo/method \" event= \" onLoad \" args= \" item \" >
1258 Element.hide( \" feedlistLoading \" );
1260 checkInactiveFeeds();
1264 # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1265 # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1271 print "</div>" ; # feeds pane
1273 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'OPML' ). " \" >" ;
1275 print "<p>" . __ ( "Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings." ) .
1276 __ ( "Only main settings profile can be migrated using OPML." ) . "</p>" ;
1278 print "<iframe id= \" upload_iframe \"
1279 name= \" upload_iframe \" onload= \" opmlImportComplete(this) \"
1280 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
1282 print "<form name= \" opml_form \" style='display : block' target= \" upload_iframe \"
1283 enctype= \" multipart/form-data \" method= \" POST \"
1284 action= \" backend.php \" >
1285 <label class= \" dijitButton \" >" . __ ( "Choose file..." ). "
1286 <input style= \" display : none \" id= \" opml_file \" name= \" opml_file \" type= \" file \" >
1288 <input type= \" hidden \" name= \" op \" value= \" dlg \" >
1289 <input type= \" hidden \" name= \" method \" value= \" importOpml \" >
1290 <button dojoType= \" dijit.form.Button \" onclick= \" return opmlImport(); \" type= \" submit \" >" .
1291 __ ( 'Import my OPML' ) . "</button>" ;
1295 $opml_export_filename = "TinyTinyRSS_" . date ( "Y-m-d" ). ".opml" ;
1297 print "<p>" . __ ( 'Filename:' ) .
1298 " <input class= \" input input-text \" type= \" text \" id= \" filename \" value= \" $opml_export_filename\" /> " .
1299 __ ( 'Include settings' ) . "<input type= \" checkbox \" id= \" settings \" checked= \" 1 \" />" ;
1301 print "</p><button dojoType= \" dijit.form.Button \"
1302 onclick= \" gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked) \" >" .
1303 __ ( 'Export OPML' ) . "</button></p></form>" ;
1307 print "<p>" . __ ( 'Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.' ) . "</p>" ;
1309 print_warning ( "Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds." );
1311 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "Public OPML URL" ). "','pubOPMLUrl') \" >" .
1312 __ ( 'Display published OPML URL' ). "</button> " ;
1314 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1315 "hook_prefs_tab_section" , "prefFeedsOPML" );
1317 print "</div>" ; # pane
1319 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Published & shared articles / Generated feeds' ). " \" >" ;
1321 print "<p>" . __ ( 'Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.' ) . "</p>" ;
1323 $rss_url = '-2::' . htmlspecialchars ( get_self_url_prefix () .
1324 "/public.php?op=rss&id=-2&view-mode=all_articles" );;
1328 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "View as RSS" ). "','generatedFeed', ' $rss_url ') \" >" .
1329 __ ( 'Display URL' ). "</button> " ;
1331 print "<button class= \" warning \" dojoType= \" dijit.form.Button \" onclick= \" return clearFeedAccessKeys() \" >" .
1332 __ ( 'Clear all generated URLs' ). "</button> " ;
1336 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1337 "hook_prefs_tab_section" , "prefFeedsPublishedGenerated" );
1339 print "</div>" ; #pane
1341 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
1342 "hook_prefs_tab" , "prefFeeds" );
1344 print "</div>" ; #container
1347 private function feedlist_init_cat ( $cat_id ) {
1349 $cat_id = ( int ) $cat_id ;
1352 $cat_unread = CCache
:: find ( $cat_id , $_SESSION [ "uid" ], true );
1353 } else if ( $cat_id == 0 ||
$cat_id == - 2 ) {
1354 $cat_unread = Feeds
:: getCategoryUnread ( $cat_id );
1357 $obj [ 'id' ] = 'CAT:' . $cat_id ;
1358 $obj [ 'items' ] = array ();
1359 $obj [ 'name' ] = Feeds
:: getCategoryTitle ( $cat_id );
1360 $obj [ 'type' ] = 'category' ;
1361 $obj [ 'unread' ] = ( int ) $cat_unread ;
1362 $obj [ 'bare_id' ] = $cat_id ;
1367 private function feedlist_init_feed ( $feed_id , $title = false , $unread = false , $error = '' , $updated = '' ) {
1369 $feed_id = ( int ) $feed_id ;
1372 $title = Feeds
:: getFeedTitle ( $feed_id , false );
1374 if ( $unread === false )
1375 $unread = getFeedUnread ( $feed_id , false );
1377 $obj [ 'id' ] = 'FEED:' . $feed_id ;
1378 $obj [ 'name' ] = $title ;
1379 $obj [ 'unread' ] = ( int ) $unread ;
1380 $obj [ 'type' ] = 'feed' ;
1381 $obj [ 'error' ] = $error ;
1382 $obj [ 'updated' ] = $updated ;
1383 $obj [ 'icon' ] = Feeds
:: getFeedIcon ( $feed_id );
1384 $obj [ 'bare_id' ] = $feed_id ;
1385 $obj [ 'auxcounter' ] = 0 ;
1390 function inactiveFeeds () {
1392 if ( DB_TYPE
== "pgsql" ) {
1393 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1395 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1398 $sth = $this -> pdo
-> prepare ( "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
1399 ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
1400 FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
1401 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1402 ttrss_entries.id = ref_id AND
1403 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
1404 AND ttrss_feeds.owner_uid = ? AND
1405 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1406 ttrss_entries.id = ref_id
1407 GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
1408 ORDER BY last_article" );
1409 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1411 print "<p" . __ ( "These feeds have not been updated with new content for 3 months (oldest first):" ) . "</p>" ;
1413 print "<div dojoType= \" dijit.Toolbar \" >" ;
1414 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1415 "<span>" . __ ( 'Select' ). "</span>" ;
1416 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1417 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'all') \"
1418 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1419 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'none') \"
1420 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1421 print "</div></div>" ;
1422 print "</div>" ; #toolbar
1424 print "<div class= \" inactiveFeedHolder \" >" ;
1426 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefInactiveFeedList \" >" ;
1430 while ( $line = $sth -> fetch ()) {
1432 $feed_id = $line [ "id" ];
1433 $this_row_id = "id= \" FUPDD- $feed_id\" " ;
1435 # class needed for selectTableRows()
1436 print "<tr class= \" placeholder \" $this_row_id >" ;
1438 # id needed for selectTableRows()
1439 print "<td width='5%' align='center'><input
1440 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1441 type= \" checkbox \" id= \" FUPDC- $feed_id\" ></td>" ;
1444 print "<a class= \" visibleLink \" href= \" # \" " .
1445 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1446 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1447 htmlspecialchars ( $line [ "title" ]). "</a>" ;
1449 print "</td><td class= \" insensitive \" align='right'>" ;
1450 print make_local_datetime ( $line [ 'last_article' ], false );
1460 print "<div class='dlgButtons'>" ;
1461 print "<div style='float : left'>" ;
1462 print "<button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').removeSelected() \" >"
1463 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1466 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').hide() \" >" .
1467 __ ( 'Close this window' ). "</button>" ;
1473 function feedsWithErrors () {
1474 $sth = $this -> pdo
-> prepare ( "SELECT id,title,feed_url,last_error,site_url
1475 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?" );
1476 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1478 print "<div dojoType= \" dijit.Toolbar \" >" ;
1479 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1480 "<span>" . __ ( 'Select' ). "</span>" ;
1481 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1482 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'all') \"
1483 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1484 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'none') \"
1485 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1486 print "</div></div>" ;
1487 print "</div>" ; #toolbar
1489 print "<div class= \" inactiveFeedHolder \" >" ;
1491 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefErrorFeedList \" >" ;
1495 while ( $line = $sth -> fetch ()) {
1497 $feed_id = $line [ "id" ];
1498 $this_row_id = "id= \" FERDD- $feed_id\" " ;
1500 # class needed for selectTableRows()
1501 print "<tr class= \" placeholder \" $this_row_id >" ;
1503 # id needed for selectTableRows()
1504 print "<td width='5%' align='center'><input
1505 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1506 type= \" checkbox \" id= \" FERDC- $feed_id\" ></td>" ;
1509 print "<a class= \" visibleLink \" href= \" # \" " .
1510 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1511 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1512 htmlspecialchars ( $line [ "title" ]). "</a>: " ;
1514 print "<span class= \" insensitive \" >" ;
1515 print htmlspecialchars ( $line [ "last_error" ]);
1527 print "<div class='dlgButtons'>" ;
1528 print "<div style='float : left'>" ;
1529 print "<button class= \" btn-danger \" dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').removeSelected() \" >"
1530 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1533 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').hide() \" >" .
1534 __ ( 'Close this window' ). "</button>" ;
1539 private function remove_feed_category ( $id , $owner_uid ) {
1541 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_feed_categories
1542 WHERE id = ? AND owner_uid = ?" );
1543 $sth -> execute ([ $id , $owner_uid ]);
1545 CCache
:: remove ( $id , $owner_uid , true );
1548 static function remove_feed ( $id , $owner_uid ) {
1549 foreach ( PluginHost
:: getInstance ()-> get_hooks ( PluginHost
:: HOOK_UNSUBSCRIBE_FEED
) as $p ) {
1550 if (! $p -> hook_unsubscribe_feed ( $id , $owner_uid )) {
1551 user_error ( "Feed $id (owner: $owner_uid ) not removed due to plugin error (HOOK_UNSUBSCRIBE_FEED)." , E_USER_WARNING
);
1559 $pdo -> beginTransaction ();
1561 /* save starred articles in Archived feed */
1563 /* prepare feed if necessary */
1565 $sth = $pdo -> prepare ( "SELECT feed_url FROM ttrss_feeds WHERE id = ?
1566 AND owner_uid = ?" );
1567 $sth -> execute ([ $id , $owner_uid ]);
1569 if ( $row = $sth -> fetch ()) {
1570 $feed_url = $row [ "feed_url" ];
1572 $sth = $pdo -> prepare ( "SELECT id FROM ttrss_archived_feeds
1573 WHERE feed_url = ? AND owner_uid = ?" );
1574 $sth -> execute ([ $feed_url , $owner_uid ]);
1576 if ( $row = $sth -> fetch ()) {
1577 $archive_id = $row [ "id" ];
1579 $res = $pdo -> query ( "SELECT MAX(id) AS id FROM ttrss_archived_feeds" );
1580 $row = $res -> fetch ();
1582 $new_feed_id = ( int ) $row [ 'id' ] +
1 ;
1584 $sth = $pdo -> prepare ( "INSERT INTO ttrss_archived_feeds
1585 (id, owner_uid, title, feed_url, site_url)
1586 SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds
1588 $sth -> execute ([ $new_feed_id , $id ]);
1590 $archive_id = $new_feed_id ;
1593 $sth = $pdo -> prepare ( "UPDATE ttrss_user_entries SET feed_id = NULL,
1594 orig_feed_id = ? WHERE feed_id = ? AND
1595 marked = true AND owner_uid = ?" );
1597 $sth -> execute ([ $archive_id , $id , $owner_uid ]);
1599 /* Remove access key for the feed */
1601 $sth = $pdo -> prepare ( "DELETE FROM ttrss_access_keys WHERE
1602 feed_id = ? AND owner_uid = ?" );
1603 $sth -> execute ([ $id , $owner_uid ]);
1605 /* remove the feed */
1607 $sth = $pdo -> prepare ( "DELETE FROM ttrss_feeds
1608 WHERE id = ? AND owner_uid = ?" );
1609 $sth -> execute ([ $id , $owner_uid ]);
1614 if ( file_exists ( ICONS_DIR
. "/ $id .ico" )) {
1615 unlink ( ICONS_DIR
. "/ $id .ico" );
1618 CCache
:: remove ( $id , $owner_uid );
1621 Labels
:: remove ( Labels
:: feed_to_label_id ( $id ), $owner_uid );
1622 //CCache::remove($id, $owner_uid); don't think labels are cached
1626 function batchSubscribe () {
1627 print_hidden ( "op" , "pref-feeds" );
1628 print_hidden ( "method" , "batchaddfeeds" );
1630 print "<table width='100%'><tr><td>
1631 " . __ ( "Add one valid RSS feed per line (no feed detection is done)" ). "
1632 </td><td align='right'>" ;
1633 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1634 print __ ( 'Place in category:' ) . " " ;
1635 print_feed_cat_select ( "cat" , false , 'dojoType="dijit.form.Select"' );
1637 print "</td></tr><tr><td colspan='2'>" ;
1639 style='font-size : 12px; width : 98%; height: 200px;'
1640 placeHolder= \" " . __ ( "Feeds to subscribe, One per line" ). " \"
1641 dojoType= \" dijit.form.SimpleTextarea \" required= \" 1 \" name= \" feeds \" ></textarea>" ;
1643 print "</td></tr><tr><td colspan='2'>" ;
1645 print "<div id='feedDlg_loginContainer' style='display : none'>
1647 " <input dojoType= \" dijit.form.TextBox \" name='login' \"
1648 placeHolder= \" " . __ ( "Login" ). " \"
1649 style= \" width : 10em; \" > " .
1651 placeHolder= \" " . __ ( "Password" ). " \"
1652 dojoType= \" dijit.form.TextBox \" type='password'
1653 autocomplete= \" new-password \"
1654 style= \" width : 10em; \" name='pass' \" >" .
1657 print "</td></tr><tr><td colspan='2'>" ;
1659 print "<div style= \" clear : both \" >
1660 <input type= \" checkbox \" name= \" need_auth \" dojoType= \" dijit.form.CheckBox \" id= \" feedDlg_loginCheck \"
1661 onclick='checkboxToggleElement(this, \" feedDlg_loginContainer \" )'>
1662 <label for= \" feedDlg_loginCheck \" >" .
1663 __ ( 'Feeds require authentication.' ). "</div>" ;
1667 print "</td></tr></table>" ;
1669 print "<div class= \" dlgButtons \" >
1670 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').execute() \" >" . __ ( 'Subscribe' ). "</button>
1671 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
1675 function batchAddFeeds () {
1676 $cat_id = clean ( $_REQUEST [ 'cat' ]);
1677 $feeds = explode ( " \n " , clean ( $_REQUEST [ 'feeds' ]));
1678 $login = clean ( $_REQUEST [ 'login' ]);
1679 $pass = trim ( clean ( $_REQUEST [ 'pass' ]));
1681 foreach ( $feeds as $feed ) {
1682 $feed = trim ( $feed );
1684 if ( validate_feed_url ( $feed )) {
1686 $this -> pdo
-> beginTransaction ();
1688 $sth = $this -> pdo
-> prepare ( "SELECT id FROM ttrss_feeds
1689 WHERE feed_url = ? AND owner_uid = ?" );
1690 $sth -> execute ([ $feed , $_SESSION [ 'uid' ]]);
1692 if (! $sth -> fetch ()) {
1693 $sth = $this -> pdo
-> prepare ( "INSERT INTO ttrss_feeds
1694 (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
1695 VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)" );
1697 $sth -> execute ([ $_SESSION [ 'uid' ], $feed , $cat_id ?
$cat_id : null , $login , $pass ]);
1700 $this -> pdo
-> commit ();
1705 function regenOPMLKey () {
1706 $this -> update_feed_access_key ( 'OPML:Publish' ,
1707 false , $_SESSION [ "uid" ]);
1709 $new_link = Opml
:: opml_publish_url ();
1711 print json_encode ( array ( "link" => $new_link ));
1714 function regenFeedKey () {
1715 $feed_id = clean ( $_REQUEST [ 'id' ]);
1716 $is_cat = clean ( $_REQUEST [ 'is_cat' ]);
1718 $new_key = $this -> update_feed_access_key ( $feed_id , $is_cat );
1720 print json_encode ([ "link" => $new_key ]);
1724 private function update_feed_access_key ( $feed_id , $is_cat , $owner_uid = false ) {
1725 if (! $owner_uid ) $owner_uid = $_SESSION [ "uid" ];
1727 // clear old value and generate new one
1728 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_access_keys
1729 WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?" );
1730 $sth -> execute ([ $feed_id , bool_to_sql_bool ( $is_cat ), $owner_uid ]);
1732 return get_feed_access_key ( $feed_id , $is_cat , $owner_uid );
1736 function clearKeys () {
1737 $sth = $this -> pdo
-> prepare ( "DELETE FROM ttrss_access_keys WHERE
1739 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1742 private function calculate_children_count ( $cat ) {
1745 foreach ( $cat [ 'items' ] as $child ) {
1746 if ( $child [ 'type' ] == 'category' ) {
1747 $c +
= $this -> calculate_children_count ( $child );
1756 function getinactivefeeds () {
1757 if ( DB_TYPE
== "pgsql" ) {
1758 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1760 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1763 $sth = $this -> pdo
-> prepare ( "SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE
1764 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1765 ttrss_entries.id = ref_id AND
1766 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1767 ttrss_feeds.owner_uid = ?" );
1768 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1770 if ( $row = $sth -> fetch ()) {
1771 print ( int ) $row [ "num_inactive" ];
1775 static function subscribe_to_feed_url () {
1776 $url_path = get_self_url_prefix () .
1777 "/public.php?op=subscribe&feed_url= %s " ;