]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/feeds.php
2 class Pref_Feeds
extends Handler_Protected
{
4 function csrf_ignore ( $method ) {
5 $csrf_ignored = array ( "index" , "getfeedtree" , "add" , "editcats" , "editfeed" ,
6 "savefeedorder" , "uploadicon" , "feedswitherrors" , "inactivefeeds" ,
9 return array_search ( $method , $csrf_ignored ) !== false ;
12 function batch_edit_cbox ( $elem , $label = false ) {
13 print "<input type= \" checkbox \" title= \" " . __ ( "Check to enable field" ). " \"
14 onchange= \" dijit.byId('feedEditDlg').toggleField(this, ' $elem ', ' $label ') \" >" ;
17 function renamecat () {
18 $title = $this -> dbh
-> escape_string ( $_REQUEST [ 'title' ]);
19 $id = $this -> dbh
-> escape_string ( $_REQUEST [ 'id' ]);
22 $this -> dbh
-> query ( "UPDATE ttrss_feed_categories SET
23 title = ' $title ' WHERE id = ' $id ' AND owner_uid = " . $_SESSION [ "uid" ]);
28 private function get_category_items ( $cat_id ) {
30 if ( $_REQUEST [ 'mode' ] != 2 )
31 $search = $_SESSION [ "prefs_feed_search" ];
35 if ( $search ) $search_qpart = " AND LOWER(title) LIKE LOWER('% $search %')" ;
37 // first one is set by API
38 $show_empty_cats = $_REQUEST [ 'force_show_empty' ] ||
39 ( $_REQUEST [ 'mode' ] != 2 && ! $search &&
40 get_pref ( '_PREFS_SHOW_EMPTY_CATS' ));
44 $result = $this -> dbh
-> query ( "SELECT id, title FROM ttrss_feed_categories
45 WHERE owner_uid = " . $_SESSION [ "uid" ] . " AND parent_cat = ' $cat_id ' ORDER BY order_id, title" );
47 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
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 ;
59 $cat [ 'items' ] = $this -> get_category_items ( $line [ 'id' ]);
61 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
63 if ( count ( $cat [ 'items' ]) > 0 ||
$show_empty_cats )
64 array_push ( $items , $cat );
68 $feed_result = $this -> dbh
-> query ( "SELECT id, title, last_error,
69 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
71 WHERE cat_id = ' $cat_id ' AND owner_uid = " . $_SESSION [ "uid" ].
72 " $search_qpart ORDER BY order_id, title" );
74 while ( $feed_line = $this -> dbh
-> fetch_assoc ( $feed_result )) {
76 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
77 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
78 $feed [ 'name' ] = $feed_line [ 'title' ];
79 $feed [ 'checkbox' ] = false ;
81 $feed [ 'error' ] = $feed_line [ 'last_error' ];
82 $feed [ 'icon' ] = getFeedIcon ( $feed_line [ 'id' ]);
83 $feed [ 'param' ] = make_local_datetime (
84 $feed_line [ 'last_updated' ], true );
86 array_push ( $items , $feed );
92 function getfeedtree () {
93 print json_encode ( $this -> makefeedtree ());
96 function makefeedtree () {
98 if ( $_REQUEST [ 'mode' ] != 2 )
99 $search = $_SESSION [ "prefs_feed_search" ];
103 if ( $search ) $search_qpart = " AND LOWER(title) LIKE LOWER('% $search %')" ;
106 $root [ 'id' ] = 'root' ;
107 $root [ 'name' ] = __ ( 'Feeds' );
108 $root [ 'items' ] = array ();
109 $root [ 'type' ] = 'category' ;
111 $enable_cats = get_pref ( 'ENABLE_FEED_CATS' );
113 if ( $_REQUEST [ 'mode' ] == 2 ) {
116 $cat = $this -> feedlist_init_cat (- 1 );
118 $cat [ 'items' ] = array ();
121 foreach ( array (- 4 , - 3 , - 1 , - 2 , 0 , - 6 ) as $i ) {
122 array_push ( $cat [ 'items' ], $this -> feedlist_init_feed ( $i ));
125 /* Plugin feeds for -1 */
127 $feeds = PluginHost
:: getInstance ()-> get_feeds (- 1 );
130 foreach ( $feeds as $feed ) {
131 $feed_id = PluginHost
:: pfeed_to_feed_id ( $feed [ 'id' ]);
134 $item [ 'id' ] = 'FEED:' . $feed_id ;
135 $item [ 'bare_id' ] = ( int ) $feed_id ;
136 $item [ 'name' ] = $feed [ 'title' ];
137 $item [ 'checkbox' ] = false ;
139 $item [ 'icon' ] = $feed [ 'icon' ];
142 $item [ 'unread' ] = 0 ; //$feed['sender']->get_unread($feed['id']);
143 $item [ 'type' ] = 'feed' ;
145 array_push ( $cat [ 'items' ], $item );
150 array_push ( $root [ 'items' ], $cat );
152 $root [ 'items' ] = array_merge ( $root [ 'items' ], $cat [ 'items' ]);
155 $result = $this -> dbh
-> query ( "SELECT * FROM
156 ttrss_labels2 WHERE owner_uid = " . $_SESSION [ 'uid' ]. " ORDER by caption" );
158 if ( $this -> dbh
-> num_rows ( $result ) > 0 ) {
160 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
161 $cat = $this -> feedlist_init_cat (- 2 );
163 $cat [ 'items' ] = array ();
166 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
168 $label_id = label_to_feed_id ( $line [ 'id' ]);
170 $feed = $this -> feedlist_init_feed ( $label_id , false , 0 );
172 $feed [ 'fg_color' ] = $line [ 'fg_color' ];
173 $feed [ 'bg_color' ] = $line [ 'bg_color' ];
175 array_push ( $cat [ 'items' ], $feed );
179 array_push ( $root [ 'items' ], $cat );
181 $root [ 'items' ] = array_merge ( $root [ 'items' ], $cat [ 'items' ]);
187 $show_empty_cats = $_REQUEST [ 'force_show_empty' ] ||
188 ( $_REQUEST [ 'mode' ] != 2 && ! $search &&
189 get_pref ( '_PREFS_SHOW_EMPTY_CATS' ));
191 $result = $this -> dbh
-> query ( "SELECT id, title FROM ttrss_feed_categories
192 WHERE owner_uid = " . $_SESSION [ "uid" ] . " AND parent_cat IS NULL ORDER BY order_id, title" );
194 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
196 $cat [ 'id' ] = 'CAT:' . $line [ 'id' ];
197 $cat [ 'bare_id' ] = ( int ) $line [ 'id' ];
198 $cat [ 'name' ] = $line [ 'title' ];
199 $cat [ 'items' ] = array ();
200 $cat [ 'checkbox' ] = false ;
201 $cat [ 'type' ] = 'category' ;
203 $cat [ 'child_unread' ] = 0 ;
205 $cat [ 'items' ] = $this -> get_category_items ( $line [ 'id' ]);
207 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
209 if ( count ( $cat [ 'items' ]) > 0 ||
$show_empty_cats )
210 array_push ( $root [ 'items' ], $cat );
212 $root [ 'param' ] +
= count ( $cat [ 'items' ]);
215 /* Uncategorized is a special case */
218 $cat [ 'id' ] = 'CAT:0' ;
220 $cat [ 'name' ] = __ ( "Uncategorized" );
221 $cat [ 'items' ] = array ();
222 $cat [ 'type' ] = 'category' ;
223 $cat [ 'checkbox' ] = false ;
225 $cat [ 'child_unread' ] = 0 ;
227 $feed_result = $this -> dbh
-> query ( "SELECT id, title,last_error,
228 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
230 WHERE cat_id IS NULL AND owner_uid = " . $_SESSION [ "uid" ].
231 " $search_qpart ORDER BY order_id, title" );
233 while ( $feed_line = $this -> dbh
-> fetch_assoc ( $feed_result )) {
235 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
236 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
237 $feed [ 'name' ] = $feed_line [ 'title' ];
238 $feed [ 'checkbox' ] = false ;
239 $feed [ 'error' ] = $feed_line [ 'last_error' ];
240 $feed [ 'icon' ] = getFeedIcon ( $feed_line [ 'id' ]);
241 $feed [ 'param' ] = make_local_datetime (
242 $feed_line [ 'last_updated' ], true );
244 $feed [ 'type' ] = 'feed' ;
246 array_push ( $cat [ 'items' ], $feed );
249 $cat [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
251 if ( count ( $cat [ 'items' ]) > 0 ||
$show_empty_cats )
252 array_push ( $root [ 'items' ], $cat );
254 $root [ 'param' ] +
= count ( $cat [ 'items' ]);
255 $root [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
258 $feed_result = $this -> dbh
-> query ( "SELECT id, title, last_error,
259 " . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
261 WHERE owner_uid = " . $_SESSION [ "uid" ].
262 " $search_qpart ORDER BY order_id, title" );
264 while ( $feed_line = $this -> dbh
-> fetch_assoc ( $feed_result )) {
266 $feed [ 'id' ] = 'FEED:' . $feed_line [ 'id' ];
267 $feed [ 'bare_id' ] = ( int ) $feed_line [ 'id' ];
268 $feed [ 'name' ] = $feed_line [ 'title' ];
269 $feed [ 'checkbox' ] = false ;
270 $feed [ 'error' ] = $feed_line [ 'last_error' ];
271 $feed [ 'icon' ] = getFeedIcon ( $feed_line [ 'id' ]);
272 $feed [ 'param' ] = make_local_datetime (
273 $feed_line [ 'last_updated' ], true );
275 $feed [ 'type' ] = 'feed' ;
277 array_push ( $root [ 'items' ], $feed );
280 $root [ 'param' ] = vsprintf ( _ngettext ( '( %d feed)' , '( %d feeds)' , count ( $cat [ 'items' ])), count ( $cat [ 'items' ]));
284 $fl [ 'identifier' ] = 'id' ;
285 $fl [ 'label' ] = 'name' ;
287 if ( $_REQUEST [ 'mode' ] != 2 ) {
288 $fl [ 'items' ] = array ( $root );
290 $fl [ 'items' ] =& $root [ 'items' ];
296 function catsortreset () {
297 $this -> dbh
-> query ( "UPDATE ttrss_feed_categories
298 SET order_id = 0 WHERE owner_uid = " . $_SESSION [ "uid" ]);
302 function feedsortreset () {
303 $this -> dbh
-> query ( "UPDATE ttrss_feeds
304 SET order_id = 0 WHERE owner_uid = " . $_SESSION [ "uid" ]);
308 function togglehiddenfeedcats () {
309 set_pref ( '_PREFS_SHOW_EMPTY_CATS' ,
310 ( get_pref ( '_PREFS_SHOW_EMPTY_CATS' ) ?
'false' : 'true' ));
313 private function process_category_order (& $data_map , $item_id , $parent_id = false , $nest_level = 0 ) {
314 $debug = isset ( $_REQUEST [ "debug" ]);
317 for ( $i = 0 ; $i < $nest_level ; $i ++
)
320 if ( $debug ) _debug ( " $prefix C: $item_id P: $parent_id " );
322 $bare_item_id = substr ( $item_id , strpos ( $item_id , ':' ) +
1 );
324 if ( $item_id != 'root' ) {
325 if ( $parent_id && $parent_id != 'root' ) {
326 $parent_bare_id = substr ( $parent_id , strpos ( $parent_id , ':' ) +
1 );
327 $parent_qpart = $this -> dbh
-> escape_string ( $parent_bare_id );
329 $parent_qpart = 'NULL' ;
332 $this -> dbh
-> query ( "UPDATE ttrss_feed_categories
333 SET parent_cat = $parent_qpart WHERE id = ' $bare_item_id ' AND
334 owner_uid = " . $_SESSION [ "uid" ]);
339 $cat = $data_map [ $item_id ];
341 if ( $cat && is_array ( $cat )) {
342 foreach ( $cat as $item ) {
343 $id = $item [ '_reference' ];
344 $bare_id = substr ( $id , strpos ( $id , ':' ) +
1 );
346 if ( $debug ) _debug ( " $prefix [ $order_id ] $id / $bare_id " );
348 if ( $item [ '_reference' ]) {
350 if ( strpos ( $id , "FEED" ) === 0 ) {
352 $cat_id = ( $item_id != "root" ) ?
353 $this -> dbh
-> escape_string ( $bare_item_id ) : "NULL" ;
355 $cat_qpart = ( $cat_id != 0 ) ?
"cat_id = ' $cat_id '" :
358 $this -> dbh
-> query ( "UPDATE ttrss_feeds
359 SET order_id = $order_id , $cat_qpart
360 WHERE id = ' $bare_id ' AND
361 owner_uid = " . $_SESSION [ "uid" ]);
363 } else if ( strpos ( $id , "CAT:" ) === 0 ) {
364 $this -> process_category_order ( $data_map , $item [ '_reference' ], $item_id ,
367 if ( $item_id != 'root' ) {
368 $parent_qpart = $this -> dbh
-> escape_string ( $bare_id );
370 $parent_qpart = 'NULL' ;
373 $this -> dbh
-> query ( "UPDATE ttrss_feed_categories
374 SET order_id = ' $order_id ' WHERE id = ' $bare_id ' AND
375 owner_uid = " . $_SESSION [ "uid" ]);
384 function savefeedorder () {
385 $data = json_decode ( $_POST [ 'payload' ], true );
387 #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
388 #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
390 if (! is_array ( $data [ 'items' ]))
391 $data [ 'items' ] = json_decode ( $data [ 'items' ], true );
393 # print_r($data['items']);
395 if ( is_array ( $data ) && is_array ( $data [ 'items' ])) {
401 foreach ( $data [ 'items' ] as $item ) {
403 # if ($item['id'] != 'root') {
404 if ( is_array ( $item [ 'items' ])) {
405 if ( isset ( $item [ 'items' ][ '_reference' ])) {
406 $data_map [ $item [ 'id' ]] = array ( $item [ 'items' ]);
408 $data_map [ $item [ 'id' ]] =& $item [ 'items' ];
411 if ( $item [ 'id' ] == 'root' ) {
412 $root_item = $item [ 'id' ];
416 $this -> process_category_order ( $data_map , $root_item );
418 /* foreach ($data['items'][0]['items'] as $item) {
419 $id = $item['_reference'];
420 $bare_id = substr($id, strpos($id, ':')+1);
425 $this->dbh->query("UPDATE ttrss_feed_categories
426 SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
427 owner_uid = " . $_SESSION["uid"]);
432 if (is_array($data_map[$id])) {
433 foreach ($data_map[$id] as $feed) {
434 $id = $feed['_reference'];
435 $feed_id = substr($id, strpos($id, ':')+1);
438 $cat_query = "cat_id = '$bare_id'";
440 $cat_query = "cat_id = NULL";
442 $this->dbh->query("UPDATE ttrss_feeds
443 SET order_id = '$feed_order_id',
445 WHERE id = '$feed_id' AND
446 owner_uid = " . $_SESSION["uid"]);
457 function removeicon () {
458 $feed_id = $this -> dbh
-> escape_string ( $_REQUEST [ "feed_id" ]);
460 $result = $this -> dbh
-> query ( "SELECT id FROM ttrss_feeds
461 WHERE id = ' $feed_id ' AND owner_uid = " . $_SESSION [ "uid" ]);
463 if ( $this -> dbh
-> num_rows ( $result ) != 0 ) {
464 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
466 $this -> dbh
-> query ( "UPDATE ttrss_feeds SET favicon_avg_color = NULL
467 where id = ' $feed_id '" );
473 function uploadicon () {
474 header ( "Content-type: text/html" );
478 if ( is_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ])) {
479 $tmp_file = tempnam ( CACHE_DIR
. '/upload' , 'icon' );
481 $result = move_uploaded_file ( $_FILES [ 'icon_file' ][ 'tmp_name' ],
491 $icon_file = $tmp_file ;
492 $feed_id = $this -> dbh
-> escape_string ( $_REQUEST [ "feed_id" ]);
494 if ( is_file ( $icon_file ) && $feed_id ) {
495 if ( filesize ( $icon_file ) < 20000 ) {
497 $result = $this -> dbh
-> query ( "SELECT id FROM ttrss_feeds
498 WHERE id = ' $feed_id ' AND owner_uid = " . $_SESSION [ "uid" ]);
500 if ( $this -> dbh
-> num_rows ( $result ) != 0 ) {
501 @unlink
( ICONS_DIR
. "/ $feed_id .ico" );
502 if ( rename ( $icon_file , ICONS_DIR
. "/ $feed_id .ico" )) {
504 require_once "colors.php" ;
506 $favicon_color = $this -> dbh
-> escape_string (
507 calculate_avg_color ( ICONS_DIR
. "/ $feed_id .ico" ));
509 $this -> dbh
-> query ( "UPDATE ttrss_feeds SET
510 favicon_avg_color = ' $favicon_color '
511 WHERE id = ' $feed_id '" );
527 print "<script type= \" text/javascript \" >" ;
528 print "parent.uploadIconHandler( $rc );" ;
533 function editfeed () {
534 global $purge_intervals ;
535 global $update_intervals ;
537 $feed_id = $this -> dbh
-> escape_string ( $_REQUEST [ "id" ]);
539 $result = $this -> dbh
-> query (
540 "SELECT * FROM ttrss_feeds WHERE id = ' $feed_id ' AND
541 owner_uid = " . $_SESSION [ "uid" ]);
543 $auth_pass_encrypted = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 ,
544 "auth_pass_encrypted" ));
546 $title = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result ,
549 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" id \" value= \" $feed_id\" >" ;
550 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-feeds \" >" ;
551 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" editSave \" >" ;
553 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
554 print "<div class= \" dlgSecCont \" >" ;
558 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
559 placeHolder= \" " . __ ( "Feed Title" ). " \"
560 style= \" font-size : 16px; width: 20em \" name= \" title \" value= \" $title\" >" ;
564 $feed_url = $this -> dbh
-> fetch_result ( $result , 0 , "feed_url" );
565 $feed_url = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result ,
570 print __ ( 'URL:' ) . " " ;
571 print "<input dojoType= \" dijit.form.ValidationTextBox \" required= \" 1 \"
572 placeHolder= \" " . __ ( "Feed URL" ). " \"
573 regExp='^(http|https)://.*' style= \" width : 20em \"
574 name= \" feed_url \" value= \" $feed_url\" >" ;
576 $last_error = $this -> dbh
-> fetch_result ( $result , 0 , "last_error" );
579 print " <span title= \" " . htmlspecialchars ( $last_error ). " \"
580 class= \" feed_error \" >(error)</span>" ;
586 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
588 $cat_id = $this -> dbh
-> fetch_result ( $result , 0 , "cat_id" );
592 print __ ( 'Place in category:' ) . " " ;
594 print_feed_cat_select ( "cat_id" , $cat_id ,
595 'dojoType="dijit.form.Select"' );
600 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
601 print "<div class= \" dlgSecCont \" >" ;
603 /* Update Interval */
605 $update_interval = $this -> dbh
-> fetch_result ( $result , 0 , "update_interval" );
607 print_select_hash ( "update_interval" , $update_interval , $update_intervals ,
608 'dojoType="dijit.form.Select"' );
612 $purge_interval = $this -> dbh
-> fetch_result ( $result , 0 , "purge_interval" );
615 print __ ( 'Article purging:' ) . " " ;
617 print_select_hash ( "purge_interval" , $purge_interval , $purge_intervals ,
618 'dojoType="dijit.form.Select" ' .
619 (( FORCE_ARTICLE_PURGE
== 0 ) ?
"" : 'disabled="1"' ));
622 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
623 print "<div class= \" dlgSecCont \" >" ;
625 $auth_login = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "auth_login" ));
627 print "<input dojoType= \" dijit.form.TextBox \" id= \" feedEditDlg_login \"
628 placeHolder= \" " . __ ( "Login" ). " \"
629 name= \" auth_login \" value= \" $auth_login\" ><hr/>" ;
631 $auth_pass = $this -> dbh
-> fetch_result ( $result , 0 , "auth_pass" );
633 if ( $auth_pass_encrypted ) {
634 require_once "crypt.php" ;
635 $auth_pass = decrypt_string ( $auth_pass );
638 $auth_pass = htmlspecialchars ( $auth_pass );
640 print "<input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
641 placeHolder= \" " . __ ( "Password" ). " \"
642 value= \" $auth_pass\" >" ;
644 print "<div dojoType= \" dijit.Tooltip \" connectId= \" feedEditDlg_login \" position= \" below \" >
645 " . __ ( '<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.' ). "
649 print "<div class= \" dlgSec \" >" . __ ( "Options" ). "</div>" ;
650 print "<div class= \" dlgSecCont \" >" ;
652 $private = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "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 $include_in_digest = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "include_in_digest" ));
665 if ( $include_in_digest ) {
666 $checked = "checked= \" 1 \" " ;
671 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" include_in_digest \"
672 name= \" include_in_digest \"
673 $checked > <label for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
676 $always_display_enclosures = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "always_display_enclosures" ));
678 if ( $always_display_enclosures ) {
679 $checked = "checked" ;
684 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" always_display_enclosures \"
685 name= \" always_display_enclosures \"
686 $checked > <label for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
688 $hide_images = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "hide_images" ));
691 $checked = "checked= \" 1 \" " ;
696 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" hide_images \"
698 $checked > <label for= \" hide_images \" >" .
699 __ ( 'Do not embed images' ). "</label>" ;
701 $cache_images = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "cache_images" ));
704 $checked = "checked= \" 1 \" " ;
709 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" cache_images \"
710 name= \" cache_images \"
711 $checked > <label for= \" cache_images \" >" .
712 __ ( 'Cache images locally' ). "</label>" ;
714 $mark_unread_on_update = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "mark_unread_on_update" ));
716 if ( $mark_unread_on_update ) {
717 $checked = "checked" ;
722 print "<hr/><input dojoType= \" dijit.form.CheckBox \" type= \" checkbox \" id= \" mark_unread_on_update \"
723 name= \" mark_unread_on_update \"
724 $checked > <label for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
730 print "<div class= \" dlgSec \" >" . __ ( "Icon" ). "</div>" ;
731 print "<div class= \" dlgSecCont \" >" ;
733 print "<iframe name= \" icon_upload_iframe \"
734 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
736 print "<form style='display : block' target= \" icon_upload_iframe \"
737 enctype= \" multipart/form-data \" method= \" POST \"
738 action= \" backend.php \" >
739 <input id= \" icon_file \" size= \" 10 \" name= \" icon_file \" type= \" file \" >
740 <input type= \" hidden \" name= \" op \" value= \" pref-feeds \" >
741 <input type= \" hidden \" name= \" feed_id \" value= \" $feed_id\" >
742 <input type= \" hidden \" name= \" method \" value= \" uploadicon \" >
743 <button dojoType= \" dijit.form.Button \" onclick= \" return uploadFeedIcon(); \"
744 type= \" submit \" >" . __ ( 'Replace' ). "</button>
745 <button dojoType= \" dijit.form.Button \" onclick= \" return removeFeedIcon( $feed_id ); \"
746 type= \" submit \" >" . __ ( 'Remove' ). "</button>
751 $title = htmlspecialchars ( $title , ENT_QUOTES
);
753 print "<div class='dlgButtons'>
754 <div style= \" float : left \" >
755 <button dojoType= \" dijit.form.Button \" onclick='return unsubscribeFeed( $feed_id , \" $title\" )'>" .
756 __ ( 'Unsubscribe' ). "</button>" ;
758 if ( PUBSUBHUBBUB_ENABLED
) {
759 $pubsub_state = $this -> dbh
-> fetch_result ( $result , 0 , "pubsub_state" );
760 $pubsub_btn_disabled = ( $pubsub_state == 2 ) ?
"" : "disabled= \" 1 \" " ;
762 print "<button dojoType= \" dijit.form.Button \" id= \" pubsubReset_Btn \" $pubsub_btn_disabled
763 onclick='return resetPubSub( $feed_id , \" $title\" )'>" . __ ( 'Resubscribe to push updates' ).
769 print "<div dojoType= \" dijit.Tooltip \" connectId= \" pubsubReset_Btn \" position= \" below \" >" .
770 __ ( 'Resets PubSubHubbub subscription status for push-enabled feeds.' ). "</div>" ;
772 print "<button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').execute() \" >" . __ ( 'Save' ). "</button>
773 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('feedEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
779 function editfeeds () {
780 global $purge_intervals ;
781 global $update_intervals ;
783 $feed_ids = $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]);
785 print_notice ( "Enable the options you wish to apply using checkboxes on the right:" );
789 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" ids \" value= \" $feed_ids\" >" ;
790 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-feeds \" >" ;
791 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" batchEditSave \" >" ;
793 print "<div class= \" dlgSec \" >" . __ ( "Feed" ). "</div>" ;
794 print "<div class= \" dlgSecCont \" >" ;
798 print "<input dojoType= \" dijit.form.ValidationTextBox \"
799 disabled= \" 1 \" style= \" font-size : 16px; width : 20em; \" required= \" 1 \"
800 name= \" title \" value= \" $title\" >" ;
802 $this -> batch_edit_cbox ( "title" );
808 print __ ( 'URL:' ) . " " ;
809 print "<input dojoType= \" dijit.form.ValidationTextBox \" disabled= \" 1 \"
810 required= \" 1 \" regExp='^(http|https)://.*' style= \" width : 20em \"
811 name= \" feed_url \" value= \" $feed_url\" >" ;
813 $this -> batch_edit_cbox ( "feed_url" );
817 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
821 print __ ( 'Place in category:' ) . " " ;
823 print_feed_cat_select ( "cat_id" , $cat_id ,
824 'disabled="1" dojoType="dijit.form.Select"' );
826 $this -> batch_edit_cbox ( "cat_id" );
832 print "<div class= \" dlgSec \" >" . __ ( "Update" ). "</div>" ;
833 print "<div class= \" dlgSecCont \" >" ;
835 /* Update Interval */
837 print_select_hash ( "update_interval" , $update_interval , $update_intervals ,
838 'disabled="1" dojoType="dijit.form.Select"' );
840 $this -> batch_edit_cbox ( "update_interval" );
844 if ( FORCE_ARTICLE_PURGE
== 0 ) {
848 print __ ( 'Article purging:' ) . " " ;
850 print_select_hash ( "purge_interval" , $purge_interval , $purge_intervals ,
851 'disabled="1" dojoType="dijit.form.Select"' );
853 $this -> batch_edit_cbox ( "purge_interval" );
857 print "<div class= \" dlgSec \" >" . __ ( "Authentication" ). "</div>" ;
858 print "<div class= \" dlgSecCont \" >" ;
860 print "<input dojoType= \" dijit.form.TextBox \"
861 placeHolder= \" " . __ ( "Login" ). " \" disabled= \" 1 \"
862 name= \" auth_login \" value= \" $auth_login\" >" ;
864 $this -> batch_edit_cbox ( "auth_login" );
866 print "<br/><input dojoType= \" dijit.form.TextBox \" type= \" password \" name= \" auth_pass \"
867 placeHolder= \" " . __ ( "Password" ). " \" disabled= \" 1 \"
868 value= \" $auth_pass\" >" ;
870 $this -> batch_edit_cbox ( "auth_pass" );
873 print "<div class= \" dlgSec \" >" . __ ( "Options" ). "</div>" ;
874 print "<div class= \" dlgSecCont \" >" ;
876 print "<input disabled= \" 1 \" type= \" checkbox \" name= \" private \" id= \" private \"
877 dojoType= \" dijit.form.CheckBox \" > <label id= \" private_l \" class='insensitive' for= \" private \" >" . __ ( 'Hide from Popular feeds' ). "</label>" ;
879 print " " ; $this -> batch_edit_cbox ( "private" , "private_l" );
881 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" include_in_digest \"
882 name= \" include_in_digest \"
883 dojoType= \" dijit.form.CheckBox \" > <label id= \" include_in_digest_l \" class='insensitive' for= \" include_in_digest \" >" . __ ( 'Include in e-mail digest' ). "</label>" ;
885 print " " ; $this -> batch_edit_cbox ( "include_in_digest" , "include_in_digest_l" );
887 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" always_display_enclosures \"
888 name= \" always_display_enclosures \"
889 dojoType= \" dijit.form.CheckBox \" > <label id= \" always_display_enclosures_l \" class='insensitive' for= \" always_display_enclosures \" >" . __ ( 'Always display image attachments' ). "</label>" ;
891 print " " ; $this -> batch_edit_cbox ( "always_display_enclosures" , "always_display_enclosures_l" );
893 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" hide_images \"
895 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" hide_images_l \"
896 for= \" hide_images \" >" .
897 __ ( 'Do not embed images' ). "</label>" ;
899 print " " ; $this -> batch_edit_cbox ( "hide_images" , "hide_images_l" );
901 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" cache_images \"
902 name= \" cache_images \"
903 dojoType= \" dijit.form.CheckBox \" > <label class='insensitive' id= \" cache_images_l \"
904 for= \" cache_images \" >" .
905 __ ( 'Cache images locally' ). "</label>" ;
907 print " " ; $this -> batch_edit_cbox ( "cache_images" , "cache_images_l" );
909 print "<br/><input disabled= \" 1 \" type= \" checkbox \" id= \" mark_unread_on_update \"
910 name= \" mark_unread_on_update \"
911 dojoType= \" dijit.form.CheckBox \" > <label id= \" mark_unread_on_update_l \" class='insensitive' for= \" mark_unread_on_update \" >" . __ ( 'Mark updated articles as unread' ). "</label>" ;
913 print " " ; $this -> batch_edit_cbox ( "mark_unread_on_update" , "mark_unread_on_update_l" );
917 print "<div class='dlgButtons'>
918 <button dojoType= \" dijit.form.Button \"
919 onclick= \" return dijit.byId('feedEditDlg').execute() \" >" .
920 __ ( 'Save' ). "</button>
921 <button dojoType= \" dijit.form.Button \"
922 onclick= \" return dijit.byId('feedEditDlg').hide() \" >" .
923 __ ( 'Cancel' ). "</button>
929 function batchEditSave () {
930 return $this -> editsaveops ( true );
933 function editSave () {
934 return $this -> editsaveops ( false );
937 function editsaveops ( $batch ) {
939 $feed_title = $this -> dbh
-> escape_string ( trim ( $_POST [ "title" ]));
940 $feed_link = $this -> dbh
-> escape_string ( trim ( $_POST [ "feed_url" ]));
941 $upd_intl = ( int ) $this -> dbh
-> escape_string ( $_POST [ "update_interval" ]);
942 $purge_intl = ( int ) $this -> dbh
-> escape_string ( $_POST [ "purge_interval" ]);
943 $feed_id = ( int ) $this -> dbh
-> escape_string ( $_POST [ "id" ]); /* editSave */
944 $feed_ids = $this -> dbh
-> escape_string ( $_POST [ "ids" ]); /* batchEditSave */
945 $cat_id = ( int ) $this -> dbh
-> escape_string ( $_POST [ "cat_id" ]);
946 $auth_login = $this -> dbh
-> escape_string ( trim ( $_POST [ "auth_login" ]));
947 $auth_pass = trim ( $_POST [ "auth_pass" ]);
948 $private = checkbox_to_sql_bool ( $this -> dbh
-> escape_string ( $_POST [ "private" ]));
949 $include_in_digest = checkbox_to_sql_bool (
950 $this -> dbh
-> escape_string ( $_POST [ "include_in_digest" ]));
951 $cache_images = checkbox_to_sql_bool (
952 $this -> dbh
-> escape_string ( $_POST [ "cache_images" ]));
953 $hide_images = checkbox_to_sql_bool (
954 $this -> dbh
-> escape_string ( $_POST [ "hide_images" ]));
955 $always_display_enclosures = checkbox_to_sql_bool (
956 $this -> dbh
-> escape_string ( $_POST [ "always_display_enclosures" ]));
958 $mark_unread_on_update = checkbox_to_sql_bool (
959 $this -> dbh
-> escape_string ( $_POST [ "mark_unread_on_update" ]));
961 if ( strlen ( FEED_CRYPT_KEY
) > 0 ) {
962 require_once "crypt.php" ;
963 $auth_pass = substr ( encrypt_string ( $auth_pass ), 0 , 250 );
964 $auth_pass_encrypted = 'true' ;
966 $auth_pass_encrypted = 'false' ;
969 $auth_pass = $this -> dbh
-> escape_string ( $auth_pass );
971 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
972 if ( $cat_id && $cat_id != 0 ) {
973 $category_qpart = "cat_id = ' $cat_id '," ;
974 $category_qpart_nocomma = "cat_id = ' $cat_id '" ;
976 $category_qpart = 'cat_id = NULL,' ;
977 $category_qpart_nocomma = 'cat_id = NULL' ;
980 $category_qpart = "" ;
981 $category_qpart_nocomma = "" ;
986 $result = $this -> dbh
-> query ( "UPDATE ttrss_feeds SET
988 title = ' $feed_title ', feed_url = ' $feed_link ',
989 update_interval = ' $upd_intl ',
990 purge_interval = ' $purge_intl ',
991 auth_login = ' $auth_login ',
992 auth_pass = ' $auth_pass ',
993 auth_pass_encrypted = $auth_pass_encrypted ,
995 cache_images = $cache_images ,
996 hide_images = $hide_images ,
997 include_in_digest = $include_in_digest ,
998 always_display_enclosures = $always_display_enclosures ,
999 mark_unread_on_update = $mark_unread_on_update
1000 WHERE id = ' $feed_id ' AND owner_uid = " . $_SESSION [ "uid" ]);
1003 $feed_data = array ();
1005 foreach ( array_keys ( $_POST ) as $k ) {
1006 if ( $k != "op" && $k != "method" && $k != "ids" ) {
1007 $feed_data [ $k ] = $_POST [ $k ];
1011 $this -> dbh
-> query ( "BEGIN" );
1013 foreach ( array_keys ( $feed_data ) as $k ) {
1019 $qpart = "title = ' $feed_title '" ;
1023 $qpart = "feed_url = ' $feed_link '" ;
1026 case "update_interval" :
1027 $qpart = "update_interval = ' $upd_intl '" ;
1030 case "purge_interval" :
1031 $qpart = "purge_interval = ' $purge_intl '" ;
1035 $qpart = "auth_login = ' $auth_login '" ;
1039 $qpart = "auth_pass = ' $auth_pass ' AND
1040 auth_pass_encrypted = $auth_pass_encrypted " ;
1044 $qpart = "private = $private " ;
1047 case "include_in_digest" :
1048 $qpart = "include_in_digest = $include_in_digest " ;
1051 case "always_display_enclosures" :
1052 $qpart = "always_display_enclosures = $always_display_enclosures " ;
1055 case "mark_unread_on_update" :
1056 $qpart = "mark_unread_on_update = $mark_unread_on_update " ;
1059 case "cache_images" :
1060 $qpart = "cache_images = $cache_images " ;
1064 $qpart = "hide_images = $hide_images " ;
1068 $qpart = $category_qpart_nocomma ;
1075 "UPDATE ttrss_feeds SET $qpart WHERE id IN ( $feed_ids )
1076 AND owner_uid = " . $_SESSION [ "uid" ]);
1081 $this -> dbh
-> query ( "COMMIT" );
1086 function resetPubSub () {
1088 $ids = $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]);
1090 $this -> dbh
-> query ( "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ( $ids )
1091 AND owner_uid = " . $_SESSION [ "uid" ]);
1098 $ids = explode ( "," , $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]));
1100 foreach ( $ids as $id ) {
1101 Pref_Feeds
:: remove_feed ( $id , $_SESSION [ "uid" ]);
1108 $id = $this -> dbh
-> escape_string ( $_REQUEST [ "id" ]);
1109 $this -> clear_feed_articles ( $id );
1112 function rescore () {
1113 require_once "rssfuncs.php" ;
1115 $ids = explode ( "," , $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]));
1117 foreach ( $ids as $id ) {
1119 $filters = load_filters ( $id , $_SESSION [ "uid" ], 6 );
1121 $result = $this -> dbh
-> query ( "SELECT
1122 title, content, link, ref_id, author," .
1123 SUBSTRING_FOR_DATE
. "(updated, 1, 19) AS updated
1125 ttrss_user_entries, ttrss_entries
1126 WHERE ref_id = id AND feed_id = ' $id ' AND
1127 owner_uid = " . $_SESSION [ 'uid' ]. "
1132 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1134 $tags = get_article_tags ( $line [ "ref_id" ]);
1136 $article_filters = get_article_filters ( $filters , $line [ 'title' ],
1137 $line [ 'content' ], $line [ 'link' ], strtotime ( $line [ 'updated' ]),
1138 $line [ 'author' ], $tags );
1140 $new_score = calculate_article_score ( $article_filters );
1142 if (! $scores [ $new_score ]) $scores [ $new_score ] = array ();
1144 array_push ( $scores [ $new_score ], $line [ 'ref_id' ]);
1147 foreach ( array_keys ( $scores ) as $s ) {
1149 $this -> dbh
-> query ( "UPDATE ttrss_user_entries SET score = ' $s ',
1151 ref_id IN (" . join ( ',' , $scores [ $s ]) . ")" );
1152 } else if ( $s < - 500 ) {
1153 $this -> dbh
-> query ( "UPDATE ttrss_user_entries SET score = ' $s ',
1154 unread = false WHERE
1155 ref_id IN (" . join ( ',' , $scores [ $s ]) . ")" );
1157 $this -> dbh
-> query ( "UPDATE ttrss_user_entries SET score = ' $s ' WHERE
1158 ref_id IN (" . join ( ',' , $scores [ $s ]) . ")" );
1163 print __ ( "All done." );
1167 function rescoreAll () {
1169 $result = $this -> dbh
-> query (
1170 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION [ 'uid' ]);
1172 while ( $feed_line = $this -> dbh
-> fetch_assoc ( $result )) {
1174 $id = $feed_line [ "id" ];
1176 $filters = load_filters ( $id , $_SESSION [ "uid" ], 6 );
1178 $tmp_result = $this -> dbh
-> query ( "SELECT
1179 title, content, link, ref_id, author," .
1180 SUBSTRING_FOR_DATE
. "(updated, 1, 19) AS updated
1182 ttrss_user_entries, ttrss_entries
1183 WHERE ref_id = id AND feed_id = ' $id ' AND
1184 owner_uid = " . $_SESSION [ 'uid' ]. "
1189 while ( $line = $this -> dbh
-> fetch_assoc ( $tmp_result )) {
1191 $tags = get_article_tags ( $line [ "ref_id" ]);
1193 $article_filters = get_article_filters ( $filters , $line [ 'title' ],
1194 $line [ 'content' ], $line [ 'link' ], strtotime ( $line [ 'updated' ]),
1195 $line [ 'author' ], $tags );
1197 $new_score = calculate_article_score ( $article_filters );
1199 if (! $scores [ $new_score ]) $scores [ $new_score ] = array ();
1201 array_push ( $scores [ $new_score ], $line [ 'ref_id' ]);
1204 foreach ( array_keys ( $scores ) as $s ) {
1206 $this -> dbh
-> query ( "UPDATE ttrss_user_entries SET score = ' $s ',
1208 ref_id IN (" . join ( ',' , $scores [ $s ]) . ")" );
1210 $this -> dbh
-> query ( "UPDATE ttrss_user_entries SET score = ' $s ' WHERE
1211 ref_id IN (" . join ( ',' , $scores [ $s ]) . ")" );
1216 print __ ( "All done." );
1220 function categorize () {
1221 $ids = explode ( "," , $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]));
1223 $cat_id = $this -> dbh
-> escape_string ( $_REQUEST [ "cat_id" ]);
1226 $cat_id_qpart = 'NULL' ;
1228 $cat_id_qpart = "' $cat_id '" ;
1231 $this -> dbh
-> query ( "BEGIN" );
1233 foreach ( $ids as $id ) {
1235 $this -> dbh
-> query ( "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1237 AND owner_uid = " . $_SESSION [ "uid" ]);
1241 $this -> dbh
-> query ( "COMMIT" );
1244 function removeCat () {
1245 $ids = explode ( "," , $this -> dbh
-> escape_string ( $_REQUEST [ "ids" ]));
1246 foreach ( $ids as $id ) {
1247 $this -> remove_feed_category ( $id , $_SESSION [ "uid" ]);
1252 $feed_cat = $this -> dbh
-> escape_string ( trim ( $_REQUEST [ "cat" ]));
1254 add_feed_category ( $feed_cat );
1259 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
1260 print "<div id= \" pref-feeds-feeds \" dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Feeds' ). " \" >" ;
1262 $result = $this -> dbh
-> query ( "SELECT COUNT(id) AS num_errors
1263 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION [ "uid" ]);
1265 $num_errors = $this -> dbh
-> fetch_result ( $result , 0 , "num_errors" );
1267 if ( $num_errors > 0 ) {
1269 $error_button = "<button dojoType= \" dijit.form.Button \"
1270 onclick= \" showFeedsWithErrors() \" id= \" errorButton \" >" .
1271 __ ( "Feeds with errors" ) . "</button>" ;
1274 if ( DB_TYPE
== "pgsql" ) {
1275 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1277 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1280 $result = $this -> dbh
-> query ( "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
1281 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1282 ttrss_entries.id = ref_id AND
1283 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1284 ttrss_feeds.owner_uid = " . $_SESSION [ "uid" ]);
1286 $num_inactive = $this -> dbh
-> fetch_result ( $result , 0 , "num_inactive" );
1288 if ( $num_inactive > 0 ) {
1289 $inactive_button = "<button dojoType= \" dijit.form.Button \"
1290 onclick= \" showInactiveFeeds() \" >" .
1291 __ ( "Inactive feeds" ) . "</button>" ;
1294 $feed_search = $this -> dbh
-> escape_string ( $_REQUEST [ "search" ]);
1296 if ( array_key_exists ( "search" , $_REQUEST )) {
1297 $_SESSION [ "prefs_feed_search" ] = $feed_search ;
1299 $feed_search = $_SESSION [ "prefs_feed_search" ];
1302 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
1304 print "<div region='top' dojoType= \" dijit.Toolbar \" >" ; #toolbar
1306 print "<div style='float : right; padding-right : 4px;'>
1307 <input dojoType= \" dijit.form.TextBox \" id= \" feed_search \" size= \" 20 \" type= \" search \"
1308 value= \" $feed_search\" >
1309 <button dojoType= \" dijit.form.Button \" onclick= \" updateFeedList() \" >" .
1310 __ ( 'Search' ). "</button>
1313 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1314 "<span>" . __ ( 'Select' ). "</span>" ;
1315 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1316 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(true) \"
1317 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1318 print "<div onclick= \" dijit.byId('feedTree').model.setAllChecked(false) \"
1319 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1320 print "</div></div>" ;
1322 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1323 "<span>" . __ ( 'Feeds' ). "</span>" ;
1324 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1325 print "<div onclick= \" quickAddFeed() \"
1326 dojoType= \" dijit.MenuItem \" >" . __ ( 'Subscribe to feed' ). "</div>" ;
1327 print "<div onclick= \" editSelectedFeed() \"
1328 dojoType= \" dijit.MenuItem \" >" . __ ( 'Edit selected feeds' ). "</div>" ;
1329 print "<div onclick= \" resetFeedOrder() \"
1330 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1331 print "<div onclick= \" batchSubscribe() \"
1332 dojoType= \" dijit.MenuItem \" >" . __ ( 'Batch subscribe' ). "</div>" ;
1333 print "<div dojoType= \" dijit.MenuItem \" onclick= \" removeSelectedFeeds() \" >"
1334 . __ ( 'Unsubscribe' ). "</div> " ;
1335 print "</div></div>" ;
1337 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1338 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1339 "<span>" . __ ( 'Categories' ). "</span>" ;
1340 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1341 print "<div onclick= \" createCategory() \"
1342 dojoType= \" dijit.MenuItem \" >" . __ ( 'Add category' ). "</div>" ;
1343 print "<div onclick= \" resetCatOrder() \"
1344 dojoType= \" dijit.MenuItem \" >" . __ ( 'Reset sort order' ). "</div>" ;
1345 print "<div onclick= \" removeSelectedCategories() \"
1346 dojoType= \" dijit.MenuItem \" >" . __ ( 'Remove selected' ). "</div>" ;
1347 print "</div></div>" ;
1351 print $error_button ;
1352 print $inactive_button ;
1354 print "<button onclick= \" toggleHiddenFeedCats() \"
1355 dojoType= \" dijit.form.Button \" >" . __ ( '(Un)hide empty categories' ). "</button>" ;
1357 if ( defined ( '_ENABLE_FEED_DEBUGGING' )) {
1359 print "<select id= \" feedActionChooser \" onchange= \" feedActionChange() \" >
1360 <option value= \" facDefault \" selected>" . __ ( 'More actions...' ). "</option>" ;
1362 if ( FORCE_ARTICLE_PURGE
== 0 ) {
1364 "<option value= \" facPurge \" >" . __ ( 'Manual purge' ). "</option>" ;
1368 <option value= \" facClear \" >" . __ ( 'Clear feed data' ). "</option>
1369 <option value= \" facRescore \" >" . __ ( 'Rescore articles' ). "</option>" ;
1375 print "</div>" ; # toolbar
1378 print '<div dojoType="dijit.layout.ContentPane" region="center">' ;
1380 print "<div id= \" feedlistLoading \" >
1381 <img src='images/indicator_tiny.gif'>" .
1382 __ ( "Loading, please wait..." ). "</div>" ;
1384 print "<div dojoType= \" fox.PrefFeedStore \" jsId= \" feedStore \"
1385 url= \" backend.php?op=pref-feeds&method=getfeedtree \" >
1387 <div dojoType= \" lib.CheckBoxStoreModel \" jsId= \" feedModel \" store= \" feedStore \"
1388 query= \" {id:'root'} \" rootId= \" root \" rootLabel= \" Feeds \"
1389 childrenAttrs= \" items \" checkboxStrict= \" false \" checkboxAll= \" false \" >
1391 <div dojoType= \" fox.PrefFeedTree \" id= \" feedTree \"
1392 dndController= \" dijit.tree.dndSource \"
1393 betweenThreshold= \" 5 \"
1394 model= \" feedModel \" openOnClick= \" false \" >
1395 <script type= \" dojo/method \" event= \" onClick \" args= \" item \" >
1396 var id = String(item.id);
1397 var bare_id = id.substr(id.indexOf(':')+1);
1399 if (id.match('FEED:')) {
1401 } else if (id.match('CAT:')) {
1402 editCat(bare_id, item);
1405 <script type= \" dojo/method \" event= \" onLoad \" args= \" item \" >
1406 Element.hide( \" feedlistLoading \" );
1410 # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1411 # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1417 print "</div>" ; # feeds pane
1419 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'OPML' ). " \" >" ;
1421 print "<p>" . __ ( "Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings." ) . " " ;
1423 print __ ( "Only main settings profile can be migrated using OPML." ) . "</p>" ;
1425 print "<iframe id= \" upload_iframe \"
1426 name= \" upload_iframe \" onload= \" opmlImportComplete(this) \"
1427 style= \" width: 400px; height: 100px; display: none; \" ></iframe>" ;
1429 print "<form name= \" opml_form \" style='display : block' target= \" upload_iframe \"
1430 enctype= \" multipart/form-data \" method= \" POST \"
1431 action= \" backend.php \" >
1432 <input id= \" opml_file \" name= \" opml_file \" type= \" file \" >
1433 <input type= \" hidden \" name= \" op \" value= \" dlg \" >
1434 <input type= \" hidden \" name= \" method \" value= \" importOpml \" >
1435 <button dojoType= \" dijit.form.Button \" onclick= \" return opmlImport(); \" type= \" submit \" >" .
1436 __ ( 'Import my OPML' ) . "</button>" ;
1440 print "<p>" . __ ( 'Filename:' ) .
1441 " <input type= \" text \" id= \" filename \" value= \" TinyTinyRSS.opml \" /> " .
1442 __ ( 'Include settings' ) . "<input type= \" checkbox \" id= \" settings \" checked= \" 1 \" />" ;
1444 print "</p><button dojoType= \" dijit.form.Button \"
1445 onclick= \" gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked) \" >" .
1446 __ ( 'Export OPML' ) . "</button></p></form>" ;
1450 print "<p>" . __ ( 'Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.' ) . " " ;
1452 print __ ( "Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds." ) . "</p>" ;
1454 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "Public OPML URL" ). "','pubOPMLUrl') \" >" .
1455 __ ( 'Display published OPML URL' ). "</button> " ;
1457 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1458 "hook_prefs_tab_section" , "prefFeedsOPML" );
1460 print "</div>" ; # pane
1462 if ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], "Firefox" ) !== false ) {
1464 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Firefox integration' ). " \" >" ;
1466 print "<p>" . __ ( 'This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.' ) . "</p>" ;
1470 print "<button onclick='window.navigator.registerContentHandler(" .
1471 " \" application/vnd.mozilla.maybe.feed \" , " .
1472 " \" " . add_feed_url () . " \" , " . " \" Tiny Tiny RSS \" )'>" .
1473 __ ( 'Click here to register this site as a feed reader.' ) .
1478 print "</div>" ; # pane
1481 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Published & shared articles / Generated feeds' ). " \" >" ;
1483 print "<h3>" . __ ( "Published articles and generated feeds" ) . "</h3>" ;
1485 print "<p>" . __ ( 'Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.' ). "</p>" ;
1487 $rss_url = '-2::' . htmlspecialchars ( get_self_url_prefix () .
1488 "/public.php?op=rss&id=-2&view-mode=all_articles" );;
1490 print "<button dojoType= \" dijit.form.Button \" onclick= \" return displayDlg('" . __ ( "View as RSS" ). "','generatedFeed', ' $rss_url ') \" >" .
1491 __ ( 'Display URL' ). "</button> " ;
1493 print "<button dojoType= \" dijit.form.Button \" onclick= \" return clearFeedAccessKeys() \" >" .
1494 __ ( 'Clear all generated URLs' ). "</button> " ;
1496 print "<h3>" . __ ( "Articles shared by URL" ) . "</h3>" ;
1498 print "<p>" . __ ( "You can disable all articles shared by unique URLs here." ) . "</p>" ;
1500 print "<button dojoType= \" dijit.form.Button \" onclick= \" return clearArticleAccessKeys() \" >" .
1501 __ ( 'Unshare all articles' ). "</button> " ;
1503 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
1504 "hook_prefs_tab_section" , "prefFeedsPublishedGenerated" );
1506 print "</div>" ; #pane
1508 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
1509 "hook_prefs_tab" , "prefFeeds" );
1511 print "</div>" ; #container
1514 private function feedlist_init_cat ( $cat_id ) {
1516 $cat_id = ( int ) $cat_id ;
1519 $cat_unread = ccache_find ( $cat_id , $_SESSION [ "uid" ], true );
1520 } else if ( $cat_id == 0 ||
$cat_id == - 2 ) {
1521 $cat_unread = getCategoryUnread ( $cat_id );
1524 $obj [ 'id' ] = 'CAT:' . $cat_id ;
1525 $obj [ 'items' ] = array ();
1526 $obj [ 'name' ] = getCategoryTitle ( $cat_id );
1527 $obj [ 'type' ] = 'category' ;
1528 $obj [ 'unread' ] = ( int ) $cat_unread ;
1529 $obj [ 'bare_id' ] = $cat_id ;
1534 private function feedlist_init_feed ( $feed_id , $title = false , $unread = false , $error = '' , $updated = '' ) {
1536 $feed_id = ( int ) $feed_id ;
1539 $title = getFeedTitle ( $feed_id , false );
1541 if ( $unread === false )
1542 $unread = getFeedUnread ( $feed_id , false );
1544 $obj [ 'id' ] = 'FEED:' . $feed_id ;
1545 $obj [ 'name' ] = $title ;
1546 $obj [ 'unread' ] = ( int ) $unread ;
1547 $obj [ 'type' ] = 'feed' ;
1548 $obj [ 'error' ] = $error ;
1549 $obj [ 'updated' ] = $updated ;
1550 $obj [ 'icon' ] = getFeedIcon ( $feed_id );
1551 $obj [ 'bare_id' ] = $feed_id ;
1556 function inactiveFeeds () {
1558 if ( DB_TYPE
== "pgsql" ) {
1559 $interval_qpart = "NOW() - INTERVAL '3 months'" ;
1561 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)" ;
1564 $result = $this -> dbh
-> query ( "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
1565 ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
1566 FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
1567 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1568 ttrss_entries.id = ref_id AND
1569 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
1570 AND ttrss_feeds.owner_uid = " . $_SESSION [ "uid" ]. " AND
1571 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1572 ttrss_entries.id = ref_id
1573 GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
1574 ORDER BY last_article" );
1576 print "<h2" . __ ( "These feeds have not been updated with new content for 3 months (oldest first):" ) . "</h2>" ;
1578 print "<div dojoType= \" dijit.Toolbar \" >" ;
1579 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1580 "<span>" . __ ( 'Select' ). "</span>" ;
1581 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1582 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'all') \"
1583 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1584 print "<div onclick= \" selectTableRows('prefInactiveFeedList', 'none') \"
1585 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1586 print "</div></div>" ;
1587 print "</div>" ; #toolbar
1589 print "<div class= \" inactiveFeedHolder \" >" ;
1591 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefInactiveFeedList \" >" ;
1595 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1597 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
1598 $feed_id = $line [ "id" ];
1599 $this_row_id = "id= \" FUPDD- $feed_id\" " ;
1601 # class needed for selectTableRows()
1602 print "<tr class= \" placeholder \" $this_row_id >" ;
1604 $edit_title = htmlspecialchars ( $line [ "title" ]);
1606 # id needed for selectTableRows()
1607 print "<td width='5%' align='center'><input
1608 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1609 type= \" checkbox \" id= \" FUPDC- $feed_id\" ></td>" ;
1612 print "<a class= \" visibleLink \" href= \" # \" " .
1613 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1614 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1615 htmlspecialchars ( $line [ "title" ]). "</a>" ;
1617 print "</td><td class= \" insensitive \" align='right'>" ;
1618 print make_local_datetime ( $line [ 'last_article' ], false );
1628 print "<div class='dlgButtons'>" ;
1629 print "<div style='float : left'>" ;
1630 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').removeSelected() \" >"
1631 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1634 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('inactiveFeedsDlg').hide() \" >" .
1635 __ ( 'Close this window' ). "</button>" ;
1641 function feedsWithErrors () {
1642 print "<h2>" . __ ( "These feeds have not been updated because of errors:" ) .
1645 $result = $this -> dbh
-> query ( "SELECT id,title,feed_url,last_error,site_url
1646 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION [ "uid" ]);
1648 print "<div dojoType= \" dijit.Toolbar \" >" ;
1649 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
1650 "<span>" . __ ( 'Select' ). "</span>" ;
1651 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
1652 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'all') \"
1653 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1654 print "<div onclick= \" selectTableRows('prefErrorFeedList', 'none') \"
1655 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1656 print "</div></div>" ;
1657 print "</div>" ; #toolbar
1659 print "<div class= \" inactiveFeedHolder \" >" ;
1661 print "<table width= \" 100% \" cellspacing= \" 0 \" id= \" prefErrorFeedList \" >" ;
1665 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1667 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
1668 $feed_id = $line [ "id" ];
1669 $this_row_id = "id= \" FERDD- $feed_id\" " ;
1671 # class needed for selectTableRows()
1672 print "<tr class= \" placeholder \" $this_row_id >" ;
1674 $edit_title = htmlspecialchars ( $line [ "title" ]);
1676 # id needed for selectTableRows()
1677 print "<td width='5%' align='center'><input
1678 onclick='toggleSelectRow2(this);' dojoType= \" dijit.form.CheckBox \"
1679 type= \" checkbox \" id= \" FERDC- $feed_id\" ></td>" ;
1682 print "<a class= \" visibleLink \" href= \" # \" " .
1683 "title= \" " . __ ( "Click to edit feed" ). " \" " .
1684 "onclick= \" editFeed(" . $line [ "id" ]. ") \" >" .
1685 htmlspecialchars ( $line [ "title" ]). "</a>: " ;
1687 print "<span class= \" insensitive \" >" ;
1688 print htmlspecialchars ( $line [ "last_error" ]);
1700 print "<div class='dlgButtons'>" ;
1701 print "<div style='float : left'>" ;
1702 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').removeSelected() \" >"
1703 . __ ( 'Unsubscribe from selected feeds' ). "</button> " ;
1706 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('errorFeedsDlg').hide() \" >" .
1707 __ ( 'Close this window' ). "</button>" ;
1713 * Purge a feed contents, marked articles excepted.
1715 * @param mixed $link The database connection.
1716 * @param integer $id The id of the feed to purge.
1719 private function clear_feed_articles ( $id ) {
1722 $result = $this -> dbh
-> query ( "DELETE FROM ttrss_user_entries
1723 WHERE feed_id = ' $id ' AND marked = false AND owner_uid = " . $_SESSION [ "uid" ]);
1725 $result = $this -> dbh
-> query ( "DELETE FROM ttrss_user_entries
1726 WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION [ "uid" ]);
1729 $result = $this -> dbh
-> query ( "DELETE FROM ttrss_entries WHERE
1730 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0" );
1732 ccache_update ( $id , $_SESSION [ 'uid' ]);
1733 } // function clear_feed_articles
1735 private function remove_feed_category ( $id , $owner_uid ) {
1737 $this -> dbh
-> query ( "DELETE FROM ttrss_feed_categories
1738 WHERE id = ' $id ' AND owner_uid = $owner_uid " );
1740 ccache_remove ( $id , $owner_uid , true );
1743 static function remove_feed ( $id , $owner_uid ) {
1747 /* save starred articles in Archived feed */
1751 /* prepare feed if necessary */
1753 $result = db_query ( "SELECT feed_url FROM ttrss_feeds WHERE id = $id
1754 AND owner_uid = $owner_uid " );
1756 $feed_url = db_escape_string ( db_fetch_result ( $result , 0 , "feed_url" ));
1758 $result = db_query ( "SELECT id FROM ttrss_archived_feeds
1759 WHERE feed_url = ' $feed_url ' AND owner_uid = $owner_uid " );
1761 if ( db_num_rows ( $result ) == 0 ) {
1762 $result = db_query ( "SELECT MAX(id) AS id FROM ttrss_archived_feeds" );
1763 $new_feed_id = ( int ) db_fetch_result ( $result , 0 , "id" ) +
1 ;
1765 db_query ( "INSERT INTO ttrss_archived_feeds
1766 (id, owner_uid, title, feed_url, site_url)
1767 SELECT $new_feed_id , owner_uid, title, feed_url, site_url from ttrss_feeds
1770 $archive_id = $new_feed_id ;
1772 $archive_id = db_fetch_result ( $result , 0 , "id" );
1775 db_query ( "UPDATE ttrss_user_entries SET feed_id = NULL,
1776 orig_feed_id = ' $archive_id ' WHERE feed_id = ' $id ' AND
1777 marked = true AND owner_uid = $owner_uid " );
1779 /* Remove access key for the feed */
1781 db_query ( "DELETE FROM ttrss_access_keys WHERE
1782 feed_id = ' $id ' AND owner_uid = $owner_uid " );
1784 /* remove the feed */
1786 db_query ( "DELETE FROM ttrss_feeds
1787 WHERE id = ' $id ' AND owner_uid = $owner_uid " );
1791 if ( file_exists ( ICONS_DIR
. "/ $id .ico" )) {
1792 unlink ( ICONS_DIR
. "/ $id .ico" );
1795 ccache_remove ( $id , $owner_uid );
1798 label_remove ( feed_to_label_id ( $id ), $owner_uid );
1799 //ccache_remove($id, $owner_uid); don't think labels are cached
1803 function batchSubscribe () {
1804 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-feeds \" >" ;
1805 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" batchaddfeeds \" >" ;
1807 print "<table width='100%'><tr><td>
1808 " . __ ( "Add one valid RSS feed per line (no feed detection is done)" ). "
1809 </td><td align='right'>" ;
1810 if ( get_pref ( 'ENABLE_FEED_CATS' )) {
1811 print __ ( 'Place in category:' ) . " " ;
1812 print_feed_cat_select ( "cat" , false , 'dojoType="dijit.form.Select"' );
1814 print "</td></tr><tr><td colspan='2'>" ;
1816 style='font-size : 12px; width : 100%; height: 200px;'
1817 placeHolder= \" " . __ ( "Feeds to subscribe, One per line" ). " \"
1818 dojoType= \" dijit.form.SimpleTextarea \" required= \" 1 \" name= \" feeds \" ></textarea>" ;
1820 print "</td></tr><tr><td colspan='2'>" ;
1822 print "<div id='feedDlg_loginContainer' style='display : none'>
1824 " <input dojoType= \" dijit.form.TextBox \" name='login' \"
1825 placeHolder= \" " . __ ( "Login" ). " \"
1826 style= \" width : 10em; \" > " .
1828 placeHolder= \" " . __ ( "Password" ). " \"
1829 dojoType= \" dijit.form.TextBox \" type='password'
1830 style= \" width : 10em; \" name='pass' \" >" .
1833 print "</td></tr><tr><td colspan='2'>" ;
1835 print "<div style= \" clear : both \" >
1836 <input type= \" checkbox \" name= \" need_auth \" dojoType= \" dijit.form.CheckBox \" id= \" feedDlg_loginCheck \"
1837 onclick='checkboxToggleElement(this, \" feedDlg_loginContainer \" )'>
1838 <label for= \" feedDlg_loginCheck \" >" .
1839 __ ( 'Feeds require authentication.' ). "</div>" ;
1843 print "</td></tr></table>" ;
1845 print "<div class= \" dlgButtons \" >
1846 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').execute() \" >" . __ ( 'Subscribe' ). "</button>
1847 <button dojoType= \" dijit.form.Button \" onclick= \" return dijit.byId('batchSubDlg').hide() \" >" . __ ( 'Cancel' ). "</button>
1851 function batchAddFeeds () {
1852 $cat_id = $this -> dbh
-> escape_string ( $_REQUEST [ 'cat' ]);
1853 $feeds = explode ( " \n " , $_REQUEST [ 'feeds' ]);
1854 $login = $this -> dbh
-> escape_string ( $_REQUEST [ 'login' ]);
1855 $pass = trim ( $_REQUEST [ 'pass' ]);
1857 foreach ( $feeds as $feed ) {
1858 $feed = $this -> dbh
-> escape_string ( trim ( $feed ));
1860 if ( validate_feed_url ( $feed )) {
1862 $this -> dbh
-> query ( "BEGIN" );
1864 if ( $cat_id == "0" ||
! $cat_id ) {
1865 $cat_qpart = "NULL" ;
1867 $cat_qpart = "' $cat_id '" ;
1870 $result = $this -> dbh
-> query (
1871 "SELECT id FROM ttrss_feeds
1872 WHERE feed_url = ' $feed ' AND owner_uid = " . $_SESSION [ "uid" ]);
1874 if ( strlen ( FEED_CRYPT_KEY
) > 0 ) {
1875 require_once "crypt.php" ;
1876 $pass = substr ( encrypt_string ( $pass ), 0 , 250 );
1877 $auth_pass_encrypted = 'true' ;
1879 $auth_pass_encrypted = 'false' ;
1882 $pass = $this -> dbh
-> escape_string ( $pass );
1884 if ( $this -> dbh
-> num_rows ( $result ) == 0 ) {
1885 $result = $this -> dbh
-> query (
1886 "INSERT INTO ttrss_feeds
1887 (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
1888 VALUES ('" . $_SESSION [ "uid" ]. "', ' $feed ',
1889 '[Unknown]', $cat_qpart , ' $login ', ' $pass ', 0, $auth_pass_encrypted )" );
1892 $this -> dbh
-> query ( "COMMIT" );
1897 function regenOPMLKey () {
1898 $this -> update_feed_access_key ( 'OPML:Publish' ,
1899 false , $_SESSION [ "uid" ]);
1901 $new_link = Opml
:: opml_publish_url ();
1903 print json_encode ( array ( "link" => $new_link ));
1906 function regenFeedKey () {
1907 $feed_id = $this -> dbh
-> escape_string ( $_REQUEST [ 'id' ]);
1908 $is_cat = $this -> dbh
-> escape_string ( $_REQUEST [ 'is_cat' ]) == "true" ;
1910 $new_key = $this -> update_feed_access_key ( $feed_id , $is_cat );
1912 print json_encode ( array ( "link" => $new_key ));
1916 private function update_feed_access_key ( $feed_id , $is_cat , $owner_uid = false ) {
1917 if (! $owner_uid ) $owner_uid = $_SESSION [ "uid" ];
1919 $sql_is_cat = bool_to_sql_bool ( $is_cat );
1921 $result = $this -> dbh
-> query ( "SELECT access_key FROM ttrss_access_keys
1922 WHERE feed_id = ' $feed_id ' AND is_cat = $sql_is_cat
1923 AND owner_uid = " . $owner_uid );
1925 if ( $this -> dbh
-> num_rows ( $result ) == 1 ) {
1926 $key = $this -> dbh
-> escape_string ( sha1 ( uniqid ( rand (), true )));
1928 $this -> dbh
-> query ( "UPDATE ttrss_access_keys SET access_key = ' $key '
1929 WHERE feed_id = ' $feed_id ' AND is_cat = $sql_is_cat
1930 AND owner_uid = " . $owner_uid );
1935 return get_feed_access_key ( $feed_id , $is_cat , $owner_uid );
1940 function clearKeys () {
1941 $this -> dbh
-> query ( "DELETE FROM ttrss_access_keys WHERE
1942 owner_uid = " . $_SESSION [ "uid" ]);