CMS for the late garbage.fm
at main 65 lines 1.5 kB view raw
1<?php 2/* 3 application controller from which all other controllers will extend. use 4 this for site-wide functions like authentication, before_filters, etc. 5*/ 6 7class ApplicationController extends HalfMoon\ApplicationController { 8 /* sessions are off by default to allow caching */ 9 static $session = "off"; 10 11 public function hosts() { 12 $users = User::find("all"); 13 14 usort($users, function ($a, $b) { 15 return strnatcasecmp($a->full_name, $b->full_name); 16 }); 17 18 return $users; 19 } 20 21 protected function authenticate_user() { 22 if (isset($_SESSION["user_id"])) 23 $this->user = User::find_by_id($_SESSION["user_id"]); 24 25 return true; 26 } 27 28 protected function require_logged_in_user() { 29 if ($this->user) 30 return true; 31 32 return $this->redirect_to(ADMIN_ROOT_URL . "login"); 33 } 34 35 protected function settings() { 36 if (!$this->_settings) 37 $this->_settings = Settings::fetch(); 38 39 return $this->_settings; 40 } 41 42 protected function flush_cache() { 43 if (\HalfMoon\Utils::is_blank(\HalfMoon\Config::instance()->cache_store_path)) 44 return false; 45 46 $deleted = 0; 47 48 $fs = new RecursiveIteratorIterator( 49 new RecursiveDirectoryIterator(\HalfMoon\Config::instance()->cache_store_path), 50 RecursiveIteratorIterator::SELF_FIRST); 51 foreach($fs as $name => $object) { 52 if (is_file($name)) { 53 unlink($name); 54 $deleted++; 55 } 56 } 57 58 $this->add_flash_success("Deleted " . $deleted . " cached file" 59 . ($deleted == 1 ? "" : "s")); 60 61 return true; 62 } 63} 64 65?>