campaign = $campaign; $this->campaign->loadSettings(); } /** * Returns built template. * * @param string * @param boolean * * @return string */ public function build($content = '', $withConfig = true) { $config = $this->getClientConfig(); $json = json_encode($config) ; $legacyClass = $this->legacyCampaignClass($this->campaign->getId()); return "
{$content}
"; } public function template() { return ($this->campaign->headlinePosition == C::HEADLINE_POSITION_ABOVE_TIMER ? $this->headline() : '') . '
' . ($this->campaign->headlinePosition == C::HEADLINE_POSITION_BELOW_TIMER ? $this->headline() : ''); } /** * Returns common client config. * * @return array */ private function commonClientConfig() { return [ 'id' => $this->campaign->getId(), 'actions' => $this->campaign->actions, 'template' => $this->timer(), ]; } private function evergreenClientConfig() { $evergreenCompaign = new EvergreenCampaign( $this->campaign->getId(), new CookieDetection(), new IPDetection() ); return [ 'isRegular' => false, 'duration' => $this->campaign->getDurationInSeconds(), 'reset' => $evergreenCompaign->reseting(), 'restart' => $this->campaign->getRestart(), 'endDate' => $evergreenCompaign->getEndDate(), 'cookieName' => $evergreenCompaign->cookieName(), ]; } /** * Returns regular config. * * @return array */ private function regularClientConfig() { return [ 'isRegular' => true, 'endDate' => date( 'Y/m/d H:i:s', strtotime($this->campaign->getEndDatetime())), ]; } /** * Returns client config for the compaign. * * @return array|null */ public function getClientConfig() { if ($this->campaign->isEvergreen()) { return array_merge($this->commonClientConfig(), $this->evergreenClientConfig()); } else { return array_merge($this->commonClientConfig(), $this->regularClientConfig()); } } /** * Returns timer. * * @return string */ public function timer() { $blocks = array_filter([ $this->daysBlock(), $this->hoursBlock(), $this->minutesBlock(), $this->secondsBlock(), ]); return implode($this->separator(), $blocks); } /** * Returns separator. * * @return string */ public function separator() { return $this->campaign->blockSeparatorVisibility === C::YES ? '
:
' : ''; } /** * Returns days block. * * @return string */ public function daysBlock() { return $this->campaign->daysVisibility === C::YES ? $this->block("%D", $this->campaign->labels['days']) : ''; } /** * Returns hours block. * * @return string */ public function hoursBlock() { return $this->campaign->hoursVisibility === C::YES ? $this->block("%H", $this->campaign->labels['hours']) : ''; } /** * Returns minutes block. * * @return string */ public function minutesBlock() { return $this->campaign->minutesVisibility === C::YES ? $this->block("%M", $this->campaign->labels['minutes']) : ''; } /** * Returns seconds block. * * @return string */ public function secondsBlock() { return $this->campaign->secondsVisibility === C::YES ? $this->block("%S", $this->campaign->labels['seconds']) : ''; } /** * Returns block. * * @param $digitFormat * @param $label * * @return string */ public function block($digitFormat, $label) { return '
' . $this->digit($digitFormat) . $this->label($label) . '
'; } public function digit($format) { return '
' . $format . '
'; } public function label($text) { if ($this->campaign->labelVisibility === "no") { return ''; } return '
' . __($text, 'hurrytimer') . '
'; } public function headline() { return $this->campaign->headlineVisibility === C::YES ? '
' . __($this->campaign->headline, 'hurrytimer') . '
' : ''; } }