Update of /cvs/scoop/scoop/struct/patch-files/current In directory sodium.sabren.com:/tmp/cvs-serv14523/struct/patch-files/current Modified Files: README Added Files: patch-05-UserPrefs2.sql script-05-post.pl Log Message: Fixes for userprefs (and comment post form) and some patented rusty "wouldn't it be cool if" features for userprefs. -janra Index: README =================================================================== RCS file: /cvs/scoop/scoop/struct/patch-files/current/README,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** README 4 Aug 2004 21:49:49 -0000 1.95 --- README 17 Aug 2004 19:03:42 -0000 1.96 *************** *** 32,35 **** --- 32,38 ---- New flexible user preferences. Both -pre and -post scripts are required + Aug 17 11:30 patch-05-UserPrefs2.sql + Bugfixes and small feature additions for the above userprefs patch. + Any problems, email scoop-help at lists.kuro5hin.org (don't forget to join!) join here: http://lists.kuro5hin.org/mailman/listinfo/scoop-help --- NEW FILE: script-05-post.pl --- #!/usr/bin/perl use strict; use Getopt::Std; use DBI; my $args = &get_args(); my $db_user = $args->{u}; my $db_pass = $args->{p}; my $db_port = $args->{o}; my $db_name = $args->{d}; my $db_host = $args->{h}; my $QUIET = $args->{q} || 0; my $dsn = "DBI:mysql:database=$db_name:host=$db_host:port=$db_port"; my $dbh = DBI->connect($dsn, $db_user, $db_pass); my ($query, $sth, $rv); my $default; $|++; my $block; $block = &grab_block($dbh,'comment_not_logged_in'); $block =~ s/\$anon/%%anon_user_nick%%/; &update_block($dbh,'comment_not_logged_in',$block); $block = &grab_block($dbh,'comment_post_form'); $block =~ s/%%rootdir%%\/#here/%%rootdir%%\/comments\/%%sid%%\/%%pid%%\/post#here/; &update_block($dbh,'comment_post_form',$block); $block = &grab_block($dbh,'commentreply_display'); $block =~ s/100\\%/100%/; &update_block($dbh,'commentreply_display',$block); $block = &grab_block($dbh,'comment_posted_display'); $block =~ s/100\\%/100%/; &update_block($dbh,'comment_posted_display',$block); $block = &grab_block($dbh,'new_user_html'); $block =~ s/required_prefs/signup_prefs/; &update_block($dbh,'new_user_html',$block); $block = &grab_box($dbh,'userpref_menu'); $block =~ s/>Protected</>Email and Password</; &update_box($dbh,'userpref_menu',$block); # utility functions follow from here sub delete_var { my ($dbh, $id) = @_; my $query = "DELETE FROM vars WHERE name=" . $dbh->quote($id); my $sth = $dbh->prepare($query); $sth->execute; $sth->finish; } sub grab_var { my ($dbh, $id) = @_; my $query = "SELECT value FROM vars WHERE name = " . $dbh->quote($id); my $sth = $dbh->prepare($query); $sth->execute; my ($contents) = $sth->fetchrow_array; $sth->finish; return $contents; } sub update_var { my ($dbh, $id, $contents) = @_; my $query = "UPDATE vars SET value = ? WHERE name = ?"; my $sth = $dbh->prepare($query); $sth->execute($contents, $id); $sth->finish; } sub grab_block { my ($dbh, $bid) = @_; my $query = "SELECT block FROM blocks WHERE bid = " . $dbh->quote($bid); my $sth = $dbh->prepare($query); $sth->execute; my ($contents) = $sth->fetchrow_array; $sth->finish; return $contents; } sub update_block { my ($dbh, $bid, $contents) = @_; my $query = "UPDATE blocks SET block = ? WHERE bid = ?"; my $sth = $dbh->prepare($query); $sth->execute($contents, $bid); $sth->finish; } sub grab_box { my ($dbh, $box) = @_; my $query = "SELECT content FROM box WHERE boxid = " . $dbh->quote($box); my $sth = $dbh->prepare($query); $sth->execute; my ($contents) = $sth->fetchrow_array; $sth->finish; return $contents; } sub update_box { my ($dbh, $box, $contents) = @_; my $query = "UPDATE box SET content = ? WHERE boxid = ?"; my $sth = $dbh->prepare($query); $sth->execute($contents, $box); $sth->finish; } sub mesg { print @_ unless $QUIET; } sub get_args { my %info; my @neededargs; getopts("u:p:d:h:o:vqD", \%info); # now first generate an array of hashrefs that tell us what we # still need to get foreach my $arg ( qw( u p d h o ) ) { next if ( $info{$arg} and $info{$arg} ne '' ); if( $arg eq 'u' ) { push( @neededargs, {arg => 'u', q => 'db username? ', default => 'nobody'} ); } elsif( $arg eq 'p' ) { push( @neededargs, {arg => 'p', q => 'db password? ', default => 'password'} ); } elsif( $arg eq 'd' ) { push( @neededargs, {arg => 'd', q => 'db name? ', default => 'scoop'} ); } elsif( $arg eq 'h' ) { push( @neededargs, {arg => 'h', q => 'db hostname? ', default => 'localhost'} ); } elsif( $arg eq 'o' ) { push( @neededargs, {arg => 'o', q => 'db port? ', default => '3306'} ); } } foreach my $h ( @neededargs ) { my $answer = ''; print "$h->{q}"."[$h->{default}] "; chomp( $answer = <STDIN> ); $answer = $h->{default} unless( $answer && $answer ne '' ); $info{ $h->{arg} } = $answer; } return \%info; } --- NEW FILE: patch-05-UserPrefs2.sql --- -- adding support for prefs shown on newuser page that aren't required -- 'normal' is for prefs shown only in the prefs pages -- 'required' is for required prefs, shown on the newuser page -- 'signup' is for non-required prefs that are shown on the newuser page ALTER TABLE pref_items ADD signup varchar(9); UPDATE pref_items SET signup='required' WHERE required='1'; UPDATE pref_items SET signup='normal' WHERE required='0'; ALTER TABLE pref_items DROP required; -- edit_prefs (remove required checkbox; add signup radio buttons) UPDATE blocks SET block='%%title_font%%Edit User Preferences%%title_font_end%%\r\n\r\n<P>%%err_font%%%%update_msg%%%%err_font_end%%</P>\r\n\r\n<FORM action="%%rootdir%%/admin/prefs" method="post">\r\n<INPUT type="submit" name="save" value="Save">\r\n<INPUT type="submit" name="get" value="Get">\r\n\r\n<TABLE border="0">\r\n <TR>\r\n <TD><B>Select Preference:</B></TD>\r\n <TD>%%pref_selectbox%%</TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"><B>Delete:</B> <INPUT type="checkbox" name="delete" value="1"> Many prefs should be disabled (not deleted) if you want to prevent users from changing them, as Scoop requires their default values in order to run correctly.</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Name:</B></TD>\r\n <TD><INPUT type="text" size="20" maxlength="32" name="prefname" value="%%pref_name%%"> <B>Enabled:</B><INPUT type="checkbox" name="enabled" value="1"%%pref_enabled%%></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Title:</B></TD>\r\n <TD><INPUT type="text" ! size="50" maxlength="50" name="title" value="%%pref_title%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Description:</B>\r\n <BR>The description may contain any HTML or normal block reference.</TD>\r\n <TD><TEXTAREA rows="%%rows%%" cols="%%cols%%" name="description">%%pref_desc%%</TEXTAREA></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Default Value:</B></TD>\r\n <TD><INPUT type="text" size="30" name="default_value" value="%%pref_default%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"> </TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"><B>Preference Display Settings</B></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Shown on signup page?</B></TD>\r\n <TD><INPUT type="radio" name="signup" value="normal"%%pref_signup_normal%%> No\r\n <BR><INPUT type="radio" name="signup" value="signup"%%pref_signup_signup%%> Yes\r\n <BR><INPUT type="radio" name="signup" value="required"%%pref_signup_required%%> Yes, and it\'s required</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Pref! erences page:</B></TD>\r\n <TD><INPUT type="text" size="20" maxleng th="50" name="page" value="%%pref_page%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Order on page:</B></TD>\r\n <TD><INPUT type="text" size="5" maxlength="5" name="display_order" value="%%pref_order%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Control to display:</B>\r\n <BR>Special key <I>value</I> is the current value of the preference</TD>\r\n <TD><INPUT type="text" size="50" name="field" value="%%pref_field%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Template:</B></TD>\r\n <TD>%%pref_template%%</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Visible on public user info page?</B></TD>\r\n <TD><INPUT type="checkbox" name="visible" value="1"%%pref_visible%%></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Formatting to apply to value</B></TD>\r\n <TD><INPUT type="text" name="display_fmt" value="%%pref_fmt%%" size="50"></TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"> </TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"><B>Requires</B></TD>\r\n </TR>\r\n <TR>\r\n <! TD><B>Site Control:</B></TD>\r\n <TD>%%pref_var%%</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Perm to view:</B></TD>\r\n <TD>%%pref_perm_view%%</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Perm to edit:</B></TD>\r\n <TD>%%pref_perm_edit%%</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Trusted User status:</B></TD>\r\n <TD><INPUT type="checkbox" name="req_tu" value="1"%%pref_tu%%></TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"> </TD>\r\n </TR>\r\n <TR>\r\n <TD colspan="2"><B>Validation</B> (blank to allow anything)</TD>\r\n </TR>\r\n <TR>\r\n <TD><B>HTML allowed?</B></TD>\r\n <TD><INPUT type="checkbox" name="html" value="1"%%pref_html%%></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Field length:</B></TD>\r\n <TD><INPUT type="text" size="5" maxlength="5" name="length" value="%%pref_length%%"></TD>\r\n </TR>\r\n <TR>\r\n <TD><B>Regular expression:</B>\r\n <BR>Perl regexp - but you must escape pipes</TD>\r\n <TD><INPUT type="text" size="50" name="regex"! value="%%pref_regex%%"></TD>\r\n </TR>\r\n</TABLE>\r\n\r\n<INPUT typ e="submit" name="save" value="Save">\r\n<INPUT type="submit" name="get" value="Get">\r\n</FORM>\r\n' WHERE bid='edit_prefs'; -- need to update: -- new_user_html (change |required_prefs| to |signup_prefs| - script)