tuupola / frog_funky_cache

Funky cache plugin for Frog CMS

This URL has Read+Write access

frog_funky_cache / FunkyCacheController.php
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 1 <?php
2
0bd085c5 » tuupola 2008-11-26 Add license header. 3 /*
4 * Funky Cache - Frog CMS caching plugin
5 *
ac5ffadd » tuupola 2009-01-13 Update copyright year. 6 * Copyright (c) 2008-2009 Mika Tuupola
0bd085c5 » tuupola 2008-11-26 Add license header. 7 *
8 * Licensed under the MIT license:
9 * http://www.opensource.org/licenses/mit-license.php
10 *
11 * Project home:
12 * http://www.appelsiini.net/projects/funky_cache
13 *
14 */
15
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 16 class FunkyCacheController extends PluginController
17 {
18 function __construct() {
19 AuthUser::load();
20 if (!(AuthUser::isLoggedIn())) {
21 redirect(get_url('login'));
22 }
23
24 $this->setLayout('backend');
7d20cc89 » tuupola 2009-04-09 0.9.5RC2 tried to use wrong... 25 if (version_compare(FROG_VERSION, '0.9.4', '<=')) {
e8c3b333 » tuupola 2009-01-13 Fix sidebar path for 0.9.5 ... 26 $this->assignToLayout('sidebar', new View('../../../plugins/funky_cache/views/sidebar'));
27 } else {
28 $this->assignToLayout('sidebar', new View('../../plugins/funky_cache/views/sidebar'));
29 }
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 30 }
31
32 function index() {
29311157 » tuupola 2008-11-20 Implement cached pages view... 33 $this->display('funky_cache/views/index', array(
773c725c » tuupola 2008-12-05 Clear cache after snippet o... 34 'cached_page' => Record::findAllFrom('FunkyCachePage', '1=1 ORDER BY created_on ASC')
29311157 » tuupola 2008-11-20 Implement cached pages view... 35 ));
36 }
37
7d954230 » tuupola 2008-11-21 Add documentation stub. 38 function documentation() {
39 $this->display('funky_cache/views/documentation');
40 }
41
f753a487 » tuupola 2008-12-05 Enable deleting cached page... 42 function delete($id) {
43 $cached_page = Record::findByIdFrom('FunkyCachePage', $id);
44 if ($cached_page->delete()) {
45 Flash::set('success', 'Page deleted from cache.');
46 } else {
47 Flash::set('error', 'Could not delete cached page. Try manually from commandline.');
48 }
49 redirect(get_url('plugin/funky_cache/'));
50 }
7d954230 » tuupola 2008-11-21 Add documentation stub. 51
29311157 » tuupola 2008-11-20 Implement cached pages view... 52 function clear() {
53 $cached_page = Record::findAllFrom('FunkyCachePage');
54 foreach ($cached_page as $page) {
55 $page->delete();
f753a487 » tuupola 2008-12-05 Enable deleting cached page... 56 }
57 Flash::set('success', 'Should have cleared cache.');
77978cad » tuupola 2009-05-28 Log basic events to Dashboard. 58 $message = sprintf('Cache was cleared by :username.');
59 Observer::notify('log_event', $message, 5, 'funky_cache');
29311157 » tuupola 2008-11-20 Implement cached pages view... 60 redirect(get_url('plugin/funky_cache/'));
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 61 }
62
63 function settings() {
64 $this->display('funky_cache/views/settings', array(
7cd8de3d » tuupola 2009-01-13 Use Setting::get() when fet... 65 'funky_cache_by_default' => Setting::get('funky_cache_by_default'),
b41dea15 » tuupola 2009-01-13 Clean up SQL when saving th... 66 'funky_cache_suffix' => Setting::get('funky_cache_suffix'),
67 'funky_cache_folder' => Setting::get('funky_cache_folder')
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 68 ));
69 }
70
71 function save() {
72 error_reporting(E_ALL);
97b956d9 » tuupola 2008-11-23 Work with any arbitary file... 73
b41dea15 » tuupola 2009-01-13 Clean up SQL when saving th... 74 /* Setting::saveFromData() does not handle any errors so lets save manually. */
75 $pdo = Record::getConnection();
76 $table = TABLE_PREFIX . 'setting';
77
78 $funky_cache_by_default = $pdo->quote($_POST['funky_cache_by_default']);
79 $funky_cache_suffix = $pdo->quote($_POST['funky_cache_suffix']);
80 $funky_cache_folder = $pdo->quote($_POST['funky_cache_folder']);
81
82 $query = "UPDATE $table
83 SET value = $funky_cache_suffix
84 WHERE name = 'funky_cache_suffix'";
85 $success_1 = $pdo->exec($query) !== false;
97b956d9 » tuupola 2008-11-23 Work with any arbitary file... 86
b41dea15 » tuupola 2009-01-13 Clean up SQL when saving th... 87 $query = "UPDATE $table
88 SET value = $funky_cache_by_default
89 WHERE name = 'funky_cache_by_default'";
90 $success_2 = $pdo->exec($query) !== false;
1acf6c89 » tuupola 2008-11-25 Configurable folder for cac... 91
b41dea15 » tuupola 2009-01-13 Clean up SQL when saving th... 92 $query = "UPDATE $table
93 SET value = $funky_cache_folder
94 WHERE name = 'funky_cache_folder'";
95 $success_3 = $pdo->exec($query) !== false;
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 96
1acf6c89 » tuupola 2008-11-25 Configurable folder for cac... 97 if ($success_1 && $success_2 && $success_3){
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 98 Flash::set('success', __('The settings have been updated.'));
77978cad » tuupola 2009-05-28 Log basic events to Dashboard. 99 $message = sprintf('Cache settings were updated by :username.');
100 Observer::notify('log_event', $message, 5, 'funky_cache');
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 101 } else {
102 Flash::set('error', 'An error has occured.');
77978cad » tuupola 2009-05-28 Log basic events to Dashboard. 103 $message = sprintf('Updating cache settings by :username failed.');
104 Observer::notify('log_event', $message, 2, 'funky_cache');
cf41c9eb » tuupola 2008-11-20 Skeleton of funky cache plu... 105 }
106 redirect(get_url('plugin/funky_cache/settings'));
107 }
108
109 }