XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
page.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class pageController extends page
9 {
10  var $target_path = '';
11 
15  function init() { }
16 
20  function getTitle($content)
21  {
22  preg_match('!<title([^>]*)>(.*?)<\/title>!is', $content, $buff);
23  return trim($buff[2]);
24  }
25 
29  function getHeadScript($content)
30  {
31  // remove the title tag
32  $content = preg_replace('!<title([^>]*)>(.*?)<\/title>!is','', $content);
33  // Remove meta tags
34  $content = preg_replace('!<(\/){0,1}meta([^>]*)>!is','', $content);
35  // Extract information such as <link, <style, <script and so on
36  preg_match_all('!<link([^>]*)>!is', $content, $link_buff);
37  for($i=0;$i<count($link_buff[0]);$i++)
38  {
39  $tmp_str = trim($link_buff[0][$i]);
40  if(!$tmp_str) continue;
41  $header_script .= $tmp_str."\n";
42  }
43 
44  preg_match_all('!<(style|script)(.*?)<\/(style|script)>!is', $content, $script_buff);
45  for($i=0;$i<count($script_buff[0]);$i++)
46  {
47  $tmp_str = trim($script_buff[0][$i]);
48  if(!$tmp_str) continue;
49  $header_script .= $tmp_str."\n";
50  }
51 
52  return $header_script;
53  }
54 
58  function getBodyScript($content)
59  {
60  // Extract content
61  preg_match('!<body([^>]*)>(.*?)<\/body>!is', $content, $body_buff);
62  $body_script = $body_buff[2];
63  // Remove link, style, script, etc.
64  $body_script = preg_replace('!<link([^>]*)>!is', '', $body_script);
65  $body_script = preg_replace('!<(style|script)(.*?)<\/(style|script)>!is', '', $body_script);
66  return $body_script;
67  }
68 
72  function replaceSrc($content, $path)
73  {
74  $url_info = parse_url($path);
75  $host = sprintf("%s://%s%s",$url_info['scheme'],$url_info['host'],$url_info['port']?':'.$url_info['port']:'');
76  $this->host = $host.'/';
77  $path = $url_info['path'];
78  if(substr($path,-1)=='/') $path = substr($path,-1);
79  $t = explode('/',$path);
80  $_t = array();
81  for($i=0,$c=count($t)-1;$i<$c;$i++)
82  {
83  $v = trim($t[$i]);
84  if(!$v) continue;
85  $_t[] = $v;
86  }
87  $path = $host.'/'.implode('/',$_t);
88  if(substr($path,-1)!='/') $path .= '/';
89  $this->path = $path;
90  $content = preg_replace_callback('/(src=|href=|url\()("|\')?([^"\'\)]+)("|\'\))?/is',array($this,'_replacePath'),$content);
91 
92  return $content;
93  }
94 
95  function _replacePath($matches)
96  {
97  $val = trim($matches[3]);
98  if(preg_match('/^(http|https|ftp|telnet|mms|mailto)/i',$val)) return $matches[0];
99  if(substr($val,0,2)=='./')
100  {
101  $path = $this->path.substr($val,2);
102  }
103  elseif(substr($val,0,1)=='/')
104  {
105  $path = $this->host.substr($val,1);
106  }
107  else
108  {
109  $path = $this->path.$val;
110  }
111  return sprintf("%s%s%s%s", $matches[1], $matches[2], $path, $matches[4]);
112  }
113 }
114 /* End of file page.controller.php */
115 /* Location: ./modules/page/page.controller.php */
high class of the module page
Definition: page.class.php:8
replaceSrc($content, $path)
Change the value of src, href in the content.
getTitle($content)
Extract a title.
getHeadScript($content)
Extract header script.
getBodyScript($content)
Extract the contents of the body.
init()
Initialization.
_replacePath($matches)