}
$page->assign('rss_hash', $token);
- header('Content-Type: application/rss+xml; charset=utf8');
+ pl_content_headers("application/rss+xml");
$this->iterator = $this->fetch($user);
$page->coreTpl('feed.' . $type . '.tpl', NO_SKIN);
$page->assign_by_ref('feed', $this);
public $cookie_ns = 'ORG';
public $cookie_path = '/';
+ /** Cache duration for static and dynamic cacheable content generated by
+ * plat/al. Defaults to a week for static content, and an hour for dynamic
+ * content.
+ */
+ public $static_cache_duration = 604800;
+ public $dynamic_cache_duration = 3600;
+
/** You must give a list of file to load.
* The filenames given are relatives to the config path of your plat/al installation.
*/
$this->addJsLink('wiki.js');
header("Accept-Charset: utf-8");
if (Env::v('forceXml')) {
- header("Content-Type: text/xml; charset=utf-8");
+ pl_content_headers("text/xml");
}
if (!$globals->debug) {
// {{{ function jsonDisplay
protected function jsonDisplay()
{
- header("Content-type: text/javascript; charset=utf-8");
+ pl_content_headers("text/javascript");
array_walk_recursive($this->_jsonVars, "escape_xorgDB");
$jsonbegin = Env::v('jsonBegin');
$jsonend = Env::v('jsonEnd');
*/
public function show()
{
- header("Pragma: ");
- header("Cache-Control: ");
-
/* XXX: RFC2425 defines the mime content-type text/directory.
* VCard inherits this type as a profile type. Maybe test/x-vcard
* could be better. To be checked.
*/
- header("Content-type: text/directory; profile=vCard; charset=" . self::$charset);
+ pl_cached_dynamic_content_headers("text/directory; profile=vCard", "utf-8");
$it = $this->fetch();
while ($item = $it->next()) {
$page = $this->getPage($curpage);
}
if ($mode == 'ajax') {
- header('Content-Type: text/html; charset=utf-8');
+ pl_content_headers("text/html");
$smarty->changeTpl($this->layout, NO_SKIN);
$smarty->assign('wiz_run_ajax', true);
} else {
return html_entity_decode($text, $mode, 'UTF-8');
}
+/**
+ * Adds content type headers; by default the encoding used is utf-8.
+ */
+function pl_content_headers($content_type, $encoding = 'utf-8')
+{
+ if (is_null($encoding)) {
+ header("Content-Type: $content_type");
+ } else {
+ header("Content-Type: $content_type; charset=$encoding");
+ }
+}
+
+/**
+ * Adds content type and caching headers for content generated by plat/al. The
+ * cache duration defaults to the global static_cache_duration. No encoding is
+ * applied by default.
+ */
+function pl_cached_content_headers($content_type, $encoding = null, $cache_duration = -1)
+{
+ global $globals;
+ $cache_duration = ($cache_duration < 0 ? $globals->static_cache_duration : $cache_duration);
+
+ header("Cache-Control: max-age=$cache_duration");
+ header("Expires: " . gmdate('D, d M Y H:i:s', time() + $cache_duration) . " GMT");
+ pl_content_headers($content_type, $encoding);
+}
+
+/**
+ * Same as above, but applying an expiration time suitable for cacheable dynamic
+ * content (eg. photos, logos, ...).
+ */
+function pl_cached_dynamic_content_headers($content_type, $encoding = null)
+{
+ global $globals;
+ pl_cached_content_headers($content_type, $encoding, $globals->dynamic_cache_duration);
+}
+
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
function handler_favicon(&$page)
{
global $globals;
- $data = file_get_contents($globals->spoolroot . '/htdocs/images/favicon.ico');
- header('Content-Type: image/x-icon');
- echo $data;
+ pl_cached_content_headers("image/x-icon");
+ readfile($globals->spoolroot . '/htdocs/images/favicon.ico');
exit;
}
}
if (count($disallowed_uris) > 0) {
- header('Content-Type: text/plain');
+ pl_cached_content_headers("text/plain");
echo "User-agent: *\n";
foreach ($disallowed_uris as $uri) {
echo "Disallow: $uri\n";
/// Shared handler for wiki syntax result preview
function handler_wiki_preview(&$page, $action = 'title')
{
- header('Content-Type: text/html; charset=utf-8');
+ pl_content_headers("text/html");
$text = Env::v('text');
echo MiniWiki::wikiToHtml($text, $action == 'title');
exit;