/** * Get the base url for simple cache requests * * @return string The simplecache root url for the current viewtype. * @access private */ function getRoot() { $viewtype = elgg_get_viewtype(); if (elgg_is_simplecache_enabled()) { // stored in datalist as 'simplecache_lastupdate' $lastcache = (int) _elgg_services()->config->get('lastcache'); } else { $lastcache = 0; } return elgg_normalize_url("/cache/{$lastcache}/{$viewtype}/"); }
<?php /** * Initialize Elgg's js lib with the uncacheable data */ $elgg = array('config' => array('lastcache' => (int) elgg_get_config('lastcache'), 'viewtype' => elgg_get_viewtype(), 'simplecache_enabled' => (int) elgg_is_simplecache_enabled()), 'security' => array('token' => array('__elgg_ts' => $ts = time(), '__elgg_token' => generate_action_token($ts))), 'session' => array('user' => null)); $page_owner = elgg_get_page_owner_entity(); if ($page_owner instanceof ElggEntity) { $elgg['page_owner'] = $page_owner->toObject(); } $user = elgg_get_logged_in_user_entity(); if ($user instanceof ElggUser) { $user_object = $user->toObject(); $user_object->admin = $user->isAdmin(); $elgg['session']['user'] = $user_object; } ?> var elgg = <?php echo json_encode($elgg); ?> ; <?php // note: elgg.session.user needs to be wrapped with elgg.ElggUser, but this class isn't // defined yet. So this is delayed until after the classes are defined, in js/lib/session.js
/** * Get the URL for the cached file * * @param string $type The file type: css or js * @param string $view The view name * @return string * @since 1.8.0 */ function elgg_get_simplecache_url($type, $view) { global $CONFIG; $lastcache = (int) $CONFIG->lastcache; $viewtype = elgg_get_viewtype(); if (elgg_is_simplecache_enabled()) { $url = elgg_get_site_url() . "cache/{$type}/{$viewtype}/{$view}.{$lastcache}.{$type}"; } else { $url = elgg_get_site_url() . "{$type}/{$view}.{$lastcache}.{$type}"; $elements = array("view" => $viewtype); $url = elgg_http_add_url_query_elements($url, $elements); } return $url; }
* Initialize Elgg's js lib with the uncacheable data */ ?> /** * Don't want to cache these -- they could change for every request */ elgg.config.lastcache = <?php echo (int) elgg_get_config('lastcache'); ?> ; elgg.config.viewtype = '<?php echo elgg_get_viewtype(); ?> '; elgg.config.simplecache_enabled = <?php echo (int) elgg_is_simplecache_enabled(); ?> ; elgg.security.token.__elgg_ts = <?php echo $ts = time(); ?> ; elgg.security.token.__elgg_token = '<?php echo generate_action_token($ts); ?> '; <?php // @todo json export should be smoother than this... // @todo Might also be nice to make url exportable. $entity->url? yes please!
$css = elgg_get_loaded_css(); $resources = array('js' => array(), 'css' => array()); /** @hack Prevent js/css from loading again if cached in default viewtype * */ $lastcached_xhr = datalist_get("simplecache_lastcached_xhr"); $lastcached_default = datalist_get("simplecache_lastcached_default"); foreach ($js as $script) { if (elgg_is_simplecache_enabled()) { $script = str_replace('cache/js/xhr', 'cache/js/default', $script); } else { $script = str_replace('view=xhr', 'view=default', $script); } $script = str_replace($lastcached_xhr, $lastcached_default, $script); $resources['js'][] = html_entity_decode($script); } foreach ($css as $link) { if (elgg_is_simplecache_enabled()) { $link = str_replace('cache/css/xhr', 'cache/css/default', $link); } else { $link = str_replace('view=xhr', 'view=default', $link); } $link = str_replace($lastcached_xhr, $lastcached_default, $link); $resources['css'][] = html_entity_decode($link); } $params = array('output' => $output, 'status' => 0, 'system_messages' => array('error' => array(), 'success' => array()), 'resources' => $resources, 'href' => full_url()); if (isset($system_messages['success']) && count($system_messages['success'])) { $params['system_messages']['success'] = $system_messages['success']; } if (isset($system_messages['error']) && count($system_messages['error'])) { $params['system_messages']['error'] = $system_messages['error']; $params['status'] = -1; }
/** * Get the URL for the cached file * * @param string $type The file type: css or js * @param string $view The view name * @return string * @since 1.8.0 */ function elgg_get_simplecache_url($type, $view) { global $CONFIG; $lastcache = (int) $CONFIG->lastcache; if (elgg_is_simplecache_enabled()) { $viewtype = elgg_get_viewtype(); $url = elgg_get_site_url() . "cache/{$type}/{$view}/{$viewtype}/{$view}.{$lastcache}.{$type}"; } else { $url = elgg_get_site_url() . "{$type}/{$view}.{$lastcache}.{$type}"; } return $url; }
/** * Get the initial contents of "elgg" client side. Will be extended by elgg.js. * * @return array * @access private */ function _elgg_get_js_page_data() { $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []); if (!is_array($data)) { elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR'); $data = []; } $elgg = array('config' => array('lastcache' => (int) elgg_get_config('lastcache'), 'viewtype' => elgg_get_viewtype(), 'simplecache_enabled' => (int) elgg_is_simplecache_enabled()), 'security' => array('token' => array('__elgg_ts' => $ts = time(), '__elgg_token' => generate_action_token($ts))), 'session' => array('user' => null, 'token' => _elgg_services()->session->get('__elgg_session')), '_data' => (object) $data); if (elgg_get_config('elgg_load_sync_code')) { $elgg['config']['load_sync_code'] = true; } $page_owner = elgg_get_page_owner_entity(); if ($page_owner instanceof ElggEntity) { $elgg['page_owner'] = $page_owner->toObject(); } $user = elgg_get_logged_in_user_entity(); if ($user instanceof ElggUser) { $user_object = $user->toObject(); $user_object->admin = $user->isAdmin(); $elgg['session']['user'] = $user_object; } return $elgg; }