]>
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 ;
6 Ajax
. Base
. prototype . initialize
= Ajax
. Base
. prototype . initialize
. wrap (
7 function ( callOriginal
, options
) {
9 if ( getInitParam ( "csrf_token" ) != undefined ) {
10 Object
. extend ( options
, options
|| { });
12 if ( Object
. isString ( options
. parameters
))
13 options
. parameters
= options
. parameters
. toQueryParams ();
14 else if ( Object
. isHash ( options
. parameters
))
15 options
. parameters
= options
. parameters
. toObject ();
17 options
. parameters
[ "csrf_token" ] = getInitParam ( "csrf_token" );
20 return callOriginal ( options
);
24 /* add method to remove element from array */
26 Array
. prototype . remove = function ( s
) {
27 for ( var i
= 0 ; i
< this . length
; i
++) {
28 if ( s
== this [ i
]) this . splice ( i
, 1 );
32 /* create console.log if it doesn't exist */
34 if (! window
. console
) console
= {};
35 console
. log
= console
. log
|| function ( msg
) { };
36 console
. warn
= console
. warn
|| function ( msg
) { };
37 console
. error
= console
. error
|| function ( msg
) { };
39 function exception_error ( location
, e
, ext_info
) {
40 var msg
= format_exception_error ( location
, e
);
42 if (! ext_info
) ext_info
= false ;
47 if ( ext_info
. responseText
) {
48 ext_info
= ext_info
. responseText
;
52 var content
= "<div class= \" fatalError \" >" +
53 "<pre>" + msg
+ "</pre>" ;
55 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
56 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
58 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
59 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
62 content
+= "<div><b>Additional information:</b></div>" +
63 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
66 content
+= "<div><b>Stack trace:</b></div>" +
67 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
73 content
+= "<div class='dlgButtons'>" ;
75 content
+= "<button dojoType= \" dijit.form.Button \" " +
76 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
77 __ ( 'Report to tt-rss.org' ) + "</button> " ;
78 content
+= "<button dojoType= \" dijit.form.Button \" " +
79 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
80 __ ( 'Close' ) + "</button>" ;
83 if ( dijit
. byId ( "exceptionDlg" ))
84 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
86 var dialog
= new dijit
. Dialog ({
88 title
: "Unhandled exception" ,
89 style
: "width: 600px" ,
91 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." ))) {
93 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
94 browserName
: navigator
. appName
,
95 browserVersion
: navigator
. appVersion
,
96 browserPlatform
: navigator
. platform
,
97 browserCookies
: navigator
. cookieEnabled
,
100 document
. forms
[ 'exceptionForm' ]. submit ();
114 function format_exception_error ( location
, e
) {
118 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
120 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
121 " \n Function: " + location
+ "()" +
122 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
124 } else if ( e
. description
) {
125 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
127 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
130 console
. error ( "EXCEPTION: " + msg
);
135 function param_escape ( arg
) {
136 if ( typeof encodeURIComponent
!= 'undefined' )
137 return encodeURIComponent ( arg
);
142 function param_unescape ( arg
) {
143 if ( typeof decodeURIComponent
!= 'undefined' )
144 return decodeURIComponent ( arg
);
146 return unescape ( arg
);
149 var notify_hide_timerid
= false ;
151 function hide_notify () {
154 n
. style
. display
= "none" ;
158 function notify_silent_next () {
159 notify_silent
= true ;
162 function notify_real ( msg
, no_hide
, n_type
) {
165 notify_silent
= false ;
170 var nb
= $( "notify_body" );
172 if (! n
|| ! nb
) return ;
174 if ( notify_hide_timerid
) {
175 window
. clearTimeout ( notify_hide_timerid
);
179 if ( n
. style
. display
== "block" ) {
180 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
184 n
. style
. display
= "block" ;
196 if ( typeof __
!= 'undefined' ) {
201 n
. className
= "notify" ;
202 } else if ( n_type
== 2 ) {
203 n
. className
= "notifyProgress" ;
204 msg
= "<img src='images/indicator_white.gif'> " + msg
;
205 } else if ( n_type
== 3 ) {
206 n
. className
= "notifyError" ;
207 msg
= "<img src='images/sign_excl.svg'> " + msg
;
208 } else if ( n_type
== 4 ) {
209 n
. className
= "notifyInfo" ;
210 msg
= "<img src='images/sign_info.svg'> " + msg
;
213 // msg = "<img src='images/live_com_loading.gif'> " + msg;
216 msg
+= " (<a href='#' onclick= \" notify('') \" >X</a>)" ;
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 ( 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
);
429 if ( callback
) callback ( transport
);
435 function infobox_callback2 ( transport
) {
439 if ( dijit
. byId ( "infoBox" )) {
440 dialog
= dijit
. byId ( "infoBox" );
443 //console.log("infobox_callback2");
446 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
448 title
= title
. firstChild
. nodeValue
;
450 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
452 content
= content
. firstChild
. nodeValue
;
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
= "db-updater.php" ;
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 filterDlgCheckType(sender) {
561 var ftype = sender.value;
563 // if selected filter type is 5 (Date) enable the modifier dropbox
565 Element.show("filterDlg_dateModBox");
566 Element.show("filterDlg_dateChkBox");
568 Element.hide("filterDlg_dateModBox");
569 Element.hide("filterDlg_dateChkBox");
574 exception_error("filterDlgCheckType", e);
579 function filterDlgCheckAction ( sender
) {
583 var action
= sender
. value
;
585 var action_param
= $( "filterDlg_paramBox" );
588 console
. log ( "filterDlgCheckAction: can't find action param box!" );
592 // if selected action supports parameters, enable params field
593 if ( action
== 4 || action
== 6 || action
== 7 ) {
594 new Effect
. Appear ( action_param
, { duration
: 0.5 });
596 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
597 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
599 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
600 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
603 Element
. hide ( action_param
);
607 exception_error ( "filterDlgCheckAction" , e
);
612 function filterDlgCheckDate () {
614 var dialog
= dijit
. byId ( "filterEditDlg" );
616 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
618 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
620 new Ajax
. Request ( "backend.php" , {
622 onComplete : function ( transport
) {
624 var reply
= JSON
. parse ( transport
. responseText
);
626 if ( reply
[ 'result' ] == true ) {
627 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
630 alert ( __ ( "Date syntax is incorrect." ));
637 exception_error ( "filterDlgCheckDate" , e
);
641 function explainError ( code
) {
642 return displayDlg ( "explainError" , code
);
645 function loading_set_progress ( p
) {
647 loading_progress
+= p
;
649 if ( dijit
. byId ( "loading_bar" ))
650 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
652 if ( loading_progress
>= 90 )
656 exception_error ( "loading_set_progress" , e
);
660 function remove_splash () {
662 if ( Element
. visible ( "overlay" )) {
663 console
. log ( "about to remove splash, OMG!" );
664 Element
. hide ( "overlay" );
665 console
. log ( "removed splash!" );
669 function transport_error_check ( transport
) {
671 if ( transport
. responseXML
) {
672 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
675 var code
= error
. getAttribute ( "error-code" );
676 var msg
= error
. getAttribute ( "error-msg" );
678 fatalError ( code
, msg
);
684 exception_error ( "check_for_error_xml" , e
);
689 function strip_tags ( s
) {
690 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
693 function truncate_string ( s
, length
) {
694 if (! length
) length
= 30 ;
695 var tmp
= s
. substring ( 0 , length
);
696 if ( s
. length
> length
) tmp
+= "…" ;
700 function hotkey_prefix_timeout () {
703 var date
= new Date ();
704 var ts
= Math
. round ( date
. getTime () / 1000 );
706 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
707 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
708 hotkey_prefix_pressed
= false ;
709 hotkey_prefix
= false ;
710 Element
. hide ( 'cmdline' );
713 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
716 exception_error ( "hotkey_prefix_timeout" , e
);
720 function hideAuxDlg () {
722 Element
. hide ( 'auxDlg' );
724 exception_error ( "hideAuxDlg" , e
);
729 function uploadIconHandler ( rc
) {
733 notify_info ( "Upload complete." );
734 if ( inPreferences ()) {
737 setTimeout ( 'updateFeedList(false, false)' , 50 );
741 notify_error ( "Upload failed: icon is too big." );
744 notify_error ( "Upload failed." );
749 exception_error ( "uploadIconHandler" , e
);
753 function removeFeedIcon ( id
) {
757 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
758 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
762 notify_progress ( "Removing feed icon..." , true );
764 new Ajax
. Request ( "backend.php" , {
766 onComplete : function ( transport
) {
767 notify_info ( "Feed icon removed." );
768 if ( inPreferences ()) {
771 setTimeout ( 'updateFeedList(false, false)' , 50 );
778 exception_error ( "removeFeedIcon" , e
);
782 function uploadFeedIcon () {
786 var file
= $( "icon_file" );
788 if ( file
. value
. length
== 0 ) {
789 alert ( __ ( "Please select an image file to upload." ));
791 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
792 notify_progress ( "Uploading, please wait..." , true );
800 exception_error ( "uploadFeedIcon" , e
);
804 function addLabel ( select
, callback
) {
808 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
810 if ( caption
!= undefined ) {
813 alert ( __ ( "Can't create label: missing caption." ));
817 var query
= "?op=pref-labels&method=add&caption=" +
818 param_escape ( caption
);
821 query
+= "&output=select" ;
823 notify_progress ( "Loading, please wait..." , true );
825 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
827 new Ajax
. Request ( "backend.php" , {
829 onComplete : function ( transport
) {
832 } else if ( inPreferences ()) {
842 exception_error ( "addLabel" , e
);
846 function quickAddFeed () {
848 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
850 // overlapping widgets
851 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
852 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
854 var dialog
= new dijit
. Dialog ({
856 title
: __ ( "Subscribe to Feed" ),
857 style
: "width: 600px" ,
858 execute : function () {
859 if ( this . validate ()) {
860 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
862 var feed_url
= this . attr ( 'value' ). feed
;
864 Element
. show ( "feed_add_spinner" );
866 new Ajax
. Request ( "backend.php" , {
867 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
868 onComplete : function ( transport
) {
871 var reply
= JSON
. parse ( transport
. responseText
);
873 var rc
= reply
[ 'result' ];
876 Element
. hide ( "feed_add_spinner" );
878 console
. log ( "GOT RC: " + rc
);
880 switch ( parseInt ( rc
[ 'code' ])) {
883 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
888 alert ( __ ( "Specified URL seems to be invalid." ));
891 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
894 /* notify_progress("Searching for feed urls...", true);
896 new Ajax.Request("backend.php", {
897 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
898 onComplete: function(transport, dialog, feed_url) {
902 var reply = JSON.parse(transport.responseText);
904 var feeds = reply['urls'];
906 console.log(transport.responseText);
908 var select = dijit.byId("feedDlg_feedContainerSelect");
910 while (select.getOptions().length > 0)
911 select.removeOption(0);
914 for (var feedUrl in feeds) {
915 select.addOption({value: feedUrl, label: feeds[feedUrl]});
919 // if (count > 5) count = 5;
920 // select.size = count;
922 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
929 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
931 while ( select
. getOptions (). length
> 0 )
932 select
. removeOption ( 0 );
935 for ( var feedUrl
in feeds
) {
936 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
940 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
944 alert ( __ ( "Couldn't download the specified URL: %s" ).
945 replace ( "%s" , rc
[ 'message' ]));
948 alert ( __ ( "You are already subscribed to this feed." ));
953 exception_error ( "subscribeToFeed" , e
, transport
);
964 exception_error ( "quickAddFeed" , e
);
968 function createNewRuleElement ( parentNode
, replaceNode
) {
970 var form
= document
. forms
[ "filter_new_rule_form" ];
972 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
974 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
975 param_escape ( dojo
. formToJson ( form
));
979 new Ajax
. Request ( "backend.php" , {
981 onComplete : function ( transport
) {
983 var li
= dojo
. create ( "li" );
985 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
987 new dijit
. form
. CheckBox ({
988 onChange : function () {
989 toggleSelectListRow2 ( this ) },
992 dojo
. create ( "input" , { type
: "hidden" ,
994 value
: dojo
. formToJson ( form
) }, li
);
996 dojo
. create ( "span" , {
997 onclick : function () {
998 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
1000 innerHTML
: transport
. responseText
}, li
);
1003 parentNode
. replaceChild ( li
, replaceNode
);
1005 parentNode
. appendChild ( li
);
1008 exception_error ( "createNewRuleElement" , e
);
1012 exception_error ( "createNewRuleElement" , e
);
1016 function createNewActionElement ( parentNode
, replaceNode
) {
1018 var form
= document
. forms
[ "filter_new_action_form" ];
1020 if ( form
. action_id
. value
== 7 ) {
1021 form
. action_param
. value
= form
. action_param_label
. value
;
1024 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
1025 param_escape ( dojo
. formToJson ( form
));
1029 new Ajax
. Request ( "backend.php" , {
1031 onComplete : function ( transport
) {
1033 var li
= dojo
. create ( "li" );
1035 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
1037 new dijit
. form
. CheckBox ({
1038 onChange : function () {
1039 toggleSelectListRow2 ( this ) },
1042 dojo
. create ( "input" , { type
: "hidden" ,
1044 value
: dojo
. formToJson ( form
) }, li
);
1046 dojo
. create ( "span" , {
1047 onclick : function () {
1048 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
1050 innerHTML
: transport
. responseText
}, li
);
1053 parentNode
. replaceChild ( li
, replaceNode
);
1055 parentNode
. appendChild ( li
);
1059 exception_error ( "createNewActionElement" , e
);
1063 exception_error ( "createNewActionElement" , e
);
1068 function addFilterRule ( replaceNode
, ruleStr
) {
1070 if ( dijit
. byId ( "filterNewRuleDlg" ))
1071 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1073 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1074 param_escape ( ruleStr
);
1076 var rule_dlg
= new dijit
. Dialog ({
1077 id
: "filterNewRuleDlg" ,
1078 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1079 style
: "width: 600px" ,
1080 execute : function () {
1081 if ( this . validate ()) {
1082 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1090 exception_error ( "addFilterRule" , e
);
1094 function addFilterAction ( replaceNode
, actionStr
) {
1096 if ( dijit
. byId ( "filterNewActionDlg" ))
1097 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1099 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1100 param_escape ( actionStr
);
1102 var rule_dlg
= new dijit
. Dialog ({
1103 id
: "filterNewActionDlg" ,
1104 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1105 style
: "width: 600px" ,
1106 execute : function () {
1107 if ( this . validate ()) {
1108 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1116 exception_error ( "addFilterAction" , e
);
1120 function quickAddFilter () {
1123 if (! inPreferences ()) {
1124 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1125 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1126 param_escape ( activeFeedIsCat ());
1128 query
= "backend.php?op=pref-filters&method=newfilter" ;
1133 if ( dijit
. byId ( "feedEditDlg" ))
1134 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1136 if ( dijit
. byId ( "filterEditDlg" ))
1137 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1139 dialog
= new dijit
. Dialog ({
1140 id
: "filterEditDlg" ,
1141 title
: __ ( "Create Filter" ),
1142 style
: "width: 600px" ,
1144 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1146 if ( dijit
. byId ( "filterTestDlg" ))
1147 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1149 var test_dlg
= new dijit
. Dialog ({
1150 id
: "filterTestDlg" ,
1151 title
: "Test Filter" ,
1152 style
: "width: 600px" ,
1157 selectRules : function ( select
) {
1158 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1161 e
. parentNode
. addClassName ( "Selected" );
1163 e
. parentNode
. removeClassName ( "Selected" );
1166 selectActions : function ( select
) {
1167 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1171 e
. parentNode
. addClassName ( "Selected" );
1173 e
. parentNode
. removeClassName ( "Selected" );
1177 editRule : function ( e
) {
1178 var li
= e
. parentNode
;
1179 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1180 addFilterRule ( li
, rule
);
1182 editAction : function ( e
) {
1183 var li
= e
. parentNode
;
1184 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1185 addFilterAction ( li
, action
);
1187 addAction : function () { addFilterAction (); },
1188 addRule : function () { addFilterRule (); },
1189 deleteAction : function () {
1190 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1192 deleteRule : function () {
1193 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1195 execute : function () {
1196 if ( this . validate ()) {
1198 var query
= dojo
. formToQuery ( "filter_new_form" );
1202 new Ajax
. Request ( "backend.php" , {
1204 onComplete : function ( transport
) {
1205 if ( inPreferences ()) {
1215 if (! inPreferences ()) {
1216 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1217 dojo
. disconnect ( lh
);
1219 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1221 new Ajax
. Request ( "backend.php" , {
1223 onComplete : function ( transport
) {
1224 var reply
= JSON
. parse ( transport
. responseText
);
1228 if ( reply
&& reply
) title
= reply
. title
;
1230 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1232 console
. log ( title
+ " " + getActiveFeedId ());
1234 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1237 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1239 addFilterRule ( null , dojo
. toJson ( rule
));
1250 exception_error ( "quickAddFilter" , e
);
1254 function resetPubSub ( feed_id
, title
) {
1256 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1258 if ( title
== undefined || confirm ( msg
)) {
1259 notify_progress ( "Loading, please wait..." );
1261 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1263 new Ajax
. Request ( "backend.php" , {
1265 onComplete : function ( transport
) {
1266 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1267 notify_info ( "Subscription reset." );
1275 function unsubscribeFeed ( feed_id
, title
) {
1277 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1279 if ( title
== undefined || confirm ( msg
)) {
1280 notify_progress ( "Removing feed..." );
1282 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1284 new Ajax
. Request ( "backend.php" , {
1286 onComplete : function ( transport
) {
1288 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1290 if ( inPreferences ()) {
1293 if ( feed_id
== getActiveFeedId ())
1294 setTimeout ( "viewfeed(-5)" , 100 );
1296 if ( feed_id
< 0 ) updateFeedList ();
1306 function backend_sanity_check_callback ( transport
) {
1310 if ( sanity_check_done
) {
1311 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1312 "presence of Firebug or some other disrupting extension. " +
1313 "Please disable it and try again." );
1317 var reply
= JSON
. parse ( transport
. responseText
);
1320 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1324 var error_code
= reply
[ 'error' ][ 'code' ];
1326 if ( error_code
&& error_code
!= 0 ) {
1327 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1330 console
. log ( "sanity check ok" );
1332 var params
= reply
[ 'init-params' ];
1335 console
. log ( 'reading init-params...' );
1340 console
. log ( "IP: " + k
+ " => " + v
);
1344 init_params
= params
;
1347 sanity_check_done
= true ;
1349 init_second_stage ();
1352 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1356 /*function has_local_storage() {
1358 return 'sessionStorage' in window && window['sessionStorage'] != null;
1364 function catSelectOnChange ( elem
) {
1366 /* var value = elem[elem.selectedIndex].value;
1367 var def = elem.getAttribute('default');
1369 if (value == "ADD_CAT") {
1372 dropboxSelect(elem, def);
1374 elem.selectedIndex = 0;
1380 exception_error ( "catSelectOnChange" , e
);
1384 function quickAddCat ( elem
) {
1386 var cat
= prompt ( __ ( "Please enter category title:" ));
1390 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1392 notify_progress ( "Loading, please wait..." , true );
1394 new Ajax
. Request ( "backend.php" , {
1396 onComplete : function ( transport
) {
1397 var response
= transport
. responseXML
;
1398 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1399 var options
= select
. getElementsByTagName ( "option" );
1401 dropbox_replace_options ( elem
, options
);
1410 exception_error ( "quickAddCat" , e
);
1414 function genUrlChangeKey ( feed
, is_cat
) {
1417 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1421 notify_progress ( "Trying to change address..." , true );
1423 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1424 "&is_cat=" + param_escape ( is_cat
);
1426 new Ajax
. Request ( "backend.php" , {
1428 onComplete : function ( transport
) {
1429 var reply
= JSON
. parse ( transport
. responseText
);
1430 var new_link
= reply
. link
;
1432 var e
= $( 'gen_feed_url' );
1436 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1437 "&key=" + new_link
);
1439 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1440 "&key=" + new_link
);
1442 new Effect
. Highlight ( e
);
1447 notify_error ( "Could not change feed URL." );
1452 exception_error ( "genUrlChangeKey" , e
);
1457 function labelSelectOnChange ( elem
) {
1459 /* var value = elem[elem.selectedIndex].value;
1460 var def = elem.getAttribute('default');
1462 if (value == "ADD_LABEL") {
1465 dropboxSelect(elem, def);
1467 elem.selectedIndex = 0;
1469 addLabel(elem, function(transport) {
1473 var response = transport.responseXML;
1474 var select = response.getElementsByTagName("select")[0];
1475 var options = select.getElementsByTagName("option");
1477 dropbox_replace_options(elem, options);
1481 exception_error("addLabel", e);
1487 exception_error ( "labelSelectOnChange" , e
);
1491 function dropbox_replace_options ( elem
, options
) {
1494 while ( elem
. hasChildNodes ())
1495 elem
. removeChild ( elem
. firstChild
);
1499 for ( var i
= 0 ; i
< options
. length
; i
++) {
1500 var text
= options
[ i
]. firstChild
. nodeValue
;
1501 var value
= options
[ i
]. getAttribute ( "value" );
1503 if ( value
== undefined ) value
= text
;
1505 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1507 var option
= new Option ( text
, value
, issel
);
1509 if ( options
[ i
]. getAttribute ( "disabled" ))
1510 option
. setAttribute ( "disabled" , true );
1512 elem
. insert ( option
);
1514 if ( issel
) sel_idx
= i
;
1517 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1518 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1521 exception_error ( "dropbox_replace_options" , e
);
1525 // mode = all, none, invert
1526 function selectTableRows ( id
, mode
) {
1528 var rows
= $( id
). rows
;
1530 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1535 if ( row
. id
&& row
. className
) {
1536 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1537 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1539 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1540 var input
= inputs
[ j
];
1542 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1543 input
. id
. match ( bare_id
)) {
1546 dcb
= dijit
. getEnclosingWidget ( cb
);
1552 var issel
= row
. hasClassName ( "Selected" );
1554 if ( mode
== "all" && ! issel
) {
1555 row
. addClassName ( "Selected" );
1557 if ( dcb
) dcb
. set ( "checked" , true );
1558 } else if ( mode
== "none" && issel
) {
1559 row
. removeClassName ( "Selected" );
1561 if ( dcb
) dcb
. set ( "checked" , false );
1563 } else if ( mode
== "invert" ) {
1566 row
. removeClassName ( "Selected" );
1568 if ( dcb
) dcb
. set ( "checked" , false );
1570 row
. addClassName ( "Selected" );
1572 if ( dcb
) dcb
. set ( "checked" , true );
1580 exception_error ( "selectTableRows" , e
);
1585 function getSelectedTableRowIds ( id
) {
1589 var elem_rows
= $( id
). rows
;
1591 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1592 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1593 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1599 exception_error ( "getSelectedTableRowIds" , e
);
1605 function editFeed ( feed
, event
) {
1608 return alert ( __ ( "You can't edit this kind of feed." ));
1610 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1615 if ( dijit
. byId ( "filterEditDlg" ))
1616 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1618 if ( dijit
. byId ( "feedEditDlg" ))
1619 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1621 dialog
= new dijit
. Dialog ({
1623 title
: __ ( "Edit Feed" ),
1624 style
: "width: 600px" ,
1625 execute : function () {
1626 if ( this . validate ()) {
1627 // console.log(dojo.objectToQuery(this.attr('value')));
1629 notify_progress ( "Saving data..." , true );
1631 new Ajax
. Request ( "backend.php" , {
1632 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1633 onComplete : function ( transport
) {
1645 exception_error ( "editFeed" , e
);
1649 function feedBrowser () {
1651 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1653 if ( dijit
. byId ( "feedAddDlg" ))
1654 dijit
. byId ( "feedAddDlg" ). hide ();
1656 if ( dijit
. byId ( "feedBrowserDlg" ))
1657 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1659 var dialog
= new dijit
. Dialog ({
1660 id
: "feedBrowserDlg" ,
1661 title
: __ ( "More Feeds" ),
1662 style
: "width: 600px" ,
1663 getSelectedFeedIds : function () {
1664 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1665 var selected
= new Array ();
1667 list
. each ( function ( child
) {
1668 var id
= child
. id
. replace ( "FBROW-" , "" );
1670 if ( child
. hasClassName ( 'Selected' )) {
1677 getSelectedFeeds : function () {
1678 var list
= $$( "#browseFeedList li.Selected" );
1679 var selected
= new Array ();
1681 list
. each ( function ( child
) {
1682 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1683 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1685 selected
. push ([ title
, url
]);
1692 subscribe : function () {
1693 var mode
= this . attr ( 'value' ). mode
;
1697 selected
= this . getSelectedFeeds ();
1699 selected
= this . getSelectedFeedIds ();
1701 if ( selected
. length
> 0 ) {
1702 dijit
. byId ( "feedBrowserDlg" ). hide ();
1704 notify_progress ( "Loading, please wait..." , true );
1706 // we use dojo.toJson instead of JSON.stringify because
1707 // it somehow escapes everything TWICE, at least in Chrome 9
1709 var query
= "?op=rpc&method=massSubscribe&payload=" +
1710 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1714 new Ajax
. Request ( "backend.php" , {
1716 onComplete : function ( transport
) {
1722 alert ( __ ( "No feeds are selected." ));
1726 update : function () {
1727 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1729 Element
. show ( 'feed_browser_spinner' );
1731 new Ajax
. Request ( "backend.php" , {
1733 onComplete : function ( transport
) {
1736 Element
. hide ( 'feed_browser_spinner' );
1738 var c
= $( "browseFeedList" );
1740 var reply
= JSON
. parse ( transport
. responseText
);
1742 var r
= reply
[ 'content' ];
1743 var mode
= reply
[ 'mode' ];
1749 dojo
. parser
. parse ( "browseFeedList" );
1752 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1754 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1759 removeFromArchive : function () {
1760 var selected
= this . getSelectedFeedIds ();
1762 if ( selected
. length
> 0 ) {
1764 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1767 Element
. show ( 'feed_browser_spinner' );
1769 var query
= "?op=rpc&method=remarchive&ids=" +
1770 param_escape ( selected
. toString ());;
1772 new Ajax
. Request ( "backend.php" , {
1774 onComplete : function ( transport
) {
1780 execute : function () {
1781 if ( this . validate ()) {
1790 exception_error ( "editFeed" , e
);
1794 function showFeedsWithErrors () {
1796 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1798 if ( dijit
. byId ( "errorFeedsDlg" ))
1799 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1801 dialog
= new dijit
. Dialog ({
1802 id
: "errorFeedsDlg" ,
1803 title
: __ ( "Feeds with update errors" ),
1804 style
: "width: 600px" ,
1805 getSelectedFeeds : function () {
1806 return getSelectedTableRowIds ( "prefErrorFeedList" );
1808 removeSelected : function () {
1809 var sel_rows
= this . getSelectedFeeds ();
1811 console
. log ( sel_rows
);
1813 if ( sel_rows
. length
> 0 ) {
1814 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1817 notify_progress ( "Removing selected feeds..." , true );
1819 var query
= "?op=pref-feeds&method=remove&ids=" +
1820 param_escape ( sel_rows
. toString ());
1822 new Ajax
. Request ( "backend.php" , {
1824 onComplete : function ( transport
) {
1832 alert ( __ ( "No feeds are selected." ));
1835 execute : function () {
1836 if ( this . validate ()) {
1844 exception_error ( "showFeedsWithErrors" , e
);
1849 /* new support functions for SelectByTag */
1851 function get_all_tags ( selObj
){
1853 if ( ! selObj
) return "" ;
1856 var len
= selObj
. options
. length
;
1858 for ( var i
= 0 ; i
< len
; i
++){
1859 if ( selObj
. options
[ i
]. selected
) {
1860 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1864 if ( result
. length
> 0 ){
1865 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1871 exception_error ( "get_all_tags" , e
);
1875 function get_radio_checked ( radioObj
) {
1877 if (! radioObj
) return "" ;
1879 var len
= radioObj
. length
;
1881 if ( len
== undefined ){
1882 if ( radioObj
. checked
){
1883 return ( radioObj
. value
);
1889 for ( var i
= 0 ; i
< len
; i
++ ){
1890 if ( radioObj
[ i
]. checked
){
1891 return ( radioObj
[ i
]. value
);
1896 exception_error ( "get_radio_checked" , e
);
1901 function get_timestamp () {
1902 var date
= new Date ();
1903 return Math
. round ( date
. getTime () / 1000 );
1906 function helpDialog ( topic
) {
1908 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1910 if ( dijit
. byId ( "helpDlg" ))
1911 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1913 dialog
= new dijit
. Dialog ({
1916 style
: "width: 600px" ,
1923 exception_error ( "helpDialog" , e
);
1927 function htmlspecialchars_decode ( string
, quote_style
) {
1928 // http://kevin.vanzonneveld.net
1929 // + original by: Mirek Slugen
1930 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1931 // + bugfixed by: Mateusz "loonquawl" Zalega
1932 // + input by: ReverseSyntax
1933 // + input by: Slawomir Kaniecki
1934 // + input by: Scott Cariss
1935 // + input by: Francois
1936 // + bugfixed by: Onno Marsman
1937 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1938 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1939 // + input by: Ratheous
1940 // + input by: Mailfaker (http://www.weedem.fr/)
1941 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1942 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1943 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1944 // * returns 1: '<p>this -> "</p>'
1945 // * example 2: htmlspecialchars_decode("&quot;");
1946 // * returns 2: '"'
1950 if ( typeof quote_style
=== 'undefined' ) {
1953 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1956 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1957 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1962 if ( quote_style
=== 0 ) {
1965 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1966 quote_style
= []. concat ( quote_style
);
1967 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1968 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1969 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1971 } else if ( OPTS
[ quote_style
[ i
]]) {
1972 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1975 quote_style
= optTemp
;
1977 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1978 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1979 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1982 string
= string
. replace ( /"/g , '"' );
1984 // Put this in last place to avoid escape being double-decoded
1985 string
= string
. replace ( /&/g , '&' );