]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
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 = $this -> dbh
-> escape_string ( $pref_name );
103 $value = $this -> dbh
-> escape_string ( $_POST [ $pref_name ]);
105 if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
106 if ( get_pref ( 'DIGEST_PREFERRED_TIME' ) != $value ) {
108 $this -> dbh
-> query ( "UPDATE ttrss_users SET
109 last_digest_sent = NULL WHERE id = " . $_SESSION [ 'uid' ]);
114 if ( $pref_name == "USER_LANGUAGE" ) {
115 if ( $_SESSION [ "language" ] != $value ) {
120 set_pref ( $pref_name , $value );
124 print "PREFS_NEED_RELOAD" ;
126 print __ ( "The configuration was saved." );
130 function changeemail () {
132 $email = $this -> dbh
-> escape_string ( $_POST [ "email" ]);
133 $full_name = $this -> dbh
-> escape_string ( $_POST [ "full_name" ]);
135 $active_uid = $_SESSION [ "uid" ];
137 $this -> dbh
-> query ( "UPDATE ttrss_users SET email = ' $email ',
138 full_name = ' $full_name ' WHERE id = ' $active_uid '" );
140 print __ ( "Your personal data has been saved." );
145 function resetconfig () {
147 $_SESSION [ "prefs_op_result" ] = "reset-to-defaults" ;
149 if ( $_SESSION [ "profile" ]) {
150 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
152 $profile_qpart = "profile IS NULL" ;
155 $this -> dbh
-> query ( "DELETE FROM ttrss_user_prefs
156 WHERE $profile_qpart AND owner_uid = " . $_SESSION [ "uid" ]);
158 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
160 echo __ ( "Your preferences are now set to default values." );
165 global $access_level_names ;
167 $prefs_blacklist = array ( "STRIP_UNSAFE_TAGS" , "REVERSE_HEADLINES" ,
168 "SORT_HEADLINES_BY_FEED_DATE" , "DEFAULT_ARTICLE_LIMIT" ,
169 "FEEDS_SORT_BY_UNREAD" );
171 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
173 $profile_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "PURGE_OLD_DAYS" ,
174 "PURGE_UNREAD_ARTICLES" , "DIGEST_ENABLE" , "DIGEST_CATCHUP" ,
175 "BLACKLISTED_TAGS" , "ENABLE_API_ACCESS" , "UPDATE_POST_ON_CHECKSUM_CHANGE" ,
176 "DEFAULT_UPDATE_INTERVAL" , "USER_TIMEZONE" , "SORT_HEADLINES_BY_FEED_DATE" ,
177 "SSL_CERT_SERIAL" , "DIGEST_PREFERRED_TIME" );
180 $_SESSION [ "prefs_op_result" ] = "" ;
182 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
183 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Personal data / Authentication' ). " \" >" ;
185 print "<form dojoType= \" dijit.form.Form \" id= \" changeUserdataForm \" >" ;
187 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
188 evt.preventDefault();
189 if (this.validate()) {
190 notify_progress('Saving data...', true);
192 new Ajax.Request('backend.php', {
193 parameters: dojo.objectToQuery(this.getValues()),
194 onComplete: function(transport) {
195 notify_callback2(transport);
201 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
203 print "<h2>" . __ ( "Personal data" ) . "</h2>" ;
205 $result = $this -> dbh
-> query ( "SELECT email,full_name,otp_enabled,
206 access_level FROM ttrss_users
207 WHERE id = " . $_SESSION [ "uid" ]);
209 $email = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "email" ));
210 $full_name = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "full_name" ));
211 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
213 print "<tr><td width= \" 40% \" >" . __ ( 'Full name' ). "</td>" ;
214 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" full_name \" required= \" 1 \"
215 value= \" $full_name\" ></td></tr>" ;
217 print "<tr><td width= \" 40% \" >" . __ ( 'E-mail' ). "</td>" ;
218 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" email \" required= \" 1 \" value= \" $email\" ></td></tr>" ;
220 if (! SINGLE_USER_MODE
&& ! $_SESSION [ "hide_hello" ]) {
222 $access_level = $this -> dbh
-> fetch_result ( $result , 0 , "access_level" );
223 print "<tr><td width= \" 40% \" >" . __ ( 'Access level' ). "</td>" ;
224 print "<td>" . $access_level_names [ $access_level ] . "</td></tr>" ;
229 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
230 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changeemail \" >" ;
232 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
233 __ ( "Save data" ). "</button>" ;
237 if ( $_SESSION [ "auth_module" ]) {
238 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
240 $authenticator = false ;
243 if ( $authenticator && method_exists ( $authenticator , "change_password" )) {
245 print "<h2>" . __ ( "Password" ) . "</h2>" ;
247 print "<div style='display : none' id='pwd_change_infobox'></div>" ;
249 $result = $this -> dbh
-> query ( "SELECT id FROM ttrss_users
250 WHERE id = " . $_SESSION [ "uid" ]. " AND pwd_hash
251 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'" );
253 if ( $this -> dbh
-> num_rows ( $result ) != 0 ) {
254 print format_warning ( __ ( "Your password is at default value, please change it." ), "default_pass_warning" );
257 print "<form dojoType= \" dijit.form.Form \" >" ;
259 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
260 evt.preventDefault();
261 if (this.validate()) {
262 notify_progress('Changing password...', true);
264 new Ajax.Request('backend.php', {
265 parameters: dojo.objectToQuery(this.getValues()),
266 onComplete: function(transport) {
268 if (transport.responseText.indexOf('ERROR: ') == 0) {
270 $('pwd_change_infobox').innerHTML =
271 transport.responseText.replace('ERROR: ', '');
274 $('pwd_change_infobox').innerHTML =
275 transport.responseText.replace('ERROR: ', '');
277 var warn = $('default_pass_warning');
278 if (warn) Element.hide(warn);
281 new Effect.Appear('pwd_change_infobox');
289 print_notice ( __ ( "Changing your current password will disable OTP." ));
292 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
294 print "<tr><td width= \" 40% \" >" . __ ( "Old password" ). "</td>" ;
295 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" old_password \" ></td></tr>" ;
297 print "<tr><td width= \" 40% \" >" . __ ( "New password" ). "</td>" ;
299 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
300 name= \" new_password \" ></td></tr>" ;
302 print "<tr><td width= \" 40% \" >" . __ ( "Confirm password" ). "</td>" ;
304 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" confirm_password \" ></td></tr>" ;
308 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
309 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changepassword \" >" ;
311 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
312 __ ( "Change password" ). "</button>" ;
316 if ( $_SESSION [ "auth_module" ] == "auth_internal" ) {
318 print "<h2>" . __ ( "One time passwords / Authenticator" ) . "</h2>" ;
322 print_notice ( __ ( "One time passwords are currently enabled. Enter your current password below to disable." ));
324 print "<form dojoType= \" dijit.form.Form \" >" ;
326 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
327 evt.preventDefault();
328 if (this.validate()) {
329 notify_progress('Disabling OTP', true);
331 new Ajax.Request('backend.php', {
332 parameters: dojo.objectToQuery(this.getValues()),
333 onComplete: function(transport) {
335 if (transport.responseText.indexOf('ERROR: ') == 0) {
336 notify_error(transport.responseText.replace('ERROR: ', ''));
338 window.location.reload();
345 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
347 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
349 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
350 name= \" password \" ></td></tr>" ;
354 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
355 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpdisable \" >" ;
357 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
358 __ ( "Disable OTP" ). "</button>" ;
362 } else if ( function_exists ( "imagecreatefromstring" )) {
364 print_warning ( __ ( "You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP." ));
366 print "<p>" . __ ( "Scan the following code by the Authenticator application:" ). "</p>" ;
368 $csrf_token = $_SESSION [ "csrf_token" ];
370 print "<img src= \" backend.php?op=pref-prefs&method=otpqrcode&csrf_token= $csrf_token\" >" ;
372 print "<form dojoType= \" dijit.form.Form \" id= \" changeOtpForm \" >" ;
374 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
375 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpenable \" >" ;
377 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
378 evt.preventDefault();
379 if (this.validate()) {
380 notify_progress('Saving data...', true);
382 new Ajax.Request('backend.php', {
383 parameters: dojo.objectToQuery(this.getValues()),
384 onComplete: function(transport) {
386 if (transport.responseText.indexOf('ERROR:') == 0) {
387 notify_error(transport.responseText.replace('ERROR:', ''));
389 window.location.reload();
396 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
398 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
400 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
401 name= \" password \" ></td></tr>" ;
403 print "<tr><td width= \" 40% \" >" . __ ( "Enter the generated one time password" ). "</td>" ;
405 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" autocomplete= \" off \"
407 name= \" otp \" ></td></tr>" ;
409 print "<tr><td colspan= \" 2 \" >" ;
411 print "</td></tr><tr><td colspan= \" 2 \" >" ;
416 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
417 __ ( "Enable OTP" ). "</button>" ;
423 print_notice ( __ ( "PHP GD functions are required for OTP support." ));
430 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
431 "hook_prefs_tab_section" , "prefPrefsAuth" );
433 print "</div>" ; #pane
435 print "<div dojoType= \" dijit.layout.AccordionPane \" selected= \" true \" title= \" " . __ ( 'Preferences' ). " \" >" ;
437 print "<form dojoType= \" dijit.form.Form \" id= \" changeSettingsForm \" >" ;
439 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt, quit \" >
440 if (evt) evt.preventDefault();
441 if (this.validate()) {
442 console.log(dojo.objectToQuery(this.getValues()));
444 new Ajax.Request('backend.php', {
445 parameters: dojo.objectToQuery(this.getValues()),
446 onComplete: function(transport) {
447 var msg = transport.responseText;
451 if (msg == 'PREFS_NEED_RELOAD') {
452 window.location.reload();
461 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
463 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">' ;
465 if ( $_SESSION [ "profile" ]) {
466 print_notice ( __ ( "Some preferences are only available in default profile." ));
469 if ( $_SESSION [ "profile" ]) {
470 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
471 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
473 initialize_user_prefs ( $_SESSION [ "uid" ]);
474 $profile_qpart = "profile IS NULL" ;
477 /* if ($_SESSION["prefs_show_advanced"])
478 $access_query = "true";
480 $access_query = "(access_level = 0 AND section_id != 3)"; */
482 $access_query = 'true' ;
484 $result = $this -> dbh
-> query ( "SELECT DISTINCT
485 ttrss_user_prefs.pref_name,value,type_name,
486 ttrss_prefs_sections.order_id,
488 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
489 WHERE type_id = ttrss_prefs_types.id AND
491 section_id = ttrss_prefs_sections.id AND
492 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
494 owner_uid = " . $_SESSION [ "uid" ]. "
495 ORDER BY ttrss_prefs_sections.order_id,pref_name" );
499 $active_section = "" ;
501 $listed_boolean_prefs = array ();
503 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
505 if ( in_array ( $line [ "pref_name" ], $prefs_blacklist )) {
509 $type_name = $line [ "type_name" ];
510 $pref_name = $line [ "pref_name" ];
511 $section_name = $this -> getSectionName ( $line [ "section_id" ]);
512 $value = $line [ "value" ];
514 $short_desc = $this -> getShortDesc ( $pref_name );
515 $help_text = $this -> getHelpText ( $pref_name );
517 if (! $short_desc ) continue ;
519 if ( $_SESSION [ "profile" ] && in_array ( $line [ "pref_name" ],
520 $profile_blacklist )) {
524 if ( $active_section != $line [ "section_id" ]) {
526 if ( $active_section != "" ) {
530 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
532 $active_section = $line [ "section_id" ];
534 print "<tr><td colspan= \" 3 \" ><h3>" . $section_name . "</h3></td></tr>" ;
541 print "<td width= \" 40% \" class= \" prefName \" id= \" $pref_name\" >" ;
542 print "<label for='CB_ $pref_name '>" ;
546 if ( $help_text ) print "<div class= \" prefHelp \" >" . __ ( $help_text ). "</div>" ;
550 print "<td class= \" prefValue \" >" ;
552 if ( $pref_name == "USER_LANGUAGE" ) {
553 print_select_hash ( $pref_name , $value , get_translations (),
554 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'" );
556 } else if ( $pref_name == "USER_TIMEZONE" ) {
558 $timezones = explode ( " \n " , file_get_contents ( "lib/timezones.txt" ));
560 print_select ( $pref_name , $value , $timezones , 'dojoType="dijit.form.FilteringSelect"' );
561 } else if ( $pref_name == "USER_STYLESHEET" ) {
563 print "<button dojoType= \" dijit.form.Button \"
564 onclick= \" customizeCSS() \" >" . __ ( 'Customize' ) . "</button>" ;
566 } else if ( $pref_name == "USER_CSS_THEME" ) {
568 $themes = array_merge ( glob ( "themes/*.css" ), glob ( "themes.local/*.css" ));
569 $themes = array_map ( "basename" , $themes );
570 $themes = array_filter ( $themes , "theme_valid" );
573 print_select ( $pref_name , $value , $themes ,
574 'dojoType="dijit.form.Select"' );
577 } else if ( $pref_name == "DEFAULT_UPDATE_INTERVAL" ) {
579 global $update_intervals_nodefault ;
581 print_select_hash ( $pref_name , $value , $update_intervals_nodefault ,
582 'dojoType="dijit.form.Select"' );
584 } else if ( $type_name == "bool" ) {
586 array_push ( $listed_boolean_prefs , $pref_name );
588 $checked = ( $value == "true" ) ?
"checked= \" checked \" " : "" ;
590 if ( $pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0 ) {
591 $disabled = "disabled= \" 1 \" " ;
592 $checked = "checked= \" checked \" " ;
597 print "<input type='checkbox' name=' $pref_name ' $checked $disabled
598 dojoType='dijit.form.CheckBox' id='CB_ $pref_name ' value='1'>" ;
600 } else if ( array_search ( $pref_name , array ( 'FRESH_ARTICLE_MAX_AGE' ,
601 'PURGE_OLD_DAYS' , 'LONG_DATE_FORMAT' , 'SHORT_DATE_FORMAT' )) !== false ) {
603 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
605 if ( $pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0 ) {
606 $disabled = "disabled= \" 1 \" " ;
607 $value = FORCE_ARTICLE_PURGE
;
612 print "<input dojoType= \" dijit.form.ValidationTextBox \"
613 required= \" 1 \" $regexp $disabled
614 name= \" $pref_name\" value= \" $value\" >" ;
616 } else if ( $pref_name == "SSL_CERT_SERIAL" ) {
618 print "<input dojoType= \" dijit.form.ValidationTextBox \"
619 id= \" SSL_CERT_SERIAL \" readonly= \" 1 \"
620 name= \" $pref_name\" value= \" $value\" >" ;
622 $cert_serial = htmlspecialchars ( get_ssl_certificate_id ());
623 $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 "<p>" . __ ( "You will need to reload Tiny Tiny RSS for plugin changes to take effect." ) . "</p>" ;
710 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>." ));
712 print "<form dojoType= \" dijit.form.Form \" id= \" changePluginsForm \" >" ;
714 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
715 evt.preventDefault();
716 if (this.validate()) {
717 notify_progress('Saving data...', true);
719 new Ajax.Request('backend.php', {
720 parameters: dojo.objectToQuery(this.getValues()),
721 onComplete: function(transport) {
723 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
724 window.location.reload();
731 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
732 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setplugins \" >" ;
734 print "<table width='100%' class='prefPluginsList'>" ;
736 print "<tr><td colspan='4'><h3>" . __ ( "System plugins" ). "</h3></td></tr>" ;
738 print "<tr class= \" title \" >
739 <td width= \" 5% \" > </td>
740 <td width='10%'>" . __ ( 'Plugin' ). "</td>
741 <td width=''>" . __ ( 'Description' ). "</td>
742 <td width='5%'>" . __ ( 'Version' ). "</td>
743 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
745 $system_enabled = array_map ( "trim" , explode ( "," , PLUGINS
));
746 $user_enabled = array_map ( "trim" , explode ( "," , get_pref ( "_ENABLED_PLUGINS" )));
748 $tmppluginhost = new PluginHost ();
749 $tmppluginhost -> load_all ( $tmppluginhost :: KIND_ALL
, $_SESSION [ "uid" ]);
750 $tmppluginhost -> load_data ( true );
752 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
753 $about = $plugin -> about ();
756 if ( in_array ( $name , $system_enabled )) {
757 $checked = "checked='1'" ;
764 print "<td align='center'><input disabled='1'
765 dojoType= \" dijit.form.CheckBox \" $checked
766 type= \" checkbox \" ></td>" ;
768 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
770 print "<td><label><img src='images/ $plugin_icon ' alt=''> $name </label></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 ();
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 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
825 print "<td align='center'><input id='FPCHK- $name ' name='plugins[]' value=' $name ' onclick='toggleSelectRow2(this);'
826 dojoType= \" dijit.form.CheckBox \" $checked $disabled
827 type= \" checkbox \" ></td>" ;
829 print "<td><label for='FPCHK- $name '><img src='images/ $plugin_icon ' alt=''> $name </label></td>" ;
830 print "<td><label for='FPCHK- $name '>" . htmlspecialchars ( $about [ 1 ]) . "</label>" ;
832 print " — <a target= \" _blank \" class= \" visibleLink \"
833 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
837 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
838 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
840 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
841 if ( in_array ( $name , $system_enabled ) ||
in_array ( $name , $user_enabled )) {
842 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \" class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
856 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
857 __ ( "Enable selected plugins" ). "</button></p>" ;
861 print "</div>" ; #pane
863 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
864 "hook_prefs_tab" , "prefPrefs" );
866 print "</div>" ; #container
869 function toggleAdvanced () {
870 $_SESSION [ "prefs_show_advanced" ] = ! $_SESSION [ "prefs_show_advanced" ];
873 function otpqrcode () {
874 require_once "lib/otphp/vendor/base32.php" ;
875 require_once "lib/otphp/lib/otp.php" ;
876 require_once "lib/otphp/lib/totp.php" ;
877 require_once "lib/phpqrcode/phpqrcode.php" ;
879 $result = $this -> dbh
-> query ( "SELECT login,salt,otp_enabled
881 WHERE id = " . $_SESSION [ "uid" ]);
883 $base32 = new Base32 ();
885 $login = $this -> dbh
-> fetch_result ( $result , 0 , "login" );
886 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
889 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
890 print QRcode
:: png ( "otpauth://totp/" . urlencode ( $login ).
891 "?secret= $secret &issuer=" . urlencode ( "Tiny Tiny RSS" ));
896 function otpenable () {
897 require_once "lib/otphp/vendor/base32.php" ;
898 require_once "lib/otphp/lib/otp.php" ;
899 require_once "lib/otphp/lib/totp.php" ;
901 $password = $_REQUEST [ "password" ];
902 $otp = $_REQUEST [ "otp" ];
904 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
906 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
908 $result = $this -> dbh
-> query ( "SELECT salt
910 WHERE id = " . $_SESSION [ "uid" ]);
912 $base32 = new Base32 ();
914 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
915 $topt = new \OTPHP\
TOTP ( $secret );
917 $otp_check = $topt -> now ();
919 if ( $otp == $otp_check ) {
920 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = true WHERE
921 id = " . $_SESSION [ "uid" ]);
925 print "ERROR:" . __ ( "Incorrect one time password" );
928 print "ERROR:" . __ ( "Incorrect password" );
933 function otpdisable () {
934 $password = $this -> dbh
-> escape_string ( $_REQUEST [ "password" ]);
936 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
938 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
940 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = false WHERE
941 id = " . $_SESSION [ "uid" ]);
945 print "ERROR: " . __ ( "Incorrect password" );
950 function setplugins () {
951 if ( is_array ( $_REQUEST [ "plugins" ]))
952 $plugins = join ( "," , $_REQUEST [ "plugins" ]);
956 set_pref ( "_ENABLED_PLUGINS" , $plugins );
959 function clearplugindata () {
960 $name = $this -> dbh
-> escape_string ( $_REQUEST [ "name" ]);
962 PluginHost
:: getInstance ()-> clear_data ( PluginHost
:: getInstance ()-> get_plugin ( $name ));
965 function customizeCSS () {
966 $value = get_pref ( "USER_STYLESHEET" );
968 $value = str_replace ( "<br/>" , " \n " , $value );
970 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" ));
972 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" rpc \" >" ;
973 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setpref \" >" ;
974 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" key \" value= \" USER_STYLESHEET \" >" ;
976 print "<table width='100%'><tr><td>" ;
977 print "<textarea dojoType= \" dijit.form.SimpleTextarea \"
978 style='font-size : 12px; width : 98%; height: 200px;'
979 placeHolder='body#ttrssMain { font-size : 14px; };'
980 name='value'> $value </textarea>" ;
981 print "</td></tr></table>" ;
983 print "<div class='dlgButtons'>" ;
984 print "<button dojoType= \" dijit.form.Button \"
985 onclick= \" dijit.byId('cssEditDlg').execute() \" >" . __ ( 'Save' ). "</button> " ;
986 print "<button dojoType= \" dijit.form.Button \"
987 onclick= \" dijit.byId('cssEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>" ;
992 function editPrefProfiles () {
993 print "<div dojoType= \" dijit.Toolbar \" >" ;
995 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
996 "<span>" . __ ( 'Select' ). "</span>" ;
997 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
998 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'all') \"
999 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1000 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'none') \"
1001 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1002 print "</div></div>" ;
1004 print "<div style= \" float : right \" >" ;
1006 print "<input name= \" newprofile \" dojoType= \" dijit.form.ValidationTextBox \"
1008 <button dojoType= \" dijit.form.Button \"
1009 onclick= \" dijit.byId('profileEditDlg').addProfile() \" >" .
1010 __ ( 'Create profile' ). "</button></div>" ;
1014 $result = $this -> dbh
-> query ( "SELECT title,id FROM ttrss_settings_profiles
1015 WHERE owner_uid = " . $_SESSION [ "uid" ]. " ORDER BY title" );
1017 print "<div class= \" prefProfileHolder \" >" ;
1019 print "<form id= \" profile_edit_form \" onsubmit= \" return false \" >" ;
1021 print "<table width= \" 100% \" class= \" prefFeedProfileList \"
1022 cellspacing= \" 0 \" id= \" prefFeedProfileList \" >" ;
1024 print "<tr class= \" placeholder \" id= \" FCATR-0 \" >" ; #odd
1026 print "<td width='5%' align='center'><input
1028 onclick='toggleSelectRow2(this);'
1029 dojoType= \" dijit.form.CheckBox \"
1030 type= \" checkbox \" ></td>" ;
1032 if (! $_SESSION [ "profile" ]) {
1033 $is_active = __ ( "(active)" );
1038 print "<td><span>" .
1039 __ ( "Default profile" ) . " $is_active </span></td>" ;
1045 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1047 $profile_id = $line [ "id" ];
1048 $this_row_id = "id= \" FCATR- $profile_id\" " ;
1050 print "<tr class= \" placeholder \" $this_row_id >" ;
1052 $edit_title = htmlspecialchars ( $line [ "title" ]);
1054 print "<td width='5%' align='center'><input
1055 onclick='toggleSelectRow2(this);'
1056 id='FCATC- $profile_id '
1057 dojoType= \" dijit.form.CheckBox \"
1058 type= \" checkbox \" ></td>" ;
1060 if ( $_SESSION [ "profile" ] == $line [ "id" ]) {
1061 $is_active = __ ( "(active)" );
1066 print "<td><span dojoType= \" dijit.InlineEditBox \"
1067 width= \" 300px \" autoSave= \" false \"
1068 profile-id= \" $profile_id\" >" . $edit_title .
1069 "<script type= \" dojo/method \" event= \" onChange \" args= \" item \" >
1073 content: {op: 'rpc', method: 'saveprofile',
1075 id: this.srcNodeRef.getAttribute('profile-id')},
1076 load: function(response) {
1077 elem.attr('value', response);
1081 </span> $is_active </td>" ;
1092 print "<div class='dlgButtons'>
1093 <div style='float : left'>
1094 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').removeSelected() \" >" .
1095 __ ( 'Remove selected profiles' ). "</button>
1096 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').activateProfile() \" >" .
1097 __ ( 'Activate profile' ). "</button>
1100 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').hide() \" >" .
1101 __ ( 'Close this window' ). "</button>" ;
1106 private function getShortDesc ( $pref_name ) {
1107 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1108 return $this -> pref_help
[ $pref_name ][ 0 ];
1113 private function getHelpText ( $pref_name ) {
1114 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1115 return $this -> pref_help
[ $pref_name ][ 1 ];
1120 private function getSectionName ( $id ) {
1121 if ( isset ( $this -> pref_sections
[ $id ])) {
1122 return $this -> pref_sections
[ $id ];