############################################################################## # # GPL # Contributed by a Metadot fan. # ############################################################################## package PageCounter; use Metadot qw ($USER $PARAMS); use DBAccess; use strict; use vars qw (@ISA); @ISA=qw (GizmoBuilder); my $version = "1.0"; sub get_version { return $version; } # ============================================================================ sub new { my $proto = shift; my $class = ref ($proto) || $proto; my $args = $class->normalize_constructor_args (shift); my $id = $args->{id}; my $self; if ( defined ($id) ) { return $class->restore ($id); } $self = $class->SUPER::new ($args); $self->{is_a} = __PACKAGE__; $self->set_field_info ( "name", "Name", 1, "description", "Caption - \# will be replaced with count", 1, "i1", "Count - Reset initial count value", 0, ); bless ($self, $class); return $self; } # ============================================================================ sub exec_show { my $self = shift; my $context = shift; return $self->show (); } # ============================================================================ sub exec_show_summary { my $self = shift; my $context = shift; return $self->show_summary (); } # ============================================================================ sub show { my $self = shift; # Just duplicate the summary view return $self->show_summary (); } # ============================================================================ # This is the primary display for the gizmo sub show_summary { my $self = shift; my ($count, $content); $content = $self->get_description (); $count = $self->get_i1 (); # Update the count $count = $count + 1; # Create the HTML string by replacing # with the count. $content =~ s/\#/$count/; # Initialize the html string. my $html = $self->get_buttons (); # Add more $html .= $content; # Now update the count $self->{i1} = $count; $self->save (); return $html; } # ============================================================================ # Bypass template processing sub response_may_contain_content { my $self = shift; return 1; } # ============================================================================ sub get_gizmo_name { return "Page Counter"; }