forked from hdrlab/silverstripe-AdManager
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
helpfulrobot
committed
Dec 24, 2015
1 parent
64fa7d5
commit b9a51c2
Showing
9 changed files
with
665 additions
and
657 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,55 +7,57 @@ | |
* @author Marcus Nyeholt <[email protected]> | ||
* @license BSD http://silverstripe.org/BSD-license | ||
*/ | ||
class UniadsAdmin extends ModelAdmin { | ||
|
||
private static $managed_models = array( | ||
'UniadsObject', | ||
'UniadsCampaign', | ||
'UniadsClient', | ||
'UniadsZone', | ||
); | ||
|
||
private static $allowed_actions = array( | ||
'preview' | ||
); | ||
|
||
private static $url_rule = '/$ModelClass/$Action/$ID/$OtherID'; | ||
|
||
private static $url_segment = 'advrt'; | ||
private static $menu_title = 'Ads'; | ||
private static $menu_icon = ''; | ||
|
||
|
||
public function __construct() { | ||
$this->config()->menu_icon = ADS_MODULE_DIR . '/images/icon-advrt.png'; | ||
parent::__construct(); | ||
} | ||
|
||
/** Preview an advertisement. | ||
*/ | ||
public function preview(SS_HTTPRequest $request) { | ||
$request->shift(); | ||
$adID = (int) $request->param('ID'); | ||
$ad = UniadsObject::get()->byID($adID); | ||
|
||
if (!$ad) { | ||
Controller::curr()->httpError(404); | ||
return; | ||
} | ||
|
||
// No impression and click tracking for previews | ||
$conf = UniadsObject::config(); | ||
$conf->use_js_tracking = false; | ||
$conf->record_impressions = false; | ||
$conf->record_impressions_stats = false; | ||
|
||
// Block stylesheets and JS that are not required (using our own template) | ||
Requirements::clear(); | ||
|
||
$template = new SSViewer('UniadsPreview'); | ||
|
||
return $template->Process($ad); | ||
} | ||
|
||
class UniadsAdmin extends ModelAdmin | ||
{ | ||
|
||
private static $managed_models = array( | ||
'UniadsObject', | ||
'UniadsCampaign', | ||
'UniadsClient', | ||
'UniadsZone', | ||
); | ||
|
||
private static $allowed_actions = array( | ||
'preview' | ||
); | ||
|
||
private static $url_rule = '/$ModelClass/$Action/$ID/$OtherID'; | ||
|
||
private static $url_segment = 'advrt'; | ||
private static $menu_title = 'Ads'; | ||
private static $menu_icon = ''; | ||
|
||
|
||
public function __construct() | ||
{ | ||
$this->config()->menu_icon = ADS_MODULE_DIR . '/images/icon-advrt.png'; | ||
parent::__construct(); | ||
} | ||
|
||
/** Preview an advertisement. | ||
*/ | ||
public function preview(SS_HTTPRequest $request) | ||
{ | ||
$request->shift(); | ||
$adID = (int) $request->param('ID'); | ||
$ad = UniadsObject::get()->byID($adID); | ||
|
||
if (!$ad) { | ||
Controller::curr()->httpError(404); | ||
return; | ||
} | ||
|
||
// No impression and click tracking for previews | ||
$conf = UniadsObject::config(); | ||
$conf->use_js_tracking = false; | ||
$conf->record_impressions = false; | ||
$conf->record_impressions_stats = false; | ||
|
||
// Block stylesheets and JS that are not required (using our own template) | ||
Requirements::clear(); | ||
|
||
$template = new SSViewer('UniadsPreview'); | ||
|
||
return $template->Process($ad); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,44 +7,47 @@ | |
* @author Marcus Nyeholt <[email protected]> | ||
* @license BSD http://silverstripe.org/BSD-license | ||
*/ | ||
class UniadsController extends Controller { | ||
class UniadsController extends Controller | ||
{ | ||
|
||
private static $allowed_actions = array( | ||
'clk', | ||
'go', | ||
); | ||
private static $allowed_actions = array( | ||
'clk', | ||
'go', | ||
); | ||
|
||
public function clk() { | ||
$this->GetAdAndLogClick($this->request->requestVar('id')); | ||
} | ||
public function clk() | ||
{ | ||
$this->GetAdAndLogClick($this->request->requestVar('id')); | ||
} | ||
|
||
public function go() { | ||
$ad = $this->GetAdAndLogClick($this->request->param('ID')); | ||
if ($ad) { | ||
$target = $ad->getTarget(); | ||
$this->redirect($target ? $target : Director::baseURL()); | ||
} | ||
} | ||
|
||
private function GetAdAndLogClick($id) { | ||
$id = (int) $id; | ||
if ($id) { | ||
$ad = UniadsObject::get()->byID($id); | ||
if ($ad && $ad->exists()) { | ||
$conf = UniadsObject::config(); | ||
if ($conf->record_clicks) { | ||
$ad->Clicks++; | ||
$ad->write(); | ||
} | ||
if ($conf->record_clicks_stats) { | ||
$clk = new UniadsClick; | ||
$clk->AdID = $ad->ID; | ||
$clk->write(); | ||
} | ||
return $ad; | ||
} | ||
} | ||
return null; | ||
} | ||
public function go() | ||
{ | ||
$ad = $this->GetAdAndLogClick($this->request->param('ID')); | ||
if ($ad) { | ||
$target = $ad->getTarget(); | ||
$this->redirect($target ? $target : Director::baseURL()); | ||
} | ||
} | ||
|
||
private function GetAdAndLogClick($id) | ||
{ | ||
$id = (int) $id; | ||
if ($id) { | ||
$ad = UniadsObject::get()->byID($id); | ||
if ($ad && $ad->exists()) { | ||
$conf = UniadsObject::config(); | ||
if ($conf->record_clicks) { | ||
$ad->Clicks++; | ||
$ad->write(); | ||
} | ||
if ($conf->record_clicks_stats) { | ||
$clk = new UniadsClick; | ||
$clk->AdID = $ad->ID; | ||
$clk->write(); | ||
} | ||
return $ad; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,53 +7,54 @@ | |
* @author Marcus Nyeholt <[email protected]> | ||
* @license BSD http://silverstripe.org/BSD-license | ||
*/ | ||
class UniadsCampaign extends DataObject { | ||
|
||
private static $db = array( | ||
'Title' => 'Varchar', | ||
'Starts' => 'Date', | ||
'Expires' => 'Date', | ||
'Active' => 'Boolean', | ||
); | ||
|
||
private static $summary_fields = array( | ||
'Title' => 'Title', | ||
'Starts' => 'Starts', | ||
'Expires' => 'Expires', | ||
'Active' => 'Active', | ||
); | ||
|
||
private static $has_many = array( | ||
'Ads' => 'UniadsObject', | ||
); | ||
|
||
private static $has_one = array( | ||
'Client' => 'UniadsClient', | ||
); | ||
|
||
public function getCMSFields() { | ||
$fields = parent::getCMSFields(); | ||
|
||
$Starts = $fields->fieldByName('Root.Main.Starts'); | ||
$Starts->setConfig('showcalendar', true); | ||
$Starts->setConfig('dateformat', i18n::get_date_format()); | ||
$Starts->setConfig('datavalueformat', 'yyyy-MM-dd'); | ||
|
||
$Expires = $fields->fieldByName('Root.Main.Expires'); | ||
$Expires->setConfig('showcalendar', true); | ||
$Expires->setConfig('dateformat', i18n::get_date_format()); | ||
$Expires->setConfig('datavalueformat', 'yyyy-MM-dd'); | ||
$Expires->setConfig('min', date('Y-m-d', strtotime($this->Starts ? $this->Starts : '+1 days'))); | ||
|
||
$fields->changeFieldOrder(array( | ||
'Title', | ||
'ClientID', | ||
'Starts', | ||
'Expires', | ||
'Active', | ||
)); | ||
|
||
return $fields; | ||
} | ||
|
||
class UniadsCampaign extends DataObject | ||
{ | ||
|
||
private static $db = array( | ||
'Title' => 'Varchar', | ||
'Starts' => 'Date', | ||
'Expires' => 'Date', | ||
'Active' => 'Boolean', | ||
); | ||
|
||
private static $summary_fields = array( | ||
'Title' => 'Title', | ||
'Starts' => 'Starts', | ||
'Expires' => 'Expires', | ||
'Active' => 'Active', | ||
); | ||
|
||
private static $has_many = array( | ||
'Ads' => 'UniadsObject', | ||
); | ||
|
||
private static $has_one = array( | ||
'Client' => 'UniadsClient', | ||
); | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
$Starts = $fields->fieldByName('Root.Main.Starts'); | ||
$Starts->setConfig('showcalendar', true); | ||
$Starts->setConfig('dateformat', i18n::get_date_format()); | ||
$Starts->setConfig('datavalueformat', 'yyyy-MM-dd'); | ||
|
||
$Expires = $fields->fieldByName('Root.Main.Expires'); | ||
$Expires->setConfig('showcalendar', true); | ||
$Expires->setConfig('dateformat', i18n::get_date_format()); | ||
$Expires->setConfig('datavalueformat', 'yyyy-MM-dd'); | ||
$Expires->setConfig('min', date('Y-m-d', strtotime($this->Starts ? $this->Starts : '+1 days'))); | ||
|
||
$fields->changeFieldOrder(array( | ||
'Title', | ||
'ClientID', | ||
'Starts', | ||
'Expires', | ||
'Active', | ||
)); | ||
|
||
return $fields; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
* @author Marcus Nyeholt <[email protected]> | ||
* @license BSD http://silverstripe.org/BSD-license | ||
*/ | ||
class UniadsClick extends UniadsImpression { | ||
|
||
class UniadsClick extends UniadsImpression | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,16 @@ | |
* @author Marcus Nyeholt <[email protected]> | ||
* @license BSD http://silverstripe.org/BSD-license | ||
*/ | ||
class UniadsClient extends DataObject { | ||
class UniadsClient extends DataObject | ||
{ | ||
|
||
private static $db = array( | ||
'Title' => 'Varchar(128)', | ||
'ContactEmail' => 'Text', | ||
); | ||
|
||
private static $summary_fields = array( | ||
'Title', | ||
'ContactEmail', | ||
); | ||
private static $db = array( | ||
'Title' => 'Varchar(128)', | ||
'ContactEmail' => 'Text', | ||
); | ||
|
||
private static $summary_fields = array( | ||
'Title', | ||
'ContactEmail', | ||
); | ||
} |
Oops, something went wrong.