Created
January 30, 2021 23:02
-
-
Save Downes/07ef87d59a16c8e1d3f66b3e9771410a to your computer and use it in GitHub Desktop.
Remote Comment Server Side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------- 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=('|'|')(.*?)"/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