Skip to content

Commit

Permalink
[#1032] Convert /misc/adult_* from BML
Browse files Browse the repository at this point in the history
Also converts to Foundation since that was straightforward
  • Loading branch information
afuna committed Nov 4, 2014
1 parent fa2075d commit 22193d1
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 278 deletions.
24 changes: 21 additions & 3 deletions cgi-bin/Apache/LiveJournal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -579,18 +579,25 @@ sub trans
$apache_r->notes->{returl} = $returl;

unless ( DW::Logic::AdultContent->user_confirmed_page( user => $remote, journal => $u, entry => $entry, adult_content => $adult_content ) ) {
my $adult_content_handler = sub {
$apache_r->handler( "perl-script" );
$apache_r->notes->{adult_content_type} = $_[0];
$apache_r->push_handlers( PerlHandler => \&adult_interstitial );
return OK;
};

# logged in users with a defined age of under 18 are blocked from explicit adult content
# logged in users with a defined age of under 18 are given a confirmation page for adult concepts depending on their settings
# logged in users with a defined age of 18 or older are given confirmation pages for adult content depending on their settings
# logged in users without defined ages and logged out users are given confirmation pages for all adult content
if ( $adult_content eq "explicit" && $remote && $remote->is_minor ) {
return $bml_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'explicit_blocked' ) );
return $adult_content_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'explicit_blocked' ) );
} else {
my $hide_adult_content = $remote ? $remote->hide_adult_content : "concepts";
if ( $adult_content eq "explicit" && $hide_adult_content ne "none" ) {
return $bml_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'explicit' ) );
return $adult_content_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'explicit' ) );
} elsif ( $adult_content eq "concepts" && $hide_adult_content eq "concepts" ) {
return $bml_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'concepts' ) );
return $adult_content_handler->( DW::Logic::AdultContent->adult_interstitial_path( type => 'concepts' ) );
}
}
}
Expand Down Expand Up @@ -1238,6 +1245,17 @@ sub vgift_content
return OK;
}

sub adult_interstitial {
my $apache_r = shift;
my $int_redir = DW::Routing->call( uri => $apache_r->notes->{adult_content_type} );

if ( defined $int_redir ) {
# we got a match; clear the request cache and return DECLINED.
LJ::start_request();
return DECLINED;
}
}

