word/edit: replace hardcoded urls to the current page
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 15 Oct 2021 10:42:28 +0000 (12:42 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 25 Oct 2021 14:33:21 +0000 (16:33 +0200)
word/edit.plp

index 31fca23384ad2912aeae73fe723751a965252576..f7d39485c992ae1f60373d2ca445534772122cd0 100644 (file)
@@ -1,6 +1,8 @@
 <(../common.inc.plp)><:
 
+my $editorurl = '/word/edit';
 s{\Aedit(/|\z)}{} for $Request // ();
+
 Html({
        title => 'words cheat sheet admin',
        version => '1.0',
@@ -21,7 +23,6 @@ my $db = eval {
 } or Abort('Database error', 501, $@);
 
 my $user = eval {
-       my $rootpath = '/word/edit';
        if (defined $post{username}) {
                $cookie{login} = EncodeURI(join ':', @post{qw( username pass )});
        }
@@ -30,7 +31,7 @@ my $user = eval {
                if (AddCookie(CGI::Cookie->new(
                        -name    => 'login',
                        -value   => '',
-                       -path    => $rootpath,
+                       -path    => $editorurl,
                        -expires => 'now',
                )->as_string)) {
                        delete $cookie{login};
@@ -50,7 +51,7 @@ my $user = eval {
                my $httpcookie = CGI::Cookie->new(
                        -name    => 'login',
                        -value   => join(':', @{$found}{qw( username pass )}),
-                       -path    => $rootpath,
+                       -path    => $editorurl,
                ) or die "prepared object is empty\n";
                AddCookie($httpcookie->as_string);
        } or Abort(["Unable to create login cookie", $@], 403);
@@ -115,7 +116,7 @@ if (my $search = $fields{q}) {
        my $results = $db->select(word => '*', \%filter);
        say '<h1>Search</h1><ul>';
        printf("<li><small>%s</small> %s %s</li>\n",
-               $_->{id}, showlink($_->{form}, "/writer/$_->{id}"),
+               $_->{id}, showlink($_->{form}, "$editorurl/$_->{id}"),
                sprintf('<img src="/%s" style="height:3ex; width:auto" />', $wordcol{convert}->{-src}->($_)) x defined $_->{image}
        ) for $results->hashes;
        say "</ul>\n";
@@ -283,7 +284,7 @@ if (not $row->{ref}) {
                printf(
                        $ref->{id} ? '<a id="%s" href="%s">%s</a></li>' :
                        '<input id="%s" name="%1$s" value="%3$s" />',
-                       "trans-$ref->{lang}", "/writer/$ref->{id}", Entity($ref->{form} // ''),
+                       "trans-$ref->{lang}", "$editorurl/$ref->{id}", Entity($ref->{form} // ''),
                );
        }
        say '</ul></div></li>';
@@ -292,7 +293,7 @@ if (not $row->{ref}) {
 </ul>
 <p>
        <input type="submit" value="Save" />
-       <input type="submit" value="New" formaction="/writer?copy=cat" />
+       <input type="submit" value="New" formaction="<:= $editorurl :>?copy=cat" />
 </p>
 </form>
 
@@ -306,15 +307,15 @@ if ($row->{id}) {
 say '<ul>';
 my $parents = $db->select(word => '*', [{id => $row->{cat}}, {id => $row->{ref}}]);
 while (my $ref = $parents->hash) {
-       printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+       printf '<li><a href="%s/%d">%s</a></li>', $editorurl, $ref->{id}, Entity($ref->{form});
 }
 say "<li><strong>$_</strong></li>" for Entity($row->{form});
 my $children = $db->select(word => '*', {cat => $row->{id}, ref => undef}, 'grade, id');
 while (my $ref = $children->hash) {
-       printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+       printf '<li><a href="%s/%d">%s</a></li>', $editorurl, $ref->{id}, Entity($ref->{form});
 }
 :>
-<li><form action="/writer">
+<li><form action="<:= $editorurl :>">
        <input type="hidden" name="cat" value="<:= $row->{id} :>" />
        <input type="hidden" name="lang" value="<:= $row->{lang} :>" />
        <input type="submit" value="Add" />