public
Description: Funky cache plugin for Frog CMS
Homepage: http://www.appelsiini.net/projects/funky_cache
Clone URL: git://github.com/tuupola/frog_funky_cache.git
frog_funky_cache / FunkyCacheController.php
100644 110 lines (93 sloc) 3.869 kb
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
 
/*
* Funky Cache - Frog CMS caching plugin
*
* Copyright (c) 2008-2009 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* http://www.appelsiini.net/projects/funky_cache
*
*/
 
class FunkyCacheController extends PluginController
{
    function __construct() {
        AuthUser::load();
        if (!(AuthUser::isLoggedIn())) {
            redirect(get_url('login'));
        }
 
        $this->setLayout('backend');
        if (version_compare(FROG_VERSION, '0.9.4', '<=')) {
            $this->assignToLayout('sidebar', new View('../../../plugins/funky_cache/views/sidebar'));
        } else {
            $this->assignToLayout('sidebar', new View('../../plugins/funky_cache/views/sidebar'));
        }
    }
 
    function index() {
        $this->display('funky_cache/views/index', array(
            'cached_page' => Record::findAllFrom('FunkyCachePage', '1=1 ORDER BY created_on ASC')
        ));
    }
    
    function documentation() {
        $this->display('funky_cache/views/documentation');
    }
    
    function delete($id) {
        $cached_page = Record::findByIdFrom('FunkyCachePage', $id);
        if ($cached_page->delete()) {
            Flash::set('success', 'Page deleted from cache.');
        } else {
            Flash::set('error', 'Could not delete cached page. Try manually from commandline.');
        }
        redirect(get_url('plugin/funky_cache/'));
    }
    
    function clear() {
        $cached_page = Record::findAllFrom('FunkyCachePage');
        foreach ($cached_page as $page) {
            $page->delete();
        }
        Flash::set('success', 'Should have cleared cache.');
        $message = sprintf('Cache was cleared by :username.');
        Observer::notify('log_event', $message, 5, 'funky_cache');
        redirect(get_url('plugin/funky_cache/'));
    }
    
    function settings() {
        $this->display('funky_cache/views/settings', array(
'funky_cache_by_default' => Setting::get('funky_cache_by_default'),
'funky_cache_suffix' => Setting::get('funky_cache_suffix'),
'funky_cache_folder' => Setting::get('funky_cache_folder')
));
    }
    
function save() {
error_reporting(E_ALL);
 
/* Setting::saveFromData() does not handle any errors so lets save manually. */
$pdo = Record::getConnection();
$table = TABLE_PREFIX . 'setting';
 
$funky_cache_by_default = $pdo->quote($_POST['funky_cache_by_default']);
$funky_cache_suffix = $pdo->quote($_POST['funky_cache_suffix']);
$funky_cache_folder = $pdo->quote($_POST['funky_cache_folder']);
                  
        $query = "UPDATE $table
SET value = $funky_cache_suffix
WHERE name = 'funky_cache_suffix'";
        $success_1 = $pdo->exec($query) !== false;
 
        $query = "UPDATE $table
SET value = $funky_cache_by_default
WHERE name = 'funky_cache_by_default'";
        $success_2 = $pdo->exec($query) !== false;
        
        $query = "UPDATE $table
SET value = $funky_cache_folder
WHERE name = 'funky_cache_folder'";
        $success_3 = $pdo->exec($query) !== false;
                
        if ($success_1 && $success_2 && $success_3){
            Flash::set('success', __('The settings have been updated.'));
            $message = sprintf('Cache settings were updated by :username.');
            Observer::notify('log_event', $message, 5, 'funky_cache');
        } else {
            Flash::set('error', 'An error has occured.');
            $message = sprintf('Updating cache settings by :username failed.');
            Observer::notify('log_event', $message, 2, 'funky_cache');
        }
        redirect(get_url('plugin/funky_cache/settings'));
}
    
}