summaryrefslogtreecommitdiffstats
path: root/index.php
blob: a92cbaf953b11334b13656a3a8c94d60a1ee9d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
$bench['start'] = microtime(true);

$debug = isset($_GET['debug']) ? $_GET['debug'] : 0;
if ($debug) {
    error_reporting(E_ALL);
} else {
    error_reporting(0);
}

include_once(dirname(__FILE__).'/app/classes/Planet.class.php');
include_once(dirname(__FILE__).'/app/lib/Cache.php');

//Load configuration
if (is_file(dirname(__FILE__).'/custom/config.yml')){
    $conf = Spyc::YAMLLoad(dirname(__FILE__).'/custom/config.yml');
    $PlanetConfig = new PlanetConfig($conf);
} else {
    echo '<p>You might want to <a href="install.php">install moonmoon</a>.</p>';
    exit;
}

//Instantiate app
$Planet = new Planet($PlanetConfig);
$bench['codeloaded'] = microtime(true);

//Load from cache
$items = Array();
if (0 < $Planet->loadOpml(dirname(__FILE__).'/custom/people.opml')) {
    $Planet->loadFeeds();
    $items = $Planet->getItems();
}
$bench['contentloaded'] = microtime(true);

//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(dirname(__FILE__).'/'.$conf['cachedir']);

//Go display
if (!isset($_GET['type']) || 
    !is_file(dirname(__FILE__).'/custom/views/'.$_GET['type'].'/index.tpl.php') || 
    strpos($_GET['type'], DIRECTORY_SEPARATOR)){
    $_GET['type'] = 'default';
}

if (!OutputCache::Start($_GET['type'], $cache_key, $cache_duration)) {
    include_once(dirname(__FILE__).'/custom/views/'.$_GET['type'].'/index.tpl.php');
    OutputCache::End();
}

$bench['contentdisplayed'] = microtime(true);

echo "<!-- Load code: ".($bench['codeloaded'] - $bench['start'])." -->";
echo "<!-- Load content: ".($bench['contentloaded'] - $bench['codeloaded'])." -->";
echo "<!-- Display: ".($bench['contentdisplayed'] - $bench['contentloaded'])." -->";
echo "<!--";
var_dump($Planet->errors);
echo "-->";