more changes to advertisements

added two new ad spots, bottom of post#index and post#show.
spots can be selectively activated in the booru config. by default,
only original spots are active.
This commit is contained in:
Parziphal 2013-12-04 15:19:11 -05:00
parent 11d4f3772e
commit e2533565bc
6 changed files with 56 additions and 22 deletions

View File

@ -9,16 +9,13 @@ class AdvertisementsHelper extends Rails\ActionView\Helper
if ($ad->html) {
return $ad->html;
} else {
return $this->contentTag("div",
$this->linkTo(
return $this->linkTo(
$this->imageTag(
$ad->image_url,
['alt' => "Advertisement", 'width' => $ad->width, 'height' => $ad->height]
),
$this->redirectAdvertisementPath($ad),
['target' => '_blank']
),
['style' => "margin-bottom: 1em;"]
);
}
}

View File

@ -1,2 +1,3 @@
<?php
echo $this->print_advertisement("horizontal");
<div style="margin-bottom: 1em;">
<?= $this->print_advertisement("horizontal") ?>
</div>

View File

@ -1,2 +1,3 @@
<?php
echo $this->print_advertisement("vertical");
<div style="margin-bottom: 1em;">
<?= $this->print_advertisement("vertical") ?>
</div>

View File

@ -73,7 +73,7 @@
<br />
<?php if (CONFIG()->can_see_ads(current_user())) : ?>
<?php if (CONFIG()->can_show_ad('post#index-sidebar', current_user())) : ?>
<?= $this->partial('vertical') ?>
<?php endif ?>
</div>
@ -83,8 +83,8 @@
<?= $this->t('.ambiguous') ?><?php array_map(function($x){echo linkTo(h($x), 'wiki#show', array('title' => $x));}, $ambiguous_tags) ?>
</div>
<?php endif ?>
<?php if (CONFIG()->can_see_ads(current_user())) : ?>
<?= CONFIG()->ad_code_index_bottom ?>
<?php if (CONFIG()->can_show_ad('post#index-top', current_user())) : ?>
<?= $this->partial('horizontal') ?>
<?php endif ?>
<div id="quick-edit" style="display: none;" class="top-corner-float">
@ -99,6 +99,9 @@
<?= $this->partial("hover") ?>
<?= $this->partial('posts', array('posts' => $this->posts)) ?>
<?php if (CONFIG()->can_show_ad('post#index-bottom', current_user())) : ?>
<?= $this->partial('horizontal') ?>
<?php endif ?>
<div id="paginator">
<?= $this->willPaginate($this->posts) ?>
</div>

View File

@ -20,18 +20,23 @@
<?= $this->partial('post/show_partials/options_panel') ?>
<?= $this->partial('post/show_partials/related_posts_panel') ?>
<br />
<?php if (CONFIG()->can_see_ads(current_user())) : ?>
<?php if (CONFIG()->can_show_ad('post#show-sidebar', current_user())) : ?>
<?= $this->partial('vertical') ?>
<?php endif ?>
</div>
<div class="content" id="right-col">
<?php if (CONFIG()->can_see_ads(current_user())) : ?>
<?php if (CONFIG()->can_show_ad('post#show-top', current_user())) : ?>
<?= $this->partial('horizontal') ?>
<?php endif ?>
<?= $this->partial('post/show_partials/image') ?>
<?= $this->partial('post/show_partials/image_footer', ['post_id' => $this->post->id]) ?>
<?= $this->partial('post/show_partials/edit') ?>
<?= $this->partial('post/show_partials/comments') ?>
<?php if (CONFIG()->can_show_ad('post#show-bottom', current_user())) : ?>
<?= $this->partial('horizontal') ?>
<?php endif ?>
</div>
<?= $this->contentFor('post_cookie_javascripts', function() { ?>

View File

@ -435,6 +435,21 @@ abstract class DefaultConfig
'similarity' => 90
];
/**
* Active advertisements spots.
* Remove one of them from the list and the ads in that
* page/place won't show.
* The ones commented are new, extra spots.
*/
public $active_ad_spots = [
'post#index-sidebar',
'post#show-sidebar',
'post#show-top',
'post#index-top',
// 'post#index-bottom',
// 'post#show-bottom'
];
# Timeout for Danbooru::http_get_streaming() (used by batch upload, similar images, etc.).
# If this limit is reached, the file that's being downloaded will be invalid.
# Set to 0 to wait indefinitely.
@ -452,6 +467,18 @@ abstract class DefaultConfig
return $this->enable_asynchronous_tasks && in_array($name, $this->active_job_tasks);
}
/**
* Does a couple of checks:
* - If $user can see ads.
* - If $spot is active.
*
* @return bool
*/
public function can_show_ad($spot, $user)
{
return in_array($spot, $this->active_ad_spots) && $this->can_see_ads($user);
}
/**
* Parses image filename into tags.
* Must return an array with tags or an empty value.