tuupola / frog_funky_cache
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
77978ca
frog_funky_cache / FunkyCacheController.php
| cf41c9eb » | tuupola | 2008-11-20 | 1 | <?php | |
| 2 | |||||
| 0bd085c5 » | tuupola | 2008-11-26 | 3 | /* | |
| 4 | * Funky Cache - Frog CMS caching plugin | ||||
| 5 | * | ||||
| ac5ffadd » | tuupola | 2009-01-13 | 6 | * Copyright (c) 2008-2009 Mika Tuupola | |
| 0bd085c5 » | tuupola | 2008-11-26 | 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 | 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 | 25 | if (version_compare(FROG_VERSION, '0.9.4', '<=')) { | |
| e8c3b333 » | tuupola | 2009-01-13 | 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 | 30 | } | |
| 31 | |||||
| 32 | function index() { | ||||
| 29311157 » | tuupola | 2008-11-20 | 33 | $this->display('funky_cache/views/index', array( | |
| 773c725c » | tuupola | 2008-12-05 | 34 | 'cached_page' => Record::findAllFrom('FunkyCachePage', '1=1 ORDER BY created_on ASC') | |
| 29311157 » | tuupola | 2008-11-20 | 35 | )); | |
| 36 | } | ||||
| 37 | |||||
| 7d954230 » | tuupola | 2008-11-21 | 38 | function documentation() { | |
| 39 | $this->display('funky_cache/views/documentation'); | ||||
| 40 | } | ||||
| 41 | |||||
| f753a487 » | tuupola | 2008-12-05 | 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 | 51 | ||
| 29311157 » | tuupola | 2008-11-20 | 52 | function clear() { | |
| 53 | $cached_page = Record::findAllFrom('FunkyCachePage'); | ||||
| 54 | foreach ($cached_page as $page) { | ||||
| 55 | $page->delete(); | ||||
| f753a487 » | tuupola | 2008-12-05 | 56 | } | |
| 57 | Flash::set('success', 'Should have cleared cache.'); | ||||
| 77978cad » | tuupola | 2009-05-28 | 58 | $message = sprintf('Cache was cleared by :username.'); | |
| 59 | Observer::notify('log_event', $message, 5, 'funky_cache'); | ||||
| 29311157 » | tuupola | 2008-11-20 | 60 | redirect(get_url('plugin/funky_cache/')); | |
| cf41c9eb » | tuupola | 2008-11-20 | 61 | } | |
| 62 | |||||
| 63 | function settings() { | ||||
| 64 | $this->display('funky_cache/views/settings', array( | ||||
| 7cd8de3d » | tuupola | 2009-01-13 | 65 | 'funky_cache_by_default' => Setting::get('funky_cache_by_default'), | |
| b41dea15 » | tuupola | 2009-01-13 | 66 | 'funky_cache_suffix' => Setting::get('funky_cache_suffix'), | |
| 67 | 'funky_cache_folder' => Setting::get('funky_cache_folder') | ||||
| cf41c9eb » | tuupola | 2008-11-20 | 68 | )); | |
| 69 | } | ||||
| 70 | |||||
| 71 | function save() { | ||||
| 72 | error_reporting(E_ALL); | ||||
| 97b956d9 » | tuupola | 2008-11-23 | 73 | ||
| b41dea15 » | tuupola | 2009-01-13 | 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 | 86 | ||
| b41dea15 » | tuupola | 2009-01-13 | 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 | 91 | ||
| b41dea15 » | tuupola | 2009-01-13 | 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 | 96 | ||
| 1acf6c89 » | tuupola | 2008-11-25 | 97 | if ($success_1 && $success_2 && $success_3){ | |
| cf41c9eb » | tuupola | 2008-11-20 | 98 | Flash::set('success', __('The settings have been updated.')); | |
| 77978cad » | tuupola | 2009-05-28 | 99 | $message = sprintf('Cache settings were updated by :username.'); | |
| 100 | Observer::notify('log_event', $message, 5, 'funky_cache'); | ||||
| cf41c9eb » | tuupola | 2008-11-20 | 101 | } else { | |
| 102 | Flash::set('error', 'An error has occured.'); | ||||
| 77978cad » | tuupola | 2009-05-28 | 103 | $message = sprintf('Updating cache settings by :username failed.'); | |
| 104 | Observer::notify('log_event', $message, 2, 'funky_cache'); | ||||
| cf41c9eb » | tuupola | 2008-11-20 | 105 | } | |
| 106 | redirect(get_url('plugin/funky_cache/settings')); | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | } | ||||
