]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var loading_progress
= 0 ;
2 var sanity_check_done
= false ;
4 var _label_base_index
= - 1024 ;
5 var notify_hide_timerid
= false ;
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
);
151 function hide_notify () {
152 Element
. hide ( 'notify' );
155 function notify_real ( msg
, no_hide
, n_type
) {
161 if ( notify_hide_timerid
) {
162 window
. clearTimeout ( notify_hide_timerid
);
166 if ( Element
. visible ( n
)) {
167 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
183 msg
= "<span class= \" msg \" > " + __ ( msg
) + "</span>" ;
186 n
. className
= "notify" ;
187 } else if ( n_type
== 2 ) {
188 n
. className
= "notify progress" ;
189 msg
= "<span><img src='images/indicator_white.gif'></span>" + msg
;
191 } else if ( n_type
== 3 ) {
192 n
. className
= "notify error" ;
193 msg
= "<span><img src='images/sign_excl.svg'></span>" + msg
;
194 } else if ( n_type
== 4 ) {
195 n
. className
= "notify info" ;
196 msg
= "<span><img src='images/sign_info.svg'></span>" + msg
;
199 msg
+= " <span><img src= \" images/close_notify.svg \" class= \" close \" title= \" " +
200 __ ( "Click to close" ) + " \" onclick= \" notify('') \" ></span>" ;
202 // msg = "<img src='images/live_com_loading.gif'> " + msg;
207 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 5 * 1000 );
211 function notify ( msg
, no_hide
) {
212 notify_real ( msg
, no_hide
, 1 );
215 function notify_progress ( msg
, no_hide
) {
216 notify_real ( msg
, no_hide
, 2 );
219 function notify_error ( msg
, no_hide
) {
220 notify_real ( msg
, no_hide
, 3 );
224 function notify_info ( msg
, no_hide
) {
225 notify_real ( msg
, no_hide
, 4 );
228 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
234 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
237 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
239 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
243 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
244 document
. cookie
= name
+ "=" + escape ( value
) +
245 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
246 (( path
) ? "; path=" + path
: "" ) +
247 (( domain
) ? "; domain=" + domain
: "" ) +
248 (( secure
) ? "; secure" : "" );
251 function delCookie ( name
, path
, domain
) {
252 if ( getCookie ( name
)) {
253 document
. cookie
= name
+ "=" +
254 (( path
) ? ";path=" + path
: "" ) +
255 (( domain
) ? ";domain=" + domain
: "" ) +
256 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
261 function getCookie ( name
) {
263 var dc
= document
. cookie
;
264 var prefix
= name
+ "=" ;
265 var begin
= dc
. indexOf ( "; " + prefix
);
267 begin
= dc
. indexOf ( prefix
);
268 if ( begin
!= 0 ) return null ;
273 var end
= document
. cookie
. indexOf ( ";" , begin
);
277 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
280 function gotoPreferences () {
281 document
. location
. href
= "prefs.php" ;
284 function gotoLogout () {
285 document
. location
. href
= "backend.php?op=logout" ;
288 function gotoMain () {
289 document
. location
. href
= "index.php" ;
292 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
293 * * @author Sundar Dorai-Raj
294 * * Email: sdoraira@vt.edu
295 * * This program is free software; you can redistribute it and/or
296 * * modify it under the terms of the GNU General Public License
297 * * as published by the Free Software Foundation; either version 2
298 * * of the License, or (at your option) any later version,
299 * * provided that any use properly credits the author.
300 * * This program is distributed in the hope that it will be useful,
301 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
302 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303 * * GNU General Public License for more details at http://www.gnu.org * * */
305 var numbers
= ".0123456789" ;
306 function isNumeric ( x
) {
307 // is x a String or a character?
309 // remove negative sign
311 for ( var j
= 0 ; j
< x
. length
; j
++) {
312 // call isNumeric recursively for each character
313 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
314 if (! number
) return number
;
319 // if x is number return true
320 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
326 function toggleSelectRowById ( sender
, id
) {
328 return toggleSelectRow ( sender
, row
);
331 function toggleSelectListRow ( sender
) {
332 var row
= sender
. parentNode
;
333 return toggleSelectRow ( sender
, row
);
336 /* this is for dijit Checkbox */
337 function toggleSelectListRow2 ( sender
) {
338 var row
= sender
. domNode
. parentNode
;
339 return toggleSelectRow ( sender
, row
);
342 /* this is for dijit Checkbox */
343 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
347 row
= sender
. domNode
. parentNode
. parentNode
;
349 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
351 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
352 row
. addClassName ( 'Selected' );
354 row
. removeClassName ( 'Selected' );
356 if ( typeof updateSelectedPrompt
!= undefined )
357 updateSelectedPrompt ();
361 function toggleSelectRow ( sender
, row
) {
363 if (! row
) row
= sender
. parentNode
. parentNode
;
365 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
366 row
. addClassName ( 'Selected' );
368 row
. removeClassName ( 'Selected' );
370 if ( typeof updateSelectedPrompt
!= undefined )
371 updateSelectedPrompt ();
374 function checkboxToggleElement ( elem
, id
) {
376 Effect
. Appear ( id
, { duration
: 0.5 });
378 Effect
. Fade ( id
, { duration
: 0.5 });
382 function dropboxSelect ( e
, v
) {
383 for ( var i
= 0 ; i
< e
. length
; i
++) {
384 if ( e
[ i
]. value
== v
) {
391 function getURLParam ( param
){
392 return String ( window
. location
. href
). parseQuery ()[ param
];
395 function closeInfoBox ( cleanup
) {
397 dialog
= dijit
. byId ( "infoBox" );
399 if ( dialog
) dialog
. hide ();
402 //exception_error("closeInfoBox", e);
408 function displayDlg ( title
, id
, param
, callback
) {
410 notify_progress ( "Loading, please wait..." , true );
412 var query
= "?op=dlg&method=" +
413 param_escape ( id
) + "¶m=" + param_escape ( param
);
415 new Ajax
. Request ( "backend.php" , {
417 onComplete : function ( transport
) {
418 infobox_callback2 ( transport
, title
);
419 if ( callback
) callback ( transport
);
425 function infobox_callback2 ( transport
, title
) {
429 if ( dijit
. byId ( "infoBox" )) {
430 dialog
= dijit
. byId ( "infoBox" );
433 //console.log("infobox_callback2");
436 var content
= transport
. responseText
;
439 dialog
= new dijit
. Dialog ({
442 style
: "width: 600px" ,
443 onCancel : function () {
446 onExecute : function () {
449 onClose : function () {
454 dialog
. attr ( 'title' , title
);
455 dialog
. attr ( 'content' , content
);
462 exception_error ( "infobox_callback2" , e
);
466 function filterCR ( e
, f
)
471 key
= window
. event
. keyCode
; //IE
473 key
= e
. which
; //firefox
476 if ( typeof f
!= 'undefined' ) {
487 function getInitParam ( key
) {
488 return init_params
[ key
];
491 function setInitParam ( key
, value
) {
492 init_params
[ key
] = value
;
495 function fatalError ( code
, msg
, ext_info
) {
499 window
. location
. href
= "index.php" ;
500 } else if ( code
== 5 ) {
501 window
. location
. href
= "public.php?op=dbupdate" ;
504 if ( msg
== "" ) msg
= "Unknown error" ;
507 if ( ext_info
. responseText
) {
508 ext_info
= ext_info
. responseText
;
512 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
516 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
517 "<p>" + msg
+ "</p>" ;
520 content
= content
+ "<div><b>Additional information:</b></div>" +
521 "<textarea style='width: 100%' readonly= \" 1 \" >" +
522 ext_info
+ "</textarea>" ;
525 var dialog
= new dijit
. Dialog ({
526 title
: "Fatal error" ,
527 style
: "width: 600px" ,
537 exception_error ( "fatalError" , e
);
541 function filterDlgCheckAction ( sender
) {
545 var action
= sender
. value
;
547 var action_param
= $( "filterDlg_paramBox" );
550 console
. log ( "filterDlgCheckAction: can't find action param box!" );
554 // if selected action supports parameters, enable params field
555 if ( action
== 4 || action
== 6 || action
== 7 ) {
556 new Effect
. Appear ( action_param
, { duration
: 0.5 });
558 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
559 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
561 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
562 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
565 Element
. hide ( action_param
);
569 exception_error ( "filterDlgCheckAction" , e
);
575 function explainError ( code
) {
576 return displayDlg ( __ ( "Error explained" ), "explainError" , code
);
579 function loading_set_progress ( p
) {
581 loading_progress
+= p
;
583 if ( dijit
. byId ( "loading_bar" ))
584 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
586 if ( loading_progress
>= 90 )
590 exception_error ( "loading_set_progress" , e
);
594 function remove_splash () {
596 if ( Element
. visible ( "overlay" )) {
597 console
. log ( "about to remove splash, OMG!" );
598 Element
. hide ( "overlay" );
599 console
. log ( "removed splash!" );
603 function transport_error_check ( transport
) {
605 if ( transport
. responseXML
) {
606 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
609 var code
= error
. getAttribute ( "error-code" );
610 var msg
= error
. getAttribute ( "error-msg" );
612 fatalError ( code
, msg
);
618 exception_error ( "check_for_error_xml" , e
);
623 function strip_tags ( s
) {
624 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
627 function truncate_string ( s
, length
) {
628 if (! length
) length
= 30 ;
629 var tmp
= s
. substring ( 0 , length
);
630 if ( s
. length
> length
) tmp
+= "…" ;
634 function hotkey_prefix_timeout () {
637 var date
= new Date ();
638 var ts
= Math
. round ( date
. getTime () / 1000 );
640 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
641 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
642 hotkey_prefix_pressed
= false ;
643 hotkey_prefix
= false ;
644 Element
. hide ( 'cmdline' );
647 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
650 exception_error ( "hotkey_prefix_timeout" , e
);
654 function uploadIconHandler ( rc
) {
658 notify_info ( "Upload complete." );
659 if ( inPreferences ()) {
662 setTimeout ( 'updateFeedList(false, false)' , 50 );
666 notify_error ( "Upload failed: icon is too big." );
669 notify_error ( "Upload failed." );
674 exception_error ( "uploadIconHandler" , e
);
678 function removeFeedIcon ( id
) {
682 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
683 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
687 notify_progress ( "Removing feed icon..." , true );
689 new Ajax
. Request ( "backend.php" , {
691 onComplete : function ( transport
) {
692 notify_info ( "Feed icon removed." );
693 if ( inPreferences ()) {
696 setTimeout ( 'updateFeedList(false, false)' , 50 );
703 exception_error ( "removeFeedIcon" , e
);
707 function uploadFeedIcon () {
711 var file
= $( "icon_file" );
713 if ( file
. value
. length
== 0 ) {
714 alert ( __ ( "Please select an image file to upload." ));
716 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
717 notify_progress ( "Uploading, please wait..." , true );
725 exception_error ( "uploadFeedIcon" , e
);
729 function addLabel ( select
, callback
) {
733 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
735 if ( caption
!= undefined ) {
738 alert ( __ ( "Can't create label: missing caption." ));
742 var query
= "?op=pref-labels&method=add&caption=" +
743 param_escape ( caption
);
746 query
+= "&output=select" ;
748 notify_progress ( "Loading, please wait..." , true );
750 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
752 new Ajax
. Request ( "backend.php" , {
754 onComplete : function ( transport
) {
757 } else if ( inPreferences ()) {
767 exception_error ( "addLabel" , e
);
771 function quickAddFeed () {
773 var query
= "backend.php?op=feeds&method=quickAddFeed" ;
775 // overlapping widgets
776 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
777 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
779 var dialog
= new dijit
. Dialog ({
781 title
: __ ( "Subscribe to Feed" ),
782 style
: "width: 600px" ,
783 execute : function () {
784 if ( this . validate ()) {
785 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
787 var feed_url
= this . attr ( 'value' ). feed
;
789 Element
. show ( "feed_add_spinner" );
791 new Ajax
. Request ( "backend.php" , {
792 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
793 onComplete : function ( transport
) {
796 var reply
= JSON
. parse ( transport
. responseText
);
798 var rc
= reply
[ 'result' ];
801 Element
. hide ( "feed_add_spinner" );
805 switch ( parseInt ( rc
[ 'code' ])) {
808 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
813 alert ( __ ( "Specified URL seems to be invalid." ));
816 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
821 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
823 while ( select
. getOptions (). length
> 0 )
824 select
. removeOption ( 0 );
826 select
. addOption ({ value
: '' , label
: __ ( "Expand to select feed" )});
829 for ( var feedUrl
in feeds
) {
830 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
834 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
838 alert ( __ ( "Couldn't download the specified URL: %s" ).
839 replace ( "%s" , rc
[ 'message' ]));
842 alert ( __ ( "XML validation failed: %s" ).
843 replace ( "%s" , rc
[ 'message' ]));
847 alert ( __ ( "You are already subscribed to this feed." ));
852 exception_error ( "subscribeToFeed" , e
, transport
);
863 exception_error ( "quickAddFeed" , e
);
867 function createNewRuleElement ( parentNode
, replaceNode
) {
869 var form
= document
. forms
[ "filter_new_rule_form" ];
871 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
873 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
874 param_escape ( dojo
. formToJson ( form
));
878 new Ajax
. Request ( "backend.php" , {
880 onComplete : function ( transport
) {
882 var li
= dojo
. create ( "li" );
884 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
886 new dijit
. form
. CheckBox ({
887 onChange : function () {
888 toggleSelectListRow2 ( this ) },
891 dojo
. create ( "input" , { type
: "hidden" ,
893 value
: dojo
. formToJson ( form
) }, li
);
895 dojo
. create ( "span" , {
896 onclick : function () {
897 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
899 innerHTML
: transport
. responseText
}, li
);
902 parentNode
. replaceChild ( li
, replaceNode
);
904 parentNode
. appendChild ( li
);
907 exception_error ( "createNewRuleElement" , e
);
911 exception_error ( "createNewRuleElement" , e
);
915 function createNewActionElement ( parentNode
, replaceNode
) {
917 var form
= document
. forms
[ "filter_new_action_form" ];
919 if ( form
. action_id
. value
== 7 ) {
920 form
. action_param
. value
= form
. action_param_label
. value
;
923 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
924 param_escape ( dojo
. formToJson ( form
));
928 new Ajax
. Request ( "backend.php" , {
930 onComplete : function ( transport
) {
932 var li
= dojo
. create ( "li" );
934 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
936 new dijit
. form
. CheckBox ({
937 onChange : function () {
938 toggleSelectListRow2 ( this ) },
941 dojo
. create ( "input" , { type
: "hidden" ,
943 value
: dojo
. formToJson ( form
) }, li
);
945 dojo
. create ( "span" , {
946 onclick : function () {
947 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
949 innerHTML
: transport
. responseText
}, li
);
952 parentNode
. replaceChild ( li
, replaceNode
);
954 parentNode
. appendChild ( li
);
958 exception_error ( "createNewActionElement" , e
);
962 exception_error ( "createNewActionElement" , e
);
967 function addFilterRule ( replaceNode
, ruleStr
) {
969 if ( dijit
. byId ( "filterNewRuleDlg" ))
970 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
972 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
973 param_escape ( ruleStr
);
975 var rule_dlg
= new dijit
. Dialog ({
976 id
: "filterNewRuleDlg" ,
977 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
978 style
: "width: 600px" ,
979 execute : function () {
980 if ( this . validate ()) {
981 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
989 exception_error ( "addFilterRule" , e
);
993 function addFilterAction ( replaceNode
, actionStr
) {
995 if ( dijit
. byId ( "filterNewActionDlg" ))
996 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
998 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
999 param_escape ( actionStr
);
1001 var rule_dlg
= new dijit
. Dialog ({
1002 id
: "filterNewActionDlg" ,
1003 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1004 style
: "width: 600px" ,
1005 execute : function () {
1006 if ( this . validate ()) {
1007 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1015 exception_error ( "addFilterAction" , e
);
1019 function quickAddFilter () {
1022 if (! inPreferences ()) {
1023 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1024 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1025 param_escape ( activeFeedIsCat ());
1027 query
= "backend.php?op=pref-filters&method=newfilter" ;
1032 if ( dijit
. byId ( "feedEditDlg" ))
1033 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1035 if ( dijit
. byId ( "filterEditDlg" ))
1036 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1038 dialog
= new dijit
. Dialog ({
1039 id
: "filterEditDlg" ,
1040 title
: __ ( "Create Filter" ),
1041 style
: "width: 600px" ,
1043 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1045 if ( dijit
. byId ( "filterTestDlg" ))
1046 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1048 var test_dlg
= new dijit
. Dialog ({
1049 id
: "filterTestDlg" ,
1050 title
: "Test Filter" ,
1051 style
: "width: 600px" ,
1056 selectRules : function ( select
) {
1057 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1060 e
. parentNode
. addClassName ( "Selected" );
1062 e
. parentNode
. removeClassName ( "Selected" );
1065 selectActions : function ( select
) {
1066 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1070 e
. parentNode
. addClassName ( "Selected" );
1072 e
. parentNode
. removeClassName ( "Selected" );
1076 editRule : function ( e
) {
1077 var li
= e
. parentNode
;
1078 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1079 addFilterRule ( li
, rule
);
1081 editAction : function ( e
) {
1082 var li
= e
. parentNode
;
1083 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1084 addFilterAction ( li
, action
);
1086 addAction : function () { addFilterAction (); },
1087 addRule : function () { addFilterRule (); },
1088 deleteAction : function () {
1089 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1091 deleteRule : function () {
1092 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1094 execute : function () {
1095 if ( this . validate ()) {
1097 var query
= dojo
. formToQuery ( "filter_new_form" );
1101 new Ajax
. Request ( "backend.php" , {
1103 onComplete : function ( transport
) {
1104 if ( inPreferences ()) {
1114 if (! inPreferences ()) {
1115 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1116 dojo
. disconnect ( lh
);
1118 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1120 new Ajax
. Request ( "backend.php" , {
1122 onComplete : function ( transport
) {
1123 var reply
= JSON
. parse ( transport
. responseText
);
1127 if ( reply
&& reply
) title
= reply
. title
;
1129 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1131 console
. log ( title
+ " " + getActiveFeedId ());
1133 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1136 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1138 addFilterRule ( null , dojo
. toJson ( rule
));
1149 exception_error ( "quickAddFilter" , e
);
1153 function resetPubSub ( feed_id
, title
) {
1155 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1157 if ( title
== undefined || confirm ( msg
)) {
1158 notify_progress ( "Loading, please wait..." );
1160 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1162 new Ajax
. Request ( "backend.php" , {
1164 onComplete : function ( transport
) {
1165 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1166 notify_info ( "Subscription reset." );
1174 function unsubscribeFeed ( feed_id
, title
) {
1176 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1178 if ( title
== undefined || confirm ( msg
)) {
1179 notify_progress ( "Removing feed..." );
1181 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1183 new Ajax
. Request ( "backend.php" , {
1185 onComplete : function ( transport
) {
1187 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1189 if ( inPreferences ()) {
1192 if ( feed_id
== getActiveFeedId ())
1193 setTimeout ( "viewfeed(-5)" , 100 );
1195 if ( feed_id
< 0 ) updateFeedList ();
1205 function backend_sanity_check_callback ( transport
) {
1209 if ( sanity_check_done
) {
1210 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1211 "presence of Firebug or some other disrupting extension. " +
1212 "Please disable it and try again." );
1216 var reply
= JSON
. parse ( transport
. responseText
);
1219 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1223 var error_code
= reply
[ 'error' ][ 'code' ];
1225 if ( error_code
&& error_code
!= 0 ) {
1226 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1229 console
. log ( "sanity check ok" );
1231 var params
= reply
[ 'init-params' ];
1234 console
. log ( 'reading init-params...' );
1239 console
. log ( "IP: " + k
+ " => " + v
);
1241 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1245 init_params
= params
;
1248 sanity_check_done
= true ;
1250 init_second_stage ();
1253 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1257 /*function has_local_storage() {
1259 return 'sessionStorage' in window && window['sessionStorage'] != null;
1265 function catSelectOnChange ( elem
) {
1267 /* var value = elem[elem.selectedIndex].value;
1268 var def = elem.getAttribute('default');
1270 if (value == "ADD_CAT") {
1273 dropboxSelect(elem, def);
1275 elem.selectedIndex = 0;
1281 exception_error ( "catSelectOnChange" , e
);
1285 function quickAddCat ( elem
) {
1287 var cat
= prompt ( __ ( "Please enter category title:" ));
1291 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1293 notify_progress ( "Loading, please wait..." , true );
1295 new Ajax
. Request ( "backend.php" , {
1297 onComplete : function ( transport
) {
1298 var response
= transport
. responseXML
;
1299 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1300 var options
= select
. getElementsByTagName ( "option" );
1302 dropbox_replace_options ( elem
, options
);
1311 exception_error ( "quickAddCat" , e
);
1315 function genUrlChangeKey ( feed
, is_cat
) {
1318 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1322 notify_progress ( "Trying to change address..." , true );
1324 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape ( feed
) +
1325 "&is_cat=" + param_escape ( is_cat
);
1327 new Ajax
. Request ( "backend.php" , {
1329 onComplete : function ( transport
) {
1330 var reply
= JSON
. parse ( transport
. responseText
);
1331 var new_link
= reply
. link
;
1333 var e
= $( 'gen_feed_url' );
1337 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1338 "&key=" + new_link
);
1340 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1341 "&key=" + new_link
);
1343 new Effect
. Highlight ( e
);
1348 notify_error ( "Could not change feed URL." );
1353 exception_error ( "genUrlChangeKey" , e
);
1358 function labelSelectOnChange ( elem
) {
1360 /* var value = elem[elem.selectedIndex].value;
1361 var def = elem.getAttribute('default');
1363 if (value == "ADD_LABEL") {
1366 dropboxSelect(elem, def);
1368 elem.selectedIndex = 0;
1370 addLabel(elem, function(transport) {
1374 var response = transport.responseXML;
1375 var select = response.getElementsByTagName("select")[0];
1376 var options = select.getElementsByTagName("option");
1378 dropbox_replace_options(elem, options);
1382 exception_error("addLabel", e);
1388 exception_error ( "labelSelectOnChange" , e
);
1392 function dropbox_replace_options ( elem
, options
) {
1395 while ( elem
. hasChildNodes ())
1396 elem
. removeChild ( elem
. firstChild
);
1400 for ( var i
= 0 ; i
< options
. length
; i
++) {
1401 var text
= options
[ i
]. firstChild
. nodeValue
;
1402 var value
= options
[ i
]. getAttribute ( "value" );
1404 if ( value
== undefined ) value
= text
;
1406 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1408 var option
= new Option ( text
, value
, issel
);
1410 if ( options
[ i
]. getAttribute ( "disabled" ))
1411 option
. setAttribute ( "disabled" , true );
1413 elem
. insert ( option
);
1415 if ( issel
) sel_idx
= i
;
1418 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1419 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1422 exception_error ( "dropbox_replace_options" , e
);
1426 // mode = all, none, invert
1427 function selectTableRows ( id
, mode
) {
1429 var rows
= $( id
). rows
;
1431 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1436 if ( row
. id
&& row
. className
) {
1437 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1438 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1440 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1441 var input
= inputs
[ j
];
1443 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1444 input
. id
. match ( bare_id
)) {
1447 dcb
= dijit
. getEnclosingWidget ( cb
);
1453 var issel
= row
. hasClassName ( "Selected" );
1455 if ( mode
== "all" && ! issel
) {
1456 row
. addClassName ( "Selected" );
1458 if ( dcb
) dcb
. set ( "checked" , true );
1459 } else if ( mode
== "none" && issel
) {
1460 row
. removeClassName ( "Selected" );
1462 if ( dcb
) dcb
. set ( "checked" , false );
1464 } else if ( mode
== "invert" ) {
1467 row
. removeClassName ( "Selected" );
1469 if ( dcb
) dcb
. set ( "checked" , false );
1471 row
. addClassName ( "Selected" );
1473 if ( dcb
) dcb
. set ( "checked" , true );
1481 exception_error ( "selectTableRows" , e
);
1486 function getSelectedTableRowIds ( id
) {
1490 var elem_rows
= $( id
). rows
;
1492 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1493 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1494 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1500 exception_error ( "getSelectedTableRowIds" , e
);
1506 function editFeed ( feed
, event
) {
1509 return alert ( __ ( "You can't edit this kind of feed." ));
1511 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1516 if ( dijit
. byId ( "filterEditDlg" ))
1517 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1519 if ( dijit
. byId ( "feedEditDlg" ))
1520 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1522 dialog
= new dijit
. Dialog ({
1524 title
: __ ( "Edit Feed" ),
1525 style
: "width: 600px" ,
1526 execute : function () {
1527 if ( this . validate ()) {
1528 // console.log(dojo.objectToQuery(this.attr('value')));
1530 notify_progress ( "Saving data..." , true );
1532 new Ajax
. Request ( "backend.php" , {
1533 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1534 onComplete : function ( transport
) {
1546 exception_error ( "editFeed" , e
);
1550 function feedBrowser () {
1552 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1554 if ( dijit
. byId ( "feedAddDlg" ))
1555 dijit
. byId ( "feedAddDlg" ). hide ();
1557 if ( dijit
. byId ( "feedBrowserDlg" ))
1558 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1560 var dialog
= new dijit
. Dialog ({
1561 id
: "feedBrowserDlg" ,
1562 title
: __ ( "More Feeds" ),
1563 style
: "width: 600px" ,
1564 getSelectedFeedIds : function () {
1565 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1566 var selected
= new Array ();
1568 list
. each ( function ( child
) {
1569 var id
= child
. id
. replace ( "FBROW-" , "" );
1571 if ( child
. hasClassName ( 'Selected' )) {
1578 getSelectedFeeds : function () {
1579 var list
= $$( "#browseFeedList li.Selected" );
1580 var selected
= new Array ();
1582 list
. each ( function ( child
) {
1583 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1584 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1586 selected
. push ([ title
, url
]);
1593 subscribe : function () {
1594 var mode
= this . attr ( 'value' ). mode
;
1598 selected
= this . getSelectedFeeds ();
1600 selected
= this . getSelectedFeedIds ();
1602 if ( selected
. length
> 0 ) {
1603 dijit
. byId ( "feedBrowserDlg" ). hide ();
1605 notify_progress ( "Loading, please wait..." , true );
1607 // we use dojo.toJson instead of JSON.stringify because
1608 // it somehow escapes everything TWICE, at least in Chrome 9
1610 var query
= "?op=rpc&method=massSubscribe&payload=" +
1611 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1615 new Ajax
. Request ( "backend.php" , {
1617 onComplete : function ( transport
) {
1623 alert ( __ ( "No feeds are selected." ));
1627 update : function () {
1628 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1630 Element
. show ( 'feed_browser_spinner' );
1632 new Ajax
. Request ( "backend.php" , {
1634 onComplete : function ( transport
) {
1637 Element
. hide ( 'feed_browser_spinner' );
1639 var c
= $( "browseFeedList" );
1641 var reply
= JSON
. parse ( transport
. responseText
);
1643 var r
= reply
[ 'content' ];
1644 var mode
= reply
[ 'mode' ];
1650 dojo
. parser
. parse ( "browseFeedList" );
1653 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1655 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1660 removeFromArchive : function () {
1661 var selected
= this . getSelectedFeedIds ();
1663 if ( selected
. length
> 0 ) {
1665 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1668 Element
. show ( 'feed_browser_spinner' );
1670 var query
= "?op=rpc&method=remarchive&ids=" +
1671 param_escape ( selected
. toString ());;
1673 new Ajax
. Request ( "backend.php" , {
1675 onComplete : function ( transport
) {
1681 execute : function () {
1682 if ( this . validate ()) {
1691 exception_error ( "editFeed" , e
);
1695 function showFeedsWithErrors () {
1697 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1699 if ( dijit
. byId ( "errorFeedsDlg" ))
1700 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1702 dialog
= new dijit
. Dialog ({
1703 id
: "errorFeedsDlg" ,
1704 title
: __ ( "Feeds with update errors" ),
1705 style
: "width: 600px" ,
1706 getSelectedFeeds : function () {
1707 return getSelectedTableRowIds ( "prefErrorFeedList" );
1709 removeSelected : function () {
1710 var sel_rows
= this . getSelectedFeeds ();
1712 console
. log ( sel_rows
);
1714 if ( sel_rows
. length
> 0 ) {
1715 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1718 notify_progress ( "Removing selected feeds..." , true );
1720 var query
= "?op=pref-feeds&method=remove&ids=" +
1721 param_escape ( sel_rows
. toString ());
1723 new Ajax
. Request ( "backend.php" , {
1725 onComplete : function ( transport
) {
1733 alert ( __ ( "No feeds are selected." ));
1736 execute : function () {
1737 if ( this . validate ()) {
1745 exception_error ( "showFeedsWithErrors" , e
);
1750 /* new support functions for SelectByTag */
1752 function get_all_tags ( selObj
){
1754 if ( ! selObj
) return "" ;
1757 var len
= selObj
. options
. length
;
1759 for ( var i
= 0 ; i
< len
; i
++){
1760 if ( selObj
. options
[ i
]. selected
) {
1761 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1765 if ( result
. length
> 0 ){
1766 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1772 exception_error ( "get_all_tags" , e
);
1776 function get_radio_checked ( radioObj
) {
1778 if (! radioObj
) return "" ;
1780 var len
= radioObj
. length
;
1782 if ( len
== undefined ){
1783 if ( radioObj
. checked
){
1784 return ( radioObj
. value
);
1790 for ( var i
= 0 ; i
< len
; i
++ ){
1791 if ( radioObj
[ i
]. checked
){
1792 return ( radioObj
[ i
]. value
);
1797 exception_error ( "get_radio_checked" , e
);
1802 function get_timestamp () {
1803 var date
= new Date ();
1804 return Math
. round ( date
. getTime () / 1000 );
1807 function helpDialog ( topic
) {
1809 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1811 if ( dijit
. byId ( "helpDlg" ))
1812 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1814 dialog
= new dijit
. Dialog ({
1817 style
: "width: 600px" ,
1824 exception_error ( "helpDialog" , e
);
1828 function htmlspecialchars_decode ( string
, quote_style
) {
1829 // http://kevin.vanzonneveld.net
1830 // + original by: Mirek Slugen
1831 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1832 // + bugfixed by: Mateusz "loonquawl" Zalega
1833 // + input by: ReverseSyntax
1834 // + input by: Slawomir Kaniecki
1835 // + input by: Scott Cariss
1836 // + input by: Francois
1837 // + bugfixed by: Onno Marsman
1838 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1839 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1840 // + input by: Ratheous
1841 // + input by: Mailfaker (http://www.weedem.fr/)
1842 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1843 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1844 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1845 // * returns 1: '<p>this -> "</p>'
1846 // * example 2: htmlspecialchars_decode("&quot;");
1847 // * returns 2: '"'
1851 if ( typeof quote_style
=== 'undefined' ) {
1854 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1857 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1858 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1863 if ( quote_style
=== 0 ) {
1866 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1867 quote_style
= []. concat ( quote_style
);
1868 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1869 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1870 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1872 } else if ( OPTS
[ quote_style
[ i
]]) {
1873 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1876 quote_style
= optTemp
;
1878 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1879 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1880 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1883 string
= string
. replace ( /"/g , '"' );
1885 // Put this in last place to avoid escape being double-decoded
1886 string
= string
. replace ( /&/g , '&' );
1892 function label_to_feed_id ( label
) {
1893 return _label_base_index
- 1 - Math
. abs ( label
);
1896 function feed_to_label_id ( feed
) {
1897 return _label_base_index
- 1 + Math
. abs ( feed
);