12e3a57053
added position to advertisements. with it, one can choose to either show an horizontal add only at top, bottom or both. removed can_see_ads check from AdvertisementsHelper::print_advertisement() because it's already checked before calling it. horizontal-bottom ads in post#index are centered. removed "Reset hit count" checkbox in ads#edit. Width and Height in ads form are now "number" fields. Width and Height must now be set also for "Html" ads. made ads#show a little nicer. ads#create and ads#update redirect to ads#index if success. some other related changes. made ad#show a little nicer
30 lines
1.0 KiB
PHP
Executable File
30 lines
1.0 KiB
PHP
Executable File
<?php
|
|
class AdvertisementsHelper extends Rails\ActionView\Helper
|
|
{
|
|
public function print_advertisement($ad_type, $position = null, $center = false)
|
|
{
|
|
$ad = Advertisement::random($ad_type, substr($position, 0, 1));
|
|
|
|
if ($ad) {
|
|
if ($ad->html) {
|
|
$contents = $ad->html;
|
|
} else {
|
|
$contents = $this->linkTo(
|
|
$this->imageTag(
|
|
$ad->image_url,
|
|
['alt' => "Advertisement", 'width' => $ad->width, 'height' => $ad->height]
|
|
),
|
|
$this->redirectAdvertisementPath($ad),
|
|
['target' => '_blank']
|
|
);
|
|
}
|
|
|
|
if ($center) {
|
|
return $this->contentTag('div', $contents, ['style' => 'margin:0 auto;width:' . $ad->width . 'px;height:' . $ad->height . 'px;']);
|
|
} else {
|
|
return $contents;
|
|
}
|
|
}
|
|
}
|
|
}
|