Created
March 9, 2012 14:50
-
-
Save tmaslen/2006826 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| class BBC_News_Core_Controller_BaseController extends BBC_Controller_Action | |
| { | |
| protected $container; | |
| /** | |
| * Primarily intended for extending the constructor. | |
| * Initializing resources used in the controller | |
| */ | |
| public function init() | |
| { | |
| $this->container = $this->getInvokeArg('container'); | |
| parent::init(); | |
| } | |
| /** | |
| * The preDispatch() method can also be used to set object or environmental | |
| * (e.g., view, action helper, etc.) state, but its primary purpose is to | |
| * make decisions about whether or not the requested action should be dispatched. | |
| */ | |
| public function preDispatch() | |
| { | |
| $this->blq->setMobile(true); | |
| $this->view->audience = $this->getRequest()->getParam("audience"); | |
| if($this->showAdvert()) { | |
| if(PAL_ENV === 'sandbox') { | |
| $this->blq->setShowAdverts(true); | |
| } | |
| $this->blq->setAdsEnabled(true); | |
| } | |
| $staticVersion = $this->getRequest()->getServer('PAL_NEWS_STATIC_VERSION', 'dev'); | |
| $this->view->staticPrefix = PAL_STATIC_HOST . '/news/' . $staticVersion; | |
| $this->view->isRequestViaVarnish = $this->getRequest()->getParam('viaVarnish'); | |
| $this->view->isRequestViaXmlHttp = $this->getRequest()->getParam('viaXmlHttp'); | |
| $this->view->forceAdvertOn = $this->container['test_context']->isAdvertForced(); | |
| $compiledJsHeader = $this->getRequest()->getHeader("X-Compiled-Js"); | |
| $this->view->compiledJs = ($compiledJsHeader != null) | |
| ? $compiledJsHeader : $this->container['config']->tabloid->js->compiled; | |
| } | |
| public function postDispatch() | |
| { | |
| if($this->showAdvert()) { | |
| $this->applyAdvertMetaData($this->asset->getAdvertMeta()); | |
| } | |
| } | |
| protected function showAdvert() { | |
| if ( | |
| ($this->getRequest()->getHeader("X-IP-IS-ADVERTISED-COMBINED") == 'yes') || | |
| ( | |
| ($this->getRequest()->getHeader("X-Force-Adverts") == 'yes') && | |
| (PAL_ENV != 'live') | |
| ) | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| protected function applyAdvertMetaData($advertMeta) | |
| { | |
| $bbcdotcom = $this->blq->addModule('bbcdotcom'); | |
| if($advertMeta['editorAdFlag'] !== true) { | |
| $this->blq->setAdsEnabled(false); | |
| } | |
| else { | |
| $bbcdotcom->setMetaData($advertMeta); | |
| $bbcdotcom->setMobileMode('feature'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment