Skip to content

Instantly share code, notes, and snippets.

@Downes
Created January 30, 2021 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Downes/07ef87d59a16c8e1d3f66b3e9771410a to your computer and use it in GitHub Desktop.
Save Downes/07ef87d59a16c8e1d3f66b3e9771410a to your computer and use it in GitHub Desktop.
Remote Comment Server Side
# ------- Remote Comment ----------------------------------------------------
sub rcomment {
&record_sanitize_input($vars);
while (my ($vkey,$vval) = each %$vars) {
$vars->{$vkey} =~ s/\0/,/g; # Replace 'multi' delimiter with comma
}
die "Not allowwed to comment" unless (&is_allowed("create",$table));
# Do some stuff
my $refer = $ENV{HTTP_REFERER};
my $table="post";
my $post = {
post_type => 'link',
post_link => $refer,
post_description => $vars->{description},
post_title => $vars->{title},
post_author => $vars->{author},
post_feed => $vars->{feed},
post_id => "new",
post_pub_date => &cal_date(time),
post_crdate => time,
post_creator => $Person->{person_id},
};
# Uniqueness Constraints
my $l;
if (($l = &db_locate($dbh,"post",{post_link => $post->{post_link}})) ||
($l = &db_locate($dbh,"post",{post_title => $post->{post_title}})) ) {
print "Content-type: text/html\n\n";
my $url = $Site->{st_url} . "post/" . $l;
printf(qq|<p>Duplicate Entry: <a href="%s">Post %s</a></p>|,$url,$l);
exit;
}
# Clean up
post->{post_description} =~ s/href=('|&#39;|&apos;)(.*?)"/href="$2"/ig; #'
# Submit and print record
my $id_number = &db_insert($dbh,$query,$table,$post) || die "Couldn't inset post";
&rcomment_keylist_update($id_number,"author",$post->{post_author}) || die "Couldn't associate author";
&rcomment_keylist_update($id_number,"feed",$post->{post_feed}) || die "Couldn't associate author";
print_record($dbh,$query,"post",$id_number,"html",$Site->{context});
# Send WebMention
my $content = get($post->{post_link});
die "Source page is unreachable" unless ($content);
my $endpoint = &find_webmention_endpoint($content);
if ($endpoint) {
&send_webmention($endpoint,$post->{post_link},$Site->{st_url}."post/".$id_number);
}
print "Content-type: text/html\n";
print "Location: ".$refer."#$id_number!\n\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment