]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
ba83a99008d0109d719e6d6058fb3cb01d18f1e0
3 class Pref_Prefs
extends Handler_Protected
{
5 private $pref_help = array ();
6 private $pref_sections = array ();
8 function csrf_ignore ( $method ) {
9 $csrf_ignored = array ( "index" , "updateself" , "customizecss" , "editprefprofiles" );
11 return array_search ( $method , $csrf_ignored ) !== false ;
14 function __construct ( $args ) {
15 parent
:: __construct ( $args );
17 $this -> pref_sections
= array (
24 $this -> pref_help
= array (
25 "ALLOW_DUPLICATE_POSTS" => array ( __ ( "Allow duplicate articles" ), "" ),
26 "AUTO_ASSIGN_LABELS" => array ( __ ( "Assign articles to labels automatically" ), "" ),
27 "BLACKLISTED_TAGS" => array ( __ ( "Blacklisted tags" ), __ ( "When auto-detecting tags in articles these tags will not be applied (comma-separated list)." )),
28 "CDM_AUTO_CATCHUP" => array ( __ ( "Automatically mark articles as read" ), __ ( "This option enables marking articles as read automatically while you scroll article list." )),
29 "CDM_EXPANDED" => array ( __ ( "Automatically expand articles in combined mode" ), "" ),
30 "COMBINED_DISPLAY_MODE" => array ( __ ( "Combined feed display" ), __ ( "Display expanded list of feed articles, instead of separate displays for headlines and article content" )),
31 "CONFIRM_FEED_CATCHUP" => array ( __ ( "Confirm marking feed as read" ), "" ),
32 "DEFAULT_ARTICLE_LIMIT" => array ( __ ( "Amount of articles to display at once" ), "" ),
33 "DEFAULT_UPDATE_INTERVAL" => array ( __ ( "Default feed update interval" ), __ ( "Shortest interval at which a feed will be checked for updates regardless of update method" )),
34 "DIGEST_CATCHUP" => array ( __ ( "Mark articles in e-mail digest as read" ), "" ),
35 "DIGEST_ENABLE" => array ( __ ( "Enable e-mail digest" ), __ ( "This option enables sending daily digest of new (and unread) headlines on your configured e-mail address" )),
36 "DIGEST_PREFERRED_TIME" => array ( __ ( "Try to send digests around specified time" ), __ ( "Uses UTC timezone" )),
37 "ENABLE_API_ACCESS" => array ( __ ( "Enable API access" ), __ ( "Allows external clients to access this account through the API" )),
38 "ENABLE_FEED_CATS" => array ( __ ( "Enable feed categories" ), "" ),
39 "FEEDS_SORT_BY_UNREAD" => array ( __ ( "Sort feeds by unread articles count" ), "" ),
40 "FRESH_ARTICLE_MAX_AGE" => array ( __ ( "Maximum age of fresh articles (in hours)" ), "" ),
41 "HIDE_READ_FEEDS" => array ( __ ( "Hide feeds with no unread articles" ), "" ),
42 "HIDE_READ_SHOWS_SPECIAL" => array ( __ ( "Show special feeds when hiding read feeds" ), "" ),
43 "LONG_DATE_FORMAT" => array ( __ ( "Long date format" ), "" ),
44 "ON_CATCHUP_SHOW_NEXT_FEED" => array ( __ ( "On catchup show next feed" ), __ ( "Automatically open next feed with unread articles after marking one as read" )),
45 "PURGE_OLD_DAYS" => array ( __ ( "Purge articles after this number of days (0 - disables)" ), "" ),
46 "PURGE_UNREAD_ARTICLES" => array ( __ ( "Purge unread articles" ), "" ),
47 "REVERSE_HEADLINES" => array ( __ ( "Reverse headline order (oldest first)" ), "" ),
48 "SHORT_DATE_FORMAT" => array ( __ ( "Short date format" ), "" ),
49 "SHOW_CONTENT_PREVIEW" => array ( __ ( "Show content preview in headlines list" ), "" ),
50 "SORT_HEADLINES_BY_FEED_DATE" => array ( __ ( "Sort headlines by feed date" ), __ ( "Use feed-specified date to sort headlines instead of local import date." )),
51 "SSL_CERT_SERIAL" => array ( __ ( "Login with an SSL certificate" ), __ ( "Click to register your SSL client certificate with tt-rss" )),
52 "STRIP_IMAGES" => array ( __ ( "Do not embed images in articles" ), "" ),
53 "STRIP_UNSAFE_TAGS" => array ( __ ( "Strip unsafe tags from articles" ), __ ( "Strip all but most common HTML tags when reading articles." )),
54 "USER_STYLESHEET" => array ( __ ( "Customize stylesheet" ), __ ( "Customize CSS stylesheet to your liking" )),
55 "USER_TIMEZONE" => array ( __ ( "Time zone" ), "" ),
56 "VFEED_GROUP_BY_FEED" => array ( __ ( "Group headlines in virtual feeds" ), __ ( "Special feeds, labels, and categories are grouped by originating feeds" )),
57 "USER_LANGUAGE" => array ( __ ( "Language" )),
58 "USER_CSS_THEME" => array ( __ ( "Theme" ), __ ( "Select one of the available CSS themes" ))
62 function changepassword () {
64 $old_pw = $_POST [ "old_password" ];
65 $new_pw = $_POST [ "new_password" ];
66 $con_pw = $_POST [ "confirm_password" ];
69 print "ERROR: " . __ ( "Old password cannot be blank." );
74 print "ERROR: " . __ ( "New password cannot be blank." );
78 if ( $new_pw != $con_pw ) {
79 print "ERROR: " . __ ( "Entered passwords do not match." );
83 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
85 if ( method_exists ( $authenticator , "change_password" )) {
86 print $authenticator -> change_password ( $_SESSION [ "uid" ], $old_pw , $new_pw );
88 print "ERROR: " . __ ( "Function not supported by authentication module." );
92 function saveconfig () {
93 $boolean_prefs = explode ( "," , $_POST [ "boolean_prefs" ]);
95 foreach ( $boolean_prefs as $pref ) {
96 if (! isset ( $_POST [ $pref ])) $_POST [ $pref ] = 'false' ;
101 foreach ( array_keys ( $_POST ) as $pref_name ) {
103 $pref_name = $this -> dbh
-> escape_string ( $pref_name );
104 $value = $this -> dbh
-> escape_string ( $_POST [ $pref_name ]);
106 if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
107 if ( get_pref ( 'DIGEST_PREFERRED_TIME' ) != $value ) {
109 $this -> dbh
-> query ( "UPDATE ttrss_users SET
110 last_digest_sent = NULL WHERE id = " . $_SESSION [ 'uid' ]);
115 if ( $pref_name == "USER_LANGUAGE" ) {
116 if ( $_SESSION [ "language" ] != $value ) {
121 set_pref ( $pref_name , $value );
125 print "PREFS_NEED_RELOAD" ;
127 print __ ( "The configuration was saved." );
133 $pref_name = $this -> dbh
-> escape_string ( $_REQUEST [ "pn" ]);
135 $result = $this -> dbh
-> query ( "SELECT help_text FROM ttrss_prefs
136 WHERE pref_name = ' $pref_name '" );
138 if ( $this -> dbh
-> num_rows ( $result ) > 0 ) {
139 $help_text = $this -> dbh
-> fetch_result ( $result , 0 , "help_text" );
142 printf ( __ ( "Unknown option: %s " ), $pref_name );
146 function changeemail () {
148 $email = $this -> dbh
-> escape_string ( $_POST [ "email" ]);
149 $full_name = $this -> dbh
-> escape_string ( $_POST [ "full_name" ]);
151 $active_uid = $_SESSION [ "uid" ];
153 $this -> dbh
-> query ( "UPDATE ttrss_users SET email = ' $email ',
154 full_name = ' $full_name ' WHERE id = ' $active_uid '" );
156 print __ ( "Your personal data has been saved." );
161 function resetconfig () {
163 $_SESSION [ "prefs_op_result" ] = "reset-to-defaults" ;
165 if ( $_SESSION [ "profile" ]) {
166 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
168 $profile_qpart = "profile IS NULL" ;
171 $this -> dbh
-> query ( "DELETE FROM ttrss_user_prefs
172 WHERE $profile_qpart AND owner_uid = " . $_SESSION [ "uid" ]);
174 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
176 echo __ ( "Your preferences are now set to default values." );
181 global $access_level_names ;
183 $prefs_blacklist = array ( "STRIP_UNSAFE_TAGS" , "REVERSE_HEADLINES" ,
184 "SORT_HEADLINES_BY_FEED_DATE" , "DEFAULT_ARTICLE_LIMIT" );
186 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
188 $profile_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "PURGE_OLD_DAYS" ,
189 "PURGE_UNREAD_ARTICLES" , "DIGEST_ENABLE" , "DIGEST_CATCHUP" ,
190 "BLACKLISTED_TAGS" , "ENABLE_API_ACCESS" , "UPDATE_POST_ON_CHECKSUM_CHANGE" ,
191 "DEFAULT_UPDATE_INTERVAL" , "USER_TIMEZONE" , "SORT_HEADLINES_BY_FEED_DATE" ,
192 "SSL_CERT_SERIAL" , "DIGEST_PREFERRED_TIME" );
195 $_SESSION [ "prefs_op_result" ] = "" ;
197 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
198 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Personal data / Authentication' ). " \" >" ;
200 print "<form dojoType= \" dijit.form.Form \" id= \" changeUserdataForm \" >" ;
202 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
203 evt.preventDefault();
204 if (this.validate()) {
205 notify_progress('Saving data...', true);
207 new Ajax.Request('backend.php', {
208 parameters: dojo.objectToQuery(this.getValues()),
209 onComplete: function(transport) {
210 notify_callback2(transport);
216 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
218 print "<h2>" . __ ( "Personal data" ) . "</h2>" ;
220 $result = $this -> dbh
-> query ( "SELECT email,full_name,otp_enabled,
221 access_level FROM ttrss_users
222 WHERE id = " . $_SESSION [ "uid" ]);
224 $email = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "email" ));
225 $full_name = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "full_name" ));
226 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
228 print "<tr><td width= \" 40% \" >" . __ ( 'Full name' ). "</td>" ;
229 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" full_name \" required= \" 1 \"
230 value= \" $full_name\" ></td></tr>" ;
232 print "<tr><td width= \" 40% \" >" . __ ( 'E-mail' ). "</td>" ;
233 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" email \" required= \" 1 \" value= \" $email\" ></td></tr>" ;
235 if (! SINGLE_USER_MODE
&& ! $_SESSION [ "hide_hello" ]) {
237 $access_level = $this -> dbh
-> fetch_result ( $result , 0 , "access_level" );
238 print "<tr><td width= \" 40% \" >" . __ ( 'Access level' ). "</td>" ;
239 print "<td>" . $access_level_names [ $access_level ] . "</td></tr>" ;
244 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
245 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changeemail \" >" ;
247 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
248 __ ( "Save data" ). "</button>" ;
252 if ( $_SESSION [ "auth_module" ]) {
253 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
255 $authenticator = false ;
258 if ( $authenticator && method_exists ( $authenticator , "change_password" )) {
260 print "<h2>" . __ ( "Password" ) . "</h2>" ;
262 $result = $this -> dbh
-> query ( "SELECT id FROM ttrss_users
263 WHERE id = " . $_SESSION [ "uid" ]. " AND pwd_hash
264 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'" );
266 if ( $this -> dbh
-> num_rows ( $result ) != 0 ) {
267 print format_warning ( __ ( "Your password is at default value, please change it." ), "default_pass_warning" );
270 print "<form dojoType= \" dijit.form.Form \" >" ;
272 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
273 evt.preventDefault();
274 if (this.validate()) {
275 notify_progress('Changing password...', true);
277 new Ajax.Request('backend.php', {
278 parameters: dojo.objectToQuery(this.getValues()),
279 onComplete: function(transport) {
281 if (transport.responseText.indexOf('ERROR: ') == 0) {
282 notify_error(transport.responseText.replace('ERROR: ', ''));
284 notify_info(transport.responseText);
285 var warn = $('default_pass_warning');
286 if (warn) Element.hide(warn);
294 print_notice ( __ ( "Changing your current password will disable OTP." ));
297 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
299 print "<tr><td width= \" 40% \" >" . __ ( "Old password" ). "</td>" ;
300 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" old_password \" ></td></tr>" ;
302 print "<tr><td width= \" 40% \" >" . __ ( "New password" ). "</td>" ;
304 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
305 name= \" new_password \" ></td></tr>" ;
307 print "<tr><td width= \" 40% \" >" . __ ( "Confirm password" ). "</td>" ;
309 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" confirm_password \" ></td></tr>" ;
313 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
314 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changepassword \" >" ;
316 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
317 __ ( "Change password" ). "</button>" ;
321 if ( $_SESSION [ "auth_module" ] == "auth_internal" ) {
323 print "<h2>" . __ ( "One time passwords / Authenticator" ) . "</h2>" ;
327 print_notice ( __ ( "One time passwords are currently enabled. Enter your current password below to disable." ));
329 print "<form dojoType= \" dijit.form.Form \" >" ;
331 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
332 evt.preventDefault();
333 if (this.validate()) {
334 notify_progress('Disabling OTP', true);
336 new Ajax.Request('backend.php', {
337 parameters: dojo.objectToQuery(this.getValues()),
338 onComplete: function(transport) {
340 if (transport.responseText.indexOf('ERROR: ') == 0) {
341 notify_error(transport.responseText.replace('ERROR: ', ''));
343 window.location.reload();
350 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
352 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
354 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
355 name= \" password \" ></td></tr>" ;
359 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
360 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpdisable \" >" ;
362 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
363 __ ( "Disable OTP" ). "</button>" ;
367 } else if ( function_exists ( "imagecreatefromstring" )) {
369 print "<p>" . __ ( "You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP." ) . "</p>" ;
371 print "<p>" . __ ( "Scan the following code by the Authenticator application:" ). "</p>" ;
373 $csrf_token = $_SESSION [ "csrf_token" ];
375 print "<img src= \" backend.php?op=pref-prefs&method=otpqrcode&csrf_token= $csrf_token\" >" ;
377 print "<form dojoType= \" dijit.form.Form \" id= \" changeOtpForm \" >" ;
379 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
380 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpenable \" >" ;
382 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
383 evt.preventDefault();
384 if (this.validate()) {
385 notify_progress('Saving data...', true);
387 new Ajax.Request('backend.php', {
388 parameters: dojo.objectToQuery(this.getValues()),
389 onComplete: function(transport) {
391 if (transport.responseText.indexOf('ERROR:') == 0) {
392 notify_error(transport.responseText.replace('ERROR:', ''));
394 window.location.reload();
401 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
403 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
405 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
406 name= \" password \" ></td></tr>" ;
408 print "<tr><td width= \" 40% \" >" . __ ( "Enter the generated one time password" ). "</td>" ;
410 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" autocomplete= \" off \"
412 name= \" otp \" ></td></tr>" ;
414 print "<tr><td colspan= \" 2 \" >" ;
416 print "</td></tr><tr><td colspan= \" 2 \" >" ;
421 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
422 __ ( "Enable OTP" ). "</button>" ;
428 print_notice ( __ ( "PHP GD functions are required for OTP support." ));
435 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
436 "hook_prefs_tab_section" , "prefPrefsAuth" );
438 print "</div>" ; #pane
440 print "<div dojoType= \" dijit.layout.AccordionPane \" selected= \" true \" title= \" " . __ ( 'Preferences' ). " \" >" ;
442 print "<form dojoType= \" dijit.form.Form \" id= \" changeSettingsForm \" >" ;
444 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt, quit \" >
445 if (evt) evt.preventDefault();
446 if (this.validate()) {
447 console.log(dojo.objectToQuery(this.getValues()));
449 new Ajax.Request('backend.php', {
450 parameters: dojo.objectToQuery(this.getValues()),
451 onComplete: function(transport) {
452 var msg = transport.responseText;
456 if (msg == 'PREFS_NEED_RELOAD') {
457 window.location.reload();
466 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
468 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">' ;
470 if ( $_SESSION [ "profile" ]) {
471 print_notice ( __ ( "Some preferences are only available in default profile." ));
474 if ( $_SESSION [ "profile" ]) {
475 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
476 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
478 initialize_user_prefs ( $_SESSION [ "uid" ]);
479 $profile_qpart = "profile IS NULL" ;
482 /* if ($_SESSION["prefs_show_advanced"])
483 $access_query = "true";
485 $access_query = "(access_level = 0 AND section_id != 3)"; */
487 $access_query = 'true' ;
489 $result = $this -> dbh
-> query ( "SELECT DISTINCT
490 ttrss_user_prefs.pref_name,value,type_name,
491 ttrss_prefs_sections.order_id,
493 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
494 WHERE type_id = ttrss_prefs_types.id AND
496 section_id = ttrss_prefs_sections.id AND
497 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
499 owner_uid = " . $_SESSION [ "uid" ]. "
500 ORDER BY ttrss_prefs_sections.order_id,pref_name" );
504 $active_section = "" ;
506 $listed_boolean_prefs = array ();
508 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
510 if ( in_array ( $line [ "pref_name" ], $prefs_blacklist )) {
514 $type_name = $line [ "type_name" ];
515 $pref_name = $line [ "pref_name" ];
516 $section_name = $this -> getSectionName ( $line [ "section_id" ]);
517 $value = $line [ "value" ];
519 $short_desc = $this -> getShortDesc ( $pref_name );
520 $help_text = $this -> getHelpText ( $pref_name );
522 if (! $short_desc ) continue ;
524 if ( $_SESSION [ "profile" ] && in_array ( $line [ "pref_name" ],
525 $profile_blacklist )) {
529 if ( $active_section != $line [ "section_id" ]) {
531 if ( $active_section != "" ) {
535 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
537 $active_section = $line [ "section_id" ];
539 print "<tr><td colspan= \" 3 \" ><h3>" . $section_name . "</h3></td></tr>" ;
546 print "<td width= \" 40% \" class= \" prefName \" id= \" $pref_name\" >" ;
547 print "<label for='CB_ $pref_name '>" ;
551 if ( $help_text ) print "<div class= \" prefHelp \" >" . __ ( $help_text ). "</div>" ;
555 print "<td class= \" prefValue \" >" ;
557 if ( $pref_name == "USER_LANGUAGE" ) {
558 print_select_hash ( $pref_name , $value , get_translations (),
559 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'" );
561 } else if ( $pref_name == "USER_TIMEZONE" ) {
563 $timezones = explode ( " \n " , file_get_contents ( "lib/timezones.txt" ));
565 print_select ( $pref_name , $value , $timezones , 'dojoType="dijit.form.FilteringSelect"' );
566 } else if ( $pref_name == "USER_STYLESHEET" ) {
568 print "<button dojoType= \" dijit.form.Button \"
569 onclick= \" customizeCSS() \" >" . __ ( 'Customize' ) . "</button>" ;
571 } else if ( $pref_name == "USER_CSS_THEME" ) {
573 $themes = array_map ( "basename" , glob ( "themes/*.css" ));
575 print_select ( $pref_name , $value , $themes ,
576 'dojoType="dijit.form.Select"' );
579 } else if ( $pref_name == "DEFAULT_UPDATE_INTERVAL" ) {
581 global $update_intervals_nodefault ;
583 print_select_hash ( $pref_name , $value , $update_intervals_nodefault ,
584 'dojoType="dijit.form.Select"' );
586 } else if ( $type_name == "bool" ) {
588 array_push ( $listed_boolean_prefs , $pref_name );
590 $checked = ( $value == "true" ) ?
"checked= \" checked \" " : "" ;
592 if ( $pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0 ) {
593 $disabled = "disabled= \" 1 \" " ;
594 $checked = "checked= \" checked \" " ;
599 print "<input type='checkbox' name=' $pref_name ' $checked $disabled
600 dojoType='dijit.form.CheckBox' id='CB_ $pref_name ' value='1'>" ;
602 } else if ( array_search ( $pref_name , array ( 'FRESH_ARTICLE_MAX_AGE' ,
603 'PURGE_OLD_DAYS' , 'LONG_DATE_FORMAT' , 'SHORT_DATE_FORMAT' )) !== false ) {
605 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
607 if ( $pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0 ) {
608 $disabled = "disabled= \" 1 \" " ;
609 $value = FORCE_ARTICLE_PURGE
;
614 print "<input dojoType= \" dijit.form.ValidationTextBox \"
615 required= \" 1 \" $regexp $disabled
616 name= \" $pref_name\" value= \" $value\" >" ;
618 } else if ( $pref_name == "SSL_CERT_SERIAL" ) {
620 print "<input dojoType= \" dijit.form.ValidationTextBox \"
621 id= \" SSL_CERT_SERIAL \" readonly= \" 1 \"
622 name= \" $pref_name\" value= \" $value\" >" ;
624 $cert_serial = htmlspecialchars ( get_ssl_certificate_id ());
625 $has_serial = ( $cert_serial ) ?
"false" : "true" ;
627 print " <button dojoType= \" dijit.form.Button \" disabled= \" $has_serial\"
628 onclick= \" insertSSLserial(' $cert_serial ') \" >" .
629 __ ( 'Register' ) . "</button>" ;
631 print " <button dojoType= \" dijit.form.Button \"
632 onclick= \" insertSSLserial('') \" >" .
633 __ ( 'Clear' ) . "</button>" ;
635 } else if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
636 print "<input dojoType= \" dijit.form.ValidationTextBox \"
637 id= \" $pref_name\" regexp= \" [012]?\d:\d\d \" placeHolder= \" 12:00 \"
638 name= \" $pref_name\" value= \" $value\" ><div class= \" insensitive \" >" .
639 T_sprintf ( "Current server time: %s (UTC)" , date ( "H:i" )) . "</div>" ;
641 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
643 print "<input dojoType= \" dijit.form.ValidationTextBox \"
645 name= \" $pref_name\" value= \" $value\" >" ;
657 $listed_boolean_prefs = htmlspecialchars ( join ( "," , $listed_boolean_prefs ));
659 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" boolean_prefs \" value= \" $listed_boolean_prefs\" >" ;
661 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
662 "hook_prefs_tab_section" , "prefPrefsPrefsInside" );
664 print '</div>' ; # inside pane
665 print '<div dojoType="dijit.layout.ContentPane" region="bottom">' ;
667 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
668 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" saveconfig \" >" ;
670 print "<div dojoType= \" dijit.form.ComboButton \" type= \" submit \" >
671 <span>" . __ ( 'Save configuration' ). "</span>
672 <div dojoType= \" dijit.DropDownMenu \" >
673 <div dojoType= \" dijit.MenuItem \"
674 onclick= \" dijit.byId('changeSettingsForm').onSubmit(null, true) \" >" .
675 __ ( "Save and exit preferences" ). "</div>
679 print "<button dojoType= \" dijit.form.Button \" onclick= \" return editProfiles() \" >" .
680 __ ( 'Manage profiles' ). "</button> " ;
682 print "<button dojoType= \" dijit.form.Button \" onclick= \" return validatePrefsReset() \" >" .
683 __ ( 'Reset to defaults' ). "</button>" ;
687 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
689 print "<input onclick='toggleAdvancedPrefs()'
690 id='prefs_show_advanced'
691 dojoType=\"dijit.form.CheckBox\"
693 type=\"checkbox\"></input>
694 <label for='prefs_show_advanced'>" .
695 __("Show additional preferences") . "</label>"; */
697 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
698 "hook_prefs_tab_section" , "prefPrefsPrefsOutside" );
701 print '</div>' ; # inner pane
702 print '</div>' ; # border container
704 print "</div>" ; #pane
706 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Plugins' ). " \" >" ;
708 print "<h2>" . __ ( "Plugins" ). "</h2>" ;
710 print "<p>" . __ ( "You will need to reload Tiny Tiny RSS for plugin changes to take effect." ) . "</p>" ;
712 print_notice ( __ ( "Download more plugins at tt-rss.org <a class= \" visibleLink \" target= \" _blank \" href= \" http://tt-rss.org/forum/viewforum.php?f=22 \" >forums</a> or <a target= \" _blank \" class= \" visibleLink \" href= \" http://tt-rss.org/wiki/Plugins \" >wiki</a>." ));
714 print "<form dojoType= \" dijit.form.Form \" id= \" changePluginsForm \" >" ;
716 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
717 evt.preventDefault();
718 if (this.validate()) {
719 notify_progress('Saving data...', true);
721 new Ajax.Request('backend.php', {
722 parameters: dojo.objectToQuery(this.getValues()),
723 onComplete: function(transport) {
725 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
726 window.location.reload();
733 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
734 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setplugins \" >" ;
736 print "<table width='100%' class='prefPluginsList'>" ;
738 print "<tr><td colspan='4'><h3>" . __ ( "System plugins" ). "</h3></td></tr>" ;
740 print "<tr class= \" title \" >
741 <td width= \" 5% \" > </td>
742 <td width='10%'>" . __ ( 'Plugin' ). "</td>
743 <td width=''>" . __ ( 'Description' ). "</td>
744 <td width='5%'>" . __ ( 'Version' ). "</td>
745 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
747 $system_enabled = array_map ( "trim" , explode ( "," , PLUGINS
));
748 $user_enabled = array_map ( "trim" , explode ( "," , get_pref ( "_ENABLED_PLUGINS" )));
750 $tmppluginhost = new PluginHost ( Db
:: get ());
751 $tmppluginhost -> load_all ( $tmppluginhost :: KIND_ALL
, $_SESSION [ "uid" ]);
752 $tmppluginhost -> load_data ( true );
754 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
755 $about = $plugin -> about ();
757 if ( $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
758 if ( in_array ( $name , $system_enabled )) {
759 $checked = "checked='1'" ;
766 print "<td align='center'><input disabled='1'
767 dojoType= \" dijit.form.CheckBox \" $checked
768 type= \" checkbox \" ></td>" ;
770 print "<td> $name </td>" ;
771 print "<td>" . htmlspecialchars ( $about [ 1 ]);
773 print " — <a target= \" _blank \" class= \" visibleLink \"
774 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
777 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
778 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
780 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
781 if ( in_array ( $name , $system_enabled )) {
782 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \"
783 class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
792 print "<tr><td colspan='4'><h3>" . __ ( "User plugins" ). "</h3></td></tr>" ;
794 print "<tr class= \" title \" >
795 <td width= \" 5% \" > </td>
796 <td width='10%'>" . __ ( 'Plugin' ). "</td>
797 <td width=''>" . __ ( 'Description' ). "</td>
798 <td width='5%'>" . __ ( 'Version' ). "</td>
799 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
802 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
803 $about = $plugin -> about ();
805 if (! $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
807 if ( in_array ( $name , $system_enabled )) {
808 $checked = "checked='1'" ;
809 $disabled = "disabled='1'" ;
811 } else if ( in_array ( $name , $user_enabled )) {
812 $checked = "checked='1'" ;
814 $rowclass = "Selected" ;
821 print "<tr class=' $rowclass '>" ;
823 print "<td align='center'><input id='FPCHK- $name ' name='plugins[]' value=' $name ' onclick='toggleSelectRow2(this);'
824 dojoType= \" dijit.form.CheckBox \" $checked $disabled
825 type= \" checkbox \" ></td>" ;
827 print "<td><label for='FPCHK- $name '> $name </label></td>" ;
828 print "<td><label for='FPCHK- $name '>" . htmlspecialchars ( $about [ 1 ]) . "</label>" ;
830 print " — <a target= \" _blank \" class= \" visibleLink \"
831 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
835 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
836 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
838 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
839 if ( in_array ( $name , $system_enabled ) ||
in_array ( $name , $user_enabled )) {
840 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \" class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
854 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
855 __ ( "Enable selected plugins" ). "</button></p>" ;
859 print "</div>" ; #pane
861 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
862 "hook_prefs_tab" , "prefPrefs" );
864 print "</div>" ; #container
867 function toggleAdvanced () {
868 $_SESSION [ "prefs_show_advanced" ] = ! $_SESSION [ "prefs_show_advanced" ];
871 function otpqrcode () {
872 require_once "lib/otphp/vendor/base32.php" ;
873 require_once "lib/otphp/lib/otp.php" ;
874 require_once "lib/otphp/lib/totp.php" ;
875 require_once "lib/phpqrcode/phpqrcode.php" ;
877 $result = $this -> dbh
-> query ( "SELECT login,salt,otp_enabled
879 WHERE id = " . $_SESSION [ "uid" ]);
881 $base32 = new Base32 ();
883 $login = $this -> dbh
-> fetch_result ( $result , 0 , "login" );
884 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
887 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
888 $topt = new \OTPHP\
TOTP ( $secret );
889 print QRcode
:: png ( $topt -> provisioning_uri ( $login ));
893 function otpenable () {
894 require_once "lib/otphp/vendor/base32.php" ;
895 require_once "lib/otphp/lib/otp.php" ;
896 require_once "lib/otphp/lib/totp.php" ;
898 $password = $_REQUEST [ "password" ];
899 $otp = $_REQUEST [ "otp" ];
901 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
903 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
905 $result = $this -> dbh
-> query ( "SELECT salt
907 WHERE id = " . $_SESSION [ "uid" ]);
909 $base32 = new Base32 ();
911 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
912 $topt = new \OTPHP\
TOTP ( $secret );
914 $otp_check = $topt -> now ();
916 if ( $otp == $otp_check ) {
917 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = true WHERE
918 id = " . $_SESSION [ "uid" ]);
922 print "ERROR:" . __ ( "Incorrect one time password" );
925 print "ERROR:" . __ ( "Incorrect password" );
930 function otpdisable () {
931 $password = $this -> dbh
-> escape_string ( $_REQUEST [ "password" ]);
933 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
935 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
937 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = false WHERE
938 id = " . $_SESSION [ "uid" ]);
942 print "ERROR: " . __ ( "Incorrect password" );
947 function setplugins () {
948 if ( is_array ( $_REQUEST [ "plugins" ]))
949 $plugins = join ( "," , $_REQUEST [ "plugins" ]);
953 set_pref ( "_ENABLED_PLUGINS" , $plugins );
956 function clearplugindata () {
957 $name = $this -> dbh
-> escape_string ( $_REQUEST [ "name" ]);
959 PluginHost
:: getInstance ()-> clear_data ( PluginHost
:: getInstance ()-> get_plugin ( $name ));
962 function customizeCSS () {
963 $value = get_pref ( "USER_STYLESHEET" );
965 $value = str_replace ( "<br/>" , " \n " , $value );
967 print_notice ( T_sprintf ( "You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target= \" _blank \" class= \" visibleLink \" href= \" %s\" >This file</a> can be used as a baseline." , "tt-rss.css" ));
969 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" rpc \" >" ;
970 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setpref \" >" ;
971 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" key \" value= \" USER_STYLESHEET \" >" ;
973 print "<table width='100%'><tr><td>" ;
974 print "<textarea dojoType= \" dijit.form.SimpleTextarea \"
975 style='font-size : 12px; width : 100%; height: 200px;'
976 placeHolder='body#ttrssMain { font-size : 14px; };'
977 name='value'> $value </textarea>" ;
978 print "</td></tr></table>" ;
980 print "<div class='dlgButtons'>" ;
981 print "<button dojoType= \" dijit.form.Button \"
982 onclick= \" dijit.byId('cssEditDlg').execute() \" >" . __ ( 'Save' ). "</button> " ;
983 print "<button dojoType= \" dijit.form.Button \"
984 onclick= \" dijit.byId('cssEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>" ;
989 function editPrefProfiles () {
990 print "<div dojoType= \" dijit.Toolbar \" >" ;
992 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
993 "<span>" . __ ( 'Select' ). "</span>" ;
994 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
995 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'all') \"
996 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
997 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'none') \"
998 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
999 print "</div></div>" ;
1001 print "<div style= \" float : right \" >" ;
1003 print "<input name= \" newprofile \" dojoType= \" dijit.form.ValidationTextBox \"
1005 <button dojoType= \" dijit.form.Button \"
1006 onclick= \" dijit.byId('profileEditDlg').addProfile() \" >" .
1007 __ ( 'Create profile' ). "</button></div>" ;
1011 $result = $this -> dbh
-> query ( "SELECT title,id FROM ttrss_settings_profiles
1012 WHERE owner_uid = " . $_SESSION [ "uid" ]. " ORDER BY title" );
1014 print "<div class= \" prefProfileHolder \" >" ;
1016 print "<form id= \" profile_edit_form \" onsubmit= \" return false \" >" ;
1018 print "<table width= \" 100% \" class= \" prefFeedProfileList \"
1019 cellspacing= \" 0 \" id= \" prefFeedProfileList \" >" ;
1021 print "<tr class= \" placeholder \" id= \" FCATR-0 \" >" ; #odd
1023 print "<td width='5%' align='center'><input
1025 onclick='toggleSelectRow2(this);'
1026 dojoType= \" dijit.form.CheckBox \"
1027 type= \" checkbox \" ></td>" ;
1029 if (! $_SESSION [ "profile" ]) {
1030 $is_active = __ ( "(active)" );
1035 print "<td><span>" .
1036 __ ( "Default profile" ) . " $is_active </span></td>" ;
1042 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1044 $profile_id = $line [ "id" ];
1045 $this_row_id = "id= \" FCATR- $profile_id\" " ;
1047 print "<tr class= \" placeholder \" $this_row_id >" ;
1049 $edit_title = htmlspecialchars ( $line [ "title" ]);
1051 print "<td width='5%' align='center'><input
1052 onclick='toggleSelectRow2(this);'
1053 id='FCATC- $profile_id '
1054 dojoType= \" dijit.form.CheckBox \"
1055 type= \" checkbox \" ></td>" ;
1057 if ( $_SESSION [ "profile" ] == $line [ "id" ]) {
1058 $is_active = __ ( "(active)" );
1063 print "<td><span dojoType= \" dijit.InlineEditBox \"
1064 width= \" 300px \" autoSave= \" false \"
1065 profile-id= \" $profile_id\" >" . $edit_title .
1066 "<script type= \" dojo/method \" event= \" onChange \" args= \" item \" >
1070 content: {op: 'rpc', method: 'saveprofile',
1072 id: this.srcNodeRef.getAttribute('profile-id')},
1073 load: function(response) {
1074 elem.attr('value', response);
1078 </span> $is_active </td>" ;
1089 print "<div class='dlgButtons'>
1090 <div style='float : left'>
1091 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').removeSelected() \" >" .
1092 __ ( 'Remove selected profiles' ). "</button>
1093 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').activateProfile() \" >" .
1094 __ ( 'Activate profile' ). "</button>
1097 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').hide() \" >" .
1098 __ ( 'Close this window' ). "</button>" ;
1103 private function getShortDesc ( $pref_name ) {
1104 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1105 return $this -> pref_help
[ $pref_name ][ 0 ];
1110 private function getHelpText ( $pref_name ) {
1111 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1112 return $this -> pref_help
[ $pref_name ][ 1 ];
1117 private function getSectionName ( $id ) {
1118 if ( isset ( $this -> pref_sections
[ $id ])) {
1119 return $this -> pref_sections
[ $id ];