]>
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 "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" ), __ ( "The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function." )),
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" ,
185 "FEEDS_SORT_BY_UNREAD" );
187 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
189 $profile_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "PURGE_OLD_DAYS" ,
190 "PURGE_UNREAD_ARTICLES" , "DIGEST_ENABLE" , "DIGEST_CATCHUP" ,
191 "BLACKLISTED_TAGS" , "ENABLE_API_ACCESS" , "UPDATE_POST_ON_CHECKSUM_CHANGE" ,
192 "DEFAULT_UPDATE_INTERVAL" , "USER_TIMEZONE" , "SORT_HEADLINES_BY_FEED_DATE" ,
193 "SSL_CERT_SERIAL" , "DIGEST_PREFERRED_TIME" );
196 $_SESSION [ "prefs_op_result" ] = "" ;
198 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
199 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Personal data / Authentication' ). " \" >" ;
201 print "<form dojoType= \" dijit.form.Form \" id= \" changeUserdataForm \" >" ;
203 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
204 evt.preventDefault();
205 if (this.validate()) {
206 notify_progress('Saving data...', true);
208 new Ajax.Request('backend.php', {
209 parameters: dojo.objectToQuery(this.getValues()),
210 onComplete: function(transport) {
211 notify_callback2(transport);
217 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
219 print "<h2>" . __ ( "Personal data" ) . "</h2>" ;
221 $result = $this -> dbh
-> query ( "SELECT email,full_name,otp_enabled,
222 access_level FROM ttrss_users
223 WHERE id = " . $_SESSION [ "uid" ]);
225 $email = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "email" ));
226 $full_name = htmlspecialchars ( $this -> dbh
-> fetch_result ( $result , 0 , "full_name" ));
227 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
229 print "<tr><td width= \" 40% \" >" . __ ( 'Full name' ). "</td>" ;
230 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" full_name \" required= \" 1 \"
231 value= \" $full_name\" ></td></tr>" ;
233 print "<tr><td width= \" 40% \" >" . __ ( 'E-mail' ). "</td>" ;
234 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" email \" required= \" 1 \" value= \" $email\" ></td></tr>" ;
236 if (! SINGLE_USER_MODE
&& ! $_SESSION [ "hide_hello" ]) {
238 $access_level = $this -> dbh
-> fetch_result ( $result , 0 , "access_level" );
239 print "<tr><td width= \" 40% \" >" . __ ( 'Access level' ). "</td>" ;
240 print "<td>" . $access_level_names [ $access_level ] . "</td></tr>" ;
245 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
246 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changeemail \" >" ;
248 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
249 __ ( "Save data" ). "</button>" ;
253 if ( $_SESSION [ "auth_module" ]) {
254 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
256 $authenticator = false ;
259 if ( $authenticator && method_exists ( $authenticator , "change_password" )) {
261 print "<h2>" . __ ( "Password" ) . "</h2>" ;
263 $result = $this -> dbh
-> query ( "SELECT id FROM ttrss_users
264 WHERE id = " . $_SESSION [ "uid" ]. " AND pwd_hash
265 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'" );
267 if ( $this -> dbh
-> num_rows ( $result ) != 0 ) {
268 print format_warning ( __ ( "Your password is at default value, please change it." ), "default_pass_warning" );
271 print "<form dojoType= \" dijit.form.Form \" >" ;
273 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
274 evt.preventDefault();
275 if (this.validate()) {
276 notify_progress('Changing password...', true);
278 new Ajax.Request('backend.php', {
279 parameters: dojo.objectToQuery(this.getValues()),
280 onComplete: function(transport) {
282 if (transport.responseText.indexOf('ERROR: ') == 0) {
283 notify_error(transport.responseText.replace('ERROR: ', ''));
285 notify_info(transport.responseText);
286 var warn = $('default_pass_warning');
287 if (warn) Element.hide(warn);
295 print_notice ( __ ( "Changing your current password will disable OTP." ));
298 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
300 print "<tr><td width= \" 40% \" >" . __ ( "Old password" ). "</td>" ;
301 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" old_password \" ></td></tr>" ;
303 print "<tr><td width= \" 40% \" >" . __ ( "New password" ). "</td>" ;
305 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
306 name= \" new_password \" ></td></tr>" ;
308 print "<tr><td width= \" 40% \" >" . __ ( "Confirm password" ). "</td>" ;
310 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" confirm_password \" ></td></tr>" ;
314 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
315 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changepassword \" >" ;
317 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
318 __ ( "Change password" ). "</button>" ;
322 if ( $_SESSION [ "auth_module" ] == "auth_internal" ) {
324 print "<h2>" . __ ( "One time passwords / Authenticator" ) . "</h2>" ;
328 print_notice ( __ ( "One time passwords are currently enabled. Enter your current password below to disable." ));
330 print "<form dojoType= \" dijit.form.Form \" >" ;
332 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
333 evt.preventDefault();
334 if (this.validate()) {
335 notify_progress('Disabling OTP', true);
337 new Ajax.Request('backend.php', {
338 parameters: dojo.objectToQuery(this.getValues()),
339 onComplete: function(transport) {
341 if (transport.responseText.indexOf('ERROR: ') == 0) {
342 notify_error(transport.responseText.replace('ERROR: ', ''));
344 window.location.reload();
351 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
353 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
355 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
356 name= \" password \" ></td></tr>" ;
360 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
361 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpdisable \" >" ;
363 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
364 __ ( "Disable OTP" ). "</button>" ;
368 } else if ( function_exists ( "imagecreatefromstring" )) {
370 print_warning ( __ ( "You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP." ));
372 print "<p>" . __ ( "Scan the following code by the Authenticator application:" ). "</p>" ;
374 $csrf_token = $_SESSION [ "csrf_token" ];
376 print "<img src= \" backend.php?op=pref-prefs&method=otpqrcode&csrf_token= $csrf_token\" >" ;
378 print "<form dojoType= \" dijit.form.Form \" id= \" changeOtpForm \" >" ;
380 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
381 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpenable \" >" ;
383 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
384 evt.preventDefault();
385 if (this.validate()) {
386 notify_progress('Saving data...', true);
388 new Ajax.Request('backend.php', {
389 parameters: dojo.objectToQuery(this.getValues()),
390 onComplete: function(transport) {
392 if (transport.responseText.indexOf('ERROR:') == 0) {
393 notify_error(transport.responseText.replace('ERROR:', ''));
395 window.location.reload();
402 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
404 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
406 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
407 name= \" password \" ></td></tr>" ;
409 print "<tr><td width= \" 40% \" >" . __ ( "Enter the generated one time password" ). "</td>" ;
411 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" autocomplete= \" off \"
413 name= \" otp \" ></td></tr>" ;
415 print "<tr><td colspan= \" 2 \" >" ;
417 print "</td></tr><tr><td colspan= \" 2 \" >" ;
422 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
423 __ ( "Enable OTP" ). "</button>" ;
429 print_notice ( __ ( "PHP GD functions are required for OTP support." ));
436 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
437 "hook_prefs_tab_section" , "prefPrefsAuth" );
439 print "</div>" ; #pane
441 print "<div dojoType= \" dijit.layout.AccordionPane \" selected= \" true \" title= \" " . __ ( 'Preferences' ). " \" >" ;
443 print "<form dojoType= \" dijit.form.Form \" id= \" changeSettingsForm \" >" ;
445 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt, quit \" >
446 if (evt) evt.preventDefault();
447 if (this.validate()) {
448 console.log(dojo.objectToQuery(this.getValues()));
450 new Ajax.Request('backend.php', {
451 parameters: dojo.objectToQuery(this.getValues()),
452 onComplete: function(transport) {
453 var msg = transport.responseText;
457 if (msg == 'PREFS_NEED_RELOAD') {
458 window.location.reload();
467 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
469 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">' ;
471 if ( $_SESSION [ "profile" ]) {
472 print_notice ( __ ( "Some preferences are only available in default profile." ));
475 if ( $_SESSION [ "profile" ]) {
476 initialize_user_prefs ( $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
477 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
479 initialize_user_prefs ( $_SESSION [ "uid" ]);
480 $profile_qpart = "profile IS NULL" ;
483 /* if ($_SESSION["prefs_show_advanced"])
484 $access_query = "true";
486 $access_query = "(access_level = 0 AND section_id != 3)"; */
488 $access_query = 'true' ;
490 $result = $this -> dbh
-> query ( "SELECT DISTINCT
491 ttrss_user_prefs.pref_name,value,type_name,
492 ttrss_prefs_sections.order_id,
494 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
495 WHERE type_id = ttrss_prefs_types.id AND
497 section_id = ttrss_prefs_sections.id AND
498 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
500 owner_uid = " . $_SESSION [ "uid" ]. "
501 ORDER BY ttrss_prefs_sections.order_id,pref_name" );
505 $active_section = "" ;
507 $listed_boolean_prefs = array ();
509 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
511 if ( in_array ( $line [ "pref_name" ], $prefs_blacklist )) {
515 $type_name = $line [ "type_name" ];
516 $pref_name = $line [ "pref_name" ];
517 $section_name = $this -> getSectionName ( $line [ "section_id" ]);
518 $value = $line [ "value" ];
520 $short_desc = $this -> getShortDesc ( $pref_name );
521 $help_text = $this -> getHelpText ( $pref_name );
523 if (! $short_desc ) continue ;
525 if ( $_SESSION [ "profile" ] && in_array ( $line [ "pref_name" ],
526 $profile_blacklist )) {
530 if ( $active_section != $line [ "section_id" ]) {
532 if ( $active_section != "" ) {
536 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
538 $active_section = $line [ "section_id" ];
540 print "<tr><td colspan= \" 3 \" ><h3>" . $section_name . "</h3></td></tr>" ;
547 print "<td width= \" 40% \" class= \" prefName \" id= \" $pref_name\" >" ;
548 print "<label for='CB_ $pref_name '>" ;
552 if ( $help_text ) print "<div class= \" prefHelp \" >" . __ ( $help_text ). "</div>" ;
556 print "<td class= \" prefValue \" >" ;
558 if ( $pref_name == "USER_LANGUAGE" ) {
559 print_select_hash ( $pref_name , $value , get_translations (),
560 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'" );
562 } else if ( $pref_name == "USER_TIMEZONE" ) {
564 $timezones = explode ( " \n " , file_get_contents ( "lib/timezones.txt" ));
566 print_select ( $pref_name , $value , $timezones , 'dojoType="dijit.form.FilteringSelect"' );
567 } else if ( $pref_name == "USER_STYLESHEET" ) {
569 print "<button dojoType= \" dijit.form.Button \"
570 onclick= \" customizeCSS() \" >" . __ ( 'Customize' ) . "</button>" ;
572 } else if ( $pref_name == "USER_CSS_THEME" ) {
574 $themes = array_map ( "basename" , glob ( "themes/*.css" ));
576 print_select ( $pref_name , $value , $themes ,
577 'dojoType="dijit.form.Select"' );
580 } else if ( $pref_name == "DEFAULT_UPDATE_INTERVAL" ) {
582 global $update_intervals_nodefault ;
584 print_select_hash ( $pref_name , $value , $update_intervals_nodefault ,
585 'dojoType="dijit.form.Select"' );
587 } else if ( $type_name == "bool" ) {
589 array_push ( $listed_boolean_prefs , $pref_name );
591 $checked = ( $value == "true" ) ?
"checked= \" checked \" " : "" ;
593 if ( $pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0 ) {
594 $disabled = "disabled= \" 1 \" " ;
595 $checked = "checked= \" checked \" " ;
600 print "<input type='checkbox' name=' $pref_name ' $checked $disabled
601 dojoType='dijit.form.CheckBox' id='CB_ $pref_name ' value='1'>" ;
603 } else if ( array_search ( $pref_name , array ( 'FRESH_ARTICLE_MAX_AGE' ,
604 'PURGE_OLD_DAYS' , 'LONG_DATE_FORMAT' , 'SHORT_DATE_FORMAT' )) !== false ) {
606 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
608 if ( $pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0 ) {
609 $disabled = "disabled= \" 1 \" " ;
610 $value = FORCE_ARTICLE_PURGE
;
615 print "<input dojoType= \" dijit.form.ValidationTextBox \"
616 required= \" 1 \" $regexp $disabled
617 name= \" $pref_name\" value= \" $value\" >" ;
619 } else if ( $pref_name == "SSL_CERT_SERIAL" ) {
621 print "<input dojoType= \" dijit.form.ValidationTextBox \"
622 id= \" SSL_CERT_SERIAL \" readonly= \" 1 \"
623 name= \" $pref_name\" value= \" $value\" >" ;
625 $cert_serial = htmlspecialchars ( get_ssl_certificate_id ());
626 $has_serial = ( $cert_serial ) ?
"false" : "true" ;
628 print " <button dojoType= \" dijit.form.Button \" disabled= \" $has_serial\"
629 onclick= \" insertSSLserial(' $cert_serial ') \" >" .
630 __ ( 'Register' ) . "</button>" ;
632 print " <button dojoType= \" dijit.form.Button \"
633 onclick= \" insertSSLserial('') \" >" .
634 __ ( 'Clear' ) . "</button>" ;
636 } else if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
637 print "<input dojoType= \" dijit.form.ValidationTextBox \"
638 id= \" $pref_name\" regexp= \" [012]?\d:\d\d \" placeHolder= \" 12:00 \"
639 name= \" $pref_name\" value= \" $value\" ><div class= \" insensitive \" >" .
640 T_sprintf ( "Current server time: %s (UTC)" , date ( "H:i" )) . "</div>" ;
642 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
644 print "<input dojoType= \" dijit.form.ValidationTextBox \"
646 name= \" $pref_name\" value= \" $value\" >" ;
658 $listed_boolean_prefs = htmlspecialchars ( join ( "," , $listed_boolean_prefs ));
660 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" boolean_prefs \" value= \" $listed_boolean_prefs\" >" ;
662 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
663 "hook_prefs_tab_section" , "prefPrefsPrefsInside" );
665 print '</div>' ; # inside pane
666 print '<div dojoType="dijit.layout.ContentPane" region="bottom">' ;
668 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
669 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" saveconfig \" >" ;
671 print "<div dojoType= \" dijit.form.ComboButton \" type= \" submit \" >
672 <span>" . __ ( 'Save configuration' ). "</span>
673 <div dojoType= \" dijit.DropDownMenu \" >
674 <div dojoType= \" dijit.MenuItem \"
675 onclick= \" dijit.byId('changeSettingsForm').onSubmit(null, true) \" >" .
676 __ ( "Save and exit preferences" ). "</div>
680 print "<button dojoType= \" dijit.form.Button \" onclick= \" return editProfiles() \" >" .
681 __ ( 'Manage profiles' ). "</button> " ;
683 print "<button dojoType= \" dijit.form.Button \" onclick= \" return validatePrefsReset() \" >" .
684 __ ( 'Reset to defaults' ). "</button>" ;
688 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
690 print "<input onclick='toggleAdvancedPrefs()'
691 id='prefs_show_advanced'
692 dojoType=\"dijit.form.CheckBox\"
694 type=\"checkbox\"></input>
695 <label for='prefs_show_advanced'>" .
696 __("Show additional preferences") . "</label>"; */
698 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB_SECTION
,
699 "hook_prefs_tab_section" , "prefPrefsPrefsOutside" );
702 print '</div>' ; # inner pane
703 print '</div>' ; # border container
705 print "</div>" ; #pane
707 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Plugins' ). " \" >" ;
709 print "<p>" . __ ( "You will need to reload Tiny Tiny RSS for plugin changes to take effect." ) . "</p>" ;
711 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>." ));
713 print "<form dojoType= \" dijit.form.Form \" id= \" changePluginsForm \" >" ;
715 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
716 evt.preventDefault();
717 if (this.validate()) {
718 notify_progress('Saving data...', true);
720 new Ajax.Request('backend.php', {
721 parameters: dojo.objectToQuery(this.getValues()),
722 onComplete: function(transport) {
724 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
725 window.location.reload();
732 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
733 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setplugins \" >" ;
735 print "<table width='100%' class='prefPluginsList'>" ;
737 print "<tr><td colspan='4'><h3>" . __ ( "System plugins" ). "</h3></td></tr>" ;
739 print "<tr class= \" title \" >
740 <td width= \" 5% \" > </td>
741 <td width='10%'>" . __ ( 'Plugin' ). "</td>
742 <td width=''>" . __ ( 'Description' ). "</td>
743 <td width='5%'>" . __ ( 'Version' ). "</td>
744 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
746 $system_enabled = array_map ( "trim" , explode ( "," , PLUGINS
));
747 $user_enabled = array_map ( "trim" , explode ( "," , get_pref ( "_ENABLED_PLUGINS" )));
749 $tmppluginhost = new PluginHost ();
750 $tmppluginhost -> load_all ( $tmppluginhost :: KIND_ALL
, $_SESSION [ "uid" ]);
751 $tmppluginhost -> load_data ( true );
753 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
754 $about = $plugin -> about ();
756 if ( $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
757 if ( in_array ( $name , $system_enabled )) {
758 $checked = "checked='1'" ;
765 print "<td align='center'><input disabled='1'
766 dojoType= \" dijit.form.CheckBox \" $checked
767 type= \" checkbox \" ></td>" ;
769 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
771 print "<td><label><img src='images/ $plugin_icon ' alt=''> $name </label></td>" ;
772 print "<td>" . htmlspecialchars ( $about [ 1 ]);
774 print " — <a target= \" _blank \" class= \" visibleLink \"
775 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
778 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
779 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
781 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
782 if ( in_array ( $name , $system_enabled )) {
783 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \"
784 class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
793 print "<tr><td colspan='4'><h3>" . __ ( "User plugins" ). "</h3></td></tr>" ;
795 print "<tr class= \" title \" >
796 <td width= \" 5% \" > </td>
797 <td width='10%'>" . __ ( 'Plugin' ). "</td>
798 <td width=''>" . __ ( 'Description' ). "</td>
799 <td width='5%'>" . __ ( 'Version' ). "</td>
800 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
803 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
804 $about = $plugin -> about ();
806 if (! $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
808 if ( in_array ( $name , $system_enabled )) {
809 $checked = "checked='1'" ;
810 $disabled = "disabled='1'" ;
812 } else if ( in_array ( $name , $user_enabled )) {
813 $checked = "checked='1'" ;
815 $rowclass = "Selected" ;
822 print "<tr class=' $rowclass '>" ;
824 $plugin_icon = $checked ?
"plugin.png" : "plugin_disabled.png" ;
826 print "<td align='center'><input id='FPCHK- $name ' name='plugins[]' value=' $name ' onclick='toggleSelectRow2(this);'
827 dojoType= \" dijit.form.CheckBox \" $checked $disabled
828 type= \" checkbox \" ></td>" ;
830 print "<td><label for='FPCHK- $name '><img src='images/ $plugin_icon ' alt=''> $name </label></td>" ;
831 print "<td><label for='FPCHK- $name '>" . htmlspecialchars ( $about [ 1 ]) . "</label>" ;
833 print " — <a target= \" _blank \" class= \" visibleLink \"
834 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
838 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
839 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
841 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
842 if ( in_array ( $name , $system_enabled ) ||
in_array ( $name , $user_enabled )) {
843 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \" class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
857 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
858 __ ( "Enable selected plugins" ). "</button></p>" ;
862 print "</div>" ; #pane
864 PluginHost
:: getInstance ()-> run_hooks ( PluginHost
:: HOOK_PREFS_TAB
,
865 "hook_prefs_tab" , "prefPrefs" );
867 print "</div>" ; #container
870 function toggleAdvanced () {
871 $_SESSION [ "prefs_show_advanced" ] = ! $_SESSION [ "prefs_show_advanced" ];
874 function otpqrcode () {
875 require_once "lib/otphp/vendor/base32.php" ;
876 require_once "lib/otphp/lib/otp.php" ;
877 require_once "lib/otphp/lib/totp.php" ;
878 require_once "lib/phpqrcode/phpqrcode.php" ;
880 $result = $this -> dbh
-> query ( "SELECT login,salt,otp_enabled
882 WHERE id = " . $_SESSION [ "uid" ]);
884 $base32 = new Base32 ();
886 $login = $this -> dbh
-> fetch_result ( $result , 0 , "login" );
887 $otp_enabled = sql_bool_to_bool ( $this -> dbh
-> fetch_result ( $result , 0 , "otp_enabled" ));
890 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
891 print QRcode
:: png ( "otpauth://totp/" . urlencode ( $login ).
892 "?secret= $secret &issuer=" . urlencode ( "Tiny Tiny RSS" ));
897 function otpenable () {
898 require_once "lib/otphp/vendor/base32.php" ;
899 require_once "lib/otphp/lib/otp.php" ;
900 require_once "lib/otphp/lib/totp.php" ;
902 $password = $_REQUEST [ "password" ];
903 $otp = $_REQUEST [ "otp" ];
905 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
907 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
909 $result = $this -> dbh
-> query ( "SELECT salt
911 WHERE id = " . $_SESSION [ "uid" ]);
913 $base32 = new Base32 ();
915 $secret = $base32 -> encode ( sha1 ( $this -> dbh
-> fetch_result ( $result , 0 , "salt" )));
916 $topt = new \OTPHP\
TOTP ( $secret );
918 $otp_check = $topt -> now ();
920 if ( $otp == $otp_check ) {
921 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = true WHERE
922 id = " . $_SESSION [ "uid" ]);
926 print "ERROR:" . __ ( "Incorrect one time password" );
929 print "ERROR:" . __ ( "Incorrect password" );
934 function otpdisable () {
935 $password = $this -> dbh
-> escape_string ( $_REQUEST [ "password" ]);
937 $authenticator = PluginHost
:: getInstance ()-> get_plugin ( $_SESSION [ "auth_module" ]);
939 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
941 $this -> dbh
-> query ( "UPDATE ttrss_users SET otp_enabled = false WHERE
942 id = " . $_SESSION [ "uid" ]);
946 print "ERROR: " . __ ( "Incorrect password" );
951 function setplugins () {
952 if ( is_array ( $_REQUEST [ "plugins" ]))
953 $plugins = join ( "," , $_REQUEST [ "plugins" ]);
957 set_pref ( "_ENABLED_PLUGINS" , $plugins );
960 function clearplugindata () {
961 $name = $this -> dbh
-> escape_string ( $_REQUEST [ "name" ]);
963 PluginHost
:: getInstance ()-> clear_data ( PluginHost
:: getInstance ()-> get_plugin ( $name ));
966 function customizeCSS () {
967 $value = get_pref ( "USER_STYLESHEET" );
969 $value = str_replace ( "<br/>" , " \n " , $value );
971 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" ));
973 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" rpc \" >" ;
974 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setpref \" >" ;
975 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" key \" value= \" USER_STYLESHEET \" >" ;
977 print "<table width='100%'><tr><td>" ;
978 print "<textarea dojoType= \" dijit.form.SimpleTextarea \"
979 style='font-size : 12px; width : 100%; height: 200px;'
980 placeHolder='body#ttrssMain { font-size : 14px; };'
981 name='value'> $value </textarea>" ;
982 print "</td></tr></table>" ;
984 print "<div class='dlgButtons'>" ;
985 print "<button dojoType= \" dijit.form.Button \"
986 onclick= \" dijit.byId('cssEditDlg').execute() \" >" . __ ( 'Save' ). "</button> " ;
987 print "<button dojoType= \" dijit.form.Button \"
988 onclick= \" dijit.byId('cssEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>" ;
993 function editPrefProfiles () {
994 print "<div dojoType= \" dijit.Toolbar \" >" ;
996 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
997 "<span>" . __ ( 'Select' ). "</span>" ;
998 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
999 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'all') \"
1000 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
1001 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'none') \"
1002 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
1003 print "</div></div>" ;
1005 print "<div style= \" float : right \" >" ;
1007 print "<input name= \" newprofile \" dojoType= \" dijit.form.ValidationTextBox \"
1009 <button dojoType= \" dijit.form.Button \"
1010 onclick= \" dijit.byId('profileEditDlg').addProfile() \" >" .
1011 __ ( 'Create profile' ). "</button></div>" ;
1015 $result = $this -> dbh
-> query ( "SELECT title,id FROM ttrss_settings_profiles
1016 WHERE owner_uid = " . $_SESSION [ "uid" ]. " ORDER BY title" );
1018 print "<div class= \" prefProfileHolder \" >" ;
1020 print "<form id= \" profile_edit_form \" onsubmit= \" return false \" >" ;
1022 print "<table width= \" 100% \" class= \" prefFeedProfileList \"
1023 cellspacing= \" 0 \" id= \" prefFeedProfileList \" >" ;
1025 print "<tr class= \" placeholder \" id= \" FCATR-0 \" >" ; #odd
1027 print "<td width='5%' align='center'><input
1029 onclick='toggleSelectRow2(this);'
1030 dojoType= \" dijit.form.CheckBox \"
1031 type= \" checkbox \" ></td>" ;
1033 if (! $_SESSION [ "profile" ]) {
1034 $is_active = __ ( "(active)" );
1039 print "<td><span>" .
1040 __ ( "Default profile" ) . " $is_active </span></td>" ;
1046 while ( $line = $this -> dbh
-> fetch_assoc ( $result )) {
1048 $profile_id = $line [ "id" ];
1049 $this_row_id = "id= \" FCATR- $profile_id\" " ;
1051 print "<tr class= \" placeholder \" $this_row_id >" ;
1053 $edit_title = htmlspecialchars ( $line [ "title" ]);
1055 print "<td width='5%' align='center'><input
1056 onclick='toggleSelectRow2(this);'
1057 id='FCATC- $profile_id '
1058 dojoType= \" dijit.form.CheckBox \"
1059 type= \" checkbox \" ></td>" ;
1061 if ( $_SESSION [ "profile" ] == $line [ "id" ]) {
1062 $is_active = __ ( "(active)" );
1067 print "<td><span dojoType= \" dijit.InlineEditBox \"
1068 width= \" 300px \" autoSave= \" false \"
1069 profile-id= \" $profile_id\" >" . $edit_title .
1070 "<script type= \" dojo/method \" event= \" onChange \" args= \" item \" >
1074 content: {op: 'rpc', method: 'saveprofile',
1076 id: this.srcNodeRef.getAttribute('profile-id')},
1077 load: function(response) {
1078 elem.attr('value', response);
1082 </span> $is_active </td>" ;
1093 print "<div class='dlgButtons'>
1094 <div style='float : left'>
1095 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').removeSelected() \" >" .
1096 __ ( 'Remove selected profiles' ). "</button>
1097 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').activateProfile() \" >" .
1098 __ ( 'Activate profile' ). "</button>
1101 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').hide() \" >" .
1102 __ ( 'Close this window' ). "</button>" ;
1107 private function getShortDesc ( $pref_name ) {
1108 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1109 return $this -> pref_help
[ $pref_name ][ 0 ];
1114 private function getHelpText ( $pref_name ) {
1115 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1116 return $this -> pref_help
[ $pref_name ][ 1 ];
1121 private function getSectionName ( $id ) {
1122 if ( isset ( $this -> pref_sections
[ $id ])) {
1123 return $this -> pref_sections
[ $id ];