Update of /cvs/scoop/scoop/lib/Scoop
In directory lithium.sabren.com:/tmp/cvs-serv17299/lib/Scoop
Modified Files:
Interface.pm Macros.pm
Log Message:
Bug 85: adding hulver's patch to let you restrict where and by whom specific
macros may be used.
-janra
Index: Interface.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Interface.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** Interface.pm 4 Aug 2004 21:49:48 -0000 1.57
--- Interface.pm 11 Feb 2005 22:11:04 -0000 1.58
***************
*** 107,111 ****
if ($rv) {
while (my $macro_record = $sth->fetchrow_hashref) {
! $macros->{$macro_record->{name}} = $macro_record->{value};
}
}
--- 107,112 ----
if ($rv) {
while (my $macro_record = $sth->fetchrow_hashref) {
! $macros->{$macro_record->{name}}->{value} = $macro_record->{value};
! $macros->{$macro_record->{name}}->{parameter} = $macro_record->{parameter};
}
}
Index: Macros.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Macros.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Macros.pm 30 Jul 2004 08:12:56 -0000 1.3
--- Macros.pm 11 Feb 2005 22:11:04 -0000 1.4
***************
*** 58,65 ****
my $S = shift;
my $text = shift || '';
return $text unless (exists $S->{UI}->{VARS}->{use_macros} && $S->{UI}->{VARS}->{use_macros});
! $text =~ s{\(\((.*?)\)\)}{ $S->_process_macro($1) }sige;
return $text;
--- 58,66 ----
my $S = shift;
my $text = shift || '';
+ my $context = shift || '';
return $text unless (exists $S->{UI}->{VARS}->{use_macros} && $S->{UI}->{VARS}->{use_macros});
! $text =~ s{\(\((.*?)\)\)}{ $S->_process_macro($1,$context) }sige;
return $text;
***************
*** 71,74 ****
--- 72,76 ----
my $S = shift;
my $text = shift;
+ my $context = shift;
# If there is no macro with the given name, just return the original text.
***************
*** 79,83 ****
my $args = $2 || '';
! my $macro_text = $S->{UI}->{MACROS}->{$macro_name} || '';
$macro_text =~ s/\|/%%/g;
$macro_text = $S->interpolate($macro_text,$S->{UI}->{BLOCKS},{special =>'true'});
--- 81,133 ----
my $args = $2 || '';
!
! # get the attributes seperated
! my @parts = split(/\s*,\s*/, $S->{UI}->{MACROS}->{$macro_name}->{parameter});
! foreach my $p (@parts) {
! my $v;
! # if the attrib has a value, seperate it off
! ($p, $v) = split(/\s*=\s*/, $p);
! if ($v) {
! # remove optional quotes around the value
! $v =~ s/^["']//;
! $v =~ s/["']$//;
! # escape any slashes
! $v =~ s/\//\\\//g;
! }
! $p = lc $p; # case-insensitive once again
! # check to see if the current group is allowed to use this tag. if
! # the value isn't set (or the attrib isn't set at all), then all
! # groups can use the tag
! if (($p eq '-groups') && $v) {
! my $invert = ($v =~ s/^\!(.+)/$1/);
! # allowed groups are seperated by spaces
! my @groups = split(/ /, $v);
! # if the list isn't inverted, then make sure the current group
! # is listed. if it is inverted, make sure it's not listed
! #unless (grep(/^$S->{GID}$/, @groups)) {
! if (
! (!$invert && !grep(/^$S->{GID}$/, @groups)) ||
! ($invert && grep(/^$S->{GID}$/, @groups))
! ) {
! # skip out of processing the attributes and move to the
! return "";
! }
! } elsif (($p eq '-context') && $v) {
! my @context_a = split(/ /, $v);
! $v = {};
! foreach my $c (@context_a) {
! if ($c =~ s/^\!(.+)/$1/) {
! # if any of the items in context start with !, all of
! # them are considered to be inverse
! $v->{'!'} = 1;
! }
! $v->{$c} = 1;
! }
! if ( ($v->{$context} && $v->{'!'}) || (!$v->{$context} && !$v->{'!'}) ) {
! return "";
! }
! }
! }
! my $macro_text = $S->{UI}->{MACROS}->{$macro_name}->{value} || '';
$macro_text =~ s/\|/%%/g;
$macro_text = $S->interpolate($macro_text,$S->{UI}->{BLOCKS},{special =>'true'});
***************
*** 143,147 ****
DEBUG => $DEBUG,
FROM => 'macros',
! WHAT => 'name, value, description, category',
ORDER_BY => 'name ASC'
});
--- 193,197 ----
DEBUG => $DEBUG,
FROM => 'macros',
! WHAT => 'name, value, description, category, parameter',
ORDER_BY => 'name ASC'
});
***************
*** 164,167 ****
--- 214,218 ----
description => $macroinfo->{description},
category => $macroinfo->{category},
+ parameter => $macroinfo->{parameter}
});
}
***************
*** 201,205 ****
my $S = shift;
my $macro_array = shift;
! my $edit = shift || 'Get';
my $item = shift;
--- 252,257 ----
my $S = shift;
my $macro_array = shift;
! my $edit = shift;
! my $mode = shift;
my $item = shift;
***************
*** 211,215 ****
# if $edit is set, these will contain the values for the macro asked for,
# else, they will be blank. These are set about 20 lines down from here
! my ($name, $category, $value, $description);
# if they just added or changed it, get it from the cgi params
--- 263,267 ----
# if $edit is set, these will contain the values for the macro asked for,
# else, they will be blank. These are set about 20 lines down from here
! my ($name, $category, $value, $description, $parameter);
# if they just added or changed it, get it from the cgi params
***************
*** 227,230 ****
--- 279,283 ----
$value = $S->{CGI}->param('value');
$description = $S->{CGI}->param('description');
+ $parameter = $S->{CGI}->param('parameter');
$category .= "," if ( $category );
***************
*** 248,256 ****
# if they are getting the macro, get it from the db
! if( $macro->{name} eq $v && $edit && $edit eq 'Get' ) {
$name = $macro->{name};
$category = $macro->{category};
$value = $macro->{value};
$description = $macro->{description};
}
--- 301,310 ----
# if they are getting the macro, get it from the db
! if( $macro->{name} eq $S->{CGI}->param('macro') && $edit && $edit eq 'Get' ) {
$name = $macro->{name};
$category = $macro->{category};
$value = $macro->{value};
$description = $macro->{description};
+ $parameter = $macro->{parameter};
}
***************
*** 279,282 ****
--- 333,345 ----
# done category chooser
+ $value =~ s/&/&/g;
+ $value =~ s/</</g;
+ $value =~ s/>/>/g;
+ $value =~ s/"/"/g;
+ $parameter =~ s/&/&/g;
+ $parameter =~ s/</</g;
+ $parameter =~ s/>/>/g;
+ $parameter =~ s/"/"/g;
+
# substitute values into html template
$content =~ s/%%macroselect%%/$macroselect/;
***************
*** 285,288 ****
--- 348,352 ----
$content =~ s/%%value%%/$value/;
$content =~ s/%%description%%/$description/;
+ $content =~ s/%%parameter%%/$parameter/;
return $content;
***************
*** 305,309 ****
# now that we have the header, generate the inputs for each macro
my ($texts, $nums, $bools, $tareas);
! my ($name, $value, $description); # $name is a link, $value is the appropriate form element, $description is text
for my $macro (@$macro_array) {
--- 369,373 ----
# now that we have the header, generate the inputs for each macro
my ($texts, $nums, $bools, $tareas);
! my ($name, $value, $description, $parameter); # $name is a link, $value is the appropriate form element, $description is text
for my $macro (@$macro_array) {
***************
*** 324,337 ****
$macro->{value} =~ s/"/"/g;
! # text, so a bigger form for a short string
! $name = qq|<a href="%%rootdir%%/admin/macros/edit/$macro->{name}">$macro->{name}</a>|;
! $value = qq|<INPUT type="hidden" name="inform_$macro->{name}" value="1"><TEXTAREA name="$macro->{name}" cols="60" rows="20" wrap="soft">$macro->{value}</TEXTAREA>|;
! $description = $macro->{description};
! $line =~ s/%%name%%/$name/;
! $line =~ s/%%value%%/$value/;
! $line =~ s/%%description%%/$description/;
! $texts .= $line;
}
--- 388,408 ----
$macro->{value} =~ s/"/"/g;
! # text, so a bigger form for a short string
! $name = qq|<a href="%%rootdir%%/admin/macros/edit/$macro->{name}">$macro->{name}</a>|;
! $value = qq|<INPUT type="hidden" name="inform_$macro->{name}" value="1"><TEXTAREA name="$macro->{name}" cols="60" rows="20" wrap="soft">$macro->{value}</TEXTAREA>|;
! $description = $macro->{description};
! $parameter = $macro->{parameter};
! $parameter =~ s/&/&/g;
! $parameter =~ s/</</g;
! $parameter =~ s/>/>/g;
! $parameter =~ s/"/"/g;
! $line =~ s/%%name%%/$name/;
! $line =~ s/%%value%%/$value/;
! $line =~ s/%%description%%/$description/;
! $line =~ s/%%parameter%%/$parameter/;
!
! $texts .= $line;
}
***************
*** 435,438 ****
--- 506,510 ----
my $description = $S->{CGI}->param('description');
my $category = $S->{CGI}->param('category');
+ my $parameter = $S->{CGI}->param('parameter');
my @catsel = $S->{CGI}->param('catsel');
warn "@catsel and ". $#catsel if $DEBUG;
***************
*** 454,459 ****
$description = $S->{DBH}->quote($description);
! $value = $S->{DBH}->quote($value);
! $category = $S->{DBH}->quote($category);
if ($macro eq 'new') {
--- 526,532 ----
$description = $S->{DBH}->quote($description);
! $value = $S->{DBH}->quote($value);
! $category = $S->{DBH}->quote($category);
! $parameter = $S->{DBH}->quote($parameter);
if ($macro eq 'new') {
***************
*** 462,467 ****
DEBUG => 0,
INTO => 'macros',
! COLS => 'name, value, description, category',
! VALUES => qq|"$name", $value, $description, $category|});
unless( $rv ) {
--- 535,540 ----
DEBUG => 0,
INTO => 'macros',
! COLS => 'name, value, description, category, parameter',
! VALUES => qq|"$name", $value, $description, $category, $parameter|});
unless( $rv ) {
***************
*** 480,485 ****
DEBUG => 0,
WHAT => 'macros',
! SET => qq|value = $value, description = $description, category = $category|,
! WHERE => qq|name = '$macro'|});
unless( $rv ) {
--- 553,558 ----
DEBUG => 0,
WHAT => 'macros',
! SET => qq|value = $value, description = $description, category = $category, parameter = $parameter|,
! WHERE => qq|name = "$macro"|});
unless( $rv ) {