summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--app/classes/Planet.php13
-rw-r--r--app/classes/PlanetConfig.php7
-rw-r--r--atom.php1
-rwxr-xr-xcustom/views/archive/footer.tpl.php3
-rw-r--r--custom/views/archive/head.tpl.php6
-rwxr-xr-xcustom/views/archive/sidebar.tpl.php34
-rw-r--r--custom/views/archive/top.tpl.php4
-rw-r--r--[-rwxr-xr-x]custom/views/default/archive.tpl.php (renamed from custom/views/archive/index.tpl.php)35
-rwxr-xr-xcustom/views/default/footer.tpl.php8
-rw-r--r--custom/views/default/head.tpl.php9
-rw-r--r--custom/views/default/index.tpl.php19
-rw-r--r--custom/views/default/top.tpl.php11
-rwxr-xr-xindex.php38
-rw-r--r--tests/InstallTest.php2
14 files changed, 65 insertions, 125 deletions
diff --git a/app/classes/Planet.php b/app/classes/Planet.php
index 402d2d0..1555c25 100644
--- a/app/classes/Planet.php
+++ b/app/classes/Planet.php
@@ -81,6 +81,19 @@ class Planet
}
/**
+ * @return array $items
+ */
+ public function getFeedsItems()
+ {
+ $items = [];
+ if (0 < $this->loadOpml($this->config->getOpmlFile())) {
+ $this->loadFeeds();
+ $items = $this->getItems();
+ }
+ return $items;
+ }
+
+ /**
* Getters
*/
public function getItems()
diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php
index a13179b..b8233e0 100644
--- a/app/classes/PlanetConfig.php
+++ b/app/classes/PlanetConfig.php
@@ -16,11 +16,8 @@ class PlanetConfig
'name' => '',
'locale' => 'en',
'items' => 10,
- 'shuffle' => 0,
- 'refresh' => 240,
- 'cache' => 10,
- 'nohtml' => 0,
- 'postmaxlength' => 0,
+ 'refresh' => 3600,
+ 'cache' => 1800,
'categories' => '',
'cachedir' => './cache',
'debug' => false,
diff --git a/atom.php b/atom.php
index 3b759e9..ddeebc0 100644
--- a/atom.php
+++ b/atom.php
@@ -24,7 +24,6 @@ echo '<?xml version="1.0" encoding="UTF-8" ?>';
<author><name><?=htmlspecialchars($PlanetConfig->getName())?></name></author>
<?php $count = 0; ?>
<?php foreach ($items as $item) : ?>
-
<entry>
<title type="html"><?=htmlspecialchars($item->get_feed()->getName())?> : <?=htmlspecialchars($item->get_title())?></title>
<id><?=htmlspecialchars($item->get_id())?></id>
diff --git a/custom/views/archive/footer.tpl.php b/custom/views/archive/footer.tpl.php
deleted file mode 100755
index c9c84b1..0000000
--- a/custom/views/archive/footer.tpl.php
+++ /dev/null
@@ -1,3 +0,0 @@
- <div id="footer">
- <p><?php echo str_replace('%s', 'href="http://moonmoon.org"', _g('Powered by <a %s>moonmoon</a>'))?> | <a href="./admin/"><?=_g('Administration')?></a></p>
- </div>
diff --git a/custom/views/archive/head.tpl.php b/custom/views/archive/head.tpl.php
deleted file mode 100644
index 005a75d..0000000
--- a/custom/views/archive/head.tpl.php
+++ /dev/null
@@ -1,6 +0,0 @@
- <link rel="stylesheet" media="screen" type="text/css" href="custom/style/default.css" title="Default" />
- <link rel="stylesheet" media="screen" type="text/css" href="custom/style/green.css" title="Green" />
- <link rel="stylesheet" media="screen" type="text/css" href="custom/style/light.css" title="Light" />
- <link rel="stylesheet" media="screen" type="text/css" href="custom/style/dark.css" title="Dark" />
-
- <link rel="alternate" type="application/atom+xml" title="ATOM" href="atom.php" />
diff --git a/custom/views/archive/sidebar.tpl.php b/custom/views/archive/sidebar.tpl.php
deleted file mode 100755
index 7a5d080..0000000
--- a/custom/views/archive/sidebar.tpl.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-$all_people = $Planet->getPeople();
-usort($all_people, array('PlanetFeed', 'compare'));
-?>
-<div id="sidebar">
- <div id="sidebar-people">
- <h2><?=_g('People')?> (<?php echo count($all_people); ?>)</h2>
- <ul>
- <?php foreach ($all_people as $person) : ?>
- <li>
- <a href="<?php echo htmlspecialchars($person->getFeed(), ENT_QUOTES, 'UTF-8'); ?>" title="<?=_g('Feed')?>"><img src="postload.php?url=<?php echo urlencode(htmlspecialchars($person->getFeed(), ENT_QUOTES, 'UTF-8')); ?>" alt="<?=_g('Feed')?>" height="12" width="12" /></a>
- <a href="<?php echo $person->getWebsite(); ?>" title="<?=_g('Website')?>"><?php echo htmlspecialchars($person->getName(), ENT_QUOTES, 'UTF-8'); ?></a>
- </li>
- <?php endforeach; ?>
- </ul>
- <p>
- <a href="custom/people.opml"><img src="custom/img/opml.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<?=_g('All feeds in OPML format')?></a>
- </p>
- </div>
-
- <div>
- <h2><?=_g('Syndicate')?></h2>
- <ul>
- <li><img src="custom/img/feed.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<a href="atom.php"><?=_g('Feed (ATOM)')?></a></li>
- </ul>
- </div>
-
- <div>
- <h2><?=_g('Archives')?></h2>
- <ul>
- <li><a href="?type=archive"><?=_g('See all headlines')?></a></li>
- </ul>
- </div>
-</div>
diff --git a/custom/views/archive/top.tpl.php b/custom/views/archive/top.tpl.php
deleted file mode 100644
index 7a818e1..0000000
--- a/custom/views/archive/top.tpl.php
+++ /dev/null
@@ -1,4 +0,0 @@
- <div id="top">
- <h1><a href="<?php echo $PlanetConfig->getUrl() ?>"><?php echo $PlanetConfig->getName(); ?></a></h1>
- </div>
- \ No newline at end of file
diff --git a/custom/views/archive/index.tpl.php b/custom/views/default/archive.tpl.php
index 679ef71..f775971 100755..100644
--- a/custom/views/archive/index.tpl.php
+++ b/custom/views/default/archive.tpl.php
@@ -1,4 +1,5 @@
<?php
+$pageTitle = $PlanetConfig->getName() . ' &middot; ' . _g('All Headlines');
$count = 0;
$today = array();
$week = array();
@@ -20,44 +21,36 @@ foreach ($items as $item) {
}
header('Content-type: text/html; charset=UTF-8');
-?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$PlanetConfig->getLocale()?>" lang="<?=$PlanetConfig->getLocale()?>">
+?><!DOCTYPE html>
+<html lang="<?=$PlanetConfig->getLocale()?>" class="no-js">
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
- <meta http-equiv="Content-Style-Type" content="text/css" />
-
- <title><?php echo $PlanetConfig->getName(); ?></title>
<?php include(__DIR__.'/head.tpl.php'); ?>
</head>
-
<body>
<div id="page">
<?php include(__DIR__.'/top.tpl.php'); ?>
-
- <div id="content">
+ <main id="content">
<?php if (0 == count($items)) :?>
- <div class="article">
+ <article class="article">
<h2 class="article-title">
<?=_g('No article')?>
</h2>
<p class="article-content"><?=_g('No news, good news.')?></p>
- </div>
+ </article>
<?php endif; ?>
<?php if (count($today)) : ?>
- <div class="article">
+ <article class="article">
<h2><?=_g('Today')?></h2>
<ul>
<?php foreach ($today as $item) : ?>
<?php $feed = $item->get_feed(); ?>
<li>
- <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> :
+ <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> &middot;
<a href="<?php echo $item->get_permalink(); ?>" title="<?=_g('Go to original place')?>"><?php echo $item->get_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
- </div>
+ </article>
<?php endif; ?>
<?php if (count($week)) : ?>
@@ -67,7 +60,7 @@ header('Content-type: text/html; charset=UTF-8');
<?php foreach ($week as $item) : ?>
<?php $feed = $item->get_feed(); ?>
<li>
- <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> :
+ <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> &middot;
<a href="<?php echo $item->get_permalink(); ?>" title="<?=_g('Go to original place')?>"><?php echo $item->get_title(); ?></a>
</li>
<?php endforeach; ?>
@@ -82,7 +75,7 @@ header('Content-type: text/html; charset=UTF-8');
<?php foreach ($month as $item) : ?>
<?php $feed = $item->get_feed(); ?>
<li>
- <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> :
+ <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> &middot;
<a href="<?php echo $item->get_permalink(); ?>" title="<?=_g('Go to original place')?>"><?php echo $item->get_title(); ?></a>
</li>
<?php endforeach; ?>
@@ -97,17 +90,15 @@ header('Content-type: text/html; charset=UTF-8');
<?php foreach ($older as $item) : ?>
<?php $feed = $item->get_feed(); ?>
<li>
- <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> :
+ <a href="<?php echo $feed->getWebsite() ?>" class="source"><?php echo $feed->getName() ?></a> &middot;
<a href="<?php echo $item->get_permalink(); ?>" title="Go to original place"><?php echo $item->get_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
- </div>
-
+ </main>
<?php include_once(__DIR__.'/sidebar.tpl.php'); ?>
-
<?php include(__DIR__.'/footer.tpl.php'); ?>
</div>
</body>
diff --git a/custom/views/default/footer.tpl.php b/custom/views/default/footer.tpl.php
index d7d6c1a..eeff62b 100755
--- a/custom/views/default/footer.tpl.php
+++ b/custom/views/default/footer.tpl.php
@@ -1,4 +1,4 @@
- <div id="footer">
- <p><?php echo str_replace('%s', 'href="http://moonmoon.org" title="moonmoon '.$moon_version.'"', _g('Powered by <a %s>moonmoon</a>'))?>
- | <a href="./admin/"><?=_g('Administration')?></a></p>
- </div>
+<footer id="footer">
+ <p><?php echo str_replace('%s', 'href="http://moonmoon.org" title="moonmoon '.$moon_version.'"', _g('Powered by <a %s>moonmoon</a>'))?>
+ | <a href="./admin/"><?=_g('Administration')?></a></p>
+</footer>
diff --git a/custom/views/default/head.tpl.php b/custom/views/default/head.tpl.php
index 5773aa6..dbaf65c 100644
--- a/custom/views/default/head.tpl.php
+++ b/custom/views/default/head.tpl.php
@@ -1,3 +1,10 @@
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title><?php echo $pageTitle; ?></title>
<link rel="stylesheet" media="screen" type="text/css" href="custom/style/default.css" title="Default" />
-
<link rel="alternate" type="application/atom+xml" title="ATOM" href="atom.php" />
+
+ <script type="module">
+ document.documentElement.classList.remove("no-js");
+ document.documentElement.classList.add("js");
+ </script> \ No newline at end of file
diff --git a/custom/views/default/index.tpl.php b/custom/views/default/index.tpl.php
index 5e68161..cad2a6f 100644
--- a/custom/views/default/index.tpl.php
+++ b/custom/views/default/index.tpl.php
@@ -1,26 +1,15 @@
<?php
+$pageTitle = $PlanetConfig->getName();
$limit = $PlanetConfig->getMaxDisplay();
$count = 0;
header('Content-type: text/html; charset=UTF-8');
-?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$PlanetConfig->getLocale()?>" lang="<?=$PlanetConfig->getLocale()?>">
+?><!DOCTYPE html>
+<html lang="<?=$PlanetConfig->getLocale()?>" class="no-js">
<head>
- <meta charset="utf-8">
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
- <meta http-equiv="Content-Style-Type" content="text/css" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-
- <title><?php echo $PlanetConfig->getName(); ?></title>
<?php include(__DIR__.'/head.tpl.php'); ?>
</head>
-
<body>
- <script type="text/javascript">
- document.body.className += 'js';
- </script>
<div id="page">
<?php include(__DIR__.'/top.tpl.php'); ?>
@@ -67,9 +56,7 @@ header('Content-type: text/html; charset=UTF-8');
<?php endforeach; ?>
<?php endif; ?>
</div>
-
<?php include_once(__DIR__.'/sidebar.tpl.php'); ?>
-
<?php include(__DIR__.'/footer.tpl.php'); ?>
</div>
</body>
diff --git a/custom/views/default/top.tpl.php b/custom/views/default/top.tpl.php
index 6db425c..ed6e19c 100644
--- a/custom/views/default/top.tpl.php
+++ b/custom/views/default/top.tpl.php
@@ -1,3 +1,8 @@
- <div id="header">
- <h1 id="top"><a href="<?php echo $PlanetConfig->getUrl(); ?>"><?php echo $PlanetConfig->getName(); ?></a></h1>
- </div> \ No newline at end of file
+<header id="header">
+ <h1 id="top">
+ <a href="<?php echo $PlanetConfig->getUrl(); ?>"><?php echo $PlanetConfig->getName(); ?></a>
+ <?php if ($pageRole == 'archive') : ?>
+ &middot; <?=_g('All Headlines') ?>
+ <?php endif; ?>
+ </h1>
+</header> \ No newline at end of file
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();
}
diff --git a/tests/InstallTest.php b/tests/InstallTest.php
index fe5dc4e..b230d74 100644
--- a/tests/InstallTest.php
+++ b/tests/InstallTest.php
@@ -48,7 +48,7 @@ class InstallTest extends GuzzleHarness
{
$data = [
'url' => 'http://127.0.0.1:8081/',
- 'title' => 'My website',
+ 'title' => 'My website',
'password' => 'admin',
'locale' => 'en',
];