##################################################################### # EDIT THE EXPORT LINE BELOW TO FIT YOUR NEEDS, BUT DO NOT UNCOMMENT! # Export = responses ##################################################################### # Plugin Name = Approve Responses (v1.0) # Author = Marko Kleen # Copyright = GPL -> see http://www.8t88.de/ # Purpose = Only show user responses that have been reviewed! ##################################################################### # Plugin types are specified in the EXPORT line above. # global: Your plugin is applied on all output # articles: Your plugin is applied on all articles' output # responses: Your plugin is applied on guestbook entries and comments # override: Your plugin overrides one of 8t88's existing subroutines # macro: Your plugin adds a new macro with new functionality ##################################################################### my ($res, $status, @date, @record) = ($_[2], undef, undef, undef); my ($response) = $res =~ /(.*?<.div>)/i; my $message_deny = 'Dieser Beitrag wird erst angezeigt, nachdem er freigeschaltet wurde!'; my $message_appr = 'Dieser Beitrag wurde freigeschaltet am '; ##################################################################### # Create "approved" table if non-existent yet ####################### if (join(' ', @tables) !~ /\bapproved\b/i) { db_query('CREATE TABLE approved (id, time, user)'); } ##################################################################### # Try to read a matching record from "approved" ##################### @record = db_query('SELECT * FROM approved WHERE id=?', $_[3]); # Prepare hyperlink parameters ###################################### $status = $ENV{'QUERY_STRING'}; $status =~ s/\&(approve|deny).*//i; # Logged in users may lock/unlock user responses #################### if ($user) { if (!$record[1]) { # This entry hasn't been approved yet! ############################ if (param('approve') == $_[3]) { # Approve this entry ######## @date = stamp2date(time()); $status = div({-class => 'edit'}, a({-href => '?'.$status.'&deny='.$_[3]}, 'Eintrag sperren')). status($message_appr.pretty_date((@date)[2,3,4]).' um '.pretty_time((@date)[1,0]). ' von '.realname($user), undef); db_query('INSERT INTO approved VALUES (?, ?, ?)', $_[3], time(), $user); } else { # No change ################# $status = div({-class => 'edit'}, a({-href => '?'.$status.'&approve='.$_[3]}, 'Eintrag freischalten')). status($message_deny, '#FF6666'); } } else { # This entry has already been approved! ########################### if (param('deny') == $_[3]) { # Deny this entry ########### $status = div({-class => 'edit'}, a({-href => '?'.$status.'&approve='.$_[3]}, 'Eintrag freischalten')). status($message_deny, '#FF6666'); db_query('DELETE FROM approved WHERE id=?', $_[3]); } else { # No change ################# @date = stamp2date($record[1]); $status = div({-class => 'edit'}, a({-href => '?'.$status.'&deny='.$_[3]}, 'Eintrag sperren')). status($message_appr.pretty_date((@date)[2,3,4]).' um '.pretty_time((@date)[1,0]). ' von '.realname($record[2]), undef); } } substr($res, index($res, $response), length($response), div({-class => 'gbook_content'}, $status.$response)); # Everyone else can only view the responses - the approved ones! #### } elsif (!@record[1]) { substr($res, index($res, $response), length($response), div({-class => 'gbook_content'}, $message_deny)); } else { undef($res); } return ($res); ##################################################################### # USAGE: # # To use this plugin simply drop it into your "8t88's CMS v2" plugins # directory. No configuration required! # # This plugin (adds and) maintains a new table in your CMS' database. # When logged in you can approve or deny user responses. Only those # responses that have been approved will be visible on your website. # # Enjoy! ##################################################################### # EOF