sub journal_content
{
my $apache_r = shift;
Expand Down
151 changes: 151 additions & 0 deletions cgi-bin/DW/Controller/Journal/AdultContent.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#!/usr/bin/perl
#
# DW::Controller::Journal::Protected
#
# Displays when a user tries to access protected content.
#
# Author:
# Allen Petersen <allen@suberic.net>
#
# Copyright (c) 2010-2014 by Dreamwidth Studios, LLC.
#
# This program is free software; you may redistribute it and/or modify it under
# the same terms as Perl itself. For a copy of the license, please reference
# 'perldoc perlartistic' or 'perldoc perlgpl'.
#

package DW::Controller::Journal::Protected;

use strict;

use DW::Controller;
use DW::Template;
use DW::Routing;
use DW::Request;

DW::Routing->register_string( "/journal/adult_concepts", \&adult_concepts_handler, app => 1 );
DW::Routing->register_string( "/journal/adult_explicit", \&adult_explicit_handler, app => 1 );
DW::Routing->register_string( "/journal/adult_explicit_blocked", \&adult_explicit_blocked_handler, app => 1 );

sub _init_vars {
my ( $type, $journal, $entry ) = @_;
return {
type => $type,
form_url => LJ::create_url( DW::Logic::AdultContent->adult_interstitial_path( type => $type ), host => $LJ::DOMAIN_WEB ),

entry => $entry,
journal => $journal,

poster => defined $entry ? $entry->poster : $journal,
markedby => defined $entry ? $entry->adult_content_marker : $journal->adult_content_marker,
reason => DW::Logic::AdultContent->interstitial_reason( $journal, $entry ),
};
}

sub _extract_from_request {
my $r = $_[0];
my $get = $r->get_args;
my $post = $r->post_args;

return (
$r->note( 'returl' ) || $post->{ret} || $get->{ret},
$r->pnote( 'entry' ),
$r->pnote( 'user' ),
)
}

sub adult_concepts_handler {
my ( $opts ) = @_;

my ( $ok, $rv ) = controller( anonymous => 1, form_auth => 1 );
return $rv unless $ok;

my $r = $rv->{r};
my $remote = $rv->{remote};

my ( $returl, $entry, $journal ) = _extract_from_request( $r );
my $type = "concepts";

# reload this entry if the user is logged in and is not choosing to
# hide adult content since otherwise, the user shouldn't be here
return $r->redirect( $returl ) if $remote && $remote->hide_adult_content ne 'concepts';

# if we posted, then record we did so and let them view the entry
if ( $r->did_post && $returl ) {
my $post = $r->post_args;
DW::Logic::AdultContent->set_confirmed_pages( user => $remote,
journalid => $post->{journalid},
entryid => $post->{entryid},
adult_content => $type
);
return $r->redirect( $returl );
}

# if we didn't provide a journal, then redirect away. We can't do anything here
return $r->redirect( $LJ::SITEROOT ) unless $journal;

my $vars = _init_vars( $type, $journal, $entry );
$vars->{returl} = $returl;

return DW::Template->render_template( 'journal/adult_content.tt', $vars );
}

sub adult_explicit_handler {
my ( $opts ) = @_;

my ( $ok, $rv ) = controller( anonymous => 1, form_auth => 1 );
return $rv unless $ok;

my $r = $rv->{r};
my $remote = $rv->{remote};

my ( $returl, $entry, $journal ) = _extract_from_request( $r );
my $type = "explicit";

# reload this entry if the user is logged in, has an age, and is not
# choosing to hide adult content since otherwise, the user shouldn't be here
return $r->redirect( $returl ) if $remote && $remote->best_guess_age && $remote->hide_adult_content eq 'none';

# if we posted, then record we did so and let them view the entry
if ( $r->did_post && $returl ) {
my $post = $r->post_args;
DW::Logic::AdultContent->set_confirmed_pages( user => $remote,
journalid => $post->{journalid},
entryid => $post->{entryid},
adult_content => $type
);
return $r->redirect( $returl );
}

# if we didn't provide a journal, then redirect away. We can't do anything here
return $r->redirect( $LJ::SITEROOT ) unless $journal;

my $vars = _init_vars( $type, $journal, $entry );
$vars->{returl} = $returl;

return DW::Template->render_template( 'journal/adult_content.tt', $vars );
}

sub adult_explicit_blocked_handler {
my ( $opts ) = @_;

my ( $ok, $rv ) = controller( anonymous => 1 );
return $rv unless $ok;

my $r = $rv->{r};
my $remote = $rv->{remote};

my ( $returl, $entry, $journal ) = _extract_from_request( $r );
my $type = "explicit_blocked";

# if we didn't provide a journal, then redirect away. We can't do anything here
return $r->redirect( $LJ::SITEROOT ) unless $journal;

my $vars = _init_vars( $type, $journal, $entry );
$vars->{returl} = $returl;
delete $vars->{form_url};

return DW::Template->render_template( 'journal/adult_content.tt', $vars );
}

1;
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/perl
#
# DW::Controller::Protected
# DW::Controller::Journal::Protected
#
# Displays when a user tries to access protected content.
#
# Author:
# Allen Petersen <allen@suberic.net>
#
# Copyright (c) 2010 by Dreamwidth Studios, LLC.
# Copyright (c) 2010-2014 by Dreamwidth Studios, LLC.
#
# This program is free software; you may redistribute it and/or modify it under
# the same terms as Perl itself. For a copy of the license, please reference
# 'perldoc perlartistic' or 'perldoc perlgpl'.
#

package DW::Controller::Protected;
package DW::Controller::Journal::Protected;

use strict;
use warnings;
Expand Down
14 changes: 7 additions & 7 deletions cgi-bin/DW/Logic/AdultContent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sub adult_interstitial_path {
my $type = $opts{type};
return '' unless $type;

my $path = "$LJ::HOME/htdocs/misc/adult_${type}.bml";
my $path = "/journal/adult_${type}";
return $path;
}

Expand All @@ -105,9 +105,9 @@ sub interstitial_reason {
my $reason = LJ::ehtml( $journal->adult_content_reason );

if ( $journal->adult_content_calculated eq 'concepts' ) {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.concepts.' . $what . 'reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.concepts.' . $what . 'reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
} else {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.explicit.' . $what . 'reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.explicit.' . $what . 'reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
}

$reason_exists = 1;
Expand All @@ -118,9 +118,9 @@ sub interstitial_reason {
my $reason = LJ::ehtml( $entry->adult_content_reason );

if ( $entry->adult_content eq 'concepts' ) {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.concepts.byposter.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.concepts.byposter.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
} else {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.explicit.byposter.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.explicit.byposter.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
}
$reason_exists = 1;
}
Expand All @@ -130,9 +130,9 @@ sub interstitial_reason {
my $reason = LJ::ehtml( $entry->adult_content_maintainer_reason );

if ( $entry->adult_content_maintainer eq 'concepts' ) {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.concepts.byjournal.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.concepts.byjournal.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
} else {
$ret .= LJ::Lang::ml( '/misc/adult_content.bml.message.explicit.byjournal.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
$ret .= LJ::Lang::ml( '/journal/adult_content.tt.message.explicit.byjournal.reason', { journal => $journal->ljuser_display, poster => $poster->ljuser_display, reason => $reason } );
}
$reason_exists = 1;
}
Expand Down
4 changes: 3 additions & 1 deletion cgi-bin/LJ/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6128,9 +6128,11 @@ sub journal_base {


sub meta_discovery_links {
my ( $u, %opts ) = @_;
my $u = shift;
my $journalbase = $u->journal_base;

my %opts = ref $_[0] ? %{$_[0]} : @_;

my $ret = "";

# Automatic Discovery of RSS/Atom
Expand Down
88 changes: 0 additions & 88 deletions htdocs/misc/adult_concepts.bml

This file was deleted.

0 comments on commit 22193d1

Please sign in to comment.