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']) && trim($server_vars[
'HTTP_IF_NONE_MATCH']) === $etag) {
61 header(
"HTTP/1.1 304 Not Modified");
65 $filename = $this->config->dataroot .
'views_simplecache/' . md5(
"$viewtype|$view");
67 $this->sendCacheHeaders($etag);
79 $cache_timestamp = (int)
_elgg_services()->config->get(
'lastcache');
81 if ($cache_timestamp ==
$ts) {
82 $this->sendCacheHeaders($etag);
86 $dir_name = $this->config->dataroot .
'views_simplecache/';
87 if (!is_dir($dir_name)) {
88 mkdir($dir_name, 0700);
109 if (
false !== strpos($request_var,
'..')) {
113 if (preg_match(
'#[^a-zA-Z0-9/\.\-_]#', $request_var)) {
120 if (!preg_match(
'#^/?([0-9]+)/([^/]+)/(.+)$#', $request_var, $matches)) {
126 'viewtype' => $matches[2],
127 'view' => $matches[3],
137 if (!empty($this->config->dataroot) && isset($this->config->simplecache_enabled)) {
141 $db_config =
new Database\Config($this->config);
145 $rows = $db->getData(
" 146 SELECT `name`, `value` 147 FROM {$db->getTablePrefix()}datalists 148 WHERE `name` IN ('dataroot', 'simplecache_enabled') 151 $this->send403(
'Cache error: unable to get the data root');
154 if (0 === strpos($e->getMessage(),
"Elgg couldn't connect")) {
155 $this->send403(
'Cache error: unable to connect to database server');
157 $this->send403(
'Cache error: unable to connect to Elgg database');
163 $this->config->{$row->name} = $row->value;
166 if (empty($this->config->dataroot)) {
167 $this->send403(
'Cache error: unable to get the data root');
178 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s \G\M\T', strtotime(
"+6 months")),
true);
179 header(
"Pragma: public",
true);
180 header(
"Cache-Control: public",
true);
191 $segments = explode(
'/',
$view, 2);
192 switch ($segments[0]) {
194 header(
"Content-Type: text/css",
true);
197 header(
'Content-Type: text/javascript',
true);
214 $hook_params = array(
256 require_once dirname(dirname(dirname(__FILE__))) .
"/start.php";
265 protected function send403($msg =
'Cache error: bad request') {
266 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.