示例#1
0
 public function postProcess($buffer)
 {
     $r = '';
     if (isset($this->metatags['seo_title'])) {
         $r = "<title>" . strip_tags($this->metatags['seo_title']) . "</title>" . PHP_EOL;
     }
     if (isset($this->metatags['seo_description'])) {
         $r .= '<meta name="description" content="' . strip_tags($this->metatags['seo_description']) . '" />' . PHP_EOL;
     }
     if (isset($this->metatags['seo_keywords'])) {
         $r .= '<meta name="keywords" content="' . strip_tags($this->metatags['seo_keywords']) . '" />' . PHP_EOL;
     }
     $r .= $this->getAssetsCode();
     if (!preg_match("~<head(\\s[^>]*?|)>~i", $buffer)) {
         if (preg_match("~<html[^>]*?>~i", $buffer)) {
             $buffer = preg_replace("~<html[^>]*?>~i", '$0<head> </head>', $buffer);
         } else {
             $buffer = '<html><head> </head>' . $buffer . '</html>';
         }
     }
     //$buffer = preg_replace("~<head(\s[^>]*?|)>~", '$0'.$r, $buffer);
     $buffer = preg_replace("~<title>.+</title>~i", '', $buffer);
     $buffer = preg_replace("~</head\\s*?>~i", $r . '$0', $buffer);
     if (count($this->after_body)) {
         $after_body = $this->after_body;
         $buffer = preg_replace_callback('~<body[^>]*?>~i', function ($body) use($after_body) {
             return $body[0] . join("\r\n", $after_body);
         }, $buffer);
     }
     $buffer = str_replace("<body", "<body data-fx_page_id='" . fx::env('page_id') . "'", $buffer);
     if (fx::isAdmin()) {
         $js = '<script type="text/javascript">' . PHP_EOL;
         if ($js_text = $this->getJsText()) {
             $js .= join(PHP_EOL, $js_text) . PHP_EOL;
         }
         $js .= '</script>' . PHP_EOL;
         $buffer = str_replace('</body>', $js . '</body>', $buffer);
     }
     return $buffer;
 }