]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var notify_silent
= false ;
2 var loading_progress
= 0 ;
3 var sanity_check_done
= false ;
5 var _label_base_index
= - 1024 ;
7 Ajax
. Base
. prototype . initialize
= Ajax
. Base
. prototype . initialize
. wrap (
8 function ( callOriginal
, options
) {
10 if ( getInitParam ( "csrf_token" ) != undefined ) {
11 Object
. extend ( options
, options
|| { });
13 if ( Object
. isString ( options
. parameters
))
14 options
. parameters
= options
. parameters
. toQueryParams ();
15 else if ( Object
. isHash ( options
. parameters
))
16 options
. parameters
= options
. parameters
. toObject ();
18 options
. parameters
[ "csrf_token" ] = getInitParam ( "csrf_token" );
21 return callOriginal ( options
);
25 /* add method to remove element from array */
27 Array
. prototype . remove = function ( s
) {
28 for ( var i
= 0 ; i
< this . length
; i
++) {
29 if ( s
== this [ i
]) this . splice ( i
, 1 );
33 /* create console.log if it doesn't exist */
35 if (! window
. console
) console
= {};
36 console
. log
= console
. log
|| function ( msg
) { };
37 console
. warn
= console
. warn
|| function ( msg
) { };
38 console
. error
= console
. error
|| function ( msg
) { };
40 function exception_error ( location
, e
, ext_info
) {
41 var msg
= format_exception_error ( location
, e
);
43 if (! ext_info
) ext_info
= false ;
48 if ( ext_info
. responseText
) {
49 ext_info
= ext_info
. responseText
;
53 var content
= "<div class= \" fatalError \" >" +
54 "<pre>" + msg
+ "</pre>" ;
56 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
57 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
59 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
60 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
63 content
+= "<div><b>Additional information:</b></div>" +
64 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
67 content
+= "<div><b>Stack trace:</b></div>" +
68 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
74 content
+= "<div class='dlgButtons'>" ;
76 content
+= "<button dojoType= \" dijit.form.Button \" " +
77 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
78 __ ( 'Report to tt-rss.org' ) + "</button> " ;
79 content
+= "<button dojoType= \" dijit.form.Button \" " +
80 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
81 __ ( 'Close' ) + "</button>" ;
84 if ( dijit
. byId ( "exceptionDlg" ))
85 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
87 var dialog
= new dijit
. Dialog ({
89 title
: "Unhandled exception" ,
90 style
: "width: 600px" ,
92 if ( confirm ( __ ( "Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database." ))) {
94 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
95 browserName
: navigator
. appName
,
96 browserVersion
: navigator
. appVersion
,
97 browserPlatform
: navigator
. platform
,
98 browserCookies
: navigator
. cookieEnabled
,
101 document
. forms
[ 'exceptionForm' ]. submit ();
115 function format_exception_error ( location
, e
) {
119 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
121 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
122 " \n Function: " + location
+ "()" +
123 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
125 } else if ( e
. description
) {
126 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
128 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
131 console
. error ( "EXCEPTION: " + msg
);
136 function param_escape ( arg
) {
137 if ( typeof encodeURIComponent
!= 'undefined' )
138 return encodeURIComponent ( arg
);
143 function param_unescape ( arg
) {
144 if ( typeof decodeURIComponent
!= 'undefined' )
145 return decodeURIComponent ( arg
);
147 return unescape ( arg
);
150 var notify_hide_timerid
= false ;
152 function hide_notify () {
155 n
. style
. display
= "none" ;
159 function notify_silent_next () {
160 notify_silent
= true ;
163 function notify_real ( msg
, no_hide
, n_type
) {
166 notify_silent
= false ;
171 var nb
= $( "notify_body" );
173 if (! n
|| ! nb
) return ;
175 if ( notify_hide_timerid
) {
176 window
. clearTimeout ( notify_hide_timerid
);
180 if ( n
. style
. display
== "block" ) {
181 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
185 n
. style
. display
= "block" ;
200 n
. className
= "notify" ;
201 } else if ( n_type
== 2 ) {
202 n
. className
= "notify progress" ;
203 msg
= "<img src='images/indicator_white.gif'> " + msg
;
204 } else if ( n_type
== 3 ) {
205 n
. className
= "notify error" ;
206 msg
= "<img src='images/sign_excl.svg'> " + msg
;
207 } else if ( n_type
== 4 ) {
208 n
. className
= "notify info" ;
209 msg
= "<img src='images/sign_info.svg'> " + msg
;
213 msg
+= " <span>(<a href='#' onclick= \" notify('') \" >" +
214 __ ( "close" ) + "</a>)</span>" ;
218 // msg = "<img src='images/live_com_loading.gif'> " + msg;
223 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 3000 );
227 function notify ( msg
, no_hide
) {
228 notify_real ( msg
, no_hide
, 1 );
231 function notify_progress ( msg
, no_hide
) {
232 notify_real ( msg
, no_hide
, 2 );
235 function notify_error ( msg
, no_hide
) {
236 notify_real ( msg
, no_hide
, 3 );
240 function notify_info ( msg
, no_hide
) {
241 notify_real ( msg
, no_hide
, 4 );
244 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
250 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
253 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
255 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
259 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
260 document
. cookie
= name
+ "=" + escape ( value
) +
261 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
262 (( path
) ? "; path=" + path
: "" ) +
263 (( domain
) ? "; domain=" + domain
: "" ) +
264 (( secure
) ? "; secure" : "" );
267 function delCookie ( name
, path
, domain
) {
268 if ( getCookie ( name
)) {
269 document
. cookie
= name
+ "=" +
270 (( path
) ? ";path=" + path
: "" ) +
271 (( domain
) ? ";domain=" + domain
: "" ) +
272 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
277 function getCookie ( name
) {
279 var dc
= document
. cookie
;
280 var prefix
= name
+ "=" ;
281 var begin
= dc
. indexOf ( "; " + prefix
);
283 begin
= dc
. indexOf ( prefix
);
284 if ( begin
!= 0 ) return null ;
289 var end
= document
. cookie
. indexOf ( ";" , begin
);
293 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
296 function gotoPreferences () {
297 document
. location
. href
= "prefs.php" ;
300 function gotoLogout () {
301 document
. location
. href
= "backend.php?op=logout" ;
304 function gotoMain () {
305 document
. location
. href
= "index.php" ;
308 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
309 * * @author Sundar Dorai-Raj
310 * * Email: sdoraira@vt.edu
311 * * This program is free software; you can redistribute it and/or
312 * * modify it under the terms of the GNU General Public License
313 * * as published by the Free Software Foundation; either version 2
314 * * of the License, or (at your option) any later version,
315 * * provided that any use properly credits the author.
316 * * This program is distributed in the hope that it will be useful,
317 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
318 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
319 * * GNU General Public License for more details at http://www.gnu.org * * */
321 var numbers
= ".0123456789" ;
322 function isNumeric ( x
) {
323 // is x a String or a character?
325 // remove negative sign
327 for ( var j
= 0 ; j
< x
. length
; j
++) {
328 // call isNumeric recursively for each character
329 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
330 if (! number
) return number
;
335 // if x is number return true
336 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
342 function toggleSelectRowById ( sender
, id
) {
344 return toggleSelectRow ( sender
, row
);
347 function toggleSelectListRow ( sender
) {
348 var row
= sender
. parentNode
;
349 return toggleSelectRow ( sender
, row
);
352 /* this is for dijit Checkbox */
353 function toggleSelectListRow2 ( sender
) {
354 var row
= sender
. domNode
. parentNode
;
355 return toggleSelectRow ( sender
, row
);
358 /* this is for dijit Checkbox */
359 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
363 row
= sender
. domNode
. parentNode
. parentNode
;
365 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
367 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
368 row
. addClassName ( 'Selected' );
370 row
. removeClassName ( 'Selected' );
372 if ( typeof updateSelectedPrompt
!= undefined )
373 updateSelectedPrompt ();
377 function toggleSelectRow ( sender
, row
) {
379 if (! row
) row
= sender
. parentNode
. parentNode
;
381 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
382 row
. addClassName ( 'Selected' );
384 row
. removeClassName ( 'Selected' );
386 if ( typeof updateSelectedPrompt
!= undefined )
387 updateSelectedPrompt ();
390 function checkboxToggleElement ( elem
, id
) {
392 Effect
. Appear ( id
, { duration
: 0.5 });
394 Effect
. Fade ( id
, { duration
: 0.5 });
398 function dropboxSelect ( e
, v
) {
399 for ( var i
= 0 ; i
< e
. length
; i
++) {
400 if ( e
[ i
]. value
== v
) {
407 function getURLParam ( param
){
408 return String ( window
. location
. href
). parseQuery ()[ param
];
411 function closeInfoBox ( cleanup
) {
413 dialog
= dijit
. byId ( "infoBox" );
415 if ( dialog
) dialog
. hide ();
418 //exception_error("closeInfoBox", e);
424 function displayDlg ( title
, id
, param
, callback
) {
426 notify_progress ( "Loading, please wait..." , true );
428 var query
= "?op=dlg&method=" +
429 param_escape ( id
) + "¶m=" + param_escape ( param
);
431 new Ajax
. Request ( "backend.php" , {
433 onComplete : function ( transport
) {
434 infobox_callback2 ( transport
, title
);
435 if ( callback
) callback ( transport
);
441 function infobox_callback2 ( transport
, title
) {
445 if ( dijit
. byId ( "infoBox" )) {
446 dialog
= dijit
. byId ( "infoBox" );
449 //console.log("infobox_callback2");
452 var content
= transport
. responseText
;
455 dialog
= new dijit
. Dialog ({
458 style
: "width: 600px" ,
459 onCancel : function () {
462 onExecute : function () {
465 onClose : function () {
470 dialog
. attr ( 'title' , title
);
471 dialog
. attr ( 'content' , content
);
478 exception_error ( "infobox_callback2" , e
);
482 function filterCR ( e
, f
)
487 key
= window
. event
. keyCode
; //IE
489 key
= e
. which
; //firefox
492 if ( typeof f
!= 'undefined' ) {
503 function getInitParam ( key
) {
504 return init_params
[ key
];
507 function setInitParam ( key
, value
) {
508 init_params
[ key
] = value
;
511 function fatalError ( code
, msg
, ext_info
) {
515 window
. location
. href
= "index.php" ;
516 } else if ( code
== 5 ) {
517 window
. location
. href
= "public.php?op=dbupdate" ;
520 if ( msg
== "" ) msg
= "Unknown error" ;
523 if ( ext_info
. responseText
) {
524 ext_info
= ext_info
. responseText
;
528 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
532 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
533 "<p>" + msg
+ "</p>" ;
536 content
= content
+ "<div><b>Additional information:</b></div>" +
537 "<textarea style='width: 100%' readonly= \" 1 \" >" +
538 ext_info
+ "</textarea>" ;
541 var dialog
= new dijit
. Dialog ({
542 title
: "Fatal error" ,
543 style
: "width: 600px" ,
553 exception_error ( "fatalError" , e
);
557 function filterDlgCheckAction ( sender
) {
561 var action
= sender
. value
;
563 var action_param
= $( "filterDlg_paramBox" );
566 console
. log ( "filterDlgCheckAction: can't find action param box!" );
570 // if selected action supports parameters, enable params field
571 if ( action
== 4 || action
== 6 || action
== 7 ) {
572 new Effect
. Appear ( action_param
, { duration
: 0.5 });
574 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
575 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
577 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
578 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
581 Element
. hide ( action_param
);
585 exception_error ( "filterDlgCheckAction" , e
);
591 function explainError ( code
) {
592 return displayDlg ( __ ( "Error explained" ), "explainError" , code
);
595 function loading_set_progress ( p
) {
597 loading_progress
+= p
;
599 if ( dijit
. byId ( "loading_bar" ))
600 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
602 if ( loading_progress
>= 90 )
606 exception_error ( "loading_set_progress" , e
);
610 function remove_splash () {
612 if ( Element
. visible ( "overlay" )) {
613 console
. log ( "about to remove splash, OMG!" );
614 Element
. hide ( "overlay" );
615 console
. log ( "removed splash!" );
619 function transport_error_check ( transport
) {
621 if ( transport
. responseXML
) {
622 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
625 var code
= error
. getAttribute ( "error-code" );
626 var msg
= error
. getAttribute ( "error-msg" );
628 fatalError ( code
, msg
);
634 exception_error ( "check_for_error_xml" , e
);
639 function strip_tags ( s
) {
640 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
643 function truncate_string ( s
, length
) {
644 if (! length
) length
= 30 ;
645 var tmp
= s
. substring ( 0 , length
);
646 if ( s
. length
> length
) tmp
+= "…" ;
650 function hotkey_prefix_timeout () {
653 var date
= new Date ();
654 var ts
= Math
. round ( date
. getTime () / 1000 );
656 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
657 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
658 hotkey_prefix_pressed
= false ;
659 hotkey_prefix
= false ;
660 Element
. hide ( 'cmdline' );
663 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
666 exception_error ( "hotkey_prefix_timeout" , e
);
670 function uploadIconHandler ( rc
) {
674 notify_info ( "Upload complete." );
675 if ( inPreferences ()) {
678 setTimeout ( 'updateFeedList(false, false)' , 50 );
682 notify_error ( "Upload failed: icon is too big." );
685 notify_error ( "Upload failed." );
690 exception_error ( "uploadIconHandler" , e
);
694 function removeFeedIcon ( id
) {
698 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
699 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
703 notify_progress ( "Removing feed icon..." , true );
705 new Ajax
. Request ( "backend.php" , {
707 onComplete : function ( transport
) {
708 notify_info ( "Feed icon removed." );
709 if ( inPreferences ()) {
712 setTimeout ( 'updateFeedList(false, false)' , 50 );
719 exception_error ( "removeFeedIcon" , e
);
723 function uploadFeedIcon () {
727 var file
= $( "icon_file" );
729 if ( file
. value
. length
== 0 ) {
730 alert ( __ ( "Please select an image file to upload." ));
732 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
733 notify_progress ( "Uploading, please wait..." , true );
741 exception_error ( "uploadFeedIcon" , e
);
745 function addLabel ( select
, callback
) {
749 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
751 if ( caption
!= undefined ) {
754 alert ( __ ( "Can't create label: missing caption." ));
758 var query
= "?op=pref-labels&method=add&caption=" +
759 param_escape ( caption
);
762 query
+= "&output=select" ;
764 notify_progress ( "Loading, please wait..." , true );
766 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
768 new Ajax
. Request ( "backend.php" , {
770 onComplete : function ( transport
) {
773 } else if ( inPreferences ()) {
783 exception_error ( "addLabel" , e
);
787 function quickAddFeed () {
789 var query
= "backend.php?op=feeds&method=quickAddFeed" ;
791 // overlapping widgets
792 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
793 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
795 var dialog
= new dijit
. Dialog ({
797 title
: __ ( "Subscribe to Feed" ),
798 style
: "width: 600px" ,
799 execute : function () {
800 if ( this . validate ()) {
801 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
803 var feed_url
= this . attr ( 'value' ). feed
;
805 Element
. show ( "feed_add_spinner" );
807 new Ajax
. Request ( "backend.php" , {
808 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
809 onComplete : function ( transport
) {
812 var reply
= JSON
. parse ( transport
. responseText
);
814 var rc
= reply
[ 'result' ];
817 Element
. hide ( "feed_add_spinner" );
821 switch ( parseInt ( rc
[ 'code' ])) {
824 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
829 alert ( __ ( "Specified URL seems to be invalid." ));
832 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
835 /* notify_progress("Searching for feed urls...", true);
837 new Ajax.Request("backend.php", {
838 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
839 onComplete: function(transport, dialog, feed_url) {
843 var reply = JSON.parse(transport.responseText);
845 var feeds = reply['urls'];
847 console.log(transport.responseText);
849 var select = dijit.byId("feedDlg_feedContainerSelect");
851 while (select.getOptions().length > 0)
852 select.removeOption(0);
855 for (var feedUrl in feeds) {
856 select.addOption({value: feedUrl, label: feeds[feedUrl]});
860 // if (count > 5) count = 5;
861 // select.size = count;
863 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
870 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
872 while ( select
. getOptions (). length
> 0 )
873 select
. removeOption ( 0 );
875 select
. addOption ({ value
: '' , label
: __ ( "Expand to select feed" )});
878 for ( var feedUrl
in feeds
) {
879 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
883 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
887 alert ( __ ( "Couldn't download the specified URL: %s" ).
888 replace ( "%s" , rc
[ 'message' ]));
891 alert ( __ ( "You are already subscribed to this feed." ));
896 exception_error ( "subscribeToFeed" , e
, transport
);
907 exception_error ( "quickAddFeed" , e
);
911 function createNewRuleElement ( parentNode
, replaceNode
) {
913 var form
= document
. forms
[ "filter_new_rule_form" ];
915 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
917 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
918 param_escape ( dojo
. formToJson ( form
));
922 new Ajax
. Request ( "backend.php" , {
924 onComplete : function ( transport
) {
926 var li
= dojo
. create ( "li" );
928 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
930 new dijit
. form
. CheckBox ({
931 onChange : function () {
932 toggleSelectListRow2 ( this ) },
935 dojo
. create ( "input" , { type
: "hidden" ,
937 value
: dojo
. formToJson ( form
) }, li
);
939 dojo
. create ( "span" , {
940 onclick : function () {
941 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
943 innerHTML
: transport
. responseText
}, li
);
946 parentNode
. replaceChild ( li
, replaceNode
);
948 parentNode
. appendChild ( li
);
951 exception_error ( "createNewRuleElement" , e
);
955 exception_error ( "createNewRuleElement" , e
);
959 function createNewActionElement ( parentNode
, replaceNode
) {
961 var form
= document
. forms
[ "filter_new_action_form" ];
963 if ( form
. action_id
. value
== 7 ) {
964 form
. action_param
. value
= form
. action_param_label
. value
;
967 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
968 param_escape ( dojo
. formToJson ( form
));
972 new Ajax
. Request ( "backend.php" , {
974 onComplete : function ( transport
) {
976 var li
= dojo
. create ( "li" );
978 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
980 new dijit
. form
. CheckBox ({
981 onChange : function () {
982 toggleSelectListRow2 ( this ) },
985 dojo
. create ( "input" , { type
: "hidden" ,
987 value
: dojo
. formToJson ( form
) }, li
);
989 dojo
. create ( "span" , {
990 onclick : function () {
991 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
993 innerHTML
: transport
. responseText
}, li
);
996 parentNode
. replaceChild ( li
, replaceNode
);
998 parentNode
. appendChild ( li
);
1002 exception_error ( "createNewActionElement" , e
);
1006 exception_error ( "createNewActionElement" , e
);
1011 function addFilterRule ( replaceNode
, ruleStr
) {
1013 if ( dijit
. byId ( "filterNewRuleDlg" ))
1014 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1016 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1017 param_escape ( ruleStr
);
1019 var rule_dlg
= new dijit
. Dialog ({
1020 id
: "filterNewRuleDlg" ,
1021 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1022 style
: "width: 600px" ,
1023 execute : function () {
1024 if ( this . validate ()) {
1025 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1033 exception_error ( "addFilterRule" , e
);
1037 function addFilterAction ( replaceNode
, actionStr
) {
1039 if ( dijit
. byId ( "filterNewActionDlg" ))
1040 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1042 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1043 param_escape ( actionStr
);
1045 var rule_dlg
= new dijit
. Dialog ({
1046 id
: "filterNewActionDlg" ,
1047 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1048 style
: "width: 600px" ,
1049 execute : function () {
1050 if ( this . validate ()) {
1051 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1059 exception_error ( "addFilterAction" , e
);
1063 function quickAddFilter () {
1066 if (! inPreferences ()) {
1067 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1068 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1069 param_escape ( activeFeedIsCat ());
1071 query
= "backend.php?op=pref-filters&method=newfilter" ;
1076 if ( dijit
. byId ( "feedEditDlg" ))
1077 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1079 if ( dijit
. byId ( "filterEditDlg" ))
1080 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1082 dialog
= new dijit
. Dialog ({
1083 id
: "filterEditDlg" ,
1084 title
: __ ( "Create Filter" ),
1085 style
: "width: 600px" ,
1087 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1089 if ( dijit
. byId ( "filterTestDlg" ))
1090 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1092 var test_dlg
= new dijit
. Dialog ({
1093 id
: "filterTestDlg" ,
1094 title
: "Test Filter" ,
1095 style
: "width: 600px" ,
1100 selectRules : function ( select
) {
1101 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1104 e
. parentNode
. addClassName ( "Selected" );
1106 e
. parentNode
. removeClassName ( "Selected" );
1109 selectActions : function ( select
) {
1110 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1114 e
. parentNode
. addClassName ( "Selected" );
1116 e
. parentNode
. removeClassName ( "Selected" );
1120 editRule : function ( e
) {
1121 var li
= e
. parentNode
;
1122 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1123 addFilterRule ( li
, rule
);
1125 editAction : function ( e
) {
1126 var li
= e
. parentNode
;
1127 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1128 addFilterAction ( li
, action
);
1130 addAction : function () { addFilterAction (); },
1131 addRule : function () { addFilterRule (); },
1132 deleteAction : function () {
1133 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1135 deleteRule : function () {
1136 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1138 execute : function () {
1139 if ( this . validate ()) {
1141 var query
= dojo
. formToQuery ( "filter_new_form" );
1145 new Ajax
. Request ( "backend.php" , {
1147 onComplete : function ( transport
) {
1148 if ( inPreferences ()) {
1158 if (! inPreferences ()) {
1159 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1160 dojo
. disconnect ( lh
);
1162 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1164 new Ajax
. Request ( "backend.php" , {
1166 onComplete : function ( transport
) {
1167 var reply
= JSON
. parse ( transport
. responseText
);
1171 if ( reply
&& reply
) title
= reply
. title
;
1173 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1175 console
. log ( title
+ " " + getActiveFeedId ());
1177 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1180 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1182 addFilterRule ( null , dojo
. toJson ( rule
));
1193 exception_error ( "quickAddFilter" , e
);
1197 function resetPubSub ( feed_id
, title
) {
1199 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1201 if ( title
== undefined || confirm ( msg
)) {
1202 notify_progress ( "Loading, please wait..." );
1204 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1206 new Ajax
. Request ( "backend.php" , {
1208 onComplete : function ( transport
) {
1209 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1210 notify_info ( "Subscription reset." );
1218 function unsubscribeFeed ( feed_id
, title
) {
1220 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1222 if ( title
== undefined || confirm ( msg
)) {
1223 notify_progress ( "Removing feed..." );
1225 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1227 new Ajax
. Request ( "backend.php" , {
1229 onComplete : function ( transport
) {
1231 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1233 if ( inPreferences ()) {
1236 if ( feed_id
== getActiveFeedId ())
1237 setTimeout ( "viewfeed(-5)" , 100 );
1239 if ( feed_id
< 0 ) updateFeedList ();
1249 function backend_sanity_check_callback ( transport
) {
1253 if ( sanity_check_done
) {
1254 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1255 "presence of Firebug or some other disrupting extension. " +
1256 "Please disable it and try again." );
1260 var reply
= JSON
. parse ( transport
. responseText
);
1263 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1267 var error_code
= reply
[ 'error' ][ 'code' ];
1269 if ( error_code
&& error_code
!= 0 ) {
1270 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1273 console
. log ( "sanity check ok" );
1275 var params
= reply
[ 'init-params' ];
1278 console
. log ( 'reading init-params...' );
1283 console
. log ( "IP: " + k
+ " => " + v
);
1285 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1289 init_params
= params
;
1292 sanity_check_done
= true ;
1294 init_second_stage ();
1297 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1301 /*function has_local_storage() {
1303 return 'sessionStorage' in window && window['sessionStorage'] != null;
1309 function catSelectOnChange ( elem
) {
1311 /* var value = elem[elem.selectedIndex].value;
1312 var def = elem.getAttribute('default');
1314 if (value == "ADD_CAT") {
1317 dropboxSelect(elem, def);
1319 elem.selectedIndex = 0;
1325 exception_error ( "catSelectOnChange" , e
);
1329 function quickAddCat ( elem
) {
1331 var cat
= prompt ( __ ( "Please enter category title:" ));
1335 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1337 notify_progress ( "Loading, please wait..." , true );
1339 new Ajax
. Request ( "backend.php" , {
1341 onComplete : function ( transport
) {
1342 var response
= transport
. responseXML
;
1343 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1344 var options
= select
. getElementsByTagName ( "option" );
1346 dropbox_replace_options ( elem
, options
);
1355 exception_error ( "quickAddCat" , e
);
1359 function genUrlChangeKey ( feed
, is_cat
) {
1362 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1366 notify_progress ( "Trying to change address..." , true );
1368 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape ( feed
) +
1369 "&is_cat=" + param_escape ( is_cat
);
1371 new Ajax
. Request ( "backend.php" , {
1373 onComplete : function ( transport
) {
1374 var reply
= JSON
. parse ( transport
. responseText
);
1375 var new_link
= reply
. link
;
1377 var e
= $( 'gen_feed_url' );
1381 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1382 "&key=" + new_link
);
1384 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1385 "&key=" + new_link
);
1387 new Effect
. Highlight ( e
);
1392 notify_error ( "Could not change feed URL." );
1397 exception_error ( "genUrlChangeKey" , e
);
1402 function labelSelectOnChange ( elem
) {
1404 /* var value = elem[elem.selectedIndex].value;
1405 var def = elem.getAttribute('default');
1407 if (value == "ADD_LABEL") {
1410 dropboxSelect(elem, def);
1412 elem.selectedIndex = 0;
1414 addLabel(elem, function(transport) {
1418 var response = transport.responseXML;
1419 var select = response.getElementsByTagName("select")[0];
1420 var options = select.getElementsByTagName("option");
1422 dropbox_replace_options(elem, options);
1426 exception_error("addLabel", e);
1432 exception_error ( "labelSelectOnChange" , e
);
1436 function dropbox_replace_options ( elem
, options
) {
1439 while ( elem
. hasChildNodes ())
1440 elem
. removeChild ( elem
. firstChild
);
1444 for ( var i
= 0 ; i
< options
. length
; i
++) {
1445 var text
= options
[ i
]. firstChild
. nodeValue
;
1446 var value
= options
[ i
]. getAttribute ( "value" );
1448 if ( value
== undefined ) value
= text
;
1450 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1452 var option
= new Option ( text
, value
, issel
);
1454 if ( options
[ i
]. getAttribute ( "disabled" ))
1455 option
. setAttribute ( "disabled" , true );
1457 elem
. insert ( option
);
1459 if ( issel
) sel_idx
= i
;
1462 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1463 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1466 exception_error ( "dropbox_replace_options" , e
);
1470 // mode = all, none, invert
1471 function selectTableRows ( id
, mode
) {
1473 var rows
= $( id
). rows
;
1475 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1480 if ( row
. id
&& row
. className
) {
1481 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1482 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1484 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1485 var input
= inputs
[ j
];
1487 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1488 input
. id
. match ( bare_id
)) {
1491 dcb
= dijit
. getEnclosingWidget ( cb
);
1497 var issel
= row
. hasClassName ( "Selected" );
1499 if ( mode
== "all" && ! issel
) {
1500 row
. addClassName ( "Selected" );
1502 if ( dcb
) dcb
. set ( "checked" , true );
1503 } else if ( mode
== "none" && issel
) {
1504 row
. removeClassName ( "Selected" );
1506 if ( dcb
) dcb
. set ( "checked" , false );
1508 } else if ( mode
== "invert" ) {
1511 row
. removeClassName ( "Selected" );
1513 if ( dcb
) dcb
. set ( "checked" , false );
1515 row
. addClassName ( "Selected" );
1517 if ( dcb
) dcb
. set ( "checked" , true );
1525 exception_error ( "selectTableRows" , e
);
1530 function getSelectedTableRowIds ( id
) {
1534 var elem_rows
= $( id
). rows
;
1536 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1537 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1538 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1544 exception_error ( "getSelectedTableRowIds" , e
);
1550 function editFeed ( feed
, event
) {
1553 return alert ( __ ( "You can't edit this kind of feed." ));
1555 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1560 if ( dijit
. byId ( "filterEditDlg" ))
1561 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1563 if ( dijit
. byId ( "feedEditDlg" ))
1564 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1566 dialog
= new dijit
. Dialog ({
1568 title
: __ ( "Edit Feed" ),
1569 style
: "width: 600px" ,
1570 execute : function () {
1571 if ( this . validate ()) {
1572 // console.log(dojo.objectToQuery(this.attr('value')));
1574 notify_progress ( "Saving data..." , true );
1576 new Ajax
. Request ( "backend.php" , {
1577 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1578 onComplete : function ( transport
) {
1590 exception_error ( "editFeed" , e
);
1594 function feedBrowser () {
1596 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1598 if ( dijit
. byId ( "feedAddDlg" ))
1599 dijit
. byId ( "feedAddDlg" ). hide ();
1601 if ( dijit
. byId ( "feedBrowserDlg" ))
1602 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1604 var dialog
= new dijit
. Dialog ({
1605 id
: "feedBrowserDlg" ,
1606 title
: __ ( "More Feeds" ),
1607 style
: "width: 600px" ,
1608 getSelectedFeedIds : function () {
1609 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1610 var selected
= new Array ();
1612 list
. each ( function ( child
) {
1613 var id
= child
. id
. replace ( "FBROW-" , "" );
1615 if ( child
. hasClassName ( 'Selected' )) {
1622 getSelectedFeeds : function () {
1623 var list
= $$( "#browseFeedList li.Selected" );
1624 var selected
= new Array ();
1626 list
. each ( function ( child
) {
1627 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1628 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1630 selected
. push ([ title
, url
]);
1637 subscribe : function () {
1638 var mode
= this . attr ( 'value' ). mode
;
1642 selected
= this . getSelectedFeeds ();
1644 selected
= this . getSelectedFeedIds ();
1646 if ( selected
. length
> 0 ) {
1647 dijit
. byId ( "feedBrowserDlg" ). hide ();
1649 notify_progress ( "Loading, please wait..." , true );
1651 // we use dojo.toJson instead of JSON.stringify because
1652 // it somehow escapes everything TWICE, at least in Chrome 9
1654 var query
= "?op=rpc&method=massSubscribe&payload=" +
1655 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1659 new Ajax
. Request ( "backend.php" , {
1661 onComplete : function ( transport
) {
1667 alert ( __ ( "No feeds are selected." ));
1671 update : function () {
1672 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1674 Element
. show ( 'feed_browser_spinner' );
1676 new Ajax
. Request ( "backend.php" , {
1678 onComplete : function ( transport
) {
1681 Element
. hide ( 'feed_browser_spinner' );
1683 var c
= $( "browseFeedList" );
1685 var reply
= JSON
. parse ( transport
. responseText
);
1687 var r
= reply
[ 'content' ];
1688 var mode
= reply
[ 'mode' ];
1694 dojo
. parser
. parse ( "browseFeedList" );
1697 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1699 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1704 removeFromArchive : function () {
1705 var selected
= this . getSelectedFeedIds ();
1707 if ( selected
. length
> 0 ) {
1709 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1712 Element
. show ( 'feed_browser_spinner' );
1714 var query
= "?op=rpc&method=remarchive&ids=" +
1715 param_escape ( selected
. toString ());;
1717 new Ajax
. Request ( "backend.php" , {
1719 onComplete : function ( transport
) {
1725 execute : function () {
1726 if ( this . validate ()) {
1735 exception_error ( "editFeed" , e
);
1739 function showFeedsWithErrors () {
1741 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1743 if ( dijit
. byId ( "errorFeedsDlg" ))
1744 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1746 dialog
= new dijit
. Dialog ({
1747 id
: "errorFeedsDlg" ,
1748 title
: __ ( "Feeds with update errors" ),
1749 style
: "width: 600px" ,
1750 getSelectedFeeds : function () {
1751 return getSelectedTableRowIds ( "prefErrorFeedList" );
1753 removeSelected : function () {
1754 var sel_rows
= this . getSelectedFeeds ();
1756 console
. log ( sel_rows
);
1758 if ( sel_rows
. length
> 0 ) {
1759 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1762 notify_progress ( "Removing selected feeds..." , true );
1764 var query
= "?op=pref-feeds&method=remove&ids=" +
1765 param_escape ( sel_rows
. toString ());
1767 new Ajax
. Request ( "backend.php" , {
1769 onComplete : function ( transport
) {
1777 alert ( __ ( "No feeds are selected." ));
1780 execute : function () {
1781 if ( this . validate ()) {
1789 exception_error ( "showFeedsWithErrors" , e
);
1794 /* new support functions for SelectByTag */
1796 function get_all_tags ( selObj
){
1798 if ( ! selObj
) return "" ;
1801 var len
= selObj
. options
. length
;
1803 for ( var i
= 0 ; i
< len
; i
++){
1804 if ( selObj
. options
[ i
]. selected
) {
1805 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1809 if ( result
. length
> 0 ){
1810 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1816 exception_error ( "get_all_tags" , e
);
1820 function get_radio_checked ( radioObj
) {
1822 if (! radioObj
) return "" ;
1824 var len
= radioObj
. length
;
1826 if ( len
== undefined ){
1827 if ( radioObj
. checked
){
1828 return ( radioObj
. value
);
1834 for ( var i
= 0 ; i
< len
; i
++ ){
1835 if ( radioObj
[ i
]. checked
){
1836 return ( radioObj
[ i
]. value
);
1841 exception_error ( "get_radio_checked" , e
);
1846 function get_timestamp () {
1847 var date
= new Date ();
1848 return Math
. round ( date
. getTime () / 1000 );
1851 function helpDialog ( topic
) {
1853 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1855 if ( dijit
. byId ( "helpDlg" ))
1856 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1858 dialog
= new dijit
. Dialog ({
1861 style
: "width: 600px" ,
1868 exception_error ( "helpDialog" , e
);
1872 function htmlspecialchars_decode ( string
, quote_style
) {
1873 // http://kevin.vanzonneveld.net
1874 // + original by: Mirek Slugen
1875 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1876 // + bugfixed by: Mateusz "loonquawl" Zalega
1877 // + input by: ReverseSyntax
1878 // + input by: Slawomir Kaniecki
1879 // + input by: Scott Cariss
1880 // + input by: Francois
1881 // + bugfixed by: Onno Marsman
1882 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1883 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1884 // + input by: Ratheous
1885 // + input by: Mailfaker (http://www.weedem.fr/)
1886 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1887 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1888 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1889 // * returns 1: '<p>this -> "</p>'
1890 // * example 2: htmlspecialchars_decode("&quot;");
1891 // * returns 2: '"'
1895 if ( typeof quote_style
=== 'undefined' ) {
1898 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1901 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1902 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1907 if ( quote_style
=== 0 ) {
1910 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1911 quote_style
= []. concat ( quote_style
);
1912 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1913 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1914 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1916 } else if ( OPTS
[ quote_style
[ i
]]) {
1917 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1920 quote_style
= optTemp
;
1922 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1923 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1924 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1927 string
= string
. replace ( /"/g , '"' );
1929 // Put this in last place to avoid escape being double-decoded
1930 string
= string
. replace ( /&/g , '&' );
1936 function label_to_feed_id ( label
) {
1937 return _label_base_index
- 1 - Math
. abs ( label
);
1940 function feed_to_label_id ( feed
) {
1941 return _label_base_index
- 1 + Math
. abs ( feed
);