XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
page.view.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class pageView extends page
9 {
10  var $module_srl = 0;
11  var $list_count = 20;
12  var $page_count = 10;
14  var $interval;
15  var $path;
16 
20  function init()
21  {
22  // Get a template path (page in the administrative template tpl putting together)
23  $this->setTemplatePath($this->module_path.'tpl');
24 
25  switch($this->module_info->page_type)
26  {
27  case 'WIDGET' :
28  {
29  $this->cache_file = sprintf("%sfiles/cache/page/%d.%s.%s.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType(), Context::getSslStatus());
30  $this->interval = (int)($this->module_info->page_caching_interval);
31  break;
32  }
33  case 'OUTSIDE' :
34  {
35  $this->cache_file = sprintf("%sfiles/cache/opage/%d.%s.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getSslStatus());
36  $this->interval = (int)($this->module_info->page_caching_interval);
37  $this->path = $this->module_info->path;
38  break;
39  }
40  }
41  }
42 
46  function dispPageIndex()
47  {
48  // Variables used in the template Context:: set()
49  if($this->module_srl) Context::set('module_srl',$this->module_srl);
50 
51  $page_type_name = strtolower($this->module_info->page_type);
52  $method = '_get' . ucfirst($page_type_name) . 'Content';
53  if(method_exists($this, $method)) $page_content = $this->{$method}();
54  else return new BaseObject(-1, sprintf('%s method is not exists', $method));
55 
56  Context::set('module_info', $this->module_info);
57  Context::set('page_content', $page_content);
58 
59  $this->setTemplateFile('content');
60  }
61 
62  function _getWidgetContent()
63  {
64  if($this->interval>0)
65  {
66  if(!file_exists($this->cache_file)) $mtime = 0;
67  else $mtime = filemtime($this->cache_file);
68 
69  if($mtime + $this->interval*60 > $_SERVER['REQUEST_TIME'])
70  {
71  $page_content = FileHandler::readFile($this->cache_file);
72  $page_content = preg_replace('@<\!--#Meta:@', '<!--Meta:', $page_content);
73  }
74  else
75  {
76  $oWidgetController = getController('widget');
77  $page_content = $oWidgetController->transWidgetCode($this->module_info->content);
78  FileHandler::writeFile($this->cache_file, $page_content);
79  }
80  }
81  else
82  {
83  if(file_exists($this->cache_file)) FileHandler::removeFile($this->cache_file);
84  $page_content = $this->module_info->content;
85  }
86  return $page_content;
87  }
88 
89  function _getArticleContent()
90  {
91  $oTemplate = &TemplateHandler::getInstance();
92 
93  $oDocumentModel = getModel('document');
94  $oDocument = $oDocumentModel->getDocument(0, true);
95 
96  if($this->module_info->document_srl)
97  {
98  $document_srl = $this->module_info->document_srl;
99  $oDocument->setDocument($document_srl);
100  Context::set('document_srl', $document_srl);
101  }
102  Context::set('oDocument', $oDocument);
103 
104  if ($this->module_info->skin)
105  {
106  $templatePath = (sprintf($this->module_path.'skins/%s', $this->module_info->skin));
107  }
108  else
109  {
110  $templatePath = ($this->module_path.'skins/default');
111  }
112 
113  $page_content = $oTemplate->compile($templatePath, 'content');
114 
115  return $page_content;
116  }
117 
119  {
120  // check if it is http or internal file
121  if($this->path)
122  {
123  if(preg_match("/^([a-z]+):\/\//i",$this->path)) $content = $this->getHtmlPage($this->path, $this->interval, $this->cache_file);
124  else $content = $this->executeFile($this->path, $this->interval, $this->cache_file);
125  }
126 
127  return $content;
128  }
129 
133  function getHtmlPage($path, $caching_interval, $cache_file)
134  {
135  // Verify cache
136  if($caching_interval > 0 && file_exists($cache_file) && filemtime($cache_file) + $caching_interval*60 > $_SERVER['REQUEST_TIME'])
137  {
139  }
140  else
141  {
144  }
145  // Create opage controller
146  $oPageController = getController('page');
147  // change url of image, css, javascript and so on if the page is from external server
148  $content = $oPageController->replaceSrc($content, $path);
149 
150  // Change the document to utf-8 format
151  $buff = new stdClass;
152  $buff->content = $content;
153  $buff = Context::convertEncoding($buff);
154  $content = $buff->content;
155  // Extract a title
156  $title = $oPageController->getTitle($content);
157  if($title) Context::setBrowserTitle($title);
158  // Extract header script
159  $head_script = $oPageController->getHeadScript($content);
160  if($head_script) Context::addHtmlHeader($head_script);
161  // Extract content from the body
162  $body_script = $oPageController->getBodyScript($content);
163  if(!$body_script) $body_script = $content;
164 
165  return $content;
166  }
167 
171  function executeFile($target_file, $caching_interval, $cache_file)
172  {
173  // Cancel if the file doesn't exist
174  if(!file_exists(FileHandler::getRealPath($target_file))) return;
175 
176  // Get a path and filename
177  $tmp_path = explode('/',$cache_file);
178  $filename = $tmp_path[count($tmp_path)-1];
179  $filepath = preg_replace('/'.$filename."$/i","",$cache_file);
181 
182  $level = ob_get_level();
183  // Verify cache
184  if($caching_interval <1 || !file_exists($cache_file) || filemtime($cache_file) + $caching_interval*60 <= $_SERVER['REQUEST_TIME'] || filemtime($cache_file)<filemtime($target_file))
185  {
187 
188  // Read a target file and get content
189  ob_start();
190  include(FileHandler::getRealPath($target_file));
191  $content = ob_get_clean();
192  // Replace relative path to the absolute path
193  $this->path = str_replace('\\', '/', realpath(dirname($target_file))) . '/';
194  $content = preg_replace_callback('/(target=|src=|href=|url\()("|\')?([^"\'\)]+)("|\'\))?/is',array($this,'_replacePath'),$content);
195  $content = preg_replace_callback('/(<!--%import\()(\")([^"]+)(\")/is',array($this,'_replacePath'),$content);
196 
198  // Include and then Return the result
199  if(!file_exists($cache_file)) return;
200  // Attempt to compile
201  $oTemplate = &TemplateHandler::getInstance();
202  $script = $oTemplate->compileDirect($filepath, $filename);
203 
205  }
206 
207  $__Context = &$GLOBALS['__Context__'];
208  $__Context->tpl_path = $filepath;
209 
210  ob_start();
211  include($cache_file);
212 
213  $contents = '';
214  while (ob_get_level() - $level > 0) {
215  $contents .= ob_get_contents();
216  ob_end_clean();
217  }
218  return $contents;
219  }
220 
221  function _replacePath($matches)
222  {
223  $val = trim($matches[3]);
224  // Pass if the path is external or starts with /, #, { characters
225  // /=absolute path, #=hash in a page, {=Template syntax
226  if(strpos($val, '.') === FALSE || preg_match('@^((?:http|https|ftp|telnet|mms)://|(?:mailto|javascript):|[/#{])@i',$val))
227  {
228  return $matches[0];
229  // In case of .. , get a path
230  }
231  else if(strncasecmp('..', $val, 2) === 0)
232  {
233  $p = Context::pathToUrl($this->path);
234  return sprintf("%s%s%s%s",$matches[1],$matches[2],$p.$val,$matches[4]);
235  }
236 
237  if(strncasecmp('..', $val, 2) === 0) $val = substr($val,2);
238  $p = Context::pathToUrl($this->path);
239  $path = sprintf("%s%s%s%s",$matches[1],$matches[2],$p.$val,$matches[4]);
240 
241  return $path;
242  }
243 }
244 /* End of file page.view.php */
245 /* Location: ./modules/page/page.view.php */
setTemplateFile($filename)
getController($module_name)
Definition: func.inc.php:90
init()
Initialization.
Definition: page.view.php:20
_getOutsideContent()
Definition: page.view.php:118
removeFile($filename)
executeFile($target_file, $caching_interval, $cache_file)
Create a cache file in order to include if it is an internal file.
Definition: page.view.php:171
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
addHtmlHeader($header)
high class of the module page
Definition: page.class.php:8
_getWidgetContent()
Definition: page.view.php:62
set($key, $val, $set_to_get_vars=0)
writeFile($filename, $buff, $mode="w")
setBrowserTitle($site_title)
page view class of the module
Definition: page.view.php:8
pathToUrl($path)
getRemoteFile($url, $target_filename, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
$document_srl
Definition: ko.install.php:279
getHtmlPage($path, $caching_interval, $cache_file)
Save the file and return if a file is requested by http.
Definition: page.view.php:133
_replacePath($matches)
Definition: page.view.php:221
$oDocumentModel
Definition: ko.install.php:259
getRealPath($source)
const _XE_PATH_
Definition: config.inc.php:49
readFile($filename)
convertEncoding($source_obj)
$obj module_srl
Definition: ko.install.php:270
dispPageIndex()
General request output.
Definition: page.view.php:46
getModel($module_name)
Definition: func.inc.php:145
_getArticleContent()
Definition: page.view.php:89