Example #1
0
 /**
  * @param string $code
  *
  * @return null|string
  */
 public function displayAd($code)
 {
     $scriptName = $this->getScriptName();
     $ad = $this->findAdByCode($code);
     $adClass = $ad->getClass();
     $adAd = $ad->getAd();
     $adPlaceholder = $ad->getPlaceholder();
     $parts = explode('/', $scriptName);
     $placeholderName = (string) $parts[1];
     if (empty($placeholderName)) {
         $placeholderName = 'placeholder';
     }
     $hash = md5($code);
     if ($this->isPhpAllowed()) {
         preg_match_all('#(<\\s*\\?php)(.*?)(\\?\\s*>)#msi', $adAd, $r);
         foreach ($r[2] as $i => $php) {
             ob_start();
             eval($php);
             $data = ob_get_contents();
             ob_end_clean();
             $adAd = str_replace($r[0][$i], $data, $adAd);
         }
     }
     if (null !== $adPlaceholder) {
         $placeholder = 'http://' . $this->getHostname() . '/' . $scriptName . '/' . md5($code);
     } else {
         $placeholder = 'http://' . $this->getHostname() . '/' . $placeholderName . '/' . $ad->getWidth() . '/' . $ad->getHeight();
     }
     return $this->output->getAdHtml(array('id' => $hash, 'class' => $adClass, 'name' => $hash, 'placeholder' => $placeholder, 'html' => $adAd));
 }