]>
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." ));
819 /* notify_progress("Searching for feed urls...", true);
821 new Ajax.Request("backend.php", {
822 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
823 onComplete: function(transport, dialog, feed_url) {
827 var reply = JSON.parse(transport.responseText);
829 var feeds = reply['urls'];
831 console.log(transport.responseText);
833 var select = dijit.byId("feedDlg_feedContainerSelect");
835 while (select.getOptions().length > 0)
836 select.removeOption(0);
839 for (var feedUrl in feeds) {
840 select.addOption({value: feedUrl, label: feeds[feedUrl]});
844 // if (count > 5) count = 5;
845 // select.size = count;
847 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
854 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
856 while ( select
. getOptions (). length
> 0 )
857 select
. removeOption ( 0 );
859 select
. addOption ({ value
: '' , label
: __ ( "Expand to select feed" )});
862 for ( var feedUrl
in feeds
) {
863 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
867 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
871 alert ( __ ( "Couldn't download the specified URL: %s" ).
872 replace ( "%s" , rc
[ 'message' ]));
875 alert ( __ ( "You are already subscribed to this feed." ));
880 exception_error ( "subscribeToFeed" , e
, transport
);
891 exception_error ( "quickAddFeed" , e
);
895 function createNewRuleElement ( parentNode
, replaceNode
) {
897 var form
= document
. forms
[ "filter_new_rule_form" ];
899 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
901 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
902 param_escape ( dojo
. formToJson ( form
));
906 new Ajax
. Request ( "backend.php" , {
908 onComplete : function ( transport
) {
910 var li
= dojo
. create ( "li" );
912 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
914 new dijit
. form
. CheckBox ({
915 onChange : function () {
916 toggleSelectListRow2 ( this ) },
919 dojo
. create ( "input" , { type
: "hidden" ,
921 value
: dojo
. formToJson ( form
) }, li
);
923 dojo
. create ( "span" , {
924 onclick : function () {
925 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
927 innerHTML
: transport
. responseText
}, li
);
930 parentNode
. replaceChild ( li
, replaceNode
);
932 parentNode
. appendChild ( li
);
935 exception_error ( "createNewRuleElement" , e
);
939 exception_error ( "createNewRuleElement" , e
);
943 function createNewActionElement ( parentNode
, replaceNode
) {
945 var form
= document
. forms
[ "filter_new_action_form" ];
947 if ( form
. action_id
. value
== 7 ) {
948 form
. action_param
. value
= form
. action_param_label
. value
;
951 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
952 param_escape ( dojo
. formToJson ( form
));
956 new Ajax
. Request ( "backend.php" , {
958 onComplete : function ( transport
) {
960 var li
= dojo
. create ( "li" );
962 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
964 new dijit
. form
. CheckBox ({
965 onChange : function () {
966 toggleSelectListRow2 ( this ) },
969 dojo
. create ( "input" , { type
: "hidden" ,
971 value
: dojo
. formToJson ( form
) }, li
);
973 dojo
. create ( "span" , {
974 onclick : function () {
975 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
977 innerHTML
: transport
. responseText
}, li
);
980 parentNode
. replaceChild ( li
, replaceNode
);
982 parentNode
. appendChild ( li
);
986 exception_error ( "createNewActionElement" , e
);
990 exception_error ( "createNewActionElement" , e
);
995 function addFilterRule ( replaceNode
, ruleStr
) {
997 if ( dijit
. byId ( "filterNewRuleDlg" ))
998 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1000 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1001 param_escape ( ruleStr
);
1003 var rule_dlg
= new dijit
. Dialog ({
1004 id
: "filterNewRuleDlg" ,
1005 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1006 style
: "width: 600px" ,
1007 execute : function () {
1008 if ( this . validate ()) {
1009 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1017 exception_error ( "addFilterRule" , e
);
1021 function addFilterAction ( replaceNode
, actionStr
) {
1023 if ( dijit
. byId ( "filterNewActionDlg" ))
1024 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1026 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1027 param_escape ( actionStr
);
1029 var rule_dlg
= new dijit
. Dialog ({
1030 id
: "filterNewActionDlg" ,
1031 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1032 style
: "width: 600px" ,
1033 execute : function () {
1034 if ( this . validate ()) {
1035 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1043 exception_error ( "addFilterAction" , e
);
1047 function quickAddFilter () {
1050 if (! inPreferences ()) {
1051 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1052 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1053 param_escape ( activeFeedIsCat ());
1055 query
= "backend.php?op=pref-filters&method=newfilter" ;
1060 if ( dijit
. byId ( "feedEditDlg" ))
1061 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1063 if ( dijit
. byId ( "filterEditDlg" ))
1064 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1066 dialog
= new dijit
. Dialog ({
1067 id
: "filterEditDlg" ,
1068 title
: __ ( "Create Filter" ),
1069 style
: "width: 600px" ,
1071 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1073 if ( dijit
. byId ( "filterTestDlg" ))
1074 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1076 var test_dlg
= new dijit
. Dialog ({
1077 id
: "filterTestDlg" ,
1078 title
: "Test Filter" ,
1079 style
: "width: 600px" ,
1084 selectRules : function ( select
) {
1085 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1088 e
. parentNode
. addClassName ( "Selected" );
1090 e
. parentNode
. removeClassName ( "Selected" );
1093 selectActions : function ( select
) {
1094 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1098 e
. parentNode
. addClassName ( "Selected" );
1100 e
. parentNode
. removeClassName ( "Selected" );
1104 editRule : function ( e
) {
1105 var li
= e
. parentNode
;
1106 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1107 addFilterRule ( li
, rule
);
1109 editAction : function ( e
) {
1110 var li
= e
. parentNode
;
1111 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1112 addFilterAction ( li
, action
);
1114 addAction : function () { addFilterAction (); },
1115 addRule : function () { addFilterRule (); },
1116 deleteAction : function () {
1117 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1119 deleteRule : function () {
1120 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1122 execute : function () {
1123 if ( this . validate ()) {
1125 var query
= dojo
. formToQuery ( "filter_new_form" );
1129 new Ajax
. Request ( "backend.php" , {
1131 onComplete : function ( transport
) {
1132 if ( inPreferences ()) {
1142 if (! inPreferences ()) {
1143 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1144 dojo
. disconnect ( lh
);
1146 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId ();
1148 new Ajax
. Request ( "backend.php" , {
1150 onComplete : function ( transport
) {
1151 var reply
= JSON
. parse ( transport
. responseText
);
1155 if ( reply
&& reply
) title
= reply
. title
;
1157 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1159 console
. log ( title
+ " " + getActiveFeedId ());
1161 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1164 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1166 addFilterRule ( null , dojo
. toJson ( rule
));
1177 exception_error ( "quickAddFilter" , e
);
1181 function resetPubSub ( feed_id
, title
) {
1183 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1185 if ( title
== undefined || confirm ( msg
)) {
1186 notify_progress ( "Loading, please wait..." );
1188 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1190 new Ajax
. Request ( "backend.php" , {
1192 onComplete : function ( transport
) {
1193 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1194 notify_info ( "Subscription reset." );
1202 function unsubscribeFeed ( feed_id
, title
) {
1204 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1206 if ( title
== undefined || confirm ( msg
)) {
1207 notify_progress ( "Removing feed..." );
1209 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1211 new Ajax
. Request ( "backend.php" , {
1213 onComplete : function ( transport
) {
1215 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1217 if ( inPreferences ()) {
1220 if ( feed_id
== getActiveFeedId ())
1221 setTimeout ( "viewfeed(-5)" , 100 );
1223 if ( feed_id
< 0 ) updateFeedList ();
1233 function backend_sanity_check_callback ( transport
) {
1237 if ( sanity_check_done
) {
1238 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1239 "presence of Firebug or some other disrupting extension. " +
1240 "Please disable it and try again." );
1244 var reply
= JSON
. parse ( transport
. responseText
);
1247 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1251 var error_code
= reply
[ 'error' ][ 'code' ];
1253 if ( error_code
&& error_code
!= 0 ) {
1254 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1257 console
. log ( "sanity check ok" );
1259 var params
= reply
[ 'init-params' ];
1262 console
. log ( 'reading init-params...' );
1267 console
. log ( "IP: " + k
+ " => " + v
);
1269 if ( k
== "label_base_index" ) _label_base_index
= parseInt ( v
);
1273 init_params
= params
;
1276 sanity_check_done
= true ;
1278 init_second_stage ();
1281 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1285 /*function has_local_storage() {
1287 return 'sessionStorage' in window && window['sessionStorage'] != null;
1293 function catSelectOnChange ( elem
) {
1295 /* var value = elem[elem.selectedIndex].value;
1296 var def = elem.getAttribute('default');
1298 if (value == "ADD_CAT") {
1301 dropboxSelect(elem, def);
1303 elem.selectedIndex = 0;
1309 exception_error ( "catSelectOnChange" , e
);
1313 function quickAddCat ( elem
) {
1315 var cat
= prompt ( __ ( "Please enter category title:" ));
1319 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1321 notify_progress ( "Loading, please wait..." , true );
1323 new Ajax
. Request ( "backend.php" , {
1325 onComplete : function ( transport
) {
1326 var response
= transport
. responseXML
;
1327 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1328 var options
= select
. getElementsByTagName ( "option" );
1330 dropbox_replace_options ( elem
, options
);
1339 exception_error ( "quickAddCat" , e
);
1343 function genUrlChangeKey ( feed
, is_cat
) {
1346 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1350 notify_progress ( "Trying to change address..." , true );
1352 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape ( feed
) +
1353 "&is_cat=" + param_escape ( is_cat
);
1355 new Ajax
. Request ( "backend.php" , {
1357 onComplete : function ( transport
) {
1358 var reply
= JSON
. parse ( transport
. responseText
);
1359 var new_link
= reply
. link
;
1361 var e
= $( 'gen_feed_url' );
1365 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1366 "&key=" + new_link
);
1368 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1369 "&key=" + new_link
);
1371 new Effect
. Highlight ( e
);
1376 notify_error ( "Could not change feed URL." );
1381 exception_error ( "genUrlChangeKey" , e
);
1386 function labelSelectOnChange ( elem
) {
1388 /* var value = elem[elem.selectedIndex].value;
1389 var def = elem.getAttribute('default');
1391 if (value == "ADD_LABEL") {
1394 dropboxSelect(elem, def);
1396 elem.selectedIndex = 0;
1398 addLabel(elem, function(transport) {
1402 var response = transport.responseXML;
1403 var select = response.getElementsByTagName("select")[0];
1404 var options = select.getElementsByTagName("option");
1406 dropbox_replace_options(elem, options);
1410 exception_error("addLabel", e);
1416 exception_error ( "labelSelectOnChange" , e
);
1420 function dropbox_replace_options ( elem
, options
) {
1423 while ( elem
. hasChildNodes ())
1424 elem
. removeChild ( elem
. firstChild
);
1428 for ( var i
= 0 ; i
< options
. length
; i
++) {
1429 var text
= options
[ i
]. firstChild
. nodeValue
;
1430 var value
= options
[ i
]. getAttribute ( "value" );
1432 if ( value
== undefined ) value
= text
;
1434 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1436 var option
= new Option ( text
, value
, issel
);
1438 if ( options
[ i
]. getAttribute ( "disabled" ))
1439 option
. setAttribute ( "disabled" , true );
1441 elem
. insert ( option
);
1443 if ( issel
) sel_idx
= i
;
1446 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1447 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1450 exception_error ( "dropbox_replace_options" , e
);
1454 // mode = all, none, invert
1455 function selectTableRows ( id
, mode
) {
1457 var rows
= $( id
). rows
;
1459 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1464 if ( row
. id
&& row
. className
) {
1465 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1466 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1468 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1469 var input
= inputs
[ j
];
1471 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1472 input
. id
. match ( bare_id
)) {
1475 dcb
= dijit
. getEnclosingWidget ( cb
);
1481 var issel
= row
. hasClassName ( "Selected" );
1483 if ( mode
== "all" && ! issel
) {
1484 row
. addClassName ( "Selected" );
1486 if ( dcb
) dcb
. set ( "checked" , true );
1487 } else if ( mode
== "none" && issel
) {
1488 row
. removeClassName ( "Selected" );
1490 if ( dcb
) dcb
. set ( "checked" , false );
1492 } else if ( mode
== "invert" ) {
1495 row
. removeClassName ( "Selected" );
1497 if ( dcb
) dcb
. set ( "checked" , false );
1499 row
. addClassName ( "Selected" );
1501 if ( dcb
) dcb
. set ( "checked" , true );
1509 exception_error ( "selectTableRows" , e
);
1514 function getSelectedTableRowIds ( id
) {
1518 var elem_rows
= $( id
). rows
;
1520 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1521 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1522 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1528 exception_error ( "getSelectedTableRowIds" , e
);
1534 function editFeed ( feed
, event
) {
1537 return alert ( __ ( "You can't edit this kind of feed." ));
1539 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1544 if ( dijit
. byId ( "filterEditDlg" ))
1545 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1547 if ( dijit
. byId ( "feedEditDlg" ))
1548 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1550 dialog
= new dijit
. Dialog ({
1552 title
: __ ( "Edit Feed" ),
1553 style
: "width: 600px" ,
1554 execute : function () {
1555 if ( this . validate ()) {
1556 // console.log(dojo.objectToQuery(this.attr('value')));
1558 notify_progress ( "Saving data..." , true );
1560 new Ajax
. Request ( "backend.php" , {
1561 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1562 onComplete : function ( transport
) {
1574 exception_error ( "editFeed" , e
);
1578 function feedBrowser () {
1580 var query
= "backend.php?op=feeds&method=feedBrowser" ;
1582 if ( dijit
. byId ( "feedAddDlg" ))
1583 dijit
. byId ( "feedAddDlg" ). hide ();
1585 if ( dijit
. byId ( "feedBrowserDlg" ))
1586 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1588 var dialog
= new dijit
. Dialog ({
1589 id
: "feedBrowserDlg" ,
1590 title
: __ ( "More Feeds" ),
1591 style
: "width: 600px" ,
1592 getSelectedFeedIds : function () {
1593 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1594 var selected
= new Array ();
1596 list
. each ( function ( child
) {
1597 var id
= child
. id
. replace ( "FBROW-" , "" );
1599 if ( child
. hasClassName ( 'Selected' )) {
1606 getSelectedFeeds : function () {
1607 var list
= $$( "#browseFeedList li.Selected" );
1608 var selected
= new Array ();
1610 list
. each ( function ( child
) {
1611 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1612 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1614 selected
. push ([ title
, url
]);
1621 subscribe : function () {
1622 var mode
= this . attr ( 'value' ). mode
;
1626 selected
= this . getSelectedFeeds ();
1628 selected
= this . getSelectedFeedIds ();
1630 if ( selected
. length
> 0 ) {
1631 dijit
. byId ( "feedBrowserDlg" ). hide ();
1633 notify_progress ( "Loading, please wait..." , true );
1635 // we use dojo.toJson instead of JSON.stringify because
1636 // it somehow escapes everything TWICE, at least in Chrome 9
1638 var query
= "?op=rpc&method=massSubscribe&payload=" +
1639 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1643 new Ajax
. Request ( "backend.php" , {
1645 onComplete : function ( transport
) {
1651 alert ( __ ( "No feeds are selected." ));
1655 update : function () {
1656 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1658 Element
. show ( 'feed_browser_spinner' );
1660 new Ajax
. Request ( "backend.php" , {
1662 onComplete : function ( transport
) {
1665 Element
. hide ( 'feed_browser_spinner' );
1667 var c
= $( "browseFeedList" );
1669 var reply
= JSON
. parse ( transport
. responseText
);
1671 var r
= reply
[ 'content' ];
1672 var mode
= reply
[ 'mode' ];
1678 dojo
. parser
. parse ( "browseFeedList" );
1681 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1683 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1688 removeFromArchive : function () {
1689 var selected
= this . getSelectedFeedIds ();
1691 if ( selected
. length
> 0 ) {
1693 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1696 Element
. show ( 'feed_browser_spinner' );
1698 var query
= "?op=rpc&method=remarchive&ids=" +
1699 param_escape ( selected
. toString ());;
1701 new Ajax
. Request ( "backend.php" , {
1703 onComplete : function ( transport
) {
1709 execute : function () {
1710 if ( this . validate ()) {
1719 exception_error ( "editFeed" , e
);
1723 function showFeedsWithErrors () {
1725 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1727 if ( dijit
. byId ( "errorFeedsDlg" ))
1728 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1730 dialog
= new dijit
. Dialog ({
1731 id
: "errorFeedsDlg" ,
1732 title
: __ ( "Feeds with update errors" ),
1733 style
: "width: 600px" ,
1734 getSelectedFeeds : function () {
1735 return getSelectedTableRowIds ( "prefErrorFeedList" );
1737 removeSelected : function () {
1738 var sel_rows
= this . getSelectedFeeds ();
1740 console
. log ( sel_rows
);
1742 if ( sel_rows
. length
> 0 ) {
1743 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1746 notify_progress ( "Removing selected feeds..." , true );
1748 var query
= "?op=pref-feeds&method=remove&ids=" +
1749 param_escape ( sel_rows
. toString ());
1751 new Ajax
. Request ( "backend.php" , {
1753 onComplete : function ( transport
) {
1761 alert ( __ ( "No feeds are selected." ));
1764 execute : function () {
1765 if ( this . validate ()) {
1773 exception_error ( "showFeedsWithErrors" , e
);
1778 /* new support functions for SelectByTag */
1780 function get_all_tags ( selObj
){
1782 if ( ! selObj
) return "" ;
1785 var len
= selObj
. options
. length
;
1787 for ( var i
= 0 ; i
< len
; i
++){
1788 if ( selObj
. options
[ i
]. selected
) {
1789 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1793 if ( result
. length
> 0 ){
1794 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1800 exception_error ( "get_all_tags" , e
);
1804 function get_radio_checked ( radioObj
) {
1806 if (! radioObj
) return "" ;
1808 var len
= radioObj
. length
;
1810 if ( len
== undefined ){
1811 if ( radioObj
. checked
){
1812 return ( radioObj
. value
);
1818 for ( var i
= 0 ; i
< len
; i
++ ){
1819 if ( radioObj
[ i
]. checked
){
1820 return ( radioObj
[ i
]. value
);
1825 exception_error ( "get_radio_checked" , e
);
1830 function get_timestamp () {
1831 var date
= new Date ();
1832 return Math
. round ( date
. getTime () / 1000 );
1835 function helpDialog ( topic
) {
1837 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1839 if ( dijit
. byId ( "helpDlg" ))
1840 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1842 dialog
= new dijit
. Dialog ({
1845 style
: "width: 600px" ,
1852 exception_error ( "helpDialog" , e
);
1856 function htmlspecialchars_decode ( string
, quote_style
) {
1857 // http://kevin.vanzonneveld.net
1858 // + original by: Mirek Slugen
1859 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1860 // + bugfixed by: Mateusz "loonquawl" Zalega
1861 // + input by: ReverseSyntax
1862 // + input by: Slawomir Kaniecki
1863 // + input by: Scott Cariss
1864 // + input by: Francois
1865 // + bugfixed by: Onno Marsman
1866 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1867 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1868 // + input by: Ratheous
1869 // + input by: Mailfaker (http://www.weedem.fr/)
1870 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1871 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1872 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1873 // * returns 1: '<p>this -> "</p>'
1874 // * example 2: htmlspecialchars_decode("&quot;");
1875 // * returns 2: '"'
1879 if ( typeof quote_style
=== 'undefined' ) {
1882 string
= string
. toString (). replace ( /</g , '<' ). replace ( />/g , '>' );
1885 'ENT_HTML_QUOTE_SINGLE' : 1 ,
1886 'ENT_HTML_QUOTE_DOUBLE' : 2 ,
1891 if ( quote_style
=== 0 ) {
1894 if ( typeof quote_style
!== 'number' ) { // Allow for a single string or an array of string flags
1895 quote_style
= []. concat ( quote_style
);
1896 for ( i
= 0 ; i
< quote_style
. length
; i
++) {
1897 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1898 if ( OPTS
[ quote_style
[ i
]] === 0 ) {
1900 } else if ( OPTS
[ quote_style
[ i
]]) {
1901 optTemp
= optTemp
| OPTS
[ quote_style
[ i
]];
1904 quote_style
= optTemp
;
1906 if ( quote_style
& OPTS
. ENT_HTML_QUOTE_SINGLE
) {
1907 string
= string
. replace ( /�*39;/g , "'" ); // PHP doesn't currently escape if more than one 0, but it should
1908 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1911 string
= string
. replace ( /"/g , '"' );
1913 // Put this in last place to avoid escape being double-decoded
1914 string
= string
. replace ( /&/g , '&' );
1920 function label_to_feed_id ( label
) {
1921 return _label_base_index
- 1 - Math
. abs ( label
);
1924 function feed_to_label_id ( feed
) {
1925 return _label_base_index
- 1 + Math
. abs ( feed
);