21 $this->config = $config;
32 if (empty($get_vars[
'request'])) {
35 $request = $this->parseRequestVar($get_vars[
'request']);
43 $this->sendContentType(
$view);
46 $this->setupSimplecache();
48 if (!$this->config->simplecache_enabled) {
60 if (isset($server_vars[
'HTTP_IF_NONE_MATCH'])) {
62 $if_none_match = str_replace(
'-gzip',
'', trim($server_vars[
'HTTP_IF_NONE_MATCH']));
63 if ($if_none_match === $etag) {
64 header(
"HTTP/1.1 304 Not Modified");
70 $filename = $this->config->dataroot .
'views_simplecache/' . md5(
"$viewtype|$view");
72 $this->sendCacheHeaders($etag);
84 $cache_timestamp = (int)
_elgg_services()->config->get(
'lastcache');
86 if ($cache_timestamp ==
$ts) {
87 $this->sendCacheHeaders($etag);
91 $dir_name = $this->config->dataroot .
'views_simplecache/';
92 if (!is_dir($dir_name)) {
93 mkdir($dir_name, 0700);
114 if (
false !== strpos($request_var,
'..')) {
118 if (preg_match(
'#[^a-zA-Z0-9/\.\-_]#', $request_var)) {
125 if (!preg_match(
'#^/?([0-9]+)/([^/]+)/(.+)$#', $request_var, $matches)) {
131 'viewtype' => $matches[2],
132 'view' => $matches[3],
142 if (!empty($this->config->dataroot) && isset($this->config->simplecache_enabled)) {
146 $db_config =
new Database\Config($this->config);
150 $rows = $db->getData(
" 151 SELECT `name`, `value` 152 FROM {$db->getTablePrefix()}datalists 153 WHERE `name` IN ('dataroot', 'simplecache_enabled') 156 $this->send403(
'Cache error: unable to get the data root');
159 if (0 === strpos($e->getMessage(),
"Elgg couldn't connect")) {
160 $this->send403(
'Cache error: unable to connect to database server');
162 $this->send403(
'Cache error: unable to connect to Elgg database');
168 $this->config->{$row->name} = $row->value;
171 if (empty($this->config->dataroot)) {
172 $this->send403(
'Cache error: unable to get the data root');
183 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s \G\M\T', strtotime(
"+6 months")),
true);
184 header(
"Pragma: public",
true);
185 header(
"Cache-Control: public",
true);
196 $segments = explode(
'/',
$view, 2);
197 switch ($segments[0]) {
199 header(
"Content-Type: text/css;charset=utf-8");
202 header(
'Content-Type: text/javascript;charset=utf-8');
205 header(
'Content-Type: text/html;charset=utf-8');
221 $hook_params = array(
263 require_once dirname(dirname(dirname(__FILE__))) .
"/start.php";
272 protected function send403($msg =
'Cache error: bad request') {
273 header(
'HTTP/1.1 403 Forbidden');
getProcessedView($view, $viewtype)
Get the contents of a view for caching.
handleRequest($get_vars, $server_vars)
Handle a request for a cached view.
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
parseRequestVar($request_var)
Parse a request.
setupSimplecache()
Do a minimal engine load.
_elgg_get_view_filetype($view)
Returns the type of output expected from the view.
__construct($config)
Constructor.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
renderView($view, $viewtype)
Render a view for caching.
_elgg_is_view_cacheable($view)
Check whether a view is registered as cacheable.
sendCacheHeaders($etag)
Send cache headers.
elgg echo
Translates a string.
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
send403($msg= 'Cache error:bad request')
Send an error message to requestor.
$content
Set robots.txt action.
sendContentType($view)
Send content type.
clearfix elgg elgg elgg elgg page header
loadEngine()
Load the complete Elgg engine.