]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
cf1322f4581cc93d8e4534db82712fdd79be3e4d
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 "BLACKLISTED_TAGS" => array ( __ ( "Blacklisted tags" ), __ ( "When auto-detecting tags in articles these tags will not be applied (comma-separated list)." )),
27 "CDM_AUTO_CATCHUP" => array ( __ ( "Automatically mark articles as read" ), __ ( "This option enables marking articles as read automatically while you scroll article list." )),
28 "CDM_EXPANDED" => array ( __ ( "Automatically expand articles in combined mode" ), "" ),
29 "COMBINED_DISPLAY_MODE" => array ( __ ( "Combined feed display" ), __ ( "Display expanded list of feed articles, instead of separate displays for headlines and article content" )),
30 "CONFIRM_FEED_CATCHUP" => array ( __ ( "Confirm marking feed as read" ), "" ),
31 "DEFAULT_ARTICLE_LIMIT" => array ( __ ( "Amount of articles to display at once" ), "" ),
32 "DEFAULT_UPDATE_INTERVAL" => array ( __ ( "Default feed update interval" ), __ ( "Shortest interval at which a feed will be checked for updates regardless of update method" )),
33 "DIGEST_CATCHUP" => array ( __ ( "Mark articles in e-mail digest as read" ), "" ),
34 "DIGEST_ENABLE" => array ( __ ( "Enable e-mail digest" ), __ ( "This option enables sending daily digest of new (and unread) headlines on your configured e-mail address" )),
35 "DIGEST_PREFERRED_TIME" => array ( __ ( "Try to send digests around specified time" ), __ ( "Uses UTC timezone" )),
36 "ENABLE_API_ACCESS" => array ( __ ( "Enable API access" ), __ ( "Allows external clients to access this account through the API" )),
37 "ENABLE_FEED_CATS" => array ( __ ( "Enable feed categories" ), "" ),
38 "FEEDS_SORT_BY_UNREAD" => array ( __ ( "Sort feeds by unread articles count" ), "" ),
39 "FRESH_ARTICLE_MAX_AGE" => array ( __ ( "Maximum age of fresh articles (in hours)" ), "" ),
40 "HIDE_READ_FEEDS" => array ( __ ( "Hide feeds with no unread articles" ), "" ),
41 "HIDE_READ_SHOWS_SPECIAL" => array ( __ ( "Show special feeds when hiding read feeds" ), "" ),
42 "LONG_DATE_FORMAT" => array ( __ ( "Long date format" ), __ ( "The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function." )),
43 "ON_CATCHUP_SHOW_NEXT_FEED" => array ( __ ( "On catchup show next feed" ), __ ( "Automatically open next feed with unread articles after marking one as read" )),
44 "PURGE_OLD_DAYS" => array ( __ ( "Purge articles after this number of days (0 - disables)" ), "" ),
45 "PURGE_UNREAD_ARTICLES" => array ( __ ( "Purge unread articles" ), "" ),
46 "REVERSE_HEADLINES" => array ( __ ( "Reverse headline order (oldest first)" ), "" ),
47 "SHORT_DATE_FORMAT" => array ( __ ( "Short date format" ), "" ),
48 "SHOW_CONTENT_PREVIEW" => array ( __ ( "Show content preview in headlines list" ), "" ),
49 "SORT_HEADLINES_BY_FEED_DATE" => array ( __ ( "Sort headlines by feed date" ), __ ( "Use feed-specified date to sort headlines instead of local import date." )),
50 "SSL_CERT_SERIAL" => array ( __ ( "Login with an SSL certificate" ), __ ( "Click to register your SSL client certificate with tt-rss" )),
51 "STRIP_IMAGES" => array ( __ ( "Do not embed images in articles" ), "" ),
52 "STRIP_UNSAFE_TAGS" => array ( __ ( "Strip unsafe tags from articles" ), __ ( "Strip all but most common HTML tags when reading articles." )),
53 "USER_STYLESHEET" => array ( __ ( "Customize stylesheet" ), __ ( "Customize CSS stylesheet to your liking" )),
54 "USER_TIMEZONE" => array ( __ ( "Time zone" ), "" ),
55 "VFEED_GROUP_BY_FEED" => array ( __ ( "Group headlines in virtual feeds" ), __ ( "Special feeds, labels, and categories are grouped by originating feeds" )),
56 "USER_LANGUAGE" => array ( __ ( "Language" )),
57 "USER_CSS_THEME" => array ( __ ( "Theme" ), __ ( "Select one of the available CSS themes" ))
61 function changepassword () {
63 $old_pw = $_POST [ "old_password" ];
64 $new_pw = $_POST [ "new_password" ];
65 $con_pw = $_POST [ "confirm_password" ];
68 print "ERROR: " . format_error ( "Old password cannot be blank." );
73 print "ERROR: " . format_error ( "New password cannot be blank." );
77 if ( $new_pw != $con_pw ) {
78 print "ERROR: " . format_error ( "Entered passwords do not match." );
82 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
84 if ( method_exists ( $authenticator , "change_password" )) {
85 print format_notice ( $authenticator -> change_password ( $_SESSION [ "uid" ], $old_pw , $new_pw ));
87 print "ERROR: " . format_error ( "Function not supported by authentication module." );
91 function saveconfig () {
92 $boolean_prefs = explode ( "," , $_POST [ "boolean_prefs" ]);
94 foreach ( $boolean_prefs as $pref ) {
95 if (! isset ( $_POST [ $pref ])) $_POST [ $pref ] = 'false' ;
100 foreach ( array_keys ( $_POST ) as $pref_name ) {
102 $pref_name = $pref_name ;
103 $value = $_POST [ $pref_name ];
105 if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
106 if ( get_pref ( 'DIGEST_PREFERRED_TIME' ) != $value ) {
108 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_users SET
109 last_digest_sent = NULL WHERE id = ?" );
110 $sth -> execute ([ $_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." );
131 function changeemail () {
133 $email = $_POST [ "email" ];
134 $full_name = $_POST [ "full_name" ];
135 $active_uid = $_SESSION [ "uid" ];
137 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_users SET email = ?,
138 full_name = ? WHERE id = ?" );
139 $sth -> execute ([ $email , $full_name , $active_uid ]);
141 print __ ( "Your personal data has been saved." );
146 function resetconfig () {
148 $_SESSION [ "prefs_op_result" ] = "reset-to-defaults" ;
150 $sth = $this -> pdo
-> query ( "DELETE FROM ttrss_user_prefs
151 WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL))
152 AND owner_uid = :uid" );
153 $sth -> execute ([ ":profile" => $_SESSION [ 'profile' ], ":uid" => $_SESSION [ 'uid' ]]);
155 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
157 echo __ ( "Your preferences are now set to default values." );
162 global $access_level_names ;
164 $prefs_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "STRIP_UNSAFE_TAGS" , "REVERSE_HEADLINES" ,
165 "SORT_HEADLINES_BY_FEED_DATE" , "DEFAULT_ARTICLE_LIMIT" ,
166 "FEEDS_SORT_BY_UNREAD" );
168 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
170 $profile_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "PURGE_OLD_DAYS" ,
171 "PURGE_UNREAD_ARTICLES" , "DIGEST_ENABLE" , "DIGEST_CATCHUP" ,
172 "BLACKLISTED_TAGS" , "ENABLE_API_ACCESS" , "UPDATE_POST_ON_CHECKSUM_CHANGE" ,
173 "DEFAULT_UPDATE_INTERVAL" , "USER_TIMEZONE" , "SORT_HEADLINES_BY_FEED_DATE" ,
174 "SSL_CERT_SERIAL" , "DIGEST_PREFERRED_TIME" );
177 $_SESSION [ "prefs_op_result" ] = "" ;
179 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
180 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Personal data / Authentication' ). " \" >" ;
182 print "<form dojoType= \" dijit.form.Form \" id= \" changeUserdataForm \" >" ;
184 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
185 evt.preventDefault();
186 if (this.validate()) {
187 notify_progress('Saving data...', true);
189 new Ajax.Request('backend.php', {
190 parameters: dojo.objectToQuery(this.getValues()),
191 onComplete: function(transport) {
192 notify_callback2(transport);
198 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
200 print "<h2>" . __ ( "Personal data" ) . "</h2>" ;
202 $sth = $this -> pdo
-> prepare ( "SELECT email,full_name,otp_enabled,
203 access_level FROM ttrss_users
205 $sth -> execute ([ $_SESSION [ "uid" ]]);
206 $row = $sth -> fetch ();
208 $email = htmlspecialchars ( $row [ "email" ]);
209 $full_name = htmlspecialchars ( $row [ "full_name" ]);
210 $otp_enabled = sql_bool_to_bool ( $row [ "otp_enabled" ]);
212 print "<tr><td width= \" 40% \" >" . __ ( 'Full name' ). "</td>" ;
213 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" full_name \" required= \" 1 \"
214 value= \" $full_name\" ></td></tr>" ;
216 print "<tr><td width= \" 40% \" >" . __ ( 'E-mail' ). "</td>" ;
217 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" email \" required= \" 1 \" value= \" $email\" ></td></tr>" ;
219 if (! SINGLE_USER_MODE
&& ! $_SESSION [ "hide_hello" ]) {
221 $access_level = $row [ "access_level" ];
222 print "<tr><td width= \" 40% \" >" . __ ( 'Access level' ). "</td>" ;
223 print "<td>" . $access_level_names [ $access_level ] . "</td></tr>" ;
228 print_hidden ( "op" , "pref-prefs" );
229 print_hidden ( "method" , "changeemail" );
231 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
232 __ ( "Save data" ). "</button>" ;
236 if ( $_SESSION [ "auth_module" ]) {
237 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
239 $authenticator = false ;
242 if ( $authenticator && method_exists ( $authenticator , "change_password" )) {
244 print "<h2>" . __ ( "Password" ) . "</h2>" ;
246 print "<div style='display : none' id='pwd_change_infobox'></div>" ;
248 print "<form dojoType= \" dijit.form.Form \" >" ;
250 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
251 evt.preventDefault();
252 if (this.validate()) {
253 notify_progress('Changing password...', true);
255 new Ajax.Request('backend.php', {
256 parameters: dojo.objectToQuery(this.getValues()),
257 onComplete: function(transport) {
259 if (transport.responseText.indexOf('ERROR: ') == 0) {
261 $('pwd_change_infobox').innerHTML =
262 transport.responseText.replace('ERROR: ', '');
265 $('pwd_change_infobox').innerHTML =
266 transport.responseText.replace('ERROR: ', '');
268 var warn = $('default_pass_warning');
269 if (warn) Element.hide(warn);
272 new Effect.Appear('pwd_change_infobox');
280 print_notice ( __ ( "Changing your current password will disable OTP." ));
283 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
285 print "<tr><td width= \" 40% \" >" . __ ( "Old password" ). "</td>" ;
286 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" old_password \" ></td></tr>" ;
288 print "<tr><td width= \" 40% \" >" . __ ( "New password" ). "</td>" ;
290 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
291 name= \" new_password \" ></td></tr>" ;
293 print "<tr><td width= \" 40% \" >" . __ ( "Confirm password" ). "</td>" ;
295 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" confirm_password \" ></td></tr>" ;
299 print_hidden ( "op" , "pref-prefs" );
300 print_hidden ( "method" , "changepassword" );
302 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
303 __ ( "Change password" ). "</button>" ;
307 if ( $_SESSION [ "auth_module" ] == "auth_internal" ) {
309 print "<h2>" . __ ( "One time passwords / Authenticator" ) . "</h2>" ;
313 print_notice ( __ ( "One time passwords are currently enabled. Enter your current password below to disable." ));
315 print "<form dojoType= \" dijit.form.Form \" >" ;
317 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
318 evt.preventDefault();
319 if (this.validate()) {
320 notify_progress('Disabling OTP', true);
322 new Ajax.Request('backend.php', {
323 parameters: dojo.objectToQuery(this.getValues()),
324 onComplete: function(transport) {
326 if (transport.responseText.indexOf('ERROR: ') == 0) {
327 notify_error(transport.responseText.replace('ERROR: ', ''));
329 window.location.reload();
336 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
338 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
340 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
341 name= \" password \" ></td></tr>" ;
345 print_hidden ( "op" , "pref-prefs" );
346 print_hidden ( "method" , "otpdisable" );
348 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
349 __ ( "Disable OTP" ). "</button>" ;
353 } else if ( function_exists ( "imagecreatefromstring" )) {
355 print_warning ( __ ( "You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP." ));
357 print "<p>" . __ ( "Scan the following code by the Authenticator application:" ). "</p>" ;
359 $csrf_token = $_SESSION [ "csrf_token" ];
361 print "<img src= \" backend.php?op=pref-prefs&method=otpqrcode&csrf_token= $csrf_token\" >" ;
363 print "<form dojoType= \" dijit.form.Form \" id= \" changeOtpForm \" >" ;
365 print_hidden ( "op" , "pref-prefs" );
366 print_hidden ( "method" , "otpenable" );
368 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
369 evt.preventDefault();
370 if (this.validate()) {
371 notify_progress('Saving data...', true);
373 new Ajax.Request('backend.php', {
374 parameters: dojo.objectToQuery(this.getValues()),
375 onComplete: function(transport) {
377 if (transport.responseText.indexOf('ERROR:') == 0) {
378 notify_error(transport.responseText.replace('ERROR:', ''));
380 window.location.reload();
387 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
389 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
391 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
392 name= \" password \" ></td></tr>" ;
394 print "<tr><td width= \" 40% \" >" . __ ( "Enter the generated one time password" ). "</td>" ;
396 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" autocomplete= \" off \"
398 name= \" otp \" ></td></tr>" ;
400 print "<tr><td colspan= \" 2 \" >" ;
402 print "</td></tr><tr><td colspan= \" 2 \" >" ;
407 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
408 __ ( "Enable OTP" ). "</button>" ;
414 print_notice ( __ ( "PHP GD functions are required for OTP support." ));
421 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
422 "hook_prefs_tab_section" , "prefPrefsAuth" );
424 print "</div>" ; #pane
426 print "<div dojoType= \" dijit.layout.AccordionPane \" selected= \" true \" title= \" " . __ ( 'Preferences' ). " \" >" ;
428 print "<form dojoType= \" dijit.form.Form \" id= \" changeSettingsForm \" >" ;
430 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt, quit \" >
431 if (evt) evt.preventDefault();
432 if (this.validate()) {
433 console.log(dojo.objectToQuery(this.getValues()));
435 new Ajax.Request('backend.php', {
436 parameters: dojo.objectToQuery(this.getValues()),
437 onComplete: function(transport) {
438 var msg = transport.responseText;
442 if (msg == 'PREFS_NEED_RELOAD') {
443 window.location.reload();
452 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
454 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">' ;
456 if ( $_SESSION [ "profile" ]) {
457 print_notice ( __ ( "Some preferences are only available in default profile." ));
460 if ( $_SESSION [ "profile" ]) {
461 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
463 initialize_user_prefs ( $_SESSION [ "uid" ]);
466 $sth = $this -> pdo
-> prepare ( "SELECT DISTINCT
467 ttrss_user_prefs.pref_name,value,type_name,
468 ttrss_prefs_sections.order_id,
470 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
471 WHERE type_id = ttrss_prefs_types.id AND
472 (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND
473 section_id = ttrss_prefs_sections.id AND
474 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
476 ORDER BY ttrss_prefs_sections.order_id,pref_name" );
477 $sth -> execute ([ ":uid" => $_SESSION [ 'uid' ], ":profile" => $_SESSION [ 'profile' ]]);
481 $active_section = "" ;
483 $listed_boolean_prefs = array ();
485 while ( $line = $sth -> fetch ()) {
487 if ( in_array ( $line [ "pref_name" ], $prefs_blacklist )) {
491 $type_name = $line [ "type_name" ];
492 $pref_name = $line [ "pref_name" ];
493 $section_name = $this -> getSectionName ( $line [ "section_id" ]);
494 $value = $line [ "value" ];
496 $short_desc = $this -> getShortDesc ( $pref_name );
497 $help_text = $this -> getHelpText ( $pref_name );
499 if (! $short_desc ) continue ;
501 if ( $_SESSION [ "profile" ] && in_array ( $line [ "pref_name" ],
502 $profile_blacklist )) {
506 if ( $active_section != $line [ "section_id" ]) {
508 if ( $active_section != "" ) {
512 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
514 $active_section = $line [ "section_id" ];
516 print "<tr><td colspan= \" 3 \" ><h3>" . $section_name . "</h3></td></tr>" ;
523 print "<td width= \" 40% \" class= \" prefName \" id= \" $pref_name\" >" ;
524 print "<label for='CB_ $pref_name '>" ;
528 if ( $help_text ) print "<div class= \" prefHelp \" >" . __ ( $help_text ). "</div>" ;
532 print "<td class= \" prefValue \" >" ;
534 if ( $pref_name == "USER_LANGUAGE" ) {
535 print_select_hash ( $pref_name , $value , get_translations (),
536 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'" );
538 } else if ( $pref_name == "USER_TIMEZONE" ) {
540 $timezones = explode ( " \n " , file_get_contents ( "lib/timezones.txt" ));
542 print_select ( $pref_name , $value , $timezones , 'dojoType="dijit.form.FilteringSelect"' );
543 } else if ( $pref_name == "USER_STYLESHEET" ) {
545 print "<button dojoType= \" dijit.form.Button \"
546 onclick= \" customizeCSS() \" >" . __ ( 'Customize' ) . "</button>" ;
548 } else if ( $pref_name == "USER_CSS_THEME" ) {
550 $themes = array_merge ( glob ( "themes/*.php" ), glob ( "themes/*.css" ), glob ( "themes.local/*.css" ));
551 $themes = array_map ( "basename" , $themes );
552 $themes = array_filter ( $themes , "theme_valid" );
555 if (! theme_valid ( $value )) $value = "default.php" ;
557 print_select ( $pref_name , $value , $themes ,
558 'dojoType="dijit.form.Select"' );
561 } else if ( $pref_name == "DEFAULT_UPDATE_INTERVAL" ) {
563 global $update_intervals_nodefault ;
565 print_select_hash ( $pref_name , $value , $update_intervals_nodefault ,
566 'dojoType="dijit.form.Select"' );
568 } else if ( $type_name == "bool" ) {
570 array_push ( $listed_boolean_prefs , $pref_name );
572 $checked = ( $value == "true" ) ?
"checked= \" checked \" " : "" ;
574 if ( $pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0 ) {
575 $disabled = "disabled= \" 1 \" " ;
576 $checked = "checked= \" checked \" " ;
581 print "<input type='checkbox' name=' $pref_name ' $checked $disabled
582 dojoType='dijit.form.CheckBox' id='CB_ $pref_name ' value='1'>" ;
584 } else if ( array_search ( $pref_name , array ( 'FRESH_ARTICLE_MAX_AGE' ,
585 'PURGE_OLD_DAYS' , 'LONG_DATE_FORMAT' , 'SHORT_DATE_FORMAT' )) !== false ) {
587 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
589 if ( $pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0 ) {
590 $disabled = "disabled= \" 1 \" " ;
591 $value = FORCE_ARTICLE_PURGE
;
596 print "<input dojoType= \" dijit.form.ValidationTextBox \"
597 required= \" 1 \" $regexp $disabled
598 name= \" $pref_name\" value= \" $value\" >" ;
600 } else if ( $pref_name == "SSL_CERT_SERIAL" ) {
602 print "<input dojoType= \" dijit.form.ValidationTextBox \"
603 id= \" SSL_CERT_SERIAL \" readonly= \" 1 \"
604 name= \" $pref_name\" value= \" $value\" >" ;
606 $cert_serial = htmlspecialchars ( get_ssl_certificate_id ());
607 $has_serial = ( $cert_serial ) ?
"false" : "true" ;
611 print " <button dojoType= \" dijit.form.Button \" disabled= \" $has_serial\"
612 onclick= \" insertSSLserial(' $cert_serial ') \" >" .
613 __ ( 'Register' ) . "</button>" ;
615 print " <button dojoType= \" dijit.form.Button \"
616 onclick= \" insertSSLserial('') \" >" .
617 __ ( 'Clear' ) . "</button>" ;
619 } else if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
620 print "<input dojoType= \" dijit.form.ValidationTextBox \"
621 id= \" $pref_name\" regexp= \" [012]?\d:\d\d \" placeHolder= \" 12:00 \"
622 name= \" $pref_name\" value= \" $value\" ><div class= \" insensitive \" >" .
623 T_sprintf ( "Current server time: %s (UTC)" , date ( "H:i" )) . "</div>" ;
625 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
627 print "<input dojoType= \" dijit.form.ValidationTextBox \"
629 name= \" $pref_name\" value= \" $value\" >" ;
641 $listed_boolean_prefs = htmlspecialchars ( join ( "," , $listed_boolean_prefs ));
643 print_hidden ( "boolean_prefs" , " $listed_boolean_prefs " );
645 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
646 "hook_prefs_tab_section" , "prefPrefsPrefsInside" );
648 print '</div>' ; # inside pane
649 print '<div dojoType="dijit.layout.ContentPane" region="bottom">' ;
651 print_hidden ( "op" , "pref-prefs" );
652 print_hidden ( "method" , "saveconfig" );
654 print "<div dojoType= \" dijit.form.ComboButton \" type= \" submit \" >
655 <span>" . __ ( 'Save configuration' ). "</span>
656 <div dojoType= \" dijit.DropDownMenu \" >
657 <div dojoType= \" dijit.MenuItem \"
658 onclick= \" dijit.byId('changeSettingsForm').onSubmit(null, true) \" >" .
659 __ ( "Save and exit preferences" ). "</div>
663 print "<button dojoType= \" dijit.form.Button \" onclick= \" return editProfiles() \" >" .
664 __ ( 'Manage profiles' ). "</button> " ;
666 print "<button dojoType= \" dijit.form.Button \" onclick= \" return validatePrefsReset() \" >" .
667 __ ( 'Reset to defaults' ). "</button>" ;
671 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
672 "hook_prefs_tab_section" , "prefPrefsPrefsOutside" );
675 print '</div>' ; # inner pane
676 print '</div>' ; # border container
678 print "</div>" ; #pane
680 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Plugins' ). " \" >" ;
682 print_notice ( __ ( "You will need to reload Tiny Tiny RSS for plugin changes to take effect." ));
684 if ( ini_get ( "open_basedir" ) && function_exists ( "curl_init" ) && ! defined ( "NO_CURL" )) {
685 print_warning ( "Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly." );
688 print "<form dojoType= \" dijit.form.Form \" id= \" changePluginsForm \" >" ;
690 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
691 evt.preventDefault();
692 if (this.validate()) {
693 notify_progress('Saving data...', true);
695 new Ajax.Request('backend.php', {
696 parameters: dojo.objectToQuery(this.getValues()),
697 onComplete: function(transport) {
699 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
700 window.location.reload();
707 print_hidden ( "op" , "pref-prefs" );
708 print_hidden ( "method" , "setplugins" );
710 print "<table width='100%' class='prefPluginsList'>" ;
712 print "<tr><td colspan='5'><h3>" . __ ( "System plugins" ). "</h3>" .
713 format_notice ( __ ( "System plugins are enabled in <strong>config.php</strong> for all users." )).
716 print "<tr class= \" title \" >
717 <td width= \" 5% \" > </td>
718 <td width='10%'>" . __ ( 'Plugin' ). "</td>
719 <td width=''>" . __ ( 'Description' ). "</td>
720 <td width='5%'>" . __ ( 'Version' ). "</td>
721 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
723 $system_enabled = array_map ( "trim" , explode ( "," , PLUGINS
));
724 $user_enabled = array_map ( "trim" , explode ( "," , get_pref ( "_ENABLED_PLUGINS" , $_SESSION [ 'uid' ])));
726 $tmppluginhost = new PluginHost ();
727 $tmppluginhost -> load_all ( $tmppluginhost :: KIND_ALL
, $_SESSION [ "uid" ], true );
728 $tmppluginhost -> load_data ( true );
730 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
731 $about = $plugin -> about ();
734 if ( in_array ( $name , $system_enabled )) {
735 $checked = "checked='1'" ;
742 print "<td align='center'><input disabled='1'
743 dojoType= \" dijit.form.CheckBox \" $checked
744 type= \" checkbox \" ></td>" ;
746 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
748 print "<td><label><img src='images/ $plugin_icon ' alt=''> $name </label></td>" ;
749 print "<td>" . htmlspecialchars ( $about [ 1 ]);
751 print " — <a target= \" _blank \" rel= \" noopener noreferrer \" class= \" visibleLink \"
752 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
755 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
756 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
758 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
759 if ( in_array ( $name , $system_enabled )) {
760 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \"
761 class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
770 print "<tr><td colspan='4'><h3>" . __ ( "User plugins" ). "</h3></td></tr>" ;
772 print "<tr class= \" title \" >
773 <td width= \" 5% \" > </td>
774 <td width='10%'>" . __ ( 'Plugin' ). "</td>
775 <td width=''>" . __ ( 'Description' ). "</td>
776 <td width='5%'>" . __ ( 'Version' ). "</td>
777 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
780 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
781 $about = $plugin -> about ();
785 if ( in_array ( $name , $system_enabled )) {
786 $checked = "checked='1'" ;
787 $disabled = "disabled='1'" ;
789 } else if ( in_array ( $name , $user_enabled )) {
790 $checked = "checked='1'" ;
792 $rowclass = "Selected" ;
799 print "<tr class=' $rowclass '>" ;
801 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
803 print "<td align='center'><input id='FPCHK- $name ' name='plugins[]' value=' $name ' onclick='toggleSelectRow2(this);'
804 dojoType= \" dijit.form.CheckBox \" $checked $disabled
805 type= \" checkbox \" ></td>" ;
807 print "<td><label for='FPCHK- $name '><img src='images/ $plugin_icon ' alt=''> $name </label></td>" ;
808 print "<td><label for='FPCHK- $name '>" . htmlspecialchars ( $about [ 1 ]) . "</label>" ;
810 print " — <a target= \" _blank \" rel= \" noopener noreferrer \" class= \" visibleLink \"
811 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
815 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
816 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
818 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
819 if ( in_array ( $name , $system_enabled ) ||
in_array ( $name , $user_enabled )) {
820 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \" class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
834 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
835 __ ( "Enable selected plugins" ). "</button></p>" ;
839 print "</div>" ; #pane
841 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
842 "hook_prefs_tab" , "prefPrefs" );
844 print "</div>" ; #container
847 function toggleAdvanced () {
848 $_SESSION [ "prefs_show_advanced" ] = ! $_SESSION [ "prefs_show_advanced" ];
851 function otpqrcode () {
852 require_once "lib/otphp/vendor/base32.php" ;
853 require_once "lib/otphp/lib/otp.php" ;
854 require_once "lib/otphp/lib/totp.php" ;
855 require_once "lib/phpqrcode/phpqrcode.php" ;
857 $sth = $this -> pdo
-> prepare ( "SELECT login,salt,otp_enabled
860 $sth -> execute ([ $_SESSION [ 'uid' ]]);
862 if ( $row = $sth -> fetch ()) {
864 $base32 = new Base32 ();
866 $login = $row [ "login" ];
867 $otp_enabled = sql_bool_to_bool ( $row [ "otp_enabled" ]);
870 $secret = $base32 -> encode ( sha1 ( $row [ "salt" ]));
872 QRcode
:: png ( "otpauth://totp/" . urlencode ( $login ).
873 "?secret= $secret &issuer=" . urlencode ( "Tiny Tiny RSS" ));
879 function otpenable () {
880 require_once "lib/otphp/vendor/base32.php" ;
881 require_once "lib/otphp/lib/otp.php" ;
882 require_once "lib/otphp/lib/totp.php" ;
884 $password = $_REQUEST [ "password" ];
885 $otp = $_REQUEST [ "otp" ];
887 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
889 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
891 $sth = $this -> pdo
-> query ( "SELECT salt
894 $sth -> execute ([ $_SESSION [ 'uid' ]]);
896 if ( $row = $sth -> fetch ()) {
898 $base32 = new Base32 ();
900 $secret = $base32 -> encode ( sha1 ( $row [ "salt" ]));
901 $topt = new \OTPHP\
TOTP ( $secret );
903 $otp_check = $topt -> now ();
905 if ( $otp == $otp_check ) {
906 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_users
907 SET otp_enabled = true WHERE id = ?" );
909 $sth -> execute ([ $_SESSION [ 'uid' ]]);
913 print "ERROR:" . __ ( "Incorrect one time password" );
918 print "ERROR:" . __ ( "Incorrect password" );
923 function otpdisable () {
924 $password = $_REQUEST [ "password" ];
926 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
928 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
930 $sth = $this -> pdo
-> prepare ( "UPDATE ttrss_users SET otp_enabled = false WHERE
932 $sth -> execute ([ $_SESSION [ 'uid' ]]);
936 print "ERROR: " . __ ( "Incorrect password" );
941 function setplugins () {
942 if ( is_array ( $_REQUEST [ "plugins" ]))
943 $plugins = join ( "," , $_REQUEST [ "plugins" ]);
947 set_pref ( "_ENABLED_PLUGINS" , $plugins , $_SESSION [ "uid" ]);
950 function clearplugindata () {
951 $name = $_REQUEST [ "name" ];
953 PluginHost
:: getInstance ()-> clear_data ( PluginHost
:: getInstance ()-> get_plugin ( $name ));
956 function customizeCSS () {
957 $value = get_pref ( "USER_STYLESHEET" );
959 $value = str_replace ( "<br/>" , " \n " , $value );
961 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." , "css/tt-rss.css" ));
963 print_hidden ( "op" , "rpc" );
964 print_hidden ( "method" , "setpref" );
965 print_hidden ( "key" , "USER_STYLESHEET" );
967 print "<table width='100%'><tr><td>" ;
968 print "<textarea dojoType= \" dijit.form.SimpleTextarea \"
969 style='font-size : 12px; width : 98%; height: 200px;'
970 placeHolder='body#ttrssMain { font-size : 14px; };'
971 name='value'> $value </textarea>" ;
972 print "</td></tr></table>" ;
974 print "<div class='dlgButtons'>" ;
975 print "<button dojoType= \" dijit.form.Button \"
976 onclick= \" dijit.byId('cssEditDlg').execute() \" >" . __ ( 'Save' ). "</button> " ;
977 print "<button dojoType= \" dijit.form.Button \"
978 onclick= \" dijit.byId('cssEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>" ;
983 function editPrefProfiles () {
984 print "<div dojoType= \" dijit.Toolbar \" >" ;
986 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
987 "<span>" . __ ( 'Select' ). "</span>" ;
988 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
989 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'all') \"
990 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
991 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'none') \"
992 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
993 print "</div></div>" ;
995 print "<div style= \" float : right \" >" ;
997 print "<input name= \" newprofile \" dojoType= \" dijit.form.ValidationTextBox \"
999 <button dojoType= \" dijit.form.Button \"
1000 onclick= \" dijit.byId('profileEditDlg').addProfile() \" >" .
1001 __ ( 'Create profile' ). "</button></div>" ;
1005 $sth = $this -> pdo
-> prepare ( "SELECT title,id FROM ttrss_settings_profiles
1006 WHERE owner_uid = ? ORDER BY title" );
1007 $sth -> execute ([ $_SESSION [ 'uid' ]]);
1009 print "<div class= \" prefProfileHolder \" >" ;
1011 print "<form id= \" profile_edit_form \" onsubmit= \" return false \" >" ;
1013 print "<table width= \" 100% \" class= \" prefFeedProfileList \"
1014 cellspacing= \" 0 \" id= \" prefFeedProfileList \" >" ;
1016 print "<tr class= \" placeholder \" id= \" FCATR-0 \" >" ; #odd
1018 print "<td width='5%' align='center'><input
1020 onclick='toggleSelectRow2(this);'
1021 dojoType= \" dijit.form.CheckBox \"
1022 type= \" checkbox \" ></td>" ;
1024 if (! $_SESSION [ "profile" ]) {
1025 $is_active = __ ( "(active)" );
1030 print "<td><span>" .
1031 __ ( "Default profile" ) . " $is_active </span></td>" ;
1037 while ( $line = $sth -> fetch ()) {
1039 $profile_id = $line [ "id" ];
1040 $this_row_id = "id= \" FCATR- $profile_id\" " ;
1042 print "<tr class= \" placeholder \" $this_row_id >" ;
1044 $edit_title = htmlspecialchars ( $line [ "title" ]);
1046 print "<td width='5%' align='center'><input
1047 onclick='toggleSelectRow2(this);'
1048 id='FCATC- $profile_id '
1049 dojoType= \" dijit.form.CheckBox \"
1050 type= \" checkbox \" ></td>" ;
1052 if ( $_SESSION [ "profile" ] == $line [ "id" ]) {
1053 $is_active = __ ( "(active)" );
1058 print "<td><span dojoType= \" dijit.InlineEditBox \"
1059 width= \" 300px \" autoSave= \" false \"
1060 profile-id= \" $profile_id\" >" . $edit_title .
1061 "<script type= \" dojo/method \" event= \" onChange \" args= \" item \" >
1065 content: {op: 'rpc', method: 'saveprofile',
1067 id: this.srcNodeRef.getAttribute('profile-id')},
1068 load: function(response) {
1069 elem.attr('value', response);
1073 </span> $is_active </td>" ;
1084 print "<div class='dlgButtons'>
1085 <div style='float : left'>
1086 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').removeSelected() \" >" .
1087 __ ( 'Remove selected profiles' ). "</button>
1088 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').activateProfile() \" >" .
1089 __ ( 'Activate profile' ). "</button>
1092 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').hide() \" >" .
1093 __ ( 'Close this window' ). "</button>" ;
1098 private function getShortDesc ( $pref_name ) {
1099 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1100 return $this -> pref_help
[ $pref_name ][ 0 ];
1105 private function getHelpText ( $pref_name ) {
1106 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1107 return $this -> pref_help
[ $pref_name ][ 1 ];
1112 private function getSectionName ( $id ) {
1113 if ( isset ( $this -> pref_sections
[ $id ])) {
1114 return $this -> pref_sections
[ $id ];