summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rdalverny@gmail.com>2022-01-15 16:41:25 +0100
committerRomain d'Alverny <rdalverny@gmail.com>2022-01-15 16:41:25 +0100
commitfda57f3b7c52ea9747e8c132c4571772ab913752 (patch)
tree73e15148320882539b1ff9dd456f8bd02a9078db /index.php
parentb9b9f483f54365ecb88572690f308a29d26da31c (diff)
downloadplanet-fda57f3b7c52ea9747e8c132c4571772ab913752.tar
planet-fda57f3b7c52ea9747e8c132c4571772ab913752.tar.gz
planet-fda57f3b7c52ea9747e8c132c4571772ab913752.tar.bz2
planet-fda57f3b7c52ea9747e8c132c4571772ab913752.tar.xz
planet-fda57f3b7c52ea9747e8c132c4571772ab913752.zip
Refactor main controller and templates
Templates for the public part: - archive/default views are merged into a single set - becomes HTML5 Controller code is reorganized for clarity. Compiled template caching is also fixed and activated when config cache value is > 0. Caching is also given new default larger values.
Diffstat (limited to 'index.php')
-rwxr-xr-xindex.php38
1 files changed, 13 insertions, 25 deletions
diff --git a/index.php b/index.php
index 75c1bc6..0d149bd 100755
--- a/index.php
+++ b/index.php
@@ -2,28 +2,17 @@
include_once(__DIR__.'/app/app.php');
include_once(__DIR__.'/app/classes/Cache.php');
-//Installed ?
if (!$PlanetConfig::isInstalled()) {
- echo '<p>' . _g('You might want to <a href="install.php">install moonmoon</a>.') . '</p>';
- exit;
+ die('<p>' . _g('You might want to <a href="install.php">install moonmoon</a>.') . '</p>');
}
-//Load from cache
-$items = array();
-if (0 < $Planet->loadOpml($PlanetConfig->getOpmlFile())) {
- $Planet->loadFeeds();
- $items = $Planet->getItems();
+$pageRole = $_GET['type'] ?? 'index';
+$pageTheme = 'default';
+if (!in_array($pageRole, ['index', 'archive', 'atom10'])) {
+ $pageRole = 'index';
}
-//Prepare output cache
-Cache::$enabled = false;
-$cache_key = (count($items)) ? $items[0]->get_id() : '';
-$last_modified = (count($items)) ? $items[0]->get_date() : '';
-$cache_duration = $PlanetConfig->getOutputTimeout() * 60;
-
-Cache::setStore($PlanetConfig->getCacheDir());
-
-if (isset($_GET['type']) && $_GET['type'] == 'atom10') {
+if ($pageRole == 'atom10') {
/* XXX: Redirect old ATOM feeds to new url to make sure our users don't
* loose subscribers upon upgrading their moonmoon installation.
* Remove this check in a more distant future.
@@ -33,15 +22,14 @@ if (isset($_GET['type']) && $_GET['type'] == 'atom10') {
exit;
}
-//Go display
-if (!isset($_GET['type']) ||
- !is_file(__DIR__.'/custom/views/'.$_GET['type'].'/index.tpl.php') ||
- strpos($_GET['type'], DIRECTORY_SEPARATOR) || strpos($_GET['type'], '..')) {
- $_GET['type'] = 'default';
-}
+$cache_duration = $PlanetConfig->getOutputTimeout();
+Cache::$enabled = ($cache_duration > 0);
+Cache::setStore($PlanetConfig->getCacheDir() . '/');
-if (!OutputCache::Start($_GET['type'], $cache_key, $cache_duration)) {
- include_once(__DIR__.'/custom/views/'.$_GET['type'].'/index.tpl.php');
+if (!OutputCache::Start('html', $pageRole, $cache_duration)) {
+ $items = $Planet->getFeedsItems();
+ $last_modified = (count($items)) ? $items[0]->get_date() : '';
+ include_once(__DIR__.'/custom/views/'.$pageTheme.'/'.$pageRole.'.tpl.php');
OutputCache::End();
}