]>
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' );
374 function toggleSelectRow ( sender
, row
) {
376 if (! row
) row
= sender
. parentNode
. parentNode
;
378 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
379 row
. addClassName ( 'Selected' );
381 row
. removeClassName ( 'Selected' );
384 function checkboxToggleElement ( elem
, id
) {
386 Effect
. Appear ( id
, { duration
: 0.5 });
388 Effect
. Fade ( id
, { duration
: 0.5 });
392 function dropboxSelect ( e
, v
) {
393 for ( var i
= 0 ; i
< e
. length
; i
++) {
394 if ( e
[ i
]. value
== v
) {
401 function getURLParam ( param
){
402 return String ( window
. location
. href
). parseQuery ()[ param
];
405 function closeInfoBox ( cleanup
) {
407 dialog
= dijit
. byId ( "infoBox" );
409 if ( dialog
) dialog
. hide ();
412 //exception_error("closeInfoBox", e);
418 function displayDlg ( title
, id
, param
, callback
) {
420 notify_progress ( "Loading, please wait..." , true );
422 var query
= "?op=dlg&method=" +
423 param_escape ( id
) + "¶m=" + param_escape ( param
);
425 new Ajax
. Request ( "backend.php" , {
427 onComplete : function ( transport
) {
428 infobox_callback2 ( transport
, title
);
429 if ( callback
) callback ( transport
);
435 function infobox_callback2 ( transport
, title
) {
439 if ( dijit
. byId ( "infoBox" )) {
440 dialog
= dijit
. byId ( "infoBox" );
443 //console.log("infobox_callback2");
446 var content
= transport
. responseText
;
449 dialog
= new dijit
. Dialog ({
452 style
: "width: 600px" ,
453 onCancel : function () {
456 onExecute : function () {
459 onClose : function () {
464 dialog
. attr ( 'title' , title
);
465 dialog
. attr ( 'content' , content
);
472 exception_error ( "infobox_callback2" , e
);
476 function filterCR ( e
, f
)
481 key
= window
. event
. keyCode
; //IE
483 key
= e
. which
; //firefox
486 if ( typeof f
!= 'undefined' ) {
497 function getInitParam ( key
) {
498 return init_params
[ key
];
501 function setInitParam ( key
, value
) {
502 init_params
[ key
] = value
;
505 function fatalError ( code
, msg
, ext_info
) {
509 window
. location
. href
= "index.php" ;
510 } else if ( code
== 5 ) {
511 window
. location
. href
= "db-updater.php" ;
514 if ( msg
== "" ) msg
= "Unknown error" ;
517 if ( ext_info
. responseText
) {
518 ext_info
= ext_info
. responseText
;
522 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
526 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
527 "<p>" + msg
+ "</p>" ;
530 content
= content
+ "<div><b>Additional information:</b></div>" +
531 "<textarea style='width: 100%' readonly= \" 1 \" >" +
532 ext_info
+ "</textarea>" ;
535 var dialog
= new dijit
. Dialog ({
536 title
: "Fatal error" ,
537 style
: "width: 600px" ,
547 exception_error ( "fatalError" , e
);
551 /* function filterDlgCheckType(sender) {
555 var ftype = sender.value;
557 // if selected filter type is 5 (Date) enable the modifier dropbox
559 Element.show("filterDlg_dateModBox");
560 Element.show("filterDlg_dateChkBox");
562 Element.hide("filterDlg_dateModBox");
563 Element.hide("filterDlg_dateChkBox");
568 exception_error("filterDlgCheckType", e);
573 function filterDlgCheckAction ( sender
) {
577 var action
= sender
. value
;
579 var action_param
= $( "filterDlg_paramBox" );
582 console
. log ( "filterDlgCheckAction: can't find action param box!" );
586 // if selected action supports parameters, enable params field
587 if ( action
== 4 || action
== 6 || action
== 7 ) {
588 new Effect
. Appear ( action_param
, { duration
: 0.5 });
590 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
591 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
593 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
594 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
597 Element
. hide ( action_param
);
601 exception_error ( "filterDlgCheckAction" , e
);
606 function filterDlgCheckDate () {
608 var dialog
= dijit
. byId ( "filterEditDlg" );
610 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
612 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
614 new Ajax
. Request ( "backend.php" , {
616 onComplete : function ( transport
) {
618 var reply
= JSON
. parse ( transport
. responseText
);
620 if ( reply
[ 'result' ] == true ) {
621 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
624 alert ( __ ( "Date syntax is incorrect." ));
631 exception_error ( "filterDlgCheckDate" , e
);
635 function explainError ( code
) {
636 return displayDlg ( __ ( "Error explained" ), "explainError" , code
);
639 function loading_set_progress ( p
) {
641 loading_progress
+= p
;
643 if ( dijit
. byId ( "loading_bar" ))
644 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
646 if ( loading_progress
>= 90 )
650 exception_error ( "loading_set_progress" , e
);
654 function remove_splash () {
656 if ( Element
. visible ( "overlay" )) {
657 console
. log ( "about to remove splash, OMG!" );
658 Element
. hide ( "overlay" );
659 console
. log ( "removed splash!" );
663 function transport_error_check ( transport
) {
665 if ( transport
. responseXML
) {
666 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
669 var code
= error
. getAttribute ( "error-code" );
670 var msg
= error
. getAttribute ( "error-msg" );
672 fatalError ( code
, msg
);
678 exception_error ( "check_for_error_xml" , e
);
683 function strip_tags ( s
) {
684 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
687 function truncate_string ( s
, length
) {
688 if (! length
) length
= 30 ;
689 var tmp
= s
. substring ( 0 , length
);
690 if ( s
. length
> length
) tmp
+= "…" ;
694 function hotkey_prefix_timeout () {
697 var date
= new Date ();
698 var ts
= Math
. round ( date
. getTime () / 1000 );
700 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
701 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
702 hotkey_prefix_pressed
= false ;
703 hotkey_prefix
= false ;
704 Element
. hide ( 'cmdline' );
707 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
710 exception_error ( "hotkey_prefix_timeout" , e
);
714 function uploadIconHandler ( rc
) {
718 notify_info ( "Upload complete." );
719 if ( inPreferences ()) {
722 setTimeout ( 'updateFeedList(false, false)' , 50 );
726 notify_error ( "Upload failed: icon is too big." );
729 notify_error ( "Upload failed." );
734 exception_error ( "uploadIconHandler" , e
);
738 function removeFeedIcon ( id
) {
742 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
743 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
747 notify_progress ( "Removing feed icon..." , true );
749 new Ajax
. Request ( "backend.php" , {
751 onComplete : function ( transport
) {
752 notify_info ( "Feed icon removed." );
753 if ( inPreferences ()) {
756 setTimeout ( 'updateFeedList(false, false)' , 50 );
763 exception_error ( "removeFeedIcon" , e
);
767 function uploadFeedIcon () {
771 var file
= $( "icon_file" );
773 if ( file
. value
. length
== 0 ) {
774 alert ( __ ( "Please select an image file to upload." ));
776 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
777 notify_progress ( "Uploading, please wait..." , true );
785 exception_error ( "uploadFeedIcon" , e
);
789 function addLabel ( select
, callback
) {
793 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
795 if ( caption
!= undefined ) {
798 alert ( __ ( "Can't create label: missing caption." ));
802 var query
= "?op=pref-labels&method=add&caption=" +
803 param_escape ( caption
);
806 query
+= "&output=select" ;
808 notify_progress ( "Loading, please wait..." , true );
810 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
812 new Ajax
. Request ( "backend.php" , {
814 onComplete : function ( transport
) {
817 } else if ( inPreferences ()) {
827 exception_error ( "addLabel" , e
);
831 function quickAddFeed () {
833 var query
= "backend.php?op=feeds&method=quickAddFeed" ;
835 // overlapping widgets
836 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
837 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
839 var dialog
= new dijit
. Dialog ({
841 title
: __ ( "Subscribe to Feed" ),
842 style
: "width: 600px" ,
843 execute : function () {
844 if ( this . validate ()) {
845 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
847 var feed_url
= this . attr ( 'value' ). feed
;
849 Element
. show ( "feed_add_spinner" );
851 new Ajax
. Request ( "backend.php" , {
852 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
853 onComplete : function ( transport
) {
856 var reply
= JSON
. parse ( transport
. responseText
);
858 var rc
= reply
[ 'result' ];
861 Element
. hide ( "feed_add_spinner" );
863 console
. log ( "GOT RC: " + rc
);
865 switch ( parseInt ( rc
[ 'code' ])) {
868 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
873 alert ( __ ( "Specified URL seems to be invalid." ));
876 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
879 /* notify_progress("Searching for feed urls...", true);
881 new Ajax.Request("backend.php", {
882 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
883 onComplete: function(transport, dialog, feed_url) {
887 var reply = JSON.parse(transport.responseText);
889 var feeds = reply['urls'];
891 console.log(transport.responseText);
893 var select = dijit.byId("feedDlg_feedContainerSelect");
895 while (select.getOptions().length > 0)
896 select.removeOption(0);
899 for (var feedUrl in feeds) {
900 select.addOption({value: feedUrl, label: feeds[feedUrl]});
904 // if (count > 5) count = 5;
905 // select.size = count;
907 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
914 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
916 while ( select
. getOptions (). length
> 0 )
917 select
. removeOption ( 0 );
920 for ( var feedUrl
in feeds
) {
921 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
925 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
929 alert ( __ ( "Couldn't download the specified URL: %s" ).
930 replace ( "%s" , rc
[ 'message' ]));
933 alert ( __ ( "You are already subscribed to this feed." ));
938 exception_error ( "subscribeToFeed" , e
, transport
);
949 exception_error ( "quickAddFeed" , e
);
953 function createNewRuleElement ( parentNode
, replaceNode
) {
955 var form
= document
. forms
[ "filter_new_rule_form" ];
957 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
959 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
960 param_escape ( dojo
. formToJson ( form
));
964 new Ajax
. Request ( "backend.php" , {
966 onComplete : function ( transport
) {
968 var li
= dojo
. create ( "li" );
970 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
972 new dijit
. form
. CheckBox ({
973 onChange : function () {
974 toggleSelectListRow2 ( this ) },
977 dojo
. create ( "input" , { type
: "hidden" ,
979 value
: dojo
. formToJson ( form
) }, li
);
981 dojo
. create ( "span" , {
982 onclick : function () {
983 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
985 innerHTML
: transport
. responseText
}, li
);
988 parentNode
. replaceChild ( li
, replaceNode
);
990 parentNode
. appendChild ( li
);
993 exception_error ( "createNewRuleElement" , e
);
997 exception_error ( "createNewRuleElement" , e
);
1001 function createNewActionElement ( parentNode
, replaceNode
) {
1003 var form
= document
. forms
[ "filter_new_action_form" ];
1005 if ( form
. action_id
. value
== 7 ) {
1006 form
. action_param
. value
= form
. action_param_label
. value
;
1009 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
1010 param_escape ( dojo
. formToJson ( form
));
1014 new Ajax
. Request ( "backend.php" , {
1016 onComplete : function ( transport
) {
1018 var li
= dojo
. create ( "li" );
1020 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
1022 new dijit
. form
. CheckBox ({
1023 onChange : function () {
1024 toggleSelectListRow2 ( this ) },
1027 dojo
. create ( "input" , { type
: "hidden" ,
1029 value
: dojo
. formToJson ( form
) }, li
);
1031 dojo
. create ( "span" , {
1032 onclick : function () {
1033 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
1035 innerHTML
: transport
. responseText
}, li
);
1038 parentNode
. replaceChild ( li
, replaceNode
);
1040 parentNode
. appendChild ( li
);
1044 exception_error ( "createNewActionElement" , e
);
1048 exception_error ( "createNewActionElement" , e
);
1053 function addFilterRule ( replaceNode
, ruleStr
) {
1055 if ( dijit
. byId ( "filterNewRuleDlg" ))
1056 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1058 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1059 param_escape ( ruleStr
);
1061 var rule_dlg
= new dijit
. Dialog ({
1062 id
: "filterNewRuleDlg" ,
1063 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1064 style
: "width: 600px" ,
1065 execute : function () {
1066 if ( this . validate ()) {
1067 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1075 exception_error ( "addFilterRule" , e
);
1079 function addFilterAction ( replaceNode
, actionStr
) {
1081 if ( dijit
. byId ( "filterNewActionDlg" ))
1082 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1084 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1085 param_escape ( actionStr
);
1087 var rule_dlg
= new dijit
. Dialog ({
1088 id
: "filterNewActionDlg" ,
1089 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1090 style
: "width: 600px" ,
1091 execute : function () {
1092 if ( this . validate ()) {
1093 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1101 exception_error ( "addFilterAction" , e
);
1105 function quickAddFilter () {
1108 if (! inPreferences ()) {
1109 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1110 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1111 param_escape ( activeFeedIsCat ());
1113 query
= "backend.php?op=pref-filters&method=newfilter" ;
1118 if ( dijit
. byId ( "feedEditDlg" ))
1119 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1121 if ( dijit
. byId ( "filterEditDlg" ))
1122 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1124 dialog
= new dijit
. Dialog ({
1125 id
: "filterEditDlg" ,
1126 title
: __ ( "Create Filter" ),
1127 style
: "width: 600px" ,
1129 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1131 if ( dijit
. byId ( "filterTestDlg" ))
1132 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1134 var test_dlg
= new dijit
. Dialog ({
1135 id
: "filterTestDlg" ,
1136 title
: "Test Filter" ,
1137 style
: "width: 600px" ,
1142 selectRules : function ( select
) {
1143 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1146 e
. parentNode
. addClassName ( "Selected" );
1148 e
. parentNode
. removeClassName ( "Selected" );
1151 selectActions : function ( select
) {
1152 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1156 e
. parentNode
. addClassName ( "Selected" );
1158 e
. parentNode
. removeClassName ( "Selected" );
1162 editRule : function ( e
) {
1163 var li
= e
. parentNode
;
1164 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1165 addFilterRule ( li
, rule
);
1167 editAction : function ( e
) {
1168 var li
= e
. parentNode
;
1169 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1170 addFilterAction ( li
, action
);
1172 addAction : function () { addFilterAction (); },
1173 addRule : function () { addFilterRule (); },
1174 deleteAction : function () {
1175 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1177 deleteRule : function () {
1178 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1180 execute : function () {
1181 if ( this . validate ()) {
1183 var query
= dojo
. formToQuery ( "filter_new_form" );
1187 new Ajax
. Request ( "backend.php" , {
1189 onComplete : function ( transport
) {
1190 if ( inPreferences ()) {
1200 if (! inPreferences ()) {
1201 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1202 dojo
. disconnect ( lh
);
1204 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1206 new Ajax
. Request ( "backend.php" , {
1208 onComplete : function ( transport
) {
1209 var reply
= JSON
. parse ( transport
. responseText
);
1213 if ( reply
&& reply
) title
= reply
. title
;
1215 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1217 console
. log ( title
+ " " + getActiveFeedId ());
1219 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1222 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1224 addFilterRule ( null , dojo
. toJson ( rule
));
1235 exception_error ( "quickAddFilter" , e
);
1239 function resetPubSub ( feed_id
, title
) {
1241 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1243 if ( title
== undefined || confirm ( msg
)) {
1244 notify_progress ( "Loading, please wait..." );
1246 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1248 new Ajax
. Request ( "backend.php" , {
1250 onComplete : function ( transport
) {
1251 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1252 notify_info ( "Subscription reset." );
1260 function unsubscribeFeed ( feed_id
, title
) {
1262 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1264 if ( title
== undefined || confirm ( msg
)) {
1265 notify_progress ( "Removing feed..." );
1267 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1269 new Ajax
. Request ( "backend.php" , {
1271 onComplete : function ( transport
) {
1273 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1275 if ( inPreferences ()) {
1278 if ( feed_id
== getActiveFeedId ())
1279 setTimeout ( "viewfeed(-5)" , 100 );
1281 if ( feed_id
< 0 ) updateFeedList ();
1291 function backend_sanity_check_callback ( transport
) {
1295 if ( sanity_check_done
) {
1296 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1297 "presence of Firebug or some other disrupting extension. " +
1298 "Please disable it and try again." );
1302 var reply
= JSON
. parse ( transport
. responseText
);
1305 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1309 var error_code
= reply
[ 'error' ][ 'code' ];
1311 if ( error_code
&& error_code
!= 0 ) {
1312 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1315 console
. log ( "sanity check ok" );
1317 var params
= reply
[ 'init-params' ];
1320 console
. log ( 'reading init-params...' );
1325 console
. log ( "IP: " + k
+ " => " + v
);
1327 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1331 init_params
= params
;
1334 sanity_check_done
= true ;
1336 init_second_stage ();
1339 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1343 /*function has_local_storage() {
1345 return 'sessionStorage' in window && window['sessionStorage'] != null;
1351 function catSelectOnChange ( elem
) {
1353 /* var value = elem[elem.selectedIndex].value;
1354 var def = elem.getAttribute('default');
1356 if (value == "ADD_CAT") {
1359 dropboxSelect(elem, def);
1361 elem.selectedIndex = 0;
1367 exception_error ( "catSelectOnChange" , e
);
1371 function quickAddCat ( elem
) {
1373 var cat
= prompt ( __ ( "Please enter category title:" ));
1377 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1379 notify_progress ( "Loading, please wait..." , true );
1381 new Ajax
. Request ( "backend.php" , {
1383 onComplete : function ( transport
) {
1384 var response
= transport
. responseXML
;
1385 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1386 var options
= select
. getElementsByTagName ( "option" );
1388 dropbox_replace_options ( elem
, options
);
1397 exception_error ( "quickAddCat" , e
);
1401 function genUrlChangeKey ( feed
, is_cat
) {
1404 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1408 notify_progress ( "Trying to change address..." , true );
1410 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1411 "&is_cat=" + param_escape ( is_cat
);
1413 new Ajax
. Request ( "backend.php" , {
1415 onComplete : function ( transport
) {
1416 var reply
= JSON
. parse ( transport
. responseText
);
1417 var new_link
= reply
. link
;
1419 var e
= $( 'gen_feed_url' );
1423 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1424 "&key=" + new_link
);
1426 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1427 "&key=" + new_link
);
1429 new Effect
. Highlight ( e
);
1434 notify_error ( "Could not change feed URL." );
1439 exception_error ( "genUrlChangeKey" , e
);
1444 function labelSelectOnChange ( elem
) {
1446 /* var value = elem[elem.selectedIndex].value;
1447 var def = elem.getAttribute('default');
1449 if (value == "ADD_LABEL") {
1452 dropboxSelect(elem, def);
1454 elem.selectedIndex = 0;
1456 addLabel(elem, function(transport) {
1460 var response = transport.responseXML;
1461 var select = response.getElementsByTagName("select")[0];
1462 var options = select.getElementsByTagName("option");
1464 dropbox_replace_options(elem, options);
1468 exception_error("addLabel", e);
1474 exception_error ( "labelSelectOnChange" , e
);
1478 function dropbox_replace_options ( elem
, options
) {
1481 while ( elem
. hasChildNodes ())
1482 elem
. removeChild ( elem
. firstChild
);
1486 for ( var i
= 0 ; i
< options
. length
; i
++) {
1487 var text
= options
[ i
]. firstChild
. nodeValue
;
1488 var value
= options
[ i
]. getAttribute ( "value" );
1490 if ( value
== undefined ) value
= text
;
1492 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1494 var option
= new Option ( text
, value
, issel
);
1496 if ( options
[ i
]. getAttribute ( "disabled" ))
1497 option
. setAttribute ( "disabled" , true );
1499 elem
. insert ( option
);
1501 if ( issel
) sel_idx
= i
;
1504 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1505 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1508 exception_error ( "dropbox_replace_options" , e
);
1512 // mode = all, none, invert
1513 function selectTableRows ( id
, mode
) {
1515 var rows
= $( id
). rows
;
1517 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1522 if ( row
. id
&& row
. className
) {
1523 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1524 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1526 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1527 var input
= inputs
[ j
];
1529 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1530 input
. id
. match ( bare_id
)) {
1533 dcb
= dijit
. getEnclosingWidget ( cb
);
1539 var issel
= row
. hasClassName ( "Selected" );
1541 if ( mode
== "all" && ! issel
) {
1542 row
. addClassName ( "Selected" );
1544 if ( dcb
) dcb
. set ( "checked" , true );
1545 } else if ( mode
== "none" && issel
) {
1546 row
. removeClassName ( "Selected" );
1548 if ( dcb
) dcb
. set ( "checked" , false );
1550 } else if ( mode
== "invert" ) {
1553 row
. removeClassName ( "Selected" );
1555 if ( dcb
) dcb
. set ( "checked" , false );
1557 row
. addClassName ( "Selected" );
1559 if ( dcb
) dcb
. set ( "checked" , true );
1567 exception_error ( "selectTableRows" , e
);
1572 function getSelectedTableRowIds ( id
) {
1576 var elem_rows
= $( id
). rows
;
1578 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1579 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1580 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1586 exception_error ( "getSelectedTableRowIds" , e
);
1592 function editFeed ( feed
, event
) {
1595 return alert ( __ ( "You can't edit this kind of feed." ));
1597 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1602 if ( dijit
. byId ( "filterEditDlg" ))
1603 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1605 if ( dijit
. byId ( "feedEditDlg" ))
1606 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1608 dialog
= new dijit
. Dialog ({
1610 title
: __ ( "Edit Feed" ),
1611 style
: "width: 600px" ,
1612 execute : function () {
1613 if ( this . validate ()) {
1614 // console.log(dojo.objectToQuery(this.attr('value')));
1616 notify_progress ( "Saving data..." , true );
1618 new Ajax
. Request ( "backend.php" , {
1619 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1620 onComplete : function ( transport
) {
1632 exception_error ( "editFeed" , e
);
1636 function feedBrowser () {
1638 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1640 if ( dijit
. byId ( "feedAddDlg" ))
1641 dijit
. byId ( "feedAddDlg" ). hide ();
1643 if ( dijit
. byId ( "feedBrowserDlg" ))
1644 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1646 var dialog
= new dijit
. Dialog ({
1647 id
: "feedBrowserDlg" ,
1648 title
: __ ( "More Feeds" ),
1649 style
: "width: 600px" ,
1650 getSelectedFeedIds : function () {
1651 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1652 var selected
= new Array ();
1654 list
. each ( function ( child
) {
1655 var id
= child
. id
. replace ( "FBROW-" , "" );
1657 if ( child
. hasClassName ( 'Selected' )) {
1664 getSelectedFeeds : function () {
1665 var list
= $$( "#browseFeedList li.Selected" );
1666 var selected
= new Array ();
1668 list
. each ( function ( child
) {
1669 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1670 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1672 selected
. push ([ title
, url
]);
1679 subscribe : function () {
1680 var mode
= this . attr ( 'value' ). mode
;
1684 selected
= this . getSelectedFeeds ();
1686 selected
= this . getSelectedFeedIds ();
1688 if ( selected
. length
> 0 ) {
1689 dijit
. byId ( "feedBrowserDlg" ). hide ();
1691 notify_progress ( "Loading, please wait..." , true );
1693 // we use dojo.toJson instead of JSON.stringify because
1694 // it somehow escapes everything TWICE, at least in Chrome 9
1696 var query
= "?op=rpc&method=massSubscribe&payload=" +
1697 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1701 new Ajax
. Request ( "backend.php" , {
1703 onComplete : function ( transport
) {
1709 alert ( __ ( "No feeds are selected." ));
1713 update : function () {
1714 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1716 Element
. show ( 'feed_browser_spinner' );
1718 new Ajax
. Request ( "backend.php" , {
1720 onComplete : function ( transport
) {
1723 Element
. hide ( 'feed_browser_spinner' );
1725 var c
= $( "browseFeedList" );
1727 var reply
= JSON
. parse ( transport
. responseText
);
1729 var r
= reply
[ 'content' ];
1730 var mode
= reply
[ 'mode' ];
1736 dojo
. parser
. parse ( "browseFeedList" );
1739 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1741 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1746 removeFromArchive : function () {
1747 var selected
= this . getSelectedFeedIds ();
1749 if ( selected
. length
> 0 ) {
1751 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1754 Element
. show ( 'feed_browser_spinner' );
1756 var query
= "?op=rpc&method=remarchive&ids=" +
1757 param_escape ( selected
. toString ());;
1759 new Ajax
. Request ( "backend.php" , {
1761 onComplete : function ( transport
) {
1767 execute : function () {
1768 if ( this . validate ()) {
1777 exception_error ( "editFeed" , e
);
1781 function showFeedsWithErrors () {
1783 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1785 if ( dijit
. byId ( "errorFeedsDlg" ))
1786 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1788 dialog
= new dijit
. Dialog ({
1789 id
: "errorFeedsDlg" ,
1790 title
: __ ( "Feeds with update errors" ),
1791 style
: "width: 600px" ,
1792 getSelectedFeeds : function () {
1793 return getSelectedTableRowIds ( "prefErrorFeedList" );
1795 removeSelected : function () {
1796 var sel_rows
= this . getSelectedFeeds ();
1798 console
. log ( sel_rows
);
1800 if ( sel_rows
. length
> 0 ) {
1801 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1804 notify_progress ( "Removing selected feeds..." , true );
1806 var query
= "?op=pref-feeds&method=remove&ids=" +
1807 param_escape ( sel_rows
. toString ());
1809 new Ajax
. Request ( "backend.php" , {
1811 onComplete : function ( transport
) {
1819 alert ( __ ( "No feeds are selected." ));
1822 execute : function () {
1823 if ( this . validate ()) {
1831 exception_error ( "showFeedsWithErrors" , e
);
1836 /* new support functions for SelectByTag */
1838 function get_all_tags ( selObj
){
1840 if ( ! selObj
) return "" ;
1843 var len
= selObj
. options
. length
;
1845 for ( var i
= 0 ; i
< len
; i
++){
1846 if ( selObj
. options
[ i
]. selected
) {
1847 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1851 if ( result
. length
> 0 ){
1852 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1858 exception_error ( "get_all_tags" , e
);
1862 function get_radio_checked ( radioObj
) {
1864 if (! radioObj
) return "" ;
1866 var len
= radioObj
. length
;
1868 if ( len
== undefined ){
1869 if ( radioObj
. checked
){
1870 return ( radioObj
. value
);
1876 for ( var i
= 0 ; i
< len
; i
++ ){
1877 if ( radioObj
[ i
]. checked
){
1878 return ( radioObj
[ i
]. value
);
1883 exception_error ( "get_radio_checked" , e
);
1888 function get_timestamp () {
1889 var date
= new Date ();
1890 return Math
. round ( date
. getTime () / 1000 );
1893 function helpDialog ( topic
) {
1895 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1897 if ( dijit
. byId ( "helpDlg" ))
1898 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1900 dialog
= new dijit
. Dialog ({
1903 style
: "width: 600px" ,
1910 exception_error ( "helpDialog" , e
);
1914 function htmlspecialchars_decode ( string
, quote_style
) {
1915 // http://kevin.vanzonneveld.net
1916 // + original by: Mirek Slugen
1917 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1918 // + bugfixed by: Mateusz "loonquawl" Zalega
1919 // + input by: ReverseSyntax
1920 // + input by: Slawomir Kaniecki
1921 // + input by: Scott Cariss
1922 // + input by: Francois
1923 // + bugfixed by: Onno Marsman
1924 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1925 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1926 // + input by: Ratheous
1927 // + input by: Mailfaker (http://www.weedem.fr/)
1928 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1929 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1930 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1931 // * returns 1: '<p>this -> "</p>'
1932 // * example 2: htmlspecialchars_decode("&quot;");
1933 // * returns 2: '"'
1937 if ( typeof quote_style
=== 'undefined' ) {
1940 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1943 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1944 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1949 if ( quote_style
=== 0 ) {
1952 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1953 quote_style
= []. concat ( quote_style
);
1954 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1955 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1956 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1958 } else if ( OPTS
[ quote_style
[ i
]]) {
1959 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1962 quote_style
= optTemp
;
1964 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1965 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1966 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1969 string
= string
. replace ( /"/g , '"' );
1971 // Put this in last place to avoid escape being double-decoded
1972 string
= string
. replace ( /&/g , '&' );
1978 function label_to_feed_id ( label
) {
1979 return _label_base_index
- 1 - Math
. abs ( label
);
1982 function feed_to_label_id ( feed
) {
1983 return _label_base_index
- 1 + Math
. abs ( feed
);