]>
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 ( $link , $args ) {
15 parent
:: __construct ( $link , $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 interval between feed updates" ), "" ),
34 "DIGEST_CATCHUP" => array ( __ ( "Mark articles in e-mail digest as read" ), "" ),
35 "DIGEST_ENABLE" => array ( __ ( "Enable e-mail digest" ), __ ( "This option enables sending daily digest of new (and unread) headlines on your configured e-mail address" )),
36 "DIGEST_PREFERRED_TIME" => array ( __ ( "Try to send digests around specified time" ), __ ( "Uses UTC timezone" )),
37 "ENABLE_API_ACCESS" => array ( __ ( "Enable API access" ), __ ( "Allows external clients to access this account through the API" )),
38 "ENABLE_FEED_CATS" => array ( __ ( "Enable feed categories" ), "" ),
39 "FEEDS_SORT_BY_UNREAD" => array ( __ ( "Sort feeds by unread articles count" ), "" ),
40 "FRESH_ARTICLE_MAX_AGE" => array ( __ ( "Maximum age of fresh articles (in hours)" ), "" ),
41 "HIDE_READ_FEEDS" => array ( __ ( "Hide feeds with no unread articles" ), "" ),
42 "HIDE_READ_SHOWS_SPECIAL" => array ( __ ( "Show special feeds when hiding read feeds" ), "" ),
43 "LONG_DATE_FORMAT" => array ( __ ( "Long date format" ), "" ),
44 "ON_CATCHUP_SHOW_NEXT_FEED" => array ( __ ( "On catchup show next feed" ), __ ( "Automatically open next feed with unread articles after marking one as read" )),
45 "PURGE_OLD_DAYS" => array ( __ ( "Purge articles after this number of days (0 - disables)" ), "" ),
46 "PURGE_UNREAD_ARTICLES" => array ( __ ( "Purge unread articles" ), "" ),
47 "REVERSE_HEADLINES" => array ( __ ( "Reverse headline order (oldest first)" ), "" ),
48 "SHORT_DATE_FORMAT" => array ( __ ( "Short date format" ), "" ),
49 "SHOW_CONTENT_PREVIEW" => array ( __ ( "Show content preview in headlines list" ), "" ),
50 "SORT_HEADLINES_BY_FEED_DATE" => array ( __ ( "Sort headlines by feed date" ), __ ( "Use feed-specified date to sort headlines instead of local import date." )),
51 "SSL_CERT_SERIAL" => array ( __ ( "Login with an SSL certificate" ), __ ( "Click to register your SSL client certificate with tt-rss" )),
52 "STRIP_IMAGES" => array ( __ ( "Do not embed images in articles" ), "" ),
53 "STRIP_UNSAFE_TAGS" => array ( __ ( "Strip unsafe tags from articles" ), __ ( "Strip all but most common HTML tags when reading articles." )),
54 "USER_STYLESHEET" => array ( __ ( "Customize stylesheet" ), __ ( "Customize CSS stylesheet to your liking" )),
55 "USER_TIMEZONE" => array ( __ ( "User timezone" ), "" ),
56 "VFEED_GROUP_BY_FEED" => array ( __ ( "Group headlines in virtual feeds" ), __ ( "Special feeds, labels, and categories are grouped by originating feeds" ))
60 function changepassword () {
62 $old_pw = $_POST [ "old_password" ];
63 $new_pw = $_POST [ "new_password" ];
64 $con_pw = $_POST [ "confirm_password" ];
67 print "ERROR: " . __ ( "Old password cannot be blank." );
72 print "ERROR: " . __ ( "New password cannot be blank." );
76 if ( $new_pw != $con_pw ) {
77 print "ERROR: " . __ ( "Entered passwords do not match." );
82 $authenticator = $pluginhost -> get_plugin ( $_SESSION [ "auth_module" ]);
84 if ( method_exists ( $authenticator , "change_password" )) {
85 print $authenticator -> change_password ( $_SESSION [ "uid" ], $old_pw , $new_pw );
87 print "ERROR: " . __ ( "Function not supported by authentication module." );
91 function saveconfig () {
93 $_SESSION [ "prefs_cache" ] = false ;
95 $boolean_prefs = explode ( "," , $_POST [ "boolean_prefs" ]);
97 foreach ( $boolean_prefs as $pref ) {
98 if (! isset ( $_POST [ $pref ])) $_POST [ $pref ] = 'false' ;
101 foreach ( array_keys ( $_POST ) as $pref_name ) {
103 $pref_name = db_escape_string ( $this -> link
, $pref_name );
104 $value = db_escape_string ( $this -> link
, $_POST [ $pref_name ]);
106 if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
107 if ( get_pref ( $this -> link
, 'DIGEST_PREFERRED_TIME' ) != $value ) {
109 db_query ( $this -> link
, "UPDATE ttrss_users SET
110 last_digest_sent = NULL WHERE id = " . $_SESSION [ 'uid' ]);
115 set_pref ( $this -> link
, $pref_name , $value );
119 print __ ( "The configuration was saved." );
124 $pref_name = db_escape_string ( $this -> link
, $_REQUEST [ "pn" ]);
126 $result = db_query ( $this -> link
, "SELECT help_text FROM ttrss_prefs
127 WHERE pref_name = ' $pref_name '" );
129 if ( db_num_rows ( $result ) > 0 ) {
130 $help_text = db_fetch_result ( $result , 0 , "help_text" );
133 printf ( __ ( "Unknown option: %s " ), $pref_name );
137 function changeemail () {
139 $email = db_escape_string ( $this -> link
, $_POST [ "email" ]);
140 $full_name = db_escape_string ( $this -> link
, $_POST [ "full_name" ]);
142 $active_uid = $_SESSION [ "uid" ];
144 db_query ( $this -> link
, "UPDATE ttrss_users SET email = ' $email ',
145 full_name = ' $full_name ' WHERE id = ' $active_uid '" );
147 print __ ( "Your personal data has been saved." );
152 function resetconfig () {
154 $_SESSION [ "prefs_op_result" ] = "reset-to-defaults" ;
156 if ( $_SESSION [ "profile" ]) {
157 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
159 $profile_qpart = "profile IS NULL" ;
162 db_query ( $this -> link
, "DELETE FROM ttrss_user_prefs
163 WHERE $profile_qpart AND owner_uid = " . $_SESSION [ "uid" ]);
165 initialize_user_prefs ( $this -> link
, $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
170 global $access_level_names ;
172 $prefs_blacklist = array ( "STRIP_UNSAFE_TAGS" , "REVERSE_HEADLINES" ,
173 "SORT_HEADLINES_BY_FEED_DATE" , "DEFAULT_ARTICLE_LIMIT" );
175 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
177 $profile_blacklist = array ( "ALLOW_DUPLICATE_POSTS" , "PURGE_OLD_DAYS" ,
178 "PURGE_UNREAD_ARTICLES" , "DIGEST_ENABLE" , "DIGEST_CATCHUP" ,
179 "BLACKLISTED_TAGS" , "ENABLE_API_ACCESS" , "UPDATE_POST_ON_CHECKSUM_CHANGE" ,
180 "DEFAULT_UPDATE_INTERVAL" , "USER_TIMEZONE" , "SORT_HEADLINES_BY_FEED_DATE" ,
181 "SSL_CERT_SERIAL" , "DIGEST_PREFERRED_TIME" );
184 $_SESSION [ "prefs_op_result" ] = "" ;
186 print "<div dojoType= \" dijit.layout.AccordionContainer \" region= \" center \" >" ;
187 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Personal data / Authentication' ). " \" >" ;
189 print "<form dojoType= \" dijit.form.Form \" id= \" changeUserdataForm \" >" ;
191 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
192 evt.preventDefault();
193 if (this.validate()) {
194 notify_progress('Saving data...', true);
196 new Ajax.Request('backend.php', {
197 parameters: dojo.objectToQuery(this.getValues()),
198 onComplete: function(transport) {
199 notify_callback2(transport);
205 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
207 print "<h2>" . __ ( "Personal data" ) . "</h2>" ;
209 $result = db_query ( $this -> link
, "SELECT email,full_name,otp_enabled,
210 access_level FROM ttrss_users
211 WHERE id = " . $_SESSION [ "uid" ]);
213 $email = htmlspecialchars ( db_fetch_result ( $result , 0 , "email" ));
214 $full_name = htmlspecialchars ( db_fetch_result ( $result , 0 , "full_name" ));
215 $otp_enabled = sql_bool_to_bool ( db_fetch_result ( $result , 0 , "otp_enabled" ));
217 print "<tr><td width= \" 40% \" >" . __ ( 'Full name' ). "</td>" ;
218 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" full_name \" required= \" 1 \"
219 value= \" $full_name\" ></td></tr>" ;
221 print "<tr><td width= \" 40% \" >" . __ ( 'E-mail' ). "</td>" ;
222 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" name= \" email \" required= \" 1 \" value= \" $email\" ></td></tr>" ;
224 if (! SINGLE_USER_MODE
&& ! $_SESSION [ "hide_hello" ]) {
226 $access_level = db_fetch_result ( $result , 0 , "access_level" );
227 print "<tr><td width= \" 40% \" >" . __ ( 'Access level' ). "</td>" ;
228 print "<td>" . $access_level_names [ $access_level ] . "</td></tr>" ;
233 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
234 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changeemail \" >" ;
236 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
237 __ ( "Save data" ). "</button>" ;
241 if ( $_SESSION [ "auth_module" ]) {
244 $authenticator = $pluginhost -> get_plugin ( $_SESSION [ "auth_module" ]);
247 $authenticator = false ;
250 if ( $authenticator && method_exists ( $authenticator , "change_password" )) {
252 print "<h2>" . __ ( "Password" ) . "</h2>" ;
254 $result = db_query ( $this -> link
, "SELECT id FROM ttrss_users
255 WHERE id = " . $_SESSION [ "uid" ]. " AND pwd_hash
256 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'" );
258 if ( db_num_rows ( $result ) != 0 ) {
259 print format_warning ( __ ( "Your password is at default value, please change it." ), "default_pass_warning" );
262 print "<form dojoType= \" dijit.form.Form \" >" ;
264 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
265 evt.preventDefault();
266 if (this.validate()) {
267 notify_progress('Changing password...', true);
269 new Ajax.Request('backend.php', {
270 parameters: dojo.objectToQuery(this.getValues()),
271 onComplete: function(transport) {
273 if (transport.responseText.indexOf('ERROR: ') == 0) {
274 notify_error(transport.responseText.replace('ERROR: ', ''));
276 notify_info(transport.responseText);
277 var warn = $('default_pass_warning');
278 if (warn) Element.hide(warn);
286 print_notice ( __ ( "Changing your current password will disable OTP." ));
289 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
291 print "<tr><td width= \" 40% \" >" . __ ( "Old password" ). "</td>" ;
292 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" old_password \" ></td></tr>" ;
294 print "<tr><td width= \" 40% \" >" . __ ( "New password" ). "</td>" ;
296 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
297 name= \" new_password \" ></td></tr>" ;
299 print "<tr><td width= \" 40% \" >" . __ ( "Confirm password" ). "</td>" ;
301 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \" name= \" confirm_password \" ></td></tr>" ;
305 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
306 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" changepassword \" >" ;
308 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
309 __ ( "Change password" ). "</button>" ;
313 if ( $_SESSION [ "auth_module" ] == "auth_internal" ) {
315 print "<h2>" . __ ( "One time passwords / Authenticator" ) . "</h2>" ;
319 print_notice ( __ ( "One time passwords are currently enabled. Enter your current password below to disable." ));
321 print "<form dojoType= \" dijit.form.Form \" >" ;
323 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
324 evt.preventDefault();
325 if (this.validate()) {
326 notify_progress('Disabling OTP', true);
328 new Ajax.Request('backend.php', {
329 parameters: dojo.objectToQuery(this.getValues()),
330 onComplete: function(transport) {
332 if (transport.responseText.indexOf('ERROR: ') == 0) {
333 notify_error(transport.responseText.replace('ERROR: ', ''));
335 window.location.reload();
342 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
344 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
346 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
347 name= \" password \" ></td></tr>" ;
351 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
352 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpdisable \" >" ;
354 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
355 __ ( "Disable OTP" ). "</button>" ;
361 print "<p>" . __ ( "You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP." ) . "</p>" ;
363 print "<p>" . __ ( "Scan the following code by the Authenticator application:" ). "</p>" ;
365 $csrf_token = $_SESSION [ "csrf_token" ];
367 print "<img src= \" backend.php?op=pref-prefs&method=otpqrcode&csrf_token= $csrf_token\" >" ;
369 print "<form dojoType= \" dijit.form.Form \" id= \" changeOtpForm \" >" ;
371 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
372 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" otpenable \" >" ;
374 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
375 evt.preventDefault();
376 if (this.validate()) {
377 notify_progress('Saving data...', true);
379 new Ajax.Request('backend.php', {
380 parameters: dojo.objectToQuery(this.getValues()),
381 onComplete: function(transport) {
383 if (transport.responseText.indexOf('ERROR: ') == 0) {
384 notify_error(transport.responseText.replace('ERROR: ', ''));
386 window.location.reload();
393 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
395 print "<tr><td width= \" 40% \" >" . __ ( "Enter your password" ). "</td>" ;
397 print "<td class= \" prefValue \" ><input dojoType= \" dijit.form.ValidationTextBox \" type= \" password \" required= \" 1 \"
398 name= \" password \" ></td></tr>" ;
400 print "<tr><td colspan= \" 2 \" >" ;
402 print "<input dojoType= \" dijit.form.CheckBox \" required= \" 1 \"
403 type= \" checkbox \" id= \" enable_otp \" name= \" enable_otp \" /> " ;
404 print "<label for= \" enable_otp \" >" . __ ( "I have scanned the code and would like to enable OTP" ). "</label>" ;
406 print "</td></tr><tr><td colspan= \" 2 \" >" ;
411 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
412 __ ( "Enable OTP" ). "</button>" ;
422 $pluginhost -> run_hooks ( $pluginhost :: HOOK_PREFS_TAB_SECTION
,
423 "hook_prefs_tab_section" , "prefPrefsAuth" );
425 print "</div>" ; #pane
427 print "<div dojoType= \" dijit.layout.AccordionPane \" selected= \" true \" title= \" " . __ ( 'Preferences' ). " \" >" ;
429 print "<form dojoType= \" dijit.form.Form \" id= \" changeSettingsForm \" >" ;
431 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
432 evt.preventDefault();
433 if (this.validate()) {
434 console.log(dojo.objectToQuery(this.getValues()));
436 new Ajax.Request('backend.php', {
437 parameters: dojo.objectToQuery(this.getValues()),
438 onComplete: function(transport) {
439 var msg = transport.responseText;
445 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">' ;
447 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">' ;
449 if ( $_SESSION [ "profile" ]) {
450 print_notice ( __ ( "Some preferences are only available in default profile." ));
453 if ( $_SESSION [ "profile" ]) {
454 initialize_user_prefs ( $this -> link
, $_SESSION [ "uid" ], $_SESSION [ "profile" ]);
455 $profile_qpart = "profile = '" . $_SESSION [ "profile" ] . "'" ;
457 initialize_user_prefs ( $this -> link
, $_SESSION [ "uid" ]);
458 $profile_qpart = "profile IS NULL" ;
461 /* if ($_SESSION["prefs_show_advanced"])
462 $access_query = "true";
464 $access_query = "(access_level = 0 AND section_id != 3)"; */
466 $access_query = 'true' ;
468 $result = db_query ( $this -> link
, "SELECT DISTINCT
469 ttrss_user_prefs.pref_name,value,type_name,
470 ttrss_prefs_sections.order_id,
472 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
473 WHERE type_id = ttrss_prefs_types.id AND
475 section_id = ttrss_prefs_sections.id AND
476 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
478 owner_uid = " . $_SESSION [ "uid" ]. "
479 ORDER BY ttrss_prefs_sections.order_id,pref_name" );
483 $active_section = "" ;
485 $listed_boolean_prefs = array ();
487 while ( $line = db_fetch_assoc ( $result )) {
489 if ( in_array ( $line [ "pref_name" ], $prefs_blacklist )) {
493 $type_name = $line [ "type_name" ];
494 $pref_name = $line [ "pref_name" ];
495 $section_name = $this -> getSectionName ( $line [ "section_id" ]);
496 $value = $line [ "value" ];
498 $short_desc = $this -> getShortDesc ( $pref_name );
499 $help_text = $this -> getHelpText ( $pref_name );
501 if (! $short_desc ) continue ;
503 if ( $_SESSION [ "profile" ] && in_array ( $line [ "pref_name" ],
504 $profile_blacklist )) {
508 if ( $active_section != $line [ "section_id" ]) {
510 if ( $active_section != "" ) {
514 print "<table width= \" 100% \" class= \" prefPrefsList \" >" ;
516 $active_section = $line [ "section_id" ];
518 print "<tr><td colspan= \" 3 \" ><h3>" . $section_name . "</h3></td></tr>" ;
525 print "<td width= \" 40% \" class= \" prefName \" id= \" $pref_name\" >" ;
526 print "<label for='CB_ $pref_name '>" ;
530 if ( $help_text ) print "<div class= \" prefHelp \" >" . __ ( $help_text ). "</div>" ;
534 print "<td class= \" prefValue \" >" ;
536 if ( $pref_name == "USER_TIMEZONE" ) {
538 $timezones = explode ( " \n " , file_get_contents ( "lib/timezones.txt" ));
540 print_select ( $pref_name , $value , $timezones , 'dojoType="dijit.form.FilteringSelect"' );
541 } else if ( $pref_name == "USER_STYLESHEET" ) {
543 print "<button dojoType= \" dijit.form.Button \"
544 onclick= \" customizeCSS() \" >" . __ ( 'Customize' ) . "</button>" ;
546 } else if ( $pref_name == "USER_CSS_THEME" ) {
548 $themes = array_map ( "basename" , glob ( "themes/*.css" ));
550 print_select ( $pref_name , $value , $themes ,
551 'dojoType="dijit.form.Select"' );
554 } else if ( $pref_name == "DEFAULT_UPDATE_INTERVAL" ) {
556 global $update_intervals_nodefault ;
558 print_select_hash ( $pref_name , $value , $update_intervals_nodefault ,
559 'dojoType="dijit.form.Select"' );
561 } else if ( $type_name == "bool" ) {
563 array_push ( $listed_boolean_prefs , $pref_name );
565 $checked = ( $value == "true" ) ?
"checked= \" checked \" " : "" ;
567 if ( $pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0 ) {
568 $disabled = "disabled= \" 1 \" " ;
569 $checked = "checked= \" checked \" " ;
574 print "<input type='checkbox' name=' $pref_name ' $checked $disabled
575 dojoType='dijit.form.CheckBox' id='CB_ $pref_name ' value='1'>" ;
577 } else if ( array_search ( $pref_name , array ( 'FRESH_ARTICLE_MAX_AGE' ,
578 'PURGE_OLD_DAYS' , 'LONG_DATE_FORMAT' , 'SHORT_DATE_FORMAT' )) !== false ) {
580 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
582 if ( $pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0 ) {
583 $disabled = "disabled= \" 1 \" " ;
584 $value = FORCE_ARTICLE_PURGE
;
589 print "<input dojoType= \" dijit.form.ValidationTextBox \"
590 required= \" 1 \" $regexp $disabled
591 name= \" $pref_name\" value= \" $value\" >" ;
593 } else if ( $pref_name == "SSL_CERT_SERIAL" ) {
595 print "<input dojoType= \" dijit.form.ValidationTextBox \"
596 id= \" SSL_CERT_SERIAL \" readonly= \" 1 \"
597 name= \" $pref_name\" value= \" $value\" >" ;
599 $cert_serial = htmlspecialchars ( get_ssl_certificate_id ());
600 $has_serial = ( $cert_serial ) ?
"false" : "true" ;
602 print " <button dojoType= \" dijit.form.Button \" disabled= \" $has_serial\"
603 onclick= \" insertSSLserial(' $cert_serial ') \" >" .
604 __ ( 'Register' ) . "</button>" ;
606 print " <button dojoType= \" dijit.form.Button \"
607 onclick= \" insertSSLserial('') \" >" .
608 __ ( 'Clear' ) . "</button>" ;
610 } else if ( $pref_name == 'DIGEST_PREFERRED_TIME' ) {
611 print "<input dojoType= \" dijit.form.ValidationTextBox \"
612 id= \" $pref_name\" regexp= \" [012]?\d:\d\d \" placeHolder= \" 12:00 \"
613 name= \" $pref_name\" value= \" $value\" ><div class= \" insensitive \" >" .
614 T_sprintf ( "Current server time: %s (UTC)" , date ( "H:i" )) . "</div>" ;
616 $regexp = ( $type_name == 'integer' ) ?
'regexp="^\d*$"' : '' ;
618 print "<input dojoType= \" dijit.form.ValidationTextBox \"
620 name= \" $pref_name\" value= \" $value\" >" ;
632 $listed_boolean_prefs = htmlspecialchars ( join ( "," , $listed_boolean_prefs ));
634 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" boolean_prefs \" value= \" $listed_boolean_prefs\" >" ;
637 $pluginhost -> run_hooks ( $pluginhost :: HOOK_PREFS_TAB_SECTION
,
638 "hook_prefs_tab_section" , "prefPrefsPrefsInside" );
640 print '</div>' ; # inside pane
641 print '<div dojoType="dijit.layout.ContentPane" region="bottom">' ;
643 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
644 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" saveconfig \" >" ;
646 print "<button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
647 __ ( 'Save configuration' ). "</button> " ;
649 print "<button dojoType= \" dijit.form.Button \" onclick= \" return editProfiles() \" >" .
650 __ ( 'Manage profiles' ). "</button> " ;
652 print "<button dojoType= \" dijit.form.Button \" onclick= \" return validatePrefsReset() \" >" .
653 __ ( 'Reset to defaults' ). "</button>" ;
657 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
659 print "<input onclick='toggleAdvancedPrefs()'
660 id='prefs_show_advanced'
661 dojoType=\"dijit.form.CheckBox\"
663 type=\"checkbox\"></input>
664 <label for='prefs_show_advanced'>" .
665 __("Show additional preferences") . "</label>"; */
668 $pluginhost -> run_hooks ( $pluginhost :: HOOK_PREFS_TAB_SECTION
,
669 "hook_prefs_tab_section" , "prefPrefsPrefsOutside" );
672 print '</div>' ; # inner pane
673 print '</div>' ; # border container
675 print "</div>" ; #pane
677 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Plugins' ). " \" >" ;
679 print "<h2>" . __ ( "Plugins" ). "</h2>" ;
681 print "<p>" . __ ( "You will need to reload Tiny Tiny RSS for plugin changes to take effect." ) . "</p>" ;
683 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>." ));
685 print "<form dojoType= \" dijit.form.Form \" id= \" changePluginsForm \" >" ;
687 print "<script type= \" dojo/method \" event= \" onSubmit \" args= \" evt \" >
688 evt.preventDefault();
689 if (this.validate()) {
690 notify_progress('Saving data...', true);
692 new Ajax.Request('backend.php', {
693 parameters: dojo.objectToQuery(this.getValues()),
694 onComplete: function(transport) {
696 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
697 window.location.reload();
704 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" pref-prefs \" >" ;
705 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setplugins \" >" ;
707 print "<table width='100%' class='prefPluginsList'>" ;
709 print "<tr><td colspan='4'><h3>" . __ ( "System plugins" ). "</h3></td></tr>" ;
711 print "<tr class= \" title \" >
712 <td width= \" 5% \" > </td>
713 <td width='10%'>" . __ ( 'Plugin' ). "</td>
714 <td width=''>" . __ ( 'Description' ). "</td>
715 <td width='5%'>" . __ ( 'Version' ). "</td>
716 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
718 $system_enabled = array_map ( "trim" , explode ( "," , PLUGINS
));
719 $user_enabled = array_map ( "trim" , explode ( "," , get_pref ( $this -> link
, "_ENABLED_PLUGINS" )));
721 $tmppluginhost = new PluginHost ( $this -> link
);
722 $tmppluginhost -> load_all ( $tmppluginhost :: KIND_ALL
, $_SESSION [ "uid" ]);
723 $tmppluginhost -> load_data ( true );
725 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
726 $about = $plugin -> about ();
728 if ( $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
729 if ( in_array ( $name , $system_enabled )) {
730 $checked = "checked='1'" ;
737 print "<td align='center'><input disabled='1'
738 dojoType= \" dijit.form.CheckBox \" $checked
739 type= \" checkbox \" ></td>" ;
741 print "<td> $name </td>" ;
742 print "<td>" . htmlspecialchars ( $about [ 1 ]);
744 print " — <a target= \" _blank \" class= \" visibleLink \"
745 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
748 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
749 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
751 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
752 if ( in_array ( $name , $system_enabled )) {
753 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \"
754 class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
763 print "<tr><td colspan='4'><h3>" . __ ( "User plugins" ). "</h3></td></tr>" ;
765 print "<tr class= \" title \" >
766 <td width= \" 5% \" > </td>
767 <td width='10%'>" . __ ( 'Plugin' ). "</td>
768 <td width=''>" . __ ( 'Description' ). "</td>
769 <td width='5%'>" . __ ( 'Version' ). "</td>
770 <td width='10%'>" . __ ( 'Author' ). "</td></tr>" ;
773 foreach ( $tmppluginhost -> get_plugins () as $name => $plugin ) {
774 $about = $plugin -> about ();
776 if (! $about [ 3 ] && strpos ( $name , "example" ) === FALSE ) {
778 if ( in_array ( $name , $system_enabled )) {
779 $checked = "checked='1'" ;
780 $disabled = "disabled='1'" ;
782 } else if ( in_array ( $name , $user_enabled )) {
783 $checked = "checked='1'" ;
785 $rowclass = "Selected" ;
792 print "<tr class=' $rowclass '>" ;
794 print "<td align='center'><input id='FPCHK- $name ' name='plugins[]' value=' $name ' onclick='toggleSelectRow2(this);'
795 dojoType= \" dijit.form.CheckBox \" $checked $disabled
796 type= \" checkbox \" ></td>" ;
798 print "<td><label for='FPCHK- $name '> $name </label></td>" ;
799 print "<td><label for='FPCHK- $name '>" . htmlspecialchars ( $about [ 1 ]) . "</label>" ;
801 print " — <a target= \" _blank \" class= \" visibleLink \"
802 href= \" " . htmlspecialchars ( $about [ 4 ]). " \" >" . __ ( "more info" ). "</a>" ;
806 print "<td>" . htmlspecialchars ( sprintf ( "%.2f" , $about [ 0 ])) . "</td>" ;
807 print "<td>" . htmlspecialchars ( $about [ 2 ]) . "</td>" ;
809 if ( count ( $tmppluginhost -> get_all ( $plugin )) > 0 ) {
810 if ( in_array ( $name , $system_enabled ) ||
in_array ( $name , $user_enabled )) {
811 print "<td><a href='#' onclick= \" clearPluginData(' $name ') \" class='visibleLink'>" . __ ( "Clear data" ). "</a></td>" ;
825 print "<p><button dojoType= \" dijit.form.Button \" type= \" submit \" >" .
826 __ ( "Enable selected plugins" ). "</button></p>" ;
830 print "</div>" ; #pane
833 $pluginhost -> run_hooks ( $pluginhost :: HOOK_PREFS_TAB
,
834 "hook_prefs_tab" , "prefPrefs" );
836 print "</div>" ; #container
839 function toggleAdvanced () {
840 $_SESSION [ "prefs_show_advanced" ] = ! $_SESSION [ "prefs_show_advanced" ];
843 function otpqrcode () {
844 require_once "lib/otphp/vendor/base32.php" ;
845 require_once "lib/otphp/lib/otp.php" ;
846 require_once "lib/otphp/lib/totp.php" ;
847 require_once "lib/phpqrcode/phpqrcode.php" ;
849 $result = db_query ( $this -> link
, "SELECT login,salt,otp_enabled
851 WHERE id = " . $_SESSION [ "uid" ]);
853 $base32 = new Base32 ();
855 $login = db_fetch_result ( $result , 0 , "login" );
856 $otp_enabled = sql_bool_to_bool ( db_fetch_result ( $result , 0 , "otp_enabled" ));
859 $secret = $base32 -> encode ( sha1 ( db_fetch_result ( $result , 0 , "salt" )));
860 $topt = new \OTPHP\
TOTP ( $secret );
861 print QRcode
:: png ( $topt -> provisioning_uri ( $login ));
865 function otpenable () {
866 $password = db_escape_string ( $this -> link
, $_REQUEST [ "password" ]);
867 $enable_otp = $_REQUEST [ "enable_otp" ] == "on" ;
870 $authenticator = $pluginhost -> get_plugin ( $_SESSION [ "auth_module" ]);
872 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
875 db_query ( $this -> link
, "UPDATE ttrss_users SET otp_enabled = true WHERE
876 id = " . $_SESSION [ "uid" ]);
881 print "ERROR: " . __ ( "Incorrect password" );
886 function otpdisable () {
887 $password = db_escape_string ( $this -> link
, $_REQUEST [ "password" ]);
890 $authenticator = $pluginhost -> get_plugin ( $_SESSION [ "auth_module" ]);
892 if ( $authenticator -> check_password ( $_SESSION [ "uid" ], $password )) {
894 db_query ( $this -> link
, "UPDATE ttrss_users SET otp_enabled = false WHERE
895 id = " . $_SESSION [ "uid" ]);
899 print "ERROR: " . __ ( "Incorrect password" );
904 function setplugins () {
905 if ( is_array ( $_REQUEST [ "plugins" ]))
906 $plugins = join ( "," , $_REQUEST [ "plugins" ]);
910 set_pref ( $this -> link
, "_ENABLED_PLUGINS" , $plugins );
913 function clearplugindata () {
914 $name = db_escape_string ( $this -> link
, $_REQUEST [ "name" ]);
917 $pluginhost -> clear_data ( $pluginhost -> get_plugin ( $name ));
920 function customizeCSS () {
921 $value = get_pref ( $this -> link
, "USER_STYLESHEET" );
923 $value = str_replace ( "<br/>" , " \n " , $value );
925 print_notice ( T_sprintf ( "You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target= \" _blank \" class= \" visibleLink \" href= \" %s\" >This file</a> can be used as a baseline." , "tt-rss.css" ));
927 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" op \" value= \" rpc \" >" ;
928 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" method \" value= \" setpref \" >" ;
929 print "<input dojoType= \" dijit.form.TextBox \" style= \" display : none \" name= \" key \" value= \" USER_STYLESHEET \" >" ;
931 print "<table width='100%'><tr><td>" ;
932 print "<textarea dojoType= \" dijit.form.SimpleTextarea \"
933 style='font-size : 12px; width : 100%; height: 200px;'
934 placeHolder='body#ttrssMain { font-size : 14px; };'
935 name='value'> $value </textarea>" ;
936 print "</td></tr></table>" ;
938 print "<div class='dlgButtons'>" ;
939 print "<button dojoType= \" dijit.form.Button \"
940 onclick= \" dijit.byId('cssEditDlg').execute() \" >" . __ ( 'Save' ). "</button> " ;
941 print "<button dojoType= \" dijit.form.Button \"
942 onclick= \" dijit.byId('cssEditDlg').hide() \" >" . __ ( 'Cancel' ). "</button>" ;
947 function editPrefProfiles () {
948 print "<div dojoType= \" dijit.Toolbar \" >" ;
950 print "<div dojoType= \" dijit.form.DropDownButton \" >" .
951 "<span>" . __ ( 'Select' ). "</span>" ;
952 print "<div dojoType= \" dijit.Menu \" style= \" display: none; \" >" ;
953 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'all') \"
954 dojoType= \" dijit.MenuItem \" >" . __ ( 'All' ). "</div>" ;
955 print "<div onclick= \" selectTableRows('prefFeedProfileList', 'none') \"
956 dojoType= \" dijit.MenuItem \" >" . __ ( 'None' ). "</div>" ;
957 print "</div></div>" ;
959 print "<div style= \" float : right \" >" ;
961 print "<input name= \" newprofile \" dojoType= \" dijit.form.ValidationTextBox \"
963 <button dojoType= \" dijit.form.Button \"
964 onclick= \" dijit.byId('profileEditDlg').addProfile() \" >" .
965 __ ( 'Create profile' ). "</button></div>" ;
969 $result = db_query ( $this -> link
, "SELECT title,id FROM ttrss_settings_profiles
970 WHERE owner_uid = " . $_SESSION [ "uid" ]. " ORDER BY title" );
972 print "<div class= \" prefProfileHolder \" >" ;
974 print "<form id= \" profile_edit_form \" onsubmit= \" return false \" >" ;
976 print "<table width= \" 100% \" class= \" prefFeedProfileList \"
977 cellspacing= \" 0 \" id= \" prefFeedProfileList \" >" ;
979 print "<tr class= \" placeholder \" id= \" FCATR-0 \" >" ; #odd
981 print "<td width='5%' align='center'><input
983 onclick='toggleSelectRow2(this);'
984 dojoType= \" dijit.form.CheckBox \"
985 type= \" checkbox \" ></td>" ;
987 if (! $_SESSION [ "profile" ]) {
988 $is_active = __ ( "(active)" );
994 __ ( "Default profile" ) . " $is_active </span></td>" ;
1000 while ( $line = db_fetch_assoc ( $result )) {
1002 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
1004 $profile_id = $line [ "id" ];
1005 $this_row_id = "id= \" FCATR- $profile_id\" " ;
1007 print "<tr class= \" placeholder \" $this_row_id >" ;
1009 $edit_title = htmlspecialchars ( $line [ "title" ]);
1011 print "<td width='5%' align='center'><input
1012 onclick='toggleSelectRow2(this);'
1013 id='FCATC- $profile_id '
1014 dojoType= \" dijit.form.CheckBox \"
1015 type= \" checkbox \" ></td>" ;
1017 if ( $_SESSION [ "profile" ] == $line [ "id" ]) {
1018 $is_active = __ ( "(active)" );
1023 print "<td><span dojoType= \" dijit.InlineEditBox \"
1024 width= \" 300px \" autoSave= \" false \"
1025 profile-id= \" $profile_id\" >" . $edit_title .
1026 "<script type= \" dojo/method \" event= \" onChange \" args= \" item \" >
1030 content: {op: 'rpc', method: 'saveprofile',
1032 id: this.srcNodeRef.getAttribute('profile-id')},
1033 load: function(response) {
1034 elem.attr('value', response);
1038 </span> $is_active </td>" ;
1049 print "<div class='dlgButtons'>
1050 <div style='float : left'>
1051 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').removeSelected() \" >" .
1052 __ ( 'Remove selected profiles' ). "</button>
1053 <button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').activateProfile() \" >" .
1054 __ ( 'Activate profile' ). "</button>
1057 print "<button dojoType= \" dijit.form.Button \" onclick= \" dijit.byId('profileEditDlg').hide() \" >" .
1058 __ ( 'Close this window' ). "</button>" ;
1063 private function getShortDesc ( $pref_name ) {
1064 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1065 return $this -> pref_help
[ $pref_name ][ 0 ];
1070 private function getHelpText ( $pref_name ) {
1071 if ( isset ( $this -> pref_help
[ $pref_name ])) {
1072 return $this -> pref_help
[ $pref_name ][ 1 ];
1077 private function getSectionName ( $id ) {
1078 if ( isset ( $this -> pref_sections
[ $id ])) {
1079 return $this -> pref_sections
[ $id ];